/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatKKHojinYkChkDataMarge
*	ソースファイル名	：JBSbatKKHojinYkChkDataMarge.java
*	作成者				：富士通　
*	作成日				：2011年10月26日
*＜機能概要＞
*　法人・コンシューマ有効性チェック要求ファイルマージ部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2011/10/26  FJ)倉上		新規作成
*	v3.00.00	2012/07/06  FJ)倉上		【ST2-2012-0001358】障害対応：加盟店任意使用欄2のチェック処理削除
*	v3.01.00	2012/09/20  FJ)倉上		【ST1-2012-0000596】障害対応
*	v5.00.00	2013/03/17  FJ)団		【IT1-2013-0000498】障害対応
*	v20.00.00	2015/10/13  FJ)阪口		【ANK-2565-00-00】クレジットカード番号預かりサービス導入（Step3：預かり番号化）
**********************************************************************/
package eo.business.service;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import eo.business.common.JBSbatBusinessService;
import eo.business.common.JCCBatCommon;
import eo.business.common.JKKBatCommon;
import eo.business.common.JKKBatConst;
import eo.common.constant.JCNStrConst;
import eo.common.constant.JPCBatchMessageConstant;
import eo.framework.application.JBSbatBusinessException;
import eo.framework.item.JBSbatCommonItem;
import eo.framework.item.JBSbatOutputItem;
import eo.framework.util.JBSbatStringUtil;

/**
* (クラスの機能概要) <p>
*<BR>
* @author 富士通
*/
public class JBSbatKKHojinYkChkDataMarge extends JBSbatBusinessService
{
	/**▼▼▼▼▼▼ツールから生成した宣言です 開始▼▼▼▼▼▼*/
	/**▲▲▲▲▲▲ツールから生成した宣言です 終了▲▲▲▲▲▲*/

	/** トータルレコードID */
	private static final String KEY_T_REC_ID = "トータルレコードID";
	
	/** 伝送相手ID */
	private static final String KEY_DENSO_ID = "伝送相手ID";
	
	/** 種別コード */
	private static final String KEY_SBT_CD = "種別コード";
	
	/** データ作成日 */
	private static final String KEY_DATA_M_D = "データ作成日";
	
	/** センター名称 */
	private static final String KEY_CENT_NAME = "センター名称";
	
	/** 予備 */
	private static final String KEY_YOBI = "予備";
	
	/** データ内容ID */
	private static final String KEY_DATA_NAIYO_ID = "データ内容ID";
	
	/** レコード区分 */
	private static final String KEY_REC_KBN = "レコード区分";
	
	/** 加盟店名 */
	private static final String KEY_MEMBSTR_MEI = "加盟店名";
	
	/** 加盟店番号 */
	private static final String KEY_MEMBSTR_NUM = "加盟店番号";
	
	/** データ名称 */
	private static final String KEY_DATA_NAME = "データ名称";
	
	/** MT作成年月日 */
	private static final String KEY_MT_SAKUSEI_YMD = "MT作成年月日";
	
	/** MT処理年月日 */
	private static final String KEY_MT_TRAN_YMD = "MT処理年月日";
	
	/** 結果リスト出力オプション */
	private static final String KEY_RSLT_LIST_OP = "結果リスト出力オプション";
	
	/** 予備1 */
	private static final String KEY_YOBI1 = "予備1";
	
	/** カード会社任意使用欄 */
	private static final String KEY_CARD_COMP_NIN_USE_FIELD = "カード会社任意使用欄";
	
	/** 予備2 */
	private static final String KEY_YOBI2 = "予備2";
	
	/** クレジットカード番号 */
	private static final String KEY_CRECA_NUM = "クレジットカード番号";
	
	/** クレジットカード有効期限 */
	private static final String KEY_CRECA_YK_KIGEN = "クレジットカード有効期限";
	
	/** 加盟店任意使用欄1 */
	private static final String KEY_MEMBSTR_NIN_USE_FIELD1 = "加盟店任意使用欄1";
	
	/** クレジットカード番号更新サイン */
	private static final String KEY_CRECA_NUM_UPD_SIGN = "クレジットカード番号更新サイン";
	
	/** クレジットカード有効期限更新サイン */
	private static final String KEY_CRECA_YK_KIGEN_UPD_SIGN = "クレジットカード有効期限更新サイン";
	
	/** 予備4 */
	private static final String KEY_YOBI4 = "予備4";
	
	/** 新クレジットカード番号 */
	private static final String KEY_NEW_CRECA_NUM = "新クレジットカード番号";
	
	/** 新クレジットカード有効期限 */
	private static final String KEY_NEW_CRECA_YK_KIGEN = "新クレジットカード有効期限";
	
	/** 有効性確認結果 */
	private static final String KEY_YK_CFM_RSLT = "有効性確認結果";
	
	/** 予備5 */
	private static final String KEY_YOBI5 = "予備5";
	
	/** 入力件数 */
	private static final String KEY_INPUT_CNT = "入力件数";
	
	/** OK件数 */
	private static final String KEY_OK_CNT = "OK件数";
	
	/** NG件数 */
	private static final String KEY_NG_CNT = "NG件数";
	
	/** エラー件数 */
	private static final String KEY_ERROR_CNT = "エラー件数";
	
	/** クレジットカード番号更新件数 */
	private static final String KEY_CRECA_NUM_UPD_CNT = "クレジットカード番号更新件数";
	
	/** クレジットカード有効期限更新件数 */
	private static final String KEY_CRECA_YK_KIGEN_UPD_CNT = "クレジットカード有効期限更新件数";
	
	/** 予備6 */
	private static final String KEY_YOBI6 = "予備6";
	
	/** データ件数 */
	private static final String KEY_DATA_CNT = "データ件数";
	
	/** 伝送ファイル数 */
	private static final String KEY_DENSO_FILE_CNT = "伝送ファイル数";
	
	/** 予備7 */
	private static final String KEY_YOBI7 = "予備7";
	
	/** クレジット会社コード */
	private static final String KEY_CRDT_KOKAN_CD = "クレジット交換コード";
	
	/** フリー項目情報保持(ファイルパス)*/
	private static String[] lines = null;
	
	/** 法人有効性チェック要求ファイル(ファイルパス)*/
	private static String strFreeParam1 = null;
	
	/** コンシューマ有効性チェック要求(ファイルパス)*/
	private static String strFreeParam2 = null;
	
	/** コンシューマ有効性チェック要求ファイル(マージ後)(ファイルパス)*/
	private static String strFreeParam3 = null;
	
	/** サブトレーラデータ件数カウント*/
	private static int isubtrlDataCnt_hojin = 0;
	
	/** サブレコード一致フラグ*/
	boolean flag = false;

	/** 伝送相手ID(JCN用)*/
	private static String denso_aite_id_jcn = null;
    /**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの初期処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した初期化のソースです 開始▼▼▼▼▼▼*/
		// 共通パラメータを設定します
		super.setCommonInfo(commonItem);
		
		// シェルからのFREEパラメータ取得
		String strFreeParam = commonItem.getFreeItem();
		
		// パラメータを区切り文字で分割して配列に格納する
		lines = strFreeParam.split(JKKBatConst.S_PARAM_DELIM);
		
		// パラメータ数チェック
		if(lines.length != 3)
		{
			throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0130CE, new String[]{"FREE"});
		}
		
		// プロパティからJCN用の「伝送相手ID」を取得します。
		denso_aite_id_jcn = JKKBatCommon.getWorkParamSetteValue(commonItem, "KK_DENSO_AITE_ID_JCN");
		super.logPrint.printDebugLog("JCN用の「伝送相手ID」:::::" + denso_aite_id_jcn);
		if (null == denso_aite_id_jcn)
		{
			throw new JBSbatBusinessException(
					JPCBatchMessageConstant.EKKB0150JE, new String[]{"業務パラメータ管理TBL(KEY:KK_DENSO_AITE_ID_JCN)"});
		}

		/**▲▲▲▲▲▲ツールから生成した初期化のソースです 終了▲▲▲▲▲▲*/
	/**▲▲▲▲▲▲業務サービスの初期処理を記述してください。▲▲▲▲▲▲*/
	}
	
	/**
	 * 主処理
	 * @return JBSbatOutputItem 出力情報
	 * @throws Exception
	 */
	public JBSbatOutputItem execute() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの主処理を記述してください。▼▼▼▼▼▼*/
		
		super.logPrint.printDebugLog("execute_START");
		
		// コンシューマ有効性チェック要求情報保持(マージ後)
		String consyuma = "";
		
		// 入力ファイル名
		strFreeParam1 = lines[0];	// 法人有効性チェック要求ファイル名取得
		strFreeParam2 = lines[1];	// コンシューマ有効性チェック要求ファイル名取得
		strFreeParam3 = lines[2];	// コンシューマ有効性チェック要求ファイル(マージ後)名取得
		
		// コンシューマ有効性ファイル情報取得
		String consyuma_data = getInputFile(strFreeParam2, true);
		
		// 法人有効性ファイル情報取得
		String hojin_data = getInputFile(strFreeParam1, false);
		
		// 法人有効性ファイルが存在しない場合。
		if ((hojin_data == null || hojin_data.length() == 0) && (consyuma_data != null && consyuma_data.length() != 0))
		{
			// 125バイトで割り切れない場合はエラーとする。
			if(null == consyuma_data || (consyuma_data.length() % 125) != 0)
			{
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0070TE, new String[]{strFreeParam2});
				throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[]{strFreeParam2});
			}
			
			// コンシューマ有効性チェック要求情報を作成します。
			consyuma = createConsyumaFile(consyuma_data, hojin_data);
			
			// ファイルへ出力(コンシューマ有効性チェック要求ファイル(マージ後))
			setOutputFile(strFreeParam3, consyuma_data);
		}
		
		// コンシューマ、法人有効性チェック要求ファイルがデータなしの場合。
		else if ((hojin_data == null || hojin_data.length() == 0) && (consyuma_data == null))
		{
			// ファイルへ出力(コンシューマ有効性チェック要求ファイル(マージ後))
			setOutputFile(strFreeParam3, "");
		}
		else
		{
			
			// 125バイトで割り切れない場合はエラーとする。
			if(null == consyuma_data || (consyuma_data.length() % 125) != 0)
			{
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0070TE, new String[]{strFreeParam2});
				throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[]{strFreeParam2});
			}
			
			// 125バイトで割り切れない場合はエラーとする。
			if(null == hojin_data || (hojin_data.length() % 125) != 0)
			{
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0070TE, new String[]{strFreeParam1});
				throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[]{strFreeParam1});
			}
			
			// コンシューマ有効性チェック要求情報を作成します。
			consyuma = createConsyumaFile(consyuma_data, hojin_data);
		}
		
		// ファイルへ出力(コンシューマ有効性チェック要求ファイル(マージ後))
		setOutputFile(strFreeParam3, consyuma);
		
		super.logPrint.printDebugLog("execute_END");
		
		return null;
	/**▲▲▲▲▲▲業務サービスの主処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 業務サービス終了処理
	 * @throws Exception
	 */
	public void terminal() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの終了処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した終了処理のソースです 開始▼▼▼▼▼▼*/
		/**▲▲▲▲▲▲ツールから生成した終了処理のソースです 終了▲▲▲▲▲▲*/
	/**▲▲▲▲▲▲業務サービスの終了処理を記述してください。▲▲▲▲▲▲*/
	}

	/**▼▼▼▼▼▼ツールから生成したメソッドです 開始▼▼▼▼▼▼*/
	/**▲▲▲▲▲▲ツールから生成したメソッドです 終了▲▲▲▲▲▲*/
	
	/**
	 * ファイル情報を読み込みます。<br>
	 * <p>
	 * @param file_name ファイル名(フルパス)
	 * @param flg ファイル名(フルパス)
	 * @return ファイルデータ
	 * @throws JBSbatBusinessException 
	 * @throws IOException 業務サービス内で発生した例外全般。
	 */	
	/* ++++++++++ v1.01.00 修正開始 ++++++++++ */
	//private String getInputFile(String file_name, boolean flg) throws JBSbatBusinessException, IOException
	/* ++++++++++ v1.01.00 修正終了 ++++++++++ */
	private String getInputFile(String file_name, boolean flg) throws JBSbatBusinessException, IOException
	{
		
		// ファイル情報保持
		String data_list = "";
		BufferedReader br = null;
		
		// ファイルを読み込みます。
		try
		{
			InputStreamReader is = new InputStreamReader(new FileInputStream(file_name), JKKBatConst.SJIS);
			br = new BufferedReader(is);
			
			// 1行読込み
			data_list = br.readLine();
		}
		catch (IOException e)
		{
			if (flg)
			{
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0070TE, new String[]{file_name});
				throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[]{file_name});
			}
			else
			{
				return null;
			}
		}
		finally
		{
			if (br != null)
			{
				br.close();
			}
		}
		return data_list;
	}
	
	/**
	 * 読み込んだファイルのレコードの並び順のチェックを行います。<br>
	 * <p>
	 * @param before 処理中のトータルレコードID
	 * @param after 次のトータルレコードID
	 * @return true：チェックOK、false：チェックNG
	 */
	private boolean checkRecordOrder(String before, String after)
	{
		// 現在のトータルレコードIDが空白の場合
		if("".equals(before))
		{
			// 次のトータルレコードIDがトータルヘッダの場合
			if(after.equals(JKKBatConst.S_TTL_REC_ID_HEAD))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		// 現在のトータルレコードIDがトータルヘッダの場合(10000)
		else if(before.equals(JKKBatConst.S_TTL_REC_ID_HEAD))
		{
			// 次のトータルレコードIDがサブヘッダの場合
			if(after.equals(JKKBatConst.S_TTL_REC_ID_SUBHEAD))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		// 現在のトータルレコードIDがサブヘッダの場合(21000)
		else if(before.equals(JKKBatConst.S_TTL_REC_ID_SUBHEAD))
		{
			// 次のトータルレコードIDがヘッダの場合
			if(after.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_HEAD))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		// 現在のトータルレコードIDがヘッダの場合(トータルレコードID＋レコード区分)(220001)
		else if(before.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_HEAD))
		{
			// 次のトータルレコードIDがデータの場合
			if(after.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_DATA))
			{
				return true;
			}
			// 次のトータルレコードIDがトレーラの場合
			else if(after.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_TRAL))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		// 現在のトータルレコードIDがデータの場合(トータルレコードID＋レコード区分)(220002)
		else if(before.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_DATA))
		{
			// 次のトータルレコードIDがデータの場合
			if(after.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_DATA))
			{
				return true;
			}
			// 次のトータルレコードIDがトレーラの場合
			else if(after.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_TRAL))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		// 現在のトータルレコードIDがトレーラの場合(トータルレコードID＋レコード区分)(220008)
		else if(before.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_TRAL))
		{
			// 次のトータルレコードIDがエンドの場合
			if(after.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_END))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		// 現在のトータルレコードIDがエンドの場合(トータルレコードID＋レコード区分)(220009)
		else if(before.equals(JKKBatConst.S_TTL_REC_ID_CARDCO + JKKBatConst.S_REC_KBN_END))
		{
			// 次のトータルレコードIDがサブトレーラの場合
			if(after.equals(JKKBatConst.S_TTL_REC_ID_SUBTRAL))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		// 現在のトータルレコードIDがサブトレーラの場合(28000)
		else if(before.equals(JKKBatConst.S_TTL_REC_ID_SUBTRAL))
		{
			// 次のトータルレコードIDがサブヘッダの場合
			if(after.equals(JKKBatConst.S_TTL_REC_ID_SUBHEAD))
			{
				return true;
			}
			// 次のトータルレコードIDがトータルトレーラの場合
			else if(after.equals(JKKBatConst.S_TTL_REC_ID_TTLTRAL))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		// 現在のトータルレコードIDがトータルトレーラの場合(80000)
		else if(before.equals(JKKBatConst.S_TTL_REC_ID_TTLTRAL))
		{
			// 次のトータルレコードIDがトータルエンドの場合
			if(after.equals(JKKBatConst.S_TTL_REC_ID_TTLEND))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		// 現在のトータルレコードIDがトータルエンドの場合(90000)
		else if(before.equals(JKKBatConst.S_TTL_REC_ID_TTLEND))
		{
			// 次のトータルレコードIDが設定されている場合
			if(!"".equals(after))
			{
				return false;
			}
		}
		
		return true;
	}
	
	/**
	 * トータルトレーラレコードに設定するデータ件数、伝送ファイル数を算出し、取得します。
	 * データ件数：総レコード件数よりサブヘッダレコード〜サブトレーラレコードまでの件数をカウントする。
	 * 伝送ファイル数：総レコード件数よりサブトレーラレコードの件数をカウントする。<br>
	 * <p>
	 * @param file_data ファイル文字列
	 * @return count 算出結果(count[0]：データ件数、count[1]：伝送ファイル数)
	 */
	private int[] getCountForTotalTrail(String file_data)
	{
		int[] count = {0, 0};
		
		// クレジット有効性チェック結果ファイルを読み込む
		int data_length    = file_data.length();
		int start_index    = 0;
		String fileCutData  = "";
		String total_rec_id = "";
		while(data_length > 0)
		{
			// 125バイトずつ読み込む
			fileCutData = file_data.substring(start_index, start_index + 125);
			
			// 先頭５桁のトータルレコードIDを読み込む
			total_rec_id = fileCutData.substring(0, 5);
			
			// トータルヘッダレコード以外の場合
			if(!total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_HEAD))
			{
				// データ件数をカウントUP
				count[0] ++;
			}
			
			// サブトレーラレコードの場合
			if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_SUBTRAL))
			{
				// 伝送ファイル数をカウントUP
				count[1] ++;
			}
			
			// データ長を125マイナス
			data_length = data_length - 125;
			// 開始インデックスを125プラス
			start_index = start_index + 125;
		}
		return count;
	}
	
	/**
	 * クレジット有効性チェック結果ファイル情報を出力します。<br>
	 * <p>
	 * @param file_Name ファイル名(フルパス)
	 * @param file_data 出力情報
	 * @throws IOException 業務サービス内で発生した例外全般。
	 * @throws Exception 
	 */	
	private void setOutputFile(String file_Name, String file_data) throws Exception
	{
		// ファイルへ出力(コンシューマ有効性チェック要求ファイル(マージ後))
		
		// 一時ファイル読込み処理
		BufferedWriter wr = null;
		try
		{
			// クレジット審査結果ファイルの生成(SJIS)
			wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file_Name), JKKBatConst.SJIS));
			
			// ファイル書き込み
			wr.write(file_data);
			wr.flush();
		}
		catch(IOException e)
		{
			throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0250CE, new String[]{file_Name, e.getMessage()});
		}
		finally
		{
			if (wr != null)
			{
				wr.close();
			}
		}
	}
	
	/**
	 * コンシューマ有効性チェック要求ファイルを作成します。<br>
	 * <p>
	 * @param consyuma_data コンシューマ有効性チェック要求ファイル
	 * @param hojin_data 法人有効性チェック要求ファイル
	 * @return String　コンシューマ有効性チェック要求ファイル(マージ後)
	 * @throws Exception 
	 * @throws IOException 
	 */
	private String createConsyumaFile(String consyuma_data, String hojin_data)throws Exception
	{
		// コンシューマ有効性チェックファイル(マージ後)情報保持。
		StringBuilder consyuma = new StringBuilder();
		
		int consyuma_length = consyuma_data.length();	// コンシューマデータ桁数の初期化
		int start_index     = 0;						// 開始インデックスの初期化
		int iDataCnt        = 0;						// データレコードカウンタ(トータルレコードID(22000)+レコード区分(2))
		int isubtrlDataCnt  = 0;						// サブトレーラデータ件数カウント(トータルレコードID(22000))
		
		String cutFileData  = "";						// 125バイト文字列保持
		String total_rec_id = "";						// トータルレコードID保持
		String rec_kbn      = "";						// レコード区分保持
		String before       = "";						// レコード並び順チェック用変数の初期化
		String after        = "";						// トータルレコードID保持
		String totalrecid   = "";						// トータルレコードID保持
		String detanaiyoid  = "";						// データ内容ID保持
		
		super.logPrint.printDebugLog("●consyuma_data:::::" + consyuma_data);
		super.logPrint.printDebugLog("●hojin_data:::::" + hojin_data);
		
		// コンシューマデータの桁数文分繰返し。
		while(consyuma_length > 0)
		{
			// 125バイトずつ読み込む
			cutFileData = consyuma_data.substring(start_index, start_index + 125);
			
			// 先頭５桁のトータルレコードIDを読み込む
			total_rec_id = cutFileData.substring(0, 5);
			
			// 処理中のトータルレコードID
			after = total_rec_id;
			
			// トータルヘッダの場合
			if (total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_CARDCO))
			{
				// 6バイト目のレコード区分を読み込む
				rec_kbn = cutFileData.substring(5, 6);
				
				// トータルレコードID＋レコード区分で保持する。
				after = total_rec_id + rec_kbn;
			}
			
			// レコードの並び順のチェックを行う。
			if(!this.checkRecordOrder(before, after))
			{
				// レコードの並び順が違う場合はエラーとする。
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0090TE, new String[] {"レコード構成の不備　トータルレコードID before：" + before
						+ " after：" + after});
				throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：レコード構成"});
			}
			
			// ■トータルヘッダレコードの場合
			if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_HEAD))
			{
				// トータルヘッダレコード情報の単項目チェックを実施します。
				if(!this.isTotalHeaderRec(cutFileData))
				{
					// トータルヘッダレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：トータルヘッダレコード"});
				}
				else
				{
					String total_head    = "";
					String rec_id        = cutFileData.substring(0, 5);
					String denso_aite_id = cutFileData.substring(5, 15);
					String work          = cutFileData.substring(15);
					
					denso_aite_id = denso_aite_id_jcn;
					total_head = rec_id + denso_aite_id + work;
					// トータルヘッダレコード情報を設定
					consyuma.append(total_head);
				}
			}
			// ■サブヘッダレコードの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_SUBHEAD))
			{
				// サブヘッダレコード情報の単項目チェックを実施します。
				if(!this.isSubHeaderRec(cutFileData))
				{
					// サブヘッダレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：サブヘッダレコード"});
				}
				else
				{
					// コンシューマ情報のトータルレコードIDを取得。
					totalrecid = cutFileData.substring(0, 5);
					// コンシューマ情報のデータ内容IDを取得。
					detanaiyoid = cutFileData.substring(5, 15);
					
					// サブヘッダレコード情報を設定
					consyuma.append(cutFileData);
				}
			}
			// ■ヘッダ〜エンドまでの共通レコードIDの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_CARDCO))
			{
				// ■ヘッダレコードの場合
				if(rec_kbn.equals(JKKBatConst.S_REC_KBN_HEAD))
				{
					// ヘッダレコード情報の単項目チェックを実施します。
					if(!this.isHeaderRec(cutFileData, true))
					{
						// ヘッダレコードの内容が異常の場合は以降の処理は行わない。
						throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：ヘッダレコード"});
					}
					else
					{
						// ヘッダレコード情報を設定
						consyuma.append(cutFileData);
						
						// サブトレーラデータ件数カウント
						isubtrlDataCnt++;
					}
				}
				// ■データレコードの場合
				else if(rec_kbn.equals(JKKBatConst.S_REC_KBN_DATA))
				{
					
					super.logPrint.printDebugLog("●cutFileData:::::" + cutFileData);
					// データレコード情報の単項目チェックを実施します。
					if(!this.isDataRec(cutFileData, true))
					{
						// データレコードの内容が異常の場合は以降の処理は行わない。
						throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：データレコード"});
					}
					else
					{
						// データレコードカウントUP
						iDataCnt++;
						// サブトレーラデータ件数カウント
						isubtrlDataCnt++;
						// データレコード情報を設定
						consyuma.append(cutFileData);
					}
				}
				// ■トレーラレコードの場合
				else if(rec_kbn.equals(JKKBatConst.S_REC_KBN_TRAL))
				{
					// トレーラレコード情報の単項目チェックを実施します。
					if(!this.isTrailerRec(cutFileData))
					{
						// トレーラレコードの内容が異常の場合は以降の処理は行わない。
						throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：トレーラレコード"});
					}
					else
					{
						// サブトレーラデータ件数カウント
						isubtrlDataCnt++;
						
						// 法人データが存在する場合
						if (hojin_data != null)
						{
							// コンシューマ、法人有効性チェック要求ファイルのマージを実施。
							margeConsyumaFile(cutFileData, hojin_data, consyuma, totalrecid , detanaiyoid, iDataCnt, isubtrlDataCnt);
							
							if(!flag)
							{
								// トレーラレコード情報を設定
								consyuma.append(cutFileData);
							}
						}
						else
						{
							// トレーラレコード情報を設定
							consyuma.append(cutFileData);
						}
						// データレコードカウンタの初期化
						iDataCnt = 0;
					}
				}
				// ■エンドレコードの場合
				else if(rec_kbn.equals(JKKBatConst.S_REC_KBN_END))
				{
					// エンドレコード情報の単項目チェックを実施します。
					if(!this.isEndRec(cutFileData))
					{
						// エンドレコードの内容が異常の場合は以降の処理は行わない。
						throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：エンドレコード"});
					}
					else
					{
						// サブトレーラデータ件数カウント
						isubtrlDataCnt++;
						// エンドレコード情報を設定
						consyuma.append(cutFileData);
					}
				}
				// 上記以外
				else
				{
					// 想定外のレコード区分が設定された場合はエラーとする。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：トータルレコードID："
							+ total_rec_id + "：想定外のレコード区分：" + rec_kbn });
				}
			}
			// ■サブトレーラレコードの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_SUBTRAL))
			{
				// サブトレーラレコード情報の単項目チェックを実施します。
				if(!this.isSubTrailerRec(cutFileData))
				{
					// サブトレーラレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：サブトレーラレコード"});
				}
				else
				{
					// サブトレーラレコードを作成します。
					createSubTrailerRec(consyuma, isubtrlDataCnt);
					// サブトレーラデータ件数カウンタの初期化
					isubtrlDataCnt = 0;
					// サブトレーラデータ件数カウント初期化(法人)
					isubtrlDataCnt_hojin = 0;
				}
			}
			// ■トータルトレーラレコードの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_TTLTRAL))
			{
				// トータルトレーラレコード情報の単項目チェックを実施します。
				if(!this.isTotalTrailerRec(cutFileData))
				{
					// トータルトレーラレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：トータルトレーラレコード"});
				}
				else
				{
					// トータルトレーラレコード情報を設定
					createTotalTrailerRec(consyuma);
				}
			}
			// ■トータルエンドレコードの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_TTLEND))
			{
				// トータルエンドレコード情報の単項目チェックを実施します。
				if(!this.isTotalEndRec(cutFileData))
				{
					// トータルエンドレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：トータルエンドレコード"});
				}
				else
				{
					// トータルエンドレコード情報を設定
					consyuma.append(cutFileData);
				}
			}
			// 上記以外
			else
			{
				// 想定外のトータルレコードIDが設定された場合はエラーとする。
				throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] { strFreeParam2 + "：想定外のトータルレコードID："
						+ total_rec_id });
			}
			
			// 前のトータルレコードIDとして保持する
			before = after;
			
			// データ長を125マイナス
			consyuma_length = consyuma_length - 125;
			// 開始インデックスを125プラス
			start_index = start_index + 125;
		}
		
		// 最終レコードがトータルエンド(90000)ではない場合
		if(!total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_TTLEND))
		{
			// レコードの並び順が違う場合はエラーとする。
			super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0090TE,
					new String[] {"レコード構成の不備　最終レコードがトータルエンドではない：" + total_rec_id});
			throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam2 + "：レコード構成"});
		}
		return consyuma.toString();
	}

	/**
	 * コンシューマ、法人有効性チェック要求ファイルを作成します。<br>
	 * <p>
	 * @param cutConsyumaData コンシューマ情報(125バイト)
	 * @param hojin_data 法人有効性チェック情報
	 * @param consyuma コンシューマ有効性チェック情報ファイル(マージ後)
	 * @param totalrecid トータルレコードID
	 * @param detanaiyoid データ内容ID
	 * @param iDataCnt データレコードカウンタ
	 * @param isubtrlDataCnt サブトレーラデータ件数カウンタ
	 * @return String　コンシューマ有効性チェック情報ファイル(マージ後)文字列
	 * @throws Exception 
	 * @throws IOException 
	 */
	private String margeConsyumaFile(String cutConsyumaData, String hojin_data, StringBuilder consyuma,
			String totalrecid , String detanaiyoid, int iDataCnt, int isubtrlDataCnt)throws Exception
	{
		int hojin_length   = hojin_data.length();	// 法人データ桁数の初期化
		int start_index    = 0;						// 開始インデックスの初期化
		
		String cutFileData  = "";					// 125バイト文字列保持
		String total_rec_id = "";					// トータルレコードID保持
		String rec_kbn      = "";					// レコード区分保持
		String before       = "";					// レコード並び順チェック用変数の初期化
		String after        = "";					// レコード並び順チェック用変数の初期化
		
		// コンシューマデータの桁数文分繰返し。
		while(hojin_length > 0)
		{
			// 125バイトずつ読み込む
			cutFileData = hojin_data.substring(start_index, start_index + 125);
			
			// 先頭５桁のトータルレコードIDを読み込む
			total_rec_id = cutFileData.substring(0, 5);
			
			// 処理中のトータルレコードID
			after = total_rec_id;
			
			// トータルヘッダの場合
			if (total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_CARDCO))
			{
				// 6バイト目のレコード区分を読み込む
				rec_kbn = cutFileData.substring(5, 6);
				
				// トータルレコードID＋レコード区分で保持する。
				after = total_rec_id + rec_kbn;
			}
			
			// レコードの並び順のチェックを行う。
			if(!this.checkRecordOrder(before, after))
			{
				// レコードの並び順が違う場合はエラーとする。
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0090TE, new String[] {"レコード構成の不備　トータルレコードID before：" + before
						+ " after：" + after});
				throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：レコード構成"});
			}
			
			// ■トータルヘッダレコードの場合
			if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_HEAD))
			{
				// トータルヘッダレコード情報の単項目チェックを実施します。
				if(!this.isTotalHeaderRec(cutFileData))
				{
					// トータルヘッダレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：トータルヘッダレコード"});
				}
			}
			// ■サブヘッダレコードの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_SUBHEAD))
			{
				// サブヘッダレコード情報の単項目チェックを実施します。
				if(!this.isSubHeaderRec(cutFileData))
				{
					// サブヘッダレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：サブヘッダレコード"});
				}
				else
				{
					// 法人情報のデータ内容IDを取得。
					String data_naiyo_id = cutFileData.substring(5, 15);
					// トータルレコードIDがサブヘッダの場合
					if(totalrecid.equals(JKKBatConst.S_TTL_REC_ID_SUBHEAD))
					{
						// コンシューマ、法人のデータ内容IDが一致している場合。
						if (detanaiyoid.equals(data_naiyo_id))
						{
							flag = true;
						}
						else
						{
							flag = false;
						}
					}
				}
			}
			// ■ヘッダ〜エンドまでの共通レコードIDの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_CARDCO))
			{
				// ■ヘッダレコードの場合
				if(rec_kbn.equals(JKKBatConst.S_REC_KBN_HEAD))
				{
					// ヘッダレコード情報の単項目チェックを実施します。
					if(!this.isHeaderRec(cutFileData, false))
					{
						// ヘッダレコードの内容が異常の場合は以降の処理は行わない。
						throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：ヘッダレコード"});
					}
				}
				// ■データレコードの場合
				else if(rec_kbn.equals(JKKBatConst.S_REC_KBN_DATA))
				{
					// データレコード情報の単項目チェックを実施します。
					if(!this.isDataRec(cutFileData, false))
					{
						// データレコードの内容が異常の場合は以降の処理は行わない。
						throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：データレコード"});
					}
					else
					{
						// コンシューマ、法人のデータ内容IDが一致している場合。
						if (flag)
						{
							// データレコード情報を設定
							consyuma.append(cutFileData);
							
							// データレコードカウンタUP
							iDataCnt++;
							// サブトレーラレコード(法人)
							isubtrlDataCnt_hojin++;
						}
					}
				}
				// ■トレーラレコードの場合
				else if(rec_kbn.equals(JKKBatConst.S_REC_KBN_TRAL))
				{
					// トレーラレコード情報の単項目チェックを実施します。
					if(!this.isTrailerRec(cutFileData))
					{
						// トレーラレコードの内容が異常の場合は以降の処理は行わない。
						throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：トレーラレコード"});
					}
					else
					{
						// コンシューマ、法人のデータ内容IDが一致している場合。
						if (flag)
						{
							// トレーラレコード作成
							createTrailerRec(consyuma, iDataCnt);
							return consyuma.toString();
						}
					}
				}
				// ■エンドレコードの場合
				else if(rec_kbn.equals(JKKBatConst.S_REC_KBN_END))
				{
					// エンドレコード情報の単項目チェックを実施します。
					if(!this.isEndRec(cutFileData))
					{
						// エンドレコードの内容が異常の場合は以降の処理は行わない。
						throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：エンドレコード"});
					}
				}
				// 上記以外
				else
				{
					// 想定外のレコード区分が設定された場合はエラーとする。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：トータルレコードID："
							+ total_rec_id + "：想定外のレコード区分：" + rec_kbn });
				}
			}
			// ■サブトレーラレコードの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_SUBTRAL))
			{
				// サブトレーラレコード情報の単項目チェックを実施します。
				if(!this.isSubTrailerRec(cutFileData))
				{
					// サブトレーラレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：サブトレーラレコード"});
				}
			}
			// ■トータルトレーラレコードの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_TTLTRAL))
			{
				// トータルトレーラレコード情報の単項目チェックを実施します。
				if(!this.isTotalTrailerRec(cutFileData))
				{
					// トータルトレーラレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：トータルトレーラレコード"});
				}
			}
			// ■トータルエンドレコードの場合
			else if(total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_TTLEND))
			{
				// トータルエンドレコード情報の単項目チェックを実施します。
				if(!this.isTotalEndRec(cutFileData))
				{
					// トータルエンドレコードの内容が異常の場合は以降の処理は行わない。
					throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：トータルエンドレコード"});
				}
			}
			// 上記以外
			else
			{
				// 想定外のトータルレコードIDが設定された場合はエラーとする。
				throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] { strFreeParam1 + "：想定外のトータルレコードID："
						+ total_rec_id });
			}
			
			// 前のトータルレコードIDとして保持する
			before = after;
			
			// データ長を125マイナス
			hojin_length = hojin_length - 125;
			// 開始インデックスを125プラス
			start_index = start_index + 125;
		}
		
		// 最終レコードがトータルエンド(90000)ではない場合
		if(!total_rec_id.equals(JKKBatConst.S_TTL_REC_ID_TTLEND))
		{
			// レコードの並び順が違う場合はエラーとする。
			super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0090TE,
					new String[] {"レコード構成の不備　最終レコードがトータルエンドではない：" + total_rec_id});
			throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0100AE, new String[] {strFreeParam1 + "：レコード構成"});
		}
		return consyuma.toString();
	}
	
	/**
	 * トータルヘッダレコード情報の単項目チェックを実施します。<br>
	 * <p>
	 * @param value 125バイト分の文字列
	 * @return boolean　true：チェックOK、false：チェックNG
	 * @throws IOException 
	 * @throws JBSbatBusinessException 業務サービス内で発生した例外全般。
	 */
	private boolean isTotalHeaderRec(String value)throws JBSbatBusinessException
	{
		int index = 0;
		
		// トータルヘッダの各項目を取得し、チェックを行う。チェックOKの場合にマップへ保持します。
		// トータルレコードID（0, 5）
		String total_rec_id = value.substring(index, index + 5);
		if(!this.isHannkakuSuuji1(total_rec_id, KEY_T_REC_ID))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// 伝送相手ID（5, 15）
		String denso_id = value.substring(index, index + 10);
		if(!this.isHannkakuESuuji1(denso_id, KEY_DENSO_ID))
		{
			return false;
		}
		else
		{
			index = index + 10;
		}
		
		// 種別コード（15, 17）
		String sbt_cd = value.substring(index, index + 2);
		if(!this.isHannkakuSuuji1(sbt_cd, KEY_SBT_CD))
		{
			return false;
		}
		else
		{
			index = index + 2;
		}
		
		// データ作成日（17, 25）
		String data_m_d = value.substring(index, index + 8);
		if(!this.isHannkakuSuuji1(data_m_d, KEY_DATA_M_D))
		{
			return false;
		}
		
		
		// データ作成日の値が「00000000」以外の場合、妥当性チェックを実施。
		if(!"00000000".equals(data_m_d))
		{
			// 日付の妥当性のチェック
			if(!JCCBatCommon.isYearMonthDay1(data_m_d))
			{
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0080TE, new String[]{"日付の妥当性エラー：" + data_m_d});
				return false;
			}
			else
			{
				index = index + 8;
			}
		}
		else
		{
			index = index + 8;
		}
		
		// センター名称（25, 31）
		String cent_nm = value.substring(index, index + 6);
		if(!this.isHannkakuESuuji1(cent_nm, KEY_CENT_NAME))
		{
			return false;
		}
		else
		{
			index = index + 6;
		}
		
		// 予備（31, 125）
		String yobi = value.substring(index);
		if(!this.isHannkakuESuuji3(yobi, KEY_YOBI)) 
		{
			return false;
		}
		return true;
	}
	
	/**
	 * サブヘッダレコードの情報の単項目チェックを実施します。<br>
	 * <p>
	 * @param value 125バイト分の文字列
	 * @param crdt_com_map　格納するクレジット交換マップ
	 * @return boolean　true：チェックOK、false：チェックNG
	 */
	private boolean isSubHeaderRec(String value)
	{
		int index = 0;
		
		// サブヘッダの各項目を取得し、チェックを行う。チェックOKの場合にマップへ保持します。
		// トータルレコードID（0, 5）
		String total_rec_id = value.substring(index, index + 5);
		if(!this.isHannkakuSuuji1(total_rec_id, KEY_T_REC_ID))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// データ内容ID（5, 15）
		String data_naiyo_id = value.substring(index, index + 10);
		if(!this.isHannkakuESuuji1(data_naiyo_id, KEY_DATA_NAIYO_ID))
		{
			return false;
		}
		else
		{
			index = index + 10;
		}
		
		// 予備（15, 125）
		String yobi = value.substring(index);
		if(!this.isHannkakuESuuji3(yobi, KEY_YOBI)) 
		{
			return false;
		}
		return true;
	}
	
	/**
	 * ヘッダレコードの単項目チェックを実施します。<br>
	 * <p>
	 * @param value 125バイト分の文字列
	 * @param flg true:コンシューマファイル用、false:法人ファイル用
	 * @return boolean　true：チェックOK、false：チェックNG
	 */
	private boolean isHeaderRec(String value, boolean flg)
	{
		int index = 0;
		
		// ヘッダの各項目を取得し、チェックを行う。チェックOKの場合にマップへ保持します。
		// トータルレコードID（0, 5）
		String total_rec_id = value.substring(index, index + 5);
		if(!this.isHannkakuSuuji1(total_rec_id, KEY_T_REC_ID))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// レコード区分（5, 6）
		String rec_kbn = value.substring(index, index + 1);
		if(!this.isHannkakuSuuji1(rec_kbn, KEY_REC_KBN))
		{
			return false;
		}
		else
		{
			index = index + 1;
		}
		
		// 加盟店名（6, 21）
		String membstr_mei = value.substring(index, index + 15);
		if(!this.isHannkakuESuujiKana3(membstr_mei, KEY_MEMBSTR_MEI))
		{
			return false;
		}
		else
		{
			index = index + 15;
		}
		
		// 加盟店番号（21, 36）
		String membstr_num = value.substring(index, index + 15);
		if(!this.isHannkakuESuuji3(membstr_num, KEY_MEMBSTR_NUM))
		{
			return false;
		}
		else
		{
			index = index + 15;
		}
		
		// クレジット交換コード（21, 26）
		String crdt_kokan_cd = value.substring(index, index + 5);
		if(!this.isHannkakuESuuji1(crdt_kokan_cd, KEY_CRDT_KOKAN_CD))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// データ名称（26, 46）
		String data_name = value.substring(index, index + 20);
		if(!this.isHannkakuESuujiKana3(data_name, KEY_DATA_NAME))
		{
			return false;
		}
		else
		{
			index = index + 20;
		}
		
		// MT作成年月日（46, 54）
		String mt_sakusei_ymd = value.substring(index, index + 8);
		if(!this.isHannkakuSuuji1(mt_sakusei_ymd, KEY_MT_SAKUSEI_YMD))
		{
			return false;
		}
		
		// MT作成年月日の値が「00000000」以外の場合、妥当性チェックを実施。
		if(!"00000000".equals(mt_sakusei_ymd))
		{
			// 日付の妥当性のチェック
			if(!JCCBatCommon.isYearMonthDay1(mt_sakusei_ymd))
			{
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0080TE, new String[]{"日付の妥当性エラー：" + mt_sakusei_ymd});
				return false;
			}
			else
			{
				index = index + 8;
			}
		}
		else
		{
			index = index + 8;
		}
		
		// MT処理年月日（54, 62）
		String mt_tran_ymd = value.substring(index, index + 8);
		if(!this.isHannkakuSuuji1(mt_tran_ymd, KEY_MT_TRAN_YMD))
		{
			return false;
		}
		
		// MT処理年月日の値が「00000000」以外の場合、妥当性チェックを実施。
		if(!"00000000".equals(mt_tran_ymd))
		{
			// 日付の妥当性のチェック
			if(!JCCBatCommon.isYearMonthDay1(mt_tran_ymd))
			{
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0080TE, new String[]{"日付の妥当性エラー：" + mt_tran_ymd});
				return false;
			}
			else
			{
				index = index + 8;
			}
		}		
		else
		{
			index = index + 8;
		}
		
		// 結果リスト出力オプション（62, 63）
		String rslt_list_op = value.substring(index, index + 1);
		if(!this.isHannkakuESuuji3(rslt_list_op, KEY_RSLT_LIST_OP))
		{
			return false;
		}
		else
		{
			index = index + 1;
		}
		
		// コンシューマファイルの場合
		if(flg)
		{
			// 予備1（63, 110）
			String yobi1 = value.substring(index, index + 47);
			if(!this.isHannkakuESuuji3(yobi1, KEY_YOBI1))
			{
				return false;
			}
			else
			{
				index = index + 47;
			}
		}
		else
		{
			// 予備1（63, 95）
			String yobi1 = value.substring(index, index + 32);
			if(!this.isHannkakuESuuji3(yobi1, KEY_YOBI1))
			{
				return false;
			}
			else
			{
				index = index + 32;
			}
			
			// カード会社任意使用欄（95, 125）
			String card_comp_nin_use_field = value.substring(index);
			if(!this.isHannkakuESuuji3(card_comp_nin_use_field, KEY_CARD_COMP_NIN_USE_FIELD))
			{
				return false;
			}
		}
		
		return true;
	}
	
	/**
	 * データレコードの単項目チェックを実施します。<br>
	 * <p>
	 * @param value 125バイト分の文字列
	 * @param flg true:コンシューマファイル用、false:法人ファイル用
	 * @return boolean　true：チェックOK、false：チェックNG
	 */
	private boolean isDataRec(String value, boolean flg)
	{
		
		int index = 0;
		
		// データの各項目を取得し、チェックを行う。チェックOKの場合にマップへ保持します。
		// トータルレコードID（0, 5）
		String total_rec_id = value.substring(index, index + 5);
		if (!this.isHannkakuSuuji1(total_rec_id, KEY_T_REC_ID))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// レコード区分（5, 6）
		String rec_kbn = value.substring(index, index + 1);
		if (!this.isHannkakuSuuji1(rec_kbn, KEY_REC_KBN))
		{
			return false;
		}
		else
		{
			index = index + 1;
		}
		
		// 予備2（6, 9）
		String yobi2 = value.substring(index, index + 3);
		if (!this.isHannkakuESuuji3(yobi2, KEY_YOBI2))
		{
			return false;
		}
		else
		{
			index = index + 3;
		}
		
		// クレジットカード番号（9, 25）※カード預りIDが設定されている
		String creca_num = value.substring(index, index + 16);
// ANK-2565-00-00 MOD START
//		if (!this.isHannkakuSuuji1(creca_num, KEY_CRECA_NUM))
		if (!this.isHannkakuESuuji1(creca_num, KEY_CRECA_NUM))
// ANK-2565-00-00 MOD END
		{
			return false;
		}
		else
		{
			index = index + 16;
		}
		
		// クレジットカード有効期限（25, 29）
		String creca_yk_kigen = value.substring(index, index + 4);
		if (!this.isHannkakuSuuji1(creca_yk_kigen, KEY_CRECA_YK_KIGEN))
		{
			return false;
		}
		// 有効期限の妥当性チェック(YYMM)
		if(!JCCBatCommon.isYearMonth2(creca_yk_kigen))
		{
			super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0080TE, new String[] { KEY_CRECA_YK_KIGEN + "：年月の妥当性エラー："
					+ creca_yk_kigen });
			return false;
		}
		else
		{
			index = index + 4;
		}
		
		// 加盟店任意使用欄1（29, 49）
		String membstr_nin_use_field1 = value.substring(index, index + 20);
		if (!this.isHannkakuESuuji3(membstr_nin_use_field1, KEY_MEMBSTR_NIN_USE_FIELD1))
		{
			return false;
		}
		else
		{
			index = index + 20;
		}
		
		// 加盟店任意使用欄2（49, 64）
		index = index + 15;
		
		// クレジットカード番号更新サイン（64, 65）
		String creca_num_upd_sign = value.substring(index, index + 1);
		if (!this.isHannkakuESuuji3(creca_num_upd_sign, KEY_CRECA_NUM_UPD_SIGN))
		{
			return false;
		}
		else
		{
			index = index + 1;
		}
		
		// クレジットカード有効期限更新サイン（65, 66）
		String creca_yk_kigen_upd_sign = value.substring(index, index + 1);
		if (!this.isHannkakuESuuji3(creca_yk_kigen_upd_sign, KEY_CRECA_YK_KIGEN_UPD_SIGN))
		{
			return false;
		}
		else
		{
			index = index + 1;
		}
		
		// 予備4（66, 69）
		String yobi4 = value.substring(index, index + 3);
		if (!this.isHannkakuESuuji3(yobi4, KEY_YOBI4))
		{
			return false;
		}
		else
		{
			index = index + 3;
		}
		
		// 新クレジットカード番号（69, 85）
		String new_creca_num = value.substring(index, index + 16);
		if (!this.isHannkakuSuuji1(new_creca_num, KEY_NEW_CRECA_NUM))
		{
			return false;
		}
		else
		{
			index = index + 16;
		}
		
		// 新クレジットカード有効期限（85, 89）
		String new_creca_yk_kigen = value.substring(index, index + 4);
		if (!this.isHannkakuSuuji1(new_creca_yk_kigen, KEY_NEW_CRECA_YK_KIGEN))
		{
			return false;
		}
		
		// 有効期限の妥当性チェック(YYMM)
		if(!"0000".equals(new_creca_yk_kigen) && !"".equals(new_creca_yk_kigen))
		{
			if(!JCCBatCommon.isYearMonth2(new_creca_yk_kigen))
			{
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0080TE, new String[] { KEY_CRECA_YK_KIGEN + "：年月の妥当性エラー："
						+ new_creca_yk_kigen });
				return false;
			}
			else
			{
				index = index + 4;
			}
		}
		else
		{
			index = index + 4;
		}
		
		// 有効性確認結果（89, 90）
		String yk_cfm_rslt = value.substring(index, index + 1);
		if (!this.isHannkakuESuuji3(yk_cfm_rslt, KEY_YK_CFM_RSLT))
		{
			return false;
		}
		else
		{
			index = index + 1;
		}
		
		// コンシューマの場合
		if(flg)
		{
			// 予備5（90, 125）
			String yobi5 = value.substring(index);
			if (!this.isHannkakuESuuji3(yobi5, KEY_YOBI5))
			{
				return false;
			}
			else
			{
				index = index + 35;
			}
		}
		else
		{
			// 予備5（90, 110）
			String yobi5 = value.substring(index, index + 20);
			if (!this.isHannkakuESuuji3(yobi5, KEY_YOBI5))
			{
				return false;
			}
			else
			{
				index = index + 20;
			}
			
			// カード会社任意使用欄（110, 125）
			String card_comp_nin_use_field = value.substring(index);
			if (!this.isHannkakuESuujiKana3(card_comp_nin_use_field, KEY_CARD_COMP_NIN_USE_FIELD))
			{
				return false;
			}
		}
		return true;
	}
	
	/**
	 * トレーラレコードの単項目チェックを実施します。<br>
	 * <p>
	 * @param value 125バイト分の文字列
	 * @return boolean　true：チェックOK、false：チェックNG
	 */
	private boolean isTrailerRec(String value)
	{
		int index = 0;
		
		// トレーラレコードの各項目を取得し、チェックを行う。チェックOKの場合にマップへ保持します。
		// トータルレコードID（0, 5）
		String total_rec_id = value.substring(index, index + 5);
		if (!this.isHannkakuSuuji1(total_rec_id, KEY_T_REC_ID))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// レコード区分（5, 6）
		String rec_kbn = value.substring(index, index + 1);
		if (!this.isHannkakuSuuji1(rec_kbn, KEY_REC_KBN))
		{
			return false;
		}
		else
		{
			index = index + 1;
		}
		
		// 入力件数（6, 13）
		String input_cnt = value.substring(index, index + 7);
		if (!this.isHannkakuSuuji1(input_cnt, KEY_INPUT_CNT))
		{
			return false;
		}
		else
		{
			index = index + 7;
		}
		
		// OK件数（13, 20）
		String ok_cnt = value.substring(index, index + 7);
		if (!this.isHannkakuSuuji1(ok_cnt, KEY_OK_CNT))
		{
			return false;
		}
		else
		{
			index = index + 7;
		}
		
		// NG件数（20, 27）
		String ng_cnt = value.substring(index, index + 7);
		if (!this.isHannkakuSuuji1(ng_cnt, KEY_NG_CNT))
		{
			return false;
		}
		else
		{
			index = index + 7;
		}
		
		// エラー件数（27, 34）
		String error_cnt = value.substring(index, index + 7);
		if (!this.isHannkakuSuuji1(error_cnt, KEY_ERROR_CNT))
		{
			return false;
		}
		else
		{
			index = index + 7;
		}
		
		// クレジットカード番号更新件数（34, 41）
		String creca_num_upd_cnt = value.substring(index, index + 7);
		if (!this.isHannkakuSuuji1(creca_num_upd_cnt, KEY_CRECA_NUM_UPD_CNT))
		{
			return false;
		}
		else
		{
			index = index + 7;
		}
		
		// クレジットカード有効期限更新件数（41, 48）
		String creca_yk_kigen_upd_cnt = value.substring(index, index + 7);
		if (!this.isHannkakuSuuji1(creca_yk_kigen_upd_cnt, KEY_CRECA_YK_KIGEN_UPD_CNT))
		{
			return false;
		}
		else
		{
			index = index + 7;
		}
		
		// 予備6（48, 110）
		String yobi6 = value.substring(index, index + 62);
		if (!this.isHannkakuESuuji3(yobi6, KEY_YOBI6))
		{
			return false;
		}
		else
		{
			index = index + 62;
		}
		
		// カード会社任意使用欄（110, 125）
		String card_comp_nin_use_field = value.substring(index);
		if (!this.isHannkakuESuujiKana3(card_comp_nin_use_field, KEY_CARD_COMP_NIN_USE_FIELD))
		{
			return false;
		}
		return true;
	}
	
	/**
	 * エンドレコードの単項目チェックを実施します。<br>
	 * <p>
	 * @param value 125バイト分の文字列
	 * @return boolean　true：チェックOK、false：チェックNG
	 */
	private boolean isEndRec(String value)
	{
		int index = 0;
		
		// エンドの各項目を取得し、チェックを行う。チェックOKの場合にマップへ保持します。
		// トータルレコードID（0, 5）
		String total_rec_id = value.substring(index, index + 5);
		if (!this.isHannkakuSuuji1(total_rec_id, KEY_T_REC_ID))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// レコード区分（5, 6）
		String rec_kbn = value.substring(index, index + 1);
		if (!this.isHannkakuSuuji1(rec_kbn, KEY_REC_KBN))
		{
			return false;
		}
		else
		{
			index = index + 1;
		}
		
		// 予備（6, 125）
		String yobi = value.substring(index);
		if (!this.isHannkakuESuuji3(yobi, KEY_YOBI7))
		{
			return false;
		}
		return true;
	}
	
	/**
	 * サブトレーラレコードの単項目チェックを実施します。<br>
	 * <p>
	 * @param value 125バイト分の文字列
	 * @return boolean　true：チェックOK、false：チェックNG
	 */
	private boolean isSubTrailerRec(String value)
	{
		int index = 0;
		
		// サブトレーラレの各項目を取得し、チェックを行う。チェックOKの場合にマップへ保持します。
		// トータルレコードID（0, 5）
		String total_rec_id = value.substring(index, index + 5);
		if (!this.isHannkakuSuuji1(total_rec_id, KEY_T_REC_ID))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// データ件数（5, 13）
		String data_cnt = value.substring(index, index + 8);
		if (!this.isHannkakuSuuji1(data_cnt, KEY_DATA_CNT))
		{
			return false;
		}
		else
		{
			index = index + 8;
		}
		
		// 予備（13, 125）
		String yobi = value.substring(index);
		if (!this.isHannkakuESuuji3(yobi, KEY_YOBI))
		{
			return false;
		}
		return true;
	}
	
	/**
	 * トータルトレーラレコードの単項目チェックを実施します。<br>
	 * <p>
	 * @param value 125バイト分の文字列
	 * @return boolean　true：チェックOK、false：チェックNG
	 */
	private boolean isTotalTrailerRec(String value)
	{
		int index = 0;
		
		// トータルトレーラの各項目を取得し、チェックを行う。チェックOKの場合にマップへ保持します。
		// トータルレコードID（0, 5）
		String total_rec_id = value.substring(index, index + 5);
		if (!this.isHannkakuSuuji1(total_rec_id, KEY_T_REC_ID))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// データ件数（5, 13）
		String data_cnt = value.substring(index, index + 8);
		if (!this.isHannkakuSuuji1(data_cnt, KEY_DATA_CNT))
		{
			return false;
		}
		else
		{
			index = index + 8;
		}
		
		// 伝送ファイル数（13, 19）
		String denso_file_cnt = value.substring(index, index + 6);
		if (!this.isHannkakuSuuji1(denso_file_cnt, KEY_DENSO_FILE_CNT))
		{
			return false;
		}
		else
		{
			index = index + 6;
		}
		
		// 予備（19, 125）
		String yobi = value.substring(index);
		if (!this.isHannkakuESuuji3(yobi, KEY_YOBI))
		{
			return false;
		}
		return true;
	}
	
	/**
	 * トータルエンドレコードの単項目チェックを実施します。<br>
	 * <p>
	 * @param value 125バイト分の文字列
	 * @return boolean　true：チェックOK、false：チェックNG
	 */
	private boolean isTotalEndRec(String value)
	{
		int index = 0;
		
		// トータルエンドの各項目を取得し、チェックを行う。チェックOKの場合にマップへ保持します。
		// トータルレコードID（0, 5）
		String total_rec_id = value.substring(index, index + 5);
		if (!this.isHannkakuSuuji1(total_rec_id, KEY_T_REC_ID))
		{
			return false;
		}
		else
		{
			index = index + 5;
		}
		
		// 予備（5, 125）
		String yobi = value.substring(index);
		if (!this.isHannkakuESuuji3(yobi, KEY_YOBI))
		{
			return false;
		}
		return true;
	}
	
	/**
	 * トレーラレコードの情報を作成します。<br>
	 * <p>
	 * @param consyuma コンシューマ有効性チェック要求情報保持(マージ後)
	 * @param iDataCnt　データレコード数
	 * @throws Exception 
	 */
	private void createTrailerRec(StringBuilder consyuma, int iDataCnt) throws Exception
	{
		// トレーラレコードの作成
		consyuma.append(JKKBatConst.S_TTL_REC_ID_CARDCO);												// トータルレコードID
		consyuma.append(JCNStrConst.S_DATA_KBN_TRAL);													// データ区分
		consyuma.append(JBSbatStringUtil.padNumFormString(String.valueOf(iDataCnt), 7));				// 入力件数
		consyuma.append(JBSbatStringUtil.padNumFormString(JKKBatConst.SPACE, 7));						// OK件数
		consyuma.append(JBSbatStringUtil.padNumFormString(JKKBatConst.SPACE, 7));						// NG件数
		consyuma.append(JBSbatStringUtil.padNumFormString(JKKBatConst.SPACE, 7));						// エラー件数
		consyuma.append(JBSbatStringUtil.padNumFormString(JKKBatConst.SPACE, 7));						// クレジットカード番号更新件数
		consyuma.append(JBSbatStringUtil.padNumFormString(JKKBatConst.SPACE, 7));						// クレジットカード有効期限更新件数
		consyuma.append(JBSbatStringUtil.adjustCharSize(JKKBatConst.SPACE, 62, JKKBatConst.SJIS));		// 予備6
		consyuma.append(JBSbatStringUtil.adjustCharSize(JKKBatConst.SPACE, 15, JKKBatConst.SJIS));		// カード会社任意使用欄
	}
	
	/**
	 * サブトレーラレコードの情報を作成します。<br>
	 * <p>
	 * @param consyuma コンシューマ有効性チェック要求情報保持(マージ後)
	 * @param isubtrlDataCnt　サブトレーラデータ件数カウンタ
	 * @throws Exception 
	 */
	private void createSubTrailerRec(StringBuilder consyuma, int isubtrlDataCnt) throws Exception
	{
		// サブトレーラレコード作成
		consyuma.append(JKKBatConst.S_TTL_REC_ID_SUBTRAL);																// トータルレコードID
		consyuma.append(JBSbatStringUtil.padNumFormString(String.valueOf(isubtrlDataCnt + isubtrlDataCnt_hojin), 8));	// データ件数
		consyuma.append(JBSbatStringUtil.adjustCharSize(JKKBatConst.SPACE, 112, JKKBatConst.SJIS));						// 予備
	}
	
	/**
	 * トータルトレーラレコードの情報を作成します。<br>
	 * <p>
	 * @param consyuma コンシューマ有効性チェック要求情報保持(マージ後)
	 * @throws Exception 
	 */
	private void createTotalTrailerRec(StringBuilder consyuma) throws Exception
	{
		// トータルトレーラレコードに設定するデータ件数、伝送ファイル数を算出し、取得します。
		int[] count = getCountForTotalTrail(consyuma.toString());
		
		// トータルトレーラレコード作成
		consyuma.append(JKKBatConst.S_TTL_REC_ID_TTLTRAL);												// トータルレコードID
		consyuma.append(JBSbatStringUtil.padNumFormString(String.valueOf(count[0]), 8));				// データ件数
		consyuma.append(JBSbatStringUtil.padNumFormString(String.valueOf(count[1]), 6));				// 伝送ファイル数
		consyuma.append(JBSbatStringUtil.adjustCharSize(JKKBatConst.SPACE, 106, JKKBatConst.SJIS));		// 予備
	}
	
	/**
	 * 半角数字１単項目チェックを実施します。<br>
	 * <p>
	 * @param value 値
	 * @param name 項目名
	 * @return true：チェックOK、false：チェックNG
	 */
	private boolean isHannkakuSuuji1(String value, String name)
	{
		boolean rslt = true;
		
		// NULLでなく、空文字でない場合
		if (value != null || !"".equals(value))
		{
		
			// 属性チェック
			rslt = JCCBatCommon.isHannkakuSuuji1(value);
			
			if (!rslt)
			{
				// 業務エラーログ出力
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0080TE, new String[]{name});
				return false;
			}
		}
		return rslt;
	}
	
	/**
	 * 半角英数字１単項目チェックを実施します。<br>
	 * <p>
	 * @param value 値
	 * @param name 項目名
	 * @return true：チェックOK、false：チェックNG
	 */
	private boolean isHannkakuESuuji1(String value, String name)
	{
		boolean rslt = true;
		
		// 属性チェック
		rslt = JCCBatCommon.isHannkakuESuuji1(value);
		
		if (!rslt)
		{
			// 業務エラーログ出力
			super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0080TE, new String[]{name});
			return false;
		}
		return rslt;
	}
	
	/**
	 * 半角英数字３単項目チェックを実施します。<br>
	 * <p>
	 * @param value 値
	 * @param name 項目名
	 * @return true：チェックOK、false：チェックNG
	 */
	private boolean isHannkakuESuuji3(String value, String name)
	{
		boolean rslt = true;
		
		// 必須チェックでない場合で空文字以外
		if (!"".equals(value))
		{
			// 属性チェック
			rslt = JCCBatCommon.isHannkakuESuuji3(value);
			
			if (!rslt)
			{
				// 業務エラーログ出力
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0080TE, new String[]{name});
				return false;
			}
		}
		return rslt;
	}

	/**
	 * 半角英数字カナ３単項目チェックを実施します。<br>
	 * <p>
	 * @param value 値
	 * @param name 項目名
	 * @return true：チェックOK、false：チェックNG
	 */
	private boolean isHannkakuESuujiKana3(String value, String name)
	{
		boolean rslt = true;
		
		// NULLでなく、空文字でない場合
		if (value != null || !"".equals(value))
		{
			// 属性チェック
			rslt = JCCBatCommon.isHannkakuESuujiKana3(value);
			
			if (!rslt)
			{
				// 業務エラーログ出力
				super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0080TE, new String[]{name});
				return false;
			}
		}
		return rslt;
	}
}
