/*********************************************************************
*	All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名		：eo顧客基幹システム
*	モジュール名	：FUSV0057_FUSV0057OPDBMapper
*	ソースファイル名：FUSV0057_FUSV0057OPDBMapper.java
*	作成者			：富士通
*	日付			：2011年07月08日
*＜機能概要＞
*	BP（メールウイルスチェックサービス申込(初期表示)）へのＤ−Ｂマッピングクラスです。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2011/07/08	FJ）西川	新規作成
*
**********************************************************************/
package eo.web.webview.mapping;

import java.util.ArrayList;
import java.util.HashMap;

import com.fujitsu.futurity.web.x00.JCCBusinessException;
import com.fujitsu.futurity.web.x31.X31CWebConst;
import com.fujitsu.futurity.web.x31.X31SDataBeanAccess;

import eo.common.constant.JFUStrConst;
import eo.web.webview.CommonInfoCF.CommonInfoCFConst;
import eo.web.webview.FUW02201SF.FUW02201SFConst;
import eo.web.webview.common.JFUWebCommon;

/**
 * DataBean-BPマッピングを行います。
 *
 * <br>
 * @author 富士通
 */
public class FUSV0057_FUSV0057OPDBMapper
{

	/** 機能コード */
	private static final String FUNC_CODE = "func_code";

	/** 業務パラメータ管理一意照会SC */
	private static final String SC_TITLE_FUSV005701 = "FUSV005701SC";
	/** 業務パラメータ管理一意照会SC */
	private static final String SC_TITLE_FUSV005702 = "FUSV005702SC";
	/** 料金プラン固定単価（オプション申込料金）一覧照会SC */
	private static final String SC_TITLE_FUSV005703 = "FUSV005703SC";
	/** 料金コース_サブオプションサービス一意照会SC */
	private static final String SC_TITLE_FUSV005704 = "FUSV005704SC";

	/** 初期費用一覧照会CC */
	private static final String CC_TITLE_FUSV005701 = "FUSV005701CC";

	/** 業務パラメータ管理一意照会SC.業務パラメータ管理一意照会明細 */
	private static final String EZM0321A010_LIST = "EZM0321A010CBSMsg1List";
	/** 料金プラン固定単価（オプション申込料金）一覧明細 */
	private static final String EKK0601B001_LIST = "EKK0601B001CBSMsg1List";
	/** 料金コース_サブオプションサービス一意照会明細 */
	private static final String EKK1881A010_LIST = "EKK1881A010CBSMsg1List";

	/** 料金コースコード */
	private static final String KEY_PCRS_CD = "key_pcrs_cd";
	/** サービス提供物無料値 */
	private static final String SVCTK_BUT_MRYO_VALUE = "svctk_but_mryo_value";
	/** サービス提供物最大値 */
	private static final String SVCTK_BUT_MAX_VALUE = "svctk_but_max_value";
	/** 業務パラメータ設定値 */
	private static final String WORK_PARAM_SETTE_VALUE = "work_param_sette_value";
	/** 基本料金 金額 */
	private static final String PPLAN_KOTEI_AMNT = "pplan_kotei_amnt";
	/** 初期費用一覧照会明細 */
	private static final String EKK0721A010_LIST = "EKK0721A010CBSMsg1List";

	/**
	 * コンストラクタ
	 */
	public FUSV0057_FUSV0057OPDBMapper()
	{
	}

	/**
	 * 上りマッピングを行います。
	 *
	 * <br>
	 * @param bean [0]:メールウイルスチェックサービス申込
	 * @param outputMap 送信情報
	 * @param func_code 機能コード
	 * @return 設定情報
	 */
	public HashMap<String, Object> setFUSV005701SC(X31SDataBeanAccess[] bean, HashMap<String, Object> outputMap, String func_code)
	{

		HashMap<String, Object> parentMap = new HashMap<String, Object>();

		// 共通情報のマッピング
		parentMap.put(FUNC_CODE, func_code);

		outputMap.put(SC_TITLE_FUSV005701, parentMap);

		return outputMap;
	}

	/**
	 * 上りマッピングを行います。
	 *
	 * <br>
	 * @param bean [0]:メールウイルスチェックサービス申込
	 * @param outputMap 送信情報
	 * @param func_code 機能コード
	 * @return 設定情報
	 */
	public HashMap<String, Object> setFUSV005702SC(X31SDataBeanAccess[] bean, HashMap<String, Object> outputMap, String func_code)
	{

		HashMap<String, Object> parentMap = new HashMap<String, Object>();

		// 共通情報のマッピング
		parentMap.put(FUNC_CODE, func_code);

		outputMap.put(SC_TITLE_FUSV005702, parentMap);

		return outputMap;
	}

	/**
	 * 上りマッピングを行います。
	 * <br>
	 * @param bean [0]:メールウイルスチェックサービス申込
	 * @param outputMap 送信情報
	 * @param func_code 機能コード
	 * @return
	 */
	public HashMap<String, Object> setFUSV005703SC(X31SDataBeanAccess[] bean, HashMap<String, Object> outputMap, String func_code)
	{
		HashMap<String, Object> parentMap = new HashMap<String, Object>();
		// 共通情報のマッピング
		parentMap.put(FUNC_CODE, func_code);
		outputMap.put(SC_TITLE_FUSV005703, parentMap);
		return outputMap;
	}

	/**
	 * 上りマッピングを行います。
	 * <br>
	 * @param bean [0]:メールウイルスチェックサービス申込
	 * @param outputMap 送信情報
	 * @param func_code 機能コード
	 * @return
	 */
	public HashMap<String, Object> setFUSV005704SC(X31SDataBeanAccess[] bean, HashMap<String, Object> outputMap, String func_code)
	{
		HashMap<String, Object> parentMap = new HashMap<String, Object>();
		// 共通情報のマッピング
		parentMap.put(FUNC_CODE, func_code);
		// 共有フォームBean.サービス契約情報 料金コースコード → 料金コースコード
		parentMap.put(KEY_PCRS_CD, bean[1].sendMessageString(CommonInfoCFConst.PCRS_CD_23, X31CWebConst.DATABEAN_GET_VALUE));

		outputMap.put(SC_TITLE_FUSV005704, parentMap);
		return outputMap;
	}

	/**
	 * 上りマッピングを行います。
	 * <br>
	 * @param bean [0]:メールウイルスチェックサービス申込
	 * @param outputMap 送信情報
	 * @param func_code 機能コード
	 * @return
	 */
	public HashMap<String, Object> setFUSV005701CC(X31SDataBeanAccess[] bean, HashMap<String, Object> outputMap, String func_code)
	{
		HashMap<String, Object> parentMap = new HashMap<String, Object>();
		// 共通情報のマッピング
		outputMap.put(CC_TITLE_FUSV005701, parentMap);
		return outputMap;
	}

	/**
	 * 下りマッピングを行います。
	 * <br>
	 * @param bean メールウイルスチェックサービス申込
	 * @param outputMap 受信情報
	 * @return データBean
	 */
	public X31SDataBeanAccess getFUSV005701SC(X31SDataBeanAccess bean, HashMap<String, Object> outputMap)
	{

		HashMap<String, Object> parentMap = null;
		if (outputMap.containsKey(SC_TITLE_FUSV005701))
		{
			parentMap = (HashMap<String, Object>)outputMap.get(SC_TITLE_FUSV005701);
		}

		String popServer = null;
		if (null != parentMap && parentMap.containsKey(EZM0321A010_LIST))
		{
			ArrayList<HashMap<String, Object>> childList = (ArrayList<HashMap<String, Object>>)parentMap.get(EZM0321A010_LIST);

			for (int i = 0; i < childList.size(); i++)
			{
				HashMap<String, Object> childMap = childList.get(i);

				if (!childMap.containsKey(WORK_PARAM_SETTE_VALUE))
				{
					continue;
				}
				popServer = (String)childMap.get(WORK_PARAM_SETTE_VALUE);
				// メールウイルスチェックサービス申込.ＰＯＰサーバー ←
				// 業務パラメータ管理一意照会SC.業務パラメータ管理一意照会明細.業務パラメータ設定値
				bean.sendMessageString(FUW02201SFConst.POP_SERVER, X31CWebConst.DATABEAN_SET_VALUE, popServer);
				break;
			}
		}
		if (JFUWebCommon.isNull(popServer))
		{
			// マスタ設定不備の場合

			// システムエラー
			throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002);
		}
		return bean;
	}

	/**
	 * 下りマッピングを行います。
	 * <br>
	 * @param bean メールウイルスチェックサービス申込
	 * @param outputMap 受信情報
	 * @return データBean
	 */
	public X31SDataBeanAccess getFUSV005702SC(X31SDataBeanAccess bean, HashMap<String, Object> outputMap)
	{

		HashMap<String, Object> parentMap = null;
		if (outputMap.containsKey(SC_TITLE_FUSV005702))
		{
			parentMap = (HashMap<String, Object>)outputMap.get(SC_TITLE_FUSV005702);
		}

		String smtpServer = null;
		if (null != parentMap && parentMap.containsKey(EZM0321A010_LIST))
		{
			ArrayList<HashMap<String, Object>> childList = (ArrayList<HashMap<String, Object>>)parentMap.get(EZM0321A010_LIST);

			for (int i = 0; i < childList.size(); i++)
			{
				HashMap<String, Object> childMap = childList.get(i);

				if (!childMap.containsKey(WORK_PARAM_SETTE_VALUE))
				{
					continue;
				}
				smtpServer = (String)childMap.get(WORK_PARAM_SETTE_VALUE);
				// メールウイルスチェックサービス申込.SMTPサーバー ←
				// 業務パラメータ管理一意照会SC.業務パラメータ管理一意照会明細.業務パラメータ設定値
				bean.sendMessageString(FUW02201SFConst.SMTP_SERVER, X31CWebConst.DATABEAN_SET_VALUE, smtpServer);
				break;
			}
		}
		if (JFUWebCommon.isNull(smtpServer))
		{
			// マスタ設定不備の場合

			// システムエラー
			throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002);
		}
		return bean;
	}

	/**
	 * 下りマッピングを行います。
	 * <br>
	 * @param bean メールウイルスチェックサービス申込
	 * @param outputMap 受信情報
	 * @return true：無料の場合:、false：有料の場合
	 */
	public boolean getFUSV005703SC(X31SDataBeanAccess bean, HashMap<String, Object> outputMap)
	{
		int pplanKoteiAmnt = 0;

		HashMap<String, Object> parentMap = null;
		if (outputMap.containsKey(SC_TITLE_FUSV005703))
		{
			parentMap = (HashMap<String, Object>)outputMap.get(SC_TITLE_FUSV005703);
		}

		if (null != parentMap && parentMap.containsKey(EKK0601B001_LIST))
		{
			ArrayList<HashMap<String, Object>> childList = (ArrayList<HashMap<String, Object>>)parentMap.get(EKK0601B001_LIST);
			for (int i = 0; i < childList.size(); i++)
			{
				HashMap<String, Object> childMap = childList.get(i);
				// 基本料金 金額
				String pplanKoteiAmntStr = (String)childMap.get(PPLAN_KOTEI_AMNT);
				if (!JFUWebCommon.isNull(pplanKoteiAmntStr))
				{
					pplanKoteiAmnt = Integer.parseInt(pplanKoteiAmntStr);
					break;
				}
			}
		}
		return 0 >= pplanKoteiAmnt;
	}

	/**
	 * 下りマッピングを行います。
	 * <br>
	 * @param bean メールウイルスチェックサービス申込
	 * @param outputMap 受信情報
	 * @param count メールウイルスチェックサービス契約数
	 * @return true：無料残数がある場合:、false：無料残数が0の場合
	 */
	public boolean getFUSV005704SC(X31SDataBeanAccess bean, HashMap<String, Object> outputMap, int count)
	{
		int countSvctkButMaxValue = 0;
		int countSvctkButMryo = 0;
		HashMap<String, Object> parentMap = null;

		if (outputMap.containsKey(SC_TITLE_FUSV005704))
		{
			parentMap = (HashMap<String, Object>)outputMap.get(SC_TITLE_FUSV005704);
		}
		if (null != parentMap && parentMap.containsKey(EKK1881A010_LIST))
		{
			ArrayList<HashMap<String, Object>> childList = (ArrayList<HashMap<String, Object>>)parentMap.get(EKK1881A010_LIST);
			for (int i = 0; i < childList.size(); i++)
			{
				HashMap<String, Object> childMap = childList.get(i);
				// 最大数
				String svctkButMaxValue = (String)childMap.get(SVCTK_BUT_MAX_VALUE);
				// 無料数
				String svctkButMryoValue = (String)childMap.get(SVCTK_BUT_MRYO_VALUE);
				if (!JFUWebCommon.isNull(svctkButMaxValue) && !JFUWebCommon.isNull(svctkButMryoValue))
				{
					countSvctkButMaxValue = Integer.parseInt(svctkButMaxValue);
					countSvctkButMryo = Integer.parseInt(svctkButMryoValue);
					break;
				}
			}
		}
		if (countSvctkButMaxValue <= count)
		{
			// 契約数が上限数以上の場合

			// 契約済エラー
			throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0103);
		}
		return count < countSvctkButMryo;
	}

	/**
	 * 下りマッピングを行います。
	 * <br>
	 * @param bean メールウイルスチェックサービス申込
	 * @param outputMap 受信情報
	 * @return true：初期費用なし false：初期費用あり
	 */
	public boolean getFUSV005701CC(X31SDataBeanAccess bean, HashMap<String, Object> outputMap)
	{
		HashMap<String, Object> parentMap = null;
		if (outputMap.containsKey(CC_TITLE_FUSV005701))
		{
			parentMap = (HashMap<String, Object>)outputMap.get(CC_TITLE_FUSV005701);
		}

		if (null != parentMap && parentMap.containsKey(EKK0721A010_LIST))
		{
			ArrayList<HashMap<String, Object>> childList = (ArrayList<HashMap<String, Object>>)parentMap.get(EKK0721A010_LIST);
			for (int i = 0; i < childList.size(); i++)
			{
				HashMap<String, Object> childMap = childList.get(i);
				return childMap == null;
			}
		}
		return true;
	}

}