/*******************************************************************************
*	 All Rights reserved,Copyright (c) K-Opticom 
********************************************************************************
*＜プログラム内容＞
*	システム名		：eo顧客基幹システム
*	モジュール名	：JSYejbDK0131JSCK
*	ソースファイル名：JSYejbDK0131JSCK.java
*	作成者			：EK901638
*	日付			：2012年09月05日
*＜機能概要＞
*	メーカー返品ETMsgの状態遷移制約チェック
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	ｖ1.00.00
*
********************************************************************************/

package eo.ejb.check.state;

import java.sql.*;
import java.text.*;
import com.fujitsu.futurity.model.base.CAANMsg;
import com.fujitsu.futurity.model.base.CAANRuntimeException;
import com.fujitsu.futurity.model.ejb.common.JSYejbLog;
import com.fujitsu.futurity.model.ejb.common.StatusCodes;
import com.fujitsu.futurity.model.ejb.common.fw.AgentDispatchContext;
import com.fujitsu.futurity.model.ejb.common.fw.JoutaiseniCheckHandler;
import eo.ejb.common.EventIDList;
import eo.ejb.cbm.entity.DK0131ETMsg;
import eo.ejb.cbm.entity.DK0131LE;

/**
 * メーカー返品状態遷移チェッククラスです。
 *  ＜メソッド一覧＞
 * invoke
 * execIDK0131C001
 *
 */
public class JSYejbDK0131JSCK implements JoutaiseniCheckHandler {

	/**
	 * コンストラクタ
	 */
	public JSYejbDK0131JSCK() {
	}

	/**
	 * メーカー返品状態遷移チェックを行います。
	 * 
	 * @param inETMsg エンティティ
	 */
	public void invoke(CAANMsg inETMsg,AgentDispatchContext context) {

		JSYejbLog.println(JSYejbLog.DEBUG, getClass(), "call:JSYejbDK0131JSCK.invoke");

		// inETMsgのチェック
		if (inETMsg == null) {
			throw new CAANRuntimeException("inETMsgがnullです。");
		}

		// 振舞ID取り出し
		String eventID = inETMsg.getString(DK0131ETMsg.EVENTID);
		if (eventID == null) {
			throw new CAANRuntimeException("振舞IDがnullです。");
		}

		// 処理の振り分け
		if (eventID.equals(EventIDList.IDK0131C001)) {	// メーカー返品対応完了振舞内部
			execIDK0131C001(inETMsg);
		}

		JSYejbLog.println(JSYejbLog.DEBUG, getClass(), "end:JSYejbDK0131JSCK.invoke");
	}

	/**
	 * メーカー返品対応完了振舞内部のチェック
	 * 
	 * @param inETMsg チェック対象のETMsg(DK0131ETMsg)
	 */
	private void execIDK0131C001(CAANMsg inETMsg) {

		JSYejbLog.println(JSYejbLog.DEBUG, getClass(), "call:JSYejbDK0131JSCK.IDK0131C001");

		int st = 0;

		DK0131LE dk0131LE = new DK0131LE();
		CAANMsg msg = new CAANMsg(inETMsg.getSchemaName());
		CAANMsg res = null;

		// キー項目のセット
		msg.set(DK0131ETMsg.MKRHMPIN_NO, inETMsg.getObject(DK0131ETMsg.MKRHMPIN_NO).toString());

		// データの照会
		res = dk0131LE.findByPrimaryKey(msg);

		// 変数宣言
		String res_MKRHMPIN_STAT = null;
		String inETMsg_MKRHMPIN_STAT = null;
		
		// 変数に値をセット
		if( !res.isNull(DK0131ETMsg.MKRHMPIN_STAT) ){
			res_MKRHMPIN_STAT = new String(res.getObject(DK0131ETMsg.MKRHMPIN_STAT).toString());
		}
		if( !inETMsg.isNull(DK0131ETMsg.MKRHMPIN_STAT) ){
			inETMsg_MKRHMPIN_STAT = new String(inETMsg.getObject(DK0131ETMsg.MKRHMPIN_STAT).toString());
		}

		// チェック
		if (res == null) {

			st = StatusCodes.FIND_DB_ERR;

		} else {

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(001)遷移後(001)
			if(res_MKRHMPIN_STAT.compareTo("001") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("001") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(001)遷移後(002)
			else if(res_MKRHMPIN_STAT.compareTo("001") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("002") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(001)遷移後(003)
			else if(res_MKRHMPIN_STAT.compareTo("001") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("003") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(001)遷移後(011)
			else if(res_MKRHMPIN_STAT.compareTo("001") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("011") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(002)遷移後(001)
			else if(res_MKRHMPIN_STAT.compareTo("002") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("001") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(002)遷移後(002)
			else if(res_MKRHMPIN_STAT.compareTo("002") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("002") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(002)遷移後(011)
			else if(res_MKRHMPIN_STAT.compareTo("002") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("011") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(003)遷移後(001)
			else if(res_MKRHMPIN_STAT.compareTo("003") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("001") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(003)遷移後(002)
			else if(res_MKRHMPIN_STAT.compareTo("003") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("002") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(003)遷移後(003)
			else if(res_MKRHMPIN_STAT.compareTo("003") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("003") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(003)遷移後(011)
			else if(res_MKRHMPIN_STAT.compareTo("003") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("011") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(011)遷移後(001)
			else if(res_MKRHMPIN_STAT.compareTo("011") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("001") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(011)遷移後(002)
			else if(res_MKRHMPIN_STAT.compareTo("011") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("002") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(011)遷移後(003)
			else if(res_MKRHMPIN_STAT.compareTo("011") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("003") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

			//メーカー返品ステータス(MKRHMPIN_STAT)のチェック：遷移前(011)遷移後(011)
			else if(res_MKRHMPIN_STAT.compareTo("011") == 0 && 
					inETMsg_MKRHMPIN_STAT.compareTo("011") == 0){

				inETMsg.set(DK0131ETMsg.MKRHMPIN_NO_ERR, "EA");
				st = StatusCodes.STATUSTRANS_ERR;

			}

		}

		//ステータスのセット
		if (st > inETMsg.getInt(DK0131ETMsg.STATUS)) {
			inETMsg.set(DK0131ETMsg.STATUS, st);
		}

		JSYejbLog.println(JSYejbLog.DEBUG, getClass(), "end:JSYejbDK0131JSCK.IDK0131C001");

	}

}
