/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatCHKyoseiDslReq
*	ソースファイル名	：JBSbatCHKyoseiDslReq.java
*	作成者				：富士通　
*	作成日				：2012年02月13日
*＜機能概要＞
*　強制解約依頼部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2012/02/13   富士通		新規作成
*	v3.00		2012/06/08   FJ)山下	【ANK-0024】処理分割
*********************************************************************/
package eo.business.service;

import eo.business.common.JACbatDebugLogUtil;
import eo.business.common.JACbatParamUtil;
import eo.business.common.JBSbatBusinessService;
import eo.business.util.file.JBSbatCHIFM101;
import eo.business.util.file.JBSbatKKIFI004;
import eo.business.util.table.JBSbatCH_M_PRC_SCHDL_TEIGI;
import eo.common.constant.JACStrConst;
import eo.common.constant.JPCBatchMessageConstant;
import eo.framework.application.JBSbatBusinessException;
import eo.framework.db.JBSbatSQLAccess;
import eo.framework.item.JBSbatCommonDBInterface;
import eo.framework.item.JBSbatCommonItem;
import eo.framework.item.JBSbatOutputItem;
import eo.framework.item.JBSbatServiceInterfaceMap;

/**
* (クラスの機能概要) <p>
*<BR>
* @author 富士通
*/
public class JBSbatCHKyoseiDslReq extends JBSbatBusinessService
{
	/**▼▼▼▼▼▼ツールから生成した宣言です 開始▼▼▼▼▼▼*/
	/** テーブル(料金スケジュール定義)*/
	private static final String D_TBL_NAME_CH_M_PRC_SCHDL_TEIGI = "CH_M_PRC_SCHDL_TEIGI";

	/** SQL定義キー(CH_SELECT_013)*/
	private static final String CH_M_PRC_SCHDL_TEIGI_CH_SELECT_013 = "CH_SELECT_013";

	/** テーブルアクセスクラス(料金スケジュール定義)*/
	private JBSbatSQLAccess db_CH_M_PRC_SCHDL_TEIGI = null;
	/**▲▲▲▲▲▲ツールから生成した宣言です 終了▲▲▲▲▲▲*/
	
	/** 退避．督促データ識別(強制解約情報データ)*/
	private String tokusokuDataSkbt09 = null;
	
	/** 強制解約日*/
	private String kyoseiDslDay = null;

	/**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの初期処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した初期化のソースです 開始▼▼▼▼▼▼*/
		// 共通パラメータを設定します
		super.setCommonInfo(commonItem);

		// DBアクセスクラスを生成します
		db_CH_M_PRC_SCHDL_TEIGI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_CH_M_PRC_SCHDL_TEIGI);
		/**▲▲▲▲▲▲ツールから生成した初期化のソースです 終了▲▲▲▲▲▲*/
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][initial]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][initial][opeDate=" + super.opeDate + "]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][initial][freeItem=" + super.freeItem + "]");
		
		// パラメータ取得部品の初期処理を行う
		JACbatParamUtil paramUtil = new JACbatParamUtil(commonItem);
		this.tokusokuDataSkbt09 = paramUtil.getGyoumuParameter(JACStrConst.WKPARA_CH_TKSK_DATA_SKBT_09);
		paramUtil.close();
		
		// 強制解約日の取得
		this.kyoseiDslDay = selectEventYmd();
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][initial][tokusokuDataSkbt09=" + this.tokusokuDataSkbt09 + "]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][initial]");
		
	/**▲▲▲▲▲▲業務サービスの初期処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 主処理
	 * @param inMap　入力電文
	 * @return JBSbatOutputItem　出力情報
	 * @throws Exception
	 */
	public JBSbatOutputItem execute(JBSbatServiceInterfaceMap inMap) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの主処理を記述してください。▼▼▼▼▼▼*/
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute]");
		assert inMap != null ? JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute][Map=" + inMap.getMap().toString() + "]") : true;
		
		// 督促データ識別判定
		if(!this.tokusokuDataSkbt09.equals(inMap.getString(JBSbatCHIFM101.TOKUSOKU_DATA_SKBT)))
		{
			// 次レコードへ
			return null;
		}
		
		// 強制解約依頼情報作成
		JBSbatOutputItem outputItem = new JBSbatOutputItem();
		JBSbatServiceInterfaceMap outMap = new JBSbatServiceInterfaceMap();
		
		// 1.請求契約番号
		outMap.setString(JBSbatKKIFI004.REQ_SEIKY_NO, inMap.getString(JBSbatCHIFM101.SEIKY_KEI_NO));
		// 2.依頼年月日
		outMap.setString(JBSbatKKIFI004.REQYMD, super.opeDate);
		// 3.サービス課金終了年月日
		outMap.setString(JBSbatKKIFI004.SVC_CHRG_ENDYMD, this.kyoseiDslDay);
		
		// 出力
		outMap.setOutFlg(true);
		outputItem.addOutMapList(outMap);
		assert outMap != null ? JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][execute][outMap=" + outMap.getMap().toString() + "]") : true;
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][execute]");
		
		return outputItem;
	/**▲▲▲▲▲▲業務サービスの主処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 業務サービス終了処理
	 * @throws Exception
	 */
	public void terminal() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの終了処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した終了処理のソースです 開始▼▼▼▼▼▼*/
		// DBアクセスクラスをクローズします
		db_CH_M_PRC_SCHDL_TEIGI.close();
		/**▲▲▲▲▲▲ツールから生成した終了処理のソースです 終了▲▲▲▲▲▲*/

		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][terminal]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][terminal]");
		
	/**▲▲▲▲▲▲業務サービスの終了処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 強制解約日を取得します。
	 * 
	 * @return trnKanriNo 強制解約日
	 * @throws Exception 業務サービス内で発生した例外全般
	 */
	private String selectEventYmd() throws Exception
	{
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][selectEventYmd]");
		
		JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface();
		
		// イベントコード
		paramList.setValue(JACStrConst.EVENT_CD_KYOSEI_KAIYAKU_YMD);
		// イベント年月日
		paramList.setValue(super.opeDate);
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][selectEventYmd][paramList=" + paramList.getList().toString() + "]");
		
		// SQL実行
		executeCH_M_PRC_SCHDL_TEIGI_CH_SELECT_013(paramList.getList().toArray());
		JBSbatCommonDBInterface dbMap = db_CH_M_PRC_SCHDL_TEIGI.selectNext(); 
		
		// 取得結果判定
		if (dbMap == null)
		{
			// DB未存在エラー
			String[] msgParam = new String[]{JBSbatCH_M_PRC_SCHDL_TEIGI.TABLE_NAME, paramList.getList().toString()};
			throw new JBSbatBusinessException(JPCBatchMessageConstant.ECHB0270CH, msgParam);
		}
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][selectEventYmd][dbMap=" + dbMap.getMap().toString() + "]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][selectEventYmd]");
		
		return dbMap.getString(JBSbatCH_M_PRC_SCHDL_TEIGI.EVENT_YMD);
	}

	/**▼▼▼▼▼▼ツールから生成したメソッドです 開始▼▼▼▼▼▼*/
	/**
	 * SQLKEY(CH_SELECT_013)でDBアクセスを行います。<br>
	 * <p>
	 * <b>処理フロー</b><br>
	 * <pre>
	 * 1.引数でバイント変数を設定します。<br>
	 *
	 * 2.DBアクセスを実行します。<br>
	 * 
	 * 3.メソッドの呼び出し方です。<br>
	 *		引数:
	 *		param:順にバイント変数の値をparam配列に入れます。バイント変数は以下に説明します。
	 *		 	イベントコード
	 *		 	イベント年月日
	 * </pre>
	 * <p>
	 * @param param バイント変数の値配列。
	 * @throws Exception 業務サービス内で発生した例外全般。
	 */
	private void executeCH_M_PRC_SCHDL_TEIGI_CH_SELECT_013(Object[] param) throws Exception
	{
		// バイント変数のリストを生成します
		JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface();
		paramList.setValue(param[0].toString());
		paramList.setValue(param[1].toString());

		// DBアクセスを実行します
		db_CH_M_PRC_SCHDL_TEIGI.selectBySqlDefine(paramList, CH_M_PRC_SCHDL_TEIGI_CH_SELECT_013);
	}
	/**▲▲▲▲▲▲ツールから生成したメソッドです 終了▲▲▲▲▲▲*/
}
