/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			： eo顧客基幹システム
*	モジュール名		：JBSbatCKEditCustChgInfo
*	ソースファイル名	：JBSbatCKEditCustChgInfo.java
*	作成者				： GDC)ニール
*	作成日				：2020年03月20日
*＜機能概要＞
*　顧客情報を編集する機能
*＜修正履歴＞
*
*	バージョン	修正日		修正者		修正内容
*   v49.00.00   2020/03/20  GDC)ニール  【ANK-3815-00-00】eo顧客変更情報mineo連携
*********************************************************************/
package eo.business.service;

import java.util.Arrays;
import java.util.Comparator;

import eo.business.common.JBSbatBusinessService;
import eo.business.common.JKKBatConst;
import eo.business.util.file.JBSbatCKIFE061;
import eo.business.util.file.JBSbatCKIFM028;
import eo.business.util.table.JBSbatCK_T_CUST;
import eo.business.util.table.JBSbatCK_T_CUST_KOJIN;
import eo.business.util.table.JBSbatCK_T_RRKS;
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 JBSbatCKEditCustChgInfo extends JBSbatBusinessService {
	/** テーブル(CK_T_CUST) */
	private static final String D_TBL_NAME_CK_T_CUST = "CK_T_CUST";
	
	/** テーブル(CK_T_CUST_KOJIN)*/
	private static final String D_TBL_NAME_CK_T_CUST_KOJIN = "CK_T_CUST_KOJIN";
	
	/** テーブル(CK_T_RRKS) */
	private static final String D_TBL_NAME_CK_T_RRKS = "CK_T_RRKS";
	
	private static final String CK_T_CUST_SELECT_018_STR = "CK_SELECT_018";
	
	private static final String CK_T_RRKS_SELECT_008_STR = "CK_SELECT_008";

	private JBSbatSQLAccess db_CK_T_CUST = null;

	private JBSbatSQLAccess db_CK_T_CUST_KOJIN = null;
	
	private JBSbatSQLAccess db_CK_T_RRKS = null;

	private String lastSendTimeStamp;

	private String lastSendOperationDate;
	
	private String currentSendTimeStamp;
	
	private String currentSendOperationDate;
	
	private enum IDO_NAIYO {
		ONE("01"), TWO("02"), THREE("03"), FOUR("04"), FIVE("05"), SIX("06"), SEVEN("07"), EIGHT("08"), NINE("09"), TEN("10");
		
		private String value;
		
		IDO_NAIYO(String value) {
			this.value = value;
		}
		
		public String getValue() {
			return this.value;
		}
	}
	
	private enum CK_T_RRKS_SELECT_008 {
		MAIL_ADDRESS_TO_CONTACT("001", "5"), MOBILE_PHONE_NO_TO_CONTACT("003", "2"), ANOTHER_PHONE_NO_TO_CONTACT_1("003", "5"), PHONE_EXTENSION_TO_CONTACT("004", "3"),
		MAIL_ADDRESS_TO_BUY_CONTENTS("001", "1"), PHONE_NO_TO_BUY_CONTENTS("003", "1");

		private String rrkWayCd;
		private String rrksSbtCd;
		
		CK_T_RRKS_SELECT_008(String rrkWayCd, String rrksSbtCd) {
			this.rrkWayCd = rrkWayCd;
			this.rrksSbtCd = rrksSbtCd;
		}

		public String getRrkWayCd() {
			return rrkWayCd;
		}

		public String getRrksSbtCd() {
			return rrksSbtCd;
		}
	}
	
	/**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception {
		super.setCommonInfo(commonItem);
		
		db_CK_T_CUST = new JBSbatSQLAccess(commonItem, D_TBL_NAME_CK_T_CUST);
		db_CK_T_CUST_KOJIN = new JBSbatSQLAccess(commonItem, D_TBL_NAME_CK_T_CUST_KOJIN);
		db_CK_T_RRKS = new JBSbatSQLAccess(commonItem, D_TBL_NAME_CK_T_RRKS);
		
		// 1. get last/current timeStamp and operationDate from "FREE" parameter
		String[] freeItems = commonItem.getFreeItem().split(JKKBatConst.S_PARAM_DELIM);

		if (freeItems.length == 0 || freeItems.length < 4) {
			super.logPrint.printDebugLog("The freeItem is incomplete.");
			return;
		} else {
			for (String freeItem : freeItems) {
				if (freeItem.trim().isEmpty()) {
					super.logPrint.printDebugLog("The freeItem is empty.");
					return;
				}
			}
		}

		this.lastSendTimeStamp = freeItems[0];
		super.logPrint.printDebugLog("lastSendTimeStamp : " + this.lastSendTimeStamp);
		this.lastSendOperationDate = freeItems[1];
		super.logPrint.printDebugLog("lastSendOperationDate : " + this.lastSendOperationDate);
		this.currentSendTimeStamp = freeItems[2];
		super.logPrint.printDebugLog("currentSendTimeStamp : " + this.currentSendTimeStamp);
		this.currentSendOperationDate = freeItems[3];
		super.logPrint.printDebugLog("currentSendOperationDate : " + this.currentSendOperationDate);

		super.logPrint.printDebugLog("Done Initialization");
	}

	/**
	 * 主処理
	 * @param inMap　入力電文
	 * @throws Exception
	 */
	public JBSbatOutputItem execute(JBSbatServiceInterfaceMap inMap) throws Exception {
		JBSbatOutputItem outputBean = new JBSbatOutputItem();
		String sysID = (String) inMap.getString(JBSbatCKIFM028.SYSID);
		super.logPrint.printDebugLog("Searching for SYSID : " + sysID);

		JBSbatCommonDBInterface current_CK_T_CUST  = execute_CK_T_CUST_SELECT_018(sysID, this.currentSendOperationDate, this.currentSendTimeStamp);
		JBSbatCommonDBInterface past_CK_T_CUST  = execute_CK_T_CUST_SELECT_018(sysID, this.lastSendOperationDate, this.lastSendTimeStamp);
		JBSbatCommonDBInterface current_CK_T_CUST_PK  = null;
		JBSbatCommonDBInterface current_CK_T_CUST_KOJIN_PK  = null;
		JBSbatCommonDBInterface past_CK_T_CUST_PK  = null;
		JBSbatCommonDBInterface past_CK_T_CUST_KOJIN_PK  = null;
		
		if (current_CK_T_CUST != null) {
			// お客様スキーマのカレントレコード取得（無効化されている場合は空マップ返却）
			String currentSYSID = current_CK_T_CUST.getString(JBSbatCK_T_CUST.SYSID);	
			current_CK_T_CUST_PK = execute_CK_T_CUST_byPK(currentSYSID, current_CK_T_CUST.getString(JBSbatCK_T_CUST.GENE_ADD_DTM));
			current_CK_T_CUST_KOJIN_PK  = execute_CK_T_CUST_KOJIN_byPK(currentSYSID, current_CK_T_CUST.getString(JBSbatCK_T_CUST.GENE_ADD_DTM));
			
			// 無効化されていた場合は空マップに削除運用日だけ設定する（後続処理で日付判定に使用）
			if(current_CK_T_CUST_PK!=null && current_CK_T_CUST_PK.getMap().isEmpty()){
				current_CK_T_CUST_PK.setValue(JBSbatCK_T_CUST.DEL_UNYO_YMD, current_CK_T_CUST.getString(JBSbatCK_T_CUST.DEL_UNYO_YMD));
			}
			if(current_CK_T_CUST_KOJIN_PK!=null && current_CK_T_CUST_KOJIN_PK.getMap().isEmpty()){
				current_CK_T_CUST_KOJIN_PK.setValue(JBSbatCK_T_CUST.DEL_UNYO_YMD, current_CK_T_CUST.getString(JBSbatCK_T_CUST.DEL_UNYO_YMD));
			}
			
			// 予約適用年月日をお客様個人にもコピー（後続処理で日付判定に使用）
			if(current_CK_T_CUST_PK!=null && current_CK_T_CUST_KOJIN_PK!=null){
				current_CK_T_CUST_KOJIN_PK.setValue(JBSbatCK_T_CUST.RSV_APLY_YMD, current_CK_T_CUST_PK.getString(JBSbatCK_T_CUST.RSV_APLY_YMD));
			}
		}
		
		if (past_CK_T_CUST != null) {
			// お客様スキーマの過去断面レコード取得（無効化されている場合は空マップ返却）
			String pastSYSID = past_CK_T_CUST.getString(JBSbatCK_T_CUST.SYSID);
			past_CK_T_CUST_PK  = execute_CK_T_CUST_byPK(pastSYSID, past_CK_T_CUST.getString(JBSbatCK_T_CUST.GENE_ADD_DTM));
			past_CK_T_CUST_KOJIN_PK  = execute_CK_T_CUST_KOJIN_byPK(pastSYSID, past_CK_T_CUST.getString(JBSbatCK_T_CUST.GENE_ADD_DTM));
			
			// 無効化されていた場合は空マップに削除運用日だけ設定する（後続処理で日付判定に使用）
			if(past_CK_T_CUST_PK!=null && past_CK_T_CUST_PK.getMap().isEmpty()){
				past_CK_T_CUST_PK.setValue(JBSbatCK_T_CUST.DEL_UNYO_YMD, past_CK_T_CUST.getString(JBSbatCK_T_CUST.DEL_UNYO_YMD));
			}
			if(past_CK_T_CUST_KOJIN_PK!=null && past_CK_T_CUST_KOJIN_PK.getMap().isEmpty()){
				past_CK_T_CUST_KOJIN_PK.setValue(JBSbatCK_T_CUST.DEL_UNYO_YMD, past_CK_T_CUST.getString(JBSbatCK_T_CUST.DEL_UNYO_YMD));
			}
			
			// 予約適用年月日をお客様個人にもコピー（後続処理で日付判定に使用）
			if(past_CK_T_CUST_PK!=null && past_CK_T_CUST_KOJIN_PK!=null){
				past_CK_T_CUST_KOJIN_PK.setValue(JBSbatCK_T_CUST.RSV_APLY_YMD, past_CK_T_CUST_PK.getString(JBSbatCK_T_CUST.RSV_APLY_YMD));
			}
		}

		// 連絡先スキーマのカレント・過去断面レコード取得（無効化されている場合は、削除運用日だけ設定された空マップを返却）
		// 3.1. mail address to contact
		JBSbatCommonDBInterface current_CK_T_RRKS_1  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.MAIL_ADDRESS_TO_CONTACT.getRrkWayCd(), CK_T_RRKS_SELECT_008.MAIL_ADDRESS_TO_CONTACT.getRrksSbtCd(), this.currentSendOperationDate, this.currentSendTimeStamp);
		JBSbatCommonDBInterface past_CK_T_RRKS_1  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.MAIL_ADDRESS_TO_CONTACT.getRrkWayCd(), CK_T_RRKS_SELECT_008.MAIL_ADDRESS_TO_CONTACT.getRrksSbtCd(), this.lastSendOperationDate, this.lastSendTimeStamp);
		
		// 3.2. movile phone no to contact
		JBSbatCommonDBInterface current_CK_T_RRKS_2  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.MOBILE_PHONE_NO_TO_CONTACT.getRrkWayCd(), CK_T_RRKS_SELECT_008.MOBILE_PHONE_NO_TO_CONTACT.getRrksSbtCd(), this.currentSendOperationDate, this.currentSendTimeStamp);
		JBSbatCommonDBInterface past_CK_T_RRKS_2  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.MOBILE_PHONE_NO_TO_CONTACT.getRrkWayCd(), CK_T_RRKS_SELECT_008.MOBILE_PHONE_NO_TO_CONTACT.getRrksSbtCd(), this.lastSendOperationDate, this.lastSendTimeStamp);
		
		// 3.3. another phone no to contract
		JBSbatCommonDBInterface current_CK_T_RRKS_3  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.ANOTHER_PHONE_NO_TO_CONTACT_1.getRrkWayCd(), CK_T_RRKS_SELECT_008.ANOTHER_PHONE_NO_TO_CONTACT_1.getRrksSbtCd(), this.currentSendOperationDate, this.currentSendTimeStamp);
		JBSbatCommonDBInterface past_CK_T_RRKS_3  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.ANOTHER_PHONE_NO_TO_CONTACT_1.getRrkWayCd(), CK_T_RRKS_SELECT_008.ANOTHER_PHONE_NO_TO_CONTACT_1.getRrksSbtCd(), this.lastSendOperationDate, this.lastSendTimeStamp);
		
		// 3.4. another phone no to contract
		JBSbatCommonDBInterface current_CK_T_RRKS_4  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.PHONE_EXTENSION_TO_CONTACT.getRrkWayCd(), CK_T_RRKS_SELECT_008.PHONE_EXTENSION_TO_CONTACT.getRrksSbtCd(), this.currentSendOperationDate, this.currentSendTimeStamp);
		JBSbatCommonDBInterface past_CK_T_RRKS_4  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.PHONE_EXTENSION_TO_CONTACT.getRrkWayCd(), CK_T_RRKS_SELECT_008.PHONE_EXTENSION_TO_CONTACT.getRrksSbtCd(), this.lastSendOperationDate, this.lastSendTimeStamp);
	
		// 3.5. mail address to buy contents
		JBSbatCommonDBInterface current_CK_T_RRKS_5  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.MAIL_ADDRESS_TO_BUY_CONTENTS.getRrkWayCd(), CK_T_RRKS_SELECT_008.MAIL_ADDRESS_TO_BUY_CONTENTS.getRrksSbtCd(), this.currentSendOperationDate, this.currentSendTimeStamp);
		JBSbatCommonDBInterface past_CK_T_RRKS_5  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.MAIL_ADDRESS_TO_BUY_CONTENTS.getRrkWayCd(), CK_T_RRKS_SELECT_008.MAIL_ADDRESS_TO_BUY_CONTENTS.getRrksSbtCd(), this.lastSendOperationDate, this.lastSendTimeStamp);
		
		// 3.6. phone no to buy contents
		JBSbatCommonDBInterface current_CK_T_RRKS_6  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.PHONE_NO_TO_BUY_CONTENTS.getRrkWayCd(), CK_T_RRKS_SELECT_008.PHONE_NO_TO_BUY_CONTENTS.getRrksSbtCd(), this.currentSendOperationDate, this.currentSendTimeStamp);
		JBSbatCommonDBInterface past_CK_T_RRKS_6  = execute_CK_T_RRKS_byPK(sysID, CK_T_RRKS_SELECT_008.PHONE_NO_TO_BUY_CONTENTS.getRrkWayCd(), CK_T_RRKS_SELECT_008.PHONE_NO_TO_BUY_CONTENTS.getRrksSbtCd(), this.lastSendOperationDate, this.lastSendTimeStamp);
		
		// 4. diff past/current records, and check whitch column is changed
		// 4.1 Checking of EOID
		if ( executeCheckValues( current_CK_T_CUST_PK, past_CK_T_CUST_PK, new String[] {JBSbatCK_T_CUST.EOID})) {
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.ONE.getValue(), getUpdYmd(current_CK_T_CUST_PK, past_CK_T_CUST_PK) ) );
		}
		
		// 4.2 Checking of CUST_NAME, CUST_KANA, CUST_SEX_CD, CUST_BIRTHD
		if ( executeCheckValues( current_CK_T_CUST_PK, past_CK_T_CUST_PK, new String[] {
				JBSbatCK_T_CUST.CUST_NM, 
				JBSbatCK_T_CUST.CUST_KANA, 
				JBSbatCK_T_CUST.CUST_SEX_CD, 
				JBSbatCK_T_CUST.CUST_BIRTHD
		})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.TWO.getValue(), getUpdYmd(current_CK_T_CUST_PK, past_CK_T_CUST_PK) ) );
		}
		
		// 4.3 KEISHA_AD_CD, KEISHA_PCD, KEISHA_STATE_NM, KEISHA_CITY_NM, KEISHA_OAZTSU_NM, KEISHA_AZCHO_NM, KEISHA_BNCHIGO, KEISHA_ADRTTM, KEISHA_ADRRM
		if ( executeCheckValues( current_CK_T_CUST_PK, past_CK_T_CUST_PK, new String[] {
				JBSbatCK_T_CUST.KEISHA_AD_CD, 
				JBSbatCK_T_CUST.KEISHA_PCD, 
				JBSbatCK_T_CUST.KEISHA_STATE_NM, 
				JBSbatCK_T_CUST.KEISHA_CITY_NM, 
				JBSbatCK_T_CUST.KEISHA_OAZTSU_NM, 
				JBSbatCK_T_CUST.KEISHA_AZCHO_NM, 
				JBSbatCK_T_CUST.KEISHA_BNCHIGO, 
				JBSbatCK_T_CUST.KEISHA_ADRTTM, 
				JBSbatCK_T_CUST.KEISHA_ADRRM
		})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.THREE.getValue(), getUpdYmd(current_CK_T_CUST_PK, past_CK_T_CUST_PK) ) );
		}
		
		// 4.4 Checking of KEISHA_TELNO, MLAD, TELNO, TELNO, and NISNNO
		if ( executeCheckValues( current_CK_T_CUST_PK, past_CK_T_CUST_PK, new String[] {JBSbatCK_T_CUST.KEISHA_TELNO})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.FOUR.getValue(), getUpdYmd(current_CK_T_CUST_PK, past_CK_T_CUST_PK) ) );
			
		} else if( executeCheckValues( current_CK_T_RRKS_1, past_CK_T_RRKS_1, new String[] {JBSbatCK_T_RRKS.MLAD})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.FOUR.getValue(), getUpdYmd(current_CK_T_RRKS_1, past_CK_T_RRKS_1) ) );
			
		} else if( executeCheckValues( current_CK_T_RRKS_2, past_CK_T_RRKS_2, new String[] {JBSbatCK_T_RRKS.TELNO})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.FOUR.getValue(), getUpdYmd(current_CK_T_RRKS_2, past_CK_T_RRKS_2) ) );
			
		} else if( executeCheckValues( current_CK_T_RRKS_3, past_CK_T_RRKS_3, new String[] {JBSbatCK_T_RRKS.TELNO})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.FOUR.getValue(), getUpdYmd(current_CK_T_RRKS_3, past_CK_T_RRKS_3) ) );
			
		} else if( executeCheckValues( current_CK_T_RRKS_4, past_CK_T_RRKS_4, new String[] {JBSbatCK_T_RRKS.NISNNO})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.FOUR.getValue(), getUpdYmd(current_CK_T_RRKS_4, past_CK_T_RRKS_4) ) );
		}
		
		// 4.5 SKSHA_NM, SKSHA_KN, SKSHA_BIRTHD, SKSHA_ZOKUGARA_CD, and ZOKUGARA_OTHER
		if ( executeCheckValues( current_CK_T_CUST_KOJIN_PK, past_CK_T_CUST_KOJIN_PK, new String[] {
				JBSbatCK_T_CUST_KOJIN.SKSHA_NM, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_KANA, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_BIRTHD, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_ZOKUGARA_CD, 
				JBSbatCK_T_CUST_KOJIN.ZOKUGARA_OTHER
		})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.FIVE.getValue(), getUpdYmd(current_CK_T_CUST_KOJIN_PK, past_CK_T_CUST_KOJIN_PK) ) );
		}
		
		// 4.6 SKSHA_AD_CD, SKSHA_PCD, SKSHA_STATE_NM, SKSHA_CITY_NM, SKSHA_OAZTSU_NM, SKSHA_AZCHO_NM, SKSHA_AD_BNCHIGO, SKSHA_ADRTTM, and SKSHA_ADRRM
		if (executeCheckValues(current_CK_T_CUST_KOJIN_PK, past_CK_T_CUST_KOJIN_PK, new String[] {
				JBSbatCK_T_CUST_KOJIN.SKSHA_AD_CD, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_PCD, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_STATE_NM, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_CITY_NM, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_OAZTSU_NM, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_AZCHO_NM, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_AD_BNCHIGO, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_ADRTTM, 
				JBSbatCK_T_CUST_KOJIN.SKSHA_ADRRM
		})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.SIX.getValue(), getUpdYmd(current_CK_T_CUST_KOJIN_PK, past_CK_T_CUST_KOJIN_PK) ) );
		}
		
		// 4.7 SKSHA_TELNO
		if ( executeCheckValues(current_CK_T_CUST_KOJIN_PK, past_CK_T_CUST_KOJIN_PK, new String[] {JBSbatCK_T_CUST_KOJIN.SKSHA_TELNO}) ) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.SEVEN.getValue(), getUpdYmd(current_CK_T_CUST_KOJIN_PK, past_CK_T_CUST_KOJIN_PK) ) );
		}
		
		// 4.8 CONT_CUST_NM, CONT_CUST_KANA, CONT_CUST_SEX_CD, and CONT_CUST_BIRTHD
		if ( executeCheckValues(current_CK_T_CUST_PK, past_CK_T_CUST_PK, new String[] {
				JBSbatCK_T_CUST.CONT_CUST_NM, 
				JBSbatCK_T_CUST.CONT_CUST_KANA, 
				JBSbatCK_T_CUST.CONT_CUST_SEX_CD, 
				JBSbatCK_T_CUST.CONT_CUST_BIRTHD
		})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.EIGHT.getValue(), getUpdYmd(current_CK_T_CUST_PK, past_CK_T_CUST_PK) ) );
		}
		
		// 4.9 CONT_PCD, CONT_BNCHIGO, CONT_ADRTTM, CONT_ADRRM, and CONT_AD_BNKT_STA_PST
		if ( executeCheckValues(current_CK_T_CUST_PK, past_CK_T_CUST_PK, new String[] {
				JBSbatCK_T_CUST.CONT_PCD, 
				JBSbatCK_T_CUST.CONT_BNCHIGO, 
				JBSbatCK_T_CUST.CONT_ADRTTM, 
				JBSbatCK_T_CUST.CONT_ADRRM, 
				JBSbatCK_T_CUST.CONT_AD_BNKT_STA_PST
		})) 
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.NINE.getValue(), getUpdYmd(current_CK_T_CUST_PK, past_CK_T_CUST_PK) ) );
		}
		
		// 4.10 MLAD and TELNO
		if( executeCheckValues(current_CK_T_RRKS_5, past_CK_T_RRKS_5, new String[] {JBSbatCK_T_RRKS.MLAD}) )
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.TEN.getValue(), getUpdYmd(current_CK_T_RRKS_5, past_CK_T_RRKS_5) ) );
			
		} else if ( executeCheckValues(current_CK_T_RRKS_6, past_CK_T_RRKS_6, new String[] {JBSbatCK_T_RRKS.TELNO}) )
		{
			// ファイル出力
			outputBean.addOutMapList( editOutMap(sysID, IDO_NAIYO.TEN.getValue(), getUpdYmd(current_CK_T_RRKS_6, past_CK_T_RRKS_6) ) );
		}

		
		return outputBean;
	/**▲▲▲▲▲▲業務サービスの主処理を記述してください。▲▲▲▲▲▲*/
	}

	private JBSbatServiceInterfaceMap editOutMap(String sysID, String idoNaiyo, String updYmd) throws Exception {
		JBSbatServiceInterfaceMap outputMap = new JBSbatServiceInterfaceMap();
		outputMap.set(JBSbatCKIFE061.SYSID, sysID);
		outputMap.set(JBSbatCKIFE061.IDO_NAIYO, idoNaiyo);
		outputMap.set(JBSbatCKIFE061.UPD_YMD, updYmd);
		outputMap.setOutFlg(true);
		return outputMap;
	}

	private String getUpdYmd(JBSbatCommonDBInterface currentRecord, JBSbatCommonDBInterface pastRecord) throws Exception {
		
		JBSbatCommonDBInterface targetRecord = currentRecord;
		if(targetRecord==null){
			targetRecord = pastRecord;
		}
		if(targetRecord==null){
			return "";
		}
		
		String rsvAplyYMD = targetRecord.getString(JBSbatCK_T_CUST.RSV_APLY_YMD);
		String addUnyoYMD = targetRecord.getString(JBSbatCK_T_CUST.ADD_UNYO_YMD);
		String delUnyoYMD = targetRecord.getString(JBSbatCK_T_CUST.DEL_UNYO_YMD);
		String updYMD = executeMaxDates(new String[] {rsvAplyYMD, addUnyoYMD, delUnyoYMD});
		return updYMD;
	}

	/**
	 * 業務サービス終了処理
	 * @throws Exception
	 */
	public void terminal() throws Exception {
		if (db_CK_T_CUST != null) {
			db_CK_T_CUST.close();
		}
		
		if (db_CK_T_CUST_KOJIN != null) {
			db_CK_T_CUST_KOJIN.close();
		}
		
		if (db_CK_T_RRKS != null) {
			db_CK_T_RRKS.close();
		}
	}
	
	/**
	 * Do a SQL for CK_T_CUST_SELECT.SELECT_018.
	 * 
	 * @param sysID
	 * @param operationDate
	 * @param sendTimeStamp
	 * @return JBSbatCommonDBInterface
	 * @throws Exception
	 */
	private JBSbatCommonDBInterface execute_CK_T_CUST_SELECT_018(String sysID, String operationDate, String sendTimeStamp) throws Exception {
		// 2-1. get pair of past/currentRecord's PK(SYSID, GENE_ADD_DTM) from CK_T_CUST
		JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface();
		// 1. SYSID
		paramList.setValue(sysID);
		// 2. 
		paramList.setValue(operationDate);
		// 3. 
		paramList.setValue(sendTimeStamp);
		// 4. 
		paramList.setValue(operationDate);
		
		db_CK_T_CUST.selectBySqlDefine(paramList, CK_T_CUST_SELECT_018_STR);
		JBSbatCommonDBInterface jbsbatCommonDBInterface_CK_T_CUST  = db_CK_T_CUST.selectNext();

		return jbsbatCommonDBInterface_CK_T_CUST;
	}
	
	/**
	 * Do a SQL for Primary Key search for CK_T_CUST.
	 * 
	 * @param sysID
	 * @param geneAddDtm
	 * @return JBSbatCommonDBInterface
	 * @throws Exception
	 */
	private JBSbatCommonDBInterface execute_CK_T_CUST_byPK(String sysID, String geneAddDtm) throws Exception {
		// 2-2. select past/currentRecord by PK from CK_T_CUST
		JBSbatCommonDBInterface whereMap = new JBSbatCommonDBInterface();
		whereMap.setValue(JBSbatCK_T_CUST.SYSID, sysID);
		whereMap.setValue(JBSbatCK_T_CUST.GENE_ADD_DTM, geneAddDtm);
		JBSbatCommonDBInterface jbsBatCommonDBInterface = db_CK_T_CUST.selectByPrimaryKeys(whereMap);
		
		// selectByPrimaryKeysは無効レコードを返さないため、ここでnull返却の場合は無効レコードとみなし空マップを返却する
		if(jbsBatCommonDBInterface == null){
			return new JBSbatCommonDBInterface();
		}

		return jbsBatCommonDBInterface;
	}
	
	/**
	 * Do a SQL for Primary Key search for CK_T_CUST_KOJIN.
	 * 
	 * @param sysID
	 * @param geneAddDtm
	 * @return JBSbatCommonDBInterface
	 * @throws Exception
	 */
	private JBSbatCommonDBInterface execute_CK_T_CUST_KOJIN_byPK(String sysID, String geneAddDtm) throws Exception {
		// 2-2. select past/currentRecord by PK from CK_T_CUST
		JBSbatCommonDBInterface whereMap = new JBSbatCommonDBInterface();
		whereMap.setValue(JBSbatCK_T_CUST_KOJIN.SYSID, sysID);
		whereMap.setValue(JBSbatCK_T_CUST_KOJIN.GENE_ADD_DTM, geneAddDtm);
		JBSbatCommonDBInterface jbsBatCommonDBInterface = db_CK_T_CUST_KOJIN.selectByPrimaryKeys(whereMap);
		
		// selectByPrimaryKeysは無効レコードを返さないため、ここでnull返却の場合は無効レコードとみなし空マップを返却する
		if(jbsBatCommonDBInterface == null){
			return new JBSbatCommonDBInterface();
		}

		return jbsBatCommonDBInterface;
	}

	/**
	 * 
	 * @param sysID
	 * @param geneAddDtm
	 * @return JBSbatCommonDBInterface
	 * @throws Exception
	 */
	private JBSbatCommonDBInterface execute_CK_T_RRKS_byPK(String sysID, String rrkWayCd, String rrksSbtCd, String operationDate, String sendTimeStamp) throws Exception {
		JBSbatCommonDBInterface jbsBatCommonDBInterface = null;
		JBSbatCommonDBInterface current_CK_T_RRKS  = execute_CK_T_RRKS_SELECT_008(sysID, rrkWayCd, rrksSbtCd, operationDate, sendTimeStamp);
		
		if (current_CK_T_RRKS != null) {
			// 3-2. select past/currentRecord by PK from CK_T_RRKS
			JBSbatCommonDBInterface whereMap = new JBSbatCommonDBInterface();
			whereMap.setValue(JBSbatCK_T_RRKS.RRKS_NO, current_CK_T_RRKS.getString(JBSbatCK_T_RRKS.RRKS_NO));
			whereMap.setValue(JBSbatCK_T_RRKS.GENE_ADD_DTM, current_CK_T_RRKS.getString(JBSbatCK_T_RRKS.GENE_ADD_DTM));
			jbsBatCommonDBInterface = db_CK_T_RRKS.selectByPrimaryKeys(whereMap);
			
			// selectByPrimaryKeysは無効レコードを返さないため、ここでnull返却の場合は無効レコードとみなし、削除運用日だけ設定した空マップを返却する
			if(jbsBatCommonDBInterface == null){
				jbsBatCommonDBInterface = new JBSbatCommonDBInterface();
				jbsBatCommonDBInterface.setValue(JBSbatCK_T_RRKS.DEL_UNYO_YMD, current_CK_T_RRKS.getString(JBSbatCK_T_RRKS.DEL_UNYO_YMD));
			}
		}

		return jbsBatCommonDBInterface;
	}
	
	/**
	 * 
	 * Do a SQL for CK_T_RRKS.SELECT_008.
	 * 
	 * @param sysID
	 * @param rrkWayCd
	 * @param rrksSbtCd
	 * @param operationDate
	 * @param sendTimeStamp
	 * @return JBSbatCommonDBInterface
	 * @throws Exception
	 */
	private JBSbatCommonDBInterface execute_CK_T_RRKS_SELECT_008(String sysID, String rrkWayCd, String rrksSbtCd, String operationDate, String sendTimeStamp) throws Exception {
		JBSbatCommonDBInterface paramList_CK_T_RRKS = new JBSbatCommonDBInterface();
		// SYSID
		paramList_CK_T_RRKS.setValue(sysID);
		// RRK_WAY_CD for 
		paramList_CK_T_RRKS.setValue(rrkWayCd);
		// RRKS_SBT_CD
		paramList_CK_T_RRKS.setValue(rrksSbtCd);
		// 2. 
		paramList_CK_T_RRKS.setValue(operationDate);
		// 3. 
		paramList_CK_T_RRKS.setValue(sendTimeStamp);
		// 4. 
		paramList_CK_T_RRKS.setValue(operationDate);
		
		db_CK_T_RRKS.selectBySqlDefine(paramList_CK_T_RRKS, CK_T_RRKS_SELECT_008_STR);
		
		JBSbatCommonDBInterface jbsBatCommonDBInterface_CK_T_RRKS = db_CK_T_RRKS.selectNext();
		
		return jbsBatCommonDBInterface_CK_T_RRKS;
	}
	
	/**
	 * 
	 * @param currentRecord
	 * @param pastRecord
	 * @param columnName
	 * @return boolean - if true, there is a change in the column
	 * @throws Exception
	 */
	private boolean executeCheckValues(JBSbatCommonDBInterface currentRecord, JBSbatCommonDBInterface pastRecord, String columnName) throws Exception {
		if (currentRecord == null && pastRecord != null) {
			if(pastRecord.getString(JBSbatCK_T_CUST.SYSID) != null && pastRecord.getString(columnName) == null){
				return false;
			}else{
				return true;
			}
		} else if (currentRecord != null && pastRecord == null) {
			if(currentRecord.getString(JBSbatCK_T_CUST.SYSID) != null && currentRecord.getString(columnName) == null){
				return false;
			}else{
				return true;
			}
		} else if (currentRecord == null && pastRecord == null) {
			return false;
		}
		
		String currentData = currentRecord.getString(columnName);
		String pastData = pastRecord.getString(columnName);
		
		if (currentData == null && pastData != null) {
			return true;
		} else if (currentData != null && pastData == null) {
			return true;
		} else if (currentData == null && pastData == null) {
			return false;
		}
		
		// If there is a change, it will return true
		return !currentData.equals(pastData);
	}
	
	/**
	 * 
	 * @param currentRecord
	 * @param pastRecord
	 * @param columnNames
	 * @return boolean
	 * @throws Exception 
	 */
	private boolean executeCheckValues(JBSbatCommonDBInterface currentRecord, JBSbatCommonDBInterface pastRecord, String[] columnNames) throws Exception {
		for (String columnName : columnNames) {
			if (executeCheckValues(currentRecord, pastRecord, columnName) ){
				return true;
			}
		}
		
		return false;
	}
	
	/**
	 * 
	 * @param dates
	 * @return String
	 */
	private String executeMaxDates(String[] dates) {
		// 降順ソートして先頭を取り出す
		Arrays.sort(dates, new Comparator<String>() {
			@Override
			public int compare(String date1, String date2) {
				if (date2 != null && date1 != null) {
					return date2.compareTo(date1);
				}
				if(date2==null && date1==null){
					return 0;
				}
				return (date1 == null) ? 1 : -1;
			}
		});
		
		String maxDate = dates[0];
		
		return maxDate;
	}
}
