/*********************************************************************
* All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：JFUdecryptUtil
*   ソースファイル名：JFUdecryptUtil.java
*   作成者          ：富士通
*   日付            ：2014年08月07日
*＜機能概要＞
*   AES複号化部品です。
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*   v10.00       2014/08/07   FJ）西山    新規作成 【ANK-0235-00-00】eoモバイルWiMAX受付対応(W10055)
*   v24.00.00    2016/04/01   FJ) 中西   【ANK-2841-00-00】 訪販フロント改善(キャンペーン名称変更等)
*
**********************************************************************/
package eo.web.webview.common;


import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import eo.common.constant.JFUStrConst;
import eo.common.util.JFUCommonUtil;

/**
 * 部品です。
 * <br>
 * @author 富士通
 */
public class JFUDispDefinitionUtil
{


	/** 属性名 */
	private static final String QUERY_ATTR_NAME = "id";
	
	/** 定義取得パス  */
	private static final String QUERY_PATH_DISP_ITEM = "DISPSETTING/COMMONSETTING/DISPTEXT[@groupid='%1%']";

	/** 置き換え文字列1 */
	private static final String RE_1 = "%1%";
	
	// ANK-2841-00-00 訪販フロント改善(キャンペーン名称変更等) 2016.04.01 add start
	/** プロパティからの取得キー：その他キャンペーンコードリスト */
	private static final String KEY_OTHER_CMP_CD_LIST = "OTHER_CMP_CD_LIST";
	/** プロパティからの取得キー：その他キャンペーンコード */
	private static final String KEY_OTHER_CMP_CD = "OTHER_CMP_CD";
	/** プロパティからの取得キー：その他キャンペーン名（表示用） */
	private static final String KEY_OTHER_CMP_NM_DISP = "OTHER_CMP_NM_DISP";
	/** 定義取得キー：グループIDプレフィックス（その他キャンペーンの割引コード） */
	private static final String KEY_GROUP_ID_PREFIX_OTHER_CMP = "OTHER_CMP_";
	// ANK-2841-00-00 訪販フロント改善(キャンペーン名称変更等) 2016.04.01 add end

	/**
	 */
	public static Map<String, String> getDispTextSmlCampMap(String kbn) throws Exception
	{

		String tabletInfoPath = QUERY_PATH_DISP_ITEM.replace(RE_1, JFUStrConst.SML_CAMP_PREFIX + kbn);
		return  JFUWebCommon.getDispItemsAsMap(tabletInfoPath, QUERY_ATTR_NAME);
	}

	
	public static String getDispTextSmlCamp(String kbn, String id) throws Exception
	{

		String tabletInfoPath = QUERY_PATH_DISP_ITEM.replace(RE_1, JFUStrConst.SML_CAMP_PREFIX + kbn);
		Map<String, String> tabletInfo = JFUWebCommon.getDispItemsAsMap(tabletInfoPath, QUERY_ATTR_NAME);
		return tabletInfo.get(id);
	}
	
	// ANK-2841-00-00 訪販フロント改善(キャンペーン名称変更等) 2016.04.01 add start
	/**
	 * 
	 * その他キャンペーンの表示用情報マップを取得
	 * (key：その他キャンペーンコード、value：その他キャンペーンの表示用情報マップ)
	 * <br>
	 * @return その他キャンペーンの表示用情報マップ
	 */
	public static Map<String, Map<String, String>> getDispTesxtOtherCmpMap()
	{
		// 返却用マップ
		Map<String, Map<String, String>> otherCmpMap = new LinkedHashMap<String, Map<String, String>>();

		try
		{
			// その他キャンペーンコードのリストを取得
			String otherCmpCdListText = JFUStrConst.EMPTY;
			otherCmpCdListText = JFUWebCommon.getDispText(JFUScreenConst.SCREEN_ID_FUW00905, KEY_OTHER_CMP_CD_LIST);

			// キャンセル対象の割引サービスコードをリストに格納
			List<String> otherCmpCdList = new ArrayList<String>();
			if ((otherCmpCdListText).contains(JFUStrConst.COMMA))
			{
				// カンマ区切りである場合、配列からリストに格納する
				String[] cancelList = (otherCmpCdListText).split(JFUStrConst.COMMA);
				for (int i = 0; i < cancelList.length; i++)
				{
					String val = cancelList[i];
					if (!JFUCommonUtil.isNull(val))
					{
						otherCmpCdList.add(val);
					}
				}
			}
			else
			{
				// カンマ区切りでない場合、直でリストに格納する
				otherCmpCdList.add(otherCmpCdListText);
			}

			// 取得したその他キャンペーンコードの件数分処理
			for (String tmpOtherCmpCd : otherCmpCdList)
			{
				// 取得キーを生成
				String tmpOtherCmpInfoKey = KEY_GROUP_ID_PREFIX_OTHER_CMP + tmpOtherCmpCd;
				String key = QUERY_PATH_DISP_ITEM.replace(RE_1, tmpOtherCmpInfoKey);
				Map<String, String> tmpOtherCmpInfoMap = null;

				tmpOtherCmpInfoMap = JFUWebCommon.getDispItemsAsMap(key, QUERY_ATTR_NAME);

				// プロパティ情報が取得できたかどうか確認
				if (null == tmpOtherCmpInfoMap || tmpOtherCmpInfoMap.isEmpty())
				{
					// 取得できなければ、スキップ
					continue;
				}

				otherCmpMap.put(tmpOtherCmpCd, tmpOtherCmpInfoMap);

			}

		}
		catch (Exception e)
		{
			// プロパティからの取得中に例外発生した場合は、空のマップを作成する。
			otherCmpMap = new LinkedHashMap<String, Map<String, String>>();
		}

		return otherCmpMap;
	}

	/**
	 * その他キャンペーンの表示用名称マップを取得
	 * (key：その他キャンペーンコード、value：その他キャンペーンの表示用名称)
	 * <br>
	 * @return その他キャンペーンの表示用名称マップ
	 */
	public static Map<String, String> getDispTesxtOtherCmpNameMap()
	{
		// その他キャンペーンの定義マップを取得
		Map<String, Map<String, String>> otherCmpMap = getDispTesxtOtherCmpMap();

		// その他キャンペーンの表示用名称マップを取得
		Map<String, String> otherCmpNmDispMap = new LinkedHashMap<String, String>();

		// 取得したその他キャンペーンコードの件数分処理
		for (Map<String, String> otherCmp : otherCmpMap.values())
		{
			// その他キャンペーンコード
			String otherCmpCd = otherCmp.get(KEY_OTHER_CMP_CD);
			// その他キャンペーン名（表示用）
			String otherCmpNmDisp = otherCmp.get(KEY_OTHER_CMP_NM_DISP);

			if (!JFUCommonUtil.isNull(otherCmpCd) && !JFUCommonUtil.isNull(otherCmpNmDisp))
			{
				// その他キャンペーンコード、その他キャンペーン名（表示用）が共に取得できた場合
				otherCmpNmDispMap.put(otherCmpCd, otherCmpNmDisp);
			}

		}

		return otherCmpNmDispMap;
	}
	// ANK-2841-00-00 訪販フロント改善(キャンペーン名称変更等) 2016.04.01 add end

}
