|
|
@@ -2191,40 +2191,60 @@ public class KwcContractTradeService {
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "商品id不能为空!");
|
|
|
}
|
|
|
|
|
|
- //查询供应商企业物流合同信息
|
|
|
+ //1. 查询供应商企业物流合同关联的unit信息
|
|
|
List<KwcContractLogisticsUnit> contractLogisticsUnits = kwcContractLogisticsUnitRepository.queryByEntIdAndType(entId);
|
|
|
if (CollectionUtils.isEmpty(contractLogisticsUnits)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
Set<Long> unitContractIds = contractLogisticsUnits.stream().map(KwcContractLogisticsUnit::getContractId).collect(Collectors.toSet());
|
|
|
|
|
|
- //查询物流商品合同信息
|
|
|
- List<KwcContractLogisticsGoods> contractLogisticsGoods = kwcContractLogisticsGoodsRepository.queryByContractIds(unitContractIds);
|
|
|
- if (CollectionUtils.isEmpty(contractLogisticsGoods)) {
|
|
|
+ //2. 查询自动派车物流合同主信息
|
|
|
+ List<KwcContractLogistics> contractLogisticsList = contractLogisticsRepository.queryByIdsAndDispatch(unitContractIds);
|
|
|
+ if (CollectionUtils.isEmpty(contractLogisticsList)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- Map<Long, List<KwcContractLogisticsGoods>> logisticsGoodsMap = contractLogisticsGoods.stream().collect(Collectors.groupingBy(KwcContractLogisticsGoods::getContractId));
|
|
|
- List<Long> contractIdList = new ArrayList<>();
|
|
|
- //校验合同里是否都包含贸易合同里的商品
|
|
|
- for (Map.Entry<Long, List<KwcContractLogisticsGoods>> entry : logisticsGoodsMap.entrySet()) {
|
|
|
- Long contractId = entry.getKey();
|
|
|
- List<KwcContractLogisticsGoods> logisticsGoodList = entry.getValue();
|
|
|
- if (CollectionUtils.isEmpty(logisticsGoodList)) {
|
|
|
- continue;
|
|
|
+
|
|
|
+ // 3. 拆分合同:通用价格>0的直接保留,通用价格=0的需要校验商品id
|
|
|
+ List<Long> validContractIds = new ArrayList<>();
|
|
|
+ List<Long> needCheckGoodsContractIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (KwcContractLogistics contractLogistics : contractLogisticsList) {
|
|
|
+ if (contractLogistics.getCommonPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //通用价格大于0,无需校验goodsIds
|
|
|
+ validContractIds.add(contractLogistics.getId());
|
|
|
+ } else {
|
|
|
+ // 通用价格=0,需要校验商品
|
|
|
+ needCheckGoodsContractIds.add(contractLogistics.getId());
|
|
|
}
|
|
|
- //提取当前合同下的所有商品ID
|
|
|
- Set<Long> currentGoodsIds = logisticsGoodList.stream().map(KwcContractLogisticsGoods::getGoodsId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
- boolean isContains = goodsIds.stream().allMatch(currentGoodsIds::contains);
|
|
|
- if (isContains) {
|
|
|
- contractIdList.add(contractId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 处理需要校验商品的合同ID
|
|
|
+ if (CollectionUtils.isNotEmpty(needCheckGoodsContractIds)) {
|
|
|
+ //查询物流商品合同信息
|
|
|
+ List<KwcContractLogisticsGoods> contractLogisticsGoods = kwcContractLogisticsGoodsRepository.queryByContractIds(unitContractIds);
|
|
|
+ if (CollectionUtils.isNotEmpty(contractLogisticsGoods)) {
|
|
|
+ // 按合同ID分组商品信息
|
|
|
+ Map<Long, List<KwcContractLogisticsGoods>> logisticsGoodsMap = contractLogisticsGoods.stream().collect(Collectors.groupingBy(KwcContractLogisticsGoods::getContractId));
|
|
|
+ for (Long contractId : needCheckGoodsContractIds) {
|
|
|
+ List<KwcContractLogisticsGoods> logisticsGoodList = logisticsGoodsMap.get(contractId);
|
|
|
+ // 提取当前合同下的所有商品ID
|
|
|
+ Set<Long> currentGoodsIds = logisticsGoodList.stream().map(KwcContractLogisticsGoods::getGoodsId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ // 校验目标商品ID是否全部包含
|
|
|
+ boolean isContains = goodsIds.stream().allMatch(currentGoodsIds::contains);
|
|
|
+ if (isContains) {
|
|
|
+ validContractIds.add(contractId);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- if (CollectionUtils.isEmpty(contractIdList)) {
|
|
|
+ if (CollectionUtils.isEmpty(validContractIds)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- //查询自动派车物流合同
|
|
|
- List<KwcContractLogistics> contractLogisticsList = contractLogisticsRepository.queryByIdsAndDispatch(contractIdList);
|
|
|
- return toLogisticsEntDtoVO(entId, contractLogisticsList);
|
|
|
+ List<KwcContractLogistics> finalContractList = contractLogisticsList.stream()
|
|
|
+ .filter(contract -> validContractIds.contains(contract.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return toLogisticsEntDtoVO(entId, finalContractList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -2308,7 +2328,7 @@ public class KwcContractTradeService {
|
|
|
//查询物流商品合同信息
|
|
|
KwcContractLogisticsGoods goods = kwcContractLogisticsGoodsRepository.queryByContractIdAndGoodId(contractId, goodsId);
|
|
|
if (goods == null) {
|
|
|
- throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "当前物流合同商品信息不存在!");
|
|
|
+ return new LogisticsGoodsDto();
|
|
|
}
|
|
|
LogisticsGoodsDto dto = new LogisticsGoodsDto();
|
|
|
dto.setGoodsId(goods.getGoodsId());
|