/*******************************************************************************
All Rights reserved,Copyright (c) K-Opticom
 ********************************************************************************
 *＜プログラム内容＞
 * システム名        ：eo顧客基幹システム
 * モジュール名      ：CRW01301SFLogic
 * ソースファイル名  ：CRW01301SFLogic.java
 * 作成者            ：富士通
 * 日付              ：2011年08月06日
 *＜機能概要＞
 * MYBOX一覧ビューロジック
 *＜修正履歴＞
 * バージョン   修正日      修正者      修正内容
 * ｖ1.00.00
 * ｖ6.00.00	2013/09/16	FJ)伊藤		OM-2013-0002356 メッセージ出力処理追加。
 * ｖ7.00.00    2014/02/12  FJ          OM-2013-0004109 子画面セッション削除
 * ｖ8.00.00	2014/04/10	FJ)伊藤		ANK-2004-00-00  【ＮＯ．８１２】　キューＢＯＸの独立表示
 * ｖ8.00.01	2014/06/16	FJ)伊藤		OM-2014-0002170 対応記録一覧照会（ＭＹＢＯＸ）明細のクリア処理追加。
 * ｖ8.00.02	2014/06/17	FJ)小野		OM-2014-0002179 問合せ客情報一覧照会画面に遷移した状態で、MyBOX一覧画面で対応記録番号リンクを押すとエラーになる現象に対応。
 * ｖ29.00.00	2017/02/28	FJ)原田		【ANK-2921-00-00】(客B) MyBox一覧、キューボックス一覧画面での簡易メモの登録
 * ｖ29.00.00	2017/03/09	FJ)クウン	ANK-2918-00-00 (客B)コールバック期限超過時の赤字表示
 *
 ********************************************************************************/

package eo.web.webview.CRW01301SF;

import java.util.EventObject;
import java.util.HashMap;

import com.fujitsu.futurity.web.x31.X31CID;
import com.fujitsu.futurity.web.x31.X31CWebConst;
import com.fujitsu.futurity.web.x31.X31SDataBeanAccess;
import com.fujitsu.futurity.web.x31.X31SDataBeanAccessArray;
import com.fujitsu.futurity.web.x33.X33SException;

import eo.common.constant.JCRStrConst;
import eo.common.constant.JPCModelConstant;
import eo.common.constant.JPCOnlineMessageConstant;
import eo.common.util.JCRUtilCommon;
import eo.web.webview.JCCWebBusinessLogic;
import eo.web.webview.CRW01201SF.CRW01201SFConst;
import eo.web.webview.CRW02401SF.CRW02401SFConst;
import eo.web.webview.CommonInfoCF.CommonInfoCFConst;
import eo.web.webview.common.JCCWebCommon;
import eo.web.webview.common.JCRGetDataUtil;
import eo.web.webview.common.JCRScreenConst;
import eo.web.webview.common.JCRWebCommon;
import eo.web.webview.mapping.CRSV0024_CRSV0024OPDBMapper;
import eo.web.webview.mapping.CRSV0288_CRSV0288OPDBMapper;

/**
 * 対応記録一覧照会(MYBOX)ビューロジック.<p>
 * <BR>
 * @author 富士通
 */
@SuppressWarnings("serial")
public class CRW01301SFLogic extends JCCWebBusinessLogic
{

	/**
	 * 親クラスX31BWebBusinessLogicのreceiveMessageWebを
	 * オーバーライドして自動生成されたメソッドです。
	 * @param arg0 (I) イベント情報
	 * @param arg1 (I) WebFWでは使用しません
	 * @param arg2 (I) WebFWでは使用しません
	 * @return 処理結果（true:正常終了、false:エラー）
	 * @throws X33SException X33SException
	 */
	@Override
	protected boolean receiveMessageWeb(X31CID arg0, Object arg1,
			EventObject arg2) throws X33SException 
	{
		return false;
	}

	/**
	 * 初期表示処理.<br>
	 * 初期表示を行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean init() throws Exception 
	{
		// (1)引継情報の取得
		JCCWebCommon.getScreenInfo(this);

		return sort(JCRStrConst.FUNC_1, JCRStrConst.KIROK_NO);
	}

	/**
	 * 対応記録番号昇順ソート処理.<br>
	 * 対応記録番号の昇順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortAscTaioKirokNo() throws Exception
	{
		return sort(JCRStrConst.FUNC_1, JCRStrConst.KIROK_NO);	
	}

	/**
	 * 対応記録番号降順ソート処理.<br>
	 * 対応記録番号の降順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortDescTaioKirokNo() throws Exception
	{
		return sort(JCRStrConst.FUNC_2, JCRStrConst.KIROK_NO);		
	}
	
	/**
	 * 簡易メモ昇順ソート処理.<br>
	 * 簡易メモの昇順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortAscEasyMemo() throws Exception
	{
		return sort(JCRStrConst.FUNC_1, JCRStrConst.EASY_MEMO);	
	}

	/**
	 * 簡易メモ降順ソート処理.<br>
	 * 簡易メモの降順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortDescEasyMemo() throws Exception
	{
		return sort(JCRStrConst.FUNC_2, JCRStrConst.EASY_MEMO);	
	}

	/**
	 * タイトル昇順ソート処理.<br>
	 * タイトルの昇順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortAscTitle() throws Exception
	{
		return sort(JCRStrConst.FUNC_1, JCRStrConst.TITLE);	
	}
	
	/**
	 * タイトル降順ソート処理.<br>
	 * タイトルの降順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortDescTitle() throws Exception
	{
		return sort(JCRStrConst.FUNC_2, JCRStrConst.TITLE);		
	}

	/**
	 * サービス契約番号昇順ソート処理.<br>
	 * サービス契約番号の昇順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortAscSvcKeiNo() throws Exception
	{
		return sort(JCRStrConst.FUNC_1, JCRStrConst.SVC_NO);	
	}

	/**
	 * サービス契約番号降順ソート処理.<br>
	 * サービス契約番号の降順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortDescSvcKeiNo() throws Exception
	{
		return sort(JCRStrConst.FUNC_2, JCRStrConst.SVC_NO);
	}

	/**
	 * コールバック日時昇順ソート処理.<br>
	 * コールバック日時の昇順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortAscCbDttm() throws Exception
	{
		return sort(JCRStrConst.FUNC_1, JCRStrConst.CALLBK_YMD);		
	}

	/**
	 * コールバック日時降順ソート処理.<br>
	 * コールバック日時の降順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortDescCbDttm() throws Exception
	{
		return sort(JCRStrConst.FUNC_2, JCRStrConst.CALLBK_YMD);	
	}
	
	/**
	 * 問合せ客名昇順ソート処理.<br>
	 * 問合せ客名の昇順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortAscProscstNm() throws Exception
	{
		return sort(JCRStrConst.FUNC_1, JCRStrConst.PROSCST_NM_KANA);	
	}
	
	/**
	 * 問合せ客名降順ソート処理.<br>
	 * 問合せ客名の降順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortDescProscstNm() throws Exception
	{
		return sort(JCRStrConst.FUNC_2, JCRStrConst.PROSCST_NM_KANA);
	}

	/**
	 * 対応開始年月日時分秒昇順ソート処理.<br>
	 * 対応開始年月日時分秒の昇順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortAscTaioStaYmd() throws Exception
	{
		return sort(JCRStrConst.FUNC_1, JCRStrConst.TAIO_START);
	}

	/**
	 * 対応開始年月日時分秒降順ソート処理.<br>
	 * 対応開始年月日時分秒の降順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortDescTaioStaYmd() throws Exception
	{
		return sort(JCRStrConst.FUNC_2, JCRStrConst.TAIO_START);
	}

	/**
	 * ステータス昇順ソート処理.<br>
	 * ステータスの昇順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortAscStatus() throws Exception
	{
		return sort(JCRStrConst.FUNC_1, JCRStrConst.TAIO_STAT);
	}

	/**
	 * ステータス降順ソート処理.<br>
	 * ステータスの降順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortDescStatus() throws Exception
	{
		return sort(JCRStrConst.FUNC_2, JCRStrConst.TAIO_STAT);	
	}

	/**
	 * 申込書番号昇順ソート処理.<br>
	 * 申込書番号の昇順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortAscMskmshoNo() throws Exception
	{
		return sort(JCRStrConst.FUNC_1, JCRStrConst.MSKM_NO);
	}

	/**
	 * 申込書番号降順ソート処理.<br>
	 * 申込書番号の降順ソートを行う。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean sortDescMskmshoNo() throws Exception
	{
		return sort(JCRStrConst.FUNC_2, JCRStrConst.MSKM_NO);
	}
	
	/**
	 * 対応記録番号リンク押下.<br>
	 * 問合せ情報詳細画面に遷移する。
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean clickLinkToiawaseId() throws Exception
	{
		// サービスフォームBeanの内容の取得
		X31SDataBeanAccess bean = getServiceFormBean();
		
		// 共通フォームBeanの内容を取得
		X31SDataBeanAccess commoninfoBean = getCommonInfoBean();

		// 子画面に渡す情報用HashMap
		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		

		// (1)引継情報の取得
		// なし。

		// (2)サービスフォームBeanの設定
		// なし。
		
		// (3)サービス呼出処理
		// なし。

		// (4)サービス処理結果の設定
		// なし。

		// (5)引継情報の設定
		String slctDetailIndex = bean.sendMessageString(CRW01301SFConst.LINE_NO
				, X31CWebConst.DATABEAN_GET_VALUE);
		X31SDataBeanAccessArray detailBeanList = bean.getDataBeanArray(CRW01301SFConst.ECR0011B090CBSMSG1LIST);
		X31SDataBeanAccess detailBean = detailBeanList.getDataBean(Integer.parseInt(slctDetailIndex));
		String slctKirokNo = detailBean.sendMessageString(CRW01301SFConst.L0_TAIO_KIROK_NO_01,X31CWebConst.DATABEAN_GET_VALUE);

		// (a)次画面への引継情報(dataMap)を作成する。
		// 子画面に渡す情報をHashMapに設定する
		String parentTab = bean.sendMessageString(CRW01301SFConst.PARENTTAB, X31CWebConst.DATABEAN_GET_VALUE); 

		if (JCRScreenConst.SCREEN_ID_CRW02401.equals(parentTab))
		{
			paramMap.put(CRW02401SFConst.HKTGI_TAIO_KIROK_NO, slctKirokNo);
		}
		else
		{
			paramMap.put(CRW01201SFConst.TAIO_KIROK_NO, slctKirokNo);
		}

		paramMap.put(CRW01201SFConst.CURRENTTAB, ""); 

		// (b)画面情報設定部品（JCCWebCommon.setScreenInfo)を使用し、次画面への引継情報を設定する。
		// 子画面に渡す情報を設定
		JCRWebCommon.setScreenInfo(this, bean.sendMessageString(CRW01301SFConst.PARENTTAB, X31CWebConst.DATABEAN_GET_VALUE), paramMap);

		// (6)遷移先画面の設定
		// 遷移先画面ID、名称の設定
		commoninfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID, X31CWebConst.DATABEAN_SET_VALUE, JCRScreenConst.SCREEN_ID_CRW01301);
		commoninfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME, X31CWebConst.DATABEAN_SET_VALUE, JCRScreenConst.SCREEN_NAME_CRW01301);
				
		return true;
	}
	
	/**
	 * サービスの呼出し、画面レイアウトの補正を行う。
	 * @param func 機能コード
	 * @param sortKey ソート指定項目
	 * @return boolean
	 * @throws Exception Exception
	*/
	@SuppressWarnings("unchecked")
	private boolean sort(String func, String sortKey) throws Exception
	{
		
		// サービスフォームBeanの内容の取得
		X31SDataBeanAccess bean = getServiceFormBean();

		// 共通フォームBeanの内容を取得
		X31SDataBeanAccess commoninfoBean = getCommonInfoBean();
		
		// ユースケースID格納用マップ
		HashMap paramMap = new HashMap();

		// マッピング用Map
		HashMap dataMap = new HashMap();

		// サービス実行結果データ用Map
		HashMap outputMap = new HashMap();

		// (1)引継情報の取得
		// なし。
		
		// (2)サービスフォームBeanの設定
		bean.sendMessageString(CRW01301SFConst.KEY_TAIO_USER_ID,X31CWebConst.DATABEAN_SET_VALUE,
				commoninfoBean.sendMessageString(CommonInfoCFConst.USER_ID, X31CWebConst.DATABEAN_GET_VALUE));
		bean.sendMessageString(CRW01301SFConst.KEY_SORT_SHITEI_KMK,X31CWebConst.DATABEAN_SET_VALUE,sortKey);
		
		// ANK-2921-00-00 ADD START
		// 設定されているソート指定項目・ソート順（機能コード）を退避用に設定
		bean.sendMessageString(CRW01301SFConst.BF_REDSP_SORT_KMK,X31CWebConst.DATABEAN_SET_VALUE,sortKey);
		bean.sendMessageString(CRW01301SFConst.BF_REDSP_SORT_JUN,X31CWebConst.DATABEAN_SET_VALUE,func);
		// ANK-2921-00-00 ADD END

		// 対応記録一覧照会（ＭＹＢＯＸ）明細をクリアする
		bean.getDataBeanArray(CRW01301SFConst.ECR0011B090CBSMSG1LIST).clearArray();

		// (3)サービス呼出処理
		// マッピングクラスを使用する為、配列化
		X31SDataBeanAccess[] paramBean = {bean};

		// ユースケースID格納
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, "CRSV0024");

		// マッピングクラス
		CRSV0024_CRSV0024OPDBMapper mapper = new CRSV0024_CRSV0024OPDBMapper();

		// マッピング処理（上り）
		mapper.setCRSV002401SC(paramBean, dataMap, func);
		mapper.setGETWORKPARAM1ICC(paramBean, dataMap, JPCModelConstant.FUNC_CD_1);
		
		// サービス実行
		invokeService(paramMap, dataMap, outputMap);
		
		// (4)サービス処理結果の設定
		// マッピング処理（下り）
		mapper.getCRSV002401SC(paramBean, outputMap);
		mapper.getGETWORKPARAM1ICC(paramBean, outputMap);

		// フォントスタイルの設定
		//---------v29.00.00 ANK-2918-00-00 削除開始---------//
//		String limitoverOkTime = bean.sendMessageString(CRW01301SFConst.LIMITOVER_OK_TIME, X31CWebConst.DATABEAN_GET_VALUE);
//		if (!JCRUtilCommon.isNull(limitoverOkTime))
//		{
//			JCRGetDataUtil.setFontStyle(bean, limitoverOkTime, 
//					CRW01301SFConst.ECR0011B090CBSMSG1LIST, CRW01301SFConst.L0_CALLBK_KIBO_DTM_01, 
//					CRW01301SFConst.L0_CALLBK_KIBO_TIME_01, CRW01301SFConst.L0_FONT_STYLE_01);
//		}
		//---------v29.00.00 ANK-2918-00-00 削除終了---------//
		//---------v29.00.00 ANK-2918-00-00 追加開始---------//
		fitColumn(bean);
		//---------v29.00.00 ANK-2918-00-00 追加終了---------//
		
		// 検索結果が0件の場合
		if (JCRStrConst.TOTAL_SEARCH_NUM_ZERO.equals(bean.sendMessageString(CRW01301SFConst.TOTAL_CNT, X31CWebConst.DATABEAN_GET_VALUE)))
		{
			//検索結果:指定されたデータが存在しません。
			JCRWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB0330__I, new String[]{""});
		}

		// (5)引継情報の設定
		// なし。
		
		// (6)共有フォームビーンの設定
		// 遷移先画面ID、名称の設定
		commoninfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID
				, X31CWebConst.DATABEAN_SET_VALUE, JCRScreenConst.SCREEN_ID_CRW01301);
		commoninfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME
				, X31CWebConst.DATABEAN_SET_VALUE, JCRScreenConst.SCREEN_NAME_CRW01301);
		
		// v7.00.00 OM-2013-0004109 子ウインドウのセッション削除 start
		JCCWebCommon.deleteChildSession();
		// v7.00.00 OM-2013-0004109 子ウインドウのセッション削除 end

		return true;
		
	}
	
	// ANK-2921-00-00 ADD START
	/**
	 * 更新（簡易メモ）ボタン押下時処理
	 * 
	 * @return boolean
	 * @exception Exception Exception
	 */
	public boolean updEasyMemo() throws Exception
	{
		// サービスフォームBeanの内容の取得
		X31SDataBeanAccess bean = getServiceFormBean();
		
		// マッピングクラスを使用する為、配列化
		X31SDataBeanAccess[] parambean = {bean};
		
		// 共通フォームBeanの内容を取得
		X31SDataBeanAccess commoninfoBean = getCommonInfoBean();
		
		
		// ユースケースID格納用マップ
		HashMap<String, Object> paramMap = new HashMap<String, Object>();

		// 引渡し用Map
		HashMap<String, String> dataMap = new HashMap<String, String>();

		// マッピング用Map
		HashMap<String, String> inputMap = new HashMap<String, String>();

		// サービス実行結果データ用Map
		HashMap<String, String> outputMap = new HashMap<String, String>();
		
		// (1)引継情報の取得
		// なし。

		// (2)サービスフォームBeanの設定
		// なし。
		
		// (3)サービス呼出処理
		// なし。

		// (4)サービス処理結果の設定
		// なし。

		// (5)引継情報の設定
		String slctDetailIndex = bean.sendMessageString(CRW01301SFConst.LINE_NO, X31CWebConst.DATABEAN_GET_VALUE);
		X31SDataBeanAccessArray detailBeanList = bean.getDataBeanArray(CRW01301SFConst.ECR0011B090CBSMSG1LIST);
		X31SDataBeanAccess detailBean = detailBeanList.getDataBean(Integer.parseInt(slctDetailIndex));
		
		// 画面のonload時に親画面のメソッドを呼ぶのを抑止するためクリアする
		bean.sendMessageString(CRW01301SFConst.LINE_NO, X31CWebConst.DATABEAN_SET_VALUE, new String());
		
		// 対応記録番号
		dataMap.put("taio_kirok_no", detailBean.sendMessageString(CRW01301SFConst.L0_TAIO_KIROK_NO_01,X31CWebConst.DATABEAN_GET_VALUE));
		
		// 更新前更新年月日時分秒
		dataMap.put("upd_dtm_bf", detailBean.sendMessageString(CRW01301SFConst.L0_UPD_DTM_01,X31CWebConst.DATABEAN_GET_VALUE));
		
		// 簡易メモ
		dataMap.put("easy_memo", (String)parambean[0].sendMessageString(CRW01301SFConst.HENSYU_YO_EASY_MEMO, X31CWebConst.DATABEAN_GET_VALUE));
		
		// マッピングクラス
		CRSV0288_CRSV0288OPDBMapper mapper = new CRSV0288_CRSV0288OPDBMapper();
		
		// 上りマッピング処理
		mapper.setCRSV028801SC(dataMap, inputMap, JPCModelConstant.FUNC_CD_1);
		
		// ユースケースID格納
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, "CRSV0288");
		
		// サービス実行
		invokeService(paramMap, inputMap, outputMap);
		
		
		// ソート指定項目（退避用）・ソート順（退避用）の取得
		String bfSortKey = (String)parambean[0].sendMessageString(CRW01301SFConst.BF_REDSP_SORT_KMK, X31CWebConst.DATABEAN_GET_VALUE);
		String bfSortJun = (String)parambean[0].sendMessageString(CRW01301SFConst.BF_REDSP_SORT_JUN, X31CWebConst.DATABEAN_GET_VALUE);
		
		// 画面の再描画を行う
		sort(bfSortJun, bfSortKey);
		
		// メッセージを設定
		JCRWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB4390__I, new String[]{JCRStrConst.REPLACE_MSG_OPERATION_NAME_UPDATE_EASY_MEMO});
		
		return true;
	}
	// ANK-2921-00-00 ADD END

	

	//---------v29.00.00 ANK-2918-00-00 追加開始---------//
	/**
	 * 画面レイアウトの補正を行う。
	 * 
	 * @param bean
	 */
	private void fitColumn(X31SDataBeanAccess bean)
	{
		String limitoverOkTime = "";
		String limitoverOkFistTime = "";
		String workParamList = bean.sendMessageString(CRW01301SFConst.LIMITOVER_OK_TIME, X31CWebConst.DATABEAN_GET_VALUE);
		workParamList = workParamList.replaceAll(",", " ");
		workParamList.trim();
		String[] workParam = workParamList.split(" ",0);
		
		for (int i = 0; i <workParam.length;i++)
		{
			String workparamtmp = workParam[i];
			if (workparamtmp.contains("CR_LIMITOVER_OK_TIME=")){
				limitoverOkTime = workparamtmp.replace("CR_LIMITOVER_OK_TIME=", "");
			}
			if (workparamtmp.contains("CR_LIMITOVER_FS_TIME=")){
				limitoverOkFistTime = workparamtmp.replace("CR_LIMITOVER_FS_TIME=", "");
			}
		}
		
		if (!JCRUtilCommon.isNull(limitoverOkTime) && !JCRUtilCommon.isNull(limitoverOkFistTime))
		{
			JCRGetDataUtil.setFontStyle2(bean, limitoverOkTime, limitoverOkFistTime,
					CRW01301SFConst.ECR0011B090CBSMSG1LIST, CRW01301SFConst.L0_CALLBK_KIBO_DTM_01, 
					CRW01301SFConst.L0_CALLBK_KIBO_TIME_01, CRW01301SFConst.L0_FONT_STYLE_01);
		}
	}
	//---------v29.00.00 ANK-2918-00-00 追加終了---------//
}
