|
@@ -30,6 +30,7 @@ import com.sd.business.entity.order.dto.OrderExchangeSelectDto;
|
|
|
import com.sd.business.entity.order.po.*;
|
|
|
import com.sd.business.entity.order.vo.OrderExchangeDetailVo;
|
|
|
import com.sd.business.entity.order.vo.OrderExchangeVo;
|
|
|
+import com.sd.business.entity.order.vo.OrderSkuBomVo;
|
|
|
import com.sd.business.entity.statement.po.StatementOfAccount;
|
|
|
import com.sd.business.entity.warehouse.constant.WarehouseConstant;
|
|
|
import com.sd.business.mapper.order.OrderExchangeMapper;
|
|
@@ -337,7 +338,46 @@ public class OrderExchangeServiceImpl extends ServiceImpl<OrderExchangeMapper, O
|
|
|
List<InOutStorageBom> tempInOutStorageBomList = new ArrayList<>();
|
|
|
List<Long> orderSkuIds = detailList.stream().map(OrderExchangeDetail::getOrderSkuId).collect(Collectors.toList());
|
|
|
Map<Long, OrderSku> orderSkuMap = orderSkuService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, orderSkuIds));
|
|
|
+
|
|
|
+ List<OrderSkuBom> orderSkuBomList = orderSkuBomService.list(q -> q.in(OrderSkuBom::getOrderSkuId, orderSkuIds));
|
|
|
+ Map<Long, List<OrderSkuBom>> orderSkuBomMap = orderSkuBomList.stream().collect(Collectors.groupingBy(OrderSkuBom::getOrderSkuId));
|
|
|
+
|
|
|
+ List<Long> bomSpecIdList = orderSkuBomList.stream()
|
|
|
+ .map(OrderSkuBom::getBomSpecId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
+
|
|
|
+ Map<Long, BigDecimal> exchangeQuantity = detailList.stream().collect(Collectors.toMap(OrderExchangeDetail::getOrderSkuId, OrderExchangeDetail::getQuantity, BigDecimal::add));
|
|
|
+ Map<Long, Map<Long, OrderSkuBomVo>> reusableOrderSkuBomMap = orderSkuBomList.stream()
|
|
|
+ .map(item -> BeanUtil.toBean(item, OrderSkuBomVo.class))
|
|
|
+ .filter(item -> {
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(item.getBomSpecId());
|
|
|
+ if (bomSpecBo != null && Objects.equals(bomSpecBo.getClassifyId(), BomClassifyConstant.MESH_BAG)) {
|
|
|
+ item.setQuantity(item.getQuantity().multiply(exchangeQuantity.getOrDefault(item.getOrderSkuId(), BigDecimal.ZERO)));
|
|
|
+ item.setBomClassifyId(BomClassifyConstant.MESH_BAG);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ OrderSkuBomVo::getOrderSkuId,
|
|
|
+ Collectors.toMap(OrderSkuBomVo::getBomClassifyId, Function.identity(), (v1, v2) -> v2)
|
|
|
+ ));
|
|
|
+
|
|
|
+ Map<Long, BigDecimal> meshBagDamageQuantityMap = new HashMap<>();
|
|
|
for (OrderExchangeDetail detail : detailList) {
|
|
|
+ Map<Long, OrderSkuBomVo> exchangeOrderSkuBomMap = reusableOrderSkuBomMap.getOrDefault(detail.getOrderSkuId(), Collections.emptyMap());
|
|
|
+ OrderSkuBomVo orderSkuBomVo = exchangeOrderSkuBomMap.get(BomClassifyConstant.MESH_BAG);
|
|
|
+ if (orderSkuBomVo != null) {
|
|
|
+ if (orderSkuBomVo.getQuantity().compareTo(detail.getMeshBagDamageQuantity()) < 0) {
|
|
|
+ throw new ServiceException("网包损坏数量大于订单网包数量!");
|
|
|
+ }
|
|
|
+ BigDecimal price = orderSkuBomVo.getUnitPrice().multiply(detail.getMeshBagDamageQuantity());
|
|
|
+
|
|
|
+ detail.setReturnAmount(detail.getReturnAmount().subtract(price));
|
|
|
+ }
|
|
|
+ meshBagDamageQuantityMap.put(detail.getOrderSkuId(), detail.getMeshBagDamageQuantity());
|
|
|
int compareTo = detail.getQuantity().compareTo(detail.getCheckPassesQuantity());
|
|
|
if (compareTo == 0) {
|
|
|
|
|
@@ -368,20 +408,38 @@ public class OrderExchangeServiceImpl extends ServiceImpl<OrderExchangeMapper, O
|
|
|
|
|
|
Map<Long, OrderSku> finishedOrderSkuMap = tempOrderSkuList.stream().collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
|
|
|
List<Long> orderSkuId = tempOrderSkuList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
- List<OrderSkuBom> orderSkuBomList = orderSkuBomService.list(q -> q.in(OrderSkuBom::getOrderSkuId, orderSkuId));
|
|
|
-
|
|
|
- List<Long> bomSpecIdList = orderSkuBomList.stream()
|
|
|
- .map(OrderSkuBom::getBomSpecId)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
- List<OrderSkuBom> tempOrderSkuBomList = orderSkuBomList.stream()
|
|
|
+ List<OrderSkuBom> tempOrderSkuBomList = orderSkuId.stream()
|
|
|
+ .map(item -> orderSkuBomMap.getOrDefault(item, Collections.emptyList()))
|
|
|
+ .flatMap(Collection::stream)
|
|
|
.filter(item -> {
|
|
|
+ item.setQuantity(item.getQuantity().multiply(finishedOrderSkuMap.get(item.getOrderSkuId()).getQuantity()));
|
|
|
BomSpecBo bomSpecBo = bomSpecBoMap.get(item.getBomSpecId());
|
|
|
- if (bomSpecBo == null
|
|
|
- || Objects.equals(bomSpecBo.getClassifyId(), BomClassifyConstant.MESH_BAG)) {
|
|
|
+ if (bomSpecBo == null) {
|
|
|
return false;
|
|
|
}
|
|
|
+ if (Objects.equals(bomSpecBo.getClassifyId(), BomClassifyConstant.MESH_BAG)) {
|
|
|
+ BigDecimal meshBagDamageQuantity = meshBagDamageQuantityMap.getOrDefault(item.getOrderSkuId(), BigDecimal.ZERO);
|
|
|
+
|
|
|
+ if (meshBagDamageQuantity.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, OrderSkuBomVo> map = reusableOrderSkuBomMap.getOrDefault(item.getOrderSkuId(), Collections.emptyMap());
|
|
|
+ OrderSkuBomVo bom = map.get(bomSpecBo.getClassifyId());
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal realityQuantity = bom.getQuantity().subtract(meshBagDamageQuantity);
|
|
|
+
|
|
|
+
|
|
|
+ if (realityQuantity.compareTo(item.getQuantity()) >= 0) {
|
|
|
+ bom.setQuantity(realityQuantity.subtract(item.getQuantity()));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ bom.setQuantity(BigDecimal.ZERO);
|
|
|
+ item.setQuantity(item.getQuantity().subtract(realityQuantity));
|
|
|
+ }
|
|
|
return true;
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
@@ -389,7 +447,7 @@ public class OrderExchangeServiceImpl extends ServiceImpl<OrderExchangeMapper, O
|
|
|
List<InOutStorageBom> outStorageBomList = tempOrderSkuBomList.stream().map(item -> {
|
|
|
InOutStorageBom inOutStorageBom = new InOutStorageBom();
|
|
|
inOutStorageBom.setBomSpecId(item.getBomSpecId());
|
|
|
- inOutStorageBom.setQuantity(item.getQuantity().multiply(finishedOrderSkuMap.get(item.getOrderSkuId()).getQuantity()));
|
|
|
+ inOutStorageBom.setQuantity(item.getQuantity());
|
|
|
return inOutStorageBom;
|
|
|
}).collect(Collectors.toList());
|
|
|
InOutStorageDto inOutStorageDto = new InOutStorageDto();
|
|
@@ -426,6 +484,40 @@ public class OrderExchangeServiceImpl extends ServiceImpl<OrderExchangeMapper, O
|
|
|
inOutStorageDto.setInOutStorageBomList(inOutStorageBomList);
|
|
|
inOutStorageService.add(inOutStorageDto);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ List<InOutStorageBom> tempInStorageBomList = reusableOrderSkuBomMap.values().stream()
|
|
|
+ .map(Map::values)
|
|
|
+ .flatMap(Collection::stream)
|
|
|
+ .filter(item -> item.getQuantity().compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ .map(item -> {
|
|
|
+ InOutStorageBom inOutStorageBom = new InOutStorageBom();
|
|
|
+ inOutStorageBom.setBomSpecId(item.getBomSpecId());
|
|
|
+ inOutStorageBom.setQuantity(item.getQuantity());
|
|
|
+ return inOutStorageBom;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ if (!tempInStorageBomList.isEmpty()) {
|
|
|
+
|
|
|
+ List<InOutStorageBom> inOutStorageBomList = new ArrayList<>(tempInStorageBomList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ InOutStorageBom::getBomSpecId,
|
|
|
+ Function.identity(),
|
|
|
+ (v1, v2) -> {
|
|
|
+ v1.setQuantity(v1.getQuantity().add(v2.getQuantity()));
|
|
|
+ return v1;
|
|
|
+ })).values());
|
|
|
+
|
|
|
+ InOutStorageDto inOutStorageDto = new InOutStorageDto();
|
|
|
+ inOutStorageDto.setType(InOutTypeEnum.IN.getKey());
|
|
|
+ inOutStorageDto.setDetailType(InDetailTypeEnum.RETURN_GOODS.getKey());
|
|
|
+ inOutStorageDto.setWarehouseId(WarehouseConstant.PACKAGING_MATERIAL);
|
|
|
+ inOutStorageDto.setDepartmentId(DepartmentConstant.SD_SPORTS);
|
|
|
+ inOutStorageDto.setApplicant(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
|
+ inOutStorageDto.setRemark("订单:" + orderInfo.getCode() + "订单售后退料入库");
|
|
|
+ inOutStorageDto.setInOutStorageBomList(inOutStorageBomList);
|
|
|
+ inOutStorageService.add(inOutStorageDto);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
StatementOfAccount statementOfAccount = this.getStatementOfAccount(orderInfo.getDepartmentId());
|
|
|
orderExchange.setStatementOfAccountId(statementOfAccount.getId());
|