package com.brilliance.isc.common.bop.bopdec.service.imp;

import com.brilliance.mda.runtime.mda.util.Dates;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.mda.util.Numerics;
import com.brilliance.mda.runtime.mda.util.Strings;
import com.brilliance.isc.bo.*;
import com.brilliance.isc.bo.bopdecbo.*;
import com.brilliance.isc.bo.model.*;
import com.brilliance.isc.common.codetable.service.CodetableService;
import com.brilliance.isc.common.sysmod.SysmodService;
import com.brilliance.isc.common.util.BopUtils;
import com.brilliance.isc.common.bopset.service.BopdecCommonService;
import com.brilliance.isc.common.bopset.service.BopremService;
import com.brilliance.isc.common.bopset.service.CtlmodService;
import com.brilliance.isc.common.component.PtsptaToolComponent;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.transaction.help.TransactionHelpService;
import com.brilliance.isc.common.trnmod.vo.TrnmodVo;
import com.brilliance.isc.common.vo.PtsptaVo;
import com.brilliance.isc.mda.dao.*;
import com.brilliance.isc.vo.bop.BopActionTypeVo;
import com.brilliance.isc.vo.bop.RptnoRequestVo;
import com.brilliance.isc.vo.collection.BodBizInfoVo;
import com.brilliance.isc.vo.collection.CcdBizInfoVo;
import com.brilliance.isc.vo.finance.BpdBizInfoVo;
import com.brilliance.isc.vo.finance.DfdBizInfoVo;
import com.brilliance.isc.vo.lc.BedBizInfoVo;
import com.brilliance.isc.vo.lc.BtdBizInfoVo;
import com.brilliance.isc.vo.remit.CpdBizInfoVo;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import static com.brilliance.mda.runtime.mda.Constants.NULLSTR;

@Service
public class BopremServiceImpl implements BopremService {

    @Autowired
    private BopdecCommonService bopdecCommonService;

    @Autowired
    private PtsptaToolComponent ptsptaToolComponent;

    @Autowired
    private TransactionHelpService transactionHelpService;

    @Autowired
    private CtlmodService ctlmodService;

    @Autowired
    private DblMapper dblMapper;

    @Autowired
    private DbbMapper dbbMapper;

    @Autowired
    private DbhMapper dbhMapper;

    @Autowired
    private DbnMapper dbnMapper;

    @Autowired
    private DbeMapper dbeMapper;

    @Autowired
    private DbqMapper dbqMapper;

    @Autowired
    private SysmodService sysmodService;

    @Autowired
    private CodetableService codetableService;

    @Autowired
    private AdrMapper adrMapper;

    @Override
    public Boprem mappingBopremDataAAAAAA(Boprem boprem) {
        //将未初始化的属性初始化
        boprem.reset();

        // 后端逻辑全是跟大写的transName做比对，这里先转成大写
        boprem.setTransName(boprem.getTransName().toUpperCase());
        String transName = boprem.getTransName().toUpperCase();

        String szflg = boprem.getSzflg();
        String basflg = boprem.getBasflg();
        String dclflg = boprem.getDclflg();
        String vrfflg = boprem.getVrfflg();
        String aloneflg = boprem.getAloneflg();
        String acttyp = boprem.getActtyp();

        // 申报类型选择不报送，需要清空原有数据，如果申报编号已生成，则保留申报编号防止跳号
        if("3".equals(szflg)){
            Boprem newBoprem = new Boprem();
            newBoprem.reset();
            String dbbrptno = "";
            String dberptno = "";
            dbbrptno = boprem.getDbbgrp().getBas().getRptno();
            newBoprem.getDbbgrp().getBas().setRptno(dbbrptno);
            newBoprem.getDbbgrp().getDcl().setRptno(dbbrptno);

            dberptno = boprem.getDbegrp().getBas().getRptno();
            newBoprem.getDbegrp().getBas().setRptno(dberptno);
            newBoprem.getDbegrp().getVrf().setRptno(dberptno);
            newBoprem.setSzflg(boprem.getSzflg());
            return newBoprem;
        }

        //地区机构号取值
        String ownextkey = boprem.getOwnextkey();
        if (MdaUtils.compareTo(boprem.getSzflg(), "1") == 0 || MdaUtils.compareTo(boprem.getSzflg(), "2") == 0) {
            if (!boprem.isModified("ownextkey")) {
                //防止未选择客户时空值针
                if(!MdaUtils.isEmpty(SettleContext.getUserSession().getWrkbch())){
                    ownextkey = SettleContext.getUserSession().getWrkbch().getBranch();
                    boprem.setOwnextkey(ownextkey);
                }
            }
        }

        // 是否随业务申报
        if(MdaUtils.compareTo(szflg, "1") == 0 || MdaUtils.compareTo(szflg, "2") == 0){
            boprem.setAloneflg(aloneflg);
        }

        //款项来源
        if(MdaUtils.compareTo(szflg, "1") == 0){
            boprem.setActtyp(acttyp);
        }

        if(!(("1".equals(szflg) || "2".equals(szflg)) && "X".equals(basflg) && !MdaUtils.isEmpty(ownextkey))){
            return boprem;
        }

        PtsptaVo ptsptaAPL = ptsptaToolComponent.getPtsFromListByRol(boprem.getPtsList(), "APL");
        if (MdaUtils.isEmpty(ptsptaAPL)) {
            ptsptaAPL = new PtsptaVo();
            ptsptaAPL.reset();
        }

        PtsptaVo ptsptaPYE = ptsptaToolComponent.getPtsFromListByRol(boprem.getPtsList(), "PYE");
        if (MdaUtils.isEmpty(ptsptaPYE)) {
            ptsptaPYE = new PtsptaVo();
            ptsptaPYE.reset();
        }

        PtsptaVo ptsptaORC = ptsptaToolComponent.getPtsFromListByRol(boprem.getPtsList(), "ORC");
        if (MdaUtils.isEmpty(ptsptaORC)) {
            ptsptaORC = new PtsptaVo();
            ptsptaORC.reset();
        }

        PtsptaVo ptsptaDFF = ptsptaToolComponent.getPtsFromListByRol(boprem.getPtsList(), "DFF");
        if (MdaUtils.isEmpty(ptsptaDFF)) {
            ptsptaDFF = new PtsptaVo();
            ptsptaDFF.reset();
        }

        String boptyp = "BOPREM";

        String method = NULLSTR;

        String payTyp = NULLSTR;
        String payType = NULLSTR;
        String orcact = NULLSTR;
        // 银行业务编号
        String ownref = "";
        String objTyp = NULLSTR;
        //收款人名称
        String pyeact = NULLSTR;
        String hndtyp = NULLSTR;
        //外币款专户
        String ffaacc = NULLSTR;
        //默认对手费用收取角色 setmod里取
        String feecorrol = NULLSTR;
        //setmod 单据币种
        String doccur = NULLSTR;
        //cptadv 处理方式
        String accmod = NULLSTR;
        // dftset 代付金额
        BigDecimal dfuamt = BigDecimal.ZERO;
        // dftset 到付币种
        String rescur = NULLSTR;
        // dftset 代付利息
        BigDecimal resamt = BigDecimal.ZERO;
        //cptopn费用承担方
        String detchgcod = NULLSTR;
        //cptopn原始金额币种
        String oricur = NULLSTR;
        //cptopn原始金额
        BigDecimal oriamt = BigDecimal.ZERO;
        //cptopn汇款金额
        BigDecimal remamt = BigDecimal.ZERO;
        //setmode 自贸区主账号
        String zmqacc = NULLSTR;
        //收款人国别
        String payeecountcode = NULLSTR;
        //同名划转
        String tsnflg = NULLSTR;
        //根据交易类型组数
        switch (Strings.mid(transName, 1, 3)) {
            case "CPT":
                CpdBizInfoVo cpdBizInfoVo = (CpdBizInfoVo)boprem.getRec();
                ownref = cpdBizInfoVo.getOwnref();
                payTyp = cpdBizInfoVo.getPaytyp();
                payType = cpdBizInfoVo.getPaytype();
                objTyp = cpdBizInfoVo.getObjtyp();
                orcact = cpdBizInfoVo.getOrcact();
                pyeact = cpdBizInfoVo.getPyeact();
                ffaacc = cpdBizInfoVo.getFfaacc();
                doccur = cpdBizInfoVo.getDoccur();
                feecorrol = cpdBizInfoVo.getFeecorrol();
                accmod = cpdBizInfoVo.getAccmod();
                detchgcod = cpdBizInfoVo.getDetchgcod();
                oricur = cpdBizInfoVo.getOricur();
                oriamt = cpdBizInfoVo.getOriamt();
                Cbb cbb = (Cbb)boprem.getCbsMap().get("NOM1");
                remamt = cbb.getAmt();
                zmqacc = cpdBizInfoVo.getZmqacc();
                payeecountcode = cpdBizInfoVo.getPayeecountcode();
                tsnflg = cpdBizInfoVo.getTsnflg();
                break;
            case "DFT":
                DfdBizInfoVo dfdBizInfoVo = (DfdBizInfoVo)boprem.getRec();
                ownref = dfdBizInfoVo.getOwnref();
                objTyp = dfdBizInfoVo.getObjtyp();
                doccur = dfdBizInfoVo.getDfucur();
                dfuamt = dfdBizInfoVo.getDfuamt();
                resamt = dfdBizInfoVo.getResamt();
                rescur = dfdBizInfoVo.getRescur();
                break;
        }


        //境内申报最新需求,收付汇款人国别均为CHN，同名划转，账号性质为主账号或者为账号性质为资本项目，则交易编码为929010灰显不可修改
        if(MdaUtils.isEmpty(boprem.getBoptxcode())) {
            String boptxcode = NULLSTR;
            if (MdaUtils.compareTo(szflg, "2") == 0 && MdaUtils.compareTo(tsnflg, "X") == 0) {
                if (!MdaUtils.isEmpty(ptsptaORC.getPtainr())) {
                    String ptaInr = ptsptaORC.getPtainr();
                    Adr adr = adrMapper.selectByPtaInr(ptaInr);
                    if (!MdaUtils.isEmpty(adr)) {
                        String loccty = adr.getLoccty();
                        if (!MdaUtils.isEmpty(loccty)) {
                            String orccty = codetableService.getTblLabel(loccty, "CTYCOD");
                            if (!MdaUtils.isEmpty(orccty) && !MdaUtils.isEmpty(payeecountcode)) {
                                if (MdaUtils.compareTo(orccty, "CHN") == 0 && MdaUtils.compareTo(payeecountcode, "CHN") == 0 && MdaUtils.compareTo(tsnflg, "X") == 0 && bopdecCommonService.isAccountZbxm(orcact)) {
                                    boptxcode = "929010";
                                }
                            }
                        }
                    }
                }
            }
            if (!boprem.isModified("boptxcode")) {
                boprem.setBoptxcode(boptxcode);
            }
        }

        //设置申报子类型
        if("1".equals(boprem.getSzflg())){
            boprem.setBopobjtyp("DBB");
        }
        if("2".equals(boprem.getSzflg())){
            boprem.setBopobjtyp("DBE");
        }

        if("X".equals(basflg)) {
            //设置收付汇日期
            if (MdaUtils.isEmpty(boprem.getPaydat())) {
                String dectyp = ctlmodService.setDectyp(transName);
                if ("V".equals(dectyp)) {
                    boprem.setPaydat(bopdecCommonService.getCoreSysDay());
                }
            }

//            if (MdaUtils.compareTo(boprem.getSzflg(), "1") == 0 || MdaUtils.compareTo(boprem.getSzflg(), "2") == 0) {
//                if (!boprem.isModified("ownextkey")) {
//                    Bch wrkBch = SettleContext.getUserSession().getWrkbch();
//                    boprem.setOwnextkey(wrkBch.getBranch());
//                }
//            }

            boprem.getDbbgrp().getBas().setBuscode(ownref);
            boprem.getDbegrp().getBas().setBuscode(ownref);

            //设置申报样式
            String typ = bopdecCommonService.getBopdecTyp(boptyp,boprem.getSzflg(),boprem.getBasflg(),boprem.getDclflg(),boprem.getVrfflg());
            boprem.setTyp(typ);
            //设置申报大类型BOPREM
            boprem.setBoptyp(boptyp);

            switch (payType) {
                case "0":
                    method = "T";
                    break;
                case "1":
                    method = "D";
                    break;
                case "2":
                    method = "M";
                    break;
                default:
                    method = "";
            }

            if(MdaUtils.compareTo(transName,"DFTSET") == 0){
                if (!boprem.getDbbgrp().getBas().isModified("method")) {
                    boprem.getDbbgrp().getBas().setMethod("T");
                }
                if (!boprem.getDbegrp().getBas().isModified("method")) {
                    boprem.getDbegrp().getBas().setMethod("T");
                }
            }else {
                if (!boprem.getDbbgrp().getBas().isModified("method")) {
                    boprem.getDbbgrp().getBas().setMethod(method);
                }
                if (!boprem.getDbegrp().getBas().isModified("method")) {
                    boprem.getDbegrp().getBas().setMethod(method);
                }
            }

            // 获取交易币种
            String cur = bopdecCommonService.getTranCur(transName, boprem.getCbsMap());
            //组织机构代码
            String nam1 = NULLSTR;
            String juscod = NULLSTR;
            Pty pty = bopdecCommonService.getPtyByTransname(transName, boprem.getPtsList(), "APL", payTyp, hndtyp);
            if (!MdaUtils.isEmpty(pty)) {
                nam1 = pty.getNam1();
                juscod = pty.getJuscod();
            }
            if (!boprem.getDbbgrp().getBas().isModified("custnm")) {
                boprem.getDbbgrp().getBas().setCustnm(nam1);
            }
            if (!boprem.getDbegrp().getBas().isModified("custnm")) {
                boprem.getDbegrp().getBas().setCustnm(nam1);
            }
            BigDecimal txamt = null;
            /*
            else if("CPTOPN".equals(transName) && "BEN".equals(detchgcod)){
                txamt = oriamt;

            }
             */
            //DFTSET 申报金额取代付利息---刘奕洋
            if(MdaUtils.compareTo(transName,"DFTSET") == 0){
                txamt = Numerics.round(resamt,0);
            }else {
                txamt = bopdecCommonService.gettxccy(transName, boprem.getSetgll(), accmod,"");
            }
            if (!boprem.getDbbgrp().getBas().isModified("txamt")) {
                boprem.getDbbgrp().getBas().setTxamt(txamt);
            }
            if (!boprem.getDbegrp().getBas().isModified("txamt")) {
                boprem.getDbegrp().getBas().setTxamt(txamt);
            }
            if(MdaUtils.compareTo(transName,"DFTSET") == 0){
                if (!boprem.getDbbgrp().getBas().isModified("txccy")) {
                    boprem.getDbbgrp().getBas().setTxccy(rescur);
                }
                if (!boprem.getDbegrp().getBas().isModified("txccy")) {
                    boprem.getDbegrp().getBas().setTxccy(rescur);
                }
            }else{
                if (!boprem.getDbbgrp().getBas().isModified("txccy")) {
                    boprem.getDbbgrp().getBas().setTxccy(doccur);
                }
                if (!boprem.getDbegrp().getBas().isModified("txccy")) {
                    boprem.getDbegrp().getBas().setTxccy(doccur);
                }
            }
            /*
            if (!boprem.getDbbgrp().getBas().isModified("txccy")) {
                if("CPTOPN".equals(transName) && "BEN".equals(detchgcod)){
                    boprem.getDbbgrp().getBas().setTxccy(oricur);
                }else {
                    boprem.getDbbgrp().getBas().setTxccy(doccur);
                }
            }
             */

            /*
            if (!boprem.getDbegrp().getBas().isModified("txccy")) {
                if("CPTOPN".equals(transName) && "BEN".equals(detchgcod)){
                    boprem.getDbegrp().getBas().setTxccy(oricur);
                }else {
                    boprem.getDbegrp().getBas().setTxccy(doccur);
                }
            }

             */


            String transRol = bopdecCommonService.getTranRol(transName);
            Pty pty1 = bopdecCommonService.getPtyByTransname(transName, boprem.getPtsList(), transRol, payTyp, hndtyp);
            String fieldVal = NULLSTR;
            String fieldVal1 = NULLSTR;
            //身份证号
            String idCode = NULLSTR;
            if (!MdaUtils.isEmpty(pty1)) {
                fieldVal = pty1.getExtkey();
                fieldVal1 = pty1.getIdtype();
                idCode = pty1.getIdcode();
            }
            if (MdaUtils.compareTo(fieldVal1, "1") == 0 || MdaUtils.compareTo(fieldVal1, "2") == 0) {
                boprem.getDbbgrp().getBas().setCustype("C");
                boprem.getDbegrp().getBas().setCustype("C");
            } else {
                if (!MdaUtils.isEmpty(fieldVal1)) {
                    boprem.getDbbgrp().getBas().setCustype(fieldVal1);
                    boprem.getDbegrp().getBas().setCustype(fieldVal1);
                } else {
                    boprem.getDbbgrp().getBas().setCustype("C");
                    boprem.getDbegrp().getBas().setCustype("C");
                }
            }
            //获得组织机构代码
            if (MdaUtils.compareTo(boprem.getDbbgrp().getBas().getCustype(), "C") == 0) {
                //对公
                if (!boprem.getDbbgrp().getBas().isModified("custcod")) {
                    boprem.getDbbgrp().getBas().setCustcod(juscod);
                }
                if (!boprem.getDbegrp().getBas().isModified("custcod")) {
                    boprem.getDbegrp().getBas().setCustcod(juscod);
                }
                if (!boprem.getDbbgrp().getBas().isModified("idcode")) {
                    boprem.getDbbgrp().getBas().setIdcode("");
                }
                if (!boprem.getDbegrp().getBas().isModified("idcode")) {
                    boprem.getDbegrp().getBas().setIdcode("");
                }
            } else {
                //给身份证号赋值
                if (!boprem.getDbbgrp().getBas().isModified("idcode")) {
                    boprem.getDbbgrp().getBas().setIdcode(idCode);
                }
                if (!boprem.getDbegrp().getBas().isModified("idcode")) {
                    boprem.getDbegrp().getBas().setIdcode(idCode);
                }
                if (!boprem.getDbbgrp().getBas().isModified("custcod")) {
                    boprem.getDbbgrp().getBas().setCustcod("");
                }
                if (!boprem.getDbegrp().getBas().isModified("custcod")) {
                    boprem.getDbegrp().getBas().setCustcod("");
                }
            }

            //针对购汇金额，现汇金额，其他金额小于0.5的
            Map<String, BigDecimal> amtList = new HashMap<>();
            Map<String, String> accList = new HashMap<>();
            bopdecCommonService.getBasic(transName, boprem.getSetgll(), cur, ffaacc, amtList, accList);
            String lcyacc = accList.get("lcyacc");
            BigDecimal exrate = amtList.get("exrate");
            String fcyacc = accList.get("fcyacc");
            String othacc = accList.get("othacc");
            BigDecimal lcyamt = amtList.get("lcyamt");
            BigDecimal fcyamt = amtList.get("fcyamt");
            BigDecimal othamt = amtList.get("othamt");
            if(MdaUtils.compareTo(transName,"DFTSET") == 0){
                if (!boprem.getDbbgrp().getBas().isModified("lcyacc")) {
                    boprem.getDbbgrp().getBas().setLcyacc(ptsptaAPL.getDftact());
                }
                if (!boprem.getDbegrp().getBas().isModified("lcyacc")) {
                    boprem.getDbegrp().getBas().setLcyacc(ptsptaAPL.getDftact());
                }
            }else {
                if (!boprem.getDbbgrp().getBas().isModified("lcyacc")) {
                    boprem.getDbbgrp().getBas().setLcyacc(lcyacc);
                }
                if (!boprem.getDbegrp().getBas().isModified("lcyacc")) {
                    boprem.getDbegrp().getBas().setLcyacc(lcyacc);
                }
            }
            if (!boprem.getDbbgrp().getBas().isModified("exrate")) {
                boprem.getDbbgrp().getBas().setExrate(exrate);
            }
            if (!boprem.getDbegrp().getBas().isModified("exrate")) {
                boprem.getDbegrp().getBas().setExrate(exrate);
            }
            if(MdaUtils.compareTo(transName,"DFTSET") == 0){
                if (!boprem.getDbbgrp().getBas().isModified("fcyacc")) {
                    boprem.getDbbgrp().getBas().setFcyacc(ptsptaAPL.getDftact());
                }
                if (!boprem.getDbegrp().getBas().isModified("fcyacc")) {
                    boprem.getDbegrp().getBas().setFcyacc(ptsptaAPL.getDftact());
                }
            }else {
                if (!boprem.getDbbgrp().getBas().isModified("fcyacc")) {
                    boprem.getDbbgrp().getBas().setFcyacc(fcyacc);
                }
                if (!boprem.getDbegrp().getBas().isModified("fcyacc")) {
                    boprem.getDbegrp().getBas().setFcyacc(fcyacc);
                }
            }
            if (!boprem.getDbbgrp().getBas().isModified("othacc")) {
                boprem.getDbbgrp().getBas().setOthacc(othacc);
            }
            if (!boprem.getDbegrp().getBas().isModified("othacc")) {
                boprem.getDbegrp().getBas().setOthacc(othacc);
            }
            if (!boprem.getDbbgrp().getBas().isModified("lcyamt")) {
                boprem.getDbbgrp().getBas().setLcyamt(Numerics.round(lcyamt, 0));
            }
            if (!boprem.getDbegrp().getBas().isModified("lcyamt")) {
                boprem.getDbegrp().getBas().setLcyamt(Numerics.round(lcyamt, 0));
            }
            if(MdaUtils.compareTo(transName,"DFTSET") == 0){
                if (!boprem.getDbbgrp().getBas().isModified("fcyamt")) {
                    boprem.getDbbgrp().getBas().setFcyamt(Numerics.round(resamt,0));
                }
                if (!boprem.getDbegrp().getBas().isModified("fcyamt")) {
                    boprem.getDbegrp().getBas().setFcyamt(Numerics.round(resamt,0));
                }
            }else {
                if (!boprem.getDbbgrp().getBas().isModified("fcyamt")) {
                    boprem.getDbbgrp().getBas().setFcyamt(Numerics.round(fcyamt, 0));
                }
                if (!boprem.getDbegrp().getBas().isModified("fcyamt")) {
                    boprem.getDbegrp().getBas().setFcyamt(Numerics.round(fcyamt, 0));
                }
            }
            if (!boprem.getDbbgrp().getBas().isModified("othamt")) {
                boprem.getDbbgrp().getBas().setOthamt(Numerics.round(othamt, 0));
            }
            if (!boprem.getDbegrp().getBas().isModified("othamt")) {
                boprem.getDbegrp().getBas().setOthamt(Numerics.round(othamt, 0));
            }

            //特殊处理cptopn，刘小璐，购汇金额/其他金额取汇款金额-----先注释掉该逻辑，影响到了有购汇的情况
            //出汇款交易 需要针对 自贸区机构 业务进行特殊处理，如果是自贸区，申报的汇款人账号需要取主账号
            String zmqflg = NULLSTR;
            Bch bch = SettleContext.getUserSession().getBch();
            if(!MdaUtils.isEmpty(bch)){
                zmqflg = bch.getZmqflg();
            }
            if("CPTOPN".equals(transName)){
                if(fcyamt.compareTo(BigDecimal.ZERO) > 0){
                    //特殊处理cptopn，刘小璐，购汇金额/其他金额取汇款金额-----先注释掉该逻辑，影响到了有购汇的情况
//                    if (!boprem.getDbbgrp().getBas().isModified("fcyamt")) {
//                        boprem.getDbbgrp().getBas().setFcyamt(Numerics.round(remamt, 0));
//                    }
//                    if (!boprem.getDbegrp().getBas().isModified("fcyamt")) {
//                        boprem.getDbegrp().getBas().setFcyamt(Numerics.round(remamt, 0));
//                    }
                    if("X".equals(zmqflg)){
                        if (!boprem.getDbbgrp().getBas().isModified("fcyacc")) {
                            boprem.getDbbgrp().getBas().setFcyacc(zmqacc);
                        }
                        if (!boprem.getDbegrp().getBas().isModified("fcyacc")) {
                            boprem.getDbegrp().getBas().setFcyacc(zmqacc);
                        }
                    }
                }
                if(othamt.compareTo(BigDecimal.ZERO) > 0){
                    //特殊处理cptopn，刘小璐，购汇金额/其他金额取汇款金额-----先注释掉该逻辑，影响到了有购汇的情况
//                    if (!boprem.getDbbgrp().getBas().isModified("othamt")) {
//                        boprem.getDbbgrp().getBas().setOthamt(Numerics.round(remamt, 0));
//                    }
//                    if (!boprem.getDbegrp().getBas().isModified("othamt")) {
//                        boprem.getDbegrp().getBas().setOthamt(Numerics.round(remamt, 0));
//                    }
                    if("X".equals(zmqflg)){
                        if (!boprem.getDbbgrp().getBas().isModified("othacc")) {
                            boprem.getDbbgrp().getBas().setOthacc(zmqacc);
                        }
                        if (!boprem.getDbegrp().getBas().isModified("othacc")) {
                            boprem.getDbegrp().getBas().setOthacc(zmqacc);
                        }
                    }
                }
            }


            if (MdaUtils.compareTo(transName, "CPTOPN") == 0 || MdaUtils.compareTo(transName, "CPTATO") == 0 || MdaUtils.compareTo(transName, "CPTHYF") == 0) {
                //刘文青要求统一修改为取pts的nam
                if (!MdaUtils.isEmpty(ptsptaPYE.getPts())) {
                    if (!boprem.getDbbgrp().getBas().isModified("oppuser")) {
                        boprem.getDbbgrp().getBas().setOppuser(ptsptaPYE.getPts().getNam());
                    }
                    if (!boprem.getDbegrp().getBas().isModified("oppuser")) {
                        boprem.getDbegrp().getBas().setOppuser(ptsptaPYE.getPts().getNam());
                    }
                }
                //cgl for szsb2012
                // 境外申报收款人名称前面增加境内境外下拉框，联动款项去向。(JW)(JN)与收款人名称分开-----边仲超
                // 境内境外下拉框赋值
                boprem.getDbbgrp().getBas().setJwjn(boprem.getActtyp());
                if (!boprem.getDbbgrp().getBas().isModified("oppuser")) {
//                    boprem.getDbbgrp().getBas().setOppuser(boprem.getActtyp() + boprem.getDbbgrp().getBas().getOppuser());
                    // 如果是对私业务，付款人名称后增加付款人账号信息，以名称后加“[acc:账号]”表示。
                    //对于速汇业务和托收等没有对应账号的业务，账号部分填写“000000”（六个零）。
                    if (MdaUtils.compareTo(boprem.getDbbgrp().getBas().getCustype(), "C") != 0) {
                        if (!MdaUtils.isEmpty(pyeact)) {
                            boprem.getDbbgrp().getBas().setOppuser(boprem.getDbbgrp().getBas().getOppuser() + "[acc:" + pyeact + "]");
                        } else {
                            boprem.getDbbgrp().getBas().setOppuser(boprem.getDbbgrp().getBas().getOppuser() + "[acc:000000]");
                        }
                    }
                }
                boprem.getDbegrp().getBas().setOppacc(pyeact);
            }
            if (MdaUtils.compareTo(transName, "CPTADV") == 0 || MdaUtils.compareTo(transName, "CPTATI") == 0) {
                if (!MdaUtils.isEmpty(ptsptaORC.getPts())) {
                    if (!boprem.getDbbgrp().getBas().isModified("oppuser")) {
                        boprem.getDbbgrp().getBas().setOppuser(ptsptaORC.getPts().getNam());
                    }
                    if (!boprem.getDbegrp().getBas().isModified("oppuser")) {
                        boprem.getDbegrp().getBas().setOppuser(ptsptaORC.getPts().getNam());
                    }
                }
            }
            //dftset oppuser取代付行---刘奕洋
            if(MdaUtils.compareTo(transName,"DFTSET") == 0){
                if (!MdaUtils.isEmpty(ptsptaDFF.getPts())) {
                    if (!boprem.getDbbgrp().getBas().isModified("oppuser")) {
                        boprem.getDbbgrp().getBas().setOppuser(ptsptaDFF.getPts().getNam());
                    }
                    if (!boprem.getDbegrp().getBas().isModified("oppuser")) {
                        boprem.getDbegrp().getBas().setOppuser(ptsptaDFF.getPts().getNam());
                    }
                }
            }
            //给地区机构号赋值
            boprem.getDbbgrp().getBas().setOwnextkey(ownextkey);
            boprem.getDbegrp().getBas().setOwnextkey(ownextkey);

            //给ctlmod中的dectyp赋值
            boprem.getCtlmod().setDectyp(ctlmodService.setDectyp(transName));

            //生成rptno
            RptnoRequestVo rptnoRequestVo = new RptnoRequestVo();
            rptnoRequestVo.setOwnextkey(ownextkey);
            rptnoRequestVo.setBopobjtyp(boprem.getBopobjtyp());
            rptnoRequestVo.setTransname(transName);
            rptnoRequestVo.setPaydat(boprem.getPaydat());
            rptnoRequestVo.setWrkDblReldat(boprem.getCtlmod().getWrkdbl().getReldat());
            if ("1".equals(szflg) && "X".equals(basflg)) {
                rptnoRequestVo.setCustype(boprem.getDbbgrp().getBas().getCustype());
                rptnoRequestVo.setRptno(boprem.getDbbgrp().getBas().getRptno());
            }
            if ("2".equals(szflg) && "X".equals(basflg)) {
                rptnoRequestVo.setCustype(boprem.getDbegrp().getBas().getCustype());
                rptnoRequestVo.setRptno(boprem.getDbegrp().getBas().getRptno());
            }
            String ref = bopdecCommonService.getRef(rptnoRequestVo);
            if (!MdaUtils.isEmpty(ref)) {
                boprem.getDbbgrp().getBas().setRptno(ref);
                boprem.getDbegrp().getBas().setRptno(ref);
            }
        }
        if("X".equals(dclflg)){
            if(!MdaUtils.isEmpty(boprem.getDbbgrp().getBas().getRptno())){
                boprem.getDbbgrp().getDcl().setRptno(boprem.getDbbgrp().getBas().getRptno());
            }
            if("1".equals(szflg)){
                String ptyInr = NULLSTR;
                switch (transName){
                    case "CPTOPN":
                        ptyInr = ptsptaORC.getPtyinr();
                        break;
                }
                if(!MdaUtils.isEmpty(ptyInr)){
                    Ptc ptc = bopdecCommonService.getPtcInfo(ptyInr,"BOP");
                    if(!MdaUtils.isEmpty(ptc)){
                        if(!boprem.getDbbgrp().getDcl().isModified("crtuser")){
                            boprem.getDbbgrp().getDcl().setCrtuser(ptc.getNam());
                        }
                        if(!boprem.getDbbgrp().getDcl().isModified("inptelc")){
                            boprem.getDbbgrp().getDcl().setInptelc(ptc.getTelmob());
                        }
                    }
                }
                //申报日期默认取当天
                if (!boprem.getDbbgrp().getDcl().isModified("rptdate")) {
                    boprem.getDbbgrp().getDcl().setRptdate(Dates.today());
                }
                //收款人国别取业务信息里收款人国别
                if(!boprem.getDbbgrp().getDcl().isModified("country")) {
                    boprem.getDbbgrp().getDcl().setCountry(payeecountcode);
                }
            }
        }
        if("X".equals(vrfflg)){
            String ptyInr = NULLSTR;
            Ptc ptc = null;
            switch (transName){
                case "CPTOPN":
                    ptyInr = ptsptaORC.getPtyinr();
                    break;
            }
            if(!MdaUtils.isEmpty(ptyInr)) {
                ptc = bopdecCommonService.getPtcInfo(ptyInr, "BOP");
            }
            if("1".equals(szflg)){
                if(!MdaUtils.isEmpty(boprem.getDbbgrp().getBas().getRptno())){
                    boprem.getDbbgrp().getVrf().setRptno(boprem.getDbbgrp().getBas().getRptno());
                }
                if(!MdaUtils.isEmpty(ptc)){
                    if(!boprem.getDbbgrp().getVrf().isModified("crtuser")){
                        boprem.getDbbgrp().getVrf().setCrtuser(ptc.getNam());
                    }
                    if(!boprem.getDbbgrp().getVrf().isModified("inptelc")){
                        boprem.getDbbgrp().getVrf().setInptelc(ptc.getTelmob());
                    }
                }
                //申报日期默认取当天
                if (!boprem.getDbbgrp().getVrf().isModified("rptdate")) {
                    boprem.getDbbgrp().getVrf().setRptdate(Dates.today());
                }
            }
            if("2".equals(szflg)){
                if(!MdaUtils.isEmpty(boprem.getDbegrp().getBas().getRptno())){
                    boprem.getDbegrp().getVrf().setRptno(boprem.getDbegrp().getBas().getRptno());
                }
                if(!MdaUtils.isEmpty(ptc)){
                    if(!boprem.getDbegrp().getVrf().isModified("crtuser")){
                        boprem.getDbegrp().getVrf().setCrtuser(ptc.getNam());
                    }
                    if(!boprem.getDbegrp().getVrf().isModified("inptelc")){
                        boprem.getDbegrp().getVrf().setInptelc(ptc.getTelmob());
                    }
                }
                //申报日期默认取当天
                if (!boprem.getDbegrp().getVrf().isModified("rptdate")) {
                    boprem.getDbegrp().getVrf().setRptdate(Dates.today());
                }
                //收款人国别取业务信息里收款人国别
                if(!boprem.getDbegrp().getVrf().isModified("country")) {
                    boprem.getDbegrp().getVrf().setCountry(payeecountcode);
                }
            }
        }
        //设置校验字段
        this.setCheckItems(boprem);
        return boprem;
    }

    private void setCheckItems(Boprem boprem){
        CheckItems checkItems = new CheckItems();
        String dectyp = ctlmodService.setDectyp(boprem.getTransName());
        checkItems.setDectyp(dectyp);
        checkItems.setTransName(boprem.getTransName());
        checkItems.setSzflg(boprem.getSzflg());
        checkItems.setBasflg(boprem.getBasflg());
        checkItems.setDclflg(boprem.getDclflg());
        checkItems.setVrfflg(boprem.getVrfflg());
        checkItems.setActtyp(boprem.getActtyp());
        checkItems.setZbxmszh(boprem.getZbxmszh());
        checkItems.setBopobjtyp(boprem.getBopobjtyp());
        if("1".equals(boprem.getSzflg())){
            checkItems.setBuscode(boprem.getDbbgrp().getBas().getBuscode());
            checkItems.setBasactiontype(boprem.getDbbgrp().getBas().getActiontype());
            checkItems.setCustcod(boprem.getDbbgrp().getBas().getCustcod());
            checkItems.setTxccy(boprem.getDbbgrp().getBas().getTxccy());
            checkItems.setExrate(boprem.getDbbgrp().getBas().getExrate());
            checkItems.setFcyacc(boprem.getDbbgrp().getBas().getFcyacc());
            checkItems.setFcyamt(boprem.getDbbgrp().getBas().getFcyamt());
            checkItems.setIdcode(boprem.getDbbgrp().getBas().getIdcode());
            checkItems.setLcyacc(boprem.getDbbgrp().getBas().getLcyacc());
            checkItems.setLcyamt(boprem.getDbbgrp().getBas().getLcyamt());
            checkItems.setOppuser(boprem.getActtyp() + boprem.getDbbgrp().getBas().getOppuser());
            checkItems.setOthacc(boprem.getDbbgrp().getBas().getOthacc());
            checkItems.setOthamt(boprem.getDbbgrp().getBas().getOthamt());
            checkItems.setTxamt(boprem.getDbbgrp().getBas().getTxamt());
            checkItems.setOwnextkey(boprem.getDbbgrp().getBas().getOwnextkey());
            checkItems.setBasactiondesc(boprem.getDbbgrp().getBas().getActiondesc());
            checkItems.setRptno(boprem.getDbbgrp().getBas().getRptno());
            checkItems.setMethod(boprem.getDbbgrp().getBas().getMethod());
            checkItems.setCustnm(boprem.getDbbgrp().getBas().getCustnm());
            checkItems.setCustype(boprem.getDbbgrp().getBas().getCustype());
            if("X".equals(boprem.getDclflg())){
                checkItems.setDclactiontype(boprem.getDbbgrp().getDcl().getActiontype());
                checkItems.setCountry(boprem.getDbbgrp().getDcl().getCountry());
                checkItems.setDclcrtuser(boprem.getDbbgrp().getDcl().getCrtuser());
                checkItems.setDclinptelc(boprem.getDbbgrp().getDcl().getInptelc());
                checkItems.setDclisref(boprem.getDbbgrp().getDcl().getIsref());
                checkItems.setPaytype(boprem.getDbbgrp().getDcl().getPaytype());
                checkItems.setDclrptdate(boprem.getDbbgrp().getDcl().getRptdate());
                checkItems.setTc1amt(boprem.getDbbgrp().getDcl().getTc1amt());
                checkItems.setTc2amt(boprem.getDbbgrp().getDcl().getTc2amt());
                checkItems.setTxrem(boprem.getDbbgrp().getDcl().getTxrem());
                checkItems.setTx2rem(boprem.getDbbgrp().getDcl().getTx2rem());
                checkItems.setTxcode(boprem.getDbbgrp().getDcl().getTxcode());
                checkItems.setTxcode2(boprem.getDbbgrp().getDcl().getTxcode2());
                checkItems.setDclactiondesc(boprem.getDbbgrp().getDcl().getActiondesc());
                checkItems.setRegno(boprem.getDbbgrp().getDcl().getRegno());
            }
            if("X".equals(boprem.getVrfflg())){
                checkItems.setVrfactiondesc(boprem.getDbbgrp().getVrf().getActiondesc());
                checkItems.setVrfactiontype(boprem.getDbbgrp().getVrf().getActiontype());
                checkItems.setVrfcrtuser(boprem.getDbbgrp().getVrf().getCrtuser());
                checkItems.setVrfinptelc(boprem.getDbbgrp().getVrf().getInptelc());
                checkItems.setVrfrptdate(boprem.getDbbgrp().getVrf().getRptdate());
                checkItems.setContrno(boprem.getDbbgrp().getVrf().getContrno());
                checkItems.setInvoino(boprem.getDbbgrp().getVrf().getInvoino());
            }
        }
        if("2".equals(boprem.getSzflg())){
            checkItems.setBuscode(boprem.getDbegrp().getBas().getBuscode());
            checkItems.setBasactiontype(boprem.getDbegrp().getBas().getActiontype());
            checkItems.setCustcod(boprem.getDbegrp().getBas().getCustcod());
            checkItems.setTxccy(boprem.getDbegrp().getBas().getTxccy());
            checkItems.setExrate(boprem.getDbegrp().getBas().getExrate());
            checkItems.setFcyacc(boprem.getDbegrp().getBas().getFcyacc());
            checkItems.setFcyamt(boprem.getDbegrp().getBas().getFcyamt());
            checkItems.setIdcode(boprem.getDbegrp().getBas().getIdcode());
            checkItems.setLcyacc(boprem.getDbegrp().getBas().getLcyacc());
            checkItems.setLcyamt(boprem.getDbegrp().getBas().getLcyamt());
            checkItems.setOppuser(boprem.getDbegrp().getBas().getOppuser());
            checkItems.setOthacc(boprem.getDbegrp().getBas().getOthacc());
            checkItems.setOthamt(boprem.getDbegrp().getBas().getOthamt());
            checkItems.setTxamt(boprem.getDbegrp().getBas().getTxamt());
            checkItems.setOwnextkey(boprem.getDbegrp().getBas().getOwnextkey());
            checkItems.setBasactiondesc(boprem.getDbegrp().getBas().getActiondesc());
            checkItems.setRptno(boprem.getDbegrp().getBas().getRptno());
            checkItems.setMethod(boprem.getDbegrp().getBas().getMethod());
            checkItems.setCustnm(boprem.getDbegrp().getBas().getCustnm());
            checkItems.setCustype(boprem.getDbegrp().getBas().getCustype());
            checkItems.setOppacc(boprem.getDbegrp().getBas().getOppacc());
            if("X".equals(boprem.getVrfflg())){
                checkItems.setVrfactiontype(boprem.getDbegrp().getVrf().getActiontype());
                checkItems.setVrfactiondesc(boprem.getDbegrp().getVrf().getActiondesc());
                checkItems.setVrfcrtuser(boprem.getDbegrp().getVrf().getCrtuser());
                checkItems.setVrfinptelc(boprem.getDbegrp().getVrf().getInptelc());
                checkItems.setVrfisref(boprem.getDbegrp().getVrf().getIsref());
                checkItems.setPaytype(boprem.getDbegrp().getVrf().getPaytype());
                checkItems.setVrfrptdate(boprem.getDbegrp().getVrf().getRptdate());
                checkItems.setTc1amt(boprem.getDbegrp().getVrf().getTc1amt());
                checkItems.setTc2amt(boprem.getDbegrp().getVrf().getTc2amt());
                checkItems.setTxrem(boprem.getDbegrp().getVrf().getTxrem());
                checkItems.setTx2rem(boprem.getDbegrp().getVrf().getTx2rem());
                checkItems.setTxcode(boprem.getDbegrp().getVrf().getTxcode());
                checkItems.setTxcode2(boprem.getDbegrp().getVrf().getTxcode2());
                checkItems.setPayattr(boprem.getDbegrp().getVrf().getPayattr());
                checkItems.setRegno(boprem.getDbegrp().getVrf().getRegno());
                checkItems.setContrno(boprem.getDbegrp().getVrf().getContrno());
                checkItems.setCountry(boprem.getDbegrp().getVrf().getCountry());
                checkItems.setInvoino(boprem.getDbegrp().getVrf().getInvoino());
            }
        }
        boprem.setCheckItems(checkItems);
    }

    @Override
    public void saveBopremData(Boprem boprem) {
        //需要从业务里去数据
        String objTyp = "";
        String hndtyp = "";
        String transName = boprem.getTransName().toUpperCase();
        BopActionTypeVo bopActionTypeVo = new BopActionTypeVo();
        if("1".equals(boprem.getSzflg())){
            bopActionTypeVo.setBasActionType(boprem.getDbbgrp().getBas().getActiontype());
            bopActionTypeVo.setDclActionType(boprem.getDbbgrp().getDcl().getActiontype());
            bopActionTypeVo.setVrfActionType(boprem.getDbbgrp().getVrf().getActiontype());
        }
        if("2".equals(boprem.getSzflg())){
            bopActionTypeVo.setBasActionType(boprem.getDbegrp().getBas().getActiontype());
            bopActionTypeVo.setVrfActionType(boprem.getDbegrp().getVrf().getActiontype());
        }

        switch (Strings.mid(transName, 1, 3)) {
            case "CPT":
                CpdBizInfoVo cpdBizInfoVo = (CpdBizInfoVo)boprem.getRec();
                objTyp = cpdBizInfoVo.getObjtyp();
                break;
            case "BOT":
                BodBizInfoVo bodBizInfoVo = (BodBizInfoVo)boprem.getRec();
                objTyp = bodBizInfoVo.getObjtyp();
                break;
            case "CCT":
                CcdBizInfoVo ccdBizInfoVo = (CcdBizInfoVo)boprem.getRec();
                objTyp = ccdBizInfoVo.getObjtyp();
                break;
            case "BPT":
                BpdBizInfoVo bpdBizInfoVo = (BpdBizInfoVo)boprem.getRec();
                objTyp = bpdBizInfoVo.getObjtyp();
                break;
            case "BET":
                BedBizInfoVo bedBizInfoVo = (BedBizInfoVo)boprem.getRec();
                objTyp = bedBizInfoVo.getObjtyp();
                break;
            case "BTT":
                BtdBizInfoVo btdBizInfoVo = (BtdBizInfoVo)boprem.getRec();
                objTyp = btdBizInfoVo.getObjtyp();
                break;
        }

        BopObjectType bopObjectType = bopdecCommonService.getBopremInfobyType(transName,hndtyp,boprem.getTyp());

        String ownref = "";
        String busCode = "";
        TrnmodVo trnmodVo = transactionHelpService.getTransactionStoreSet().getTrnmodVo();
        ownref = trnmodVo.getTrn().getOwnref();
        if(MdaUtils.compareTo(boprem.getSzflg(),"1") == 0){
            busCode = boprem.getDbbgrp().getBas().getBuscode();
            if( !MdaUtils.isEmpty(ownref) && MdaUtils.compareTo(ownref,busCode) != 0 ) {
                boprem.getDbbgrp().getBas().setBuscode(ownref);
            }

        }
        if(MdaUtils.compareTo(boprem.getSzflg(),"2") == 0){
            busCode = boprem.getDbegrp().getBas().getBuscode();
            if( !MdaUtils.isEmpty(ownref) && MdaUtils.compareTo(ownref,busCode) != 0 ) {
                boprem.getDbegrp().getBas().setBuscode(ownref);
            }
        }

        this.saveTmpRef(boprem);

        Dbl dbl = ctlmodService.setDblSta(transName,bopActionTypeVo,bopObjectType,boprem.getCtlmod().getDbl(),boprem.getCtlmod().getWrkdbl());
        boprem.getCtlmod().setDbl(dbl);
        // 拼接收款人名称
        boprem.getDbbgrp().getBas().setOppuser(boprem.getActtyp() + boprem.getDbbgrp().getBas().getOppuser());
        ctlmodService.bopRemStoreContract(boprem);
//        String tratyp = ctlmodService.getTraTyp("REM","","");
        boprem.getCtlmod().getDbl().setActtyp(boprem.getActtyp());
        ctlmodService.setBopremDblDat(boprem,bopObjectType.getSubtyp());
        ctlmodService.bopStoreDBL(transName,boprem.getCtlmod(),"");

    }

    @Override
    public void repairBopremData(String trninr) {
        this.repairDbbData(trninr);
        this.repairDbeData(trninr);
    }

    private void repairDbbData(String trninr){
        if (MdaUtils.isEmpty(trninr)) {
            return;
        }
        Dbl dblObj = dblMapper.selectByOBjtypAndTrninr("DBB",trninr);
        if (!MdaUtils.isEmpty(dblObj)) {
            String objInr = dblObj.getObjinr();
            if(!MdaUtils.isEmpty(objInr)) {
                Dbb dbbCondition = new Dbb();
                dbbCondition.setInr(objInr);
                Dbb dbbObj = dbbMapper.selectByPrimaryKey(dbbCondition);
                if(!MdaUtils.isEmpty(dbbObj)){
                    sysmodService.sdbDeleteWithLog(dbbObj);
                }
                Dbh dbhObj = dbhMapper.selectByTmpref(objInr);
                if(!MdaUtils.isEmpty(dbhObj)){
                    sysmodService.sdbDeleteWithLog(dbhObj);
                }
                Dbn dbnObj = dbnMapper.selectByTmpref(objInr);
                if(!MdaUtils.isEmpty(dbnObj)){
                    sysmodService.sdbDeleteWithLog(dbnObj);
                }
            }
            sysmodService.sdbDeleteWithLog(dblObj);
        }
    }

    private void repairDbeData(String trninr){
        if (MdaUtils.isEmpty(trninr)) {
            return;
        }
        Dbl dblObj = dblMapper.selectByOBjtypAndTrninr("DBE",trninr);
        if (!MdaUtils.isEmpty(dblObj)) {
            String objInr = dblObj.getObjinr();
            if(!MdaUtils.isEmpty(objInr)) {
                Dbe dbeCondition = new Dbe();
                dbeCondition.setInr(objInr);
                Dbe dbeObj = dbeMapper.selectByPrimaryKey(dbeCondition);
                if(!MdaUtils.isEmpty(dbeObj)){
                    sysmodService.sdbDeleteWithLog(dbeObj);
                }
                Dbq dbqObj = dbqMapper.selectByTmpref(objInr);
                if(!MdaUtils.isEmpty(dbqObj)){
                    sysmodService.sdbDeleteWithLog(dbqObj);
                }
            }
            sysmodService.sdbDeleteWithLog(dblObj);
        }
    }

    @Override
    public void saveSpt(Boprem boprem) {
        //通过境内境外判断交易码
        if("1".equals(boprem.getSzflg())){
            BopUtils.saveSpt("DBBAME");
        }else{
            BopUtils.saveSpt("DBEAME");
        }
    }

    /**
     * 数据提取交易存盘时自动生成临时临时参考号
     * @param boprem
     * @return
     */
    public void saveTmpRef(Boprem boprem){
        String rptno = NULLSTR;
        String szflg = boprem.getSzflg();
        String temRef = NULLSTR;
        String transName = boprem.getTransName().toUpperCase();
        if(MdaUtils.compareTo(boprem.getSzflg(),"1") == 0){
            temRef = boprem.getDbbgrp().getBas().getTmpref();
        }
        if(MdaUtils.compareTo(boprem.getSzflg(),"2") == 0){
            temRef = boprem.getDbegrp().getBas().getTmpref();
        }
        if(MdaUtils.isEmpty(temRef)){
            temRef = bopdecCommonService.getBopTmpRef();
            if(MdaUtils.compareTo(boprem.getSzflg(),"1") == 0) {
                boprem.getDbbgrp().getBas().setTmpref(temRef);
                //此处不进行赋值，存盘时管理和申报信息中 tmpref 赋值 基础信息inr
                //boprem.getDbbgrp().getDcl().setTmpref(temRef);
                //boprem.getDbbgrp().getVrf().setTmpref(temRef);
            }
            if(MdaUtils.compareTo(boprem.getSzflg(),"2") == 0){
                boprem.getDbegrp().getBas().setTmpref(temRef);
                //此处不进行赋值，存盘时管理和申报信息中 tmpref 赋值 基础信息inr
                //boprem.getDbegrp().getVrf().setTmpref(temRef);
            }

        }
        if(MdaUtils.compareTo(boprem.getSzflg(),"3") != 0 && MdaUtils.compareTo(boprem.getSzflg(),"") != 0 && (MdaUtils.compareTo(boprem.getCtlmod().getDectyp(),"V") == 0 || MdaUtils.compareTo(boprem.getCtlmod().getDectyp(),"A") == 0)){
            if("1".equals(boprem.getSzflg())){
                rptno = boprem.getDbbgrp().getBas().getRptno();
            }
            if("2".equals(boprem.getSzflg())){
                rptno = boprem.getDbegrp().getBas().getRptno();
            }
            if(MdaUtils.isEmpty(rptno)) {
                RptnoRequestVo rptnoRequestVo = new RptnoRequestVo();
                rptnoRequestVo.setTransname(transName);
                rptnoRequestVo.setSzflg(boprem.getSzflg());
                rptnoRequestVo.setBasflg(boprem.getBasflg());
                rptnoRequestVo.setDclflg(boprem.getDclflg());
                rptnoRequestVo.setVrfflg(boprem.getVrfflg());
                rptnoRequestVo.setBopobjtyp(boprem.getBopobjtyp());
                rptnoRequestVo.setBoptyp(boprem.getBoptyp());
                rptnoRequestVo.setTyp(boprem.getTyp());
                rptnoRequestVo.setOwnextkey(boprem.getOwnextkey());
                String dectyp = ctlmodService.setDectyp(transName);
                if (MdaUtils.isEmpty(boprem.getPaydat())) {
                    if ("V".equals(dectyp)) {
                        rptnoRequestVo.setPaydat(bopdecCommonService.getCoreSysDay());
                    }
                } else {
                    rptnoRequestVo.setPaydat(boprem.getPaydat());
                }
                if("1".equals(szflg)) {
                    rptnoRequestVo.setCustype(boprem.getDbbgrp().getBas().getCustype());
                }
                if("2".equals(szflg)) {
                    rptnoRequestVo.setCustype(boprem.getDbegrp().getBas().getCustype());
                }
                String ref = bopdecCommonService.getRef(rptnoRequestVo);
                boprem.getDbbgrp().getBas().setRptno(ref);
                boprem.getDbegrp().getBas().setRptno(ref);
                if("X".equals(boprem.getDclflg())){
                    boprem.getDbbgrp().getDcl().setRptno(ref);
                }
                if("X".equals(boprem.getVrfflg())){
                    boprem.getDbbgrp().getVrf().setRptno(ref);
                    boprem.getDbbgrp().getVrf().setRptno(ref);
                }
            }
        }

    }
}
