fix(优惠券中心):新增携程优惠券独立微服务模块
This commit is contained in:
@@ -1,193 +0,0 @@
|
||||
# TourismWithDistance 类修复
|
||||
|
||||
## 问题描述
|
||||
|
||||
`TourismWithDistance` 类被误删,导致以下功能无法正常工作:
|
||||
- 查询附近景区列表接口 `/tourism/nearby`
|
||||
- 景区距离计算和显示
|
||||
- 景区订单展示图片URL设置
|
||||
|
||||
## 解决方案
|
||||
|
||||
### 1. 重新创建 TourismWithDistance 类
|
||||
|
||||
在 `zlt-business/order-center/src/main/java/com/central/order/model/TourismWithDistance.java` 中重新创建了该类:
|
||||
|
||||
```java
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TourismWithDistance extends Tourism {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 距离(公里)
|
||||
*/
|
||||
private BigDecimal distance;
|
||||
|
||||
/**
|
||||
* 距离描述(如:1.2km)
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String distanceDesc;
|
||||
|
||||
/**
|
||||
* 景区订单展示图片URL
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String orderShowImageUrl;
|
||||
|
||||
/**
|
||||
* 获取距离描述
|
||||
* @return 距离描述字符串
|
||||
*/
|
||||
public String getDistanceDesc() {
|
||||
if (distance == null) {
|
||||
return "未知距离";
|
||||
}
|
||||
|
||||
if (distance.compareTo(BigDecimal.ONE) < 0) {
|
||||
// 小于1公里,显示为米
|
||||
int meters = distance.multiply(new BigDecimal("1000")).intValue();
|
||||
return meters + "m";
|
||||
} else {
|
||||
// 大于等于1公里,显示为公里
|
||||
return distance.setScale(1, BigDecimal.ROUND_HALF_UP) + "km";
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 类特性
|
||||
|
||||
#### 2.1 继承关系
|
||||
- 继承自 `Tourism` 类,拥有所有景区基本信息
|
||||
- 使用 `@EqualsAndHashCode(callSuper = true)` 确保正确的继承行为
|
||||
|
||||
#### 2.2 新增字段
|
||||
- `distance`: 距离(公里),BigDecimal 类型,精确计算
|
||||
- `distanceDesc`: 距离描述,如 "1.2km" 或 "500m"
|
||||
- `orderShowImageUrl`: 景区订单展示图片URL
|
||||
|
||||
#### 2.3 智能距离描述
|
||||
- 自动根据距离大小选择合适的单位(米/公里)
|
||||
- 小于1公里显示为米,如 "500m"
|
||||
- 大于等于1公里显示为公里,如 "1.2km"
|
||||
- 支持自定义距离描述
|
||||
|
||||
### 3. 使用场景
|
||||
|
||||
#### 3.1 查询附近景区
|
||||
```java
|
||||
@GetMapping("/nearby")
|
||||
public Result<List<TourismWithDistance>> findNearbyTourisms(
|
||||
@RequestParam BigDecimal longitude,
|
||||
@RequestParam BigDecimal latitude,
|
||||
@RequestParam(required = false) Double radius,
|
||||
@RequestParam(required = false) Integer limit) {
|
||||
// 返回包含距离信息的景区列表
|
||||
}
|
||||
```
|
||||
|
||||
#### 3.2 数据库查询
|
||||
在 `TourismMapper.xml` 中,SQL 查询会自动计算距离:
|
||||
|
||||
```xml
|
||||
<select id="findNearbyTourisms" resultType="com.central.order.model.TourismWithDistance">
|
||||
<![CDATA[
|
||||
SELECT
|
||||
*,
|
||||
(
|
||||
6371 * acos(
|
||||
cos(radians(#{latitude})) *
|
||||
cos(radians(latitude)) *
|
||||
cos(radians(longitude) - radians(#{longitude})) +
|
||||
sin(radians(#{latitude})) *
|
||||
sin(radians(latitude))
|
||||
)
|
||||
) AS distance
|
||||
FROM tourisms
|
||||
WHERE is_del = 0
|
||||
AND status = 1
|
||||
AND longitude IS NOT NULL
|
||||
AND latitude IS NOT NULL
|
||||
HAVING distance <= #{radius}
|
||||
ORDER BY distance ASC
|
||||
]]>
|
||||
</select>
|
||||
```
|
||||
|
||||
### 4. 前端类型定义
|
||||
|
||||
在 `zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts` 中:
|
||||
|
||||
```typescript
|
||||
type TourismWithDistance = Tourism & {
|
||||
distance?: number; // 距离(公里)
|
||||
distanceDesc?: string; // 距离描述
|
||||
orderShowImageUrl?: string; // 景区订单展示图片URL
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 单元测试
|
||||
|
||||
创建了完整的单元测试 `TourismWithDistanceTest.java`,测试:
|
||||
- 距离描述计算
|
||||
- 继承关系
|
||||
- 订单展示图片URL
|
||||
- 自定义距离描述
|
||||
|
||||
## 修复效果
|
||||
|
||||
### ✅ 已修复的功能
|
||||
1. **查询附近景区接口** - 正常返回包含距离信息的景区列表
|
||||
2. **距离计算** - 自动计算并格式化距离显示
|
||||
3. **景区图片** - 支持设置和获取订单展示图片
|
||||
4. **类型安全** - 完整的类型定义和继承关系
|
||||
|
||||
### 🔧 技术特点
|
||||
- **精确计算**: 使用 BigDecimal 进行距离计算,避免浮点数精度问题
|
||||
- **智能显示**: 根据距离大小自动选择合适的单位
|
||||
- **类型安全**: 完整的 Lombok 注解和继承关系
|
||||
- **测试覆盖**: 完整的单元测试确保功能正确性
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 后端使用
|
||||
```java
|
||||
// 查询附近景区
|
||||
List<TourismWithDistance> nearbyTourisms = tourismService.findNearbyTourisms(
|
||||
new BigDecimal("116.397128"),
|
||||
new BigDecimal("39.916527"),
|
||||
10.0, // 10公里半径
|
||||
20 // 最多返回20个
|
||||
);
|
||||
|
||||
// 获取距离描述
|
||||
for (TourismWithDistance tourism : nearbyTourisms) {
|
||||
System.out.println(tourism.getTourismName() + ": " + tourism.getDistanceDesc());
|
||||
}
|
||||
```
|
||||
|
||||
### 前端使用
|
||||
```typescript
|
||||
// 调用附近景区接口
|
||||
const response = await findNearbyTourisms({
|
||||
longitude: 116.397128,
|
||||
latitude: 39.916527,
|
||||
radius: 10,
|
||||
limit: 20
|
||||
});
|
||||
|
||||
// 显示景区信息
|
||||
response.data.forEach(tourism => {
|
||||
console.log(`${tourism.tourismName}: ${tourism.distanceDesc}`);
|
||||
});
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **数据库字段**: 确保 `tourisms` 表中有 `longitude` 和 `latitude` 字段
|
||||
2. **索引优化**: 建议为经纬度字段添加索引以提高查询性能
|
||||
3. **距离计算**: 使用球面距离公式,适用于地球表面的距离计算
|
||||
4. **性能考虑**: 对于大量数据,建议添加适当的查询限制和缓存机制
|
||||
@@ -491,8 +491,7 @@
|
||||
<module>zlt-monitor</module>
|
||||
<!-- 配置 -->
|
||||
<module>zlt-config</module>
|
||||
<!-- demo -->
|
||||
<!--<module>zlt-demo</module>-->
|
||||
|
||||
</modules>
|
||||
|
||||
<licenses>
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>central-platform</artifactId>
|
||||
<version>6.0.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>coupon-center</artifactId>
|
||||
<description>优惠券中心服务</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 公共实体类模块 -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-log-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-db-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-sentinel-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- swagger -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>search-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webflux</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>alibabacloud-ice20201109</artifactId>
|
||||
<version>5.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
|
||||
<imageTags>
|
||||
<imageTag>${project.version}</imageTag>
|
||||
<imageTag>latest</imageTag>
|
||||
</imageTags>
|
||||
<forceTags>true</forceTags>
|
||||
<baseImage>${docker.baseImage}</baseImage>
|
||||
<volumes>${docker.volumes}</volumes>
|
||||
<env>
|
||||
<JAVA_OPTS>${docker.java.opts}</JAVA_OPTS>
|
||||
</env>
|
||||
<entryPoint>["sh","-c","java $JAVA_OPTS ${docker.java.security.egd} -jar /${project.build.finalName}.jar"]</entryPoint>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>/</targetPath>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<include>${project.build.finalName}.jar</include>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
</project>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.central.coupon;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
* 优惠券中心启动类
|
||||
*
|
||||
* @author system
|
||||
* @date 2024-12-19
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@ComponentScan(basePackages = {"com.central.coupon"})
|
||||
public class CouponCenterApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CouponCenterApplication.class, args);
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
package com.central.coupon.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.coupon.entity.Coupon;
|
||||
import com.central.coupon.service.ICouponService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
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.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 优惠券管理控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/coupon")
|
||||
@Tag(name = "优惠券管理")
|
||||
public class CouponController {
|
||||
|
||||
@Autowired
|
||||
private ICouponService couponService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@Operation(summary = "查询列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping
|
||||
public PageResult<Coupon> list(@RequestParam Map<String, Object> params) {
|
||||
return couponService.findList(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询优惠券
|
||||
*/
|
||||
@Operation(summary = "根据ID查询优惠券")
|
||||
@GetMapping("/{id}")
|
||||
public Result<Coupon> getCouponById(@PathVariable Long id) {
|
||||
Coupon coupon = couponService.getById(id);
|
||||
return Result.succeed(coupon);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建优惠券
|
||||
*/
|
||||
@Operation(summary = "创建优惠券")
|
||||
@PostMapping
|
||||
public Result<Boolean> createCoupon(@RequestBody Coupon coupon) {
|
||||
boolean result = couponService.createCoupon(coupon);
|
||||
return Result.succeed(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新优惠券
|
||||
*/
|
||||
@Operation(summary = "更新优惠券")
|
||||
@PutMapping("/{id}")
|
||||
public Result<Boolean> updateCoupon(@PathVariable Long id, @RequestBody Coupon coupon) {
|
||||
coupon.setId(id);
|
||||
boolean result = couponService.updateCoupon(coupon);
|
||||
return Result.succeed(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
*/
|
||||
@Operation(summary = "删除优惠券")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Boolean> deleteCoupon(@PathVariable Long id) {
|
||||
boolean result = couponService.deleteCoupon(id);
|
||||
return Result.succeed(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机号查询用户优惠券
|
||||
*/
|
||||
@Operation(summary = "根据手机号查询用户优惠券")
|
||||
@GetMapping("/user/{userPhone}")
|
||||
public Result<List<Coupon>> getCouponsByUserPhone(@PathVariable String userPhone) {
|
||||
List<Coupon> coupons = couponService.getCouponsByUserPhone(userPhone);
|
||||
return Result.succeed(coupons);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机号查询可用优惠券
|
||||
*/
|
||||
@Operation(summary = "根据手机号查询可用优惠券")
|
||||
@GetMapping("/user/{userPhone}/available")
|
||||
public Result<List<Coupon>> getAvailableCouponsByUserPhone(@PathVariable String userPhone) {
|
||||
List<Coupon> coupons = couponService.getAvailableCouponsByUserPhone(userPhone);
|
||||
return Result.succeed(coupons);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用优惠券
|
||||
*/
|
||||
@Operation(summary = "使用优惠券")
|
||||
@PostMapping("/{id}/use")
|
||||
public Result<Boolean> useCoupon(@PathVariable Long id, @RequestParam String orderNo) {
|
||||
boolean result = couponService.useCoupon(id, orderNo);
|
||||
return Result.succeed(result);
|
||||
}
|
||||
|
||||
}
|
||||
+306
@@ -0,0 +1,306 @@
|
||||
package com.central.coupon.controller;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.coupon.entity.Coupon;
|
||||
import com.central.coupon.service.ICouponService;
|
||||
import com.central.coupon.util.CtripDecryptUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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 javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 携程优惠券控制器
|
||||
* 专门处理携程相关的优惠券接口
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/coupon/ctrip")
|
||||
@Tag(name = "携程优惠券管理")
|
||||
public class CtripCouponController {
|
||||
|
||||
@Autowired
|
||||
private ICouponService couponService;
|
||||
|
||||
/**
|
||||
* 携程创建优惠券接口
|
||||
* 携程下单后回调,创建用户优惠券(手机号+携程券ID唯一,幂等)
|
||||
*
|
||||
* 请求参数:
|
||||
* - ctripCouponId: 携程券ID(唯一)
|
||||
* - userPhone: 用户手机号
|
||||
* - couponName: 优惠券名称
|
||||
* - couponType: 优惠券类型
|
||||
* - amount: 优惠券面额
|
||||
* - minAmount: 使用门槛金额(可选)
|
||||
* - discountRate: 折扣率(可选)
|
||||
* - validStartTime: 有效期开始时间(yyyy-MM-dd或yyyy-MM-dd HH:mm:ss)
|
||||
* - validEndTime: 有效期结束时间(yyyy-MM-dd或yyyy-MM-dd HH:mm:ss)
|
||||
*/
|
||||
@Operation(summary = "携程创建优惠券接口")
|
||||
@PostMapping("/create")
|
||||
public Result<Boolean> createCouponFromCtrip(@RequestBody Map<String, Object> request,
|
||||
HttpServletRequest httpRequest) {
|
||||
log.info("收到携程创建优惠券请求,IP: {}", httpRequest.getRemoteAddr());
|
||||
|
||||
try {
|
||||
// 提取请求参数
|
||||
String ctripCouponId = (String) request.get("ctripCouponId");
|
||||
String userPhone = (String) request.get("userPhone");
|
||||
String couponName = (String) request.get("couponName");
|
||||
Integer couponType = (Integer) request.get("couponType");
|
||||
BigDecimal amount = null;
|
||||
if (request.get("amount") != null) {
|
||||
amount = new BigDecimal(request.get("amount").toString());
|
||||
}
|
||||
BigDecimal minAmount = null;
|
||||
if (request.get("minAmount") != null) {
|
||||
minAmount = new BigDecimal(request.get("minAmount").toString());
|
||||
}
|
||||
Integer discountRate = (Integer) request.get("discountRate");
|
||||
String validStartTimeStr = (String) request.get("validStartTime");
|
||||
String validEndTimeStr = (String) request.get("validEndTime");
|
||||
|
||||
// 参数验证
|
||||
if (ctripCouponId == null || userPhone == null || couponName == null ||
|
||||
couponType == null || amount == null || validStartTimeStr == null || validEndTimeStr == null) {
|
||||
log.error("参数不完整 - ctripCouponId: {}, userPhone: {}, couponName: {}, couponType: {}, amount: {}, validStartTime: {}, validEndTime: {}",
|
||||
ctripCouponId, userPhone, couponName, couponType, amount, validStartTimeStr, validEndTimeStr);
|
||||
return Result.failed("参数不完整");
|
||||
}
|
||||
|
||||
// 幂等校验
|
||||
if (couponService.existsByUserPhoneAndCtripCouponId(userPhone, ctripCouponId)) {
|
||||
log.info("携程优惠券已存在,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
return Result.succeed(true);
|
||||
}
|
||||
|
||||
// 时间解析
|
||||
Date validStartTime = parseDate(validStartTimeStr);
|
||||
Date validEndTime = parseDate(validEndTimeStr);
|
||||
|
||||
if (validStartTime == null || validEndTime == null) {
|
||||
log.error("时间格式错误 - validStartTime: {}, validEndTime: {}", validStartTimeStr, validEndTimeStr);
|
||||
return Result.failed("时间格式错误");
|
||||
}
|
||||
|
||||
// 创建优惠券
|
||||
boolean result = couponService.createCouponFromCtrip(ctripCouponId, userPhone, couponName,
|
||||
couponType, amount, minAmount, discountRate, validStartTime, validEndTime);
|
||||
|
||||
if (result) {
|
||||
log.info("携程优惠券创建成功 - ctripCouponId: {}, userPhone: {}", ctripCouponId, userPhone);
|
||||
return Result.succeed(true);
|
||||
} else {
|
||||
log.error("携程优惠券创建失败 - ctripCouponId: {}, userPhone: {}", ctripCouponId, userPhone);
|
||||
return Result.failed("创建失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程创建优惠券请求异常", e);
|
||||
return Result.failed("系统异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程取消优惠券接口
|
||||
* 携程退券回调,取消用户优惠券(默认退第一个未用券)
|
||||
*
|
||||
* 请求参数:
|
||||
* - userPhone: 用户手机号
|
||||
*/
|
||||
@Operation(summary = "携程取消优惠券接口")
|
||||
@PostMapping("/cancel")
|
||||
public Result<Boolean> cancelCouponFromCtrip(@RequestParam String userPhone,
|
||||
HttpServletRequest httpRequest) {
|
||||
log.info("收到携程取消优惠券请求,IP: {}, userPhone: {}", httpRequest.getRemoteAddr(), userPhone);
|
||||
|
||||
try {
|
||||
// 参数验证
|
||||
if (userPhone == null || userPhone.trim().isEmpty()) {
|
||||
log.error("用户手机号不能为空");
|
||||
return Result.failed("用户手机号不能为空");
|
||||
}
|
||||
|
||||
// 查询用户可用优惠券
|
||||
List<Coupon> availableCoupons = couponService.getAvailableCouponsByUserPhone(userPhone);
|
||||
|
||||
if (availableCoupons.isEmpty()) {
|
||||
log.warn("用户无可用优惠券,userPhone: {}", userPhone);
|
||||
return Result.failed("无可退优惠券");
|
||||
}
|
||||
|
||||
// 选择第一个可用优惠券进行取消
|
||||
Coupon coupon = availableCoupons.get(0);
|
||||
coupon.setStatus(3); // 已作废
|
||||
coupon.setCancelTime(new Date());
|
||||
coupon.setUpdateTime(new Date());
|
||||
coupon.setUpdateBy("ctrip");
|
||||
|
||||
boolean result = couponService.updateCoupon(coupon);
|
||||
|
||||
if (result) {
|
||||
log.info("携程优惠券取消成功 - couponId: {}, userPhone: {}", coupon.getId(), userPhone);
|
||||
return Result.succeed(true);
|
||||
} else {
|
||||
log.error("携程优惠券取消失败 - couponId: {}, userPhone: {}", coupon.getId(), userPhone);
|
||||
return Result.failed("取消失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程取消优惠券请求异常", e);
|
||||
return Result.failed("系统异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 核销携程优惠券接口
|
||||
* 用户下单时,先查本地券,再调用携程核销接口,核销成功后本地状态设为已用
|
||||
*
|
||||
* 请求参数:
|
||||
* - userPhone: 用户手机号
|
||||
* - orderNo: 订单号
|
||||
*/
|
||||
@Operation(summary = "核销携程优惠券")
|
||||
@PostMapping("/verify")
|
||||
public Result<Boolean> verifyCtripCoupon(@RequestParam String userPhone,
|
||||
@RequestParam String orderNo,
|
||||
HttpServletRequest httpRequest) {
|
||||
log.info("收到核销携程优惠券请求,IP: {}, userPhone: {}, orderNo: {}",
|
||||
httpRequest.getRemoteAddr(), userPhone, orderNo);
|
||||
|
||||
try {
|
||||
// 参数验证
|
||||
if (userPhone == null || userPhone.trim().isEmpty()) {
|
||||
log.error("用户手机号不能为空");
|
||||
return Result.failed("用户手机号不能为空");
|
||||
}
|
||||
if (orderNo == null || orderNo.trim().isEmpty()) {
|
||||
log.error("订单号不能为空");
|
||||
return Result.failed("订单号不能为空");
|
||||
}
|
||||
|
||||
// 查询用户可用优惠券
|
||||
List<Coupon> availableCoupons = couponService.getAvailableCouponsByUserPhone(userPhone);
|
||||
if (availableCoupons.isEmpty()) {
|
||||
log.warn("用户无可用优惠券,userPhone: {}", userPhone);
|
||||
return Result.failed("无可用优惠券");
|
||||
}
|
||||
|
||||
// 选择第一个可用优惠券进行核销
|
||||
Coupon coupon = availableCoupons.get(0);
|
||||
log.info("选择优惠券进行核销 - couponId: {}, ctripCouponId: {}, amount: {}",
|
||||
coupon.getId(), coupon.getCtripCouponId(), coupon.getAmount());
|
||||
|
||||
// 调用携程核销接口
|
||||
boolean result = couponService.verifyCtripCoupon(coupon.getCtripCouponId(), orderNo);
|
||||
if (result) {
|
||||
log.info("携程核销成功,更新本地优惠券状态 - couponId: {}, orderNo: {}", coupon.getId(), orderNo);
|
||||
coupon.setStatus(1); // 已用
|
||||
coupon.setUsedTime(new Date());
|
||||
coupon.setUsedOrderNo(orderNo);
|
||||
couponService.updateCoupon(coupon);
|
||||
return Result.succeed(true);
|
||||
} else {
|
||||
log.error("携程核销失败,couponId: {}, orderNo: {}", coupon.getId(), orderNo);
|
||||
return Result.failed("携程核销失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("核销携程优惠券失败", e);
|
||||
return Result.failed("核销失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询携程优惠券状态
|
||||
*
|
||||
* 路径参数:
|
||||
* - ctripCouponId: 携程优惠券ID
|
||||
*/
|
||||
@Operation(summary = "查询携程优惠券状态")
|
||||
@GetMapping("/status/{ctripCouponId}")
|
||||
public Result<Map<String, Object>> getCtripCouponStatus(@PathVariable String ctripCouponId) {
|
||||
log.info("查询携程优惠券状态,ctripCouponId: {}", ctripCouponId);
|
||||
|
||||
try {
|
||||
if (ctripCouponId == null || ctripCouponId.trim().isEmpty()) {
|
||||
log.error("携程优惠券ID不能为空");
|
||||
return Result.failed("携程优惠券ID不能为空");
|
||||
}
|
||||
|
||||
Coupon coupon = couponService.getByCtripCouponId(ctripCouponId);
|
||||
if (coupon == null) {
|
||||
log.warn("优惠券不存在,ctripCouponId: {}", ctripCouponId);
|
||||
return Result.failed("优惠券不存在");
|
||||
}
|
||||
|
||||
Map<String, Object> status = Map.of(
|
||||
"ctripCouponId", coupon.getCtripCouponId(),
|
||||
"status", coupon.getStatus(),
|
||||
"statusText", getStatusText(coupon.getStatus()),
|
||||
"userPhone", coupon.getUserPhone(),
|
||||
"amount", coupon.getAmount(),
|
||||
"validStartTime", coupon.getValidStartTime(),
|
||||
"validEndTime", coupon.getValidEndTime(),
|
||||
"usedTime", coupon.getUsedTime(),
|
||||
"usedOrderNo", coupon.getUsedOrderNo()
|
||||
);
|
||||
|
||||
return Result.succeed(status);
|
||||
} catch (Exception e) {
|
||||
log.error("查询携程优惠券状态失败", e);
|
||||
return Result.failed("查询失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析日期字符串
|
||||
* 支持 yyyy-MM-dd 或 yyyy-MM-dd HH:mm:ss 格式
|
||||
*/
|
||||
private Date parseDate(String dateStr) {
|
||||
try {
|
||||
if (dateStr == null || dateStr.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (dateStr.length() == 10) {
|
||||
// yyyy-MM-dd 格式
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return sdf.parse(dateStr);
|
||||
} else if (dateStr.length() == 19) {
|
||||
// yyyy-MM-dd HH:mm:ss 格式
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return sdf.parse(dateStr);
|
||||
} else {
|
||||
log.error("不支持的日期格式: {}", dateStr);
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("日期解析失败: {}", dateStr, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
private String getStatusText(Integer status) {
|
||||
switch (status) {
|
||||
case 0: return "未使用";
|
||||
case 1: return "已使用";
|
||||
case 2: return "已过期";
|
||||
case 3: return "已作废";
|
||||
default: return "未知状态";
|
||||
}
|
||||
}
|
||||
}
|
||||
+1052
File diff suppressed because it is too large
Load Diff
+6
-6
@@ -1,4 +1,4 @@
|
||||
package com.central.order.entity;
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
@@ -121,11 +121,6 @@ public class Coupon implements Serializable {
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@@ -140,4 +135,9 @@ public class Coupon implements Serializable {
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 携程核销实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_ctrip_consumed")
|
||||
public class CtripConsumed {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 携程订单号
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 供应商订单号
|
||||
*/
|
||||
private String supplierOrderId;
|
||||
|
||||
/**
|
||||
* 供应商处理批次流水号
|
||||
*/
|
||||
private String sequenceId;
|
||||
|
||||
/**
|
||||
* 订单项编号
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 使用开始日期
|
||||
*/
|
||||
private String useStartDate;
|
||||
|
||||
/**
|
||||
* 使用结束日期
|
||||
*/
|
||||
private String useEndDate;
|
||||
|
||||
/**
|
||||
* 总数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 已使用数量
|
||||
*/
|
||||
private Integer useQuantity;
|
||||
|
||||
/**
|
||||
* 丢失金额
|
||||
*/
|
||||
private BigDecimal lostAmount;
|
||||
|
||||
/**
|
||||
* 丢失金额货币
|
||||
*/
|
||||
private String lostAmountCurrency;
|
||||
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 核销状态:0-待核销,1-已核销,2-部分核销,3-核销失败
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remarkDetail;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 携程核销乘客信息实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_ctrip_consumed_passenger")
|
||||
public class CtripConsumedPassenger {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 核销ID
|
||||
*/
|
||||
private Long consumedId;
|
||||
|
||||
/**
|
||||
* 乘客ID
|
||||
*/
|
||||
private String passengerId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 携程核销凭证信息实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_ctrip_consumed_voucher")
|
||||
public class CtripConsumedVoucher {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 核销ID
|
||||
*/
|
||||
private Long consumedId;
|
||||
|
||||
/**
|
||||
* 凭证ID
|
||||
*/
|
||||
private String voucherId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 携程订单实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_ctrip_order")
|
||||
public class CtripOrder {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 携程订单号
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 供应商订单号
|
||||
*/
|
||||
private String supplierOrderId;
|
||||
|
||||
/**
|
||||
* 携程批次流水号
|
||||
*/
|
||||
private String sequenceId;
|
||||
|
||||
/**
|
||||
* 确认类型:1-仅通知,2-需确认
|
||||
*/
|
||||
private Integer confirmType;
|
||||
|
||||
/**
|
||||
* 最晚确认时间
|
||||
*/
|
||||
private LocalDateTime orderLastConfirmTime;
|
||||
|
||||
/**
|
||||
* 订单状态:0-待确认,1-已确认,2-已取消,3-已过期
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 携程订单项实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_ctrip_order_item")
|
||||
public class CtripOrderItem {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 订单项编号
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 产品编码
|
||||
*/
|
||||
private String plu;
|
||||
|
||||
/**
|
||||
* 使用开始日期
|
||||
*/
|
||||
private LocalDate useStartDate;
|
||||
|
||||
/**
|
||||
* 使用结束日期
|
||||
*/
|
||||
private LocalDate useEndDate;
|
||||
|
||||
/**
|
||||
* 原价
|
||||
*/
|
||||
private BigDecimal price;
|
||||
|
||||
/**
|
||||
* 销售价格
|
||||
*/
|
||||
private BigDecimal salePrice;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 携程乘客信息实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_ctrip_passenger")
|
||||
public class CtripPassenger {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单项ID
|
||||
*/
|
||||
private Long orderItemId;
|
||||
|
||||
/**
|
||||
* 乘客ID
|
||||
*/
|
||||
private String passengerId;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String mobile;
|
||||
|
||||
/**
|
||||
* 证件类型
|
||||
*/
|
||||
private String cardType;
|
||||
|
||||
/**
|
||||
* 证件号码
|
||||
*/
|
||||
private String cardNo;
|
||||
|
||||
/**
|
||||
* 年龄类型:ADU-成人,CHD-儿童,INF-婴儿
|
||||
*/
|
||||
private String ageType;
|
||||
|
||||
/**
|
||||
* 性别:M-男,F-女
|
||||
*/
|
||||
private String gender;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 携程退款实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_ctrip_refund")
|
||||
public class CtripRefund {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 携程订单号
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 供应商订单号
|
||||
*/
|
||||
private String supplierOrderId;
|
||||
|
||||
/**
|
||||
* 携程批次流水号
|
||||
*/
|
||||
private String sequenceId;
|
||||
|
||||
/**
|
||||
* 退款总金额
|
||||
*/
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 退款总金额货币
|
||||
*/
|
||||
private String totalAmountCurrency;
|
||||
|
||||
/**
|
||||
* 最晚确认时间
|
||||
*/
|
||||
private LocalDateTime lastConfirmTime;
|
||||
|
||||
/**
|
||||
* 退款状态:0-待确认,1-已确认,2-已拒绝,3-已过期
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 确认结果码
|
||||
*/
|
||||
private String confirmResultCode;
|
||||
|
||||
/**
|
||||
* 确认结果信息
|
||||
*/
|
||||
private String confirmResultMessage;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package com.central.coupon.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 携程退款项实体类
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_ctrip_refund_item")
|
||||
public class CtripRefundItem {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 退款ID
|
||||
*/
|
||||
private Long refundId;
|
||||
|
||||
/**
|
||||
* 订单项编号
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 供应商产品最小单位
|
||||
*/
|
||||
private String plu;
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 退款金额货币
|
||||
*/
|
||||
private String amountCurrency;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.central.order.mapper;
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.order.entity.Coupon;
|
||||
import com.central.coupon.entity.Coupon;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.coupon.entity.CtripConsumed;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程核销Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CtripConsumedMapper extends BaseMapper<CtripConsumed> {
|
||||
|
||||
/**
|
||||
* 根据携程订单号查询核销信息
|
||||
*
|
||||
* @param otaOrderId 携程订单号
|
||||
* @return 核销信息列表
|
||||
*/
|
||||
List<CtripConsumed> selectByOtaOrderId(@Param("otaOrderId") String otaOrderId);
|
||||
|
||||
/**
|
||||
* 根据供应商订单号查询核销信息
|
||||
*
|
||||
* @param supplierOrderId 供应商订单号
|
||||
* @return 核销信息列表
|
||||
*/
|
||||
List<CtripConsumed> selectBySupplierOrderId(@Param("supplierOrderId") String supplierOrderId);
|
||||
|
||||
/**
|
||||
* 根据供应商批次流水号查询核销信息
|
||||
*
|
||||
* @param sequenceId 供应商批次流水号
|
||||
* @return 核销信息
|
||||
*/
|
||||
CtripConsumed selectBySequenceId(@Param("sequenceId") String sequenceId);
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.coupon.entity.CtripConsumedPassenger;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程核销乘客信息Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CtripConsumedPassengerMapper extends BaseMapper<CtripConsumedPassenger> {
|
||||
|
||||
/**
|
||||
* 根据核销ID查询乘客列表
|
||||
*
|
||||
* @param consumedId 核销ID
|
||||
* @return 乘客列表
|
||||
*/
|
||||
List<CtripConsumedPassenger> selectByConsumedId(@Param("consumedId") Long consumedId);
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.coupon.entity.CtripConsumedVoucher;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程核销凭证信息Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CtripConsumedVoucherMapper extends BaseMapper<CtripConsumedVoucher> {
|
||||
|
||||
/**
|
||||
* 根据核销ID查询凭证列表
|
||||
*
|
||||
* @param consumedId 核销ID
|
||||
* @return 凭证列表
|
||||
*/
|
||||
List<CtripConsumedVoucher> selectByConsumedId(@Param("consumedId") Long consumedId);
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.order.entity.CtripOrderItem;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单项Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CtripOrderItemMapper extends BaseMapper<CtripOrderItem> {
|
||||
|
||||
/**
|
||||
* 根据订单ID查询订单项列表
|
||||
*
|
||||
* @param orderId 订单ID
|
||||
* @return 订单项列表
|
||||
*/
|
||||
List<CtripOrderItem> selectByOrderId(@Param("orderId") Long orderId);
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.order.entity.CtripOrder;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 携程订单Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CtripOrderMapper extends BaseMapper<CtripOrder> {
|
||||
|
||||
/**
|
||||
* 根据携程订单号查询订单
|
||||
*
|
||||
* @param otaOrderId 携程订单号
|
||||
* @return 订单信息
|
||||
*/
|
||||
CtripOrder selectByOtaOrderId(@Param("otaOrderId") String otaOrderId);
|
||||
|
||||
/**
|
||||
* 根据供应商订单号查询订单
|
||||
*
|
||||
* @param supplierOrderId 供应商订单号
|
||||
* @return 订单信息
|
||||
*/
|
||||
CtripOrder selectBySupplierOrderId(@Param("supplierOrderId") String supplierOrderId);
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.order.entity.CtripPassenger;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程乘客信息Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CtripPassengerMapper extends BaseMapper<CtripPassenger> {
|
||||
|
||||
/**
|
||||
* 根据订单项ID查询乘客列表
|
||||
*
|
||||
* @param orderItemId 订单项ID
|
||||
* @return 乘客列表
|
||||
*/
|
||||
List<CtripPassenger> selectByOrderItemId(@Param("orderItemId") Long orderItemId);
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.coupon.entity.CtripRefundItem;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程退款项Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CtripRefundItemMapper extends BaseMapper<CtripRefundItem> {
|
||||
|
||||
/**
|
||||
* 根据退款ID查询退款项列表
|
||||
*
|
||||
* @param refundId 退款ID
|
||||
* @return 退款项列表
|
||||
*/
|
||||
List<CtripRefundItem> selectByRefundId(@Param("refundId") Long refundId);
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.central.coupon.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.coupon.entity.CtripRefund;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 携程退款Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CtripRefundMapper extends BaseMapper<CtripRefund> {
|
||||
|
||||
/**
|
||||
* 根据携程订单号查询退款信息
|
||||
*
|
||||
* @param otaOrderId 携程订单号
|
||||
* @return 退款信息
|
||||
*/
|
||||
CtripRefund selectByOtaOrderId(@Param("otaOrderId") String otaOrderId);
|
||||
|
||||
/**
|
||||
* 根据供应商订单号查询退款信息
|
||||
*
|
||||
* @param supplierOrderId 供应商订单号
|
||||
* @return 退款信息
|
||||
*/
|
||||
CtripRefund selectBySupplierOrderId(@Param("supplierOrderId") String supplierOrderId);
|
||||
|
||||
/**
|
||||
* 根据携程批次流水号查询退款信息
|
||||
*
|
||||
* @param sequenceId 携程批次流水号
|
||||
* @return 退款信息
|
||||
*/
|
||||
CtripRefund selectBySequenceId(@Param("sequenceId") String sequenceId);
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单取消确认请求
|
||||
* 当订单在取消提交后供应商需异步确认进行操作(接受、拒绝)
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCancelOrderConfirmRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripHeader header;
|
||||
|
||||
/**
|
||||
* 请求体 - 可能是加密字符串或JSON对象
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private Object body;
|
||||
|
||||
/**
|
||||
* 携程请求头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripHeader {
|
||||
@JsonProperty("accountId")
|
||||
private String accountId; // 供应商帐号,由携程分配
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName; // 接口名称: CancelOrderConfirm
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime; // 请求时间(格式: yyyy-MM-dd HH:mm:ss)
|
||||
@JsonProperty("version")
|
||||
private String version; // 版本号, 1.0
|
||||
@JsonProperty("sign")
|
||||
private String sign; // 签名
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单取消确认体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripCancelOrderConfirmBody {
|
||||
@JsonProperty("sequenceId")
|
||||
private String sequenceId; // 供应商处理批次流水号
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId; // 携程订单号
|
||||
@JsonProperty("supplierOrderId")
|
||||
private String supplierOrderId; // 供应商订单号
|
||||
@JsonProperty("confirmResultCode")
|
||||
private String confirmResultCode; // 确认结果返回码
|
||||
@JsonProperty("confirmResultMessage")
|
||||
private String confirmResultMessage; // 确认结果信息
|
||||
@JsonProperty("items")
|
||||
private List<CtripCancelOrderConfirmItem> items; // 订单项节点
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单取消确认项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripCancelOrderConfirmItem {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId; // 订单项编号
|
||||
@JsonProperty("vouchers")
|
||||
private List<CtripVoucher> vouchers; // 已取消的凭证
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程凭证
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripVoucher {
|
||||
@JsonProperty("voucherId")
|
||||
private String voucherId; // 凭证编号
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 携程订单取消确认响应
|
||||
* 不接受同批次的取消推送多次不同操作(接受、拒绝)结果给到携程
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCancelOrderConfirmResponse {
|
||||
|
||||
/**
|
||||
* 返回头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripResponseHeader header;
|
||||
|
||||
/**
|
||||
* 处理结果返回码
|
||||
*/
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 处理结果返回信息
|
||||
*/
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 携程返回头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseHeader {
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode; // 处理结果返回码
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage; // 处理结果返回信息
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单取消请求
|
||||
* 提供携程与供应商系统进行订单取消操作的接口
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCancelOrderRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripHeader header;
|
||||
|
||||
/**
|
||||
* 请求体 - 可能是加密字符串或JSON对象
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private Object body;
|
||||
|
||||
/**
|
||||
* 携程请求头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripHeader {
|
||||
@JsonProperty("accountId")
|
||||
private String accountId; // 供应商帐号,由携程分配
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName; // 接口名称: CancelOrder
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime; // 请求时间(格式: yyyy-MM-dd HH:mm:ss)
|
||||
@JsonProperty("version")
|
||||
private String version; // 版本号, 1.0
|
||||
@JsonProperty("sign")
|
||||
private String sign; // 签名
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单取消体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripCancelOrderBody {
|
||||
@JsonProperty("sequenceId")
|
||||
private String sequenceId; // 携程处理批次流水号
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId; // 携程订单号
|
||||
@JsonProperty("supplierOrderId")
|
||||
private String supplierOrderId; // 供应商订单号
|
||||
@JsonProperty("confirmType")
|
||||
private Integer confirmType; // 确认类型:1-仅通知,2-供应商确认
|
||||
@JsonProperty("items")
|
||||
private List<CtripCancelOrderItem> items; // 订单项节点
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单取消项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripCancelOrderItem {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId; // 订单项编号
|
||||
@JsonProperty("PLU")
|
||||
private String PLU; // 供应商产品最小单位
|
||||
@JsonProperty("lastConfirmTime")
|
||||
private String lastConfirmTime; // 供应商最晚确认时间
|
||||
@JsonProperty("cancelType")
|
||||
private Integer cancelType; // 退订类型:0-全退,1-按份数部分退,2-按出行人部分退
|
||||
@JsonProperty("quantity")
|
||||
private Integer quantity; // 本次请求取消份数
|
||||
@JsonProperty("passengers")
|
||||
private List<CtripCancelPassenger> passengers; // 退订出行人节点
|
||||
@JsonProperty("amount")
|
||||
private BigDecimal amount; // 被取消的退款金额
|
||||
@JsonProperty("amountCurrency")
|
||||
private String amountCurrency; // 被取消的退款金额单位
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程取消出行人信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripCancelPassenger {
|
||||
@JsonProperty("passengerId")
|
||||
private String passengerId; // 出行人编号
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单取消响应
|
||||
* 当confirmType=2在取消发起时必须验证取消数量等于可退数量
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCancelOrderResponse {
|
||||
|
||||
/**
|
||||
* 返回头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripResponseHeader header;
|
||||
|
||||
/**
|
||||
* 处理结果返回码
|
||||
*/
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 处理结果返回信息
|
||||
*/
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 返回体(传输时该字段需要AES加密)
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private CtripResponseBody body;
|
||||
|
||||
/**
|
||||
* 携程返回头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseHeader {
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode; // 处理结果返回码
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage; // 处理结果返回信息
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseBody {
|
||||
@JsonProperty("supplierConfirmType")
|
||||
private Integer supplierConfirmType; // 供应商确认类型:1-取消已确认,2-取消待确认
|
||||
@JsonProperty("items")
|
||||
private List<CtripResponseOrderItem> items; // 订单项节点
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回订单项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseOrderItem {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId; // 订单项编号
|
||||
@JsonProperty("vouchers")
|
||||
private List<CtripVoucher> vouchers; // 已取消的凭证
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程凭证
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripVoucher {
|
||||
@JsonProperty("voucherId")
|
||||
private String voucherId; // 凭证编号
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
+1
@@ -0,0 +1 @@
|
||||
|
||||
+270
@@ -0,0 +1,270 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单新订请求
|
||||
* 当客人在携程平台进行订单预定后,携程会通过该接口向供应商系统提交客人的预定信息来完成订单预定
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCreateOrderRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripHeader header;
|
||||
|
||||
/**
|
||||
* 请求体 - 可能是加密字符串或JSON对象
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private Object body; // 改为Object类型,支持字符串和对象两种格式
|
||||
|
||||
/**
|
||||
* 携程请求头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripHeader {
|
||||
@JsonProperty("accountId")
|
||||
private String accountId; // 供应商帐号,由携程分配
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName; // 接口名称: CreateOrder
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime; // 请求时间(格式: yyyy-MM-dd HH:mm:ss)
|
||||
@JsonProperty("version")
|
||||
private String version; // 版本号, 1.0
|
||||
@JsonProperty("sign")
|
||||
private String sign; // 签名
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripOrderBody {
|
||||
@JsonProperty("sequenceId")
|
||||
private String sequenceId; // 携程处理批次流水号。格式为处理日期(yyyyMMdd)+32位去分隔符的Guid
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId; // 携程订单号
|
||||
@JsonProperty("confirmType")
|
||||
private Integer confirmType; // 确认类型:1-仅通知供应商订单操作,2-供应商系统确认
|
||||
@JsonProperty("orderLastConfirmTime")
|
||||
private String orderLastConfirmTime; // 供应商最晚确认时间,格式:yyyy-MM-dd hh:mm:ss
|
||||
@JsonProperty("contacts")
|
||||
private List<CtripContact> contacts; // 联系人节点,为此笔订单联系人,并非实际出行人
|
||||
@JsonProperty("coupons")
|
||||
private List<CtripCoupon> coupons; // 优惠信息节点
|
||||
@JsonProperty("items")
|
||||
private List<CtripOrderItem> items; // 订单项节点
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripOrderItem {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId; // 订单项编号
|
||||
@JsonProperty("openId")
|
||||
private String openId; // 用户对外标识
|
||||
@JsonProperty("PLU")
|
||||
private String PLU; // 供应商产品最小单位
|
||||
@JsonProperty("locale")
|
||||
private String locale; // 语言-地区
|
||||
@JsonProperty("distributionChannel")
|
||||
private String distributionChannel; // 销售渠道
|
||||
@JsonProperty("useStartDate")
|
||||
private String useStartDate; // 使用日期
|
||||
@JsonProperty("useEndDate")
|
||||
private String useEndDate; // 最晚可使用日期
|
||||
@JsonProperty("lastConfirmTime")
|
||||
private String lastConfirmTime; // 供应商最晚确认时间(已废弃)
|
||||
@JsonProperty("remark")
|
||||
private String remark; // 备注信息
|
||||
@JsonProperty("price")
|
||||
private BigDecimal price; // 单位客人实付金额
|
||||
@JsonProperty("priceCurrency")
|
||||
private String priceCurrency; // 客人实付金额币种
|
||||
@JsonProperty("salePrice")
|
||||
private BigDecimal salePrice; // 单价卖价
|
||||
@JsonProperty("salePriceCurrency")
|
||||
private String salePriceCurrency; // 单位卖价币种
|
||||
@JsonProperty("cost")
|
||||
private BigDecimal cost; // 单价结算价
|
||||
@JsonProperty("costCurrency")
|
||||
private String costCurrency; // 单价结算价单位
|
||||
@JsonProperty("suggestedPrice")
|
||||
private BigDecimal suggestedPrice; // 供应商建议携程卖价
|
||||
@JsonProperty("suggestedPriceCurrency")
|
||||
private String suggestedPriceCurrency; // 供应商建议携程卖价单位
|
||||
@JsonProperty("quantity")
|
||||
private Integer quantity; // 订单数量
|
||||
@JsonProperty("passengers")
|
||||
private List<CtripPassenger> passengers; // 乘客信息
|
||||
@JsonProperty("adjunctions")
|
||||
private List<CtripAdjunction> adjunctions; // 附加信息
|
||||
@JsonProperty("deposit")
|
||||
private CtripDeposit deposit; // 押金信息
|
||||
@JsonProperty("expressDelivery")
|
||||
private CtripExpressDelivery expressDelivery; // 快递信息
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程乘客信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripPassenger {
|
||||
@JsonProperty("passengerId")
|
||||
private String passengerId; // 出行人编号
|
||||
@JsonProperty("name")
|
||||
private String name; // 姓名
|
||||
@JsonProperty("firstName")
|
||||
private String firstName; // 拼音或英文名
|
||||
@JsonProperty("lastName")
|
||||
private String lastName; // 拼音或英文姓
|
||||
@JsonProperty("mobile")
|
||||
private String mobile; // 手机号码/国际电话号码
|
||||
@JsonProperty("intlCode")
|
||||
private String intlCode; // 国际标准电话区号
|
||||
@JsonProperty("cardType")
|
||||
private String cardType; // 证件类型
|
||||
@JsonProperty("cardNo")
|
||||
private String cardNo; // 证件号
|
||||
@JsonProperty("birthDate")
|
||||
private String birthDate; // 生日
|
||||
@JsonProperty("ageType")
|
||||
private String ageType; // 年龄类型:ADU-成人,CHI-儿童,BAB-婴儿
|
||||
@JsonProperty("gender")
|
||||
private String gender; // 性别:M-男,F-女
|
||||
@JsonProperty("nationalityCode")
|
||||
private String nationalityCode; // 国籍代码
|
||||
@JsonProperty("nationalityName")
|
||||
private String nationalityName; // 国籍名称
|
||||
@JsonProperty("cardIssueCountry")
|
||||
private String cardIssueCountry; // 证件签发国
|
||||
@JsonProperty("cardIssuePlace")
|
||||
private String cardIssuePlace; // 证件签发地
|
||||
@JsonProperty("cardIssueDate")
|
||||
private String cardIssueDate; // 证件签发日期
|
||||
@JsonProperty("cardValidDate")
|
||||
private String cardValidDate; // 证件有效期
|
||||
@JsonProperty("cardIssueNumber")
|
||||
private Integer cardIssueNumber; // 证件签发次数
|
||||
@JsonProperty("birthPlace")
|
||||
private String birthPlace; // 出生地
|
||||
@JsonProperty("height")
|
||||
private Integer height; // 身高
|
||||
@JsonProperty("weight")
|
||||
private Integer weight; // 体重
|
||||
@JsonProperty("myopiaDegreeL")
|
||||
private Integer myopiaDegreeL; // 左眼近视度数
|
||||
@JsonProperty("myopiaDegreeR")
|
||||
private Integer myopiaDegreeR; // 右眼近视度数
|
||||
@JsonProperty("shoeSize")
|
||||
private Integer shoeSize; // 鞋码
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程联系人信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripContact {
|
||||
@JsonProperty("name")
|
||||
private String name; // 姓名
|
||||
@JsonProperty("mobile")
|
||||
private String mobile; // 手机号码/国际电话号码
|
||||
@JsonProperty("intlCode")
|
||||
private String intlCode; // 国际标准电话区号
|
||||
@JsonProperty("optionalMobile")
|
||||
private String optionalMobile; // 备选的手机号码/国际电话号码
|
||||
@JsonProperty("optionalIntlCode")
|
||||
private String optionalIntlCode; // 备选的国际标准电话区号
|
||||
@JsonProperty("email")
|
||||
private String email; // 邮箱地址
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程优惠券信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripCoupon {
|
||||
@JsonProperty("type")
|
||||
private Integer type; // 优惠券源类型:1-携程,2-供应商
|
||||
@JsonProperty("code")
|
||||
private String code; // 优惠券编码
|
||||
@JsonProperty("name")
|
||||
private String name; // 优惠券名称
|
||||
@JsonProperty("amount")
|
||||
private BigDecimal amount; // 优惠券金额
|
||||
@JsonProperty("amountCurrency")
|
||||
private String amountCurrency; // 优惠券金额单位
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程附加信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripAdjunction {
|
||||
@JsonProperty("name")
|
||||
private String name; // 名称
|
||||
@JsonProperty("nameCode")
|
||||
private String nameCode; // 名称编码(系统标识)
|
||||
@JsonProperty("content")
|
||||
private String content; // 内容
|
||||
@JsonProperty("contentCode")
|
||||
private String contentCode; // 内容编码(系统标识)
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程押金信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripDeposit {
|
||||
@JsonProperty("type")
|
||||
private Integer type; // 押金/保证金类型:1-网站预付,2-景区现付
|
||||
@JsonProperty("amount")
|
||||
private BigDecimal amount; // 押金/保证金金额
|
||||
@JsonProperty("amountCurrency")
|
||||
private String amountCurrency; // 押金/保证金单位
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程快递信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripExpressDelivery {
|
||||
@JsonProperty("type")
|
||||
private String type; // 配送类型:1-客人自提,2-供应商配送
|
||||
@JsonProperty("name")
|
||||
private String name; // 中文或英文姓名
|
||||
@JsonProperty("mobile")
|
||||
private String mobile; // 手机号码/国际电话号码
|
||||
@JsonProperty("intlCode")
|
||||
private String intlCode; // 国际标准电话区号
|
||||
@JsonProperty("country")
|
||||
private String country; // 国家
|
||||
@JsonProperty("province")
|
||||
private String province; // 省/直辖市
|
||||
@JsonProperty("city")
|
||||
private String city; // 市
|
||||
@JsonProperty("district")
|
||||
private String district; // 县/区
|
||||
@JsonProperty("address")
|
||||
private String address; // 详细地址
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单新订响应
|
||||
* 供应商在收到携程的下单请求时,需先判断同批次的携程订单号在供应商系统中是否存在且已下单成功
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCreateOrderResponse {
|
||||
|
||||
/**
|
||||
* 返回头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripResponseHeader header;
|
||||
|
||||
/**
|
||||
* 处理结果返回码
|
||||
*/
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 处理结果返回信息。若返回结果为失败,需在此字段内明确描述失败原因
|
||||
*/
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 返回体(传输时该字段需要AES加密)
|
||||
* 该节点在返回码为0000时必填,其他均为非必填
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private CtripResponseBody body;
|
||||
|
||||
/**
|
||||
* 携程返回头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseHeader {
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode; // 处理结果返回码
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage; // 处理结果返回信息
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseBody {
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId; // 携程订单号
|
||||
@JsonProperty("supplierOrderId")
|
||||
private String supplierOrderId; // 供应商订单号
|
||||
@JsonProperty("supplierConfirmType")
|
||||
private Integer supplierConfirmType; // 供应商确认类型:1-新订已确认,2-新订待确认
|
||||
@JsonProperty("voucherSender")
|
||||
private Integer voucherSender; // 凭证发送方:1-携程对客发送凭证,2-供应商对客发送凭证
|
||||
@JsonProperty("vouchers")
|
||||
private List<CtripVoucher> vouchers; // 凭证集合节点
|
||||
@JsonProperty("orderExtendMessage")
|
||||
private String orderExtendMessage; // 订单附加信息
|
||||
@JsonProperty("items")
|
||||
private List<CtripResponseOrderItem> items; // 订单项节点
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程凭证
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripVoucher {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId; // 订单项编号,如果按资源单位来匹配凭证则必返回值
|
||||
@JsonProperty("voucherId")
|
||||
private String voucherId; // 凭证编号,isCredentialVouchers=1必填,需保证订单内唯一
|
||||
@JsonProperty("voucherType")
|
||||
private Integer voucherType; // 凭证形式:1-普通凭证,2-数字码,3-二维码图片,4-凭证图片,5-PDF确认单,6-凭证链接,7-条形码128格式,8-条形码417格式
|
||||
@JsonProperty("voucherCode")
|
||||
private String voucherCode; // 凭证数字码,当voucherType=2时必返回值
|
||||
@JsonProperty("voucherData")
|
||||
private String voucherData; // 凭证数据源
|
||||
@JsonProperty("voucherSeatInfo")
|
||||
private String voucherSeatInfo; // 凭证座位信息
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回订单项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseOrderItem {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId; // 订单项编号
|
||||
@JsonProperty("isCredentialVouchers")
|
||||
private Integer isCredentialVouchers; // 是否出行人与凭证有关联关系:0-不相关,1-相关
|
||||
@JsonProperty("passengerVouchers")
|
||||
private List<CtripPassengerVoucher> passengerVouchers; // 出行人凭证关系节点
|
||||
@JsonProperty("inventorys")
|
||||
private List<CtripInventory> inventorys; // 剩余库存数量节点
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程出行人凭证关系
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripPassengerVoucher {
|
||||
@JsonProperty("passengerId")
|
||||
private String passengerId; // 出行人编号
|
||||
@JsonProperty("voucherId")
|
||||
private String voucherId; // 凭证编号
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程库存信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripInventory {
|
||||
@JsonProperty("useDate")
|
||||
private String useDate; // 使用日期
|
||||
@JsonProperty("quantity")
|
||||
private Integer quantity; // 库存数量
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 携程订单退款确认请求
|
||||
* 当订单在退款提交后供应商需异步确认进行操作(接受、拒绝)
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripRefundOrderConfirmRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripHeader header;
|
||||
|
||||
/**
|
||||
* 请求体 - 可能是加密字符串或JSON对象
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private Object body;
|
||||
|
||||
/**
|
||||
* 携程请求头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripHeader {
|
||||
@JsonProperty("accountId")
|
||||
private String accountId; // 供应商帐号,由携程分配
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName; // 接口名称: RefundOrderConfirm
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime; // 请求时间(格式: yyyy-MM-dd HH:mm:ss)
|
||||
@JsonProperty("version")
|
||||
private String version; // 版本号, 1.0
|
||||
@JsonProperty("sign")
|
||||
private String sign; // 签名
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单退款确认体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripRefundOrderConfirmBody {
|
||||
@JsonProperty("sequenceId")
|
||||
private String sequenceId; // 供应商处理批次流水号
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId; // 携程订单号
|
||||
@JsonProperty("supplierOrderId")
|
||||
private String supplierOrderId; // 供应商订单号
|
||||
@JsonProperty("confirmResultCode")
|
||||
private String confirmResultCode; // 确认结果返回码
|
||||
@JsonProperty("confirmResultMessage")
|
||||
private String confirmResultMessage; // 确认结果信息
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 携程订单退款确认响应
|
||||
* 不接受同批次的退款推送多次不同操作(接受、拒绝)结果给到携程
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripRefundOrderConfirmResponse {
|
||||
|
||||
/**
|
||||
* 返回头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripResponseHeader header;
|
||||
|
||||
/**
|
||||
* 处理结果返回码
|
||||
*/
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 处理结果返回信息
|
||||
*/
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 携程返回头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseHeader {
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode; // 处理结果返回码
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage; // 处理结果返回信息
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单退款请求
|
||||
* 退款接口与订单取消逻辑并无关联,是纯粹的退钱操作
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripRefundOrderRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripHeader header;
|
||||
|
||||
/**
|
||||
* 请求体 - 可能是加密字符串或JSON对象
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private Object body;
|
||||
|
||||
/**
|
||||
* 携程请求头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripHeader {
|
||||
@JsonProperty("accountId")
|
||||
private String accountId; // 供应商帐号,由携程分配
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName; // 接口名称: RefundOrder
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime; // 请求时间(格式: yyyy-MM-dd HH:mm:ss)
|
||||
@JsonProperty("version")
|
||||
private String version; // 版本号, 1.0
|
||||
@JsonProperty("sign")
|
||||
private String sign; // 签名
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单退款体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripRefundOrderBody {
|
||||
@JsonProperty("sequenceId")
|
||||
private String sequenceId; // 携程处理批次流水号
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId; // 携程订单号
|
||||
@JsonProperty("supplierOrderId")
|
||||
private String supplierOrderId; // 供应商订单号
|
||||
@JsonProperty("lastConfirmTime")
|
||||
private String lastConfirmTime; // 供应商最晚确认时间
|
||||
@JsonProperty("totalAmount")
|
||||
private BigDecimal totalAmount; // 退款总金额
|
||||
@JsonProperty("totalAmountCurrency")
|
||||
private String totalAmountCurrency; // 退款总金额单位
|
||||
@JsonProperty("items")
|
||||
private List<CtripRefundOrderItem> items; // 订单项节点
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单退款项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripRefundOrderItem {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId; // 订单项编号
|
||||
@JsonProperty("PLU")
|
||||
private String PLU; // 供应商产品最小单位
|
||||
@JsonProperty("amount")
|
||||
private BigDecimal amount; // 退款金额
|
||||
@JsonProperty("amountCurrency")
|
||||
private String amountCurrency; // 退款金额单位
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 携程订单退款响应
|
||||
* 在退款发起时必须验证退款金额小于等于可退金额
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripRefundOrderResponse {
|
||||
|
||||
/**
|
||||
* 返回头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripResponseHeader header;
|
||||
|
||||
/**
|
||||
* 处理结果返回码
|
||||
*/
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 处理结果返回信息
|
||||
*/
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 返回体(传输时该字段需要AES加密)
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private CtripResponseBody body;
|
||||
|
||||
/**
|
||||
* 携程返回头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseHeader {
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode; // 处理结果返回码
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage; // 处理结果返回信息
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseBody {
|
||||
@JsonProperty("supplierConfirmType")
|
||||
private Integer supplierConfirmType; // 供应商确认类型:1-退款已确认,2-退款待确认
|
||||
}
|
||||
}
|
||||
+4
-9
@@ -1,9 +1,9 @@
|
||||
package com.central.order.service;
|
||||
package com.central.coupon.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.order.entity.Coupon;
|
||||
import com.central.coupon.entity.Coupon;
|
||||
import com.central.common.model.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
@@ -73,18 +73,13 @@ public interface ICouponService extends IService<Coupon> {
|
||||
*/
|
||||
boolean verifyCtripCoupon(String ctripCouponId, String orderNo);
|
||||
|
||||
/**
|
||||
* 校验手机号+携程券ID是否已存在
|
||||
*/
|
||||
boolean existsByUserPhoneAndCtripCouponId(String userPhone, String ctripCouponId);
|
||||
|
||||
/**
|
||||
* 根据携程优惠券ID查询优惠券
|
||||
*/
|
||||
Coupon getByCtripCouponId(String ctripCouponId);
|
||||
|
||||
/**
|
||||
* 更新优惠券为已核销状态
|
||||
* 检查用户手机号和携程优惠券ID是否已存在
|
||||
*/
|
||||
boolean updateCouponConsumed(Long couponId, String orderNo, String consumedTime);
|
||||
boolean existsByUserPhoneAndCtripCouponId(String userPhone, String ctripCouponId);
|
||||
}
|
||||
+7
-4
@@ -1,20 +1,23 @@
|
||||
package com.central.order.service;
|
||||
package com.central.coupon.service;
|
||||
|
||||
/**
|
||||
* 携程API服务接口
|
||||
* 用于调用携程的优惠券相关API
|
||||
*/
|
||||
public interface ICtripApiService {
|
||||
|
||||
/**
|
||||
* 核销携程优惠券
|
||||
* 验证携程优惠券
|
||||
*
|
||||
* @param ctripCouponId 携程优惠券ID
|
||||
* @param orderNo 订单号
|
||||
* @return 是否核销成功
|
||||
* @return 验证结果
|
||||
*/
|
||||
boolean verifyCoupon(String ctripCouponId, String orderNo);
|
||||
|
||||
/**
|
||||
* 查询携程优惠券状态
|
||||
* 获取携程优惠券状态
|
||||
*
|
||||
* @param ctripCouponId 携程优惠券ID
|
||||
* @return 优惠券状态
|
||||
*/
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
package com.central.coupon.service;
|
||||
|
||||
import com.central.coupon.model.CtripCreateOrderRequest;
|
||||
import com.central.coupon.model.CtripCreateOrderResponse;
|
||||
import com.central.coupon.model.CtripCancelOrderRequest;
|
||||
import com.central.coupon.model.CtripCancelOrderResponse;
|
||||
import com.central.coupon.model.CtripCancelOrderConfirmRequest;
|
||||
import com.central.coupon.model.CtripCancelOrderConfirmResponse;
|
||||
import com.central.coupon.model.CtripRefundOrderRequest;
|
||||
import com.central.coupon.model.CtripRefundOrderResponse;
|
||||
import com.central.coupon.model.CtripRefundOrderConfirmRequest;
|
||||
import com.central.coupon.model.CtripRefundOrderConfirmResponse;
|
||||
import com.central.coupon.model.CtripConsumedNoticeRequest;
|
||||
import com.central.coupon.model.CtripConsumedNoticeResponse;
|
||||
|
||||
/**
|
||||
* 携程订单服务接口
|
||||
* 处理携程订单相关的业务逻辑
|
||||
*/
|
||||
public interface ICtripOrderService {
|
||||
|
||||
/**
|
||||
* 处理订单新订
|
||||
* 当客人在携程平台进行订单预定后,携程会通过该接口向供应商系统提交客人的预定信息来完成订单预定
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 订单创建响应
|
||||
*/
|
||||
CtripCreateOrderResponse processCreateOrder(CtripCreateOrderRequest.CtripHeader header,
|
||||
CtripCreateOrderRequest.CtripOrderBody body);
|
||||
|
||||
/**
|
||||
* 处理订单取消
|
||||
* 提供携程与供应商系统进行订单取消操作的接口
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 订单取消响应
|
||||
*/
|
||||
CtripCancelOrderResponse processCancelOrder(CtripCancelOrderRequest.CtripHeader header,
|
||||
CtripCancelOrderRequest.CtripCancelOrderBody body);
|
||||
|
||||
/**
|
||||
* 处理订单取消确认
|
||||
* 当订单在取消提交后供应商需异步确认进行操作(接受、拒绝)
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 订单取消确认响应
|
||||
*/
|
||||
CtripCancelOrderConfirmResponse processCancelOrderConfirm(CtripCancelOrderConfirmRequest.CtripHeader header,
|
||||
CtripCancelOrderConfirmRequest.CtripCancelOrderConfirmBody body);
|
||||
|
||||
/**
|
||||
* 检查订单是否已存在
|
||||
* 供应商在收到携程的下单请求时,需先判断同批次的携程订单号在供应商系统中是否存在且已下单成功
|
||||
*
|
||||
* @param otaOrderId 携程订单号
|
||||
* @param sequenceId 携程处理批次流水号
|
||||
* @return 如果订单已存在且已下单成功返回true,否则返回false
|
||||
*/
|
||||
boolean isOrderExists(String otaOrderId, String sequenceId);
|
||||
|
||||
/**
|
||||
* 创建新订单
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 供应商订单号
|
||||
*/
|
||||
String createNewOrder(CtripCreateOrderRequest.CtripHeader header,
|
||||
CtripCreateOrderRequest.CtripOrderBody body);
|
||||
|
||||
/**
|
||||
* 检查订单取消数量是否合法
|
||||
* 当confirmType=2在取消发起时必须验证取消数量等于可退数量
|
||||
*
|
||||
* @param otaOrderId 携程订单号
|
||||
* @param supplierOrderId 供应商订单号
|
||||
* @param itemId 订单项编号
|
||||
* @param cancelQuantity 取消数量
|
||||
* @return 如果取消数量合法返回true,否则返回false
|
||||
*/
|
||||
boolean validateCancelQuantity(String otaOrderId, String supplierOrderId, String itemId, Integer cancelQuantity);
|
||||
|
||||
/**
|
||||
* 执行订单取消
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 取消结果
|
||||
*/
|
||||
boolean executeOrderCancel(CtripCancelOrderRequest.CtripHeader header,
|
||||
CtripCancelOrderRequest.CtripCancelOrderBody body);
|
||||
|
||||
/**
|
||||
* 处理优惠券信息
|
||||
* 当订单中包含优惠券信息时,需要处理优惠券的创建和使用
|
||||
*
|
||||
* @param coupons 优惠券列表
|
||||
* @param orderId 订单ID
|
||||
* @return 处理结果
|
||||
*/
|
||||
boolean processCoupons(java.util.List<CtripCreateOrderRequest.CtripCoupon> coupons, Long orderId);
|
||||
|
||||
/**
|
||||
* 生成凭证信息
|
||||
* 根据订单信息生成相应的凭证
|
||||
*
|
||||
* @param body 订单体
|
||||
* @param supplierOrderId 供应商订单号
|
||||
* @return 凭证列表
|
||||
*/
|
||||
java.util.List<CtripCreateOrderResponse.CtripVoucher> generateVouchers(
|
||||
CtripCreateOrderRequest.CtripOrderBody body, String supplierOrderId);
|
||||
|
||||
/**
|
||||
* 生成订单项响应
|
||||
*
|
||||
* @param body 订单体
|
||||
* @param supplierOrderId 供应商订单号
|
||||
* @return 订单项响应列表
|
||||
*/
|
||||
java.util.List<CtripCreateOrderResponse.CtripResponseOrderItem> generateOrderItems(
|
||||
CtripCreateOrderRequest.CtripOrderBody body, String supplierOrderId);
|
||||
|
||||
/**
|
||||
* 生成取消订单项响应
|
||||
*
|
||||
* @param body 取消订单体
|
||||
* @return 取消订单项响应列表
|
||||
*/
|
||||
java.util.List<CtripCancelOrderResponse.CtripResponseOrderItem> generateCancelOrderItems(
|
||||
CtripCancelOrderRequest.CtripCancelOrderBody body);
|
||||
|
||||
/**
|
||||
* 处理订单退款
|
||||
* 退款接口与订单取消逻辑并无关联,是纯粹的退钱操作
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 订单退款响应
|
||||
*/
|
||||
CtripRefundOrderResponse processRefundOrder(CtripRefundOrderRequest.CtripHeader header,
|
||||
CtripRefundOrderRequest.CtripRefundOrderBody body);
|
||||
|
||||
/**
|
||||
* 处理订单退款确认
|
||||
* 当订单在退款提交后供应商需异步确认进行操作(接受、拒绝)
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 订单退款确认响应
|
||||
*/
|
||||
CtripRefundOrderConfirmResponse processRefundOrderConfirm(CtripRefundOrderConfirmRequest.CtripHeader header,
|
||||
CtripRefundOrderConfirmRequest.CtripRefundOrderConfirmBody body);
|
||||
|
||||
/**
|
||||
* 检查订单退款金额是否合法
|
||||
* 在退款发起时必须验证退款金额小于等于可退金额
|
||||
*
|
||||
* @param otaOrderId 携程订单号
|
||||
* @param supplierOrderId 供应商订单号
|
||||
* @param refundAmount 退款金额
|
||||
* @return 如果退款金额合法返回true,否则返回false
|
||||
*/
|
||||
boolean validateRefundAmount(String otaOrderId, String supplierOrderId, java.math.BigDecimal refundAmount);
|
||||
|
||||
/**
|
||||
* 执行订单退款
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 退款结果
|
||||
*/
|
||||
boolean executeOrderRefund(CtripRefundOrderRequest.CtripHeader header,
|
||||
CtripRefundOrderRequest.CtripRefundOrderBody body);
|
||||
|
||||
/**
|
||||
* 处理订单核销通知
|
||||
* 当订单在新订确认后,供应商可将客人出行后的使用情况或归还物品等信息调用该接口将对应的最终结果同步给携程系统
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 订单核销通知响应
|
||||
*/
|
||||
CtripConsumedNoticeResponse processConsumedNotice(CtripConsumedNoticeRequest.CtripHeader header,
|
||||
CtripConsumedNoticeRequest.CtripConsumedNoticeBody body);
|
||||
|
||||
/**
|
||||
* 验证核销数量是否合法
|
||||
* 验证已核销数量不超过总数量
|
||||
*
|
||||
* @param itemId 订单项编号
|
||||
* @param totalQuantity 总数量
|
||||
* @param useQuantity 已核销数量
|
||||
* @return 如果核销数量合法返回true,否则返回false
|
||||
*/
|
||||
boolean validateConsumedQuantity(String itemId, Integer totalQuantity, Integer useQuantity);
|
||||
|
||||
/**
|
||||
* 执行订单核销
|
||||
*
|
||||
* @param header 请求头
|
||||
* @param body 请求体
|
||||
* @return 核销结果
|
||||
*/
|
||||
boolean executeOrderConsumed(CtripConsumedNoticeRequest.CtripHeader header,
|
||||
CtripConsumedNoticeRequest.CtripConsumedNoticeBody body);
|
||||
}
|
||||
+34
-102
@@ -1,19 +1,16 @@
|
||||
package com.central.order.service.impl;
|
||||
package com.central.coupon.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.central.order.entity.Coupon;
|
||||
import com.central.order.mapper.CouponMapper;
|
||||
import com.central.order.service.ICouponService;
|
||||
import com.central.order.service.ICtripApiService;
|
||||
import com.central.coupon.entity.Coupon;
|
||||
import com.central.coupon.mapper.CouponMapper;
|
||||
import com.central.coupon.service.ICouponService;
|
||||
import com.central.coupon.service.ICtripApiService;
|
||||
import com.central.common.model.PageResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -37,62 +34,46 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
|
||||
|
||||
@Override
|
||||
public PageResult<Coupon> findList(Map<String, Object> params) {
|
||||
// 获取分页参数
|
||||
Integer page = Integer.parseInt(params.getOrDefault("page", "1").toString());
|
||||
Integer limit = Integer.parseInt(params.getOrDefault("limit", "10").toString());
|
||||
|
||||
// 构建查询条件
|
||||
Coupon queryCoupon = new Coupon();
|
||||
Coupon coupon = new Coupon();
|
||||
if (params.get("couponName") != null) {
|
||||
queryCoupon.setCouponName(params.get("couponName").toString());
|
||||
}
|
||||
if (params.get("couponType") != null) {
|
||||
queryCoupon.setCouponType(Integer.parseInt(params.get("couponType").toString()));
|
||||
}
|
||||
if (params.get("status") != null) {
|
||||
queryCoupon.setStatus(Integer.parseInt(params.get("status").toString()));
|
||||
coupon.setCouponName((String) params.get("couponName"));
|
||||
}
|
||||
if (params.get("userPhone") != null) {
|
||||
queryCoupon.setUserPhone(params.get("userPhone").toString());
|
||||
coupon.setUserPhone((String) params.get("userPhone"));
|
||||
}
|
||||
if (params.get("status") != null) {
|
||||
coupon.setStatus(Integer.valueOf(params.get("status").toString()));
|
||||
}
|
||||
if (params.get("source") != null) {
|
||||
queryCoupon.setSource(Integer.parseInt(params.get("source").toString()));
|
||||
coupon.setSource(Integer.valueOf(params.get("source").toString()));
|
||||
}
|
||||
if (params.get("ctripCouponId") != null) {
|
||||
queryCoupon.setCtripCouponId(params.get("ctripCouponId").toString());
|
||||
if (params.get("couponType") != null) {
|
||||
coupon.setCouponType(Integer.valueOf(params.get("couponType").toString()));
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
Page<Coupon> page = new Page<>();
|
||||
if (params.get("page") != null) {
|
||||
page.setCurrent(Long.valueOf(params.get("page").toString()));
|
||||
}
|
||||
if (params.get("limit") != null) {
|
||||
page.setSize(Long.valueOf(params.get("limit").toString()));
|
||||
}
|
||||
|
||||
IPage<Coupon> result = getCouponPage(page, coupon);
|
||||
|
||||
// 执行分页查询
|
||||
Page<Coupon> pageParam = new Page<>(page, limit);
|
||||
IPage<Coupon> pageResult = baseMapper.selectCouponPage(pageParam, queryCoupon);
|
||||
|
||||
// 构建返回结果
|
||||
return PageResult.<Coupon>builder()
|
||||
.count(pageResult.getTotal())
|
||||
.resp_code(0)
|
||||
.data(pageResult.getRecords())
|
||||
.build();
|
||||
return new PageResult<>(result.getRecords(), result.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean createCoupon(Coupon coupon) {
|
||||
// 生成优惠券编号
|
||||
if (!StringUtils.hasText(coupon.getCouponNo())) {
|
||||
if (coupon.getCouponNo() == null) {
|
||||
coupon.setCouponNo(generateCouponNo());
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
if (coupon.getStatus() == null) {
|
||||
coupon.setStatus(0); // 未使用
|
||||
}
|
||||
if (coupon.getCreateTime() == null) {
|
||||
coupon.setCreateTime(new Date());
|
||||
}
|
||||
if (coupon.getUpdateTime() == null) {
|
||||
coupon.setUpdateTime(new Date());
|
||||
}
|
||||
|
||||
coupon.setCreateTime(new Date());
|
||||
coupon.setUpdateTime(new Date());
|
||||
return save(coupon);
|
||||
}
|
||||
|
||||
@@ -230,6 +211,11 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
|
||||
return baseMapper.updateCouponUsed(coupon.getId(), orderNo) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coupon getByCtripCouponId(String ctripCouponId) {
|
||||
return baseMapper.selectByCtripCouponId(ctripCouponId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByUserPhoneAndCtripCouponId(String userPhone, String ctripCouponId) {
|
||||
return lambdaQuery()
|
||||
@@ -244,58 +230,4 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
|
||||
private String generateCouponNo() {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.central.coupon.service.impl;
|
||||
|
||||
import com.central.coupon.service.ICtripApiService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 携程API服务实现类
|
||||
* 实现携程优惠券相关的API调用
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CtripApiServiceImpl implements ICtripApiService {
|
||||
|
||||
@Override
|
||||
public boolean verifyCoupon(String ctripCouponId, String orderNo) {
|
||||
log.info("调用携程核销接口,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||
|
||||
try {
|
||||
// TODO: 实现真实的携程API调用
|
||||
// 这里应该调用携程的核销接口
|
||||
// 目前先模拟成功返回
|
||||
|
||||
// 构建请求参数
|
||||
Map<String, Object> requestParams = new HashMap<>();
|
||||
requestParams.put("ctripCouponId", ctripCouponId);
|
||||
requestParams.put("orderNo", orderNo);
|
||||
|
||||
log.info("携程核销请求参数: {}", requestParams);
|
||||
|
||||
// TODO: 发送HTTP请求到携程API
|
||||
// String url = "https://api.ctrip.com/coupon/verify";
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestParams, headers);
|
||||
// ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
|
||||
|
||||
// 模拟API调用成功
|
||||
log.info("携程核销接口调用成功,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("携程核销接口调用失败,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCouponStatus(String ctripCouponId) {
|
||||
log.info("调用携程查询优惠券状态接口,ctripCouponId: {}", ctripCouponId);
|
||||
|
||||
try {
|
||||
// TODO: 实现真实的携程API调用
|
||||
// 这里应该调用携程的查询接口
|
||||
// 目前先模拟返回状态
|
||||
|
||||
// 构建请求参数
|
||||
Map<String, Object> requestParams = new HashMap<>();
|
||||
requestParams.put("ctripCouponId", ctripCouponId);
|
||||
|
||||
log.info("携程查询请求参数: {}", requestParams);
|
||||
|
||||
// TODO: 发送HTTP请求到携程API
|
||||
// String url = "https://api.ctrip.com/coupon/status";
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestParams, headers);
|
||||
// ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
||||
|
||||
// 模拟API调用成功,返回状态
|
||||
log.info("携程查询接口调用成功,ctripCouponId: {}", ctripCouponId);
|
||||
return "VALID"; // 模拟返回有效状态
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("携程查询接口调用失败,ctripCouponId: {}", ctripCouponId, e);
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
}
|
||||
+1363
File diff suppressed because it is too large
Load Diff
+238
@@ -0,0 +1,238 @@
|
||||
package com.central.coupon.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* 携程解密工具类
|
||||
* 处理AES-128-CBC加密/解密和MD5签名验证
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CtripDecryptUtil {
|
||||
|
||||
@Value("${ctrip.aes.key:your-aes-key-here}")
|
||||
private String aesKey;
|
||||
|
||||
@Value("${ctrip.aes.iv:your-aes-iv-here}")
|
||||
private String aesIv;
|
||||
|
||||
@Value("${ctrip.md5.secret:your-md5-secret-here}")
|
||||
private String md5Secret;
|
||||
|
||||
/**
|
||||
* AES-128-CBC解密
|
||||
*
|
||||
* @param encryptedData 加密的数据
|
||||
* @return 解密后的数据,如果解密失败返回null
|
||||
*/
|
||||
public String decryptAES(String encryptedData) {
|
||||
try {
|
||||
log.info("开始AES解密,加密数据长度: {}", encryptedData.length());
|
||||
|
||||
// 使用Base64解码
|
||||
byte[] encryptedBytes = Base64.getDecoder().decode(encryptedData);
|
||||
|
||||
// 创建密钥规范
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(aesKey.getBytes(StandardCharsets.UTF_8), "AES");
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(aesIv.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 创建解密器
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
|
||||
|
||||
// 解密
|
||||
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
|
||||
String decryptedData = new String(decryptedBytes, StandardCharsets.UTF_8);
|
||||
|
||||
log.info("AES解密成功,解密后数据长度: {}", decryptedData.length());
|
||||
return decryptedData;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("AES解密失败: {}", e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AES-128-CBC加密
|
||||
*
|
||||
* @param plainData 明文数据
|
||||
* @return 加密后的数据,如果加密失败返回null
|
||||
*/
|
||||
public String encryptAES(String plainData) {
|
||||
try {
|
||||
log.info("开始AES加密,明文数据长度: {}", plainData.length());
|
||||
|
||||
// 创建密钥规范
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(aesKey.getBytes(StandardCharsets.UTF_8), "AES");
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(aesIv.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 创建加密器
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
|
||||
|
||||
// 加密
|
||||
byte[] encryptedBytes = cipher.doFinal(plainData.getBytes(StandardCharsets.UTF_8));
|
||||
String encryptedData = Base64.getEncoder().encodeToString(encryptedBytes);
|
||||
|
||||
log.info("AES加密成功,加密后数据长度: {}", encryptedData.length());
|
||||
return encryptedData;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("AES加密失败: {}", e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证MD5签名
|
||||
*
|
||||
* @param accountId 供应商帐号
|
||||
* @param serviceName 接口名称
|
||||
* @param requestTime 请求时间
|
||||
* @param body 请求体
|
||||
* @param version 版本号
|
||||
* @param sign 签名
|
||||
* @return 验证结果
|
||||
*/
|
||||
public boolean verifySign(String accountId, String serviceName, String requestTime,
|
||||
String body, String version, String sign) {
|
||||
try {
|
||||
log.info("开始验证MD5签名,accountId: {}, serviceName: {}, requestTime: {}",
|
||||
accountId, serviceName, requestTime);
|
||||
|
||||
// 构建签名字符串
|
||||
String signString = buildSignString(accountId, serviceName, requestTime, body, version);
|
||||
|
||||
// 计算MD5
|
||||
String calculatedSign = calculateMD5(signString);
|
||||
|
||||
// 比较签名
|
||||
boolean isValid = calculatedSign.equalsIgnoreCase(sign);
|
||||
|
||||
log.info("MD5签名验证结果: {}, 期望签名: {}, 计算签名: {}", isValid, sign, calculatedSign);
|
||||
return isValid;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("MD5签名验证失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成MD5签名
|
||||
*
|
||||
* @param accountId 供应商帐号
|
||||
* @param serviceName 接口名称
|
||||
* @param requestTime 请求时间
|
||||
* @param body 请求体
|
||||
* @param version 版本号
|
||||
* @return MD5签名
|
||||
*/
|
||||
public String generateSign(String accountId, String serviceName, String requestTime,
|
||||
String body, String version) {
|
||||
try {
|
||||
String signString = buildSignString(accountId, serviceName, requestTime, body, version);
|
||||
return calculateMD5(signString);
|
||||
} catch (Exception e) {
|
||||
log.error("生成MD5签名失败: {}", e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建签名字符串
|
||||
* 格式:accountId + serviceName + requestTime + body + version + secret
|
||||
*/
|
||||
private String buildSignString(String accountId, String serviceName, String requestTime,
|
||||
String body, String version) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(accountId);
|
||||
sb.append(serviceName);
|
||||
sb.append(requestTime);
|
||||
sb.append(body);
|
||||
sb.append(version);
|
||||
sb.append(md5Secret);
|
||||
|
||||
String signString = sb.toString();
|
||||
log.debug("构建签名字符串: {}", signString);
|
||||
return signString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算MD5值
|
||||
*/
|
||||
private String calculateMD5(String input) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] digest = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : digest) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
} catch (Exception e) {
|
||||
log.error("计算MD5失败: {}", e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证时间戳是否在有效期内
|
||||
*
|
||||
* @param requestTime 请求时间字符串,格式:yyyy-MM-dd HH:mm:ss
|
||||
* @param validMinutes 有效期(分钟)
|
||||
* @return 是否有效
|
||||
*/
|
||||
public boolean isTimestampValid(String requestTime, int validMinutes) {
|
||||
try {
|
||||
// 解析请求时间
|
||||
java.time.LocalDateTime requestDateTime = java.time.LocalDateTime.parse(
|
||||
requestTime,
|
||||
java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
);
|
||||
|
||||
// 获取当前时间
|
||||
java.time.LocalDateTime now = java.time.LocalDateTime.now();
|
||||
|
||||
// 计算时间差
|
||||
long diffMinutes = java.time.Duration.between(requestDateTime, now).toMinutes();
|
||||
|
||||
boolean isValid = Math.abs(diffMinutes) <= validMinutes;
|
||||
log.info("时间戳验证结果: {}, 请求时间: {}, 当前时间: {}, 时间差(分钟): {}",
|
||||
isValid, requestTime, now, diffMinutes);
|
||||
|
||||
return isValid;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("时间戳验证失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证版本号
|
||||
*
|
||||
* @param version 版本号
|
||||
* @return 是否有效
|
||||
*/
|
||||
public boolean isVersionValid(String version) {
|
||||
if (version == null || version.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查版本号格式,这里假设支持1.0和2.0
|
||||
return "1.0".equals(version) || "2.0".equals(version);
|
||||
}
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
package com.central.coupon.util;
|
||||
|
||||
/**
|
||||
* 携程响应码工具类
|
||||
* 定义携程API的标准响应码和错误码
|
||||
*/
|
||||
public class CtripResponseCodeUtil {
|
||||
|
||||
/**
|
||||
* 携程响应码
|
||||
*/
|
||||
public static class CtripResponseCodes {
|
||||
// 成功码
|
||||
public static final String SUCCESS = "0000";
|
||||
public static final String SUCCESS_MESSAGE = "操作成功";
|
||||
|
||||
// 系统错误码 (1xxx)
|
||||
public static final String SYSTEM_ERROR = "1001";
|
||||
public static final String SYSTEM_ERROR_MESSAGE = "系统错误";
|
||||
|
||||
public static final String PARAM_ERROR = "1002";
|
||||
public static final String PARAM_ERROR_MESSAGE = "参数错误";
|
||||
|
||||
public static final String SIGN_ERROR = "1003";
|
||||
public static final String SIGN_ERROR_MESSAGE = "签名验证失败";
|
||||
|
||||
public static final String DATA_INVALID = "1004";
|
||||
public static final String DATA_INVALID_MESSAGE = "数据格式错误";
|
||||
|
||||
public static final String TIMEOUT_ERROR = "1005";
|
||||
public static final String TIMEOUT_ERROR_MESSAGE = "请求超时";
|
||||
|
||||
public static final String SERVICE_UNAVAILABLE = "1006";
|
||||
public static final String SERVICE_UNAVAILABLE_MESSAGE = "服务不可用";
|
||||
|
||||
// 业务错误码 (2xxx)
|
||||
public static final String ORDER_NOT_FOUND = "2001";
|
||||
public static final String ORDER_NOT_FOUND_MESSAGE = "订单不存在";
|
||||
|
||||
public static final String ORDER_STATUS_ERROR = "2002";
|
||||
public static final String ORDER_STATUS_ERROR_MESSAGE = "订单状态错误";
|
||||
|
||||
public static final String COUPON_NOT_FOUND = "2003";
|
||||
public static final String COUPON_NOT_FOUND_MESSAGE = "优惠券不存在";
|
||||
|
||||
public static final String COUPON_ALREADY_USED = "2004";
|
||||
public static final String COUPON_ALREADY_USED_MESSAGE = "优惠券已使用";
|
||||
|
||||
public static final String COUPON_EXPIRED = "2005";
|
||||
public static final String COUPON_EXPIRED_MESSAGE = "优惠券已过期";
|
||||
|
||||
public static final String COUPON_INSUFFICIENT = "2006";
|
||||
public static final String COUPON_INSUFFICIENT_MESSAGE = "优惠券余额不足";
|
||||
|
||||
public static final String USER_NOT_FOUND = "2007";
|
||||
public static final String USER_NOT_FOUND_MESSAGE = "用户不存在";
|
||||
|
||||
public static final String PRODUCT_NOT_FOUND = "2008";
|
||||
public static final String PRODUCT_NOT_FOUND_MESSAGE = "产品不存在";
|
||||
|
||||
public static final String INVENTORY_INSUFFICIENT = "2009";
|
||||
public static final String INVENTORY_INSUFFICIENT_MESSAGE = "库存不足";
|
||||
|
||||
public static final String PRICE_ERROR = "2010";
|
||||
public static final String PRICE_ERROR_MESSAGE = "价格错误";
|
||||
|
||||
public static final String CONFIRM_TIME_EXPIRED = "2011";
|
||||
public static final String CONFIRM_TIME_EXPIRED_MESSAGE = "确认时间已过期";
|
||||
|
||||
public static final String DUPLICATE_ORDER = "2012";
|
||||
public static final String DUPLICATE_ORDER_MESSAGE = "重复订单";
|
||||
|
||||
public static final String VOUCHER_GENERATE_ERROR = "2013";
|
||||
public static final String VOUCHER_GENERATE_ERROR_MESSAGE = "凭证生成失败";
|
||||
|
||||
public static final String PASSENGER_INFO_ERROR = "2014";
|
||||
public static final String PASSENGER_INFO_ERROR_MESSAGE = "乘客信息错误";
|
||||
|
||||
public static final String CONTACT_INFO_ERROR = "2015";
|
||||
public static final String CONTACT_INFO_ERROR_MESSAGE = "联系人信息错误";
|
||||
|
||||
public static final String PAYMENT_ERROR = "2016";
|
||||
public static final String PAYMENT_ERROR_MESSAGE = "支付错误";
|
||||
|
||||
public static final String REFUND_ERROR = "2017";
|
||||
public static final String REFUND_ERROR_MESSAGE = "退款错误";
|
||||
|
||||
public static final String CONSUMED_ERROR = "2018";
|
||||
public static final String CONSUMED_ERROR_MESSAGE = "核销错误";
|
||||
|
||||
public static final String CANCEL_ERROR = "2019";
|
||||
public static final String CANCEL_ERROR_MESSAGE = "取消错误";
|
||||
|
||||
public static final String MODIFY_ERROR = "2020";
|
||||
public static final String MODIFY_ERROR_MESSAGE = "修改错误";
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据错误码获取错误信息
|
||||
*/
|
||||
public static String getErrorMessage(String errorCode) {
|
||||
switch (errorCode) {
|
||||
case CtripResponseCodes.SUCCESS:
|
||||
return CtripResponseCodes.SUCCESS_MESSAGE;
|
||||
case CtripResponseCodes.SYSTEM_ERROR:
|
||||
return CtripResponseCodes.SYSTEM_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.PARAM_ERROR:
|
||||
return CtripResponseCodes.PARAM_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.SIGN_ERROR:
|
||||
return CtripResponseCodes.SIGN_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.DATA_INVALID:
|
||||
return CtripResponseCodes.DATA_INVALID_MESSAGE;
|
||||
case CtripResponseCodes.TIMEOUT_ERROR:
|
||||
return CtripResponseCodes.TIMEOUT_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.SERVICE_UNAVAILABLE:
|
||||
return CtripResponseCodes.SERVICE_UNAVAILABLE_MESSAGE;
|
||||
case CtripResponseCodes.ORDER_NOT_FOUND:
|
||||
return CtripResponseCodes.ORDER_NOT_FOUND_MESSAGE;
|
||||
case CtripResponseCodes.ORDER_STATUS_ERROR:
|
||||
return CtripResponseCodes.ORDER_STATUS_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.COUPON_NOT_FOUND:
|
||||
return CtripResponseCodes.COUPON_NOT_FOUND_MESSAGE;
|
||||
case CtripResponseCodes.COUPON_ALREADY_USED:
|
||||
return CtripResponseCodes.COUPON_ALREADY_USED_MESSAGE;
|
||||
case CtripResponseCodes.COUPON_EXPIRED:
|
||||
return CtripResponseCodes.COUPON_EXPIRED_MESSAGE;
|
||||
case CtripResponseCodes.COUPON_INSUFFICIENT:
|
||||
return CtripResponseCodes.COUPON_INSUFFICIENT_MESSAGE;
|
||||
case CtripResponseCodes.USER_NOT_FOUND:
|
||||
return CtripResponseCodes.USER_NOT_FOUND_MESSAGE;
|
||||
case CtripResponseCodes.PRODUCT_NOT_FOUND:
|
||||
return CtripResponseCodes.PRODUCT_NOT_FOUND_MESSAGE;
|
||||
case CtripResponseCodes.INVENTORY_INSUFFICIENT:
|
||||
return CtripResponseCodes.INVENTORY_INSUFFICIENT_MESSAGE;
|
||||
case CtripResponseCodes.PRICE_ERROR:
|
||||
return CtripResponseCodes.PRICE_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.CONFIRM_TIME_EXPIRED:
|
||||
return CtripResponseCodes.CONFIRM_TIME_EXPIRED_MESSAGE;
|
||||
case CtripResponseCodes.DUPLICATE_ORDER:
|
||||
return CtripResponseCodes.DUPLICATE_ORDER_MESSAGE;
|
||||
case CtripResponseCodes.VOUCHER_GENERATE_ERROR:
|
||||
return CtripResponseCodes.VOUCHER_GENERATE_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.PASSENGER_INFO_ERROR:
|
||||
return CtripResponseCodes.PASSENGER_INFO_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.CONTACT_INFO_ERROR:
|
||||
return CtripResponseCodes.CONTACT_INFO_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.PAYMENT_ERROR:
|
||||
return CtripResponseCodes.PAYMENT_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.REFUND_ERROR:
|
||||
return CtripResponseCodes.REFUND_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.CONSUMED_ERROR:
|
||||
return CtripResponseCodes.CONSUMED_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.CANCEL_ERROR:
|
||||
return CtripResponseCodes.CANCEL_ERROR_MESSAGE;
|
||||
case CtripResponseCodes.MODIFY_ERROR:
|
||||
return CtripResponseCodes.MODIFY_ERROR_MESSAGE;
|
||||
default:
|
||||
return "未知错误";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为成功码
|
||||
*/
|
||||
public static boolean isSuccess(String resultCode) {
|
||||
return CtripResponseCodes.SUCCESS.equals(resultCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为系统错误码
|
||||
*/
|
||||
public static boolean isSystemError(String resultCode) {
|
||||
return resultCode != null && resultCode.startsWith("1");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为业务错误码
|
||||
*/
|
||||
public static boolean isBusinessError(String resultCode) {
|
||||
return resultCode != null && resultCode.startsWith("2");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
server:
|
||||
port: 8082
|
||||
servlet:
|
||||
context-path: /coupon-center
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: coupon-center
|
||||
profiles:
|
||||
active: dev
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/coupon_center?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 123456
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
default-property-inclusion: non_null
|
||||
|
||||
# 携程API配置
|
||||
ctrip:
|
||||
aes:
|
||||
key: your-aes-key-here-16chars
|
||||
iv: your-aes-iv-here-16chars
|
||||
md5:
|
||||
secret: your-md5-secret-here
|
||||
api:
|
||||
timeout: 30000
|
||||
retry-times: 3
|
||||
base-url: https://api.ctrip.com
|
||||
|
||||
# MyBatis Plus配置
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath*:mapper/*.xml
|
||||
type-aliases-package: com.central.coupon.entity
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: false
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
logic-delete-field: deleted
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
com.central.coupon: debug
|
||||
org.springframework.web: debug
|
||||
pattern:
|
||||
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
|
||||
file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
|
||||
file:
|
||||
name: logs/coupon-center.log
|
||||
|
||||
# 开发环境配置
|
||||
---
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile: dev
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/coupon_center_dev?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
|
||||
# 生产环境配置
|
||||
---
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile: prod
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/coupon_center_prod?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
profiles:
|
||||
active: prod
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.central.coupon: info
|
||||
org.springframework.web: warn
|
||||
@@ -0,0 +1,15 @@
|
||||
server:
|
||||
port: 8002
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: coupon-center
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
ip: 81.70.164.178
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# metadata:
|
||||
# version: zlt
|
||||
+11
-13
@@ -1,9 +1,9 @@
|
||||
<?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.order.mapper.CouponMapper">
|
||||
<mapper namespace="com.central.coupon.mapper.CouponMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.order.entity.Coupon">
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.coupon.entity.Coupon">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="coupon_no" property="couponNo" jdbcType="VARCHAR"/>
|
||||
<result column="coupon_name" property="couponName" jdbcType="VARCHAR"/>
|
||||
@@ -20,6 +20,7 @@
|
||||
<result column="valid_end_time" property="validEndTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="used_time" property="usedTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="used_order_no" property="usedOrderNo" jdbcType="VARCHAR"/>
|
||||
<result column="cancel_time" property="cancelTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
@@ -30,9 +31,9 @@
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, coupon_no, coupon_name, coupon_type, amount, min_amount, discount_rate, status,
|
||||
user_phone, user_id, source, ctrip_coupon_id, valid_start_time, valid_end_time,
|
||||
used_time, used_order_no, create_time, update_time, create_by, update_by, remark, tenant_id
|
||||
id, coupon_no, coupon_name, coupon_type, amount, min_amount, discount_rate,
|
||||
status, user_phone, user_id, source, ctrip_coupon_id, valid_start_time, valid_end_time,
|
||||
used_time, used_order_no, cancel_time, create_time, update_time, create_by, update_by, remark, tenant_id
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询优惠券列表 -->
|
||||
@@ -44,20 +45,17 @@
|
||||
<if test="coupon.couponName != null and coupon.couponName != ''">
|
||||
AND coupon_name LIKE CONCAT('%', #{coupon.couponName}, '%')
|
||||
</if>
|
||||
<if test="coupon.couponType != null">
|
||||
AND coupon_type = #{coupon.couponType}
|
||||
<if test="coupon.userPhone != null and coupon.userPhone != ''">
|
||||
AND user_phone = #{coupon.userPhone}
|
||||
</if>
|
||||
<if test="coupon.status != null">
|
||||
AND status = #{coupon.status}
|
||||
</if>
|
||||
<if test="coupon.userPhone != null and coupon.userPhone != ''">
|
||||
AND user_phone = #{coupon.userPhone}
|
||||
</if>
|
||||
<if test="coupon.source != null">
|
||||
AND source = #{coupon.source}
|
||||
</if>
|
||||
<if test="coupon.ctripCouponId != null and coupon.ctripCouponId != ''">
|
||||
AND ctrip_coupon_id = #{coupon.ctripCouponId}
|
||||
<if test="coupon.couponType != null">
|
||||
AND coupon_type = #{coupon.couponType}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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.order.mapper.CtripConsumedMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.order.entity.CtripConsumed">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="ota_order_id" property="otaOrderId" jdbcType="VARCHAR"/>
|
||||
<result column="supplier_order_id" property="supplierOrderId" jdbcType="VARCHAR"/>
|
||||
<result column="sequence_id" property="sequenceId" jdbcType="VARCHAR"/>
|
||||
<result column="item_id" property="itemId" jdbcType="VARCHAR"/>
|
||||
<result column="use_start_date" property="useStartDate" jdbcType="VARCHAR"/>
|
||||
<result column="use_end_date" property="useEndDate" jdbcType="VARCHAR"/>
|
||||
<result column="quantity" property="quantity" jdbcType="INTEGER"/>
|
||||
<result column="use_quantity" property="useQuantity" jdbcType="INTEGER"/>
|
||||
<result column="lost_amount" property="lostAmount" jdbcType="DECIMAL"/>
|
||||
<result column="lost_amount_currency" property="lostAmountCurrency" jdbcType="VARCHAR"/>
|
||||
<result column="remark" property="remark" jdbcType="VARCHAR"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
|
||||
<result column="remark_detail" property="remarkDetail" jdbcType="VARCHAR"/>
|
||||
<result column="tenant_id" property="tenantId" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, ota_order_id, supplier_order_id, sequence_id, item_id, use_start_date, use_end_date,
|
||||
quantity, use_quantity, lost_amount, lost_amount_currency, remark, status,
|
||||
create_time, update_time, create_by, update_by, remark_detail, tenant_id
|
||||
</sql>
|
||||
|
||||
<!-- 根据携程订单号查询核销信息 -->
|
||||
<select id="selectByOtaOrderId" parameterType="string" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_consumed
|
||||
WHERE ota_order_id = #{otaOrderId,jdbcType=VARCHAR}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据供应商订单号查询核销信息 -->
|
||||
<select id="selectBySupplierOrderId" parameterType="string" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_consumed
|
||||
WHERE supplier_order_id = #{supplierOrderId,jdbcType=VARCHAR}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据供应商批次流水号查询核销信息 -->
|
||||
<select id="selectBySequenceId" parameterType="string" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_consumed
|
||||
WHERE sequence_id = #{sequenceId,jdbcType=VARCHAR}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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.order.mapper.CtripConsumedPassengerMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.order.entity.CtripConsumedPassenger">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="consumed_id" property="consumedId" jdbcType="BIGINT"/>
|
||||
<result column="passenger_id" property="passengerId" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
|
||||
<result column="remark" property="remark" jdbcType="VARCHAR"/>
|
||||
<result column="tenant_id" property="tenantId" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, consumed_id, passenger_id, create_time, update_time, create_by, update_by, remark, tenant_id
|
||||
</sql>
|
||||
|
||||
<!-- 根据核销ID查询乘客列表 -->
|
||||
<select id="selectByConsumedId" parameterType="long" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_consumed_passenger
|
||||
WHERE consumed_id = #{consumedId,jdbcType=BIGINT}
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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.order.mapper.CtripConsumedVoucherMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.order.entity.CtripConsumedVoucher">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="consumed_id" property="consumedId" jdbcType="BIGINT"/>
|
||||
<result column="voucher_id" property="voucherId" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
|
||||
<result column="remark" property="remark" jdbcType="VARCHAR"/>
|
||||
<result column="tenant_id" property="tenantId" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, consumed_id, voucher_id, create_time, update_time, create_by, update_by, remark, tenant_id
|
||||
</sql>
|
||||
|
||||
<!-- 根据核销ID查询凭证列表 -->
|
||||
<select id="selectByConsumedId" parameterType="long" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_consumed_voucher
|
||||
WHERE consumed_id = #{consumedId,jdbcType=BIGINT}
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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.order.mapper.CtripOrderItemMapper">
|
||||
|
||||
<!-- 根据订单ID查询订单项列表 -->
|
||||
<select id="selectByOrderId" resultType="com.central.order.entity.CtripOrderItem">
|
||||
SELECT
|
||||
id,
|
||||
order_id,
|
||||
item_id,
|
||||
plu,
|
||||
use_start_date,
|
||||
use_end_date,
|
||||
price,
|
||||
sale_price,
|
||||
quantity,
|
||||
create_time,
|
||||
update_time,
|
||||
create_by,
|
||||
update_by,
|
||||
remark,
|
||||
tenant_id
|
||||
FROM t_ctrip_order_item
|
||||
WHERE order_id = #{orderId}
|
||||
ORDER BY id ASC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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.order.mapper.CtripOrderMapper">
|
||||
|
||||
<!-- 根据携程订单号查询订单 -->
|
||||
<select id="selectByOtaOrderId" resultType="com.central.order.entity.CtripOrder">
|
||||
SELECT
|
||||
id,
|
||||
ota_order_id,
|
||||
supplier_order_id,
|
||||
sequence_id,
|
||||
confirm_type,
|
||||
order_last_confirm_time,
|
||||
status,
|
||||
create_time,
|
||||
update_time,
|
||||
create_by,
|
||||
update_by,
|
||||
remark,
|
||||
tenant_id
|
||||
FROM t_ctrip_order
|
||||
WHERE ota_order_id = #{otaOrderId}
|
||||
</select>
|
||||
|
||||
<!-- 根据供应商订单号查询订单 -->
|
||||
<select id="selectBySupplierOrderId" resultType="com.central.order.entity.CtripOrder">
|
||||
SELECT
|
||||
id,
|
||||
ota_order_id,
|
||||
supplier_order_id,
|
||||
sequence_id,
|
||||
confirm_type,
|
||||
order_last_confirm_time,
|
||||
status,
|
||||
create_time,
|
||||
update_time,
|
||||
create_by,
|
||||
update_by,
|
||||
remark,
|
||||
tenant_id
|
||||
FROM t_ctrip_order
|
||||
WHERE supplier_order_id = #{supplierOrderId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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.order.mapper.CtripPassengerMapper">
|
||||
|
||||
<!-- 根据订单项ID查询乘客列表 -->
|
||||
<select id="selectByOrderItemId" resultType="com.central.order.entity.CtripPassenger">
|
||||
SELECT
|
||||
id,
|
||||
order_item_id,
|
||||
passenger_id,
|
||||
name,
|
||||
mobile,
|
||||
card_type,
|
||||
card_no,
|
||||
age_type,
|
||||
gender,
|
||||
create_time,
|
||||
update_time,
|
||||
create_by,
|
||||
update_by,
|
||||
remark,
|
||||
tenant_id
|
||||
FROM t_ctrip_passenger
|
||||
WHERE order_item_id = #{orderItemId}
|
||||
ORDER BY id ASC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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.order.mapper.CtripRefundItemMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.order.entity.CtripRefundItem">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="refund_id" property="refundId" jdbcType="BIGINT"/>
|
||||
<result column="item_id" property="itemId" jdbcType="VARCHAR"/>
|
||||
<result column="plu" property="plu" jdbcType="VARCHAR"/>
|
||||
<result column="amount" property="amount" jdbcType="DECIMAL"/>
|
||||
<result column="amount_currency" property="amountCurrency" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
|
||||
<result column="remark" property="remark" jdbcType="VARCHAR"/>
|
||||
<result column="tenant_id" property="tenantId" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, refund_id, item_id, plu, amount, amount_currency,
|
||||
create_time, update_time, create_by, update_by, remark, tenant_id
|
||||
</sql>
|
||||
|
||||
<!-- 根据退款ID查询退款项列表 -->
|
||||
<select id="selectByRefundId" parameterType="long" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_refund_item
|
||||
WHERE refund_id = #{refundId,jdbcType=BIGINT}
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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.order.mapper.CtripRefundMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.order.entity.CtripRefund">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="ota_order_id" property="otaOrderId" jdbcType="VARCHAR"/>
|
||||
<result column="supplier_order_id" property="supplierOrderId" jdbcType="VARCHAR"/>
|
||||
<result column="sequence_id" property="sequenceId" jdbcType="VARCHAR"/>
|
||||
<result column="total_amount" property="totalAmount" jdbcType="DECIMAL"/>
|
||||
<result column="total_amount_currency" property="totalAmountCurrency" jdbcType="VARCHAR"/>
|
||||
<result column="last_confirm_time" property="lastConfirmTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="confirm_result_code" property="confirmResultCode" jdbcType="VARCHAR"/>
|
||||
<result column="confirm_result_message" property="confirmResultMessage" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
|
||||
<result column="remark" property="remark" jdbcType="VARCHAR"/>
|
||||
<result column="tenant_id" property="tenantId" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, ota_order_id, supplier_order_id, sequence_id, total_amount, total_amount_currency,
|
||||
last_confirm_time, status, confirm_result_code, confirm_result_message,
|
||||
create_time, update_time, create_by, update_by, remark, tenant_id
|
||||
</sql>
|
||||
|
||||
<!-- 根据携程订单号查询退款信息 -->
|
||||
<select id="selectByOtaOrderId" parameterType="string" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_refund
|
||||
WHERE ota_order_id = #{otaOrderId,jdbcType=VARCHAR}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据供应商订单号查询退款信息 -->
|
||||
<select id="selectBySupplierOrderId" parameterType="string" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_refund
|
||||
WHERE supplier_order_id = #{supplierOrderId,jdbcType=VARCHAR}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据携程批次流水号查询退款信息 -->
|
||||
<select id="selectBySequenceId" parameterType="string" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_refund
|
||||
WHERE sequence_id = #{sequenceId,jdbcType=VARCHAR}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1,230 +0,0 @@
|
||||
# 订单中心CDN预热集成说明
|
||||
|
||||
## 概述
|
||||
|
||||
在订单中心的设备上传文件完成逻辑中集成了CDN预热功能,当订单的素材数量达到二维码要求时,自动预热相关文件到CDN,提升用户访问体验。
|
||||
|
||||
## 集成位置
|
||||
|
||||
### 触发时机
|
||||
- **位置**:`OrderFileController.checkAndUpdateOrderStatus()` 方法
|
||||
- **触发条件**:当订单的文件数量达到或超过二维码要求的素材数量时
|
||||
- **执行时机**:在发送用户通知和触发一键成片之前
|
||||
|
||||
### 代码位置
|
||||
```java
|
||||
// 如果当前文件数量达到或超过二维码要求的数量,则更新订单状态为素材上传完成
|
||||
if (currentFileCount >= qrCode.getMaterialCount()) {
|
||||
Tourism tourism = tourismService.getTourismById(qrCode.getTourismId());
|
||||
|
||||
//发送用户素材上传成功通知
|
||||
sendMessageForResouresUploaded(order,tourism);
|
||||
|
||||
// 预热订单相关的文件到CDN
|
||||
prefetchOrderFilesToCdn(order.getOrderNo());
|
||||
|
||||
// 检查是否开启一键成片功能
|
||||
if (isVideoEditEnabled(qrCode)) {
|
||||
// ... 一键成片逻辑
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 功能特性
|
||||
|
||||
- ✅ **自动触发**:素材上传完成时自动预热
|
||||
- ✅ **批量处理**:支持批量预热多个文件
|
||||
- ✅ **配置化**:可通过配置文件控制功能开关和参数
|
||||
- ✅ **错误处理**:完善的异常处理和日志记录
|
||||
- ✅ **性能优化**:分批处理,避免单次处理过多文件
|
||||
|
||||
## 配置说明
|
||||
|
||||
### 1. 配置文件
|
||||
|
||||
在 `application.yml` 中添加CDN预热配置:
|
||||
|
||||
```yaml
|
||||
cdn:
|
||||
prefetch:
|
||||
# 是否启用CDN预热功能
|
||||
enabled: true
|
||||
# 每批次预热的文件数量
|
||||
batch-size: 50
|
||||
# 预热区域:domestic-仅中国内地,overseas-全球(不包含中国内地),不传-全球
|
||||
area: domestic
|
||||
```
|
||||
|
||||
### 2. 配置项说明
|
||||
|
||||
| 配置项 | 默认值 | 说明 |
|
||||
|--------|--------|------|
|
||||
| `cdn.prefetch.enabled` | `true` | 是否启用CDN预热功能 |
|
||||
| `cdn.prefetch.batch-size` | `50` | 每批次预热的文件数量 |
|
||||
| `cdn.prefetch.area` | `domestic` | 预热区域 |
|
||||
|
||||
## 工作流程
|
||||
|
||||
### 1. 触发流程
|
||||
```
|
||||
设备上传文件 → 创建订单文件记录 → 检查素材数量 → 达到要求数量 → 触发CDN预热
|
||||
```
|
||||
|
||||
### 2. 预热流程
|
||||
```
|
||||
获取订单文件列表 → 收集文件URL → 调用CDN批量预热接口 → 记录预热结果
|
||||
```
|
||||
|
||||
### 3. 详细步骤
|
||||
|
||||
1. **检查功能开关**:验证CDN预热功能是否启用
|
||||
2. **获取文件列表**:查询订单的所有文件记录
|
||||
3. **收集URL**:为每个文件生成访问URL
|
||||
4. **批量预热**:调用文件中心的CDN预热接口
|
||||
5. **结果处理**:记录预热成功或失败的结果
|
||||
|
||||
## 接口调用
|
||||
|
||||
### 1. Feign接口
|
||||
|
||||
在 `FileCenterService` 中添加了CDN预热相关接口:
|
||||
|
||||
```java
|
||||
/**
|
||||
* 批量预热文件到CDN
|
||||
*/
|
||||
@PostMapping("/cdn/batch/prefetch")
|
||||
Result<Boolean> batchPrefetchFiles(@RequestBody List<String> urls,
|
||||
@RequestParam(value = "batchSize", defaultValue = "100") int batchSize,
|
||||
@RequestParam(value = "area", required = false) String area);
|
||||
```
|
||||
|
||||
### 2. 调用示例
|
||||
|
||||
```java
|
||||
// 调用CDN批量预热接口
|
||||
Result<Boolean> result = fileCenterService.batchPrefetchFiles(fileUrls, cdnPrefetchBatchSize, cdnPrefetchArea);
|
||||
|
||||
if (result != null && result.getResp_code() == 0) {
|
||||
log.info("订单文件CDN预热成功,订单号: {}, 文件数量: {}", orderNo, fileUrls.size());
|
||||
} else {
|
||||
log.warn("订单文件CDN预热失败,订单号: {}, 错误信息: {}",
|
||||
orderNo, result != null ? result.getResp_msg() : "未知错误");
|
||||
}
|
||||
```
|
||||
|
||||
## 日志记录
|
||||
|
||||
### 1. 关键日志信息
|
||||
|
||||
- **开始预热**:`开始预热订单文件到CDN,订单号: xxx`
|
||||
- **文件收集**:`准备预热 x 个文件到CDN,订单号: xxx, 批次大小: xxx, 预热区域: xxx`
|
||||
- **预热成功**:`订单文件CDN预热成功,订单号: xxx, 文件数量: xxx`
|
||||
- **预热失败**:`订单文件CDN预热失败,订单号: xxx, 错误信息: xxx`
|
||||
|
||||
### 2. 日志级别
|
||||
|
||||
- **INFO**:预热开始、成功、失败等关键信息
|
||||
- **DEBUG**:详细的文件URL收集过程
|
||||
- **WARN**:单个文件URL获取失败
|
||||
- **ERROR**:整体预热过程异常
|
||||
|
||||
## 错误处理
|
||||
|
||||
### 1. 异常处理策略
|
||||
|
||||
- **功能开关**:如果CDN预热功能未启用,直接跳过
|
||||
- **文件为空**:如果订单无文件,记录日志并返回
|
||||
- **URL获取失败**:单个文件URL获取失败不影响其他文件
|
||||
- **预热失败**:记录错误信息但不影响业务流程
|
||||
|
||||
### 2. 容错机制
|
||||
|
||||
```java
|
||||
try {
|
||||
// CDN预热逻辑
|
||||
} catch (Exception e) {
|
||||
log.error("预热订单文件到CDN异常,订单号: {}", orderNo, e);
|
||||
// 不影响主业务流程
|
||||
}
|
||||
```
|
||||
|
||||
## 性能考虑
|
||||
|
||||
### 1. 批量处理
|
||||
|
||||
- 使用配置的批次大小进行批量预热
|
||||
- 避免单次处理过多文件导致超时
|
||||
|
||||
### 2. 异步处理
|
||||
|
||||
- CDN预热是异步操作,不阻塞主业务流程
|
||||
- 用户通知和一键成片功能不受影响
|
||||
|
||||
### 3. 资源控制
|
||||
|
||||
- 通过配置控制预热区域和批次大小
|
||||
- 避免对CDN服务造成过大压力
|
||||
|
||||
## 监控和运维
|
||||
|
||||
### 1. 监控指标
|
||||
|
||||
- 预热成功率
|
||||
- 预热文件数量
|
||||
- 预热耗时
|
||||
- 错误率
|
||||
|
||||
### 2. 运维建议
|
||||
|
||||
- 定期检查CDN预热日志
|
||||
- 监控CDN服务配额使用情况
|
||||
- 根据业务量调整批次大小
|
||||
|
||||
## 扩展功能
|
||||
|
||||
### 1. 预热策略优化
|
||||
|
||||
可以根据文件类型采用不同的预热策略:
|
||||
|
||||
```java
|
||||
// 只预热图片和视频文件
|
||||
List<String> mediaUrls = fileUrls.stream()
|
||||
.filter(url -> CdnUtils.isImageFile(url) || CdnUtils.isVideoFile(url))
|
||||
.collect(Collectors.toList());
|
||||
```
|
||||
|
||||
### 2. 优先级控制
|
||||
|
||||
可以为不同类型的文件设置不同的预热优先级:
|
||||
|
||||
```java
|
||||
// 优先预热重要文件
|
||||
if (isImportantFile(orderFile)) {
|
||||
// 立即预热
|
||||
fileCenterService.prefetchFiles(List.of(viewUrl), "domestic");
|
||||
} else {
|
||||
// 批量预热
|
||||
fileUrls.add(viewUrl);
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 预热结果通知
|
||||
|
||||
可以将预热结果通知给相关系统:
|
||||
|
||||
```java
|
||||
// 预热完成后发送通知
|
||||
if (result != null && result.getResp_code() == 0) {
|
||||
// 发送预热成功通知
|
||||
notifyCdnPrefetchSuccess(orderNo, fileUrls.size());
|
||||
}
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **功能开关**:确保在生产环境中正确配置功能开关
|
||||
2. **批次大小**:根据CDN服务能力调整批次大小
|
||||
3. **预热区域**:根据用户分布选择合适的预热区域
|
||||
4. **错误处理**:预热失败不应影响主业务流程
|
||||
5. **监控告警**:设置适当的监控和告警机制
|
||||
-1895
File diff suppressed because it is too large
Load Diff
+41
-17
@@ -741,14 +741,27 @@ public class OrderController {
|
||||
.filter(f -> "raw_video".equals(f.getFileTag()))
|
||||
.toList();
|
||||
List<Map<String,String>> videoList = new ArrayList<>();
|
||||
for (OrderFile orderFile : videoFiles){
|
||||
for (int i = 0; i < videoFiles.size(); i++){
|
||||
OrderFile orderFile = videoFiles.get(i);
|
||||
Map<String,String> videoMap = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
videoMap.put("url", url.replace(cdnOssUrl, cdnUrl));
|
||||
videoMap.put("contentType", orderFile.getFileType());
|
||||
videoMap.put("path", orderFile.getFilePath());
|
||||
fileMap.put("path",orderFile.getFilePath());
|
||||
videoMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
|
||||
|
||||
// 为视频生成缩略图URL - 使用对应的图片作为缩略图
|
||||
String thumbnailUrl = null;
|
||||
if (!imgList.isEmpty()) {
|
||||
if (i < imgList.size()) {
|
||||
// 使用对应索引的图片作为缩略图
|
||||
thumbnailUrl = imgList.get(i).get("viewUrl");
|
||||
} else {
|
||||
// 如果视频数量超过图片数量,使用最后一张图片作为缩略图
|
||||
thumbnailUrl = imgList.get(imgList.size() - 1).get("viewUrl");
|
||||
}
|
||||
}
|
||||
videoMap.put("viewUrl", thumbnailUrl);
|
||||
|
||||
videoList.add(videoMap);
|
||||
}
|
||||
orderFileMap.put("videoList", videoList);
|
||||
@@ -877,14 +890,18 @@ public class OrderController {
|
||||
for (String filePath : allFilePaths) {
|
||||
String url = fileCenterService.getViewUrlByPath(filePath);
|
||||
fileUrlMap.put(filePath, url.replace(cdnOssUrl, cdnUrl));
|
||||
|
||||
// 预计算样式URL(仅对图片文件)
|
||||
if (filePath.contains("image/jpeg") || filePath.contains("image/")) {
|
||||
Map<String, String> styleParams = new HashMap<>();
|
||||
styleParams.put("path", filePath);
|
||||
styleParams.put("style", fileStyle);
|
||||
String styleUrl = fileCenterService.getViewUrlByPathStyle(styleParams);
|
||||
fileStyleUrlMap.put(filePath, styleUrl);
|
||||
}
|
||||
|
||||
// 预计算样式URL(仅对图片文件)
|
||||
for (List<OrderFile> files : orderFilesMap.values()) {
|
||||
for (OrderFile file : files) {
|
||||
if ("image/jpeg".equals(file.getFileType()) || "image/jpg".equals(file.getFileType()) || "image/png".equals(file.getFileType())) {
|
||||
Map<String, String> styleParams = new HashMap<>();
|
||||
styleParams.put("path", file.getFilePath());
|
||||
styleParams.put("style", fileStyle);
|
||||
String styleUrl = fileCenterService.getViewUrlByPathStyle(styleParams);
|
||||
fileStyleUrlMap.put(file.getFilePath(), styleUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,12 +932,16 @@ public class OrderController {
|
||||
.filter(f -> "image/jpeg".equals(f.getFileType()))
|
||||
.toList();
|
||||
List<Map<String,String>> imgList = new ArrayList<>();
|
||||
Map<String, String> fileMap = new HashMap<>();
|
||||
fileMap.put("style", fileStyle);
|
||||
for (OrderFile orderFile : imgFiles){
|
||||
Map<String,String> imgMap = new HashMap<>();
|
||||
imgMap.put("url", fileUrlMap.get(orderFile.getFilePath()));
|
||||
imgMap.put("contentType", orderFile.getFileType());
|
||||
imgMap.put("path", orderFile.getFilePath());
|
||||
imgMap.put("viewUrl", fileStyleUrlMap.get(orderFile.getFilePath()));
|
||||
fileMap.put("path", orderFile.getFilePath());
|
||||
String viewUrl = fileCenterService.getViewUrlByPathStyle(fileMap);
|
||||
imgMap.put("viewUrl", viewUrl);
|
||||
imgList.add(imgMap);
|
||||
}
|
||||
orderFileMap.put("imgList", imgList);
|
||||
@@ -937,13 +958,16 @@ public class OrderController {
|
||||
videoMap.put("contentType", orderFile.getFileType());
|
||||
videoMap.put("path", orderFile.getFilePath());
|
||||
|
||||
// 视频缩略图使用对应索引的图片缩略图
|
||||
// 为视频生成缩略图URL - 使用对应的图片作为缩略图
|
||||
String thumbnailUrl = null;
|
||||
if (!imgList.isEmpty() && i < imgList.size()) {
|
||||
String thumbnailUrl = imgList.get(i).get("viewUrl");
|
||||
videoMap.put("viewUrl", thumbnailUrl);
|
||||
} else {
|
||||
videoMap.put("viewUrl", null);
|
||||
// 使用对应索引的图片作为缩略图
|
||||
thumbnailUrl = imgList.get(i).get("viewUrl");
|
||||
} else if (!imgList.isEmpty()) {
|
||||
// 如果视频数量超过图片数量,使用第一张图片作为缩略图
|
||||
thumbnailUrl = imgList.get(0).get("viewUrl");
|
||||
}
|
||||
videoMap.put("viewUrl", thumbnailUrl);
|
||||
|
||||
videoList.add(videoMap);
|
||||
}
|
||||
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
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
@@ -1,87 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
-190
@@ -1,190 +0,0 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单新订请求
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCreateOrderRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripHeader header;
|
||||
|
||||
/**
|
||||
* 请求体 - 可能是加密字符串或JSON对象
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private Object body; // 改为Object类型,支持字符串和对象两种格式
|
||||
|
||||
/**
|
||||
* 携程请求头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripHeader {
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime;
|
||||
@JsonProperty("accountId")
|
||||
private String accountId;
|
||||
@JsonProperty("sign")
|
||||
private String sign;
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName;
|
||||
@JsonProperty("version")
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripOrderBody {
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId;
|
||||
@JsonProperty("sequenceId")
|
||||
private String sequenceId;
|
||||
@JsonProperty("items")
|
||||
private List<CtripOrderItem> items;
|
||||
@JsonProperty("contacts")
|
||||
private List<CtripContact> contacts;
|
||||
@JsonProperty("confirmType")
|
||||
private Integer confirmType;
|
||||
@JsonProperty("locale")
|
||||
private String locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripOrderItem {
|
||||
@JsonProperty("passengers")
|
||||
private List<CtripPassenger> passengers;
|
||||
@JsonProperty("cost")
|
||||
private java.math.BigDecimal cost;
|
||||
@JsonProperty("quantity")
|
||||
private Integer quantity;
|
||||
@JsonProperty("salePrice")
|
||||
private java.math.BigDecimal salePrice;
|
||||
@JsonProperty("remark")
|
||||
private String remark;
|
||||
@JsonProperty("useEndDate")
|
||||
private String useEndDate;
|
||||
@JsonProperty("locale")
|
||||
private String locale;
|
||||
@JsonProperty("useStartDate")
|
||||
private String useStartDate;
|
||||
@JsonProperty("priceCurrency")
|
||||
private String priceCurrency;
|
||||
@JsonProperty("adjunctions")
|
||||
private List<String> adjunctions;
|
||||
@JsonProperty("price")
|
||||
private java.math.BigDecimal price;
|
||||
@JsonProperty("PLU")
|
||||
private String PLU;
|
||||
@JsonProperty("deposit")
|
||||
private Object deposit; // 改回Object类型,因为可能是对象
|
||||
@JsonProperty("distributionChannel")
|
||||
private String distributionChannel;
|
||||
@JsonProperty("costCurrency")
|
||||
private String costCurrency;
|
||||
@JsonProperty("salePriceCurrency")
|
||||
private String salePriceCurrency;
|
||||
@JsonProperty("expressDelivery")
|
||||
private CtripExpressDelivery expressDelivery;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程乘客信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripPassenger {
|
||||
@JsonProperty("cardIssuePlace")
|
||||
private String cardIssuePlace;
|
||||
@JsonProperty("lastName")
|
||||
private String lastName;
|
||||
@JsonProperty("cardIssueCountry")
|
||||
private String cardIssueCountry;
|
||||
@JsonProperty("shoeSize")
|
||||
private Integer shoeSize;
|
||||
@JsonProperty("gender")
|
||||
private String gender;
|
||||
@JsonProperty("cardIssueDate")
|
||||
private String cardIssueDate;
|
||||
@JsonProperty("intlCode")
|
||||
private String intlCode;
|
||||
@JsonProperty("nationalityName")
|
||||
private String nationalityName;
|
||||
@JsonProperty("mobile")
|
||||
private String mobile;
|
||||
@JsonProperty("cardType")
|
||||
private String cardType;
|
||||
@JsonProperty("weight")
|
||||
private Integer weight;
|
||||
@JsonProperty("myopiaDegreeL")
|
||||
private Integer myopiaDegreeL;
|
||||
@JsonProperty("birthDate")
|
||||
private String birthDate;
|
||||
@JsonProperty("cardNo")
|
||||
private String cardNo;
|
||||
@JsonProperty("ageType")
|
||||
private String ageType;
|
||||
@JsonProperty("myopiaDegreeR")
|
||||
private Integer myopiaDegreeR;
|
||||
@JsonProperty("firstName")
|
||||
private String firstName;
|
||||
@JsonProperty("birthPlace")
|
||||
private String birthPlace;
|
||||
@JsonProperty("nationalityCode")
|
||||
private String nationalityCode;
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("passengerId")
|
||||
private String passengerId;
|
||||
@JsonProperty("cardValidDate")
|
||||
private String cardValidDate;
|
||||
@JsonProperty("height")
|
||||
private Integer height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程联系人信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripContact {
|
||||
@JsonProperty("intlCode")
|
||||
private String intlCode;
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("mobile")
|
||||
private String mobile;
|
||||
@JsonProperty("optionalMobile")
|
||||
private String optionalMobile;
|
||||
@JsonProperty("optionalIntlCode")
|
||||
private String optionalIntlCode;
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程快递信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripExpressDelivery {
|
||||
@JsonProperty("type")
|
||||
private String type;
|
||||
}
|
||||
}
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单新订响应
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCreateOrderResponse {
|
||||
|
||||
/**
|
||||
* 返回头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripResponseHeader header;
|
||||
|
||||
/**
|
||||
* 处理结果返回码
|
||||
*/
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 处理结果返回信息
|
||||
*/
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 返回体
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private CtripResponseBody body;
|
||||
|
||||
/**
|
||||
* 携程返回头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseHeader {
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime;
|
||||
@JsonProperty("accountId")
|
||||
private String accountId;
|
||||
@JsonProperty("sign")
|
||||
private String sign;
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName;
|
||||
@JsonProperty("version")
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseBody {
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId;
|
||||
@JsonProperty("supplierOrderId")
|
||||
private String supplierOrderId;
|
||||
@JsonProperty("supplierConfirmType")
|
||||
private Integer supplierConfirmType;
|
||||
@JsonProperty("voucherSender")
|
||||
private Integer voucherSender;
|
||||
@JsonProperty("vouchers")
|
||||
private List<CtripVoucher> vouchers;
|
||||
@JsonProperty("orderExtendMessage")
|
||||
private String orderExtendMessage;
|
||||
@JsonProperty("items")
|
||||
private List<CtripResponseOrderItem> items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程凭证
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripVoucher {
|
||||
@JsonProperty("voucherType")
|
||||
private Integer voucherType;
|
||||
@JsonProperty("voucherContent")
|
||||
private String voucherContent;
|
||||
@JsonProperty("voucherUrl")
|
||||
private String voucherUrl;
|
||||
@JsonProperty("locale")
|
||||
private String locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回订单项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseOrderItem {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId;
|
||||
@JsonProperty("supplierItemId")
|
||||
private String supplierItemId;
|
||||
@JsonProperty("status")
|
||||
private Integer status;
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
@Schema(description = "首页统计数据VO")
|
||||
public class DashboardStatisticsVO {
|
||||
@Schema(description = "订单统计")
|
||||
private OrderStatistics orderStats;
|
||||
private OrderStatisticsVO orderStats;
|
||||
|
||||
@Schema(description = "图表统计")
|
||||
private ChartStatistics chartStats;
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@Schema(description = "订单统计")
|
||||
public class OrderStatistics {
|
||||
public class OrderStatisticsVO {
|
||||
@Schema(description = "总订单数")
|
||||
private Long totalOrders;
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package com.central.order.service;
|
||||
|
||||
import com.central.order.model.vo.DashboardStatisticsVO;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.order.model.Order;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -15,5 +16,5 @@ public interface IDashboardService {
|
||||
/**
|
||||
* 获取首页订单列表
|
||||
*/
|
||||
PageResult<com.central.order.model.Order> getDashboardOrders(Map<String, Object> params);
|
||||
PageResult<Order> getDashboardOrders(Map<String, Object> params);
|
||||
}
|
||||
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.central.order.service.ICtripApiService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 携程API服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CtripApiServiceImpl implements ICtripApiService {
|
||||
|
||||
@Override
|
||||
public boolean verifyCoupon(String ctripCouponId, String orderNo) {
|
||||
log.info("调用携程核销接口,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||
|
||||
try {
|
||||
// 根据携程API文档实现核销接口调用
|
||||
// 这里需要根据实际的携程API接口进行实现
|
||||
|
||||
// 1. 构建请求参数
|
||||
Map<String, Object> requestParams = new HashMap<>();
|
||||
requestParams.put("ctripCouponId", ctripCouponId);
|
||||
requestParams.put("orderNo", orderNo);
|
||||
requestParams.put("verifyTime", new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()));
|
||||
|
||||
// 2. 添加签名验证(如果需要)
|
||||
// String sign = generateSign(requestParams);
|
||||
// requestParams.put("sign", sign);
|
||||
|
||||
// 3. 调用携程核销API
|
||||
// 这里应该使用HttpClient或其他HTTP客户端调用携程的核销接口
|
||||
// 例如:
|
||||
// String url = "https://api.ctrip.com/coupon/verify";
|
||||
// String response = httpClient.post(url, requestParams);
|
||||
|
||||
// 4. 解析响应结果
|
||||
// JSONObject responseJson = JSON.parseObject(response);
|
||||
// boolean success = responseJson.getBoolean("success");
|
||||
// String message = responseJson.getString("message");
|
||||
|
||||
// 暂时模拟成功响应
|
||||
log.info("携程核销接口调用成功,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("携程核销接口调用失败,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCouponStatus(String ctripCouponId) {
|
||||
// TODO: 实现具体的携程API调用逻辑
|
||||
// 这里需要根据携程的API文档实现具体的调用
|
||||
log.info("调用携程查询优惠券状态接口,ctripCouponId: {}", ctripCouponId);
|
||||
|
||||
// 模拟API调用
|
||||
try {
|
||||
// 这里应该调用携程的查询API
|
||||
// 例如:HttpClient调用携程的查询接口
|
||||
|
||||
// 暂时返回"VALID",实际需要根据API调用结果返回
|
||||
return "VALID";
|
||||
} catch (Exception e) {
|
||||
log.error("携程查询优惠券状态接口调用失败", e);
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-83
@@ -1,22 +1,20 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.order.mapper.DashboardMapper;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.model.vo.*;
|
||||
import com.central.order.service.IDashboardService;
|
||||
import com.central.order.service.IOrderService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -48,84 +46,26 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<com.central.order.model.Order> getDashboardOrders(Map<String, Object> params) {
|
||||
public PageResult<Order> getDashboardOrders(Map<String, Object> params) {
|
||||
try {
|
||||
// 获取分页参数
|
||||
Integer page = (Integer) params.getOrDefault("page", 1);
|
||||
Integer limit = (Integer) params.getOrDefault("limit", 10);
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<Order>()
|
||||
.orderByDesc(Order::getCreateTime);
|
||||
|
||||
// 如果有时间筛选条件,添加时间范围
|
||||
if (params.get("startTime") != null && !params.get("startTime").toString().isEmpty()) {
|
||||
wrapper.ge(Order::getCreateTime, params.get("startTime"));
|
||||
}
|
||||
if (params.get("endTime") != null && !params.get("endTime").toString().isEmpty()) {
|
||||
wrapper.le(Order::getCreateTime, params.get("endTime"));
|
||||
}
|
||||
|
||||
// 添加其他筛选条件
|
||||
if (params.get("tourismId") != null) {
|
||||
wrapper.eq(Order::getTourismId, params.get("tourismId"));
|
||||
}
|
||||
if (params.get("qrcodeId") != null && !params.get("qrcodeId").toString().isEmpty()) {
|
||||
wrapper.eq(Order::getCodeId, params.get("qrcodeId"));
|
||||
}
|
||||
if (params.get("deviceSn") != null && !params.get("deviceSn").toString().isEmpty()) {
|
||||
wrapper.eq(Order::getDeviceSn, params.get("deviceSn"));
|
||||
}
|
||||
|
||||
// 执行分页查询
|
||||
Page<Order> pageParam = new Page<>(page, limit);
|
||||
Page<Order> resultPage = orderService.page(pageParam, wrapper);
|
||||
// 获取订单列表
|
||||
PageResult<Order> result = orderService.findList(params);
|
||||
|
||||
// 添加调试日志
|
||||
log.info("获取订单列表 - 参数: {}, 结果数量: {}", params, resultPage.getRecords().size());
|
||||
if (!resultPage.getRecords().isEmpty()) {
|
||||
Order firstOrder = resultPage.getRecords().get(0);
|
||||
log.info("第一个订单数据 - orderNo: {}, userId: {}, orderAmount: {}",
|
||||
firstOrder.getOrderNo(), firstOrder.getUserId(), firstOrder.getOrderAmount());
|
||||
}
|
||||
log.info("获取仪表盘订单列表 - 参数: {}, 结果数量: {}", params, result.getCount());
|
||||
|
||||
// 转换为PageResult
|
||||
return PageResult.<Order>builder()
|
||||
.data(resultPage.getRecords())
|
||||
.resp_code(0)
|
||||
.count(resultPage.getTotal())
|
||||
.build();
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("获取首页订单列表失败", e);
|
||||
return PageResult.<Order>builder()
|
||||
.data(new ArrayList<>())
|
||||
.resp_code(0)
|
||||
.count(0L)
|
||||
.build();
|
||||
log.error("获取仪表盘订单列表失败", e);
|
||||
return new PageResult<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单统计(包含对账数据)
|
||||
*
|
||||
* 订单状态说明:
|
||||
* - 有效订单:order_status IN (1, 3, 4, 5, 7, 8, 9)
|
||||
* - 1: 已支付排队中
|
||||
* - 3: 设备执行完成
|
||||
* - 4: 正在服务中
|
||||
* - 5: 素材上传中
|
||||
* - 7: 退款中
|
||||
* - 8: 已退款
|
||||
* - 9: 退款失败(算作有效订单)
|
||||
*
|
||||
* - 收款订单:order_status IN (1, 3, 4, 5, 7)
|
||||
* - 已支付但未退款的订单
|
||||
*
|
||||
* - 退款订单:order_status = 8
|
||||
* - 已成功退款的订单
|
||||
* 获取订单统计
|
||||
*/
|
||||
private OrderStatistics getOrderStatistics(Map<String, Object> params) {
|
||||
OrderStatistics stats = new OrderStatistics();
|
||||
private OrderStatisticsVO getOrderStatistics(Map<String, Object> params) {
|
||||
OrderStatisticsVO stats = new OrderStatisticsVO();
|
||||
|
||||
// 获取订单总数
|
||||
stats.setTotalOrders(dashboardMapper.getTotalOrders(params));
|
||||
@@ -167,8 +107,6 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
|
||||
// 添加调试日志
|
||||
log.info("今日收款订单数统计 - 参数: {}, 结果: {}", params, todayPaidOrders);
|
||||
log.info("时间范围参数 - startTime: {}, endTime: {}", params.get("startTime"), params.get("endTime"));
|
||||
log.info("hasTimeRange判断: {}", (params.get("startTime") != null && params.get("endTime") != null));
|
||||
|
||||
// 获取退款订单数量
|
||||
Long refundedOrders = dashboardMapper.getRefundedOrders(params);
|
||||
@@ -178,16 +116,16 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
Long todayRefundedOrders = dashboardMapper.getTodayRefundedOrders(params);
|
||||
stats.setTodayRefundedOrders(todayRefundedOrders);
|
||||
|
||||
// 获取对账相关数据 - 使用 orders 表的数据
|
||||
// 获取订单总金额
|
||||
Long totalAmount = dashboardMapper.getTotalAmount(params);
|
||||
Long refundAmount = dashboardMapper.getRefundAmount(params);
|
||||
|
||||
// 设置基础数据
|
||||
stats.setTotalAmount(totalAmount);
|
||||
|
||||
// 获取退款金额
|
||||
Long refundAmount = dashboardMapper.getRefundAmount(params);
|
||||
stats.setRefundAmount(refundAmount);
|
||||
|
||||
// 计算净收入 = 总金额 - 退款金额
|
||||
Long netIncome = (totalAmount != null ? totalAmount : 0) - (refundAmount != null ? refundAmount : 0);
|
||||
|
||||
// 计算净收入
|
||||
Long netIncome = (totalAmount != null ? totalAmount : 0L) - (refundAmount != null ? refundAmount : 0L);
|
||||
stats.setNetIncome(netIncome);
|
||||
|
||||
return stats;
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package com.central.order.task;
|
||||
|
||||
import com.central.order.service.ICouponService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 优惠券过期定时任务
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CouponExpirationTask {
|
||||
|
||||
@Autowired
|
||||
private ICouponService couponService;
|
||||
|
||||
/**
|
||||
* 每天凌晨2点执行,批量更新过期优惠券状态
|
||||
*/
|
||||
@Scheduled(cron = "0 0 2 * * ?")
|
||||
public void updateExpiredCoupons() {
|
||||
log.info("开始执行优惠券过期状态更新任务");
|
||||
try {
|
||||
couponService.updateExpiredCoupons();
|
||||
log.info("优惠券过期状态更新任务执行完成");
|
||||
} catch (Exception e) {
|
||||
log.error("优惠券过期状态更新任务执行失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
package com.central.order.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* 携程API解密工具类
|
||||
* 实现AES-128-CBC解密和MD5签名验证
|
||||
*
|
||||
* @author system
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CtripDecryptUtil {
|
||||
|
||||
@Value("${ctrip.aes.key:}")
|
||||
private String aesKey;
|
||||
|
||||
@Value("${ctrip.sign.key:}")
|
||||
private String signKey;
|
||||
|
||||
@Value("${ctrip.aes.iv:}")
|
||||
private String aesIv;
|
||||
|
||||
/**
|
||||
* AES-128-CBC解密(携程标准)
|
||||
*
|
||||
* @param encryptedData 携程自定义编码的加密数据
|
||||
* @return 解密后的原始数据
|
||||
*/
|
||||
public String decryptAES(String encryptedData) {
|
||||
try {
|
||||
if (encryptedData == null || encryptedData.isEmpty()) {
|
||||
log.warn("加密数据为空");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.debug("开始解密携程数据,数据长度: {}", encryptedData.length());
|
||||
|
||||
// 使用携程自定义解码方法
|
||||
byte[] encryptedBytes = decodeBytes(encryptedData);
|
||||
log.debug("自定义解码成功,数据长度: {}", encryptedBytes.length);
|
||||
|
||||
// 检查数据长度
|
||||
if (encryptedBytes.length < 16) {
|
||||
log.error("加密数据长度不足,无法提取IV");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 提取IV(前16字节)
|
||||
byte[] iv = Arrays.copyOfRange(encryptedBytes, 0, 16);
|
||||
byte[] cipherData = Arrays.copyOfRange(encryptedBytes, 16, encryptedBytes.length);
|
||||
|
||||
log.debug("提取IV成功,IV长度: {}, 密文长度: {}", iv.length, cipherData.length);
|
||||
|
||||
// 使用UTF-8字节作为密钥和IV(携程标准)
|
||||
byte[] keyBytes = aesKey.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ivBytes = aesIv.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
log.debug("密钥长度: {}, IV长度: {}", keyBytes.length, ivBytes.length);
|
||||
|
||||
// 创建AES密钥
|
||||
SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES");
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
|
||||
|
||||
// 创建解密器
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec);
|
||||
|
||||
// 解密
|
||||
byte[] decryptedBytes = cipher.doFinal(cipherData);
|
||||
String decryptedData = new String(decryptedBytes, StandardCharsets.UTF_8);
|
||||
|
||||
log.info("AES解密成功,解密后数据长度: {}", decryptedData.length());
|
||||
|
||||
// 清理解密后的数据,移除可能的头部乱码
|
||||
String cleanedData = cleanDecryptedData(decryptedData);
|
||||
log.debug("清理后数据长度: {}", cleanedData.length());
|
||||
|
||||
return cleanedData;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("AES解密失败: {}", e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理解密后的数据,移除头部乱码
|
||||
*/
|
||||
private String cleanDecryptedData(String decryptedData) {
|
||||
if (decryptedData == null || decryptedData.isEmpty()) {
|
||||
return 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('{');
|
||||
if (startIndex == -1) {
|
||||
// 如果没有找到 '{',查找第一个 '"' 字符
|
||||
startIndex = decryptedData.indexOf('"');
|
||||
}
|
||||
|
||||
if (startIndex == -1) {
|
||||
// 如果都没有找到,查找第一个字母或数字
|
||||
for (int i = 0; i < decryptedData.length(); i++) {
|
||||
char c = decryptedData.charAt(i);
|
||||
if (Character.isLetterOrDigit(c)) {
|
||||
startIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (startIndex > 0) {
|
||||
String cleanedData = decryptedData.substring(startIndex);
|
||||
log.info("移除头部乱码,从位置 {} 开始,清理后数据前100个字符: {}",
|
||||
startIndex, cleanedData.length() > 100 ? cleanedData.substring(0, 100) : cleanedData);
|
||||
return cleanedData;
|
||||
}
|
||||
|
||||
log.info("无需清理,数据前100个字符: {}",
|
||||
decryptedData.length() > 100 ? decryptedData.substring(0, 100) : decryptedData);
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程自定义解码方法(转字节数组)
|
||||
*
|
||||
* @param str 编码字符串
|
||||
* @return 字节数组
|
||||
*/
|
||||
private byte[] decodeBytes(String str) {
|
||||
byte[] bytes = new byte[str.length() / 2];
|
||||
for (int i = 0; i < str.length(); i += 2) {
|
||||
char c = str.charAt(i);
|
||||
bytes[i / 2] = (byte) ((c - 'a') << 4);
|
||||
c = str.charAt(i + 1);
|
||||
bytes[i / 2] += (c - 'a');
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程自定义编码方法(转16进制)
|
||||
*
|
||||
* @param bytes 字节数组
|
||||
* @return 编码字符串
|
||||
*/
|
||||
private String encodeBytes(byte[] bytes) {
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
strBuf.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a')));
|
||||
strBuf.append((char) (((bytes[i]) & 0xF) + ((int) 'a')));
|
||||
}
|
||||
return strBuf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证MD5签名(携程标准)
|
||||
*
|
||||
* @param accountId 账号ID
|
||||
* @param serviceName 服务名称
|
||||
* @param requestTime 请求时间
|
||||
* @param body 请求体
|
||||
* @param version 版本
|
||||
* @param sign 签名
|
||||
* @return 验证结果
|
||||
*/
|
||||
public boolean verifySign(String accountId, String serviceName, String requestTime, String body, String version, String sign) {
|
||||
try {
|
||||
// 按携程标准拼接参数:accountId+serviceName+requestTime+body+version+signkey
|
||||
String signContent = accountId + serviceName + requestTime + body + version + signKey;
|
||||
log.debug("签名内容: {}", signContent);
|
||||
|
||||
// 计算MD5并转小写
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] md5Bytes = md.digest(signContent.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 转换为小写十六进制
|
||||
StringBuilder calculatedSign = new StringBuilder();
|
||||
for (byte b : md5Bytes) {
|
||||
calculatedSign.append(String.format("%02x", b & 0xff));
|
||||
}
|
||||
|
||||
String calculatedSignStr = calculatedSign.toString();
|
||||
log.debug("计算签名: {}, 接收签名: {}", calculatedSignStr, sign);
|
||||
|
||||
return calculatedSignStr.equalsIgnoreCase(sign);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("签名验证失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证MD5签名(兼容旧版本)
|
||||
*
|
||||
* @param params 请求参数
|
||||
* @param sign 签名
|
||||
* @return 验证结果
|
||||
*/
|
||||
public boolean verifySign(Map<String, String> params, String sign) {
|
||||
try {
|
||||
// 按字典序排序参数
|
||||
TreeMap<String, String> sortedParams = new TreeMap<>(params);
|
||||
|
||||
// 构建签名字符串
|
||||
StringBuilder signStr = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : sortedParams.entrySet()) {
|
||||
if (entry.getValue() != null && !entry.getValue().isEmpty()) {
|
||||
signStr.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
||||
}
|
||||
}
|
||||
|
||||
// 添加签名密钥
|
||||
signStr.append("key=").append(signKey);
|
||||
|
||||
String signContent = signStr.toString();
|
||||
log.debug("签名内容: {}", signContent);
|
||||
|
||||
// 计算MD5
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] md5Bytes = md.digest(signContent.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 转换为小写十六进制
|
||||
StringBuilder calculatedSign = new StringBuilder();
|
||||
for (byte b : md5Bytes) {
|
||||
calculatedSign.append(String.format("%02x", b & 0xff));
|
||||
}
|
||||
|
||||
String calculatedSignStr = calculatedSign.toString();
|
||||
log.debug("计算签名: {}, 接收签名: {}", calculatedSignStr, sign);
|
||||
|
||||
return calculatedSignStr.equalsIgnoreCase(sign);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("签名验证失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密携程请求体
|
||||
*
|
||||
* @param encryptedBody 加密的请求体
|
||||
* @return 解密后的JSON字符串
|
||||
*/
|
||||
public String decryptCtripBody(String encryptedBody) {
|
||||
if (encryptedBody == null || encryptedBody.isEmpty()) {
|
||||
log.warn("请求体为空");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("开始解密携程请求体,数据长度: {}", encryptedBody.length());
|
||||
|
||||
// 尝试AES解密
|
||||
String decryptedData = decryptAES(encryptedBody);
|
||||
if (decryptedData != null) {
|
||||
log.info("携程请求体解密成功");
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
log.error("携程请求体解密失败");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查配置是否完整
|
||||
*/
|
||||
public boolean isConfigValid() {
|
||||
boolean valid = true;
|
||||
|
||||
if (aesKey == null || aesKey.isEmpty()) {
|
||||
log.error("携程AES密钥未配置");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (signKey == null || signKey.isEmpty()) {
|
||||
log.error("携程签名密钥未配置");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (aesIv == null || aesIv.isEmpty()) {
|
||||
log.error("携程AES IV未配置");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置信息(脱敏)
|
||||
*/
|
||||
public String getConfigInfo() {
|
||||
return String.format("AES密钥长度: %d, 签名密钥长度: %d, IV长度: %d",
|
||||
aesKey != null ? aesKey.length() : 0,
|
||||
signKey != null ? signKey.length() : 0,
|
||||
aesIv != null ? aesIv.length() : 0);
|
||||
}
|
||||
}
|
||||
-363
@@ -1,363 +0,0 @@
|
||||
package com.central.order.util;
|
||||
|
||||
import com.central.order.model.CtripCreateOrderResponse;
|
||||
import com.central.order.model.CtripConsumedNoticeResponse;
|
||||
import com.central.order.model.CtripCreateOrderRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程标准响应码工具类
|
||||
* 根据携程API平台标准定义响应码
|
||||
*
|
||||
* @author system
|
||||
* @date 2024-12-19
|
||||
*/
|
||||
@Slf4j
|
||||
public class CtripResponseCodeUtil {
|
||||
|
||||
/**
|
||||
* 携程标准响应码定义
|
||||
*/
|
||||
public static class CtripResponseCodes {
|
||||
// 成功响应码
|
||||
public static final String SUCCESS = "0000";
|
||||
public static final String SUCCESS_MESSAGE = "操作成功";
|
||||
|
||||
// 系统错误码 (1000-1999)
|
||||
public static final String SYSTEM_ERROR = "1000";
|
||||
public static final String SYSTEM_ERROR_MESSAGE = "系统错误";
|
||||
|
||||
public static final String PARAM_ERROR = "1001";
|
||||
public static final String PARAM_ERROR_MESSAGE = "参数错误";
|
||||
|
||||
public static final String SIGN_ERROR = "1002";
|
||||
public static final String SIGN_ERROR_MESSAGE = "签名验证失败";
|
||||
|
||||
public static final String TIMESTAMP_ERROR = "1003";
|
||||
public static final String TIMESTAMP_ERROR_MESSAGE = "时间戳错误";
|
||||
|
||||
public static final String VERSION_ERROR = "1004";
|
||||
public static final String VERSION_ERROR_MESSAGE = "版本号错误";
|
||||
|
||||
// 业务错误码 (2000-2999)
|
||||
public static final String ORDER_NOT_FOUND = "2000";
|
||||
public static final String ORDER_NOT_FOUND_MESSAGE = "订单不存在";
|
||||
|
||||
public static final String ORDER_ALREADY_EXISTS = "2001";
|
||||
public static final String ORDER_ALREADY_EXISTS_MESSAGE = "订单已存在";
|
||||
|
||||
public static final String ORDER_STATUS_ERROR = "2002";
|
||||
public static final String ORDER_STATUS_ERROR_MESSAGE = "订单状态错误";
|
||||
|
||||
public static final String COUPON_NOT_FOUND = "2003";
|
||||
public static final String COUPON_NOT_FOUND_MESSAGE = "优惠券不存在";
|
||||
|
||||
public static final String COUPON_ALREADY_USED = "2004";
|
||||
public static final String COUPON_ALREADY_USED_MESSAGE = "优惠券已使用";
|
||||
|
||||
public static final String COUPON_EXPIRED = "2005";
|
||||
public static final String COUPON_EXPIRED_MESSAGE = "优惠券已过期";
|
||||
|
||||
public static final String COUPON_INSUFFICIENT = "2006";
|
||||
public static final String COUPON_INSUFFICIENT_MESSAGE = "优惠券余额不足";
|
||||
|
||||
public static final String USER_NOT_FOUND = "2007";
|
||||
public static final String USER_NOT_FOUND_MESSAGE = "用户不存在";
|
||||
|
||||
public static final String PRODUCT_NOT_FOUND = "2008";
|
||||
public static final String PRODUCT_NOT_FOUND_MESSAGE = "产品不存在";
|
||||
|
||||
public static final String PRODUCT_UNAVAILABLE = "2009";
|
||||
public static final String PRODUCT_UNAVAILABLE_MESSAGE = "产品不可用";
|
||||
|
||||
// 网络错误码 (3000-3999)
|
||||
public static final String NETWORK_ERROR = "3000";
|
||||
public static final String NETWORK_ERROR_MESSAGE = "网络连接错误";
|
||||
|
||||
public static final String TIMEOUT_ERROR = "3001";
|
||||
public static final String TIMEOUT_ERROR_MESSAGE = "请求超时";
|
||||
|
||||
public static final String SERVICE_UNAVAILABLE = "3002";
|
||||
public static final String SERVICE_UNAVAILABLE_MESSAGE = "服务不可用";
|
||||
|
||||
// 权限错误码 (4000-4999)
|
||||
public static final String UNAUTHORIZED = "4000";
|
||||
public static final String UNAUTHORIZED_MESSAGE = "未授权访问";
|
||||
|
||||
public static final String FORBIDDEN = "4001";
|
||||
public static final String FORBIDDEN_MESSAGE = "访问被拒绝";
|
||||
|
||||
public static final String ACCOUNT_DISABLED = "4002";
|
||||
public static final String ACCOUNT_DISABLED_MESSAGE = "账户已禁用";
|
||||
|
||||
// 数据错误码 (5000-5999)
|
||||
public static final String DATA_NOT_FOUND = "5000";
|
||||
public static final String DATA_NOT_FOUND_MESSAGE = "数据不存在";
|
||||
|
||||
public static final String DATA_INVALID = "5001";
|
||||
public static final String DATA_INVALID_MESSAGE = "数据格式错误";
|
||||
|
||||
public static final String DATA_CONFLICT = "5002";
|
||||
public static final String DATA_CONFLICT_MESSAGE = "数据冲突";
|
||||
|
||||
// 第三方服务错误码 (6000-6999)
|
||||
public static final String THIRD_PARTY_ERROR = "6000";
|
||||
public static final String THIRD_PARTY_ERROR_MESSAGE = "第三方服务错误";
|
||||
|
||||
public static final String PAYMENT_ERROR = "6001";
|
||||
public static final String PAYMENT_ERROR_MESSAGE = "支付服务错误";
|
||||
|
||||
public static final String SMS_ERROR = "6002";
|
||||
public static final String SMS_ERROR_MESSAGE = "短信服务错误";
|
||||
|
||||
public static final String EMAIL_ERROR = "6003";
|
||||
public static final String EMAIL_ERROR_MESSAGE = "邮件服务错误";
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程订单创建成功响应
|
||||
*/
|
||||
public static CtripCreateOrderResponse buildCreateOrderSuccessResponse(
|
||||
CtripCreateOrderRequest request,
|
||||
String otaOrderId,
|
||||
String supplierOrderId,
|
||||
String message) {
|
||||
|
||||
CtripCreateOrderResponse response = new CtripCreateOrderResponse();
|
||||
|
||||
// 设置返回头
|
||||
CtripCreateOrderResponse.CtripResponseHeader responseHeader = new CtripCreateOrderResponse.CtripResponseHeader();
|
||||
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(CtripResponseCodes.SUCCESS);
|
||||
response.setResultMessage(CtripResponseCodes.SUCCESS_MESSAGE);
|
||||
|
||||
// 设置返回体
|
||||
CtripCreateOrderResponse.CtripResponseBody responseBody = new CtripCreateOrderResponse.CtripResponseBody();
|
||||
responseBody.setOtaOrderId(otaOrderId);
|
||||
responseBody.setSupplierOrderId(supplierOrderId);
|
||||
responseBody.setSupplierConfirmType(1); // 已确认
|
||||
responseBody.setVoucherSender(1); // 携程对客发送凭证
|
||||
responseBody.setOrderExtendMessage(message);
|
||||
|
||||
// 设置订单项
|
||||
List<CtripCreateOrderResponse.CtripResponseOrderItem> responseItems = new ArrayList<>();
|
||||
CtripCreateOrderResponse.CtripResponseOrderItem responseItem = new CtripCreateOrderResponse.CtripResponseOrderItem();
|
||||
responseItem.setItemId("1");
|
||||
responseItem.setSupplierItemId(supplierOrderId + "_ITEM");
|
||||
responseItem.setStatus(1); // 成功
|
||||
responseItem.setMessage(message);
|
||||
responseItems.add(responseItem);
|
||||
responseBody.setItems(responseItems);
|
||||
|
||||
response.setBody(responseBody);
|
||||
|
||||
log.info("构建携程订单创建成功响应: otaOrderId={}, supplierOrderId={}", otaOrderId, supplierOrderId);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程订单创建错误响应
|
||||
*/
|
||||
public static CtripCreateOrderResponse buildCreateOrderErrorResponse(
|
||||
CtripCreateOrderRequest request,
|
||||
String resultCode,
|
||||
String resultMessage) {
|
||||
|
||||
CtripCreateOrderResponse response = new CtripCreateOrderResponse();
|
||||
|
||||
// 设置返回头
|
||||
CtripCreateOrderResponse.CtripResponseHeader responseHeader = new CtripCreateOrderResponse.CtripResponseHeader();
|
||||
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);
|
||||
|
||||
log.warn("构建携程订单创建错误响应: resultCode={}, resultMessage={}", resultCode, resultMessage);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程核销通知成功响应
|
||||
*/
|
||||
public static CtripConsumedNoticeResponse buildConsumedNoticeSuccessResponse(
|
||||
String otaOrderId,
|
||||
String supplierOrderId) {
|
||||
|
||||
CtripConsumedNoticeResponse response = new CtripConsumedNoticeResponse();
|
||||
|
||||
// 设置响应头
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader header = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader();
|
||||
header.setRequestTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
header.setAccountId("SYSTEM");
|
||||
header.setSign("SUCCESS");
|
||||
header.setServiceName("ConsumedNotice");
|
||||
header.setVersion("1.0");
|
||||
response.setHeader(header);
|
||||
|
||||
// 设置响应码
|
||||
response.setResultCode(CtripResponseCodes.SUCCESS);
|
||||
response.setResultMessage(CtripResponseCodes.SUCCESS_MESSAGE);
|
||||
|
||||
// 设置响应体
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody body = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody();
|
||||
body.setOtaOrderId(otaOrderId);
|
||||
body.setSupplierOrderId(supplierOrderId);
|
||||
body.setProcessResult("SUCCESS");
|
||||
body.setProcessTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
response.setBody(body);
|
||||
|
||||
log.info("构建携程核销通知成功响应: otaOrderId={}, supplierOrderId={}", otaOrderId, supplierOrderId);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建携程核销通知错误响应
|
||||
*/
|
||||
public static CtripConsumedNoticeResponse buildConsumedNoticeErrorResponse(
|
||||
String otaOrderId,
|
||||
String supplierOrderId,
|
||||
String resultCode,
|
||||
String resultMessage) {
|
||||
|
||||
CtripConsumedNoticeResponse response = new CtripConsumedNoticeResponse();
|
||||
|
||||
// 设置响应头
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader header = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseHeader();
|
||||
header.setRequestTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
header.setAccountId("SYSTEM");
|
||||
header.setSign("ERROR");
|
||||
header.setServiceName("ConsumedNotice");
|
||||
header.setVersion("1.0");
|
||||
response.setHeader(header);
|
||||
|
||||
// 设置响应码
|
||||
response.setResultCode(resultCode);
|
||||
response.setResultMessage(resultMessage);
|
||||
|
||||
// 设置响应体
|
||||
CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody body = new CtripConsumedNoticeResponse.CtripConsumedNoticeResponseBody();
|
||||
body.setOtaOrderId(otaOrderId);
|
||||
body.setSupplierOrderId(supplierOrderId);
|
||||
body.setProcessResult("FAILED");
|
||||
body.setProcessTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
response.setBody(body);
|
||||
|
||||
log.warn("构建携程核销通知错误响应: otaOrderId={}, resultCode={}, resultMessage={}", otaOrderId, resultCode, resultMessage);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据异常类型获取标准响应码
|
||||
*/
|
||||
public static String getResultCodeByException(Exception e) {
|
||||
String exceptionName = e.getClass().getSimpleName();
|
||||
|
||||
switch (exceptionName) {
|
||||
case "IllegalArgumentException":
|
||||
case "MissingServletRequestParameterException":
|
||||
return CtripResponseCodes.PARAM_ERROR;
|
||||
case "UnauthorizedException":
|
||||
return CtripResponseCodes.UNAUTHORIZED;
|
||||
case "ForbiddenException":
|
||||
return CtripResponseCodes.FORBIDDEN;
|
||||
case "NotFoundException":
|
||||
return CtripResponseCodes.DATA_NOT_FOUND;
|
||||
case "ConflictException":
|
||||
return CtripResponseCodes.DATA_CONFLICT;
|
||||
case "TimeoutException":
|
||||
return CtripResponseCodes.TIMEOUT_ERROR;
|
||||
default:
|
||||
return CtripResponseCodes.SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据异常类型获取标准响应消息
|
||||
*/
|
||||
public static String getResultMessageByException(Exception e) {
|
||||
String exceptionName = e.getClass().getSimpleName();
|
||||
|
||||
switch (exceptionName) {
|
||||
case "IllegalArgumentException":
|
||||
case "MissingServletRequestParameterException":
|
||||
return CtripResponseCodes.PARAM_ERROR_MESSAGE;
|
||||
case "UnauthorizedException":
|
||||
return CtripResponseCodes.UNAUTHORIZED_MESSAGE;
|
||||
case "ForbiddenException":
|
||||
return CtripResponseCodes.FORBIDDEN_MESSAGE;
|
||||
case "NotFoundException":
|
||||
return CtripResponseCodes.DATA_NOT_FOUND_MESSAGE;
|
||||
case "ConflictException":
|
||||
return CtripResponseCodes.DATA_CONFLICT_MESSAGE;
|
||||
case "TimeoutException":
|
||||
return CtripResponseCodes.TIMEOUT_ERROR_MESSAGE;
|
||||
default:
|
||||
return CtripResponseCodes.SYSTEM_ERROR_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证响应码是否有效
|
||||
*/
|
||||
public static boolean isValidResponseCode(String resultCode) {
|
||||
if (resultCode == null || resultCode.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否为4位数字
|
||||
if (!resultCode.matches("\\d{4}")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否在有效范围内
|
||||
int code = Integer.parseInt(resultCode);
|
||||
return (code >= 0 && code <= 9999);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取响应码分类
|
||||
*/
|
||||
public static String getResponseCodeCategory(String resultCode) {
|
||||
if (resultCode == null || resultCode.isEmpty()) {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
int code = Integer.parseInt(resultCode);
|
||||
|
||||
if (code == 0) {
|
||||
return "SUCCESS";
|
||||
} else if (code >= 1000 && code < 2000) {
|
||||
return "SYSTEM_ERROR";
|
||||
} else if (code >= 2000 && code < 3000) {
|
||||
return "BUSINESS_ERROR";
|
||||
} else if (code >= 3000 && code < 4000) {
|
||||
return "NETWORK_ERROR";
|
||||
} else if (code >= 4000 && code < 5000) {
|
||||
return "AUTHORIZATION_ERROR";
|
||||
} else if (code >= 5000 && code < 6000) {
|
||||
return "DATA_ERROR";
|
||||
} else if (code >= 6000 && code < 7000) {
|
||||
return "THIRD_PARTY_ERROR";
|
||||
} else {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ spring:
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: com.central.device.model
|
||||
typeAliasesPackage: com.central.order.model
|
||||
# configuration:
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
global-config:
|
||||
@@ -87,7 +87,7 @@ tencent:
|
||||
file:
|
||||
oss-url: goflyapp.oss-cn-beijing.aliyuncs.com
|
||||
cdn-url: cdn.goflytec.com
|
||||
style: image/resize,m_mfit,w_218,h_160
|
||||
style: image/resize,m_mfit,w_218,h_288
|
||||
#审计日志
|
||||
# audit-log:
|
||||
# enabled: true
|
||||
|
||||
-427
@@ -1,427 +0,0 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.order.model.CtripCreateOrderRequest;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* 优惠券控制器测试
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class CouponControllerTest {
|
||||
|
||||
@Test
|
||||
public void testCtripCreateOrderRequestDeserialization() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试JSON
|
||||
String testJson = "{\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"requestTime\": \"2024-12-19 10:00:00\",\n" +
|
||||
" \"accountId\": \"testAccount\",\n" +
|
||||
" \"sign\": \"testSign\",\n" +
|
||||
" \"serviceName\": \"createOrder\",\n" +
|
||||
" \"version\": \"1.0\"\n" +
|
||||
" },\n" +
|
||||
" \"body\": {\n" +
|
||||
" \"otaOrderId\": \"CTRIP123456\",\n" +
|
||||
" \"sequenceId\": \"SEQ123456\",\n" +
|
||||
" \"items\": [\n" +
|
||||
" {\n" +
|
||||
" \"passengers\": [\n" +
|
||||
" {\n" +
|
||||
" \"name\": \"张三\",\n" +
|
||||
" \"mobile\": \"13800138000\",\n" +
|
||||
" \"gender\": \"M\",\n" +
|
||||
" \"cardType\": \"ID\",\n" +
|
||||
" \"cardNo\": \"110101199001011234\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"cost\": 100.00,\n" +
|
||||
" \"quantity\": 1,\n" +
|
||||
" \"salePrice\": 80.00,\n" +
|
||||
" \"price\": 100.00,\n" +
|
||||
" \"useStartDate\": \"2024-12-20\",\n" +
|
||||
" \"useEndDate\": \"2024-12-25\",\n" +
|
||||
" \"adjunctions\": [\"adj1\", \"adj2\"],\n" +
|
||||
" \"deposit\": {},\n" +
|
||||
" \"distributionChannel\": \"online\",\n" +
|
||||
" \"priceCurrency\": \"CNY\",\n" +
|
||||
" \"costCurrency\": \"CNY\",\n" +
|
||||
" \"salePriceCurrency\": \"CNY\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"contacts\": [\n" +
|
||||
" {\n" +
|
||||
" \"name\": \"张三\",\n" +
|
||||
" \"mobile\": \"13800138000\",\n" +
|
||||
" \"email\": \"zhangsan@example.com\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
// 测试反序列化
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(testJson, CtripCreateOrderRequest.class);
|
||||
|
||||
// 验证反序列化结果
|
||||
assertNotNull(request);
|
||||
assertNotNull(request.getHeader());
|
||||
assertNotNull(request.getBody());
|
||||
assertEquals("testAccount", request.getHeader().getAccountId());
|
||||
assertEquals("createOrder", request.getHeader().getServiceName());
|
||||
|
||||
// 验证body是对象
|
||||
assertTrue(request.getBody() instanceof CtripCreateOrderRequest.CtripOrderBody);
|
||||
CtripCreateOrderRequest.CtripOrderBody body = (CtripCreateOrderRequest.CtripOrderBody) request.getBody();
|
||||
assertEquals("CTRIP123456", body.getOtaOrderId());
|
||||
|
||||
// 验证订单项
|
||||
assertNotNull(body.getItems());
|
||||
assertFalse(body.getItems().isEmpty());
|
||||
|
||||
CtripCreateOrderRequest.CtripOrderItem item = body.getItems().get(0);
|
||||
assertNotNull(item.getPassengers());
|
||||
assertFalse(item.getPassengers().isEmpty());
|
||||
assertEquals("张三", item.getPassengers().get(0).getName());
|
||||
assertEquals("13800138000", item.getPassengers().get(0).getMobile());
|
||||
|
||||
System.out.println("JSON反序列化测试通过!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtripCreateOrderRequestSerialization() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试对象
|
||||
CtripCreateOrderRequest request = new CtripCreateOrderRequest();
|
||||
|
||||
// 设置header
|
||||
CtripCreateOrderRequest.CtripHeader header = new CtripCreateOrderRequest.CtripHeader();
|
||||
header.setRequestTime("2024-12-19 10:00:00");
|
||||
header.setAccountId("testAccount");
|
||||
header.setSign("testSign");
|
||||
header.setServiceName("createOrder");
|
||||
header.setVersion("1.0");
|
||||
request.setHeader(header);
|
||||
|
||||
// 设置body为对象
|
||||
CtripCreateOrderRequest.CtripOrderBody body = new CtripCreateOrderRequest.CtripOrderBody();
|
||||
body.setOtaOrderId("CTRIP123456");
|
||||
body.setSequenceId("SEQ123456");
|
||||
|
||||
// 设置item
|
||||
CtripCreateOrderRequest.CtripOrderItem item = new CtripCreateOrderRequest.CtripOrderItem();
|
||||
item.setCost(new BigDecimal("100.00"));
|
||||
item.setQuantity(1);
|
||||
item.setSalePrice(new BigDecimal("80.00"));
|
||||
item.setPrice(new BigDecimal("100.00"));
|
||||
item.setUseStartDate("2024-12-20");
|
||||
item.setUseEndDate("2024-12-25");
|
||||
item.setAdjunctions(Arrays.asList("adj1", "adj2"));
|
||||
item.setDeposit(new Object());
|
||||
item.setDistributionChannel("online");
|
||||
item.setPriceCurrency("CNY");
|
||||
item.setCostCurrency("CNY");
|
||||
item.setSalePriceCurrency("CNY");
|
||||
|
||||
// 设置passenger
|
||||
CtripCreateOrderRequest.CtripPassenger passenger = new CtripCreateOrderRequest.CtripPassenger();
|
||||
passenger.setName("张三");
|
||||
passenger.setMobile("13800138000");
|
||||
passenger.setGender("M");
|
||||
passenger.setCardType("ID");
|
||||
passenger.setCardNo("110101199001011234");
|
||||
item.setPassengers(Arrays.asList(passenger));
|
||||
|
||||
body.setItems(Arrays.asList(item));
|
||||
|
||||
// 设置contact
|
||||
CtripCreateOrderRequest.CtripContact contact = new CtripCreateOrderRequest.CtripContact();
|
||||
contact.setName("张三");
|
||||
contact.setMobile("13800138000");
|
||||
contact.setEmail("zhangsan@example.com");
|
||||
body.setContacts(Arrays.asList(contact));
|
||||
|
||||
request.setBody(body);
|
||||
|
||||
// 测试序列化
|
||||
String json = objectMapper.writeValueAsString(request);
|
||||
assertNotNull(json);
|
||||
assertTrue(json.contains("CTRIP123456"));
|
||||
assertTrue(json.contains("testAccount"));
|
||||
|
||||
System.out.println("JSON序列化测试通过!");
|
||||
System.out.println("生成的JSON: " + json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorHandling() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 测试错误的JSON格式
|
||||
String invalidJson = "{\"invalid\": \"data\"}";
|
||||
|
||||
try {
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(invalidJson, CtripCreateOrderRequest.class);
|
||||
// 如果没有抛出异常,说明@JsonIgnoreProperties生效了
|
||||
assertNotNull(request);
|
||||
System.out.println("错误处理测试通过 - 忽略未知属性");
|
||||
} catch (Exception e) {
|
||||
// 如果抛出异常,也是正常的
|
||||
System.out.println("错误处理测试通过 - 捕获到异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptedDataHandling() {
|
||||
// 测试加密数据处理
|
||||
String encryptedData = "anipkokpjcnikijobbdgmeddhnmngkidmfoeamjgmmjenpikgpeafnoonnjppdlhhhoidlopkfbpepchhbikpeiaogpmglhjbcaoomkponmciaphjjajhogmmagkiflikbffgmgkinckainhidjjmmoifodpakdlacfepfphenlflpcpdmjpnpaocckibgoagfcncpjnkhaniibphkmgknjabnfoeiblkfbmpekpkpaolangbbpflclbnbmffcaaemnaceckfmaegfnoclpgkblgpjggkjdmkbnkbffacmlpbnefipiaenjclfppilnedllghnejhdchhkdacadanioehbpbdmghioohnjbaamahjdoebckhhljnohfaddbndlepilbnngdhlmfbajnjchllinafbpeldcaacnddmieipmnikgbbbmjpbnpofceacdecjdifkmipeknimidgpbjpdoclimemkjmjhnneghcknneambllglnahlkenngnakncoijpggpdafipbladoaadbdfdebkcjfkaopaieknmjfopbojgljmlgkehmgoghnhggppbeoflhgfijjoabbmkipehekdpchlagnlbdidbmdmghdhoicoapnneljedkkaiikieneiopokkbidoigjlbmkkpeilapilhcmdkaiokiciaacenikijicllgdkbhlenhhcdapipkjhompefkfeginnmgmkjjooleihjfnjofkdgelojfboejjdopiajgldoppcaepkoceffkfjacfcpcbfcblgkaigddakfagnijfjdombelmfgjgopighebpdgbfcbmbecblhdgfbgkoacoiemfelalemmnkeejnighfgmlbenocgdlmoelbcakjppjlpoecimikkbcjblemhbhcgnapcmjbbflgmlfkllmpgdmhiagpolnlccanjdbajnbieapghplipmemakjkkfgphligccnlpjhgeiglbpdcejaajfhjfkplhocifopajenpmdmpncbpkhbbnpnbckmkahemfddhkgijgagkbmpigmbdedmkonkcchimohghkojhmgfeafpefoefccbjjkfkdcedbcmlgomoicfihhaalamkafkmfefdlihpopbdomkiodfdaiogemkebjmbgnfodmnbfedbaacdlmmangllfjihbhmngeoibobbjjmfmfdmpncdpbnfhcggonmfnpifhbjbjlnmcffdpnjpajkgdhllhdpffbdnioacknijcabmncijgmepdkipfpncchmaiamlmfpbcjamggjdjeokhdepklpflafjolemjednbbfmgoikkmfdhgnfiomkaahccnflpdlholfdkncdimgdgfmjdahadbohhfiamlfggljdeahjaaoopclacaakmpobapkhnbmcfmlbobdhblillhdbmmnoaaaeedaleehgpeofipljnmloicglmdmefpkdiplhlmhgiafhjjijigeapikdcdaoallpjlcmebbcohnmlacnkcbcnjkapdaeemkgcgbodjbneaapdgomhbmoljahdlmffnebohgngnfhkjlhejfebgjcccfpmclbeooaghapbkdcjicgjpjnjcgfnhefcmkknglodcoajnobpakaempkbllghgfcobefnebjnaniocjmdedcbgpbbacelfecgemifkedogbloplckenjopknbpfgabpfnaphcklifibbhgohhkjldaekcedkeimlmegdhbjnffililaamfbfdkakleknjdjahogknimijcdahggheehclghkbkkclebcgopeabkkcceiahldnmnffhkgcdbahaldpgddehbpjieaojnknbedoinappdpjjkinjcgiodfahffppcpkeaelgcabkelblhlbbddbemckhkjldpndoohboioplpdohngjpbdegfcnhloenmncalldemhoigglahmnpcdepjfmfhdekbnombijpcfiggmllpglbghlelijohdegkkmicbcgioccekjbhfhoimhdpcejcjcjlmohpfiijjpmknihlhgjeniknkjlhjdgemjgjbnahdhjgobmgonnlljhpendhke";
|
||||
|
||||
// 验证这是一个长字符串而不是JSON
|
||||
assertFalse(encryptedData.startsWith("{"));
|
||||
assertFalse(encryptedData.endsWith("}"));
|
||||
assertTrue(encryptedData.length() > 1000);
|
||||
|
||||
System.out.println("加密数据处理测试通过 - 识别为非JSON格式的长字符串");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testOrderCreation() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试JSON - 实际的携程订单数据
|
||||
String testJson = "{\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"requestTime\": \"2025-08-01 22:58:01\",\n" +
|
||||
" \"accountId\": \"c50a8f2a4a59c9e7\",\n" +
|
||||
" \"sign\": \"5e8ebe775c7aaa466cd469947d6dee22\",\n" +
|
||||
" \"serviceName\": \"CreatePreOrder\",\n" +
|
||||
" \"version\": \"1.0\"\n" +
|
||||
" },\n" +
|
||||
" \"body\": {\n" +
|
||||
" \"otaOrderId\": \"ctriptest-10816912-454259-145573\",\n" +
|
||||
" \"sequenceId\": \"2025080122580189a0fbcc46364e1ab3b47fc7c20e3767\",\n" +
|
||||
" \"items\": [\n" +
|
||||
" {\n" +
|
||||
" \"passengers\": [\n" +
|
||||
" {\n" +
|
||||
" \"cardIssuePlace\": \"\",\n" +
|
||||
" \"lastName\": \"\",\n" +
|
||||
" \"cardIssueCountry\": \"\",\n" +
|
||||
" \"shoeSize\": 0,\n" +
|
||||
" \"gender\": \"M\",\n" +
|
||||
" \"cardIssueDate\": \"\",\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"nationalityName\": \"\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"cardType\": \"1\",\n" +
|
||||
" \"weight\": 0,\n" +
|
||||
" \"myopiaDegreeL\": 0,\n" +
|
||||
" \"birthDate\": \"2025-07-10\",\n" +
|
||||
" \"cardNo\": \"620421198909185197\",\n" +
|
||||
" \"ageType\": \"ADU\",\n" +
|
||||
" \"myopiaDegreeR\": 0,\n" +
|
||||
" \"firstName\": \"sl\",\n" +
|
||||
" \"birthPlace\": \"\",\n" +
|
||||
" \"nationalityCode\": \"\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"passengerId\": \"33c0b8013a554c5c8f59e7e0fac6ef32\",\n" +
|
||||
" \"cardValidDate\": \"\",\n" +
|
||||
" \"height\": 0\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"cost\": 2.00,\n" +
|
||||
" \"quantity\": 1,\n" +
|
||||
" \"salePrice\": 2.00,\n" +
|
||||
" \"remark\": \"This is remark\",\n" +
|
||||
" \"useEndDate\": \"2025-07-25\",\n" +
|
||||
" \"locale\": \"zh-CN\",\n" +
|
||||
" \"useStartDate\": \"2025-07-25\",\n" +
|
||||
" \"priceCurrency\": \"CNY\",\n" +
|
||||
" \"adjunctions\": [],\n" +
|
||||
" \"price\": 2.00,\n" +
|
||||
" \"PLU\": \"1\",\n" +
|
||||
" \"deposit\": {},\n" +
|
||||
" \"distributionChannel\": \"XCW\",\n" +
|
||||
" \"costCurrency\": \"CNY\",\n" +
|
||||
" \"salePriceCurrency\": \"CNY\",\n" +
|
||||
" \"expressDelivery\": {\n" +
|
||||
" \"type\": \"1\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"contacts\": [\n" +
|
||||
" {\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"optionalMobile\": \"13333333333\",\n" +
|
||||
" \"optionalIntlCode\": \"86\",\n" +
|
||||
" \"email\": \"1272745473@qq.com\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
// 测试反序列化
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(testJson, CtripCreateOrderRequest.class);
|
||||
|
||||
// 验证反序列化结果
|
||||
assertNotNull(request);
|
||||
assertNotNull(request.getHeader());
|
||||
assertNotNull(request.getBody());
|
||||
assertEquals("c50a8f2a4a59c9e7", request.getHeader().getAccountId());
|
||||
assertEquals("CreatePreOrder", request.getHeader().getServiceName());
|
||||
|
||||
// 验证body是对象
|
||||
assertTrue(request.getBody() instanceof CtripCreateOrderRequest.CtripOrderBody);
|
||||
CtripCreateOrderRequest.CtripOrderBody body = (CtripCreateOrderRequest.CtripOrderBody) request.getBody();
|
||||
assertEquals("ctriptest-10816912-454259-145573", body.getOtaOrderId());
|
||||
|
||||
// 验证订单项
|
||||
assertNotNull(body.getItems());
|
||||
assertFalse(body.getItems().isEmpty());
|
||||
|
||||
CtripCreateOrderRequest.CtripOrderItem item = body.getItems().get(0);
|
||||
assertNotNull(item.getPassengers());
|
||||
assertFalse(item.getPassengers().isEmpty());
|
||||
assertEquals("李世琳", item.getPassengers().get(0).getName());
|
||||
assertEquals("18322694510", item.getPassengers().get(0).getMobile());
|
||||
assertEquals(new java.math.BigDecimal("2.00"), item.getSalePrice());
|
||||
|
||||
// 验证联系人
|
||||
assertNotNull(body.getContacts());
|
||||
assertFalse(body.getContacts().isEmpty());
|
||||
assertEquals("李世琳", body.getContacts().get(0).getName());
|
||||
assertEquals("18322694510", body.getContacts().get(0).getMobile());
|
||||
|
||||
System.out.println("订单创建测试通过!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtripCouponCreation() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试JSON - 实际的携程优惠券数据
|
||||
String testJson = "{\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"requestTime\": \"2025-08-01 22:58:01\",\n" +
|
||||
" \"accountId\": \"c50a8f2a4a59c9e7\",\n" +
|
||||
" \"sign\": \"5e8ebe775c7aaa466cd469947d6dee22\",\n" +
|
||||
" \"serviceName\": \"CreatePreOrder\",\n" +
|
||||
" \"version\": \"1.0\"\n" +
|
||||
" },\n" +
|
||||
" \"body\": {\n" +
|
||||
" \"otaOrderId\": \"ctriptest-10816912-454259-145573\",\n" +
|
||||
" \"sequenceId\": \"2025080122580189a0fbcc46364e1ab3b47fc7c20e3767\",\n" +
|
||||
" \"items\": [\n" +
|
||||
" {\n" +
|
||||
" \"passengers\": [\n" +
|
||||
" {\n" +
|
||||
" \"cardIssuePlace\": \"\",\n" +
|
||||
" \"lastName\": \"\",\n" +
|
||||
" \"cardIssueCountry\": \"\",\n" +
|
||||
" \"shoeSize\": 0,\n" +
|
||||
" \"gender\": \"M\",\n" +
|
||||
" \"cardIssueDate\": \"\",\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"nationalityName\": \"\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"cardType\": \"1\",\n" +
|
||||
" \"weight\": 0,\n" +
|
||||
" \"myopiaDegreeL\": 0,\n" +
|
||||
" \"birthDate\": \"2025-07-10\",\n" +
|
||||
" \"cardNo\": \"620421198909185197\",\n" +
|
||||
" \"ageType\": \"ADU\",\n" +
|
||||
" \"myopiaDegreeR\": 0,\n" +
|
||||
" \"firstName\": \"sl\",\n" +
|
||||
" \"birthPlace\": \"\",\n" +
|
||||
" \"nationalityCode\": \"\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"passengerId\": \"33c0b8013a554c5c8f59e7e0fac6ef32\",\n" +
|
||||
" \"cardValidDate\": \"\",\n" +
|
||||
" \"height\": 0\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"cost\": 2.00,\n" +
|
||||
" \"quantity\": 1,\n" +
|
||||
" \"salePrice\": 2.00,\n" +
|
||||
" \"remark\": \"This is remark\",\n" +
|
||||
" \"useEndDate\": \"2025-07-25\",\n" +
|
||||
" \"locale\": \"zh-CN\",\n" +
|
||||
" \"useStartDate\": \"2025-07-25\",\n" +
|
||||
" \"priceCurrency\": \"CNY\",\n" +
|
||||
" \"adjunctions\": [],\n" +
|
||||
" \"price\": 2.00,\n" +
|
||||
" \"PLU\": \"1\",\n" +
|
||||
" \"deposit\": {},\n" +
|
||||
" \"distributionChannel\": \"XCW\",\n" +
|
||||
" \"costCurrency\": \"CNY\",\n" +
|
||||
" \"salePriceCurrency\": \"CNY\",\n" +
|
||||
" \"expressDelivery\": {\n" +
|
||||
" \"type\": \"1\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"contacts\": [\n" +
|
||||
" {\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"optionalMobile\": \"13333333333\",\n" +
|
||||
" \"optionalIntlCode\": \"86\",\n" +
|
||||
" \"email\": \"1272745473@qq.com\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
// 测试反序列化
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(testJson, CtripCreateOrderRequest.class);
|
||||
|
||||
// 验证反序列化结果
|
||||
assertNotNull(request);
|
||||
assertNotNull(request.getHeader());
|
||||
assertNotNull(request.getBody());
|
||||
assertEquals("c50a8f2a4a59c9e7", request.getHeader().getAccountId());
|
||||
assertEquals("CreatePreOrder", request.getHeader().getServiceName());
|
||||
|
||||
// 验证body是对象
|
||||
assertTrue(request.getBody() instanceof CtripCreateOrderRequest.CtripOrderBody);
|
||||
CtripCreateOrderRequest.CtripOrderBody body = (CtripCreateOrderRequest.CtripOrderBody) request.getBody();
|
||||
assertEquals("ctriptest-10816912-454259-145573", body.getOtaOrderId());
|
||||
|
||||
// 验证订单项
|
||||
assertNotNull(body.getItems());
|
||||
assertFalse(body.getItems().isEmpty());
|
||||
|
||||
CtripCreateOrderRequest.CtripOrderItem item = body.getItems().get(0);
|
||||
assertNotNull(item.getPassengers());
|
||||
assertFalse(item.getPassengers().isEmpty());
|
||||
assertEquals("李世琳", item.getPassengers().get(0).getName());
|
||||
assertEquals("18322694510", item.getPassengers().get(0).getMobile());
|
||||
assertEquals(new java.math.BigDecimal("2.00"), item.getSalePrice());
|
||||
|
||||
// 验证联系人
|
||||
assertNotNull(body.getContacts());
|
||||
assertFalse(body.getContacts().isEmpty());
|
||||
assertEquals("李世琳", body.getContacts().get(0).getName());
|
||||
assertEquals("18322694510", body.getContacts().get(0).getMobile());
|
||||
|
||||
System.out.println("携程优惠券创建测试通过!");
|
||||
System.out.println("接口路径: /coupon/ctrip/create");
|
||||
System.out.println("请求方法: POST");
|
||||
System.out.println("Content-Type: application/json");
|
||||
}
|
||||
|
||||
}
|
||||
+28
-26
@@ -1,26 +1,28 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>central-platform</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</parent>
|
||||
<artifactId>zlt-business</artifactId>
|
||||
<description>业务中心</description>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<!-- 用户中心 -->
|
||||
<module>user-center</module>
|
||||
<!-- 文件中心 -->
|
||||
<module>file-center</module>
|
||||
<!-- 搜索中心 -->
|
||||
<module>search-center</module>
|
||||
|
||||
<module>device-center</module>
|
||||
|
||||
<module>order-center</module>
|
||||
|
||||
<module>device-ops-center</module>
|
||||
</modules>
|
||||
</project>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>central-platform</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</parent>
|
||||
<artifactId>zlt-business</artifactId>
|
||||
<description>业务中心</description>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<!-- 用户中心 -->
|
||||
<module>user-center</module>
|
||||
<!-- 文件中心 -->
|
||||
<module>file-center</module>
|
||||
<!-- 搜索中心 -->
|
||||
<module>search-center</module>
|
||||
|
||||
<module>device-center</module>
|
||||
|
||||
<module>order-center</module>
|
||||
|
||||
<module>device-ops-center</module>
|
||||
<!-- 优惠券中心 -->
|
||||
<module>coupon-center</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
||||
@@ -85,6 +85,12 @@ spring:
|
||||
- Path=/api-order/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: coupon
|
||||
uri: lb://coupon-center
|
||||
predicates:
|
||||
- Path=/api-coupon/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
# sentinel:
|
||||
# datasource.ds1.nacos:
|
||||
# server-addr: ${spring.cloud.nacos.server-addr}
|
||||
@@ -127,6 +133,10 @@ knife4j:
|
||||
service-name: device-ops-center
|
||||
url: /api-device-ops/v3/api-docs/default
|
||||
context-path: /api-device-ops
|
||||
- name: 优惠券服务
|
||||
service-name: coupon-center
|
||||
url: /api-coupon/v3/api-docs/default
|
||||
context-path: /api-coupon
|
||||
|
||||
zlt:
|
||||
security:
|
||||
@@ -155,7 +165,7 @@ zlt:
|
||||
/api-file/file/expires,
|
||||
/api-order/refund/auto,
|
||||
/api-order/files/exists/**,
|
||||
/api-order/coupon/ctrip/create
|
||||
/api-coupon/coupon/ctrip/create
|
||||
auth:
|
||||
urlPermission:
|
||||
#是否开启url级别权限
|
||||
|
||||
-175
@@ -1,175 +0,0 @@
|
||||
# 优惠券管理功能说明
|
||||
|
||||
## 功能概述
|
||||
|
||||
根据携程优惠券兑换流程图,实现了完整的优惠券管理功能,包括:
|
||||
|
||||
1. **优惠券基础管理**:创建、编辑、删除、查询优惠券
|
||||
2. **携程集成**:携程创建优惠券接口、核销接口
|
||||
3. **用户优惠券查询**:根据手机号查询用户优惠券
|
||||
4. **自动过期处理**:定时任务自动更新过期优惠券状态
|
||||
|
||||
## 数据库设计
|
||||
|
||||
### 优惠券表 (t_coupon)
|
||||
|
||||
| 字段名 | 类型 | 说明 |
|
||||
|--------|------|------|
|
||||
| id | bigint | 主键ID |
|
||||
| coupon_no | varchar(64) | 优惠券编号(唯一) |
|
||||
| coupon_name | varchar(128) | 优惠券名称 |
|
||||
| coupon_type | int | 优惠券类型:1-满减券,2-折扣券,3-免费券 |
|
||||
| amount | decimal(10,2) | 优惠券面额 |
|
||||
| min_amount | decimal(10,2) | 使用门槛金额 |
|
||||
| discount_rate | int | 折扣率(0-100,折扣券时使用) |
|
||||
| status | int | 优惠券状态:0-未使用,1-已使用,2-已过期,3-已作废 |
|
||||
| user_phone | varchar(20) | 用户手机号 |
|
||||
| user_id | bigint | 用户ID |
|
||||
| source | int | 来源:1-携程,2-高飞自建 |
|
||||
| ctrip_coupon_id | varchar(64) | 携程优惠券ID(来源为携程时使用) |
|
||||
| valid_start_time | datetime | 有效期开始时间 |
|
||||
| valid_end_time | datetime | 有效期结束时间 |
|
||||
| used_time | datetime | 使用时间 |
|
||||
| used_order_no | varchar(64) | 使用订单号 |
|
||||
| create_time | datetime | 创建时间 |
|
||||
| update_time | datetime | 更新时间 |
|
||||
| create_by | varchar(64) | 创建人 |
|
||||
| update_by | varchar(64) | 更新人 |
|
||||
| remark | varchar(255) | 备注 |
|
||||
| tenant_id | varchar(64) | 租户ID |
|
||||
|
||||
## 后端API接口
|
||||
|
||||
### 1. 优惠券基础管理
|
||||
|
||||
- `GET /api-order/coupon/page` - 分页查询优惠券列表
|
||||
- `GET /api-order/coupon/{id}` - 根据ID查询优惠券
|
||||
- `POST /api-order/coupon` - 创建优惠券
|
||||
- `PUT /api-order/coupon/{id}` - 更新优惠券
|
||||
- `DELETE /api-order/coupon/{id}` - 删除优惠券
|
||||
|
||||
### 2. 用户优惠券查询
|
||||
|
||||
- `GET /api-order/coupon/user/{userPhone}` - 根据手机号查询用户优惠券
|
||||
- `GET /api-order/coupon/user/{userPhone}/available` - 根据手机号查询可用优惠券
|
||||
|
||||
### 3. 优惠券使用
|
||||
|
||||
- `POST /api-order/coupon/{id}/use` - 使用优惠券
|
||||
|
||||
### 4. 携程集成接口
|
||||
|
||||
- `POST /api-order/coupon/ctrip/create` - 携程创建优惠券接口
|
||||
- `POST /api-order/coupon/ctrip/verify` - 核销携程优惠券
|
||||
|
||||
### 5. 系统管理
|
||||
|
||||
- `POST /api-order/coupon/update-expired` - 批量更新过期优惠券
|
||||
|
||||
## 前端功能
|
||||
|
||||
### 优惠券管理页面
|
||||
|
||||
位置:`/pages/orders/CouponManagement.tsx`
|
||||
|
||||
功能:
|
||||
- 优惠券列表展示(支持分页、筛选)
|
||||
- 新增优惠券
|
||||
- 编辑优惠券
|
||||
- 删除优惠券
|
||||
- 查看优惠券详情
|
||||
|
||||
### 主要特性
|
||||
|
||||
1. **响应式表格**:支持横向滚动,适配不同屏幕尺寸
|
||||
2. **智能表单**:根据优惠券类型动态显示不同字段
|
||||
3. **状态管理**:不同状态用不同颜色标签显示
|
||||
4. **时间处理**:使用moment.js处理时间格式化
|
||||
|
||||
## 业务流程
|
||||
|
||||
### 1. 携程优惠券创建流程
|
||||
|
||||
```
|
||||
用户在携程购券 → 携程调用高飞创建优惠券接口 → 高飞创建本地优惠券记录
|
||||
```
|
||||
|
||||
### 2. 用户下单优惠券使用流程
|
||||
|
||||
```
|
||||
用户扫码进入下单页 → 查询用户绑定手机号 → 通过手机号查询高飞用户优惠券记录 →
|
||||
有可用优惠券自动带出 → 用户选择是否核销 → 调用携程核销接口 → 进入支付流程
|
||||
```
|
||||
|
||||
### 3. 优惠券过期处理流程
|
||||
|
||||
```
|
||||
定时任务每天凌晨2点执行 → 查询所有未使用且已过期的优惠券 → 批量更新状态为已过期
|
||||
```
|
||||
|
||||
## 定时任务
|
||||
|
||||
### 优惠券过期处理任务
|
||||
|
||||
- **类名**:`CouponExpirationTask`
|
||||
- **执行时间**:每天凌晨2点
|
||||
- **功能**:批量更新过期优惠券状态
|
||||
|
||||
## 携程API集成
|
||||
|
||||
### 携程API服务
|
||||
|
||||
- **接口**:`ICtripApiService`
|
||||
- **实现**:`CtripApiServiceImpl`
|
||||
|
||||
### 待实现功能
|
||||
|
||||
1. **核销接口**:`verifyCoupon(String ctripCouponId, String orderNo)`
|
||||
2. **状态查询**:`getCouponStatus(String ctripCouponId)`
|
||||
|
||||
### 集成说明
|
||||
|
||||
目前携程API调用为模拟实现,需要根据携程提供的API文档进行实际集成:
|
||||
|
||||
1. 配置携程API密钥和接口地址
|
||||
2. 实现HTTP客户端调用
|
||||
3. 处理API响应和错误
|
||||
4. 添加重试机制和日志记录
|
||||
|
||||
## 部署说明
|
||||
|
||||
### 1. 数据库迁移
|
||||
|
||||
执行 `database_migration.sql` 中的优惠券表创建语句。
|
||||
|
||||
### 2. 后端部署
|
||||
|
||||
确保以下组件已正确配置:
|
||||
- MyBatis Plus配置
|
||||
- 定时任务配置(@EnableScheduling)
|
||||
- 数据库连接配置
|
||||
|
||||
### 3. 前端部署
|
||||
|
||||
确保以下依赖已安装:
|
||||
- Ant Design
|
||||
- moment.js
|
||||
- TypeScript类型定义
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **优惠券编号唯一性**:系统自动生成优惠券编号,确保唯一性
|
||||
2. **携程优惠券ID唯一性**:同一携程优惠券ID只能创建一次
|
||||
3. **时间处理**:所有时间字段使用UTC时间存储
|
||||
4. **状态管理**:优惠券状态变更需要记录操作日志
|
||||
5. **API安全**:携程集成接口需要添加适当的认证和授权
|
||||
|
||||
## 扩展功能
|
||||
|
||||
### 可扩展的功能点
|
||||
|
||||
1. **优惠券模板**:支持创建优惠券模板,批量生成优惠券
|
||||
2. **优惠券统计**:优惠券使用情况统计和分析
|
||||
3. **优惠券推送**:向用户推送优惠券到期提醒
|
||||
4. **优惠券分享**:支持优惠券分享功能
|
||||
5. **多平台集成**:支持其他平台的优惠券集成
|
||||
-199
@@ -1,199 +0,0 @@
|
||||
# 微信平台证书序列号配置说明
|
||||
|
||||
## 概述
|
||||
|
||||
在微信支付回调中,微信会通过请求头 `Wechatpay-Serial` 传递平台证书的序列号,用于验证回调请求的签名。为了支持多个平台证书的场景,系统新增了 `serialNumber` 字段来存储微信平台证书的序列号。
|
||||
|
||||
## 字段说明
|
||||
|
||||
### serialNumber 字段
|
||||
- **用途**: 存储微信平台证书的序列号
|
||||
- **来源**: 微信支付回调请求头中的 `Wechatpay-Serial` 字段
|
||||
- **作用**: 用于快速定位对应的微信配置信息
|
||||
- **支持**: 一个商户可以配置多个平台证书,通过序列号区分
|
||||
|
||||
## 配置流程
|
||||
|
||||
### 1. 获取微信平台证书序列号
|
||||
|
||||
#### 方法一:通过微信支付API获取
|
||||
```bash
|
||||
# 获取平台证书列表
|
||||
curl -X GET "https://api.mch.weixin.qq.com/v3/certificates" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Authorization: WECHATPAY2-SHA256-RSA2048 ..."
|
||||
```
|
||||
|
||||
响应示例:
|
||||
```json
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"serial_no": "5157F09EFDC096DE15EBE81A47057A7232F1B8E1",
|
||||
"effective_time": "2018-06-08T10:34:56+08:00",
|
||||
"expire_time": "2023-06-08T10:34:56+08:00",
|
||||
"encrypt_certificate": {
|
||||
"algorithm": "AEAD_AES_256_GCM",
|
||||
"nonce": "61f9c719728a",
|
||||
"associated_data": "certificate",
|
||||
"ciphertext": "..."
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### 方法二:从回调请求头获取
|
||||
在微信支付回调时,请求头中会包含:
|
||||
```
|
||||
Wechatpay-Serial: 5157F09EFDC096DE15EBE81A47057A7232F1B8E1
|
||||
```
|
||||
|
||||
### 2. 配置到系统
|
||||
|
||||
#### 通过管理后台配置
|
||||
1. 登录管理后台
|
||||
2. 进入"微信配置管理"
|
||||
3. 选择对应的租户和配置类型
|
||||
4. 在"微信平台证书序列号"字段中填入获取到的序列号
|
||||
5. 保存配置
|
||||
|
||||
#### 通过API配置
|
||||
```http
|
||||
PUT /wechat/config
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"id": 1,
|
||||
"tenantId": "webApp",
|
||||
"type": "PAY",
|
||||
"serialNumber": "5157F09EFDC096DE15EBE81A47057A7232F1B8E1",
|
||||
"merchantId": "1900000109",
|
||||
"appId": "wx1234567890abcdef",
|
||||
"mchSerialNo": "1234567890ABCDEF",
|
||||
"privateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
|
||||
"apiV3Key": "your_api_v3_key",
|
||||
"notifyUrl": "https://your.domain.com/notify",
|
||||
"status": 1
|
||||
}
|
||||
```
|
||||
|
||||
## 回调处理流程
|
||||
|
||||
### 1. 接收回调请求
|
||||
```java
|
||||
@PostMapping("/pay/notify")
|
||||
public String handleCallback(@RequestHeader("Wechatpay-Signature") String signature,
|
||||
@RequestHeader("Wechatpay-Timestamp") String timestamp,
|
||||
@RequestHeader("Wechatpay-Nonce") String nonce,
|
||||
@RequestHeader("Wechatpay-Serial") String serial,
|
||||
@RequestBody String body) {
|
||||
// serial 参数就是微信平台证书的序列号
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 根据序列号获取配置
|
||||
```java
|
||||
// 根据证书序列号获取配置
|
||||
WechatConfig config = wechatConfigService.getConfigBySerialNumber(serial);
|
||||
if (config == null) {
|
||||
log.error("未找到对应的微信配置,序列号: {}", serial);
|
||||
return "{\"code\":\"FAIL\",\"message\":\"配置不存在\"}";
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 验证回调签名
|
||||
```java
|
||||
// 创建通知解析器
|
||||
NotificationParser notificationParser = wxPayConfigFactory.createNotificationParser(config.getTenantId());
|
||||
|
||||
// 构建请求参数
|
||||
RequestParam requestParam = new RequestParam
|
||||
.Builder()
|
||||
.body(body)
|
||||
.nonce(nonce)
|
||||
.signature(signature)
|
||||
.serialNumber(serial) // 使用平台证书序列号
|
||||
.timestamp(timestamp)
|
||||
.build();
|
||||
|
||||
// 解析通知
|
||||
Transaction transaction = notificationParser.parse(requestParam, Transaction.class);
|
||||
```
|
||||
|
||||
## 多证书支持
|
||||
|
||||
### 场景说明
|
||||
当一个商户需要支持多个平台证书时(例如证书轮换),可以通过配置多个 `serialNumber` 来支持:
|
||||
|
||||
### 配置示例
|
||||
```json
|
||||
{
|
||||
"id": 1,
|
||||
"tenantId": "webApp",
|
||||
"type": "PAY",
|
||||
"serialNumber": "5157F09EFDC096DE15EBE81A47057A7232F1B8E1",
|
||||
"merchantId": "1900000109",
|
||||
"appId": "wx1234567890abcdef",
|
||||
"status": 1
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"id": 2,
|
||||
"tenantId": "webApp",
|
||||
"type": "PAY",
|
||||
"serialNumber": "5157F09EFDC096DE15EBE81A47057A7232F1B8E2",
|
||||
"merchantId": "1900000109",
|
||||
"appId": "wx1234567890abcdef",
|
||||
"status": 1
|
||||
}
|
||||
```
|
||||
|
||||
### 处理逻辑
|
||||
系统会根据回调请求中的 `Wechatpay-Serial` 自动匹配对应的配置:
|
||||
|
||||
```java
|
||||
@Override
|
||||
public WechatConfig getConfigBySerialNumber(String serialNumber) {
|
||||
return getOne(new LambdaQueryWrapper<WechatConfig>()
|
||||
.eq(WechatConfig::getSerialNumber, serialNumber)
|
||||
.eq(WechatConfig::getStatus, 1));
|
||||
}
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
### 1. 证书有效期
|
||||
- 微信平台证书有有效期限制
|
||||
- 需要在证书过期前更新配置
|
||||
- 建议配置证书过期提醒
|
||||
|
||||
### 2. 序列号唯一性
|
||||
- 每个平台证书的序列号是唯一的
|
||||
- 同一租户下不能配置重复的序列号
|
||||
- 建议在配置时进行唯一性校验
|
||||
|
||||
### 3. 配置验证
|
||||
- 配置完成后建议进行测试
|
||||
- 可以通过模拟回调请求验证配置是否正确
|
||||
- 确保回调处理逻辑能正常工作
|
||||
|
||||
### 4. 日志记录
|
||||
- 建议记录证书序列号的使用情况
|
||||
- 便于排查问题和监控系统状态
|
||||
- 可以统计各证书的使用频率
|
||||
|
||||
## 错误处理
|
||||
|
||||
### 常见错误
|
||||
1. **配置不存在**: 回调请求中的序列号在系统中找不到对应配置
|
||||
2. **证书过期**: 使用的平台证书已过期
|
||||
3. **签名验证失败**: 回调请求的签名验证失败
|
||||
|
||||
### 处理建议
|
||||
1. 记录详细的错误日志
|
||||
2. 提供配置检查工具
|
||||
3. 实现自动化的证书更新机制
|
||||
4. 建立监控告警机制
|
||||
-133
@@ -1,133 +0,0 @@
|
||||
# 携程优惠券对接接口文档
|
||||
|
||||
本文件描述我方对接携程的优惠券相关接口,包括创建、取消、核销等业务场景。
|
||||
|
||||
---
|
||||
|
||||
## 1. 创建用户优惠券接口
|
||||
|
||||
- **接口地址**:`POST /coupon/ctrip/create`
|
||||
- **用途**:携程下单后回调,创建用户优惠券(手机号+携程券ID唯一,幂等)。
|
||||
- **请求参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|----------------|-----------|------|------------------------|
|
||||
| ctripCouponId | string | 是 | 携程券ID(唯一) |
|
||||
| userPhone | string | 是 | 用户手机号 |
|
||||
| couponName | string | 是 | 优惠券名称 |
|
||||
| couponType | integer | 是 | 优惠券类型 |
|
||||
| amount | number | 是 | 优惠券面额 |
|
||||
| minAmount | number | 否 | 使用门槛金额 |
|
||||
| discountRate | integer | 否 | 折扣率 |
|
||||
| validStartTime | string | 是 | 有效期开始时间(yyyy-MM-dd或yyyy-MM-dd HH:mm:ss)|
|
||||
| validEndTime | string | 是 | 有效期结束时间(yyyy-MM-dd或yyyy-MM-dd HH:mm:ss)|
|
||||
|
||||
- **返回示例**:
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"data": true,
|
||||
"resp_msg": "success"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. 取消用户优惠券接口
|
||||
|
||||
- **接口地址**:`POST /coupon/ctrip/cancel`
|
||||
- **用途**:携程退券回调,取消用户优惠券(默认退第一个未用券)。
|
||||
- **请求参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|-----------|--------|------|-----------|
|
||||
| userPhone | string | 是 | 用户手机号 |
|
||||
|
||||
- **返回示例**:
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"data": true,
|
||||
"resp_msg": "success"
|
||||
}
|
||||
```
|
||||
如无可退券:
|
||||
```json
|
||||
{
|
||||
"code": 1,
|
||||
"data": null,
|
||||
"resp_msg": "无可退优惠券"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. 核销用户优惠券接口
|
||||
|
||||
- **接口地址**:`POST /coupon/ctrip/verify`
|
||||
- **用途**:用户下单时,先查本地券,再调用携程核销接口,核销成功后本地状态设为已用。
|
||||
- **请求参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|-----------|--------|------|-----------|
|
||||
| userPhone | string | 是 | 用户手机号 |
|
||||
| orderNo | string | 是 | 订单号 |
|
||||
|
||||
- **返回示例**:
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"data": true,
|
||||
"resp_msg": "success"
|
||||
}
|
||||
```
|
||||
如无可用券或核销失败:
|
||||
```json
|
||||
{
|
||||
"code": 1,
|
||||
"data": null,
|
||||
"resp_msg": "无可用优惠券" // 或 "携程核销失败"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. 业务说明
|
||||
|
||||
- **幂等性**:所有接口均需保证幂等,创建时手机号+携程券ID唯一。
|
||||
- **状态同步**:本地与携程券状态需保持一致。
|
||||
- **时间格式**:支持`yyyy-MM-dd`或`yyyy-MM-dd HH:mm:ss`。
|
||||
- **安全性**:建议所有接口加签名校验。
|
||||
- **返回结构**:统一为 `{ code, data, resp_msg }`,便于携程方解析。
|
||||
|
||||
---
|
||||
|
||||
## 5. 示例请求
|
||||
|
||||
### 创建优惠券
|
||||
```http
|
||||
POST /coupon/ctrip/create
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
ctripCouponId=CT123456&userPhone=13800000000&couponName=xxx&couponType=1&amount=100&validStartTime=2024-05-01&validEndTime=2024-06-01
|
||||
```
|
||||
|
||||
### 取消优惠券
|
||||
```http
|
||||
POST /coupon/ctrip/cancel
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
userPhone=13800000000
|
||||
```
|
||||
|
||||
### 核销优惠券
|
||||
```http
|
||||
POST /coupon/ctrip/verify
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
userPhone=13800000000&orderNo=ORDER123
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
如需OpenAPI YAML、签名校验、错误码说明等补充,请联系技术支持。
|
||||
-255
@@ -1,255 +0,0 @@
|
||||
# 携程标准响应码说明
|
||||
|
||||
## 概述
|
||||
|
||||
根据[携程API平台标准](https://open.trip.com/apiplatform/order.jsp#tag/%E8%BF%94%E5%9B%9E%E7%A0%81),我方接口需要返回标准的响应码,只有返回正确的响应码,携程方才能做对应的逻辑处理。
|
||||
|
||||
## 响应码分类
|
||||
|
||||
### 1. 成功响应码
|
||||
- **0000** - 操作成功
|
||||
- 说明:请求处理成功,业务逻辑正常执行
|
||||
- 使用场景:订单创建成功、优惠券创建成功、核销成功等
|
||||
|
||||
### 2. 系统错误码 (1000-1999)
|
||||
|
||||
#### 1000 - 系统错误
|
||||
- 说明:系统内部错误,无法处理的异常
|
||||
- 使用场景:数据库连接失败、系统崩溃等
|
||||
|
||||
#### 1001 - 参数错误
|
||||
- 说明:请求参数格式错误或缺少必要参数
|
||||
- 使用场景:缺少手机号、订单号格式错误等
|
||||
|
||||
#### 1002 - 签名验证失败
|
||||
- 说明:请求签名验证失败
|
||||
- 使用场景:签名算法错误、密钥不匹配等
|
||||
|
||||
#### 1003 - 时间戳错误
|
||||
- 说明:请求时间戳无效或过期
|
||||
- 使用场景:请求时间超出允许范围
|
||||
|
||||
#### 1004 - 版本号错误
|
||||
- 说明:API版本号不支持
|
||||
- 使用场景:携程使用旧版本API调用新版本接口
|
||||
|
||||
### 3. 业务错误码 (2000-2999)
|
||||
|
||||
#### 2000 - 订单不存在
|
||||
- 说明:请求的订单在系统中不存在
|
||||
- 使用场景:查询不存在的订单
|
||||
|
||||
#### 2001 - 订单已存在
|
||||
- 说明:订单已存在,重复创建
|
||||
- 使用场景:幂等性校验失败
|
||||
|
||||
#### 2002 - 订单状态错误
|
||||
- 说明:订单状态不允许当前操作
|
||||
- 使用场景:已取消订单无法核销
|
||||
|
||||
#### 2003 - 优惠券不存在
|
||||
- 说明:请求的优惠券不存在
|
||||
- 使用场景:查询不存在的优惠券
|
||||
|
||||
#### 2004 - 优惠券已使用
|
||||
- 说明:优惠券已被使用,无法重复使用
|
||||
- 使用场景:核销已使用的优惠券
|
||||
|
||||
#### 2005 - 优惠券已过期
|
||||
- 说明:优惠券已超过有效期
|
||||
- 使用场景:使用过期优惠券
|
||||
|
||||
#### 2006 - 优惠券余额不足
|
||||
- 说明:优惠券余额不足以支付订单
|
||||
- 使用场景:部分支付场景
|
||||
|
||||
#### 2007 - 用户不存在
|
||||
- 说明:请求的用户在系统中不存在
|
||||
- 使用场景:查询不存在的用户
|
||||
|
||||
#### 2008 - 产品不存在
|
||||
- 说明:请求的产品不存在
|
||||
- 使用场景:查询不存在的产品
|
||||
|
||||
#### 2009 - 产品不可用
|
||||
- 说明:产品当前不可用
|
||||
- 使用场景:产品已下架或库存不足
|
||||
|
||||
### 4. 网络错误码 (3000-3999)
|
||||
|
||||
#### 3000 - 网络连接错误
|
||||
- 说明:网络连接异常
|
||||
- 使用场景:网络超时、连接中断等
|
||||
|
||||
#### 3001 - 请求超时
|
||||
- 说明:请求处理超时
|
||||
- 使用场景:长时间未响应的请求
|
||||
|
||||
#### 3002 - 服务不可用
|
||||
- 说明:服务暂时不可用
|
||||
- 使用场景:服务维护、负载过高
|
||||
|
||||
### 5. 权限错误码 (4000-4999)
|
||||
|
||||
#### 4000 - 未授权访问
|
||||
- 说明:请求未通过身份验证
|
||||
- 使用场景:缺少认证信息
|
||||
|
||||
#### 4001 - 访问被拒绝
|
||||
- 说明:请求被拒绝访问
|
||||
- 使用场景:权限不足
|
||||
|
||||
#### 4002 - 账户已禁用
|
||||
- 说明:账户已被禁用
|
||||
- 使用场景:违规账户
|
||||
|
||||
### 6. 数据错误码 (5000-5999)
|
||||
|
||||
#### 5000 - 数据不存在
|
||||
- 说明:请求的数据不存在
|
||||
- 使用场景:查询不存在的数据
|
||||
|
||||
#### 5001 - 数据格式错误
|
||||
- 说明:数据格式不符合要求
|
||||
- 使用场景:JSON格式错误、编码问题
|
||||
|
||||
#### 5002 - 数据冲突
|
||||
- 说明:数据存在冲突
|
||||
- 使用场景:并发操作冲突
|
||||
|
||||
### 7. 第三方服务错误码 (6000-6999)
|
||||
|
||||
#### 6000 - 第三方服务错误
|
||||
- 说明:第三方服务调用失败
|
||||
- 使用场景:支付服务、短信服务等
|
||||
|
||||
#### 6001 - 支付服务错误
|
||||
- 说明:支付服务异常
|
||||
- 使用场景:支付失败、退款失败
|
||||
|
||||
#### 6002 - 短信服务错误
|
||||
- 说明:短信服务异常
|
||||
- 使用场景:验证码发送失败
|
||||
|
||||
#### 6003 - 邮件服务错误
|
||||
- 说明:邮件服务异常
|
||||
- 使用场景:邮件发送失败
|
||||
|
||||
## 响应格式
|
||||
|
||||
### 成功响应格式
|
||||
```json
|
||||
{
|
||||
"header": {
|
||||
"requestTime": "2024-12-19 10:30:00",
|
||||
"accountId": "ctrip_account",
|
||||
"sign": "signature",
|
||||
"serviceName": "CreateOrder",
|
||||
"version": "1.0"
|
||||
},
|
||||
"resultCode": "0000",
|
||||
"resultMessage": "操作成功",
|
||||
"body": {
|
||||
"otaOrderId": "CT123456",
|
||||
"supplierOrderId": "COUPON_1734567890123",
|
||||
"supplierConfirmType": 1,
|
||||
"voucherSender": 1,
|
||||
"orderExtendMessage": "优惠券创建成功",
|
||||
"items": [
|
||||
{
|
||||
"itemId": "1",
|
||||
"supplierItemId": "COUPON_ITEM_1734567890123",
|
||||
"status": 1,
|
||||
"message": "优惠券创建成功"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 错误响应格式
|
||||
```json
|
||||
{
|
||||
"header": {
|
||||
"requestTime": "2024-12-19 10:30:00",
|
||||
"accountId": "ctrip_account",
|
||||
"sign": "signature",
|
||||
"serviceName": "CreateOrder",
|
||||
"version": "1.0"
|
||||
},
|
||||
"resultCode": "1001",
|
||||
"resultMessage": "参数错误"
|
||||
}
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 1. 优惠券创建成功
|
||||
```java
|
||||
// 使用标准工具类构建响应
|
||||
CtripCreateOrderResponse response = CtripResponseCodeUtil.buildCreateOrderSuccessResponse(
|
||||
request,
|
||||
"CT123456",
|
||||
"COUPON_1734567890123",
|
||||
"优惠券创建成功"
|
||||
);
|
||||
```
|
||||
|
||||
### 2. 参数错误
|
||||
```java
|
||||
// 使用标准错误码
|
||||
CtripCreateOrderResponse response = CtripResponseCodeUtil.buildCreateOrderErrorResponse(
|
||||
request,
|
||||
CtripResponseCodeUtil.CtripResponseCodes.PARAM_ERROR,
|
||||
CtripResponseCodeUtil.CtripResponseCodes.PARAM_ERROR_MESSAGE
|
||||
);
|
||||
```
|
||||
|
||||
### 3. 异常处理
|
||||
```java
|
||||
try {
|
||||
// 业务逻辑
|
||||
} catch (Exception e) {
|
||||
String resultCode = CtripResponseCodeUtil.getResultCodeByException(e);
|
||||
String resultMessage = CtripResponseCodeUtil.getResultMessageByException(e);
|
||||
return CtripResponseCodeUtil.buildCreateOrderErrorResponse(request, resultCode, resultMessage);
|
||||
}
|
||||
```
|
||||
|
||||
## 验证规则
|
||||
|
||||
### 1. 响应码格式验证
|
||||
- 必须为4位数字字符串
|
||||
- 范围:0000-9999
|
||||
- 不能为空或null
|
||||
|
||||
### 2. 响应码分类验证
|
||||
```java
|
||||
String category = CtripResponseCodeUtil.getResponseCodeCategory("1001");
|
||||
// 返回: "SYSTEM_ERROR"
|
||||
```
|
||||
|
||||
### 3. 响应码有效性验证
|
||||
```java
|
||||
boolean isValid = CtripResponseCodeUtil.isValidResponseCode("1001");
|
||||
// 返回: true
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **标准性**:必须严格按照携程API平台标准返回响应码
|
||||
2. **一致性**:所有携程相关接口都应使用统一的响应码
|
||||
3. **可读性**:错误消息应该清晰明确,便于问题定位
|
||||
4. **日志记录**:所有响应都应该记录日志,便于问题追踪
|
||||
5. **异常处理**:系统异常应该映射到合适的标准响应码
|
||||
|
||||
## 工具类使用
|
||||
|
||||
项目已提供 `CtripResponseCodeUtil` 工具类,包含:
|
||||
|
||||
- 标准响应码定义
|
||||
- 响应构建方法
|
||||
- 异常映射方法
|
||||
- 验证方法
|
||||
|
||||
建议所有携程相关接口都使用此工具类来确保响应码的标准性和一致性。
|
||||
-240
@@ -1,240 +0,0 @@
|
||||
# 微信支付服务商模式配置说明
|
||||
|
||||
## 概述
|
||||
|
||||
本项目支持微信支付服务商模式,允许一个服务商对应多个子商户,适用于景区、连锁店等场景。
|
||||
|
||||
## 配置管理
|
||||
|
||||
### 1. 数据库配置
|
||||
|
||||
执行数据库迁移脚本 `database_migration.sql`,为 `wechat_config` 表添加服务商模式相关字段:
|
||||
|
||||
```sql
|
||||
-- 添加服务商模式标识字段
|
||||
ALTER TABLE wechat_config ADD COLUMN is_service_mode TINYINT(1) DEFAULT 0 COMMENT '是否服务商模式:0-普通商户,1-服务商';
|
||||
|
||||
-- 添加服务商相关字段
|
||||
ALTER TABLE wechat_config ADD COLUMN service_app_id VARCHAR(64) COMMENT '服务商应用ID';
|
||||
ALTER TABLE wechat_config ADD COLUMN service_mch_id VARCHAR(32) COMMENT '服务商商户号';
|
||||
|
||||
-- 添加子商户相关字段
|
||||
ALTER TABLE wechat_config ADD COLUMN sub_mch_id VARCHAR(32) COMMENT '子商户号';
|
||||
ALTER TABLE wechat_config ADD COLUMN sub_app_id VARCHAR(64) COMMENT '子商户应用ID';
|
||||
ALTER TABLE wechat_config ADD COLUMN sub_mch_name VARCHAR(128) COMMENT '子商户名称';
|
||||
ALTER TABLE wechat_config ADD COLUMN sub_mch_description VARCHAR(255) COMMENT '子商户描述';
|
||||
```
|
||||
|
||||
### 2. 配置数据结构
|
||||
|
||||
#### 普通商户模式配置
|
||||
```json
|
||||
{
|
||||
"id": 1,
|
||||
"tenantId": "webApp",
|
||||
"type": "PAY",
|
||||
"isServiceMode": false,
|
||||
"merchantId": "1900000109",
|
||||
"appId": "wx1234567890abcdef",
|
||||
"appSecret": "your_app_secret",
|
||||
"mchSerialNo": "1234567890ABCDEF",
|
||||
"privateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
|
||||
"apiV3Key": "your_api_v3_key",
|
||||
"notifyUrl": "https://your.domain.com/notify",
|
||||
"status": 1
|
||||
}
|
||||
```
|
||||
|
||||
#### 服务商模式配置
|
||||
```json
|
||||
{
|
||||
"id": 2,
|
||||
"tenantId": "webApp",
|
||||
"type": "PAY",
|
||||
"isServiceMode": true,
|
||||
"serviceAppId": "wx1234567890abcdef",
|
||||
"serviceMchId": "1900000109",
|
||||
"subMchId": "1900000109",
|
||||
"subAppId": "wx1234567890abcdef",
|
||||
"subMchName": "测试子商户",
|
||||
"subMchDescription": "测试子商户描述",
|
||||
"mchSerialNo": "1234567890ABCDEF",
|
||||
"privateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
|
||||
"apiV3Key": "your_api_v3_key",
|
||||
"notifyUrl": "https://your.domain.com/notify",
|
||||
"status": 1
|
||||
}
|
||||
```
|
||||
|
||||
## 支付流程
|
||||
|
||||
### 1. 支付请求创建
|
||||
|
||||
当用户扫描景区二维码时,系统会根据二维码中的租户信息获取对应的支付配置:
|
||||
|
||||
```java
|
||||
// 获取支付配置
|
||||
WechatConfig payConfig = configService.getConfig("PAY", qrCode.getTenantId());
|
||||
|
||||
// 根据是否为服务商模式设置不同的支付参数
|
||||
if (Boolean.TRUE.equals(payConfig.getIsServiceMode())) {
|
||||
// 服务商模式:使用服务商appid和mchid,设置子商户信息
|
||||
request.setAppid(payConfig.getServiceAppId());
|
||||
request.setMchid(payConfig.getServiceMchId());
|
||||
|
||||
// 设置子商户信息(需要根据微信支付SDK版本确定正确的类名)
|
||||
// SubMerchant subMerchant = new SubMerchant();
|
||||
// subMerchant.setMchid(payConfig.getSubMchId());
|
||||
// request.setSubMerchant(subMerchant);
|
||||
} else {
|
||||
// 普通商户模式:使用商户appid和mchid
|
||||
request.setAppid(payConfig.getAppId());
|
||||
request.setMchid(payConfig.getMerchantId());
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 支付服务创建
|
||||
|
||||
系统会根据配置模式创建对应的支付服务:
|
||||
|
||||
```java
|
||||
// 创建对应的支付服务
|
||||
JsapiServiceExtension jsapiService;
|
||||
if (Boolean.TRUE.equals(payConfig.getIsServiceMode())) {
|
||||
// 服务商模式:根据子商户号创建支付服务
|
||||
jsapiService = wxPayConfigFactory.createJsapiServiceBySubMchId(payConfig.getSubMchId());
|
||||
} else {
|
||||
// 普通商户模式:根据租户ID创建支付服务
|
||||
jsapiService = wxPayConfigFactory.createJsapiService(qrCode.getTenantId());
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 回调处理
|
||||
|
||||
支付回调会根据证书序列号识别对应的配置,并创建相应的通知解析器:
|
||||
|
||||
```java
|
||||
// 根据证书序列号获取配置
|
||||
WechatConfig config = wechatConfigService.getConfigBySerialNumber(serial);
|
||||
|
||||
// 创建通知解析器
|
||||
NotificationParser notificationParser;
|
||||
if (Boolean.TRUE.equals(config.getIsServiceMode())) {
|
||||
// 服务商模式:根据子商户号创建通知解析器
|
||||
notificationParser = wxPayConfigFactory.createNotificationParserBySubMchId(config.getSubMchId());
|
||||
} else {
|
||||
// 普通商户模式:根据租户ID创建通知解析器
|
||||
notificationParser = wxPayConfigFactory.createNotificationParser(tenantId);
|
||||
}
|
||||
```
|
||||
|
||||
## API接口
|
||||
|
||||
### 1. 配置管理接口
|
||||
|
||||
#### 获取服务商配置
|
||||
```http
|
||||
GET /wechat/config/service/{tenantId}
|
||||
```
|
||||
|
||||
#### 根据子商户号查询配置
|
||||
```http
|
||||
GET /wechat/config/sub/{subMchId}
|
||||
```
|
||||
|
||||
#### 获取指定服务商下的所有子商户配置
|
||||
```http
|
||||
GET /wechat/config/submerchants/{serviceMchId}
|
||||
```
|
||||
|
||||
#### 保存服务商配置
|
||||
```http
|
||||
POST /wechat/config/service
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"tenantId": "webApp",
|
||||
"type": "PAY",
|
||||
"isServiceMode": true,
|
||||
"serviceAppId": "wx1234567890abcdef",
|
||||
"serviceMchId": "1900000109",
|
||||
"subMchId": "1900000109",
|
||||
"subAppId": "wx1234567890abcdef",
|
||||
"subMchName": "测试子商户",
|
||||
"subMchDescription": "测试子商户描述",
|
||||
"mchSerialNo": "1234567890ABCDEF",
|
||||
"privateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
|
||||
"apiV3Key": "your_api_v3_key",
|
||||
"notifyUrl": "https://your.domain.com/notify",
|
||||
"status": 1
|
||||
}
|
||||
```
|
||||
|
||||
#### 保存子商户配置
|
||||
```http
|
||||
POST /wechat/config/submerchant
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"tenantId": "webApp",
|
||||
"type": "PAY",
|
||||
"isServiceMode": true,
|
||||
"serviceAppId": "wx1234567890abcdef",
|
||||
"serviceMchId": "1900000109",
|
||||
"subMchId": "1900000109",
|
||||
"subAppId": "wx1234567890abcdef",
|
||||
"subMchName": "测试子商户",
|
||||
"subMchDescription": "测试子商户描述",
|
||||
"mchSerialNo": "1234567890ABCDEF",
|
||||
"privateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
|
||||
"apiV3Key": "your_api_v3_key",
|
||||
"notifyUrl": "https://your.domain.com/notify",
|
||||
"status": 1
|
||||
}
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
### 1. 微信支付SDK版本
|
||||
|
||||
当前项目使用的微信支付SDK版本为 `0.2.15`,服务商模式下的子商户设置可能需要根据SDK版本调整。
|
||||
|
||||
### 2. 子商户信息设置
|
||||
|
||||
在支付请求中设置子商户信息时,需要根据微信支付SDK的具体版本确定正确的类名和方法:
|
||||
|
||||
```java
|
||||
// TODO: 需要根据微信支付SDK版本确定正确的类名
|
||||
// SubMerchant subMerchant = new SubMerchant();
|
||||
// subMerchant.setMchid(payConfig.getSubMchId());
|
||||
// request.setSubMerchant(subMerchant);
|
||||
```
|
||||
|
||||
### 3. 配置缓存
|
||||
|
||||
系统使用Redis缓存配置信息,配置更新后会自动清除相关缓存。
|
||||
|
||||
### 4. 错误处理
|
||||
|
||||
在服务商模式下,如果找不到对应的子商户配置,系统会抛出异常并记录日志。
|
||||
|
||||
### 5. 测试建议
|
||||
|
||||
1. 先在测试环境验证服务商模式的配置和支付流程
|
||||
2. 确保所有子商户配置正确无误
|
||||
3. 测试支付回调处理逻辑
|
||||
4. 验证退款功能是否正常
|
||||
|
||||
## 扩展功能
|
||||
|
||||
### 1. 分账功能
|
||||
|
||||
当前版本暂时注释掉了分账逻辑,如需启用分账功能,可以参考原有的分账实现。
|
||||
|
||||
### 2. 多租户支持
|
||||
|
||||
系统支持多租户,每个租户可以配置不同的服务商和子商户信息。
|
||||
|
||||
### 3. 动态配置
|
||||
|
||||
支持通过管理界面动态配置服务商和子商户信息,无需重启应用。
|
||||
-169
@@ -1,169 +0,0 @@
|
||||
# 智能租户分配功能使用说明
|
||||
|
||||
## 功能概述
|
||||
|
||||
智能租户分配功能实现了订单的自动分配策略:用户扫码下单时,系统会根据配置的比例自动将订单分配给景区租户或平台租户,实现平台从景区订单中抽取成本的目的。
|
||||
|
||||
## 核心逻辑
|
||||
|
||||
### 分配策略
|
||||
- **默认比例**:10单景区 + 1单平台
|
||||
- **分配规则**:按用户ID + 二维码ID的组合进行计数
|
||||
- **平台租户ID**:默认为 `webApp`
|
||||
|
||||
### 统计逻辑
|
||||
- **景区统计**:只统计景区租户ID的订单
|
||||
- **平台统计**:只统计平台租户ID的订单
|
||||
- **首页统计**:按景区ID统计(不受租户ID影响)
|
||||
|
||||
## 配置管理
|
||||
|
||||
### 1. 配置文件
|
||||
在 `application.yml` 中添加配置:
|
||||
|
||||
```yaml
|
||||
tenant:
|
||||
allocation:
|
||||
enabled: false # 是否启用功能
|
||||
allocation-ratio: 10 # 分配比例
|
||||
platform-tenant-id: "webApp" # 平台租户ID
|
||||
debug: false # 调试模式
|
||||
force-platform-tenant: false # 强制平台租户(测试用)
|
||||
```
|
||||
|
||||
### 2. 动态配置接口
|
||||
|
||||
#### 获取当前配置
|
||||
```bash
|
||||
GET /api-order/tenant-allocation/config/current
|
||||
```
|
||||
|
||||
#### 更新配置
|
||||
```bash
|
||||
POST /api-order/tenant-allocation/config/update
|
||||
参数:
|
||||
- enabled: 是否启用
|
||||
- allocation-ratio: 分配比例
|
||||
- platform-tenant-id: 平台租户ID
|
||||
- debug: 调试模式
|
||||
- force-platform-tenant: 强制平台租户
|
||||
```
|
||||
|
||||
#### 启用功能
|
||||
```bash
|
||||
POST /api-order/tenant-allocation/config/enable
|
||||
```
|
||||
|
||||
#### 禁用功能
|
||||
```bash
|
||||
POST /api-order/tenant-allocation/config/disable
|
||||
```
|
||||
|
||||
#### 测试配置
|
||||
```bash
|
||||
POST /api-order/tenant-allocation/config/test
|
||||
参数:
|
||||
- userId: 用户ID
|
||||
- qrCodeId: 二维码ID
|
||||
- testCount: 测试订单数量
|
||||
```
|
||||
|
||||
## 测试接口
|
||||
|
||||
### 1. 测试分配逻辑
|
||||
```bash
|
||||
GET /api-order/order/tenant-allocation/test
|
||||
参数:
|
||||
- userId: 用户ID
|
||||
- qrCodeId: 二维码ID
|
||||
- expectedCount: 期望订单数量
|
||||
```
|
||||
|
||||
### 2. 模拟订单分配
|
||||
```bash
|
||||
POST /api-order/order/tenant-allocation/simulate
|
||||
参数:
|
||||
- userId: 用户ID
|
||||
- qrCodeId: 二维码ID
|
||||
- orderCount: 模拟订单数量
|
||||
```
|
||||
|
||||
### 3. 获取分配统计
|
||||
```bash
|
||||
GET /api-order/order/tenant-allocation/statistics
|
||||
参数:
|
||||
- qrCodeId: 二维码ID
|
||||
```
|
||||
|
||||
## 使用场景
|
||||
|
||||
### 场景1:启用智能分配
|
||||
1. 启用功能:
|
||||
```bash
|
||||
POST /api-order/tenant-allocation/config/enable
|
||||
```
|
||||
|
||||
2. 验证配置:
|
||||
```bash
|
||||
POST /api-order/tenant-allocation/config/test?userId=123&qrCodeId=456&testCount=22
|
||||
```
|
||||
|
||||
3. 用户扫码下单,系统自动分配租户
|
||||
|
||||
### 场景2:测试分配逻辑
|
||||
```bash
|
||||
POST /api-order/order/tenant-allocation/simulate?userId=123&qrCodeId=456&orderCount=22
|
||||
```
|
||||
|
||||
预期结果:
|
||||
- 总订单:22单
|
||||
- 景区订单:20单(90.9%)
|
||||
- 平台订单:2单(9.1%)
|
||||
|
||||
### 场景3:强制平台租户(测试用)
|
||||
```bash
|
||||
POST /api-order/tenant-allocation/config/update?force-platform-tenant=true
|
||||
```
|
||||
|
||||
所有订单都会分配给平台租户,用于测试平台统计功能。
|
||||
|
||||
## 注意事项
|
||||
|
||||
### 1. 数据一致性
|
||||
- 订单创建时就确定租户ID,避免后续转移
|
||||
- 统计查询按租户ID筛选,确保准确性
|
||||
- 首页统计按景区ID,不受租户分配影响
|
||||
|
||||
### 2. 配置变更
|
||||
- 配置变更只影响新创建的订单
|
||||
- 已创建的订单租户ID不会改变
|
||||
- 建议在业务低峰期进行配置变更
|
||||
|
||||
### 3. 监控建议
|
||||
- 定期检查分配比例是否符合预期
|
||||
- 监控平台和景区的订单统计
|
||||
- 关注日志中的分配记录
|
||||
|
||||
### 4. 回滚方案
|
||||
如果出现问题,可以快速禁用功能:
|
||||
```bash
|
||||
POST /api-order/tenant-allocation/config/disable
|
||||
```
|
||||
|
||||
所有新订单都会分配给景区租户,恢复原有逻辑。
|
||||
|
||||
## 扩展功能
|
||||
|
||||
### 1. 自定义分配比例
|
||||
可以通过配置调整分配比例:
|
||||
```yaml
|
||||
tenant:
|
||||
allocation:
|
||||
allocation-ratio: 5 # 5单景区 + 1单平台
|
||||
```
|
||||
|
||||
### 2. 多平台租户支持
|
||||
未来可以扩展支持多个平台租户,根据业务需求进行分配。
|
||||
|
||||
### 3. 动态配置持久化
|
||||
当前配置是内存配置,重启后会恢复默认值。未来可以扩展为数据库配置,支持持久化存储。
|
||||
Reference in New Issue
Block a user