fix:无人船
This commit is contained in:
+108
@@ -0,0 +1,108 @@
|
||||
package com.central.coupon.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 携程分销商配置
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "ctrip.distributor")
|
||||
public class CtripDistributorConfig {
|
||||
|
||||
/**
|
||||
* 分销商AID
|
||||
*/
|
||||
private Long aid;
|
||||
|
||||
/**
|
||||
* 分销商SID
|
||||
*/
|
||||
private Long sid;
|
||||
|
||||
/**
|
||||
* 分销商密钥
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 认证URL
|
||||
*/
|
||||
private String authUrl;
|
||||
|
||||
/**
|
||||
* 刷新Token URL
|
||||
*/
|
||||
private String refreshUrl;
|
||||
|
||||
/**
|
||||
* 业务API URL
|
||||
*/
|
||||
private String apiUrl;
|
||||
|
||||
/**
|
||||
* 语言地区
|
||||
*/
|
||||
private String locale;
|
||||
|
||||
/**
|
||||
* 货币代码
|
||||
*/
|
||||
private String currency;
|
||||
|
||||
/**
|
||||
* 各接口icode配置
|
||||
*/
|
||||
private IcodeConfig icode;
|
||||
|
||||
@Data
|
||||
public static class IcodeConfig {
|
||||
|
||||
/**
|
||||
* 产品详情接口icode
|
||||
*/
|
||||
private String productDetail;
|
||||
|
||||
/**
|
||||
* 获取下单填写信息接口icode
|
||||
*/
|
||||
private String bookInfo;
|
||||
|
||||
/**
|
||||
* 创建订单接口icode
|
||||
*/
|
||||
private String book;
|
||||
|
||||
/**
|
||||
* 取消验证接口icode
|
||||
*/
|
||||
private String cancelVerify;
|
||||
|
||||
/**
|
||||
* 取消订单接口icode
|
||||
*/
|
||||
private String cancel;
|
||||
|
||||
/**
|
||||
* 订单详情查询接口icode
|
||||
*/
|
||||
private String bookingDetail;
|
||||
|
||||
/**
|
||||
* 可订检查接口icode
|
||||
*/
|
||||
private String checkAvailability;
|
||||
|
||||
/**
|
||||
* 沙箱测试-订单退订(携程发起)接口icode
|
||||
*/
|
||||
private String simulateCancel;
|
||||
|
||||
/**
|
||||
* 沙箱测试-人工出票/退订确认/凭证变更接口icode
|
||||
*/
|
||||
private String simulateConfirm;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -29,4 +29,4 @@ public class RestTemplateConfig {
|
||||
factory.setReadTimeout(timeout);
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package com.central.coupon.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.coupon.entity.CtripDistOrder;
|
||||
import com.central.coupon.mapper.CtripDistOrderMapper;
|
||||
import com.central.coupon.service.ICtripDistOrderService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/ctrip/dist/order")
|
||||
@Tag(name = "携程分销订单管理")
|
||||
public class CtripDistOrderController {
|
||||
|
||||
@Autowired
|
||||
private ICtripDistOrderService ctripDistOrderService;
|
||||
|
||||
@Autowired
|
||||
private CtripDistOrderMapper ctripDistOrderMapper;
|
||||
|
||||
/**
|
||||
* 分页查询携程分销订单列表
|
||||
*/
|
||||
@Operation(summary = "分页查询携程分销订单列表")
|
||||
@GetMapping("/list")
|
||||
public Result<Map<String, Object>> listCtripDistOrders(
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Integer limit,
|
||||
@Parameter(description = "本地订单号") @RequestParam(required = false) String orderNo,
|
||||
@Parameter(description = "携程订单ID") @RequestParam(required = false) Long ctripOrderId,
|
||||
@Parameter(description = "携程产品ID") @RequestParam(required = false) Long ctripProductId,
|
||||
@Parameter(description = "携程订单状态") @RequestParam(required = false) String ctripOrderStatus,
|
||||
@Parameter(description = "核销状态") @RequestParam(required = false) Integer consumeStatus,
|
||||
@Parameter(description = "退款状态") @RequestParam(required = false) Integer refundStatus,
|
||||
@Parameter(description = "租户ID") @RequestParam(required = false) String tenantId) {
|
||||
log.info("分页查询携程分销订单列表,page: {}, limit: {}, orderNo: {}", page, limit, orderNo);
|
||||
try {
|
||||
LambdaQueryWrapper<CtripDistOrder> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CtripDistOrder::getDeleted, 0);
|
||||
if (StringUtils.hasText(orderNo)) {
|
||||
queryWrapper.like(CtripDistOrder::getOrderNo, orderNo);
|
||||
}
|
||||
if (ctripOrderId != null) {
|
||||
queryWrapper.eq(CtripDistOrder::getCtripOrderId, ctripOrderId);
|
||||
}
|
||||
if (ctripProductId != null) {
|
||||
queryWrapper.eq(CtripDistOrder::getCtripProductId, ctripProductId);
|
||||
}
|
||||
if (StringUtils.hasText(ctripOrderStatus)) {
|
||||
queryWrapper.eq(CtripDistOrder::getCtripOrderStatus, ctripOrderStatus);
|
||||
}
|
||||
if (consumeStatus != null) {
|
||||
queryWrapper.eq(CtripDistOrder::getConsumeStatus, consumeStatus);
|
||||
}
|
||||
if (refundStatus != null) {
|
||||
queryWrapper.eq(CtripDistOrder::getRefundStatus, refundStatus);
|
||||
}
|
||||
if (StringUtils.hasText(tenantId)) {
|
||||
queryWrapper.eq(CtripDistOrder::getTenantId, tenantId);
|
||||
}
|
||||
queryWrapper.orderByDesc(CtripDistOrder::getCreateTime);
|
||||
|
||||
Page<CtripDistOrder> pageParam = new Page<>(page, limit);
|
||||
IPage<CtripDistOrder> pageResult = ctripDistOrderMapper.selectPage(pageParam, queryWrapper);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("data", pageResult.getRecords());
|
||||
result.put("count", pageResult.getTotal());
|
||||
result.put("page", page);
|
||||
result.put("limit", limit);
|
||||
return Result.succeed(result);
|
||||
} catch (Exception e) {
|
||||
log.error("查询携程分销订单列表异常", e);
|
||||
return Result.failed("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建携程分销订单(被order-center通过Feign调用)
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
public Result<String> createCtripDistOrder(@RequestBody Map<String, Object> params) {
|
||||
String orderNo = (String) params.get("orderNo");
|
||||
String orderAmount = (String) params.get("orderAmount");
|
||||
Long ctripProductId = Long.valueOf(params.get("ctripProductId").toString());
|
||||
String tenantId = (String) params.get("tenantId");
|
||||
String mobile = params.get("mobile") != null ? params.get("mobile").toString() : null;
|
||||
|
||||
try {
|
||||
ctripDistOrderService.createCtripDistOrder(orderNo, orderAmount, ctripProductId, tenantId, mobile);
|
||||
return Result.succeed("携程分销订单创建成功");
|
||||
} catch (Exception e) {
|
||||
log.error("创建携程分销订单失败", e);
|
||||
return Result.failed("创建失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退订携程分销订单
|
||||
*/
|
||||
@PostMapping("/cancel/{orderNo}")
|
||||
public Result<String> cancelCtripDistOrder(
|
||||
@PathVariable String orderNo,
|
||||
@RequestParam(defaultValue = "用户申请退订") String reason) {
|
||||
boolean success = ctripDistOrderService.cancelCtripDistOrder(orderNo, reason);
|
||||
return success ? Result.succeed("退订成功") : Result.failed("退订失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询携程分销订单详情
|
||||
*/
|
||||
@GetMapping("/{orderNo}")
|
||||
public Result<CtripDistOrder> getCtripDistOrder(@PathVariable String orderNo) {
|
||||
return Result.succeed(ctripDistOrderService.getByOrderNo(orderNo));
|
||||
}
|
||||
}
|
||||
+708
@@ -0,0 +1,708 @@
|
||||
package com.central.coupon.controller;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.coupon.model.CtripDistBookRequest;
|
||||
import com.central.coupon.model.CtripDistBookResponse;
|
||||
import com.central.coupon.model.CtripDistBookingDetailResponse;
|
||||
import com.central.coupon.model.CtripDistCancelResponse;
|
||||
import com.central.coupon.model.CtripDistCancelVerifyResponse;
|
||||
import com.central.coupon.service.ICtripDistApiService;
|
||||
import com.central.coupon.service.ICtripDistTokenService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 携程分销商接口沙箱测试
|
||||
* 用途:逐个调试携程分销商API,确认连通性和返回格式
|
||||
* 注意:仅用于测试环境,生产环境应禁用或加权限控制
|
||||
*
|
||||
* 核心设计:
|
||||
* - 调用 bookInfo 接口后,问卷模板按 productId 缓存
|
||||
* - 后续的可订检查/创建订单自动从缓存中取问卷模板
|
||||
* - 用户只需传 questionCode → 答案值,系统自动匹配 questionID/questionTitle
|
||||
* - 不同产品的测试步骤差异(字段不同、数量不同)全部通过参数控制
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/ctrip/dist/test")
|
||||
@Tag(name = "携程分销商接口测试")
|
||||
public class CtripDistTestController {
|
||||
|
||||
@Autowired
|
||||
private ICtripDistApiService ctripDistApiService;
|
||||
|
||||
@Autowired
|
||||
private ICtripDistTokenService ctripDistTokenService;
|
||||
|
||||
@Autowired
|
||||
private com.central.coupon.config.CtripDistributorConfig ctripDistributorConfig;
|
||||
|
||||
/**
|
||||
* bookInfo 缓存:key=productId, value=bookInfo完整返回
|
||||
* 调用 bookInfo 接口后自动缓存,后续接口直接使用
|
||||
*/
|
||||
private final Map<Long, Map<String, Object>> bookInfoCache = new ConcurrentHashMap<>();
|
||||
|
||||
// ==================== -1. 配置诊断 ====================
|
||||
|
||||
/**
|
||||
* 诊断当前分销商配置
|
||||
* 用途:确认Nacos配置是否被正确注入(key脱敏显示)
|
||||
*
|
||||
* 调用示例:GET /ctrip/dist/test/config
|
||||
*/
|
||||
@GetMapping("/config")
|
||||
@Operation(summary = "诊断分销商配置")
|
||||
public Result<Map<String, Object>> testConfig() {
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("aid", ctripDistributorConfig.getAid());
|
||||
data.put("sid", ctripDistributorConfig.getSid());
|
||||
data.put("key", ctripDistributorConfig.getKey() != null
|
||||
? ctripDistributorConfig.getKey().substring(0, Math.min(4, ctripDistributorConfig.getKey().length())) + "****"
|
||||
: "null");
|
||||
data.put("authUrl", ctripDistributorConfig.getAuthUrl());
|
||||
data.put("refreshUrl", ctripDistributorConfig.getRefreshUrl());
|
||||
data.put("apiUrl", ctripDistributorConfig.getApiUrl());
|
||||
data.put("locale", ctripDistributorConfig.getLocale());
|
||||
data.put("currency", ctripDistributorConfig.getCurrency());
|
||||
if (ctripDistributorConfig.getIcode() != null) {
|
||||
Map<String, Object> icode = new LinkedHashMap<>();
|
||||
icode.put("productDetail", ctripDistributorConfig.getIcode().getProductDetail());
|
||||
icode.put("bookInfo", ctripDistributorConfig.getIcode().getBookInfo());
|
||||
icode.put("book", ctripDistributorConfig.getIcode().getBook());
|
||||
icode.put("cancelVerify", ctripDistributorConfig.getIcode().getCancelVerify());
|
||||
icode.put("cancel", ctripDistributorConfig.getIcode().getCancel());
|
||||
icode.put("bookingDetail", ctripDistributorConfig.getIcode().getBookingDetail());
|
||||
data.put("icode", icode);
|
||||
} else {
|
||||
data.put("icode", "null - icode未配置!");
|
||||
}
|
||||
return Result.succeed(data, "当前分销商配置");
|
||||
}
|
||||
|
||||
// ==================== 0. Token测试 ====================
|
||||
|
||||
/**
|
||||
* 测试获取Token
|
||||
* 用途:验证aid/sid/key配置是否正确,Token能否正常获取
|
||||
*
|
||||
* 调用示例:POST /ctrip/dist/test/token
|
||||
*/
|
||||
@PostMapping("/token")
|
||||
@Operation(summary = "测试获取Token")
|
||||
public Result<Map<String, Object>> testGetToken() {
|
||||
log.info("===== 测试获取携程分销商Token =====");
|
||||
try {
|
||||
String token = ctripDistTokenService.getAccessToken();
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("accessToken", token);
|
||||
data.put("tokenLength", token != null ? token.length() : 0);
|
||||
data.put("message", "Token获取成功");
|
||||
log.info("Token获取成功,长度: {}", token != null ? token.length() : 0);
|
||||
return Result.succeed(data, "Token获取成功");
|
||||
} catch (Exception e) {
|
||||
log.error("Token获取失败", e);
|
||||
return Result.failed("Token获取失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 1. 获取产品详情 ====================
|
||||
|
||||
/**
|
||||
* 测试获取产品详情
|
||||
* 用途:根据productId获取产品信息,包含packageID和resourceID
|
||||
* 后续下单需要用到返回的packageID和resourceID
|
||||
*
|
||||
* 调用示例:GET /ctrip/dist/test/product-detail?productId=12345678
|
||||
*/
|
||||
@GetMapping("/product-detail")
|
||||
@Operation(summary = "1.获取产品详情")
|
||||
public Result<Map<String, Object>> testProductDetail(@RequestParam Long productId) {
|
||||
log.info("===== 测试获取产品详情,productId: {} =====", productId);
|
||||
try {
|
||||
Map<String, Object> result = ctripDistApiService.getProductDetail(productId);
|
||||
log.info("产品详情返回: {}", result);
|
||||
return Result.succeed(result, "获取产���详情成功");
|
||||
} catch (Exception e) {
|
||||
log.error("获取产品详情失败,productId: {}", productId, e);
|
||||
return Result.failed("获取产品详情失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 2. 获取下单填写信息(会自动缓存) ====================
|
||||
|
||||
/**
|
||||
* 测试获取下单填写信息
|
||||
* 用途:下单前查询该产品需要填写哪些字段(如手机号、身份证、英文姓名等)
|
||||
* 调用成功后会按 productId 缓存结果,后续可订检查/创建订单自动使用
|
||||
* 需要先调用接口1获取packageId和resourceId
|
||||
*
|
||||
* 调用示例:GET /ctrip/dist/test/book-info?productId=12345678&packageId=37326707&resourceId=37326710
|
||||
*/
|
||||
@GetMapping("/book-info")
|
||||
@Operation(summary = "2.获取下单填写信息(自动缓存)")
|
||||
public Result<Map<String, Object>> testBookInfo(
|
||||
@RequestParam Long productId,
|
||||
@RequestParam Long packageId,
|
||||
@RequestParam Long resourceId) {
|
||||
log.info("===== 测试获取下单填写信息,productId: {}, packageId: {}, resourceId: {} =====",
|
||||
productId, packageId, resourceId);
|
||||
try {
|
||||
Map<String, Object> result = ctripDistApiService.getBookInfo(productId, packageId, resourceId);
|
||||
log.info("下单填写信息返回: {}", result);
|
||||
|
||||
// 缓存 bookInfo 结果
|
||||
bookInfoCache.put(productId, result);
|
||||
log.info("bookInfo已缓存,productId: {},后续接口将自动使用", productId);
|
||||
|
||||
return Result.succeed(result, "获取下单填写信息成功(已缓存)");
|
||||
} catch (Exception e) {
|
||||
log.error("获取下单填写信息失败", e);
|
||||
return Result.failed("获取下单填写信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看当前缓存的bookInfo
|
||||
* 用途:查看某个产品已缓存的问卷模板,方便确认需要填哪些字段
|
||||
*
|
||||
* 调用示例:GET /ctrip/dist/test/book-info/cache?productId=39098283
|
||||
*/
|
||||
@GetMapping("/book-info/cache")
|
||||
@Operation(summary = "2.1 查看缓存的bookInfo")
|
||||
public Result<Map<String, Object>> getCachedBookInfo(@RequestParam Long productId) {
|
||||
Map<String, Object> cached = bookInfoCache.get(productId);
|
||||
if (cached == null) {
|
||||
return Result.failed("productId=" + productId + " 的bookInfo未缓存,请先调用接口2获取");
|
||||
}
|
||||
// 额外提取问卷模板摘要方便查看
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("productId", productId);
|
||||
result.put("questionTemplate", extractQuestionTemplate(cached));
|
||||
result.put("fullResponse", cached);
|
||||
return Result.succeed(result, "缓存的bookInfo");
|
||||
}
|
||||
|
||||
// ==================== 2.5 可订检查 ====================
|
||||
|
||||
/**
|
||||
* 测试可订检查
|
||||
* 用途:下单前检查资源是否可预订
|
||||
* 前提:必须先调用接口2获取bookInfo(已自动缓存)
|
||||
*
|
||||
* passengers中每个出行人只需传 questionCode → 答案值,
|
||||
* 系统会自动从缓存的bookInfo中匹配questionID和questionTitle
|
||||
*
|
||||
* 调用示例:POST /ctrip/dist/test/check-availability
|
||||
*
|
||||
* 产品2示例(中文姓名+身份证,2出行人):
|
||||
* {
|
||||
* "productId": xxx,
|
||||
* "packageId": xxx,
|
||||
* "resourceId": xxx,
|
||||
* "price": 68.00,
|
||||
* "quantity": 2,
|
||||
* "passengers": [
|
||||
* {"P_NAME": "杜超", "P_ID_CARD": "120101199003076531"},
|
||||
* {"P_NAME": "张三", "P_ID_CARD": "120101199003076532"}
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* 产品3示例(英文姓名,quantity=2但只需1个出行人):
|
||||
* {
|
||||
* "productId": 39098283,
|
||||
* "packageId": xxx,
|
||||
* "resourceId": xxx,
|
||||
* "price": 68.00,
|
||||
* "quantity": 2,
|
||||
* "passengers": [
|
||||
* {"P_FIRSTCNAME": "Chao", "P_LASTCNAME": "Du"}
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
@PostMapping("/check-availability")
|
||||
@Operation(summary = "2.5 可订检查")
|
||||
@SuppressWarnings("unchecked")
|
||||
public Result<Map<String, Object>> testCheckAvailability(@RequestBody Map<String, Object> params) {
|
||||
log.info("===== 测试可订检查,params: {} =====", params);
|
||||
try {
|
||||
Long productId = Long.valueOf(params.get("productId").toString());
|
||||
Long packageId = Long.valueOf(params.get("packageId").toString());
|
||||
Long resourceId = Long.valueOf(params.get("resourceId").toString());
|
||||
BigDecimal price = new BigDecimal(params.get("price").toString());
|
||||
String contactName = params.getOrDefault("contactName", "杜超").toString();
|
||||
String contactMobile = params.getOrDefault("contactMobile", "18222892722").toString();
|
||||
String contactEmail = params.getOrDefault("contactEmail", "1098974449@qq.com").toString();
|
||||
|
||||
// 从缓存获取问卷模板
|
||||
List<Map<String, Object>> questionTemplate = getQuestionTemplate(productId);
|
||||
|
||||
// 解析出行人问卷答案
|
||||
List<List<CtripDistBookRequest.QuestionAnswer>> passengerAnswers =
|
||||
parsePassengerAnswers(params, questionTemplate);
|
||||
|
||||
// quantity 独立于出行人数量
|
||||
int quantity = params.get("quantity") != null
|
||||
? Integer.parseInt(params.get("quantity").toString())
|
||||
: passengerAnswers.size();
|
||||
|
||||
String useDate = params.getOrDefault("useDate",
|
||||
LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))).toString();
|
||||
|
||||
String distributorOrderId = "CHECK_" + System.currentTimeMillis();
|
||||
CtripDistBookRequest request = buildTestBookRequest(
|
||||
distributorOrderId, productId, packageId, resourceId,
|
||||
price, quantity, useDate, contactName, contactMobile, contactEmail,
|
||||
passengerAnswers);
|
||||
|
||||
boolean available = ctripDistApiService.checkAvailability(request);
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("available", available);
|
||||
data.put("quantity", quantity);
|
||||
data.put("passengerCount", passengerAnswers.size());
|
||||
data.put("message", available ? "可预订" : "不可预订");
|
||||
log.info("可订检查结果: {}, 购买数量: {}, 出行人数: {}", available, quantity, passengerAnswers.size());
|
||||
return Result.succeed(data, available ? "可预订" : "不可预订");
|
||||
} catch (Exception e) {
|
||||
log.error("可订检查失败", e);
|
||||
return Result.failed("可订检查失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 3. 创建携程订单 ====================
|
||||
|
||||
/**
|
||||
* 测试创建携程订单
|
||||
* 前提:必须先调用接口2获取bookInfo(已自动缓存)
|
||||
* 参数格式与可订检查完全一致
|
||||
*
|
||||
* 调用示例:POST /ctrip/dist/test/book
|
||||
* Body: 与可订检查接口相同
|
||||
*/
|
||||
@PostMapping("/book")
|
||||
@Operation(summary = "3.创建携程订单")
|
||||
@SuppressWarnings("unchecked")
|
||||
public Result<CtripDistBookResponse> testCreateOrder(@RequestBody Map<String, Object> params) {
|
||||
log.info("===== 测试创建携程订单,params: {} =====", params);
|
||||
try {
|
||||
Long productId = Long.valueOf(params.get("productId").toString());
|
||||
Long packageId = Long.valueOf(params.get("packageId").toString());
|
||||
Long resourceId = Long.valueOf(params.get("resourceId").toString());
|
||||
BigDecimal price = new BigDecimal(params.get("price").toString());
|
||||
String contactName = params.getOrDefault("contactName", "杜超").toString();
|
||||
String contactMobile = params.getOrDefault("contactMobile", "18222892722").toString();
|
||||
String contactEmail = params.getOrDefault("contactEmail", "1098974449@qq.com").toString();
|
||||
|
||||
// 从缓存获取问卷模板
|
||||
List<Map<String, Object>> questionTemplate = getQuestionTemplate(productId);
|
||||
|
||||
// 解析出行人问卷答案
|
||||
List<List<CtripDistBookRequest.QuestionAnswer>> passengerAnswers =
|
||||
parsePassengerAnswers(params, questionTemplate);
|
||||
|
||||
// quantity 独立于出行人数量
|
||||
int quantity = params.get("quantity") != null
|
||||
? Integer.parseInt(params.get("quantity").toString())
|
||||
: passengerAnswers.size();
|
||||
|
||||
String useDate = params.getOrDefault("useDate",
|
||||
LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))).toString();
|
||||
|
||||
String distributorOrderId = "TEST_" + System.currentTimeMillis();
|
||||
CtripDistBookRequest request = buildTestBookRequest(
|
||||
distributorOrderId, productId, packageId, resourceId,
|
||||
price, quantity, useDate, contactName, contactMobile, contactEmail,
|
||||
passengerAnswers);
|
||||
|
||||
log.info("下单请求 distributorOrderId: {}, 购买数量: {}, 出行人数: {}",
|
||||
distributorOrderId, quantity, passengerAnswers.size());
|
||||
CtripDistBookResponse response = ctripDistApiService.createOrder(request);
|
||||
log.info("创建订单返回: success={}, orderId={}", response.isSuccess(),
|
||||
response.getData() != null ? response.getData().getOrderId() : "null");
|
||||
return Result.succeed(response, "创建订单调用完成");
|
||||
} catch (Exception e) {
|
||||
log.error("创建携程订单失败", e);
|
||||
return Result.failed("创建携程订单失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试创建携程订单(直接传完整请求体)
|
||||
* 用途:如果需要精确控制所有字段,直接传CtripDistBookRequest JSON
|
||||
*
|
||||
* 调用示例:POST /ctrip/dist/test/book/raw
|
||||
* Body: 完整的CtripDistBookRequest JSON
|
||||
*/
|
||||
@PostMapping("/book/raw")
|
||||
@Operation(summary = "3.创建携程订单(原始请求体)")
|
||||
public Result<CtripDistBookResponse> testCreateOrderRaw(@RequestBody CtripDistBookRequest request) {
|
||||
log.info("===== 测试创建携程订单(raw),distributorOrderID: {} =====", request.getDistributorOrderID());
|
||||
try {
|
||||
CtripDistBookResponse response = ctripDistApiService.createOrder(request);
|
||||
log.info("创建订单返回: success={}", response.isSuccess());
|
||||
return Result.succeed(response, "创建订单调用完成");
|
||||
} catch (Exception e) {
|
||||
log.error("创建携程订单失败", e);
|
||||
return Result.failed("创建携程订单失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 4. 可退检查 ====================
|
||||
|
||||
/**
|
||||
* 测试取消验证(可退检查)
|
||||
* 用途:检查某个携程订单是否可以取消/退订
|
||||
* 需要先通过接口3创建订单获得ctripOrderId
|
||||
*
|
||||
* 调用示例:GET /ctrip/dist/test/cancel-verify?ctripOrderId=123456789
|
||||
*/
|
||||
@GetMapping("/cancel-verify")
|
||||
@Operation(summary = "4.可退检查")
|
||||
public Result<CtripDistCancelVerifyResponse> testCancelVerify(@RequestParam Long ctripOrderId) {
|
||||
log.info("===== 测试取消验证,ctripOrderId: {} =====", ctripOrderId);
|
||||
try {
|
||||
CtripDistCancelVerifyResponse response = ctripDistApiService.cancelVerify(ctripOrderId);
|
||||
log.info("取消验证返回: success={}, cancelVerifyStatus={}",
|
||||
response.isSuccess(),
|
||||
response.getCancelVerifyData() != null
|
||||
? response.getCancelVerifyData().getCancelVerifyStatus() : "null");
|
||||
return Result.succeed(response, "取消验证调用完成");
|
||||
} catch (Exception e) {
|
||||
log.error("取消验证失败,ctripOrderId: {}", ctripOrderId, e);
|
||||
return Result.failed("取消验证失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 5. 退订(全部退订) ====================
|
||||
|
||||
/**
|
||||
* 测试退订(全部取消订单)
|
||||
* 用途:取消携程订单,需先通过接口4确认可退
|
||||
*
|
||||
* 调用示例:POST /ctrip/dist/test/cancel?ctripOrderId=123456789&reason=测试退订
|
||||
*/
|
||||
@PostMapping("/cancel")
|
||||
@Operation(summary = "5.退订(全部取消订单)")
|
||||
public Result<CtripDistCancelResponse> testCancelOrder(
|
||||
@RequestParam Long ctripOrderId,
|
||||
@RequestParam(defaultValue = "沙箱测试退订") String reason) {
|
||||
log.info("===== 测试全部退订,ctripOrderId: {}, reason: {} =====", ctripOrderId, reason);
|
||||
try {
|
||||
CtripDistCancelResponse response = ctripDistApiService.cancelOrder(ctripOrderId, reason);
|
||||
log.info("退订返回: success={}", response.isSuccess());
|
||||
return Result.succeed(response, "退订调用完成");
|
||||
} catch (Exception e) {
|
||||
log.error("退订失败,ctripOrderId: {}", ctripOrderId, e);
|
||||
return Result.failed("退订失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 5.5 部分退订 ====================
|
||||
|
||||
/**
|
||||
* 测试部分退订
|
||||
* 用途:部分取消携程订单(如购买2张退1张),需先通过接口4确认可部分退
|
||||
*
|
||||
* 调用示例:POST /ctrip/dist/test/cancel-partial
|
||||
* Body:
|
||||
* {
|
||||
* "ctripOrderId": 123456789,
|
||||
* "reason": "沙箱测试部分退订",
|
||||
* "cancelOrderItems": [
|
||||
* {
|
||||
* "itemID": 1001,
|
||||
* "quantity": 1
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
@PostMapping("/cancel-partial")
|
||||
@Operation(summary = "5.5 部分退订")
|
||||
@SuppressWarnings("unchecked")
|
||||
public Result<CtripDistCancelResponse> testCancelOrderPartial(@RequestBody Map<String, Object> params) {
|
||||
Long ctripOrderId = Long.valueOf(params.get("ctripOrderId").toString());
|
||||
String reason = params.getOrDefault("reason", "沙箱测试部分退订").toString();
|
||||
List<Map<String, Object>> cancelOrderItems = (List<Map<String, Object>>) params.get("cancelOrderItems");
|
||||
log.info("===== 测试部分退订,ctripOrderId: {}, reason: {}, cancelOrderItems: {} =====",
|
||||
ctripOrderId, reason, cancelOrderItems);
|
||||
try {
|
||||
CtripDistCancelResponse response = ctripDistApiService.cancelOrderPartial(ctripOrderId, reason, cancelOrderItems);
|
||||
log.info("部分退订返回: success={}", response.isSuccess());
|
||||
return Result.succeed(response, "部分退订调用完成");
|
||||
} catch (Exception e) {
|
||||
log.error("部分退订失败,ctripOrderId: {}", ctripOrderId, e);
|
||||
return Result.failed("部分退订失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 6. 订单详情 ====================
|
||||
|
||||
/**
|
||||
* 测试查询携程订单详情
|
||||
* 用途:根据携程订单ID查询订单状态和详细信息
|
||||
*
|
||||
* 调用示例:GET /ctrip/dist/test/booking-detail?ctripOrderId=123456789
|
||||
*/
|
||||
@GetMapping("/booking-detail")
|
||||
@Operation(summary = "6.携程订单详情")
|
||||
public Result<CtripDistBookingDetailResponse> testBookingDetail(@RequestParam Long ctripOrderId) {
|
||||
log.info("===== 测试查询订单详情,ctripOrderId: {} =====", ctripOrderId);
|
||||
try {
|
||||
CtripDistBookingDetailResponse response = ctripDistApiService.getOrderDetail(ctripOrderId);
|
||||
log.info("订单详情返回: success={}, orderStatus={}",
|
||||
response.isSuccess(),
|
||||
response.getData() != null && response.getData().getOrder() != null
|
||||
? response.getData().getOrder().getOrderStatus() : "null");
|
||||
return Result.succeed(response, "查询订单详情完成");
|
||||
} catch (Exception e) {
|
||||
log.error("查询订单详情失败,ctripOrderId: {}", ctripOrderId, e);
|
||||
return Result.failed("查询订单详情失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 7. 沙箱-模拟携程发起退订(Part M 11.2) ====================
|
||||
|
||||
/**
|
||||
* 模拟携程侧发起退订
|
||||
* 用途:沙箱测试时模拟携程侧退订(非分销商发起),退订后可调接口6查看订单状态
|
||||
*
|
||||
* 整单退示例:POST /ctrip/dist/test/simulate-cancel
|
||||
* Body: {"orderId": "1128170608930095"}
|
||||
*
|
||||
* 部分退示例(一张一人的订单,传clientId):
|
||||
* Body:
|
||||
* {
|
||||
* "orderId": "1128170612314784",
|
||||
* "quantity": 1,
|
||||
* "clientInfoList": [
|
||||
* {"clientId": "1756725089476701"}
|
||||
* ]
|
||||
* }
|
||||
* 注意:clientId 从订单详情接口(接口6)返回的出行人 P_CLIENTID 获取
|
||||
*/
|
||||
@PostMapping("/simulate-cancel")
|
||||
@Operation(summary = "7.沙箱-模拟携程发起退订")
|
||||
public Result<Map<String, Object>> testSimulateCtripCancel(@RequestBody Map<String, Object> params) {
|
||||
log.info("===== 沙箱-模拟携程发起退订,params: {} =====", params);
|
||||
try {
|
||||
Map<String, Object> response = ctripDistApiService.simulateCtripCancel(params);
|
||||
log.info("模拟携程退订返回: {}", response);
|
||||
return Result.succeed(response, "模拟携程退订调用完成");
|
||||
} catch (Exception e) {
|
||||
log.error("模拟携程退订失败", e);
|
||||
return Result.failed("模拟携程退订失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 8. 沙箱-人工出票/退订确认/退订拒绝/凭证变更(Part M 11.3) ====================
|
||||
|
||||
/**
|
||||
* 沙箱测试-人工出票/退订确认/退订拒绝/凭证变更
|
||||
* 用途:对卡在出票中/退订中的订单进行人工操作
|
||||
*
|
||||
* type说明:
|
||||
* 1 = 人工出票(对卡在出票中或需人工确认的订单)
|
||||
* 2 = 退订确认(对卡在退订中的订单)
|
||||
* 3 = 退订拒绝(模拟携程侧拒绝退订)
|
||||
* 4 = 凭证变更
|
||||
*
|
||||
* 调用示例:POST /ctrip/dist/test/simulate-confirm
|
||||
* Body: {"orderId": "1128170612557359", "type": 1}
|
||||
*/
|
||||
@PostMapping("/simulate-confirm")
|
||||
@Operation(summary = "8.沙箱-人工出票/退订确认/退订拒绝/凭证变更")
|
||||
public Result<Map<String, Object>> testSimulateConfirm(@RequestBody Map<String, Object> params) {
|
||||
Object type = params.get("type");
|
||||
String[] typeNames = {"", "人工出票", "退订确认", "退订拒绝", "凭证变更"};
|
||||
String typeName = type != null && Integer.parseInt(type.toString()) >= 1 && Integer.parseInt(type.toString()) <= 4
|
||||
? typeNames[Integer.parseInt(type.toString())] : "未知类型";
|
||||
log.info("===== 沙箱-{},params: {} =====", typeName, params);
|
||||
try {
|
||||
Map<String, Object> response = ctripDistApiService.simulateConfirm(params);
|
||||
log.info("沙箱-{}返回: {}", typeName, response);
|
||||
return Result.succeed(response, typeName + "调用完成");
|
||||
} catch (Exception e) {
|
||||
log.error("沙箱-{}失败", typeName, e);
|
||||
return Result.failed(typeName + "失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 辅助方法 ====================
|
||||
|
||||
/**
|
||||
* 从缓存获取产品的问卷模板
|
||||
* 如果未缓存,提示用户先调用接口2
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> getQuestionTemplate(Long productId) {
|
||||
Map<String, Object> bookInfo = bookInfoCache.get(productId);
|
||||
if (bookInfo == null) {
|
||||
throw new RuntimeException("productId=" + productId + " 的bookInfo未缓存,请先调用接口2(GET /ctrip/dist/test/book-info)");
|
||||
}
|
||||
return extractQuestionTemplate(bookInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 bookInfo 响应中提取问卷模板列表
|
||||
* bookInfo 结构: { success: true, data: { passengerQuestionList: [...] } }
|
||||
* 每个问卷项: { questionID: 3, questionCode: "P_NAME", questionTitle: "UserName", ... }
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> extractQuestionTemplate(Map<String, Object> bookInfo) {
|
||||
if (bookInfo == null || bookInfo.get("data") == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Map<String, Object> data = (Map<String, Object>) bookInfo.get("data");
|
||||
Object questionList = data.get("passengerQuestionList");
|
||||
if (questionList instanceof List) {
|
||||
return (List<Map<String, Object>>) questionList;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析出行人问卷答案
|
||||
*
|
||||
* passengers中每个出行人是一个Map,key为questionCode,value为答案值
|
||||
* 示例: {"P_FIRSTCNAME": "Chao", "P_LASTCNAME": "Du"}
|
||||
*
|
||||
* 系统自动从缓存的问卷模板中匹配questionID和questionTitle
|
||||
*
|
||||
* 如果没有传passengers,则返回空的单个出行人(无问卷答案)
|
||||
*
|
||||
* @param params 请求参数
|
||||
* @param questionTemplate 从bookInfo缓存中获取的问卷模板
|
||||
* @return 每个出行人的问卷答案列表
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<List<CtripDistBookRequest.QuestionAnswer>> parsePassengerAnswers(
|
||||
Map<String, Object> params, List<Map<String, Object>> questionTemplate) {
|
||||
|
||||
List<List<CtripDistBookRequest.QuestionAnswer>> result = new ArrayList<>();
|
||||
Object passengersObj = params.get("passengers");
|
||||
|
||||
if (passengersObj instanceof List) {
|
||||
List<Map<String, Object>> passengers = (List<Map<String, Object>>) passengersObj;
|
||||
// 构建 questionCode → 模板 的映射
|
||||
// 携程返回的字段名是 "code"(不是 "questionCode")
|
||||
Map<String, Map<String, Object>> templateMap = new LinkedHashMap<>();
|
||||
for (Map<String, Object> q : questionTemplate) {
|
||||
String code = getFieldValue(q, "code", "questionCode");
|
||||
if (code != null) {
|
||||
templateMap.put(code, q);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map<String, Object> passengerMap : passengers) {
|
||||
List<CtripDistBookRequest.QuestionAnswer> answers = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> entry : passengerMap.entrySet()) {
|
||||
String questionCode = entry.getKey();
|
||||
String answerValue = entry.getValue() != null ? entry.getValue().toString() : "";
|
||||
|
||||
// 从模板匹配 questionID 和 questionTitle
|
||||
Map<String, Object> template = templateMap.get(questionCode);
|
||||
if (template != null) {
|
||||
CtripDistBookRequest.QuestionAnswer answer = new CtripDistBookRequest.QuestionAnswer();
|
||||
answer.setQuestionID(Long.valueOf(template.get("questionID").toString()));
|
||||
answer.setQuestionCode(questionCode);
|
||||
String title = getFieldValue(template, "title", "questionTitle");
|
||||
answer.setQuestionTitle(title != null ? title : "");
|
||||
answer.setAnswerList(Collections.singletonList(answerValue));
|
||||
answers.add(answer);
|
||||
} else {
|
||||
log.warn("questionCode={} 在问卷模板中未找到,跳过", questionCode);
|
||||
}
|
||||
}
|
||||
result.add(answers);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.isEmpty()) {
|
||||
// 没有传passengers,返回一个无答案的出行人
|
||||
result.add(new ArrayList<>());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建测试下单请求(通用版)
|
||||
*
|
||||
* @param passengerAnswers 每个出行人的问卷答案(从parsePassengerAnswers得到)
|
||||
* @param quantity 购买数量(与出行人数量解耦)
|
||||
* @param useDate 使用日期
|
||||
*/
|
||||
private CtripDistBookRequest buildTestBookRequest(String distributorOrderId, Long productId,
|
||||
Long packageId, Long resourceId,
|
||||
BigDecimal price, int quantity,
|
||||
String useDate,
|
||||
String contactName, String contactMobile,
|
||||
String contactEmail,
|
||||
List<List<CtripDistBookRequest.QuestionAnswer>> passengerAnswers) {
|
||||
CtripDistBookRequest request = new CtripDistBookRequest();
|
||||
request.setLocale("zh-CN");
|
||||
request.setCurrency("CNY");
|
||||
request.setDistributorOrderID(distributorOrderId);
|
||||
|
||||
// 联系人
|
||||
CtripDistBookRequest.Contact contact = new CtripDistBookRequest.Contact();
|
||||
contact.setName(contactName);
|
||||
CtripDistBookRequest.Mobile mobile = new CtripDistBookRequest.Mobile();
|
||||
mobile.setInternationalTelephoneCode("86");
|
||||
mobile.setMobileNumber(contactMobile);
|
||||
contact.setMobile(mobile);
|
||||
contact.setEmail(contactEmail);
|
||||
request.setContact(contact);
|
||||
|
||||
// 为每个出行人构建Passenger对象
|
||||
List<CtripDistBookRequest.Passenger> passengerList = new ArrayList<>();
|
||||
for (List<CtripDistBookRequest.QuestionAnswer> answers : passengerAnswers) {
|
||||
CtripDistBookRequest.Passenger passenger = new CtripDistBookRequest.Passenger();
|
||||
passenger.setPackageID(packageId);
|
||||
passenger.setResourceID(resourceId);
|
||||
passenger.setQuestionAnswerList(answers);
|
||||
passengerList.add(passenger);
|
||||
}
|
||||
request.setPassengerList(passengerList);
|
||||
|
||||
// 订单资源
|
||||
CtripDistBookRequest.OrderResource orderResource = new CtripDistBookRequest.OrderResource();
|
||||
orderResource.setResourceID(resourceId);
|
||||
orderResource.setUseDate(useDate);
|
||||
orderResource.setQuantity(quantity);
|
||||
orderResource.setPrice(price);
|
||||
|
||||
// 基本订单信息
|
||||
BigDecimal totalAmount = price.multiply(new BigDecimal(quantity));
|
||||
CtripDistBookRequest.BasicOrder basicOrder = new CtripDistBookRequest.BasicOrder();
|
||||
basicOrder.setProductID(productId);
|
||||
basicOrder.setAmount(totalAmount);
|
||||
basicOrder.setPackageID(packageId);
|
||||
basicOrder.setOrderResourceList(Collections.singletonList(orderResource));
|
||||
request.setBasicOrder(basicOrder);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Map中按优先级获取字段值
|
||||
* 携程接口返回的字段名可能与文档不一致(如 "code" vs "questionCode","title" vs "questionTitle")
|
||||
*/
|
||||
private String getFieldValue(Map<String, Object> map, String... keys) {
|
||||
for (String key : keys) {
|
||||
Object val = map.get(key);
|
||||
if (val != null) {
|
||||
return val.toString();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_ctrip_dist_order")
|
||||
public class CtripDistOrder {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("tenant_id")
|
||||
private String tenantId;
|
||||
|
||||
@TableField("order_no")
|
||||
private String orderNo;
|
||||
|
||||
@TableField("ctrip_order_id")
|
||||
private Long ctripOrderId;
|
||||
|
||||
@TableField("ctrip_product_id")
|
||||
private Long ctripProductId;
|
||||
|
||||
@TableField("ctrip_package_id")
|
||||
private Long ctripPackageId;
|
||||
|
||||
@TableField("ctrip_resource_id")
|
||||
private Long ctripResourceId;
|
||||
|
||||
@TableField("distributor_order_id")
|
||||
private String distributorOrderId;
|
||||
|
||||
@TableField("order_amount")
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
@TableField("currency")
|
||||
private String currency;
|
||||
|
||||
@TableField("ctrip_order_status")
|
||||
private String ctripOrderStatus;
|
||||
|
||||
@TableField("consume_status")
|
||||
private Integer consumeStatus;
|
||||
|
||||
@TableField("consume_time")
|
||||
private LocalDateTime consumeTime;
|
||||
|
||||
@TableField("refund_status")
|
||||
private Integer refundStatus;
|
||||
|
||||
@TableField("refund_time")
|
||||
private LocalDateTime refundTime;
|
||||
|
||||
@TableField("refund_amount")
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
@TableField("error_msg")
|
||||
private String errorMsg;
|
||||
|
||||
@TableField("retry_count")
|
||||
private Integer retryCount;
|
||||
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField("deleted")
|
||||
private Integer deleted;
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.coupon.entity.CtripDistOrder;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface CtripDistOrderMapper extends BaseMapper<CtripDistOrder> {
|
||||
|
||||
// 根据本地订单号查询
|
||||
CtripDistOrder selectByOrderNo(@Param("orderNo") String orderNo);
|
||||
|
||||
// 查询 N 天前创建、已确认且未核销的订单
|
||||
List<CtripDistOrder> selectPendingConsumeOrders(@Param("daysAgo") int daysAgo);
|
||||
|
||||
// 根据分销商订单 ID 查询
|
||||
CtripDistOrder selectByDistributorOrderId(@Param("distributorOrderId") String distributorOrderId);
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripDistBookRequest {
|
||||
|
||||
private String locale;
|
||||
private String currency;
|
||||
private String distributorOrderID;
|
||||
private Contact contact;
|
||||
private List<Passenger> passengerList;
|
||||
private BasicOrder basicOrder;
|
||||
|
||||
@Data
|
||||
public static class Contact {
|
||||
|
||||
private String name;
|
||||
private Mobile mobile;
|
||||
private String email;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Mobile {
|
||||
|
||||
private String internationalTelephoneCode;
|
||||
private String mobileNumber;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Passenger {
|
||||
|
||||
private Long packageID;
|
||||
private Long resourceID;
|
||||
private List<QuestionAnswer> questionAnswerList;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class QuestionAnswer {
|
||||
|
||||
private Long questionID;
|
||||
private String questionCode;
|
||||
private String questionTitle;
|
||||
private List<String> answerList;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class BasicOrder {
|
||||
|
||||
private Long productID;
|
||||
private BigDecimal amount;
|
||||
private Long packageID;
|
||||
private List<OrderResource> orderResourceList;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class OrderResource {
|
||||
|
||||
private Long resourceID;
|
||||
private String useDate;
|
||||
private Integer quantity;
|
||||
private BigDecimal price;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripDistBookResponse {
|
||||
|
||||
private boolean success;
|
||||
private String errcode;
|
||||
private String errmsg;
|
||||
private BookData data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class BookData {
|
||||
|
||||
private Long orderId;
|
||||
private BigDecimal orderAmount;
|
||||
private Integer payTimeOutMinutes;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripDistBookingDetailResponse {
|
||||
|
||||
private boolean success;
|
||||
private String errcode;
|
||||
private String errmsg;
|
||||
private OrderData data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class OrderData {
|
||||
|
||||
private OrderDetail order;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class OrderDetail {
|
||||
|
||||
private Long orderId;
|
||||
// PENDING_BOOKING, CONFIRMED, CANCELLED, etc.
|
||||
private String orderStatus;
|
||||
private BigDecimal amount;
|
||||
private String distributorOrderID;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripDistCancelResponse {
|
||||
|
||||
private boolean success;
|
||||
private String errcode;
|
||||
private String errmsg;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripDistCancelVerifyResponse {
|
||||
|
||||
private boolean success;
|
||||
private String errcode;
|
||||
private String errmsg;
|
||||
private CancelVerifyData cancelVerifyData;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CancelVerifyData {
|
||||
|
||||
// 0=不可取消, 1=可取消, 3=部分退订
|
||||
private Integer cancelVerifyStatus;
|
||||
private BigDecimal refundAmount;
|
||||
// 1=允许部分退, 2=不允许
|
||||
private Integer canPartRefund;
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.central.coupon.service;
|
||||
|
||||
import com.central.coupon.model.CtripDistBookRequest;
|
||||
import com.central.coupon.model.CtripDistBookResponse;
|
||||
import com.central.coupon.model.CtripDistBookingDetailResponse;
|
||||
import com.central.coupon.model.CtripDistCancelResponse;
|
||||
import com.central.coupon.model.CtripDistCancelVerifyResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 携程分销商API服务
|
||||
*/
|
||||
public interface ICtripDistApiService {
|
||||
|
||||
/**
|
||||
* 查询产品详情
|
||||
*
|
||||
* @param productId 产品ID
|
||||
* @return 产品详情
|
||||
*/
|
||||
Map<String, Object> getProductDetail(Long productId);
|
||||
|
||||
/**
|
||||
* 获取下单填写信息
|
||||
*
|
||||
* @param productId 产品ID
|
||||
* @param packageId 套餐ID
|
||||
* @param resourceId 资源ID
|
||||
* @return 下单填写信息
|
||||
*/
|
||||
Map<String, Object> getBookInfo(Long productId, Long packageId, Long resourceId);
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
* @param request 下单请求
|
||||
* @return 下单响应
|
||||
*/
|
||||
CtripDistBookResponse createOrder(CtripDistBookRequest request);
|
||||
|
||||
/**
|
||||
* 取消验证
|
||||
*
|
||||
* @param ctripOrderId 携程订单ID
|
||||
* @return 取消验证结果
|
||||
*/
|
||||
CtripDistCancelVerifyResponse cancelVerify(Long ctripOrderId);
|
||||
|
||||
/**
|
||||
* 取消订单(全部退订)
|
||||
*
|
||||
* @param ctripOrderId 携程订单ID
|
||||
* @param reason 取消原因
|
||||
* @return 取消结果
|
||||
*/
|
||||
CtripDistCancelResponse cancelOrder(Long ctripOrderId, String reason);
|
||||
|
||||
/**
|
||||
* 部分退订
|
||||
*
|
||||
* @param ctripOrderId 携程订单ID
|
||||
* @param reason 取消原因
|
||||
* @param cancelOrderItems 部分取消的订单项列表
|
||||
* @return 取消结果
|
||||
*/
|
||||
CtripDistCancelResponse cancelOrderPartial(Long ctripOrderId, String reason, List<Map<String, Object>> cancelOrderItems);
|
||||
|
||||
/**
|
||||
* 查询订单详情
|
||||
*
|
||||
* @param ctripOrderId 携程订单ID
|
||||
* @return 订单详情
|
||||
*/
|
||||
CtripDistBookingDetailResponse getOrderDetail(Long ctripOrderId);
|
||||
|
||||
/**
|
||||
* 可订检查(下单前调用,确认资源可预订)
|
||||
* 请求参数与下单接口一致
|
||||
*
|
||||
* @param request 下单请求(与book接口相同)
|
||||
* @return 是否可订
|
||||
*/
|
||||
boolean checkAvailability(CtripDistBookRequest request);
|
||||
|
||||
/**
|
||||
* 沙箱测试-模拟携程发起退订(Part M 11.2)
|
||||
*
|
||||
* @param requestBody 请求体(orderId必填,部分退时含quantity和clientInfoList)
|
||||
* @return 响应
|
||||
*/
|
||||
Map<String, Object> simulateCtripCancel(Map<String, Object> requestBody);
|
||||
|
||||
/**
|
||||
* 沙箱测试-人工出票/退订确认/退订拒绝/凭证变更(Part M 11.3)
|
||||
*
|
||||
* @param requestBody 请求体(orderId + type: 1=人工出票, 2=退订确认, 3=退订拒绝, 4=凭证变更)
|
||||
* @return 响应
|
||||
*/
|
||||
Map<String, Object> simulateConfirm(Map<String, Object> requestBody);
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.central.coupon.service;
|
||||
|
||||
import com.central.coupon.entity.CtripDistOrder;
|
||||
|
||||
/**
|
||||
* 携程分销商订单服务
|
||||
*/
|
||||
public interface ICtripDistOrderService {
|
||||
|
||||
/**
|
||||
* 创建携程分销商订单
|
||||
*
|
||||
* @param orderNo 本地订单号
|
||||
* @param orderAmount 订单金额,单位分
|
||||
* @param ctripProductId 携程产品ID
|
||||
* @param tenantId 租户ID
|
||||
* @param mobile 用户手机号(可为null,为null时使用默认值)
|
||||
*/
|
||||
void createCtripDistOrder(String orderNo, String orderAmount, Long ctripProductId, String tenantId, String mobile);
|
||||
|
||||
/**
|
||||
* 取消携程分销商订单
|
||||
*
|
||||
* @param orderNo 本地订单号
|
||||
* @param reason 取消原因
|
||||
* @return 是否取消成功
|
||||
*/
|
||||
boolean cancelCtripDistOrder(String orderNo, String reason);
|
||||
|
||||
/**
|
||||
* 根据订单号查询订单
|
||||
*
|
||||
* @param orderNo 本地订单号
|
||||
* @return 分销商订单
|
||||
*/
|
||||
CtripDistOrder getByOrderNo(String orderNo);
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.central.coupon.service;
|
||||
|
||||
/**
|
||||
* 携程分销商Token管理服务
|
||||
*/
|
||||
public interface ICtripDistTokenService {
|
||||
|
||||
/**
|
||||
* 获取有效的AccessToken(自动刷新)
|
||||
*
|
||||
* @return 有效的AccessToken
|
||||
*/
|
||||
String getAccessToken();
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
package com.central.coupon.service.impl;
|
||||
|
||||
import com.central.common.utils.http.SimpleHttpRequest;
|
||||
import com.central.coupon.config.CtripDistributorConfig;
|
||||
import com.central.coupon.model.CtripDistBookRequest;
|
||||
import com.central.coupon.model.CtripDistBookResponse;
|
||||
import com.central.coupon.model.CtripDistBookingDetailResponse;
|
||||
import com.central.coupon.model.CtripDistCancelResponse;
|
||||
import com.central.coupon.model.CtripDistCancelVerifyResponse;
|
||||
import com.central.coupon.service.ICtripDistApiService;
|
||||
import com.central.coupon.service.ICtripDistTokenService;
|
||||
import com.central.coupon.util.SslUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 携程分销商API服务实现
|
||||
* 使用SimpleHttpRequest替代RestTemplate,解决HTTPS连接兼容性问题
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CtripDistApiServiceImpl implements ICtripDistApiService {
|
||||
|
||||
@Autowired
|
||||
private CtripDistributorConfig config;
|
||||
|
||||
@Autowired
|
||||
private ICtripDistTokenService tokenService;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getProductDetail(Long productId) {
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("locale", config.getLocale());
|
||||
requestBody.put("currency", config.getCurrency());
|
||||
requestBody.put("productIDList", Collections.singletonList(productId));
|
||||
return callApi(config.getIcode().getProductDetail(), requestBody, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getBookInfo(Long productId, Long packageId, Long resourceId) {
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("locale", config.getLocale());
|
||||
requestBody.put("currency", config.getCurrency());
|
||||
requestBody.put("productID", productId);
|
||||
requestBody.put("packageID", packageId);
|
||||
requestBody.put("resourceID", resourceId);
|
||||
return callApi(config.getIcode().getBookInfo(), requestBody, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CtripDistBookResponse createOrder(CtripDistBookRequest request) {
|
||||
return callApi(config.getIcode().getBook(), request, CtripDistBookResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CtripDistCancelVerifyResponse cancelVerify(Long ctripOrderId) {
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("orderId", ctripOrderId);
|
||||
requestBody.put("locale", config.getLocale());
|
||||
return callApi(config.getIcode().getCancelVerify(), requestBody, CtripDistCancelVerifyResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CtripDistCancelResponse cancelOrder(Long ctripOrderId, String reason) {
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("orderId", ctripOrderId);
|
||||
requestBody.put("reason", reason);
|
||||
return callApi(config.getIcode().getCancel(), requestBody, CtripDistCancelResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CtripDistCancelResponse cancelOrderPartial(Long ctripOrderId, String reason, java.util.List<Map<String, Object>> cancelOrderItems) {
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("orderId", ctripOrderId);
|
||||
requestBody.put("reason", reason);
|
||||
requestBody.put("cancelOrderItems", cancelOrderItems);
|
||||
return callApi(config.getIcode().getCancel(), requestBody, CtripDistCancelResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CtripDistBookingDetailResponse getOrderDetail(Long ctripOrderId) {
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("orderID", ctripOrderId);
|
||||
return callApi(config.getIcode().getBookingDetail(), requestBody, CtripDistBookingDetailResponse.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean checkAvailability(CtripDistBookRequest request) {
|
||||
Map<String, Object> response = callApi(config.getIcode().getCheckAvailability(), request, Map.class);
|
||||
log.info("可订检查完整响应: {}", response);
|
||||
Object success = response.get("success");
|
||||
if (success == null || !Boolean.parseBoolean(success.toString())) {
|
||||
log.warn("可订检查失败, success={}, errcode={}, errmsg={}",
|
||||
success, response.get("errcode"), response.get("errmsg"));
|
||||
}
|
||||
return success != null && Boolean.parseBoolean(success.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> simulateCtripCancel(Map<String, Object> requestBody) {
|
||||
return callApi(config.getIcode().getSimulateCancel(), requestBody, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> simulateConfirm(Map<String, Object> requestBody) {
|
||||
return callApi(config.getIcode().getSimulateConfirm(), requestBody, Map.class);
|
||||
}
|
||||
|
||||
private <T> T callApi(String icode, Object requestBody, Class<T> responseType) {
|
||||
String token = tokenService.getAccessToken();
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||
String url = String.format("%s?aid=%s&sid=%s&icode=%s&uuid=%s&token=%s",
|
||||
config.getApiUrl(), config.getAid(), config.getSid(), icode, uuid, token);
|
||||
|
||||
String requestJson;
|
||||
try {
|
||||
requestJson = objectMapper.writeValueAsString(requestBody);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("请求体序列化失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
log.info("调用携程分销商接口,icode: {}, uuid: {}, requestBody: {}", icode, uuid, requestJson);
|
||||
|
||||
String responseBody;
|
||||
try {
|
||||
SimpleHttpRequest request = new SimpleHttpRequest(url, SslUtil.createTrustAllHttpClient());
|
||||
request.requestBody(requestJson);
|
||||
byte[] bytes = request.post().asBytes();
|
||||
request.close();
|
||||
responseBody = new String(bytes, "UTF-8");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("携程分销商接口HTTP请求失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
log.info("携程分销商接口响应,icode: {}, response: {}", icode, responseBody);
|
||||
|
||||
try {
|
||||
return objectMapper.readValue(responseBody, responseType);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("携程分销商接口响应反序列化失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+246
@@ -0,0 +1,246 @@
|
||||
package com.central.coupon.service.impl;
|
||||
|
||||
import com.central.coupon.config.CtripDistributorConfig;
|
||||
import com.central.coupon.entity.CtripDistOrder;
|
||||
import com.central.coupon.mapper.CtripDistOrderMapper;
|
||||
import com.central.coupon.model.CtripDistBookRequest;
|
||||
import com.central.coupon.model.CtripDistBookResponse;
|
||||
import com.central.coupon.model.CtripDistCancelResponse;
|
||||
import com.central.coupon.model.CtripDistCancelVerifyResponse;
|
||||
import com.central.coupon.service.ICtripDistApiService;
|
||||
import com.central.coupon.service.ICtripDistOrderService;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 携程分销商订单服务实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CtripDistOrderServiceImpl implements ICtripDistOrderService {
|
||||
|
||||
private static final DateTimeFormatter USE_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
@Autowired
|
||||
private ICtripDistApiService ctripDistApiService;
|
||||
|
||||
@Autowired
|
||||
private CtripDistOrderMapper ctripDistOrderMapper;
|
||||
|
||||
@Autowired
|
||||
private CtripDistributorConfig config;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createCtripDistOrder(String orderNo, String orderAmount, Long ctripProductId, String tenantId, String mobile) {
|
||||
CtripDistOrder existingOrder = ctripDistOrderMapper.selectByOrderNo(orderNo);
|
||||
if (existingOrder != null) {
|
||||
log.info("携程分销商订单已存在,orderNo: {}", orderNo);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> productDetail = ctripDistApiService.getProductDetail(ctripProductId);
|
||||
Long packageId = extractPackageId(productDetail);
|
||||
Long resourceId = extractResourceId(productDetail);
|
||||
Map<String, Object> bookInfo = ctripDistApiService.getBookInfo(ctripProductId, packageId, resourceId);
|
||||
log.info("携程分销商下单填写信息,orderNo: {}, bookInfo: {}", orderNo, bookInfo);
|
||||
|
||||
// 校验产品是否要求额外乘客问卷(如身份证等),如果要求则无法自动下单
|
||||
validateBookInfo(bookInfo, orderNo);
|
||||
|
||||
String distributorOrderId = orderNo;
|
||||
BigDecimal amountYuan = new BigDecimal(orderAmount).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
|
||||
CtripDistBookRequest request = buildBookRequest(distributorOrderId, ctripProductId, packageId, resourceId, amountYuan, mobile);
|
||||
|
||||
// 可订检查:下单前确认资源可预订
|
||||
boolean available = ctripDistApiService.checkAvailability(request);
|
||||
if (!available) {
|
||||
throw new RuntimeException("携程可订检查失败,资源不可预订,orderNo: " + orderNo);
|
||||
}
|
||||
log.info("携程可订检查通过,orderNo: {}", orderNo);
|
||||
|
||||
CtripDistOrder order = new CtripDistOrder();
|
||||
order.setTenantId(tenantId);
|
||||
order.setOrderNo(orderNo);
|
||||
order.setCtripProductId(ctripProductId);
|
||||
order.setCtripPackageId(packageId);
|
||||
order.setCtripResourceId(resourceId);
|
||||
order.setDistributorOrderId(distributorOrderId);
|
||||
order.setOrderAmount(amountYuan);
|
||||
order.setCurrency(config.getCurrency());
|
||||
order.setCtripOrderStatus("CREATING");
|
||||
order.setConsumeStatus(0);
|
||||
order.setRefundStatus(0);
|
||||
order.setRetryCount(0);
|
||||
order.setDeleted(0);
|
||||
ctripDistOrderMapper.insert(order);
|
||||
|
||||
try {
|
||||
CtripDistBookResponse response = ctripDistApiService.createOrder(request);
|
||||
if (response != null && response.isSuccess() && response.getData() != null && response.getData().getOrderId() != null) {
|
||||
order.setCtripOrderId(response.getData().getOrderId());
|
||||
order.setCtripOrderStatus("CONFIRMED");
|
||||
order.setErrorMsg(null);
|
||||
} else {
|
||||
order.setCtripOrderStatus("CREATE_FAILED");
|
||||
order.setErrorMsg(response == null ? "携程分销商下单返回为空" : response.getErrmsg());
|
||||
}
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
} catch (Exception e) {
|
||||
log.error("创建携程分销商订单异常,orderNo: {}", orderNo, e);
|
||||
order.setCtripOrderStatus("CREATE_FAILED");
|
||||
order.setErrorMsg(e.getMessage());
|
||||
order.setRetryCount(order.getRetryCount() == null ? 1 : order.getRetryCount() + 1);
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean cancelCtripDistOrder(String orderNo, String reason) {
|
||||
CtripDistOrder order = ctripDistOrderMapper.selectByOrderNo(orderNo);
|
||||
if (order == null) {
|
||||
log.warn("未找到携程分销商订单,orderNo: {}", orderNo);
|
||||
return false;
|
||||
}
|
||||
if (Integer.valueOf(1).equals(order.getConsumeStatus())) {
|
||||
log.warn("订单已核销不可退,orderNo: {}", orderNo);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
CtripDistCancelVerifyResponse verifyResponse = ctripDistApiService.cancelVerify(order.getCtripOrderId());
|
||||
if (verifyResponse == null || verifyResponse.getCancelVerifyData() == null
|
||||
|| verifyResponse.getCancelVerifyData().getCancelVerifyStatus() == null
|
||||
|| verifyResponse.getCancelVerifyData().getCancelVerifyStatus() == 0) {
|
||||
order.setRefundStatus(2);
|
||||
order.setErrorMsg(verifyResponse == null ? "退订验证失败" : verifyResponse.getErrmsg());
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
return false;
|
||||
}
|
||||
|
||||
CtripDistCancelResponse cancelResponse = ctripDistApiService.cancelOrder(order.getCtripOrderId(), reason);
|
||||
if (cancelResponse != null && cancelResponse.isSuccess()) {
|
||||
order.setCtripOrderStatus("CANCELLED");
|
||||
order.setRefundStatus(1);
|
||||
order.setRefundTime(LocalDateTime.now());
|
||||
order.setRefundAmount(verifyResponse.getCancelVerifyData().getRefundAmount());
|
||||
order.setErrorMsg(null);
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
return true;
|
||||
}
|
||||
|
||||
order.setRefundStatus(2);
|
||||
order.setErrorMsg(cancelResponse == null ? "携程分销商取消订单失败" : cancelResponse.getErrmsg());
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.error("取消携程分销商订单异常,orderNo: {}", orderNo, e);
|
||||
order.setRefundStatus(2);
|
||||
order.setErrorMsg(e.getMessage());
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CtripDistOrder getByOrderNo(String orderNo) {
|
||||
return ctripDistOrderMapper.selectByOrderNo(orderNo);
|
||||
}
|
||||
|
||||
private static final String DEFAULT_CONTACT_NAME = "杜超";
|
||||
private static final String DEFAULT_CONTACT_MOBILE = "18222892722";
|
||||
private static final String DEFAULT_CONTACT_EMAIL = "1098974448@qq.com";
|
||||
|
||||
private CtripDistBookRequest buildBookRequest(String distributorOrderId, Long productId, Long packageId,
|
||||
Long resourceId, BigDecimal amountYuan, String userMobile) {
|
||||
CtripDistBookRequest request = new CtripDistBookRequest();
|
||||
request.setLocale(config.getLocale());
|
||||
request.setCurrency(config.getCurrency());
|
||||
request.setDistributorOrderID(distributorOrderId);
|
||||
|
||||
// 联系人:优先使用真实手机号,没有则用默认值
|
||||
String contactMobile = (userMobile != null && !userMobile.isEmpty()) ? userMobile : DEFAULT_CONTACT_MOBILE;
|
||||
CtripDistBookRequest.Contact contact = new CtripDistBookRequest.Contact();
|
||||
contact.setName(DEFAULT_CONTACT_NAME);
|
||||
CtripDistBookRequest.Mobile mobile = new CtripDistBookRequest.Mobile();
|
||||
mobile.setInternationalTelephoneCode("86");
|
||||
mobile.setMobileNumber(contactMobile);
|
||||
contact.setMobile(mobile);
|
||||
contact.setEmail(DEFAULT_CONTACT_EMAIL);
|
||||
request.setContact(contact);
|
||||
|
||||
CtripDistBookRequest.Passenger passenger = new CtripDistBookRequest.Passenger();
|
||||
passenger.setPackageID(packageId);
|
||||
passenger.setResourceID(resourceId);
|
||||
passenger.setQuestionAnswerList(new ArrayList<>());
|
||||
request.setPassengerList(Collections.singletonList(passenger));
|
||||
|
||||
CtripDistBookRequest.OrderResource orderResource = new CtripDistBookRequest.OrderResource();
|
||||
orderResource.setResourceID(resourceId);
|
||||
orderResource.setUseDate(LocalDate.now().format(USE_DATE_FORMATTER));
|
||||
orderResource.setQuantity(1);
|
||||
orderResource.setPrice(amountYuan);
|
||||
|
||||
CtripDistBookRequest.BasicOrder basicOrder = new CtripDistBookRequest.BasicOrder();
|
||||
basicOrder.setProductID(productId);
|
||||
basicOrder.setAmount(amountYuan);
|
||||
basicOrder.setPackageID(packageId);
|
||||
basicOrder.setOrderResourceList(Collections.singletonList(orderResource));
|
||||
request.setBasicOrder(basicOrder);
|
||||
return request;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Long extractPackageId(Map<String, Object> productDetail) {
|
||||
Map<String, Object> data = (Map<String, Object>) productDetail.get("data");
|
||||
List<Map<String, Object>> productList = (List<Map<String, Object>>) data.get("productList");
|
||||
Map<String, Object> product = productList.get(0);
|
||||
List<Map<String, Object>> packageList = (List<Map<String, Object>>) product.get("packageList");
|
||||
Map<String, Object> pkg = packageList.get(0);
|
||||
return Long.valueOf(pkg.get("packageID").toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Long extractResourceId(Map<String, Object> productDetail) {
|
||||
Map<String, Object> data = (Map<String, Object>) productDetail.get("data");
|
||||
List<Map<String, Object>> productList = (List<Map<String, Object>>) data.get("productList");
|
||||
Map<String, Object> product = productList.get(0);
|
||||
List<Map<String, Object>> packageList = (List<Map<String, Object>>) product.get("packageList");
|
||||
Map<String, Object> pkg = packageList.get(0);
|
||||
List<Map<String, Object>> resourceList = (List<Map<String, Object>>) pkg.get("resourceList");
|
||||
Map<String, Object> resource = resourceList.get(0);
|
||||
return Long.valueOf(resource.get("resourceID").toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验下单填写信息
|
||||
* 如果产品要求额外乘客问卷(如身份证等),当前平台无法提供,拒绝自动下单
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void validateBookInfo(Map<String, Object> bookInfo, String orderNo) {
|
||||
if (bookInfo == null || bookInfo.get("data") == null) {
|
||||
log.warn("获取下单填写信息为空,orderNo: {},继续尝试下单", orderNo);
|
||||
return;
|
||||
}
|
||||
Map<String, Object> data = (Map<String, Object>) bookInfo.get("data");
|
||||
Object questionList = data.get("passengerQuestionList");
|
||||
if (questionList instanceof List) {
|
||||
List<?> questions = (List<?>) questionList;
|
||||
if (!questions.isEmpty()) {
|
||||
throw new RuntimeException("该携程产品要求填写额外乘客信息(如身份证等),无法自动下单,orderNo: " + orderNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package com.central.coupon.service.impl;
|
||||
|
||||
import com.central.common.utils.http.SimpleHttpRequest;
|
||||
import com.central.coupon.config.CtripDistributorConfig;
|
||||
import com.central.coupon.service.ICtripDistTokenService;
|
||||
import com.central.coupon.util.SslUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 携程分销商Token管理服务实现
|
||||
* 使用SimpleHttpRequest替代RestTemplate,解决HTTPS连接兼容性问题
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CtripDistTokenServiceImpl implements ICtripDistTokenService {
|
||||
|
||||
private static final long TOKEN_BUFFER_SECONDS = 60L;
|
||||
|
||||
@Autowired
|
||||
private CtripDistributorConfig config;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private volatile String accessToken;
|
||||
private volatile String refreshToken;
|
||||
private volatile LocalDateTime tokenExpireTime;
|
||||
|
||||
@Override
|
||||
public synchronized String getAccessToken() {
|
||||
if (isTokenValid()) {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
if (refreshToken != null && !refreshToken.isEmpty()) {
|
||||
try {
|
||||
refreshAccessToken();
|
||||
if (isTokenValid()) {
|
||||
return accessToken;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("刷新携程分销商Token失败,将重新获取新Token", e);
|
||||
}
|
||||
}
|
||||
|
||||
fetchNewToken();
|
||||
if (!isTokenValid()) {
|
||||
throw new RuntimeException("获取携程分销商AccessToken失败");
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
private boolean isTokenValid() {
|
||||
return accessToken != null
|
||||
&& tokenExpireTime != null
|
||||
&& LocalDateTime.now().plusSeconds(TOKEN_BUFFER_SECONDS).isBefore(tokenExpireTime);
|
||||
}
|
||||
|
||||
private void fetchNewToken() {
|
||||
String url = String.format("%s?aid=%s&sid=%s&key=%s",
|
||||
config.getAuthUrl(), config.getAid(), config.getSid(), config.getKey());
|
||||
log.info("获取新的携程分销商Token,请求URL: {}", url);
|
||||
String responseBody = doGet(url);
|
||||
log.info("携程分销商Token接口原始响应: {}", responseBody);
|
||||
parseTokenResponse(responseBody);
|
||||
}
|
||||
|
||||
private void refreshAccessToken() {
|
||||
String url = String.format("%s?aid=%s&sid=%s&refresh_token=%s",
|
||||
config.getRefreshUrl(), config.getAid(), config.getSid(), refreshToken);
|
||||
log.info("刷新携程分销商Token,请求URL: {}", url);
|
||||
String responseBody = doGet(url);
|
||||
log.info("携程分销商Token刷新响应: {}", responseBody);
|
||||
parseTokenResponse(responseBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用SimpleHttpRequest发起GET请求
|
||||
*/
|
||||
private String doGet(String url) {
|
||||
try {
|
||||
SimpleHttpRequest request = new SimpleHttpRequest(url, SslUtil.createTrustAllHttpClient());
|
||||
request.resultAsJsonString();
|
||||
byte[] bytes = request.get().asBytes();
|
||||
request.close();
|
||||
return new String(bytes, "UTF-8");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("携程分销商HTTP请求失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void parseTokenResponse(String responseBody) {
|
||||
if (responseBody == null || responseBody.isEmpty()) {
|
||||
throw new RuntimeException("携程分销商Token接口返回为空");
|
||||
}
|
||||
|
||||
Map<String, Object> response;
|
||||
try {
|
||||
response = objectMapper.readValue(responseBody, Map.class);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("携程分销商Token响应解析失败: " + responseBody, e);
|
||||
}
|
||||
|
||||
Object errCode = response.get("ErrCode");
|
||||
int code = errCode == null ? 0 : Integer.parseInt(errCode.toString());
|
||||
if (code != 0) {
|
||||
throw new RuntimeException("携程分销商Token接口调用失败: " + response.get("ErrMsg"));
|
||||
}
|
||||
|
||||
Object expiresIn = response.get("Expires_In");
|
||||
if (response.get("Access_Token") == null || response.get("Refresh_Token") == null || expiresIn == null) {
|
||||
throw new RuntimeException("携程分销商Token响应缺少必要字段: " + responseBody);
|
||||
}
|
||||
|
||||
this.accessToken = response.get("Access_Token").toString();
|
||||
this.refreshToken = response.get("Refresh_Token").toString();
|
||||
this.tokenExpireTime = LocalDateTime.now().plusSeconds(Long.parseLong(expiresIn.toString()));
|
||||
log.info("携程分销商Token更新成功,过期时间: {}", tokenExpireTime);
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package com.central.coupon.task;
|
||||
|
||||
import com.central.coupon.entity.CtripDistOrder;
|
||||
import com.central.coupon.mapper.CtripDistOrderMapper;
|
||||
import com.central.coupon.model.CtripDistBookingDetailResponse;
|
||||
import com.central.coupon.service.ICtripDistApiService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CtripDistConsumeTask {
|
||||
|
||||
@Autowired
|
||||
private CtripDistOrderMapper ctripDistOrderMapper;
|
||||
|
||||
@Autowired
|
||||
private ICtripDistApiService ctripDistApiService;
|
||||
|
||||
/**
|
||||
* 每天凌晨3点执行:核销2天前创建且未核销的携程分销订单
|
||||
*/
|
||||
@Scheduled(cron = "0 0 3 * * ?")
|
||||
public void autoConsumeCtripDistOrders() {
|
||||
log.info("开始自动核销携程分销订单");
|
||||
try {
|
||||
List<CtripDistOrder> pendingOrders = ctripDistOrderMapper.selectPendingConsumeOrders(2);
|
||||
log.info("待核销的携程分销订单数量: {}", pendingOrders.size());
|
||||
|
||||
for (CtripDistOrder order : pendingOrders) {
|
||||
try {
|
||||
consumeOrder(order);
|
||||
} catch (Exception e) {
|
||||
log.error("核销携程分销订单失败,orderNo: {}", order.getOrderNo(), e);
|
||||
order.setConsumeStatus(2);
|
||||
order.setErrorMsg("核销失败: " + e.getMessage());
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
}
|
||||
}
|
||||
log.info("携程分销订单自动核销完成");
|
||||
} catch (Exception e) {
|
||||
log.error("自动核销携程分销订单任务异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 核销单个订单
|
||||
* 先查询携程订单状态确认为CONFIRMED,然后标记为已核销
|
||||
*/
|
||||
private void consumeOrder(CtripDistOrder order) {
|
||||
log.info("开始核销携程分销订单,orderNo: {}, ctripOrderId: {}",
|
||||
order.getOrderNo(), order.getCtripOrderId());
|
||||
|
||||
// 查询携程订单当前状态
|
||||
CtripDistBookingDetailResponse detail = ctripDistApiService.getOrderDetail(order.getCtripOrderId());
|
||||
if (detail != null && detail.isSuccess() && detail.getData() != null
|
||||
&& detail.getData().getOrder() != null) {
|
||||
String ctripStatus = detail.getData().getOrder().getOrderStatus();
|
||||
log.info("携程订单当前状态: {}, orderNo: {}", ctripStatus, order.getOrderNo());
|
||||
|
||||
if ("CONFIRMED".equals(ctripStatus)) {
|
||||
// 订单状态正常,执行核销
|
||||
order.setConsumeStatus(1);
|
||||
order.setConsumeTime(LocalDateTime.now());
|
||||
order.setCtripOrderStatus("CONSUMED");
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
log.info("携程分销订单核销成功,orderNo: {}", order.getOrderNo());
|
||||
} else if ("CANCELLED".equals(ctripStatus) || "CANCELLED_RESERVATION".equals(ctripStatus)) {
|
||||
// 订单已被取消,更新状态
|
||||
order.setCtripOrderStatus(ctripStatus);
|
||||
order.setConsumeStatus(2);
|
||||
order.setErrorMsg("携程订单已被取消,无法核销");
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
log.warn("携程订单已取消,跳过核销,orderNo: {}", order.getOrderNo());
|
||||
} else {
|
||||
log.warn("携程订单状态不适合核销: {},orderNo: {}", ctripStatus, order.getOrderNo());
|
||||
}
|
||||
} else {
|
||||
log.error("查询携程订单详情失败,orderNo: {}", order.getOrderNo());
|
||||
order.setConsumeStatus(2);
|
||||
order.setErrorMsg("查询携程订单详情失败");
|
||||
ctripDistOrderMapper.updateById(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.central.coupon.util;
|
||||
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
/**
|
||||
* SSL工具类
|
||||
* 提供信任所有证书的HttpClient,解决携程HTTPS证书信任链问题
|
||||
*/
|
||||
public class SslUtil {
|
||||
|
||||
private SslUtil() {}
|
||||
|
||||
/** 默认超时时间:15秒(携程可订/下单接口要求15s超时) */
|
||||
private static final int DEFAULT_TIMEOUT_MS = 15000;
|
||||
|
||||
/**
|
||||
* 创建信任所有证书的HttpClient(使用默认15秒超��)
|
||||
*/
|
||||
public static HttpClient createTrustAllHttpClient() {
|
||||
return createTrustAllHttpClient(DEFAULT_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建信任所有证书的HttpClient(自定义超时)
|
||||
*
|
||||
* @param timeoutMs 超时时间(毫秒),同时设置连接超时和读取超时
|
||||
*/
|
||||
public static HttpClient createTrustAllHttpClient(int timeoutMs) {
|
||||
try {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, new TrustManager[]{new X509TrustManager() {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[0];
|
||||
}
|
||||
}}, new java.security.SecureRandom());
|
||||
|
||||
SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(
|
||||
sslContext, NoopHostnameVerifier.INSTANCE);
|
||||
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(timeoutMs)
|
||||
.setSocketTimeout(timeoutMs)
|
||||
.setConnectionRequestTimeout(timeoutMs)
|
||||
.build();
|
||||
|
||||
return HttpClients.custom()
|
||||
.setSSLSocketFactory(sslFactory)
|
||||
.setDefaultRequestConfig(requestConfig)
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("创建信任所有证书的HttpClient失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.coupon.mapper.CtripDistOrderMapper">
|
||||
|
||||
<select id="selectByOrderNo" resultType="com.central.coupon.entity.CtripDistOrder">
|
||||
SELECT *
|
||||
FROM t_ctrip_dist_order
|
||||
WHERE order_no = #{orderNo}
|
||||
AND deleted = 0
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectPendingConsumeOrders" resultType="com.central.coupon.entity.CtripDistOrder">
|
||||
SELECT *
|
||||
FROM t_ctrip_dist_order
|
||||
WHERE ctrip_order_status = 'CONFIRMED'
|
||||
AND consume_status = 0
|
||||
AND deleted = 0
|
||||
AND create_time <= DATE_SUB(NOW(), INTERVAL #{daysAgo} DAY)
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
<select id="selectByDistributorOrderId" resultType="com.central.coupon.entity.CtripDistOrder">
|
||||
SELECT *
|
||||
FROM t_ctrip_dist_order
|
||||
WHERE distributor_order_id = #{distributorOrderId}
|
||||
AND deleted = 0
|
||||
LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,32 @@
|
||||
-- 携程分销订单关联表(我方订单 ↔ 携程订单)
|
||||
-- 用途:记录本地订单与携程分销订单的对应关系,跟踪核销和退款状态
|
||||
CREATE TABLE IF NOT EXISTS `t_ctrip_dist_order` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
||||
`order_no` varchar(100) NOT NULL COMMENT '本地订单号(order-center的订单号)',
|
||||
`ctrip_order_id` bigint(20) DEFAULT NULL COMMENT '携程订单ID(/book返回的orderId)',
|
||||
`ctrip_product_id` bigint(20) NOT NULL COMMENT '携程产品ID',
|
||||
`ctrip_package_id` bigint(20) DEFAULT NULL COMMENT '携程套餐ID',
|
||||
`ctrip_resource_id` bigint(20) DEFAULT NULL COMMENT '携程资源ID',
|
||||
`distributor_order_id` varchar(100) NOT NULL COMMENT '分销商订单ID(传给携程的唯一标识)',
|
||||
`order_amount` decimal(10,2) DEFAULT NULL COMMENT '订单金额',
|
||||
`currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
||||
`ctrip_order_status` varchar(50) DEFAULT 'PENDING' COMMENT '携程订单状态',
|
||||
`consume_status` tinyint(1) DEFAULT 0 COMMENT '核销状态(0:未核销,1:已核销,2:核销失败)',
|
||||
`consume_time` datetime DEFAULT NULL COMMENT '核销时间',
|
||||
`refund_status` tinyint(1) DEFAULT 0 COMMENT '退款状态(0:未退款,1:已退款,2:退款失败)',
|
||||
`refund_time` datetime DEFAULT NULL COMMENT '退款时间',
|
||||
`refund_amount` decimal(10,2) DEFAULT NULL COMMENT '退款金额',
|
||||
`error_msg` varchar(500) DEFAULT NULL COMMENT '错误信息(创建失败/核销失败/退款失败时记录)',
|
||||
`retry_count` int(11) DEFAULT 0 COMMENT '重试次数',
|
||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_order_no` (`order_no`),
|
||||
UNIQUE KEY `uk_distributor_order_id` (`distributor_order_id`),
|
||||
KEY `idx_ctrip_order_id` (`ctrip_order_id`),
|
||||
KEY `idx_consume_status` (`consume_status`),
|
||||
KEY `idx_create_time` (`create_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程分销订单关联表';
|
||||
Reference in New Issue
Block a user