/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatCHKeiStatInfSksi
*	ソースファイル名	：JBSbatCHKeiStatInfSksi.java
*	作成者				：富士通　
*	作成日				：2012年02月23日
*＜機能概要＞
*　契約状態情報作成部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2012/02/23   富士通		新規作成
*********************************************************************/
package eo.business.service;

import eo.business.common.JACbatDebugLogUtil;
import eo.business.common.JBSbatBusinessService;
import eo.business.common.JBSbatMatchServiceInterface;
import eo.business.util.file.JBSbatCHIFI008;
import eo.business.util.file.JBSbatCHIFM139;
import eo.common.constant.JACStrConst;
import eo.framework.item.JBSbatCommonItem;
import eo.framework.item.JBSbatOutputItem;
import eo.framework.item.JBSbatServiceInterfaceMap;

/**
* (クラスの機能概要) <p>
*<BR>
* @author 富士通
*/
public class JBSbatCHKeiStatInfSksi extends JBSbatBusinessService implements JBSbatMatchServiceInterface
{
	/**▼▼▼▼▼▼ツールから生成した宣言です 開始▼▼▼▼▼▼*/
	/** キーマッチ処理フラグ*/
	private boolean matchProcFlg;

	/** マスタファイル処理フラグ*/
	private boolean mastProcFlg;

	/** トランファイル処理フラグ*/
	private boolean tranProcFlg;
	/**▲▲▲▲▲▲ツールから生成した宣言です 終了▲▲▲▲▲▲*/
	
	/** マッチフラグ */
	private boolean tmpMatchFlg = false;

	/**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの初期処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した初期化のソースです 開始▼▼▼▼▼▼*/
		// 共通パラメータを設定します
		super.setCommonInfo(commonItem);
		/**▲▲▲▲▲▲ツールから生成した初期化のソースです 終了▲▲▲▲▲▲*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][initial]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][initial][opeDate=" + super.opeDate + "]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][initial][freeItem=" + super.freeItem + "]");
		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;
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute][tmpMatchFlg=" + this.tmpMatchFlg + "]");
		
		// トランのみの場合
		if(mastMap == null)
		{
			assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][execute][トランのみ]");
			this.setTranProcFlg(true);
		}
		// マスタのみの場合
		else if(tranMap == null)
		{
			assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][execute][マスタのみ]");
			
			// 退避．マッチフラグ＝falseの場合
			if(!tmpMatchFlg)
			{
				// 出力情報を設定します。
				this.setOutputInf(mastMap, outputInItem);
			}
			// 退避．マッチフラグ更新
			this.tmpMatchFlg = false;
			
			this.setMastProcFlg(true);
		}
		// 上記以外の場合
		else
		{
			// マスタキー
			String mastKey = mastMap.getString(JBSbatCHIFM139.SEIKY_KEI_NO);
			// トランキー
			String tranKey = tranMap.getString(JBSbatCHIFI008.SEIKY_KEI_NO);
			
			// マッチの場合
			if(mastKey.equals(tranKey))
			{
				assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][execute][マッチ]");
				
				// 退避．マッチフラグ更新
				this.tmpMatchFlg = true;
				
				// 出力情報を設定します。
				this.setOutputInf(mastMap, outputInItem);
				
				this.setMatchProcFlg(true);
			}
			// マスタキー＜トランキーの場合
			else if(mastKey.compareTo(tranKey) < 0)
			{
				assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][execute][マスタキー＜トランキー]");
				
				// 退避．マッチフラグ＝falseの場合
				if(!tmpMatchFlg)
				{
					// 出力情報を設定します。
					this.setOutputInf(mastMap, outputInItem);
				}
				
				// 退避．マッチフラグ更新
				this.tmpMatchFlg = false;
				
				this.setMastProcFlg(true);
				
				
			}
			// 上記以外の場合
			else
			{
				assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][execute][マスタキー＞トランキー]");
				
				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 outputInItem 出力情報
	 * @throws Exception 業務サービス内で発生した例外全般。
	 */
	private void setOutputInf(JBSbatServiceInterfaceMap mastMap, JBSbatOutputItem outputInItem) throws Exception
	{
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][setOutputInf]");
		
		JBSbatServiceInterfaceMap outBean = new JBSbatServiceInterfaceMap();
		
		// 請求契約番号
		outBean.set(JBSbatCHIFM139.SEIKY_KEI_NO, mastMap.get(JBSbatCHIFM139.SEIKY_KEI_NO));
		// 請求契約配下サービス契約状態
		if(this.tmpMatchFlg)
		{
			// マッチした場合
			outBean.set(JBSbatCHIFM139.SKHK_SVKEI_STAT_CD, JACStrConst.SVC_KEI_STAT_TEKKYO_KOJI);
		}
		else
		{
			// マッチしていない場合
			outBean.set(JBSbatCHIFM139.SKHK_SVKEI_STAT_CD, mastMap.get(JBSbatCHIFM139.SKHK_SVKEI_STAT_CD));
		}
		// 請求契約配下サービス契約解約理由識別 
		outBean.set(JBSbatCHIFM139.SKHK_SVKEI_DLRE_SKBT_CD, mastMap.get(JBSbatCHIFM139.SKHK_SVKEI_DLRE_SKBT_CD));
		// サービス課金終了年月日
		outBean.set(JBSbatCHIFM139.SVC_CHRG_ENDYMD, mastMap.get(JBSbatCHIFM139.SVC_CHRG_ENDYMD));
		
		outBean.setOutFlg(true);
		
		outputInItem.addOutMapList(outBean);
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][setOutputInf]");
	}
	
	/**▲▲▲▲▲▲メソッド追加 終了▲▲▲▲▲▲*/
	
}
