package com.yem.em.ass.cmmptable.validator;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;

/**
 * @author zhouc
 * @date 2023/11/2 18:16
 * @className CMMPTableAuditvalidator
 * @description CMMP部件明细表审核校验器
 */
public class CMMPTableAuditvalidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntitie : dataEntities) {
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            DynamicObjectCollection yem_entryentity = dataEntity.getDynamicObjectCollection("yem_entryentity");
            for (int i = 0; i < yem_entryentity.size(); i++) {
                DynamicObject dynamicObject = yem_entryentity.get(i);
                int seq = i+1;
                boolean yemIsnormal = dynamicObject.getBoolean("yem_isnormal");
                if (!yemIsnormal) {
                    this.addErrorMessage(dataEntitie, String.format("部件详情第【"+seq+"】行未匹配【系统编码】，请重试！"));
                }
                boolean yem_isassatlasdet = dynamicObject.getBoolean("yem_isassatlasdet");
                if (!yemIsnormal) {
                    this.addErrorMessage(dataEntitie, String.format("部件详情第【"+seq+"】行未匹配【图册明细】，请重试！"));
                }
            }
        }
    }
}
