diff --git a/zlt-business/coupon-center/src/main/java/com/central/coupon/config/CtripDistributorConfig.java b/zlt-business/coupon-center/src/main/java/com/central/coupon/config/CtripDistributorConfig.java index 199c8146..b5439ae7 100644 --- a/zlt-business/coupon-center/src/main/java/com/central/coupon/config/CtripDistributorConfig.java +++ b/zlt-business/coupon-center/src/main/java/com/central/coupon/config/CtripDistributorConfig.java @@ -104,5 +104,20 @@ public class CtripDistributorConfig { * 沙箱测试-人工出票/退订确认/凭证变更接口icode */ private String simulateConfirm; + + /** + * 产品列表接口icode + */ + private String productList; + + /** + * 位置列表接口icode + */ + private String locationList; + + /** + * 产品全量列表接口icode + */ + private String allProducts; } } diff --git a/zlt-business/coupon-center/src/main/java/com/central/coupon/controller/CtripDistTestController.java b/zlt-business/coupon-center/src/main/java/com/central/coupon/controller/CtripDistTestController.java index 616279f6..41a97a30 100644 --- a/zlt-business/coupon-center/src/main/java/com/central/coupon/controller/CtripDistTestController.java +++ b/zlt-business/coupon-center/src/main/java/com/central/coupon/controller/CtripDistTestController.java @@ -82,6 +82,7 @@ public class CtripDistTestController { icode.put("cancelVerify", ctripDistributorConfig.getIcode().getCancelVerify()); icode.put("cancel", ctripDistributorConfig.getIcode().getCancel()); icode.put("bookingDetail", ctripDistributorConfig.getIcode().getBookingDetail()); + icode.put("allProducts",ctripDistributorConfig.getIcode().getAllProducts()); data.put("icode", icode); } else { data.put("icode", "null - icode未配置!"); @@ -536,6 +537,145 @@ public class CtripDistTestController { } } + // ==================== 9. 获取位置列表 ==================== + + /** + * 获取位置列表 + * 用途:查询可用城市/地区列表,获取locationID和locationType供产品列表接口使用 + * locale固定为zh-CN + * + * 调用示例:GET /ctrip/dist/test/location-list?pageIndex=1&pageSize=20 + */ + @GetMapping("/location-list") + @Operation(summary = "9.获取位置列表") + public Result> testLocationList( + @RequestParam(defaultValue = "1") int pageIndex, + @RequestParam(defaultValue = "20") int pageSize) { + log.info("===== 获取位置列表,pageIndex: {}, pageSize: {} =====", pageIndex, pageSize); + try { + Map result = ctripDistApiService.getLocationList(pageIndex, pageSize); + log.info("位置列表返回: {}", result); + return Result.succeed(result, "获取位置列表成功"); + } catch (Exception e) { + log.error("获取位置列表失败", e); + return Result.failed("获取位置列表失败: " + e.getMessage()); + } + } + + // ==================== 10. 获取产品列表 ==================== + + /** + * 获取产品列表 + * 用途:查询产品列表,site和destination的locationID/locationType自动从位置列表接口获取 + * 可通过locationIndex指定使用位置列表中的第几个位置(0-based,默认0) + * + * 调用示例:POST /ctrip/dist/test/product-list + * Body: + * { + * "locale": "zh-HK", + * "currency": "HKD", + * "categoryIDList": [1, 2], + * "sortOrder": "ID_A", + * "pageIndex": 1, + * "pageSize": 10, + * "imageSize": "500_280", + * "poiIDList": [], + * "keyWord": "", + * "lastUpdateProductID": 0, + * "business": "ACTIVITY", + * "locationIndex": 0 + * } + */ + @PostMapping("/product-list") + @Operation(summary = "10.获取产品列表(自动填充位置)") + @SuppressWarnings("unchecked") + public Result> testProductList(@RequestBody Map params) { + log.info("===== 获取产品列表,params: {} =====", params); + try { + // 提取locationIndex并从请求体中移除(不传给产品列表接口) + int locationIndex = params.containsKey("locationIndex") + ? Integer.parseInt(params.get("locationIndex").toString()) : 0; + Map productListRequest = new java.util.LinkedHashMap<>(params); + productListRequest.remove("locationIndex"); + + // 第一步:调用位置列表接口获取locationID和locationType + log.info("第一步:调用位置列表接口,locale=zh-CN,取第{}个位置", locationIndex); + Map locationResult = ctripDistApiService.getLocationList(1, 20); + Object locationData = locationResult.get("data"); + if (locationData == null) { + return Result.failed("位置列表接口返回data为空,无法获取locationID"); + } + List> locationList = + (List>) ((Map) locationData).get("locationList"); + if (locationList == null || locationList.isEmpty()) { + return Result.failed("位置列表为空,无法获取locationID"); + } + if (locationIndex >= locationList.size()) { + return Result.failed("locationIndex=" + locationIndex + " 超出位置列表范围(共" + locationList.size() + "个位置)"); + } + Map location = locationList.get(locationIndex); + Object locationID = location.get("locationID"); + Object locationType = location.get("type"); + log.info("获取到位置:locationID={}, type={}, name={}", locationID, locationType, location.get("name")); + + // 第二步:用获取到的locationID和locationType填充site和destination + Map siteMap = new java.util.LinkedHashMap<>(); + siteMap.put("locationID", locationID); + siteMap.put("locationType", locationType); + Map destinationMap = new java.util.LinkedHashMap<>(); + destinationMap.put("locationID", locationID); + destinationMap.put("locationType", locationType); + productListRequest.put("site", siteMap); + productListRequest.put("destination", destinationMap); + + log.info("第二步:调用产品列表接口,site/destination locationID={}, locationType={}", locationID, locationType); + + // 第三步:调用产品列表接口 + Map result = ctripDistApiService.getProductList(productListRequest); + log.info("产品列表返回: {}", result); + + // 在返回结果中附加使用的位置信息,方便调试 + Map response = new java.util.LinkedHashMap<>(); + response.put("usedLocation", location); + response.put("productListResult", result); + return Result.succeed(response, "获取产品列表成功"); + } catch (Exception e) { + log.error("获取产品列表失败", e); + return Result.failed("获取产品列表失败: " + e.getMessage()); + } + } + + // ==================== 11. 获取产品全量列表 ==================== + + /** + * 获取产品全量列表 + * 用途:分批拉取指定业务类型下的全量产品ID及销售状态 + * 首次调用 lastMaxId 传 "0",后续将上次返回的 maxId 作为 lastMaxId 继续翻页, + * 直到返回的 productList 为空或数量小于 limit 为止 + * + * 调用示例:GET /ctrip/dist/test/all-products?business=ACTIVITY&lastMaxId=0&limit=50 + */ + @GetMapping("/all-products") + @Operation(summary = "11.获取产品全量列表") + public Result> testAllProducts( + @RequestParam(defaultValue = "ACTIVITY") String business, + @RequestParam(defaultValue = "0") String lastMaxId, + @RequestParam(defaultValue = "50") int limit) { + log.info("===== 获取产品全量列表,business: {}, lastMaxId: {}, limit: {} =====", + business, lastMaxId, limit); + try { + Map result = ctripDistApiService.getAllProducts(business, lastMaxId, limit); + log.info("产品全量列表返回: success={}, maxId={}, productList size={}", + result.get("success"), result.get("maxId"), + result.get("productList") instanceof java.util.List + ? ((java.util.List) result.get("productList")).size() : 0); + return Result.succeed(result, "获取产品全量列表成功"); + } catch (Exception e) { + log.error("获取产品全量列表失败", e); + return Result.failed("获取产品全量列表失败: " + e.getMessage()); + } + } + // ==================== 辅助方法 ==================== /** diff --git a/zlt-business/coupon-center/src/main/java/com/central/coupon/service/ICtripDistApiService.java b/zlt-business/coupon-center/src/main/java/com/central/coupon/service/ICtripDistApiService.java index b9c27fcf..4c6b8c75 100644 --- a/zlt-business/coupon-center/src/main/java/com/central/coupon/service/ICtripDistApiService.java +++ b/zlt-business/coupon-center/src/main/java/com/central/coupon/service/ICtripDistApiService.java @@ -98,4 +98,31 @@ public interface ICtripDistApiService { * @return 响应 */ Map simulateConfirm(Map requestBody); + + /** + * 获取位置列表 + * + * @param pageIndex 页码 + * @param pageSize 每页数量 + * @return 位置列表 + */ + Map getLocationList(int pageIndex, int pageSize); + + /** + * 获取产品列表 + * + * @param request 请求参数 + * @return 产品列表 + */ + Map getProductList(Map request); + + /** + * 获取产品全量列表 + * + * @param business 业务类型(如 ACTIVITY) + * @param lastMaxId 上次返回的maxId,首次传"0" + * @param limit 每页条数 + * @return 产品全量列表 + */ + Map getAllProducts(String business, String lastMaxId, int limit); } diff --git a/zlt-business/coupon-center/src/main/java/com/central/coupon/service/impl/CtripDistApiServiceImpl.java b/zlt-business/coupon-center/src/main/java/com/central/coupon/service/impl/CtripDistApiServiceImpl.java index 70fb3a1a..7e7ef194 100644 --- a/zlt-business/coupon-center/src/main/java/com/central/coupon/service/impl/CtripDistApiServiceImpl.java +++ b/zlt-business/coupon-center/src/main/java/com/central/coupon/service/impl/CtripDistApiServiceImpl.java @@ -117,6 +117,29 @@ public class CtripDistApiServiceImpl implements ICtripDistApiService { return callApi(config.getIcode().getSimulateConfirm(), requestBody, Map.class); } + @Override + public Map getLocationList(int pageIndex, int pageSize) { + Map requestBody = new HashMap<>(); + requestBody.put("locale", "zh-CN"); + requestBody.put("pageIndex", pageIndex); + requestBody.put("pageSize", pageSize); + return callApi(config.getIcode().getLocationList(), requestBody, Map.class); + } + + @Override + public Map getProductList(Map request) { + return callApi(config.getIcode().getProductList(), request, Map.class); + } + + @Override + public Map getAllProducts(String business, String lastMaxId, int limit) { + Map requestBody = new HashMap<>(); + requestBody.put("business", business); + requestBody.put("lastMaxId", lastMaxId); + requestBody.put("limit", limit); + return callApi(config.getIcode().getAllProducts(), requestBody, Map.class); + } + private T callApi(String icode, Object requestBody, Class responseType) { String token = tokenService.getAccessToken(); String uuid = UUID.randomUUID().toString().replace("-", "");