/*******************************************************************************
* All Rights reserved,Copyright (c) K-Opticom
********************************************************************************
*＜プログラム内容＞
* システム名        ：eo顧客基幹システム
* モジュール名      ：JKKSendMailCC
* ソースファイル名  ：JKKSendMailCC.java
* 作成者            ：富士通
* 日付              ：2015年08月26日
*＜機能概要＞
* メール情報登録コモンコンポーネント部品
*＜修正履歴＞
* バージョン    修正日      修正者      修正内容
* ｖ18.00.00	2015/08/25	FJ)松本		【ANK-2631-00-00】ワンストップ案件（ＳＴＥＰ１）仕様変更
* ｖ74.00.00	2025/02/21	FJ)藤井		【ANK-4656-00-00】eo光シンプルプラン提供(STEP3)
*
********************************************************************************/
package com.fujitsu.futurity.bp.custom.common;

import java.util.ArrayList;
import java.util.HashMap;
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.common.constant.JPCModelConstant;
import eo.common.util.JCRUtilCommon;
import eo.ejb.cbs.cbsmsg.ECC0021D010CBSMsg;
import eo.ejb.cbs.cbsmsg.ECC0021D010CBSMsg1List;
import eo.ejb.cbs.cbsmsg.ECC0021D010CBSMsg2List;
import eo.ejb.cbs.cbsmsg.ECC0021D010CBSMsg3List;
import eo.ejb.cbs.cbsmsg.ECC0021D010CBSMsg4List;
import eo.ejb.cbs.cbsmsg.ECC0021D010CBSMsg5List;

public class JKKSendMailCC extends AbstractCommonComponent
{
	/**
	 * テンプレートID
	 */
	private static final String TEMPLATE_ID = "ECC0021D010";


	/** ユーザ任意文字列 */
	private String fixedTextGlobal = null;
	/**
	 * 対応記録明細登録（コール）チェック処理.<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 = editInMsg(param);
		
		return paramMap;
	}

	/**
	 * 対応記録明細登録（コール）処理.<br>
	 * 
	 * @param handle セッションハンドル
	 * @param param リクエストパラメータ
	 * @param fixedText サービスメッセージ
	 * @return リクエストパラメータ
	 * @throws Exception Exception
	 */
	public IRequestParameterReadWrite sendMailCC(SessionHandle handle, 
			IRequestParameterReadWrite param, String fixedText) throws Exception
	{

		/* ◇上りマッピング処理                         */
		// 上りマッピングの処理結果を取得するためのマップを生成
		// リクエストパラメータを引数に上りマッピング処理メソッドを実行
		this.fixedTextGlobal = fixedText;
		HashMap<String, Object> paramMap = editInMsg(param);
		
		/* ◇ＳＣ呼出実行 */
		// SC呼び出し部品のインスタンス生成（引数にはログに出力するクラス名を渡す。空文字を設定した場合はログに出力されない。
		ServiceComponentRequestInvoker scCall = new ServiceComponentRequestInvoker();
		Map<?, ?> resultKeyWord = scCall.run(paramMap, handle);
		
		/* ◇下りマッピング処理 */
		editOutMsg(resultKeyWord, param);

		return param;
	}
	
	/**
	 * サービスコンポーネント実行後に、IRequestParameterReadWriteにエラー情報をマッピングする
	 * @param param リクエストパラメータ
	 * @param templates テンプレート
	 * @param returnCode リターンコード
	 * @return IRequestParameterReadWrite
	 * @throws RequestParameterException RequestParameterException
	 */
	public IRequestParameterReadWrite editErrorInfo(IRequestParameterReadWrite param
			, CAANMsg[] templates, int returnCode) throws RequestParameterException
	{
		CAANMsg template = templates[0];
		CAANMsg[] templateArray = null;
		int templateStatus = template.getInt(ECC0021D010CBSMsg.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 inMap = null;
		ArrayList inList = null;
		
		// 作業項目領域
		Map workMap = param.getMappingWorkArea();
		if (workMap == null) {
			workMap = new HashMap();
			param.setMappingWorkArea(workMap);
		}
		
		/* ユーザデータ情報 */
		inMap = (HashMap)param.getData(this.fixedTextGlobal);
		if (inMap == null) {
			inMap = new HashMap();
			param.setData(this.fixedTextGlobal, inMap);
		}

		// メール送信情報登録マップ.メールコード → メールコード のエラー情報返却
		if (!template.isNull(ECC0021D010CBSMsg.MAIL_CD_ERR)) {
			if (!inMap.containsKey("mail_cd_err")) {
				inMap.put("mail_cd_err", template.getString(ECC0021D010CBSMsg.MAIL_CD_ERR));
			}
		}
		// メール送信情報登録マップ.送信予定年月日時分秒 → 送信予定年月日時分秒 のエラー情報返却
		if (!template.isNull(ECC0021D010CBSMsg.MAIL_SEND_RSV_DTM_ERR)) {
			if (!inMap.containsKey("mail_send_rsv_dtm_err")) {
				inMap.put("mail_send_rsv_dtm_err", template.getString(ECC0021D010CBSMsg.MAIL_SEND_RSV_DTM_ERR));
			}
		}
		// メール送信情報登録マップ.送信元メールアドレス → 送信元メールアドレス のエラー情報返却
		if (!template.isNull(ECC0021D010CBSMsg.SENDM_MLAD_ERR)) {
			if (!inMap.containsKey("sendm_mlad_err")) {
				inMap.put("sendm_mlad_err", template.getString(ECC0021D010CBSMsg.SENDM_MLAD_ERR));
			}
		}
		// メール送信情報登録マップ.送信元メールアドレス表示名 → 送信元メールアドレス表示名 のエラー情報返却
		if (!template.isNull(ECC0021D010CBSMsg.SENDM_MLAD_DSP_NM_ERR)) {
			if (!inMap.containsKey("sendm_mlad_dsp_nm_err")) {
				inMap.put("sendm_mlad_dsp_nm_err", template.getString(ECC0021D010CBSMsg.SENDM_MLAD_DSP_NM_ERR));
			}
		}
		// メール送信情報登録マップ.メール送信パターンコード → メール送信パターンコード のエラー情報返却
		if (!template.isNull(ECC0021D010CBSMsg.MAIL_SEND_PATTERN_CD_ERR)) {
			if (!inMap.containsKey("mail_send_pattern_cd_err")) {
				inMap.put("mail_send_pattern_cd_err", template.getString(ECC0021D010CBSMsg.MAIL_SEND_PATTERN_CD_ERR));
			}
		}
		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg1List");
		if (inList == null) {
			inList = new ArrayList();
			inMap.put("ECC0021D010CBSMsg1List", inList);
		}

		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG1LIST);

		if (templateArray != null) {
			for (int i = 0; i < templateArray.length; i++) {
				if (i >= inList.size()) {
					inList.add(new HashMap());
				}
			
				HashMap childMap = (HashMap)inList.get(i);
				CAANMsg childTemplate = templateArray[i];

				// メール送信情報登録マップ.送信先一覧明細.送信先メールアドレス → 送信先一覧明細.送信先メールアドレス のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg1List.MLAD_ERR)) {
					if (!childMap.containsKey("mlad_err")) {
						childMap.put("mlad_err", childTemplate.getString(ECC0021D010CBSMsg1List.MLAD_ERR));
					}
				}
				// メール送信情報登録マップ.送信先一覧明細.送信先メールアドレス表示名 → 送信先一覧明細.送信先メールアドレス表示名 のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg1List.MLAD_DSP_NM_ERR)) {
					if (!childMap.containsKey("mlad_dsp_nm_err")) {
						childMap.put("mlad_dsp_nm_err", childTemplate.getString(ECC0021D010CBSMsg1List.MLAD_DSP_NM_ERR));
					}
				}
				// メール送信情報登録マップ.送信先一覧明細.メールアドレス設定フィールドコード → 送信先一覧明細.メールアドレス設定フィールドコード のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg1List.MLAD_SET_FIELD_CD_ERR)) {
					if (!childMap.containsKey("mlad_set_field_cd_err")) {
						childMap.put("mlad_set_field_cd_err", childTemplate.getString(ECC0021D010CBSMsg1List.MLAD_SET_FIELD_CD_ERR));
					}
				}
			}
		}
		if (!template.isNull(ECC0021D010CBSMsg.ECC0021D010CBSMSG1LIST_ERR)) {
			if (!inMap.containsKey("ECC0021D010CBSMsg1List_err")) {
				inMap.put("ECC0021D010CBSMsg1List_err", template.getString(ECC0021D010CBSMsg.ECC0021D010CBSMSG1LIST_ERR));
			}
		}
		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg2List");
		if (inList == null) {
			inList = new ArrayList();
			inMap.put("ECC0021D010CBSMsg2List", inList);
		}

		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG2LIST);

		if (templateArray != null) {
			for (int i = 0; i < templateArray.length; i++) {
				if (i >= inList.size()) {
					inList.add(new HashMap());
				}
			
				HashMap childMap = (HashMap)inList.get(i);
				CAANMsg childTemplate = templateArray[i];

				// メール送信情報登録マップ.非定型文字列一覧明細.本文非定型置換文字 → 非定型文字列一覧明細.本文非定型置換文字 のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg2List.TEXT_HTK_CKAM_MOJI_ERR)) {
					if (!childMap.containsKey("text_htk_ckam_moji_err")) {
						childMap.put("text_htk_ckam_moji_err", childTemplate.getString(ECC0021D010CBSMsg2List.TEXT_HTK_CKAM_MOJI_ERR));
					}
				}
			}
		}
		if (!template.isNull(ECC0021D010CBSMsg.ECC0021D010CBSMSG2LIST_ERR)) {
			if (!inMap.containsKey("ECC0021D010CBSMsg2List_err")) {
				inMap.put("ECC0021D010CBSMsg2List_err", template.getString(ECC0021D010CBSMsg.ECC0021D010CBSMSG2LIST_ERR));
			}
		}
		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg3List");
		if (inList == null) {
			inList = new ArrayList();
			inMap.put("ECC0021D010CBSMsg3List", inList);
		}

		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG3LIST);

		if (templateArray != null) {
			for (int i = 0; i < templateArray.length; i++) {
				if (i >= inList.size()) {
					inList.add(new HashMap());
				}
			
				HashMap childMap = (HashMap)inList.get(i);
				CAANMsg childTemplate = templateArray[i];

				// メール送信情報登録マップ.電子ファイル一覧明細.電子ファイル管理番号 → 電子ファイル一覧明細.電子ファイル管理番号 のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg3List.EFILE_KANRI_NO_ERR)) {
					if (!childMap.containsKey("efile_kanri_no_err")) {
						childMap.put("efile_kanri_no_err", childTemplate.getString(ECC0021D010CBSMsg3List.EFILE_KANRI_NO_ERR));
					}
				}
				// メール送信情報登録マップ.電子ファイル一覧明細.ファイル名 → 電子ファイル一覧明細.ファイル名 のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg3List.FILE_NM_ERR)) {
					if (!childMap.containsKey("file_nm_err")) {
						childMap.put("file_nm_err", childTemplate.getString(ECC0021D010CBSMsg3List.FILE_NM_ERR));
					}
				}
			}
		}
		if (!template.isNull(ECC0021D010CBSMsg.ECC0021D010CBSMSG3LIST_ERR)) {
			if (!inMap.containsKey("ECC0021D010CBSMsg3List_err")) {
				inMap.put("ECC0021D010CBSMsg3List_err", template.getString(ECC0021D010CBSMsg.ECC0021D010CBSMSG3LIST_ERR));
			}
		}
		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg4List");
		if (inList == null) {
			inList = new ArrayList();
			inMap.put("ECC0021D010CBSMsg4List", inList);
		}

		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG4LIST);

		if (templateArray != null) {
			for (int i = 0; i < templateArray.length; i++) {
				if (i >= inList.size()) {
					inList.add(new HashMap());
				}
			
				HashMap childMap = (HashMap)inList.get(i);
				CAANMsg childTemplate = templateArray[i];

				// メール送信情報登録マップ.メール明細一覧明細.メール明細コード → メール明細一覧明細.メール明細コード のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg4List.MAIL_DTL_CD_ERR)) {
					if (!childMap.containsKey("mail_dtl_cd_err")) {
						childMap.put("mail_dtl_cd_err", childTemplate.getString(ECC0021D010CBSMsg4List.MAIL_DTL_CD_ERR));
					}
				}
				// メール送信情報登録マップ.メール明細一覧明細.明細本文非定型置換文字 → メール明細一覧明細.明細本文非定型置換文字 のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg4List.DTL_TEXT_HTK_CKAM_MOJI_ERR)) {
					if (!childMap.containsKey("dtl_text_htk_ckam_moji_err")) {
						childMap.put("dtl_text_htk_ckam_moji_err", childTemplate.getString(ECC0021D010CBSMsg4List.DTL_TEXT_HTK_CKAM_MOJI_ERR));
					}
				}
			}
		}
		if (!template.isNull(ECC0021D010CBSMsg.ECC0021D010CBSMSG4LIST_ERR)) {
			if (!inMap.containsKey("ECC0021D010CBSMsg4List_err")) {
				inMap.put("ECC0021D010CBSMsg4List_err", template.getString(ECC0021D010CBSMsg.ECC0021D010CBSMSG4LIST_ERR));
			}
		}
		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg5List");
		if (inList == null) {
			inList = new ArrayList();
			inMap.put("ECC0021D010CBSMsg5List", inList);
		}

		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG5LIST);

		if (templateArray != null) {
			for (int i = 0; i < templateArray.length; i++) {
				if (i >= inList.size()) {
					inList.add(new HashMap());
				}
			
				HashMap childMap = (HashMap)inList.get(i);
				CAANMsg childTemplate = templateArray[i];

				// メール送信情報登録マップ.メールヘッダー一覧明細.メールヘッダーキー → メールヘッダー一覧明細.メールヘッダーキー のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg5List.MAIL_HEADER_KEY_ERR)) {
					if (!childMap.containsKey("mail_header_key_err")) {
						childMap.put("mail_header_key_err", childTemplate.getString(ECC0021D010CBSMsg5List.MAIL_HEADER_KEY_ERR));
					}
				}
				// メール送信情報登録マップ.メールヘッダー一覧明細.メールヘッダー値 → メールヘッダー一覧明細.メールヘッダー値 のエラー情報返却
				if (!childTemplate.isNull(ECC0021D010CBSMsg5List.MAIL_HEADER_VALUE_ERR)) {
					if (!childMap.containsKey("mail_header_value_err")) {
						childMap.put("mail_header_value_err", childTemplate.getString(ECC0021D010CBSMsg5List.MAIL_HEADER_VALUE_ERR));
					}
				}
			}
		}
		if (!template.isNull(ECC0021D010CBSMsg.ECC0021D010CBSMSG5LIST_ERR)) {
			if (!inMap.containsKey("ECC0021D010CBSMsg5List_err")) {
				inMap.put("ECC0021D010CBSMsg5List_err", template.getString(ECC0021D010CBSMsg.ECC0021D010CBSMSG5LIST_ERR));
			}
		}

		return param;
	}

	/**
	 * メール送信情報登録処理用メッセージ設定処理.<br>
	 * @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>();

		/* SCインプット共通データ */
		// **********************************************
		// 【取得元：電文ヘッダ(ヘッダ)】
		// **********************************************
		// 電文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));

		CAANMsg template = new CAANMsg(ECC0021D010CBSMsg.class.getName());
		CAANMsg[] templateArray = null;

		ArrayList inList = null;

		// テンプレートID
		template.set(ECC0021D010CBSMsg.TEMPLATEID, TEMPLATE_ID);

		// 機能コード（デフォルト：１）
		template.set(ECC0021D010CBSMsg.FUNC_CODE, JPCModelConstant.FUNC_CD_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);

		/* ユーザデータ情報 */
		HashMap<String, Object> inMap = (HashMap<String, Object>)param.getData(this.fixedTextGlobal);

		if (inMap == null)
		{
			inMap = new HashMap<String, Object>();
			param.setData(this.fixedTextGlobal, inMap);
		}

		// ワーク領域の値を取得する。
		if (JPCModelConstant.FUNC_CD_1.equals(inMap.get(JCMConstants.FUNC_CODE_KEY)))
		{
			// ワーク領域の値を取得する。
			editWorkArea(param);
		}

		// 機能コード
		template.set(ECC0021D010CBSMsg.FUNC_CODE, inMap.get(JCMConstants.FUNC_CODE_KEY));

		editWorkArea(param);
		
		// メール送信情報登録マップ.メールコード → メールコード
		if (inMap == null || inMap.get("mail_cd") == null || "".equals(inMap.get("mail_cd"))) {
			template.setNull(ECC0021D010CBSMsg.MAIL_CD);
		} else {
			template.set(ECC0021D010CBSMsg.MAIL_CD, (String) inMap.get("mail_cd"));
		}

		// メール送信情報登録マップ.送信予定年月日時分秒 → 送信予定年月日時分秒
		if (inMap == null || inMap.get("mail_send_rsv_dtm") == null || "".equals(inMap.get("mail_send_rsv_dtm"))) {
		//	template.setNull(ECC0021D010CBSMsg.MAIL_SEND_RSV_DTM);
		} else {
			template.set(ECC0021D010CBSMsg.MAIL_SEND_RSV_DTM, (String) inMap.get("mail_send_rsv_dtm"));
		}

		// メール送信情報登録マップ.送信元メールアドレス → 送信元メールアドレス
		if (inMap == null || inMap.get("sendm_mlad") == null || "".equals(inMap.get("sendm_mlad"))) {
			template.setNull(ECC0021D010CBSMsg.SENDM_MLAD);
		} else {
			template.set(ECC0021D010CBSMsg.SENDM_MLAD, (String) inMap.get("sendm_mlad"));
		}

		// メール送信情報登録マップ.送信元メールアドレス表示名 → 送信元メールアドレス表示名
		if (inMap == null || inMap.get("sendm_mlad_dsp_nm") == null || "".equals(inMap.get("sendm_mlad_dsp_nm"))) {
			template.setNull(ECC0021D010CBSMsg.SENDM_MLAD_DSP_NM);
		} else {
			template.set(ECC0021D010CBSMsg.SENDM_MLAD_DSP_NM, (String) inMap.get("sendm_mlad_dsp_nm"));
		}

		// メール送信情報登録マップ.メール送信パターンコード → メール送信パターンコード
		if (inMap == null || inMap.get("mail_send_pattern_cd") == null || "".equals(inMap.get("mail_send_pattern_cd"))) {
			template.setNull(ECC0021D010CBSMsg.MAIL_SEND_PATTERN_CD);
		} else {
			template.set(ECC0021D010CBSMsg.MAIL_SEND_PATTERN_CD, (String) inMap.get("mail_send_pattern_cd"));
		}

		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg1List");
		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG1LIST);

		if (templateArray == null) {
			templateArray = new CAANMsg[inList.size()];
		}

		if (inList != null) {
			for (int i = 0; i < inList.size(); i++) {
				HashMap childMap = (HashMap)inList.get(i);

				CAANMsg childTemplate = templateArray[i];
				if (childTemplate == null) {
					childTemplate = new CAANMsg(ECC0021D010CBSMsg1List.class.getName());
				}
				// メール送信情報登録マップ.送信先一覧明細.送信先メールアドレス → 送信先一覧明細.送信先メールアドレス
				if (childMap == null || childMap.get("mlad") == null || "".equals(childMap.get("mlad"))) {
					childTemplate.setNull(ECC0021D010CBSMsg1List.MLAD);
				} else {
					childTemplate.set(ECC0021D010CBSMsg1List.MLAD, (String) childMap.get("mlad"));
				}

				// メール送信情報登録マップ.送信先一覧明細.送信先メールアドレス表示名 → 送信先一覧明細.送信先メールアドレス表示名
				if (childMap == null || childMap.get("mlad_dsp_nm") == null || "".equals(childMap.get("mlad_dsp_nm"))) {
					childTemplate.setNull(ECC0021D010CBSMsg1List.MLAD_DSP_NM);
				} else {
					childTemplate.set(ECC0021D010CBSMsg1List.MLAD_DSP_NM, (String) childMap.get("mlad_dsp_nm"));
				}

				// メール送信情報登録マップ.送信先一覧明細.メールアドレス設定フィールドコード → 送信先一覧明細.メールアドレス設定フィールドコード
				if (childMap == null || childMap.get("mlad_set_field_cd") == null || "".equals(childMap.get("mlad_set_field_cd"))) {
					childTemplate.setNull(ECC0021D010CBSMsg1List.MLAD_SET_FIELD_CD);
				} else {
					childTemplate.set(ECC0021D010CBSMsg1List.MLAD_SET_FIELD_CD, (String) childMap.get("mlad_set_field_cd"));
				}

				templateArray[i] = childTemplate;
			}
		}
		template.set(ECC0021D010CBSMsg.ECC0021D010CBSMSG1LIST, templateArray);

		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg2List");
		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG2LIST);

		if (templateArray == null) {
			templateArray = new CAANMsg[inList.size()];
		}

		if (inList != null) {
			for (int i = 0; i < inList.size(); i++) {
				HashMap childMap = (HashMap)inList.get(i);

				CAANMsg childTemplate = templateArray[i];
				if (childTemplate == null) {
					childTemplate = new CAANMsg(ECC0021D010CBSMsg2List.class.getName());
				}
				// メール送信情報登録マップ.非定型文字列一覧明細.本文非定型置換文字 → 非定型文字列一覧明細.本文非定型置換文字
				if (childMap == null || childMap.get("text_htk_ckam_moji") == null || "".equals(childMap.get("text_htk_ckam_moji"))) {
					childTemplate.setNull(ECC0021D010CBSMsg2List.TEXT_HTK_CKAM_MOJI);
				} else {
					childTemplate.set(ECC0021D010CBSMsg2List.TEXT_HTK_CKAM_MOJI, (String) childMap.get("text_htk_ckam_moji"));
				}

				templateArray[i] = childTemplate;
			}
		}
		template.set(ECC0021D010CBSMsg.ECC0021D010CBSMSG2LIST, templateArray);

		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg3List");
		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG3LIST);

		if (templateArray == null) {
			templateArray = new CAANMsg[inList.size()];
		}

		if (inList != null) {
			for (int i = 0; i < inList.size(); i++) {
				HashMap childMap = (HashMap)inList.get(i);

				CAANMsg childTemplate = templateArray[i];
				if (childTemplate == null) {
					childTemplate = new CAANMsg(ECC0021D010CBSMsg3List.class.getName());
				}
				// メール送信情報登録マップ.電子ファイル一覧明細.電子ファイル管理番号 → 電子ファイル一覧明細.電子ファイル管理番号
				if (childMap == null || childMap.get("efile_kanri_no") == null || "".equals(childMap.get("efile_kanri_no"))) {
					childTemplate.setNull(ECC0021D010CBSMsg3List.EFILE_KANRI_NO);
				} else {
					childTemplate.set(ECC0021D010CBSMsg3List.EFILE_KANRI_NO, (String) childMap.get("efile_kanri_no"));
				}

				// メール送信情報登録マップ.電子ファイル一覧明細.ファイル名 → 電子ファイル一覧明細.ファイル名
				if (childMap == null || childMap.get("file_nm") == null || "".equals(childMap.get("file_nm"))) {
					childTemplate.setNull(ECC0021D010CBSMsg3List.FILE_NM);
				} else {
					childTemplate.set(ECC0021D010CBSMsg3List.FILE_NM, (String) childMap.get("file_nm"));
				}

				templateArray[i] = childTemplate;
			}
		}
		template.set(ECC0021D010CBSMsg.ECC0021D010CBSMSG3LIST, templateArray);

		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg4List");
		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG4LIST);

		if (templateArray == null) {
			templateArray = new CAANMsg[inList.size()];
		}

		if (inList != null) {
			for (int i = 0; i < inList.size(); i++) {
				HashMap childMap = (HashMap)inList.get(i);

				CAANMsg childTemplate = templateArray[i];
				if (childTemplate == null) {
					childTemplate = new CAANMsg(ECC0021D010CBSMsg4List.class.getName());
				}
				// メール送信情報登録マップ.メール明細一覧明細.メール明細コード → メール明細一覧明細.メール明細コード
				if (childMap == null || childMap.get("mail_dtl_cd") == null || "".equals(childMap.get("mail_dtl_cd"))) {
					childTemplate.setNull(ECC0021D010CBSMsg4List.MAIL_DTL_CD);
				} else {
					childTemplate.set(ECC0021D010CBSMsg4List.MAIL_DTL_CD, (String) childMap.get("mail_dtl_cd"));
				}

				// メール送信情報登録マップ.メール明細一覧明細.明細本文非定型置換文字 → メール明細一覧明細.明細本文非定型置換文字
				if (childMap == null || childMap.get("dtl_text_htk_ckam_moji") == null || "".equals(childMap.get("dtl_text_htk_ckam_moji"))) {
					childTemplate.setNull(ECC0021D010CBSMsg4List.DTL_TEXT_HTK_CKAM_MOJI);
				} else {
					childTemplate.set(ECC0021D010CBSMsg4List.DTL_TEXT_HTK_CKAM_MOJI, (String) childMap.get("dtl_text_htk_ckam_moji"));
				}

				templateArray[i] = childTemplate;
			}
		}
		template.set(ECC0021D010CBSMsg.ECC0021D010CBSMSG4LIST, templateArray);

		inList = (ArrayList)inMap.get("ECC0021D010CBSMsg5List");
		templateArray = template.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG5LIST);

		if (templateArray == null) {
			templateArray = new CAANMsg[inList.size()];
		}

		if (inList != null) {
			for (int i = 0; i < inList.size(); i++) {
				HashMap childMap = (HashMap)inList.get(i);

				CAANMsg childTemplate = templateArray[i];
				if (childTemplate == null) {
					childTemplate = new CAANMsg(ECC0021D010CBSMsg5List.class.getName());
				}
				// メール送信情報登録マップ.メールヘッダー一覧明細.メールヘッダーキー → メールヘッダー一覧明細.メールヘッダーキー
				if (childMap == null || childMap.get("mail_header_key") == null || "".equals(childMap.get("mail_header_key"))) {
					childTemplate.setNull(ECC0021D010CBSMsg5List.MAIL_HEADER_KEY);
				} else {
					childTemplate.set(ECC0021D010CBSMsg5List.MAIL_HEADER_KEY, (String) childMap.get("mail_header_key"));
				}

				// メール送信情報登録マップ.メールヘッダー一覧明細.メールヘッダー値 → メールヘッダー一覧明細.メールヘッダー値
				if (childMap == null || childMap.get("mail_header_value") == null || "".equals(childMap.get("mail_header_value"))) {
					childTemplate.setNull(ECC0021D010CBSMsg5List.MAIL_HEADER_VALUE);
				} else {
					childTemplate.set(ECC0021D010CBSMsg5List.MAIL_HEADER_VALUE, (String) childMap.get("mail_header_value"));
				}

				templateArray[i] = childTemplate;
			}
		}
		template.set(ECC0021D010CBSMsg.ECC0021D010CBSMSG5LIST, templateArray);
			

		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		paramMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);

		return paramMap;
	}


	/**
	 * メール送信情報登録処理用メッセージ取得処理.<br>
	 * 
	 * @param msgList メッセージリスト
	 * @param param リクエストパラメータ
	 * @return IRequestParameterReadWrite
	 * @throws Exception
	 */
	/**
	 * @param msgList
	 * @param param
	 * @return
	 * @throws Exception
	 */
	private IRequestParameterReadWrite editOutMsg(Map<?, ?> msgList,
			IRequestParameterReadWrite param) throws Exception
	{

		// SCからの戻り値からCAANMsgを取得する。
		CAANMsg[] templates = (CAANMsg[]) msgList.get(JCMConstants.TEMPLATE_LIST_KEY);
		CAANMsg parentTemplate = templates[0];
		CAANMsg[] templateArray = null;

		// リターンコード取得
		Object return_code = msgList.get(JCMConstants.RET_CD_INT_KEY);
		
		// 結果を詰めるマップを取得。
		HashMap dataMap = null;
		ArrayList dataList = null;

		/* 業務データ設定 */
		dataMap = (HashMap)param.getData(this.fixedTextGlobal);
		if (dataMap == null) {
			dataMap = new HashMap();
			param.setData(this.fixedTextGlobal, dataMap);
		}

		// 作業項目領域
		Map<Object, Object> workAreaMap = param.getMappingWorkArea();
		if (workAreaMap == null)
		{
			workAreaMap = new HashMap<Object, Object>();
			param.setMappingWorkArea(workAreaMap);
		}
		
		/* 作業項目情報 */
		Map<String, Object> workMap = (HashMap<String, Object>)workAreaMap.get("WORK");
		if (workMap == null)
		{
			workMap = new HashMap<String, Object>();
			workAreaMap.put("WORK", workMap);
		}

		// メール送信情報登録マップ.メール送信番号 ← メール送信番号
		if (parentTemplate.isNull(ECC0021D010CBSMsg.MAIL_SEND_NO)) {
			dataMap.put("mail_send_no", new String());
			workMap.put("mail_send_no_w", new String());
		} else {
			dataMap.put("mail_send_no", parentTemplate.getString(ECC0021D010CBSMsg.MAIL_SEND_NO));
			workMap.put("mail_send_no_w", parentTemplate.getString(ECC0021D010CBSMsg.MAIL_SEND_NO));
		}

		// メール送信情報登録マップ.メール送信ステータス ← メール送信ステータス
		if (parentTemplate.isNull(ECC0021D010CBSMsg.MAIL_SEND_STAT)) {
			dataMap.put("mail_send_stat", new String());
		} else {
			dataMap.put("mail_send_stat", parentTemplate.getString(ECC0021D010CBSMsg.MAIL_SEND_STAT));
		}

		// メール送信情報登録マップ.メール送信エラーフラグ ← メール送信エラーフラグ
		if (parentTemplate.isNull(ECC0021D010CBSMsg.MAIL_SEND_ERR_FLG)) {
			dataMap.put("mail_send_err_flg", new String());
		} else {
			dataMap.put("mail_send_err_flg", parentTemplate.getString(ECC0021D010CBSMsg.MAIL_SEND_ERR_FLG));
		}
		
		// ANK-4656-00-00 ADD START
		// メール送信情報登録マップ.メールタイトル ← メールタイトル
		if (parentTemplate.isNull(ECC0021D010CBSMsg.MAIL_TITLE)) {
			dataMap.put("mail_title", new String());
		} else {
			dataMap.put("mail_title", parentTemplate.getString(ECC0021D010CBSMsg.MAIL_TITLE));
		}
		
		// メール送信情報登録マップ.メール本文 ← メール本文
		if (parentTemplate.isNull(ECC0021D010CBSMsg.MAIL_TEXT)) {
			dataMap.put("mail_text", new String());
		} else {
			dataMap.put("mail_text", parentTemplate.getString(ECC0021D010CBSMsg.MAIL_TEXT));
		}
		// ANK-4656-00-00 ADD END

		// メール送信情報登録マップ.登録年月日時分秒 ← 登録年月日時分秒
		if (parentTemplate.isNull(ECC0021D010CBSMsg.ADD_DTM)) {
			dataMap.put("add_dtm", new String());
		} else {
			dataMap.put("add_dtm", parentTemplate.getString(ECC0021D010CBSMsg.ADD_DTM));
		}

		// メール送信情報登録マップ.登録オペレータアカウント ← 登録オペレータアカウント
		if (parentTemplate.isNull(ECC0021D010CBSMsg.ADD_OPEACNT)) {
			dataMap.put("add_opeacnt", new String());
		} else {
			dataMap.put("add_opeacnt", parentTemplate.getString(ECC0021D010CBSMsg.ADD_OPEACNT));
		}

		templateArray = parentTemplate.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG1LIST);
		dataList = (ArrayList)dataMap.get("ECC0021D010CBSMsg1List");
		  
		if (dataList == null) {
			dataList = new ArrayList();
		}

		if (templateArray != null) {
			for (int i = 0; i < templateArray.length; i++) {
				CAANMsg childTemplate = templateArray[i];
				if ( i >= dataList.size()) {
					dataList.add(new HashMap());
				}
				HashMap childMap = (HashMap)dataList.get(i);

				
				// メール送信情報登録マップ.送信先一覧明細.メールアドレス番号 ← 送信先一覧明細.メールアドレス番号
				if (childTemplate.isNull(ECC0021D010CBSMsg1List.MLAD_NO)) {
					childMap.put("mlad_no", new String());
				} else {
					childMap.put("mlad_no", childTemplate.getString(ECC0021D010CBSMsg1List.MLAD_NO));
				}
			}
		}
		dataMap.put("ECC0021D010CBSMsg1List", dataList);

		templateArray = parentTemplate.getCAANMsgList(ECC0021D010CBSMsg.ECC0021D010CBSMSG3LIST);
		dataList = (ArrayList)dataMap.get("ECC0021D010CBSMsg3List");
		  
		if (dataList == null) {
			dataList = new ArrayList();
		}

		if (templateArray != null) {
			for (int i = 0; i < templateArray.length; i++) {
				CAANMsg childTemplate = templateArray[i];
				if ( i >= dataList.size()) {
					dataList.add(new HashMap());
				}
				HashMap childMap = (HashMap)dataList.get(i);

				
				// メール送信情報登録マップ.電子ファイル一覧明細.添付ファイル番号 ← 電子ファイル一覧明細.添付ファイル番号
				if (childTemplate.isNull(ECC0021D010CBSMsg3List.TEMP_FILE_NO)) {
					childMap.put("temp_file_no", new String());
				} else {
					childMap.put("temp_file_no", childTemplate.getString(ECC0021D010CBSMsg3List.TEMP_FILE_NO));
				}
			}
		}
		dataMap.put("ECC0021D010CBSMsg3List", dataList);

        
		// エラー情報の設定
		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);
		
//		// 異常の場合、SCCallExceptionを生成してスローする
//		if(!("0".equals(rtnCode) && 0 == Integer.parseInt(status))) 
//		{
//			SCCallException scCallEx = new SCCallException("INVALID_RETURN_MESSAGE", rtnCode, Integer.parseInt(status));
//			throw scCallEx;
//		}
//
//		if ("1".equals(dataMap.get("mail_send_err_flg")))
//		{
//			// BPにサービスコンポーネントのステータスを設定する。
//			String formatStatus = "1100";
//			String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus);
//			param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus);
//			param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message);
//			ArrayList<Object> errorInfoArray = new ArrayList<Object>();
//			HashMap<String, Object> itemCheckErrors = new HashMap<String, Object>();
//			HashMap<String, Object> errorInfo = new HashMap<String, Object>();
//			itemCheckErrors.put("mail_send_err_flg_err", "EA");
//			errorInfo.put("ITEM_CHECK_ERRORS", itemCheckErrors);
//			errorInfo.put("RETURN_CODE", "0");
//			errorInfo.put("TEMPLATE_ID", "ECC0021D010");
//			errorInfo.put("STATUS", formatStatus);
//			errorInfoArray.add(errorInfo);
//			param.setControlMapData(SCControlMapKeys.ERROR_INFO, errorInfoArray);
//			dataMap.put("mail_send_err_flg_err", "EA");
//			SCCallException scCallEx = new SCCallException("INVALID_RETURN_MESSAGE", rtnCode, Integer.parseInt(formatStatus));
//			throw scCallEx;
//		}
		
		
		if(!("0".equals(rtnCode) && 0 == Integer.parseInt(status))) 
		{
			// メール送信エラーの場合、送信エラーの情報をパラメータに設定
			param.setControlMapData(this.fixedTextGlobal, "MAIL_SEND_ERR");
		}

		if ("1".equals(dataMap.get("mail_send_err_flg")))
		{
			// メール送信エラーの場合、送信エラーの情報をパラメータに設定
			param.setControlMapData(this.fixedTextGlobal, "MAIL_SEND_ERR");

		}
		
		return param;
	}

	/**
	 * ワーク領域値取得処理
	 * @param param リクエストパラメータ
	 * @throws RequestParameterException
	 */
	private void editWorkArea(IRequestParameterReadWrite param) throws RequestParameterException
	{
		// 作業項目領域
		Map<Object, Object> workAreaMap = param.getMappingWorkArea();
		if (workAreaMap == null)
		{
			workAreaMap = new HashMap<Object, Object>();
			param.setMappingWorkArea(workAreaMap);
		}
		
		/* 作業項目情報 */
		Map<String, Object> workMap = (HashMap<String, Object>)workAreaMap.get("WORK");
		if (workMap == null)
		{
			workMap = new HashMap<String, Object>();
			workAreaMap.put("WORK", workMap);
		}

		/* ユーザデータ情報 */
		HashMap<String, Object> inMap = (HashMap<String, Object>)param.getData(this.fixedTextGlobal);

		if (inMap == null)
		{
			inMap = new HashMap<String, Object>();
			param.setData(this.fixedTextGlobal, inMap);
		}

		ArrayList<HashMap<String, Object>> tmpFileList = (ArrayList<HashMap<String, Object>>)inMap.get("ECC0021D010CBSMsg3List");

		if (tmpFileList == null)
		{
			return;
		}

		ArrayList<HashMap<String, Object>> efileKanriList = (ArrayList<HashMap<String, Object>>) workMap.get("EfileKanriList");
		if (efileKanriList == null)
		{
			efileKanriList = new ArrayList<HashMap<String, Object>>();
		}

		for (int i = 0; i < tmpFileList.size(); i++)
		{
			HashMap<String, Object> mapTmpFile = tmpFileList.get(i);

			if (!JCRUtilCommon.isNull(mapTmpFile.get("seq")))
			{
				int seq = Integer.parseInt((String) mapTmpFile.get("seq"));
				
				if (seq < efileKanriList.size())
				{
					HashMap<String, Object> mapEfileKanri = efileKanriList.get(seq);
	
					// 対応履歴電子ファイル管理登録.電子ファイル管理番号 → 電子ファイル管理番号
					mapTmpFile.put("efile_kanri_no", mapEfileKanri.get("efile_kanri_no"));
	
					mapTmpFile.put("file_nm", mapEfileKanri.get("file_nm"));
				}
			}

		}
	}

}

