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 2024/1/5 19:24
 * @className CMMPTableUnAuditvalidator
 * @description CMMP部件明细表审核校验器
 */
public class CMMPTableUnAuditvalidator 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;
                String yem_ccode = dynamicObject.getString("yem_ccode");
                //新增
                boolean yem_isadd = dynamicObject.getBoolean("yem_isadd");
                if (yem_isadd) {
                    this.addErrorMessage(dataEntitie, String.format("部件详情第【" + seq + "】行为变更【新增】行，禁止反审核！"));
                }
                //删除
                boolean yem_isdelete = dynamicObject.getBoolean("yem_isdelete");
                if (yem_isdelete) {
                    this.addErrorMessage(dataEntitie, String.format("部件详情第【" + seq + "】行为变更【删除】行，禁止反审核！"));
                }
                //替换
                boolean yem_partisreplace = dynamicObject.getBoolean("yem_partisreplace");
                if (yem_partisreplace) {
                    this.addErrorMessage(dataEntitie, String.format("部件详情第【" + seq + "】行为已发生替换，禁止反审核！"));
                }
            }
        }
    }
}
