/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatCHMtOnerCreSeikyInf
*	ソースファイル名	：JBSbatCHMtOnerCreSeikyInf.java
*	作成者				：富士通　
*	作成日				：2024年08月06日
*＜機能概要＞
*　マンションオーナー問合せ先印刷対象請求先生成部品です。
*＜修正履歴＞
*	バージョン	修正日		 修正者		 修正内容
*	v71.00.00	2024/08/06   FJ) 山岡	【ANK-4595-00-00】請求書の問い合わせ先追加対応
*	v71.00.01	2024/09/03   FJ) 山岡	 IT1-2024-0000036【ANK-4595-00-00】請求書の問い合わせ先追加対応
*********************************************************************/
package eo.business.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

import eo.business.common.JBSbatBusinessService;
import eo.business.common.JKKBatConst;
import eo.business.util.file.JBSbatCHIFM473;
import eo.business.util.file.JBSbatCHIFM474;
import eo.common.util.JPCUtilCommon;
import eo.framework.file.JBSbatDefFileUtil;
import eo.framework.file.JBSbatInputFileUtil;
import eo.framework.item.JBSbatCommonItem;
import eo.framework.item.JBSbatOutputItem;
import eo.framework.item.JBSbatServiceInterfaceMap;
import eo.framework.util.JBSbatAplConst;

/**
* (クラスの機能概要) <p>
*<BR>
* @author 富士通
*/
public class JBSbatCHMtOnerCreSeikyInf extends JBSbatBusinessService
{
	/**▼▼▼▼▼▼ツールから生成した宣言です 開始▼▼▼▼▼▼*/
	
	/**▲▲▲▲▲▲ツールから生成した宣言です 終了▲▲▲▲▲▲*/
	
	
	/** freeパラメタ：請求契約番号 */
	private ArrayList<HashMap<String, String>> seikyKeiNoList = null;
	
	/**
	 * 初期処理
	 * @param JBSbatCommonItem commonItem　バッチ共通パラメータ電文
	 * @throws Exception
	 */
	public void initial(JBSbatCommonItem commonItem) throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの初期処理を記述してください。▼▼▼▼▼▼*/
		
		/**▼▼▼▼▼▼ツールから生成した初期化のソースです 開始▼▼▼▼▼▼*/
		
		// 共通パラメータを設定します
		super.setCommonInfo(commonItem);
		
		/**▲▲▲▲▲▲ツールから生成した初期化のソースです 終了▲▲▲▲▲▲*/
		
		// 初期化
		this.seikyKeiNoList = new ArrayList<HashMap<String,String>>();
		
		// フリー項目取得
		String[] freeItem = super.freeItem.split(JKKBatConst.S_PARAM_DELIM);
		
		// 起動パラメータ FREEパラメタ を元に,クラス変数へ値を保持.
		//20240903_IT1-2024-0000036 MOD START
//		setFreePararm(freeItem[0], "CHIFM471.def");
		setFreePararm(freeItem[0], "CHIFM473.def");
		//20240903_IT1-2024-0000036 MOD END		
		
	/**▲▲▲▲▲▲業務サービスの初期処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 主処理
	 * @return JBSbatOutputItem　出力情報
	 * @throws Exception
	 */
	public JBSbatOutputItem execute() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの主処理を記述してください。▼▼▼▼▼▼*/
		
		// 対象（mineo単独請求抽出）請求契約番号出力
		return setTgSeikyKeiNoInfo();
		
	/**▲▲▲▲▲▲業務サービスの主処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 業務サービス終了処理
	 * @throws Exception
	 */
	public void terminal() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの終了処理を記述してください。▼▼▼▼▼▼*/
		
		/**▼▼▼▼▼▼ツールから生成した終了処理のソースです 開始▼▼▼▼▼▼*/
		
		/**▲▲▲▲▲▲ツールから生成した終了処理のソースです 終了▲▲▲▲▲▲*/
		
	/**▲▲▲▲▲▲業務サービスの終了処理を記述してください。▲▲▲▲▲▲*/
	}

	/**▼▼▼▼▼▼ツールから生成したメソッドです 開始▼▼▼▼▼▼*/
	
	/**▲▲▲▲▲▲ツールから生成したメソッドです 終了▲▲▲▲▲▲*/
	
	/**
	 * 
	 * freeパラメタ設定
	 * 
	 * @param  path
	 * @param  def
	 */
	private void setFreePararm(String path, String def) throws Exception {
		
		super.logPrint.printDebugLog("setFreePararm() START [def：" + path + "]");
		
		JBSbatServiceInterfaceMap rowMap = null;
		
		JBSbatInputFileUtil readObj      = new JBSbatInputFileUtil(path);
		JBSbatDefFileUtil   fileDef      = new JBSbatDefFileUtil(JBSbatAplConst.getAplConstValue("IND") + def, readObj);
		
		readObj.createReader();
		
		String line = "";
		while(readObj.ready()) {
			
			line   = readObj.readLine();
			rowMap = fileDef.lineToObject(line, readObj, 0);
			
			// 格納リストへ設定
			this.seikyKeiNoList.add(retKey(rowMap));
		}
		
		// 閉じる
		if (readObj != null)
			readObj.close();
		
		// 初期化
		readObj = null;
		
		super.logPrint.printDebugLog("setFreePararm() END");
	}
	
	/**
	 * 
	 * key付与して返却
	 * 
	 * @param  adRowMap
	 * @return 
	 * @throws Exception
	 */
	private HashMap<String, String> retKey(JBSbatServiceInterfaceMap adRowMap) throws Exception {
		
		HashMap<String, String> ret = new HashMap<String, String>();
		//20240903_IT1-2024-0000036 MOD START
//		ret.put(JBSbatCHIFM471.SEIKY_KEI_NO, adRowMap.getString(JBSbatCHIFM471.SEIKY_KEI_NO));
		ret.put(JBSbatCHIFM473.SEIKY_KEI_NO, adRowMap.getString(JBSbatCHIFM473.SEIKY_KEI_NO));
		//20240903_IT1-2024-0000036 MOD END
		return ret;
	}
	
	/**
	 * マンションオーナー問合せ先印刷対象請求先情報を作成します。
	 * 
	 * @return JBSbatOutputItem マンションオーナー問合せ先印刷対象請求先情報
	 * @throws Exception 
	 */
	private JBSbatOutputItem setTgSeikyKeiNoInfo() throws Exception
	{
		super.logPrint.printDebugLog("setTgSeikyKeiNoInfo() START");
		
		JBSbatOutputItem oBean = new JBSbatOutputItem();		
		
		int i = 0;
		// データレコード
		for (HashMap<String, String> tg : this.seikyKeiNoList) {
			//20240903_IT1-2024-0000036 MOD START
//			String sKno = tg.get(JBSbatCHIFM471.SEIKY_KEI_NO);
			String sKno = tg.get(JBSbatCHIFM473.SEIKY_KEI_NO);
			//20240903_IT1-2024-0000036 MOD END
			BigDecimal cnt = new BigDecimal(i + 1);
			
			// 出力対象項目格納領域作成
			JBSbatServiceInterfaceMap oMap = new JBSbatServiceInterfaceMap();
			
			// レコード長10バイト、請求契約番号
			oMap.setString(JBSbatCHIFM474.CLAIM_NO,      sKno);
			// レコード長1バイト、レコード識別：4マンションオーナー請求
			oMap.setString(JBSbatCHIFM474.END_REC_SKBT,  "4");
			// レコード長19バイト、連番6桁左0埋め、残り13桁右空白埋め
			oMap.setString(JBSbatCHIFM474.SEQ,           JPCUtilCommon.fillHalfSpace(JPCUtilCommon.fillZero(cnt.toString(), 6, false), 19, true));
			// 全体レコード長30バイト
			oMap.setOutFlg(true);
			oBean.addOutMapList(oMap);
			
			i++;
		}
		
		
		super.logPrint.printDebugLog("setTgSeikyKeiNoInfo() END");
		return oBean;
	}
}
