package com.yem.wm.es.shippingdetails.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/10/31 16:17
 * @description ShippingDetailsAuditValidator
 */
public class ShippingDetailsAuditValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntity : dataEntities) {
            DynamicObject dataEntitie = dataEntity.getDataEntity();
            if (dataEntitie.getDynamicObjectType().getName().equals("yem_xshippingdetails")) {
                DynamicObjectCollection yemEsSalesorderTotal = dataEntitie.getDynamicObjectCollection("yem_es_salesorder_total");
                if (!yemEsSalesorderTotal.isEmpty()){
                    for (DynamicObject dynamicObject : yemEsSalesorderTotal) {
                        BigDecimal yemQtyTl = dynamicObject.getBigDecimal("yem_qty_tl");
                        BigDecimal yemAllocateqtyTl = dynamicObject.getBigDecimal("yem_allocateqty_tl");
                        int i = dynamicObject.getInt("seq")+1;
                        String yemAccesmaterial = dynamicObject.getString("yem_accesmaterial_tl.name");
                        if (yemQtyTl.compareTo(yemAllocateqtyTl)<0){
                            this.addMessage(dataEntity,"出运汇总页签，第"+i+"行物料"+yemAccesmaterial+"，已调数量"+yemQtyTl+"，出运数量"+yemAllocateqtyTl+"，不允许审核，请修改调拨后处理！");
                        }
                    }
                }
            }
        }
    }
}
