|
|
@@ -13,10 +13,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.dromara.common.core.context.PlatformContext;
|
|
|
-import org.dromara.common.core.enums.AssigneeTypeConstants;
|
|
|
-import org.dromara.common.core.enums.OrderPayType;
|
|
|
-import org.dromara.common.core.enums.OrderStatus;
|
|
|
-import org.dromara.common.core.enums.SysPlatformYesNo;
|
|
|
+import org.dromara.common.core.enums.*;
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.exception.api.ZhongcheException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
@@ -34,10 +31,7 @@ import org.dromara.external.api.zhongche.domain.bo.OrderConfirmBo;
|
|
|
import org.dromara.external.api.zhongche.domain.bo.OrderRejectBo;
|
|
|
import org.dromara.external.api.zhongche.domain.vo.GoodsUpdateVo;
|
|
|
import org.dromara.order.domain.*;
|
|
|
-import org.dromara.order.domain.bo.OrderMainBo;
|
|
|
-import org.dromara.order.domain.bo.OrderProductBo;
|
|
|
-import org.dromara.order.domain.bo.OrderSplitAssignBo;
|
|
|
-import org.dromara.order.domain.bo.PcSubmitOrderBo;
|
|
|
+import org.dromara.order.domain.bo.*;
|
|
|
import org.dromara.order.domain.dto.AssignmentStatsDto;
|
|
|
import org.dromara.order.domain.vo.*;
|
|
|
import org.dromara.order.mapper.*;
|
|
|
@@ -58,6 +52,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.sql.SQLIntegrityConstraintViolationException;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -466,7 +462,7 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
retryCount++;
|
|
|
|
|
|
// --- 步骤 A: 生成订单号 ---
|
|
|
- orderNo = SequenceUtils.generateOrderCode("RS");
|
|
|
+ orderNo = SequenceUtils.generateOrderCode(bo.getOrderNoPrefix());
|
|
|
bo.setOrderNo(orderNo);
|
|
|
|
|
|
bo.setProductQuantity(productQuantity);
|
|
|
@@ -647,6 +643,7 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
mainBo.setCustomerService(staffMap.get(serviceStaffId));
|
|
|
mainBo.setBusinessDept(deptMap.get(belongingDepartmentId));
|
|
|
}
|
|
|
+ mainBo.setOrderNoPrefix("Mo");
|
|
|
// 1. 插入主订单,获取生成的 ID
|
|
|
Long orderId = this.insertByBo(mainBo);
|
|
|
// 2. 校验插入是否成功
|
|
|
@@ -1314,4 +1311,415 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /*api外部订单下单*/
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Long apiCreateOrder(ApiSubmitOrderBo bo) {
|
|
|
+ try {
|
|
|
+ // 构造 OrderMainBo 对象
|
|
|
+ OrderMainBo mainBo = new OrderMainBo();
|
|
|
+
|
|
|
+ // API订单不需要绑定customerId、userId、contactId
|
|
|
+ mainBo.setCustomerId(null);
|
|
|
+ mainBo.setUserId(null);
|
|
|
+ mainBo.setContactId(null);
|
|
|
+
|
|
|
+ mainBo.setShippingAddressId(bo.getShippingAddressId());
|
|
|
+ mainBo.setPurchaseReason(bo.getPurchaseReason());
|
|
|
+ mainBo.setRemark(bo.getRemark());
|
|
|
+ mainBo.setExpenseType(bo.getExpenseType());
|
|
|
+ mainBo.setShippingFee(bo.getShippingFee() != null ? bo.getShippingFee() : BigDecimal.ZERO);
|
|
|
+
|
|
|
+ // 设置订单来源为API
|
|
|
+ mainBo.setOrderSource(bo.getOrderSource() != null ? bo.getOrderSource() : "API");
|
|
|
+
|
|
|
+ // 解析配送时间
|
|
|
+ if (bo.getDeliveryDate() != null && !bo.getDeliveryDate().isEmpty()) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ LocalDate deliveryLocalDate = LocalDate.parse(bo.getDeliveryDate(), formatter);
|
|
|
+ Date expectedDeliveryTime = Date.from(deliveryLocalDate.atStartOfDay().toInstant(java.time.ZoneOffset.UTC));
|
|
|
+ mainBo.setExpectedDeliveryTime(expectedDeliveryTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置仓库(假设默认仓库)
|
|
|
+ mainBo.setWarehouseId(1L); // TODO: 后续可配置或根据客户动态获取
|
|
|
+
|
|
|
+ // 设置订单状态为待支付
|
|
|
+ mainBo.setOrderStatus(OrderStatus.PENDING_PAYMENT.getCode());
|
|
|
+
|
|
|
+ // 设置审核状态为待审核
|
|
|
+ mainBo.setCheckStatus("0");
|
|
|
+
|
|
|
+
|
|
|
+ mainBo.setOrderStatuses(OrderSourceEnum.Api_ADD.getCode());
|
|
|
+
|
|
|
+ mainBo.setOrderNoPrefix("Po");
|
|
|
+
|
|
|
+
|
|
|
+ // 处理商品信息
|
|
|
+ if (bo.getProductInfo() == null || bo.getProductInfo().isEmpty()) {
|
|
|
+ throw new IllegalArgumentException("商品信息不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建 productId -> productNum 映射
|
|
|
+ Map<Long, Long> productNumMap = bo.getProductInfo().stream()
|
|
|
+ .filter(item -> item.getProductId() != null && item.getProductNum() != null)
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ ApiSubmitOrderBo.PcOrderProduct::getProductId,
|
|
|
+ ApiSubmitOrderBo.PcOrderProduct::getProductNum,
|
|
|
+ (existing, replacement) -> existing // 防止重复 key 冲突
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 提取所有商品 ID
|
|
|
+ List<Long> productIds = new ArrayList<>(productNumMap.keySet());
|
|
|
+
|
|
|
+ // 获取商品详情
|
|
|
+ List<ProductVo> productDetails = remoteProductService.getProductDetails(productIds);
|
|
|
+
|
|
|
+ // 构建订单商品列表
|
|
|
+ List<OrderProductBo> orderProductBos = productDetails.stream()
|
|
|
+ .map(productVo -> {
|
|
|
+ Long productId = productVo.getId();
|
|
|
+ Long quantity = productNumMap.get(productId);
|
|
|
+ if (quantity == null) {
|
|
|
+ // 理论上不会发生,但防御性处理
|
|
|
+ log.warn("商品 {} 在请求中无数量信息,跳过", productId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderProductBo orderProductBo = new OrderProductBo();
|
|
|
+ orderProductBo.setProductId(productId);
|
|
|
+ orderProductBo.setProductNo(productVo.getProductNo());
|
|
|
+ orderProductBo.setProductName(productVo.getItemName());
|
|
|
+ orderProductBo.setProductUnitId(Long.valueOf(productVo.getUnitId()));
|
|
|
+ orderProductBo.setProductUnit(productVo.getUnitName());
|
|
|
+ orderProductBo.setProductImage(productVo.getProductImage());
|
|
|
+ orderProductBo.setOrderPrice(productVo.getMemberPrice());
|
|
|
+ orderProductBo.setMarketPrice(productVo.getMarketPrice());
|
|
|
+ orderProductBo.setTaxRate(productVo.getTaxRate());
|
|
|
+ orderProductBo.setCategoryName(productVo.getCategoryName());
|
|
|
+ orderProductBo.setPurchasingPrice(productVo.getPurchasingPrice());
|
|
|
+ orderProductBo.setMinOrderQuantity(productVo.getMinOrderQuantity());
|
|
|
+ orderProductBo.setMinSellingPrice(productVo.getMinSellingPrice());
|
|
|
+ orderProductBo.setOrderQuantity(quantity);
|
|
|
+ orderProductBo.setSubtotal(productVo.getMemberPrice().multiply(BigDecimal.valueOf(quantity)));
|
|
|
+ return orderProductBo;
|
|
|
+ })
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (orderProductBos.isEmpty()) {
|
|
|
+ throw new IllegalStateException("无可下单的商品");
|
|
|
+ }
|
|
|
+
|
|
|
+ mainBo.setOrderProductBos(orderProductBos);
|
|
|
+
|
|
|
+ // 保存订单
|
|
|
+ Long orderId = this.insertByBo(mainBo);
|
|
|
+
|
|
|
+ // 初始化审批流程(由于没有contactId,可能需要特殊处理)
|
|
|
+ Boolean initOrderFlow = orderCustomerFlowService.initOrderFlow(orderId, null);
|
|
|
+
|
|
|
+ // 如果流程初始化成功,更新订单状态
|
|
|
+ if (initOrderFlow) {
|
|
|
+ log.info("成功初始化API订单审批流程,订单ID: {}", orderId);
|
|
|
+ this.update(Wrappers.lambdaUpdate(OrderMain.class)
|
|
|
+ .eq(OrderMain::getId, orderId)
|
|
|
+ .set(OrderMain::getOrderStatus, 1) // 假设 1 代表某种特定状态,需确认枚举值
|
|
|
+ .set(OrderMain::getIsNeedCheck, SysPlatformYesNo.YES.getCode())
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ log.info("失败初始化API订单审批流程,订单ID: {}", orderId);
|
|
|
+ this.update(Wrappers.lambdaUpdate(OrderMain.class)
|
|
|
+ .eq(OrderMain::getId, orderId)
|
|
|
+ .set(OrderMain::getCheckStatus, "1")
|
|
|
+ .set(OrderMain::getIsNeedCheck, SysPlatformYesNo.NO.getCode())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ return orderId;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("API端提交订单失败", e);
|
|
|
+ throw new RuntimeException("API下单失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据订单号查询订单详情(API专用)
|
|
|
+ * 不绑定customerId、userId,直接根据orderNo查询
|
|
|
+ *
|
|
|
+ * @param orderNo 订单编号
|
|
|
+ * @return 订单详情
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public OrderMainVo queryByOrderNo(String orderNo) {
|
|
|
+ if (StringUtils.isBlank(orderNo)) {
|
|
|
+ throw new IllegalArgumentException("订单号不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 根据订单号查询主订单
|
|
|
+ OrderMainVo orderMainVo = baseMapper.selectVoOne(new LambdaQueryWrapper<OrderMain>()
|
|
|
+ .eq(OrderMain::getOrderNo, orderNo)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (orderMainVo == null) {
|
|
|
+ log.warn("订单号 {} 不存在", orderNo);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 查询关联的商品列表--并且查询商品已发货数量与未发货数量
|
|
|
+ List<OrderProductVo> orderProductVoList = orderProductMapper.selectProductsWithDelivered(orderMainVo.getId());
|
|
|
+ if (orderProductVoList != null && !orderProductVoList.isEmpty()) {
|
|
|
+ // 收集所有需要处理的 childOrderId (去重)
|
|
|
+ List<Long> childOrderIds = orderProductVoList.stream()
|
|
|
+ .map(OrderProductVo::getAssignedChildOrderId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!childOrderIds.isEmpty()) {
|
|
|
+ // 批量查询子订单信息 (避免 N+1 数据库查询)
|
|
|
+ List<OrderMainVo> childOrderList = baseMapper.selectVoByIds(childOrderIds);
|
|
|
+
|
|
|
+ // 将子订单放入 Map 方便快速查找: Key = childOrderId, Value = OrderMainVo
|
|
|
+ Map<Long, OrderMainVo> childOrderMap = childOrderList.stream()
|
|
|
+ .collect(Collectors.toMap(OrderMainVo::getId, Function.identity(), (k1, k2) -> k1));
|
|
|
+
|
|
|
+ // 按分配类型分组收集 ID,准备批量调用远程服务
|
|
|
+ List<Long> customerIds = new ArrayList<>();
|
|
|
+ List<Long> supplierIds = new ArrayList<>();
|
|
|
+ List<Long> partnerIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (OrderMainVo childOrder : childOrderList) {
|
|
|
+ if (childOrder.getAssigneeId() == null) continue;
|
|
|
+
|
|
|
+ String type = childOrder.getAssigneeType();
|
|
|
+ if (AssigneeTypeConstants.CUSTOMER.getCode().equals(type)) {
|
|
|
+ customerIds.add(childOrder.getAssigneeId());
|
|
|
+ } else if (AssigneeTypeConstants.SUPPLIER.getCode().equals(type)) {
|
|
|
+ supplierIds.add(childOrder.getAssigneeId());
|
|
|
+ } else if (AssigneeTypeConstants.PARTNER.getCode().equals(type)) {
|
|
|
+ partnerIds.add(childOrder.getAssigneeId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量调用远程服务 (每种类型只调用一次)
|
|
|
+ Map<Long, String> customerNameMap = Collections.emptyMap();
|
|
|
+ Map<Long, String> supplierNameMap = Collections.emptyMap();
|
|
|
+ Map<Long, String> partnerNameMap = Collections.emptyMap();
|
|
|
+
|
|
|
+ if (!customerIds.isEmpty()) {
|
|
|
+ customerNameMap = remoteCustomerService.selectCustomerNameByIds(new HashSet<>(customerIds));
|
|
|
+ }
|
|
|
+ if (!supplierIds.isEmpty()) {
|
|
|
+ supplierNameMap = remoteSupplierInfoService.selectSupplierNameByIds(new HashSet<>(supplierIds));
|
|
|
+ }
|
|
|
+ if (!partnerIds.isEmpty()) {
|
|
|
+ partnerNameMap = remotePartnerInfoService.selectPartnerNameByIds(new HashSet<>(partnerIds));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 内存组装数据
|
|
|
+ for (OrderProductVo productVo : orderProductVoList) {
|
|
|
+ Long childOrderId = productVo.getAssignedChildOrderId();
|
|
|
+ if (childOrderId != null) {
|
|
|
+ OrderMainVo childOrder = childOrderMap.get(childOrderId);
|
|
|
+ if (childOrder != null && childOrder.getAssigneeId() != null) {
|
|
|
+ String assigneeName = null;
|
|
|
+ String type = childOrder.getAssigneeType();
|
|
|
+
|
|
|
+ if (AssigneeTypeConstants.CUSTOMER.getCode().equals(type)) {
|
|
|
+ assigneeName = customerNameMap.get(childOrder.getAssigneeId());
|
|
|
+ } else if (AssigneeTypeConstants.SUPPLIER.getCode().equals(type)) {
|
|
|
+ assigneeName = supplierNameMap.get(childOrder.getAssigneeId());
|
|
|
+ } else if (AssigneeTypeConstants.PARTNER.getCode().equals(type)) {
|
|
|
+ assigneeName = partnerNameMap.get(childOrder.getAssigneeId());
|
|
|
+ }
|
|
|
+ productVo.setAssigneeName(assigneeName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 组装数据
|
|
|
+ orderMainVo.setOrderProductList(orderProductVoList);
|
|
|
+
|
|
|
+ // 如果有关联的客户,查询客户名称
|
|
|
+ if (orderMainVo.getCustomerId() != null) {
|
|
|
+ Set<Long> customerIds = new HashSet<>();
|
|
|
+ customerIds.add(orderMainVo.getCustomerId());
|
|
|
+ Map<Long, String> map = remoteCustomerService.selectCustomerNameByIds(customerIds);
|
|
|
+ orderMainVo.setCustomerName(map.get(orderMainVo.getCustomerId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询发货商品列表
|
|
|
+ orderMainVo.setDeliverProductList(
|
|
|
+ orderDeliverProductMapper.selectDeliverProductsByOrderId(orderMainVo.getId())
|
|
|
+ );
|
|
|
+
|
|
|
+ // 查询主订单原始商品的总行数与已分配行数
|
|
|
+ AssignmentStatsDto stats = orderProductMapper.getAssignmentStats(orderMainVo.getId());
|
|
|
+ Long total = stats.getTotal();
|
|
|
+ Long assigned = stats.getAssigned();
|
|
|
+
|
|
|
+ orderMainVo.setProductTotal(total);
|
|
|
+ orderMainVo.setUnassigned(total - assigned);
|
|
|
+ orderMainVo.setAssigned(assigned);
|
|
|
+
|
|
|
+ log.info("成功查询订单详情,订单号: {}", orderNo);
|
|
|
+ return orderMainVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int apiCancelOrder(Long orderId, String orderNo) {
|
|
|
+ if (orderId == null && orderNo == null) {
|
|
|
+ throw new IllegalArgumentException("订单ID和订单号不能同时为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<OrderMain> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+
|
|
|
+ // 设置取消状态
|
|
|
+ updateWrapper.set(OrderMain::getOrderStatus, OrderStatus.CANCEL.getCode());
|
|
|
+
|
|
|
+ // 设置更新时间
|
|
|
+ updateWrapper.set(OrderMain::getUpdateTime, new Date());
|
|
|
+
|
|
|
+ // 根据orderId或orderNo进行更新
|
|
|
+ if (orderId != null) {
|
|
|
+ updateWrapper.eq(OrderMain::getId, orderId);
|
|
|
+ } else {
|
|
|
+ updateWrapper.eq(OrderMain::getOrderNo, orderNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 只有特定状态的订单可以取消
|
|
|
+ updateWrapper.in(OrderMain::getOrderStatus,
|
|
|
+ OrderStatus.PENDING_PAYMENT.getCode(),
|
|
|
+ OrderStatus.PENDING_CONFIRMATION.getCode(),
|
|
|
+ OrderStatus.PENDING_SHIPMENT.getCode());
|
|
|
+
|
|
|
+ int result = baseMapper.update(updateWrapper);
|
|
|
+
|
|
|
+ if (result > 0) {
|
|
|
+ log.info("API成功取消订单,订单ID: {},订单号: {}", orderId, orderNo);
|
|
|
+ } else {
|
|
|
+ log.warn("API取消订单失败,订单可能不存在或状态不允许取消,订单ID: {},订单号: {}", orderId, orderNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean apiConfirmReceipt(Long orderId, String orderNo) {
|
|
|
+ if (orderId == null && orderNo == null) {
|
|
|
+ throw new IllegalArgumentException("订单ID和订单号不能同时为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构造更新条件
|
|
|
+ LambdaUpdateWrapper<OrderMain> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+
|
|
|
+ // 设置更新后的值为已完成
|
|
|
+ updateWrapper.set(OrderMain::getOrderStatus, OrderStatus.COMPLETED.getCode());
|
|
|
+
|
|
|
+ // 设置收货时间
|
|
|
+ updateWrapper.set(OrderMain::getReceivingTime, new Date());
|
|
|
+
|
|
|
+ // 设置更新时间
|
|
|
+ updateWrapper.set(OrderMain::getUpdateTime, new Date());
|
|
|
+
|
|
|
+ // 根据orderId或orderNo进行更新
|
|
|
+ if (orderId != null) {
|
|
|
+ updateWrapper.and(wrapper -> wrapper
|
|
|
+ .eq(OrderMain::getId, orderId)
|
|
|
+ .or()
|
|
|
+ .eq(OrderMain::getParentOrderId, orderId)
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ // 如果通过订单号查询,先获取订单ID
|
|
|
+ OrderMain orderMain = baseMapper.selectOne(new LambdaQueryWrapper<OrderMain>()
|
|
|
+ .eq(OrderMain::getOrderNo, orderNo)
|
|
|
+ .select(OrderMain::getId)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (orderMain == null) {
|
|
|
+ log.warn("API确认收货失败,订单号 {} 不存在", orderNo);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long id = orderMain.getId();
|
|
|
+ updateWrapper.and(wrapper -> wrapper
|
|
|
+ .eq(OrderMain::getId, id)
|
|
|
+ .or()
|
|
|
+ .eq(OrderMain::getParentOrderId, id)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 只有已发货的订单才能确认收货
|
|
|
+ updateWrapper.eq(OrderMain::getOrderStatus, OrderStatus.SHIPPED.getCode());
|
|
|
+
|
|
|
+ // 执行更新
|
|
|
+ int updateCount = baseMapper.update(updateWrapper);
|
|
|
+
|
|
|
+ boolean success = updateCount > 0;
|
|
|
+
|
|
|
+ if (success) {
|
|
|
+ log.info("API成功确认收货,订单ID: {},订单号: {}", orderId, orderNo);
|
|
|
+ } else {
|
|
|
+ log.warn("API确认收货失败,订单可能不存在或状态不允许确认收货,订单ID: {},订单号: {}", orderId, orderNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return success;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void apiConfirmOrder(Long orderId, String orderNo) {
|
|
|
+ if (orderId == null && orderNo == null) {
|
|
|
+ throw new IllegalArgumentException("订单ID和订单号不能同时为空");
|
|
|
+ }
|
|
|
+ // 构造更新条件
|
|
|
+ LambdaUpdateWrapper<OrderMain> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+
|
|
|
+ // 设置更新后的值为已完成
|
|
|
+ updateWrapper.set(OrderMain::getOrderStatus, OrderStatus.PENDING_SHIPMENT.getCode());
|
|
|
+
|
|
|
+ // 设置更新时间
|
|
|
+ updateWrapper.set(OrderMain::getUpdateTime, new Date());
|
|
|
+
|
|
|
+ // 根据orderId或orderNo进行更新
|
|
|
+ if (orderId != null) {
|
|
|
+ updateWrapper.and(wrapper -> wrapper
|
|
|
+ .eq(OrderMain::getId, orderId)
|
|
|
+ .or()
|
|
|
+ .eq(OrderMain::getParentOrderId, orderId)
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ // 如果通过订单号查询,先获取订单ID
|
|
|
+ OrderMain orderMain = baseMapper.selectOne(new LambdaQueryWrapper<OrderMain>()
|
|
|
+ .eq(OrderMain::getOrderNo, orderNo)
|
|
|
+ .select(OrderMain::getId)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (orderMain == null) {
|
|
|
+ log.warn("API确认收货失败,订单号 {} 不存在", orderNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long id = orderMain.getId();
|
|
|
+ updateWrapper.and(wrapper -> wrapper
|
|
|
+ .eq(OrderMain::getId, id)
|
|
|
+ .or()
|
|
|
+ .eq(OrderMain::getParentOrderId, id)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // 执行更新
|
|
|
+ int updateCount = baseMapper.update(updateWrapper);
|
|
|
+
|
|
|
+ boolean success = updateCount > 0;
|
|
|
+
|
|
|
+ if (success) {
|
|
|
+ log.info("API订单确认成功,订单ID: {},订单号: {}", orderId, orderNo);
|
|
|
+ } else {
|
|
|
+ log.warn("API订单确认失败,订单可能不存在,订单ID: {},订单号: {}", orderId, orderNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|