fix(文件中心):修复冷数据访问问题彻底修复,携程回调流程数据解析完成
This commit is contained in:
+175
-4
@@ -27,6 +27,8 @@ import com.central.order.model.CtripCreateOrderRequest.CtripContact;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripHeader;
|
||||
|
||||
import com.central.order.model.CtripCreateOrderResponse;
|
||||
import com.central.order.model.CtripConsumedNoticeRequest;
|
||||
import com.central.order.model.CtripConsumedNoticeResponse;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.util.CtripDecryptUtil;
|
||||
import java.util.ArrayList;
|
||||
@@ -379,6 +381,58 @@ public class CouponController {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程核销通知成功响应
|
||||
*/
|
||||
private CtripConsumedNoticeResponse buildConsumedNoticeSuccessResponse(CtripConsumedNoticeRequest request, String message) {
|
||||
CtripConsumedNoticeResponse response = new CtripConsumedNoticeResponse();
|
||||
|
||||
// 设置返回头
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader responseHeader = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader();
|
||||
responseHeader.setRequestTime(request.getHeader().getRequestTime());
|
||||
responseHeader.setAccountId(request.getHeader().getAccountId());
|
||||
responseHeader.setSign(request.getHeader().getSign());
|
||||
responseHeader.setServiceName(request.getHeader().getServiceName());
|
||||
responseHeader.setVersion(request.getHeader().getVersion());
|
||||
response.setHeader(responseHeader);
|
||||
|
||||
// 设置返回码
|
||||
response.setResultCode("0000");
|
||||
response.setResultMessage("操作成功");
|
||||
|
||||
// 设置返回体
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody responseBody = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody();
|
||||
responseBody.setOtaOrderId(request.getBody().getOtaOrderId());
|
||||
responseBody.setSupplierOrderId(request.getBody().getSupplierOrderId());
|
||||
responseBody.setProcessResult(message);
|
||||
responseBody.setProcessTime(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
response.setBody(responseBody);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程核销通知错误响应
|
||||
*/
|
||||
private CtripConsumedNoticeResponse buildConsumedNoticeErrorResponse(CtripConsumedNoticeRequest request, String resultCode, String resultMessage) {
|
||||
CtripConsumedNoticeResponse response = new CtripConsumedNoticeResponse();
|
||||
|
||||
// 设置返回头
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader responseHeader = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader();
|
||||
responseHeader.setRequestTime(request.getHeader().getRequestTime());
|
||||
responseHeader.setAccountId(request.getHeader().getAccountId());
|
||||
responseHeader.setSign(request.getHeader().getSign());
|
||||
responseHeader.setServiceName(request.getHeader().getServiceName());
|
||||
responseHeader.setVersion(request.getHeader().getVersion());
|
||||
response.setHeader(responseHeader);
|
||||
|
||||
// 设置返回码
|
||||
response.setResultCode(resultCode);
|
||||
response.setResultMessage(resultMessage);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程创建优惠券接口 - 备用方法
|
||||
*/
|
||||
@@ -527,6 +581,67 @@ public class CouponController {
|
||||
return Result.succeed("批量更新过期优惠券成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程核销通知接口
|
||||
* 接收携程的核销通知,更新本地优惠券状态
|
||||
*/
|
||||
@Operation(summary = "携程核销通知接口")
|
||||
@PostMapping("/ctrip/consumed-notice")
|
||||
public CtripConsumedNoticeResponse consumedNotice(@RequestBody CtripConsumedNoticeRequest request) {
|
||||
log.info("收到携程核销通知:{}", request);
|
||||
|
||||
try {
|
||||
// 验证签名
|
||||
Map<String, String> signParams = new HashMap<>();
|
||||
signParams.put("accountId", request.getHeader().getAccountId());
|
||||
signParams.put("serviceName", request.getHeader().getServiceName());
|
||||
signParams.put("requestTime", request.getHeader().getRequestTime());
|
||||
signParams.put("version", request.getHeader().getVersion());
|
||||
signParams.put("body", request.getBody().toString()); // 这里需要根据实际情况调整
|
||||
|
||||
if (!ctripDecryptUtil.verifySign(signParams, request.getHeader().getSign())) {
|
||||
log.error("携程核销通知签名验证失败");
|
||||
return buildConsumedNoticeErrorResponse(request, "0001", "签名验证失败");
|
||||
}
|
||||
|
||||
// 解析核销信息
|
||||
String otaOrderId = request.getBody().getOtaOrderId();
|
||||
String supplierOrderId = request.getBody().getSupplierOrderId();
|
||||
String consumedTime = request.getBody().getConsumedTime();
|
||||
String consumedLocation = request.getBody().getConsumedLocation();
|
||||
|
||||
log.info("核销信息 - otaOrderId: {}, supplierOrderId: {}, consumedTime: {}, consumedLocation: {}",
|
||||
otaOrderId, supplierOrderId, consumedTime, consumedLocation);
|
||||
|
||||
// 查找对应的优惠券
|
||||
Coupon coupon = couponService.getByCtripCouponId(otaOrderId);
|
||||
if (coupon == null) {
|
||||
log.error("未找到对应的携程优惠券,otaOrderId: {}", otaOrderId);
|
||||
return buildConsumedNoticeErrorResponse(request, "0002", "未找到对应的优惠券");
|
||||
}
|
||||
|
||||
// 检查优惠券状态
|
||||
if (coupon.getStatus() != 0) {
|
||||
log.warn("优惠券状态不正确,couponId: {}, status: {}", coupon.getId(), coupon.getStatus());
|
||||
return buildConsumedNoticeErrorResponse(request, "0003", "优惠券状态不正确");
|
||||
}
|
||||
|
||||
// 更新优惠券状态为已使用
|
||||
boolean updateResult = couponService.updateCouponConsumed(coupon.getId(), supplierOrderId, consumedTime);
|
||||
if (!updateResult) {
|
||||
log.error("更新优惠券状态失败,couponId: {}", coupon.getId());
|
||||
return buildConsumedNoticeErrorResponse(request, "0004", "更新优惠券状态失败");
|
||||
}
|
||||
|
||||
log.info("携程优惠券核销成功,couponId: {}, otaOrderId: {}", coupon.getId(), otaOrderId);
|
||||
return buildConsumedNoticeSuccessResponse(request, "核销成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程核销通知失败", e);
|
||||
return buildConsumedNoticeErrorResponse(request, "9999", "系统异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 时间解析工具
|
||||
private Date parseDate(String dateStr) {
|
||||
try {
|
||||
@@ -917,8 +1032,10 @@ public class CouponController {
|
||||
}
|
||||
|
||||
log.info("body数据解密成功,解密后数据长度: {}", decryptedBody.length());
|
||||
log.debug("解密后数据前200个字符: {}",
|
||||
decryptedBody.length() > 200 ? decryptedBody.substring(0, 200) + "..." : decryptedBody);
|
||||
log.info("解密后数据前500个字符: {}",
|
||||
decryptedBody.length() > 500 ? decryptedBody.substring(0, 500) + "..." : decryptedBody);
|
||||
log.info("解密后数据后500个字符: {}",
|
||||
decryptedBody.length() > 500 ? "..." + decryptedBody.substring(decryptedBody.length() - 500) : decryptedBody);
|
||||
|
||||
// 解析解密后的JSON
|
||||
try {
|
||||
@@ -932,7 +1049,34 @@ public class CouponController {
|
||||
|
||||
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
body = objectMapper.readValue(decryptedBody, CtripOrderBody.class);
|
||||
|
||||
// 尝试解析为订单项(item)
|
||||
try {
|
||||
CtripOrderItem item = objectMapper.readValue(decryptedBody, CtripOrderItem.class);
|
||||
log.info("成功解析为订单项,创建订单体");
|
||||
|
||||
// 创建订单体,将解析的订单项放入items数组
|
||||
body = new CtripOrderBody();
|
||||
body.setItems(java.util.Arrays.asList(item));
|
||||
body.setLocale("zh-CN"); // 设置默认locale
|
||||
|
||||
// 如果有乘客信息,提取联系人信息
|
||||
if (item.getPassengers() != null && !item.getPassengers().isEmpty()) {
|
||||
CtripPassenger passenger = item.getPassengers().get(0);
|
||||
CtripContact contact = new CtripContact();
|
||||
contact.setName(passenger.getName());
|
||||
contact.setMobile(passenger.getMobile());
|
||||
contact.setIntlCode(passenger.getIntlCode());
|
||||
body.setContacts(java.util.Arrays.asList(contact));
|
||||
}
|
||||
|
||||
} catch (Exception itemParseException) {
|
||||
log.info("解析为订单项失败,尝试解析为订单体: {}", itemParseException.getMessage());
|
||||
|
||||
// 如果解析为订单项失败,尝试解析为订单体
|
||||
body = objectMapper.readValue(decryptedBody, CtripOrderBody.class);
|
||||
}
|
||||
|
||||
log.info("成功解析解密后的JSON数据");
|
||||
} catch (Exception e) {
|
||||
log.error("解析解密后的JSON数据失败:{}", e.getMessage());
|
||||
@@ -1037,7 +1181,34 @@ public class CouponController {
|
||||
try {
|
||||
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
CtripOrderBody body = objectMapper.readValue(decryptedData, CtripOrderBody.class);
|
||||
|
||||
// 尝试解析为订单项(item)
|
||||
CtripOrderBody body = null;
|
||||
try {
|
||||
CtripOrderItem item = objectMapper.readValue(decryptedData, CtripOrderItem.class);
|
||||
log.info("成功解析为订单项,创建订单体");
|
||||
|
||||
// 创建订单体,将解析的订单项放入items数组
|
||||
body = new CtripOrderBody();
|
||||
body.setItems(java.util.Arrays.asList(item));
|
||||
body.setLocale("zh-CN"); // 设置默认locale
|
||||
|
||||
// 如果有乘客信息,提取联系人信息
|
||||
if (item.getPassengers() != null && !item.getPassengers().isEmpty()) {
|
||||
CtripPassenger passenger = item.getPassengers().get(0);
|
||||
CtripContact contact = new CtripContact();
|
||||
contact.setName(passenger.getName());
|
||||
contact.setMobile(passenger.getMobile());
|
||||
contact.setIntlCode(passenger.getIntlCode());
|
||||
body.setContacts(java.util.Arrays.asList(contact));
|
||||
}
|
||||
|
||||
} catch (Exception itemParseException) {
|
||||
log.info("解析为订单项失败,尝试解析为订单体: {}", itemParseException.getMessage());
|
||||
|
||||
// 如果解析为订单项失败,尝试解析为订单体
|
||||
body = objectMapper.readValue(decryptedData, CtripOrderBody.class);
|
||||
}
|
||||
|
||||
result.put("jsonParseSuccess", true);
|
||||
result.put("otaOrderId", body.getOtaOrderId());
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ public interface DashboardMapper {
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
"</if>",
|
||||
"AND (o.order_status = 3 OR o.order_status = 8)",
|
||||
"AND o.order_status = 3",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程核销通知请求
|
||||
*/
|
||||
@Data
|
||||
public class CtripConsumedNoticeRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
private CtripConsumedNoticeHeader header;
|
||||
|
||||
/**
|
||||
* 请求体
|
||||
*/
|
||||
private CtripConsumedNoticeBody body;
|
||||
|
||||
/**
|
||||
* 携程核销通知请求头
|
||||
*/
|
||||
@Data
|
||||
public static class CtripConsumedNoticeHeader {
|
||||
/**
|
||||
* 请求时间
|
||||
*/
|
||||
private String requestTime;
|
||||
|
||||
/**
|
||||
* 账户ID
|
||||
*/
|
||||
private String accountId;
|
||||
|
||||
/**
|
||||
* 签名
|
||||
*/
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程核销通知请求体
|
||||
*/
|
||||
@Data
|
||||
public static class CtripConsumedNoticeBody {
|
||||
/**
|
||||
* OTA订单ID
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 供应商订单ID
|
||||
*/
|
||||
private String supplierOrderId;
|
||||
|
||||
/**
|
||||
* 核销时间
|
||||
*/
|
||||
private String consumedTime;
|
||||
|
||||
/**
|
||||
* 核销地点
|
||||
*/
|
||||
private String consumedLocation;
|
||||
|
||||
/**
|
||||
* 核销人
|
||||
*/
|
||||
private String consumedBy;
|
||||
|
||||
/**
|
||||
* 核销备注
|
||||
*/
|
||||
private String consumedRemark;
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 携程核销通知响应
|
||||
*/
|
||||
@Data
|
||||
public class CtripConsumedNoticeResponse {
|
||||
|
||||
/**
|
||||
* 响应头
|
||||
*/
|
||||
private CtripConsumedNoticeResponseHeader header;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 响应消息
|
||||
*/
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 响应体
|
||||
*/
|
||||
private CtripConsumedNoticeResponseBody body;
|
||||
|
||||
/**
|
||||
* 携程核销通知响应头
|
||||
*/
|
||||
@Data
|
||||
public static class CtripConsumedNoticeResponseHeader {
|
||||
/**
|
||||
* 请求时间
|
||||
*/
|
||||
private String requestTime;
|
||||
|
||||
/**
|
||||
* 账户ID
|
||||
*/
|
||||
private String accountId;
|
||||
|
||||
/**
|
||||
* 签名
|
||||
*/
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程核销通知响应体
|
||||
*/
|
||||
@Data
|
||||
public static class CtripConsumedNoticeResponseBody {
|
||||
/**
|
||||
* OTA订单ID
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 供应商订单ID
|
||||
*/
|
||||
private String supplierOrderId;
|
||||
|
||||
/**
|
||||
* 处理结果
|
||||
*/
|
||||
private String processResult;
|
||||
|
||||
/**
|
||||
* 处理时间
|
||||
*/
|
||||
private String processTime;
|
||||
}
|
||||
}
|
||||
@@ -77,4 +77,14 @@ public interface ICouponService extends IService<Coupon> {
|
||||
* 校验手机号+携程券ID是否已存在
|
||||
*/
|
||||
boolean existsByUserPhoneAndCtripCouponId(String userPhone, String ctripCouponId);
|
||||
|
||||
/**
|
||||
* 根据携程优惠券ID查询优惠券
|
||||
*/
|
||||
Coupon getByCtripCouponId(String ctripCouponId);
|
||||
|
||||
/**
|
||||
* 更新优惠券为已核销状态
|
||||
*/
|
||||
boolean updateCouponConsumed(Long couponId, String orderNo, String consumedTime);
|
||||
}
|
||||
+52
@@ -229,5 +229,57 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
|
||||
return "CP" + System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coupon getByCtripCouponId(String ctripCouponId) {
|
||||
return baseMapper.selectByCtripCouponId(ctripCouponId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateCouponConsumed(Long couponId, String orderNo, String consumedTime) {
|
||||
try {
|
||||
Coupon coupon = getById(couponId);
|
||||
if (coupon == null) {
|
||||
log.error("优惠券不存在,couponId: {}", couponId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 更新优惠券状态
|
||||
coupon.setStatus(1); // 已使用
|
||||
coupon.setUsedOrderNo(orderNo);
|
||||
coupon.setUsedTime(parseDate(consumedTime));
|
||||
coupon.setUpdateTime(new Date());
|
||||
coupon.setUpdateBy("ctrip-consumed");
|
||||
|
||||
boolean result = updateById(coupon);
|
||||
if (result) {
|
||||
log.info("优惠券核销成功,couponId: {}, orderNo: {}, consumedTime: {}",
|
||||
couponId, orderNo, consumedTime);
|
||||
} else {
|
||||
log.error("优惠券核销失败,couponId: {}", couponId);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("更新优惠券核销状态失败,couponId: {}", couponId, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析日期字符串
|
||||
*/
|
||||
private Date parseDate(String dateStr) {
|
||||
try {
|
||||
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
return new java.text.SimpleDateFormat("yyyy-MM-dd").parse(dateStr);
|
||||
} catch (Exception ex) {
|
||||
return new Date();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+8
-6
@@ -104,8 +104,10 @@ public class CtripDecryptUtil {
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
log.debug("原始解密数据前50个字符: {}",
|
||||
decryptedData.length() > 50 ? decryptedData.substring(0, 50) : decryptedData);
|
||||
log.info("原始解密数据前100个字符: {}",
|
||||
decryptedData.length() > 100 ? decryptedData.substring(0, 100) : decryptedData);
|
||||
log.info("原始解密数据后100个字符: {}",
|
||||
decryptedData.length() > 100 ? decryptedData.substring(decryptedData.length() - 100) : decryptedData);
|
||||
|
||||
// 查找第一个 '{' 字符(JSON对象开始)
|
||||
int startIndex = decryptedData.indexOf('{');
|
||||
@@ -127,13 +129,13 @@ public class CtripDecryptUtil {
|
||||
|
||||
if (startIndex > 0) {
|
||||
String cleanedData = decryptedData.substring(startIndex);
|
||||
log.debug("移除头部乱码,从位置 {} 开始,清理后数据前50个字符: {}",
|
||||
startIndex, cleanedData.length() > 50 ? cleanedData.substring(0, 50) : cleanedData);
|
||||
log.info("移除头部乱码,从位置 {} 开始,清理后数据前100个字符: {}",
|
||||
startIndex, cleanedData.length() > 100 ? cleanedData.substring(0, 100) : cleanedData);
|
||||
return cleanedData;
|
||||
}
|
||||
|
||||
log.debug("无需清理,数据前50个字符: {}",
|
||||
decryptedData.length() > 50 ? decryptedData.substring(0, 50) : decryptedData);
|
||||
log.info("无需清理,数据前100个字符: {}",
|
||||
decryptedData.length() > 100 ? decryptedData.substring(0, 100) : decryptedData);
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user