package com.yem.wm.es.salesorder.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.util.HashMap;
import java.util.Map;

/**
 * @author ljw
 * @date 2024/5/23 18:40
 * @description NewSalesOrderSubmitValidator
 */
public class NewSalesOrderSubmitValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntitie : dataEntities) {
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            DynamicObjectCollection yem_es_salescontrac_s = dataEntity.getDynamicObjectCollection("yem_es_salescontrac_s");
            if (yem_es_salescontrac_s.size()>0){
                Map<Long,String > map = new HashMap<>();
                for (DynamicObject dynamicObject : yem_es_salescontrac_s) {
                    String yemIssinosure = dynamicObject.getString("yem_issinosure");
                    if (yemIssinosure.equals("A")){
                        DynamicObject yemRapstyle = dynamicObject.getDynamicObject("yem_rapstyle");
                        map.put(yemRapstyle.getLong("id"),yemRapstyle.getString("number"));
                    }
                }
                if (map.size()>1){
                    this.addErrorMessage(dataEntitie,"当前单据”收款计划分录“中”是否信保“为“是”的结算方式必须唯一，请修改后提交！！！");
                }
            }

        }
    }
}
