package com.yem.wm.es.salesorder.validator;

import com.grapecity.documents.excel.L;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;
import scala.Int;

import java.util.*;

/**
 * @author ljw
 * @date 2024/9/12 19:01
 * @description SalesOrderSaveValidator
 */
public class SalesOrderSaveValidator extends AbstractValidator {
    @Override
    public void validate() {
        ExtendedDataEntity[] dataEntities = this.getDataEntities();
        for (ExtendedDataEntity dataEntitie : dataEntities) {
            DynamicObject dataEntity = dataEntitie.getDataEntity();
            DynamicObjectCollection yemEsMaterialinfo = dataEntity.getDynamicObjectCollection("yem_es_materialinfo");
            Map<Long, String> map = new HashMap<>();
            Map<Long, String> maps = new HashMap<>();
            for (DynamicObject dynamicObject : yemEsMaterialinfo) {
                DynamicObject yemMateriel = dynamicObject.getDynamicObject("yem_materiel");
                if (yemMateriel != null) {
                    String seq = dynamicObject.getString("seq");
                    Long aLong = yemMateriel.getLong("id");
                    if (map.get(aLong) == null) {
                        map.put(aLong, seq);
                    } else {
                        if (maps.get(aLong) == null) {
                            maps.put(aLong, map.get(aLong) + "," + seq);
                        } else {
                            maps.put(aLong, maps.get(aLong) + "," + seq);
                        }
                    }

                }
            }
            for (Long key : maps.keySet()) {
                this.addWarningMessage(dataEntitie, "商品明细：第" +  maps.get(key) + "行物料编码重复!!!\n");
            }
        }
    }
}
