/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatAKKnshoTgChshu
*	ソースファイル名	：JBSbatAKKnshoTgChshu.java
*	作成者				：富士通　
*	作成日				：2013年04月30日
*＜機能概要＞
*　検証対象抽出部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2013/04/30   富士通		新規作成
*********************************************************************/
package eo.business.service;

import eo.business.common.JACbatDebugLogUtil;
import eo.business.common.JBSbatBusinessService;
import eo.framework.item.JBSbatCommonItem;
import eo.framework.item.JBSbatServiceInterfaceMap;
import eo.framework.item.JBSbatOutputItem;
import eo.business.common.JBSbatMatchServiceInterface;
import eo.business.util.file.JBSbatAKIFM001;
import eo.business.util.file.JBSbatAKIFM023;
import eo.business.util.file.JBSbatAKIFM024;

/**
* (クラスの機能概要) <p>
*<BR>
* @author 富士通
*/
public class JBSbatAKKnshoTgChshu extends JBSbatBusinessService implements JBSbatMatchServiceInterface
{
	/**▼▼▼▼▼▼ツールから生成した宣言です 開始▼▼▼▼▼▼*/
	/** キーマッチ処理フラグ*/
	private boolean matchProcFlg;

	/** マスタファイル処理フラグ*/
	private boolean mastProcFlg;

	/** トランファイル処理フラグ*/
	private boolean tranProcFlg;
	/**▲▲▲▲▲▲ツールから生成した宣言です 終了▲▲▲▲▲▲*/

	/**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの初期処理を記述してください。▼▼▼▼▼▼*/
		assert 	JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][initial]");
		assert 	JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][initial][opeDate=" + super.opeDate + "]");
		/**▼▼▼▼▼▼ツールから生成した初期化のソースです 開始▼▼▼▼▼▼*/
		// 共通パラメータを設定します
		super.setCommonInfo(commonItem);
		/**▲▲▲▲▲▲ツールから生成した初期化のソースです 終了▲▲▲▲▲▲*/
		assert 	JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][initial]");
	/**▲▲▲▲▲▲業務サービスの初期処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 主処理
	 * @param mastMap 請求内訳異動データ
	 * @param tranMap 料金検証対象外パターン
	 * @param outputInItem  入力情報
	 * @return JBSbatOutputItem 出力情報
	 * @throws Exception
	 */
	public JBSbatOutputItem execute(JBSbatServiceInterfaceMap mastMap, JBSbatServiceInterfaceMap tranMap, JBSbatOutputItem outputInItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの主処理を記述してください。▼▼▼▼▼▼*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute]");
		assert mastMap != null ? JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute][mastMap=" + mastMap.getMap().toString() + "]") : true;
		assert tranMap != null ? JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute][tranMap=" + tranMap.getMap().toString() + "]") : true;
		
		// 入力Ｍ、入力Ｔともにnullの場合
		if(mastMap == null && tranMap == null)
		{
			// 処理を抜ける
			return null;
		}
		// 入力Ｍのみ存在する
		else if (mastMap != null && tranMap == null)
		{
			// 出力処理
			outputInItem.addOutMapList(makeOutputInfo(mastMap));
			// マスタファイル処理フラグを設定する
			this.setMastProcFlg(true);
		}
		// 入力Ｔのみ存在する
		else if (mastMap == null && tranMap != null)
		{
			// トランファイル処理フラグを設定する
			this.setTranProcFlg(true);
		}
		// 入力Ｍ、入力Ｔともに存在する
		else
		{
			// マッチングキーリスト(配列[0]:マッチングキー(マスタ) 、配列[1]:マッチングキー(トラン) 
			String[] matchKeyList = new String[2];
			
			// マッチングキー取得
			matchKeyList = getMatchKey(mastMap, tranMap);
			
			// 入力Ｍ ＝ 入力Ｔ
			if (matchKeyList[0].compareTo(matchKeyList[1]) == 0)
			{
				// マスタファイル処理フラグを設定する
				this.setMastProcFlg(true);

			}
			// 入力Ｍ < 入力Ｔ
			else if (matchKeyList[0].compareTo(matchKeyList[1]) < 0)
			{
				// 出力処理
				outputInItem.addOutMapList(makeOutputInfo(mastMap));
				// マスタファイル処理フラグを設定する
				this.setMastProcFlg(true);
				
			
			}
			// 入力Ｍ > 入力Ｔ
			else if (matchKeyList[0].compareTo(matchKeyList[1]) > 0)
			{
				// トランファイル処理フラグを設定する
				this.setTranProcFlg(true);
			}
		}

		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][execute]");
		
	    return outputInItem;
	/**▲▲▲▲▲▲業務サービスの主処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 業務サービス終了処理
	 * @throws Exception
	 */
	public void terminal() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの終了処理を記述してください。▼▼▼▼▼▼*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][terminal]");
		/**▼▼▼▼▼▼ツールから生成した終了処理のソースです 開始▼▼▼▼▼▼*/
		/**▲▲▲▲▲▲ツールから生成した終了処理のソースです 終了▲▲▲▲▲▲*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][terminal]");
	/**▲▲▲▲▲▲業務サービスの終了処理を記述してください。▲▲▲▲▲▲*/
	}

	/**▼▼▼▼▼▼ツールから生成したメソッドです 開始▼▼▼▼▼▼*/
	/**
	 * @return mastProcFlg を戻します。
	 */
	public boolean isMastProcFlg()
	{
		return mastProcFlg;
	}

	/**
	 * @return matchProcFlg を戻します。
	 */
	public boolean isMatchProcFlg()
	{
		return matchProcFlg;
	}

	/**
	 * @return tranProcFlg を戻します。
	 */
	public boolean isTranProcFlg()
	{
		return tranProcFlg;
	}

	/**
	 * @param mast_ProcFlg 設定する mastProcFlg。
	 */
	public void setMastProcFlg(boolean mast_ProcFlg)
	{
		this.mastProcFlg = mast_ProcFlg;
	}

	/**
	 * @param match_ProcFlg 設定する matchProcFlg。
	 */
	public void setMatchProcFlg(boolean match_ProcFlg)
	{
		this.matchProcFlg = match_ProcFlg;
	}

	/**
	 * @param tran_ProcFlg 設定する tranProcFlg。
	 */
	public void setTranProcFlg(boolean tran_ProcFlg)
	{
		this.tranProcFlg = tran_ProcFlg;
	}
	/**▲▲▲▲▲▲ツールから生成したメソッドです 終了▲▲▲▲▲▲*/
	
	/**▼▼▼▼▼▼メソッド追加 開始▼▼▼▼▼▼*/
	/**
	 * マッチングキーリストを取得します。
	 * @param mastMap 請求内訳異動データ
	 * @param tranMap 料金検証対象外パターン
	 * @return String[] 配列[0]:マッチングキー(マスタ)、配列[1]:マッチングキー(トラン) 
	 * @throws Exception 業務サービス内で発生した例外全般
	 */
	private String[] getMatchKey(JBSbatServiceInterfaceMap mastMap, JBSbatServiceInterfaceMap tranMap) throws Exception
	{
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][getMatchKey]");
		
		// マッチングキーリスト(配列[0]:マッチングキー(マスタ) 、配列[1]:マッチングキー(トラン) 
		String[] macthKeyList = new String[2];
		
		StringBuffer keyBufMast = new StringBuffer();		
		keyBufMast.append(mastMap.getString(JBSbatAKIFM023.DATA_SBT));				// データ種別
		keyBufMast.append(mastMap.getString(JBSbatAKIFM023.PRC_GRP_CD));			// 料金グループコード
		keyBufMast.append(mastMap.getString(JBSbatAKIFM023.PCRS_CD));				// 料金コースコード
		keyBufMast.append(mastMap.getString(JBSbatAKIFM023.PRC_SVC_CD));			// 料金サービスコード
		keyBufMast.append(mastMap.getString(JBSbatAKIFM023.PRC_KMK_CD));			// 料金項目コード
		keyBufMast.append(mastMap.getString(JBSbatAKIFM023.PRC_TEISE_ADD_FLG));		// 料金訂正登録フラグ
		keyBufMast.append(mastMap.getString(JBSbatAKIFM023.IDO_DIV));				// 異動区分
		keyBufMast.append(mastMap.getString(JBSbatAKIFM023.PRG_STAT));				// 進捗ステータス
		macthKeyList[0] = keyBufMast.toString(); 									// マッチングキー（マスタ）生成
		
		StringBuffer keyBufTran = new StringBuffer();
		keyBufTran.append(tranMap.getString(JBSbatAKIFM024.DATA_SBT));				// データ種別
		keyBufTran.append(tranMap.getString(JBSbatAKIFM024.PRC_GRP_CD));			// 料金グループコード
		keyBufTran.append(tranMap.getString(JBSbatAKIFM024.PCRS_CD));				// 料金コースコード
		keyBufTran.append(tranMap.getString(JBSbatAKIFM024.PRC_SVC_CD));			// 料金サービスコード
		keyBufTran.append(tranMap.getString(JBSbatAKIFM024.PRC_KMK_CD));			// 料金項目コード
		keyBufTran.append(tranMap.getString(JBSbatAKIFM024.PRC_TEISE_ADD_FLG));		// 料金訂正登録フラグ
		keyBufTran.append(tranMap.getString(JBSbatAKIFM024.IDO_DIV));				// 異動区分
		keyBufTran.append(tranMap.getString(JBSbatAKIFM024.PRG_STAT));				// 進捗ステータス
		macthKeyList[1] = keyBufTran.toString(); 									// マッチングキー（トラン）生成
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][getMatchKey]");
		return macthKeyList;
	}
	
	/**
	 * 検証対象請求契約番号情報作成
	 * @param mastMap 請求内訳異動データ
	 * @return JBSbatServiceInterfaceMap		出力情報
	 * @throws Exception  業務サービス内で発生した例外全般
	 */
	private JBSbatServiceInterfaceMap makeOutputInfo(JBSbatServiceInterfaceMap mastMap) throws Exception
	{
		assert 	JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][makeOutputInfo]");
		
		// 検証対象請求契約番号情報マップ
		JBSbatServiceInterfaceMap retMap = new JBSbatServiceInterfaceMap();
		
		retMap.set(JBSbatAKIFM001.SEIKY_KEI_NO, mastMap.getString(JBSbatAKIFM023.SEIKY_KEI_NO));		// 請求契約番号
		
		retMap.setOutFlg(true);
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][makeOutputInfo][retMap=" + retMap.getMap().toString() + "]");
		assert 	JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][makeOutputInfo]");
		return retMap;
	}
	/**▲▲▲▲▲▲メソッド追加 終了▲▲▲▲▲▲*/
}
