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

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;

import java.math.BigDecimal;

/**
 * @author ljw
 * @date 2024/11/12 17:46
 * @description StorageTransSubmitValidator
 */
public class StorageTransSubmitValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntitie : dataEntities) {
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            DynamicObjectCollection yemEsMaterialinfo = dataEntity.getDynamicObjectCollection("yem_es_materialinfo");
            BigDecimal yemOrdersumnumber = dataEntity.getBigDecimal("yem_ordersumnumber");
            if (!yemEsMaterialinfo.isEmpty()){
                BigDecimal yemQty = BigDecimal.ZERO;
                for (DynamicObject dynamicObject : yemEsMaterialinfo) {
                    String yemBusinesssort = dynamicObject.getString("yem_businesssort");
                    boolean yemIfgift = dynamicObject.getBoolean("yem_ifgift");
                    if ("Z".equals(yemBusinesssort)&&!yemIfgift){
                        yemQty =yemQty.add(dynamicObject.getBigDecimal("yem_qty"));
                    }
                }
                if (yemOrdersumnumber.compareTo(yemQty)!= 0){
                    this.addMessage(dataEntitie,"订单总台数["+yemOrdersumnumber+"]和汇总数量["+yemQty+"]不一致，不允许提交!!!");
                }
            }
        }
    }
}
