!31 fix(订单中心):事件处理逻辑问题优化修复
Merge pull request !31 from Iamasoldier/feature_lsl
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
-- 为 t_ctrip_order 表添加 order_no 字段,用于关联订单中心的订单号
|
||||
-- 这样核销成功后可以通过这个关联关系更新订单状态
|
||||
|
||||
ALTER TABLE `t_ctrip_order`
|
||||
ADD COLUMN `order_no` varchar(50) DEFAULT NULL COMMENT '关联的订单中心订单号' AFTER `ota_order_id`;
|
||||
|
||||
-- 添加索引以提高查询性能
|
||||
ALTER TABLE `t_ctrip_order`
|
||||
ADD INDEX `idx_order_no` (`order_no`);
|
||||
|
||||
-- 添加唯一索引确保一个订单号只能关联一个携程订单
|
||||
ALTER TABLE `t_ctrip_order`
|
||||
ADD UNIQUE INDEX `uk_order_no` (`order_no`);
|
||||
+6
-2
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -32,6 +33,9 @@ public class CtripPayPreOrderConfirmController {
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Value("${ctrip.account.id}")
|
||||
private String ctripAccountId;
|
||||
|
||||
/**
|
||||
* 处理支付确认请求
|
||||
*/
|
||||
@@ -137,7 +141,7 @@ public class CtripPayPreOrderConfirmController {
|
||||
|
||||
// 构建header
|
||||
CtripPayPreOrderConfirmRequest.CtripHeader header = new CtripPayPreOrderConfirmRequest.CtripHeader();
|
||||
header.setAccountId("c50a8f2a4a59c9e7");
|
||||
header.setAccountId(ctripAccountId);
|
||||
header.setServiceName("PayPreOrderConfirm");
|
||||
header.setRequestTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
header.setVersion("1.0");
|
||||
@@ -170,7 +174,7 @@ public class CtripPayPreOrderConfirmController {
|
||||
@PostMapping("/buildPayload")
|
||||
public Map<String, Object> buildEncryptedSignedPayload(@RequestBody Map<String, Object> payload) {
|
||||
try {
|
||||
String accountId = (String) payload.getOrDefault("accountId", "c50a8f2a4a59c9e7");
|
||||
String accountId = (String) payload.getOrDefault("accountId", ctripAccountId);
|
||||
String version = (String) payload.getOrDefault("version", "1.0");
|
||||
String requestTime = (String) payload.getOrDefault(
|
||||
"requestTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
+2
-2
@@ -34,8 +34,8 @@ public class CtripQueryOrderController {
|
||||
@Autowired
|
||||
private CtripDecryptUtil ctripDecryptUtil;
|
||||
|
||||
// 携程SDK配置参数
|
||||
@Value("${ctrip.account.id:c50a8f2a4a59c9e7}")
|
||||
// 携程SDK配置参数(保持兼容但不使用硬编码默认值)
|
||||
@Value("${ctrip.account.id}")
|
||||
private String ctripAccountId;
|
||||
|
||||
@Value("${ctrip.aes.key:750e15a31356a99d}")
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ public class CtripRefundOrderController {
|
||||
private CtripDecryptUtil ctripDecryptUtil;
|
||||
|
||||
// 携程SDK配置参数
|
||||
@Value("${ctrip.account.id:c50a8f2a4a59c9e7}")
|
||||
@Value("${ctrip.account.id}")
|
||||
private String ctripAccountId;
|
||||
|
||||
@Value("${ctrip.aes.key:750e15a31356a99d}")
|
||||
|
||||
+20
-3
@@ -147,8 +147,8 @@ public class OrderDetailController {
|
||||
*/
|
||||
@PostMapping("/consume-simple")
|
||||
public Result<Boolean> consumeOrderSimple(@Valid @RequestBody SimpleConsumeDTO consumeDTO) {
|
||||
log.info("简化核销订单,订单号: {}, 商品ID: {}, 数量: {}",
|
||||
consumeDTO.getOtaOrderId(), consumeDTO.getItemId(), consumeDTO.getUseQuantity());
|
||||
log.info("简化核销订单,订单号: {}, 商品ID: {}, 数量: {}, 关联订单号: {}",
|
||||
consumeDTO.getOtaOrderId(), consumeDTO.getItemId(), consumeDTO.getUseQuantity(), consumeDTO.getOrderNo());
|
||||
|
||||
try {
|
||||
// 1. 验证订单是否存在
|
||||
@@ -164,7 +164,21 @@ public class OrderDetailController {
|
||||
return Result.failed("订单不可核销");
|
||||
}
|
||||
|
||||
// 3. 调用携程核销服务
|
||||
// 3. 建立订单关联关系(如果前端传入了orderNo)
|
||||
if (consumeDTO.getOrderNo() != null && !consumeDTO.getOrderNo().trim().isEmpty()) {
|
||||
if (order.getOrderNo() == null || order.getOrderNo().trim().isEmpty()) {
|
||||
// 更新携程订单的orderNo字段
|
||||
order.setOrderNo(consumeDTO.getOrderNo());
|
||||
ctripOrderMapper.updateById(order);
|
||||
log.info("建立订单关联关系,otaOrderId: {}, orderNo: {}",
|
||||
consumeDTO.getOtaOrderId(), consumeDTO.getOrderNo());
|
||||
} else if (!order.getOrderNo().equals(consumeDTO.getOrderNo())) {
|
||||
log.warn("订单关联关系不匹配,数据库orderNo: {}, 前端orderNo: {}",
|
||||
order.getOrderNo(), consumeDTO.getOrderNo());
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 调用携程核销服务
|
||||
CtripConsumedController.CtripConsumeRequest request = new CtripConsumedController.CtripConsumeRequest();
|
||||
request.setOtaOrderId(consumeDTO.getOtaOrderId());
|
||||
request.setSupplierOrderId(order.getSupplierOrderId());
|
||||
@@ -176,8 +190,11 @@ public class OrderDetailController {
|
||||
boolean success = response != null && "0000".equals(response.getHeader().getResultCode());
|
||||
|
||||
if (success) {
|
||||
log.info("核销成功,订单号: {}, 关联订单号: {}", consumeDTO.getOtaOrderId(), order.getOrderNo());
|
||||
return Result.succeed(true, "核销成功");
|
||||
} else {
|
||||
log.error("核销失败,订单号: {}, 错误信息: {}", consumeDTO.getOtaOrderId(),
|
||||
response != null ? response.getHeader().getResultMessage() : "未知错误");
|
||||
return Result.failed("核销失败: " + (response != null ? response.getHeader().getResultMessage() : "未知错误"));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ public class SimpleConsumeDTO {
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 关联的订单中心订单号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
|
||||
@@ -33,6 +33,11 @@ public class CtripOrder implements Serializable {
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 关联的订单中心订单号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 供应商订单号
|
||||
*/
|
||||
|
||||
+15
@@ -3,12 +3,27 @@ package com.central.coupon.feign;
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.coupon.feign.dto.QrCodeInfo;
|
||||
import com.central.coupon.feign.dto.OrderInfo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, dismiss404 = true)
|
||||
public interface OrderCenterService {
|
||||
@GetMapping("/qrcode/{codeId}")
|
||||
Result<QrCodeInfo> getQrCode(@PathVariable("codeId") String codeId);
|
||||
|
||||
/**
|
||||
* 根据订单号获取订单信息
|
||||
*/
|
||||
@GetMapping("/order/{orderNo}")
|
||||
Result<OrderInfo> getOrderByOrderNo(@PathVariable("orderNo") String orderNo);
|
||||
|
||||
/**
|
||||
* 更新订单状态为已支付(优惠券核销成功后调用)
|
||||
*/
|
||||
@PostMapping("/order/{orderNo}/status/paid")
|
||||
Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.central.coupon.feign;
|
||||
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.coupon.feign.dto.SysUserDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
@FeignClient(name = ServiceNameConstants.USER_SERVICE, dismiss404 = true)
|
||||
public interface UserCenterService {
|
||||
@GetMapping("/users/{id}")
|
||||
SysUserDTO findUserById(@PathVariable("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.central.coupon.feign.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 订单信息DTO
|
||||
*/
|
||||
@Data
|
||||
public class OrderInfo {
|
||||
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 景区ID
|
||||
*/
|
||||
private Long tourismId;
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
private String orderAmount;
|
||||
|
||||
/**
|
||||
* 订单状态
|
||||
*/
|
||||
private Integer orderStatus;
|
||||
|
||||
/**
|
||||
* 支付类型(1:微信支付,2:优惠券支付)
|
||||
*/
|
||||
private Integer payType;
|
||||
|
||||
/**
|
||||
* 支付时间
|
||||
*/
|
||||
private LocalDateTime payTime;
|
||||
|
||||
/**
|
||||
* 二维码ID
|
||||
*/
|
||||
private String codeId;
|
||||
|
||||
/**
|
||||
* 设备SN
|
||||
*/
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.central.coupon.feign.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SysUserDTO {
|
||||
private Long id;
|
||||
private String mobile;
|
||||
}
|
||||
+10
@@ -19,6 +19,16 @@ public interface CtripOrderMapper extends BaseMapper<CtripOrder> {
|
||||
*/
|
||||
CtripOrder selectByOtaOrderId(@Param("otaOrderId") String otaOrderId);
|
||||
|
||||
/**
|
||||
* 根据订单中心订单号查询携程订单
|
||||
*/
|
||||
CtripOrder selectByOrderNo(@Param("orderNo") String orderNo);
|
||||
|
||||
/**
|
||||
* 根据携程订单号更新订单
|
||||
*/
|
||||
int updateByOtaOrderId(CtripOrder order);
|
||||
|
||||
/**
|
||||
* 根据供应商订单号查询订单
|
||||
*
|
||||
|
||||
+5
-1
@@ -24,6 +24,7 @@ import java.util.Date;
|
||||
import com.central.coupon.enums.CtripOrderStatus;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import com.central.coupon.config.CtripApiConfig;
|
||||
|
||||
/**
|
||||
* 携程取消订单服务实现
|
||||
@@ -48,6 +49,9 @@ public class CtripCancelOrderServiceImpl implements CtripCancelOrderService {
|
||||
@Autowired
|
||||
private CtripDecryptUtil ctripDecryptUtil;
|
||||
|
||||
@Autowired
|
||||
private CtripApiConfig ctripApiConfig;
|
||||
|
||||
@Override
|
||||
public CtripCancelOrderResponse cancelOrder(CtripCancelOrderRequest request, HttpServletRequest httpRequest) {
|
||||
log.info("开始处理携程取消订单请求,serviceName: {}", request.getHeader().getServiceName());
|
||||
@@ -139,7 +143,7 @@ public class CtripCancelOrderServiceImpl implements CtripCancelOrderService {
|
||||
*/
|
||||
private boolean isValidAccountId(String accountId) {
|
||||
// 从配置中获取有效的accountId
|
||||
String validAccountId = "c50a8f2a4a59c9e7"; // 应该从配置中读取
|
||||
String validAccountId = ctripApiConfig.getAccount().getId();
|
||||
|
||||
boolean isValid = validAccountId.equals(accountId);
|
||||
log.info("accountId验证结果: {}, 请求accountId: {}, 有效accountId: {}",
|
||||
|
||||
+41
-15
@@ -2,7 +2,9 @@ package com.central.coupon.service.impl;
|
||||
|
||||
import com.central.coupon.entity.CtripConsumed;
|
||||
import com.central.coupon.entity.CtripOrder;
|
||||
import com.central.coupon.entity.CtripOrderItem;
|
||||
import com.central.coupon.mapper.CtripConsumedMapper;
|
||||
import com.central.coupon.mapper.CtripOrderItemMapper;
|
||||
import com.central.coupon.mapper.CtripOrderMapper;
|
||||
import com.central.coupon.model.CtripConsumedNoticeRequest;
|
||||
import com.central.coupon.model.CtripConsumedNoticeResponse;
|
||||
@@ -16,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 携程核销优惠券通知接口Service实现类
|
||||
@@ -30,6 +33,9 @@ public class CtripConsumedNoticeServiceImpl implements CtripConsumedNoticeServic
|
||||
@Autowired
|
||||
private CtripOrderMapper ctripOrderMapper;
|
||||
|
||||
@Autowired
|
||||
private CtripOrderItemMapper ctripOrderItemMapper;
|
||||
|
||||
@Autowired
|
||||
private CtripConsumedMapper ctripConsumedMapper;
|
||||
|
||||
@@ -231,25 +237,45 @@ public class CtripConsumedNoticeServiceImpl implements CtripConsumedNoticeServic
|
||||
*/
|
||||
private void updateOrderStatus(CtripOrder order) {
|
||||
try {
|
||||
// 查询该订单的所有核销记录
|
||||
List<CtripConsumed> consumedList = ctripConsumedMapper.selectByOtaOrderId(order.getOtaOrderId());
|
||||
|
||||
// 计算总使用数量
|
||||
int totalUseQuantity = consumedList.stream()
|
||||
.mapToInt(c -> c.getUseQuantity() != null ? c.getUseQuantity() : 0)
|
||||
.sum();
|
||||
|
||||
// 如果使用数量大于0,更新订单状态为已使用(状态8)
|
||||
if (totalUseQuantity > 0) {
|
||||
order.setStatus(8); // 已使用状态
|
||||
// 查询订单项
|
||||
List<CtripOrderItem> orderItems = ctripOrderItemMapper.selectByOrderId(order.getId());
|
||||
if (orderItems == null || orderItems.isEmpty()) {
|
||||
log.warn("订单无订单项,无法根据份数判断使用状态,保持原状态,otaOrderId: {}", order.getOtaOrderId());
|
||||
return;
|
||||
}
|
||||
|
||||
boolean allFullyUsed = true;
|
||||
boolean anyUsed = false;
|
||||
|
||||
for (CtripOrderItem item : orderItems) {
|
||||
List<CtripConsumed> consumedRecords = ctripConsumedMapper.selectByItemId(item.getItemId());
|
||||
int used = consumedRecords.stream()
|
||||
.map(CtripConsumed::getUseQuantity)
|
||||
.filter(Objects::nonNull)
|
||||
.mapToInt(Integer::intValue)
|
||||
.sum();
|
||||
int qty = item.getQuantity() != null ? item.getQuantity() : 0;
|
||||
|
||||
if (used > 0) anyUsed = true;
|
||||
if (used < qty) allFullyUsed = false;
|
||||
|
||||
log.debug("订单 {} 明细 itemId={} 已用/总量: {}/{}", order.getOtaOrderId(), item.getItemId(), used, qty);
|
||||
}
|
||||
|
||||
if (allFullyUsed && anyUsed) {
|
||||
order.setStatus(8);
|
||||
ctripOrderMapper.updateById(order);
|
||||
log.info("订单状态更新为已使用,otaOrderId: {}, totalUseQuantity: {}",
|
||||
order.getOtaOrderId(), totalUseQuantity);
|
||||
log.info("订单状态更新为全部使用(8),otaOrderId: {}", order.getOtaOrderId());
|
||||
} else if (anyUsed) {
|
||||
order.setStatus(7);
|
||||
ctripOrderMapper.updateById(order);
|
||||
log.info("订单状态更新为部分使用(7),otaOrderId: {}", order.getOtaOrderId());
|
||||
} else {
|
||||
log.info("订单尚未发生使用变化,保持原状态,otaOrderId: {}", order.getOtaOrderId());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单状态异常", e);
|
||||
// 不抛出异常,避免影响核销记录保存
|
||||
// 不抛异常,避免影响通知处理
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+142
-16
@@ -5,11 +5,15 @@ import com.central.coupon.controller.CtripConsumedController.CtripConsumeRequest
|
||||
import com.central.coupon.controller.CtripConsumedController.CtripConsumeBatchRequest;
|
||||
import com.central.coupon.entity.CtripConsumed;
|
||||
import com.central.coupon.entity.CtripOrder;
|
||||
import com.central.coupon.entity.CtripOrderItem;
|
||||
import com.central.coupon.mapper.CtripConsumedMapper;
|
||||
import com.central.coupon.mapper.CtripOrderMapper;
|
||||
import com.central.coupon.mapper.CtripOrderItemMapper;
|
||||
import com.central.coupon.model.CtripConsumedNoticeResponse;
|
||||
import com.central.coupon.service.CtripConsumedService;
|
||||
import com.central.coupon.feign.OrderCenterService;
|
||||
import com.central.coupon.util.CtripDecryptUtil;
|
||||
import com.central.common.model.Result;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -35,6 +39,9 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
||||
@Autowired
|
||||
private CtripConsumedMapper ctripConsumedMapper;
|
||||
|
||||
@Autowired
|
||||
private CtripOrderItemMapper ctripOrderItemMapper;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@@ -44,6 +51,9 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
||||
@Autowired
|
||||
private CtripApiConfig ctripApiConfig;
|
||||
|
||||
@Autowired
|
||||
private OrderCenterService orderCenterService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CtripConsumedNoticeResponse consumeOrder(CtripConsumeRequest request) {
|
||||
@@ -67,7 +77,35 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
||||
// 3. 生成序列号
|
||||
String sequenceId = generateSequenceId();
|
||||
|
||||
// 4. 保存核销记录到本地数据库
|
||||
// 4.1 校验单个item的剩余可核销数量,防止超量核销
|
||||
List<CtripOrderItem> orderItems = ctripOrderItemMapper.selectByOrderId(order.getId());
|
||||
CtripOrderItem matchedItem = null;
|
||||
if (orderItems != null) {
|
||||
for (CtripOrderItem it : orderItems) {
|
||||
if (it.getItemId() != null && it.getItemId().equals(request.getItemId())) {
|
||||
matchedItem = it; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matchedItem == null) {
|
||||
log.error("未找到匹配的订单项,otaOrderId: {}, itemId: {}", request.getOtaOrderId(), request.getItemId());
|
||||
return buildErrorResponse("4002", "未找到匹配的订单项");
|
||||
}
|
||||
|
||||
// 直接使用订单项表中的当前数量,因为核销后数量已经被更新
|
||||
int currentQuantity = matchedItem.getQuantity() != null ? matchedItem.getQuantity() : 0;
|
||||
log.info("订单项当前数量: {}, 请求核销数量: {}", currentQuantity, request.getUseQuantity());
|
||||
|
||||
if (request.getUseQuantity() == null || request.getUseQuantity() <= 0) {
|
||||
return buildErrorResponse("0001", "使用数量必须大于0");
|
||||
}
|
||||
if (request.getUseQuantity() > currentQuantity) {
|
||||
log.warn("核销使用数量超出当前可用数量,otaOrderId: {}, itemId: {}, requestUse: {}, currentQuantity: {}",
|
||||
request.getOtaOrderId(), request.getItemId(), request.getUseQuantity(), currentQuantity);
|
||||
return buildErrorResponse("4003", "使用数量超过剩余可核销数量");
|
||||
}
|
||||
|
||||
// 4.2 保存核销记录到本地数据库
|
||||
saveConsumedRecord(request, sequenceId);
|
||||
|
||||
// 5. 更新订单状态
|
||||
@@ -236,6 +274,40 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
||||
|
||||
ctripConsumedMapper.insert(consumed);
|
||||
log.info("核销记录保存成功,sequenceId: {}", sequenceId);
|
||||
|
||||
// 更新订单项表中的数量(减去已使用的数量)
|
||||
updateOrderItemQuantity(request.getItemId(), useQuantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单项表中的数量
|
||||
*/
|
||||
private void updateOrderItemQuantity(String itemId, Integer useQuantity) {
|
||||
try {
|
||||
// 查询订单项
|
||||
CtripOrderItem orderItem = ctripOrderItemMapper.selectByItemId(itemId);
|
||||
if (orderItem == null) {
|
||||
log.warn("未找到对应的订单项,itemId: {}", itemId);
|
||||
return;
|
||||
}
|
||||
|
||||
Integer currentQuantity = orderItem.getQuantity();
|
||||
if (currentQuantity == null || currentQuantity <= 0) {
|
||||
log.warn("订单项数量无效,itemId: {}, currentQuantity: {}", itemId, currentQuantity);
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算新的数量(当前数量减去使用数量)
|
||||
int newQuantity = Math.max(0, currentQuantity - useQuantity);
|
||||
orderItem.setQuantity(newQuantity);
|
||||
|
||||
// 更新数据库
|
||||
ctripOrderItemMapper.updateById(orderItem);
|
||||
log.info("订单项数量更新成功,itemId: {}, 原数量: {}, 使用数量: {}, 新数量: {}",
|
||||
itemId, currentQuantity, useQuantity, newQuantity);
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单项数量异常,itemId: {}", itemId, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,27 +315,79 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
||||
*/
|
||||
private void updateOrderStatus(CtripOrder order, Integer useQuantity) {
|
||||
try {
|
||||
// 查询该订单的所有核销记录
|
||||
List<CtripConsumed> consumedList = ctripConsumedMapper.selectByOtaOrderId(order.getOtaOrderId());
|
||||
|
||||
// 计算总使用数量
|
||||
int totalUseQuantity = consumedList.stream()
|
||||
.mapToInt(c -> c.getUseQuantity() != null ? c.getUseQuantity() : 0)
|
||||
.sum();
|
||||
|
||||
// 如果使用数量大于0,更新订单状态为已使用(状态8)
|
||||
if (totalUseQuantity > 0) {
|
||||
order.setStatus(8); // 已使用状态
|
||||
// 查询订单项
|
||||
List<CtripOrderItem> orderItems = ctripOrderItemMapper.selectByOrderId(order.getId());
|
||||
if (orderItems == null || orderItems.isEmpty()) {
|
||||
log.warn("订单无订单项,无法根据份数判断使用状态,保持原状态,otaOrderId: {}", order.getOtaOrderId());
|
||||
return;
|
||||
}
|
||||
|
||||
boolean allFullyUsed = true;
|
||||
boolean anyUsed = false;
|
||||
|
||||
for (CtripOrderItem item : orderItems) {
|
||||
// 直接使用订单项表中的数量,因为核销后数量已经被更新
|
||||
int currentQuantity = item.getQuantity() != null ? item.getQuantity() : 0;
|
||||
int originalQuantity = currentQuantity + useQuantity; // 反推原始数量
|
||||
|
||||
log.debug("订单 {} 明细 itemId={} 当前数量/原始数量: {}/{}",
|
||||
order.getOtaOrderId(), item.getItemId(), currentQuantity, originalQuantity);
|
||||
|
||||
if (currentQuantity < originalQuantity) {
|
||||
anyUsed = true;
|
||||
}
|
||||
if (currentQuantity > 0) {
|
||||
allFullyUsed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (allFullyUsed && anyUsed) {
|
||||
order.setStatus(8); // 全部使用
|
||||
ctripOrderMapper.updateById(order);
|
||||
log.info("订单状态更新为已使用,otaOrderId: {}, totalUseQuantity: {}",
|
||||
order.getOtaOrderId(), totalUseQuantity);
|
||||
log.info("订单状态更新为全部使用(8),otaOrderId: {}", order.getOtaOrderId());
|
||||
} else if (anyUsed) {
|
||||
order.setStatus(7); // 部分使用
|
||||
ctripOrderMapper.updateById(order);
|
||||
log.info("订单状态更新为部分使用(7),otaOrderId: {}", order.getOtaOrderId());
|
||||
} else {
|
||||
log.info("订单尚未发生使用变化,保持原状态,otaOrderId: {}", order.getOtaOrderId());
|
||||
}
|
||||
|
||||
// 同步订单中心状态(成功使用即认为支付成功)
|
||||
if (anyUsed) {
|
||||
updateOrderCenterStatus(order);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单状态异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单中心订单状态
|
||||
*/
|
||||
private void updateOrderCenterStatus(CtripOrder order) {
|
||||
try {
|
||||
if (StringUtils.hasText(order.getOrderNo())) {
|
||||
log.info("开始更新订单中心订单状态,orderNo: {}", order.getOrderNo());
|
||||
|
||||
// 调用订单中心接口更新订单状态为已支付(状态1)
|
||||
Result<String> result = orderCenterService.updateOrderStatusToPaid(order.getOrderNo());
|
||||
|
||||
if (result != null && result.getResp_code() == 0) {
|
||||
log.info("订单中心订单状态更新成功,orderNo: {}", order.getOrderNo());
|
||||
} else {
|
||||
log.error("订单中心订单状态更新失败,orderNo: {}, result: {}",
|
||||
order.getOrderNo(), result);
|
||||
}
|
||||
} else {
|
||||
log.warn("携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: {}",
|
||||
order.getOtaOrderId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单中心订单状态异常,orderNo: {}", order.getOrderNo(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建成功响应
|
||||
*/
|
||||
@@ -299,10 +423,12 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
||||
|
||||
// 1. 构建请求头
|
||||
Map<String, Object> header = new HashMap<>();
|
||||
header.put("accountId", "c50a8f2a4a59c9e7");
|
||||
String configuredAccountId = ctripApiConfig.getAccount().getId();
|
||||
header.put("accountId", configuredAccountId);
|
||||
header.put("serviceName", "OrderConsumedNotice");
|
||||
header.put("requestTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
header.put("version", "1.0");
|
||||
log.info("OrderConsumedNotice 使用的accountId: {}", configuredAccountId);
|
||||
|
||||
// 2. 从数据库获取正确的supplierOrderId
|
||||
CtripOrder order = ctripOrderMapper.selectByOtaOrderId(request.getOtaOrderId());
|
||||
|
||||
+9
-5
@@ -31,6 +31,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.central.coupon.enums.CtripOrderStatus;
|
||||
import com.central.coupon.config.CtripApiConfig;
|
||||
|
||||
/**
|
||||
* 携程预下单支付服务实现类
|
||||
@@ -59,6 +60,9 @@ public class CtripPayPreOrderServiceImpl implements CtripPayPreOrderService {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private CtripApiConfig ctripApiConfig;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -750,9 +754,8 @@ public class CtripPayPreOrderServiceImpl implements CtripPayPreOrderService {
|
||||
try {
|
||||
log.info("=== 开始发送HTTP请求到携程PayPreOrderConfirm接口 ===");
|
||||
|
||||
// 使用与CtripApiServiceImpl相同的baseUrl
|
||||
String baseUrl = "https://ttdopen.ctrip.com";
|
||||
String url = baseUrl + "/api/order/notice.do"; // 使用正确的API端点
|
||||
// 使用配置中的URL
|
||||
String url = ctripApiConfig.getApi().getOrderNoticeUrl();
|
||||
|
||||
log.info("携程API URL: {}", url);
|
||||
|
||||
@@ -773,8 +776,9 @@ public class CtripPayPreOrderServiceImpl implements CtripPayPreOrderService {
|
||||
log.info("Headers: {}", headers);
|
||||
log.info("Request Body: {}", finalRequestMap);
|
||||
|
||||
// 重试机制(与核销优惠券相同)
|
||||
int retryTimes = 3;
|
||||
// 重试机制(读取配置)
|
||||
Integer configuredRetries = ctripApiConfig.getApi().getRetryTimes();
|
||||
int retryTimes = configuredRetries != null ? configuredRetries : 3;
|
||||
for (int i = 0; i < retryTimes; i++) {
|
||||
try {
|
||||
log.info("第{}次尝试调用携程API,URL: {}", i + 1, url);
|
||||
|
||||
+82
-36
@@ -40,6 +40,9 @@ import com.central.common.model.Result;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
import com.central.coupon.feign.UserCenterService;
|
||||
import com.central.coupon.feign.dto.SysUserDTO;
|
||||
|
||||
/**
|
||||
* 订单明细服务实现类
|
||||
@@ -69,6 +72,9 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
||||
@Autowired
|
||||
private OrderCenterService orderCenterService;
|
||||
|
||||
@Autowired
|
||||
private UserCenterService userCenterService;
|
||||
|
||||
@Override
|
||||
public PageResult<OrderDetailVO> queryOrderDetails(OrderQueryDTO queryDTO) {
|
||||
log.info("查询可核销订单明细,codeId: {},page: {},size: {}", queryDTO.getCodeId(), queryDTO.getPage(), queryDTO.getSize());
|
||||
@@ -77,8 +83,24 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
||||
// 0. 从登录上下文获取用户手机号
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
String userPhone = user != null ? user.getMobile() : null;
|
||||
log.info("当前登录用户手机号: {}", userPhone);
|
||||
Long userId = user != null ? user.getId() : null;
|
||||
log.info("当前登录用户信息 -> userId: {}, mobile: {}", userId, userPhone);
|
||||
|
||||
// 如果手机号为空,尝试通过user-center用userId查询手机号
|
||||
if (!StringUtils.hasText(userPhone) && userId != null) {
|
||||
try {
|
||||
SysUserDTO sysUser = userCenterService.findUserById(userId);
|
||||
if (sysUser != null && StringUtils.hasText(sysUser.getMobile())) {
|
||||
userPhone = sysUser.getMobile();
|
||||
log.info("从user-center获取到用户手机号: {} (userId: {})", userPhone, userId);
|
||||
} else {
|
||||
log.warn("user-center未返回手机号,userId: {}", userId);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("调用user-center查询手机号异常,userId: {}", userId, ex);
|
||||
}
|
||||
}
|
||||
|
||||
// 0.1 通过codeId调用订单中心获取二维码信息,得到价格
|
||||
BigDecimal couponPrice = null;
|
||||
if (!StringUtils.isEmpty(queryDTO.getCodeId())) {
|
||||
@@ -239,7 +261,7 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
||||
}
|
||||
|
||||
// 2. 检查订单状态
|
||||
if (order.getStatus() == null || (order.getStatus() != 1 && order.getStatus() != 13)) {
|
||||
if (order.getStatus() == null || (order.getStatus() != 1 && order.getStatus() != 13 && order.getStatus() != 7)) {
|
||||
log.warn("订单状态不正确,订单号: {}, 状态: {}", otaOrderId, order.getStatus());
|
||||
return false;
|
||||
}
|
||||
@@ -253,6 +275,8 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
||||
|
||||
// 4. 检查每个订单项是否可核销
|
||||
for (CtripOrderItem item : orderItems) {
|
||||
log.info("检查订单项: itemId={}, quantity={}, useStartDate={}, useEndDate={}",
|
||||
item.getItemId(), item.getQuantity(), item.getUseStartDate(), item.getUseEndDate());
|
||||
if (!validateOrderItemForConsume(item)) {
|
||||
log.warn("订单项不可核销,订单号: {}, 商品ID: {}", otaOrderId, item.getItemId());
|
||||
return false;
|
||||
@@ -278,34 +302,20 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 1. 通过乘客信息查询订单
|
||||
List<CtripPassenger> passengers = ctripPassengerMapper.selectByPhone(userPhone);
|
||||
log.info("通过乘客信息查询到 {} 条记录", passengers != null ? passengers.size() : 0);
|
||||
|
||||
List<Long> orderIds = new ArrayList<>();
|
||||
|
||||
if (passengers != null && !passengers.isEmpty()) {
|
||||
orderIds.addAll(passengers.stream()
|
||||
.map(CtripPassenger::getOrderId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList()));
|
||||
log.info("从乘客信息中提取到 {} 个订单ID: {}", orderIds.size(), orderIds);
|
||||
}
|
||||
|
||||
// 2. 通过联系人信息查询订单
|
||||
// 仅通过联系人信息查询订单(按需求不再从乘客表查询)
|
||||
List<CtripContact> contacts = ctripContactMapper.selectByMobile(userPhone);
|
||||
log.info("通过联系人信息查询到 {} 条记录", contacts != null ? contacts.size() : 0);
|
||||
|
||||
List<Long> orderIds = new ArrayList<>();
|
||||
if (contacts != null && !contacts.isEmpty()) {
|
||||
List<Long> contactOrderIds = contacts.stream()
|
||||
orderIds.addAll(contacts.stream()
|
||||
.map(CtripContact::getOrderId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
orderIds.addAll(contactOrderIds);
|
||||
log.info("从联系人信息中提取到 {} 个订单ID: {}", contactOrderIds.size(), contactOrderIds);
|
||||
.collect(Collectors.toList()));
|
||||
log.info("从联系人信息中提取到 {} 个订单ID: {}", orderIds.size(), orderIds);
|
||||
}
|
||||
|
||||
// 3. 查询订单详情
|
||||
// 查询订单详情
|
||||
if (orderIds.isEmpty()) {
|
||||
log.warn("未找到任何订单ID,返回空列表");
|
||||
return new ArrayList<>();
|
||||
@@ -324,12 +334,29 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
||||
.filter(order -> {
|
||||
log.debug("筛选订单: otaOrderId={}, totalAmount={}", order.getOtaOrderId(), order.getTotalAmount());
|
||||
if (couponPrice != null) {
|
||||
if (order.getTotalAmount() == null || !order.getTotalAmount().equals(couponPrice)) {
|
||||
log.debug("订单 {} 价格不匹配,期望: {}, 实际: {}",
|
||||
order.getOtaOrderId(), couponPrice, order.getTotalAmount());
|
||||
// 改为按订单明细的单价(unit_price)匹配
|
||||
List<CtripOrderItem> items = ctripOrderItemMapper.selectByOrderId(order.getId());
|
||||
if (items == null || items.isEmpty()) {
|
||||
log.debug("订单 {} 无明细,跳过", order.getOtaOrderId());
|
||||
return false;
|
||||
}
|
||||
log.debug("订单 {} 价格匹配", order.getOtaOrderId());
|
||||
// 打印每个明细的unitPrice便于排查
|
||||
try {
|
||||
String unitPrices = items.stream()
|
||||
.map(CtripOrderItem::getUnitPrice)
|
||||
.map(p -> p == null ? "null" : p.toPlainString())
|
||||
.collect(Collectors.joining(","));
|
||||
log.debug("订单 {} 明细单价列表: [{}],目标单价: {}", order.getOtaOrderId(), unitPrices, couponPrice);
|
||||
} catch (Exception ignore) {}
|
||||
boolean itemPriceMatched = items.stream()
|
||||
.map(CtripOrderItem::getUnitPrice)
|
||||
.filter(Objects::nonNull)
|
||||
.anyMatch(p -> p.compareTo(couponPrice) == 0);
|
||||
if (!itemPriceMatched) {
|
||||
log.debug("订单 {} 未找到与单价 {} 匹配的明细项", order.getOtaOrderId(), couponPrice);
|
||||
return false;
|
||||
}
|
||||
log.debug("订单 {} 存在与单价 {} 匹配的明细项", order.getOtaOrderId(), couponPrice);
|
||||
}
|
||||
if (onlyConsumable != null && onlyConsumable) {
|
||||
if (!validateOrderForConsume(order.getOtaOrderId())) {
|
||||
@@ -405,11 +432,13 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
||||
itemDetail.setUseStartDate(item.getUseStartDate());
|
||||
itemDetail.setUseEndDate(item.getUseEndDate());
|
||||
|
||||
// 计算已使用数量和剩余数量
|
||||
int usedQuantity = getUsedQuantity(item.getId());
|
||||
// 计算已使用数量和剩余数量(按携程itemId匹配)
|
||||
int usedQuantity = getUsedQuantityByCtripItemId(item.getItemId());
|
||||
itemDetail.setUsedQuantity(usedQuantity);
|
||||
itemDetail.setAvailableQuantity(item.getQuantity() - usedQuantity);
|
||||
itemDetail.setCanConsume(usedQuantity < item.getQuantity());
|
||||
// 订单项表中的数量已经是更新后的数量(原始数量减去已使用数量)
|
||||
int currentQuantity = item.getQuantity() != null ? item.getQuantity() : 0;
|
||||
itemDetail.setAvailableQuantity(currentQuantity);
|
||||
itemDetail.setCanConsume(currentQuantity > 0);
|
||||
|
||||
return itemDetail;
|
||||
}).collect(Collectors.toList());
|
||||
@@ -453,31 +482,48 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
||||
* 验证订单项是否可核销
|
||||
*/
|
||||
private boolean validateOrderItemForConsume(CtripOrderItem item) {
|
||||
log.debug("开始验证订单项是否可核销,itemId: {}, quantity: {}, useStartDate: {}, useEndDate: {}",
|
||||
item.getItemId(), item.getQuantity(), item.getUseStartDate(), item.getUseEndDate());
|
||||
|
||||
// 检查使用日期
|
||||
LocalDate today = LocalDate.now();
|
||||
if (item.getUseStartDate() != null && today.isBefore(item.getUseStartDate())) {
|
||||
log.debug("订单项 {} 使用开始日期未到,today: {}, useStartDate: {}",
|
||||
item.getItemId(), today, item.getUseStartDate());
|
||||
return false;
|
||||
}
|
||||
if (item.getUseEndDate() != null && today.isAfter(item.getUseEndDate())) {
|
||||
log.debug("订单项 {} 使用结束日期已过,today: {}, useEndDate: {}",
|
||||
item.getItemId(), today, item.getUseEndDate());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查剩余数量
|
||||
int usedQuantity = getUsedQuantity(item.getId());
|
||||
return usedQuantity < item.getQuantity();
|
||||
// 直接使用订单项表中的当前数量,因为核销后数量已经被更新
|
||||
int currentQuantity = item.getQuantity() != null ? item.getQuantity() : 0;
|
||||
|
||||
log.debug("订单项 {} 数量检查:当前数量: {}", item.getItemId(), currentQuantity);
|
||||
|
||||
boolean isValid = currentQuantity > 0;
|
||||
if (!isValid) {
|
||||
log.debug("订单项 {} 当前数量不足,不可核销", item.getItemId());
|
||||
} else {
|
||||
log.debug("订单项 {} 验证通过,可以核销", item.getItemId());
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已使用数量
|
||||
*/
|
||||
private int getUsedQuantity(Long itemId) {
|
||||
private int getUsedQuantityByCtripItemId(String ctripItemId) {
|
||||
try {
|
||||
List<CtripConsumed> consumedRecords = ctripConsumedMapper.selectByItemId(itemId.toString());
|
||||
List<CtripConsumed> consumedRecords = ctripConsumedMapper.selectByItemId(ctripItemId);
|
||||
return consumedRecords.stream()
|
||||
.mapToInt(CtripConsumed::getUseQuantity)
|
||||
.sum();
|
||||
} catch (Exception e) {
|
||||
log.error("查询已使用数量异常,商品ID: {}", itemId, e);
|
||||
log.error("查询已使用数量异常,商品ID: {}", ctripItemId, e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
-103
@@ -510,107 +510,4 @@ public class CtripDecryptUtil {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证时间戳是否在有效期内
|
||||
*
|
||||
* @param requestTime 请求时间字符串,格式:yyyy-MM-dd HH:mm:ss
|
||||
* @param validMinutes 有效期(分钟)
|
||||
* @return 是否有效
|
||||
*/
|
||||
public boolean isTimestampValid(String requestTime, int validMinutes) {
|
||||
try {
|
||||
// 解析请求时间
|
||||
java.time.LocalDateTime requestDateTime = java.time.LocalDateTime.parse(
|
||||
requestTime,
|
||||
java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
);
|
||||
|
||||
// 获取当前时间
|
||||
java.time.LocalDateTime now = java.time.LocalDateTime.now();
|
||||
|
||||
// 计算时间差
|
||||
long diffMinutes = java.time.Duration.between(requestDateTime, now).toMinutes();
|
||||
|
||||
boolean isValid = Math.abs(diffMinutes) <= validMinutes;
|
||||
log.info("时间戳验证结果: {}, 请求时间: {}, 当前时间: {}, 时间差(分钟): {}",
|
||||
isValid, requestTime, now, diffMinutes);
|
||||
|
||||
return isValid;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("时间戳验证失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证版本号
|
||||
*
|
||||
* @param version 版本号
|
||||
* @return 是否有效
|
||||
*/
|
||||
public boolean isVersionValid(String version) {
|
||||
if (version == null || version.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查版本号格式,这里假设支持1.0和2.0
|
||||
return "1.0".equals(version) || "2.0".equals(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取AES密钥(仅用于调试)
|
||||
*/
|
||||
public String getAesKey() {
|
||||
return aesKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取AES IV(仅用于调试)
|
||||
*/
|
||||
public String getAesIv() {
|
||||
return aesIv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试特定场景的签名计算
|
||||
* 用于调试实际的携程请求
|
||||
*/
|
||||
public void testSpecificScenario() {
|
||||
try {
|
||||
log.info("=== 测试特定场景签名计算 ===");
|
||||
|
||||
// 使用日志中的实际数据
|
||||
String accountId = "c50a8f2a4a59c9e7";
|
||||
String serviceName = "QueryOrder";
|
||||
String requestTime = "2025-08-26 12:19:31";
|
||||
String encryptedBody = "eehodncdippnljpadokdehbpaheoaofpkmnlndpiablomiamepgkbgbiaghlhcffffoemepcnbnbnimkomidjidnlpfcaecakbocfpdpkmhcejelamhaplbofamkgaadlplpbhbfkmpckdioahheifjhgonkaimckfajdmnjjghofndadhkieacdgeakemiloehcaddlcpffidienipihmcdjbhicjggehakhflnbohhackfjjajoegafekfdgdcmopojmjmimbegcdoffpkifpemeoleaadfpknbjpomlcaimjpjjddcbeejeaidgjfhndhgnefhhagehicmfjppcpbigmoglpkbkadkcjlnfoaeooejhmbolendokblhfe";
|
||||
String version = "1.0";
|
||||
String expectedSign = "66be9cfafed2f88fd1418927ce2db876";
|
||||
|
||||
log.info("测试参数:");
|
||||
log.info(" accountId: {}", accountId);
|
||||
log.info(" serviceName: {}", serviceName);
|
||||
log.info(" requestTime: {}", requestTime);
|
||||
log.info(" encryptedBody长度: {}", encryptedBody.length());
|
||||
log.info(" version: {}", version);
|
||||
log.info(" expectedSign: {}", expectedSign);
|
||||
log.info(" accountSecret: {}", accountSecret);
|
||||
|
||||
// 计算签名
|
||||
String calculatedSign = generateSign(accountId, serviceName, requestTime, encryptedBody, version);
|
||||
|
||||
log.info("计算结果:");
|
||||
log.info(" calculatedSign: {}", calculatedSign);
|
||||
log.info(" isMatch: {}", calculatedSign != null && calculatedSign.equalsIgnoreCase(expectedSign));
|
||||
|
||||
// 详细调试
|
||||
Map<String, Object> debugInfo = debugSignCalculation(accountId, serviceName, requestTime, encryptedBody, version, expectedSign);
|
||||
log.info("调试信息: {}", debugInfo);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("测试特定场景失败: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ logging:
|
||||
level:
|
||||
com.central.order.controller.OrderFileController: DEBUG
|
||||
com.central.coupon.util.CtripDecryptUtil: DEBUG
|
||||
com.central.coupon.service.impl.OrderDetailServiceImpl: DEBUG
|
||||
|
||||
# 携程API配置
|
||||
ctrip:
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
use_end_date,
|
||||
price,
|
||||
sale_price,
|
||||
unit_price AS unitPrice,
|
||||
total_price,
|
||||
currency,
|
||||
quantity,
|
||||
@@ -46,6 +47,7 @@
|
||||
use_end_date,
|
||||
price,
|
||||
sale_price,
|
||||
unit_price AS unitPrice,
|
||||
total_price,
|
||||
currency,
|
||||
quantity,
|
||||
@@ -76,6 +78,7 @@
|
||||
use_end_date,
|
||||
price,
|
||||
sale_price,
|
||||
unit_price AS unitPrice,
|
||||
total_price,
|
||||
currency,
|
||||
quantity,
|
||||
@@ -107,6 +110,7 @@
|
||||
oi.use_end_date,
|
||||
oi.price,
|
||||
oi.sale_price,
|
||||
oi.unit_price AS unitPrice,
|
||||
oi.total_price,
|
||||
oi.currency,
|
||||
oi.quantity,
|
||||
|
||||
@@ -4,29 +4,33 @@
|
||||
|
||||
<!-- 根据携程订单号查询订单 -->
|
||||
<select id="selectByOtaOrderId" resultType="com.central.coupon.entity.CtripOrder">
|
||||
SELECT
|
||||
id,
|
||||
ota_order_id,
|
||||
supplier_order_id,
|
||||
sequence_id,
|
||||
confirm_type,
|
||||
order_last_confirm_time,
|
||||
status,
|
||||
total_amount,
|
||||
currency,
|
||||
create_time,
|
||||
update_time,
|
||||
create_by,
|
||||
update_by,
|
||||
remark,
|
||||
tenant_id
|
||||
FROM t_ctrip_order
|
||||
WHERE ota_order_id = #{otaOrderId}
|
||||
AND deleted = 0
|
||||
ORDER BY create_time DESC
|
||||
LIMIT 1
|
||||
SELECT * FROM t_ctrip_order WHERE ota_order_id = #{otaOrderId}
|
||||
</select>
|
||||
|
||||
<!-- 根据订单中心订单号查询携程订单 -->
|
||||
<select id="selectByOrderNo" resultType="com.central.coupon.entity.CtripOrder">
|
||||
SELECT * FROM t_ctrip_order WHERE order_no = #{orderNo}
|
||||
</select>
|
||||
|
||||
<!-- 根据携程订单号更新订单 -->
|
||||
<update id="updateByOtaOrderId" parameterType="com.central.coupon.entity.CtripOrder">
|
||||
UPDATE t_ctrip_order
|
||||
SET supplier_order_id = #{supplierOrderId},
|
||||
sequence_id = #{sequenceId},
|
||||
confirm_type = #{confirmType},
|
||||
order_last_confirm_time = #{orderLastConfirmTime},
|
||||
status = #{status},
|
||||
total_amount = #{totalAmount},
|
||||
currency = #{currency},
|
||||
update_time = #{updateTime},
|
||||
create_by = #{createBy},
|
||||
update_by = #{updateBy},
|
||||
remark = #{remark},
|
||||
tenant_id = #{tenantId},
|
||||
order_no = #{orderNo}
|
||||
WHERE ota_order_id = #{otaOrderId}
|
||||
</update>
|
||||
|
||||
<!-- 根据供应商订单号查询订单 -->
|
||||
<select id="selectBySupplierOrderId" resultType="com.central.coupon.entity.CtripOrder">
|
||||
SELECT
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
# 优惠券核销订单状态更新设计说明
|
||||
|
||||
## 功能概述
|
||||
|
||||
当优惠券核销成功后,需要自动更新订单中心的订单状态为"已支付",以便订单能够进入正常的业务流程(排队、执行等)。
|
||||
|
||||
## 设计方案
|
||||
|
||||
### 1. 绑定关系设计
|
||||
|
||||
在 `t_ctrip_order` 表中添加 `order_no` 字段,建立携程订单与订单中心订单的关联关系:
|
||||
|
||||
```sql
|
||||
ALTER TABLE `t_ctrip_order`
|
||||
ADD COLUMN `order_no` varchar(50) DEFAULT NULL COMMENT '关联的订单中心订单号' AFTER `ota_order_id`;
|
||||
|
||||
-- 添加索引
|
||||
ALTER TABLE `t_ctrip_order` ADD INDEX `idx_order_no` (`order_no`);
|
||||
ALTER TABLE `t_ctrip_order` ADD UNIQUE INDEX `uk_order_no` (`order_no`);
|
||||
```
|
||||
|
||||
### 2. 数据流程
|
||||
|
||||
```
|
||||
用户下单 → 创建订单中心订单 → 关联携程订单 → 核销优惠券 → 更新订单状态
|
||||
```
|
||||
|
||||
1. **用户下单时**:在订单中心创建订单,记录订单号
|
||||
2. **关联携程订单**:将订单中心的订单号关联到携程订单的 `order_no` 字段
|
||||
3. **核销优惠券**:调用携程核销接口
|
||||
4. **更新订单状态**:核销成功后,通过 `order_no` 调用订单中心接口更新订单状态
|
||||
|
||||
### 3. 核心组件
|
||||
|
||||
#### 3.1 数据库表结构
|
||||
|
||||
**t_ctrip_order 表新增字段:**
|
||||
- `order_no` varchar(50) - 关联的订单中心订单号
|
||||
|
||||
#### 3.2 实体类更新
|
||||
|
||||
**CtripOrder.java:**
|
||||
```java
|
||||
/**
|
||||
* 关联的订单中心订单号
|
||||
*/
|
||||
private String orderNo;
|
||||
```
|
||||
|
||||
#### 3.3 Mapper 接口
|
||||
|
||||
**CtripOrderMapper.java:**
|
||||
```java
|
||||
/**
|
||||
* 根据订单中心订单号查询携程订单
|
||||
*/
|
||||
CtripOrder selectByOrderNo(@Param("orderNo") String orderNo);
|
||||
```
|
||||
|
||||
#### 3.4 Feign 客户端
|
||||
|
||||
**OrderCenterService.java:**
|
||||
```java
|
||||
/**
|
||||
* 更新订单状态为已支付(优惠券核销成功后调用)
|
||||
*/
|
||||
@PostMapping("/order/{orderNo}/status/paid")
|
||||
Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo);
|
||||
|
||||
/**
|
||||
* 根据订单号获取订单信息
|
||||
*/
|
||||
@GetMapping("/order/{orderNo}")
|
||||
Result<OrderInfo> getOrderByOrderNo(@PathVariable("orderNo") String orderNo);
|
||||
```
|
||||
|
||||
#### 3.5 订单中心接口
|
||||
|
||||
**OrderController.java 新增接口:**
|
||||
```java
|
||||
@Operation(summary = "更新订单状态为已支付(优惠券核销成功后调用)")
|
||||
@PostMapping("/order/{orderNo}/status/paid")
|
||||
public Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo)
|
||||
|
||||
@Operation(summary = "根据订单号获取订单信息")
|
||||
@GetMapping("/order/{orderNo}")
|
||||
public Result<Order> getOrderByOrderNo(@PathVariable("orderNo") String orderNo)
|
||||
```
|
||||
|
||||
### 4. 核销流程更新
|
||||
|
||||
#### 4.1 核销服务更新
|
||||
|
||||
**CtripConsumedServiceImpl.java:**
|
||||
```java
|
||||
/**
|
||||
* 更新订单中心订单状态
|
||||
*/
|
||||
private void updateOrderCenterStatus(CtripOrder order) {
|
||||
try {
|
||||
if (StringUtils.hasText(order.getOrderNo())) {
|
||||
log.info("开始更新订单中心订单状态,orderNo: {}", order.getOrderNo());
|
||||
|
||||
// 调用订单中心接口更新订单状态为已支付(状态1)
|
||||
Result<String> result = orderCenterService.updateOrderStatusToPaid(order.getOrderNo());
|
||||
|
||||
if (result != null && result.getResp_code() == 0) {
|
||||
log.info("订单中心订单状态更新成功,orderNo: {}", order.getOrderNo());
|
||||
} else {
|
||||
log.error("订单中心订单状态更新失败,orderNo: {}, result: {}",
|
||||
order.getOrderNo(), result);
|
||||
}
|
||||
} else {
|
||||
log.warn("携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: {}",
|
||||
order.getOtaOrderId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单中心订单状态异常,orderNo: {}", order.getOrderNo(), e);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 订单状态映射
|
||||
|
||||
| 订单中心状态 | 状态值 | 说明 |
|
||||
|-------------|--------|------|
|
||||
| UNPAID | 0 | 待支付 |
|
||||
| PAID | 1 | 已支付排队中 |
|
||||
| CANCELED | 2 | 已取消 |
|
||||
| COMPLETE | 3 | 设备执行完成 |
|
||||
| DOING | 4 | 正在服务中 |
|
||||
| UPLOADING | 5 | 素材上传中 |
|
||||
| UPLOADED | 6 | 素材上传完成 |
|
||||
|
||||
**核销成功后更新为:**
|
||||
- 订单状态:`PAID` (1) - 已支付排队中
|
||||
- 支付类型:`COUPON_PAY` (2) - 优惠券支付
|
||||
- 支付时间:当前时间
|
||||
|
||||
### 6. 使用方式
|
||||
|
||||
#### 6.1 创建订单时建立关联
|
||||
|
||||
```java
|
||||
// 1. 创建订单中心订单
|
||||
Order order = new Order();
|
||||
order.setOrderNo("ORDER_20250901_001");
|
||||
// ... 设置其他字段
|
||||
orderService.createOrder(order);
|
||||
|
||||
// 2. 创建携程订单并关联
|
||||
CtripOrder ctripOrder = new CtripOrder();
|
||||
ctripOrder.setOtaOrderId("ctriptest-xxx");
|
||||
ctripOrder.setOrderNo("ORDER_20250901_001"); // 关联订单号
|
||||
// ... 设置其他字段
|
||||
ctripOrderMapper.insert(ctripOrder);
|
||||
```
|
||||
|
||||
#### 6.2 核销时自动更新状态
|
||||
|
||||
```java
|
||||
// 核销成功后,系统会自动:
|
||||
// 1. 更新携程订单状态为已使用(状态8)
|
||||
// 2. 调用订单中心接口更新订单状态为已支付(状态1)
|
||||
// 3. 设置支付类型为优惠券支付(类型2)
|
||||
```
|
||||
|
||||
### 7. 错误处理
|
||||
|
||||
#### 7.1 关联关系不存在
|
||||
- 日志记录:`携程订单未关联订单中心订单号,无法更新订单状态`
|
||||
- 不影响核销流程,只影响订单状态更新
|
||||
|
||||
#### 7.2 订单中心接口调用失败
|
||||
- 日志记录:`订单中心订单状态更新失败`
|
||||
- 不影响核销流程,只影响订单状态更新
|
||||
|
||||
#### 7.3 订单状态不正确
|
||||
- 只有 `UNPAID` 状态的订单才能更新为 `PAID`
|
||||
- 其他状态会返回错误信息
|
||||
|
||||
### 8. 监控和日志
|
||||
|
||||
#### 8.1 关键日志点
|
||||
- 核销开始:`开始执行核销订单`
|
||||
- 状态更新开始:`开始更新订单中心订单状态`
|
||||
- 状态更新成功:`订单中心订单状态更新成功`
|
||||
- 状态更新失败:`订单中心订单状态更新失败`
|
||||
|
||||
#### 8.2 监控指标
|
||||
- 核销成功率
|
||||
- 订单状态更新成功率
|
||||
- 接口调用响应时间
|
||||
|
||||
### 9. 注意事项
|
||||
|
||||
1. **数据一致性**:确保携程订单和订单中心订单的关联关系正确
|
||||
2. **幂等性**:多次核销同一订单时,状态更新应该是幂等的
|
||||
3. **事务性**:核销和状态更新应该在同一个事务中
|
||||
4. **异常处理**:订单中心接口调用失败不应影响核销流程
|
||||
5. **性能考虑**:状态更新是异步的,不应阻塞核销流程
|
||||
|
||||
### 10. 测试验证
|
||||
|
||||
#### 10.1 单元测试
|
||||
- 测试核销流程
|
||||
- 测试状态更新逻辑
|
||||
- 测试异常情况处理
|
||||
|
||||
#### 10.2 集成测试
|
||||
- 测试完整的核销到状态更新流程
|
||||
- 测试订单中心接口调用
|
||||
- 测试数据一致性
|
||||
|
||||
#### 10.3 端到端测试
|
||||
- 测试用户下单到核销的完整流程
|
||||
- 测试订单状态变化
|
||||
- 测试业务流程连续性
|
||||
@@ -0,0 +1,398 @@
|
||||
# 前端优惠券查询核销接口文档
|
||||
|
||||
## 概述
|
||||
|
||||
本文档描述了前端查询可核销订单和核销优惠券的完整接口流程。
|
||||
|
||||
## 基础信息
|
||||
|
||||
- **服务地址**: `http://localhost:8002/coupon`
|
||||
- **接口前缀**: `/api/order-detail`
|
||||
- **请求方式**: POST/GET
|
||||
- **数据格式**: JSON
|
||||
|
||||
## 1. 查询可核销订单接口
|
||||
|
||||
### 接口信息
|
||||
- **接口地址**: `POST /api/order-detail/query`
|
||||
- **功能描述**: 根据二维码ID查询可核销的订单(手机号从登录上下文获取,价格从二维码信息获取)
|
||||
- **请求方式**: POST
|
||||
|
||||
### 请求参数
|
||||
|
||||
```json
|
||||
{
|
||||
"codeId": "5e0b3d9d-fc1a-4c8f-9c1a-7f4d2d9b6a11",
|
||||
"page": 1,
|
||||
"size": 10
|
||||
}
|
||||
```
|
||||
|
||||
### 参数说明
|
||||
|
||||
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|
||||
|--------|------|------|--------|------|
|
||||
| codeId | String | 是 | - | 二维码ID(订单中的codeId) |
|
||||
| page | Integer | 否 | 1 | 页码,从1开始(必须 ≥ 1) |
|
||||
| size | Integer | 否 | 10 | 每页数量(必须 ≥ 1,最大100) |
|
||||
|
||||
说明:
|
||||
- 后端通过 `LoginUserContextHolder.getUser().getMobile()` 获取用户手机号。
|
||||
- 后端通过 Feign 调用订单中心 `/qrcode/{codeId}` 获取二维码信息中的价格,并据此匹配订单金额。
|
||||
- **重要**:页码从1开始,不是从0开始。如果传入page=0,系统会自动调整为page=1。
|
||||
- 页大小限制在1-100之间,超出范围会自动调整。
|
||||
|
||||
### 响应结果
|
||||
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "",
|
||||
"data": {
|
||||
"count": 1,
|
||||
"resp_code": 0,
|
||||
"data": [
|
||||
{
|
||||
"orderId": 137,
|
||||
"otaOrderId": "ctriptest-10816828-454259-145573",
|
||||
"supplierOrderId": "SUPPLIER_ctriptest-10816828-454259-145573_301495ef",
|
||||
"orderStatus": 13,
|
||||
"orderStatusDesc": "支付确认",
|
||||
"totalAmount": 2.0,
|
||||
"currency": "CNY",
|
||||
"createTime": "2025-09-01T10:30:00",
|
||||
"canConsume": true,
|
||||
"consumeReason": null,
|
||||
"orderItems": [
|
||||
{
|
||||
"itemId": 456,
|
||||
"productId": "1801589811",
|
||||
"itemName": "门票",
|
||||
"itemType": "1",
|
||||
"plu": "1",
|
||||
"quantity": 2,
|
||||
"unitPrice": 1.0,
|
||||
"totalPrice": 2.0,
|
||||
"currency": "CNY",
|
||||
"useStartDate": "2025-07-25",
|
||||
"useEndDate": "2025-07-25",
|
||||
"canConsume": true,
|
||||
"usedQuantity": 0,
|
||||
"availableQuantity": 2
|
||||
}
|
||||
],
|
||||
"passengers": [
|
||||
{
|
||||
"passengerId": "PASS_1",
|
||||
"passengerName": "张三",
|
||||
"phone": "18322694510",
|
||||
"passengerStatus": 0,
|
||||
"passengerStatusDesc": "未使用",
|
||||
"idCard": "110101199001011234",
|
||||
"gender": "ADULT",
|
||||
"age": null
|
||||
}
|
||||
],
|
||||
"contact": {
|
||||
"name": "张三",
|
||||
"mobile": "18322694510",
|
||||
"email": "zhangsan@example.com",
|
||||
"contactType": "CONTACT"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 响应字段说明
|
||||
|
||||
#### 订单信息 (OrderDetailVO)
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| orderId | Long | 订单ID |
|
||||
| otaOrderId | String | 携程订单号 |
|
||||
| supplierOrderId | String | 供应商订单号 |
|
||||
| orderStatus | Integer | 订单状态码 |
|
||||
| orderStatusDesc | String | 订单状态描述 |
|
||||
| totalAmount | BigDecimal | 订单总金额 |
|
||||
| currency | String | 货币类型 |
|
||||
| createTime | String | 创建时间 |
|
||||
| canConsume | Boolean | 是否可核销 |
|
||||
| consumeReason | String | 不可核销原因(如果不可核销) |
|
||||
|
||||
#### 订单项信息 (OrderItemDetailVO)
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| itemId | Long | 订单项ID |
|
||||
| productId | String | 商品ID(用于核销) |
|
||||
| itemName | String | 商品名称 |
|
||||
| itemType | String | 商品类型 |
|
||||
| plu | String | 商品编码 |
|
||||
| quantity | Integer | 总数量 |
|
||||
| unitPrice | BigDecimal | 单价 |
|
||||
| totalPrice | BigDecimal | 总价 |
|
||||
| currency | String | 货币类型 |
|
||||
| useStartDate | String | 使用开始日期 |
|
||||
| useEndDate | String | 使用结束日期 |
|
||||
| canConsume | Boolean | 是否可核销 |
|
||||
| usedQuantity | Integer | 已使用数量 |
|
||||
| availableQuantity | Integer | 可用数量 |
|
||||
|
||||
#### 乘客信息 (PassengerDetailVO)
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| passengerId | String | 乘客ID |
|
||||
| passengerName | String | 乘客姓名 |
|
||||
| phone | String | 乘客手机号 |
|
||||
| passengerStatus | Integer | 乘客状态 |
|
||||
| passengerStatusDesc | String | 乘客状态描述 |
|
||||
| idCard | String | 身份证号 |
|
||||
| gender | String | 性别 |
|
||||
| age | Integer | 年龄 |
|
||||
|
||||
#### 联系人信息 (ContactDetailVO)
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| name | String | 联系人姓名 |
|
||||
| mobile | String | 联系人手机号 |
|
||||
| email | String | 联系人邮箱 |
|
||||
| contactType | String | 联系人类型 |
|
||||
|
||||
## 2. 简化核销接口(推荐)
|
||||
|
||||
### 接口信息
|
||||
- **接口地址**: `POST /api/order-detail/consume-simple`
|
||||
- **功能描述**: 核销单个订单项
|
||||
- **请求方式**: POST
|
||||
|
||||
### 请求参数
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| otaOrderId | String | 是 | 携程订单号 |
|
||||
| orderNo | String | 否 | 关联的订单中心订单号(用于更新订单状态) |
|
||||
| itemId | String | 是 | 商品ID |
|
||||
| useQuantity | Integer | 是 | 核销数量 |
|
||||
| remark | String | 否 | 备注信息 |
|
||||
|
||||
**请求示例:**
|
||||
```json
|
||||
{
|
||||
"otaOrderId": "ctriptest-10816828-454259-145573",
|
||||
"orderNo": "ORDER_20250901_001",
|
||||
"itemId": "1801589811",
|
||||
"useQuantity": 1,
|
||||
"remark": "使用优惠券核销门票"
|
||||
}
|
||||
```
|
||||
|
||||
**业务逻辑:**
|
||||
1. 验证携程订单是否存在且可核销
|
||||
2. 如果传入了 `orderNo`,建立携程订单与订单中心订单的关联关系
|
||||
3. 执行核销操作,更新携程订单状态为已使用(状态8)
|
||||
4. 如果有关联的订单号,自动调用订单中心接口更新订单状态为已支付(状态1)
|
||||
5. 设置支付类型为优惠券支付(类型2)
|
||||
|
||||
### 参数说明
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| otaOrderId | String | 是 | 携程订单号 |
|
||||
| itemId | String | 是 | 商品ID(使用查询接口返回的productId) |
|
||||
| useQuantity | Integer | 是 | 核销数量 |
|
||||
| remark | String | 否 | 备注信息 |
|
||||
|
||||
### 响应结果
|
||||
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "核销成功",
|
||||
"data": true
|
||||
}
|
||||
```
|
||||
|
||||
### 错误响应
|
||||
|
||||
```json
|
||||
{
|
||||
"resp_code": 1,
|
||||
"resp_msg": "核销失败: 订单不存在",
|
||||
"data": false
|
||||
}
|
||||
```
|
||||
|
||||
## 3. 复杂核销接口(支持批量)
|
||||
|
||||
### 接口信息
|
||||
- **接口地址**: `POST /api/order-detail/consume`
|
||||
- **功能描述**: 批量核销多个订单项
|
||||
- **请求方式**: POST
|
||||
|
||||
### 请求参数
|
||||
|
||||
```json
|
||||
{
|
||||
"otaOrderId": "ctriptest-10816828-454259-145573",
|
||||
"supplierOrderId": "SUPPLIER_ctriptest-10816828-454259-145573_301495ef",
|
||||
"items": [
|
||||
{
|
||||
"itemId": "1801589811",
|
||||
"plu": "1",
|
||||
"quantity": 1,
|
||||
"passengerIds": ["PASS_1"],
|
||||
"voucherIds": ["VOUCHER_1"]
|
||||
}
|
||||
],
|
||||
"remark": "使用优惠券核销门票"
|
||||
}
|
||||
```
|
||||
|
||||
### 参数说明
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| otaOrderId | String | 是 | 携程订单号 |
|
||||
| supplierOrderId | String | 是 | 供应商订单号 |
|
||||
| items | Array | 是 | 核销项目列表 |
|
||||
| remark | String | 否 | 备注信息 |
|
||||
|
||||
#### items数组元素
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| itemId | String | 是 | 商品ID |
|
||||
| plu | String | 是 | 商品编码 |
|
||||
| quantity | Integer | 是 | 核销数量 |
|
||||
| passengerIds | Array | 否 | 乘客ID列表 |
|
||||
| voucherIds | Array | 否 | 凭证ID列表 |
|
||||
|
||||
### 响应结果
|
||||
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "核销成功",
|
||||
"data": true
|
||||
}
|
||||
```
|
||||
|
||||
## 4. 验证订单是否可核销
|
||||
|
||||
### 接口信息
|
||||
- **接口地址**: `GET /api/order-detail/{otaOrderId}/validate`
|
||||
- **功能描述**: 验证指定订单是否可核销
|
||||
- **请求方式**: GET
|
||||
|
||||
### 请求参数
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| otaOrderId | String | 是 | 携程订单号(路径参数) |
|
||||
|
||||
### 响应结果
|
||||
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "",
|
||||
"data": true
|
||||
}
|
||||
```
|
||||
|
||||
## 5. 调试接口
|
||||
|
||||
### 接口信息
|
||||
- **接口地址**: `GET /api/order-detail/debug/data`
|
||||
- **功能描述**: 调试接口,检查数据库中的数据情况
|
||||
- **请求方式**: GET
|
||||
|
||||
### 响应结果
|
||||
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "",
|
||||
"data": {
|
||||
"orderCount": 10,
|
||||
"passengerCount": 20,
|
||||
"contactCount": 15,
|
||||
"orderItemCount": 25,
|
||||
"latestOrders": [...],
|
||||
"passengersForPhone": 1,
|
||||
"passengerDetails": [...],
|
||||
"contactsForPhone": 1,
|
||||
"contactDetails": [...]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 6. 前端集成示例
|
||||
|
||||
### JavaScript/TypeScript 示例
|
||||
|
||||
```typescript
|
||||
// 查询可核销订单
|
||||
async function queryConsumableOrdersByCode(codeId: string, page = 1, size = 10) {
|
||||
const response = await fetch('/api/order-detail/query', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ codeId, page, size })
|
||||
});
|
||||
const result = await response.json();
|
||||
return result.data;
|
||||
}
|
||||
|
||||
// 简化核销订单
|
||||
async function consumeOrderSimple(otaOrderId: string, itemId: string, useQuantity: number, remark: string) {
|
||||
const response = await fetch('/api/order-detail/consume-simple', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ otaOrderId, itemId, useQuantity, remark })
|
||||
});
|
||||
const result = await response.json();
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
### 注意
|
||||
- 无需传手机号和价格,后端会自动从登录上下文与二维码信息中获取。
|
||||
|
||||
## 7. 错误码说明
|
||||
|
||||
| 错误码 | 说明 |
|
||||
|--------|------|
|
||||
| 0 | 成功 |
|
||||
| 1 | 失败 |
|
||||
| 1001 | 参数错误 |
|
||||
| 1002 | 订单不存在 |
|
||||
| 1003 | 订单不可核销 |
|
||||
| 1004 | 商品不存在 |
|
||||
| 1005 | 核销数量超出限制 |
|
||||
|
||||
## 8. 注意事项
|
||||
|
||||
1. **手机号格式**: 建议统一使用11位数字格式,如 `18322694510`
|
||||
2. **价格精度**: 使用 `BigDecimal` 类型处理价格,避免精度问题
|
||||
3. **itemId映射**: 核销时使用查询接口返回的 `productId` 作为 `itemId`
|
||||
4. **状态验证**: 只有状态为1(已确认)或13(支付确认)的订单可以核销
|
||||
5. **数量限制**: 核销数量不能超过 `availableQuantity`
|
||||
6. **错误处理**: 前端需要处理核销失败的情况,并给出用户友好的提示
|
||||
|
||||
## 9. 测试用例
|
||||
|
||||
### 测试数据
|
||||
- 手机号: `18322694510`
|
||||
- 优惠券价格: `2.0`
|
||||
- 订单号: `ctriptest-10816828-454259-145573`
|
||||
- 商品ID: `1801589811`
|
||||
|
||||
### 测试步骤
|
||||
1. 调用查询接口,确认能返回订单数据
|
||||
2. 调用验证接口,确认订单可核销
|
||||
3. 调用核销接口,确认核销成功
|
||||
4. 再次调用查询接口,确认订单状态已更新
|
||||
@@ -0,0 +1,209 @@
|
||||
# 携程核销订单状态更新确认
|
||||
|
||||
## 完整流程确认
|
||||
|
||||
### 1. 前端调用核销接口
|
||||
```java
|
||||
// 前端调用 OrderDetailController.consumeOrderSimple
|
||||
POST /api-coupon/api/order-detail/consume-simple
|
||||
{
|
||||
"otaOrderId": "ctriptest-xxx",
|
||||
"orderNo": "ORDER_20250901_001", // 关联的订单中心订单号
|
||||
"itemId": "123456",
|
||||
"useQuantity": 1,
|
||||
"remark": "优惠券核销"
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 建立订单关联关系
|
||||
```java
|
||||
// OrderDetailController.consumeOrderSimple 第3步
|
||||
if (consumeDTO.getOrderNo() != null && !consumeDTO.getOrderNo().trim().isEmpty()) {
|
||||
if (order.getOrderNo() == null || order.getOrderNo().trim().isEmpty()) {
|
||||
// 更新携程订单的orderNo字段
|
||||
order.setOrderNo(consumeDTO.getOrderNo());
|
||||
ctripOrderMapper.updateById(order);
|
||||
log.info("建立订单关联关系,otaOrderId: {}, orderNo: {}",
|
||||
consumeDTO.getOtaOrderId(), consumeDTO.getOrderNo());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 调用核销服务
|
||||
```java
|
||||
// OrderDetailController.consumeOrderSimple 第4步
|
||||
CtripConsumedNoticeResponse response = ctripConsumedService.consumeOrder(request);
|
||||
```
|
||||
|
||||
### 4. 核销服务执行流程
|
||||
```java
|
||||
// CtripConsumedServiceImpl.consumeOrder()
|
||||
@Override
|
||||
@Transactional
|
||||
public CtripConsumedNoticeResponse consumeOrder(CtripConsumeRequest request) {
|
||||
// 1. 验证请求参数
|
||||
// 2. 检查订单是否存在
|
||||
// 3. 生成序列号
|
||||
// 4. 保存核销记录到本地数据库
|
||||
// 5. 更新订单状态 ← 这里会触发订单中心更新
|
||||
updateOrderStatus(order, request.getUseQuantity());
|
||||
// 6. 生成OrderConsumedNotice请求体
|
||||
// 7. 返回成功响应
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 更新携程订单状态
|
||||
```java
|
||||
// CtripConsumedServiceImpl.updateOrderStatus()
|
||||
private void updateOrderStatus(CtripOrder order, Integer useQuantity) {
|
||||
// 查询该订单的所有核销记录
|
||||
List<CtripConsumed> consumedList = ctripConsumedMapper.selectByOtaOrderId(order.getOtaOrderId());
|
||||
|
||||
// 计算总使用数量
|
||||
int totalUseQuantity = consumedList.stream()
|
||||
.mapToInt(c -> c.getUseQuantity() != null ? c.getUseQuantity() : 0)
|
||||
.sum();
|
||||
|
||||
// 如果使用数量大于0,更新订单状态为已使用(状态8)
|
||||
if (totalUseQuantity > 0) {
|
||||
order.setStatus(8); // 已使用状态
|
||||
ctripOrderMapper.updateById(order);
|
||||
log.info("订单状态更新为已使用,otaOrderId: {}, totalUseQuantity: {}",
|
||||
order.getOtaOrderId(), totalUseQuantity);
|
||||
|
||||
// 6. 更新订单中心订单状态(如果有关联的订单号)
|
||||
updateOrderCenterStatus(order);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 6. 更新订单中心状态
|
||||
```java
|
||||
// CtripConsumedServiceImpl.updateOrderCenterStatus()
|
||||
private void updateOrderCenterStatus(CtripOrder order) {
|
||||
if (StringUtils.hasText(order.getOrderNo())) {
|
||||
log.info("开始更新订单中心订单状态,orderNo: {}", order.getOrderNo());
|
||||
|
||||
// 调用订单中心接口更新订单状态为已支付(状态1)
|
||||
Result<String> result = orderCenterService.updateOrderStatusToPaid(order.getOrderNo());
|
||||
|
||||
if (result != null && result.getResp_code() == 0) {
|
||||
log.info("订单中心订单状态更新成功,orderNo: {}", order.getOrderNo());
|
||||
} else {
|
||||
log.error("订单中心订单状态更新失败,orderNo: {}, result: {}",
|
||||
order.getOrderNo(), result);
|
||||
}
|
||||
} else {
|
||||
log.warn("携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: {}",
|
||||
order.getOtaOrderId());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 7. 订单中心状态更新接口
|
||||
```java
|
||||
// OrderController.updateOrderStatusToPaid()
|
||||
@PostMapping("/order/{orderNo}/status/paid")
|
||||
public Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo) {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
|
||||
if (order.getOrderStatus().equals(OrderStatus.UNPAID.getId())) {
|
||||
// 更新订单状态为已支付排队中
|
||||
order.setOrderStatus(OrderStatus.PAID.getId());
|
||||
// 设置支付类型为优惠券支付
|
||||
order.setPayType(2); // 2表示优惠券支付
|
||||
// 设置支付时间
|
||||
order.setPayTime(new Date());
|
||||
|
||||
boolean result = orderService.updateOrder(order);
|
||||
if (result) {
|
||||
log.info("订单状态更新成功,orderNo: {}, 新状态: {}", orderNo, OrderStatus.PAID.getId());
|
||||
return Result.succeed("订单状态更新成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 关键日志点确认
|
||||
|
||||
### 成功流程日志
|
||||
```
|
||||
简化核销订单,订单号: ctriptest-xxx, 商品ID: 123456, 数量: 1, 关联订单号: ORDER_20250901_001
|
||||
建立订单关联关系,otaOrderId: ctriptest-xxx, orderNo: ORDER_20250901_001
|
||||
开始执行核销订单,otaOrderId: ctriptest-xxx, itemId: 123456, useQuantity: 1
|
||||
核销记录保存成功,sequenceId: 20250901xxx
|
||||
订单状态更新为已使用,otaOrderId: ctriptest-xxx, totalUseQuantity: 1
|
||||
开始更新订单中心订单状态,orderNo: ORDER_20250901_001
|
||||
订单中心订单状态更新成功,orderNo: ORDER_20250901_001
|
||||
核销订单执行成功,otaOrderId: ctriptest-xxx, sequenceId: 20250901xxx
|
||||
核销成功,订单号: ctriptest-xxx, 关联订单号: ORDER_20250901_001
|
||||
```
|
||||
|
||||
### 订单中心日志
|
||||
```
|
||||
优惠券核销成功,更新订单状态为已支付,orderNo: ORDER_20250901_001
|
||||
订单状态更新成功,orderNo: ORDER_20250901_001, 新状态: 1
|
||||
```
|
||||
|
||||
## 数据库状态变化确认
|
||||
|
||||
### 携程订单表 (t_ctrip_order)
|
||||
```sql
|
||||
-- 核销前
|
||||
SELECT ota_order_id, order_no, status FROM t_ctrip_order WHERE ota_order_id = 'ctriptest-xxx';
|
||||
-- 结果: status = 1 (已确认), order_no = NULL
|
||||
|
||||
-- 核销后
|
||||
SELECT ota_order_id, order_no, status FROM t_ctrip_order WHERE ota_order_id = 'ctriptest-xxx';
|
||||
-- 结果: status = 8 (已使用), order_no = 'ORDER_20250901_001'
|
||||
```
|
||||
|
||||
### 订单中心表 (orders)
|
||||
```sql
|
||||
-- 核销前
|
||||
SELECT order_no, order_status, pay_type, pay_time FROM orders WHERE order_no = 'ORDER_20250901_001';
|
||||
-- 结果: order_status = 0 (未支付), pay_type = NULL, pay_time = NULL
|
||||
|
||||
-- 核销后
|
||||
SELECT order_no, order_status, pay_type, pay_time FROM orders WHERE order_no = 'ORDER_20250901_001';
|
||||
-- 结果: order_status = 1 (已支付), pay_type = 2 (优惠券支付), pay_time = 2025-09-01 17:32:30
|
||||
```
|
||||
|
||||
### 核销记录表 (t_ctrip_consumed)
|
||||
```sql
|
||||
-- 核销后新增记录
|
||||
SELECT ota_order_id, supplier_order_id, item_id, use_quantity, create_time
|
||||
FROM t_ctrip_consumed WHERE ota_order_id = 'ctriptest-xxx';
|
||||
-- 结果: 新增一条核销记录
|
||||
```
|
||||
|
||||
## 状态映射确认
|
||||
|
||||
| 系统 | 状态值 | 状态含义 | 说明 |
|
||||
|------|--------|----------|------|
|
||||
| 携程订单 | 0 | 待确认 | 预下单创建后 |
|
||||
| 携程订单 | 1 | 已确认 | 预下单确认后 |
|
||||
| 携程订单 | 8 | 已使用 | 核销成功后 |
|
||||
| 订单中心 | 0 | 未支付 | 订单创建后 |
|
||||
| 订单中心 | 1 | 已支付 | 核销成功后更新 |
|
||||
|
||||
## 支付类型确认
|
||||
|
||||
| 支付类型值 | 支付方式 | 说明 |
|
||||
|------------|----------|------|
|
||||
| 1 | 微信支付 | 用户通过微信支付 |
|
||||
| 2 | 优惠券支付 | 用户使用优惠券核销 |
|
||||
|
||||
## 结论
|
||||
|
||||
✅ **流程完整**:前端调用 → 建立关联 → 核销执行 → 状态更新 → 订单中心更新
|
||||
|
||||
✅ **状态正确**:携程订单状态8(已使用),订单中心状态1(已支付)
|
||||
|
||||
✅ **关联正确**:通过orderNo字段建立携程订单与订单中心订单的关联
|
||||
|
||||
✅ **日志完整**:每个关键步骤都有详细的日志记录
|
||||
|
||||
✅ **异常处理**:即使订单中心更新失败,也不会影响核销流程
|
||||
|
||||
✅ **事务安全**:核销操作在事务中执行,确保数据一致性
|
||||
@@ -0,0 +1,240 @@
|
||||
# 优惠券核销流程测试用例
|
||||
|
||||
## 测试目标
|
||||
|
||||
验证优惠券核销成功后,能够正确更新订单中心订单状态为"已支付"。
|
||||
|
||||
## 测试环境
|
||||
|
||||
- 优惠券中心服务:`coupon-center`
|
||||
- 订单中心服务:`order-center`
|
||||
- 数据库:MySQL
|
||||
|
||||
## 测试步骤
|
||||
|
||||
### 1. 准备测试数据
|
||||
|
||||
#### 1.1 创建订单中心订单
|
||||
```sql
|
||||
-- 在订单中心数据库中创建测试订单
|
||||
INSERT INTO orders (
|
||||
order_no, user_id, tourism_id, order_amount, order_status,
|
||||
pay_type, code_id, device_sn, tenant_id, create_time, update_time
|
||||
) VALUES (
|
||||
'TEST_ORDER_001', 1, 1, '9990', 0, -- 0表示待支付
|
||||
1, 'test-code-id', 'TEST_DEVICE_001', 'test-tenant',
|
||||
NOW(), NOW()
|
||||
);
|
||||
```
|
||||
|
||||
#### 1.2 创建携程订单(不关联订单号)
|
||||
```sql
|
||||
-- 在优惠券中心数据库中创建携程订单
|
||||
INSERT INTO t_ctrip_order (
|
||||
ota_order_id, supplier_order_id, sequence_id, status,
|
||||
total_amount, currency, create_time, update_time
|
||||
) VALUES (
|
||||
'ctriptest-test-001', 'SUPPLIER_test_001', 'test-sequence-001', 13, -- 13表示支付已确认
|
||||
99.90, 'CNY', NOW(), NOW()
|
||||
);
|
||||
```
|
||||
|
||||
### 2. 测试场景
|
||||
|
||||
#### 场景1:核销时传入orderNo,建立关联关系
|
||||
|
||||
**请求:**
|
||||
```bash
|
||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"otaOrderId": "ctriptest-test-001",
|
||||
"orderNo": "TEST_ORDER_001",
|
||||
"itemId": "test-item-001",
|
||||
"useQuantity": 1,
|
||||
"remark": "测试核销"
|
||||
}'
|
||||
```
|
||||
|
||||
**预期结果:**
|
||||
1. 核销成功,返回 `{"resp_code": 0, "resp_msg": "核销成功", "data": true}`
|
||||
2. 携程订单状态更新为已使用(状态8)
|
||||
3. 携程订单的 `order_no` 字段被设置为 `TEST_ORDER_001`
|
||||
4. 订单中心订单状态更新为已支付(状态1)
|
||||
5. 订单中心订单的 `pay_type` 字段被设置为优惠券支付(类型2)
|
||||
|
||||
**验证SQL:**
|
||||
```sql
|
||||
-- 验证携程订单状态和关联关系
|
||||
SELECT ota_order_id, order_no, status FROM t_ctrip_order WHERE ota_order_id = 'ctriptest-test-001';
|
||||
|
||||
-- 验证订单中心订单状态
|
||||
SELECT order_no, order_status, pay_type, pay_time FROM orders WHERE order_no = 'TEST_ORDER_001';
|
||||
```
|
||||
|
||||
#### 场景2:核销时未传入orderNo
|
||||
|
||||
**请求:**
|
||||
```bash
|
||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"otaOrderId": "ctriptest-test-002",
|
||||
"itemId": "test-item-002",
|
||||
"useQuantity": 1,
|
||||
"remark": "测试核销(无关联)"
|
||||
}'
|
||||
```
|
||||
|
||||
**预期结果:**
|
||||
1. 核销成功,返回 `{"resp_code": 0, "resp_msg": "核销成功", "data": true}`
|
||||
2. 携程订单状态更新为已使用(状态8)
|
||||
3. 携程订单的 `order_no` 字段为空
|
||||
4. 不会调用订单中心接口更新状态
|
||||
5. 日志中显示:`携程订单未关联订单中心订单号,无法更新订单状态`
|
||||
|
||||
#### 场景3:核销已关联的订单
|
||||
|
||||
**请求:**
|
||||
```bash
|
||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"otaOrderId": "ctriptest-test-001",
|
||||
"orderNo": "TEST_ORDER_002", -- 传入不同的订单号
|
||||
"itemId": "test-item-003",
|
||||
"useQuantity": 1,
|
||||
"remark": "测试核销(已关联)"
|
||||
}'
|
||||
```
|
||||
|
||||
**预期结果:**
|
||||
1. 核销成功
|
||||
2. 日志中显示:`订单关联关系不匹配,数据库orderNo: TEST_ORDER_001, 前端orderNo: TEST_ORDER_002`
|
||||
3. 不会更新关联关系,继续使用原有的 `TEST_ORDER_001`
|
||||
4. 订单中心订单状态正常更新
|
||||
|
||||
### 3. 日志验证
|
||||
|
||||
#### 3.1 成功核销日志
|
||||
```
|
||||
简化核销订单,订单号: ctriptest-test-001, 商品ID: test-item-001, 数量: 1, 关联订单号: TEST_ORDER_001
|
||||
建立订单关联关系,otaOrderId: ctriptest-test-001, orderNo: TEST_ORDER_001
|
||||
开始执行核销订单,otaOrderId: ctriptest-test-001, itemId: test-item-001, useQuantity: 1
|
||||
订单状态更新为已使用,otaOrderId: ctriptest-test-001, totalUseQuantity: 1
|
||||
开始更新订单中心订单状态,orderNo: TEST_ORDER_001
|
||||
订单中心订单状态更新成功,orderNo: TEST_ORDER_001
|
||||
核销成功,订单号: ctriptest-test-001, 关联订单号: TEST_ORDER_001
|
||||
```
|
||||
|
||||
#### 3.2 无关联订单日志
|
||||
```
|
||||
简化核销订单,订单号: ctriptest-test-002, 商品ID: test-item-002, 数量: 1, 关联订单号: null
|
||||
开始执行核销订单,otaOrderId: ctriptest-test-002, itemId: test-item-002, useQuantity: 1
|
||||
订单状态更新为已使用,otaOrderId: ctriptest-test-002, totalUseQuantity: 1
|
||||
携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: ctriptest-test-002
|
||||
核销成功,订单号: ctriptest-test-002, 关联订单号: null
|
||||
```
|
||||
|
||||
### 4. 异常场景测试
|
||||
|
||||
#### 4.1 订单不存在
|
||||
**请求:**
|
||||
```bash
|
||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"otaOrderId": "non-existent-order",
|
||||
"itemId": "test-item-001",
|
||||
"useQuantity": 1
|
||||
}'
|
||||
```
|
||||
|
||||
**预期结果:**
|
||||
- 返回错误:`{"resp_code": -1, "resp_msg": "订单不存在"}`
|
||||
|
||||
#### 4.2 订单中心接口调用失败
|
||||
**模拟场景:** 订单中心服务不可用
|
||||
|
||||
**预期结果:**
|
||||
- 核销成功
|
||||
- 日志显示:`订单中心订单状态更新失败,orderNo: TEST_ORDER_001, result: null`
|
||||
- 不影响核销流程
|
||||
|
||||
#### 4.3 订单状态不正确
|
||||
**模拟场景:** 订单中心订单状态不是待支付(状态0)
|
||||
|
||||
**预期结果:**
|
||||
- 订单中心接口返回:`订单状态不正确,无法更新为已支付`
|
||||
- 不影响核销流程
|
||||
|
||||
### 5. 性能测试
|
||||
|
||||
#### 5.1 并发核销测试
|
||||
```bash
|
||||
# 使用Apache Bench进行并发测试
|
||||
ab -n 100 -c 10 -p test_data.json -T application/json \
|
||||
http://localhost:8002/api-coupon/api/order-detail/consume-simple
|
||||
```
|
||||
|
||||
**预期结果:**
|
||||
- 所有请求成功处理
|
||||
- 无数据竞争问题
|
||||
- 订单状态正确更新
|
||||
|
||||
### 6. 数据一致性验证
|
||||
|
||||
#### 6.1 事务回滚测试
|
||||
**模拟场景:** 在核销过程中发生异常
|
||||
|
||||
**预期结果:**
|
||||
- 携程订单状态回滚
|
||||
- 核销记录回滚
|
||||
- 订单中心状态不更新
|
||||
|
||||
#### 6.2 幂等性测试
|
||||
**操作:** 对同一订单多次核销
|
||||
|
||||
**预期结果:**
|
||||
- 第一次核销成功
|
||||
- 后续核销返回已核销状态
|
||||
- 订单中心状态只更新一次
|
||||
|
||||
## 测试报告模板
|
||||
|
||||
### 测试结果汇总
|
||||
|
||||
| 测试场景 | 预期结果 | 实际结果 | 状态 |
|
||||
|----------|----------|----------|------|
|
||||
| 场景1:传入orderNo | 核销成功,状态更新 | | |
|
||||
| 场景2:未传入orderNo | 核销成功,无状态更新 | | |
|
||||
| 场景3:已关联订单 | 核销成功,使用原关联 | | |
|
||||
| 异常场景1:订单不存在 | 返回错误 | | |
|
||||
| 异常场景2:接口调用失败 | 核销成功,状态更新失败 | | |
|
||||
| 异常场景3:状态不正确 | 核销成功,状态更新失败 | | |
|
||||
| 性能测试:并发核销 | 100%成功率 | | |
|
||||
| 数据一致性:事务回滚 | 数据回滚正确 | | |
|
||||
| 数据一致性:幂等性 | 幂等性正确 | | |
|
||||
|
||||
### 问题记录
|
||||
|
||||
| 问题描述 | 严重程度 | 状态 | 备注 |
|
||||
|----------|----------|------|------|
|
||||
| | | | |
|
||||
|
||||
### 测试结论
|
||||
|
||||
- [ ] 所有测试场景通过
|
||||
- [ ] 性能满足要求
|
||||
- [ ] 数据一致性正确
|
||||
- [ ] 异常处理完善
|
||||
- [ ] 日志记录完整
|
||||
|
||||
## 部署验证清单
|
||||
|
||||
- [ ] 数据库表结构已更新(添加 `order_no` 字段)
|
||||
- [ ] 优惠券中心服务已部署
|
||||
- [ ] 订单中心服务已部署
|
||||
- [ ] Feign客户端配置正确
|
||||
- [ ] 日志级别配置正确
|
||||
- [ ] 监控告警配置正确
|
||||
@@ -0,0 +1,128 @@
|
||||
# 核销流程验证
|
||||
|
||||
## 验证目标
|
||||
|
||||
确认前端调用的 `consumeOrderSimple` 接口能够正确触发订单中心状态更新。
|
||||
|
||||
## 调用链验证
|
||||
|
||||
### 1. 前端接口调用
|
||||
```java
|
||||
// OrderDetailController.consumeOrderSimple()
|
||||
@PostMapping("/consume-simple")
|
||||
public Result<Boolean> consumeOrderSimple(@Valid @RequestBody SimpleConsumeDTO consumeDTO)
|
||||
```
|
||||
|
||||
### 2. 建立订单关联
|
||||
```java
|
||||
// 如果前端传入了orderNo,建立关联关系
|
||||
if (consumeDTO.getOrderNo() != null && !consumeDTO.getOrderNo().trim().isEmpty()) {
|
||||
if (order.getOrderNo() == null || order.getOrderNo().trim().isEmpty()) {
|
||||
order.setOrderNo(consumeDTO.getOrderNo());
|
||||
ctripOrderMapper.updateById(order);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 调用核销服务
|
||||
```java
|
||||
// 调用携程核销服务
|
||||
CtripConsumedNoticeResponse response = ctripConsumedService.consumeOrder(request);
|
||||
```
|
||||
|
||||
### 4. 核销服务执行
|
||||
```java
|
||||
// CtripConsumedServiceImpl.consumeOrder()
|
||||
@Override
|
||||
@Transactional
|
||||
public CtripConsumedNoticeResponse consumeOrder(CtripConsumeRequest request) {
|
||||
// ... 验证和保存逻辑 ...
|
||||
|
||||
// 5. 更新订单状态 ← 这里会触发订单中心更新
|
||||
updateOrderStatus(order, request.getUseQuantity());
|
||||
|
||||
// ... 其他逻辑 ...
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 订单状态更新
|
||||
```java
|
||||
// CtripConsumedServiceImpl.updateOrderStatus()
|
||||
private void updateOrderStatus(CtripOrder order, Integer useQuantity) {
|
||||
// ... 更新携程订单状态 ...
|
||||
|
||||
// 6. 更新订单中心订单状态 ← 这里调用订单中心接口
|
||||
updateOrderCenterStatus(order);
|
||||
}
|
||||
```
|
||||
|
||||
### 6. 订单中心状态更新
|
||||
```java
|
||||
// CtripConsumedServiceImpl.updateOrderCenterStatus()
|
||||
private void updateOrderCenterStatus(CtripOrder order) {
|
||||
if (StringUtils.hasText(order.getOrderNo())) {
|
||||
// 调用订单中心接口更新订单状态为已支付(状态1)
|
||||
Result<String> result = orderCenterService.updateOrderStatusToPaid(order.getOrderNo());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 关键日志点
|
||||
|
||||
### 成功流程日志
|
||||
```
|
||||
简化核销订单,订单号: xxx, 商品ID: xxx, 数量: 1, 关联订单号: ORDER_001
|
||||
建立订单关联关系,otaOrderId: xxx, orderNo: ORDER_001
|
||||
开始执行核销订单,otaOrderId: xxx, itemId: xxx, useQuantity: 1
|
||||
订单状态更新为已使用,otaOrderId: xxx, totalUseQuantity: 1
|
||||
开始更新订单中心订单状态,orderNo: ORDER_001
|
||||
订单中心订单状态更新成功,orderNo: ORDER_001
|
||||
核销成功,订单号: xxx, 关联订单号: ORDER_001
|
||||
```
|
||||
|
||||
### 无关联订单日志
|
||||
```
|
||||
简化核销订单,订单号: xxx, 商品ID: xxx, 数量: 1, 关联订单号: null
|
||||
开始执行核销订单,otaOrderId: xxx, itemId: xxx, useQuantity: 1
|
||||
订单状态更新为已使用,otaOrderId: xxx, totalUseQuantity: 1
|
||||
携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: xxx
|
||||
核销成功,订单号: xxx, 关联订单号: null
|
||||
```
|
||||
|
||||
## 验证方法
|
||||
|
||||
### 1. 数据库验证
|
||||
```sql
|
||||
-- 验证携程订单关联关系
|
||||
SELECT ota_order_id, order_no, status FROM t_ctrip_order WHERE ota_order_id = 'your-ota-order-id';
|
||||
|
||||
-- 验证订单中心订单状态
|
||||
SELECT order_no, order_status, pay_type, pay_time FROM orders WHERE order_no = 'your-order-no';
|
||||
```
|
||||
|
||||
### 2. 日志验证
|
||||
检查应用日志中是否包含上述关键日志点。
|
||||
|
||||
### 3. 接口验证
|
||||
```bash
|
||||
# 测试核销接口
|
||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"otaOrderId": "your-ota-order-id",
|
||||
"orderNo": "your-order-no",
|
||||
"itemId": "your-item-id",
|
||||
"useQuantity": 1,
|
||||
"remark": "测试核销"
|
||||
}'
|
||||
```
|
||||
|
||||
## 结论
|
||||
|
||||
✅ **调用链完整**:`consumeOrderSimple` → `consumeOrder` → `updateOrderStatus` → `updateOrderCenterStatus`
|
||||
|
||||
✅ **逻辑正确**:前端传入的 `orderNo` 会被正确处理,核销成功后会自动更新订单中心状态
|
||||
|
||||
✅ **异常处理**:即使订单中心接口调用失败,也不会影响核销流程
|
||||
|
||||
✅ **日志完整**:所有关键步骤都有详细的日志记录
|
||||
@@ -0,0 +1,635 @@
|
||||
# 接口文档
|
||||
|
||||
## 1. 订单创建接口
|
||||
|
||||
### 接口信息
|
||||
- **接口名称**: 创建订单
|
||||
- **请求方式**: POST
|
||||
- **接口路径**: `/api-order/orders`
|
||||
- **接口描述**: 用户通过扫描二维码创建订单,系统自动分配租户、设置订单金额等信息
|
||||
|
||||
### 请求参数
|
||||
|
||||
#### 请求头
|
||||
```
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer {access_token}
|
||||
```
|
||||
|
||||
#### 请求体 (JSON)
|
||||
```json
|
||||
{
|
||||
"codeId": "string", // 二维码ID(必填)
|
||||
"payType": 1 // 支付类型(可选,1:微信支付,2:优惠券支付,默认1)
|
||||
}
|
||||
```
|
||||
|
||||
#### 参数说明
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| codeId | String | 是 | 二维码唯一标识 |
|
||||
| payType | Integer | 否 | 支付类型,默认1(微信支付) |
|
||||
|
||||
### 响应结果
|
||||
|
||||
#### 成功响应
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "订单创建成功",
|
||||
"data": {
|
||||
"id": 123,
|
||||
"orderNo": "202501150001",
|
||||
"userId": 456,
|
||||
"tourismId": 789,
|
||||
"deviceSn": "8UUXN2A00A00LR",
|
||||
"orderAmount": "5000",
|
||||
"orderStatus": 0,
|
||||
"payType": 1,
|
||||
"codeId": "QR001",
|
||||
"tenantId": "tenant_001",
|
||||
"createTime": "2025-01-15T10:30:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 失败响应
|
||||
```json
|
||||
{
|
||||
"resp_code": 1,
|
||||
"resp_msg": "已存在订单,请前往订单页确认,请勿重复下单"
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应字段说明
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| resp_code | Integer | 响应码,0表示成功,非0表示失败 |
|
||||
| resp_msg | String | 响应消息 |
|
||||
| data | Object | 订单数据(成功时返回) |
|
||||
|
||||
### 业务逻辑
|
||||
1. **用户身份验证**: 验证用户登录状态
|
||||
2. **重复订单检查**: 检查用户是否已有未完成的订单
|
||||
3. **二维码验证**: 验证二维码是否存在且有效
|
||||
4. **租户分配**: 根据二维码ID智能分配租户
|
||||
5. **订单创建**: 设置订单基本信息并保存
|
||||
6. **幂等性保证**: 使用分布式锁确保订单不重复创建
|
||||
|
||||
### 错误码说明
|
||||
| 错误码 | 错误信息 | 说明 |
|
||||
|--------|----------|------|
|
||||
| 1 | 已存在订单,请前往订单页确认,请勿重复下单 | 用户已有未完成订单 |
|
||||
| 1 | 该二维码已过期 | 二维码状态为不可用 |
|
||||
| 1 | 二维码不存在 | 二维码ID无效 |
|
||||
|
||||
### 使用示例
|
||||
|
||||
#### cURL
|
||||
```bash
|
||||
curl -X POST "http://localhost:8080/api-order/orders" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer your_access_token" \
|
||||
-d '{
|
||||
"codeId": "QR001",
|
||||
"payType": 1
|
||||
}'
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
```javascript
|
||||
const response = await fetch('/api-order/orders', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + accessToken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
codeId: 'QR001',
|
||||
payType: 1
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.resp_code === 0) {
|
||||
console.log('订单创建成功:', result.data);
|
||||
} else {
|
||||
console.error('订单创建失败:', result.resp_msg);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. 任务执行状态查询接口
|
||||
|
||||
### 接口信息
|
||||
- **接口名称**: 获取任务状态
|
||||
- **请求方式**: GET
|
||||
- **接口路径**: `/api-order/auto-cut-video/task/status/{orderNo}`
|
||||
- **接口描述**: 根据订单号查询视频编辑任务的执行状态
|
||||
|
||||
### 请求参数
|
||||
|
||||
#### 路径参数
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| orderNo | String | 是 | 订单编号 |
|
||||
|
||||
#### 请求头
|
||||
```
|
||||
Authorization: Bearer {access_token}
|
||||
```
|
||||
|
||||
### 响应结果
|
||||
|
||||
#### 成功响应
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "查询成功",
|
||||
"data": {
|
||||
"id": 123,
|
||||
"orderSn": "202501150001",
|
||||
"jobId": "job_abc123",
|
||||
"userId": 456,
|
||||
"status": 1,
|
||||
"result": "处理中",
|
||||
"createTime": "2025-01-15T10:30:00Z",
|
||||
"updateTime": "2025-01-15T10:35:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 失败响应
|
||||
```json
|
||||
{
|
||||
"resp_code": 1,
|
||||
"resp_msg": "未找到任务记录"
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应字段说明
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| resp_code | Integer | 响应码,0表示成功,非0表示失败 |
|
||||
| resp_msg | String | 响应消息 |
|
||||
| data | Object | 任务数据(成功时返回) |
|
||||
|
||||
#### 任务状态说明
|
||||
| 状态值 | 状态描述 | 说明 |
|
||||
|--------|----------|------|
|
||||
| 0 | 待处理 | 任务已创建,等待处理 |
|
||||
| 1 | 处理中 | 任务正在执行 |
|
||||
| 2 | 处理完成 | 任务执行成功 |
|
||||
| 3 | 处理失败 | 任务执行失败 |
|
||||
|
||||
### 业务逻辑
|
||||
1. **参数验证**: 验证订单号格式
|
||||
2. **任务查询**: 根据订单号查询对应的编辑任务
|
||||
3. **状态返回**: 返回任务的当前执行状态和相关信息
|
||||
|
||||
### 错误码说明
|
||||
| 错误码 | 错误信息 | 说明 |
|
||||
|--------|----------|------|
|
||||
| 1 | 未找到任务记录 | 订单号对应的任务不存在 |
|
||||
| 1 | 获取任务状态失败 | 系统内部错误 |
|
||||
|
||||
### 使用示例
|
||||
|
||||
#### cURL
|
||||
```bash
|
||||
curl -X GET "http://localhost:8080/api-order/auto-cut-video/task/status/202501150001" \
|
||||
-H "Authorization: Bearer your_access_token"
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
```javascript
|
||||
const response = await fetch('/api-order/auto-cut-video/task/status/202501150001', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + accessToken
|
||||
}
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.resp_code === 0) {
|
||||
console.log('任务状态:', result.data);
|
||||
console.log('状态描述:', getStatusDesc(result.data.status));
|
||||
} else {
|
||||
console.error('查询失败:', result.resp_msg);
|
||||
}
|
||||
|
||||
function getStatusDesc(status) {
|
||||
const statusMap = {
|
||||
0: '待处理',
|
||||
1: '处理中',
|
||||
2: '处理完成',
|
||||
3: '处理失败'
|
||||
};
|
||||
return statusMap[status] || '未知状态';
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
## 3. 按照订单号获取图片视频资源接口
|
||||
|
||||
### 接口信息
|
||||
- **接口名称**: 根据订单号查询订单素材
|
||||
- **请求方式**: GET
|
||||
- **接口路径**: `/api-order/orders/user/files/{orderNo}`
|
||||
- **接口描述**: 根据订单号获取订单相关的所有素材资源,包括图片、视频、AI生成视频等
|
||||
|
||||
### 请求参数
|
||||
|
||||
#### 路径参数
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| orderNo | String | 是 | 订单编号 |
|
||||
|
||||
#### 请求头
|
||||
```
|
||||
Authorization: Bearer {access_token}
|
||||
```
|
||||
|
||||
### 响应结果
|
||||
|
||||
#### 成功响应
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "查询成功",
|
||||
"data": {
|
||||
"time": "2025-01-15 10:30",
|
||||
"addr": "北京市朝阳区某某景区",
|
||||
"orderNo": "202501150001",
|
||||
"aiVideo": "https://cdn.example.com/video/2025/01/15/ai_video_abc123.mp4",
|
||||
"imgList": [
|
||||
{
|
||||
"url": "https://cdn.example.com/picture/2025/01/15/img_001.jpeg",
|
||||
"contentType": "image/jpeg",
|
||||
"path": "picture/2025/01/15/img_001.jpeg",
|
||||
"viewUrl": "https://cdn.example.com/picture/2025/01/15/img_001.jpeg?style=thumbnail"
|
||||
},
|
||||
{
|
||||
"url": "https://cdn.example.com/picture/2025/01/15/img_002.jpeg",
|
||||
"contentType": "image/jpeg",
|
||||
"path": "picture/2025/01/15/img_002.jpeg",
|
||||
"viewUrl": "https://cdn.example.com/picture/2025/01/15/img_002.jpeg?style=thumbnail"
|
||||
}
|
||||
],
|
||||
"videoList": [
|
||||
{
|
||||
"url": "https://cdn.example.com/video/2025/01/15/video_001.mp4",
|
||||
"contentType": "video/mp4",
|
||||
"path": "video/2025/01/15/video_001.mp4",
|
||||
"viewUrl": "https://cdn.example.com/picture/2025/01/15/img_001.jpeg?style=thumbnail"
|
||||
}
|
||||
],
|
||||
"showVideoEditOnly": 0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 失败响应
|
||||
```json
|
||||
{
|
||||
"resp_code": 1,
|
||||
"resp_msg": "订单不存在"
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应字段说明
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| resp_code | Integer | 响应码,0表示成功,非0表示失败 |
|
||||
| resp_msg | String | 响应消息 |
|
||||
| data | Object | 订单素材数据(成功时返回) |
|
||||
|
||||
#### 素材数据字段说明
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| time | String | 订单创建时间(格式:yyyy-MM-dd HH:mm) |
|
||||
| addr | String | 景区地址 |
|
||||
| orderNo | String | 订单编号 |
|
||||
| aiVideo | String | AI生成视频的访问地址(可能为null) |
|
||||
| imgList | Array | 图片素材列表 |
|
||||
| videoList | Array | 视频素材列表 |
|
||||
| showVideoEditOnly | Integer | 是否只显示一键成片(0:否,1:是) |
|
||||
|
||||
#### 图片/视频素材字段说明
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| url | String | 文件访问地址(CDN加速) |
|
||||
| contentType | String | 文件MIME类型 |
|
||||
| path | String | 文件存储路径 |
|
||||
| viewUrl | String | 文件预览地址(图片为缩略图,视频为对应图片缩略图) |
|
||||
|
||||
### 业务逻辑
|
||||
1. **订单验证**: 验证订单号是否存在
|
||||
2. **景区信息获取**: 根据订单获取景区地址信息
|
||||
3. **素材分类查询**: 分别查询图片、视频、AI视频等不同类型的素材
|
||||
4. **URL生成**: 为每个素材生成访问地址和预览地址
|
||||
5. **缩略图关联**: 为视频素材关联对应的图片缩略图
|
||||
6. **功能控制**: 根据二维码设置决定是否返回图片和视频素材
|
||||
|
||||
### 素材类型说明
|
||||
- **AI视频 (aiVideo)**: 系统自动生成的视频,标签为 `ai_video`
|
||||
- **图片素材 (imgList)**: 原始拍摄的图片,文件类型为 `image/jpeg`
|
||||
- **视频素材 (videoList)**: 原始拍摄的视频,标签为 `raw_video`
|
||||
|
||||
### 功能控制说明
|
||||
- **showVideoEditOnly = 1**: 只显示一键成片功能,不返回图片和视频素材
|
||||
- **showVideoEditOnly = 0**: 显示所有功能,返回完整的图片和视频素材
|
||||
|
||||
### 错误码说明
|
||||
| 错误码 | 错误信息 | 说明 |
|
||||
|--------|----------|------|
|
||||
| 1 | 订单不存在 | 订单号无效或订单已被删除 |
|
||||
|
||||
### 使用示例
|
||||
|
||||
#### cURL
|
||||
```bash
|
||||
curl -X GET "http://localhost:8080/api-order/orders/user/files/202501150001" \
|
||||
-H "Authorization: Bearer your_access_token"
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
```javascript
|
||||
const response = await fetch('/api-order/orders/user/files/202501150001', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + accessToken
|
||||
}
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.resp_code === 0) {
|
||||
const data = result.data;
|
||||
console.log('订单时间:', data.time);
|
||||
console.log('景区地址:', data.addr);
|
||||
console.log('AI视频:', data.aiVideo);
|
||||
console.log('图片数量:', data.imgList.length);
|
||||
console.log('视频数量:', data.videoList.length);
|
||||
|
||||
// 处理图片素材
|
||||
data.imgList.forEach((img, index) => {
|
||||
console.log(`图片${index + 1}:`, img.url);
|
||||
console.log(`缩略图${index + 1}:`, img.viewUrl);
|
||||
});
|
||||
|
||||
// 处理视频素材
|
||||
data.videoList.forEach((video, index) => {
|
||||
console.log(`视频${index + 1}:`, video.url);
|
||||
console.log(`视频缩略图${index + 1}:`, video.viewUrl);
|
||||
});
|
||||
} else {
|
||||
console.error('查询失败:', result.resp_msg);
|
||||
}
|
||||
```
|
||||
|
||||
#### 前端展示示例
|
||||
```javascript
|
||||
function renderOrderResources(orderNo) {
|
||||
fetch(`/api-order/orders/user/files/${orderNo}`)
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.resp_code === 0) {
|
||||
const data = result.data;
|
||||
|
||||
// 显示基本信息
|
||||
document.getElementById('orderTime').textContent = data.time;
|
||||
document.getElementById('orderAddress').textContent = data.addr;
|
||||
|
||||
// 显示AI视频
|
||||
if (data.aiVideo) {
|
||||
const aiVideoElement = document.getElementById('aiVideo');
|
||||
aiVideoElement.src = data.aiVideo;
|
||||
aiVideoElement.style.display = 'block';
|
||||
}
|
||||
|
||||
// 显示图片列表
|
||||
const imgContainer = document.getElementById('imageList');
|
||||
imgContainer.innerHTML = '';
|
||||
data.imgList.forEach(img => {
|
||||
const imgElement = document.createElement('img');
|
||||
imgElement.src = img.viewUrl; // 使用缩略图
|
||||
imgElement.onclick = () => window.open(img.url); // 点击查看原图
|
||||
imgContainer.appendChild(imgElement);
|
||||
});
|
||||
|
||||
// 显示视频列表
|
||||
const videoContainer = document.getElementById('videoList');
|
||||
videoContainer.innerHTML = '';
|
||||
data.videoList.forEach(video => {
|
||||
const videoElement = document.createElement('div');
|
||||
videoElement.innerHTML = `
|
||||
<video src="${video.url}" controls></video>
|
||||
<img src="${video.viewUrl}" alt="视频缩略图" />
|
||||
`;
|
||||
videoContainer.appendChild(videoElement);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取订单素材失败:', error);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
### 注意事项
|
||||
1. **权限控制**: 只能查询当前用户自己的订单素材
|
||||
2. **素材完整性**: 返回的素材包括订单关联的所有文件
|
||||
3. **CDN加速**: 所有文件地址都经过CDN加速处理
|
||||
4. **缩略图优化**: 图片提供缩略图版本,提升加载性能
|
||||
5. **功能控制**: 根据二维码设置动态控制素材显示
|
||||
|
||||
### 业务逻辑
|
||||
1. **文件验证**: 验证文件类型、大小等
|
||||
2. **文件上传**: 将文件上传到OSS存储
|
||||
3. **元数据保存**: 保存文件信息到数据库
|
||||
4. **URL生成**: 生成文件的访问地址
|
||||
5. **CDN加速**: 支持CDN加速访问
|
||||
|
||||
### 支持的文件类型
|
||||
- **图片**: jpg, jpeg, png, gif, webp
|
||||
- **视频**: mp4, avi, mov, wmv, flv
|
||||
- **其他**: 支持任意二进制文件
|
||||
|
||||
### 文件大小限制
|
||||
- **默认限制**: 100MB
|
||||
- **可配置**: 通过配置文件调整
|
||||
|
||||
### 使用示例
|
||||
|
||||
#### 文件上传 (cURL)
|
||||
```bash
|
||||
curl -X POST "http://localhost:8080/api-file/files-anon" \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-F "file=@/path/to/video.mp4"
|
||||
```
|
||||
|
||||
#### 文件上传 (JavaScript)
|
||||
```javascript
|
||||
const formData = new FormData();
|
||||
formData.append('file', fileInput.files[0]);
|
||||
|
||||
const response = await fetch('/api-file/files-anon', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.id) {
|
||||
console.log('文件上传成功:', result);
|
||||
console.log('文件访问地址:', result.url);
|
||||
} else {
|
||||
console.error('文件上传失败');
|
||||
}
|
||||
```
|
||||
|
||||
#### 获取文件地址 (JavaScript)
|
||||
```javascript
|
||||
// 根据文件ID获取地址
|
||||
const response = await fetch(`/api-file/files/${fileId}`);
|
||||
const result = await response.json();
|
||||
if (result.resp_code === 0) {
|
||||
console.log('文件地址:', result.data);
|
||||
}
|
||||
|
||||
// 根据路径获取地址
|
||||
const pathResponse = await fetch(`/api-file/files/path?path=${filePath}`);
|
||||
const pathResult = await pathResponse.json();
|
||||
if (pathResult.resp_code === 0) {
|
||||
console.log('文件地址:', pathResult.data);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 注意事项
|
||||
1. **文件安全**: 上传的文件会进行类型和大小验证
|
||||
2. **存储策略**: 支持OSS、S3、MinIO等多种存储方式
|
||||
3. **CDN加速**: 支持CDN预热和刷新功能
|
||||
4. **访问控制**: 文件访问地址支持过期时间设置
|
||||
5. **错误处理**: 上传失败时会返回详细的错误信息
|
||||
|
||||
---
|
||||
|
||||
## 接口调用流程示例
|
||||
|
||||
### 完整的订单创建到视频上传流程
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant User as 用户
|
||||
participant Frontend as 前端
|
||||
participant OrderAPI as 订单API
|
||||
participant FileAPI as 文件API
|
||||
participant OSS as OSS存储
|
||||
|
||||
User->>Frontend: 扫描二维码
|
||||
Frontend->>OrderAPI: 创建订单
|
||||
OrderAPI-->>Frontend: 返回订单信息
|
||||
Frontend->>User: 显示订单详情
|
||||
|
||||
User->>Frontend: 上传视频文件
|
||||
Frontend->>FileAPI: 上传文件到OSS
|
||||
FileAPI->>OSS: 存储文件
|
||||
OSS-->>FileAPI: 返回存储结果
|
||||
FileAPI-->>Frontend: 返回文件信息
|
||||
|
||||
Frontend->>OrderAPI: 关联文件到订单
|
||||
OrderAPI-->>Frontend: 更新订单状态
|
||||
|
||||
Frontend->>User: 显示上传成功
|
||||
```
|
||||
|
||||
### 状态查询流程
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant User as 用户
|
||||
participant Frontend as 前端
|
||||
participant TaskAPI as 任务API
|
||||
participant MediaService as 媒体服务
|
||||
|
||||
User->>Frontend: 查看任务状态
|
||||
Frontend->>TaskAPI: 查询任务状态
|
||||
TaskAPI->>MediaService: 获取媒体处理状态
|
||||
MediaService-->>TaskAPI: 返回处理状态
|
||||
TaskAPI-->>Frontend: 返回任务状态
|
||||
Frontend->>User: 显示状态信息
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 错误处理建议
|
||||
|
||||
### 1. 网络错误处理
|
||||
```javascript
|
||||
try {
|
||||
const response = await fetch(url, options);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const result = await response.json();
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('请求失败:', error);
|
||||
// 显示用户友好的错误信息
|
||||
showErrorMessage('网络请求失败,请稍后重试');
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 业务错误处理
|
||||
```javascript
|
||||
if (result.resp_code === 0) {
|
||||
// 处理成功响应
|
||||
handleSuccess(result.data);
|
||||
} else {
|
||||
// 处理业务错误
|
||||
handleBusinessError(result.resp_msg);
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 重试机制
|
||||
```javascript
|
||||
async function requestWithRetry(url, options, maxRetries = 3) {
|
||||
for (let i = 0; i < maxRetries; i++) {
|
||||
try {
|
||||
return await fetch(url, options);
|
||||
} catch (error) {
|
||||
if (i === maxRetries - 1) throw error;
|
||||
await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 测试建议
|
||||
|
||||
### 1. 接口测试
|
||||
- 使用Postman或类似工具测试各个接口
|
||||
- 验证参数验证、错误处理等
|
||||
- 测试不同文件类型和大小
|
||||
|
||||
### 2. 集成测试
|
||||
- 测试完整的业务流程
|
||||
- 验证订单创建、文件上传、状态查询的联动
|
||||
- 测试异常情况的处理
|
||||
|
||||
### 3. 性能测试
|
||||
- 测试文件上传的性能
|
||||
- 验证大文件上传的稳定性
|
||||
- 测试并发上传的处理能力
|
||||
|
||||
### 4. 安全测试
|
||||
- 验证文件类型限制
|
||||
- 测试文件大小限制
|
||||
- 验证访问权限控制
|
||||
@@ -0,0 +1,90 @@
|
||||
# 订单支付类型字段功能说明
|
||||
|
||||
## 功能概述
|
||||
|
||||
为订单表新增 `payType` 字段,用于区分支付类型是微信支付还是优惠券支付。
|
||||
|
||||
## 数据库变更
|
||||
|
||||
### 新增字段
|
||||
- **字段名**: `pay_type`
|
||||
- **数据类型**: `TINYINT(1)`
|
||||
- **默认值**: `1` (微信支付)
|
||||
- **注释**: 支付类型(1:微信支付,2:优惠券支付)
|
||||
- **位置**: 在 `order_status` 字段之后
|
||||
|
||||
### 索引
|
||||
- 为 `pay_type` 字段创建索引 `idx_pay_type`
|
||||
|
||||
### SQL脚本
|
||||
执行 `sql/add_pay_type_field.sql` 脚本完成数据库变更。
|
||||
|
||||
## 代码变更
|
||||
|
||||
### 1. 实体类 (Order.java)
|
||||
- 新增 `payType` 字段
|
||||
- 添加 Swagger 注解 `@Schema`
|
||||
- 导入相关依赖
|
||||
|
||||
### 2. 枚举类 (PayTypeEnum.java)
|
||||
- `WECHAT_PAY(1, "微信支付")`
|
||||
- `COUPON_PAY(2, "优惠券支付")`
|
||||
- 提供根据 code 获取枚举的方法
|
||||
- 提供验证 code 是否有效的方法
|
||||
|
||||
### 3. 常量类 (PayTypeConstants.java)
|
||||
- 提供前端使用的常量值
|
||||
- `WECHAT_PAY = 1`
|
||||
- `COUPON_PAY = 2`
|
||||
|
||||
## 使用方式
|
||||
|
||||
### 后端使用
|
||||
```java
|
||||
// 设置支付类型
|
||||
order.setPayType(PayTypeEnum.WECHAT_PAY.getCode());
|
||||
|
||||
// 判断支付类型
|
||||
if (PayTypeEnum.WECHAT_PAY.getCode().equals(order.getPayType())) {
|
||||
// 微信支付逻辑
|
||||
} else if (PayTypeEnum.COUPON_PAY.getCode().equals(order.getPayType())) {
|
||||
// 优惠券支付逻辑
|
||||
}
|
||||
|
||||
// 验证支付类型
|
||||
if (PayTypeEnum.isValidCode(payType)) {
|
||||
// 支付类型有效
|
||||
}
|
||||
```
|
||||
|
||||
### 前端使用
|
||||
```typescript
|
||||
// 支付类型选项
|
||||
const payTypeOptions = [
|
||||
{ label: '微信支付', value: 1 },
|
||||
{ label: '优惠券支付', value: 2 }
|
||||
];
|
||||
|
||||
// 显示支付类型
|
||||
const getPayTypeText = (payType: number) => {
|
||||
switch (payType) {
|
||||
case 1: return '微信支付';
|
||||
case 2: return '优惠券支付';
|
||||
default: return '未知';
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **默认值**: 现有订单的 `pay_type` 字段默认为 `1` (微信支付)
|
||||
2. **数据一致性**: 新增订单时必须设置 `pay_type` 字段
|
||||
3. **业务逻辑**: 根据支付类型实现不同的业务逻辑
|
||||
4. **前端展示**: 在订单列表、详情等页面显示支付类型信息
|
||||
|
||||
## 后续扩展
|
||||
|
||||
1. **支付状态**: 可结合支付状态字段,实现更完整的支付流程
|
||||
2. **支付记录**: 可扩展支付记录表,记录详细的支付信息
|
||||
3. **优惠券管理**: 可结合优惠券系统,实现优惠券支付逻辑
|
||||
4. **统计分析**: 可基于支付类型进行订单统计分析
|
||||
@@ -0,0 +1,149 @@
|
||||
# 订单支付类型字段功能完整说明
|
||||
|
||||
## 功能概述
|
||||
|
||||
为订单表新增 `payType` 字段,用于区分支付类型是微信支付还是优惠券支付。同时修改任务列表显示支付类型,并修改首页统计只统计微信支付的订单。
|
||||
|
||||
## 数据库变更
|
||||
|
||||
### 新增字段
|
||||
- **字段名**: `pay_type`
|
||||
- **数据类型**: `TINYINT(1)`
|
||||
- **默认值**: `1` (微信支付)
|
||||
- **注释**: 支付类型(1:微信支付,2:优惠券支付)
|
||||
- **位置**: 在 `order_status` 字段之后
|
||||
|
||||
### 索引
|
||||
- 为 `pay_type` 字段创建索引 `idx_pay_type`
|
||||
|
||||
### SQL脚本
|
||||
执行 `sql/add_pay_type_field.sql` 脚本完成数据库变更。
|
||||
|
||||
## 代码变更
|
||||
|
||||
### 1. 实体类 (Order.java)
|
||||
- 新增 `payType` 字段
|
||||
- 添加 Swagger 注解 `@Schema`
|
||||
- 导入相关依赖
|
||||
|
||||
### 2. 枚举类 (PayTypeEnum.java)
|
||||
- `WECHAT_PAY(1, "微信支付")`
|
||||
- `COUPON_PAY(2, "优惠券支付")`
|
||||
- 提供根据 code 获取枚举的方法
|
||||
- 提供验证 code 是否有效的方法
|
||||
|
||||
### 3. 常量类 (PayTypeConstants.java)
|
||||
- 提供前端使用的常量值
|
||||
- `WECHAT_PAY = 1`
|
||||
- `COUPON_PAY = 2`
|
||||
|
||||
### 4. 前端类型定义 (typings.d.ts)
|
||||
- 在 `Order` 类型中添加 `payType?: number` 字段
|
||||
|
||||
### 5. 前端订单列表页面 (Order/index.tsx)
|
||||
- 新增支付类型列显示
|
||||
- 新增支付类型筛选功能
|
||||
- 支付类型标签颜色区分(微信支付:绿色,优惠券支付:蓝色)
|
||||
|
||||
### 6. 后端统计接口 (DashboardMapper.java)
|
||||
- 所有统计查询都添加支付类型条件:`AND (o.pay_type = 1 OR o.pay_type IS NULL)`
|
||||
- 确保首页统计只统计微信支付的订单
|
||||
- 包括以下统计方法:
|
||||
- `getTotalOrders` - 总订单数
|
||||
- `getTodayOrders` - 今日订单数
|
||||
- `getYesterdayOrders` - 昨日订单数
|
||||
- `getCompletedOrders` - 已完成订单数
|
||||
- `getTotalPaidOrders` - 总收款订单数
|
||||
- `getTodayPaidOrders` - 今日收款订单数
|
||||
- `getRefundedOrders` - 退款订单数
|
||||
- `getTodayRefundedOrders` - 今日退款订单数
|
||||
- `getTotalAmount` - 总金额
|
||||
- `getRefundAmount` - 退款金额
|
||||
- `getOrderTrend` - 订单趋势
|
||||
- `getOrderDistribution` - 订单状态分布
|
||||
- `getPlatformDistribution` - 平台分账统计
|
||||
- `getQrcodeOrderCount` - 二维码订单统计
|
||||
|
||||
## 使用方式
|
||||
|
||||
### 后端使用
|
||||
```java
|
||||
// 设置支付类型
|
||||
order.setPayType(PayTypeEnum.WECHAT_PAY.getCode());
|
||||
|
||||
// 判断支付类型
|
||||
if (PayTypeEnum.WECHAT_PAY.getCode().equals(order.getPayType())) {
|
||||
// 微信支付逻辑
|
||||
} else if (PayTypeEnum.COUPON_PAY.getCode().equals(order.getPayType())) {
|
||||
// 优惠券支付逻辑
|
||||
}
|
||||
|
||||
// 验证支付类型
|
||||
if (PayTypeEnum.isValidCode(payType)) {
|
||||
// 支付类型有效
|
||||
}
|
||||
```
|
||||
|
||||
### 前端使用
|
||||
```typescript
|
||||
// 支付类型选项
|
||||
const payTypeOptions = [
|
||||
{ label: '微信支付', value: 1 },
|
||||
{ label: '优惠券支付', value: 2 }
|
||||
];
|
||||
|
||||
// 显示支付类型
|
||||
const getPayTypeText = (payType: number) => {
|
||||
switch (payType) {
|
||||
case 1: return '微信支付';
|
||||
case 2: return '优惠券支付';
|
||||
default: return '未知';
|
||||
}
|
||||
};
|
||||
|
||||
// 支付类型标签颜色
|
||||
const getPayTypeColor = (payType: number) => {
|
||||
return payType === 1 ? 'green' : 'blue';
|
||||
};
|
||||
```
|
||||
|
||||
## 功能特点
|
||||
|
||||
### 1. 任务列表显示支付类型
|
||||
- 新增支付类型列,显示支付方式
|
||||
- 支持按支付类型筛选订单
|
||||
- 支付类型标签颜色区分,提升用户体验
|
||||
|
||||
### 2. 首页统计只统计微信支付
|
||||
- 所有统计查询默认只统计微信支付订单
|
||||
- 确保统计数据的一致性和准确性
|
||||
- 支持通过参数扩展统计其他支付类型(如需要)
|
||||
|
||||
### 3. 数据一致性
|
||||
- 现有订单的 `pay_type` 字段默认为 `1` (微信支付)
|
||||
- 新增订单时必须设置 `pay_type` 字段
|
||||
- 统计查询包含 `IS NULL` 条件,兼容历史数据
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **默认值**: 现有订单的 `pay_type` 字段默认为 `1` (微信支付)
|
||||
2. **数据一致性**: 新增订单时必须设置 `pay_type` 字段
|
||||
3. **业务逻辑**: 根据支付类型实现不同的业务逻辑
|
||||
4. **前端展示**: 在订单列表、详情等页面显示支付类型信息
|
||||
5. **统计准确性**: 首页统计默认只统计微信支付订单,确保数据准确性
|
||||
|
||||
## 后续扩展
|
||||
|
||||
1. **支付状态**: 可结合支付状态字段,实现更完整的支付流程
|
||||
2. **支付记录**: 可扩展支付记录表,记录详细的支付信息
|
||||
3. **优惠券管理**: 可结合优惠券系统,实现优惠券支付逻辑
|
||||
4. **统计分析**: 可基于支付类型进行订单统计分析
|
||||
5. **多支付方式**: 可扩展支持支付宝、银行卡等其他支付方式
|
||||
|
||||
## 测试建议
|
||||
|
||||
1. **数据库测试**: 验证字段添加和索引创建
|
||||
2. **后端测试**: 验证统计接口只返回微信支付订单
|
||||
3. **前端测试**: 验证支付类型列显示和筛选功能
|
||||
4. **数据迁移**: 验证现有订单数据正确设置默认值
|
||||
5. **业务逻辑**: 验证不同支付类型的业务处理逻辑
|
||||
@@ -0,0 +1,20 @@
|
||||
-- 为订单表添加支付类型字段
|
||||
-- 执行前请备份数据库
|
||||
|
||||
USE `order-center`;
|
||||
|
||||
-- 1. 添加 payType 字段
|
||||
ALTER TABLE `orders`
|
||||
ADD COLUMN `pay_type` TINYINT(1) DEFAULT 1 COMMENT '支付类型(1:微信支付,2:优惠券支付)'
|
||||
AFTER `order_status`;
|
||||
|
||||
-- 2. 为 payType 字段添加索引
|
||||
CREATE INDEX `idx_pay_type` ON `orders`(`pay_type`);
|
||||
|
||||
-- 3. 更新现有订单的支付类型(默认为微信支付)
|
||||
UPDATE `orders` SET `pay_type` = 1 WHERE `pay_type` IS NULL;
|
||||
|
||||
-- 4. 验证字段添加成功
|
||||
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'orders' AND COLUMN_NAME = 'pay_type';
|
||||
+71
@@ -45,6 +45,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Order information
|
||||
@@ -780,8 +781,20 @@ public class OrderController {
|
||||
* @return
|
||||
*/
|
||||
private String appendPriceStr(String str){
|
||||
// 参数验证
|
||||
if (str == null || str.trim().isEmpty()) {
|
||||
return "0.00";
|
||||
}
|
||||
|
||||
// 获取字符串长度
|
||||
int length = str.length();
|
||||
|
||||
// 处理长度小于2的情况
|
||||
if (length == 1) {
|
||||
return "0.0" + str;
|
||||
} else if (length == 0) {
|
||||
return "0.00";
|
||||
}
|
||||
|
||||
// 获取除了最后两位字符之外的部分
|
||||
String prefix = str.substring(0, length - 2);
|
||||
@@ -1149,4 +1162,62 @@ public class OrderController {
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
@Operation(summary = "更新订单状态为已支付(优惠券核销成功后调用)")
|
||||
@PostMapping("/order/{orderNo}/status/paid")
|
||||
public Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo) {
|
||||
log.info("优惠券核销成功,更新订单状态为已支付,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
log.error("订单不存在,orderNo: {}", orderNo);
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
|
||||
// 检查订单当前状态
|
||||
if (order.getOrderStatus().equals(OrderStatus.UNPAID.getId())) {
|
||||
// 更新订单状态为已支付排队中
|
||||
order.setOrderStatus(OrderStatus.PAID.getId());
|
||||
// 设置支付类型为优惠券支付
|
||||
order.setPayType(2); // 2表示优惠券支付
|
||||
// 设置支付时间
|
||||
order.setPayTime(new Date());
|
||||
|
||||
boolean result = orderService.updateOrder(order);
|
||||
if (result) {
|
||||
log.info("订单状态更新成功,orderNo: {}, 新状态: {}", orderNo, OrderStatus.PAID.getId());
|
||||
return Result.succeed("订单状态更新成功");
|
||||
} else {
|
||||
log.error("订单状态更新失败,orderNo: {}", orderNo);
|
||||
return Result.failed("订单状态更新失败");
|
||||
}
|
||||
} else {
|
||||
log.warn("订单状态不正确,无法更新为已支付,orderNo: {}, 当前状态: {}",
|
||||
orderNo, order.getOrderStatus());
|
||||
return Result.failed("订单状态不正确,无法更新为已支付");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单状态异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("更新订单状态异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "根据订单号获取订单信息")
|
||||
@GetMapping("/order/{orderNo}")
|
||||
public Result<Order> getOrderByOrderNo(@PathVariable("orderNo") String orderNo) {
|
||||
log.info("根据订单号获取订单信息,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
return Result.succeed(order);
|
||||
} catch (Exception e) {
|
||||
log.error("获取订单信息异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("获取订单信息异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-6
@@ -86,8 +86,8 @@ public class DateMetaObjectHandler implements MetaObjectHandler {
|
||||
// 如果无法获取字段类型,使用默认的Date类型
|
||||
}
|
||||
|
||||
// 默认使用LocalDateTime,因为这是更现代的时间类型
|
||||
return LocalDateTime.now();
|
||||
// 默认使用Date类型,因为大多数实体类都使用Date
|
||||
return new Date();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,10 +107,19 @@ public class DateMetaObjectHandler implements MetaObjectHandler {
|
||||
Object originalObject = metaObject.getOriginalObject();
|
||||
if (originalObject != null) {
|
||||
try {
|
||||
java.lang.reflect.Field field = originalObject.getClass().getDeclaredField(fieldName);
|
||||
return field.getType();
|
||||
} catch (NoSuchFieldException e) {
|
||||
// 字段不存在,忽略
|
||||
// 递归查找字段,包括父类中的字段
|
||||
Class<?> currentClass = originalObject.getClass();
|
||||
while (currentClass != null && currentClass != Object.class) {
|
||||
try {
|
||||
java.lang.reflect.Field field = currentClass.getDeclaredField(fieldName);
|
||||
return field.getType();
|
||||
} catch (NoSuchFieldException e) {
|
||||
// 当前类中没有找到,继续查找父类
|
||||
currentClass = currentClass.getSuperclass();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 忽略异常,使用默认类型
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user