/*********************************************************************
* All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：JFUFUSV0316ReqChk
*   ソースファイル名：JFUFUSV0316ReqChk.java
*   作成者          ：富士通
*   日付            ：2018年05月18日
*＜機能概要＞
*   実行判定部品です。
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*   v37.00      2018/05/18   FJ）岡井    【ANK-3119-00-00】開通前でもＷｅｂから支払方法を変更可能とする
*
**********************************************************************/
package com.fujitsu.futurity.bp.custom.reqchk;

import java.util.ArrayList;
import java.util.HashMap;

import com.fujitsu.futurity.bp.custom.common.JFUBPCommon;
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.JFUStrConst;

/**
 * FUSV0316の実行条件判定クラス
 * 
 * <br>
 * @author 富士通
 */
public class JFUFUSV0316ReqChk extends AbstractCustomReqChk
{

	/**
	 * サービスIFの実行判定を実施する。
	 * <br>
	 * @param irp
	 * @param conditionvalue
	 * @return 判定結果(条件を満たすtrue/満たさないfalse)
	 * @throws ReqChkException
	 */
	@SuppressWarnings("unchecked")
	public boolean checkExecution(IRequestParameterReadOnly irp, IConditionValue conditionvalue) throws ReqChkException
	{
		// 各処理が成功の場合に、trueを返す。
		try
		{
			// BP定義ツールでセットしている値の取得
			String key = conditionvalue.get(null);

			if ("1".equals(key))
			{
				// コードが"1"の場合：同一請求先照会が0件の時は、実行しない。

				// 同一請求先照会マップを取得
				HashMap<String, Object> parentMap = (HashMap<String, Object>)irp.getData("FUSV031601SC");

				if (parentMap == null)
				{
					return false;
				}

				// 同一請求先照会明細を取得
				if (parentMap.containsKey("EKK0321B501CBSMsg1List"))
				{
					ArrayList msgList = (ArrayList)parentMap.get("EKK0321B501CBSMsg1List");

					// 検索結果レコードが1件以上ある場合
					if (msgList.size() > 0)
					{
						return true;
					}

					return false;
				}
			}
			else if ("2".equals(key))
			{
				// コードが"2"の場合：請求方法が"2"「預金口座振替」または、"3"「郵便自動振込」の場合のみ実行

				// 開通前支払方法変更関連チェックCCマップを取得
				HashMap<String, Object> parentMap = (HashMap<String, Object>)irp.getData("FUSV031602CC");

				// 請求方法コード取得
				String seikyWayCd = JFUStrConst.EMPTY;

				if (parentMap != null && !JFUBPCommon.isNull((String)parentMap.get("out_seiky_way_cd")))
				{
					seikyWayCd = (String)parentMap.get("out_seiky_way_cd");
				}

				if (JFUStrConst.CD00166_2.equals(seikyWayCd) || JFUStrConst.CD00166_3.equals(seikyWayCd))
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else if ("3".equals(key))
			{
				// コードが"3"の場合：請求方法が"4"「クレジットカード」の場合のみ実行

				// 開通前支払方法変更関連チェックCCマップを取得
				HashMap<String, Object> parentMap = (HashMap<String, Object>)irp.getData("FUSV031602CC");

				// 請求方法コード取得
				String seikyWayCd = JFUStrConst.EMPTY;

				if (parentMap != null && !JFUBPCommon.isNull((String)parentMap.get("out_seiky_way_cd")))
				{
					seikyWayCd = (String)parentMap.get("out_seiky_way_cd");
				}

				if (JFUStrConst.CD00166_4.equals(seikyWayCd))
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else if ("4".equals(key))
			{
				// コードが"4"の場合：マンション物件一意照会用のマップが設定されている場合実行

				// 開通前支払方法変更関連チェックCCマップを取得
				HashMap<String, Object> parentMap = (HashMap<String, Object>)irp.getData("FUSV031601CC");

				// マンション物件コード取得
				String mansBukkenCd = JFUStrConst.EMPTY;

				if (parentMap != null && !JFUBPCommon.isNull((String)parentMap.get("out_mansion_bukken_no")))
				{
					mansBukkenCd = (String)parentMap.get("out_mansion_bukken_no");
				}

				// マンション物件コードが未設定の場合は実行しない
				if (JFUBPCommon.isNull(mansBukkenCd))
				{
					return false;
				}
				else
				{
					return true;
				}
			}
			else if ("5".equals(key))
			{
				// 金融機関一意照会SCマップを取得
				HashMap<String, Object> parentMap = (HashMap)irp.getData("FUSV031610SC");

				if (parentMap != null)
				{
					// 金融機関コードが設定されている場合に実行する
					if (!JFUBPCommon.isNull(parentMap.get("key_bank_cd")))
					{
						return true;
					}
					else
					{
						return false;
					}
				}
			}
			else if ("6".equals(key))
			{
				// 開通前支払方法変更関連チェックCCマップを取得
				HashMap<String, Object> parentMap = (HashMap<String, Object>)irp.getData("FUSV031602CC");

				// 請求契約番号
				String seikyKeiNo = JFUStrConst.EMPTY;

				if (parentMap != null && !JFUBPCommon.isNull((String)parentMap.get("out_seiky_kei_no")))
				{
					seikyKeiNo = (String)parentMap.get("out_seiky_kei_no");
				}

				if (!JFUBPCommon.isNull(seikyKeiNo))
				{
					return true;
				}
				else
				{
					return false;
				}
			}

			return false;

		}
		catch (RequestParameterException e)
		{
			throw new ReqChkException(e.getMessage(), e);
		}
	}
}
