/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom  					 *
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatCHAuthoriRsltListMake
*	ソースファイル名	：JBSbatCHAuthoriRsltListMake.java
*	作成者				：富士通　
*	作成日				：2011年07月16日
*＜機能概要＞
*　売上オーソリ結果リスト作成部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2011/07/16   富士通		新規作成
*	v4.00.00	2013/01/31   FJ) 小柴	項目をダブルクォーテーションで囲んで出力するように修正
*	v4.00.01	2013/03/22   FJ) 小柴	【内部管理番号-0000302】クレジット会社交換コードの設定値を修正
*	v5.00.00	2013/10/08   FJ) 北端	【OM-2013-0003230】不正な書式で出力されている項目の修正
*	v53.00.00	2021/05/14   FJ) 謝     【ANK-4029-00-00】売上オーソリエラーコード追加対応
*	v58.00.00	2022/05/17   FJ) 秋末   【ANK-3846-00-00】【クレカ】クリアパス→ペイジェント移行
*********************************************************************/
package eo.business.service;

import java.text.DecimalFormat;

import eo.business.common.JACBatCommon;
import eo.business.common.JACbatDebugLogUtil;
import eo.business.common.JBSbatBusinessService;
import eo.business.util.file.JBSbatCHIFE055;
import eo.business.util.file.JBSbatCHIFM066;
import eo.common.constant.JACStrConst;
import eo.framework.item.JBSbatCommonItem;
import eo.framework.item.JBSbatOutputItem;
import eo.framework.item.JBSbatServiceInterfaceMap;

/**
* 売上オーソリ結果リスト作成 <p>
*<BR>
* @author 富士通
*/
public class JBSbatCHAuthoriRsltListMake extends JBSbatBusinessService
{
	/**▼▼▼▼▼▼ツールから生成した宣言です 開始▼▼▼▼▼▼*/
	/**▲▲▲▲▲▲ツールから生成した宣言です 終了▲▲▲▲▲▲*/

	/** 項番カウンタ */
	private int noCnt = 0;

	/**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの初期処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した初期化のソースです 開始▼▼▼▼▼▼*/
		// 共通パラメータを設定します
		super.setCommonInfo(commonItem);
		/**▲▲▲▲▲▲ツールから生成した初期化のソースです 終了▲▲▲▲▲▲*/
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][initial]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][initial][opeDate=" + super.opeDate + "]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][initial][freeItem=" + super.freeItem + "]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][initial]");
	
	/**▲▲▲▲▲▲業務サービスの初期処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 主処理
	 * @param inMap　入力電文
	 * @return JBSbatOutputItem　出力情報
	 * @throws Exception
	 */
	public JBSbatOutputItem execute(JBSbatServiceInterfaceMap inMap) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの主処理を記述してください。▼▼▼▼▼▼*/
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][execute]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][execute][inMap=" + inMap.getMap().toString() + "]");
		
		// 抑止情報作成
		JBSbatOutputItem outputItem = makeAuthoriRsltList(inMap);
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][execute]");
		
		return outputItem;
	/**▲▲▲▲▲▲業務サービスの主処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 売上オーソリ結果リストを作成します。
	 * 
	 * @param inMap　入力電文
	 * @return JBSbatOutputItem　出力情報
	 * @throws Exception　業務サービス内で発生した例外全般
	 */
	private JBSbatOutputItem makeAuthoriRsltList(JBSbatServiceInterfaceMap inMap) throws Exception
	{
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][makeAuthoriRsltList]");
		
		JBSbatOutputItem outputItem = new JBSbatOutputItem();
		
		// 売上オーソリ結果リスト
		JBSbatServiceInterfaceMap authoriRsltListInfo = new JBSbatServiceInterfaceMap();
		
		// 項番カウンタに加算
		noCnt++;
		// 項番
		authoriRsltListInfo.setString(JBSbatCHIFE055.NO, noCnt);
		// 結果
		authoriRsltListInfo.setString(JBSbatCHIFE055.RSLT, inMap.get(JBSbatCHIFM066.SALES_AUTHORI_CHK_RSLT));
// ANK-4029-00-00 ADD START
		// 売上オーソリ結果コードが「3」(エラー)の場合、結果を再設定する
		if (JACStrConst.SALES_AUTHORI_RSLT_CD_ERR.equals((String)inMap.get(JBSbatCHIFM066.SALES_AUTHORI_RSLT_CD)))
		{
			authoriRsltListInfo.setString(JBSbatCHIFE055.RSLT, JACStrConst.AUTHORI_CHK_RSLT_ERR);
		}
// ANK-4029-00-00 ADD END
		// 処理結果コード
		authoriRsltListInfo.setString(JBSbatCHIFE055.TRN_RSLT_CD, editTRN_RSLT_CD((String)inMap.get(JBSbatCHIFM066.TRN_RSLT_CD)));
		// 処理結果内容
		authoriRsltListInfo.setString(JBSbatCHIFE055.TRN_RSLT_NAIYO, inMap.get(JBSbatCHIFM066.TRN_RSLT_NAIYO));
		// オーソリ承認番号
		authoriRsltListInfo.setString(JBSbatCHIFE055.AUTHORI_SHONIN_NO, inMap.get(JBSbatCHIFM066.AUTHORI_SHONIN_NO));
		// 請求月
		authoriRsltListInfo.setString(JBSbatCHIFE055.SEIKY_MON, editSEIKY_MON((String)inMap.getString(JBSbatCHIFM066.SEIKY_YM)));
		// 請求額
		authoriRsltListInfo.setString(JBSbatCHIFE055.SEIKY_AMNT, editSEIKY_AMNT((String)inMap.get(JBSbatCHIFM066.SEIKY_AMNT)));
		// 合算有無
		authoriRsltListInfo.setString(JBSbatCHIFE055.GSAN_UM, editGSAN_UM((String)inMap.get(JBSbatCHIFM066.MINO_GSAN_UM)));
		// 督促ステータス
		authoriRsltListInfo.setString(JBSbatCHIFE055.TOKUSOKU_STAT, inMap.get(JBSbatCHIFM066.TOKUSOKU_STAT));
		// 督促ステータス内容
		authoriRsltListInfo.setString(JBSbatCHIFE055.TOKUSOKU_STAT_NAIYO, inMap.get(JBSbatCHIFM066.TOKUSOKU_STAT_NM));
		// 請求契約番号
		authoriRsltListInfo.setString(JBSbatCHIFE055.SEIKY_KEI_NO, inMap.get(JBSbatCHIFM066.SEIKY_KEI_NO));
		// 請求先（カナ）
		authoriRsltListInfo.setString(JBSbatCHIFE055.SEIKY_SAKI_NM_KANA, editSEIKY_SAKI_NM_KANA((String)inMap.get(JBSbatCHIFM066.SEIKY_SAKI_NM_KANA)));
		// クレジット会社交換コード
		authoriRsltListInfo.setString(JBSbatCHIFE055.CRDT_COMP_KOKAN_CD, inMap.get(JBSbatCHIFM066.CRECARD_COMP_KOKAN_CD));
		// クレジット会社コード
		authoriRsltListInfo.setString(JBSbatCHIFE055.CRDT_COMP_CD, inMap.get(JBSbatCHIFM066.CRECARD_COMP_CD));
		// クレジット会社名
		authoriRsltListInfo.setString(JBSbatCHIFE055.CRDT_COMP_NM, inMap.get(JBSbatCHIFM066.CRDT_COMP_NM));
		//ANK-3846-00-00 ADD START
		// クレジットカード種別名
		authoriRsltListInfo.setString(JBSbatCHIFE055.CRECARD_SBT_NM, inMap.get(JBSbatCHIFM066.CRECARD_SBT_NM));
		//クレジットイシュア区分名(国内／海外)
		authoriRsltListInfo.setString(JBSbatCHIFE055.CRDT_ISSUER_NM, inMap.get(JBSbatCHIFM066.CRDT_ISSUER_NM));	
		//ANK-3846-00-00 ADD END
		// 出力情報を""で囲む
		authoriRsltListInfo.setMap(JACBatCommon.quote(authoriRsltListInfo.getMap(), JACStrConst.DOUBLE_QUOTE, JACStrConst.DOUBLE_QUOTE));
		
		// 出力フラグON
		authoriRsltListInfo.setOutFlg(true);
		
		// 出力共通電文
		outputItem.addOutMapList(authoriRsltListInfo);
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[L][makeAuthoriRsltList][authoriRsltListInfo=" + authoriRsltListInfo.getMap().toString() + "]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][makeAuthoriRsltList]");
		
		return outputItem;
	}
	/**
	 * 業務サービス終了処理
	 * @throws Exception
	 */
	public void terminal() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの終了処理を記述してください。▼▼▼▼▼▼*/
		/**▼▼▼▼▼▼ツールから生成した終了処理のソースです 開始▼▼▼▼▼▼*/
		/**▲▲▲▲▲▲ツールから生成した終了処理のソースです 終了▲▲▲▲▲▲*/
		
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[S][terminal]");
		assert JACbatDebugLogUtil.printDebugLog(super.logPrint, "[E][terminal]");
	
	/**▲▲▲▲▲▲業務サービスの終了処理を記述してください。▲▲▲▲▲▲*/
	}

	/**▼▼▼▼▼▼ツールから生成したメソッドです 開始▼▼▼▼▼▼*/
	/**▲▲▲▲▲▲ツールから生成したメソッドです 終了▲▲▲▲▲▲*/
	
	
	/*
	 * 処理結果コード編集
	 * （xxx-xxxx）
	 * 
	 * @param inStr　入力文字列
	 * @return String 編集済文字列
	 */
	private String editTRN_RSLT_CD(String str)
	{
		int TRN_RSLT_CD_P1LEN = 3;
		if(str != null && str.length() > 0) {
			return str.substring(0, TRN_RSLT_CD_P1LEN) + "-" + str.substring(TRN_RSLT_CD_P1LEN, str.length());
		} else {
			return str;
		}
	}
	
	/*
	 * 請求月編集
	 * （YYYY/MM）
	 * 
	 * @param inStr　入力文字列
	 * @return String 編集済文字列
	 */
	private String editSEIKY_MON(String str)
	{
		int SEIKY_MON_P1LEN = 4;
		if(str != null && str.length() > 0) {
			return str.substring(0, SEIKY_MON_P1LEN) + "/" + str.substring(SEIKY_MON_P1LEN, str.length());
		} else {
			return str;
		}
	}

	/*
	 * 合算有無編集
	 * （0 -> "無", 1 -> "有"）
	 * 
	 * @param inStr　入力文字列
	 * @return String 編集済文字列
	 */
	private String editGSAN_UM(String str)
	{
		String GSAN_NASHI = "無";
		String GSAN_ARI = "有";
		if(str != null && str.length() > 0) {
			if(str.equals("0")) {
				return GSAN_NASHI;
			} else if(str.equals("1")) {
				return GSAN_ARI;
				
			} else {
				return str;
			}
		} else {
			return str;
		}
	}

	/*
	 * 請求額編集
	 * （ZZZ,ZZZ,ZZZ,ZZ9）
	 * 
	 * @param inStr　入力文字列
	 * @return String 編集済文字列
	 */
	private String editSEIKY_AMNT(String str)
	{
		if (str != null && str.length() > 0) {
			DecimalFormat fmt;
			try {
				double d = Double.parseDouble(str);
				fmt = new DecimalFormat("#,###");
				String s = fmt.format(d);
				return s;
			} catch (IllegalArgumentException e) {
				return str;
			}
		} else {
			return str;
		}
	}

	/*
	 * 請求先名（カナ）編集
	 * 先頭25文字を返却
	 * 
	 * @param inStr　入力文字列
	 * @return String 編集済文字列
	 */
	private String editSEIKY_SAKI_NM_KANA(String str)
	{
		int CRDT_COMP_NM_LEN = 25;
		if(str != null && str.length() > CRDT_COMP_NM_LEN) {
			return str.substring(0, CRDT_COMP_NM_LEN);
		} else {
			return str;
		}
	}
}
