package com.yem.wm.es.encasement.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;

/**
 * @Classname EncaseMentSubmitValidator
 * @Description TODO
 * @Date 2023/12/12 20:22
 * @Created by ZZSLL
 */

public class EncaseMentSubmitValidator extends AbstractValidator
{
    @Override
    public void validate()
    {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntity : dataEntities) {
            DynamicObject entity = dataEntity.getDataEntity();
            DynamicObjectCollection collection = entity.getDynamicObjectCollection("yem_im_materialinfo_mi");
            for (int i = 0; i < collection.size(); i++) {
                // 装箱数量
                BigDecimal decimal = collection.get(i).getBigDecimal("yem_shipmentqty");
                // 已包装数量
                BigDecimal packingqty = collection.get(i).getBigDecimal("yem_packingqty");

                if (packingqty.compareTo(decimal) > 0) {
                    this.addErrorMessage(dataEntity, "明细信息第" + (i + 1) + "行，已包装数量不能大于装箱数量");
                }
            }
        }
    }
}
