Compare commits
121
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c52b3986e5 | ||
|
|
66025b661d | ||
|
|
74d99e6b60 | ||
|
|
c6dfad912d | ||
|
|
ce17f6ec90 | ||
|
|
ad3190c850 | ||
|
|
b8c25eccd7 | ||
|
|
c429d14d43 | ||
|
|
7b4a5b52e7 | ||
|
|
efea836e50 | ||
|
|
c2fabdfbe4 | ||
|
|
9a27919956 | ||
|
|
3faedcb033 | ||
|
|
4cf7ea7768 | ||
|
|
56cfffbee4 | ||
|
|
0ae7b493f7 | ||
|
|
9326b0e5e9 | ||
|
|
a9d2711532 | ||
|
|
515792a2f8 | ||
|
|
bc66fab897 | ||
|
|
0bdfeed86c | ||
|
|
fe24d44834 | ||
|
|
78337a0cc0 | ||
|
|
9c56e54f69 | ||
|
|
31e87a98d5 | ||
|
|
527e591619 | ||
|
|
d7e5802979 | ||
|
|
0a3721f35e | ||
|
|
273c34b44a | ||
|
|
527a12fd30 | ||
|
|
8a4b710bce | ||
|
|
971a0d4817 | ||
|
|
8113e1a7c3 | ||
|
|
84bd74d324 | ||
|
|
f135d5fc3c | ||
|
|
2b730a00c5 | ||
|
|
e82389d2dc | ||
|
|
b7e75456ef | ||
|
|
a358522d4e | ||
|
|
e6e99a5ea6 | ||
|
|
30510653a0 | ||
|
|
abf1e93ae3 | ||
|
|
df9ac8a574 | ||
|
|
118145ab54 | ||
|
|
5119989f2e | ||
|
|
ed6a331e6e | ||
|
|
39ec2e3f59 | ||
|
|
e8eeed90fb | ||
|
|
1a862c3e2b | ||
|
|
29b2e743ab | ||
|
|
e7d40a658c | ||
|
|
cc96117b7d | ||
|
|
caa4ec68c0 | ||
|
|
08f8f19178 | ||
|
|
79d517d24c | ||
|
|
f4f8771378 | ||
|
|
c684905484 | ||
|
|
9043e8d698 | ||
|
|
b3bd36be60 | ||
|
|
e035219ed1 | ||
|
|
a83edf6a05 | ||
|
|
89de206bcb | ||
|
|
ab6aff8671 | ||
|
|
1579a9a31c | ||
|
|
d6996a20fc | ||
|
|
1c72dba543 | ||
|
|
8465bcd1c4 | ||
|
|
7fc388d049 | ||
|
|
2a70b54435 | ||
|
|
0bf4d47bf6 | ||
|
|
2a4f2cbc69 | ||
|
|
54c5a33658 | ||
|
|
1872025c95 | ||
|
|
3fabed19f2 | ||
|
|
5e004678b6 | ||
|
|
80afc4045e | ||
|
|
2697eac46b | ||
|
|
b86def053c | ||
|
|
fe8636ada2 | ||
|
|
a74ad64109 | ||
|
|
0611f17b21 | ||
|
|
e119517d79 | ||
|
|
9702534db7 | ||
|
|
f0d50d53a9 | ||
|
|
d62be7adc2 | ||
|
|
4f41f51def | ||
|
|
46178e1a0e | ||
|
|
96ee918cb1 | ||
|
|
c0746dfd0c | ||
|
|
4f7e4bf27f | ||
|
|
464c166a70 | ||
|
|
68fe9c8e41 | ||
|
|
a05dc8cda3 | ||
|
|
7ba5689e48 | ||
|
|
586c792e1e | ||
|
|
3ed189ca6c | ||
|
|
811b405ef3 | ||
|
|
680972f7c1 | ||
|
|
490f3a65cc | ||
|
|
caa112b0bd | ||
|
|
a98eb63bcf | ||
|
|
7f75f35db0 | ||
|
|
cc500ccb1b | ||
|
|
030ab15cc2 | ||
|
|
9f72363638 | ||
|
|
8a25b120e3 | ||
|
|
e44dd4496a | ||
|
|
4ba0457073 | ||
|
|
6518a80148 | ||
|
|
9998468d2a | ||
|
|
eae7264ab9 | ||
|
|
4d8a02d45f | ||
|
|
8e05e1335d | ||
|
|
35a8d33053 | ||
|
|
0ce6c412ae | ||
|
|
af5438e1bc | ||
|
|
3a27f05122 | ||
|
|
1235f019e4 | ||
|
|
5cafcd3f43 | ||
|
|
eaef798aef | ||
|
|
02175cad3f |
@@ -81,25 +81,7 @@
|
|||||||
"Bash(python3:*)",
|
"Bash(python3:*)",
|
||||||
"Bash(npx:*)",
|
"Bash(npx:*)",
|
||||||
"Bash(xargs head:*)",
|
"Bash(xargs head:*)",
|
||||||
"Bash(for file in *.png)",
|
"Bash(rm:*)"
|
||||||
"Bash(do echo \"=== $file ===\")",
|
|
||||||
"Read(//f/project/go-fly-platform-services/**)",
|
|
||||||
"Bash(find \"F:/project/go-fly-platform-services/zlt-web/react-web-next/src/pages/orders/VideoTemplate\" -type f \\\\\\( -name \"*.tsx\" -o -name \"*.ts\" -o -name \"*.jsx\" -o -name \"*.js\" -o -name \"*.json\" \\\\\\) 2>/dev/null | head -50)",
|
|
||||||
"Bash(find \"F:/project/go-fly-platform-services/zlt-web/react-web-next/src/services\" -type f \\\\\\( -name \"*.ts\" -o -name \"*.tsx\" \\\\\\) 2>/dev/null | grep -i order)",
|
|
||||||
"Bash(ls /f/project/go-fly-platform-services/zlt-business/device-center/src/main/java/com/central/device/controller/*.java)",
|
|
||||||
"Bash(ls /f/project/go-fly-platform-services/zlt-business/device-center/src/main/java/com/central/device/service/*.java)",
|
|
||||||
"Bash(ls /f/project/go-fly-platform-services/zlt-business/device-center/src/main/java/com/central/device/entity/*.java)",
|
|
||||||
"Bash(xargs wc:*)",
|
|
||||||
"Bash(ls -la zlt-web/yingyan/.env*)",
|
|
||||||
"Bash(ls -d zlt-web/*/)",
|
|
||||||
"Bash(git rm:*)",
|
|
||||||
"Bash(claude mcp:*)",
|
|
||||||
"WebFetch(domain:pixso.cn)",
|
|
||||||
"Bash(awk '{print $2}')",
|
|
||||||
"Bash(python -c \"print\\('hello'\\)\")",
|
|
||||||
"Bash(grep -r \"RightPanel\" src/pages/client/index.tsx)",
|
|
||||||
"Bash(grep \"statusBar\\\\|statusDot\" src/pages/client/index.tsx)",
|
|
||||||
"Bash(grep \"routeActions\\\\|routeActionsTitle\" src/pages/client/components/CenterView/index.tsx)"
|
|
||||||
],
|
],
|
||||||
"deny": [],
|
"deny": [],
|
||||||
"ask": []
|
"ask": []
|
||||||
|
|||||||
-11
@@ -10,14 +10,3 @@ nacos/
|
|||||||
# Claude Code specific
|
# Claude Code specific
|
||||||
.claude/agents/
|
.claude/agents/
|
||||||
.claude/team-collaboration-matrix.md
|
.claude/team-collaboration-matrix.md
|
||||||
|
|
||||||
# Cesium static assets (auto-generated by npm install)
|
|
||||||
zlt-web/react-web-next/public/cesium/
|
|
||||||
|
|
||||||
|
|
||||||
zlt-web/yingyan/public/cesium/
|
|
||||||
|
|
||||||
|
|
||||||
zlt-web/react-web-next/dist.zip
|
|
||||||
|
|
||||||
zlt-web/yingyan/dist.zip
|
|
||||||
|
|||||||
@@ -1,832 +0,0 @@
|
|||||||
# go-fly-platform-services 项目 Skill
|
|
||||||
|
|
||||||
**⚠️ 强制规范:所有后台开发必须严格遵循本 Skill 文档中的所有规范、模式和最佳实践**
|
|
||||||
|
|
||||||
## 项目概览
|
|
||||||
|
|
||||||
**项目名称**: go-fly-platform-services (中央平台微服务)
|
|
||||||
**技术栈**: Spring Boot 3.1 + Spring Cloud 2022 + MyBatis-Plus 3.x
|
|
||||||
**Java 版本**: 17
|
|
||||||
**构建工具**: Maven 3.8+
|
|
||||||
**架构模式**: 微服务 + 多租户 + OAuth2 认证
|
|
||||||
|
|
||||||
### 核心特性
|
|
||||||
- 多租户架构(租户级数据隔离 + 数据权限控制)
|
|
||||||
- OAuth2 认证授权(支持密码、手机号、OpenID、第三方登录)
|
|
||||||
- 分布式锁与幂等性保证
|
|
||||||
- 全链路追踪(TraceId 跨服务传播)
|
|
||||||
- 动态路由(Nacos 配置中心热更新)
|
|
||||||
- 服务熔断降级(Sentinel + Feign Fallback)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 常见问题
|
|
||||||
|
|
||||||
### 1. 如何添加新的业务模块?
|
|
||||||
|
|
||||||
1. 在 `zlt-business/` 下创建新模块
|
|
||||||
2. 复制标准包结构(controller/service/mapper/model)
|
|
||||||
3. 实体类继承 `SuperEntity`
|
|
||||||
4. Mapper 继承 `SuperMapper<T>`
|
|
||||||
5. Service 接口继承 `ISuperService<T>`
|
|
||||||
6. Service 实现继承 `SuperServiceImpl<Mapper, Entity>`
|
|
||||||
7. 配置 `bootstrap.yml` 设置服务名
|
|
||||||
|
|
||||||
### 2. 如何实现服务间调用?
|
|
||||||
|
|
||||||
```java
|
|
||||||
// 1. 定义Feign客户端
|
|
||||||
@FeignClient(name = "user-center", fallback = UserServiceFallback.class)
|
|
||||||
public interface UserService {
|
|
||||||
@GetMapping("/users/{id}")
|
|
||||||
Result<SysUser> findById(@PathVariable Long id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 实现降级处理
|
|
||||||
@Component
|
|
||||||
public class UserServiceFallback implements UserService {
|
|
||||||
@Override
|
|
||||||
public Result<SysUser> findById(Long id) {
|
|
||||||
return Result.failed("用户服务不可用");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 使用
|
|
||||||
@Autowired
|
|
||||||
private UserService userService;
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 如何处理多租户数据?
|
|
||||||
|
|
||||||
**自动隔离**: 默认所有查询自动添加租户条件
|
|
||||||
|
|
||||||
**跳过隔离**: 使用 `@IgnoreTenantScope` 注解
|
|
||||||
|
|
||||||
**配置忽略表**: 在 `application.yml` 配置 `zlt.tenant.ignoreTables`
|
|
||||||
|
|
||||||
### 4. 如何实现分布式锁?
|
|
||||||
|
|
||||||
```java
|
|
||||||
// 注解方式(推荐)
|
|
||||||
@Lock(key = "order:create", waitTime = 5, leaseTime = 10)
|
|
||||||
public void createOrder() { ... }
|
|
||||||
|
|
||||||
// 手动方式
|
|
||||||
ZLock lock = distributedLock.tryLock("key", 5, 10, TimeUnit.SECONDS);
|
|
||||||
try {
|
|
||||||
// 业务逻辑
|
|
||||||
} finally {
|
|
||||||
distributedLock.unlock(lock);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. 如何配置动态路由?
|
|
||||||
|
|
||||||
在 Nacos 配置中心创建配置:
|
|
||||||
- Data ID: `scg-routes`
|
|
||||||
- Group: `SCG_GATEWAY`
|
|
||||||
- 格式: JSON 数组的 RouteDefinition
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 快速参考
|
|
||||||
|
|
||||||
### 端口分配
|
|
||||||
- 认证中心: 8000
|
|
||||||
- 网关: 9900
|
|
||||||
- 用户中心: 7000
|
|
||||||
- 文件中心: 5000
|
|
||||||
- 日志中心: 7200
|
|
||||||
- 应用监控: 6500
|
|
||||||
- Nacos: 8848
|
|
||||||
|
|
||||||
### 关键配置项
|
|
||||||
```yaml
|
|
||||||
# 多租户
|
|
||||||
zlt.tenant.enable: true
|
|
||||||
|
|
||||||
# URL权限
|
|
||||||
zlt.security.auth.urlPermission.enable: false
|
|
||||||
|
|
||||||
# 动态路由
|
|
||||||
zlt.gateway.dynamicRoute.enabled: true
|
|
||||||
|
|
||||||
# 单点登录
|
|
||||||
zlt.security.auth.isSingleLogin: true
|
|
||||||
```
|
|
||||||
|
|
||||||
### 核心依赖版本
|
|
||||||
- Spring Boot: 3.1.6
|
|
||||||
- Spring Cloud: 2022.0.4
|
|
||||||
- Spring Cloud Alibaba: 2022.0.0.0
|
|
||||||
- MyBatis-Plus: 3.5.4.1
|
|
||||||
- Java: 17
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 项目文档位置
|
|
||||||
|
|
||||||
- **仓库指南**: `AGENTS.md`
|
|
||||||
- **项目文档**: `zlt-doc/`
|
|
||||||
- **API文档**: 启动服务后访问 `/doc.html`
|
|
||||||
- **README**: `README.md`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Git 操作限制
|
|
||||||
|
|
||||||
**重要**: 除非用户明确要求,否则不要执行任何 Git 操作:
|
|
||||||
- 禁止自动 commit、push、pull、merge、rebase
|
|
||||||
- 需要读取 Git 元数据时先获得用户确认
|
|
||||||
- 破坏性操作(reset、force push)必须明确风险并征得同意
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Agent 使用建议
|
|
||||||
|
|
||||||
### 适合场景
|
|
||||||
- 生成标准 CRUD 代码
|
|
||||||
- 添加新的业务模块
|
|
||||||
- 实现服务间调用
|
|
||||||
- 配置多租户隔离
|
|
||||||
- 添加缓存和分布式锁
|
|
||||||
- 生成 API 文档
|
|
||||||
|
|
||||||
### 注意事项
|
|
||||||
- 遵循现有代码风格和命名规范
|
|
||||||
- 使用项目提供的基类和工具类
|
|
||||||
- 添加适当的注释和文档
|
|
||||||
- 考虑多租户和权限控制
|
|
||||||
- 添加审计日志和链路追踪
|
|
||||||
- 实现服务降级和熔断
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*最后更新: 2026-04-01*
|
|
||||||
|
|
||||||
### 测试框架
|
|
||||||
- JUnit 4 / JUnit 5(按模块)
|
|
||||||
- 测试类命名: `*Test.java`
|
|
||||||
- 测试类位置: `src/test/java`
|
|
||||||
|
|
||||||
### 测试要求
|
|
||||||
- 为新增逻辑补充单测
|
|
||||||
- 测试用例相互独立、可重复
|
|
||||||
- 提PR前执行: `mvn -pl <module> -am test`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 提交规范
|
|
||||||
|
|
||||||
### 约定式提交
|
|
||||||
格式: `type(scope): 简要说明`
|
|
||||||
|
|
||||||
**类型**:
|
|
||||||
- `feat` - 新功能
|
|
||||||
- `fix` - 修复bug
|
|
||||||
- `docs` - 文档
|
|
||||||
- `refactor` - 重构
|
|
||||||
- `test` - 测试
|
|
||||||
- `chore` - 构建/工具
|
|
||||||
|
|
||||||
**示例**:
|
|
||||||
```
|
|
||||||
feat(订单中心): 添加订单导出功能
|
|
||||||
fix(用户中心): 修复用户登录验证码失效问题
|
|
||||||
docs(README): 更新部署文档
|
|
||||||
```
|
|
||||||
|
|
||||||
### PR规范
|
|
||||||
- 描述清晰:目的/影响/涉及模块
|
|
||||||
- 包含测试说明
|
|
||||||
- 前端改动附截图
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
### Lombok
|
|
||||||
```java
|
|
||||||
@Slf4j // 自动注入logger
|
|
||||||
@Data // getter/setter/toString
|
|
||||||
@EqualsAndHashCode // equals/hashCode
|
|
||||||
@AllArgsConstructor // 全参构造
|
|
||||||
@NoArgsConstructor // 无参构造
|
|
||||||
```
|
|
||||||
|
|
||||||
### MyBatis-Plus
|
|
||||||
```java
|
|
||||||
@TableName("table_name") // 表名映射
|
|
||||||
@TableId // 主键
|
|
||||||
@TableField(exist = false) // 非数据库字段
|
|
||||||
@TableField(fill = FieldFill.INSERT) // 插入时填充
|
|
||||||
@TableLogic // 逻辑删除
|
|
||||||
```
|
|
||||||
|
|
||||||
### Spring
|
|
||||||
```java
|
|
||||||
@RestController // REST控制器
|
|
||||||
@Service // 业务层
|
|
||||||
@Transactional // 事务管理
|
|
||||||
@Cacheable // 查询缓存
|
|
||||||
@CachePut // 更新缓存
|
|
||||||
@CacheEvict // 清除缓存
|
|
||||||
@Async // 异步执行
|
|
||||||
```
|
|
||||||
|
|
||||||
### 项目自定义
|
|
||||||
```java
|
|
||||||
@AuditLog(operation = "操作描述") // 审计日志
|
|
||||||
@IgnoreTenantScope // 跳过租户隔离
|
|
||||||
@Lock(key = "lock_key") // 分布式锁
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 开发最佳实践
|
|
||||||
|
|
||||||
**⚠️ 重要:所有后台开发必须严格遵循本 Skill 中的规范和模式**
|
|
||||||
|
|
||||||
### 1. 实体类设计
|
|
||||||
- 继承 `SuperEntity` 获得id/createTime/updateTime
|
|
||||||
- **必须为每个字段添加注释**,说明字段的业务含义
|
|
||||||
- 枚举类型注明可选值,布尔类型注明 true/false 含义
|
|
||||||
- 使用 `@TableLogic` 实现逻辑删除
|
|
||||||
- 非数据库字段标记 `@TableField(exist = false)`
|
|
||||||
|
|
||||||
### 2. Service层规范
|
|
||||||
- 接口继承 `ISuperService<T>`
|
|
||||||
- 实现继承 `SuperServiceImpl<Mapper, Entity>`
|
|
||||||
- **优先使用 MPJBaseMapper 的 Lambda 方式**,少用 XML
|
|
||||||
- 只有复杂 SQL(多表关联、子查询、复杂统计)才使用 XML
|
|
||||||
- 事务方法添加 `@Transactional(rollbackFor = Exception.class)`
|
|
||||||
- 并发操作使用 `saveOrUpdateIdempotency()` 保证幂等性
|
|
||||||
|
|
||||||
### 3. 用户查询规范
|
|
||||||
- **全局统一使用**: `SysUser sysUser = userService.findUserById(userId);`
|
|
||||||
- 获取当前登录用户: `LoginUserContextHolder.getUser()`
|
|
||||||
|
|
||||||
### 4. 缓存使用
|
|
||||||
- 查询使用 `@Cacheable`
|
|
||||||
- 更新使用 `@CachePut`
|
|
||||||
- 删除使用 `@CacheEvict`
|
|
||||||
- 配置缓存过期时间
|
|
||||||
|
|
||||||
### 4. 异常处理
|
|
||||||
- 业务异常抛出 `BusinessException`
|
|
||||||
- 全局异常由 `DefaultExceptionAdvice` 统一处理
|
|
||||||
- 返回统一格式 `Result<T>`
|
|
||||||
|
|
||||||
### 5. 日志规范
|
|
||||||
- 使用 `@Slf4j` 注解
|
|
||||||
- 关键操作添加 `@AuditLog`
|
|
||||||
- 日志自动包含 TraceId
|
|
||||||
|
|
||||||
### 6. 安全规范
|
|
||||||
- 禁止提交密钥和凭据
|
|
||||||
- 使用环境变量或配置中心
|
|
||||||
- 敏感操作添加审计日志
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
### OAuth2 认证中心(zlt-uaa)
|
|
||||||
|
|
||||||
**支持的授权方式**:
|
|
||||||
- `password` - 用户名密码
|
|
||||||
- `password_code` - 密码+验证码
|
|
||||||
- `mobile` - 手机号认证
|
|
||||||
- `openid` - OpenID认证
|
|
||||||
- `tencent` - 腾讯第三方登录
|
|
||||||
|
|
||||||
**Token生成流程**:
|
|
||||||
```
|
|
||||||
登录请求 → AuthenticationProvider → BaseAuthenticationProvider
|
|
||||||
→ TokenGenerator (JWT + AccessToken + RefreshToken)
|
|
||||||
→ 保存到Redis → 返回Token响应
|
|
||||||
```
|
|
||||||
|
|
||||||
**Token增强**: 自动添加用户ID、用户名、账户类型等信息
|
|
||||||
|
|
||||||
**Token存储**: Redis(默认)或内存
|
|
||||||
|
|
||||||
### API网关(sc-gateway)
|
|
||||||
|
|
||||||
**动态路由**: Nacos配置中心热更新
|
|
||||||
```yaml
|
|
||||||
zlt:
|
|
||||||
gateway:
|
|
||||||
dynamicRoute:
|
|
||||||
enabled: true
|
|
||||||
dataType: nacos
|
|
||||||
```
|
|
||||||
|
|
||||||
**过滤器链**:
|
|
||||||
```
|
|
||||||
请求 → TraceFilter(链路追踪) → RequestFilter(方法验证)
|
|
||||||
→ ResourceServer(Token验证) → PermissionAuthManager(权限检查)
|
|
||||||
→ 后端服务
|
|
||||||
```
|
|
||||||
|
|
||||||
**权限检查**:
|
|
||||||
- 超级管理员(admin)自动放行
|
|
||||||
- 应用黑白名单控制
|
|
||||||
- URL级别权限验证
|
|
||||||
- 支持忽略列表配置
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 构建与运行
|
|
||||||
|
|
||||||
### 构建命令
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 全量构建(跳过测试)
|
|
||||||
mvn -q -DskipTests clean package
|
|
||||||
|
|
||||||
# 全量测试
|
|
||||||
mvn -q test
|
|
||||||
|
|
||||||
# 指定模块构建+测试
|
|
||||||
mvn -pl zlt-business/user-center -am clean verify
|
|
||||||
```
|
|
||||||
|
|
||||||
### 本地运行
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 运行网关
|
|
||||||
mvn -pl zlt-gateway/sc-gateway -am spring-boot:run
|
|
||||||
|
|
||||||
# 运行认证中心
|
|
||||||
mvn -pl zlt-uaa -am spring-boot:run
|
|
||||||
|
|
||||||
# 从JAR运行
|
|
||||||
java -jar zlt-gateway/sc-gateway/target/*.jar
|
|
||||||
```
|
|
||||||
|
|
||||||
**先决条件**: JDK 17、Maven 3.8+
|
|
||||||
|
|
||||||
### 配置文件
|
|
||||||
|
|
||||||
**bootstrap.yml** (服务启动配置):
|
|
||||||
```yaml
|
|
||||||
spring:
|
|
||||||
application:
|
|
||||||
name: user-center # 服务名
|
|
||||||
```
|
|
||||||
|
|
||||||
**application.yml** (通常从Nacos读取):
|
|
||||||
```yaml
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://localhost/user-center
|
|
||||||
username: root
|
|
||||||
password: password
|
|
||||||
|
|
||||||
mybatis-plus:
|
|
||||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
|
||||||
|
|
||||||
zlt:
|
|
||||||
tenant:
|
|
||||||
enable: true
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
### 核心基础库(zlt-common-core)
|
|
||||||
|
|
||||||
**通用返回模型**:
|
|
||||||
```java
|
|
||||||
Result<T> // API返回包装 {data, resp_code, resp_msg}
|
|
||||||
PageResult<T> // 分页返回 {count, data, resp_code}
|
|
||||||
```
|
|
||||||
|
|
||||||
**用户与租户上下文**:
|
|
||||||
```java
|
|
||||||
LoginUserContextHolder.getUser() // 获取当前登录用户
|
|
||||||
TenantContextHolder.getTenantId() // 获取当前租户ID
|
|
||||||
LoginUserUtils.getCurrentUser(true) // 从请求获取用户
|
|
||||||
|
|
||||||
// 全局根据userId获取用户的标准方法
|
|
||||||
SysUser sysUser = userService.findUserById(userId);
|
|
||||||
```
|
|
||||||
|
|
||||||
**常用工具类**:
|
|
||||||
- `JsonUtil` - JSON序列化
|
|
||||||
- `IdGenerator` - 分布式ID生成
|
|
||||||
- `ExcelUtil` - Excel导入导出
|
|
||||||
- `ResponseUtil` - HTTP响应工具
|
|
||||||
|
|
||||||
**异常处理**:
|
|
||||||
- `BusinessException` - 业务异常
|
|
||||||
- `DefaultExceptionAdvice` - 全局异常处理
|
|
||||||
|
|
||||||
### 分布式锁(zlt-redis-spring-boot-starter)
|
|
||||||
|
|
||||||
```java
|
|
||||||
// 方式1: 注解驱动
|
|
||||||
@Lock(key = "order:create", waitTime = 5, leaseTime = 10)
|
|
||||||
public void createOrder() { ... }
|
|
||||||
|
|
||||||
// 方式2: 手动调用
|
|
||||||
@Autowired
|
|
||||||
private DistributedLock lock;
|
|
||||||
|
|
||||||
ZLock zlock = lock.tryLock("order:123", 5, 10, TimeUnit.SECONDS);
|
|
||||||
try {
|
|
||||||
// 业务逻辑
|
|
||||||
} finally {
|
|
||||||
lock.unlock(zlock);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Redis 缓存
|
|
||||||
|
|
||||||
```java
|
|
||||||
@Autowired
|
|
||||||
private RedisRepository redisRepository;
|
|
||||||
|
|
||||||
// 基础操作
|
|
||||||
redisRepository.set("key", value, 3600, TimeUnit.SECONDS);
|
|
||||||
Object value = redisRepository.get("key");
|
|
||||||
redisRepository.del("key");
|
|
||||||
|
|
||||||
// Hash操作
|
|
||||||
redisRepository.hSet("hash:key", "field", value);
|
|
||||||
Object field = redisRepository.hGet("hash:key", "field");
|
|
||||||
```
|
|
||||||
|
|
||||||
### 审计日志
|
|
||||||
|
|
||||||
```java
|
|
||||||
@AuditLog(operation = "'创建订单:' + #order.orderNo")
|
|
||||||
public void createOrder(Order order) {
|
|
||||||
// 自动记录: 操作时间、操作人、操作内容、IP地址
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 多租户隔离
|
|
||||||
|
|
||||||
**自动隔离**: SQL自动添加 `WHERE tenant_id = ?`
|
|
||||||
|
|
||||||
**跳过隔离**:
|
|
||||||
```java
|
|
||||||
@IgnoreTenantScope
|
|
||||||
public List<SysUser> findAllUsers() {
|
|
||||||
// 查询所有租户的用户
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**配置忽略表**:
|
|
||||||
```yaml
|
|
||||||
zlt:
|
|
||||||
tenant:
|
|
||||||
enable: true
|
|
||||||
ignoreTables:
|
|
||||||
- sys_user
|
|
||||||
- sys_role
|
|
||||||
```
|
|
||||||
|
|
||||||
### 链路追踪
|
|
||||||
|
|
||||||
**自动传播**: TraceId 自动跨服务传递(Web → Feign → Dubbo)
|
|
||||||
|
|
||||||
**MDC集成**: 日志自动包含 TraceId
|
|
||||||
```
|
|
||||||
[TraceId: abc123] 用户登录成功
|
|
||||||
```
|
|
||||||
|
|
||||||
### 对象存储(zlt-oss-spring-boot-starter)
|
|
||||||
|
|
||||||
```java
|
|
||||||
@Autowired
|
|
||||||
private IOssService ossService;
|
|
||||||
|
|
||||||
// 上传文件
|
|
||||||
ObjectInfo info = ossService.upload(multipartFile);
|
|
||||||
|
|
||||||
// 上传流
|
|
||||||
ObjectInfo info = ossService.upload("path/file.jpg", inputStream);
|
|
||||||
|
|
||||||
// 删除
|
|
||||||
ossService.delete("path/file.jpg");
|
|
||||||
```
|
|
||||||
|
|
||||||
支持: FastDFS、Amazon S3、阿里云OSS、腾讯云COS
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
### Controller 层
|
|
||||||
|
|
||||||
```java
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@Tag(name = "用户管理")
|
|
||||||
public class SysUserController {
|
|
||||||
@Autowired
|
|
||||||
private ISysUserService userService;
|
|
||||||
|
|
||||||
// 查询单条
|
|
||||||
@GetMapping("/users/{id}")
|
|
||||||
@Operation(summary = "根据ID查询用户")
|
|
||||||
public Result<SysUser> findById(@PathVariable Long id) {
|
|
||||||
return Result.succeed(userService.getById(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
@GetMapping("/users")
|
|
||||||
public PageResult<SysUser> findUsers(@RequestParam Map<String, Object> params) {
|
|
||||||
return userService.findUsers(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新增或更新
|
|
||||||
@PostMapping("/users/saveOrUpdate")
|
|
||||||
@AuditLog(operation = "'保存用户:' + #user.username")
|
|
||||||
public Result saveOrUpdate(@RequestBody SysUser user) {
|
|
||||||
return userService.saveOrUpdateUser(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除
|
|
||||||
@DeleteMapping("/users/{id}")
|
|
||||||
public Result delete(@PathVariable Long id) {
|
|
||||||
userService.delUser(id);
|
|
||||||
return Result.succeed("删除成功");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**关键注解**:
|
|
||||||
- `@RestController` - REST控制器
|
|
||||||
- `@Tag` / `@Operation` - Swagger 3.0文档
|
|
||||||
- `@AuditLog` - 审计日志(自动记录操作)
|
|
||||||
- `@CachePut` / `@Cacheable` - 缓存管理
|
|
||||||
|
|
||||||
### Service 层
|
|
||||||
|
|
||||||
```java
|
|
||||||
// 接口
|
|
||||||
public interface ISysUserService extends ISuperService<SysUser> {
|
|
||||||
PageResult<SysUser> findUsers(Map<String, Object> params);
|
|
||||||
Result saveOrUpdateUser(SysUser user);
|
|
||||||
boolean delUser(Long id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 实现
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
|
||||||
implements ISysUserService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DistributedLock lock;
|
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
@Override
|
|
||||||
public Result saveOrUpdateUser(SysUser user) {
|
|
||||||
// 幂等性保证
|
|
||||||
boolean result = super.saveOrUpdateIdempotency(user, lock,
|
|
||||||
"username:" + user.getUsername(),
|
|
||||||
new QueryWrapper<SysUser>().eq("username", user.getUsername()),
|
|
||||||
"用户名已存在"
|
|
||||||
);
|
|
||||||
return result ? Result.succeed(user) : Result.failed("操作失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@IgnoreTenantScope // 跳过租户隔离
|
|
||||||
public List<SysRole> findRoles(Long userId) {
|
|
||||||
return roleMapper.findByUserId(userId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**关键点**:
|
|
||||||
- 继承 `SuperServiceImpl<Mapper, Entity>`
|
|
||||||
- `@Transactional` 事务管理
|
|
||||||
- `saveOrUpdateIdempotency()` 幂等性操作
|
|
||||||
- `@IgnoreTenantScope` 跳过多租户隔离
|
|
||||||
|
|
||||||
### Mapper 层
|
|
||||||
|
|
||||||
```java
|
|
||||||
@Mapper
|
|
||||||
public interface SysUserMapper extends SuperMapper<SysUser> {
|
|
||||||
// 简单查询优先使用 MPJBaseMapper 的 Lambda 方式
|
|
||||||
// 复杂查询才使用 XML
|
|
||||||
List<SysUser> findList(Page<SysUser> page, @Param("u") Map<String, Object> params);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**重要规范**:
|
|
||||||
- 继承 `SuperMapper<T>` (基于 MPJBaseMapper)
|
|
||||||
- **优先使用 MPJBaseMapper 的 Lambda 方式**,少用 XML
|
|
||||||
- 只有复杂 SQL(多表关联、子查询、复杂统计)才使用 `*Mapper.xml`
|
|
||||||
|
|
||||||
**MPJBaseMapper 使用示例**:
|
|
||||||
```java
|
|
||||||
// Service 实现中使用 MPJBaseMapper
|
|
||||||
@Service
|
|
||||||
public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> {
|
|
||||||
|
|
||||||
// 简单关联查询 - 使用 MPJBaseMapper
|
|
||||||
public List<Order> findOrdersWithUser(Long userId) {
|
|
||||||
return baseMapper.selectJoinList(Order.class,
|
|
||||||
new MPJLambdaWrapper<Order>()
|
|
||||||
.selectAll(Order.class)
|
|
||||||
.select(SysUser::getUsername, SysUser::getNickname)
|
|
||||||
.leftJoin(SysUser.class, SysUser::getId, Order::getUserId)
|
|
||||||
.eq(Order::getUserId, userId)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 复杂统计查询 - 使用 XML
|
|
||||||
public List<OrderStatVO> getOrderStats(Map<String, Object> params) {
|
|
||||||
return baseMapper.getOrderStats(params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 实体类
|
|
||||||
|
|
||||||
**重要规范**: 所有字段必须添加注释说明字段作用
|
|
||||||
|
|
||||||
```java
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("sys_user")
|
|
||||||
public class SysUser extends SuperEntity {
|
|
||||||
/** 用户名(登录账号) */
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/** 密码(加密存储) */
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/** 昵称(显示名称) */
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
/** 手机号 */
|
|
||||||
private String mobile;
|
|
||||||
|
|
||||||
/** 是否启用(true=启用,false=禁用) */
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
/** 用户类型(APP=移动端用户,BACKEND=后台用户) */
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
/** 逻辑删除标记(true=已删除,false=未删除) */
|
|
||||||
@TableLogic
|
|
||||||
private boolean isDel;
|
|
||||||
|
|
||||||
/** 用户角色列表(非数据库字段,用于传输) */
|
|
||||||
@TableField(exist = false)
|
|
||||||
private List<SysRole> roles;
|
|
||||||
|
|
||||||
/** 角色ID(非数据库字段,用于前端传参) */
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String roleId;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**基类 SuperEntity**:
|
|
||||||
```java
|
|
||||||
public class SuperEntity {
|
|
||||||
/** 主键ID(自增) */
|
|
||||||
@TableId
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/** 创建时间(插入时自动填充) */
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
/** 更新时间(插入和更新时自动填充) */
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private Date updateTime;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**字段注释规范**:
|
|
||||||
- 必须说明字段的业务含义
|
|
||||||
- 枚举类型需注明可选值
|
|
||||||
- 布尔类型需注明 true/false 的含义
|
|
||||||
- 关联字段需注明关联的表或实体
|
|
||||||
|
|
||||||
### Feign 服务调用
|
|
||||||
|
|
||||||
```java
|
|
||||||
// 客户端定义
|
|
||||||
@FeignClient(name = "order-center", fallback = OrderServiceFallback.class)
|
|
||||||
public interface OrderCenterService {
|
|
||||||
@DeleteMapping("/orders/user/{userId}")
|
|
||||||
Result<String> deleteUserOrders(@PathVariable("userId") Long userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 熔断降级
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class OrderServiceFallback implements OrderCenterService {
|
|
||||||
@Override
|
|
||||||
public Result<String> deleteUserOrders(Long userId) {
|
|
||||||
log.error("订单中心服务不可用,用户ID: {}", userId);
|
|
||||||
return Result.failed("订单中心服务不可用");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
central-platform
|
|
||||||
├── zlt-commons/ # 公共模块(14个starter)
|
|
||||||
│ ├── zlt-common-core # 核心基础库
|
|
||||||
│ ├── zlt-db-spring-boot-starter # 数据库增强
|
|
||||||
│ ├── zlt-redis-spring-boot-starter # Redis缓存
|
|
||||||
│ ├── zlt-auth-client-spring-boot-starter # OAuth2客户端
|
|
||||||
│ ├── zlt-log-spring-boot-starter # 日志链路追踪
|
|
||||||
│ ├── zlt-oss-spring-boot-starter # 对象存储
|
|
||||||
│ └── zlt-common-spring-boot-starter # 多租户过滤器
|
|
||||||
├── zlt-uaa/ # 认证中心 [8000]
|
|
||||||
├── zlt-gateway/sc-gateway/ # API网关 [9900]
|
|
||||||
├── zlt-business/ # 业务服务
|
|
||||||
│ ├── user-center # 用户中心 [7000]
|
|
||||||
│ ├── order-center # 订单中心
|
|
||||||
│ ├── device-center # 设备中心
|
|
||||||
│ ├── file-center # 文件中心 [5000]
|
|
||||||
│ ├── msg-center # 消息中心
|
|
||||||
│ └── coupon-center # 优惠券中心
|
|
||||||
├── zlt-monitor/ # 监控
|
|
||||||
│ ├── sc-admin # 应用监控 [6500]
|
|
||||||
│ └── log-center # 日志中心 [7200]
|
|
||||||
└── zlt-web/ # 前端
|
|
||||||
├── react-web-next # React前端
|
|
||||||
└── yingyan # 鹰眼前端
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 语言与编码规范
|
|
||||||
|
|
||||||
### 交互语言
|
|
||||||
- **所有回复、解释、建议、错误信息必须使用中文(简体)**
|
|
||||||
- 代码注释、日志消息、文档内容使用中文
|
|
||||||
- 编程关键字、API标识符保持原文
|
|
||||||
- 提交信息、PR描述、Issue使用中文
|
|
||||||
- 所有文本使用 UTF-8 编码
|
|
||||||
|
|
||||||
### 命名约定
|
|
||||||
- **包名**: `com.central.*`
|
|
||||||
- **模块名**: `zlt-*` 前缀
|
|
||||||
- **类名**: PascalCase(如 `SysUserController`)
|
|
||||||
- **方法/字段**: lowerCamelCase(如 `findUserById`)
|
|
||||||
- **常量**: UPPER_SNAKE_CASE(如 `TOKEN_HEADER`)
|
|
||||||
- **接口**: `I` 前缀(如 `ISysUserService`)
|
|
||||||
- **实现类**: `Impl` 后缀(如 `SysUserServiceImpl`)
|
|
||||||
- **测试类**: `*Test.java` 后缀
|
|
||||||
|
|
||||||
### 代码风格
|
|
||||||
- 4空格缩进(Java)
|
|
||||||
- 左大括号同一行
|
|
||||||
- UTF-8 编码
|
|
||||||
- 优先使用 Lombok 注解(`@Data`, `@Slf4j`)
|
|
||||||
- 尽量不要controller层编写业务代码,在service层写业务代码
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 标准分层架构
|
|
||||||
|
|
||||||
### 四层分层模式
|
|
||||||
|
|
||||||
```
|
|
||||||
Controller 层 (HTTP入口)
|
|
||||||
↓
|
|
||||||
Service 接口 (ISxxService)
|
|
||||||
↓
|
|
||||||
Service 实现 (SxxServiceImpl)
|
|
||||||
↓
|
|
||||||
Mapper 接口 (数据库访问)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 标准包结构
|
|
||||||
|
|
||||||
```java
|
|
||||||
com.central.{module}/
|
|
||||||
├── controller/ // HTTP入口层
|
|
||||||
├── service/ // Service接口
|
|
||||||
│ └── impl/ // Service实现
|
|
||||||
├── mapper/ // MyBatis-Plus Mapper
|
|
||||||
├── model/ // 实体类
|
|
||||||
│ ├── dto/ // 数据传输对象
|
|
||||||
│ └── vo/ // 值对象
|
|
||||||
├── feign/ // Feign客户端
|
|
||||||
│ └── fallback/ // 熔断降级
|
|
||||||
├── config/ // 配置类
|
|
||||||
├── constants/ // 常量
|
|
||||||
├── enums/ // 枚举
|
|
||||||
├── event/ // 事件
|
|
||||||
├── listener/ // 监听器
|
|
||||||
└── util/ // 工具类
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
@@ -1,466 +0,0 @@
|
|||||||
# react-web-next 项目 Skill
|
|
||||||
|
|
||||||
**适用范围**: `zlt-web/react-web-next`
|
|
||||||
|
|
||||||
**强制要求**: 在该项目中进行开发、修复、重构、迁移时,默认以本 Skill 为第一约束;除非用户明确要求,否则不要偏离这里定义的结构、边界和实现方式。
|
|
||||||
|
|
||||||
## 1. 项目一句话定义
|
|
||||||
|
|
||||||
`react-web-next` 是旧版 `zlt-web/react-web` 的重构版管理后台:
|
|
||||||
|
|
||||||
- 保持旧功能、旧接口、旧菜单路径兼容
|
|
||||||
- 用更清晰的页面/组件/service/utils 分层重组代码
|
|
||||||
- 把“租户过滤”沉淀为横切基础设施
|
|
||||||
- 在不升级核心技术栈的前提下优化 UI 与维护性
|
|
||||||
|
|
||||||
## 2. 技术边界
|
|
||||||
|
|
||||||
### 必须遵守
|
|
||||||
|
|
||||||
- React 17
|
|
||||||
- UmiJS 3.5
|
|
||||||
- Ant Design 4
|
|
||||||
- `@ant-design/pro-components` 1.x
|
|
||||||
- `@ant-design/pro-layout` 7.x
|
|
||||||
- TypeScript 4.5,且 `strict: true`
|
|
||||||
- Less + 主题变量 + 运行时主题包装
|
|
||||||
|
|
||||||
### 不要擅自做的事
|
|
||||||
|
|
||||||
- 不要切 React 18 写法再反向污染项目
|
|
||||||
- 不要引入 Ant Design 5 的 token/ConfigProvider 主题范式替换现有体系
|
|
||||||
- 不要为了“现代化”重做路由、菜单、登录态、代理机制
|
|
||||||
- 不要把页面请求逻辑重新散落回页面组件内部
|
|
||||||
|
|
||||||
## 3. 先认清这 5 个核心事实
|
|
||||||
|
|
||||||
### 3.1 这是兼容旧后台路径的重构工程
|
|
||||||
|
|
||||||
- 大量页面仍然保留 `*.html` 路径,例如 `/system/user.html`
|
|
||||||
- 这是兼容旧菜单入口、部署方式、历史链接的刻意设计
|
|
||||||
- **不要批量改路由风格,不要把 `.html` 路径私自改没**
|
|
||||||
|
|
||||||
### 3.2 开发态和构建态的 API 路径策略不同
|
|
||||||
|
|
||||||
- 开发态:靠 `config/proxy.ts` 转发
|
|
||||||
- 构建态:靠 `process.env.API_PREFIX` 注入请求前缀
|
|
||||||
- `APP_BASE` 同时影响 `base`、`publicPath` 和最终部署目录
|
|
||||||
|
|
||||||
### 3.3 租户过滤不是页面私有逻辑,而是全局基础设施
|
|
||||||
|
|
||||||
- 首选 `src/components/TenantScopeFilter/index.tsx`
|
|
||||||
- 配套缓存与 Token 保护在 `src/utils/tenantCache.ts`
|
|
||||||
- 页面如果天然受租户影响,默认要先判断是否应接入这套能力
|
|
||||||
|
|
||||||
### 3.4 应用层已经统一接管了认证行为
|
|
||||||
|
|
||||||
- 全局入口在 `src/app.tsx`
|
|
||||||
- 会自动注入 `Authorization: Bearer <token>`
|
|
||||||
- 会统一处理 401/403 与部分业务未授权码
|
|
||||||
- 会统一清理:
|
|
||||||
- `sessionStorage.access_token`
|
|
||||||
- `sessionStorage.current_user`
|
|
||||||
- 租户缓存
|
|
||||||
|
|
||||||
### 3.5 后端返回结构需要兼容 `resp_code`
|
|
||||||
|
|
||||||
默认优先兼容:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "success",
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
前端处理后的目标语义应尽量统一为:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
{
|
|
||||||
success: true,
|
|
||||||
code: 0,
|
|
||||||
msg: 'success',
|
|
||||||
data: {}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**结论**: 新增 service、下载、列表查询、提交保存时,都要先考虑这层兼容,不要重新定义另一套响应契约。
|
|
||||||
|
|
||||||
## 4. 目录落位规则
|
|
||||||
|
|
||||||
```text
|
|
||||||
zlt-web/react-web-next/
|
|
||||||
├─ config/
|
|
||||||
│ ├─ config.ts
|
|
||||||
│ ├─ proxy.ts
|
|
||||||
│ └─ routes.ts
|
|
||||||
├─ src/
|
|
||||||
│ ├─ app.tsx
|
|
||||||
│ ├─ global.less
|
|
||||||
│ ├─ theme.tsx
|
|
||||||
│ ├─ layouts/
|
|
||||||
│ ├─ pages/
|
|
||||||
│ ├─ services/
|
|
||||||
│ ├─ components/
|
|
||||||
│ ├─ hooks/
|
|
||||||
│ ├─ utils/
|
|
||||||
│ ├─ theme/
|
|
||||||
│ ├─ types/
|
|
||||||
│ └─ typings.d.ts
|
|
||||||
```
|
|
||||||
|
|
||||||
### 你改代码前先判断放哪层
|
|
||||||
|
|
||||||
- 页面编排、状态、弹窗、列表交互:`src/pages/`
|
|
||||||
- 复用 UI 或复用业务组件:`src/components/`
|
|
||||||
- API 请求与协议适配:`src/services/`
|
|
||||||
- 跨页面纯逻辑、下载、导出、安全、缓存:`src/utils/`
|
|
||||||
- 与 React 生命周期强相关、可复用的逻辑:`src/hooks/`
|
|
||||||
- 顶层壳层、菜单、头部、账户区:`src/layouts/`
|
|
||||||
|
|
||||||
### 默认禁止
|
|
||||||
|
|
||||||
- 不要把接口直接堆在页面里
|
|
||||||
- 不要把页面专属状态机塞进 `utils`
|
|
||||||
- 不要把通用组件又复制一份到页面目录
|
|
||||||
|
|
||||||
## 5. 配置层规则
|
|
||||||
|
|
||||||
### `config/config.ts`
|
|
||||||
|
|
||||||
你需要知道它控制了:
|
|
||||||
|
|
||||||
- 显式路由入口:`routes.ts`
|
|
||||||
- 开发/生产差异化 `publicPath`
|
|
||||||
- `base` 与部署子路径
|
|
||||||
- Ant Design 4 主题变量
|
|
||||||
- `dynamicImport.loading`
|
|
||||||
- `process.env.API_PREFIX`
|
|
||||||
- `process.env.APP_BASE`
|
|
||||||
- `process.env.CESIUM_BASE_URL`
|
|
||||||
|
|
||||||
### 配置层修改原则
|
|
||||||
|
|
||||||
- 影响部署路径时,同时检查 `base`、`publicPath`、构建脚本
|
|
||||||
- 影响 API 访问时,同时检查 `proxy.ts` 和 `src/app.tsx` 的 request prefix
|
|
||||||
- 影响 Cesium 资源时,不要绕开 `CESIUM_BASE_URL` 另造路径机制
|
|
||||||
|
|
||||||
### `config/proxy.ts`
|
|
||||||
|
|
||||||
已存在的代理重点:
|
|
||||||
|
|
||||||
- `/api-`
|
|
||||||
- `/goflymodel`
|
|
||||||
- `/rtc`
|
|
||||||
- `/terraform`
|
|
||||||
|
|
||||||
新增代理规则前先问自己:
|
|
||||||
|
|
||||||
- 是开发态临时代理,还是生产态正式访问路径?
|
|
||||||
- 这条规则是否应该进网关,而不是前端本地代理?
|
|
||||||
|
|
||||||
### `config/routes.ts`
|
|
||||||
|
|
||||||
主要业务域:
|
|
||||||
|
|
||||||
- `system`
|
|
||||||
- `orders`
|
|
||||||
- `device`
|
|
||||||
- `log`
|
|
||||||
- `search`
|
|
||||||
- `files`
|
|
||||||
|
|
||||||
新增页面时:
|
|
||||||
|
|
||||||
- 优先挂到已有业务域下
|
|
||||||
- 保持与旧菜单 URL 兼容
|
|
||||||
- 普通后台页面默认走 `@/layouts/BasicLayout`
|
|
||||||
|
|
||||||
## 6. 页面开发规则
|
|
||||||
|
|
||||||
### 页面职责
|
|
||||||
|
|
||||||
页面负责:
|
|
||||||
|
|
||||||
- 组织查询区、操作区、表格区、弹窗区
|
|
||||||
- 管理页面级状态
|
|
||||||
- 调用 service
|
|
||||||
- 组合通用组件
|
|
||||||
|
|
||||||
页面不负责:
|
|
||||||
|
|
||||||
- 直接写大量裸请求
|
|
||||||
- 复制通用下载/导出/加密逻辑
|
|
||||||
- 重复实现租户缓存或登录态处理
|
|
||||||
|
|
||||||
### 列表页默认长相
|
|
||||||
|
|
||||||
- 优先 ProTable / Ant Design Pro 风格
|
|
||||||
- 查询区、工具栏、表格区分层清晰
|
|
||||||
- 批量操作与单行操作分离
|
|
||||||
- 页面如果受租户影响,优先在工具栏接入 `TenantScopeFilter`
|
|
||||||
|
|
||||||
### 复杂页面建议拆法
|
|
||||||
|
|
||||||
优先拆成:
|
|
||||||
|
|
||||||
1. 页面容器
|
|
||||||
2. 表格或主展示区
|
|
||||||
3. 查询条件区
|
|
||||||
4. 编辑弹窗/抽屉
|
|
||||||
5. service
|
|
||||||
6. 页面专属 hooks 或 utils
|
|
||||||
|
|
||||||
## 7. 组件开发规则
|
|
||||||
|
|
||||||
### 统一组件规范
|
|
||||||
|
|
||||||
- 一律函数组件 + Hooks
|
|
||||||
- Props 必须显式定义 TypeScript 类型
|
|
||||||
- 优先保持低副作用、低耦合、可复用
|
|
||||||
- 页面通用视觉组件优先放到 `src/components/ui/`
|
|
||||||
|
|
||||||
### 优先复用的现成组件
|
|
||||||
|
|
||||||
- `TenantScopeFilter`
|
|
||||||
- `ActionBar`
|
|
||||||
- `GradientButton`
|
|
||||||
- `GlassCard`
|
|
||||||
- `ThemeSwitch`
|
|
||||||
- `PageHeaderPlus`
|
|
||||||
|
|
||||||
### 组件设计原则
|
|
||||||
|
|
||||||
- 复用价值高的交互下沉到组件层
|
|
||||||
- 单页面专属又很重的块,不要强行抽成“伪通用”组件
|
|
||||||
- 组件内部不要私自接管全局登录态或全局路由行为
|
|
||||||
|
|
||||||
## 8. Service 层规则
|
|
||||||
|
|
||||||
### 基本要求
|
|
||||||
|
|
||||||
- 所有请求默认进入 `src/services/`
|
|
||||||
- 一个文件对应一个业务域
|
|
||||||
- 统一使用 `request('/api-xxx/...')`
|
|
||||||
- 统一处理参数映射和返回兼容
|
|
||||||
|
|
||||||
### Service 层该做什么
|
|
||||||
|
|
||||||
- 管理接口路径
|
|
||||||
- 管理请求方法和参数
|
|
||||||
- 处理返回数据兼容
|
|
||||||
- 隔离页面与后端协议细节
|
|
||||||
|
|
||||||
### Service 层不该做什么
|
|
||||||
|
|
||||||
- 不要掺杂大量页面状态
|
|
||||||
- 不要做重 UI 的逻辑
|
|
||||||
- 不要重新实现 token 注入
|
|
||||||
|
|
||||||
### 已有参考
|
|
||||||
|
|
||||||
- `src/services/login.ts`
|
|
||||||
- `src/services/tenant.ts`
|
|
||||||
- `src/services/orders.ts`
|
|
||||||
|
|
||||||
### 写新 service 的默认模板
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import { request } from 'umi';
|
|
||||||
|
|
||||||
export async function queryExample(params: Record<string, unknown>) {
|
|
||||||
return request('/api-example/path', {
|
|
||||||
method: 'GET',
|
|
||||||
params,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function saveExample(data: Record<string, unknown>) {
|
|
||||||
return request('/api-example/path', {
|
|
||||||
method: 'POST',
|
|
||||||
data,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 9. Utils 与 Hooks 规则
|
|
||||||
|
|
||||||
### `src/utils/` 已有重点能力
|
|
||||||
|
|
||||||
- `request.ts`
|
|
||||||
- `download.ts`
|
|
||||||
- `export.ts`
|
|
||||||
- `rsaUtil.ts`
|
|
||||||
- `securityUtil.ts`
|
|
||||||
- `tenantCache.ts`
|
|
||||||
|
|
||||||
### 什么时候放 utils
|
|
||||||
|
|
||||||
- 与 React 生命周期无关
|
|
||||||
- 跨页面可复用
|
|
||||||
- 纯逻辑、下载、导出、加密、缓存工具
|
|
||||||
|
|
||||||
### 什么时候放 hooks
|
|
||||||
|
|
||||||
- 跟组件生命周期、effect、状态协同强相关
|
|
||||||
- 需要被多个页面/组件复用
|
|
||||||
- 典型例子:`src/hooks/useSecurity.ts`
|
|
||||||
|
|
||||||
### 不要放错层
|
|
||||||
|
|
||||||
- 单纯对象转换,不要写成 hook
|
|
||||||
- 页面专属临时状态,不要塞进 utils
|
|
||||||
|
|
||||||
## 10. 布局与主题规则
|
|
||||||
|
|
||||||
### 布局
|
|
||||||
|
|
||||||
`src/layouts/BasicLayout.tsx` 负责:
|
|
||||||
|
|
||||||
- 主后台壳层
|
|
||||||
- 菜单和路由联动
|
|
||||||
- 面包屑
|
|
||||||
- 账户区
|
|
||||||
- 统一框架风格
|
|
||||||
|
|
||||||
规则:
|
|
||||||
|
|
||||||
- 普通后台页默认挂在 `BasicLayout` 下
|
|
||||||
- 不要为普通业务页再造一层平行顶层布局
|
|
||||||
|
|
||||||
### 主题
|
|
||||||
|
|
||||||
这个项目是双层主题体系:
|
|
||||||
|
|
||||||
1. Umi `theme` 配置 Ant Design 4 基础 token
|
|
||||||
2. `src/theme.tsx` + `src/theme/modern.less` + `src/global.less` 做增强和运行时切换
|
|
||||||
|
|
||||||
样式开发要求:
|
|
||||||
|
|
||||||
- 优先复用已有变量、阴影、渐变、间距
|
|
||||||
- 不要到处写魔法色值
|
|
||||||
- 保持现代后台而不是另起一套审美体系
|
|
||||||
|
|
||||||
## 11. 登录、安全、租户三条红线
|
|
||||||
|
|
||||||
### 登录与安全
|
|
||||||
|
|
||||||
- 登录页:`src/pages/user/Login`
|
|
||||||
- 登录 service:`src/services/login.ts`
|
|
||||||
- 前端密码加密:`jsencrypt`
|
|
||||||
- Token 存储:
|
|
||||||
- `sessionStorage.access_token`
|
|
||||||
- `sessionStorage.current_user`
|
|
||||||
|
|
||||||
禁止:
|
|
||||||
|
|
||||||
- 裸写明文密码提交流程替换现有逻辑
|
|
||||||
- 绕开全局 request 拦截器单独处理认证头
|
|
||||||
|
|
||||||
### 租户
|
|
||||||
|
|
||||||
默认判断:
|
|
||||||
|
|
||||||
- 该页面数据是否按租户隔离?
|
|
||||||
- 如果是,优先接入 `TenantScopeFilter`
|
|
||||||
|
|
||||||
禁止:
|
|
||||||
|
|
||||||
- 页面自己维护另一份租户树缓存
|
|
||||||
- 页面自己发明新的“包含子租户”参数语义
|
|
||||||
- 每个接口手写重复租户拼接逻辑而不复用现有设施
|
|
||||||
|
|
||||||
## 12. 3D / 地图相关边界
|
|
||||||
|
|
||||||
虽然它是管理后台,但已内置 3D 能力:
|
|
||||||
|
|
||||||
- 路由:
|
|
||||||
- `/device/3dModel.html`
|
|
||||||
- `/device/mapDashboard.html`
|
|
||||||
- 代理:
|
|
||||||
- `/goflymodel`
|
|
||||||
- `/rtc`
|
|
||||||
- `/terraform`
|
|
||||||
|
|
||||||
规则:
|
|
||||||
|
|
||||||
- 资源路径走 `CESIUM_BASE_URL`
|
|
||||||
- 模型/流媒体跨域优先沿用现有代理策略
|
|
||||||
- 不要随意替换资源根路径方案
|
|
||||||
|
|
||||||
## 13. TypeScript 规则
|
|
||||||
|
|
||||||
- 必须尊重 `strict: true`
|
|
||||||
- 优先写明确接口/类型
|
|
||||||
- 路径别名统一使用 `@/`
|
|
||||||
- 全局声明与补充类型优先查看:
|
|
||||||
- `src/typings.d.ts`
|
|
||||||
- `src/types/`
|
|
||||||
|
|
||||||
严格禁止:
|
|
||||||
|
|
||||||
- `as any`
|
|
||||||
- `@ts-ignore`
|
|
||||||
- `@ts-expect-error`
|
|
||||||
|
|
||||||
## 14. 典型工作流
|
|
||||||
|
|
||||||
### 新增后台页面
|
|
||||||
|
|
||||||
1. 在 `config/routes.ts` 补路由,优先挂已有业务域
|
|
||||||
2. 在 `src/pages/<domain>/` 建页面目录
|
|
||||||
3. 在 `src/services/<domain>.ts` 补接口
|
|
||||||
4. 判断是否需要接入 `TenantScopeFilter`
|
|
||||||
5. 优先复用 `src/components/ui/` 组件
|
|
||||||
6. 样式继承现有主题变量
|
|
||||||
7. 确保响应兼容 `resp_code`
|
|
||||||
|
|
||||||
### 从旧 `react-web` 迁移页面
|
|
||||||
|
|
||||||
1. 先保功能等价,不先追求重写
|
|
||||||
2. 保持接口地址、菜单 URL、参数语义尽量不变
|
|
||||||
3. 把旧页拆成:页面 / 组件 / service / utils
|
|
||||||
4. 把租户过滤从页面私有逻辑改为基础设施接入
|
|
||||||
5. 再做局部 UI 统一
|
|
||||||
|
|
||||||
## 15. 决策清单
|
|
||||||
|
|
||||||
动手前自检:
|
|
||||||
|
|
||||||
- 这次改动是否破坏旧菜单 URL 兼容?
|
|
||||||
- 这个请求是否应该放进现有 `src/services/`?
|
|
||||||
- 这个页面是否应该接入租户过滤?
|
|
||||||
- 是否复用了已有下载/导出/安全/缓存工具?
|
|
||||||
- 是否仍然处在 React 17 + Antd4 + Umi3 的边界内?
|
|
||||||
- 是否兼容 `resp_code / resp_msg / data`?
|
|
||||||
|
|
||||||
## 16. 明确禁止事项
|
|
||||||
|
|
||||||
- 擅自升级 React 18 / Ant Design 5 写法
|
|
||||||
- 在页面中大量内联请求绕开 service
|
|
||||||
- 为普通页面重复造布局壳层
|
|
||||||
- 绕开全局 request 拦截器自行接管授权
|
|
||||||
- 批量移除 `.html` 路径兼容
|
|
||||||
- 新造一套与现有主题冲突的视觉体系
|
|
||||||
|
|
||||||
## 17. 优先参考文件
|
|
||||||
|
|
||||||
- `zlt-web/react-web-next/config/config.ts`
|
|
||||||
- `zlt-web/react-web-next/config/routes.ts`
|
|
||||||
- `zlt-web/react-web-next/config/proxy.ts`
|
|
||||||
- `zlt-web/react-web-next/src/app.tsx`
|
|
||||||
- `zlt-web/react-web-next/src/layouts/BasicLayout.tsx`
|
|
||||||
- `zlt-web/react-web-next/src/components/TenantScopeFilter/index.tsx`
|
|
||||||
- `zlt-web/react-web-next/src/services/login.ts`
|
|
||||||
- `zlt-web/react-web-next/src/services/tenant.ts`
|
|
||||||
- `zlt-web/react-web-next/src/services/orders.ts`
|
|
||||||
- `zlt-web/react-web-next/src/utils/tenantCache.ts`
|
|
||||||
- `zlt-web/react-web-next/src/utils/download.ts`
|
|
||||||
- `zlt-web/react-web-next/src/utils/export.ts`
|
|
||||||
- `zlt-web/react-web-next/src/theme.tsx`
|
|
||||||
- `zlt-web/react-web-next/src/theme/modern.less`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*最后更新: 2026-04-01*
|
|
||||||
@@ -1,463 +0,0 @@
|
|||||||
# yingyan 项目 Skill
|
|
||||||
|
|
||||||
**适用范围**: `zlt-web/yingyan`
|
|
||||||
|
|
||||||
**强制要求**: 在该项目中进行 3D 可视化、监控大屏、客户端 Pad、海事场景、地图控制、实时通信相关开发时,默认以本 Skill 为第一约束;除非用户明确要求,否则不要偏离这里定义的结构、边界和实现方式。
|
|
||||||
|
|
||||||
## 1. 项目一句话定义
|
|
||||||
|
|
||||||
`yingyan` 是“鹰眼”3D 可视化管控平台,不是传统后台 CRUD 前端:
|
|
||||||
|
|
||||||
- 以监控大屏、海事场景、3D 地图、Pad 客户端为核心产品形态
|
|
||||||
- 以 Cesium、SSE、WebSocket、深色科技风为核心实现特征
|
|
||||||
- 复用管理端认证、租户、服务接口,但交互模型明显不同于普通后台
|
|
||||||
- 重点不是表单堆砌,而是场景容器、可视化面板、实时状态与地图交互
|
|
||||||
|
|
||||||
## 2. 技术边界
|
|
||||||
|
|
||||||
### 必须遵守
|
|
||||||
|
|
||||||
- React 18
|
|
||||||
- UmiJS 3.5
|
|
||||||
- Ant Design 5
|
|
||||||
- `@ant-design/pro-components` 2.x
|
|
||||||
- TypeScript 5.9,且 `strict: true`
|
|
||||||
- Ant Design 5 `ConfigProvider` 主题体系
|
|
||||||
- Cesium 1.110
|
|
||||||
- `dayjs`
|
|
||||||
|
|
||||||
### 不要擅自做的事
|
|
||||||
|
|
||||||
- 不要把 `react-web-next` 的 Ant Design 4 / Less token 方案直接搬进来
|
|
||||||
- 不要把大屏/地图页改造成普通后台管理页布局
|
|
||||||
- 不要绕开现有 Cesium hook、实时连接 hook、编辑器子系统另造平行实现
|
|
||||||
- 不要把客户端 `/client` 的认证逻辑和管理端 token 逻辑混用
|
|
||||||
|
|
||||||
## 3. 先认清这 6 个核心事实
|
|
||||||
|
|
||||||
### 3.1 这不是普通后台,而是多形态可视化平台
|
|
||||||
|
|
||||||
- 路由同时覆盖管理登录、客户端登录、监控大屏、海事大屏、3D 地图
|
|
||||||
- 页面差异很大,但底层仍共用 Umi、request、租户、部分服务接口
|
|
||||||
- 你做功能前,先判断它属于后台管理、地图场景、客户端 Pad 还是大屏信息展示
|
|
||||||
|
|
||||||
### 3.2 主题体系是 Ant Design 5 + 深色科技风
|
|
||||||
|
|
||||||
- `config/config.ts` 中 `antd: false`
|
|
||||||
- 主题由 `src/theme.tsx` 中的 `ConfigProvider` 接管
|
|
||||||
- 主色、成功色、暗色算法都已统一设定
|
|
||||||
- **不要回退到 Ant Design 4 的 Less 变量主题改法**
|
|
||||||
|
|
||||||
### 3.3 这是双登录体系,不是单一 token 模型
|
|
||||||
|
|
||||||
- 管理端使用:
|
|
||||||
- `sessionStorage.access_token`
|
|
||||||
- `sessionStorage.current_user`
|
|
||||||
- 客户端 `/client` 使用:
|
|
||||||
- `sessionStorage.client_device_sn`
|
|
||||||
- 新逻辑必须先区分当前路径属于管理端还是客户端
|
|
||||||
|
|
||||||
### 3.4 实时数据是基础设施,不是页面临时能力
|
|
||||||
|
|
||||||
- 已有 SSE hook
|
|
||||||
- 已有设备控制 WebSocket service
|
|
||||||
- 已有视频流代理
|
|
||||||
- 页面应消费状态,而不是在 JSX 内到处散写连接生命周期
|
|
||||||
|
|
||||||
### 3.5 3D 能力已经形成子系统,不要单文件硬写
|
|
||||||
|
|
||||||
- 已有 `MapContainer`
|
|
||||||
- 已有 `CesiumContainer`
|
|
||||||
- 已有 `RouteEditor`
|
|
||||||
- 已有 `BoundaryEditor`
|
|
||||||
- 已有 tileset / drone / boat / track / route renderer 等 hook
|
|
||||||
|
|
||||||
### 3.6 后端响应依然优先兼容 `resp_code`
|
|
||||||
|
|
||||||
默认优先兼容:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "success",
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
结论:
|
|
||||||
|
|
||||||
- 新增 service 时不要发明全新响应契约
|
|
||||||
- 页面层不要直接假设所有接口都已经是纯前端理想结构
|
|
||||||
|
|
||||||
## 4. 目录落位规则
|
|
||||||
|
|
||||||
```text
|
|
||||||
zlt-web/yingyan/
|
|
||||||
├─ config/
|
|
||||||
│ ├─ config.ts
|
|
||||||
│ ├─ proxy.ts
|
|
||||||
│ └─ routes.ts
|
|
||||||
├─ src/
|
|
||||||
│ ├─ app.tsx
|
|
||||||
│ ├─ global.less
|
|
||||||
│ ├─ theme.tsx
|
|
||||||
│ ├─ layouts/
|
|
||||||
│ ├─ pages/
|
|
||||||
│ ├─ services/
|
|
||||||
│ ├─ components/
|
|
||||||
│ ├─ hooks/
|
|
||||||
│ ├─ utils/
|
|
||||||
│ ├─ types/
|
|
||||||
│ └─ typings.d.ts
|
|
||||||
```
|
|
||||||
|
|
||||||
### 你改代码前先判断放哪层
|
|
||||||
|
|
||||||
- 页面容器、页面状态、主交互编排:`src/pages/`
|
|
||||||
- 复用组件、通用可视化面板、平台切换器:`src/components/`
|
|
||||||
- API、实时控制协议、后端接口封装:`src/services/`
|
|
||||||
- 纯工具、缓存、加密、协议辅助:`src/utils/`
|
|
||||||
- 与 React 生命周期强相关的 Cesium / SSE / 状态逻辑:`hooks` 或页面子目录内 hooks
|
|
||||||
- 顶层头部、布局槽位、统一壳层:`src/layouts/`
|
|
||||||
|
|
||||||
### 默认禁止
|
|
||||||
|
|
||||||
- 不要把 viewer 级逻辑直接堆进页面根组件
|
|
||||||
- 不要把页面专属临时状态塞进全局 utils
|
|
||||||
- 不要把通用面板复制到多个页面目录各自维护
|
|
||||||
|
|
||||||
## 5. 配置层规则
|
|
||||||
|
|
||||||
### `config/config.ts`
|
|
||||||
|
|
||||||
你需要知道它控制了:
|
|
||||||
|
|
||||||
- `antd: false`
|
|
||||||
- `routes.ts`
|
|
||||||
- 开发/生产差异化 `publicPath`
|
|
||||||
- `base` 与部署子路径
|
|
||||||
- `dynamicImport.loading`
|
|
||||||
- `process.env.API_PREFIX`
|
|
||||||
- `process.env.APP_BASE`
|
|
||||||
- `process.env.CESIUM_BASE_URL`
|
|
||||||
|
|
||||||
### 配置层修改原则
|
|
||||||
|
|
||||||
- 改部署路径时,同时检查 `base`、`publicPath`、构建脚本
|
|
||||||
- 改 API 访问时,同时检查 `proxy.ts` 与 `src/app.tsx` 中 request prefix
|
|
||||||
- 改 Cesium 资源路径时,不要绕开 `CESIUM_BASE_URL`
|
|
||||||
- 改主题时,优先改 `src/theme.tsx` 的 `ConfigProvider` 配置,而不是退回旧体系
|
|
||||||
|
|
||||||
### `config/proxy.ts`
|
|
||||||
|
|
||||||
已存在的代理重点:
|
|
||||||
|
|
||||||
- `/api-`
|
|
||||||
- `/goflymodel`
|
|
||||||
- `/rtc`
|
|
||||||
- `/terraform`
|
|
||||||
|
|
||||||
新增代理前先问自己:
|
|
||||||
|
|
||||||
- 这是开发期代理,还是正式线上路径?
|
|
||||||
- 是否应由网关、Nginx 或后端服务接管,而不是前端本地代理?
|
|
||||||
|
|
||||||
### `config/routes.ts`
|
|
||||||
|
|
||||||
核心页面包括:
|
|
||||||
|
|
||||||
- `/user/login`
|
|
||||||
- `/client/login`
|
|
||||||
- `/client`
|
|
||||||
- `/dashboard`
|
|
||||||
- `/maritime`
|
|
||||||
- `/map3d`
|
|
||||||
|
|
||||||
规则:
|
|
||||||
|
|
||||||
- 管理登录与客户端登录不挂主布局
|
|
||||||
- 主应用默认挂 `@/layouts/BlankLayout`
|
|
||||||
- 不要把地图页和大屏页硬改造成 ProLayout 导航壳层
|
|
||||||
|
|
||||||
## 6. 页面开发规则
|
|
||||||
|
|
||||||
### 页面职责
|
|
||||||
|
|
||||||
页面负责:
|
|
||||||
|
|
||||||
- 组织场景容器、面板、头部插槽、可视化区块
|
|
||||||
- 管理页面级状态
|
|
||||||
- 组合 hook 与 service
|
|
||||||
- 控制子组件装配关系
|
|
||||||
|
|
||||||
页面不负责:
|
|
||||||
|
|
||||||
- 直接维护大量 viewer 底层实体生命周期
|
|
||||||
- 到处手搓 SSE / WebSocket 连接
|
|
||||||
- 把复杂地图交互全部堆在单个组件中
|
|
||||||
|
|
||||||
### 不同页面类型的默认思路
|
|
||||||
|
|
||||||
#### 大屏页
|
|
||||||
|
|
||||||
- 强调信息区块、KPI、卡片、视觉层次
|
|
||||||
- 组件通常拆在对应页面的 `components/`
|
|
||||||
|
|
||||||
#### 地图页
|
|
||||||
|
|
||||||
- 强调容器 + 面板 + hook 分层
|
|
||||||
- viewer、实体、轨迹、绘制、加载逻辑优先下沉
|
|
||||||
|
|
||||||
#### 客户端页
|
|
||||||
|
|
||||||
- 强调沉浸式交互与状态联动
|
|
||||||
- 登录、导航、遥测、路线预览优先在 `src/pages/client/` 内自洽管理
|
|
||||||
|
|
||||||
## 7. 组件开发规则
|
|
||||||
|
|
||||||
### 统一组件规范
|
|
||||||
|
|
||||||
- 一律函数组件 + Hooks
|
|
||||||
- Props 必须显式定义 TypeScript 类型
|
|
||||||
- 复杂视觉页面拆成容器层、面板层、hook 层
|
|
||||||
- 复用价值高的场景组件优先抽离,不要复制实现
|
|
||||||
|
|
||||||
### 优先复用的现成组件
|
|
||||||
|
|
||||||
- `TenantScopeFilter`
|
|
||||||
- `PlatformSwitcher`
|
|
||||||
- `PageLoading`
|
|
||||||
|
|
||||||
### 地图/大屏组件设计原则
|
|
||||||
|
|
||||||
- 容器组件负责装配
|
|
||||||
- 面板组件负责展示和局部交互
|
|
||||||
- hook 负责副作用、场景对象、连接管理
|
|
||||||
- service 负责远端协议与接口
|
|
||||||
|
|
||||||
## 8. Service 层规则
|
|
||||||
|
|
||||||
### 基本要求
|
|
||||||
|
|
||||||
- 所有接口默认进入 `src/services/`
|
|
||||||
- 一个文件对应一个业务域
|
|
||||||
- 统一封装请求、参数映射、返回兼容
|
|
||||||
- 需要实时控制时,区分 HTTP service 和 WebSocket service
|
|
||||||
|
|
||||||
### 常见 service 领域
|
|
||||||
|
|
||||||
- `login.ts`
|
|
||||||
- `device.ts`
|
|
||||||
- `dashboard.ts`
|
|
||||||
- `mission.ts`
|
|
||||||
- `boatRoute.ts`
|
|
||||||
- `waterBoundary.ts`
|
|
||||||
- `threeDModel.ts`
|
|
||||||
- `maritime.ts`
|
|
||||||
- `tenant.ts`
|
|
||||||
- `deviceControlWs.ts`
|
|
||||||
|
|
||||||
### Service 层该做什么
|
|
||||||
|
|
||||||
- 管理接口路径和请求方法
|
|
||||||
- 隔离页面与后端协议细节
|
|
||||||
- 统一兼容 `resp_code / resp_msg / data`
|
|
||||||
- 为地图/航线/边界/模型等能力提供清晰 API
|
|
||||||
|
|
||||||
### Service 层不该做什么
|
|
||||||
|
|
||||||
- 不要塞入重 UI 逻辑
|
|
||||||
- 不要接管页面状态机
|
|
||||||
- 不要在 service 里重新实现布局或页面判断
|
|
||||||
|
|
||||||
## 9. Hooks 与实时通信规则
|
|
||||||
|
|
||||||
### 什么时候放 hooks
|
|
||||||
|
|
||||||
- 需要跟 React 生命周期绑定
|
|
||||||
- 需要管理连接、清理、副作用
|
|
||||||
- 需要复用 Cesium viewer、实体、轨迹、绘制逻辑
|
|
||||||
|
|
||||||
### 已有重点 hook 类型
|
|
||||||
|
|
||||||
- SSE:`useDroneSSE`、`useBoatSSE`、`useClientSSE`
|
|
||||||
- Tileset:`useTilesetLoader`
|
|
||||||
- 船舶/无人机轨迹与渲染:相关 Cesium hook
|
|
||||||
- 路线编辑:`useRouteDrawing`、`useCesiumRouteRenderer`、`useRouteValidation`
|
|
||||||
- 边界编辑:`useBoundaryDrawing`、`useCesiumBoundaryRenderer`
|
|
||||||
|
|
||||||
### 实时能力规则
|
|
||||||
|
|
||||||
- 建立连接、断线重连、释放资源必须封装在 hook 或 service 中
|
|
||||||
- 页面只消费状态与回调,不要直接到处 new 连接
|
|
||||||
- 组件卸载时必须有清理逻辑
|
|
||||||
|
|
||||||
## 10. 布局与主题规则
|
|
||||||
|
|
||||||
### 布局
|
|
||||||
|
|
||||||
`src/layouts/BlankLayout.tsx` 负责:
|
|
||||||
|
|
||||||
- 顶部栏
|
|
||||||
- 平台切换
|
|
||||||
- 租户过滤
|
|
||||||
- 用户菜单
|
|
||||||
- 大屏 / 海事 / 地图头部插槽
|
|
||||||
|
|
||||||
规则:
|
|
||||||
|
|
||||||
- `/dashboard`、`/maritime` 走大屏标题模式
|
|
||||||
- `/map3d` 通过 header slot 注入地图专属头部内容
|
|
||||||
- 不要把地图专属头部逻辑硬塞进普通布局分支
|
|
||||||
|
|
||||||
### 主题
|
|
||||||
|
|
||||||
主题核心在 `src/theme.tsx`:
|
|
||||||
|
|
||||||
- `ConfigProvider`
|
|
||||||
- 深色算法 `antdTheme.darkAlgorithm`
|
|
||||||
- 主色 `#00d4ff`
|
|
||||||
- 成功色 `#00ff88`
|
|
||||||
|
|
||||||
样式开发要求:
|
|
||||||
|
|
||||||
- 保持深色科技风一致性
|
|
||||||
- 强调玻璃面板、边框高亮、信息层次
|
|
||||||
- 浮层和地图覆盖物要兼顾可读性与点击区域
|
|
||||||
|
|
||||||
## 11. 登录、租户、客户端三条红线
|
|
||||||
|
|
||||||
### 登录
|
|
||||||
|
|
||||||
- 管理端登录页:`src/pages/user/Login`
|
|
||||||
- 客户端登录页:`src/pages/client/Login`
|
|
||||||
- 管理端和客户端认证逻辑必须区分处理
|
|
||||||
|
|
||||||
禁止:
|
|
||||||
|
|
||||||
- 把 `/client` 也按后台 token 模式处理
|
|
||||||
- 把后台未授权跳转逻辑直接复用到客户端页面
|
|
||||||
|
|
||||||
### 租户
|
|
||||||
|
|
||||||
- 管理端与大屏数据如果受租户影响,优先接入 `TenantScopeFilter`
|
|
||||||
- 缓存与 Token 联动优先沿用 `tenantCache`
|
|
||||||
|
|
||||||
禁止:
|
|
||||||
|
|
||||||
- 每个页面各自维护租户树副本
|
|
||||||
- 每个大屏组件私自再造租户过滤协议
|
|
||||||
|
|
||||||
### 客户端
|
|
||||||
|
|
||||||
- `/client` 下逻辑优先在该目录内部自洽封装
|
|
||||||
- 导航、遥测、预览、设备态等优先下沉 hook
|
|
||||||
|
|
||||||
## 12. 3D / 地图子系统边界
|
|
||||||
|
|
||||||
### 重点目录
|
|
||||||
|
|
||||||
- `src/pages/map3d/components/MapContainer/3d/`
|
|
||||||
- `src/pages/map3d/components/RouteEditor/`
|
|
||||||
- `src/pages/map3d/components/BoundaryEditor/`
|
|
||||||
- `src/services/threeDModel.ts`
|
|
||||||
|
|
||||||
### 已有核心能力
|
|
||||||
|
|
||||||
- 3D Tiles 模型加载
|
|
||||||
- 路线绘制与渲染
|
|
||||||
- 边界绘制与渲染
|
|
||||||
- 船舶轨迹渲染
|
|
||||||
- 相机飞行与聚焦
|
|
||||||
- 实时点位刷新
|
|
||||||
|
|
||||||
### 开发规则
|
|
||||||
|
|
||||||
- viewer 级副作用优先集中在容器/hook 层
|
|
||||||
- 不要在多个组件里重复创建全局场景逻辑
|
|
||||||
- 先查现有 RouteEditor / BoundaryEditor 基础设施,再决定是否扩展
|
|
||||||
|
|
||||||
## 13. TypeScript 规则
|
|
||||||
|
|
||||||
- 必须尊重 `strict: true`
|
|
||||||
- 复杂场景对象必须显式类型化
|
|
||||||
- 航点、边界、模型、设备状态、导航状态优先抽到类型文件
|
|
||||||
- 全局和场景类型优先查看:
|
|
||||||
- `src/typings.d.ts`
|
|
||||||
- `src/types/`
|
|
||||||
- 各子系统自己的 `types.ts`
|
|
||||||
|
|
||||||
严格禁止:
|
|
||||||
|
|
||||||
- `as any`
|
|
||||||
- `@ts-ignore`
|
|
||||||
- `@ts-expect-error`
|
|
||||||
|
|
||||||
## 14. 典型工作流
|
|
||||||
|
|
||||||
### 新增地图/3D 功能
|
|
||||||
|
|
||||||
1. 先判断属于容器、面板、hook 还是 service
|
|
||||||
2. 查现有 tileset / route / boundary / track 相关基础设施
|
|
||||||
3. 优先复用已有 hook 与 renderer
|
|
||||||
4. 补充必要的 service 封装
|
|
||||||
5. 做好卸载清理、实体清理、事件解绑
|
|
||||||
6. 保持深色科技风一致
|
|
||||||
|
|
||||||
### 新增大屏区块
|
|
||||||
|
|
||||||
1. 优先放对应页面 `components/`
|
|
||||||
2. 保持卡片、信息带、面板的视觉语言统一
|
|
||||||
3. 数据获取放 service,状态组装放页面或 hook
|
|
||||||
|
|
||||||
### 新增客户端能力
|
|
||||||
|
|
||||||
1. 优先放 `src/pages/client/` 内部
|
|
||||||
2. 先判断是否依赖设备号登录态
|
|
||||||
3. 导航/预览/遥测逻辑优先用 hook 管理
|
|
||||||
|
|
||||||
## 15. 决策清单
|
|
||||||
|
|
||||||
动手前自检:
|
|
||||||
|
|
||||||
- 当前逻辑是管理端、客户端、大屏还是地图页?
|
|
||||||
- 是否误用了后台 token 逻辑到 `/client`?
|
|
||||||
- 是否已有可复用的 Cesium hook、编辑器或 service?
|
|
||||||
- 这段逻辑应放 panel、hook、service 还是页面容器?
|
|
||||||
- 是否仍然在 Ant Design 5 + ConfigProvider + 深色科技风边界内?
|
|
||||||
- 是否兼容 `resp_code / resp_msg / data`?
|
|
||||||
- 是否考虑了连接清理、资源释放、viewer 生命周期?
|
|
||||||
|
|
||||||
## 16. 明确禁止事项
|
|
||||||
|
|
||||||
- 按 `react-web-next` 的 Antd4 思路改这个项目主题
|
|
||||||
- 在地图页重复造 viewer 生命周期管理
|
|
||||||
- 把 `/client` 与后台登录态混为一谈
|
|
||||||
- 把复杂实时连接逻辑直接塞进 JSX 页面
|
|
||||||
- 新增浅色后台风格破坏整体科技感
|
|
||||||
- 绕过现有 Cesium hook 和编辑器基础设施重新手搓一套平行系统
|
|
||||||
|
|
||||||
## 17. 优先参考文件
|
|
||||||
|
|
||||||
- `zlt-web/yingyan/config/config.ts`
|
|
||||||
- `zlt-web/yingyan/config/routes.ts`
|
|
||||||
- `zlt-web/yingyan/config/proxy.ts`
|
|
||||||
- `zlt-web/yingyan/src/app.tsx`
|
|
||||||
- `zlt-web/yingyan/src/theme.tsx`
|
|
||||||
- `zlt-web/yingyan/src/global.less`
|
|
||||||
- `zlt-web/yingyan/src/layouts/BlankLayout.tsx`
|
|
||||||
- `zlt-web/yingyan/src/components/TenantScopeFilter/index.tsx`
|
|
||||||
- `zlt-web/yingyan/src/components/PlatformSwitcher/index.tsx`
|
|
||||||
- `zlt-web/yingyan/src/services/device.ts`
|
|
||||||
- `zlt-web/yingyan/src/services/threeDModel.ts`
|
|
||||||
- `zlt-web/yingyan/src/services/deviceControlWs.ts`
|
|
||||||
- `zlt-web/yingyan/src/services/boatRoute.ts`
|
|
||||||
- `zlt-web/yingyan/src/services/waterBoundary.ts`
|
|
||||||
- `zlt-web/yingyan/src/pages/map3d/components/MapContainer/CesiumContainer.tsx`
|
|
||||||
- `zlt-web/yingyan/src/pages/map3d/components/RouteEditor/index.tsx`
|
|
||||||
- `zlt-web/yingyan/src/pages/map3d/components/BoundaryEditor/index.tsx`
|
|
||||||
- `zlt-web/yingyan/src/pages/client/index.tsx`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*最后更新: 2026-04-01*
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
# 仓库指南(Repository Guidelines)
|
|
||||||
|
|
||||||
## 语言与注释规范(Agent 专用)
|
|
||||||
- 所有交互回答必须使用中文(简体),包括解释、建议与错误信息。
|
|
||||||
- 代码片段中的注释、日志消息、文档内容与示例说明均应为中文;编程语言关键字与三方 API 标识符保持原文。
|
|
||||||
- 提交信息(commit)、合并请求(PR)描述与 Issue 标题/内容默认使用中文;涉及外部专有名词可保留英文缩写。
|
|
||||||
- 所有中文都使用utf-8
|
|
||||||
|
|
||||||
## 权限与执行策略
|
|
||||||
- 默认权限:Codex 在本仓库内可直接读取与编辑文件,无需额外审批。
|
|
||||||
- 命令执行:在具备网络访问权限时,可直接执行包含网络的命令(如依赖下载、API 请求、构建/测试脚本)。
|
|
||||||
- 安全边界:遵循最小影响原则,避免破坏性操作(如强制删除、重置历史、批量改名)。如确需此类操作,请在回复中明确风险与范围,并征得用户同意。
|
|
||||||
- 可追溯性:在回复或提交说明中简要标注关键命令、影响模块与文件路径,便于审计。
|
|
||||||
- Git 操作限制:除非用户明确要求,否则不要执行任何 Git 相关操作(包括但不限于 `commit`、`push`、`pull`、`merge`、`rebase`、`tag`、`branch`、`reset` 等)。如需读取 Git 元数据(如 `git log`、`git status`),也需先获得用户确认。
|
|
||||||
|
|
||||||
## 项目结构与模块组织
|
|
||||||
- 父聚合工程:`pom.xml`(Java 17,Spring Boot 3.1,Spring Cloud 2022)。
|
|
||||||
- 核心模块:
|
|
||||||
- `zlt-commons`(公共 starter、工具)
|
|
||||||
- `zlt-uaa`(认证),`zlt-gateway/sc-gateway`(API 网关)
|
|
||||||
- `zlt-business/*`(业务服务:用户/文件/订单等)
|
|
||||||
- `zlt-monitor/sc-admin`(监控),`zlt-config`(配置),`zlt-web/*`(前端)
|
|
||||||
- 标准目录:`src/main/java`、`src/main/resources`,单测放在 `src/test/java`。
|
|
||||||
|
|
||||||
## 构建、测试与本地运行
|
|
||||||
- 全量构建:`mvn -q -DskipTests clean package`
|
|
||||||
- 全量测试:`mvn -q test`
|
|
||||||
- 指定模块构建+测试:`mvn -pl zlt-business/user-center -am clean verify`
|
|
||||||
- 本地运行示例:
|
|
||||||
- 网关:`mvn -pl zlt-gateway/sc-gateway -am spring-boot:run`
|
|
||||||
- 认证:`mvn -pl zlt-uaa -am spring-boot:run`
|
|
||||||
- 从 JAR 运行:`java -jar zlt-gateway/sc-gateway/target/*.jar`
|
|
||||||
先决条件:JDK 17、Maven 3.8+。
|
|
||||||
|
|
||||||
## 编码风格与命名约定
|
|
||||||
- Java 使用 4 空格缩进、UTF-8、同一行左大括号。
|
|
||||||
- 包名使用 `com.central.*`;模块名称以 `zlt-*` 为前缀。
|
|
||||||
- 已使用处优先采用 Lombok 注解(如 `@Data`、`@Slf4j`)。
|
|
||||||
- 方法/字段使用 lowerCamelCase;类名使用 PascalCase。
|
|
||||||
|
|
||||||
## 测试规范
|
|
||||||
- 测试框架:JUnit 4 与 JUnit 5(按模块而定)。
|
|
||||||
- 用例命名以 `*Test.java` 结尾,放在 `src/test/java`。
|
|
||||||
- 为新增逻辑与关键路径补充单测;保持可重复、相互独立。
|
|
||||||
- 提 PR 前执行:`mvn -pl <module> -am test`。
|
|
||||||
|
|
||||||
## 提交与合并请求规范
|
|
||||||
- 采用约定式提交:`type(scope): 简要说明`,示例:`fix(订单中心): 修复事件处理逻辑`。
|
|
||||||
- 常见类型:`feat`、`fix`、`docs`、`refactor`、`test`、`chore`。
|
|
||||||
- 小步且描述清晰;必要时关联 Issue。
|
|
||||||
- PR 需包含:目的/影响、涉及模块、测试说明;前端改动请附截图(`zlt-web/*`)。
|
|
||||||
|
|
||||||
## 安全与配置提示
|
|
||||||
- 多模块使用 Nacos。请在本地提供 `spring.cloud.nacos.server-addr`,或在 `bootstrap.yml` 注释相关配置以单机运行。
|
|
||||||
- 外部依赖常见:MySQL/Redis/Elasticsearch。按模块检查 `application.yml` 的端口/连接串。
|
|
||||||
- 禁止提交密钥与凭据;使用环境变量或本地覆盖配置。
|
|
||||||
@@ -1,94 +1,104 @@
|
|||||||
# Go-Fly Platform Services - AI开发团队配置
|
# Central Platform - 企业级微服务脚手架 AI 开发指南
|
||||||
|
|
||||||
## 项目概述
|
## 项目概述
|
||||||
**项目类型**: 企业级Spring Cloud微服务平台
|
**项目类型**: 企业级Spring Cloud微服务脚手架
|
||||||
**主要业务**: 旅游景区管理 + IoT设备控制 + 支付分润系统
|
**主要功能**: 用户权限管理 + 文件存储 + 全文搜索 + 微服务基础设施
|
||||||
**技术栈**: Java 17 + Spring Cloud + React + MySQL + Redis + Elasticsearch
|
**技术栈**: Java 17 + Spring Cloud + React + MySQL + Redis + Elasticsearch
|
||||||
**复杂度**: Enterprise级 (8+专业领域)
|
**定位**: 通用后台管理系统脚手架
|
||||||
|
|
||||||
## 专属AI代理团队
|
## 核心模块
|
||||||
|
|
||||||
### 🏗️ 架构与基础设施层
|
### 🏗️ 基础设施层
|
||||||
- **spring-cloud-microservice-architect** (opus) - 微服务架构设计与优化专家
|
- **API网关** - Spring Cloud Gateway + Sentinel 限流熔断
|
||||||
- **mysql-data-architect** (sonnet) - MySQL数据库架构与MyBatis Plus优化专家
|
- **认证中心** - OAuth2 + JWT + Spring Security
|
||||||
- **file-storage-specialist** (sonnet) - 多云存储与CDN集成专家
|
- **配置中心** - Nacos Config 集中配置管理
|
||||||
|
- **监控中心** - Spring Boot Admin 应用监控
|
||||||
|
|
||||||
### 🎯 业务领域专家层
|
### 📦 公共组件库
|
||||||
- **tourism-business-specialist** (sonnet) - 旅游行业业务逻辑与景区管理专家
|
- **通用工具** - 核心工具类、通用配置
|
||||||
- **iot-device-integration-specialist** (sonnet) - IoT设备管理与大疆无人机集成专家
|
- **数据库集成** - MyBatis Plus + 多数据源
|
||||||
- **payment-system-specialist** (opus) - 微信支付服务商模式与分润系统专家
|
- **缓存集成** - Redis + Redisson 分布式锁
|
||||||
|
- **日志集成** - 集中式日志收集
|
||||||
|
- **搜索集成** - Elasticsearch 全文搜索
|
||||||
|
- **存储集成** - 多云对象存储(OSS、MinIO)
|
||||||
|
|
||||||
### 💻 前端与质量保障层
|
### 💼 业务模块
|
||||||
- **react-dashboard-developer** (sonnet) - React + Ant Design Pro仪表板开发专家
|
- **用户中心** - 用户、角色、权限、租户管理
|
||||||
- **platform-testing-specialist** (sonnet) - 微服务平台综合测试策略专家
|
- **文件中心** - 文件上传下载、多云存储
|
||||||
|
- **搜索中心** - 全文搜索服务
|
||||||
## 团队协作策略
|
- **代码生成器** - 基于数据库表的代码生成
|
||||||
|
|
||||||
### 🚀 智能任务分发规则
|
|
||||||
**Level 1-2 任务**: 直接调用对应专业代理
|
|
||||||
**Level 3-4 任务**: 根据依赖关系串行或并行调用
|
|
||||||
**Level 5 任务**: 由task-dispatch-director协调分发
|
|
||||||
|
|
||||||
### ⚡ 关键协作流程
|
|
||||||
1. **架构设计**: cto → spring-cloud-microservice-architect → mysql-data-architect
|
|
||||||
2. **业务开发**: 业务专家并行 → react-dashboard-developer → platform-testing-specialist
|
|
||||||
3. **集成测试**: 所有专家 → platform-testing-specialist → devops-engineer
|
|
||||||
|
|
||||||
### 🔧 依赖管理
|
|
||||||
- **高依赖**: 架构 → 数据 → 业务 (必须串行)
|
|
||||||
- **中等依赖**: 支付 ↔ 旅游, 设备 → 文件存储 (混合执行)
|
|
||||||
- **零依赖**: React组件 + 测试编写 (完全并行)
|
|
||||||
|
|
||||||
## 开发工作流
|
## 开发工作流
|
||||||
|
|
||||||
### 🎯 新功能开发
|
### 🎯 新功能开发
|
||||||
```bash
|
```bash
|
||||||
# 示例: 景区门票预订功能
|
# 示例: 添加新的业务模块
|
||||||
/ai "开发景区门票在线预订和支付功能"
|
参考 demo-center 示例模块创建新的业务服务
|
||||||
→ tourism-business-specialist (业务逻辑)
|
1. 创建模块目录结构
|
||||||
→ payment-system-specialist (支付集成)
|
2. 配置 pom.xml 依赖
|
||||||
→ react-dashboard-developer (管理界面)
|
3. 实现业务逻辑
|
||||||
→ platform-testing-specialist (端到端测试)
|
4. 注册到 Nacos
|
||||||
```
|
```
|
||||||
|
|
||||||
### 🔧 系统优化
|
### 🔧 系统优化
|
||||||
```bash
|
```bash
|
||||||
# 示例: 微服务性能优化
|
# 示例: 微服务性能优化
|
||||||
/ai "优化微服务间通信性能和数据库查询效率"
|
1. 分析服务调用链路
|
||||||
→ spring-cloud-microservice-architect (服务优化)
|
2. 优化数据库查询
|
||||||
→ mysql-data-architect (查询优化)
|
3. 添加缓存策略
|
||||||
→ platform-testing-specialist (性能测试)
|
4. 配置限流规则
|
||||||
```
|
```
|
||||||
|
|
||||||
### 🚨 问题排查
|
### 🚨 问题排查
|
||||||
```bash
|
```bash
|
||||||
# 示例: 支付异常排查
|
# 示例: 服务异常排查
|
||||||
/ai "排查订单支付失败和分润异常问题"
|
1. 查看 Nacos 服务注册状态
|
||||||
→ payment-system-specialist (支付逻辑检查)
|
2. 检查日志中心日志
|
||||||
→ mysql-data-architect (数据一致性验证)
|
3. 查看监控中心指标
|
||||||
→ platform-testing-specialist (问题复现测试)
|
4. 验证配置中心配置
|
||||||
```
|
```
|
||||||
|
|
||||||
## 技术规范
|
## 技术规范
|
||||||
|
|
||||||
### 📋 开发标准
|
### 📋 开发标准
|
||||||
- **后端**: Spring Boot 3.1.6 + MyBatis Plus 3.5.4 + Java 17
|
- **后端**: Spring Boot 3.1.6 + MyBatis Plus 3.5.4 + Java 17
|
||||||
- **前端**: React 17 + Ant Design 4.20 + UmiJS 3.5 + TypeScript
|
- **前端**: React 17 + Ant Design 4.20 + UmiJS 3.5
|
||||||
- **数据库**: MySQL 8.0 + Redis 7.0 + Elasticsearch 7.13
|
- **数据库**: MySQL 8.0 + Redis 7.0 + Elasticsearch 7.13
|
||||||
- **部署**: Docker + Kubernetes + Spring Cloud Gateway
|
- **部署**: Docker + Kubernetes + Nacos
|
||||||
|
|
||||||
### 🔒 安全要求
|
### 🔒 安全要求
|
||||||
- OAuth2 + JWT 认证授权
|
- OAuth2 + JWT 认证授权
|
||||||
- 支付数据加密存储
|
|
||||||
- 多租户数据隔离
|
- 多租户数据隔离
|
||||||
- API 访问频率限制
|
- API 访问频率限制
|
||||||
|
- 敏感数据加密存储
|
||||||
|
|
||||||
### 📊 监控指标
|
### 📊 性能指标
|
||||||
- 服务响应时间 < 200ms
|
- 服务响应时间 < 200ms
|
||||||
- 数据库查询优化 (N+1问题避免)
|
- 数据库查询优化(避免 N+1 问题)
|
||||||
- 支付成功率 > 99.9%
|
- 缓存命中率 > 80%
|
||||||
- 设备连接稳定性 > 99%
|
- 服务可用性 > 99.9%
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 环境准备
|
||||||
|
1. JDK 17+
|
||||||
|
2. Maven 3.6+
|
||||||
|
3. MySQL 8.0+
|
||||||
|
4. Redis 7.0+
|
||||||
|
5. Nacos 2.0+
|
||||||
|
|
||||||
|
### 启动步骤
|
||||||
|
1. 初始化数据库: `mysql < zlt-doc/database/init.sql`
|
||||||
|
2. 启动 Nacos
|
||||||
|
3. 启动网关 (9900)
|
||||||
|
4. 启动认证中心 (8000)
|
||||||
|
5. 启动用户中心 (7000)
|
||||||
|
6. 启动文件中心 (5000)
|
||||||
|
|
||||||
|
### 默认账号
|
||||||
|
- 用户名: `admin`
|
||||||
|
- 密码: `admin123`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**🚀 专属AI团队已就绪!使用 `/ai "具体任务描述"` 即可调用专业团队协作完成复杂任务。**
|
**🚀 企业级微服务脚手架,快速构建你的业务系统!**
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
# 贡献指南 (Contributing Guide)
|
|
||||||
|
|
||||||
## 快速开始
|
|
||||||
- Fork 本仓库(GitHub/Gitee),克隆到本地:`git clone <your_fork_url>`。
|
|
||||||
- 目标分支:优先提交到 `develop`(如无则 `master`)。
|
|
||||||
- 创建特性分支:`git checkout -b feature/<简要描述>`(缺陷用 `bugfix/`,文档用 `docs/`)。
|
|
||||||
- 环境要求:JDK 17,Maven 3.8+。
|
|
||||||
|
|
||||||
## 构建与本地运行
|
|
||||||
- 全量构建:`mvn -q -DskipTests clean package`
|
|
||||||
- 全量测试:`mvn -q test`
|
|
||||||
- 指定模块构建+测试:`mvn -pl zlt-business/user-center -am clean verify`
|
|
||||||
- 本地运行示例:
|
|
||||||
- 网关:`mvn -pl zlt-gateway/sc-gateway -am spring-boot:run`
|
|
||||||
- 认证:`mvn -pl zlt-uaa -am spring-boot:run`
|
|
||||||
- 从 JAR 运行:`java -jar zlt-gateway/sc-gateway/target/*.jar`
|
|
||||||
|
|
||||||
## 代码风格
|
|
||||||
- Java:4 空格缩进、UTF-8、左大括号同行。
|
|
||||||
- 包命名:`com.central.*`;模块命名:`zlt-*`。
|
|
||||||
- 项目已使用 Lombok(如 `@Data`、`@Slf4j`),保持一致。
|
|
||||||
|
|
||||||
## 测试要求
|
|
||||||
- 测试框架:JUnit 4/5(按模块而定)。
|
|
||||||
- 测试类放在 `src/test/java`,命名以 `*Test.java` 结尾。
|
|
||||||
- 为新增/变更逻辑补充单测;尽量使用 mock,避免依赖真实外部服务。
|
|
||||||
- 提交前运行:`mvn -pl <module> -am test`,确保通过。
|
|
||||||
|
|
||||||
## 提交规范(Conventional Commits)
|
|
||||||
- 格式:`type(scope): 简要说明`,示例:`fix(订单中心): 修复事件处理逻辑`。
|
|
||||||
- 常用类型:`feat`、`fix`、`docs`、`refactor`、`test`、`chore`。
|
|
||||||
- 正文可描述动机/实现要点;页脚关联问题:`Closes #123`。
|
|
||||||
|
|
||||||
## Pull Request 规范
|
|
||||||
- 内容包含:变更目的与影响、涉及模块、测试方式与结果;前端改动(`zlt-web/*`)请附截图。
|
|
||||||
- 保持 PR 粒度清晰、可审查;避免混入无关格式化改动。
|
|
||||||
- 确保构建与测试通过,冲突已解决。
|
|
||||||
|
|
||||||
## 配置与安全
|
|
||||||
- 多模块使用 Nacos;本地可提供 `spring.cloud.nacos.server-addr`,或在 `bootstrap.yml` 注释相关配置以单机运行。
|
|
||||||
- 常见外部依赖:MySQL/Redis/Elasticsearch。按模块检查 `application.yml`。
|
|
||||||
- 禁止提交密钥、证书与账户;使用环境变量或本地覆盖配置。
|
|
||||||
|
|
||||||
## 问题反馈
|
|
||||||
- 提交 Issue 时请附:期望/实际结果、复现步骤、相关日志与环境信息(模块名、版本、OS、JDK)。
|
|
||||||
+168
@@ -0,0 +1,168 @@
|
|||||||
|
# 快速开始指南
|
||||||
|
|
||||||
|
本指南将帮助你快速搭建和运行 Central Platform 微服务脚手架。
|
||||||
|
|
||||||
|
## 前置准备
|
||||||
|
|
||||||
|
### 1. 安装必要软件
|
||||||
|
|
||||||
|
- **JDK 17**: [下载地址](https://www.oracle.com/java/technologies/downloads/)
|
||||||
|
- **Maven 3.6+**: [下载地址](https://maven.apache.org/download.cgi)
|
||||||
|
- **MySQL 8.0+**: [下载地址](https://dev.mysql.com/downloads/mysql/)
|
||||||
|
- **Redis 7.0+**: [下载地址](https://redis.io/download)
|
||||||
|
- **Nacos 2.0+**: [下载地址](https://github.com/alibaba/nacos/releases)
|
||||||
|
|
||||||
|
### 2. 验证安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
java -version # 应显示 Java 17
|
||||||
|
mvn -version # 应显示 Maven 3.6+
|
||||||
|
mysql --version # 应显示 MySQL 8.0+
|
||||||
|
redis-server --version # 应显示 Redis 7.0+
|
||||||
|
```
|
||||||
|
|
||||||
|
## 第一步:数据库初始化
|
||||||
|
|
||||||
|
### 1. 创建数据库
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mysql -u root -p
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 执行初始化脚本
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mysql -u root -p < zlt-doc/database/init.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
脚本会自动创建:
|
||||||
|
- 数据库 `central_platform`
|
||||||
|
- 核心表(用户、角色、菜单等)
|
||||||
|
- 默认管理员账号(admin/admin123)
|
||||||
|
|
||||||
|
## 第二步:启动 Nacos
|
||||||
|
|
||||||
|
### 1. 下载并解压 Nacos
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wget https://github.com/alibaba/nacos/releases/download/2.2.0/nacos-server-2.2.0.tar.gz
|
||||||
|
tar -xvf nacos-server-2.2.0.tar.gz
|
||||||
|
cd nacos
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 单机模式启动
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Linux/Mac
|
||||||
|
sh bin/startup.sh -m standalone
|
||||||
|
|
||||||
|
# Windows
|
||||||
|
cmd bin/startup.cmd -m standalone
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 访问控制台
|
||||||
|
|
||||||
|
- 地址: http://localhost:8848/nacos
|
||||||
|
- 账号: nacos
|
||||||
|
- 密码: nacos
|
||||||
|
|
||||||
|
## 第三步:启动 Redis
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Linux/Mac
|
||||||
|
redis-server
|
||||||
|
|
||||||
|
# Windows
|
||||||
|
redis-server.exe
|
||||||
|
```
|
||||||
|
|
||||||
|
## 第四步:编译项目
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd central-platform
|
||||||
|
mvn clean install -DskipTests
|
||||||
|
```
|
||||||
|
|
||||||
|
## 第五步:启动服务
|
||||||
|
|
||||||
|
### 方式一:IDE 启动(推荐开发环境)
|
||||||
|
|
||||||
|
按以下顺序启动:
|
||||||
|
|
||||||
|
1. **网关服务** - `zlt-gateway/sc-gateway/src/main/java/com/central/gateway/GatewayApp.java`
|
||||||
|
2. **认证中心** - `zlt-uaa/src/main/java/com/central/oauth/UaaServerApplication.java`
|
||||||
|
3. **用户中心** - `zlt-business/user-center/src/main/java/com/central/user/UserCenterApplication.java`
|
||||||
|
4. **文件中心** - `zlt-business/file-center/src/main/java/com/central/file/FileCenterApplication.java`
|
||||||
|
|
||||||
|
### 方式二:命令行启动
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 启动网关
|
||||||
|
cd zlt-gateway/sc-gateway
|
||||||
|
mvn spring-boot:run
|
||||||
|
|
||||||
|
# 启动认证中心
|
||||||
|
cd zlt-uaa
|
||||||
|
mvn spring-boot:run
|
||||||
|
|
||||||
|
# 启动用户中心
|
||||||
|
cd zlt-business/user-center
|
||||||
|
mvn spring-boot:run
|
||||||
|
|
||||||
|
# 启动文件中心
|
||||||
|
cd zlt-business/file-center
|
||||||
|
mvn spring-boot:run
|
||||||
|
```
|
||||||
|
|
||||||
|
## 第六步:验证服务
|
||||||
|
|
||||||
|
### 1. 检查 Nacos 服务注册
|
||||||
|
|
||||||
|
访问 http://localhost:8848/nacos,在"服务管理 > 服务列表"中应该看到:
|
||||||
|
- sc-gateway
|
||||||
|
- uaa-server
|
||||||
|
- user-center
|
||||||
|
- file-center
|
||||||
|
|
||||||
|
### 2. 访问 API 文档
|
||||||
|
|
||||||
|
http://localhost:9900/doc.html
|
||||||
|
|
||||||
|
### 3. 测试登录接口
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST "http://localhost:9900/api-uaa/oauth/token" \
|
||||||
|
-H "Authorization: Basic d2ViQXBwOndlYkFwcA==" \
|
||||||
|
-d "username=admin&password=admin123&grant_type=password"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常见问题
|
||||||
|
|
||||||
|
### 1. 端口被占用
|
||||||
|
|
||||||
|
修改各服务的 `application.yml` 中的 `server.port` 配置。
|
||||||
|
|
||||||
|
### 2. Nacos 连接失败
|
||||||
|
|
||||||
|
检查 `bootstrap.yml` 中的 Nacos 地址配置:
|
||||||
|
```yaml
|
||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: localhost:8848
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 数据库连接失败
|
||||||
|
|
||||||
|
检查 Nacos 配置中心的数据库配置。
|
||||||
|
|
||||||
|
## 下一步
|
||||||
|
|
||||||
|
- 查看 [开发指南](./DEVELOPMENT.md)
|
||||||
|
- 了解 [架构设计](./ARCHITECTURE.md)
|
||||||
|
- 参考 [API 文档](http://localhost:9900/doc.html)
|
||||||
|
|
||||||
|
## 获取帮助
|
||||||
|
|
||||||
|
- GitHub Issues: https://github.com/zlt2000/microservices-platform/issues
|
||||||
@@ -1,47 +1,123 @@
|
|||||||
|
# Central Platform - 企业级微服务脚手架
|
||||||
|
|
||||||
|
[](https://www.oracle.com/java/)
|
||||||
|
[](https://spring.io/projects/spring-boot)
|
||||||
|
[](https://spring.io/projects/spring-cloud)
|
||||||
|
[](https://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
|
||||||
|
## 项目简介
|
||||||
|
|
||||||
|
Central Platform 是一个基于 Spring Cloud 的企业级微服务脚手架,提供完整的微服务基础设施和通用业务模块,帮助快速构建企业级应用。
|
||||||
|
|
||||||
|
### 核心特性
|
||||||
|
|
||||||
|
- ✅ **微服务架构** - 基于 Spring Cloud 2022.0.4
|
||||||
|
- ✅ **服务治理** - Nacos 服务注册发现与配置中心
|
||||||
|
- ✅ **API 网关** - Spring Cloud Gateway + Sentinel 限流熔断
|
||||||
|
- ✅ **认证授权** - OAuth2 + JWT + Spring Security
|
||||||
|
- ✅ **多租户支持** - 完整的多租户数据隔离方案
|
||||||
|
- ✅ **分布式缓存** - Redis + Redisson 分布式锁
|
||||||
|
- ✅ **数据库** - MyBatis Plus + 多数据源
|
||||||
|
- ✅ **全文搜索** - Elasticsearch 集成
|
||||||
|
- ✅ **文件存储** - 多云存储支持(阿里云OSS、七牛云、MinIO)
|
||||||
|
- ✅ **监控中心** - Spring Boot Admin 应用监控
|
||||||
|
- ✅ **代码生成** - 基于数据库表的代码生成器
|
||||||
|
|
||||||
|
## 技术栈
|
||||||
|
|
||||||
|
| 技术 | 版本 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| Java | 17 | 编程语言 |
|
||||||
|
| Spring Boot | 3.1.6 | 应用框架 |
|
||||||
|
| Spring Cloud | 2022.0.4 | 微服务框架 |
|
||||||
|
| Spring Cloud Alibaba | 2022.0.0.0 | 阿里云组件 |
|
||||||
|
| MyBatis Plus | 3.5.4.1 | ORM 框架 |
|
||||||
|
| MySQL | 8.0+ | 关系数据库 |
|
||||||
|
| Redis | 7.0+ | 缓存数据库 |
|
||||||
|
| Elasticsearch | 7.13.4 | 搜索引擎 |
|
||||||
|
| Nacos | Latest | 注册中心/配置中心 |
|
||||||
|
| Sentinel | Latest | 限流熔断 |
|
||||||
|
|
||||||
|
## 模块说明
|
||||||
|
|
||||||
## 5. 模块说明
|
|
||||||
```lua
|
```lua
|
||||||
central-platform -- 父项目,公共依赖
|
central-platform -- 父项目,公共依赖
|
||||||
│ ├─zlt-business -- 业务模块一级工程
|
│ ├─zlt-business -- 业务模块一级工程
|
||||||
│ │ ├─user-center -- 用户中心[7000]
|
│ │ ├─user-center -- 用户中心[7000]
|
||||||
│ │ ├─file-center -- 文件中心[5000]
|
│ │ ├─file-center -- 文件中心[5000]
|
||||||
│ │ ├─code-generator -- 代码生成器[7300]
|
|
||||||
│ │ ├─search-center -- 搜索中心
|
│ │ ├─search-center -- 搜索中心
|
||||||
│ │ │ ├─search-client -- 搜索中心客户端
|
│ │ │ ├─search-client -- 搜索中心客户端
|
||||||
│ │ │ ├─search-server -- 搜索中心服务端[7100]
|
│ │ │ ├─search-server -- 搜索中心服务端[7100]
|
||||||
│ │─zlt-commons -- 通用工具一级工程
|
│ │ ├─code-generator -- 代码生成器[7300]
|
||||||
│ │ ├─zlt-auth-client-spring-boot-starter -- 封装spring security client端的通用操作逻辑
|
│ │ └─demo-center -- 示例模块[8100]
|
||||||
│ │ ├─zlt-common-core -- 封装通用操作逻辑
|
│ ├─zlt-commons -- 通用工具一级工程
|
||||||
│ │ ├─zlt-common-spring-boot-starter -- 封装通用操作逻辑
|
│ │ ├─zlt-common-core -- 核心工具类
|
||||||
│ │ ├─zlt-db-spring-boot-starter -- 封装数据库通用操作逻辑
|
│ │ ├─zlt-common-spring-boot-starter -- 通用配置
|
||||||
│ │ ├─zlt-log-spring-boot-starter -- 封装log通用操作逻辑
|
│ │ ├─zlt-db-spring-boot-starter -- 数据库集成
|
||||||
│ │ ├─zlt-redis-spring-boot-starter -- 封装Redis通用操作逻辑
|
│ │ ├─zlt-redis-spring-boot-starter -- Redis集成
|
||||||
│ │ ├─zlt-loadbalancer-spring-boot-starter -- 封装Loadbalancer和Feign的通用操作逻辑
|
│ │ ├─zlt-log-spring-boot-starter -- 日志集成
|
||||||
│ │ ├─zlt-sentinel-spring-boot-starter -- 封装Sentinel的通用操作逻辑
|
│ │ ├─zlt-auth-client-spring-boot-starter -- 认证客户端
|
||||||
│ │ ├─zlt-elasticsearch-spring-boot-starter -- 封装Elasticsearch通用操作逻辑
|
│ │ ├─zlt-loadbalancer-spring-boot-starter -- 负载均衡
|
||||||
│ │ ├─zlt-oss-spring-boot-starter -- 封装对象存储通用操作逻辑
|
│ │ ├─zlt-sentinel-spring-boot-starter -- 限流熔断
|
||||||
│ │ ├─zlt-zookeeper-spring-boot-starter -- 封装Zookeeper通用操作逻辑
|
│ │ ├─zlt-elasticsearch-spring-boot-starter -- 搜索引擎
|
||||||
|
│ │ ├─zlt-oss-spring-boot-starter -- 对象存储
|
||||||
|
│ │ ├─zlt-sms-spring-boot-starter -- 短信集成
|
||||||
|
│ │ ├─zlt-zookeeper-spring-boot-starter -- Zookeeper集成
|
||||||
|
│ │ ├─zlt-wechat-common-core -- 微信通用核心
|
||||||
|
│ │ └─zlt-wechat-spring-boot-starter -- 微信集成
|
||||||
|
│ ├─zlt-gateway -- API网关[9900]
|
||||||
|
│ ├─zlt-uaa -- 认证授权中心[8000]
|
||||||
│ ├─zlt-config -- 配置中心
|
│ ├─zlt-config -- 配置中心
|
||||||
│ ├─zlt-doc -- 项目文档
|
│ ├─zlt-monitor -- 监控中心
|
||||||
│ ├─zlt-gateway -- api网关一级工程
|
|
||||||
│ │ ├─sc-gateway -- spring-cloud-gateway[9900]
|
|
||||||
│ ├─zlt-monitor -- 监控一级工程
|
|
||||||
│ │ ├─sc-admin -- 应用监控[6500]
|
│ │ ├─sc-admin -- 应用监控[6500]
|
||||||
│ │ ├─log-center -- 日志中心[7200]
|
│ │ └─log-center -- 日志中心[7200]
|
||||||
│ ├─zlt-uaa -- spring-security认证中心[8000]
|
│ └─zlt-doc -- 项目文档
|
||||||
│ ├─zlt-register -- 注册中心Nacos[8848]
|
└─database -- 数据库脚本
|
||||||
│ ├─zlt-web -- 前端一级工程
|
|
||||||
│ │ ├─layui-web -- layui前端[8066]
|
|
||||||
│ │ ├─react-web -- react前端[8066]
|
|
||||||
│ ├─zlt-demo -- demo一级工程
|
|
||||||
│ │ ├─dubbo-demo -- dubbo服务demo
|
|
||||||
│ │ ├─resource-server-demo -- 资源服务器demo
|
|
||||||
│ │ ├─seata-demo -- seata分布式事务demo
|
|
||||||
│ │ ├─sharding-jdbc-demo -- sharding-jdbc分库分表demo
|
|
||||||
│ │ ├─rocketmq-demo -- rocketmq和mq事务demo
|
|
||||||
│ │ ├─sso-demo -- 单点登录demo
|
|
||||||
│ │ ├─websocket-demo -- websocket demo
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 环境要求
|
||||||
|
|
||||||
|
- JDK 17+
|
||||||
|
- Maven 3.6+
|
||||||
|
- MySQL 8.0+
|
||||||
|
- Redis 7.0+
|
||||||
|
- Nacos 2.0+
|
||||||
|
|
||||||
|
### 数据库初始化
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mysql -u root -p < zlt-doc/database/init.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
### 启动 Nacos
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 单机模式启动
|
||||||
|
sh nacos/bin/startup.sh -m standalone
|
||||||
|
```
|
||||||
|
|
||||||
|
访问: http://localhost:8848/nacos (账号: nacos/nacos)
|
||||||
|
|
||||||
|
### 编译项目
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn clean install -DskipTests
|
||||||
|
```
|
||||||
|
|
||||||
|
### 启动服务
|
||||||
|
|
||||||
|
1. 启动网关 (9900)
|
||||||
|
2. 启动认证中心 (8000)
|
||||||
|
3. 启动用户中心 (7000)
|
||||||
|
4. 启动文件中心 (5000)
|
||||||
|
|
||||||
|
### 默认账号
|
||||||
|
|
||||||
|
- 用户名: `admin`
|
||||||
|
- 密码: `admin123`
|
||||||
|
|
||||||
|
## 许可证
|
||||||
|
|
||||||
|
Apache License 2.0
|
||||||
|
|||||||
@@ -0,0 +1,269 @@
|
|||||||
|
# 企业级微服务脚手架抽离总结报告
|
||||||
|
|
||||||
|
## 项目信息
|
||||||
|
- **原项目**: Go-Fly Platform Services (旅游景区管理平台)
|
||||||
|
- **新项目**: Central Platform (企业级微服务脚手架)
|
||||||
|
- **版本**: 6.0.0
|
||||||
|
- **分支**: scaffold-base
|
||||||
|
- **提交**: 74d99e6b
|
||||||
|
|
||||||
|
## 抽离概述
|
||||||
|
|
||||||
|
成功将业务特定的旅游平台项目抽离为通用的企业级微服务脚手架,保留了完整的微服务基础设施和核心通用功能。
|
||||||
|
|
||||||
|
## 一、保留的核心模块
|
||||||
|
|
||||||
|
### 1. 基础设施层 ✅
|
||||||
|
```
|
||||||
|
zlt-gateway/ # API网关 (Spring Cloud Gateway + Sentinel)
|
||||||
|
zlt-uaa/ # 认证授权中心 (OAuth2 + JWT)
|
||||||
|
zlt-config/ # 配置中心 (Nacos Config)
|
||||||
|
zlt-monitor/ # 监控中心 (Spring Boot Admin)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 公共组件库 ✅ (完整保留)
|
||||||
|
```
|
||||||
|
zlt-commons/
|
||||||
|
├── zlt-common-core/ # 核心工具类
|
||||||
|
├── zlt-common-spring-boot-starter/ # 通用配置
|
||||||
|
├── zlt-redis-spring-boot-starter/ # Redis集成
|
||||||
|
├── zlt-db-spring-boot-starter/ # 数据库集成
|
||||||
|
├── zlt-log-spring-boot-starter/ # 日志集成
|
||||||
|
├── zlt-auth-client-spring-boot-starter/ # 认证客户端
|
||||||
|
├── zlt-loadbalancer-spring-boot-starter/ # 负载均衡
|
||||||
|
├── zlt-sentinel-spring-boot-starter/ # 限流熔断
|
||||||
|
├── zlt-elasticsearch-spring-boot-starter/# 搜索引擎
|
||||||
|
├── zlt-oss-spring-boot-starter/ # 对象存储
|
||||||
|
├── zlt-sms-spring-boot-starter/ # 短信集成
|
||||||
|
├── zlt-zookeeper-spring-boot-starter/ # Zookeeper集成
|
||||||
|
├── zlt-wechat-common-core/ # 微信通用核心
|
||||||
|
└── zlt-wechat-spring-boot-starter/ # 微信集成
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 核心业务模块 ✅
|
||||||
|
```
|
||||||
|
zlt-business/
|
||||||
|
├── user-center/ # 用户中心 (用户、角色、权限、租户)
|
||||||
|
├── file-center/ # 文件中心 (多云存储)
|
||||||
|
├── search-center/ # 搜索中心 (Elasticsearch)
|
||||||
|
├── code-generator/ # 代码生成器
|
||||||
|
└── demo-center/ # 示例模块 (新增)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 前端项目 ✅
|
||||||
|
```
|
||||||
|
zlt-web/
|
||||||
|
├── layui-web/ # Layui 管理后台
|
||||||
|
└── react-web/ # React + Ant Design Pro 管理后台
|
||||||
|
```
|
||||||
|
|
||||||
|
## 二、删除的业务模块
|
||||||
|
|
||||||
|
### 1. 业务特定模块 ❌
|
||||||
|
```
|
||||||
|
zlt-business/
|
||||||
|
├── device-center/ # 设备中心 (IoT设备、大疆无人机)
|
||||||
|
├── device-ops-center/ # 设备运维中心
|
||||||
|
├── order-center/ # 订单中心 (景区门票、旅游产品)
|
||||||
|
├── coupon-center/ # 优惠券中心 (携程对接)
|
||||||
|
└── msg-center/ # 消息中心 (邮件、短信、推送)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 业务前端项目 ❌
|
||||||
|
```
|
||||||
|
zlt-web/
|
||||||
|
├── react-web-next/ # 旅游业务前端
|
||||||
|
└── yingyan/ # 鹰眼系统前端
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 业务文档 ❌
|
||||||
|
```
|
||||||
|
zlt-doc/
|
||||||
|
├── device_ops_requirements.md
|
||||||
|
├── MAP_DASHBOARD_ANALYSIS.md
|
||||||
|
├── third-party-aerial-photography-flow.md
|
||||||
|
├── TOURISM_WITH_DISTANCE_FIX.md
|
||||||
|
├── yingyan-design.md
|
||||||
|
├── 优惠券管理功能说明.md
|
||||||
|
├── 携程优惠券对接接口文档.md
|
||||||
|
├── 多租户层级使用指南.md
|
||||||
|
├── 租户组织机构重构计划.md
|
||||||
|
└── ... (共24个业务文档)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 三、新增内容
|
||||||
|
|
||||||
|
### 1. 示例模块
|
||||||
|
- **demo-center**: 完整的示例业务模块,展示如何创建新的微服务
|
||||||
|
|
||||||
|
### 2. 数据库脚本
|
||||||
|
- **zlt-doc/database/init.sql**: 核心表初始化脚本
|
||||||
|
- sys_user (用户表)
|
||||||
|
- sys_role (角色表)
|
||||||
|
- sys_menu (菜单表)
|
||||||
|
- sys_user_role (用户角色关联)
|
||||||
|
- sys_role_menu (角色菜单关联)
|
||||||
|
- sys_tenant (租户表)
|
||||||
|
- sys_file (文件表)
|
||||||
|
- sys_log (操作日志表)
|
||||||
|
- 默认管理员账号 (admin/admin123)
|
||||||
|
|
||||||
|
### 3. 项目文档
|
||||||
|
- **README.md**: 项目介绍和快速开始
|
||||||
|
- **QUICK_START.md**: 详细的快速开始指南
|
||||||
|
- **CLAUDE.md**: AI 开发指南 (更新为脚手架版本)
|
||||||
|
|
||||||
|
## 四、技术栈
|
||||||
|
|
||||||
|
### 后端技术
|
||||||
|
| 技术 | 版本 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| Java | 17 | 编程语言 |
|
||||||
|
| Spring Boot | 3.1.6 | 应用框架 |
|
||||||
|
| Spring Cloud | 2022.0.4 | 微服务框架 |
|
||||||
|
| Spring Cloud Alibaba | 2022.0.0.0 | 阿里云组件 |
|
||||||
|
| MyBatis Plus | 3.5.4.1 | ORM 框架 |
|
||||||
|
| MySQL | 8.0+ | 关系数据库 |
|
||||||
|
| Redis | 7.0+ | 缓存数据库 |
|
||||||
|
| Elasticsearch | 7.13.4 | 搜索引擎 |
|
||||||
|
| Nacos | Latest | 注册中心/配置中心 |
|
||||||
|
| Sentinel | Latest | 限流熔断 |
|
||||||
|
|
||||||
|
### 前端技术
|
||||||
|
| 技术 | 版本 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| React | 17 | UI 框架 |
|
||||||
|
| Ant Design | 4.20 | UI 组件库 |
|
||||||
|
| UmiJS | 3.5 | 应用框架 |
|
||||||
|
| TypeScript | 4.x | 编程语言 |
|
||||||
|
|
||||||
|
## 五、核心功能
|
||||||
|
|
||||||
|
### 1. 用户中心
|
||||||
|
- ✅ 用户管理 (CRUD、状态管理)
|
||||||
|
- ✅ 角色管理 (RBAC权限)
|
||||||
|
- ✅ 菜单管理 (动态路由)
|
||||||
|
- ✅ 权限管理 (按钮级权限)
|
||||||
|
- ✅ 租户管理 (多租户隔离)
|
||||||
|
- ✅ 登录日志
|
||||||
|
- ✅ 操作日志
|
||||||
|
|
||||||
|
### 2. 文件中心
|
||||||
|
- ✅ 文件上传下载
|
||||||
|
- ✅ 多云存储支持 (阿里云OSS、七牛云、MinIO)
|
||||||
|
- ✅ 图片预览
|
||||||
|
- ✅ CDN加速
|
||||||
|
|
||||||
|
### 3. 搜索中心
|
||||||
|
- ✅ 全文搜索
|
||||||
|
- ✅ 数据索引管理
|
||||||
|
- ✅ 搜索结果排序
|
||||||
|
|
||||||
|
### 4. 代码生成器
|
||||||
|
- ✅ 基于数据库表生成代码
|
||||||
|
- ✅ 支持自定义模板
|
||||||
|
|
||||||
|
## 六、项目结构
|
||||||
|
|
||||||
|
```
|
||||||
|
central-platform/
|
||||||
|
├── zlt-commons/ # 公共组件库 (13个模块)
|
||||||
|
├── zlt-gateway/ # API网关
|
||||||
|
├── zlt-uaa/ # 认证授权中心
|
||||||
|
├── zlt-config/ # 配置中心
|
||||||
|
├── zlt-monitor/ # 监控中心
|
||||||
|
├── zlt-business/ # 业务模块
|
||||||
|
│ ├── user-center/ # 用户中心
|
||||||
|
│ ├── file-center/ # 文件中心
|
||||||
|
│ ├── search-center/ # 搜索中心
|
||||||
|
│ ├── code-generator/ # 代码生成器
|
||||||
|
│ └── demo-center/ # 示例模块
|
||||||
|
├── zlt-web/ # 前端项目
|
||||||
|
│ ├── layui-web/ # Layui 管理后台
|
||||||
|
│ └── react-web/ # React 管理后台
|
||||||
|
├── zlt-doc/ # 项目文档
|
||||||
|
│ ├── database/ # 数据库脚本
|
||||||
|
│ └── sql/ # SQL脚本
|
||||||
|
├── README.md # 项目说明
|
||||||
|
├── QUICK_START.md # 快速开始
|
||||||
|
└── CLAUDE.md # AI 开发指南
|
||||||
|
```
|
||||||
|
|
||||||
|
## 七、统计数据
|
||||||
|
|
||||||
|
### 代码变更
|
||||||
|
- **删除文件**: 1879 个
|
||||||
|
- **删除代码行**: 293,423 行
|
||||||
|
- **新增代码行**: 609 行
|
||||||
|
- **净减少**: 292,814 行
|
||||||
|
|
||||||
|
### 模块统计
|
||||||
|
- **保留模块**: 9 个 (基础设施 4 + 业务 5)
|
||||||
|
- **删除模块**: 5 个 (业务特定)
|
||||||
|
- **新增模块**: 1 个 (demo-center)
|
||||||
|
- **公共组件**: 13 个 (全部保留)
|
||||||
|
|
||||||
|
### 文档清理
|
||||||
|
- **删除业务文档**: 24 个
|
||||||
|
- **保留配置文档**: 3 个
|
||||||
|
- **新增文档**: 2 个
|
||||||
|
|
||||||
|
## 八、快速开始
|
||||||
|
|
||||||
|
### 环境要求
|
||||||
|
- JDK 17+
|
||||||
|
- Maven 3.6+
|
||||||
|
- MySQL 8.0+
|
||||||
|
- Redis 7.0+
|
||||||
|
- Nacos 2.0+
|
||||||
|
|
||||||
|
### 启动步骤
|
||||||
|
1. 初始化数据库: `mysql < zlt-doc/database/init.sql`
|
||||||
|
2. 启动 Nacos (单机模式)
|
||||||
|
3. 启动网关 (9900)
|
||||||
|
4. 启动认证中心 (8000)
|
||||||
|
5. 启动用户中心 (7000)
|
||||||
|
6. 启动文件中心 (5000)
|
||||||
|
|
||||||
|
### 默认账号
|
||||||
|
- 用户名: `admin`
|
||||||
|
- 密码: `admin123`
|
||||||
|
|
||||||
|
## 九、后续建议
|
||||||
|
|
||||||
|
### 1. 可选扩展模块
|
||||||
|
- 消息中心 (邮件、短信、站内信)
|
||||||
|
- 工作流引擎 (Activiti/Flowable)
|
||||||
|
- 报表中心 (JasperReports/ECharts)
|
||||||
|
- 定时任务 (XXL-Job)
|
||||||
|
- 第三方登录 (OAuth2社交登录)
|
||||||
|
|
||||||
|
### 2. 文档完善
|
||||||
|
- 架构设计文档
|
||||||
|
- 开发规范文档
|
||||||
|
- 部署运维文档
|
||||||
|
- API 接口文档
|
||||||
|
|
||||||
|
### 3. 示例完善
|
||||||
|
- 更多业务场景示例
|
||||||
|
- 最佳实践示例
|
||||||
|
- 性能优化示例
|
||||||
|
|
||||||
|
## 十、总结
|
||||||
|
|
||||||
|
成功将业务特定的旅游平台抽离为通用的企业级微服务脚手架:
|
||||||
|
|
||||||
|
✅ **保留完整的微服务基础设施**
|
||||||
|
✅ **保留所有公共组件库**
|
||||||
|
✅ **保留核心通用业务模块**
|
||||||
|
✅ **删除所有业务特定代码**
|
||||||
|
✅ **创建完整的示例模块**
|
||||||
|
✅ **提供详细的文档和快速开始指南**
|
||||||
|
|
||||||
|
该脚手架可作为企业级后台管理系统的基础框架,支持快速开发各类业务系统。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**抽离完成时间**: 2026-03-07
|
||||||
|
**Git 分支**: scaffold-base
|
||||||
|
**Git 提交**: 74d99e6b
|
||||||
@@ -60,10 +60,6 @@
|
|||||||
<tomcat-embed-core.version>10.1.11</tomcat-embed-core.version>
|
<tomcat-embed-core.version>10.1.11</tomcat-embed-core.version>
|
||||||
<httpclient.version>5.2.1</httpclient.version>
|
<httpclient.version>5.2.1</httpclient.version>
|
||||||
<oauth2-oidc-sdk.version>11.7</oauth2-oidc-sdk.version>
|
<oauth2-oidc-sdk.version>11.7</oauth2-oidc-sdk.version>
|
||||||
<dji-cloud-sdk.version>1.3.1</dji-cloud-sdk.version>
|
|
||||||
<okhttp3.version>4.9.1</okhttp3.version>
|
|
||||||
<glassfish-jaxb.version>2.3.3</glassfish-jaxb.version>
|
|
||||||
<javax-jaxb.version>2.3.0</javax-jaxb.version>
|
|
||||||
<easyexcel.version>3.3.3</easyexcel.version>
|
<easyexcel.version>3.3.3</easyexcel.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|||||||
@@ -1,225 +0,0 @@
|
|||||||
# 优惠券中心服务 (Coupon Center Service)
|
|
||||||
|
|
||||||
## 项目简介
|
|
||||||
|
|
||||||
优惠券中心服务是一个基于Spring Boot的微服务,专门处理优惠券相关的业务逻辑,包括与携程API的集成。
|
|
||||||
|
|
||||||
## 功能特性
|
|
||||||
|
|
||||||
- ✅ 优惠券管理(创建、查询、使用、过期处理)
|
|
||||||
- ✅ 携程API集成(订单创建、退款、核销通知)
|
|
||||||
- ✅ AES加密/解密支持
|
|
||||||
- ✅ MD5签名验证
|
|
||||||
- ✅ 多租户支持
|
|
||||||
- ✅ 软删除支持
|
|
||||||
|
|
||||||
## 技术栈
|
|
||||||
|
|
||||||
- **Spring Boot 3.x**
|
|
||||||
- **MyBatis Plus**
|
|
||||||
- **MySQL 8.0**
|
|
||||||
- **Redis** (可选)
|
|
||||||
- **Nacos** (服务发现和配置管理)
|
|
||||||
|
|
||||||
## 快速开始
|
|
||||||
|
|
||||||
### 1. 数据库初始化
|
|
||||||
|
|
||||||
首先需要创建数据库和表结构:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 连接到MySQL数据库
|
|
||||||
mysql -u your_username -p
|
|
||||||
|
|
||||||
# 执行数据库初始化脚本
|
|
||||||
source sql/create_ctrip_order_tables.sql
|
|
||||||
```
|
|
||||||
|
|
||||||
或者手动执行:
|
|
||||||
|
|
||||||
```sql
|
|
||||||
-- 创建数据库
|
|
||||||
CREATE DATABASE IF NOT EXISTS `coupon-center` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
-- 使用数据库
|
|
||||||
USE `coupon-center`;
|
|
||||||
|
|
||||||
-- 执行sql/create_ctrip_order_tables.sql中的所有建表语句
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 配置数据库连接
|
|
||||||
|
|
||||||
修改 `application.yml` 中的数据库配置:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://your_mysql_host:3306/coupon-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
|
||||||
username: your_username
|
|
||||||
password: your_password
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 配置携程API参数
|
|
||||||
|
|
||||||
确保 `application.yml` 中的携程API配置正确:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
ctrip:
|
|
||||||
aes:
|
|
||||||
key: 087b36ad0dff7942 # AES密钥
|
|
||||||
iv: 750e15a31356a99d # AES IV
|
|
||||||
sign:
|
|
||||||
key: ce6033ae31124ec5cdab3d2bc79f2622 # 签名密钥
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 启动服务
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 编译项目
|
|
||||||
mvn clean compile
|
|
||||||
|
|
||||||
# 启动服务
|
|
||||||
mvn spring-boot:run
|
|
||||||
```
|
|
||||||
|
|
||||||
或者打包后运行:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 打包
|
|
||||||
mvn clean package
|
|
||||||
|
|
||||||
# 运行jar包
|
|
||||||
java -jar target/coupon-center.jar
|
|
||||||
```
|
|
||||||
|
|
||||||
## API接口
|
|
||||||
|
|
||||||
### 携程相关接口
|
|
||||||
|
|
||||||
#### 创建优惠券
|
|
||||||
- **URL**: `POST /api-order/coupon/ctrip/create`
|
|
||||||
- **描述**: 接收携程创建优惠券请求
|
|
||||||
- **请求格式**: 加密的JSON数据
|
|
||||||
|
|
||||||
#### 验证优惠券
|
|
||||||
- **URL**: `POST /api-order/coupon/ctrip/verify`
|
|
||||||
- **描述**: 验证优惠券有效性
|
|
||||||
|
|
||||||
#### 取消优惠券
|
|
||||||
- **URL**: `POST /api-order/coupon/ctrip/cancel`
|
|
||||||
- **描述**: 取消优惠券
|
|
||||||
|
|
||||||
#### 查询优惠券状态
|
|
||||||
- **URL**: `GET /api-order/coupon/ctrip/status/{ctripCouponId}`
|
|
||||||
- **描述**: 查询优惠券状态
|
|
||||||
|
|
||||||
### 测试接口
|
|
||||||
|
|
||||||
#### 签名调试
|
|
||||||
- **URL**: `POST /api-order/coupon/ctrip/test/debug-sign`
|
|
||||||
- **描述**: 调试签名计算过程
|
|
||||||
|
|
||||||
#### 实际请求测试
|
|
||||||
- **URL**: `POST /api-order/coupon/ctrip/test/real-request`
|
|
||||||
- **描述**: 测试实际请求数据解析
|
|
||||||
|
|
||||||
## 数据库表结构
|
|
||||||
|
|
||||||
### 主要表
|
|
||||||
|
|
||||||
1. **t_coupon** - 优惠券主表
|
|
||||||
2. **t_ctrip_order** - 携程订单表
|
|
||||||
3. **t_ctrip_order_item** - 携程订单项目表
|
|
||||||
4. **t_ctrip_passenger** - 携程乘客表
|
|
||||||
5. **t_ctrip_contact** - 携程联系人表
|
|
||||||
6. **t_ctrip_coupon** - 携程优惠券表
|
|
||||||
7. **t_ctrip_voucher** - 携程凭证表
|
|
||||||
8. **t_ctrip_refund** - 携程退款表
|
|
||||||
9. **t_ctrip_refund_item** - 携程退款项目表
|
|
||||||
10. **t_ctrip_consumed** - 携程核销表
|
|
||||||
11. **t_ctrip_consumed_passenger** - 携程核销乘客表
|
|
||||||
12. **t_ctrip_consumed_voucher** - 携程核销凭证表
|
|
||||||
|
|
||||||
## 携程API集成
|
|
||||||
|
|
||||||
### 加密解密
|
|
||||||
|
|
||||||
服务支持携程的AES-128-CBC加密和自定义编码:
|
|
||||||
|
|
||||||
- **AES加密**: 使用CBC模式,PKCS5Padding填充
|
|
||||||
- **自定义编码**: 非标准Base64编码,使用字母a-p表示4位数据
|
|
||||||
|
|
||||||
### 签名验证
|
|
||||||
|
|
||||||
使用MD5算法进行签名验证:
|
|
||||||
|
|
||||||
```
|
|
||||||
签名字符串 = accountId + serviceName + requestTime + body + version + signKey
|
|
||||||
签名 = MD5(签名字符串).toLowerCase()
|
|
||||||
```
|
|
||||||
|
|
||||||
## 故障排除
|
|
||||||
|
|
||||||
### 常见问题
|
|
||||||
|
|
||||||
1. **数据库连接失败**
|
|
||||||
- 检查数据库配置
|
|
||||||
- 确保数据库和表已创建
|
|
||||||
|
|
||||||
2. **签名验证失败**
|
|
||||||
- 检查签名密钥配置
|
|
||||||
- 使用调试接口分析签名计算过程
|
|
||||||
|
|
||||||
3. **AES解密失败**
|
|
||||||
- 检查AES密钥和IV配置
|
|
||||||
- 确认使用正确的自定义编码
|
|
||||||
|
|
||||||
### 调试工具
|
|
||||||
|
|
||||||
- **签名调试**: `/api-order/coupon/ctrip/test/debug-sign`
|
|
||||||
- **AES测试**: `/api-order/coupon/ctrip/test/aes`
|
|
||||||
- **配置验证**: `/api-order/coupon/ctrip/test/aes-config`
|
|
||||||
|
|
||||||
## 开发指南
|
|
||||||
|
|
||||||
### 添加新的API接口
|
|
||||||
|
|
||||||
1. 在 `controller` 包中创建控制器
|
|
||||||
2. 在 `service` 包中实现业务逻辑
|
|
||||||
3. 在 `mapper` 包中定义数据访问方法
|
|
||||||
4. 在 `entity` 包中定义实体类
|
|
||||||
|
|
||||||
### 数据库迁移
|
|
||||||
|
|
||||||
1. 创建新的SQL脚本
|
|
||||||
2. 更新实体类和Mapper
|
|
||||||
3. 测试数据访问功能
|
|
||||||
|
|
||||||
## 部署
|
|
||||||
|
|
||||||
### Docker部署
|
|
||||||
|
|
||||||
```dockerfile
|
|
||||||
FROM openjdk:17-jre-slim
|
|
||||||
COPY target/coupon-center.jar app.jar
|
|
||||||
EXPOSE 8002
|
|
||||||
ENTRYPOINT ["java", "-jar", "/app.jar"]
|
|
||||||
```
|
|
||||||
|
|
||||||
### 环境变量
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 数据库配置
|
|
||||||
ZLT_DATASOURCE_IP=your_mysql_host
|
|
||||||
ZLT_DATASOURCE_USERNAME=your_username
|
|
||||||
ZLT_DATASOURCE_PASSWORD=your_password
|
|
||||||
|
|
||||||
# 携程API配置
|
|
||||||
CTRIP_AES_KEY=087b36ad0dff7942
|
|
||||||
CTRIP_AES_IV=750e15a31356a99d
|
|
||||||
CTRIP_SIGN_KEY=ce6033ae31124ec5cdab3d2bc79f2622
|
|
||||||
```
|
|
||||||
|
|
||||||
## 许可证
|
|
||||||
|
|
||||||
本项目采用 MIT 许可证。
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
-- 调试查询脚本
|
|
||||||
-- 用于检查数据库中的数据情况
|
|
||||||
|
|
||||||
-- 1. 检查订单表数据
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
ota_order_id,
|
|
||||||
supplier_order_id,
|
|
||||||
total_amount,
|
|
||||||
currency,
|
|
||||||
status,
|
|
||||||
create_time
|
|
||||||
FROM t_ctrip_order
|
|
||||||
ORDER BY create_time DESC
|
|
||||||
LIMIT 10;
|
|
||||||
|
|
||||||
-- 2. 检查乘客表数据
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
order_id,
|
|
||||||
passenger_name,
|
|
||||||
phone,
|
|
||||||
create_time
|
|
||||||
FROM t_ctrip_passenger
|
|
||||||
ORDER BY create_time DESC
|
|
||||||
LIMIT 10;
|
|
||||||
|
|
||||||
-- 3. 检查联系人表数据
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
order_id,
|
|
||||||
name,
|
|
||||||
mobile,
|
|
||||||
email,
|
|
||||||
create_time
|
|
||||||
FROM t_ctrip_contact
|
|
||||||
ORDER BY create_time DESC
|
|
||||||
LIMIT 10;
|
|
||||||
|
|
||||||
-- 4. 检查订单项表数据
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
order_id,
|
|
||||||
item_id,
|
|
||||||
item_name,
|
|
||||||
plu,
|
|
||||||
quantity,
|
|
||||||
unit_price,
|
|
||||||
total_price,
|
|
||||||
create_time
|
|
||||||
FROM t_ctrip_order_item
|
|
||||||
ORDER BY create_time DESC
|
|
||||||
LIMIT 10;
|
|
||||||
|
|
||||||
-- 5. 根据手机号查询乘客信息
|
|
||||||
SELECT
|
|
||||||
p.id,
|
|
||||||
p.order_id,
|
|
||||||
p.passenger_name,
|
|
||||||
p.phone,
|
|
||||||
o.ota_order_id,
|
|
||||||
o.total_amount,
|
|
||||||
o.status
|
|
||||||
FROM t_ctrip_passenger p
|
|
||||||
JOIN t_ctrip_order o ON p.order_id = o.id
|
|
||||||
WHERE p.phone = '18322694510'
|
|
||||||
ORDER BY p.create_time DESC;
|
|
||||||
|
|
||||||
-- 6. 根据手机号查询联系人信息
|
|
||||||
SELECT
|
|
||||||
c.id,
|
|
||||||
c.order_id,
|
|
||||||
c.name,
|
|
||||||
c.mobile,
|
|
||||||
c.email,
|
|
||||||
o.ota_order_id,
|
|
||||||
o.total_amount,
|
|
||||||
o.status
|
|
||||||
FROM t_ctrip_contact c
|
|
||||||
JOIN t_ctrip_order o ON c.order_id = o.id
|
|
||||||
WHERE c.mobile = '18322694510'
|
|
||||||
ORDER BY c.create_time DESC;
|
|
||||||
|
|
||||||
-- 7. 查询所有订单的价格分布
|
|
||||||
SELECT
|
|
||||||
total_amount,
|
|
||||||
COUNT(*) as count
|
|
||||||
FROM t_ctrip_order
|
|
||||||
WHERE total_amount IS NOT NULL
|
|
||||||
GROUP BY total_amount
|
|
||||||
ORDER BY total_amount;
|
|
||||||
@@ -1,201 +0,0 @@
|
|||||||
# 酒店优惠券二维码需求实现方案
|
|
||||||
|
|
||||||
## 1. 背景与目标
|
|
||||||
- 为协商酒店提供一次性实体二维码优惠券,入住绑定用户后可在设备端免支付下单。
|
|
||||||
- 确保券码唯一、不可重复使用,订单需区分优惠券订单类型,保证业务闭环(生成-发放-绑定-核销-订单-设备任务)。
|
|
||||||
- 方案部署在 coupon-center 模块,可扩展到其他券类型/渠道。
|
|
||||||
|
|
||||||
## 2. 业务角色与定义
|
|
||||||
- 协商酒店:已签约的酒店实体,负责发放线下券。
|
|
||||||
- 优惠券批次:一次生成的一组券码,绑定同一酒店、有效期、面值规则。
|
|
||||||
- 优惠券券码/二维码:携带唯一券码和签名的二维码图片,实体印刷,状态流转 UNBOUND -> BOUND -> USED/VOID/EXPIRED。
|
|
||||||
- 用户:入住客人,登录后绑定券码;同一用户同一酒店默认仅可绑定一张(可配置)。
|
|
||||||
- 设备端:自助设备/终端,负责扫码下单并执行任务。
|
|
||||||
- 订单类型:`NORMAL` 普通订单;`HOTEL_COUPON_FREE` 酒店券免单订单;预留 `HOTEL_COUPON_DEDUCTION` 抵扣类。
|
|
||||||
|
|
||||||
## 3. 流程说明
|
|
||||||
### 3.1 券码生成与发放
|
|
||||||
- 管理端选择酒店、配置面值(默认免单0元)、有效期、单用户限领数、生成数量。
|
|
||||||
- 系统创建批次,生成唯一 `coupon_code`,写入券码表,构造绑定入口 `https://xxx/h5/hotel-coupon/bind?code=...&hotelId=...&ts=...&sign=...`,生成二维码图片并打包 zip 提供下载。
|
|
||||||
- 下载记录写入事件表,批次状态从 `GENERATED` -> `FINISHED`,券码状态初始为 `UNBOUND`。
|
|
||||||
|
|
||||||
### 3.2 入住绑定
|
|
||||||
- 前台发放实体码,用户扫码进入 H5,登录后调用绑定接口。
|
|
||||||
- 校验:有效期、券码状态=UNBOUND、酒店匹配、用户在同酒店限领数未超限;签名校验防伪。
|
|
||||||
- 事务内执行:`UPDATE t_hotel_coupon_code SET status='BOUND', bind_user_id=?, bind_time=NOW(), version=version+1 WHERE coupon_code=? AND status='UNBOUND'`;写入事件流水。
|
|
||||||
- 返回成功页并展示可用状态;重复提交按幂等返回已绑定信息。
|
|
||||||
|
|
||||||
### 3.3 设备扫码下单与核销
|
|
||||||
- 设备端通过用户身份/手机号调用“查询可用券”接口,若存在 BOUND 且未过期券,前端金额置零并将 `orderType=HOTEL_COUPON_FREE`。
|
|
||||||
- 下单接口在同一事务内写入订单表、将券码从 BOUND 更新为 USED,落订单-券码关联,推送设备执行任务。
|
|
||||||
- 同步返回订单号;失败时回滚券状态,设备收到失败提示继续正常付费路径。
|
|
||||||
- 若用户无绑定券或券不可用,则按 `NORMAL` 下单,不影响其他流程。
|
|
||||||
|
|
||||||
### 3.4 异常/风控
|
|
||||||
- 管理端支持作废券码/批次(status->VOID),并记录原因;VOID 后绑定/核销均拒绝。
|
|
||||||
- 定时任务每日凌晨标记过期,写事件流水;订单幂等使用 `requestId`/`orderNo` 双重校验。
|
|
||||||
- 券码字符串含签名与时间戳,服务端校验防止伪造;绑定、核销接口限流并记录审计。
|
|
||||||
|
|
||||||
## 4. 数据库表设计(coupon-center)
|
|
||||||
### 4.1 协商酒店表 t_partner_hotel
|
|
||||||
```sql
|
|
||||||
CREATE TABLE `t_partner_hotel` (
|
|
||||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
|
|
||||||
`hotel_code` varchar(64) NOT NULL COMMENT '酒店编码(对外展示/查询)',
|
|
||||||
`hotel_name` varchar(100) NOT NULL COMMENT '酒店名称',
|
|
||||||
`contact_name` varchar(50) DEFAULT NULL COMMENT '联系人',
|
|
||||||
`contact_phone` varchar(20) DEFAULT NULL COMMENT '联系电话',
|
|
||||||
`address` varchar(255) DEFAULT NULL COMMENT '地址',
|
|
||||||
`status` varchar(20) DEFAULT 'ENABLED' COMMENT 'ENABLED/ DISABLED',
|
|
||||||
`remark` varchar(255) DEFAULT NULL,
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
`deleted` tinyint(1) DEFAULT 0,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_hotel_code` (`hotel_code`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='协商酒店';
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4.2 优惠券批次表 t_hotel_coupon_batch
|
|
||||||
```sql
|
|
||||||
CREATE TABLE `t_hotel_coupon_batch` (
|
|
||||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
||||||
`batch_no` varchar(64) NOT NULL COMMENT '批次号',
|
|
||||||
`hotel_id` bigint NOT NULL COMMENT '关联酒店',
|
|
||||||
`coupon_type` varchar(20) NOT NULL COMMENT 'FREE_ORDER/DEDUCTION',
|
|
||||||
`face_value` decimal(10,2) NOT NULL DEFAULT 0 COMMENT '面值,免单为0',
|
|
||||||
`quantity` int NOT NULL COMMENT '生成数量',
|
|
||||||
`valid_start_time` datetime NOT NULL,
|
|
||||||
`valid_end_time` datetime NOT NULL,
|
|
||||||
`per_user_limit` int NOT NULL DEFAULT 1 COMMENT '同酒店同用户限领数',
|
|
||||||
`order_type` varchar(20) NOT NULL DEFAULT 'HOTEL_COUPON_FREE' COMMENT '下单类型标识',
|
|
||||||
`qr_payload_prefix` varchar(255) NOT NULL COMMENT '绑定入口前缀/域名',
|
|
||||||
`download_url` varchar(500) DEFAULT NULL COMMENT '二维码zip存储路径',
|
|
||||||
`status` varchar(20) DEFAULT 'GENERATED' COMMENT 'GENERATED/PROCESSING/FINISHED/CLOSED',
|
|
||||||
`created_by` varchar(50) DEFAULT NULL,
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
`deleted` tinyint(1) DEFAULT 0,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_batch_no` (`batch_no`),
|
|
||||||
KEY `idx_hotel` (`hotel_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='酒店优惠券批次';
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4.3 券码表 t_hotel_coupon_code
|
|
||||||
```sql
|
|
||||||
CREATE TABLE `t_hotel_coupon_code` (
|
|
||||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
||||||
`batch_id` bigint NOT NULL,
|
|
||||||
`hotel_id` bigint NOT NULL,
|
|
||||||
`coupon_code` varchar(128) NOT NULL COMMENT '唯一券码',
|
|
||||||
`qr_content` varchar(500) NOT NULL COMMENT '二维码携带内容(含签名)',
|
|
||||||
`qr_image_url` varchar(500) DEFAULT NULL COMMENT '二维码图片地址',
|
|
||||||
`status` varchar(20) NOT NULL DEFAULT 'UNBOUND' COMMENT 'UNBOUND/BOUND/USED/EXPIRED/VOID',
|
|
||||||
`bind_user_id` bigint DEFAULT NULL,
|
|
||||||
`bind_user_name` varchar(50) DEFAULT NULL,
|
|
||||||
`bind_user_phone` varchar(20) DEFAULT NULL,
|
|
||||||
`bind_time` datetime DEFAULT NULL,
|
|
||||||
`bind_channel` varchar(30) DEFAULT NULL COMMENT 'H5/MINI/FRONT_DESK',
|
|
||||||
`use_time` datetime DEFAULT NULL,
|
|
||||||
`use_order_no` varchar(64) DEFAULT NULL,
|
|
||||||
`use_device_code` varchar(64) DEFAULT NULL,
|
|
||||||
`order_type` varchar(20) DEFAULT NULL COMMENT '下单类型冗余',
|
|
||||||
`expire_time` datetime DEFAULT NULL,
|
|
||||||
`version` int NOT NULL DEFAULT 0 COMMENT '乐观锁',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_coupon_code` (`coupon_code`),
|
|
||||||
KEY `idx_batch` (`batch_id`),
|
|
||||||
KEY `idx_hotel_status` (`hotel_id`,`status`),
|
|
||||||
KEY `idx_user` (`bind_user_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='酒店优惠券券码';
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4.4 事件流水表 t_hotel_coupon_event
|
|
||||||
```sql
|
|
||||||
CREATE TABLE `t_hotel_coupon_event` (
|
|
||||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
||||||
`coupon_code` varchar(128) NOT NULL,
|
|
||||||
`hotel_id` bigint NOT NULL,
|
|
||||||
`batch_id` bigint NOT NULL,
|
|
||||||
`user_id` bigint DEFAULT NULL,
|
|
||||||
`device_code` varchar(64) DEFAULT NULL,
|
|
||||||
`event_type` varchar(30) NOT NULL COMMENT 'GENERATE/BIND/USE/EXPIRE/VOID/DOWNLOAD',
|
|
||||||
`request_id` varchar(64) DEFAULT NULL COMMENT '幂等/追踪ID',
|
|
||||||
`remark` varchar(500) DEFAULT NULL,
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_coupon_event` (`coupon_code`,`event_type`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='券码事件流水';
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4.5 订单表 t_hotel_coupon_order
|
|
||||||
```sql
|
|
||||||
CREATE TABLE `t_hotel_coupon_order` (
|
|
||||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
||||||
`order_no` varchar(64) NOT NULL,
|
|
||||||
`user_id` bigint NOT NULL,
|
|
||||||
`user_phone` varchar(20) DEFAULT NULL,
|
|
||||||
`hotel_id` bigint NOT NULL,
|
|
||||||
`device_code` varchar(64) NOT NULL,
|
|
||||||
`coupon_code` varchar(128) DEFAULT NULL,
|
|
||||||
`order_type` varchar(20) NOT NULL COMMENT 'NORMAL/HOTEL_COUPON_FREE/HOTEL_COUPON_DEDUCTION',
|
|
||||||
`origin_amount` decimal(10,2) NOT NULL COMMENT '原价',
|
|
||||||
`pay_amount` decimal(10,2) NOT NULL COMMENT '实付,免单为0',
|
|
||||||
`status` varchar(20) NOT NULL DEFAULT 'CREATED' COMMENT 'CREATED/DOING/DONE/CANCELLED/FAILED',
|
|
||||||
`task_payload` json DEFAULT NULL COMMENT '下发设备任务数据',
|
|
||||||
`remark` varchar(255) DEFAULT NULL,
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_order_no` (`order_no`),
|
|
||||||
KEY `idx_user_type` (`user_id`,`order_type`),
|
|
||||||
KEY `idx_coupon` (`coupon_code`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='设备订单(含优惠券)';
|
|
||||||
```
|
|
||||||
|
|
||||||
## 5. 接口设计(关键)
|
|
||||||
### 5.1 管理端(需认证)
|
|
||||||
- `POST /admin/hotel` 创建/编辑酒店;`GET /admin/hotel` 列表筛选,`PUT /admin/hotel/{id}/status` 启停。
|
|
||||||
- `POST /admin/hotel/{hotelId}/coupon-batches` 创建批次(quantity/validity/perUserLimit/faceValue/orderType);异步生成券码。
|
|
||||||
- `GET /admin/coupon-batches` 按酒店/时间查询;`GET /admin/coupon-batches/{id}/download` 下载二维码zip;`POST /admin/coupon-batches/{id}/close` 关闭批次。
|
|
||||||
- `GET /admin/coupons` 券码明细分页;`POST /admin/coupons/{code}/void` 作废单码;导出报表。
|
|
||||||
|
|
||||||
### 5.2 H5 绑定
|
|
||||||
- `GET /public/hotel-coupon/{code}/precheck?hotelId=...&ts=...&sign=...` 校验二维码、返回酒店名/有效期/状态。
|
|
||||||
- `POST /public/hotel-coupon/bind` 绑定券码,入参:`code, hotelId, userId, userPhone, deviceCode(optional)`;返回绑定结果和可用状态。
|
|
||||||
|
|
||||||
### 5.3 设备侧下单/核销
|
|
||||||
- `GET /device/hotel-coupon/available?userId=...&hotelId=...` 返回可用券及订单类型;无券时返回空。
|
|
||||||
- `POST /device/hotel-coupon/use` 入参:`code/orderNo/userId/userPhone/hotelId/deviceCode/orderAmount/requestId`;事务化校验并落订单,成功返回免单订单号,失败返回原因。
|
|
||||||
- `POST /device/hotel-coupon/order` 可直接创建订单(包含 taskPayload),内部调用 use 接口扣券并设置 `orderType`。
|
|
||||||
|
|
||||||
### 5.4 运维/风控
|
|
||||||
- 事件列表接口:根据券码/用户/时间查询绑定、核销流水。
|
|
||||||
- 定时任务/手动触发接口:补偿过期、批量作废、重新生成二维码。
|
|
||||||
|
|
||||||
## 6. 核心实现要点
|
|
||||||
- 一次性二维码:券码唯一+签名+状态机控制;绑定/核销均通过 `status` + `version` 条件更新,避免并发复用。
|
|
||||||
- 订单类型:下单时写入 `t_hotel_coupon_order.order_type` 与设备任务记录,用于报表、风控、资金对账。
|
|
||||||
- 扩展性:`coupon_type/order_type` 预留,订单表 `task_payload`、券码表 `qr_content` 可存 JSON 扩展;批次/券码表均含 `deleted/status` 便于软删除和扩展。
|
|
||||||
- 监控审计:事件流水表记录全链路;关键接口打印 `requestId`;Prometheus/日志可按券码/酒店打标签。
|
|
||||||
- 定时任务:复用 `CouponExpireTask` 思路新增批次/券码过期处理;对过期券写事件并禁止绑定/核销。
|
|
||||||
|
|
||||||
## 7. 前端管理页面方案(zlt-web/react-web)
|
|
||||||
- 新增菜单「酒店优惠券」下包含:
|
|
||||||
- 「协商酒店管理」:列表/搜索/启停,表单字段:酒店名称、编码、联系人、电话、地址、备注。
|
|
||||||
- 「优惠券批次」:表单配置酒店、面值/类型、有效期、生成数量、单用户限领、二维码域名;表格展示状态、下载、关闭、查看日志。
|
|
||||||
- 「券码明细」:按批次/状态/用户过滤,支持导出、作废单码,展示绑定人、绑定时间、使用订单、设备号。
|
|
||||||
- H5 绑定页:展示酒店名称、有效期、状态文案;登录校验后点击「立即绑定」,提示绑定成功/失败原因。
|
|
||||||
- 交互提示:批次生成异步轮询,下载二维码给出 zip 地址;作废操作二次确认并展示影响范围。
|
|
||||||
|
|
||||||
## 8. 测试验证
|
|
||||||
- 单测/接口测试:批次生成数量正确、二维码签名校验、绑定幂等、并发绑定/核销互斥、过期/作废拦截。
|
|
||||||
- 联调:H5 绑定 -> 设备查询可用券 -> 免单下单 -> 设备任务执行 -> 订单状态回写。
|
|
||||||
- 回归:无券用户正常下单流程不受影响;报表统计区分订单类型。
|
|
||||||
|
|
||||||
## 9. 上线与配置
|
|
||||||
- SQL:新增表写入 `coupon-center/sql`,发布前执行;确保 DB 字符集 utf8mb4。
|
|
||||||
- 配置:新增二维码生成域名、OSS/本地存储路径、签名密钥;绑定/核销接口在网关配置白名单/限流。
|
|
||||||
- 发布:优先低峰期启用新定时任务,观察事件流水与日志;确认前端菜单、H5 入口发布同步。
|
|
||||||
@@ -1,772 +0,0 @@
|
|||||||
# 发明专利申请书
|
|
||||||
|
|
||||||
## 一、发明名称
|
|
||||||
|
|
||||||
**一种基于实体二维码的酒店优惠券发放与自动核销系统及方法**
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 二、技术领域
|
|
||||||
|
|
||||||
本发明涉及电子商务与旅游信息化技术领域,尤其涉及一种基于实体二维码的酒店优惠券发放与自动核销系统及方法。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 三、背景技术
|
|
||||||
|
|
||||||
随着旅游行业的快速发展,景区与酒店的合作营销成为重要的获客渠道。酒店作为游客集中的场所,具有天然的流量优势,如何有效地将酒店住客引流至合作景区成为行业关注的重点。
|
|
||||||
|
|
||||||
然而,现有的酒店与景区合作营销方案存在以下技术问题:
|
|
||||||
|
|
||||||
1. **优惠券发放效率低**:传统纸质优惠券需要人工发放,容易遗失、伪造,且无法精准追踪发放和使用情况。
|
|
||||||
|
|
||||||
2. **优惠券核销流程繁琐**:用户使用优惠券时需要手动出示、人工核验,影响用户体验,增加景区运营成本。
|
|
||||||
|
|
||||||
3. **缺乏一码一用机制**:传统优惠券容易被复制传播,难以控制实际使用量,造成营销成本失控。
|
|
||||||
|
|
||||||
4. **数据追踪困难**:无法准确统计优惠券的发放、绑定、使用情况,难以评估合作效果和优化营销策略。
|
|
||||||
|
|
||||||
5. **系统对接复杂**:优惠券系统与订单系统分离,需要人工核对,容易出现核销遗漏或重复核销问题。
|
|
||||||
|
|
||||||
6. **有效期管理粗放**:无法支持灵活的有效期策略(如固定时间或绑定后N天有效),用户体验欠佳。
|
|
||||||
|
|
||||||
因此,亟需一种能够实现优惠券自动化发放、一码一用、自动核销的技术方案。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 四、发明内容
|
|
||||||
|
|
||||||
### 4.1 发明目的
|
|
||||||
|
|
||||||
本发明的目的在于提供一种基于实体二维码的酒店优惠券发放与自动核销系统及方法,解决现有技术中优惠券发放效率低、核销流程繁琐、缺乏一码一用机制、数据追踪困难等技术问题。
|
|
||||||
|
|
||||||
### 4.2 技术方案
|
|
||||||
|
|
||||||
为实现上述目的,本发明提供以下技术方案:
|
|
||||||
|
|
||||||
#### 4.2.1 一种基于实体二维码的酒店优惠券发放与自动核销系统
|
|
||||||
|
|
||||||
所述系统包括:
|
|
||||||
|
|
||||||
**合作酒店管理模块**,用于管理与景区建立合作关系的酒店信息,包括:
|
|
||||||
- 酒店基本信息(名称、地址、联系人等);
|
|
||||||
- 合作有效期管理;
|
|
||||||
- 酒店状态管理(启用/禁用);
|
|
||||||
|
|
||||||
**优惠券批量生成模块**,用于为指定酒店批量生成带有唯一标识码的优惠券,包括:
|
|
||||||
- 生成唯一的批次号标识同一批次优惠券;
|
|
||||||
- 为每张优惠券生成全局唯一的优惠券码;
|
|
||||||
- 根据优惠券码生成对应的二维码图片;
|
|
||||||
- 支持配置优惠券类型(免费体验券、折扣券、满减券);
|
|
||||||
- 支持配置适用范围(指定景区、指定设备);
|
|
||||||
- 支持配置有效期策略(固定时间或绑定后N天);
|
|
||||||
|
|
||||||
**二维码图片管理模块**,用于管理优惠券二维码图片,包括:
|
|
||||||
- 将二维码图片上传至云存储服务;
|
|
||||||
- 支持按批次或按条件批量下载二维码图片;
|
|
||||||
- 将二维码打包为压缩文件供酒店打印制作实体二维码;
|
|
||||||
|
|
||||||
**用户扫码绑定模块**,用于处理用户扫描实体二维码后的绑定请求,包括:
|
|
||||||
- 解析二维码获取优惠券码;
|
|
||||||
- 校验优惠券状态(是否存在、是否已绑定、是否已过期、是否已作废);
|
|
||||||
- 采用分布式锁机制确保一码只能被一个用户绑定;
|
|
||||||
- 创建优惠券与用户的绑定关系;
|
|
||||||
- 根据有效期策略计算优惠券的实际生效时间;
|
|
||||||
- 更新优惠券状态为已绑定;
|
|
||||||
|
|
||||||
**用户优惠券查询模块**,用于为用户提供已绑定优惠券的查询功能,包括:
|
|
||||||
- 展示用户所有已绑定的优惠券列表;
|
|
||||||
- 支持按状态筛选(可用、已使用、已过期);
|
|
||||||
- 展示优惠券详情和适用范围;
|
|
||||||
|
|
||||||
**可用优惠券检测模块**,用于在用户下单前检测是否有可用优惠券,包括:
|
|
||||||
- 根据当前景区和设备信息查询用户的可用优惠券;
|
|
||||||
- 校验优惠券是否在有效期内;
|
|
||||||
- 校验优惠券是否适用于当前景区和设备;
|
|
||||||
- 返回可用优惠券信息供下单使用;
|
|
||||||
|
|
||||||
**自动核销模块**,用于在订单创建时自动完成优惠券核销,包括:
|
|
||||||
- 在订单创建流程中嵌入优惠券核销逻辑;
|
|
||||||
- 根据优惠券类型计算优惠金额;
|
|
||||||
- 创建零金额订单(免费体验券)或优惠后金额订单;
|
|
||||||
- 更新优惠券状态和绑定记录状态为已使用;
|
|
||||||
- 创建详细的核销记录用于数据追踪;
|
|
||||||
|
|
||||||
**订单类型标记模块**,用于在订单中标记优惠券使用信息,包括:
|
|
||||||
- 订单类型标记(普通订单/优惠券订单);
|
|
||||||
- 关联的优惠券标识;
|
|
||||||
- 原始金额、优惠金额、实付金额;
|
|
||||||
|
|
||||||
**过期处理模块**,用于定时处理过期的优惠券,包括:
|
|
||||||
- 定时扫描超过有效期的优惠券;
|
|
||||||
- 更新未使用的过期优惠券状态;
|
|
||||||
- 更新过期的绑定记录状态;
|
|
||||||
|
|
||||||
**数据统计模块**,用于统计优惠券的发放和使用情况,包括:
|
|
||||||
- 按酒店统计优惠券发放数量;
|
|
||||||
- 统计已绑定、已使用、已过期数量;
|
|
||||||
- 支持按批次、按时间维度统计;
|
|
||||||
|
|
||||||
#### 4.2.2 一种基于实体二维码的酒店优惠券发放与自动核销方法
|
|
||||||
|
|
||||||
所述方法包括以下步骤:
|
|
||||||
|
|
||||||
**步骤S1:酒店合作关系建立**
|
|
||||||
- S1.1:在系统中录入合作酒店基本信息;
|
|
||||||
- S1.2:设置合作有效期;
|
|
||||||
- S1.3:生成酒店唯一编码;
|
|
||||||
|
|
||||||
**步骤S2:优惠券批量生成**
|
|
||||||
- S2.1:选择目标酒店,配置优惠券参数;
|
|
||||||
- S2.2:系统生成批次号,格式为:B + 年月日 + 4位序号;
|
|
||||||
- S2.3:循环生成指定数量的优惠券码,格式为:HC + 批次号 + 6位序号;
|
|
||||||
- S2.4:为每个优惠券码生成二维码图片,二维码内容为小程序页面路径加优惠券码参数;
|
|
||||||
- S2.5:将二维码图片上传至云存储;
|
|
||||||
- S2.6:批量写入优惠券记录至数据库,初始状态为未绑定;
|
|
||||||
|
|
||||||
**步骤S3:实体二维码制作与投放**
|
|
||||||
- S3.1:管理人员按批次下载二维码图片压缩包;
|
|
||||||
- S3.2:将二维码图片打印制作成实体二维码卡片或海报;
|
|
||||||
- S3.3:将实体二维码投放至合作酒店指定位置;
|
|
||||||
|
|
||||||
**步骤S4:用户扫码绑定**
|
|
||||||
- S4.1:用户在酒店扫描实体二维码;
|
|
||||||
- S4.2:小程序打开优惠券绑定页面,获取优惠券码参数;
|
|
||||||
- S4.3:调用绑定接口,系统获取分布式锁防止并发绑定;
|
|
||||||
- S4.4:校验优惠券状态,确保未被绑定、未过期、未作废;
|
|
||||||
- S4.5:根据有效期策略计算优惠券的实际生效开始时间和结束时间;
|
|
||||||
- S4.6:创建优惠券与用户的绑定记录;
|
|
||||||
- S4.7:更新优惠券状态为已绑定;
|
|
||||||
- S4.8:释放分布式锁,返回绑定成功信息;
|
|
||||||
|
|
||||||
**步骤S5:设备端下单检测**
|
|
||||||
- S5.1:用户在景区设备端准备下单;
|
|
||||||
- S5.2:系统调用可用优惠券检测接口;
|
|
||||||
- S5.3:查询用户已绑定且状态为有效的优惠券;
|
|
||||||
- S5.4:过滤出适用于当前景区和设备的优惠券;
|
|
||||||
- S5.5:过滤出在有效期内的优惠券;
|
|
||||||
- S5.6:若存在可用优惠券,前端展示免费体验或优惠信息;
|
|
||||||
|
|
||||||
**步骤S6:订单创建与自动核销**
|
|
||||||
- S6.1:用户确认使用优惠券下单;
|
|
||||||
- S6.2:创建订单,设置订单类型为优惠券订单;
|
|
||||||
- S6.3:根据优惠券类型计算优惠金额:
|
|
||||||
- 免费体验券:优惠金额等于订单原始金额,实付金额为0;
|
|
||||||
- 折扣券:优惠金额等于原始金额乘以折扣率,实付金额为原始金额减优惠金额;
|
|
||||||
- 满减券:满足最低消费条件时,优惠金额等于满减金额;
|
|
||||||
- S6.4:在订单中记录优惠券标识和优惠金额;
|
|
||||||
- S6.5:调用核销接口完成优惠券核销;
|
|
||||||
- S6.6:更新优惠券状态为已使用;
|
|
||||||
- S6.7:更新绑定记录状态为已使用;
|
|
||||||
- S6.8:创建核销记录,记录核销详情;
|
|
||||||
- S6.9:触发设备执行任务;
|
|
||||||
|
|
||||||
**步骤S7:过期优惠券处理**
|
|
||||||
- S7.1:定时任务每日扫描所有优惠券;
|
|
||||||
- S7.2:将超过有效期且状态仍为未绑定的优惠券状态更新为已过期;
|
|
||||||
- S7.3:将超过有效期且状态仍为已绑定的绑定记录状态更新为已过期;
|
|
||||||
|
|
||||||
### 4.3 有益效果
|
|
||||||
|
|
||||||
本发明与现有技术相比,具有以下有益效果:
|
|
||||||
|
|
||||||
1. **一码一用防滥用**:每个优惠券码全局唯一,通过分布式锁确保同一时刻只有一个用户能成功绑定,有效防止优惠券被复制滥用。
|
|
||||||
|
|
||||||
2. **自动核销提效率**:优惠券核销与订单创建流程无缝集成,用户下单时自动完成核销,无需人工核验,提升用户体验和运营效率。
|
|
||||||
|
|
||||||
3. **实体二维码易投放**:将优惠券二维码制作成实体卡片或海报投放至酒店,无需酒店培训人员发放,降低合作门槛。
|
|
||||||
|
|
||||||
4. **灵活的有效期策略**:支持固定时间有效期和绑定后N天有效期两种策略,满足不同营销场景需求。
|
|
||||||
|
|
||||||
5. **精准的适用范围控制**:可配置优惠券仅适用于指定景区或指定设备,实现精细化营销。
|
|
||||||
|
|
||||||
6. **完整的数据追踪链路**:从发放、绑定、使用到过期,全链路数据可追溯,便于评估营销效果和优化策略。
|
|
||||||
|
|
||||||
7. **多类型优惠券支持**:支持免费体验券、折扣券、满减券等多种类型,可根据营销目标灵活配置。
|
|
||||||
|
|
||||||
8. **批量操作高效率**:支持批量生成优惠券、批量下载二维码,满足大规模投放需求。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 五、附图说明
|
|
||||||
|
|
||||||
### 图1:系统整体架构图
|
|
||||||
|
|
||||||
```
|
|
||||||
┌─────────────────────────────────────────────────────────────────────┐
|
|
||||||
│ 前端应用层 │
|
|
||||||
├────────────────┬────────────────┬────────────────────────────────────┤
|
|
||||||
│ 管理后台 │ 用户小程序 │ 设备端 │
|
|
||||||
│ (优惠券管理) │ (扫码绑定) │ (自动核销) │
|
|
||||||
└───────┬────────┴───────┬────────┴───────────────┬────────────────────┘
|
|
||||||
│ │ │
|
|
||||||
▼ ▼ ▼
|
|
||||||
┌─────────────────────────────────────────────────────────────────────┐
|
|
||||||
│ 业务服务层 │
|
|
||||||
├─────────────────────────────────────────────────────────────────────┤
|
|
||||||
│ 合作酒店 优惠券生成 扫码绑定 可用检测 自动核销 过期处理 │
|
|
||||||
│ 管理 模块 模块 模块 模块 模块 │
|
|
||||||
└─────────────────────────────────────────────────────────────────────┘
|
|
||||||
│ │ │
|
|
||||||
▼ ▼ ▼
|
|
||||||
┌─────────────────────────────────────────────────────────────────────┐
|
|
||||||
│ 数据存储层 │
|
|
||||||
├─────────────────────────────────────────────────────────────────────┤
|
|
||||||
│ 合作酒店表 优惠券表 绑定记录表 核销记录表 订单表 │
|
|
||||||
└─────────────────────────────────────────────────────────────────────┘
|
|
||||||
│
|
|
||||||
▼
|
|
||||||
┌─────────────────────────────────────────────────────────────────────┐
|
|
||||||
│ 基础设施层 │
|
|
||||||
├─────────────────────────────────────────────────────────────────────┤
|
|
||||||
│ 云存储(二维码图片) │ 分布式锁(Redis) │
|
|
||||||
└─────────────────────────────────────────────────────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
### 图2:优惠券生命周期状态图
|
|
||||||
|
|
||||||
```
|
|
||||||
┌─────────────────────────────────────────────────────────────────────┐
|
|
||||||
│ 优惠券状态流转 │
|
|
||||||
├─────────────────────────────────────────────────────────────────────┤
|
|
||||||
│ │
|
|
||||||
│ ┌───────────┐ │
|
|
||||||
│ │ 生成优惠券 │ │
|
|
||||||
│ └─────┬─────┘ │
|
|
||||||
│ │ │
|
|
||||||
│ ▼ │
|
|
||||||
│ ┌───────────┐ │
|
|
||||||
│ ┌─────────│ 未绑定(0) │─────────┐ │
|
|
||||||
│ │ └─────┬─────┘ │ │
|
|
||||||
│ │ │ │ │
|
|
||||||
│ ▼ ▼ ▼ │
|
|
||||||
│ ┌───────────┐ ┌───────────┐ ┌───────────┐ │
|
|
||||||
│ │ 已作废(4) │ │ 已绑定(1) │ │ 已过期(3) │ │
|
|
||||||
│ └───────────┘ └─────┬─────┘ └───────────┘ │
|
|
||||||
│ │ │
|
|
||||||
│ ┌─────────┼─────────┐ │
|
|
||||||
│ │ │ │ │
|
|
||||||
│ ▼ ▼ ▼ │
|
|
||||||
│ ┌───────────┐ ┌───────────┐ │
|
|
||||||
│ │ 已过期(3) │ │ 已使用(2) │ │
|
|
||||||
│ └───────────┘ └───────────┘ │
|
|
||||||
│ │
|
|
||||||
└─────────────────────────────────────────────────────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
### 图3:核心业务流程图
|
|
||||||
|
|
||||||
```
|
|
||||||
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
|
|
||||||
│ 创建合作酒店 │ ──> │ 生成优惠券码 │ ──> │ 用户扫码绑定 │ ──> │ 设备端核销 │
|
|
||||||
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
|
|
||||||
│ │ │ │
|
|
||||||
▼ ▼ ▼ ▼
|
|
||||||
酒店基本信息 批量生成二维码 一码一用 订单金额为0
|
|
||||||
合作有效期 可批量下载 绑定用户ID 区分订单类型
|
|
||||||
```
|
|
||||||
|
|
||||||
### 图4:用户扫码绑定流程图
|
|
||||||
|
|
||||||
```
|
|
||||||
┌─────────────────────────────────────────────────────────────────┐
|
|
||||||
│ 用户扫码绑定流程 │
|
|
||||||
├─────────────────────────────────────────────────────────────────┤
|
|
||||||
│ 1. 用户在酒店扫描实体二维码 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 2. 小程序打开绑定页面,获取优惠券码 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 3. 调用绑定接口,获取分布式锁 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 4. 后端校验: │
|
|
||||||
│ ├─ 优惠券是否存在 │
|
|
||||||
│ ├─ 优惠券是否已被绑定 │
|
|
||||||
│ ├─ 优惠券是否已过期 │
|
|
||||||
│ └─ 优惠券是否已作废 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 5. 创建绑定记录 │
|
|
||||||
│ - 计算生效时间(固定时间或绑定后N天) │
|
|
||||||
│ ↓ │
|
|
||||||
│ 6. 更新优惠券状态为"已绑定" │
|
|
||||||
│ ↓ │
|
|
||||||
│ 7. 释放分布式锁,返回绑定成功信息 │
|
|
||||||
└─────────────────────────────────────────────────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
### 图5:自动核销流程图
|
|
||||||
|
|
||||||
```
|
|
||||||
┌─────────────────────────────────────────────────────────────────┐
|
|
||||||
│ 优惠券核销流程 │
|
|
||||||
├─────────────────────────────────────────────────────────────────┤
|
|
||||||
│ 1. 用户在设备端扫码准备下单 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 2. 前端调用检查可用优惠券接口 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 3. 后端查询用户绑定的有效优惠券 │
|
|
||||||
│ - 状态为有效 │
|
|
||||||
│ - 在有效期内 │
|
|
||||||
│ - 适用于当前景区/设备 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 4. 如有可用优惠券,前端展示"免费体验" │
|
|
||||||
│ ↓ │
|
|
||||||
│ 5. 用户确认下单 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 6. 创建订单 │
|
|
||||||
│ - order_type = 2(优惠券订单) │
|
|
||||||
│ - pay_type = 2(优惠券支付) │
|
|
||||||
│ - order_amount = 0 │
|
|
||||||
│ - coupon_id = 优惠券ID │
|
|
||||||
│ ↓ │
|
|
||||||
│ 7. 调用优惠券核销接口 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 8. 更新优惠券状态和绑定记录状态为"已使用" │
|
|
||||||
│ ↓ │
|
|
||||||
│ 9. 创建核销记录 │
|
|
||||||
│ ↓ │
|
|
||||||
│ 10. 触发设备执行任务 │
|
|
||||||
└─────────────────────────────────────────────────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
### 图6:数据表关系图
|
|
||||||
|
|
||||||
```
|
|
||||||
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
|
|
||||||
│ partner_hotel │ │ hotel_coupon │ │ coupon_binding │
|
|
||||||
│ (合作酒店表) │ 1───n │ (优惠券表) │ 1───1 │ (绑定记录表) │
|
|
||||||
├──────────────────┤ ├──────────────────┤ ├──────────────────┤
|
|
||||||
│ id (PK) │ │ id (PK) │ │ id (PK) │
|
|
||||||
│ hotel_code (UQ) │◄──────│ hotel_id (FK) │◄──────│ coupon_id (FK) │
|
|
||||||
│ hotel_name │ │ coupon_code (UQ) │ │ coupon_code │
|
|
||||||
│ contact_name │ │ batch_no │ │ user_id │
|
|
||||||
│ cooperation_ │ │ coupon_type │ │ bind_time │
|
|
||||||
│ start_date │ │ valid_start_time │ │ effective_ │
|
|
||||||
│ cooperation_ │ │ valid_end_time │ │ start_time │
|
|
||||||
│ end_date │ │ status │ │ effective_ │
|
|
||||||
│ status │ │ qrcode_url │ │ end_time │
|
|
||||||
│ ... │ │ ... │ │ status │
|
|
||||||
└──────────────────┘ └──────────────────┘ └──────────────────┘
|
|
||||||
│ │
|
|
||||||
│ │
|
|
||||||
▼ ▼
|
|
||||||
┌──────────────────┐ ┌──────────────────┐
|
|
||||||
│ coupon_usage │ │ orders │
|
|
||||||
│ (核销记录表) │ │ (订单表) │
|
|
||||||
├──────────────────┤ ├──────────────────┤
|
|
||||||
│ id (PK) │ │ id (PK) │
|
|
||||||
│ coupon_id │ │ order_no (UQ) │
|
|
||||||
│ binding_id │ │ order_type │
|
|
||||||
│ user_id │ │ coupon_id │
|
|
||||||
│ order_id │───────│ coupon_code │
|
|
||||||
│ order_no │ │ original_amount │
|
|
||||||
│ original_amount │ │ discount_amount │
|
|
||||||
│ discount_amount │ │ order_amount │
|
|
||||||
│ actual_amount │ │ ... │
|
|
||||||
│ usage_time │ └──────────────────┘
|
|
||||||
│ ... │
|
|
||||||
└──────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 六、具体实施方式
|
|
||||||
|
|
||||||
### 6.1 实施例一:优惠券批量生成
|
|
||||||
|
|
||||||
本实施例描述为合作酒店批量生成优惠券的过程:
|
|
||||||
|
|
||||||
**步骤1**:管理员在后台选择合作酒店"XX国际酒店"(ID=1),配置优惠券参数:
|
|
||||||
- 优惠券名称:酒店住客免费体验券
|
|
||||||
- 优惠券类型:免费体验券
|
|
||||||
- 生成数量:1000张
|
|
||||||
- 有效期类型:固定时间
|
|
||||||
- 有效期:2024-11-25 至 2025-11-25
|
|
||||||
- 适用景区:景区A、景区B
|
|
||||||
|
|
||||||
**步骤2**:系统生成批次号:
|
|
||||||
```
|
|
||||||
批次号 = "B" + "20241125" + "0001" = "B202411250001"
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤3**:循环生成1000个优惠券码:
|
|
||||||
```
|
|
||||||
优惠券码1 = "HC" + "202411250001" + "000001" = "HC202411250001000001"
|
|
||||||
优惠券码2 = "HC" + "202411250001" + "000002" = "HC202411250001000002"
|
|
||||||
...
|
|
||||||
优惠券码1000 = "HC" + "202411250001" + "001000" = "HC202411250001001000"
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤4**:为每个优惠券码生成二维码,二维码内容:
|
|
||||||
```
|
|
||||||
pages/coupon/bind?code=HC202411250001000001
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤5**:将二维码图片上传至云存储,保存访问URL。
|
|
||||||
|
|
||||||
**步骤6**:批量插入优惠券记录到数据库:
|
|
||||||
```
|
|
||||||
{
|
|
||||||
coupon_code: "HC202411250001000001",
|
|
||||||
hotel_id: 1,
|
|
||||||
batch_no: "B202411250001",
|
|
||||||
coupon_name: "酒店住客免费体验券",
|
|
||||||
coupon_type: 1,
|
|
||||||
valid_start_time: "2024-11-25 00:00:00",
|
|
||||||
valid_end_time: "2025-11-25 23:59:59",
|
|
||||||
status: 0, // 未绑定
|
|
||||||
applicable_tourism_ids: "1,2",
|
|
||||||
qrcode_url: "https://oss.xxx.com/coupon/HC202411250001000001.png"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6.2 实施例二:用户扫码绑定
|
|
||||||
|
|
||||||
本实施例描述用户在酒店扫描实体二维码绑定优惠券的过程:
|
|
||||||
|
|
||||||
**前置条件**:酒店已投放优惠券二维码海报,用户已登录小程序。
|
|
||||||
|
|
||||||
**步骤1**:用户张三(user_id=10001)在酒店前台扫描二维码海报。
|
|
||||||
|
|
||||||
**步骤2**:小程序解析二维码获取页面路径:
|
|
||||||
```
|
|
||||||
pages/coupon/bind?code=HC202411250001000001
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤3**:小程序打开绑定页面,提取优惠券码,调用绑定接口:
|
|
||||||
```
|
|
||||||
POST /coupon/user/bind
|
|
||||||
{
|
|
||||||
"couponCode": "HC202411250001000001"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤4**:后端获取分布式锁,锁键值:
|
|
||||||
```
|
|
||||||
coupon:bind:HC202411250001000001
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤5**:后端查询优惠券信息并校验:
|
|
||||||
- 优惠券存在 ✓
|
|
||||||
- 状态为未绑定(0) ✓
|
|
||||||
- 在有效期内 ✓
|
|
||||||
- 未被作废 ✓
|
|
||||||
|
|
||||||
**步骤6**:创建绑定记录:
|
|
||||||
```
|
|
||||||
{
|
|
||||||
coupon_id: 1,
|
|
||||||
coupon_code: "HC202411250001000001",
|
|
||||||
user_id: 10001,
|
|
||||||
user_openid: "oXXXXX",
|
|
||||||
bind_time: "2024-11-26 10:30:00",
|
|
||||||
bind_source: 1, // 扫码绑定
|
|
||||||
effective_start_time: "2024-11-25 00:00:00",
|
|
||||||
effective_end_time: "2025-11-25 23:59:59",
|
|
||||||
status: 1 // 有效
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤7**:更新优惠券状态为已绑定:
|
|
||||||
```
|
|
||||||
UPDATE hotel_coupon SET status = 1 WHERE id = 1
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤8**:释放分布式锁,返回绑定成功:
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"code": 0,
|
|
||||||
"msg": "绑定成功",
|
|
||||||
"data": {
|
|
||||||
"couponName": "酒店住客免费体验券",
|
|
||||||
"effectiveEndTime": "2025-11-25 23:59:59",
|
|
||||||
"applicableTourisms": ["景区A", "景区B"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6.3 实施例三:设备端自动核销
|
|
||||||
|
|
||||||
本实施例描述用户在景区设备端使用优惠券下单的自动核销过程:
|
|
||||||
|
|
||||||
**前置条件**:用户张三已绑定优惠券,现在景区A的设备DEVICE001前准备下单。
|
|
||||||
|
|
||||||
**步骤1**:用户扫描设备二维码进入下单页面。
|
|
||||||
|
|
||||||
**步骤2**:前端调用可用优惠券检测接口:
|
|
||||||
```
|
|
||||||
GET /coupon/user/check-available?tourismId=1&deviceSn=DEVICE001
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤3**:后端查询用户可用优惠券:
|
|
||||||
```sql
|
|
||||||
SELECT cb.*, hc.* FROM coupon_binding cb
|
|
||||||
JOIN hotel_coupon hc ON cb.coupon_id = hc.id
|
|
||||||
WHERE cb.user_id = 10001
|
|
||||||
AND cb.status = 1
|
|
||||||
AND cb.effective_end_time > NOW()
|
|
||||||
AND (hc.applicable_tourism_ids IS NULL
|
|
||||||
OR FIND_IN_SET('1', hc.applicable_tourism_ids))
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤4**:返回可用优惠券信息:
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"hasCoupon": true,
|
|
||||||
"coupon": {
|
|
||||||
"couponId": 1,
|
|
||||||
"couponName": "酒店住客免费体验券",
|
|
||||||
"couponType": 1,
|
|
||||||
"discountValue": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤5**:前端展示"您有可用的免费体验券",用户点击确认使用。
|
|
||||||
|
|
||||||
**步骤6**:创建订单,设置订单类型为优惠券订单:
|
|
||||||
```
|
|
||||||
{
|
|
||||||
order_no: "ORD202411260001",
|
|
||||||
order_type: 2, // 优惠券订单
|
|
||||||
pay_type: 2, // 优惠券支付
|
|
||||||
coupon_id: 1,
|
|
||||||
coupon_code: "HC202411250001000001",
|
|
||||||
original_amount: 99.00,
|
|
||||||
discount_amount: 99.00,
|
|
||||||
order_amount: 0.00, // 实付金额为0
|
|
||||||
order_status: 2 // 已支付(无需支付)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤7**:调用优惠券核销接口:
|
|
||||||
```
|
|
||||||
POST /coupon/internal/use
|
|
||||||
{
|
|
||||||
"userId": 10001,
|
|
||||||
"couponId": 1,
|
|
||||||
"orderId": 1,
|
|
||||||
"orderNo": "ORD202411260001",
|
|
||||||
"tourismId": 1,
|
|
||||||
"tourismName": "景区A",
|
|
||||||
"deviceSn": "DEVICE001",
|
|
||||||
"originalAmount": 99.00
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤8**:更新优惠券和绑定记录状态为已使用:
|
|
||||||
```sql
|
|
||||||
UPDATE hotel_coupon SET status = 2 WHERE id = 1;
|
|
||||||
UPDATE coupon_binding SET status = 2 WHERE coupon_id = 1;
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤9**:创建核销记录:
|
|
||||||
```
|
|
||||||
{
|
|
||||||
coupon_id: 1,
|
|
||||||
coupon_code: "HC202411250001000001",
|
|
||||||
binding_id: 1,
|
|
||||||
user_id: 10001,
|
|
||||||
order_id: 1,
|
|
||||||
order_no: "ORD202411260001",
|
|
||||||
tourism_id: 1,
|
|
||||||
tourism_name: "景区A",
|
|
||||||
device_sn: "DEVICE001",
|
|
||||||
original_amount: 99.00,
|
|
||||||
discount_amount: 99.00,
|
|
||||||
actual_amount: 0.00,
|
|
||||||
usage_time: "2024-11-26 14:30:00",
|
|
||||||
usage_type: 1 // 自动核销
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**步骤10**:触发设备执行任务,完成服务交付。
|
|
||||||
|
|
||||||
### 6.4 实施例四:绑定后N天有效期计算
|
|
||||||
|
|
||||||
本实施例描述"绑定后N天有效"类型优惠券的有效期计算:
|
|
||||||
|
|
||||||
**配置**:优惠券配置为"绑定后30天有效"。
|
|
||||||
|
|
||||||
**绑定时间**:2024-11-26 10:30:00
|
|
||||||
|
|
||||||
**有效期计算**:
|
|
||||||
```
|
|
||||||
effective_start_time = 绑定时间 = 2024-11-26 10:30:00
|
|
||||||
effective_end_time = 绑定时间 + 30天 = 2024-12-26 10:30:00
|
|
||||||
```
|
|
||||||
|
|
||||||
**存储的绑定记录**:
|
|
||||||
```
|
|
||||||
{
|
|
||||||
bind_time: "2024-11-26 10:30:00",
|
|
||||||
effective_start_time: "2024-11-26 10:30:00",
|
|
||||||
effective_end_time: "2024-12-26 10:30:00"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6.5 实施例五:并发绑定控制
|
|
||||||
|
|
||||||
本实施例描述两个用户同时扫描同一优惠券二维码时的处理:
|
|
||||||
|
|
||||||
**场景**:用户A和用户B同时扫描优惠券码HC202411250001000001。
|
|
||||||
|
|
||||||
**时序**:
|
|
||||||
```
|
|
||||||
T1: 用户A调用绑定接口
|
|
||||||
T2: 用户A尝试获取分布式锁,成功
|
|
||||||
T3: 用户B调用绑定接口
|
|
||||||
T4: 用户B尝试获取分布式锁,等待
|
|
||||||
T5: 用户A完成绑定,释放锁
|
|
||||||
T6: 用户B获取到锁
|
|
||||||
T7: 用户B查询优惠券状态,发现已被绑定
|
|
||||||
T8: 用户B返回错误:优惠券已被其他用户绑定
|
|
||||||
T9: 用户B释放锁
|
|
||||||
```
|
|
||||||
|
|
||||||
**结果**:只有用户A成功绑定优惠券,用户B收到"优惠券已被其他用户绑定"的提示。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 七、权利要求书
|
|
||||||
|
|
||||||
### 权利要求1
|
|
||||||
|
|
||||||
一种基于实体二维码的酒店优惠券发放与自动核销系统,其特征在于,包括:
|
|
||||||
|
|
||||||
合作酒店管理模块,用于管理与景区建立合作关系的酒店信息;
|
|
||||||
|
|
||||||
优惠券批量生成模块,用于为指定酒店批量生成带有唯一标识码的优惠券,并为每张优惠券生成对应的二维码图片;
|
|
||||||
|
|
||||||
二维码图片管理模块,用于将二维码图片上传至云存储并支持批量下载,供酒店制作实体二维码投放;
|
|
||||||
|
|
||||||
用户扫码绑定模块,用于处理用户扫描实体二维码后的绑定请求,采用分布式锁机制确保一码只能被一个用户绑定;
|
|
||||||
|
|
||||||
可用优惠券检测模块,用于在用户下单前根据当前景区和设备信息检测是否有可用优惠券;
|
|
||||||
|
|
||||||
自动核销模块,用于在订单创建时自动完成优惠券核销,更新优惠券状态并创建核销记录。
|
|
||||||
|
|
||||||
### 权利要求2
|
|
||||||
|
|
||||||
根据权利要求1所述的系统,其特征在于,所述优惠券批量生成模块支持配置多种优惠券类型,包括免费体验券、折扣券和满减券,并支持配置适用范围包括指定景区和指定设备。
|
|
||||||
|
|
||||||
### 权利要求3
|
|
||||||
|
|
||||||
根据权利要求1所述的系统,其特征在于,所述优惠券批量生成模块支持两种有效期策略:固定时间有效期和绑定后N天有效期,所述用户扫码绑定模块根据有效期策略计算优惠券的实际生效时间。
|
|
||||||
|
|
||||||
### 权利要求4
|
|
||||||
|
|
||||||
根据权利要求1所述的系统,其特征在于,所述用户扫码绑定模块的具体处理过程为:
|
|
||||||
|
|
||||||
解析二维码获取优惠券码;
|
|
||||||
|
|
||||||
获取分布式锁;
|
|
||||||
|
|
||||||
校验优惠券状态,确保未被绑定、未过期、未作废;
|
|
||||||
|
|
||||||
根据有效期策略计算优惠券的实际生效开始时间和结束时间;
|
|
||||||
|
|
||||||
创建优惠券与用户的绑定记录;
|
|
||||||
|
|
||||||
更新优惠券状态为已绑定;
|
|
||||||
|
|
||||||
释放分布式锁。
|
|
||||||
|
|
||||||
### 权利要求5
|
|
||||||
|
|
||||||
根据权利要求1所述的系统,其特征在于,所述自动核销模块在订单创建流程中嵌入核销逻辑,根据优惠券类型计算优惠金额,创建标记为优惠券订单的订单记录,并在订单中记录优惠券标识和优惠金额。
|
|
||||||
|
|
||||||
### 权利要求6
|
|
||||||
|
|
||||||
根据权利要求1所述的系统,其特征在于,还包括:
|
|
||||||
|
|
||||||
过期处理模块,用于定时扫描超过有效期的优惠券,更新未使用的过期优惠券状态和过期的绑定记录状态;
|
|
||||||
|
|
||||||
数据统计模块,用于按酒店、按批次统计优惠券的发放、绑定、使用、过期数量。
|
|
||||||
|
|
||||||
### 权利要求7
|
|
||||||
|
|
||||||
一种基于实体二维码的酒店优惠券发放与自动核销方法,其特征在于,包括以下步骤:
|
|
||||||
|
|
||||||
S1:为合作酒店批量生成带有唯一标识码的优惠券,并为每张优惠券生成对应的二维码图片上传至云存储;
|
|
||||||
|
|
||||||
S2:将二维码图片批量下载并制作成实体二维码投放至酒店;
|
|
||||||
|
|
||||||
S3:用户扫描实体二维码后,系统获取分布式锁,校验优惠券状态后创建用户与优惠券的绑定关系;
|
|
||||||
|
|
||||||
S4:用户在景区设备端下单时,系统检测用户是否有适用于当前景区和设备的可用优惠券;
|
|
||||||
|
|
||||||
S5:若有可用优惠券,创建优惠券订单,根据优惠券类型计算优惠金额,自动完成优惠券核销。
|
|
||||||
|
|
||||||
### 权利要求8
|
|
||||||
|
|
||||||
根据权利要求7所述的方法,其特征在于,步骤S3中获取分布式锁的锁键值为优惠券码,确保同一优惠券在同一时刻只能被一个用户绑定。
|
|
||||||
|
|
||||||
### 权利要求9
|
|
||||||
|
|
||||||
根据权利要求7所述的方法,其特征在于,步骤S3中根据优惠券配置的有效期策略计算实际生效时间:若为固定时间策略,使用配置的有效期;若为绑定后N天策略,以绑定时间为起点计算有效期。
|
|
||||||
|
|
||||||
### 权利要求10
|
|
||||||
|
|
||||||
根据权利要求7所述的方法,其特征在于,步骤S5中自动核销的具体过程为:
|
|
||||||
|
|
||||||
在订单中设置订单类型为优惠券订单;
|
|
||||||
|
|
||||||
根据优惠券类型计算优惠金额和实付金额;
|
|
||||||
|
|
||||||
记录优惠券标识和优惠金额到订单;
|
|
||||||
|
|
||||||
更新优惠券状态和绑定记录状态为已使用;
|
|
||||||
|
|
||||||
创建包含核销详情的核销记录。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 八、摘要
|
|
||||||
|
|
||||||
### 说明书摘要
|
|
||||||
|
|
||||||
本发明公开了一种基于实体二维码的酒店优惠券发放与自动核销系统及方法,涉及电子商务与旅游信息化技术领域。系统包括合作酒店管理模块、优惠券批量生成模块、二维码图片管理模块、用户扫码绑定模块、可用优惠券检测模块和自动核销模块。通过为每张优惠券生成唯一标识码和对应二维码,制作成实体二维码投放至酒店,用户扫码后完成绑定,在景区设备端下单时自动检测并核销优惠券。本发明采用分布式锁机制确保一码一用,支持多种优惠券类型和灵活的有效期策略,将核销逻辑嵌入订单创建流程实现自动核销,具有发放效率高、核销自动化、防滥用、数据可追溯等优点。
|
|
||||||
|
|
||||||
### 摘要附图
|
|
||||||
|
|
||||||
(选用图3:核心业务流程图)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 九、附加说明
|
|
||||||
|
|
||||||
### 9.1 技术关键点
|
|
||||||
|
|
||||||
1. **一码一用机制**:每个优惠券码全局唯一,通过分布式锁防止并发绑定,确保一个优惠券只能被一个用户使用。
|
|
||||||
|
|
||||||
2. **实体二维码投放**:将数字优惠券转化为实体二维码,无需酒店人员培训,降低合作门槛。
|
|
||||||
|
|
||||||
3. **自动核销集成**:核销逻辑与订单创建流程无缝集成,用户无感知完成核销,提升体验。
|
|
||||||
|
|
||||||
4. **灵活有效期策略**:支持固定时间和绑定后N天两种策略,适应不同营销场景。
|
|
||||||
|
|
||||||
5. **精准适用范围**:可限定优惠券适用的景区和设备,实现精细化营销。
|
|
||||||
|
|
||||||
### 9.2 应用场景
|
|
||||||
|
|
||||||
- 酒店与景区合作营销
|
|
||||||
- 酒店与游乐园合作营销
|
|
||||||
- 民宿与周边景点合作营销
|
|
||||||
- 其他需要线下发放、线上核销的优惠券场景
|
|
||||||
|
|
||||||
### 9.3 技术创新点
|
|
||||||
|
|
||||||
1. 首次提出将实体二维码与一码一用机制结合的酒店优惠券发放方案
|
|
||||||
2. 首次实现优惠券核销与订单创建流程的无缝集成
|
|
||||||
3. 首次提出支持"绑定后N天有效"的动态有效期计算机制
|
|
||||||
4. 首次将分布式锁应用于优惠券绑定场景防止并发滥用
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**申请人**:湖北高飞智航科技有限责任公司
|
|
||||||
|
|
||||||
**发明人**:杜志超
|
|
||||||
|
|
||||||
**申请日期**:2025年12月01日
|
|
||||||
|
|
||||||
**文档版本**:v1.0
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
# 优惠券核销订单状态更新设计说明
|
|
||||||
|
|
||||||
## 功能概述
|
|
||||||
|
|
||||||
当优惠券核销成功后,需要自动更新订单中心的订单状态为"已支付",以便订单能够进入正常的业务流程(排队、执行等)。
|
|
||||||
|
|
||||||
## 设计方案
|
|
||||||
|
|
||||||
### 1. 绑定关系设计
|
|
||||||
|
|
||||||
在 `t_ctrip_order` 表中添加 `order_no` 字段,建立携程订单与订单中心订单的关联关系:
|
|
||||||
|
|
||||||
```sql
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `order_no` varchar(50) DEFAULT NULL COMMENT '关联的订单中心订单号' AFTER `ota_order_id`;
|
|
||||||
|
|
||||||
-- 添加索引
|
|
||||||
ALTER TABLE `t_ctrip_order` ADD INDEX `idx_order_no` (`order_no`);
|
|
||||||
ALTER TABLE `t_ctrip_order` ADD UNIQUE INDEX `uk_order_no` (`order_no`);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 数据流程
|
|
||||||
|
|
||||||
```
|
|
||||||
用户下单 → 创建订单中心订单 → 关联携程订单 → 核销优惠券 → 更新订单状态
|
|
||||||
```
|
|
||||||
|
|
||||||
1. **用户下单时**:在订单中心创建订单,记录订单号
|
|
||||||
2. **关联携程订单**:将订单中心的订单号关联到携程订单的 `order_no` 字段
|
|
||||||
3. **核销优惠券**:调用携程核销接口
|
|
||||||
4. **更新订单状态**:核销成功后,通过 `order_no` 调用订单中心接口更新订单状态
|
|
||||||
|
|
||||||
### 3. 核心组件
|
|
||||||
|
|
||||||
#### 3.1 数据库表结构
|
|
||||||
|
|
||||||
**t_ctrip_order 表新增字段:**
|
|
||||||
- `order_no` varchar(50) - 关联的订单中心订单号
|
|
||||||
|
|
||||||
#### 3.2 实体类更新
|
|
||||||
|
|
||||||
**CtripOrder.java:**
|
|
||||||
```java
|
|
||||||
/**
|
|
||||||
* 关联的订单中心订单号
|
|
||||||
*/
|
|
||||||
private String orderNo;
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 3.3 Mapper 接口
|
|
||||||
|
|
||||||
**CtripOrderMapper.java:**
|
|
||||||
```java
|
|
||||||
/**
|
|
||||||
* 根据订单中心订单号查询携程订单
|
|
||||||
*/
|
|
||||||
CtripOrder selectByOrderNo(@Param("orderNo") String orderNo);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 3.4 Feign 客户端
|
|
||||||
|
|
||||||
**OrderCenterService.java:**
|
|
||||||
```java
|
|
||||||
/**
|
|
||||||
* 更新订单状态为已支付(优惠券核销成功后调用)
|
|
||||||
*/
|
|
||||||
@PostMapping("/order/{orderNo}/status/paid")
|
|
||||||
Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单号获取订单信息
|
|
||||||
*/
|
|
||||||
@GetMapping("/order/{orderNo}")
|
|
||||||
Result<OrderInfo> getOrderByOrderNo(@PathVariable("orderNo") String orderNo);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 3.5 订单中心接口
|
|
||||||
|
|
||||||
**OrderController.java 新增接口:**
|
|
||||||
```java
|
|
||||||
@Operation(summary = "更新订单状态为已支付(优惠券核销成功后调用)")
|
|
||||||
@PostMapping("/order/{orderNo}/status/paid")
|
|
||||||
public Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo)
|
|
||||||
|
|
||||||
@Operation(summary = "根据订单号获取订单信息")
|
|
||||||
@GetMapping("/order/{orderNo}")
|
|
||||||
public Result<Order> getOrderByOrderNo(@PathVariable("orderNo") String orderNo)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 核销流程更新
|
|
||||||
|
|
||||||
#### 4.1 核销服务更新
|
|
||||||
|
|
||||||
**CtripConsumedServiceImpl.java:**
|
|
||||||
```java
|
|
||||||
/**
|
|
||||||
* 更新订单中心订单状态
|
|
||||||
*/
|
|
||||||
private void updateOrderCenterStatus(CtripOrder order) {
|
|
||||||
try {
|
|
||||||
if (StringUtils.hasText(order.getOrderNo())) {
|
|
||||||
log.info("开始更新订单中心订单状态,orderNo: {}", order.getOrderNo());
|
|
||||||
|
|
||||||
// 调用订单中心接口更新订单状态为已支付(状态1)
|
|
||||||
Result<String> result = orderCenterService.updateOrderStatusToPaid(order.getOrderNo());
|
|
||||||
|
|
||||||
if (result != null && result.getResp_code() == 0) {
|
|
||||||
log.info("订单中心订单状态更新成功,orderNo: {}", order.getOrderNo());
|
|
||||||
} else {
|
|
||||||
log.error("订单中心订单状态更新失败,orderNo: {}, result: {}",
|
|
||||||
order.getOrderNo(), result);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.warn("携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: {}",
|
|
||||||
order.getOtaOrderId());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("更新订单中心订单状态异常,orderNo: {}", order.getOrderNo(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. 订单状态映射
|
|
||||||
|
|
||||||
| 订单中心状态 | 状态值 | 说明 |
|
|
||||||
|-------------|--------|------|
|
|
||||||
| UNPAID | 0 | 待支付 |
|
|
||||||
| PAID | 1 | 已支付排队中 |
|
|
||||||
| CANCELED | 2 | 已取消 |
|
|
||||||
| COMPLETE | 3 | 设备执行完成 |
|
|
||||||
| DOING | 4 | 正在服务中 |
|
|
||||||
| UPLOADING | 5 | 素材上传中 |
|
|
||||||
| UPLOADED | 6 | 素材上传完成 |
|
|
||||||
|
|
||||||
**核销成功后更新为:**
|
|
||||||
- 订单状态:`PAID` (1) - 已支付排队中
|
|
||||||
- 支付类型:`COUPON_PAY` (2) - 优惠券支付
|
|
||||||
- 支付时间:当前时间
|
|
||||||
|
|
||||||
### 6. 使用方式
|
|
||||||
|
|
||||||
#### 6.1 创建订单时建立关联
|
|
||||||
|
|
||||||
```java
|
|
||||||
// 1. 创建订单中心订单
|
|
||||||
Order order = new Order();
|
|
||||||
order.setOrderNo("ORDER_20250901_001");
|
|
||||||
// ... 设置其他字段
|
|
||||||
orderService.createOrder(order);
|
|
||||||
|
|
||||||
// 2. 创建携程订单并关联
|
|
||||||
CtripOrder ctripOrder = new CtripOrder();
|
|
||||||
ctripOrder.setOtaOrderId("ctriptest-xxx");
|
|
||||||
ctripOrder.setOrderNo("ORDER_20250901_001"); // 关联订单号
|
|
||||||
// ... 设置其他字段
|
|
||||||
ctripOrderMapper.insert(ctripOrder);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 6.2 核销时自动更新状态
|
|
||||||
|
|
||||||
```java
|
|
||||||
// 核销成功后,系统会自动:
|
|
||||||
// 1. 更新携程订单状态为已使用(状态8)
|
|
||||||
// 2. 调用订单中心接口更新订单状态为已支付(状态1)
|
|
||||||
// 3. 设置支付类型为优惠券支付(类型2)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 7. 错误处理
|
|
||||||
|
|
||||||
#### 7.1 关联关系不存在
|
|
||||||
- 日志记录:`携程订单未关联订单中心订单号,无法更新订单状态`
|
|
||||||
- 不影响核销流程,只影响订单状态更新
|
|
||||||
|
|
||||||
#### 7.2 订单中心接口调用失败
|
|
||||||
- 日志记录:`订单中心订单状态更新失败`
|
|
||||||
- 不影响核销流程,只影响订单状态更新
|
|
||||||
|
|
||||||
#### 7.3 订单状态不正确
|
|
||||||
- 只有 `UNPAID` 状态的订单才能更新为 `PAID`
|
|
||||||
- 其他状态会返回错误信息
|
|
||||||
|
|
||||||
### 8. 监控和日志
|
|
||||||
|
|
||||||
#### 8.1 关键日志点
|
|
||||||
- 核销开始:`开始执行核销订单`
|
|
||||||
- 状态更新开始:`开始更新订单中心订单状态`
|
|
||||||
- 状态更新成功:`订单中心订单状态更新成功`
|
|
||||||
- 状态更新失败:`订单中心订单状态更新失败`
|
|
||||||
|
|
||||||
#### 8.2 监控指标
|
|
||||||
- 核销成功率
|
|
||||||
- 订单状态更新成功率
|
|
||||||
- 接口调用响应时间
|
|
||||||
|
|
||||||
### 9. 注意事项
|
|
||||||
|
|
||||||
1. **数据一致性**:确保携程订单和订单中心订单的关联关系正确
|
|
||||||
2. **幂等性**:多次核销同一订单时,状态更新应该是幂等的
|
|
||||||
3. **事务性**:核销和状态更新应该在同一个事务中
|
|
||||||
4. **异常处理**:订单中心接口调用失败不应影响核销流程
|
|
||||||
5. **性能考虑**:状态更新是异步的,不应阻塞核销流程
|
|
||||||
|
|
||||||
### 10. 测试验证
|
|
||||||
|
|
||||||
#### 10.1 单元测试
|
|
||||||
- 测试核销流程
|
|
||||||
- 测试状态更新逻辑
|
|
||||||
- 测试异常情况处理
|
|
||||||
|
|
||||||
#### 10.2 集成测试
|
|
||||||
- 测试完整的核销到状态更新流程
|
|
||||||
- 测试订单中心接口调用
|
|
||||||
- 测试数据一致性
|
|
||||||
|
|
||||||
#### 10.3 端到端测试
|
|
||||||
- 测试用户下单到核销的完整流程
|
|
||||||
- 测试订单状态变化
|
|
||||||
- 测试业务流程连续性
|
|
||||||
@@ -1,398 +0,0 @@
|
|||||||
# 前端优惠券查询核销接口文档
|
|
||||||
|
|
||||||
## 概述
|
|
||||||
|
|
||||||
本文档描述了前端查询可核销订单和核销优惠券的完整接口流程。
|
|
||||||
|
|
||||||
## 基础信息
|
|
||||||
|
|
||||||
- **服务地址**: `http://localhost:8002/coupon`
|
|
||||||
- **接口前缀**: `/api/order-detail`
|
|
||||||
- **请求方式**: POST/GET
|
|
||||||
- **数据格式**: JSON
|
|
||||||
|
|
||||||
## 1. 查询可核销订单接口
|
|
||||||
|
|
||||||
### 接口信息
|
|
||||||
- **接口地址**: `POST /api/order-detail/query`
|
|
||||||
- **功能描述**: 根据二维码ID查询可核销的订单(手机号从登录上下文获取,价格从二维码信息获取)
|
|
||||||
- **请求方式**: POST
|
|
||||||
|
|
||||||
### 请求参数
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"codeId": "5e0b3d9d-fc1a-4c8f-9c1a-7f4d2d9b6a11",
|
|
||||||
"page": 1,
|
|
||||||
"size": 10
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 参数说明
|
|
||||||
|
|
||||||
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|
|
||||||
|--------|------|------|--------|------|
|
|
||||||
| codeId | String | 是 | - | 二维码ID(订单中的codeId) |
|
|
||||||
| page | Integer | 否 | 1 | 页码,从1开始(必须 ≥ 1) |
|
|
||||||
| size | Integer | 否 | 10 | 每页数量(必须 ≥ 1,最大100) |
|
|
||||||
|
|
||||||
说明:
|
|
||||||
- 后端通过 `LoginUserContextHolder.getUser().getMobile()` 获取用户手机号。
|
|
||||||
- 后端通过 Feign 调用订单中心 `/qrcode/{codeId}` 获取二维码信息中的价格,并据此匹配订单金额。
|
|
||||||
- **重要**:页码从1开始,不是从0开始。如果传入page=0,系统会自动调整为page=1。
|
|
||||||
- 页大小限制在1-100之间,超出范围会自动调整。
|
|
||||||
|
|
||||||
### 响应结果
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "",
|
|
||||||
"data": {
|
|
||||||
"count": 1,
|
|
||||||
"resp_code": 0,
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"orderId": 137,
|
|
||||||
"otaOrderId": "ctriptest-10816828-454259-145573",
|
|
||||||
"supplierOrderId": "SUPPLIER_ctriptest-10816828-454259-145573_301495ef",
|
|
||||||
"orderStatus": 13,
|
|
||||||
"orderStatusDesc": "支付确认",
|
|
||||||
"totalAmount": 2.0,
|
|
||||||
"currency": "CNY",
|
|
||||||
"createTime": "2025-09-01T10:30:00",
|
|
||||||
"canConsume": true,
|
|
||||||
"consumeReason": null,
|
|
||||||
"orderItems": [
|
|
||||||
{
|
|
||||||
"itemId": 456,
|
|
||||||
"productId": "1801589811",
|
|
||||||
"itemName": "门票",
|
|
||||||
"itemType": "1",
|
|
||||||
"plu": "1",
|
|
||||||
"quantity": 2,
|
|
||||||
"unitPrice": 1.0,
|
|
||||||
"totalPrice": 2.0,
|
|
||||||
"currency": "CNY",
|
|
||||||
"useStartDate": "2025-07-25",
|
|
||||||
"useEndDate": "2025-07-25",
|
|
||||||
"canConsume": true,
|
|
||||||
"usedQuantity": 0,
|
|
||||||
"availableQuantity": 2
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"passengers": [
|
|
||||||
{
|
|
||||||
"passengerId": "PASS_1",
|
|
||||||
"passengerName": "张三",
|
|
||||||
"phone": "18322694510",
|
|
||||||
"passengerStatus": 0,
|
|
||||||
"passengerStatusDesc": "未使用",
|
|
||||||
"idCard": "110101199001011234",
|
|
||||||
"gender": "ADULT",
|
|
||||||
"age": null
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"contact": {
|
|
||||||
"name": "张三",
|
|
||||||
"mobile": "18322694510",
|
|
||||||
"email": "zhangsan@example.com",
|
|
||||||
"contactType": "CONTACT"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 响应字段说明
|
|
||||||
|
|
||||||
#### 订单信息 (OrderDetailVO)
|
|
||||||
| 字段名 | 类型 | 说明 |
|
|
||||||
|--------|------|------|
|
|
||||||
| orderId | Long | 订单ID |
|
|
||||||
| otaOrderId | String | 携程订单号 |
|
|
||||||
| supplierOrderId | String | 供应商订单号 |
|
|
||||||
| orderStatus | Integer | 订单状态码 |
|
|
||||||
| orderStatusDesc | String | 订单状态描述 |
|
|
||||||
| totalAmount | BigDecimal | 订单总金额 |
|
|
||||||
| currency | String | 货币类型 |
|
|
||||||
| createTime | String | 创建时间 |
|
|
||||||
| canConsume | Boolean | 是否可核销 |
|
|
||||||
| consumeReason | String | 不可核销原因(如果不可核销) |
|
|
||||||
|
|
||||||
#### 订单项信息 (OrderItemDetailVO)
|
|
||||||
| 字段名 | 类型 | 说明 |
|
|
||||||
|--------|------|------|
|
|
||||||
| itemId | Long | 订单项ID |
|
|
||||||
| productId | String | 商品ID(用于核销) |
|
|
||||||
| itemName | String | 商品名称 |
|
|
||||||
| itemType | String | 商品类型 |
|
|
||||||
| plu | String | 商品编码 |
|
|
||||||
| quantity | Integer | 总数量 |
|
|
||||||
| unitPrice | BigDecimal | 单价 |
|
|
||||||
| totalPrice | BigDecimal | 总价 |
|
|
||||||
| currency | String | 货币类型 |
|
|
||||||
| useStartDate | String | 使用开始日期 |
|
|
||||||
| useEndDate | String | 使用结束日期 |
|
|
||||||
| canConsume | Boolean | 是否可核销 |
|
|
||||||
| usedQuantity | Integer | 已使用数量 |
|
|
||||||
| availableQuantity | Integer | 可用数量 |
|
|
||||||
|
|
||||||
#### 乘客信息 (PassengerDetailVO)
|
|
||||||
| 字段名 | 类型 | 说明 |
|
|
||||||
|--------|------|------|
|
|
||||||
| passengerId | String | 乘客ID |
|
|
||||||
| passengerName | String | 乘客姓名 |
|
|
||||||
| phone | String | 乘客手机号 |
|
|
||||||
| passengerStatus | Integer | 乘客状态 |
|
|
||||||
| passengerStatusDesc | String | 乘客状态描述 |
|
|
||||||
| idCard | String | 身份证号 |
|
|
||||||
| gender | String | 性别 |
|
|
||||||
| age | Integer | 年龄 |
|
|
||||||
|
|
||||||
#### 联系人信息 (ContactDetailVO)
|
|
||||||
| 字段名 | 类型 | 说明 |
|
|
||||||
|--------|------|------|
|
|
||||||
| name | String | 联系人姓名 |
|
|
||||||
| mobile | String | 联系人手机号 |
|
|
||||||
| email | String | 联系人邮箱 |
|
|
||||||
| contactType | String | 联系人类型 |
|
|
||||||
|
|
||||||
## 2. 简化核销接口(推荐)
|
|
||||||
|
|
||||||
### 接口信息
|
|
||||||
- **接口地址**: `POST /api/order-detail/consume-simple`
|
|
||||||
- **功能描述**: 核销单个订单项
|
|
||||||
- **请求方式**: POST
|
|
||||||
|
|
||||||
### 请求参数
|
|
||||||
|
|
||||||
| 参数名 | 类型 | 必填 | 说明 |
|
|
||||||
|--------|------|------|------|
|
|
||||||
| otaOrderId | String | 是 | 携程订单号 |
|
|
||||||
| orderNo | String | 否 | 关联的订单中心订单号(用于更新订单状态) |
|
|
||||||
| itemId | String | 是 | 商品ID |
|
|
||||||
| useQuantity | Integer | 是 | 核销数量 |
|
|
||||||
| remark | String | 否 | 备注信息 |
|
|
||||||
|
|
||||||
**请求示例:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"otaOrderId": "ctriptest-10816828-454259-145573",
|
|
||||||
"orderNo": "ORDER_20250901_001",
|
|
||||||
"itemId": "1801589811",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "使用优惠券核销门票"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**业务逻辑:**
|
|
||||||
1. 验证携程订单是否存在且可核销
|
|
||||||
2. 如果传入了 `orderNo`,建立携程订单与订单中心订单的关联关系
|
|
||||||
3. 执行核销操作,更新携程订单状态为已使用(状态8)
|
|
||||||
4. 如果有关联的订单号,自动调用订单中心接口更新订单状态为已支付(状态1)
|
|
||||||
5. 设置支付类型为优惠券支付(类型2)
|
|
||||||
|
|
||||||
### 参数说明
|
|
||||||
|
|
||||||
| 参数名 | 类型 | 必填 | 说明 |
|
|
||||||
|--------|------|------|------|
|
|
||||||
| otaOrderId | String | 是 | 携程订单号 |
|
|
||||||
| itemId | String | 是 | 商品ID(使用查询接口返回的productId) |
|
|
||||||
| useQuantity | Integer | 是 | 核销数量 |
|
|
||||||
| remark | String | 否 | 备注信息 |
|
|
||||||
|
|
||||||
### 响应结果
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "核销成功",
|
|
||||||
"data": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 错误响应
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 1,
|
|
||||||
"resp_msg": "核销失败: 订单不存在",
|
|
||||||
"data": false
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 3. 复杂核销接口(支持批量)
|
|
||||||
|
|
||||||
### 接口信息
|
|
||||||
- **接口地址**: `POST /api/order-detail/consume`
|
|
||||||
- **功能描述**: 批量核销多个订单项
|
|
||||||
- **请求方式**: POST
|
|
||||||
|
|
||||||
### 请求参数
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"otaOrderId": "ctriptest-10816828-454259-145573",
|
|
||||||
"supplierOrderId": "SUPPLIER_ctriptest-10816828-454259-145573_301495ef",
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"itemId": "1801589811",
|
|
||||||
"plu": "1",
|
|
||||||
"quantity": 1,
|
|
||||||
"passengerIds": ["PASS_1"],
|
|
||||||
"voucherIds": ["VOUCHER_1"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"remark": "使用优惠券核销门票"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 参数说明
|
|
||||||
|
|
||||||
| 参数名 | 类型 | 必填 | 说明 |
|
|
||||||
|--------|------|------|------|
|
|
||||||
| otaOrderId | String | 是 | 携程订单号 |
|
|
||||||
| supplierOrderId | String | 是 | 供应商订单号 |
|
|
||||||
| items | Array | 是 | 核销项目列表 |
|
|
||||||
| remark | String | 否 | 备注信息 |
|
|
||||||
|
|
||||||
#### items数组元素
|
|
||||||
| 参数名 | 类型 | 必填 | 说明 |
|
|
||||||
|--------|------|------|------|
|
|
||||||
| itemId | String | 是 | 商品ID |
|
|
||||||
| plu | String | 是 | 商品编码 |
|
|
||||||
| quantity | Integer | 是 | 核销数量 |
|
|
||||||
| passengerIds | Array | 否 | 乘客ID列表 |
|
|
||||||
| voucherIds | Array | 否 | 凭证ID列表 |
|
|
||||||
|
|
||||||
### 响应结果
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "核销成功",
|
|
||||||
"data": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 4. 验证订单是否可核销
|
|
||||||
|
|
||||||
### 接口信息
|
|
||||||
- **接口地址**: `GET /api/order-detail/{otaOrderId}/validate`
|
|
||||||
- **功能描述**: 验证指定订单是否可核销
|
|
||||||
- **请求方式**: GET
|
|
||||||
|
|
||||||
### 请求参数
|
|
||||||
|
|
||||||
| 参数名 | 类型 | 必填 | 说明 |
|
|
||||||
|--------|------|------|------|
|
|
||||||
| otaOrderId | String | 是 | 携程订单号(路径参数) |
|
|
||||||
|
|
||||||
### 响应结果
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "",
|
|
||||||
"data": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 5. 调试接口
|
|
||||||
|
|
||||||
### 接口信息
|
|
||||||
- **接口地址**: `GET /api/order-detail/debug/data`
|
|
||||||
- **功能描述**: 调试接口,检查数据库中的数据情况
|
|
||||||
- **请求方式**: GET
|
|
||||||
|
|
||||||
### 响应结果
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "",
|
|
||||||
"data": {
|
|
||||||
"orderCount": 10,
|
|
||||||
"passengerCount": 20,
|
|
||||||
"contactCount": 15,
|
|
||||||
"orderItemCount": 25,
|
|
||||||
"latestOrders": [...],
|
|
||||||
"passengersForPhone": 1,
|
|
||||||
"passengerDetails": [...],
|
|
||||||
"contactsForPhone": 1,
|
|
||||||
"contactDetails": [...]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 6. 前端集成示例
|
|
||||||
|
|
||||||
### JavaScript/TypeScript 示例
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 查询可核销订单
|
|
||||||
async function queryConsumableOrdersByCode(codeId: string, page = 1, size = 10) {
|
|
||||||
const response = await fetch('/api/order-detail/query', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ codeId, page, size })
|
|
||||||
});
|
|
||||||
const result = await response.json();
|
|
||||||
return result.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 简化核销订单
|
|
||||||
async function consumeOrderSimple(otaOrderId: string, itemId: string, useQuantity: number, remark: string) {
|
|
||||||
const response = await fetch('/api/order-detail/consume-simple', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ otaOrderId, itemId, useQuantity, remark })
|
|
||||||
});
|
|
||||||
const result = await response.json();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 注意
|
|
||||||
- 无需传手机号和价格,后端会自动从登录上下文与二维码信息中获取。
|
|
||||||
|
|
||||||
## 7. 错误码说明
|
|
||||||
|
|
||||||
| 错误码 | 说明 |
|
|
||||||
|--------|------|
|
|
||||||
| 0 | 成功 |
|
|
||||||
| 1 | 失败 |
|
|
||||||
| 1001 | 参数错误 |
|
|
||||||
| 1002 | 订单不存在 |
|
|
||||||
| 1003 | 订单不可核销 |
|
|
||||||
| 1004 | 商品不存在 |
|
|
||||||
| 1005 | 核销数量超出限制 |
|
|
||||||
|
|
||||||
## 8. 注意事项
|
|
||||||
|
|
||||||
1. **手机号格式**: 建议统一使用11位数字格式,如 `18322694510`
|
|
||||||
2. **价格精度**: 使用 `BigDecimal` 类型处理价格,避免精度问题
|
|
||||||
3. **itemId映射**: 核销时使用查询接口返回的 `productId` 作为 `itemId`
|
|
||||||
4. **状态验证**: 只有状态为1(已确认)或13(支付确认)的订单可以核销
|
|
||||||
5. **数量限制**: 核销数量不能超过 `availableQuantity`
|
|
||||||
6. **错误处理**: 前端需要处理核销失败的情况,并给出用户友好的提示
|
|
||||||
|
|
||||||
## 9. 测试用例
|
|
||||||
|
|
||||||
### 测试数据
|
|
||||||
- 手机号: `18322694510`
|
|
||||||
- 优惠券价格: `2.0`
|
|
||||||
- 订单号: `ctriptest-10816828-454259-145573`
|
|
||||||
- 商品ID: `1801589811`
|
|
||||||
|
|
||||||
### 测试步骤
|
|
||||||
1. 调用查询接口,确认能返回订单数据
|
|
||||||
2. 调用验证接口,确认订单可核销
|
|
||||||
3. 调用核销接口,确认核销成功
|
|
||||||
4. 再次调用查询接口,确认订单状态已更新
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
# 前端核销传参方案
|
|
||||||
|
|
||||||
## 核销接口参数结构
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"otaOrderId": "ctriptest-10816870-454259-145573",
|
|
||||||
"itemId": "106943568",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "门票入园核销"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 前端传参方案
|
|
||||||
|
|
||||||
### 方案一:直接使用订单项ID
|
|
||||||
|
|
||||||
**查询接口返回的订单项数据:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"orderItems": [
|
|
||||||
{
|
|
||||||
"itemId": 456, // 数据库主键ID
|
|
||||||
"productId": "106943568", // 商品ID(携程的itemId)
|
|
||||||
"itemName": "门票",
|
|
||||||
"plu": "1",
|
|
||||||
"quantity": 2,
|
|
||||||
"canConsume": true,
|
|
||||||
"availableQuantity": 2
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**前端传参:**
|
|
||||||
```javascript
|
|
||||||
// 选择第一个可核销的订单项
|
|
||||||
const orderItem = order.orderItems.find(item => item.canConsume);
|
|
||||||
const consumeParams = {
|
|
||||||
otaOrderId: order.otaOrderId,
|
|
||||||
itemId: orderItem.productId, // 使用productId作为itemId
|
|
||||||
useQuantity: 1, // 核销数量
|
|
||||||
remark: "使用优惠券核销门票"
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
### 方案二:支持批量核销
|
|
||||||
|
|
||||||
如果需要支持一次核销多个订单项,可以这样设计:
|
|
||||||
|
|
||||||
**前端传参:**
|
|
||||||
```javascript
|
|
||||||
// 核销多个订单项
|
|
||||||
const consumeParams = {
|
|
||||||
otaOrderId: order.otaOrderId,
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
itemId: "106943568",
|
|
||||||
useQuantity: 1,
|
|
||||||
remark: "核销门票1张"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
itemId: "106943569",
|
|
||||||
useQuantity: 1,
|
|
||||||
remark: "核销门票1张"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## 推荐实现方案
|
|
||||||
|
|
||||||
### 1. 使用简化核销接口
|
|
||||||
|
|
||||||
**接口地址:** `POST /api/order-detail/consume-simple`
|
|
||||||
|
|
||||||
**请求参数:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"otaOrderId": "ctriptest-10816870-454259-145573",
|
|
||||||
"itemId": "106943568",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "使用优惠券核销门票"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 前端实现示例
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
interface SimpleConsumeRequest {
|
|
||||||
otaOrderId: string;
|
|
||||||
itemId: string;
|
|
||||||
useQuantity: number;
|
|
||||||
remark?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 简化核销订单
|
|
||||||
async function consumeOrderSimple(request: SimpleConsumeRequest) {
|
|
||||||
const response = await fetch('/api/order-detail/consume-simple', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(request)
|
|
||||||
});
|
|
||||||
|
|
||||||
return response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用示例
|
|
||||||
function handleConsume() {
|
|
||||||
const orderItem = order.orderItems.find(item => item.canConsume);
|
|
||||||
|
|
||||||
if (orderItem) {
|
|
||||||
const consumeRequest: SimpleConsumeRequest = {
|
|
||||||
otaOrderId: order.otaOrderId,
|
|
||||||
itemId: orderItem.productId, // 使用productId作为itemId
|
|
||||||
useQuantity: 1, // 核销数量
|
|
||||||
remark: `使用优惠券核销${orderItem.itemName}`
|
|
||||||
};
|
|
||||||
|
|
||||||
consumeOrderSimple(consumeRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 前端UI交互设计
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 订单项选择组件
|
|
||||||
function OrderItemSelector({ orderItem, onSelect }) {
|
|
||||||
const [selectedQuantity, setSelectedQuantity] = useState(0);
|
|
||||||
const maxQuantity = orderItem.availableQuantity;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="order-item">
|
|
||||||
<div className="item-info">
|
|
||||||
<span>{orderItem.itemName}</span>
|
|
||||||
<span>可用数量: {maxQuantity}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{orderItem.canConsume && (
|
|
||||||
<div className="quantity-selector">
|
|
||||||
<button
|
|
||||||
onClick={() => setSelectedQuantity(Math.max(0, selectedQuantity - 1))}
|
|
||||||
disabled={selectedQuantity <= 0}
|
|
||||||
>
|
|
||||||
-
|
|
||||||
</button>
|
|
||||||
<span>{selectedQuantity}</span>
|
|
||||||
<button
|
|
||||||
onClick={() => setSelectedQuantity(Math.min(maxQuantity, selectedQuantity + 1))}
|
|
||||||
disabled={selectedQuantity >= maxQuantity}
|
|
||||||
>
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 核销按钮
|
|
||||||
function ConsumeButton({ order, selectedItems }) {
|
|
||||||
const canConsume = selectedItems.length > 0 &&
|
|
||||||
selectedItems.every(item => item.useQuantity > 0);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
onClick={() => handleConsume(order, selectedItems)}
|
|
||||||
disabled={!canConsume}
|
|
||||||
>
|
|
||||||
确认核销
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 数据映射关系
|
|
||||||
|
|
||||||
| 查询接口返回字段 | 核销接口参数 | 说明 |
|
|
||||||
|----------------|-------------|------|
|
|
||||||
| `orderItems[].productId` | `itemId` | 携程的商品ID |
|
|
||||||
| `orderItems[].availableQuantity` | `useQuantity` | 可核销数量 |
|
|
||||||
| `orderItems[].itemName` | `remark` | 商品名称用于备注 |
|
|
||||||
|
|
||||||
## 注意事项
|
|
||||||
|
|
||||||
1. **itemId映射**:使用 `productId` 作为核销接口的 `itemId`
|
|
||||||
2. **数量验证**:核销数量不能超过 `availableQuantity`
|
|
||||||
3. **状态检查**:只允许核销 `canConsume=true` 的订单项
|
|
||||||
4. **批量支持**:建议支持一次核销多个订单项
|
|
||||||
5. **错误处理**:前端需要处理核销失败的情况
|
|
||||||
@@ -1,288 +0,0 @@
|
|||||||
# 订单明细查询核销接口使用示例
|
|
||||||
|
|
||||||
## 场景描述
|
|
||||||
|
|
||||||
用户有一张100元的优惠券,想要查询可以用这张优惠券核销的携程订单。
|
|
||||||
|
|
||||||
## 使用步骤
|
|
||||||
|
|
||||||
### 1. 查询可核销订单
|
|
||||||
|
|
||||||
**请求:**
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:8002/coupon/api/order-detail/query \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"userPhone": "13800138000",
|
|
||||||
"couponPrice": 100.00,
|
|
||||||
"onlyConsumable": true,
|
|
||||||
"page": 1,
|
|
||||||
"size": 10
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
**响应:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "",
|
|
||||||
"data": {
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"orderId": 123,
|
|
||||||
"otaOrderId": "ctriptest-10816828-454259-145573",
|
|
||||||
"supplierOrderId": "SUPPLIER_ctriptest-10816828-454259-145573_301495ef",
|
|
||||||
"orderStatus": 1,
|
|
||||||
"orderStatusDesc": "已确认",
|
|
||||||
"totalAmount": 100.00,
|
|
||||||
"currency": "CNY",
|
|
||||||
"createTime": "2025-08-30T09:33:42",
|
|
||||||
"orderItems": [
|
|
||||||
{
|
|
||||||
"itemId": 456,
|
|
||||||
"productId": "1801589811",
|
|
||||||
"itemName": "门票",
|
|
||||||
"itemType": "1",
|
|
||||||
"plu": "1",
|
|
||||||
"quantity": 2,
|
|
||||||
"unitPrice": 50.00,
|
|
||||||
"totalPrice": 100.00,
|
|
||||||
"currency": "CNY",
|
|
||||||
"useStartDate": "2025-07-25",
|
|
||||||
"useEndDate": "2025-07-25",
|
|
||||||
"canConsume": true,
|
|
||||||
"usedQuantity": 0,
|
|
||||||
"availableQuantity": 2
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"passengers": [
|
|
||||||
{
|
|
||||||
"passengerId": "PASS_1",
|
|
||||||
"passengerName": "张三",
|
|
||||||
"phone": "13800138000",
|
|
||||||
"passengerStatus": 0,
|
|
||||||
"passengerStatusDesc": "未使用",
|
|
||||||
"idCard": "110101199001011234",
|
|
||||||
"gender": "ADULT",
|
|
||||||
"age": null
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"contact": {
|
|
||||||
"name": "张三",
|
|
||||||
"mobile": "13800138000",
|
|
||||||
"email": "zhangsan@example.com",
|
|
||||||
"contactType": "BOOKER"
|
|
||||||
},
|
|
||||||
"canConsume": true,
|
|
||||||
"consumeReason": null
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"count": 1,
|
|
||||||
"resp_code": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 验证订单是否可核销
|
|
||||||
|
|
||||||
**请求:**
|
|
||||||
```bash
|
|
||||||
curl -X GET http://localhost:8002/coupon/api/order-detail/ctriptest-10816828-454259-145573/validate
|
|
||||||
```
|
|
||||||
|
|
||||||
**响应:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "",
|
|
||||||
"data": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 执行简化核销操作
|
|
||||||
|
|
||||||
**请求:**
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:8002/coupon/api/order-detail/consume-simple \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"otaOrderId": "ctriptest-10816870-454259-145573",
|
|
||||||
"itemId": "106943568",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "使用100元优惠券核销门票"
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
**响应:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "核销成功",
|
|
||||||
"data": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 前端集成示例
|
|
||||||
|
|
||||||
### JavaScript/TypeScript
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 查询可核销订单
|
|
||||||
async function queryConsumableOrders(userPhone: string, couponPrice: number) {
|
|
||||||
const response = await fetch('/api/order-detail/query', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
userPhone,
|
|
||||||
couponPrice,
|
|
||||||
onlyConsumable: true,
|
|
||||||
page: 1,
|
|
||||||
size: 10
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
return result.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 简化核销订单
|
|
||||||
async function consumeOrderSimple(otaOrderId: string, itemId: string, useQuantity: number, remark: string) {
|
|
||||||
const response = await fetch('/api/order-detail/consume-simple', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
otaOrderId,
|
|
||||||
itemId,
|
|
||||||
useQuantity,
|
|
||||||
remark
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用示例
|
|
||||||
async function useCoupon() {
|
|
||||||
const userPhone = '13800138000';
|
|
||||||
const couponPrice = 100.00;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. 查询可核销订单
|
|
||||||
const orders = await queryConsumableOrders(userPhone, couponPrice);
|
|
||||||
console.log('可核销订单:', orders);
|
|
||||||
|
|
||||||
if (orders.data.length > 0) {
|
|
||||||
const order = orders.data[0];
|
|
||||||
const orderItem = order.orderItems.find(item => item.canConsume);
|
|
||||||
|
|
||||||
if (orderItem) {
|
|
||||||
// 2. 执行简化核销
|
|
||||||
const consumeResult = await consumeOrderSimple(
|
|
||||||
order.otaOrderId,
|
|
||||||
orderItem.productId, // 使用productId作为itemId
|
|
||||||
1, // 核销数量
|
|
||||||
'使用优惠券核销'
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log('核销结果:', consumeResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('操作失败:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### React Hook 示例
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
|
|
||||||
interface OrderDetail {
|
|
||||||
orderId: number;
|
|
||||||
otaOrderId: string;
|
|
||||||
supplierOrderId: string;
|
|
||||||
totalAmount: number;
|
|
||||||
canConsume: boolean;
|
|
||||||
orderItems: any[];
|
|
||||||
passengers: any[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useConsumableOrders(userPhone: string, couponPrice: number) {
|
|
||||||
const [orders, setOrders] = useState<OrderDetail[]>([]);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
const fetchOrders = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch('/api/order-detail/query', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({
|
|
||||||
userPhone,
|
|
||||||
couponPrice,
|
|
||||||
onlyConsumable: true,
|
|
||||||
page: 1,
|
|
||||||
size: 10
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
if (result.resp_code === 0) {
|
|
||||||
setOrders(result.data.data);
|
|
||||||
} else {
|
|
||||||
setError(result.resp_msg);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
setError('查询失败');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const consumeOrder = async (order: OrderDetail, itemId: string, useQuantity: number) => {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/api/order-detail/consume-simple', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({
|
|
||||||
otaOrderId: order.otaOrderId,
|
|
||||||
itemId: itemId,
|
|
||||||
useQuantity: useQuantity,
|
|
||||||
remark: '使用优惠券核销'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
return result.resp_code === 0;
|
|
||||||
} catch (err) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (userPhone && couponPrice) {
|
|
||||||
fetchOrders();
|
|
||||||
}
|
|
||||||
}, [userPhone, couponPrice]);
|
|
||||||
|
|
||||||
return { orders, loading, error, consumeOrder, refetch: fetchOrders };
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 注意事项
|
|
||||||
|
|
||||||
1. **优惠券价格匹配**:订单总金额必须与优惠券价格完全匹配
|
|
||||||
2. **可核销条件**:只有已确认且在使用有效期内的订单才能核销
|
|
||||||
3. **数量限制**:核销数量不能超过订单项的剩余可用数量
|
|
||||||
4. **幂等性**:重复核销同一订单项会返回成功,但不会重复扣减数量
|
|
||||||
5. **错误处理**:建议在前端做好错误处理和用户提示
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
# 携程API配置说明
|
|
||||||
|
|
||||||
## 配置结构
|
|
||||||
|
|
||||||
### 1. 配置文件位置
|
|
||||||
- **配置文件**: `src/main/resources/application.yml`
|
|
||||||
|
|
||||||
### 2. 配置项说明
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
spring:
|
|
||||||
# 环境配置:test(测试环境) / prod(生产环境)
|
|
||||||
profiles:
|
|
||||||
active: test
|
|
||||||
|
|
||||||
ctrip:
|
|
||||||
# AES加密配置
|
|
||||||
aes:
|
|
||||||
key: 087b36ad0dff7942 # AES密钥
|
|
||||||
iv: 750e15a31356a99d # AES IV
|
|
||||||
|
|
||||||
# API配置
|
|
||||||
api:
|
|
||||||
test-url: https://ttdopen.ctrip.com/api # 测试环境URL
|
|
||||||
prod-url: https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier # 生产环境URL
|
|
||||||
environment: test # 当前环境:test/prod
|
|
||||||
timeout: 30000 # 请求超时时间(毫秒)
|
|
||||||
retry-times: 3 # 重试次数
|
|
||||||
|
|
||||||
# 账户配置
|
|
||||||
account:
|
|
||||||
id: c50a8f2a59c9e7 # 账户ID
|
|
||||||
secret: ce6033ae31124ec5cdab3d2bc79f2622 # 账户密钥
|
|
||||||
```
|
|
||||||
|
|
||||||
## 环境切换
|
|
||||||
|
|
||||||
### 1. 测试环境(默认)
|
|
||||||
```bash
|
|
||||||
# 使用默认配置(测试环境)
|
|
||||||
java -jar coupon-center.jar
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 生产环境
|
|
||||||
```bash
|
|
||||||
# 使用生产环境配置
|
|
||||||
java -jar coupon-center.jar --spring.profiles.active=prod
|
|
||||||
```
|
|
||||||
|
|
||||||
或者在 `application.yml` 中设置:
|
|
||||||
```yaml
|
|
||||||
spring:
|
|
||||||
profiles:
|
|
||||||
active: prod
|
|
||||||
```
|
|
||||||
|
|
||||||
## URL配置说明
|
|
||||||
|
|
||||||
### 1. 测试环境
|
|
||||||
- **基础URL**: `https://ttdopen.ctrip.com/api`
|
|
||||||
- **订单通知接口**: `https://ttdopen.ctrip.com/api/order/notice.do`
|
|
||||||
|
|
||||||
### 2. 生产环境
|
|
||||||
- **基础URL**: `https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier`
|
|
||||||
- **订单通知接口**: `https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier/order/notice.do`
|
|
||||||
|
|
||||||
## 代码使用
|
|
||||||
|
|
||||||
### 1. 注入配置
|
|
||||||
```java
|
|
||||||
@Autowired
|
|
||||||
private CtripApiConfig ctripApiConfig;
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 获取URL
|
|
||||||
```java
|
|
||||||
// 获取当前环境的订单通知URL
|
|
||||||
String url = ctripApiConfig.getApi().getOrderNoticeUrl();
|
|
||||||
|
|
||||||
// 获取当前环境的基础URL
|
|
||||||
String baseUrl = ctripApiConfig.getApi().getBaseUrl();
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 获取账户信息
|
|
||||||
```java
|
|
||||||
String accountId = ctripApiConfig.getAccount().getId();
|
|
||||||
String accountSecret = ctripApiConfig.getAccount().getSecret();
|
|
||||||
```
|
|
||||||
|
|
||||||
## 安全注意事项
|
|
||||||
|
|
||||||
1. **生产环境密钥**: 生产环境的AES密钥和账户密钥应该通过环境变量或配置中心管理
|
|
||||||
2. **日志级别**: 生产环境建议将敏感信息的日志级别设置为WARN或ERROR
|
|
||||||
3. **网络访问**: 确保服务器能够访问携程的API地址
|
|
||||||
4. **超时配置**: 根据网络情况调整timeout和retry-times参数
|
|
||||||
|
|
||||||
## 故障排查
|
|
||||||
|
|
||||||
### 1. 网络连接问题
|
|
||||||
```bash
|
|
||||||
# 测试网络连接
|
|
||||||
curl -I https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier/order/notice.do
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 配置验证
|
|
||||||
```java
|
|
||||||
// 在启动时验证配置
|
|
||||||
@PostConstruct
|
|
||||||
public void validateConfig() {
|
|
||||||
log.info("当前环境: {}", ctripApiConfig.getApi().getEnvironment());
|
|
||||||
log.info("API URL: {}", ctripApiConfig.getApi().getOrderNoticeUrl());
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 日志监控
|
|
||||||
```yaml
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
com.central.coupon.service.impl.CtripConsumedServiceImpl: DEBUG
|
|
||||||
com.central.coupon.util.CtripDecryptUtil: DEBUG
|
|
||||||
```
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
# 携程核销订单状态更新确认
|
|
||||||
|
|
||||||
## 完整流程确认
|
|
||||||
|
|
||||||
### 1. 前端调用核销接口
|
|
||||||
```java
|
|
||||||
// 前端调用 OrderDetailController.consumeOrderSimple
|
|
||||||
POST /api-coupon/api/order-detail/consume-simple
|
|
||||||
{
|
|
||||||
"otaOrderId": "ctriptest-xxx",
|
|
||||||
"orderNo": "ORDER_20250901_001", // 关联的订单中心订单号
|
|
||||||
"itemId": "123456",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "优惠券核销"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 建立订单关联关系
|
|
||||||
```java
|
|
||||||
// OrderDetailController.consumeOrderSimple 第3步
|
|
||||||
if (consumeDTO.getOrderNo() != null && !consumeDTO.getOrderNo().trim().isEmpty()) {
|
|
||||||
if (order.getOrderNo() == null || order.getOrderNo().trim().isEmpty()) {
|
|
||||||
// 更新携程订单的orderNo字段
|
|
||||||
order.setOrderNo(consumeDTO.getOrderNo());
|
|
||||||
ctripOrderMapper.updateById(order);
|
|
||||||
log.info("建立订单关联关系,otaOrderId: {}, orderNo: {}",
|
|
||||||
consumeDTO.getOtaOrderId(), consumeDTO.getOrderNo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 调用核销服务
|
|
||||||
```java
|
|
||||||
// OrderDetailController.consumeOrderSimple 第4步
|
|
||||||
CtripConsumedNoticeResponse response = ctripConsumedService.consumeOrder(request);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 核销服务执行流程
|
|
||||||
```java
|
|
||||||
// CtripConsumedServiceImpl.consumeOrder()
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public CtripConsumedNoticeResponse consumeOrder(CtripConsumeRequest request) {
|
|
||||||
// 1. 验证请求参数
|
|
||||||
// 2. 检查订单是否存在
|
|
||||||
// 3. 生成序列号
|
|
||||||
// 4. 保存核销记录到本地数据库
|
|
||||||
// 5. 更新订单状态 ← 这里会触发订单中心更新
|
|
||||||
updateOrderStatus(order, request.getUseQuantity());
|
|
||||||
// 6. 生成OrderConsumedNotice请求体
|
|
||||||
// 7. 返回成功响应
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. 更新携程订单状态
|
|
||||||
```java
|
|
||||||
// CtripConsumedServiceImpl.updateOrderStatus()
|
|
||||||
private void updateOrderStatus(CtripOrder order, Integer useQuantity) {
|
|
||||||
// 查询该订单的所有核销记录
|
|
||||||
List<CtripConsumed> consumedList = ctripConsumedMapper.selectByOtaOrderId(order.getOtaOrderId());
|
|
||||||
|
|
||||||
// 计算总使用数量
|
|
||||||
int totalUseQuantity = consumedList.stream()
|
|
||||||
.mapToInt(c -> c.getUseQuantity() != null ? c.getUseQuantity() : 0)
|
|
||||||
.sum();
|
|
||||||
|
|
||||||
// 如果使用数量大于0,更新订单状态为已使用(状态8)
|
|
||||||
if (totalUseQuantity > 0) {
|
|
||||||
order.setStatus(8); // 已使用状态
|
|
||||||
ctripOrderMapper.updateById(order);
|
|
||||||
log.info("订单状态更新为已使用,otaOrderId: {}, totalUseQuantity: {}",
|
|
||||||
order.getOtaOrderId(), totalUseQuantity);
|
|
||||||
|
|
||||||
// 6. 更新订单中心订单状态(如果有关联的订单号)
|
|
||||||
updateOrderCenterStatus(order);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6. 更新订单中心状态
|
|
||||||
```java
|
|
||||||
// CtripConsumedServiceImpl.updateOrderCenterStatus()
|
|
||||||
private void updateOrderCenterStatus(CtripOrder order) {
|
|
||||||
if (StringUtils.hasText(order.getOrderNo())) {
|
|
||||||
log.info("开始更新订单中心订单状态,orderNo: {}", order.getOrderNo());
|
|
||||||
|
|
||||||
// 调用订单中心接口更新订单状态为已支付(状态1)
|
|
||||||
Result<String> result = orderCenterService.updateOrderStatusToPaid(order.getOrderNo());
|
|
||||||
|
|
||||||
if (result != null && result.getResp_code() == 0) {
|
|
||||||
log.info("订单中心订单状态更新成功,orderNo: {}", order.getOrderNo());
|
|
||||||
} else {
|
|
||||||
log.error("订单中心订单状态更新失败,orderNo: {}, result: {}",
|
|
||||||
order.getOrderNo(), result);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.warn("携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: {}",
|
|
||||||
order.getOtaOrderId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 7. 订单中心状态更新接口
|
|
||||||
```java
|
|
||||||
// OrderController.updateOrderStatusToPaid()
|
|
||||||
@PostMapping("/order/{orderNo}/status/paid")
|
|
||||||
public Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo) {
|
|
||||||
Order order = orderService.getOrderByNumber(orderNo);
|
|
||||||
|
|
||||||
if (order.getOrderStatus().equals(OrderStatus.UNPAID.getId())) {
|
|
||||||
// 更新订单状态为已支付排队中
|
|
||||||
order.setOrderStatus(OrderStatus.PAID.getId());
|
|
||||||
// 设置支付类型为优惠券支付
|
|
||||||
order.setPayType(2); // 2表示优惠券支付
|
|
||||||
// 设置支付时间
|
|
||||||
order.setPayTime(new Date());
|
|
||||||
|
|
||||||
boolean result = orderService.updateOrder(order);
|
|
||||||
if (result) {
|
|
||||||
log.info("订单状态更新成功,orderNo: {}, 新状态: {}", orderNo, OrderStatus.PAID.getId());
|
|
||||||
return Result.succeed("订单状态更新成功");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 关键日志点确认
|
|
||||||
|
|
||||||
### 成功流程日志
|
|
||||||
```
|
|
||||||
简化核销订单,订单号: ctriptest-xxx, 商品ID: 123456, 数量: 1, 关联订单号: ORDER_20250901_001
|
|
||||||
建立订单关联关系,otaOrderId: ctriptest-xxx, orderNo: ORDER_20250901_001
|
|
||||||
开始执行核销订单,otaOrderId: ctriptest-xxx, itemId: 123456, useQuantity: 1
|
|
||||||
核销记录保存成功,sequenceId: 20250901xxx
|
|
||||||
订单状态更新为已使用,otaOrderId: ctriptest-xxx, totalUseQuantity: 1
|
|
||||||
开始更新订单中心订单状态,orderNo: ORDER_20250901_001
|
|
||||||
订单中心订单状态更新成功,orderNo: ORDER_20250901_001
|
|
||||||
核销订单执行成功,otaOrderId: ctriptest-xxx, sequenceId: 20250901xxx
|
|
||||||
核销成功,订单号: ctriptest-xxx, 关联订单号: ORDER_20250901_001
|
|
||||||
```
|
|
||||||
|
|
||||||
### 订单中心日志
|
|
||||||
```
|
|
||||||
优惠券核销成功,更新订单状态为已支付,orderNo: ORDER_20250901_001
|
|
||||||
订单状态更新成功,orderNo: ORDER_20250901_001, 新状态: 1
|
|
||||||
```
|
|
||||||
|
|
||||||
## 数据库状态变化确认
|
|
||||||
|
|
||||||
### 携程订单表 (t_ctrip_order)
|
|
||||||
```sql
|
|
||||||
-- 核销前
|
|
||||||
SELECT ota_order_id, order_no, status FROM t_ctrip_order WHERE ota_order_id = 'ctriptest-xxx';
|
|
||||||
-- 结果: status = 1 (已确认), order_no = NULL
|
|
||||||
|
|
||||||
-- 核销后
|
|
||||||
SELECT ota_order_id, order_no, status FROM t_ctrip_order WHERE ota_order_id = 'ctriptest-xxx';
|
|
||||||
-- 结果: status = 8 (已使用), order_no = 'ORDER_20250901_001'
|
|
||||||
```
|
|
||||||
|
|
||||||
### 订单中心表 (orders)
|
|
||||||
```sql
|
|
||||||
-- 核销前
|
|
||||||
SELECT order_no, order_status, pay_type, pay_time FROM orders WHERE order_no = 'ORDER_20250901_001';
|
|
||||||
-- 结果: order_status = 0 (未支付), pay_type = NULL, pay_time = NULL
|
|
||||||
|
|
||||||
-- 核销后
|
|
||||||
SELECT order_no, order_status, pay_type, pay_time FROM orders WHERE order_no = 'ORDER_20250901_001';
|
|
||||||
-- 结果: order_status = 1 (已支付), pay_type = 2 (优惠券支付), pay_time = 2025-09-01 17:32:30
|
|
||||||
```
|
|
||||||
|
|
||||||
### 核销记录表 (t_ctrip_consumed)
|
|
||||||
```sql
|
|
||||||
-- 核销后新增记录
|
|
||||||
SELECT ota_order_id, supplier_order_id, item_id, use_quantity, create_time
|
|
||||||
FROM t_ctrip_consumed WHERE ota_order_id = 'ctriptest-xxx';
|
|
||||||
-- 结果: 新增一条核销记录
|
|
||||||
```
|
|
||||||
|
|
||||||
## 状态映射确认
|
|
||||||
|
|
||||||
| 系统 | 状态值 | 状态含义 | 说明 |
|
|
||||||
|------|--------|----------|------|
|
|
||||||
| 携程订单 | 0 | 待确认 | 预下单创建后 |
|
|
||||||
| 携程订单 | 1 | 已确认 | 预下单确认后 |
|
|
||||||
| 携程订单 | 8 | 已使用 | 核销成功后 |
|
|
||||||
| 订单中心 | 0 | 未支付 | 订单创建后 |
|
|
||||||
| 订单中心 | 1 | 已支付 | 核销成功后更新 |
|
|
||||||
|
|
||||||
## 支付类型确认
|
|
||||||
|
|
||||||
| 支付类型值 | 支付方式 | 说明 |
|
|
||||||
|------------|----------|------|
|
|
||||||
| 1 | 微信支付 | 用户通过微信支付 |
|
|
||||||
| 2 | 优惠券支付 | 用户使用优惠券核销 |
|
|
||||||
|
|
||||||
## 结论
|
|
||||||
|
|
||||||
✅ **流程完整**:前端调用 → 建立关联 → 核销执行 → 状态更新 → 订单中心更新
|
|
||||||
|
|
||||||
✅ **状态正确**:携程订单状态8(已使用),订单中心状态1(已支付)
|
|
||||||
|
|
||||||
✅ **关联正确**:通过orderNo字段建立携程订单与订单中心订单的关联
|
|
||||||
|
|
||||||
✅ **日志完整**:每个关键步骤都有详细的日志记录
|
|
||||||
|
|
||||||
✅ **异常处理**:即使订单中心更新失败,也不会影响核销流程
|
|
||||||
|
|
||||||
✅ **事务安全**:核销操作在事务中执行,确保数据一致性
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
# 携程订单状态说明
|
|
||||||
|
|
||||||
## 订单状态定义
|
|
||||||
|
|
||||||
| 状态码 | 状态名称 | 中文描述 | 是否可核销 | 说明 |
|
|
||||||
|--------|----------|----------|------------|------|
|
|
||||||
| 0 | PENDING | 待确认 | ❌ | 订单已创建但未确认 |
|
|
||||||
| 1 | CONFIRMED | 已确认 | ✅ | 订单已确认,可以核销 |
|
|
||||||
| 2 | CANCELLED | 已取消 | ❌ | 订单已取消 |
|
|
||||||
| 3 | REFUNDED | 已退款 | ❌ | 订单已退款 |
|
|
||||||
| 4 | CONSUMED | 已核销 | ❌ | 订单已核销完成 |
|
|
||||||
| 5 | FULLY_CANCELLED | 已取消 | ❌ | 订单完全取消 |
|
|
||||||
| 11 | WAITING_PAYMENT | 待支付 | ❌ | 等待支付 |
|
|
||||||
| 12 | PAYMENT_PENDING | 支付中 | ❌ | 支付处理中 |
|
|
||||||
| 13 | PAYMENT_CONFIRMED | 支付确认 | ✅ | 支付已确认,可以核销 |
|
|
||||||
| 14 | PRE_ORDER_CANCELLED | 预订单已取消 | ❌ | 预订单已取消 |
|
|
||||||
|
|
||||||
## 可核销状态
|
|
||||||
|
|
||||||
根据携程API文档和业务逻辑,以下状态的订单可以进行核销:
|
|
||||||
|
|
||||||
1. **状态1 - 已确认 (CONFIRMED)**
|
|
||||||
- 订单已确认,供应商已接受订单
|
|
||||||
- 可以进行核销操作
|
|
||||||
|
|
||||||
2. **状态13 - 支付确认 (PAYMENT_CONFIRMED)**
|
|
||||||
- 支付已确认,订单已支付完成
|
|
||||||
- 可以进行核销操作
|
|
||||||
|
|
||||||
## 核销验证逻辑
|
|
||||||
|
|
||||||
```java
|
|
||||||
// 检查订单状态是否允许核销
|
|
||||||
if (order.getStatus() == null || (order.getStatus() != 1 && order.getStatus() != 13)) {
|
|
||||||
return false; // 订单状态不允许核销
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 状态转换流程
|
|
||||||
|
|
||||||
```
|
|
||||||
创建订单 (0) → 确认订单 (1) → 支付确认 (13) → 核销 (4)
|
|
||||||
↓
|
|
||||||
取消 (2/5/14)
|
|
||||||
```
|
|
||||||
|
|
||||||
## 注意事项
|
|
||||||
|
|
||||||
1. **状态13是最常见的可核销状态**,因为大多数订单在支付确认后就可以进行核销
|
|
||||||
2. **状态1通常用于预付费订单**,在支付前就确认的订单
|
|
||||||
3. **状态4表示已核销**,核销完成后订单状态会变为4
|
|
||||||
4. **状态0、11、12** 表示订单还未完全确认,不能进行核销
|
|
||||||
5. **状态2、3、5、14** 表示订单已取消或退款,不能进行核销
|
|
||||||
@@ -1,240 +0,0 @@
|
|||||||
# 优惠券核销流程测试用例
|
|
||||||
|
|
||||||
## 测试目标
|
|
||||||
|
|
||||||
验证优惠券核销成功后,能够正确更新订单中心订单状态为"已支付"。
|
|
||||||
|
|
||||||
## 测试环境
|
|
||||||
|
|
||||||
- 优惠券中心服务:`coupon-center`
|
|
||||||
- 订单中心服务:`order-center`
|
|
||||||
- 数据库:MySQL
|
|
||||||
|
|
||||||
## 测试步骤
|
|
||||||
|
|
||||||
### 1. 准备测试数据
|
|
||||||
|
|
||||||
#### 1.1 创建订单中心订单
|
|
||||||
```sql
|
|
||||||
-- 在订单中心数据库中创建测试订单
|
|
||||||
INSERT INTO orders (
|
|
||||||
order_no, user_id, tourism_id, order_amount, order_status,
|
|
||||||
pay_type, code_id, device_sn, tenant_id, create_time, update_time
|
|
||||||
) VALUES (
|
|
||||||
'TEST_ORDER_001', 1, 1, '9990', 0, -- 0表示待支付
|
|
||||||
1, 'test-code-id', 'TEST_DEVICE_001', 'test-tenant',
|
|
||||||
NOW(), NOW()
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 1.2 创建携程订单(不关联订单号)
|
|
||||||
```sql
|
|
||||||
-- 在优惠券中心数据库中创建携程订单
|
|
||||||
INSERT INTO t_ctrip_order (
|
|
||||||
ota_order_id, supplier_order_id, sequence_id, status,
|
|
||||||
total_amount, currency, create_time, update_time
|
|
||||||
) VALUES (
|
|
||||||
'ctriptest-test-001', 'SUPPLIER_test_001', 'test-sequence-001', 13, -- 13表示支付已确认
|
|
||||||
99.90, 'CNY', NOW(), NOW()
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 测试场景
|
|
||||||
|
|
||||||
#### 场景1:核销时传入orderNo,建立关联关系
|
|
||||||
|
|
||||||
**请求:**
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"otaOrderId": "ctriptest-test-001",
|
|
||||||
"orderNo": "TEST_ORDER_001",
|
|
||||||
"itemId": "test-item-001",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "测试核销"
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
**预期结果:**
|
|
||||||
1. 核销成功,返回 `{"resp_code": 0, "resp_msg": "核销成功", "data": true}`
|
|
||||||
2. 携程订单状态更新为已使用(状态8)
|
|
||||||
3. 携程订单的 `order_no` 字段被设置为 `TEST_ORDER_001`
|
|
||||||
4. 订单中心订单状态更新为已支付(状态1)
|
|
||||||
5. 订单中心订单的 `pay_type` 字段被设置为优惠券支付(类型2)
|
|
||||||
|
|
||||||
**验证SQL:**
|
|
||||||
```sql
|
|
||||||
-- 验证携程订单状态和关联关系
|
|
||||||
SELECT ota_order_id, order_no, status FROM t_ctrip_order WHERE ota_order_id = 'ctriptest-test-001';
|
|
||||||
|
|
||||||
-- 验证订单中心订单状态
|
|
||||||
SELECT order_no, order_status, pay_type, pay_time FROM orders WHERE order_no = 'TEST_ORDER_001';
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 场景2:核销时未传入orderNo
|
|
||||||
|
|
||||||
**请求:**
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"otaOrderId": "ctriptest-test-002",
|
|
||||||
"itemId": "test-item-002",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "测试核销(无关联)"
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
**预期结果:**
|
|
||||||
1. 核销成功,返回 `{"resp_code": 0, "resp_msg": "核销成功", "data": true}`
|
|
||||||
2. 携程订单状态更新为已使用(状态8)
|
|
||||||
3. 携程订单的 `order_no` 字段为空
|
|
||||||
4. 不会调用订单中心接口更新状态
|
|
||||||
5. 日志中显示:`携程订单未关联订单中心订单号,无法更新订单状态`
|
|
||||||
|
|
||||||
#### 场景3:核销已关联的订单
|
|
||||||
|
|
||||||
**请求:**
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"otaOrderId": "ctriptest-test-001",
|
|
||||||
"orderNo": "TEST_ORDER_002", -- 传入不同的订单号
|
|
||||||
"itemId": "test-item-003",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "测试核销(已关联)"
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
**预期结果:**
|
|
||||||
1. 核销成功
|
|
||||||
2. 日志中显示:`订单关联关系不匹配,数据库orderNo: TEST_ORDER_001, 前端orderNo: TEST_ORDER_002`
|
|
||||||
3. 不会更新关联关系,继续使用原有的 `TEST_ORDER_001`
|
|
||||||
4. 订单中心订单状态正常更新
|
|
||||||
|
|
||||||
### 3. 日志验证
|
|
||||||
|
|
||||||
#### 3.1 成功核销日志
|
|
||||||
```
|
|
||||||
简化核销订单,订单号: ctriptest-test-001, 商品ID: test-item-001, 数量: 1, 关联订单号: TEST_ORDER_001
|
|
||||||
建立订单关联关系,otaOrderId: ctriptest-test-001, orderNo: TEST_ORDER_001
|
|
||||||
开始执行核销订单,otaOrderId: ctriptest-test-001, itemId: test-item-001, useQuantity: 1
|
|
||||||
订单状态更新为已使用,otaOrderId: ctriptest-test-001, totalUseQuantity: 1
|
|
||||||
开始更新订单中心订单状态,orderNo: TEST_ORDER_001
|
|
||||||
订单中心订单状态更新成功,orderNo: TEST_ORDER_001
|
|
||||||
核销成功,订单号: ctriptest-test-001, 关联订单号: TEST_ORDER_001
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 3.2 无关联订单日志
|
|
||||||
```
|
|
||||||
简化核销订单,订单号: ctriptest-test-002, 商品ID: test-item-002, 数量: 1, 关联订单号: null
|
|
||||||
开始执行核销订单,otaOrderId: ctriptest-test-002, itemId: test-item-002, useQuantity: 1
|
|
||||||
订单状态更新为已使用,otaOrderId: ctriptest-test-002, totalUseQuantity: 1
|
|
||||||
携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: ctriptest-test-002
|
|
||||||
核销成功,订单号: ctriptest-test-002, 关联订单号: null
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 异常场景测试
|
|
||||||
|
|
||||||
#### 4.1 订单不存在
|
|
||||||
**请求:**
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"otaOrderId": "non-existent-order",
|
|
||||||
"itemId": "test-item-001",
|
|
||||||
"useQuantity": 1
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
**预期结果:**
|
|
||||||
- 返回错误:`{"resp_code": -1, "resp_msg": "订单不存在"}`
|
|
||||||
|
|
||||||
#### 4.2 订单中心接口调用失败
|
|
||||||
**模拟场景:** 订单中心服务不可用
|
|
||||||
|
|
||||||
**预期结果:**
|
|
||||||
- 核销成功
|
|
||||||
- 日志显示:`订单中心订单状态更新失败,orderNo: TEST_ORDER_001, result: null`
|
|
||||||
- 不影响核销流程
|
|
||||||
|
|
||||||
#### 4.3 订单状态不正确
|
|
||||||
**模拟场景:** 订单中心订单状态不是待支付(状态0)
|
|
||||||
|
|
||||||
**预期结果:**
|
|
||||||
- 订单中心接口返回:`订单状态不正确,无法更新为已支付`
|
|
||||||
- 不影响核销流程
|
|
||||||
|
|
||||||
### 5. 性能测试
|
|
||||||
|
|
||||||
#### 5.1 并发核销测试
|
|
||||||
```bash
|
|
||||||
# 使用Apache Bench进行并发测试
|
|
||||||
ab -n 100 -c 10 -p test_data.json -T application/json \
|
|
||||||
http://localhost:8002/api-coupon/api/order-detail/consume-simple
|
|
||||||
```
|
|
||||||
|
|
||||||
**预期结果:**
|
|
||||||
- 所有请求成功处理
|
|
||||||
- 无数据竞争问题
|
|
||||||
- 订单状态正确更新
|
|
||||||
|
|
||||||
### 6. 数据一致性验证
|
|
||||||
|
|
||||||
#### 6.1 事务回滚测试
|
|
||||||
**模拟场景:** 在核销过程中发生异常
|
|
||||||
|
|
||||||
**预期结果:**
|
|
||||||
- 携程订单状态回滚
|
|
||||||
- 核销记录回滚
|
|
||||||
- 订单中心状态不更新
|
|
||||||
|
|
||||||
#### 6.2 幂等性测试
|
|
||||||
**操作:** 对同一订单多次核销
|
|
||||||
|
|
||||||
**预期结果:**
|
|
||||||
- 第一次核销成功
|
|
||||||
- 后续核销返回已核销状态
|
|
||||||
- 订单中心状态只更新一次
|
|
||||||
|
|
||||||
## 测试报告模板
|
|
||||||
|
|
||||||
### 测试结果汇总
|
|
||||||
|
|
||||||
| 测试场景 | 预期结果 | 实际结果 | 状态 |
|
|
||||||
|----------|----------|----------|------|
|
|
||||||
| 场景1:传入orderNo | 核销成功,状态更新 | | |
|
|
||||||
| 场景2:未传入orderNo | 核销成功,无状态更新 | | |
|
|
||||||
| 场景3:已关联订单 | 核销成功,使用原关联 | | |
|
|
||||||
| 异常场景1:订单不存在 | 返回错误 | | |
|
|
||||||
| 异常场景2:接口调用失败 | 核销成功,状态更新失败 | | |
|
|
||||||
| 异常场景3:状态不正确 | 核销成功,状态更新失败 | | |
|
|
||||||
| 性能测试:并发核销 | 100%成功率 | | |
|
|
||||||
| 数据一致性:事务回滚 | 数据回滚正确 | | |
|
|
||||||
| 数据一致性:幂等性 | 幂等性正确 | | |
|
|
||||||
|
|
||||||
### 问题记录
|
|
||||||
|
|
||||||
| 问题描述 | 严重程度 | 状态 | 备注 |
|
|
||||||
|----------|----------|------|------|
|
|
||||||
| | | | |
|
|
||||||
|
|
||||||
### 测试结论
|
|
||||||
|
|
||||||
- [ ] 所有测试场景通过
|
|
||||||
- [ ] 性能满足要求
|
|
||||||
- [ ] 数据一致性正确
|
|
||||||
- [ ] 异常处理完善
|
|
||||||
- [ ] 日志记录完整
|
|
||||||
|
|
||||||
## 部署验证清单
|
|
||||||
|
|
||||||
- [ ] 数据库表结构已更新(添加 `order_no` 字段)
|
|
||||||
- [ ] 优惠券中心服务已部署
|
|
||||||
- [ ] 订单中心服务已部署
|
|
||||||
- [ ] Feign客户端配置正确
|
|
||||||
- [ ] 日志级别配置正确
|
|
||||||
- [ ] 监控告警配置正确
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
# 核销流程验证
|
|
||||||
|
|
||||||
## 验证目标
|
|
||||||
|
|
||||||
确认前端调用的 `consumeOrderSimple` 接口能够正确触发订单中心状态更新。
|
|
||||||
|
|
||||||
## 调用链验证
|
|
||||||
|
|
||||||
### 1. 前端接口调用
|
|
||||||
```java
|
|
||||||
// OrderDetailController.consumeOrderSimple()
|
|
||||||
@PostMapping("/consume-simple")
|
|
||||||
public Result<Boolean> consumeOrderSimple(@Valid @RequestBody SimpleConsumeDTO consumeDTO)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 建立订单关联
|
|
||||||
```java
|
|
||||||
// 如果前端传入了orderNo,建立关联关系
|
|
||||||
if (consumeDTO.getOrderNo() != null && !consumeDTO.getOrderNo().trim().isEmpty()) {
|
|
||||||
if (order.getOrderNo() == null || order.getOrderNo().trim().isEmpty()) {
|
|
||||||
order.setOrderNo(consumeDTO.getOrderNo());
|
|
||||||
ctripOrderMapper.updateById(order);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 调用核销服务
|
|
||||||
```java
|
|
||||||
// 调用携程核销服务
|
|
||||||
CtripConsumedNoticeResponse response = ctripConsumedService.consumeOrder(request);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 核销服务执行
|
|
||||||
```java
|
|
||||||
// CtripConsumedServiceImpl.consumeOrder()
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public CtripConsumedNoticeResponse consumeOrder(CtripConsumeRequest request) {
|
|
||||||
// ... 验证和保存逻辑 ...
|
|
||||||
|
|
||||||
// 5. 更新订单状态 ← 这里会触发订单中心更新
|
|
||||||
updateOrderStatus(order, request.getUseQuantity());
|
|
||||||
|
|
||||||
// ... 其他逻辑 ...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. 订单状态更新
|
|
||||||
```java
|
|
||||||
// CtripConsumedServiceImpl.updateOrderStatus()
|
|
||||||
private void updateOrderStatus(CtripOrder order, Integer useQuantity) {
|
|
||||||
// ... 更新携程订单状态 ...
|
|
||||||
|
|
||||||
// 6. 更新订单中心订单状态 ← 这里调用订单中心接口
|
|
||||||
updateOrderCenterStatus(order);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6. 订单中心状态更新
|
|
||||||
```java
|
|
||||||
// CtripConsumedServiceImpl.updateOrderCenterStatus()
|
|
||||||
private void updateOrderCenterStatus(CtripOrder order) {
|
|
||||||
if (StringUtils.hasText(order.getOrderNo())) {
|
|
||||||
// 调用订单中心接口更新订单状态为已支付(状态1)
|
|
||||||
Result<String> result = orderCenterService.updateOrderStatusToPaid(order.getOrderNo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 关键日志点
|
|
||||||
|
|
||||||
### 成功流程日志
|
|
||||||
```
|
|
||||||
简化核销订单,订单号: xxx, 商品ID: xxx, 数量: 1, 关联订单号: ORDER_001
|
|
||||||
建立订单关联关系,otaOrderId: xxx, orderNo: ORDER_001
|
|
||||||
开始执行核销订单,otaOrderId: xxx, itemId: xxx, useQuantity: 1
|
|
||||||
订单状态更新为已使用,otaOrderId: xxx, totalUseQuantity: 1
|
|
||||||
开始更新订单中心订单状态,orderNo: ORDER_001
|
|
||||||
订单中心订单状态更新成功,orderNo: ORDER_001
|
|
||||||
核销成功,订单号: xxx, 关联订单号: ORDER_001
|
|
||||||
```
|
|
||||||
|
|
||||||
### 无关联订单日志
|
|
||||||
```
|
|
||||||
简化核销订单,订单号: xxx, 商品ID: xxx, 数量: 1, 关联订单号: null
|
|
||||||
开始执行核销订单,otaOrderId: xxx, itemId: xxx, useQuantity: 1
|
|
||||||
订单状态更新为已使用,otaOrderId: xxx, totalUseQuantity: 1
|
|
||||||
携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: xxx
|
|
||||||
核销成功,订单号: xxx, 关联订单号: null
|
|
||||||
```
|
|
||||||
|
|
||||||
## 验证方法
|
|
||||||
|
|
||||||
### 1. 数据库验证
|
|
||||||
```sql
|
|
||||||
-- 验证携程订单关联关系
|
|
||||||
SELECT ota_order_id, order_no, status FROM t_ctrip_order WHERE ota_order_id = 'your-ota-order-id';
|
|
||||||
|
|
||||||
-- 验证订单中心订单状态
|
|
||||||
SELECT order_no, order_status, pay_type, pay_time FROM orders WHERE order_no = 'your-order-no';
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 日志验证
|
|
||||||
检查应用日志中是否包含上述关键日志点。
|
|
||||||
|
|
||||||
### 3. 接口验证
|
|
||||||
```bash
|
|
||||||
# 测试核销接口
|
|
||||||
curl -X POST http://localhost:8002/api-coupon/api/order-detail/consume-simple \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"otaOrderId": "your-ota-order-id",
|
|
||||||
"orderNo": "your-order-no",
|
|
||||||
"itemId": "your-item-id",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "测试核销"
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
## 结论
|
|
||||||
|
|
||||||
✅ **调用链完整**:`consumeOrderSimple` → `consumeOrder` → `updateOrderStatus` → `updateOrderCenterStatus`
|
|
||||||
|
|
||||||
✅ **逻辑正确**:前端传入的 `orderNo` 会被正确处理,核销成功后会自动更新订单中心状态
|
|
||||||
|
|
||||||
✅ **异常处理**:即使订单中心接口调用失败,也不会影响核销流程
|
|
||||||
|
|
||||||
✅ **日志完整**:所有关键步骤都有详细的日志记录
|
|
||||||
@@ -1,251 +0,0 @@
|
|||||||
# 订单明细查询核销接口说明
|
|
||||||
|
|
||||||
## 概述
|
|
||||||
|
|
||||||
本接口提供通过手机号和优惠券价格查询可核销的携程订单明细的功能,支持用户选择订单进行核销操作。
|
|
||||||
|
|
||||||
## 接口列表
|
|
||||||
|
|
||||||
### 1. 查询可核销订单明细
|
|
||||||
|
|
||||||
**接口地址:** `POST /api/order-detail/query`
|
|
||||||
|
|
||||||
**请求参数:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"userPhone": "13800138000", // 用户手机号(必填)
|
|
||||||
"couponPrice": 100.00, // 优惠券价格(可选,用于筛选匹配的订单)
|
|
||||||
"onlyConsumable": true, // 是否只查询可核销的订单(默认true)
|
|
||||||
"page": 1, // 页码(默认1)
|
|
||||||
"size": 10 // 页大小(默认10)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**响应结果:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "",
|
|
||||||
"data": {
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"orderId": 123,
|
|
||||||
"otaOrderId": "ctriptest-10816828-454259-145573",
|
|
||||||
"supplierOrderId": "SUPPLIER_ctriptest-10816828-454259-145573_301495ef",
|
|
||||||
"orderStatus": 1,
|
|
||||||
"orderStatusDesc": "已确认",
|
|
||||||
"totalAmount": 100.00,
|
|
||||||
"currency": "CNY",
|
|
||||||
"createTime": "2025-08-30T09:33:42",
|
|
||||||
"orderItems": [
|
|
||||||
{
|
|
||||||
"itemId": 456,
|
|
||||||
"productId": "1801589811",
|
|
||||||
"itemName": "门票",
|
|
||||||
"itemType": "1",
|
|
||||||
"plu": "1",
|
|
||||||
"quantity": 2,
|
|
||||||
"unitPrice": 50.00,
|
|
||||||
"totalPrice": 100.00,
|
|
||||||
"currency": "CNY",
|
|
||||||
"useStartDate": "2025-07-25",
|
|
||||||
"useEndDate": "2025-07-25",
|
|
||||||
"canConsume": true,
|
|
||||||
"usedQuantity": 0,
|
|
||||||
"availableQuantity": 2
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"passengers": [
|
|
||||||
{
|
|
||||||
"passengerId": "PASS_1",
|
|
||||||
"passengerName": "张三",
|
|
||||||
"phone": "13800138000",
|
|
||||||
"passengerStatus": 0,
|
|
||||||
"passengerStatusDesc": "未使用",
|
|
||||||
"idCard": "110101199001011234",
|
|
||||||
"gender": "ADULT",
|
|
||||||
"age": null
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"contact": {
|
|
||||||
"name": "张三",
|
|
||||||
"mobile": "13800138000",
|
|
||||||
"email": "zhangsan@example.com",
|
|
||||||
"contactType": "BOOKER"
|
|
||||||
},
|
|
||||||
"canConsume": true,
|
|
||||||
"consumeReason": null
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"count": 1,
|
|
||||||
"resp_code": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 查询单个订单明细
|
|
||||||
|
|
||||||
**接口地址:** `GET /api/order-detail/{otaOrderId}`
|
|
||||||
|
|
||||||
**路径参数:**
|
|
||||||
- `otaOrderId`: 携程订单号
|
|
||||||
|
|
||||||
**响应结果:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "",
|
|
||||||
"data": {
|
|
||||||
// 同上面的订单明细结构
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 核销订单
|
|
||||||
|
|
||||||
**接口地址:** `POST /api/order-detail/consume`
|
|
||||||
|
|
||||||
**请求参数:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"otaOrderId": "ctriptest-10816828-454259-145573",
|
|
||||||
"supplierOrderId": "SUPPLIER_ctriptest-10816828-454259-145573_301495ef",
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"itemId": "1801589811",
|
|
||||||
"plu": "1",
|
|
||||||
"quantity": 1,
|
|
||||||
"passengerIds": ["PASS_1"],
|
|
||||||
"voucherIds": ["VOUCHER_1"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"remark": "门票入园核销"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**响应结果:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "核销成功",
|
|
||||||
"data": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 简化核销订单(单商品)
|
|
||||||
|
|
||||||
**接口地址:** `POST /api/order-detail/consume-simple`
|
|
||||||
|
|
||||||
**请求参数:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"otaOrderId": "ctriptest-10816870-454259-145573",
|
|
||||||
"itemId": "106943568",
|
|
||||||
"useQuantity": 1,
|
|
||||||
"remark": "门票入园核销"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**响应结果:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "核销成功",
|
|
||||||
"data": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. 验证订单是否可核销
|
|
||||||
|
|
||||||
**接口地址:** `GET /api/order-detail/{otaOrderId}/validate`
|
|
||||||
|
|
||||||
**路径参数:**
|
|
||||||
- `otaOrderId`: 携程订单号
|
|
||||||
|
|
||||||
**响应结果:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"resp_code": 0,
|
|
||||||
"resp_msg": "",
|
|
||||||
"data": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 业务逻辑说明
|
|
||||||
|
|
||||||
### 订单查询逻辑
|
|
||||||
|
|
||||||
1. **根据手机号查询订单**:
|
|
||||||
- 通过乘客信息表(t_ctrip_passenger)查询手机号匹配的订单
|
|
||||||
- 通过联系人信息表(t_ctrip_contact)查询手机号匹配的订单
|
|
||||||
- 合并去重后返回订单列表
|
|
||||||
|
|
||||||
2. **订单筛选**:
|
|
||||||
- 支持按优惠券价格筛选(订单总金额必须与优惠券价格匹配)
|
|
||||||
- 默认只返回可核销的订单(onlyConsumable=true)
|
|
||||||
- 支持分页查询
|
|
||||||
|
|
||||||
3. **可核销订单条件**:
|
|
||||||
- 订单状态为"已确认"(1)
|
|
||||||
- 订单项在使用有效期内
|
|
||||||
- 订单项有剩余可用数量
|
|
||||||
- 订单总金额与优惠券价格匹配
|
|
||||||
|
|
||||||
4. **订单状态说明**:
|
|
||||||
- 0: 待确认
|
|
||||||
- 1: 已确认
|
|
||||||
- 2: 已取消
|
|
||||||
- 3: 已退款
|
|
||||||
- 4: 已核销
|
|
||||||
- 5: 已取消
|
|
||||||
- 11: 待支付
|
|
||||||
- 12: 支付中
|
|
||||||
- 13: 支付确认
|
|
||||||
- 14: 预订单已取消
|
|
||||||
|
|
||||||
### 核销验证逻辑
|
|
||||||
|
|
||||||
1. **订单状态验证**:
|
|
||||||
- 只有状态为"已确认"(1)的订单才能核销
|
|
||||||
|
|
||||||
2. **订单项验证**:
|
|
||||||
- 检查使用日期是否在有效期内
|
|
||||||
- 检查剩余可用数量是否足够
|
|
||||||
|
|
||||||
3. **核销流程**:
|
|
||||||
- 验证订单和订单项的可核销性
|
|
||||||
- 调用携程核销接口
|
|
||||||
- 更新本地核销记录
|
|
||||||
|
|
||||||
### 使用场景
|
|
||||||
|
|
||||||
1. **用户查询可核销订单**:
|
|
||||||
- 用户输入手机号和优惠券价格
|
|
||||||
- 系统返回匹配的可核销订单列表
|
|
||||||
- 用户查看订单详细信息和核销状态
|
|
||||||
|
|
||||||
2. **选择核销订单**:
|
|
||||||
- 用户从查询结果中选择要核销的订单
|
|
||||||
- 系统显示订单的可核销状态和原因
|
|
||||||
|
|
||||||
3. **执行核销操作**:
|
|
||||||
- 用户选择要核销的商品和数量
|
|
||||||
- 系统验证核销条件
|
|
||||||
- 调用携程接口完成核销
|
|
||||||
|
|
||||||
## 错误码说明
|
|
||||||
|
|
||||||
- `0000`: 成功
|
|
||||||
- `0001`: 参数错误
|
|
||||||
- `0002`: 订单不存在
|
|
||||||
- `0003`: 订单状态不正确
|
|
||||||
- `0004`: 订单项不可核销
|
|
||||||
- `0005`: 核销失败
|
|
||||||
|
|
||||||
## 注意事项
|
|
||||||
|
|
||||||
1. **手机号查询**:系统会同时查询乘客信息和联系人信息,确保能找到用户的所有订单
|
|
||||||
2. **核销限制**:只有已确认的订单才能进行核销操作
|
|
||||||
3. **数量控制**:核销数量不能超过订单项的剩余可用数量
|
|
||||||
4. **日期验证**:核销日期必须在商品的使用有效期内
|
|
||||||
5. **幂等性**:重复核销同一订单项会返回成功,但不会重复扣减数量
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,167 +0,0 @@
|
|||||||
<?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>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.trip</groupId>
|
|
||||||
<artifactId>tourop</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
</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>
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
-- 为 t_ctrip_order 表添加 order_no 字段,用于关联订单中心的订单号
|
|
||||||
-- 这样核销成功后可以通过这个关联关系更新订单状态
|
|
||||||
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `order_no` varchar(50) DEFAULT NULL COMMENT '关联的订单中心订单号' AFTER `ota_order_id`;
|
|
||||||
|
|
||||||
-- 添加索引以提高查询性能
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD INDEX `idx_order_no` (`order_no`);
|
|
||||||
|
|
||||||
-- 添加唯一索引确保一个订单号只能关联一个携程订单
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD UNIQUE INDEX `uk_order_no` (`order_no`);
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
-- 修复 t_ctrip_order 表字段不匹配问题
|
|
||||||
-- 添加缺失的字段,修改字段名称以匹配实体类
|
|
||||||
|
|
||||||
-- 1. 添加 supplier_order_id 字段
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `supplier_order_id` varchar(100) DEFAULT NULL COMMENT '供应商订单号' AFTER `ota_order_id`;
|
|
||||||
|
|
||||||
-- 2. 添加 confirm_type 字段
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `confirm_type` int(11) DEFAULT NULL COMMENT '确认类型:1-仅通知,2-需确认' AFTER `sequence_id`;
|
|
||||||
|
|
||||||
-- 3. 添加 status 字段(重命名 order_status)
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `status` int(11) DEFAULT 0 COMMENT '订单状态:0-待确认,1-已确认,2-已取消' AFTER `confirm_type`;
|
|
||||||
|
|
||||||
-- 4. 修改 total_amount_currency 为 currency
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型' AFTER `total_amount`;
|
|
||||||
|
|
||||||
-- 5. 为新字段添加索引
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD INDEX `idx_supplier_order_id` (`supplier_order_id`);
|
|
||||||
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD INDEX `idx_status` (`status`);
|
|
||||||
|
|
||||||
-- 6. 可选:删除旧的字段(先确认数据迁移完成后再执行)
|
|
||||||
-- ALTER TABLE `t_ctrip_order` DROP COLUMN `order_status`;
|
|
||||||
-- ALTER TABLE `t_ctrip_order` DROP COLUMN `total_amount_currency`;
|
|
||||||
-- ALTER TABLE `t_ctrip_order` DROP COLUMN `contact_name`;
|
|
||||||
-- ALTER TABLE `t_ctrip_order` DROP COLUMN `contact_phone`;
|
|
||||||
-- ALTER TABLE `t_ctrip_order` DROP COLUMN `contact_email`;
|
|
||||||
-- ALTER TABLE `t_ctrip_order` DROP COLUMN `contact_type`;
|
|
||||||
-- ALTER TABLE `t_ctrip_order` DROP COLUMN `order_create_time`;
|
|
||||||
|
|
||||||
-- 执行完毕后,表结构将与实体类匹配
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
@@ -1,278 +0,0 @@
|
|||||||
-- 创建数据库
|
|
||||||
CREATE DATABASE IF NOT EXISTS `coupon-center` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
||||||
|
|
||||||
USE `coupon-center`;
|
|
||||||
|
|
||||||
-- 优惠券表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_coupon` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`coupon_name` varchar(100) NOT NULL COMMENT '优惠券名称',
|
|
||||||
`coupon_type` varchar(20) NOT NULL COMMENT '优惠券类型',
|
|
||||||
`amount` decimal(10,2) NOT NULL COMMENT '优惠券金额',
|
|
||||||
`amount_currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
|
||||||
`user_phone` varchar(20) NOT NULL COMMENT '用户手机号',
|
|
||||||
`ctrip_coupon_id` varchar(100) DEFAULT NULL COMMENT '携程优惠券ID',
|
|
||||||
`ctrip_order_id` varchar(100) DEFAULT NULL COMMENT '携程订单ID',
|
|
||||||
`status` varchar(20) DEFAULT 'UNUSED' COMMENT '状态:UNUSED-未使用,USED-已使用,EXPIRED-已过期,VOIDED-已作废',
|
|
||||||
`valid_start_time` datetime NOT NULL COMMENT '有效期开始时间',
|
|
||||||
`valid_end_time` datetime NOT NULL COMMENT '有效期结束时间',
|
|
||||||
`used_time` datetime DEFAULT NULL COMMENT '使用时间',
|
|
||||||
`used_order_no` varchar(100) DEFAULT NULL COMMENT '使用订单号',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_user_phone` (`user_phone`),
|
|
||||||
KEY `idx_ctrip_coupon_id` (`ctrip_coupon_id`),
|
|
||||||
KEY `idx_status` (`status`),
|
|
||||||
KEY `idx_valid_end_time` (`valid_end_time`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='优惠券表';
|
|
||||||
|
|
||||||
-- 携程订单表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_order` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`ota_order_id` varchar(100) NOT NULL COMMENT 'OTA订单ID',
|
|
||||||
`sequence_id` varchar(100) NOT NULL COMMENT '序列号ID',
|
|
||||||
`order_status` varchar(20) DEFAULT 'PENDING' COMMENT '订单状态',
|
|
||||||
`total_amount` decimal(10,2) DEFAULT NULL COMMENT '订单总金额',
|
|
||||||
`total_amount_currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
|
||||||
`contact_name` varchar(50) DEFAULT NULL COMMENT '联系人姓名',
|
|
||||||
`contact_phone` varchar(20) DEFAULT NULL COMMENT '联系人电话',
|
|
||||||
`contact_email` varchar(100) DEFAULT NULL COMMENT '联系人邮箱',
|
|
||||||
`contact_type` varchar(20) DEFAULT NULL COMMENT '联系人类型',
|
|
||||||
`order_create_time` datetime DEFAULT NULL COMMENT '订单创建时间',
|
|
||||||
`order_last_confirm_time` datetime DEFAULT NULL COMMENT '订单最后确认时间',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_sequence_id` (`sequence_id`),
|
|
||||||
KEY `idx_ota_order_id` (`ota_order_id`),
|
|
||||||
KEY `idx_order_status` (`order_status`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程订单表';
|
|
||||||
|
|
||||||
-- 携程订单项目表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_order_item` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`order_id` bigint(20) NOT NULL COMMENT '订单ID',
|
|
||||||
`item_id` varchar(100) NOT NULL COMMENT '项目ID',
|
|
||||||
`item_name` varchar(200) DEFAULT NULL COMMENT '项目名称',
|
|
||||||
`item_type` varchar(50) DEFAULT NULL COMMENT '项目类型',
|
|
||||||
`quantity` int(11) DEFAULT 1 COMMENT '数量',
|
|
||||||
`unit_price` decimal(10,2) DEFAULT NULL COMMENT '单价',
|
|
||||||
`total_price` decimal(10,2) DEFAULT NULL COMMENT '总价',
|
|
||||||
`total_price_currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_order_item` (`order_id`, `item_id`),
|
|
||||||
KEY `idx_order_id` (`order_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程订单项目表';
|
|
||||||
|
|
||||||
-- 携程乘客表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_passenger` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`order_id` bigint(20) NOT NULL COMMENT '订单ID',
|
|
||||||
`item_id` varchar(100) NOT NULL COMMENT '项目ID',
|
|
||||||
`passenger_id` varchar(100) NOT NULL COMMENT '乘客ID',
|
|
||||||
`passenger_name` varchar(50) NOT NULL COMMENT '乘客姓名',
|
|
||||||
`passenger_type` varchar(20) DEFAULT NULL COMMENT '乘客类型',
|
|
||||||
`id_type` varchar(20) DEFAULT NULL COMMENT '证件类型',
|
|
||||||
`id_number` varchar(50) DEFAULT NULL COMMENT '证件号码',
|
|
||||||
`phone` varchar(20) DEFAULT NULL COMMENT '手机号',
|
|
||||||
`gender` varchar(10) DEFAULT NULL COMMENT '性别',
|
|
||||||
`birth_date` date DEFAULT NULL COMMENT '出生日期',
|
|
||||||
`age_type` varchar(20) DEFAULT NULL COMMENT '年龄类型',
|
|
||||||
`nationality_code` varchar(10) DEFAULT NULL COMMENT '国籍代码',
|
|
||||||
`nationality_name` varchar(50) DEFAULT NULL COMMENT '国籍名称',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_order_id` (`order_id`),
|
|
||||||
KEY `idx_item_id` (`item_id`),
|
|
||||||
KEY `idx_passenger_id` (`passenger_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程乘客表';
|
|
||||||
|
|
||||||
-- 携程联系人表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_contact` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`order_id` bigint(20) NOT NULL COMMENT '订单ID',
|
|
||||||
`name` varchar(50) NOT NULL COMMENT '联系人姓名',
|
|
||||||
`mobile` varchar(20) NOT NULL COMMENT '手机号',
|
|
||||||
`email` varchar(100) DEFAULT NULL COMMENT '邮箱',
|
|
||||||
`intl_code` varchar(10) DEFAULT '+86' COMMENT '国际区号',
|
|
||||||
`optional_mobile` varchar(20) DEFAULT NULL COMMENT '备用手机号',
|
|
||||||
`optional_intl_code` varchar(10) DEFAULT NULL COMMENT '备用国际区号',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_order_id` (`order_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程联系人表';
|
|
||||||
|
|
||||||
-- 携程优惠券表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_coupon` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`order_id` bigint(20) NOT NULL COMMENT '订单ID',
|
|
||||||
`coupon_id` varchar(100) NOT NULL COMMENT '优惠券ID',
|
|
||||||
`coupon_type` varchar(20) DEFAULT NULL COMMENT '优惠券类型',
|
|
||||||
`amount` decimal(10,2) DEFAULT NULL COMMENT '优惠券金额',
|
|
||||||
`amount_currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
|
||||||
`status` varchar(20) DEFAULT 'UNUSED' COMMENT '状态',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_order_id` (`order_id`),
|
|
||||||
KEY `idx_coupon_id` (`coupon_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程优惠券表';
|
|
||||||
|
|
||||||
-- 携程凭证表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_voucher` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`order_id` bigint(20) NOT NULL COMMENT '订单ID',
|
|
||||||
`voucher_id` varchar(100) NOT NULL COMMENT '凭证ID',
|
|
||||||
`voucher_type` varchar(20) DEFAULT NULL COMMENT '凭证类型',
|
|
||||||
`voucher_code` varchar(100) DEFAULT NULL COMMENT '凭证码',
|
|
||||||
`status` varchar(20) DEFAULT 'UNUSED' COMMENT '状态',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_order_id` (`order_id`),
|
|
||||||
KEY `idx_voucher_id` (`voucher_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程凭证表';
|
|
||||||
|
|
||||||
-- 携程退款表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_refund` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`order_id` bigint(20) NOT NULL COMMENT '订单ID',
|
|
||||||
`refund_id` varchar(100) NOT NULL COMMENT '退款ID',
|
|
||||||
`refund_amount` decimal(10,2) DEFAULT NULL COMMENT '退款金额',
|
|
||||||
`refund_amount_currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
|
||||||
`refund_status` varchar(20) DEFAULT 'PENDING' COMMENT '退款状态',
|
|
||||||
`refund_reason` varchar(200) DEFAULT NULL COMMENT '退款原因',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_order_id` (`order_id`),
|
|
||||||
KEY `idx_refund_id` (`refund_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程退款表';
|
|
||||||
|
|
||||||
-- 携程退款项目表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_refund_item` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`refund_id` bigint(20) NOT NULL COMMENT '退款ID',
|
|
||||||
`item_id` varchar(100) NOT NULL COMMENT '项目ID',
|
|
||||||
`item_name` varchar(200) DEFAULT NULL COMMENT '项目名称',
|
|
||||||
`quantity` int(11) DEFAULT 1 COMMENT '数量',
|
|
||||||
`refund_amount` decimal(10,2) DEFAULT NULL COMMENT '退款金额',
|
|
||||||
`refund_amount_currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_refund_id` (`refund_id`),
|
|
||||||
KEY `idx_item_id` (`item_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程退款项目表';
|
|
||||||
|
|
||||||
-- 携程核销表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_consumed` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`order_id` bigint(20) NOT NULL COMMENT '订单ID',
|
|
||||||
`consumed_id` varchar(100) NOT NULL COMMENT '核销ID',
|
|
||||||
`total_quantity` int(11) DEFAULT 0 COMMENT '总数量',
|
|
||||||
`consumed_status` varchar(20) DEFAULT 'PENDING' COMMENT '核销状态',
|
|
||||||
`consumed_time` datetime DEFAULT NULL COMMENT '核销时间',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_order_id` (`order_id`),
|
|
||||||
KEY `idx_consumed_id` (`consumed_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程核销表';
|
|
||||||
|
|
||||||
-- 携程核销乘客表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_consumed_passenger` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`consumed_id` bigint(20) NOT NULL COMMENT '核销ID',
|
|
||||||
`passenger_id` varchar(100) NOT NULL COMMENT '乘客ID',
|
|
||||||
`passenger_name` varchar(50) NOT NULL COMMENT '乘客姓名',
|
|
||||||
`quantity` int(11) DEFAULT 1 COMMENT '数量',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_consumed_id` (`consumed_id`),
|
|
||||||
KEY `idx_passenger_id` (`passenger_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程核销乘客表';
|
|
||||||
|
|
||||||
-- 携程核销凭证表
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_consumed_voucher` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
`consumed_id` bigint(20) NOT NULL COMMENT '核销ID',
|
|
||||||
`voucher_id` varchar(100) NOT NULL COMMENT '凭证ID',
|
|
||||||
`voucher_code` varchar(100) DEFAULT NULL COMMENT '凭证码',
|
|
||||||
`quantity` int(11) DEFAULT 1 COMMENT '数量',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_consumed_id` (`consumed_id`),
|
|
||||||
KEY `idx_voucher_id` (`voucher_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程核销凭证表';
|
|
||||||
|
|
||||||
-- 插入测试数据
|
|
||||||
INSERT INTO `t_coupon` (`coupon_name`, `coupon_type`, `amount`, `user_phone`, `status`, `valid_start_time`, `valid_end_time`, `create_by`)
|
|
||||||
VALUES ('测试优惠券', 'DISCOUNT', 10.00, '18322694510', 'UNUSED', NOW(), DATE_ADD(NOW(), INTERVAL 30 DAY), 'system');
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
-- 删除旧的优惠券相关表
|
|
||||||
-- 这些表已被 t_user_coupon 表替代
|
|
||||||
|
|
||||||
-- 删除 t_coupon 表
|
|
||||||
DROP TABLE IF EXISTS `t_coupon`;
|
|
||||||
|
|
||||||
-- 删除 t_ctrip_coupon 表
|
|
||||||
DROP TABLE IF EXISTS `t_ctrip_coupon`;
|
|
||||||
|
|
||||||
-- 删除相关的索引(如果存在)
|
|
||||||
-- 注意:DROP TABLE 会自动删除相关的索引,所以这里不需要单独删除
|
|
||||||
|
|
||||||
-- 验证表是否已删除
|
|
||||||
SELECT
|
|
||||||
TABLE_NAME
|
|
||||||
FROM
|
|
||||||
INFORMATION_SCHEMA.TABLES
|
|
||||||
WHERE
|
|
||||||
TABLE_SCHEMA = DATABASE()
|
|
||||||
AND TABLE_NAME IN ('t_coupon', 't_ctrip_coupon');
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
-- 修复 t_ctrip_order 和 t_ctrip_order_item 表缺少的字段
|
|
||||||
-- 执行前请备份数据库
|
|
||||||
|
|
||||||
USE `coupon-center`;
|
|
||||||
|
|
||||||
-- ========================================
|
|
||||||
-- 修复 t_ctrip_order 表
|
|
||||||
-- ========================================
|
|
||||||
|
|
||||||
-- 1. 添加 supplier_order_id 字段
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `supplier_order_id` varchar(100) DEFAULT NULL COMMENT '供应商订单ID'
|
|
||||||
AFTER `ota_order_id`;
|
|
||||||
|
|
||||||
-- 2. 添加 confirm_type 字段
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `confirm_type` int(11) DEFAULT NULL COMMENT '确认类型'
|
|
||||||
AFTER `sequence_id`;
|
|
||||||
|
|
||||||
-- 3. 添加 status 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `status` int(11) DEFAULT 0 COMMENT '订单状态:0-待确认,1-已确认,2-已取消'
|
|
||||||
AFTER `confirm_type`;
|
|
||||||
|
|
||||||
-- 4. 添加 currency 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD COLUMN `currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型'
|
|
||||||
AFTER `total_amount`;
|
|
||||||
|
|
||||||
-- 5. 添加索引
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
ADD INDEX `idx_supplier_order_id` (`supplier_order_id`);
|
|
||||||
|
|
||||||
-- ========================================
|
|
||||||
-- 修复 t_ctrip_order_item 表
|
|
||||||
-- ========================================
|
|
||||||
|
|
||||||
-- 1. 添加 currency 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型'
|
|
||||||
AFTER `total_price`;
|
|
||||||
|
|
||||||
-- 2. 添加 use_start_date 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `use_start_date` date DEFAULT NULL COMMENT '使用开始日期'
|
|
||||||
AFTER `currency`;
|
|
||||||
|
|
||||||
-- 3. 添加 use_end_date 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `use_end_date` date DEFAULT NULL COMMENT '使用结束日期'
|
|
||||||
AFTER `use_start_date`;
|
|
||||||
|
|
||||||
-- 4. 添加 plu 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `plu` varchar(100) DEFAULT NULL COMMENT 'PLU编码'
|
|
||||||
AFTER `item_type`;
|
|
||||||
|
|
||||||
-- 5. 添加 price 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `price` decimal(10,2) DEFAULT NULL COMMENT '原价'
|
|
||||||
AFTER `plu`;
|
|
||||||
|
|
||||||
-- 6. 添加 sale_price 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `sale_price` decimal(10,2) DEFAULT NULL COMMENT '销售价'
|
|
||||||
AFTER `price`;
|
|
||||||
|
|
||||||
-- 7. 添加 create_by 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `create_by` varchar(50) DEFAULT NULL COMMENT '创建人'
|
|
||||||
AFTER `update_time`;
|
|
||||||
|
|
||||||
-- 8. 添加 update_by 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `update_by` varchar(50) DEFAULT NULL COMMENT '更新人'
|
|
||||||
AFTER `create_by`;
|
|
||||||
|
|
||||||
-- 9. 添加 remark 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `remark` varchar(500) DEFAULT NULL COMMENT '备注'
|
|
||||||
AFTER `update_by`;
|
|
||||||
|
|
||||||
-- 10. 添加 tenant_id 字段(如果不存在)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID'
|
|
||||||
AFTER `remark`;
|
|
||||||
|
|
||||||
-- 11. 添加 voucher_id 字段(用于PayPreOrderConfirm)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `voucher_id` varchar(100) DEFAULT NULL COMMENT '凭证ID(用于PayPreOrderConfirm)'
|
|
||||||
AFTER `use_end_date`;
|
|
||||||
|
|
||||||
-- 12. 添加 passenger_id 字段(用于PayPreOrderConfirm)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `passenger_id` varchar(100) DEFAULT NULL COMMENT '乘客ID(用于PayPreOrderConfirm)'
|
|
||||||
AFTER `voucher_id`;
|
|
||||||
|
|
||||||
-- 13. 添加 passenger_voucher_id 字段(用于PayPreOrderConfirm,与voucher_id不同)
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD COLUMN `passenger_voucher_id` varchar(100) DEFAULT NULL COMMENT '乘客凭证ID(用于PayPreOrderConfirm,与voucher_id不同)'
|
|
||||||
AFTER `passenger_id`;
|
|
||||||
|
|
||||||
-- 14. 添加索引
|
|
||||||
ALTER TABLE `t_ctrip_order_item`
|
|
||||||
ADD INDEX `idx_currency` (`currency`);
|
|
||||||
|
|
||||||
-- ========================================
|
|
||||||
-- 验证表结构
|
|
||||||
-- ========================================
|
|
||||||
|
|
||||||
-- 验证 t_ctrip_order 表结构
|
|
||||||
DESCRIBE `t_ctrip_order`;
|
|
||||||
|
|
||||||
-- 验证 t_ctrip_order_item 表结构
|
|
||||||
DESCRIBE `t_ctrip_order_item`;
|
|
||||||
|
|
||||||
-- 显示修复后的完整表结构
|
|
||||||
SHOW CREATE TABLE `t_ctrip_order`;
|
|
||||||
SHOW CREATE TABLE `t_ctrip_order_item`;
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
-- 紧急修复 t_ctrip_order 表字段不匹配问题
|
|
||||||
-- 只添加立即需要的关键字段
|
|
||||||
|
|
||||||
-- 检查字段是否存在,如果不存在则添加
|
|
||||||
-- 1. 添加 supplier_order_id 字段
|
|
||||||
SET @sql = CONCAT('ALTER TABLE t_ctrip_order ADD COLUMN supplier_order_id varchar(100) DEFAULT NULL COMMENT ''供应商订单号'' AFTER ota_order_id');
|
|
||||||
SET @exist = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_ctrip_order' AND COLUMN_NAME = 'supplier_order_id');
|
|
||||||
SET @sql = IF(@exist = 0, @sql, 'SELECT ''supplier_order_id already exists'' AS info');
|
|
||||||
PREPARE stmt FROM @sql;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
-- 2. 添加 confirm_type 字段
|
|
||||||
SET @sql = CONCAT('ALTER TABLE t_ctrip_order ADD COLUMN confirm_type int(11) DEFAULT NULL COMMENT ''确认类型:1-仅通知,2-需确认'' AFTER sequence_id');
|
|
||||||
SET @exist = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_ctrip_order' AND COLUMN_NAME = 'confirm_type');
|
|
||||||
SET @sql = IF(@exist = 0, @sql, 'SELECT ''confirm_type already exists'' AS info');
|
|
||||||
PREPARE stmt FROM @sql;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
-- 3. 添加 status 字段
|
|
||||||
SET @sql = CONCAT('ALTER TABLE t_ctrip_order ADD COLUMN status int(11) DEFAULT 0 COMMENT ''订单状态:0-待确认,1-已确认,2-已取消'' AFTER confirm_type');
|
|
||||||
SET @exist = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_ctrip_order' AND COLUMN_NAME = 'status');
|
|
||||||
SET @sql = IF(@exist = 0, @sql, 'SELECT ''status already exists'' AS info');
|
|
||||||
PREPARE stmt FROM @sql;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
-- 4. 添加 currency 字段
|
|
||||||
SET @sql = CONCAT('ALTER TABLE t_ctrip_order ADD COLUMN currency varchar(10) DEFAULT ''CNY'' COMMENT ''货币类型'' AFTER total_amount');
|
|
||||||
SET @exist = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_ctrip_order' AND COLUMN_NAME = 'currency');
|
|
||||||
SET @sql = IF(@exist = 0, @sql, 'SELECT ''currency already exists'' AS info');
|
|
||||||
PREPARE stmt FROM @sql;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
-- 5. 添加索引(如果不存在)
|
|
||||||
SET @sql = 'CREATE INDEX idx_supplier_order_id ON t_ctrip_order (supplier_order_id)';
|
|
||||||
SET @exist = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_ctrip_order' AND INDEX_NAME = 'idx_supplier_order_id');
|
|
||||||
SET @sql = IF(@exist = 0, @sql, 'SELECT ''idx_supplier_order_id already exists'' AS info');
|
|
||||||
PREPARE stmt FROM @sql;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @sql = 'CREATE INDEX idx_status ON t_ctrip_order (status)';
|
|
||||||
SET @exist = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_ctrip_order' AND INDEX_NAME = 'idx_status');
|
|
||||||
SET @sql = IF(@exist = 0, @sql, 'SELECT ''idx_status already exists'' AS info');
|
|
||||||
PREPARE stmt FROM @sql;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
-- 完成提示
|
|
||||||
SELECT 'Database schema update completed successfully!' AS result;
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
-- 携程退款功能表结构更新脚本
|
|
||||||
-- 执行前请备份数据
|
|
||||||
|
|
||||||
USE `coupon-center`;
|
|
||||||
|
|
||||||
-- 更新 t_ctrip_refund 表结构(如果表已存在则修改,否则创建)
|
|
||||||
DROP TABLE IF EXISTS `t_ctrip_refund_backup`;
|
|
||||||
|
|
||||||
-- 检查表是否存在,如果存在则备份
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_refund_backup` AS SELECT * FROM `t_ctrip_refund` WHERE 1=0;
|
|
||||||
INSERT INTO `t_ctrip_refund_backup` SELECT * FROM `t_ctrip_refund` WHERE 1=1;
|
|
||||||
|
|
||||||
-- 删除旧表并重建
|
|
||||||
DROP TABLE IF EXISTS `t_ctrip_refund`;
|
|
||||||
|
|
||||||
CREATE TABLE `t_ctrip_refund` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`ota_order_id` varchar(100) NOT NULL COMMENT '携程订单号',
|
|
||||||
`supplier_order_id` varchar(100) DEFAULT NULL COMMENT '供应商订单号',
|
|
||||||
`sequence_id` varchar(100) NOT NULL COMMENT '携程批次流水号',
|
|
||||||
`refund_amount` decimal(10,2) NOT NULL COMMENT '退款金额',
|
|
||||||
`currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
|
||||||
`refund_status` int(11) DEFAULT 0 COMMENT '退款状态:0-待确认,1-已确认,2-已拒绝',
|
|
||||||
`confirm_result_code` varchar(50) DEFAULT NULL COMMENT '确认结果码',
|
|
||||||
`confirm_result_message` varchar(500) DEFAULT NULL COMMENT '确认结果信息',
|
|
||||||
`last_confirm_time` datetime DEFAULT NULL COMMENT '最晚确认时间',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
|
||||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
|
||||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
||||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_sequence_id` (`sequence_id`),
|
|
||||||
KEY `idx_ota_order_id` (`ota_order_id`),
|
|
||||||
KEY `idx_supplier_order_id` (`supplier_order_id`),
|
|
||||||
KEY `idx_refund_status` (`refund_status`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程退款表';
|
|
||||||
|
|
||||||
-- 更新 t_ctrip_refund_item 表结构
|
|
||||||
DROP TABLE IF EXISTS `t_ctrip_refund_item_backup`;
|
|
||||||
|
|
||||||
-- 检查表是否存在,如果存在则备份
|
|
||||||
CREATE TABLE IF NOT EXISTS `t_ctrip_refund_item_backup` AS SELECT * FROM `t_ctrip_refund_item` WHERE 1=0;
|
|
||||||
INSERT INTO `t_ctrip_refund_item_backup` SELECT * FROM `t_ctrip_refund_item` WHERE 1=1;
|
|
||||||
|
|
||||||
-- 删除旧表并重建
|
|
||||||
DROP TABLE IF EXISTS `t_ctrip_refund_item`;
|
|
||||||
|
|
||||||
CREATE TABLE `t_ctrip_refund_item` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
||||||
`refund_id` bigint(20) NOT NULL COMMENT '退款ID',
|
|
||||||
`item_id` varchar(100) DEFAULT NULL COMMENT '订单项编号',
|
|
||||||
`plu` varchar(100) DEFAULT NULL COMMENT '供应商产品最小单位',
|
|
||||||
`refund_amount` decimal(10,2) DEFAULT NULL COMMENT '退款金额',
|
|
||||||
`currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
|
||||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除:0-未删除,1-已删除',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `idx_refund_id` (`refund_id`),
|
|
||||||
KEY `idx_item_id` (`item_id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程退款项表';
|
|
||||||
|
|
||||||
-- 确保 t_ctrip_order 表有 status 字段(整数类型)
|
|
||||||
-- 订单状态:0-待确认,1-已确认,2-已取消,3-已过期,4-退款中,5-已退款
|
|
||||||
ALTER TABLE `t_ctrip_order`
|
|
||||||
MODIFY COLUMN `status` int(11) DEFAULT 0 COMMENT '订单状态:0-待确认,1-已确认,2-已取消,3-已过期,4-退款中,5-已退款';
|
|
||||||
|
|
||||||
-- 如果 status 字段不存在,则添加
|
|
||||||
-- ALTER TABLE `t_ctrip_order` ADD COLUMN `status` int(11) DEFAULT 0 COMMENT '订单状态:0-待确认,1-已确认,2-已取消,3-已过期,4-退款中,5-已退款';
|
|
||||||
|
|
||||||
-- 清理备份表(可选,确认数据无误后执行)
|
|
||||||
-- DROP TABLE IF EXISTS `t_ctrip_refund_backup`;
|
|
||||||
-- DROP TABLE IF EXISTS `t_ctrip_refund_item_backup`;
|
|
||||||
-27
@@ -1,27 +0,0 @@
|
|||||||
package com.central.coupon;
|
|
||||||
|
|
||||||
import com.central.common.lb.annotation.EnableFeignInterceptor;
|
|
||||||
import com.central.search.annotation.EnableSearchClient;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券中心启动类
|
|
||||||
*
|
|
||||||
* @author system
|
|
||||||
* @date 2024-12-19
|
|
||||||
*/
|
|
||||||
@EnableDiscoveryClient
|
|
||||||
@EnableSearchClient
|
|
||||||
@EnableTransactionManagement
|
|
||||||
@EnableFeignInterceptor
|
|
||||||
@SpringBootApplication
|
|
||||||
public class CouponCenterApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(CouponCenterApplication.class, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
package com.central.coupon.config;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程API配置
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "ctrip")
|
|
||||||
public class CtripApiConfig {
|
|
||||||
/**
|
|
||||||
* AES加密配置
|
|
||||||
*/
|
|
||||||
private AesConfig aes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API配置
|
|
||||||
*/
|
|
||||||
private ApiConfig api;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 账户配置
|
|
||||||
*/
|
|
||||||
private AccountConfig account;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class AesConfig {
|
|
||||||
private String key;
|
|
||||||
private String iv;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class ApiConfig {
|
|
||||||
private String testUrl;
|
|
||||||
private String prodUrl;
|
|
||||||
private String environment;
|
|
||||||
private Integer timeout;
|
|
||||||
private Integer retryTimes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前环境的API基础URL
|
|
||||||
*/
|
|
||||||
public String getBaseUrl() {
|
|
||||||
return "prod".equals(environment) ? prodUrl : testUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取订单通知接口的完整URL
|
|
||||||
*/
|
|
||||||
public String getOrderNoticeUrl() {
|
|
||||||
return getBaseUrl() + "/order/notice.do";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class AccountConfig {
|
|
||||||
private String id;
|
|
||||||
private String secret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-108
@@ -1,108 +0,0 @@
|
|||||||
package com.central.coupon.config;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程分销商配置
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "ctrip.distributor")
|
|
||||||
public class CtripDistributorConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分销商AID
|
|
||||||
*/
|
|
||||||
private Long aid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分销商SID
|
|
||||||
*/
|
|
||||||
private Long sid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分销商密钥
|
|
||||||
*/
|
|
||||||
private String key;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 认证URL
|
|
||||||
*/
|
|
||||||
private String authUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新Token URL
|
|
||||||
*/
|
|
||||||
private String refreshUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务API URL
|
|
||||||
*/
|
|
||||||
private String apiUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 语言地区
|
|
||||||
*/
|
|
||||||
private String locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 货币代码
|
|
||||||
*/
|
|
||||||
private String currency;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 各接口icode配置
|
|
||||||
*/
|
|
||||||
private IcodeConfig icode;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class IcodeConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 产品详情接口icode
|
|
||||||
*/
|
|
||||||
private String productDetail;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取下单填写信息接口icode
|
|
||||||
*/
|
|
||||||
private String bookInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建订单接口icode
|
|
||||||
*/
|
|
||||||
private String book;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消验证接口icode
|
|
||||||
*/
|
|
||||||
private String cancelVerify;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消订单接口icode
|
|
||||||
*/
|
|
||||||
private String cancel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单详情查询接口icode
|
|
||||||
*/
|
|
||||||
private String bookingDetail;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 可订检查接口icode
|
|
||||||
*/
|
|
||||||
private String checkAvailability;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 沙箱测试-订单退订(携程发起)接口icode
|
|
||||||
*/
|
|
||||||
private String simulateCancel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 沙箱测试-人工出票/退订确认/凭证变更接口icode
|
|
||||||
*/
|
|
||||||
private String simulateConfirm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
package com.central.coupon.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
|
||||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RestTemplate配置类
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class RestTemplateConfig {
|
|
||||||
|
|
||||||
@Value("${ctrip.api.timeout:30000}")
|
|
||||||
private int timeout;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RestTemplate restTemplate() {
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
|
||||||
restTemplate.setRequestFactory(clientHttpRequestFactory());
|
|
||||||
return restTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ClientHttpRequestFactory clientHttpRequestFactory() {
|
|
||||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
|
||||||
factory.setConnectTimeout(timeout);
|
|
||||||
factory.setReadTimeout(timeout);
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-117
@@ -1,117 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-334
@@ -1,334 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.central.common.model.Result;
|
|
||||||
import com.central.coupon.entity.CtripContact;
|
|
||||||
import com.central.coupon.entity.CtripOrder;
|
|
||||||
import com.central.coupon.entity.CtripRefund;
|
|
||||||
import com.central.coupon.enums.CtripOrderStatus;
|
|
||||||
import com.central.coupon.mapper.CtripContactMapper;
|
|
||||||
import com.central.coupon.mapper.CtripOrderMapper;
|
|
||||||
import com.central.coupon.mapper.CtripRefundMapper;
|
|
||||||
import com.central.coupon.model.CtripAdminRefundRequest;
|
|
||||||
import com.central.coupon.service.ICtripAdminRefundService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程管理后台退款控制器
|
|
||||||
* 用于管理后台发起携程订单退款
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Tag(name = "携程管理后台退款接口")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coupon/ctrip/admin/refund")
|
|
||||||
public class CtripAdminRefundController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ICtripAdminRefundService ctripAdminRefundService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripOrderMapper ctripOrderMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripRefundMapper ctripRefundMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripContactMapper ctripContactMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理后台发起携程退款
|
|
||||||
*/
|
|
||||||
@Operation(summary = "管理后台发起携程退款")
|
|
||||||
@PostMapping("/apply")
|
|
||||||
public Result<String> applyRefund(@RequestBody CtripAdminRefundRequest request) {
|
|
||||||
log.info("管理后台发起携程退款请求,orderNo: {}, refundAmount: {}",
|
|
||||||
request.getOrderNo(), request.getRefundAmount());
|
|
||||||
|
|
||||||
try {
|
|
||||||
return ctripAdminRefundService.processAdminRefund(request);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("管理后台携程退款异常,orderNo: {}", request.getOrderNo(), e);
|
|
||||||
return Result.failed("退款处理异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取可退金额
|
|
||||||
*/
|
|
||||||
@Operation(summary = "获取订单可退金额")
|
|
||||||
@GetMapping("/available/{orderNo}")
|
|
||||||
public Result<Map<String, Object>> getAvailableRefundAmount(
|
|
||||||
@Parameter(description = "订单中心订单号") @PathVariable String orderNo) {
|
|
||||||
log.info("获取订单可退金额,orderNo: {}", orderNo);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 根据orderNo查询携程订单
|
|
||||||
CtripOrder ctripOrder = ctripOrderMapper.selectByOrderNo(orderNo);
|
|
||||||
if (ctripOrder == null) {
|
|
||||||
return Result.failed("未找到关联的携程订单");
|
|
||||||
}
|
|
||||||
|
|
||||||
BigDecimal availableAmount = ctripAdminRefundService.getAvailableRefundAmount(orderNo);
|
|
||||||
boolean canRefund = ctripAdminRefundService.canRefund(orderNo);
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("orderNo", orderNo);
|
|
||||||
result.put("otaOrderId", ctripOrder.getOtaOrderId());
|
|
||||||
result.put("totalAmount", ctripOrder.getTotalAmount());
|
|
||||||
result.put("availableRefundAmount", availableAmount);
|
|
||||||
result.put("canRefund", canRefund);
|
|
||||||
result.put("orderStatus", ctripOrder.getStatus());
|
|
||||||
result.put("orderStatusDesc", getOrderStatusDesc(ctripOrder.getStatus()));
|
|
||||||
|
|
||||||
return Result.succeed(result);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("获取可退金额异常,orderNo: {}", orderNo, e);
|
|
||||||
return Result.failed("获取可退金额异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查订单是否可退款
|
|
||||||
*/
|
|
||||||
@Operation(summary = "检查订单是否可退款")
|
|
||||||
@GetMapping("/check/{orderNo}")
|
|
||||||
public Result<Map<String, Object>> checkCanRefund(
|
|
||||||
@Parameter(description = "订单中心订单号") @PathVariable String orderNo) {
|
|
||||||
log.info("检查订单是否可退款,orderNo: {}", orderNo);
|
|
||||||
|
|
||||||
try {
|
|
||||||
CtripOrder ctripOrder = ctripOrderMapper.selectByOrderNo(orderNo);
|
|
||||||
if (ctripOrder == null) {
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("orderNo", orderNo);
|
|
||||||
result.put("canRefund", false);
|
|
||||||
result.put("reason", "未找到关联的携程订单");
|
|
||||||
return Result.succeed(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean canRefund = ctripAdminRefundService.canRefund(orderNo);
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("orderNo", orderNo);
|
|
||||||
result.put("otaOrderId", ctripOrder.getOtaOrderId());
|
|
||||||
result.put("canRefund", canRefund);
|
|
||||||
result.put("orderStatus", ctripOrder.getStatus());
|
|
||||||
result.put("orderStatusDesc", getOrderStatusDesc(ctripOrder.getStatus()));
|
|
||||||
if (!canRefund) {
|
|
||||||
result.put("reason", "订单状态不支持退款,当前状态: " + getOrderStatusDesc(ctripOrder.getStatus()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.succeed(result);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("检查订单是否可退款异常,orderNo: {}", orderNo, e);
|
|
||||||
return Result.failed("检查失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询退款记录
|
|
||||||
*/
|
|
||||||
@Operation(summary = "查询订单退款记录")
|
|
||||||
@GetMapping("/records/{orderNo}")
|
|
||||||
public Result<List<CtripRefund>> getRefundRecords(
|
|
||||||
@Parameter(description = "订单中心订单号") @PathVariable String orderNo) {
|
|
||||||
log.info("查询订单退款记录,orderNo: {}", orderNo);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 根据orderNo查询携程订单
|
|
||||||
CtripOrder ctripOrder = ctripOrderMapper.selectByOrderNo(orderNo);
|
|
||||||
if (ctripOrder == null) {
|
|
||||||
return Result.failed("未找到关联的携程订单");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<CtripRefund> refunds = ctripRefundMapper.selectByOtaOrderId(ctripOrder.getOtaOrderId());
|
|
||||||
return Result.succeed(refunds);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询退款记录异常,orderNo: {}", orderNo, e);
|
|
||||||
return Result.failed("查询失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取订单状态描述
|
|
||||||
*/
|
|
||||||
private String getOrderStatusDesc(Integer status) {
|
|
||||||
if (status == null) {
|
|
||||||
return "未知";
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return CtripOrderStatus.fromNumericValue(status).getDescription();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return "未知状态";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取退款状态描述
|
|
||||||
*/
|
|
||||||
private String getRefundStatusDesc(Integer status) {
|
|
||||||
if (status == null) {
|
|
||||||
return "未知";
|
|
||||||
}
|
|
||||||
switch (status) {
|
|
||||||
case 0:
|
|
||||||
return "待确认";
|
|
||||||
case 1:
|
|
||||||
return "已确认";
|
|
||||||
case 2:
|
|
||||||
return "已拒绝";
|
|
||||||
default:
|
|
||||||
return "未知状态";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询携程订单列表
|
|
||||||
*/
|
|
||||||
@Operation(summary = "分页查询携程订单列表")
|
|
||||||
@GetMapping("/orders")
|
|
||||||
public Result<Map<String, Object>> getCtripOrderList(
|
|
||||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
|
|
||||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Integer limit,
|
|
||||||
@Parameter(description = "携程订单号") @RequestParam(required = false) String otaOrderId,
|
|
||||||
@Parameter(description = "关联订单号") @RequestParam(required = false) String orderNo,
|
|
||||||
@Parameter(description = "订单状态") @RequestParam(required = false) Integer status,
|
|
||||||
@Parameter(description = "联系人姓名") @RequestParam(required = false) String contactName,
|
|
||||||
@Parameter(description = "联系人手机号") @RequestParam(required = false) String contactMobile) {
|
|
||||||
log.info("分页查询携程订单列表,page: {}, limit: {}, otaOrderId: {}, orderNo: {}, status: {}, contactName: {}, contactMobile: {}",
|
|
||||||
page, limit, otaOrderId, orderNo, status, contactName, contactMobile);
|
|
||||||
|
|
||||||
try {
|
|
||||||
LambdaQueryWrapper<CtripOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
if (StringUtils.hasText(otaOrderId)) {
|
|
||||||
queryWrapper.like(CtripOrder::getOtaOrderId, otaOrderId);
|
|
||||||
}
|
|
||||||
if (StringUtils.hasText(orderNo)) {
|
|
||||||
queryWrapper.like(CtripOrder::getOrderNo, orderNo);
|
|
||||||
}
|
|
||||||
if (status != null) {
|
|
||||||
queryWrapper.eq(CtripOrder::getStatus, status);
|
|
||||||
}
|
|
||||||
queryWrapper.orderByDesc(CtripOrder::getCreateTime);
|
|
||||||
|
|
||||||
Page<CtripOrder> pageParam = new Page<>(page, limit);
|
|
||||||
IPage<CtripOrder> pageResult = ctripOrderMapper.selectPage(pageParam, queryWrapper);
|
|
||||||
|
|
||||||
// 关联查询联系人信息
|
|
||||||
List<Map<String, Object>> dataWithContact = new ArrayList<>();
|
|
||||||
for (CtripOrder order : pageResult.getRecords()) {
|
|
||||||
Map<String, Object> orderMap = new HashMap<>();
|
|
||||||
orderMap.put("id", order.getId());
|
|
||||||
orderMap.put("otaOrderId", order.getOtaOrderId());
|
|
||||||
orderMap.put("orderNo", order.getOrderNo());
|
|
||||||
orderMap.put("supplierOrderId", order.getSupplierOrderId());
|
|
||||||
orderMap.put("sequenceId", order.getSequenceId());
|
|
||||||
orderMap.put("confirmType", order.getConfirmType());
|
|
||||||
orderMap.put("orderLastConfirmTime", order.getOrderLastConfirmTime());
|
|
||||||
orderMap.put("status", order.getStatus());
|
|
||||||
orderMap.put("totalAmount", order.getTotalAmount());
|
|
||||||
orderMap.put("currency", order.getCurrency());
|
|
||||||
orderMap.put("createTime", order.getCreateTime());
|
|
||||||
orderMap.put("updateTime", order.getUpdateTime());
|
|
||||||
orderMap.put("remark", order.getRemark());
|
|
||||||
orderMap.put("tenantId", order.getTenantId());
|
|
||||||
|
|
||||||
// 查询联系人信息
|
|
||||||
List<CtripContact> contacts = ctripContactMapper.selectByOrderId(order.getId());
|
|
||||||
if (contacts != null && !contacts.isEmpty()) {
|
|
||||||
CtripContact contact = contacts.get(0); // 取第一个联系人
|
|
||||||
orderMap.put("contactName", contact.getName());
|
|
||||||
orderMap.put("contactMobile", contact.getMobile());
|
|
||||||
orderMap.put("contactEmail", contact.getEmail());
|
|
||||||
} else {
|
|
||||||
orderMap.put("contactName", null);
|
|
||||||
orderMap.put("contactMobile", null);
|
|
||||||
orderMap.put("contactEmail", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果有联系人筛选条件,进行过滤
|
|
||||||
if (StringUtils.hasText(contactName) || StringUtils.hasText(contactMobile)) {
|
|
||||||
String name = (String) orderMap.get("contactName");
|
|
||||||
String mobile = (String) orderMap.get("contactMobile");
|
|
||||||
boolean matchName = !StringUtils.hasText(contactName) || (name != null && name.contains(contactName));
|
|
||||||
boolean matchMobile = !StringUtils.hasText(contactMobile) || (mobile != null && mobile.contains(contactMobile));
|
|
||||||
if (matchName && matchMobile) {
|
|
||||||
dataWithContact.add(orderMap);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dataWithContact.add(orderMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("data", dataWithContact);
|
|
||||||
// 如果有联系人筛选,总数需要重新计算(简化处理,返回当前页数量)
|
|
||||||
result.put("count", (StringUtils.hasText(contactName) || StringUtils.hasText(contactMobile))
|
|
||||||
? dataWithContact.size() : pageResult.getTotal());
|
|
||||||
result.put("page", page);
|
|
||||||
result.put("limit", limit);
|
|
||||||
|
|
||||||
return Result.succeed(result);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询携程订单列表异常", e);
|
|
||||||
return Result.failed("查询失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询携程退款列表
|
|
||||||
*/
|
|
||||||
@Operation(summary = "分页查询携程退款列表")
|
|
||||||
@GetMapping("/refunds")
|
|
||||||
public Result<Map<String, Object>> getCtripRefundList(
|
|
||||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
|
|
||||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Integer limit,
|
|
||||||
@Parameter(description = "携程订单号") @RequestParam(required = false) String otaOrderId,
|
|
||||||
@Parameter(description = "供应商订单号") @RequestParam(required = false) String supplierOrderId,
|
|
||||||
@Parameter(description = "退款状态") @RequestParam(required = false) Integer refundStatus) {
|
|
||||||
log.info("分页查询携程退款列表,page: {}, limit: {}, otaOrderId: {}, supplierOrderId: {}, refundStatus: {}",
|
|
||||||
page, limit, otaOrderId, supplierOrderId, refundStatus);
|
|
||||||
|
|
||||||
try {
|
|
||||||
LambdaQueryWrapper<CtripRefund> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
if (StringUtils.hasText(otaOrderId)) {
|
|
||||||
queryWrapper.like(CtripRefund::getOtaOrderId, otaOrderId);
|
|
||||||
}
|
|
||||||
if (StringUtils.hasText(supplierOrderId)) {
|
|
||||||
queryWrapper.like(CtripRefund::getSupplierOrderId, supplierOrderId);
|
|
||||||
}
|
|
||||||
if (refundStatus != null) {
|
|
||||||
queryWrapper.eq(CtripRefund::getRefundStatus, refundStatus);
|
|
||||||
}
|
|
||||||
queryWrapper.orderByDesc(CtripRefund::getCreateTime);
|
|
||||||
|
|
||||||
Page<CtripRefund> pageParam = new Page<>(page, limit);
|
|
||||||
IPage<CtripRefund> pageResult = ctripRefundMapper.selectPage(pageParam, queryWrapper);
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("data", pageResult.getRecords());
|
|
||||||
result.put("count", pageResult.getTotal());
|
|
||||||
result.put("page", page);
|
|
||||||
result.put("limit", limit);
|
|
||||||
|
|
||||||
return Result.succeed(result);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询携程退款列表异常", e);
|
|
||||||
return Result.failed("查询失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-78
@@ -1,78 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.model.CtripCancelOrderRequest;
|
|
||||||
import com.central.coupon.model.CtripCancelOrderResponse;
|
|
||||||
import com.central.coupon.service.CtripCancelOrderService;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程取消订单控制器
|
|
||||||
* 参考文档: https://open.trip.com/apiplatform/order.jsp#operation/CancelOrder
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/ctrip")
|
|
||||||
public class CtripCancelOrderController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripCancelOrderService ctripCancelOrderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理取消订单请求
|
|
||||||
* @param request 取消订单请求
|
|
||||||
* @param httpRequest HTTP请求对象
|
|
||||||
* @return 取消订单响应
|
|
||||||
*/
|
|
||||||
@PostMapping("/cancelOrder")
|
|
||||||
public CtripCancelOrderResponse processCancelOrderRequest(@RequestBody CtripCancelOrderRequest request,
|
|
||||||
HttpServletRequest httpRequest) {
|
|
||||||
log.info("收到携程取消订单请求,serviceName: {}", request.getHeader().getServiceName());
|
|
||||||
return ctripCancelOrderService.cancelOrder(request, httpRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理取消订单请求(统一接口调用)
|
|
||||||
* @param requestBody 请求体
|
|
||||||
* @param httpRequest HTTP请求对象
|
|
||||||
* @return 取消订单响应
|
|
||||||
*/
|
|
||||||
public CtripCancelOrderResponse processCancelOrderRequest(Object requestBody, jakarta.servlet.http.HttpServletRequest httpRequest) {
|
|
||||||
log.info("收到携程取消订单请求(统一接口)");
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 将Object转换为CtripCancelOrderRequest
|
|
||||||
CtripCancelOrderRequest request = objectMapper.convertValue(requestBody, CtripCancelOrderRequest.class);
|
|
||||||
|
|
||||||
// 处理请求
|
|
||||||
CtripCancelOrderResponse response = ctripCancelOrderService.cancelOrder(request, httpRequest);
|
|
||||||
|
|
||||||
log.info("携程取消订单请求处理完成,resultCode: {}",
|
|
||||||
response.getHeader() != null ? response.getHeader().getResultCode() : "unknown");
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理携程取消订单请求异常", e);
|
|
||||||
|
|
||||||
// 返回错误响应
|
|
||||||
CtripCancelOrderResponse errorResponse = new CtripCancelOrderResponse();
|
|
||||||
CtripCancelOrderResponse.CtripResponseHeader header = new CtripCancelOrderResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode("0001");
|
|
||||||
header.setResultMessage("处理请求异常: " + e.getMessage());
|
|
||||||
errorResponse.setHeader(header);
|
|
||||||
|
|
||||||
return errorResponse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-114
@@ -1,114 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.model.CtripCancelPreOrderRequest;
|
|
||||||
import com.central.coupon.model.CtripCancelPreOrderResponse;
|
|
||||||
import com.central.coupon.service.CtripCancelPreOrderService;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程取消预下单控制器
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coupon/ctrip")
|
|
||||||
public class CtripCancelPreOrderController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripCancelPreOrderService ctripCancelPreOrderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消预下单接口
|
|
||||||
*/
|
|
||||||
@PostMapping("/cancelPreOrder")
|
|
||||||
public CtripCancelPreOrderResponse cancelPreOrder(@RequestBody CtripCancelPreOrderRequest request, HttpServletRequest httpRequest) {
|
|
||||||
String clientIp = getClientIp(httpRequest);
|
|
||||||
log.info("收到携程取消预下单请求,IP: {}, serviceName: {}", clientIp,
|
|
||||||
request.getHeader() != null ? request.getHeader().getServiceName() : "unknown");
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 保存原始加密体用于签名验证
|
|
||||||
request.setOriginalEncryptedBody(request.getBody());
|
|
||||||
|
|
||||||
// 处理请求
|
|
||||||
CtripCancelPreOrderResponse response = ctripCancelPreOrderService.processCancelPreOrderRequest(request);
|
|
||||||
|
|
||||||
log.info("携程取消预下单请求处理完成,IP: {}, resultCode: {}", clientIp,
|
|
||||||
response.getHeader() != null ? response.getHeader().getResultCode() : "unknown");
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理携程取消预下单请求异常,IP: {}", clientIp, e);
|
|
||||||
|
|
||||||
// 返回错误响应
|
|
||||||
CtripCancelPreOrderResponse errorResponse = new CtripCancelPreOrderResponse();
|
|
||||||
CtripCancelPreOrderResponse.CtripResponseHeader header = new CtripCancelPreOrderResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode("0001");
|
|
||||||
header.setResultMessage("处理请求异常: " + e.getMessage());
|
|
||||||
errorResponse.setHeader(header);
|
|
||||||
|
|
||||||
return errorResponse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消预下单接口(统一接口调用)
|
|
||||||
*/
|
|
||||||
public CtripCancelPreOrderResponse processCancelPreOrderRequest(Object requestBody, jakarta.servlet.http.HttpServletRequest httpRequest) {
|
|
||||||
String clientIp = getClientIp(httpRequest);
|
|
||||||
log.info("收到携程取消预下单请求(统一接口),IP: {}", clientIp);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 将Object转换为CtripCancelPreOrderRequest
|
|
||||||
CtripCancelPreOrderRequest request = objectMapper.convertValue(requestBody, CtripCancelPreOrderRequest.class);
|
|
||||||
|
|
||||||
// 保存原始加密体用于签名验证
|
|
||||||
request.setOriginalEncryptedBody(request.getBody());
|
|
||||||
|
|
||||||
// 处理请求
|
|
||||||
CtripCancelPreOrderResponse response = ctripCancelPreOrderService.processCancelPreOrderRequest(request);
|
|
||||||
|
|
||||||
log.info("携程取消预下单请求处理完成,IP: {}, resultCode: {}", clientIp,
|
|
||||||
response.getHeader() != null ? response.getHeader().getResultCode() : "unknown");
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理携程取消预下单请求异常,IP: {}", clientIp, e);
|
|
||||||
|
|
||||||
// 返回错误响应
|
|
||||||
CtripCancelPreOrderResponse errorResponse = new CtripCancelPreOrderResponse();
|
|
||||||
CtripCancelPreOrderResponse.CtripResponseHeader header = new CtripCancelPreOrderResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode("0001");
|
|
||||||
header.setResultMessage("处理请求异常: " + e.getMessage());
|
|
||||||
errorResponse.setHeader(header);
|
|
||||||
|
|
||||||
return errorResponse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取客户端IP地址
|
|
||||||
*/
|
|
||||||
private String getClientIp(HttpServletRequest request) {
|
|
||||||
String xForwardedFor = request.getHeader("X-Forwarded-For");
|
|
||||||
if (xForwardedFor != null && !xForwardedFor.isEmpty() && !"unknown".equalsIgnoreCase(xForwardedFor)) {
|
|
||||||
return xForwardedFor.split(",")[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
String xRealIp = request.getHeader("X-Real-IP");
|
|
||||||
if (xRealIp != null && !xRealIp.isEmpty() && !"unknown".equalsIgnoreCase(xRealIp)) {
|
|
||||||
return xRealIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return request.getRemoteAddr();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-169
@@ -1,169 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.model.CtripConsumedNoticeRequest;
|
|
||||||
import com.central.coupon.model.CtripConsumedNoticeResponse;
|
|
||||||
import com.central.coupon.service.CtripConsumedService;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销业务接口Controller
|
|
||||||
* 用于业务系统调用,向携程发送核销通知
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/ctrip/consumed")
|
|
||||||
public class CtripConsumedController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripConsumedService ctripConsumedService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销订单接口
|
|
||||||
* 业务系统调用此接口执行核销操作
|
|
||||||
*
|
|
||||||
* @param request 核销请求参数
|
|
||||||
* @return 核销结果
|
|
||||||
*/
|
|
||||||
@PostMapping("/consume")
|
|
||||||
public CtripConsumedNoticeResponse consumeOrder(@RequestBody CtripConsumeRequest request) {
|
|
||||||
log.info("收到核销订单请求,otaOrderId: {}, itemId: {}, useQuantity: {}",
|
|
||||||
request.getOtaOrderId(), request.getItemId(), request.getUseQuantity());
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 执行核销逻辑
|
|
||||||
CtripConsumedNoticeResponse response = ctripConsumedService.consumeOrder(request);
|
|
||||||
|
|
||||||
log.info("核销订单处理完成,otaOrderId: {}, resultCode: {}",
|
|
||||||
request.getOtaOrderId(), response.getHeader().getResultCode());
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("核销订单异常,otaOrderId: {}", request.getOtaOrderId(), e);
|
|
||||||
return buildErrorResponse("0003", "核销异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量核销订单接口
|
|
||||||
*
|
|
||||||
* @param request 批量核销请求
|
|
||||||
* @return 核销结果
|
|
||||||
*/
|
|
||||||
@PostMapping("/consume-batch")
|
|
||||||
public CtripConsumedNoticeResponse consumeOrderBatch(@RequestBody CtripConsumeBatchRequest request) {
|
|
||||||
log.info("收到批量核销订单请求,订单数量: {}", request.getItems().size());
|
|
||||||
|
|
||||||
try {
|
|
||||||
CtripConsumedNoticeResponse response = ctripConsumedService.consumeOrderBatch(request);
|
|
||||||
|
|
||||||
log.info("批量核销订单处理完成,resultCode: {}", response.getHeader().getResultCode());
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("批量核销订单异常", e);
|
|
||||||
return buildErrorResponse("0003", "批量核销异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询核销记录接口
|
|
||||||
*
|
|
||||||
* @param otaOrderId 携程订单号
|
|
||||||
* @return 核销记录列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/records/{otaOrderId}")
|
|
||||||
public List<Map<String, Object>> getConsumedRecords(@PathVariable String otaOrderId) {
|
|
||||||
log.info("查询核销记录,otaOrderId: {}", otaOrderId);
|
|
||||||
|
|
||||||
try {
|
|
||||||
return ctripConsumedService.getConsumedRecords(otaOrderId);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询核销记录异常,otaOrderId: {}", otaOrderId, e);
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建错误响应
|
|
||||||
*/
|
|
||||||
private CtripConsumedNoticeResponse buildErrorResponse(String resultCode, String resultMessage) {
|
|
||||||
CtripConsumedNoticeResponse response = new CtripConsumedNoticeResponse();
|
|
||||||
CtripConsumedNoticeResponse.CtripResponseHeader header = new CtripConsumedNoticeResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode(resultCode);
|
|
||||||
header.setResultMessage(resultMessage);
|
|
||||||
response.setHeader(header);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销请求参数
|
|
||||||
*/
|
|
||||||
public static class CtripConsumeRequest {
|
|
||||||
private String otaOrderId; // 携程订单号
|
|
||||||
private String supplierOrderId; // 供应商订单号
|
|
||||||
private String itemId; // 订单项编号
|
|
||||||
private String useStartDate; // 使用开始日期
|
|
||||||
private String useEndDate; // 使用结束日期
|
|
||||||
private Integer quantity; // 订单总份数
|
|
||||||
private Integer useQuantity; // 已核销份数
|
|
||||||
private List<String> passengerIds; // 乘客ID列表
|
|
||||||
private List<String> voucherIds; // 凭证ID列表
|
|
||||||
private String remark; // 备注信息
|
|
||||||
private Integer lostAmount; // 损失金额
|
|
||||||
private String lostAmountCurrency; // 损失金额货币类型
|
|
||||||
|
|
||||||
// getters and setters
|
|
||||||
public String getOtaOrderId() { return otaOrderId; }
|
|
||||||
public void setOtaOrderId(String otaOrderId) { this.otaOrderId = otaOrderId; }
|
|
||||||
|
|
||||||
public String getSupplierOrderId() { return supplierOrderId; }
|
|
||||||
public void setSupplierOrderId(String supplierOrderId) { this.supplierOrderId = supplierOrderId; }
|
|
||||||
|
|
||||||
public String getItemId() { return itemId; }
|
|
||||||
public void setItemId(String itemId) { this.itemId = itemId; }
|
|
||||||
|
|
||||||
public String getUseStartDate() { return useStartDate; }
|
|
||||||
public void setUseStartDate(String useStartDate) { this.useStartDate = useStartDate; }
|
|
||||||
|
|
||||||
public String getUseEndDate() { return useEndDate; }
|
|
||||||
public void setUseEndDate(String useEndDate) { this.useEndDate = useEndDate; }
|
|
||||||
|
|
||||||
public Integer getQuantity() { return quantity; }
|
|
||||||
public void setQuantity(Integer quantity) { this.quantity = quantity; }
|
|
||||||
|
|
||||||
public Integer getUseQuantity() { return useQuantity; }
|
|
||||||
public void setUseQuantity(Integer useQuantity) { this.useQuantity = useQuantity; }
|
|
||||||
|
|
||||||
public List<String> getPassengerIds() { return passengerIds; }
|
|
||||||
public void setPassengerIds(List<String> passengerIds) { this.passengerIds = passengerIds; }
|
|
||||||
|
|
||||||
public List<String> getVoucherIds() { return voucherIds; }
|
|
||||||
public void setVoucherIds(List<String> voucherIds) { this.voucherIds = voucherIds; }
|
|
||||||
|
|
||||||
public String getRemark() { return remark; }
|
|
||||||
public void setRemark(String remark) { this.remark = remark; }
|
|
||||||
|
|
||||||
public Integer getLostAmount() { return lostAmount; }
|
|
||||||
public void setLostAmount(Integer lostAmount) { this.lostAmount = lostAmount; }
|
|
||||||
|
|
||||||
public String getLostAmountCurrency() { return lostAmountCurrency; }
|
|
||||||
public void setLostAmountCurrency(String lostAmountCurrency) { this.lostAmountCurrency = lostAmountCurrency; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量核销请求参数
|
|
||||||
*/
|
|
||||||
public static class CtripConsumeBatchRequest {
|
|
||||||
private List<CtripConsumeRequest> items;
|
|
||||||
|
|
||||||
public List<CtripConsumeRequest> getItems() { return items; }
|
|
||||||
public void setItems(List<CtripConsumeRequest> items) { this.items = items; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-83
@@ -1,83 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.model.CtripConsumedNoticeRequest;
|
|
||||||
import com.central.coupon.model.CtripConsumedNoticeResponse;
|
|
||||||
import com.central.coupon.service.CtripConsumedNoticeService;
|
|
||||||
import com.central.coupon.util.CtripDecryptUtil;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销优惠券通知接口Controller
|
|
||||||
* 参考文档:https://open.trip.com/apiplatform/order.jsp#operation/OrderConsumedNotice
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/ctrip")
|
|
||||||
public class CtripConsumedNoticeController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripConsumedNoticeService ctripConsumedNoticeService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripDecryptUtil ctripDecryptUtil;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销优惠券通知接口
|
|
||||||
*
|
|
||||||
* @param encryptedRequest 加密的请求体
|
|
||||||
* @return 核销通知响应
|
|
||||||
*/
|
|
||||||
@PostMapping("/consumed-notice")
|
|
||||||
public CtripConsumedNoticeResponse consumedNotice(@RequestBody String encryptedRequest) {
|
|
||||||
log.info("收到携程核销优惠券通知请求,加密请求体长度: {}", encryptedRequest.length());
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. 解密请求体
|
|
||||||
String decryptedBody = ctripDecryptUtil.decryptAES(encryptedRequest);
|
|
||||||
if (decryptedBody == null) {
|
|
||||||
log.error("解密携程核销通知请求体失败");
|
|
||||||
return buildErrorResponse("0001", "解密请求失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("携程核销通知请求体解密成功,内容: {}", decryptedBody);
|
|
||||||
|
|
||||||
// 2. 解析请求体
|
|
||||||
CtripConsumedNoticeRequest request = objectMapper.readValue(decryptedBody, CtripConsumedNoticeRequest.class);
|
|
||||||
if (request == null) {
|
|
||||||
log.error("解析携程核销通知请求失败");
|
|
||||||
return buildErrorResponse("0002", "解析请求失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 处理核销通知
|
|
||||||
CtripConsumedNoticeResponse response = ctripConsumedNoticeService.processConsumedNotice(request);
|
|
||||||
|
|
||||||
log.info("携程核销优惠券通知处理完成,sequenceId: {}", request.getBody().getSequenceId());
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理携程核销优惠券通知异常", e);
|
|
||||||
return buildErrorResponse("0003", "处理异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建错误响应
|
|
||||||
*/
|
|
||||||
private CtripConsumedNoticeResponse buildErrorResponse(String resultCode, String resultMessage) {
|
|
||||||
CtripConsumedNoticeResponse response = new CtripConsumedNoticeResponse();
|
|
||||||
CtripConsumedNoticeResponse.CtripResponseHeader header = new CtripConsumedNoticeResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode(resultCode);
|
|
||||||
header.setResultMessage(resultMessage);
|
|
||||||
response.setHeader(header);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-106
@@ -1,106 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.service.CtripDataCleanupService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程数据清理控制器
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coupon/ctrip/cleanup")
|
|
||||||
@Tag(name = "携程数据清理", description = "携程数据清理相关接口")
|
|
||||||
public class CtripDataCleanupController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripDataCleanupService ctripDataCleanupService;
|
|
||||||
|
|
||||||
@PostMapping("/duplicate-order-items/{otaOrderId}")
|
|
||||||
@Operation(summary = "清理指定订单的重复订单项记录", description = "删除itemId为PLU值的旧记录,保留真实的携程itemId记录")
|
|
||||||
public Map<String, Object> cleanupDuplicateOrderItems(
|
|
||||||
@Parameter(description = "携程订单号") @PathVariable String otaOrderId) {
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
log.info("开始清理重复订单项记录,otaOrderId: {}", otaOrderId);
|
|
||||||
|
|
||||||
boolean success = ctripDataCleanupService.cleanupDuplicateOrderItems(otaOrderId);
|
|
||||||
|
|
||||||
result.put("success", success);
|
|
||||||
result.put("message", success ? "清理成功" : "清理失败");
|
|
||||||
result.put("otaOrderId", otaOrderId);
|
|
||||||
|
|
||||||
log.info("清理重复订单项记录完成,otaOrderId: {}, 结果: {}", otaOrderId, success);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("清理重复订单项记录异常,otaOrderId: {}", otaOrderId, e);
|
|
||||||
result.put("success", false);
|
|
||||||
result.put("message", "清理异常: " + e.getMessage());
|
|
||||||
result.put("otaOrderId", otaOrderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/duplicate-order-items-by-order-id/{orderId}")
|
|
||||||
@Operation(summary = "根据订单ID清理重复订单项记录", description = "删除itemId为PLU值的旧记录,保留真实的携程itemId记录")
|
|
||||||
public Map<String, Object> cleanupDuplicateOrderItemsByOrderId(
|
|
||||||
@Parameter(description = "订单ID") @PathVariable Long orderId) {
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
log.info("开始清理重复订单项记录,orderId: {}", orderId);
|
|
||||||
|
|
||||||
boolean success = ctripDataCleanupService.cleanupDuplicateOrderItemsByOrderId(orderId);
|
|
||||||
|
|
||||||
result.put("success", success);
|
|
||||||
result.put("message", success ? "清理成功" : "清理失败");
|
|
||||||
result.put("orderId", orderId);
|
|
||||||
|
|
||||||
log.info("清理重复订单项记录完成,orderId: {}, 结果: {}", orderId, success);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("清理重复订单项记录异常,orderId: {}", orderId, e);
|
|
||||||
result.put("success", false);
|
|
||||||
result.put("message", "清理异常: " + e.getMessage());
|
|
||||||
result.put("orderId", orderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/all-duplicate-order-items")
|
|
||||||
@Operation(summary = "清理所有订单的重复订单项记录", description = "清理所有订单中的重复订单项记录")
|
|
||||||
public Map<String, Object> cleanupAllDuplicateOrderItems() {
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
log.info("开始清理所有订单的重复订单项记录");
|
|
||||||
|
|
||||||
boolean success = ctripDataCleanupService.cleanupAllDuplicateOrderItems();
|
|
||||||
|
|
||||||
result.put("success", success);
|
|
||||||
result.put("message", success ? "清理成功" : "清理失败");
|
|
||||||
|
|
||||||
log.info("清理所有重复订单项记录完成,结果: {}", success);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("清理所有重复订单项记录异常", e);
|
|
||||||
result.put("success", false);
|
|
||||||
result.put("message", "清理异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-128
@@ -1,128 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.central.common.model.Result;
|
|
||||||
import com.central.coupon.entity.CtripDistOrder;
|
|
||||||
import com.central.coupon.mapper.CtripDistOrderMapper;
|
|
||||||
import com.central.coupon.service.ICtripDistOrderService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/ctrip/dist/order")
|
|
||||||
@Tag(name = "携程分销订单管理")
|
|
||||||
public class CtripDistOrderController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ICtripDistOrderService ctripDistOrderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripDistOrderMapper ctripDistOrderMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询携程分销订单列表
|
|
||||||
*/
|
|
||||||
@Operation(summary = "分页查询携程分销订单列表")
|
|
||||||
@GetMapping("/list")
|
|
||||||
public Result<Map<String, Object>> listCtripDistOrders(
|
|
||||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
|
|
||||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Integer limit,
|
|
||||||
@Parameter(description = "本地订单号") @RequestParam(required = false) String orderNo,
|
|
||||||
@Parameter(description = "携程订单ID") @RequestParam(required = false) Long ctripOrderId,
|
|
||||||
@Parameter(description = "携程产品ID") @RequestParam(required = false) Long ctripProductId,
|
|
||||||
@Parameter(description = "携程订单状态") @RequestParam(required = false) String ctripOrderStatus,
|
|
||||||
@Parameter(description = "核销状态") @RequestParam(required = false) Integer consumeStatus,
|
|
||||||
@Parameter(description = "退款状态") @RequestParam(required = false) Integer refundStatus,
|
|
||||||
@Parameter(description = "租户ID") @RequestParam(required = false) String tenantId) {
|
|
||||||
log.info("分页查询携程分销订单列表,page: {}, limit: {}, orderNo: {}", page, limit, orderNo);
|
|
||||||
try {
|
|
||||||
LambdaQueryWrapper<CtripDistOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
queryWrapper.eq(CtripDistOrder::getDeleted, 0);
|
|
||||||
if (StringUtils.hasText(orderNo)) {
|
|
||||||
queryWrapper.like(CtripDistOrder::getOrderNo, orderNo);
|
|
||||||
}
|
|
||||||
if (ctripOrderId != null) {
|
|
||||||
queryWrapper.eq(CtripDistOrder::getCtripOrderId, ctripOrderId);
|
|
||||||
}
|
|
||||||
if (ctripProductId != null) {
|
|
||||||
queryWrapper.eq(CtripDistOrder::getCtripProductId, ctripProductId);
|
|
||||||
}
|
|
||||||
if (StringUtils.hasText(ctripOrderStatus)) {
|
|
||||||
queryWrapper.eq(CtripDistOrder::getCtripOrderStatus, ctripOrderStatus);
|
|
||||||
}
|
|
||||||
if (consumeStatus != null) {
|
|
||||||
queryWrapper.eq(CtripDistOrder::getConsumeStatus, consumeStatus);
|
|
||||||
}
|
|
||||||
if (refundStatus != null) {
|
|
||||||
queryWrapper.eq(CtripDistOrder::getRefundStatus, refundStatus);
|
|
||||||
}
|
|
||||||
if (StringUtils.hasText(tenantId)) {
|
|
||||||
queryWrapper.eq(CtripDistOrder::getTenantId, tenantId);
|
|
||||||
}
|
|
||||||
queryWrapper.orderByDesc(CtripDistOrder::getCreateTime);
|
|
||||||
|
|
||||||
Page<CtripDistOrder> pageParam = new Page<>(page, limit);
|
|
||||||
IPage<CtripDistOrder> pageResult = ctripDistOrderMapper.selectPage(pageParam, queryWrapper);
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("data", pageResult.getRecords());
|
|
||||||
result.put("count", pageResult.getTotal());
|
|
||||||
result.put("page", page);
|
|
||||||
result.put("limit", limit);
|
|
||||||
return Result.succeed(result);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询携程分销订单列表异常", e);
|
|
||||||
return Result.failed("查询失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建携程分销订单(被order-center通过Feign调用)
|
|
||||||
*/
|
|
||||||
@PostMapping("/create")
|
|
||||||
public Result<String> createCtripDistOrder(@RequestBody Map<String, Object> params) {
|
|
||||||
String orderNo = (String) params.get("orderNo");
|
|
||||||
String orderAmount = (String) params.get("orderAmount");
|
|
||||||
Long ctripProductId = Long.valueOf(params.get("ctripProductId").toString());
|
|
||||||
String tenantId = (String) params.get("tenantId");
|
|
||||||
String mobile = params.get("mobile") != null ? params.get("mobile").toString() : null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
ctripDistOrderService.createCtripDistOrder(orderNo, orderAmount, ctripProductId, tenantId, mobile);
|
|
||||||
return Result.succeed("携程分销订单创建成功");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("创建携程分销订单失败", e);
|
|
||||||
return Result.failed("创建失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退订携程分销订单
|
|
||||||
*/
|
|
||||||
@PostMapping("/cancel/{orderNo}")
|
|
||||||
public Result<String> cancelCtripDistOrder(
|
|
||||||
@PathVariable String orderNo,
|
|
||||||
@RequestParam(defaultValue = "用户申请退订") String reason) {
|
|
||||||
boolean success = ctripDistOrderService.cancelCtripDistOrder(orderNo, reason);
|
|
||||||
return success ? Result.succeed("退订成功") : Result.failed("退订失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询携程分销订单详情
|
|
||||||
*/
|
|
||||||
@GetMapping("/{orderNo}")
|
|
||||||
public Result<CtripDistOrder> getCtripDistOrder(@PathVariable String orderNo) {
|
|
||||||
return Result.succeed(ctripDistOrderService.getByOrderNo(orderNo));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-708
@@ -1,708 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.common.model.Result;
|
|
||||||
import com.central.coupon.model.CtripDistBookRequest;
|
|
||||||
import com.central.coupon.model.CtripDistBookResponse;
|
|
||||||
import com.central.coupon.model.CtripDistBookingDetailResponse;
|
|
||||||
import com.central.coupon.model.CtripDistCancelResponse;
|
|
||||||
import com.central.coupon.model.CtripDistCancelVerifyResponse;
|
|
||||||
import com.central.coupon.service.ICtripDistApiService;
|
|
||||||
import com.central.coupon.service.ICtripDistTokenService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程分销商接口沙箱测试
|
|
||||||
* 用途:逐个调试携程分销商API,确认连通性和返回格式
|
|
||||||
* 注意:仅用于测试环境,生产环境应禁用或加权限控制
|
|
||||||
*
|
|
||||||
* 核心设计:
|
|
||||||
* - 调用 bookInfo 接口后,问卷模板按 productId 缓存
|
|
||||||
* - 后续的可订检查/创建订单自动从缓存中取问卷模板
|
|
||||||
* - 用户只需传 questionCode → 答案值,系统自动匹配 questionID/questionTitle
|
|
||||||
* - 不同产品的测试步骤差异(字段不同、数量不同)全部通过参数控制
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/ctrip/dist/test")
|
|
||||||
@Tag(name = "携程分销商接口测试")
|
|
||||||
public class CtripDistTestController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ICtripDistApiService ctripDistApiService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ICtripDistTokenService ctripDistTokenService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private com.central.coupon.config.CtripDistributorConfig ctripDistributorConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bookInfo 缓存:key=productId, value=bookInfo完整返回
|
|
||||||
* 调用 bookInfo 接口后自动缓存,后续接口直接使用
|
|
||||||
*/
|
|
||||||
private final Map<Long, Map<String, Object>> bookInfoCache = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
// ==================== -1. 配置诊断 ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 诊断当前分销商配置
|
|
||||||
* 用途:确认Nacos配置是否被正确注入(key脱敏显示)
|
|
||||||
*
|
|
||||||
* 调用示例:GET /ctrip/dist/test/config
|
|
||||||
*/
|
|
||||||
@GetMapping("/config")
|
|
||||||
@Operation(summary = "诊断分销商配置")
|
|
||||||
public Result<Map<String, Object>> testConfig() {
|
|
||||||
Map<String, Object> data = new LinkedHashMap<>();
|
|
||||||
data.put("aid", ctripDistributorConfig.getAid());
|
|
||||||
data.put("sid", ctripDistributorConfig.getSid());
|
|
||||||
data.put("key", ctripDistributorConfig.getKey() != null
|
|
||||||
? ctripDistributorConfig.getKey().substring(0, Math.min(4, ctripDistributorConfig.getKey().length())) + "****"
|
|
||||||
: "null");
|
|
||||||
data.put("authUrl", ctripDistributorConfig.getAuthUrl());
|
|
||||||
data.put("refreshUrl", ctripDistributorConfig.getRefreshUrl());
|
|
||||||
data.put("apiUrl", ctripDistributorConfig.getApiUrl());
|
|
||||||
data.put("locale", ctripDistributorConfig.getLocale());
|
|
||||||
data.put("currency", ctripDistributorConfig.getCurrency());
|
|
||||||
if (ctripDistributorConfig.getIcode() != null) {
|
|
||||||
Map<String, Object> icode = new LinkedHashMap<>();
|
|
||||||
icode.put("productDetail", ctripDistributorConfig.getIcode().getProductDetail());
|
|
||||||
icode.put("bookInfo", ctripDistributorConfig.getIcode().getBookInfo());
|
|
||||||
icode.put("book", ctripDistributorConfig.getIcode().getBook());
|
|
||||||
icode.put("cancelVerify", ctripDistributorConfig.getIcode().getCancelVerify());
|
|
||||||
icode.put("cancel", ctripDistributorConfig.getIcode().getCancel());
|
|
||||||
icode.put("bookingDetail", ctripDistributorConfig.getIcode().getBookingDetail());
|
|
||||||
data.put("icode", icode);
|
|
||||||
} else {
|
|
||||||
data.put("icode", "null - icode未配置!");
|
|
||||||
}
|
|
||||||
return Result.succeed(data, "当前分销商配置");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 0. Token测试 ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试获取Token
|
|
||||||
* 用途:验证aid/sid/key配置是否正确,Token能否正常获取
|
|
||||||
*
|
|
||||||
* 调用示例:POST /ctrip/dist/test/token
|
|
||||||
*/
|
|
||||||
@PostMapping("/token")
|
|
||||||
@Operation(summary = "测试获取Token")
|
|
||||||
public Result<Map<String, Object>> testGetToken() {
|
|
||||||
log.info("===== 测试获取携程分销商Token =====");
|
|
||||||
try {
|
|
||||||
String token = ctripDistTokenService.getAccessToken();
|
|
||||||
Map<String, Object> data = new LinkedHashMap<>();
|
|
||||||
data.put("accessToken", token);
|
|
||||||
data.put("tokenLength", token != null ? token.length() : 0);
|
|
||||||
data.put("message", "Token获取成功");
|
|
||||||
log.info("Token获取成功,长度: {}", token != null ? token.length() : 0);
|
|
||||||
return Result.succeed(data, "Token获取成功");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Token获取失败", e);
|
|
||||||
return Result.failed("Token获取失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 1. 获取产品详情 ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试获取产品详情
|
|
||||||
* 用途:根据productId获取产品信息,包含packageID和resourceID
|
|
||||||
* 后续下单需要用到返回的packageID和resourceID
|
|
||||||
*
|
|
||||||
* 调用示例:GET /ctrip/dist/test/product-detail?productId=12345678
|
|
||||||
*/
|
|
||||||
@GetMapping("/product-detail")
|
|
||||||
@Operation(summary = "1.获取产品详情")
|
|
||||||
public Result<Map<String, Object>> testProductDetail(@RequestParam Long productId) {
|
|
||||||
log.info("===== 测试获取产品详情,productId: {} =====", productId);
|
|
||||||
try {
|
|
||||||
Map<String, Object> result = ctripDistApiService.getProductDetail(productId);
|
|
||||||
log.info("产品详情返回: {}", result);
|
|
||||||
return Result.succeed(result, "获取产���详情成功");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("获取产品详情失败,productId: {}", productId, e);
|
|
||||||
return Result.failed("获取产品详情失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 2. 获取下单填写信息(会自动缓存) ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试获取下单填写信息
|
|
||||||
* 用途:下单前查询该产品需要填写哪些字段(如手机号、身份证、英文姓名等)
|
|
||||||
* 调用成功后会按 productId 缓存结果,后续可订检查/创建订单自动使用
|
|
||||||
* 需要先调用接口1获取packageId和resourceId
|
|
||||||
*
|
|
||||||
* 调用示例:GET /ctrip/dist/test/book-info?productId=12345678&packageId=37326707&resourceId=37326710
|
|
||||||
*/
|
|
||||||
@GetMapping("/book-info")
|
|
||||||
@Operation(summary = "2.获取下单填写信息(自动缓存)")
|
|
||||||
public Result<Map<String, Object>> testBookInfo(
|
|
||||||
@RequestParam Long productId,
|
|
||||||
@RequestParam Long packageId,
|
|
||||||
@RequestParam Long resourceId) {
|
|
||||||
log.info("===== 测试获取下单填写信息,productId: {}, packageId: {}, resourceId: {} =====",
|
|
||||||
productId, packageId, resourceId);
|
|
||||||
try {
|
|
||||||
Map<String, Object> result = ctripDistApiService.getBookInfo(productId, packageId, resourceId);
|
|
||||||
log.info("下单填写信息返回: {}", result);
|
|
||||||
|
|
||||||
// 缓存 bookInfo 结果
|
|
||||||
bookInfoCache.put(productId, result);
|
|
||||||
log.info("bookInfo已缓存,productId: {},后续接口将自动使用", productId);
|
|
||||||
|
|
||||||
return Result.succeed(result, "获取下单填写信息成功(已缓存)");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("获取下单填写信息失败", e);
|
|
||||||
return Result.failed("获取下单填写信息失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查看当前缓存的bookInfo
|
|
||||||
* 用途:查看某个产品已缓存的问卷模板,方便确认需要填哪些字段
|
|
||||||
*
|
|
||||||
* 调用示例:GET /ctrip/dist/test/book-info/cache?productId=39098283
|
|
||||||
*/
|
|
||||||
@GetMapping("/book-info/cache")
|
|
||||||
@Operation(summary = "2.1 查看缓存的bookInfo")
|
|
||||||
public Result<Map<String, Object>> getCachedBookInfo(@RequestParam Long productId) {
|
|
||||||
Map<String, Object> cached = bookInfoCache.get(productId);
|
|
||||||
if (cached == null) {
|
|
||||||
return Result.failed("productId=" + productId + " 的bookInfo未缓存,请先调用接口2获取");
|
|
||||||
}
|
|
||||||
// 额外提取问卷模板摘要方便查看
|
|
||||||
Map<String, Object> result = new LinkedHashMap<>();
|
|
||||||
result.put("productId", productId);
|
|
||||||
result.put("questionTemplate", extractQuestionTemplate(cached));
|
|
||||||
result.put("fullResponse", cached);
|
|
||||||
return Result.succeed(result, "缓存的bookInfo");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 2.5 可订检查 ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试可订检查
|
|
||||||
* 用途:下单前检查资源是否可预订
|
|
||||||
* 前提:必须先调用接口2获取bookInfo(已自动缓存)
|
|
||||||
*
|
|
||||||
* passengers中每个出行人只需传 questionCode → 答案值,
|
|
||||||
* 系统会自动从缓存的bookInfo中匹配questionID和questionTitle
|
|
||||||
*
|
|
||||||
* 调用示例:POST /ctrip/dist/test/check-availability
|
|
||||||
*
|
|
||||||
* 产品2示例(中文姓名+身份证,2出行人):
|
|
||||||
* {
|
|
||||||
* "productId": xxx,
|
|
||||||
* "packageId": xxx,
|
|
||||||
* "resourceId": xxx,
|
|
||||||
* "price": 68.00,
|
|
||||||
* "quantity": 2,
|
|
||||||
* "passengers": [
|
|
||||||
* {"P_NAME": "杜超", "P_ID_CARD": "120101199003076531"},
|
|
||||||
* {"P_NAME": "张三", "P_ID_CARD": "120101199003076532"}
|
|
||||||
* ]
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* 产品3示例(英文姓名,quantity=2但只需1个出行人):
|
|
||||||
* {
|
|
||||||
* "productId": 39098283,
|
|
||||||
* "packageId": xxx,
|
|
||||||
* "resourceId": xxx,
|
|
||||||
* "price": 68.00,
|
|
||||||
* "quantity": 2,
|
|
||||||
* "passengers": [
|
|
||||||
* {"P_FIRSTCNAME": "Chao", "P_LASTCNAME": "Du"}
|
|
||||||
* ]
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
@PostMapping("/check-availability")
|
|
||||||
@Operation(summary = "2.5 可订检查")
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Result<Map<String, Object>> testCheckAvailability(@RequestBody Map<String, Object> params) {
|
|
||||||
log.info("===== 测试可订检查,params: {} =====", params);
|
|
||||||
try {
|
|
||||||
Long productId = Long.valueOf(params.get("productId").toString());
|
|
||||||
Long packageId = Long.valueOf(params.get("packageId").toString());
|
|
||||||
Long resourceId = Long.valueOf(params.get("resourceId").toString());
|
|
||||||
BigDecimal price = new BigDecimal(params.get("price").toString());
|
|
||||||
String contactName = params.getOrDefault("contactName", "杜超").toString();
|
|
||||||
String contactMobile = params.getOrDefault("contactMobile", "18222892722").toString();
|
|
||||||
String contactEmail = params.getOrDefault("contactEmail", "1098974449@qq.com").toString();
|
|
||||||
|
|
||||||
// 从缓存获取问卷模板
|
|
||||||
List<Map<String, Object>> questionTemplate = getQuestionTemplate(productId);
|
|
||||||
|
|
||||||
// 解析出行人问卷答案
|
|
||||||
List<List<CtripDistBookRequest.QuestionAnswer>> passengerAnswers =
|
|
||||||
parsePassengerAnswers(params, questionTemplate);
|
|
||||||
|
|
||||||
// quantity 独立于出行人数量
|
|
||||||
int quantity = params.get("quantity") != null
|
|
||||||
? Integer.parseInt(params.get("quantity").toString())
|
|
||||||
: passengerAnswers.size();
|
|
||||||
|
|
||||||
String useDate = params.getOrDefault("useDate",
|
|
||||||
LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))).toString();
|
|
||||||
|
|
||||||
String distributorOrderId = "CHECK_" + System.currentTimeMillis();
|
|
||||||
CtripDistBookRequest request = buildTestBookRequest(
|
|
||||||
distributorOrderId, productId, packageId, resourceId,
|
|
||||||
price, quantity, useDate, contactName, contactMobile, contactEmail,
|
|
||||||
passengerAnswers);
|
|
||||||
|
|
||||||
boolean available = ctripDistApiService.checkAvailability(request);
|
|
||||||
Map<String, Object> data = new LinkedHashMap<>();
|
|
||||||
data.put("available", available);
|
|
||||||
data.put("quantity", quantity);
|
|
||||||
data.put("passengerCount", passengerAnswers.size());
|
|
||||||
data.put("message", available ? "可预订" : "不可预订");
|
|
||||||
log.info("可订检查结果: {}, 购买数量: {}, 出行人数: {}", available, quantity, passengerAnswers.size());
|
|
||||||
return Result.succeed(data, available ? "可预订" : "不可预订");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("可订检查失败", e);
|
|
||||||
return Result.failed("可订检查失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 3. 创建携程订单 ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试创建携程订单
|
|
||||||
* 前提:必须先调用接口2获取bookInfo(已自动缓存)
|
|
||||||
* 参数格式与可订检查完全一致
|
|
||||||
*
|
|
||||||
* 调用示例:POST /ctrip/dist/test/book
|
|
||||||
* Body: 与可订检查接口相同
|
|
||||||
*/
|
|
||||||
@PostMapping("/book")
|
|
||||||
@Operation(summary = "3.创建携程订单")
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Result<CtripDistBookResponse> testCreateOrder(@RequestBody Map<String, Object> params) {
|
|
||||||
log.info("===== 测试创建携程订单,params: {} =====", params);
|
|
||||||
try {
|
|
||||||
Long productId = Long.valueOf(params.get("productId").toString());
|
|
||||||
Long packageId = Long.valueOf(params.get("packageId").toString());
|
|
||||||
Long resourceId = Long.valueOf(params.get("resourceId").toString());
|
|
||||||
BigDecimal price = new BigDecimal(params.get("price").toString());
|
|
||||||
String contactName = params.getOrDefault("contactName", "杜超").toString();
|
|
||||||
String contactMobile = params.getOrDefault("contactMobile", "18222892722").toString();
|
|
||||||
String contactEmail = params.getOrDefault("contactEmail", "1098974449@qq.com").toString();
|
|
||||||
|
|
||||||
// 从缓存获取问卷模板
|
|
||||||
List<Map<String, Object>> questionTemplate = getQuestionTemplate(productId);
|
|
||||||
|
|
||||||
// 解析出行人问卷答案
|
|
||||||
List<List<CtripDistBookRequest.QuestionAnswer>> passengerAnswers =
|
|
||||||
parsePassengerAnswers(params, questionTemplate);
|
|
||||||
|
|
||||||
// quantity 独立于出行人数量
|
|
||||||
int quantity = params.get("quantity") != null
|
|
||||||
? Integer.parseInt(params.get("quantity").toString())
|
|
||||||
: passengerAnswers.size();
|
|
||||||
|
|
||||||
String useDate = params.getOrDefault("useDate",
|
|
||||||
LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))).toString();
|
|
||||||
|
|
||||||
String distributorOrderId = "TEST_" + System.currentTimeMillis();
|
|
||||||
CtripDistBookRequest request = buildTestBookRequest(
|
|
||||||
distributorOrderId, productId, packageId, resourceId,
|
|
||||||
price, quantity, useDate, contactName, contactMobile, contactEmail,
|
|
||||||
passengerAnswers);
|
|
||||||
|
|
||||||
log.info("下单请求 distributorOrderId: {}, 购买数量: {}, 出行人数: {}",
|
|
||||||
distributorOrderId, quantity, passengerAnswers.size());
|
|
||||||
CtripDistBookResponse response = ctripDistApiService.createOrder(request);
|
|
||||||
log.info("创建订单返回: success={}, orderId={}", response.isSuccess(),
|
|
||||||
response.getData() != null ? response.getData().getOrderId() : "null");
|
|
||||||
return Result.succeed(response, "创建订单调用完成");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("创建携程订单失败", e);
|
|
||||||
return Result.failed("创建携程订单失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试创建携程订单(直接传完整请求体)
|
|
||||||
* 用途:如果需要精确控制所有字段,直接传CtripDistBookRequest JSON
|
|
||||||
*
|
|
||||||
* 调用示例:POST /ctrip/dist/test/book/raw
|
|
||||||
* Body: 完整的CtripDistBookRequest JSON
|
|
||||||
*/
|
|
||||||
@PostMapping("/book/raw")
|
|
||||||
@Operation(summary = "3.创建携程订单(原始请求体)")
|
|
||||||
public Result<CtripDistBookResponse> testCreateOrderRaw(@RequestBody CtripDistBookRequest request) {
|
|
||||||
log.info("===== 测试创建携程订单(raw),distributorOrderID: {} =====", request.getDistributorOrderID());
|
|
||||||
try {
|
|
||||||
CtripDistBookResponse response = ctripDistApiService.createOrder(request);
|
|
||||||
log.info("创建订单返回: success={}", response.isSuccess());
|
|
||||||
return Result.succeed(response, "创建订单调用完成");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("创建携程订单失败", e);
|
|
||||||
return Result.failed("创建携程订单失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 4. 可退检查 ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试取消验证(可退检查)
|
|
||||||
* 用途:检查某个携程订单是否可以取消/退订
|
|
||||||
* 需要先通过接口3创建订单获得ctripOrderId
|
|
||||||
*
|
|
||||||
* 调用示例:GET /ctrip/dist/test/cancel-verify?ctripOrderId=123456789
|
|
||||||
*/
|
|
||||||
@GetMapping("/cancel-verify")
|
|
||||||
@Operation(summary = "4.可退检查")
|
|
||||||
public Result<CtripDistCancelVerifyResponse> testCancelVerify(@RequestParam Long ctripOrderId) {
|
|
||||||
log.info("===== 测试取消验证,ctripOrderId: {} =====", ctripOrderId);
|
|
||||||
try {
|
|
||||||
CtripDistCancelVerifyResponse response = ctripDistApiService.cancelVerify(ctripOrderId);
|
|
||||||
log.info("取消验证返回: success={}, cancelVerifyStatus={}",
|
|
||||||
response.isSuccess(),
|
|
||||||
response.getCancelVerifyData() != null
|
|
||||||
? response.getCancelVerifyData().getCancelVerifyStatus() : "null");
|
|
||||||
return Result.succeed(response, "取消验证调用完成");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("取消验证失败,ctripOrderId: {}", ctripOrderId, e);
|
|
||||||
return Result.failed("取消验证失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 5. 退订(全部退订) ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试退订(全部取消订单)
|
|
||||||
* 用途:取消携程订单,需先通过接口4确认可退
|
|
||||||
*
|
|
||||||
* 调用示例:POST /ctrip/dist/test/cancel?ctripOrderId=123456789&reason=测试退订
|
|
||||||
*/
|
|
||||||
@PostMapping("/cancel")
|
|
||||||
@Operation(summary = "5.退订(全部取消订单)")
|
|
||||||
public Result<CtripDistCancelResponse> testCancelOrder(
|
|
||||||
@RequestParam Long ctripOrderId,
|
|
||||||
@RequestParam(defaultValue = "沙箱测试退订") String reason) {
|
|
||||||
log.info("===== 测试全部退订,ctripOrderId: {}, reason: {} =====", ctripOrderId, reason);
|
|
||||||
try {
|
|
||||||
CtripDistCancelResponse response = ctripDistApiService.cancelOrder(ctripOrderId, reason);
|
|
||||||
log.info("退订返回: success={}", response.isSuccess());
|
|
||||||
return Result.succeed(response, "退订调用完成");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("退订失败,ctripOrderId: {}", ctripOrderId, e);
|
|
||||||
return Result.failed("退订失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 5.5 部分退订 ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试部分退订
|
|
||||||
* 用途:部分取消携程订单(如购买2张退1张),需先通过接口4确认可部分退
|
|
||||||
*
|
|
||||||
* 调用示例:POST /ctrip/dist/test/cancel-partial
|
|
||||||
* Body:
|
|
||||||
* {
|
|
||||||
* "ctripOrderId": 123456789,
|
|
||||||
* "reason": "沙箱测试部分退订",
|
|
||||||
* "cancelOrderItems": [
|
|
||||||
* {
|
|
||||||
* "itemID": 1001,
|
|
||||||
* "quantity": 1
|
|
||||||
* }
|
|
||||||
* ]
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
@PostMapping("/cancel-partial")
|
|
||||||
@Operation(summary = "5.5 部分退订")
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Result<CtripDistCancelResponse> testCancelOrderPartial(@RequestBody Map<String, Object> params) {
|
|
||||||
Long ctripOrderId = Long.valueOf(params.get("ctripOrderId").toString());
|
|
||||||
String reason = params.getOrDefault("reason", "沙箱测试部分退订").toString();
|
|
||||||
List<Map<String, Object>> cancelOrderItems = (List<Map<String, Object>>) params.get("cancelOrderItems");
|
|
||||||
log.info("===== 测试部分退订,ctripOrderId: {}, reason: {}, cancelOrderItems: {} =====",
|
|
||||||
ctripOrderId, reason, cancelOrderItems);
|
|
||||||
try {
|
|
||||||
CtripDistCancelResponse response = ctripDistApiService.cancelOrderPartial(ctripOrderId, reason, cancelOrderItems);
|
|
||||||
log.info("部分退订返回: success={}", response.isSuccess());
|
|
||||||
return Result.succeed(response, "部分退订调用完成");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("部分退订失败,ctripOrderId: {}", ctripOrderId, e);
|
|
||||||
return Result.failed("部分退订失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 6. 订单详情 ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试查询携程订单详情
|
|
||||||
* 用途:根据携程订单ID查询订单状态和详细信息
|
|
||||||
*
|
|
||||||
* 调用示例:GET /ctrip/dist/test/booking-detail?ctripOrderId=123456789
|
|
||||||
*/
|
|
||||||
@GetMapping("/booking-detail")
|
|
||||||
@Operation(summary = "6.携程订单详情")
|
|
||||||
public Result<CtripDistBookingDetailResponse> testBookingDetail(@RequestParam Long ctripOrderId) {
|
|
||||||
log.info("===== 测试查询订单详情,ctripOrderId: {} =====", ctripOrderId);
|
|
||||||
try {
|
|
||||||
CtripDistBookingDetailResponse response = ctripDistApiService.getOrderDetail(ctripOrderId);
|
|
||||||
log.info("订单详情返回: success={}, orderStatus={}",
|
|
||||||
response.isSuccess(),
|
|
||||||
response.getData() != null && response.getData().getOrder() != null
|
|
||||||
? response.getData().getOrder().getOrderStatus() : "null");
|
|
||||||
return Result.succeed(response, "查询订单详情完成");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询订单详情失败,ctripOrderId: {}", ctripOrderId, e);
|
|
||||||
return Result.failed("查询订单详情失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 7. 沙箱-模拟携程发起退订(Part M 11.2) ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 模拟携程侧发起退订
|
|
||||||
* 用途:沙箱测试时模拟携程侧退订(非分销商发起),退订后可调接口6查看订单状态
|
|
||||||
*
|
|
||||||
* 整单退示例:POST /ctrip/dist/test/simulate-cancel
|
|
||||||
* Body: {"orderId": "1128170608930095"}
|
|
||||||
*
|
|
||||||
* 部分退示例(一张一人的订单,传clientId):
|
|
||||||
* Body:
|
|
||||||
* {
|
|
||||||
* "orderId": "1128170612314784",
|
|
||||||
* "quantity": 1,
|
|
||||||
* "clientInfoList": [
|
|
||||||
* {"clientId": "1756725089476701"}
|
|
||||||
* ]
|
|
||||||
* }
|
|
||||||
* 注意:clientId 从订单详情接口(接口6)返回的出行人 P_CLIENTID 获取
|
|
||||||
*/
|
|
||||||
@PostMapping("/simulate-cancel")
|
|
||||||
@Operation(summary = "7.沙箱-模拟携程发起退订")
|
|
||||||
public Result<Map<String, Object>> testSimulateCtripCancel(@RequestBody Map<String, Object> params) {
|
|
||||||
log.info("===== 沙箱-模拟携程发起退订,params: {} =====", params);
|
|
||||||
try {
|
|
||||||
Map<String, Object> response = ctripDistApiService.simulateCtripCancel(params);
|
|
||||||
log.info("模拟携程退订返回: {}", response);
|
|
||||||
return Result.succeed(response, "模拟携程退订调用完成");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("模拟携程退订失败", e);
|
|
||||||
return Result.failed("模拟携程退订失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 8. 沙箱-人工出票/退订确认/退订拒绝/凭证变更(Part M 11.3) ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 沙箱测试-人工出票/退订确认/退订拒绝/凭证变更
|
|
||||||
* 用途:对卡在出票中/退订中的订单进行人工操作
|
|
||||||
*
|
|
||||||
* type说明:
|
|
||||||
* 1 = 人工出票(对卡在出票中或需人工确认的订单)
|
|
||||||
* 2 = 退订确认(对卡在退订中的订单)
|
|
||||||
* 3 = 退订拒绝(模拟携程侧拒绝退订)
|
|
||||||
* 4 = 凭证变更
|
|
||||||
*
|
|
||||||
* 调用示例:POST /ctrip/dist/test/simulate-confirm
|
|
||||||
* Body: {"orderId": "1128170612557359", "type": 1}
|
|
||||||
*/
|
|
||||||
@PostMapping("/simulate-confirm")
|
|
||||||
@Operation(summary = "8.沙箱-人工出票/退订确认/退订拒绝/凭证变更")
|
|
||||||
public Result<Map<String, Object>> testSimulateConfirm(@RequestBody Map<String, Object> params) {
|
|
||||||
Object type = params.get("type");
|
|
||||||
String[] typeNames = {"", "人工出票", "退订确认", "退订拒绝", "凭证变更"};
|
|
||||||
String typeName = type != null && Integer.parseInt(type.toString()) >= 1 && Integer.parseInt(type.toString()) <= 4
|
|
||||||
? typeNames[Integer.parseInt(type.toString())] : "未知类型";
|
|
||||||
log.info("===== 沙箱-{},params: {} =====", typeName, params);
|
|
||||||
try {
|
|
||||||
Map<String, Object> response = ctripDistApiService.simulateConfirm(params);
|
|
||||||
log.info("沙箱-{}返回: {}", typeName, response);
|
|
||||||
return Result.succeed(response, typeName + "调用完成");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("沙箱-{}失败", typeName, e);
|
|
||||||
return Result.failed(typeName + "失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 辅助方法 ====================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从缓存获取产品的问卷模板
|
|
||||||
* 如果未缓存,提示用户先调用接口2
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private List<Map<String, Object>> getQuestionTemplate(Long productId) {
|
|
||||||
Map<String, Object> bookInfo = bookInfoCache.get(productId);
|
|
||||||
if (bookInfo == null) {
|
|
||||||
throw new RuntimeException("productId=" + productId + " 的bookInfo未缓存,请先调用接口2(GET /ctrip/dist/test/book-info)");
|
|
||||||
}
|
|
||||||
return extractQuestionTemplate(bookInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从 bookInfo 响应中提取问卷模板列表
|
|
||||||
* bookInfo 结构: { success: true, data: { passengerQuestionList: [...] } }
|
|
||||||
* 每个问卷项: { questionID: 3, questionCode: "P_NAME", questionTitle: "UserName", ... }
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private List<Map<String, Object>> extractQuestionTemplate(Map<String, Object> bookInfo) {
|
|
||||||
if (bookInfo == null || bookInfo.get("data") == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
Map<String, Object> data = (Map<String, Object>) bookInfo.get("data");
|
|
||||||
Object questionList = data.get("passengerQuestionList");
|
|
||||||
if (questionList instanceof List) {
|
|
||||||
return (List<Map<String, Object>>) questionList;
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析出行人问卷答案
|
|
||||||
*
|
|
||||||
* passengers中每个出行人是一个Map,key为questionCode,value为答案值
|
|
||||||
* 示例: {"P_FIRSTCNAME": "Chao", "P_LASTCNAME": "Du"}
|
|
||||||
*
|
|
||||||
* 系统自动从缓存的问卷模板中匹配questionID和questionTitle
|
|
||||||
*
|
|
||||||
* 如果没有传passengers,则返回空的单个出行人(无问卷答案)
|
|
||||||
*
|
|
||||||
* @param params 请求参数
|
|
||||||
* @param questionTemplate 从bookInfo缓存中获取的问卷模板
|
|
||||||
* @return 每个出行人的问卷答案列表
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private List<List<CtripDistBookRequest.QuestionAnswer>> parsePassengerAnswers(
|
|
||||||
Map<String, Object> params, List<Map<String, Object>> questionTemplate) {
|
|
||||||
|
|
||||||
List<List<CtripDistBookRequest.QuestionAnswer>> result = new ArrayList<>();
|
|
||||||
Object passengersObj = params.get("passengers");
|
|
||||||
|
|
||||||
if (passengersObj instanceof List) {
|
|
||||||
List<Map<String, Object>> passengers = (List<Map<String, Object>>) passengersObj;
|
|
||||||
// 构建 questionCode → 模板 的映射
|
|
||||||
// 携程返回的字段名是 "code"(不是 "questionCode")
|
|
||||||
Map<String, Map<String, Object>> templateMap = new LinkedHashMap<>();
|
|
||||||
for (Map<String, Object> q : questionTemplate) {
|
|
||||||
String code = getFieldValue(q, "code", "questionCode");
|
|
||||||
if (code != null) {
|
|
||||||
templateMap.put(code, q);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map<String, Object> passengerMap : passengers) {
|
|
||||||
List<CtripDistBookRequest.QuestionAnswer> answers = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, Object> entry : passengerMap.entrySet()) {
|
|
||||||
String questionCode = entry.getKey();
|
|
||||||
String answerValue = entry.getValue() != null ? entry.getValue().toString() : "";
|
|
||||||
|
|
||||||
// 从模板匹配 questionID 和 questionTitle
|
|
||||||
Map<String, Object> template = templateMap.get(questionCode);
|
|
||||||
if (template != null) {
|
|
||||||
CtripDistBookRequest.QuestionAnswer answer = new CtripDistBookRequest.QuestionAnswer();
|
|
||||||
answer.setQuestionID(Long.valueOf(template.get("questionID").toString()));
|
|
||||||
answer.setQuestionCode(questionCode);
|
|
||||||
String title = getFieldValue(template, "title", "questionTitle");
|
|
||||||
answer.setQuestionTitle(title != null ? title : "");
|
|
||||||
answer.setAnswerList(Collections.singletonList(answerValue));
|
|
||||||
answers.add(answer);
|
|
||||||
} else {
|
|
||||||
log.warn("questionCode={} 在问卷模板中未找到,跳过", questionCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.add(answers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.isEmpty()) {
|
|
||||||
// 没有传passengers,返回一个无答案的出行人
|
|
||||||
result.add(new ArrayList<>());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建测试下单请求(通用版)
|
|
||||||
*
|
|
||||||
* @param passengerAnswers 每个出行人的问卷答案(从parsePassengerAnswers得到)
|
|
||||||
* @param quantity 购买数量(与出行人数量解耦)
|
|
||||||
* @param useDate 使用日期
|
|
||||||
*/
|
|
||||||
private CtripDistBookRequest buildTestBookRequest(String distributorOrderId, Long productId,
|
|
||||||
Long packageId, Long resourceId,
|
|
||||||
BigDecimal price, int quantity,
|
|
||||||
String useDate,
|
|
||||||
String contactName, String contactMobile,
|
|
||||||
String contactEmail,
|
|
||||||
List<List<CtripDistBookRequest.QuestionAnswer>> passengerAnswers) {
|
|
||||||
CtripDistBookRequest request = new CtripDistBookRequest();
|
|
||||||
request.setLocale("zh-CN");
|
|
||||||
request.setCurrency("CNY");
|
|
||||||
request.setDistributorOrderID(distributorOrderId);
|
|
||||||
|
|
||||||
// 联系人
|
|
||||||
CtripDistBookRequest.Contact contact = new CtripDistBookRequest.Contact();
|
|
||||||
contact.setName(contactName);
|
|
||||||
CtripDistBookRequest.Mobile mobile = new CtripDistBookRequest.Mobile();
|
|
||||||
mobile.setInternationalTelephoneCode("86");
|
|
||||||
mobile.setMobileNumber(contactMobile);
|
|
||||||
contact.setMobile(mobile);
|
|
||||||
contact.setEmail(contactEmail);
|
|
||||||
request.setContact(contact);
|
|
||||||
|
|
||||||
// 为每个出行人构建Passenger对象
|
|
||||||
List<CtripDistBookRequest.Passenger> passengerList = new ArrayList<>();
|
|
||||||
for (List<CtripDistBookRequest.QuestionAnswer> answers : passengerAnswers) {
|
|
||||||
CtripDistBookRequest.Passenger passenger = new CtripDistBookRequest.Passenger();
|
|
||||||
passenger.setPackageID(packageId);
|
|
||||||
passenger.setResourceID(resourceId);
|
|
||||||
passenger.setQuestionAnswerList(answers);
|
|
||||||
passengerList.add(passenger);
|
|
||||||
}
|
|
||||||
request.setPassengerList(passengerList);
|
|
||||||
|
|
||||||
// 订单资源
|
|
||||||
CtripDistBookRequest.OrderResource orderResource = new CtripDistBookRequest.OrderResource();
|
|
||||||
orderResource.setResourceID(resourceId);
|
|
||||||
orderResource.setUseDate(useDate);
|
|
||||||
orderResource.setQuantity(quantity);
|
|
||||||
orderResource.setPrice(price);
|
|
||||||
|
|
||||||
// 基本订单信息
|
|
||||||
BigDecimal totalAmount = price.multiply(new BigDecimal(quantity));
|
|
||||||
CtripDistBookRequest.BasicOrder basicOrder = new CtripDistBookRequest.BasicOrder();
|
|
||||||
basicOrder.setProductID(productId);
|
|
||||||
basicOrder.setAmount(totalAmount);
|
|
||||||
basicOrder.setPackageID(packageId);
|
|
||||||
basicOrder.setOrderResourceList(Collections.singletonList(orderResource));
|
|
||||||
request.setBasicOrder(basicOrder);
|
|
||||||
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从Map中按优先级获取字段值
|
|
||||||
* 携程接口返回的字段名可能与文档不一致(如 "code" vs "questionCode","title" vs "questionTitle")
|
|
||||||
*/
|
|
||||||
private String getFieldValue(Map<String, Object> map, String... keys) {
|
|
||||||
for (String key : keys) {
|
|
||||||
Object val = map.get(key);
|
|
||||||
if (val != null) {
|
|
||||||
return val.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-421
@@ -1,421 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.model.CtripPayPreOrderConfirmRequest;
|
|
||||||
import com.central.coupon.model.CtripPayPreOrderConfirmResponse;
|
|
||||||
import com.central.coupon.service.ICtripPayPreOrderConfirmService;
|
|
||||||
import com.central.coupon.util.CtripDecryptUtil;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程支付确认控制器
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coupon/ctrip/confirm")
|
|
||||||
public class CtripPayPreOrderConfirmController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ICtripPayPreOrderConfirmService payPreOrderConfirmService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripDecryptUtil ctripDecryptUtil;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
@Value("${ctrip.account.id}")
|
|
||||||
private String ctripAccountId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理支付确认请求
|
|
||||||
*/
|
|
||||||
@PostMapping("/pay")
|
|
||||||
public CtripPayPreOrderConfirmResponse processPayPreOrderConfirm(@RequestBody Map<String, Object> requestMap,
|
|
||||||
HttpServletRequest request) {
|
|
||||||
String clientIp = getClientIp(request);
|
|
||||||
log.info("收到携程支付确认请求,IP: {}", clientIp);
|
|
||||||
log.info("请求URL: {}", request.getRequestURL());
|
|
||||||
log.info("请求URI: {}", request.getRequestURI());
|
|
||||||
log.info("请求方法: {}", request.getMethod());
|
|
||||||
log.info("请求体类型: {}", requestMap.getClass().getSimpleName());
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. 解析请求体
|
|
||||||
CtripPayPreOrderConfirmRequest ctripRequest = parseRequest(requestMap);
|
|
||||||
if (ctripRequest == null) {
|
|
||||||
log.error("解析支付确认请求失败");
|
|
||||||
return buildErrorResponse("0001", "请求解析失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 验证签名
|
|
||||||
if (!validateSignature(ctripRequest)) {
|
|
||||||
log.error("支付确认请求签名验证失败");
|
|
||||||
return buildErrorResponse("0001", "签名验证失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 处理业务逻辑
|
|
||||||
CtripPayPreOrderConfirmResponse response = payPreOrderConfirmService.processPayPreOrderConfirm(
|
|
||||||
ctripRequest.getHeader(), ctripRequest.getBody());
|
|
||||||
|
|
||||||
log.info("携程支付确认处理完成,otaOrderId: {}",
|
|
||||||
ctripRequest.getBody() != null ? ctripRequest.getBody().getOtaOrderId() : "unknown");
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理携程支付确认请求异常", e);
|
|
||||||
return buildErrorResponse("1100", "处理请求异常:" + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 手动调用支付确认接口(用于测试)
|
|
||||||
*/
|
|
||||||
@PostMapping("/manual")
|
|
||||||
public CtripPayPreOrderConfirmResponse manualPayPreOrderConfirm(@RequestBody Map<String, Object> requestMap,
|
|
||||||
HttpServletRequest request) {
|
|
||||||
String clientIp = getClientIp(request);
|
|
||||||
log.info("=== 收到手动支付确认请求(测试接口) ===");
|
|
||||||
log.info("IP: {}", clientIp);
|
|
||||||
log.info("请求URL: {}", request.getRequestURL());
|
|
||||||
log.info("请求URI: {}", request.getRequestURI());
|
|
||||||
log.info("请求方法: {}", request.getMethod());
|
|
||||||
log.info("请求体类型: {}", requestMap.getClass().getSimpleName());
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. 解析请求体
|
|
||||||
CtripPayPreOrderConfirmRequest ctripRequest = parseRequest(requestMap);
|
|
||||||
if (ctripRequest == null) {
|
|
||||||
log.error("解析支付确认请求失败");
|
|
||||||
return buildErrorResponse("0001", "请求解析失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 验证签名(手动调用时可选)
|
|
||||||
boolean signatureValid = validateSignature(ctripRequest);
|
|
||||||
if (!signatureValid) {
|
|
||||||
log.warn("签名验证失败,但继续处理(手动调用模式)");
|
|
||||||
} else {
|
|
||||||
log.info("签名验证通过");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 处理业务逻辑
|
|
||||||
CtripPayPreOrderConfirmResponse response = payPreOrderConfirmService.processPayPreOrderConfirm(
|
|
||||||
ctripRequest.getHeader(), ctripRequest.getBody());
|
|
||||||
|
|
||||||
log.info("=== 手动支付确认处理完成 ===");
|
|
||||||
log.info("otaOrderId: {}",
|
|
||||||
ctripRequest.getBody() != null ? ctripRequest.getBody().getOtaOrderId() : "unknown");
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理手动支付确认请求异常", e);
|
|
||||||
return buildErrorResponse("1100", "处理请求异常:" + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 简化手动调用接口(无需签名验证)
|
|
||||||
*/
|
|
||||||
@PostMapping("/simple")
|
|
||||||
public CtripPayPreOrderConfirmResponse simplePayPreOrderConfirm(@RequestBody Map<String, Object> requestMap,
|
|
||||||
HttpServletRequest request) {
|
|
||||||
String clientIp = getClientIp(request);
|
|
||||||
log.info("=== 收到简化支付确认请求(测试接口) ===");
|
|
||||||
log.info("IP: {}", clientIp);
|
|
||||||
log.info("请求体: {}", requestMap);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 直接构建请求对象,跳过签名验证
|
|
||||||
CtripPayPreOrderConfirmRequest ctripRequest = new CtripPayPreOrderConfirmRequest();
|
|
||||||
|
|
||||||
// 构建header
|
|
||||||
CtripPayPreOrderConfirmRequest.CtripHeader header = new CtripPayPreOrderConfirmRequest.CtripHeader();
|
|
||||||
header.setAccountId(ctripAccountId);
|
|
||||||
header.setServiceName("PayPreOrderConfirm");
|
|
||||||
header.setRequestTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
||||||
header.setVersion("1.0");
|
|
||||||
header.setSign("manual_test_sign");
|
|
||||||
ctripRequest.setHeader(header);
|
|
||||||
|
|
||||||
// 构建body
|
|
||||||
CtripPayPreOrderConfirmRequest.CtripPayPreOrderConfirmBody body =
|
|
||||||
objectMapper.convertValue(requestMap, CtripPayPreOrderConfirmRequest.CtripPayPreOrderConfirmBody.class);
|
|
||||||
ctripRequest.setBody(body);
|
|
||||||
|
|
||||||
// 3. 处理业务逻辑
|
|
||||||
CtripPayPreOrderConfirmResponse response = payPreOrderConfirmService.processPayPreOrderConfirm(header, body);
|
|
||||||
|
|
||||||
log.info("=== 简化支付确认处理完成 ===");
|
|
||||||
log.info("otaOrderId: {}", body.getOtaOrderId());
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理简化支付确认请求异常", e);
|
|
||||||
return buildErrorResponse("1100", "处理请求异常:" + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建加密+签名后的请求(生成给Postman使用)
|
|
||||||
* 入参格式:{"accountId":"...","version":"1.0","requestTime":"可选,默认当前","body":{...明文body...}}
|
|
||||||
*/
|
|
||||||
@PostMapping("/buildPayload")
|
|
||||||
public Map<String, Object> buildEncryptedSignedPayload(@RequestBody Map<String, Object> payload) {
|
|
||||||
try {
|
|
||||||
String accountId = (String) payload.getOrDefault("accountId", ctripAccountId);
|
|
||||||
String version = (String) payload.getOrDefault("version", "1.0");
|
|
||||||
String requestTime = (String) payload.getOrDefault(
|
|
||||||
"requestTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
||||||
Object bodyObj = payload.get("body");
|
|
||||||
if (bodyObj == null) {
|
|
||||||
throw new IllegalArgumentException("body不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证body中的必需字段
|
|
||||||
if (bodyObj instanceof Map) {
|
|
||||||
Map<String, Object> bodyMap = (Map<String, Object>) bodyObj;
|
|
||||||
|
|
||||||
// 检查必需字段
|
|
||||||
String[] requiredFields = {"sequenceId", "otaOrderId", "supplierOrderId", "confirmResultCode", "confirmResultMessage"};
|
|
||||||
for (String field : requiredFields) {
|
|
||||||
if (!bodyMap.containsKey(field) || bodyMap.get(field) == null ||
|
|
||||||
(bodyMap.get(field) instanceof String && ((String) bodyMap.get(field)).trim().isEmpty())) {
|
|
||||||
throw new IllegalArgumentException("body中缺少必需字段或字段为空: " + field);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 特殊检查sequenceId格式
|
|
||||||
String sequenceId = (String) bodyMap.get("sequenceId");
|
|
||||||
if (sequenceId != null && sequenceId.length() < 40) {
|
|
||||||
log.warn("sequenceId长度可能不符合要求,建议格式:yyyyMMdd + 32位GUID,当前长度: {}", sequenceId.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("验证通过,sequenceId: {}, otaOrderId: {}, supplierOrderId: {}",
|
|
||||||
sequenceId, bodyMap.get("otaOrderId"), bodyMap.get("supplierOrderId"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 固定服务名
|
|
||||||
String serviceName = "PayPreOrderConfirm";
|
|
||||||
// 序列化 body 为 JSON
|
|
||||||
String bodyJson = objectMapper.writeValueAsString(bodyObj);
|
|
||||||
log.info("序列化后的body JSON: {}", bodyJson);
|
|
||||||
|
|
||||||
// 加密 body
|
|
||||||
String encryptedBody = ctripDecryptUtil.encryptAES(bodyJson);
|
|
||||||
if (encryptedBody == null) {
|
|
||||||
throw new IllegalStateException("加密失败");
|
|
||||||
}
|
|
||||||
log.info("加密后的body长度: {}", encryptedBody.length());
|
|
||||||
|
|
||||||
// 生成 sign(注意使用加密后的 body)
|
|
||||||
String sign = ctripDecryptUtil.generateSign(accountId, serviceName, requestTime, encryptedBody, version);
|
|
||||||
if (sign == null) {
|
|
||||||
throw new IllegalStateException("签名失败");
|
|
||||||
}
|
|
||||||
log.info("生成的签名: {}", sign);
|
|
||||||
|
|
||||||
// 组装返回
|
|
||||||
Map<String, Object> header = new HashMap<>();
|
|
||||||
header.put("accountId", accountId);
|
|
||||||
header.put("serviceName", serviceName);
|
|
||||||
header.put("requestTime", requestTime);
|
|
||||||
header.put("version", version);
|
|
||||||
header.put("sign", sign);
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("header", header);
|
|
||||||
result.put("body", encryptedBody);
|
|
||||||
// 便于核对:透传明文 body
|
|
||||||
result.put("plainBody", bodyObj);
|
|
||||||
return result;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("构建加密签名请求失败", e);
|
|
||||||
Map<String, Object> err = new HashMap<>();
|
|
||||||
err.put("error", e.getMessage());
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析请求体
|
|
||||||
*/
|
|
||||||
private CtripPayPreOrderConfirmRequest parseRequest(Map<String, Object> requestMap) {
|
|
||||||
try {
|
|
||||||
log.info("请求体内容: {}", requestMap);
|
|
||||||
|
|
||||||
if (requestMap == null || requestMap.isEmpty()) {
|
|
||||||
log.warn("请求体为空");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否包含header和body
|
|
||||||
if (!requestMap.containsKey("header") || !requestMap.containsKey("body")) {
|
|
||||||
log.warn("请求体格式不正确,缺少header或body");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> headerMap = (Map<String, Object>) requestMap.get("header");
|
|
||||||
Object bodyObj = requestMap.get("body");
|
|
||||||
|
|
||||||
log.info("字段: header = {}", headerMap);
|
|
||||||
log.info("字段: body = {}", bodyObj);
|
|
||||||
|
|
||||||
// 构建请求对象
|
|
||||||
CtripPayPreOrderConfirmRequest request = new CtripPayPreOrderConfirmRequest();
|
|
||||||
|
|
||||||
// 设置header
|
|
||||||
CtripPayPreOrderConfirmRequest.CtripHeader header = objectMapper.convertValue(headerMap,
|
|
||||||
CtripPayPreOrderConfirmRequest.CtripHeader.class);
|
|
||||||
request.setHeader(header);
|
|
||||||
|
|
||||||
// 检查body是否为加密字符串
|
|
||||||
if (bodyObj instanceof String) {
|
|
||||||
String encryptedBody = (String) bodyObj;
|
|
||||||
log.info("body是加密字符串,长度: {}", encryptedBody.length());
|
|
||||||
|
|
||||||
// 保存原始加密body用于签名验证
|
|
||||||
request.setOriginalEncryptedBody(encryptedBody);
|
|
||||||
|
|
||||||
// 解密body
|
|
||||||
String decryptedBody = ctripDecryptUtil.decryptAES(encryptedBody);
|
|
||||||
if (decryptedBody == null) {
|
|
||||||
log.error("解密body失败");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("解密成功,解密后body长度: {}", decryptedBody.length());
|
|
||||||
log.info("解密后body内容: {}", decryptedBody);
|
|
||||||
|
|
||||||
// 解析解密后的body
|
|
||||||
Map<String, Object> bodyMap = objectMapper.readValue(decryptedBody, Map.class);
|
|
||||||
log.info("解析body成功,新的请求体: {}", bodyMap);
|
|
||||||
|
|
||||||
// 设置body
|
|
||||||
CtripPayPreOrderConfirmRequest.CtripPayPreOrderConfirmBody body = objectMapper.convertValue(bodyMap,
|
|
||||||
CtripPayPreOrderConfirmRequest.CtripPayPreOrderConfirmBody.class);
|
|
||||||
request.setBody(body);
|
|
||||||
|
|
||||||
log.info("检测到携程加密请求格式");
|
|
||||||
return request;
|
|
||||||
|
|
||||||
} else if (bodyObj instanceof Map) {
|
|
||||||
// body是JSON对象(明文格式)
|
|
||||||
log.info("body是JSON对象格式(明文)");
|
|
||||||
|
|
||||||
// 设置body
|
|
||||||
CtripPayPreOrderConfirmRequest.CtripPayPreOrderConfirmBody body = objectMapper.convertValue(bodyObj,
|
|
||||||
CtripPayPreOrderConfirmRequest.CtripPayPreOrderConfirmBody.class);
|
|
||||||
request.setBody(body);
|
|
||||||
|
|
||||||
// 对于明文格式,需要将body序列化为JSON字符串用于签名验证
|
|
||||||
String bodyJson = objectMapper.writeValueAsString(bodyObj);
|
|
||||||
log.info("明文body JSON: {}", bodyJson);
|
|
||||||
|
|
||||||
// 加密body用于签名验证
|
|
||||||
String encryptedBody = ctripDecryptUtil.encryptAES(bodyJson);
|
|
||||||
if (encryptedBody != null) {
|
|
||||||
request.setOriginalEncryptedBody(encryptedBody);
|
|
||||||
log.info("明文body加密成功,用于签名验证");
|
|
||||||
} else {
|
|
||||||
log.warn("明文body加密失败,签名验证可能失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("检测到携程明文请求格式");
|
|
||||||
return request;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
log.warn("body格式不支持: {}", bodyObj.getClass().getSimpleName());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析支付确认请求异常", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证签名
|
|
||||||
*/
|
|
||||||
private boolean validateSignature(CtripPayPreOrderConfirmRequest request) {
|
|
||||||
try {
|
|
||||||
if (request.getHeader() == null) {
|
|
||||||
log.warn("请求头为空,无法验证签名");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String accountId = request.getHeader().getAccountId();
|
|
||||||
String serviceName = request.getHeader().getServiceName();
|
|
||||||
String requestTime = request.getHeader().getRequestTime();
|
|
||||||
String version = request.getHeader().getVersion();
|
|
||||||
String sign = request.getHeader().getSign();
|
|
||||||
|
|
||||||
if (accountId == null || serviceName == null || requestTime == null || version == null || sign == null) {
|
|
||||||
log.warn("签名验证参数不完整");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用原始加密body进行签名验证
|
|
||||||
String originalEncryptedBody = request.getOriginalEncryptedBody();
|
|
||||||
if (originalEncryptedBody == null) {
|
|
||||||
log.warn("原始加密body为空,无法验证签名");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String expectedSign = ctripDecryptUtil.generateSign(accountId, serviceName, requestTime,
|
|
||||||
originalEncryptedBody, version);
|
|
||||||
|
|
||||||
boolean isValid = sign.equals(expectedSign);
|
|
||||||
log.info("签名验证结果: {}, 期望签名: {}, 实际签名: {}", isValid, expectedSign, sign);
|
|
||||||
|
|
||||||
return isValid;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("验证签名异常", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取客户端IP
|
|
||||||
*/
|
|
||||||
private String getClientIp(HttpServletRequest request) {
|
|
||||||
String xForwardedFor = request.getHeader("X-Forwarded-For");
|
|
||||||
if (xForwardedFor != null && !xForwardedFor.isEmpty() && !"unknown".equalsIgnoreCase(xForwardedFor)) {
|
|
||||||
return xForwardedFor.split(",")[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
String xRealIp = request.getHeader("X-Real-IP");
|
|
||||||
if (xRealIp != null && !xRealIp.isEmpty() && !"unknown".equalsIgnoreCase(xRealIp)) {
|
|
||||||
return xRealIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return request.getRemoteAddr();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建错误响应
|
|
||||||
*/
|
|
||||||
private CtripPayPreOrderConfirmResponse buildErrorResponse(String resultCode, String resultMessage) {
|
|
||||||
CtripPayPreOrderConfirmResponse response = new CtripPayPreOrderConfirmResponse();
|
|
||||||
|
|
||||||
CtripPayPreOrderConfirmResponse.CtripResponseHeader header = new CtripPayPreOrderConfirmResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode(resultCode);
|
|
||||||
header.setResultMessage(resultMessage);
|
|
||||||
header.setVersion("1.0");
|
|
||||||
response.setHeader(header);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-200
@@ -1,200 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.model.CtripPayPreOrderRequest;
|
|
||||||
import com.central.coupon.model.CtripPayPreOrderResponse;
|
|
||||||
import com.central.coupon.service.CtripPayPreOrderService;
|
|
||||||
import com.central.coupon.util.CtripDecryptUtil;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程预下单支付控制器
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coupon/ctrip/pay")
|
|
||||||
public class CtripPayPreOrderController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripPayPreOrderService ctripPayPreOrderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripDecryptUtil ctripDecryptUtil;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理携程预下单支付请求
|
|
||||||
*/
|
|
||||||
@PostMapping("")
|
|
||||||
public CtripPayPreOrderResponse payPreOrder(@RequestBody Object requestBody, HttpServletRequest request) {
|
|
||||||
log.info("收到携程预下单支付请求,IP: {}", request.getRemoteAddr());
|
|
||||||
log.info("请求URL: {}", request.getRequestURL());
|
|
||||||
log.info("请求URI: {}", request.getRequestURI());
|
|
||||||
log.info("请求方法: {}", request.getMethod());
|
|
||||||
log.info("请求体类型: {}", requestBody.getClass().getSimpleName());
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 解析请求体
|
|
||||||
CtripPayPreOrderRequest ctripRequest = parseRequestBody(requestBody);
|
|
||||||
if (ctripRequest == null) {
|
|
||||||
log.error("解析请求体失败");
|
|
||||||
return buildErrorResponse("0001", "请求体解析失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证签名
|
|
||||||
if (!validateSignature(ctripRequest)) {
|
|
||||||
log.error("签名验证失败");
|
|
||||||
return buildErrorResponse("0002", "签名验证失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理预下单支付请求
|
|
||||||
return ctripPayPreOrderService.processPayPreOrderRequest(ctripRequest);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理携程预下单支付请求异常", e);
|
|
||||||
return buildErrorResponse("0003", "处理请求异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析请求体
|
|
||||||
*/
|
|
||||||
private CtripPayPreOrderRequest parseRequestBody(Object requestBody) {
|
|
||||||
try {
|
|
||||||
if (requestBody instanceof Map) {
|
|
||||||
// 如果已经是Map格式,直接转换
|
|
||||||
log.info("请求体已经是Map格式");
|
|
||||||
Map<String, Object> requestMap = (Map<String, Object>) requestBody;
|
|
||||||
log.info("请求体内容: {}", requestMap);
|
|
||||||
|
|
||||||
// 检查是否是携程标准请求格式
|
|
||||||
if (requestMap.containsKey("header") && requestMap.containsKey("body")) {
|
|
||||||
log.info("检测到携程标准请求格式(包含header和body)");
|
|
||||||
Object bodyObj = requestMap.get("body");
|
|
||||||
|
|
||||||
if (bodyObj instanceof String) {
|
|
||||||
// body是加密字符串
|
|
||||||
String encryptedBody = (String) bodyObj;
|
|
||||||
log.info("body是加密字符串,长度: {}", encryptedBody.length());
|
|
||||||
|
|
||||||
// 保存原始加密body用于签名验证
|
|
||||||
CtripPayPreOrderRequest request = new CtripPayPreOrderRequest();
|
|
||||||
request.setOriginalEncryptedBody(encryptedBody);
|
|
||||||
|
|
||||||
// 解密body
|
|
||||||
String decryptedBody = ctripDecryptUtil.decryptAES(encryptedBody);
|
|
||||||
if (decryptedBody == null) {
|
|
||||||
log.error("解密body失败");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("解密成功,解密后body长度: {}", decryptedBody.length());
|
|
||||||
log.info("解密后body内容: {}", decryptedBody);
|
|
||||||
|
|
||||||
// 解析header
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> headerMap = (Map<String, Object>) requestMap.get("header");
|
|
||||||
CtripPayPreOrderRequest.CtripRequestHeader header = objectMapper.convertValue(headerMap, CtripPayPreOrderRequest.CtripRequestHeader.class);
|
|
||||||
request.setHeader(header);
|
|
||||||
|
|
||||||
// 解析解密后的body
|
|
||||||
CtripPayPreOrderRequest.CtripPayPreOrderBody body = objectMapper.readValue(decryptedBody, CtripPayPreOrderRequest.CtripPayPreOrderBody.class);
|
|
||||||
request.setBody(body);
|
|
||||||
|
|
||||||
log.info("解析body成功,新的请求体: {}", body);
|
|
||||||
return request;
|
|
||||||
} else {
|
|
||||||
// body已经是对象
|
|
||||||
log.info("body已经是对象格式");
|
|
||||||
CtripPayPreOrderRequest request = new CtripPayPreOrderRequest();
|
|
||||||
|
|
||||||
// 解析header
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> headerMap = (Map<String, Object>) requestMap.get("header");
|
|
||||||
CtripPayPreOrderRequest.CtripRequestHeader header = objectMapper.convertValue(headerMap, CtripPayPreOrderRequest.CtripRequestHeader.class);
|
|
||||||
request.setHeader(header);
|
|
||||||
|
|
||||||
// 解析body
|
|
||||||
CtripPayPreOrderRequest.CtripPayPreOrderBody body = objectMapper.convertValue(bodyObj, CtripPayPreOrderRequest.CtripPayPreOrderBody.class);
|
|
||||||
request.setBody(body);
|
|
||||||
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 直接解析整个请求体
|
|
||||||
log.info("直接解析整个请求体");
|
|
||||||
return objectMapper.convertValue(requestBody, CtripPayPreOrderRequest.class);
|
|
||||||
}
|
|
||||||
} else if (requestBody instanceof String) {
|
|
||||||
// 如果是字符串,直接解析
|
|
||||||
log.info("请求体是字符串格式");
|
|
||||||
return objectMapper.readValue((String) requestBody, CtripPayPreOrderRequest.class);
|
|
||||||
} else {
|
|
||||||
// 其他格式,尝试直接转换
|
|
||||||
log.info("尝试直接转换请求体");
|
|
||||||
return objectMapper.convertValue(requestBody, CtripPayPreOrderRequest.class);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析请求体异常", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证签名
|
|
||||||
*/
|
|
||||||
private boolean validateSignature(CtripPayPreOrderRequest request) {
|
|
||||||
try {
|
|
||||||
if (request.getHeader() == null || request.getHeader().getSign() == null) {
|
|
||||||
log.error("请求头或签名为空");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String receivedSign = request.getHeader().getSign();
|
|
||||||
log.info("收到的签名: {}", receivedSign);
|
|
||||||
|
|
||||||
// 使用原始加密body计算签名
|
|
||||||
String originalEncryptedBody = request.getOriginalEncryptedBody();
|
|
||||||
if (originalEncryptedBody == null) {
|
|
||||||
log.error("原始加密body为空,无法验证签名");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String calculatedSign = ctripDecryptUtil.generateSign(
|
|
||||||
request.getHeader().getAccountId(),
|
|
||||||
request.getHeader().getServiceName(),
|
|
||||||
request.getHeader().getRequestTime(),
|
|
||||||
originalEncryptedBody,
|
|
||||||
request.getHeader().getVersion()
|
|
||||||
);
|
|
||||||
log.info("计算的签名: {}", calculatedSign);
|
|
||||||
|
|
||||||
boolean isValid = receivedSign.equals(calculatedSign);
|
|
||||||
log.info("签名验证结果: {}", isValid);
|
|
||||||
|
|
||||||
return isValid;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("验证签名异常", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建错误响应
|
|
||||||
*/
|
|
||||||
private CtripPayPreOrderResponse buildErrorResponse(String resultCode, String resultMessage) {
|
|
||||||
CtripPayPreOrderResponse response = new CtripPayPreOrderResponse();
|
|
||||||
CtripPayPreOrderResponse.CtripResponseHeader header = new CtripPayPreOrderResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode(resultCode);
|
|
||||||
header.setResultMessage(resultMessage);
|
|
||||||
response.setHeader(header);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-498
@@ -1,498 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
|
||||||
import com.central.coupon.model.CtripQueryOrderRequest;
|
|
||||||
import com.central.coupon.model.CtripQueryOrderResponse;
|
|
||||||
import com.central.coupon.service.ICtripQueryOrderService;
|
|
||||||
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.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单查询控制器
|
|
||||||
* 专门处理携程订单查询相关接口
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coupon/ctrip/query")
|
|
||||||
@Tag(name = "携程订单查询")
|
|
||||||
public class CtripQueryOrderController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ICtripQueryOrderService ctripQueryOrderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripDecryptUtil ctripDecryptUtil;
|
|
||||||
|
|
||||||
// 携程SDK配置参数(保持兼容但不使用硬编码默认值)
|
|
||||||
@Value("${ctrip.account.id}")
|
|
||||||
private String ctripAccountId;
|
|
||||||
|
|
||||||
@Value("${ctrip.aes.key:750e15a31356a99d}")
|
|
||||||
private String ctripAesKey;
|
|
||||||
|
|
||||||
@Value("${ctrip.aes.iv:087b36ad0dff7942}")
|
|
||||||
private String ctripAesIv;
|
|
||||||
|
|
||||||
@Value("${ctrip.account.secret:ce6033ae31124ec5cdab3d2bc79f2622}")
|
|
||||||
private String ctripAccountSecret;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单查询接口
|
|
||||||
* 携程调用此接口查询订单详细信息
|
|
||||||
*
|
|
||||||
* 请求格式:
|
|
||||||
* {
|
|
||||||
* "header": {
|
|
||||||
* "accountId": "c50a8f2a4a59c9e7",
|
|
||||||
* "serviceName": "QueryOrder",
|
|
||||||
* "requestTime": "2025-01-23 14:57:34",
|
|
||||||
* "version": "1.0",
|
|
||||||
* "sign": "md5签名"
|
|
||||||
* },
|
|
||||||
* "body": "加密的JSON字符串"
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
@Operation(summary = "携程订单查询接口")
|
|
||||||
@PostMapping("/order")
|
|
||||||
public CtripQueryOrderResponse queryOrder(@RequestBody Object requestBody,
|
|
||||||
jakarta.servlet.http.HttpServletRequest httpRequest) {
|
|
||||||
return processQueryOrderRequest(requestBody, httpRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理查询订单请求(内部方法,供统一接口调用)
|
|
||||||
*/
|
|
||||||
public CtripQueryOrderResponse processQueryOrderRequest(Object requestBody,
|
|
||||||
jakarta.servlet.http.HttpServletRequest httpRequest) {
|
|
||||||
log.info("收到携程订单查询请求,IP: {}", httpRequest.getRemoteAddr());
|
|
||||||
log.info("请求URL: {}", httpRequest.getRequestURL());
|
|
||||||
log.info("请求URI: {}", httpRequest.getRequestURI());
|
|
||||||
log.info("请求方法: {}", httpRequest.getMethod());
|
|
||||||
log.info("请求体类型: {}", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
|
|
||||||
CtripQueryOrderRequest request = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. 解析请求体
|
|
||||||
if (requestBody instanceof Map) {
|
|
||||||
Map<String, Object> requestMap = (Map<String, Object>) requestBody;
|
|
||||||
log.info("请求体内容: {}", requestMap);
|
|
||||||
|
|
||||||
// 检查是否是携程标准请求格式(包含header和body)
|
|
||||||
if (requestMap.containsKey("header") && requestMap.containsKey("body")) {
|
|
||||||
log.info("检测到携程标准请求格式(包含header和body)");
|
|
||||||
|
|
||||||
// 构建请求对象
|
|
||||||
request = new CtripQueryOrderRequest();
|
|
||||||
|
|
||||||
// 解析header
|
|
||||||
Map<String, Object> headerMap = (Map<String, Object>) requestMap.get("header");
|
|
||||||
CtripQueryOrderRequest.CtripHeader header = new CtripQueryOrderRequest.CtripHeader();
|
|
||||||
header.setAccountId((String) headerMap.get("accountId"));
|
|
||||||
header.setServiceName((String) headerMap.get("serviceName"));
|
|
||||||
header.setRequestTime((String) headerMap.get("requestTime"));
|
|
||||||
header.setVersion((String) headerMap.get("version"));
|
|
||||||
header.setSign((String) headerMap.get("sign"));
|
|
||||||
request.setHeader(header);
|
|
||||||
|
|
||||||
// 处理body
|
|
||||||
Object bodyObj = requestMap.get("body");
|
|
||||||
if (bodyObj instanceof String) {
|
|
||||||
// body是加密字符串,需要解密
|
|
||||||
String encryptedBody = (String) bodyObj;
|
|
||||||
log.info("body是加密字符串,长度: {}", encryptedBody.length());
|
|
||||||
|
|
||||||
// 保存原始的加密body用于签名验证
|
|
||||||
request.setOriginalEncryptedBody(encryptedBody);
|
|
||||||
|
|
||||||
String decryptedBody = ctripDecryptUtil.decryptAES(encryptedBody);
|
|
||||||
if (decryptedBody == null) {
|
|
||||||
log.error("解密body失败");
|
|
||||||
return buildErrorResponse("0001", "解密body失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("解密成功,解密后body长度: {}", decryptedBody.length());
|
|
||||||
log.info("解密后body内容: {}", decryptedBody);
|
|
||||||
|
|
||||||
request.setBody(decryptedBody);
|
|
||||||
} else {
|
|
||||||
// body已经是对象
|
|
||||||
request.setBody(bodyObj);
|
|
||||||
log.info("body已经是对象格式");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("请求格式不正确,缺少header或body字段");
|
|
||||||
return buildErrorResponse("0001", "请求格式不正确");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("未知的请求体类型:{}", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
return buildErrorResponse("0001", "未知的请求体类型");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 验证服务名称
|
|
||||||
if (!"QueryOrder".equals(request.getHeader().getServiceName())) {
|
|
||||||
log.error("服务名称不正确: {}", request.getHeader().getServiceName());
|
|
||||||
return buildErrorResponse("0002", "服务名称不正确");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 验证账号
|
|
||||||
if (!validateAccountId(request.getHeader().getAccountId())) {
|
|
||||||
log.error("无效的accountId: {}", request.getHeader().getAccountId());
|
|
||||||
return buildErrorResponse("0003", "账号错误");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 验证签名
|
|
||||||
if (!validateSignature(request)) {
|
|
||||||
log.error("签名验证失败");
|
|
||||||
return buildErrorResponse("0002", "签名验证失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 解析请求体
|
|
||||||
CtripQueryOrderRequest.CtripQueryOrderBody body = parseRequestBody(request.getBody());
|
|
||||||
if (body == null) {
|
|
||||||
log.error("请求体解析失败");
|
|
||||||
return buildErrorResponse("0004", "请求体解析失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. 验证查询条件
|
|
||||||
if (!validateQueryConditions(body)) {
|
|
||||||
log.error("查询条件不完整");
|
|
||||||
return buildErrorResponse("0005", "查询条件不完整,至少需要提供otaOrderId、supplierOrderId或sequenceId中的一个");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 7. 处理查询请求
|
|
||||||
CtripQueryOrderResponse response = ctripQueryOrderService.processQueryOrder(request.getHeader(), body);
|
|
||||||
|
|
||||||
log.info("携程订单查询处理完成");
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理携程订单查询请求异常", e);
|
|
||||||
return buildErrorResponse("1100", "处理请求异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据携程订单号查询订单(内部接口)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "根据携程订单号查询订单")
|
|
||||||
@GetMapping("/order/ota/{otaOrderId}")
|
|
||||||
public CtripQueryOrderResponse queryOrderByOtaOrderId(@PathVariable("otaOrderId") String otaOrderId) {
|
|
||||||
log.info("根据携程订单号查询订单: {}", otaOrderId);
|
|
||||||
return ctripQueryOrderService.queryOrderByOtaOrderId(otaOrderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据供应商订单号查询订单(内部接口)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "根据供应商订单号查询订单")
|
|
||||||
@GetMapping("/order/supplier/{supplierOrderId}")
|
|
||||||
public CtripQueryOrderResponse queryOrderBySupplierOrderId(@PathVariable("supplierOrderId") String supplierOrderId) {
|
|
||||||
log.info("根据供应商订单号查询订单: {}", supplierOrderId);
|
|
||||||
return ctripQueryOrderService.queryOrderBySupplierOrderId(supplierOrderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据流水号查询订单(内部接口)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "根据流水号查询订单")
|
|
||||||
@GetMapping("/order/sequence/{sequenceId}")
|
|
||||||
public CtripQueryOrderResponse queryOrderBySequenceId(@PathVariable("sequenceId") String sequenceId) {
|
|
||||||
log.info("根据流水号查询订单: {}", sequenceId);
|
|
||||||
return ctripQueryOrderService.queryOrderBySequenceId(sequenceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证签名
|
|
||||||
*/
|
|
||||||
private boolean validateSignature(CtripQueryOrderRequest request) {
|
|
||||||
try {
|
|
||||||
String accountId = request.getHeader().getAccountId();
|
|
||||||
String serviceName = request.getHeader().getServiceName();
|
|
||||||
String requestTime = request.getHeader().getRequestTime();
|
|
||||||
String version = request.getHeader().getVersion();
|
|
||||||
String sign = request.getHeader().getSign();
|
|
||||||
|
|
||||||
// 获取原始的加密body(用于签名验证)
|
|
||||||
// 根据官方示例:需要使用原始的加密body,而不是解密后的body
|
|
||||||
String encryptedBody = request.getOriginalEncryptedBody();
|
|
||||||
if (encryptedBody == null) {
|
|
||||||
// 如果没有原始加密body,尝试使用当前body
|
|
||||||
encryptedBody = request.getBody().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证签名
|
|
||||||
boolean isValid = ctripDecryptUtil.verifySign(accountId, serviceName, requestTime, encryptedBody, version, sign);
|
|
||||||
|
|
||||||
if (!isValid) {
|
|
||||||
log.error("签名验证失败,期望签名: {}, 计算签名: {}", sign,
|
|
||||||
ctripDecryptUtil.generateSign(accountId, serviceName, requestTime, encryptedBody, version));
|
|
||||||
|
|
||||||
// 额外的调试信息
|
|
||||||
log.debug("签名验证详细信息:");
|
|
||||||
log.debug("- accountId: {}", accountId);
|
|
||||||
log.debug("- serviceName: {}", serviceName);
|
|
||||||
log.debug("- requestTime: {}", requestTime);
|
|
||||||
log.debug("- version: {}", version);
|
|
||||||
log.debug("- encryptedBody长度: {}", encryptedBody != null ? encryptedBody.length() : 0);
|
|
||||||
log.debug("- accountSecret: {}", ctripDecryptUtil.getAccountSecret());
|
|
||||||
}
|
|
||||||
|
|
||||||
return isValid;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("验证签名异常", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证账号ID
|
|
||||||
*/
|
|
||||||
private boolean validateAccountId(String accountId) {
|
|
||||||
return ctripAccountId.equals(accountId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析请求体
|
|
||||||
*/
|
|
||||||
private CtripQueryOrderRequest.CtripQueryOrderBody parseRequestBody(Object body) {
|
|
||||||
try {
|
|
||||||
if (body instanceof String) {
|
|
||||||
// 此时body已经是解密后的JSON字符串,直接解析
|
|
||||||
String jsonBody = body.toString();
|
|
||||||
log.debug("解析JSON字符串: {}", jsonBody);
|
|
||||||
return objectMapper.readValue(jsonBody, CtripQueryOrderRequest.CtripQueryOrderBody.class);
|
|
||||||
} else {
|
|
||||||
// 如果是JSON对象,直接转换
|
|
||||||
return objectMapper.convertValue(body, CtripQueryOrderRequest.CtripQueryOrderBody.class);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析请求体异常", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证查询条件
|
|
||||||
*/
|
|
||||||
private boolean validateQueryConditions(CtripQueryOrderRequest.CtripQueryOrderBody body) {
|
|
||||||
return (body.getOtaOrderId() != null && !body.getOtaOrderId().trim().isEmpty()) ||
|
|
||||||
(body.getSupplierOrderId() != null && !body.getSupplierOrderId().trim().isEmpty()) ||
|
|
||||||
(body.getSequenceId() != null && !body.getSequenceId().trim().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建错误响应
|
|
||||||
*/
|
|
||||||
private CtripQueryOrderResponse buildErrorResponse(String resultCode, String resultMessage) {
|
|
||||||
CtripQueryOrderResponse response = new CtripQueryOrderResponse();
|
|
||||||
|
|
||||||
CtripQueryOrderResponse.CtripResponseHeader header = new CtripQueryOrderResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode(resultCode);
|
|
||||||
header.setResultMessage(resultMessage);
|
|
||||||
response.setHeader(header);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试MD5计算(内部测试用)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "测试MD5计算")
|
|
||||||
@PostMapping("/test/md5")
|
|
||||||
public Map<String, Object> testMD5(@RequestBody Map<String, String> request) {
|
|
||||||
log.info("测试MD5计算,请求参数: {}", request);
|
|
||||||
|
|
||||||
Map<String, Object> result = new java.util.HashMap<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
String input = request.get("input");
|
|
||||||
String md5Result = ctripDecryptUtil.testMD5(input);
|
|
||||||
|
|
||||||
result.put("input", input);
|
|
||||||
result.put("md5Result", md5Result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("测试MD5计算异常", e);
|
|
||||||
result.put("error", e.getMessage());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试签名计算(内部测试用)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "测试签名计算")
|
|
||||||
@PostMapping("/test/sign")
|
|
||||||
public Map<String, Object> testSignCalculation(@RequestBody Map<String, Object> request) {
|
|
||||||
log.info("测试签名计算,请求参数: {}", request);
|
|
||||||
|
|
||||||
Map<String, Object> result = new java.util.HashMap<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 解析请求
|
|
||||||
Map<String, Object> headerMap = (Map<String, Object>) request.get("header");
|
|
||||||
Object bodyObj = request.get("body");
|
|
||||||
|
|
||||||
String accountId = (String) headerMap.get("accountId");
|
|
||||||
String serviceName = (String) headerMap.get("serviceName");
|
|
||||||
String requestTime = (String) headerMap.get("requestTime");
|
|
||||||
String version = (String) headerMap.get("version");
|
|
||||||
String expectedSign = (String) headerMap.get("sign");
|
|
||||||
|
|
||||||
// 解密body
|
|
||||||
String decryptedBody = null;
|
|
||||||
if (bodyObj instanceof String) {
|
|
||||||
decryptedBody = ctripDecryptUtil.decryptAES((String) bodyObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.put("accountId", accountId);
|
|
||||||
result.put("serviceName", serviceName);
|
|
||||||
result.put("requestTime", requestTime);
|
|
||||||
result.put("version", version);
|
|
||||||
result.put("expectedSign", expectedSign);
|
|
||||||
result.put("decryptedBody", decryptedBody);
|
|
||||||
result.put("accountSecret", ctripDecryptUtil.getAccountSecret());
|
|
||||||
|
|
||||||
// 计算签名
|
|
||||||
String calculatedSign = ctripDecryptUtil.generateSign(accountId, serviceName, requestTime, decryptedBody, version);
|
|
||||||
result.put("calculatedSign", calculatedSign);
|
|
||||||
result.put("isMatch", expectedSign.equalsIgnoreCase(calculatedSign));
|
|
||||||
|
|
||||||
// 详细调试信息
|
|
||||||
Map<String, Object> debugInfo = ctripDecryptUtil.debugSignCalculation(accountId, serviceName, requestTime, decryptedBody, version, expectedSign);
|
|
||||||
result.put("debugInfo", debugInfo);
|
|
||||||
|
|
||||||
log.info("签名测试结果: {}", result);
|
|
||||||
return result;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("测试签名计算异常", e);
|
|
||||||
result.put("error", e.getMessage());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试QueryOrder接口(内部测试用)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "测试QueryOrder接口")
|
|
||||||
@PostMapping("/test")
|
|
||||||
public CtripQueryOrderResponse testQueryOrder(@RequestBody Map<String, Object> request) {
|
|
||||||
log.info("测试QueryOrder接口,请求参数: {}", request);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 构建测试请求
|
|
||||||
CtripQueryOrderRequest testRequest = new CtripQueryOrderRequest();
|
|
||||||
|
|
||||||
// 设置请求头
|
|
||||||
CtripQueryOrderRequest.CtripHeader header = new CtripQueryOrderRequest.CtripHeader();
|
|
||||||
header.setAccountId(ctripAccountId);
|
|
||||||
header.setServiceName("QueryOrder");
|
|
||||||
header.setRequestTime(java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
||||||
header.setVersion("1.0");
|
|
||||||
header.setSign("test_sign"); // 测试时跳过签名验证
|
|
||||||
testRequest.setHeader(header);
|
|
||||||
|
|
||||||
// 设置请求体
|
|
||||||
CtripQueryOrderRequest.CtripQueryOrderBody body = new CtripQueryOrderRequest.CtripQueryOrderBody();
|
|
||||||
body.setOtaOrderId((String) request.get("otaOrderId"));
|
|
||||||
body.setSupplierOrderId((String) request.get("supplierOrderId"));
|
|
||||||
body.setSequenceId((String) request.get("sequenceId"));
|
|
||||||
testRequest.setBody(body);
|
|
||||||
|
|
||||||
// 调用查询服务
|
|
||||||
return ctripQueryOrderService.processQueryOrder(header, body);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("测试QueryOrder接口异常", e);
|
|
||||||
return buildErrorResponse("1100", "测试异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试QueryOrder接口解密(内部测试用)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "测试QueryOrder接口解密")
|
|
||||||
@PostMapping("/test/decrypt")
|
|
||||||
public Map<String, Object> testQueryOrderDecrypt(@RequestBody Object requestBody) {
|
|
||||||
log.info("测试QueryOrder接口解密,请求体类型: {}", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
|
|
||||||
Map<String, Object> result = new java.util.HashMap<>();
|
|
||||||
result.put("requestType", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
result.put("requestContent", requestBody);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (requestBody instanceof Map) {
|
|
||||||
Map<String, Object> requestMap = (Map<String, Object>) requestBody;
|
|
||||||
result.put("requestSize", requestMap.size());
|
|
||||||
result.put("requestKeys", requestMap.keySet());
|
|
||||||
|
|
||||||
// 检查是否是携程标准请求格式
|
|
||||||
if (requestMap.containsKey("header") && requestMap.containsKey("body")) {
|
|
||||||
result.put("isStandardFormat", true);
|
|
||||||
|
|
||||||
// 解析header
|
|
||||||
Map<String, Object> headerMap = (Map<String, Object>) requestMap.get("header");
|
|
||||||
result.put("header", headerMap);
|
|
||||||
|
|
||||||
// 处理body
|
|
||||||
Object bodyObj = requestMap.get("body");
|
|
||||||
if (bodyObj instanceof String) {
|
|
||||||
String encryptedBody = (String) bodyObj;
|
|
||||||
result.put("bodyType", "encrypted");
|
|
||||||
result.put("encryptedBodyLength", encryptedBody.length());
|
|
||||||
result.put("encryptedBodyPreview", encryptedBody.length() > 100 ? encryptedBody.substring(0, 100) + "..." : encryptedBody);
|
|
||||||
|
|
||||||
// 尝试解密
|
|
||||||
String decryptedBody = ctripDecryptUtil.decryptAES(encryptedBody);
|
|
||||||
if (decryptedBody != null) {
|
|
||||||
result.put("decryptSuccess", true);
|
|
||||||
result.put("decryptedBodyLength", decryptedBody.length());
|
|
||||||
result.put("decryptedBody", decryptedBody);
|
|
||||||
|
|
||||||
// 尝试解析JSON
|
|
||||||
try {
|
|
||||||
Object jsonObj = objectMapper.readValue(decryptedBody, Object.class);
|
|
||||||
result.put("jsonParseSuccess", true);
|
|
||||||
result.put("parsedJson", jsonObj);
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.put("jsonParseSuccess", false);
|
|
||||||
result.put("jsonParseError", e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.put("decryptSuccess", false);
|
|
||||||
result.put("decryptError", "解密失败");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.put("bodyType", "object");
|
|
||||||
result.put("body", bodyObj);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.put("isStandardFormat", false);
|
|
||||||
result.put("error", "不是携程标准请求格式");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.put("error", "请求体不是Map类型");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.put("error", "处理异常: " + e.getMessage());
|
|
||||||
log.error("测试QueryOrder接口解密异常", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-453
@@ -1,453 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.model.CtripRefundOrderRequest;
|
|
||||||
import com.central.coupon.model.CtripRefundOrderResponse;
|
|
||||||
import com.central.coupon.service.ICtripRefundOrderService;
|
|
||||||
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.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单退款控制器
|
|
||||||
* 专门处理携程订单退款相关接口
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coupon/ctrip/refund")
|
|
||||||
@Tag(name = "携程订单退款")
|
|
||||||
public class CtripRefundOrderController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ICtripRefundOrderService ctripRefundOrderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripDecryptUtil ctripDecryptUtil;
|
|
||||||
|
|
||||||
// 携程SDK配置参数
|
|
||||||
@Value("${ctrip.account.id}")
|
|
||||||
private String ctripAccountId;
|
|
||||||
|
|
||||||
@Value("${ctrip.aes.key:750e15a31356a99d}")
|
|
||||||
private String ctripAesKey;
|
|
||||||
|
|
||||||
@Value("${ctrip.aes.iv:087b36ad0dff7942}")
|
|
||||||
private String ctripAesIv;
|
|
||||||
|
|
||||||
@Value("${ctrip.account.secret:ce6033ae31124ec5cdab3d2bc79f2622}")
|
|
||||||
private String ctripAccountSecret;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单退款接口
|
|
||||||
* 携程调用此接口申请订单退款
|
|
||||||
*
|
|
||||||
* 请求格式:
|
|
||||||
* {
|
|
||||||
* "header": {
|
|
||||||
* "accountId": "c50a8f2a4a59c9e7",
|
|
||||||
* "serviceName": "RefundOrder",
|
|
||||||
* "requestTime": "2025-01-23 14:57:34",
|
|
||||||
* "version": "1.0",
|
|
||||||
* "sign": "md5签名"
|
|
||||||
* },
|
|
||||||
* "body": "加密的JSON字符串"
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
@Operation(summary = "携程订单退款接口")
|
|
||||||
@PostMapping("/order")
|
|
||||||
public CtripRefundOrderResponse refundOrder(@RequestBody Object requestBody,
|
|
||||||
jakarta.servlet.http.HttpServletRequest httpRequest) {
|
|
||||||
return processRefundOrderRequest(requestBody, httpRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理退款订单请求(内部方法,供统一接口调用)
|
|
||||||
*/
|
|
||||||
public CtripRefundOrderResponse processRefundOrderRequest(Object requestBody,
|
|
||||||
jakarta.servlet.http.HttpServletRequest httpRequest) {
|
|
||||||
log.info("收到携程订单退款请求,IP: {}", httpRequest.getRemoteAddr());
|
|
||||||
log.info("请求URL: {}", httpRequest.getRequestURL());
|
|
||||||
log.info("请求URI: {}", httpRequest.getRequestURI());
|
|
||||||
log.info("请求方法: {}", httpRequest.getMethod());
|
|
||||||
log.info("请求体类型: {}", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
|
|
||||||
CtripRefundOrderRequest request = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. 解析请求体
|
|
||||||
if (requestBody instanceof Map) {
|
|
||||||
Map<String, Object> requestMap = (Map<String, Object>) requestBody;
|
|
||||||
log.info("请求体内容: {}", requestMap);
|
|
||||||
|
|
||||||
// 检查是否是携程标准请求格式(包含header和body)
|
|
||||||
if (requestMap.containsKey("header") && requestMap.containsKey("body")) {
|
|
||||||
log.info("检测到携程标准请求格式(包含header和body)");
|
|
||||||
|
|
||||||
// 构建请求对象
|
|
||||||
request = new CtripRefundOrderRequest();
|
|
||||||
|
|
||||||
// 解析header
|
|
||||||
Map<String, Object> headerMap = (Map<String, Object>) requestMap.get("header");
|
|
||||||
CtripRefundOrderRequest.CtripHeader header = new CtripRefundOrderRequest.CtripHeader();
|
|
||||||
header.setAccountId((String) headerMap.get("accountId"));
|
|
||||||
header.setServiceName((String) headerMap.get("serviceName"));
|
|
||||||
header.setRequestTime((String) headerMap.get("requestTime"));
|
|
||||||
header.setVersion((String) headerMap.get("version"));
|
|
||||||
header.setSign((String) headerMap.get("sign"));
|
|
||||||
request.setHeader(header);
|
|
||||||
|
|
||||||
// 处理body
|
|
||||||
Object bodyObj = requestMap.get("body");
|
|
||||||
if (bodyObj instanceof String) {
|
|
||||||
// body是加密字符串,需要解密
|
|
||||||
String encryptedBody = (String) bodyObj;
|
|
||||||
log.info("body是加密字符串,长度: {}", encryptedBody.length());
|
|
||||||
|
|
||||||
// 保存原始的加密body用于签名验证
|
|
||||||
request.setOriginalEncryptedBody(encryptedBody);
|
|
||||||
|
|
||||||
String decryptedBody = ctripDecryptUtil.decryptAES(encryptedBody);
|
|
||||||
if (decryptedBody == null) {
|
|
||||||
log.error("解密body失败");
|
|
||||||
return buildErrorResponse("0001", "解密body失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("解密成功,解密后body长度: {}", decryptedBody.length());
|
|
||||||
log.info("解密后body内容: {}", decryptedBody);
|
|
||||||
|
|
||||||
request.setBody(decryptedBody);
|
|
||||||
} else {
|
|
||||||
// body已经是对象
|
|
||||||
request.setBody(bodyObj);
|
|
||||||
log.info("body已经是对象格式");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("请求格式不正确,缺少header或body字段");
|
|
||||||
return buildErrorResponse("0001", "请求格式不正确");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("未知的请求体类型:{}", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
return buildErrorResponse("0001", "未知的请求体类型");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 验证请求头
|
|
||||||
if (request.getHeader() == null) {
|
|
||||||
log.error("请求头为空");
|
|
||||||
return buildErrorResponse("0001", "请求头不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 验证服务名称
|
|
||||||
if (!"RefundOrder".equals(request.getHeader().getServiceName())) {
|
|
||||||
log.error("服务名称不正确: {}", request.getHeader().getServiceName());
|
|
||||||
return buildErrorResponse("0002", "服务名称不正确");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 验证签名
|
|
||||||
if (!validateSignature(request)) {
|
|
||||||
log.error("签名验证失败");
|
|
||||||
return buildErrorResponse("0003", "签名验证失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 解析请求体
|
|
||||||
CtripRefundOrderRequest.CtripRefundOrderBody body = parseRequestBody(request.getBody());
|
|
||||||
if (body == null) {
|
|
||||||
log.error("请求体解析失败");
|
|
||||||
return buildErrorResponse("0004", "请求体解析失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 验证退款参数
|
|
||||||
if (!validateRefundParameters(body)) {
|
|
||||||
log.error("退款参数验证失败");
|
|
||||||
return buildErrorResponse("0005", "退款参数验证失败,请检查订单号、退款金额等参数");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. 处理退款请求
|
|
||||||
CtripRefundOrderResponse response = ctripRefundOrderService.processRefundOrder(request.getHeader(), body);
|
|
||||||
|
|
||||||
log.info("携程订单退款处理完成");
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理携程订单退款请求异常", e);
|
|
||||||
return buildErrorResponse("1100", "处理请求异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证退款金额(内部接口)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "验证退款金额")
|
|
||||||
@GetMapping("/validate/{otaOrderId}")
|
|
||||||
public Map<String, Object> validateRefundAmount(@PathVariable("otaOrderId") String otaOrderId,
|
|
||||||
@RequestParam("refundAmount") java.math.BigDecimal refundAmount) {
|
|
||||||
log.info("验证退款金额,otaOrderId: {}, refundAmount: {}", otaOrderId, refundAmount);
|
|
||||||
|
|
||||||
try {
|
|
||||||
boolean isValid = ctripRefundOrderService.validateRefundAmount(otaOrderId, null, refundAmount);
|
|
||||||
java.math.BigDecimal availableAmount = ctripRefundOrderService.getAvailableRefundAmount(otaOrderId, null);
|
|
||||||
|
|
||||||
Map<String, Object> result = Map.of(
|
|
||||||
"otaOrderId", otaOrderId,
|
|
||||||
"refundAmount", refundAmount,
|
|
||||||
"availableAmount", availableAmount,
|
|
||||||
"isValid", isValid,
|
|
||||||
"message", isValid ? "退款金额验证通过" : "退款金额大于可退金额"
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("验证退款金额异常,otaOrderId: {}", otaOrderId, e);
|
|
||||||
return Map.of(
|
|
||||||
"otaOrderId", otaOrderId,
|
|
||||||
"refundAmount", refundAmount,
|
|
||||||
"availableAmount", java.math.BigDecimal.ZERO,
|
|
||||||
"isValid", false,
|
|
||||||
"message", "验证异常: " + e.getMessage()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取可退金额(内部接口)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "获取可退金额")
|
|
||||||
@GetMapping("/available/{otaOrderId}")
|
|
||||||
public Map<String, Object> getAvailableRefundAmount(@PathVariable("otaOrderId") String otaOrderId) {
|
|
||||||
log.info("获取可退金额,otaOrderId: {}", otaOrderId);
|
|
||||||
|
|
||||||
try {
|
|
||||||
java.math.BigDecimal availableAmount = ctripRefundOrderService.getAvailableRefundAmount(otaOrderId, null);
|
|
||||||
|
|
||||||
return Map.of(
|
|
||||||
"otaOrderId", otaOrderId,
|
|
||||||
"availableAmount", availableAmount,
|
|
||||||
"message", "获取成功"
|
|
||||||
);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("获取可退金额异常,otaOrderId: {}", otaOrderId, e);
|
|
||||||
return Map.of(
|
|
||||||
"otaOrderId", otaOrderId,
|
|
||||||
"availableAmount", java.math.BigDecimal.ZERO,
|
|
||||||
"message", "获取异常: " + e.getMessage()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试RefundOrder接口(内部测试用)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "测试RefundOrder接口")
|
|
||||||
@PostMapping("/test")
|
|
||||||
public CtripRefundOrderResponse testRefundOrder(@RequestBody Map<String, Object> request) {
|
|
||||||
log.info("测试RefundOrder接口,请求参数: {}", request);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 构建测试请求
|
|
||||||
CtripRefundOrderRequest testRequest = new CtripRefundOrderRequest();
|
|
||||||
|
|
||||||
// 设置请求头
|
|
||||||
CtripRefundOrderRequest.CtripHeader header = new CtripRefundOrderRequest.CtripHeader();
|
|
||||||
header.setAccountId(ctripAccountId);
|
|
||||||
header.setServiceName("RefundOrder");
|
|
||||||
header.setRequestTime(java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
||||||
header.setVersion("1.0");
|
|
||||||
header.setSign("test_sign"); // 测试时跳过签名验证
|
|
||||||
testRequest.setHeader(header);
|
|
||||||
|
|
||||||
// 设置请求体
|
|
||||||
CtripRefundOrderRequest.CtripRefundOrderBody body = new CtripRefundOrderRequest.CtripRefundOrderBody();
|
|
||||||
body.setOtaOrderId((String) request.get("otaOrderId"));
|
|
||||||
body.setSupplierOrderId((String) request.get("supplierOrderId"));
|
|
||||||
body.setSequenceId((String) request.get("sequenceId"));
|
|
||||||
body.setTotalAmount(new java.math.BigDecimal(request.get("totalAmount").toString()));
|
|
||||||
body.setTotalAmountCurrency((String) request.get("totalAmountCurrency"));
|
|
||||||
body.setLastConfirmTime((String) request.get("lastConfirmTime"));
|
|
||||||
body.setRefundReason((String) request.get("refundReason"));
|
|
||||||
testRequest.setBody(body);
|
|
||||||
|
|
||||||
// 调用退款服务
|
|
||||||
return ctripRefundOrderService.processRefundOrder(header, body);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("测试RefundOrder接口异常", e);
|
|
||||||
return buildErrorResponse("1100", "测试异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证签名
|
|
||||||
*/
|
|
||||||
private boolean validateSignature(CtripRefundOrderRequest request) {
|
|
||||||
try {
|
|
||||||
String accountId = request.getHeader().getAccountId();
|
|
||||||
String serviceName = request.getHeader().getServiceName();
|
|
||||||
String requestTime = request.getHeader().getRequestTime();
|
|
||||||
String version = request.getHeader().getVersion();
|
|
||||||
String sign = request.getHeader().getSign();
|
|
||||||
|
|
||||||
// 获取原始的加密body(用于签名验证)
|
|
||||||
// 根据官方示例:需要使用原始的加密body,而不是解密后的body
|
|
||||||
String encryptedBody = request.getOriginalEncryptedBody();
|
|
||||||
if (encryptedBody == null) {
|
|
||||||
// 如果没有原始加密body,尝试使用当前body
|
|
||||||
encryptedBody = request.getBody().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证签名
|
|
||||||
boolean isValid = ctripDecryptUtil.verifySign(accountId, serviceName, requestTime, encryptedBody, version, sign);
|
|
||||||
|
|
||||||
if (!isValid) {
|
|
||||||
log.error("签名验证失败,期望签名: {}, 计算签名: {}", sign,
|
|
||||||
ctripDecryptUtil.generateSign(accountId, serviceName, requestTime, encryptedBody, version));
|
|
||||||
}
|
|
||||||
|
|
||||||
return isValid;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("验证签名异常", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析请求体
|
|
||||||
*/
|
|
||||||
private CtripRefundOrderRequest.CtripRefundOrderBody parseRequestBody(Object body) {
|
|
||||||
try {
|
|
||||||
if (body instanceof String) {
|
|
||||||
// 此时body已经是解密后的JSON字符串,直接解析
|
|
||||||
String jsonBody = body.toString();
|
|
||||||
log.debug("解析JSON字符串: {}", jsonBody);
|
|
||||||
return objectMapper.readValue(jsonBody, CtripRefundOrderRequest.CtripRefundOrderBody.class);
|
|
||||||
} else {
|
|
||||||
// 如果是JSON对象,直接转换
|
|
||||||
return objectMapper.convertValue(body, CtripRefundOrderRequest.CtripRefundOrderBody.class);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析请求体异常", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证退款参数
|
|
||||||
*/
|
|
||||||
private boolean validateRefundParameters(CtripRefundOrderRequest.CtripRefundOrderBody body) {
|
|
||||||
// 验证订单号
|
|
||||||
if (body.getOtaOrderId() == null || body.getOtaOrderId().trim().isEmpty()) {
|
|
||||||
log.error("携程订单号为空");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证退款金额
|
|
||||||
if (body.getTotalAmount() == null || body.getTotalAmount().compareTo(java.math.BigDecimal.ZERO) <= 0) {
|
|
||||||
log.error("退款金额无效: {}", body.getTotalAmount());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证流水号
|
|
||||||
if (body.getSequenceId() == null || body.getSequenceId().trim().isEmpty()) {
|
|
||||||
log.error("流水号为空");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试RefundOrder接口解密(内部测试用)
|
|
||||||
*/
|
|
||||||
@Operation(summary = "测试RefundOrder接口解密")
|
|
||||||
@PostMapping("/test/decrypt")
|
|
||||||
public Map<String, Object> testRefundOrderDecrypt(@RequestBody Object requestBody) {
|
|
||||||
log.info("测试RefundOrder接口解密,请求体类型: {}", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
|
|
||||||
Map<String, Object> result = new java.util.HashMap<>();
|
|
||||||
result.put("requestType", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
result.put("requestContent", requestBody);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (requestBody instanceof Map) {
|
|
||||||
Map<String, Object> requestMap = (Map<String, Object>) requestBody;
|
|
||||||
result.put("requestSize", requestMap.size());
|
|
||||||
result.put("requestKeys", requestMap.keySet());
|
|
||||||
|
|
||||||
// 检查是否是携程标准请求格式
|
|
||||||
if (requestMap.containsKey("header") && requestMap.containsKey("body")) {
|
|
||||||
result.put("isStandardFormat", true);
|
|
||||||
|
|
||||||
// 解析header
|
|
||||||
Map<String, Object> headerMap = (Map<String, Object>) requestMap.get("header");
|
|
||||||
result.put("header", headerMap);
|
|
||||||
|
|
||||||
// 处理body
|
|
||||||
Object bodyObj = requestMap.get("body");
|
|
||||||
if (bodyObj instanceof String) {
|
|
||||||
String encryptedBody = (String) bodyObj;
|
|
||||||
result.put("bodyType", "encrypted");
|
|
||||||
result.put("encryptedBodyLength", encryptedBody.length());
|
|
||||||
result.put("encryptedBodyPreview", encryptedBody.length() > 100 ? encryptedBody.substring(0, 100) + "..." : encryptedBody);
|
|
||||||
|
|
||||||
// 尝试解密
|
|
||||||
String decryptedBody = ctripDecryptUtil.decryptAES(encryptedBody);
|
|
||||||
if (decryptedBody != null) {
|
|
||||||
result.put("decryptSuccess", true);
|
|
||||||
result.put("decryptedBodyLength", decryptedBody.length());
|
|
||||||
result.put("decryptedBody", decryptedBody);
|
|
||||||
|
|
||||||
// 尝试解析JSON
|
|
||||||
try {
|
|
||||||
Object jsonObj = objectMapper.readValue(decryptedBody, Object.class);
|
|
||||||
result.put("jsonParseSuccess", true);
|
|
||||||
result.put("parsedJson", jsonObj);
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.put("jsonParseSuccess", false);
|
|
||||||
result.put("jsonParseError", e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.put("decryptSuccess", false);
|
|
||||||
result.put("decryptError", "解密失败");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.put("bodyType", "object");
|
|
||||||
result.put("body", bodyObj);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.put("isStandardFormat", false);
|
|
||||||
result.put("error", "不是携程标准请求格式");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.put("error", "请求体不是Map类型");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.put("error", "处理异常: " + e.getMessage());
|
|
||||||
log.error("测试RefundOrder接口解密异常", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建错误响应
|
|
||||||
*/
|
|
||||||
private CtripRefundOrderResponse buildErrorResponse(String resultCode, String resultMessage) {
|
|
||||||
CtripRefundOrderResponse response = new CtripRefundOrderResponse();
|
|
||||||
|
|
||||||
CtripRefundOrderResponse.CtripResponseHeader header = new CtripRefundOrderResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode(resultCode);
|
|
||||||
header.setResultMessage(resultMessage);
|
|
||||||
response.setHeader(header);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-373
@@ -1,373 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.model.CtripCouponResponse;
|
|
||||||
import com.central.coupon.model.CtripQueryOrderResponse;
|
|
||||||
import com.central.coupon.model.CtripRefundOrderResponse;
|
|
||||||
import com.central.coupon.service.ICtripQueryOrderService;
|
|
||||||
import com.central.coupon.service.ICtripRefundOrderService;
|
|
||||||
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 java.util.Map;
|
|
||||||
import com.central.coupon.service.CtripCancelPreOrderService;
|
|
||||||
import com.central.coupon.service.ICtripOrderService;
|
|
||||||
import com.central.coupon.model.CtripCreateOrderRequest;
|
|
||||||
import com.central.coupon.model.CtripCreateOrderResponse;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程统一接口控制器
|
|
||||||
* 根据请求头中的serviceName路由到不同的处理方法
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coupon/ctrip")
|
|
||||||
@Tag(name = "携程统一接口")
|
|
||||||
public class CtripUnifiedController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripQueryOrderController ctripQueryOrderController;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripRefundOrderController ctripRefundOrderController;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripPayPreOrderController ctripPayPreOrderController;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripCancelPreOrderController ctripCancelPreOrderController;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripCancelOrderController ctripCancelOrderController;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripCancelPreOrderService ctripCancelPreOrderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ICtripOrderService ctripOrderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripDecryptUtil ctripDecryptUtil;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程统一接口入口
|
|
||||||
* 根据serviceName路由到不同的处理方法
|
|
||||||
*/
|
|
||||||
@Operation(summary = "携程统一接口")
|
|
||||||
@PostMapping("/create")
|
|
||||||
public Object handleCtripRequest(@RequestBody Object requestBody,
|
|
||||||
jakarta.servlet.http.HttpServletRequest httpRequest) {
|
|
||||||
log.info("收到携程统一接口请求,IP: {}", httpRequest.getRemoteAddr());
|
|
||||||
log.info("请求URL: {}", httpRequest.getRequestURL());
|
|
||||||
log.info("请求URI: {}", httpRequest.getRequestURI());
|
|
||||||
log.info("请求方法: {}", httpRequest.getMethod());
|
|
||||||
log.info("请求体类型: {}", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 解析请求体
|
|
||||||
Map<String, Object> request = parseRequestBody(requestBody);
|
|
||||||
if (request == null) {
|
|
||||||
return buildErrorResponse("0001", "请求体解析失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取请求头
|
|
||||||
Map<String, Object> header = (Map<String, Object>) request.get("header");
|
|
||||||
if (header == null) {
|
|
||||||
log.error("请求头为空");
|
|
||||||
return buildErrorResponse("0001", "请求头不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取serviceName
|
|
||||||
String serviceName = (String) header.get("serviceName");
|
|
||||||
log.info("携程请求的serviceName: {}", serviceName);
|
|
||||||
|
|
||||||
// 根据serviceName路由到不同的处理方法
|
|
||||||
switch (serviceName) {
|
|
||||||
case "CreatePreOrder":
|
|
||||||
log.info("路由到创建订单接口");
|
|
||||||
return processCreatePreOrder(request, header);
|
|
||||||
|
|
||||||
case "QueryOrder":
|
|
||||||
log.info("路由到查询订单接口");
|
|
||||||
return ctripQueryOrderController.processQueryOrderRequest(requestBody, httpRequest);
|
|
||||||
|
|
||||||
case "RefundOrder":
|
|
||||||
log.info("路由到退款订单接口");
|
|
||||||
return ctripRefundOrderController.processRefundOrderRequest(requestBody, httpRequest);
|
|
||||||
|
|
||||||
case "PayPreOrder":
|
|
||||||
log.info("路由到预下单支付接口");
|
|
||||||
return ctripPayPreOrderController.payPreOrder(requestBody, httpRequest);
|
|
||||||
|
|
||||||
case "CancelPreOrder":
|
|
||||||
log.info("路由到取消预下单接口");
|
|
||||||
return ctripCancelPreOrderController.processCancelPreOrderRequest(requestBody, httpRequest);
|
|
||||||
|
|
||||||
case "CancelOrder":
|
|
||||||
log.info("路由到取消订单接口");
|
|
||||||
return ctripCancelOrderController.processCancelOrderRequest(requestBody, httpRequest);
|
|
||||||
|
|
||||||
default:
|
|
||||||
log.error("未知的serviceName: {}", serviceName);
|
|
||||||
return buildErrorResponse("0002", "未知的服务名称: " + serviceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理携程统一接口请求异常", e);
|
|
||||||
return buildErrorResponse("1100", "处理请求异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析请求体
|
|
||||||
*/
|
|
||||||
private Map<String, Object> parseRequestBody(Object requestBody) {
|
|
||||||
try {
|
|
||||||
if (requestBody instanceof Map) {
|
|
||||||
return (Map<String, Object>) requestBody;
|
|
||||||
} else if (requestBody instanceof String) {
|
|
||||||
// 如果是加密字符串,先解密
|
|
||||||
String decryptedBody = ctripDecryptUtil.decryptAES((String) requestBody);
|
|
||||||
if (decryptedBody == null) {
|
|
||||||
log.error("解密请求体失败");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return objectMapper.readValue(decryptedBody, Map.class);
|
|
||||||
} else {
|
|
||||||
log.error("未知的请求体类型: {}", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析请求体异常", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建错误响应
|
|
||||||
*/
|
|
||||||
private CtripCouponResponse buildErrorResponse(String resultCode, String resultMessage) {
|
|
||||||
CtripCouponResponse response = new CtripCouponResponse();
|
|
||||||
|
|
||||||
CtripCouponResponse.CtripResponseHeader header = new CtripCouponResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode(resultCode);
|
|
||||||
header.setResultMessage(resultMessage);
|
|
||||||
response.setHeader(header);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建CreatePreOrder错误响应
|
|
||||||
*/
|
|
||||||
private CtripCreateOrderResponse buildCreatePreOrderErrorResponse(String resultCode, String resultMessage) {
|
|
||||||
CtripCreateOrderResponse response = new CtripCreateOrderResponse();
|
|
||||||
|
|
||||||
CtripCreateOrderResponse.CtripResponseHeader header = new CtripCreateOrderResponse.CtripResponseHeader();
|
|
||||||
header.setResultCode(resultCode);
|
|
||||||
header.setResultMessage(resultMessage);
|
|
||||||
response.setHeader(header);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理CreatePreOrder请求
|
|
||||||
*/
|
|
||||||
private Object processCreatePreOrder(Map<String, Object> request, Map<String, Object> header) {
|
|
||||||
try {
|
|
||||||
log.info("开始处理CreatePreOrder请求");
|
|
||||||
|
|
||||||
// 调试:打印整个请求结构
|
|
||||||
log.info("CreatePreOrder完整请求结构: {}", request);
|
|
||||||
log.info("request.get('body')类型: {}, 值: {}",
|
|
||||||
request.get("body") != null ? request.get("body").getClass().getSimpleName() : "null",
|
|
||||||
request.get("body"));
|
|
||||||
|
|
||||||
// 获取请求体
|
|
||||||
Object bodyObj = request.get("body");
|
|
||||||
Map<String, Object> body;
|
|
||||||
|
|
||||||
if (bodyObj instanceof String) {
|
|
||||||
// 如果body是加密字符串,需要先解密
|
|
||||||
log.info("检测到body是加密字符串,开始解密");
|
|
||||||
String decryptedBody = ctripDecryptUtil.decryptAES((String) bodyObj);
|
|
||||||
if (decryptedBody == null) {
|
|
||||||
log.error("解密CreatePreOrder请求体失败");
|
|
||||||
return buildCreatePreOrderErrorResponse("0001", "解密请求体失败");
|
|
||||||
}
|
|
||||||
log.info("解密后的body: {}", decryptedBody);
|
|
||||||
body = objectMapper.readValue(decryptedBody, Map.class);
|
|
||||||
} else if (bodyObj instanceof Map) {
|
|
||||||
body = (Map<String, Object>) bodyObj;
|
|
||||||
} else {
|
|
||||||
log.error("CreatePreOrder请求体类型不支持: {}", bodyObj != null ? bodyObj.getClass().getSimpleName() : "null");
|
|
||||||
return buildCreatePreOrderErrorResponse("0001", "请求体类型不支持");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (body == null) {
|
|
||||||
log.error("CreatePreOrder请求体为空");
|
|
||||||
return buildCreatePreOrderErrorResponse("0001", "请求体不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调试:打印请求体结构
|
|
||||||
log.info("CreatePreOrder请求体结构: {}", body);
|
|
||||||
log.info("contacts字段类型: {}, 值: {}",
|
|
||||||
body.get("contacts") != null ? body.get("contacts").getClass().getSimpleName() : "null",
|
|
||||||
body.get("contacts"));
|
|
||||||
log.info("items字段类型: {}, 值: {}",
|
|
||||||
body.get("items") != null ? body.get("items").getClass().getSimpleName() : "null",
|
|
||||||
body.get("items"));
|
|
||||||
log.info("coupons字段类型: {}, 值: {}",
|
|
||||||
body.get("coupons") != null ? body.get("coupons").getClass().getSimpleName() : "null",
|
|
||||||
body.get("coupons"));
|
|
||||||
|
|
||||||
// 构建请求对象
|
|
||||||
CtripCreateOrderRequest createOrderRequest = new CtripCreateOrderRequest();
|
|
||||||
|
|
||||||
// 构建请求头
|
|
||||||
CtripCreateOrderRequest.CtripHeader requestHeader = new CtripCreateOrderRequest.CtripHeader();
|
|
||||||
requestHeader.setAccountId((String) header.get("accountId"));
|
|
||||||
requestHeader.setServiceName((String) header.get("serviceName"));
|
|
||||||
requestHeader.setRequestTime((String) header.get("requestTime"));
|
|
||||||
requestHeader.setVersion((String) header.get("version"));
|
|
||||||
requestHeader.setSign((String) header.get("sign"));
|
|
||||||
createOrderRequest.setHeader(requestHeader);
|
|
||||||
|
|
||||||
// 构建请求体
|
|
||||||
CtripCreateOrderRequest.CtripOrderBody requestBody = new CtripCreateOrderRequest.CtripOrderBody();
|
|
||||||
requestBody.setOtaOrderId((String) body.get("otaOrderId"));
|
|
||||||
requestBody.setSequenceId((String) body.get("sequenceId"));
|
|
||||||
requestBody.setConfirmType((Integer) body.get("confirmType"));
|
|
||||||
requestBody.setOrderLastConfirmTime((String) body.get("orderLastConfirmTime"));
|
|
||||||
|
|
||||||
// 注意:乘客信息是在订单项中,不是在订单体中,所以这里不需要处理body级别的passengers
|
|
||||||
|
|
||||||
// 处理联系人信息
|
|
||||||
if (body.get("contacts") != null) {
|
|
||||||
Object contactsObj = body.get("contacts");
|
|
||||||
if (contactsObj instanceof List) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<Map<String, Object>> contactsData = (List<Map<String, Object>>) contactsObj;
|
|
||||||
List<CtripCreateOrderRequest.CtripContact> contacts = new ArrayList<>();
|
|
||||||
for (Map<String, Object> contactData : contactsData) {
|
|
||||||
CtripCreateOrderRequest.CtripContact contact = new CtripCreateOrderRequest.CtripContact();
|
|
||||||
contact.setName((String) contactData.get("name"));
|
|
||||||
contact.setMobile((String) contactData.get("mobile"));
|
|
||||||
contact.setEmail((String) contactData.get("email"));
|
|
||||||
contacts.add(contact);
|
|
||||||
}
|
|
||||||
requestBody.setContacts(contacts);
|
|
||||||
} else {
|
|
||||||
log.warn("contacts字段不是List类型,跳过处理: {}", contactsObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理订单项信息
|
|
||||||
if (body.get("items") != null) {
|
|
||||||
Object itemsObj = body.get("items");
|
|
||||||
if (itemsObj instanceof List) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<Map<String, Object>> itemsData = (List<Map<String, Object>>) itemsObj;
|
|
||||||
List<CtripCreateOrderRequest.CtripOrderItem> items = new ArrayList<>();
|
|
||||||
for (Map<String, Object> itemData : itemsData) {
|
|
||||||
CtripCreateOrderRequest.CtripOrderItem item = new CtripCreateOrderRequest.CtripOrderItem();
|
|
||||||
|
|
||||||
// 如果itemId不存在,保持为空(携程期望空值)
|
|
||||||
String itemId = (String) itemData.get("itemId");
|
|
||||||
if (itemId == null || itemId.trim().isEmpty()) {
|
|
||||||
log.info("itemId为空,保持为空值(携程期望)");
|
|
||||||
}
|
|
||||||
item.setItemId(itemId);
|
|
||||||
|
|
||||||
item.setPLU((String) itemData.get("PLU"));
|
|
||||||
item.setUseStartDate((String) itemData.get("useStartDate"));
|
|
||||||
item.setUseEndDate((String) itemData.get("useEndDate"));
|
|
||||||
item.setQuantity((Integer) itemData.get("quantity"));
|
|
||||||
if (itemData.get("price") != null) {
|
|
||||||
item.setPrice(new java.math.BigDecimal(itemData.get("price").toString()));
|
|
||||||
}
|
|
||||||
item.setPriceCurrency((String) itemData.get("priceCurrency"));
|
|
||||||
|
|
||||||
// 处理订单项中的乘客信息
|
|
||||||
if (itemData.get("passengers") != null) {
|
|
||||||
Object passengersObj = itemData.get("passengers");
|
|
||||||
if (passengersObj instanceof List) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<Map<String, Object>> passengersData = (List<Map<String, Object>>) passengersObj;
|
|
||||||
List<CtripCreateOrderRequest.CtripPassenger> passengers = new ArrayList<>();
|
|
||||||
for (Map<String, Object> passengerData : passengersData) {
|
|
||||||
CtripCreateOrderRequest.CtripPassenger passenger = new CtripCreateOrderRequest.CtripPassenger();
|
|
||||||
passenger.setPassengerId((String) passengerData.get("passengerId"));
|
|
||||||
passenger.setName((String) passengerData.get("name"));
|
|
||||||
passenger.setMobile((String) passengerData.get("mobile"));
|
|
||||||
passenger.setCardNo((String) passengerData.get("cardNo"));
|
|
||||||
passengers.add(passenger);
|
|
||||||
}
|
|
||||||
item.setPassengers(passengers);
|
|
||||||
} else {
|
|
||||||
log.warn("订单项中的passengers字段不是List类型,跳过处理: {}", passengersObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
items.add(item);
|
|
||||||
}
|
|
||||||
requestBody.setItems(items);
|
|
||||||
} else {
|
|
||||||
log.warn("items字段不是List类型,跳过处理: {}", itemsObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理优惠券信息
|
|
||||||
if (body.get("coupons") != null) {
|
|
||||||
Object couponsObj = body.get("coupons");
|
|
||||||
if (couponsObj instanceof List) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<Map<String, Object>> couponsData = (List<Map<String, Object>>) couponsObj;
|
|
||||||
List<CtripCreateOrderRequest.CtripCoupon> coupons = new ArrayList<>();
|
|
||||||
for (Map<String, Object> couponData : couponsData) {
|
|
||||||
CtripCreateOrderRequest.CtripCoupon coupon = new CtripCreateOrderRequest.CtripCoupon();
|
|
||||||
coupon.setType((Integer) couponData.get("type"));
|
|
||||||
coupon.setCode((String) couponData.get("code"));
|
|
||||||
coupon.setName((String) couponData.get("name"));
|
|
||||||
if (couponData.get("amount") != null) {
|
|
||||||
coupon.setAmount(new java.math.BigDecimal(couponData.get("amount").toString()));
|
|
||||||
}
|
|
||||||
coupon.setAmountCurrency((String) couponData.get("amountCurrency"));
|
|
||||||
coupons.add(coupon);
|
|
||||||
}
|
|
||||||
requestBody.setCoupons(coupons);
|
|
||||||
} else {
|
|
||||||
log.warn("coupons字段不是List类型,跳过处理: {}", couponsObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createOrderRequest.setBody(requestBody);
|
|
||||||
|
|
||||||
// 调用订单服务处理
|
|
||||||
CtripCreateOrderResponse response = ctripOrderService.processCreateOrder(requestHeader, requestBody);
|
|
||||||
|
|
||||||
// 检查响应是否成功
|
|
||||||
if (response != null && response.getHeader() != null) {
|
|
||||||
log.info("CreatePreOrder处理完成,resultCode: {}", response.getHeader().getResultCode());
|
|
||||||
return response;
|
|
||||||
} else {
|
|
||||||
log.error("CreatePreOrder处理失败,响应为空");
|
|
||||||
return buildErrorResponse("1100", "CreatePreOrder处理失败,响应为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理CreatePreOrder请求异常", e);
|
|
||||||
return buildErrorResponse("1100", "处理CreatePreOrder请求异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-283
@@ -1,283 +0,0 @@
|
|||||||
package com.central.coupon.controller;
|
|
||||||
|
|
||||||
import com.central.coupon.dto.OrderQueryDTO;
|
|
||||||
import com.central.coupon.dto.ConsumeOrderDTO;
|
|
||||||
import com.central.coupon.dto.SimpleConsumeDTO;
|
|
||||||
import com.central.coupon.vo.OrderDetailVO;
|
|
||||||
import com.central.coupon.service.IOrderDetailService;
|
|
||||||
import com.central.coupon.entity.CtripOrder;
|
|
||||||
import com.central.coupon.mapper.CtripOrderMapper;
|
|
||||||
import com.central.coupon.controller.CtripConsumedController;
|
|
||||||
import com.central.coupon.model.CtripConsumedNoticeResponse;
|
|
||||||
import com.central.coupon.service.CtripConsumedService;
|
|
||||||
import com.central.common.model.PageResult;
|
|
||||||
import com.central.common.model.Result;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.central.coupon.entity.CtripPassenger;
|
|
||||||
import com.central.coupon.mapper.CtripPassengerMapper;
|
|
||||||
import com.central.coupon.entity.CtripContact;
|
|
||||||
import com.central.coupon.mapper.CtripContactMapper;
|
|
||||||
import com.central.coupon.entity.CtripOrderItem;
|
|
||||||
import com.central.coupon.mapper.CtripOrderItemMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单明细控制器
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/order-detail")
|
|
||||||
public class OrderDetailController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IOrderDetailService orderDetailService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripOrderMapper ctripOrderMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripConsumedService ctripConsumedService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripPassengerMapper ctripPassengerMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripContactMapper ctripContactMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CtripOrderItemMapper ctripOrderItemMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据二维码ID查询可核销的订单明细
|
|
||||||
*
|
|
||||||
* @param queryDTO 查询条件(codeId、page、size)
|
|
||||||
* @return 订单明细分页结果
|
|
||||||
*/
|
|
||||||
@PostMapping("/query")
|
|
||||||
public Result<PageResult<OrderDetailVO>> queryOrderDetails(@Valid @RequestBody OrderQueryDTO queryDTO) {
|
|
||||||
log.info("查询可核销订单明细,codeId: {},page: {},size: {}", queryDTO.getCodeId(), queryDTO.getPage(), queryDTO.getSize());
|
|
||||||
|
|
||||||
try {
|
|
||||||
PageResult<OrderDetailVO> result = orderDetailService.queryOrderDetails(queryDTO);
|
|
||||||
return Result.succeed(result);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询可核销订单明细异常", e);
|
|
||||||
return Result.failed("查询可核销订单明细失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单号查询订单明细
|
|
||||||
*
|
|
||||||
* @param otaOrderId 携程订单号
|
|
||||||
* @return 订单明细
|
|
||||||
*/
|
|
||||||
@GetMapping("/{otaOrderId}")
|
|
||||||
public Result<OrderDetailVO> getOrderDetail(@PathVariable String otaOrderId) {
|
|
||||||
log.info("查询订单明细,订单号: {}", otaOrderId);
|
|
||||||
|
|
||||||
try {
|
|
||||||
OrderDetailVO orderDetail = orderDetailService.getOrderDetail(otaOrderId);
|
|
||||||
if (orderDetail == null) {
|
|
||||||
return Result.failed("订单不存在");
|
|
||||||
}
|
|
||||||
return Result.succeed(orderDetail);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询订单明细异常,订单号: {}", otaOrderId, e);
|
|
||||||
return Result.failed("查询订单明细失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销订单
|
|
||||||
*
|
|
||||||
* @param consumeDTO 核销请求
|
|
||||||
* @return 核销结果
|
|
||||||
*/
|
|
||||||
@PostMapping("/consume")
|
|
||||||
public Result<Boolean> consumeOrder(@Valid @RequestBody ConsumeOrderDTO consumeDTO) {
|
|
||||||
log.info("核销订单,订单号: {}", consumeDTO.getOtaOrderId());
|
|
||||||
|
|
||||||
try {
|
|
||||||
boolean result = orderDetailService.consumeOrder(consumeDTO);
|
|
||||||
if (result) {
|
|
||||||
return Result.succeed(true, "核销成功");
|
|
||||||
} else {
|
|
||||||
return Result.failed("核销失败");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("核销订单异常,订单号: {}", consumeDTO.getOtaOrderId(), e);
|
|
||||||
return Result.failed("核销失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证订单是否可核销
|
|
||||||
*
|
|
||||||
* @param otaOrderId 携程订单号
|
|
||||||
* @return 是否可核销
|
|
||||||
*/
|
|
||||||
@GetMapping("/{otaOrderId}/validate")
|
|
||||||
public Result<Boolean> validateOrderForConsume(@PathVariable String otaOrderId) {
|
|
||||||
log.info("验证订单是否可核销,订单号: {}", otaOrderId);
|
|
||||||
|
|
||||||
try {
|
|
||||||
boolean canConsume = orderDetailService.validateOrderForConsume(otaOrderId);
|
|
||||||
return Result.succeed(canConsume);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("验证订单核销异常,订单号: {}", otaOrderId, e);
|
|
||||||
return Result.failed("验证失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 简化核销订单(单商品)
|
|
||||||
*
|
|
||||||
* @param consumeDTO 核销请求
|
|
||||||
* @return 核销结果
|
|
||||||
*/
|
|
||||||
@PostMapping("/consume-simple")
|
|
||||||
public Result<Boolean> consumeOrderSimple(@Valid @RequestBody SimpleConsumeDTO consumeDTO) {
|
|
||||||
log.info("简化核销订单,订单号: {}, 商品ID: {}, 数量: {}, 关联订单号: {}",
|
|
||||||
consumeDTO.getOtaOrderId(), consumeDTO.getItemId(), consumeDTO.getUseQuantity(), consumeDTO.getOrderNo());
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. 验证订单是否存在
|
|
||||||
CtripOrder order = ctripOrderMapper.selectByOtaOrderId(consumeDTO.getOtaOrderId());
|
|
||||||
if (order == null) {
|
|
||||||
log.error("订单不存在,订单号: {}", consumeDTO.getOtaOrderId());
|
|
||||||
return Result.failed("订单不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 验证订单是否可核销
|
|
||||||
if (!orderDetailService.validateOrderForConsume(consumeDTO.getOtaOrderId())) {
|
|
||||||
log.error("订单不可核销,订单号: {}", consumeDTO.getOtaOrderId());
|
|
||||||
return Result.failed("订单不可核销");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 建立订单关联关系(如果前端传入了orderNo)
|
|
||||||
if (consumeDTO.getOrderNo() != null && !consumeDTO.getOrderNo().trim().isEmpty()) {
|
|
||||||
if (order.getOrderNo() == null || order.getOrderNo().trim().isEmpty()) {
|
|
||||||
// 更新携程订单的orderNo字段
|
|
||||||
order.setOrderNo(consumeDTO.getOrderNo());
|
|
||||||
ctripOrderMapper.updateById(order);
|
|
||||||
log.info("建立订单关联关系,otaOrderId: {}, orderNo: {}",
|
|
||||||
consumeDTO.getOtaOrderId(), consumeDTO.getOrderNo());
|
|
||||||
} else if (!order.getOrderNo().equals(consumeDTO.getOrderNo())) {
|
|
||||||
log.warn("订单关联关系不匹配,数据库orderNo: {}, 前端orderNo: {}",
|
|
||||||
order.getOrderNo(), consumeDTO.getOrderNo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 调用携程核销服务
|
|
||||||
CtripConsumedController.CtripConsumeRequest request = new CtripConsumedController.CtripConsumeRequest();
|
|
||||||
request.setOtaOrderId(consumeDTO.getOtaOrderId());
|
|
||||||
request.setSupplierOrderId(order.getSupplierOrderId());
|
|
||||||
request.setItemId(consumeDTO.getItemId());
|
|
||||||
request.setUseQuantity(consumeDTO.getUseQuantity());
|
|
||||||
request.setRemark(consumeDTO.getRemark());
|
|
||||||
|
|
||||||
CtripConsumedNoticeResponse response = ctripConsumedService.consumeOrder(request);
|
|
||||||
boolean success = response != null && "0000".equals(response.getHeader().getResultCode());
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
log.info("核销成功,订单号: {}, 关联订单号: {}", consumeDTO.getOtaOrderId(), order.getOrderNo());
|
|
||||||
return Result.succeed(true, "核销成功");
|
|
||||||
} else {
|
|
||||||
log.error("核销失败,订单号: {}, 错误信息: {}", consumeDTO.getOtaOrderId(),
|
|
||||||
response != null ? response.getHeader().getResultMessage() : "未知错误");
|
|
||||||
return Result.failed("核销失败: " + (response != null ? response.getHeader().getResultMessage() : "未知错误"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("简化核销订单异常,订单号: {}", consumeDTO.getOtaOrderId(), e);
|
|
||||||
return Result.failed("核销失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调试接口 - 检查数据库中的数据
|
|
||||||
*/
|
|
||||||
@GetMapping("/debug/data")
|
|
||||||
public Result<Map<String, Object>> debugData() {
|
|
||||||
log.info("调试接口 - 检查数据库中的数据");
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. 检查订单总数
|
|
||||||
long orderCount = ctripOrderMapper.selectCount(null);
|
|
||||||
result.put("orderCount", orderCount);
|
|
||||||
|
|
||||||
// 2. 检查乘客总数
|
|
||||||
long passengerCount = ctripPassengerMapper.selectCount(null);
|
|
||||||
result.put("passengerCount", passengerCount);
|
|
||||||
|
|
||||||
// 3. 检查联系人总数
|
|
||||||
long contactCount = ctripContactMapper.selectCount(null);
|
|
||||||
result.put("contactCount", contactCount);
|
|
||||||
|
|
||||||
// 4. 检查订单项总数
|
|
||||||
long orderItemCount = ctripOrderItemMapper.selectCount(null);
|
|
||||||
result.put("orderItemCount", orderItemCount);
|
|
||||||
|
|
||||||
// 5. 查询最新的几个订单
|
|
||||||
List<CtripOrder> latestOrders = ctripOrderMapper.selectList(
|
|
||||||
new QueryWrapper<CtripOrder>().orderByDesc("create_time").last("LIMIT 5")
|
|
||||||
);
|
|
||||||
result.put("latestOrders", latestOrders.stream().map(order -> {
|
|
||||||
Map<String, Object> orderInfo = new HashMap<>();
|
|
||||||
orderInfo.put("id", order.getId());
|
|
||||||
orderInfo.put("otaOrderId", order.getOtaOrderId());
|
|
||||||
orderInfo.put("totalAmount", order.getTotalAmount());
|
|
||||||
orderInfo.put("status", order.getStatus());
|
|
||||||
orderInfo.put("createTime", order.getCreateTime());
|
|
||||||
return orderInfo;
|
|
||||||
}).collect(Collectors.toList()));
|
|
||||||
|
|
||||||
// 6. 查询手机号18322694510的乘客信息
|
|
||||||
List<CtripPassenger> passengers = ctripPassengerMapper.selectByPhone("18322694510");
|
|
||||||
result.put("passengersForPhone", passengers != null ? passengers.size() : 0);
|
|
||||||
if (passengers != null && !passengers.isEmpty()) {
|
|
||||||
result.put("passengerDetails", passengers.stream().map(passenger -> {
|
|
||||||
Map<String, Object> passengerInfo = new HashMap<>();
|
|
||||||
passengerInfo.put("id", passenger.getId());
|
|
||||||
passengerInfo.put("orderId", passenger.getOrderId());
|
|
||||||
passengerInfo.put("passengerName", passenger.getPassengerName());
|
|
||||||
passengerInfo.put("phone", passenger.getPhone());
|
|
||||||
return passengerInfo;
|
|
||||||
}).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 7. 查询手机号18322694510的联系人信息
|
|
||||||
List<CtripContact> contacts = ctripContactMapper.selectByMobile("18322694510");
|
|
||||||
result.put("contactsForPhone", contacts != null ? contacts.size() : 0);
|
|
||||||
if (contacts != null && !contacts.isEmpty()) {
|
|
||||||
result.put("contactDetails", contacts.stream().map(contact -> {
|
|
||||||
Map<String, Object> contactInfo = new HashMap<>();
|
|
||||||
contactInfo.put("id", contact.getId());
|
|
||||||
contactInfo.put("orderId", contact.getOrderId());
|
|
||||||
contactInfo.put("name", contact.getName());
|
|
||||||
contactInfo.put("mobile", contact.getMobile());
|
|
||||||
return contactInfo;
|
|
||||||
}).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.succeed(result);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("调试接口异常", e);
|
|
||||||
result.put("error", e.getMessage());
|
|
||||||
return Result.failed("调试接口异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.central.coupon.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销项目DTO
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class ConsumeItemDTO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 商品ID
|
|
||||||
*/
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PLU码
|
|
||||||
*/
|
|
||||||
private String plu;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销数量
|
|
||||||
*/
|
|
||||||
private Integer quantity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 乘客ID列表
|
|
||||||
*/
|
|
||||||
private String[] passengerIds;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 凭证ID列表
|
|
||||||
*/
|
|
||||||
private String[] voucherIds;
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.central.coupon.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销订单DTO
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class ConsumeOrderDTO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单号
|
|
||||||
*/
|
|
||||||
private String otaOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 供应商订单号
|
|
||||||
*/
|
|
||||||
private String supplierOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销项目列表
|
|
||||||
*/
|
|
||||||
private List<ConsumeItemDTO> items;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.central.coupon.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import javax.validation.constraints.Min;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单查询DTO
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class OrderQueryDTO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 二维码ID(来自订单的codeId)
|
|
||||||
*/
|
|
||||||
@NotNull(message = "二维码ID不能为空")
|
|
||||||
private String codeId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否只查询可核销的订单(内部控制,前端不必传,默认true)
|
|
||||||
*/
|
|
||||||
private Boolean onlyConsumable = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 页码
|
|
||||||
*/
|
|
||||||
@Min(value = 1, message = "页码必须大于等于1")
|
|
||||||
private Integer page = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 页大小
|
|
||||||
*/
|
|
||||||
@Min(value = 1, message = "页大小必须大于等于1")
|
|
||||||
private Integer size = 10;
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.central.coupon.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 简化核销DTO
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class SimpleConsumeDTO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单号
|
|
||||||
*/
|
|
||||||
private String otaOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关联的订单中心订单号
|
|
||||||
*/
|
|
||||||
private String orderNo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 商品ID
|
|
||||||
*/
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销数量
|
|
||||||
*/
|
|
||||||
private Integer useQuantity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注信息
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券实体类
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_coupon")
|
|
||||||
public class Coupon implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户ID
|
|
||||||
*/
|
|
||||||
private String tenantId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券名称
|
|
||||||
*/
|
|
||||||
private String couponName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券类型
|
|
||||||
*/
|
|
||||||
private String couponType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券金额
|
|
||||||
*/
|
|
||||||
private BigDecimal amount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 货币类型
|
|
||||||
*/
|
|
||||||
private String amountCurrency;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户手机号
|
|
||||||
*/
|
|
||||||
private String userPhone;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程优惠券ID
|
|
||||||
*/
|
|
||||||
private String ctripCouponId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单ID
|
|
||||||
*/
|
|
||||||
private String ctripOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态:UNUSED-未使用,USED-已使用,EXPIRED-已过期,VOIDED-已作废
|
|
||||||
*/
|
|
||||||
private String status;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 有效期开始时间
|
|
||||||
*/
|
|
||||||
private Date validStartTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 有效期结束时间
|
|
||||||
*/
|
|
||||||
private Date validEndTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用时间
|
|
||||||
*/
|
|
||||||
private Date usedTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用订单号
|
|
||||||
*/
|
|
||||||
private String usedOrderNo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建人
|
|
||||||
*/
|
|
||||||
private String createBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新人
|
|
||||||
*/
|
|
||||||
private String updateBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private Date updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
-118
@@ -1,118 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单ID
|
|
||||||
*/
|
|
||||||
@TableField("ota_order_id")
|
|
||||||
private String otaOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 供应商订单ID
|
|
||||||
*/
|
|
||||||
@TableField("supplier_order_id")
|
|
||||||
private String supplierOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 序列号ID
|
|
||||||
*/
|
|
||||||
@TableField("sequence_id")
|
|
||||||
private String sequenceId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 商品ID
|
|
||||||
*/
|
|
||||||
@TableField("item_id")
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用开始日期
|
|
||||||
*/
|
|
||||||
@TableField("use_start_date")
|
|
||||||
private String useStartDate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用结束日期
|
|
||||||
*/
|
|
||||||
@TableField("use_end_date")
|
|
||||||
private String useEndDate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 总数量
|
|
||||||
*/
|
|
||||||
@TableField("quantity")
|
|
||||||
private Integer quantity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 已使用数量
|
|
||||||
*/
|
|
||||||
@TableField("use_quantity")
|
|
||||||
private Integer useQuantity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 乘客ID列表(JSON格式)
|
|
||||||
*/
|
|
||||||
@TableField("passenger_ids")
|
|
||||||
private String passengerIds;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 凭证ID列表(JSON格式)
|
|
||||||
*/
|
|
||||||
@TableField("voucher_ids")
|
|
||||||
private String voucherIds;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注信息
|
|
||||||
*/
|
|
||||||
@TableField("remark")
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 折扣政策列表(JSON格式)
|
|
||||||
*/
|
|
||||||
@TableField("discount_policy")
|
|
||||||
private String discountPolicy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 损失金额
|
|
||||||
*/
|
|
||||||
@TableField("lost_amount")
|
|
||||||
private Integer lostAmount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 损失金额货币类型
|
|
||||||
*/
|
|
||||||
@TableField("lost_amount_currency")
|
|
||||||
private String lostAmountCurrency;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
}
|
|
||||||
-61
@@ -1,61 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销乘客表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_consumed_passenger")
|
|
||||||
public class CtripConsumedPassenger implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销ID
|
|
||||||
*/
|
|
||||||
private Long consumedId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 乘客ID
|
|
||||||
*/
|
|
||||||
private String passengerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 乘客姓名
|
|
||||||
*/
|
|
||||||
private String passengerName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除:0-未删除,1-已删除
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
-61
@@ -1,61 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销凭证表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_consumed_voucher")
|
|
||||||
public class CtripConsumedVoucher implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核销ID
|
|
||||||
*/
|
|
||||||
private Long consumedId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 凭证编号
|
|
||||||
*/
|
|
||||||
private String voucherId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 凭证码
|
|
||||||
*/
|
|
||||||
private String voucherCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除:0-未删除,1-已删除
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程联系人信息表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_contact")
|
|
||||||
public class CtripContact implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单ID
|
|
||||||
*/
|
|
||||||
private Long orderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 联系人姓名
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 联系人电话
|
|
||||||
*/
|
|
||||||
private String mobile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 联系人邮箱
|
|
||||||
*/
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除:0-未删除,1-已删除
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程优惠券信息表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_coupon")
|
|
||||||
public class CtripCoupon implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单ID
|
|
||||||
*/
|
|
||||||
private Long orderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券类型
|
|
||||||
*/
|
|
||||||
private String couponType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券代码
|
|
||||||
*/
|
|
||||||
private String couponCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券名称
|
|
||||||
*/
|
|
||||||
private String couponName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券金额
|
|
||||||
*/
|
|
||||||
private BigDecimal couponAmount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 货币类型
|
|
||||||
*/
|
|
||||||
private String currency;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券状态:1-有效,2-已使用,3-已过期
|
|
||||||
*/
|
|
||||||
private Integer couponStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime useTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除:0-未删除,1-已删除
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
-83
@@ -1,83 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_dist_order")
|
|
||||||
public class CtripDistOrder {
|
|
||||||
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@TableField("tenant_id")
|
|
||||||
private String tenantId;
|
|
||||||
|
|
||||||
@TableField("order_no")
|
|
||||||
private String orderNo;
|
|
||||||
|
|
||||||
@TableField("ctrip_order_id")
|
|
||||||
private Long ctripOrderId;
|
|
||||||
|
|
||||||
@TableField("ctrip_product_id")
|
|
||||||
private Long ctripProductId;
|
|
||||||
|
|
||||||
@TableField("ctrip_package_id")
|
|
||||||
private Long ctripPackageId;
|
|
||||||
|
|
||||||
@TableField("ctrip_resource_id")
|
|
||||||
private Long ctripResourceId;
|
|
||||||
|
|
||||||
@TableField("distributor_order_id")
|
|
||||||
private String distributorOrderId;
|
|
||||||
|
|
||||||
@TableField("order_amount")
|
|
||||||
private BigDecimal orderAmount;
|
|
||||||
|
|
||||||
@TableField("currency")
|
|
||||||
private String currency;
|
|
||||||
|
|
||||||
@TableField("ctrip_order_status")
|
|
||||||
private String ctripOrderStatus;
|
|
||||||
|
|
||||||
@TableField("consume_status")
|
|
||||||
private Integer consumeStatus;
|
|
||||||
|
|
||||||
@TableField("consume_time")
|
|
||||||
private LocalDateTime consumeTime;
|
|
||||||
|
|
||||||
@TableField("refund_status")
|
|
||||||
private Integer refundStatus;
|
|
||||||
|
|
||||||
@TableField("refund_time")
|
|
||||||
private LocalDateTime refundTime;
|
|
||||||
|
|
||||||
@TableField("refund_amount")
|
|
||||||
private BigDecimal refundAmount;
|
|
||||||
|
|
||||||
@TableField("error_msg")
|
|
||||||
private String errorMsg;
|
|
||||||
|
|
||||||
@TableField("retry_count")
|
|
||||||
private Integer retryCount;
|
|
||||||
|
|
||||||
@TableField("remark")
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
@TableField("deleted")
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_order")
|
|
||||||
public class CtripOrder implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单号
|
|
||||||
*/
|
|
||||||
private String otaOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关联的订单中心订单号
|
|
||||||
*/
|
|
||||||
private String orderNo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 供应商订单号
|
|
||||||
*/
|
|
||||||
private String supplierOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程批次流水号
|
|
||||||
*/
|
|
||||||
private String sequenceId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 确认类型:1-仅通知,2-需确认
|
|
||||||
*/
|
|
||||||
private Integer confirmType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 最晚确认时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime orderLastConfirmTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单状态:0-待确认,1-已确认,2-已取消,3-已过期
|
|
||||||
*/
|
|
||||||
private Integer status;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单总金额
|
|
||||||
*/
|
|
||||||
private BigDecimal totalAmount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 货币类型
|
|
||||||
*/
|
|
||||||
private String currency;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建人
|
|
||||||
*/
|
|
||||||
private String createBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新人
|
|
||||||
*/
|
|
||||||
private String updateBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户ID
|
|
||||||
*/
|
|
||||||
private String tenantId;
|
|
||||||
}
|
|
||||||
-149
@@ -1,149 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单项表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_order_item")
|
|
||||||
public class CtripOrderItem implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单ID
|
|
||||||
*/
|
|
||||||
private Long orderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单项编号
|
|
||||||
*/
|
|
||||||
@TableField("item_id")
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单项名称
|
|
||||||
*/
|
|
||||||
private String itemName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单项类型
|
|
||||||
*/
|
|
||||||
private String itemType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PLU编码
|
|
||||||
*/
|
|
||||||
private String plu;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数量
|
|
||||||
*/
|
|
||||||
private Integer quantity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单价
|
|
||||||
*/
|
|
||||||
private BigDecimal unitPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 原价
|
|
||||||
*/
|
|
||||||
private BigDecimal price;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 销售价
|
|
||||||
*/
|
|
||||||
private BigDecimal salePrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 总价
|
|
||||||
*/
|
|
||||||
private BigDecimal totalPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 货币类型
|
|
||||||
*/
|
|
||||||
private String currency;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用开始日期
|
|
||||||
*/
|
|
||||||
private LocalDate useStartDate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用结束日期
|
|
||||||
*/
|
|
||||||
private LocalDate useEndDate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 凭证ID(用于PayPreOrderConfirm)
|
|
||||||
*/
|
|
||||||
private String voucherId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 乘客ID(用于PayPreOrderConfirm)
|
|
||||||
*/
|
|
||||||
private String passengerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 乘客凭证ID(用于PayPreOrderConfirm,与voucherId不同)
|
|
||||||
*/
|
|
||||||
private String passengerVoucherId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建人
|
|
||||||
*/
|
|
||||||
private String createBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新人
|
|
||||||
*/
|
|
||||||
private String updateBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户ID
|
|
||||||
*/
|
|
||||||
private String tenantId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除:0-未删除,1-已删除
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
-87
@@ -1,87 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程乘客信息表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_passenger")
|
|
||||||
public class CtripPassenger implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单ID
|
|
||||||
*/
|
|
||||||
private Long orderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单项编号
|
|
||||||
*/
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 乘客ID
|
|
||||||
*/
|
|
||||||
private String passengerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 乘客姓名
|
|
||||||
*/
|
|
||||||
private String passengerName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 乘客类型:ADULT-成人,CHILD-儿童,INFANT-婴儿
|
|
||||||
*/
|
|
||||||
private String passengerType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 证件类型:ID_CARD-身份证,PASSPORT-护照
|
|
||||||
*/
|
|
||||||
private String idType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 证件号码
|
|
||||||
*/
|
|
||||||
private String idNumber;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 手机号码
|
|
||||||
*/
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除:0-未删除,1-已删除
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程退款表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_refund")
|
|
||||||
public class CtripRefund implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单号
|
|
||||||
*/
|
|
||||||
private String otaOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 供应商订单号
|
|
||||||
*/
|
|
||||||
private String supplierOrderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程批次流水号
|
|
||||||
*/
|
|
||||||
private String sequenceId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款金额
|
|
||||||
*/
|
|
||||||
private BigDecimal refundAmount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 货币类型
|
|
||||||
*/
|
|
||||||
private String currency;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款状态:0-待确认,1-已确认,2-已拒绝
|
|
||||||
*/
|
|
||||||
private Integer refundStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 确认结果码
|
|
||||||
*/
|
|
||||||
private String confirmResultCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 确认结果信息
|
|
||||||
*/
|
|
||||||
private String confirmResultMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 最晚确认时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime lastConfirmTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建人
|
|
||||||
*/
|
|
||||||
private String createBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新人
|
|
||||||
*/
|
|
||||||
private String updateBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户ID
|
|
||||||
*/
|
|
||||||
private String tenantId;
|
|
||||||
}
|
|
||||||
-72
@@ -1,72 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程退款项表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_refund_item")
|
|
||||||
public class CtripRefundItem implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款ID
|
|
||||||
*/
|
|
||||||
private Long refundId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单项编号
|
|
||||||
*/
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 供应商产品最小单位
|
|
||||||
*/
|
|
||||||
private String plu;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款金额
|
|
||||||
*/
|
|
||||||
private BigDecimal refundAmount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 货币类型
|
|
||||||
*/
|
|
||||||
private String currency;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除:0-未删除,1-已删除
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
package com.central.coupon.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程凭证信息表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@TableName("t_ctrip_voucher")
|
|
||||||
public class CtripVoucher implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键ID
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单ID
|
|
||||||
*/
|
|
||||||
private Long orderId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单项编号
|
|
||||||
*/
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 凭证编号
|
|
||||||
*/
|
|
||||||
private String voucherId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 凭证码
|
|
||||||
*/
|
|
||||||
private String voucherCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 凭证类型
|
|
||||||
*/
|
|
||||||
private String voucherType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 凭证状态:1-未使用,2-已使用,3-已过期
|
|
||||||
*/
|
|
||||||
private Integer voucherStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime useTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除:0-未删除,1-已删除
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
}
|
|
||||||
-89
@@ -1,89 +0,0 @@
|
|||||||
package com.central.coupon.enums;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单状态枚举
|
|
||||||
* 用于映射数字状态值和字符串状态值
|
|
||||||
*/
|
|
||||||
public enum CtripOrderStatus {
|
|
||||||
|
|
||||||
// 数字状态值 -> 字符串状态值映射
|
|
||||||
PENDING(0, "PENDING", "待确认"),
|
|
||||||
CONFIRMED(1, "CONFIRMED", "已确认"),
|
|
||||||
CANCELLED(2, "CANCELLED", "已取消"),
|
|
||||||
EXPIRED(3, "EXPIRED", "已过期"),
|
|
||||||
PARTIAL_CANCELLED(4, "PARTIAL_CANCELLED", "部分取消"),
|
|
||||||
FULLY_CANCELLED(5, "FULLY_CANCELLED", "全部取消"),
|
|
||||||
PICKED_UP(6, "PICKED_UP", "已取物品"),
|
|
||||||
PARTIAL_USED(7, "PARTIAL_USED", "部分使用"),
|
|
||||||
FULLY_USED(8, "FULLY_USED", "全部使用"),
|
|
||||||
RETURNED(9, "RETURNED", "已还物品"),
|
|
||||||
EXPIRED_AFTER_PAYMENT(10, "EXPIRED_AFTER_PAYMENT", "已过期"),
|
|
||||||
WAITING_PAYMENT(11, "WAITING_PAYMENT", "待支付"),
|
|
||||||
PAYMENT_PENDING(12, "PAYMENT_PENDING", "支付待确认"),
|
|
||||||
PAYMENT_CONFIRMED(13, "PAYMENT_CONFIRMED", "支付已确认"),
|
|
||||||
PRE_ORDER_CANCELLED(14, "PRE_ORDER_CANCELLED", "预下单取消成功"),
|
|
||||||
// 管理后台主动发起退款的状态
|
|
||||||
ADMIN_REFUNDING(15, "ADMIN_REFUNDING", "退款中"),
|
|
||||||
ADMIN_REFUNDED(16, "ADMIN_REFUNDED", "已退款"),
|
|
||||||
ADMIN_PART_REFUNDED(17, "ADMIN_PART_REFUNDED", "部分退款");
|
|
||||||
|
|
||||||
private final int numericValue;
|
|
||||||
private final String stringValue;
|
|
||||||
private final String description;
|
|
||||||
|
|
||||||
CtripOrderStatus(int numericValue, String stringValue, String description) {
|
|
||||||
this.numericValue = numericValue;
|
|
||||||
this.stringValue = stringValue;
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumericValue() {
|
|
||||||
return numericValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStringValue() {
|
|
||||||
return stringValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据数字值获取状态枚举
|
|
||||||
*/
|
|
||||||
public static CtripOrderStatus fromNumericValue(int numericValue) {
|
|
||||||
for (CtripOrderStatus status : values()) {
|
|
||||||
if (status.numericValue == numericValue) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Unknown numeric status value: " + numericValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据字符串值获取状态枚举
|
|
||||||
*/
|
|
||||||
public static CtripOrderStatus fromStringValue(String stringValue) {
|
|
||||||
for (CtripOrderStatus status : values()) {
|
|
||||||
if (status.stringValue.equals(stringValue)) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Unknown string status value: " + stringValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据数字值获取字符串值
|
|
||||||
*/
|
|
||||||
public static String getStringValue(int numericValue) {
|
|
||||||
return fromNumericValue(numericValue).stringValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据字符串值获取数字值
|
|
||||||
*/
|
|
||||||
public static int getNumericValue(String stringValue) {
|
|
||||||
return fromStringValue(stringValue).numericValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-139
@@ -1,139 +0,0 @@
|
|||||||
package com.central.coupon.exception;
|
|
||||||
|
|
||||||
import com.central.common.model.Result;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全局异常处理器
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@RestControllerAdvice
|
|
||||||
public class GlobalExceptionHandler {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券不存在异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(CouponNotFoundException.class)
|
|
||||||
public Result<String> handleCouponNotFoundException(CouponNotFoundException e) {
|
|
||||||
log.error("优惠券不存在异常", e);
|
|
||||||
return Result.failed("COUPON_NOT_FOUND", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券状态不正确异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(CouponInvalidException.class)
|
|
||||||
public Result<String> handleCouponInvalidException(CouponInvalidException e) {
|
|
||||||
log.error("优惠券状态不正确异常", e);
|
|
||||||
return Result.failed("COUPON_INVALID", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券已过期异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(CouponExpiredException.class)
|
|
||||||
public Result<String> handleCouponExpiredException(CouponExpiredException e) {
|
|
||||||
log.error("优惠券已过期异常", e);
|
|
||||||
return Result.failed("COUPON_EXPIRED", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券使用条件不满足异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(CouponUsageException.class)
|
|
||||||
public Result<String> handleCouponUsageException(CouponUsageException e) {
|
|
||||||
log.error("优惠券使用条件不满足异常", e);
|
|
||||||
return Result.failed("COUPON_USAGE_ERROR", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销失败异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(CouponVerifyException.class)
|
|
||||||
public Result<String> handleCouponVerifyException(CouponVerifyException e) {
|
|
||||||
log.error("携程核销失败异常", e);
|
|
||||||
return Result.failed("COUPON_VERIFY_FAILED", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券更新失败异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(CouponUpdateException.class)
|
|
||||||
public Result<String> handleCouponUpdateException(CouponUpdateException e) {
|
|
||||||
log.error("优惠券更新失败异常", e);
|
|
||||||
return Result.failed("COUPON_UPDATE_FAILED", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 参数验证异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(IllegalArgumentException.class)
|
|
||||||
public Result<String> handleIllegalArgumentException(IllegalArgumentException e) {
|
|
||||||
log.error("参数验证异常", e);
|
|
||||||
return Result.failed("PARAM_ERROR", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HTTP消息读取异常(请求体解析失败)
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(HttpMessageNotReadableException.class)
|
|
||||||
public Result<String> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
|
||||||
log.error("HTTP消息读取异常,请求体解析失败", e);
|
|
||||||
String errorMessage = "请求体格式错误";
|
|
||||||
if (e.getMessage() != null && e.getMessage().contains("empty String")) {
|
|
||||||
errorMessage = "请求体不能为空,请提供有效的JSON数据";
|
|
||||||
} else if (e.getMessage() != null && e.getMessage().contains("JSON parse error")) {
|
|
||||||
errorMessage = "JSON格式错误,请检查请求体格式";
|
|
||||||
}
|
|
||||||
return Result.failed("REQUEST_BODY_ERROR", errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(Exception.class)
|
|
||||||
public Result<String> handleException(Exception e) {
|
|
||||||
log.error("系统异常", e);
|
|
||||||
return Result.failed("SYSTEM_ERROR", "系统异常:" + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 自定义异常类
|
|
||||||
public static class CouponNotFoundException extends RuntimeException {
|
|
||||||
public CouponNotFoundException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CouponInvalidException extends RuntimeException {
|
|
||||||
public CouponInvalidException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CouponExpiredException extends RuntimeException {
|
|
||||||
public CouponExpiredException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CouponUsageException extends RuntimeException {
|
|
||||||
public CouponUsageException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CouponVerifyException extends RuntimeException {
|
|
||||||
public CouponVerifyException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CouponUpdateException extends RuntimeException {
|
|
||||||
public CouponUpdateException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-50
@@ -1,50 +0,0 @@
|
|||||||
package com.central.coupon.feign;
|
|
||||||
|
|
||||||
import com.central.common.constant.ServiceNameConstants;
|
|
||||||
import com.central.common.model.Result;
|
|
||||||
import com.central.coupon.feign.dto.QrCodeInfo;
|
|
||||||
import com.central.coupon.feign.dto.OrderInfo;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, dismiss404 = true)
|
|
||||||
public interface OrderCenterService {
|
|
||||||
@GetMapping("/qrcode/{codeId}")
|
|
||||||
Result<QrCodeInfo> getQrCode(@PathVariable("codeId") String codeId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单号获取订单信息
|
|
||||||
*/
|
|
||||||
@GetMapping("/order/{orderNo}")
|
|
||||||
Result<OrderInfo> getOrderByOrderNo(@PathVariable("orderNo") String orderNo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新订单状态为已支付(优惠券核销成功后调用)
|
|
||||||
*/
|
|
||||||
@PostMapping("/order/{orderNo}/status/paid")
|
|
||||||
Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新订单状态为退款中
|
|
||||||
*/
|
|
||||||
@PostMapping("/order/{orderNo}/status/refunding")
|
|
||||||
Result<String> updateOrderStatusToRefunding(@PathVariable("orderNo") String orderNo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新订单状态为已退款
|
|
||||||
*/
|
|
||||||
@PostMapping("/order/{orderNo}/status/refunded")
|
|
||||||
Result<String> updateOrderStatusToRefunded(@PathVariable("orderNo") String orderNo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建退款记录
|
|
||||||
*/
|
|
||||||
@PostMapping("/refund/ctrip/{orderNo}")
|
|
||||||
Result<String> createCtripRefund(@PathVariable("orderNo") String orderNo, @RequestBody Map<String, Object> refundInfo);
|
|
||||||
}
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package com.central.coupon.feign;
|
|
||||||
|
|
||||||
import com.central.common.constant.ServiceNameConstants;
|
|
||||||
import com.central.coupon.feign.dto.SysUserDTO;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
|
|
||||||
@FeignClient(name = ServiceNameConstants.USER_SERVICE, dismiss404 = true)
|
|
||||||
public interface UserCenterService {
|
|
||||||
@GetMapping("/users/{id}")
|
|
||||||
SysUserDTO findUserById(@PathVariable("id") Long id);
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
package com.central.coupon.feign.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单信息DTO
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class OrderInfo {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单ID
|
|
||||||
*/
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单号
|
|
||||||
*/
|
|
||||||
private String orderNo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户ID
|
|
||||||
*/
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 景区ID
|
|
||||||
*/
|
|
||||||
private Long tourismId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单金额
|
|
||||||
*/
|
|
||||||
private String orderAmount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单状态
|
|
||||||
*/
|
|
||||||
private Integer orderStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 支付类型(1:微信支付,2:优惠券支付)
|
|
||||||
*/
|
|
||||||
private Integer payType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 支付时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime payTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 二维码ID
|
|
||||||
*/
|
|
||||||
private String codeId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备SN
|
|
||||||
*/
|
|
||||||
private String deviceSn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户ID
|
|
||||||
*/
|
|
||||||
private String tenantId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.central.coupon.feign.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class QrCodeInfo {
|
|
||||||
private String codeId;
|
|
||||||
private String price;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.central.coupon.feign.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class SysUserDTO {
|
|
||||||
private Long id;
|
|
||||||
private String mobile;
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
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.coupon.entity.Coupon;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
import org.apache.ibatis.annotations.Update;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 优惠券Mapper接口
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface CouponMapper extends BaseMapper<Coupon> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询优惠券列表
|
|
||||||
*/
|
|
||||||
IPage<Coupon> selectCouponPage(Page<Coupon> page, @Param("coupon") Coupon coupon);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据手机号查询用户优惠券
|
|
||||||
*/
|
|
||||||
List<Coupon> selectByUserPhone(@Param("userPhone") String userPhone);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据手机号查询可用优惠券
|
|
||||||
*/
|
|
||||||
List<Coupon> selectAvailableByUserPhone(@Param("userPhone") String userPhone);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据携程优惠券ID查询
|
|
||||||
*/
|
|
||||||
Coupon selectByCtripCouponId(@Param("ctripCouponId") String ctripCouponId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据携程订单ID查询优惠券
|
|
||||||
*/
|
|
||||||
List<Coupon> selectByCtripOrderId(@Param("ctripOrderId") String ctripOrderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据携程优惠券ID模糊查询优惠券
|
|
||||||
*/
|
|
||||||
List<Coupon> selectByCtripCouponIdLike(@Param("ctripCouponIdPattern") String ctripCouponIdPattern);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单号查询使用的优惠券
|
|
||||||
*/
|
|
||||||
Coupon selectByUsedOrderNo(@Param("usedOrderNo") String usedOrderNo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新优惠券状态为已使用
|
|
||||||
*/
|
|
||||||
int updateCouponUsed(@Param("id") Long id, @Param("usedOrderNo") String usedOrderNo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量更新过期优惠券状态
|
|
||||||
*/
|
|
||||||
int updateExpiredCoupons();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查用户手机号和携程优惠券ID是否已存在
|
|
||||||
*/
|
|
||||||
int countByUserPhoneAndCtripCouponId(@Param("userPhone") String userPhone, @Param("ctripCouponId") String ctripCouponId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新优惠券状态(避免DateMetaObjectHandler干扰)
|
|
||||||
*
|
|
||||||
* @param id 优惠券ID
|
|
||||||
* @param status 状态
|
|
||||||
* @return 更新结果
|
|
||||||
*/
|
|
||||||
int updateCouponStatus(@Param("id") Long id, @Param("status") String status);
|
|
||||||
}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
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> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据携程订单ID查询核销记录
|
|
||||||
*/
|
|
||||||
List<CtripConsumed> selectByOtaOrderId(@Param("otaOrderId") String otaOrderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据序列号ID查询核销记录
|
|
||||||
*/
|
|
||||||
CtripConsumed selectBySequenceId(@Param("sequenceId") String sequenceId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据供应商订单ID查询核销记录
|
|
||||||
*/
|
|
||||||
List<CtripConsumed> selectBySupplierOrderId(@Param("supplierOrderId") String supplierOrderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据商品ID查询核销记录
|
|
||||||
*/
|
|
||||||
List<CtripConsumed> selectByItemId(@Param("itemId") String itemId);
|
|
||||||
}
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据乘客ID查询核销乘客记录
|
|
||||||
*
|
|
||||||
* @param passengerId 乘客ID
|
|
||||||
* @return 核销乘客记录列表
|
|
||||||
*/
|
|
||||||
List<CtripConsumedPassenger> selectByPassengerId(@Param("passengerId") String passengerId);
|
|
||||||
}
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据凭证编号查询核销凭证记录
|
|
||||||
*
|
|
||||||
* @param voucherId 凭证编号
|
|
||||||
* @return 核销凭证记录列表
|
|
||||||
*/
|
|
||||||
List<CtripConsumedVoucher> selectByVoucherId(@Param("voucherId") String voucherId);
|
|
||||||
}
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
package com.central.coupon.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.central.coupon.entity.CtripContact;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程联系人Mapper接口
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface CtripContactMapper extends BaseMapper<CtripContact> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单ID查询联系人列表
|
|
||||||
*
|
|
||||||
* @param orderId 订单ID
|
|
||||||
* @return 联系人列表
|
|
||||||
*/
|
|
||||||
List<CtripContact> selectByOrderId(@Param("orderId") Long orderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据手机号查询联系人列表
|
|
||||||
*
|
|
||||||
* @param mobile 手机号
|
|
||||||
* @return 联系人列表
|
|
||||||
*/
|
|
||||||
List<CtripContact> selectByMobile(@Param("mobile") String mobile);
|
|
||||||
}
|
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
package com.central.coupon.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.central.coupon.entity.CtripCoupon;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程优惠券Mapper接口
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface CtripCouponMapper extends BaseMapper<CtripCoupon> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单ID查询优惠券列表
|
|
||||||
*
|
|
||||||
* @param orderId 订单ID
|
|
||||||
* @return 优惠券列表
|
|
||||||
*/
|
|
||||||
List<CtripCoupon> selectByOrderId(@Param("orderId") Long orderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据优惠券代码查询优惠券
|
|
||||||
*
|
|
||||||
* @param couponCode 优惠券代码
|
|
||||||
* @return 优惠券信息
|
|
||||||
*/
|
|
||||||
CtripCoupon selectByCouponCode(@Param("couponCode") String couponCode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单ID和优惠券状态查询优惠券
|
|
||||||
*
|
|
||||||
* @param orderId 订单ID
|
|
||||||
* @param couponStatus 优惠券状态
|
|
||||||
* @return 优惠券列表
|
|
||||||
*/
|
|
||||||
List<CtripCoupon> selectByOrderIdAndStatus(@Param("orderId") Long orderId, @Param("couponStatus") Integer couponStatus);
|
|
||||||
}
|
|
||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
package com.central.coupon.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.central.coupon.entity.CtripDistOrder;
|
|
||||||
import java.util.List;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface CtripDistOrderMapper extends BaseMapper<CtripDistOrder> {
|
|
||||||
|
|
||||||
// 根据本地订单号查询
|
|
||||||
CtripDistOrder selectByOrderNo(@Param("orderNo") String orderNo);
|
|
||||||
|
|
||||||
// 查询 N 天前创建、已确认且未核销的订单
|
|
||||||
List<CtripDistOrder> selectPendingConsumeOrders(@Param("daysAgo") int daysAgo);
|
|
||||||
|
|
||||||
// 根据分销商订单 ID 查询
|
|
||||||
CtripDistOrder selectByDistributorOrderId(@Param("distributorOrderId") String distributorOrderId);
|
|
||||||
}
|
|
||||||
-58
@@ -1,58 +0,0 @@
|
|||||||
package com.central.coupon.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.central.coupon.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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单项编号查询订单项
|
|
||||||
*
|
|
||||||
* @param itemId 订单项编号
|
|
||||||
* @return 订单项信息
|
|
||||||
*/
|
|
||||||
CtripOrderItem selectByItemId(@Param("itemId") String itemId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单ID和订单项编号查询订单项
|
|
||||||
*
|
|
||||||
* @param orderId 订单ID
|
|
||||||
* @param itemId 订单项编号
|
|
||||||
* @return 订单项信息
|
|
||||||
*/
|
|
||||||
CtripOrderItem selectByOrderIdAndItemId(@Param("orderId") Long orderId, @Param("itemId") String itemId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据携程订单号和订单项编号查询订单项
|
|
||||||
*
|
|
||||||
* @param otaOrderId 携程订单号
|
|
||||||
* @param itemId 订单项编号
|
|
||||||
* @return 订单项信息
|
|
||||||
*/
|
|
||||||
CtripOrderItem selectByOtaOrderIdAndItemId(@Param("otaOrderId") String otaOrderId, @Param("itemId") String itemId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据携程订单号和PLU查询订单项
|
|
||||||
*
|
|
||||||
* @param otaOrderId 携程订单号
|
|
||||||
* @param plu PLU编码
|
|
||||||
* @return 订单项信息
|
|
||||||
*/
|
|
||||||
CtripOrderItem selectByOtaOrderIdAndPlu(@Param("otaOrderId") String otaOrderId, @Param("plu") String plu);
|
|
||||||
}
|
|
||||||
-56
@@ -1,56 +0,0 @@
|
|||||||
package com.central.coupon.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.central.coupon.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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单中心订单号查询携程订单
|
|
||||||
*/
|
|
||||||
CtripOrder selectByOrderNo(@Param("orderNo") String orderNo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据携程订单号更新订单
|
|
||||||
*/
|
|
||||||
int updateByOtaOrderId(CtripOrder order);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据供应商订单号查询订单
|
|
||||||
*
|
|
||||||
* @param supplierOrderId 供应商订单号
|
|
||||||
* @return 订单信息
|
|
||||||
*/
|
|
||||||
CtripOrder selectBySupplierOrderId(@Param("supplierOrderId") String supplierOrderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据流水号查询订单
|
|
||||||
*
|
|
||||||
* @param sequenceId 流水号
|
|
||||||
* @return 订单信息
|
|
||||||
*/
|
|
||||||
CtripOrder selectBySequenceId(@Param("sequenceId") String sequenceId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新订单的 order_status 字段
|
|
||||||
*
|
|
||||||
* @param orderId 订单ID
|
|
||||||
* @param orderStatus 订单状态(字符串值)
|
|
||||||
* @return 更新结果
|
|
||||||
*/
|
|
||||||
int updateOrderStatus(@Param("orderId") Long orderId, @Param("orderStatus") String orderStatus);
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
package com.central.coupon.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.central.coupon.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 orderId 订单ID
|
|
||||||
* @return 乘客列表
|
|
||||||
*/
|
|
||||||
List<CtripPassenger> selectByOrderId(@Param("orderId") Long orderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单项编号查询乘客列表
|
|
||||||
*
|
|
||||||
* @param itemId 订单项编号
|
|
||||||
* @return 乘客列表
|
|
||||||
*/
|
|
||||||
List<CtripPassenger> selectByItemId(@Param("itemId") String itemId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据乘客ID查询乘客信息
|
|
||||||
*
|
|
||||||
* @param passengerId 乘客ID
|
|
||||||
* @return 乘客信息
|
|
||||||
*/
|
|
||||||
CtripPassenger selectByPassengerId(@Param("passengerId") String passengerId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据手机号查询乘客列表
|
|
||||||
*
|
|
||||||
* @param phone 手机号
|
|
||||||
* @return 乘客列表
|
|
||||||
*/
|
|
||||||
List<CtripPassenger> selectByPhone(@Param("phone") String phone);
|
|
||||||
}
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单项编号查询退款项
|
|
||||||
*
|
|
||||||
* @param itemId 订单项编号
|
|
||||||
* @return 退款项列表
|
|
||||||
*/
|
|
||||||
List<CtripRefundItem> selectByItemId(@Param("itemId") String itemId);
|
|
||||||
}
|
|
||||||
-39
@@ -1,39 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程退款Mapper接口
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface CtripRefundMapper extends BaseMapper<CtripRefund> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据携程订单号查询退款记录
|
|
||||||
*
|
|
||||||
* @param otaOrderId 携程订单号
|
|
||||||
* @return 退款记录列表
|
|
||||||
*/
|
|
||||||
List<CtripRefund> selectByOtaOrderId(@Param("otaOrderId") String otaOrderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据供应商订单号查询退款记录
|
|
||||||
*
|
|
||||||
* @param supplierOrderId 供应商订单号
|
|
||||||
* @return 退款记录列表
|
|
||||||
*/
|
|
||||||
List<CtripRefund> selectBySupplierOrderId(@Param("supplierOrderId") String supplierOrderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据批次流水号查询退款记录
|
|
||||||
*
|
|
||||||
* @param sequenceId 批次流水号
|
|
||||||
* @return 退款记录
|
|
||||||
*/
|
|
||||||
CtripRefund selectBySequenceId(@Param("sequenceId") String sequenceId);
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
package com.central.coupon.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.central.coupon.entity.CtripVoucher;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程凭证Mapper接口
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface CtripVoucherMapper extends BaseMapper<CtripVoucher> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单ID查询凭证列表
|
|
||||||
*
|
|
||||||
* @param orderId 订单ID
|
|
||||||
* @return 凭证列表
|
|
||||||
*/
|
|
||||||
List<CtripVoucher> selectByOrderId(@Param("orderId") Long orderId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据订单项ID查询凭证列表
|
|
||||||
*
|
|
||||||
* @param itemId 订单项ID
|
|
||||||
* @return 凭证列表
|
|
||||||
*/
|
|
||||||
List<CtripVoucher> selectByItemId(@Param("itemId") String itemId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据凭证编号查询凭证
|
|
||||||
*
|
|
||||||
* @param voucherId 凭证编号
|
|
||||||
* @return 凭证信息
|
|
||||||
*/
|
|
||||||
CtripVoucher selectByVoucherId(@Param("voucherId") String voucherId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据凭证码查询凭证
|
|
||||||
*
|
|
||||||
* @param voucherCode 凭证码
|
|
||||||
* @return 凭证信息
|
|
||||||
*/
|
|
||||||
CtripVoucher selectByVoucherCode(@Param("voucherCode") String voucherCode);
|
|
||||||
}
|
|
||||||
-59
@@ -1,59 +0,0 @@
|
|||||||
package com.central.coupon.model;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理后台携程退款请求
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class CtripAdminRefundRequest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单中心订单号
|
|
||||||
*/
|
|
||||||
private String orderNo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款金额
|
|
||||||
*/
|
|
||||||
private BigDecimal refundAmount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款原因
|
|
||||||
*/
|
|
||||||
private String refundReason;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款项列表(可选)
|
|
||||||
*/
|
|
||||||
private List<RefundItem> items;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款项
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class RefundItem {
|
|
||||||
/**
|
|
||||||
* 订单项编号
|
|
||||||
*/
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PLU编码
|
|
||||||
*/
|
|
||||||
private String plu;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款金额
|
|
||||||
*/
|
|
||||||
private BigDecimal amount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 货币类型
|
|
||||||
*/
|
|
||||||
private String amountCurrency;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-87
@@ -1,87 +0,0 @@
|
|||||||
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; // 凭证编号
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程返回头
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public static class CtripResponseHeader {
|
|
||||||
@JsonProperty("resultCode")
|
|
||||||
private String resultCode; // 处理结果返回码
|
|
||||||
@JsonProperty("resultMessage")
|
|
||||||
private String resultMessage; // 处理结果返回信息
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-85
@@ -1,85 +0,0 @@
|
|||||||
package com.central.coupon.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程取消订单请求模型
|
|
||||||
* 参考文档: https://open.trip.com/apiplatform/order.jsp#operation/CancelOrder
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class CtripCancelOrderRequest {
|
|
||||||
|
|
||||||
@JsonProperty("header")
|
|
||||||
private CtripHeader header;
|
|
||||||
|
|
||||||
@JsonProperty("body")
|
|
||||||
private String body; // 加密的请求体
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public static class CtripHeader {
|
|
||||||
@JsonProperty("accountId")
|
|
||||||
private String accountId;
|
|
||||||
|
|
||||||
@JsonProperty("serviceName")
|
|
||||||
private String serviceName;
|
|
||||||
|
|
||||||
@JsonProperty("requestTime")
|
|
||||||
private String requestTime;
|
|
||||||
|
|
||||||
@JsonProperty("version")
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
@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("cancelReason")
|
|
||||||
private String cancelReason; // 取消原因
|
|
||||||
|
|
||||||
@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; // 订单项ID
|
|
||||||
|
|
||||||
@JsonProperty("cancelQuantity")
|
|
||||||
private Integer cancelQuantity; // 取消数量
|
|
||||||
|
|
||||||
@JsonProperty("PLU")
|
|
||||||
private String plu; // 供应商产品最小单位
|
|
||||||
|
|
||||||
@JsonProperty("lastConfirmTime")
|
|
||||||
private String lastConfirmTime; // 最后确认时间
|
|
||||||
|
|
||||||
@JsonProperty("quantity")
|
|
||||||
private Integer quantity; // 数量
|
|
||||||
|
|
||||||
@JsonProperty("cancelType")
|
|
||||||
private Integer cancelType; // 取消类型
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-92
@@ -1,92 +0,0 @@
|
|||||||
package com.central.coupon.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程取消订单响应模型
|
|
||||||
* 参考文档: https://open.trip.com/apiplatform/order.jsp#operation/CancelOrder
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class CtripCancelOrderResponse {
|
|
||||||
|
|
||||||
@JsonProperty("header")
|
|
||||||
private CtripResponseHeader header;
|
|
||||||
|
|
||||||
@JsonProperty("body")
|
|
||||||
private String body; // 加密的响应体
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripResponseHeader {
|
|
||||||
@JsonProperty("resultCode")
|
|
||||||
private String resultCode;
|
|
||||||
|
|
||||||
@JsonProperty("resultMessage")
|
|
||||||
private String resultMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripCancelOrderResponseBody {
|
|
||||||
@JsonProperty("otaOrderId")
|
|
||||||
private String otaOrderId; // 携程订单号
|
|
||||||
|
|
||||||
@JsonProperty("supplierOrderId")
|
|
||||||
private String supplierOrderId; // 供应商订单号
|
|
||||||
|
|
||||||
@JsonProperty("supplierConfirmType")
|
|
||||||
private Integer supplierConfirmType; // 供应商确认类型:1-确认,2-拒绝
|
|
||||||
|
|
||||||
@JsonProperty("items")
|
|
||||||
private List<CtripCancelOrderResponseItem> items; // 订单项列表
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripCancelOrderResponseItem {
|
|
||||||
@JsonProperty("itemId")
|
|
||||||
private String itemId; // 订单项ID
|
|
||||||
|
|
||||||
@JsonProperty("useStartDate")
|
|
||||||
private String useStartDate; // 使用开始日期
|
|
||||||
|
|
||||||
@JsonProperty("useEndDate")
|
|
||||||
private String useEndDate; // 使用结束日期
|
|
||||||
|
|
||||||
@JsonProperty("orderStatus")
|
|
||||||
private Integer orderStatus; // 订单状态:10-已取消
|
|
||||||
|
|
||||||
@JsonProperty("quantity")
|
|
||||||
private Integer quantity; // 总数量
|
|
||||||
|
|
||||||
@JsonProperty("useQuantity")
|
|
||||||
private Integer useQuantity; // 已使用数量
|
|
||||||
|
|
||||||
@JsonProperty("cancelQuantity")
|
|
||||||
private Integer cancelQuantity; // 取消数量
|
|
||||||
|
|
||||||
@JsonProperty("passengers")
|
|
||||||
private List<CtripPassenger> passengers; // 乘客信息
|
|
||||||
|
|
||||||
@JsonProperty("vouchers")
|
|
||||||
private List<CtripVoucher> vouchers; // 凭证信息
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripPassenger {
|
|
||||||
@JsonProperty("passengerId")
|
|
||||||
private String passengerId; // 乘客ID
|
|
||||||
|
|
||||||
@JsonProperty("passengerStatus")
|
|
||||||
private Integer passengerStatus; // 乘客状态:2-已取消
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripVoucher {
|
|
||||||
@JsonProperty("voucherId")
|
|
||||||
private String voucherId; // 凭证ID
|
|
||||||
|
|
||||||
@JsonProperty("voucherStatus")
|
|
||||||
private Integer voucherStatus; // 凭证状态:2-已取消
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-70
@@ -1,70 +0,0 @@
|
|||||||
package com.central.coupon.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程取消预下单请求模型
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class CtripCancelPreOrderRequest {
|
|
||||||
|
|
||||||
@JsonProperty("header")
|
|
||||||
private CtripHeader header;
|
|
||||||
|
|
||||||
@JsonProperty("body")
|
|
||||||
private String body; // 加密的请求体
|
|
||||||
|
|
||||||
@JsonProperty("originalEncryptedBody")
|
|
||||||
private String originalEncryptedBody; // 原始加密体,用于签名验证
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripHeader {
|
|
||||||
@JsonProperty("accountId")
|
|
||||||
private String accountId;
|
|
||||||
|
|
||||||
@JsonProperty("serviceName")
|
|
||||||
private String serviceName;
|
|
||||||
|
|
||||||
@JsonProperty("requestTime")
|
|
||||||
private String requestTime;
|
|
||||||
|
|
||||||
@JsonProperty("version")
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
@JsonProperty("sign")
|
|
||||||
private String sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripCancelPreOrderBody {
|
|
||||||
@JsonProperty("sequenceId")
|
|
||||||
private String sequenceId;
|
|
||||||
|
|
||||||
@JsonProperty("otaOrderId")
|
|
||||||
private String otaOrderId;
|
|
||||||
|
|
||||||
@JsonProperty("supplierOrderId")
|
|
||||||
private String supplierOrderId;
|
|
||||||
|
|
||||||
@JsonProperty("cancelReason")
|
|
||||||
private String cancelReason;
|
|
||||||
|
|
||||||
@JsonProperty("items")
|
|
||||||
private List<CtripCancelPreOrderItem> items;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripCancelPreOrderItem {
|
|
||||||
@JsonProperty("itemId")
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
@JsonProperty("cancelQuantity")
|
|
||||||
private Integer cancelQuantity;
|
|
||||||
|
|
||||||
@JsonProperty("cancelReason")
|
|
||||||
private String cancelReason;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-88
@@ -1,88 +0,0 @@
|
|||||||
package com.central.coupon.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程取消预下单响应模型(与QueryOrder响应格式相同)
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class CtripCancelPreOrderResponse {
|
|
||||||
|
|
||||||
@JsonProperty("header")
|
|
||||||
private CtripResponseHeader header;
|
|
||||||
|
|
||||||
@JsonProperty("body")
|
|
||||||
private String body; // 加密的响应体
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripResponseHeader {
|
|
||||||
@JsonProperty("resultCode")
|
|
||||||
private String resultCode;
|
|
||||||
|
|
||||||
@JsonProperty("resultMessage")
|
|
||||||
private String resultMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripCancelPreOrderResponseBody {
|
|
||||||
@JsonProperty("otaOrderId")
|
|
||||||
private String otaOrderId;
|
|
||||||
|
|
||||||
@JsonProperty("supplierOrderId")
|
|
||||||
private String supplierOrderId;
|
|
||||||
|
|
||||||
@JsonProperty("items")
|
|
||||||
private List<CtripCancelPreOrderResponseItem> items;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripCancelPreOrderResponseItem {
|
|
||||||
@JsonProperty("itemId")
|
|
||||||
private String itemId;
|
|
||||||
|
|
||||||
@JsonProperty("useStartDate")
|
|
||||||
private String useStartDate;
|
|
||||||
|
|
||||||
@JsonProperty("useEndDate")
|
|
||||||
private String useEndDate;
|
|
||||||
|
|
||||||
@JsonProperty("orderStatus")
|
|
||||||
private Integer orderStatus;
|
|
||||||
|
|
||||||
@JsonProperty("quantity")
|
|
||||||
private Integer quantity;
|
|
||||||
|
|
||||||
@JsonProperty("useQuantity")
|
|
||||||
private Integer useQuantity;
|
|
||||||
|
|
||||||
@JsonProperty("cancelQuantity")
|
|
||||||
private Integer cancelQuantity;
|
|
||||||
|
|
||||||
@JsonProperty("passengers")
|
|
||||||
private List<CtripPassenger> passengers;
|
|
||||||
|
|
||||||
@JsonProperty("vouchers")
|
|
||||||
private List<CtripVoucher> vouchers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripPassenger {
|
|
||||||
@JsonProperty("passengerId")
|
|
||||||
private String passengerId;
|
|
||||||
|
|
||||||
@JsonProperty("passengerStatus")
|
|
||||||
private Integer passengerStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class CtripVoucher {
|
|
||||||
@JsonProperty("voucherId")
|
|
||||||
private String voucherId;
|
|
||||||
|
|
||||||
@JsonProperty("voucherStatus")
|
|
||||||
private Integer voucherStatus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-126
@@ -1,126 +0,0 @@
|
|||||||
package com.central.coupon.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程订单核销通知请求
|
|
||||||
* 当订单在新订确认后,供应商可将客人出行后的使用情况或归还物品等信息调用该接口将对应的最终结果同步给携程系统
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class CtripConsumedNoticeRequest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程请求头
|
|
||||||
*/
|
|
||||||
@JsonProperty("header")
|
|
||||||
private CtripHeader header;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程请求体
|
|
||||||
*/
|
|
||||||
@JsonProperty("body")
|
|
||||||
private CtripConsumedNoticeBody body;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程请求头
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class CtripHeader {
|
|
||||||
@JsonProperty("accountId")
|
|
||||||
private String accountId;
|
|
||||||
@JsonProperty("serviceName")
|
|
||||||
private String serviceName;
|
|
||||||
@JsonProperty("requestTime")
|
|
||||||
private String requestTime;
|
|
||||||
@JsonProperty("version")
|
|
||||||
private String version;
|
|
||||||
@JsonProperty("sign")
|
|
||||||
private String sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销通知体
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class CtripConsumedNoticeBody {
|
|
||||||
@JsonProperty("sequenceId")
|
|
||||||
private String sequenceId;
|
|
||||||
@JsonProperty("otaOrderId")
|
|
||||||
private String otaOrderId;
|
|
||||||
@JsonProperty("supplierOrderId")
|
|
||||||
private String supplierOrderId;
|
|
||||||
@JsonProperty("items")
|
|
||||||
private List<CtripConsumedNoticeItem> items;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销通知项
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class CtripConsumedNoticeItem {
|
|
||||||
@JsonProperty("itemId")
|
|
||||||
private String itemId;
|
|
||||||
@JsonProperty("useStartDate")
|
|
||||||
private String useStartDate;
|
|
||||||
@JsonProperty("useEndDate")
|
|
||||||
private String useEndDate;
|
|
||||||
@JsonProperty("quantity")
|
|
||||||
private Integer quantity;
|
|
||||||
@JsonProperty("useQuantity")
|
|
||||||
private Integer useQuantity;
|
|
||||||
@JsonProperty("passengers")
|
|
||||||
private List<CtripConsumedPassenger> passengers;
|
|
||||||
@JsonProperty("vouchers")
|
|
||||||
private List<CtripConsumedVoucher> vouchers;
|
|
||||||
@JsonProperty("remark")
|
|
||||||
private String remark;
|
|
||||||
@JsonProperty("discount")
|
|
||||||
private CtripDiscount discount;
|
|
||||||
@JsonProperty("lostAmount")
|
|
||||||
private BigDecimal lostAmount;
|
|
||||||
@JsonProperty("lostAmountCurrency")
|
|
||||||
private String lostAmountCurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销乘客
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class CtripConsumedPassenger {
|
|
||||||
@JsonProperty("passengerId")
|
|
||||||
private String passengerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程核销凭证
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class CtripConsumedVoucher {
|
|
||||||
@JsonProperty("voucherId")
|
|
||||||
private String voucherId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程折扣信息
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class CtripDiscount {
|
|
||||||
@JsonProperty("policyList")
|
|
||||||
private List<CtripDiscountPolicy> policyList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 携程折扣政策
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class CtripDiscountPolicy {
|
|
||||||
@JsonProperty("date")
|
|
||||||
private String date;
|
|
||||||
@JsonProperty("quantity")
|
|
||||||
private Integer quantity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user