package com.yem.wm.im.xpricelibrary.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 zhouc
 * @date 2024/1/30 11:31
 * @className XPriceLibrarySubmitValidator
 * @description
 */
public class XPriceLibrarySubmitValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntitie : dataEntities) {
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            DynamicObject billType = dataEntity.getDynamicObject("yem_billtype");//单据类型
            if (billType != null) {
                String number = billType.getString("number");
                if ("yem_pricelibrary_e_ZJ".equals(number)) {
                    DynamicObjectCollection yem_optional = dataEntity.getDynamicObjectCollection("yem_optional");
                    for (int i = 0; i < yem_optional.size(); i++) {
                        DynamicObject dynamicObject = yem_optional.get(i);
                        int seq = i + 1;
                        String yem_profilename_o = dynamicObject.getString("yem_profilename_o");
                        BigDecimal yem_salesmarkup_o = dynamicObject.getBigDecimal("yem_salesmarkup_o");
                        if (yem_profilename_o.length() > 0 && yem_salesmarkup_o.compareTo(BigDecimal.ZERO) == 0) {
                            String str = "可选装第【"+seq+"】行，选装销售定价为空，是否提交？";
                            this.addWarningMessage(dataEntitie, str);
                        }
                    }
                    DynamicObjectCollection yem_replaceable = dataEntity.getDynamicObjectCollection("yem_replaceable");
                    for (int j = 0; j < yem_replaceable.size(); j++) {
                        DynamicObject dynamicObject = yem_replaceable.get(j);
                        int seq = j + 1;
                        String yem_profilename_re = dynamicObject.getString("yem_profilename_re");
                        BigDecimal yem_salesmarkup_o = dynamicObject.getBigDecimal("yem_salesmarkup_re");
                        if (yem_profilename_re.length() > 0 && yem_salesmarkup_o.compareTo(BigDecimal.ZERO) == 0) {
                            String str = "可替换第【"+seq+"】行，替换销售加价为空，是否提交？";
                            this.addWarningMessage(dataEntitie, str);
                        }
                    }
                    DynamicObjectCollection yem_retrofitting = dataEntity.getDynamicObjectCollection("yem_retrofitting");
                    for (int k = 0; k < yem_retrofitting.size(); k++) {
                        DynamicObject dynamicObject = yem_retrofitting.get(k);
                        int seq = k + 1;
                        String yem_profilename_rt = dynamicObject.getString("yem_profilename_rt");
                        BigDecimal yem_salesmarkup_o = dynamicObject.getBigDecimal("yem_salesmarkup_re");
                        if (yem_profilename_rt.length() > 0 && yem_salesmarkup_o.compareTo(BigDecimal.ZERO) == 0) {
                            String str = "可加装第【"+ seq+"】行，加装销售加价为空，是否提交？";
                            this.addWarningMessage(dataEntitie, str);
                        }
                    }
                }
            }
        }
    }
}
