/*********************************************************************
* All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：TELvisionユーザー公衆通話設定解約
*   ソースファイル名：FUW04801SFLogic.java
*   作成者          ：富士通
*   日付            ：2012年02月09日
*＜機能概要＞
*  TELvisionユーザー公衆通話設定解約のビューロジッククラスです。
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*   v1.00.00    2012/02/09   FJ）赤井    新規作成
*
**********************************************************************/

package eo.web.webview.FUW04801SF;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

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.JCCWebBusinessLogic;
import eo.web.webview.CommonInfoCF.CommonInfoCFConst;
import eo.web.webview.common.JFUScreenConst;
import eo.web.webview.common.JFUWebCommon;

/**
 * TELvisionユーザー公衆通話設定解約のビューロジッククラスです。<p>
 * <BR>
 * @author 富士通
 */
@SuppressWarnings("serial")
public class FUW04801SFLogic extends JCCWebBusinessLogic
{
	/** 外部コマンド正常終了 */
	private static final String SUCCESS = "0";

	/** ステータス：情報取得成功 */
	private static final String STAT_000 = "000";

	/** サービスID */
	private static final String SERVICE_ID = "FUSV0144_01";

	/**
	 * 初期表示処理
	 * @return 処理結果
	 * @throws Exception 例外
	 */
	public boolean init() throws Exception
	{
		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- init_FUW04801SFLogic Start -----");

		// 共有フォームBean保持
		X31SDataBeanAccess commonInfoBean = getCommonInfoBean();

		// 画面情報を取得し、サービスフォームBeanに設定
		JFUWebCommon.getScreenInfo(this);

		// 共通関連チェック
		JFUWebCommon.checkCommonRelation(this, SERVICE_ID);

		// 遷移先画面IDを設定
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_ID_FUW04801);
		// 遷移先画面名を設定
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_NAME_FUW04801);

		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- init_FUW04801SFLogic End -----");

		return true;

	}

	/**
	 * 確認ボタン押下時処理
	 * 
	 * @return 処理結果
	 * @throws Exception 例外
	 */
	public boolean cfm() throws Exception
	{
		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- cfm_FUW04801SFLogic Start -----");

		// 共有フォームBean保持
		X31SDataBeanAccess commonInfoBean = getCommonInfoBean();

		// 遷移先画面IDを設定
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_ID_FUW04802);
		// 遷移先画面名を設定
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_NAME_FUW04802);

		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- cfm_FUW04801SFLogic End -----");

		return true;
	}

	/**
	 * 戻るボタン押下時処理
	 * 
	 * @return 処理結果
	 * @throws Exception 例外
	 */
	public boolean back() throws Exception
	{
		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- back_FUW04801SFLogic Start -----");

		// 共有フォームBean保持
		X31SDataBeanAccess commonInfoBean = getCommonInfoBean();

		// 遷移先画面IDを設定
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_ID_FUW04801);
		// 遷移先画面名を設定
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_NAME_FUW04801);

		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- back_FUW04801SFLogic End -----");

		return true;
	}

	/**
	 * 解除ボタン押下時処理
	 * 
	 * @return 処理結果
	 * @throws Exception 例外
	 */
	public boolean dsl() throws Exception
	{
		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- dsl_FUW04801SFLogic Start -----");

		// 共有フォームBean保持
		X31SDataBeanAccess commonInfoBean = getCommonInfoBean();

		// サービスフォームBean保持
		X31SDataBeanAccess serviceFormBean = getServiceFormBean();

		// 共有フォームBean.サービス契約情報
		X31SDataBeanAccess svcKeiInfoBean = JFUWebCommon.getDataBeanTypeByPath(commonInfoBean, JFUWebCommon.SVC_KEI_INFO);

		// 共通関連チェック
		JFUWebCommon.checkCommonRelation(this, SERVICE_ID);

		// -------------------------------------------------
		// TELvisionユーザー公衆通話設定解約
		// -------------------------------------------------
		// サービス契約情報.サービス契約番号
		String svcKeiNo = svcKeiInfoBean.sendMessageString(CommonInfoCFConst.SVC_KEI_NO_23, X31CWebConst.DATABEAN_GET_VALUE);

		// 外部API呼出処理
		execSync(serviceFormBean, svcKeiNo);

		// 遷移先画面IDを設定
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_ID_FUW04803);
		// 遷移先画面名を設定
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_NAME_FUW04803);

		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- dsl_FUW04801SFLogic End -----");

		return true;
	}

	/**
	 * 外部API呼出処理を行います。 <BR>
	 * 
	 * @param serviceFormBean サービスフォームBean
	 * @param strSvcKeiNo サービス契約番号
	 */
	private void execSync(X31SDataBeanAccess serviceFormBean, String strSvcKeiNo)
	{
		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- execSync_FUW04801SFLogic Start -----");

		// 実行結果
		List<String> dataList = new ArrayList<String>();

		// 外部コマンド実行標準出力格納
		StringBuffer outPut = new StringBuffer();

		// 外部コマンド情報
		String[] cmd =
				{ JFUWebCommon.getApplicationConst(JFUStrConst.REMOTE_CMD_NM), JFUWebCommon.getApplicationConst(JFUStrConst.REMOTE_CMD_OP1),
						JFUWebCommon.getApplicationConst(JFUStrConst.FUIFE014_PARAM1), strSvcKeiNo,
						JFUWebCommon.getApplicationConst(JFUStrConst.REMOTE_CMD_OP2), JFUWebCommon.getApplicationConst(JFUStrConst.VOIP_ENV) };

		// (デバッグログ)
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("★ コマンドライン引数配列 ★：＝" + Arrays.toString(cmd));

		// 外部コマンド実行処理
		String execSyncCode =
				JFUWebCommon.execSync(cmd, outPut, Integer.parseInt(JFUWebCommon.getApplicationConst(JFUStrConst.REMOTE_EXEC_TIME_OUT)));

		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("★ リターンコード ★：＝" + execSyncCode);

		// 外部コマンド実行結果
		if (SUCCESS.equals(execSyncCode))
		{
			if (0 < outPut.length())
			{
				// デバッグログ
				com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("★ 外部コマンド実行結果 ★：＝" + outPut.toString());

				// 出力結果をListに詰め直す。
				dataList = Arrays.asList(outPut.toString().split(JFUWebCommon.LINE_SEPARATOR));
			}
			else
			{
				// "0002"（システムエラー）
				com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("★ 外部コマンド実行結果なしエラー ★");
				throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002);
			}
		}
		else
		{
			// "0002"（システムエラー）
			com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("★ リターンコードエラー ★");
			throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002);
		}

		// 出力結果のステータスをチェック
		checkStat(dataList);

		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- execSync_FUW04801SFLogic End -----");

	}

	/**
	 * 出力結果のステータスをチェックします <BR>
	 * 
	 * @param dataList 出力結果
	 */
	private void checkStat(List<String> dataList)
	{
		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- checkStat_FUW04801SFLogic Start -----");

		// -------------------------------------------------
		// 出力結果から値の取得
		// -------------------------------------------------
		// ステータス
		String stat = dataList.get(0);

		if (!STAT_000.equals(stat))
		{
			// デバッグログ
			com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- ★ ステータスエラー ★ 外部インターフェイス出力結果ステータス=" + stat + " -----");

			// ステータスが"000"以外の場合、エラーパターンIDに"0002"（システムエラー）を設定し、
			// 業務用例外クラスをthrowする。
			throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002);
		}

		// デバッグログ
		com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG.debug("----- checkStat_FUW04801SFLogic End -----");
	}
}
