/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatCHSksHakCmsYoksiInfSksi
*	ソースファイル名	：JBSbatCHSksHakCmsYoksiInfSksi.java
*	作成者				：富士通　
*	作成日				：2011年09月22日
*＜機能概要＞
*　請求書発行手数料抑止情報作成部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2011/09/22   富士通		新規作成
*********************************************************************/
package eo.business.service;

import eo.business.common.JACbatDebugLogUtil;
import eo.business.common.JBSbatBusinessService;
import eo.business.util.file.JBSbatCHIFM065;
import eo.business.util.file.JBSbatCHIFM087;
import eo.business.util.table.JBSbatKK_T_SEIKY_YOKSI;
import eo.common.constant.JACStrConst;
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 JBSbatCHSksHakCmsYoksiInfSksi extends JBSbatBusinessService
{
	/**▼▼▼▼▼▼ツールから生成した宣言です 開始▼▼▼▼▼▼*/
	/** テーブル(請求抑止)*/
	private static final String D_TBL_NAME_KK_T_SEIKY_YOKSI = "KK_T_SEIKY_YOKSI";

	/** SQL定義キー(CH_SELECT_004)*/
	private static final String KK_T_SEIKY_YOKSI_CH_SELECT_004 = "CH_SELECT_004";

	/** テーブルアクセスクラス(請求抑止)*/
	private JBSbatSQLAccess db_KK_T_SEIKY_YOKSI = null;
	/**▲▲▲▲▲▲ツールから生成した宣言です 終了▲▲▲▲▲▲*/

	/**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの初期処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した初期化のソースです 開始▼▼▼▼▼▼*/
		// 共通パラメータを設定します
		super.setCommonInfo(commonItem);

		// DBアクセスクラスを生成します
		db_KK_T_SEIKY_YOKSI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_SEIKY_YOKSI);
		/**▲▲▲▲▲▲ツールから生成した初期化のソースです 終了▲▲▲▲▲▲*/
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][initial]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][initial][opeDate=" + super.opeDate + "]");
		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 JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute][inMap=" + inMap.getMap().toString() + "]");
		
		JBSbatOutputItem outputBean = new JBSbatOutputItem();
		
		// 請求抑止フラグ取得
		String seikyYokushiFlg = getSeikyYokushiFlg(inMap.getString(JBSbatCHIFM087.SEIKY_KEI_NO));
		
		// 抑止ありの場合、抑止情報を作成する
		if (JACStrConst.YOKSI_FLG_ARI.equals(seikyYokushiFlg))
		{
			// 抑止情報作成
			outputBean.addOutMapList(makeYokushiInfo(inMap));
		}
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][execute]");
		
		return outputBean;
	/**▲▲▲▲▲▲業務サービスの主処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 請求抑止テーブルから請求抑止フラグを取得します。
	 * 
	 * @param seikyKeiNo 請求契約番号
	 * @return 請求抑止フラグ
	 * @throws Exception 
	 */
	private String getSeikyYokushiFlg(String seikyKeiNo) throws Exception
	{
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][selectSeikyYokushiFlg]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][selectSeikyYokushiFlg][seikyKeiNo=" + seikyKeiNo + "]");
		
		// 条件設定
		JBSbatCommonDBInterface whereParam = new JBSbatCommonDBInterface();
		whereParam.setValue(seikyKeiNo);
		whereParam.setValue(JACStrConst.SEIKY_YOKSI_CD_HAK_CMS_YOKSI);
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][selectSeikyYokushiFlg][whereParam = " + whereParam.getList().toString() + "]");
		
		String seikyYoksiFlg = null;
		
		// SQL実行
		executeKK_T_SEIKY_YOKSI_CH_SELECT_004(whereParam.getList().toArray());
		
		JBSbatCommonDBInterface seikyYoksiInfo = db_KK_T_SEIKY_YOKSI.selectNext();
		
		// 請求抑止情報を取得できた場合
		if (seikyYoksiInfo != null)
		{
			seikyYoksiFlg = seikyYoksiInfo.getString(JBSbatKK_T_SEIKY_YOKSI.SEIKY_YOKSI_FLG);
		}
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][getSeikyYokushiFlg][seikyYoksiFlg = " + seikyYoksiFlg + "]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][getSeikyYokushiFlg]");
		
		return seikyYoksiFlg;
	}

	/**
	 * 抑止情報を作成します。
	 * 
	 * @param 入力電文
	 * @return 抑止情報
	 * @throws Exception 
	 */
	private JBSbatServiceInterfaceMap makeYokushiInfo(JBSbatServiceInterfaceMap inMap) throws Exception
	{
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][makeYokushiInfo]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][makeYokushiInfo][inMap=" + inMap.getMap().toString() + "]");
		
		JBSbatServiceInterfaceMap outMap = new JBSbatServiceInterfaceMap();
		
		// 請求契約番号
		outMap.setString(JBSbatCHIFM065.SEIKY_KEI_NO, inMap.getString(JBSbatCHIFM087.SEIKY_KEI_NO));
		// 請求年月
		outMap.setString(JBSbatCHIFM065.SEIKY_YM, inMap.getString(JBSbatCHIFM087.SEIKY_YM));
		// 発行抑止コード
		outMap.setString(JBSbatCHIFM065.HAK_YOKSI_CD, JACStrConst.SEIKY_YOKSI_CD_HAK_CMS_YOKSI);
		
		// 出力フラグON
		outMap.setOutFlg(true);
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][makeYokushiInfo][outMap=" + outMap.getMap().toString() + "]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][makeYokushiInfo]");
		
		return outMap;
	}

	/**
	 * 業務サービス終了処理
	 * @throws Exception
	 */
	public void terminal() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの終了処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した終了処理のソースです 開始▼▼▼▼▼▼*/
		// DBアクセスクラスをクローズします
		db_KK_T_SEIKY_YOKSI.close();
		/**▲▲▲▲▲▲ツールから生成した終了処理のソースです 終了▲▲▲▲▲▲*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][terminal]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][terminal]");
	/**▲▲▲▲▲▲業務サービスの終了処理を記述してください。▲▲▲▲▲▲*/
	}

	/**▼▼▼▼▼▼ツールから生成したメソッドです 開始▼▼▼▼▼▼*/
	/**
	 * SQLKEY(CH_SELECT_004)でDBアクセスを行います。<br>
	 * <p>
	 * <b>処理フロー</b><br>
	 * <pre>
	 * 1.引数でバイント変数を設定します。<br>
	 *
	 * 2.DBアクセスを実行します。<br>
	 * 
	 * 3.メソッドの呼び出し方です。<br>
	 *		引数:
	 *		param:順にバイント変数の値をparam配列に入れます。バイント変数は以下に説明します。
	 *		 	請求契約番号
	 *		 	請求抑止コード
	 * </pre>
	 * <p>
	 * @param param バイント変数の値配列。
	 * @throws Exception 業務サービス内で発生した例外全般。
	 */
	private void executeKK_T_SEIKY_YOKSI_CH_SELECT_004(Object[] param) throws Exception
	{
		// バイント変数のリストを生成します
		JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface();
		paramList.setValue(param[0].toString());
		paramList.setValue(param[1].toString());

		// DBアクセスを実行します
		db_KK_T_SEIKY_YOKSI.selectBySqlDefine(paramList, KK_T_SEIKY_YOKSI_CH_SELECT_004);
	}
	/**▲▲▲▲▲▲ツールから生成したメソッドです 終了▲▲▲▲▲▲*/
}
