/*********************************************************************
* All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：JFUKariMskmDelUtil
*   ソースファイル名：JFUKariMskmDelUtil.java
*   作成者          ：富士通
*   日付            ：2016年09月25日
*＜機能概要＞
*   仮申込破棄部品です。
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*   v26.00.00   2016/09/25   FJ) 張本    【ANK-2914-00-00】(客A)サービス追加申込時の仮申込機能削除
**********************************************************************/
package eo.web.webview.common;

import java.util.ArrayList;
import java.util.HashMap;

import com.fujitsu.futurity.web.x00.JCCBusinessException;
import com.fujitsu.futurity.web.x00.JCCWebServiceException;
import com.fujitsu.futurity.web.x31.X31BWebBusinessLogic;
import com.fujitsu.futurity.web.x31.X31CMessageResult;
import com.fujitsu.futurity.web.x31.X31CWebConst;
import com.fujitsu.futurity.web.x31.X31SWebLog;
import com.fujitsu.futurity.web.x31.X31CMessageResult.X31CMessageMoreInfo;

import eo.common.constant.JFUStrConst;
import eo.common.util.JFUKariMskmDelMappingUtil;

/**
 * 仮申込破棄部品
 * <br>
 * @author 富士通
 */
public class JFUKariMskmDelUtil
{

	/** 入力項目　申込番号 */
	private static final String IN_MSKM_NO = "mskm_no";

	/** サービスID */
	private static final String USECASE_ID_FUSV0300 = "FUSV0300";
	/** サービスID */
	private static final String USECASE_ID_KKSV0079 = "KKSV0079";
	/** サービスID */
	private static final String USECASE_ID_KKSV0568 = "KKSV0568";

	/** 仮申込情報照会共通コンポーネント上りマッピング */
	private static final String FUSV030001SC = "FUSV030001SC";

	/** 仮申込情報一覧 (SYSID)明細 */
	private static final String EKK0011B507_CBSMSG1_LIST = "EKK0011B507CBSMsg1List";

	/**
	 * 仮申込破棄処理
	 * <br>
	 * @param sysid SYSID
	 * @param bl VIEWロジックインスタンス
	 */
	@SuppressWarnings("unchecked")
	public static void executeKariMskmDel(String sysid, X31BWebBusinessLogic bl)
	{

		// 検索結果格納用マップを生成。
		HashMap<String, HashMap<String, Object>> fusv0300OutMap = new HashMap<String, HashMap<String, Object>>();

		// ●ユースケースIDを設定
		HashMap<String, String> paramMap = new HashMap<String, String>(16);
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, USECASE_ID_FUSV0300);

		// ●上りマッピング
		HashMap<String, HashMap<String, String>> dataMap = JFUKariMskmDelMappingUtil.setFUSV0300(sysid);

		try
		{
			bl.invokeService(paramMap, dataMap, fusv0300OutMap);
		}
		catch (JCCWebServiceException jwse)
		{
			// 例外情報を取得
			X31CMessageResult msgResult = jwse.getMessageList();
			X31CMessageMoreInfo[] moreInfo = msgResult.getMessageMoreInfoList();
			X31CMessageMoreInfo info = moreInfo[0];// 関連チェック系は必ずエラーが1つのため0番目から取得する。
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKariMskmDel):その他：エラー詳細(サービスIF)：" + info.getTemplateId());
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKariMskmDel):その他：エラー詳細(ステータス)：" + info.getStatus());
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKariMskmDel):その他：エラー詳細(エラー項目名)：" + info.getItemId());
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKariMskmDel):その他：エラー詳細(エラーフラグ)：" + info.getItemCheckErr());

			// システムエラー
			throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002);
		}

		// 申込番号
		HashMap<String, Object> fusv030001Map = (HashMap<String, Object>)fusv0300OutMap.get(FUSV030001SC);
		if (fusv030001Map != null)
		{
			if (fusv030001Map.get(EKK0011B507_CBSMSG1_LIST) != null)
			{
				ArrayList<HashMap<String, Object>> mskmList = (ArrayList<HashMap<String, Object>>)fusv030001Map.get("EKK0011B507CBSMsg1List");

				for (HashMap<String, Object> mskmMap : mskmList)
				{
					String mskmNo = (String)mskmMap.get(IN_MSKM_NO);
					if (null == mskmNo)
					{
						continue;
					}
					// 申込件数分の申込情報を照会
					executeKKSV0079(sysid, mskmNo, bl);
				}
			}
		}
	}

	/**
	 * 申込情報取得処理
	 * <br>
	 * @param sysid SYSID
	 * @param mskmNo 申込番号
	 * @param bl VIEWロジックインスタンス
	 */
	private static void executeKKSV0079(String sysid, String mskmNo, X31BWebBusinessLogic bl)
	{

		// 検索結果格納用マップを生成。
		HashMap<String, HashMap<String, Object>> kksv0079OutMap = new HashMap<String, HashMap<String, Object>>();

		// ●ユースケースIDを設定
		HashMap<String, String> paramMap = new HashMap<String, String>(16);
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, USECASE_ID_KKSV0079);

		// ●上りマッピング
		HashMap<String, HashMap<String, String>> dataMap = JFUKariMskmDelMappingUtil.setKKSV0079(mskmNo, JCCWebCommon.getOpeDate(bl, null));
		try
		{
			bl.invokeService(paramMap, dataMap, kksv0079OutMap);
		}
		catch (JCCWebServiceException jwse)
		{
			// 例外情報を取得
			X31CMessageResult msgResult = jwse.getMessageList();
			X31CMessageMoreInfo[] moreInfo = msgResult.getMessageMoreInfoList();
			X31CMessageMoreInfo info = moreInfo[0];// 関連チェック系は必ずエラーが1つのため0番目から取得する。
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKKSV0079):その他：エラー詳細(サービスIF)：" + info.getTemplateId());
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKKSV0079):その他：エラー詳細(ステータス)：" + info.getStatus());
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKKSV0079):その他：エラー詳細(エラー項目名)：" + info.getItemId());
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKKSV0079):その他：エラー詳細(エラーフラグ)：" + info.getItemCheckErr());

			// システムエラー
			throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002);
		}

		// 申込情報を破棄
		executeKKSV0568(sysid, mskmNo, bl, kksv0079OutMap);
	}

	/**
	 * 申込情報破棄処理
	 * <br>
	 * @param sysid SYSID
	 * @param mskmNo 申込番号
	 * @param bl VIEWロジックインスタンス
	 * @param kksv0079OutMap 申込情報取得結果マップ
	 */
	private static void executeKKSV0568(String sysid, String mskmNo, X31BWebBusinessLogic bl, HashMap<String, HashMap<String, Object>> kksv0079OutMap)
	{

		// 検索結果格納用マップを生成。
		HashMap<Object, Object> kksv0568OutMap = new HashMap<Object, Object>();

		// ●ユースケースIDを設定
		HashMap<String, String> paramMap = new HashMap<String, String>(16);
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, USECASE_ID_KKSV0568);

		// ●上りマッピング
		HashMap<String, HashMap<String, String>> dataMap =
				JFUKariMskmDelMappingUtil.setKKSV0568(sysid, JCCWebCommon.getOpeDate(bl, null), kksv0079OutMap);

		try
		{
			bl.invokeService(paramMap, dataMap, kksv0568OutMap);

		}
		catch (JCCWebServiceException jwse)
		{
			// 例外情報を取得
			X31CMessageResult msgResult = jwse.getMessageList();
			X31CMessageMoreInfo[] moreInfo = msgResult.getMessageMoreInfoList();
			X31CMessageMoreInfo info = moreInfo[0];// 関連チェック系は必ずエラーが1つのため0番目から取得する。
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKKSV0568):その他：エラー詳細(サービスIF)：" + info.getTemplateId());
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKKSV0568):その他：エラー詳細(ステータス)：" + info.getStatus());
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKKSV0568):その他：エラー詳細(エラー項目名)：" + info.getItemId());
			X31SWebLog.DEBUG_LOG.info("JFUKariMskmDelUtil(executeKKSV0568):その他：エラー詳細(エラーフラグ)：" + info.getItemCheckErr());

			// システムエラー
			throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002);
		}
	}

}
