package com.brilliance.isc.common.component;

import com.brilliance.isc.bo.*;
import com.brilliance.isc.common.api.bch.service.BchService;
import com.brilliance.isc.common.cache.pta.PtaCacheService;
import com.brilliance.isc.common.codetable.service.CodetableService;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.counter.service.CounterService;
import com.brilliance.isc.common.setgll.vo.SetgllVo;
import com.brilliance.isc.common.sysmod.SysmodService;
import com.brilliance.isc.common.util.StringUtils;
import com.brilliance.isc.common.util.Utils;
import com.brilliance.isc.common.vo.BizInfoVo;
import com.brilliance.isc.common.vo.PtsptaVo;
import com.brilliance.isc.mda.dao.AtdMapper;
import com.brilliance.isc.mda.dao.CndMapper;
import com.brilliance.isc.mda.dao.CnnMapper;
import com.brilliance.isc.vo.CipmodVo;
import com.brilliance.isc.vo.FxpmodVo;
import com.brilliance.mda.runtime.mda.util.Dates;
import com.brilliance.mda.runtime.mda.util.Numerics;
import com.brilliance.mda.runtime.mda.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component
public class CipsHelperComponent {

    private static Logger log = LoggerFactory.getLogger(CipsHelperComponent.class);

    @Autowired
    private CndMapper cndMapper;

    @Autowired
    private CnnMapper cnnMapper;

    @Autowired
    private AtdMapper atdMapper;

    @Autowired
    private CounterService counterService;

    @Autowired
    private PtsptaToolComponent ptsptaToolComponent;

    @Autowired
    private PtaCacheService ptaCacheService;

    @Autowired
    private SysmodService sysmodService;

    @Autowired
    private BchService bchService;

    @Autowired
    private CodetableService codetableService;

    //cips存盘 cnd和cnn表逻辑
    public void cipsSav(CipmodVo cipmodVo, BizInfoVo bizInfoVo, List<PtsptaVo> ptsList, List<SetgllVo> setglls) {
        //!主键
        String cndinr = counterService.dbCounterFormat("CND");
        Cnd cnd = new Cnd();
        cnd.setInr(cndinr);
        cnd.setObjinr(bizInfoVo.getObjinr());
        cnd.setObjtyp(bizInfoVo.getObjtyp());
        cnd.setOwnref(bizInfoVo.getOwnref());
        //@Default(target="trnmod.orcnam",order=1000)
        //@Default(target="trnmod.orcadr",order=1000)
        PtsptaVo apl = ptsptaToolComponent.getPtsFromListByRol(ptsList, "APL");
        if (apl != null) {
            Pta pta = ptaCacheService.getPtaByInr(apl.getPtainr());
            if (pta != null) {
                cnd.setOrcnam(pta.getNam());
            }
            if (apl.getPts() != null) {
                String address = StringUtils.isEmpty(apl.getPts().getCnadr()) ? apl.getPts().getEnadr() : apl.getPts().getCnadr();
                cnd.setOrcadr(address);
            }
        }
        //this.getTrnmod().getCnd().setPyeact( this.getTrnmod().getPyeact());
        //@Default(target="trnmod.pyenam",order=1000)
        PtsptaVo ben = ptsptaToolComponent.getPtsFromListByRol(ptsList, "BEN");
        if (ben != null) {
            Pta pta = ptaCacheService.getPtaByInr(ben.getPtainr());
            if (pta != null) {
                cnd.setPyenam(pta.getNam());
            }
            if (ben.getPts() != null) {
                String address = StringUtils.isEmpty(ben.getPts().getCnadr()) ? ben.getPts().getEnadr() : ben.getPts().getCnadr();
                cnd.setPyeadr(address);
            }
        }
        cnd.setCommet(bizInfoVo.getOwnref());
        cnd.setFbmosi("");
        cnd.setDlgdat(Dates.today());
        cnd.setExctyp("");
        String bchkey = sysmodService.getProcessBranch();
        Bch docbch = bchService.getByBranch(bchkey);
        if (docbch != null) {
            String bchNo = StringUtils.isNotEmpty(docbch.getBchref())?docbch.getBchref():docbch.getBranch();
            cnd.setOrcact(Strings.trim(bchNo) + "0121200000001");
        }
        cnd.setPyebchkey(cipmodVo.getPyebchkey());
        cnd.setPyebchnam(cipmodVo.getPyebchnam());
        if (SettleContext.getUserSession().getWrkbch() != null) {
            cnd.setOrcbchkey(SettleContext.getUserSession().getWrkbch().getSwfcod());
        }
        cnd.setAgency("");
        cnd.setAgname("");
        cnd.setBustyp(cipmodVo.getBustyp());
        cnd.setUrgtyp("URGT");
        cnd.setBusmod("A113");
        if (setglls != null) {
            for (SetgllVo setgllVo : setglls) {
                if ("PAC".equalsIgnoreCase(setgllVo.getDsp())) {
                    cnd.setAmt(setgllVo.getAcccpramt().abs());
                    cnd.setCur(setgllVo.getAcccur());
                }
            }
        }
        if (StringUtils.isNotEmpty(cipmodVo.getDddbsh())) {
            cnd.setOribusnum(cipmodVo.getDddbsh());
        } else {
            cnd.setOribusnum(bizInfoVo.getOwnref());
        }
        cnd.setStaonebch(cipmodVo.getStaonebch());
        cnd.setStasehbch(cipmodVo.getStasehbch());
        cnd.setReconebch(cipmodVo.getReconebch());
        cnd.setRecsehbch(cipmodVo.getRecsehbch());
        cnd.setStasehbchnam(cipmodVo.getStasehbchnam());
        cnd.setRecsehbchnam(cipmodVo.getRecsehbchnam());
        cnd.setStaonebchnam(cipmodVo.getStaonebchnam());
        cnd.setReconebchnam(cipmodVo.getReconebchnam());
        cnd.setAgency(cipmodVo.getZjg1hh());
        cnd.setAgname(cipmodVo.getZjg1mc());
        String swftyp = bizInfoVo.getSwftyp();
        String fbmosi = "";
        if ("CIU".equalsIgnoreCase(swftyp)) {
            fbmosi = "U";
        } else {
            fbmosi = "V";
        }
        cnd.setFbmosi(fbmosi);
        cndMapper.insert(cnd);
        String cnninr = counterService.dbCounterFormat("CNN");
        Cnn cnn = new Cnn();
        cnn.setInr(cnninr);
        cnn.setCndinr(cndinr);
        cnn.setLindat(Utils.fmtDate(Dates.today(), "yyyyMMdd"));
        if ("CIU".equalsIgnoreCase(swftyp)) {
            cnn.setFeecod(cipmodVo.getFeecod());
        }
        cnn.setSkrmc2("");
        cnn.setSkrmc3("");
        cnn.setSkrdz2(cipmodVo.getSkrdz2());
        cnn.setSkrdz3(cipmodVo.getSkrdz3());
        cnn.setSkrdz4(cipmodVo.getSkrdz4());
        cnn.setSkrdz5(cipmodVo.getSkrdz5());
        cnn.setSkrdz6(cipmodVo.getSkrdz6());
        cnn.setSkrdz7(cipmodVo.getSkrdz7());
        cnn.setSkrzh2("");
        cnn.setFkrmc2("");
        cnn.setFkrmc3("");
        cnn.setFkrdz2(cipmodVo.getFkrdz2());
        cnn.setFkrdz3(cipmodVo.getFkrdz3());
        cnn.setFkrdz4(cipmodVo.getFkrdz4());
        cnn.setFkrdz5(cipmodVo.getFkrdz5());
        cnn.setFkrdz6(cipmodVo.getFkrdz6());
        cnn.setFkrdz7(cipmodVo.getFkrdz7());
        cnn.setFkrzh2("");
        cnn.setFeecom(BigDecimal.ZERO);
        cnn.setFeesen(BigDecimal.ZERO);
        cnn.setComme2(cipmodVo.getFuynh2());
        cnn.setComme3(cipmodVo.getFuynh3());
        cnn.setComme4(cipmodVo.getFuynh4());
        cnn.setAgency2(cipmodVo.getZjg2hh());
        cnn.setAgname2(cipmodVo.getZjg2mc());
        cnn.setFufeih(cipmodVo.getFufeih());
        cnn.setFeiyon(cipmodVo.getFeiyon());
        cnn.setFeiyn2(cipmodVo.getFeiyn2());
        cnn.setFfeih2(cipmodVo.getFfeih2());
        cnn.setFkhkhh(cipmodVo.getFkhkhh());
        cnn.setFkkhmc(cipmodVo.getFkkhmc());
        cnn.setFkhdzh(cipmodVo.getFkhdzh());
        cnn.setFkkhzh(cipmodVo.getFkkhzh());
        cnn.setSkkhhh(cipmodVo.getSkkhhh());
        cnn.setSkkhhm(cipmodVo.getSkkhhm());
        cnn.setSkkhdz(cipmodVo.getSkkhdz());
        cnn.setSkkhzh(cipmodVo.getSkkhzh());
        cnn.setFkrkhh(cipmodVo.getFkrkhh());
        cnn.setFukrhm(cipmodVo.getFukrhm());
        cnn.setFuyns1(cipmodVo.getFuyns1());
        cnn.setFuyns2(cipmodVo.getFuyns2());
        cnn.setFuyns3(cipmodVo.getFuyns3());
        cnn.setFuyns4(cipmodVo.getFuyns4());
        cnn.setFkrzhj(cipmodVo.getFkrzhj());
        cnn.setFkrzjl(Strings.trim(cipmodVo.getFkrzjl()));
        cnn.setFkrzjh(cipmodVo.getFkrzjh());
        cnn.setFkrzgj(cipmodVo.getFkrzgj());
        cnn.setFkreid(cipmodVo.getFkreid());
        cnn.setFkfyzh(cipmodVo.getFkfyzh());
        cnn.setFkfdz1(cipmodVo.getFkfdz1());
        cnn.setFkfdz2(cipmodVo.getFkfdz2());
        cnn.setFkfdz3(cipmodVo.getFkfdz3());
        cnn.setFkfdz4(cipmodVo.getFkfdz4());
        cnn.setFkfdz5(cipmodVo.getFkfdz5());
        cnn.setFkfdz6(cipmodVo.getFkfdz6());
        cnn.setFkfdz7(cipmodVo.getFkfdz7());
        cnn.setSkrzhj(cipmodVo.getSkrzhj());
        cnn.setSkrzjl(Strings.trim(cipmodVo.getSkrzjl()));
        cnn.setSkrzjh(cipmodVo.getSkrzjh());
        cnn.setSkrzgj(cipmodVo.getSkrzgj());
        cnn.setSkreid(cipmodVo.getSkreid());
        cnn.setSkfyzh(cipmodVo.getSkfyzh());
        cnn.setSkfdz1(cipmodVo.getSkfdz1());
        cnn.setSkfdz2(cipmodVo.getSkfdz2());
        cnn.setSkfdz3(cipmodVo.getSkfdz3());
        cnn.setSkfdz4(cipmodVo.getSkfdz4());
        cnn.setSkfdz5(cipmodVo.getSkfdz5());
        cnn.setSkfdz6(cipmodVo.getSkfdz6());
        cnn.setSkfdz7(cipmodVo.getSkfdz7());
        cnn.setDdmsu1(cipmodVo.getDdmsu1());
        cnn.setDdmsu2(cipmodVo.getDdmsu2());
        cnn.setDdmsu3(cipmodVo.getDdmsu3());
        cnn.setDdmsu4(cipmodVo.getDdmsu4());
        cnn.setDdmsu5(cipmodVo.getDdmsu5());
        cnn.setDdmsu6(cipmodVo.getDdmsu6());
        cnn.setDdmsu7(cipmodVo.getDdmsu7());
        cnn.setDdmsu8(cipmodVo.getDdmsu8());
        cnn.setDdbhao(cipmodVo.getDdbhao());
        if ("CIV".equalsIgnoreCase(swftyp)) {
            if ("X".equalsIgnoreCase(cipmodVo.getCovflg())) {
                for (SetgllVo setgllVo : setglls) {
                    if ("PAC".equalsIgnoreCase(setgllVo.getDsp())) {
                        cnn.setCysbzh(setgllVo.getAcccur());
                        cnn.setCyshje(setgllVo.getAcccpramt().abs());
                    }
                }
                cnn.setCfkkhh(cipmodVo.getCfkkhh());
                cnn.setCfkkhm(cipmodVo.getCfkkhm());
                cnn.setCfkrzh(cipmodVo.getCfkrzh());
                cnn.setCfkrmc(cipmodVo.getCfkrmc());
                cnn.setCfkdz1(cipmodVo.getCfkdz1());
                cnn.setCfkdz2(cipmodVo.getCfkdz2());
                cnn.setCfkdz3(cipmodVo.getCfkdz3());
                cnn.setCfkdz4(cipmodVo.getCfkdz4());
                cnn.setCfkdz5(cipmodVo.getCfkdz5());
                cnn.setCfkdz6(cipmodVo.getCfkdz6());
                cnn.setCfkdz7(cipmodVo.getCfkdz7());
                cnn.setCskkhh(cipmodVo.getCskkhh());
                cnn.setCskkhm(cipmodVo.getCskkhm());
                cnn.setCskrzh(cipmodVo.getCskrzh());
                cnn.setCskrmc(cipmodVo.getCskrmc());
                cnn.setCskdz1(cipmodVo.getCskdz1());
                cnn.setCskdz2(cipmodVo.getCskdz2());
                cnn.setCskdz3(cipmodVo.getCskdz3());
                cnn.setCskdz4(cipmodVo.getCskdz4());
                cnn.setCskdz5(cipmodVo.getCskdz5());
                cnn.setCskdz6(cipmodVo.getCskdz6());
                cnn.setCskdz7(cipmodVo.getCskdz7());
                cnn.setCzjjg1(cipmodVo.getCzjjg1());
                cnn.setCzj1mc(cipmodVo.getCzj1mc());
                cnn.setCovfuy(cipmodVo.getCovfuy());
                cnn.setCovfy2(cipmodVo.getCovfy2());
                cnn.setCovfy3(cipmodVo.getCovfy3());
                cnn.setCovfy4(cipmodVo.getCovfy4());
                cnn.setCfkfzh(cipmodVo.getCfkfzh());
                cnn.setCffdz1(cipmodVo.getCffdz1());
                cnn.setCffdz2(cipmodVo.getCffdz2());
                cnn.setCffdz3(cipmodVo.getCffdz3());
                cnn.setCffdz4(cipmodVo.getCffdz4());
                cnn.setCffdz5(cipmodVo.getCffdz5());
                cnn.setCffdz6(cipmodVo.getCffdz6());
                cnn.setCffdz7(cipmodVo.getCffdz7());
                cnn.setCfkrzj(cipmodVo.getCfkrzj());
                cnn.setCfkzjl(Strings.trim(cipmodVo.getCfkzjl()));
                cnn.setCfkzjh(cipmodVo.getCfkzjh());
                cnn.setCfkrgj(cipmodVo.getCfkrgj());
                cnn.setCfkeid(cipmodVo.getCfkeid());
                cnn.setCskfzh(cipmodVo.getCskfzh());
                cnn.setCsfdz1(cipmodVo.getCsfdz1());
                cnn.setCsfdz2(cipmodVo.getCsfdz2());
                cnn.setCsfdz3(cipmodVo.getCsfdz3());
                cnn.setCsfdz4(cipmodVo.getCsfdz4());
                cnn.setCsfdz5(cipmodVo.getCsfdz5());
                cnn.setCsfdz6(cipmodVo.getCsfdz6());
                cnn.setCsfdz7(cipmodVo.getCsfdz7());
                cnn.setCskrzj(cipmodVo.getCskrzj());
                cnn.setCskzjl(Strings.trim(cipmodVo.getCskzjl()));
                cnn.setCskzjh(cipmodVo.getCskzjh());
                cnn.setCskrgj(cipmodVo.getCskrgj());
                cnn.setCskeid(cipmodVo.getCskeid());
            }
            cnn.setDdmisu(cipmodVo.getDdmisu());
            cnn.setDdbhao(cipmodVo.getDdbhao());
        }
        cnnMapper.insert(cnn);
    }

    //cips存盘 cnd和cnn表逻辑 2期公共逻辑
    public void cipsSav2(BizInfoVo bizInfoVo, List<SetgllVo> setglls) {
        //!主键
        SetgllVo setgll = null;
        for (int i=0; i<setglls.size(); i++) {
            if ("CIV".equals(setglls.get(i).getSftmt()) || "CIU".equals(setglls.get(i).getSftmt())) {
                setgll = setglls.get(i);
                break;
            }
        }
        if (setgll == null) {
            log.warn("CIPS存盘报错找不到结算数据");
            return;
        }
        CipmodVo cipmodVo = setgll.getSespay().getCipmod();
        String cndinr = counterService.dbCounterFormat("CND");
        Cnd cnd = new Cnd();
        cnd.setInr(cndinr);
        cnd.setObjinr(bizInfoVo.getObjinr());
        cnd.setObjtyp(bizInfoVo.getObjtyp());
        cnd.setOwnref(bizInfoVo.getOwnref());
        cnd.setOrcact(cipmodVo.getOrcact());
        cnd.setOrcnam(cipmodVo.getOrcnam());
        cnd.setOrcadr(cipmodVo.getOrcadr());
        cnd.setPyeact(cipmodVo.getPyeact());
        cnd.setPyenam(cipmodVo.getPyenam());
        cnd.setPyeadr(cipmodVo.getPyenam());
        cnd.setCommet(cipmodVo.getCommen());
        cnd.setFbmosi("");
        cnd.setDlgdat(Dates.today());
        cnd.setExctyp("");
        Bch bch = SettleContext.getUserSession().getBch();
        if (bch != null) {
            cnd.setOrcbchkey(bch.getSwfcod());
        }
        cnd.setPyebchkey(cipmodVo.getPyebchkey());
        cnd.setPyebchnam(cipmodVo.getPyebchnam());
        cnd.setAgency("");
        cnd.setAgname("");
        cnd.setBustyp(cipmodVo.getBustyp());
        cnd.setUrgtyp("URGT");
        cnd.setBusmod("A113");
        cnd.setAmt(setgll.getAcccpramt().abs());
        cnd.setCur(setgll.getAcccur());
        if (StringUtils.isNotEmpty(cipmodVo.getDddbsh())) {
            cnd.setOribusnum(cipmodVo.getDddbsh());
        } else {
            cnd.setOribusnum(bizInfoVo.getOwnref());
        }
        cnd.setStaonebch(cipmodVo.getStaonebch());
        cnd.setStasehbch(cipmodVo.getStasehbch());
        cnd.setReconebch(cipmodVo.getReconebch());
        cnd.setRecsehbch(cipmodVo.getRecsehbch());
        cnd.setStasehbchnam(cipmodVo.getStasehbchnam());
        cnd.setRecsehbchnam(cipmodVo.getRecsehbchnam());
        cnd.setStaonebchnam(cipmodVo.getStaonebchnam());
        cnd.setReconebchnam(cipmodVo.getReconebchnam());
        cnd.setAgency(cipmodVo.getZjg1hh());
        cnd.setAgname(cipmodVo.getZjg1mc());
        String swftyp = bizInfoVo.getSwftyp();
        String fbmosi = "";
        if ("CIU".equalsIgnoreCase(swftyp)) {
            fbmosi = "U";
        } else {
            fbmosi = "V";
        }
        cnd.setFbmosi(fbmosi);
        cndMapper.insert(cnd);
        String cnninr = counterService.dbCounterFormat("CNN");
        Cnn cnn = new Cnn();
        cnn.setInr(cnninr);
        cnn.setCndinr(cndinr);
        cnn.setLindat(Utils.fmtDate(Dates.today(), "yyyyMMdd"));
        if ("CIU".equalsIgnoreCase(swftyp)) {
            cnn.setFeecod(cipmodVo.getFeecod());
        }
        cnn.setSkrmc2("");
        cnn.setSkrmc3("");
        cnn.setSkrdz2(cipmodVo.getSkrdz2());
        cnn.setSkrdz3(cipmodVo.getSkrdz3());
        cnn.setSkrdz4(cipmodVo.getSkrdz4());
        cnn.setSkrdz5(cipmodVo.getSkrdz5());
        cnn.setSkrdz6(cipmodVo.getSkrdz6());
        cnn.setSkrdz7(cipmodVo.getSkrdz7());
        cnn.setSkrzh2("");
        cnn.setFkrmc2("");
        cnn.setFkrmc3("");
        cnn.setFkrdz2(cipmodVo.getFkrdz2());
        cnn.setFkrdz3(cipmodVo.getFkrdz3());
        cnn.setFkrdz4(cipmodVo.getFkrdz4());
        cnn.setFkrdz5(cipmodVo.getFkrdz5());
        cnn.setFkrdz6(cipmodVo.getFkrdz6());
        cnn.setFkrdz7(cipmodVo.getFkrdz7());
        cnn.setFkrzh2("");
        cnn.setFeecom(BigDecimal.ZERO);
        cnn.setFeesen(BigDecimal.ZERO);
        cnn.setComme2(cipmodVo.getFuynh2());
        cnn.setComme3(cipmodVo.getFuynh3());
        cnn.setComme4(cipmodVo.getFuynh4());
        cnn.setAgency2(cipmodVo.getZjg2hh());
        cnn.setAgname2(cipmodVo.getZjg2mc());
        cnn.setFufeih(cipmodVo.getFufeih());
        cnn.setFeiyon(cipmodVo.getFeiyon());
        cnn.setFeiyn2(cipmodVo.getFeiyn2());
        cnn.setFfeih2(cipmodVo.getFfeih2());
        cnn.setFkhkhh(cipmodVo.getFkhkhh());
        cnn.setFkkhmc(cipmodVo.getFkkhmc());
        cnn.setFkhdzh(cipmodVo.getFkhdzh());
        cnn.setFkkhzh(cipmodVo.getFkkhzh());
        if ("CIV".equals(swftyp)) {
            if (StringUtils.isEmpty(cipmodVo.getSkkhhh())) {
                cipmodVo.setSkkhhh(cipmodVo.getRecsehbch());
            }
            if (StringUtils.isEmpty(cipmodVo.getSkkhhm())) {
                cipmodVo.setSkkhhm(cipmodVo.getRecsehbchnam());
            }
        }
        cnn.setSkkhhh(cipmodVo.getSkkhhh());
        cnn.setSkkhhm(cipmodVo.getSkkhhm());
        cnn.setSkkhdz(cipmodVo.getSkkhdz());
        cnn.setSkkhzh(cipmodVo.getSkkhzh());
        cnn.setFkrkhh(cipmodVo.getFkrkhh());
        cnn.setFukrhm(cipmodVo.getFukrhm());
        cnn.setFuyns1(cipmodVo.getFuyns1());
        cnn.setFuyns2(cipmodVo.getFuyns2());
        cnn.setFuyns3(cipmodVo.getFuyns3());
        cnn.setFuyns4(cipmodVo.getFuyns4());
        cnn.setFkrzhj(cipmodVo.getFkrzhj());
        cnn.setFkrzjl(Strings.trim(cipmodVo.getFkrzjl()));
        cnn.setFkrzjh(cipmodVo.getFkrzjh());
        cnn.setFkrzgj(cipmodVo.getFkrzgj());
        cnn.setFkreid(cipmodVo.getFkreid());
        cnn.setFkfyzh(cipmodVo.getFkfyzh());
        cnn.setFkfdz1(cipmodVo.getFkfdz1());
        cnn.setFkfdz2(cipmodVo.getFkfdz2());
        cnn.setFkfdz3(cipmodVo.getFkfdz3());
        cnn.setFkfdz4(cipmodVo.getFkfdz4());
        cnn.setFkfdz5(cipmodVo.getFkfdz5());
        cnn.setFkfdz6(cipmodVo.getFkfdz6());
        cnn.setFkfdz7(cipmodVo.getFkfdz7());
        cnn.setSkrzhj(cipmodVo.getSkrzhj());
        cnn.setSkrzjl(Strings.trim(cipmodVo.getSkrzjl()));
        cnn.setSkrzjh(cipmodVo.getSkrzjh());
        cnn.setSkrzgj(cipmodVo.getSkrzgj());
        cnn.setSkreid(cipmodVo.getSkreid());
        cnn.setSkfyzh(cipmodVo.getSkfyzh());
        cnn.setSkfdz1(cipmodVo.getSkfdz1());
        cnn.setSkfdz2(cipmodVo.getSkfdz2());
        cnn.setSkfdz3(cipmodVo.getSkfdz3());
        cnn.setSkfdz4(cipmodVo.getSkfdz4());
        cnn.setSkfdz5(cipmodVo.getSkfdz5());
        cnn.setSkfdz6(cipmodVo.getSkfdz6());
        cnn.setSkfdz7(cipmodVo.getSkfdz7());
        cnn.setDdmsu1(cipmodVo.getDdmsu1());
        cnn.setDdmsu2(cipmodVo.getDdmsu2());
        cnn.setDdmsu3(cipmodVo.getDdmsu3());
        cnn.setDdmsu4(cipmodVo.getDdmsu4());
        cnn.setDdmsu5(cipmodVo.getDdmsu5());
        cnn.setDdmsu6(cipmodVo.getDdmsu6());
        cnn.setDdmsu7(cipmodVo.getDdmsu7());
        cnn.setDdmsu8(cipmodVo.getDdmsu8());
        cnn.setDdbhao(cipmodVo.getDdbhao());
        if ("CIV".equalsIgnoreCase(swftyp)) {
            if ("X".equalsIgnoreCase(cipmodVo.getCovflg())) {
                cnn.setCysbzh(setgll.getAcccur());
                cnn.setCyshje(setgll.getAcccpramt().abs());
                cnn.setCfkkhh(cipmodVo.getCfkkhh());
                cnn.setCfkkhm(cipmodVo.getCfkkhm());
                cnn.setCfkrzh(cipmodVo.getCfkrzh());
                cnn.setCfkrmc(cipmodVo.getCfkrmc());
                cnn.setCfkdz1(cipmodVo.getCfkdz1());
                cnn.setCfkdz2(cipmodVo.getCfkdz2());
                cnn.setCfkdz3(cipmodVo.getCfkdz3());
                cnn.setCfkdz4(cipmodVo.getCfkdz4());
                cnn.setCfkdz5(cipmodVo.getCfkdz5());
                cnn.setCfkdz6(cipmodVo.getCfkdz6());
                cnn.setCfkdz7(cipmodVo.getCfkdz7());
                cnn.setCskkhh(cipmodVo.getCskkhh());
                cnn.setCskkhm(cipmodVo.getCskkhm());
                cnn.setCskrzh(cipmodVo.getCskrzh());
                cnn.setCskrmc(cipmodVo.getCskrmc());
                cnn.setCskdz1(cipmodVo.getCskdz1());
                cnn.setCskdz2(cipmodVo.getCskdz2());
                cnn.setCskdz3(cipmodVo.getCskdz3());
                cnn.setCskdz4(cipmodVo.getCskdz4());
                cnn.setCskdz5(cipmodVo.getCskdz5());
                cnn.setCskdz6(cipmodVo.getCskdz6());
                cnn.setCskdz7(cipmodVo.getCskdz7());
                cnn.setCzjjg1(cipmodVo.getCzjjg1());
                cnn.setCzj1mc(cipmodVo.getCzj1mc());
                cnn.setCovfuy(cipmodVo.getCovfuy());
                cnn.setCovfy2(cipmodVo.getCovfy2());
                cnn.setCovfy3(cipmodVo.getCovfy3());
                cnn.setCovfy4(cipmodVo.getCovfy4());
                cnn.setCfkfzh(cipmodVo.getCfkfzh());
                cnn.setCffdz1(cipmodVo.getCffdz1());
                cnn.setCffdz2(cipmodVo.getCffdz2());
                cnn.setCffdz3(cipmodVo.getCffdz3());
                cnn.setCffdz4(cipmodVo.getCffdz4());
                cnn.setCffdz5(cipmodVo.getCffdz5());
                cnn.setCffdz6(cipmodVo.getCffdz6());
                cnn.setCffdz7(cipmodVo.getCffdz7());
                cnn.setCfkrzj(cipmodVo.getCfkrzj());
                cnn.setCfkzjl(Strings.trim(cipmodVo.getCfkzjl()));
                cnn.setCfkzjh(cipmodVo.getCfkzjh());
                cnn.setCfkrgj(cipmodVo.getCfkrgj());
                cnn.setCfkeid(cipmodVo.getCfkeid());
                cnn.setCskfzh(cipmodVo.getCskfzh());
                cnn.setCsfdz1(cipmodVo.getCsfdz1());
                cnn.setCsfdz2(cipmodVo.getCsfdz2());
                cnn.setCsfdz3(cipmodVo.getCsfdz3());
                cnn.setCsfdz4(cipmodVo.getCsfdz4());
                cnn.setCsfdz5(cipmodVo.getCsfdz5());
                cnn.setCsfdz6(cipmodVo.getCsfdz6());
                cnn.setCsfdz7(cipmodVo.getCsfdz7());
                cnn.setCskrzj(cipmodVo.getCskrzj());
                cnn.setCskzjl(Strings.trim(cipmodVo.getCskzjl()));
                cnn.setCskzjh(cipmodVo.getCskzjh());
                cnn.setCskrgj(cipmodVo.getCskrgj());
                cnn.setCskeid(cipmodVo.getCskeid());
            }
            cnn.setDdmisu(cipmodVo.getDdmisu());
            cnn.setDdbhao(cipmodVo.getDdbhao());
        }
        cnnMapper.insert(cnn);
    }

    //fxps atd存盘
    public void atdSav(BizInfoVo rec, List<SetgllVo> setglls) {
        //!主键
        SetgllVo setgll = null;
        for (int i = 0; i < setglls.size(); i++) {
            if ("111".equals(setglls.get(i).getSftmt()) || "112".equals(setglls.get(i).getSftmt())) {
                setgll = setglls.get(i);
                break;
            }
        }
        if (setgll == null) {
            log.warn("FXPS存盘报错找不到结算数据");
            return;
        }
        FxpmodVo fxpmod = setgll.getSespay().getFxpmod();
        Atd atd = new Atd();
        atd.setInr(counterService.dbCounterFormat("ATD"));
        atd.setObjtyp(rec.getObjtyp());
        atd.setObjinr(rec.getObjinr());
        atd.setFmttyp(fxpmod.getFmttyp());
        //业务编号
        atd.setOwnref(rec.getOwnref());
        //汇入汇款标志
        atd.setPaytyp( "O");
        //汇款人信息：
        //---地址、客户号
        atd.setOrcnam(fxpmod.getOrcnam());
        atd.setOrcadr(fxpmod.getOrcadr());
        atd.setOrcext(fxpmod.getOrcext());
        //---付款内部账号、币种、金额
        atd.setAmt(Numerics.abs(setgll.getAcccpramt()));
        atd.setCur(setgll.getAcccur());
        atd.setCurcod(codetableService.getTblLabel(setgll.getAcccur(), "CURKEY"));
        //扣款账号全部为内部帐
        atd.setZhangh(setgll.getAct());
        atd.setOrcact(fxpmod.getOrcact());
        //收费类型，客户类型
        atd.setFeetyp(fxpmod.getFeetyp());
        atd.setCustyp(Utils.getFieldValue(rec, "clityp", ""));
        //收款方信息：账号，名称，地址
        atd.setPyeact(fxpmod.getPyeact());
        //收款人民称、地址
        atd.setPyenam(fxpmod.getPyenam());
        atd.setPyeadr(fxpmod.getPyeadr());
        //接收行信息
        atd.setRbknum(fxpmod.getResbch());
        atd.setRbknam(fxpmod.getResbchnam());
        //汇款人开户行、收款人开户行
        PtsptaVo ori = fxpmod.getOri();
        if (ptsptaToolComponent.ptsIsRolSet(ori)) {
            ptsptaToolComponent.fillPtsptaAllProperties(ori);
            atd.setSbkopn(ori.getAdr().getBic());
            atd.setSbkdet(ori.getAdrblk());
        }
        PtsptaVo pyb = fxpmod.getPyb();
        if (ptsptaToolComponent.ptsIsRolSet(pyb)) {
            ptsptaToolComponent.fillPtsptaAllProperties(pyb);
            atd.setRbkopn(pyb.getAdr().getBic());
            atd.setRbkdet(pyb.getAdrblk());
        }
        //附言、银行操作码、发起行行号、委托日期、业务种类、汇款人账户性质、起息日期
        atd.setCommet(fxpmod.getCommet());
        atd.setBnkcod("CRED");
        Bch bch = SettleContext.getUserSession().getBch();
        if (bch != null) {
            atd.setSbknum(bch.getSwfcod());
        }
        atd.setValdat(fxpmod.getValdat());
        atd.setYwlxdm(fxpmod.getTxntyp());
        atd.setBustyp(fxpmod.getBustyp());
        atd.setAcctyp(fxpmod.getAcctyp());
        atd.setOpndat(fxpmod.getOpndat());
        atdMapper.insert(atd);
    }
}
