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

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 org.springframework.util.ObjectUtils;
import com.brilliance.isc.bo.*;
import com.brilliance.isc.common.cbsmod.service.CbsmodService;
import com.brilliance.isc.common.cbsmod.service.XrtmodService;
import com.brilliance.isc.common.ccimod.service.CcimodService;
import com.brilliance.isc.common.codetable.service.CodetableService;
import com.brilliance.isc.common.component.DyncDaoService;
import com.brilliance.isc.common.component.PtsptaToolComponent;
import com.brilliance.isc.common.contants.CommonContants;
import com.brilliance.isc.common.context.AppEnv;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.context.SettleSession;
import com.brilliance.isc.common.counter.service.CounterService;
import com.brilliance.isc.common.docimm.service.DocimmService;
import com.brilliance.isc.common.exception.CommonServiceException;
import com.brilliance.isc.common.liaccv.vo.FcdgrpVo;
import com.brilliance.isc.common.ntfmod.service.NtfmodService;
import com.brilliance.isc.common.ordmod.service.OrdmodService;
import com.brilliance.isc.common.ordmod.vo.OrdmodVo;
import com.brilliance.isc.common.quemod.vo.TaskFlowStatus;
import com.brilliance.isc.common.register.saveadddata.SaveDataRegisterFactory;
import com.brilliance.isc.common.register.setadddata.SetDataRegisterFactory;
import com.brilliance.isc.common.setgll.vo.SetgllVo;
import com.brilliance.isc.common.setmod.vo.PtsFeeDetailVo;
import com.brilliance.isc.common.setmod.vo.SetmodVo;
import com.brilliance.isc.common.sysmod.SysmodService;
import com.brilliance.isc.common.taskdistributor.service.TaskDistService;
import com.brilliance.isc.common.transaction.help.TransactionHelpService;
import com.brilliance.isc.common.transaction.help.TransactionServiceSet;
import com.brilliance.isc.common.transaction.vo.BaseTransactionVo;
import com.brilliance.isc.common.transaction.vo.BimdataVo;
import com.brilliance.isc.common.transaction.vo.TrnInfo;
import com.brilliance.isc.common.transaction.vo.TroStoreObjectVo;
import com.brilliance.isc.common.trndoc.service.TrndocService;
import com.brilliance.isc.common.trnism.service.TrnismService;
import com.brilliance.isc.common.trnism.vo.TrnismVo;
import com.brilliance.isc.common.trnmod.service.TrnmodService;
import com.brilliance.isc.common.trnmod.vo.TrnmodVo;
import com.brilliance.isc.common.umdmod.vo.UmdmodVo;
import com.brilliance.isc.common.util.I18nUtil;
import com.brilliance.isc.common.util.SettleExceptionUtils;
import com.brilliance.isc.common.util.StringUtils;
import com.brilliance.isc.common.util.Utils;
import com.brilliance.isc.common.vo.BizInfoVo;
import com.brilliance.isc.common.vo.PtsptaVo;
import com.brilliance.isc.common.wfmmod.service.WfmmodService;
import com.brilliance.isc.mda.dao.*;
import com.brilliance.isc.vo.remit.CpdBizInfoVo;
import com.google.common.collect.ImmutableBiMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

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

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


@Service
public class TrnmodServiceImpl implements TrnmodService {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private CounterService counterService;

    @Autowired
    private TrsMapper trsMapper;
    @Autowired
    private QueMapper queMapper;
    @Autowired
    private TrnMapper trnMapper;
    @Autowired
    private ChlrptMapper chlrptMapper;
    @Autowired
    private PublicMapper publicMapper;
    @Autowired
    private TroMapper troMapper;
    @Autowired
    private SmhMapper smhMapper;
    @Autowired
    private UsrMapper usrMapper;
    @Autowired
    private PtsMapper ptsMapper;
    @Autowired
    private PteMapper pteMapper;

    @Autowired
    private BatopnMapper batchCecmGidOpnMapper;

    @Autowired
    private SysmodService sysmodService;
    @Autowired
    private NtfmodService ntfmodService;
    @Autowired
    private PtsptaToolComponent ptsptaToolComponent;
    @Autowired
    private OrdmodService ordmodService;
    @Autowired
    private TrnismService trnismService;
    @Autowired
    private CodetableService codetableService;
    @Autowired
    private XrtmodService xrtmodService;
    @Autowired
    private DocimmService docimmService;

    @Autowired
    private WfmmodService wfmmodService;

    @Autowired
    private DyncDaoService dyncDaoService;

    @Autowired
    private TaskDistService taskDistService;

    @Autowired
    private SetDataRegisterFactory setDataRegisterFactory;

    @Autowired
    private SaveDataRegisterFactory saveDataRegisterFactory;

    @Autowired
    private CcimodService ccimodService;

    @Autowired
    private CbsmodService cbsmodService;

    @Autowired
    private TransactionHelpService transactionHelpService;

    @Autowired
    private TrndocService trndocService;

    @Autowired
    private AppEnv appEnv;

    @Autowired
    private DiaMapper diaMapper;

    @Autowired
    private SptMapper sptMapper;

    @Autowired
    private FecMapper fecMapper;

    @Autowired
    private LgToolComponent lgToolComponent;

    public TrnmodServiceImpl() {
    }

    @Override
    public void troLockContractForCBSOnly(FcdgrpVo fcdgrp) {

    }

    /**
     * @param argFlg
     * @param obj
     * @param argSigIdx
     */
    public void sigWrite(String argFlg, Object obj, String argSigIdx) {
        // Writes signature record
        Trs trs = new Trs();
        trs.setInr(counterService.dbCounterFormat("TRS"));
        // trs.setSsninr(SettleContext.getUserSession().getSsn().getInr());
        trs.setDattim(Dates.now());
        trs.setUsr(SettleContext.getUserSession().getUsr().getExtkey());
        trs.setNam(SettleContext.getUserSession().getUsr().getNam());
        trs.setFlg(argFlg);
        trs.setObjtyp(Utils.recGetObj(obj));
        trs.setObjinr(Utils.recGetInr(obj));
        trs.setSigidx(argSigIdx);
        // set entity of transaction
        String etg = "";
        Object etgObj = Utils.getFieldValue(obj, "etgextkey");
        if (etgObj != null) {
            etg = etgObj.toString();
        }
        String ety = "";
        Object etyObj = Utils.getFieldValue(obj, "etyextkey");
        if (etyObj != null) {
            ety = etyObj.toString();
        }
        Utils.sdbEtySetRec(trs, "TRS", etg, ety);
        trsMapper.insert(trs);
    }

    public void trnmodCancel(Trn trn, String argStopText, String argCanTyp) {
        //取得上下文
//        IContext ctx = MdaEnv.getContext();
//        ctx.setErrorCode(NO_ERROR);
        //! Cancel execution and exit from transaction as there are problems in execution
        //! ArgStopText : Reason of Cancel to be passed to Notify or as Prompt
        //! ArgCanTyp   : Type of cancel. Possible values are:
        //!
        //! TrnmodCancelExitWithPrompt      : Transaction is terminated after call. Prompt user (usually used in Init)
        //! TrnmodCancelExitWithoutPrompt   : Transaction is terminated after call. Don`t prompt user (usually used in Events leaving transaction)
        //!
        //! In Background an event with the stoptext is written and the transaction is interrupted. ArgCanTyp is ignored.
        //! In Foreground:
        //! 1. the user is informed about the problem with a prompt (only if ArgPromptFlag is )
        //! 2. DbFreeall is executed to free all locks if ArgPromptflag is not TrnmodCancelExitWithPrompt .
        //! 3. transaction is exited (LnkRetunrToCaller will clear SPT)
//        String dummy = NULLSTR;
//        Ssn ssn = SettleContext.getUserSession().getSsn();
//        if( MdaUtils.compareTo(ssn.getBckgrd(),"B")== 0 )
//        {
//            dummy = sysmodService.evtWrite( trn.getObjtyp(), trn.getObjinr(), "E", argStopText );
//            ntfmodService.ntfSendToUsr( SettleContext.getUserSession().getUsr().getExtkey(), NtfTypWarning, argStopText );
        // to issue the logic synchronously to handle the break function
//            ctx.absGet(Sysmod.class).lnkHandleInterruptTransaction();
//            ssn.setSta("C");
//        }
//        else
//        {
//            if( MdaUtils.compareTo(argCanTyp,TrnmodCancelExitWithPrompt) == 0 )
//            {
//                ctx.setMessage("$1",argStopText);
//            }
//            ctx.absGet(Mtabut.class).saverecgrp();
//            ctx.getDaoSession().dbExecuteSQL("Update QUE set HLDFLG=' ', HLDDATTIM = ? where HLDFLG='L' and HLDSSNINR = ?",Dates.now(),ssn.getInr());
//            queExtMapper.holdUpdate(Dates.now(),ssn.getInr());
//        }

//        ctx.getDaoSession().dbFreeAll();
//        Platform.lnkReturnToCaller();
        internalTrnmodCancel(trn, argStopText, argCanTyp);
        throw new CommonServiceException("TrnmodCancel!");
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void internalTrnmodCancel(Trn trn, String argStopText, String argCanTyp) {
        // Ssn ssn = SettleContext.getUserSession().getSsn();
        if (MdaUtils.compareTo("", "B") == 0) {
            sysmodService.evtWrite(trn.getObjtyp(), trn.getObjinr(), "E", argStopText);
            ntfmodService.ntfSendToUsr(SettleContext.getUserSession().getUsr().getExtkey(), NtfTypWarning, argStopText);
            // ssn.setSta("C");
        } else {
            queMapper.holdUpdate(Dates.now(), "");
        }
    }


    public void setTrnTxt(TrnmodVo trnmod) {
        Trn trn = trnmod.getTrn();
        Object rec = getRec();
        List<PtsptaVo> ptsList = getPtsList();
        Map<String, Cbb> cbsMap = getCbsMap();
        //取得上下文
//        IContext ctx = MdaEnv.getContext();
//        ctx.setErrorCode(NO_ERROR);
        String dflg = NULLSTR;
        String frm = NULLSTR;
        String msgtyp = NULLSTR;
        String paytyp = NULLSTR;
        String ptynam = NULLSTR;
        String ptyextkey = NULLSTR;
        Atp atp = SettleContext.getUserSession().getAtp();
        if (MdaUtils.compareTo(Strings.mid(atp.getCod(), 1, 3), "LIT") == 0 || MdaUtils.compareTo(Strings.mid(atp.getCod(), 1, 3), "LET") == 0) {
            setTrnTxtAmt(trn, cbsMap, getDocamt());
        } else {
            dflg = "";
            frm = Strings.mid(atp.getCod(), 1, 2);
            switch (frm) {
                case "DI":
                case "DE":
                    setTrnTxtAmt(trn, cbsMap, getDocamt());
                    String rol = MdaUtils.compareTo(frm, "DI") == 0 ? "APL" : "BEN";
                    PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, rol);
                    trn.setAddtxt(trn.getAddtxt() + " " + ptsptaVo.getNam() + " " + ptsptaVo.getExtkey() + " GUONEI");
                    break;
                case "BD":
                case "BF":
                    if (MdaUtils.compareTo(SettleContext.getTransName(), "BDTSET") == 0) {
                        trn.setAddtxt(trn.getAddtxt() + " " + "GUONEI");
                    } else {
                        trn.setAddtxt("GUONEI");
                    }
                    break;
                case "TR":
                case "BP":
                    dflg = Utils.getFieldValue(rec, "dflg");
                    if (MdaUtils.compareTo(dflg, "D") == 0) {
                        trn.setAddtxt("GUONEI");
                    }
                    break;
                default:
                    if (MdaUtils.compareTo(trn.getObjtyp(), "CPD") == 0) {
                        msgtyp = Utils.getFieldValue(rec, "swftyp");
                        trn.setAddtxt(msgtyp);
                        paytyp = Utils.getFieldValue(rec, "paytyp");
                        rol = MdaUtils.compareTo(paytyp, "I") == 0 ? "PYE" : "ORC";
                        ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, rol);
                        ptynam = ptsptaVo.getPtanam1();
                        ptyextkey = ptsptaVo.getExtkey();
                        if (!MdaUtils.isEmpty(ptsptaVo.getNam()) || !MdaUtils.isEmpty(ptyextkey)) {
                            trn.setAddtxt(trn.getAddtxt() + " " + ptyextkey + " " + ptynam);
                        }
                    }
            }
        }
    }

    public void trnStoreFinal(TrnmodVo trnmod) {
        // Public
        // Purpose: Finally stores the TRN after possible updates to release fields and EVTINR
        // ArgRec : Existing contract-Record
        // Check for SPT and get an INFTXT + INFDSP from there
        if (sysmodService.sptIsAnyLoaded(trnmod.getSpt().getSta()) && MdaUtils.isEmpty(trnmod.getTrn().getInftxt())) {
            trnmod.getTrn().setInfdsp(trnmod.getSpt().getInfdsp());
            trnmod.getTrn().setInftxt(trnmod.getSpt().getInftxt());
        }
        // if order processing is active, update resp. create order
        trnORDUpdate(trnmod);
        if (MdaUtils.isEmpty(trnmod.getTrn().getInr())) {
            SettleExceptionUtils.sysDump("TRN not initialized by TrnSetFromContract, Check transaction definition");
        } else {
            Trn trn = trnmod.getTrn();
            trnMapper.updateByPrimaryKeySelective(trnmod.getTrn());
            // 存文件操作// Store BIM
            BimdataVo bimdataVo = transactionHelpService.getTransactionStoreSet().getBimdataVo();
            storeBimdata(trnmod, bimdataVo);
            //          sysmodService.streamSaveInDir(bimdata, "bimdata", trn.getInr()  + ".dat");
//            Utils.streamSave(bimdata, appEnv.getFullName("DATA", "bimdata\\" + trn.getInr() + ".dat"));
        }
//        Streams.streamClear(this.getBimdata());
    }

    public void initBimdata() {
        BimdataVo bimdataVo = new BimdataVo();
        bimdataVo.reset();
        Object rec = transactionHelpService.getTransactionStoreSet().getRec();
        Object blk = transactionHelpService.getTransactionStoreSet().getBlk();
        String objtyp = Utils.recGetObj(rec);
        String objinr = Utils.recGetInr(rec);
        Object initRec = dyncDaoService.dyncReadByInr(rec.getClass(), objinr);
        List<Pts> ptsList = ptsMapper.getPtsByObjInrTyp(objinr, objtyp);
        List<Pte> pteList = pteMapper.selectByBusinessObjtypAndObjinr(objtyp, objinr);
        if (blk != null) {
            Object initBlk = dyncDaoService.dyncReadByInr(blk.getClass(), objinr);
            bimdataVo.setBlk(new TroStoreObjectVo(initBlk));
        }
        bimdataVo.setRec(new TroStoreObjectVo(initRec));
        bimdataVo.setPtsList(ptsList);
        bimdataVo.setPteList(pteList);
        //备忘录数据
        if (StringUtils.isNotEmpty(objtyp) && StringUtils.isNotEmpty(objinr)) {
            List<Dia> diaList = diaMapper.getDiaByObjtypAndObjinr(objtyp, objinr);
            if (diaList != null && diaList.size() > 0) {
                bimdataVo.getDiaList().addAll(diaList);
            }
            List<Fec> fecList = fecMapper.selectFecByObjtypAndObjinrAndFeeinrAndFeepri(objtyp, objinr, null, "6");
            if (fecList != null && fecList.size() > 0) {
                bimdataVo.getFecList().addAll(fecList);
            }
        }
        /**
         *增加EBA表初始化逻辑 后续回滚的时候 再回退下  modelListmodelList！
         */
//        Cfagit cfagitTemp = transactionHelpService.getTransactionStoreSet().getCfagit();
//        if (!MdaUtils.isEmpty(cfagitTemp)) {
//            Eba objEba = cfagitTemp.getRecgrp().getBas();
//            if (!MdaUtils.isEmpty(objEba))
//                bimdataVo.addModel(new TroStoreObjectVo(objEba));
//        }

        transactionHelpService.getTransactionStoreSet().setBimdataVo(bimdataVo);
    }

    public BimdataVo getBimdataVo(BimdataVo bimdataVo, String objinr) {
        try {
            Class recClazz = Class.forName(bimdataVo.getRec().getClassName());
            Object rec = dyncDaoService.dyncReadByInr(recClazz, objinr);
            String objtyp = Utils.recGetObj(rec);
            List<Pts> ptsList = ptsMapper.getPtsByObjInrTyp(objinr, objtyp);
            List<Pte> pteList = pteMapper.selectByBusinessObjtypAndObjinr(objtyp, objinr);
            BimdataVo newBimdataVo = new BimdataVo();
            newBimdataVo.reset();
            newBimdataVo.setRec(new TroStoreObjectVo(rec));
            if (bimdataVo.getBlk() != null) {
                Class blkClazz = Class.forName(bimdataVo.getBlk().getClassName());
                Object blk = dyncDaoService.dyncReadByInr(blkClazz, objinr);
                newBimdataVo.setBlk(new TroStoreObjectVo(blk));
            }
            newBimdataVo.setPtsList(ptsList);
            newBimdataVo.setPteList(pteList);
            //备忘录数据
            if (StringUtils.isNotEmpty(objtyp) && StringUtils.isNotEmpty(objinr)) {
                List<Dia> diaList = diaMapper.getDiaByObjtypAndObjinr(objtyp, objinr);
                if (diaList != null && diaList.size() > 0) {
                    newBimdataVo.getDiaList().addAll(diaList);
                }
                List<Fec> fecList = fecMapper.selectFecByObjtypAndObjinrAndFeeinrAndFeepri(objtyp, objinr, null, "6");
                if (fecList != null && fecList.size() > 0) {
                    newBimdataVo.getFecList().addAll(fecList);
                }
            }
            return newBimdataVo;
        } catch (Exception e) {
            throw new CommonServiceException(e.getMessage());
        }
    }

    public void storeBimdata(TrnmodVo trnmod, Object obj) {
        BimdataVo bimdataVo = transactionHelpService.getTransactionStoreSet().getBimdataVo();
        if (bimdataVo != null) {
            String bimDataJson = Utils.toPrettyJson(bimdataVo);
            sysmodService.saveObjectJson("bimdata", trnmod.getTrn().getInr() + ".dat", bimDataJson);
        }
    }

    public void storeTrndata(TrnmodVo trnmod, Object obj) {
//        TrndataVo trndataVo =transactionHelpService.getTransactionStoreSet().getTrndataVo();
        String trnDataJson = Utils.toPrettyJson(obj);
        sysmodService.saveObjectJson("trndata", trnmod.getTrn().getInr() + ".dat", trnDataJson);
    }

    public String replaceALlObjinr(String json) {
        String transName = SettleContext.getTransName();
        Object rec = transactionHelpService.getTransactionStoreSet().getRec();
        String objinr = Utils.recGetInr(rec);
        if (!StringUtils.isEmpty(objinr) && ("OPN".equalsIgnoreCase(transName.substring(3, transName.length())) || "CRQ".equalsIgnoreCase(transName.substring(3, transName.length())))) {
            return json.replaceAll(objinr, "");
        } else {
            return json;
        }
    }

    public void rollBackByBimdata(Trn trn) {
        String json = sysmodService.loadObjectJson("bimdata", trn.getInr() + ".dat");
        if (StringUtils.isEmpty(json)) {
            log.warn("没有找到bimdata文件,不会回滚数据,直接返回");
            return;
        }
        //旧的BIMDATA
        BimdataVo oldBimdataVo = new BimdataVo();
        oldBimdataVo = Utils.toObject(oldBimdataVo.getClass(), json);
        Object recObj = Utils.getObjectByMap(oldBimdataVo.getRec().getClassName(), (Map<String, Object>) oldBimdataVo.getRec().getObj());
        oldBimdataVo.setRec(new TroStoreObjectVo(recObj));
        if (oldBimdataVo.getBlk() != null) {
            Object blkObj = Utils.getObjectByMap(oldBimdataVo.getBlk().getClassName(), (Map<String, Object>) oldBimdataVo.getBlk().getObj());
            oldBimdataVo.setBlk(new TroStoreObjectVo(blkObj));
        }

        //新的BIMDATA
        BimdataVo newBimdataVo = getBimdataVo(oldBimdataVo, trn.getObjinr());
        rollBackRecBlk(oldBimdataVo.getRec().getObj(), newBimdataVo.getRec().getObj());
        if (oldBimdataVo.getBlk() != null) {
            rollBackRecBlk(oldBimdataVo.getBlk().getObj(), newBimdataVo.getBlk().getObj());
        }
        rollBackPts(oldBimdataVo.getPtsList(), newBimdataVo.getPtsList());
        rollBackPte(oldBimdataVo.getPteList(), newBimdataVo.getPteList());
        rollBackDia(oldBimdataVo.getDiaList(), newBimdataVo.getDiaList());
        rollBackFec(oldBimdataVo.getFecList(), newBimdataVo.getFecList());
        //更新需要更新的模型
        List<TroStoreObjectVo> updateModelList = oldBimdataVo.getModelList();
        if (updateModelList != null && updateModelList.size() > 0) {
            updateModelList.forEach(model -> {
                Object modelObj = Utils.getObjectByMap(model.getClassName(), (Map<String, Object>) model.getObj());
                sysmodService.sdbUpdateWithLog2(modelObj);
            });
        }
        //删除需要删除的模型
        List<TroStoreObjectVo> deleteModelList = oldBimdataVo.getDeleteModelList();
        if (deleteModelList != null && deleteModelList.size() > 0) {
            deleteModelList.forEach(model -> {
                Object modelObj = Utils.getObjectByMap(model.getClassName(), (Map<String, Object>) model.getObj());
                sysmodService.sdbDeleteWithLog(modelObj);
            });
        }
    }

    public void rollBackRecBlk(Object oldVo, Object newVo) {
        if (Utils.isEmpty(oldVo) && !Utils.isEmpty(newVo)) {
            sysmodService.sdbDeleteWithLog(newVo);
        }
        if (!Utils.isEmpty(oldVo) && !Utils.isEmpty(newVo)) {
            dyncDaoService.dyncUpdateByPrimaryKey(oldVo);
        }
        if (!Utils.isEmpty(oldVo) && Utils.isEmpty(newVo)) {
            dyncDaoService.dyncInsert(oldVo);
        }
    }

    public void rollBackPts(List<Pts> oldPtsList, List<Pts> newPtsList) {
        //删除当前业务数据
        if (newPtsList != null) {
            newPtsList.forEach(pts -> {
                if (!Utils.isEmpty(pts)) {
                    sysmodService.sdbDeleteWithLog(pts);
                }
            });
        }
        //恢复备份数据
        if (oldPtsList != null) {
            oldPtsList.forEach(pts -> {
                if (!Utils.isEmpty(pts)) {
                    dyncDaoService.dyncInsert(pts);
                }
            });
        }
    }

    public void rollBackPte(List<Pte> oldPteList, List<Pte> newPteList) {
        //删除当前业务数据
        if (newPteList != null) {
            newPteList.forEach(pte -> {
                if (!Utils.isEmpty(pte)) {
                    sysmodService.sdbDeleteWithLog(pte);
                }
            });
        }
        //恢复备份数据
        if (oldPteList != null) {
            oldPteList.forEach(pte -> {
                if (!Utils.isEmpty(pte)) {
                    dyncDaoService.dyncInsert(pte);
                }
            });
        }
    }

    public void rollBackDia(List<Dia> oldDiaList, List<Dia> newDiaList) {
        //删除当前业务数据
        if (newDiaList != null && newDiaList.size() > 0) {
            newDiaList.forEach(dia -> sysmodService.sdbDeleteWithLog(dia));
        }
        //恢复备份数据
        if (oldDiaList != null && oldDiaList.size() > 0) {
            oldDiaList.forEach(dia -> diaMapper.insert(dia));
        }
    }

    public void rollBackFec(List<Fec> oldFecList, List<Fec> newFecList) {
        //删除当前业务数据
        if (newFecList != null && newFecList.size() > 0) {
            newFecList.forEach(fec -> sysmodService.sdbDeleteWithLog(fec));
        }
        //恢复备份数据
        if (oldFecList != null && oldFecList.size() > 0) {
            oldFecList.forEach(fec -> fecMapper.insert(fec));
        }
    }

    public void rollBackModelList(List<TroStoreObjectVo> oldModelList, List<TroStoreObjectVo> newModelList) {
        //删除当前业务数据
        if (newModelList != null) {
            newModelList.forEach(model -> {
                if (!Utils.isEmpty(model.getObj())) {
                    sysmodService.sdbDeleteWithLog(model.getObj());
                }
            });
        }
        //恢复备份数据
        if (oldModelList != null) {
            oldModelList.forEach(model -> {
                if (!Utils.isEmpty(model.getObj())) {
                    dyncDaoService.dyncInsert(model.getObj());
                }
            });
        }
    }

    public void updateChlrpt(Trn trn, Smh smh) {
        String smhinr = smh.getInr();
        String inr = "";
//        Argument<String> _inrBox = Argument.box(inr);
//        ctx.getDaoSession().dbExecuteSQL("Select INR from chlrpt where smhinr = ?",ctx.absGet(Trnmod.class).getSmh().getInr());
//        ctx.getDaoSession().dbFetchFields("",_inrBox);
//        inr = _inrBox.value;
//        int err = ctx.getErrorCode();
//        ctx.getDaoSession().dbCloseCursor();
        String sql = "Select INR from chlrpt where smhinr = '" + smhinr + "'";
        inr = publicMapper.dyncQueryStr(ImmutableBiMap.of("sql", sql));
        String trninr = NULLSTR;
        String ownref = NULLSTR;
        if (!MdaUtils.isEmpty(inr)) {
            Chlrpt chlrpt = new Chlrpt();
            chlrpt.setTrninr(trn.getInr());
            chlrpt.setOwnref(trn.getOwnref());
            chlrpt.setInr(inr);
//            ctx.getDaoSession().dbExecuteSQL("update chlrpt set TRNINR=?,OWNREF=? where inr = ?",trninr,ownref,inr);
            chlrptMapper.updateByPrimaryKey(chlrpt);
        }

    }

    /**
     * @param trn       \TRNMOD\TRN
     * @param trorescon \TRNMOD\TRORESCON
     */
    public void troCommit(Trn trn, IStream trorescon) {
        troProcessLockTable(trorescon, "C", trn);
    }

    /**
     * @param trn
     * @param ord
     * @param relusr   //\MATBUT\CONINF\RELUSR
     * @param objsubid //\TRNMOD\ORR\OBJSUBID 数据字典标注该字段暂未使用，传null即可。
     */
    public void trnQUECreate(Trn trn, Ord ord, String relusr, String objsubid) {
        Date date = new Date();
        if (MdaUtils.compareTo(trn.getRelflg(), "W") == 0) {
            for (int sigidx = 1; sigidx <= Strings.len(trn.getRelreq()); sigidx++) {
                if (MdaUtils.compareTo(Strings.mid(trn.getRelreq(), sigidx, 1), Strings.mid(trn.getRelres(), sigidx, 1)) != 0) {
                    Que que = queMapper.selectByObjTypeInrSubId("TRN", trn.getInr(), MdaUtils.toString(sigidx));
                    if (que == null) {
                        que = new Que();
                        que.setObjtyp("TRN");
                        que.setObjinr(trn.getInr());
                        que.setObjsubid(MdaUtils.toString(sigidx));
                    }
                    que.setCla("REL");
                    que.setConobjtyp(trn.getObjtyp());
                    que.setConobjinr(trn.getObjinr());
                    que.setObjnam(trn.getObjnam());
                    que.setCtmnam(trn.getObjnam());
                    que.setObjref(trn.getOwnref());
                    que.setFrm(trn.getInifrm());
                    que.setTxt(codetableService.getTblLabel(trn.getInifrm(), "ATPTXT"));
                    que.setRelamt(trn.getReloriamt());
                    que.setRelcur(trn.getReloricur());
                    que.setXrfamt(trn.getRelamt());
                    que.setXrfcur(trn.getRelcur());
                    que.setStatus(CommonContants.QUE_STATUS_WAITING);
                    que.setBranchinr(trn.getBranchinr());
                    que.setBchkeyinr(trn.getBchkeyinr());
                    Bch accBch = SettleContext.getUserSession().getBch();
                    que.setAccbchinr(accBch != null ? accBch.getInr() : "");
                    que.setCreateTime(date);
                    que.setUpdateTime(date);
                    que.setRelflg(trn.getRelflg());
                    que.setRelreq(trn.getRelreq() + ":" + trn.getRelreq0() + "-" + trn.getRelreq1() + "-" + trn.getRelreq2());
                    que.setRelres(trn.getRelres() + ":" + trn.getRelres0() + "-" + trn.getRelres1() + "-" + trn.getRelres2());
                    que.setSdhflg(ord.getSdhflg());
                    que.setOrdinr(ord.getInr());
                    Bch orgBch = SettleContext.getUserSession().getOrgBch();
                    if (MdaUtils.compareTo(que.getBalflg(), "M") != 0 && MdaUtils.compareTo(que.getBalflg(), "U") != 0) {
                        que.setBalflg("C");
                        que.setSlacla(ord.getSlacla());
                        que.setBalcla("zzz");
                    }
                    que.setTardattim(trn.getInidattim());
                    que.setUsg(trn.getUsg());
                    if (!MdaUtils.isEmpty(relusr)) {
                        if (MdaUtils.compareTo(que.getObjsubid(), objsubid) == 0 || MdaUtils.isEmpty(objsubid)) {
                            // set user for release if available
                            que.setUsrcon(trn.getIniusr());
                        }
                    }
                    if ("1000".equals(orgBch.getBranch())) {
                        if ("X".equals(ord.getSdhflg())) {
                            que.setFlowstatus(TaskFlowStatus.HEADQUARTER_SDH_FIRST_RELEASE.getValue());
                        } else {
                            que.setFlowstatus(TaskFlowStatus.HEADQUARTER_FIRST_RELEASE.getValue());
                        }
                    } else {
                        que.setFlowstatus(TaskFlowStatus.BRANCH_FIRST_RELEASE.getValue());
                    }
                    if (MdaUtils.isEmpty(que.getInr())) {
                        sysmodService.sdbInsert(que);
                        taskDistService.handleTaskEnqueue(que);
                    } else {
                        queMapper.updateByPrimaryKeySelective(que);
                    }
                }
            }
        }

    }

    /**
     * source:trnmod.0046.script
     */
    public void troStoreInBimForUndo(TrnmodVo trnmod, Object argObj, String argUndoStaOnly) {
        //! Stores ArgMod to BimData in order and remember it for undo in TRNREL
        //! If ArgUndoStaonly is set, the undo is only done with this type of Rollback (e.g. "R" is used for SPT to undo only if Rejected; not if sent to correct)
        //! Argmod has to hold an INR
        //! In addition it has to hold OBJTYP. If this is empty, the row is deleted on undo in TRNREL
        //! The caller is responsible for locking Argmod.
        //! If used, the Object Type of Argmod has to be available in BIMEMU to allow TRNREL to roll back
        // store information in TRNBIM\\BIMUDOSTM
        Streams.streamInsert(trnmod.getTrnbim().getBimudostm(), 0, Utils.recGetObj(argObj) + TAB + Utils.recGetInr(argObj) + TAB + argUndoStaOnly);
        // store Argmod in BIMDATA
//        troStoreInBim(argObj);
    }

    /**
     * source:trnmod.0045.script
     */
    public void troStoreInBim(TrnmodVo trnmod, Object argObj) {
        //! private function to store Argmod in BIM to allow Rollback in TRNREL
        //! This is used by TroLoadContract (for Load of contract groups)
        String objInr = Utils.recGetInr(argObj);
        String dataLabel = NULLSTR;
        if (MdaUtils.isEmpty(objInr)) {
            SettleExceptionUtils.sysDump("TrnStoreInBim : Argument " + /*Platform.recGetPath(argMod)*/argObj.getClass() + " does not hold an INR");
        } else {
            dataLabel = troGetBimLabel(Utils.recGetObj(argObj), objInr);
            //Systems.setContext("SAVEDATASKIPEMPTY",true);
            Utils.saveData(argObj, trnmod.getBimdata(), dataLabel, "");
            //Systems.setContext("SAVEDATASKIPEMPTY",false);
        }

    }

    public void troStoreInBim(Object argObj) {
        //! private function to store Argmod in BIM to allow Rollback in TRNREL
        //! This is used by TroLoadContract (for Load of contract groups)
        TroStoreObjectVo modelVo = new TroStoreObjectVo();
        modelVo.setObj(argObj);
        modelVo.setClassName(argObj.getClass().getName());
        String objInr = Utils.recGetInr(argObj);
        if (MdaUtils.isEmpty(objInr)) {
            SettleExceptionUtils.sysDump("TrnStoreInBim : Argument " + argObj.getClass() + " does not hold an INR");
        }
        transactionHelpService.getTransactionStoreSet().getBimdataVo().addModel(modelVo);
    }

    /**
     * source:trnmod.0040.script
     */
    public String troGetBimLabel(String objTyp, String objInr) {
        // Public
        // Label of contract OBJTYP / INR in Before image streams
        return objTyp + "#" + objInr;
    }

    private void troProcessLockTable(IStream lckTblStm, String flag, Trn trn) {
        // lckTblStm
        int cnt = Streams.streamCount(lckTblStm);
        String lin = NULLSTR;
        String objId = NULLSTR;
        String objInr = NULLSTR;
        String objTyp = NULLSTR;
        int staFlg = 0;
        if (cnt > 0) {
            for (int i = 1; i <= cnt; i++) {
                lin = Strings.getLine(lckTblStm, i);
                objId = Strings.mid(lin, 1, Strings.pos(lin, TAB) - 1);
                objInr = Strings.mid(objId, 1, 16);
                objTyp = Strings.mid(objId, 17, Strings.len(objId) - 16);
                staFlg = Strings.parseInt(Strings.mid(lin, Strings.pos(lin, TAB) + 1));
                if (MdaUtils.compareTo(flag, "C") == 0 && staFlg == 3) {
                    troWriteEntry(objTyp, objInr, trn.getInr());
                }
            }
        }
        MdaUtils.clear(lckTblStm);
    }

    private Tro troWriteEntry(String objTyp, String objInr, String trnInr) {
        // sets TRN as last modifing transaction of contract
        if (MdaUtils.isEmpty(objInr)) {
//            Platform.sysDump("Can not insert contract without INR in SRO");
            SettleExceptionUtils.sysDump("Can not insert contract without INR in SRO");
            return null;
        }

        // Is already a last TRN stored for this contract?
//        String sql = Platform.sdbEtyGenSql(this.getTro(),"where OBJTYP = " + Platform.sqlLit(objTyp) + " AND OBJINR = " + Platform.sqlLit(objInr) + " AND LSTFLG = 'X'");
//        ctx.getDaoSession().dbReadHold(this.getTro(),sql);
        Tro tro = new Tro();
//        if ("-GITPCR-GETPCR-GITCRQ-GETCRQ-".indexOf(SettleContext.getTransName()) > 0) {
//            Gcd rec = (Gcd) transactionHelpService.getTransactionStoreSet().getRec();
//            objTyp = rec.getPnttyp();
//            objInr = rec.getPntinr();
//        }
//        if ("-NITPCR-NETPCR-NITCRQ-NETCRQ-".indexOf(SettleContext.getTransName()) > 0) {
//            Ncd rec = (Ncd) transactionHelpService.getTransactionStoreSet().getRec();
//            objTyp = rec.getPnttyp();
//            objInr = rec.getPntinr();
//        }

        String sql = Utils.sdbEtyGenSql("TRO", String.format("WHERE OBJTYP = '%s' AND OBJINR = '%s' AND LSTFLG = 'X'", objTyp, objInr));
        List<Tro> troList = troMapper.selectTroByConditionSql(sql);
        if (troList.size() == 0) {
            tro.setTrninr(trnInr);
            tro.setObjtyp(objTyp);
            tro.setObjinr(objInr);
            tro.setLstflg("X");
            tro.setInr(counterService.dbCounterFormat("TRO"));
            troMapper.insert(tro);
        } else {
            tro = troList.get(0);
            if (MdaUtils.compareTo(tro.getTrninr(), trnInr) != 0) {
                // clear the LSTFLG in the old one.
                tro.setLstflg(NULLSTR);
                troMapper.updateByPrimaryKeySelective(tro);
                // the old one is now a predecessor of the new.
                tro.setPrvinr(tro.getTrninr());
                tro.setTrninr(trnInr);
                tro.setObjtyp(objTyp);
                tro.setObjinr(objInr);
                tro.setLstflg("X");
                tro.setInr(counterService.dbCounterFormat("TRO"));
                troMapper.insert(tro);
            }
        }
        return tro;
    }

    /**
     * source:trnmod.0078.script
     */
    public void trnORDUpdate(TrnmodVo trnmod) {
        //! Update ORD in TrnStoreFinal and set TRN\\ORDINR
        Ord ord = trnmod.getOrdmod().getOrd();
        Trn trn = trnmod.getTrn();
        Ore ore = trnmod.getOrdmod().getOre();
        if (MdaUtils.compareTo(trnmod.getOrdmod().getOrdinr(), "NEW") == 0) {
            // ORD created on demand, fill additional fields
            ord.setOwnusg(trn.getUsg());
            ord.setOwnusr(trn.getUsr());
            ord.setSmhinr(trnmod.getSmh().getInr()); // incoming message
            ord.setExtkey(trn.getOwnref() + "/" + Formats.format(ore.getBegdattim(), "YYMMDD") + "/" + trn.getInifrm());
            if (StringUtils.isNotEmpty(trn.getObjnam())) {
                if (trn.getObjnam().length() > 60) {
                    //防止字段超长
                    ord.setNam(trn.getObjnam().substring(0, 60));
                } else {
                    ord.setNam(trn.getObjnam());
                }
            }
            ord.setBchkeyinr(SettleContext.getUserSession().getBch().getInr());
            ord.setBranchinr(SettleContext.getUserSession().getWrkbch().getInr());
            ord.setFrm(SettleContext.getTransName());
            if ("1000".equals(SettleContext.getUserSession().getOrgBch().getBranch()) && StringUtils.isEmpty(ord.getSdhflg())) {
                //押汇中心经办替收单行经办分行业务做的处理
                ord.setSdhflg("X");
            }
        }
        if (MdaUtils.compareTo(Strings.toUpper(Strings.mid(ord.getExtkey(), 1, 7)), "NONREF/") == 0) {
            // update ORD\\EXTKEY, as TRN fields could be changed
            ord.setExtkey(trn.getOwnref() + "/" + Strings.mid(ord.getExtkey(), 8));
        }
        // set ORD object = contract (in case is was just created)
        ord.setObjtyp(trn.getObjtyp());
        ord.setObjinr(trn.getObjinr());
        if ("X".equals(ord.getSdhflg()))
            ordmodService.ordUpdate(trnmod.getOrdmod(), "CMT");
        else
            ordmodService.ordUpdate(trnmod.getOrdmod(), "TRN");
        trn.setOrdinr(ord.getInr());
    }


    private void setTrnTxtAmt(Trn trn, Map<String, Cbb> cbsMap, BigDecimal docamt) {
        Cbb cbb = cbsMap.getOrDefault("NOM1", cbsMap.get("OPN1"));
        if (cbb != null) {
            trn.setAddtxt(StringUtils.toString(cbb.getAmt()));
        } else {
            trn.setAddtxt(StringUtils.toString(docamt));
        }
    }

    public void setWfsRelease(TrnmodVo trnmodVo) {
        //取得上下文
        //IContext ctx = MdaEnv.getContext();
        //ctx.setErrorCode(NO_ERROR);
        //! Used to set release data depending on ATP definition
        //! 1 : Standard rule `Set_Wfs_Release` in transaction is used
        //! 2 : Signature required with amount specified in ATP
        //! 3 : No release required
        switch (SettleContext.getUserSession().getAtp().getReltyp()) {
            case "1":
                // if standard rule does not set the mandatory fields create a dump
                if (MdaUtils.isEmpty(trnmodVo.getTrn().getRelreq()) || MdaUtils.isEmpty(trnmodVo.getTrn().getReloricur())) {
                    SettleExceptionUtils.sysDump("TRNMOD.SetWfsRelease: Set_Wfs_Release is not correct specified.");
                }
                break;
            case "2":
                setWfsAmount(trnmodVo);
                trnismService.setRelRequest(trnmodVo.getTrn(), trnmodVo, getCbsMap());
                //    TRNISM.SetUsg
                // Product view release required
                //    TRN\\RELREQ = "A"
                // or customer specific rule to determine the value for TRN\\RELREQ
                break;
            case "3":
                trnmodVo.getTrn().setRelreq("");
                trnmodVo.getTrn().setReloricur("");
                trnmodVo.getTrn().setReloriamt(new BigDecimal("0"));
                trnmodVo.getTrn().setRelcur("");
                trnmodVo.getTrn().setRelamt(new BigDecimal("0"));
                break;
            default:
                SettleExceptionUtils.sysDump("TRNMOD.SetWfsRelease: no customer specific function defined. Please check ATP entry.");
        }
        //非收单交易存入WFE工作流
        if (!sysmodService.isSdhBusiness()) {
            trnismService.wfmAdd_Release(trnmodVo);
        }
    }

    /**
     * 设置 复核数据的原始币种和原始金额
     */
    public void setWfsAmount(TrnmodVo trnmodVo) {
        Cbb cbb = null;
        Cbb cbb2 = null;
        switch (SettleContext.getUserSession().getAtp().getRelamt()) {
            case "M":     // Maximum Amount
                cbb = getCbsMap().get("MAX");
                if (cbb != null) {
                    trnmodVo.getTrn().setReloricur(cbb.getCur());
                    trnmodVo.getTrn().setReloriamt(cbb.getAmt());
                }
                break;
            case "O":     // Open Amount
                cbb = getCbsMap().get("OPN1");
                if (cbb != null) {
                    trnmodVo.getTrn().setReloricur(cbb.getCur());
                    trnmodVo.getTrn().setReloriamt(cbb.getAmt());
                }
                break;
            case "N":     // Nominal Amount
                cbb = getCbsMap().get("NOM1");
                if (cbb != null) {
                    trnmodVo.getTrn().setReloricur(cbb.getCur());
                    trnmodVo.getTrn().setReloriamt(cbb.getAmt());
                }
                break;
            case "A":     // Maximum Amount with additional Amount
                cbb = getCbsMap().get("MAX");
                cbb2 = getCbsMap().get("MAX2");
                if (cbb != null) {
                    trnmodVo.getTrn().setReloricur(cbb.getCur());
                    if (cbb2 != null) {
                        trnmodVo.getTrn().setReloriamt(cbb.getAmt().add(cbb2.getAmt()));
                    } else {
                        trnmodVo.getTrn().setReloriamt(cbb.getAmt());
                    }
                }
                break;
            case "P":     // Open Amount with additional Amount
                cbb = getCbsMap().get("OPN1");
                cbb2 = getCbsMap().get("OPN2");
                if (cbb != null) {
                    trnmodVo.getTrn().setReloricur(cbb.getCur());
                    if (cbb2 != null) {
                        trnmodVo.getTrn().setReloriamt(cbb.getAmt().add(cbb2.getAmt()));
                    } else {
                        trnmodVo.getTrn().setReloriamt(cbb.getAmt());
                    }
                }
                if (StringUtils.isEmpty(trnmodVo.getTrn().getReloricur())) {
                    cbb = getCbsMap().get("MAX");
                    cbb2 = getCbsMap().get("MAX2");
                    if (cbb != null) {
                        trnmodVo.getTrn().setReloricur(cbb.getCur());
                        if (cbb2 != null) {
                            trnmodVo.getTrn().setReloriamt(cbb.getAmt().add(cbb2.getAmt()));
                        } else {
                            trnmodVo.getTrn().setReloriamt(cbb.getAmt());
                        }
                    }

                }
                break;
            case "C":     // Confirmation Amount
                cbb = getCbsMap().get("CNF");
                if (cbb != null) {
                    trnmodVo.getTrn().setReloricur(cbb.getCur());
                    trnmodVo.getTrn().setReloriamt(cbb.getAmt());
                }
                break;
            case "S":     // Document Amount
                /**
                 if GetFramename == "MCTFEE" then
                 TRN\\RELORICUR = GetContent( "\\\\SETCUR" )
                 TRN\\RELORIAMT = GetContentNumeric( "\\\\SETAMT" )
                 else
                 **/
//                trnmodVo.getTrn().setReloricur( Datas.getContent(this,"\\SETMOD\\DOCCUR"));
//                trnmodVo.getTrn().setReloriamt( Datas.getContentNumeric(this,"\\SETMOD\\DOCAMT"));
                trnmodVo.getTrn().setReloricur(getDoccur());
                trnmodVo.getTrn().setReloriamt(getDocamt());
                //endif
                break;
            case "T":     // No AmounT
                trnmodVo.getTrn().setReloricur("");
                trnmodVo.getTrn().setReloriamt(new BigDecimal("0"));
                break;
        }
        trnmodVo.getTrn().setRelcur(xrtmodService.sysiso());
        trnmodVo.getTrn().setRelamt(xrtmodService.sysCurEqu(trnmodVo.getTrn().getReloricur(), trnmodVo.getTrn().getReloriamt(), Dates.today()));
    }

    public void setWfsAmount(Trn trn) {
        Cbb cbb = null;
        Cbb cbb2 = null;
        switch (SettleContext.getUserSession().getAtp().getRelamt()) {
            case "M":     // Maximum Amount
                cbb = getCbsMap().get("MAX");
                if (cbb != null) {
                    trn.setReloricur(cbb.getCur());
                    trn.setReloriamt(cbb.getAmt());
                }
                break;
            case "O":     // Open Amount
                cbb = getCbsMap().get("OPN1");
                if (cbb != null) {
                    trn.setReloricur(cbb.getCur());
                    trn.setReloriamt(cbb.getAmt());
                }
                break;
            case "N":     // Nominal Amount
                cbb = getCbsMap().get("NOM1");
                if (cbb != null) {
                    trn.setReloricur(cbb.getCur());
                    trn.setReloriamt(cbb.getAmt());
                }
                break;
            case "A":     // Maximum Amount with additional Amount
                cbb = getCbsMap().get("MAX");
                cbb2 = getCbsMap().get("MAX2");
                if (cbb != null) {
                    trn.setReloricur(cbb.getCur());
                    if (cbb2 != null) {
                        trn.setReloriamt(cbb.getAmt().add(cbb2.getAmt()));
                    } else {
                        trn.setReloriamt(cbb.getAmt());
                    }
                }
                break;
            case "P":     // Open Amount with additional Amount
                cbb = getCbsMap().get("OPN1");
                cbb2 = getCbsMap().get("OPN2");
                if (cbb != null) {
                    trn.setReloricur(cbb.getCur());
                    if (cbb2 != null) {
                        trn.setReloriamt(cbb.getAmt().add(cbb2.getAmt()));
                    } else {
                        trn.setReloriamt(cbb.getAmt());
                    }
                }
                if (StringUtils.isEmpty(trn.getReloricur())) {
                    cbb = getCbsMap().get("MAX");
                    cbb2 = getCbsMap().get("MAX2");
                    if (cbb != null) {
                        trn.setReloricur(cbb.getCur());
                        if (cbb2 != null) {
                            trn.setReloriamt(cbb.getAmt().add(cbb2.getAmt()));
                        } else {
                            trn.setReloriamt(cbb.getAmt());
                        }
                    }

                }
                break;
            case "C":     // Confirmation Amount
                cbb = getCbsMap().get("CNF");
                if (cbb != null) {
                    trn.setReloricur(cbb.getCur());
                    trn.setReloriamt(cbb.getAmt());
                }
                break;
            case "S":     // Document Amount
                /**
                 if GetFramename == "MCTFEE" then
                 TRN\\RELORICUR = GetContent( "\\\\SETCUR" )
                 TRN\\RELORIAMT = GetContentNumeric( "\\\\SETAMT" )
                 else
                 **/
                if (transactionHelpService.getTransactionStoreSet().getSetmodVo() == null) {
                    cbb = getCbsMap().get("OPN1");
                    cbb2 = getCbsMap().get("OPN2");
                    if (cbb != null) {
                        trn.setReloricur(cbb.getCur());
                        if (cbb2 != null) {
                            trn.setReloriamt(cbb.getAmt().add(cbb2.getAmt()));
                        } else {
                            trn.setReloriamt(cbb.getAmt());
                        }
                    }
                    if (StringUtils.isEmpty(trn.getReloricur())) {
                        cbb = getCbsMap().get("MAX");
                        cbb2 = getCbsMap().get("MAX2");
                        if (cbb != null) {
                            trn.setReloricur(cbb.getCur());
                            if (cbb2 != null) {
                                trn.setReloriamt(cbb.getAmt().add(cbb2.getAmt()));
                            } else {
                                trn.setReloriamt(cbb.getAmt());
                            }
                        }
                    }
                } else {
                    trn.setReloricur(getDoccur());
                    trn.setReloriamt(getDocamt());
                }
                //endif
                break;
            case "T":     // No AmounT
                trn.setReloricur("");
                trn.setReloriamt(new BigDecimal("0"));
                break;
        }
        trn.setRelcur(xrtmodService.sysiso());
        trn.setRelamt(xrtmodService.sysCurEqu(trn.getReloricur(), trn.getReloriamt(), Dates.today()));
    }

    public void smhUpdate(TrnmodVo trnmodVo) {
        //! Set TRNINR,OBJTYP and INR in SMH picked up (incl. all SMH of multipart message)
//        IStream iNRStream = new StreamImpl();
//        int stmCnt = 0;
        String inr = NULLSTR;
        String sdate = NULLSTR;
        IStream stm = new StreamImpl();
        String stoday = NULLSTR;
//        IPanel docpan = null;
        String docfdr = NULLSTR;
        String sql = NULLSTR;
        List<String> smhs = new ArrayList<>();
        if (!MdaUtils.isEmpty(trnmodVo.getSmh().getInr())) {
            if (MdaUtils.isEmpty(trnmodVo.getSmh().getGrpinr())) {
//                Streams.streamSet(iNRStream, trnmodVo.getSmh().getInr());
                smhs.add(trnmodVo.getSmh().getInr());
            } else {
//                Streams.streamClear(iNRStream);
//                ctx.getDaoSession().dbExecuteSQL("Select INR from SMH where GRPINR = ?",ctx.absGet(Trnmod.class).getSmh().getGrpinr());
//                ctx.getDaoSession().dbFetchStream(iNRStream);
//                ctx.getDaoSession().dbCloseCursor();
                Map<String, Object> dyncMap = new HashMap<>();
                sql = "Select INR from SMH where GRPINR = '" + trnmodVo.getSmh().getGrpinr() + "'";
                dyncMap.put("sql", sql);
                smhs = publicMapper.dyncQueryStrList(dyncMap);
//                if ( smhs != null && smhs.size() > 0) {
//                    for (String smhinr : smhs) {
//                        iNRStream.addLine(smhinr);
//                    }
//                }

            }
//            stmCnt = Streams.streamCount(iNRStream);
            for (int idx = 0; idx < smhs.size(); idx++) {
//                inr = Strings.getLine(iNRStream, idx);
//                Platform.sdbReadHold(this.getSmh(),inr);
                inr = smhs.get(idx);
                Smh smhQry = new Smh();
                smhQry.setInr(inr);
                smhQry = smhMapper.selectByPrimaryKey(smhQry);
                if (null != smhQry) {
                    trnmodVo.setSmh(smhQry);
                    trnmodVo.getSmh().setTrninr(trnmodVo.getTrn().getInr());
                    trnmodVo.getSmh().setObjtyp(trnmodVo.getTrn().getObjtyp());
                    trnmodVo.getSmh().setObjinr(trnmodVo.getTrn().getObjinr());
                    trnmodVo.getSmh().setTrntyp("TRN");
                    /**
                     if GetFramename == "CPTADV" then
                     **/
                    if (MdaUtils.compareTo(SettleContext.getTransName(), "CPTADV") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "CPTECI") == 0) {
                        /**
                         if Pos( "-CMT100-PKG001-PKG005-hvps111-hvps112-beps121-beps122-beps125-", SMH\\MSGTYP ) > 0 then
                         **/
                        if (Strings.pos("-CMT100-PKG001-PKG005-hvps111-hvps112-hvps115-beps121-beps122-beps125-", trnmodVo.getSmh().getMsgtyp()) > 0) {
                            Streams.streamClear(stm);
                            Streams.streamClear(trnmodVo.getDoctxt());
                            stoday = Formats.format(Dates.today(), "YYYYMMDD");
                            sdate = Strings.mid(stoday, 1, 6);
                            trnmodVo.getSmh().setDocpth("DOCS" + "\\" + sdate);
                            trnmodVo.getSmh().setDocfil(trnmodVo.getSmh().getInr());
                            if ("CIPS".equals(trnmodVo.getSmh().getDocfxt()) || "CNAP".equals(trnmodVo.getSmh().getDocfxt()) || "FXPS".equals(trnmodVo.getSmh().getDocfxt()) ||
                                    "HVPS".equals(trnmodVo.getSmh().getDocfxt()) || "SWTE".equals(trnmodVo.getSmh().getDocfxt()) || "CIPE".equals(trnmodVo.getSmh().getDocfxt()) || "FXPE".equals(trnmodVo.getSmh().getDocfxt())) {
                            }else {
                                trnmodVo.getSmh().setDocfxt("XML");
                            }
                            trnmodVo.getSmh().setCortyp("LET");
//                            docpan = Systems.getPanel("\\CMTPAYL1")
                            docfdr = docimmService.getDocumentFdr(trnmodVo.getSmh());
                            Utils.saveData(trnmodVo.getSmh(), stm, "", "");
//                            Streams.saveTextStream(trnmodVo.getDoctxt(), docpan, 2);
//                            Datas.loadData(trnmodVo.getSmh(), stm);
                            appEnv.streamSaveInDirectory(trnmodVo.getDoctxt(), docfdr);
                        }
                        /**
                         if Pos( "-cips111-cips112-", SMH\\MSGTYP ) > 0 then
                         **/
                        if (Strings.pos("-cips111-cips112-cips113-", trnmodVo.getSmh().getMsgtyp()) > 0) {
                            Streams.streamClear(stm);
                            Streams.streamClear(trnmodVo.getDoctxt());
                            stoday = Formats.format(Dates.today(), "YYYYMMDD");
                            sdate = Strings.mid(stoday, 1, 6);
                            trnmodVo.getSmh().setDocpth("DOCS" + "\\" + sdate);
                            trnmodVo.getSmh().setDocfil(trnmodVo.getSmh().getInr());
                            if ("CIPS".equals(trnmodVo.getSmh().getDocfxt()) || "CNAP".equals(trnmodVo.getSmh().getDocfxt()) || "FXPS".equals(trnmodVo.getSmh().getDocfxt()) ||
                                    "HVPS".equals(trnmodVo.getSmh().getDocfxt()) || "SWTE".equals(trnmodVo.getSmh().getDocfxt()) || "CIPE".equals(trnmodVo.getSmh().getDocfxt()) || "FXPE".equals(trnmodVo.getSmh().getDocfxt())) {
                            }else {
                                trnmodVo.getSmh().setDocfxt("XML");
                            }
                            trnmodVo.getSmh().setCortyp("LET");
                            //         $docpan = GetPanel( "\\\\CMTPAYL1" )
//                            docpan = Systems.getPanel("\\CIPSPAN");
                            docfdr = docimmService.getDocumentFdr(trnmodVo.getSmh());
                            Utils.saveData(trnmodVo.getSmh(), stm, "", "");
//                            Streams.saveTextStream(trnmodVo.getDoctxt(), docpan, 2);
//                            Datas.loadData(trnmodVo.getSmh(), stm);
                            appEnv.streamSaveInDirectory(trnmodVo.getDoctxt(), docfdr);
                        }
                    } else {
                        if (MdaUtils.compareTo(SettleContext.getTransName(), "CPTATI") == 0) {
                            sdate = "";
                            Streams.streamClear(stm);
                            Streams.streamClear(trnmodVo.getDoctxt());
                            stoday = Formats.format(Dates.today(), "YYYYMMDD");
                            sdate = Strings.mid(stoday, 1, 6);
                            trnmodVo.getSmh().setDocpth("DOCS" + "\\" + sdate);
                            trnmodVo.getSmh().setDocfil(trnmodVo.getSmh().getInr());
                            if ("CIPS".equals(trnmodVo.getSmh().getDocfxt()) || "CNAP".equals(trnmodVo.getSmh().getDocfxt()) || "FXPS".equals(trnmodVo.getSmh().getDocfxt()) ||
                                    "HVPS".equals(trnmodVo.getSmh().getDocfxt()) || "SWTE".equals(trnmodVo.getSmh().getDocfxt()) || "CIPE".equals(trnmodVo.getSmh().getDocfxt()) || "FXPE".equals(trnmodVo.getSmh().getDocfxt())) {
                            }else {
                                trnmodVo.getSmh().setDocfxt("XML");
                            }
                            trnmodVo.getSmh().setCortyp("LET");
//                            docpan = Systems.getPanel("\\FMTPAYL1");
                            docfdr = docimmService.getDocumentFdr(trnmodVo.getSmh());
                            Utils.saveData(trnmodVo.getSmh(), stm, "", "");
//                            Streams.saveTextStream(trnmodVo.getDoctxt(), docpan, 2);
//                            Datas.loadData(trnmodVo.getSmh(), stm);
                            appEnv.streamSaveInDirectory(trnmodVo.getDoctxt(), docfdr);
                        }
                    }
//                    Platform.sdbUpdate(this.getSmh());
                    smhMapper.updateByPrimaryKey(trnmodVo.getSmh());
                }
            }
        }

    }

    /**
     * source:trnmod.0027.script
     * 传入rec指定的对象,例如老TD传入的是LIDGRP，这里应该传入LID
     */
    public void autoRegistration(TrnmodVo trnmod, Object argObj, String argfrm, String argtxt) {
        //! Register a pending entry to be picked up and executed separatly
        //! ArgGrp holds the owning contract of the created SPT
        //! ArgFrm holds the transaction to be executed
        //! ArgTxt holds the Text used to identify the SPT
        //! The routine creates an SMH without a document and spt of type RIM which is automatically kept hold
        //! The current contents of SWIADD is saved in the savedata file of the SPT
        String recTyp = Utils.recGetObj(argObj);
        String recInr = Utils.recGetInr(argObj);
        String userId = SettleContext.getUserSession().getUsr().getExtkey();
        String recOwnRef = "";
        Object ownrefObj = Utils.getFieldValue(argObj, "ownref");
        if (ownrefObj != null) {
            recOwnRef = ownrefObj.toString();
        }
        String recNam = "";
        Object namObj = Utils.getFieldValue(argObj, "nam");
        if (namObj != null) {
            recNam = namObj.toString();
        }
        // Create SMH (start with SMH of incoming message, if set)
        Smh smh = new Smh();
        smh.setInr(counterService.dbCounterFormat("SMH"));
        if (!MdaUtils.isEmpty(recTyp)) {
            smh.setObjinr(recInr);
            smh.setObjtyp(recTyp);
        }
        /** no longer set
         SMH\\TRNTYP = "TRN"
         SMH\\TRNINR = TRN\\INR
         **/
        smh.setTrnsub(trnmod.getTrn().getSmhnxt());
        trnmod.getTrn().setSmhnxt(trnmod.getTrn().getSmhnxt() + 1);
        smh.setExtkey(recOwnRef + "/" + argfrm);
        // always set SMH\\NAM as it has to show different infos for different SMHs
        smh.setNam(Strings.getText("$1 by $2 on $3/$4", recOwnRef, userId, Formats.fmtDateShort(Dates.today()), Strings.mid(Utils.fmtTime(Numerics.time()), 1, 5)));
        smh.setCreusr(userId);
        smh.setCredattim(Dates.now());
        smh.setCrefrm(SettleContext.getTransName());
        smh.setDir("<");
        if (MdaUtils.isEmpty(smh.getCortyp())) {
            smh.setCortyp("RIM");
            // else leave old SMH type, i.e. SWT
        }
        smhMapper.insert(smh);
        Spt sptaut = new Spt();
        // create SPT
        sptaut.setFrm(argfrm);
        sptaut.setTxt(argtxt);
        sptaut.setObjnam(Strings.getText("Autoreg. $1 $2", recOwnRef, recNam));
        sptaut.setSmhinr(smh.getInr());
        if (!MdaUtils.isEmpty(recTyp)) {
            sptaut.setObjinr(recInr);
            sptaut.setObjtyp(recTyp);
        }
        sptaut.setOwnusr(trnmod.getTrn().getUsr());
        sptaut.setOwnusg(trnmod.getTrn().getUsg());
        sptaut.setHldflg("R");
        sptaut.setCreobjtyp("TRN");
        sptaut.setCreobjinr(trnmod.getTrn().getInr());
        trnORDSetSPTAUT(trnmod, sptaut);
        trnmod.setSptaut(sptaut);
        String objName = sysmodService.internalSetObjNam(argObj, null);
        sysmodService.sptSaveEntry(sptaut, argObj, SptWaitingRegistration, trnmod.getSwiadd(), objName);
    }

    @Override
    public String tcoCreateHeaderAll(String mod, String msgMT, String tags) {
        return null;
    }


    /**
     * source:trnmod.0080.script
     */
    public void trnORDSetSPTAUT(TrnmodVo trnmod, Spt sptaut) {
        //! handle order for auto registration
        //! set SPTAUT\\ORDINR from current ORD (i.e. loaded or to be created ORD)
        sptaut.setOrdinr(ordmodService.ordGetINR(trnmod.getOrdmod()));
        //! remove `FIN` from workflow, as order can only be finalized by autoregistered pending entry
        wfmmodService.wfeRemove("FIN", trnmod.getTrnism().getWfmmod());
    }

    public void trnSetFromContract(TrnmodVo trnmodVo) {
        Spt spt = trnmodVo.getSptaut();
        Trn trn = trnmodVo.getTrn();
        Object rec = getRec();
        TrnismVo trnismVo = trnmodVo.getTrnism();
        String trans = SettleContext.getTransName();
        SettleSession session = SettleContext.getUserSession();
        //取得上下文
        // Public
        // Purpose: initial sets the TRN from passed contract.
        // ArgRec : Existing contract-Record with INR set
        // result : TRN holds all fields, empty REL-Fields, and it"s INR
        // Usually called on after final check, and after contract is stored
        // before further processing takes place.
        // in recalculation old transaction is re-used
        if (sysmodService.sptIsExeLoaded(spt.getSta())) {
            return;
        }
        trn.setInidattim(Dates.now());
        trn.setInifrm(Files.fileBaseName(trans));
//        if (!MdaUtils.isEmpty(ctx.absGet(Sysmod.class).getTrnnam())) {
//            trn.setIninam(ctx.absGet(Sysmod.class).getTrnnam());
//        } else {
//            trn.setIninam(ctx.absGet(Sysmod.class).getTrnnam());
//        }
        trn.setIniusr(SettleContext.getUserSession().getUserVo().getLogName());
        if ("1000".equals(SettleContext.getUserSession().getOrgBch().getBranch())) {
            //总行经办柜员赋值
            trn.setRelusr3(trn.getIniusr());
        }
//        String objMod1 = MdaDriver.getModuleInfo(argRec, tdModuleInfoFullName);
//        String name = Strings.mid(trans, 1, 2);
//        String dflg = "";
//        switch (name) {
////            // case "DI", "DE"
//            //   $dflg = $ObjMod1 + "\\\\rec\\\\dflg"
//            case "BD":
//            case "DI":
//                dflg = Datas.getContent(this, "\\DIDGRP\\REC\\DFLG");
//                /**
//                 $dflg = GetContent( "\\\\LIDGRP\\\\REC\\\\DFLG" )
//                 **/
//                break;
//            case "BF":
//            case "DE":
//                /**
//                 $dflg = GetContent( "\\\\LEDGRP\\\\REC\\\\DFLG" )
//                 **/
//                dflg = Datas.getContent(this, "\\DEDGRP\\REC\\DFLG");
//                break;
//        }
        String dflg = Utils.getFieldValue(rec, "dflg");
        if (MdaUtils.compareTo(dflg, "D") == 0) {
            if (MdaUtils.compareTo(trans, "DITDCK") == 0) {
                trn.setObjtyp("BDD");
            } else {
                if (MdaUtils.compareTo(trans, "DETDRV") == 0) {
                    trn.setObjtyp("BFD");
                } else {
                    trn.setObjtyp(Strings.mid(trans, 1, 2) + "D");
                }
            }
        } else {
//            trn.setObjtyp(MdaDriver.getModuleInfo(argRec, tdModuleInfoClass));
            trn.setObjtyp(Utils.recGetObj(rec));
        }
        //-------------------押汇中心调整---------------byte-------------
        /**r
         TRN\\BCHKEYINR = getProcessBCHKEYin
         **/
        trn.setBchkeyinr(session.getHldbch().getInr());
        trn.setAccbchinr(session.getBch().getInr());
        trn.setBranchinr(session.getWrkbch().getInr());

        //-------------------------------------------------------------
//        objMod1 = MdaDriver.getModuleInfo(argRec, tdModuleInfoFullName);
//        IModule mod = MdaDriver.getModule(this, objMod1 + "\\rec");
//        String objMod = NULLSTR;
//        if (ctx.getErrorCode() == 0) {
//            objMod = objMod1 + "\\rec";
//        } else {
//            objMod = objMod1;
//        }
//        trn.setObjinr(Datas.getContent(this, objMod + "\\INR"));
        trn.setObjinr(Utils.getFieldValue(rec, "inr"));

        if (MdaUtils.isEmpty(trn.getObjinr())) {
            //syswrnService.sysWarningSet(SYSWRNTypeWarning, MdaUtils.getI18NString("trnmod", "CT000005"), "TRNCONNIL");
        }
        // trn.setSsninr(session.getSsn().getInr());
//        trn.setObjnam(Datas.getContent(this, objMod + "\\NAM"));
//        if (ctx.getErrorCode() != 0) {
//            trn.setObjnam(NULLSTR);
//        }
//        trn.setUsg(Datas.getContent(this, objMod + "\\OWNUSG"));
//        if (ctx.getErrorCode() != 0) {
//            trn.setUsg(NULLSTR);
//        }
        /**
         TRN\\USR = GetContent( $ObjMod + "\\\\OWNUSR" )
         **/
        trn.setObjnam(Utils.getFieldValue(rec, "nam"));
        trn.setUsg(Utils.getFieldValue(rec, "ownusg"));
        trn.setUsr(session.getUsr().getExtkey());
        trn.setEtyextkey("CEB");
//        if (ctx.getErrorCode() != 0) {
//            trn.setUsr(NULLSTR);
//        }
        // if no user and no group is set based on the contract fallback to the
        // user itself as default
        //TODO usr从session取不到为什么还要去session取呢？？？
        if (MdaUtils.isEmpty(trn.getUsr()) && MdaUtils.isEmpty(trn.getUsg())) {
//            trn.setUsr(SettleContext.getUserSession().getUsr().getExtkey());
            trn.setUsr(session.getUsr().getExtkey());
        }
        String conditionSql = NULLSTR;
//        String sql = NULLSTR;
        if (MdaUtils.isEmpty(trn.getUsg())) {
//            if (MdaUtils.compareTo(trn.getUsr(), session.getUsr().getExtkey()) == 0) {
//                trn.setUsg(session.getUsr().getUsg());
//            } else {
//                if (MdaUtils.compareTo(trn.getUsr(), this.getTrnism().getUsr().getExtkey()) == 0) {
//                    trn.setUsg(this.getTrnism().getUsr().getUsg());
//                } else {
//                    // Cached Ety Select USG from USR where EXTKEY = TRN\\USR
//                    Caches.cacheRead(trn.getUsg(), "TRNUSG", trn.getUsr());
//                    if (ctx.getErrorCode() == 166) {
//                        // Restrict usergroups to the usergroups of the current entity
//                        sqlChk = Platform.sdbEtyGenSql(ctx.absGet(Sysmod.class).getUsr(), "WHERE EXTKEY = " + Platform.sqlLit(trn.getUsr()));
//                        sql = "SELECT USG from USR " + sqlChk;
//                        ctx.getDaoSession().dbExecuteSQL(sql);
//                        Argument<String> usgBox = Argument.box(trn.getUsg());
//                        ctx.getDaoSession().dbFetchFields("USG", usgBox);
//                        trn.setUsg(usgBox.value);
//                        if (ctx.getErrorCode() != tdOdbcNotFound) {
//                            ctx.reraise();
//                        }
//                        ctx.getDaoSession().dbCloseCursor();
//                        Caches.cacheWrite(trn.getUsg(), "TRNUSG", trn.getUsr());
//                    } else {
//                        ctx.reraise();
//                    }
//                }
//            }

            if (MdaUtils.compareTo(trn.getUsr(), session.getUsr().getExtkey()) == 0) {
                trn.setUsg(session.getUsr().getUsg());
            } else {
                if (MdaUtils.compareTo(trn.getUsr(), trnismVo.getUsr().getExtkey()) == 0) {
                    trn.setUsg(trnismVo.getUsr().getUsg());
                } else {
                    //为空时取trn.usr对应用户usg
                    conditionSql = Utils.sdbEtyGenSql("USR", String.format("WHERE EXTKEY = '%s'", trn.getUsr()));
//          sql = "SELECT * from USR " + conditionSql;
                    List<Usr> usrList = usrMapper.getUsrByConditionSql(conditionSql);
                    if (usrList.size() > 0) {
                        trn.setUsg(usrList.get(0).getUsg());
                    }
                    // Cached Ety Select USG from USR where EXTKEY = TRN\\USR

                }
            }
        }
        if ((MdaUtils.compareTo(trans, "MCTFEE") == 0 || MdaUtils.compareTo(trans, "MCTFRE") == 0)) {
//            trn.setOwnref(Datas.getContent(this, objMod + "\\SUBREF"));
            trn.setOwnref(Utils.getFieldValue(rec, "subref"));
        } else {
//            trn.setOwnref(Datas.getContent(this, objMod + "\\OWNREF"));
            trn.setOwnref(Utils.getFieldValue(rec, "ownref"));
        }
        Utils.sdbEtySetRec(trn, "TRN", "", "");
        // mark transaction as `entered`
        trn.setRelflg("E");
        trn.setOrgflg(session.getBch().getBchtyp());
        //退回交易如果绑定影像，take后不点击image按纽则不会产生imginr
        if (MdaUtils.isEmpty(trn.getImginr()) && !MdaUtils.isEmpty(spt.getImginr())) {
            trn.setImginr(spt.getImginr());
        }

    }

    /**
     * 将业务grp都存一遍，并且留下修改记录和修改日志，并支持为回滚做准备
     * 但改方法实现的时候未考虑后手交易会存前手数据，准备逐步清理掉。不要再使用。请使用trnStoreContract(Object objgrp)
     *
     * @param rec 业务主表
     * @param blk 业务副表
     */
    @Deprecated
    public void trnStoreContract(Object rec, Object blk) {
        List<PtsptaVo> ptsList = transactionHelpService.getTransactionStoreSet().getPtsList();
        TrnmodVo trnmod = transactionHelpService.getTransactionStoreSet().getTrnmodVo();
        // public
        // Store Contract incl. BLK and maintain TRO-Table
        // Passed object has to be the recordgroup. If there is a BLK submodule
        // this is stored automatically.
        String objInr = Utils.recGetInr(rec);
        String objtyp = Utils.recGetObj(rec);
        String objFlg = "";
        // make sure that PTS-std-fields in contract are updated
        ptsptaToolComponent.ptsptaSetConForContract(rec, ptsList);
        if (StringUtils.isNotEmpty(objInr)) {
            if (dyncDaoService.dyncReadByInr(rec, objInr)) {
                objFlg = "F";
            }
        }
        // prepare customized additional data xxTMOD.SetxxdAddData
        // Caution: $Sec might be "PT" from handling of PTE pseudocontractsS
        String sec = Strings.mid(objtyp, 1, 2);
        setDataRegisterFactory.getSetDataRegister(sec + "T").setAddData();
        boolean troInsertContract = false;
//        IModule objBlkMod = null;
        if (MdaUtils.isEmpty(objFlg)) {
            if (MdaUtils.isEmpty(objInr)) {
                sysmodService.sdbInsertWithLog(rec);
                objInr = Utils.recGetInr(rec);
            } else {
                sysmodService.sdbUndeleteWithLog(rec);
            }
            // do not dblock new contracts to avoid incomplete rollbacks.
            // as lock check has been removed from CBSMOD, locking of new contracts is not necessary anymore
            if (blk != null) {
                Utils.setFieldValue(blk, "inr", objInr);
                dyncDaoService.dyncInsert(blk);
            }
            troInsertContract = true;
            //\\TRNMOD.TroInsertContract( Obj, \\TRNMOD\\TRN\\INR )
        } else {
            // Checking whether the contract to be updated is registered for update
            if (Streams.streamSearch(trnmod.getTrorescon(), sysmodService.midObjinr(objInr) + objtyp + TAB + "3") == 0) {
                //SettleExceptionUtils.sysDump("TrnStoreContract: Update of not properly registered contract " +
                // objtyp + " issued.\nProbably TroLockExistingOrNewContract is missing in init rule of transaction.");
            }
            sysmodService.sdbUpdateWithLog(rec);
            if (blk != null) {
                Utils.setFieldValue(blk, "inr", objInr);
                dyncDaoService.dyncUpdateByPrimaryKeySelective(blk);
            }
        }
        if (!Pte.class.equals(rec.getClass())) {
            // store PTS
            savPtsptaForContract(ptsList, rec);
        }
        // save common contract information
        if (MdaUtils.compareTo(objtyp, "PTE") != 0) {
            ccimodService.storeCCIForContract(ptsList, rec);
        }
        // save customized additional data xxTMOD.SavxxdAddData
        saveDataRegisterFactory.getSaveDataRegister(sec + "T").saveAddData();
        // save contract in TRO here as contract group now complete filled
        if (troInsertContract) {
            troInsertContract(rec, trnmod);
        }
    }

    /**
     * 将业务grp都存一遍，并且留下修改记录和修改日志，并支持为回滚做准备
     *
     * @param objgrp 业务grp
     */
    public void trnStoreContract(Object objgrp) {
        Object rec = Utils.getFieldValue(objgrp, "rec");
        Object blk = Utils.getFieldValue(objgrp, "blk");
        //收集当业务grp的ptspta
        List<PtsptaVo> ptsList = ptsptaToolComponent.getPtsptaFromGroup(objgrp, false);
        //获取当前Trn信息
        TrnmodVo trnmod = transactionHelpService.getTransactionStoreSet().getTrnmodVo();
        // public
        // Store Contract incl. BLK and maintain TRO-Table
        // Passed object has to be the recordgroup. If there is a BLK submodule
        // this is stored automatically.
        String objInr = Utils.recGetInr(rec);
        String objtyp = Utils.recGetObj(rec);
        String objFlg = "";
        // make sure that PTS-std-fields in contract are updated
        ptsptaToolComponent.ptsptaSetConForContract(rec, ptsList);
        if (StringUtils.isNotEmpty(objInr)) {
            if (dyncDaoService.dyncReadNoDataByInr(rec)) {
                objFlg = "F";
            }
        }
        // prepare customized additional data xxTMOD.SetxxdAddData
        // Caution: $Sec might be "PT" from handling of PTE pseudocontractsS
        String sec = Strings.mid(objtyp, 1, 2);
        setDataRegisterFactory.getSetDataRegister(sec + "T").setAddData();
        //设置统一名单的交易对手名称
        saveUmdbennam(rec);
        boolean troInsertContract = false;
//        IModule objBlkMod = null;
        if (MdaUtils.isEmpty(objFlg)) {
            if (MdaUtils.isEmpty(objInr)) {
                sysmodService.sdbInsertWithLog(rec);
                objInr = Utils.recGetInr(rec);
            } else {
                sysmodService.sdbUndeleteWithLog(rec);
            }
            // do not dblock new contracts to avoid incomplete rollbacks.
            // as lock check has been removed from CBSMOD, locking of new contracts is not necessary anymore
            if (blk != null) {
                Utils.setFieldValue(blk, "inr", objInr);
                Utils.setFieldValue(blk, "ver", "0000");
                dyncDaoService.dyncInsert(blk);
            }
            troInsertContract = true;
            //\\TRNMOD.TroInsertContract( Obj, \\TRNMOD\\TRN\\INR )
        } else {
            // Checking whether the contract to be updated is registered for update
            if (Streams.streamSearch(trnmod.getTrorescon(), sysmodService.midObjinr(objInr) + objtyp + TAB + "3") == 0) {
                //SettleExceptionUtils.sysDump("TrnStoreContract: Update of not properly registered contract " +
                // objtyp + " issued.\nProbably TroLockExistingOrNewContract is missing in init rule of transaction.");
            }
            sysmodService.sdbUpdateWithLog(rec);
            if (blk != null) {
                Utils.setFieldValue(blk, "inr", objInr);
                Utils.setFieldValue(blk, "ver", Utils.getFieldValue(rec, "ver"));
                dyncDaoService.dyncUpdateByPrimaryKeySelective(blk);
            }
        }
        if (!Pte.class.equals(rec.getClass()) && !sysmodService.isSdhBusiness()) {
            // store PTS
            savPtsptaForContract(ptsList, rec);
        }
        // save common contract information
        if (MdaUtils.compareTo(objtyp, "PTE") != 0) {
            ccimodService.storeCCIForContract(ptsList, rec);
        }
        // save customized additional data xxTMOD.SavxxdAddData
        saveDataRegisterFactory.getSaveDataRegister(sec + "T").saveAddData();
        // save contract in TRO here as contract group now complete filled
        if (troInsertContract) {
            troInsertContract(rec, trnmod);
        }
    }

    public void troInsertContract(Object obj, TrnmodVo trnmodVo) {
        String trnInr = trnmodVo.getTrn().getInr();
        // Public
        // Has to be called after creating a new contract to maintain TRO chain
        // The new contract has to be read with hold
        // The new contract must be locked for any updates
        troAddToLocktable(trnmodVo.getTrorescon(), obj, 3);
        String oldVer = Utils.getFieldValue(obj, "ver");
        Utils.setFieldValue(obj, "ver", "");
        Utils.saveData(obj, trnmodVo.getBimdata(), troGetBimLabel(Utils.recGetObj(obj), Utils.recGetInr(obj)), "");
        if (!MdaUtils.isEmpty(oldVer)) {
            Utils.setFieldValue(obj, "ver", oldVer);
        }
    }

    @Override
    public void troLockExistingContract(TrnmodVo trnmodVo, Object obj) {
        int statusFlag = getStatusFlagOfOBJ(trnmodVo.getTrorescon(), obj);
        if (statusFlag > 0 && statusFlag < 3) {
            SettleExceptionUtils.sysDump(Strings.formatText("TRNMOD.TroLockExistingContract: contract $1/$2\nhas previously been registered with level $3.\nNo second registration with higher level possible.", Utils.recGetObj(obj), Utils.recGetInr(obj), statusFlag));
        }
        if (statusFlag == 3) {
            // contract already locked for any update
            return;
        }
        IStream sptData = new StreamImpl();
        Streams.streamClear(sptData);
        String objTyp = NULLSTR;
        String objinr = NULLSTR;
        String dataLabel = NULLSTR;
        if (sysmodService.sptIsAnyLoaded(trnmodVo.getSpt().getSta())) {
//            if( ! sysmodService.sptIsManLoaded() && ! Platform.sptIsAutLoaded() ){
            objTyp = Utils.recGetObj(obj);
            objinr = Utils.recGetInr(obj);
            dataLabel = troGetBimLabel(objTyp, objinr);
            Utils.saveData(obj, sptData, dataLabel, "");
//                Systems.setContext("SAVEDATASKIPEMPTY",true);
//                Datas.saveData(obj,sptData,dataLabel);
//                Systems.setContext("SAVEDATASKIPEMPTY",false);
//            }
        }
//        prepareContract( trnmodVo,obj, "X" );
//        String errTxt = NULLSTR;
//        if( ctx.getErrorCode() == tdOdbcNotFound )
//        {
//            errTxt = Strings.getText(MdaUtils.getI18NString("trnmod","CT000021"));
//            trnmodCancel( errTxt, TrnmodCancelExitWithPrompt );
//        }
//        if( Platform.sptIsAnyLoaded() )
//        {
//            //! 收单行上收业务连续到单交易，会导致信用证余额有误
//            /**
//             if not SptIsManLoaded and not SptIsAutLoaded then
//             **/
//            if( ! Platform.sptIsManLoaded() && ! Platform.sptIsAutLoaded() && ! Platform.sptIsCMCLoaded() )
//            {
//                mergeSptandContractData( obj, sptData );
//            }
//        }
//        postProcessingPerContract( obj );//todo
        troAddToLocktable(trnmodVo.getTrorescon(), obj, 3);
//        troCheckPendingTroEntries( obj );//todo

    }

    public void prepareContract(TrnmodVo trnmodVo, Object obj, String argFlg) {
        String objtyp = Utils.recGetObj(obj);
        String objinr = Utils.recGetInr(obj);
        String objPath = Utils.recGetPath(obj);
        String dataLabel = troGetBimLabel(objtyp, objinr);
        String ownref = "<NONREF>";
        // if order processing is active, initialize order
        ordLockForTRN(trnmodVo);
        // if order is locked - no processing of transaction possible
//        String errtxt = NULLSTR;
//        if( ctx.getErrorCode() == tdOdbcLocked )
//        {
//            ownref = Datas.getContent(this,objPath + "\\OWNREF");
//            if( ctx.getErrorCode() > 0 )
//            {
//                ownref = "<NONREF>";
//            }
//            errtxt = Strings.getText(MdaUtils.getI18NString("trnmod","CT000060"),ctx.getErrorCode(),Strings.trim(Databases.getLockUID()),GetLockDate,Strings.mid(Platform.fmtTime(Databases.getLockTime()),1,5),ownref);
//            trnmodCancel( errtxt, TrnmodCancelExitWithPrompt );
//        }
        // if contract is empty/no inr ->
        // check if transaction is allowed with empty contract and return to caller
        IStream stm = new StreamImpl();
//        if( MdaUtils.isEmpty(objinr) ) {
//            Streams.streamClear(stm);
//            Systems.setContext("SAVEDATASKIPEMPTY",true);
//            Datas.saveData(obj,stm);
//            Systems.setContext("SAVEDATASKIPEMPTY",false);
//            MdaUtils.clear(obj);
//            troCheckIfTrnAllowed( obj, "<new contract>" );//todo
//            if( sysmodService.sptIsAnyLoaded(trnmodVo.getSpt().getSta()) ) {
//                Systems.setContext("LOADDATAIMPLICITCLEAR",true);
//                Datas.loadData(obj,stm);
//                Systems.setContext("LOADDATAIMPLICITCLEAR",false);
//                internalTroChkOwnref( obj );//todo
//            }
//        }
//        if( ! MdaUtils.isEmpty(argFlg) ) {
//            dyncDaoService.dyncReadByInr(objtyp,objinr);//SdbReadLock( $ObjMod, $objinr )
//        } else {
//            dyncDaoService.dyncReadByInr(objtyp,objinr);
//        }
        // if contract not found, this is allowed for correction of contract allocating transactions
//        String notFndTxt = NULLSTR;
//        int ignore = 0;
//        String path = NULLSTR;
//        String postCmd = NULLSTR;
//        if( ctx.getErrorCode() == tdOdbcNotFound ) {
//            notFndTxt = ctx.getErrorMessage();
//            Streams.streamClear(stm);
//            Systems.setContext("SAVEDATASKIPEMPTY",true);
//            Datas.saveData(obj,stm);
//            Systems.setContext("SAVEDATASKIPEMPTY",false);
//            MdaUtils.clear(obj);
//            troSaveOld( obj );
//            troCheckIfTrnAllowed( obj, "<new contract>" );
//            // if contract loaded from SYSSTREAM and not found in database - clear data
//            if( Platform.sptIsAnyLoaded() )
//            {
//                Systems.setContext("LOADDATAIMPLICITCLEAR",true);
//                Datas.loadData(obj,stm);
//                Systems.setContext("LOADDATAIMPLICITCLEAR",false);
//                internalTroChkOwnref( obj );
//            }
//            ctx.setErrorCode(tdOdbcNotFound,notFndTxt);
//        }
//        else
//        {
        // if contract locked - no processing of transaction possible
//            if( ctx.getErrorCode() == tdOdbcLocked )
//            {
//                ownref = Datas.getContent(this,objPath + "\\OWNREF");
//                if( ctx.getErrorCode() > 0 )
//                {
//                    ownref = "<NONREF>";
//                }
//                errtxt = Strings.getText(MdaUtils.getI18NString("trnmod","CT000068"),ctx.getErrorCode(),Strings.trim(Databases.getLockUID()),GetLockDate,Strings.mid(Platform.fmtTime(Databases.getLockTime()),1,5),ownref);
//                trnmodCancel( errtxt, TrnmodCancelExitWithPrompt );
//                // in all other cases try to process
//            }
//            else
//            {
//                ctx.reraise();
//                ownref = Datas.getContent(this,objPath + "\\OWNREF");
//                if( ctx.getErrorCode() > 0 )
//                {
//                    ownref = "<NONREF>";
//                }
//                // no process if contract does not exist in the current entity context
//                ctx.getDaoSession().dbReadNoData(objMod,Platform.sdbEtyGenSql(objMod,"INR = ?"),objinr);
//                if( ctx.getErrorCode() == tdOdbcNotFound )
//                {
//                    /**
//                     TrnmodCancel( GetText( 'L0000084', $ownref ), TrnmodCancelExitWithPrompt )
//                     **/
//                    //如果跨机构REROUTING，会检查报错，因此屏蔽
//                    ignore = ctx.getErrorCode();
//                }
//                else
//                {
//                    ctx.reraise();
//                }
//                // call Get<type>GrpButRec to load complete contract group.
//                if( Strings.pos(objtyp,"PTE") == 0 )
//                {
//                    path = Platform.getPathofName(objPath);
//                    postCmd = "Get" + Platform.recGetObj(obj) + "GrpButRec( " + path + ", \"" + objinr + "\" )";
//                    Modules.invokeExpress(this,postCmd,-1);
//                }
        // save to old if defined
//                troSaveOld( obj );//todo
        // Saving before image
        troStoreInBim(obj);
        // check if transation is allowed with contract completely loaded from database
//                troCheckIfTrnAllowed( obj, ownref );//todo
//            }
//        }
    }

    public int getStatusFlagOfOBJ(IStream argStream, Object obj) {
        int statusFlag = 0;
        String objINR = Utils.recGetInr(obj);
        String objTyp = Utils.recGetObj(obj);
        String objId = Strings.mid(objINR, 1, 8) + objTyp;
        int fnd = Streams.streamSearch(argStream, objId + TAB);
        String fndLin = "";
        if (fnd > 0) {
            fndLin = Strings.getLine(argStream, fnd);
            statusFlag = Strings.parseInt(Strings.mid(fndLin, Strings.pos(fndLin, TAB) + 1));
        }
        return statusFlag;

    }

    /**
     * source:trnmod.0017.script
     */
    @Override
    public void troAddToLocktable(IStream lcktblstm, Object obj, int argStatusFlag) {
        //! Add a new object to or replace an existing entry in the lock table lcktblstm .
        //! used for TRORESCON
        //! The possible values of ArgFlg are:
        //! 0 - new contract
        //! 1 - read only / no TRO-Dependency
        //! 2 - locked for CBS  (read and locked for CBS)
        //! 3 - locked for update (read and locked for any updates)
        if (MdaUtils.compareTo(argStatusFlag, 0) < 0 || MdaUtils.compareTo(argStatusFlag, 3) > 0) {
            SettleExceptionUtils.sysDump("TRNMOD: TroAddToLocktable called with unknown ArgStatusFlag");
        }
        // passed object might be REC or RECGRP.
        String objINR = Utils.recGetInr(obj);
        String objTyp = Utils.recGetObj(obj);
        // set main contract in first line
        int insLin = 1;
        /*if( MdaUtils.compareTo(Utils.recGetInr(trnmod.getRec()),objINR) == 0 && MdaUtils.compareTo(Platform.recGetObj(ctx.absGet(Mtabut.class).getRec()),objTyp) == 0 ) {
            insLin = 1;
        } else {
            insLin = 0;
        }*/
        int staFlg = 0;
        if (!MdaUtils.isEmpty(objINR)) {
            staFlg = argStatusFlag;
        }
        String objId = sysmodService.midObjinr(objINR) + objTyp;
        int fnd = Streams.streamSearch(lcktblstm, objId);
        int fndNewCon = 0;
        if (fnd == 0) {
            // new or existing contract must be replaced with new data otherwise add new line
            fndNewCon = Streams.streamSearch(lcktblstm, sysmodService.midObjinr("") + objTyp + TAB + "0");
            if (fndNewCon > 0) {
                Streams.streamSetLine(lcktblstm, fndNewCon, objId + TAB + MdaUtils.toString(staFlg));
            } else {
                Streams.streamInsert(lcktblstm, insLin, objId + TAB + MdaUtils.toString(staFlg));
            }
        } else {
            Streams.streamSetLine(lcktblstm, fnd, objId + TAB + MdaUtils.toString(staFlg));
        }
    }

    /**
     * source:trnmod.0049.script
     */
    public void savPtsptaForContract(List<PtsptaVo> ptsptaVos, Object rec) {
        //! Saves all not empty PTS-records inside PTSPTA instances inside Arggrp for ArgInr to database
        // get info about Arggrp
        String objInr = Utils.recGetInr(rec);
        String objTyp = Utils.recGetObj(rec);
        //! ArgInr has to be set
        if (MdaUtils.isEmpty(objInr)) {
            SettleExceptionUtils.sysDump("TRNMOD.SavPtsptaForContract: Cannot save involved parties as passed INR of " + objTyp + " contract is empty.");
        }
        ptsptaVos.forEach(ptsptaVo -> {
            String rol = ptsptaVo.getPts().getRol();
            if (StringUtils.isEmpty(rol)) {
                rol = ptsptaVo.getRol();
            }
            Pts pts = ptsMapper.getPtsByObjInrTypAndRole(objInr, objTyp, rol, null);
            String ptsinr = "";
            if (pts != null) {
                ptsinr = pts.getInr();
            } else {
                pts = new Pts();
            }
            if ("Y".equals(ptsptaVo.getRolsetflg())) {
                pts = ptsptaVo.getPts();
                // set key fields.
                pts.setInr(ptsinr);
//                pts.setPtyinr(ptsptaVo.getPtyinr());
//                pts.setPtainr(ptsptaVo.getPtainr());
                pts.setRol(rol);
                String ownref = "<NONREF>";
                ownref = Utils.getFieldValue(rec, "ownref", ownref);
                pts.setObjtyp(objTyp);
                pts.setObjinr(objInr);
                pts.setOwnref(ownref + "\\" + rol);
                //去掉两侧字符串
                if (StringUtils.isNotEmpty(pts.getRef())) {
                    pts.setRef(pts.getRef().trim());
                }
                if (StringUtils.isNotEmpty(pts.getNam()) && pts.getNam().length() > 40) {
                    pts.setNam(pts.getNam().substring(0, 40));
                }
                if (StringUtils.isNotEmpty(pts.getEnnam()) && pts.getEnnam().length() > 140) {
                    pts.setEnnam(pts.getEnnam().substring(0, 140));
                }
                if (StringUtils.isNotEmpty(pts.getEnadr()) && pts.getEnadr().length() > 140) {
                    pts.setEnadr(pts.getEnadr().substring(0, 140));
                }
                pts.setAdrblk(StringUtils.convertBlock(pts.getEnnam() + "\n" + pts.getEnadr(), 4, 35));
                if (StringUtils.isNotEmpty(pts.getCnnam()) && pts.getCnnam().length() > 140) {
                    pts.setCnnam(pts.getCnnam().substring(0, 140));
                }
                if (StringUtils.isNotEmpty(pts.getCnadr()) && pts.getCnadr().length() > 400) {
                    pts.setCnadr(pts.getCnadr().substring(0, 400));
                }
                //如果是国内临时地址
                if (StringUtils.isEmpty(pts.getAdrblk())) {
                    pts.setAdrblk(StringUtils.convertBlock(pts.getCnnam() + "\n" + pts.getCnadr(), 4, 35));
                }
                //dftcur,dftdsp,dftact,dftfeecur,dftactptainr,glggrpflg
                SetmodVo setmodVo = transactionHelpService.getTransactionStoreSet().getSetmodVo();
                if (setmodVo != null) {
                    List<PtsFeeDetailVo> ptydet = setmodVo.getPtydet();
                    if (ptydet != null && ptydet.size() > 0) {
                        String finalRol = rol;
                        Optional<PtsFeeDetailVo> optionalPtydet = ptydet.stream().filter(ptsFeeDetailVo -> finalRol.equalsIgnoreCase(ptsFeeDetailVo.getRol())).findFirst();
                        if (optionalPtydet.isPresent()) {
                            pts.setDftcur(optionalPtydet.get().getDftcur());
                            pts.setDftdsp(optionalPtydet.get().getDftdsp());
                            pts.setDftact(optionalPtydet.get().getDftact());
                            pts.setDftfeecur(optionalPtydet.get().getDftfeecur());
                            pts.setDftactptainr(optionalPtydet.get().getDftactptainr());
                            pts.setGlggrpflg(optionalPtydet.get().getGlggrpflg());
                        }
                    }
                }
                // insert or update row depending on availability
                if (MdaUtils.isEmpty(ptsinr)) {
                    sysmodService.sdbInsert(pts);
                    ptsptaVo.setPtsinr(pts.getInr());
                } else {
                    ptsptaVo.setPtsinr(ptsinr);
                    ptsMapper.updateByPrimaryKeySelective(pts);
                }
            } else {
                // if role is stored, remove it
                if (!MdaUtils.isEmpty(ptsinr)) {
                    ptsMapper.deleteByPrimaryKey(pts);
                }
            }
        });
    }

    /**
     * 从trorescon流中获取objTyp是否是PTE，不是就放到argStm流的第一条
     *
     * @param argStm
     * @param trorescon
     */
    public void getStreamOfAllObj(IStream argStm, IStream trorescon) {
        //取得上下文
//        IContext ctx = MdaEnv.getContext();
//        ctx.setErrorCode(NO_ERROR);
        //! return stream with all loaded OBJ in this transaction except PTE records
        //MdaUtils.clear(argStm);
        int stmCnt = Streams.streamCount(trorescon);
        String lin = NULLSTR;
        String resLin = NULLSTR;
        String objTyp = NULLSTR;
        for (int i = 1; i <= stmCnt; i++) {
            lin = Strings.getLine(trorescon, i);
            resLin = Strings.mid(lin, 1, Strings.pos(lin, TAB) - 1);
            objTyp = Strings.mid(resLin, 9);
            if (MdaUtils.compareTo(objTyp, "PTE") != 0) {
                Streams.streamInsert(argStm, 0, objTyp);
            }
        }

    }

    public void init200(TrnmodVo trnmod) {
        Trn trn = trnmod.getTrn();
        TrnismVo trnism = trnmod.getTrnism();
        // Reinititialize release information (e.g. after pickup)
        trn.setRelres(" ");
        trn.setRelflg(" ");
        trnism.setRelliaamt(new BigDecimal("0"));
        // after pickup there is a new TRN created
        trn.setInr(NULLSTR);

    }

    public void cbsTrnStoreCur(String cbt, String extid, Date dat, String cur, BigDecimal amt, String nam, Object obj, String trninr) {
        if (!MdaUtils.isEmpty(cur)) {
            Cbe cbe = new Cbe();
            cbe.setExtid(extid);
            cbe.setCbt(cbt);
            cbe.setTrntyp("TRN");
            cbe.setTrninr(trninr);
            cbe.setDat(dat);
            cbe.setCur(cur);
            cbe.setAmt(amt);
            cbe.setNam(nam);
            cbsmodService.cbsStoreEntry(cbe, obj);
        }

    }


    public void cbsTrnStore(String cbt, String extid, Date dat, String cur, BigDecimal amt, String nam, Object obj, String trninr) {
        if (!MdaUtils.isEmpty(amt) || MdaUtils.compareTo(Strings.mid(extid, 1, 3), "CCV") == 0) {
            Cbe cbe = new Cbe();
            cbe.setExtid(extid);
            cbe.setCbt(cbt);
            cbe.setTrntyp("TRN");
            cbe.setTrninr(trninr);
            cbe.setDat(dat);
            cbe.setCur(cur);
            cbe.setAmt(amt);
            cbe.setNam(nam);
            cbsmodService.cbsStoreEntry(cbe, obj);
        }

    }

    /**
     * source:trnmod.0081.script
     */
    public void ordLockForTRN(TrnmodVo trnmod) {
        //! Lock ORD when specified in SPT, otherwise initialize (so that new ORD is created on SAVE)
        String oldORDINR = NULLSTR;
        if (trnmod.getSpt() != null && !StringUtils.isEmpty(trnmod.getSpt().getInr())) {
            Spt spt = sptMapper.selectByPrimaryKey(trnmod.getSpt());
            trnmod.setSpt(spt);
        }
        if (sysmodService.sptIsAnyLoaded(trnmod.getSpt().getSta())) {
            if (MdaUtils.isEmpty(trnmod.getSpt().getOrdinr())) {
                ordmodService.ordNew(trnmod.getOrdmod());
            } else {
                //Systems.setVisible(this.getMtabut(),"ord");
                oldORDINR = trnmod.getOrdmod().getOrdinr();
                ordmodService.ordReadLock(trnmod.getSpt().getOrdinr(), trnmod.getOrdmod());
                // show INFTXT if present and has not yet been shown
                if (MdaUtils.compareTo(oldORDINR, trnmod.getOrdmod().getOrdinr()) != 0
                        && !MdaUtils.isEmpty(trnmod.getOrdmod().getOrd().getInfdsp())
                        && !MdaUtils.isEmpty(trnmod.getOrdmod().getOrd().getInftxt())) {
                    log.warn(Strings.getText("Please note the following instruction for order $2:\\n$1", trnmod.getOrdmod().getOrd().getInftxt(), trnmod.getOrdmod().getOrd().getExtkey()));
                }
            }
        } else {
            //Systems.resetVisible(this.getMtabut(),"ord");
            ordmodService.ordNew(trnmod.getOrdmod());
        }
    }

    /**
     * source:trnmod.0063.script
     *
     * @Rule(target="mtabut.sav",order=490) ruleMtabutSavN490
     */
    public void initTrndocAndTrninr(TrnmodVo trnmod) {
        //! To initiate the update phase of the transaction (which starts with order 500)
        //! finally get the TRN\\INR and lock the transaction
        // get new transaction INR if not in recalculation
        trndocService.trnDOCFillDOCTree();
        if (!sysmodService.sptIsExeLoaded(trnmod.getSpt().getSta())) {
            trnmod.getTrn().setInr(counterService.dbCounterFormat("TRN"));
        }
        ordLockForTRN(trnmod);
        // Keep in mind that locking implies a commit
        //ctx.getLocker().lock(this.getTrn());
        // no errorchecking
        // it should dump if problems with counter occured
    }


    public Object getRec() {
        return transactionHelpService.getTransactionStoreSet().getRec();
    }

    public Map<String, Cbb> getCbsMap() {
        return transactionHelpService.getTransactionStoreSet().getCbsMap();
    }

    public List<PtsptaVo> getPtsList() {
        return transactionHelpService.getTransactionStoreSet().getPtsList();
    }

    public BigDecimal getDocamt() {
        return transactionHelpService.getTransactionStoreSet().getSetmodVo() == null ? BigDecimal.ZERO : transactionHelpService.getTransactionStoreSet().getSetmodVo().getDocamt();
    }

    public String getDoccur() {
        return transactionHelpService.getTransactionStoreSet().getSetmodVo() == null ? "" : transactionHelpService.getTransactionStoreSet().getSetmodVo().getDoccur();
    }

    public boolean isRamSptLoaded(String sptSta, String smhinr) {
        //! checks, if the actual transaction is initiated originally by a xxTRAM or xxTAMR, i.e. the SMH was created by a xxxRAM or xxTAMR transaction.
        //! Return TRUE even if transaction i.e. has been send to correction and picked up again inbetween
        if (sysmodService.sptIsAnyLoaded(sptSta)) {
            if (MdaUtils.isEmpty(smhinr)) {
                return false;
            } else {
                Smh smh = new Smh();
                smh.setInr(smhinr);
                smh = smhMapper.selectByPrimaryKey(smh);
                switch (Strings.mid(smh.getCrefrm(), 4, 3)) {
                    case "RAM":
                    case "AMR":
                        return true;
                    default:
                        return false;
                }
            }
        } else {
            return false;
        }

    }

    public boolean filtmarks(String strtxt) {
        //!人民币跨境过滤标点符号函数
        //!==================================================
        //!返回值：过滤成功与否
        //!变量:   过滤栏位内容
        //!==================================================
        String marks1 = ":-,.";
        String marks2 = "，。，．";
        boolean flg = false;
        int a = 0;
        int n = marks1.length();
        int m = Decimals.div(Strings.len(marks2), 2).intValue();
        String mark = NULLSTR;
        int k = 0;
        for (int i = 1; i <= n; i++) {
            mark = marks1.substring(i, i + 2);
            k = strtxt.indexOf(mark);
            if (k > 0 && i < 2) {
                flg = true;
            }
            if (k == 1 && i > 1) {
                flg = true;
            }
        }
        for (int j = 1; j <= m; j++) {
            mark = marks2.substring(j + a, j + a + 2);
            k = strtxt.indexOf(mark);
            if (k == 1) {
                flg = true;
            }
            a = a + 1;
        }
        return flg;
    }

    public int chineseFldLength(String txt) {
        //!判断字符串长度（含中文）函数
        //!一个汉字当作一个字符来计算
        //!=========================================
        //!返回值：实际字符长度
        //!变量：   txt     待判断的字符串
        //!           number  小数部分数字
        //!=========================================
        //计算规则:UTF-8的长度和GBK计算长度的差异来进行计算
        int len = Strings.len(txt);
        int len1 = Strings.len(Strings.convertBlock(txt, 11));
        int len2 = Strings.len(Strings.convertBlock(txt, 13));
        int lenChinese = (len2 - len1);  //因为convert会把XML特殊字符进行转意，所以需要用这种方式计算
        return len - lenChinese;
    }

    public Date calcTargetDate(Date argRefDat, BigDecimal argNbr, String argPer) {
        //取得上下文
//        IContext ctx = MdaEnv.getContext();
//        ctx.setErrorCode(NO_ERROR);
        //! Calculate target date depending on a number and period type strting form a reference date
        //! ArgRefDat : Start date of calculation
        //! ArgNbr: Number of periods; negative numbers are supported to caclulated periods before reference date.
        //! ArgPer: Type of period. Supported values are:
        //!            D - calendar days
        //!            M - Months
        //!            Y - Years
        //!            Remark: Years and months are calculated as duration periods, i.e. usually the day of the date retuned is the day of the reference date.
        //!                       except if the reference date is the last day of the month or the day of the refernce date is not present in the target month. In such cases the last day of the target month is returned.
        Date res = NULLDATE;
        BigDecimal clcMth = new BigDecimal("0");
        // DNGDEV.002541: Add SR2020-Codes to avoid Dump. Return ArgRefDat if code is not recognized or OTHR
        switch (argPer) {
            case "D":
            case "DAYS":
                res = Dates.add(argRefDat, argNbr.intValue());
                break;
            case "M":
                clcMth = argNbr;
                break;
            case "Y":
                clcMth = Decimals.mul(12, argNbr);
                break;
            case "ONEY":
                res = Dates.add(argRefDat, 365);
                break;
            default:
                res = argRefDat;
        }
        int refYhr = 0;
        int refMth = 0;
        int refday = 0;
        int refLst = 0;
        BigDecimal mth = null;
        int resYhr = 0;
        BigDecimal resMth = null;
        int resLst = 0;
        int resDay = 0;
        if (MdaUtils.compareTo(clcMth, 0) != 0) {
            refYhr = Dates.getYear(argRefDat);
            refMth = Dates.getMonth(argRefDat);
            refday = Dates.getDay(argRefDat);
            refLst = getLastDayofMonth(new BigDecimal(refYhr), new BigDecimal(refMth));
            mth = Decimals.sub(Decimals.add(12 * refYhr + refMth, clcMth), 1);
            resYhr = Numerics.toInt(Decimals.div(mth, 12));
            resMth = Decimals.add(Decimals.sub(mth, 12 * resYhr), 1);
            resLst = getLastDayofMonth(new BigDecimal(refYhr), new BigDecimal(refMth));
            resDay = refday;
            if (refday == refLst || resDay > resLst) {
                resDay = resLst;
            }
            res = Strings.parseDate(MdaUtils.toString(Numerics.toInt(resDay), -2) + "/" + MdaUtils.toString(resMth, -2) + "/" + MdaUtils.toString(resYhr, -4));
        }
        return res;

    }

    public int getLastDayofMonth(BigDecimal yea, BigDecimal mon) {
        //取得上下文
//        IContext ctx = MdaEnv.getContext();
//        ctx.setErrorCode(NO_ERROR);
        // determine last day of month
        // requires year to respect leap years
        BigDecimal nextmonth = Decimals.add(mon, 1);
        BigDecimal nextyear = null;
        if (MdaUtils.compareTo(nextmonth, 12) > 0) {
            nextyear = Decimals.add(yea, 1);
            nextmonth = new BigDecimal("1");
        } else {
            nextyear = yea;
        }
        String date = "01/" + Strings.mid(MdaUtils.toString(Numerics.toInt(nextmonth), -2), 1, 2) + "/" + Strings.mid(MdaUtils.toString(nextyear, -4), 1, 4);
        Date nextdate = Dates.add(Strings.parseDate(date), -1);
        return Dates.getDay(nextdate);

    }

    /**
     * source:trnmod.0237.script
     */
    public Map<String, String> characterZ(String argField, String resultKey) {
        Map<String, String> resultMap = new HashMap<>();
        //先排除中文和中文符号
        //再排除不符合的英文符号
//        String txt = Systems.getAttributeText(argField,tdAttrContent);
        String txt = argField;
//        int len1 = Strings.len(Strings.convertBlock(txt, 11));
//        int len2 = Strings.len(Strings.convertBlock(txt,13));
//        int len2 = Strings.len(argField);
//        int lenChinese = ( len2 - len1 );
        int lenChinese = 0;
        int num = 0;
        IStream txtStm = new StreamImpl();
        String line = NULLSTR;
        int p = 0;
        if (lenChinese == 0) {
            if (!MdaUtils.isEmpty(txt)) {
                Streams.streamSet(txtStm, txt);
                num = Streams.streamCount(txtStm);
            }
            if (num > 0) {
                for (int i = 1; i <= num; i++) {
                    line = Strings.getLine(txtStm, i);
                    if (!MdaUtils.isEmpty(line)) {
                        for (int j = 1; j <= Strings.len(line); j++) {
                            p = Strings.pos("}[]|~$`^", Strings.mid(line, j, 1));
                            if (p > 0) {
//                                ctx.setFieldError(argField,MdaUtils.getI18NString("trnmod","CT000305"));
//                                MdaUtils.exitRule();
//                                return "This fields is not allowed ";
                                resultMap.put(resultKey, I18nUtil.getMessage("0006"));
                            }
                        }
                    }
                }
            }
        }
//        else {
//            ctx.setFieldError(argField,MdaUtils.getI18NString("trnmod","CT000306"));
//            MdaUtils.exitRule();
//            return "此栏位不允许输入中文和中文符号以及全角字符 ";
//        }
        return resultMap;

    }

    public void trnORDBreak(Spt spt, String objName, BaseTransactionVo storeObj) {
        OrdmodVo ordmodVo = new OrdmodVo();
        List<Ore> oreList = new ArrayList<>();
        TrnInfo trnInfo = storeObj.getTrnInfo();
        if (trnInfo != null) {
            oreList = trnInfo.getOreList();
            ordmodVo.setOreList(oreList);
        }
        ordmodService.ordReadHold(spt.getOrdinr(), ordmodVo);
        if (MdaUtils.isEmpty(spt.getOrdinr())) {
            ordmodService.ordNew(ordmodVo);
        }
        if ("NEW".equals(ordmodVo.getOrdinr())) {
            ordmodVo.getOrd().setExtkey(SettleContext.getOwnPts() == null ? "" : SettleContext.getOwnPts().getExtkey());
            ordmodVo.getOrd().setNam((StringUtils.isNotEmpty(objName) && objName.length() > 60) ? objName.substring(0, 60) : objName);
            ordmodVo.getOrd().setObjtyp(spt.getObjtyp());
            ordmodVo.getOrd().setObjinr(spt.getObjinr());
            // Load responsible user from currently loaded USR
            ordmodVo.getOrd().setOwnusr(SettleContext.getUserSession().getUsr().getExtkey());
            // Load Workgroup, if field available in USR table
            ordmodVo.getOrd().setOwnusg(SettleContext.getUserSession().getUsr().getUsg());
            ordmodVo.getOrd().setSmhinr(spt.getSmhinr()); // incoming message
        }
        //>>>---------收单行上收业务的BREAK时候的标志----------
        Atp atp = SettleContext.getUserSession().getAtp();
        Bch bch = SettleContext.getUserSession().getBch();
        Bch workBch = SettleContext.getUserSession().getWrkbch();
        String sptSta = NULLSTR;
//        if ("X".equals(ordmodVo.getOrd().getSdhflg())   ||  ("X".equals(atp.getNegflg()))
//                || ("X".equals(atp.getNegflg()) && !bch.getBchkey().equals(bch.getBranch())
//                && StringUtils.isNotEmpty(bch.getBranch()))) {
        if ("X".equals(ordmodVo.getOrd().getSdhflg())) {
            sptSta = "CMB";
        } else {
            sptSta = "BRK";
        }
        ordmodVo.getOrd().setExtkey(objName.length() > 30 ? objName.substring(0, 30) : objName);
        ordmodVo.getOrd().setBchkeyinr(bch.getInr());
        ordmodVo.getOrd().setBranchinr(workBch.getInr());
        ordmodVo.getOrd().setFrm(SettleContext.getTransName());
        if ("1000".equals(SettleContext.getUserSession().getOrgBch().getBranch()) && StringUtils.isEmpty(ordmodVo.getOrd().getSdhflg())) {
            //押汇中心经办替收单行经办分行业务做的处理
            ordmodVo.getOrd().setSdhflg("X");
        }
        ordmodService.ordUpdate(ordmodVo, sptSta);
        spt.setOrdinr(ordmodVo.getOrd().getInr());
    }

    public void trnORDBreak(Spt spt, String objName) {
        //! Write/Update ORD on break (locked ORD will be released by free all)
        OrdmodVo ordmodVo = new OrdmodVo();
        ordmodService.ordReadHold(spt.getOrdinr(), ordmodVo);
        if (MdaUtils.isEmpty(spt.getOrdinr())) {
            ordmodService.ordNew(ordmodVo);
        }
        if ("NEW".equals(ordmodVo.getOrdinr())) {
            ordmodVo.getOrd().setExtkey(SettleContext.getOwnPts() == null ? "" : SettleContext.getOwnPts().getExtkey());
            ordmodVo.getOrd().setNam((StringUtils.isNotEmpty(objName) && objName.length() > 60) ? objName.substring(0, 60) : objName);
            ordmodVo.getOrd().setObjtyp(spt.getObjtyp());
            ordmodVo.getOrd().setObjinr(spt.getObjinr());
            // Load responsible user from currently loaded USR
            ordmodVo.getOrd().setOwnusr(SettleContext.getUserSession().getUsr().getExtkey());
            // Load Workgroup, if field available in USR table
            ordmodVo.getOrd().setOwnusg(SettleContext.getUserSession().getUsr().getUsg());
            ordmodVo.getOrd().setSmhinr(spt.getSmhinr()); // incoming message
        }
        //>>>---------收单行上收业务的BREAK时候的标志----------
        Atp atp = SettleContext.getUserSession().getAtp();
        Bch bch = SettleContext.getUserSession().getBch();
        Bch workBch = SettleContext.getUserSession().getWrkbch();
        //USG弃用
       /* Usg usg = null;
        List<Usg> usgList = usgMapper.getUsgByEtyextkey(SettleContext.getUserEty().getExtkey());
        if (usgList != null && usgList.size() > 0) {
            usg = usgList.get(0);
        }*/
        String sptSta = NULLSTR;
        //"X".equals(atp.getNegflg()) && "X".equals(usg.getCusmgrflg())
        if (("X".equals(atp.getNegflg()))
                || ("X".equals(atp.getNegflg()) && !bch.getBchkey().equals(bch.getBranch())
                && StringUtils.isNotEmpty(bch.getBranch()))) {
            sptSta = "CMB";
        } else {
            sptSta = "BRK";
        }
        ordmodVo.getOrd().setExtkey(objName.length() > 30 ? objName.substring(0, 30) : objName);
        ordmodVo.getOrd().setBchkeyinr(bch.getInr());
        ordmodVo.getOrd().setBranchinr(workBch.getInr());
        ordmodVo.getOrd().setFrm(SettleContext.getTransName());
        ordmodService.ordUpdate(ordmodVo, sptSta);
        spt.setOrdinr(ordmodVo.getOrd().getInr());
    }

    /**
     * source:trnmod.0120.script
     */
    public void trnORDCreate(TrnmodVo trnmodVo, Spt spt, String objName, BaseTransactionVo storeObj) {
        //! Write/Update ORD on create (locked ORD will be released by free all)
        String eventtyp = NULLSTR;
        if (MdaUtils.compareTo(spt.getSta(), "COR") == 0) {
            eventtyp = "COR";
        } else {
            eventtyp = "CRE";
        }
        OrdmodVo ordmodVo = trnmodVo.getOrdmod();
        if (MdaUtils.isEmpty(ordmodVo.getOrdinr())) {
            ordmodService.ordNew(ordmodVo);
        }

        if ("NEW".equals(ordmodVo.getOrdinr())) {
            TransactionServiceSet transactionServiceSet = transactionHelpService.getTransactionStoreSet();
            ordmodVo.getOrd().setExtkey(sysmodService.getReferenceOfRol(transactionServiceSet.getPtsList(), "OWN", transactionServiceSet.getRec()) + "/" + Formats.format(ordmodVo.getOre().getBegdattim(), "YYMMDD") + "/" + SettleContext.getTransName());
            ordmodVo.getOrd().setObjtyp(spt.getObjtyp());
            ordmodVo.getOrd().setObjinr(spt.getObjinr());
            // Load responsible user from currently loaded USR
            ordmodVo.getOrd().setOwnusr(SettleContext.getUserSession().getUsr().getExtkey());
            // Load Workgroup, if field available in USR table
            ordmodVo.getOrd().setOwnusg(SettleContext.getUserSession().getUsr().getUsg());
            ordmodVo.getOrd().setSmhinr(spt.getSmhinr()); // incoming message
        }
        Bch bch = SettleContext.getUserSession().getBch();
        Bch workBch = SettleContext.getUserSession().getWrkbch();
        ordmodVo.getOrd().setExtkey(objName.length() > 30 ? objName.substring(0, 30) : objName);
        ordmodVo.getOrd().setBchkeyinr(bch.getInr());
        ordmodVo.getOrd().setBranchinr(workBch.getInr());
        ordmodVo.getOrd().setFrm(SettleContext.getTransName());
        ordmodService.ordUpdate(ordmodVo, eventtyp);
        spt.setOrdinr(ordmodVo.getOrd().getInr());
        sysmodService.streamSaveInSubDir(storeObj, "display", trnmodVo.getTrn().getInr() + ".dsp");
    }

    /**
     * source:trnmod.0123.script
     */
    public boolean conCheck() {
        //如果是收单行做业务则返回false
        //其他返回true
        if (MdaUtils.compareTo(SettleContext.getUserSession().getBch().getLev(), "0") == 0) {
            return true;
        }
        if (SettleContext.getUserSession().getAtp() != null && MdaUtils.compareTo(SettleContext.getUserSession().getAtp().getNegflg(), "X") == 0
                && StringUtils.isNotEmpty(SettleContext.getUserSession().getBch().getBchkey())) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * source:trnmod.0177.script
     */
    public void east7759(BizInfoVo bizInfoVo, List<PtsptaVo> ptsList, List<SetgllVo> setgllVos, Argument<String> oppacc, Argument<String> oppnam, Argument<String> oppbnk) {
        String voppacc = "";
        String voppbnk = "";
        String voppnam = "";
        String objtyp = bizInfoVo.getObjtyp();
        switch (objtyp) {
            case "GID":
            case "NID":
            case "GCD":
            case "NCD":
                String hndtyp = Utils.getFieldValue(bizInfoVo, "hndtyp", "");
                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)) {
                    voppbnk = dyncDaoService.dyncReadFieldByInr(tableName, inr, "oppbnk");
                }
                String bank = "";
                if (SettleContext.getTransName().startsWith("GE") || SettleContext.getTransName().startsWith("NE")) {
                    PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ISS");
                    if (ptsptaVo != null) {
                        bank = StringUtils.isNotEmpty(ptsptaVo.getExtkey()) ? ptsptaVo.getExtkey() : ptsptaVo.getPts().getExtkey();
                    }
                } else {
                    PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ADV");
                    if (ptsptaVo != null) {
                        bank = StringUtils.isNotEmpty(ptsptaVo.getExtkey()) ? ptsptaVo.getExtkey() : ptsptaVo.getPts().getExtkey();
                    }
                }
                if ("OT".equalsIgnoreCase(hndtyp) || "FA".equalsIgnoreCase(hndtyp) || "FR".equalsIgnoreCase(hndtyp)) {
                    PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "APL");
                    if (ptsptaVo != null) {
                        voppnam = ptsptaVo.getNam();
                    }
                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ISS");
                    if (ptsptaVo != null) {
                        bank = StringUtils.isNotEmpty(ptsptaVo.getExtkey()) ? ptsptaVo.getExtkey() : ptsptaVo.getPts().getExtkey();
                    }
                } else {
                    PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "BEN");
                    if (ptsptaVo != null) {
                        voppnam = ptsptaVo.getNam();
                    }
                }
                if (MdaUtils.isEmpty(voppbnk)) {
                    voppbnk = Strings.mid(bank, 1, 11);
                }
                voppacc = "";
                String swftyp = Utils.getFieldValue(bizInfoVo, "swftyp", "");
                String cmtflg = Utils.getFieldValue(bizInfoVo, "cmtflg", "");
                if (MdaUtils.compareTo(swftyp, "CMT") == 0
                        || MdaUtils.compareTo(swftyp, "HVQ") == 0
                        || MdaUtils.compareTo(swftyp, "CIV") == 0
                        || MdaUtils.compareTo(cmtflg, "X") == 0) {
                    voppacc = Utils.getFieldValue(bizInfoVo, "pyeact", "");
                    voppnam = Utils.getFieldValue(bizInfoVo, "pyenam", "");
                    voppbnk = Utils.getFieldValue(bizInfoVo, "pyebchkey", "");
                } else {
                    for (SetgllVo setgllVo : setgllVos) {
                        String sftmt = setgllVo.getSftmt();
                        if ("202".equalsIgnoreCase(sftmt) || "756".equalsIgnoreCase(sftmt)) {
                            voppacc = setgllVo.getSespay().getBeiacc();
                            if (setgllVo.getSetgrp().getBei() != null) {
                                String oppbnk1 = setgllVo.getSetgrp().getBei().getExtkey();
                                if (StringUtils.isEmpty(oppbnk1)) {
                                    oppbnk1 = setgllVo.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) {
                                        voppbnk = Strings.mid(oppbnk1, 1, 11);
                                    } else {
                                        voppbnk = oppbnk1;
                                    }
                                }
                            }
                        }
                    }
                }
                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 (MdaUtils.compareTo(paytyp, "I") == 0) {
                    voppacc = cpd != null ? cpd.getOrcact() : cpdBizInfoVo.getOrcact();
                    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) {
                        voppnam = cpd != null ? cpd.getOrcnam() : cpdBizInfoVo.getOrcnam();
                    } else {
                        voppnam = cpd != null ? cpd.getOrcnam() : cpdBizInfoVo.getOrcnam();
                        if (StringUtils.isEmpty(voppnam)) {
                            if (cpd != null) {
                                voppnam = cpd.getOppnam();
                            }
                        }
                    }
                    if (!MdaUtils.isEmpty(sndbch)) {
                        voppbnk = sndbch;
                    } else {
                        PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ORI");
                        if (ptsptaVo != null) {
                            voppbnk = ptsptaVo.getExtkey();
                        }
                        //103报文中无52A时抓取发报行BIC
                        if (MdaUtils.compareTo(SettleContext.getTransName(), "CPTADV") == 0 && MdaUtils.isEmpty(voppbnk)) {
                            ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "SND");
                            if (ptsptaVo != null) {
                                voppbnk = ptsptaVo.getExtkey();
                            }
                        }
                        if (Strings.len(voppbnk) > 11) {
                            voppbnk = Strings.mid(voppbnk, 1, 11);
                        }
                    }
                    //---0514LWQ--cips：付款人开户行行号---
                    if (MdaUtils.compareTo(swftyp, "CIU") == 0
                            || MdaUtils.compareTo(swftyp, "CIV") == 0
                            || MdaUtils.compareTo(swftyp, "CIW") == 0) {
                        if (cpdBizInfoVo.getCpdCipsBizInfo() != null) {
                            voppbnk = cpdBizInfoVo.getCpdCipsBizInfo().getFkrkhh();
                        }
                    }
                    if (MdaUtils.compareTo(swftyp, "HVP") == 0 || MdaUtils.compareTo(swftyp, "HVQ") == 0) {
                        //---hvps-发起行行号---
                        voppbnk = cpdBizInfoVo.getSatbch();
                    }
                }
                if (MdaUtils.compareTo(paytyp, "O") == 0) {
                    voppacc = cpd != null ? cpd.getPyeact() : cpdBizInfoVo.getPyeact();
                    swftyp = cpd != null ? cpd.getSwftyp() : cpdBizInfoVo.getSwftyp();
                    String resbch = cpdBizInfoVo.getResbch();
                    voppnam = cpd != null ? cpd.getPyenam() : cpdBizInfoVo.getPyenam();
                    if (!MdaUtils.isEmpty(resbch)) {
                        voppbnk = resbch;
                        if (MdaUtils.compareTo(SettleContext.getTransName(), "CPTECO") == 0
                                && (MdaUtils.compareTo(swftyp, "FXP") == 0 || MdaUtils.compareTo(swftyp, "FMS") == 0)) {
                            String oppbnk1 = "";
                            PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "PYB");
                            if (ptsptaVo != null) {
                                oppbnk1 = ptsptaVo.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) {
                                    voppbnk = Strings.mid(oppbnk1, 1, 11);
                                } else {
                                    voppbnk = oppbnk1;
                                }
                            }
                        }
                    } else {
                        for (SetgllVo setgllVo : setgllVos) {
                            String sftmt = setgllVo.getSftmt();
                            if ("202".equalsIgnoreCase(sftmt) || "103".equalsIgnoreCase(sftmt)) {
                                //--此写法当报文类型为202COV时候，出的是COVER A的57场---
                                voppbnk = setgllVo.getSetgrp().getAwi().getExtkey();
                                if (MdaUtils.compareTo(swftyp, "200") == 0) {
                                    voppbnk = setgllVo.getSetgrp().getBei().getExtkey();
                                }
                                if (Strings.len(voppbnk) > 11) {
                                    voppbnk = Strings.mid(voppbnk, 1, 11);
                                }
                            }
                        }
                    }
                }
                break;
            case "BED":
            case "BFD":
                PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "APL");
                if (ptsptaVo != null) {
                    voppnam = ptsptaVo.getNam();
                }
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ISS");
                if (ptsptaVo != null) {
                    voppbnk = ptsptaVo.getExtkey();
                    if (Strings.len(voppbnk) > 11) {
                        voppbnk = Strings.mid(voppbnk, 1, 11);
                    }
                }
                break;
            case "BRD":
            case "BDD":
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "BEN");
                if (ptsptaVo != null) {
                    voppnam = ptsptaVo.getNam();
                }
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ADV");
                if (ptsptaVo != null) {
                    voppbnk = ptsptaVo.getExtkey();
                    if (Strings.len(voppbnk) > 11) {
                        voppbnk = Strings.mid(voppbnk, 1, 11);
                    }
                }
                swftyp = Utils.getFieldValue(bizInfoVo, "swftyp", "");
                if (MdaUtils.compareTo(swftyp, "CMT") == 0 || MdaUtils.compareTo(swftyp, "HVQ") == 0 || MdaUtils.compareTo(swftyp, "CIV") == 0) {
                    voppacc = Utils.getFieldValue(bizInfoVo, "pyeact", "");
                    voppnam = Utils.getFieldValue(bizInfoVo, "pyenam", "");
                    voppbnk = Utils.getFieldValue(bizInfoVo, "pyebchkey", "");
                } else {
                    for (SetgllVo setgllVo : setgllVos) {
                        String sftmt = setgllVo.getSftmt();
                        if ("202".equalsIgnoreCase(sftmt) || "756".equalsIgnoreCase(sftmt)) {
                            voppacc = setgllVo.getSespay().getBeiacc();
                            if (setgllVo.getSetgrp().getBei() != null) {
                                String oppbnk1 = setgllVo.getSetgrp().getBei().getExtkey();
                                if (StringUtils.isEmpty(oppbnk1)) {
                                    oppbnk1 = setgllVo.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) {
                                        voppbnk = Strings.mid(oppbnk1, 1, 11);
                                    } else {
                                        voppbnk = oppbnk1;
                                    }
                                }
                            }
                        }
                    }
                }
                if (MdaUtils.compareTo(Strings.mid(SettleContext.getTransName(), 4, 3), "DCK") == 0) {
                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "PRB");
                    if (ptsptaVo != null) {
                        String oppbnk1 = ptsptaVo.getExtkey();
                        if (MdaUtils.compareTo(Strings.mid(Strings.toUpper(oppbnk1), 1, 4), "TEMP") != 0 && !MdaUtils.isEmpty(oppbnk1)) {
                            if (Strings.len(oppbnk1) > 11) {
                                voppbnk = Strings.mid(oppbnk1, 1, 11);
                            }
                        }
                    }
                }
                if (MdaUtils.compareTo(SettleContext.getTransName(), "BDTSET") == 0) {
                    //voppbnk = Datas.getContent(this,"\\SKHNUM");
                    voppbnk = Utils.getFieldValue(bizInfoVo, "skhnum", "");
                    //voppnam = Datas.getContent(this,"\\SKR");
                    voppnam = Utils.getFieldValue(bizInfoVo, "skr", "");
                    //voppacc = Datas.getContent(this,"\\SKZH");
                    voppacc = Utils.getFieldValue(bizInfoVo, "skzh", "");
                }
                break;
            case "BCD":
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "DRR");
                if (ptsptaVo != null) {
                    voppnam = ptsptaVo.getNam();
                }
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "RMI");
                if (ptsptaVo != null) {
                    voppbnk = ptsptaVo.getExtkey();
                    if (Strings.len(voppbnk) > 11) {
                        voppbnk = Strings.mid(voppbnk, 1, 11);
                    }
                }
                swftyp = Utils.getFieldValue(bizInfoVo, "swftyp", "");
                if (MdaUtils.compareTo(swftyp, "CMT") == 0 || MdaUtils.compareTo(swftyp, "HVQ") == 0 || MdaUtils.compareTo(swftyp, "CIV") == 0) {
                    voppacc = Utils.getFieldValue(bizInfoVo, "pyeact", "");
                    voppnam = Utils.getFieldValue(bizInfoVo, "pyenam", "");
                    voppbnk = Utils.getFieldValue(bizInfoVo, "pyebchkey", "");
                } else {
                    for (SetgllVo setgllVo : setgllVos) {
                        String sftmt = setgllVo.getSftmt();
                        if ("202".equalsIgnoreCase(sftmt) || "400".equalsIgnoreCase(sftmt)) {
                            voppacc = setgllVo.getSespay().getBeiacc();
                            if (setgllVo.getSetgrp().getBei() != null) {
                                String oppbnk1 = setgllVo.getSetgrp().getBei().getExtkey();
                                if (StringUtils.isEmpty(oppbnk1)) {
                                    oppbnk1 = setgllVo.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) {
                                        voppbnk = Strings.mid(oppbnk1, 1, 11);
                                    } else {
                                        voppbnk = oppbnk1;
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            case "BTD":
            case "LTD":
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "BE2");
                if (ptsptaVo != null) {
                    voppnam = ptsptaVo.getNam();
                }
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ADT");
                if (ptsptaVo != null) {
                    voppbnk = ptsptaVo.getExtkey();
                    if (Strings.len(voppbnk) > 11) {
                        voppbnk = Strings.mid(voppbnk, 1, 11);
                    }
                }
                swftyp = Utils.getFieldValue(bizInfoVo, "swftyp", "");
                if (MdaUtils.compareTo(swftyp, "CMT") == 0 || MdaUtils.compareTo(swftyp, "HVQ") == 0 || MdaUtils.compareTo(swftyp, "CIV") == 0) {
                    voppacc = Utils.getFieldValue(bizInfoVo, "pyeact", "");
                    voppnam = Utils.getFieldValue(bizInfoVo, "pyenam", "");
                    voppbnk = Utils.getFieldValue(bizInfoVo, "pyebchkey", "");
                } else {
                    for (SetgllVo setgllVo : setgllVos) {
                        String sftmt = setgllVo.getSftmt();
                        if ("202".equalsIgnoreCase(sftmt) || "400".equalsIgnoreCase(sftmt)) {
                            voppacc = setgllVo.getSespay().getBeiacc();
                            if (setgllVo.getSetgrp().getBei() != null) {
                                String oppbnk1 = setgllVo.getSetgrp().getBei().getExtkey();
                                if (StringUtils.isEmpty(oppbnk1)) {
                                    oppbnk1 = setgllVo.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) {
                                        voppbnk = Strings.mid(oppbnk1, 1, 11);
                                    } else {
                                        voppbnk = oppbnk1;
                                    }
                                }
                            }
                        }
                    }
                }
                if (MdaUtils.compareTo(Strings.mid(SettleContext.getTransName(), 4, 3), "DCK") == 0) {
                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "PRB");
                    if (ptsptaVo != null) {
                        String oppbnk1 = ptsptaVo.getExtkey();
                        if (MdaUtils.compareTo(Strings.mid(Strings.toUpper(oppbnk1), 1, 4), "TEMP") != 0 && !MdaUtils.isEmpty(oppbnk1)) {
                            if (Strings.len(oppbnk1) > 11) {
                                voppbnk = Strings.mid(oppbnk1, 1, 11);
                            }
                        }
                    }
                }
                break;
            case "CCD":
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "COR");
                if (!ptsptaToolComponent.ptsIsRolSet(ptsptaVo)) {
                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "PRE");
                }
                if (ptsptaVo != null) {
                    voppnam = ptsptaVo.getNam();
                }
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "COL");
                if (!ptsptaToolComponent.ptsIsRolSet(ptsptaVo)) {
                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "DRO");
                }
                if (ptsptaVo != null) {
                    voppbnk = ptsptaVo.getExtkey();
                    if (Strings.len(voppbnk) > 11) {
                        voppbnk = Strings.mid(voppbnk, 1, 11);
                    }
                }
                break;
            case "BOD":
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "DRE");
                if (ptsptaVo != null) {
                    voppnam = ptsptaVo.getNam();
                }
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "COL");
                if (ptsptaVo != null) {
                    voppbnk = ptsptaVo.getExtkey();
                    if (Strings.len(voppbnk) > 11) {
                        voppbnk = Strings.mid(voppbnk, 1, 11);
                    }
                }
                break;
            case "TRD":
            case "BPD":
                voppacc = Utils.getFieldValue(bizInfoVo, "oppacc", "");
                if (StringUtils.isEmpty(voppacc)) {
                    voppacc = dyncDaoService.dyncReadFieldByInr(bizInfoVo.getObjtyp(), bizInfoVo.getObjinr(), "oppacc");
                }
                break;
            case "LID":
            case "DID":
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "BEN");
                if (ptsptaVo != null) {
                    voppnam = ptsptaVo.getNam();
                }
                voppbnk = Utils.getFieldValue(bizInfoVo, "oppbnk", "");
                if (StringUtils.isEmpty(voppbnk)) {
                    voppbnk = dyncDaoService.dyncReadFieldByInr(bizInfoVo.getObjtyp(), bizInfoVo.getObjinr(), "oppbnk");
                }
                if (StringUtils.isEmpty(voppbnk)) {
                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ADV");
                    if (ptsptaVo != null) {
                        voppbnk = ptsptaVo.getExtkey();
                    }
                }
                voppbnk = Strings.mid(voppbnk, 1, 11);
                break;
            case "LED":
            case "DED":
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "APL");
                if (ptsptaVo != null) {
                    voppnam = ptsptaVo.getNam();
                }
                voppbnk = Utils.getFieldValue(bizInfoVo, "oppbnk", "");
                if (StringUtils.isEmpty(voppbnk)) {
                    voppbnk = dyncDaoService.dyncReadFieldByInr(bizInfoVo.getObjtyp(), bizInfoVo.getObjinr(), "oppbnk");
                }
                if (StringUtils.isEmpty(voppbnk)) {
                    ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ISS");
                    if (ptsptaVo != null) {
                        voppbnk = ptsptaVo.getExtkey();
                    }
                }
                voppbnk = Strings.mid(voppbnk, 1, 11);
                break;
            case "DFD":
                ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "DFF");
                if (ptsptaVo != null) {
                    voppbnk = ptsptaVo.getExtkey();
                    if (Strings.len(voppbnk) > 11) {
                        voppbnk = Strings.mid(voppbnk, 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();
                        }*/
                        voppacc = Utils.getFieldValue(bizInfoVo, "pyeact", "");
                        voppnam = Utils.getFieldValue(bizInfoVo, "pyenam", "");
                        voppbnk = Utils.getFieldValue(bizInfoVo, "pyebchkey", "");
                    }
                    if (MdaUtils.compareTo(swftyp, "100") == 0 || MdaUtils.compareTo(swftyp, "111") == 0) {
                        //voppbnk = Datas.getContent(this,"\\DFTP\\RESBCH");
                        voppbnk = Utils.getFieldValue(bizInfoVo, "resbch", "");
                        //voppnam = Datas.getContent(this,"\\DFTP\\RESBCHNAM");
                        voppnam = Utils.getFieldValue(bizInfoVo, "resbchnam", "");
                    }
                    if (MdaUtils.compareTo(swftyp, "202") == 0) {
                        for (SetgllVo setgllVo : setgllVos) {
                            String sftmt = setgllVo.getSftmt();
                            if ("202".equalsIgnoreCase(sftmt) || "756".equalsIgnoreCase(sftmt)) {
                                voppacc = setgllVo.getSespay().getBeiacc();
                                if (setgllVo.getSetgrp().getBei() != null) {
                                    String oppbnk1 = setgllVo.getSetgrp().getBei().getExtkey();
                                    if (StringUtils.isEmpty(oppbnk1)) {
                                        oppbnk1 = setgllVo.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) {
                                            voppbnk = Strings.mid(oppbnk1, 1, 11);
                                        } else {
                                            voppbnk = oppbnk1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            case "FCD":
            case "JSD":
            case "MCD":
                break;
            default:
                throw new CommonServiceException("east7759 无效的业务种类{" + objtyp + "}");
        }
        //String transName = SettleContext.getTransName();
        String transName = SettleContext.getDirectTransName();
        String swftyp = Utils.getFieldValue(bizInfoVo, "swftyp", "");
        String oppnam1 = "";
        String umdchkflg = NULLSTR;
        switch (transName) {
            case "CPTOPN":
            case "CPTECO":
                if (Strings.pos("-200-103-202-", swftyp) > 0) {
                    PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "PYE");
                    if (ptsptaVo != null) {
                        oppnam1 = ptsptaVo.getNam();
                    }
                }
                break;
            case "CPTADV":
            case "CPTECI":
                PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "ORC");
                if (ptsptaVo != null) {
                    oppnam1 = ptsptaVo.getNam();
                }
                break;
            case "LITOPN":
            case "LITAME":
            case "LITDCK":
            case "BCTDAV":
            case "BCTAME":
            case "LETOPN":
            case "LETAME":
            case "LETRSV":
            case "LETDRW":
            case "BOTDAV":
            case "BOTAME":
            case "DFTMSG":
            case "CCTDAV":
            case "CLTDAV":
            case "LTTOPN":
            case "LTTDCK":
            case "LTTAME":
            case "GITOPN":
            case "GITPOP":
            case "NITOPN":
            case "NITPOP":
            case "HITOPN":
            case "HITPOP":
            case "GITAME":
            case "GITPAM":
            case "NITAME":
            case "NITPAM":
            case "GETOPN":
            case "NETOPN":
            case "GETAME":
            case "NETAME":
            case "BCTSET":
            case "BRTSET":
            case "GITSET":
            case "NITSET":
            case "GITPSE":
            case "NITPSE":
            case "GITODZ":
                umdchkflg = Inis.getIniBlock("intace.ini", "FXQGFX", "open");
                if ("Y".equalsIgnoreCase(umdchkflg)) {
                    UmdmodVo umdmodVo = transactionHelpService.getTransactionStoreSet().getUmdmodVo();
                    if (umdmodVo != null) {
                        oppnam1 = umdmodVo.getBennam();
                    }
                }
                break;
        }
        if (!MdaUtils.isEmpty(Strings.trim(oppnam1))) {
            voppnam = oppnam1;
        }
        if (MdaUtils.isEmpty(voppacc)) {
            voppacc = "0";
        }
        if (MdaUtils.compareTo(objtyp, "CLD") == 0) {
            PtsptaVo ptsptaVo = ptsptaToolComponent.getPtsFromListByRol(ptsList, "COL");
            if (ptsptaVo != null) {
                voppbnk = ptsptaVo.getExtkey();
                if (Strings.len(voppbnk) > 11) {
                    voppbnk = Strings.mid(voppbnk, 1, 11);
                }
            }
        }
        if (MdaUtils.compareTo(SettleContext.getTransName(), "DFTSET") == 0) {
            voppacc = "";
            voppbnk = "";
            voppnam = "";
        }
        oppacc.value = voppacc;
        oppbnk.value = voppbnk;
        oppnam.value = voppnam;
    }

    /**
     * 保存统一名单的交易对手信息
     *
     * @param rec
     */
    void saveUmdbennam(Object rec) {
        if (ObjectUtils.isEmpty(rec)) {
            return;
        }

        UmdmodVo umdmodVo = transactionHelpService.getTransactionStoreSet().getUmdmodVo();
        if (!ObjectUtils.isEmpty(umdmodVo)) {
            Utils.setFieldValue(rec, "oppnam", umdmodVo.getBennam());
        }


    }

    /**
     * source:trnmod.0075.script
     */
    public void getCommonGroupMt(Argument<String> argMT) {
        //! Check passed message type.
        //! If passed message type is empty, 1st digit will be returned only.
        // ArgMT     = message type
        // ArgCORTYP = medium, because TCO can get other MTs
        // get 1st digit of message type
        String v1st = Strings.mid(argMT.value, 1, 1);
        // get remaining digits
        String end = Strings.mid(argMT.value, 2);
        switch (SettleContext.getUserSession().getAtp().getBus()) {
            // Clean Payment
            case "CP":
                /**
                 $1st = "1"
                 **/
                v1st = "9";
                // Import/Export Collection
                break;
            case "BC":
            case "BO":
            case "CC":
                v1st = "4";
                // Import: L/C, L/C Documents
                // Export: L/C, L/C Documents, L/C Transfer, L/C Transfer Document
                // Guarantee, Guarantee Claim
                // Reimbursement, Reimbursement Claim
                // DNGDEV.002002 Syndication Deal
                break;
            case "LI":
            case "BR":
            case "LE":
            case "BE":
            case "LT":
            case "BT":
            case "GI":
            case "GC":
            case "RM":
            case "RC":
            case "BP":
            case "TR":
            case "FS":
            case "FP":
            case "PA":
            case "LD":
            case "MC":
            case "SD":
            case "GE":
                v1st = "7";
                // all other messages are using "9"
                break;
            default:
                v1st = "9";
        }
        argMT.value = v1st + end;
    }

    /**
     * source:trnmod.0076.script
     *
     * @param value
     * @param argCodeMandatory
     * @param argTag
     * @param argMT
     * @param argErrFlg
     * @param argCur
     */
    public String checkSWTCode(String value, boolean argCodeMandatory, String argTag, String argMT, boolean argErrFlg, String argCur, int rowLength, int lineLength) {
        //! Checks the passed field for used codes.
        // ArgCodeMandatory = FALSE (not mandatory) = User may use codes.
        //                    TRUE      (mandatory) = User must use a code.
        // ArgWrnFlg = FALSE = If error found, set warning with SYSWRN
        //           = TRUE  = If error found, set Error on ArgField
        //   mandatory:
        // each line has to be started with a slash "/"
        // each line has to be included a 2nd slash "//"
        // 1st line has to be started with a swift code
        // 1st line: /code1/aaa
        // 2nd line: /code2/bbb
        // 3nd line: //bbb
        //   not mandatory:
        // any line, that is started with a slash, has to be included a 2nd slash
        // 1st line: aaa
        // 2nd line: /code2/bbb
        // 3nd line: //bbb
        // NOTE: To get codes to top use "SWTMoveCodesToTop"!
        //   always:
        // if there is any text between 2 slashs "/xxx/", it has to be a swift code
        // code can consists of max. 8 digits
        String errtxt = "";
        String code = swtGetAllowedCodes(argTag, argMT, argCur);
        IStream codStm = new StreamImpl();
        Streams.streamSet(codStm, code);
        //String txt = Systems.getAttributeText(argField,tdAttrContent);
        String txt = value;
        // get number of lines and length of ArgField
        int linNum = rowLength;
        int lenNum = lineLength;
        // convert according to properties of passed ArgField
        // ConvType=1 : For calculation of line break include character conversion too!
        txt = StringUtils.convertBlock(txt, linNum, lenNum);
        //dngdev.001640
        boolean v1stLinehasslash = false;
        IStream txtStm = new StreamImpl();
        int num = 0;
        String lin = "";
        int v1stPos = 0;
        boolean check4error = false;
        String linNew = "";
        int v2ndPos = 0;
        String cod = "";
        int stmCnt = 0;
        boolean errMsg = false;
        String codLin = "";
        if (!MdaUtils.isEmpty(txt)) {
            Streams.streamSet(txtStm, txt);
            num = Streams.streamCount(txtStm);
            for (int i = 1; i <= num; i++) {
                lin = Strings.getLine(txtStm, i);
                if (!MdaUtils.isEmpty(lin)) {
                    // look for 1st slash
                    v1stPos = Strings.pos(lin, "/");
                    if (v1stPos != 1) {
                        //dngdev.001640
                        if (i > 1) {
                            switch (argTag) {
                                case "76":
                                case "79":
                                    check4error = true;
                                    if (MdaUtils.compareTo(argTag, "79") == 0 && MdaUtils.compareTo(Strings.mid(argMT, 2, 2), "92") != 0) {
                                        check4error = false;
                                    }
                                    if (v1stLinehasslash && check4error) {
                                        errtxt = Strings.getText("Line $1 has to start with a slash (\'/\').", i);
                                        break;
                                    }
                                    break;
                                default:
                                    //nothing
                            }
                        }
                        // if code must used
                        if (argCodeMandatory) {
                            errtxt = Strings.getText("Line $1 has to start with a slash (\'/\').", i);
                            break;
                        }
                    } else {
                        // if exists a slash at 1st position of any line
                        if (i == 1) {
                            v1stLinehasslash = true;
                        } else {
                            switch (argTag) {
                                case "76":
                                case "79":
                                    check4error = true;
                                    if (MdaUtils.compareTo(argTag, "79") == 0 && MdaUtils.compareTo(Strings.mid(argMT, 2, 2), "92") != 0) {
                                        check4error = false;
                                    }
                                    if (!v1stLinehasslash && check4error) {
                                        errtxt = Strings.getText("Line $1 must not start with a slash (\'/\').", i);
                                        break;
                                    }
                                    break;
                                default:
                                    //nothing
                            }
                        }
                        // look for 2nd slash
                        linNew = Strings.mid(lin, 2);
                        v2ndPos = Strings.pos(linNew, "/");
                        if (v2ndPos == 0) {
                            errtxt = Strings.getText("A 2nd slash (\'/\') is missing at line $1.", i);
                            break;
                        } else {
                            // if exists a 2nd slash
                            if (v2ndPos == 1) {
                                if (i == 1) {
                                    errtxt = Strings.getText("1st line has to start with a codeword.");
                                    break;
                                }
                            }
                            // to do: maximum position of 2nd slash may only be 10
                            cod = Strings.mid(lin, 2, v2ndPos - 1);
                            if (MdaUtils.isEmpty(cod) && i != 1) {
                                // each other line can be started with "//"
                            } else {
                                // compare current code of field line ($Cod) with allowed codes ($CodStm)
                                stmCnt = Streams.streamCount(codStm);
                                errMsg = true;
                                for (int j = 1; j <= stmCnt; j++) {
                                    codLin = Strings.getLine(codStm, j);
                                    if (MdaUtils.compareTo(cod.toUpperCase() + "\t", codLin + "\t") == 0) {
                                        // this code is possible
                                        errMsg = false;
                                        break;
                                    }
                                }
                                if (errMsg) {
                                    errtxt = Strings.getText("The following codes are allowed to use only:\n$1.", code);
                                    // don`t repeat error message
                                    break;
                                }
                                Argument<String> errtxtBox = new Argument<String>("", errtxt);
                                if (checkSWTCodeSyntax(lin, cod, argTag, argMT, errtxtBox)) {
                                    errtxt = errtxtBox.value;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (argErrFlg) {
            return errtxt;
        } else {
            if (StringUtils.isNotEmpty(errtxt)) {
                return Strings.getText("Error in message $1, tag $2: ", argMT, argTag) + CR + errtxt;
            }
        }
        return "";
    }

    public String swtGetAllowedCodes(String argTag, String argMT, String argCur) {
        //! Get allowed codes for passed tag and message type.
        // DO5DOS 008399 new codes für n90, 291
        String code = "";
        // remove `:` from ArgTag-Content
        String tag = argTag;
        if (Strings.pos(tag, ":") == 1) {
            tag = Strings.mid(tag, 2);
        }
        if (Strings.pos(tag, ":") > 0) {
            tag = Strings.mid(tag, 1, Strings.pos(tag, ":") - 1);
        }
        switch (tag) {
            // Tag :70:
            case "70":
                switch (argMT) {
                    case "103":
                        code = code + "INV" + "\n";
                        code = code + "IPI" + "\n";
                        code = code + "RFB" + "\n";
                        code = code + "ROC" + "\n";
                        code = code + "TSU" + "\n";
                        break;
                    default:
                        // no codes
                }
                // Tag :71B:
                break;
            case "71B":
                switch (argMT) {
                    // Correction for MT491,791,490 and 790
                    case "400":
                    case "700":
                    case "710":
                    case "720":
                    case "730":
                    case "491":
                    case "791":
                    case "490":
                    case "790":
                        code = code + "AGENT" + "\n";
                        code = code + "TELECHAR" + "\n";
                        code = code + "COMM" + "\n";
                        code = code + "CORCOM" + "\n";
                        code = code + "DISC" + "\n";
                        code = code + "INSUR" + "\n";
                        code = code + "POST" + "\n";
                        code = code + "STAMP" + "\n";
                        code = code + "WAREHOUS" + "\n";
                        break;
                    case "740":
                        code = code + "ACCECHGS" + "\n";
                        code = code + "DISCCHGS" + "\n";
                        // Correction for MT191,291,190 and 290
                        break;
                    case "191":
                    case "291":
                    case "190":
                    case "290":
                        code = code + "COMM" + "\n";
                        code = code + "INT" + "\n";
                        code = code + "PHON" + "\n";
                        code = code + "TELE" + "\n";
                        code = code + "TELEX" + "\n";
                        code = code + "AMND" + "\n";
                        code = code + "CANF" + "\n";
                        code = code + "CLEF" + "\n";
                        code = code + "INVS" + "\n";
                        code = code + "NSTP" + "\n";
                        code = code + "OURC" + "\n";
                        break;
                    default:
                        // no codes
                }
                //Tag :71M:
                break;
            case "71M":
                switch (argMT) {
                    case "757":
                        code = code + "ACCPTCOM" + "\n";
                        code = code + "ADVCOM" + "\n";
                        code = code + "AMNDCOM" + "\n";
                        code = code + "CMTCOM" + "\n";
                        code = code + "COMM" + "\n";
                        code = code + "CONFCOM" + "\n";
                        code = code + "CORCOM" + "\n";
                        code = code + "COUR" + "\n";
                        code = code + "DEFCOM" + "\n";
                        code = code + "DSCRPCOM" + "\n";
                        code = code + "FORFAIT" + "\n";
                        code = code + "HANDLCOM" + "\n";
                        code = code + "INTEREST" + "\n";
                        code = code + "INSUR" + "\n";
                        code = code + "ISSCOM" + "\n";
                        code = code + "MISC" + "\n";
                        code = code + "NEGCOM" + "\n";
                        code = code + "NOTFCOM" + "\n";
                        code = code + "PAYCOM" + "\n";
                        code = code + "POST" + "\n";
                        code = code + "PREADCOM" + "\n";
                        code = code + "PURCH" + "\n";
                        code = code + "SWIFT" + "\n";
                        code = code + "TELECHAR" + "\n";
                        code = code + "TRANSCOM" + "\n";
                        break;
                }
                // Tag :72:
                break;
            case "72":
            case "72Z":
                switch (argMT) {
                    case "103":
                        if (MdaUtils.compareTo(argCur, "CNH") == 0) {
                            // DO5WGZ.001696
                            code = code + "REMTDR" + "\n";
                            code = code + "CGODDR" + "\n";
                            code = code + "CSTRDR" + "\n";
                            code = code + "CCTFDR" + "\n";
                            code = code + "CCDNDR" + "\n";
                            code = code + "COCADR" + "\n";
                        } else {
                            code = code + "ACC" + "\n";
                            code = code + "INS" + "\n";
                            code = code + "INT" + "\n";
                            code = code + "PPRO" + "\n";
                            // DNGDEV.001898 - REC is not allow in SR 2019
                            //if not IsSwiftRelNov2019Active then
                            //  $Code = $Code + "REC" +  "\n"
                            //endif
                            //dngdev.003391 codes REJT + RETN removed for payment messages to avoid conflicts with Swifts Payme
                        }
                        break;
                    case "202":
                        if (MdaUtils.compareTo(argCur, "CNH") == 0) {
                            // DO5WGZ.001696
                            code = code + "BGODDR" + "\n";
                            code = code + "BSTRDR" + "\n";
                            code = code + "BNDDR" + "\n";
                            code = code + "BCTFDR" + "\n";
                            code = code + "BOCADR" + "\n";
                            code = code + "BFTFDR" + "\n";
                        } else {
                            code = code + "BEN" + "\n";
                            code = code + "DEDUCT" + "\n";
                            code = code + "ACC" + "\n";
                            code = code + "BNF" + "\n";
                            code = code + "INS" + "\n";
                            code = code + "INT" + "\n";
                            code = code + "PHON" + "\n";
                            code = code + "PHONBEN" + "\n";
                            code = code + "PHONIBK" + "\n";
                            // DNGDEV.001898 - REC is not allow in SR 2019
                            //if not IsSwiftRelNov2019Active then
                            //  $Code = $Code + "REC" +  "\n"
                            //endif
                            //dngdev.003391 codes REJT + RETN removed for payment messages to avoid conflicts with Swifts Payme
                            code = code + "TELE" + "\n";
                            code = code + "TELEBEN" + "\n";
                            code = code + "TELEIBK" + "\n";
                            code = code + "TSU" + "\n";
                        }
                        break;
                    case "400":
                        code = code + "ALCHAREF" + "\n";
                        code = code + "OUCHAREF" + "\n";
                        code = code + "UCHAREF" + "\n";
                        code = code + "PHONBEN" + "\n";
                        code = code + "REC" + "\n";
                        code = code + "TELEBEN" + "\n";
                        code = code + "BNF" + "\n";
                        code = code + "TSU" + "\n";
                        break;
                    case "410":
                        code = code + "DRAWEE" + "\n";
                        code = code + "FORWARD" + "\n";
                        code = code + "REC" + "\n";
                        break;
                    case "412":
                        code = code + "ALCHAREF" + "\n";
                        code = code + "DOMICIL" + "\n";
                        code = code + "HOLD" + "\n";
                        code = code + "OUCHAREF" + "\n";
                        code = code + "REC" + "\n";
                        code = code + "RETURN" + "\n";
                        code = code + "UCHAREF" + "\n";
                        break;
                    case "430":
                        code = code + "TSU" + "\n";
                        break;
                    case "700":
                    case "705":
                    case "710":
                    case "720":
                    case "707":
                        //dngdev.001410 since SR2018 MT 707 Tag 72Z allows only PHONBEN and TELEBEN
                        code = code + "PHONBEN" + "\n";
                        code = code + "TELEBEN" + "\n";
                        break;
                    case "760":
                    case "767":
//                        if (isSwtRelNov2020Active()) {
                        // DNGDEv.001410 only code TELEBEN or PHONBEN are allowed
                        code = code + "PHONBEN" + "\n";
                        code = code + "TELEBEN" + "\n";
//                        } else {
//                            code = code + "BENCON" +  "\n";
//                            code = code + "PHONBEN" +  "\n";
//                            code = code + "TELEBEN" +  "\n";
//                        }
                        break;
                    case "730":
                        code = code + "BENACC" + "\n";
                        code = code + "BENREJ" + "\n";
                        //dngdev.001410: With SR2020 MT768 do not have Code limitation anymore
                        break;
                    case "768":
//                        if (!isSwtRelNov2020Active()) {
//                            code = code + "BENACC" +  "\n";
//                            code = code + "BENREJ" +  "\n";
//                        }
                        break;
                    case "742":
                        code = code + "REIMBREF" + "\n";
                        break;
                    case "747":
                        code = code + "CANC" + "\n";
                        break;
                    case "752":
                    case "756":
                        /**
                         $Code = $Code + "RCB" +  "\n"
                         **/
                        break;
                    case "754":
                        code = code + "ACC" + "\n";
                        code = code + "PHONBEN" + "\n";
                        code = code + "REC" + "\n";
                        code = code + "TELEBEN" + "\n";
                        //      case <other MT>
                        break;
                    default:
                        // no codes
                }
                // Tag :73:
                break;
            case "73":
                switch (argMT) {
                    case "400":
                        code = code + "INTEREST" + "\n";
                        code = code + "RETCOMM" + "\n";
                        code = code + "YOURCHAR" + "\n";
                        break;
                    case "754":
                        code = code + "ACCPTCOM" + "\n";
                        code = code + "ADVCOM" + "\n";
                        code = code + "AMNDCOM" + "\n";
                        code = code + "CONFCOM" + "\n";
                        code = code + "CORCOM" + "\n";
                        code = code + "DEFCOM" + "\n";
                        code = code + "DSCRPCOM" + "\n";
                        code = code + "HANDLCOM" + "\n";
                        code = code + "INTEREST" + "\n";
                        code = code + "MISC" + "\n";
                        code = code + "NEGCOM" + "\n";
                        code = code + "NOTFCOM" + "\n";
                        code = code + "PAYCOM" + "\n";
                        code = code + "POST" + "\n";
                        code = code + "PREADCOM" + "\n";
                        code = code + "SEE72" + "\n";
                        code = code + "SEE77A" + "\n";
                        code = code + "STAMP" + "\n";
                        code = code + "TELECHAR" + "\n";
                        break;
                    default:
                        // no codes
                }
                // Tag :74:
                break;
            case "74":
                switch (argMT) {
                    case "430":
                        code = code + "CLOSE" + "\n";
                        code = code + "FREE" + "\n";
                        code = code + "HOLDCEP" + "\n";
                        code = code + "SENDCEP" + "\n";
                        //      case <other MT>
                        break;
                    default:
                        // no codes
                }
                // Tag :75:
                break;
            case "75":
                switch (argMT) {
                    case "422":
                        code = code + "1" + "\n";
                        code = code + "14" + "\n";
                        code = code + "15" + "\n";
                        code = code + "16" + "\n";
                        // DO5DOS.006583
                        break;
                    case "195":
                    case "295":
                    case "495":
                    case "795":
                    case "995":
                        code = code + "1" + "\n";
                        code = code + "2" + "\n";
                        code = code + "3" + "\n";
                        code = code + "4" + "\n";
                        code = code + "5" + "\n";
                        code = code + "6" + "\n";
                        code = code + "7" + "\n";
                        code = code + "8" + "\n";
                        code = code + "9" + "\n";
                        code = code + "10" + "\n";
                        code = code + "11" + "\n";
                        code = code + "12" + "\n";
                        code = code + "13" + "\n";
                        code = code + "14" + "\n";
                        code = code + "15" + "\n";
                        code = code + "16" + "\n";
                        code = code + "17" + "\n";
                        code = code + "18" + "\n";
                        code = code + "19" + "\n";
                        code = code + "20" + "\n";
                        code = code + "22" + "\n";
                        // DO5DOS.011969 - intentionally directly checked here as this is the only change for 2017 - use GENDAT for test
                        if (Dates.diff(Dates.today(), Strings.parseDate("19/11/2017")) >= 0) {
                            code = code + "33" + "\n";
                        }
                        code = code + "36" + "\n";
                        code = code + "37" + "\n";
                        code = code + "38" + "\n";
                        code = code + "39" + "\n";
                        code = code + "40" + "\n";
                        code = code + "41" + "\n";
                        code = code + "42" + "\n";
                        code = code + "43" + "\n";
                        code = code + "44" + "\n";
                        code = code + "45" + "\n";
                        code = code + "46" + "\n";
                        code = code + "47" + "\n";
                        code = code + "48" + "\n";
                        code = code + "49" + "\n";
                        code = code + "50" + "\n";
                        code = code + "51" + "\n";
                        //do5dos.009920
                        code = code + "52" + "\n";
                        // additional codes are available for MT 295 only
                        if (MdaUtils.compareTo(argMT, "295") == 0) {
                            code = code + "23" + "\n";
                            code = code + "24" + "\n";
                            code = code + "25" + "\n";
                            code = code + "26" + "\n";
                            code = code + "27" + "\n";
                            code = code + "28" + "\n";
                            code = code + "29" + "\n";
                            code = code + "30" + "\n";
                            code = code + "31" + "\n";
                            code = code + "32" + "\n";
                            // DO5DOS.011969 - intentionally directly checked here as this is the only change for 2017 - use GENDAT for test
                            if (Dates.diff(Dates.today(), Strings.parseDate("19/11/2017")) < 0) {
                                code = code + "33" + "\n";
                            }
                            code = code + "34" + "\n";
                            code = code + "35" + "\n";
                        }
                        //      case <other MT>
                        break;
                    default:
                        // no codes
                }
                // Tag :76:
                break;
            case "76":
                switch (argMT) {
                    case "422":
                        code = code + "1" + "\n";
                        code = code + "2" + "\n";
                        code = code + "10" + "\n";
                        code = code + "ARRIVCEP" + "\n";
                        code = code + "ARRIVPAY" + "\n";
                        code = code + "DIRECPAY" + "\n";
                        code = code + "DRAWEE" + "\n";
                        code = code + "EXCONPER" + "\n";
                        code = code + "INFNOCEP" + "\n";
                        code = code + "INFNOPAY" + "\n";
                        code = code + "LOCAL" + "\n";
                        code = code + "NOANSWER" + "\n";
                        code = code + "PROMICEP" + "\n";
                        code = code + "PROMIPAY" + "\n";
                        //      case <other MT>
                        break;
                    case "196":
                    case "296":
                    case "496":
                    case "796":
                    case "996":
                        code = code + "1" + "\n";
                        code = code + "2" + "\n";
                        code = code + "3" + "\n";
                        code = code + "4" + "\n";
                        code = code + "5" + "\n";
                        code = code + "6" + "\n";
                        code = code + "7" + "\n";
                        code = code + "8" + "\n";
                        code = code + "9" + "\n";
                        code = code + "10" + "\n";
                        code = code + "11" + "\n";
                        code = code + "12" + "\n";
                        code = code + "13" + "\n";
                        code = code + "14" + "\n";
                        code = code + "15" + "\n";
                        code = code + "16" + "\n";
                        code = code + "17" + "\n";
                        code = code + "18" + "\n";
                        code = code + "19" + "\n";
                        code = code + "20" + "\n";
                        code = code + "22" + "\n";
                        code = code + "23" + "\n";
                        code = code + "24" + "\n";
                        code = code + "25" + "\n";
                        code = code + "26" + "\n";
                        code = code + "27" + "\n";
                        code = code + "28" + "\n";
                        code = code + "29" + "\n";
                        code = code + "30" + "\n";
                        code = code + "31" + "\n";
                        code = code + "32" + "\n";
                        code = code + "33" + "\n";
                        //dngdev.001640
                        code = code + "CNCL" + "\n";
                        code = code + "PDCR" + "\n";
                        code = code + "RJCR" + "\n";
                        code = code + "CODE" + "\n";
                        code = code + "AC04" + "\n";
                        code = code + "AGNT" + "\n";
                        code = code + "AM04" + "\n";
                        code = code + "ARDT" + "\n";
                        code = code + "ARPL" + "\n";
                        code = code + "CUST" + "\n";
                        code = code + "INDM" + "\n";
                        code = code + "LEGL" + "\n";
                        code = code + "NOAS" + "\n";
                        code = code + "NOOR" + "\n";
                        code = code + "PTNA" + "\n";
                        code = code + "RQDA" + "\n";
                        break;
                    default:
                        // no codes
                }
                // Tag :77:
                break;
            case "77B":
                switch (argMT) {
                    case "734":
                        code = code + "RETURN" + "\n";
                        code = code + "HOLD" + "\n";
                        code = code + "NOTIFY" + "\n";
                        code = code + "PREVINST" + "\n";
                        //      case <other MT>
                        break;
                    default:
                        // no codes
                }
                // Tag :79:
                break;
            case "79":
                switch (argMT) {
                    case "707":
                        code = code + "CANCEL" + "\n";
                        break;
                    case "192":
                    case "292":
                    case "492":
                    case "792":
                    case "992":
                        code = code + "AGNT" + "\n";
                        code = code + "CURR" + "\n";
                        code = code + "CUST" + "\n";
                        code = code + "CUTA" + "\n";
                        code = code + "DUPL" + "\n";
                        code = code + "FRAD" + "\n";
                        code = code + "TECH" + "\n";
                        code = code + "UPAY" + "\n";
                        // DNGDEV.001907 - Adding new Codes for SR2019
                        //if IsSwiftRelNov2019Active then
                        code = code + "AM09" + "\n";   // Amount is not the amount agreed or expected
                        code = code + "COVR" + "\n";   // Cover payment ahs either been returned or cancelled
                        //endif
                        break;
                    default:
                        // no codes
                }
                //  case "<other Tag>"
                break;
            default:
                // no codes
        }
        return code;
    }

    public boolean checkSWTCodeSyntax(String argLine, String argCode, String argTag, String argMT, Argument<String> errTxt) {
        //取得上下文
        //! Checks the passed field for used code syntax.
        //! Corresponding function:
        boolean error = false;
        String text = Strings.trim(Strings.mid(argLine, Strings.len(argCode) + 3));
        int slashPos = 0;
        switch (argCode) {
            case "IPI":
                if ((MdaUtils.compareTo(argMT, "103") == 0 && MdaUtils.compareTo(argTag, "70") == 0)) {
                    if (Strings.len(text) > 20) {
                        error = true;
                        errTxt.value = Strings.getText("", argCode);
                    }
                }
                break;
            case "RFB":
                if ((MdaUtils.compareTo(argMT, "103") == 0 && MdaUtils.compareTo(argTag, "70") == 0)) {
                    if (Strings.len(text) > 16) {
                        error = true;//CT000102
                        errTxt.value = Strings.getText("", argCode);
                    }
                }
                break;
            case "TSU":
                if ((MdaUtils.compareTo(argMT, "103") == 0 && MdaUtils.compareTo(argTag, "70") == 0) || (MdaUtils.compareTo(argMT, "202") == 0 && MdaUtils.compareTo(argTag, "72") == 0)) {
                    if (Strings.pos(text, "/") == 0) {
                        error = true;//CT000103
                        errTxt.value = Strings.getText("", argCode);
                    }
                }
                break;
            case "7":
            case "11":
            case "12":
            case "19":
            case "38":
            case "40":
            case "41":
            case "42":
            case "43":
            case "48":
            case "49":
            case "50":
            case "51":
                if (MdaUtils.compareTo(Strings.mid(argMT, 2, 2), "95") == 0 && MdaUtils.compareTo(argTag, "75") == 0) {
                    if (MdaUtils.isEmpty(text)) {
                        error = true;
                        errTxt.value = Strings.getText("", argCode);//CT000104
                    }
                }
                break;
            case "13":
            case "17":
            case "20":
            case "22":
            case "44":
            case "45":
                if (MdaUtils.compareTo(Strings.mid(argMT, 2, 2), "95") == 0 && MdaUtils.compareTo(argTag, "75") == 0) {
                    if (MdaUtils.isEmpty(text)) {
                        error = true;
                        errTxt.value = Strings.getText("", argCode);//CT000105
                    } else {
                        slashPos = Strings.pos(text, "/");
                        if (slashPos == 0) {
                            error = true;
                            errTxt.value = Strings.getText("", argCode);//CT000107
                        } else {
                            if (slashPos == 1) {
                                error = true;
                                errTxt.value = Strings.getText("", argCode);//CT000108
                            } else {
                                if (MdaUtils.isEmpty(Strings.mid(text, slashPos + 1))) {
                                    error = true;
                                    errTxt.value = Strings.getText("", argCode);//CT000109
                                }
                            }
                        }
                    }
                }
                break;
            case "23":
            case "24":
            case "25":
            case "26":
            case "27":
            case "28":
            case "29":
                if (MdaUtils.compareTo(argMT, "295") == 0 && MdaUtils.compareTo(argTag, "75") == 0) {
                    if (MdaUtils.isEmpty(text)) {
                        error = true;
                        errTxt.value = Strings.getText("", argCode);//CT000106
                    }
                }
                break;
        }
        return error;
    }
}
