package nckd.jxccl.hr.psms.plugin.operate.performance.validate;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.sdk.plugin.Plugin;
import nckd.jxccl.base.common.constant.FormConstant;
import nckd.jxccl.hr.psms.common.PerfRankMgmtConstant;

import java.math.BigDecimal;

/**
* 排名考核结果比例配置-校验器
* @author W.Y.C
* @date 2025/10/22 12:59
* @version 1.0
*/
public class RankRatioConfValidate extends AbstractValidator {

    @Override
    public void validate() {
        for (ExtendedDataEntity dataEntity : this.getDataEntities()) {
            DynamicObject data = dataEntity.getDataEntity();
            DynamicObjectCollection entrys = data.getDynamicObjectCollection(FormConstant.NCKD_ENTRYENTITY);
            BigDecimal ratio = BigDecimal.ZERO;
            for (DynamicObject entry : entrys) {
                BigDecimal bigDecimal = entry.getBigDecimal(PerfRankMgmtConstant.NCKD_RATIO);
                ratio = ratio.add(bigDecimal);
            }
            //判断是否等于100
            if (ratio.compareTo(new BigDecimal(100)) != 0) {
                addMessage(dataEntity, "比例总和必须等于100");
            }

        }
    }
}