/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatAKTouIdoChsht
*	ソースファイル名	：JBSbatAKTouIdoChsht.java
*	作成者				：富士通　
*	作成日				：2013年04月24日
*＜機能概要＞
*　当月異動情報抽出部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2013/04/24   富士通		新規作成
*********************************************************************/
package eo.business.service;

import eo.business.common.JACbatDebugLogUtil;
import eo.business.common.JBSbatBusinessService;
import eo.business.util.file.JBSbatAKIFM022;
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;

/**
 * 商用検証-料金-異動分抽出ツール<BR>
 * 当月異動情報抽出クラス
 * 
 * @author 富士通
 */
public class JBSbatAKTouIdoChsht extends JBSbatBusinessService
{
	/**▼▼▼▼▼▼ツールから生成した宣言です 開始▼▼▼▼▼▼*/
	/** テーブル(課金先)*/
	private static final String D_TBL_NAME_AK_CH_T_SEIKY = "AK_CH_T_SEIKY";

	/** SQL定義キー(AK_SELECT_004)*/
	private static final String AK_CH_T_SEIKY_AK_SELECT_004 = "AK_SELECT_004";

	/** テーブルアクセスクラス(課金先)*/
	private JBSbatSQLAccess db_AK_CH_T_SEIKY = null;
	/**▲▲▲▲▲▲ツールから生成した宣言です 終了▲▲▲▲▲▲*/

	/** フリー項目情報格納用配列 */
	private String[] fleeItemArray = null;

	/**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception 業務サービス内で発生した例外全般
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの初期処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した初期化のソースです 開始▼▼▼▼▼▼*/
		// 共通パラメータを設定します
		super.setCommonInfo(commonItem);

		// DBアクセスクラスを生成します
		db_AK_CH_T_SEIKY = new JBSbatSQLAccess(commonItem, D_TBL_NAME_AK_CH_T_SEIKY);
		/**▲▲▲▲▲▲ツールから生成した初期化のソースです 終了▲▲▲▲▲▲*/
		
		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 + "]");

		// フリー項目情報を取得
		fleeItemArray = super.freeItem.split(JACStrConst.FREE_DIV);
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][initial]");
	/**▲▲▲▲▲▲業務サービスの初期処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 主処理
	 * @param inMap　入力電文
	 * @return JBSbatOutputItem　出力情報
	 * @throws Exception 業務サービス内で発生した例外全般
	 */
	public JBSbatOutputItem execute() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの主処理を記述してください。▼▼▼▼▼▼*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute]");
		
		// 出力するデータの作成
		JBSbatOutputItem item = new JBSbatOutputItem();
		
		// 異動分レコードの検索
		this.selectZenIdoChsht();
		// 異動分レコードの出力
		this.setOutputItems(item);
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][execute]");
		return item;
	/**▲▲▲▲▲▲業務サービスの主処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 業務サービス終了処理
	 * @throws Exception 業務サービス内で発生した例外全般
	 */
	public void terminal() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの終了処理を記述してください。▼▼▼▼▼▼*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][terminal]");
		/**▼▼▼▼▼▼ツールから生成した終了処理のソースです 開始▼▼▼▼▼▼*/
		// DBアクセスクラスをクローズします
		db_AK_CH_T_SEIKY.close();
		/**▲▲▲▲▲▲ツールから生成した終了処理のソースです 終了▲▲▲▲▲▲*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][terminal]");
	/**▲▲▲▲▲▲業務サービスの終了処理を記述してください。▲▲▲▲▲▲*/
	}

	/**▼▼▼▼▼▼ツールから生成したメソッドです 開始▼▼▼▼▼▼*/

	/**
	 * SQLKEY(AK_SELECT_004)でDBアクセスを行います。<br>
	 * <p>
	 * <b>処理フロー</b><br>
	 * <pre>
	 * 1.引数でバイント変数を設定します。<br>
	 *
	 * 2.DBアクセスを実行します。<br>
	 * 
	 * 3.メソッドの呼び出し方です。<br>
	 *		引数:
	 *		param:順にバイント変数の値をparam配列に入れます。バイント変数は以下に説明します。
	 *		 	進捗年月日FROM
	 *		 	進捗年月日TO
	 * </pre>
	 * <p>
	 * @param param バイント変数の値配列。
	 * @throws Exception 業務サービス内で発生した例外全般。
	 */
	private void executeAK_CH_T_SEIKY_AK_SELECT_004(Object[] param) throws Exception
	{
		// バイント変数のリストを生成します
		JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface();
		paramList.setValue(param[0].toString());
		paramList.setValue(param[1].toString());

		// DBアクセスを実行します
		db_AK_CH_T_SEIKY.selectBySqlDefine(paramList, AK_CH_T_SEIKY_AK_SELECT_004);
	}
	/**▲▲▲▲▲▲ツールから生成したメソッドです 終了▲▲▲▲▲▲*/

	
	/**▼▼▼▼▼▼メソッド追加 開始▼▼▼▼▼▼*/

	/**
	 * SELECT文を発行するために必要なパラメタを設定する。
	 * 
	 * @throws Exception 業務サービス内で発生した例外全般
	 */
	private void selectZenIdoChsht() throws Exception {
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][svcKeiChstSelect001]");

		// DBアクセス用のパラメータ定義
		JBSbatCommonDBInterface dbList = new JBSbatCommonDBInterface();
		
		// 対象キーの設定
		dbList.setValue(fleeItemArray[0]);									// 進捗.進捗年月日時分秒の年月日
		dbList.setValue(fleeItemArray[1]);									// 進捗.進捗年月日時分秒の年月日
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][svcKeiChstSelect001][dbList=" + dbList.getList().toString() + "]");
		
		// サービス契約情報抽出
		executeAK_CH_T_SEIKY_AK_SELECT_004(dbList.getList().toArray());
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][svcKeiChstSelect001]");
		
		return;
	}

	/**
	 * 取得した当月の異動情報のレコードを出力する。
	 * 
	 * @param outputItem 出力情報のレコード
	 * @throws Exception 業務サービス内で発生した例外全般
	 */
	private void setOutputItems(JBSbatOutputItem outputItem) throws Exception {

		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][setOutputItems]");
		
		// DBからの検索結果の取得
		JBSbatCommonDBInterface rec = db_AK_CH_T_SEIKY.selectNext();
		
		JBSbatServiceInterfaceMap outRecord = null;
		
		while(null != rec)
		{
			assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][setOutputItems][rec=" + rec.getMap().toString() + "]");
			
			outRecord = new JBSbatServiceInterfaceMap();
			
			//取得したレコードを設定します
			// 請求契約番号
			outRecord.setString(JBSbatAKIFM022.SEIKY_KEI_NO, rec.getString(JBSbatAKIFM022.SEIKY_KEI_NO));
			// 進捗番号
			outRecord.setString(JBSbatAKIFM022.PRG_NO, rec.getString(JBSbatAKIFM022.PRG_NO));
			// 申込明細番号
			outRecord.setString(JBSbatAKIFM022.MSKM_DTL_NO, rec.getString(JBSbatAKIFM022.MSKM_DTL_NO));
			// サービス契約番号
			outRecord.setString(JBSbatAKIFM022.SVC_KEI_NO, rec.getString(JBSbatAKIFM022.SVC_KEI_NO));
			// サービス契約内訳番号
			outRecord.setString(JBSbatAKIFM022.SVC_KEI_UCWK_NO, rec.getString(JBSbatAKIFM022.SVC_KEI_UCWK_NO));
			// サービス契約回線内訳番号
			outRecord.setString(JBSbatAKIFM022.SVC_KEI_KAISEN_UCWK_NO, rec.getString(JBSbatAKIFM022.SVC_KEI_KAISEN_UCWK_NO));
			// 機器提供サービス契約番号
			outRecord.setString(JBSbatAKIFM022.KKTK_SVC_KEI_NO, rec.getString(JBSbatAKIFM022.KKTK_SVC_KEI_NO));
			// オプションサービス契約番号
			outRecord.setString(JBSbatAKIFM022.OP_SVC_KEI_NO, rec.getString(JBSbatAKIFM022.OP_SVC_KEI_NO));
			// 請求オプションサービス契約番号
			outRecord.setString(JBSbatAKIFM022.SEIOPSVC_KEI_NO, rec.getString(JBSbatAKIFM022.SEIOPSVC_KEI_NO));
			// サブオプションサービス契約番号
			outRecord.setString(JBSbatAKIFM022.SBOP_SVC_KEI_NO, rec.getString(JBSbatAKIFM022.SBOP_SVC_KEI_NO));
			// 割引サービス契約番号
			outRecord.setString(JBSbatAKIFM022.WRIB_SVC_KEI_NO, rec.getString(JBSbatAKIFM022.WRIB_SVC_KEI_NO));
			// 異動区分
			outRecord.setString(JBSbatAKIFM022.IDO_DIV, rec.getString(JBSbatAKIFM022.IDO_DIV));
			// 異動区分名
			outRecord.setString(JBSbatAKIFM022.IDO_DIV_NM, rec.getString("CD_DIV_NM"));
			// 異動年月日時分秒
			outRecord.setString(JBSbatAKIFM022.IDO_DTM, rec.getString(JBSbatAKIFM022.IDO_DTM));
			// 進捗ステータス
			outRecord.setString(JBSbatAKIFM022.PRG_STAT, rec.getString(JBSbatAKIFM022.PRG_STAT));
			// 進捗年月日時分秒
			outRecord.setString(JBSbatAKIFM022.PRG_DTM, rec.getString(JBSbatAKIFM022.PRG_DTM));
			// 進捗メモ
			outRecord.setString(JBSbatAKIFM022.PRG_MEMO, rec.getString(JBSbatAKIFM022.PRG_MEMO));
			// 進捗特記事項１
			outRecord.setString(JBSbatAKIFM022.PRG_TKJK_1, rec.getString(JBSbatAKIFM022.PRG_TKJK_1));
			// 進捗特記事項２
			outRecord.setString(JBSbatAKIFM022.PRG_TKJK_2, rec.getString(JBSbatAKIFM022.PRG_TKJK_2));

			// 出力フラグを設定します
			outRecord.setOutFlg(true);
			// 出力レコード1件設定します
			outputItem.addOutMapList(outRecord);
			// 次レコード
			rec = db_AK_CH_T_SEIKY.selectNext();	
		
		}
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][setOutputItems]");
	}
}
