|
|
@@ -1,12 +1,16 @@
|
|
|
package org.dromara.order.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.dromara.common.core.enums.InvoiceStatus;
|
|
|
import org.dromara.common.core.enums.OrderStatus;
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
@@ -14,13 +18,14 @@ import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.redis.utils.SequenceUtils;
|
|
|
+import org.dromara.customer.api.RemoteCustomerService;
|
|
|
import org.dromara.order.domain.OrderDeliver;
|
|
|
import org.dromara.order.domain.OrderDeliverProduct;
|
|
|
import org.dromara.order.domain.OrderMain;
|
|
|
+import org.dromara.order.domain.OrderProduct;
|
|
|
import org.dromara.order.domain.bo.OrderDeliverBo;
|
|
|
import org.dromara.order.domain.bo.OrderDeliverProductBo;
|
|
|
-import org.dromara.order.domain.vo.OrderDeliverVo;
|
|
|
-import org.dromara.order.domain.vo.OrderQuantitySummary;
|
|
|
+import org.dromara.order.domain.vo.*;
|
|
|
import org.dromara.order.mapper.OrderDeliverMapper;
|
|
|
import org.dromara.order.mapper.OrderDeliverProductMapper;
|
|
|
import org.dromara.order.mapper.OrderMainMapper;
|
|
|
@@ -29,13 +34,13 @@ import org.dromara.order.service.IOrderDeliverService;
|
|
|
import org.dromara.order.utils.kd100.Kd100Util;
|
|
|
import org.dromara.order.utils.kd100.domain.QueryTrackDTO;
|
|
|
import org.dromara.order.utils.kd100.domain.TrackVO;
|
|
|
+import org.dromara.system.api.RemoteDeptService;
|
|
|
+import org.dromara.system.api.RemoteUserService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -49,6 +54,15 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class OrderDeliverServiceImpl extends ServiceImpl<OrderDeliverMapper, OrderDeliver> implements IOrderDeliverService {
|
|
|
|
|
|
+ @DubboReference
|
|
|
+ private RemoteUserService remoteUserService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteDeptService remoteDeptService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteCustomerService remoteCustomerService;
|
|
|
+
|
|
|
private final OrderDeliverMapper baseMapper;
|
|
|
|
|
|
private final OrderMainMapper orderMainMapper;
|
|
|
@@ -219,6 +233,38 @@ public class OrderDeliverServiceImpl extends ServiceImpl<OrderDeliverMapper, Ord
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<OrderDeliverProductVo> getCustomerOrderProductList(Set<Long> orderIdList) {
|
|
|
+ // 1. 空值与空集合校验
|
|
|
+ if (CollectionUtils.isEmpty(orderIdList)) {
|
|
|
+ return TableDataInfo.build(Collections.emptyList());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderDeliverVo> orderDeliverVoList = baseMapper.selectVoList(
|
|
|
+ new LambdaQueryWrapper<OrderDeliver>()
|
|
|
+ .in(OrderDeliver::getId, orderIdList)
|
|
|
+ );
|
|
|
+
|
|
|
+ /*构建发货id与订单编号对应关系的map*/
|
|
|
+ Map<Long, String> deliverIdToOrderNoMap = orderDeliverVoList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ OrderDeliverVo::getId,
|
|
|
+ OrderDeliverVo::getOrderCode,
|
|
|
+ (v1, v2) -> v1
|
|
|
+ ));
|
|
|
+
|
|
|
+ List<OrderDeliverProductVo> orderProductVoList = orderDeliverProductMapper.selectVoList(
|
|
|
+ new LambdaQueryWrapper<OrderDeliverProduct>()
|
|
|
+ .in(OrderDeliverProduct::getDeliverId, orderIdList)
|
|
|
+ );
|
|
|
+
|
|
|
+ orderProductVoList.forEach(v -> {
|
|
|
+ v.setOrderNo(deliverIdToOrderNoMap.get(v.getDeliverId()));
|
|
|
+ });
|
|
|
+
|
|
|
+ return TableDataInfo.build(orderProductVoList);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改订单发货主
|
|
|
*
|
|
|
@@ -267,6 +313,7 @@ public class OrderDeliverServiceImpl extends ServiceImpl<OrderDeliverMapper, Ord
|
|
|
.map(bo -> {
|
|
|
OrderDeliverProduct product = MapstructUtils.convert(bo, OrderDeliverProduct.class);
|
|
|
product.setDeliverId(deliverId);
|
|
|
+ product.setSubtotal(product.getOrderPrice().multiply(BigDecimal.valueOf(product.getDeliverNum())));
|
|
|
return product;
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
@@ -276,6 +323,97 @@ public class OrderDeliverServiceImpl extends ServiceImpl<OrderDeliverMapper, Ord
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<OrderDeliverVo> listDeliverOrderByCustomerIdPage(Long customerId, PageQuery pageQuery) {
|
|
|
+ if (customerId == null) {
|
|
|
+ return TableDataInfo.build(new Page<>(0, 0));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询客户的所有有效订单
|
|
|
+ LambdaQueryWrapper<OrderMain> orderWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderWrapper.eq(OrderMain::getCustomerId, customerId)
|
|
|
+ .eq(OrderMain::getDelFlag, "0");
|
|
|
+
|
|
|
+ List<OrderMain> orderMainList = orderMainMapper.selectList(orderWrapper);
|
|
|
+ if (orderMainList.isEmpty()) {
|
|
|
+ return TableDataInfo.build(new Page<>(0, 0));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> orderIds = orderMainList.stream()
|
|
|
+ .map(OrderMain::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 构建 orderId -> totalAmount 映射
|
|
|
+ Map<Long, BigDecimal> orderIdToAmountMap = orderMainList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ OrderMain::getId,
|
|
|
+ OrderMain::getTotalAmount,
|
|
|
+ (v1, v2) -> v1
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 构建 orderId -> orderTime 映射
|
|
|
+ Map<Long, Date> orderIdToorderTimeMap = orderMainList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ OrderMain::getId,
|
|
|
+ OrderMain::getOrderTime,
|
|
|
+ (v1, v2) -> v1
|
|
|
+ ));
|
|
|
+
|
|
|
+ Set<Long> createUserIds = orderMainList.stream().map(OrderMain::getCreateBy).collect(Collectors.toSet());
|
|
|
+ Set<Long> createDeptIds = orderMainList.stream().map(OrderMain::getCreateDept).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ final Map<Long, String> userMap = new HashMap<>();
|
|
|
+ if (!createUserIds.isEmpty()) {
|
|
|
+ userMap.putAll(remoteUserService.selectUserNamesByIds(new ArrayList<>(createUserIds)));
|
|
|
+ }
|
|
|
+
|
|
|
+ final Map<Long, String> deptMap = new HashMap<>();
|
|
|
+ if (!createDeptIds.isEmpty()) {
|
|
|
+ deptMap.putAll(remoteDeptService.selectDeptNameByIds(new HashSet<>(createDeptIds)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询明细(分页)
|
|
|
+ LambdaQueryWrapper<OrderDeliver> deliverWrapper = new LambdaQueryWrapper<>();
|
|
|
+ deliverWrapper.in(OrderDeliver::getOrderId, orderIds)
|
|
|
+ .eq(OrderDeliver::getDelFlag, "0");
|
|
|
+
|
|
|
+ Page<OrderDeliverVo> pageResult = baseMapper.selectVoPage(pageQuery.build(), deliverWrapper);
|
|
|
+ List<OrderDeliverVo> records = pageResult.getRecords();
|
|
|
+ if (CollUtil.isNotEmpty(records)) {
|
|
|
+ // 1. 提取所有 deliverId
|
|
|
+ List<Long> deliverIds = records.stream()
|
|
|
+ .map(OrderDeliverVo::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 批量查询所有商品明细
|
|
|
+ List<OrderDeliverProductVo> allProducts = orderDeliverProductMapper.selectVoList(
|
|
|
+ new LambdaQueryWrapper<OrderDeliverProduct>()
|
|
|
+ .in(OrderDeliverProduct::getDeliverId, deliverIds)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 安全聚合:处理 null subtotal
|
|
|
+ Map<Long, BigDecimal> deliverIdToTotalAmount = allProducts.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ OrderDeliverProductVo::getDeliverId,
|
|
|
+ Collectors.reducing(
|
|
|
+ BigDecimal.ZERO,
|
|
|
+ product -> Optional.ofNullable(product.getSubtotal()).orElse(BigDecimal.ZERO),
|
|
|
+ BigDecimal::add
|
|
|
+ )
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 4. 回填 totalAmount 和其他字段
|
|
|
+ for (OrderDeliverVo record : records) {
|
|
|
+ record.setTotalAmount(deliverIdToTotalAmount.getOrDefault(record.getId(), BigDecimal.ZERO));
|
|
|
+ record.setCreateName(userMap.getOrDefault(record.getCreateBy(), "未知用户"));
|
|
|
+ record.setCreateDeptName(deptMap.getOrDefault(record.getCreateDept(), "未知部门"));
|
|
|
+ record.setOrderTime(orderIdToorderTimeMap.get(record.getOrderId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return TableDataInfo.build(pageResult);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
*/
|