package com.yem.ia.intebilllogon.validator;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.yem.wm.utils.StringUtils;
import com.yem.wm.utils.YEM;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;

import java.math.BigDecimal;

/**
 * @author zhouc
 * @date 2023/11/11 17:24
 * @className IntebilllogonSaveValidator
 * @description 智能审批单据注册校验器
 */
public class IntebilllogonSaveValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntitie : dataEntities) {
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            Boolean fag = false;
            DynamicObjectCollection yem_billtype = dataEntity.getDynamicObjectCollection("yem_billtype");
            for (int i = 0; i < yem_billtype.size(); i++) {
                DynamicObject dynamicObject = yem_billtype.get(i);
                DynamicObject fbasedataid = dynamicObject.getDynamicObject("fbasedataid");
                String string = fbasedataid.getString("number");
                if (string.equals("yem_orderproreqbill_DB")) {
                    fag = true;
                }
            }
            if (fag) {
                String yem_isvmi = dataEntity.getString("yem_isvmi");
                if (YEM.isEmpty(yem_isvmi)) {
                    this.addErrorMessage(dataEntitie, String.format("当前单据选择单据类型包含【配件调拨计划】，请维护【仓库类型】！！！"));
                }
            }
        }
    }
}
