package com.seeyon.apps.jync_file.util;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.jync_file.kit.form.CAP4FormKit;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.cap4.form.bean.FormDataSubBean;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.SystemEnvironment;
import com.seeyon.ctp.common.ctpenumnew.manager.EnumManager;
import com.seeyon.v3x.dee.util.DateUtil;

public class ParamUtil {

	private static final Log log = LogFactory.getLog(ParamUtil.class);

	private  EnumManager enumManagerNew;

	public void setEnumManagerNew(EnumManager enumManagerNew) {
		this.enumManagerNew = enumManagerNew;
	}

	public EnumManager getEnumManagerNew() {
		if (enumManagerNew == null) {
			enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");
		}
		return enumManagerNew;
	}

	/**
	 * 薪酬分账参数封装
	 * @param master
	 * @param summaryId
	 * @return
	 * @throws IOException
	 */
	public JSONObject getXinChouFenZhangParam(FormDataMasterBean master,String summaryId) throws IOException{
		JSONObject jsonObject = new JSONObject();
		JSONArray jsonArray = new JSONArray();
		List<FormDataSubBean> formDataSubBeans = CAP4FormKit.getSubBeans(master,"分账明细表");
		List<Object> istrue = new ArrayList<Object>();
		String isbearid =  CAP4FormKit.getFieldStrValue(master, "支付公司是否成本承担公司");
		String isbear = "";
		if("".equals(isbearid)){
			isbear = "否";
		}else {
			isbear =  getEnumManagerNew().getEnumItem(Long.parseLong(isbearid)).getLabel();
		}
		for (FormDataSubBean formDataSubBean : formDataSubBeans) {
			if(CAP4FormKit.getSubFieldValue(formDataSubBean, "BIP单据号")!=null) {
				istrue.add(CAP4FormKit.getSubFieldValue(formDataSubBean, "BIP单据号"));
			}
			JSONObject subjson = new JSONObject();
			subjson.put("psndoccode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款人编码"));
			subjson.put("businessdate", CAP4FormKit.getFieldStrValue(master, "单据日期"));
			JSONArray data = new JSONArray();
			JSONObject jsondata = new JSONObject();
			jsondata.put("scomment", CAP4FormKit.getFieldStrValue(master, "摘要内容"));
			jsondata.put("field0120", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账税率"));
			jsondata.put("field0121", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账税额"));
			jsondata.put("field0119", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账行无税金额"));
			jsondata.put("money", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账原币金额"));
			jsondata.put("jsfs", CAP4FormKit.getFieldStrValue(master, "结算方式编号"));
			jsondata.put("kmdl", CAP4FormKit.getFieldStrValue(master, "科目大类编号"));
			jsondata.put("szxm", CAP4FormKit.getFieldStrValue(master, "收支项目编号"));
//				String fkyw = CAP4FormKit.getFieldStrValue(master, "可选转账用途");
//				String fkywvalue = enumManagerNew.getEnumItem(Long.parseLong(fkyw)).getValue();
//				jsondata.put("fkyw", fkywvalue);
			jsondata.put("fkyw", "OA");
			data.add(jsondata);
			subjson.put("data", data);
			if("是".equals(isbear)) {
				subjson.put("orgcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账组织编码"));
				subjson.put("fkbankcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账付款银行账号"));
			}else {
				subjson.put("orgcode", CAP4FormKit.getFieldStrValue(master, "主表支付公司编码"));
				subjson.put("fkbankcode", CAP4FormKit.getFieldStrValue(master, "付款银行账号"));
			}
			subjson.put("skbankcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款银行账号"));
			subjson.put("path", "/seeyon/cst/flowInfo.do?summaryId="+summaryId);
			subjson.put("oabillcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账单据流水号"));
			subjson.put("field0006", CAP4FormKit.getFieldStrValue(master, "原始单据数"));
			subjson.put("suppliercode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款人编码"));
			subjson.put("yt", CAP4FormKit.getFieldStrValue(master, "摘要内容"));
			String busitypecodeId = CAP4FormKit.getFieldStrValue(master, "业务流程");
			String busitypecodeCode = getEnumManagerNew().getEnumItem(Long.parseLong(busitypecodeId)).getEnumItemCode();
			String busitypecode = busitypecodeCode.substring(5);
			subjson.put("busitypecode", busitypecode);
			String wldxid = "";
			if(CAP4FormKit.getSubFieldValue(formDataSubBean, "往来对象")!=null) {
				wldxid = CAP4FormKit.getSubFieldValue(formDataSubBean, "往来对象").toString();
			}
			String wldxCode = getEnumManagerNew().getEnumItem(Long.parseLong(wldxid)).getEnumItemCode();
			String wldxvalue = wldxCode.substring(5);
			subjson.put("wldx", wldxvalue);
			subjson.put("fklx", "D3");
			jsonArray.add(subjson);
		}
		jsonObject.put("data", jsonArray);
		System.out.println(istrue.size()==formDataSubBeans.size());
		if(istrue.size()==formDataSubBeans.size()) {
			jsonObject = new JSONObject();
		}
		String str = SystemEnvironment.getApplicationFolder();
		String date = DateUtil.format(new Date(), "yyyyMMddHHmmss");
		FileUtils.writeStringToFile(new File(str+"/bipjson/"+date.substring(0,4)+"/"+date.substring(5,6)+"/"+date.substring(7,8)+"/XCFZ_" + date + ".json"), jsonObject.toString(), "UTF-8");
		return jsonObject;
	}


	/**
	 * 通用分账参数封装
	 * @param master
	 * @param summaryId
	 * @return
	 * @throws IOException
	 */
	public JSONObject getTongYongFenZhangParam(FormDataMasterBean master,String summaryId) throws IOException{
		JSONObject jsonObject = new JSONObject();
		JSONArray jsonArray = new JSONArray();
		List<FormDataSubBean> formDataSubBeans = CAP4FormKit.getSubBeans(master,"分账明细表");
//		List<Object> istrue = new ArrayList<Object>();
		String isbearid =  CAP4FormKit.getFieldStrValue(master, "支付公司是否成本承担公司");
		String isbear = "";
		if("".equals(isbearid)){
			isbear = "否";
		}else {
			isbear =  getEnumManagerNew().getEnumItem(Long.parseLong(isbearid)).getLabel();
		}
		for (FormDataSubBean formDataSubBean : formDataSubBeans) {
//			if(CAP4FormKit.getSubFieldValue(formDataSubBean, "BIP单据号")!=null) {
//				istrue.add(CAP4FormKit.getSubFieldValue(formDataSubBean, "BIP单据号"));
//			}
			String num = CAP4FormKit.getSubFieldValue(formDataSubBean, "分账原币金额").toString();
			if("0".equals(num)) {
				log.info("分账原币金额为0，跳过处理："+ CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款人编码"));
				continue;
			}
			JSONObject subjson = new JSONObject();
			subjson.put("psndoccode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款人编码"));
			subjson.put("businessdate", CAP4FormKit.getFieldStrValue(master, "单据日期"));
			JSONArray data = new JSONArray();
			JSONObject jsondata = new JSONObject();
			jsondata.put("scomment", CAP4FormKit.getFieldStrValue(master, "摘要内容"));
			jsondata.put("field0120", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账税率"));
			jsondata.put("field0121", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账税额"));
			jsondata.put("field0119", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账行无税金额"));
//				jsondata.put("field0120", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账税率"));
//				jsondata.put("field0121", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账税额"));
//				jsondata.put("field0119", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账行无税金额"));
			jsondata.put("money", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账原币金额"));
			jsondata.put("jsfs", CAP4FormKit.getFieldStrValue(master, "结算方式编号"));
			jsondata.put("kmdl", CAP4FormKit.getFieldStrValue(master, "科目大类编号"));
			jsondata.put("szxm", CAP4FormKit.getFieldStrValue(master, "收支项目编号"));
			jsondata.put("fkyw", "OA");
			data.add(jsondata);
			subjson.put("data", data);
			if("是".equals(isbear)) {
				subjson.put("orgcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账组织编码"));
				subjson.put("fkbankcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账付款银行账号"));
			}else {
				subjson.put("orgcode", CAP4FormKit.getFieldStrValue(master, "主表支付公司编码"));
				subjson.put("fkbankcode", CAP4FormKit.getFieldStrValue(master, "付款银行账号"));
			}
			subjson.put("skbankcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款银行账号"));
			subjson.put("path", "/seeyon/cst/flowInfo.do?summaryId="+summaryId);
			subjson.put("oabillcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账单据流水号"));
			subjson.put("field0006", CAP4FormKit.getFieldStrValue(master, "原始单据数"));
			subjson.put("suppliercode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款人编码"));
			subjson.put("yt", CAP4FormKit.getFieldStrValue(master, "摘要内容"));
			String busitypecodeId = CAP4FormKit.getFieldStrValue(master, "业务流程");
			String busitypecodeCode = getEnumManagerNew().getEnumItem(Long.parseLong(busitypecodeId)).getEnumItemCode();
			String busitypecode = busitypecodeCode.substring(5);
			subjson.put("busitypecode", busitypecode);
			String wldxid = "";
			if(CAP4FormKit.getSubFieldValue(formDataSubBean, "往来对象")!=null) {
				wldxid = CAP4FormKit.getSubFieldValue(formDataSubBean, "往来对象").toString();
			}
			String wldxCode = getEnumManagerNew().getEnumItem(Long.parseLong(wldxid)).getEnumItemCode();
			String wldxvalue = wldxCode.substring(5);
			subjson.put("wldx", wldxvalue);
			subjson.put("fklx", "D3");
			jsonArray.add(subjson);
		}
		jsonObject.put("data", jsonArray);
//		System.out.println(istrue.size()==formDataSubBeans.size());
//		if(istrue.size()==formDataSubBeans.size()) {
//			jsonObject = new JSONObject();
//		}
		String str = SystemEnvironment.getApplicationFolder();
		String date = DateUtil.format(new Date(), "yyyyMMddHHmmss");
		FileUtils.writeStringToFile(new File(str+"/bipjson/"+date.substring(0,4)+"/"+date.substring(5,6)+"/"+date.substring(7,8)+"/TYFZ_" + date + ".json"), jsonObject.toString(), "UTF-8");
		return jsonObject;
	}


	/**
	 * 社保分账参数封装
	 * @param master
	 * @param summaryId
	 * @return
	 * @throws IOException
	 */
	public JSONObject getSheBaoFenZhangParam(FormDataMasterBean master,String summaryId) throws IOException{
		JSONObject jsonObject = new JSONObject();
		JSONArray jsonArray = new JSONArray();
		List<FormDataSubBean> formDataSubBeans = CAP4FormKit.getSubBeans(master,"分账明细表");
		List<Object> istrue = new ArrayList<Object>();
		String isbearid =  CAP4FormKit.getFieldStrValue(master, "支付公司是否成本承担公司");
		String isbear = "";
		if("".equals(isbearid)){
			isbear = "否";
		}else {
			isbear =  getEnumManagerNew().getEnumItem(Long.parseLong(isbearid)).getLabel();
		}
		String isunitid =  CAP4FormKit.getFieldStrValue(master, "是否同一收款单位");
		String isunit = "";
		if("".equals(isunitid)){
			isunit = "是";
		}else {
			isunit =  getEnumManagerNew().getEnumItem(Long.parseLong(isunitid)).getLabel();
		}
		if("是".equals(isunit) && "否".equals(isbear)) {
//			istrue.add(CAP4FormKit.getFieldStrValue(master, "BIP单据编号"));
			JSONObject subjson = new JSONObject();
			subjson.put("psndoccode", CAP4FormKit.getFieldStrValue(master, "收款单位编码"));
			subjson.put("businessdate", CAP4FormKit.getFieldStrValue(master, "单据日期"));
			JSONArray data = new JSONArray();
			JSONObject jsondata = new JSONObject();
			jsondata.put("scomment", CAP4FormKit.getFieldStrValue(master, "摘要内容"));
			jsondata.put("field0120", "0");
			jsondata.put("field0121", "0");
			jsondata.put("money", CAP4FormKit.getFieldStrValue(master, "合计分账支付"));
			jsondata.put("jsfs", CAP4FormKit.getFieldStrValue(master, "结算方式编号"));
			jsondata.put("kmdl", CAP4FormKit.getFieldStrValue(master, "科目大类编号"));
			jsondata.put("szxm", CAP4FormKit.getFieldStrValue(master, "收支项目编号"));
			jsondata.put("field0119","0");
//				String fkyw = CAP4FormKit.getFieldStrValue(master, "可选转账用途");
//				String fkywvalue = enumManagerNew.getEnumItem(Long.parseLong(fkyw)).getValue();
//				jsondata.put("fkyw", fkywvalue);
			jsondata.put("fkyw", "OA");
			data.add(jsondata);
			subjson.put("data", data);
			subjson.put("orgcode", CAP4FormKit.getFieldStrValue(master, "主表支付公司编码"));
			subjson.put("fkbankcode", CAP4FormKit.getFieldStrValue(master, "付款银行账号"));
			subjson.put("skbankcode", CAP4FormKit.getFieldStrValue(master, "收款银行账号"));
			subjson.put("path", "/seeyon/cst/flowInfo.do?summaryId="+summaryId);
			subjson.put("oabillcode", CAP4FormKit.getFieldStrValue(master, "单据流水号"));
			subjson.put("field0006", CAP4FormKit.getFieldStrValue(master, "原始单据数"));
			subjson.put("suppliercode", CAP4FormKit.getFieldStrValue(master, "收款单位编码"));
			subjson.put("yt", CAP4FormKit.getFieldStrValue(master, "摘要内容"));
			String wldxid = "";
			if(CAP4FormKit.getFieldStrValue(master, "表头往来对象")!=null) {
				wldxid = CAP4FormKit.getFieldStrValue(master, "表头往来对象").toString();
			}
			String wldxCode = getEnumManagerNew().getEnumItem(Long.parseLong(wldxid)).getEnumItemCode();
			String wldxvalue = wldxCode.substring(5);
			subjson.put("wldx", wldxvalue);
			subjson.put("fklx", "D3");
			jsonArray.add(subjson);
		}else {
			for (FormDataSubBean formDataSubBean : formDataSubBeans) {
				if(CAP4FormKit.getSubFieldValue(formDataSubBean, "BIP单据号")!=null) {
					istrue.add(CAP4FormKit.getSubFieldValue(formDataSubBean, "BIP单据号"));
				}
				JSONObject subjson = new JSONObject();
				if("否".equals(isunit)) {
					subjson.put("psndoccode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款人编码"));
					subjson.put("skbankcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款银行账号"));
					subjson.put("suppliercode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账收款人编码"));
				}else {
					subjson.put("psndoccode", CAP4FormKit.getFieldStrValue(master, "收款单位编码"));
					subjson.put("skbankcode", CAP4FormKit.getFieldStrValue(master, "收款银行账号"));
					subjson.put("suppliercode", CAP4FormKit.getFieldStrValue(master, "收款单位编码"));
				}
				subjson.put("businessdate", CAP4FormKit.getFieldStrValue(master, "单据日期"));
				JSONArray data = new JSONArray();
				JSONObject jsondata = new JSONObject();
				jsondata.put("scomment", CAP4FormKit.getFieldStrValue(master, "摘要内容"));
				jsondata.put("field0120", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账税率"));
				jsondata.put("field0121", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账税额"));
				jsondata.put("field0119", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账行无税金额"));
				jsondata.put("money", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账原币金额"));
				jsondata.put("jsfs", CAP4FormKit.getFieldStrValue(master, "结算方式编号"));
				jsondata.put("kmdl", CAP4FormKit.getFieldStrValue(master, "科目大类编号"));
				jsondata.put("szxm", CAP4FormKit.getFieldStrValue(master, "收支项目编号"));
//					String fkyw = CAP4FormKit.getFieldStrValue(master, "可选转账用途");
//					String fkywvalue = enumManagerNew.getEnumItem(Long.parseLong(fkyw)).getValue();
//					jsondata.put("fkyw", fkywvalue);
				jsondata.put("fkyw", "OA");
				data.add(jsondata);
				subjson.put("data", data);
				if("是".equals(isbear)) {
					subjson.put("orgcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账组织编码"));
					subjson.put("fkbankcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账付款银行账号"));
				}
				else {
					subjson.put("orgcode", CAP4FormKit.getFieldStrValue(master, "主表支付公司编码"));
					subjson.put("fkbankcode", CAP4FormKit.getFieldStrValue(master, "付款银行账号"));
				}
				subjson.put("path", "/seeyon/cst/flowInfo.do?summaryId="+summaryId);
				subjson.put("oabillcode", CAP4FormKit.getSubFieldValue(formDataSubBean, "分账单据流水号"));
				subjson.put("field0006", CAP4FormKit.getFieldStrValue(master, "原始单据数"));
				subjson.put("yt", CAP4FormKit.getFieldStrValue(master, "摘要内容"));
				//业务流程
//				String busitypecodeId = CAP4FormKit.getFieldStrValue(master, "业务流程");
//				String busitypecodeCode = getEnumManagerNew().getEnumItem(Long.parseLong(busitypecodeId)).getEnumItemCode();
//				String busitypecode = busitypecodeCode.substring(5);
//				subjson.put("busitypecode", busitypecode);
				String wldxid = "";
				if(CAP4FormKit.getSubFieldValue(formDataSubBean, "往来对象")!=null) {
					wldxid = CAP4FormKit.getSubFieldValue(formDataSubBean, "往来对象").toString();
				}
				String wldxCode = getEnumManagerNew().getEnumItem(Long.parseLong(wldxid)).getEnumItemCode();
				String wldxvalue = wldxCode.substring(5);
				subjson.put("wldx", wldxvalue);
				subjson.put("fklx", "D3");
				jsonArray.add(subjson);
			}
		}

		jsonObject.put("data", jsonArray);
		System.out.println(istrue.size()==formDataSubBeans.size());
		if(istrue.size()==formDataSubBeans.size()) {
			jsonObject = new JSONObject();
		}
		String str = SystemEnvironment.getApplicationFolder();
		String date = DateUtil.format(new Date(), "yyyyMMddHHmmss");
		FileUtils.writeStringToFile(new File(str+"/bipjson/"+date.substring(0,4)+"/"+date.substring(5,6)+"/"+date.substring(7,8)+"/SBFZ_" + date + ".json"), jsonObject.toString(), "UTF-8");
		return jsonObject;
	}

	/**
	 * 薪酬分账终止参数
	 * @param master
	 * @return
	 * @throws IOException
	 */
	public JSONObject getXinChouFenZhangStopParam(FormDataMasterBean master) throws IOException{
		JSONObject jsonObject = new JSONObject();
		System.out.println("设置终止参数");
		String billcode = CAP4FormKit.getFieldStrValue(master, "NC单据编号");
		jsonObject.put("billcode", billcode);
		jsonObject.put("status", "0");
		System.out.println("终止参数："+jsonObject);
		return jsonObject;
	}

	/**
	 * 社保分账终止参数
	 * @param master
	 * @return
	 * @throws IOException
	 */
	public JSONObject getSheBaoFenZhangStopParam(FormDataMasterBean master) throws IOException{
		JSONObject jsonObject = new JSONObject();
		System.out.println("设置终止参数");
		String billcode = CAP4FormKit.getFieldStrValue(master, "BIP单据编号");
		jsonObject.put("compose_pk", billcode);
		jsonObject.put("status", 1);
		System.out.println("终止参数："+jsonObject);
		return jsonObject;
	}

	/**
	 * 薪酬分账结束参数
	 * @param master
	 * @return
	 * @throws IOException
	 */
	public JSONObject getXinChouFenZhangEndParam(FormDataMasterBean master) throws IOException{
		JSONObject jsonObject = new JSONObject();
		System.out.println("设置流程结束参数");
		String billcode = CAP4FormKit.getFieldStrValue(master, "NC单据编号");
		jsonObject.put("billcode", billcode);
		jsonObject.put("status", "1");
		System.out.println("流程结束参数："+jsonObject);
		return jsonObject;
	}


	/**
	 * 社保分账结束参数
	 * @param master
	 * @return
	 * @throws IOException
	 */
	public JSONObject getSheBaoFenZhangEndParam(FormDataMasterBean master) throws IOException{
		JSONObject jsonObject = new JSONObject();
		System.out.println("设置流程结束参数");
		String billcode = CAP4FormKit.getFieldStrValue(master, "BIP单据编号");
		jsonObject.put("compose_pk", billcode);
		jsonObject.put("status", 2);
		System.out.println("流程结束参数："+jsonObject);
		return jsonObject;
	}


	/**
	 * 通用收款参数
	 * @param master
	 * @return
	 * @throws IOException
	 */
	public JSONObject getTongyongshoukuanParam(FormDataMasterBean master,String summaryId) throws IOException{
		JSONObject jsonObject = new JSONObject();
		System.out.println("设置通用收款参数");
		jsonObject.put("oabillcode", CAP4FormKit.getFieldStrValue(master, "单据流水号"));
		jsonObject.put("path", "/seeyon/cst/flowInfo.do?summaryId="+summaryId);
		jsonObject.put("financialOrg", CAP4FormKit.getFieldStrValue(master, "BIP公司编号"));
		jsonObject.put("billDate", CAP4FormKit.getFieldStrValue(master, "单据日期"));
		jsonObject.put("customer", CAP4FormKit.getFieldStrValue(master, "客商编号"));
		jsonObject.put("paymentAccount", CAP4FormKit.getFieldStrValue(master, "付款银行账号"));
		jsonObject.put("settlementMethod", CAP4FormKit.getFieldStrValue(master, "结算方式编码"));
		jsonObject.put("recAccount", CAP4FormKit.getFieldStrValue(master, "收款银行账号"));
//		jsonObject.put("deptid", CAP4FormKit.getFieldStrValue(master, "部门编码"));
		jsonObject.put("psndoc", CAP4FormKit.getFieldStrValue(master, "业务员编码"));
		String sklxId = CAP4FormKit.getFieldStrValue(master, "收款类型");
		String sklxCode = getEnumManagerNew().getEnumItem(Long.parseLong(sklxId)).getEnumItemCode();
		jsonObject.put("sklx",sklxCode);
		jsonObject.put("def29", CAP4FormKit.getFieldStrValue(master, "摘要"));
		jsonObject.put("prepay", CAP4FormKit.getFieldStrValue(master, "收款性质"));

		//该超级节点存在多流程共用情况，通过不同变量，兼容不同表单的数据域
		String subName =
				StringUtils.isEmpty(CAP4FormKit.getFieldStrValue(master, "明细表名称"))?"通用收费明细":CAP4FormKit.getFieldStrValue(master, "明细表名称");

		List<FormDataSubBean> formDataSubBeans = CAP4FormKit.getSubBeans(master,subName);
		JSONArray jsonArray = new JSONArray();
		for (FormDataSubBean formDataSubBean : formDataSubBeans) {
			JSONObject items = new JSONObject();

			//该超级节点存在多流程共用情况，通过不同变量，兼容不同表单的数据域
			String skywName =
					StringUtils.isEmpty(CAP4FormKit.getFieldStrValue(master, "收款业务类型名称"))?"收款业务类型编码":CAP4FormKit.getFieldStrValue(master, "收款业务类型名称");

			items.put("skyw", CAP4FormKit.getSubFieldValue(formDataSubBean, skywName));

			items.put("money", CAP4FormKit.getSubFieldValue(formDataSubBean, "本次收款金额"));
			items.put("field0120", CAP4FormKit.getSubFieldValue(formDataSubBean, "税率"));
			items.put("field0121", CAP4FormKit.getSubFieldValue(formDataSubBean, "税额"));
			items.put("field0119", CAP4FormKit.getSubFieldValue(formDataSubBean, "无税金额"));
//			items.put("subjectCode", CAP4FormKit.getSubFieldValue(formDataSubBean, "科目大类编码"));
			String subjectCode = CAP4FormKit.getSubFieldValue(formDataSubBean, "科目大类编码").toString();
			subjectCode = subjectCode.substring(5);
			items.put("subjectCode", subjectCode);//科目大类01-应收款项,02-预收款项
			items.put("scomment", CAP4FormKit.getSubFieldValue(formDataSubBean, "备注"));
			items.put("szxm", CAP4FormKit.getSubFieldValue(formDataSubBean, "收支项目编码"));
			jsonArray.add(items);
		}
		jsonObject.put("items", jsonArray);
		System.out.println("通用收款参数："+jsonObject);
		String str = SystemEnvironment.getApplicationFolder();
		String date = DateUtil.format(new Date(), "yyyyMMddHHmmss");
		FileUtils.writeStringToFile(new File(str+"/bipjson/"+date.substring(0,4)+"/"+date.substring(5,6)+"/"+date.substring(7,8)+"/TYSK_" + date + ".json"), jsonObject.toString(), "UTF-8");
		return jsonObject;
	}
}
