package com.yem.em.bd.bomchange.validator;

import com.yem.wm.utils.StringUtils;
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/8/30 17:01
 * @className BomChangeAuditvalidatorEdit
 * @description BOM变更单校验器
 */
public class BomChangeAuditvalidatorEdit 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 materialinfo = yem_entryentity.get(i);
                int seq = i + 1;
                String yem_enablesubno = materialinfo.getString("yem_enablesubno");
                String yem_enablesta = materialinfo.getString("yem_enablesta");
                String yem_replace = materialinfo.getString("yem_replace");
                if (yem_enablesta.equals("B")) {
                    if (StringUtils.isNotEmpty(yem_replace)) {
                        if (yem_replace.equals("A") || yem_replace.equals("B")) {
                            if (StringUtils.isEmpty(yem_enablesubno)) {
                                this.addWarningMessage(dataEntitie, String.format("明细信息第【" + seq + "】行未选择【替换零件】和【替换关系】，是否继续？"));
                            }
                        }
                    }
                }
            }
        }
    }
}
