/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatACTrgtSvcKeiDel
*	ソースファイル名	：JBSbatACTrgtSvcKeiDel.java
*	作成者				：富士通　
*	作成日				：2012年08月24日
*＜機能概要＞
*　課金対象従量サービス契約情報削除部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v3.00.00	2012/08/24   富士通		【TG1-2012-0000123】新規作成
*	v4.00.00	2013/03/08   FJ)岡田	【TG1-2013-0000070】通信料未取込対応
*	v4.00.01	2013/04/14   FJ)早崎	【TG1-2013-0000153】TG1-2013-0000070対応戻し対応
*********************************************************************/
package eo.business.service;

import eo.business.common.JACbatDebugLogUtil;
import eo.business.common.JACbatSchdlUtil;
import eo.business.common.JBSbatBusinessService;
import eo.business.common.JBSbatInterface;
import eo.common.constant.JACStrConst;
import eo.common.constant.JPCBatchMessageConstant;
import eo.framework.item.JBSbatCommonItem;
import eo.framework.item.JBSbatOutputItem;
import eo.framework.item.JBSbatCommonDBInterface;
import eo.framework.db.JBSbatSQLAccess;

/**
* (クラスの機能概要) <p>
*<BR>
* @author 富士通
*/
public class JBSbatACTrgtSvcKeiDel extends JBSbatBusinessService
{
	/**▼▼▼▼▼▼ツールから生成した宣言です 開始▼▼▼▼▼▼*/
	/** テーブル(課金対象従量サービス契約蓄積)*/
	private static final String D_TBL_NAME_AC_T_CHRG_JSVKEI_CKS = "AC_T_CHRG_JSVKEI_CKS";

	/** SQL定義キー(AC_DELETE_001)*/
	private static final String AC_T_CHRG_JSVKEI_CKS_AC_DELETE_001 = "AC_DELETE_001";

	/** テーブルアクセスクラス(課金対象従量サービス契約蓄積)*/
	private JBSbatSQLAccess db_AC_T_CHRG_JSVKEI_CKS = null;
	/**▲▲▲▲▲▲ツールから生成した宣言です 終了▲▲▲▲▲▲*/

	/** 請求年月用月調整（２ヶ月前） */
	private static final int MON_NUM_2 = -2;
	
	/** 削除件数ログ用置換文字列*/
	private static final String MSG_REP = "課金対象従量サービス契約蓄積";
	
	/** 請求年月（2か月前） */
	private String skyYm2 = "";
	
	/** 請求年月（当月） */
	private String skyYm = "";
	
	/**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの初期処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した初期化のソースです 開始▼▼▼▼▼▼*/
		// 共通パラメータを設定します
		super.setCommonInfo(commonItem);

		// DBアクセスクラスを生成します
		db_AC_T_CHRG_JSVKEI_CKS = new JBSbatSQLAccess(commonItem, D_TBL_NAME_AC_T_CHRG_JSVKEI_CKS);
		/**▲▲▲▲▲▲ツールから生成した初期化のソースです 終了▲▲▲▲▲▲*/

		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][initial]");
		
		// 請求年月取得
		JACbatSchdlUtil schdlObj = new JACbatSchdlUtil(commonItem);
		
		// イベントコード（利用終了日）に対する請求年月を取得する
		skyYm = schdlObj.getBillDate(super.opeDate, JACStrConst.EVENT_CD_USE_ENDYMD);
		
		// 月調整（2ヶ月前）
		skyYm2 = JBSbatInterface.adjustMonth(skyYm + "01", MON_NUM_2).substring(0, 6);
		
		
		// 削除対象となる請求年月の基準
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][initial] 削除対象請求年月（2か月前）：" + skyYm2);
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][initial] 削除対象請求年月（当月）：" + skyYm);

		schdlObj.close();
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][initial]");
	/**▲▲▲▲▲▲業務サービスの初期処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 主処理
	 * @return JBSbatOutputItem　出力情報
	 * @throws Exception
	 */
	public JBSbatOutputItem execute() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの主処理を記述してください。▼▼▼▼▼▼*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute]");
		
		// 削除件数
		int cnt = 0;
		
			// 削除キーの設定
			JBSbatCommonDBInterface dbList = new JBSbatCommonDBInterface();
			dbList.setValue(skyYm2); 	// 請求年月（2か月前）
			dbList.setValue(skyYm); 	// 請求年月（当月）
			
			// サービス契約情報クリア(返値:削除件数)
			cnt = executeAC_T_CHRG_JSVKEI_CKS_AC_DELETE_001(dbList.getList().toArray());
		
		// 削除件数ログ出力
		super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EACB0540AI, 
				 new String[]{MSG_REP, Integer.toString(cnt)});
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][execute]");
		return null;
	/**▲▲▲▲▲▲業務サービスの主処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 業務サービス終了処理
	 * @throws Exception
	 */
	public void terminal() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの終了処理を記述してください。▼▼▼▼▼▼*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][terminal]");
		/**▼▼▼▼▼▼ツールから生成した終了処理のソースです 開始▼▼▼▼▼▼*/
		// DBアクセスクラスをクローズします
		db_AC_T_CHRG_JSVKEI_CKS.close();
		/**▲▲▲▲▲▲ツールから生成した終了処理のソースです 終了▲▲▲▲▲▲*/
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][terminal]");
	/**▲▲▲▲▲▲業務サービスの終了処理を記述してください。▲▲▲▲▲▲*/
	}


	/**▼▼▼▼▼▼ツールから生成したメソッドです 開始▼▼▼▼▼▼*/
	/**
	 * SQLKEY(AC_DELETE_001)でDBアクセスを行います。<br>
	 * <p>
	 * <b>処理フロー</b><br>
	 * <pre>
	 * 1.引数でバイント変数を設定します。<br>
	 *
	 * 2.DBアクセスを実行します。<br>
	 * 
	 * 3.メソッドの呼び出し方です。<br>
	 *		引数:
	 *		param:順にバイント変数の値をparam配列に入れます。バイント変数は以下に説明します。
	 *		 	請求年月（2か月前）
	 *		 	請求年月（当月）
	 * </pre>
	 * <p>
	 * @param param バイント変数の値配列。
	 * @return 削除件数
	 * @throws Exception 業務サービス内で発生した例外全般。
	 */
	private int executeAC_T_CHRG_JSVKEI_CKS_AC_DELETE_001(Object[] param) throws Exception
	{
		// バイント変数のリストを生成します
		JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface();
		paramList.setValue(param[0].toString());
		paramList.setValue(param[1].toString());

		// DBアクセスを実行します
		return db_AC_T_CHRG_JSVKEI_CKS.executeBySqlDefine(paramList, AC_T_CHRG_JSVKEI_CKS_AC_DELETE_001);
	}

	/**▲▲▲▲▲▲ツールから生成したメソッドです 終了▲▲▲▲▲▲*/
}
