fix(优惠券中心):新增订单支付类型后,优惠券查询逻辑优化
This commit is contained in:
+3
-3
@@ -57,14 +57,14 @@ public class OrderDetailController {
|
|||||||
private CtripOrderItemMapper ctripOrderItemMapper;
|
private CtripOrderItemMapper ctripOrderItemMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据手机号和优惠券价格查询可核销的订单明细
|
* 根据二维码ID查询可核销的订单明细
|
||||||
*
|
*
|
||||||
* @param queryDTO 查询条件
|
* @param queryDTO 查询条件(codeId、page、size)
|
||||||
* @return 订单明细分页结果
|
* @return 订单明细分页结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("/query")
|
@PostMapping("/query")
|
||||||
public Result<PageResult<OrderDetailVO>> queryOrderDetails(@Valid @RequestBody OrderQueryDTO queryDTO) {
|
public Result<PageResult<OrderDetailVO>> queryOrderDetails(@Valid @RequestBody OrderQueryDTO queryDTO) {
|
||||||
log.info("查询可核销订单明细,手机号: {}, 优惠券价格: {}", queryDTO.getUserPhone(), queryDTO.getCouponPrice());
|
log.info("查询可核销订单明细,codeId: {},page: {},size: {}", queryDTO.getCodeId(), queryDTO.getPage(), queryDTO.getSize());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PageResult<OrderDetailVO> result = orderDetailService.queryOrderDetails(queryDTO);
|
PageResult<OrderDetailVO> result = orderDetailService.queryOrderDetails(queryDTO);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.central.coupon.dto;
|
package com.central.coupon.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单查询DTO
|
* 订单查询DTO
|
||||||
@@ -10,17 +9,12 @@ import java.math.BigDecimal;
|
|||||||
public class OrderQueryDTO {
|
public class OrderQueryDTO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户手机号
|
* 二维码ID(来自订单的codeId)
|
||||||
*/
|
*/
|
||||||
private String userPhone;
|
private String codeId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优惠券价格(用于筛选匹配的订单)
|
* 是否只查询可核销的订单(内部控制,前端不必传,默认true)
|
||||||
*/
|
|
||||||
private BigDecimal couponPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否只查询可核销的订单
|
|
||||||
*/
|
*/
|
||||||
private Boolean onlyConsumable = true;
|
private Boolean onlyConsumable = true;
|
||||||
|
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
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 org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, dismiss404 = true)
|
||||||
|
public interface OrderCenterService {
|
||||||
|
@GetMapping("/qrcode/{codeId}")
|
||||||
|
Result<QrCodeInfo> getQrCode(@PathVariable("codeId") String codeId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.central.coupon.feign.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QrCodeInfo {
|
||||||
|
private String codeId;
|
||||||
|
private String price;
|
||||||
|
}
|
||||||
+2
-2
@@ -11,9 +11,9 @@ import com.central.common.model.PageResult;
|
|||||||
public interface IOrderDetailService {
|
public interface IOrderDetailService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据手机号和价格查询订单明细
|
* 根据二维码ID及分页参数查询订单明细
|
||||||
*
|
*
|
||||||
* @param queryDTO 查询条件
|
* @param queryDTO 查询条件(codeId、page、size)
|
||||||
* @return 订单明细分页结果
|
* @return 订单明细分页结果
|
||||||
*/
|
*/
|
||||||
PageResult<OrderDetailVO> queryOrderDetails(OrderQueryDTO queryDTO);
|
PageResult<OrderDetailVO> queryOrderDetails(OrderQueryDTO queryDTO);
|
||||||
|
|||||||
+43
-21
@@ -32,6 +32,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import com.central.coupon.dto.ConsumeItemDTO;
|
import com.central.coupon.dto.ConsumeItemDTO;
|
||||||
|
import com.central.coupon.feign.OrderCenterService;
|
||||||
|
import com.central.coupon.feign.dto.QrCodeInfo;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.common.context.LoginUserContextHolder;
|
||||||
|
import com.central.common.model.LoginAppUser;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单明细服务实现类
|
* 订单明细服务实现类
|
||||||
@@ -58,15 +64,42 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CtripConsumedService ctripConsumedService;
|
private CtripConsumedService ctripConsumedService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderCenterService orderCenterService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<OrderDetailVO> queryOrderDetails(OrderQueryDTO queryDTO) {
|
public PageResult<OrderDetailVO> queryOrderDetails(OrderQueryDTO queryDTO) {
|
||||||
log.info("查询可核销订单明细,手机号: {}, 优惠券价格: {}", queryDTO.getUserPhone(), queryDTO.getCouponPrice());
|
log.info("查询可核销订单明细,codeId: {},page: {},size: {}", queryDTO.getCodeId(), queryDTO.getPage(), queryDTO.getSize());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 0. 从登录上下文获取用户手机号
|
||||||
|
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||||
|
String userPhone = user != null ? user.getMobile() : null;
|
||||||
|
log.info("当前登录用户手机号: {}", userPhone);
|
||||||
|
|
||||||
|
// 0.1 通过codeId调用订单中心获取二维码信息,得到价格
|
||||||
|
BigDecimal couponPrice = null;
|
||||||
|
if (!StringUtils.isEmpty(queryDTO.getCodeId())) {
|
||||||
|
Result<QrCodeInfo> qrResp = orderCenterService.getQrCode(queryDTO.getCodeId());
|
||||||
|
if (qrResp != null && qrResp.getResp_code() != null && qrResp.getResp_code() == 0 && qrResp.getData() != null) {
|
||||||
|
QrCodeInfo qr = qrResp.getData();
|
||||||
|
if (qr.getPrice() != null) {
|
||||||
|
try {
|
||||||
|
couponPrice = new BigDecimal(qr.getPrice());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.warn("二维码价格解析失败, price={}, codeId={}", qr.getPrice(), queryDTO.getCodeId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("订单中心查询二维码失败,codeId={}, resp={}", queryDTO.getCodeId(), qrResp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("根据二维码获得价格: {}", couponPrice);
|
||||||
|
|
||||||
// 1. 根据手机号查询订单
|
// 1. 根据手机号查询订单
|
||||||
List<CtripOrder> orders = findOrdersByPhone(queryDTO.getUserPhone());
|
List<CtripOrder> orders = findOrdersByPhone(userPhone);
|
||||||
if (orders == null || orders.isEmpty()) {
|
if (orders == null || orders.isEmpty()) {
|
||||||
log.info("未找到手机号 {} 的订单", queryDTO.getUserPhone());
|
log.info("未找到手机号 {} 的订单", userPhone);
|
||||||
return PageResult.<OrderDetailVO>builder()
|
return PageResult.<OrderDetailVO>builder()
|
||||||
.data(new ArrayList<>())
|
.data(new ArrayList<>())
|
||||||
.count(0L)
|
.count(0L)
|
||||||
@@ -74,8 +107,8 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 筛选符合条件的订单
|
// 2. 筛选符合条件的订单(使用从二维码获取的价格)
|
||||||
List<CtripOrder> filteredOrders = filterOrders(orders, queryDTO);
|
List<CtripOrder> filteredOrders = filterOrdersByPriceAndConsumable(orders, couponPrice, queryDTO.getOnlyConsumable());
|
||||||
|
|
||||||
// 3. 分页处理
|
// 3. 分页处理
|
||||||
int startIndex = (queryDTO.getPage() - 1) * queryDTO.getSize();
|
int startIndex = (queryDTO.getPage() - 1) * queryDTO.getSize();
|
||||||
@@ -263,40 +296,29 @@ public class OrderDetailServiceImpl implements IOrderDetailService {
|
|||||||
return orders;
|
return orders;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private List<CtripOrder> filterOrdersByPriceAndConsumable(List<CtripOrder> orders, BigDecimal couponPrice, Boolean onlyConsumable) {
|
||||||
* 筛选订单
|
|
||||||
*/
|
|
||||||
private List<CtripOrder> filterOrders(List<CtripOrder> orders, OrderQueryDTO queryDTO) {
|
|
||||||
log.info("开始筛选订单,原始订单数量: {}", orders.size());
|
log.info("开始筛选订单,原始订单数量: {}", orders.size());
|
||||||
|
|
||||||
List<CtripOrder> filteredOrders = orders.stream()
|
List<CtripOrder> filteredOrders = orders.stream()
|
||||||
.filter(order -> {
|
.filter(order -> {
|
||||||
log.debug("筛选订单: otaOrderId={}, totalAmount={}", order.getOtaOrderId(), order.getTotalAmount());
|
log.debug("筛选订单: otaOrderId={}, totalAmount={}", order.getOtaOrderId(), order.getTotalAmount());
|
||||||
|
if (couponPrice != null) {
|
||||||
// 按优惠券价格筛选
|
if (order.getTotalAmount() == null || !order.getTotalAmount().equals(couponPrice)) {
|
||||||
if (queryDTO.getCouponPrice() != null) {
|
|
||||||
if (order.getTotalAmount() == null ||
|
|
||||||
!order.getTotalAmount().equals(queryDTO.getCouponPrice())) {
|
|
||||||
log.debug("订单 {} 价格不匹配,期望: {}, 实际: {}",
|
log.debug("订单 {} 价格不匹配,期望: {}, 实际: {}",
|
||||||
order.getOtaOrderId(), queryDTO.getCouponPrice(), order.getTotalAmount());
|
order.getOtaOrderId(), couponPrice, order.getTotalAmount());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
log.debug("订单 {} 价格匹配", order.getOtaOrderId());
|
log.debug("订单 {} 价格匹配", order.getOtaOrderId());
|
||||||
}
|
}
|
||||||
|
if (onlyConsumable != null && onlyConsumable) {
|
||||||
// 如果只查询可核销订单,则过滤掉不可核销的订单
|
|
||||||
if (queryDTO.getOnlyConsumable() != null && queryDTO.getOnlyConsumable()) {
|
|
||||||
if (!validateOrderForConsume(order.getOtaOrderId())) {
|
if (!validateOrderForConsume(order.getOtaOrderId())) {
|
||||||
log.debug("订单 {} 不可核销", order.getOtaOrderId());
|
log.debug("订单 {} 不可核销", order.getOtaOrderId());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
log.debug("订单 {} 可核销", order.getOtaOrderId());
|
log.debug("订单 {} 可核销", order.getOtaOrderId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
log.info("筛选后订单数量: {}", filteredOrders.size());
|
log.info("筛选后订单数量: {}", filteredOrders.size());
|
||||||
return filteredOrders;
|
return filteredOrders;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ logging:
|
|||||||
ctrip:
|
ctrip:
|
||||||
# AES加密配置
|
# AES加密配置
|
||||||
aes:
|
aes:
|
||||||
key: 087b36ad0dff7942 # 为实际的AES密钥
|
key: 6196f64f4f6e5dca # 为实际的AES密钥
|
||||||
iv: 750e15a31356a99d # 为实际的AES IV
|
iv: 28405d20246ecccd # 为实际的AES IV
|
||||||
# 签名配置(使用账户密钥进行签名计算)
|
# 签名配置(使用账户密钥进行签名计算)
|
||||||
# API配置
|
# API配置
|
||||||
api:
|
api:
|
||||||
@@ -59,10 +59,10 @@ ctrip:
|
|||||||
# 生产环境URL
|
# 生产环境URL
|
||||||
prod-url: https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier
|
prod-url: https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier
|
||||||
# 当前环境(test/prod)
|
# 当前环境(test/prod)
|
||||||
environment: test
|
environment: prod
|
||||||
timeout: 30000 # 请求超时时间(毫秒)
|
timeout: 30000 # 请求超时时间(毫秒)
|
||||||
retry-times: 3 # 重试次数
|
retry-times: 3 # 重试次数
|
||||||
# 账户配置
|
# 账户配置
|
||||||
account:
|
account:
|
||||||
id: c50a8f2a4a59c9e7 # 为实际的账户ID
|
id: e02647943fdfb4c5 # 为实际的账户ID
|
||||||
secret: ce6033ae31124ec5cdab3d2bc79f2622 # 实际的账户密钥
|
secret: 0b4f4dabb50999cb04a773fc96f81499 # 实际的账户密钥
|
||||||
|
|||||||
+5
-12
@@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -29,9 +28,7 @@ public class OrderDetailServiceTest {
|
|||||||
public void testQueryOrderDetails() {
|
public void testQueryOrderDetails() {
|
||||||
// 准备测试数据
|
// 准备测试数据
|
||||||
OrderQueryDTO queryDTO = new OrderQueryDTO();
|
OrderQueryDTO queryDTO = new OrderQueryDTO();
|
||||||
queryDTO.setUserPhone("13800138000");
|
queryDTO.setCodeId("test-code-id");
|
||||||
queryDTO.setCouponPrice(new BigDecimal("100.00"));
|
|
||||||
queryDTO.setOnlyConsumable(true);
|
|
||||||
queryDTO.setPage(1);
|
queryDTO.setPage(1);
|
||||||
queryDTO.setSize(10);
|
queryDTO.setSize(10);
|
||||||
|
|
||||||
@@ -100,12 +97,10 @@ public class OrderDetailServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryOrderDetailsWithEmptyPhone() {
|
public void testQueryOrderDetailsWithEmptyCodeId() {
|
||||||
// 准备测试数据
|
// 准备测试数据
|
||||||
OrderQueryDTO queryDTO = new OrderQueryDTO();
|
OrderQueryDTO queryDTO = new OrderQueryDTO();
|
||||||
queryDTO.setUserPhone(""); // 空手机号
|
queryDTO.setCodeId("");
|
||||||
queryDTO.setCouponPrice(new BigDecimal("100.00"));
|
|
||||||
queryDTO.setOnlyConsumable(true);
|
|
||||||
queryDTO.setPage(1);
|
queryDTO.setPage(1);
|
||||||
queryDTO.setSize(10);
|
queryDTO.setSize(10);
|
||||||
|
|
||||||
@@ -120,12 +115,10 @@ public class OrderDetailServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryOrderDetailsWithNullPhone() {
|
public void testQueryOrderDetailsWithNullCodeId() {
|
||||||
// 准备测试数据
|
// 准备测试数据
|
||||||
OrderQueryDTO queryDTO = new OrderQueryDTO();
|
OrderQueryDTO queryDTO = new OrderQueryDTO();
|
||||||
queryDTO.setUserPhone(null); // null手机号
|
queryDTO.setCodeId(null);
|
||||||
queryDTO.setCouponPrice(new BigDecimal("100.00"));
|
|
||||||
queryDTO.setOnlyConsumable(true);
|
|
||||||
queryDTO.setPage(1);
|
queryDTO.setPage(1);
|
||||||
queryDTO.setSize(10);
|
queryDTO.setSize(10);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user