1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package cn.iocoder.yudao.module.srm.service.tender;
 
import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierQuoteDO;
import cn.iocoder.yudao.module.srm.dal.dataobject.SrmTenderMaterialDO;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.invalidParamException;
 
/** 生成采购单前核对每一项物料,避免静默丢失订单明细。 */
final class SrmPurchaseQuoteValidator {
    private SrmPurchaseQuoteValidator() {}
 
    static Map<Long, SrmSupplierQuoteDO> validate(List<SrmTenderMaterialDO> materials, List<SrmSupplierQuoteDO> quotes) {
        if (materials == null || materials.isEmpty()) throw invalidParamException("招标项目没有物料,不能生成采购订单");
        Map<Long, SrmSupplierQuoteDO> byMaterial = new HashMap<>();
        if (quotes != null) for (var quote : quotes) {
            if (quote.getTenderMaterialId() == null || byMaterial.putIfAbsent(quote.getTenderMaterialId(), quote) != null)
                throw invalidParamException("存在重复或无物料的报价,请先核对");
        }
        for (var material : materials) {
            var quote = byMaterial.get(material.getId());
            if (material.getId() == null || material.getProductId() == null || material.getQuantity() == null
                    || material.getQuantity().signum() <= 0 || quote == null || quote.getQuotePrice() == null
                    || quote.getQuotePrice().signum() < 0)
                throw invalidParamException("存在未报价或物料数量无效的明细,请补齐后再生成采购订单");
        }
        if (byMaterial.size() != materials.size()) throw invalidParamException("报价包含不属于当前项目的物料,请核对");
        return byMaterial;
    }
}