/*********************************************************************
*	All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：JCHSeikyYoksiHriwakeCC
*   ソースファイル名：JCHSeikyYoksiHriwakeCC.java
*   作成者          ：富士通
*   日付            ：2012年01月17日
*＜機能概要＞
*  請求抑止振分CC部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2012/01/17	富士通		新規作成
*	v10.00.00	2014/09/08	富士通		【OM-2014-0002891】請求抑止年月日更新不備修正
*
**********************************************************************/
package com.fujitsu.futurity.bp.custom.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.fujitsu.futurity.bp.custom.constant.JCHSeikyYoksiHriwakeConstCC;
import com.fujitsu.futurity.bp.x21.bpm.ServiceComponentRequestInvoker;
import com.fujitsu.futurity.bp.x21.bpm.db.SessionHandle;
import com.fujitsu.futurity.bp.x21.bpm.exception.RequestParameterException;
import com.fujitsu.futurity.bp.x21.bpm.parameter.IRequestParameterReadWrite;
import com.fujitsu.futurity.bp.x21.cc.AbstractCommonComponent;
import com.fujitsu.futurity.bp.x21.cc.exception.CCException;
import com.fujitsu.futurity.common.JCMConstants;
import com.fujitsu.futurity.common.x01.sc.SCControlMapKeys;
import com.fujitsu.futurity.mapping.bp.common.TemplateErrorUtil;
import com.fujitsu.futurity.model.base.CAANMsg;
import com.fujitsu.futurity.model.common.JCMAPLConstMgr;

import eo.common.constant.JACStrConst;
import eo.ejb.cbs.cbsmsg.EKK0541C010CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0541D010CBSMsg;

/**
 * 督促状況更新の各サービスより呼び出される請求抑止振分CC部品です。<p>
 * <BR>
 * @author 富士通
 */
public class JCHSeikyYoksiHriwakeCC extends AbstractCommonComponent {

	/** 抑止情報なし */
	private static final String YOKSI_INFO_NS = "0";
	/** 抑止情報あり */
	private static final String YOKSI_INFO_AR = "1";

	/**
	 * 請求抑止振分処理チェック処理.<br>
	 * 
	 * @param handle セッションハンドル
	 * @param param リクエストパラメータ
	 * @param fixedText サービスメッセージ
	 * @return HashMap<String, Object>
	 * @throws RequestParameterException RequestParameterException
	 */
	public HashMap<String, Object> getInvokeCBS(SessionHandle handle, 
				IRequestParameterReadWrite param, String fixedText) throws RequestParameterException 
	{
		/* ◇パラメータマップ生成 */
		HashMap<String, Object> paramMap = this.createNewParamMap(param);
		
		/* ◇テンプレートリスト生成 */
		ArrayList<CAANMsg> templateList = new ArrayList<CAANMsg>();
		
		// MAPリストを取得
		ArrayList<HashMap<String, Object>> inList = this.getMapListItem(param, JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_HRIWAKE_LIST);

		if (inList != null)
		{
			for (int i = 0; i < inList.size(); i++){
				HashMap<String,Object> childMap = inList.get(i);

				// 請求抑止変更か請求抑止登録かを判断する
				if(YOKSI_INFO_AR.equals(seikyYoksiJuge(childMap))) {
					// 請求抑止更新サービスIF用メッセージ設定処理
					ArrayList<CAANMsg> templateEKK0541C010 = editInMsgEKK0541C010(param, childMap);
					
					for (CAANMsg msg : templateEKK0541C010)
					{
						templateList.add(msg);
					}
				}
				else if(YOKSI_INFO_NS.equals(seikyYoksiJuge(childMap)))
				{
					// 請求抑止登録サービスIF用メッセージ設定処理
					ArrayList<CAANMsg> templateEKK0541D010 = editInMsgEKK0541D010(param, childMap);
					
					for (CAANMsg msg : templateEKK0541D010)
					{
						templateList.add(msg);
					}
				}
			}
		}

		CAANMsg[] templates = templateList.toArray(new CAANMsg[templateList.size()]);
		paramMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);

		return paramMap;
	}
	// ▲▲ invokeCBSによる単項目チェック処理 ▲▲
	
	
	// ▼▼ 請求抑止処理 ▼▼
	/**
	 * 請求抑止振分処理.<br>
	 * 
	 * @param handle セッションハンドル
	 * @param param リクエストパラメータ
	 * @param fixedText サービスメッセージ
	 * @return リクエストパラメータ
	 * @throws Exception 
	 */
	public IRequestParameterReadWrite hriwakeSeikyYoksi(SessionHandle handle, 
				IRequestParameterReadWrite param, String fixedText) throws Exception 
	{

		// MAPリストを取得
		ArrayList<HashMap<String, Object>> inList = this.getMapListItem(param, JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_HRIWAKE_LIST);

		if (inList != null)
		{
			for (int i = 0; i < inList.size(); i++){
				HashMap<String,Object> childMap = inList.get(i);

				// 請求抑止変更か請求抑止登録かを判断する
				if(YOKSI_INFO_AR.equals(seikyYoksiJuge(childMap))) {
					// 抑止情報有無が有の場合、請求抑止変更サービスを呼び出す
					execEKK0541C010(handle, param, childMap);
				}
				else if(YOKSI_INFO_NS.equals(seikyYoksiJuge(childMap))) {
					// 抑止情報有無が無の場合、請求抑止登録サービスを呼び出す
					execEKK0541D010(handle, param, childMap);
				}
			}
		}

		return param;
	}

	/**
	 * 請求抑止変更サービスインターフェイス実行処理.<br>
	 * @param handle   セッションハンドル
	 * @param param    リクエストパラメータ
	 * @param childMap マップ
	 * @throws Exception 例外が発生した場合
	 */
	private void execEKK0541C010(SessionHandle handle, IRequestParameterReadWrite param, HashMap<String,Object> childMap) throws Exception
	{
		/* ◇パラメータマップ生成 */
		HashMap<String, Object> paramMap = this.createNewParamMap(param);

		/* ◇テンプレートリスト生成 */
		ArrayList<CAANMsg> templateList = new ArrayList<CAANMsg>();

		// 上りマッピング
		ArrayList<CAANMsg> templateEKK0541C010 = editInMsgEKK0541C010(param, childMap);
		for (CAANMsg msg : templateEKK0541C010)
		{
			templateList.add(msg);
		}
		CAANMsg[] templates = templateList.toArray(new CAANMsg[templateList.size()]);
		paramMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);

		// ＳＣ呼出実行
		ServiceComponentRequestInvoker scCall = new ServiceComponentRequestInvoker();
		Map<?, ?> result = scCall.run(paramMap, handle);

		// 下りマッピング
		editOutMsgEKK0541C010(result, param);
	}

	/**
	 * 請求抑止登録サービスインターフェイス実行処理.<br>
	 * @param handle   セッションハンドル
	 * @param param    リクエストパラメータ
	 * @param childMap マップ
	 * @throws Exception 例外が発生した場合
	 */
	private void execEKK0541D010(SessionHandle handle, IRequestParameterReadWrite param, HashMap<String,Object> childMap) throws Exception
	{
		/* ◇パラメータマップ生成 */
		HashMap<String, Object> paramMap = this.createNewParamMap(param);

		/* ◇テンプレートリスト生成 */
		ArrayList<CAANMsg> templateList = new ArrayList<CAANMsg>();

		// 上りマッピング
		ArrayList<CAANMsg> templateEKK0541D010 = editInMsgEKK0541D010(param, childMap);
		for (CAANMsg msg : templateEKK0541D010)
		{
			templateList.add(msg);
		}
		CAANMsg[] templates = templateList.toArray(new CAANMsg[templateList.size()]);
		paramMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);

		// ＳＣ呼出実行
		ServiceComponentRequestInvoker scCall = new ServiceComponentRequestInvoker();
		Map<?, ?> result = scCall.run(paramMap, handle);

		// 下りマッピング
		editOutMsgEKK0541D010(result, param);
	}

	/**
	 * 請求抑止変更サービスインターフェイス用メッセージ設定処理<br>
	 * @param param リクエストパラメータ
	 * @return HashMap<String, Object>
	 * @throws RequestParameterException
	 */
	private ArrayList<CAANMsg> editInMsgEKK0541C010(IRequestParameterReadWrite param, HashMap<String,Object> childMap) throws RequestParameterException
	{
		HashMap<String, Object> inMap = this.getMap(param);
		ArrayList<CAANMsg> templateList = new ArrayList<CAANMsg>();

		/* ◇テンプレート生成 */
		CAANMsg template = new CAANMsg(EKK0541C010CBSMsg.class.getName());
		this.setTemplateCommonItem(param, template, 
				EKK0541C010CBSMsg.TEMPLATEID, JCHSeikyYoksiHriwakeConstCC.TEMPLATE_ID_EKK0541C010, EKK0541C010CBSMsg.FUNC_CODE);

		if (childMap != null)
		{
			// 機能コード
			template.set(EKK0541C010CBSMsg.FUNC_CODE, inMap.get(JCMConstants.FUNC_CODE_KEY));

			// 請求契約番号
			template.set(EKK0541C010CBSMsg.SEIKY_KEI_NO, (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_KEI_NO));

			// 請求抑止コード
			template.set(EKK0541C010CBSMsg.SEIKY_YOKSI_CD, (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_CD));

			// 請求抑止フラグ
			template.set(EKK0541C010CBSMsg.SEIKY_YOKSI_FLG, (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_FLG));

			// 請求抑止フラグ
			String yoksiFlg = (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_FLG);
			if (yoksiFlg == null) {
				yoksiFlg = JACStrConst.KARA_MOJI;
			}

			// 変更前抑止フラグ
			String henkoMaeYoksiFlg = (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_HENKO_MAE_YOKSI_FLG);
			if (henkoMaeYoksiFlg == null) {
				henkoMaeYoksiFlg = JACStrConst.KARA_MOJI;
			}

			// 請求抑止解除年月日 抑止フラグが1⇒0になった場合
			if (JACStrConst.YOKSI_FLG_ARI.equals(henkoMaeYoksiFlg) && JACStrConst.YOKSI_FLG_NASHI.equals(yoksiFlg))
			{
				template.set(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_YMD, JCCBPCommon.getOpeDate(JACStrConst.SYS_CD_CH));
			}
			else
			{
				// OM-2014-0002891 ADD START
//				// 請求抑止年月日
//				template.set(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_YMD,  (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_RLS_YMD));
				// 請求抑止年月日
				template.set(EKK0541C010CBSMsg.SEIKY_YOKSI_YMD, JCCBPCommon.getOpeDate(JACStrConst.SYS_CD_CH));
				// 請求抑止解除年月日
				template.set(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_YMD, JACStrConst.KARA_MOJI);
				// OM-2014-0002891 ADD END
			}

			// 請求抑止解除予定年月日
			template.set(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD, (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_RLS_RSV_YMD));

			// 更新年月日時分秒(更新前)
			template.set(EKK0541C010CBSMsg.UPD_DTM_BF, (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_UPD_DTM_BF));
		}

		templateList.add(template);

		return templateList;
	}

	/**
	 * 請求抑止登録サービスインターフェイス用メッセージ設定処理<br>
	 * @param param リクエストパラメータ
	 * @return HashMap<String, Object>
	 * @throws RequestParameterException
	 */
	private ArrayList<CAANMsg> editInMsgEKK0541D010(IRequestParameterReadWrite param, HashMap<String,Object> childMap) throws RequestParameterException
	{
		HashMap<String, Object> inMap = this.getMap(param);
		ArrayList<CAANMsg> templateList = new ArrayList<CAANMsg>();

		/* ◇テンプレート生成 */
		CAANMsg template = new CAANMsg(EKK0541D010CBSMsg.class.getName());

		this.setTemplateCommonItem(param, template, 
				EKK0541D010CBSMsg.TEMPLATEID, JCHSeikyYoksiHriwakeConstCC.TEMPLATE_ID_EKK0541D010, EKK0541D010CBSMsg.FUNC_CODE);

		if (childMap != null)
		{
			// 機能コード
			template.set(EKK0541D010CBSMsg.FUNC_CODE, inMap.get(JCMConstants.FUNC_CODE_KEY));

			// 請求契約番号
			template.set(EKK0541D010CBSMsg.SEIKY_KEI_NO, (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_KEI_NO));

			// 請求抑止コード
			template.set(EKK0541D010CBSMsg.SEIKY_YOKSI_CD, (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_CD));

			// 請求抑止フラグ
			template.set(EKK0541D010CBSMsg.SEIKY_YOKSI_FLG, (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_FLG));

			// 請求抑止フラグ
			String yoksiFlg = (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_FLG);
			if (yoksiFlg == null) {
				yoksiFlg = JACStrConst.KARA_MOJI;
			}

			// 変更前抑止フラグ
			String henkoMaeYoksiFlg = (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_HENKO_MAE_YOKSI_FLG);
			if (henkoMaeYoksiFlg == null) {
				henkoMaeYoksiFlg = JACStrConst.KARA_MOJI;
			}

			// 請求抑止年月日 抑止フラグが0⇒1になった場合
			if (JACStrConst.YOKSI_FLG_NASHI.equals(henkoMaeYoksiFlg) && JACStrConst.YOKSI_FLG_ARI.equals(yoksiFlg))
			{
				template.set(EKK0541D010CBSMsg.SEIKY_YOKSI_YMD, JCCBPCommon.getOpeDate(JACStrConst.SYS_CD_CH));
			}
			else
			{
				// 請求抑止年月日
				template.set(EKK0541D010CBSMsg.SEIKY_YOKSI_YMD,  (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_YMD));
			}

			// 請求抑止解除予定年月日
			template.set(EKK0541D010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD, (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_RLS_RSV_YMD));
		}

		templateList.add(template);

		return templateList;
	}

	/**
	 * 請求抑止変更サービスインターフェイス用メッセージ取得処理<br>
	 * 
	 * @param msgList メッセージリスト
	 * @param param リクエストパラメータ
	 * @return IRequestParameterReadWrite
	 * @throws Exception
	 */
	private IRequestParameterReadWrite editOutMsgEKK0541C010(Map<?, ?> msgList,
			IRequestParameterReadWrite param) throws Exception
	{

		// SCからの戻り値からCAANMsgを取得する。
		CAANMsg[] templates = (CAANMsg[])msgList.get(JCMConstants.TEMPLATE_LIST_KEY);

		// リターンコード取得
		Object return_code = msgList.get(JCMConstants.RET_CD_INT_KEY);

		// エラー情報の設定
		editErrorInfo(param, templates, (Integer)return_code);

		//エラー情報のマップを取得
		ArrayList<Object> errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO);
		if(errList == null)
		{
			errList = new ArrayList<Object>();
		}
		// コントロールマップに設定
		param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(msgList, errList));

		// 例外通知
		String rtnCode = msgList.get(JCMConstants.RET_CD_INT_KEY).toString();
		String status = (String)param.getControlMapData(SCControlMapKeys.RETURN_CODE);
		if(!("0".equals(rtnCode) && 0 == Integer.parseInt(status)))
		{
			throw new CCException("INVALID_RETURN_MESSAGE", new Exception());
		}

		return param;
	}

	/**
	 * 請求抑止登録サービスインターフェイス用メッセージ取得処理<br>
	 * 
	 * @param msgList メッセージリスト
	 * @param param リクエストパラメータ
	 * @return IRequestParameterReadWrite
	 * @throws Exception
	 */
	private IRequestParameterReadWrite editOutMsgEKK0541D010(Map<?, ?> msgList,
			IRequestParameterReadWrite param) throws Exception
	{

		// SCからの戻り値からCAANMsgを取得する。
		CAANMsg[] templates = (CAANMsg[])msgList.get(JCMConstants.TEMPLATE_LIST_KEY);

		// リターンコード取得
		Object return_code = msgList.get(JCMConstants.RET_CD_INT_KEY);

		// エラー情報の設定
		editErrorInfo(param, templates, (Integer)return_code);

		//エラー情報のマップを取得
		ArrayList<Object> errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO);
		if(errList == null)
		{
			errList = new ArrayList<Object>();
		}
		// コントロールマップに設定
		param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(msgList, errList));

		// 例外通知
		String rtnCode = msgList.get(JCMConstants.RET_CD_INT_KEY).toString();
		String status = (String)param.getControlMapData(SCControlMapKeys.RETURN_CODE);
		if(!("0".equals(rtnCode) && 0 == Integer.parseInt(status)))
		{
			throw new CCException("INVALID_RETURN_MESSAGE", new Exception());
		}

		return param;
	}

	// ▼▼ エラー情報マッピング処理 ▼▼
	/**
	 * サービスIF実行後に、IRequestParameterReadWriteにエラー情報をマッピングする
	 * @param param リクエストパラメータ
	 * @param templates テンプレート
	 * @param returnCode リターンコード
	 * @return IRequestParameterReadWrite
	 * @throws RequestParameterException RequestParameterException
	 */
	public IRequestParameterReadWrite editErrorInfo(IRequestParameterReadWrite param, CAANMsg[] templates, int returnCode) throws RequestParameterException
	{

		for (CAANMsg template : templates)
		{
			String templateId = template.getString("templateID");
			CAANMsg[] workTemplates = { template };
			if (JCHSeikyYoksiHriwakeConstCC.TEMPLATE_ID_EKK0541C010 .equals(templateId))
			{
				// 請求抑止変更
				editErrorInfoEKK0541C010(param, workTemplates, returnCode);
			}
			else if (JCHSeikyYoksiHriwakeConstCC.TEMPLATE_ID_EKK0541D010.equals(templateId))
			{
				// 請求抑止登録
				editErrorInfoEKK0541D010(param, workTemplates, returnCode);
			}
		}

		return param;
	}

	/**
	 * 請求抑止変更サービスIF実行後に、IRequestParameterReadWriteにエラー情報をマッピングする
	 * @param param      リクエストパラメータ
	 * @param templates  テンプレート
	 * @param returnCode リターンコード
	 * @return IRequestParameterReadWrite
	 * @throws RequestParameterException RequestParameterException
	 */
	public IRequestParameterReadWrite editErrorInfoEKK0541C010(IRequestParameterReadWrite param
			, CAANMsg[] templates, int returnCode) throws RequestParameterException
	{
		CAANMsg template = templates[0];

		int templateStatus = template.getInt(EKK0541C010CBSMsg.STATUS);

		if (returnCode != 0)
		{
			templateStatus = 9000;
		}

		if (JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)) == null)
		{
			templateStatus = 0;
		}

		int bpStatus = 0;
		Object obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE);
		if (obj == null)
		{
			bpStatus = -1;
		}
		else
		{
			bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE));
		}

		if (templateStatus > bpStatus)
		{
			// BPにサービスコンポーネントのステータスを設定する。
			String formatStatus = String.format("%1$04d", templateStatus);
			String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus);
			param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus);
			param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message);
		}

		HashMap<String, Object> inMap = this.getMap(param);

		// 請求契約番号 のエラー情報返却
		if (!template.isNull(EKK0541C010CBSMsg.SEIKY_KEI_NO_ERR)) {
			if (!inMap.containsKey(EKK0541C010CBSMsg.SEIKY_KEI_NO_ERR)) {
				inMap.put(EKK0541C010CBSMsg.SEIKY_KEI_NO_ERR, template.getString(EKK0541C010CBSMsg.SEIKY_KEI_NO_ERR));
			}
		}
		// 請求抑止コード のエラー情報返却
		if (!template.isNull(EKK0541C010CBSMsg.SEIKY_YOKSI_CD_ERR)) {
			if (!inMap.containsKey(EKK0541C010CBSMsg.SEIKY_YOKSI_CD_ERR)) {
				inMap.put(EKK0541C010CBSMsg.SEIKY_YOKSI_CD_ERR, template.getString(EKK0541C010CBSMsg.SEIKY_YOKSI_CD_ERR));
			}
		}
		// 請求抑止フラグ のエラー情報返却
		if (!template.isNull(EKK0541C010CBSMsg.SEIKY_YOKSI_FLG_ERR)) {
			if (!inMap.containsKey(EKK0541C010CBSMsg.SEIKY_YOKSI_FLG_ERR)) {
				inMap.put(EKK0541C010CBSMsg.SEIKY_YOKSI_FLG_ERR, template.getString(EKK0541C010CBSMsg.SEIKY_YOKSI_FLG_ERR));
			}
		}
		// 請求抑止解除年月日 のエラー情報返却
		if (!template.isNull(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_YMD_ERR)) {
			if (!inMap.containsKey(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_YMD_ERR)) {
				inMap.put(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_YMD_ERR, template.getString(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_YMD_ERR));
			}
		}
		// 請求抑止解除予定年月日 のエラー情報返却
		if (!template.isNull(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD_ERR)) {
			if (!inMap.containsKey(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD_ERR)) {
				inMap.put(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD_ERR, template.getString(EKK0541C010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD_ERR));
			}
		}
		// 更新年月日時分秒(更新前) のエラー情報返却
		if (!template.isNull(EKK0541C010CBSMsg.UPD_DTM_BF_ERR)) {
			if (!inMap.containsKey(EKK0541C010CBSMsg.UPD_DTM_BF_ERR)) {
				inMap.put(EKK0541C010CBSMsg.UPD_DTM_BF_ERR, template.getString(EKK0541C010CBSMsg.UPD_DTM_BF_ERR));
			}
		}

		return param;
	}

	/**
	 * 請求抑止登録サービスIF実行後に、IRequestParameterReadWriteにエラー情報をマッピングする
	 * @param param      リクエストパラメータ
	 * @param templates  テンプレート
	 * @param returnCode リターンコード
	 * @return IRequestParameterReadWrite
	 * @throws RequestParameterException RequestParameterException
	 */
	public IRequestParameterReadWrite editErrorInfoEKK0541D010(IRequestParameterReadWrite param
			, CAANMsg[] templates, int returnCode) throws RequestParameterException
	{
		CAANMsg template = templates[0];

		int templateStatus = template.getInt(EKK0541D010CBSMsg.STATUS);

		if (returnCode != 0)
		{
			templateStatus = 9000;
		}

		if (JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)) == null)
		{
			templateStatus = 0;
		}

		int bpStatus = 0;
		Object obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE);
		if (obj == null)
		{
			bpStatus = -1;
		}
		else
		{
			bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE));
		}

		if (templateStatus > bpStatus)
		{
			// BPにサービスコンポーネントのステータスを設定する。
			String formatStatus = String.format("%1$04d", templateStatus);
			String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus);
			param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus);
			param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message);
		}

		HashMap<String, Object> inMap = this.getMap(param);
		
		// 請求契約番号 のエラー情報返却
		if (!template.isNull(EKK0541D010CBSMsg.SEIKY_KEI_NO_ERR)) {
			if (!inMap.containsKey(EKK0541D010CBSMsg.SEIKY_KEI_NO_ERR)) {
				inMap.put(EKK0541D010CBSMsg.SEIKY_KEI_NO_ERR, template.getString(EKK0541D010CBSMsg.SEIKY_KEI_NO_ERR));
			}
		}
		// 請求抑止コード のエラー情報返却
		if (!template.isNull(EKK0541D010CBSMsg.SEIKY_YOKSI_CD_ERR)) {
			if (!inMap.containsKey(EKK0541D010CBSMsg.SEIKY_YOKSI_CD_ERR)) {
				inMap.put(EKK0541D010CBSMsg.SEIKY_YOKSI_CD_ERR, template.getString(EKK0541D010CBSMsg.SEIKY_YOKSI_CD_ERR));
			}
		}
		// 請求抑止フラグ のエラー情報返却
		if (!template.isNull(EKK0541D010CBSMsg.SEIKY_YOKSI_FLG_ERR)) {
			if (!inMap.containsKey(EKK0541D010CBSMsg.SEIKY_YOKSI_FLG_ERR)) {
				inMap.put(EKK0541D010CBSMsg.SEIKY_YOKSI_FLG_ERR, template.getString(EKK0541D010CBSMsg.SEIKY_YOKSI_FLG_ERR));
			}
		}
		// 請求抑止年月日 のエラー情報返却
		if (!template.isNull(EKK0541D010CBSMsg.SEIKY_YOKSI_YMD_ERR)) {
			if (!inMap.containsKey(EKK0541D010CBSMsg.SEIKY_YOKSI_YMD_ERR)) {
				inMap.put(EKK0541D010CBSMsg.SEIKY_YOKSI_YMD_ERR, template.getString(EKK0541D010CBSMsg.SEIKY_YOKSI_YMD_ERR));
			}
		}
		// 請求抑止解除予定年月日 のエラー情報返却
		if (!template.isNull(EKK0541D010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD_ERR)) {
			if (!inMap.containsKey(EKK0541D010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD_ERR)) {
				inMap.put(EKK0541D010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD_ERR, template.getString(EKK0541D010CBSMsg.SEIKY_YOKSI_RLS_RSV_YMD_ERR));
			}
		}

		return param;
	}

	// ▼▼ クラス内共通処理 ▼▼
	/**
	 * サービスインタフェースに渡すパラメータマップを新規に作成します。
	 * マップには共通項目である電文ヘッダ、コントロールマップを設定します。
	 * <br>
	 * @param handle セッションハンドル
	 * @param param リクエストパラメータ
	 * @param childMap 請求契約明細１件のマップ
	 * @throws RequestParameterException パラメータ取得で例外が発生した場合
	 */
	private HashMap<String, Object> createNewParamMap(IRequestParameterReadWrite param) throws RequestParameterException
	{
		HashMap<String, Object> paramMap = new HashMap<String, Object>();

		/* ◇電文ヘッダ */
		// 電文ID
		paramMap.put(JCMConstants.TRANZACTION_ID_KEY, param.getTelegramID());
		// ユースケースID
		paramMap.put(JCMConstants.USECASE_ID_KEY, param.getUsecaseID());
		// オペレーションID
		paramMap.put(JCMConstants.OPERATION_ID_KEY, param.getOperationID());
		// サービス呼び出し区分
		paramMap.put(JCMConstants.CALL_TYPE_KEY, param.getCallType());

		/* ◇コントロールマップ */
		// 依頼先ホスト名
		paramMap.put(JCMConstants.CLIENT_HOST_NAME_KEY, param.getControlMapData(SCControlMapKeys.REQ_HOSTNAME));
		// 依頼元IPアドレス
		paramMap.put(JCMConstants.CLIENT_IP_ADDRESS_KEY, param.getControlMapData(SCControlMapKeys.REQ_HOSTIP));
		// 依頼元画面ID
		paramMap.put(JCMConstants.INVOKE_GAMEN_ID_KEY, param.getControlMapData(SCControlMapKeys.REQ_VIEWID));
		// オペレータID
		paramMap.put(JCMConstants.OPERATOR_ID_KEY, param.getControlMapData(SCControlMapKeys.OPERATOR_ID));

		return paramMap;
	}

	/**
	 * テンプレートの共通項目を設定します。
	 * <br>
	 * @param param リクエストパラメータ
	 * @param template テンプレート
	 * @param templateIdKey テンプレートIDキー名
	 * @param templateIdVal テンプレートID値
	 * @param templateFuncCdKey テンプレート機能コードキー名
	 * @throws RequestParameterException パラメータ取得で例外が発生した場合
	 */
	private CAANMsg setTemplateCommonItem(IRequestParameterReadWrite param, CAANMsg template, 
											String templateIdKey, String templateIdVal, String templateFuncCdKey) throws RequestParameterException
	{
		// テンプレートID
		template.set(templateIdKey, templateIdVal);

		// 機能コード（デフォルト：１）
		template.set(templateFuncCdKey, "1");

		// オペレータID
		Object operatorId = param.getControlMapData(SCControlMapKeys.OPERATOR_ID);
		template.set(JCMConstants.OPERATOR_ID_KEY, operatorId);

		// 運用日付
		Object operateDate = param.getControlMapData(SCControlMapKeys.OPE_DATE);
		template.set(JCMConstants.OPERATE_DATE_KEY, operateDate);

		// 運用日時
		Object operateDateTime = param.getControlMapData(SCControlMapKeys.OPE_TIME);
		template.set(JCMConstants.OPERATE_DATETIME_KEY, operateDateTime);

		return template;
	}

	/**
	 * 請求抑止振分マップを取得します。
	 * <br>
	 * @param param リクエストパラメータ
	 * @return 請求抑止振分マップ
	 * @throws RequestParameterException パラメータ取得で例外が発生した場合
	 */
	@SuppressWarnings("unchecked")
	private HashMap<String, Object> getMap(IRequestParameterReadWrite param) throws RequestParameterException
	{
		return (HashMap<String, Object>)param.getData(JCHSeikyYoksiHriwakeConstCC.MAP_CC_ID);
	}

	/**
	 * マップから指定された項目名の値を取得します。
	 * <br>
	 * @param param リクエストパラメータ
	 * @param key 項目名
	 * @return マップ項目値
	 * @throws RequestParameterException パラメータ取得で例外が発生した場合
	 */
	@SuppressWarnings("unchecked")
	private String getMapItem(IRequestParameterReadWrite param, String key) throws RequestParameterException
	{
		HashMap<String, Object> inMap = (HashMap<String, Object>)param.getData(JCHSeikyYoksiHriwakeConstCC.MAP_CC_ID);
		return (String)inMap.get(key);
	}

	/**
	 * マップから指定されたリスト項目名の値を取得します。
	 * <br>
	 * @param param リクエストパラメータ
	 * @param key リスト項目名
	 * @return マップ項目値
	 * @throws RequestParameterException パラメータ取得で例外が発生した場合
	 */
	@SuppressWarnings("unchecked")
	private ArrayList<HashMap<String, Object>> getMapListItem(IRequestParameterReadWrite param, String key) throws RequestParameterException
	{
		HashMap<String, Object> inMap = (HashMap<String, Object>)param.getData(JCHSeikyYoksiHriwakeConstCC.MAP_CC_ID);
		return (ArrayList<HashMap<String, Object>>)inMap.get(key);
	}
	// ▲▲ クラス内共通処理 ▲▲

	/**
	 * 請求抑止登録情報が登録か更新かを判断します
	 * <br>
	 * @param childMap 抑止情報
	 * @return String 抑止情報有:1 抑止情報無:0 登録更新対象外:空文字
	 * @throws RequestParameterException パラメータ取得で例外が発生した場合
	 */
	private String seikyYoksiJuge(HashMap<String,Object> childMap) throws RequestParameterException
	{
		String yoksiUm = JACStrConst.KARA_MOJI;

		// 請求抑止フラグ
		String yoksiFlg = (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_SEIKY_YOKSI_FLG);
		if (yoksiFlg == null) {
			yoksiFlg = JACStrConst.KARA_MOJI;
		}

		// 変更前抑止フラグ
		String henkoMaeYoksiFlg = (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_HENKO_MAE_YOKSI_FLG);
		if (henkoMaeYoksiFlg == null) {
			henkoMaeYoksiFlg = JACStrConst.KARA_MOJI;
		}

		// 抑止情報有無
		String yoksiInfoUm = (String)childMap.get(JCHSeikyYoksiHriwakeConstCC.MAP_KEY_YOKSI_INFO_UM);
		if (yoksiInfoUm == null) {
			yoksiInfoUm = JACStrConst.KARA_MOJI;
		}

		// 抑止フラグ ≠ 変更前抑止フラグの場合
		if (!yoksiFlg.equals(henkoMaeYoksiFlg)) {

			// 抑止情報有無が有
			if (yoksiInfoUm.equals(YOKSI_INFO_AR)) {
				yoksiUm = YOKSI_INFO_AR;
			}
			else
			{
				// 抑止情報有無が無
				yoksiUm = YOKSI_INFO_NS;
			}
		}

		return yoksiUm;
	}
}
