package com.yem.em.ass.compsub.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;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author zhouc
 * @date 2023/11/1 23:09
 * @className CompSubSubmitvalidatorEdit
 * @description 部件替换关系提交校验器
 */
public class CompSubSubmitvalidatorEdit 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");
            if (yem_entryentity.size() > 0) {
                for (int i = 0; i < yem_entryentity.size(); i++) {
                    DynamicObject dynamicObject = yem_entryentity.get(i);
                    int seq = i + 1;
                    String yem_onumber = dynamicObject.getString("yem_onumber");
                    Date yem_completetime = dynamicObject.getDate("yem_completetime");
                    if (yem_completetime == null) {
                        this.addErrorMessage(dataEntitie, String.format("明细信息第【" + seq + "】行【替换时间】必录，请修改后重试！"));
                    }
                    String yem_replace = dynamicObject.getString("yem_replace");
                    if (!yem_replace.equals("E")) {
                        BigDecimal yem_repenqty = dynamicObject.getBigDecimal("yem_repenqty");
                        if (yem_repenqty.compareTo(BigDecimal.ZERO) == 0) {
                            this.addErrorMessage(dataEntitie, String.format("明细信息第【" + seq + "】行【替换零件数量】必录，请修改后重试！"));
                        }
                        String yem_repenname = dynamicObject.getString("yem_repenname");
                        if (yem_repenname.length() == 0) {
                            this.addErrorMessage(dataEntitie, String.format("明细信息第【" + seq + "】行【替换零件英文名称】必录，请修改后重试！"));
                        }
                    }
                }
            }

        }
    }
}
