/*********************************************************************
* All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：JCHCHSV005402ReqChk
*   ソースファイル名：JCHCHSV005402ReqChk.java
*   作成者          ：富士通
*   日付            ：2012年08月08日
*＜機能概要＞
*   追加料金項目パターン一覧照会SC実行判定部品です。
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*	v1.00.00	2012/08/08	富士通		新規作成
*
**********************************************************************/
package com.fujitsu.futurity.bp.custom.reqchk;

import java.util.ArrayList;
import java.util.HashMap;

import com.fujitsu.futurity.bp.x21.bpm.common.AbstractCustomReqChk;
import com.fujitsu.futurity.bp.x21.bpm.common.IConditionValue;
import com.fujitsu.futurity.bp.x21.bpm.exception.RequestParameterException;
import com.fujitsu.futurity.bp.x21.bpm.parameter.IRequestParameterReadOnly;
import com.fujitsu.futurity.bp.x21.bpm.reqchk.exception.ReqChkException;

import eo.common.constant.JACStrConst;
import eo.common.util.JPCUtilCommon;

/**
 * 内訳パターン情報取得サービスの追加料金項目パターン取得CCの実行条件を判定する独自部品。<p>
 * <BR>
 * @author 富士通
 */
public class JCHGetAddPrcKmkPtnReqChk extends AbstractCustomReqChk {

	@Override
	/**
	 * 実行条件を判定します。
	 * <br>
	 * @param irp リクエストパラメータ操作クラス
	 * @param conditionvalue 判定値格納クラス
	 * @return 判定結果
	 * @throws ReqChkException 
	 */
	public boolean checkExecution(IRequestParameterReadOnly irp, IConditionValue conditionvalue) throws ReqChkException {

		boolean isExec = false;

		HashMap<String, Object> dataMap1 = null;
		HashMap<String, Object> dataMap2 = null;
		HashMap<String, Object> dataMap3 = null;

		try
		{
			// サービス契約一意照会マップ取得
			dataMap1 = (HashMap)irp.getData("CHSV005401SC");

			// サービス契約内訳一覧照会マップ取得
			dataMap2 = (HashMap)irp.getData("CHSV005402SC");
			
			// 追加料金項目パターンマップ取得
			dataMap3 = (HashMap)irp.getData("GETADDPRCKMKPTNCC");

			ArrayList<HashMap<String, Object>> mapList = new ArrayList<HashMap<String, Object>>();

			// ＫＥＹ＿サービス契約番号
			if(dataMap1.get("key_svc_kei_no") != null && !JACStrConst.KARA_MOJI.equals(dataMap1.get("key_svc_kei_no")))
			{
				// サービス契約一意照会が取得できる場合
				ArrayList<HashMap<String, Object>> inList = (ArrayList<HashMap<String, Object>>)dataMap1.get("EKK0081A010CBSMsg1List");
				if(inList != null && inList.size() != 0)
				{
					// 料金プランコードリスト定義
					ArrayList<String> pplanCdList = new ArrayList<String>();
					
					// 料金プランコード追加
					pplanCdList.add((String)inList.get(0).get("pplan_cd"));
					
					// サービス契約内訳一覧照会が取得できる場合
					ArrayList<HashMap<String, Object>> inList2 = (ArrayList<HashMap<String, Object>>)dataMap2.get("EKK0161B004CBSMsg1List");
					if (inList2 != null)
					{
						for (int i = 0; i < inList2.size(); i++)
						{
							// 料金プランコード取得
							String pplanCd = (String)inList2.get(i).get("pplan_cd");
							
							// 料金プランコードリストに存在しない場合
							if (pplanCdList.indexOf(pplanCd) < 0)
							{
								// 料金プランコード追加
								pplanCdList.add(pplanCd);
							}
						}
					}
					
					// 追加料金項目パターンリスト生成
					for (int j = 0; j < pplanCdList.size(); j++)
					{
						HashMap<String, Object> map = new HashMap<String, Object>();
						
						// ＫＥＹ＿追加料金グループコード設定
						map.put("key_add_prc_grp_cd", inList.get(0).get("prc_grp_cd"));
						// ＫＥＹ＿追加料金コースコード設定
						map.put("key_add_pcrs_cd", inList.get(0).get("pcrs_cd"));
						// ＫＥＹ＿追加料金サービスコード設定
						map.put("key_add_prc_svc_cd", JPCUtilCommon.fillHalfSpace(pplanCdList.get(j), 12, true));

						mapList.add(map);
					}
					
					// 追加料金項目パターンリスト登録
					dataMap3.put("ADD_PRC_KMK_PTN_LIST", mapList);

					isExec = true;
				}
			}
			else
			{
				HashMap<String, Object> map = new HashMap<String, Object>();

				// ＫＥＹ＿追加料金グループコード設定
				map.put("key_add_prc_grp_cd", JACStrConst.PRC_GRP_CD_SP);
				// ＫＥＹ＿追加料金コースコード設定
				map.put("key_add_pcrs_cd", JACStrConst.PRC_GRP_CD_SP);
				// ＫＥＹ＿追加料金サービスコード設定
				map.put("key_add_prc_svc_cd", JACStrConst.PRC_GRP_CD_SP);

				mapList.add(map);

				// 追加料金項目パターンリスト登録
				dataMap3.put("ADD_PRC_KMK_PTN_LIST", mapList);

				isExec = true;
			}
		}
		catch (RequestParameterException ex)
		{
			isExec = false;
		}

		return isExec;
	}
}
