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

import com.yem.wm.utils.YEM;
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/14
 */
public class SaleOrderProValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for(ExtendedDataEntity dataEntitie : dataEntities){
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            DynamicObjectCollection materialInfos = dataEntity.getDynamicObjectCollection("yem_im_detailedinfor");
            for (int i = 0; i < materialInfos.size(); i++) {
                DynamicObject materialInfo = materialInfos.get(i);
                String businesssort = materialInfo.getString("yem_businesssort");
                String resourcenog = materialInfo.getString("yem_resourcenog.number");
                String materiel = materialInfo.getString("yem_materiel.number");
                if("Z".equals(businesssort)){
                    if (StringUtil.isNotEmpty(resourcenog)){
                        if (StringUtil.isEmpty(materiel)){
                            this.addMessage(dataEntitie,resourcenog+"对应的物料编码为空");
                        }
                    }
                }

            }
        }
    }
}
