package com.yem.wm.bd.packplan.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 power
 * @ClassName  SubmotOpValidator
 * @description: 装箱方案自定义校验器
 * @date 2023/9/19
 */
public class SubmotOpValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[]  datas = this.getDataEntities();
        for(ExtendedDataEntity temp:datas) {
            DynamicObject bill = temp.getDataEntity();
            BigDecimal sumweight = bill.getBigDecimal("yem_weight");
            BigDecimal sumweights =BigDecimal.ZERO;
            DynamicObjectCollection packplans =  bill.getDynamicObjectCollection("yem_packplan_e");
            for (DynamicObject packplan:packplans) {
                BigDecimal staqty = packplan.getBigDecimal("yem_staqty");
                BigDecimal weight = packplan.getBigDecimal("yem_weight_e");
                BigDecimal weights =staqty.multiply(weight);
                sumweights =sumweights.add(weights);
            }
            if (sumweights.compareTo(sumweight) != 0) {
                this.addErrorMessage(temp,"整机重量"+sumweight+"不等于分录标准数量*大件重量的汇总值"+sumweights+"，请检查数据！");
            }
        }
    }
}
