/*********************************************************************
* All Rights reserved, Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム共通（共通マスタ）
*   モジュール名    ：ZMW03701SFLogic
*   ソースファイル名：ZMW03701SFLogic.java
*   作成者          ：富士通
*   日付            ：2012年04月12日
*＜機能概要＞
*   ロール情報照会のビューロジックです。
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*   v3.00.00    2012/04/12   FJ）岩元    新規作成
*	v3.00.00	2012/04/12   FJ) 岩元	【SGY-2012-000006】統合認証対応
*
**********************************************************************/

package eo.web.webview.ZMW03701SF;

import java.util.HashMap;

import com.fujitsu.futurity.web.x31.X31CWebConst;
import com.fujitsu.futurity.web.x31.X31SDataBeanAccess;

import eo.common.constant.JPCModelConstant;
import eo.common.constant.JPCOnlineMessageConstant;
import eo.web.webview.JCCWebBusinessLogic;
import eo.web.webview.common.JZMScreenConst;
import eo.web.webview.common.JZMWebCommon;
import eo.web.webview.common.JZMWebConst;
import eo.web.webview.mapping.ZMSV0100_ZMSV0100OPDBMapper_ZMSV010002CC;
import eo.web.webview.mapping.ZMSV0124_ZMSV0124OPDBMapper;

/**
 * ロール情報照会のビューロジックです。
 * @author 909281
 *
 */
@SuppressWarnings("serial")
public class ZMW03701SFLogic extends JCCWebBusinessLogic
{

	/** メッセージID EKB0330--I  */
	private static final String SEARCH_ERR_MESSAGE_ZERO_ROLE = JPCOnlineMessageConstant.EKB0300_KW;
	
	/** メッセージID EKB0330--I  */
	private static final String SEARCH_ERR_MESSAGE_ZERO = JPCOnlineMessageConstant.EKB0330__I;

	/** メッセージID EKB0340--I  */
	private static final String SEARCH_ERR_MESSAGE_OVERMAX =  JPCOnlineMessageConstant.EKB0340__I;

	/** メッセージID EKB0350--I  */
	private static final String SEARCH_ERR_MESSAGE_NODATA =  JPCOnlineMessageConstant.EKB0350__I;

	/** 最大検索数 */
	private static final String MAX_SHOW_CNT = "ZMW03701_MAX_SHOW_CNT";
	
	/** 最大表示数 */
	private static final String ROW_PER_PAGE = "ZMW03701_ROW_PER_PAGE";
	
	/** ロールコードが存在しない場合のエラーメッセージ */
	private static final String[] NO_ROLE_MSG_ITEM  = {"ロール", "情報"};
	
	/**
	 * ロール照会初期表示処理を行います。
	 * <br>
	 * @return 処理結果 
	 * @throws Exception 予期せぬエラー
	 */
	public boolean init()throws Exception
	{
		
		// 共通フォームBeanの内容を取得
		X31SDataBeanAccess commonBean = getCommonInfoBean();
		
		if(JZMWebCommon.getScreenInfo(this) == null)
		{
			
			setTransferPageId(commonBean, true);
			
			return true;
		}

		// ページリンク情報の消去
		JZMWebCommon.clearPageLinkInfo(this, this.getGamenId());
		
		// サービスフォームBeanの内容の取得
		X31SDataBeanAccess bean = getServiceFormBean();
				

		X31SDataBeanAccess[] paramBean = {bean};

		// ユースケースID格納用マップを生成。
		HashMap<String, Object> paramMap = new HashMap<String, Object>();

		// サービス実行結果データ用Map
		HashMap<String, Object> outputMap = new HashMap<String, Object>();

		HashMap<String, Object> dataMap = new HashMap<String, Object>();
		
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, JZMWebConst.SV124);

		// マッピングクラスのインスタンスを生成
		ZMSV0124_ZMSV0124OPDBMapper mapper = new ZMSV0124_ZMSV0124OPDBMapper();
		
		mapper.setZMSV012401SC(paramBean, dataMap, JPCModelConstant.FUNC_CD_1);

		mapper.setZMSV012402CC(paramBean, dataMap, JPCModelConstant.FUNC_CD_1);
		
		// ページング情報の設定
		JZMWebCommon.upmapperPageLinkInfo(this, JZMWebConst.CC12402, dataMap);
		
		// サービスの呼び出し
		invokeService(paramMap, dataMap, outputMap);
		
		// 一覧の初期化
		bean.getDataBeanArray(ZMW03701SFConst.EZM0011B011CBSMSG1LIST).clearArray();

		// マッピングクラスの呼び出し
		mapper.getZMSV012401SC(paramBean, outputMap);
		
		// マッピングクラスの呼び出し
		mapper.getZMSV012402CC(paramBean, outputMap);

		
		// 検索エラーフラグの取得
		String roleSearchErrFlg = JZMWebCommon.getSearchErrFlg(JZMWebConst.SC12401, outputMap);
		
		String authSearchErrFlg = JZMWebCommon.getSearchErrFlg(JZMWebConst.CC12402, outputMap);
		
		// 検索結果0件の場合
		if(JPCModelConstant.SEARCH_ERR_FLG_ZERO.equals(roleSearchErrFlg))
		{
			// 検索結果が0件の場合、エラーメッセージを表示
			JZMWebCommon.setMessageInfo(this, SEARCH_ERR_MESSAGE_ZERO_ROLE, NO_ROLE_MSG_ITEM);
			
			// 遷移先画面を設定する。
			setTransferPageId(commonBean, false);
			
			return true;
		}
		
		
		if(JPCModelConstant.SEARCH_ERR_FLG_ZERO.equals(authSearchErrFlg))
		{
			// 検索結果が0件の場合、エラーメッセージを表示
			JZMWebCommon.setMessageInfo(this, SEARCH_ERR_MESSAGE_ZERO);
		}
		
		// 検索結果が最大超過の場合
		else if(JPCModelConstant.SEARCH_ERR_FLG_OVERMAX.equals(authSearchErrFlg))
		{
			String[] item = {JZMWebCommon.getSearchConst(MAX_SHOW_CNT)};
			
			// 検索結果が最大検索件数を超える場合、エラーメッセージを表示
			JZMWebCommon.setMessageInfo(this, SEARCH_ERR_MESSAGE_OVERMAX, item);
		}

		if(!JZMWebCommon.isNullOrBlank(authSearchErrFlg))
		{

			setTransferPageId(commonBean, true);
			
			return true;
		}

		// ページング情報の設定
		JZMWebCommon.downmapperPageLinkInfo(this, JZMWebConst.CC12402, outputMap);
	
		// 検索のコマンドIDを設定する。
		JZMWebCommon.setSearchCommand(this, JZMWebConst.EVENT_ID_PAGING);
		
		// 背景色のスタイルクラスを設定
		JZMWebCommon.setRowStyleClass(bean, ZMW03701SFConst.EZM0011B011CBSMSG1LIST, ZMW03701SFConst.ROW_STYLE_CLASS_01);
		
		
		// 遷移先画面を設定する。
		JZMWebCommon.setNextScreenInfo(commonBean, JZMScreenConst.SCREEN_ID_ZMW03701, JZMScreenConst.SCREEN_NAME_ZMW03701);
		
		return true;
	}
	
	/**
	 * ページング処理を行います。
	 * <br>
	 * @return 処理結果 
	 * @throws Exception 予期せぬエラー
	 */
	public boolean paging()throws Exception
	{

		// 共通フォームBeanの内容を取得
		X31SDataBeanAccess commoninfoBean = getCommonInfoBean();
		
		if(!callAuthoritySearchSrv())
		{
			// 権限選択画面に遷移する。
			JZMWebCommon.setNextScreenInfo(commoninfoBean, JZMScreenConst.SCREEN_ID_ZMW03302, JZMScreenConst.SCREEN_NAME_ZMW03302);
			return true;
		}
		
		JZMWebCommon.setNextScreenInfo(commoninfoBean, JZMScreenConst.SCREEN_ID_ZMW03701, JZMScreenConst.SCREEN_NAME_ZMW03701);
		
		return true;
	}
	
	/**
	 * 戻るボタン処理を行います。
	 * <br>
	 * @return 処理結果 
	 * @throws Exception 予期せぬエラー
	 */
	public boolean back()throws Exception
	{

		// 共有フォームBean
		X31SDataBeanAccess commonBean = getCommonInfoBean();

		JZMWebCommon.clearPageLinkInfo(this, this.getGamenId());
		
		// 画面遷移
		JZMWebCommon.setNextScreenInfo(commonBean, JZMWebCommon.getScreenId(this), JZMWebConst.BLANK);
		
		return true;
	}
	
	/**
	 * 権限検索サービスを呼び出します。
	 * <br />
	 * @return 検索エラーフラグ
	 */
	@SuppressWarnings("unchecked")
	private boolean callAuthoritySearchSrv()
	{

		// サービスフォームBeanのデータBeanアクセスクラスを取得。
		X31SDataBeanAccess bean = super.getServiceFormBean();
		
		X31SDataBeanAccess[] paramBean = {bean};
		
		// ユースケースID格納用マップを生成。
		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, JZMWebConst.SV100);

		// サービス実行結果データ用Map
		HashMap<String, Object> outputMap = new HashMap<String, Object>();

		// 検索エラーフラグの取得
		String searchErrFlg = null;
		
		String maxShowCnt = JZMWebCommon.getSearchConst(MAX_SHOW_CNT);
		
		String rowPerPage = JZMWebCommon.getSearchConst(ROW_PER_PAGE);
		
		// マッピングクラスのインスタンスを生成
		ZMSV0100_ZMSV0100OPDBMapper_ZMSV010002CC mapper = new ZMSV0100_ZMSV0100OPDBMapper_ZMSV010002CC();
		
		HashMap<String, Object> dataMap = new HashMap<String, Object>();
		
		mapper.setBeanListNm(ZMW03701SFConst.EZM0011B011CBSMSG1LIST);
		mapper.setKeyClmNmRoleCd(ZMW03701SFConst.ROLE_CD);
		mapper.setKeyClmNmAuthorityCd(ZMW03701SFConst.AUTHORITY_CD);
		mapper.setKeyClmNmAuthorityNm(ZMW03701SFConst.AUTHORITY_NM);
		mapper.setKeyClmNmAuthoritySbtCd(ZMW03701SFConst.AUTHORITY_SBT_CD);
		mapper.setListClmNmAuthorityCd(ZMW03701SFConst.AUTHORITY_CD_01);
		mapper.setListClmNmAuthorityNm(ZMW03701SFConst.AUTHORITY_NM_01);
		mapper.setListClmNmAuthoritySbtCdNm(ZMW03701SFConst.AUTHORITY_SBT_CD_NM_01);
		mapper.setListClmNmAuthorityTendymd(ZMW03701SFConst.AUTHORITY_TENDYMD_01);
		mapper.setListClmNmAuthorityTstaymd(ZMW03701SFConst.AUTHORITY_TSTAYMD_01);
		
		mapper.setZMSV010002CC(paramBean, dataMap, JPCModelConstant.FUNC_CD_1, maxShowCnt, rowPerPage);
		
		HashMap<String, Object> inDataMap = (HashMap<String, Object>)dataMap.get(JZMWebConst.CC10002);
		
		inDataMap.put(JZMWebConst.EZM0031_KEY_SEARCH_DIV, JZMWebConst.ONE);

		// ページング情報の設定
		JZMWebCommon.upmapperPageLinkInfo(this, JZMWebConst.CC10002, dataMap);
		
		// サービスの呼び出し
		invokeService(paramMap, dataMap, outputMap);
		
		// 一覧の初期化
		bean.getDataBeanArray(ZMW03701SFConst.EZM0011B011CBSMSG1LIST).clearArray();
		
		// マッピングクラスの呼び出し
		mapper.getZMSV010002CC(paramBean, outputMap);

		// ページング情報の設定
		JZMWebCommon.downmapperPageLinkInfo(this, JZMWebConst.CC10002, outputMap);
		
		// 検索エラーフラグの取得
		searchErrFlg = JZMWebCommon.getSearchErrFlg(JZMWebConst.CC10002, outputMap);

		// 検索結果0件の場合
		if(JPCModelConstant.SEARCH_ERR_FLG_ZERO.equals(searchErrFlg))
		{
			
			// 検索結果が0件の場合、エラーメッセージを表示
			JZMWebCommon.setMessageInfo(this, SEARCH_ERR_MESSAGE_ZERO);
		}
		
		// 検索結果が最大超過の場合
		else if(JPCModelConstant.SEARCH_ERR_FLG_OVERMAX.equals(searchErrFlg))
		{
			String[] item = {maxShowCnt};
			
			// 検索結果が最大検索件数を超える場合、エラーメッセージを表示
			JZMWebCommon.setMessageInfo(this, SEARCH_ERR_MESSAGE_OVERMAX, item);
		}

		// 表示ページなしの場合
		else if(JPCModelConstant.SEARCH_ERR_FLG_NODATA.equals(searchErrFlg))
		{
			
			// 表示ページに該当するデータが存在しない場合、エラーメッセージを表示
			JZMWebCommon.setMessageInfo(this, SEARCH_ERR_MESSAGE_NODATA);
		}
		
		// 行の背景色を設定
		JZMWebCommon.setRowStyleClass(bean, ZMW03701SFConst.EZM0011B011CBSMSG1LIST, ZMW03701SFConst.ROW_STYLE_CLASS_01);

		if(searchErrFlg != null && !JZMWebConst.BLANK.equals(searchErrFlg))
		{

			return false;
		}
		
		return true;
	}

	/**
	 * セッションから遷移先画面を取得し共通ビーンに設定します。
	 * @param commonBean 共通ビーン
	 * @param is3302 権限設定画面の場合true,それ以外の場合false
	 */
	private void setTransferPageId(X31SDataBeanAccess commonBean, boolean is3302)
	{
		String screenId = null;
		if(is3302)
		{
			screenId = JZMScreenConst.SCREEN_ID_ZMW03302;
		}
		else
		{
			screenId = JZMWebCommon.getScreenId(this);
		}
		JZMWebCommon.setNextScreenInfo(commonBean, screenId, JZMWebConst.BLANK);
		
		setTransferPageId(screenId + JZMWebConst.PJP);
	}
}
