package com.yem.wm.im.clientdemand.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 张立攀
 * @version 1.0
 * @description  客户需求单保存校验器
 * @date 2023-07-22 14:56
 */
public class ClientDemandValidator extends AbstractValidator {
    public static final  String billtypes = "yem_billtype.number";
    public static final  String materialclass = "yem_businesssort";
    @Override
    public void validate() {
        ExtendedDataEntity[]  datas = this.getDataEntities();
        //整机行数
        int rowCount = 0;
        boolean flag = false;
        for(ExtendedDataEntity temp:datas){
            DynamicObject dy = temp.getDataEntity();
            String billtype = dy.getString(billtypes);
            if(billtype != null && "yem_im_clientdeman_zj".equals(billtype)){
                flag = true;
                DynamicObjectCollection coll = dy.getDynamicObjectCollection("yem_im_detailedinfor");
                for(DynamicObject dyTemp:coll){
                    String materialclas = dyTemp.getString(materialclass);
                    if(materialclas != null && "Z".equals(materialclas)){
                        rowCount++;
                    }
                }
            }
            if(flag == true && rowCount < 1){
                addErrorMessage(temp,"明细信息中至少有一行整机");
            }
        }

    }
}
