/*********************************************************************
*  All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名			：eo顧客基幹システム
*	モジュール名		：JBSbatCHNttoCreSeikyInf
*	ソースファイル名	：JBSbatCHNttoCreSeikyInf.java
*	作成者				：富士通　
*	作成日				：2015年01月06日
*＜機能概要＞
*　NTT卸問合せ先印刷対象請求先生成部品です。
*＜修正履歴＞
*	バージョン	修正日		 修正者		 修正内容
*	v73.00.00	2024/11/11   FJ) 張    新規作成【ANK-4427-00-00】NTT卸対応：STEP1
*********************************************************************/
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.JBSbatCHIFM486;
import eo.business.util.file.JBSbatCHIFM487;
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 JBSbatCHNttoCreSeikyInf 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パラメタ を元に,クラス変数へ値を保持.
		setFreePararm(freeItem[0], "CHIFM486.def");
		
		
	/**▲▲▲▲▲▲業務サービスの初期処理を記述してください。▲▲▲▲▲▲*/
	}

	/**
	 * 主処理
	 * @return JBSbatOutputItem　出力情報
	 * @throws Exception
	 */
	public JBSbatOutputItem execute() throws Exception
	{
	/**▼▼▼▼▼▼業務サービスの主処理を記述してください。▼▼▼▼▼▼*/
		
		// 対象（NTT卸単独請求抽出）請求契約番号出力
		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(retCHIFM238(rowMap));
		}
		
		// 閉じる
		if (readObj != null)
			readObj.close();
		
		// 初期化
		readObj = null;
		
		super.logPrint.printDebugLog("setFreePararm() END");
	}
	
	/**
	 * 
	 * key付与して返却
	 * 
	 * @param  adRowMap
	 * @return 
	 * @throws Exception
	 */
	private HashMap<String, String> retCHIFM238(JBSbatServiceInterfaceMap adRowMap) throws Exception {
		
		HashMap<String, String> ret = new HashMap<String, String>();
		
		ret.put(JBSbatCHIFM486.SEIKY_KEI_NO, adRowMap.getString(JBSbatCHIFM486.SEIKY_KEI_NO));
		
		return ret;
	}
	
	/**
	 * NTT卸問合せ先印刷対象請求先情報を作成します。
	 * 
	 * @return JBSbatOutputItem NTT卸問合せ先印刷対象請求先情報
	 * @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) {
			//NTT卸単独請求抽出アンローダファイル　請求先番号
			String sKno = tg.get(JBSbatCHIFM486.SEIKY_KEI_NO);
			
			
			BigDecimal cnt = new BigDecimal(i + 1);
			
			// 出力対象項目格納領域作成
			JBSbatServiceInterfaceMap oMap = new JBSbatServiceInterfaceMap();
			
			oMap.setString(JBSbatCHIFM487.CLAIM_NO,      sKno);
			//レコード識別　5:NTT卸
			String REC_SKBT = "5";
			oMap.setString(JBSbatCHIFM487.END_REC_SKBT,  REC_SKBT);
			oMap.setString(JBSbatCHIFM487.SEQ,           JPCUtilCommon.fillHalfSpace(JPCUtilCommon.fillZero(cnt.toString(), 6, false), 19, true));
			oMap.setOutFlg(true);
			oBean.addOutMapList(oMap);
			
			i++;
		}
		
		super.logPrint.printDebugLog("setTgSeikyKeiNoInfo() END");
		return oBean;
	}
}
