package com.yem.wm.es.salesorder.validator;

import kd.bos.armor.core.util.StringUtil;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;

/**
 * @author power
 * @ClassName  外销合同
 * @description: 提交校验器： 根据整机类型进行判断是否必录
 * @date 2023/8/15
 */
public class SalesOrderMaterielSubValidator extends AbstractValidator {

    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        int message = 0;
        for(ExtendedDataEntity dataEntitie : dataEntities){
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            String billtype = dataEntity.getString("yem_billtype.number");
            DynamicObjectCollection materialInfos = dataEntity.getDynamicObjectCollection("yem_es_materialinfo");
            if ("yem_es_salesorder_ZJ".equals(billtype) || "yem_es_salesorder_nmzj".equals(billtype)){
                for (int i = 0; i < materialInfos.size(); i++) {
                    DynamicObject materialInfo = materialInfos.get(i);
                    String businesssort = materialInfo.getString("yem_businesssort");
                    String materiel = materialInfo.getString("yem_materiel.number");
                    if("P".equals(businesssort)){
                        if (StringUtil.isEmpty(materiel)){
                            message = i+1;
                            this.addErrorMessage(dataEntitie,"请填写”商品明细“第"+message+"行”：物料编码“。");
                        }
                    }
                }
            }
            if ("yem_es_salesorder_PJ".equals(billtype)  || "yem_es_salesorder_nmpj".equals(billtype)){
                for (int i = 0; i < materialInfos.size(); i++) {
                    DynamicObject materialInfo = materialInfos.get(i);
                    String businesssort = materialInfo.getString("yem_businesssort");
                    String materiel = materialInfo.getString("yem_materiel.number");
                    if (StringUtil.isEmpty(materiel)){
                        message = i+1;
                        this.addErrorMessage(dataEntitie,"请填写”商品明细“第"+message+"行”：物料编码“。");
                    }
                }
            }

//            this.addErrorMessage(dataEntitie,"请填写”商品明细“第"+i+1+"行”物料编码“");
        }
    }
}
