|
@@ -458,8 +458,8 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getIsNeedCheck()), OrderMain::getIsNeedCheck, bo.getIsNeedCheck());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getIsNeedCheck()), OrderMain::getIsNeedCheck, bo.getIsNeedCheck());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getReturnedStatus()), OrderMain::getReturnedStatus, bo.getReturnedStatus());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getReturnedStatus()), OrderMain::getReturnedStatus, bo.getReturnedStatus());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getOrderType()), OrderMain::getOrderType, bo.getOrderType());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getOrderType()), OrderMain::getOrderType, bo.getOrderType());
|
|
|
- if (ObjectUtils.isNotEmpty(bo.getDataSource())){
|
|
|
|
|
- if ("1".equals(bo.getDataSource())){
|
|
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(bo.getDataSource())) {
|
|
|
|
|
+ if ("1".equals(bo.getDataSource())) {
|
|
|
// dataSource="1" 时,查询 dataSource 为空或 null 的数据
|
|
// dataSource="1" 时,查询 dataSource 为空或 null 的数据
|
|
|
lqw.and(wrapper -> wrapper.isNull(OrderMain::getDataSource).or().eq(OrderMain::getDataSource, ""));
|
|
lqw.and(wrapper -> wrapper.isNull(OrderMain::getDataSource).or().eq(OrderMain::getDataSource, ""));
|
|
|
} else {
|
|
} else {
|
|
@@ -561,7 +561,7 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
bo.setProductQuantity(productQuantity);
|
|
bo.setProductQuantity(productQuantity);
|
|
|
bo.setTotalAmount(totalAmount);
|
|
bo.setTotalAmount(totalAmount);
|
|
|
bo.setPayableAmount(payableAmount);
|
|
bo.setPayableAmount(payableAmount);
|
|
|
-
|
|
|
|
|
|
|
+ bo.setPaymentStatus("1");//后台下单默认已支付
|
|
|
// --- 步骤 B: 处理下单时间 ---
|
|
// --- 步骤 B: 处理下单时间 ---
|
|
|
Date orderTimeToUse;
|
|
Date orderTimeToUse;
|
|
|
if (bo.getOrderTime() != null) {
|
|
if (bo.getOrderTime() != null) {
|
|
@@ -1849,4 +1849,184 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
log.warn("API订单确认失败,订单可能不存在,订单ID: {},订单号: {}", orderId, orderNo);
|
|
log.warn("API订单确认失败,订单可能不存在,订单ID: {},订单号: {}", orderId, orderNo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询订单及其所有子订单和商品(树形结构)
|
|
|
|
|
+ * 支持1级、2级、3级订单层级
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param orderId 订单ID
|
|
|
|
|
+ * @return 订单树形结构
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public OrderTreeVo queryOrderWithChildren(Long orderId) {
|
|
|
|
|
+ if (orderId == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("订单ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 查询当前订单
|
|
|
|
|
+ OrderMainVo currentOrder = baseMapper.selectVoById(orderId);
|
|
|
|
|
+ if (currentOrder == null) {
|
|
|
|
|
+ log.warn("订单ID {} 不存在", orderId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 构建当前订单的树形节点
|
|
|
|
|
+ OrderTreeVo treeVo = buildOrderTree(currentOrder);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 递归查询所有子订单
|
|
|
|
|
+ List<OrderTreeVo> childOrders = queryChildOrdersRecursive(orderId);
|
|
|
|
|
+ treeVo.setChildOrders(childOrders);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("成功查询订单树形结构,订单ID: {},子订单数量: {}", orderId, childOrders != null ? childOrders.size() : 0);
|
|
|
|
|
+ return treeVo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 递归查询子订单
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param parentOrderId 父订单ID
|
|
|
|
|
+ * @return 子订单树形列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<OrderTreeVo> queryChildOrdersRecursive(Long parentOrderId) {
|
|
|
|
|
+ // 查询直接子订单
|
|
|
|
|
+ List<OrderMainVo> directChildren = baseMapper.selectVoList(
|
|
|
|
|
+ new LambdaQueryWrapper<OrderMain>()
|
|
|
|
|
+ .eq(OrderMain::getParentOrderId, parentOrderId)
|
|
|
|
|
+ .orderByAsc(OrderMain::getId)
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if (CollUtil.isEmpty(directChildren)) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<OrderTreeVo> childTreeList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (OrderMainVo childOrder : directChildren) {
|
|
|
|
|
+ // 构建子订单节点
|
|
|
|
|
+ OrderTreeVo childTreeVo = buildOrderTree(childOrder);
|
|
|
|
|
+
|
|
|
|
|
+ // 递归查询子订单的子订单
|
|
|
|
|
+ List<OrderTreeVo> grandChildren = queryChildOrdersRecursive(childOrder.getId());
|
|
|
|
|
+ if (CollUtil.isNotEmpty(grandChildren)) {
|
|
|
|
|
+ childTreeVo.setChildOrders(grandChildren);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ childTreeList.add(childTreeVo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return childTreeList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构建订单树形节点(包含商品信息)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param orderMainVo 订单信息
|
|
|
|
|
+ * @return 订单树形节点
|
|
|
|
|
+ */
|
|
|
|
|
+ private OrderTreeVo buildOrderTree(OrderMainVo orderMainVo) {
|
|
|
|
|
+ OrderTreeVo treeVo = new OrderTreeVo();
|
|
|
|
|
+
|
|
|
|
|
+ // 复制基本字段
|
|
|
|
|
+ treeVo.setId(orderMainVo.getId());
|
|
|
|
|
+ treeVo.setOrderNo(orderMainVo.getOrderNo());
|
|
|
|
|
+ treeVo.setParentOrderId(orderMainVo.getParentOrderId());
|
|
|
|
|
+ treeVo.setParentOrderNo(orderMainVo.getParentOrderNo());
|
|
|
|
|
+ treeVo.setCurrentLevel(orderMainVo.getCurrentLevel());
|
|
|
|
|
+ treeVo.setOrderStatus(orderMainVo.getOrderStatus());
|
|
|
|
|
+ treeVo.setPaymentStatus(orderMainVo.getPaymentStatus());
|
|
|
|
|
+ treeVo.setCheckStatus(orderMainVo.getCheckStatus());
|
|
|
|
|
+ treeVo.setAssigneeType(orderMainVo.getAssigneeType());
|
|
|
|
|
+ treeVo.setAssigneeId(orderMainVo.getAssigneeId());
|
|
|
|
|
+ treeVo.setCustomerId(orderMainVo.getCustomerId());
|
|
|
|
|
+ treeVo.setCustomerName(orderMainVo.getCustomerName());
|
|
|
|
|
+ treeVo.setTotalAmount(orderMainVo.getTotalAmount());
|
|
|
|
|
+ treeVo.setPayableAmount(orderMainVo.getPayableAmount());
|
|
|
|
|
+ treeVo.setShippingFee(orderMainVo.getShippingFee());
|
|
|
|
|
+ treeVo.setOrderTime(orderMainVo.getOrderTime());
|
|
|
|
|
+ treeVo.setConfirmTime(orderMainVo.getConfirmTime());
|
|
|
|
|
+ treeVo.setShippingTime(orderMainVo.getShippingTime());
|
|
|
|
|
+ treeVo.setReceivingTime(orderMainVo.getReceivingTime());
|
|
|
|
|
+ treeVo.setRemark(orderMainVo.getRemark());
|
|
|
|
|
+ treeVo.setDataSource(orderMainVo.getDataSource());
|
|
|
|
|
+
|
|
|
|
|
+ // 查询并设置分配对象名称
|
|
|
|
|
+ if (orderMainVo.getAssigneeId() != null && StringUtils.isNotBlank(orderMainVo.getAssigneeType())) {
|
|
|
|
|
+ String assigneeName = getAssigneeName(orderMainVo.getAssigneeId(), orderMainVo.getAssigneeType());
|
|
|
|
|
+ treeVo.setAssigneeName(assigneeName);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询该订单的商品列表
|
|
|
|
|
+ List<OrderProductSimpleVo> productList = queryOrderProductsSimple(orderMainVo.getId());
|
|
|
|
|
+ treeVo.setProductList(productList);
|
|
|
|
|
+
|
|
|
|
|
+ return treeVo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询订单商品(简化版)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param orderId 订单ID
|
|
|
|
|
+ * @return 商品列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<OrderProductSimpleVo> queryOrderProductsSimple(Long orderId) {
|
|
|
|
|
+ List<OrderProductVo> productVos = orderProductMapper.selectVoList(
|
|
|
|
|
+ new LambdaQueryWrapper<OrderProduct>()
|
|
|
|
|
+ .eq(OrderProduct::getOrderId, orderId)
|
|
|
|
|
+ .orderByAsc(OrderProduct::getId)
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if (CollUtil.isEmpty(productVos)) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return productVos.stream().map(vo -> {
|
|
|
|
|
+ OrderProductSimpleVo simpleVo = new OrderProductSimpleVo();
|
|
|
|
|
+ simpleVo.setId(vo.getId());
|
|
|
|
|
+ simpleVo.setOrderId(vo.getOrderId());
|
|
|
|
|
+ simpleVo.setProductId(vo.getProductId());
|
|
|
|
|
+ simpleVo.setProductNo(vo.getProductNo());
|
|
|
|
|
+ simpleVo.setProductName(vo.getProductName());
|
|
|
|
|
+ simpleVo.setProductUnit(vo.getProductUnit());
|
|
|
|
|
+ simpleVo.setProductImage(vo.getProductImage());
|
|
|
|
|
+ simpleVo.setOrderPrice(vo.getOrderPrice());
|
|
|
|
|
+ simpleVo.setOrderQuantity(vo.getOrderQuantity());
|
|
|
|
|
+ simpleVo.setSubtotal(vo.getSubtotal());
|
|
|
|
|
+ simpleVo.setQuantitySent(vo.getQuantitySent());
|
|
|
|
|
+ simpleVo.setUnsentQuantity(vo.getUnsentQuantity());
|
|
|
|
|
+ simpleVo.setCurrentLevel(vo.getCurrentLevel());
|
|
|
|
|
+ simpleVo.setAssignmentStatus(vo.getAssignmentStatus());
|
|
|
|
|
+ simpleVo.setRemark(vo.getRemark());
|
|
|
|
|
+ return simpleVo;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取分配对象名称
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param assigneeId 分配对象ID
|
|
|
|
|
+ * @param assigneeType 分配对象类型
|
|
|
|
|
+ * @return 分配对象名称
|
|
|
|
|
+ */
|
|
|
|
|
+ private String getAssigneeName(Long assigneeId, String assigneeType) {
|
|
|
|
|
+ if (assigneeId == null || StringUtils.isBlank(assigneeType)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (AssigneeTypeConstants.CUSTOMER.getCode().equals(assigneeType)) {
|
|
|
|
|
+ Map<Long, String> customerMap = remoteCustomerService.selectCustomerNameByIds(Collections.singleton(assigneeId));
|
|
|
|
|
+ return customerMap.get(assigneeId);
|
|
|
|
|
+ } else if (AssigneeTypeConstants.SUPPLIER.getCode().equals(assigneeType)) {
|
|
|
|
|
+ Map<Long, String> supplierMap = remoteSupplierInfoService.selectSupplierNameByIds(Collections.singleton(assigneeId));
|
|
|
|
|
+ return supplierMap.get(assigneeId);
|
|
|
|
|
+ } else if (AssigneeTypeConstants.PARTNER.getCode().equals(assigneeType)) {
|
|
|
|
|
+ Map<Long, String> partnerMap = remotePartnerInfoService.selectPartnerNameByIds(Collections.singleton(assigneeId));
|
|
|
|
|
+ return partnerMap.get(assigneeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("获取分配对象名称失败,assigneeId: {}, assigneeType: {}", assigneeId, assigneeType, e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|