|
@@ -1,5 +1,6 @@
|
|
|
package com.sd.business.service.order.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.ruoyi.common.core.domain.BaseIdPo;
|
|
@@ -9,20 +10,25 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.sd.business.entity.order.dto.IssueBillSelectDto;
|
|
|
import com.sd.business.entity.order.dto.OrderInfoDto;
|
|
|
import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
+import com.sd.business.entity.order.po.OrderEncasement;
|
|
|
+import com.sd.business.entity.order.po.OrderEncasementDetail;
|
|
|
import com.sd.business.entity.order.po.OrderInfo;
|
|
|
-import com.sd.business.entity.order.vo.IssueBillVO;
|
|
|
+import com.sd.business.entity.order.po.OrderSku;
|
|
|
+import com.sd.business.entity.order.vo.AssemblyDetailVo;
|
|
|
+import com.sd.business.entity.order.vo.IssueBillVo;
|
|
|
+import com.sd.business.entity.order.vo.OrderEncasementDetailVo;
|
|
|
+import com.sd.business.entity.order.vo.OrderEncasementVo;
|
|
|
import com.sd.business.entity.production.dto.MergeOrderDto;
|
|
|
import com.sd.business.mapper.order.IssueBillMapper;
|
|
|
-import com.sd.business.service.order.IssueBillService;
|
|
|
-import com.sd.business.service.order.OrderService;
|
|
|
+import com.sd.business.service.order.*;
|
|
|
+import com.sd.business.service.sku.SkuSpecService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -34,8 +40,20 @@ public class IssueBillServiceImpl implements IssueBillService {
|
|
|
@Autowired
|
|
|
private OrderService orderService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrderSkuService orderSkuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderEncasementService orderEncasementService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderEncasementDetailService orderEncasementDetailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SkuSpecService skuSpecService;
|
|
|
+
|
|
|
@Override
|
|
|
- public Page<IssueBillVO> getPage(IssueBillSelectDto dto) {
|
|
|
+ public Page<IssueBillVo> getPage(IssueBillSelectDto dto) {
|
|
|
IWrapper<Object> wrapper = IWrapper.getWrapper();
|
|
|
wrapper.orderByDesc("oi", OrderInfo::getWlnCreateTime);
|
|
|
|
|
@@ -57,15 +75,15 @@ public class IssueBillServiceImpl implements IssueBillService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Page<IssueBillVO> page = mapper.getPage(dto.getPage(), wrapper);
|
|
|
- List<IssueBillVO> records = page.getRecords();
|
|
|
+ Page<IssueBillVo> page = mapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<IssueBillVo> records = page.getRecords();
|
|
|
|
|
|
if (records.size() == 0) {
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
// 查询合并订单code
|
|
|
- List<Long> orderIdList = records.stream().map(IssueBillVO::getId).collect(Collectors.toList());
|
|
|
+ List<Long> orderIdList = records.stream().map(IssueBillVo::getId).collect(Collectors.toList());
|
|
|
List<OrderInfo> orderInfoList = orderService.list(q -> q.in(OrderInfo::getMasterOrderId, orderIdList));
|
|
|
|
|
|
Map<Long, List<String>> map = orderInfoList.stream().collect(
|
|
@@ -75,7 +93,6 @@ public class IssueBillServiceImpl implements IssueBillService {
|
|
|
});
|
|
|
|
|
|
return page;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -121,12 +138,85 @@ public class IssueBillServiceImpl implements IssueBillService {
|
|
|
public void merge(MergeOrderDto dto) {
|
|
|
orderService.update(q -> q.eq(OrderInfo::getId, dto.getId()).set(OrderInfo::getMasterOrderId, 0));
|
|
|
orderService.update(q -> q.in(OrderInfo::getId, dto.getMergeIdList()).set(OrderInfo::getMasterOrderId, dto.getId()));
|
|
|
+ orderEncasementService.delete(dto.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void unmerge(Long id) {
|
|
|
orderService.update(q -> q.eq(OrderInfo::getId, id).set(OrderInfo::getMasterOrderId, null));
|
|
|
orderService.update(q -> q.eq(OrderInfo::getMasterOrderId, id).set(OrderInfo::getMasterOrderId, null));
|
|
|
+ orderEncasementService.delete(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AssemblyDetailVo assemblyDetail(Long id) {
|
|
|
+ AssemblyDetailVo result = new AssemblyDetailVo();
|
|
|
+
|
|
|
+ // 获取合并订单
|
|
|
+ List<OrderInfo> mergeOrderList = orderService.list(q -> q.eq(OrderInfo::getMasterOrderId, id));
|
|
|
+
|
|
|
+ // 订单id列表
|
|
|
+ List<Long> orderIdList = mergeOrderList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ orderIdList.add(id);
|
|
|
+
|
|
|
+ // 赋值产品清单
|
|
|
+ List<OrderSku> list = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIdList));
|
|
|
+ List<AssemblyDetailVo.SkuInfo> skuInfoList = list.stream().map(item -> {
|
|
|
+ AssemblyDetailVo.SkuInfo skuInfo = new AssemblyDetailVo.SkuInfo();
|
|
|
+ skuInfo.setOrderSkuId(item.getId());
|
|
|
+ skuInfo.setSkuSpecId(item.getSkuSpecId());
|
|
|
+ skuInfo.setTotalQuantity(item.getQuantity());
|
|
|
+ skuInfo.setSurplusQuantity(item.getQuantity());
|
|
|
+ return skuInfo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 赋值sku规格编号、名称
|
|
|
+ skuSpecService.attributeAssign(skuInfoList, AssemblyDetailVo.SkuInfo::getSkuSpecId, (item, skuSpec) -> {
|
|
|
+ item.setSkuSpecCode(skuSpec.getCode());
|
|
|
+ item.setSkuSpecName(skuSpec.getName());
|
|
|
+ });
|
|
|
+ result.setSkuInfoList(skuInfoList);
|
|
|
+
|
|
|
+ // 包裹规格数
|
|
|
+ List<OrderEncasement> tempOrderEncasementList = orderEncasementService.list(q -> q.eq(OrderEncasement::getOrderId, id));
|
|
|
+ if (tempOrderEncasementList.size() == 0) {
|
|
|
+ result.setOrderEncasementList(Collections.emptyList());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderEncasementVo> orderEncasementList = BeanUtil.copyToList(tempOrderEncasementList, OrderEncasementVo.class);
|
|
|
+ Map<Long, OrderEncasementVo> orderEncasementVoMap = orderEncasementList.stream().collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
|
|
|
+ Set<Long> orderEncasementIdList = orderEncasementVoMap.keySet();
|
|
|
+
|
|
|
+ // 查询包裹规格sku列表
|
|
|
+ List<OrderEncasementDetail> tempOrderEncasementDetailList = orderEncasementDetailService.list(
|
|
|
+ q -> q.in(OrderEncasementDetail::getOrderEncasementId, orderEncasementIdList));
|
|
|
+ List<OrderEncasementDetailVo> orderEncasementDetailList = BeanUtil.copyToList(tempOrderEncasementDetailList, OrderEncasementDetailVo.class);
|
|
|
+
|
|
|
+ // 设置包裹规格sku品号、品名
|
|
|
+ skuSpecService.attributeAssign(orderEncasementDetailList, OrderEncasementDetailVo::getSkuSpecId, (item, skuSpec) -> {
|
|
|
+ item.setSkuSpecCode(skuSpec.getCode());
|
|
|
+ item.setSkuSpecName(skuSpec.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+ // 通过订单id分组
|
|
|
+ Map<Long, List<OrderEncasementDetailVo>> map = orderEncasementDetailList.stream()
|
|
|
+ .collect(Collectors.groupingBy(OrderEncasementDetail::getOrderEncasementId));
|
|
|
+ orderEncasementList.forEach(item -> item.setOrderEncasementDetailList(map.get(item.getId())));
|
|
|
+
|
|
|
+ // 赋值剩余可装箱数量
|
|
|
+ Map<Long, List<OrderEncasementDetailVo>> collect = orderEncasementDetailList.stream()
|
|
|
+ .collect(Collectors.groupingBy(OrderEncasementDetail::getOrderSkuId));
|
|
|
+ for (AssemblyDetailVo.SkuInfo skuInfo : skuInfoList) {
|
|
|
+ List<OrderEncasementDetailVo> tempList = collect.getOrDefault(skuInfo.getOrderSkuId(), Collections.emptyList());
|
|
|
+ tempList.forEach(item -> {
|
|
|
+ OrderEncasementVo orderEncasementVo = orderEncasementVoMap.get(item.getOrderEncasementId());
|
|
|
+ BigDecimal quantity = item.getQuantity().multiply(new BigDecimal(orderEncasementVo.getTotal()));
|
|
|
+ skuInfo.setSurplusQuantity(skuInfo.getSurplusQuantity().subtract(quantity));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ result.setOrderEncasementList(orderEncasementList);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
}
|