package com.brilliance.isc.common.transaction.newcheck.setmod;

import com.brilliance.isc.bo.Fec;
import com.brilliance.isc.bo.Fee;
import com.brilliance.isc.bo.Fep;
import com.brilliance.isc.bo.Oit;
import com.brilliance.isc.common.cbsmod.CbsRange;
import com.brilliance.isc.common.cbsmod.service.XrtmodService;
import com.brilliance.isc.common.codetable.service.CodetableService;
import com.brilliance.isc.common.fecism.service.FecismService;
import com.brilliance.isc.common.oit.service.OitService;
import com.brilliance.isc.common.setfeg.service.SetfelService;
import com.brilliance.isc.common.setfeg.vo.SetfelVo;
import com.brilliance.isc.common.setmod.vo.SetmodVo;
import com.brilliance.isc.common.transaction.newcheck.*;
import com.brilliance.isc.common.util.I18nUtil;
import com.brilliance.isc.common.util.StringUtils;
import com.brilliance.isc.common.util.Utils;
import com.brilliance.isc.common.vo.FecVo;
import com.brilliance.isc.mda.dao.FeeMapper;
import com.brilliance.isc.mda.dao.FepMapper;
import com.brilliance.mda.runtime.mda.impl.Argument;
import com.brilliance.mda.runtime.mda.util.Dates;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.mda.util.Streams;
import com.brilliance.mda.runtime.mda.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

@Component
public class SetfelValidator extends AbstractModuleValidator<SetfelVo> {

    private static Logger log = LoggerFactory.getLogger(SetfelValidator.class);
    public static final String CR = "\n";

    @Autowired
    private CodetableService codetableService;

    @Autowired
    private XrtmodService xrtmodService;

    @Autowired
    private FecismService fecismService;

    @Autowired
    private SetfelService setfelService;

    @Autowired
    private CbsRange cbsRange;

    @Autowired
    private FeeMapper feeMapper;

    @Autowired
    private FepMapper fepMapper;

    @Autowired(required = false)
    private OitService oitService;

    @Validate(path = "setmod.setfeg.setfel.%s.amt")
    public ValidResult checkAmt(SetfelVo setfelVo) {
        if(setfelVo.getAmt().compareTo(BigDecimal.ZERO) == 0) {
            if("AM".equals(setfelVo.getWrkfec().getSetchgflg())
                    || "BM".equals(setfelVo.getWrkfec().getSetchgflg())) {
                return ValidResult.build(false, I18nUtil.getMessage("0002"));
            }
        }
        SetmodVo setmodVo = (SetmodVo)getParent();
        boolean posFnd = false;
        if(MdaUtils.compareTo(setfelVo.getAmt(),0) < 0) {
            for(int i = 0; i < setmodVo.getSetfeg().getSetfel().size(); i++) {
                SetfelVo tmpSetfelVo = setmodVo.getSetfeg().getSetfel().get(i);
                if( MdaUtils.compareTo(tmpSetfelVo.getAmt(),0)>0 && (MdaUtils.compareTo(tmpSetfelVo.getDsp(),"X") == 0 || MdaUtils.compareTo(tmpSetfelVo.getDsp(), "S")== 0) && MdaUtils.compareTo(setfelVo.getRol(), tmpSetfelVo.getRol()) == 0) {
                    posFnd = true;
                }
            }
            if(posFnd) {
                return ValidResult.build(false, Strings.formatText("Either charge or refund, no mixes are allowed.\nPlease make sure to settle or advise either only and store other fees in pool for role $1.", setfelVo.getRol()));
            }
        }
        if( MdaUtils.compareTo(setfelVo.getAmt(), 0) != 0 && MdaUtils.isEmpty(setfelVo.getFeecod()) ) {
            return ValidResult.build(false, "Please enter a fee code for this amount.");
        }
        return null;
    }

    /**
     *   source:setfel.0010.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.feecod")
    public ValidResult checkFeecod(SetfelVo setfelVo){
        if(setfelVo.getErrcod() > 0) {
            String errtxt = MdaUtils.toString(setfelVo.getErrcod()) + "  " + setfelVo.getErrtxt();
            return ValidResult.build(false, Strings.formatText("Couldn\'t process fee $1 / Error : $2", setfelVo.getFeecod(), errtxt));
        }
        return null;
    }

    @Validate(path = "setmod.setfeg.setfel.%s.feecod")
    public ValidResult checkFeecodForOit(SetfelVo setfelVo){
        FecVo fecVo = setfelVo.getWrkfec();
        if (fecVo != null && StringUtils.isNotEmpty(fecVo.getInr())) {
            Map<String, List<Oit>> maps = oitService.filterOit(fecVo.getInr(), "FEC");
            if (maps != null && maps.containsKey("ERROR")) {
                List<Oit> errorOits = maps.get("ERROR");
                String message = getMessage("0217", null);
                for (int i=0; i<errorOits.size(); i++) {
                    if (i == 0) {
                        message += errorOits.get(i).getInftxt();
                    } else {
                        message += "\r\n" + errorOits.get(i).getInftxt();
                    }
                }
                return ValidResult.build(false, message);
            }
        }
        return null;
    }

    @Warning(path = "setmod.setfeg.setfel.%s.feecod")
    public WarningResult warningFeecodForOit(SetfelVo setfelVo) {
        FecVo fecVo = setfelVo.getWrkfec();
        if (fecVo != null && StringUtils.isNotEmpty(fecVo.getInr())) {
            Map<String, List<Oit>> maps = oitService.filterOit(fecVo.getInr(), "FEC");
            if (maps != null && !maps.containsKey("ERROR") && maps.containsKey("WARN")) {
                List<Oit> warnOits = maps.get("WARN");
                String title = getMessage("0221", setfelVo.getFeecod());
                String message = getMessage("0218", title);
                for (int i=0; i<warnOits.size(); i++) {
                    if (i == 0) {
                        message += warnOits.get(i).getInftxt();
                    } else {
                        message += "\r\n" + warnOits.get(i).getInftxt();
                    }
                }
                return WarningResult.build("SetfelFeecodWarning", message);
            }
        }
        return WarningResult.buildEmpty("SetfelFeecodWarning");
    }

    @Warning(path = "setmod.setfeg.setfel.%s.feecod", level = "3")
    public WarningResult infoFeecodForOit(SetfelVo setfelVo) {
        FecVo fecVo = setfelVo.getWrkfec();
        if (fecVo != null && StringUtils.isNotEmpty(fecVo.getInr())) {
            Map<String, List<Oit>> maps = oitService.filterOit(fecVo.getInr(), "FEC");
            if (maps != null && !maps.containsKey("ERROR") && maps.containsKey("INFO")) {
                List<Oit> warnOits = maps.get("INFO");
                String title = getMessage("0221", setfelVo.getFeecod());
                String message = getMessage("0219", title);
                for (int i=0; i<warnOits.size(); i++) {
                    if (i == 0) {
                        message += warnOits.get(i).getInftxt();
                    } else {
                        message += "\r\n" + warnOits.get(i).getInftxt();
                    }
                }
                return WarningResult.build("SetfelFeecodInfo", message);
            }
        }
        return WarningResult.buildEmpty("SetfelFeecodInfo");
    }


    /**
     *   source:setfel.0011.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.rol")
    public ValidResult checkRol(SetfelVo setfelVo){
        //! this function checks, if the role the user selected is still available.
        //! This rule should be used for all fields allowing the user to select a role from ROLDSC
        String rol = setfelVo.getRol();
        if(StringUtils.isNotEmpty(rol)) {
            SetmodVo setmodVo = (SetmodVo)getParent();
            int fnd = 0;
            int stmCnt = Streams.streamCount(setmodVo.getRoldsc());
            for(int  i = 1;i <= stmCnt;i++) {
                if( MdaUtils.compareTo(Strings.mid(Strings.getLine(setmodVo.getRoldsc(),i),1,3), rol) == 0 ) {
                    fnd = i;
                }
            }
            if( fnd == 0 ) {
                return ValidResult.build(false, Strings.formatText("角色$1不再可用。请使用可用的当事人再次选择", rol));
            }
        }
        if(StringUtils.isEmpty(rol) && setfelVo.getAmt().compareTo(BigDecimal.ZERO) != 0) {
            return errorMandatory();
        }
        return null;
    }

    /**
     *   source:setfel.0020.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.dat1")
    public ValidResult checkDat1(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getAccacr()) && MdaUtils.isEmpty(setfelVo.getDat1()) && MdaUtils.compareTo(setfelVo.getAmt(),0) != 0 ) {
            return ValidResult.build(false, "This field is mandatory");
        }
        return null;
    }

    /**
     *   source:setfel.0021.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.dat2")
    public ValidResult checkDat2(SetfelVo setfelVo){
        //! Set warning, if minimum used for incomplete period (900671)
        if( Dates.diff(setfelVo.getDat2(), setfelVo.getDat2dft()) < 0 && MdaUtils.compareTo(setfelVo.getAllcalflg(),"T")== 0 ) {
            log.warn("Fee minimum of {} {} used for fee {}, payer {}, but not complete period settled", setfelVo.getCur(), Utils.fmtAmount(setfelVo.getAmt(), setfelVo.getCur()), setfelVo.getFeecod(), setfelVo.getRol());
        }
        //! if amount has been changed in commission calculation and date has not been modified, clear date and ask user to enter date for which entered amount is valid
        if( MdaUtils.compareTo(setfelVo.getWrkfec().getCalrul(),"C")== 0 && setfelVo.isModified("amt") && (!setfelVo.isModified("dat2") || setfelVo.getDat2() == null)) {
            return ValidResult.build(false, "You have changed the amount of calculation.\nPlease enter end date of period paid with this amount manually.\nIf the date is already correct, clear it and retype it after tab out.");
        }
        //! If DAT1 is set, dat2 has to be set to a date not earlier if it is not an in arreas calculation
        if(!MdaUtils.isEmpty(setfelVo.getDat1()) && (Dates.diff(setfelVo.getDat1(), setfelVo.getDat2())>0 && (!MdaUtils.isEmpty(setfelVo.getDat2()) || !"E".equals(setfelVo.getWrkfec().getSettyp())))) {
            return ValidResult.build(false, "结束日期必须晚于开始日期");
        }
        if(!MdaUtils.isEmpty(setfelVo.getAccacr()) && MdaUtils.isEmpty(setfelVo.getDat2()) && MdaUtils.compareTo(setfelVo.getAmt(),0) != 0 ) {
            return ValidResult.build(false, "This field is mandatory");
        }
        return null;
    }

    /**
     *   source:setfel.0038.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.dctamt")
    public ValidResult checkDctamt(SetfelVo setfelVo){
        if( MdaUtils.compareTo(setfelVo.getDctamt(), setfelVo.getOgiamt()) > 0 ) {
            return ValidResult.build(false, Strings.formatText("Discount amount $1 could not more than original fee", setfelVo.getDctamt()));
        }
        return null;
    }

    /**
     *   source:setfel.0040.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.dctrat")
    public ValidResult checkDctrat(SetfelVo setfelVo){
        if( MdaUtils.compareTo(setfelVo.getDctrat(), 100) > 0 ) {
            return ValidResult.build(false, Strings.formatText("Discount rate $1 could not be used!", setfelVo.getDctrat()));
        }
        return null;
    }

    /**
     *   source:fecp1.0000.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.mincur")
    public ValidResult checkFecMincur(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getWrkfec().getMincur()) ) {
            if(!xrtmodService.isCurrencyValid(setfelVo.getWrkfec().getMincur())) {
                return ValidResult.build(false, "The selected currency is invalid");
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0001.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.permaxtr2")
    public ValidResult checkFecPermaxtr2(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getWrkfec().getPermaxtr2()) ) {
            if( MdaUtils.compareTo(setfelVo.getWrkfec().getPermintr2(), setfelVo.getWrkfec().getPermaxtr2())>0 ) {
                return ValidResult.build(false, "Maximum amount cannot be less than the minimum amount.");
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0002.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.permaxtr3")
    public ValidResult checkFecPermaxtr3(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getWrkfec().getPermaxtr3())) {
            if(MdaUtils.compareTo(setfelVo.getWrkfec().getPermintr3(), setfelVo.getWrkfec().getPermaxtr3()) > 0) {
                return ValidResult.build(false, "Maximum amount cannot be less than the minimum amount.");
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0003.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.permaxtr4")
    public ValidResult checkFecPermaxtr4(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getWrkfec().getPermaxtr4()) ) {
            if(MdaUtils.compareTo(setfelVo.getWrkfec().getPermintr4(), setfelVo.getWrkfec().getPermaxtr4()) > 0) {
                return ValidResult.build(false, "Maximum amount cannot be less than the minimum amount.");
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0004.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.permaxtr5")
    public ValidResult checkFecPermaxtr5(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getWrkfec().getPermaxtr5()) ) {
            if( MdaUtils.compareTo(setfelVo.getWrkfec().getPermintr5(), setfelVo.getWrkfec().getPermaxtr5())>0 ) {
                return ValidResult.build(false, "Maximum amount cannot be less than the minimum amount.");
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0005.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.permaxtr6")
    public ValidResult checkFecPermaxtr6(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getWrkfec().getPermaxtr6()) ) {
            if( MdaUtils.compareTo(setfelVo.getWrkfec().getPermintr6(), setfelVo.getWrkfec().getPermaxtr6())>0 ) {
                return ValidResult.build(false, "Maximum amount cannot be less than the minimum amount.");
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0006.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.permaxtr7")
    public ValidResult checkFecPermaxtr7(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getWrkfec().getPermaxtr7()) ) {
            if( MdaUtils.compareTo(setfelVo.getWrkfec().getPermintr7(), setfelVo.getWrkfec().getPermaxtr7()) > 0 ) {
                return ValidResult.build(false, "Maximum amount cannot be less than the minimum amount.");
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0007.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.ratcur")
    public ValidResult checkFecRatcur(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getWrkfec().getRatcur())) {
            if(!xrtmodService.isCurrencyValid(setfelVo.getWrkfec().getRatcur())) {
                return ValidResult.build(false, "The selected currency is invalid");
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0008.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.maxamt")
    public ValidResult checkFecMaxamt(SetfelVo setfelVo){
        if(MdaUtils.compareTo(setfelVo.getWrkfec().getMinfcc(), "S") == 0
                && MdaUtils.compareTo(setfelVo.getWrkfec().getMaxfcc(),"S") == 0) {
            if( ! MdaUtils.isEmpty(setfelVo.getWrkfec().getMaxamt()) ) {
                if (MdaUtils.compareTo(setfelVo.getWrkfec().getMaxcur(), setfelVo.getWrkfec().getMincur()) != 0) {
                    BigDecimal maxamt = BigDecimal.ZERO;
                    Argument<String> inftxtArg = new Argument<>("", "");
                    maxamt = xrtmodService.amtRndUnt(fecismService.fecIsmAmtConv(inftxtArg, setfelVo.getWrkfec().getMaxcur(), setfelVo.getWrkfec().getMaxamt(), setfelVo.getWrkfec().getMincur(), Dates.today()), setfelVo.getWrkfec().getMincur());
                    if (MdaUtils.compareTo(maxamt, setfelVo.getWrkfec().getMinamt()) < 0) {
                        return ValidResult.build(false, "Maximum amount cannot be less than the minimum amount.");
                    }
                }else {
                    if (MdaUtils.compareTo(setfelVo.getWrkfec().getMaxamt(), setfelVo.getWrkfec().getMinamt()) < 0) {
                        return ValidResult.build(false, "Maximum amount cannot be less than the minimum amount.");
                    }
                }
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0009.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.maxcur")
    public ValidResult checkFecMaxcur(SetfelVo setfelVo){
        if(!MdaUtils.isEmpty(setfelVo.getWrkfec().getMaxcur())) {
            if(!xrtmodService.isCurrencyValid(setfelVo.getWrkfec().getMaxcur())) {
                return ValidResult.build(false, "The selected currency is invalid");
            }
        }
        return null;
    }

    /**
     *   source:fecp1.0012.script
     */
    @Validate(path = "setmod.setfeg.setfel.%s.fec.pertyp")
    public ValidResult checkFecPertyp(SetfelVo setfelVo){
        if((MdaUtils.compareTo(setfelVo.getWrkfec().getCalrul(),"1") == 0
                || MdaUtils.compareTo(setfelVo.getWrkfec().getCalrul(),"4") == 0
                || MdaUtils.compareTo(setfelVo.getWrkfec().getCalrul(),"%") == 0)
                && MdaUtils.compareTo(setfelVo.getWrkfec().getRatfcc(),"S") == 0) {
            if( MdaUtils.isEmpty(setfelVo.getWrkfec().getPertyp()) ) {
                return ValidResult.build(false, "You must select a period type for per mille fees");
            }
        }
        return null;
    }

    @Validate(path = "setmod.setfeg.setfel.%s.unt")
    public ValidResult checkUnt(SetfelVo setfelVo) {
        if ("Y".equals(setfelVo.getCommFeeFlag())) {
            if (setfelVo.getDat2dft() != null && setfelVo.getDat2() != null && StringUtils.isNotEmpty(setfelVo.getWrkfec().getPertyp())) {
                Date endDate = Utils.calcDate(setfelVo.getDat2dft(), 1, setfelVo.getWrkfec().getPertyp(), "");
                if (MdaUtils.compareTo(setfelVo.getDat2(), endDate) > 0) {
                    return ValidResult.build(false, "收费区间不允许超过业务效期");
                }
                if (MdaUtils.compareTo(setfelVo.getDat2(), endDate) == 0) {
                    //比较日期
                    int expDays = Dates.getDay(setfelVo.getDat2dft());
                    int days = Dates.getDay(setfelVo.getDat2());
                    if (days >= expDays) {
                        return ValidResult.build(false, "收费区间不允许超过业务效期");
                    }
                }
            }
        }
        return null;
    }

    /**
     *   source:setfel.0024.script
     */
    @Warning(path = "setmod.setfeg.setfel.%s.feetxtinf")
    public WarningResult checkFeetxtinf(SetfelVo setfelVo){
        if(setfelVo.isModified("feetxtinf") && MdaUtils.compareTo(setfelVo.getAmt(), 0) != 0 ) {
            return WarningResult.build("SubCheckFEETXTINF", getMessage("0137", setfelVo.getFeecod()));
        } else {
            if(Strings.len(codetableService.getTblLabel(setfelVo.getFeecod(), "FEETXT")) > Strings.len(setfelVo.getFeetxt())) {
                return WarningResult.build("SubCheckFEETXTINF", getMessage("0138", setfelVo.getFeecod()));
            }
        }
        return WarningResult.buildEmpty("SubCheckFEETXTINF");
    }

    /**
     *   source:setfel.0025.script
     */
    @Warning(path = "setmod.setfeg.setfel.%s.dat2")
    public WarningResult warningDat2(SetfelVo setfelVo){
        //! Set warning, if minimum used for incomplete period (900671)
        if( Dates.diff(setfelVo.getDat2(), setfelVo.getDat2dft()) < 0 && MdaUtils.compareTo(setfelVo.getAllcalflg(),"T")== 0 ) {
            return WarningResult.build("SubCheckDAT2", getMessage("0139", setfelVo.getCur(),Utils.fmtAmount(setfelVo.getAmt(),setfelVo.getCur()),setfelVo.getFeecod(),setfelVo.getRol()));
        }
        return WarningResult.buildEmpty("SubCheckDAT2");
    }

    /**
     *   source:setfel.0025.script
     */
    @Warning(path = "setmod.setfeg.setfel.%s.amt", enable = "N")
    public WarningResult warningAmt(SetfelVo setfelVo){
        //! Set warning, if minimum used for incomplete period (900671)
        if ("T".equalsIgnoreCase(setfelVo.getSrc()) || "P".equalsIgnoreCase(setfelVo.getSrc())) {
            if (setfelVo.getAmt().compareTo(BigDecimal.ZERO) == 0) {
                return WarningResult.build("SubCheckAmt", getMessage("0226"));
            }
        }
        return WarningResult.buildEmpty("SubCheckAmt");
    }

    @Warning(path = "setmod.setfeg.setfel.%s.dat2dft", enable = "N")
    public WarningResult warningDat2dft(SetfelVo setfelVo){
        if ("Y".equals(setfelVo.getCommFeeFlag()) && setfelVo.getDat2dft() != null && setfelVo.getDat2() != null) {
            if (MdaUtils.compareTo(setfelVo.getDat2dft(), setfelVo.getDat2()) < 0) {
                return WarningResult.build("SUBCHECKDAT2DFT", "计费结束日期晚于保函到期日");
            }
        }
        return WarningResult.buildEmpty("SUBCHECKDAT2DFT");
    }

    @Warning(path = "setmod.setfeg.setfel.%s.wrkfec.ratcal")
    public WarningResult warningRatcal(SetfelVo setfelVo) {
        boolean isGuaranteeAmeFeeFlag = setfelService.isGuaranteeAmeFee(setfelVo.getFeecod());
        if ("T".equals(setfelVo.getSrc())
                && isGuaranteeAmeFeeFlag
                && setfelVo.getAmt().compareTo(BigDecimal.ZERO) > 0) {
            String feeCode = "GIOPN" + setfelVo.getFeecod().substring(5);
            Fee opnFee = feeMapper.selectByCod(feeCode);
            if (opnFee == null) {
                log.warn("检核修改费率是找不到开立的费用代码 {}", feeCode);
                return WarningResult.buildEmpty("CHECKRATCAL");
            }
            SetmodVo setmodVo = (SetmodVo)getParent();
            Fec fec = new Fec();
            fec.setObjtyp(setmodVo.getRec().getObjtyp());
            fec.setObjinr(setmodVo.getRec().getObjinr());
            fec.setFeepri("6");
            fec.setFeeinr(opnFee.getInr());
            Date date = Dates.add(Utils.getMaxDate(), -1);
            cbsRange.sdbRngRead(fec, date);
            if (StringUtils.isNotEmpty(fec.getInr())) {
                if (setfelVo.getWrkfec().getCalrul().equals(fec.getCalrul())
                        && setfelVo.getWrkfec().getRatcal().compareTo(fec.getRatcal()) != 0) {
                    return WarningResult.build("CHECKRATCAL", "修改时保函费率跟开立不一致，请关注！");
                }
            }
        }
        return WarningResult.buildEmpty("CHECKRATCAL");
    }
    @Validate(path = "setmod.setfeg.setfel.%s.dsp")
    public ValidResult checkDsp(SetfelVo setfelVo) {
        if ("Y".equals(setfelVo.getCommFeeFlag()) && setfelVo.getAmt().compareTo(BigDecimal.ZERO) == 0) {
            if (StringUtils.isEmpty(setfelVo.getDsp())) {
                return ValidResult.build(false, "我行佣金收费金额为0的情况下，请在收费方式选择后收或者免收（如果免收该费用的话）");
            }
        }
        return null;
    }

    @Validate(path = "setmod.setfeg.setfel.%s.dsp")
    public ValidResult checkDsp1000(SetfelVo setfelVo) {
        if (StringUtils.isNotEmpty(setfelVo.getFeecod()) && setfelVo.getAmt().compareTo(BigDecimal.ZERO) != 0) {
            if (StringUtils.isEmpty(setfelVo.getDsp())) {
                return errorMandatory();
            }
        }
        return null;
    }

    @Warning(path = "setmod.setfeg.setfel.%s.feecod")
    public WarningResult warningFeecod(SetfelVo setfelVo) {
        SetmodVo setmodVo = (SetmodVo)getParent();
        if (setfelVo.getFeecod().indexOf("GIOPN") > -1) {
            String objinr = setmodVo.getRec().getObjinr();
            String objtyp = setmodVo.getRec().getObjtyp();
            //迁移数据
            if (StringUtils.isNotEmpty(objinr) && objinr.length() == 8) {
                boolean doFlag = false;
                String sql = "select inr from fep where feecod = '" + setfelVo.getFeecod() + "' and objtyp = '" + objtyp + "' and objinr = '" + objinr + "'";
                Map<String, Object> dyncMap = new HashMap<>();
                dyncMap.put("sql", sql);
                List<Fep> fepList = fepMapper.dyncRead(dyncMap);
                if (fepList != null && fepList.size() > 0) {
                    for (int i=0; i<fepList.size(); i++) {
                        if (fepList.get(i).getInr().length() == 16) {
                            doFlag = true;
                            break;
                        }
                    }
                }
                if (!doFlag) {
                    return WarningResult.build("SUBFEECOD", "迁移数据未在新系统中收费，请关注收费时间以及收费金额，建议在定期收费交易收费并重点关注收费起始日期");
                }
            }
        }
        return WarningResult.buildEmpty("SUBFEECOD");
    }}
