Compare commits
156
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
982b1ee3e4 | ||
|
|
b6f20c976d | ||
|
|
369da9f997 | ||
|
|
cd8e552d21 | ||
|
|
05e28c2c6d | ||
|
|
b30434777d | ||
|
|
4aafb17214 | ||
|
|
c18d0e8a9f | ||
|
|
134218b56a | ||
|
|
5a07bfb7e3 | ||
|
|
1203ccfa4a | ||
|
|
7adea85e1f | ||
|
|
1b221b13d1 | ||
|
|
48eaf2356f | ||
|
|
970952d9fa | ||
|
|
135996ce19 | ||
|
|
e5bfb59a1c | ||
|
|
51c1d20d3c | ||
|
|
6b85cddede | ||
|
|
9256e08cfc | ||
|
|
d0dcd0283e | ||
|
|
76c5495c32 | ||
|
|
e486f850f2 | ||
|
|
cee7dd2442 | ||
|
|
8f2545f271 | ||
|
|
76c2f3a5fd | ||
|
|
b5a7c0d46c | ||
|
|
088afbe5c1 | ||
|
|
0d155ec5b2 | ||
|
|
7d53d31c3f | ||
|
|
cd8bcae5be | ||
|
|
a2b6253d1d | ||
|
|
bb542e7510 | ||
|
|
6ac84c11b2 | ||
|
|
1192bee431 | ||
|
|
c77813af0d | ||
|
|
eba4461381 | ||
|
|
aa7b83ed1e | ||
|
|
ac310414fe | ||
|
|
f5ad238015 | ||
|
|
8618a00e5d | ||
|
|
5f97a1933e | ||
|
|
4bdb24e9ac | ||
|
|
398e1b8095 | ||
|
|
086d2b42e2 | ||
|
|
425922fd04 | ||
|
|
b24d6b3a01 | ||
|
|
c35132d06b | ||
|
|
91072d6d50 | ||
|
|
d65424e5bf | ||
|
|
f0b72b70e7 | ||
|
|
daa5a6aa5e | ||
|
|
2a35793baf | ||
|
|
4a157e9578 | ||
|
|
eabb4c6aa6 | ||
|
|
d22df698b6 | ||
|
|
cb6051cc41 | ||
|
|
1d1009b121 | ||
|
|
94f3fbb867 | ||
|
|
1771bf9909 | ||
|
|
fc4d55517b | ||
|
|
ec72a99d74 | ||
|
|
a431db6e6e | ||
|
|
9cfb31b015 | ||
|
|
15d69f9361 | ||
|
|
b000390a75 | ||
|
|
1b9f92caf5 | ||
|
|
7b08641acc | ||
|
|
66c13062b2 | ||
|
|
2b4089ef59 | ||
|
|
cdf8a426e9 | ||
|
|
a2d69fe721 | ||
|
|
19db357b44 | ||
|
|
07ffef3e2a | ||
|
|
20c3e1f422 | ||
|
|
f93ec3cd4d | ||
|
|
3cdac98832 | ||
|
|
c122c35376 | ||
|
|
3b19d9e930 | ||
|
|
2ea06fb5c0 | ||
|
|
00bb300755 | ||
|
|
ea44dd5c0e | ||
|
|
818207d6c9 | ||
|
|
af76eb43b8 | ||
|
|
5fd11e9caf | ||
|
|
d920b8630d | ||
|
|
0b98dcdfe9 | ||
|
|
1e62576d36 | ||
|
|
b373cbbe46 | ||
|
|
bb5abcb48e | ||
|
|
acd97c7b9b | ||
|
|
4a549e77cb | ||
|
|
118bdb1666 | ||
|
|
461af4d581 | ||
|
|
37dc1c9904 | ||
|
|
3a4386261c | ||
|
|
01d33a1122 | ||
|
|
db2fca5715 | ||
|
|
f3166f0413 | ||
|
|
41f692aad9 | ||
|
|
df16ac3c8e | ||
|
|
913dc3d278 | ||
|
|
731c777b8b | ||
|
|
944de228f7 | ||
|
|
a81c8476e7 | ||
|
|
25c9cd4dfc | ||
|
|
e7cf1a72e3 | ||
|
|
882cd226ec | ||
|
|
eec665109e | ||
|
|
f6a2f5a6f5 | ||
|
|
9ba610de86 | ||
|
|
e59dc363f4 | ||
|
|
eeb7b5b32e | ||
|
|
b4b6a13f8d | ||
|
|
4a7de1909c | ||
|
|
b7fcecfa7b | ||
|
|
3b68e6dd85 | ||
|
|
feb4d7af66 | ||
|
|
5cfcd24657 | ||
|
|
712118556b | ||
|
|
d75ab1ed5f | ||
|
|
4496619eeb | ||
|
|
c85b400a94 | ||
|
|
94c99e3444 | ||
|
|
44c2095d77 | ||
|
|
a501eb7443 | ||
|
|
35ec38ed9c | ||
|
|
2b5be16ad7 | ||
|
|
d747a0fdae | ||
|
|
9f884e2b74 | ||
|
|
0239697a2b | ||
|
|
2b11bdf65e | ||
|
|
19941d9480 | ||
|
|
81933d4e61 | ||
|
|
43d76040d8 | ||
|
|
cd3d522d4f | ||
|
|
8de739cbb7 | ||
|
|
181c5078e9 | ||
|
|
e2e0023d13 | ||
|
|
8c6eed2379 | ||
|
|
c32ecd1f8c | ||
|
|
3c56e21efa | ||
|
|
376f0ecd05 | ||
|
|
e97f46e6b4 | ||
|
|
a208947a1b | ||
|
|
c0f89deb83 | ||
|
|
fc62663f2c | ||
|
|
fcae2eac09 | ||
|
|
2e9225852d | ||
|
|
3a3809b661 | ||
|
|
1b8936f197 | ||
|
|
ce695463d3 | ||
|
|
aff056712e | ||
|
|
af18b0999d | ||
|
|
83c683d473 | ||
|
|
4963988ec2 |
@@ -4,6 +4,7 @@
|
|||||||
/target
|
/target
|
||||||
/temp
|
/temp
|
||||||
/AGENTS.md
|
/AGENTS.md
|
||||||
|
/.workbuddy
|
||||||
|
|
||||||
multilingualField/
|
multilingualField/
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
|||||||
-163
@@ -1,163 +0,0 @@
|
|||||||
# HTTP 调试与文档规范
|
|
||||||
|
|
||||||
本目录下的 `.http` 文件同时承担接口调试和接口文档职责,也要保证 AIAgent 能稳定读取
|
|
||||||
|
|
||||||
## 目录分工
|
|
||||||
|
|
||||||
### `.http`
|
|
||||||
|
|
||||||
`.http` 只描述接口级信息:
|
|
||||||
|
|
||||||
1. 接口中文名
|
|
||||||
2. 权限要求
|
|
||||||
3. 前置条件
|
|
||||||
4. 请求参数对应的对象说明
|
|
||||||
5. 返回参数对应的对象说明
|
|
||||||
|
|
||||||
`.http` 不重复展开对象字段明细,复杂字段、嵌套结构、枚举值统一写到 `./object` 下
|
|
||||||
|
|
||||||
### `./object`
|
|
||||||
|
|
||||||
`./object` 只描述对象级信息:
|
|
||||||
|
|
||||||
1. 字段名
|
|
||||||
2. 字段类型
|
|
||||||
3. 字段说明
|
|
||||||
4. 枚举值及含义
|
|
||||||
|
|
||||||
所有模块都可能复用的通用对象必须写在 `./object/common.md`
|
|
||||||
|
|
||||||
按业务领域拆分对象说明文件,例如:
|
|
||||||
|
|
||||||
1. `./object/common.md`
|
|
||||||
2. `./object/user.md`
|
|
||||||
3. `./object/role.md`
|
|
||||||
4. `./object/permission.md`
|
|
||||||
|
|
||||||
不要把同一个对象的字段说明散落到多个文件里
|
|
||||||
|
|
||||||
## 全局约定
|
|
||||||
|
|
||||||
### 返回包装
|
|
||||||
|
|
||||||
除使用 `IgnoreGlobalReturn` 跳过全局包装的方法外,接口默认都会经过
|
|
||||||
[GlobalReturnHandler](E:/IDEAProject/timi-spring/src/main/java/com/imyeyu/spring/util/GlobalReturnHandler.java)
|
|
||||||
统一包装返回
|
|
||||||
|
|
||||||
因此 `.http` 里的 `返回参数` 默认只描述业务 `data` 对象,不再重复赘述全局包装结构
|
|
||||||
|
|
||||||
全局返回包装、通用成功码、错误信息、常见分页壳子等内容统一维护在 `./object/common.md`
|
|
||||||
|
|
||||||
如果接口使用
|
|
||||||
[IgnoreGlobalReturn](E:/IDEAProject/timi-spring/src/main/java/com/imyeyu/spring/annotation/IgnoreGlobalReturn.java)
|
|
||||||
跳过全局包装,必须在对应接口的 `前置条件` 或补充说明里明确写出“该接口不走全局返回包装”
|
|
||||||
|
|
||||||
### 文档真实性
|
|
||||||
|
|
||||||
1. 文档只记录服务端真实行为
|
|
||||||
2. 不写猜测
|
|
||||||
3. 不写“看代码”
|
|
||||||
4. 接口改了就同步更新 `.http` 和 `./object`
|
|
||||||
|
|
||||||
### 变量复用
|
|
||||||
|
|
||||||
能复用的变量统一放在文件顶部,例如 `@user_token`、`@userId`
|
|
||||||
|
|
||||||
## `.http` 模板
|
|
||||||
|
|
||||||
每个接口块固定使用下面格式,不要擅自增删字段名:
|
|
||||||
|
|
||||||
```http
|
|
||||||
### <接口中文名>
|
|
||||||
### 权限:
|
|
||||||
### 前置条件:
|
|
||||||
### 请求参数:
|
|
||||||
### 返回参数:
|
|
||||||
|
|
||||||
POST {{baseUrl}}/path
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{}
|
|
||||||
```
|
|
||||||
|
|
||||||
## `.http` 填写要求
|
|
||||||
|
|
||||||
### 接口中文名
|
|
||||||
|
|
||||||
直接写接口用途,别写成控制器方法名
|
|
||||||
|
|
||||||
### 权限
|
|
||||||
|
|
||||||
1. 优先直接翻译控制器上的真实注解
|
|
||||||
2. 同时存在角色和权限时一起写,例如 `需要 ADMIN 角色 + USER_UPDATE 权限`
|
|
||||||
3. 只有 Token 要求时写 `需要有效 Token`
|
|
||||||
4. 无需登录时直接写 `无需登录`
|
|
||||||
|
|
||||||
### 前置条件
|
|
||||||
|
|
||||||
这里只写接口调用前必须知道的约束,例如:
|
|
||||||
|
|
||||||
1. 需要先登录并回填 `user_token`
|
|
||||||
2. 需要先创建用户再传入 `userId`
|
|
||||||
3. 重复调用可能因为唯一约束失败
|
|
||||||
4. 接口当前实现为空
|
|
||||||
5. 该接口不走全局返回包装
|
|
||||||
|
|
||||||
没有额外限制时写 `无`
|
|
||||||
|
|
||||||
### 请求参数
|
|
||||||
|
|
||||||
只写请求对象名和对象说明文件,不在 `.http` 内展开字段
|
|
||||||
|
|
||||||
推荐格式:
|
|
||||||
|
|
||||||
1. `无`
|
|
||||||
2. `UserCreateRequest,详见 ./object/user.md`
|
|
||||||
3. `Page<UserQuery>,详见 ./object/common.md 和 ./object/user.md`
|
|
||||||
|
|
||||||
### 返回参数
|
|
||||||
|
|
||||||
只写业务返回对象名和对象说明文件,不在 `.http` 内展开字段
|
|
||||||
|
|
||||||
推荐格式:
|
|
||||||
|
|
||||||
1. `无`
|
|
||||||
2. `User,详见 ./object/user.md`
|
|
||||||
3. `PageResult<User>,详见 ./object/common.md 和 ./object/user.md`
|
|
||||||
4. `二进制数据流,该接口不走全局返回包装`
|
|
||||||
|
|
||||||
## `./object` 编写要求
|
|
||||||
|
|
||||||
对象说明统一使用 Markdown 表格,推荐结构如下
|
|
||||||
|
|
||||||
```md
|
|
||||||
## User
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| name | String | 登录名,系统内唯一 |
|
|
||||||
|
|
||||||
## RoleCode
|
|
||||||
|
|
||||||
| 枚举 | 说明 |
|
|
||||||
|---|---|
|
|
||||||
| SYSTEM | 系统 |
|
|
||||||
| ADMIN | 管理员 |
|
|
||||||
```
|
|
||||||
|
|
||||||
### 对象说明规则
|
|
||||||
|
|
||||||
1. 一个对象一个标题,标题名必须和 `.http` 里引用的对象名一致
|
|
||||||
2. 字段说明只写真实存在且调用方需要关心的内容
|
|
||||||
3. 枚举单独列出,不要把枚举值混进普通字段表
|
|
||||||
4. 嵌套对象、列表元素对象也要有独立标题
|
|
||||||
5. 通用壳子对象统一写在 `./object/common.md`
|
|
||||||
|
|
||||||
## 维护要求
|
|
||||||
|
|
||||||
1. 一个控制器通常对应一个 `.http` 文件
|
|
||||||
2. 新增接口时,同步补齐对应 `.http`
|
|
||||||
3. 新增或修改对象字段时,同步更新对应 `./object/*.md`
|
|
||||||
4. 注释语言统一用中文
|
|
||||||
5. 示例请求优先保证可调试,其次才是看起来完整
|
|
||||||
@@ -1,200 +0,0 @@
|
|||||||
### AttachmentController 接口测试
|
|
||||||
### 在 IDEA 中选择 dev 或 prod 环境后执行
|
|
||||||
|
|
||||||
@attachmentId =
|
|
||||||
@attachmentBizType = TEMP_FILE
|
|
||||||
@attachmentBizId = demo-biz-id
|
|
||||||
@attachmentAttachType = SOURCE
|
|
||||||
@attachmentName = demo.png
|
|
||||||
@attachmentFilePath = E:/Temp/demo.png
|
|
||||||
@attachmentTempFileId =
|
|
||||||
|
|
||||||
### 查询附件详情
|
|
||||||
### 前置条件:`id` 必须传有效附件 ID
|
|
||||||
### 请求参数:URL 参数 `id` 为附件 ID
|
|
||||||
### 返回参数:Attachment,详见 ./object/common.md
|
|
||||||
POST {{baseUrl}}/attach/detail?id={{attachmentId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 创建附件
|
|
||||||
### 前置条件:回填 `attachmentFilePath` 为本地文件绝对路径
|
|
||||||
### 请求参数:multipart/form-data
|
|
||||||
### 返回参数:Attachment,详见 ./object/common.md
|
|
||||||
POST {{baseUrl}}/attach/create
|
|
||||||
Content-Type: multipart/form-data; boundary=AttachmentCreateBoundary
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
--AttachmentCreateBoundary
|
|
||||||
Content-Disposition: form-data; name="bizType"
|
|
||||||
|
|
||||||
{{attachmentBizType}}
|
|
||||||
--AttachmentCreateBoundary
|
|
||||||
Content-Disposition: form-data; name="bizId"
|
|
||||||
|
|
||||||
{{attachmentBizId}}
|
|
||||||
--AttachmentCreateBoundary
|
|
||||||
Content-Disposition: form-data; name="attachType"
|
|
||||||
|
|
||||||
{{attachmentAttachType}}
|
|
||||||
--AttachmentCreateBoundary
|
|
||||||
Content-Disposition: form-data; name="name"
|
|
||||||
|
|
||||||
{{attachmentName}}
|
|
||||||
--AttachmentCreateBoundary
|
|
||||||
Content-Disposition: form-data; name="file"; filename="demo.png"
|
|
||||||
Content-Type: application/octet-stream
|
|
||||||
|
|
||||||
< {{attachmentFilePath}}
|
|
||||||
--AttachmentCreateBoundary--
|
|
||||||
|
|
||||||
### 更新附件元数据
|
|
||||||
### 前置条件:`id` 必须传有效附件 ID
|
|
||||||
### 请求参数:multipart/form-data
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/attach/update
|
|
||||||
Content-Type: multipart/form-data; boundary=AttachmentUpdateMetaBoundary
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
--AttachmentUpdateMetaBoundary
|
|
||||||
Content-Disposition: form-data; name="id"
|
|
||||||
|
|
||||||
{{attachmentId}}
|
|
||||||
--AttachmentUpdateMetaBoundary
|
|
||||||
Content-Disposition: form-data; name="name"
|
|
||||||
|
|
||||||
{{attachmentName}}-updated
|
|
||||||
--AttachmentUpdateMetaBoundary
|
|
||||||
Content-Disposition: form-data; name="attachType"
|
|
||||||
|
|
||||||
{{attachmentAttachType}}
|
|
||||||
--AttachmentUpdateMetaBoundary--
|
|
||||||
|
|
||||||
### 更新附件文件
|
|
||||||
### 前置条件:`id` 必须传有效附件 ID,`attachmentFilePath` 必须传本地文件绝对路径
|
|
||||||
### 请求参数:multipart/form-data
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/attach/update
|
|
||||||
Content-Type: multipart/form-data; boundary=AttachmentUpdateFileBoundary
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
--AttachmentUpdateFileBoundary
|
|
||||||
Content-Disposition: form-data; name="id"
|
|
||||||
|
|
||||||
{{attachmentId}}
|
|
||||||
--AttachmentUpdateFileBoundary
|
|
||||||
Content-Disposition: form-data; name="name"
|
|
||||||
|
|
||||||
{{attachmentName}}-file-updated
|
|
||||||
--AttachmentUpdateFileBoundary
|
|
||||||
Content-Disposition: form-data; name="file"; filename="demo.png"
|
|
||||||
Content-Type: application/octet-stream
|
|
||||||
|
|
||||||
< {{attachmentFilePath}}
|
|
||||||
--AttachmentUpdateFileBoundary--
|
|
||||||
|
|
||||||
### 删除附件
|
|
||||||
### 前置条件:`id` 必须传有效附件 ID
|
|
||||||
### 请求参数:URL 参数 `id` 为附件 ID
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/attach/delete?id={{attachmentId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 按业务查询单个附件
|
|
||||||
### 前置条件:`bizType` 和 `bizId` 必须传有效值
|
|
||||||
### 请求参数:URL 参数 `bizType`、`bizId`
|
|
||||||
### 返回参数:Attachment,详见 ./object/common.md
|
|
||||||
GET {{baseUrl}}/attach/detail/byBiz?bizType={{attachmentBizType}}&bizId={{attachmentBizId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 按业务和附件类型查询单个附件
|
|
||||||
### 前置条件:`bizType`、`bizId`、`attachType` 必须传有效值
|
|
||||||
### 请求参数:URL 参数 `bizType`、`bizId`、`attachType`
|
|
||||||
### 返回参数:Attachment,详见 ./object/common.md
|
|
||||||
GET {{baseUrl}}/attach/detail/byAttachType?bizType={{attachmentBizType}}&bizId={{attachmentBizId}}&attachType={{attachmentAttachType}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 按业务查询附件列表
|
|
||||||
### 前置条件:`bizType` 和 `bizId` 必须传有效值
|
|
||||||
### 请求参数:URL 参数 `bizType`、`bizId`,可重复传 `attachTypeList`
|
|
||||||
### 返回参数:Attachment[]
|
|
||||||
GET {{baseUrl}}/attach/list/byBiz?bizType={{attachmentBizType}}&bizId={{attachmentBizId}}&attachTypeList={{attachmentAttachType}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 按业务统计附件数量
|
|
||||||
### 前置条件:`bizType` 和 `bizId` 必须传有效值
|
|
||||||
### 请求参数:URL 参数 `bizType`、`bizId`,可重复传 `attachTypeList`
|
|
||||||
### 返回参数:number
|
|
||||||
GET {{baseUrl}}/attach/count/byBiz?bizType={{attachmentBizType}}&bizId={{attachmentBizId}}&attachTypeList={{attachmentAttachType}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 按业务分页查询附件
|
|
||||||
### 前置条件:`bizType` 和 `bizId` 必须传有效值
|
|
||||||
### 请求参数:URL 参数 `bizType`、`bizId`,可重复传 `attachTypeList`,请求体为 Page
|
|
||||||
### 返回参数:PageResult<Attachment>
|
|
||||||
POST {{baseUrl}}/attach/page/byBiz?bizType={{attachmentBizType}}&bizId={{attachmentBizId}}&attachTypeList={{attachmentAttachType}}
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"index": 0,
|
|
||||||
"size": 10
|
|
||||||
}
|
|
||||||
|
|
||||||
### 按业务差分更新附件
|
|
||||||
### 前置条件:新增项需要传有效 `tempFileId`
|
|
||||||
### 请求参数:BizUpdateReq
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/attach/update/byBiz
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"bizType": "{{attachmentBizType}}",
|
|
||||||
"bizId": "{{attachmentBizId}}",
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"id": "{{attachmentId}}",
|
|
||||||
"attachType": "{{attachmentAttachType}}",
|
|
||||||
"name": "{{attachmentName}}-biz-updated"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tempFileId": "{{attachmentTempFileId}}",
|
|
||||||
"attachType": "{{attachmentAttachType}}",
|
|
||||||
"name": "{{attachmentName}}-from-temp"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
### 按业务删除全部附件
|
|
||||||
### 前置条件:`bizType` 和 `bizId` 必须传有效值
|
|
||||||
### 请求参数:BizDeleteReq
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/attach/delete/byBiz
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"bizType": "{{attachmentBizType}}",
|
|
||||||
"bizId": "{{attachmentBizId}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 读取附件原图
|
|
||||||
### 前置条件:`attachmentId` 必须传有效附件 ID
|
|
||||||
### 请求参数:路径参数 `id`
|
|
||||||
### 返回参数:附件二进制流
|
|
||||||
GET {{baseUrl}}/attach/read/{{attachmentId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 读取附件缩略图
|
|
||||||
### 前置条件:`attachmentId` 必须传有效图片或视频附件 ID
|
|
||||||
### 请求参数:路径参数 `id`,URL 参数 `thumbWidth`、`thumbHeight`
|
|
||||||
### 返回参数:附件二进制流
|
|
||||||
GET {{baseUrl}}/attach/read/{{attachmentId}}?thumbWidth=200&thumbHeight=200
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 下载附件
|
|
||||||
### 前置条件:`attachmentId` 必须传有效附件 ID
|
|
||||||
### 请求参数:路径参数 `id`
|
|
||||||
### 返回参数:附件二进制流
|
|
||||||
GET {{baseUrl}}/attach/download/{{attachmentId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
### MultilingualController 接口测试
|
|
||||||
### 在 IDEA 中选择 dev 或 prod 环境后执行
|
|
||||||
|
|
||||||
@multilingualId =
|
|
||||||
@multilingualZhCN = 测试简体中文
|
|
||||||
@multilingualZhTW = 測試繁體中文
|
|
||||||
@multilingualEnUS = Test English
|
|
||||||
@multilingualRuRU = Тест
|
|
||||||
@multilingualJaJP = テスト
|
|
||||||
@multilingualDeDE = Test Deutsch
|
|
||||||
@multilingualKoKR = 테스트
|
|
||||||
|
|
||||||
### 查询多语言详情
|
|
||||||
### 权限:需要 ADMIN 角色 + MULTILINGUAL_READ 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,URL 参数 `id` 必须传有效多语言 ID
|
|
||||||
### 请求参数:无请求体,URL 参数:`id` 为多语言 ID
|
|
||||||
### 返回参数:Multilingual,详见 ./object/common.md
|
|
||||||
POST {{baseUrl}}/system/multilingual/detail?id={{multilingualId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 创建多语言
|
|
||||||
### 权限:需要 ADMIN 角色 + MULTILINGUAL_CREATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:Multilingual,详见 ./object/common.md
|
|
||||||
### 返回参数:Multilingual,详见 ./object/common.md
|
|
||||||
POST {{baseUrl}}/system/multilingual/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"zhCN": "{{multilingualZhCN}}",
|
|
||||||
"zhTW": "{{multilingualZhTW}}",
|
|
||||||
"enUS": "{{multilingualEnUS}}",
|
|
||||||
"ruRU": "{{multilingualRuRU}}",
|
|
||||||
"jaJP": "{{multilingualJaJP}}",
|
|
||||||
"deDE": "{{multilingualDeDE}}",
|
|
||||||
"koKR": "{{multilingualKoKR}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 更新多语言
|
|
||||||
### 权限:需要 ADMIN 角色 + MULTILINGUAL_UPDATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,`id` 必须存在
|
|
||||||
### 请求参数:Multilingual,详见 ./object/common.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/system/multilingual/update
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "{{multilingualId}}",
|
|
||||||
"zhCN": "{{multilingualZhCN}}-已更新",
|
|
||||||
"zhTW": "{{multilingualZhTW}}-已更新",
|
|
||||||
"enUS": "{{multilingualEnUS}}-updated",
|
|
||||||
"ruRU": "{{multilingualRuRU}}-updated",
|
|
||||||
"jaJP": "{{multilingualJaJP}}-updated",
|
|
||||||
"deDE": "{{multilingualDeDE}}-updated",
|
|
||||||
"koKR": "{{multilingualKoKR}}-updated"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 删除多语言
|
|
||||||
### 权限:需要 ADMIN 角色 + MULTILINGUAL_DELETE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,URL 参数 `id` 必须传有效多语言 ID
|
|
||||||
### 请求参数:无请求体,URL 参数:`id` 为多语言 ID
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/system/multilingual/delete?id={{multilingualId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
### GaoRegisterAction 接口测试
|
|
||||||
### 在 IDEA 中选择 dev 或 prod 环境后执行
|
|
||||||
|
|
||||||
@actionId =
|
|
||||||
|
|
||||||
### 分页查询登记行为
|
|
||||||
POST {{baseUrl}}/gao/action/list
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"index": 0,
|
|
||||||
"size": 16
|
|
||||||
}
|
|
||||||
|
|
||||||
### 查询启用行为
|
|
||||||
POST {{baseUrl}}/gao/action/enabled/list
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 查询行为详情
|
|
||||||
POST {{baseUrl}}/gao/action/detail?id={{actionId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 创建登记行为
|
|
||||||
POST {{baseUrl}}/gao/action/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"name": "签到",
|
|
||||||
"description": "客户到店签到",
|
|
||||||
"enabled": true,
|
|
||||||
"requirePhoto": false,
|
|
||||||
"sort": 10,
|
|
||||||
"permissionCodeList": [
|
|
||||||
"RECORD:CREATE"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
### 更新登记行为
|
|
||||||
POST {{baseUrl}}/gao/action/update
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "{{actionId}}",
|
|
||||||
"name": "物品领取",
|
|
||||||
"description": "登记客户领取物品",
|
|
||||||
"enabled": true,
|
|
||||||
"requirePhoto": true,
|
|
||||||
"sort": 20,
|
|
||||||
"permissionCodeList": [
|
|
||||||
"RECORD:CREATE",
|
|
||||||
"STAT:READ"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
### 删除登记行为
|
|
||||||
POST {{baseUrl}}/gao/action/delete?id={{actionId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
### GaoCustomer 接口测试
|
|
||||||
### 在 IDEA 中选择 dev 或 prod 环境后执行
|
|
||||||
|
|
||||||
@customerId =
|
|
||||||
@introducerCustomerId =
|
|
||||||
@customerCode = GAO-0001
|
|
||||||
|
|
||||||
### 分页查询客户
|
|
||||||
POST {{baseUrl}}/gao/customer/list
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"index": 0,
|
|
||||||
"size": 16
|
|
||||||
}
|
|
||||||
|
|
||||||
### 搜索客户
|
|
||||||
POST {{baseUrl}}/gao/customer/search
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"keyword": "张",
|
|
||||||
"introducerCustomerId": "{{introducerCustomerId}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 查询客户详情
|
|
||||||
POST {{baseUrl}}/gao/customer/detail?id={{customerId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 按客户编码查询
|
|
||||||
POST {{baseUrl}}/gao/customer/detail/code?code={{customerCode}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 查询某客户邀请了哪些人
|
|
||||||
POST {{baseUrl}}/gao/customer/invited/list?introducerCustomerId={{customerId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 创建客户
|
|
||||||
POST {{baseUrl}}/gao/customer/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"code": "{{customerCode}}",
|
|
||||||
"name": "张三",
|
|
||||||
"age": 56,
|
|
||||||
"telephone": "020-88886666",
|
|
||||||
"address": "广州市天河区某街道",
|
|
||||||
"remark": "首诊客户",
|
|
||||||
"disease": "肩颈不适",
|
|
||||||
"conditioningPart": [
|
|
||||||
{
|
|
||||||
"code": "neck",
|
|
||||||
"name": "颈部"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"code": "shoulder",
|
|
||||||
"name": "肩部"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"introducerCustomerId": "{{introducerCustomerId}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 更新客户
|
|
||||||
POST {{baseUrl}}/gao/customer/update
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "{{customerId}}",
|
|
||||||
"code": "{{customerCode}}",
|
|
||||||
"name": "张三",
|
|
||||||
"age": 57,
|
|
||||||
"telephone": "020-88886667",
|
|
||||||
"address": "广州市天河区某街道 88 号",
|
|
||||||
"remark": "复诊客户",
|
|
||||||
"disease": "腰背调理",
|
|
||||||
"conditioningPart": {
|
|
||||||
"parts": [
|
|
||||||
"waist",
|
|
||||||
"back"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"introducerCustomerId": "{{introducerCustomerId}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 删除客户
|
|
||||||
POST {{baseUrl}}/gao/customer/delete?id={{customerId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 创建客户邀请关系
|
|
||||||
POST {{baseUrl}}/gao/customer/invite/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"customerId": "{{customerId}}",
|
|
||||||
"introducerCustomerId": "{{introducerCustomerId}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 查询客户邀请关系详情
|
|
||||||
POST {{baseUrl}}/gao/customer/invite/detail?customerId={{customerId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 更新客户邀请关系
|
|
||||||
POST {{baseUrl}}/gao/customer/invite/update
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"customerId": "{{customerId}}",
|
|
||||||
"introducerCustomerId": "{{introducerCustomerId}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 删除客户邀请关系
|
|
||||||
POST {{baseUrl}}/gao/customer/invite/delete?customerId={{customerId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
### GaoRegisterRecord 接口测试
|
|
||||||
### 在 IDEA 中选择 dev 或 prod 环境后执行
|
|
||||||
|
|
||||||
@recordId =
|
|
||||||
@customerId =
|
|
||||||
@customerCode = GAO-0001
|
|
||||||
@actionId =
|
|
||||||
|
|
||||||
### 分页查询登记记录
|
|
||||||
POST {{baseUrl}}/gao/record/list
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"index": 0,
|
|
||||||
"size": 16
|
|
||||||
}
|
|
||||||
|
|
||||||
### 查询登记记录详情
|
|
||||||
POST {{baseUrl}}/gao/record/detail?id={{recordId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 创建登记记录,直接传客户 ID
|
|
||||||
POST {{baseUrl}}/gao/record/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"customerId": "{{customerId}}",
|
|
||||||
"actionId": "{{actionId}}",
|
|
||||||
"remark": "客户到店签到"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 创建登记记录,扫码后传客户编码
|
|
||||||
POST {{baseUrl}}/gao/record/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"customerCode": "{{customerCode}}",
|
|
||||||
"actionId": "{{actionId}}",
|
|
||||||
"remark": "扫码快速登记"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 更新登记记录
|
|
||||||
POST {{baseUrl}}/gao/record/update
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "{{recordId}}",
|
|
||||||
"customerId": "{{customerId}}",
|
|
||||||
"actionId": "{{actionId}}",
|
|
||||||
"remark": "补充备注",
|
|
||||||
"registeredAt": 1785110400
|
|
||||||
}
|
|
||||||
|
|
||||||
### 删除登记记录
|
|
||||||
POST {{baseUrl}}/gao/record/delete?id={{recordId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 按日查询某个行为记录
|
|
||||||
POST {{baseUrl}}/gao/record/period/list
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"actionId": "{{actionId}}",
|
|
||||||
"periodType": "DAY",
|
|
||||||
"periodValue": 20260727
|
|
||||||
}
|
|
||||||
|
|
||||||
### 按月统计某个行为记录
|
|
||||||
POST {{baseUrl}}/gao/record/period/stat
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"actionId": "{{actionId}}",
|
|
||||||
"periodType": "MONTH",
|
|
||||||
"periodValue": 202607
|
|
||||||
}
|
|
||||||
|
|
||||||
### 查询客户所有登记统计
|
|
||||||
POST {{baseUrl}}/gao/record/customer/stat?customerId={{customerId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"dev": {
|
|
||||||
"baseUrl": "http://localhost:8091"
|
|
||||||
},
|
|
||||||
"prod": {
|
|
||||||
"baseUrl": "https://api.example.com"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
# 通用对象说明
|
|
||||||
|
|
||||||
## TimiResponse<T>
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| code | Integer | 响应码,`20000` 为成功 |
|
|
||||||
| msg | String | 响应消息 |
|
|
||||||
| data | T | 业务数据体,具体结构由接口返回对象决定 |
|
|
||||||
|
|
||||||
## Page<T>
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| index | int | 页码下标,从 `0` 开始 |
|
|
||||||
| size | long | 每页数量 |
|
|
||||||
| equalsExample | T | 精确匹配示例对象,非空字段参与精确查询 |
|
|
||||||
| likesExample | T | 模糊匹配示例对象,非空字段参与模糊查询 |
|
|
||||||
| equalsLogic | Logic | 精确匹配字段之间的连接逻辑,默认 `AND` |
|
|
||||||
| likesLogic | Logic | 模糊匹配字段之间的连接逻辑,默认 `OR` |
|
|
||||||
| orderMap | LinkedHashMap<String, OrderType> | 排序字段映射,键通常为字段名,值为排序方向 |
|
|
||||||
|
|
||||||
## PageResult<T>
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| total | long | 总数据量 |
|
|
||||||
| pages | int | 总页数 |
|
|
||||||
| list | List<T> | 当前页数据列表 |
|
|
||||||
|
|
||||||
## UUIDEntity
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| id | String | 主键 ID,UUID 字符串 |
|
|
||||||
| createdAt | Long | 创建时间,Unix 时间戳毫秒 |
|
|
||||||
| updatedAt | Long | 更新时间,Unix 时间戳毫秒 |
|
|
||||||
| deletedAt | Long | 删除时间,Unix 时间戳毫秒,未删除时通常为空 |
|
|
||||||
|
|
||||||
## Multilingual
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| id | String | 多语言 ID |
|
|
||||||
| zhCN | String | 简体中文文本 |
|
|
||||||
| zhTW | String | 繁体中文文本 |
|
|
||||||
| enUS | String | 英文文本 |
|
|
||||||
| ruRU | String | 俄文文本 |
|
|
||||||
| jaJP | String | 日文文本 |
|
|
||||||
| deDE | String | 德文文本 |
|
|
||||||
| koKR | String | 韩文文本 |
|
|
||||||
| lastAccessAt | Long | 最后访问时间,Unix 时间戳毫秒 |
|
|
||||||
| createdAt | Long | 创建时间,Unix 时间戳毫秒 |
|
|
||||||
| updatedAt | Long | 更新时间,Unix 时间戳毫秒 |
|
|
||||||
| deletedAt | Long | 删除时间,Unix 时间戳毫秒,未删除时通常为空 |
|
|
||||||
|
|
||||||
## Logic
|
|
||||||
|
|
||||||
| 枚举 | 说明 |
|
|
||||||
|---|---|
|
|
||||||
| AND | 多个条件同时满足 |
|
|
||||||
| OR | 多个条件满足其一 |
|
|
||||||
|
|
||||||
## OrderType
|
|
||||||
|
|
||||||
| 枚举 | 说明 |
|
|
||||||
|---|---|
|
|
||||||
| ASC | 升序 |
|
|
||||||
| DESC | 降序 |
|
|
||||||
|
|
||||||
## ImageType
|
|
||||||
|
|
||||||
| 枚举 | 说明 |
|
|
||||||
|---|---|
|
|
||||||
| AUTO | 双线性 |
|
|
||||||
| SMOOTH | 模糊 |
|
|
||||||
| PIXELATED | 像素 |
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
# 权限对象说明
|
|
||||||
|
|
||||||
## Permission
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| id | String | 权限 ID |
|
|
||||||
| createdAt | Long | 创建时间,Unix 时间戳毫秒 |
|
|
||||||
| updatedAt | Long | 更新时间,Unix 时间戳毫秒 |
|
|
||||||
| deletedAt | Long | 删除时间,Unix 时间戳毫秒 |
|
|
||||||
| code | String | 权限代码,需与数据库 `permission.code` 保持一致 |
|
|
||||||
| nameLangId | String | 权限名称的多语言键 |
|
|
||||||
| description | String | 权限说明 |
|
|
||||||
| name | String | 当前语言下的权限名称 |
|
|
||||||
|
|
||||||
## BatchCreateReq
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| prefixCode | String | 权限代码前缀,例如 `ROLE` |
|
|
||||||
| prefixName | String | 权限名称前缀,例如 `角色` |
|
|
||||||
| types | Type[] | 需要批量生成的权限类型列表,详见 `BatchCreateType` |
|
|
||||||
|
|
||||||
## BatchCreateType
|
|
||||||
|
|
||||||
| 枚举 | 说明 |
|
|
||||||
|---|---|
|
|
||||||
| CREATE | 创建权限 |
|
|
||||||
| READ | 读取权限 |
|
|
||||||
| UPDATE | 更新权限 |
|
|
||||||
| DELETE | 删除权限 |
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# 角色对象说明
|
|
||||||
|
|
||||||
## Role
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| id | String | 角色 ID |
|
|
||||||
| createdAt | Long | 创建时间,Unix 时间戳毫秒 |
|
|
||||||
| updatedAt | Long | 更新时间,Unix 时间戳毫秒 |
|
|
||||||
| deletedAt | Long | 删除时间,Unix 时间戳毫秒 |
|
|
||||||
| code | String | 角色代码,常见值见 `RoleCode` |
|
|
||||||
| nameLangId | String | 角色名称的多语言键 |
|
|
||||||
| description | String | 角色说明 |
|
|
||||||
| name | String | 当前语言下的角色名称 |
|
|
||||||
| permissionList | List<Permission> | 角色自身直接绑定的权限列表 |
|
|
||||||
| allPermissionList | List<Permission> | 角色全部权限列表,包含继承自子角色的权限 |
|
|
||||||
| childRoleList | List<Role> | 子角色列表 |
|
|
||||||
| permissionIdList | Set<String> | 权限 ID 列表,创建或更新角色时使用 |
|
|
||||||
| childRoleIdList | Set<String> | 子角色 ID 列表,创建或更新角色时使用 |
|
|
||||||
|
|
||||||
## UserRoleAuthorizeReq
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| userId | String | 目标用户 ID |
|
|
||||||
| roleIdList | List<String> | 需要授权的角色 ID 列表 |
|
|
||||||
| roleCodeList | List<String> | 需要授权的角色代码列表 |
|
|
||||||
|
|
||||||
## RoleCode
|
|
||||||
|
|
||||||
| 枚举 | 说明 |
|
|
||||||
|---|---|
|
|
||||||
| SYSTEM | 系统 |
|
|
||||||
| ADMIN | 管理员 |
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
# 用户对象说明
|
|
||||||
|
|
||||||
## User
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| id | String | 用户 ID |
|
|
||||||
| createdAt | Long | 创建时间,Unix 时间戳毫秒 |
|
|
||||||
| updatedAt | Long | 更新时间,Unix 时间戳毫秒 |
|
|
||||||
| deletedAt | Long | 删除时间,Unix 时间戳毫秒 |
|
|
||||||
| name | String | 登录名,系统内唯一 |
|
|
||||||
| nick | String | 用户昵称 |
|
|
||||||
| password | String | 明文密码,请求时填写,响应通常不返回 |
|
|
||||||
| email | String | 邮箱地址 |
|
|
||||||
| emailVerifyAt | Long | 邮箱验证时间,Unix 时间戳毫秒 |
|
|
||||||
| phoneNo | String | 手机号,11 位大陆手机号 |
|
|
||||||
| phoneNoVerifyAt | Long | 手机号验证时间,Unix 时间戳毫秒 |
|
|
||||||
| wrapperType | ImageType | 背景图渲染算法,详见 `ImageType` |
|
|
||||||
| avatarType | ImageType | 头像渲染算法,详见 `ImageType` |
|
|
||||||
| exp | Integer | 经验值 |
|
|
||||||
| sex | Integer | 性别,当前代码未定义枚举说明 |
|
|
||||||
| birthdate | Long | 出生日期,Unix 时间戳毫秒 |
|
|
||||||
| qq | String | QQ 号 |
|
|
||||||
| description | String | 个人说明 |
|
|
||||||
| lastLoginIP | String | 上次登录 IP |
|
|
||||||
| lastLoginAt | Long | 上次登录时间,Unix 时间戳毫秒 |
|
|
||||||
| unmuteAt | Long | 解除禁言时间,Unix 时间戳毫秒 |
|
|
||||||
| unbanAt | Long | 解除封禁时间,Unix 时间戳毫秒 |
|
|
||||||
| roleList | List<String> | 角色代码列表 |
|
|
||||||
| permissionList | List<String> | 权限代码列表 |
|
|
||||||
| attachmentList | List<Attachment> | 附件列表 |
|
|
||||||
| settingList | List<Setting> | 设置列表 |
|
|
||||||
|
|
||||||
## LoginRequest
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| user | String | 用户标识,可能是 UID、邮箱或用户名 |
|
|
||||||
| password | String | 明文密码 |
|
|
||||||
|
|
||||||
## LoginResponse
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| token | String | 登录令牌 |
|
|
||||||
| expireAt | Long | 令牌过期时间,Unix 时间戳毫秒 |
|
|
||||||
| user | User | 当前登录用户 |
|
|
||||||
|
|
||||||
## UpdatePasswordRequest
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| oldValue | String | 原密码 |
|
|
||||||
| newValue | String | 新密码 |
|
|
||||||
|
|
||||||
## PhoneVerifyCodeSendRequest
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| phoneNo | String | 手机号,必须为 11 位大陆手机号 |
|
|
||||||
|
|
||||||
## PhoneVerifyRequest
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| phoneNo | String | 手机号,必须为 11 位大陆手机号 |
|
|
||||||
| verifyCode | String | 6 位数字验证码 |
|
|
||||||
|
|
||||||
## CancelRequest
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|---|---|---|
|
|
||||||
| password | String | 当前密码,用于确认注销 |
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
### PermissionController 接口测试
|
|
||||||
### 在 IDEA 中选择 dev 或 prod 环境后执行
|
|
||||||
|
|
||||||
@user_token =
|
|
||||||
@permissionId =
|
|
||||||
@permissionCode = TEST_PERMISSION
|
|
||||||
@permissionNameLangId = permission.test.name
|
|
||||||
@permissionDescription = 测试权限
|
|
||||||
@moduleCode = CORE
|
|
||||||
|
|
||||||
### 分页查询权限
|
|
||||||
### 权限:需要 PERMISSION_READ 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:Page<Permission>,详见 ./http/object/permission.md
|
|
||||||
### 返回参数:PageResult<Permission>,详见 ./http/object/permission.md
|
|
||||||
POST {{baseUrl}}/user/permission/list
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"index": 0,
|
|
||||||
"size": 10,
|
|
||||||
"likesExample": {
|
|
||||||
"code": "{{permissionCode}}",
|
|
||||||
"moduleCode": "{{moduleCode}}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
### 创建权限
|
|
||||||
### 权限:当前代码要求 PERMISSION_READ 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:Permission,详见 ./http/object/permission.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/permission/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"moduleCode": "{{moduleCode}}",
|
|
||||||
"code": "{{permissionCode}}",
|
|
||||||
"nameLangId": "{{permissionNameLangId}}",
|
|
||||||
"description": "{{permissionDescription}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 批量创建权限
|
|
||||||
### 权限:需要 PERMISSION_CREATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:BatchCreateReq,详见 ./http/object/permission.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/permission/create/batch
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"moduleCode": "{{moduleCode}}",
|
|
||||||
"prefixCode": "ROLE",
|
|
||||||
"prefixName": "角色",
|
|
||||||
"types": ["CREATE", "READ", "UPDATE", "DELETE"]
|
|
||||||
}
|
|
||||||
|
|
||||||
### 更新权限
|
|
||||||
### 权限:需要 PERMISSION_UPDATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,`id` 必须存在
|
|
||||||
### 请求参数:Permission,详见 ./http/object/permission.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/permission/update
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "{{permissionId}}",
|
|
||||||
"moduleCode": "{{moduleCode}}",
|
|
||||||
"code": "{{permissionCode}}",
|
|
||||||
"nameLangId": "{{permissionNameLangId}}",
|
|
||||||
"description": "测试权限-已更新"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 删除权限
|
|
||||||
### 权限:需要 PERMISSION_DELETE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,URL 参数 `id` 必须传有效权限 ID
|
|
||||||
### 请求参数:无请求体,URL 参数:`id` 为权限 ID
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/permission/delete?id={{permissionId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
### RoleController 接口测试
|
|
||||||
### 在 IDEA 中选择 dev 或 prod 环境后执行
|
|
||||||
|
|
||||||
@permissionId =
|
|
||||||
@roleId =
|
|
||||||
@roleCode = TEST_ROLE
|
|
||||||
@roleNameLangId = role.test.name
|
|
||||||
@roleDescription = 测试角色
|
|
||||||
@childRoleId =
|
|
||||||
@authorizedUserId =
|
|
||||||
@moduleCode = CORE
|
|
||||||
|
|
||||||
### 分页查询角色
|
|
||||||
### 权限:需要 ADMIN 角色 + ROLE_READ 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:Page<Role>,详见 ./http/object/role.md
|
|
||||||
### 返回参数:PageResult<Role>,详见 ./http/object/role.md
|
|
||||||
POST {{baseUrl}}/user/role/list
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"index": 0,
|
|
||||||
"size": 16,
|
|
||||||
"likesExample": {
|
|
||||||
"moduleCode": "{{moduleCode}}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
### 查询角色详情
|
|
||||||
### 权限:需要 ADMIN 角色 + ROLE_READ 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,URL 参数 `id` 必须传有效角色 ID
|
|
||||||
### 请求参数:无请求体,URL 参数:`id` 为角色 ID
|
|
||||||
### 返回参数:Role,详见 ./http/object/role.md
|
|
||||||
POST {{baseUrl}}/user/role/detail?id={{roleId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 创建角色
|
|
||||||
### 权限:需要 ADMIN 角色 + ROLE_CREATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:Role,详见 ./http/object/role.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/role/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"moduleCode": "{{moduleCode}}",
|
|
||||||
"code": "{{roleCode}}",
|
|
||||||
"nameLangId": "{{roleNameLangId}}",
|
|
||||||
"description": "{{roleDescription}}",
|
|
||||||
"permissionIdList": ["{{permissionId}}"],
|
|
||||||
"childRoleIdList": []
|
|
||||||
}
|
|
||||||
|
|
||||||
### 更新角色
|
|
||||||
### 权限:需要 ADMIN 角色 + ROLE_UPDATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,`id` 必须存在
|
|
||||||
### 请求参数:Role,详见 ./http/object/role.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/role/update
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "{{roleId}}",
|
|
||||||
"moduleCode": "{{moduleCode}}",
|
|
||||||
"code": "{{roleCode}}",
|
|
||||||
"nameLangId": "{{roleNameLangId}}",
|
|
||||||
"description": "测试角色-已更新",
|
|
||||||
"permissionIdList": ["{{permissionId}}"],
|
|
||||||
"childRoleIdList": ["{{childRoleId}}"]
|
|
||||||
}
|
|
||||||
|
|
||||||
### 删除角色
|
|
||||||
### 权限:需要 ADMIN 角色 + ROLE_DELETE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,URL 参数 `id` 必须传有效角色 ID
|
|
||||||
### 请求参数:无请求体,URL 参数:`id` 为角色 ID
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/role/delete?id={{roleId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 查询用户角色
|
|
||||||
### 权限:需要 ADMIN 角色 + USER_ROLE_READ 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,URL 参数 `userId` 必须传有效用户 ID
|
|
||||||
### 请求参数:无请求体,URL 参数:`userId` 为用户 ID
|
|
||||||
### 返回参数:List<Role>,详见 ./http/object/role.md
|
|
||||||
POST {{baseUrl}}/user/role/authorized/list?userId={{authorizedUserId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 设置用户角色
|
|
||||||
### 权限:需要 ADMIN 角色 + 同时具备 USER_ROLE_CREATE 和 USER_ROLE_DELETE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:UserRoleAuthorizeReq,详见 ./http/object/role.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/role/authorized/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"userId": "{{authorizedUserId}}",
|
|
||||||
"moduleCode": "{{moduleCode}}",
|
|
||||||
"roleIdList": ["{{roleId}}"],
|
|
||||||
"roleCodeList": ["{{roleCode}}"]
|
|
||||||
}
|
|
||||||
|
|
||||||
### 查询用户已授权权限
|
|
||||||
### 权限:需要 ADMIN 角色 + USER_ROLE_READ 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,URL 参数 `userId` 必须传有效用户 ID
|
|
||||||
### 请求参数:无请求体,URL 参数:`userId` 为用户 ID
|
|
||||||
### 返回参数:List<Permission>,详见 ./http/object/permission.md
|
|
||||||
POST {{baseUrl}}/user/role/authorized/permission?userId={{authorizedUserId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
@@ -1,186 +0,0 @@
|
|||||||
### UserController 接口测试
|
|
||||||
### 在 IDEA 中选择 dev 或 prod 环境后执行
|
|
||||||
|
|
||||||
@userId =
|
|
||||||
@name = System
|
|
||||||
@password = u#HA027xq$i9]P}uB]LweJspTb!3oS^.
|
|
||||||
@newPassword = qwe123
|
|
||||||
@nick = 测试用户
|
|
||||||
@email = test@example.com
|
|
||||||
|
|
||||||
### 分页查询用户
|
|
||||||
### 权限:需要 ADMIN 角色 + USER_READ 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:Page<User>,详见 ./http/object/user.md
|
|
||||||
### 返回参数:PageResult<User>,详见 ./http/object/user.md
|
|
||||||
POST {{baseUrl}}/user/list
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"index": 0,
|
|
||||||
"size": 16
|
|
||||||
}
|
|
||||||
|
|
||||||
### 查询用户详情
|
|
||||||
### 权限:需要 ADMIN 角色 + USER_READ 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,URL 参数 `id` 必须传有效用户 ID
|
|
||||||
### 请求参数:无请求体,URL 参数:`id` 为用户 ID
|
|
||||||
### 返回参数:User,详见 ./http/object/user.md
|
|
||||||
POST {{baseUrl}}/user/detail?id={{userId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 创建用户
|
|
||||||
### 权限:需要 ADMIN 角色 + USER_CREATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,重复用户名通常会失败
|
|
||||||
### 请求参数:User,详见 ./http/object/user.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/create
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"name": "{{name}}",
|
|
||||||
"nick": "{{nick}}",
|
|
||||||
"email": "{{email}}",
|
|
||||||
"phoneNo": "13800138000",
|
|
||||||
"password": "{{password}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 更新用户
|
|
||||||
### 权限:需要 ADMIN 角色 + USER_UPDATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,`id` 必须存在
|
|
||||||
### 请求参数:User,详见 ./http/object/user.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/update
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "{{userId}}",
|
|
||||||
"name": "{{name}}",
|
|
||||||
"nick": "{{nick}}",
|
|
||||||
"email": "{{email}}",
|
|
||||||
"phoneNo": "13800138000"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 删除用户
|
|
||||||
### 权限:需要 ADMIN 角色
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`,URL 参数 `id` 必须传有效用户 ID
|
|
||||||
### 请求参数:无请求体,URL 参数:`id` 为用户 ID
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/delete?id={{userId}}
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 注册
|
|
||||||
### 权限:无需登录
|
|
||||||
### 前置条件:重复用户名通常会失败
|
|
||||||
### 请求参数:User,详见 ./http/object/user.md
|
|
||||||
### 返回参数:LoginResponse,详见 ./http/object/user.md
|
|
||||||
POST {{baseUrl}}/user/register
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"name": "Test",
|
|
||||||
"nick": "测试用户",
|
|
||||||
"phoneNo": "13800138000",
|
|
||||||
"password": "qwe123"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 登录
|
|
||||||
### 权限:无需登录
|
|
||||||
### 前置条件:成功后需要把响应中的 token 回填到 `user_token`
|
|
||||||
### 请求参数:LoginRequest,详见 ./http/object/user.md
|
|
||||||
### 返回参数:LoginResponse,详见 ./http/object/user.md
|
|
||||||
POST {{baseUrl}}/user/login
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"user": "{{name}}",
|
|
||||||
"password": "{{password}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
> {%
|
|
||||||
client.global.set("user_token", response.body?.data?.token)
|
|
||||||
%}
|
|
||||||
|
|
||||||
### 令牌登录
|
|
||||||
### 权限:需要有效 Token
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:无
|
|
||||||
### 返回参数:LoginResponse,详见 ./http/object/user.md
|
|
||||||
GET {{baseUrl}}/user/login/token
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 登出
|
|
||||||
### 权限:当前控制器未声明 RequiredToken/权限注解,按服务端实际会话处理
|
|
||||||
### 前置条件:当前接口通常用于退出当前登录态
|
|
||||||
### 请求参数:无
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/logout
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
### 修改当前用户密码
|
|
||||||
### 权限:需要 USER_UPDATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:UpdatePasswordRequest,详见 ./http/object/user.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/update/password
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"oldValue": "{{password}}",
|
|
||||||
"newValue": "{{newPassword}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 修改当前用户邮箱
|
|
||||||
### 权限:需要 USER_UPDATE 权限
|
|
||||||
### 前置条件:当前方法体为空,接口尚未实现
|
|
||||||
### 请求参数:无
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/update/email
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{}
|
|
||||||
|
|
||||||
### 发送当前用户手机号验证码
|
|
||||||
### 权限:需要 USER_UPDATE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:PhoneVerifyCodeSendRequest,详见 ./http/object/user.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/phone/verify/send
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"phoneNo": "13800138000"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 验证当前用户手机号
|
|
||||||
### 权限:需要 USER_UPDATE 权限
|
|
||||||
### 前置条件:需要先调用手机号验证码发送接口获取验证码
|
|
||||||
### 请求参数:PhoneVerifyRequest,详见 ./http/object/user.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/phone/verify
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"phoneNo": "13800138000",
|
|
||||||
"verifyCode": "123456"
|
|
||||||
}
|
|
||||||
|
|
||||||
### 注销当前用户
|
|
||||||
### 权限:需要 USER_DELETE 权限
|
|
||||||
### 前置条件:需要先登录并回填 `user_token`
|
|
||||||
### 请求参数:CancelRequest,详见 ./http/object/user.md
|
|
||||||
### 返回参数:无
|
|
||||||
POST {{baseUrl}}/user/cancel
|
|
||||||
Content-Type: application/json
|
|
||||||
Token: {{user_token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"password": "{{password}}"
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.timiserverapi</groupId>
|
<groupId>com.imyeyu.timiserverapi</groupId>
|
||||||
<artifactId>TimiServerAPI</artifactId>
|
<artifactId>TimiServerAPI</artifactId>
|
||||||
<version>1.0.19</version>
|
<version>1.0.56</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>TimiServerAPI</name>
|
<name>TimiServerAPI</name>
|
||||||
<description>imyeyu.com API</description>
|
<description>imyeyu.com API</description>
|
||||||
@@ -180,10 +180,19 @@
|
|||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.groovy</groupId>
|
||||||
|
<artifactId>groovy</artifactId>
|
||||||
|
<version>4.0.29</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.spring</groupId>
|
<groupId>com.imyeyu.spring</groupId>
|
||||||
<artifactId>timi-spring</artifactId>
|
<artifactId>timi-spring</artifactId>
|
||||||
<version>0.0.19</version>
|
<version>0.0.20</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.network</groupId>
|
<groupId>com.imyeyu.network</groupId>
|
||||||
@@ -198,7 +207,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.java</groupId>
|
<groupId>com.imyeyu.java</groupId>
|
||||||
<artifactId>timi-java</artifactId>
|
<artifactId>timi-java</artifactId>
|
||||||
<version>0.0.7</version>
|
<version>0.0.11</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.utils</groupId>
|
<groupId>com.imyeyu.utils</groupId>
|
||||||
@@ -210,10 +219,15 @@
|
|||||||
<artifactId>tinypinyin</artifactId>
|
<artifactId>tinypinyin</artifactId>
|
||||||
<version>2.0.3</version>
|
<version>2.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.hankcs</groupId>
|
||||||
|
<artifactId>hanlp</artifactId>
|
||||||
|
<version>portable-1.8.4</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.font.icon</groupId>
|
<groupId>com.imyeyu.font.icon</groupId>
|
||||||
<artifactId>timi-icon-font</artifactId>
|
<artifactId>timi-icon-font</artifactId>
|
||||||
<version>0.0.1</version>
|
<version>0.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -240,11 +254,6 @@
|
|||||||
<groupId>org.flywaydb</groupId>
|
<groupId>org.flywaydb</groupId>
|
||||||
<artifactId>flyway-mysql</artifactId>
|
<artifactId>flyway-mysql</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.e2ins.ms.notify</groupId>
|
|
||||||
<artifactId>e2ins-msg-notify-service-sdk</artifactId>
|
|
||||||
<version>0.0.9</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tencentcloudapi</groupId>
|
<groupId>com.tencentcloudapi</groupId>
|
||||||
<artifactId>tencentcloud-sdk-java-sms</artifactId>
|
<artifactId>tencentcloud-sdk-java-sms</artifactId>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,35 +0,0 @@
|
|||||||
package com.imyeyu.api.annotation;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 启用配置注解
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2023-07-15 10:00
|
|
||||||
*/
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface EnableSetting {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-27 14:45
|
|
||||||
*/
|
|
||||||
enum Logic {
|
|
||||||
|
|
||||||
AND,
|
|
||||||
|
|
||||||
OR
|
|
||||||
}
|
|
||||||
|
|
||||||
Logic logic() default Logic.AND;
|
|
||||||
|
|
||||||
/** @return 未启用配置时响应消息语言映射键 */
|
|
||||||
String message() default "service.offline";
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package com.imyeyu.api.annotation;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.service.SettingService;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.lang.NonNull;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 启用配置注解处理器
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2023-07-15 10:01
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
||||||
public class EnableSettingInterceptor implements HandlerInterceptor {
|
|
||||||
|
|
||||||
private final SettingService service;
|
|
||||||
|
|
||||||
public boolean preHandle(@NonNull HttpServletRequest req, @NonNull HttpServletResponse resp, @NonNull Object handler) throws InvocationTargetException, IllegalAccessException {
|
|
||||||
if (handler instanceof HandlerMethod handlerMethod) {
|
|
||||||
EnableSetting annotation = handlerMethod.getMethodAnnotation(EnableSetting.class);
|
|
||||||
if (annotation == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
EnableSetting.Logic logic = annotation.logic();
|
|
||||||
List<Boolean> valueList = new ArrayList<>();
|
|
||||||
for (Method method : annotation.getClass().getMethods()) {
|
|
||||||
if (method.getName().equals("message")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Enum<?>[] enums = (Enum<?>[]) method.invoke(annotation);
|
|
||||||
for (Enum<?> anEnum : enums) {
|
|
||||||
valueList.add(service.getSystem(anEnum).isTrue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (logic == EnableSetting.Logic.AND) {
|
|
||||||
return valueList.stream().allMatch(Boolean::booleanValue);
|
|
||||||
} else {
|
|
||||||
return valueList.stream().anyMatch(Boolean::booleanValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.imyeyu.api.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-09-08 15:22
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface SettingBizType {
|
||||||
|
|
||||||
|
String value();
|
||||||
|
}
|
||||||
@@ -45,6 +45,11 @@ public enum CorePermissionCode implements BuiltinPermissionCode {
|
|||||||
TAG_UPDATE("TAG:UPDATE", "标签修改", false, true),
|
TAG_UPDATE("TAG:UPDATE", "标签修改", false, true),
|
||||||
TAG_DELETE("TAG:DELETE", "标签删除", false, true),
|
TAG_DELETE("TAG:DELETE", "标签删除", false, true),
|
||||||
|
|
||||||
|
ARTICLE_CREATE("ARTICLE:CREATE", "文章创建", false, true),
|
||||||
|
ARTICLE_READ("ARTICLE:READ", "文章读取", false, true),
|
||||||
|
ARTICLE_UPDATE("ARTICLE:UPDATE", "文章修改", false, true),
|
||||||
|
ARTICLE_DELETE("ARTICLE:DELETE", "文章删除", false, true),
|
||||||
|
|
||||||
USER_CREATE("USER:CREATE", "用户创建", false, true),
|
USER_CREATE("USER:CREATE", "用户创建", false, true),
|
||||||
USER_READ("USER:READ", "用户读取", false, true),
|
USER_READ("USER:READ", "用户读取", false, true),
|
||||||
USER_UPDATE("USER:UPDATE", "用户修改", false, true),
|
USER_UPDATE("USER:UPDATE", "用户修改", false, true),
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.imyeyu.api.bean;
|
||||||
|
|
||||||
|
import com.imyeyu.api.annotation.SettingBizType;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Setting;
|
||||||
|
import com.imyeyu.utils.Text;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-09-08 15:18
|
||||||
|
public interface SettingEnum {
|
||||||
|
|
||||||
|
default String getBizType() {
|
||||||
|
Class<? extends SettingEnum> implEnum = getClass();
|
||||||
|
SettingBizType bizType = implEnum.getAnnotation(SettingBizType.class);
|
||||||
|
if (bizType == null) {
|
||||||
|
return Text.bizClassName(implEnum);
|
||||||
|
}
|
||||||
|
return bizType.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
String name();
|
||||||
|
|
||||||
|
String getDefaultValue();
|
||||||
|
|
||||||
|
Setting.ValueType getValueType();
|
||||||
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
package com.imyeyu.api.config;
|
package com.imyeyu.api.config;
|
||||||
|
|
||||||
import com.e2ins.ms.notify.SmsNotifyService;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.MapperFeature;
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
|
||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.imyeyu.utils.Time;
|
import com.imyeyu.utils.Time;
|
||||||
@@ -32,12 +29,6 @@ public class BeanConfig {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public SmsNotifyService smsNotifyService() {
|
|
||||||
// TODO
|
|
||||||
return new SmsNotifyService(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Yaml yaml() {
|
public Yaml yaml() {
|
||||||
return new Yaml();
|
return new Yaml();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.imyeyu.api.config;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.imyeyu.api.modules.common.entity.Multilingual;
|
import com.imyeyu.api.modules.common.entity.Multilingual;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoUserInviteCache;
|
import com.imyeyu.api.modules.gao.bean.GaoUserInviteCache;
|
||||||
import com.imyeyu.spring.bean.RedisConfigParams;
|
import com.imyeyu.spring.bean.RedisConfigParams;
|
||||||
import com.imyeyu.spring.config.AbstractRedisConfig;
|
import com.imyeyu.spring.config.AbstractRedisConfig;
|
||||||
@@ -209,4 +210,10 @@ public class RedisConfig extends AbstractRedisConfig {
|
|||||||
public Redis<String, GaoUserInviteCache> getGaoUserInviteRedisTemplate() {
|
public Redis<String, GaoUserInviteCache> getGaoUserInviteRedisTemplate() {
|
||||||
return getRedis(database, RedisSerializers.STRING, RedisSerializers.jacksonSerializer(jackson, GaoUserInviteCache.class));
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.jacksonSerializer(jackson, GaoUserInviteCache.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @return AI 会话,AI 会话 ID: 会话授权内容
|
||||||
|
@Bean("redisGaoAiSession")
|
||||||
|
public Redis<String, GaoAiSession> getGaoAiSessionRedisTemplate() {
|
||||||
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.jacksonSerializer(jackson, GaoAiSession.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,4 +32,22 @@ public class ThreadPoolConfig {
|
|||||||
executor.initialize();
|
executor.initialize();
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 创建操作审计线程池
|
||||||
|
///
|
||||||
|
/// @return 操作审计线程池
|
||||||
|
@Bean(name = "auditTaskExecutor")
|
||||||
|
public ThreadPoolTaskExecutor auditTaskExecutor() {
|
||||||
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
|
executor.setCorePoolSize(4);
|
||||||
|
executor.setMaxPoolSize(8);
|
||||||
|
executor.setQueueCapacity(2000);
|
||||||
|
executor.setKeepAliveSeconds(60);
|
||||||
|
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||||
|
executor.setAwaitTerminationSeconds(60);
|
||||||
|
executor.setThreadNamePrefix("audit-task-executor-");
|
||||||
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
executor.initialize();
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.MapperFeature;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.imyeyu.api.annotation.EnableSettingInterceptor;
|
|
||||||
import com.imyeyu.api.annotation.RequestRateLimitInterceptor;
|
import com.imyeyu.api.annotation.RequestRateLimitInterceptor;
|
||||||
import com.imyeyu.api.annotation.RequireCorePermissionInterceptor;
|
import com.imyeyu.api.annotation.RequireCorePermissionInterceptor;
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermissionInterceptor;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermissionInterceptor;
|
||||||
@@ -40,7 +39,6 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
private final ObjectMapper jackson;
|
private final ObjectMapper jackson;
|
||||||
private final SystemAPIInterceptor systemAPIInterceptor;
|
private final SystemAPIInterceptor systemAPIInterceptor;
|
||||||
private final JournalAPIInterceptor journalAPIInterceptor;
|
private final JournalAPIInterceptor journalAPIInterceptor;
|
||||||
private final EnableSettingInterceptor enableSettingInterceptor;
|
|
||||||
private final RequestRateLimitInterceptor requestRateLimitInterceptor;
|
private final RequestRateLimitInterceptor requestRateLimitInterceptor;
|
||||||
private final RequireGaoPermissionInterceptor requireGaoPermissionInterceptor;
|
private final RequireGaoPermissionInterceptor requireGaoPermissionInterceptor;
|
||||||
private final RequireCorePermissionInterceptor requireCorePermissionInterceptor;
|
private final RequireCorePermissionInterceptor requireCorePermissionInterceptor;
|
||||||
@@ -54,7 +52,6 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(systemAPIInterceptor).addPathPatterns(SystemAPIInterceptor.PATH);
|
registry.addInterceptor(systemAPIInterceptor).addPathPatterns(SystemAPIInterceptor.PATH);
|
||||||
registry.addInterceptor(journalAPIInterceptor).addPathPatterns(JournalAPIInterceptor.PATH);
|
registry.addInterceptor(journalAPIInterceptor).addPathPatterns(JournalAPIInterceptor.PATH);
|
||||||
registry.addInterceptor(enableSettingInterceptor).addPathPatterns("/**");
|
|
||||||
registry.addInterceptor(requireCorePermissionInterceptor).addPathPatterns("/**");
|
registry.addInterceptor(requireCorePermissionInterceptor).addPathPatterns("/**");
|
||||||
registry.addInterceptor(requireGaoPermissionInterceptor).addPathPatterns("/**");
|
registry.addInterceptor(requireGaoPermissionInterceptor).addPathPatterns("/**");
|
||||||
registry.addInterceptor(requestRateLimitInterceptor).addPathPatterns("/**");
|
registry.addInterceptor(requestRateLimitInterceptor).addPathPatterns("/**");
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.imyeyu.api.modules.common.bean;
|
||||||
|
|
||||||
|
/// Groovy 脚本执行结果
|
||||||
|
///
|
||||||
|
/// @param <T> 脚本返回值类型
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
public record GroovyScriptExecutionResult<T>(String scriptId, String versionId, Integer version, String checksum, T result) {
|
||||||
|
}
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.common.bean;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Setting;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置模块
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 00:59
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public enum SettingModule {
|
|
||||||
|
|
||||||
COMMON(Setting.Module.Common.class),
|
|
||||||
|
|
||||||
DOMAIN(Setting.Module.Domain.class),
|
|
||||||
|
|
||||||
FOREVER_MC(Setting.Module.ForeverMC.class),
|
|
||||||
|
|
||||||
MULTILINGUAL(Setting.Module.Multilingual.class),
|
|
||||||
|
|
||||||
GITEA(Setting.Module.Gitea.class),
|
|
||||||
|
|
||||||
MUSIC(Setting.Module.Music.class),
|
|
||||||
|
|
||||||
JOURNAL(Setting.Module.Journal.class),
|
|
||||||
|
|
||||||
TEMP_FILE(Setting.Module.TempFile.class),
|
|
||||||
|
|
||||||
USER(Setting.Module.User.class),
|
|
||||||
|
|
||||||
SYSTEM(Setting.Module.System.class),
|
|
||||||
|
|
||||||
SYSTEM_STATUS(Setting.Module.SystemStatus.class);
|
|
||||||
|
|
||||||
/** 模块枚举类 */
|
|
||||||
final Class<? extends Enum<?>> clazz;
|
|
||||||
|
|
||||||
public static <T extends Enum<?>> SettingModule fromClass(Class<T> clazz) {
|
|
||||||
for (SettingModule value : values()) {
|
|
||||||
if (value.clazz.equals(clazz)) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new TimiException(TimiCode.ERROR, "not found System Module: %s".formatted(clazz.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.imyeyu.api.modules.common.bean;
|
||||||
|
|
||||||
|
import com.imyeyu.api.annotation.SettingBizType;
|
||||||
|
import com.imyeyu.api.bean.SettingEnum;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Setting;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2026-04-24 14:47
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@SettingBizType("TEMP_FILE")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum TempFileSetting implements SettingEnum {
|
||||||
|
|
||||||
|
/** 启用服务 */
|
||||||
|
ENABLE(Boolean.TRUE.toString(), Setting.ValueType.BOOLEAN),
|
||||||
|
|
||||||
|
/** 最小缓存时长 */
|
||||||
|
TTL_MIN("1h", Setting.ValueType.TIME),
|
||||||
|
|
||||||
|
/** 默认缓存时长 */
|
||||||
|
TTL_DEFAULT("3d", Setting.ValueType.TIME),
|
||||||
|
|
||||||
|
/** 最大缓存时长 */
|
||||||
|
TTL_MAX("7d", Setting.ValueType.TIME),
|
||||||
|
|
||||||
|
/** 已过期文件残留时长 */
|
||||||
|
RESIDUE_TTL("90d", Setting.ValueType.TIME),
|
||||||
|
|
||||||
|
/** 每个 IP 限制有效临时文件容量 */
|
||||||
|
LIMIT_SIZE_OF_IP("10 GB", Setting.ValueType.BYTE_SIZE);
|
||||||
|
|
||||||
|
final String defaultValue;
|
||||||
|
|
||||||
|
final Setting.ValueType valueType;
|
||||||
|
}
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.common.bean.attachment;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2025-12-11 18:14
|
|
||||||
*/
|
|
||||||
public class Metadata {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图片
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2025-12-11 18:15
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class Image {
|
|
||||||
|
|
||||||
private int width;
|
|
||||||
|
|
||||||
private int height;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缩略图
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-01-04 18:10
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public static class ThumbImage extends Image {
|
|
||||||
|
|
||||||
private String sourceId;
|
|
||||||
|
|
||||||
private String sourceMongoId;
|
|
||||||
|
|
||||||
private String sourceMimeType;
|
|
||||||
|
|
||||||
/** 请求宽度(缓存键之一,null 表示未指定) */
|
|
||||||
private Integer requestWidth;
|
|
||||||
|
|
||||||
/** 请求高度(缓存键之一,null 表示未指定) */
|
|
||||||
private Integer requestHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.imyeyu.api.modules.common.bean.attachment;
|
||||||
|
|
||||||
|
/// 缩略图缩放模式
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
public enum ThumbnailFitMode {
|
||||||
|
|
||||||
|
/// 保持比例完整放入目标尺寸
|
||||||
|
FIT,
|
||||||
|
|
||||||
|
/// 保持比例裁剪填满目标尺寸
|
||||||
|
COVER,
|
||||||
|
|
||||||
|
/// 强制缩放到目标尺寸,可能导致图片变形
|
||||||
|
STRETCH
|
||||||
|
}
|
||||||
@@ -42,6 +42,19 @@ public class NotifyQueueConfig {
|
|||||||
private String secretId;
|
private String secretId;
|
||||||
|
|
||||||
private String secretKey;
|
private String secretKey;
|
||||||
|
|
||||||
|
private Captcha captcha;
|
||||||
|
|
||||||
|
/// 短信验证码
|
||||||
|
@Data
|
||||||
|
public static class Captcha {
|
||||||
|
|
||||||
|
private String templateId;
|
||||||
|
|
||||||
|
private int ttlMinute;
|
||||||
|
|
||||||
|
private int argIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 微信队列配置
|
/// 微信队列配置
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package com.imyeyu.api.modules.common.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.imyeyu.api.annotation.RequireCorePermission;
|
||||||
|
import com.imyeyu.api.bean.CorePermissionCode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Article;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.ArticleService;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
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.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/// 文章接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-09
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/article")
|
||||||
|
public class ArticleController {
|
||||||
|
|
||||||
|
private final ArticleService service;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
|
/// 查询文章列表
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @return 文章分页
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.ARTICLE_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<Article> list(@RequestBody Page<Article> page) {
|
||||||
|
return service.page(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询文章详情
|
||||||
|
///
|
||||||
|
/// @param id 文章 ID
|
||||||
|
/// @return 文章详情
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequestMapping("/detail")
|
||||||
|
public Article detail(@RequestParam String id) {
|
||||||
|
Article article = service.get(id);
|
||||||
|
article.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.ARTICLE, article.getId()));
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 创建文章
|
||||||
|
///
|
||||||
|
/// @param article 文章
|
||||||
|
/// @return 创建后的文章
|
||||||
|
@AOPLog
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.ARTICLE_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public Article create(@RequestBody Article article) {
|
||||||
|
service.create(article);
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 更新文章
|
||||||
|
///
|
||||||
|
/// @param article 文章
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.ARTICLE_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody Article article) {
|
||||||
|
service.update(article);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除文章
|
||||||
|
///
|
||||||
|
/// @param id 文章 ID
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.ARTICLE_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.imyeyu.api.modules.common.controller;
|
package com.imyeyu.api.modules.common.controller;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.ThumbnailFitMode;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentVariantService;
|
||||||
import com.imyeyu.api.modules.common.service.TempFileService;
|
import com.imyeyu.api.modules.common.service.TempFileService;
|
||||||
import com.imyeyu.api.modules.common.vo.attach.TempFileResp;
|
import com.imyeyu.api.modules.common.vo.attach.TempFileResp;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
@@ -41,6 +43,7 @@ public class AttachmentController {
|
|||||||
|
|
||||||
private final TempFileService tempFileService;
|
private final TempFileService tempFileService;
|
||||||
private final AttachmentService service;
|
private final AttachmentService service;
|
||||||
|
private final AttachmentVariantService variantService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询附件详情
|
* 查询附件详情
|
||||||
@@ -184,14 +187,19 @@ public class AttachmentController {
|
|||||||
@AOPLog
|
@AOPLog
|
||||||
@IgnoreGlobalReturn
|
@IgnoreGlobalReturn
|
||||||
@GetMapping({"/read/{id}", "/download/{id}"})
|
@GetMapping({"/read/{id}", "/download/{id}"})
|
||||||
public void readById(@PathVariable String id, @RequestParam(required = false) Integer thumbWidth, @RequestParam(required = false) Integer thumbHeight) throws UnsupportedEncodingException {
|
public void readById(
|
||||||
|
@PathVariable String id,
|
||||||
|
@RequestParam(required = false) Integer thumbWidth,
|
||||||
|
@RequestParam(required = false) Integer thumbHeight,
|
||||||
|
@RequestParam(defaultValue = "FIT") ThumbnailFitMode fitMode
|
||||||
|
) throws UnsupportedEncodingException {
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
Attachment attach = service.get(id);
|
Attachment attach = service.get(id);
|
||||||
if (attach == null) {
|
if (attach == null) {
|
||||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
responseAttachment(attach, thumbWidth, thumbHeight);
|
responseAttachment(attach, thumbWidth, thumbHeight, fitMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -207,21 +215,31 @@ public class AttachmentController {
|
|||||||
public void read(@RequestParam String id) throws UnsupportedEncodingException {
|
public void read(@RequestParam String id) throws UnsupportedEncodingException {
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
Attachment attach = service.get(id);
|
Attachment attach = service.get(id);
|
||||||
|
if (attach == null) {
|
||||||
|
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (TimiSpring.getRequest().getRequestURI().endsWith("/download")) {
|
if (TimiSpring.getRequest().getRequestURI().endsWith("/download")) {
|
||||||
resp.setHeader("Content-Disposition", Network.getFileDownloadHeader(attach.getName()));
|
resp.setHeader("Content-Disposition", Network.getFileDownloadHeader(attach.getName()));
|
||||||
}
|
}
|
||||||
response(attach);
|
response(attach, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void responseAttachment(Attachment attach, Integer thumbWidth, Integer thumbHeight) throws UnsupportedEncodingException {
|
private void responseAttachment(
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
Attachment attach,
|
||||||
if (attach != null && TimiSpring.getRequest().getRequestURI().endsWith("/download") && attach.getName() != null) {
|
Integer thumbWidth,
|
||||||
resp.setHeader("Content-Disposition", Network.getFileDownloadHeader(attach.getName()));
|
Integer thumbHeight,
|
||||||
}
|
ThumbnailFitMode fitMode
|
||||||
responseThumb(attach, thumbWidth, thumbHeight);
|
) throws UnsupportedEncodingException {
|
||||||
|
responseThumb(attach, thumbWidth, thumbHeight, fitMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void responseThumb(Attachment attachment, Integer thumbWidth, Integer thumbHeight) {
|
protected void responseThumb(
|
||||||
|
Attachment attachment,
|
||||||
|
Integer thumbWidth,
|
||||||
|
Integer thumbHeight,
|
||||||
|
ThumbnailFitMode fitMode
|
||||||
|
) throws UnsupportedEncodingException {
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
if (TimiJava.isEmpty(attachment)) {
|
if (TimiJava.isEmpty(attachment)) {
|
||||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
@@ -229,21 +247,65 @@ public class AttachmentController {
|
|||||||
}
|
}
|
||||||
if (thumbWidth == null && thumbHeight == null) {
|
if (thumbWidth == null && thumbHeight == null) {
|
||||||
// 原图
|
// 原图
|
||||||
|
setDownloadHeader(attachment);
|
||||||
response(attachment);
|
response(attachment);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 缩略图
|
// 缩略图
|
||||||
Attachment thumb = service.fetchThumb(attachment, thumbWidth, thumbHeight);
|
Attachment thumb = variantService.fetchThumb(attachment, thumbWidth, thumbHeight, fitMode);
|
||||||
response(TimiJava.defaultIfNull(thumb, attachment));
|
setDownloadHeader(thumb);
|
||||||
|
response(thumb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDownloadHeader(Attachment attachment) throws UnsupportedEncodingException {
|
||||||
|
if (attachment != null && TimiSpring.getRequest().getRequestURI().endsWith("/download") && attachment.getName() != null) {
|
||||||
|
TimiSpring.getResponse().setHeader("Content-Disposition", Network.getFileDownloadHeader(attachment.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 设置附件缓存头并处理条件请求
|
||||||
|
///
|
||||||
|
/// @param attachment 实际响应附件
|
||||||
|
/// @return true 表示客户端缓存仍有效,已返回 304
|
||||||
|
private boolean responseCache(Attachment attachment) {
|
||||||
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
|
resp.setHeader("Cache-Control", "private, no-cache");
|
||||||
|
String md5 = attachment.getMd5();
|
||||||
|
if (md5 == null || md5.isBlank()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String etag = "\"%s\"".formatted(md5);
|
||||||
|
resp.setHeader("ETag", etag);
|
||||||
|
String ifNoneMatch = TimiSpring.getHeader("If-None-Match");
|
||||||
|
if (ifNoneMatch == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String value : ifNoneMatch.split(",")) {
|
||||||
|
String candidate = value.trim();
|
||||||
|
if ("*".equals(candidate) || etag.equals(candidate) || ("W/" + etag).equals(candidate)) {
|
||||||
|
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void response(Attachment attachment) {
|
protected void response(Attachment attachment) {
|
||||||
|
response(attachment, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void response(Attachment attachment, boolean cacheable) {
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
try {
|
try {
|
||||||
if (TimiJava.isEmpty(attachment)) {
|
if (TimiJava.isEmpty(attachment)) {
|
||||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!cacheable) {
|
||||||
|
resp.setHeader("Cache-Control", "private, no-store");
|
||||||
|
} else if (responseCache(attachment)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
resp.setContentType(attachment.getMimeType());
|
resp.setContentType(attachment.getMimeType());
|
||||||
attachment.doResponse();
|
attachment.doResponse();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.imyeyu.api.modules.common.controller;
|
package com.imyeyu.api.modules.common.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.vo.ClientLogRequest;
|
||||||
import com.imyeyu.api.modules.system.entity.Logger;
|
import com.imyeyu.api.modules.system.entity.Logger;
|
||||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
@@ -29,7 +30,9 @@ public class LoggerController {
|
|||||||
@AOPLog
|
@AOPLog
|
||||||
@RequiredToken
|
@RequiredToken
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public void create(@Valid @RequestBody Logger logger) {
|
public void create(@Valid @RequestBody ClientLogRequest request) {
|
||||||
|
Logger logger = Logger.info(Logger.Module.COMMON, "CLIENT_LOG");
|
||||||
|
logger.setContent(request.getContent());
|
||||||
service.create(logger);
|
service.create(logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,17 @@ import com.imyeyu.api.modules.common.entity.Notify;
|
|||||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||||
import com.imyeyu.api.modules.common.service.NotifyService;
|
import com.imyeyu.api.modules.common.service.NotifyService;
|
||||||
|
import com.imyeyu.api.modules.common.service.SmsService;
|
||||||
|
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||||
import com.imyeyu.api.modules.user.entity.User;
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
import com.imyeyu.api.modules.user.service.UserService;
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.CaptchaValid;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import com.imyeyu.spring.annotation.RequiredToken;
|
import com.imyeyu.spring.annotation.RequiredToken;
|
||||||
|
import com.imyeyu.spring.bean.CaptchaData;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.util.ResponseView;
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
@@ -37,6 +43,8 @@ import java.util.stream.Stream;
|
|||||||
@RequestMapping("/notify")
|
@RequestMapping("/notify")
|
||||||
public class NotifyController {
|
public class NotifyController {
|
||||||
|
|
||||||
|
|
||||||
|
private final SmsService smsService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final NotifyService service;
|
private final NotifyService service;
|
||||||
private final UserLoginService userLoginService;
|
private final UserLoginService userLoginService;
|
||||||
@@ -50,6 +58,14 @@ public class NotifyController {
|
|||||||
@RequiredToken
|
@RequiredToken
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public Notify create(@RequestBody Notify notify) {
|
public Notify create(@RequestBody Notify notify) {
|
||||||
|
String sendFrom = userLoginService.isLogged() ? userLoginService.getRequireLoginUserId() : null;
|
||||||
|
notify.setCreatedBy(sendFrom);
|
||||||
|
for (NotifyDetail detail : notify.getDetailList()) {
|
||||||
|
detail.setNotifyId(notify.getId());
|
||||||
|
if (TimiJava.isNotEmpty(sendFrom)) {
|
||||||
|
detail.setSendFrom(sendFrom);
|
||||||
|
}
|
||||||
|
}
|
||||||
service.create(notify);
|
service.create(notify);
|
||||||
return notify;
|
return notify;
|
||||||
}
|
}
|
||||||
@@ -63,25 +79,31 @@ public class NotifyController {
|
|||||||
@RequiredToken
|
@RequiredToken
|
||||||
@RequestMapping("/detail")
|
@RequestMapping("/detail")
|
||||||
public Notify detail(@RequestParam String id) {
|
public Notify detail(@RequestParam String id) {
|
||||||
Notify notify = service.get(id);
|
return fillDetailList(service.get(id));
|
||||||
{
|
}
|
||||||
List<NotifyDetail> detailList = detailService.listByNotifyId(id);
|
|
||||||
Set<String> userIdSet = detailList.stream()
|
/// 查询管理端通知列表
|
||||||
.filter(item -> item.getMsgType() == NotifyDetail.MsgType.INTERNAL)
|
///
|
||||||
.flatMap(item -> Stream.of(item.getSendFrom(), item.getSendTo()))
|
/// @param page 分页参数
|
||||||
.collect(Collectors.toSet());
|
/// @return 管理端通知列表
|
||||||
Map<String, User> userMap = userService.mapByIdList(userIdSet);
|
@JsonView(ResponseView.Admin.class)
|
||||||
for (NotifyDetail detail : detailList) {
|
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||||
if (TimiJava.isNotEmpty(detail.getSendFrom())) {
|
@RequiredToken
|
||||||
detail.setFromUser(userMap.get(detail.getSendFrom()));
|
@PostMapping("/management/list")
|
||||||
}
|
public PageResult<NotifyManagementItem> managementList(@RequestBody(required = false) Page<Notify> page) {
|
||||||
if (TimiJava.isNotEmpty(detail.getSendTo())) {
|
return service.pageManagement(page, userLoginService.getRequireLoginUserId());
|
||||||
detail.setToUser(userMap.get(detail.getSendTo()));
|
}
|
||||||
}
|
|
||||||
}
|
/// 查询管理端通知详情及收件人
|
||||||
notify.setDetailList(detailList);
|
///
|
||||||
}
|
/// @param id 通知 ID
|
||||||
return notify;
|
/// @return 通知详情及收件人
|
||||||
|
@JsonView(ResponseView.Admin.class)
|
||||||
|
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||||
|
@RequiredToken
|
||||||
|
@PostMapping("/management/detail")
|
||||||
|
public Notify managementDetail(@RequestParam String id) {
|
||||||
|
return fillDetailList(service.getManagement(id, userLoginService.getRequireLoginUserId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 删除通知及其通知详情
|
/// 删除通知及其通知详情
|
||||||
@@ -104,6 +126,34 @@ public class NotifyController {
|
|||||||
service.cancel(id);
|
service.cancel(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 删除管理端通知及其通知详情
|
||||||
|
///
|
||||||
|
/// @param id 通知 ID
|
||||||
|
@RequireCorePermission(CorePermissionCode.NOTIFY_DELETE)
|
||||||
|
@RequiredToken
|
||||||
|
@PostMapping("/management/delete")
|
||||||
|
public void managementDelete(@RequestParam String id) {
|
||||||
|
service.deleteManagement(id, userLoginService.getRequireLoginUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 取消管理端尚未成功发送的通知
|
||||||
|
///
|
||||||
|
/// @param id 通知 ID
|
||||||
|
@RequireCorePermission(CorePermissionCode.NOTIFY_CANCEL)
|
||||||
|
@RequiredToken
|
||||||
|
@PostMapping("/management/cancel")
|
||||||
|
public void managementCancel(@RequestParam String id) {
|
||||||
|
service.cancelManagement(id, userLoginService.getRequireLoginUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@CaptchaValid
|
||||||
|
@RequestRateLimit(value = 1, inSeconds = 59)
|
||||||
|
@PostMapping("/sms/captcha/create")
|
||||||
|
public String smsCaptchaCreate(@RequestBody CaptchaData<Notify> req) {
|
||||||
|
return smsService.captchaCreate(req.getData());
|
||||||
|
}
|
||||||
|
|
||||||
/// 查询当前用户的站内通知
|
/// 查询当前用户的站内通知
|
||||||
///
|
///
|
||||||
/// @param page 分页参数
|
/// @param page 分页参数
|
||||||
@@ -134,14 +184,14 @@ public class NotifyController {
|
|||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 删除当前用户的一条站内通知
|
/// 隐藏当前用户的一条站内通知
|
||||||
///
|
///
|
||||||
/// @param id 通知详情 ID
|
/// @param id 通知详情 ID
|
||||||
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||||
@RequiredToken
|
@RequiredToken
|
||||||
@PostMapping("/internal/delete")
|
@PostMapping("/internal/delete")
|
||||||
public void deleteInternal(@RequestParam String id) {
|
public void deleteInternal(@RequestParam String id) {
|
||||||
detailService.deleteInternalByUserId(id, userLoginService.getRequireLoginUserId());
|
detailService.hideInternalByUserId(id, userLoginService.getRequireLoginUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 查询当前用户未读通知数量
|
/// 查询当前用户未读通知数量
|
||||||
@@ -171,4 +221,30 @@ public class NotifyController {
|
|||||||
public void markAllSiteRead() {
|
public void markAllSiteRead() {
|
||||||
detailService.markAllSiteRead(userLoginService.getRequireLoginUserId());
|
detailService.markAllSiteRead(userLoginService.getRequireLoginUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 回填通知详情中的用户信息
|
||||||
|
///
|
||||||
|
/// @param notify 通知
|
||||||
|
/// @return 已回填用户信息的通知
|
||||||
|
private Notify fillDetailList(Notify notify) {
|
||||||
|
if (notify == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<NotifyDetail> detailList = detailService.listByNotifyId(notify.getId());
|
||||||
|
Set<String> userIdSet = detailList.stream()
|
||||||
|
.filter(item -> item.getMsgType() == NotifyDetail.MsgType.INTERNAL)
|
||||||
|
.flatMap(item -> Stream.of(item.getSendFrom(), item.getSendTo()))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
Map<String, User> userMap = userService.mapByIdList(userIdSet);
|
||||||
|
for (NotifyDetail detail : detailList) {
|
||||||
|
if (TimiJava.isNotEmpty(detail.getSendFrom())) {
|
||||||
|
detail.setFromUser(userMap.get(detail.getSendFrom()));
|
||||||
|
}
|
||||||
|
if (TimiJava.isNotEmpty(detail.getSendTo())) {
|
||||||
|
detail.setToUser(userMap.get(detail.getSendTo()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notify.setDetailList(detailList);
|
||||||
|
return notify;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,12 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@@ -26,11 +30,30 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/system/setting")
|
@RequestMapping("/setting")
|
||||||
public class SettingController {
|
public class SettingController {
|
||||||
|
|
||||||
private final SettingService service;
|
private final SettingService service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询公开配置映射
|
||||||
|
*
|
||||||
|
* @param bizType 业务类型
|
||||||
|
* @param bizId 业务 ID,可为空
|
||||||
|
* @param code 配置代码列表,可为空
|
||||||
|
* @return 公开配置映射
|
||||||
|
*/
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequestMapping("/map")
|
||||||
|
public Map<String, Setting> map(
|
||||||
|
@RequestParam String bizType,
|
||||||
|
@RequestParam(required = false) String bizId,
|
||||||
|
@RequestParam(required = false) List<String> code
|
||||||
|
) {
|
||||||
|
return service.mapPublic(bizType, bizId, code);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询配置列表
|
* 查询配置列表
|
||||||
*
|
*
|
||||||
@@ -53,6 +76,7 @@ public class SettingController {
|
|||||||
*/
|
*/
|
||||||
@JsonView(ResponseView.Admin.class)
|
@JsonView(ResponseView.Admin.class)
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.SETTING_READ)
|
||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
public Setting detail(@RequestBody String id) {
|
public Setting detail(@RequestBody String id) {
|
||||||
return service.get(id);
|
return service.get(id);
|
||||||
@@ -66,6 +90,7 @@ public class SettingController {
|
|||||||
*/
|
*/
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@JsonView(ResponseView.Admin.class)
|
@JsonView(ResponseView.Admin.class)
|
||||||
|
@RequireCorePermission(CorePermissionCode.SETTING_CREATE)
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public Setting create(@RequestBody Setting setting) {
|
public Setting create(@RequestBody Setting setting) {
|
||||||
@@ -80,6 +105,7 @@ public class SettingController {
|
|||||||
*/
|
*/
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.SETTING_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void update(@RequestBody Setting setting) {
|
public void update(@RequestBody Setting setting) {
|
||||||
service.update(setting);
|
service.update(setting);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.SettingSupport;
|
import com.imyeyu.api.modules.common.bean.attachment.SettingSupport;
|
||||||
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
import com.imyeyu.spring.annotation.table.PageIgnore;
|
import com.imyeyu.spring.annotation.table.PageIgnore;
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
@@ -30,6 +31,13 @@ public class Article extends UUIDEntity implements SettingSupport {
|
|||||||
/** 博客 */
|
/** 博客 */
|
||||||
BLOG,
|
BLOG,
|
||||||
|
|
||||||
|
/// GAO 门店日记
|
||||||
|
GAO_STORE_DIARY,
|
||||||
|
|
||||||
|
GAO_HELP,
|
||||||
|
|
||||||
|
GAO_SYSTEM,
|
||||||
|
|
||||||
/// 反馈
|
/// 反馈
|
||||||
FEEDBACK
|
FEEDBACK
|
||||||
}
|
}
|
||||||
@@ -93,6 +101,12 @@ public class Article extends UUIDEntity implements SettingSupport {
|
|||||||
/** 文章状态 */
|
/** 文章状态 */
|
||||||
protected Status status;
|
protected Status status;
|
||||||
|
|
||||||
|
/// 最后更新用户 ID
|
||||||
|
protected String updatedBy;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
protected User updater;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
protected List<Setting> settingList;
|
protected List<Setting> settingList;
|
||||||
|
|
||||||
|
|||||||
@@ -32,12 +32,32 @@ public class Attachment extends UUIDEntity {
|
|||||||
|
|
||||||
ARTICLE,
|
ARTICLE,
|
||||||
|
|
||||||
|
NOTIFY_DETAIL,
|
||||||
|
|
||||||
USER,
|
USER,
|
||||||
|
|
||||||
GAO_CUSTOMER,
|
GAO_CUSTOMER,
|
||||||
|
|
||||||
|
GAO_PRODUCT,
|
||||||
|
|
||||||
|
GAO_PRODUCT_SKU,
|
||||||
|
|
||||||
GAO_EVENT_RECORD,
|
GAO_EVENT_RECORD,
|
||||||
|
|
||||||
|
GAO_FUND_RECORD,
|
||||||
|
|
||||||
|
GAO_STOCK_RECORD,
|
||||||
|
|
||||||
|
GAO_ORDER_FULFILLMENT,
|
||||||
|
|
||||||
|
GAO_SALES_ORDER,
|
||||||
|
|
||||||
|
GAO_POINT_REDEMPTION,
|
||||||
|
|
||||||
|
GAO_POINT_REDEMPTION_RETURN,
|
||||||
|
|
||||||
|
GAO_CUSTOMER_FOLLOW_UP_REMINDER,
|
||||||
|
|
||||||
TEMP_FILE,
|
TEMP_FILE,
|
||||||
|
|
||||||
MIRROR
|
MIRROR
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.ThumbnailFitMode;
|
||||||
|
import com.imyeyu.spring.annotation.table.AutoUUID;
|
||||||
|
import com.imyeyu.spring.annotation.table.Id;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/// 附件缩略图变体记录
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
@Data
|
||||||
|
public class AttachmentVariant {
|
||||||
|
|
||||||
|
/// 变体 ID
|
||||||
|
@Id
|
||||||
|
@AutoUUID
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/// 源附件 ID
|
||||||
|
private String sourceAttachmentId;
|
||||||
|
|
||||||
|
/// 源文件版本,使用源 GridFS ID
|
||||||
|
private String sourceMongoId;
|
||||||
|
|
||||||
|
/// 源文件摘要
|
||||||
|
private String sourceMd5;
|
||||||
|
|
||||||
|
/// 请求宽度,0 表示未指定
|
||||||
|
private int requestWidth;
|
||||||
|
|
||||||
|
/// 请求高度,0 表示未指定
|
||||||
|
private int requestHeight;
|
||||||
|
|
||||||
|
/// 缩放模式
|
||||||
|
private ThumbnailFitMode fitMode;
|
||||||
|
|
||||||
|
/// 输出格式
|
||||||
|
private String outputFormat;
|
||||||
|
|
||||||
|
/// 缩略图算法版本
|
||||||
|
private String algorithmVersion;
|
||||||
|
|
||||||
|
/// 缩略图 GridFS ID
|
||||||
|
private String mongoId;
|
||||||
|
|
||||||
|
/// 缩略图名称
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/// 缩略图 MIME 类型
|
||||||
|
private String mimeType;
|
||||||
|
|
||||||
|
/// 缩略图元数据
|
||||||
|
private ObjectNode metadata;
|
||||||
|
|
||||||
|
/// 缩略图大小
|
||||||
|
private long size;
|
||||||
|
|
||||||
|
/// 缩略图摘要
|
||||||
|
private String md5;
|
||||||
|
|
||||||
|
/// 创建时间
|
||||||
|
private long createdAt;
|
||||||
|
|
||||||
|
/// 过期时间
|
||||||
|
private long expireAt;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.imyeyu.spring.annotation.table.AutoUUID;
|
import com.imyeyu.spring.annotation.table.AutoUUID;
|
||||||
import com.imyeyu.spring.annotation.table.Id;
|
import com.imyeyu.spring.annotation.table.Id;
|
||||||
import com.imyeyu.spring.entity.Creatable;
|
import com.imyeyu.spring.entity.Creatable;
|
||||||
@@ -25,10 +26,10 @@ public class BaseQueueEntity implements IDEntity<String>, Creatable, Destroyable
|
|||||||
protected String notifyDetailId;
|
protected String notifyDetailId;
|
||||||
|
|
||||||
/** 内容 */
|
/** 内容 */
|
||||||
protected String data;
|
protected String content;
|
||||||
|
|
||||||
/** 参数 */
|
/** 参数 */
|
||||||
protected String args;
|
protected JsonNode args;
|
||||||
|
|
||||||
/** 发送去向 */
|
/** 发送去向 */
|
||||||
protected String sendTo;
|
protected String sendTo;
|
||||||
@@ -50,7 +51,7 @@ public class BaseQueueEntity implements IDEntity<String>, Creatable, Destroyable
|
|||||||
/// @param detail 通知详情
|
/// @param detail 通知详情
|
||||||
public BaseQueueEntity(NotifyDetail detail) {
|
public BaseQueueEntity(NotifyDetail detail) {
|
||||||
notifyDetailId = detail.getId();
|
notifyDetailId = detail.getId();
|
||||||
data = detail.getData();
|
content = detail.getContent();
|
||||||
args = detail.getArgs();
|
args = detail.getArgs();
|
||||||
sendTo = detail.getSendTo();
|
sendTo = detail.getSendTo();
|
||||||
sendAt = detail.getSendAt();
|
sendAt = detail.getSendAt();
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/// Groovy 脚本
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GroovyScript extends UUIDEntity {
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026/9/4 14:54
|
||||||
|
public enum BizType {
|
||||||
|
|
||||||
|
/// GAO 积分规则
|
||||||
|
GAO_POINT_RULE
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 业务归属
|
||||||
|
private BizType bizType;
|
||||||
|
|
||||||
|
/// 业务内唯一代码
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/// 名称
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/// 说明
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/// true 为允许执行已发布版本
|
||||||
|
private Boolean enabled;
|
||||||
|
|
||||||
|
/// 当前发布版本 ID
|
||||||
|
private String publishedVersionId;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private GroovyScriptVersion latest;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/// Groovy 脚本版本
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GroovyScriptVersion extends UUIDEntity {
|
||||||
|
|
||||||
|
/// 脚本 ID
|
||||||
|
private String scriptId;
|
||||||
|
|
||||||
|
/// 版本号
|
||||||
|
private Integer version;
|
||||||
|
|
||||||
|
/// 脚本内容
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/// 脚本内容 SHA-256
|
||||||
|
private String checksum;
|
||||||
|
}
|
||||||
@@ -20,11 +20,11 @@ public class Notify extends UUIDEntity {
|
|||||||
/** 业务类型 */
|
/** 业务类型 */
|
||||||
private String bizType;
|
private String bizType;
|
||||||
|
|
||||||
/** 提醒业务类型 */
|
/** 业务提醒类型 */
|
||||||
private String bizRemindedType;
|
private String bizRemindedType;
|
||||||
|
|
||||||
/** 提醒业务 ID */
|
/** 业务提醒查重键 */
|
||||||
private String bizRemindedId;
|
private String bizRemindedKey;
|
||||||
|
|
||||||
/** 参数 */
|
/** 参数 */
|
||||||
private String args;
|
private String args;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonView;
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.imyeyu.api.TimiServerAPI;
|
import com.imyeyu.api.TimiServerAPI;
|
||||||
import com.imyeyu.api.modules.common.service.BaseQueueService;
|
import com.imyeyu.api.modules.common.service.BaseQueueService;
|
||||||
import com.imyeyu.api.modules.common.service.HTTPQueueService;
|
import com.imyeyu.api.modules.common.service.HTTPQueueService;
|
||||||
@@ -15,6 +17,8 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知详情
|
* 通知详情
|
||||||
*
|
*
|
||||||
@@ -81,6 +85,19 @@ public class NotifyDetail extends UUIDEntity {
|
|||||||
FAIL
|
FAIL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 内容类型
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-24
|
||||||
|
public enum ContentType {
|
||||||
|
|
||||||
|
/** 纯文本 */
|
||||||
|
TEXT,
|
||||||
|
|
||||||
|
/** TipTap 富文本 */
|
||||||
|
TIP_TAP
|
||||||
|
}
|
||||||
|
|
||||||
/** 所属通知 ID */
|
/** 所属通知 ID */
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
private String notifyId;
|
private String notifyId;
|
||||||
@@ -99,11 +116,15 @@ public class NotifyDetail extends UUIDEntity {
|
|||||||
|
|
||||||
/** 内容 */
|
/** 内容 */
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
private String data;
|
private String content;
|
||||||
|
|
||||||
|
/// 内容类型
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
private ContentType contentType;
|
||||||
|
|
||||||
/** 参数 */
|
/** 参数 */
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
private String args;
|
private JsonNode args;
|
||||||
|
|
||||||
/** 发送来源 */
|
/** 发送来源 */
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
@@ -137,6 +158,10 @@ public class NotifyDetail extends UUIDEntity {
|
|||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
private Long readAt;
|
private Long readAt;
|
||||||
|
|
||||||
|
/// 收件人隐藏时间,仅站内通知生效
|
||||||
|
@JsonIgnore
|
||||||
|
private Long hiddenAt;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
protected Notify notify;
|
protected Notify notify;
|
||||||
|
|
||||||
@@ -145,4 +170,9 @@ public class NotifyDetail extends UUIDEntity {
|
|||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
protected User toUser;
|
protected User toUser;
|
||||||
|
|
||||||
|
/// 媒体附件列表
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@Transient
|
||||||
|
protected List<Attachment> attachmentList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.imyeyu.api.TimiServerAPI;
|
import com.imyeyu.api.TimiServerAPI;
|
||||||
import com.imyeyu.api.modules.common.bean.SettingModule;
|
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import com.imyeyu.spring.util.ResponseView;
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
@@ -62,6 +61,9 @@ public class Setting extends UUIDEntity {
|
|||||||
/** 时间 */
|
/** 时间 */
|
||||||
TIME,
|
TIME,
|
||||||
|
|
||||||
|
/// 字节大小
|
||||||
|
BYTE_SIZE,
|
||||||
|
|
||||||
/** 时长 */
|
/** 时长 */
|
||||||
DURATION,
|
DURATION,
|
||||||
|
|
||||||
@@ -102,16 +104,6 @@ public class Setting extends UUIDEntity {
|
|||||||
@Transient
|
@Transient
|
||||||
private Enum<?> keyRaw;
|
private Enum<?> keyRaw;
|
||||||
|
|
||||||
public Setting(Enum<?> key) {
|
|
||||||
setKeyRaw(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Setting(Enum<?> key, Object value, ValueType valueType) {
|
|
||||||
setKeyRaw(key);
|
|
||||||
this.value = value.toString();
|
|
||||||
this.valueType = valueType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以字符串形式返回配置值
|
* 以字符串形式返回配置值
|
||||||
*
|
*
|
||||||
@@ -221,298 +213,4 @@ public class Setting extends UUIDEntity {
|
|||||||
throw new IllegalArgumentException("setting value is not valid json: %s".formatted(value), e);
|
throw new IllegalArgumentException("setting value is not valid json: %s".formatted(value), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyRaw(Enum<?> key) {
|
|
||||||
this.keyRaw = key;
|
|
||||||
this.bizType = SettingModule.fromClass(key.getClass()).toString();
|
|
||||||
this.code = key.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean is(Enum<?> key) {
|
|
||||||
return SettingModule.fromClass(key.getClass()).toString().equals(bizType) && key.toString().equals(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 14:23
|
|
||||||
*/
|
|
||||||
public static final class Module {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 15:39
|
|
||||||
*/
|
|
||||||
public enum Common {
|
|
||||||
|
|
||||||
/** 微信收款码 */
|
|
||||||
WECHAT_RECEIVE_QR_CODE
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 域名
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-26 17:18
|
|
||||||
*/
|
|
||||||
public enum Domain {
|
|
||||||
|
|
||||||
ROOT,
|
|
||||||
|
|
||||||
API,
|
|
||||||
|
|
||||||
GIT,
|
|
||||||
|
|
||||||
BLOG,
|
|
||||||
|
|
||||||
SPACE,
|
|
||||||
|
|
||||||
FOREVER_MC
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 15:14
|
|
||||||
*/
|
|
||||||
public enum Blog {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 15:03
|
|
||||||
*/
|
|
||||||
public enum User {
|
|
||||||
|
|
||||||
/** 启用登录 */
|
|
||||||
ENABLE_LOGIN,
|
|
||||||
|
|
||||||
/** 启用注册 */
|
|
||||||
ENABLE_REGISTER,
|
|
||||||
|
|
||||||
/** 允许数据更新 */
|
|
||||||
ENABLE_PROFILE_UPDATE,
|
|
||||||
|
|
||||||
/** 令牌有效期 */
|
|
||||||
TOKEN_TTL
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 15:21
|
|
||||||
*/
|
|
||||||
public enum Comment {
|
|
||||||
|
|
||||||
/** 启用服务 */
|
|
||||||
ENABLE
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 15:03
|
|
||||||
*/
|
|
||||||
public enum ICP {
|
|
||||||
|
|
||||||
IMYEYU_COM
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 15:01
|
|
||||||
*/
|
|
||||||
public enum ForeverMC {
|
|
||||||
|
|
||||||
PLAYER_BIND_MAX,
|
|
||||||
|
|
||||||
LOGIN_TOKEN_TTL
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 14:57
|
|
||||||
*/
|
|
||||||
public enum Multilingual {
|
|
||||||
|
|
||||||
/** 翻译 API */
|
|
||||||
TRANSLATE_API,
|
|
||||||
|
|
||||||
/** 翻译 AppId */
|
|
||||||
TRANSLATE_APP_ID,
|
|
||||||
|
|
||||||
/** 翻译密钥 */
|
|
||||||
TRANSLATE_KEY,
|
|
||||||
|
|
||||||
/** 翻译计划任务表达式 */
|
|
||||||
TRANSLATE_CORN,
|
|
||||||
|
|
||||||
/** 缓存时长 */
|
|
||||||
CACHE_TTL
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 14:55
|
|
||||||
*/
|
|
||||||
public enum Gitea {
|
|
||||||
|
|
||||||
/** 接口地址 */
|
|
||||||
API,
|
|
||||||
|
|
||||||
/** 关于页面所属文章 ID */
|
|
||||||
ABOUT_ARTICLE_ID,
|
|
||||||
|
|
||||||
/** 仓库文件地址 */
|
|
||||||
REPOSITORY_PATH
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 14:52
|
|
||||||
*/
|
|
||||||
public enum Music {
|
|
||||||
|
|
||||||
/** 启用服务 */
|
|
||||||
ENABLE,
|
|
||||||
|
|
||||||
/** 通信消息最大帧长度 */
|
|
||||||
MAX_FRAME_LENGTH,
|
|
||||||
|
|
||||||
/** 受控端 IP */
|
|
||||||
PLAYER_IP,
|
|
||||||
|
|
||||||
/** 受控端端口 */
|
|
||||||
PLAYER_PORT,
|
|
||||||
|
|
||||||
/** 控制端 IP */
|
|
||||||
CONTROLLER_IP,
|
|
||||||
|
|
||||||
/** 控制端端口 */
|
|
||||||
CONTROLLER_PORT,
|
|
||||||
|
|
||||||
/** 控制端入口地址 */
|
|
||||||
CONTROLLER_URI,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 14:49
|
|
||||||
*/
|
|
||||||
public enum Journal {
|
|
||||||
|
|
||||||
/** 启用服务 */
|
|
||||||
ENABLE,
|
|
||||||
|
|
||||||
/** 审核中 */
|
|
||||||
REVIEWING,
|
|
||||||
|
|
||||||
/** 访问密钥 */
|
|
||||||
KEY,
|
|
||||||
|
|
||||||
/** 微信小程序 AppId */
|
|
||||||
APP_ID,
|
|
||||||
|
|
||||||
/** 微信小程序 AppSecret */
|
|
||||||
APP_SECRET,
|
|
||||||
|
|
||||||
/** 备忘录内容 */
|
|
||||||
MEMO,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 14:47
|
|
||||||
*/
|
|
||||||
public enum TempFile {
|
|
||||||
|
|
||||||
/** 启用服务 */
|
|
||||||
ENABLE,
|
|
||||||
|
|
||||||
/** 最小缓存时长 */
|
|
||||||
TTL_MIN,
|
|
||||||
|
|
||||||
/** 默认缓存时长 */
|
|
||||||
TTL_DEFAULT,
|
|
||||||
|
|
||||||
/** 最大缓存时长 */
|
|
||||||
TTL_MAX,
|
|
||||||
|
|
||||||
/** 已过期文件残留时长 */
|
|
||||||
RESIDUE_TTL,
|
|
||||||
|
|
||||||
/** 每个 IP 限制有效临时文件容量 */
|
|
||||||
LIMIT_SIZE_OF_IP
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-27 14:35
|
|
||||||
*/
|
|
||||||
public enum FileSync {
|
|
||||||
|
|
||||||
ENABLE,
|
|
||||||
|
|
||||||
CRON,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 14:23
|
|
||||||
*/
|
|
||||||
public enum System {
|
|
||||||
|
|
||||||
/** 文件系统基准路径 */
|
|
||||||
FILE_BASE_PATH,
|
|
||||||
|
|
||||||
/** 设置缓存时长 */
|
|
||||||
SETTING_TTL,
|
|
||||||
|
|
||||||
/** 哀悼滤镜 */
|
|
||||||
ENABLE_MOURN_FILTER,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-04-24 14:23
|
|
||||||
*/
|
|
||||||
public enum SystemStatus {
|
|
||||||
|
|
||||||
/** 状态采集数据量 */
|
|
||||||
LIMIT,
|
|
||||||
|
|
||||||
/** 状态采集网卡 */
|
|
||||||
NETWORK_MAC,
|
|
||||||
|
|
||||||
/** 状态采集频率 */
|
|
||||||
RATE,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,28 +34,10 @@ public interface AttachmentMapper extends BaseMapper<Attachment, String>, RawMap
|
|||||||
|
|
||||||
List<Attachment> selectAllByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, List<String> attachTypes);
|
List<Attachment> selectAllByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, List<String> attachTypes);
|
||||||
|
|
||||||
|
List<Attachment> selectImageByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String attachType);
|
||||||
|
|
||||||
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
||||||
|
|
||||||
/**
|
|
||||||
* 按源附件 ID 与请求尺寸查询已缓存缩略图
|
|
||||||
*
|
|
||||||
* @param bizType 源附件业务类型
|
|
||||||
* @param sourceId 源附件 ID
|
|
||||||
* @param requestWidth 请求宽度,{@code null} 表示未指定
|
|
||||||
* @param requestHeight 请求高度,{@code null} 表示未指定
|
|
||||||
* @return 缩略图附件,不存在返回 {@code null}
|
|
||||||
*/
|
|
||||||
Attachment selectThumb(Attachment.BizType bizType, String sourceId, Integer requestWidth, Integer requestHeight);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询源附件的所有未销毁缩略图(含已软删除)
|
|
||||||
*
|
|
||||||
* @param sourceId 源附件 ID
|
|
||||||
* @return 缩略图列表
|
|
||||||
*/
|
|
||||||
@Select("SELECT * FROM attachment WHERE biz_id = #{sourceId} AND attach_type = 'THUMB' AND is_destroyed = FALSE")
|
|
||||||
List<Attachment> selectThumbsBySourceId(String sourceId);
|
|
||||||
|
|
||||||
@Select("SELECT * FROM attachment WHERE `is_destroyed` = FALSE AND `destroy_at` < " + UNIX_TIME)
|
@Select("SELECT * FROM attachment WHERE `is_destroyed` = FALSE AND `destroy_at` < " + UNIX_TIME)
|
||||||
List<Attachment> selectNeedDestroy();
|
List<Attachment> selectNeedDestroy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.imyeyu.api.modules.common.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.entity.AttachmentVariant;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 附件缩略图变体 Mapper
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
public interface AttachmentVariantMapper {
|
||||||
|
|
||||||
|
/// 查询有效缩略图附件
|
||||||
|
///
|
||||||
|
/// @param sourceAttachmentId 源附件 ID
|
||||||
|
/// @param sourceMongoId 源 GridFS ID
|
||||||
|
/// @param requestWidth 请求宽度,0 表示未指定
|
||||||
|
/// @param requestHeight 请求高度,0 表示未指定
|
||||||
|
/// @param fitMode 缩放模式
|
||||||
|
/// @param outputFormat 输出格式
|
||||||
|
/// @param algorithmVersion 算法版本
|
||||||
|
/// @param now 当前时间
|
||||||
|
/// @return 缩略图附件
|
||||||
|
Attachment selectValidAttachment(
|
||||||
|
@Param("sourceAttachmentId") String sourceAttachmentId,
|
||||||
|
@Param("sourceMongoId") String sourceMongoId,
|
||||||
|
@Param("requestWidth") int requestWidth,
|
||||||
|
@Param("requestHeight") int requestHeight,
|
||||||
|
@Param("fitMode") String fitMode,
|
||||||
|
@Param("outputFormat") String outputFormat,
|
||||||
|
@Param("algorithmVersion") String algorithmVersion,
|
||||||
|
@Param("now") long now
|
||||||
|
);
|
||||||
|
|
||||||
|
/// 查询指定变体记录,不判断是否过期
|
||||||
|
///
|
||||||
|
/// @param sourceAttachmentId 源附件 ID
|
||||||
|
/// @param sourceMongoId 源 GridFS ID
|
||||||
|
/// @param requestWidth 请求宽度,0 表示未指定
|
||||||
|
/// @param requestHeight 请求高度,0 表示未指定
|
||||||
|
/// @param fitMode 缩放模式
|
||||||
|
/// @param outputFormat 输出格式
|
||||||
|
/// @param algorithmVersion 算法版本
|
||||||
|
/// @return 变体记录
|
||||||
|
AttachmentVariant selectByKey(
|
||||||
|
@Param("sourceAttachmentId") String sourceAttachmentId,
|
||||||
|
@Param("sourceMongoId") String sourceMongoId,
|
||||||
|
@Param("requestWidth") int requestWidth,
|
||||||
|
@Param("requestHeight") int requestHeight,
|
||||||
|
@Param("fitMode") String fitMode,
|
||||||
|
@Param("outputFormat") String outputFormat,
|
||||||
|
@Param("algorithmVersion") String algorithmVersion
|
||||||
|
);
|
||||||
|
|
||||||
|
/// 查询源附件的所有变体
|
||||||
|
///
|
||||||
|
/// @param sourceAttachmentId 源附件 ID
|
||||||
|
/// @return 变体列表
|
||||||
|
List<AttachmentVariant> selectBySourceAttachmentId(@Param("sourceAttachmentId") String sourceAttachmentId);
|
||||||
|
|
||||||
|
/// 查询已过期变体
|
||||||
|
///
|
||||||
|
/// @param now 当前时间
|
||||||
|
/// @return 已过期变体列表
|
||||||
|
List<AttachmentVariant> selectExpired(@Param("now") long now);
|
||||||
|
|
||||||
|
/// 新增变体
|
||||||
|
///
|
||||||
|
/// @param variant 变体
|
||||||
|
void insert(AttachmentVariant variant);
|
||||||
|
|
||||||
|
/// 延长缩略图变体的过期时间
|
||||||
|
///
|
||||||
|
/// @param id 变体 ID
|
||||||
|
/// @param now 当前时间
|
||||||
|
/// @param expireAt 新的过期时间
|
||||||
|
/// @return 更新记录数
|
||||||
|
int updateExpireAt(@Param("id") String id, @Param("now") long now, @Param("expireAt") long expireAt);
|
||||||
|
|
||||||
|
/// 删除变体
|
||||||
|
///
|
||||||
|
/// @param id 变体 ID
|
||||||
|
void delete(@Param("id") String id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.imyeyu.api.modules.common.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/// Groovy 脚本 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
public interface GroovyScriptMapper extends BaseMapper<GroovyScript, String> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.imyeyu.api.modules.common.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScriptVersion;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
/// Groovy 脚本版本 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
public interface GroovyScriptVersionMapper extends BaseMapper<GroovyScriptVersion, String> {
|
||||||
|
|
||||||
|
@Select("SELECT * FROM `groovy_script_version` WHERE `script_id` = #{scriptId} " + NOT_DELETE + " ORDER BY `version` DESC " + LIMIT_1)
|
||||||
|
GroovyScriptVersion selectLatest(String scriptId);
|
||||||
|
}
|
||||||
@@ -16,35 +16,37 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface NotifyDetailMapper extends BaseMapper<NotifyDetail, String> {
|
public interface NotifyDetailMapper extends BaseMapper<NotifyDetail, String> {
|
||||||
|
|
||||||
|
String NOT_HIDDEN = " AND `hidden_at` IS NULL";
|
||||||
|
|
||||||
/** 查询用户的站内通知 */
|
/** 查询用户的站内通知 */
|
||||||
@Select("SELECT * FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} " + NOT_DELETE + " ORDER BY `created_at` DESC LIMIT #{offset}, #{limit}")
|
@Select("SELECT * FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + NOT_HIDDEN + NOT_DELETE + " ORDER BY `created_at` DESC LIMIT #{offset}, #{limit}")
|
||||||
List<NotifyDetail> selectSiteByUserId(@Param("userId") String userId, @Param("offset") long offset, @Param("limit") long limit);
|
List<NotifyDetail> selectSiteByUserId(@Param("userId") String userId, @Param("offset") long offset, @Param("limit") long limit);
|
||||||
|
|
||||||
/** 查询用户的未读站内通知 */
|
/** 查询用户的未读站内通知 */
|
||||||
@Select("SELECT * FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `read_at` IS NULL " + NOT_DELETE + " ORDER BY `created_at` DESC LIMIT #{offset}, #{limit}")
|
@Select("SELECT * FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + " AND `read_at` IS NULL " + NOT_HIDDEN + NOT_DELETE + " ORDER BY `created_at` DESC LIMIT #{offset}, #{limit}")
|
||||||
List<NotifyDetail> selectUnreadSiteByUserId(@Param("userId") String userId, @Param("offset") long offset, @Param("limit") long limit);
|
List<NotifyDetail> selectUnreadSiteByUserId(@Param("userId") String userId, @Param("offset") long offset, @Param("limit") long limit);
|
||||||
|
|
||||||
/** 统计用户的站内通知数量 */
|
/** 统计用户的站内通知数量 */
|
||||||
@Select("SELECT COUNT(*) FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} " + NOT_DELETE)
|
@Select("SELECT COUNT(*) FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + NOT_HIDDEN + NOT_DELETE)
|
||||||
long countSiteByUserId(@Param("userId") String userId);
|
long countSiteByUserId(@Param("userId") String userId);
|
||||||
|
|
||||||
/** 统计用户的未读站内通知数量 */
|
/** 统计用户的未读站内通知数量 */
|
||||||
@Select("SELECT COUNT(*) FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `read_at` IS NULL " + NOT_DELETE)
|
@Select("SELECT COUNT(*) FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + " AND `read_at` IS NULL " + NOT_HIDDEN + NOT_DELETE)
|
||||||
long countUnreadSiteByUserId(@Param("userId") String userId);
|
long countUnreadSiteByUserId(@Param("userId") String userId);
|
||||||
|
|
||||||
/** 查询用户拥有的站内通知 */
|
/** 查询用户拥有的站内通知 */
|
||||||
@Select("SELECT * FROM `notify_detail` WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} " + NOT_DELETE + " LIMIT 1")
|
@Select("SELECT * FROM `notify_detail` WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + NOT_HIDDEN + NOT_DELETE + " LIMIT 1")
|
||||||
NotifyDetail selectSiteByIdAndUserId(@Param("detailId") String detailId, @Param("userId") String userId);
|
NotifyDetail selectSiteByIdAndUserId(@Param("detailId") String detailId, @Param("userId") String userId);
|
||||||
|
|
||||||
/** 删除用户的站内通知 */
|
/** 隐藏用户的站内通知 */
|
||||||
@Update("UPDATE `notify_detail` SET `deleted_at` = " + UNIX_TIME + ", `updated_at` = " + UNIX_TIME + " WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} " + NOT_DELETE)
|
@Update("UPDATE `notify_detail` SET `hidden_at` = " + UNIX_TIME + ", `updated_at` = " + UNIX_TIME + " WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + NOT_HIDDEN + NOT_DELETE)
|
||||||
int deleteSiteByIdAndUserId(@Param("detailId") String detailId, @Param("userId") String userId);
|
int hideSiteByIdAndUserId(@Param("detailId") String detailId, @Param("userId") String userId);
|
||||||
|
|
||||||
/** 标记站内通知已读 */
|
/** 标记站内通知已读 */
|
||||||
@Update("UPDATE `notify_detail` SET `read_at` = #{readAt}, `updated_at` = " + UNIX_TIME + " WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `read_at` IS NULL " + NOT_DELETE)
|
@Update("UPDATE `notify_detail` SET `read_at` = #{readAt}, `updated_at` = " + UNIX_TIME + " WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + " AND `read_at` IS NULL " + NOT_HIDDEN + NOT_DELETE)
|
||||||
int markSiteRead(@Param("detailId") String detailId, @Param("userId") String userId, @Param("readAt") long readAt);
|
int markSiteRead(@Param("detailId") String detailId, @Param("userId") String userId, @Param("readAt") long readAt);
|
||||||
|
|
||||||
/** 标记用户全部站内通知已读 */
|
/** 标记用户全部站内通知已读 */
|
||||||
@Update("UPDATE `notify_detail` SET `read_at` = #{readAt}, `updated_at` = " + UNIX_TIME + " WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `read_at` IS NULL " + NOT_DELETE)
|
@Update("UPDATE `notify_detail` SET `read_at` = #{readAt}, `updated_at` = " + UNIX_TIME + " WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + " AND `read_at` IS NULL " + NOT_HIDDEN + NOT_DELETE)
|
||||||
int markAllSiteRead(@Param("userId") String userId, @Param("readAt") long readAt);
|
int markAllSiteRead(@Param("userId") String userId, @Param("readAt") long readAt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package com.imyeyu.api.modules.common.mapper;
|
package com.imyeyu.api.modules.common.mapper;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Notify;
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知 Mapper
|
* 通知 Mapper
|
||||||
@@ -10,4 +14,38 @@ import com.imyeyu.spring.mapper.BaseMapper;
|
|||||||
* @since 2026-05-13 14:46
|
* @since 2026-05-13 14:46
|
||||||
*/
|
*/
|
||||||
public interface NotifyMapper extends BaseMapper<Notify, String> {
|
public interface NotifyMapper extends BaseMapper<Notify, String> {
|
||||||
|
|
||||||
|
/// 原子创建业务提醒
|
||||||
|
int insertIfAbsent(Notify notify);
|
||||||
|
|
||||||
|
/// 按业务查重键查询未删除通知
|
||||||
|
///
|
||||||
|
/// @param bizType 业务类型
|
||||||
|
/// @param bizRemindedType 业务提醒类型
|
||||||
|
/// @param bizRemindedKey 业务提醒查重键
|
||||||
|
/// @return 通知
|
||||||
|
Notify selectByBusinessKey(@Param("bizType") String bizType,
|
||||||
|
@Param("bizRemindedType") String bizRemindedType,
|
||||||
|
@Param("bizRemindedKey") String bizRemindedKey);
|
||||||
|
|
||||||
|
/// 分页查询管理端通知
|
||||||
|
///
|
||||||
|
/// @param userId 管理员用户 ID
|
||||||
|
/// @param offset 分页偏移量
|
||||||
|
/// @param limit 分页大小
|
||||||
|
/// @return 通知列表
|
||||||
|
List<NotifyManagementItem> selectManagementPage(@Param("userId") String userId, @Param("offset") long offset, @Param("limit") long limit);
|
||||||
|
|
||||||
|
/// 统计管理端通知数量
|
||||||
|
///
|
||||||
|
/// @param userId 管理员用户 ID
|
||||||
|
/// @return 通知数量
|
||||||
|
long countManagement(@Param("userId") String userId);
|
||||||
|
|
||||||
|
/// 查询管理员可管理的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 管理员用户 ID
|
||||||
|
/// @return 通知
|
||||||
|
Notify selectManagement(@Param("notifyId") String notifyId, @Param("userId") String userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.imyeyu.api.modules.common.mapper;
|
|||||||
import com.imyeyu.api.modules.common.entity.Setting;
|
import com.imyeyu.api.modules.common.entity.Setting;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统配置
|
* 系统配置
|
||||||
*
|
*
|
||||||
@@ -10,4 +12,6 @@ import com.imyeyu.spring.mapper.BaseMapper;
|
|||||||
* @since 2021-07-20 22:26
|
* @since 2021-07-20 22:26
|
||||||
*/
|
*/
|
||||||
public interface SettingMapper extends BaseMapper<Setting, String> {
|
public interface SettingMapper extends BaseMapper<Setting, String> {
|
||||||
|
|
||||||
|
List<Setting> selectPublicByQuery(String bizType, String bizId, List<String> codeList);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.imyeyu.api.modules.common.service;
|
|||||||
import com.imyeyu.api.modules.common.entity.Article;
|
import com.imyeyu.api.modules.common.entity.Article;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章服务
|
* 文章服务
|
||||||
*
|
*
|
||||||
@@ -10,4 +12,10 @@ import com.imyeyu.spring.service.BaseService;
|
|||||||
* @since 2021-02-23 21:33
|
* @since 2021-02-23 21:33
|
||||||
*/
|
*/
|
||||||
public interface ArticleService extends BaseService<Article, String> {
|
public interface ArticleService extends BaseService<Article, String> {
|
||||||
|
|
||||||
|
/// 按示例查询文章
|
||||||
|
///
|
||||||
|
/// @param example 查询示例
|
||||||
|
/// @return 文章列表
|
||||||
|
List<Article> listByExample(Article example);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,18 +25,6 @@ public interface AttachmentService extends BaseService<Attachment, String> {
|
|||||||
/// @return 克隆后的附件
|
/// @return 克隆后的附件
|
||||||
Attachment clone(String id);
|
Attachment clone(String id);
|
||||||
|
|
||||||
/**
|
|
||||||
* 按需获取或创建缩略图附件。
|
|
||||||
* <p>当附件为图片或视频时,若指定尺寸的缩略图已存在则直接返回缓存,
|
|
||||||
* 否则生成并持久化后返回。不支持缩略图的附件类型返回 {@code null}。</p>
|
|
||||||
*
|
|
||||||
* @param source 源附件(必须已持久化,mimeType 已填充)
|
|
||||||
* @param requestWidth 请求宽度,{@code null} 表示未指定
|
|
||||||
* @param requestHeight 请求高度,{@code null} 表示未指定
|
|
||||||
* @return 缩略图附件,不支持时返回 {@code null}
|
|
||||||
*/
|
|
||||||
Attachment fetchThumb(Attachment source, Integer requestWidth, Integer requestHeight);
|
|
||||||
|
|
||||||
Attachment getByBizId(Attachment.BizType bizType, String bizId);
|
Attachment getByBizId(Attachment.BizType bizType, String bizId);
|
||||||
|
|
||||||
Attachment getByAttachType(Attachment.BizType bizType, String bizId, String attachType);
|
Attachment getByAttachType(Attachment.BizType bizType, String bizId, String attachType);
|
||||||
@@ -57,6 +45,12 @@ public interface AttachmentService extends BaseService<Attachment, String> {
|
|||||||
*/
|
*/
|
||||||
List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes);
|
List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes);
|
||||||
|
|
||||||
|
default Map<String, Attachment> mapFirstImageByIdList(Attachment.BizType bizType, Collection<String> bizIdList) {
|
||||||
|
return mapFirstImageByIdList(bizType, bizIdList, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Attachment> mapFirstImageByIdList(Attachment.BizType bizType, Collection<String> bizIdList, String attachType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据多个业务 ID 批量获取附件
|
* 根据多个业务 ID 批量获取附件
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.ThumbnailFitMode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
|
||||||
|
/// 附件缩略图变体服务
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
public interface AttachmentVariantService {
|
||||||
|
|
||||||
|
/// 按需获取或创建缩略图附件
|
||||||
|
///
|
||||||
|
/// @param source 源附件
|
||||||
|
/// @param requestWidth 请求宽度
|
||||||
|
/// @param requestHeight 请求高度
|
||||||
|
/// @param fitMode 缩放模式
|
||||||
|
/// @return 缩略图附件
|
||||||
|
Attachment fetchThumb(Attachment source, Integer requestWidth, Integer requestHeight, ThumbnailFitMode fitMode);
|
||||||
|
|
||||||
|
/// 删除源附件对应的全部缩略图变体
|
||||||
|
///
|
||||||
|
/// @param sourceAttachmentId 源附件 ID
|
||||||
|
void deleteBySourceId(String sourceAttachmentId);
|
||||||
|
|
||||||
|
/// 清理已过期的缩略图变体
|
||||||
|
void clearExpired();
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.bean.GroovyScriptExecutionResult;
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScriptVersion;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/// Groovy 脚本服务
|
||||||
|
///
|
||||||
|
/// 脚本仅限可信管理员维护,不能作为不可信用户代码的执行环境
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
public interface GroovyScriptService extends BaseService<GroovyScript, String> {
|
||||||
|
|
||||||
|
/// 按业务归属查询脚本列表
|
||||||
|
///
|
||||||
|
/// @param bizType 业务归属
|
||||||
|
/// @return 脚本列表
|
||||||
|
List<GroovyScript> listByBizType(GroovyScript.BizType bizType);
|
||||||
|
|
||||||
|
/// 按业务归属和代码查询脚本
|
||||||
|
///
|
||||||
|
/// @param bizType 业务归属
|
||||||
|
/// @param code 业务内唯一代码
|
||||||
|
/// @return 脚本,不存在时返回 null
|
||||||
|
GroovyScript getByCode(GroovyScript.BizType bizType, String code);
|
||||||
|
|
||||||
|
/// 设置脚本启用状态
|
||||||
|
///
|
||||||
|
/// @param id 脚本 ID
|
||||||
|
/// @param enabled true 为允许执行已发布版本
|
||||||
|
void setEnabled(String id, boolean enabled);
|
||||||
|
|
||||||
|
GroovyScriptVersion getLatestVersion(String scriptId);
|
||||||
|
|
||||||
|
/// 创建不可变的脚本版本
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
/// @param content 脚本内容
|
||||||
|
/// @return 新版本
|
||||||
|
GroovyScriptVersion createVersion(String scriptId, String content);
|
||||||
|
|
||||||
|
/// 查询脚本的全部版本
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
/// @return 按版本号升序的版本列表
|
||||||
|
List<GroovyScriptVersion> listVersion(String scriptId);
|
||||||
|
|
||||||
|
/// 发布指定版本
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
/// @param versionId 脚本版本 ID
|
||||||
|
void publish(String scriptId, String versionId);
|
||||||
|
|
||||||
|
/// 取消当前发布版本
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
void unpublish(String scriptId);
|
||||||
|
|
||||||
|
/// 执行已发布且启用的脚本
|
||||||
|
///
|
||||||
|
/// @param bizType 业务归属
|
||||||
|
/// @param code 业务内唯一代码
|
||||||
|
/// @param bindings 传给脚本的变量
|
||||||
|
/// @return 脚本返回值
|
||||||
|
Object execute(GroovyScript.BizType bizType, String code, Map<String, Object> bindings);
|
||||||
|
|
||||||
|
/// 执行已发布且启用的脚本并返回实际执行版本
|
||||||
|
///
|
||||||
|
/// @param bizType 业务归属
|
||||||
|
/// @param code 业务内唯一代码
|
||||||
|
/// @param bindings 传给脚本的变量
|
||||||
|
/// @param resultType 返回值类型
|
||||||
|
/// @param <T> 返回值类型
|
||||||
|
/// @return 脚本执行结果
|
||||||
|
<T> GroovyScriptExecutionResult<T> executePublished(GroovyScript.BizType bizType, String code, Map<String, Object> bindings, Class<T> resultType);
|
||||||
|
|
||||||
|
/// 按指定历史版本执行脚本
|
||||||
|
///
|
||||||
|
/// 用于按积分发生时的脚本版本复算,脚本当前是否发布或启用不影响执行;脚本返回 null 表示未命中,属合法结果
|
||||||
|
///
|
||||||
|
/// @param versionId 脚本版本 ID
|
||||||
|
/// @param bindings 传给脚本的变量
|
||||||
|
/// @param resultType 返回值类型
|
||||||
|
/// @param <T> 返回值类型
|
||||||
|
/// @return 脚本执行结果
|
||||||
|
<T> GroovyScriptExecutionResult<T> executeVersion(String versionId, Map<String, Object> bindings, Class<T> resultType);
|
||||||
|
|
||||||
|
/// 执行已发布且启用的脚本并验证返回值类型
|
||||||
|
///
|
||||||
|
/// @param bizType 业务归属
|
||||||
|
/// @param code 业务内唯一代码
|
||||||
|
/// @param bindings 传给脚本的变量
|
||||||
|
/// @param resultType 返回值类型
|
||||||
|
/// @param <T> 返回值类型
|
||||||
|
/// @return 脚本返回值
|
||||||
|
<T> T execute(GroovyScript.BizType bizType, String code, Map<String, Object> bindings, Class<T> resultType);
|
||||||
|
|
||||||
|
/// 清除脚本的本地编译缓存
|
||||||
|
///
|
||||||
|
/// 多实例部署时,其他节点在收到脚本变更通知后调用此方法
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
void invalidate(String scriptId);
|
||||||
|
}
|
||||||
@@ -26,6 +26,12 @@ public interface NotifyDetailService extends BaseService<NotifyDetail, String> {
|
|||||||
/// @param detailId 通知详情 ID
|
/// @param detailId 通知详情 ID
|
||||||
void requeue(String detailId);
|
void requeue(String detailId);
|
||||||
|
|
||||||
|
/// 取消尚未生效的通知详情
|
||||||
|
///
|
||||||
|
/// @param detailId 通知详情 ID
|
||||||
|
/// @param reason 取消原因
|
||||||
|
void cancelPending(String detailId, String reason);
|
||||||
|
|
||||||
/// 分页查询用户的站内通知
|
/// 分页查询用户的站内通知
|
||||||
///
|
///
|
||||||
/// @param page 分页参数
|
/// @param page 分页参数
|
||||||
@@ -41,11 +47,11 @@ public interface NotifyDetailService extends BaseService<NotifyDetail, String> {
|
|||||||
/// @return 通知详情
|
/// @return 通知详情
|
||||||
NotifyDetail getInternalByUserId(String detailId, String userId);
|
NotifyDetail getInternalByUserId(String detailId, String userId);
|
||||||
|
|
||||||
/// 删除当前用户拥有的站内通知详情
|
/// 隐藏当前用户拥有的站内通知详情
|
||||||
///
|
///
|
||||||
/// @param detailId 通知详情 ID
|
/// @param detailId 通知详情 ID
|
||||||
/// @param userId 用户 ID
|
/// @param userId 用户 ID
|
||||||
void deleteInternalByUserId(String detailId, String userId);
|
void hideInternalByUserId(String detailId, String userId);
|
||||||
|
|
||||||
/// 查询用户未读站内通知数量
|
/// 查询用户未读站内通知数量
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.imyeyu.api.modules.common.service;
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Notify;
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,6 +14,45 @@ import com.imyeyu.spring.service.BaseService;
|
|||||||
*/
|
*/
|
||||||
public interface NotifyService extends BaseService<Notify, String> {
|
public interface NotifyService extends BaseService<Notify, String> {
|
||||||
|
|
||||||
|
/// 原子创建业务提醒,重复查重键不会创建通知详情
|
||||||
|
///
|
||||||
|
/// @param notify 通知
|
||||||
|
void createIfAbsent(Notify notify);
|
||||||
|
|
||||||
|
/// 按业务查重键查询未删除通知
|
||||||
|
///
|
||||||
|
/// @param bizType 业务类型
|
||||||
|
/// @param bizRemindedType 业务提醒类型
|
||||||
|
/// @param bizRemindedKey 业务提醒查重键
|
||||||
|
/// @return 通知
|
||||||
|
Notify getByBusinessKey(String bizType, String bizRemindedType, String bizRemindedKey);
|
||||||
|
|
||||||
|
/// 分页查询当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 管理端通知列表
|
||||||
|
PageResult<NotifyManagementItem> pageManagement(Page<Notify> page, String userId);
|
||||||
|
|
||||||
|
/// 查询当前用户可管理的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 通知
|
||||||
|
Notify getManagement(String notifyId, String userId);
|
||||||
|
|
||||||
|
/// 删除当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
void deleteManagement(String notifyId, String userId);
|
||||||
|
|
||||||
|
/// 取消当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
void cancelManagement(String notifyId, String userId);
|
||||||
|
|
||||||
/// 取消通知中尚未成功发送的通知详情
|
/// 取消通知中尚未成功发送的通知详情
|
||||||
///
|
///
|
||||||
/// @param notifyId 通知 ID
|
/// @param notifyId 通知 ID
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package com.imyeyu.api.modules.common.service;
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.bean.SettingModule;
|
import com.imyeyu.api.bean.SettingEnum;
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.SettingSupport;
|
import com.imyeyu.api.modules.common.bean.attachment.SettingSupport;
|
||||||
import com.imyeyu.api.modules.common.entity.Setting;
|
import com.imyeyu.api.modules.common.entity.Setting;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置服务
|
* 配置服务
|
||||||
@@ -18,12 +19,22 @@ public interface SettingService extends BaseService<Setting, String> {
|
|||||||
|
|
||||||
Setting getByCode(String bizType, String bizId, String code);
|
Setting getByCode(String bizType, String bizId, String code);
|
||||||
|
|
||||||
default Setting getSystem(Enum<?> bizType) {
|
default Setting getSystem(SettingEnum setting) {
|
||||||
return getByCode(SettingModule.fromClass(bizType.getClass()).name(), TimiJava.ZERO_UUID, bizType.toString());
|
return getByCode(setting.getBizType(), TimiJava.ZERO_UUID, setting.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Setting> listByBizId(String bizType, String bizId);
|
List<Setting> listByBizId(String bizType, String bizId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询公开配置映射
|
||||||
|
*
|
||||||
|
* @param bizType 业务类型
|
||||||
|
* @param bizId 业务 ID,可为空
|
||||||
|
* @param code 配置代码列表,可为空
|
||||||
|
* @return 公开配置映射
|
||||||
|
*/
|
||||||
|
Map<String, Setting> mapPublic(String bizType, String bizId, List<String> code);
|
||||||
|
|
||||||
default List<Setting> listBySettingSupport(SettingSupport settingSupport) {
|
default List<Setting> listBySettingSupport(SettingSupport settingSupport) {
|
||||||
String bizType = settingSupport.getClass().getSimpleName().toUpperCase();
|
String bizType = settingSupport.getClass().getSimpleName().toUpperCase();
|
||||||
return listByBizId(bizType, settingSupport.getId());
|
return listByBizId(bizType, settingSupport.getId());
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2026-05-14 12:12
|
||||||
|
*/
|
||||||
|
public interface SmsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建短信验证码通知
|
||||||
|
*
|
||||||
|
* @param detail 通知
|
||||||
|
* @return 通知详情 ID
|
||||||
|
*/
|
||||||
|
String captchaCreate(Notify detail);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验短信验证码
|
||||||
|
*
|
||||||
|
* @param detailId 通知详情 ID
|
||||||
|
* @param captcha 请求验证码
|
||||||
|
* @return 通知详情
|
||||||
|
*/
|
||||||
|
NotifyDetail captchaVerify(String detailId, String captcha);
|
||||||
|
}
|
||||||
@@ -39,4 +39,10 @@ public interface TagService extends BaseService<Tag, String> {
|
|||||||
/// @param bizId 业务 ID
|
/// @param bizId 业务 ID
|
||||||
/// @param tagIdList 标签 ID 列表
|
/// @param tagIdList 标签 ID 列表
|
||||||
void apply(TagApply.BizType bizType, String bizId, List<String> tagIdList);
|
void apply(TagApply.BizType bizType, String bizId, List<String> tagIdList);
|
||||||
|
|
||||||
|
/// 删除指定归属下的全部标签
|
||||||
|
///
|
||||||
|
/// @param ownerType 归属类型
|
||||||
|
/// @param ownerId 归属 ID
|
||||||
|
void deleteByOwner(Tag.OwnerType ownerType, String ownerId);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -16,6 +16,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章服务实现
|
* 文章服务实现
|
||||||
*
|
*
|
||||||
@@ -37,6 +39,11 @@ public class ArticleServiceImplement extends AbstractEntityService<Article, Stri
|
|||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Article> listByExample(Article example) {
|
||||||
|
return mapper.selectAllByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create(Article article) {
|
public void create(Article article) {
|
||||||
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_ARTICLE_CREATE");
|
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_ARTICLE_CREATE");
|
||||||
|
|||||||
+33
-101
@@ -3,19 +3,14 @@ package com.imyeyu.api.modules.common.service.implement;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.MediaAttach;
|
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.Metadata;
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.mapper.AttachmentMapper;
|
import com.imyeyu.api.modules.common.mapper.AttachmentMapper;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.util.JavaCV;
|
import com.imyeyu.api.modules.common.service.AttachmentVariantService;
|
||||||
import com.imyeyu.io.IO;
|
import com.imyeyu.io.IO;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.CallbackArg;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.java.ref.Ref;
|
|
||||||
import com.imyeyu.network.Network;
|
|
||||||
import com.imyeyu.spring.TimiSpring;
|
import com.imyeyu.spring.TimiSpring;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
@@ -26,7 +21,6 @@ import com.mongodb.client.gridfs.GridFSBucket;
|
|||||||
import com.mongodb.client.gridfs.model.GridFSFile;
|
import com.mongodb.client.gridfs.model.GridFSFile;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.coobird.thumbnailator.Thumbnails;
|
|
||||||
import org.apache.tika.Tika;
|
import org.apache.tika.Tika;
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
@@ -36,18 +30,16 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,6 +56,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
private final ObjectMapper jackson;
|
private final ObjectMapper jackson;
|
||||||
private final GridFSBucket gridFSBucket;
|
private final GridFSBucket gridFSBucket;
|
||||||
private final GridFsTemplate gridFsTemplate;
|
private final GridFsTemplate gridFsTemplate;
|
||||||
|
private final AttachmentVariantService variantService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<Attachment, String> mapper() {
|
protected BaseMapper<Attachment, String> mapper() {
|
||||||
@@ -124,6 +117,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
}
|
}
|
||||||
// 有新文件时,先查旧记录获取旧 mongoId 和兜底字段
|
// 有新文件时,先查旧记录获取旧 mongoId 和兜底字段
|
||||||
Attachment old = mapper.selectRaw(attachment.getId());
|
Attachment old = mapper.selectRaw(attachment.getId());
|
||||||
|
TimiException.required(old, "not found attachment");
|
||||||
// 存储新文件
|
// 存储新文件
|
||||||
newMongoId = gridFsTemplate.store(stream, attachment.buildMongoName()).toString();
|
newMongoId = gridFsTemplate.store(stream, attachment.buildMongoName()).toString();
|
||||||
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(newMongoId)));
|
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(newMongoId)));
|
||||||
@@ -141,6 +135,8 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
|
|
||||||
// 更新数据库后删除旧 GridFS 文件
|
// 更新数据库后删除旧 GridFS 文件
|
||||||
super.update(attachment);
|
super.update(attachment);
|
||||||
|
// 源文件版本已变化,旧缩略图全部失效
|
||||||
|
variantService.deleteBySourceId(attachment.getId());
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(old.getMongoId())));
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(old.getMongoId())));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 新文件已上传但后续操作失败,清理新文件防止孤儿数据
|
// 新文件已上传但后续操作失败,清理新文件防止孤儿数据
|
||||||
@@ -155,36 +151,18 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void delete(String id) {
|
public void delete(String id) {
|
||||||
mapper.selectThumbsBySourceId(id).forEach(thumb -> super.delete(thumb.getId()));
|
variantService.deleteBySourceId(id);
|
||||||
super.delete(id);
|
super.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void destroy(String id) {
|
public void destroy(String id) {
|
||||||
CallbackArg<Attachment> doDestroy = attach -> {
|
variantService.deleteBySourceId(id);
|
||||||
try {
|
Attachment attachment = mapper.selectRaw(id);
|
||||||
if (attach.getMongoId() != null) {
|
if (attachment != null) {
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(attach.getMongoId())));
|
destroyAttachment(attachment);
|
||||||
}
|
}
|
||||||
if (!attach.isDeleted()) {
|
|
||||||
attach.setDeletedAt(Time.now());
|
|
||||||
}
|
|
||||||
attach.setIsDestroyed(true);
|
|
||||||
attach.setDestroyAt(Time.now());
|
|
||||||
mapper.update(attach);
|
|
||||||
|
|
||||||
if (Ref.toType(MediaAttach.Type.class, attach.getAttachType()) == MediaAttach.Type.THUMB) {
|
|
||||||
// 缩略图记录物理删除
|
|
||||||
mapper.destroy(attach.getId());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("delete mongo file error, id={}", attach.getId(), e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "TODO delete mongo file error");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mapper.selectThumbsBySourceId(id).forEach(doDestroy::handler);
|
|
||||||
doDestroy.handler(mapper.selectRaw(id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@@ -206,6 +184,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
try (InputStream inputStream = getInputStreamByMongoId(source.getMongoId())) {
|
try (InputStream inputStream = getInputStreamByMongoId(source.getMongoId())) {
|
||||||
target.setInputStream(inputStream);
|
target.setInputStream(inputStream);
|
||||||
create(target);
|
create(target);
|
||||||
|
target.setInputStream(null);
|
||||||
return target;
|
return target;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (target.getMongoId() != null) {
|
if (target.getMongoId() != null) {
|
||||||
@@ -216,74 +195,20 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
private void destroyAttachment(Attachment attachment) {
|
||||||
@Override
|
|
||||||
public Attachment fetchThumb(Attachment source, Integer requestWidth, Integer requestHeight) {
|
|
||||||
TimiException.requiredTrue(requestWidth != null || requestHeight != null, "required width or height");
|
|
||||||
String mimeType = source.getMimeType();
|
|
||||||
boolean isImage = mimeType != null && Set.of("image/png", "image/bmp", "image/jpeg").contains(mimeType);
|
|
||||||
boolean isVideo = mimeType != null && Set.of("video/mp4", "video/quicktime").contains(mimeType);
|
|
||||||
if (!isImage && !isVideo) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Attachment cached = mapper.selectThumb(source.getBizType(), source.getId(), requestWidth, requestHeight);
|
|
||||||
if (cached != null) {
|
|
||||||
// 命中缓存直接返回
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream thumbStream = new ByteArrayOutputStream();
|
if (attachment.getMongoId() != null) {
|
||||||
CallbackArg<InputStream> applyThumbSize = inputStream -> {
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(attachment.getMongoId())));
|
||||||
try {
|
|
||||||
Thumbnails.Builder<? extends InputStream> builder = Thumbnails.of(inputStream);
|
|
||||||
if (requestWidth != null && requestHeight != null) {
|
|
||||||
builder.size(requestWidth, requestHeight).keepAspectRatio(false).toOutputStream(thumbStream);
|
|
||||||
} else if (requestWidth != null) {
|
|
||||||
builder.width(requestWidth).keepAspectRatio(true).toOutputStream(thumbStream);
|
|
||||||
} else {
|
|
||||||
builder.height(requestHeight).keepAspectRatio(true).toOutputStream(thumbStream);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("applyThumbSize error for fetchThumb", e);
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (isImage) {
|
|
||||||
applyThumbSize.handler(source.openInputStream());
|
|
||||||
} else {
|
|
||||||
String name = source.getName();
|
|
||||||
File tempFile = IO.file("temp/%s_%s".formatted(UUID.randomUUID(), name));
|
|
||||||
try {
|
|
||||||
IO.toFile(tempFile, source.openInputStream());
|
|
||||||
ByteArrayOutputStream baos = JavaCV.captureThumbnail(IO.getInputStream(tempFile), 2);
|
|
||||||
applyThumbSize.handler(IO.toInputStream(baos));
|
|
||||||
} finally {
|
|
||||||
IO.destroy(tempFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Metadata.ThumbImage thumbMeta = new Metadata.ThumbImage();
|
if (!attachment.isDeleted()) {
|
||||||
thumbMeta.setSourceId(source.getId());
|
attachment.setDeletedAt(Time.now());
|
||||||
thumbMeta.setSourceMongoId(source.getMongoId());
|
}
|
||||||
thumbMeta.setSourceMimeType(mimeType);
|
attachment.setIsDestroyed(true);
|
||||||
thumbMeta.setRequestWidth(requestWidth);
|
attachment.setDestroyAt(Time.now());
|
||||||
thumbMeta.setRequestHeight(requestHeight);
|
mapper.update(attachment);
|
||||||
|
|
||||||
Attachment thumb = new Attachment();
|
|
||||||
thumb.setName(Network.simpleURIFileName(source.getName()) + ".png");
|
|
||||||
thumb.setBizType(source.getBizType());
|
|
||||||
thumb.setBizId(source.getId());
|
|
||||||
thumb.setAttachType(MediaAttach.Type.THUMB.toString());
|
|
||||||
thumb.setMetadata(jackson.valueToTree(thumbMeta));
|
|
||||||
thumb.setInputStream(new ByteArrayInputStream(thumbStream.toByteArray()));
|
|
||||||
// 缩略图 7 天后过期,额外 1 天宽限供后台任务销毁
|
|
||||||
long expireAt = Time.now() + 7 * Time.D;
|
|
||||||
thumb.setDeletedAt(expireAt);
|
|
||||||
thumb.setDestroyAt(expireAt + Time.D);
|
|
||||||
create(thumb);
|
|
||||||
return thumb;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("create thumbnail error", e);
|
log.error("delete mongo file error, id={}", attachment.getId(), e);
|
||||||
throw new TimiException(TimiCode.ERROR, "exception.attachment.create.error");
|
throw new TimiException(TimiCode.ERROR, "TODO delete mongo file error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,9 +247,14 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
return mapper.selectAllByBizIdList(bizType, List.of(bizId), List.of(attachTypes));
|
return mapper.selectAllByBizIdList(bizType, List.of(bizId), List.of(attachTypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Attachment> mapFirstImageByIdList(Attachment.BizType bizType, Collection<String> bizIdList, String attachType) {
|
||||||
|
return mapper.selectImageByBizIdList(bizType, new HashSet<>(bizIdList), attachType).stream().collect(Collectors.toMap(Attachment::getBizId, Function.identity()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String... attachTypes) {
|
public Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String... attachTypes) {
|
||||||
return mapper.selectAllByBizIdList(bizType, bizIdList, List.of(attachTypes)).stream().collect(Collectors.groupingBy(Attachment::getBizId));
|
return mapper.selectAllByBizIdList(bizType, new HashSet<>(bizIdList), List.of(attachTypes)).stream().collect(Collectors.groupingBy(Attachment::getBizId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -390,6 +320,8 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
// 将临时文件的 GridFS 存储转移至当前永久记录,废弃临时记录
|
// 将临时文件的 GridFS 存储转移至当前永久记录,废弃临时记录
|
||||||
Attachment current = mapper.selectRaw(item.getId());
|
Attachment current = mapper.selectRaw(item.getId());
|
||||||
Attachment tempFile = mapper.selectRaw(tempFileId);
|
Attachment tempFile = mapper.selectRaw(tempFileId);
|
||||||
|
// 源文件版本已变化,旧缩略图全部失效
|
||||||
|
variantService.deleteBySourceId(current.getId());
|
||||||
// 删除旧 GridFS 文件
|
// 删除旧 GridFS 文件
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(current.getMongoId())));
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(current.getMongoId())));
|
||||||
// 将存储信息从临时记录迁移到永久记录
|
// 将存储信息从临时记录迁移到永久记录
|
||||||
|
|||||||
+377
@@ -0,0 +1,377 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.MediaAttach;
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.ThumbnailFitMode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.entity.AttachmentVariant;
|
||||||
|
import com.imyeyu.api.modules.common.mapper.AttachmentVariantMapper;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentVariantService;
|
||||||
|
import com.imyeyu.api.util.JavaCV;
|
||||||
|
import com.imyeyu.io.IO;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.network.Network;
|
||||||
|
import com.imyeyu.spring.util.Redis;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import com.mongodb.client.gridfs.GridFSBucket;
|
||||||
|
import com.mongodb.client.gridfs.model.GridFSFile;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.coobird.thumbnailator.Thumbnails;
|
||||||
|
import net.coobird.thumbnailator.geometry.Positions;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/// 附件缩略图变体服务实现
|
||||||
|
///
|
||||||
|
/// 负责缩略图生成、变体缓存、并发控制和变体文件清理,源附件生命周期由 `AttachmentService` 负责
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AttachmentVariantServiceImplement implements AttachmentVariantService {
|
||||||
|
|
||||||
|
private static final int THUMB_MAX_WIDTH = 4096;
|
||||||
|
private static final int THUMB_MAX_HEIGHT = 4096;
|
||||||
|
private static final long THUMB_MAX_PIXELS = 16_000_000L;
|
||||||
|
private static final long THUMB_CACHE_TTL = Time.D * 7;
|
||||||
|
private static final long THUMB_LOCK_TTL = Time.M;
|
||||||
|
private static final double THUMB_TARGET_SECONDS = 2;
|
||||||
|
private static final int VARIANT_NAME_MAX_LENGTH = 255;
|
||||||
|
private static final String THUMB_OUTPUT_FORMAT = "png";
|
||||||
|
private static final String THUMB_ALGORITHM_VERSION = "v3";
|
||||||
|
private static final String THUMB_LOCK_KEY_PREFIX = "ATTACHMENT:THUMB:LOCK:";
|
||||||
|
|
||||||
|
private final AttachmentVariantMapper variantMapper;
|
||||||
|
private final ObjectMapper jackson;
|
||||||
|
private final GridFSBucket gridFSBucket;
|
||||||
|
private final GridFsTemplate gridFsTemplate;
|
||||||
|
|
||||||
|
@Qualifier("redisLocker")
|
||||||
|
private final Redis<String, Integer> redisLocker;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Attachment fetchThumb(Attachment source, Integer requestWidth, Integer requestHeight, ThumbnailFitMode fitMode) {
|
||||||
|
TimiException.required(source, "not found source attachment");
|
||||||
|
TimiException.required(source.getId(), "not found source attachment.id");
|
||||||
|
TimiException.required(source.getMongoId(), "not found source attachment.mongoId");
|
||||||
|
TimiException.requiredTrue(requestWidth != null || requestHeight != null, "required width or height");
|
||||||
|
if (requestWidth != null && !(0 < requestWidth && requestWidth < THUMB_MAX_WIDTH + 1)) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "attachment.thumbnail.width.invalid");
|
||||||
|
}
|
||||||
|
if (requestHeight != null && !(0 < requestHeight && requestHeight < THUMB_MAX_HEIGHT + 1)) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "attachment.thumbnail.height.invalid");
|
||||||
|
}
|
||||||
|
if (requestWidth != null && requestHeight != null) {
|
||||||
|
long pixels = (long) requestWidth * requestHeight;
|
||||||
|
if (THUMB_MAX_PIXELS < pixels) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "attachment.thumbnail.area.invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fitMode = TimiJava.defaultIfNull(fitMode, ThumbnailFitMode.FIT);
|
||||||
|
|
||||||
|
String mimeType = source.getMimeType();
|
||||||
|
boolean isImage = mimeType != null && Set.of("image/png", "image/bmp", "image/jpeg").contains(mimeType);
|
||||||
|
boolean isVideo = mimeType != null && Set.of("video/mp4", "video/quicktime").contains(mimeType);
|
||||||
|
if (!isImage && !isVideo) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "attachment.thumbnail.not.support");
|
||||||
|
}
|
||||||
|
|
||||||
|
int width = TimiJava.defaultIfNull(requestWidth, 0);
|
||||||
|
int height = TimiJava.defaultIfNull(requestHeight, 0);
|
||||||
|
long now = Time.now();
|
||||||
|
Attachment cached = variantMapper.selectValidAttachment(
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode.toString(),
|
||||||
|
THUMB_OUTPUT_FORMAT,
|
||||||
|
THUMB_ALGORITHM_VERSION,
|
||||||
|
now
|
||||||
|
);
|
||||||
|
if (cached != null) {
|
||||||
|
Attachment refreshed = refreshCachedThumb(cached);
|
||||||
|
if (refreshed != null) {
|
||||||
|
return refreshed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String lockKey = buildThumbLockKey(source, width, height, fitMode);
|
||||||
|
if (!redisLocker.lock(lockKey, 1, THUMB_LOCK_TTL)) {
|
||||||
|
throw new TimiException(TimiCode.ERROR_SERVICE_BUSY, "attachment.thumbnail.generating");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
cached = variantMapper.selectValidAttachment(
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode.toString(),
|
||||||
|
THUMB_OUTPUT_FORMAT,
|
||||||
|
THUMB_ALGORITHM_VERSION,
|
||||||
|
Time.now()
|
||||||
|
);
|
||||||
|
if (cached != null) {
|
||||||
|
Attachment refreshed = refreshCachedThumb(cached);
|
||||||
|
if (refreshed != null) {
|
||||||
|
return refreshed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AttachmentVariant oldVariant = variantMapper.selectByKey(
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode.toString(),
|
||||||
|
THUMB_OUTPUT_FORMAT,
|
||||||
|
THUMB_ALGORITHM_VERSION
|
||||||
|
);
|
||||||
|
if (oldVariant != null) {
|
||||||
|
deleteVariant(oldVariant);
|
||||||
|
}
|
||||||
|
File thumbFile = null;
|
||||||
|
AttachmentVariant variant = null;
|
||||||
|
boolean variantInserted = false;
|
||||||
|
try {
|
||||||
|
thumbFile = createThumbFile(source, requestWidth, requestHeight, fitMode, isImage);
|
||||||
|
variant = new AttachmentVariant();
|
||||||
|
variant.setId(UUID.randomUUID().toString());
|
||||||
|
variant.setName(buildVariantName(source.getName()));
|
||||||
|
variant.setMimeType("image/" + THUMB_OUTPUT_FORMAT);
|
||||||
|
long expireAt = Time.now() + THUMB_CACHE_TTL;
|
||||||
|
variant.setSourceAttachmentId(source.getId());
|
||||||
|
variant.setSourceMongoId(source.getMongoId());
|
||||||
|
variant.setSourceMd5(source.getMd5());
|
||||||
|
variant.setRequestWidth(width);
|
||||||
|
variant.setRequestHeight(height);
|
||||||
|
variant.setFitMode(fitMode);
|
||||||
|
variant.setOutputFormat(THUMB_OUTPUT_FORMAT);
|
||||||
|
variant.setAlgorithmVersion(THUMB_ALGORITHM_VERSION);
|
||||||
|
variant.setCreatedAt(Time.now());
|
||||||
|
variant.setExpireAt(expireAt);
|
||||||
|
BufferedImage image = ImageIO.read(thumbFile);
|
||||||
|
if (image != null) {
|
||||||
|
ObjectNode metadata = jackson.createObjectNode();
|
||||||
|
metadata.put("width", image.getWidth());
|
||||||
|
metadata.put("height", image.getHeight());
|
||||||
|
variant.setMetadata(metadata);
|
||||||
|
}
|
||||||
|
try (InputStream inputStream = Files.newInputStream(thumbFile.toPath())) {
|
||||||
|
String mongoId = gridFsTemplate.store(inputStream, variant.getName()).toString();
|
||||||
|
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(mongoId)));
|
||||||
|
variant.setMongoId(mongoId);
|
||||||
|
variant.setSize(gridFSFile.getLength());
|
||||||
|
try (InputStream md5InputStream = gridFSBucket.openDownloadStream(gridFSFile.getObjectId())) {
|
||||||
|
variant.setMd5(IO.md5(md5InputStream));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
variantMapper.insert(variant);
|
||||||
|
variantInserted = true;
|
||||||
|
} catch (DuplicateKeyException e) {
|
||||||
|
destroyVariantFile(variant);
|
||||||
|
Attachment concurrent = variantMapper.selectValidAttachment(
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode.toString(),
|
||||||
|
THUMB_OUTPUT_FORMAT,
|
||||||
|
THUMB_ALGORITHM_VERSION,
|
||||||
|
Time.now()
|
||||||
|
);
|
||||||
|
if (concurrent != null) {
|
||||||
|
Attachment refreshed = refreshCachedThumb(concurrent);
|
||||||
|
if (refreshed != null) {
|
||||||
|
return refreshed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return toThumbAttachment(source, variant);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (variant != null) {
|
||||||
|
destroyVariantFile(variant);
|
||||||
|
if (variantInserted) {
|
||||||
|
variantMapper.delete(variant.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
IO.destroy(thumbFile);
|
||||||
|
}
|
||||||
|
} catch (TimiException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("create thumbnail error", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "exception.attachment.create.error", e);
|
||||||
|
} finally {
|
||||||
|
redisLocker.releaseLock(lockKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 延长已命中缩略图缓存的有效期
|
||||||
|
///
|
||||||
|
/// @param cached 已命中的缩略图
|
||||||
|
/// @return 更新成功时返回刷新后的缩略图,记录已不存在或已过期时返回 `null`
|
||||||
|
private Attachment refreshCachedThumb(Attachment cached) {
|
||||||
|
long now = Time.now();
|
||||||
|
long expireAt = now + THUMB_CACHE_TTL;
|
||||||
|
if (!(0 < variantMapper.updateExpireAt(cached.getId(), now, expireAt))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
cached.setDestroyAt(expireAt);
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildThumbLockKey(Attachment source, int width, int height, ThumbnailFitMode fitMode) {
|
||||||
|
return "%s%s:%s:%s:%s:%s".formatted(
|
||||||
|
THUMB_LOCK_KEY_PREFIX,
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构建不超过数据库字段长度的变体名称
|
||||||
|
///
|
||||||
|
/// @param sourceName 源附件名称
|
||||||
|
/// @return 变体名称
|
||||||
|
private String buildVariantName(String sourceName) {
|
||||||
|
String suffix = "." + THUMB_OUTPUT_FORMAT;
|
||||||
|
String baseName = Network.simpleURIFileName(sourceName);
|
||||||
|
int maxBaseLength = VARIANT_NAME_MAX_LENGTH - suffix.length();
|
||||||
|
if (maxBaseLength < baseName.codePointCount(0, baseName.length())) {
|
||||||
|
baseName = baseName.substring(0, baseName.offsetByCodePoints(0, maxBaseLength));
|
||||||
|
}
|
||||||
|
return baseName + suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
private File createThumbFile(
|
||||||
|
Attachment source,
|
||||||
|
Integer requestWidth,
|
||||||
|
Integer requestHeight,
|
||||||
|
ThumbnailFitMode fitMode,
|
||||||
|
boolean isImage
|
||||||
|
) throws Exception {
|
||||||
|
File thumbFile = Files.createTempFile("timi-thumb-", ".png").toFile();
|
||||||
|
try {
|
||||||
|
if (isImage) {
|
||||||
|
try (InputStream inputStream = source.openInputStream()) {
|
||||||
|
resize(inputStream, thumbFile, requestWidth, requestHeight, fitMode);
|
||||||
|
}
|
||||||
|
return thumbFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (InputStream inputStream = source.openInputStream()) {
|
||||||
|
ByteArrayOutputStream frame = JavaCV.captureThumbnail(inputStream, THUMB_TARGET_SECONDS);
|
||||||
|
if (!(0 < frame.size())) {
|
||||||
|
throw new TimiException(TimiCode.ERROR_NOT_SUPPORT, "attachment.thumbnail.video.frame.empty");
|
||||||
|
}
|
||||||
|
try (InputStream frameInputStream = new ByteArrayInputStream(frame.toByteArray())) {
|
||||||
|
resize(frameInputStream, thumbFile, requestWidth, requestHeight, fitMode);
|
||||||
|
}
|
||||||
|
return thumbFile;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
IO.destroy(thumbFile);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resize(
|
||||||
|
InputStream inputStream,
|
||||||
|
File outputFile,
|
||||||
|
Integer requestWidth,
|
||||||
|
Integer requestHeight,
|
||||||
|
ThumbnailFitMode fitMode
|
||||||
|
) throws IOException {
|
||||||
|
Thumbnails.Builder<? extends InputStream> builder = Thumbnails.of(inputStream)
|
||||||
|
.useExifOrientation(true)
|
||||||
|
.outputFormat(THUMB_OUTPUT_FORMAT);
|
||||||
|
if (requestWidth != null && requestHeight != null) {
|
||||||
|
switch (fitMode) {
|
||||||
|
case FIT -> builder.size(requestWidth, requestHeight).keepAspectRatio(true);
|
||||||
|
case COVER -> builder.size(requestWidth, requestHeight).keepAspectRatio(true).crop(Positions.CENTER);
|
||||||
|
case STRETCH -> builder.size(requestWidth, requestHeight).keepAspectRatio(false);
|
||||||
|
}
|
||||||
|
} else if (requestWidth != null) {
|
||||||
|
builder.width(requestWidth).keepAspectRatio(true);
|
||||||
|
} else {
|
||||||
|
builder.height(requestHeight).keepAspectRatio(true);
|
||||||
|
}
|
||||||
|
builder.toFile(outputFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void deleteBySourceId(String sourceAttachmentId) {
|
||||||
|
for (AttachmentVariant variant : variantMapper.selectBySourceAttachmentId(sourceAttachmentId)) {
|
||||||
|
deleteVariant(variant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteVariant(AttachmentVariant variant) {
|
||||||
|
destroyVariantFile(variant);
|
||||||
|
variantMapper.delete(variant.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyVariantFile(AttachmentVariant variant) {
|
||||||
|
if (variant.getMongoId() != null) {
|
||||||
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(variant.getMongoId())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Attachment toThumbAttachment(Attachment source, AttachmentVariant variant) {
|
||||||
|
Attachment thumb = new Attachment();
|
||||||
|
thumb.setId(variant.getId());
|
||||||
|
thumb.setBizType(source.getBizType());
|
||||||
|
thumb.setBizId(source.getId());
|
||||||
|
thumb.setAttachType(MediaAttach.Type.THUMB.toString());
|
||||||
|
thumb.setMongoId(variant.getMongoId());
|
||||||
|
thumb.setName(variant.getName());
|
||||||
|
thumb.setMimeType(variant.getMimeType());
|
||||||
|
thumb.setMetadata(variant.getMetadata());
|
||||||
|
thumb.setSize(variant.getSize());
|
||||||
|
thumb.setMd5(variant.getMd5());
|
||||||
|
thumb.setIsDestroyed(false);
|
||||||
|
thumb.setDestroyAt(variant.getExpireAt());
|
||||||
|
return thumb;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearExpired() {
|
||||||
|
for (AttachmentVariant variant : variantMapper.selectExpired(Time.now())) {
|
||||||
|
try {
|
||||||
|
deleteVariant(variant);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("clear expired thumbnail variant error, id={}", variant.getId(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+299
@@ -0,0 +1,299 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.common.bean.GroovyScriptExecutionResult;
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScriptVersion;
|
||||||
|
import com.imyeyu.api.modules.common.mapper.GroovyScriptMapper;
|
||||||
|
import com.imyeyu.api.modules.common.mapper.GroovyScriptVersionMapper;
|
||||||
|
import com.imyeyu.api.modules.common.service.GroovyScriptService;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
|
import groovy.lang.Binding;
|
||||||
|
import groovy.lang.GroovyClassLoader;
|
||||||
|
import groovy.lang.Script;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.transaction.support.TransactionSynchronization;
|
||||||
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/// Groovy 脚本服务实现
|
||||||
|
///
|
||||||
|
/// 每个已编译版本使用独立类加载器,缓存失效后可释放对应类及其元数据
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GroovyScriptServiceImplement extends AbstractEntityService<GroovyScript, String> implements GroovyScriptService {
|
||||||
|
|
||||||
|
private final GroovyScriptMapper mapper;
|
||||||
|
private final GroovyScriptVersionMapper versionMapper;
|
||||||
|
private final Map<String, CompiledScript> compiledScriptMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseMapper<GroovyScript, String> mapper() {
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GroovyScript> listByBizType(GroovyScript.BizType bizType) {
|
||||||
|
TimiException.required(bizType, "未找到脚本业务归属");
|
||||||
|
GroovyScript example = new GroovyScript();
|
||||||
|
example.setBizType(bizType);
|
||||||
|
return mapper.selectAllByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GroovyScript getByCode(GroovyScript.BizType bizType, String code) {
|
||||||
|
GroovyScript example = new GroovyScript();
|
||||||
|
example.setBizType(bizType);
|
||||||
|
example.setCode(code);
|
||||||
|
return mapper.selectByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void create(GroovyScript script) {
|
||||||
|
TimiException.required(script, "未找到脚本");
|
||||||
|
TimiException.required(script.getBizType(), "未找到脚本业务归属");
|
||||||
|
TimiException.required(script.getCode(), "未找到脚本代码");
|
||||||
|
TimiException.required(script.getName(), "未找到脚本名称");
|
||||||
|
TimiException.requiredNull(getByCode(script.getBizType(), script.getCode()), "Groovy 脚本已存在");
|
||||||
|
script.setEnabled(false);
|
||||||
|
script.setPublishedVersionId(null);
|
||||||
|
super.create(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void update(GroovyScript script) {
|
||||||
|
TimiException.required(script, "未找到脚本");
|
||||||
|
TimiException.required(script.getId(), "未找到脚本 ID");
|
||||||
|
TimiException.required(script.getName(), "未找到脚本名称");
|
||||||
|
GroovyScript dbScript = get(script.getId());
|
||||||
|
TimiException.required(dbScript, "未找到脚本");
|
||||||
|
dbScript.setName(script.getName());
|
||||||
|
dbScript.setDescription(script.getDescription());
|
||||||
|
mapper.update(dbScript);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void setEnabled(String id, boolean enabled) {
|
||||||
|
GroovyScript script = requireScript(id);
|
||||||
|
script.setEnabled(enabled);
|
||||||
|
mapper.update(script);
|
||||||
|
invalidateAfterCommit(script.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GroovyScriptVersion getLatestVersion(String scriptId) {
|
||||||
|
return versionMapper.selectLatest(scriptId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public GroovyScriptVersion createVersion(String scriptId, String content) {
|
||||||
|
requireScript(scriptId);
|
||||||
|
TimiException.required(content, "未找到脚本内容");
|
||||||
|
TimiException.requiredTrue(!content.isBlank(), "脚本内容不能为空");
|
||||||
|
|
||||||
|
GroovyScriptVersion version = new GroovyScriptVersion();
|
||||||
|
version.setScriptId(scriptId);
|
||||||
|
version.setVersion(versionMapper.selectLatest(scriptId).getVersion() + 1);
|
||||||
|
version.setContent(content);
|
||||||
|
version.setChecksum(checksum(content));
|
||||||
|
versionMapper.insert(version);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GroovyScriptVersion> listVersion(String scriptId) {
|
||||||
|
TimiException.required(scriptId, "未找到脚本 ID");
|
||||||
|
GroovyScriptVersion example = new GroovyScriptVersion();
|
||||||
|
example.setScriptId(scriptId);
|
||||||
|
List<GroovyScriptVersion> versionList = new ArrayList<>(versionMapper.selectAllByExample(example));
|
||||||
|
versionList.sort(Comparator.comparing(GroovyScriptVersion::getVersion));
|
||||||
|
return versionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void publish(String scriptId, String versionId) {
|
||||||
|
GroovyScript script = requireScript(scriptId);
|
||||||
|
GroovyScriptVersion version = requireVersion(versionId);
|
||||||
|
TimiException.requiredTrue(script.getId().equals(version.getScriptId()), "脚本版本不属于当前脚本");
|
||||||
|
script.setPublishedVersionId(version.getId());
|
||||||
|
mapper.update(script);
|
||||||
|
invalidateAfterCommit(script.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void unpublish(String scriptId) {
|
||||||
|
GroovyScript script = requireScript(scriptId);
|
||||||
|
script.setPublishedVersionId(null);
|
||||||
|
mapper.update(script);
|
||||||
|
invalidateAfterCommit(script.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
requireScript(id);
|
||||||
|
super.delete(id);
|
||||||
|
invalidateAfterCommit(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object execute(GroovyScript.BizType bizType, String code, Map<String, Object> bindings) {
|
||||||
|
return executePublished(bizType, code, bindings, Object.class).result();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> GroovyScriptExecutionResult<T> executePublished(GroovyScript.BizType bizType, String code, Map<String, Object> bindings, Class<T> resultType) {
|
||||||
|
TimiException.required(bizType, "未找到脚本业务归属");
|
||||||
|
TimiException.required(code, "未找到脚本代码");
|
||||||
|
TimiException.required(resultType, "未找到返回值类型");
|
||||||
|
GroovyScript script = getByCode(bizType, code);
|
||||||
|
TimiException.required(script, "未找到 Groovy 脚本");
|
||||||
|
TimiException.requiredTrue(Boolean.TRUE.equals(script.getEnabled()), "Groovy 脚本已停用");
|
||||||
|
TimiException.required(script.getPublishedVersionId(), "Groovy 脚本尚未发布");
|
||||||
|
GroovyScriptExecutionResult<T> result = executeVersion(script.getPublishedVersionId(), bindings, resultType);
|
||||||
|
TimiException.requiredTrue(script.getId().equals(result.scriptId()), "Groovy 脚本已发布版本无效");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T execute(GroovyScript.BizType bizType, String code, Map<String, Object> bindings, Class<T> resultType) {
|
||||||
|
return executePublished(bizType, code, bindings, resultType).result();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> GroovyScriptExecutionResult<T> executeVersion(String versionId, Map<String, Object> bindings, Class<T> resultType) {
|
||||||
|
TimiException.required(resultType, "未找到返回值类型");
|
||||||
|
GroovyScriptVersion version = requireVersion(versionId);
|
||||||
|
CompiledScript compiledScript = compiledScriptMap.computeIfAbsent(cacheKey(version), key -> compile(version.getScriptId(), version));
|
||||||
|
try {
|
||||||
|
Object result = compiledScript.execute(bindings);
|
||||||
|
TimiException.requiredTrue(result == null || resultType.isInstance(result), "Groovy 脚本返回值类型不匹配");
|
||||||
|
return new GroovyScriptExecutionResult<>(version.getScriptId(), version.getId(), version.getVersion(), version.getChecksum(), resultType.cast(result));
|
||||||
|
} catch (TimiException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.warn("Groovy 脚本执行失败,scriptId={}, versionId={}", version.getScriptId(), version.getId(), e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "Groovy 脚本执行失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate(String scriptId) {
|
||||||
|
if (scriptId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
compiledScriptMap.entrySet().removeIf(entry -> {
|
||||||
|
if (!scriptId.equals(entry.getValue().scriptId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
entry.getValue().close();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private GroovyScript requireScript(String id) {
|
||||||
|
TimiException.required(id, "未找到脚本 ID");
|
||||||
|
GroovyScript script = get(id);
|
||||||
|
TimiException.required(script, "未找到脚本");
|
||||||
|
return script;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GroovyScriptVersion requireVersion(String id) {
|
||||||
|
TimiException.required(id, "未找到脚本版本 ID");
|
||||||
|
GroovyScriptVersion version = versionMapper.select(id);
|
||||||
|
TimiException.required(version, "未找到脚本版本");
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String cacheKey(GroovyScriptVersion version) {
|
||||||
|
return "%s:%s".formatted(version.getId(), version.getChecksum());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompiledScript compile(String scriptId, GroovyScriptVersion version) {
|
||||||
|
GroovyClassLoader classLoader = new GroovyClassLoader(getClass().getClassLoader());
|
||||||
|
try {
|
||||||
|
Class<?> type = classLoader.parseClass(version.getContent(), "GroovyScript_%s_%d.groovy".formatted(version.getId().replace('-', '_'), version.getVersion()));
|
||||||
|
return new CompiledScript(scriptId, type.asSubclass(Script.class), classLoader);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
close(classLoader);
|
||||||
|
log.warn("Groovy 脚本编译失败,scriptId={}, versionId={}", scriptId, version.getId(), e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "Groovy 脚本编译失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String checksum(String content) {
|
||||||
|
try {
|
||||||
|
return java.util.HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(content.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new IllegalStateException("JVM 缺少 SHA-256 算法", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void invalidateAfterCommit(String scriptId) {
|
||||||
|
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||||
|
invalidate(scriptId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterCommit() {
|
||||||
|
invalidate(scriptId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(GroovyClassLoader classLoader) {
|
||||||
|
try {
|
||||||
|
classLoader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("关闭 Groovy 脚本类加载器失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record CompiledScript(String scriptId, Class<? extends Script> type, GroovyClassLoader classLoader) {
|
||||||
|
|
||||||
|
private Object execute(Map<String, Object> bindings) {
|
||||||
|
try {
|
||||||
|
Script script = type.getDeclaredConstructor().newInstance();
|
||||||
|
script.setBinding(new Binding(bindings == null ? Map.of() : new HashMap<>(bindings)));
|
||||||
|
return script.run();
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
throw new IllegalStateException("Groovy 脚本实例化失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close() {
|
||||||
|
try {
|
||||||
|
classLoader.close();
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -60,7 +60,7 @@ public class MailQueueServiceImplement extends AbstractQueueService<MailQueue, N
|
|||||||
message.setFrom(queue.getSendFrom());
|
message.setFrom(queue.getSendFrom());
|
||||||
message.setTo(queue.getSendTo());
|
message.setTo(queue.getSendTo());
|
||||||
message.setSubject(queue.getSubject());
|
message.setSubject(queue.getSubject());
|
||||||
message.setText(queue.getData());
|
message.setText(queue.getContent());
|
||||||
mailSender.send(message);
|
mailSender.send(message);
|
||||||
log.info("邮件发送成功,目标:{}", queue.getSendTo());
|
log.info("邮件发送成功,目标:{}", queue.getSendTo());
|
||||||
}
|
}
|
||||||
|
|||||||
+87
-10
@@ -1,10 +1,12 @@
|
|||||||
package com.imyeyu.api.modules.common.service.implement;
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.entity.Notify;
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
import com.imyeyu.api.modules.common.mapper.NotifyDetailMapper;
|
import com.imyeyu.api.modules.common.mapper.NotifyDetailMapper;
|
||||||
import com.imyeyu.api.modules.common.mapper.NotifyMapper;
|
import com.imyeyu.api.modules.common.mapper.NotifyMapper;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
@@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知详情服务实现
|
* 通知详情服务实现
|
||||||
@@ -31,6 +34,7 @@ import java.util.List;
|
|||||||
public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDetail, String> implements NotifyDetailService {
|
public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDetail, String> implements NotifyDetailService {
|
||||||
|
|
||||||
private final NotifyMapper notifyMapper;
|
private final NotifyMapper notifyMapper;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
private final NotifyDetailMapper mapper;
|
private final NotifyDetailMapper mapper;
|
||||||
|
|
||||||
@@ -53,15 +57,22 @@ public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDe
|
|||||||
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL) {
|
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL) {
|
||||||
TimiException.required(detail.getSendTo(), "未找到站内通知接收用户 ID");
|
TimiException.required(detail.getSendTo(), "未找到站内通知接收用户 ID");
|
||||||
}
|
}
|
||||||
|
detail.setContentType(TimiJava.defaultIfNull(detail.getContentType(), detail.getMsgType() == NotifyDetail.MsgType.INTERNAL
|
||||||
|
? NotifyDetail.ContentType.TIP_TAP
|
||||||
|
: NotifyDetail.ContentType.TEXT));
|
||||||
|
|
||||||
detail.setRetry(TimiJava.defaultIfNull(detail.getRetry(), 1));
|
detail.setRetry(TimiJava.defaultIfNull(detail.getRetry(), 1));
|
||||||
detail.setSendAt(TimiJava.defaultIfNull(detail.getSendAt(), Time.now()));
|
detail.setSendAt(TimiJava.defaultIfNull(detail.getSendAt(), Time.now()));
|
||||||
detail.setTimeoutAt(TimiJava.defaultIfNull(detail.getTimeoutAt(), detail.getSendAt() + Time.D));
|
detail.setTimeoutAt(TimiJava.defaultIfNull(detail.getTimeoutAt(), detail.getSendAt() + Time.D));
|
||||||
detail.setStatus(detail.getMsgType() == NotifyDetail.MsgType.INTERNAL
|
boolean scheduled = Time.now() < detail.getSendAt();
|
||||||
? NotifyDetail.Status.REMINDED
|
detail.setStatus(detail.getMsgType() == NotifyDetail.MsgType.INTERNAL && !scheduled
|
||||||
: NotifyDetail.Status.WAITING);
|
? NotifyDetail.Status.REMINDED
|
||||||
|
: NotifyDetail.Status.WAITING);
|
||||||
detail.setReadAt(null);
|
detail.setReadAt(null);
|
||||||
super.create(detail);
|
super.create(detail);
|
||||||
|
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL) {
|
||||||
|
attachmentService.updateByBizId(Attachment.BizType.NOTIFY_DETAIL, detail.getId(), detail.getAttachmentList());
|
||||||
|
}
|
||||||
|
|
||||||
if (detail.getMsgType().isQueue()) {
|
if (detail.getMsgType().isQueue()) {
|
||||||
// 加入外部消息队列
|
// 加入外部消息队列
|
||||||
@@ -77,7 +88,9 @@ public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDe
|
|||||||
public List<NotifyDetail> listByNotifyId(String notifyId) {
|
public List<NotifyDetail> listByNotifyId(String notifyId) {
|
||||||
NotifyDetail example = new NotifyDetail();
|
NotifyDetail example = new NotifyDetail();
|
||||||
example.setNotifyId(notifyId);
|
example.setNotifyId(notifyId);
|
||||||
return mapper.selectAllByExample(example);
|
List<NotifyDetail> detailList = mapper.selectAllByExample(example);
|
||||||
|
loadAttachments(detailList);
|
||||||
|
return detailList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 删除通知详情
|
/// 删除通知详情
|
||||||
@@ -95,6 +108,36 @@ public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDe
|
|||||||
super.delete(detailId);
|
super.delete(detailId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 取消尚未生效的通知详情
|
||||||
|
///
|
||||||
|
/// @param detailId 通知详情 ID
|
||||||
|
/// @param reason 取消原因
|
||||||
|
@Override
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
public void cancelPending(String detailId, String reason) {
|
||||||
|
TimiException.required(detailId, "未找到通知详情 ID");
|
||||||
|
NotifyDetail detail = get(detailId);
|
||||||
|
TimiException.required(detail, "未找到通知详情");
|
||||||
|
if (detail.getStatus() == NotifyDetail.Status.CANCEL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long now = Time.now();
|
||||||
|
boolean canCancel = detail.getMsgType() == NotifyDetail.MsgType.INTERNAL
|
||||||
|
? detail.getSendAt() != null && now < detail.getSendAt()
|
||||||
|
: detail.getMsgType() != null && detail.getMsgType().isQueue()
|
||||||
|
&& detail.getStatus() == NotifyDetail.Status.WAITING;
|
||||||
|
if (!canCancel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (detail.getMsgType().isQueue()) {
|
||||||
|
detail.getMsgType().getService().destroyQueue(detail);
|
||||||
|
}
|
||||||
|
detail.setStatus(NotifyDetail.Status.CANCEL);
|
||||||
|
detail.setResultDesc(TimiJava.defaultIfEmpty(reason, "通知已取消"));
|
||||||
|
update(detail);
|
||||||
|
}
|
||||||
|
|
||||||
/// 重新将通知详情放入消息队列
|
/// 重新将通知详情放入消息队列
|
||||||
///
|
///
|
||||||
/// @param detailId 通知详情 ID
|
/// @param detailId 通知详情 ID
|
||||||
@@ -135,9 +178,11 @@ public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDe
|
|||||||
result.setTotal(unreadOnly
|
result.setTotal(unreadOnly
|
||||||
? mapper.countUnreadSiteByUserId(userId)
|
? mapper.countUnreadSiteByUserId(userId)
|
||||||
: mapper.countSiteByUserId(userId));
|
: mapper.countSiteByUserId(userId));
|
||||||
result.setList(unreadOnly
|
List<NotifyDetail> detailList = unreadOnly
|
||||||
? mapper.selectUnreadSiteByUserId(userId, validPage.getOffset(), validPage.getLimit())
|
? mapper.selectUnreadSiteByUserId(userId, validPage.getOffset(), validPage.getLimit())
|
||||||
: mapper.selectSiteByUserId(userId, validPage.getOffset(), validPage.getLimit()));
|
: mapper.selectSiteByUserId(userId, validPage.getOffset(), validPage.getLimit());
|
||||||
|
loadAttachments(detailList);
|
||||||
|
result.setList(detailList);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,19 +197,51 @@ public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDe
|
|||||||
TimiException.required(userId, "未找到用户 ID");
|
TimiException.required(userId, "未找到用户 ID");
|
||||||
NotifyDetail detail = mapper.selectSiteByIdAndUserId(detailId, userId);
|
NotifyDetail detail = mapper.selectSiteByIdAndUserId(detailId, userId);
|
||||||
TimiException.required(detail, "未找到站内通知");
|
TimiException.required(detail, "未找到站内通知");
|
||||||
|
loadAttachments(detail);
|
||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 删除当前用户拥有的站内通知详情
|
/// 回填通知详情的媒体附件
|
||||||
|
///
|
||||||
|
/// @param detailList 通知详情列表
|
||||||
|
private void loadAttachments(List<NotifyDetail> detailList) {
|
||||||
|
List<String> detailIdList = detailList.stream()
|
||||||
|
.filter(detail -> detail.getMsgType() == NotifyDetail.MsgType.INTERNAL)
|
||||||
|
.map(NotifyDetail::getId)
|
||||||
|
.toList();
|
||||||
|
if (detailIdList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(
|
||||||
|
Attachment.BizType.NOTIFY_DETAIL,
|
||||||
|
detailIdList
|
||||||
|
);
|
||||||
|
for (NotifyDetail detail : detailList) {
|
||||||
|
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL) {
|
||||||
|
detail.setAttachmentList(attachmentMap.getOrDefault(detail.getId(), List.of()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 回填通知详情的媒体附件
|
||||||
|
///
|
||||||
|
/// @param detail 通知详情
|
||||||
|
private void loadAttachments(NotifyDetail detail) {
|
||||||
|
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL) {
|
||||||
|
detail.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.NOTIFY_DETAIL, detail.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 隐藏当前用户拥有的站内通知详情
|
||||||
///
|
///
|
||||||
/// @param detailId 通知详情 ID
|
/// @param detailId 通知详情 ID
|
||||||
/// @param userId 用户 ID
|
/// @param userId 用户 ID
|
||||||
@Override
|
@Override
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
public void deleteInternalByUserId(String detailId, String userId) {
|
public void hideInternalByUserId(String detailId, String userId) {
|
||||||
TimiException.required(detailId, "未找到通知详情 ID");
|
TimiException.required(detailId, "未找到通知详情 ID");
|
||||||
TimiException.required(userId, "未找到用户 ID");
|
TimiException.required(userId, "未找到用户 ID");
|
||||||
int affected = mapper.deleteSiteByIdAndUserId(detailId, userId);
|
int affected = mapper.hideSiteByIdAndUserId(detailId, userId);
|
||||||
TimiException.requiredTrue(0 < affected, "未找到站内通知");
|
TimiException.requiredTrue(0 < affected, "未找到站内通知");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+120
-58
@@ -6,20 +6,23 @@ import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
|||||||
import com.imyeyu.api.modules.common.mapper.NotifyMapper;
|
import com.imyeyu.api.modules.common.mapper.NotifyMapper;
|
||||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||||
import com.imyeyu.api.modules.common.service.NotifyService;
|
import com.imyeyu.api.modules.common.service.NotifyService;
|
||||||
import com.imyeyu.api.modules.system.entity.Logger;
|
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
import com.imyeyu.api.modules.system.audit.AuditOperation;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.api.modules.system.audit.OperationAudit;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知服务实现
|
* 通知服务实现
|
||||||
@@ -27,13 +30,10 @@ import java.util.List;
|
|||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @since 2026-05-13 14:46
|
* @since 2026-05-13 14:46
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class NotifyServiceImplement extends AbstractEntityService<Notify, String> implements NotifyService {
|
public class NotifyServiceImplement extends AbstractEntityService<Notify, String> implements NotifyService {
|
||||||
|
|
||||||
private final LoggerService loggerService;
|
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
private final NotifyDetailService detailService;
|
private final NotifyDetailService detailService;
|
||||||
|
|
||||||
private final NotifyMapper mapper;
|
private final NotifyMapper mapper;
|
||||||
@@ -46,71 +46,133 @@ public class NotifyServiceImplement extends AbstractEntityService<Notify, String
|
|||||||
/// 创建通知并级联创建通知详情
|
/// 创建通知并级联创建通知详情
|
||||||
///
|
///
|
||||||
/// @param notify 通知
|
/// @param notify 通知
|
||||||
|
@OperationAudit(AuditOperation.COMMON_NOTIFY_CREATE)
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void create(Notify notify) {
|
public void create(Notify notify) {
|
||||||
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_NOTIFY_CREATE");
|
prepareCreate(notify);
|
||||||
try {
|
super.create(notify);
|
||||||
TimiException.required(notify, "未找到通知");
|
createDetails(notify);
|
||||||
TimiException.required(notify.getDetailList(), "未找到通知详情列表");
|
}
|
||||||
super.create(notify);
|
|
||||||
|
|
||||||
String sendFrom = null;
|
/// 原子创建业务提醒并级联创建通知详情
|
||||||
if (userLoginService.isLogged()) {
|
///
|
||||||
sendFrom = userLoginService.getRequireLoginUserId();
|
/// @param notify 通知
|
||||||
}
|
@OperationAudit(AuditOperation.COMMON_NOTIFY_CREATE)
|
||||||
for (NotifyDetail detail : notify.getDetailList()) {
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
detail.setNotifyId(notify.getId());
|
@Override
|
||||||
if (TimiJava.isNotEmpty(sendFrom)) {
|
public void createIfAbsent(Notify notify) {
|
||||||
detail.setSendFrom(sendFrom);
|
prepareCreate(notify);
|
||||||
}
|
if (mapper.insertIfAbsent(notify) == 0) {
|
||||||
detailService.create(detail);
|
return;
|
||||||
}
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(notify.getId());
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("创建通知失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "创建通知失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
}
|
||||||
|
createDetails(notify);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 按业务查重键查询未删除通知
|
||||||
|
///
|
||||||
|
/// @param bizType 业务类型
|
||||||
|
/// @param bizRemindedType 业务提醒类型
|
||||||
|
/// @param bizRemindedKey 业务提醒查重键
|
||||||
|
/// @return 通知
|
||||||
|
@Override
|
||||||
|
public Notify getByBusinessKey(String bizType, String bizRemindedType, String bizRemindedKey) {
|
||||||
|
TimiException.required(bizType, "未找到通知业务类型");
|
||||||
|
TimiException.required(bizRemindedType, "未找到通知提醒类型");
|
||||||
|
TimiException.required(bizRemindedKey, "未找到通知查重键");
|
||||||
|
return mapper.selectByBusinessKey(bizType, bizRemindedType, bizRemindedKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 校验并补全通知创建字段
|
||||||
|
///
|
||||||
|
/// @param notify 通知
|
||||||
|
private void prepareCreate(Notify notify) {
|
||||||
|
TimiException.required(notify, "未找到通知");
|
||||||
|
TimiException.required(notify.getDetailList(), "未找到通知详情列表");
|
||||||
|
notify.setId(TimiJava.defaultIfEmpty(notify.getId(), UUID.randomUUID().toString()));
|
||||||
|
notify.setCreatedBy(TimiJava.defaultIfEmpty(notify.getCreatedBy(), TimiJava.ZERO_UUID));
|
||||||
|
notify.setCreatedAt(TimiJava.defaultIfNull(notify.getCreatedAt(), Time.now()));
|
||||||
|
notify.setUpdatedAt(null);
|
||||||
|
notify.setDeletedAt(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 创建通知详情
|
||||||
|
///
|
||||||
|
/// @param notify 通知
|
||||||
|
private void createDetails(Notify notify) {
|
||||||
|
for (NotifyDetail detail : notify.getDetailList()) {
|
||||||
|
detail.setNotifyId(notify.getId());
|
||||||
|
detail.setSendFrom(TimiJava.defaultIfEmpty(detail.getSendFrom(), TimiJava.ZERO_UUID));
|
||||||
|
detailService.create(detail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 分页查询当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 管理端通知列表
|
||||||
|
@Override
|
||||||
|
public PageResult<NotifyManagementItem> pageManagement(Page<Notify> page, String userId) {
|
||||||
|
TimiException.required(userId, "未找到用户 ID");
|
||||||
|
Page<Notify> validPage = TimiJava.defaultIfNull(page, new Page<>());
|
||||||
|
PageResult<NotifyManagementItem> result = new PageResult<>();
|
||||||
|
result.setTotal(mapper.countManagement(userId));
|
||||||
|
result.setList(mapper.selectManagementPage(userId, validPage.getOffset(), validPage.getLimit()));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询当前用户可管理的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 通知
|
||||||
|
@Override
|
||||||
|
public Notify getManagement(String notifyId, String userId) {
|
||||||
|
TimiException.required(notifyId, "未找到通知 ID");
|
||||||
|
TimiException.required(userId, "未找到用户 ID");
|
||||||
|
Notify notify = mapper.selectManagement(notifyId, userId);
|
||||||
|
TimiException.required(notify, "未找到可管理的通知");
|
||||||
|
return notify;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
@Override
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@OperationAudit(AuditOperation.COMMON_NOTIFY_DELETE)
|
||||||
|
public void deleteManagement(String notifyId, String userId) {
|
||||||
|
getManagement(notifyId, userId);
|
||||||
|
delete(notifyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 取消当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
@Override
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
public void cancelManagement(String notifyId, String userId) {
|
||||||
|
getManagement(notifyId, userId);
|
||||||
|
cancel(notifyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 删除通知并级联软删除通知详情
|
/// 删除通知并级联软删除通知详情
|
||||||
///
|
///
|
||||||
/// @param notifyId 通知 ID
|
/// @param notifyId 通知 ID
|
||||||
|
@OperationAudit(AuditOperation.COMMON_NOTIFY_DELETE)
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void delete(String notifyId) {
|
public void delete(String notifyId) {
|
||||||
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_NOTIFY_DELETE");
|
TimiException.required(notifyId, "未找到通知 ID");
|
||||||
try {
|
TimiException.required(get(notifyId), "未找到通知");
|
||||||
TimiException.required(notifyId, "未找到通知 ID");
|
List<NotifyDetail> detailList = detailService.listByNotifyId(notifyId);
|
||||||
TimiException.required(get(notifyId), "未找到通知");
|
for (NotifyDetail detail : detailList) {
|
||||||
List<NotifyDetail> detailList = detailService.listByNotifyId(notifyId);
|
detailService.delete(detail.getId());
|
||||||
for (NotifyDetail detail : detailList) {
|
|
||||||
detailService.delete(detail.getId());
|
|
||||||
}
|
|
||||||
super.delete(notifyId);
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(notifyId);
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("删除通知失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "删除通知失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
}
|
||||||
|
super.delete(notifyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 取消通知中尚未成功发送的通知详情
|
/// 取消通知中尚未成功发送的通知详情
|
||||||
|
|||||||
+8
@@ -17,6 +17,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统配置服务实现
|
* 系统配置服务实现
|
||||||
@@ -53,6 +55,12 @@ public class SettingServiceImplement extends AbstractEntityService<Setting, Stri
|
|||||||
return mapper.selectAllByExample(example);
|
return mapper.selectAllByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Setting> mapPublic(String bizType, String bizId, List<String> code) {
|
||||||
|
TimiException.required(bizType, "not found bizType");
|
||||||
|
return mapper.selectPublicByQuery(bizType, bizId, code).stream().collect(Collectors.toMap(Setting::getCode, Function.identity()));
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void updateByBizId(String bizType, String bizId, List<Setting> list) {
|
public void updateByBizId(String bizType, String bizId, List<Setting> list) {
|
||||||
|
|||||||
+2
-8
@@ -1,6 +1,5 @@
|
|||||||
package com.imyeyu.api.modules.common.service.implement;
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
@@ -11,9 +10,9 @@ import com.imyeyu.api.modules.common.service.SmsQueueService;
|
|||||||
import com.imyeyu.api.modules.common.util.QCloudSmsProxy;
|
import com.imyeyu.api.modules.common.util.QCloudSmsProxy;
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.utils.Regex;
|
||||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||||
import com.tencentcloudapi.sms.v20210111.models.SendStatus;
|
import com.tencentcloudapi.sms.v20210111.models.SendStatus;
|
||||||
import com.imyeyu.utils.Regex;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -56,12 +55,7 @@ public class SmsQueueServiceImplement extends AbstractQueueService<SmsQueue, Not
|
|||||||
@Override
|
@Override
|
||||||
protected void doSend(SmsQueue queue) {
|
protected void doSend(SmsQueue queue) {
|
||||||
try {
|
try {
|
||||||
String[] args = new String[0];
|
String[] args = jackson.treeToValue(queue.getArgs(), String[].class);
|
||||||
if (queue.getArgs() != null && !queue.getArgs().isBlank()) {
|
|
||||||
JsonNode argsNode = jackson.readTree(queue.getArgs());
|
|
||||||
TimiException.requiredTrue(argsNode != null && argsNode.isArray(), "短信参数必须是数组");
|
|
||||||
args = jackson.treeToValue(argsNode, String[].class);
|
|
||||||
}
|
|
||||||
SendSmsResponse response = smsProxy.send(queue.getSendTo(), queue.getTemplateId(), args);
|
SendSmsResponse response = smsProxy.send(queue.getSendTo(), queue.getTemplateId(), args);
|
||||||
TimiException.required(response, "未找到短信响应");
|
TimiException.required(response, "未找到短信响应");
|
||||||
SendStatus[] statusSet = response.getSendStatusSet();
|
SendStatus[] statusSet = response.getSendStatusSet();
|
||||||
|
|||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
|
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||||
|
import com.imyeyu.api.modules.common.service.NotifyService;
|
||||||
|
import com.imyeyu.api.modules.common.service.SmsService;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.utils.Regex;
|
||||||
|
import com.imyeyu.utils.Text;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2026-05-14 12:12
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SmsServiceImplement implements SmsService {
|
||||||
|
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String env;
|
||||||
|
|
||||||
|
private final NotifyQueueConfig config;
|
||||||
|
private final ObjectMapper jackson;
|
||||||
|
|
||||||
|
private final NotifyService notifyService;
|
||||||
|
private final NotifyDetailService notifyDetailService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String captchaCreate(Notify notify) {
|
||||||
|
NotifyQueueConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha();
|
||||||
|
|
||||||
|
NotifyDetail detail = notify.getDetailList().getFirst();
|
||||||
|
|
||||||
|
TimiException.requiredTrue(Regex.isMatch(Regex.MOBILE_PHONE, detail.getSendTo()), "invalid mobilePhone");
|
||||||
|
|
||||||
|
String code = Text.randomString("0123456789", 6);
|
||||||
|
if (!env.equalsIgnoreCase("prod")) {
|
||||||
|
code = "123456";
|
||||||
|
}
|
||||||
|
detail.setMsgType(NotifyDetail.MsgType.SMS);
|
||||||
|
detail.setTemplateId(captchaConf.getTemplateId());
|
||||||
|
detail.setArgs(jackson.valueToTree(List.of(code, captchaConf.getTtlMinute())));
|
||||||
|
|
||||||
|
notifyService.create(notify);
|
||||||
|
return notifyDetailService.listByNotifyId(notify.getId()).getFirst().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotifyDetail captchaVerify(String detailId, String captcha) {
|
||||||
|
NotifyQueueConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha();
|
||||||
|
|
||||||
|
NotifyDetail detail = notifyDetailService.get(detailId);
|
||||||
|
TimiException.required(detail, "短信验证码无效");
|
||||||
|
TimiException.required(detail.getSendAt(), "短信验证码无效");
|
||||||
|
TimiException.requiredTrue(NotifyDetail.MsgType.SMS == detail.getMsgType(), "短信验证码无效");
|
||||||
|
if (Time.M * captchaConf.getTtlMinute() < Time.now() - detail.getSendAt()) {
|
||||||
|
throw new TimiException(TimiCode.ARG_EXPIRED, "验证码过期");
|
||||||
|
}
|
||||||
|
if (detail.getArgs() instanceof ArrayNode array) {
|
||||||
|
String dbCaptcha = array.get(captchaConf.getArgIndex()).asText();
|
||||||
|
if (!dbCaptcha.equalsIgnoreCase(captcha)) {
|
||||||
|
throw new TimiException(TimiCode.RESULT_BAD, "验证码错误");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new TimiException(TimiCode.ERROR, "not array args");
|
||||||
|
}
|
||||||
|
detail.setNotify(notifyService.get(detail.getNotifyId()));
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -1,5 +1,6 @@
|
|||||||
package com.imyeyu.api.modules.common.service.implement;
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
import com.imyeyu.api.modules.common.entity.Tag;
|
import com.imyeyu.api.modules.common.entity.Tag;
|
||||||
import com.imyeyu.api.modules.common.entity.TagApply;
|
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||||
import com.imyeyu.api.modules.common.mapper.TagApplyMapper;
|
import com.imyeyu.api.modules.common.mapper.TagApplyMapper;
|
||||||
@@ -14,6 +15,7 @@ import com.imyeyu.spring.service.AbstractEntityService;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -104,6 +106,19 @@ public class TagServiceImplement extends AbstractEntityService<Tag, String> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void deleteByOwner(Tag.OwnerType ownerType, String ownerId) {
|
||||||
|
TimiException.required(ownerType, "not found ownerType");
|
||||||
|
TimiException.required(ownerId, "not found ownerId");
|
||||||
|
Tag example = new Tag();
|
||||||
|
example.setOwnerType(ownerType);
|
||||||
|
example.setOwnerId(ownerId);
|
||||||
|
for (Tag tag : mapper.selectAllByExample(example)) {
|
||||||
|
super.delete(tag.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<TagApply> listApply(TagApply.BizType bizType, String bizId) {
|
private List<TagApply> listApply(TagApply.BizType bizType, String bizId) {
|
||||||
TimiException.required(bizType, "not found bizType");
|
TimiException.required(bizType, "not found bizType");
|
||||||
TimiException.required(bizId, "not found bizId");
|
TimiException.required(bizId, "not found bizId");
|
||||||
|
|||||||
+7
-5
@@ -3,6 +3,7 @@ package com.imyeyu.api.modules.common.service.implement;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.imyeyu.api.modules.common.bean.TempFileSetting;
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.entity.Setting;
|
import com.imyeyu.api.modules.common.entity.Setting;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
@@ -52,11 +53,11 @@ public class TempFileServiceImplement implements TempFileService {
|
|||||||
try {
|
try {
|
||||||
logger.setContent(jackson.writeValueAsString(logRequestArgs(files, ttl)));
|
logger.setContent(jackson.writeValueAsString(logRequestArgs(files, ttl)));
|
||||||
|
|
||||||
Setting ttlMin = settingService.getSystem(Setting.Module.TempFile.TTL_MIN);
|
Setting ttlMin = settingService.getSystem(TempFileSetting.TTL_MIN);
|
||||||
Setting ttlMax = settingService.getSystem(Setting.Module.TempFile.TTL_MAX);
|
Setting ttlMax = settingService.getSystem(TempFileSetting.TTL_MAX);
|
||||||
Setting ttlDefault = settingService.getSystem(Setting.Module.TempFile.TTL_DEFAULT);
|
Setting ttlDefault = settingService.getSystem(TempFileSetting.TTL_DEFAULT);
|
||||||
Setting residueTime = settingService.getSystem(Setting.Module.TempFile.RESIDUE_TTL);
|
Setting residueTime = settingService.getSystem(TempFileSetting.RESIDUE_TTL);
|
||||||
String limitStr = settingService.getSystem(Setting.Module.TempFile.LIMIT_SIZE_OF_IP).asString();
|
String limitStr = settingService.getSystem(TempFileSetting.LIMIT_SIZE_OF_IP).asString();
|
||||||
|
|
||||||
long limit = IOSize.parse(limitStr);
|
long limit = IOSize.parse(limitStr);
|
||||||
|
|
||||||
@@ -71,6 +72,7 @@ public class TempFileServiceImplement implements TempFileService {
|
|||||||
page.setSize(Long.MAX_VALUE);
|
page.setSize(Long.MAX_VALUE);
|
||||||
{
|
{
|
||||||
Attachment example = new Attachment();
|
Attachment example = new Attachment();
|
||||||
|
example.setBizType(BIZ_TYPE);
|
||||||
example.setUploaderIp(TimiSpring.getRequestIP());
|
example.setUploaderIp(TimiSpring.getRequestIP());
|
||||||
page.setEqualsExample(example);
|
page.setEqualsExample(example);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.imyeyu.api.modules.common.task;
|
|||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentVariantService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -23,6 +24,7 @@ import java.util.List;
|
|||||||
public class AttachmentClearTask {
|
public class AttachmentClearTask {
|
||||||
|
|
||||||
private final AttachmentService attachmentService;
|
private final AttachmentService attachmentService;
|
||||||
|
private final AttachmentVariantService attachmentVariantService;
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 1 * * ?")
|
@Scheduled(cron = "0 0 1 * * ?")
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -31,19 +33,20 @@ public class AttachmentClearTask {
|
|||||||
List<Attachment> needDestroyList = attachmentService.listNeedDestroy();
|
List<Attachment> needDestroyList = attachmentService.listNeedDestroy();
|
||||||
if (needDestroyList.isEmpty()) {
|
if (needDestroyList.isEmpty()) {
|
||||||
log.info("nothing attachment need clear");
|
log.info("nothing attachment need clear");
|
||||||
return;
|
} else {
|
||||||
}
|
for (Attachment attach : needDestroyList) {
|
||||||
for (Attachment attach : needDestroyList) {
|
try {
|
||||||
try {
|
attachmentService.destroy(attach.getId());
|
||||||
attachmentService.destroy(attach.getId());
|
log.info("clear attachment success: id[{}]", attach.getId());
|
||||||
log.info("clear attachment success: id[{}]", attach.getId());
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
log.error("clear attachment error: id[{}]", attach.getId(), e);
|
||||||
log.error("clear attachment error: id[{}]", attach.getId(), e);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
attachmentVariantService.clearExpired();
|
||||||
log.info("end clear expired attachments");
|
log.info("end clear expired attachments");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("attachment clear task error", e);
|
log.error("attachment clear task error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.imyeyu.api.modules.common.vo;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/// 客户端诊断日志请求
|
||||||
|
///
|
||||||
|
/// 客户端日志不是操作审计,操作编码、模块、级别、用户和 IP 均由服务端决定
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-09
|
||||||
|
@Data
|
||||||
|
public class ClientLogRequest {
|
||||||
|
|
||||||
|
/// 日志内容
|
||||||
|
@Size(max = 32768, message = "日志内容不能超过 32 KB")
|
||||||
|
private String content;
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.imyeyu.api.modules.common.vo;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/// 管理端通知列表项
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-25
|
||||||
|
@Data
|
||||||
|
public class NotifyManagementItem {
|
||||||
|
|
||||||
|
/// 通知 ID
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/// 创建者用户 ID
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
|
/// 创建时间
|
||||||
|
private Long createdAt;
|
||||||
|
|
||||||
|
/// 更新时间
|
||||||
|
private Long updatedAt;
|
||||||
|
|
||||||
|
/// 通知标题
|
||||||
|
private String subject;
|
||||||
|
|
||||||
|
/// 通知内容
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/// 内容类型
|
||||||
|
private NotifyDetail.ContentType contentType;
|
||||||
|
|
||||||
|
/// 发送时间
|
||||||
|
private Long sendAt;
|
||||||
|
|
||||||
|
/// 接收用户数量
|
||||||
|
private Long recipientCount;
|
||||||
|
|
||||||
|
/// 已读用户数量
|
||||||
|
private Long readCount;
|
||||||
|
|
||||||
|
/// 等待发送数量
|
||||||
|
private Long waitingCount;
|
||||||
|
|
||||||
|
/// 已发送数量
|
||||||
|
private Long remindedCount;
|
||||||
|
|
||||||
|
/// 超时数量
|
||||||
|
private Long timeoutCount;
|
||||||
|
|
||||||
|
/// 已取消数量
|
||||||
|
private Long cancelCount;
|
||||||
|
|
||||||
|
/// 失败数量
|
||||||
|
private Long failCount;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.imyeyu.api.modules.common.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21 17:59
|
||||||
|
@Data
|
||||||
|
public class SmsCaptchaVerifyRequest {
|
||||||
|
|
||||||
|
private String detailId;
|
||||||
|
|
||||||
|
private String captcha;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.config;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// GAO 智能体配置
|
||||||
|
///
|
||||||
|
/// 密钥只从部署环境变量或外部配置读取,不允许写入仓库
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Getter
|
||||||
|
@Component
|
||||||
|
public class GaoAiProperties {
|
||||||
|
|
||||||
|
/// AI 会话有效期,单位秒
|
||||||
|
@Value("${gao.ai.session-ttl-seconds:300}")
|
||||||
|
private long sessionTtlSeconds;
|
||||||
|
|
||||||
|
/// 工具单页最大条数
|
||||||
|
@Value("${gao.ai.max-tool-page-size:20}")
|
||||||
|
private int maxToolPageSize;
|
||||||
|
|
||||||
|
/// Dify 连接超时,单位秒
|
||||||
|
@Value("${gao.ai.connect-timeout-seconds:10}")
|
||||||
|
private long connectTimeoutSeconds;
|
||||||
|
|
||||||
|
/// Dify 流式读取空闲超时,单位秒
|
||||||
|
@Value("${gao.ai.read-timeout-seconds:600}")
|
||||||
|
private long readTimeoutSeconds;
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiAccessException;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiChatService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiChatRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiConversationListRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiConversationReadRequest;
|
||||||
|
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
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.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
/// GAO 智能体聊天接口
|
||||||
|
///
|
||||||
|
/// 浏览器只携带 Timi 登录令牌访问本接口,不接触 Dify 或 MCP 密钥
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/ai")
|
||||||
|
public class GaoAiChatController {
|
||||||
|
|
||||||
|
private final GaoAiChatService chatService;
|
||||||
|
|
||||||
|
/// 发起门店智能体流式聊天
|
||||||
|
///
|
||||||
|
/// @param request 聊天请求
|
||||||
|
/// @return SSE 发射器
|
||||||
|
@RequestRateLimit
|
||||||
|
@IgnoreGlobalReturn
|
||||||
|
@PostMapping(value = "/chat", produces = "text/event-stream")
|
||||||
|
public SseEmitter chat(@RequestBody GaoAiChatRequest request) {
|
||||||
|
try {
|
||||||
|
return chatService.chat(request);
|
||||||
|
} catch (GaoAiAccessException e) {
|
||||||
|
throw accessException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 列出当前登录用户的历史会话
|
||||||
|
///
|
||||||
|
/// @param request 历史会话分页请求
|
||||||
|
/// @return 历史会话分页结果
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/conversation/list")
|
||||||
|
public JsonNode listConversation(@RequestBody(required = false) GaoAiConversationListRequest request) {
|
||||||
|
try {
|
||||||
|
return chatService.listConversation(request);
|
||||||
|
} catch (GaoAiAccessException e) {
|
||||||
|
throw accessException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 读取指定历史会话的消息
|
||||||
|
///
|
||||||
|
/// @param request 历史会话读取请求
|
||||||
|
/// @return 会话消息分页结果
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/conversation/read")
|
||||||
|
public JsonNode readConversation(@RequestBody GaoAiConversationReadRequest request) {
|
||||||
|
try {
|
||||||
|
return chatService.readConversation(request);
|
||||||
|
} catch (GaoAiAccessException e) {
|
||||||
|
throw accessException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除当前登录用户的历史会话
|
||||||
|
///
|
||||||
|
/// @param conversationId Dify 会话 ID
|
||||||
|
/// @return 无
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/conversation/delete")
|
||||||
|
public void deleteConversation(@RequestParam String conversationId) {
|
||||||
|
try {
|
||||||
|
chatService.deleteConversation(conversationId);
|
||||||
|
} catch (GaoAiAccessException e) {
|
||||||
|
throw accessException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 转换智能体访问异常
|
||||||
|
///
|
||||||
|
/// @param exception 智能体访问异常
|
||||||
|
/// @return HTTP 响应状态异常
|
||||||
|
private ResponseStatusException accessException(GaoAiAccessException exception) {
|
||||||
|
return new ResponseStatusException(HttpStatus.valueOf(exception.getStatus()), exception.getMessage(), exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/// GAO 智能体审计记录
|
||||||
|
///
|
||||||
|
/// 业务审计通过现有系统日志服务落库,本对象只承载脱敏后的结构化内容
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Data
|
||||||
|
public class GaoAiAuditLog {
|
||||||
|
|
||||||
|
/// 登录用户 ID
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
|
/// 问题摘要哈希,不保存问题原文
|
||||||
|
private String questionDigest;
|
||||||
|
|
||||||
|
/// Dify 会话 ID
|
||||||
|
private String conversationId;
|
||||||
|
|
||||||
|
/// 调用的工具名称
|
||||||
|
private String toolName;
|
||||||
|
|
||||||
|
/// 查询耗时,单位毫秒
|
||||||
|
private long duration;
|
||||||
|
|
||||||
|
/// 查询状态
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/// 返回条数
|
||||||
|
private long resultCount;
|
||||||
|
|
||||||
|
/// 记录时间,单位毫秒
|
||||||
|
private long createdAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/// GAO 智能体短期会话授权
|
||||||
|
///
|
||||||
|
/// 该对象只存储在服务端,`sessionId` 不是 JWT,也不是用户登录令牌
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class GaoAiSession {
|
||||||
|
|
||||||
|
/// 不可预测的 AI 会话 ID
|
||||||
|
private String sessionId;
|
||||||
|
|
||||||
|
/// 登录用户 ID
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/// 固定的门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
|
/// Dify 会话 ID,可为空
|
||||||
|
private String difyConversationId;
|
||||||
|
|
||||||
|
/// 允许调用的只读工具
|
||||||
|
private Set<String> allowedTools = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
/// 过期时间,单位毫秒
|
||||||
|
private long expiresAt;
|
||||||
|
|
||||||
|
/// 已调用工具次数
|
||||||
|
private long usedCount;
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.service.SettingService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiSessionService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.implement.GaoAiSessionServiceImplement.GaoAiSessionException;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoSystemSetting;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
|
||||||
|
/// Dify MCP 请求认证
|
||||||
|
///
|
||||||
|
/// 服务密钥只证明请求来自 Dify,门店和用户身份完全来自 AI 会话
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoAiMcpAuthentication {
|
||||||
|
|
||||||
|
private final SettingService settingService;
|
||||||
|
private final GaoAiSessionService sessionService;
|
||||||
|
|
||||||
|
/// 校验 Dify 服务密钥和 AI 会话
|
||||||
|
///
|
||||||
|
/// @param authorization Authorization 请求头
|
||||||
|
/// @param headerSessionId X-Timi-AI-Session 请求头
|
||||||
|
/// @param argumentSessionId MCP 工具参数中的 AI 会话 ID
|
||||||
|
/// @param toolName 工具名称,可为空
|
||||||
|
/// @return 已认证会话
|
||||||
|
public GaoAiSession authenticate(String authorization, String headerSessionId, String argumentSessionId, String toolName) {
|
||||||
|
authenticateService(authorization);
|
||||||
|
String sessionId = headerSessionId;
|
||||||
|
if (isBlank(sessionId) && !isBlank(argumentSessionId)) {
|
||||||
|
sessionId = argumentSessionId;
|
||||||
|
}
|
||||||
|
GaoAiSession session = sessionService.require(sessionId);
|
||||||
|
if (toolName != null && (session.getAllowedTools() == null || !session.getAllowedTools().contains(toolName))) {
|
||||||
|
throw new GaoAiSessionException("AI 会话无权调用该工具", 403);
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 只校验 Dify 服务间密钥
|
||||||
|
///
|
||||||
|
/// MCP 初始化和工具声明阶段尚未绑定店长会话,只能校验服务间身份
|
||||||
|
///
|
||||||
|
/// @param authorization Authorization 请求头
|
||||||
|
public void authenticateService(String authorization) {
|
||||||
|
String key = settingService.getSystem(GaoSystemSetting.DIFY_MCP_SERVICE_KEY).asString();
|
||||||
|
String actualKey = bearerValue(authorization);
|
||||||
|
if (key.isEmpty() || actualKey.isEmpty() || !constantTimeEquals(key, actualKey)) {
|
||||||
|
throw new GaoAiSessionException("MCP 服务认证失败", 401);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String bearerValue(String authorization) {
|
||||||
|
if (authorization == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String value = authorization.trim();
|
||||||
|
if (7 > value.length() || !value.regionMatches(true, 0, "Bearer ", 0, 7)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return value.substring(7).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean constantTimeEquals(String left, String right) {
|
||||||
|
return MessageDigest.isEqual(left.getBytes(StandardCharsets.UTF_8), right.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String trim(String value) {
|
||||||
|
return value == null ? "" : value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 判断字符串是否为空
|
||||||
|
///
|
||||||
|
/// @param value 待判断字符串
|
||||||
|
/// @return true 为 null、空字符串或空白字符串
|
||||||
|
private boolean isBlank(String value) {
|
||||||
|
return value == null || value.trim().isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,273 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiAuditLog;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.tool.GaoAiTool;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiAuditService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiSessionService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiToolException;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.implement.GaoAiSessionServiceImplement.GaoAiSessionException;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/// GAO 智能体 MCP Streamable HTTP 接口
|
||||||
|
///
|
||||||
|
/// Dify 通过 Docker 内网访问本接口,业务查询只允许调用已注册的只读工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/mcp/gao-ai")
|
||||||
|
public class GaoAiMcpController {
|
||||||
|
|
||||||
|
private final ObjectMapper jackson;
|
||||||
|
private final GaoAiMcpAuthentication authentication;
|
||||||
|
private final GaoAiSessionService sessionService;
|
||||||
|
private final GaoAiAuditService auditService;
|
||||||
|
private final Map<String, GaoAiTool> toolMap;
|
||||||
|
|
||||||
|
public GaoAiMcpController(ObjectMapper jackson, GaoAiMcpAuthentication authentication,
|
||||||
|
GaoAiSessionService sessionService, GaoAiAuditService auditService, List<GaoAiTool> toolList) {
|
||||||
|
this.jackson = jackson;
|
||||||
|
this.authentication = authentication;
|
||||||
|
this.sessionService = sessionService;
|
||||||
|
this.auditService = auditService;
|
||||||
|
this.toolMap = toolList.stream().collect(Collectors.toUnmodifiableMap(GaoAiTool::name, Function.identity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 处理 MCP JSON-RPC 请求
|
||||||
|
///
|
||||||
|
/// @param authorization Dify 服务密钥
|
||||||
|
/// @param aiSessionId AI 会话头
|
||||||
|
/// @param request JSON-RPC 请求
|
||||||
|
/// @return JSON-RPC 响应
|
||||||
|
@IgnoreGlobalReturn
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<Object> handle(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authorization,
|
||||||
|
@RequestHeader(value = "X-Timi-AI-Session", required = false) String aiSessionId,
|
||||||
|
@RequestBody JsonNode request) {
|
||||||
|
JsonNode id = request == null ? null : request.get("id");
|
||||||
|
String method = text(request, "method");
|
||||||
|
String toolName = text(request == null ? null : request.path("params"), "name");
|
||||||
|
log.info("GAO MCP 请求:method={}, toolName={}, authorizationPresent={}, aiSessionPresent={}, aiSessionLength={}",
|
||||||
|
method, toolName, hasText(authorization), hasText(aiSessionId), length(aiSessionId));
|
||||||
|
try {
|
||||||
|
if (request == null || !request.isObject()) {
|
||||||
|
return response(400, error(id, -32600, "MCP 请求格式无效"));
|
||||||
|
}
|
||||||
|
if (method == null) {
|
||||||
|
return response(400, error(id, -32600, "MCP 请求缺少 method"));
|
||||||
|
}
|
||||||
|
return switch (method) {
|
||||||
|
case "initialize" -> {
|
||||||
|
authentication.authenticateService(authorization);
|
||||||
|
yield response(200, success(id, initializeResult()));
|
||||||
|
}
|
||||||
|
case "notifications/initialized", "ping" -> {
|
||||||
|
authentication.authenticateService(authorization);
|
||||||
|
yield response(200, success(id, Map.of()));
|
||||||
|
}
|
||||||
|
case "tools/list" -> {
|
||||||
|
authentication.authenticateService(authorization);
|
||||||
|
yield response(200, success(id, toolsResult()));
|
||||||
|
}
|
||||||
|
case "tools/call" -> {
|
||||||
|
JsonNode params = request.path("params");
|
||||||
|
String argumentSessionId = text(params.path("arguments"), "aiSessionId");
|
||||||
|
GaoAiSession session = authentication.authenticate(authorization, aiSessionId, argumentSessionId, text(params, "name"));
|
||||||
|
if (hasText(argumentSessionId) && !hasText(aiSessionId)) {
|
||||||
|
log.info("GAO MCP 使用工具参数中的 AI 会话:toolName={}, aiSessionLength={}", toolName, length(argumentSessionId));
|
||||||
|
}
|
||||||
|
yield response(200, success(id, executeTool(session, params, hasText(aiSessionId) ? aiSessionId : argumentSessionId)));
|
||||||
|
}
|
||||||
|
default -> response(400, error(id, -32601, "MCP 方法不支持"));
|
||||||
|
};
|
||||||
|
} catch (GaoAiSessionException e) {
|
||||||
|
log.warn("GAO MCP 认证失败:method={}, toolName={}, status={}, authorizationPresent={}, aiSessionPresent={}, aiSessionLength={}, reason={}",
|
||||||
|
method, toolName, e.getStatus(), hasText(authorization), hasText(aiSessionId), length(aiSessionId), e.getMessage());
|
||||||
|
return response(e.getStatus(), error(id, -32001, e.getMessage()));
|
||||||
|
} catch (GaoAiToolException e) {
|
||||||
|
log.warn("GAO MCP 工具调用失败:method={}, toolName={}, status={}, aiSessionPresent={}, reason={}",
|
||||||
|
method, toolName, e.getStatus(), hasText(aiSessionId), e.getMessage());
|
||||||
|
return response(e.getStatus(), error(id, -32602, e.getMessage()));
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.warn("GAO 智能体 MCP 请求失败", e);
|
||||||
|
return response(500, error(id, -32603, "智能体查询失败,请稍后重试"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object executeTool(GaoAiSession session, JsonNode params, String aiSessionId) {
|
||||||
|
if (params == null || !params.isObject()) {
|
||||||
|
throw new GaoAiToolException("工具参数格式无效", 400);
|
||||||
|
}
|
||||||
|
String toolName = text(params, "name");
|
||||||
|
GaoAiTool tool = toolMap.get(toolName);
|
||||||
|
if (tool == null) {
|
||||||
|
throw new GaoAiToolException("工具不存在或未启用", 403);
|
||||||
|
}
|
||||||
|
JsonNode arguments = params == null || !params.has("arguments") ? jackson.createObjectNode() : params.get("arguments");
|
||||||
|
if (arguments == null || !arguments.isObject()) {
|
||||||
|
throw new GaoAiToolException("工具参数格式无效", 400);
|
||||||
|
}
|
||||||
|
ObjectNode businessArguments = ((ObjectNode) arguments).deepCopy();
|
||||||
|
businessArguments.remove("aiSessionId");
|
||||||
|
if (containsField(businessArguments, "storeId")) {
|
||||||
|
throw new GaoAiToolException("工具请求不允许携带 storeId", 403);
|
||||||
|
}
|
||||||
|
GaoAiToolRequest request;
|
||||||
|
try {
|
||||||
|
request = jackson.treeToValue(businessArguments, GaoAiToolRequest.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new GaoAiToolException("工具参数格式无效", 400);
|
||||||
|
}
|
||||||
|
long startedAt = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
GaoAiToolResult result = tool.execute(session, request);
|
||||||
|
long duration = System.currentTimeMillis() - startedAt;
|
||||||
|
if (hasText(aiSessionId)) {
|
||||||
|
sessionService.increaseUsedCount(aiSessionId);
|
||||||
|
}
|
||||||
|
recordAudit(session, request, toolName, duration, "SUCCESS", result == null ? 0L : result.getDetails().size());
|
||||||
|
Map<String, Object> content = new LinkedHashMap<>();
|
||||||
|
content.put("type", "text");
|
||||||
|
content.put("text", writeJson(result));
|
||||||
|
return Map.of("content", List.of(content), "structuredContent", result);
|
||||||
|
} catch (GaoAiToolException e) {
|
||||||
|
recordAudit(session, request, toolName, System.currentTimeMillis() - startedAt, "ERROR", 0L);
|
||||||
|
throw e;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
recordAudit(session, request, toolName, System.currentTimeMillis() - startedAt, "ERROR", 0L);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> initializeResult() {
|
||||||
|
Map<String, Object> result = new LinkedHashMap<>();
|
||||||
|
result.put("protocolVersion", "2025-03-26");
|
||||||
|
result.put("capabilities", Map.of("tools", Map.of("listChanged", false)));
|
||||||
|
result.put("serverInfo", Map.of("name", "TimiServerAPI-GAO-AI", "version", "1.0"));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> toolsResult() {
|
||||||
|
List<Map<String, Object>> tools = toolMap.values().stream()
|
||||||
|
.map(tool -> {
|
||||||
|
Map<String, Object> item = new LinkedHashMap<>();
|
||||||
|
item.put("name", tool.name());
|
||||||
|
item.put("description", tool.description());
|
||||||
|
item.put("inputSchema", tool.inputSchema());
|
||||||
|
return item;
|
||||||
|
}).toList();
|
||||||
|
return Map.of("tools", tools);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void recordAudit(GaoAiSession session, GaoAiToolRequest request, String toolName, long duration,
|
||||||
|
String status, long resultCount) {
|
||||||
|
GaoAiAuditLog audit = new GaoAiAuditLog();
|
||||||
|
audit.setUserId(session.getUserId());
|
||||||
|
audit.setStoreId(session.getStoreId());
|
||||||
|
audit.setQuestionDigest(auditService.digest(request == null ? null : request.getQuery()));
|
||||||
|
audit.setConversationId(session.getDifyConversationId());
|
||||||
|
audit.setToolName(toolName);
|
||||||
|
audit.setDuration(Math.max(0L, duration));
|
||||||
|
audit.setStatus(status);
|
||||||
|
audit.setResultCount(resultCount);
|
||||||
|
audit.setCreatedAt(System.currentTimeMillis());
|
||||||
|
auditService.record(audit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResponseEntity<Object> response(int status, Object body) {
|
||||||
|
return ResponseEntity.status(status).body(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> success(JsonNode id, Object result) {
|
||||||
|
Map<String, Object> response = new LinkedHashMap<>();
|
||||||
|
response.put("jsonrpc", "2.0");
|
||||||
|
response.put("id", id);
|
||||||
|
response.put("result", result);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> error(JsonNode id, int code, String message) {
|
||||||
|
Map<String, Object> response = new LinkedHashMap<>();
|
||||||
|
response.put("jsonrpc", "2.0");
|
||||||
|
response.put("id", id);
|
||||||
|
response.put("error", Map.of("code", code, "message", message));
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String text(JsonNode node, String field) {
|
||||||
|
if (node == null || !node.hasNonNull(field)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String value = node.get(field).asText();
|
||||||
|
return value == null || value.trim().isEmpty() ? null : value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 判断字符串是否有实际内容
|
||||||
|
///
|
||||||
|
/// @param value 待判断字符串
|
||||||
|
/// @return true 为有内容
|
||||||
|
private boolean hasText(String value) {
|
||||||
|
return value != null && !value.trim().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 获取字符串长度
|
||||||
|
///
|
||||||
|
/// @param value 待计算字符串
|
||||||
|
/// @return 字符串长度
|
||||||
|
private int length(String value) {
|
||||||
|
return value == null ? 0 : value.trim().length();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean containsField(JsonNode node, String field) {
|
||||||
|
if (node == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (node.isObject()) {
|
||||||
|
if (node.has(field)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (JsonNode child : node) {
|
||||||
|
if (containsField(child, field)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (node.isArray()) {
|
||||||
|
for (JsonNode child : node) {
|
||||||
|
if (containsField(child, field)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String writeJson(Object value) {
|
||||||
|
try {
|
||||||
|
return jackson.writeValueAsString(value);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new GaoAiToolException("工具结果序列化失败", 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||||
|
import org.springframework.http.CacheControl;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/// GAO MCP OAuth 探测兼容接口
|
||||||
|
///
|
||||||
|
/// Dify 即使配置固定请求头认证,也会预先探测 OAuth 元数据。本服务不提供 OAuth,必须返回原始 404,
|
||||||
|
/// 不能落入全局异常处理后被包装为业务 JSON
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@RestController
|
||||||
|
public class GaoAiMcpOAuthDiscoveryController {
|
||||||
|
|
||||||
|
/// 返回未实现的 OAuth 探测结果
|
||||||
|
///
|
||||||
|
/// @return 原始 HTTP 404
|
||||||
|
@IgnoreGlobalReturn
|
||||||
|
@GetMapping({
|
||||||
|
"/.well-known/oauth-authorization-server",
|
||||||
|
"/.well-known/oauth-authorization-server/mcp/gao-ai",
|
||||||
|
"/.well-known/oauth-protected-resource",
|
||||||
|
"/.well-known/oauth-protected-resource/mcp/gao-ai",
|
||||||
|
"/.well-known/openid-configuration",
|
||||||
|
"/.well-known/openid-configuration/mcp/gao-ai",
|
||||||
|
"/mcp/gao-ai/.well-known/oauth-authorization-server",
|
||||||
|
"/mcp/gao-ai/.well-known/oauth-protected-resource",
|
||||||
|
"/mcp/gao-ai/.well-known/openid-configuration"
|
||||||
|
})
|
||||||
|
public ResponseEntity<Void> notSupported() {
|
||||||
|
return ResponseEntity.notFound().cacheControl(CacheControl.noStore()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/// GAO 智能体只读工具名称
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
public final class GaoAiToolNames {
|
||||||
|
|
||||||
|
public static final String STORE_OVERVIEW = "store_overview";
|
||||||
|
public static final String CUSTOMER_SEARCH = "customer_search";
|
||||||
|
public static final String CUSTOMER_PROFILE = "customer_profile";
|
||||||
|
public static final String ORDER_QUERY = "order_query";
|
||||||
|
public static final String EVENT_QUERY = "event_query";
|
||||||
|
public static final String PRODUCT_INVENTORY_QUERY = "product_inventory_query";
|
||||||
|
public static final String POINT_QUERY = "point_query";
|
||||||
|
public static final String BUSINESS_REPORT = "business_report";
|
||||||
|
public static final String STORE_DIARY_QUERY = "store_diary_query";
|
||||||
|
public static final String METRIC_DEFINITION = "metric_definition";
|
||||||
|
|
||||||
|
public static final Set<String> READ_ONLY_TOOLS = java.util.Collections.unmodifiableSet(new LinkedHashSet<>(List.of(
|
||||||
|
STORE_OVERVIEW,
|
||||||
|
CUSTOMER_SEARCH,
|
||||||
|
CUSTOMER_PROFILE,
|
||||||
|
ORDER_QUERY,
|
||||||
|
EVENT_QUERY,
|
||||||
|
PRODUCT_INVENTORY_QUERY,
|
||||||
|
POINT_QUERY,
|
||||||
|
BUSINESS_REPORT,
|
||||||
|
STORE_DIARY_QUERY,
|
||||||
|
METRIC_DEFINITION
|
||||||
|
)));
|
||||||
|
|
||||||
|
private GaoAiToolNames() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 生成稳定的工具顺序
|
||||||
|
///
|
||||||
|
/// @return 工具名称集合
|
||||||
|
public static Set<String> orderedReadOnlyTools() {
|
||||||
|
return new LinkedHashSet<>(READ_ONLY_TOOLS);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 门店经营报表工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BusinessReportTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.BUSINESS_REPORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "查询当前门店销售趋势、应收、客户复购和产品排行";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.businessReport(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 客户经营档案工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class CustomerProfileTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.CUSTOMER_PROFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "查询当前门店单个客户的套餐、积分、消费和事件档案";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.customerProfile(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 客户查询工具
|
||||||
|
///
|
||||||
|
/// 同时承载客户搜索和客户经营档案查询
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class CustomerTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.CUSTOMER_SEARCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "按客户姓名或编码查询当前门店客户摘要";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.customerSearch(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 登记事件查询工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class EventTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.EVENT_QUERY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "查询当前门店登记事件记录及事件统计,严格只读";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.eventQuery(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/// GAO 智能体只读工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
public interface GaoAiTool {
|
||||||
|
|
||||||
|
/// @return 工具名称
|
||||||
|
String name();
|
||||||
|
|
||||||
|
/// @return 工具描述
|
||||||
|
String description();
|
||||||
|
|
||||||
|
/// 执行工具查询
|
||||||
|
///
|
||||||
|
/// @param session 已认证 AI 会话
|
||||||
|
/// @param request 工具请求
|
||||||
|
/// @return 脱敏查询结果
|
||||||
|
GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request);
|
||||||
|
|
||||||
|
/// @return MCP 输入参数结构
|
||||||
|
default Map<String, Object> inputSchema() {
|
||||||
|
Map<String, Object> timeRange = Map.of(
|
||||||
|
"type", "object",
|
||||||
|
"properties", Map.of(
|
||||||
|
"preset", Map.of("type", "string", "enum", new String[]{"TODAY", "LAST_7_DAYS", "LAST_30_DAYS", "THIS_MONTH", "THIS_YEAR", "CUSTOM"}),
|
||||||
|
"startDate", Map.of("type", "string", "description", "自定义开始日期,格式 yyyy-MM-dd"),
|
||||||
|
"endDate", Map.of("type", "string", "description", "自定义结束日期,格式 yyyy-MM-dd")
|
||||||
|
),
|
||||||
|
"additionalProperties", false
|
||||||
|
);
|
||||||
|
Map<String, Object> properties = new LinkedHashMap<>();
|
||||||
|
properties.put("query", Map.of("type", "string", "description", "自然语言关键词"));
|
||||||
|
properties.put("timeRange", timeRange);
|
||||||
|
properties.put("filters", Map.of("type", "object"));
|
||||||
|
properties.put("pageSize", Map.of("type", "integer", "minimum", 1, "maximum", 20));
|
||||||
|
properties.put("cursor", Map.of("type", "string"));
|
||||||
|
properties.put("aiSessionId", Map.of(
|
||||||
|
"type", "string",
|
||||||
|
"description", "由工作流变量注入的 AI 会话 ID,不允许由模型生成"
|
||||||
|
));
|
||||||
|
return Map.of(
|
||||||
|
"type", "object",
|
||||||
|
"properties", properties,
|
||||||
|
"additionalProperties", false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 指标口径查询工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MetricDefinitionTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.METRIC_DEFINITION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "查询门店经营助手使用的固定指标名称和计算口径";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.metricDefinition(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 订单和资金查询工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class OrderTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.ORDER_QUERY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "查询当前门店销售订单、履约和资金摘要,严格只读";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.orderQuery(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 积分查询工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PointTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.POINT_QUERY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "查询当前门店积分账户、积分流水、规则和兑换摘要,严格只读";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.pointQuery(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 产品库存查询工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ProductInventoryTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.PRODUCT_INVENTORY_QUERY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "查询当前门店产品、SKU 和库存余额,严格只读";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.productInventoryQuery(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 门店日记查询工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class StoreDiaryTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.STORE_DIARY_QUERY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "查询当前门店日记和营业日信息,严格只读";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.storeDiaryQuery(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.mcp.tool;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.mcp.GaoAiToolNames;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.service.GaoAiQueryService;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiToolResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/// 门店经营总览工具
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class StoreOverviewTool implements GaoAiTool {
|
||||||
|
|
||||||
|
private final GaoAiQueryService queryService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return GaoAiToolNames.STORE_OVERVIEW;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "查询当前门店指定周期的营业日、销售、应收和库存健康总览";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoAiToolResult execute(GaoAiSession session, GaoAiToolRequest request) {
|
||||||
|
return queryService.storeOverview(session, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.service;
|
||||||
|
|
||||||
|
/// GAO 智能体访问异常
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
public class GaoAiAccessException extends RuntimeException {
|
||||||
|
|
||||||
|
private final int status;
|
||||||
|
|
||||||
|
/// @param message 用户可读消息
|
||||||
|
/// @param status HTTP 状态码
|
||||||
|
public GaoAiAccessException(String message, int status) {
|
||||||
|
super(message);
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @return HTTP 状态码
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiAuditLog;
|
||||||
|
|
||||||
|
/// GAO 智能体审计服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
public interface GaoAiAuditService {
|
||||||
|
|
||||||
|
/// 记录脱敏后的 AI 查询审计
|
||||||
|
///
|
||||||
|
/// @param auditLog 审计记录
|
||||||
|
void record(GaoAiAuditLog auditLog);
|
||||||
|
|
||||||
|
/// 计算问题摘要哈希
|
||||||
|
///
|
||||||
|
/// @param question 问题原文
|
||||||
|
/// @return SHA-256 摘要
|
||||||
|
String digest(String question);
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.ai.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiChatRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiConversationListRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.ai.vo.GaoAiConversationReadRequest;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
/// GAO 智能体聊天服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-15
|
||||||
|
public interface GaoAiChatService {
|
||||||
|
|
||||||
|
/// 创建 AI 会话并转发 Dify 流式响应
|
||||||
|
///
|
||||||
|
/// @param request 聊天请求
|
||||||
|
/// @return SSE 发射器
|
||||||
|
SseEmitter chat(GaoAiChatRequest request);
|
||||||
|
|
||||||
|
/// 列出当前登录用户的历史会话
|
||||||
|
///
|
||||||
|
/// @param request 历史会话分页请求
|
||||||
|
/// @return 历史会话分页结果
|
||||||
|
JsonNode listConversation(GaoAiConversationListRequest request);
|
||||||
|
|
||||||
|
/// 读取当前登录用户的历史会话消息
|
||||||
|
///
|
||||||
|
/// @param request 历史会话读取请求
|
||||||
|
/// @return 会话消息分页结果
|
||||||
|
JsonNode readConversation(GaoAiConversationReadRequest request);
|
||||||
|
|
||||||
|
/// 删除当前登录用户的历史会话
|
||||||
|
///
|
||||||
|
/// @param conversationId Dify 会话 ID
|
||||||
|
void deleteConversation(String conversationId);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user