/*********************************************************************
* All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：JKKStarChannelSetwariMapperCC
*   ソースファイル名：JKKStarChannelSetwariMapperCC.java
*   作成者          ：FJ
*   日付            ：2014年07月03日
*＜機能概要＞
*   スターチャンネルセット割部品
*＜修正履歴＞
*   バージョン  修正日      修正者      修正内容
*	v10.00.00   2014/07/03  FJ)寺園     新規作成(ANK-2135-00-00)
*
**********************************************************************/
package com.fujitsu.futurity.bp.custom.common;

import java.util.ArrayList;
import java.util.Arrays;
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.parameter.IRequestParameterReadWrite;
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 com.fujitsu.futurity.model.ejb.common.JSYejbLog;

import eo.common.constant.JKKStrConst;
import eo.ejb.cbs.cbsmsg.EKK0081A010CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0321B002CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0321D010CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0451B001CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0451B001CBSMsg1List;
import eo.ejb.cbs.cbsmsg.EKK0451B005CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0451C020CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0451C070CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0451D010CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0451D010CBSMsg1List;
import eo.ejb.cbs.cbsmsg.EKK0491A010CBSMsg;
import eo.ejb.cbs.cbsmsg.EKK0851B001CBSMsg;

/**
 * スターチャンネルセット割部品CC CC-SCマッピングクラス
 * 
 * @author 富士通
 */
public class JKKStarChannelSetwariMapperCC
{
	/** SC呼び出し部品 */
	private ServiceComponentRequestInvoker scCall = null;
	/** セッションハンドル */
	private SessionHandle handle = null;
	/** 業務データ取得用I/F */
	private IRequestParameterReadWrite param = null;
	/** オンライン運用日付 */
	private String opeDate = null;
	
	/** サービス契約一意照会 */
	private final String EKK0081A010 = "EKK0081A010";
	/** 割引サービス契約一覧照会 */
	private final String EKK0451B001 = "EKK0451B001";
	/** 割引サービス契約登録 */
	private final String EKK0451D010 = "EKK0451D010";
	/** 割引サービス契約キャンセル */
	private final String EKK0451C070 = "EKK0451C070";
	/** 割引サービス対象サービス一覧照会 */
	private final String EKK0851B001 = "EKK0851B001";
	/** 請求契約一意照会 */
	private final String EKK0491A010 = "EKK0491A010";
	/** 課金先一覧照会（サービス契約番号） */
	private final String EKK0321B002 = "EKK0321B002";
	/** 課金先登録 */
	private final String EKK0321D010 = "EKK0321D010";
	
	
	/**
	 * 
	 * リクエストパラメータのキー定数
	 * 
	 * ・SYSID
	 * ・サービス契約番号
	 * ・申込明細番号
	 * ・サービスキャンセル理由コード
	 * ・起算日
	 * ・利用開始希望年月日
	 * ・異動区分
	 * ・更新年月日時分秒（更新前）
	 */
	private final String KEY_SYSID             = "sysid";
	private final String KEY_SVC_KEI_NO        = "svc_kei_no";
	private final String KEY_MSKM_DTL_NO       = "mskm_dtl_no";
	private final String KEY_SVC_CANCEL_RSN_CD = "svc_cancel_rsn_cd";
	private final String KEY_KISAN_YMD         = "kisan_ymd";
	private final String KEY_USE_STA_KIBO_YMD  = "use_sta_kibo_ymd";
	private final String KEY_IDO_DIV           = "ido_div";
	private final String KEY_KK0081_UPD_DTM    = "kk0081_upd_dtm";
	
	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>コンストラクタ<br>
	 * <dt>処理補足：
	 * <dd>フィールド変数の値を設定する<br>
	 * </dl>
	 * 
	 * @param iCmnHandle セッションハンドル
	 * @param iCmnParam 業務データ取得用I/F
	 * @param iOpeDate オンライン運用日付
	 */
	public JKKStarChannelSetwariMapperCC(SessionHandle iCmnHandle,
										IRequestParameterReadWrite iCmnParam,
										String iOpeDate) {
		this.handle = iCmnHandle;
		this.param = iCmnParam;
		this.opeDate = iOpeDate;
		this.scCall = new ServiceComponentRequestInvoker();
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>デバッグログを出力する<br>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param dumpObj 出力するオブジェクト
	 */
	@SuppressWarnings("static-access")
	private void printlnEjbLog(Object dumpObj) {
		JSYejbLog.println(JSYejbLog.DEBUG, this.getClass(), dumpObj, null, null, null);
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>持ちうるフィールドにNullマッピングで埋める<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param msg 対象クラス
	 * @param contents 対応クラスのフィールド列挙
	 */
	private void fillCAANMSGNullMapping(CAANMsg msg, Object[][] contents) {
		
		// 要素ごとのループ
		for (int i = 0; i < contents.length; i++) {
			
			Object element = null;
			
			// キーに該当する箇所の取得
			element = contents[i][0];
			// Nullでマッピング
			msg.setNull((String) element);
		}
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>S/IF呼出時の共通情報を設定する<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param template 条件の設定先
	 * @throws Throwable
	 */
	private void templateCommonInfo(CAANMsg template) throws Throwable {
		
		// オペレータID
		Object operatorId = this.param.getControlMapData(SCControlMapKeys.OPERATOR_ID);
		template.set(JCMConstants.OPERATOR_ID_KEY, operatorId);
		
		// 運用日付
		Object operateDate = this.param.getControlMapData(SCControlMapKeys.OPE_DATE);
		template.set(JCMConstants.OPERATE_DATE_KEY, operateDate);
		
		// 運用日時
		Object operateDateTime = this.param.getControlMapData(SCControlMapKeys.OPE_TIME);
		template.set(JCMConstants.OPERATE_DATETIME_KEY, operateDateTime);
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>SCインプット共通データ設定処理です。<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param inMap
	 * @return パラメータマップ
	 * @throws Throwable
	 */
	private HashMap<String, Object> setSCInputCommonData(HashMap<String, Object> inMap) throws Throwable {
		
		/* SCインプット共通データ */
		// **********************************************
		// 【取得元：電文ヘッダ(ヘッダ)】
		// **********************************************
		// 電文ID
		inMap.put(JCMConstants.TRANZACTION_ID_KEY, this.param.getTelegramID());
		// ユースケースID
		inMap.put(JCMConstants.USECASE_ID_KEY, this.param.getUsecaseID());
		// オペレーションID
		inMap.put(JCMConstants.OPERATION_ID_KEY, this.param.getOperationID());
		// サービス呼び出し区分
		inMap.put(JCMConstants.CALL_TYPE_KEY, this.param.getCallType());
		
		// **********************************************
		// 【取得元：ユーザエリア(コントロールマップ)】
		// **********************************************
		// 依頼先ホスト名
		inMap.put(JCMConstants.CLIENT_HOST_NAME_KEY, this.param.getControlMapData(SCControlMapKeys.REQ_HOSTNAME));
		// 依頼元IPアドレス
		inMap.put(JCMConstants.CLIENT_IP_ADDRESS_KEY, this.param.getControlMapData(SCControlMapKeys.REQ_HOSTIP));
		// 依頼元画面ID
		inMap.put(JCMConstants.INVOKE_GAMEN_ID_KEY, this.param.getControlMapData(SCControlMapKeys.REQ_VIEWID));
		// オペレータID
		inMap.put(JCMConstants.OPERATOR_ID_KEY, this.param.getControlMapData(SCControlMapKeys.OPERATOR_ID));
		
		return inMap;
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>呼び出したサービスIFの処理結果を判定する.<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param result
	 * @throws Throwable
	 */
	@SuppressWarnings("boxing")
	private void checkExecutionResult(Map<?, ?> result) throws Throwable {
		
		// 取得したリターンコード、ステータスの内容を見て異常かどうかの判断をする。
		String rtnCode = result.get(JCMConstants.RET_CD_INT_KEY).toString();
		CAANMsg[] templates = (CAANMsg[])result.get(JCMConstants.TEMPLATE_LIST_KEY);
		Integer status = templates[0].getInt(JCMConstants.STATUS_INT_KEY);
		
		// 異常の場合、SCCallExceptionを生成してスローする
		if (!("0".equals(rtnCode) && 0 == status.intValue()))
		{
			SCCallException scCallEx = new SCCallException("戻り値不正", rtnCode, status);
			throw scCallEx;
		}
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>サービスIFの結果を取得する<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param rsltMap サービスIFリスト
	 * @return templateList 結果が格納されたリスト
	 * @throws Throwable 
	 */
	private ArrayList<CAANMsg> getRsltList(Map<?, ?> rsltMap) {
		
		// SCからの戻り値からCAANMsgを取得する。
		CAANMsg[] templates = (CAANMsg[])rsltMap.get(JCMConstants.TEMPLATE_LIST_KEY);
		ArrayList<CAANMsg> resultList = new ArrayList<CAANMsg>(Arrays.asList(templates));
		return resultList;
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>サービスコンポーネント実行後に、IRequestParameterReadWriteに必要なデータをマッピングする<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param param 
	 * @param mapName 
	 * @return templateList 結果が格納されたリスト
	 * @throws Throwable 
	 */
	@SuppressWarnings({ "unchecked", "cast", "boxing" })
	public IRequestParameterReadWrite editResultRP(Map<?, ?> msgList,
													@SuppressWarnings("hiding") IRequestParameterReadWrite param,
													String mapName) throws Throwable {
		
		// SCからの戻り値からCAANMsgを取得する。
		CAANMsg[] templates = (CAANMsg[]) msgList.get(JCMConstants.TEMPLATE_LIST_KEY);
		
		// リターンコード取得
		Object return_code = msgList.get(JCMConstants.RET_CD_INT_KEY);
		
		// 作業領域の取得
		Map workMap = (Map)param.getMappingWorkArea();
		if (workMap == null) {
			workMap = new HashMap();
			param.setMappingWorkArea(workMap);
		}
		
		// 結果を詰めるマップを取得。
		HashMap dataMap = null;
		
		/* 業務データ設定 */
		dataMap = (HashMap)param.getData(mapName);
		if (dataMap == null) {
			dataMap = new HashMap();
			param.setData(mapName, dataMap);
		}
		
		// エラー情報の設定
		param = editErrorInfo(param, templates, (Integer)return_code, mapName);
		
		//エラー情報のマップを取得
		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));
		
		return param;
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>サービス契約一意照会サービスIFを呼び出す<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param  funcCd
	 * @param  svcKeiNo
	 * @return CAANMsg[]
	 * @throws Throwable
	 */
	public CAANMsg[] callEKK0081A010(String funcCd, String svcKeiNo) throws Throwable {
		
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0081A010 start");
		/* --------------------------------------------------
		 * CC項目 -> SC項目 上りマッピング
		 * -------------------------------------------------- */
		HashMap<String, Object> inMap = new HashMap<String, Object>();
		
		// 割引サービス契約一意照会サービスインターフェイスを作成
		CAANMsg template = new CAANMsg(EKK0081A010CBSMsg.class.getName());
		
		// nullを設定
		fillCAANMSGNullMapping(template, new EKK0081A010CBSMsg().getContents());
		
		// テンプレートID
		template.set(EKK0081A010CBSMsg.TEMPLATEID, this.EKK0081A010);
		// 機能コード
		template.set(EKK0081A010CBSMsg.FUNC_CODE, funcCd);
		// サービス契約番号
		template.set(EKK0081A010CBSMsg.KEY_SVC_KEI_NO, svcKeiNo);
		// 予約適用年月日
		template.set(EKK0081A010CBSMsg.KEY_RSV_APLY_YMD, this.opeDate);
		
		// 共通情報設定処理
		templateCommonInfo(template);
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		inMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		
		// SCインプット共通データ設定処理
		setSCInputCommonData(inMap);
		
		printlnEjbLog("inMap="  + inMap.toString());
		printlnEjbLog("handle=" + this.handle.toString());
		
		/* --------------------------------------------------
		 * サービスIF実行
		 * -------------------------------------------------- */
		Map<?, ?> result = this.scCall.run(inMap, this.handle);
		
		// エラー情報の設定
		this.param = editResultRP(result, this.param, this.EKK0081A010);
		
		checkExecutionResult(result);
		
		/* --------------------------------------------------
		 * CC項目 <- SC項目 下りマッピング
		 * -------------------------------------------------- */
		// 結果をリストで取得
		ArrayList<CAANMsg> kk0081List = getRsltList(result);
		
		CAANMsg kk0081 = kk0081List.get(0);
		CAANMsg[] ret = kk0081.getCAANMsgList(EKK0081A010CBSMsg.EKK0081A010CBSMSG1LIST);
		
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0081A010 end");
		return ret;
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>割引サービス契約一覧照会サービスIFを呼び出す<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param  funcCd 
	 * @param  svcKeiNo
	 * @return CAANMsg[]
	 * @throws Throwable
	 */
	public CAANMsg[] callEKK0451B001(String funcCd, String svcKeiNo) throws Throwable {
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0451B001 start");
		
		/* --------------------------------------------------
		 * CC項目 -> SC項目 上りマッピング
		 * -------------------------------------------------- */
		HashMap<String, Object> inMap = new HashMap<String, Object>();
		
		// 割引サービス対象契約一覧照会サービスインターフェイスを作成
		CAANMsg template = new CAANMsg(EKK0451B001CBSMsg.class.getName());
		
		// nullを設定
		fillCAANMSGNullMapping(template, new EKK0451B001CBSMsg().getContents());
		
		// テンプレートID
		template.set(EKK0451B001CBSMsg.TEMPLATEID, this.EKK0451B001);
		// 機能コード
		template.set(EKK0451B001CBSMsg.FUNC_CODE,  funcCd);
		
		// サービス契約番号
		template.set(EKK0451B001CBSMsg.KEY_SVC_KEI_NO, svcKeiNo);
		
		// 共通情報設定処理
		templateCommonInfo(template);
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		inMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		
		// SCインプット共通データ設定処理
		setSCInputCommonData(inMap);
		
		printlnEjbLog("inMap="  + inMap.toString());
		printlnEjbLog("handle=" + this.handle.toString());
		
		/* --------------------------------------------------
		 * サービスIF実行
		 * -------------------------------------------------- */
		Map<?, ?> result = this.scCall.run(inMap, this.handle);
		
		// エラー情報の設定
		this.param = editResultRP(result, this.param, this.EKK0451B001);
		
		checkExecutionResult(result);
		
		/* --------------------------------------------------
		 * CC項目 <- SC項目 下りマッピング
		 * -------------------------------------------------- */
		// 結果をリストで取得
		ArrayList<CAANMsg> kk0451List = getRsltList(result);
		
		CAANMsg kk0451 = kk0451List.get(0);
		CAANMsg[] ret  = kk0451.getCAANMsgList(EKK0451B001CBSMsg.EKK0451B001CBSMSG1LIST);
		
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0451B001 end");
		return ret;
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>割引サービス契約登録サービスIFを呼び出す<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param  funcCd 
	 * @param  wribSvcKeiInf
	 * @return wrisvcTgKeiList
	 * @throws Throwable
	 */
	public CAANMsg callEKK0451D010(String funcCd, Map<String, Object> ccMapWork, String wribSvcCd, String pcrsCd, String pplanCd, String wribSvcTgSvcCd) throws Throwable {
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0451D010 start");
		
		/* --------------------------------------------------
		 * CC項目 -> SC項目 上りマッピング
		 * -------------------------------------------------- */
		HashMap<String, Object> inMap = new HashMap<String, Object>();
		
		// 進捗登録サービスインターフェイスを作成
		CAANMsg template = new CAANMsg(EKK0451D010CBSMsg.class.getName());
		
		// nullを設定
		fillCAANMSGNullMapping(template, new EKK0451D010CBSMsg().getContents());
		
		// テンプレートID
		template.set(EKK0451D010CBSMsg.TEMPLATEID, this.EKK0451D010);
		// 機能コード
		template.set(EKK0451D010CBSMsg.FUNC_CODE, funcCd);
		
		
		//----------------------------
		// 割引サービス契約の設定値
		//----------------------------
		// SYSID
		template.set(EKK0451D010CBSMsg.SYSID,                  ccMapWork.get(this.KEY_SYSID));
		// 割引サービスコード
		template.set(EKK0451D010CBSMsg.WRIB_SVC_CD,            wribSvcCd);
		// 料金コースコード
		template.set(EKK0451D010CBSMsg.PCRS_CD,                pcrsCd);
		// 料金プランコード
		template.set(EKK0451D010CBSMsg.PPLAN_CD,               pplanCd);
		// サービス利用開始希望年月日
		template.set(EKK0451D010CBSMsg.SVC_USE_STA_KIBO_YMD,   ccMapWork.get(this.KEY_USE_STA_KIBO_YMD));
		// 申込明細番号
		template.set(EKK0451D010CBSMsg.MSKM_DTL_NO,            ccMapWork.get(this.KEY_MSKM_DTL_NO));
		// 即時適用フラグ
		template.set(EKK0451D010CBSMsg.APLY_JUN,               JKKStrConst.CD00403_NO);
		// 異動区分
		template.set(EKK0451D010CBSMsg.IDO_DIV,                ccMapWork.get(this.KEY_IDO_DIV));
		// 申込起算日
		template.set(EKK0451D010CBSMsg.MSKM_KISAN_YMD,         ccMapWork.get(this.KEY_KISAN_YMD));
		// 割引登録契機コード
		template.set(EKK0451D010CBSMsg.WRIB_ADD_OPTY_CD,       JKKStrConst.CD00874_MAN_SET);
		// 割引登録年月日
		template.set(EKK0451D010CBSMsg.WRIB_ADD_YMD,           this.opeDate);
		// 更新年月日時分秒(変更前)
		template.set(EKK0451D010CBSMsg.UPD_DTM_BF,             ccMapWork.get(this.KEY_KK0081_UPD_DTM));
		
		CAANMsg[] childTemplate = template.getCAANMsgList(EKK0451D010CBSMsg.EKK0451D010CBSMSG1LIST);
		if (childTemplate == null) {
			childTemplate = new CAANMsg[1];
		}
		//---------------------------------------------
		// 割引サービス契約の設定値（サービス契約）
		//---------------------------------------------
		childTemplate[0] = new CAANMsg(EKK0451D010CBSMsg1List.class.getName());
		// 対象契約識別コード
		childTemplate[0].set(EKK0451D010CBSMsg1List.TG_KEI_SKBT_CD,        JKKStrConst.CD_DIV_OYAKEISKBTCD_SVCKEI);
		// サービス契約番号
		childTemplate[0].set(EKK0451D010CBSMsg1List.SVC_KEI_NO,            ccMapWork.get(this.KEY_SVC_KEI_NO));
		// 割引サービス対象サービスコード
		childTemplate[0].set(EKK0451D010CBSMsg1List.WRIB_SVC_TRGT_SVC_CD,  wribSvcTgSvcCd);
		// 設定登録年月日
		childTemplate[0].set(EKK0451D010CBSMsg1List.SET_ADD_YMD,           this.opeDate);
		// 割引サービス対象契約適用開始年月日
		childTemplate[0].set(EKK0451D010CBSMsg1List.WRISVC_TG_KEI_TSTAYMD, this.opeDate);
		// 割引サービス対象契約適用終了年月日
		childTemplate[0].set(EKK0451D010CBSMsg1List.WRISVC_TG_KEI_TENDYMD, JKKStrConst.END_YMD_DEFAULT);
		
		// 割引サービス対象契約明細
		template.set(EKK0451D010CBSMsg.EKK0451D010CBSMSG1LIST, childTemplate);
		
		// 共通情報設定処理
		templateCommonInfo(template);
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		inMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		
		// SCインプット共通データ設定処理
		setSCInputCommonData(inMap);
		
		printlnEjbLog("inMap="  + inMap.toString());
		printlnEjbLog("handle=" + this.handle.toString());
		
		/* --------------------------------------------------
		 * サービスIF実行
		 * -------------------------------------------------- */
		Map<?, ?> result = this.scCall.run(inMap, this.handle);
		
		// エラー情報の設定
		this.param = editResultRP(result, this.param, this.EKK0451D010);
		
		checkExecutionResult(result);
		
		/* --------------------------------------------------
		 * CC項目 <- SC項目 下りマッピング
		 * -------------------------------------------------- */
		// 結果をリストで取得
		ArrayList<CAANMsg> kk0451List = getRsltList(result);
		
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0451D010 end");
		
		return kk0451List.get(0);
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>割引サービス契約キャンセルサービスIFを呼び出す<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param  funcCd 
	 * @param  ccMapWork
	 * @param  msg
	 * @param  svcMsg
	 * @return 
	 * @throws Throwable
	 */
	public CAANMsg callEKK0451C070(String funcCd, Map<String, Object> ccMapWork, CAANMsg msg) throws Throwable {
		printlnEjbLog("callEKK0451C070 start");
		
		/* --------------------------------------------------
		 * CC項目 -> SC項目 上りマッピング
		 * -------------------------------------------------- */
		HashMap<String, Object> inMap = new HashMap<String, Object>();

		// 割引サービス契約キャンセルサービスインターフェイスを作成
		CAANMsg template = new CAANMsg(EKK0451C070CBSMsg.class.getName());

		// nullを設定
		fillCAANMSGNullMapping(template, new EKK0451C070CBSMsg().getContents());

		// テンプレートID
		template.set(EKK0451C070CBSMsg.TEMPLATEID, this.EKK0451C070);
		// 機能コード
		template.set(EKK0451C070CBSMsg.FUNC_CODE, funcCd);
		
		
		// 割引サービス契約番号 
		template.set(EKK0451C070CBSMsg.WRIB_SVC_KEI_NO,       msg.getString(EKK0451B001CBSMsg1List.WRIB_SVC_KEI_NO));
		// 申込明細番号
		template.set(EKK0451C070CBSMsg.MSKM_DTL_NO,           ccMapWork.get(this.KEY_MSKM_DTL_NO));
		// サービスキャンセル理由コード
		template.set(EKK0451C070CBSMsg.SVC_CANCEL_RSN_CD,     ccMapWork.get(this.KEY_SVC_CANCEL_RSN_CD));
		// 異動区分
		template.set(EKK0451C070CBSMsg.IDO_DIV,               ccMapWork.get(this.KEY_IDO_DIV));
		// 解約キャンセル契機コード
		template.set(EKK0451C020CBSMsg.WRIB_DSL_CNCL_OPTY_CD, JKKStrConst.CD00874_MAN_SET);
		// 更新年月日時分秒(更新前)
		template.set(EKK0451C070CBSMsg.UPD_DTM_BF,            ccMapWork.get(this.KEY_KK0081_UPD_DTM));
		
		// 共通情報設定処理
		templateCommonInfo(template);
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		inMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);

		// SCインプット共通データ設定処理
		setSCInputCommonData(inMap);
		
		printlnEjbLog("inMap="  + inMap.toString());
		printlnEjbLog("handle=" + this.handle.toString());
		
		/* --------------------------------------------------
		 * サービスIF実行
		 * -------------------------------------------------- */
		Map<?, ?> result = this.scCall.run(inMap, this.handle);
		
        // エラー情報の設定
		this.param = editResultRP(result, this.param, this.EKK0451C070);
		
		checkExecutionResult(result);
		
		/* --------------------------------------------------
		 * CC項目 <- SC項目 下りマッピング
		 * -------------------------------------------------- */
		// 結果をリストで取得
		ArrayList<CAANMsg> kk0451List = getRsltList(result);
		
		printlnEjbLog("callEKK0451C070 end");
		return kk0451List.get(0);
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>割引サービス対象サービス一覧照会サービスIFを呼び出す<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param  funcCd 
	 * @param  wribSvcCd
	 * @return CAANMsg[]
	 * @throws Throwable
	 */
	public CAANMsg[] callEKK0851B001(String funcCd, String wribSvcCd) throws Throwable {
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0851B001 start");
		
		/* --------------------------------------------------
		 * CC項目 -> SC項目 上りマッピング
		 * -------------------------------------------------- */
		HashMap<String, Object> inMap = new HashMap<String, Object>();
		
		// 割引サービス対象サービス一覧照会サービスインターフェイスを作成
		CAANMsg template = new CAANMsg(EKK0851B001CBSMsg.class.getName());
		
		// nullを設定
		fillCAANMSGNullMapping(template, new EKK0851B001CBSMsg().getContents());
		
		// テンプレートID
		template.set(EKK0851B001CBSMsg.TEMPLATEID, this.EKK0851B001);
		// 機能コード
		template.set(EKK0851B001CBSMsg.FUNC_CODE, funcCd);
		
		// 割引サービスコード
		template.set(EKK0851B001CBSMsg.KEY_WRIB_SVC_CD, wribSvcCd);

		// 最大表示件数
		template.set(EKK0851B001CBSMsg.MAX_SEARCH_NUM, "9999");
		
		// 共通情報設定処理
		templateCommonInfo(template);
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		inMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		
		// SCインプット共通データ設定処理
		setSCInputCommonData(inMap);
		
		printlnEjbLog("inMap="  + inMap.toString());
		printlnEjbLog("handle=" + this.handle.toString());
		
		/* --------------------------------------------------
		 * サービスIF実行
		 * -------------------------------------------------- */
		Map<?, ?> result = this.scCall.run(inMap, this.handle);
		
		// エラー情報の設定
		this.param = editResultRP(result, this.param, this.EKK0851B001);
		
		checkExecutionResult(result);
		
		/* --------------------------------------------------
		 * CC項目 <- SC項目 下りマッピング
		 * -------------------------------------------------- */
		// 結果をリストで取得
		ArrayList<CAANMsg> kk0481List = getRsltList(result);
		
		CAANMsg kk0481 = kk0481List.get(0);
		CAANMsg[] ret  = kk0481.getCAANMsgList(EKK0851B001CBSMsg.EKK0851B001CBSMSG1LIST);
		
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0851B001 end");
		return ret;
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>請求契約一意照会サービスIFを呼び出す<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param  funcCd
	 * @param  seikyKeiNo
	 * @return CAANMsg[]
	 * @throws Throwable
	 */
	public CAANMsg[] callEKK0491A010(String funcCd, String seikyKeiNo) throws Throwable {
		
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0491A010 start");
		/* --------------------------------------------------
		 * CC項目 -> SC項目 上りマッピング
		 * -------------------------------------------------- */
		HashMap<String, Object> inMap = new HashMap<String, Object>();
		
		// 請求契約一意照会サービスインターフェイスを作成
		CAANMsg template = new CAANMsg(EKK0491A010CBSMsg.class.getName());
		
		// nullを設定
		fillCAANMSGNullMapping(template, new EKK0491A010CBSMsg().getContents());
		
		// テンプレートID
		template.set(EKK0491A010CBSMsg.TEMPLATEID, this.EKK0491A010);
		// 機能コード
		template.set(EKK0491A010CBSMsg.FUNC_CODE, funcCd);
		// 請求契約番号
		template.set(EKK0491A010CBSMsg.KEY_SEIKY_KEI_NO, seikyKeiNo);
		// 予約適用年月日
		template.set(EKK0491A010CBSMsg.KEY_RSV_APLY_YMD, this.opeDate);
		
		// 共通情報設定処理
		templateCommonInfo(template);
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		inMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		
		// SCインプット共通データ設定処理
		setSCInputCommonData(inMap);
		
		printlnEjbLog("inMap="  + inMap.toString());
		printlnEjbLog("handle=" + this.handle.toString());
		
		/* --------------------------------------------------
		 * サービスIF実行
		 * -------------------------------------------------- */
		Map<?, ?> result = this.scCall.run(inMap, this.handle);
		
		// エラー情報の設定
		this.param = editResultRP(result, this.param, this.EKK0491A010);
		
		checkExecutionResult(result);
		
		/* --------------------------------------------------
		 * CC項目 <- SC項目 下りマッピング
		 * -------------------------------------------------- */
		// 結果をリストで取得
		ArrayList<CAANMsg> kk0491List = getRsltList(result);
		
		CAANMsg kk0491 = kk0491List.get(0);
		CAANMsg[] ret = kk0491.getCAANMsgList(EKK0491A010CBSMsg.EKK0491A010CBSMSG1LIST);
		
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0491A010 end");
		return ret;
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>課金先一覧照会（請求契約番号／サービス契約番号）サービスIFを呼び出す<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param  funcCd 
	 * @param  svcKeiNo
	 * @return CAANMsg[]
	 * @throws Throwable
	 */
	public CAANMsg[] callEKK0321B002(String funcCd, String svcKeiNo) throws Throwable {
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0321B002 start");
		
		/* --------------------------------------------------
		 * CC項目 -> SC項目 上りマッピング
		 * -------------------------------------------------- */
		HashMap<String, Object> inMap = new HashMap<String, Object>();
		
		// 課金先一覧照会（サービス契約番号）照会サービスインターフェイスを作成
		CAANMsg template = new CAANMsg(EKK0321B002CBSMsg.class.getName());
		
		// nullを設定
		fillCAANMSGNullMapping(template, new EKK0321B002CBSMsg().getContents());
		
		// テンプレートID
		template.set(EKK0321B002CBSMsg.TEMPLATEID, this.EKK0321B002);
		// 機能コード
		template.set(EKK0321B002CBSMsg.FUNC_CODE, funcCd);
		
		// サービス契約番号
		template.set(EKK0321B002CBSMsg.KEY_SVC_KEI_NO, svcKeiNo);
		
		// 共通情報設定処理
		templateCommonInfo(template);
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		inMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		
		// SCインプット共通データ設定処理
		setSCInputCommonData(inMap);
		
		printlnEjbLog("inMap="  + inMap.toString());
		printlnEjbLog("handle=" + this.handle.toString());
		
		/* --------------------------------------------------
		 * サービスIF実行
		 * -------------------------------------------------- */
		Map<?, ?> result = this.scCall.run(inMap, this.handle);
		
        // エラー情報の設定
		this.param = editResultRP(result, this.param, this.EKK0321B002);
		
		checkExecutionResult(result);
		
		/* --------------------------------------------------
		 * CC項目 <- SC項目 下りマッピング
		 * -------------------------------------------------- */
		// 結果をリストで取得
		ArrayList<CAANMsg> kk0321List = getRsltList(result);
		
		CAANMsg kk0321 = kk0321List.get(0);
		CAANMsg[] ret  = kk0321.getCAANMsgList(EKK0321B002CBSMsg.EKK0321B002CBSMSG1LIST);
		
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0321B002 end");
		return ret;
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>課金先登録サービスIFを呼び出す<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param  funcCd 
	 * @param  wribSvcKeiInf
	 * @return wrisvcTgKeiList
	 * @throws Throwable
	 */
	public CAANMsg callEKK0321D010(String funcCd, String seikyKeiNo, String wribSvcKeiNo, String updDtmBf) throws Throwable {
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0321D010 start");
		
		/* --------------------------------------------------
		 * CC項目 -> SC項目 上りマッピング
		 * -------------------------------------------------- */
		HashMap<String, Object> inMap = new HashMap<String, Object>();
		
		// 割引サービス契約登録サービスインターフェイスを作成
		CAANMsg template = new CAANMsg(EKK0321D010CBSMsg.class.getName());
		
		// nullを設定
		fillCAANMSGNullMapping(template, new EKK0321D010CBSMsg().getContents());
		
		// テンプレートID
		template.set(EKK0321D010CBSMsg.TEMPLATEID, this.EKK0321D010);
		// 機能コード
		template.set(EKK0321D010CBSMsg.FUNC_CODE, funcCd);
		
		
		// 請求契約番号
		template.set(EKK0321D010CBSMsg.SEIKY_KEI_NO,    seikyKeiNo);
		// 割引サービス契約番号	
		template.set(EKK0321D010CBSMsg.WRIB_SVC_KEI_NO, wribSvcKeiNo);
		// 課金先適用開始年月日	
		template.set(EKK0321D010CBSMsg.KAKINS_TSTAYMD,  this.opeDate);
		// 課金先適用終了年月日
		template.set(EKK0321D010CBSMsg.KAKINS_TENDYMD,  JKKStrConst.END_YMD_DEFAULT);
		// 更新年月日時分秒
		template.set(EKK0321D010CBSMsg.UPD_DTM_BF,      updDtmBf);
		
		
		// 共通情報設定処理
		templateCommonInfo(template);
		
		CAANMsg[] templates = new CAANMsg[1];
		templates[0] = template;
		inMap.put(JCMConstants.TEMPLATE_LIST_KEY, templates);
		
		// SCインプット共通データ設定処理
		setSCInputCommonData(inMap);
		
		printlnEjbLog("inMap="  + inMap.toString());
		printlnEjbLog("handle=" + this.handle.toString());
		
		/* --------------------------------------------------
		 * サービスIF実行
		 * -------------------------------------------------- */
		Map<?, ?> result = this.scCall.run(inMap, this.handle);
		
		// エラー情報の設定
		this.param = editResultRP(result, this.param, this.EKK0321D010);
		
		checkExecutionResult(result);
		
		/* --------------------------------------------------
		 * CC項目 <- SC項目 下りマッピング
		 * -------------------------------------------------- */
		// 結果をリストで取得
		ArrayList<CAANMsg> kk0321List = getRsltList(result);
		
		printlnEjbLog("JKKStarChannelSetwariMapperCC.callEKK0321D010 end");
		
		return kk0321List.get(0);
	}

	/**
	 * 
	 * <dl>
	 * <dt>処理概要：
	 * <dd>サービスコンポーネント実行後に、IRequestParameterReadWriteにエラー情報をマッピングする<BR>
	 * <dt>処理補足：
	 * <dd>
	 * </dl>
	 * 
	 * @param param      業務データ取得・書込用I/F
	 * @param templates  CAANMsgクラス配列
	 * @param returnCode リターンコード
	 * @param mapName    SCマップ名
	 * 
	 * @return 業務データ取得・書込用I/F
	 */
	@SuppressWarnings({ "unchecked", "cast", "null", "boxing" })
	public IRequestParameterReadWrite editErrorInfo(@SuppressWarnings("hiding") IRequestParameterReadWrite param,
													 CAANMsg[] templates,
													 int returnCode,
													 String mapName) throws Throwable {
		CAANMsg template = templates[0];
		CAANMsg[] templateArray = null;
		int templateStatus = template.getInt(EKK0451B005CBSMsg.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 = (Map)param.getMappingWorkArea();
		if (workMap == null) {
			workMap = new HashMap();
			param.setMappingWorkArea(workMap);
		}
		
		/* ユーザデータ情報 */
		inMap = (HashMap)param.getData(mapName);
		if (inMap == null) {
			inMap = new HashMap();
			param.setData(mapName, inMap);
		}

		String svcIf = null;
		if (svcIf == null) {
			return param;
			
		} else {
			
			// 処理なし
		}
		return param;
	}
}
