package com.yem.wm.im.tracktaskconsole.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 2023/10/11 19:12
 * @className TracktaskconsoleSavevalidator
 * @description 跟单任务控制台【保存】服务插件
 */
public class TracktaskconsoleSavevalidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntitie : dataEntities) {
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            DynamicObject yemBilltype = dataEntity.getDynamicObject("yem_billtype");
            String typeNumber = "";
            if (yemBilltype != null) {
                typeNumber = yemBilltype.getString("number");
            }
            if ("yem_tracktaskconsole_pj".equals(typeNumber)) {//配件
                DynamicObjectCollection yem_es_materialinfo = dataEntity.getDynamicObjectCollection("yem_es_salesorder_r");//备料（生产、采购）信息
                for (int i = 0; i < yem_es_materialinfo.size(); i++) {
                    DynamicObject materialinfo = yem_es_materialinfo.get(i);
                    //配件:如果备料方式是调拨，仓库类型比录
                    String yem_stockway = materialinfo.getString("yem_stockway");
                    if (yem_stockway != null && yem_stockway.equals("E")) {
                        String yem_isvmi = materialinfo.getString("yem_isvmi");
                        if (yem_isvmi == null || yem_isvmi == "") {
                            int seq = i + 1;
                            this.addErrorMessage(dataEntitie, String.format("备料（生产、采购）信息第" + seq + "行【备料方式】为【调拨】,【仓库类型】必录!"));
                        }
                    }
                }
            }
        }
    }
}
