package com.brilliance.isc.common.transaction.check;

import com.brilliance.isc.bo.Bch;
import com.brilliance.isc.common.codetable.service.CodetableService;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.liaccv.vo.LiaccvVo;
import com.brilliance.isc.common.util.I18nUtil;
import com.brilliance.isc.mda.dao.PublicMapper;
import com.brilliance.mda.runtime.mda.impl.Argument;
import com.brilliance.mda.runtime.mda.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

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

/**
 * @author huangmengyuan
 */
@Component
public class LiaccvCheck implements ICheck<LiaccvVo> {

    @Resource
    PublicMapper publicMapper;

    @Autowired
    private CodetableService codetableService;

    @Override
    public Map<String, String> check(LiaccvVo vo) {
        Map<String, String> map = new HashMap<>();
        map.putAll(checkTizamtN1000(vo));
        map.putAll(checkLxzyzhN1000(vo));
        map.putAll(checkKehuzhN1000(vo));
        map.putAll(checkYewudhN1000(vo));
        map.putAll(checkQicujeN1000(vo));
        map.putAll(checkZhruzhN1000(vo));
        map.putAll(checkZhqtypN1000(vo));

        map.putAll(checkRelcshpctN1000(vo));
        return map;
    }

    /**
     * source:dnfmod.0012.script
     */
//    @Check(target="tizamt",order=1000)
    public Map<String, String> checkTizamtN1000(LiaccvVo vo) {
        Map<String, String> resultMap = new HashMap<>();
        //!提支金额校验
        BigDecimal tizMax = null;
        if (MdaUtils.compareTo(vo.getDnfmodVo().getZhqtyp(), "B") == 0) {
            if (MdaUtils.isEmpty(vo.getDnfmodVo().getTizamt())) {
                resultMap.put("liaall.liaccv.dnfmod.tizamt", I18nUtil.getMessage("0002"));
            } else {
                //与余额的校验
                tizMax = Decimals.sub(vo.getDnfmodVo().getZhhuye(), vo.getDnfmodVo().getQicuje());
                if (MdaUtils.compareTo(vo.getDnfmodVo().getTizamt(), tizMax) > 0) {
                    resultMap.put("liaall.liaccv.dnfmod.tizamt", I18nUtil.getMessage("0057"));
                }
            }
        }
        return resultMap;
    }

    /**
     * source:dnfmod.0015.script
     */
//    @Check(target="lxzyzh",order=1000)
    public Map<String, String> checkLxzyzhN1000(LiaccvVo vo) {
        Map<String, String> resultMap = new HashMap<>();
        //!利息转入账号的校验
        String yy = NULLSTR;
        String mm = NULLSTR;
        String dd = NULLSTR;
        Date dqxrq = null;
        String err = NULLSTR;
        if (!MdaUtils.isEmpty(vo.getDnfmodVo().getZhqtyp())) {
            if (MdaUtils.isEmpty(vo.getDnfmodVo().getLxzyzh())) {
                if (!MdaUtils.isEmpty(vo.getDnfmodVo().getQixirq())) {
                    yy = Strings.mid(vo.getDnfmodVo().getQixirq(), 1, 4);
                    mm = Strings.mid(vo.getDnfmodVo().getQixirq(), 5, 2);
                    dd = Strings.mid(vo.getDnfmodVo().getQixirq(), 7, 2);
                    dqxrq = Strings.parseDate(yy + "-" + mm + "-" + dd);
                    if (Dates.diff(dqxrq, Dates.today()) < 0) {
                        resultMap.put("liaall.liaccv.dnfmod.lxzyzh", I18nUtil.getMessage("0002"));
                    }
                }
            } else {
                if (MdaUtils.compareTo(vo.getDnfmodVo().getIntdsp(), "LO") == 0) {
                    if (MdaUtils.compareTo(Strings.mid(vo.getDnfmodVo().getLxzyzh(), 1, 2), "FT") != 0
                            && MdaUtils.compareTo(Strings.mid(vo.getDnfmodVo().getLxzyzh(), 1, 2), "EF") != 0
                            && MdaUtils.compareTo(Strings.mid(vo.getDnfmodVo().getLxzyzh(), 1, 3), "ZMQ") != 0) {
                        if (!chkActMac(vo.getDnfmodVo().getLxzyzh())) {
                            resultMap.put("liaall.liaccv.dnfmod.lxzyzh", I18nUtil.getMessage("0058"));
                        }
                    }
                } else {
                    Argument<String> errBox = new Argument<>();
                    Bch bch = SettleContext.getUserSession().getBch();
                    if (!checkAccount(vo.getDnfmodVo().getLxzyzh(), vo.getDnfmodVo().getIntdsp(), bch.getBranch(), vo.getDnfmodVo().getCur(), "N", errBox)) {
                        resultMap.put("liaall.liaccv.dnfmod.lxzyzh", errBox.value);
                    }
                }
            }
        }
        return resultMap;
    }

    /**
     * source:dnfmod.0041.script
     */
//    @Check(target="kehuzh",order=1000)
    public Map<String, String> checkKehuzhN1000(LiaccvVo vo) {
        Map<String, String> resultMap = new HashMap<>();
        //!检查账户是否为已经销户
        if (MdaUtils.compareTo(vo.getDnfmodVo().getCcvtyp(), "C") == 0) {
            if (MdaUtils.compareTo(vo.getDnfmodVo().getJiluzt(), "1") == 0) {
//                resultMap.put("liaall.liaccv.dnfmod.kehuzh", "当前" + vo.getDnfmodVo().getKehuzh() + "账号已经在核心销户，国结不允许进行操作！  ");
                resultMap.put("liaall.liaccv.dnfmod.kehuzh", I18nUtil.getMessage("0033", vo.getDnfmodVo().getKehuzh()));
            }
        }
        /*
         if not IsEmpty( KEHUZH ) then
         if Mid( GetFramename, 4, 3 ) == "ENC" then
         $OBJTYP = RecGetObj( \\MTABUT\\REC )
         $OBJINR = RecGetInr( \\MTABUT\\REC )
         $Sql = "Where OBJTYP = '" + $OBJTYP + "'  and objinr <> '" + $OBJINR+ "' AND CBC = 'CCVSUM' and enddat= to_date('2299-12-31','YYYY-MM-DD') and amt = 0 ORDER BY EXTID ASC, BEGDAT DESC, INR DESC "
         $COUNT = 0
         DBExecuteSQL( $Sql )
         if ErrorCode == 0 then
         DBFetchFields( "", $COUNT )
         $Ignore = ErrorCode
         endif
         DBCloseCursor
         endif
         endi**/


        return resultMap;
    }

    /**
     * source:dnfmod.0029.script
     */
//    @Check(target="yewudh",order=1000)
    public Map<String, String> checkYewudhN1000(LiaccvVo vo) {
        Map<String, String> resultMap = new HashMap<>();
//        resultMap.put("liaall.liaccv.dnfmod.yewudh", I18nUtil.getMessage("0001"));
        //!检查业务代号
        /*
         if Mid( KEHUZH, 1, 3 ) == "ZMQ" then
         $RFLG = Mid( KEHUZH, 10, 2 )
         else
         $RFLG = Mid( KEHUZH, 7, 2 )
         endif
         */
        String rflg = "";
        if (Strings.len(vo.getDnfmodVo().getKehuzh()) == 17) {
            rflg = Strings.mid(vo.getDnfmodVo().getKehuzh(), 7, 2);
        }
        if (Strings.len(vo.getDnfmodVo().getKehuzh()) == 21) {
            rflg = Strings.mid(vo.getDnfmodVo().getKehuzh(), 11, 2);
        }
        if (MdaUtils.compareTo(Strings.mid(vo.getDnfmodVo().getKehuzh(), 1, 3), "ZMQ") == 0 || MdaUtils.compareTo(Strings.mid(vo.getDnfmodVo().getKehuzh(), 1, 3), "NRA") == 0) {
            rflg = Strings.mid(vo.getDnfmodVo().getKehuzh(), 10, 2);
        }
        if (MdaUtils.compareTo(rflg, "81") == 0) {
            if (!MdaUtils.isEmpty(vo.getDnfmodVo().getYewudh())) {
                if (MdaUtils.compareTo(SettleContext.getTransName(), "GITENG") == 0 && !MdaUtils.isEmpty(vo.getDnfmodVo().getZhqtyp())) {
                    if (MdaUtils.compareTo(vo.getDnfmodVo().getYewudh(), "0436") != 0) {
//                        resultMap.put("liaall.liaccv.dnfmod.yewudh", "非担保定期保证金业务代号，不支持此操作，请重新选择账号！");
                        resultMap.put("liaall.liaccv.dnfmod.yewudh", I18nUtil.getMessage("0001"));
                    }
                }
                if ((MdaUtils.compareTo(SettleContext.getTransName(), "LITENG") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "DITENG") == 0) && !MdaUtils.isEmpty(vo.getDnfmodVo().getZhqtyp())) {
                    if (MdaUtils.compareTo(vo.getDnfmodVo().getYewudh(), "0432") != 0) {
//                        resultMap.put("liaall.liaccv.dnfmod.yewudh", "非信用证定期保证金业务代号，不支持此操作，请重新选择账号！");
                        resultMap.put("liaall.liaccv.dnfmod.yewudh", I18nUtil.getMessage("0059"));

                    }
                }
            }
        }
        return resultMap;
    }

    /**
     * source:dnfmod.0025.script
     */
//    @Check(target="qicuje",order=1000)
    public Map<String, String> checkQicujeN1000(LiaccvVo vo) {
        Map<String, String> resultMap = new HashMap<>();

        //!当业务选择部分提支的时候起存金额必输
        if (MdaUtils.compareTo(vo.getDnfmodVo().getZhqtyp(), "B") == 0) {
            if (MdaUtils.isEmpty(vo.getDnfmodVo().getQicuje())) {
                resultMap.put("liaall.liaccv.dnfmod.yewudh", I18nUtil.getMessage("0034"));
            }
        }
        return resultMap;
    }

    /**
     * source:dnfmod.0013.script
     */
//    @Check(target="zhruzh",order=1000)
    public Map<String, String> checkZhruzhN1000(LiaccvVo vo) {
        Map<String, String> resultMap = new HashMap<>();

        //!操作类型选择部分提支时，注入活期账户必输
        String err = NULLSTR;
        if (!MdaUtils.isEmpty(vo.getDnfmodVo().getZhqtyp())) {
            if (MdaUtils.isEmpty(vo.getDnfmodVo().getZhruzh())) {
                resultMap.put("liaall.liaccv.dnfmod.zhruzh", I18nUtil.getMessage("0002"));
            } else {
                Argument<String> errBox = new Argument<>();
                Bch bch = SettleContext.getUserSession().getBch();
                if (!checkAccount(vo.getDnfmodVo().getZhruzh(), vo.getDnfmodVo().getPridsp(), bch.getBranch(), vo.getDnfmodVo().getCur(), "N", errBox)) {
                    resultMap.put("liaall.liaccv.dnfmod.zhruzh", errBox.value);
                }
            }
        }
        return resultMap;
    }

    /**
     * source:dnfmod.0016.script
     */
//    @Check(target="zhqtyp",order=1000)
    public Map<String, String> checkZhqtypN1000(LiaccvVo vo){
        Map<String, String> resultMap = new HashMap<>();

        //!检查账户是否办理部分提支业务
        if( MdaUtils.compareTo(vo.getDnfmodVo().getCcvtyp(),"C") == 0 )
        {
            if( MdaUtils.isEmpty(vo.getDnfmodVo().getZhqtyp()) )
            {
                resultMap.put("liaall.liaccv.dnfmod.zhqtyp", I18nUtil.getMessage("0002"));
            }
            else
            {
                if( MdaUtils.compareTo(vo.getDnfmodVo().getZhqtyp(),"B") == 0 && MdaUtils.compareTo(vo.getDnfmodVo().getZhqucs(),"0") != 0 )
                {
                    resultMap.put("liaall.liaccv.dnfmod.zhqtyp", I18nUtil.getMessage("0035"));
                    vo.getDnfmodVo().setZhqtyp("");
                }
            }
        }
        return resultMap;
    }

    /**
     * source:actmod.0017.script
     */
    public boolean chkActMac(String account) {
        //----------------------------
        //现有账号校验均不合法，屏蔽
        //= TRUE
        //----------------------------
        String e0 = "000000000000000000000";
        String fullAct = Strings.mid(e0, 1, 21 - Strings.len(account)) + account;
        int ss = 0;
        String switchVar = NULLSTR;
        int k = 0;
        String j = NULLSTR;
        int factor = 0;
        for (int i = 1; i <= 19; i++) {
            switchVar = Strings.mid(fullAct, i, 1);
            switch (switchVar) {
                case "0":
                    k = 0;
                    break;
                case "1":
                    k = 1;
                    break;
                case "2":
                    k = 2;
                    break;
                case "3":
                    k = 3;
                    break;
                case "4":
                    k = 4;
                    break;
                case "5":
                    k = 5;
                    break;
                case "6":
                    k = 6;
                    break;
                case "7":
                    k = 7;
                    break;
                case "8":
                    k = 8;
                    break;
                case "9":
                    k = 9;
                    break;
            }
            j = MdaUtils.toString(i);
            switch (j) {
                case "1":
                    factor = 1;
                    break;
                case "2":
                    factor = 3;
                    break;
                case "3":
                    factor = 5;
                    break;
                case "4":
                    factor = 7;
                    break;
                case "5":
                    factor = 11;
                    break;
                case "6":
                    factor = 13;
                    break;
                case "7":
                    factor = 17;
                    break;
                case "8":
                    factor = 19;
                    break;
                case "9":
                    factor = 23;
                    break;
                case "10":
                    factor = 29;
                    break;
                case "11":
                    factor = 31;
                    break;
                case "12":
                    factor = 37;
                    break;
                case "13":
                    factor = 53;
                    break;
                case "14":
                    factor = 61;
                    break;
                case "15":
                    factor = 67;
                    break;
                case "16":
                    factor = 89;
                    break;
                case "17":
                    factor = 91;
                    break;
                case "18":
                    factor = 73;
                    break;
                case "19":
                    factor = 79;
                    break;
            }
            ss = factor * k + ss;
        }
        int a = Numerics.floor(Decimals.div(ss, 97));
        int returnVar = ss - a * 97;
        String result = NULLSTR;
        if (returnVar - 10 >= 0) {
            result = MdaUtils.toString(returnVar);
        } else {
            result = "0" + MdaUtils.toString(returnVar);
        }
        return MdaUtils.compareTo(result, Strings.mid(fullAct, 20, 2)) == 0;

    }

    /**
     * source:actmod.0016.script
     */
    public boolean checkAccount(String account, String term_id, String branch, String cur, String manFLG, Argument<String> err) {
        String transName = SettleContext.getDirectTransName();
        //---------------------------------------------
        //   新一代账号检核函数
        //   返回：True    正确
        //         False   错误   Err  错误原因
        //   参数：Account 账号
        //         Term_id 科目代码
        //         CUR     记账币别
        //         Branch  机构
        //         ManFlg  手工输入帐码（M）
        //---------------------------------------------
        int length = Strings.len(account);
        //#DG 20101227 新需求，新账号前面增加"NRA"
        /*
         if $length == 20 and Mid( Account, 1, 3 ) == "NRA" then
         */
        //------ZMQZMQ---------------------------------------
        //---自贸区主账号处理--
        String notyp = NULLSTR;
        String repflg = NULLSTR;
        String vterm_id = NULLSTR;
        String term_nam = NULLSTR;
        String seqNo = NULLSTR;
        String prtTyp = NULLSTR;
        String nam = NULLSTR;
        String vcur = NULLSTR;
        if (MdaUtils.compareTo(Strings.mid(account, 1, 2), "FT") == 0 || MdaUtils.compareTo(Strings.mid(account, 1, 2), "EF") == 0 || MdaUtils.compareTo(Strings.mid(account, 1, 3), "ZMQ") == 0) {
            if (MdaUtils.compareTo(Strings.mid(account, 1, 2), "FT") == 0 || MdaUtils.compareTo(Strings.mid(account, 1, 2), "EF") == 0) {
                return true;
            } else {
                //------ZMQZMQ---------------------------------------
                return checkZMQAccount(Strings.mid(account, 4), term_id, branch, cur, manFLG, err);
            }
        } else {
            if (length == 20 && MdaUtils.compareTo(Strings.mid(account, 1, 3), "NRA") == 0) {
                return checkAccount(Strings.mid(account, 4, 17), term_id, branch, cur, manFLG, err);
            } else {
                if (length != 17 && length != 21) {
                    err.value = "账号位数错误";
                    return false;
                }
                /*
                 //505新需求
                 //同一客户下不能维护相同的账号
                 $ptyinr = GetContent( "\\\\recpan\\\\actgrp\\\\holpty\\\\inr" )
                 $error = ErrorCode
                 if not IsEmpty( $ptyinr ) then
                 $actsql = "select count(*) from act where extkey = '" + Account + "' and  holptyinr = '" + $ptyinr + "'"
                 $cnt = 0
                 DBExecuteSQL( $actsql )
                 DBFetchFields( "", $cnt )
                 DBCloseCursor
                 if $cnt > 0 then
                 Err = "该客户已经存在此账号,不能添加!           "
                 = FALSE
                 endif
                 endif
                 */
                //---------------------------------------------
                //if IsEmpty( term_id )  then
                if (MdaUtils.isEmpty(term_id) && (MdaUtils.compareTo(transName, "BRTSET") != 0 && MdaUtils.compareTo(transName, "GITSET") != 0 && MdaUtils.compareTo(transName, "MCTFEE") != 0)) {
                    err.value = "科目代码为空";
                    return false;
                }
                Argument<String> notypBox = new Argument<String>();
                Argument<String> repflgBox = new Argument<String>();
                Argument<String> vterm_idBox = new Argument<String>();
                Argument<String> term_namBox = new Argument<String>();
                Argument<String> seqNoBox = new Argument<String>();
                Argument<String> prtTypBox = new Argument<String>();
                Argument<String> namBox = new Argument<String>();
                getActTypField(term_id, notypBox, repflgBox, vterm_idBox, term_namBox, seqNoBox, prtTypBox, namBox);

                notyp = notypBox.value;
                repflg = repflgBox.value;
                vterm_id = vterm_idBox.value;
                term_nam = term_namBox.value;
                seqNo = seqNoBox.value;
                prtTyp = prtTypBox.value;
                nam = namBox.value;

                /*
                 if $notyp == "O" then // 旧帐号的检核
                 goto CheckOldAccount
                 else
                 if $notyp == "N" then // 新账号的检核
                 goto CheckNewAccount
                 else  // 根据位数判断新旧帐号
                 */
                boolean gotoNewAccount = Objects.equals(notyp, "N");
                // goto CheckOldAccount
                //  goto CheckNewAccount
                /*
                 endif
                 endif
                 */
                //  label CheckNewAccount
                if (gotoNewAccount) {
                    if (length == 21) {
                        err.value = "科目：" + vterm_id + " 为新帐号类型，长度必须为17位          ";
                        return false;
                    }
                    /*
                     $term_act = "0" + Mid( Account, 7, 4 )
                     if $repflg <> "C" or Mid( term_id, 1, 2 ) == "AS" then // 不是客户帐
                     if ManFLG == "M" and $term_act <> $term_id and ( GetFramename <> "BRTSET" and GetFramename <> "GITSET" and GetFramename <> "MCTFEE" ) then
                     Err = "账号的对应位 " + $term_act + " 与科目 " + $term_id + " 不符          "
                     = FALSE
                     endif
                     endif
                     */
                    if (MdaUtils.compareTo(repflg, "R") == 0 && !MdaUtils.isEmpty(branch) && MdaUtils.compareTo(getBranch(branch), Strings.mid(account, 1, 4)) != 0) {
                        err.value = "账号中的机构位(1-4)与记账机构 " + branch + " 不符          ";
                        return false;
                    }
                    vcur = Strings.mid(account, 5, 2);
                    // goto checkEnd
                }
                // label CheckOldAccount
                if (!gotoNewAccount) {
                    if (length == 17) {
                        err.value = "科目：" + vterm_id + " 为旧帐号类型，长度必须为21位          ";
                        return false;
                    }
                    /*
                     $term_act = Mid( Account, 11, 5 )
                     //if ManFLG = "M" and $term_act <> $term_id then
                     if ManFLG == "M" and $term_act <> $term_id and ( GetFramename <> "BRTSET" and GetFramename <> "GITSET" and GetFramename <> "MCTFEE" ) then
                     Err = "账号的对应位 " + $term_act + " 与科目 " + $term_id + " 不符        "
                     = FALSE
                     endif
                     */
                    if (MdaUtils.compareTo(repflg, "R") == 0 && !MdaUtils.isEmpty(branch) && MdaUtils.compareTo(branch, Strings.mid(account, 1, 8)) != 0) {
                        err.value = "账号中的机构位(1-8)与记账机构 " + branch + " 不符     ";
                        return false;
                    }
                    vcur = Strings.mid(account, 9, 2);
                    // goto checkEnd
                }
                //label checkEnd
                //检查账号的币别位
                if (!MdaUtils.isEmpty(cur)) {
                    if (MdaUtils.compareTo(vcur,
                            Strings.mid(codetableService.getTblLabel(cur, "CURKEY"), 1, 2)) != 0) {
                        err.value = "记账币种 " + cur + " 与账号币种不符       ";
                        return false;
                    }
                }
                //检查客户帐的校验位
                if (MdaUtils.compareTo(repflg, "C") == 0 && MdaUtils.compareTo(Strings.mid(term_id, 1, 2), "AS") != 0) {
                    if (!chkActMac(account)) {
                        err.value = "客户帐号合法性校验错误          ";
                        //    Err = "MAC[" + GetActMac( Account ) + "]," + Err
                        return false;
                    }
                }
                return true;
            }
        }

    }

    /**
     * source:actmod.0024.script
     */
    public boolean checkZMQAccount(String account, String term_id, String branch, String cur, String manFLG, Argument<String> err) {
        String transName = SettleContext.getDirectTransName();
        //---------------------------------------------
        //   新一代账号检核函数
        //   返回：True    正确
        //         False   错误   Err  错误原因
        //   参数：Account 账号
        //         Term_id 科目代码
        //         CUR     记账币别
        //         Branch  机构
        //         ManFlg  手工输入帐码（M）
        //---------------------------------------------
        int length = Strings.len(account);
        //------ZMQZMQ---------------------------------------
        if (length != 17 && length != 21) {
            err.value = "账号位数错误";
            return false;
        }
        String vcur = Strings.mid(account, 5, 2);
        // return ; //   ####   goto checkEnd
        //    ####    label checkEnd
        if (MdaUtils.isEmpty(term_id) && (MdaUtils.compareTo(transName, "BRTSET") != 0 && MdaUtils.compareTo(transName, "GITSET") != 0 && MdaUtils.compareTo(transName, "MCTFEE") != 0)) {
            err.value = "科目代码为空";
            return false;
        }
        /*
         if not IsEmpty( branch ) and GetBranch( branch ) <> Mid( Account, 1, 4 ) then
         Err = "账号中的机构位(1-4)与记账机构 " + branch + " 不符          "
         = FALSE
         endif
         */
        //检查账号的币别位
        if (!MdaUtils.isEmpty(cur)) {
            if (MdaUtils.compareTo(vcur, Strings.mid(codetableService.getTblLabel(cur, "CURKEY"), 1, 2)) != 0) {
                err.value = "记账币种 " + cur + " 与账号币种不符       ";
                return false;
            }
        }
        String vbranch = Strings.mid(account, 1, 4);
        Map<String, Object> sqlMap = new HashMap<>();
        sqlMap.put("sql", " select count(*) from sysbch where YNGYJG='" + vbranch + "'");
        int count = publicMapper.dyncCount(sqlMap);
        if (MdaUtils.compareTo(count, "0") == 0) {
            err.value = "机构不存在             ";
            return false;
        }
        /*
         //检查客户帐的校验位
         if not ChkZMQActMac( Account ) then
         Err = "客户帐号合法性校验错误          "
         = FALSE
         endif
         */
        return true;

    }

    /**
     * source:actmod.0011.script
     */
    public void getActTypField(String tbltyp, Argument<String> nottyp, Argument<String> repTyp, Argument<String> term_id, Argument<String> term_nam, Argument<String> seqNo, Argument<String> prttyp, Argument<String> nam) {
        //-------------------------------------------
        //    获取账户信息的函数
        //    TBLTYP  CodeTable ACTMIX 的TBL
        //    NOTTYP  返回新旧帐号类型   N 新帐号 O旧帐号 M 新旧帐号并存
        //    RepTyp  账号中机构位的生成规则  R  用当前机构替换  G  使用EXTACT中的机构    C 客户类账号
        //    term_id  科目代码   账号中的科目号位  5位  新帐号需要去掉前1位   08开头的仅仅取头3位
        //    term_nam 科目号     账号对应的科目号，打印传票时使用
        //    SEQNo   顺序号
        //    PRTTYP  传票打印类型
        //    NAM     该科目的名称
        //-------------------------------------------
        nottyp.value = "";
        repTyp.value = "";
        term_id.value = "";
        seqNo.value = "";
        prttyp.value = "";
        nam.value = "";
        String txt = codetableService.getTblLabel(tbltyp, "ACTMIX");
        if (!MdaUtils.isEmpty(txt)) {
            nottyp.value = Strings.mid(txt, 1, 1);
            repTyp.value = Strings.mid(txt, 2, 1);
            term_id.value = Strings.mid(txt, 4, 5);
            term_nam.value = Strings.mid(txt, 10, 6);
            seqNo.value = Strings.mid(txt, 17, 1);
            prttyp.value = Strings.mid(txt, 19, 2);
            nam.value = Strings.mid(txt, 22, -1);
        }

    }

    /**
     * source:actmod.0010.script
     */
    public String getBranch(String branch) {
        //-----获取核心的记账机构代码－－－－－－－－－－－－－
        return Strings.mid(codetableService.getTblLabel(branch, "ACCBCH"), 1, 4);
    }

    //    @Check(target = "relcshpct", order = 1000)
    public Map<String, String> checkRelcshpctN1000(LiaccvVo liaccv) {
        Map<String, String> map = new HashMap<>();
        String transName = SettleContext.getTransName();
        BigDecimal maxamt;
        switch (transName) {
            case "LITOPN":
            case "LITAME":
            case "LITENG":
            case "LITROP":
            case "BRTSET":
            case "GITOPN":
            case "GITAME":
            case "GITROP":
            case "GITENG":
            case "GITSET":
            case "LITDLA":
            case "BRTLAT":
            case "LITROG":
            case "BRTUDP":
            case "DITOPN":
            case "DITAME":
            case "DITENG":
            case "BDTSET":
            case "BDTUDP":
            case "DITDLA":
            case "DITODZ":
                /*
                 //---ysp---
                 case "LITOPN", "LITAME", "LITENG", "LITROP", "BRTSET", "GITOPN", "GITAME", "GITROP", "GITENG", "GITSET", "LITDLA", "BRTLAT", "LITROG", "BRTUDP", "DITOPN", "DITAME", "DITENG", "BDTSET", "BDTUDP", "DITDLA"
                 */
                if (!MdaUtils.isEmpty(liaccv.getRelcshpct())) {
                    if (MdaUtils.compareTo(liaccv.getRelcshpct(), liaccv.getCshpct()) < 0)
                        map.put("liaccv.relcshpct", I18nUtil.getMessage("0036"));

                } else {
                    maxamt = Decimals.add(liaccv.getOldamt(), liaccv.getChgamt());
                    if (MdaUtils.compareTo(maxamt, 0) > 0) {
                        if (MdaUtils.compareTo(liaccv.getRelcshpct(), liaccv.getCshpct()) < 0)
                            map.put("liaccv.relcshpct", I18nUtil.getMessage("0036"));
                    }
                }
                break;
        }
        return map;
    }

}
