package com.seeyon.apps.jync_file.util;

import cn.hutool.log.Log;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.ext.workflow.vo.FieldDataVo;
import com.seeyon.apps.ext.workflow.vo.FormDataVo;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.ctpenumnew.manager.EnumManager;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ParamNewUtil {

    private static final Log log = Log.get(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 formDataVo
     * @param summaryId
     * @return
     * @throws IOException
     */
    public JSONObject getXinChouFenZhangParam(FormDataVo formDataVo, String summaryId) throws  NoSuchFieldException {
        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        Map<String, List<FormDataVo>> subFormMaps = formDataVo.getSubFormMap();
        List<FormDataVo> subFormMap = subFormMaps.get("分账明细表");
        List<Object> istrue = new ArrayList<Object>();
        FieldDataVo isbearidVo = formDataVo.getFieldData("支付公司是否成本承担公司");
        String isbearid = "";
        if(isbearidVo!=null){
            isbearid =  isbearidVo.getDbValue().toString();
        }

        String isbear = "";
        if("".equals(isbearid)){
            isbear = "否";
        }else {
            isbear =  getEnumManagerNew().getEnumItem(Long.parseLong(isbearid)).getLabel();
        }
        for (FormDataVo subFormDataVo : subFormMap) {
            FieldDataVo bipNoVo =  subFormDataVo.getFieldData("BIP单据号");
            String bipNo = "";
            if(bipNoVo!=null){
                bipNo = bipNoVo.getStringValue();
                istrue.add(bipNo);
            }
            JSONObject subjson = new JSONObject();
            FieldDataVo  psndoccodeVo = subFormDataVo.getFieldData("分账收款人编码");
            String psndoccode = "";
            if(psndoccodeVo!=null){
                psndoccode = psndoccodeVo.getStringValue();
            }
            subjson.put("psndoccode", psndoccode);
            FieldDataVo  businessdateVo = formDataVo.getFieldData("单据日期");
            String businessdate = "";
            if(businessdateVo!=null){
                businessdate = businessdateVo.getStringValue();
            }
            subjson.put("businessdate", businessdate);
            JSONArray data = new JSONArray();
            JSONObject jsondata = new JSONObject();
            FieldDataVo  scommentVo = formDataVo.getFieldData("摘要内容");
            String scomment = "";
            if(scommentVo!=null){
                scomment = scommentVo.getStringValue();
            }
            jsondata.put("scomment", scomment);
            FieldDataVo  field0120Vo = subFormDataVo.getFieldData("摘要内容");
            String field0120 = "";
            if(field0120Vo!=null){
                field0120 = field0120Vo.getStringValue();
            }
            jsondata.put("field0120", field0120);
            FieldDataVo  field0121Vo = subFormDataVo.getFieldData("分账税额");
            String field0121 = "";
            if(field0121Vo!=null){
                field0121 = field0121Vo.getStringValue();
            }
            jsondata.put("field0121", field0121);
            FieldDataVo  field0119Vo = subFormDataVo.getFieldData("分账行无税金额");
            String field0119 = "";
            if(field0119Vo!=null){
                field0119 = field0119Vo.getStringValue();
            }
            jsondata.put("field0119", field0119);
            FieldDataVo  moneyVo = subFormDataVo.getFieldData("分账原币金额");
            String money = "";
            if(moneyVo!=null){
                money = moneyVo.getStringValue();
            }
            jsondata.put("money", money);
            FieldDataVo  jsfsVo = formDataVo.getFieldData("结算方式编号");
            String jsfs = "";
            if(jsfsVo!=null){
                jsfs = jsfsVo.getStringValue();
            }
            jsondata.put("jsfs", jsfs);
            FieldDataVo  kmdlVo = formDataVo.getFieldData("科目大类编号");
            String kmdl = "";
            if(kmdlVo!=null){
                kmdl = kmdlVo.getStringValue();
            }
            jsondata.put("kmdl", kmdl);
            FieldDataVo  szxmVo = formDataVo.getFieldData("收支项目编号");
            String szxm = "";
            if(szxmVo!=null){
                szxm = szxmVo.getStringValue();
            }
            jsondata.put("szxm",szxm);
            jsondata.put("fkyw", "OA");
            data.add(jsondata);
            subjson.put("data", data);
            if("是".equals(isbear)) {
                FieldDataVo  orgcodeVo = subFormDataVo.getFieldData("分账组织编码");
                String orgcode = "";
                if(orgcodeVo!=null){
                    orgcode = orgcodeVo.getStringValue();
                }
                subjson.put("orgcode",orgcode);
                FieldDataVo  fkbankcodeVo = subFormDataVo.getFieldData("分账付款银行账号");
                String fkbankcode = "";
                if(fkbankcodeVo!=null){
                    fkbankcode = fkbankcodeVo.getStringValue();
                }
                subjson.put("fkbankcode", fkbankcode);
            }else {
                FieldDataVo  orgcodeVo = formDataVo.getFieldData("主表支付公司编码");
                String orgcode = "";
                if(orgcodeVo!=null){
                    orgcode = orgcodeVo.getStringValue();
                }
                subjson.put("orgcode", orgcode);
                FieldDataVo  fkbankcodeVo = formDataVo.getFieldData("付款银行账号");
                String fkbankcode = "";
                if(fkbankcodeVo!=null){
                    fkbankcode = fkbankcodeVo.getStringValue();
                }
                subjson.put("fkbankcode",fkbankcode);
            }
            FieldDataVo  skbankcodeVo = subFormDataVo.getFieldData("分账收款银行账号");
            String skbankcode = "";
            if(skbankcodeVo!=null){
                skbankcode = skbankcodeVo.getStringValue();
            }
            subjson.put("skbankcode", skbankcode);
            subjson.put("path", "/seeyon/cst/flowInfo.do?summaryId="+summaryId);
            FieldDataVo  oabillcodeVo = subFormDataVo.getFieldData("分账单据流水号");
            String oabillcode = "";
            if(oabillcodeVo!=null){
                oabillcode = oabillcodeVo.getStringValue();
            }
            subjson.put("oabillcode", oabillcode);
            FieldDataVo  field0006Vo = formDataVo.getFieldData("原始单据数");
            String field0006 = "";
            if(field0006Vo!=null){
                field0006 = field0006Vo.getStringValue();
            }
            subjson.put("field0006", field0006);
            FieldDataVo  suppliercodeVo = subFormDataVo.getFieldData("分账收款人编码");
            String suppliercode = "";
            if(suppliercodeVo!=null){
                suppliercode = suppliercodeVo.getStringValue();
            }
            subjson.put("suppliercode", suppliercode);
            FieldDataVo  ytVo = formDataVo.getFieldData("摘要内容");
            String yt = "";
            if(ytVo!=null){
                yt = ytVo.getStringValue();
            }
            subjson.put("yt", yt);
            FieldDataVo  busitypecodeIdVo = formDataVo.getFieldData("业务流程");
            String busitypecodeId = "";
            if(busitypecodeIdVo!=null){
                busitypecodeId = busitypecodeIdVo.getDbValue().toString();
            }
            String busitypecodeCode = getEnumManagerNew().getEnumItem(Long.parseLong(busitypecodeId)).getEnumItemCode();
            String busitypecode = busitypecodeCode.substring(5);
            subjson.put("busitypecode", busitypecode);
            FieldDataVo  wldxidVo = subFormDataVo.getFieldData("业务流程");
            String wldxid = "";
            if(wldxidVo!=null){
                wldxid = wldxidVo.getDbValue().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);
        if(istrue.size() == subFormMap.size()) {
            jsonObject = new JSONObject();
        }
        return jsonObject;
    }

    /**
     * 通用分账参数封装-新
     * @param formDataVo
     * @param summaryId
     * @return
     * @throws IOException
     */
    public JSONObject getTongYongFenZhangParam(FormDataVo formDataVo,String summaryId) throws  NoSuchFieldException {
        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        Map<String, List<FormDataVo>> subFormMaps = formDataVo.getSubFormMap();
        List<FormDataVo> subFormMap = subFormMaps.get("分账明细表");

        FieldDataVo isbearidVo = formDataVo.getFieldData("支付公司是否成本承担公司");
        String isbearid = "";
        if(isbearidVo!=null){
            isbearid = isbearidVo.getStringValue();
        }
        String isbear = "";
        if("".equals(isbearid)){
            isbear = "否";
        }else {
            isbear =  getEnumManagerNew().getEnumItem(Long.parseLong(isbearid)).getLabel();
        }
        for (FormDataVo subFormDataVo : subFormMap) {
            FieldDataVo numVo = subFormDataVo.getFieldData("分账原币金额");
            String num = "";
            if(numVo!=null){
                num = numVo.getStringValue();
            }
            if("0".equals(num)) {
                FieldDataVo fieldDataVo = subFormDataVo.getFieldData("分账收款人编码");
                log.info("分账原币金额为0，跳过处理："+ fieldDataVo.getStringValue());
                continue;
            }
            JSONObject subjson = new JSONObject();
            FieldDataVo psndoccodeVo = subFormDataVo.getFieldData("分账收款人编码");
            String psndoccode = "";
            if(psndoccodeVo!=null){
                psndoccode = psndoccodeVo.getStringValue();
            }
            subjson.put("psndoccode", psndoccode);
            FieldDataVo businessdateVo = formDataVo.getFieldData("单据日期");
            String businessdate = "";
            if(businessdateVo!=null){
                businessdate = businessdateVo.getStringValue();
            }
            subjson.put("businessdate", businessdate);
            JSONArray data = new JSONArray();
            JSONObject jsondata = new JSONObject();
            FieldDataVo scommentVo = formDataVo.getFieldData("摘要内容");
            String scomment = "";
            if(scommentVo!=null){
                scomment = scommentVo.getStringValue();
            }
            jsondata.put("scomment", scomment);
            FieldDataVo field0120Vo = subFormDataVo.getFieldData("分账税率");
            String field0120 = "";
            if(field0120Vo!=null){
                field0120 = field0120Vo.getStringValue();
            }
            jsondata.put("field0120", field0120);
            FieldDataVo field0121Vo = subFormDataVo.getFieldData("分账税额");
            String field0121 = "";
            if(field0121Vo!=null){
                field0121 = field0121Vo.getStringValue();
            }
            jsondata.put("field0121", field0121);
            FieldDataVo field0119Vo = subFormDataVo.getFieldData("分账行无税金额");
            String field0119 = "";
            if(field0119Vo!=null){
                field0119 = field0119Vo.getStringValue();
            }
            jsondata.put("field0119", field0119);
            FieldDataVo moneyVo = subFormDataVo.getFieldData("分账原币金额");
            String money = "";
            if(moneyVo!=null){
                money = moneyVo.getStringValue();
            }
            jsondata.put("money", money);
            FieldDataVo jsfsVo = formDataVo.getFieldData("结算方式编号");
            String jsfs = "";
            if(jsfsVo!=null){
                jsfs = jsfsVo.getStringValue();
            }
            jsondata.put("jsfs",jsfs);
            FieldDataVo kmdlVo = formDataVo.getFieldData("科目大类编号");
            String kmdl = "";
            if(kmdlVo!=null){
                kmdl = kmdlVo.getStringValue();
            }
            jsondata.put("kmdl", kmdl);
            FieldDataVo szxmVo = formDataVo.getFieldData("收支项目编号");
            String szxm = "";
            if(szxmVo!=null){
                szxm = szxmVo.getStringValue();
            }
            jsondata.put("szxm", szxm);
            jsondata.put("fkyw", "OA");
            data.add(jsondata);
            subjson.put("data", data);
            if("是".equals(isbear)) {
                FieldDataVo orgcodeVo = subFormDataVo.getFieldData("分账组织编码");
                String orgcode = "";
                if(orgcodeVo!=null){
                    orgcode = orgcodeVo.getStringValue();
                }
                subjson.put("orgcode",orgcode);
                FieldDataVo fkbankcodeVo = subFormDataVo.getFieldData("分账付款银行账号");
                String fkbankcode = "";
                if(fkbankcodeVo!=null){
                    fkbankcode = fkbankcodeVo.getStringValue();
                }
                subjson.put("fkbankcode", fkbankcode);
            }else {
                FieldDataVo orgcodeVo = formDataVo.getFieldData("主表支付公司编码");
                String orgcode = "";
                if(orgcodeVo!=null){
                    orgcode = orgcodeVo.getStringValue();
                }
                subjson.put("orgcode", orgcode);
                FieldDataVo fkbankcodeVo = formDataVo.getFieldData("付款银行账号");
                String fkbankcode = "";
                if(fkbankcodeVo!=null){
                    fkbankcode = fkbankcodeVo.getStringValue();
                }
                subjson.put("fkbankcode", fkbankcode);
            }
            FieldDataVo skbankcodeVo = subFormDataVo.getFieldData("分账收款银行账号");
            String skbankcode = "";
            if(skbankcodeVo!=null){
                skbankcode = skbankcodeVo.getStringValue();
            }
            subjson.put("skbankcode", skbankcode);
            subjson.put("path", "/seeyon/cst/flowInfo.do?summaryId="+summaryId);
            FieldDataVo oabillcodeVo = subFormDataVo.getFieldData("分账单据流水号");
            String oabillcode = "";
            if(oabillcodeVo!=null){
                oabillcode = oabillcodeVo.getStringValue();
            }
            subjson.put("oabillcode", oabillcode);
            FieldDataVo field0006Vo = formDataVo.getFieldData("分账单据流水号");
            String field0006 = "";
            if(field0006Vo!=null){
                field0006 = field0006Vo.getStringValue();
            }
            subjson.put("field0006", field0006);
            FieldDataVo suppliercodeVo = subFormDataVo.getFieldData("分账单据流水号");
            String suppliercode = "";
            if(suppliercodeVo!=null){
                suppliercode = suppliercodeVo.getStringValue();
            }
            subjson.put("suppliercode", suppliercode);
            FieldDataVo ytVo = formDataVo.getFieldData("分账单据流水号");
            String yt = "";
            if(ytVo!=null){
                yt = ytVo.getStringValue();
            }
            subjson.put("yt", yt);
            FieldDataVo busitypecodeIdVo = formDataVo.getFieldData("业务流程");
            String busitypecodeId = "";
            if(ytVo!=null){
                busitypecodeId = busitypecodeIdVo.getDbValue().toString();
            }
            String busitypecodeCode = getEnumManagerNew().getEnumItem(Long.parseLong(busitypecodeId)).getEnumItemCode();
            String busitypecode = busitypecodeCode.substring(5);
            subjson.put("busitypecode", busitypecode);
            FieldDataVo wldxidVo = subFormDataVo.getFieldData("往来对象");
            String wldxid = "";
            if(wldxidVo!=null) {
                wldxid = wldxidVo.getDbValue().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);
        return jsonObject;
    }



    /**
     * 社保分账参数封装
     * @param formDataVo
     * @param summaryId
     * @return
     * @throws IOException
     */
    public JSONObject getSheBaoFenZhangParam( FormDataVo formDataVo,String summaryId) throws IOException, NoSuchFieldException {
        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        Map<String, List<FormDataVo>> subFormMaps = formDataVo.getSubFormMap();
        List<FormDataVo> subFormMap = subFormMaps.get("分账明细表");
        List<Object> istrue = new ArrayList<Object>();
        FieldDataVo isbearidVo = formDataVo.getFieldData("支付公司是否成本承担公司");
        String isbearid = "";
        if(isbearidVo!=null){
            isbearid = isbearidVo.getDbValue().toString();
        }
        String isbear = "";
        if("".equals(isbearid)){
            isbear = "否";
        }else {
            isbear =  getEnumManagerNew().getEnumItem(Long.parseLong(isbearid)).getLabel();
        }
        FieldDataVo isunitidVo = formDataVo.getFieldData("是否同一收款单位");
        String isunitid = "";
        if(isunitidVo != null){
            isunitid = isunitidVo.getDbValue().toString();
        }
        String isunit = StringUtils.isBlank(isunitid) ? "是" : getEnumManagerNew().getEnumItem(Long.parseLong(isunitid)).getLabel();
        if("是".equals(isunit) && "否".equals(isbear)) {
            JSONObject subjson = new JSONObject();
            FieldDataVo psndoccodeVo = formDataVo.getFieldData("收款单位编码");
            String psndoccode = "";
            if(psndoccodeVo!=null){
                psndoccode = psndoccodeVo.getStringValue();
            }
            subjson.put("psndoccode", psndoccode);
            FieldDataVo businessdateVo = formDataVo.getFieldData("单据日期");
            String businessdate = "";
            if(businessdateVo!=null){
                businessdate = businessdateVo.getStringValue();
            }
            subjson.put("businessdate", businessdate);
            JSONArray data = new JSONArray();
            JSONObject jsondata = new JSONObject();
            FieldDataVo scommentVo = formDataVo.getFieldData("摘要内容");
            String scomment = "";
            if(scommentVo!=null){
                scomment = scommentVo.getStringValue();
            }
            jsondata.put("scomment", scomment);
            jsondata.put("field0120", "0");
            jsondata.put("field0121", "0");
            FieldDataVo moneyVo = formDataVo.getFieldData("合计分账支付");
            String money = "";
            if(moneyVo!=null){
                money = moneyVo.getStringValue();
            }
            jsondata.put("money", money);
            FieldDataVo jsfsVo = formDataVo.getFieldData("结算方式编号");
            String jsfs = "";
            if(jsfsVo!=null){
                jsfs = jsfsVo.getStringValue();
            }
            jsondata.put("jsfs", jsfs);
            FieldDataVo kmdlVo = formDataVo.getFieldData("科目大类编号");
            String kmdl = "";
            if(kmdlVo!=null){
                kmdl = kmdlVo.getStringValue();
            }
            jsondata.put("kmdl", kmdl);
            FieldDataVo szxmVo = formDataVo.getFieldData("收支项目编号");
            String szxm = "";
            if(szxmVo!=null){
                szxm = szxmVo.getStringValue();
            }
            jsondata.put("szxm", szxm);
            jsondata.put("field0119","0");
            jsondata.put("fkyw", "OA");
            data.add(jsondata);
            subjson.put("data", data);
            jsondata.put("szxm", szxm);
            FieldDataVo orgcodeVo = formDataVo.getFieldData("主表支付公司编码");
            String orgcode = "";
            if(orgcodeVo!=null){
                orgcode = orgcodeVo.getStringValue();
            }
            subjson.put("orgcode", orgcode);
            FieldDataVo fkbankcodeVo = formDataVo.getFieldData("付款银行账号");
            String fkbankcode = "";
            if(fkbankcodeVo!=null){
                fkbankcode = fkbankcodeVo.getStringValue();
            }
            subjson.put("fkbankcode", fkbankcode);
            FieldDataVo skbankcodeVo = formDataVo.getFieldData("收款银行账号");
            String skbankcode = "";
            if(skbankcodeVo!=null){
                skbankcode = skbankcodeVo.getStringValue();
            }
            subjson.put("skbankcode", skbankcode);
            subjson.put("path", "/seeyon/cst/flowInfo.do?summaryId="+summaryId);
            FieldDataVo oabillcodeVo = formDataVo.getFieldData("单据流水号");
            String oabillcode = "";
            if(oabillcodeVo!=null){
                oabillcode = oabillcodeVo.getStringValue();
            }
            subjson.put("oabillcode",oabillcode);
            FieldDataVo field0006Vo = formDataVo.getFieldData("原始单据数");
            String field0006 = "";
            if(field0006Vo!=null){
                field0006 = field0006Vo.getStringValue();
            }
            subjson.put("field0006", field0006);
            FieldDataVo suppliercodeVo = formDataVo.getFieldData("收款单位编码");
            String suppliercode = "";
            if(suppliercodeVo!=null){
                suppliercode = suppliercodeVo.getStringValue();
            }
            subjson.put("suppliercode", suppliercode);
            FieldDataVo ytVo = formDataVo.getFieldData("摘要内容");
            String yt = "";
            if(ytVo!=null){
                yt = ytVo.getStringValue();
            }
            subjson.put("yt", yt);

            FieldDataVo wldxidVo = formDataVo.getFieldData("表头往来对象");
            String wldxid = "";
            if(wldxidVo!=null){
                wldxid = wldxidVo.getDbValue().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 (FormDataVo subFormDataVo : subFormMap) {
                FieldDataVo bipNoVo =  subFormDataVo.getFieldData("BIP单据号");
                if (bipNoVo != null && StringUtils.isNotBlank(bipNoVo.getStringValue())) {
                    istrue.add(bipNoVo.getStringValue());
                }
                JSONObject subjson = new JSONObject();
                if("否".equals(isunit)) {
                    FieldDataVo psndoccodeVo = subFormDataVo.getFieldData("分账收款人编码");
                    String psndoccode = "";
                    if(psndoccodeVo!=null){
                        psndoccode = psndoccodeVo.getStringValue();
                    }
                    subjson.put("psndoccode", psndoccode);
                    subjson.put("suppliercode", psndoccode);
                    FieldDataVo skbankcodeVo = subFormDataVo.getFieldData("分账收款银行账号");
                    String skbankcode = "";
                    if(skbankcodeVo!=null){
                        skbankcode = skbankcodeVo.getStringValue();
                    }
                    subjson.put("skbankcode", skbankcode);

                }else {
                    FieldDataVo psndoccodeVo = formDataVo.getFieldData("收款单位编码");
                    String psndoccode = "";
                    if(psndoccodeVo!=null){
                        psndoccode = psndoccodeVo.getStringValue();
                    }
                    subjson.put("psndoccode", psndoccode);
                    subjson.put("suppliercode", psndoccode);
                    FieldDataVo skbankcodeVo = formDataVo.getFieldData("收款银行账号");
                    String skbankcode = "";
                    if(skbankcodeVo!=null){
                        skbankcode = skbankcodeVo.getStringValue();
                    }
                    subjson.put("skbankcode",skbankcode);

                }
                FieldDataVo businessdateVo = formDataVo.getFieldData("单据日期");
                String businessdate = "";
                if(businessdateVo!=null){
                    businessdate = businessdateVo.getStringValue();
                }
                subjson.put("businessdate", businessdate);
                JSONArray data = new JSONArray();
                JSONObject jsondata = new JSONObject();
                FieldDataVo scommentVo = formDataVo.getFieldData("摘要内容");
                String scomment = "";
                if(scommentVo!=null){
                    scomment = scommentVo.getStringValue();
                }
                jsondata.put("scomment", scomment);
                FieldDataVo field0120Vo = subFormDataVo.getFieldData("分账税率");
                String field0120 = "";
                if(field0120Vo!=null){
                    field0120 = field0120Vo.getStringValue();
                }
                jsondata.put("field0120",field0120);
                FieldDataVo field0121Vo = subFormDataVo.getFieldData("分账税额");
                String field0121 = "";
                if(field0121Vo!=null){
                    field0121 = field0121Vo.getStringValue();
                }
                jsondata.put("field0121",field0121);
                FieldDataVo field0119Vo = subFormDataVo.getFieldData("分账行无税金额");
                String field0119 = "";
                if(field0119Vo!=null){
                    field0119 = field0119Vo.getStringValue();
                }
                jsondata.put("field0119", field0119);
                FieldDataVo moneyVo = subFormDataVo.getFieldData("分账原币金额");
                String money = "";
                if(moneyVo!=null){
                    money = moneyVo.getStringValue();
                }
                jsondata.put("money", money);
                FieldDataVo jsfsVo = formDataVo.getFieldData("结算方式编号");
                String jsfs = "";
                if(jsfsVo!=null){
                    jsfs = jsfsVo.getStringValue();
                }
                jsondata.put("jsfs", jsfs);
                FieldDataVo kmdlVo = formDataVo.getFieldData("科目大类编号");
                String kmdl = "";
                if(kmdlVo!=null){
                    kmdl = kmdlVo.getStringValue();
                }
                jsondata.put("kmdl", kmdl);
                FieldDataVo szxmVo = formDataVo.getFieldData("收支项目编号");
                String szxm = "";
                if(szxmVo!=null){
                    szxm = szxmVo.getStringValue();
                }
                jsondata.put("szxm", szxm);
                jsondata.put("fkyw", "OA");
                data.add(jsondata);
                subjson.put("data", data);
                if("是".equals(isbear)) {
                    FieldDataVo orgcodeVo = subFormDataVo.getFieldData("分账组织编码");
                    String orgcode = "";
                    if(orgcodeVo!=null){
                        orgcode = orgcodeVo.getStringValue();
                    }
                    subjson.put("orgcode", orgcode);
                    FieldDataVo fkbankcodeVo = subFormDataVo.getFieldData("分账付款银行账号");
                    String fkbankcode = "";
                    if(fkbankcodeVo!=null){
                        fkbankcode = fkbankcodeVo.getStringValue();
                    }
                    subjson.put("fkbankcode", fkbankcode);
                }
                else {
                    FieldDataVo orgcodeVo = formDataVo.getFieldData("主表支付公司编码");
                    String orgcode = "";
                    if(orgcodeVo!=null){
                        orgcode = orgcodeVo.getStringValue();
                    }
                    subjson.put("orgcode", orgcode);
                    FieldDataVo fkbankcodeVo = formDataVo.getFieldData("付款银行账号");
                    String fkbankcode = "";
                    if(fkbankcodeVo!=null){
                        fkbankcode = fkbankcodeVo.getStringValue();
                    }
                    subjson.put("fkbankcode", fkbankcode);
                }
                subjson.put("path", "/seeyon/cst/flowInfo.do?summaryId="+summaryId);
                FieldDataVo oabillcodeVo = subFormDataVo.getFieldData("分账单据流水号");
                String oabillcode = "";
                if(oabillcodeVo!=null){
                    oabillcode = oabillcodeVo.getStringValue();
                }
                subjson.put("oabillcode", oabillcode);
                FieldDataVo field0006Vo = formDataVo.getFieldData("原始单据数");
                String field0006 = "";
                if(field0006Vo!=null){
                    field0006 = field0006Vo.getStringValue();
                }
                subjson.put("field0006", field0006);
                FieldDataVo ytVo = formDataVo.getFieldData("摘要内容");
                String yt = "";
                if(ytVo!=null){
                    yt = ytVo.getStringValue();
                }
                subjson.put("yt", yt);
                //业务流程
                String wldxid = "";
                FieldDataVo wldxidVo = subFormDataVo.getFieldData("往来对象");
                if(wldxidVo!=null){
                    wldxid = wldxidVo.getDbValue().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);
        if(istrue.size() == subFormMap.size()) {
            jsonObject = new JSONObject();
        }
        return jsonObject;
    }

    /**
     * 薪酬分账终止参数
     * @param formDataVo
     * @return
     * @throws IOException
     */
    public JSONObject getXinChouFenZhangStopParam(FormDataVo formDataVo) throws NoSuchFieldException {
        JSONObject jsonObject = new JSONObject();
//		System.out.println("设置终止参数");
        FieldDataVo billcodeVo = formDataVo.getFieldData("NC单据编号");
        String billcode = "";
        if(billcodeVo!=null){
            billcode = billcodeVo.getStringValue();
        }
//		String billcode = CAP4FormKit.getFieldStrValue(master, "NC单据编号");
        jsonObject.put("billcode", billcode);
        jsonObject.put("status", "0");
        log.info("终止参数："+jsonObject);
        return jsonObject;
    }

    /**
     * 社保分账终止参数
     * @param formDataVo
     * @return
     * @throws IOException
     */
    public JSONObject getSheBaoFenZhangStopParam( FormDataVo formDataVo) throws NoSuchFieldException {
        JSONObject jsonObject = new JSONObject();
        FieldDataVo billcodeVo = formDataVo.getFieldData("BIP单据编号");
        String billcode = "";
        if(billcodeVo!=null){
            billcode = billcodeVo.getStringValue();
        }
        jsonObject.put("compose_pk", billcode);
        jsonObject.put("status", 1);
        return jsonObject;
    }

    /**
     * 薪酬分账结束参数
     * @param formDataVo
     * @return
     * @throws IOException
     */
    public JSONObject getXinChouFenZhangEndParam(FormDataVo formDataVo) throws  NoSuchFieldException {
        JSONObject jsonObject = new JSONObject();
        FieldDataVo billcodeVo = formDataVo.getFieldData("NC单据编号");
        String billcode = "";
        if(billcodeVo!=null){
            billcode = billcodeVo.getStringValue();
        }
        jsonObject.put("billcode", billcode);
        jsonObject.put("status", "1");
        log.info("流程结束参数："+jsonObject);
        return jsonObject;
    }


    /**
     * 社保分账结束参数
     * @param formDataVo
     * @return
     * @throws IOException
     */
    public JSONObject getSheBaoFenZhangEndParam(FormDataVo formDataVo) throws  NoSuchFieldException {
        JSONObject jsonObject = new JSONObject();
        FieldDataVo billcodeVo = formDataVo.getFieldData("BIP单据编号");
        String billcode = "";
        if(billcodeVo!=null){
            billcode = billcodeVo.getStringValue();
        }
        jsonObject.put("compose_pk", billcode);
        jsonObject.put("status", 2);
        log.info("流程结束参数："+jsonObject);
        return jsonObject;
    }


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

        //该超级节点存在多流程共用情况，通过不同变量，兼容不同表单的数据域
        String subName =formDataVo.getFieldData("明细表名称")!=null?formDataVo.getFieldData("明细表名称").getStringValue():"";
//				StringUtils.isEmpty(formDataVo.getFieldData("明细表名称")!=null?formDataVo.getFieldData("明细表名称").getStringValue():"")?"通用收费明细":CAP4FormKit.getFieldStrValue(master, "明细表名称");
        subName = StringUtils.isEmpty(subName)?"通用收费明细":subName;
        List<FormDataVo> subFormDataVos = formDataVo.getSubFormMap().get(subName);
//		List<FormDataSubBean> formDataSubBeans = CAP4FormKit.getSubBeans(master,subName);
        JSONArray jsonArray = new JSONArray();
        for (FormDataVo subFormDataVo : subFormDataVos) {
            JSONObject items = new JSONObject();
            //该超级节点存在多流程共用情况，通过不同变量，兼容不同表单的数据域
            String skywName =formDataVo.getFieldData("明细表名称")!=null?formDataVo.getFieldData("明细表名称").getStringValue():"";
//					StringUtils.isEmpty(CAP4FormKit.getFieldStrValue(master, "收款业务类型名称"))?"收款业务类型编码":CAP4FormKit.getFieldStrValue(master, "收款业务类型名称");
            skywName = StringUtils.isEmpty(skywName)?"收款业务类型编码":skywName;

//			items.put("skyw", CAP4FormKit.getSubFieldValue(formDataSubBean, skywName));
            items.put("skyw", subFormDataVo.getFieldData(skywName)!=null?subFormDataVo.getFieldData(skywName).getStringValue():"");
//			items.put("money", CAP4FormKit.getSubFieldValue(formDataSubBean, "本次收款金额"));
            items.put("money", subFormDataVo.getFieldData("本次收款金额")!=null?subFormDataVo.getFieldData("本次收款金额").getStringValue():"");
//			items.put("field0120", CAP4FormKit.getSubFieldValue(formDataSubBean, "税率"));
            items.put("field0120", subFormDataVo.getFieldData("税率")!=null?subFormDataVo.getFieldData("税率").getStringValue():"");
//			items.put("field0121", CAP4FormKit.getSubFieldValue(formDataSubBean, "税额"));
            items.put("field0121", subFormDataVo.getFieldData("税额")!=null?subFormDataVo.getFieldData("税额").getStringValue():"");
//			items.put("field0119", CAP4FormKit.getSubFieldValue(formDataSubBean, "无税金额"));
            items.put("field0119", subFormDataVo.getFieldData("无税金额")!=null?subFormDataVo.getFieldData("无税金额").getStringValue():"");
//			String subjectCode = CAP4FormKit.getSubFieldValue(formDataSubBean, "科目大类编码").toString();
            String subjectCode =subFormDataVo.getFieldData("科目大类编码")!=null?subFormDataVo.getFieldData("科目大类编码").getStringValue():"";
            subjectCode = subjectCode.substring(5);
            items.put("subjectCode", subjectCode);//科目大类01-应收款项,02-预收款项
//			items.put("scomment", CAP4FormKit.getSubFieldValue(formDataSubBean, "备注"));
            items.put("scomment", subFormDataVo.getFieldData("备注")!=null?subFormDataVo.getFieldData("备注").getStringValue():"");
//			items.put("szxm", CAP4FormKit.getSubFieldValue(formDataSubBean, "收支项目编码"));
            items.put("szxm",subFormDataVo.getFieldData("收支项目编码")!=null?subFormDataVo.getFieldData("收支项目编码").getStringValue():"");
            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;
    }
}
