/*********************************************************************
*	All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名		：eo顧客基幹システム
*	モジュール名	：JKKSjishoAddCC
*	ソースファイル名：JKKSjishoAddCC.java
*	作成者			：FJ
*	日付			：2011年12月14日
*＜機能概要＞ 
*	契約紐付変更登録の共通コンポーネント
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2011/12/14	FJ）川田	新規作成
*	v4.00.00	2013/03/16	FJ）稲岡	【IT1-2013-0000478】対応
*	v4.00.01	2013/04/04	FJ）稲岡	【IT1-2013-0000770】対応
*   v11.00.00   2014/12/18	FJ )舩橋	【ST-2014-0000171】対応
*
**********************************************************************/
package com.fujitsu.futurity.bp.custom.common;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

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.SCCallException;
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.ejb.cbs.cbsmsg.ECK0151D010CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0081A010CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0081A010CBSMsg1List;
import eo.ejb.cbs.cbsmsg.EKK0081B006CBSMsg;

/**
 * 
 * @author 909486
 *
 */
public class JKKSjishoAddCC extends AbstractCommonComponent
{
	/** 指示書登録 */
	private static final String TEMPLATE_ID_ECK0151D010 = "ECK0151D010";
/* ++++++++++ v4.00.00 追加開始 ++++++++++ */
	/** サービス契約一意照会 */
	private static final String TEMPLATE_ID_EKK0081A010 = "EKK0081A010";
	/** FIXED KEY */
	private static final String FIXED_KEY_KEI_HMDK_SJISHO_ADD_CC = "KeiHmdkShijiAddCC";
/* ++++++++++ v4.00.00 追加終了 ++++++++++ */
/* ++++++++++ v4.00.01 追加開始 ++++++++++ */
	/** FIXED KEY */
	private static final String FIXED_KEY_JDG_EXEC_SJISHO_ADD_CC = "JdgExecSjishoAddCC";
/* ++++++++++ v4.00.01 追加終了 ++++++++++ */
	
	/**
	 * 指示書の登録処理を行います。
	 * 
	 * @param handle
	 * @param param
	 * @param fixedText
	 * @return IRequestParameterReadWrite
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public IRequestParameterReadWrite addSjisho(SessionHandle handle, 
												IRequestParameterReadWrite param, 
												String fixedText) throws Throwable, Exception
	{
		// ユーザデータ情報
		HashMap<String, Object> dataMap = (HashMap<String, Object>)param.getData(fixedText);
		String mtSysid = (String)dataMap.get("mt_sysid");
		String skSysid = (String)dataMap.get("sk_sysid");
		
		ServiceComponentRequestInvoker scCall = new ServiceComponentRequestInvoker();
		Map<?, ?> result = null;
		HashMap<String, Object> paramMap = null;
		HashMap<String, String> svcMap = null;
		
		HashMap<String, Object> work01Map = (HashMap<String, Object>)param.getData("KKSV0360WORK01");
		ArrayList<HashMap<String, String>> svcList = (ArrayList<HashMap<String, String>>)work01Map.get("svc_kei_list");
		
/* ++++++++++ v4.00.00 追加開始 ++++++++++ */
		// 作業領域の取得
		Map workMap = (Map)param.getMappingWorkArea();
		// 作業項目マップ
		HashMap workDataMap = (HashMap)workMap.get("WORK");
		
		workDataMap.put("sj_mt_sys_id", mtSysid);
		workDataMap.put("sj_sk_sys_id", skSysid);
/* ++++++++++ v4.00.00 追加終了 ++++++++++ */
		
		// 選択された併合元サービス契約一覧分繰り返す
		for(int i=0; i<svcList.size(); i++)
		{
			svcMap = svcList.get(i);
			
			// 画面で選択されている場合
			if((Boolean.valueOf(svcMap.get("isSelect"))))
			{
/* ++++++++++ v4.00.00 修正開始 ++++++++++ */
				// サービス契約一意照会
				Object[][] ekk0081a010In = {{EKK0081A010CBSMsg.TEMPLATEID, TEMPLATE_ID_EKK0081A010},
											{EKK0081A010CBSMsg.FUNC_CODE, "2"},
											{EKK0081A010CBSMsg.KEY_SVC_KEI_NO, (String)svcMap.get("svc_kei_no")},
											{EKK0081A010CBSMsg.KEY_GENE_ADD_DTM, ""},
											{EKK0081A010CBSMsg.KEY_RSV_APLY_YMD, JCCBPCommon.getOpeDate(null)}};
				
				CAANMsg[] ekk0081a010Out = callSC(handle, scCall, param, fixedText, ekk0081a010In).getCAANMsgList(EKK0081A010CBSMsg.EKK0081A010CBSMSG1LIST);
				
				if (ekk0081a010Out != null && ekk0081a010Out.length > 0)
				{
/* ++++++++++ v4.00.01 修正開始 ++++++++++ */
					//ST-2014-0000171 MOD START
//					if (isSjishoAdd(handle, param, svcMap))

					String svcCd = ekk0081a010Out[0].getString(EKK0081A010CBSMsg1List.SVC_CD);
					String svckeiStat = ekk0081a010Out[0].getString(EKK0081A010CBSMsg1List.SVC_KEI_STAT);
					if ("51".equals(svcCd) &&
							("020".equals(svckeiStat) || "030".equals(svckeiStat) ||
							 "100".equals(svckeiStat) || "220".equals(svckeiStat))) 
					{
						String pplanCd = ekk0081a010Out[0].getString(EKK0081A010CBSMsg1List.PPLAN_CD);
						String shosaYmd = ekk0081a010Out[0].getString(EKK0081A010CBSMsg1List.SHOSA_YMD);
						
						workDataMap.put("sj_svc_kei_no", (String)svcMap.get("svc_kei_no"));
						workDataMap.put("sj_svc_cd", (String)svcMap.get("svc_cd_KK0081"));
						workDataMap.put("sj_prc_grp_cd", (String)svcMap.get("prc_grp_cd_KK0081"));
						workDataMap.put("sj_pcrs_cd", (String)svcMap.get("pcrs_cd_KK0081"));
						workDataMap.put("sj_pplan_cd", pplanCd);
						workDataMap.put("sj_shosa_ymd", shosaYmd);
						
						// A回線契約にかかるサービス契約番号とSYSIDとの紐付け情報
						addSjishoSvckeiNoSysIdInf(handle, param, scCall, result, fixedText, dataMap, paramMap, svcMap, shosaYmd);
						
						// F回線契約に紐づく各種サービス契約の情報
						addSjishoSvckeiInf(handle, param, scCall, fixedText, svcMap, workDataMap);
					}
					else if (isSjishoAdd(handle, param, svcMap))
					//ST-2014-0000171 MOD END
					{
						String pplanCd = ekk0081a010Out[0].getString(EKK0081A010CBSMsg1List.PPLAN_CD);
						String shosaYmd = ekk0081a010Out[0].getString(EKK0081A010CBSMsg1List.SHOSA_YMD);
						
						workDataMap.put("sj_svc_kei_no", (String)svcMap.get("svc_kei_no"));
						workDataMap.put("sj_svc_cd", (String)svcMap.get("svc_cd_KK0081"));
						workDataMap.put("sj_prc_grp_cd", (String)svcMap.get("prc_grp_cd_KK0081"));
						workDataMap.put("sj_pcrs_cd", (String)svcMap.get("pcrs_cd_KK0081"));
						workDataMap.put("sj_pplan_cd", pplanCd);
						workDataMap.put("sj_shosa_ymd", shosaYmd);
						
						// A回線契約にかかるサービス契約番号とSYSIDとの紐付け情報
						addSjishoSvckeiNoSysIdInf(handle, param, scCall, result, fixedText, dataMap, paramMap, svcMap, shosaYmd);
						
						// F回線契約に紐づく各種サービス契約の情報
						addSjishoSvckeiInf(handle, param, scCall, fixedText, svcMap, workDataMap);
						
						// E請求契約番号（#T）の情報
						// →JKKKeiHimoSeikyKakinsUpdCCで登録
					}
/* ++++++++++ v4.00.01 修正終了 ++++++++++ */
				}
/* ++++++++++ v4.00.00 修正終了 ++++++++++ */
			}
		}
		
		return param;
	}
	
	/**
	 * チェック処理です。<br>
	 * <br>
	 * 
	 * @param handle
	 * @param param
	 * @param fixedText
	 * @return HashMap<String, Object>
	 * @throws RequestParameterException
	 */
	@SuppressWarnings("unchecked")
	public HashMap getInvokeCBS(SessionHandle handle, IRequestParameterReadWrite param, String fixedText)
			throws RequestParameterException
	{
		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		
		List<CAANMsg> templates = new ArrayList<CAANMsg>();
		
		// チェック用サービスインターフェイス
		paramMap.put(JCMConstants.TEMPLATE_LIST_KEY, Arrays.asList(templates));
		
		return paramMap;
	}
	
/* ++++++++++ v4.00.00 修正開始 ++++++++++ */
	/**
	 * 指示書の登録処理を行います。
	 * A回線契約にかかるサービス契約番号とSYSIDとの紐付け情報
	 * 
	 * @param handle
	 * @param param
	 * @param scCall
	 * @param result
	 * @param fixedText
	 * @param dataMap
	 * @param paramMap
	 * @param svcMap
	 * @param shosaYmd
	 * @return IRequestParameterReadWrite
	 * @throws Exception
	 */
	private IRequestParameterReadWrite addSjishoSvckeiNoSysIdInf(
																	SessionHandle handle, 
																	IRequestParameterReadWrite param, 
																	ServiceComponentRequestInvoker scCall, 
																	Map<?, ?> result, 
																	String fixedText, 
																	HashMap<String, Object> dataMap, 
																	HashMap<String, Object> paramMap, 
																	HashMap<String, String> svcMap, 
																	String shosaYmd) throws Exception
	{
		// 指示書登録（併合元紐付情報）
		// ◇ 上りマッピング処理
		paramMap = editInMsg_mtHimotsuki(param, dataMap, svcMap, shosaYmd);
		
		// ◇ SC呼出実行
		result = scCall.run(paramMap, handle);
		
		// ◇ 下りマッピング処理
		editOutMsg_Himotsuki(result, param, fixedText);
		
		// 指示書登録（併合先紐付情報）
		// ◇ 上りマッピング処理
		paramMap = editInMsg_skHimotsuki(param, dataMap, svcMap);
		
		// ◇ SC呼出実行
		result = scCall.run(paramMap, handle);
		
		// ◇ 下りマッピング処理
		editOutMsg_Himotsuki(result, param, fixedText);
		
		return param;
	}
	
	/**
	 * 指示書の登録処理を行います。
	 * F回線契約に紐づく各種サービス契約の情報
	 * 
	 * @param handle
	 * @param param
	 * @param fixedText
	 * @return IRequestParameterReadWrite
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	private IRequestParameterReadWrite addSjishoSvckeiInf(
															SessionHandle handle, 
															IRequestParameterReadWrite param, 
															ServiceComponentRequestInvoker scCall, 
															String fixedText, 
															HashMap<String, String> svcMap, 
															HashMap workDataMap) throws Throwable, Exception
	{
		JCKKisnKeiHmdkShijiAddCC sjishoAddCC = new JCKKisnKeiHmdkShijiAddCC();
		sjishoAddCC.execMakeSjisho(handle, param, FIXED_KEY_KEI_HMDK_SJISHO_ADD_CC);
		
		return param;
	}
	
/* ++++++++++ v4.00.00 修正終了 ++++++++++ */
	
	/**
	 * 指示書登録（併合元紐付情報）用のメッセージを作成します。
	 * 
	 * @param param
	 * @param inMap
	 * @param svcMap
	 * @param shosaYmd
	 * @return HashMap<String, Object>
	 * @throws RequestParameterException
	 */
	@SuppressWarnings("unchecked")
	private HashMap<String, Object> editInMsg_mtHimotsuki(IRequestParameterReadWrite param,
															HashMap<String, Object> inMap,
															HashMap<String, String> svcMap,
															String shosaYmd) throws RequestParameterException
	{
		// 共通部の設定
		HashMap<String, Object> paramMap = editInMsg(param);
		
		CAANMsg template = new CAANMsg(ECK0151D010CBSMsg.class.getName());
		
		// テンプレートID
		template.set(ECK0151D010CBSMsg.TEMPLATEID, TEMPLATE_ID_ECK0151D010);
		// 機能コード
		template.set(ECK0151D010CBSMsg.FUNC_CODE, "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);
		
		// 作業領域の取得
		Map workMap = (Map)param.getMappingWorkArea();
		// 作業項目マップ
		HashMap workDataMap = (HashMap)workMap.get("WORK");
		
		// ◇ 業務データの設定
		setParam(template, inMap, ECK0151D010CBSMsg.TRN_CD, "trn_cd");							// 処理コード
		setParam(template, inMap, ECK0151D010CBSMsg.TRGT_TABLE_ID, "trgt_table_id");			// 対象テーブルID
		setParam(template, inMap, ECK0151D010CBSMsg.TRAN_TRGT_SYSID, "mt_sysid");				// 処理対象SYSID
		setParam(template, inMap, ECK0151D010CBSMsg.RSLT_FLG, "rslt_flg");						// 結果フラグ
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_YK_CNT, "pram_yk_cnt");			// パラメータ有効数
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_1, "mt_sysid");					// パラメータ1
		setParam(template, svcMap, ECK0151D010CBSMsg.PARAMETER_2, "svc_kei_no");				// パラメータ2
		template.set(ECK0151D010CBSMsg.PARAMETER_3, shosaYmd);									// パラメータ3
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_4, "mt_param4_tendymd");			// パラメータ4
		setParam(template, svcMap, ECK0151D010CBSMsg.PARAMETER_5, "mk_flg_KK0081");				// パラメータ5
/* ++++++++++ v4.00.00 追加開始 ++++++++++ */
		template.set(ECK0151D010CBSMsg.PARAMETER_6, (String)workDataMap.get("sj_add_dtm"));		// パラメータ6
		template.set(ECK0151D010CBSMsg.PARAMETER_7, (String)workDataMap.get("sj_add_opeacnt"));	// パラメータ7
		template.setNull(ECK0151D010CBSMsg.PARAMETER_8);										// パラメータ8
		template.set(ECK0151D010CBSMsg.PARAMETER_9, (String)workDataMap.get("sj_upd_dtm"));		// パラメータ9
		template.set(ECK0151D010CBSMsg.PARAMETER_10, (String)workDataMap.get("sj_upd_opeacnt"));// パラメータ10
		template.setNull(ECK0151D010CBSMsg.PARAMETER_11);										// パラメータ11
/* ++++++++++ v4.00.00 追加終了 ++++++++++ */
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_12, "param12_kei_sbt_cd");		// パラメータ12
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_13, "param13_svc_cd");			// パラメータ13
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		paramMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		
		return paramMap;
	}
	
	/**
	 * 指示書登録（併合先紐付情報）用のメッセージを作成します。
	 * 
	 * @param param
	 * @param inMap
	 * @return HashMap<String, Object>
	 * @throws RequestParameterException
	 */
	@SuppressWarnings("unchecked")
	private HashMap<String, Object> editInMsg_skHimotsuki(IRequestParameterReadWrite param,
															HashMap<String, Object> inMap,
															HashMap<String, String> svcMap) throws RequestParameterException
	{
		// 共通部の設定
		HashMap<String, Object> paramMap = editInMsg(param);
		
		CAANMsg template = new CAANMsg(ECK0151D010CBSMsg.class.getName());
		
		// テンプレートID
		template.set(ECK0151D010CBSMsg.TEMPLATEID, TEMPLATE_ID_ECK0151D010);
		// 機能コード
		template.set(ECK0151D010CBSMsg.FUNC_CODE, "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);
		
		// 作業領域の取得
		Map workMap = (Map)param.getMappingWorkArea();
		// 作業項目マップ
		HashMap workDataMap = (HashMap)workMap.get("WORK");
		
		// ◇ 業務データの設定
		setParam(template, inMap, ECK0151D010CBSMsg.TRN_CD, "trn_cd");							// 処理コード
		setParam(template, inMap, ECK0151D010CBSMsg.TRGT_TABLE_ID, "trgt_table_id");			// 対象テーブルID
		setParam(template, inMap, ECK0151D010CBSMsg.TRAN_TRGT_SYSID, "sk_sysid");				// 処理対象SYSID
		setParam(template, inMap, ECK0151D010CBSMsg.RSLT_FLG, "rslt_flg");						// 結果フラグ
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_YK_CNT, "pram_yk_cnt");			// パラメータ有効数
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_1, "sk_sysid");					// パラメータ1
		setParam(template, svcMap, ECK0151D010CBSMsg.PARAMETER_2, "svc_kei_no");				// パラメータ2
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_3, "sk_param3_tstaymd");			// パラメータ3
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_4, "sk_param4_tendymd");			// パラメータ4
		setParam(template, svcMap, ECK0151D010CBSMsg.PARAMETER_5, "mk_flg_KK0081");				// パラメータ5
/* ++++++++++ v4.00.00 追加開始 ++++++++++ */
		template.set(ECK0151D010CBSMsg.PARAMETER_6, (String)workDataMap.get("sj_add_dtm"));		// パラメータ6
		template.set(ECK0151D010CBSMsg.PARAMETER_7, (String)workDataMap.get("sj_add_opeacnt"));	// パラメータ7
		template.setNull(ECK0151D010CBSMsg.PARAMETER_8);										// パラメータ8
		template.set(ECK0151D010CBSMsg.PARAMETER_9, (String)workDataMap.get("sj_upd_dtm"));		// パラメータ9
		template.set(ECK0151D010CBSMsg.PARAMETER_10, (String)workDataMap.get("sj_upd_opeacnt"));// パラメータ10
		template.setNull(ECK0151D010CBSMsg.PARAMETER_11);										// パラメータ11
/* ++++++++++ v4.00.00 追加終了 ++++++++++ */
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_12, "param12_kei_sbt_cd");		// パラメータ12
		setParam(template, inMap, ECK0151D010CBSMsg.PARAMETER_13, "param13_svc_cd");			// パラメータ13
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		paramMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		
		return paramMap;
	}
	
	/**
	 * 共通部のメッセージを作成します。
	 * 
	 * @param param
	 * @return HashMap<String, Object>
	 * @throws RequestParameterException
	 */
	private HashMap<String, Object> editInMsg(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;
	}
	
	/**
	 * 
	 * @param msgList
	 * @param param
	 * @param fixedText
	 * 
	 * @return IRequestParameterReadWrite
	 * 
	 * @throws RequestParameterException
	 */
	@SuppressWarnings("unchecked")
	private IRequestParameterReadWrite editOutMsg_Himotsuki(Map<?, ?> msgList,
																IRequestParameterReadWrite param,
																String fixedText) throws Exception
	{
		// SCからの戻り値からCAANMsgを取得する
		CAANMsg[] templates = (CAANMsg[])msgList.get(JCMConstants.TEMPLATE_LIST_KEY);
		
		/* ◇処理結果の判定*/
		// 取得したリターンコード、ステータスの内容を見て異常かどうかの判断をする。
		// リターンコード取得
		String rtnCode = msgList.get(JCMConstants.RET_CD_INT_KEY).toString();
		Integer status = templates[0].getInt(JCMConstants.STATUS_INT_KEY);
		
		// エラー情報の設定
		IRequestParameterReadWrite retParam = this.editErrorInfo_Himotsuki(param, templates, Integer.parseInt(rtnCode), fixedText);
		
		//エラー情報のマップを取得
		ArrayList<Object> errList = (ArrayList<Object>)retParam.getControlMapData(SCControlMapKeys.ERROR_INFO);
		if (errList == null)
		{
			errList = new ArrayList<Object>();
		}
		
		// コントロールマップに設定
		retParam.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(msgList, errList));
		
		// 異常の場合、SCCallExceptionを生成してスローする
		if(!("0".equals(rtnCode) && 0 == status)){
			SCCallException scCallEx = new SCCallException("戻り値不正", rtnCode, status);
			throw scCallEx;
		}
		
		return retParam;
	}
	
	/**
	 * SC(サービスインターフェイス）を呼び出す。
	 * 
	 * @param handle
	 * @param scCall
	 * @param param
	 * @param fixedText
	 * @param mappingData
	 * @return CAANMsg
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	private CAANMsg callSC(SessionHandle handle,
							ServiceComponentRequestInvoker scCall,
							IRequestParameterReadWrite param,
							String fixedText,
							Object[][] mappingData) throws Exception
	{
		HashMap<String, Object> paramMap = editInMsg(param, mappingData);
		
		Map<?, ?> result = scCall.run(paramMap, handle);
		
		CAANMsg[] templates = (CAANMsg[])result.get(JCMConstants.TEMPLATE_LIST_KEY);
		CAANMsg msg = templates[0];
		
		// リターンコード取得
		int returnCode = (Integer)result.get(JCMConstants.RET_CD_INT_KEY);
		
		int templateStatus = msg.getInt(EKK0081B006CBSMsg.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);
		}
		
		setErrorInf(msg, (HashMap<String, Object>)param.getData(fixedText));
		
		//エラー情報のマップを取得
		ArrayList<Object> errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO);
		if (errList == null)
		{
			errList = new ArrayList<Object>();
		}
		
		// コントロールマップに設定
		param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(result, errList));
		
		/* ◇処理結果の判定*/
		// 取得したリターンコード、ステータスの内容を見て異常かどうかの判断をする。
		String rtnCode = result.get(JCMConstants.RET_CD_INT_KEY).toString();
		Integer status = msg.getInt(JCMConstants.STATUS_INT_KEY);
		
		// 異常の場合、SCCallExceptionを生成してスローする
		if(!("0".equals(rtnCode) && 0 == status.intValue())){
			
			/* ++++++++++ v4.02.00 追加開始 ++++++++++ */
			if(!("0".equals(rtnCode) && 4 == status.intValue())){
			/* ++++++++++ v4.02.00 追加終了 ++++++++++ */
				SCCallException scCallEx = new SCCallException("戻り値不正", rtnCode, status);
				throw scCallEx;
			/* ++++++++++ v4.02.00 追加開始 ++++++++++ */
			}
			/* ++++++++++ v4.02.00 追加終了 ++++++++++ */
		}
		
		return msg;
	}
	
	/**
	 * @param param
	 * @param mappingData
	 * @return HashMap<String, Object>
	 * @throws RequestParameterException
	 */
	private HashMap<String, Object> editInMsg(IRequestParameterReadWrite param,
												Object[][] mappingData) throws RequestParameterException
	{
		HashMap<String, Object> paramMap = editInMsg(param);
		
		String svcIf = (String)mappingData[0][1];
		
		CAANMsg template = new CAANMsg(String.format("eo.ejb.cbs.cbsmsg.%sCBSMsg", svcIf));
		
		// オペレータID
		template.set(JCMConstants.OPERATOR_ID_KEY, param.getControlMapData(SCControlMapKeys.OPERATOR_ID));
		// 運用日付
		template.set(JCMConstants.OPERATE_DATE_KEY, param.getControlMapData(SCControlMapKeys.OPE_DATE));
		// 運用日時
		template.set(JCMConstants.OPERATE_DATETIME_KEY, param.getControlMapData(SCControlMapKeys.OPE_TIME));
		
		for (int i = 0; i < mappingData.length; i++)
		{
			if ("".equals(mappingData[i][1]))
			{
				template.setNull((String)mappingData[i][0]);
			}
			else
			{
				template.set((String)mappingData[i][0], mappingData[i][1]);
			}
		}
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		paramMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		return paramMap;
	}
	
	/**
	 * エラー情報を設定します。
	 * 
	 * @param msg
	 * @param map
	 * 
	 */
	@SuppressWarnings("unchecked")
	private void setErrorInf(CAANMsg msg, HashMap<String, Object> map)
	{
		Iterator<String> msgKey = msg.getSchema().getSchemaKeySet().iterator();
		
		while (msgKey.hasNext())
		{
			String key = msgKey.next();
			
			if (key.endsWith("_err"))
			{
				if (!msg.isNull(key))
				{
					if (!map.containsKey(key))
					{
						map.put(key, msg.getString(key));
					}
				}
			}
		}
	}
	
	/**
	 * 
	 * @param param
	 * @param templates
	 * @param returnCode
	 * @param fixedText
	 * @return IRequestParameterReadWrite
	 * @throws RequestParameterException
	 */
	@SuppressWarnings("unchecked")
	private IRequestParameterReadWrite editErrorInfo_Himotsuki(IRequestParameterReadWrite param, 
														CAANMsg[] templates,
														int returnCode,
														String fixedText) throws RequestParameterException
	{
		CAANMsg template = templates[0];
		
		int templateStatus = template.getInt(ECK0151D010CBSMsg.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, String> inMap = (HashMap<String, String>)param.getData(fixedText);
		
		// エラー情報の設定
		setErr(template, inMap, ECK0151D010CBSMsg.TRN_CD_ERR, "tran_cd_err");						// 処理コード
		setErr(template, inMap, ECK0151D010CBSMsg.TRGT_TABLE_ID_ERR, "trgt_table_id_err");			// 対象テーブルID
		setErr(template, inMap, ECK0151D010CBSMsg.RSLT_FLG_ERR, "rslt_flg_err");					// 結果フラグ
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_YK_CNT_ERR, "parameter_yk_cnt_err");	// パラメータ有効数
		setErr(template, inMap, ECK0151D010CBSMsg.TRAN_TRGT_SYSID_ERR, "tran_trgt_sysid_err");		// 処理対象SYSID
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_1_ERR, "mt_sysid_err");					// パラメータ1
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_2_ERR, "svc_kei_no_err");				// パラメータ2
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_3_ERR, "svc_sta_ymd_KK0081_err");		// パラメータ3
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_4_ERR, "svc_endymd_KK0081_err");		// パラメータ4
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_5_ERR, "mk_flg_KK0081_err");			// パラメータ5
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_6_ERR, "add_dtm_KK0081_err");			// パラメータ6
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_7_ERR, "add_opeacnt_KK0081_err");		// パラメータ7
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_9_ERR, "upd_dtm_KK0081_err");			// パラメータ9
		setErr(template, inMap, ECK0151D010CBSMsg.PARAMETER_10_ERR, "upd_opeacnt_KK0081_err");		// パラメータ10
		
		return param;
	}
	
	/**
	 * パラメータを設定します。
	 * @param template
	 * @param map
	 * @param item
	 * @param key
	 * @return 判定結果
	 */
	@SuppressWarnings("unchecked")
	private void setParam(CAANMsg template, HashMap map, String item, String key)
	{
		String value = null;
		
		if(isNull(map))
		{
			template.setNull(item);
		}
		else
		{
			value = (String)map.get(key);
			if(isEmpty(value))
			{
				template.setNull(item);
			}
			else
			{
				template.set(item, value);
			}
		}
	}
	
	/**
	 * エラー情報を設定します。
	 * @param template
	 * @param map
	 * @param item
	 * @param key
	 * @return 判定結果
	 */
	private void setErr(CAANMsg template, HashMap<String, String> inMap, String item, String key) {
		
		if (!template.isNull(item))
		{
			if (!inMap.containsKey(key))
			{
				inMap.put(key, template.getString(item));
			}
		}
	}
	
/* ++++++++++ v4.00.01 追加開始 ++++++++++ */
	/**
	 * 指示書登録実行判定を行います。
	 * @param handle
	 * @param param
	 * @param svcMap
	 * @return 判定結果
	 */
	@SuppressWarnings("unchecked")
	private boolean isSjishoAdd(SessionHandle handle, IRequestParameterReadWrite param, HashMap svcMap) throws Throwable
	{
		Map workMap = param.getMappingWorkArea();
		HashMap workDataMap = (HashMap)workMap.get("WORK");
		workDataMap.put("pcrs_cd", svcMap.get("pcrs_cd_KK0081"));
		param.setData(FIXED_KEY_JDG_EXEC_SJISHO_ADD_CC, new HashMap<String, Object>());
		
		JCKKJdgExecSjishoAddCC jdgExecSjishoAddCC = new JCKKJdgExecSjishoAddCC();
		jdgExecSjishoAddCC.execJdgSjishoAdd(handle, param, FIXED_KEY_JDG_EXEC_SJISHO_ADD_CC);
		HashMap<String, Object> outMap = (HashMap<String, Object>)param.getData(FIXED_KEY_JDG_EXEC_SJISHO_ADD_CC);
		
		return (Boolean)outMap.get("sjisho_add_flg");
	}
/* ++++++++++ v4.00.01 追加終了 ++++++++++ */
	
	/**
	 * 引数のNULL判定を行います。
	 * @param param
	 * @return 判定結果
	 */
	private boolean isNull(Object param)
	{
		if(param == null)
		{
			return true;
		}
		return false;
	}
	
	/**
	 * 引数の空文字判定を行います。
	 * @param param
	 * @return 判定結果
	 */
	private boolean isEmpty(String param)
	{
		if(param == null || "".equals(param))
		{
			return true;
		}
		return false;
	}
}
