package com.brilliance.isc.common.trnmod.service.impl;

import com.brilliance.mda.runtime.mda.util.Dates;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.isc.bo.*;
import com.brilliance.isc.bo.model.*;
import com.brilliance.isc.common.api.lim.vo.LimRequest;
import com.brilliance.isc.common.cache.adr.AdrCacheService;
import com.brilliance.isc.common.cache.pta.PtaCacheService;
import com.brilliance.isc.common.cbsmod.Cbsget;
import com.brilliance.isc.common.cbsmod.service.CbsmodService;
import com.brilliance.isc.common.cbsmod.service.XrtmodService;
import com.brilliance.isc.common.component.PtsptaToolComponent;
import com.brilliance.isc.common.liaall.service.LiaallService;
import com.brilliance.isc.common.liaall.vo.LiaallVo;
import com.brilliance.isc.common.transaction.help.TransactionServiceSet;
import com.brilliance.isc.common.util.StringUtils;
import com.brilliance.isc.common.util.Utils;
import com.brilliance.isc.common.vo.FremsgVo;
import com.brilliance.isc.common.vo.PtsptaVo;
import com.brilliance.isc.common.vo.SimpleModuleVo;
import com.brilliance.isc.mda.dao.*;
import com.brilliance.isc.vo.domlc.BddBizAmdInfoVo;
import com.brilliance.isc.vo.domlc.BddBizInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class DiToolComponents {
    private static final String DED_DATA_TYPE = "DED";

    private static final String BFD_DATA_TYPE = "BFD";

    private static final String DID_DATA_TYPE = "DID";

    private static final String BDD_DATA_TYPE = "BDD";


    @Autowired
    private DedMapper dedMapper;

    @Autowired
    private DetMapper detMapper;

    @Autowired
    private BfdMapper bfdMapper;

    @Autowired
    private BftMapper bftMapper;

    @Autowired
    private DidMapper didMapper;

    @Autowired
    private DitMapper ditMapper;

    @Autowired
    private BddMapper bddMapper;

    @Autowired
    private BdtMapper bdtMapper;

    @Autowired
    private CbsmodService cbsmodService;

    @Autowired
    private Cbsget cbsget;

    @Autowired
    private PtaCacheService ptaCacheService;

    @Autowired
    private AdrCacheService adrCacheService;

    @Autowired
    private PtsptaToolComponent ptsptaToolComponent;

    @Autowired
    private LiaallService liaallService;

    @Autowired
    private XrtmodService xrtmodService;


    public void collectCbsMap(TransactionServiceSet set, String prefix, Deacbs cbs, String... cbsNames) {
        Map<String, Cbb> cbsMap = set.getCbsMap();
        if (cbsMap == null) {
            cbsMap = new HashMap<>();
        }
        for (String name : cbsNames) {
            Cbb cbb = Utils.getFieldValue(cbs, name);
            if (cbb != null) {
                cbsMap.put(prefix.toUpperCase() + name.toUpperCase(), cbb);
            }
        }
        set.setCbsMap(cbsMap);
    }

    public void collectCbsMap(TransactionServiceSet set, String prefix, Bfacbs cbs, String... cbsNames) {
        Map<String, Cbb> cbsMap = set.getCbsMap();
        if (cbsMap == null) {
            cbsMap = new HashMap<>();
        }
        for (String name : cbsNames) {
            Cbb cbb = Utils.getFieldValue(cbs, name);
            if (cbb != null) {
                cbsMap.put(prefix.toUpperCase() + name.toUpperCase(), cbb);
            }
        }
        set.setCbsMap(cbsMap);
    }

    public void collectPtsList(TransactionServiceSet set, Dedgrp dedgrp, String... ptsNames) {
        if (ptsNames == null) {
            //找所有的ptspta对象
            Field[] fields = dedgrp.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                if (PtsptaVo.class.equals(field.getType())) {
                    PtsptaVo ptspta = Utils.getFieldValue(dedgrp, field.getName());
                    if (ptspta != null) {
                        set.addPtspta(transferFrom(ptspta));
                    }
                }
            }
        } else {
            for (String name : ptsNames) {
                PtsptaVo ptspta = Utils.getFieldValue(dedgrp, name);
                if (ptspta != null && ptspta.getPts() != null && StringUtils.isNotEmpty(ptspta.getPts().getRol())) {
                    set.addPtspta(transferFrom(ptspta));
                }
            }
        }
    }

    public void collectPtsList(TransactionServiceSet set, Bfdgrp bfdgrp, String... ptsNames) {
        if (ptsNames == null) {
            //找所有的ptspta对象
            Field[] fields = bfdgrp.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                if (PtsptaVo.class.equals(field.getType())) {
                    PtsptaVo ptspta = Utils.getFieldValue(bfdgrp, field.getName());
                    if (ptspta != null) {
                        set.addPtspta(transferFrom(ptspta));
                    }
                }
            }
        } else {
            for (String name : ptsNames) {
                PtsptaVo ptspta = Utils.getFieldValue(bfdgrp, name);
                if (ptspta != null) {
                    set.addPtspta(transferFrom(ptspta));
                }
            }
        }
    }


    public void collectPtsList(TransactionServiceSet set, FremsgVo fremsg, String... ptsNames) {
        if (ptsNames == null) {
            //找所有的ptspta对象
            Field[] fields = fremsg.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                if (PtsptaVo.class.equals(field.getType())) {
                    PtsptaVo ptspta = Utils.getFieldValue(fremsg, field.getName());
                    if (ptspta != null) {
                        set.addPtspta(transferFrom(ptspta));
                    }
                }
            }
        } else {
            for (String name : ptsNames) {
                PtsptaVo ptspta = Utils.getFieldValue(fremsg, name);
                if (ptspta != null) {
                    set.addPtspta(transferFrom(ptspta));
                }
            }
        }
    }

    public void collectPtsList(TransactionServiceSet set, FremsgVo fremsg, String[] fremsgPtsNames, Dedgrp dedgrp, String[] gidgrpPtsNames) {
        for (String name : fremsgPtsNames) {
            PtsptaVo ptspta = Utils.getFieldValue(fremsg, name);
            if (ptspta != null) {
                set.addPtspta(transferFrom(ptspta));
            }
        }
        for (String name : gidgrpPtsNames) {
            PtsptaVo ptspta = Utils.getFieldValue(dedgrp, name);
            if (ptspta != null) {
                set.addPtspta(transferFrom(ptspta));
            }
        }
    }

    public void collectPtsaddg(TransactionServiceSet set, List<Ptsaddg> ptsaddg) {
        set.setPtsaddg(ptsaddg);
    }

    /**
     * 根据STL结构的ptspta转化成抽象组件的ptspta，结构不一样
     *
     * @param ptsptas
     * @return List<com.brilliance.common.vo.PtsptaVo>
     */
    public PtsptaVo transferFrom(PtsptaVo ptsptas) {
        PtsptaVo ptspta = ptsptas;
        ptspta.setRol(ptsptas.getPts().getRol());
        ptspta.setPtsinr(ptsptas.getPts().getInr());
        ptspta.setNam(ptsptas.getPts().getNam());
        ptspta.setPtyinr(ptsptas.getPts().getPtyinr());
        ptspta.setPtainr(ptsptas.getPts().getPtainr());
        ptspta.setExtkey(ptsptas.getPts().getExtkey());
        ptspta.setDftdsp(ptsptas.getPts().getDftdsp());
        ptspta.setDftcur(ptsptas.getPts().getDftcur());
        ptspta.setDftact(ptsptas.getPts().getDftact());
        ptspta.setDftfeecur(ptsptas.getPts().getDftfeecur());
        ptspta.setDftactptainr(ptsptas.getPts().getDftactptainr());
        ptspta.setDftselrol(ptsptas.getPts().getDftsetrol());
        ptspta.setGlggrpflg(ptsptas.getPts().getGlggrpflg());
        ptspta.setRef(ptsptas.getPts().getRef());
        ptspta.setPtytyp(ptsptas.getPtytyp());
        ptspta.setPtyextkey(ptsptas.getPtyextkey());
        ptspta.setAdrblk(ptsptas.getPts().getAdrblk());

        if(ptspta.getPta() == null && StringUtils.isNotEmpty(ptspta.getPtainr())){
            ptspta.setPta(ptaCacheService.getPtaByInr(ptspta.getPtainr()));
        }
        if(ptspta.getAdr() == null && StringUtils.isNotEmpty(ptspta.getPtainr())){
            ptspta.setAdr(adrCacheService.selectByPtaInr(ptspta.getPtainr()));
        }
        return ptspta;
    }

    public Dedgrp getDedgrpByInr(String inr) {
        Dedgrp dedgrp = new Dedgrp();
        dedgrp.reset();
        //找DED的数据
        Ded ded = dedgrp.getRec();
        ded.setInr(inr);
        ded = dedMapper.selectByPrimaryKey(ded);
        if (ded != null) {
            dedgrp.setRec(ded);
        }
        //找DET的数据
        Det det = dedgrp.getBlk();
        det.setInr(inr);
        det = detMapper.selectByPrimaryKey(det);
        if (det != null) {
            dedgrp.setBlk(det);
        }
        //找Deacbs数据
        Date date = Dates.add(Utils.getMaxDate(), -1);
        cbsmodService.cbsGetBalance(dedgrp.getCbs().getMax(),DED_DATA_TYPE,inr,"MAXSUM","AMT1",date);
        cbsmodService.cbsGetBalance(dedgrp.getCbs().getNom1(),DED_DATA_TYPE,inr,"NOMSUM","AMT1",date);
        cbsmodService.cbsGetBalance(dedgrp.getCbs().getCnf(),DED_DATA_TYPE,inr,"CNFSUM","AMT1",date);
        cbsmodService.cbsGetBalance(dedgrp.getCbs().getOpn1(),DED_DATA_TYPE,inr,"OPN","AMT1",date);
        cbsmodService.cbsGetBalance(dedgrp.getCbs().getMax2(),DED_DATA_TYPE,inr,"MAXSUM","AMT2",date);
        cbsmodService.cbsGetBalance(dedgrp.getCbs().getOpn2(),DED_DATA_TYPE,inr,"OPN","AMT2",date);
        storePtsToGrp(dedgrp, inr, DED_DATA_TYPE);
        return dedgrp;
    }

    public Bfdgrp getBfdgrpByInr(String inr) {
        Bfdgrp bfdgrp = new Bfdgrp();
        bfdgrp.reset();
        //找BFD的数据
        Bfd bfd = bfdgrp.getRec();
        bfd.setInr(inr);
        bfd = bfdMapper.selectByPrimaryKey(bfd);
        if (bfd != null) {
            bfdgrp.setRec(bfd);
        }
        //找BFT的数据
        Bft bft = bfdgrp.getBlk();
        bft.setInr(inr);
        bft = bftMapper.selectByPrimaryKey(bft);
        if (bft != null) {
            bfdgrp.setBlk(bft);
        }
        //找Deacbs数据
        Date date = Dates.add(Utils.getMaxDate(), -1);
        cbsmodService.cbsGetBalance(bfdgrp.getCbs().getMax(),BFD_DATA_TYPE,inr,"MAXSUM","AMT1",date);
        cbsmodService.cbsGetBalance(bfdgrp.getCbs().getOpn1(),BFD_DATA_TYPE,inr,"OPN","AMT1",date);
        cbsmodService.cbsGetBalance(bfdgrp.getCbs().getMax2(),BFD_DATA_TYPE,inr,"MAXSUM","AMT2",date);
        cbsmodService.cbsGetBalance(bfdgrp.getCbs().getOpn2(),BFD_DATA_TYPE,inr,"OPN","AMT2",date);
        storePtsToGrp(bfdgrp, inr, BFD_DATA_TYPE);
        return bfdgrp;
    }
//    public Gidgrp getGidgrpByInrButBlk(String inr) {
//        Gidgrp gidgrp = new Gidgrp();
//        gidgrp.reset();
//        //找GID的数据
//        Gid gid = gidgrp.getRec();
//        gid.setInr(inr);
//        gid = gidMapper.selectByPrimaryKey(gid);
//        if (gid != null) {
//            gidgrp.setRec(gid);
//        }
//        //找GIT的数据
////        Git git = gidgrp.getBlk();
////        git.setInr(inr);
////        git = gitMapper.selectByPrimaryKey(git);
////        if (git != null) {
////            gidgrp.setBlk(git);
////        }
//        //找giacbs数据
//        Date date = Dates.add(Utils.getMaxDate(), -1);
//
//
//        cbsmodService.cbsGetBalance(gidgrp.getCbs().getMax(), GID_DATA_TYPE, inr, "MAXSUM", "AMT1", date);
//        cbsmodService.cbsGetBalance(gidgrp.getCbs().getOpn1(), GID_DATA_TYPE, inr, "OPN", "AMT1", date);
//        cbsmodService.cbsGetBalance(gidgrp.getCbs().getCnf(), GID_DATA_TYPE, inr, "CNFSUM", "AMT1", date);
//        Map<String, Cbb> cbbMap = new HashMap<>();
//        gidgrp.getCbs().fillToMap(cbbMap);
//        cbsget.getAamCbsPerDate(cbbMap, GID_DATA_TYPE, inr, "GIDGRP\\REC", date);
//        // DO5DOS.011084
//        //DNGDEV.000389
//        cbsmodService.cbsGetBalance(gidgrp.getCbs().getMaxint(), GID_DATA_TYPE, inr, "MAXSUM", "AMTINT", date);
//        cbsmodService.cbsGetBalance(gidgrp.getCbs().getOpnint(), GID_DATA_TYPE, inr, "OPN", "AMTINT", date);
//        // DNGDEV.001449
//        cbsmodService.cbsGetBalance(gidgrp.getCbs().getMac(), GID_DATA_TYPE, inr, "MACSUM", "AMT1", date);
//        cbsmodService.cbsGetBalance(gidgrp.getCbs().getOpc1(), GID_DATA_TYPE, inr, "OPC", "AMT1", date);
//        //找ptspta数据
//        storePtsToGrp(gidgrp, inr, GID_DATA_TYPE);
//
//        return gidgrp;
//    }
//

//    public PtsptaVo getOldGidRolByInr(String gidinr, String rol) {
//        Map<String, PtsptaVo> ptsptaVoMap = ptsptaToolComponent.getPtsptaList(gidinr, GID_DATA_TYPE);
//        return ptsptaVoMap.get(rol);
//    }
//

//    public Gid getOldRecByInr(String gidinr) {
//        Gid gid = new Gid();
//        gid.setInr(gidinr);
//        gid = gidMapper.selectByPrimaryKey(gid);
//        return gid;
//    }
//

//
//    public Giacbs getCbsByInr(String inr) {
//        Giacbs giacbs = new Giacbs();
//        giacbs.reset();
//        Date date = Dates.add(Utils.getMaxDate(), -1);
//        cbsmodService.cbsGetBalance(giacbs.getMax(), GID_DATA_TYPE, inr, "MAXSUM", "AMT1", date);
//        cbsmodService.cbsGetBalance(giacbs.getOpn1(), GID_DATA_TYPE, inr, "OPN", "AMT1", date);
//        cbsmodService.cbsGetBalance(giacbs.getCnf(), GID_DATA_TYPE, inr, "CNFSUM", "AMT1", date);
//        Map<String, Cbb> cbbMap = new HashMap<>();
//        giacbs.fillToMap(cbbMap);
//        cbsget.getAamCbsPerDate(cbbMap, GID_DATA_TYPE, inr, "GIDGRP\\REC", date);
//        // DO5DOS.011084
//        //DNGDEV.000389
//        cbsmodService.cbsGetBalance(giacbs.getMaxint(), GID_DATA_TYPE, inr, "MAXSUM", "AMTINT", date);
//        cbsmodService.cbsGetBalance(giacbs.getOpnint(), GID_DATA_TYPE, inr, "OPN", "AMTINT", date);
//        // DNGDEV.001449
//        cbsmodService.cbsGetBalance(giacbs.getMac(), GID_DATA_TYPE, inr, "MACSUM", "AMT1", date);
//        cbsmodService.cbsGetBalance(giacbs.getOpc1(), GID_DATA_TYPE, inr, "OPC", "AMT1", date);
//        return giacbs;
//    }
//
//    public Giacbs getCbsByInr(String inr, String cbsType) {
//        Giacbs giacbs = new Giacbs();
//        giacbs.reset();
//        Date date = Dates.add(Utils.getMaxDate(), -1);
//        cbsmodService.cbsGetBalance(giacbs.getMax(), cbsType, inr, "MAXSUM", "AMT1", date);
//        cbsmodService.cbsGetBalance(giacbs.getOpn1(), cbsType, inr, "OPN", "AMT1", date);
//        cbsmodService.cbsGetBalance(giacbs.getCnf(), cbsType, inr, "CNFSUM", "AMT1", date);
//        Map<String, Cbb> cbbMap = new HashMap<>();
//        giacbs.fillToMap(cbbMap);
//        cbsget.getAamCbsPerDate(cbbMap, cbsType, inr, "GIDGRP\\REC", date);
//        // DO5DOS.011084
//        //DNGDEV.000389
//        cbsmodService.cbsGetBalance(giacbs.getMaxint(), cbsType, inr, "MAXSUM", "AMTINT", date);
//        cbsmodService.cbsGetBalance(giacbs.getOpnint(), cbsType, inr, "OPN", "AMTINT", date);
//        // DNGDEV.001449
//        cbsmodService.cbsGetBalance(giacbs.getMac(), cbsType, inr, "MACSUM", "AMT1", date);
//        cbsmodService.cbsGetBalance(giacbs.getOpc1(), cbsType, inr, "OPC", "AMT1", date);
//        return giacbs;
//    }
//
    public void storePtsToGrp(Object grpObject, String objInr, String objType) {
        //找ptspta数据
        Map<String, PtsptaVo> maps = ptsptaToolComponent.getPtsptaList(objInr, objType);
        if (maps.size() > 0) {
            maps.keySet().forEach(key -> {
                PtsptaVo ptsptaVo = maps.get(key);
                if (key.equalsIgnoreCase("INT")) {
                    key = "tmpint";
                }
                Utils.setFieldValue(grpObject, key.toLowerCase(), ptsptaVo);
            });
        }
    }
//
//    public RmbbopVo getRmbbopByObj(String ownref){
//        RmbbopVo rmbbopVo = new RmbbopVo();
//        rmbbopVo.reset();
//
//        //2122
//        Tdo tdo = tdoMapper.selectTdoByOwnref(ownref);
//        if (tdo !=null) {
//            BeanUtils.copyProperties(tdo, rmbbopVo.getRmbbop2122Vo().getRecgrp().getAds());
//            String objinr = tdo.getInr();
//            if (!MdaUtils.isEmpty(objinr)){
//                Pbl pbl = pblMapper.selectByObjtypOrderByObjinr("TDO", objinr);
//                if (!MdaUtils.isEmpty(pbl)){
//                    rmbbopVo.getRmbbop2122Vo().setPblsta(pbl.getSta());
//                }
//            }
//
//        }
//
//
//        return rmbbopVo;
//    }



    public void collectCbsMap(TransactionServiceSet set, String prefix, Diacbs cbs, String... cbsNames) {
        Map<String, Cbb> cbsMap = set.getCbsMap();
        if (cbsMap == null) {
            cbsMap = new HashMap<>();
        }
        for (String name : cbsNames) {
            Cbb cbb = Utils.getFieldValue(cbs, name);
            if (cbb != null) {
                cbsMap.put(prefix.toUpperCase() + name.toUpperCase(), cbb);
            }
        }
        set.setCbsMap(cbsMap);
    }
    public void collectCbsMap(TransactionServiceSet set, String prefix, Bdacbs cbs, String... cbsNames) {
        Map<String, Cbb> cbsMap = set.getCbsMap();
        if (cbsMap == null) {
            cbsMap = new HashMap<>();
        }
        for (String name : cbsNames) {
            Cbb cbb = Utils.getFieldValue(cbs, name);
            if (cbb != null) {
                cbsMap.put(prefix.toUpperCase() + name.toUpperCase(), cbb);
            }
        }
        set.setCbsMap(cbsMap);
    }
    public void collectPtsList(TransactionServiceSet set, Didgrp didgrp, String... ptsNames) {
        if (ptsNames == null) {
            //找所有的ptspta对象
            Field[] fields = didgrp.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                if (PtsptaVo.class.equals(field.getType())) {
                    PtsptaVo ptspta = Utils.getFieldValue(didgrp, field.getName());
                    if (ptspta != null) {
                        set.addPtspta(transferFrom(ptspta));
                    }
                }
            }
        } else {
            for (String name : ptsNames) {
                PtsptaVo ptspta = Utils.getFieldValue(didgrp, name);
                if (ptspta != null && ptspta.getPts() != null && StringUtils.isNotEmpty(ptspta.getPts().getRol())) {
                    set.addPtspta(transferFrom(ptspta));
                }
            }
        }
    }
    public void collectPtsList(TransactionServiceSet set, Bddgrp bddgrp, String... ptsNames) {
        if (ptsNames == null) {
            //找所有的ptspta对象
            Field[] fields = bddgrp.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                if (PtsptaVo.class.equals(field.getType())) {
                    PtsptaVo ptspta = Utils.getFieldValue(bddgrp, field.getName());
                    if (ptspta != null) {
                        set.addPtspta(transferFrom(ptspta));
                    }
                }
            }
        } else {
            for (String name : ptsNames) {
                PtsptaVo ptspta = Utils.getFieldValue(bddgrp, name);
                if (ptspta != null && ptspta.getPts() != null && StringUtils.isNotEmpty(ptspta.getPts().getRol())) {
                    set.addPtspta(transferFrom(ptspta));
                }
            }
        }
    }

    public void collectPtsList(TransactionServiceSet set, Bdtp bdtp, String... ptsNames) {
        if (ptsNames == null) {
            //找所有的ptspta对象
            Field[] fields = bdtp.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                if (PtsptaVo.class.equals(field.getType())) {
                    PtsptaVo ptspta = Utils.getFieldValue(bdtp, field.getName());
                    if (ptspta != null) {
                        set.addPtspta(transferFrom(ptspta));
                    }
                }
            }
        } else {
            for (String name : ptsNames) {
                PtsptaVo ptspta = Utils.getFieldValue(bdtp, name);
                if (ptspta != null && ptspta.getPts() != null && StringUtils.isNotEmpty(ptspta.getPts().getRol())) {
                    set.addPtspta(transferFrom(ptspta));
                }
            }
        }
    }

    public Didgrp getDidgrpByInr(String inr) {
        Didgrp didgrp = new Didgrp();
        didgrp.reset();
        //找DID的数据
        Did did = didgrp.getRec();
        did.setInr(inr);
        did = didMapper.selectByPrimaryKey(did);
        if (did != null) {
            didgrp.setRec(did);
        }
        //找DIT的数据
        Dit dit = didgrp.getBlk();
        dit.setInr(inr);
        dit = ditMapper.selectByPrimaryKey(dit);
        if (dit != null) {
            didgrp.setBlk(dit);
        }
        //找giacbs数据
        Date date = Dates.add(Utils.getMaxDate(), -1);


        cbsmodService.cbsGetBalance(didgrp.getCbs().getMax(), DID_DATA_TYPE, inr, "MAXSUM", "AMT1", date);
        cbsmodService.cbsGetBalance(didgrp.getCbs().getNom1(),DID_DATA_TYPE,inr,"NOMSUM","AMT1",date);
        cbsmodService.cbsGetBalance(didgrp.getCbs().getOpn1(), DID_DATA_TYPE, inr, "OPN", "AMT1", date);

        Map<String, Cbb> cbbMap = new HashMap<>();
        didgrp.getCbs().fillToMap(cbbMap);
        cbsget.getAamCbsPerDate(cbbMap, DID_DATA_TYPE, inr, "DIDGRP\\REC", date);
        storePtsToGrp(didgrp, inr, DID_DATA_TYPE);
        return didgrp;
    }

    public Bddgrp getBddgrpByInr(String inr) {
        Bddgrp bddgrp = new Bddgrp();
        bddgrp.reset();
        //找DID的数据
        Bdd bdd = bddgrp.getRec();
        bdd.setInr(inr);
        bdd = bddMapper.selectByPrimaryKey(bdd);
        if (bdd != null) {
            bddgrp.setRec(bdd);
        }
        //找DIT的数据
        Bdt bdt = bddgrp.getBlk();
        bdt.setInr(inr);
        bdt = bdtMapper.selectByPrimaryKey(bdt);
        if (bdt != null) {
            bddgrp.setBlk(bdt);
        }
        //找giacbs数据
        Date date = Dates.add(Utils.getMaxDate(), -1);

        cbsmodService.cbsGetBalance(bddgrp.getCbs().getMax(), BDD_DATA_TYPE, inr, "MAXSUM", "AMT1", date);
        cbsmodService.cbsGetBalance(bddgrp.getCbs().getOpn1(), BDD_DATA_TYPE, inr, "OPN", "AMT1", date);

        Map<String, Cbb> cbbMap = new HashMap<>();
        bddgrp.getCbs().fillToMap(cbbMap);
        cbsget.getAamCbsPerDate(cbbMap, BDD_DATA_TYPE, inr, "BDDGRP\\REC", date);
        storePtsToGrp(bddgrp, inr, BDD_DATA_TYPE);
        return bddgrp;
    }
    //lialed.bookCnfAmt
    public void bookCnfAmt(LiaallVo liaallVo, SimpleModuleVo linkModule, BigDecimal argMaxAmt) {
        Cbb maxCbb = liaallVo.getCbsMap().getOrDefault("MAX", new Cbb());
        liaallService.liaallSetGrpKey( "LE", "INT", "INT" );
        liaallService.liaallSetGrpKey( "LE", "AVL", "AVL" );
        liaallService.liaallSetGrpKey( "LE", "AVS", "AVS" );
        liaallService.liaallSetCbeAmount( "ISS", 3, maxCbb.getCur(), xrtmodService.amtRnd(argMaxAmt, maxCbb.getCur()), "INT", linkModule);
        liaallService.liaallSetDisable( "INT" );
    }

    //国际索赔赔付统一授信
    public void updateBddToDidLimRequest(LimRequest<BddBizInfoVo, BddBizAmdInfoVo> limRequest) {
        String objInr = limRequest.getRec().getPntinr();
        Didgrp didgrp = getDidgrpByInrButBlk(objInr);
        TransactionServiceSet transactionServiceSet = new TransactionServiceSet();
        collectCbsMap(transactionServiceSet,"",didgrp.getCbs(),"max", "nom1", "max2", "opn1", "opn2");
        collectPtsList(transactionServiceSet,didgrp,"apl", "ben", "iss","atb","adv","at2","ada","rmr");
        BddBizInfoVo bddBizInfoVo = buildBddBizInfoVo(didgrp.getRec());
        limRequest.setRec(bddBizInfoVo);
        limRequest.setCbsMap(transactionServiceSet.getCbsMap());
        limRequest.setPtsList(transactionServiceSet.getPtsList());
    }
    public Didgrp getDidgrpByInrButBlk(String inr) {
        Didgrp didgrp = new Didgrp();
        didgrp.reset();
        //找DID的数据
        Did did = didgrp.getRec();
        did.setInr(inr);
        did = didMapper.selectByPrimaryKey(did);
        if (did != null) {
            didgrp.setRec(did);
        }
        //找DIT的数据
//        Dit dit = didgrp.getBlk();
//        dit.setInr(inr);
//        dit = ditMapper.selectByPrimaryKey(dit);
//        if (dit != null) {
//            didgrp.setBlk(dit);
//        }
        //找giacbs数据
        Date date = Dates.add(Utils.getMaxDate(), -1);
        cbsmodService.cbsGetBalance(didgrp.getCbs().getMax(), DID_DATA_TYPE, inr, "MAXSUM", "AMT1", date);
        cbsmodService.cbsGetBalance(didgrp.getCbs().getNom1(),DID_DATA_TYPE,inr,"NOMSUM","AMT1",date);
        cbsmodService.cbsGetBalance(didgrp.getCbs().getOpn1(), DID_DATA_TYPE, inr, "OPN", "AMT1", date);

        Map<String, Cbb> cbbMap = new HashMap<>();
        didgrp.getCbs().fillToMap(cbbMap);
        cbsget.getAamCbsPerDate(cbbMap, DID_DATA_TYPE, inr, "DIDGRP\\REC", date);
        storePtsToGrp(didgrp, inr, DID_DATA_TYPE);
        return didgrp;
    }
    public BddBizInfoVo buildBddBizInfoVo(Did did) {
        BddBizInfoVo rec = new BddBizInfoVo();
        rec.setObjinr(did.getInr());
        rec.setObjtyp("DID");
        rec.setNam(did.getNam());
        rec.setOwnref(did.getOwnref());
        rec.setBranchInr(did.getBranchinr());
        rec.setOpndat(did.getOpndat());
        rec.setExpdat(did.getExpdat());
        return rec;
    }

    public PtsptaVo deepClonePtspta(PtsptaVo argPtsptaVo, String srcRole) {
        PtsptaVo ptsptaVo = MdaUtils.deepClone(argPtsptaVo);
        ptsptaVo.setRol(srcRole.toUpperCase());
        if (ptsptaVo.getPts() != null) {
            ptsptaVo.getPts().setRol(srcRole.toUpperCase());
        }
        return ptsptaVo;
    }


}
