/*********************************************************************
* All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：JKKOptPackAplyChkUtil
*   ソースファイル名：JKKOptPackAplyChkUtil.java
*   作成者          ：富士通
*   日付            ：2014年05月13日
*＜機能概要＞
*   登録部品
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*   v9.00.00    2014/05/13   FJ）中山    新規作成
*
**********************************************************************/
package com.fujitsu.futurity.bp.custom.common;

import java.util.ArrayList;
import java.util.HashMap;

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.AbstractCommonComponent;
import com.fujitsu.futurity.common.JSYLogBase;
import com.fujitsu.futurity.common.JSYbpmLog;


/**
 * オプションパック適用判定コモンコンポーネント部品の呼び出しを行う。
 * <br>
 * @author 富士通
 */
public class JKKOptPackAplyChkUtil extends AbstractCommonComponent
{
	/** サービスメッセージ */
	private static final String SERVICE_MESSAGE = "optPackAplyChkMap";
	
	/** 戻りコード 正常終了 */
	private static final String RETURN_CD_NORMAL = "000";
	
	/**
	 * オプションパック適用判定処理
	 * <br/>
	 * @param handle セッションハンドル
	 * @param param リクエストパラメータ
	 * @param fixedText ユーザー固定文字列
	 * @return param リクエストパラメータ
	 * @throws Throwable
	 */
	@SuppressWarnings("unchecked")
	public IRequestParameterReadWrite judgeOptPack(SessionHandle handle, IRequestParameterReadWrite param, String fixedText) throws Throwable
	{
		HashMap inMap = (HashMap)param.getData(fixedText);
		if (null == inMap)
		{
			return param;
		}
		
		// オプションパック適用判定部品
		
		// パラメータ設定処理
		HashMap<String, Object> optPackAplyChkMap = new HashMap<String, Object>();
		
		param.setData(SERVICE_MESSAGE, optPackAplyChkMap);
		
		// 基準年月日
		optPackAplyChkMap.put("base_date", inMap.get("base_date"));
		
		// 判定用料金コースコードリスト
		ArrayList<HashMap<String, Object>> judgePcrsCdList = new ArrayList<HashMap<String, Object>>();
		
		ArrayList<HashMap<String, Object>> orgJdgPcrsCdList = (ArrayList<HashMap<String, Object>>)inMap.get("judge_pcrs_cd_list");
		if (null != orgJdgPcrsCdList)
		{
			for (HashMap<String, Object> orgJdgPcrsCdMap: orgJdgPcrsCdList)
			{
				HashMap<String, Object> childMap = new HashMap<String, Object>();
				
				// 料金コースコード
				childMap.put("pcrs_cd", orgJdgPcrsCdMap.get("pcrs_cd"));
				// 料金プランコード
				childMap.put("pplan_cd", orgJdgPcrsCdMap.get("pplan_cd"));
				
				judgePcrsCdList.add(childMap);
			}
		}
		
		optPackAplyChkMap.put("judge_pcrs_cd_list", judgePcrsCdList);
		
		// オプションパック適用判定の呼び出し
		JFUOptPackAplyChkCC obj = new JFUOptPackAplyChkCC();
		
		JSYbpmLog.println(JSYLogBase.EXECUTION, this.getClass(), null, "BPCON0I002",
				new String[]{"[KK2]judgeOptPack->JFUOptPackAplyChkCC#judgeOptPack:START"}, "");
		
		obj.judgeOptPack(handle, param, SERVICE_MESSAGE);
		
		JSYbpmLog.println(JSYLogBase.EXECUTION, this.getClass(), null, "BPCON0I002",
				new String[]{"[KK2]judgeOptPack->JFUOptPackAplyChkCC#judgeOptPack:END"}, "");
		
		// オプションパック適用判定部品でインスタンスが入れ替えられていることを考慮してインスタンスを再取得
		HashMap retOptPackAplyChkMap = (HashMap)param.getData(SERVICE_MESSAGE);
		
		// 結果判定処理
		String returnCd = (String)retOptPackAplyChkMap.get("return_cd");
		if (!RETURN_CD_NORMAL.equals(returnCd))
		{
			// 戻りコードが正常終了以外の場合はCCExcelptionをスロー
			throw new Exception("オプションパック適用判定部品の戻りコードに「" + returnCd + "」が指定されたため、異常終了しました。"
					+ "【呼出時のパラメータ】：" + optPackAplyChkMap.toString()
					+ "【戻り時のパラメータ】：" + retOptPackAplyChkMap.toString());
		}
		
		inMap.put("return_cd", returnCd);
		inMap.put("wrib_svc_cd", retOptPackAplyChkMap.get("wrib_svc_cd"));
		
		return param;
	}
}