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

import cn.hutool.core.lang.Assert;
import com.brilliance.mda.runtime.mda.CodetableItem;
import com.brilliance.mda.runtime.mda.IStream;
import com.brilliance.mda.runtime.mda.impl.Argument;
import com.brilliance.mda.runtime.mda.impl.StreamImpl;
import com.brilliance.mda.runtime.mda.util.*;
import com.brilliance.isc.bo.*;
import com.brilliance.isc.common.cache.adr.AdrCacheService;
import com.brilliance.isc.common.cache.pta.PtaCacheService;
import com.brilliance.isc.common.cache.pty.PtyCacheService;
import com.brilliance.isc.common.cbsmod.service.XrtmodService;
import com.brilliance.isc.common.codetable.service.CodetableService;
import com.brilliance.isc.common.component.ActmodComponent;
import com.brilliance.isc.common.component.DyncDaoService;
import com.brilliance.isc.common.component.PtsptaToolComponent;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.converter.DtoMapper;
import com.brilliance.isc.common.esb.account.IAccountFeign;
import com.brilliance.isc.common.exception.CommonServiceException;
import com.brilliance.isc.common.glemod.service.GlemodService;
import com.brilliance.isc.common.sespay.service.SespayService;
import com.brilliance.isc.common.setfeg.fee.Setpty;
import com.brilliance.isc.common.setfeg.service.SetfegService;
import com.brilliance.isc.common.setfeg.vo.SetfelVo;
import com.brilliance.isc.common.setfog.vo.SetfolVo;
import com.brilliance.isc.common.setglg.service.SetglgService;
import com.brilliance.isc.common.setgll.service.SetgllService;
import com.brilliance.isc.common.setgll.vo.SetgllVo;
import com.brilliance.isc.common.setmod.service.SetmodService;
import com.brilliance.isc.common.setmod.vo.PtsFeeDetailVo;
import com.brilliance.isc.common.setmod.vo.SetmodVo;
import com.brilliance.isc.common.transaction.help.TransactionHelpService;
import com.brilliance.isc.common.trndoc.service.DoceotService;
import com.brilliance.isc.common.trnmod.service.TrnmodService;
import com.brilliance.isc.common.util.StringUtils;
import com.brilliance.isc.common.util.Utils;
import com.brilliance.isc.common.vo.ActVo;
import com.brilliance.isc.common.vo.BizInfoVo;
import com.brilliance.isc.common.vo.PtsptaVo;
import com.brilliance.isc.esb.model.inner.InnerReq;
import com.brilliance.isc.esb.model.inner.InnerReq8091;
import com.brilliance.isc.esb.model.inner.InnerRes;
import com.brilliance.isc.esb.model.inner.InnerRes8091;
import com.brilliance.isc.mda.dao.ActMapper;
import com.brilliance.isc.mda.dao.PtyratMapper;
import com.brilliance.isc.vo.FxpmodVo;
import com.brilliance.isc.vo.remit.CpdBizInfoVo;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;

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

@Service
public class SetgllServiceImpl implements SetgllService {

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

    @Autowired
    private SetmodService setmodService;

    @Autowired
    private SetfegService setfegService;

    @Autowired
    private GlemodService glemodService;

    @Autowired
    private XrtmodService xrtmodService;

    @Autowired
    private SetglgService setglgService;

    @Autowired
    private CodetableService codetableService;

    @Autowired
    private TransactionHelpService transactionHelpService;

    @Autowired(required = false)
    private IAccountFeign accountFeign;

    @Autowired
    private PtaCacheService ptaCacheService;

    @Autowired
    private PtyCacheService ptyCacheService;

    @Autowired
    private PtyratMapper ptyratMapper;

    @Autowired
    private AdrCacheService adrCacheService;

    @Autowired
    private ActMapper actMapper;

    @Autowired
    private PtsptaToolComponent ptsptaToolComponent;

    @Autowired
    private DoceotService doceotService;

    @Autowired
    private SespayService sespayService;

    @Autowired
    private TrnmodService trnmodService;

    @Autowired
    private ActmodComponent actmodComponent;

    @Autowired
    private DyncDaoService dyncDaoService;

    @Override
    public String calcMac(SetgllVo setgll, SetmodVo setmod) {
        // mac berechnen aus: ROL ACCCUR ACT VALDAT DEBCDTFLG CUR FMTAMT AMT ROLPTAINR RAT
        IStream stm = new StreamImpl();
        int gridcnt = 0;
        String mac = "";
        if (MdaUtils.isEmpty(setgll.getAmt()) && MdaUtils.isEmpty(setgll.getRol())) {
            //不做操作
        } else {
            // Start with installation specific portion
            Streams.streamSet(stm, getSetGllIsfMac(setgll));
            Streams.streamInsert(stm, 0, setgll.getRol() + setgll.getAcccur() + setgll.getAct()
                    + Utils.fmtDate(setgll.getValdat()) + Utils.fmtDate(setgll.getValdattrn())
                    + setgll.getDebcdtflg() + setgll.getCur()
                    + StringUtils.toString(Numerics.round(setgll.getFmtamt(), 2)) + StringUtils.toString(Numerics.round(setgll.getAmt(), 2))
                    + StringUtils.toString(Numerics.round(setgll.getAccamt(), 2)) + StringUtils.toString(Numerics.round(setgll.getAcccpramt(), 2))
                    + setgll.getSftmt() + setgll.getDirindflg());
            Streams.streamInsert(stm, 0, setgll.getRolptainr() + StringUtils.toString(Numerics.round(setgll.getRat(), 6))
                    + setgll.getDsp() + setgll.getActpriflg() + setgll.getPaoflg()
                    + setgll.getRattyp() + setgll.getDcbrattyp() + setgll.getScbrattyp()
                    + StringUtils.toString(Numerics.round(setgll.getDcbextrat(), 6)) + StringUtils.toString(Numerics.round(setgll.getScbextrat(), 6)));
            if (setgll.getActrec() == null) {
                Streams.streamInsert(stm, 0, setgll.getModflg());
            } else {
                Streams.streamInsert(stm, 0, setgll.getModflg() + setgll.getActrec().getSerptyinr() + setgll.getActrec().getHolptyinr() + setgll.getActrec().getTyp());
            }
            Streams.streamInsert(stm, 0, setgll.getSetgrp().getTmpint().getPansta() + setgll.getSetgrp().getRol().getPtytyp() + setgll.getDspflg() + setgll.getFchchkflg() + setgll.getAccamtfix() + setgll.getSetgrp().getTmpint().getAdrblk() + setgll.getSetgrp().getAct().getExtkey());
            Streams.streamInsert(stm, 0, setmod.getRoldsc());
            List<PtsFeeDetailVo> ptydets = setmod.getPtydet();
            if (ptydets != null) {
                gridcnt = ptydets.size();
            }
            for (int i = 0; i < gridcnt; i++) {
                Assert.notNull(ptydets);
                PtsFeeDetailVo ptsFeeDetail = ptydets.get(i);
                if (setgll.getRol().equals(ptsFeeDetail.getRol())) {
                    Streams.streamInsert(stm, 0, ptsFeeDetail.getPtyinr());
                    Streams.streamInsert(stm, 0, ptsFeeDetail.getDftcur());
                    Streams.streamInsert(stm, 0, ptsFeeDetail.getDftdsp());
                    Streams.streamInsert(stm, 0, ptsFeeDetail.getDftact());
                    Streams.streamInsert(stm, 0, ptsFeeDetail.getDftfeecur());
                    Streams.streamInsert(stm, 0, ptsFeeDetail.getGlggrpflg());
                }
            }
            //报文渠道修改了 也会重算setgll
            String swttyp = setmod.getRec().getSwftyp();
            Streams.streamInsert(stm, 0, swttyp);
            mac = Systems.macGen(stm, 0);
        }
        setgll.setMac(mac);
        return mac;
    }

    /**
     * source:setgll.0052.script
     */
    public String getSetGllIsfMac(SetgllVo setgll) {
        //! Function to return MAC portion for ISF-fields
        //! (usually the fields used in RecalcSetGllIsfDft if not already in Default MAC)
        String res = setgll.getSftmt() + setgll.getDirindflg()
                + setgll.getSetgrp().getBei().getExtkey()
                + setgll.getSetgrp().getActser().getExtkey();
        return res;
    }

    public void recalcSetgll(SetgllVo setgll, SetmodVo setmod) {
        // Reset depending fields on changes
        internalResetDependingFields(setgll, setmod);
        // Default fields standard
        recalcSetgllStdDft(setgll, setmod);
        // Do installation specific defaulting
        recalcSetgllIsfDft(setgll, setmod);
        //给交易主体和结售汇类型赋值
        calcTrdinoutAndTrnman(setgll, setmod);
        //传票摘要
        getTxt(setgll, setmod);
        getTxt1(setgll, setmod);
        getTxt2(setgll);
        defaultTypN1000(setgll, setmod.getRec());
        //east7759
        defaultZimaoqu(setgll, setmod);
        defaultEasTto7759(setgll, setmod);
        //根据账号调用核心8091接口获取核心业务代码和账户余额
        //recalcSetgllCoreAcctInfo(setgll);
        setgll.setCprmac(this.generateCprMac(setgll));
        String mac = calcMac(setgll, setmod);
        setgll.setMac(mac);
        setgll.setMacold(mac);
    }

    /**
     * source:setgll.0006.script
     */
    public void internalResetDependingFields(SetgllVo setgll, SetmodVo setmod) {
        //! Reset depending fileds if fields are changed
        //  Created form old event rules
        if (MdaUtils.compareTo(setgll.getOldactpriflg(), setgll.getActpriflg()) != 0 && setgll.isModified("actpriflg")) {
            setgll.setOldactpriflg(setgll.getActpriflg());
            if (!setglgService.getFixDspflagSet().contains(setgll.getDspflg())) {
                setgll.setAct(NULLSTR);
                setgll.resetModified("act");
            }
            defdsp(setgll, setmod);
            defActSub(setgll, setmod);
        }
        boolean redo = false;
        if (MdaUtils.compareTo(setgll.getOldactinr(), setgll.getSetgrp().getAct().getPtainr()) != 0) {
            redo = true;
            if (MdaUtils.isEmpty(setgll.getOldactinr()) && (!MdaUtils.isEmpty(setgll.getGlpinr()))) {
                redo = false;
            }
            setgll.setOldactinr(setgll.getSetgrp().getAct().getPtainr());
            if (redo) {
                //Modules.invokeExpress(this,MdaDriver.getModuleInfo(this,tdModuleInfoFullName) + ".checkACTBic",0);
                if (!setglgService.getFixDspflagSet().contains(setgll.getDspflg())) {
                    setgll.setAct(NULLSTR);
                    setgll.resetModified("act");
                }
                setgll.setActflg(NULLSTR);
                setgll.setScbrattyp(NULLSTR);
                setgll.setDcbrattyp(NULLSTR);
                setgll.setRattyp(" ");
                setgll.setExtsetflg(NULLSTR);
                setgll.setActptyflg("X");
                //setcurandval();
                defdsp(setgll, setmod);
                defActSub(setgll, setmod);
            }
        }
        if (MdaUtils.compareTo(setgll.getRolptyinr(), setgll.getOldrolptyinr()) != 0 || MdaUtils.compareTo(setgll.getDsp(), setgll.getOlddsp()) != 0 || MdaUtils.compareTo(setgll.getAcccur(), setgll.getAcccurold()) != 0) {
            setgll.setOldrolptyinr(setgll.getRolptyinr());
            setgll.setOlddsp(setgll.getDsp());
            setgll.setAcccurold(setgll.getAcccur());
            setgll.setActflg(NULLSTR);
            if (!setglgService.getFixDspflagSet().contains(setgll.getDspflg())) {
                setgll.setAct(NULLSTR);
                setgll.resetModified("act");
            }
            setgll.setScbrattyp(NULLSTR);
            setgll.setDcbrattyp(NULLSTR);
            setgll.setRattyp(" ");
            setgll.setExtsetflg(NULLSTR);
            //MdaUtils.clear(this.getActp());
            PtsptaVo ptsptaVo = new PtsptaVo();
            setgll.getSetgrp().setAct(ptsptaVo);
            //setcurandval();
            defdsp(setgll, setmod);
            defActSub(setgll, setmod);
        }
        if (MdaUtils.compareTo(setgll.getAct(), setgll.getOldact()) != 0) {
            setgll.setOldact(setgll.getAct());
            //Systems.resetModified(this,"paoflg");
        }
        if (MdaUtils.compareTo(setgll.getOlddcbextrat(), setgll.getDcbextrat()) != 0 && MdaUtils.compareTo(setgll.getDcbrattyp(), "F") == 0) {
            setgll.setOlddcbextrat(setgll.getDcbextrat());
            if (MdaUtils.compareTo(setgll.getDcbextrat(), 0) == 0) {
                setgll.setDcbrattyp(NULLSTR);
                //---ZMQZMQ-----
                //--zmqtest----
                if (MdaUtils.compareTo(this.getzmqflg(), "X") == 0) {
                    clcrat_ZMQ(setgll);
                } else {
                    clcrat(setgll);
                }
            } else {
                setgll.setAccamt(xrtmodService.amtViaSysCnv(setgll.getAmt(), setgll.getDcbextrat(), setgll.getScbextrat(), setgll.getCur(), setgll.getAcccur()));
                setgll.setDcbrattyp("F");
            }
        }
        if (MdaUtils.compareTo(setgll.getOldscbextrat(), setgll.getScbextrat()) != 0 && MdaUtils.compareTo(setgll.getScbrattyp(), "F") == 0) {
            setgll.setOldscbextrat(setgll.getScbextrat());
            if (MdaUtils.compareTo(setgll.getScbextrat(), 0) == 0) {
                setgll.setScbrattyp(NULLSTR);
                /**
                 //---ZMQZMQ-----
                 if getzmqflg == "X" then
                 clcrat_ZMQ
                 else
                 **/
                clcrat(setgll);
                //   endif
            } else {
                setgll.setAccamt(xrtmodService.amtViaSysCnv(setgll.getAmt(), setgll.getDcbextrat(), setgll.getScbextrat(), setgll.getCur(), setgll.getAcccur()));
                setgll.setScbrattyp("F");
            }
        }

    }

    /**
     * source:setgll.0012.script
     */
    public void clcrat(SetgllVo setgll) {
        //! calulation of rates and rate types
        boolean restarted = false;
        boolean valuesSet = false;
        // ####### 改写 LABEL与GOTO   ####    label restart
        while(true){
            // use valdat as rate date. If valdat not available use Today
            Date vald = Dates.today();
            clcratSetTypes(setgll);
            boolean ininflg = false;
            // no conversion if currencies are the same
            String sysCur = NULLSTR;
            String newcur = NULLSTR;
            String newacccur = NULLSTR;
            String cur1 = NULLSTR;
            String cur2 = NULLSTR;
            Date curdat = null;
            BigDecimal cur1dif = null;
            BigDecimal cur2dif = null;
            Date accdat = null;
            if(MdaUtils.compareTo(setgll.getAcccur(), setgll.getCur()) == 0) {
                setgll.setDisable("dcbextrat");
                setgll.setDisable("dcbsqrrat");
                setgll.setDisable("dcbrattyp");
                setgll.setDisable("scbextrat");
                setgll.setDisable("scbsqrrat");
                setgll.setDisable("scbrattyp");
                setgll.setDisable("rat");
                setgll.setRat( new BigDecimal("1"));
                setgll.setDcbextrat( new BigDecimal("1"));
                setgll.setDcbsqrrat( new BigDecimal("1"));
                setgll.setScbextrat( new BigDecimal("1"));
                setgll.setScbsqrrat( new BigDecimal("1"));
                setgll.setDcbresrat( new BigDecimal("1"));
                setgll.setDcbrebrat( new BigDecimal("1"));
                setgll.setScbresrat( new BigDecimal("1"));
                setgll.setScbrebrat( new BigDecimal("1"));
                setgll.setRatcurlab(NULLSTR);
                setgll.setDcbratlab(NULLSTR);
                setgll.setScbratlab(NULLSTR);
                setgll.setDisable("rattyp");
                setgll.setRattyp(" ");
                setgll.setXrtdatacc(null);
                setgll.setXrtdatcur(null);
                Set<String> ratTypFilter = new HashSet<>();
                ratTypFilter.add(" ");
                setgll.setRatTypFilter(ratTypFilter);
                valuesSet = true;
            } else {
                //取牌价时间、卖价、买价和中间价
                Argument<String> pathBox = new Argument<String>("",setgll.getXrttim());
                Argument<BigDecimal> pathBox1 = new Argument<BigDecimal>("",setgll.getBuyrat());
                Argument<BigDecimal> pathBox2 = new Argument<BigDecimal>("",setgll.getSelrat());
                Argument<BigDecimal> pathBox3 = new Argument<BigDecimal>("",setgll.getMidrat());
                xrtmodService.getratCebTim(setgll.getCur(), setgll.getAcccur(), Dates.today(), pathBox, pathBox1, pathBox2, pathBox3 );

                setgll.setXrttim( pathBox.value);
                setgll.setBuyrat( pathBox1.value);
                setgll.setSelrat( pathBox2.value);
                setgll.setMidrat( pathBox3.value);

                //取出汇率优惠值
                //----------获取ptyrat对应客户对应币种的优惠方式和优惠点数------
                Pty pty = ptyCacheService.getPtyById(setgll.getRolptyinr());
                sysCur = xrtmodService.sysiso();
                Ptyrat ptyrat = null;
                if (MdaUtils.compareTo(setgll.getCur(), sysCur) == 0 && MdaUtils.compareTo(setgll.getAcccur(), sysCur) != 0) {
                    ptyrat = ptyratMapper.getPtyratByPtyinrAndCur(pty.getInr(), setgll.getAcccur());
                } else {
                    if (MdaUtils.compareTo(setgll.getAcccur(), sysCur) == 0 && MdaUtils.compareTo(setgll.getCur(), sysCur) != 0) {
                        ptyrat = ptyratMapper.getPtyratByPtyinrAndCur(pty.getInr(), setgll.getCur());
                    }
                }
                if (ptyrat != null) {
                    setgll.setPrebuyrat(ptyrat.getBuyrat());
                    setgll.setPreselrat(ptyrat.getSelrat());
                    setgll.setBuyrattyp(StringUtils.isEmpty(ptyrat.getBuytyp())?" ":ptyrat.getBuytyp());
                    setgll.setSelrattyp(StringUtils.isEmpty(ptyrat.getSeltyp())?" ":ptyrat.getSeltyp());
                }
                /**
                 PREBUYRAT = \\TRNMOD\\PTSMOD\\PTY\\BUYRAT
                 PRESELRAT = \\TRNMOD\\PTSMOD\\PTY\\SELRAT
                 BUYRATTYP = \\TRNMOD\\PTSMOD\\PTY\\BUYTYP
                 SELRATTYP = \\TRNMOD\\PTSMOD\\PTY\\SELTYP
                 **/
                // set currencies involved in conversion (incl. IN/IN specials)
                ininflg = false;
                Argument<String> newcurBox = new Argument<String>();
                Argument<String> newacccurBox = new Argument<String>();
                Argument<String> pathBox4 = new Argument<String>("",setgll.getBascur());
                Argument<Boolean> ininflgBox = new Argument<Boolean>("",ininflg);
                xrtmodService.xrtCheckInIn(setgll.getCur(), setgll.getAcccur(), newcurBox, newacccurBox, pathBox4, ininflgBox );

                newcur = newcurBox.value;
                newacccur = newacccurBox.value;
                setgll.setBascur(pathBox4.value);
                ininflg = ininflgBox.value;

                if( MdaUtils.isEmpty(newcur) || ininflg ) {
                    cur1 = setgll.getCur();
                } else {
                    cur1 = newcur;
                }
                if( MdaUtils.isEmpty(newacccur) || ininflg ) {
                    cur2 = setgll.getAcccur();
                } else {
                    cur2 = newacccur;
                }
                setgll.setRatcurlab( cur1 + "/" + cur2);
                setgll.setDcbratlab( cur1 + "/" + setgll.getBascur());
                setgll.setScbratlab( setgll.getBascur() + "/" + cur2);
                // if in/in or forward contract disable everything
                if( ininflg || ( ! MdaUtils.isEmpty(setgll.getFcdinr()) ) ) {
                    setgll.setDisable("dcbextrat");
                    setgll.setDisable("dcbsqrrat");
                    setgll.setDisable("dcbrattyp");
                    setgll.setDisable("scbextrat");
                    setgll.setDisable("scbsqrrat");
                    setgll.setDisable("scbrattyp");
                    setgll.setDisable("rat");
                    setgll.setDisable("rattyp");
                    // for forward contract set forward contract rate type
                    if(!MdaUtils.isEmpty(setgll.getFcdinr()) ) {
                        setgll.setRattyp( "C");
                        Set<String> ratTypFilter = new HashSet<>();
                        ratTypFilter.add("C");
                        setgll.setRatTypFilter(ratTypFilter);
                        valuesSet = true;
                        setgll.setDcbrattyp( "R");
                        setgll.setScbrattyp( "R");
                        // SCBEXTRAT & DCBEXTRAT are already set via SetglgAddAmtFldExtRat
                    } else {
                        Set<String> ratTypFilter = new HashSet<>();
                        ratTypFilter.add(" ");
                        setgll.setRatTypFilter(ratTypFilter);
                        valuesSet = true;
                    }
                } else {
                    // otherwise allow change of ratetype
                    setgll.setDisable("dcbextrat");
                    setgll.setDisable("dcbsqrrat");
                    setgll.setDisable("dcbrattyp");
                    setgll.setDisable("scbextrat");
                    setgll.setDisable("scbsqrrat");
                    setgll.setDisable("scbrattyp");
                    setgll.resetDisable("rattyp");
                    //如果是结售汇需要置灰rattyp
                    if ("J".equals(setgll.getDspflg())) {
                        setgll.setDisable("rattyp");
                    }
                    Cur cur = new Cur();
                    Xrt xrt = new Xrt();
                    // get currency with bigger margin (only in crosrate calculations i.e. both currencies are not base currency)
                    xrtmodService.getXrt(cur1, vald, cur, xrt);
                    // show begin-date of exchange rate of CUR
                    curdat = xrt.getBegdat();
                    setgll.setXrtdatcur(curdat);
                    // avoid dump if rate is not available (no difference for BASCUR)
                    if (MdaUtils.compareTo(cur1, setgll.getBascur()) == 0) {
                        cur1dif = new BigDecimal("0");
                    } else {
                        if (MdaUtils.compareTo(xrt.getBuyrat(), 0) != 0 && MdaUtils.compareTo(xrt.getSelrat(), 0) != 0) {
                            cur1dif = Decimals.div(xrt.getSelrat(), xrt.getBuyrat());
                        } else {
                            cur1dif = new BigDecimal("0");
                            /*ctx.setFieldError(this,"rat",MdaUtils.getI18NString("setgll","CT000118"),cur1);*/
                            throw new CommonServiceException("No exchange rate found for " + cur1 + ", please enter exchange rate first!");
                        }
                    }
                    xrtmodService.getXrt(cur2, vald, cur, xrt);
                    // avoid dump if rate is not available (no difference for BASCUR)
                    if (MdaUtils.compareTo(cur2, setgll.getBascur()) == 0) {
                        cur2dif = new BigDecimal("0");
                    } else {
                        if (MdaUtils.compareTo(xrt.getBuyrat(), 0) != 0 && MdaUtils.compareTo(xrt.getSelrat(), 0) != 0) {
                            cur2dif = Decimals.div(xrt.getSelrat(), xrt.getBuyrat());
                        } else {
                            cur2dif = new BigDecimal("0");
                            /*ctx.setFieldError(this,"rat",MdaUtils.getI18NString("setgll","CT000120"),cur2);*/
                            throw new CommonServiceException("No exchange rate found for " + cur2 + ", please enter exchange rate first!");
                        }
                    }
                    // show begin-date of exchange rate of ACCCUR
                    accdat = xrt.getBegdat();
                    setgll.setXrtdatacc(accdat);
                    // set middle rate for curreny with smaller margin, selling/buying for the other
                    if( ( MdaUtils.compareTo(cur2,setgll.getBascur()) != 0 && MdaUtils.compareTo(cur1dif,cur2dif)>0 )
                            || MdaUtils.compareTo(cur1,setgll.getBascur()) == 0 ) {
                        if( MdaUtils.compareTo(setgll.getDcbrattyp(),"F") != 0 && Strings.len(setgll.getRattyp()) != 1 ) {
                            setgll.setDcbrattyp( "M");
                        }
                        if( Strings.len(setgll.getRattyp().trim()) == 1 ) {
                            setgll.resetDisable("scbrattyp");
                        }
                    } else {
                        if( MdaUtils.compareTo(setgll.getScbrattyp(),"F") != 0
                                && Strings.len(setgll.getRattyp()) != 1 ) {
                            setgll.setScbrattyp( "M");
                        }
                        if( Strings.len(setgll.getRattyp().trim()) == 1 ) {
                            setgll.resetDisable("dcbrattyp");
                        }
                    }
                }
                // rate calulation:
                switch(setgll.getRattyp()) {
                    // for crossrates, the crossrate can be entered and the rate not beeing the middle rate is calculated from crossrate ane middle rate
                    case "RX":
                    case  "FX":
                        setgll.resetDisable("rat");
                        if( MdaUtils.compareTo(setgll.getDcbrattyp(),"M") == 0 ) {
                            if( MdaUtils.compareTo(cur1,setgll.getBascur()) == 0 || MdaUtils.compareTo(cur2,setgll.getBascur()) == 0 ) {
                                setgll.setScbextrat(setgll.getRat());
                            } else {
                                if(xrtmodService.xrtCrossRateDirFlg( cur1, cur2, setgll.getDcbextrat(), setgll.getScbextrat() ) ) {
                                    if( MdaUtils.compareTo(setgll.getRat(),0) == 0 ) {
                                        setgll.setScbextrat(new BigDecimal("0"));
                                    } else {
                                        setgll.setScbextrat(Decimals.mul(Decimals.div(setgll.getDcbextrat(),setgll.getRat()),xrtmodService.crossRatebas( cur1, cur2 )));
                                    }
                                } else {
                                    setgll.setScbextrat(Decimals.mul(Decimals.mul(setgll.getDcbextrat(),setgll.getRat()),xrtmodService.crossRatebas( cur1, cur2 )));
                                }
                            }
                            Argument<BigDecimal> pathBox5 = new Argument<BigDecimal>("",setgll.getDcbextrat());
                            Argument<BigDecimal> pathBox6 = new Argument<BigDecimal>("",setgll.getDcbsqrrat());
                            Argument<BigDecimal> pathBox7 = new Argument<BigDecimal>("",setgll.getDcbresrat());
                            Argument<BigDecimal> pathBox8 = new Argument<BigDecimal>("",setgll.getDcbrebrat());
                            setglgService.getRateXrtWithResRatesZZZ(ptyrat, setgll.getCur(), setgll.getBascur(), ininflg, setgll.getDcbrattyp(), vald, pathBox5, pathBox6, pathBox7, pathBox8 );

                            setgll.setDcbextrat( pathBox5.value);
                            setgll.setDcbsqrrat( pathBox6.value);
                            setgll.setDcbresrat( pathBox7.value);
                            setgll.setDcbrebrat( pathBox8.value);

                        } else {
                            if( MdaUtils.compareTo(cur1,setgll.getBascur()) == 0 || MdaUtils.compareTo(cur2,setgll.getBascur()) == 0 ) {
                                setgll.setDcbextrat(setgll.getRat());
                            } else {
                                if( xrtmodService.xrtCrossRateDirFlg( cur1, cur2, setgll.getDcbextrat(), setgll.getScbextrat() ) ) {
                                    setgll.setDcbextrat( Decimals.mul(Decimals.mul(setgll.getRat(),setgll.getScbextrat()),xrtmodService.crossRatebas( cur2, cur1 )));
                                } else {
                                    if( MdaUtils.compareTo(setgll.getRat(),0) == 0 ) {
                                        setgll.setDcbextrat( new BigDecimal("0"));
                                    } else {
                                        setgll.setDcbextrat( Decimals.mul(Decimals.div(setgll.getScbextrat(),setgll.getRat()),xrtmodService.crossRatebas( cur2, cur1 )));
                                    }
                                }
                            }
                            Argument<BigDecimal> pathBox9 = new Argument<BigDecimal>("",setgll.getScbextrat());
                            Argument<BigDecimal> pathBox10 = new Argument<BigDecimal>("",setgll.getScbsqrrat());
                            Argument<BigDecimal> pathBox11 = new Argument<BigDecimal>("",setgll.getScbresrat());
                            Argument<BigDecimal> pathBox12 = new Argument<BigDecimal>("",setgll.getScbrebrat());
                            setglgService.getRateXrtWithResRatesZZZ(ptyrat, setgll.getAcccur(), setgll.getBascur(), ininflg, setgll.getScbrattyp(), vald, pathBox9, pathBox10, pathBox11, pathBox12 );

                            setgll.setScbextrat( pathBox9.value);
                            setgll.setScbsqrrat( pathBox10.value);
                            setgll.setScbresrat( pathBox11.value);
                            setgll.setScbrebrat( pathBox12.value);
                        }
                        break;
                    default:
                        // in other cases the crossrate is disabled
                        setgll.setDisable("rat");
                        // the rates are read (according to rate type if not free)
                        switch( setgll.getDcbrattyp() ) {
                            case "F":
                                // clear begin-date of exchange-rate, if crossrate can be entered
                                setgll.setXrtdatcur(null);
                                break;
                            case "C":
                            case  "R":
                                break;
                            default:
                                Argument<BigDecimal> pathBox13 = new Argument<BigDecimal>("",setgll.getDcbextrat());
                                Argument<BigDecimal> pathBox14 = new Argument<BigDecimal>("",setgll.getDcbsqrrat());
                                Argument<BigDecimal> pathBox15 = new Argument<BigDecimal>("",setgll.getDcbresrat());
                                Argument<BigDecimal> pathBox16 = new Argument<BigDecimal>("",setgll.getDcbrebrat());
                                setglgService.getRateXrtWithResRatesZZZ(ptyrat, setgll.getCur(), setgll.getBascur(), ininflg, setgll.getDcbrattyp(), vald, pathBox13, pathBox14, pathBox15, pathBox16 );

                                setgll.setDcbextrat( pathBox13.value);
                                setgll.setDcbsqrrat( pathBox14.value);
                                setgll.setDcbresrat( pathBox15.value);
                                setgll.setDcbrebrat( pathBox16.value);
                        }
                        switch( setgll.getScbrattyp() ) {
                            case "F":
                                // clear begin-date of exchange-rate, if crossrate can be entered
                                setgll.setXrtdatacc(null);
                                break;
                            case "C":
                            case  "R":
                                break;
                            default:
                                Argument<BigDecimal> pathBox17 = new Argument<BigDecimal>("",setgll.getScbextrat());
                                Argument<BigDecimal> pathBox18 = new Argument<BigDecimal>("",setgll.getScbsqrrat());
                                Argument<BigDecimal> pathBox19 = new Argument<BigDecimal>("",setgll.getScbresrat());
                                Argument<BigDecimal> pathBox20 = new Argument<BigDecimal>("",setgll.getScbrebrat());
                                setglgService.getRateXrtWithResRatesZZZ(ptyrat, setgll.getAcccur(), setgll.getBascur(), ininflg, setgll.getScbrattyp(), vald, pathBox17, pathBox18, pathBox19, pathBox20 );

                                setgll.setScbextrat( pathBox17.value);
                                setgll.setScbsqrrat( pathBox18.value);
                                setgll.setScbresrat( pathBox19.value);
                                setgll.setScbrebrat( pathBox20.value);
                        }
                        // and the crossrate (RAT) is calculated. ( the logic has to match with the setting of the direction in CnvAmtAccamt)
                        if( MdaUtils.compareTo(setgll.getCur(),setgll.getBascur()) == 0 ) {
                            setgll.setRat( setgll.getScbextrat());
                            // clear begin-date of exchange rate, if exchange = 1
                            setgll.setXrtdatcur(null);
                        } else {
                            if( MdaUtils.compareTo(setgll.getAcccur(),setgll.getBascur()) == 0 ) {
                                setgll.setRat(setgll.getDcbextrat());
                            } else {
                                if( MdaUtils.compareTo(setgll.getDcbextrat(),0) == 0 || MdaUtils.compareTo(setgll.getScbextrat(),0) == 0 ) {
                                    setgll.setRat( new BigDecimal("0"));
                                } else {
                                    if( ininflg ) {
                                        setgll.setRat( new BigDecimal("1"));
                                        setgll.setRatcurlab( setgll.getBascur() + "/" + setgll.getBascur());
                                    } else {
                                        if(xrtmodService.xrtCrossRateDirFlg( cur1, cur2, setgll.getDcbextrat(), setgll.getScbextrat() ) ) {
                                            setgll.setRat( Decimals.mul(Decimals.div(setgll.getDcbextrat(),setgll.getScbextrat()),xrtmodService.crossRatebas( cur1, cur2 )));
                                        } else {
                                            setgll.setRat( Decimals.div(Decimals.div(setgll.getScbextrat(),setgll.getDcbextrat()),xrtmodService.crossRatebas( cur1, cur2 )));
                                        }
                                    }
                                }
                            }
                        }
                }
            }
            // convert amounts (only if currency has been changed, if to account with AmtRndUnt to respect rounding unit)
            if(MdaUtils.isEmpty(setgll.getAccamtfix())) {
                cnvAmtAccamt(setgll);
            }
            // set modification in case of free or reserved rate
            BigDecimal xrfamt = null;
            BigDecimal curMaxAmt = null;
            BigDecimal curXrfAmt = null;
            BigDecimal accCurMaxAmt = null;
            BigDecimal accCurXrfAmt = null;

            if( ( ! ininflg ) && ( MdaUtils.compareTo(setgll.getCur(),setgll.getAcccur()) != 0 ) ) {
                // if couter value in system currency is greater as maximum rate amount for account or contract currency only allow reserved rates (if not forward contract)
                xrfamt = Numerics.abs(xrtmodService.basCurEqu(setgll.getAcccur(), setgll.getAccamt(), vald));
                Cur cur = xrtmodService.getCurByCode(setgll.getCur());
                curMaxAmt = xrtmodService.getCurMaxAmt(setgll.getCur());
                curXrfAmt = Numerics.abs(xrtmodService.basCurEqu(cur.getMaxcur(), curMaxAmt, vald));
                Cur accCur = xrtmodService.getCurByCode(setgll.getAcccur());
                accCurMaxAmt = xrtmodService.getCurMaxAmt(setgll.getAcccur());
                accCurXrfAmt = Numerics.abs(xrtmodService.basCurEqu(accCur.getMaxcur(), accCurMaxAmt, vald));
                if((MdaUtils.compareTo(xrfamt,curXrfAmt) > 0 || MdaUtils.compareTo(xrfamt,accCurXrfAmt)>0 ) && MdaUtils.isEmpty(setgll.getFcdinr()) ) {
                    Set<String> ratTypFilter = new HashSet<>();
                    ratTypFilter.add("RX");
                    ratTypFilter.add("R");
                    setgll.setRatTypFilter(ratTypFilter);
                    valuesSet = true;
                }
                switch(setgll.getRattyp() ) {
                    // if reserved rate, set both rate types to
                    case "R":
                        setgll.resetModified("scbrattyp");
                        setgll.setDisable("scbrattyp");
                        if( MdaUtils.compareTo(cur2,setgll.getBascur()) != 0 ) {
                            setgll.setScbrattyp( "F");
                            setgll.resetDisable("scbextrat");
                        } else {
                            setgll.setScbrattyp( "M");
                            setgll.setDisable("scbextrat");
                        }
                        setgll.resetModified("dcbrattyp");
                        setgll.setDisable("dcbrattyp");
                        if( MdaUtils.compareTo(cur1,setgll.getBascur()) != 0 ) {
                            setgll.setDcbrattyp( "F");
                            setgll.resetDisable("dcbextrat");
                        } else {
                            setgll.setDcbrattyp( "M");
                            setgll.setDisable("dcbextrat");
                        }
                        break;
                    case "F":
                        //      Enable( DCBRATTYP )
                        //光大要求选择free时灰掉
                        setgll.setDisable("dcbrattyp");
                        if(!setgll.isModified("dcbrattyp") ) {
                            if( MdaUtils.compareTo(cur1,setgll.getBascur()) != 0 ) {
                                setgll.setDcbrattyp( "F");
                            } else {
                                setgll.setDcbrattyp( "M");
                            }
                        }
                        //     Enable( SCBRATTYP )
                        setgll.setDisable("scbrattyp");
                        if(!setgll.isModified("scbrattyp") ) {
                            if( MdaUtils.compareTo(cur2,setgll.getBascur()) != 0 ) {
                                setgll.setScbrattyp( "F");
                            } else {
                                setgll.setScbrattyp( "M");
                            }
                        }
                        break;
                }
            }
            if (!valuesSet) {
                //来源于default rule
                Set<String> ratTypFilter = new HashSet<>();
                ratTypFilter.add(" ");
                ratTypFilter.add("F");
                setgll.setRatTypFilter(ratTypFilter);
                // if selected type is not available any more, reset it
                if(!ratTypFilter.contains(setgll.getRattyp())) {
                    setgll.resetModified("rattyp");
                }
                if (!setgll.isModified("rattyp") && !" ".equals(setgll.getRattyp())) {
                    setgll.setRattyp(" ");
                    if(!restarted) {
                        //重算
                        restarted = true;
                        continue;
                    }
                }
            }
            break;
        }
        // enable rates for free rate types
        if( MdaUtils.compareTo(setgll.getScbrattyp(),"F") == 0 ) {
            setgll.resetDisable("scbextrat");
        }
        if( MdaUtils.compareTo(setgll.getDcbrattyp(),"F") == 0 ) {
            setgll.resetDisable("dcbextrat");
        }
    }

    /**
     * source:setgll.0044.script
     */
    public void defdsp(SetgllVo setgll, SetmodVo setmod) {

        // default disposition from available accounts
        if (MdaUtils.isEmpty(setgll.getRol())) {
            setgll.setRolptyinr(NULLSTR);
            setgll.setRolptainr(NULLSTR);
            setgll.setActptyflg(NULLSTR);
        } else {
            Argument<String> pathBox = new Argument<String>("", setgll.getRolptyinr());
            Argument<String> pathBox1 = new Argument<String>("", setgll.getRolptainr());
            setmodService.getPtxInr(setgll.getRol(), pathBox, pathBox1);
            setgll.setRolptyinr(pathBox.value);
            setgll.setRolptainr(pathBox1.value);
        }
        String dsplst = "";
        String cr = "";
        String paxacc = "";
        String priodsp = "";
        String val = NULLSTR;
        IStream valstm = new StreamImpl();
        int stmCnt = 0;
        String dsp = NULLSTR;
        String actptainr = NULLSTR;
        String actptyinr = NULLSTR;
        boolean prioflg = false;
        String acc = NULLSTR;
        int ptydetRow = 0;
        String dftAct = NULLSTR;
        String dftDsp = NULLSTR;
        String dftcur = NULLSTR;
        String newDSP = NULLSTR;
        IStream dsplststm = new StreamImpl();
        if (MdaUtils.compareTo(setgll.getAmt(), 0) == 0 || MdaUtils.isEmpty(setgll.getRol())) {
            //TODO Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"dsp") );
            setgll.setDsp("");
        } else {
            if (StringUtils.isEmpty(setgll.getDspflg())) {
                val = setmodService.getDsp(SettleContext.getTransName(), setgll.getAmt(), setmod);
                //国内证，融资 如果只是费用的账务，科目只能选择LO
                val = this.filterDsp(setgll, val, setmod.getRec().getObjtyp());
            } else {
                val = setgll.getDsp();
            }
            switch (Strings.mid(setgll.getDsp(), 1, 2)) {
                case "PA":
                case "RT":
                case "TG":
                    if (Strings.pos(setgll.getSetgrp().getAct().getPtytyp(), "B") == 0) {
                        //Dynamic.ptsmodGetPtsptaFromPtaINR( this.getSetgrp().getAct(), "" );
                        PtsptaVo ptsptaVo = new PtsptaVo();
                        ptsptaVo.reset();
                        setgll.getSetgrp().setAct(ptsptaVo);
                    }
                    break;
            }
            Streams.streamSet(valstm, val);
            stmCnt = Streams.streamCount(valstm);
            for (int idx = 1; idx <= stmCnt; idx++) {
                dsp = Strings.getLine(valstm, idx);
                dsplst = dsplst + cr + dsp;
                cr = CR;
            }
            if (!MdaUtils.isEmpty(dsplst)) {
                if (((!setgll.isModified("dsp")) && MdaUtils.isEmpty(setgll.getGlpinr()) && (MdaUtils.isEmpty(setgll.getExtsetflg()))) || MdaUtils.isEmpty(setgll.getDsp())) {
                    ptydetRow = setmodService.getPtyDetRow(setgll.getRol(), setmod);
                    if (ptydetRow < 0) {
                        dftAct = "";
                        dftDsp = "";
                        dftcur = "";
                    } else {
                        dftAct = setmod.getPtydet().get(ptydetRow).getDftact();
                        dftDsp = setmod.getPtydet().get(ptydetRow).getDftdsp();
                        dftcur = setmod.getPtydet().get(ptydetRow).getDftcur();
                    }
                    // allow interchange between xxD and xxC
                    if (MdaUtils.isEmpty(dftDsp) || MdaUtils.compareTo(setgll.getAcccur(), dftcur) != 0 || Strings.searchBlock(dsplst, Strings.mid(dftDsp, 1, 2) + setgll.getDebcdtflg()) == 0) {
                        newDSP = Strings.getLine(dsplst, 1);
                    } else {
                        String crdrFlg = "";
                        if (setgll.getAmt().compareTo(BigDecimal.ZERO) < 0) {
                            crdrFlg = "C";
                        } else if (setgll.getAmt().compareTo(BigDecimal.ZERO) > 0) {
                            crdrFlg = "D";
                        }
                        newDSP = Strings.mid(dftDsp, 1, 2) + crdrFlg;
                    }
                    if (MdaUtils.compareTo(setgll.getDsp(), newDSP) != 0) {
                        //MdaUtils.clear(setgll.getActp());
                        //MdaUtils.clear(setgll.getApyp());
                        PtsptaVo ptsptaVo1 = new PtsptaVo();
                        ptsptaVo1.reset();
                        setgll.getSetgrp().setAct(ptsptaVo1);
                        ptsptaVo1 = new PtsptaVo();
                        ptsptaVo1.reset();
                        setgll.getSetgrp().setApy(ptsptaVo1);
                    }
                    setgll.setDsp(newDSP);
                    setgll.resetModified("dsp");
                }
            }
            //设置dsp动态码表\
            if (dsplst != null) {
                List<CodetableItem> dspSet = new ArrayList<>();
                String[] dsps = dsplst.split("\n");
                for (String dspStr : dsps) {
                    String dspLabel = codetableService.getTblLabel(dspStr,"dsptrm");
                    if (StringUtils.isEmpty(dspLabel)) {
                        dspLabel = dspStr;
                    }
                    dspSet.add(new CodetableItem(dspLabel, dspStr));
                }
                setgll.setDspSet(dspSet);
            }
            //  if dsp without accounts should be selectable use: SetValues( DSP, $VAL )
            /*Systems.setValues(this,"dsp",dsplst);
            Streams.streamSet(dsplststm,dsplst);
            if( Streams.streamCount(dsplststm) > 1 )
            {
                Systems.setEnabled(this,"dsp");
            }
            else
            {
                Systems.resetEnabled(this,"dsp");
                Systems.resetModified(this,"dsp");
            }*/
        }
    }

    /**
     * source:setgll.0007.script
     */
    public void defActSub(SetgllVo setgll, SetmodVo setmod) {
        //! defaults account and account related fields including enabling/disabling
        //---ZMQZMQ-----
        //--zmqtest----
        if (MdaUtils.compareTo(this.getzmqflg(), "X") == 0) {
            clcrat_ZMQ(setgll);
        } else {
            clcrat(setgll);
        }
        String actptainr = NULLSTR;
        String actptyinr = NULLSTR;
        String actlst = NULLSTR;
        IStream actval = new StreamImpl();
        int ptydetRow = 0;
        String dftAct = NULLSTR;
        String rulenam = NULLSTR;
        String postcmd = NULLSTR;
        String sql = NULLSTR;
        //IStream actvalstm = new StreamImpl();
        if (MdaUtils.isEmpty(setgll.getAcccur()) || (MdaUtils.compareTo(setgll.getAccamt(), 0) == 0) || MdaUtils.isEmpty(setgll.getRol()) || MdaUtils.isEmpty(setgll.getDsp())) {
            setgll.setActflg(NULLSTR);
            //MdaUtils.clear(this.getActrec());
            //MdaUtilsEx.setStyleNum(-1,this.getAct());
            //Systems.resetEnabled(this,"act");
        } else {
            actptainr = getACTPTAINR(setgll, setmod, setgll.getDsp());
            Pta pta = ptaCacheService.getPtaByInr(actptainr);
            if (pta != null) {
                actptyinr = pta.getPtyinr();
            }
            /**  $sql = ACTgetsql( $ACTPTYINR, DSP, ACCCUR, self, ACTPTYFLG )
             $actlst = \\TRNMOD.ACTGetSerBlk( $sql, $ACTPTYINR, DSP, $prioflg, AMT )
             if IsEmpty( $actlst ) then
             $actlst = ACTGetComBlk( DSP, DSP, ACCCUR, self )
             endif
             **/
            if (!MdaUtils.isEmpty(setgll.getSetgrp().getAct().getPtyinr())) {
                actptyinr = setgll.getSetgrp().getAct().getPtyinr();
            }
            actlst = glemodService.getAvailAcc(setgll.getDsp(), setgll.getAcccur(), actptyinr, setgll.getAmt());
            //设置账号动态码表
            Set<String> actSet = new HashSet<>();
            String[] acts = actlst.split("\r\n");
            for (String account : acts) {
                if (StringUtils.isNotEmpty(account.trim())) {
                    actSet.add(account);
                }
            }
            setgll.setActSet(actSet);
            //Systems.setValues(this,"act",actlst);
            setgll.setActflg("N");
            Streams.streamSet(actval, actlst);

            //actval = Streams.streamInsert(actval);
            ptydetRow = setmodService.getPtyDetRow(setgll.getRol(), setmod);
            if (ptydetRow < 0) {
                dftAct = "";
            } else {
                dftAct = setmod.getPtydet().get(ptydetRow).getDftact();
            }
            if (((!setgll.isModified("act")) || MdaUtils.isEmpty(setgll.getAct())) && (!MdaUtils.isEmpty(actval)) && ((MdaUtils.isEmpty(setgll.getExtsetflg())) || MdaUtils.compareTo(setgll.getExtsetflg(), "D") == 0) && !setglgService.getFixDspflagSet().contains(setgll.getDspflg()) && (MdaUtils.isEmpty(setgll.getGlpinr()) || MdaUtils.isEmpty(setgll.getAct()) || Strings.searchBlock(actval, dftAct) == 0)) {
                if (MdaUtils.isEmpty(dftAct) || Strings.searchBlock(actval, dftAct) == 0) {
                    if (SettleContext.getUserSession().getAtp() != null && MdaUtils.compareTo(SettleContext.getUserSession().getAtp().getCod(), "GITODZ") == 0) {
                        if (!MdaUtils.isEmpty(dftAct)) {
                            setgll.setAct(dftAct);
                        } else {
                            setgll.setAct(Strings.getLine(actval, 1));
                        }
                    } else {
                        setgll.setAct(Strings.getLine(actval, 1));
                    }
                } else {
                    setgll.setAct(dftAct);
                }
                setgll.setActflg("D");
            }
            // check defaulted account number i.e. against host accounts. Rule has to be defined on level 6
            if (Strings.searchBlock(actval, setgll.getAct()) == 0) {
                //Systems.setTDStyle("red",this.getAct());
                if (MdaUtils.isEmpty(setgll.getAct())) {
                    setgll.setActflg("N");
                    //MdaUtils.clear(this.getActrec());
                } else {
                    setgll.setActflg("M");
                }
            } else {
                setgll.setActflg("D");
                if (MdaUtils.compareTo(setgll.getActrec().getExtkey(), setgll.getAct()) != 0) {
                    if (MdaUtils.isEmpty(setgll.getAct())) {
                        //MdaUtils.clear(this.getActrec());
                    } else {
                        sql = Utils.sdbEtyGenSql("ACT", "WHERE EXTKEY = '" + setgll.getAct() + "'");
                        List<Act> actList = actMapper.getActByConditionSql(sql);
                        if (actList == null || actList.size() == 0) {
                            setgll.getActrec().setExtkey(setgll.getAct());
                            setgll.setActflg("L");
                        } else {
                            ActVo actVo = DtoMapper.INSTANCE.transfer(actList.get(0));
                            setgll.setActrec(actVo);
                        }
                    }
                    //      informcurrent
                }
            }
            //  ActSetCodeValues( ACT )
            // Streams.streamSet(actvalstm,actval);
            // 光大需求，如果只带出一个账号，一样要能改
            /*if( MdaUtils.compareTo(this.getDspflg(),"A") != 0 )
            {
                //  if ( StreamCount( $actvalstm ) <> 1 or Mid( ACT, 1, 1 ) = "*" ) and DSPFLG <> "A" then
                Systems.setEnabled(this,"act");
            }
            else
            {
                Systems.resetEnabled(this,"act");
            }*/
        }
    }

    /**
     * source:setgll.0045.script
     */
    public String getACTPTAINR(SetgllVo setgll, SetmodVo setmod, String actdsp) {
        int ptydetRow = -1;
        String dftAct = NULLSTR;
        String dftActptainr = NULLSTR;
        String dftDsp = NULLSTR;
        String dftcur = NULLSTR;
        switch (Strings.mid(actdsp, 1, 2)) {
            //  case "DBT", "CDT", "HLD", "BEF", "BDF"
            case "LO":
            case "BD":
            case "BE":
            case "BR":
            case "CC":
            case "TR":
            case "FI":
            case "LF":
                Setpty setpty = setfegService.getFeeSet().getSetpty(setgll.getRol());
                if (setpty != null) {
                    if (StringUtils.isEmpty(setpty.getActptainr())) {
                        return setpty.getPtaInr();
                    } else {
                        return setpty.getActptainr();
                    }
                } else {
                    return "";
                }
                //  case "INC", "IND", "SID"
                //break;
            case "IN":
                return SettleContext.getUserEty().getOwnptainr();
            default:
                ptydetRow = setmodService.getPtyDetRow(setgll.getRol(), setmod);
                if (ptydetRow < 0) { //没有找到ptydet
                    dftAct = "";
                    dftActptainr = "";
                    dftDsp = "";
                    dftcur = "";
                } else {
                    dftAct = setmod.getPtydet().get(ptydetRow).getDftact();
                    dftActptainr = setmod.getPtydet().get(ptydetRow).getDftactptainr();
                    dftDsp = setmod.getPtydet().get(ptydetRow).getDftdsp();
                    dftcur = setmod.getPtydet().get(ptydetRow).getDftcur();
                }
                if (MdaUtils.compareTo(setgll.getAcccur(), dftcur) == 0 && MdaUtils.compareTo(setgll.getDsp(), dftDsp) == 0 && (!MdaUtils.isEmpty(dftActptainr))) {
                    return dftActptainr;
                } else {
                    // read PTY-Info for party, if account party for current dispocode
                    if (MdaUtils.compareTo(setgll.getDsp(), actdsp) == 0) {
                        return setgll.getSetgrp().getAct().getPtainr();
                    } else {
                        return "";
                    }
                }
        }
    }

    /**
     * source:setgll.0137.script
     */
    public void clcrat_ZMQ(SetgllVo setgll) {
        //! calulation of rates and rate types
        boolean restarted = false;
        boolean valuesSet = false;
        // ####### 改写 LABEL与GOTO   ####    label restart
        while(true){
            // use valdat as rate date. If valdat not available use Today
            Date vald = Dates.today();
            clcratSetTypes(setgll);
            boolean ininflg = false;
            // no conversion if currencies are the same
            String sysCur = NULLSTR;
            String newcur = NULLSTR;
            String newacccur = NULLSTR;
            String cur1 = NULLSTR;
            String cur2 = NULLSTR;
            Date curdat = null;
            BigDecimal cur1dif = null;
            BigDecimal cur2dif = null;
            Date accdat = null;
            if(MdaUtils.compareTo(setgll.getAcccur(), setgll.getCur()) == 0) {
                setgll.setDisable("dcbextrat");
                setgll.setDisable("dcbsqrrat");
                setgll.setDisable("dcbrattyp");
                setgll.setDisable("scbextrat");
                setgll.setDisable("scbsqrrat");
                setgll.setDisable("scbrattyp");
                setgll.setDisable("rat");
                setgll.setRat( new BigDecimal("1"));
                setgll.setDcbextrat( new BigDecimal("1"));
                setgll.setDcbsqrrat( new BigDecimal("1"));
                setgll.setScbextrat( new BigDecimal("1"));
                setgll.setScbsqrrat( new BigDecimal("1"));
                setgll.setDcbresrat( new BigDecimal("1"));
                setgll.setDcbrebrat( new BigDecimal("1"));
                setgll.setScbresrat( new BigDecimal("1"));
                setgll.setScbrebrat( new BigDecimal("1"));
                setgll.setRatcurlab(NULLSTR);
                setgll.setDcbratlab(NULLSTR);
                setgll.setScbratlab(NULLSTR);
                setgll.setDisable("rattyp");
                setgll.setRattyp(" ");
                setgll.setXrtdatacc(null);
                setgll.setXrtdatcur(null);
                Set<String> ratTypFilter = new HashSet<>();
                ratTypFilter.add(" ");
                setgll.setRatTypFilter(ratTypFilter);
                valuesSet = true;
            } else {
                //取牌价时间、卖价、买价和中间价
                Argument<String> pathBox = new Argument<String>("",setgll.getXrttim());
                Argument<BigDecimal> pathBox1 = new Argument<BigDecimal>("",setgll.getBuyrat());
                Argument<BigDecimal> pathBox2 = new Argument<BigDecimal>("",setgll.getSelrat());
                Argument<BigDecimal> pathBox3 = new Argument<BigDecimal>("",setgll.getMidrat());
                xrtmodService.getratCebTim_ZMQ(setgll.getCur(), setgll.getAcccur(), Dates.today(), pathBox, pathBox1, pathBox2, pathBox3 );

                setgll.setXrttim( pathBox.value);
                setgll.setBuyrat( pathBox1.value);
                setgll.setSelrat( pathBox2.value);
                setgll.setMidrat( pathBox3.value);

                //取出汇率优惠值
                //----------获取ptyrat对应客户对应币种的优惠方式和优惠点数------
                Pty pty = ptyCacheService.getPtyById(setgll.getRolptyinr());
                sysCur = xrtmodService.sysiso();
                Ptyrat ptyrat = null;
                if (MdaUtils.compareTo(setgll.getCur(), sysCur) == 0 && MdaUtils.compareTo(setgll.getAcccur(), sysCur) != 0) {
                    ptyrat = ptyratMapper.getPtyratByPtyinrAndCur(pty.getInr(), setgll.getAcccur());
                } else {
                    if (MdaUtils.compareTo(setgll.getAcccur(), sysCur) == 0 && MdaUtils.compareTo(setgll.getCur(), sysCur) != 0) {
                        ptyrat = ptyratMapper.getPtyratByPtyinrAndCur(pty.getInr(), setgll.getCur());
                    }
                }
                if (ptyrat != null) {
                    setgll.setPrebuyrat(ptyrat.getBuyrat());
                    setgll.setPreselrat(ptyrat.getSelrat());
                    setgll.setBuyrattyp(StringUtils.isEmpty(ptyrat.getBuytyp())?" ":ptyrat.getBuytyp());
                    setgll.setSelrattyp(StringUtils.isEmpty(ptyrat.getSeltyp())?" ":ptyrat.getSeltyp());
                }
                /**
                 PREBUYRAT = \\TRNMOD\\PTSMOD\\PTY\\BUYRAT
                 PRESELRAT = \\TRNMOD\\PTSMOD\\PTY\\SELRAT
                 BUYRATTYP = \\TRNMOD\\PTSMOD\\PTY\\BUYTYP
                 SELRATTYP = \\TRNMOD\\PTSMOD\\PTY\\SELTYP
                 **/
                // set currencies involved in conversion (incl. IN/IN specials)
                ininflg = false;
                Argument<String> newcurBox = new Argument<String>();
                Argument<String> newacccurBox = new Argument<String>();
                Argument<String> pathBox4 = new Argument<String>("",setgll.getBascur());
                Argument<Boolean> ininflgBox = new Argument<Boolean>("",ininflg);
                xrtmodService.xrtCheckInIn(setgll.getCur(), setgll.getAcccur(), newcurBox, newacccurBox, pathBox4, ininflgBox );

                newcur = newcurBox.value;
                newacccur = newacccurBox.value;
                setgll.setBascur(pathBox4.value);
                ininflg = ininflgBox.value;

                if( MdaUtils.isEmpty(newcur) || ininflg ) {
                    cur1 = setgll.getCur();
                } else {
                    cur1 = newcur;
                }
                if( MdaUtils.isEmpty(newacccur) || ininflg ) {
                    cur2 = setgll.getAcccur();
                } else {
                    cur2 = newacccur;
                }
                setgll.setRatcurlab( cur1 + "/" + cur2);
                setgll.setDcbratlab( cur1 + "/" + setgll.getBascur());
                setgll.setScbratlab( setgll.getBascur() + "/" + cur2);
                // if in/in or forward contract disable everything
                if( ininflg || ( ! MdaUtils.isEmpty(setgll.getFcdinr()) ) ) {
                    setgll.setDisable("dcbextrat");
                    setgll.setDisable("dcbsqrrat");
                    setgll.setDisable("dcbrattyp");
                    setgll.setDisable("scbextrat");
                    setgll.setDisable("scbsqrrat");
                    setgll.setDisable("scbrattyp");
                    setgll.setDisable("rat");
                    setgll.setDisable("rattyp");
                    // for forward contract set forward contract rate type
                    if(!MdaUtils.isEmpty(setgll.getFcdinr()) ) {
                        setgll.setRattyp( "C");
                        Set<String> ratTypFilter = new HashSet<>();
                        ratTypFilter.add("C");
                        setgll.setRatTypFilter(ratTypFilter);
                        valuesSet = true;
                        setgll.setDcbrattyp( "R");
                        setgll.setScbrattyp( "R");
                        // SCBEXTRAT & DCBEXTRAT are already set via SetglgAddAmtFldExtRat
                    } else {
                        Set<String> ratTypFilter = new HashSet<>();
                        ratTypFilter.add(" ");
                        setgll.setRatTypFilter(ratTypFilter);
                        valuesSet = true;
                    }
                } else {
                    // otherwise allow change of ratetype
                    setgll.setDisable("dcbextrat");
                    setgll.setDisable("dcbsqrrat");
                    setgll.setDisable("dcbrattyp");
                    setgll.setDisable("scbextrat");
                    setgll.setDisable("scbsqrrat");
                    setgll.setDisable("scbrattyp");
                    setgll.resetDisable("rattyp");
                    //如果是结售汇需要置灰rattyp
                    if ("J".equals(setgll.getDspflg())) {
                        setgll.setDisable("rattyp");
                    }
                    Cur cur = new Cur();
                    Zmqxrt zmqxrt = new Zmqxrt();
                    // get currency with bigger margin (only in crosrate calculations i.e. both currencies are not base currency)
                    xrtmodService.getzmqXrt(cur1, vald, cur, zmqxrt);
                    // show begin-date of exchange rate of CUR
                    curdat = zmqxrt.getBegdat();
                    setgll.setXrtdatcur(curdat);
                    // avoid dump if rate is not available (no difference for BASCUR)
                    if (MdaUtils.compareTo(cur1, setgll.getBascur()) == 0) {
                        cur1dif = new BigDecimal("0");
                    } else {
                        if (MdaUtils.compareTo(zmqxrt.getBuyrat(), 0) != 0 && MdaUtils.compareTo(zmqxrt.getSelrat(), 0) != 0) {
                            cur1dif = Decimals.div(zmqxrt.getSelrat(), zmqxrt.getBuyrat());
                        } else {
                            cur1dif = new BigDecimal("0");
                            throw new CommonServiceException("No exchange rate found for " + cur1 + ", please enter exchange rate first!");
                        }
                    }
                    xrtmodService.getzmqXrt(cur2, vald, cur, zmqxrt);
                    // avoid dump if rate is not available (no difference for BASCUR)
                    if (MdaUtils.compareTo(cur2, setgll.getBascur()) == 0) {
                        cur2dif = new BigDecimal("0");
                    } else {
                        if (MdaUtils.compareTo(zmqxrt.getBuyrat(), 0) != 0 && MdaUtils.compareTo(zmqxrt.getSelrat(), 0) != 0) {
                            cur2dif = Decimals.div(zmqxrt.getSelrat(), zmqxrt.getBuyrat());
                        } else {
                            cur2dif = new BigDecimal("0");
                            /*ctx.setFieldError(this,"rat",MdaUtils.getI18NString("setgll","CT000120"),cur2);*/
                            throw new CommonServiceException("No exchange rate found for " + cur2 + ", please enter exchange rate first!");
                        }
                    }
                    // show begin-date of exchange rate of ACCCUR
                    accdat = zmqxrt.getBegdat();
                    setgll.setXrtdatacc(accdat);
                    // set middle rate for curreny with smaller margin, selling/buying for the other
                    if( ( MdaUtils.compareTo(cur2,setgll.getBascur()) != 0 && MdaUtils.compareTo(cur1dif,cur2dif)>0 )
                            || MdaUtils.compareTo(cur1,setgll.getBascur()) == 0 ) {
                        if( MdaUtils.compareTo(setgll.getDcbrattyp(),"F") != 0 && Strings.len(setgll.getRattyp()) != 1 ) {
                            setgll.setDcbrattyp( "M");
                        }
                        if( Strings.len(setgll.getRattyp().trim()) == 1 ) {
                            setgll.resetDisable("scbrattyp");
                        }
                    } else {
                        if( MdaUtils.compareTo(setgll.getScbrattyp(),"F") != 0
                                && Strings.len(setgll.getRattyp()) != 1 ) {
                            setgll.setScbrattyp( "M");
                        }
                        if( Strings.len(setgll.getRattyp().trim()) == 1 ) {
                            setgll.resetDisable("dcbrattyp");
                        }
                    }
                }
                // rate calulation:
                switch(setgll.getRattyp()) {
                    // for crossrates, the crossrate can be entered and the rate not beeing the middle rate is calculated from crossrate ane middle rate
                    case "RX":
                    case  "FX":
                        setgll.resetDisable("rat");
                        if( MdaUtils.compareTo(setgll.getDcbrattyp(),"M") == 0 ) {
                            if( MdaUtils.compareTo(cur1,setgll.getBascur()) == 0 || MdaUtils.compareTo(cur2,setgll.getBascur()) == 0 ) {
                                setgll.setScbextrat(setgll.getRat());
                            } else {
                                if(xrtmodService.xrtCrossRateDirFlg( cur1, cur2, setgll.getDcbextrat(), setgll.getScbextrat() ) ) {
                                    if( MdaUtils.compareTo(setgll.getRat(),0) == 0 ) {
                                        setgll.setScbextrat(new BigDecimal("0"));
                                    } else {
                                        setgll.setScbextrat(Decimals.mul(Decimals.div(setgll.getDcbextrat(),setgll.getRat()),xrtmodService.crossRatebas( cur1, cur2 )));
                                    }
                                } else {
                                    setgll.setScbextrat(Decimals.mul(Decimals.mul(setgll.getDcbextrat(),setgll.getRat()),xrtmodService.crossRatebas( cur1, cur2 )));
                                }
                            }
                            Argument<BigDecimal> pathBox5 = new Argument<BigDecimal>("",setgll.getDcbextrat());
                            Argument<BigDecimal> pathBox6 = new Argument<BigDecimal>("",setgll.getDcbsqrrat());
                            Argument<BigDecimal> pathBox7 = new Argument<BigDecimal>("",setgll.getDcbresrat());
                            Argument<BigDecimal> pathBox8 = new Argument<BigDecimal>("",setgll.getDcbrebrat());
                            setglgService.getRateXrtWithResRatesZZZ_ZMQ(ptyrat, setgll.getCur(), setgll.getBascur(), ininflg, setgll.getDcbrattyp(), vald, pathBox5, pathBox6, pathBox7, pathBox8 );

                            setgll.setDcbextrat( pathBox5.value);
                            setgll.setDcbsqrrat( pathBox6.value);
                            setgll.setDcbresrat( pathBox7.value);
                            setgll.setDcbrebrat( pathBox8.value);

                        } else {
                            if( MdaUtils.compareTo(cur1,setgll.getBascur()) == 0 || MdaUtils.compareTo(cur2,setgll.getBascur()) == 0 ) {
                                setgll.setDcbextrat(setgll.getRat());
                            } else {
                                if( xrtmodService.xrtCrossRateDirFlg( cur1, cur2, setgll.getDcbextrat(), setgll.getScbextrat() ) ) {
                                    setgll.setDcbextrat( Decimals.mul(Decimals.mul(setgll.getRat(),setgll.getScbextrat()),xrtmodService.crossRatebas( cur2, cur1 )));
                                } else {
                                    if( MdaUtils.compareTo(setgll.getRat(),0) == 0 ) {
                                        setgll.setDcbextrat( new BigDecimal("0"));
                                    } else {
                                        setgll.setDcbextrat( Decimals.mul(Decimals.div(setgll.getScbextrat(),setgll.getRat()),xrtmodService.crossRatebas( cur2, cur1 )));
                                    }
                                }
                            }
                            Argument<BigDecimal> pathBox9 = new Argument<BigDecimal>("",setgll.getScbextrat());
                            Argument<BigDecimal> pathBox10 = new Argument<BigDecimal>("",setgll.getScbsqrrat());
                            Argument<BigDecimal> pathBox11 = new Argument<BigDecimal>("",setgll.getScbresrat());
                            Argument<BigDecimal> pathBox12 = new Argument<BigDecimal>("",setgll.getScbrebrat());
                            setglgService.getRateXrtWithResRatesZZZ_ZMQ(ptyrat, setgll.getAcccur(), setgll.getBascur(), ininflg, setgll.getScbrattyp(), vald, pathBox9, pathBox10, pathBox11, pathBox12 );

                            setgll.setScbextrat( pathBox9.value);
                            setgll.setScbsqrrat( pathBox10.value);
                            setgll.setScbresrat( pathBox11.value);
                            setgll.setScbrebrat( pathBox12.value);
                        }
                        break;
                    default:
                        // in other cases the crossrate is disabled
                        setgll.setDisable("rat");
                        // the rates are read (according to rate type if not free)
                        switch( setgll.getDcbrattyp() ) {
                            case "F":
                                // clear begin-date of exchange-rate, if crossrate can be entered
                                setgll.setXrtdatcur(null);
                                break;
                            case "C":
                            case  "R":
                                break;
                            default:
                                Argument<BigDecimal> pathBox13 = new Argument<BigDecimal>("",setgll.getDcbextrat());
                                Argument<BigDecimal> pathBox14 = new Argument<BigDecimal>("",setgll.getDcbsqrrat());
                                Argument<BigDecimal> pathBox15 = new Argument<BigDecimal>("",setgll.getDcbresrat());
                                Argument<BigDecimal> pathBox16 = new Argument<BigDecimal>("",setgll.getDcbrebrat());
                                setglgService.getRateXrtWithResRatesZZZ_ZMQ(ptyrat, setgll.getCur(), setgll.getBascur(), ininflg, setgll.getDcbrattyp(), vald, pathBox13, pathBox14, pathBox15, pathBox16 );

                                setgll.setDcbextrat( pathBox13.value);
                                setgll.setDcbsqrrat( pathBox14.value);
                                setgll.setDcbresrat( pathBox15.value);
                                setgll.setDcbrebrat( pathBox16.value);
                        }
                        switch( setgll.getScbrattyp() ) {
                            case "F":
                                // clear begin-date of exchange-rate, if crossrate can be entered
                                setgll.setXrtdatacc(null);
                                break;
                            case "C":
                            case  "R":
                                break;
                            default:
                                Argument<BigDecimal> pathBox17 = new Argument<BigDecimal>("",setgll.getScbextrat());
                                Argument<BigDecimal> pathBox18 = new Argument<BigDecimal>("",setgll.getScbsqrrat());
                                Argument<BigDecimal> pathBox19 = new Argument<BigDecimal>("",setgll.getScbresrat());
                                Argument<BigDecimal> pathBox20 = new Argument<BigDecimal>("",setgll.getScbrebrat());
                                setglgService.getRateXrtWithResRatesZZZ_ZMQ(ptyrat, setgll.getAcccur(), setgll.getBascur(), ininflg, setgll.getScbrattyp(), vald, pathBox17, pathBox18, pathBox19, pathBox20 );

                                setgll.setScbextrat( pathBox17.value);
                                setgll.setScbsqrrat( pathBox18.value);
                                setgll.setScbresrat( pathBox19.value);
                                setgll.setScbrebrat( pathBox20.value);
                        }
                        // and the crossrate (RAT) is calculated. ( the logic has to match with the setting of the direction in CnvAmtAccamt)
                        if( MdaUtils.compareTo(setgll.getCur(),setgll.getBascur()) == 0 ) {
                            setgll.setRat( setgll.getScbextrat());
                            // clear begin-date of exchange rate, if exchange = 1
                            setgll.setXrtdatcur(null);
                        } else {
                            if( MdaUtils.compareTo(setgll.getAcccur(),setgll.getBascur()) == 0 ) {
                                setgll.setRat(setgll.getDcbextrat());
                            } else {
                                if( MdaUtils.compareTo(setgll.getDcbextrat(),0) == 0 || MdaUtils.compareTo(setgll.getScbextrat(),0) == 0 ) {
                                    setgll.setRat( new BigDecimal("0"));
                                } else {
                                    if( ininflg ) {
                                        setgll.setRat( new BigDecimal("1"));
                                        setgll.setRatcurlab( setgll.getBascur() + "/" + setgll.getBascur());
                                    } else {
                                        if(xrtmodService.xrtCrossRateDirFlg( cur1, cur2, setgll.getDcbextrat(), setgll.getScbextrat() ) ) {
                                            setgll.setRat( Decimals.mul(Decimals.div(setgll.getDcbextrat(),setgll.getScbextrat()),xrtmodService.crossRatebas( cur1, cur2 )));
                                        } else {
                                            setgll.setRat( Decimals.div(Decimals.div(setgll.getScbextrat(),setgll.getDcbextrat()),xrtmodService.crossRatebas( cur1, cur2 )));
                                        }
                                    }
                                }
                            }
                        }
                }
            }
            // convert amounts (only if currency has been changed, if to account with AmtRndUnt to respect rounding unit)
            if(MdaUtils.isEmpty(setgll.getAccamtfix())) {
                cnvAmtAccamt(setgll);
            }
            // set modification in case of free or reserved rate
            BigDecimal xrfamt = null;
            BigDecimal curMaxAmt = null;
            BigDecimal curXrfAmt = null;
            BigDecimal accCurMaxAmt = null;
            BigDecimal accCurXrfAmt = null;

            if( ( ! ininflg ) && ( MdaUtils.compareTo(setgll.getCur(),setgll.getAcccur()) != 0 ) ) {
                // if couter value in system currency is greater as maximum rate amount for account or contract currency only allow reserved rates (if not forward contract)
                xrfamt = Numerics.abs(xrtmodService.basCurEqu(setgll.getAcccur(), setgll.getAccamt(), vald));
                Cur cur = xrtmodService.getCurByCode(setgll.getCur());
                curMaxAmt = xrtmodService.getCurMaxAmt(setgll.getCur());
                curXrfAmt = Numerics.abs(xrtmodService.basCurEqu(cur.getMaxcur(), curMaxAmt, vald));
                Cur accCur = xrtmodService.getCurByCode(setgll.getAcccur());
                accCurMaxAmt = xrtmodService.getCurMaxAmt(setgll.getAcccur());
                accCurXrfAmt = Numerics.abs(xrtmodService.basCurEqu(accCur.getMaxcur(), accCurMaxAmt, vald));
                if((MdaUtils.compareTo(xrfamt,curXrfAmt) > 0 || MdaUtils.compareTo(xrfamt,accCurXrfAmt)>0 ) && MdaUtils.isEmpty(setgll.getFcdinr()) ) {
                    Set<String> ratTypFilter = new HashSet<>();
                    ratTypFilter.add("RX");
                    ratTypFilter.add("R");
                    setgll.setRatTypFilter(ratTypFilter);
                    valuesSet = true;
                }
                switch(setgll.getRattyp() ) {
                    // if reserved rate, set both rate types to
                    case "R":
                        setgll.resetModified("scbrattyp");
                        setgll.setDisable("scbrattyp");
                        if( MdaUtils.compareTo(cur2,setgll.getBascur()) != 0 ) {
                            setgll.setScbrattyp( "F");
                            setgll.resetDisable("scbextrat");
                        } else {
                            setgll.setScbrattyp( "M");
                            setgll.setDisable("scbextrat");
                        }
                        setgll.resetModified("dcbrattyp");
                        setgll.setDisable("dcbrattyp");
                        if( MdaUtils.compareTo(cur1,setgll.getBascur()) != 0 ) {
                            setgll.setDcbrattyp( "F");
                            setgll.resetDisable("dcbextrat");
                        } else {
                            setgll.setDcbrattyp( "M");
                            setgll.setDisable("dcbextrat");
                        }
                        break;
                    case "F":
                        //      Enable( DCBRATTYP )
                        //光大要求选择free时灰掉
                        setgll.setDisable("dcbrattyp");
                        if(!setgll.isModified("dcbrattyp") ) {
                            if( MdaUtils.compareTo(cur1,setgll.getBascur()) != 0 ) {
                                setgll.setDcbrattyp( "F");
                            } else {
                                setgll.setDcbrattyp( "M");
                            }
                        }
                        //     Enable( SCBRATTYP )
                        setgll.setDisable("scbrattyp");
                        if(!setgll.isModified("scbrattyp") ) {
                            if( MdaUtils.compareTo(cur2,setgll.getBascur()) != 0 ) {
                                setgll.setScbrattyp( "F");
                            } else {
                                setgll.setScbrattyp( "M");
                            }
                        }
                        break;
                }
            }
            if (!valuesSet) {
                //来源于default rule
                Set<String> ratTypFilter = new HashSet<>();
                ratTypFilter.add(" ");
                ratTypFilter.add("F");
                setgll.setRatTypFilter(ratTypFilter);
                // if selected type is not available any more, reset it
                if(!ratTypFilter.contains(setgll.getRattyp())) {
                    setgll.resetModified("rattyp");
                }
                if (!setgll.isModified("rattyp") && !" ".equals(setgll.getRattyp())) {
                    setgll.setRattyp(" ");
                    if(!restarted) {
                        //重算
                        restarted = true;
                        continue;
                    }
                }
            }
            break;
        }
        // enable rates for free rate types
        if( MdaUtils.compareTo(setgll.getScbrattyp(),"F") == 0 ) {
            setgll.resetDisable("scbextrat");
        }
        if( MdaUtils.compareTo(setgll.getDcbrattyp(),"F") == 0 ) {
            setgll.resetDisable("dcbextrat");
        }
    }

    /**
     * source:setgll.0053.script
     */
    public void clcratSetTypes(SetgllVo setgll) {
        // set rate type for document conversion
        // this is done, if one of the following is true:
        // 1. The rate type isempty
        // 2. The rate type is not modified and
        //  2a) the selected type is not free rate or
        //  2b) the overall rate type is a crossrate or automatic (in this cases even free rates are resetted).
        // read rate types per party, if defined
        if (((!setgll.isModified("dcbrattyp")) && (MdaUtils.compareTo(setgll.getDcbrattyp(), "F") != 0 || MdaUtils.compareTo(Strings.mid(setgll.getRattyp(), 2, 1), "X") == 0 || MdaUtils.isEmpty(setgll.getRattyp()))) || MdaUtils.isEmpty(setgll.getDcbrattyp()) || MdaUtils.isEmpty(setgll.getRattyp())) {
            setgll.resetModified("dcbrattyp");
            if (MdaUtils.compareTo(setgll.getRattyp(), "R") == 0) {
                setgll.setDcbrattyp("F");
            } else {
                setgll.resetModified("dcbextrat");
                if (MdaUtils.compareTo(setgll.getAmt(), 0) >= 0) {
                    /**
                     if not IsEmpty( \\TRNMOD\\PTSMOD\\PTY\\SELTYP ) then
                     DCBRATTYP = \\TRNMOD\\PTSMOD\\PTY\\SELTYP
                     else
                     DCBRATTYP = "S"
                     endif
                     **/
                    setgll.setDcbrattyp("S");
                } else {
                    /**
                     if not IsEmpty( \\TRNMOD\\PTSMOD\\PTY\\BUYTYP ) then
                     DCBRATTYP = \\TRNMOD\\PTSMOD\\PTY\\BUYTYP
                     else
                     DCBRATTYP = "B"
                     endif
                     **/
                    setgll.setDcbrattyp("B");
                }
            }
        }
        // same for settlement conversion
        if (((!setgll.isModified("scbrattyp")) && (MdaUtils.compareTo(setgll.getScbrattyp(), "F") != 0 || MdaUtils.compareTo(Strings.mid(setgll.getRattyp(), 2, 1), "X") == 0 || MdaUtils.isEmpty(setgll.getRattyp()))) || MdaUtils.isEmpty(setgll.getScbrattyp()) || MdaUtils.isEmpty(setgll.getRattyp())) {
            setgll.resetModified("scbrattyp");
            if (MdaUtils.compareTo(setgll.getRattyp(), "R") == 0) {
                setgll.setScbrattyp("F");
            } else {
                setgll.resetModified("scbextrat");
                if (MdaUtils.compareTo(setgll.getAmt(), 0) >= 0) {
                    /**
                     if not IsEmpty( \\TRNMOD\\PTSMOD\\PTY\\BUYTYP ) then
                     SCBRATTYP = \\TRNMOD\\PTSMOD\\PTY\\BUYTYP
                     else
                     SCBRATTYP = "B"
                     endif
                     **/
                    setgll.setScbrattyp("B");
                } else {
                    /**
                     if not IsEmpty( \\TRNMOD\\PTSMOD\\PTY\\SELTYP ) then
                     SCBRATTYP = \\TRNMOD\\PTSMOD\\PTY\\SELTYP
                     else
                     SCBRATTYP = "S"
                     endif
                     **/
                    setgll.setScbrattyp("S");
                }
            }
        }
    }

    /**
     * source:setgll.0028.script
     */
    public void cnvAmtAccamt(SetgllVo setgll) {
        //! Converts amount AMT to ACCAMT or vice versa depending on MODFLG using rates
        boolean ininflg = false;
        String newcur;
        Argument<String> newcurBox = new Argument<String>();
        String newacccur;
        Argument<String> newacccurBox = new Argument<String>();
        Argument<String> pathBox = new Argument<String>("", setgll.getBascur());
        Argument<Boolean> ininflgBox = new Argument<Boolean>("", ininflg);
        xrtmodService.xrtCheckInIn(setgll.getCur(), setgll.getAcccur(), newcurBox, newacccurBox, pathBox, ininflgBox);

        newcur = newcurBox.value;
        newacccur = newacccurBox.value;
        setgll.setBascur(pathBox.value);
        ininflg = ininflgBox.value;

        String cur1 = NULLSTR;
        if (MdaUtils.isEmpty(newcur) || ininflg) {
            cur1 = setgll.getCur();
        } else {
            cur1 = newcur;
        }
        String cur2 = NULLSTR;
        if (MdaUtils.isEmpty(newacccur) || ininflg) {
            cur2 = setgll.getAcccur();
        } else {
            cur2 = newacccur;
        }
        // calculating according to direction of setting crossrate in clcrat
        // if from currency is basecurrecy the rate is to be used for calclulation to target currency
        boolean dirflg = false;
        if (MdaUtils.compareTo(setgll.getCur(), setgll.getBascur()) == 0) {
            dirflg = false;
        } else {
            // if target currency is basecurrecy the rate is to be used for calclulation from from currency to bas currency
            if (MdaUtils.compareTo(setgll.getAcccur(), setgll.getBascur()) == 0) {
                dirflg = true;
            } else {
                // otherwise it is decided by XrtCrossRateDirFlg
                dirflg = xrtmodService.xrtCrossRateDirFlg(cur1, cur2, setgll.getDcbextrat(), setgll.getScbextrat());
            }
        }
        BigDecimal xrfBas = null;
        if (MdaUtils.compareTo(setgll.getAcccur(), xrtmodService.basRatCur()) == 0 || MdaUtils.compareTo(setgll.getCur(), xrtmodService.basRatCur()) == 0) {
            xrfBas = new BigDecimal("1");
        } else {
            xrfBas = xrtmodService.crossRatebas(setgll.getAcccur(), setgll.getCur());
        }
        switch (setgll.getModflg()) {
            case "T":
                break;
            case "b":
                if (MdaUtils.compareTo(setgll.getAcccur(), setgll.getCur()) == 0) {
                    setgll.setAmt(setgll.getAccamt());
                } else {
                    if (MdaUtils.compareTo(Strings.mid(setgll.getRattyp(), 2, 1), "X") == 0) {
                        if (dirflg) {
                            Argument<String> pathBox1 = new Argument<String>("", setgll.getBascur());
                            Argument<BigDecimal> pathBox2 = new Argument<BigDecimal>("", setgll.getBasamt());
                            setgll.setAmt(xrtmodService.amtConvRates(setgll.getAccamt(), setgll.getRat(), Decimals.div(1, xrfBas), setgll.getAcccur(), setgll.getCur(), pathBox1, pathBox2));

                            setgll.setBascur(pathBox1.value);
                            setgll.setBasamt(pathBox2.value);

                        } else {
                            Argument<String> pathBox3 = new Argument<String>("", setgll.getBascur());
                            Argument<BigDecimal> pathBox4 = new Argument<BigDecimal>("", setgll.getBasamt());
                            setgll.setAmt(xrtmodService.amtConvRates(setgll.getAccamt(), xrfBas, setgll.getRat(), setgll.getAcccur(), setgll.getCur(), pathBox3, pathBox4));

                            setgll.setBascur(pathBox3.value);
                            setgll.setBasamt(pathBox4.value);
                        }
                    } else {
                        Argument<String> pathBox5 = new Argument<String>("", setgll.getBascur());
                        Argument<BigDecimal> pathBox6 = new Argument<BigDecimal>("", setgll.getBasamt());
                        setgll.setAmt(xrtmodService.amtConvRates(setgll.getAccamt(), setgll.getScbextrat(), setgll.getDcbextrat(), setgll.getAcccur(), setgll.getCur(), pathBox5, pathBox6));

                        setgll.setBascur(pathBox5.value);
                        setgll.setBasamt(pathBox6.value);
                    }
                }
                break;
            default:
                if (MdaUtils.compareTo(setgll.getAcccur(), setgll.getCur()) == 0) {
                    setgll.setAccamt(setgll.getAmt());
                } else {
                    if (MdaUtils.compareTo(Strings.mid(setgll.getRattyp(), 2, 1), "X") == 0) {
                        if (dirflg) {
                            Argument<String> pathBox7 = new Argument<String>("", setgll.getBascur());
                            Argument<BigDecimal> pathBox8 = new Argument<BigDecimal>("", setgll.getBasamt());
                            setgll.setAccamt(xrtmodService.amtRndUnt(xrtmodService.amtConvRates(setgll.getAmt(), setgll.getRat(), Decimals.div(1, xrfBas), setgll.getCur(), setgll.getAcccur(), pathBox7, pathBox8), setgll.getAcccur()));

                            setgll.setBascur(pathBox7.value);
                            setgll.setBasamt(pathBox8.value);
                        } else {
                            Argument<String> pathBox9 = new Argument<String>("", setgll.getBascur());
                            Argument<BigDecimal> pathBox10 = new Argument<BigDecimal>("", setgll.getBasamt());
                            setgll.setAccamt(xrtmodService.amtRndUnt(xrtmodService.amtConvRates(setgll.getAmt(), xrfBas, setgll.getRat(), setgll.getCur(), setgll.getAcccur(), pathBox9, pathBox10), setgll.getAcccur()));

                            setgll.setBascur(pathBox9.value);
                            setgll.setBasamt(pathBox10.value);
                        }
                    } else {
                        Argument<String> pathBox11 = new Argument<String>("", setgll.getBascur());
                        Argument<BigDecimal> pathBox12 = new Argument<BigDecimal>("", setgll.getBasamt());
                        setgll.setAccamt(xrtmodService.amtRndUnt(xrtmodService.amtConvRates(setgll.getAmt(), setgll.getDcbextrat(), setgll.getScbextrat(), setgll.getCur(), setgll.getAcccur(), pathBox11, pathBox12), setgll.getAcccur()));

                        setgll.setBascur(pathBox11.value);
                        setgll.setBasamt(pathBox12.value);
                    }
                }
        }
    }

    /**
     * source:setgll.0024.script
     */
    public void recalcSetgllStdDft(SetgllVo setgll, SetmodVo setmod) {
        //! Standard defaults in lines
        // from default ROL
        //Codetables.setCodeValues(this,"rol",ctx.absGet(Setmod.class).getRoldsc());
        //Systems.setValues(this,"acccur",Dynamic.validCurrencies( Dates.today() ));
        //this.getXrtgetscb().setDissel( "X");
        //this.getXrtgetdcb().setDissel( "X");
        // from default DEBCDTFLG
        if (MdaUtils.compareTo(setgll.getAmt(), 0) < 0) {
            setgll.setDebcdtflg("C");
        } else {
            if (MdaUtils.compareTo(setgll.getAmt(), 0) == 0) {
                setgll.setRol(NULLSTR);
                setgll.setDebcdtflg(NULLSTR);
            } else {
                setgll.setDebcdtflg("D");
            }
        }
        // from default ROLACTLAB + ROLLAB
        if (MdaUtils.compareTo(setgll.getAmt(), 0) > 0) {
            setgll.setRolactlab("Payer's account");
            setgll.setRollab("Payer");
        } else {
            setgll.setRolactlab("Payee's account");
            setgll.setRollab("Payee");
        }
        // From default ROLPTXINR ( ROLPTYINR, ROLPTAINR, ACTPTYINR, ACTPTAINR )
        if (MdaUtils.isEmpty(setgll.getRol())) {
            setgll.setRolptyinr(NULLSTR);
            setgll.setRolptainr(NULLSTR);
            PtsptaVo ptsptaVo = new PtsptaVo();
            ptsptaVo.reset();
            setgll.getSetgrp().setRol(ptsptaVo);
        } else {
            int ptydetRow = setmodService.getPtyDetRow(setgll.getRol(), setmod);
            if (ptydetRow < 0) {
                PtsptaVo ptsptaVo = new PtsptaVo();
                ptsptaVo.reset();
                setgll.getSetgrp().setRol(ptsptaVo);
            } else {
                PtsFeeDetailVo ptsFeeDetail = setmod.getPtydet().get(ptydetRow);
                PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsptaFromPts(ptsFeeDetail);
                setgll.getSetgrp().setRol(ptsptaVo);
            }
        }
        // from default ACCAMT
        /*if( MdaUtils.compareTo(this.getModflg(),"T") == 0 || MdaUtils.compareTo(this.getRol(),ctx.absGet(Setmod.class).getFeeclirol()) != 0 ) {
            Systems.resetEnabled(this,"accamt");
        } else {
            Systems.setEnabled(this,"accamt");
        }*/
        // from default CORACTID
        if (Utils.isAccountTypNostro(setgll.getActrec().getTyp())) {
            setgll.setCoractid(setgll.getActrec().getSeracc());
        } else {
            setgll.setCoractid(setgll.getActrec().getHolacc());
        }
        // from default DET
        //! defaults Details Button
        // If forward contract, style is set to red.
        /*if( MdaUtils.isEmpty(this.getFchchkflg()) ) {
            // Platform.setTDStyle( "", $det );
        } else
        {
            // Platform.setTDStyle( "red", $det );
        }
        // If no role is set, the button is disabled
        if( MdaUtils.isEmpty(this.getRol()) ) {
            //Platform.disable( $det );
        } else {
            //Platform.enable( $det );
        }
        // from default FMTACCAMT
        // set FMTACCAMT from accamt and enable if role is set for this line
        if( MdaUtils.isEmpty(this.getRol()) || ( MdaUtils.compareTo(this.getAccamtfix(),"T") == 0 ) )
        {
            Systems.resetEnabled(this,"fmtaccamt");
        }
        else
        {
            Systems.setEnabled(this,"fmtaccamt");
        }*/
        setgll.setFmtaccamt(Numerics.abs(setgll.getAccamt()));
        // from default FMTAMT
        //! set FMTAMT from amt and enable if role is set for this line and conversion not set by transaction
        /*if( MdaUtils.isEmpty(this.getRol()) || ( MdaUtils.compareTo(this.getAccamtfix(),"T") == 0 ) ) {
            Systems.resetEnabled(this,"fmtamt");
        } else {
            Systems.setEnabled(this,"fmtamt");
        }*/
        setgll.setFmtamt(Numerics.abs(setgll.getAmt()));
        // from default INTACTID
        /*if( MdaUtils.compareTo(this.getIntp().getPansta(),PanStaEdit) == 0 && ( this.getSetgrp().getInt().isRolSet() ) ) {
            Systems.setEnabled(this,"intactid");
        } else {
            Systems.resetEnabled(this,"intactid");
            this.setIntactid("");
        }
        // from default ORIACTID
        if( MdaUtils.compareTo(this.getOrip().getPansta(),PanStaEdit) == 0 && ( this.getSetgrp().getOri().isRolSet() ) ) {
            Systems.setEnabled(this,"oriactid");
        } else {
            Systems.resetEnabled(this,"oriactid");
            this.setOriactid( "");
        }
        // from default SCBEXTRAT
        if( MdaUtils.compareTo(this.getScbrattyp(),"F") == 0 && MdaUtils.compareTo(this.getAcccur(),this.getCur()) != 0 ) {
            Systems.setEnabled(this,"scbextrat");
        } else {
            Systems.resetEnabled(this,"scbextrat");
        }
        // from default SCBSQRRAT
        if( MdaUtils.compareTo(this.getScbrattyp(),"F") == 0 && MdaUtils.compareTo(this.getAcccur(),this.getCur()) != 0 )
        {
            Systems.setTDStyle("red",this.getScbsqrrat());
            Systems.setEnabled(this,"scbsqrrat");
        }
        else
        {
            Systems.setTDStyle("",this.getScbsqrrat());
            Systems.resetEnabled(this,"scbsqrrat");
        }*/
        // default account parties
        //103报文的发报行check后自动清空
       /* String ptyinrsql = "select inr from pty where extkey = '" + ctx.absGet(Sysmod.class).getWrkbch().getSwfcod() + "'";
        String ptyinr = "";
        Argument<String> _ptyinrBox = Argument.box(ptyinr);
        ctx.getDaoSession().dbExecuteSQL(ptyinrsql);
        ctx.getDaoSession().dbFetchFields("",_ptyinrBox);
        ptyinr = _ptyinrBox.value;
        int err = ctx.getErrorCode();
        ctx.getDaoSession().dbCloseCursor();*/
        PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsptaFromPtyINR(setgll.getActrec().getHolptyinr());
        setgll.getSetgrp().setActhol(ptsptaVo);
        if (!setgll.getSetgrp().isModified("actser")) {
            ptsptaVo = ptsptaToolComponent.getPtsptaFromPtyINR(setgll.getActrec().getSerptyinr());
        } else {
            ptsptaVo = ptsptaToolComponent.getPtsptaFromPtyINR(setgll.getSetgrp().getActser().getPtyinr());
        }
        setgll.getSetgrp().setActser(ptsptaVo);
        if (Utils.isAccountTypNostro(setgll.getActrec().getTyp())) {
            ptsptaVo = ptsptaToolComponent.getPtsptaFromPtyINR(setgll.getActrec().getSerptyinr());
            setgll.getSetgrp().setApy(ptsptaVo);
        } else {
            //光大需求汇出汇款 收报行为业务经办行的swift
            //根据刘文青要求 光大所有103，202的收报行都为业务经办行的swift号
            //  $paytyp = GetContent( "\\\\cptp\\\\cpdgrp\\\\rec\\\\PAYTYP" )
            //  $err = ErrorCode
            //  if $paytyp = "O" then
            //
            /**
             PtsmodGetPtsptaFromPtyINR( SETGRP\\APY, $ptyinr )
             **/
            //收报行默认总行
            if (MdaUtils.isEmpty(setgll.getSetgrp().getApy().getExtkey())) {
                Pty pty = ptyCacheService.getOwnPty();
                if (pty != null) {
                    ptsptaVo = ptsptaToolComponent.getPtsptaFromPtyINR(pty.getInr());
                    setgll.getSetgrp().setApy(ptsptaVo);
                }
            }
            //  else
            // PtsmodGetPtsptaFromPtyINR( SETGRP\\APY, ACTREC\\HOLPTYINR )
            //  endif
        }
        // from default STRINF52LAB
        if (MdaUtils.compareTo(setgll.getAmt(), 0) > 0) {
            setgll.setStrinf52lab("Debit information");
        } else {
            setgll.setStrinf52lab("Payment information");
        }
        // from default STRINFCON1
        if ((!MdaUtils.isEmpty(setgll.getPaoflg())) && (Strings.pos(setgll.getSetgrp().getRol().getPtytyp(), "B") == 0) && MdaUtils.compareTo(setgll.getAccamt(), 0) < 0) {
            //Systems.resetEnabled(this,"strinfcon1");
            if ((!MdaUtils.isEmpty(setgll.getSetgrp().getAwi().getAdrblk()))) {
                if (MdaUtils.isEmpty(setgll.getDirindflg())) {
                    setgll.setStrinfcon1("REC");
                } else {
                    setgll.setStrinfcon1("ACC");
                }
            } else {
                setgll.setStrinfcon1("REC");
            }
        } else {
            //Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"strinfcon1") );
        }
        strINFERIset(setgll, setmod);
        // from default TXMGRP order 100
        setgll.setTxmgrp("SET" + setgll.getDsp());
        // from default VALDAT order 10000
        //! VALDAT has to be enabled for all types of settlement, if role is set
        /*if( MdaUtils.isEmpty(this.getRol()) )
        {
            Systems.resetEnabled(this,"valdat");
        }
        else
        {
            if( Strings.pos(ctx.absGet(Setmod.class).getDspflg(),"G") == 0 )
            {
                Systems.setEnabled(this,"valdat");
            }
            else
            {
                Systems.setEnabled(this,"valdat");
            }
        }*/
        // from default XRFAMT
        String bscur = NULLSTR;
        String newcur = NULLSTR;
        String newsys = NULLSTR;
        Boolean ininflg = null;
        BigDecimal sysrat = null;
        BigDecimal sqrrat = null;
        BigDecimal refamt = BigDecimal.ZERO;
        if (MdaUtils.compareTo(setgll.getAcccur(), setgll.getCur()) == 0) {
            setgll.setXrfamt(xrtmodService.basCurEqu(setgll.getCur(), setgll.getAmt(), Dates.today()));
        } else {
            bscur = xrtmodService.basRatCur();
            Argument<String> newcurBox = new Argument<String>();
            Argument<String> newsysBox = new Argument<String>();
            Argument<String> bscurBox = new Argument<String>("", bscur);
            Argument<Boolean> ininflgBox = new Argument<Boolean>();
            xrtmodService.xrtCheckInIn(setgll.getCur(), xrtmodService.sysiso(), newcurBox, newsysBox, bscurBox, ininflgBox);

            newcur = newcurBox.value;
            newsys = newsysBox.value;
            bscur = bscurBox.value;
            ininflg = ininflgBox.value;

            Argument<BigDecimal> sysratBox = new Argument<BigDecimal>();
            Argument<BigDecimal> sqrratBox = new Argument<BigDecimal>();
            xrtmodService.getRateXrt(xrtmodService.sysiso(), bscur, ininflg, "M", Dates.today(), sysratBox, sqrratBox);

            sysrat = sysratBox.value;
            sqrrat = sqrratBox.value;


            Argument<String> bscurBox1 = new Argument<String>("", bscur);
            Argument<BigDecimal> refamtBox = Argument.box(refamt);
            setgll.setXrfamt(xrtmodService.amtConvRates(setgll.getAmt(), setgll.getDcbextrat(), sysrat, setgll.getCur(), xrtmodService.sysiso(), bscurBox1, refamtBox));

            bscur = bscurBox1.value;
            refamt = refamtBox.value;

        }
        setgll.setXrfcur(xrtmodService.sysiso());
        // If temporary settlement is picked up, set style of MOD to blue
        /*if( MdaUtils.isEmpty(this.getGlpinr()) )
        {
            Systems.setTDStyle("",this.getModflg());
        }
        else
        {
            Systems.setTDStyle("blue",this.getModflg());
        }*/

    }

    /**
     * source:setgll.0047.script
     */
    public void strINFERIset(SetgllVo setgll, SetmodVo setmod) {
        String res = NULLSTR;
        String cr = NULLSTR;
        String amtinf = NULLSTR;
        String feeinf = NULLSTR;
        if (!MdaUtils.isEmpty(setgll.getPaoflg())) {
            res = "";
            cr = "";
            if (!MdaUtils.isEmpty(setgll.getPaoflg())) {
                amtinf = swiftGetERIOriAmt(setgll, setmod);
                if (!MdaUtils.isEmpty(amtinf)) {
                    res = res + cr + amtinf;
                    cr = CR;
                }
                feeinf = setfegService.swiftGetERIfee(setmod.getSetfeg(), setgll.getRol(), "X", setgll.getAcccur());
                if (!MdaUtils.isEmpty(feeinf) && false) {
                    res = res + cr + feeinf;
                    cr = CR;
                }
            }
            /**ist im Standard immer leer -> löschen ?
             if not IsEmpty( TLEBENFLG ) then
             $res = $res + $cr + "/TELEBEN/"
             $cr = CR
             endif
             **/
            if (!MdaUtils.isEmpty(setgll.getStrinf())) {
                res = res + cr + "/" + setgll.getStrinfcon1() + "/" + Strings.getLine(setgll.getStrinf(), 1);
                cr = CR;
                if (!MdaUtils.isEmpty(Strings.getLine(setgll.getStrinf(), 2))) {
                    res = res + cr + "//" + Strings.getLine(setgll.getStrinf(), 2);
                }
            }
            setgll.setStrinferi(res);
        } else {
            setgll.setStrinferi(NULLSTR);
        }

    }

    public String swiftGetERIOriAmt(SetgllVo setgll, SetmodVo setmod) {
        if (sumTabRowIsERI(setgll, setmod)) {
            return "/OCMT/" + setgll.getCur() + Utils.fmtAmountSwift(Numerics.abs(setgll.getAmt()), setgll.getCur()) + "/";
        } else {
            return "";
        }
    }

    public boolean sumTabRowIsERI(SetgllVo setgll, SetmodVo setmod) {
        boolean printERI = false;
        if (MdaUtils.compareTo(setgll.getAcccur(), setmod.getDoccur()) != 0 && MdaUtils.compareTo(setgll.getAcccur(), "EUR") == 0) {
            Cur cur = xrtmodService.getCurByCode(setmod.getDoccur());
            if (cur.getSeq() == -1) {
                printERI = true;
            }
        }
        return printERI;
    }

    /**
     * source:setgll.0049.script
     */
    public void recalcSetgllIsfDft(SetgllVo setgll, SetmodVo setmod) {
        //! Set installation specific fields (called from RecalcSetgll after common defaults are executed
        // from default ACCCUR
        // default account currency for old currency to new currency if currency is not blocked by transaction
        String newcur = NULLSTR;
        if (!setgll.isModified("acccur") && MdaUtils.compareTo(setgll.getDspflg(), "C") != 0 && MdaUtils.compareTo(setgll.getDspflg(), "A") != 0) {
            newcur = xrtmodService.getCurByCode(setgll.getAcccur()).getNewcur();
            if (!MdaUtils.isEmpty(newcur) && MdaUtils.compareTo(setgll.getAcccur(), newcur) != 0) {
                setgll.setAcccur(newcur);
            }
        }
        // from default AMT
        /*if( MdaUtils.compareTo(this.getModflg(),"T") == 0 || MdaUtils.compareTo(this.getRol(),ctx.absGet(Setmod.class).getFeeclirol()) != 0 )
        {
            Systems.resetEnabled(this,"amt");
        }
        else
        {
            Systems.setEnabled(this,"amt");
        }*/
        // from default ActpInclPansta ( ACTP\\PANSTA, SETGRP\\ACT )
        // default ACTP including PANSTA
        int ptydetRow = 0;
        String dftAct = NULLSTR;
        String dftActptainr = NULLSTR;
        String dftDsp = NULLSTR;
        String dftcur = NULLSTR;
        String frame = NULLSTR;
        String sta = null;
        PtsptaVo ptspta = null;
        switch (setgll.getDsp()) {
            case "DAC":
            case "IBC":
            case "DAD":
            case "IBD":
                ptspta = setgll.getSetgrp().getAct();
                ptspta.setPansta(PanStaShow);
                if (!MdaUtils.isEmpty(setgll.getSetgrp().getRol().getPtainr())) {
                    ptspta = ptsptaToolComponent.getPtsptaFromPtaINR(setgll.getSetgrp().getRol().getPtainr());
                    setgll.getSetgrp().setAct(ptspta);
                }
                //    SetModuleContent( SETGRP\\ACT, SETGRP\\ROL )
                break;
            case "IND":
            case "SID":
            case "INC":
                ptspta = setgll.getSetgrp().getAct();;
                ptspta.setPansta(PanStaShow);
                ptspta = ptsptaToolComponent.getPtsptaFromPtaINR(SettleContext.getUserEty().getOwnptainr());
                setgll.getSetgrp().setAct(ptspta);
                break;
            case "PAC":
            case "PAD":
            case "RTC":
            case "TGC":
            case "PAY":
                // type set directly in SETGRP\\ACT to B
                setgll.getSetgrp().getAct().setPansta(PanStaEdit);
                setgll.getSetgrp().getOri().setPansta(PanStaEdit);
                ptydetRow = setmodService.getPtyDetRow(setgll.getRol(), setmod);
                if (ptydetRow < 0) {
                    dftAct = "";
                    dftActptainr = "";
                    dftDsp = "";
                    dftcur = "";
                } else {
                    PtsFeeDetailVo ptsFeeDetail = setmod.getPtydet().get(ptydetRow);
                    dftAct = ptsFeeDetail.getDftact();
                    dftActptainr = ptsFeeDetail.getDftactptainr();
                    dftDsp = ptsFeeDetail.getDftdsp();
                    dftcur = ptsFeeDetail.getDftcur();
                }
                if (MdaUtils.compareTo(setgll.getAcccur(), dftcur) == 0 && MdaUtils.compareTo(setgll.getDsp(), dftDsp) == 0 && (!MdaUtils.isEmpty(dftActptainr))) {
                    ptspta = ptsptaToolComponent.getPtsptaFromPtaINR(dftActptainr);
                    setgll.getSetgrp().setAct(ptspta);
                    //Dynamic.ptsmodGetPtsptaFromPtaINR( this.getSetgrp().getAct(), this.getSetgrp().getRol().getPts().getDftactptainr() );
                }
                break;
            default:
                frame = SettleContext.getTransName();
                sta = PanStaShow;
                if (MdaUtils.compareTo(setgll.getDebcdtflg(), "D") == 0) {
                    switch (frame) {
                        case "TRTSET":
                        case "BPTSET":
                            if (!MdaUtils.isEmpty(setgll.getAct3flg())) {
                                sta = PanStaEdit;
                            }
                            break;
                    }
                }
                setgll.getSetgrp().getAct().setPansta(sta);
        }
        // from default ACTPRIFLG
        /*if( MdaUtils.compareTo(Strings.mid(this.getDsp(),1,2),"PA") == 0 ) {
            Systems.setVisible(this,"actpriflg");
            Systems.setEnabled(this,"actpriflg");
        } else {
            Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"actpriflg") );
            Systems.resetVisible(this,"actpriflg");
        }*/
        // Account with Institution is needed for field 57 in MT n91
        // DETAWI - Detailspanel Account with Institution
        /*if( ( MdaUtils.compareTo(this.getDsp(),"PAD") == 0 || MdaUtils.compareTo(this.getDsp(),"IND") == 0 ) && MdaUtils.compareTo(this.getRol(),"OWN") != 0 ) {
            Systems.setVisible(this,"detawi");
            Systems.resetVisible(this,"det52");
        } else {
            Systems.resetVisible(this,"detawi");
            // from default DET52
            if( MdaUtils.compareTo(Strings.mid(this.getDsp(),1,2),"IN") == 0 && MdaUtils.compareTo(this.getRol(),"OWN") != 0 ) {
                Systems.setVisible(this,"det52");
            } else {
                Systems.resetVisible(this,"det52");
            }
        }*/
        recalcSetGllPaoDft(setgll);
        recalcSetGllStrinfDft(setgll);
        defaultSFTMT(setgll, setmod);
        sespayService.recalcSesPay(setgll,setmod);
        //this.getSespay().recalcIZV ( this );
        // 解决第一次Check报科目代码为空的问题
        //Modules.postDefaultRule(this,"acttrmtyp");
        setActtrmtypAndActflg(setgll);
        if( MdaUtils.isEmpty(setgll.getFcdinr())
                && MdaUtils.compareTo(setgll.getDspflg(),"C") != 0 && MdaUtils.compareTo(setgll.getDspflg(),"A") != 0 ) {
            //不做任何操作
        } else {
            setgll.setDisable("acccur");
        }
        //@Default(target="acccur",order=1000)
        List<CodetableItem> acccurSet = new ArrayList<>();
        if (StringUtils.isNotEmpty(setgll.getCur())) {
            if ("CNY".equals(setgll.getCur())) {
                acccurSet = xrtmodService.validCurrencies();
            } else {
                acccurSet.add(new CodetableItem(codetableService.getTblLabel("CNY", "CURTXT"), "CNY"));
                acccurSet.add(new CodetableItem(codetableService.getTblLabel(setgll.getCur(), "CURTXT"), setgll.getCur()));
            }
        }
        setgll.setAcccurSet(acccurSet);

    }

    /**
     * @Default(value={"acttrmtyp","actflg"},order=1000)
     * @param setgll
     */
    public void setActtrmtypAndActflg(SetgllVo setgll) {
        String act = setgll.getAct();
        if (StringUtils.isEmpty(act)) {
            setgll.setActflg("N");
            setgll.setActtrmtyp("");
            setgll.setDisable("acttrmtyp");
        } else {
            setgll.setActflg("M");
            String trmcod = actMapper.getTxmcodByExtkey(act);
            if (StringUtils.isEmpty(trmcod)) {
                String termid = "";
                String termid2 = "";
                if(act.length() == 20) {
                    termid = Strings.mid(act,10,4);
                    termid2 = Strings.mid(act,10,2);
                }
                if( act.length() == 17 ) {
                    termid = Strings.mid(act,7,4);
                    termid2 = Strings.mid(act,7,2);
                }
                if( act.length() == 21 ) {
                    termid = Strings.mid(act,12,4);
                    termid2 = Strings.mid(act,12,2);
                }
                List<CodetableItem> acttrmtypSet = new ArrayList<>();
                List<Trm> trmList = actmodComponent.getActTermCode(setgll.getDsp());
                if (trmList != null) {
                    trmList.forEach(trm -> {
                        CodetableItem item = new CodetableItem();
                        item.setValue(trm.getTrmcod());
                        item.setLabel(trm.getTrmtyp() + " " + trm.getNam());
                        acttrmtypSet.add(item);
                    });
                }
                setgll.setActtrmtypSet(acttrmtypSet);
                setgll.resetDisable("acttrmtyp");
                if( StringUtils.isNotEmpty(termid) && !setgll.isModified("acttrmtyp")) {
                    setgll.setActtrmtyp(termid);
                    /**
                     if ACTTRMTYP == "8800" then
                     **/
                    if( MdaUtils.compareTo(termid,"8800") == 0 || MdaUtils.compareTo(termid2,"88") == 0 || MdaUtils.compareTo(termid2,"80") == 0 ) {
                        setgll.setActtrmtyp("");
                    }
                }
            } else {
                setgll.setActtrmtyp(trmcod);
                setgll.setDisable("acttrmtyp");
            }
        }
    }

    /**
     * source:setgll.0041.script
     */
    public void defaultSFTMT(SetgllVo setgll, SetmodVo setmod) {
        //! Checks the criteria in which payment messages can be created depending on dispo code from settlement
        //! and sets the SFTMT to the value for messages to be created.
        switch (setgll.getDsp()) {
            case "PAC":
            case "RTC":
            case "TGC":
            case "PAY":
                // no creation of payment messages for amount zero and for debits
                if (MdaUtils.compareTo(setgll.getAcccpramt(), 0) >= 0) {
                    /*Systems.resetVisible(this,"detpay");
                    Systems.resetVisible(this,"detpay1");
                    Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"sftmt") );
                    Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"dirindflg") );*/
                    setgll.setSftmt("");
                    setgll.setDirindflg("");
                }
                break;
            case "DAC":
                // no creation of payment messages for temporary settlement and for debits.
                // and only allowed, if allowed MT set from RegisterSettlement
                if (MdaUtils.compareTo(setgll.getAcccpramt(), 0) >= 0 || MdaUtils.isEmpty(setfegService.getFeeSet().getSetpty(setgll.getRol()).getAvbmt())) {
                    /*Systems.resetVisible(this,"detpay");
                    Systems.resetVisible(this,"detpay1");
                    Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"sftmt") );
                    Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"dirindflg") );*/
                    setgll.setSftmt("");
                    setgll.setDirindflg("");
                } else {
                    setgll.setDirindflg("X");
                }
                break;
            case "IZC":
            case "IZD":
                // no creation of payment messages for temporary settlement and for zero amount to be settled
                if (MdaUtils.compareTo(setgll.getAcccpramt(), 0) == 0) {
                    /*Systems.resetVisible(this,"detpay");
                    Systems.resetVisible(this,"detpay1");
                    Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"sftmt") );
                    Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"dirindflg") );*/
                    setgll.setSftmt("");
                    setgll.setDirindflg("");
                }
                break;
            default:
                // in all other cases: no payment message possible
                /*Systems.resetVisible(this,"detpay");
                Systems.resetVisible(this,"detpay1");
                Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"sftmt") );
                Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"dirindflg") );*/
                setgll.setSftmt("");
                setgll.setDirindflg("");
                return;
        }
        String transName = SettleContext.getDirectTransName();
        // set flags for creation of payment message. If flags set, SESPAY is active, otherwise not
        //! If RTGSPlus, show always MT103
        while (true) {
            // check, if there are settings for special message types from registersettlement/SetPtyAvbMt
            //Platform.readSetPtyfromCache(this.getRol(),ctx.absGet(Setmod.class).getSetpty());
            boolean doit = false;
            // special message types 400 and/or 756 only possible, if
            // currency in line not changed or In-In settlement (i.e. DEM/EUR)
            String refcur = NULLSTR;
            String newcur1 = NULLSTR;
            String newcur2 = NULLSTR;
            Boolean ininflg = null;
            Setpty setpty = setfegService.getFeeSet().getSetpty(setgll.getRol());
            if (setpty != null && !MdaUtils.isEmpty(setpty.getAvbmt())) {
                if (MdaUtils.compareTo(setgll.getAcccur(), setgll.getCur()) == 0) {
                    doit = true;
                } else {
                    refcur = xrtmodService.sysiso();
                    Argument<String> newcur1Box = new Argument<String>();
                    Argument<String> newcur2Box = new Argument<String>();
                    Argument<String> refcurBox = new Argument<String>("", refcur);
                    Argument<Boolean> ininflgBox = new Argument<Boolean>();
                    xrtmodService.xrtCheckInIn(setgll.getAcccur(), setgll.getCur(), newcur1Box, newcur2Box, refcurBox, ininflgBox);

                    newcur1 = newcur1Box.value;
                    newcur2 = newcur2Box.value;
                    refcur = refcurBox.value;
                    ininflg = ininflgBox.value;

                    if (ininflg) {
                        doit = true;
                    }
                }
            }
            if (doit && !"CNY".equals(setgll.getCur())) {
                // only the message types set by SetPtyAvbMt are valid, 103/202 should be set explicitely in registersettlement, if allowed
                //Systems.setValues(this,"sftmt",ctx.absGet(Setmod.class).getSetpty().getAvbmt());
                Assert.notNull(setpty);
                if (MdaUtils.isEmpty(Strings.getLine(setpty.getAvbmt(), 2))) {
                    setgll.setSftmt(Strings.getLine(setpty.getAvbmt(), 1));
                } else {
                    /*Systems.setEnabled(this,"sftmt");*/
                    if (!setgll.isModified("sftmt")) {
                        setgll.setSftmt(Strings.getLine(setpty.getAvbmt(), 1));
                    }

                }
            } else {
                //主界面报文类型为主
                String sfttyp = setmod.getRec().getSwftyp();
                //需求变更swift升级后仍需单发202
                if (MdaUtils.compareTo(sfttyp, "200") == 0) {
                    sfttyp = "202";
                }
                setgll.setSftmt(sfttyp);

                // 汇出汇款 且 报文类型为202COV  ==> 出103报文
                if ("CPTOPN".equalsIgnoreCase(transName) && "202".equalsIgnoreCase(setmod.getRec().getSwftyp())) {
                    setgll.setSftmt("103");
                }
            }
            //特殊交易特殊处理
            if (MdaUtils.compareTo(transName, "GITSET") == 0 || MdaUtils.compareTo(transName, "GITPSE") == 0 || MdaUtils.compareTo(transName, "NITSET") == 0 || MdaUtils.compareTo(transName, "NITPSE") == 0) {
                setgll.setSftmt("756");
            }
            if (MdaUtils.compareTo(transName, "BETSET") == 0) {
                setgll.setSftmt("202");
            }
            if (MdaUtils.compareTo(transName, "BTTSET") == 0) {
                setgll.setSftmt("202");
            }
            //如果是国内索赔赔付 走CIPS清算系统 则sftmt=CIV
            if("NITSET|NITPSE|GITSET|GITPSE".indexOf(transName.toUpperCase())>-1){
                String cmtflg = Utils.getFieldValue(setmod.getRec(), "cmtflg");
                String sfttyp = Utils.getFieldValue(setmod.getRec(), "swftyp");
                if (StringUtils.isNotEmpty(cmtflg) && StringUtils.isNotEmpty(sfttyp)) {
                    setgll.setSftmt(sfttyp);
                }

                //人民币不出头寸
                String cur = setmod.getDoccur();
                if(StringUtils.isNotEmpty(cur)&&"CNY".equals(cur)&&(setgll.getSftmt().equals("202")||setgll.getSftmt().equals("756"))){
                    setgll.setSftmt("");
                }
            }
            //所有的收费交易发202与756
            if (MdaUtils.compareTo(Strings.mid(transName, 4, 3), "FEE") == 0) {
                setgll.setSftmt("756");
            }
            //--------end------------------------
            //同业代付还款时
            //我行风险参与是出202
            String fintyp = NULLSTR;
            String msgtyp = NULLSTR;
            if (MdaUtils.compareTo(transName, "DFTSET") == 0) {
                fintyp = Utils.getFieldValue(setmod.getRec(), "fintyp");
                msgtyp = setmod.getRec().getSwftyp();
                if (MdaUtils.compareTo(fintyp, "B") == 0) {
                    //还需判断币种
                    if (MdaUtils.compareTo(msgtyp, "202") == 0) {
                        setgll.setSftmt("756");
                    } else {
                        setgll.setSftmt("");
                    }
                }
            }
            if (MdaUtils.compareTo(transName, "DFTMSG") == 0) {
                msgtyp = setmod.getRec().getSwftyp();
                if (MdaUtils.compareTo(msgtyp, "202") == 0) {
                    setgll.setSftmt("756");
                }
            }
            /**
             if Pos( "-GITSET-BRTSET-BCTSET-DFTMSG-", GetFramename ) > 0 then
             $cmtflg = GetContent( "\\\\TRNMOD\\\\CMTFLG" )
             if $cmtflg == "P" then
             SFTMT = GetContent( "\\\\TRNMOD\\\\SWFTYP" )
             endif
             endif
             **/
            break;
        }
        if ("OTH".equals(setgll.getSftmt())) {
            setgll.setSftmt("");
            setgll.setDirindflg("");
            return;
        }
        // ####### 改写 LABEL与GOTO   ####    label setdirindflg
        //! If a special MT is sent (not 202 or 103), it has to be indirect to ensure sending of special message to beneficiary
        // if authorisation for rembourse, no 202
        //由于光大银行的帐户行的帐号不在国结维护
        //因此SETGRP\\ACTSER\\PTA\\INR是没有值的,所以DIRINDFLG = x
        //将DIRINDFLG放开，报文都显示在MSG页面，有业务员手工去调整发不发送
        //if IsEmpty( SETGRP\\ACTSER\\PTA\\INR ) or SETGRP\\ACTSER\\PTA\\INR = SETGRP\\BEI\\PTA\\INR or SETGRP\\ACTSER\\PTA\\BIC = SETGRP\\BEI\\PTA\\BIC then
        // if not IsModified( DIRINDFLG ) then
        //   DIRINDFLG = "X"
        // endif
        //else
        if (setgll.getSftmt() == null) {
            setgll.setSftmt("");
        }
        switch (setgll.getSftmt()) {
            case "103":
            case "202":
                if (MdaUtils.compareTo(setgll.getDsp(), "TGC") == 0) {
                    setgll.setDirindflg("X");
                    //Systems.resetEnabled(this,"dirindflg");
                } else {
                    //汇款单独处理-------------------
                    //新增的电商支付交易CPTECO，与原汇款逻辑保持一致
                    /**
                     if GetFramename == "CPTADV" or GetFramename == "CPTOPN" or GetFramename == "BTTSET" or GetFramename == "BETSET" then
                     **/
                    /**
                     if GetFramename == "CPTADV" or GetFramename == "CPTOPN" or GetFramename == "BTTSET" or GetFramename == "BETSET" or GetFramename == "CPTECO" then
                     **/
                    if (MdaUtils.compareTo(transName, "CPTADV") == 0 || MdaUtils.compareTo(transName, "CPTOPN") == 0 || MdaUtils.compareTo(transName, "BTTSET") == 0 || MdaUtils.compareTo(transName, "BETSET") == 0 || MdaUtils.compareTo(transName, "CPTECO") == 0 || MdaUtils.compareTo(transName, "CPTECI") == 0 || MdaUtils.compareTo(transName, "NITSET") == 0 || MdaUtils.compareTo(transName, "NITPSE") == 0) {
                        setgll.setDirindflg("X");
                    }
                    //如果是202也支持单发
                    if ("BCTSET".equals(transName)) {
                        setgll.setDirindflg("X");
                    }
                }
                break;
            case "IZV":
                setgll.setDirindflg("X");
                /**
                 case "100", "CMT"
                 **/
                //20180330，解决生产环境问题，cptopn交易MT202报文转为hvps或者cips时，Pay 202页签未隐藏，所以显示两种报文
                /**
                 case "100", "CMT", "HVP", "HVQ", "CIU", "CIV", "CIW"
                 **/
                break;
            case "100":
            case "CMT":
            case "HVP":
            case "HVQ":
            case "HVR":
            case "CIU":
            case "CIV":
            case "CIW":
            case "111":
            case "112":
                setgll.setDirindflg("X");
                break;
            default:
                if (MdaUtils.compareTo(setgll.getSetgrp().getActser().getPtainr(), setgll.getSetgrp().getBei().getPtainr()) == 0) {
                    if (!setgll.isModified("dirindflg")) {
                        setgll.setDirindflg("X");
                    }
                } else {
                    setgll.setDirindflg("");
                }
                //代收付款出400+202cover
                if (MdaUtils.compareTo(setgll.getSftmt(), "400") == 0) {
                    setgll.setDirindflg("");
                }
                //保函赔付交易出756+202cover
                if (MdaUtils.compareTo(setgll.getSftmt(), "756") == 0) {
                    setgll.setDirindflg("");
                }
        }
    }

    /**
     * source:setgll.0046.script
     */
    public void recalcSetGllPaoDft(SetgllVo setgll) {
        // Set payment order flag ( from default PAOFLG)
        if (MdaUtils.compareTo(setgll.getAmt(), 0) >= 0) {
            //Systems.resetVisible(this,"paoflg");
            //Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"paoflg") );
            if (MdaUtils.compareTo(Strings.mid(setgll.getDsp(), 1, 2), "PA") == 0) {
                if (Utils.isAccountTypNostro(setgll.getActrec().getTyp())) {
                    setgll.setPaoflg("X");
                }
            }
        } else {
            //Systems.setVisible(this,"paoflg");
            if (MdaUtils.compareTo(setgll.getRolptyinr(), setgll.getActrec().getSerptyinr()) == 0 || MdaUtils.compareTo(setgll.getRolptyinr(), setgll.getActrec().getHolptyinr()) == 0) {
                //Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"paoflg") );
                setgll.setPaoflg("");
            } else {
                switch (Strings.mid(setgll.getDsp(), 1, 2)) {
                    case "SI":
                    case "RT":
                    case "TG":
                        //Systems.resetEnabled(this,"paoflg");
                        setgll.setPaoflg("X");
                        break;
                    case "PA":
                        if (MdaUtils.compareTo(Strings.mid(setgll.getSetgrp().getRol().getAdr().getBic(), 1, 6), Strings.mid(setgll.getSetgrp().getApy().getAdr().getBic(), 1, 6)) == 0 && (!MdaUtils.isEmpty(setgll.getSetgrp().getRol().getAdr().getBic()))) {
                            //Systems.setEnabled(this,"paoflg");
                            if (!setgll.isModified("paoflg")) {
                                setgll.setPaoflg("");
                            }

                        } else {
                            if (MdaUtils.compareTo(Strings.mid(setgll.getSetgrp().getRol().getAdr().getBic(), 1, 4), Strings.mid(setgll.getSetgrp().getApy().getAdr().getBic(), 1, 4)) == 0 && (!MdaUtils.isEmpty(setgll.getSetgrp().getRol().getAdr().getBic()))) {
                                /*Systems.setEnabled(this,"paoflg");*/
                                if (!setgll.isModified("paoflg")) {
                                    setgll.setPaoflg("X");
                                }
                            } else {
                                //Systems.resetEnabled(this,"paoflg");
                                setgll.setPaoflg("X");
                            }
                        }
                        break;
                    default:
                        //Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"paoflg") );
                        setgll.setPaoflg("");
                }
            }
        }
    }

    /**
     * source:setgll.0050.script
     */
    public void recalcSetGllStrinfDft(SetgllVo setgll) {
        // from default STRINF
        if (!MdaUtils.isEmpty(setgll.getStrinfcon1())) {
            //Systems.setEnabled(this,"strinf");
        } else {
            //Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"strinf") );
            setgll.setStrinf("");
        }
        // from default STRINF52
        if (MdaUtils.compareTo(Strings.mid(setgll.getDsp(), 1, 2), "IN") == 0 && Strings.pos(setgll.getSetgrp().getRol().getPtytyp(), "A") == 0) {
            //Systems.setEnabled(this,"strinf52");
        } else {
            //Dynamic.disableAndClearField( MdaDriver.getDatafield(this,"strinf52") );
            setgll.setStrinf52("");
        }

    }

    /**
     * source:setgll.0051.script
     */
    public String generateCprMac(SetgllVo setgll) {
        //! Returns MAC for amount compression in ACCCPRAMT.
        // Usually this is the MAC to the relevant party, account currency and value date
        // You may use ROLPTYINR instead of ROL of entries of different roles for same party shall be compressed (correspondence have to be adapted too in that case)
        String str = setgll.getRol() + setgll.getAcccur() + setgll.getAct() + Utils.fmtDate(setgll.getValdat()) + setgll.getSftmt();
        return Systems.macGen(str, 0);
    }

    /**
     *   source:setgll.0076.script
     *   @Default(target="txt2",order=1000)
     */
    public void getTxt2(SetgllVo setgll){
        if(!setgll.isModified("txt2")) {
            String txt2 = "";
            if( MdaUtils.compareTo(SettleContext.getTransName(),"FCTOPN") == 0 ) {
                txt2 = "保证金收取" + setgll.getTxt() + setgll.getTxt1();
            } else {
                txt2 += setgll.getTxt() + "#" + setgll.getTxt1();
            }
            setgll.setTxt2(txt2);
        }
    }

    @Override
    public List getAvailAccts(SetgllVo setgll, SetmodVo setmod) {
        String actptainr = getACTPTAINR(setgll, setmod, setgll.getDsp());
        Pta pta = ptaCacheService.getPtaByInr(actptainr);
        String actptyinr = Optional.ofNullable(pta).map(tPta -> tPta.getPtyinr()).orElse("");

        String actlst = glemodService.getAvailAcc(setgll.getDsp(), setgll.getAcccur(), actptyinr, setgll.getAmt());
        IStream actval = new StreamImpl();
        Streams.streamSet(actval, actlst);

        List<Map<String, String>> acctCodeItems = Lists.newArrayList();
        for (int idx = 1, cnt = Streams.streamCount(actval); idx <= cnt; idx++) {
            String acctItm = Strings.getLine(actval, idx);
            Map<String, String> mpCodeItm = new ImmutableMap.Builder<String, String>()
                    .put("value", acctItm).put("label", acctItm).build();
            acctCodeItems.add(mpCodeItm);
        }

        return acctCodeItems;
    }


    /**
     *   source:setgll.0087.script
     *   @Default(target="txt",order=1000)
     */
    public void getTxt(SetgllVo setgll, SetmodVo setmod){
        String ownref = NULLSTR;
        String pntRef = NULLSTR;
        String frame = NULLSTR;
        String ref = NULLSTR;
        String contentnum = NULLSTR;
        String txt = "";
        String transName = SettleContext.getTransName();
        if(!setgll.isModified("txt")) {
            if(MdaUtils.compareTo(Strings.mid(transName,1,3),"MCT") == 0 ) {
                ownref = setmod.getRec().getSubref();
            } else {
                ownref = setmod.getRec().getOwnref();
            }
            String pntTyp = setmod.getRec().getPnttyp();
            String pntInr = setmod.getRec().getPntinr();
            pntRef = "";
            if(!MdaUtils.isEmpty(pntTyp) && !MdaUtils.isEmpty(pntInr)) {
                String parentRef = dyncDaoService.dyncReadFieldByInr(pntTyp, pntInr, "ownref");
                if (StringUtils.isNotEmpty(parentRef)) {
                    pntRef = " " + parentRef;
                }
            }
            txt = ownref + pntRef;
            if(MdaUtils.compareTo(setgll.getAcccur(), setgll.getCur()) != 0 ) {
                txt += " " + MdaUtils.toString(setgll.getRat()) + " " + setgll.getCur() + " " + Utils.fmtAmount(Numerics.abs(setgll.getAmt()),setgll.getCur());
            }
            //2017/09刘文青要求将ref存入传票摘要框中
            frame = SettleContext.getDirectTransName();
            if( MdaUtils.compareTo(frame,"BOTSET") == 0 ) {
                PtsptaVo ptspta = ptsptaToolComponent.getPtsFromListByRol(setmod.getPtsList(), "DRR");
                if (ptspta != null) {
                    ref = ptspta.getRef();
                }
                /**
                 TXT = TXT + " 客户Ref No." + $ref
                 **/
                txt += CR + "#客户Ref No." + ref;
            }
            if( MdaUtils.compareTo(frame,"BETSET") == 0 ) {
                PtsptaVo ptspta = ptsptaToolComponent.getPtsFromListByRol(setmod.getPtsList(), "BEN");
                if (ptspta != null) {
                    ref = ptspta.getRef();
                }
                txt += CR + "#客户Ref No." + ref;
            }
            // 汇出汇入、境内外币汇出汇入、电商汇出汇入  传票摘要中增加对手名称+账号+对手行行号
            if( Strings.pos("-CPTOPN-CPTADV-CPTATO-CPTATI-CPTECO-CPTECI-",frame) != 0 ) {
                txt += getNamAccBnkForHuiDan(setgll,setmod);
            }
            //进口信用证单据付款交易传票摘要中增加合同号
            if( MdaUtils.compareTo(frame,"BRTSET") == 0 ) {
                contentnum = dyncDaoService.dyncReadFieldByInr(setmod.getRec().getObjtyp(), setmod.getRec().getObjinr(), "rptref");
                //contentnum = Utils.getFieldValue(setmod.getRec(), "rptref");
                if(!MdaUtils.isEmpty(contentnum)) {
                    txt += CR + "#" + contentnum;
                }
            }
            if ("BPTOPN".equals(frame)) {
                if ("C".equals(setgll.getDebcdtflg()) && "FIA".equals(setgll.getRol())) {
                    String fintyp = Utils.getFieldValue(setmod.getRec(), "fintyp", "");
                    String label = codetableService.getTblLabel(fintyp, "BPDTYP", "CN");
                    if (StringUtils.isNotEmpty(label)) {
                        txt += "#" + label + "融资款项";
                    }
                    String inttyp = Utils.getFieldValue(setmod.getRec(), "inttyp", "");
                    BigDecimal intAmt = Utils.getFieldValue(setmod.getRec(), "intamt", BigDecimal.ZERO);
                    if ("0".equals(inttyp) && intAmt.compareTo(BigDecimal.ZERO) != 0) {
                        txt += "#" + "预扣息金额 " + setmod.getDoccur() + Utils.fmtAmount(intAmt,setmod.getDoccur());
                    }
                }
            }
            setgll.setTxt(txt);
        }
    }

    /**
     * 汇出汇入、境内外币汇出汇入、电商汇出汇入  传票摘要中增加对手名称+账号+对手行行号
     * @param setgll
     * @param setmod
     * @return
     */
    private String getNamAccBnkForHuiDan(SetgllVo setgll, SetmodVo setmod) {
        String transName = SettleContext.getTransName();
        String oppnam = "";
        String oppacc = "";
        String oppbnk = "";
        String txt = "";
        CpdBizInfoVo cpdBizInfoVo = (CpdBizInfoVo) setmod.getRec();
        String cptrou = cpdBizInfoVo.getCptrou();
        //汇入汇款
        String ptytyp = NULLSTR;
        if (MdaUtils.compareTo(transName, "CPTADV") == 0 && ("SWIFT".equals(cptrou) || "CIPS".equals(cptrou) || "OTHER".equals(cptrou))) {
            oppnam = cpdBizInfoVo.getOrcnam(); //Datas.getContent(this,"\\CPTP\\ORCNAM");
            oppacc = cpdBizInfoVo.getOrcact(); //Datas.getContent(this,"\\CPDGRP\\REC\\orcact");
            ptytyp = cpdBizInfoVo.getSndptytyp(); //Datas.getContent(this,"\\CPDGRP\\SND\\PTA\\PTYTYP");
            if (MdaUtils.compareTo(ptytyp, "B") == 0) {
                oppbnk = cpdBizInfoVo.getSndbch(); //Datas.getContent(this,"\\CPDGRP\\SND\\PTA\\BIC");
            }
        }
        //汇出汇款
        if (MdaUtils.compareTo(transName, "CPTOPN") == 0) {
            if ("JNWB".equals(cptrou)) {
                oppnam = Utils.getFieldValue(cpdBizInfoVo, "cpdJnwbBizInfo//pyenam", "");
                oppacc = cpdBizInfoVo.getPyeact();
                for (int i=0; i<setmod.getSetglg().getSetgll().size(); i++) {
                    SetgllVo tmpSetgll = setmod.getSetglg().getSetgll().get(i);
                    if ("111".equals(tmpSetgll.getSftmt()) || "112".equals(tmpSetgll.getSftmt())) {
                        FxpmodVo fxpmodVo = tmpSetgll.getSespay().getFxpmod();
                        if (fxpmodVo != null) {
                            oppbnk = fxpmodVo.getResbch();
                        }
                    }
                }
            } else {
                //SWIFT CIPS HNHZ
                oppnam = cpdBizInfoVo.getPyenam();
                oppacc = cpdBizInfoVo.getPyeact();
                for (int i=0; i<setmod.getSetglg().getSetgll().size(); i++) {
                    PtsptaVo awi = setgll.getSetgrp().getAwi();
                    if (awi != null) {
                        Adr adr = adrCacheService.selectByPtaInr(awi.getPtainr());
                        if (adr != null && StringUtils.isNotEmpty(adr.getBic())) {
                            oppbnk = adr.getBic();
                            break;
                        }
                    }
                }
            }
        }
        //境内外币汇入汇款
        if (MdaUtils.compareTo(transName, "CPTADV") == 0 && ("JNWB".equals(cptrou) || "HNHZ".equals(cptrou))) {
            oppnam = cpdBizInfoVo.getOrcnam(); //Datas.getContent(this, "\\ATTP\\ORCNAM");
            oppacc = cpdBizInfoVo.getOrcact(); //Datas.getContent(this, "\\CPDGRP\\REC\\orcact");
            oppbnk = cpdBizInfoVo.getSndbch(); //Datas.getContent(this, "\\ATTP\\SNDBCH");
        }
        //电商汇入汇款
        //todo
//        if (MdaUtils.compareTo(transName, "CPTECI") == 0) {
//            oppnam = Datas.getContent(this, "\\CPTP2\\ORCNAM");
//            oppacc = Datas.getContent(this, "\\CPDGRP\\REC\\orcact");
//            ptytyp = Datas.getContent(this, "\\CPDGRP\\SND\\PTA\\PTYTYP");
//            if (MdaUtils.compareTo(ptytyp, "B") == 0) {
//                oppbnk = Datas.getContent(this, "\\CPDGRP\\SND\\PTA\\BIC");
//            }
//        }
        //电商汇出汇款
        //todo
//        if (MdaUtils.compareTo(transName, "CPTECO") == 0) {
//            oppnam = Datas.getContent(this, "\\CPTP1\\PYENAM");
//            oppacc = Datas.getContent(this, "\\CPDGRP\\REC\\pyeact");
//            /**
//             if \\TRNMOD\\DOCIMM\\PTA\\PTYTYP == "B" then
//             $oppbnk = GetContent( "\\\\TRNMOD\\\\DOCIMM\\\\PTA\\\\BIC" )
//             endif
//             **/
//            for (int i = 1; i <= Grids.gridCount(ctx.absGet(Setmod.class).getSetglg().getSetgll()); i++) {
//                if (MdaUtils.compareTo(ctx.absGet(Setmod.class).getSetglg().getSetgll().getElement(i).getSespay().getAwip().getPtspta().getAdr().getBic(), "") != 0) {
//                    oppbnk = ctx.absGet(Setmod.class).getSetglg().getSetgll().getElement(i).getSespay().getAwip().getPtspta().getAdr().getBic();
//                }
//            }
//        }
        txt = CR + "#" + oppnam;
        if (!MdaUtils.isEmpty(oppacc)) {
            txt = txt + CR + "#" + oppacc;
            if (!MdaUtils.isEmpty(oppbnk)) {
                txt = txt + " " + oppbnk;
            }
        } else {
            if (!MdaUtils.isEmpty(oppbnk)) {
                txt = txt + "#" + oppbnk;
            }
        }
        return txt;

    }

    /**
     *   source:setgll.0088.script
     *   @Default(target="txt1",order=1000)
     */
    public void getTxt1(SetgllVo setgll, SetmodVo setmod){
        String rol = setgll.getRol();
        String text = NULLSTR;
        if (StringUtils.isEmpty(rol)) {
            return;
        }
        int index = setmodService.getPtyDetRow(rol, setmod);
        if (index >= 0) {
            PtsFeeDetailVo ptsFeeDetailVo = setmod.getPtydet().get(index);
            //BPTOPN 贷记 外扣 不需要费用
            if (ptsFeeDetailVo != null && "F".equals(ptsFeeDetailVo.getGlggrpflg())
                    && "C".equals(setgll.getDebcdtflg())
                    && "BPTOPN".equals(SettleContext.getDirectTransName())) {
                setgll.setTxt1(text);
                return;
            }
        }
        if(!setgll.isModified("txt1")) {
            List<SetfelVo> setfels = setmod.getSetfeg().getSetfel();
            if (setfels != null && setfels.size() > 0) {
                for (int i=0; i<setfels.size(); i++) {
                    SetfelVo setfel = setfels.get(i);
                    if ((rol.equals(setfel.getRol()) || rol.equals(setmodService.getGllRol(setfel.getRol()))) && "X".equals(setfel.getDsp())) {
                        text += setfel.getFeetxtinf() + " " + setfel.getCur() + Utils.fmtAmount(setfel.getAmt(),setfel.getCur()) + " ";
                        /*if (setfel.getDat1() != null && setfel.getDat2() != null) {
                            Date endDate = setfel.getDat2();
                            if (setfel.getDat2dft() != null && MdaUtils.compareTo(setfel.getDat2(), setfel.getDat2dft()) > 0) {
                                endDate = setfel.getDat2dft();
                            }
                            text += Strings.getText("收取区间$1到$2", Utils.fmtDate(setfel.getDat1(), "yyyy-MM-dd"), Utils.fmtDate(endDate, "yyyy-MM-dd"));
                        }*/
                    }
                }
            }
            List<SetfolVo> setfols = setmod.getSetfog().getSetfol();
            if (setfols != null && setfols.size() > 0) {
                for (int i=0; i<setfols.size(); i++) {
                    SetfolVo setfol = setfols.get(i);
                    if (rol.equals(setfol.getPtydbt())) {
                        text += setfol.getTxtdbt() + " " + setfol.getCur() + Utils.fmtAmount(setfol.getAmt(), setfol.getCur()) + " ";
                    }
                }
            }
            setgll.setTxt1(text);
        }
    }

    /**
     *
     * @param setgllVo 该条结算信息
     * @param argDsp
     * @param argRol
     */
    public void getRelevantRtgRol(SetgllVo setgllVo, String argDsp, Argument<String> argRol) {
        //! get relevant ROL from SETGRP for RTG/TAR messages
        //! ArgDsp: "RTC" or "TGC"
        //! ArgRol: relevant role for RTGSplus or TARGET
        // ArgRol is filled with the first filled role of SETGRP\\INT, AWI, BEI. But only, if this role is allowed for the actual ArgDsp.
        argRol.value = "";
        String tarFlg = NULLSTR;
        String rtgFlg = NULLSTR;
        PtsptaVo ownPts = SettleContext.getOwnPts();
        if( ptsptaToolComponent.ptsIsRolSet(setgllVo.getSetgrp().getTmpint()))
        {
            Adr adr = getAdrOfPtaInr(setgllVo.getSetgrp().getTmpint().getPts().getInr());
            if( MdaUtils.compareTo(adr.getLoccty(),ownPts.getAdr().getLoccty()) == 0 )
            {
                tarFlg = "X";
            }
            else
            {
                tarFlg = doceotService.getPtmField ( setgllVo.getSetgrp().getTmpint().getPts().getPtainr(), "TAR", "AUTFLG" );
            }
            if( MdaUtils.compareTo(adr.getLoccty(),ownPts.getAdr().getLoccty()) == 0 )
            {
                rtgFlg = "X";
            }
            else
            {
                rtgFlg = doceotService.getPtmField ( setgllVo.getSetgrp().getTmpint().getPts().getPtainr(), "RTG", "AUTFLG" );
            }
            if( ( MdaUtils.compareTo(argDsp,"RTC") == 0 && ! MdaUtils.isEmpty(rtgFlg) ) || ( MdaUtils.compareTo(argDsp,"TGC") == 0 && ! MdaUtils.isEmpty(tarFlg) ) )
            {
                argRol.value = "INT";
            }
            else
            {
                return;
            }
        }
        if( ptsptaToolComponent.ptsIsRolSet(setgllVo.getSetgrp().getAwi()) )
        {
            Adr adr = getAdrOfPtaInr(setgllVo.getSetgrp().getAwi().getPts().getInr());
            if( MdaUtils.compareTo(adr.getLoccty(),ownPts.getAdr().getLoccty()) == 0 )
            {
                tarFlg = "X";
            }
            else
            {
                tarFlg = doceotService.getPtmField ( setgllVo.getSetgrp().getAwi().getPts().getPtainr(), "TAR", "AUTFLG" );
            }
            if( MdaUtils.compareTo(adr.getLoccty(),ownPts.getAdr().getLoccty()) == 0 )
            {
                rtgFlg = "X";
            }
            else
            {
                rtgFlg = doceotService.getPtmField ( setgllVo.getSetgrp().getAwi().getPts().getPtainr(), "RTG", "AUTFLG" );
            }
            if( ( MdaUtils.compareTo(argDsp,"RTC") == 0 && ! MdaUtils.isEmpty(rtgFlg) ) || ( MdaUtils.compareTo(argDsp,"TGC") == 0 && ! MdaUtils.isEmpty(tarFlg) ) )
            {
                argRol.value = "AWI";
            }
            else
            {
                return;
            }
        }
        if( ptsptaToolComponent.ptsIsRolSet(setgllVo.getSetgrp().getBei()) )
        {
            Adr adr = getAdrOfPtaInr(setgllVo.getSetgrp().getBei().getPts().getInr());
            if( MdaUtils.compareTo(adr.getLoccty(),ownPts.getAdr().getLoccty()) == 0 )
            {
                tarFlg = "X";
            }
            else
            {
                tarFlg = doceotService.getPtmField ( setgllVo.getSetgrp().getBei().getPts().getPtainr(), "TAR", "AUTFLG" );
            }
            if( MdaUtils.compareTo(adr.getLoccty(),ownPts.getAdr().getLoccty()) == 0 )
            {
                rtgFlg = "X";
            }
            else
            {
                rtgFlg = doceotService.getPtmField ( setgllVo.getSetgrp().getBei().getPts().getPtainr(), "RTG", "AUTFLG" );
            }
            if( ( MdaUtils.compareTo(argDsp,"RTC") == 0 && ! MdaUtils.isEmpty(rtgFlg) ) || ( MdaUtils.compareTo(argDsp,"TGC") == 0 && ! MdaUtils.isEmpty(tarFlg) ) )
            {
                argRol.value = "BEI";
            }
            else
            {
                return;
            }
        }

    }

    private Adr getAdrOfPtaInr(String ptaInr){
        Adr adr = adrCacheService.selectByPtaInr(ptaInr);
        if(adr == null){
            return new Adr();
        }
        return adr;
    }

    /**
     * 根据账号调用核心8091接口获取核心业务代码和账户余额
     * 获取不到也不会报错，不影响流程
     * @param setgllVo
     */
    public void recalcSetgllCoreAcctInfo(SetgllVo setgllVo) {
       boolean do8091 = false;
       try {
           if (StringUtils.isNotEmpty(setgllVo.getAct())) {
               //组装8091接口请求对象
               InnerReq8091 req8091 = new InnerReq8091(setgllVo.getAct());
               InnerReq<InnerReq8091> innerReq8091 = new InnerReq<>(req8091);
               //调用接口
               InnerRes<InnerRes8091> innerRes8091 = accountFeign.call8091(innerReq8091);
               if (innerRes8091 != null && "AAAAAAA".equals(innerRes8091.header.code) && innerRes8091.DATA != null) {
                   do8091 = true;
                   setgllVo.setAcccode(innerRes8091.DATA.yewudh);
                   if (StringUtils.isNotEmpty(innerRes8091.DATA.zhhuye)) {
                       setgllVo.setAccountBalance(new BigDecimal(innerRes8091.DATA.zhhuye));
                   }
               }
           }
       } catch (Exception e) {
           log.warn("调用核心8091接口出现异常,错误信息：{},不影响账务计算", e.getMessage());
           do8091 = false;
       }
       //如果没有调用8091接口或者调用8091接口失败，重置
       if (!do8091) {
           setgllVo.setAcccode("");
           setgllVo.setAccountBalance(BigDecimal.ZERO);
       }
    }

    /**
     *   source:setgll.0071.script
     *   @Default(value={"trdint","trdout","trnman","xrttim","buyrat","selrat","midrat"},order=1000)
     */
    public void calcTrdinoutAndTrnman(SetgllVo setgllVo, SetmodVo setmodVo){
        // 给交易主体和结售汇类型灰显
        String rmb = xrtmodService.sysiso();
        if((MdaUtils.compareTo(setgllVo.getAcccur(),rmb) == 0 && MdaUtils.compareTo(setgllVo.getCur(),rmb) != 0 && MdaUtils.compareTo(setgllVo.getAmt(),0) < 0)
                || (MdaUtils.compareTo(setgllVo.getAcccur(),rmb) != 0 && MdaUtils.compareTo(setgllVo.getCur(),rmb) == 0 && MdaUtils.compareTo(setgllVo.getAmt(),0) > 0)
                || (MdaUtils.compareTo(setgllVo.getAcccur(),rmb) == 0 && MdaUtils.compareTo(setgllVo.getCur(),rmb) != 0 && MdaUtils.compareTo(setgllVo.getAmt(),0) > 0)
                || (MdaUtils.compareTo(setgllVo.getAcccur(),rmb) != 0 && MdaUtils.compareTo(setgllVo.getCur(),rmb) == 0 && MdaUtils.compareTo(setgllVo.getAmt(),0) < 0)) {
            //Systems.setEnabled(this,"trnman");
            //满足结售汇条件
            setgllVo.setExchangeFlag(true);
            //505新需求
            //自动赋上在静态数据中维护的
            if(!setgllVo.isModified("trnman")) {
                String trnman = Utils.getFieldValue(setmodVo.getRec(), "dfkhlb", "");
                if (StringUtils.isEmpty(trnman)) {
                    Pty pty = ptyCacheService.getPtyById(setgllVo.getRolptyinr());
                    if (pty != null) {
                        trnman = pty.getTrnman();
                    }
                }
                setgllVo.setTrnman(trnman);
            }
            Set<String> trnmanFilter = new HashSet<>();
            if ("X".equals(getzmqflg())) {
                trnmanFilter.add("01");
                trnmanFilter.add("03");
                trnmanFilter.add("04");
                trnmanFilter.add("05");
                trnmanFilter.add("06");
                trnmanFilter.add("99");
            } else {
                trnmanFilter.add("01");
                trnmanFilter.add("02");
                trnmanFilter.add("03");
                trnmanFilter.add("04");
                trnmanFilter.add("05");
                trnmanFilter.add("06");
            }
            setgllVo.setTrnmanFilter(trnmanFilter);
        } else {
            setgllVo.setExchangeFlag(false);
            setgllVo.setTrnman("");
            //清掉牌价时间
            setgllVo.setXrttim("");
            //清掉买价、卖价及中间价
            setgllVo.setBuyrat(BigDecimal.ZERO);
            setgllVo.setSelrat(BigDecimal.ZERO);
            setgllVo.setMidrat(BigDecimal.ZERO);
        }
        if((MdaUtils.compareTo(setgllVo.getAcccur(), rmb) == 0 && MdaUtils.compareTo(setgllVo.getCur(),rmb) != 0 && MdaUtils.compareTo(setgllVo.getAmt(),0) < 0)
            || (MdaUtils.compareTo(setgllVo.getAcccur(),rmb) != 0 && MdaUtils.compareTo(setgllVo.getCur(),rmb) == 0 && MdaUtils.compareTo(setgllVo.getAmt(),0) > 0)) {
            setgllVo.setTrdintFlag(true);
            if(!setgllVo.isModified("trdint")) {
                String trdint = Utils.getFieldValue(setmodVo.getRec(), "waitjm", "");
                setgllVo.setTrdint(trdint);
            }
        } else {
            setgllVo.setTrdintFlag(false);
            setgllVo.setTrdint("");
        }
        if((MdaUtils.compareTo(setgllVo.getAcccur(),rmb) == 0 && MdaUtils.compareTo(setgllVo.getCur(),rmb) != 0 && MdaUtils.compareTo(setgllVo.getAmt(),0) > 0)
            || (MdaUtils.compareTo(setgllVo.getAcccur(),rmb) != 0 && MdaUtils.compareTo(setgllVo.getCur(),rmb) == 0 && MdaUtils.compareTo(setgllVo.getAmt(),0) < 0)) {
            setgllVo.setTrdoutFlag(true);
            if(!setgllVo.isModified("trdout")) {
                String trdout = Utils.getFieldValue(setmodVo.getRec(), "waitjm", "");
                setgllVo.setTrdout(trdout);
            }
        } else {
            setgllVo.setTrdoutFlag(false);
            setgllVo.setTrdout("");
        }
    }

    /**
     *   source:setgll.0120.script
     *   @Default(value={"trntyp","oppacc","oppnam","oppbnk","discod","ctycod"},order=1000)
     */
    public void defaultZimaoqu(SetgllVo setgllVo, SetmodVo setmodVo){
        if( MdaUtils.compareTo(Strings.mid(setgllVo.getAct(),1,2),"FT") == 0
                || MdaUtils.compareTo(Strings.mid(setgllVo.getAct(),1,2),"EF") == 0
                || MdaUtils.compareTo(Strings.mid(setgllVo.getAct(),1,3),"ZMQ") == 0 ) {
            String trntyp = "";
            String oppacc = "";
            String oppnam = "";
            String oppbnk = "";
            String discod = "";
            String ctycod = "";
            String accbch = "";
            String line = Strings.getLine(setgllVo.getAmtidsstm(), 1);
            if( MdaUtils.compareTo(Strings.mid(line,1,7),"*SETFEG") == 0 ) {
                ctycod = "CHN";
                //---ZMQZMQ--
                //---for test---
                if (SettleContext.getUserSession().getWrkbch() != null) {
                    oppbnk = SettleContext.getUserSession().getWrkbch().getLhanum();
                }
                if (SettleContext.getUserSession().getBch() != null) {
                    accbch = SettleContext.getUserSession().getBch().getBranch();
                }
                discod = codetableService.getTblLabel(accbch, "ZMQBCH");
                oppnam = "中国光大银行";
                //--20150305-----------
                trntyp = "D20000";
                //---如果为其他自贸区？？-----------
                oppacc = codetableService.getTblLabel(accbch, "ZMQACT");
                if(MdaUtils.isEmpty(oppacc)) {
                    /**
                     $OPPACC = "36930107320000003"
                     **/
                    oppacc = accbch + "0107320000003";
                }
            } else {
                BizInfoVo bizInfoVo = setmodVo.getRec();
                String objtyp = bizInfoVo.getObjtyp();
                String transName = SettleContext.getTransName();
                List<SetgllVo> setgllVos = setmodVo.getSetglg().getSetgll();
                List<PtsptaVo> ptsList = setmodVo.getPtsList();
                switch(transName) {
                    case "FCTOPN":
                    case  "FCTCAN":
                    case  "LITENG":
                    case  "GITENG":
                    case  "NITENG":
                    case  "LITCAN":
                    case  "GITCAN":
                    case  "NITCAN":
                    case  "HITCAN":
                        ctycod = "CHN";
                        if(MdaUtils.compareTo(setgllVo.getDebcdtflg(), "C") == 0) {
                            for (int i=0; i<setgllVos.size(); i++) {
                                if ("D".equalsIgnoreCase(setgllVos.get(i).getDebcdtflg())) {
                                    oppacc = setgllVos.get(i).getAct();
                                }
                            }
                            if (StringUtils.isEmpty(oppacc)) {
                                setgllVo.setOppaccLoseFlag(true);
                            }
                        }
                        if(MdaUtils.compareTo(setgllVo.getDebcdtflg(), "D") == 0) {
                            for (int i=0; i<setgllVos.size(); i++) {
                                if ("C".equalsIgnoreCase(setgllVos.get(i).getDebcdtflg())) {
                                    oppacc = setgllVos.get(i).getAct();
                                }
                            }
                            if (StringUtils.isEmpty(oppacc)) {
                                setgllVo.setOppaccLoseFlag(true);
                            }
                        }
                        //---for test---
                        if (SettleContext.getUserSession().getWrkbch() != null) {
                            oppbnk = SettleContext.getUserSession().getWrkbch().getLhanum();
                        }
                        trntyp = "D80003";
                        PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "APL");
                        if (ptsptaVo != null) {
                            Pta pta = ptaCacheService.getPtaByInr(ptsptaVo.getPtainr());
                            if (pta != null) {
                                oppnam = pta.getNam1();
                            }
                        }
                        if (SettleContext.getUserSession().getBch() != null) {
                            accbch = SettleContext.getUserSession().getBch().getBranch();
                        }
                        discod = codetableService.getTblLabel(accbch, "ZMQBCH");
                        //discod = Codetables.getCodetableLabelOfTd(accbch,"ZMQBCH","EN");
                        break;
                    default:
                        if( MdaUtils.compareTo(Strings.mid(transName,4,3),"FEE") == 0 || "JSTOPN".equals(transName)) {
                            ctycod = "CHN";
                            if(MdaUtils.compareTo(setgllVo.getDebcdtflg(), "C") == 0) {
                                for (int i=0; i<setgllVos.size(); i++) {
                                    if ("D".equalsIgnoreCase(setgllVos.get(i).getDebcdtflg())) {
                                        oppacc = setgllVos.get(i).getAct();
                                    }
                                }
                                if (StringUtils.isEmpty(oppacc)) {
                                    setgllVo.setOppaccLoseFlag(true);
                                }
                            }
                            if(MdaUtils.compareTo(setgllVo.getDebcdtflg(), "D") == 0) {
                                for (int i=0; i<setgllVos.size(); i++) {
                                    if ("C".equalsIgnoreCase(setgllVos.get(i).getDebcdtflg())) {
                                        oppacc = setgllVos.get(i).getAct();
                                    }
                                }
                                if (StringUtils.isEmpty(oppacc)) {
                                    setgllVo.setOppaccLoseFlag(true);
                                }
                            }
                            //---for test---
                            if (SettleContext.getUserSession().getWrkbch() != null) {
                                oppbnk = SettleContext.getUserSession().getWrkbch().getLhanum();
                            }
                            String role = "";
                            switch(objtyp) {
                                case "MCD":
                                    role = "ADE";
                                    break;
                                case "BOD":
                                    role = "DRR";
                                    break;
                                case "BED":
                                case  "LED":
                                    role = "BEN";
                                    break;
                                case "BCD":
                                    role = "DRE";
                                    break;
                                case "BRD":
                                case  "LID":
                                case  "DFD":
                                    role = "APL";
                                    break;
                                case "BDD":
                                case "DID":
                                    role = "APL";
                                    break;
                                case "CPD":
                                    String paytyp = Utils.getFieldValue(bizInfoVo, "paytyp");
                                    if(MdaUtils.compareTo(paytyp, "I") == 0) {
                                        role = "PYE";
                                    } else {
                                        role = "ORC";
                                    }
                                    break;
                                case "TRD":
                                    role = "FIP";
                                    break;
                                case "BPD":
                                    role = "FIA";
                                    break;
                                case "CCD":
                                    role = "PRE";
                                    break;
                                case "GID":
                                case "NID":
                                case "GCD":
                                case "NCD":
                                    String hndtyp = Utils.getFieldValue(bizInfoVo, "hndtyp");
                                    if( MdaUtils.compareTo(hndtyp,"OT") == 0 || MdaUtils.compareTo(hndtyp,"FA") == 0 || MdaUtils.compareTo(hndtyp,"FR") == 0 ) {
                                        role = "BEN";
                                    } else {
                                        role = "APL";
                                    }
                                    break;
                                case "JSD":
                                    role = "APL";
                                    break;
                            }
                            ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, role);
                            if (ptsptaVo != null) {
                                Pta pta = ptaCacheService.getPtaByInr(ptsptaVo.getPtainr());
                                if (pta != null) {
                                    oppnam = pta.getNam1();
                                }
                            }
                            if (SettleContext.getUserSession().getBch() != null) {
                                accbch = SettleContext.getUserSession().getBch().getBranch();
                            }
                            discod = codetableService.getTblLabel(accbch, "ZMQBCH");
                            trntyp = "D80003";
                            //--其他交易--
                        } else {
                            switch (objtyp) {
                                case "GID":
                                case "NID":
                                case "GCD":
                                case "NCD":
                                    String hndtyp = Utils.getFieldValue(bizInfoVo, "hndtyp");
                                    if(MdaUtils.compareTo(hndtyp,"OT") == 0 || MdaUtils.compareTo(hndtyp,"FA") == 0 || MdaUtils.compareTo(hndtyp,"FR") == 0 ) {
                                        ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "APL");
                                        if (ptsptaVo != null) {
                                            oppnam = ptsptaVo.getNam();
                                        }
                                    } else {
                                        ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "BEN");
                                        if (ptsptaVo != null) {
                                            oppnam = ptsptaVo.getNam();
                                        }
                                    }
                                    String tableName = "";
                                    String inr = "";
                                    if ("GID".equals(objtyp) || "NID".equals(objtyp)) {
                                        tableName = objtyp;
                                        inr = bizInfoVo.getObjinr();
                                    } else if ("GCD".equals(objtyp)) {
                                        tableName = "GID";
                                        inr = Utils.getFieldValue(bizInfoVo, "gidinr", "");
                                    } else if ("NCD".equals(objtyp)) {
                                        tableName = "NID";
                                        inr = Utils.getFieldValue(bizInfoVo, "nidinr", "");
                                    }
                                    if (StringUtils.isNotEmpty(tableName) && StringUtils.isNotEmpty(inr)) {
                                        oppbnk = dyncDaoService.dyncReadFieldByInr(tableName, inr, "oppbnk");
                                    }
                                    for (int i=0; i<setgllVos.size(); i++) {
                                        if ("202".equalsIgnoreCase(setgllVos.get(i).getSftmt())) {
                                            oppacc = setgllVos.get(i).getSespay().getBeiacc();
                                        }
                                    }
                                    break;
                                case "FCD":
                                    break;
                                case "CPD":
                                    CpdBizInfoVo cpdBizInfoVo = (CpdBizInfoVo) bizInfoVo;
                                    Cpd cpd = null;
                                    if (StringUtils.isNotEmpty(cpdBizInfoVo.getObjinr())) {
                                        cpd = new Cpd();
                                        dyncDaoService.dyncReadByInr(cpd, cpdBizInfoVo.getObjinr());
                                    }
                                    String paytyp = cpdBizInfoVo.getPaytyp();
                                    if ("I".equals(paytyp)) {
                                        ctycod = cpdBizInfoVo.getDraweecountcode();
                                        oppacc = cpd != null ? cpd.getOrcact() : cpdBizInfoVo.getOrcact();
                                        String swftyp = cpd != null ? cpd.getSwftyp() : cpdBizInfoVo.getSwftyp();
                                        String sndbch = cpdBizInfoVo.getSndbch();
                                        if (MdaUtils.compareTo(swftyp, "CMT") == 0
                                                || MdaUtils.compareTo(swftyp, "HVP") == 0
                                                || MdaUtils.compareTo(swftyp, "HVQ") == 0
                                                || MdaUtils.compareTo(swftyp, "CIU") == 0
                                                || MdaUtils.compareTo(swftyp, "CIV") == 0
                                                || MdaUtils.compareTo(swftyp, "CIW") == 0) {
                                            oppnam = cpd != null ? cpd.getOrcnam() : cpdBizInfoVo.getOrcnam();
                                        } else {
                                            oppnam = cpd != null ? cpd.getOrcnam() : cpdBizInfoVo.getOrcnam();
                                        }
                                        if (!MdaUtils.isEmpty(sndbch)) {
                                            oppbnk = sndbch;
                                        } else {
                                            ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ORI");
                                            if (ptsptaVo != null) {
                                                oppbnk = ptsptaVo.getExtkey();
                                            }
                                            if (Strings.len(oppbnk) > 11) {
                                                oppbnk = Strings.mid(oppbnk, 1, 11);
                                            }
                                        }
                                    } else if ("O".equals(paytyp)) {
                                        ctycod = cpdBizInfoVo.getPayeecountcode();
                                        oppacc = cpd != null ? cpd.getPyeact() : cpdBizInfoVo.getPyeact();
                                        String swftyp = cpd != null ? cpd.getSwftyp() : cpdBizInfoVo.getSwftyp();
                                        String resbch = cpdBizInfoVo.getResbch();
                                        oppnam = cpd != null ? cpd.getPyenam() : cpdBizInfoVo.getPyenam();
                                        if (!MdaUtils.isEmpty(resbch)) {
                                            oppbnk = resbch;
                                        } else {
                                            for (SetgllVo setgll : setgllVos) {
                                                String sftmt = setgll.getSftmt();
                                                if ("202".equalsIgnoreCase(sftmt) || "103".equalsIgnoreCase(sftmt)) {
                                                    //--此写法当报文类型为202COV时候，出的是COVER A的57场---
                                                    oppbnk = setgll.getSetgrp().getAwi().getExtkey();
                                                    if (MdaUtils.compareTo(swftyp, "200") == 0) {
                                                        oppbnk = setgll.getSetgrp().getBei().getExtkey();
                                                    }
                                                    if (Strings.len(oppbnk) > 11) {
                                                        oppbnk = Strings.mid(oppbnk, 1, 11);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "BED":
                                case "BFD":
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "APL");
                                    if (ptsptaVo != null) {
                                        oppnam = ptsptaVo.getNam();
                                    }
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ISS");
                                    if (ptsptaVo != null) {
                                        oppbnk = ptsptaVo.getExtkey();
                                        if (Strings.len(oppbnk) > 11) {
                                            oppbnk = Strings.mid(oppbnk, 1, 11);
                                        }
                                    }
                                    break;
                                case "BRD":
                                case "BDD":
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "BEN");
                                    if (ptsptaVo != null) {
                                        oppnam = ptsptaVo.getNam();
                                    }
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ADV");
                                    if (ptsptaVo != null) {
                                        oppbnk = ptsptaVo.getExtkey();
                                        if (Strings.len(oppbnk) > 11) {
                                            oppbnk = Strings.mid(oppbnk, 1, 11);
                                        }
                                    }
                                    String swftyp = Utils.getFieldValue(bizInfoVo, "swftyp", "");
                                    if (MdaUtils.compareTo(swftyp, "CMT") == 0 || MdaUtils.compareTo(swftyp, "HVQ") == 0 || MdaUtils.compareTo(swftyp, "CIV") == 0) {
                                        oppacc = Utils.getFieldValue(bizInfoVo, "pyeact", "");
                                        oppnam = Utils.getFieldValue(bizInfoVo, "pyenam", "");
                                        oppbnk = Utils.getFieldValue(bizInfoVo, "pyebchkey", "");
                                    } else {
                                        for (SetgllVo setgll : setgllVos) {
                                            String sftmt = setgll.getSftmt();
                                            if ("202".equalsIgnoreCase(sftmt) || "756".equalsIgnoreCase(sftmt)) {
                                                oppacc = setgll.getSespay().getBeiacc();
                                                if (setgll.getSetgrp().getBei() != null) {
                                                    String oppbnk1 = setgll.getSetgrp().getBei().getExtkey();
                                                    if (StringUtils.isEmpty(oppbnk1)) {
                                                        oppbnk1 = setgll.getSetgrp().getBei().getPts().getExtkey();
                                                    }
                                                    if (!MdaUtils.isEmpty(oppbnk1) && Strings.pos("0123456789", Strings.mid(oppbnk1, 1, 1)) == 0 && MdaUtils.compareTo(Strings.mid(Strings.toUpper(oppbnk1), 1, 4), "TEMP") != 0) {
                                                        if (Strings.len(oppbnk1) > 11) {
                                                            oppbnk = Strings.mid(oppbnk1, 1, 11);
                                                        } else {
                                                            oppbnk = oppbnk1;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "BCD":
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "DRR");
                                    if (ptsptaVo != null) {
                                        oppnam = ptsptaVo.getNam();
                                    }
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "RMI");
                                    if (ptsptaVo != null) {
                                        oppbnk = ptsptaVo.getExtkey();
                                        if (Strings.len(oppbnk) > 11) {
                                            oppbnk = Strings.mid(oppbnk, 1, 11);
                                        }
                                    }
                                    swftyp = Utils.getFieldValue(bizInfoVo, "swftyp", "");
                                    if (MdaUtils.compareTo(swftyp, "CMT") == 0 || MdaUtils.compareTo(swftyp, "HVQ") == 0 || MdaUtils.compareTo(swftyp, "CIV") == 0) {
                                        oppacc = Utils.getFieldValue(bizInfoVo, "pyeact", "");
                                        oppnam = Utils.getFieldValue(bizInfoVo, "pyenam", "");
                                        oppbnk = Utils.getFieldValue(bizInfoVo, "pyebchkey", "");
                                    } else {
                                        for (SetgllVo setgll : setgllVos) {
                                            String sftmt = setgll.getSftmt();
                                            if ("202".equalsIgnoreCase(sftmt) || "400".equalsIgnoreCase(sftmt)) {
                                                oppacc = setgll.getSespay().getBeiacc();
                                                if (setgll.getSetgrp().getBei() != null) {
                                                    String oppbnk1 = setgll.getSetgrp().getBei().getExtkey();
                                                    if (StringUtils.isEmpty(oppbnk1)) {
                                                        oppbnk1 = setgll.getSetgrp().getBei().getPts().getExtkey();
                                                    }
                                                    if (!MdaUtils.isEmpty(oppbnk1) && Strings.pos("0123456789", Strings.mid(oppbnk1, 1, 1)) == 0 && MdaUtils.compareTo(Strings.mid(Strings.toUpper(oppbnk1), 1, 4), "TEMP") != 0) {
                                                        if (Strings.len(oppbnk1) > 11) {
                                                            oppbnk = Strings.mid(oppbnk1, 1, 11);
                                                        } else {
                                                            oppbnk = oppbnk1;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "CCD":
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "COR");
                                    if (!ptsptaToolComponent.ptsIsRolSet(ptsptaVo)) {
                                        ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "PRE");
                                    }
                                    if (ptsptaVo != null) {
                                        oppnam = ptsptaVo.getNam();
                                    }
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "COL");
                                    if (!ptsptaToolComponent.ptsIsRolSet(ptsptaVo)) {
                                        ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "DRO");
                                    }
                                    if (ptsptaVo != null) {
                                        oppbnk = ptsptaVo.getExtkey();
                                        if (Strings.len(oppbnk) > 11) {
                                            oppbnk = Strings.mid(oppbnk, 1, 11);
                                        }
                                    }
                                    break;
                                case "BOD":
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "DRE");
                                    if (ptsptaVo != null) {
                                        oppnam = ptsptaVo.getNam();
                                    }
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "COL");
                                    if (ptsptaVo != null) {
                                        oppbnk = ptsptaVo.getExtkey();
                                        if (Strings.len(oppbnk) > 11) {
                                            oppbnk = Strings.mid(oppbnk, 1, 11);
                                        }
                                    }
                                    break;
                                case "TRD":
                                case "BPD":
                                    oppacc = Utils.getFieldValue(bizInfoVo, "oppacc", "");
                                    if (StringUtils.isEmpty(oppacc)) {
                                        oppacc = dyncDaoService.dyncReadFieldByInr(bizInfoVo.getObjtyp(), bizInfoVo.getObjinr(), "oppacc");
                                    }
                                    trntyp = Utils.getFieldValue(bizInfoVo, "trntyp", "");
                                    if (StringUtils.isEmpty(oppacc)) {
                                        trntyp = dyncDaoService.dyncReadFieldByInr(bizInfoVo.getObjtyp(), bizInfoVo.getObjinr(), "trntyp");
                                    }
                                    break;
                                case "LID":
                                case "DID":
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "BEN");
                                    if (ptsptaVo != null) {
                                        oppnam = ptsptaVo.getNam();
                                    }
                                    oppbnk = Utils.getFieldValue(bizInfoVo, "oppbnk", "");
                                    if (StringUtils.isEmpty(oppbnk)) {
                                        oppbnk = dyncDaoService.dyncReadFieldByInr(bizInfoVo.getObjtyp(), bizInfoVo.getObjinr(), "oppbnk");
                                    }
                                    if (StringUtils.isEmpty(oppbnk)) {
                                        ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ADV");
                                        if (ptsptaVo != null) {
                                            oppbnk = ptsptaVo.getExtkey();
                                        }
                                    }
                                    oppbnk = Strings.mid(oppbnk, 1, 11);
                                    break;
                                case "LED":
                                case "DED":
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "APL");
                                    if (ptsptaVo != null) {
                                        oppnam = ptsptaVo.getNam();
                                    }
                                    oppbnk = Utils.getFieldValue(bizInfoVo, "oppbnk", "");
                                    if (StringUtils.isEmpty(oppbnk)) {
                                        oppbnk = dyncDaoService.dyncReadFieldByInr(bizInfoVo.getObjtyp(), bizInfoVo.getObjinr(), "oppbnk");
                                    }
                                    if (StringUtils.isEmpty(oppbnk)) {
                                        ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ISS");
                                        if (ptsptaVo != null) {
                                            oppbnk = ptsptaVo.getExtkey();
                                        }
                                    }
                                    oppbnk = Strings.mid(oppbnk, 1, 11);
                                    break;
                                case "DFD":
                                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "DFF");
                                    if (ptsptaVo != null) {
                                        oppbnk = ptsptaVo.getExtkey();
                                        if (Strings.len(oppbnk) > 11) {
                                            oppbnk = Strings.mid(oppbnk, 1, 11);
                                        }
                                    }
                                    if (MdaUtils.compareTo(SettleContext.getTransName(), "DFTMSG") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "DFTSET") == 0) {
                                        swftyp = Utils.getFieldValue(bizInfoVo, "msgtyp", "");
                                        //swftyp = Datas.getContent(this,"\\DFTP\\MSGTYP");
                                        if (MdaUtils.compareTo(swftyp, "CMT") == 0 || MdaUtils.compareTo(swftyp, "HVQ") == 0 || MdaUtils.compareTo(swftyp, "CIV") == 0) {
                                            /*voppacc = Datas.getContent(this,"\\TRNMOD\\PYEACT");
                                            voppnam = Datas.getContent(this,"\\TRNMOD\\PYENAM");
                                            voppbnk = Datas.getContent(this,"\\TRNMOD\\PYEBCHKEY");
                                            if( MdaUtils.isEmpty(voppnam) ) {
                                                voppnam = Datas.getContent(this,"\\TRNMOD\\CIPMOD\\PYEBCHNAM");
                                                err = ctx.getErrorCode();
                                            }
                                            if( MdaUtils.isEmpty(voppbnk) ) {
                                                voppbnk = Datas.getContent(this,"\\TRNMOD\\CIPMOD\\PYEBCHKEY");
                                                err = ctx.getErrorCode();
                                            }*/
                                            oppacc = Utils.getFieldValue(bizInfoVo, "pyeact", "");
                                            oppnam = Utils.getFieldValue(bizInfoVo, "pyenam", "");
                                            oppbnk = Utils.getFieldValue(bizInfoVo, "pyebchkey", "");
                                        }
                                        if (MdaUtils.compareTo(swftyp, "100") == 0 || MdaUtils.compareTo(swftyp, "111") == 0) {
                                            //voppbnk = Datas.getContent(this,"\\DFTP\\RESBCH");
                                            oppbnk = Utils.getFieldValue(bizInfoVo, "resbch", "");
                                            //voppnam = Datas.getContent(this,"\\DFTP\\RESBCHNAM");
                                            oppnam = Utils.getFieldValue(bizInfoVo, "resbchnam", "");
                                        }
                                        if (MdaUtils.compareTo(swftyp, "202") == 0) {
                                            for (SetgllVo setgll : setgllVos) {
                                                String sftmt = setgll.getSftmt();
                                                if ("202".equalsIgnoreCase(sftmt) || "756".equalsIgnoreCase(sftmt)) {
                                                    oppacc = setgll.getSespay().getBeiacc();
                                                    if (setgll.getSetgrp().getBei() != null) {
                                                        String oppbnk1 = setgll.getSetgrp().getBei().getExtkey();
                                                        if (StringUtils.isEmpty(oppbnk1)) {
                                                            oppbnk1 = setgll.getSetgrp().getBei().getPts().getExtkey();
                                                        }
                                                        if (!MdaUtils.isEmpty(oppbnk1) && Strings.pos("0123456789", Strings.mid(oppbnk1, 1, 1)) == 0 && MdaUtils.compareTo(Strings.mid(Strings.toUpper(oppbnk1), 1, 4), "TEMP") != 0) {
                                                            if (Strings.len(oppbnk1) > 11) {
                                                                oppbnk = Strings.mid(oppbnk1, 1, 11);
                                                            } else {
                                                                oppbnk = oppbnk1;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "JSD":
                                case "MCD":
                                    break;
                                default:
                                    throw new CommonServiceException("无效的业务种类{"+objtyp+"}");
                            }
                        }
                }
            }
            if(!setgllVo.isModified("trntyp")) {
                setgllVo.setTrntyp(trntyp);
            }
            if(!setgllVo.isModified("oppacc")) {
                setgllVo.setOppacc(oppacc);
            }
            if(!setgllVo.isModified("oppnam")) {
                setgllVo.setOppnam(oppnam);
            }
            if(!setgllVo.isModified("oppbnk")) {
                setgllVo.setOppbnk(oppbnk);
            }
            if(!setgllVo.isModified("discod")) {
                setgllVo.setDiscod(discod);
            }
            if(!setgllVo.isModified("ctycod")) {
                setgllVo.setCtycod(ctycod);
            }
            setgllVo.setCtycod(Strings.toUpper(setgllVo.getCtycod()));
            setgllVo.setOppbnk(Strings.toUpper(setgllVo.getOppbnk()));
        }
    }

    /**
     *   source:setgll.0146.script
     *   @Default(value={"eastoppacc","eastoppnam","eastoppbnk","eastinf"},order=1000)
     */
    public void defaultEasTto7759(SetgllVo setgllVo, SetmodVo setmodVo){
        String trntyp = "";
        String oppacc = "";
        String oppnam = "";
        String oppbnk = "";
        String discod = "";
        String ctycod = "";
        Argument<String> oppaccBox = new Argument<String>("",oppacc);
        Argument<String> oppnamBox = new Argument<String>("",oppnam);
        Argument<String> oppbnkBox = new Argument<String>("",oppbnk);
        trnmodService.east7759(setmodVo.getRec(), setmodVo.getPtsList(), setmodVo.getSetglg().getSetgll(), oppaccBox, oppnamBox, oppbnkBox);

        oppacc = oppaccBox.value;
        oppnam = oppnamBox.value;
        oppbnk = oppbnkBox.value;

        setgllVo.setEastoppacc(oppacc);
        setgllVo.setEastoppnam(oppnam);
        setgllVo.setEastoppbnk(Strings.toUpper(oppbnk));
    }

    /**
     *   source:setgll.0129.script
     *   @Default(target="typ",order=1000)
     */
    public void defaultTypN1000(SetgllVo setgllVo, BizInfoVo rec){
        //--zmqzmq---
        String objtyp = rec.getObjtyp();
        switch(objtyp) {
            case "LID":
            case  "BRD":
            case  "BDD":
            case  "LTD":
            case  "BCD":
            case  "DID":
            case  "DFD":
                setgllVo.setTyp("O");
                break;
            case "LED":
            case  "BED":
            case  "BOD":
            case  "CCD":
            case  "BTD":
            case  "BPD":
            case  "TRD":
            case  "BFD":
            case  "CLD":
            case  "DED":
                setgllVo.setTyp("I");
                break;
            case "GID":
            case "GCD":
            case "NID":
            case "NCD":
                String hndtyp = Utils.getFieldValue(rec, "hndtyp", "");
                if( MdaUtils.compareTo(Strings.mid(hndtyp,1,1),"F") == 0 ) {
                    setgllVo.setTyp("I");
                } else {
                    setgllVo.setTyp("O");
                }
                break;
            case "CPD":
                String paytyp = Utils.getFieldValue(rec, "paytyp", "");
                if( MdaUtils.compareTo(paytyp,"I") == 0 ) {
                    setgllVo.setTyp(  "I");
                } else {
                    setgllVo.setTyp(  "O");
                }
                break;
            case "MCD":
            case "FCD":
                if( MdaUtils.compareTo(setgllVo.getDebcdtflg(),"D") == 0 ) {
                    setgllVo.setTyp(  "O");
                } else {
                    setgllVo.setTyp(  "I");
                }
                break;
        }
    }

    public String getzmqflg() {
        if (SettleContext.getUserSession().getBch() != null) {
            return SettleContext.getUserSession().getBch().getZmqflg();
        } else {
            return "";
        }
    }

    /**
     * 国内证 融资 如果是费用的账务，科目只能选择LO
     */
    private String filterDsp(SetgllVo setgllVo, String val, String objtyp) {
        if ("DID|BDD|DED|BFD|BPD|TRD".indexOf(objtyp) > -1) {
            String role = "";
            if ("DID|BDD".indexOf(objtyp) > -1) {
                role = "APL";
            } else if ("DED|BFD".indexOf(objtyp) > -1) {
                role = "BEN";
            } else if ("BPD".indexOf(objtyp) > -1) {
                role = "FIA";
            } else if ("TRD".indexOf(objtyp) > -1) {
                role = "FIP";
            }
            IStream amtidsstm = setgllVo.getAmtidsstm();
            boolean onlyfeeflag = true;
            if (amtidsstm.isEmpty()) {
                onlyfeeflag = false;
            } else {
                for (String row : amtidsstm.getRows()) {
                    if (!row.startsWith("*SETFEG")){
                        onlyfeeflag = false;
                        break;
                    }
                }
            }
            if (onlyfeeflag && role.equals(setgllVo.getRol())) {
                if (MdaUtils.compareTo(setgllVo.getAmt(), 0) > 0) {
                    return "LOD";
                } else {
                    return "LOC";
                }
            }
        }
        return val;
    }
}
