Compare commits
77
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df2da25833 | ||
|
|
1ea4cfeba3 | ||
|
|
ce6e3ef70a | ||
|
|
87e20c31a9 | ||
|
|
22edf34ff1 | ||
|
|
16ba79a336 | ||
|
|
9c25b1b397 | ||
|
|
5a80e6693f | ||
|
|
ab58641bbe | ||
|
|
45e3d84f59 | ||
|
|
a3ff636e45 | ||
|
|
7b360ddccd | ||
|
|
758c7521bb | ||
|
|
e730cfaa7d | ||
|
|
60a87a8d15 | ||
|
|
0b519b8ca1 | ||
|
|
e6b4a747ce | ||
|
|
f009f75c03 | ||
|
|
91b621fe75 | ||
|
|
5d1a157085 | ||
|
|
5552caa6c1 | ||
|
|
ad84704d28 | ||
|
|
08eddc9ed2 | ||
|
|
660afaf66d | ||
|
|
f9bc6eee6d | ||
|
|
5ef5dd8eaf | ||
|
|
a35b02dd18 | ||
|
|
04d25cd23d | ||
|
|
217ff24f1c | ||
|
|
40a884cc85 | ||
|
|
345408d5e7 | ||
|
|
090f149b31 | ||
|
|
f66eae5baf | ||
|
|
4219186ab0 | ||
|
|
7e6075a2e9 | ||
|
|
cd51aabe7e | ||
|
|
c5468a669b | ||
|
|
7b694938c6 | ||
|
|
71b0c7315a | ||
|
|
ec15950851 | ||
|
|
7d563f2cd6 | ||
|
|
6bdd245a83 | ||
|
|
316baf28d6 | ||
|
|
70da939a58 | ||
|
|
07754ff4e4 | ||
|
|
4159af1732 | ||
|
|
0143fa036c | ||
|
|
5227762aeb | ||
|
|
a4317bb6f1 | ||
|
|
9adf8c5630 | ||
|
|
8bb7f63c62 | ||
|
|
b8b3fd867b | ||
|
|
e92ec118fe | ||
|
|
4c4b53cd69 | ||
|
|
d7f226659c | ||
|
|
979e6ebea3 | ||
|
|
3a581163aa | ||
|
|
97c2153c2e | ||
|
|
27a15dd1b4 | ||
|
|
cf37d6c408 | ||
|
|
c9b8ec6805 | ||
|
|
31d88b634a | ||
|
|
5704f80929 | ||
|
|
652ef050ee | ||
|
|
8f35160b56 | ||
|
|
0e8fb1582d | ||
|
|
aa74770256 | ||
|
|
01ae6d44f0 | ||
|
|
ff14762426 | ||
|
|
419119725e | ||
|
|
b31784010c | ||
|
|
4049cfd2d0 | ||
|
|
c70054e83d | ||
|
|
9baab3777a | ||
|
|
3036b782f9 | ||
|
|
1fa3631e53 | ||
|
|
2df4e5cc9f |
No files matched your search
+336
-6
@@ -167,10 +167,10 @@ app.register.max-per-device-per-day
|
||||
| --- | --- | --- |
|
||||
| GET | `/app/home/feed` | 首页:轮播 + 分区,卡片带 `preview` 可播预览集与 `language` 语种 |
|
||||
| GET | `/app/discover/feed` | 发现页分区 |
|
||||
| GET | `/app/feed?types=ANIME,LIVE&cursor=&size=20` | 推荐流;按内容类型多选过滤,游标翻页 |
|
||||
| GET | `/app/feed?types=ANIME,LIVE&categoryId=7&cursor=&size=20` | 推荐流;支持内容类型与分类叠加过滤,游标翻页 |
|
||||
| GET | `/app/categories` | 分类列表 |
|
||||
| GET | `/app/dramas/{id}` | 详情(含剧集列表,免费集带**已签名**播放地址) |
|
||||
| GET | `/app/search?keyword=&pageIndex=&pageSize=` | 搜索已上线短剧:按标题/简介模糊匹配,分页返回卡片列表 |
|
||||
| GET | `/app/search?keyword=&pageIndex=&pageSize=` | **匿名**。搜索已上线短剧:按标题/简介模糊匹配,分页返回卡片列表 |
|
||||
|
||||
> 卡片(`AppDramaCardVO`)统一新增 `language` 字段(取值如 `zh-CN` / `id`),
|
||||
> 首页、发现页、分类、收藏、搜索等所有下发卡片的场景都带该字段,客户端可据此做语言筛选。
|
||||
@@ -188,7 +188,10 @@ app.register.max-per-device-per-day
|
||||
|
||||
- `types` 可选,逗号分隔,支持 `ANIME`、`LIVE` 或多选 `ANIME,LIVE`;不传或空值返回全部已上线内容。
|
||||
过滤按 `drama_types` 整词匹配,多标签剧可被多个类型同时命中。
|
||||
- `categoryId` 可选;不传返回全部分类。传入后按 `category_ids` 整词匹配,
|
||||
可与 `types` 叠加,只返回同时命中内容类型和分类的已上线短剧。
|
||||
- `cursor` 可选,上一页返回的 `nextCursor`;`size` 默认 20,最大 50。
|
||||
游标短剧必须同时满足已上线、内容类型命中和分类命中,否则返回空列表。
|
||||
- 排序:`recommend_weight DESC NULLS LAST, view_count DESC, id DESC`。
|
||||
- 返回 `Result<CursorResult<AppDramaCardVO>>`,卡片字段与首页一致,包含互动计数、`preview`、`language`、`dramaType`。
|
||||
|
||||
@@ -224,7 +227,8 @@ app.register.max-per-device-per-day
|
||||
"unlockCoin": 0,
|
||||
"likeCount": "45",
|
||||
"commentCount": "8",
|
||||
"playUrl": "/files/episode/202610/xxx.mp4?e=1760000000&s=9f2c..."
|
||||
"playUrl": "/files/episode/202610/xxx.mp4?e=1760000000&s=9f2c...",
|
||||
"thumbnailsUrl": "/files/transcoded/88/thumbnails/thumbnails.vtt?e=1760000000&s=8a1d..."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -241,6 +245,7 @@ app.register.max-per-device-per-day
|
||||
| `viewCount` | Long(JSON 字符串) | 取 `drama.view_count`,累计播放量,既有字段语义不变 |
|
||||
| `episodes[].likeCount` | Long(JSON 字符串) | 本集点赞数,取 `drama_episode.like_count` |
|
||||
| `episodes[].commentCount` | Long(JSON 字符串) | 本集未删除评论数,按 `episode_id` 统计 |
|
||||
| `episodes[].thumbnailsUrl` | String / null | 本集雪碧图 WebVTT 时间轴签名地址;没有 READY 产物时为 `null` |
|
||||
|
||||
计数是只读快照:互动操作完成后客户端重新拉取详情即可刷新;`Long` 字段一律按字符串下发,
|
||||
客户端需要转成数字再展示(与 `viewCount` 相同)。
|
||||
@@ -259,7 +264,12 @@ app.register.max-per-device-per-day
|
||||
"accessible": true,
|
||||
"accessType": "FREE",
|
||||
"playUrl": "/files/episode/202610/xxx.mp4?e=1760000000&s=9f2c...",
|
||||
"qualities": ["AUTO"],
|
||||
"qualities": ["AUTO", "720p", "1080p"],
|
||||
"tracks": [
|
||||
{"quality": "AUTO", "playUrl": "/files/transcoded/88/master.m3u8?e=1760000000&s=9f2c..."},
|
||||
{"quality": "720p", "playUrl": "/files/transcoded/88/720p/index.m3u8?e=1760000000&s=a1b2..."}
|
||||
],
|
||||
"thumbnailsUrl": "/files/transcoded/88/thumbnails/thumbnails.vtt?e=1760000000&s=8a1d...",
|
||||
"unlockCoin": 0,
|
||||
"previewSeconds": 0,
|
||||
"likeCount": "45",
|
||||
@@ -274,22 +284,105 @@ app.register.max-per-device-per-day
|
||||
**判定顺序由服务端决定,客户端不得自行推断可否播放。** 签名默认 15 分钟有效;
|
||||
开启 `fruitshorts.media.signature-required` 后,`/files/episode/**` 没带有效签名会返回 403。
|
||||
|
||||
`thumbnailsUrl` 指向 WebVTT:cue 链接为同目录相对雪碧图
|
||||
`sprite_XXX.jpg#xywh=x,y,w,h`。有 READY `media_thumbnail` 时返回签名地址,
|
||||
无产物时为 `null`;该字段不影响 `playUrl`、`qualities` 和 HLS/原文件回落。
|
||||
|
||||
### 1.5 观看记录与收藏(已实现)
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| POST | `/app/watch/progress` | 上报进度(建议每 10s 一次,切集时补一次) |
|
||||
| GET | `/app/watch/progress?dramaId=` | 某剧续看位置 |
|
||||
| GET | `/app/watch/recent?limit=20` | 最近观看 |
|
||||
| GET | `/app/watch/recent` | 最近观看分页;`pageIndex` 默认 1,`pageSize` 默认 20、上限 100 |
|
||||
| DELETE | `/app/watch/progress/{dramaId}` | 删除某剧记录 |
|
||||
| DELETE | `/app/watch/progress` | 清空记录 |
|
||||
| POST | `/app/favorites/toggle` | 收藏/取消收藏,返回切换后状态 |
|
||||
| GET | `/app/favorites` | 收藏列表(卡片结构与首页一致) |
|
||||
| GET | `/app/favorites` | 收藏分页;`pageIndex` 默认 1,`pageSize` 默认 20、上限 100 |
|
||||
| DELETE | `/app/favorites/{dramaId}` | 取消收藏 |
|
||||
| POST | `/app/favorites/remove` | 批量取消收藏,请求体 `{ "dramaIds": ["12", "15"] }` |
|
||||
|
||||
进度合并规则:同一集内只前进不后退;换集直接采纳新集;`finished` 只在接近片尾或客户端显式上报时置位。
|
||||
这样用户换设备不会看到进度倒退。
|
||||
|
||||
#### 收藏分页
|
||||
|
||||
`GET /app/favorites?pageIndex=1&pageSize=20`
|
||||
|
||||
请求参数:
|
||||
|
||||
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `pageIndex` | int | 否 | 1 | 页码,小于 1 按 1 处理 |
|
||||
| `pageSize` | int | 否 | 20 | 每页数量,上限 100,小于 1 按 1 处理 |
|
||||
|
||||
响应 `data` 为 `PageResult<AppDramaCardVO>`:
|
||||
|
||||
```json
|
||||
{
|
||||
"total": "23",
|
||||
"list": [
|
||||
{
|
||||
"id": "12",
|
||||
"title": "替嫁新娘:总裁的掌心宠",
|
||||
"cover": "/files/drama_cover/12.jpg",
|
||||
"preview": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
排序固定为收藏时间倒序 `created_at DESC`,收藏时间相同时按 `drama_id DESC`。
|
||||
仅统计和返回仍处于已上线状态的短剧。
|
||||
|
||||
#### 最近观看分页
|
||||
|
||||
`GET /app/watch/recent?pageIndex=1&pageSize=20`
|
||||
|
||||
请求参数:
|
||||
|
||||
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `pageIndex` | int | 否 | 1 | 页码,小于 1 按 1 处理 |
|
||||
| `pageSize` | int | 否 | 20 | 每页数量,上限 100,小于 1 按 1 处理 |
|
||||
|
||||
分页响应 `data` 为 `PageResult<ProgressRespVO>`:
|
||||
|
||||
```json
|
||||
{
|
||||
"total": "18",
|
||||
"list": [
|
||||
{
|
||||
"dramaId": "12",
|
||||
"episodeId": "88",
|
||||
"dramaTitle": "替嫁新娘:总裁的掌心宠",
|
||||
"dramaCover": "/files/drama_cover/12.jpg",
|
||||
"episodeNumber": 6,
|
||||
"totalEpisodes": 68,
|
||||
"viewCount": "1800",
|
||||
"positionMs": "80000",
|
||||
"durationMs": "120000",
|
||||
"finished": false,
|
||||
"playCount": 3,
|
||||
"updatedAt": "2026-10-22 10:00:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
排序固定为 `updated_at DESC, id DESC`。每页记录通过批量 IN 查询装配短剧和分集,
|
||||
不逐条访问数据库。越界页返回空 `list` 且 `total` 保持正确。
|
||||
|
||||
`ProgressRespVO` 展示字段:
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `dramaTitle` | string / null | 短剧标题 |
|
||||
| `dramaCover` | string / null | 短剧封面 |
|
||||
| `episodeNumber` | int / null | 当前续看集号 `ep_no` |
|
||||
| `totalEpisodes` | int / null | 短剧总集数 |
|
||||
| `viewCount` | Long(JSON 字符串)/ null | 短剧热度,取 `drama.view_count`。`playCount` 是用户自己的播放次数 |
|
||||
|
||||
### 1.6 离线下载(已实现)
|
||||
|
||||
服务端只发**授权**与**短时效地址**,分片由客户端直接向 CDN 拉取 ——
|
||||
@@ -457,6 +550,17 @@ GET /app/notices?pageIndex=1&pageSize=20
|
||||
`expire_at` 为空或未过期的公告;按 `publish_at desc, id desc` 排序。
|
||||
**表里没有数据时返回 `total=0, list=[]`(HTTP 与 code 都是成功),不是 404。**
|
||||
|
||||
#### 1.9.2a 协议公开页(匿名 HTML)
|
||||
|
||||
客户端按当前界面语言打开,不走 `{code,message,data}` 包装。正文在后台「协议设置」用 Markdown 维护,页面不另加标题。
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| GET | `/privacy/{lang}` | 隐私协议。`lang` 为 `zh` / `en` / `id` |
|
||||
| GET | `/terms/{lang}` | 服务条款。语言同上 |
|
||||
|
||||
响应 `Content-Type: text/html;charset=UTF-8`。语言或路径不在上表时 HTTP 404。库里还没有该语言时返回内置缺省文案,不返回空页。
|
||||
|
||||
#### 1.9.3 `POST /app/creator/apply`(登录)
|
||||
|
||||
```json
|
||||
@@ -518,6 +622,8 @@ GET /app/notices?pageIndex=1&pageSize=20
|
||||
| 角色分类 | PUT · DELETE | `/admin/role-categories/{id}` | `system:role-category` |
|
||||
| 系统配置 | GET | `/admin/configs` | `system:role` / `system:menu` |
|
||||
| 系统配置 | PUT | `/admin/configs` | `system:role` |
|
||||
| 协议 | GET | `/admin/legal-documents` | `system:role` / `system:menu` |
|
||||
| 协议 | PUT | `/admin/legal-documents` | `system:role` |
|
||||
| 操作日志 | GET | `/admin/operation-logs/page` · `/{id}` | `log:list` |
|
||||
| 字典 | GET | `/admin/dicts/drama-category` · `/content-status` | `drama:list` |
|
||||
|
||||
@@ -594,6 +700,42 @@ GET /app/notices?pageIndex=1&pageSize=20
|
||||
**上传会话归属**:`uploadId` 相当于上传凭证,`chunk` / `complete` / 进度查询都校验会话发起人,
|
||||
别人拿到 `uploadId` 也塞不进分片(`{"code":403,"message":"无权操作该上传会话"}`)。
|
||||
|
||||
**转码档位配置**
|
||||
|
||||
| 方法 | 路径 | 权限点 | 说明 |
|
||||
| --- | --- | --- | --- |
|
||||
| GET | `/admin/media/transcode-profile` | `episode:upload` | 读取当前配置;缺省返回四档默认值 |
|
||||
| PUT | `/admin/media/transcode-profile` | `episode:upload` | 保存配置并记录操作日志 |
|
||||
|
||||
配置保存在 `sys_config` 的 `media.transcode.profile`,JSON 结构:
|
||||
|
||||
```json
|
||||
{
|
||||
"enabled": true,
|
||||
"segmentSeconds": 6,
|
||||
"ladder": [
|
||||
{
|
||||
"quality": "360p",
|
||||
"width": 640,
|
||||
"height": 360,
|
||||
"videoBitrateKbps": 400,
|
||||
"audioBitrateKbps": 64,
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"sprite": {
|
||||
"enabled": true,
|
||||
"intervalSeconds": 1,
|
||||
"columns": 10,
|
||||
"thumbWidth": 160
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`quality` 必须唯一且非空,宽高必须为大于 0 的偶数,音视频码率必须大于 0,
|
||||
至少启用一档;`segmentSeconds` 2–10、`intervalSeconds` 1–10、`columns` 5–20、
|
||||
`thumbWidth` 120–240。非法请求返回统一错误码 `400` 且不写库。
|
||||
|
||||
### 2.3 App 用户管理(已实现)
|
||||
|
||||
| 方法 | 路径 | 权限点 | 说明 |
|
||||
@@ -952,6 +1094,194 @@ GET /app/notices?pageIndex=1&pageSize=20
|
||||
**筛选与错误码**:`title` 必填(1–128);`content` 最长 2000;公告不存在 → `200002 公告不存在`;
|
||||
`status` 只接受 0/1,其他值 → `400`。
|
||||
|
||||
### 2.13 运营分类管理(已实现)
|
||||
|
||||
> 「分类」是运营自定义的分组,与短剧**类型**(`/admin/drama-categories`,写 `drama_category`)是两套独立概念。
|
||||
> 分类存在 `drama_classification`,通过 `drama_classification_drama` 关联任意多部短剧。
|
||||
> 后台页面:菜单 **分类管理**(`/content/category-dramas` → `CategoryDramaView.vue`)。
|
||||
|
||||
**接口清单**(前缀 `/admin/drama-classifications`)
|
||||
|
||||
| 方法 | 路径 | 权限点 | 说明 |
|
||||
| --- | --- | --- | --- |
|
||||
| GET | `/admin/drama-classifications` | `drama:list` | 分类列表(带关联短剧数量) |
|
||||
| POST | `/admin/drama-classifications` | `drama:create` | 新建分类,返回新分类 id |
|
||||
| PUT | `/admin/drama-classifications/{id}` | `drama:update` | 编辑分类 |
|
||||
| DELETE | `/admin/drama-classifications/{id}` | `drama:delete` | 删除分类(级联删关联,短剧本身保留) |
|
||||
| GET | `/admin/drama-classifications/{id}/dramas` | `drama:list` | 分类下已关联的短剧(分页) |
|
||||
| GET | `/admin/drama-classifications/{id}/dramas/candidates` | `drama:list` | 尚未关联到该分类的短剧(分页,供多选) |
|
||||
| POST | `/admin/drama-classifications/{id}/dramas` | `drama:update` | 批量关联短剧,返回实际新增数量 |
|
||||
| DELETE | `/admin/drama-classifications/{id}/dramas/{dramaId}` | `drama:update` | 从分类移出短剧(幂等) |
|
||||
|
||||
**列表响应**
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
"data": [
|
||||
{
|
||||
"id": "2112807182243336193",
|
||||
"name": "本周必看",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"dramaCount": 12,
|
||||
"updatedAt": "2026-10-22T19:41:02"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
排序规则固定为 `sort asc, id desc`;`dramaCount` 是关联表按分类聚合的实时数量。
|
||||
时间字段为 `LocalDateTime` 的 ISO 字符串(`yyyy-MM-ddTHH:mm:ss`,秒级),前端按需替换 `T` 为空格。
|
||||
|
||||
**新建 / 编辑请求体**
|
||||
|
||||
```json
|
||||
{ "name": "本周必看", "sort": 1, "status": 1 }
|
||||
```
|
||||
|
||||
| 字段 | 必填 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `name` | 是 | 去首尾空格后保存,全局唯一;`@NotBlank` 提示「请填写分类名称」 |
|
||||
| `sort` | 否 | 新建不传时取 `现有条数 + 1`;编辑不传(null)时保持原值 |
|
||||
| `status` | 否 | `1` 启用 / `0` 停用;新建默认 `1`,编辑不传保持原值 |
|
||||
|
||||
**关联短剧**
|
||||
|
||||
```json
|
||||
POST /admin/drama-classifications/2112807182243336193/dramas
|
||||
{ "dramaIds": ["2112807182243336194", "2112807182243336195"] }
|
||||
```
|
||||
|
||||
返回 `data` 为实际新增条数(整数)。已关联的、以及不存在的 `dramaId` 会被静默跳过,不报错;
|
||||
全部跳过时返回 `0`。`dramaIds` 为空数组 → `400 请选择短剧`。
|
||||
|
||||
**短剧列表项(`GET /{id}/dramas` 与 `/dramas/candidates` 共用)**
|
||||
|
||||
```json
|
||||
{
|
||||
"total": 12,
|
||||
"list": [
|
||||
{
|
||||
"id": "2112807182243336194",
|
||||
"title": "闪婚后首富老公竟是我老板",
|
||||
"cover": "https://.../cover.jpg",
|
||||
"status": "published",
|
||||
"totalEpisodes": 80,
|
||||
"sort": 100,
|
||||
"updatedAt": "2026-10-22T18:00:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- 查询参数:`keyword`(按 `title` 模糊匹配,可空)、`pageIndex`(默认 1)、`pageSize`(默认 10,上限 100)
|
||||
- 排序:`sort desc, id desc`
|
||||
- `status` 取值:`draft` 草稿 / `reviewing` 审核中 / `approved` 待发布 / `published` 已上线 / `offline` 已下线
|
||||
- `cover` 取自短剧 `cover_url`
|
||||
|
||||
**错误码**
|
||||
|
||||
| 场景 | 返回 |
|
||||
| --- | --- |
|
||||
| 分类名称重复(新建或改名撞已有) | `200001 分类名称已存在` |
|
||||
| 分类 id 不存在(编辑/删除/查询/关联/移出) | `200002 分类不存在` |
|
||||
| `name` 为空 | `400 请填写分类名称` |
|
||||
| `dramaIds` 为空 | `400 请选择短剧` |
|
||||
|
||||
> 所有写操作带 `@OperationLog(module = "内容管理")` 操作日志。ID 下发口径见 **§0**。
|
||||
|
||||
### 2.14 剧单管理(已实现)
|
||||
|
||||
> 剧单使用**自己的一套分类**(`drama_playlist_category`),与「分类管理」和「类型」都没有关系。
|
||||
> **没有「剧单」这一层实体**:分类直接挂短剧,关联表 `drama_playlist_category_drama(category_id, drama_id)`。
|
||||
> 后台页面:菜单 **剧单管理**(`/content/drama-playlists` → `DramaPlaylistView.vue`)。
|
||||
|
||||
**接口清单**(前缀 `/admin/drama-playlist-categories`)
|
||||
|
||||
| 方法 | 路径 | 权限点 | 说明 |
|
||||
| --- | --- | --- | --- |
|
||||
| GET | `/admin/drama-playlist-categories` | `drama:list` | 剧单分类列表(带短剧数量) |
|
||||
| POST | `/admin/drama-playlist-categories` | `drama:create` | 新建剧单分类,返回新分类 id |
|
||||
| PUT | `/admin/drama-playlist-categories/{id}` | `drama:update` | 编辑剧单分类 |
|
||||
| DELETE | `/admin/drama-playlist-categories/{id}` | `drama:delete` | 删除剧单分类(级联删关联,短剧本身保留) |
|
||||
| GET | `/admin/drama-playlist-categories/{id}/dramas` | `drama:list` | 分类下已关联的短剧(分页) |
|
||||
| GET | `/admin/drama-playlist-categories/{id}/dramas/candidates` | `drama:list` | 尚未关联到该分类的短剧(分页,供多选) |
|
||||
| POST | `/admin/drama-playlist-categories/{id}/dramas` | `drama:update` | 批量把短剧加入分类,返回实际新增数量 |
|
||||
| DELETE | `/admin/drama-playlist-categories/{id}/dramas/{dramaId}` | `drama:update` | 从分类移出短剧(幂等) |
|
||||
|
||||
**列表响应**
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
"data": [
|
||||
{
|
||||
"id": "2112807182243336196",
|
||||
"name": "高甜先婚后爱",
|
||||
"description": "站内投放位使用,按周更新",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"dramaCount": 8
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
排序规则 `sort asc, id desc`;`dramaCount` 为该分类下已关联短剧数量。
|
||||
|
||||
**新建 / 编辑请求体**
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "高甜先婚后爱",
|
||||
"description": "站内投放位使用,按周更新",
|
||||
"sort": 1,
|
||||
"status": 1
|
||||
}
|
||||
```
|
||||
|
||||
| 字段 | 必填 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `name` | 是 | 去首尾空格后保存,全局唯一;`@NotBlank` 提示「请填写剧单分类名称」 |
|
||||
| `description` | 否 | 最长 255 字符(超长 → `400 描述最多 255 个字符`);新建不传存空串,编辑不传保持原值 |
|
||||
| `sort` | 否 | 新建不传取 `现有条数 + 1`;编辑不传保持原值 |
|
||||
| `status` | 否 | `1` 启用 / `0` 停用;新建默认 `1` |
|
||||
|
||||
**关联短剧**
|
||||
|
||||
```json
|
||||
POST /admin/drama-playlist-categories/2112807182243336196/dramas
|
||||
{ "dramaIds": ["2112807182243336194"] }
|
||||
```
|
||||
|
||||
返回实际新增条数;已关联或不存在的短剧自动跳过;`dramaIds` 为空 → `400 请选择短剧`。
|
||||
`GET /{id}/dramas` 与 `GET /{id}/dramas/candidates` 的查询参数和响应结构与 **§2.13** 完全一致
|
||||
(`keyword` / `pageIndex` / `pageSize`,响应 `{ total, list }`,列表项含
|
||||
`id` / `title` / `cover` / `status` / `totalEpisodes` / `sort` / `updatedAt`)。
|
||||
|
||||
**错误码**
|
||||
|
||||
| 场景 | 返回 |
|
||||
| --- | --- |
|
||||
| 剧单分类名称重复 | `200001 剧单分类名称已存在` |
|
||||
| 剧单分类 id 不存在 | `200002 剧单分类不存在` |
|
||||
| `name` 为空 | `400 请填写剧单分类名称` |
|
||||
| `description` 超过 255 | `400 描述最多 255 个字符` |
|
||||
| `dramaIds` 为空 | `400 请选择短剧` |
|
||||
|
||||
**与「分类管理」的差异**
|
||||
|
||||
| 项 | 运营分类(2.13) | 剧单分类(2.14) |
|
||||
| --- | --- | --- |
|
||||
| 数据表 | `drama_classification` + `drama_classification_drama` | `drama_playlist_category` + `drama_playlist_category_drama` |
|
||||
| 描述字段 | 无 | 有(`description`,≤255) |
|
||||
| 列表返回 | 含 `updatedAt` | 含 `description`,不含 `updatedAt` |
|
||||
| 菜单 | 分类管理(`/content/category-dramas`) | 剧单管理(`/content/drama-playlists`) |
|
||||
| 用途 | 内容侧分组 | 运营侧投放/剧单位分组 |
|
||||
|
||||
## 3. 契约与实现状态对照
|
||||
|
||||
> 最后更新:2026-10-16(`develop` 分支)。未完成项汇总见仓库根 `README.md`「尚未完成」。
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# K100 后台剧集多选上传(分片 + 断点续传 + 批量建集)
|
||||
|
||||
> 日期:2026-10-21
|
||||
> 范围:仅 `ReelShortWeb`;不改 FruitServer 后端、不改 ReelShort 客户端、不改接口契约。
|
||||
|
||||
## 目标
|
||||
|
||||
剧集管理页「批量上传」:多选视频 → 队列分片上传(文件并发 2 / 分片并发 3)→ 单项与字节加权总进度 → 失败隔离/可重试 → localStorage 断点续传 → 上传完成后批量创建分集。
|
||||
|
||||
## 步骤
|
||||
|
||||
1. 从 `develop` 拉 `feature/episode-batch-upload`。
|
||||
2. 新建 `src/views/contentManagement/upload/uploadSessions.ts`:`reel_upload_sessions` 读写/过滤/清理。
|
||||
3. 新建 `useUploadQueue.ts`:状态机、文件并发泵、进度加权、pause/retry/remove、complete 写回 assetId/url、挂接 session。
|
||||
4. 新建 `UploadTaskRow.vue` / `BatchUploadDialog.vue` / `CreateEpisodesDialog.vue`。
|
||||
5. `EpisodeManagementView.vue` 仅加「批量上传」入口,保留原单文件上传。
|
||||
6. `zh-CN.ts` / `en.ts` 补齐文案;白名单 mp4/mov/mkv/webm;超限标红不入队;`beforeunload`。
|
||||
7. 门禁:`pnpm lint:eslint` + `pnpm build:dev`。
|
||||
8. 提交 `feat(admin): 剧集多选分片上传与断点续传` → `--no-ff` 合回 `develop` 并 push。
|
||||
|
||||
## 风险 / 待确认
|
||||
|
||||
- 续传需用户重新选择本地文件才能匹配;换机器/改名无法自动续传(产品已接受)。
|
||||
- 暂停不 abort 进行中分片,已在传任务会跑完再停派发。
|
||||
- `EpisodeManagementView.vue` 存量已超 500 行,本轮只加入口,不整体拆旧编辑器。
|
||||
- 手工联调(多选/暂停/刷新续传/建集)由 PM 在 8080+3005 复核,本轮不操作真机、不 kill 已运行端口。
|
||||
@@ -0,0 +1,126 @@
|
||||
# K94 首页内容类型 Feed 与无感切换
|
||||
|
||||
## 目标
|
||||
|
||||
- 首页顶栏「漫剧 / 真人剧 / 推荐」接入既有 `/app/feed`。
|
||||
- 每频道独立缓存与分页,切换时先同步展示缓存,再后台静默刷新。
|
||||
- 推荐首屏复用 `/app/home/feed` 打平数据,首次进入不额外转圈。
|
||||
- 无缓存频道只在黑色内容区显示小转圈,顶栏和底栏保持。
|
||||
- 滑动接近末尾自动加载下一页,并在播放器队列中原地追加。
|
||||
|
||||
## 分支
|
||||
|
||||
- ReelShort:`feat/k94-home-type-feed`,从 `origin/develop` 创建。
|
||||
- FruitServer 仅文档留痕,不改功能代码。
|
||||
|
||||
## A. 数据层
|
||||
|
||||
### A1 FeedPage
|
||||
|
||||
新增 `lib/core/data/models/feed_page.dart`:
|
||||
|
||||
- `dramas` 使用 `Drama.fromCardJson`。
|
||||
- `nextCursor` 兼容数字/字符串,空值或字符串 `"null"` 转为 null。
|
||||
- `hasMore` 读取布尔值。
|
||||
|
||||
### A2 CatalogApi / Repository
|
||||
|
||||
- `CatalogApi.feed({types, cursor, size})` 请求 `/app/feed`。
|
||||
- types 为空不传;非空用逗号拼接。
|
||||
- cursor 为空不传。
|
||||
- 返回结构异常抛 `ApiException(-1, '返回数据格式异常')`。
|
||||
- `CatalogRepository` 与 HTTP 实现增加 `fetchFeed`。
|
||||
- 所有测试 CatalogRepository 实现同步补齐方法。
|
||||
|
||||
## B. 频道控制器
|
||||
|
||||
新增:
|
||||
|
||||
- `lib/pages/home/home_feed_channel.dart`
|
||||
- `lib/core/data/services/home_feed_controller.dart`
|
||||
|
||||
`HomeFeedController` 使用每个频道独立状态:
|
||||
|
||||
- dramas / cursor / hasMore / loaded / loadingMore / requestSeq
|
||||
- 当前 channel,默认 recommend
|
||||
- `seedRecommend`:同步写入推荐首屏,不发请求
|
||||
- `selectChannel`:同步切频道并 notify;无缓存加载第一页,有缓存静默刷新
|
||||
- `refreshCurrent`:失败保留旧列表
|
||||
- `loadMore`:cursor 追加,按 drama.id 去重
|
||||
- 所有响应必须同时满足“仍为当前频道 + requestSeq 最新”才应用
|
||||
- dispose 后停止 notify
|
||||
|
||||
## C. 首页接入
|
||||
|
||||
### C1 顶栏受控
|
||||
|
||||
`HomeFeedHeader`:
|
||||
|
||||
- 删除内部 tab 状态、comingSoon 和 SnackBar。
|
||||
- 新增 `channel` 与 `onChannelSelected`。
|
||||
- 三个 Key 保持不变。
|
||||
- refresh 内部 loading 状态保留。
|
||||
|
||||
### C2 HomePage
|
||||
|
||||
- `_HomePageState` 用 `CatalogController.repository` 创建 HomeFeedController。
|
||||
- Catalog 首次有数据时同步 seed recommend,随后在 post-frame 静默刷新 recommend。
|
||||
- `_HomeTabs` 使用稳定 Key,删除 `ValueKey(catalog.dramas.first.id)`。
|
||||
- 当前频道无数据时,保留 `_HomeTabs` 顶栏/底栏,body 用黑色背景 + 居中
|
||||
`home-feed-channel-loading`。
|
||||
- 当前频道有数据时把频道列表传给 PlayerPage。
|
||||
- 刷新回调改 `refreshCurrent`;分页回调改 `loadMore`。
|
||||
|
||||
### C3 PlayerPage / PlayerLogic
|
||||
|
||||
- PlayerPage 增加 `feedChannel` 和 `onLoadMore`。
|
||||
- 同频道 feed 列表变化:`updateFeed(..., keepDramaId: currentDramaId)`。
|
||||
- channel 变化:`updateFeed(..., keepDramaId: null)`,回到新频道第 1 个。
|
||||
- PlayerLogic 保存 factory/coordinator,支持需要换内容时替换 PlaybackSession。
|
||||
- 空列表清空 queue/visibleIndices 并停止旧播放。
|
||||
- 当前剧仍在新列表且索引不变时,只扩展队列与 episode 列表,不重新 select。
|
||||
- PageView 在 `position >= visibleIndices.length - 3` 时调用 onLoadMore。
|
||||
|
||||
## D. 测试
|
||||
|
||||
新增 `test/core/data/services/home_feed_controller_test.dart`:
|
||||
|
||||
- recommendation seed 不发请求
|
||||
- 三频道请求 types 分别为 `[] / [ANIME] / [LIVE]`
|
||||
- 缓存频道切换不清空并后台刷新
|
||||
- loadMore 追加去重、无更多后不再请求
|
||||
- 串包只接受最新频道请求
|
||||
- refresh 失败保留旧数据
|
||||
|
||||
新增顶栏 widget 测试:
|
||||
|
||||
- 三个 Key 存在
|
||||
- 点击分别回调 anime/live/recommend
|
||||
- 当前 channel 决定选中样式
|
||||
|
||||
PlayerLogic 测试补充:
|
||||
|
||||
- updateFeed 空列表安全
|
||||
- 追加列表保持当前剧
|
||||
- 切频道列表回到第 1 个
|
||||
|
||||
门禁:
|
||||
|
||||
- `dart analyze lib test`
|
||||
- `flutter test --no-pub`
|
||||
- `flutter build apk --debug`
|
||||
|
||||
## 风险与控制
|
||||
|
||||
1. PlaybackSession 的 episodes 是构造时绑定的列表;分页原地追加时会同步扩展该列表,
|
||||
避免仅换 queue 而 session 仍指向旧列表。
|
||||
2. 换频道可能释放并重建播放器 session,这是内容源变化;静默刷新/分页在顺序不变时
|
||||
不重新 select 当前剧,避免视频重启。
|
||||
3. 推荐 seed 只保证首帧立即有内容;后台 `/app/feed` 刷新失败时保留 seed。
|
||||
4. 首页仍在 `/app/home/feed` 首次加载期间使用既有启动页;频道切换不再触发整页 splash。
|
||||
|
||||
## Git
|
||||
|
||||
- 提交:`feat(home): 首页按内容类型分频道 Feed 并支持分页`
|
||||
- `--no-ff` 合回 ReelShort `develop` 并 push。
|
||||
- 作者:`Zhou Weidong <502333560@qq.com>`;禁止 `git add -A`。
|
||||
@@ -0,0 +1,100 @@
|
||||
# K95 修复首页频道快速切换卡 Loading
|
||||
|
||||
## 目标
|
||||
|
||||
- 频道请求完成后始终写回发起请求的频道缓存,不再因用户切走而丢失结果。
|
||||
- 每频道明确区分 loaded / loading / in-flight / error,无请求时绝不显示首屏转圈。
|
||||
- 首屏和刷新请求增加可注入的 10 秒超时兜底。
|
||||
- PlayerLogic 保证连续 feed 更新串行应用,只让最后一次 feed/session 生效。
|
||||
|
||||
## 分支
|
||||
|
||||
- ReelShort:`fix/k95-feed-switch-loading`,从 `origin/develop` 创建。
|
||||
- FruitServer 仅提交计划与 PROGRESS,不改功能代码。
|
||||
|
||||
## A. HomeFeedController
|
||||
|
||||
每个频道状态增加:
|
||||
|
||||
- `List<Drama> dramas`
|
||||
- `String? cursor`
|
||||
- `bool hasMore`
|
||||
- `bool loaded`
|
||||
- `bool loading`
|
||||
- `bool loadingMore`
|
||||
- `String? lastError`
|
||||
- `int requestSeq`
|
||||
- `Future<bool>? inFlight`
|
||||
|
||||
请求规则:
|
||||
|
||||
1. 响应成功/失败都写入发起请求的频道状态。
|
||||
2. 只有频道仍为当前频道时才 `notifyListeners`。
|
||||
3. `requestSeq` 只比较同一频道的新旧请求,不参与跨频道过滤。
|
||||
4. 超时时间通过构造参数注入,默认 10 秒。
|
||||
5. `loadingFirstPage = !loaded && loading`。
|
||||
6. `selectChannel`:
|
||||
- 有缓存:同步显示,未在飞时后台静默刷新
|
||||
- 无缓存且正在飞:等待现有请求,不重复发
|
||||
- 无缓存且有历史错误:自动重试
|
||||
- 从未加载:发起首屏请求
|
||||
7. `refreshCurrent` 同样复用 in-flight,防止并发重复刷新。
|
||||
8. `loadMore` 失败保留 cursor/hasMore,允许下次继续重试。
|
||||
|
||||
## B. PlayerLogic / PlayerPage
|
||||
|
||||
### B1 Feed revision
|
||||
|
||||
- PlayerLogic 增加 `int feedRevision`。
|
||||
- 每次 `updateFeed` 自增 revision,记录最新目标 feed。
|
||||
- `_replaceSession` 与 `selectEpisode` 在 await 后校验 revision,过期流程直接返回。
|
||||
- 连续 updateFeed 使用串行队列:当前应用结束后再应用最新待处理 feed。
|
||||
|
||||
### B2 空队列与频道切换
|
||||
|
||||
- 空 feed 不创建新 session,只清空 queue/visibleIndices 并停播。
|
||||
- 空 → 非空必须恢复 route visible,并 select 第 0 个。
|
||||
- 频道变化通过额外 reset 标志传入 `updateFeed`,即使 drama id 列表相同,
|
||||
也重置到第 1 个并开始播放。
|
||||
|
||||
### B3 PlayerPage 更新判定
|
||||
|
||||
- `didUpdateWidget` 用 `feedDramas` 的 drama id 列表签名判断内容变化。
|
||||
- 同一列表的新 List 实例不重复 updateFeed。
|
||||
- 频道变化始终触发 updateFeed,并传 `resetToFirst=true`。
|
||||
|
||||
## C. 测试
|
||||
|
||||
### HomeFeedController
|
||||
|
||||
- A 挂起 → B 成功 → A 成功:A/B loaded 均为 true,切回 A 立即有数据。
|
||||
- 同频道旧失败响应不得覆盖新成功响应。
|
||||
- 无在飞请求时 `loadingFirstPage=false`。
|
||||
- 永不返回的请求在注入超时后结束 loading、写 lastError、loaded=true。
|
||||
- 失败频道再次 select 自动重试。
|
||||
- loadMore 失败保留原有 hasMore/cursor。
|
||||
|
||||
### PlayerLogic
|
||||
|
||||
- 连续 5 次 updateFeed,最终 queue/session 对应最后一次列表。
|
||||
- 空 → 非空会创建 session 并 select 第 0 个。
|
||||
- 频道变化时相同 id 列表也回到第 1 个。
|
||||
|
||||
门禁:
|
||||
|
||||
- `dart analyze lib test`
|
||||
- `flutter test --no-pub`
|
||||
- `flutter build apk --debug`
|
||||
|
||||
## 风险与控制
|
||||
|
||||
1. 跨频道响应写回缓存必须与同频道 seq 校验同时存在;前者解决缓存丢失,后者解决同频道旧请求覆盖新结果。
|
||||
2. Player session 替换以 revision 作为唯一有效性判断,避免旧 close/select 回调干扰新 session。
|
||||
3. 空队列期间不创建 PlaybackSession;恢复非空时重新创建并起播。
|
||||
4. 不改后端、ReelShortWeb、specs;不安装或操作真机。
|
||||
|
||||
## Git
|
||||
|
||||
- 提交:`fix(home): 修复频道快速切换卡 loading`
|
||||
- `--no-ff` 合回 ReelShort `develop` 并 push。
|
||||
- 作者:`Zhou Weidong <502333560@qq.com>`;禁止 `git add -A`。
|
||||
@@ -0,0 +1,83 @@
|
||||
# K95.1 首次切换频道无感显示
|
||||
|
||||
## 目标
|
||||
|
||||
- 推荐首屏成功后后台预取 anime/live,避免第一次切换出现阻断式 loading。
|
||||
- 目标频道尚未返回时保留上一频道 PlayerPage 和视频画面,只叠加轻量 loading 遮罩。
|
||||
- 数据到达后原子替换为新频道 feed,并从第 1 个播放。
|
||||
|
||||
## 分支
|
||||
|
||||
- ReelShort:`fix/k95.1-seamless-first-switch`,从已包含 K95 的 `origin/develop` 创建。
|
||||
- FruitServer 仅文档留痕,不改功能代码。
|
||||
|
||||
## A. HomeFeedController
|
||||
|
||||
新增 `Future<void> prefetchChannels()`:
|
||||
|
||||
- 仅处理 anime/live。
|
||||
- 只对 `!loaded && !loading` 的频道请求。
|
||||
- 请求结果写回对应频道缓存。
|
||||
- 不切换当前频道、不改变当前列表;仅目标恰为当前频道时 notify。
|
||||
- 失败只写 lastError,不向外抛。
|
||||
- 成功预取设置一次性 `skipNextRefresh`:首次切到该频道直接使用缓存,不立刻重复静默刷新;
|
||||
后续再次切回仍执行正常缓存静默刷新。
|
||||
- 预取期间用户切换到该频道时等待已有 inFlight,不重复请求。
|
||||
|
||||
## B. HomePage / _HomeTabs
|
||||
|
||||
### B1 最近可见 feed
|
||||
|
||||
`_HomeTabsState` 维护:
|
||||
|
||||
- `List<Drama>? _visibleDramas`
|
||||
- `HomeFeedChannel? _visibleChannel`
|
||||
|
||||
当前频道有数据时更新这两个值,并以当前频道渲染 PlayerPage。
|
||||
|
||||
### B2 首次切换
|
||||
|
||||
当前频道无数据且 loading:
|
||||
|
||||
- 继续复用上一频道 `_visibleDramas/_visibleChannel` 渲染同一个 PlayerPage。
|
||||
- header 使用当前选中频道,但 PlayerPage.feedChannel 仍使用可见旧频道,避免队列更新。
|
||||
- Stack 上叠加 `IgnorePointer + ColoredBox(black26) + 24px spinner`,
|
||||
Key 为 `home-feed-channel-loading`。
|
||||
- 数据返回后页面树保持同一层级的 PlayerPage,传入新 feed/channel,触发原子更新和第 1 个起播。
|
||||
- 空结果/失败后才切到「暂无剧目 / 重试」占位。
|
||||
|
||||
### B3 Prefetch 触发
|
||||
|
||||
推荐首屏后台刷新成功后 `unawaited(prefetchChannels())`。
|
||||
|
||||
## C. 测试
|
||||
|
||||
HomeFeedController:
|
||||
|
||||
- prefetch 后首次 select anime 不再发请求。
|
||||
- prefetch 期间选择 anime 不重复请求。
|
||||
- prefetch 失败不影响推荐,也不向外抛。
|
||||
|
||||
Widget:
|
||||
|
||||
- 首切未缓存频道时 PlayerPage 仍在树中且出现 loading 遮罩。
|
||||
- 数据返回后遮罩消失并使用新频道 feed。
|
||||
|
||||
门禁:
|
||||
|
||||
- `dart analyze lib test`
|
||||
- `flutter test --no-pub`
|
||||
- `flutter build apk --debug`
|
||||
|
||||
## 风险与控制
|
||||
|
||||
1. 预取完成与 select 同时发生时,select 等待同一 inFlight,避免重复请求。
|
||||
2. 加载遮罩 IgnorePointer,不阻断顶栏/底栏交互。
|
||||
3. PlayerPage 在正常和 loading 状态都放在相同 Stack 层级,保证 State 不因分支切换被销毁。
|
||||
4. 不改后端、ReelShortWeb、specs;不安装或操作真机。
|
||||
|
||||
## Git
|
||||
|
||||
- 提交:`fix(home): 首切频道预取并保留播放画面`
|
||||
- `--no-ff` 合回 ReelShort `develop` 并 push。
|
||||
- 作者:`Zhou Weidong <502333560@qq.com>`;禁止 `git add -A`。
|
||||
@@ -0,0 +1,54 @@
|
||||
# K95.2 首切频道用封面过渡
|
||||
|
||||
## 目标
|
||||
|
||||
- 首页频道切换后立即显示目标短剧封面,视频首帧就绪后再淡入。
|
||||
- 首页模式视频初始化期间不再显示 `player-session-loading` 大转圈。
|
||||
- 非首页播放器及票据加载状态保持现有行为。
|
||||
|
||||
## 分支
|
||||
|
||||
- ReelShort:`fix/k95.2-poster-transition`,从最新 `origin/develop` 创建。
|
||||
- FruitServer 仅写计划与 PROGRESS 留痕,不改后端功能代码。
|
||||
|
||||
## A. PlayerVideoSurface
|
||||
|
||||
- 新增可选参数 `posterUrl = ''`。
|
||||
- 未 reveal 时:
|
||||
- `posterUrl` 非空显示 `RemoteImage(path: posterUrl, fit: BoxFit.cover)`,
|
||||
Key 为 `player-video-poster`。
|
||||
- `posterUrl` 为空继续显示黑色 `ColoredBox`,保留
|
||||
`player-fallback-background` Key。
|
||||
- 视频 reveal 后继续通过现有 200ms `AnimatedOpacity` 淡入覆盖封面。
|
||||
|
||||
## B. PlayerPage
|
||||
|
||||
- `PlayerVideoSurface` 传入当前 `drama.posterUrl`。
|
||||
- `player-session-loading` 条件增加 `!widget.homeMode`:
|
||||
- 首页模式视频初始化期间只显示封面。
|
||||
- 非首页播放器继续显示原 session loading。
|
||||
- 首页 `player-ticket-loading` 不变。
|
||||
|
||||
## C. 测试
|
||||
|
||||
- 视频表面:非空 poster 显示 `player-video-poster`,空 poster 保留黑底且无封面。
|
||||
- 首页模式:视频未就绪时不出现 `player-session-loading`。
|
||||
- 非首页模式:视频未就绪时仍出现 `player-session-loading`。
|
||||
- 复跑既有播放器、首页相关测试。
|
||||
|
||||
## 门禁
|
||||
|
||||
- `dart analyze lib test`
|
||||
- `flutter test`
|
||||
- `flutter build apk --debug`
|
||||
|
||||
## Git
|
||||
|
||||
- ReelShort 提交:`fix(home): 频道切换用封面过渡`
|
||||
- `--no-ff` 合回 `develop` 并 push。
|
||||
- 作者 `Zhou Weidong <502333560@qq.com>`;禁止 `git add -A`。
|
||||
|
||||
## 约束
|
||||
|
||||
- 全程中文;不改后端、ReelShortWeb、specs。
|
||||
- 不安装或操作真机;完成后停住等待验收。
|
||||
@@ -0,0 +1,86 @@
|
||||
# K96 剧场页服务端分类分页
|
||||
|
||||
## 目标
|
||||
|
||||
- `/app/feed` 支持按分类过滤,并与内容类型过滤叠加。
|
||||
- 剧场页「全部」展示全部已上线短剧,任意分类展示该分类全部已上线短剧。
|
||||
- 列表使用游标分页,切分类优先命中缓存,支持静默刷新、加载更多和失败重试。
|
||||
|
||||
## 分支
|
||||
|
||||
- FruitServer:`feat/k96-feed-category`
|
||||
- ReelShort:`feat/k96-theater-feed`
|
||||
|
||||
## A. FruitServer
|
||||
|
||||
1. `AppCatalogController.feed` 增加可选 `Long categoryId` 并传给服务层。
|
||||
2. `AppCatalogService.feed` 增加 `categoryId`,传给
|
||||
`DramaService.listPublishedFeed`。
|
||||
3. `DramaService.listPublishedFeed` 增加 `categoryId`:
|
||||
- 非空时使用 `DramaMultiTagSupport.applyCategoryIdTokens`
|
||||
按 `category_ids` 整词匹配。
|
||||
- 游标 marker 必须同时满足已上线、内容类型命中和分类命中,否则返回空列表。
|
||||
4. 补充服务层、控制器契约测试:
|
||||
- 仅 categoryId。
|
||||
- categoryId + types。
|
||||
- 分类游标翻页。
|
||||
- marker 分类不命中返回空。
|
||||
5. 更新 `docs/api-phase1.md` 的 `/app/feed` 参数和分类过滤说明。
|
||||
|
||||
门禁:`mvn test` 全模块通过。
|
||||
|
||||
## B. ReelShort
|
||||
|
||||
### B1. API 与仓库
|
||||
|
||||
- `CatalogApi.feed` 增加可选 `String? categoryId`,非空才拼 query。
|
||||
- `CatalogRepository.fetchFeed` 同步参数,HTTP 实现透传。
|
||||
|
||||
### B2. TheaterFeedController
|
||||
|
||||
- 新增 `lib/core/data/services/theater_feed_controller.dart`。
|
||||
- 按 `String? categoryId` 独立缓存状态:
|
||||
`dramas / cursor / hasMore / loaded / loading / loadingMore / lastError /
|
||||
requestSeq / inFlight`。
|
||||
- `select(id)` 同步切分类;有数据先渲染并静默刷新,无数据时加载。
|
||||
- `loadMore` 游标追加并按 id 去重;`hasMore=false` 停止。
|
||||
- `refreshCurrent` 失败保留旧数据;切换回失败分类自动重试。
|
||||
- 单请求 10 秒超时,响应写回发起分类,requestSeq 仅处理同分类顺序。
|
||||
|
||||
### B3. 剧场接入
|
||||
|
||||
- `DiscoverPage` 创建并持有 TheaterFeedController,初始请求「全部」。
|
||||
- 「全部」和分类 chips 的网格统一读取 `theater.dramas`,不再使用
|
||||
`categories.feed.dramas` / `dramasOf`。
|
||||
- `_selectCategory` 同时更新 `DiscoverLogic.selectedCategoryId` 和
|
||||
`theater.select(categoryId)`。
|
||||
- 滚动剩余不足 400px 时触发 `loadMore`;搜索模式不触发剧场分页。
|
||||
- 下拉刷新并行执行 `categories.load()` 和 `theater.refreshCurrent()`。
|
||||
- 无缓存首屏显示转圈;空、失败和重试保持既有剧场视觉。
|
||||
|
||||
### B4. 测试
|
||||
|
||||
- TheaterFeedController:
|
||||
- 全部使用空 categoryId,分类使用对应 id。
|
||||
- 缓存切回不闪烁。
|
||||
- 分页去重、hasMore=false 停止。
|
||||
- 失败保留旧数据、失败分类切回自动重试。
|
||||
- 剧场 widget:
|
||||
- 点击分类请求对应 categoryId。
|
||||
- 接近底部触发下一页。
|
||||
- 搜索、下拉刷新与既有布局不回归。
|
||||
|
||||
门禁:`dart analyze lib test` 零告警、`flutter test` 全过、
|
||||
`flutter build apk --debug` 成功。
|
||||
|
||||
## Git
|
||||
|
||||
- FruitServer 提交:`feat(app): 推荐流支持分类过滤`
|
||||
- ReelShort 提交:`feat(theater): 剧场分类列表服务端分页`
|
||||
- 两仓库作者:`Zhou Weidong <502333560@qq.com>`,禁止 `git add -A`。
|
||||
- 各自 `--no-ff` 合回 `develop` 并 push,两仓库 PROGRESS 留痕。
|
||||
|
||||
## 约束
|
||||
|
||||
- 全程中文;不改 specs、ReelShortWeb,不改首页 K94/K95 已交付逻辑。
|
||||
- 不安装或操作真机;完成后停住等待验收。
|
||||
@@ -0,0 +1,64 @@
|
||||
# K97 修复 iOS 评论输入弹窗键盘避让
|
||||
|
||||
## 目标
|
||||
|
||||
- iOS 评论输入浮层实时跟随 `MediaQuery.viewInsets.bottom`,确保输入框与发表按钮
|
||||
位于键盘上方。
|
||||
- Android 保留既有 MethodChannel + 80ms 防抖 pinned 策略,不恢复底部 SafeArea,
|
||||
避免键盘收起时 48px 抖动回归。
|
||||
- 聚焦、`TextInput.show` 兜底和发表成功提示逻辑不变。
|
||||
|
||||
## 分支
|
||||
|
||||
- ReelShort:`fix/k97-ios-comment-keyboard`,从最新 `origin/develop` 创建。
|
||||
- FruitServer 仅写计划与 PROGRESS 留痕,不改后端功能代码。
|
||||
|
||||
## A. 平台区分
|
||||
|
||||
- `_isAndroid = !kIsWeb && defaultTargetPlatform == TargetPlatform.android`。
|
||||
- Android:
|
||||
- 继续监听 `KeyboardInsetNotifier`。
|
||||
- 继续使用 80ms 防抖后的 `_pinnedKeyboardInset`。
|
||||
- iOS / 其他平台:
|
||||
- 不读取 pinned/channel 值。
|
||||
- `build` 中直接读取 `MediaQuery.viewInsetsOf(context).bottom`。
|
||||
- inset 超过屏幕高度 60% 时按 0 处理,负值归零。
|
||||
|
||||
## B. 面板布局
|
||||
|
||||
- 面板主体使用 `AnimatedPadding`,只设置 bottom:
|
||||
- `duration: 160ms`
|
||||
- `curve: Curves.easeOutCubic`
|
||||
- Android 使用 pinned 值。
|
||||
- iOS / 其他平台使用实时 viewInsets。
|
||||
- Material 仍铺到屏幕底部,用于键盘收起后的实色填充。
|
||||
- Android 不包裹 SafeArea。
|
||||
- iOS / 其他平台包裹 `SafeArea(top: false)`,保留 home indicator 底部避让。
|
||||
|
||||
## C. 测试
|
||||
|
||||
- iOS + `viewInsets.bottom=300`:
|
||||
- 键盘避让 AnimatedPadding 的 bottom 为 300。
|
||||
- `comment-composer-post` 底边位于屏幕高度减 300 之上。
|
||||
- iOS + `viewInsets=0`:padding 为 0。
|
||||
- Android 既有 pinned/channel、焦点、弹出、关闭、发布用例保持通过。
|
||||
- 所有平台 override 测试结束恢复
|
||||
`debugDefaultTargetPlatformOverride = null`。
|
||||
|
||||
## 门禁
|
||||
|
||||
- `dart analyze lib test`
|
||||
- `flutter test`
|
||||
- `flutter build apk --debug`
|
||||
- `flutter build ios --simulator --no-codesign`
|
||||
|
||||
## Git
|
||||
|
||||
- ReelShort 提交:`fix(comment): 修复 iOS 评论输入弹窗键盘避让`
|
||||
- 作者 `Zhou Weidong <502333560@qq.com>`;禁止 `git add -A`。
|
||||
- `--no-ff` 合回 `develop` 并 push,两仓库 PROGRESS 留痕。
|
||||
|
||||
## 约束
|
||||
|
||||
- 全程中文;不改后端、ReelShortWeb、specs。
|
||||
- 不安装或操作真机;完成后停住等待验收。
|
||||
@@ -0,0 +1,73 @@
|
||||
# K98 修复登录与手机号登录键盘遮挡
|
||||
|
||||
## 目标
|
||||
|
||||
- 登录/注册页在邮箱或密码框聚焦后,自动滚动到键盘上方。
|
||||
- 手机号登录弹窗的手机号/验证码框同样保持可见。
|
||||
- Android `adjustNothing` 下通过既有 MethodChannel 获取键盘高度,iOS 使用实时
|
||||
`MediaQuery.viewInsets`。
|
||||
|
||||
## 分支
|
||||
|
||||
- ReelShort:`fix/k98-auth-keyboard`,从最新 `origin/develop` 创建。
|
||||
- FruitServer 仅写计划与 PROGRESS 留痕,不改后端功能代码。
|
||||
|
||||
## A. 有效键盘高度
|
||||
|
||||
在 `keyboard_inset.dart` 增加:
|
||||
|
||||
```dart
|
||||
double effectiveKeyboardInset(
|
||||
BuildContext context,
|
||||
KeyboardInsetNotifier notifier, {
|
||||
double maxRatio = 0.6,
|
||||
});
|
||||
```
|
||||
|
||||
- 取 MediaQuery viewInsets 与 Android channel 逻辑像素值的最大值。
|
||||
- Web/非 Android 不读取 channel。
|
||||
- 超过屏幕高度 60% 时按 0 处理,负值/非法值归零。
|
||||
|
||||
## B. AuthPage
|
||||
|
||||
1. `initState` 启动 `KeyboardInsetNotifier`,监听并用 setState 刷新。
|
||||
2. `SingleChildScrollView` 增加 `ScrollController`。
|
||||
3. 底部 padding 使用固定底部留白 + effectiveKeyboardInset。
|
||||
4. 邮箱/密码 FocusNode 监听焦点;聚焦或键盘高度变化后:
|
||||
- 通过 FocusNode.context 的 RenderBox 获取字段全局底边。
|
||||
- 与屏幕高度 - 键盘高度 - 24 比较。
|
||||
- 被遮挡时用 200ms easeOutCubic animateTo 补足滚动。
|
||||
5. `resizeToAvoidBottomInset` 保持 false。
|
||||
|
||||
## C. PhoneAuthSheet
|
||||
|
||||
1. 接入 KeyboardInsetNotifier 和 ScrollController。
|
||||
2. 底部 padding 改用 effectiveKeyboardInset。
|
||||
3. 手机号/验证码 FocusNode 增加与 AuthPage 相同的焦点/键盘变化滚动校正。
|
||||
4. 保持现有 SingleChildScrollView、弹窗和返回键行为。
|
||||
|
||||
## D. 测试
|
||||
|
||||
- iOS viewInsets=300:登录密码框、注册密码框均在键盘上方。
|
||||
- Android platform + MethodChannel 键盘高度:密码框仍在键盘上方。
|
||||
- iOS:手机号弹窗验证码框在键盘上方。
|
||||
- 所有平台 override 测试返回前显式恢复
|
||||
`debugDefaultTargetPlatformOverride = null`。
|
||||
|
||||
## 门禁
|
||||
|
||||
- `dart analyze lib test`
|
||||
- `flutter test`
|
||||
- `flutter build apk --debug`
|
||||
|
||||
## Git
|
||||
|
||||
- ReelShort 提交:`fix(auth): 登录注册与手机号登录键盘避让`
|
||||
- 作者 `Zhou Weidong <502333560@qq.com>`;禁止 `git add -A`。
|
||||
- `--no-ff` 合回 `develop` 并 push,两仓库 PROGRESS 留痕。
|
||||
|
||||
## 约束
|
||||
|
||||
- 全程中文;不改后端、ReelShortWeb、specs。
|
||||
- 不改评论输入框已验证的 Android pinned 策略。
|
||||
- 不安装或操作真机;完成后停住等待验收。
|
||||
@@ -0,0 +1,30 @@
|
||||
# 2026-10-21 | 短剧保存免费集数同步分集
|
||||
|
||||
## 目标
|
||||
|
||||
后台短剧编辑改 `freeEpisodes` / `unlockCoin` 后,同步 `drama_episode.is_free` / `unlock_coin`,与定价页 `PriceService.save()` 规则一致。
|
||||
|
||||
## 方案
|
||||
|
||||
1. 抽出 `EpisodePriceSync.syncByDramaRule(dramaId, freeEpisodes, unlockCoin)`,供 `DramaService.update` 与 `PriceService.save` 共用。
|
||||
2. `DramaService.update` 在 `updateById` 后,仅当免费集数或解锁金币相对更新前有变化时调用同步。
|
||||
3. TDD:先写 `DramaServiceTest` 复现失败,再改实现转绿。
|
||||
|
||||
## 范围
|
||||
|
||||
- 仅 `fruitshorts-module-content`
|
||||
- 不改 Controller / VO / 契约 / 前端
|
||||
|
||||
## 门禁
|
||||
|
||||
```bash
|
||||
mvn -pl fruitshorts-module-content test -Dtest=DramaServiceTest
|
||||
mvn -pl fruitshorts-module-content test
|
||||
```
|
||||
|
||||
## 分支 / 提交
|
||||
|
||||
- `feature/drama-free-episodes-sync` ← `develop`
|
||||
- `test(content): 覆盖短剧免费集数同步分集价格`
|
||||
- `fix(content): 短剧保存免费集数时同步分集免费状态`
|
||||
- `merge --no-ff` 回 develop 并 push
|
||||
@@ -0,0 +1,24 @@
|
||||
# 2026-10-21 | 短剧保存始终同步分集价格(幂等纠偏)
|
||||
|
||||
## 背景
|
||||
|
||||
承接 K104。短剧 `free_episodes=9` 重存后,分集 5~9 仍收费。
|
||||
|
||||
## 根因
|
||||
|
||||
`DramaService.update()` 仅在 `freeEpisodes` / `unlockCoin` 相对更新前有变化时调用 `EpisodePriceSync`。历史数据已漂移时,同值重存不触发同步。
|
||||
|
||||
## 方案
|
||||
|
||||
1. 测试:覆盖「规则字段未变、分集已漂移」仍纠正。
|
||||
2. `DramaService.update()`:每次保存都调用 `EpisodePriceSync.syncByDramaRule(drama)`。
|
||||
3. `EpisodePriceSync`:仅对有差异的行走 `updateById`(已具备,保持)。
|
||||
|
||||
## 范围
|
||||
|
||||
只改 `fruitshorts-module-content` 的 `DramaService` / `EpisodePriceSync` / `DramaServiceTest`。不改 Controller / VO / 契约 / 前端。
|
||||
|
||||
## 提交
|
||||
|
||||
1. `test(content): 覆盖免费集数未变但分集漂移的修复场景`
|
||||
2. `fix(content): 短剧保存时始终同步分集价格`
|
||||
@@ -0,0 +1,24 @@
|
||||
# 客户端收藏与观看历史分页
|
||||
|
||||
## 目标
|
||||
|
||||
- `/app/favorites` 改为 `PageResult<AppDramaCardVO>`,默认第 1 页、每页 20,最大 100。
|
||||
- `/app/watch/recent` 默认返回 `PageResult<ProgressRespVO>`;请求带 `limit` 时保留一版旧
|
||||
`List<ProgressRespVO>` 响应。
|
||||
- 观看历史补充短剧标题、封面、集号和总集数,剧/集均批量查询。
|
||||
|
||||
## 实现步骤
|
||||
|
||||
1. 收藏关系使用 `selectPage`,按 `created_at DESC, drama_id DESC` 稳定排序;
|
||||
只统计已上线短剧收藏,再按当前页 ID 批量加载短剧。
|
||||
2. 观看进度使用 `selectPage`,按 `updated_at DESC, drama_id DESC` 稳定排序。
|
||||
3. 当前页的 dramaId / episodeId 去重排序后,分别执行一次 IN 查询并装配展示字段。
|
||||
4. Controller 归一化 pageIndex/pageSize;观看历史根据是否传 `limit` 分流新旧响应。
|
||||
5. 更新 API 契约 §1.5,补 service/controller 测试。
|
||||
|
||||
## 风险与约束
|
||||
|
||||
- `limit` 分支仅用于旧客户端兼容,新分页响应与旧 List 响应不能混用。
|
||||
- 已下线短剧不计入收藏 total,也不出现在收藏页。
|
||||
- 观看历史展示字段找不到对应剧或集时保持 null,不影响历史记录返回。
|
||||
- 不修改客户端、不改表结构、不启停服务、不操作真机。
|
||||
@@ -0,0 +1,38 @@
|
||||
# 转码产物查询接口
|
||||
|
||||
## 目标
|
||||
|
||||
- 媒体维度查询 rendition 与帧图产物。
|
||||
- 分集维度聚合转码任务、rendition、帧图状态。
|
||||
- `/admin/dashboard/transcode` 改为明确 VO,OpenAPI 不再出现匿名 Object。
|
||||
|
||||
## 设计
|
||||
|
||||
1. `MediaTranscodeOutputService` 统一读取媒体、任务、rendition 与 thumbnail。
|
||||
2. rendition 按高度、视频码率、质量倒序,id 正序保证稳定。
|
||||
3. thumbnail 优先读取 `thumbnails.vtt`,解析 cue 后分页;无记录返回 `EMPTY`,
|
||||
记录失败返回 `FAILED`,不把缺产物当服务错误。
|
||||
4. 分集聚合对不存在、无视频、无媒资、无任务返回明确 status 和空列表。
|
||||
5. dashboard 使用强类型 queue/failed task VO,保留现有字段语义并补 total。
|
||||
|
||||
## 接口
|
||||
|
||||
- `GET /admin/media/{id}/renditions`
|
||||
- `GET /admin/media/{id}/thumbnails?pageIndex=1&pageSize=100`
|
||||
- `GET /admin/episodes/{id}/transcode`
|
||||
- `GET /admin/dashboard/transcode`(响应类型由 Map 收敛为 VO)
|
||||
|
||||
缩略图响应内嵌 `PageResult<MediaThumbnailFrameVO>`,同时返回 sprite/VTT 元数据;
|
||||
空产物 status 为 `EMPTY`,无绑定分集为 `NO_EPISODE`,损坏 VTT 为 `INVALID`。
|
||||
|
||||
## TDD
|
||||
|
||||
- 先提交媒体有/无产物、不存在、VTT 解析与分页边界测试。
|
||||
- 再提交接口、VO、聚合服务和 dashboard 类型收敛实现。
|
||||
- 门禁:`mvn -pl fruitshorts-module-media test`。
|
||||
|
||||
## 红线
|
||||
|
||||
- 不改 `/app` 契约、specs、ReelShortWeb、Flutter。
|
||||
- 不改 P1 入队与手动重转逻辑。
|
||||
- 不启停服务,不操作真机。
|
||||
@@ -0,0 +1,40 @@
|
||||
# 后台转码链路打通
|
||||
|
||||
## 现状取证
|
||||
|
||||
- 上传完成时 `MediaService.complete` 已为视频调用 `TranscodeService.enqueue`。
|
||||
- 分集创建/替换视频地址时 `EpisodeService` 已调用
|
||||
`EpisodeTranscodeBindingService.bind`,会复用并绑定同一媒体的未完成任务。
|
||||
- 转码失败原因已写入 `transcode_task.error_msg`,最终状态写入 `status`。
|
||||
- 缺口是后台手动触发/重转接口,以及对应幂等和链路测试。
|
||||
|
||||
## 实现
|
||||
|
||||
1. 保留上传完成和改片自动入队逻辑,补测试锁定行为。
|
||||
2. `TranscodeService` 增加手动触发:
|
||||
- QUEUED/RUNNING 直接返回现有任务;
|
||||
- FAILED 重置原任务为 QUEUED;
|
||||
- SUCCESS 才创建新任务,紧接着重复触发会复用新 QUEUED 任务。
|
||||
3. 新增 `POST /admin/media/{id}/transcode`,校验媒资存在,复用 `episode:upload`。
|
||||
4. 返回任务 id 与状态,便于后台提示。
|
||||
|
||||
实现时对同一媒资行使用 `FOR UPDATE`,让重复请求在事务内串行判定;
|
||||
平台不存在的媒资保持 `DATA_NOT_FOUND`,不产生任务或 500。
|
||||
|
||||
## TDD 测试矩阵
|
||||
|
||||
| 场景 | 断言 |
|
||||
| --- | --- |
|
||||
| 视频上传完成 | `MediaService.complete` 调用一次 `enqueue(assetId, 0, 0, sourceUrl)` |
|
||||
| 图片上传完成 | 不创建转码任务 |
|
||||
| 手动触发成功媒资 | 新建一个 QUEUED 任务,重复调用复用同一任务 |
|
||||
| 手动触发进行中媒资 | 直接返回 QUEUED/RUNNING 任务,不新增记录 |
|
||||
| 手动触发失败媒资 | 原任务重置为 QUEUED,保留任务 id |
|
||||
| 媒资不存在 | 返回既有 `DATA_NOT_FOUND`,控制器不产生 500 |
|
||||
| worker 最终失败 | 任务状态 FAILED,`error_msg` 保留 ffmpeg 原因 |
|
||||
|
||||
## 验证
|
||||
|
||||
- 先提交失败测试,再提交实现。
|
||||
- `mvn -pl fruitshorts-module-media,fruitshorts-transcode-worker test`
|
||||
- 不启停任何服务,不执行数据库变更,不改 Web/Flutter/specs/API 文档。
|
||||
@@ -0,0 +1,53 @@
|
||||
# 转码档位配置、雪碧图与播放缩略图轴
|
||||
|
||||
## 目标
|
||||
|
||||
1. 后台可配置转码档位与雪碧图参数,worker 对之后的新任务在 30 秒内自动生效。
|
||||
2. 转码成功后生成雪碧图与 VTT,登记到 `media_thumbnail`。
|
||||
3. 播放接口与详情剧集返回 `thumbnailsUrl`,无产物时为 `null`。
|
||||
|
||||
## 配置模型
|
||||
|
||||
- `sys_config.config_key = media.transcode.profile`,值为 JSON。
|
||||
- 配置包含总开关、分片秒数、码率阶梯与雪碧图参数。
|
||||
- 缺省配置等价于现有 360p/480p/720p/1080p 四档。
|
||||
- 后台 GET 缺省或历史配置非法时返回 yml 等价默认值;PUT 非法时返回统一 400,且不写库。
|
||||
- worker 读取配置缓存 30 秒;缺省、解析失败或校验失败时回退 yml 默认阶梯。
|
||||
|
||||
## 权限取舍
|
||||
|
||||
现有权限点没有 `media:transcode`。本次两个接口复用最小可用的
|
||||
`episode:upload`,避免新增权限点导致已有角色需要补授权;不新增菜单或权限 SQL。
|
||||
|
||||
## 数据与产物
|
||||
|
||||
- 新增 `media_thumbnail`,按 `episode_id` 唯一,记录 VTT、雪碧图前缀、采样参数、
|
||||
尺寸、帧数、时长、状态、错误与总大小。
|
||||
- 雪碧图目录固定在 `transcoded/{taskId}/thumbnails/`:
|
||||
`thumbnails.vtt` + `sprite_001.jpg` 等多张图。
|
||||
- VTT cue 链接使用相对路径 `sprite_XXX.jpg#xywh=x,y,w,h`,同一 VTT 目录下可直接解析。
|
||||
- 缩略图失败只把 `media_thumbnail.status` 置 `FAILED` 并记录错误;主 HLS 仍成功。
|
||||
|
||||
## 播放
|
||||
|
||||
- `PlayRespVO` 和 `AppEpisodeVO` 增加 `thumbnailsUrl`。
|
||||
- 查询 `media_thumbnail` 仅读取 `READY` 产物;objectKey 经
|
||||
`MediaStorageService.toPublicUrl` 后使用现有 `PlaybackSigner` 签名。
|
||||
- 详情剧集列表批量查询缩略图,禁止 N+1。
|
||||
- 不改变现有 HLS/原文件回落与 qualities 列表。
|
||||
|
||||
## 测试
|
||||
|
||||
- worker:配置解析、非法配置回退 yml、30 秒缓存、VTT 坐标、多雪碧图索引、
|
||||
缩略图失败不阻断主转码。
|
||||
- admin:GET 默认值、PUT 非法不落库、PUT 成功落库。
|
||||
- playback:有 READY 缩略图返回签名 `thumbnailsUrl`,无产物返回 `null`。
|
||||
- 门禁:`mvn -pl fruitshorts-transcode-worker,fruitshorts-admin-api,fruitshorts-app-api -am test`。
|
||||
|
||||
## 风险 / 边界
|
||||
|
||||
- 本次只对合并后的新转码任务生效,不回跑历史任务。
|
||||
- 配置中的顶层 `enabled` 会持久化并返回;本单不改变既有队列消费开关语义,
|
||||
worker 仍以 `worker-enabled` 决定是否消费任务。
|
||||
- 雪碧图生成依赖 ffmpeg `tile` 滤镜;真实产物由 worker 门禁和 PM 后续环境验收,
|
||||
本任务不启动服务、不改客户端。
|
||||
@@ -0,0 +1,38 @@
|
||||
# 转码分集绑定与运行态修复
|
||||
|
||||
## 已确认现场
|
||||
|
||||
admin-api/app-api/worker 均运行旧包;worker 未运行;`media_thumbnail` 表缺失;
|
||||
新上传任务 drama_id/episode_id 为 0;旧 worker jar 缺 MediaThumbnail。
|
||||
|
||||
## 代码修复
|
||||
|
||||
1. 分集保存后按视频 URL 的 objectKey 查找 `media_asset`。
|
||||
2. media 域新增绑定服务:
|
||||
- 将 dramaId/episodeId 回填到对应 `transcode_task`;
|
||||
- QUeued/RUNNING/SUCCESS 任务复用,不重复入队;
|
||||
- FAILED/CANCELED 或不存在时新建任务;
|
||||
- 已成功但 episodeId=0 的 rendition 同步回填。
|
||||
3. `claimNext` 只认领 `episode_id > 0`,零绑定任务保留 QUEUED。
|
||||
4. 缩略图登记使用 REQUIRES_NEW 独立事务;生成或登记失败只记 warn/error_msg,
|
||||
主任务仍 SUCCESS。
|
||||
5. 对 episode_id=0 且源文件不存在的明显测试垃圾标记 CANCELED,不删除。
|
||||
|
||||
## 迁移与运行
|
||||
|
||||
1. 确认 `media_thumbnail` 不存在后执行幂等 patch。
|
||||
2. `mvn -DskipTests package` 全量重建。
|
||||
3. 检查三个 jar 分别含:
|
||||
- admin-api:MediaTranscodeProfile;
|
||||
- app-api:PlayRespVO.thumbnailsUrl 对应新类;
|
||||
- worker:MediaThumbnail / MediaThumbnailMapper。
|
||||
4. 重启 8080/8081/worker,日志写 `logs/*.log`。
|
||||
5. 冒烟 admin 配置、App 详情 thumbnailsUrl、worker 轮询。
|
||||
6. 上传真实视频,创建绑定分集,等待 worker 消费,验证任务、四档 HLS、
|
||||
media_thumbnail、VTT 与 sprite HTTP 200。
|
||||
|
||||
## 风险
|
||||
|
||||
- 旧 QUEUED 中无法绑定且源文件不存在的测试任务将被取消并记录 id。
|
||||
- 真实视频端到端验证会写入运行数据库和媒资目录。
|
||||
- 不修改 Web/Flutter,不操作真机。
|
||||
@@ -0,0 +1,24 @@
|
||||
# 转码任务认领与媒资 ID 校验
|
||||
|
||||
## 现场结论
|
||||
|
||||
- `media_asset.id=21` 确实存在,source_url 对应分集 id=13。
|
||||
- 分集 13 的 video_asset_id=0,旧手动触发只拿媒资,不知道分集绑定,
|
||||
因而创建了 media_asset_id=21、episode_id=0 的 QUEUED 任务。
|
||||
- claim 只筛选 episode_id>0,因此该任务永久跳过且没有原因日志。
|
||||
|
||||
## 修复
|
||||
|
||||
1. POST /admin/media/{id}/transcode 严格只按 media_asset.id 查询;
|
||||
不再把候选 id 当分集 id 兜底或补登记。
|
||||
2. 媒资存在时按 source_url 反查分集;找到后绑定 drama_id/episode_id。
|
||||
3. 找不到分集时拒绝建任务,避免生成永远无法认领的 episode_id=0 记录。
|
||||
4. claim 增加 media_asset_id/source_url 条件,并记录被跳过任务 id 与原因。
|
||||
5. RUNNING 无更新阈值收敛到 5 分钟,覆盖 worker 重启后的孤儿任务。
|
||||
6. 一次性 patch 将 media_asset_id 不存在且 episode_id=0 的 QUEUED/RUNNING 标记 FAILED。
|
||||
|
||||
## 验证
|
||||
|
||||
- 非法 media id 拒绝、未绑定分集拒绝、合法 URL 自动绑定。
|
||||
- claim 跳过原因、进度更新、僵尸任务恢复。
|
||||
- `mvn -pl fruitshorts-module-media,fruitshorts-transcode-worker test`。
|
||||
@@ -0,0 +1,28 @@
|
||||
# 转码媒资 ID 精度与存量兜底修复
|
||||
|
||||
## 取证
|
||||
|
||||
- 示例分集 `2113150431755636737` 的 `video_asset_id` 为
|
||||
`2113150398670966786`,与 `media_asset.id` 完全一致。
|
||||
- JS `Number('2113150398670966786')` 序列化为 `2113150398670966800`,
|
||||
超出安全整数后发生精度丢失,导致手动转码查询了错误 ID。
|
||||
|
||||
## 修复
|
||||
|
||||
1. 聚合响应的 episodeId/mediaAssetId/taskId 使用字符串。
|
||||
2. 手动转码仍由后端 Long 接收精确路径 ID。
|
||||
3. 媒资不存在时通过 content 模块的端口按候选 ID 查找分集:
|
||||
- 分集 id;
|
||||
- video_asset_id;
|
||||
- transcode_task.id。
|
||||
4. 找到分集后按 video_url/source_url/objectKey 反查媒资;
|
||||
文件存在但媒资缺失时补登记并回填分集 video_asset_id。
|
||||
5. 无可用视频时保持明确空态/错误语义。
|
||||
|
||||
## 验证
|
||||
|
||||
- 超 2^53 ID 字符串契约。
|
||||
- 聚合无媒资空态。
|
||||
- video_url 反查命中。
|
||||
- 文件存在时补登记。
|
||||
- `mvn -pl fruitshorts-module-media,fruitshorts-transcode-worker test`。
|
||||
@@ -0,0 +1,27 @@
|
||||
# 转码保持原始宽高比
|
||||
|
||||
## 目标
|
||||
|
||||
- 横屏源按档位短边作为高度,竖屏源按档位短边作为宽度。
|
||||
- 源短边小于档位短边时按源短边输出,不放大。
|
||||
- 输出宽高均为偶数,SAR 固定为 1。
|
||||
- rendition 的 width/height 使用 ffprobe 探测到的实际值。
|
||||
|
||||
## 实施
|
||||
|
||||
1. ffprobe 读取源显示方向尺寸,旋转 90/270 度时交换宽高。
|
||||
2. `effectiveShort = min(sourceShort, rungShort)` 并向下取偶数。
|
||||
3. 横屏使用 `scale=-2:<effectiveShort>:flags=lanczos,setsar=1`;
|
||||
竖屏使用 `scale=<effectiveShort>:-2:flags=lanczos,setsar=1`。
|
||||
4. 转码完成后 ffprobe variant playlist,写入实际输出尺寸。
|
||||
5. master playlist 的 RESOLUTION 同步使用实际尺寸。
|
||||
|
||||
## 不放大策略
|
||||
|
||||
选用“用源尺寸输出”:高于源短边的档位仍保留原 quality 标识和码率,
|
||||
但分辨率封顶到源短边,避免所有档位都被跳过导致无产物。
|
||||
|
||||
## 验证
|
||||
|
||||
- 先补横屏、竖屏、小源码片、偶数、SAR=1 与实际尺寸回写测试。
|
||||
- 门禁:`mvn -pl fruitshorts-module-media,fruitshorts-transcode-worker test`。
|
||||
@@ -0,0 +1,29 @@
|
||||
# 转码错误截断与进度上报
|
||||
|
||||
## 问题
|
||||
|
||||
- ffmpeg 错误输出超过 `error_msg varchar(500)`,失败回写 UPDATE 再次失败,
|
||||
任务停在 RUNNING/0。
|
||||
- worker 未解析 ffmpeg progress,前端只能看到 0。
|
||||
- 缺少 RUNNING 超时收口。
|
||||
|
||||
## 修复
|
||||
|
||||
1. SQL patch 将 transcode_task/media_thumbnail 的 error_msg 改为 TEXT,可重复执行。
|
||||
2. 新增统一错误消息截断,最多保留 500 字符并附总长度;即使补丁尚未执行,
|
||||
也不会超过旧 varchar(500) 限制。
|
||||
3. ffmpeg 使用 `-progress` 临时文件,worker 节流为约 1 秒写 transcode_task.progress。
|
||||
4. rendition 阶段映射 0-90%,封面/缩略图 90-99%,成功后 100。
|
||||
5. 失败保留最后进度;RUNNING 超过 10 分钟无 updated_at 变化标记 FAILED。
|
||||
6. 手动重转复用最新任务,SUCCESS/FAILED/CANCELED 原地重置为 QUEUED、progress=0。
|
||||
7. 成功写 rendition 前替换同媒资旧产物,避免重复重转唯一键冲突。
|
||||
|
||||
## 风险
|
||||
|
||||
- 进度写入只允许 RUNNING 状态,避免覆盖已完成/失败状态。
|
||||
- 历史僵尸任务由 worker 下一轮自动收口,无需手工 SQL。
|
||||
|
||||
## 验证
|
||||
|
||||
- 错误截断、进度更新、僵尸重置、重复触发幂等测试。
|
||||
- `mvn -pl fruitshorts-module-media,fruitshorts-transcode-worker test`。
|
||||
@@ -0,0 +1,24 @@
|
||||
# 转码 rendition 幂等与失败落库
|
||||
|
||||
## 根因
|
||||
|
||||
- 成功事务只按 media_asset_id 删除旧 rendition。
|
||||
- 同一分集替换视频后 media_asset_id 改变、episode_id 不变,
|
||||
旧行未被删除,触发 uk_rendition(episode_id, quality, format)。
|
||||
- rendition 插入异常后任务未被可靠置为 FAILED。
|
||||
|
||||
## 修复
|
||||
|
||||
1. 成功事务删除条件分组为:
|
||||
`media_asset_id = 本次媒体 OR (episode_id > 0 AND episode_id = 本次分集)`。
|
||||
2. 缩略图登记按 episode_id 删除旧行后重新插入。
|
||||
3. 主流程异常调用 failFinal,直接写 FAILED、错误、finished_at,保留 progress。
|
||||
4. failFinal 自身异常在 worker 中 catch 并打印 ERROR,不静默。
|
||||
5. error 截断同时保留头部与尾部,长度仍 <= 500。
|
||||
|
||||
## 验证
|
||||
|
||||
- 不同 media_asset_id、同 episode_id 的重复转码清理条件。
|
||||
- thumbnail 旧行替换。
|
||||
- 失败落库字段与尾段错误保留。
|
||||
- `mvn -q -DskipTests=false test -pl ... -am`。
|
||||
+74
-76
@@ -1,97 +1,95 @@
|
||||
# INBOX
|
||||
|
||||
## K85 收藏数 / 评论数实时更新
|
||||
> 本轮任务:K100 后台剧集多选上传(分片 + 断点续传 + 进度展示)。**[已处理]**
|
||||
> 开工前置:先读 `AGENTS.md`、`CODING_STANDARDS.md`、`GIT_WORKFLOW.md` 本文件,再读
|
||||
> `ReelShortWeb/src/utils/uploader.ts`、`src/api/admin/media.ts`、`src/views/contentManagement/EpisodeManagementView.vue`。
|
||||
|
||||
### 现象
|
||||
### Codex 回执(K100)
|
||||
|
||||
首页 feed 右侧互动栏已经能显示数字,但**收藏数、评论数点完不变**:
|
||||
- ReelShortWeb 分支:`feature/episode-batch-upload` → `--no-ff` 合入 `develop` 并 push
|
||||
- 提交:`feat(admin): 剧集多选分片上传与断点续传`
|
||||
- 门禁:`pnpm lint:eslint` 零错误;`pnpm build:dev` 成功
|
||||
- 未验证:PM 手工多选/暂停/刷新续传/批量建集(8080+3005)
|
||||
- 风险:续传需重选相同本地文件;暂停不 abort 进行中分片
|
||||
|
||||
- 收藏(点星标)后数字不动,杀掉 App 重进又回到旧值
|
||||
- 发表评论后评论数不动
|
||||
## 现状(已勘察,不要重复排查)
|
||||
|
||||
### 已定位的根因(勘察结论,不要再重复排查)
|
||||
- 后端分片上传已具备且不改:`POST /admin/media/upload/init` → `POST /admin/media/upload/chunk` →
|
||||
`POST /admin/media/upload/complete`;断点查询 `GET /admin/media/upload/{uploadId}`
|
||||
返回 `receivedChunks/totalChunks/chunkSize/percent/status/assetId/url`。
|
||||
- 前端已有 `src/utils/uploader.ts`:`uploadFile()` 分片并发 3、`resumeUpload()` 按服务端已收片数续传、
|
||||
`probeVideoDuration()` 探测时长。**这两个函数已可用,本次在其上做批量队列 UI**。
|
||||
- 当前剧集管理 `EpisodeManagementView.vue` 只有一个 `el-upload` 单文件入口(`http-request="uploadVideo"`),
|
||||
**不支持多选、没有进度条、没有断点续传入口**,`onSession` 也没有落盘。
|
||||
|
||||
**后端(FruitServer)**
|
||||
## 目标
|
||||
|
||||
1. `drama.favorite_count` 从建剧时置 0 之后**没有任何地方自增/自减**:
|
||||
- `FavoriteService.toggle()` 只写/删 `user_favorite`,注释写着「计数走异步聚合」,
|
||||
但仓库里**没有这个聚合任务**,所以收藏数永远是 0
|
||||
- `remove()` / `removeBatch()` 也不维护计数
|
||||
- `LikeService` 是同步维护 `drama.like_count` 的(`DramaService.adjustLikeCount`),收藏应对齐这个做法
|
||||
2. 数据库现状(本机 PG `fruitshorts`):`drama.favorite_count` 全为 0,
|
||||
而 `user_favorite` 实际有记录(剧 1 有 4 条、剧 2 有 2 条、剧 5 有 5 条……)→ 需要回填
|
||||
3. 评论数没有单个剧集的计数接口:`GET /app/comments` 是游标翻页,不返回总数
|
||||
在剧集管理页提供「批量上传」:一次选多个视频 → 队列分片上传 → 每个文件独立进度 → 失败可重试 →
|
||||
刷新/重进页面能续传 → 上传完成后批量创建分集。
|
||||
|
||||
**客户端(ReelShort)**
|
||||
## A. 上传队列(新建 `src/views/contentManagement/upload/useUploadQueue.ts`)
|
||||
|
||||
4. 首页 feed 的收藏回调(`player_view.dart` 约 468 行)是内联实现,**没有调用已有的
|
||||
`_applyFavoriteDelta`**;只有全屏播放页的 `_toggleSave`(`player_view_actions.dart`)调了
|
||||
→ 首页收藏后数字不变
|
||||
5. 两处 rail 的 `commentCount: drama.commentCount` 是静态值,评论面板关闭后不刷新
|
||||
6. 详情页 `DramaStatsCard` 用 `drama.favoriteCount`,`drama_detail_logic.toggleFavorite()`
|
||||
切换后不更新显示
|
||||
1. 输入:`File[]` + `dramaId` + 可选 `bizType`
|
||||
2. 每项状态机:`waiting → uploading → merging → done / failed / paused`;对外暴露 `items`、`overallPercent`、
|
||||
`start()`、`pause()`、`retry(id)`、`retryAll()`、`remove(id)`、`clear()`
|
||||
3. 队列并发:同时最多 2 个文件上传(文件内分片并发沿用 `uploadFile` 的 3)
|
||||
4. 进度:文件内 `onProgress` 回调更新单项百分比;总进度 = 各文件字节加权,不是简单平均
|
||||
5. 失败隔离:单文件失败不影响其它文件,错误原因记在该项 `error`
|
||||
6. 暂停语义(本轮简化,不做 abort):暂停后不再派发新任务,已在传的分片让其完成
|
||||
7. 上传完成后 `completeUploadApi` 拿到 `assetId/url/durationSec` 写回该项
|
||||
|
||||
### 任务
|
||||
## B. 断点续传(关键)
|
||||
|
||||
#### A. FruitServer(后端)
|
||||
1. 上传开始(拿到 `uploadId`)即写入 `localStorage`:键 `reel_upload_sessions`,
|
||||
值数组项含 `{ uploadId, fileName, fileSize, lastModified, dramaId, bizType, createdAt }`
|
||||
2. 页面进入时读取该键,过滤 `dramaId` 匹配且 24 小时内的会话,弹出提示「发现 N 个未完成上传,是否续传」
|
||||
3. 续传前用 `file.name + size + lastModified` 匹配本地重新选择的文件;
|
||||
**文件匹配不上(换机器/改名)则不自动续传,提示后由用户手动重选**
|
||||
4. 续传走现有 `resumeUpload(file, uploadId)`;`GET /admin/media/upload/{uploadId}` 返回 404 或已 completed 的会话要从 localStorage 清理
|
||||
5. 上传成功、用户移除、用户放弃续传三种情况都要清理对应记录
|
||||
|
||||
1. `fruitshorts-module-content/.../service/DramaService.java`
|
||||
- 新增 `adjustFavoriteCount(Long dramaId, int delta)`:SQL 自增,
|
||||
参考现有 `adjustLikeCount`,减号用 `GREATEST(favorite_count - 1, 0)`
|
||||
2. `fruitshorts-module-playback/.../service/FavoriteService.java`
|
||||
- 类注释里「计数走异步聚合」改成与 `LikeService` 一致的同步维护说明
|
||||
- `toggle()`:插入关系后 `adjustFavoriteCount(+1)`;`physicalDelete` 返回行数 > 0 时 `-1`
|
||||
- `remove()`:删除成功(返回行数 > 0)时 `-1`
|
||||
- `removeBatch()`:按 dramaId 逐个 `physicalDelete` 并按其返回值 `-1`
|
||||
(保持与前端「取消收藏」一致的物理删除语义,避免逻辑删除挡住再次收藏)
|
||||
3. `fruitshorts-app-api/.../controller/AppCommentController.java`
|
||||
- 新增 `GET /app/comments/count?dramaId={id}` → `Result<Long>`,
|
||||
内部 `commentService.countByDrama(dramaId)`(匿名可访问,与列表一致)
|
||||
4. `sql/` 下加一次性回填脚本 `sql/backfill_favorite_count.sql`
|
||||
- `UPDATE drama d SET favorite_count = (SELECT count(*) FROM user_favorite f WHERE f.drama_id = d.id AND f.deleted = 0);`
|
||||
- 只放脚本,不要在应用启动时自动执行
|
||||
5. 测试
|
||||
- `FavoriteService` 单测:收藏 +1、取消 -1、不会减到负数、removeBatch 多剧集各自扣减
|
||||
- `AppCommentController` 契约测试:`/app/comments/count` 返回数字
|
||||
## C. 批量创建分集
|
||||
|
||||
#### B. ReelShort(客户端)
|
||||
1. 上传完成列表提供「批量创建分集」按钮
|
||||
2. 默认值:按文件名自然排序(去扩展名后再比较,`第2集` 排在 `第10集` 之前);
|
||||
集号 = 该剧当前最大集号 + 1 起顺延;标题取文件名去扩展名;是否免费沿用现有新建默认值
|
||||
3. 弹窗内每行可改:集号、标题、是否免费;冲突集号在提交前本地校验并标红
|
||||
4. 提交:逐条调用现有 `createEpisodeApi`(`src/api/admin/episode.ts`),
|
||||
逐条显示成功/失败,失败的保留在弹窗内可重试;全部结束后刷新剧集列表
|
||||
5. **不新增后端接口**,契约不动
|
||||
|
||||
1. `lib/core/data/remote/comment_api.dart`
|
||||
- 新增 `Future<int> count(String dramaId)`,解析 `data`(Long 可能是字符串,用现有 `jsonToInt`)
|
||||
2. `lib/core/data/repositories/comment_repository.dart`
|
||||
- 接口与 `HttpCommentRepository` 同步新增 `count`
|
||||
3. `lib/pages/player/player_view.dart`
|
||||
- 首页 feed 的 `onSave` 改为复用 `_toggleSave(context, drama)`(内部已有 `_applyFavoriteDelta`)
|
||||
- 新增 `Map<String, int> _commentCounts`
|
||||
- 新增 `_openComments(context, drama)`:`await openCommentsWithAuth(...)`,
|
||||
结束后 `await commentRepository.count(drama.id)` 并 `setState` 写入 `_commentCounts`;
|
||||
失败静默(保留旧值,不弹错)
|
||||
- 首页 rail 与播放页 rail 的 `commentCount` 都改成
|
||||
`_commentCounts[drama.id] ?? drama.commentCount`;`onComments` 都走 `_openComments`
|
||||
4. `lib/pages/drama_detail/drama_detail_logic.dart`(收藏数同步)
|
||||
- 记录本地收藏增量,把调整后的收藏数提供给 `DramaStatsCard`
|
||||
(不要改 `Drama` 模型;用 getter 或在 view 层叠加 delta)
|
||||
- 只在切换成功且状态确实变化时 ±1,失败回滚
|
||||
5. 测试
|
||||
- `CommentApi.count` 的解析测试(数字 / 字符串两种返回)
|
||||
- 收藏增量逻辑(可抽纯函数或独立小对象)单测:+1、-1、失败不变
|
||||
## D. 组件拆分(红线:单文件 ≤ 500 行)
|
||||
|
||||
### 验收
|
||||
- `src/views/contentManagement/upload/BatchUploadDialog.vue`:多选、队列列表、总进度、暂停/重试/移除
|
||||
- `src/views/contentManagement/upload/UploadTaskRow.vue`:单行(文件名、大小、进度条、状态、操作)
|
||||
- `src/views/contentManagement/upload/CreateEpisodesDialog.vue`:批量建分集表单
|
||||
- `src/views/contentManagement/upload/useUploadQueue.ts`:队列逻辑(纯逻辑单元,不写 UI)
|
||||
- `EpisodeManagementView.vue` 只加一个「批量上传」入口按钮,并保持原单文件上传入口可用
|
||||
|
||||
- 后端:`mvn test` 全过;`mvn -pl fruitshorts-app-api -am package -DskipTests` 出包;
|
||||
本地执行回填脚本后 `GET /app/home/feed` 的 `favoriteCount` 与 `user_favorite` 实际条数一致
|
||||
- 客户端:`dart analyze lib test` 零告警、`flutter test` 全过
|
||||
- 功能:收藏后 rail 数字立即 ±1;重进 App 数字不回退;发表评论后关闭面板,评论数 +1(重新拉取)
|
||||
## E. 细节要求
|
||||
|
||||
### Git
|
||||
- 文件类型白名单:`mp4/mov/mkv/webm`(`accept="video/*"` + `before-upload` 二次校验)
|
||||
- 单文件大小上限从现有常量取值,超限直接标红不入队
|
||||
- 所有文案走 `src/locales/zh-CN.ts` / `en.ts`,禁止硬编码中文
|
||||
- 进度与错误展示用项目现有样式变量,不新引入 UI 依赖
|
||||
- 上传期间:关闭页面前用 `beforeunload` 提示存在未完成上传
|
||||
|
||||
- FruitServer:从 `develop` 拉 `fix/favorite-comment-count`,
|
||||
提交 `fix(interaction): 收藏计数同步维护并新增评论数接口`,`--no-ff` 合回 `develop` 并 push
|
||||
- ReelShort:从 `develop` 拉 `fix/interaction-count-refresh`,
|
||||
提交 `fix(player): 收藏与评论数实时刷新`,`--no-ff` 合回 `develop` 并 push
|
||||
- 作者统一 `Zhou Weidong <502333560@qq.com>`;各自仓库 `docs/plans/PROGRESS.md` 追加 K85 留痕
|
||||
## F. 门禁
|
||||
|
||||
### 约束
|
||||
- `pnpm lint:eslint` 零错误
|
||||
- `pnpm build:dev` 构建成功
|
||||
- 手工验证(PM 会复核):本地起 8080 + 3005,多选 3 个视频 → 三条并行进度 → 中途暂停 → 刷新页面 → 出现续传提示 → 续传完成 → 批量建分集成功
|
||||
|
||||
- 全程中文;禁止 `git add -A`;不改 specs 仓库;不动 `pubspec.lock` 以外的无关文件
|
||||
- 完成后停住,等待验收
|
||||
## Git
|
||||
|
||||
- ReelShortWeb:从 `develop` 拉 `feature/episode-batch-upload` → 提交
|
||||
`feat(admin): 剧集多选分片上传与断点续传` → `--no-ff` 合回 `develop` 并 push
|
||||
- 作者 `Zhou Weidong <502333560@qq.com>`;禁止 `git add -A`;源码首行 `// Author: fruit.com.cn`
|
||||
|
||||
## 约束
|
||||
|
||||
- 先写计划 `docs/plans/2026-10-21-K100-episode-batch-upload.md`,再改代码
|
||||
- 每跑一个命令,把「命令 + 原始输出 + 解读」追加到 `docs/plans/PROGRESS.md`
|
||||
- 不改 FruitServer、不改 ReelShort 客户端、不改接口契约
|
||||
- 禁止 `git add -A`;不要操作真机
|
||||
- 完成后停住等 PM 验收,回执需贴门禁原始输出
|
||||
File diff suppressed because it is too large.
Load diff
+13
-2
@@ -4,6 +4,7 @@ package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import com.fruitshorts.admin.service.AppSessionSystemService;
|
||||
import com.fruitshorts.admin.vo.AppUserWatchHistoryVO;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
@@ -13,6 +14,7 @@ import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.framework.log.OperationLog;
|
||||
import com.fruitshorts.framework.security.SecurityUtils;
|
||||
import com.fruitshorts.playback.dal.entity.WatchHistory;
|
||||
import com.fruitshorts.user.dal.entity.AppUserSession;
|
||||
import com.fruitshorts.playback.service.WatchProgressService;
|
||||
import com.fruitshorts.user.dal.entity.AppUserBanRecord;
|
||||
import com.fruitshorts.user.service.AppUserAdminService;
|
||||
@@ -44,6 +46,7 @@ public class AppUserAdminController {
|
||||
private final WatchProgressService watchProgressService;
|
||||
private final DramaService dramaService;
|
||||
private final EpisodeService episodeService;
|
||||
private final AppSessionSystemService sessionSystem;
|
||||
|
||||
@Operation(summary = "App 用户分页查询")
|
||||
@GetMapping("/page")
|
||||
@@ -83,11 +86,15 @@ public class AppUserAdminController {
|
||||
Map<Long, DramaEpisode> episodes = episodeService
|
||||
.listByIds(rows.stream().map(WatchHistory::getEpisodeId).distinct().toList())
|
||||
.stream().collect(Collectors.toMap(DramaEpisode::getId, item -> item, (a, b) -> a));
|
||||
return Result.ok(rows.stream().map(row -> toVo(row, dramas, episodes)).toList());
|
||||
List<AppUserSession> sessions = sessionSystem.groupByUser(List.of(id))
|
||||
.getOrDefault(id, List.of());
|
||||
return Result.ok(rows.stream()
|
||||
.map(row -> toVo(row, dramas, episodes, sessionSystem.match(sessions, row.getDeviceId())))
|
||||
.toList());
|
||||
}
|
||||
|
||||
private AppUserWatchHistoryVO toVo(WatchHistory row, Map<Long, Drama> dramas,
|
||||
Map<Long, DramaEpisode> episodes) {
|
||||
Map<Long, DramaEpisode> episodes, AppUserSession session) {
|
||||
AppUserWatchHistoryVO vo = new AppUserWatchHistoryVO();
|
||||
vo.setId(row.getId());
|
||||
vo.setDramaId(row.getDramaId());
|
||||
@@ -100,6 +107,10 @@ public class AppUserAdminController {
|
||||
long position = row.getPositionMs() == null ? 0L : row.getPositionMs();
|
||||
long duration = row.getDurationMs() == null ? 0L : row.getDurationMs();
|
||||
vo.setFinished(duration > 0 && position + 1000L >= duration);
|
||||
if (session != null) {
|
||||
vo.setPlatform(session.getPlatform());
|
||||
vo.setOsVersion(session.getOsVersion());
|
||||
}
|
||||
Drama drama = dramas.get(row.getDramaId());
|
||||
if (drama != null) {
|
||||
vo.setDramaTitle(drama.getTitle());
|
||||
|
||||
+2
-1
@@ -3,6 +3,7 @@
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.admin.service.DashboardService;
|
||||
import com.fruitshorts.admin.vo.TranscodeDashboardRespVO;
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -40,7 +41,7 @@ public class DashboardAdminController {
|
||||
@Operation(summary = "转码看板(队列积压与失败任务)")
|
||||
@GetMapping("/transcode")
|
||||
@PreAuthorize("@ss.hasPermission('dashboard:view')")
|
||||
public Result<Map<String, Object>> transcode() {
|
||||
public Result<TranscodeDashboardRespVO> transcode() {
|
||||
return Result.ok(dashboardService.transcode());
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import com.fruitshorts.content.service.DramaClassificationService;
|
||||
import com.fruitshorts.content.vo.DramaBriefVO;
|
||||
import com.fruitshorts.content.vo.DramaClassificationRespVO;
|
||||
import com.fruitshorts.content.vo.DramaClassificationSaveReqVO;
|
||||
import com.fruitshorts.content.vo.DramaIdsReqVO;
|
||||
import com.fruitshorts.framework.log.OperationLog;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
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 java.util.List;
|
||||
|
||||
/**
|
||||
* 运营分类管理。分类与短剧类型(drama-categories)是两套独立概念,
|
||||
* 分类可自定义增删,并关联任意多部短剧。
|
||||
*/
|
||||
@Tag(name = "后台-运营分类")
|
||||
@RestController
|
||||
@RequestMapping("/admin/drama-classifications")
|
||||
@RequiredArgsConstructor
|
||||
public class DramaClassificationController {
|
||||
|
||||
private final DramaClassificationService classificationService;
|
||||
|
||||
@Operation(summary = "分类列表(带关联数量)")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('drama:list')")
|
||||
public Result<List<DramaClassificationRespVO>> list() {
|
||||
return Result.ok(classificationService.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "新建分类")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPermission('drama:create')")
|
||||
@OperationLog(module = "内容管理", action = "新增分类")
|
||||
public Result<Long> create(@Valid @RequestBody DramaClassificationSaveReqVO req) {
|
||||
return Result.ok(classificationService.create(req));
|
||||
}
|
||||
|
||||
@Operation(summary = "编辑分类")
|
||||
@PutMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('drama:update')")
|
||||
@OperationLog(module = "内容管理", action = "编辑分类")
|
||||
public Result<Void> update(@PathVariable Long id,
|
||||
@Valid @RequestBody DramaClassificationSaveReqVO req) {
|
||||
classificationService.update(id, req);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除分类")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('drama:delete')")
|
||||
@OperationLog(module = "内容管理", action = "删除分类")
|
||||
public Result<Void> delete(@PathVariable Long id) {
|
||||
classificationService.delete(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "分类下已关联的短剧")
|
||||
@GetMapping("/{id}/dramas")
|
||||
@PreAuthorize("@ss.hasPermission('drama:list')")
|
||||
public Result<PageResult<DramaBriefVO>> dramas(
|
||||
@PathVariable Long id,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(defaultValue = "1") int pageIndex,
|
||||
@RequestParam(defaultValue = "10") int pageSize) {
|
||||
return Result.ok(classificationService.pageDramas(id, keyword, pageIndex, pageSize));
|
||||
}
|
||||
|
||||
@Operation(summary = "尚未关联到该分类的短剧")
|
||||
@GetMapping("/{id}/dramas/candidates")
|
||||
@PreAuthorize("@ss.hasPermission('drama:list')")
|
||||
public Result<PageResult<DramaBriefVO>> candidates(
|
||||
@PathVariable Long id,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(defaultValue = "1") int pageIndex,
|
||||
@RequestParam(defaultValue = "10") int pageSize) {
|
||||
return Result.ok(classificationService.pageCandidates(id, keyword, pageIndex, pageSize));
|
||||
}
|
||||
|
||||
@Operation(summary = "批量关联短剧")
|
||||
@PostMapping("/{id}/dramas")
|
||||
@PreAuthorize("@ss.hasPermission('drama:update')")
|
||||
@OperationLog(module = "内容管理", action = "分类关联短剧")
|
||||
public Result<Integer> bindDramas(@PathVariable Long id,
|
||||
@Valid @RequestBody DramaIdsReqVO req) {
|
||||
return Result.ok(classificationService.bindDramas(id, req.getDramaIds()));
|
||||
}
|
||||
|
||||
@Operation(summary = "移除分类下的短剧")
|
||||
@DeleteMapping("/{id}/dramas/{dramaId}")
|
||||
@PreAuthorize("@ss.hasPermission('drama:update')")
|
||||
@OperationLog(module = "内容管理", action = "分类移除短剧")
|
||||
public Result<Void> unbindDrama(@PathVariable Long id, @PathVariable Long dramaId) {
|
||||
classificationService.unbindDrama(id, dramaId);
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import com.fruitshorts.content.service.DramaPlaylistCategoryService;
|
||||
import com.fruitshorts.content.vo.DramaBriefVO;
|
||||
import com.fruitshorts.content.vo.DramaIdsReqVO;
|
||||
import com.fruitshorts.content.vo.DramaPlaylistCategoryRespVO;
|
||||
import com.fruitshorts.content.vo.DramaPlaylistCategorySaveReqVO;
|
||||
import com.fruitshorts.framework.log.OperationLog;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
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 java.util.List;
|
||||
|
||||
/**
|
||||
* 剧单分类管理:分类直接关联短剧,没有「剧单」这一层。
|
||||
* 与「类型」「分类管理」均无关。
|
||||
*/
|
||||
@Tag(name = "后台-剧单分类")
|
||||
@RestController
|
||||
@RequestMapping("/admin/drama-playlist-categories")
|
||||
@RequiredArgsConstructor
|
||||
public class DramaPlaylistCategoryController {
|
||||
|
||||
private final DramaPlaylistCategoryService categoryService;
|
||||
|
||||
@Operation(summary = "剧单分类列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('drama:list')")
|
||||
public Result<List<DramaPlaylistCategoryRespVO>> list() {
|
||||
return Result.ok(categoryService.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "新建剧单分类")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPermission('drama:create')")
|
||||
@OperationLog(module = "内容管理", action = "新增剧单分类")
|
||||
public Result<Long> create(@Valid @RequestBody DramaPlaylistCategorySaveReqVO req) {
|
||||
return Result.ok(categoryService.create(req));
|
||||
}
|
||||
|
||||
@Operation(summary = "编辑剧单分类")
|
||||
@PutMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('drama:update')")
|
||||
@OperationLog(module = "内容管理", action = "编辑剧单分类")
|
||||
public Result<Void> update(@PathVariable Long id,
|
||||
@Valid @RequestBody DramaPlaylistCategorySaveReqVO req) {
|
||||
categoryService.update(id, req);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除剧单分类")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('drama:delete')")
|
||||
@OperationLog(module = "内容管理", action = "删除剧单分类")
|
||||
public Result<Void> delete(@PathVariable Long id) {
|
||||
categoryService.delete(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "分类下已关联的短剧")
|
||||
@GetMapping("/{id}/dramas")
|
||||
@PreAuthorize("@ss.hasPermission('drama:list')")
|
||||
public Result<PageResult<DramaBriefVO>> dramas(
|
||||
@PathVariable Long id,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(defaultValue = "1") int pageIndex,
|
||||
@RequestParam(defaultValue = "10") int pageSize) {
|
||||
return Result.ok(categoryService.pageDramas(id, keyword, pageIndex, pageSize));
|
||||
}
|
||||
|
||||
@Operation(summary = "尚未关联到该分类的短剧")
|
||||
@GetMapping("/{id}/dramas/candidates")
|
||||
@PreAuthorize("@ss.hasPermission('drama:list')")
|
||||
public Result<PageResult<DramaBriefVO>> candidates(
|
||||
@PathVariable Long id,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(defaultValue = "1") int pageIndex,
|
||||
@RequestParam(defaultValue = "10") int pageSize) {
|
||||
return Result.ok(categoryService.pageCandidates(id, keyword, pageIndex, pageSize));
|
||||
}
|
||||
|
||||
@Operation(summary = "批量关联短剧")
|
||||
@PostMapping("/{id}/dramas")
|
||||
@PreAuthorize("@ss.hasPermission('drama:update')")
|
||||
@OperationLog(module = "内容管理", action = "剧单分类关联短剧")
|
||||
public Result<Integer> bindDramas(@PathVariable Long id,
|
||||
@Valid @RequestBody DramaIdsReqVO req) {
|
||||
return Result.ok(categoryService.bindDramas(id, req.getDramaIds()));
|
||||
}
|
||||
|
||||
@Operation(summary = "移除分类下的短剧")
|
||||
@DeleteMapping("/{id}/dramas/{dramaId}")
|
||||
@PreAuthorize("@ss.hasPermission('drama:update')")
|
||||
@OperationLog(module = "内容管理", action = "剧单分类移除短剧")
|
||||
public Result<Void> unbindDrama(@PathVariable Long id, @PathVariable Long dramaId) {
|
||||
categoryService.unbindDrama(id, dramaId);
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -2,6 +2,7 @@
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
@@ -39,12 +40,15 @@ public class EpisodeController {
|
||||
private final CommentService commentService;
|
||||
private final DramaService dramaService;
|
||||
|
||||
@Operation(summary = "剧集列表")
|
||||
@Operation(summary = "剧集列表(分页)")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('episode:list')")
|
||||
public Result<List<EpisodeRespVO>> list(@RequestParam Long dramaId,
|
||||
@RequestParam(required = false) String status) {
|
||||
List<EpisodeRespVO> episodes = episodeService.listByDrama(dramaId, status);
|
||||
public Result<PageResult<EpisodeRespVO>> list(@RequestParam Long dramaId,
|
||||
@RequestParam(required = false) String status,
|
||||
@RequestParam(required = false) Integer pageIndex,
|
||||
@RequestParam(required = false) Integer pageSize) {
|
||||
PageResult<EpisodeRespVO> page = episodeService.pageByDrama(dramaId, status, pageIndex, pageSize);
|
||||
List<EpisodeRespVO> episodes = page.getList();
|
||||
Map<Long, Long> commentCounts = commentService.countByEpisodes(
|
||||
episodes.stream().map(EpisodeRespVO::getId).toList());
|
||||
Drama drama = dramaService.getExisting(dramaId);
|
||||
@@ -53,7 +57,7 @@ public class EpisodeController {
|
||||
episode.setFavoriteCount(drama.getFavoriteCount());
|
||||
episode.setHeat(drama.getViewCount());
|
||||
});
|
||||
return Result.ok(episodes);
|
||||
return Result.ok(new PageResult<>(page.getTotal(), episodes));
|
||||
}
|
||||
|
||||
@Operation(summary = "新建剧集")
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.admin.service.EpisodeTranscodeAdminService;
|
||||
import com.fruitshorts.admin.vo.EpisodeTranscodeRespVO;
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/** 后台剧集转码聚合查询。 */
|
||||
@Tag(name = "后台-剧集转码")
|
||||
@RestController
|
||||
@RequestMapping("/admin/episodes")
|
||||
@RequiredArgsConstructor
|
||||
public class EpisodeTranscodeController {
|
||||
|
||||
private final EpisodeTranscodeAdminService service;
|
||||
|
||||
@Operation(summary = "查询分集转码聚合信息")
|
||||
@GetMapping("/{id}/transcode")
|
||||
@PreAuthorize("@ss.hasPermission('episode:list')")
|
||||
public Result<EpisodeTranscodeRespVO> detail(@PathVariable Long id) {
|
||||
return Result.ok(service.detail(id));
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import com.fruitshorts.framework.log.OperationLog;
|
||||
import com.fruitshorts.system.service.LegalDocumentService;
|
||||
import com.fruitshorts.system.vo.LegalDocumentVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台维护服务条款和隐私协议。公开页面由客户端服务按语言输出。
|
||||
*/
|
||||
@Tag(name = "后台-协议")
|
||||
@RestController
|
||||
@RequestMapping("/admin/legal-documents")
|
||||
@RequiredArgsConstructor
|
||||
public class LegalDocumentAdminController {
|
||||
|
||||
private final LegalDocumentService legalDocumentService;
|
||||
|
||||
@Operation(summary = "协议列表(服务条款、隐私协议,各含中英印尼语)")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasAnyPermission('system:role','system:menu')")
|
||||
public Result<List<LegalDocumentVO>> list() {
|
||||
return Result.ok(legalDocumentService.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "保存协议")
|
||||
@PutMapping
|
||||
@PreAuthorize("@ss.hasPermission('system:role')")
|
||||
@OperationLog(module = "后台管理", action = "修改服务条款或隐私协议")
|
||||
public Result<Void> save(@RequestBody List<LegalDocumentVO> items) {
|
||||
legalDocumentService.save(items);
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
||||
+32
@@ -5,8 +5,12 @@ package com.fruitshorts.admin.controller;
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import com.fruitshorts.framework.security.SecurityUtils;
|
||||
import com.fruitshorts.framework.security.ImpersonationGuard;
|
||||
import com.fruitshorts.framework.log.OperationLog;
|
||||
import com.fruitshorts.media.config.MediaTranscodeProfile;
|
||||
import com.fruitshorts.media.service.MediaService;
|
||||
import com.fruitshorts.media.service.MediaTranscodeProfileService;
|
||||
import com.fruitshorts.media.vo.MediaAssetRespVO;
|
||||
import com.fruitshorts.media.vo.TranscodeTriggerRespVO;
|
||||
import com.fruitshorts.media.vo.UploadCompleteReqVO;
|
||||
import com.fruitshorts.media.vo.UploadInitReqVO;
|
||||
import com.fruitshorts.media.vo.UploadInitRespVO;
|
||||
@@ -19,6 +23,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -35,6 +40,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
public class MediaController {
|
||||
|
||||
private final MediaService mediaService;
|
||||
private final MediaTranscodeProfileService profileService;
|
||||
|
||||
@Operation(summary = "初始化分片上传")
|
||||
@PostMapping("/upload/init")
|
||||
@@ -78,4 +84,30 @@ public class MediaController {
|
||||
public Result<MediaAssetRespVO> get(@PathVariable Long id) {
|
||||
return Result.ok(mediaService.get(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "手动触发或重转媒资")
|
||||
@PostMapping("/{id}/transcode")
|
||||
@PreAuthorize("@ss.hasPermission('episode:upload')")
|
||||
@OperationLog(module = "后台管理", action = "触发媒资转码")
|
||||
public Result<TranscodeTriggerRespVO> transcode(@PathVariable Long id) {
|
||||
ImpersonationGuard.rejectWrite();
|
||||
return Result.ok(mediaService.triggerTranscode(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "读取转码档位配置")
|
||||
@GetMapping("/transcode-profile")
|
||||
@PreAuthorize("@ss.hasPermission('episode:upload')")
|
||||
public Result<MediaTranscodeProfile> transcodeProfile() {
|
||||
return Result.ok(profileService.readConfiguredProfile());
|
||||
}
|
||||
|
||||
@Operation(summary = "保存转码档位配置")
|
||||
@PutMapping("/transcode-profile")
|
||||
@PreAuthorize("@ss.hasPermission('episode:upload')")
|
||||
@OperationLog(module = "后台管理", action = "修改转码设置")
|
||||
public Result<MediaTranscodeProfile> saveTranscodeProfile(
|
||||
@Valid @RequestBody MediaTranscodeProfile profile) {
|
||||
ImpersonationGuard.rejectWrite();
|
||||
return Result.ok(profileService.save(profile));
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import com.fruitshorts.media.service.MediaTranscodeOutputService;
|
||||
import com.fruitshorts.media.vo.MediaRenditionRespVO;
|
||||
import com.fruitshorts.media.vo.MediaThumbnailRespVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 后台媒资转码产物只读查询。 */
|
||||
@Tag(name = "后台-媒资转码产物")
|
||||
@RestController
|
||||
@RequestMapping("/admin/media")
|
||||
@RequiredArgsConstructor
|
||||
public class MediaTranscodeOutputController {
|
||||
|
||||
private final MediaTranscodeOutputService outputService;
|
||||
|
||||
@Operation(summary = "查询媒资清晰度产物")
|
||||
@GetMapping("/{id}/renditions")
|
||||
@PreAuthorize("@ss.hasPermission('episode:upload')")
|
||||
public Result<List<MediaRenditionRespVO>> renditions(@PathVariable Long id) {
|
||||
return Result.ok(outputService.renditions(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询媒资帧图产物")
|
||||
@GetMapping("/{id}/thumbnails")
|
||||
@PreAuthorize("@ss.hasPermission('episode:upload')")
|
||||
public Result<MediaThumbnailRespVO> thumbnails(
|
||||
@PathVariable Long id,
|
||||
@RequestParam(defaultValue = "1") Integer pageIndex,
|
||||
@RequestParam(defaultValue = "100") Integer pageSize) {
|
||||
return Result.ok(outputService.thumbnails(id, pageIndex, pageSize));
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fruitshorts.user.dal.entity.AppUserSession;
|
||||
import com.fruitshorts.user.dal.mapper.AppUserSessionMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 按用户最近会话解析系统。同一设备优先,否则用仍有效的最近一次登录。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AppSessionSystemService {
|
||||
|
||||
private final AppUserSessionMapper sessionMapper;
|
||||
|
||||
/** 按用户分组,组内按最近活跃倒序。 */
|
||||
public Map<Long, List<AppUserSession>> groupByUser(Collection<Long> userIds) {
|
||||
Map<Long, List<AppUserSession>> grouped = new HashMap<>();
|
||||
if (userIds == null || userIds.isEmpty()) {
|
||||
return grouped;
|
||||
}
|
||||
List<AppUserSession> sessions = sessionMapper.selectList(Wrappers.<AppUserSession>lambdaQuery()
|
||||
.in(AppUserSession::getUserId, userIds)
|
||||
.orderByDesc(AppUserSession::getLastActiveAt)
|
||||
.orderByDesc(AppUserSession::getId));
|
||||
for (AppUserSession session : sessions) {
|
||||
grouped.computeIfAbsent(session.getUserId(), key -> new ArrayList<>()).add(session);
|
||||
}
|
||||
return grouped;
|
||||
}
|
||||
|
||||
/** 观看记录优先匹配同一设备,其次取未吊销会话。 */
|
||||
public AppUserSession match(List<AppUserSession> sessions, String deviceId) {
|
||||
if (sessions == null || sessions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (StringUtils.hasText(deviceId)) {
|
||||
for (AppUserSession session : sessions) {
|
||||
if (deviceId.equals(session.getDeviceId())) {
|
||||
return session;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (AppUserSession session : sessions) {
|
||||
if (session.getRevokedAt() == null) {
|
||||
return session;
|
||||
}
|
||||
}
|
||||
return sessions.get(0);
|
||||
}
|
||||
}
|
||||
+17
-12
@@ -3,6 +3,7 @@
|
||||
package com.fruitshorts.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fruitshorts.admin.vo.TranscodeDashboardRespVO;
|
||||
import com.fruitshorts.commerce.dal.entity.CoinLedger;
|
||||
import com.fruitshorts.commerce.dal.entity.Entitlement;
|
||||
import com.fruitshorts.commerce.dal.entity.Orders;
|
||||
@@ -21,6 +22,8 @@ import com.fruitshorts.interaction.dal.entity.ContentReport;
|
||||
import com.fruitshorts.interaction.dal.mapper.ContentCommentMapper;
|
||||
import com.fruitshorts.interaction.dal.mapper.ContentReportMapper;
|
||||
import com.fruitshorts.media.service.TranscodeService;
|
||||
import com.fruitshorts.media.vo.TranscodeQueueStatsVO;
|
||||
import com.fruitshorts.media.vo.TranscodeTaskRespVO;
|
||||
import com.fruitshorts.playback.dal.entity.WatchHistory;
|
||||
import com.fruitshorts.playback.dal.entity.WatchProgress;
|
||||
import com.fruitshorts.playback.dal.mapper.WatchHistoryMapper;
|
||||
@@ -101,12 +104,14 @@ public class DashboardService {
|
||||
}
|
||||
|
||||
/** 转码看板:队列积压与失败明细。 */
|
||||
public Map<String, Object> transcode() {
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("generatedAt", LocalDateTime.now());
|
||||
data.put("queue", transcodeService.stats());
|
||||
data.put("failedTasks", transcodeService.failedTasks(20));
|
||||
data.put("notes", List.of(
|
||||
public TranscodeDashboardRespVO transcode() {
|
||||
TranscodeDashboardRespVO data = new TranscodeDashboardRespVO();
|
||||
data.setGeneratedAt(LocalDateTime.now());
|
||||
data.setQueue(transcodeService.stats());
|
||||
data.setFailedTasks(transcodeService.failedTasks(20).stream()
|
||||
.map(TranscodeTaskRespVO::from)
|
||||
.toList());
|
||||
data.setNotes(List.of(
|
||||
"queue 为累计口径(不限时间),反映当前积压与历史成败分布",
|
||||
"failedTasks 最多返回 20 条,按 id 倒序"));
|
||||
return data;
|
||||
@@ -205,12 +210,12 @@ public class DashboardService {
|
||||
|
||||
private Map<String, Object> costMetrics(LocalDateTime sevenDaysAgo) {
|
||||
Map<String, Object> cost = new LinkedHashMap<>();
|
||||
Map<String, Object> queue = transcodeService.stats();
|
||||
cost.put("transcodeQueued", queue.get("queued"));
|
||||
cost.put("transcodeRunning", queue.get("running"));
|
||||
cost.put("transcodeFailed", queue.get("failed"));
|
||||
cost.put("transcodeSuccess", queue.get("success"));
|
||||
cost.put("renditions", queue.get("renditions"));
|
||||
TranscodeQueueStatsVO queue = transcodeService.stats();
|
||||
cost.put("transcodeQueued", queue.getQueued());
|
||||
cost.put("transcodeRunning", queue.getRunning());
|
||||
cost.put("transcodeFailed", queue.getFailed());
|
||||
cost.put("transcodeSuccess", queue.getSuccess());
|
||||
cost.put("renditions", queue.getRenditions());
|
||||
cost.put("otpSent7d", appUserOtpMapper.selectCount(Wrappers.<AppUserOtp>lambdaQuery()
|
||||
.ge(AppUserOtp::getCreatedAt, sevenDaysAgo)));
|
||||
cost.put("cdnTrafficBytes", null);
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.service;
|
||||
|
||||
import com.fruitshorts.admin.vo.EpisodeTranscodeRespVO;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.dal.mapper.DramaEpisodeMapper;
|
||||
import com.fruitshorts.media.service.MediaTranscodeOutputService;
|
||||
import com.fruitshorts.media.vo.MediaThumbnailRespVO;
|
||||
import com.fruitshorts.media.vo.TranscodeTaskRespVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/** 聚合剧集与媒资转码产物,供后台编辑页一次读取。 */
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EpisodeTranscodeAdminService {
|
||||
|
||||
private static final String STATUS_EPISODE_NOT_FOUND = "EPISODE_NOT_FOUND";
|
||||
private static final String STATUS_NO_VIDEO = "NO_VIDEO";
|
||||
private static final String STATUS_NO_MEDIA_ASSET = "NO_MEDIA_ASSET";
|
||||
private static final String STATUS_NO_TASK = "NO_TASK";
|
||||
private static final String REASON_EPISODE_NOT_FOUND = "分集不存在或已删除";
|
||||
private static final String REASON_NO_VIDEO = "分集未配置视频";
|
||||
private static final String REASON_NO_MEDIA_ASSET = "未找到分集视频对应的媒资";
|
||||
private static final int THUMBNAIL_PAGE_INDEX = 1;
|
||||
private static final int THUMBNAIL_PAGE_SIZE = 100;
|
||||
|
||||
private final DramaEpisodeMapper episodeMapper;
|
||||
private final MediaTranscodeOutputService outputService;
|
||||
|
||||
public EpisodeTranscodeRespVO detail(Long episodeId) {
|
||||
DramaEpisode episode = episodeId == null ? null : episodeMapper.selectById(episodeId);
|
||||
if (episode == null) {
|
||||
return empty(episodeId, STATUS_EPISODE_NOT_FOUND, REASON_EPISODE_NOT_FOUND);
|
||||
}
|
||||
boolean hasVideoAsset = episode.getVideoAssetId() != null
|
||||
&& episode.getVideoAssetId() > 0;
|
||||
if (!StringUtils.hasText(episode.getVideoUrl()) && !hasVideoAsset) {
|
||||
return empty(episodeId, STATUS_NO_VIDEO, REASON_NO_VIDEO);
|
||||
}
|
||||
Long mediaAssetId = outputService.resolveMediaAssetId(episode.getVideoUrl());
|
||||
if ((mediaAssetId == null || mediaAssetId <= 0) && hasVideoAsset
|
||||
&& outputService.mediaAssetExists(episode.getVideoAssetId())) {
|
||||
mediaAssetId = episode.getVideoAssetId();
|
||||
}
|
||||
if (mediaAssetId == null || mediaAssetId <= 0) {
|
||||
return empty(episodeId, STATUS_NO_MEDIA_ASSET, REASON_NO_MEDIA_ASSET);
|
||||
}
|
||||
|
||||
EpisodeTranscodeRespVO result = new EpisodeTranscodeRespVO();
|
||||
result.setEpisodeId(idString(episodeId));
|
||||
result.setMediaAssetId(idString(mediaAssetId));
|
||||
result.setRenditions(outputService.renditionsForMediaAssetId(mediaAssetId));
|
||||
result.setThumbnails(outputService.thumbnailForEpisode(
|
||||
episodeId, mediaAssetId, THUMBNAIL_PAGE_INDEX, THUMBNAIL_PAGE_SIZE));
|
||||
|
||||
TranscodeTaskRespVO task = outputService.latestTask(mediaAssetId);
|
||||
if (task == null) {
|
||||
result.setStatus(taskStatusOf(episode));
|
||||
result.setProgress(0);
|
||||
result.setRetryCount(0);
|
||||
result.setErrorMsg("");
|
||||
result.setUpdatedAt(episode.getUpdatedAt());
|
||||
return result;
|
||||
}
|
||||
result.setTaskId(idString(task.getId()));
|
||||
result.setStatus(task.getStatus());
|
||||
result.setProgress(task.getProgress());
|
||||
result.setRetryCount(task.getRetryCount());
|
||||
result.setErrorMsg(task.getErrorMsg());
|
||||
result.setUpdatedAt(task.getUpdatedAt());
|
||||
return result;
|
||||
}
|
||||
|
||||
private EpisodeTranscodeRespVO empty(Long episodeId, String status, String reason) {
|
||||
EpisodeTranscodeRespVO result = new EpisodeTranscodeRespVO();
|
||||
result.setEpisodeId(idString(episodeId));
|
||||
result.setStatus(status);
|
||||
result.setProgress(0);
|
||||
result.setRetryCount(0);
|
||||
result.setErrorMsg(reason);
|
||||
result.setRenditions(List.of());
|
||||
result.setThumbnails(MediaThumbnailRespVO.empty(
|
||||
null, episodeId, MediaThumbnailRespVO.STATUS_EMPTY,
|
||||
THUMBNAIL_PAGE_INDEX, THUMBNAIL_PAGE_SIZE));
|
||||
return result;
|
||||
}
|
||||
|
||||
private String idString(Long id) {
|
||||
return id == null ? null : String.valueOf(id);
|
||||
}
|
||||
|
||||
private String taskStatusOf(DramaEpisode episode) {
|
||||
return StringUtils.hasText(episode.getTranscodeStatus())
|
||||
? episode.getTranscodeStatus().toUpperCase(Locale.ROOT)
|
||||
: STATUS_NO_TASK;
|
||||
}
|
||||
}
|
||||
+11
-2
@@ -17,6 +17,7 @@ import com.fruitshorts.content.enums.ContentStatus;
|
||||
import com.fruitshorts.playback.dal.entity.WatchHistory;
|
||||
import com.fruitshorts.playback.dal.mapper.WatchHistoryMapper;
|
||||
import com.fruitshorts.user.dal.entity.AppUser;
|
||||
import com.fruitshorts.user.dal.entity.AppUserSession;
|
||||
import com.fruitshorts.user.dal.mapper.AppUserMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -46,6 +47,7 @@ public class WatchHistoryAdminService {
|
||||
private final AppUserMapper appUserMapper;
|
||||
private final DramaMapper dramaMapper;
|
||||
private final DramaEpisodeMapper dramaEpisodeMapper;
|
||||
private final AppSessionSystemService sessionSystem;
|
||||
|
||||
/** 按后台筛选条件分页查询观看记录。 */
|
||||
public PageResult<AdminWatchHistoryVO> page(WatchHistoryQueryReqVO req) {
|
||||
@@ -125,10 +127,13 @@ public class WatchHistoryAdminService {
|
||||
Map<Long, AppUser> users = loadUsers(rows);
|
||||
Map<Long, Drama> dramas = loadDramas(rows);
|
||||
Map<Long, DramaEpisode> episodes = loadEpisodes(rows);
|
||||
Map<Long, List<AppUserSession>> sessions = sessionSystem.groupByUser(
|
||||
rows.stream().map(WatchHistory::getUserId).distinct().toList());
|
||||
List<AdminWatchHistoryVO> list = new ArrayList<>(rows.size());
|
||||
for (WatchHistory row : rows) {
|
||||
list.add(toVo(row, users.get(row.getUserId()), dramas.get(row.getDramaId()),
|
||||
episodes.get(row.getEpisodeId())));
|
||||
episodes.get(row.getEpisodeId()),
|
||||
sessionSystem.match(sessions.get(row.getUserId()), row.getDeviceId())));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -161,7 +166,7 @@ public class WatchHistoryAdminService {
|
||||
}
|
||||
|
||||
private AdminWatchHistoryVO toVo(WatchHistory row, AppUser user, Drama drama,
|
||||
DramaEpisode episode) {
|
||||
DramaEpisode episode, AppUserSession session) {
|
||||
AdminWatchHistoryVO vo = new AdminWatchHistoryVO();
|
||||
vo.setId(row.getId());
|
||||
vo.setUserId(row.getUserId());
|
||||
@@ -172,6 +177,10 @@ public class WatchHistoryAdminService {
|
||||
vo.setSource(row.getSource());
|
||||
vo.setDeviceId(row.getDeviceId());
|
||||
vo.setWatchedAt(row.getWatchedAt());
|
||||
if (session != null) {
|
||||
vo.setPlatform(session.getPlatform());
|
||||
vo.setOsVersion(session.getOsVersion());
|
||||
}
|
||||
long position = row.getPositionMs() == null ? 0L : row.getPositionMs();
|
||||
long duration = row.getDurationMs() == null ? 0L : row.getDurationMs();
|
||||
vo.setFinished(duration > 0L && position + FINISHED_TOLERANCE_MS >= duration);
|
||||
|
||||
@@ -29,5 +29,9 @@ public class AdminWatchHistoryVO {
|
||||
private Boolean finished;
|
||||
private String source;
|
||||
private String deviceId;
|
||||
/** ANDROID / IOS / WEB,来自该次设备的登录会话。 */
|
||||
private String platform;
|
||||
/** 系统版本,例如 Android 16。 */
|
||||
private String osVersion;
|
||||
private LocalDateTime watchedAt;
|
||||
}
|
||||
+4
@@ -28,5 +28,9 @@ public class AppUserWatchHistoryVO {
|
||||
private Boolean finished;
|
||||
private String source;
|
||||
private String deviceId;
|
||||
/** ANDROID / IOS / WEB,来自该次设备的登录会话。 */
|
||||
private String platform;
|
||||
/** 系统版本。 */
|
||||
private String osVersion;
|
||||
private LocalDateTime watchedAt;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.vo;
|
||||
|
||||
import com.fruitshorts.media.vo.MediaRenditionRespVO;
|
||||
import com.fruitshorts.media.vo.MediaThumbnailRespVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/** 后台剧集编辑页一次性获取的转码状态。 */
|
||||
@Data
|
||||
@Schema(description = "分集转码聚合信息")
|
||||
public class EpisodeTranscodeRespVO {
|
||||
|
||||
private String episodeId;
|
||||
private String mediaAssetId;
|
||||
private String taskId;
|
||||
private String status;
|
||||
private Integer progress;
|
||||
private Integer retryCount;
|
||||
private String errorMsg;
|
||||
private LocalDateTime updatedAt;
|
||||
private List<MediaRenditionRespVO> renditions = List.of();
|
||||
private MediaThumbnailRespVO thumbnails;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.vo;
|
||||
|
||||
import com.fruitshorts.media.vo.TranscodeQueueStatsVO;
|
||||
import com.fruitshorts.media.vo.TranscodeTaskRespVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/** 后台转码看板强类型响应。 */
|
||||
@Data
|
||||
@Schema(description = "转码看板")
|
||||
public class TranscodeDashboardRespVO {
|
||||
|
||||
private LocalDateTime generatedAt;
|
||||
private TranscodeQueueStatsVO queue;
|
||||
private List<TranscodeTaskRespVO> failedTasks = List.of();
|
||||
private List<String> notes = List.of();
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.admin.service.DashboardService;
|
||||
import com.fruitshorts.admin.support.ControllerContractSupport;
|
||||
import com.fruitshorts.admin.vo.TranscodeDashboardRespVO;
|
||||
import com.fruitshorts.media.vo.TranscodeQueueStatsVO;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class DashboardTranscodeContractTest {
|
||||
|
||||
private DashboardService dashboardService;
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
dashboardService = mock(DashboardService.class);
|
||||
mockMvc = ControllerContractSupport.mockMvcOf(
|
||||
new DashboardAdminController(dashboardService));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_typed_queue_and_failed_tasks() throws Exception {
|
||||
TranscodeQueueStatsVO queue = new TranscodeQueueStatsVO(
|
||||
10L, 2L, 1L, 5L, 1L, 1L, 20L);
|
||||
TranscodeDashboardRespVO vo = new TranscodeDashboardRespVO();
|
||||
vo.setQueue(queue);
|
||||
vo.setFailedTasks(List.of());
|
||||
vo.setNotes(List.of("queue total"));
|
||||
given(dashboardService.transcode()).willReturn(vo);
|
||||
|
||||
mockMvc.perform(get("/admin/dashboard/transcode"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.queue.total").value(10))
|
||||
.andExpect(jsonPath("$.data.queue.queued").value(2))
|
||||
.andExpect(jsonPath("$.data.queue.running").value(1))
|
||||
.andExpect(jsonPath("$.data.queue.success").value(5))
|
||||
.andExpect(jsonPath("$.data.queue.failed").value(1))
|
||||
.andExpect(jsonPath("$.data.failedTasks").isArray());
|
||||
}
|
||||
}
|
||||
+101
-16
@@ -3,6 +3,7 @@
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.admin.support.ControllerContractSupport;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
@@ -10,20 +11,30 @@ import com.fruitshorts.content.vo.EpisodeRespVO;
|
||||
import com.fruitshorts.interaction.service.CommentService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/** K89:后台剧集列表按集回填点赞/评论,并带所属剧收藏/热度。 */
|
||||
/** 后台剧集列表:互动数量回填 + 分页契约。 */
|
||||
class EpisodeControllerContractTest {
|
||||
|
||||
private static final long DRAMA_ID = 5L;
|
||||
private static final int DEFAULT_PAGE_SIZE = 100;
|
||||
|
||||
private EpisodeService episodeService;
|
||||
private CommentService commentService;
|
||||
private DramaService dramaService;
|
||||
@@ -36,34 +47,108 @@ class EpisodeControllerContractTest {
|
||||
dramaService = mock(DramaService.class);
|
||||
mockMvc = ControllerContractSupport.mockMvcOf(
|
||||
new EpisodeController(episodeService, commentService, dramaService));
|
||||
Drama drama = new Drama();
|
||||
drama.setFavoriteCount(88L);
|
||||
drama.setViewCount(1000L);
|
||||
given(dramaService.getExisting(DRAMA_ID)).willReturn(drama);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_episode_and_drama_interaction_counts() throws Exception {
|
||||
given(episodeService.listByDrama(5L, null)).willReturn(List.of(
|
||||
episode(11L, 10L),
|
||||
episode(12L, 20L)));
|
||||
given(episodeService.pageByDrama(eq(DRAMA_ID), isNull(), isNull(), isNull()))
|
||||
.willReturn(new PageResult<>(2L, List.of(episode(11L, 10L), episode(12L, 20L))));
|
||||
given(commentService.countByEpisodes(List.of(11L, 12L)))
|
||||
.willReturn(Map.of(11L, 3L));
|
||||
Drama drama = new Drama();
|
||||
drama.setFavoriteCount(88L);
|
||||
drama.setViewCount(1000L);
|
||||
given(dramaService.getExisting(5L)).willReturn(drama);
|
||||
|
||||
mockMvc.perform(get("/admin/episodes").param("dramaId", "5"))
|
||||
mockMvc.perform(get("/admin/episodes").param("dramaId", String.valueOf(DRAMA_ID)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data[0].likeCount").value("10"))
|
||||
.andExpect(jsonPath("$.data[0].commentCount").value("3"))
|
||||
.andExpect(jsonPath("$.data[0].favoriteCount").value("88"))
|
||||
.andExpect(jsonPath("$.data[0].heat").value("1000"))
|
||||
.andExpect(jsonPath("$.data[1].likeCount").value("20"))
|
||||
.andExpect(jsonPath("$.data[1].commentCount").value("0"));
|
||||
.andExpect(jsonPath("$.data.total").value(2))
|
||||
.andExpect(jsonPath("$.data.list[0].likeCount").value("10"))
|
||||
.andExpect(jsonPath("$.data.list[0].commentCount").value("3"))
|
||||
.andExpect(jsonPath("$.data.list[0].favoriteCount").value("88"))
|
||||
.andExpect(jsonPath("$.data.list[0].heat").value("1000"))
|
||||
.andExpect(jsonPath("$.data.list[1].likeCount").value("20"))
|
||||
.andExpect(jsonPath("$.data.list[1].commentCount").value("0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_use_default_page_size_100_when_page_size_omitted() throws Exception {
|
||||
given(episodeService.pageByDrama(eq(DRAMA_ID), isNull(), isNull(), isNull()))
|
||||
.willReturn(PageResult.empty());
|
||||
given(commentService.countByEpisodes(List.of())).willReturn(Map.of());
|
||||
|
||||
mockMvc.perform(get("/admin/episodes").param("dramaId", String.valueOf(DRAMA_ID)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.total").value(0))
|
||||
.andExpect(jsonPath("$.data.list").isArray())
|
||||
.andExpect(jsonPath("$.data.list").isEmpty());
|
||||
|
||||
ArgumentCaptor<Integer> pageIndexCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||
ArgumentCaptor<Integer> pageSizeCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||
verify(episodeService).pageByDrama(
|
||||
eq(DRAMA_ID), isNull(), pageIndexCaptor.capture(), pageSizeCaptor.capture());
|
||||
assertThat(pageIndexCaptor.getValue()).isNull();
|
||||
assertThat(pageSizeCaptor.getValue()).isNull();
|
||||
assertThat(DEFAULT_PAGE_SIZE).isEqualTo(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_non_overlapping_ids_when_second_page_requested() throws Exception {
|
||||
List<EpisodeRespVO> page1 = List.of(episode(1L, 1L), episode(2L, 2L));
|
||||
List<EpisodeRespVO> page2 = List.of(episode(3L, 3L), episode(4L, 4L));
|
||||
given(episodeService.pageByDrama(DRAMA_ID, null, 1, 2))
|
||||
.willReturn(new PageResult<>(4L, page1));
|
||||
given(episodeService.pageByDrama(DRAMA_ID, null, 2, 2))
|
||||
.willReturn(new PageResult<>(4L, page2));
|
||||
given(commentService.countByEpisodes(List.of(1L, 2L))).willReturn(Map.of());
|
||||
given(commentService.countByEpisodes(List.of(3L, 4L))).willReturn(Map.of());
|
||||
|
||||
mockMvc.perform(get("/admin/episodes")
|
||||
.param("dramaId", String.valueOf(DRAMA_ID))
|
||||
.param("pageIndex", "1")
|
||||
.param("pageSize", "2"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.total").value(4))
|
||||
.andExpect(jsonPath("$.data.list.length()").value(2));
|
||||
|
||||
String page2Body = mockMvc.perform(get("/admin/episodes")
|
||||
.param("dramaId", String.valueOf(DRAMA_ID))
|
||||
.param("pageIndex", "2")
|
||||
.param("pageSize", "2"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.total").value(4))
|
||||
.andExpect(jsonPath("$.data.list[0].id").value("3"))
|
||||
.andExpect(jsonPath("$.data.list[1].id").value("4"))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
Set<Long> page1Ids = page1.stream().map(EpisodeRespVO::getId).collect(Collectors.toSet());
|
||||
Set<Long> page2Ids = page2.stream().map(EpisodeRespVO::getId).collect(Collectors.toSet());
|
||||
assertThat(page1Ids).doesNotContainAnyElementsOf(page2Ids);
|
||||
assertThat(page2Body).contains("\"id\":\"3\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_empty_list_with_correct_total_when_page_out_of_range() throws Exception {
|
||||
given(episodeService.pageByDrama(DRAMA_ID, null, 99, 100))
|
||||
.willReturn(new PageResult<>(5L, List.of()));
|
||||
given(commentService.countByEpisodes(List.of())).willReturn(Map.of());
|
||||
|
||||
mockMvc.perform(get("/admin/episodes")
|
||||
.param("dramaId", String.valueOf(DRAMA_ID))
|
||||
.param("pageIndex", "99")
|
||||
.param("pageSize", "100"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.total").value(5))
|
||||
.andExpect(jsonPath("$.data.list").isArray())
|
||||
.andExpect(jsonPath("$.data.list").isEmpty());
|
||||
}
|
||||
|
||||
private EpisodeRespVO episode(Long id, Long likeCount) {
|
||||
EpisodeRespVO episode = new EpisodeRespVO();
|
||||
episode.setId(id);
|
||||
episode.setDramaId(5L);
|
||||
episode.setDramaId(DRAMA_ID);
|
||||
episode.setLikeCount(likeCount);
|
||||
return episode;
|
||||
}
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.admin.service.EpisodeTranscodeAdminService;
|
||||
import com.fruitshorts.admin.support.ControllerContractSupport;
|
||||
import com.fruitshorts.admin.vo.EpisodeTranscodeRespVO;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class EpisodeTranscodeContractTest {
|
||||
|
||||
private EpisodeTranscodeAdminService service;
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = mock(EpisodeTranscodeAdminService.class);
|
||||
mockMvc = ControllerContractSupport.mockMvcOf(
|
||||
new EpisodeTranscodeController(service));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_aggregated_episode_transcode_state() throws Exception {
|
||||
String episodeId = "2113150431755636737";
|
||||
String mediaAssetId = "2113150398670966786";
|
||||
String taskId = "2113150398935207938";
|
||||
EpisodeTranscodeRespVO vo = new EpisodeTranscodeRespVO();
|
||||
vo.setEpisodeId(episodeId);
|
||||
vo.setMediaAssetId(mediaAssetId);
|
||||
vo.setTaskId(taskId);
|
||||
vo.setStatus("SUCCESS");
|
||||
vo.setProgress(100);
|
||||
vo.setUpdatedAt(LocalDateTime.of(2026, 10, 22, 15, 10));
|
||||
given(service.detail(Long.parseLong(episodeId))).willReturn(vo);
|
||||
|
||||
mockMvc.perform(get("/admin/episodes/" + episodeId + "/transcode"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
.andExpect(jsonPath("$.data.episodeId").value(episodeId))
|
||||
.andExpect(jsonPath("$.data.mediaAssetId").value(mediaAssetId))
|
||||
.andExpect(jsonPath("$.data.taskId").value(taskId))
|
||||
.andExpect(jsonPath("$.data.status").value("SUCCESS"))
|
||||
.andExpect(jsonPath("$.data.progress").value(100))
|
||||
.andExpect(jsonPath("$.data.updatedAt").value("2026-10-22T15:10:00"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_explicit_empty_state_when_episode_has_no_video() throws Exception {
|
||||
EpisodeTranscodeRespVO vo = new EpisodeTranscodeRespVO();
|
||||
vo.setEpisodeId("31");
|
||||
vo.setStatus("NO_VIDEO");
|
||||
given(service.detail(31L)).willReturn(vo);
|
||||
|
||||
mockMvc.perform(get("/admin/episodes/31/transcode"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.status").value("NO_VIDEO"))
|
||||
.andExpect(jsonPath("$.data.renditions").isEmpty());
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.admin.support.ControllerContractSupport;
|
||||
import com.fruitshorts.common.exception.ErrorCode;
|
||||
import com.fruitshorts.common.exception.ServiceException;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.media.service.MediaTranscodeOutputService;
|
||||
import com.fruitshorts.media.vo.MediaRenditionRespVO;
|
||||
import com.fruitshorts.media.vo.MediaThumbnailRespVO;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class MediaTranscodeOutputContractTest {
|
||||
|
||||
private MediaTranscodeOutputService outputService;
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
outputService = mock(MediaTranscodeOutputService.class);
|
||||
mockMvc = ControllerContractSupport.mockMvcOf(
|
||||
new MediaTranscodeOutputController(outputService));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_typed_rendition_list() throws Exception {
|
||||
MediaRenditionRespVO vo = new MediaRenditionRespVO();
|
||||
vo.setQuality("1080p");
|
||||
vo.setQualityName("1080P");
|
||||
vo.setResolution("1920x1080");
|
||||
vo.setVideoBitrateKbps(5000);
|
||||
vo.setVideoCodec("H.264");
|
||||
vo.setAudioCodec("AAC");
|
||||
vo.setContainer("HLS");
|
||||
vo.setHlsUrl("/files/master.m3u8");
|
||||
vo.setSizeBytes(4096L);
|
||||
vo.setStatus("ready");
|
||||
given(outputService.renditions(88L)).willReturn(List.of(vo));
|
||||
|
||||
mockMvc.perform(get("/admin/media/88/renditions"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
.andExpect(jsonPath("$.data[0].quality").value("1080p"))
|
||||
.andExpect(jsonPath("$.data[0].resolution").value("1920x1080"))
|
||||
.andExpect(jsonPath("$.data[0].videoBitrateKbps").value(5000))
|
||||
.andExpect(jsonPath("$.data[0].hlsUrl").value("/files/master.m3u8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_not_found_for_missing_media() throws Exception {
|
||||
given(outputService.renditions(404L))
|
||||
.willThrow(new ServiceException(ErrorCode.DATA_NOT_FOUND, "媒资不存在"));
|
||||
|
||||
mockMvc.perform(get("/admin/media/404/renditions"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.DATA_NOT_FOUND.getCode()))
|
||||
.andExpect(jsonPath("$.message").value("媒资不存在"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_empty_thumbnail_status_without_error() throws Exception {
|
||||
MediaThumbnailRespVO vo = new MediaThumbnailRespVO();
|
||||
vo.setStatus("EMPTY");
|
||||
vo.setPageIndex(1);
|
||||
vo.setPageSize(100);
|
||||
vo.setFrames(PageResult.empty());
|
||||
given(outputService.thumbnails(88L, 1, 100)).willReturn(vo);
|
||||
|
||||
mockMvc.perform(get("/admin/media/88/thumbnails"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
.andExpect(jsonPath("$.data.status").value("EMPTY"))
|
||||
.andExpect(jsonPath("$.data.frames.total").value(0))
|
||||
.andExpect(jsonPath("$.data.frames.list").isEmpty());
|
||||
|
||||
verify(outputService).thumbnails(88L, 1, 100);
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fruitshorts.admin.support.ControllerContractSupport;
|
||||
import com.fruitshorts.media.config.MediaTranscodeProfile;
|
||||
import com.fruitshorts.media.config.TranscodeProperties;
|
||||
import com.fruitshorts.media.service.MediaService;
|
||||
import com.fruitshorts.media.service.MediaTranscodeProfileService;
|
||||
import com.fruitshorts.system.service.ConfigService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* 后台转码配置接口:默认值、非法拒绝与成功落库。
|
||||
*/
|
||||
class MediaTranscodeProfileContractTest {
|
||||
|
||||
private ConfigService configService;
|
||||
private ObjectMapper objectMapper;
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
configService = mock(ConfigService.class);
|
||||
objectMapper = new ObjectMapper();
|
||||
MediaTranscodeProfileService profileService = new MediaTranscodeProfileService(
|
||||
configService, objectMapper, new TranscodeProperties());
|
||||
MediaController controller = new MediaController(mock(MediaService.class), profileService);
|
||||
mockMvc = ControllerContractSupport.mockMvcOf(controller);
|
||||
given(configService.get(eq(MediaTranscodeProfileService.CONFIG_KEY), anyString()))
|
||||
.willReturn("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_default_profile_when_config_is_missing() throws Exception {
|
||||
mockMvc.perform(get("/admin/media/transcode-profile"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
.andExpect(jsonPath("$.data.segmentSeconds").value(6))
|
||||
.andExpect(jsonPath("$.data.ladder.length()").value(4))
|
||||
.andExpect(jsonPath("$.data.ladder[0].quality").value("360p"))
|
||||
.andExpect(jsonPath("$.data.sprite.columns").value(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_reject_illegal_profile_without_writing_config() throws Exception {
|
||||
MediaTranscodeProfile profile = new MediaTranscodeProfile();
|
||||
profile.getLadder().get(0).setWidth(641);
|
||||
|
||||
mockMvc.perform(put("/admin/media/transcode-profile")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(profile)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(400))
|
||||
.andExpect(jsonPath("$.message").value("宽高必须为正偶数"));
|
||||
|
||||
verify(configService, never()).update(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_persist_profile_when_request_is_valid() throws Exception {
|
||||
MediaTranscodeProfile profile = new MediaTranscodeProfile();
|
||||
profile.setSegmentSeconds(4);
|
||||
|
||||
mockMvc.perform(put("/admin/media/transcode-profile")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(profile)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
.andExpect(jsonPath("$.data.segmentSeconds").value(4));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Map<String, String>> captor = ArgumentCaptor.forClass(Map.class);
|
||||
verify(configService).update(captor.capture());
|
||||
assertThat(captor.getValue().get(MediaTranscodeProfileService.CONFIG_KEY))
|
||||
.contains("\"segmentSeconds\":4");
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.admin.support.ControllerContractSupport;
|
||||
import com.fruitshorts.common.exception.ErrorCode;
|
||||
import com.fruitshorts.common.exception.ServiceException;
|
||||
import com.fruitshorts.media.service.MediaService;
|
||||
import com.fruitshorts.media.service.MediaTranscodeProfileService;
|
||||
import com.fruitshorts.media.service.TranscodeService;
|
||||
import com.fruitshorts.media.vo.TranscodeTriggerRespVO;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* 后台手动触发转码的最小契约。
|
||||
*/
|
||||
class MediaTranscodeTriggerContractTest {
|
||||
|
||||
private MediaService mediaService;
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mediaService = mock(MediaService.class);
|
||||
MediaController controller = new MediaController(
|
||||
mediaService, mock(MediaTranscodeProfileService.class));
|
||||
mockMvc = ControllerContractSupport.mockMvcOf(controller);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_task_id_and_status_when_triggering_transcode() throws Exception {
|
||||
given(mediaService.triggerTranscode(88L))
|
||||
.willReturn(new TranscodeTriggerRespVO(100L, TranscodeService.STATUS_QUEUED));
|
||||
|
||||
mockMvc.perform(post("/admin/media/88/transcode"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
.andExpect(jsonPath("$.data.taskId").value("100"))
|
||||
.andExpect(jsonPath("$.data.status").value(TranscodeService.STATUS_QUEUED));
|
||||
|
||||
verify(mediaService).triggerTranscode(88L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_keep_not_found_semantics_when_media_does_not_exist() throws Exception {
|
||||
given(mediaService.triggerTranscode(404L))
|
||||
.willThrow(new ServiceException(ErrorCode.DATA_NOT_FOUND, "媒资不存在"));
|
||||
|
||||
mockMvc.perform(post("/admin/media/404/transcode"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(ErrorCode.DATA_NOT_FOUND.getCode()))
|
||||
.andExpect(jsonPath("$.message").value("媒资不存在"));
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.service;
|
||||
|
||||
import com.fruitshorts.user.dal.entity.AppUserSession;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/** 观看记录匹配登录系统。 */
|
||||
class AppSessionSystemServiceTest {
|
||||
|
||||
private final AppSessionSystemService service = new AppSessionSystemService(null);
|
||||
|
||||
@Test
|
||||
void should_use_same_device_session_when_watch_history_has_device() {
|
||||
AppUserSession older = session("device-1", "ANDROID", "14", null);
|
||||
AppUserSession newer = session("device-2", "IOS", "18", null);
|
||||
|
||||
AppUserSession matched = service.match(List.of(newer, older), "device-1");
|
||||
|
||||
assertThat(matched.getPlatform()).isEqualTo("ANDROID");
|
||||
assertThat(matched.getOsVersion()).isEqualTo("14");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_use_active_session_when_device_does_not_match() {
|
||||
AppUserSession revoked = session("device-9", "WEB", "1", LocalDateTime.now());
|
||||
AppUserSession active = session("device-2", "IOS", "18", null);
|
||||
|
||||
AppUserSession matched = service.match(List.of(revoked, active), "missing");
|
||||
|
||||
assertThat(matched.getPlatform()).isEqualTo("IOS");
|
||||
}
|
||||
|
||||
private AppUserSession session(String deviceId, String platform, String osVersion,
|
||||
LocalDateTime revokedAt) {
|
||||
AppUserSession session = new AppUserSession();
|
||||
session.setDeviceId(deviceId);
|
||||
session.setPlatform(platform);
|
||||
session.setOsVersion(osVersion);
|
||||
session.setRevokedAt(revokedAt);
|
||||
return session;
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.service;
|
||||
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.dal.mapper.DramaEpisodeMapper;
|
||||
import com.fruitshorts.media.service.MediaTranscodeOutputService;
|
||||
import com.fruitshorts.media.vo.MediaThumbnailRespVO;
|
||||
import com.fruitshorts.media.vo.TranscodeTaskRespVO;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
class EpisodeTranscodeAdminServiceTest {
|
||||
|
||||
private static final Long EPISODE_ID = 2113150431755636737L;
|
||||
private static final Long MEDIA_ASSET_ID = 2113150398670966786L;
|
||||
private static final Long TASK_ID = 2113150398935207938L;
|
||||
|
||||
private DramaEpisodeMapper episodeMapper;
|
||||
private MediaTranscodeOutputService outputService;
|
||||
private EpisodeTranscodeAdminService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
episodeMapper = mock(DramaEpisodeMapper.class);
|
||||
outputService = mock(MediaTranscodeOutputService.class);
|
||||
service = new EpisodeTranscodeAdminService(episodeMapper, outputService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_episode_not_found_state_without_aggregating_media() {
|
||||
given(episodeMapper.selectById(404L)).willReturn(null);
|
||||
|
||||
var result = service.detail(404L);
|
||||
|
||||
assertThat(result.getStatus()).isEqualTo("EPISODE_NOT_FOUND");
|
||||
assertThat(result.getEpisodeId()).isEqualTo("404");
|
||||
assertThat(result.getRenditions()).isEmpty();
|
||||
verifyNoInteractions(outputService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_no_video_state_when_episode_video_url_is_blank() {
|
||||
DramaEpisode episode = new DramaEpisode();
|
||||
episode.setId(31L);
|
||||
episode.setVideoUrl("");
|
||||
given(episodeMapper.selectById(31L)).willReturn(episode);
|
||||
|
||||
var result = service.detail(31L);
|
||||
|
||||
assertThat(result.getStatus()).isEqualTo("NO_VIDEO");
|
||||
assertThat(result.getRenditions()).isEmpty();
|
||||
verifyNoInteractions(outputService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_exact_snowflake_media_asset_id_as_string() {
|
||||
DramaEpisode episode = episode(MEDIA_ASSET_ID);
|
||||
given(episodeMapper.selectById(EPISODE_ID)).willReturn(episode);
|
||||
given(outputService.resolveMediaAssetId(episode.getVideoUrl())).willReturn(null);
|
||||
given(outputService.mediaAssetExists(MEDIA_ASSET_ID)).willReturn(true);
|
||||
given(outputService.renditionsForMediaAssetId(MEDIA_ASSET_ID)).willReturn(List.of());
|
||||
given(outputService.thumbnailForEpisode(
|
||||
EPISODE_ID, MEDIA_ASSET_ID, 1, 100))
|
||||
.willReturn(MediaThumbnailRespVO.empty(
|
||||
MEDIA_ASSET_ID, EPISODE_ID,
|
||||
MediaThumbnailRespVO.STATUS_EMPTY, 1, 100));
|
||||
TranscodeTaskRespVO task = new TranscodeTaskRespVO();
|
||||
task.setId(TASK_ID);
|
||||
task.setMediaAssetId(MEDIA_ASSET_ID);
|
||||
task.setStatus("SUCCESS");
|
||||
task.setProgress(100);
|
||||
task.setUpdatedAt(LocalDateTime.of(2026, 10, 22, 15, 10));
|
||||
given(outputService.latestTask(MEDIA_ASSET_ID)).willReturn(task);
|
||||
|
||||
var result = service.detail(EPISODE_ID);
|
||||
|
||||
assertThat(result.getEpisodeId()).isEqualTo("2113150431755636737");
|
||||
assertThat(result.getMediaAssetId()).isEqualTo("2113150398670966786");
|
||||
assertThat(result.getTaskId()).isEqualTo("2113150398935207938");
|
||||
assertThat(result.getUpdatedAt()).isEqualTo(task.getUpdatedAt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_explicit_empty_state_when_episode_media_is_missing() {
|
||||
DramaEpisode episode = episode(MEDIA_ASSET_ID);
|
||||
given(episodeMapper.selectById(EPISODE_ID)).willReturn(episode);
|
||||
given(outputService.mediaAssetExists(MEDIA_ASSET_ID)).willReturn(false);
|
||||
given(outputService.resolveMediaAssetId(episode.getVideoUrl())).willReturn(null);
|
||||
|
||||
var result = service.detail(EPISODE_ID);
|
||||
|
||||
assertThat(result.getMediaAssetId()).isNull();
|
||||
assertThat(result.getStatus()).isEqualTo("NO_MEDIA_ASSET");
|
||||
assertThat(result.getErrorMsg()).isNotBlank();
|
||||
assertThat(result.getRenditions()).isEmpty();
|
||||
}
|
||||
|
||||
private DramaEpisode episode(Long videoAssetId) {
|
||||
DramaEpisode episode = new DramaEpisode();
|
||||
episode.setId(EPISODE_ID);
|
||||
episode.setDramaId(7L);
|
||||
episode.setDurationSec(120);
|
||||
episode.setVideoAssetId(videoAssetId);
|
||||
episode.setVideoUrl("/files/episode/202610/video.mp4");
|
||||
return episode;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -58,7 +58,7 @@ class WatchHistoryAdminServiceTest {
|
||||
dramaMapper = mock(DramaMapper.class);
|
||||
dramaEpisodeMapper = mock(DramaEpisodeMapper.class);
|
||||
service = new WatchHistoryAdminService(watchHistoryMapper, appUserMapper, dramaMapper,
|
||||
dramaEpisodeMapper);
|
||||
dramaEpisodeMapper, mock(AppSessionSystemService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class AppAuthController {
|
||||
@Operation(summary = "刷新令牌(旧 refresh token 立即失效)")
|
||||
@PostMapping("/refresh")
|
||||
public Result<TokenRespVO> refresh(@Valid @RequestBody RefreshReqVO req) {
|
||||
return Result.ok(authService.refresh(req.getRefreshToken()));
|
||||
return Result.ok(authService.refresh(req.getRefreshToken(), req.getPlatform(), req.getOsVersion()));
|
||||
}
|
||||
|
||||
/** 登出:默认只吊销当前设备的会话,allDevices=true 时吊销全部。 */
|
||||
|
||||
+3
-2
@@ -41,13 +41,14 @@ public class AppCatalogController {
|
||||
return Result.ok(appCatalogService.discoverFeed());
|
||||
}
|
||||
|
||||
@Operation(summary = "推荐流:支持内容类型多选与游标翻页")
|
||||
@Operation(summary = "推荐流:支持内容类型、分类过滤与游标翻页")
|
||||
@GetMapping("/feed")
|
||||
public Result<CursorResult<AppDramaCardVO>> feed(
|
||||
@RequestParam(required = false) String types,
|
||||
@RequestParam(required = false) Long categoryId,
|
||||
@RequestParam(required = false) Long cursor,
|
||||
@RequestParam(required = false) Integer size) {
|
||||
return Result.ok(appCatalogService.feed(types, cursor, size));
|
||||
return Result.ok(appCatalogService.feed(types, categoryId, cursor, size));
|
||||
}
|
||||
|
||||
@Operation(summary = "分类列表")
|
||||
|
||||
+11
-5
@@ -4,9 +4,12 @@ package com.fruitshorts.app.controller;
|
||||
|
||||
import com.fruitshorts.app.service.AppCatalogService;
|
||||
import com.fruitshorts.app.vo.AppDramaCardVO;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.framework.security.SecurityUtils;
|
||||
import com.fruitshorts.playback.service.FavoriteService;
|
||||
import com.fruitshorts.playback.vo.FavoriteRemoveReqVO;
|
||||
import com.fruitshorts.playback.vo.FavoriteToggleReqVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -18,10 +21,9 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 收藏。 */
|
||||
@Tag(name = "客户端-收藏")
|
||||
@RestController
|
||||
@@ -42,9 +44,13 @@ public class AppFavoriteController {
|
||||
/** 收藏列表,卡片结构与首页一致。 */
|
||||
@Operation(summary = "我的收藏列表")
|
||||
@GetMapping
|
||||
public Result<List<AppDramaCardVO>> list() {
|
||||
return Result.ok(appCatalogService.toCards(
|
||||
favoriteService.listDramas(SecurityUtils.getAppUserId())));
|
||||
public Result<PageResult<AppDramaCardVO>> list(
|
||||
@RequestParam(defaultValue = "1") int pageIndex,
|
||||
@RequestParam(defaultValue = "20") int pageSize) {
|
||||
PageResult<Drama> page = favoriteService.page(
|
||||
SecurityUtils.getAppUserId(), pageIndex, pageSize);
|
||||
return Result.ok(new PageResult<>(
|
||||
page.getTotal(), appCatalogService.toCards(page.getList())));
|
||||
}
|
||||
|
||||
@Operation(summary = "取消收藏")
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/** 客户端搜索:按标题或简介模糊匹配已上线短剧。 */
|
||||
/** 客户端搜索:按标题或简介模糊匹配已上线短剧。不需要登录。 */
|
||||
@Tag(name = "客户端-搜索")
|
||||
@RestController
|
||||
@RequestMapping("/app")
|
||||
|
||||
+8
-5
@@ -2,6 +2,7 @@
|
||||
|
||||
package com.fruitshorts.app.controller;
|
||||
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.common.pojo.Result;
|
||||
import com.fruitshorts.framework.security.SecurityUtils;
|
||||
import com.fruitshorts.playback.service.WatchProgressService;
|
||||
@@ -20,8 +21,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 观看进度与观看记录。 */
|
||||
@Tag(name = "客户端-观看进度")
|
||||
@RestController
|
||||
@@ -45,10 +44,14 @@ public class AppWatchController {
|
||||
return Result.ok(progressService.ofDrama(SecurityUtils.getAppUserId(), dramaId));
|
||||
}
|
||||
|
||||
@Operation(summary = "最近观看列表")
|
||||
/** 最近观看分页,契约与 /app/favorites 一致:pageIndex/pageSize。 */
|
||||
@Operation(summary = "最近观看分页")
|
||||
@GetMapping("/recent")
|
||||
public Result<List<ProgressRespVO>> recent(@RequestParam(defaultValue = "20") int limit) {
|
||||
return Result.ok(progressService.recent(SecurityUtils.getAppUserId(), limit));
|
||||
public Result<PageResult<ProgressRespVO>> recent(
|
||||
@RequestParam(defaultValue = "1") int pageIndex,
|
||||
@RequestParam(defaultValue = "20") int pageSize) {
|
||||
return Result.ok(progressService.recentPage(
|
||||
SecurityUtils.getAppUserId(), pageIndex, pageSize));
|
||||
}
|
||||
|
||||
@Operation(summary = "删除某部剧的观看记录")
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.app.controller;
|
||||
|
||||
import com.fruitshorts.system.service.LegalDocumentService;
|
||||
import com.fruitshorts.system.service.LegalPages;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 协议公开页。客户端按当前语言打开 /privacy/zh 或 /terms/en,不需要登录。
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class LegalPageController {
|
||||
|
||||
private static final MediaType HTML = MediaType.parseMediaType("text/html;charset=UTF-8");
|
||||
|
||||
private final LegalDocumentService legalDocumentService;
|
||||
|
||||
/** 隐私协议。语言只接受 zh、en、id。 */
|
||||
@GetMapping("/" + LegalPages.PATH_PRIVACY + "/{lang}")
|
||||
public ResponseEntity<String> privacy(@PathVariable String lang) {
|
||||
return page(LegalPages.PATH_PRIVACY, lang);
|
||||
}
|
||||
|
||||
/** 服务条款。语言只接受 zh、en、id。 */
|
||||
@GetMapping("/" + LegalPages.PATH_TERMS + "/{lang}")
|
||||
public ResponseEntity<String> terms(@PathVariable String lang) {
|
||||
return page(LegalPages.PATH_TERMS, lang);
|
||||
}
|
||||
|
||||
private ResponseEntity<String> page(String path, String lang) {
|
||||
String html = legalDocumentService.render(path, lang);
|
||||
if (html == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
return ResponseEntity.ok().contentType(HTML).body(html);
|
||||
}
|
||||
}
|
||||
+20
-7
@@ -20,6 +20,7 @@ import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.interaction.service.CommentService;
|
||||
import com.fruitshorts.media.service.PlaybackSigner;
|
||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||
import com.fruitshorts.content.vo.DramaCategoryRespVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -50,6 +51,7 @@ public class AppCatalogService {
|
||||
private final DramaCategoryService dramaCategoryService;
|
||||
private final PlaybackSigner playbackSigner;
|
||||
private final CommentService commentService;
|
||||
private final ThumbnailUrlResolver thumbnailUrlResolver;
|
||||
|
||||
public AppFeedVO homeFeed() {
|
||||
Map<Long, String> categoryNames = categoryNameMap();
|
||||
@@ -74,7 +76,8 @@ public class AppCatalogService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public CursorResult<AppDramaCardVO> feed(String types, Long cursor, Integer size) {
|
||||
public CursorResult<AppDramaCardVO> feed(
|
||||
String types, Long categoryId, Long cursor, Integer size) {
|
||||
int pageSize = size == null ? DEFAULT_FEED_SIZE : Math.max(1, Math.min(size, MAX_FEED_SIZE));
|
||||
List<String> dramaTypes = types == null
|
||||
? List.of()
|
||||
@@ -82,7 +85,8 @@ public class AppCatalogService {
|
||||
.map(String::trim)
|
||||
.filter(type -> !type.isEmpty())
|
||||
.toList();
|
||||
List<Drama> rows = dramaService.listPublishedFeed(dramaTypes, cursor, pageSize + 1);
|
||||
List<Drama> rows = dramaService.listPublishedFeed(
|
||||
dramaTypes, categoryId, cursor, pageSize + 1);
|
||||
if (rows.isEmpty()) {
|
||||
return CursorResult.empty();
|
||||
}
|
||||
@@ -108,6 +112,8 @@ public class AppCatalogService {
|
||||
List<DramaEpisode> episodes = episodeService.listPublishedByDrama(dramaId);
|
||||
Map<Long, Long> episodeCommentCounts = commentService.countByEpisodes(
|
||||
episodes.stream().map(DramaEpisode::getId).sorted().toList());
|
||||
Map<Long, String> thumbnailUrls = thumbnailUrlResolver.resolveAll(
|
||||
episodes.stream().map(DramaEpisode::getId).sorted().toList());
|
||||
String categoryName = categoryNameMap().getOrDefault(drama.getCategoryId(), "");
|
||||
|
||||
AppDramaDetailVO detail = new AppDramaDetailVO();
|
||||
@@ -126,7 +132,7 @@ public class AppCatalogService {
|
||||
detail.setFavoriteCount(drama.getFavoriteCount());
|
||||
detail.setCommentCount(commentService.countByDrama(dramaId));
|
||||
detail.setEpisodes(episodes.stream()
|
||||
.map(episode -> toEpisode(episode, episodeCommentCounts))
|
||||
.map(episode -> toEpisode(episode, episodeCommentCounts, thumbnailUrls))
|
||||
.toList());
|
||||
return detail;
|
||||
}
|
||||
@@ -174,14 +180,18 @@ public class AppCatalogService {
|
||||
Map<Long, DramaEpisode> previews = episodeService.firstPlayableByDramas(ids);
|
||||
Map<Long, Long> commentCounts = commentService.countByEpisodes(
|
||||
previews.values().stream().map(DramaEpisode::getId).sorted().toList());
|
||||
Map<Long, String> thumbnailUrls = thumbnailUrlResolver.resolveAll(
|
||||
previews.values().stream().map(DramaEpisode::getId).sorted().toList());
|
||||
return dramas.stream()
|
||||
.map(drama -> toCard(
|
||||
drama, categoryNames, previews.get(drama.getId()), commentCounts))
|
||||
drama, categoryNames, previews.get(drama.getId()), commentCounts,
|
||||
thumbnailUrls))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private AppDramaCardVO toCard(Drama drama, Map<Long, String> categoryNames,
|
||||
DramaEpisode preview, Map<Long, Long> commentCounts) {
|
||||
DramaEpisode preview, Map<Long, Long> commentCounts,
|
||||
Map<Long, String> thumbnailUrls) {
|
||||
AppDramaCardVO card = new AppDramaCardVO();
|
||||
card.setId(drama.getId());
|
||||
card.setTitle(drama.getTitle());
|
||||
@@ -199,11 +209,13 @@ public class AppCatalogService {
|
||||
? 0L : commentCounts.getOrDefault(preview.getId(), 0L));
|
||||
card.setLanguage(drama.getLanguage());
|
||||
card.setDramaType(drama.getDramaType());
|
||||
card.setPreview(preview == null ? null : toEpisode(preview, commentCounts));
|
||||
card.setPreview(preview == null
|
||||
? null : toEpisode(preview, commentCounts, thumbnailUrls));
|
||||
return card;
|
||||
}
|
||||
|
||||
private AppEpisodeVO toEpisode(DramaEpisode episode, Map<Long, Long> commentCounts) {
|
||||
private AppEpisodeVO toEpisode(DramaEpisode episode, Map<Long, Long> commentCounts,
|
||||
Map<Long, String> thumbnailUrls) {
|
||||
AppEpisodeVO vo = new AppEpisodeVO();
|
||||
vo.setId(episode.getId());
|
||||
vo.setNumber(episode.getEpNo());
|
||||
@@ -217,6 +229,7 @@ public class AppCatalogService {
|
||||
vo.setUnlockCoin(episode.getUnlockCoin());
|
||||
vo.setLikeCount(episode.getLikeCount() == null ? 0L : episode.getLikeCount());
|
||||
vo.setCommentCount(commentCounts.getOrDefault(episode.getId(), 0L));
|
||||
vo.setThumbnailsUrl(thumbnailUrls.get(episode.getId()));
|
||||
if (free) {
|
||||
// 播放地址统一在这里签名:客户端拿不到可长期复用的裸地址
|
||||
vo.setPlayUrl(playbackSigner.sign(playableSource(episode)));
|
||||
|
||||
@@ -24,4 +24,6 @@ public class AppEpisodeVO {
|
||||
* 详情页拿到就能直接播,不必按集再请求一次播放票据。
|
||||
*/
|
||||
private String playUrl;
|
||||
/** 雪碧图 WebVTT 时间轴地址;没有产物时为 null */
|
||||
private String thumbnailsUrl;
|
||||
}
|
||||
+3
-2
@@ -96,11 +96,12 @@ class AppCatalogControllerContractTest {
|
||||
card.setId(12L);
|
||||
card.setTitle("漫剧卡片");
|
||||
card.setDramaType("ANIME");
|
||||
given(catalogService.feed("ANIME", null, 20))
|
||||
given(catalogService.feed("ANIME", 7L, null, 20))
|
||||
.willReturn(new CursorResult<>(List.of(card), 12L, true));
|
||||
|
||||
catalogMvc.perform(get("/app/feed")
|
||||
.param("types", "ANIME")
|
||||
.param("categoryId", "7")
|
||||
.param("size", "20"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
@@ -109,7 +110,7 @@ class AppCatalogControllerContractTest {
|
||||
.andExpect(jsonPath("$.data.nextCursor").value("12"))
|
||||
.andExpect(jsonPath("$.data.hasMore").value(true));
|
||||
|
||||
verify(catalogService).feed("ANIME", null, 20);
|
||||
verify(catalogService).feed("ANIME", 7L, null, 20);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class AppCommentCountAnonymousSecurityTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
given(commentService.countByDrama(7L)).willReturn(9L);
|
||||
given(catalogService.feed("ANIME", null, 20))
|
||||
given(catalogService.feed("ANIME", null, null, 20))
|
||||
.willReturn(new CursorResult<>(List.of(), null, false));
|
||||
}
|
||||
|
||||
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.app.controller;
|
||||
|
||||
import com.fruitshorts.app.service.AppCatalogService;
|
||||
import com.fruitshorts.app.support.ControllerContractSupport;
|
||||
import com.fruitshorts.app.vo.AppDramaCardVO;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.framework.security.LoginUser;
|
||||
import com.fruitshorts.playback.service.FavoriteService;
|
||||
import com.fruitshorts.playback.service.WatchProgressService;
|
||||
import com.fruitshorts.playback.vo.ProgressRespVO;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/** 客户端收藏与观看历史分页契约。 */
|
||||
class AppLibraryPagingContractTest {
|
||||
|
||||
private static final long USER_ID = 1001L;
|
||||
|
||||
private FavoriteService favoriteService;
|
||||
private AppCatalogService catalogService;
|
||||
private WatchProgressService progressService;
|
||||
private MockMvc favoriteMvc;
|
||||
private MockMvc watchMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
favoriteService = mock(FavoriteService.class);
|
||||
catalogService = mock(AppCatalogService.class);
|
||||
progressService = mock(WatchProgressService.class);
|
||||
favoriteMvc = ControllerContractSupport.mockMvcOf(
|
||||
new AppFavoriteController(favoriteService, catalogService));
|
||||
watchMvc = ControllerContractSupport.mockMvcOf(
|
||||
new AppWatchController(progressService));
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new UsernamePasswordAuthenticationToken(
|
||||
new LoginUser(USER_ID, "app-user", "APP_USER", List.of()),
|
||||
null,
|
||||
List.of()));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_page_favorites_with_default_size_and_non_overlapping_second_page()
|
||||
throws Exception {
|
||||
Drama first = drama(101L, "收藏一");
|
||||
Drama second = drama(102L, "收藏二");
|
||||
Drama third = drama(103L, "收藏三");
|
||||
given(favoriteService.page(USER_ID, 1, 20))
|
||||
.willReturn(new PageResult<>(21L, List.of(first, second)));
|
||||
given(favoriteService.page(USER_ID, 2, 20))
|
||||
.willReturn(new PageResult<>(21L, List.of(third)));
|
||||
given(catalogService.toCards(List.of(first, second)))
|
||||
.willReturn(List.of(card(101L), card(102L)));
|
||||
given(catalogService.toCards(List.of(third)))
|
||||
.willReturn(List.of(card(103L)));
|
||||
|
||||
favoriteMvc.perform(get("/app/favorites"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
.andExpect(jsonPath("$.data.total").value("21"))
|
||||
.andExpect(jsonPath("$.data.list.length()").value(2))
|
||||
.andExpect(jsonPath("$.data.list[0].id").value("101"))
|
||||
.andExpect(jsonPath("$.data.list[1].id").value("102"));
|
||||
|
||||
favoriteMvc.perform(get("/app/favorites").param("pageIndex", "2"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.total").value("21"))
|
||||
.andExpect(jsonPath("$.data.list.length()").value(1))
|
||||
.andExpect(jsonPath("$.data.list[0].id").value("103"));
|
||||
|
||||
verify(favoriteService).page(USER_ID, 1, 20);
|
||||
verify(favoriteService).page(USER_ID, 2, 20);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_page_recent_watch_with_display_fields() throws Exception {
|
||||
ProgressRespVO first = progress(12L, 88L, 6, "剧名一", 68);
|
||||
ProgressRespVO second = progress(13L, 99L, 2, "剧名二", 20);
|
||||
ProgressRespVO third = progress(14L, 100L, 1, "剧名三", 16);
|
||||
given(progressService.recentPage(USER_ID, 1, 20))
|
||||
.willReturn(new PageResult<>(23L, List.of(first, second)));
|
||||
given(progressService.recentPage(USER_ID, 2, 20))
|
||||
.willReturn(new PageResult<>(23L, List.of(third)));
|
||||
|
||||
watchMvc.perform(get("/app/watch/recent"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.total").value("23"))
|
||||
.andExpect(jsonPath("$.data.list.length()").value(2))
|
||||
.andExpect(jsonPath("$.data.list[0].dramaTitle").value("剧名一"))
|
||||
.andExpect(jsonPath("$.data.list[0].episodeNumber").value(6))
|
||||
.andExpect(jsonPath("$.data.list[0].totalEpisodes").value(68))
|
||||
.andExpect(jsonPath("$.data.list[1].dramaTitle").value("剧名二"))
|
||||
.andExpect(jsonPath("$.data.list[1].episodeNumber").value(2));
|
||||
|
||||
watchMvc.perform(get("/app/watch/recent").param("pageIndex", "2"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.total").value("23"))
|
||||
.andExpect(jsonPath("$.data.list.length()").value(1))
|
||||
.andExpect(jsonPath("$.data.list[0].dramaId").value("14"))
|
||||
.andExpect(jsonPath("$.data.list[0].dramaTitle").value("剧名三"));
|
||||
|
||||
verify(progressService).recentPage(USER_ID, 1, 20);
|
||||
verify(progressService).recentPage(USER_ID, 2, 20);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_keep_total_and_return_empty_list_when_watch_page_is_out_of_range()
|
||||
throws Exception {
|
||||
given(progressService.recentPage(USER_ID, 9, 20))
|
||||
.willReturn(new PageResult<>(23L, List.of()));
|
||||
|
||||
watchMvc.perform(get("/app/watch/recent").param("pageIndex", "9"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.total").value("23"))
|
||||
.andExpect(jsonPath("$.data.list").isArray())
|
||||
.andExpect(jsonPath("$.data.list").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ignore_removed_limit_and_still_return_page_result() throws Exception {
|
||||
// limit 已从契约移除:即使客户端误传,也应走分页并返回 PageResult。
|
||||
given(progressService.recentPage(USER_ID, 1, 20))
|
||||
.willReturn(new PageResult<>(3L, List.of(progress(12L, 88L, 6, "剧名一", 68))));
|
||||
|
||||
watchMvc.perform(get("/app/watch/recent").param("limit", "5"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.total").value("3"))
|
||||
.andExpect(jsonPath("$.data.list").isArray())
|
||||
.andExpect(jsonPath("$.data.list.length()").value(1))
|
||||
.andExpect(jsonPath("$.data.list[0].dramaTitle").value("剧名一"));
|
||||
|
||||
verify(progressService).recentPage(USER_ID, 1, 20);
|
||||
}
|
||||
|
||||
private Drama drama(Long id, String title) {
|
||||
Drama drama = new Drama();
|
||||
drama.setId(id);
|
||||
drama.setTitle(title);
|
||||
return drama;
|
||||
}
|
||||
|
||||
private AppDramaCardVO card(Long id) {
|
||||
AppDramaCardVO card = new AppDramaCardVO();
|
||||
card.setId(id);
|
||||
return card;
|
||||
}
|
||||
|
||||
private ProgressRespVO progress(Long dramaId, Long episodeId, int episodeNumber,
|
||||
String dramaTitle, int totalEpisodes) {
|
||||
ProgressRespVO vo = new ProgressRespVO();
|
||||
vo.setDramaId(dramaId);
|
||||
vo.setEpisodeId(episodeId);
|
||||
vo.setEpisodeNumber(episodeNumber);
|
||||
vo.setDramaTitle(dramaTitle);
|
||||
vo.setDramaCover("/files/cover/" + dramaId + ".jpg");
|
||||
vo.setTotalEpisodes(totalEpisodes);
|
||||
vo.setPositionMs(80_000L);
|
||||
vo.setDurationMs(120_000L);
|
||||
vo.setFinished(false);
|
||||
vo.setPlayCount(1);
|
||||
vo.setUpdatedAt(LocalDateTime.of(2026, 10, 22, 10, 0));
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+13
-4
@@ -15,6 +15,7 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
@@ -55,7 +56,9 @@ class AppPlaybackContractTest {
|
||||
@Test
|
||||
void should_return_free_access_when_episode_is_free() throws Exception {
|
||||
given(playbackService.play(isNull(), eq(11L), any(), any()))
|
||||
.willReturn(ticket(11L, true, PlaybackService.ACCESS_FREE, "/files/ep.mp4?s=1"));
|
||||
.willReturn(ticket(11L, true, PlaybackService.ACCESS_FREE,
|
||||
"/files/ep.mp4?s=1",
|
||||
"/files/transcoded/11/thumbnails/thumbnails.vtt?e=1&s=sig"));
|
||||
|
||||
mockMvc.perform(get("/app/episodes/11/play").header("X-Device-Id", "device-9"))
|
||||
.andExpect(status().isOk())
|
||||
@@ -66,13 +69,15 @@ class AppPlaybackContractTest {
|
||||
.andExpect(jsonPath("$.data.accessible").value(true))
|
||||
.andExpect(jsonPath("$.data.accessType").value(PlaybackService.ACCESS_FREE))
|
||||
.andExpect(jsonPath("$.data.playUrl").value("/files/ep.mp4?s=1"))
|
||||
.andExpect(jsonPath("$.data.thumbnailsUrl")
|
||||
.value("/files/transcoded/11/thumbnails/thumbnails.vtt?e=1&s=sig"))
|
||||
.andExpect(jsonPath("$.data.likeCount").value("88"))
|
||||
.andExpect(jsonPath("$.data.commentCount").value("0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_coin_required_when_episode_is_locked_and_not_entitled() throws Exception {
|
||||
PlayRespVO locked = ticket(12L, false, PlaybackService.ACCESS_COIN_REQUIRED, "");
|
||||
PlayRespVO locked = ticket(12L, false, PlaybackService.ACCESS_COIN_REQUIRED, "", null);
|
||||
locked.setUnlockCoin(60);
|
||||
given(playbackService.play(isNull(), eq(12L), any(), any())).willReturn(locked);
|
||||
|
||||
@@ -81,13 +86,15 @@ class AppPlaybackContractTest {
|
||||
.andExpect(jsonPath("$.data.accessible").value(false))
|
||||
.andExpect(jsonPath("$.data.accessType").value(PlaybackService.ACCESS_COIN_REQUIRED))
|
||||
.andExpect(jsonPath("$.data.playUrl").value(""))
|
||||
.andExpect(jsonPath("$.data.thumbnailsUrl").value(nullValue()))
|
||||
.andExpect(jsonPath("$.data.unlockCoin").value(60));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_pass_episode_id_and_device_header_when_play_is_requested() throws Exception {
|
||||
given(playbackService.play(isNull(), eq(13L), eq("device-9"), any()))
|
||||
.willReturn(ticket(13L, true, PlaybackService.ACCESS_FREE, "/files/ep13.mp4?s=1"));
|
||||
.willReturn(ticket(13L, true, PlaybackService.ACCESS_FREE,
|
||||
"/files/ep13.mp4?s=1", null));
|
||||
|
||||
mockMvc.perform(get("/app/episodes/13/play").header("X-Device-Id", "device-9"))
|
||||
.andExpect(status().isOk());
|
||||
@@ -95,7 +102,8 @@ class AppPlaybackContractTest {
|
||||
verify(playbackService).play(isNull(), eq(13L), eq("device-9"), any());
|
||||
}
|
||||
|
||||
private PlayRespVO ticket(Long episodeId, boolean accessible, String accessType, String playUrl) {
|
||||
private PlayRespVO ticket(Long episodeId, boolean accessible, String accessType,
|
||||
String playUrl, String thumbnailsUrl) {
|
||||
PlayRespVO vo = new PlayRespVO();
|
||||
vo.setEpisodeId(episodeId);
|
||||
vo.setDramaId(7L);
|
||||
@@ -105,6 +113,7 @@ class AppPlaybackContractTest {
|
||||
vo.setAccessible(accessible);
|
||||
vo.setAccessType(accessType);
|
||||
vo.setPlayUrl(playUrl);
|
||||
vo.setThumbnailsUrl(thumbnailsUrl);
|
||||
vo.setQualities(List.of("AUTO"));
|
||||
vo.setUnlockCoin(0);
|
||||
vo.setPreviewSeconds(0);
|
||||
|
||||
+38
-11
@@ -12,6 +12,7 @@ import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.interaction.service.CommentService;
|
||||
import com.fruitshorts.media.service.PlaybackSigner;
|
||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -35,6 +36,7 @@ class AppCatalogServiceTest {
|
||||
private EpisodeService episodeService;
|
||||
private DramaCategoryService dramaCategoryService;
|
||||
private CommentService commentService;
|
||||
private ThumbnailUrlResolver thumbnailUrlResolver;
|
||||
private AppCatalogService catalogService;
|
||||
|
||||
@BeforeEach
|
||||
@@ -44,9 +46,11 @@ class AppCatalogServiceTest {
|
||||
BannerService bannerService = mock(BannerService.class);
|
||||
dramaCategoryService = mock(DramaCategoryService.class);
|
||||
PlaybackSigner playbackSigner = mock(PlaybackSigner.class);
|
||||
thumbnailUrlResolver = mock(ThumbnailUrlResolver.class);
|
||||
given(thumbnailUrlResolver.resolveAll(any())).willReturn(Map.of());
|
||||
commentService = mock(CommentService.class);
|
||||
catalogService = new AppCatalogService(dramaService, episodeService, bannerService,
|
||||
dramaCategoryService, playbackSigner, commentService);
|
||||
dramaCategoryService, playbackSigner, commentService, thumbnailUrlResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,6 +70,8 @@ class AppCatalogServiceTest {
|
||||
given(commentService.countByDrama(42L)).willReturn(96L);
|
||||
given(commentService.countByEpisodes(List.of(11L, 22L)))
|
||||
.willReturn(Map.of(11L, 2L, 22L, 4L));
|
||||
given(thumbnailUrlResolver.resolveAll(List.of(11L, 22L)))
|
||||
.willReturn(Map.of(22L, "/files/transcoded/22/thumbnails/thumbnails.vtt"));
|
||||
|
||||
AppDramaDetailVO detail = catalogService.dramaDetail(42L);
|
||||
|
||||
@@ -75,7 +81,10 @@ class AppCatalogServiceTest {
|
||||
assertThat(detail.getCommentCount()).isEqualTo(96L);
|
||||
assertThat(detail.getEpisodes().get(0).getLikeCount()).isEqualTo(66L);
|
||||
assertThat(detail.getEpisodes().get(0).getCommentCount()).isEqualTo(4L);
|
||||
assertThat(detail.getEpisodes().get(0).getThumbnailsUrl())
|
||||
.isEqualTo("/files/transcoded/22/thumbnails/thumbnails.vtt");
|
||||
verify(commentService).countByDrama(42L);
|
||||
verify(thumbnailUrlResolver).resolveAll(List.of(11L, 22L));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +127,7 @@ class AppCatalogServiceTest {
|
||||
@Test
|
||||
void should_filter_feed_by_drama_type_and_expose_it_on_card() {
|
||||
Drama anime = drama(1L, "ANIME");
|
||||
given(dramaService.listPublishedFeed(List.of("ANIME"), null, 21))
|
||||
given(dramaService.listPublishedFeed(List.of("ANIME"), null, null, 21))
|
||||
.willReturn(List.of(anime));
|
||||
given(dramaCategoryService.listBasic()).willReturn(List.of());
|
||||
DramaEpisode preview = episode(11L, 1L, 45L);
|
||||
@@ -126,41 +135,59 @@ class AppCatalogServiceTest {
|
||||
.willReturn(Map.of(1L, preview));
|
||||
given(commentService.countByEpisodes(List.of(11L))).willReturn(Map.of(11L, 3L));
|
||||
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed("ANIME", null, null);
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed(
|
||||
"ANIME", null, null, null);
|
||||
|
||||
assertThat(result.getList()).hasSize(1);
|
||||
assertThat(result.getList().get(0).getDramaType()).isEqualTo("ANIME");
|
||||
assertThat(result.getList().get(0).getCommentCount()).isEqualTo(3L);
|
||||
assertThat(result.getList().get(0).getLikeCount()).isEqualTo(45L);
|
||||
assertThat(result.isHasMore()).isFalse();
|
||||
verify(dramaService).listPublishedFeed(List.of("ANIME"), null, 21);
|
||||
verify(dramaService).listPublishedFeed(List.of("ANIME"), null, null, 21);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_parse_multiple_feed_types() {
|
||||
given(dramaService.listPublishedFeed(List.of("ANIME", "LIVE"), null, 11))
|
||||
given(dramaService.listPublishedFeed(
|
||||
List.of("ANIME", "LIVE"), null, null, 11))
|
||||
.willReturn(List.of());
|
||||
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed("ANIME,LIVE", null, 10);
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed(
|
||||
"ANIME,LIVE", null, null, 10);
|
||||
|
||||
assertThat(result.getList()).isEmpty();
|
||||
verify(dramaService).listPublishedFeed(List.of("ANIME", "LIVE"), null, 11);
|
||||
verify(dramaService).listPublishedFeed(
|
||||
List.of("ANIME", "LIVE"), null, null, 11);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_filter_feed_by_category_id_only() {
|
||||
given(dramaService.listPublishedFeed(List.of(), 7L, null, 21))
|
||||
.willReturn(List.of());
|
||||
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed(
|
||||
null, 7L, null, null);
|
||||
|
||||
assertThat(result.getList()).isEmpty();
|
||||
verify(dramaService).listPublishedFeed(List.of(), 7L, null, 21);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_page_feed_with_cursor_without_duplicates() {
|
||||
Drama first = drama(1L, "ANIME");
|
||||
Drama second = drama(2L, "LIVE");
|
||||
given(dramaService.listPublishedFeed(List.of(), null, 2))
|
||||
given(dramaService.listPublishedFeed(List.of(), null, null, 2))
|
||||
.willReturn(List.of(first, second));
|
||||
given(dramaService.listPublishedFeed(List.of(), 1L, 2))
|
||||
given(dramaService.listPublishedFeed(List.of(), null, 1L, 2))
|
||||
.willReturn(List.of(second));
|
||||
given(dramaCategoryService.listBasic()).willReturn(List.of());
|
||||
given(episodeService.firstPlayableByDramas(any())).willReturn(Map.of());
|
||||
given(commentService.countByEpisodes(any())).willReturn(Map.of());
|
||||
|
||||
CursorResult<AppDramaCardVO> firstPage = catalogService.feed(null, null, 1);
|
||||
CursorResult<AppDramaCardVO> secondPage = catalogService.feed(null, firstPage.getNextCursor(), 1);
|
||||
CursorResult<AppDramaCardVO> firstPage = catalogService.feed(
|
||||
null, null, null, 1);
|
||||
CursorResult<AppDramaCardVO> secondPage = catalogService.feed(
|
||||
null, null, firstPage.getNextCursor(), 1);
|
||||
|
||||
assertThat(firstPage.getList()).extracting(AppDramaCardVO::getId).containsExactly(1L);
|
||||
assertThat(firstPage.getNextCursor()).isEqualTo(1L);
|
||||
|
||||
+3
-1
@@ -12,6 +12,7 @@ import com.fruitshorts.content.dal.mapper.DramaMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaReviewRecordMapper;
|
||||
import com.fruitshorts.content.service.DramaCategoryService;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodePriceSync;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -41,7 +42,8 @@ class DramaServiceFavoriteCountTest {
|
||||
dramaMapper,
|
||||
mock(DramaEpisodeMapper.class),
|
||||
mock(DramaReviewRecordMapper.class),
|
||||
mock(DramaCategoryService.class));
|
||||
mock(DramaCategoryService.class),
|
||||
mock(EpisodePriceSync.class));
|
||||
given(dramaMapper.update(isNull(), any())).willReturn(1);
|
||||
ArgumentCaptor<Wrapper<Drama>> captor = ArgumentCaptor.forClass(Wrapper.class);
|
||||
|
||||
|
||||
+67
-3
@@ -11,6 +11,7 @@ import com.fruitshorts.content.dal.mapper.DramaMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaReviewRecordMapper;
|
||||
import com.fruitshorts.content.service.DramaCategoryService;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodePriceSync;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -23,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/** K88 App 推荐流的类型过滤与三字段 keyset 游标。 */
|
||||
@@ -44,7 +46,8 @@ class DramaServiceFeedTest {
|
||||
dramaMapper,
|
||||
mock(DramaEpisodeMapper.class),
|
||||
mock(DramaReviewRecordMapper.class),
|
||||
mock(DramaCategoryService.class));
|
||||
mock(DramaCategoryService.class),
|
||||
mock(EpisodePriceSync.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +63,7 @@ class DramaServiceFeedTest {
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), null, 9L, 5);
|
||||
|
||||
verify(dramaMapper).selectList(captor.capture());
|
||||
QueryWrapper<Drama> query = captor.getValue();
|
||||
@@ -86,7 +89,7 @@ class DramaServiceFeedTest {
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of("LIVE"), 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("LIVE"), null, 9L, 5);
|
||||
|
||||
verify(dramaMapper).selectList(captor.capture());
|
||||
assertThat(captor.getValue().getSqlSegment())
|
||||
@@ -94,4 +97,65 @@ class DramaServiceFeedTest {
|
||||
.contains("view_count")
|
||||
.contains("id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void should_apply_category_and_type_tokens_together() {
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), 7L, null, 5);
|
||||
|
||||
verify(dramaMapper).selectList(captor.capture());
|
||||
QueryWrapper<Drama> query = captor.getValue();
|
||||
assertThat(query.getSqlSegment())
|
||||
.contains("drama_types")
|
||||
.contains("category_ids")
|
||||
.contains("recommend_weight");
|
||||
assertThat(query.getParamNameValuePairs().values())
|
||||
.contains("%,ANIME,%", "%,7,%");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void should_apply_category_cursor_for_matching_marker() {
|
||||
Drama marker = new Drama();
|
||||
marker.setId(9L);
|
||||
marker.setStatus("published");
|
||||
marker.setDramaType("ANIME");
|
||||
marker.setCategoryId(7L);
|
||||
marker.setCategoryIds("7,8");
|
||||
marker.setRecommendWeight(30);
|
||||
marker.setViewCount(1200L);
|
||||
given(dramaMapper.selectById(9L)).willReturn(marker);
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of(), 7L, 9L, 5);
|
||||
|
||||
verify(dramaMapper).selectList(captor.capture());
|
||||
QueryWrapper<Drama> query = captor.getValue();
|
||||
assertThat(query.getSqlSegment())
|
||||
.contains("category_ids")
|
||||
.contains("recommend_weight")
|
||||
.contains("id");
|
||||
assertThat(query.getParamNameValuePairs().values())
|
||||
.contains("%,7,%", 30, 1200L, 9L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_empty_when_cursor_marker_does_not_match_category() {
|
||||
Drama marker = new Drama();
|
||||
marker.setId(9L);
|
||||
marker.setStatus("published");
|
||||
marker.setDramaType("ANIME");
|
||||
marker.setCategoryId(8L);
|
||||
marker.setCategoryIds("8");
|
||||
given(dramaMapper.selectById(9L)).willReturn(marker);
|
||||
|
||||
List<Drama> rows = dramaService.listPublishedFeed(List.of("ANIME"), 7L, 9L, 5);
|
||||
|
||||
assertThat(rows).isEmpty();
|
||||
verify(dramaMapper, never()).selectList(any());
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -12,6 +12,7 @@ import com.fruitshorts.content.dal.mapper.DramaMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaReviewRecordMapper;
|
||||
import com.fruitshorts.content.service.DramaCategoryService;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodePriceSync;
|
||||
import com.fruitshorts.content.vo.DramaSaveReqVO;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
@@ -46,7 +47,8 @@ class DramaServiceK88Test {
|
||||
dramaMapper,
|
||||
mock(DramaEpisodeMapper.class),
|
||||
mock(DramaReviewRecordMapper.class),
|
||||
mock(DramaCategoryService.class));
|
||||
mock(DramaCategoryService.class),
|
||||
mock(EpisodePriceSync.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+5
-3
@@ -13,6 +13,7 @@ import com.fruitshorts.content.dal.mapper.DramaMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaReviewRecordMapper;
|
||||
import com.fruitshorts.content.service.DramaCategoryService;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodePriceSync;
|
||||
import com.fruitshorts.content.vo.DramaPageReqVO;
|
||||
import com.fruitshorts.content.vo.DramaRespVO;
|
||||
import com.fruitshorts.content.vo.DramaSaveReqVO;
|
||||
@@ -54,7 +55,8 @@ class DramaServiceMultiTagTest {
|
||||
dramaMapper,
|
||||
mock(DramaEpisodeMapper.class),
|
||||
mock(DramaReviewRecordMapper.class),
|
||||
categoryService);
|
||||
categoryService,
|
||||
mock(EpisodePriceSync.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,8 +136,8 @@ class DramaServiceMultiTagTest {
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("LIVE"), 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), null, 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("LIVE"), null, 9L, 5);
|
||||
|
||||
verify(dramaMapper, times(2)).selectList(captor.capture());
|
||||
assertThat(captor.getAllValues()).allSatisfy(query ->
|
||||
|
||||
+4
-1
@@ -13,6 +13,7 @@ import com.fruitshorts.content.dal.mapper.DramaEpisodeMapper;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.content.vo.EpisodeSaveReqVO;
|
||||
import com.fruitshorts.media.service.EpisodeTranscodeBindingService;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -46,7 +47,9 @@ class EpisodeServiceK89Test {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
episodeMapper = mock(DramaEpisodeMapper.class);
|
||||
episodeService = new EpisodeService(episodeMapper, mock(DramaService.class));
|
||||
episodeService = new EpisodeService(
|
||||
episodeMapper, mock(DramaService.class),
|
||||
mock(EpisodeTranscodeBindingService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.app.service;
|
||||
|
||||
import com.fruitshorts.system.service.LegalPageHtml;
|
||||
import com.fruitshorts.system.service.LegalPages;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class LegalPageHtmlTest {
|
||||
|
||||
@Test
|
||||
void should_render_markdown_without_an_extra_title() {
|
||||
String html = LegalPageHtml.render("zh", "第一行\n\n<script>alert(1)</script>\n\n**粗体**");
|
||||
|
||||
assertTrue(html.contains("<html lang=\"zh\">"));
|
||||
assertFalse(html.contains("<h1>"));
|
||||
assertTrue(html.contains("<p>第一行</p>"));
|
||||
assertTrue(html.contains("<script>"));
|
||||
assertTrue(html.contains("<strong>粗体</strong>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_map_public_paths_to_document_codes() {
|
||||
assertEquals(LegalPages.PRIVACY, LegalPages.docCodeOfPath("privacy"));
|
||||
assertEquals(LegalPages.TERMS, LegalPages.docCodeOfPath("terms"));
|
||||
assertNull(LegalPages.docCodeOfPath("other"));
|
||||
}
|
||||
}
|
||||
+51
-1
@@ -5,7 +5,9 @@ import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.media.dal.entity.MediaRendition;
|
||||
import com.fruitshorts.media.service.PlaybackSigner;
|
||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||
import com.fruitshorts.media.service.TranscodeService;
|
||||
import com.fruitshorts.playback.dal.entity.PlaybackTicket;
|
||||
import com.fruitshorts.playback.dal.mapper.PlaybackTicketMapper;
|
||||
@@ -42,6 +44,7 @@ class PlaybackServiceTest {
|
||||
private PlaybackSigner signer;
|
||||
private EntitlementPort entitlementPort;
|
||||
private TranscodeService transcodeService;
|
||||
private ThumbnailUrlResolver thumbnailUrlResolver;
|
||||
private PlaybackService playbackService;
|
||||
|
||||
@BeforeEach
|
||||
@@ -52,10 +55,12 @@ class PlaybackServiceTest {
|
||||
signer = mock(PlaybackSigner.class);
|
||||
entitlementPort = mock(EntitlementPort.class);
|
||||
transcodeService = mock(TranscodeService.class);
|
||||
thumbnailUrlResolver = mock(ThumbnailUrlResolver.class);
|
||||
playbackService = new PlaybackService(episodeService, dramaService, ticketMapper, signer,
|
||||
entitlementPort, transcodeService);
|
||||
entitlementPort, transcodeService, thumbnailUrlResolver);
|
||||
given(dramaService.getPublished(anyLong())).willReturn(drama());
|
||||
given(transcodeService.listRenditions(anyLong())).willReturn(List.of());
|
||||
given(thumbnailUrlResolver.resolve(anyLong())).willReturn(null);
|
||||
given(signer.sign(anyString())).willReturn("/files/episode/1.mp4?e=1&s=sig");
|
||||
}
|
||||
|
||||
@@ -72,6 +77,27 @@ class PlaybackServiceTest {
|
||||
verify(ticketMapper, never()).insert(any(PlaybackTicket.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_signed_thumbnails_url_when_thumbnail_exists() {
|
||||
given(episodeService.getPublished(11L)).willReturn(episode(11L, 1, 0, "/files/episode/1.mp4"));
|
||||
given(thumbnailUrlResolver.resolve(11L))
|
||||
.willReturn("/files/transcoded/1/thumbnails/thumbnails.vtt?e=1&s=sig");
|
||||
|
||||
PlayRespVO resp = playbackService.play(null, 11L, "device-9", "203.0.113.8");
|
||||
|
||||
assertThat(resp.getThumbnailsUrl())
|
||||
.isEqualTo("/files/transcoded/1/thumbnails/thumbnails.vtt?e=1&s=sig");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_null_thumbnails_url_when_thumbnail_is_absent() {
|
||||
given(episodeService.getPublished(11L)).willReturn(episode(11L, 1, 0, "/files/episode/1.mp4"));
|
||||
|
||||
PlayRespVO resp = playbackService.play(null, 11L, "device-9", "203.0.113.8");
|
||||
|
||||
assertThat(resp.getThumbnailsUrl()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_coin_required_when_episode_is_locked_and_not_entitled() {
|
||||
given(episodeService.getPublished(12L)).willReturn(episode(12L, 0, 60, "/files/episode/2.mp4"));
|
||||
@@ -122,6 +148,30 @@ class PlaybackServiceTest {
|
||||
verify(signer).sign("/files/episode/15/master.m3u8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_sign_each_ready_rendition_when_episode_has_multiple_qualities() {
|
||||
DramaEpisode episode = episode(16L, 1, 0, "/files/episode/origin.mp4");
|
||||
episode.setHlsUrl("/files/transcoded/16/master.m3u8");
|
||||
given(episodeService.getPublished(16L)).willReturn(episode);
|
||||
given(signer.sign(anyString())).willAnswer(invocation -> invocation.getArgument(0) + "?s=1");
|
||||
MediaRendition ready = new MediaRendition();
|
||||
ready.setQuality("720p");
|
||||
ready.setPlayUrl("/files/transcoded/16/720p/index.m3u8");
|
||||
ready.setStatus("ready");
|
||||
MediaRendition failed = new MediaRendition();
|
||||
failed.setQuality("1080p");
|
||||
failed.setPlayUrl("/files/transcoded/16/1080p/index.m3u8");
|
||||
failed.setStatus("failed");
|
||||
given(transcodeService.listRenditions(16L)).willReturn(List.of(ready, failed));
|
||||
|
||||
PlayRespVO resp = playbackService.play(null, 16L, "device-9", "203.0.113.8");
|
||||
|
||||
assertThat(resp.getTracks()).extracting(track -> track.getQuality())
|
||||
.containsExactly("AUTO", "720p");
|
||||
assertThat(resp.getTracks().get(1).getPlayUrl())
|
||||
.isEqualTo("/files/transcoded/16/720p/index.m3u8?s=1");
|
||||
}
|
||||
|
||||
private DramaEpisode episode(Long id, int isFree, int unlockCoin, String videoUrl) {
|
||||
DramaEpisode episode = new DramaEpisode();
|
||||
episode.setId(id);
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.app.service;
|
||||
|
||||
import com.fruitshorts.media.dal.entity.MediaThumbnail;
|
||||
import com.fruitshorts.media.service.MediaStorageService;
|
||||
import com.fruitshorts.media.service.PlaybackSigner;
|
||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||
import com.fruitshorts.media.service.TranscodeService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* 缩略图 objectKey 到公开签名地址的转换。
|
||||
*/
|
||||
class ThumbnailUrlResolverTest {
|
||||
|
||||
private TranscodeService transcodeService;
|
||||
private MediaStorageService storageService;
|
||||
private PlaybackSigner signer;
|
||||
private ThumbnailUrlResolver resolver;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
transcodeService = mock(TranscodeService.class);
|
||||
storageService = mock(MediaStorageService.class);
|
||||
signer = mock(PlaybackSigner.class);
|
||||
resolver = new ThumbnailUrlResolver(transcodeService, storageService, signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_sign_vtt_public_url_when_ready_thumbnail_exists() {
|
||||
MediaThumbnail thumbnail = new MediaThumbnail();
|
||||
thumbnail.setVttObjectKey("transcoded/88/thumbnails/thumbnails.vtt");
|
||||
given(transcodeService.findReadyThumbnail(11L)).willReturn(thumbnail);
|
||||
given(storageService.toPublicUrl(thumbnail.getVttObjectKey()))
|
||||
.willReturn("/files/transcoded/88/thumbnails/thumbnails.vtt");
|
||||
given(signer.sign("/files/transcoded/88/thumbnails/thumbnails.vtt"))
|
||||
.willReturn("/files/transcoded/88/thumbnails/thumbnails.vtt?e=1&s=sig");
|
||||
|
||||
assertThat(resolver.resolve(11L))
|
||||
.isEqualTo("/files/transcoded/88/thumbnails/thumbnails.vtt?e=1&s=sig");
|
||||
verify(signer).sign("/files/transcoded/88/thumbnails/thumbnails.vtt");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_null_when_thumbnail_record_is_absent() {
|
||||
assertThat(resolver.resolve(12L)).isNull();
|
||||
}
|
||||
}
|
||||
+58
@@ -2,13 +2,23 @@
|
||||
|
||||
package com.fruitshorts.playback.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.playback.dal.entity.UserFavorite;
|
||||
import com.fruitshorts.playback.dal.mapper.UserFavoriteMapper;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -20,6 +30,12 @@ import static org.mockito.Mockito.verify;
|
||||
/** 收藏关系变化时同步维护短剧收藏数。 */
|
||||
class FavoriteServiceTest {
|
||||
|
||||
@BeforeAll
|
||||
static void initTableInfoCache() {
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, UserFavorite.class);
|
||||
}
|
||||
|
||||
private UserFavoriteMapper favoriteMapper;
|
||||
private DramaService dramaService;
|
||||
private FavoriteService favoriteService;
|
||||
@@ -77,4 +93,46 @@ class FavoriteServiceTest {
|
||||
verify(dramaService, never()).adjustFavoriteCount(8L, -1);
|
||||
verify(dramaService).adjustFavoriteCount(9L, -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_use_database_page_and_keep_favorite_order_when_listing() {
|
||||
UserFavorite first = favorite(51L);
|
||||
UserFavorite second = favorite(52L);
|
||||
Page<UserFavorite> databasePage = new Page<>(2, 20, 25);
|
||||
databasePage.setRecords(List.of(first, second));
|
||||
given(favoriteMapper.selectPage(any(Page.class), any())).willReturn(databasePage);
|
||||
Drama firstDrama = drama(51L);
|
||||
Drama secondDrama = drama(52L);
|
||||
given(dramaService.listPublishedByIds(List.of(51L, 52L)))
|
||||
.willReturn(List.of(secondDrama, firstDrama));
|
||||
|
||||
PageResult<Drama> result = favoriteService.page(1L, 2, 20);
|
||||
|
||||
assertThat(result.getTotal()).isEqualTo(25);
|
||||
assertThat(result.getList()).containsExactly(firstDrama, secondDrama);
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Page<UserFavorite>> pageCaptor = ArgumentCaptor.forClass(Page.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Wrapper<UserFavorite>> wrapperCaptor =
|
||||
ArgumentCaptor.forClass(Wrapper.class);
|
||||
verify(favoriteMapper).selectPage(pageCaptor.capture(), wrapperCaptor.capture());
|
||||
assertThat(pageCaptor.getValue().getCurrent()).isEqualTo(2);
|
||||
assertThat(pageCaptor.getValue().getSize()).isEqualTo(20);
|
||||
assertThat(wrapperCaptor.getValue().getSqlSegment())
|
||||
.contains("created_at DESC")
|
||||
.contains("drama_id DESC");
|
||||
verify(dramaService).listPublishedByIds(List.of(51L, 52L));
|
||||
}
|
||||
|
||||
private UserFavorite favorite(Long dramaId) {
|
||||
UserFavorite favorite = new UserFavorite();
|
||||
favorite.setDramaId(dramaId);
|
||||
return favorite;
|
||||
}
|
||||
|
||||
private Drama drama(Long id) {
|
||||
Drama drama = new Drama();
|
||||
drama.setId(id);
|
||||
return drama;
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.playback.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.playback.dal.entity.WatchProgress;
|
||||
import com.fruitshorts.playback.dal.mapper.WatchHistoryMapper;
|
||||
import com.fruitshorts.playback.dal.mapper.WatchProgressMapper;
|
||||
import com.fruitshorts.playback.vo.ProgressRespVO;
|
||||
import com.fruitshorts.playback.vo.ProgressSaveReqVO;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/** 观看历史分页、稳定排序与批量展示字段装配。 */
|
||||
class WatchProgressServiceTest {
|
||||
|
||||
@BeforeAll
|
||||
static void initTableInfoCache() {
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, WatchProgress.class);
|
||||
}
|
||||
|
||||
private WatchProgressMapper progressMapper;
|
||||
private DramaService dramaService;
|
||||
private EpisodeService episodeService;
|
||||
private WatchProgressService progressService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
progressMapper = mock(WatchProgressMapper.class);
|
||||
dramaService = mock(DramaService.class);
|
||||
episodeService = mock(EpisodeService.class);
|
||||
progressService = new WatchProgressService(
|
||||
progressMapper,
|
||||
mock(WatchHistoryMapper.class),
|
||||
dramaService,
|
||||
episodeService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_page_recent_and_fill_display_fields_with_two_batch_queries() {
|
||||
WatchProgress first = progress(12L, 88L);
|
||||
WatchProgress second = progress(13L, 99L);
|
||||
Page<WatchProgress> databasePage = new Page<>(1, 20, 23);
|
||||
databasePage.setRecords(List.of(first, second));
|
||||
given(progressMapper.selectPage(any(Page.class), any())).willReturn(databasePage);
|
||||
given(dramaService.listByIds(List.of(12L, 13L)))
|
||||
.willReturn(List.of(drama(13L, "剧名二", 20), drama(12L, "剧名一", 68)));
|
||||
given(episodeService.listByIds(List.of(88L, 99L)))
|
||||
.willReturn(List.of(episode(99L, 2), episode(88L, 6)));
|
||||
|
||||
PageResult<ProgressRespVO> result =
|
||||
progressService.recentPage(1001L, 1, 20);
|
||||
|
||||
assertThat(result.getTotal()).isEqualTo(23);
|
||||
assertThat(result.getList()).hasSize(2);
|
||||
assertThat(result.getList().get(0).getDramaTitle()).isEqualTo("剧名一");
|
||||
assertThat(result.getList().get(0).getEpisodeNumber()).isEqualTo(6);
|
||||
assertThat(result.getList().get(0).getTotalEpisodes()).isEqualTo(68);
|
||||
assertThat(result.getList().get(1).getDramaTitle()).isEqualTo("剧名二");
|
||||
assertThat(result.getList().get(1).getEpisodeNumber()).isEqualTo(2);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Page<WatchProgress>> pageCaptor = ArgumentCaptor.forClass(Page.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Wrapper<WatchProgress>> wrapperCaptor =
|
||||
ArgumentCaptor.forClass(Wrapper.class);
|
||||
verify(progressMapper).selectPage(pageCaptor.capture(), wrapperCaptor.capture());
|
||||
assertThat(pageCaptor.getValue().getCurrent()).isEqualTo(1);
|
||||
assertThat(pageCaptor.getValue().getSize()).isEqualTo(20);
|
||||
assertThat(wrapperCaptor.getValue().getSqlSegment())
|
||||
.contains("updated_at DESC")
|
||||
.contains("id DESC");
|
||||
verify(dramaService, times(1)).listByIds(List.of(12L, 13L));
|
||||
verify(episodeService, times(1)).listByIds(List.of(88L, 99L));
|
||||
}
|
||||
|
||||
private WatchProgress progress(Long dramaId, Long episodeId) {
|
||||
WatchProgress progress = new WatchProgress();
|
||||
progress.setUserId(1001L);
|
||||
progress.setDramaId(dramaId);
|
||||
progress.setEpisodeId(episodeId);
|
||||
progress.setPositionMs(80_000L);
|
||||
progress.setDurationMs(120_000L);
|
||||
progress.setFinished(0);
|
||||
progress.setPlayCount(1);
|
||||
progress.setUpdatedAt(LocalDateTime.of(2026, 10, 22, 10, 0));
|
||||
return progress;
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_revive_deleted_progress_when_same_drama_is_reported_again() {
|
||||
DramaEpisode episode = episode(88L, 1);
|
||||
episode.setDramaId(5L);
|
||||
given(episodeService.getPublished(88L)).willReturn(episode);
|
||||
given(dramaService.getPublished(5L)).willReturn(drama(5L, "剧名", 10));
|
||||
WatchProgress hidden = progress(5L, 88L);
|
||||
hidden.setId(9L);
|
||||
hidden.setUserId(7L);
|
||||
hidden.setDeleted(1);
|
||||
given(progressMapper.selectAny(7L, 5L)).willReturn(hidden);
|
||||
given(progressMapper.selectById(9L)).willReturn(hidden);
|
||||
ProgressSaveReqVO req = new ProgressSaveReqVO();
|
||||
req.setEpisodeId(88L);
|
||||
req.setPositionMs(1_000L);
|
||||
req.setDurationMs(2_000L);
|
||||
|
||||
progressService.save(7L, req);
|
||||
|
||||
verify(progressMapper, never()).insert(any(WatchProgress.class));
|
||||
verify(progressMapper).updateAny(hidden);
|
||||
assertThat(hidden.getDeleted()).isZero();
|
||||
}
|
||||
|
||||
private Drama drama(Long id, String title, int totalEpisodes) {
|
||||
Drama drama = new Drama();
|
||||
drama.setId(id);
|
||||
drama.setTitle(title);
|
||||
drama.setCoverUrl("/files/cover/" + id + ".jpg");
|
||||
drama.setTotalEpisodes(totalEpisodes);
|
||||
return drama;
|
||||
}
|
||||
|
||||
private DramaEpisode episode(Long id, int epNo) {
|
||||
DramaEpisode episode = new DramaEpisode();
|
||||
episode.setId(id);
|
||||
episode.setEpNo(epNo);
|
||||
return episode;
|
||||
}
|
||||
}
|
||||
+4
@@ -40,11 +40,15 @@ public class SecurityConfig {
|
||||
"/app/categories/**",
|
||||
"/app/banners/**",
|
||||
"/app/dramas/**",
|
||||
"/app/search",
|
||||
"/app/episodes/*/play",
|
||||
"/app/config/**",
|
||||
/* 启动配置与公告:客户端登录前就要拿(POST /app/creator/apply 等仍要登录) */
|
||||
"/app/config",
|
||||
"/app/notices",
|
||||
/* 服务条款与隐私协议:登录前就要能打开,按语言返回 HTML */
|
||||
"/privacy/**",
|
||||
"/terms/**",
|
||||
/* 埋点上报:游客浏览也要记录,匿名可访问 */
|
||||
"/app/events",
|
||||
/* 媒资:封面与视频用 <img>/<video> 直接访问,无法带请求头。
|
||||
|
||||
@@ -25,5 +25,14 @@
|
||||
<groupId>com.fruitshorts</groupId>
|
||||
<artifactId>fruitshorts-module-system</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fruitshorts</groupId>
|
||||
<artifactId>fruitshorts-module-media</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 运营分类:与短剧类型(drama_category)是两套独立概念。 */
|
||||
@Data
|
||||
@TableName("drama_classification")
|
||||
public class DramaClassification {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
private String name;
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 分类与短剧的关联关系(多对多)。 */
|
||||
@Data
|
||||
@TableName("drama_classification_drama")
|
||||
public class DramaClassificationDrama {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
private Long classificationId;
|
||||
private Long dramaId;
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 剧单专属分类:只服务于剧单分组,与运营分类(drama_classification)无关。 */
|
||||
@Data
|
||||
@TableName("drama_playlist_category")
|
||||
public class DramaPlaylistCategory {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
private String name;
|
||||
/** 分类描述,便于运营说明该分类的用途 */
|
||||
private String description;
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 剧单分类与短剧的关联关系(分类直接挂短剧,没有剧单层)。 */
|
||||
@Data
|
||||
@TableName("drama_playlist_category_drama")
|
||||
public class DramaPlaylistCategoryDrama {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
private Long categoryId;
|
||||
private Long dramaId;
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.dal.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.fruitshorts.content.dal.entity.DramaClassificationDrama;
|
||||
|
||||
public interface DramaClassificationDramaMapper extends BaseMapper<DramaClassificationDrama> {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.dal.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.fruitshorts.content.dal.entity.DramaClassification;
|
||||
|
||||
public interface DramaClassificationMapper extends BaseMapper<DramaClassification> {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.dal.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.fruitshorts.content.dal.entity.DramaPlaylistCategoryDrama;
|
||||
|
||||
public interface DramaPlaylistCategoryDramaMapper extends BaseMapper<DramaPlaylistCategoryDrama> {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.dal.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.fruitshorts.content.dal.entity.DramaPlaylistCategory;
|
||||
|
||||
public interface DramaPlaylistCategoryMapper extends BaseMapper<DramaPlaylistCategory> {
|
||||
}
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fruitshorts.common.exception.ErrorCode;
|
||||
import com.fruitshorts.common.exception.ServiceException;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaClassification;
|
||||
import com.fruitshorts.content.dal.entity.DramaClassificationDrama;
|
||||
import com.fruitshorts.content.dal.mapper.DramaClassificationDramaMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaClassificationMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaMapper;
|
||||
import com.fruitshorts.content.vo.DramaBriefVO;
|
||||
import com.fruitshorts.content.vo.DramaClassificationRespVO;
|
||||
import com.fruitshorts.content.vo.DramaClassificationSaveReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 运营分类服务。分类是独立于「短剧类型(drama_category)」的一套概念,
|
||||
* 由运营自定义增删,并通过关联表挂载任意多部短剧。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DramaClassificationService {
|
||||
|
||||
private final DramaClassificationMapper classificationMapper;
|
||||
private final DramaClassificationDramaMapper classificationDramaMapper;
|
||||
private final DramaMapper dramaMapper;
|
||||
|
||||
public List<DramaClassificationRespVO> list() {
|
||||
Map<Long, Integer> counts = countDramas();
|
||||
return classificationMapper.selectList(Wrappers.<DramaClassification>lambdaQuery()
|
||||
.orderByAsc(DramaClassification::getSort)
|
||||
.orderByDesc(DramaClassification::getId))
|
||||
.stream().map(item -> {
|
||||
DramaClassificationRespVO vo = new DramaClassificationRespVO();
|
||||
vo.setId(item.getId());
|
||||
vo.setName(item.getName());
|
||||
vo.setSort(item.getSort());
|
||||
vo.setStatus(item.getStatus());
|
||||
vo.setUpdatedAt(item.getUpdatedAt());
|
||||
vo.setDramaCount(counts.getOrDefault(item.getId(), 0));
|
||||
return vo;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
public Long create(DramaClassificationSaveReqVO req) {
|
||||
ensureNameAvailable(req.getName(), null);
|
||||
DramaClassification entity = new DramaClassification();
|
||||
entity.setName(req.getName().trim());
|
||||
Long count = classificationMapper.selectCount(null);
|
||||
entity.setSort(req.getSort() == null
|
||||
? (count == null ? 0 : count.intValue()) + 1
|
||||
: req.getSort());
|
||||
entity.setStatus(req.getStatus() == null ? 1 : req.getStatus());
|
||||
classificationMapper.insert(entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
public void update(Long id, DramaClassificationSaveReqVO req) {
|
||||
DramaClassification entity = getExisting(id);
|
||||
ensureNameAvailable(req.getName(), id);
|
||||
entity.setName(req.getName().trim());
|
||||
if (req.getSort() != null) {
|
||||
entity.setSort(req.getSort());
|
||||
}
|
||||
if (req.getStatus() != null) {
|
||||
entity.setStatus(req.getStatus());
|
||||
}
|
||||
classificationMapper.updateById(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
getExisting(id);
|
||||
classificationDramaMapper.delete(Wrappers.<DramaClassificationDrama>lambdaQuery()
|
||||
.eq(DramaClassificationDrama::getClassificationId, id));
|
||||
classificationMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/** 分类下已关联的短剧(分页)。 */
|
||||
public PageResult<DramaBriefVO> pageDramas(Long id, String keyword,
|
||||
int pageIndex, int pageSize) {
|
||||
return pageDramas(id, keyword, pageIndex, pageSize, true);
|
||||
}
|
||||
|
||||
/** 尚未关联到该分类的短剧(分页),供「添加短剧」多选。 */
|
||||
public PageResult<DramaBriefVO> pageCandidates(Long id, String keyword,
|
||||
int pageIndex, int pageSize) {
|
||||
return pageDramas(id, keyword, pageIndex, pageSize, false);
|
||||
}
|
||||
|
||||
/** 批量关联短剧;已关联的自动跳过。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int bindDramas(Long id, List<Long> dramaIds) {
|
||||
getExisting(id);
|
||||
if (dramaIds == null || dramaIds.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int added = 0;
|
||||
for (Long dramaId : dramaIds) {
|
||||
if (dramaId == null || dramaMapper.selectById(dramaId) == null) {
|
||||
continue;
|
||||
}
|
||||
Long exists = classificationDramaMapper.selectCount(
|
||||
Wrappers.<DramaClassificationDrama>lambdaQuery()
|
||||
.eq(DramaClassificationDrama::getClassificationId, id)
|
||||
.eq(DramaClassificationDrama::getDramaId, dramaId));
|
||||
if (exists != null && exists > 0) {
|
||||
continue;
|
||||
}
|
||||
DramaClassificationDrama relation = new DramaClassificationDrama();
|
||||
relation.setClassificationId(id);
|
||||
relation.setDramaId(dramaId);
|
||||
classificationDramaMapper.insert(relation);
|
||||
added++;
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
/** 移出分类;短剧本身不受影响。 */
|
||||
public void unbindDrama(Long id, Long dramaId) {
|
||||
getExisting(id);
|
||||
classificationDramaMapper.delete(Wrappers.<DramaClassificationDrama>lambdaQuery()
|
||||
.eq(DramaClassificationDrama::getClassificationId, id)
|
||||
.eq(DramaClassificationDrama::getDramaId, dramaId));
|
||||
}
|
||||
|
||||
private PageResult<DramaBriefVO> pageDramas(Long id, String keyword,
|
||||
int pageIndex, int pageSize, boolean bound) {
|
||||
getExisting(id);
|
||||
Page<Drama> page = new Page<>(Math.max(1, pageIndex), Math.max(1, Math.min(pageSize, 100)));
|
||||
LambdaQueryWrapper<Drama> wrapper = Wrappers.<Drama>lambdaQuery()
|
||||
.like(StringUtils.hasText(keyword), Drama::getTitle, keyword)
|
||||
.orderByDesc(Drama::getSort)
|
||||
.orderByDesc(Drama::getId);
|
||||
String subQuery = "SELECT drama_id FROM drama_classification_drama WHERE classification_id = " + id;
|
||||
if (bound) {
|
||||
wrapper.inSql(Drama::getId, subQuery);
|
||||
} else {
|
||||
wrapper.notInSql(Drama::getId, subQuery);
|
||||
}
|
||||
IPage<Drama> result = dramaMapper.selectPage(page, wrapper);
|
||||
return new PageResult<>(result.getTotal(),
|
||||
result.getRecords().stream().map(this::toBrief).toList());
|
||||
}
|
||||
|
||||
private Map<Long, Integer> countDramas() {
|
||||
Map<Long, Integer> counts = new HashMap<>();
|
||||
classificationDramaMapper.selectMaps(new QueryWrapper<DramaClassificationDrama>()
|
||||
.select("classification_id AS cid", "COUNT(*) AS cnt")
|
||||
.groupBy("classification_id"))
|
||||
.forEach(row -> {
|
||||
Object cid = row.get("cid");
|
||||
Object cnt = row.get("cnt");
|
||||
if (cid instanceof Number c && cnt instanceof Number n) {
|
||||
counts.put(c.longValue(), n.intValue());
|
||||
}
|
||||
});
|
||||
return counts;
|
||||
}
|
||||
|
||||
private DramaClassification getExisting(Long id) {
|
||||
DramaClassification entity = id == null ? null : classificationMapper.selectById(id);
|
||||
if (entity == null) {
|
||||
throw new ServiceException(ErrorCode.DATA_NOT_FOUND, "分类不存在");
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void ensureNameAvailable(String name, Long excludeId) {
|
||||
Long count = classificationMapper.selectCount(Wrappers.<DramaClassification>lambdaQuery()
|
||||
.eq(DramaClassification::getName, name.trim())
|
||||
.ne(excludeId != null, DramaClassification::getId, excludeId));
|
||||
if (count != null && count > 0) {
|
||||
throw new ServiceException(ErrorCode.DATA_EXISTS, "分类名称已存在");
|
||||
}
|
||||
}
|
||||
|
||||
private DramaBriefVO toBrief(Drama drama) {
|
||||
DramaBriefVO vo = new DramaBriefVO();
|
||||
vo.setId(drama.getId());
|
||||
vo.setTitle(drama.getTitle());
|
||||
vo.setCover(drama.getCoverUrl());
|
||||
vo.setStatus(drama.getStatus());
|
||||
vo.setTotalEpisodes(drama.getTotalEpisodes());
|
||||
vo.setSort(drama.getSort());
|
||||
vo.setUpdatedAt(drama.getUpdatedAt());
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+13
@@ -99,6 +99,19 @@ final class DramaMultiTagSupport {
|
||||
});
|
||||
}
|
||||
|
||||
static void applyCategoryIdTokens(QueryWrapper<Drama> wrapper,
|
||||
List<Long> categoryIds) {
|
||||
wrapper.and(nested -> {
|
||||
for (int index = 0; index < categoryIds.size(); index++) {
|
||||
if (index > 0) {
|
||||
nested.or();
|
||||
}
|
||||
nested.apply("(',' || category_ids || ',') LIKE {0}",
|
||||
tokenPattern(categoryIds.get(index)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static List<String> parseDramaTypes(Drama drama) {
|
||||
List<String> values = parseStringTokens(drama.getDramaTypes()).stream()
|
||||
.map(DramaMultiTagSupport::normalizeDramaType)
|
||||
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fruitshorts.common.exception.ErrorCode;
|
||||
import com.fruitshorts.common.exception.ServiceException;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaPlaylistCategory;
|
||||
import com.fruitshorts.content.dal.entity.DramaPlaylistCategoryDrama;
|
||||
import com.fruitshorts.content.dal.mapper.DramaMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaPlaylistCategoryDramaMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaPlaylistCategoryMapper;
|
||||
import com.fruitshorts.content.vo.DramaBriefVO;
|
||||
import com.fruitshorts.content.vo.DramaPlaylistCategoryRespVO;
|
||||
import com.fruitshorts.content.vo.DramaPlaylistCategorySaveReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 剧单分类服务:分类直接关联短剧,没有「剧单」这一层。
|
||||
* 这套分类与「类型」「分类管理」都不是同一套数据。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DramaPlaylistCategoryService {
|
||||
|
||||
private final DramaPlaylistCategoryMapper categoryMapper;
|
||||
private final DramaPlaylistCategoryDramaMapper categoryDramaMapper;
|
||||
private final DramaMapper dramaMapper;
|
||||
|
||||
public List<DramaPlaylistCategoryRespVO> list() {
|
||||
Map<Long, Integer> counts = countDramas();
|
||||
return categoryMapper.selectList(Wrappers.<DramaPlaylistCategory>lambdaQuery()
|
||||
.orderByAsc(DramaPlaylistCategory::getSort)
|
||||
.orderByDesc(DramaPlaylistCategory::getId))
|
||||
.stream().map(item -> {
|
||||
DramaPlaylistCategoryRespVO vo = new DramaPlaylistCategoryRespVO();
|
||||
vo.setId(item.getId());
|
||||
vo.setName(item.getName());
|
||||
vo.setDescription(item.getDescription());
|
||||
vo.setSort(item.getSort());
|
||||
vo.setStatus(item.getStatus());
|
||||
vo.setDramaCount(counts.getOrDefault(item.getId(), 0));
|
||||
return vo;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
public Long create(DramaPlaylistCategorySaveReqVO req) {
|
||||
ensureNameAvailable(req.getName(), null);
|
||||
DramaPlaylistCategory entity = new DramaPlaylistCategory();
|
||||
entity.setName(req.getName().trim());
|
||||
entity.setDescription(req.getDescription() == null ? "" : req.getDescription().trim());
|
||||
Long count = categoryMapper.selectCount(null);
|
||||
entity.setSort(req.getSort() == null
|
||||
? (count == null ? 0 : count.intValue()) + 1
|
||||
: req.getSort());
|
||||
entity.setStatus(req.getStatus() == null ? 1 : req.getStatus());
|
||||
categoryMapper.insert(entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
public void update(Long id, DramaPlaylistCategorySaveReqVO req) {
|
||||
DramaPlaylistCategory entity = getExisting(id);
|
||||
ensureNameAvailable(req.getName(), id);
|
||||
entity.setName(req.getName().trim());
|
||||
if (req.getDescription() != null) {
|
||||
entity.setDescription(req.getDescription().trim());
|
||||
}
|
||||
if (req.getSort() != null) {
|
||||
entity.setSort(req.getSort());
|
||||
}
|
||||
if (req.getStatus() != null) {
|
||||
entity.setStatus(req.getStatus());
|
||||
}
|
||||
categoryMapper.updateById(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
getExisting(id);
|
||||
categoryDramaMapper.delete(Wrappers.<DramaPlaylistCategoryDrama>lambdaQuery()
|
||||
.eq(DramaPlaylistCategoryDrama::getCategoryId, id));
|
||||
categoryMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/** 分类下已关联的短剧(分页)。 */
|
||||
public PageResult<DramaBriefVO> pageDramas(Long id, String keyword,
|
||||
int pageIndex, int pageSize) {
|
||||
return pageDramas(id, keyword, pageIndex, pageSize, true);
|
||||
}
|
||||
|
||||
/** 尚未关联到该分类的短剧(分页),供「选择短剧」多选。 */
|
||||
public PageResult<DramaBriefVO> pageCandidates(Long id, String keyword,
|
||||
int pageIndex, int pageSize) {
|
||||
return pageDramas(id, keyword, pageIndex, pageSize, false);
|
||||
}
|
||||
|
||||
/** 批量把短剧加入分类;已关联的自动跳过。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int bindDramas(Long id, List<Long> dramaIds) {
|
||||
getExisting(id);
|
||||
if (dramaIds == null || dramaIds.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int added = 0;
|
||||
for (Long dramaId : dramaIds) {
|
||||
if (dramaId == null || dramaMapper.selectById(dramaId) == null) {
|
||||
continue;
|
||||
}
|
||||
Long exists = categoryDramaMapper.selectCount(
|
||||
Wrappers.<DramaPlaylistCategoryDrama>lambdaQuery()
|
||||
.eq(DramaPlaylistCategoryDrama::getCategoryId, id)
|
||||
.eq(DramaPlaylistCategoryDrama::getDramaId, dramaId));
|
||||
if (exists != null && exists > 0) {
|
||||
continue;
|
||||
}
|
||||
DramaPlaylistCategoryDrama relation = new DramaPlaylistCategoryDrama();
|
||||
relation.setCategoryId(id);
|
||||
relation.setDramaId(dramaId);
|
||||
categoryDramaMapper.insert(relation);
|
||||
added++;
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
/** 把短剧移出分类;短剧本身不受影响。 */
|
||||
public void unbindDrama(Long id, Long dramaId) {
|
||||
getExisting(id);
|
||||
categoryDramaMapper.delete(Wrappers.<DramaPlaylistCategoryDrama>lambdaQuery()
|
||||
.eq(DramaPlaylistCategoryDrama::getCategoryId, id)
|
||||
.eq(DramaPlaylistCategoryDrama::getDramaId, dramaId));
|
||||
}
|
||||
|
||||
private PageResult<DramaBriefVO> pageDramas(Long id, String keyword,
|
||||
int pageIndex, int pageSize, boolean bound) {
|
||||
getExisting(id);
|
||||
Page<Drama> page = new Page<>(Math.max(1, pageIndex), Math.max(1, Math.min(pageSize, 100)));
|
||||
LambdaQueryWrapper<Drama> wrapper = Wrappers.<Drama>lambdaQuery()
|
||||
.like(StringUtils.hasText(keyword), Drama::getTitle, keyword)
|
||||
.orderByDesc(Drama::getSort)
|
||||
.orderByDesc(Drama::getId);
|
||||
String subQuery = "SELECT drama_id FROM drama_playlist_category_drama WHERE category_id = " + id;
|
||||
if (bound) {
|
||||
wrapper.inSql(Drama::getId, subQuery);
|
||||
} else {
|
||||
wrapper.notInSql(Drama::getId, subQuery);
|
||||
}
|
||||
IPage<Drama> result = dramaMapper.selectPage(page, wrapper);
|
||||
return new PageResult<>(result.getTotal(),
|
||||
result.getRecords().stream().map(this::toBrief).toList());
|
||||
}
|
||||
|
||||
private Map<Long, Integer> countDramas() {
|
||||
Map<Long, Integer> counts = new HashMap<>();
|
||||
categoryDramaMapper.selectMaps(new QueryWrapper<DramaPlaylistCategoryDrama>()
|
||||
.select("category_id AS cid", "COUNT(*) AS cnt")
|
||||
.groupBy("category_id"))
|
||||
.forEach(row -> {
|
||||
Object cid = row.get("cid");
|
||||
Object cnt = row.get("cnt");
|
||||
if (cid instanceof Number c && cnt instanceof Number n) {
|
||||
counts.put(c.longValue(), n.intValue());
|
||||
}
|
||||
});
|
||||
return counts;
|
||||
}
|
||||
|
||||
private DramaPlaylistCategory getExisting(Long id) {
|
||||
DramaPlaylistCategory entity = id == null ? null : categoryMapper.selectById(id);
|
||||
if (entity == null) {
|
||||
throw new ServiceException(ErrorCode.DATA_NOT_FOUND, "剧单分类不存在");
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void ensureNameAvailable(String name, Long excludeId) {
|
||||
Long count = categoryMapper.selectCount(Wrappers.<DramaPlaylistCategory>lambdaQuery()
|
||||
.eq(DramaPlaylistCategory::getName, name.trim())
|
||||
.ne(excludeId != null, DramaPlaylistCategory::getId, excludeId));
|
||||
if (count != null && count > 0) {
|
||||
throw new ServiceException(ErrorCode.DATA_EXISTS, "剧单分类名称已存在");
|
||||
}
|
||||
}
|
||||
|
||||
private DramaBriefVO toBrief(Drama drama) {
|
||||
DramaBriefVO vo = new DramaBriefVO();
|
||||
vo.setId(drama.getId());
|
||||
vo.setTitle(drama.getTitle());
|
||||
vo.setCover(drama.getCoverUrl());
|
||||
vo.setStatus(drama.getStatus());
|
||||
vo.setTotalEpisodes(drama.getTotalEpisodes());
|
||||
vo.setSort(drama.getSort());
|
||||
vo.setUpdatedAt(drama.getUpdatedAt());
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+54
-17
@@ -42,6 +42,7 @@ public class DramaService {
|
||||
private final DramaEpisodeMapper dramaEpisodeMapper;
|
||||
private final DramaReviewRecordMapper dramaReviewRecordMapper;
|
||||
private final DramaCategoryService dramaCategoryService;
|
||||
private final EpisodePriceSync episodePriceSync;
|
||||
|
||||
public PageResult<DramaRespVO> page(DramaPageReqVO req) {
|
||||
List<String> dramaTypes = DramaMultiTagSupport.normalizeDramaTypes(req.getDramaTypes());
|
||||
@@ -92,7 +93,7 @@ public class DramaService {
|
||||
|
||||
private Long insert(DramaSaveReqVO req, Long operatorId, Long creatorId) {
|
||||
Drama drama = new Drama();
|
||||
apply(drama, req);
|
||||
apply(drama, req, true);
|
||||
drama.setCode(generateCode());
|
||||
drama.setStatus(ContentStatus.DRAFT.getCode());
|
||||
drama.setCreatorId(creatorId == null ? 0L : creatorId);
|
||||
@@ -109,7 +110,7 @@ public class DramaService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Long id, DramaSaveReqVO req) {
|
||||
Drama drama = getExisting(id);
|
||||
apply(drama, req);
|
||||
apply(drama, req, false);
|
||||
if (req.getFavoriteCount() != null) {
|
||||
drama.setFavoriteCount(nonNegative(req.getFavoriteCount(), "收藏数"));
|
||||
}
|
||||
@@ -120,6 +121,7 @@ public class DramaService {
|
||||
drama.setViewCount(nonNegative(req.getHeat(), "热度"));
|
||||
}
|
||||
dramaMapper.updateById(drama);
|
||||
episodePriceSync.syncByDramaRule(drama);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -237,20 +239,26 @@ public class DramaService {
|
||||
* App 推荐流:按推荐权重、热度、ID 倒序,并支持内容类型多选。
|
||||
* cursor 使用上一页最后一条 ID,服务端反查排序键后做 keyset 查询。
|
||||
*/
|
||||
public List<Drama> listPublishedFeed(List<String> dramaTypes, Long cursor, int limit) {
|
||||
public List<Drama> listPublishedFeed(
|
||||
List<String> dramaTypes, Long categoryId, Long cursor, int limit) {
|
||||
List<String> normalizedTypes = DramaMultiTagSupport.normalizeDramaTypes(dramaTypes);
|
||||
QueryWrapper<Drama> query = new QueryWrapper<>();
|
||||
query.eq("status", ContentStatus.PUBLISHED.getCode());
|
||||
if (!normalizedTypes.isEmpty()) {
|
||||
DramaMultiTagSupport.applyDramaTypeTokens(query, normalizedTypes);
|
||||
}
|
||||
if (categoryId != null) {
|
||||
DramaMultiTagSupport.applyCategoryIdTokens(query, List.of(categoryId));
|
||||
}
|
||||
if (cursor != null) {
|
||||
Drama marker = dramaMapper.selectById(cursor);
|
||||
if (marker == null
|
||||
|| !ContentStatus.PUBLISHED.getCode().equals(marker.getStatus())
|
||||
|| (!normalizedTypes.isEmpty()
|
||||
&& DramaMultiTagSupport.parseDramaTypes(marker).stream()
|
||||
.noneMatch(normalizedTypes::contains))) {
|
||||
.noneMatch(normalizedTypes::contains))
|
||||
|| (categoryId != null
|
||||
&& !DramaMultiTagSupport.parseCategoryIds(marker).contains(categoryId))) {
|
||||
return List.of();
|
||||
}
|
||||
applyFeedCursor(query, marker);
|
||||
@@ -339,21 +347,50 @@ public class DramaService {
|
||||
}
|
||||
}
|
||||
|
||||
private void apply(Drama drama, DramaSaveReqVO req) {
|
||||
/**
|
||||
* 字段映射。新建时(isNew=true)缺省字段按默认值补齐;
|
||||
* 更新时只覆盖请求里显式传入的字段,漏传的字段保持库里原值,
|
||||
* 避免编辑表单没带 sort / language / trailerUrl 时把已有数据清掉。
|
||||
*/
|
||||
private void apply(Drama drama, DramaSaveReqVO req, boolean isNew) {
|
||||
drama.setTitle(req.getTitle());
|
||||
drama.setSubtitle(req.getSubtitle() == null ? "" : req.getSubtitle());
|
||||
DramaMultiTagSupport.applyCategoryIds(drama, req);
|
||||
drama.setGenre(req.getGenre() == null ? "" : req.getGenre());
|
||||
drama.setSynopsis(req.getDescription() == null ? "" : req.getDescription());
|
||||
drama.setCoverUrl(req.getCover() == null ? "" : req.getCover());
|
||||
drama.setTrailerUrl(req.getTrailerUrl() == null ? "" : req.getTrailerUrl());
|
||||
if (isNew || req.getSubtitle() != null) {
|
||||
drama.setSubtitle(req.getSubtitle() == null ? "" : req.getSubtitle());
|
||||
}
|
||||
if (isNew || req.getCategoryIds() != null || req.getCategoryId() != null) {
|
||||
DramaMultiTagSupport.applyCategoryIds(drama, req);
|
||||
}
|
||||
if (isNew || req.getGenre() != null) {
|
||||
drama.setGenre(req.getGenre() == null ? "" : req.getGenre());
|
||||
}
|
||||
if (isNew || req.getDescription() != null) {
|
||||
drama.setSynopsis(req.getDescription() == null ? "" : req.getDescription());
|
||||
}
|
||||
if (isNew || req.getCover() != null) {
|
||||
drama.setCoverUrl(req.getCover() == null ? "" : req.getCover());
|
||||
}
|
||||
if (isNew || req.getTrailerUrl() != null) {
|
||||
drama.setTrailerUrl(req.getTrailerUrl() == null ? "" : req.getTrailerUrl());
|
||||
}
|
||||
drama.setHorizontalCoverUrl(drama.getHorizontalCoverUrl() == null ? "" : drama.getHorizontalCoverUrl());
|
||||
drama.setLanguage(req.getLanguage() == null ? "zh-CN" : req.getLanguage());
|
||||
DramaMultiTagSupport.applyDramaTypes(drama, req);
|
||||
drama.setFreeEpisodes(req.getFreeEpisodes() == null ? 3 : req.getFreeEpisodes());
|
||||
drama.setUnlockCoin(req.getUnlockCoin() == null ? 0 : req.getUnlockCoin());
|
||||
drama.setIsHot(Boolean.TRUE.equals(req.getIsHot()) ? 1 : 0);
|
||||
drama.setSort(req.getSort() == null ? 0 : req.getSort());
|
||||
if (isNew || req.getLanguage() != null) {
|
||||
drama.setLanguage(req.getLanguage() == null ? "zh-CN" : req.getLanguage());
|
||||
}
|
||||
if (isNew || req.getDramaTypes() != null || req.getDramaType() != null) {
|
||||
DramaMultiTagSupport.applyDramaTypes(drama, req);
|
||||
}
|
||||
if (isNew || req.getFreeEpisodes() != null) {
|
||||
drama.setFreeEpisodes(req.getFreeEpisodes() == null ? 3 : req.getFreeEpisodes());
|
||||
}
|
||||
if (isNew || req.getUnlockCoin() != null) {
|
||||
drama.setUnlockCoin(req.getUnlockCoin() == null ? 0 : req.getUnlockCoin());
|
||||
}
|
||||
if (isNew || req.getIsHot() != null) {
|
||||
drama.setIsHot(Boolean.TRUE.equals(req.getIsHot()) ? 1 : 0);
|
||||
}
|
||||
if (isNew || req.getSort() != null) {
|
||||
drama.setSort(req.getSort() == null ? 0 : req.getSort());
|
||||
}
|
||||
}
|
||||
|
||||
private String generateCode() {
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.dal.mapper.DramaEpisodeMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 按短剧免费集数规则同步分集 {@code is_free} / {@code unlock_coin}。
|
||||
*
|
||||
* <p>定价页与短剧编辑共用同一套规则,避免两处口径漂移。</p>
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class EpisodePriceSync {
|
||||
|
||||
private final DramaEpisodeMapper dramaEpisodeMapper;
|
||||
|
||||
/**
|
||||
* 按短剧当前免费集数与解锁金币同步全部分集。
|
||||
*
|
||||
* @return 实际写库的分集数
|
||||
*/
|
||||
public int syncByDramaRule(Drama drama) {
|
||||
int freeEpisodes = drama.getFreeEpisodes() == null ? 0 : Math.max(0, drama.getFreeEpisodes());
|
||||
int unlockCoin = drama.getUnlockCoin() == null ? 0 : Math.max(0, drama.getUnlockCoin());
|
||||
return syncByDramaRule(drama.getId(), freeEpisodes, unlockCoin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全量同步某剧全部分集价格。
|
||||
*
|
||||
* <p>规则:{@code epNo > 0 && epNo <= freeEpisodes} 为免费且 coin=0,
|
||||
* 否则收费且 coin={@code unlockCoin}。</p>
|
||||
*
|
||||
* @return 实际写库的分集数
|
||||
*/
|
||||
public int syncByDramaRule(Long dramaId, int freeEpisodes, int unlockCoin) {
|
||||
List<DramaEpisode> episodes = dramaEpisodeMapper.selectList(Wrappers.<DramaEpisode>lambdaQuery()
|
||||
.eq(DramaEpisode::getDramaId, dramaId)
|
||||
.orderByAsc(DramaEpisode::getEpNo));
|
||||
int changed = 0;
|
||||
for (DramaEpisode episode : episodes) {
|
||||
int epNo = episode.getEpNo() == null ? 0 : episode.getEpNo();
|
||||
int isFree = resolveIsFree(epNo, freeEpisodes);
|
||||
int coin = resolveUnlockCoin(isFree, unlockCoin);
|
||||
if (!Objects.equals(episode.getIsFree(), isFree)
|
||||
|| !Objects.equals(episode.getUnlockCoin(), coin)) {
|
||||
episode.setIsFree(isFree);
|
||||
episode.setUnlockCoin(coin);
|
||||
dramaEpisodeMapper.updateById(episode);
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
/** 集号落在免费区间内则为免费。 */
|
||||
public static int resolveIsFree(int epNo, int freeEpisodes) {
|
||||
return epNo > 0 && epNo <= freeEpisodes ? 1 : 0;
|
||||
}
|
||||
|
||||
/** 免费集 coin 置 0,收费集用短剧解锁金币。 */
|
||||
public static int resolveUnlockCoin(int isFree, int unlockCoin) {
|
||||
return isFree == 1 ? 0 : unlockCoin;
|
||||
}
|
||||
}
|
||||
+93
-6
@@ -2,18 +2,26 @@
|
||||
|
||||
package com.fruitshorts.content.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fruitshorts.common.exception.ErrorCode;
|
||||
import com.fruitshorts.common.exception.ServiceException;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.dal.mapper.DramaEpisodeMapper;
|
||||
import com.fruitshorts.content.enums.ContentStatus;
|
||||
import com.fruitshorts.content.vo.EpisodeRespVO;
|
||||
import com.fruitshorts.content.vo.EpisodeSaveReqVO;
|
||||
import com.fruitshorts.media.service.EpisodeTranscodeBindingService;
|
||||
import com.fruitshorts.media.service.EpisodeTranscodeCompletionPort;
|
||||
import com.fruitshorts.media.service.EpisodeVideoSourcePort;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -24,21 +32,72 @@ import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EpisodeService {
|
||||
public class EpisodeService implements EpisodeTranscodeCompletionPort, EpisodeVideoSourcePort {
|
||||
|
||||
private static final int DEFAULT_PAGE_INDEX = 1;
|
||||
private static final int DEFAULT_PAGE_SIZE = 100;
|
||||
private static final int MAX_PAGE_SIZE = 200;
|
||||
|
||||
private final DramaEpisodeMapper dramaEpisodeMapper;
|
||||
private final DramaService dramaService;
|
||||
private final EpisodeTranscodeBindingService transcodeBindingService;
|
||||
|
||||
@Override
|
||||
public java.util.Optional<EpisodeVideoSource> resolveByVideoUrl(String videoUrl) {
|
||||
if (!StringUtils.hasText(videoUrl)) {
|
||||
return java.util.Optional.empty();
|
||||
}
|
||||
DramaEpisode episode = dramaEpisodeMapper.selectOne(Wrappers.<DramaEpisode>lambdaQuery()
|
||||
.eq(DramaEpisode::getVideoUrl, videoUrl)
|
||||
.last("limit 1"));
|
||||
return episode == null
|
||||
? java.util.Optional.empty()
|
||||
: java.util.Optional.of(toVideoSource(episode));
|
||||
}
|
||||
|
||||
private EpisodeVideoSource toVideoSource(DramaEpisode episode) {
|
||||
return new EpisodeVideoSource(
|
||||
episode.getId(), episode.getDramaId(), episode.getVideoAssetId(),
|
||||
episode.getVideoUrl(), episode.getDurationSec());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void link(Long episodeId, Long mediaAssetId) {
|
||||
if (episodeId == null || episodeId <= 0 || mediaAssetId == null || mediaAssetId <= 0) {
|
||||
return;
|
||||
}
|
||||
dramaEpisodeMapper.update(null, Wrappers.<DramaEpisode>lambdaUpdate()
|
||||
.eq(DramaEpisode::getId, episodeId)
|
||||
.set(DramaEpisode::getVideoAssetId, mediaAssetId));
|
||||
}
|
||||
|
||||
/** 后台:按短剧分页查询分集,status 在 SQL 层过滤;排序稳定(sort、ep_no)。 */
|
||||
public PageResult<EpisodeRespVO> pageByDrama(Long dramaId, String status,
|
||||
Integer pageIndex, Integer pageSize) {
|
||||
dramaService.getExisting(dramaId);
|
||||
int safeIndex = pageIndex == null || pageIndex < 1 ? DEFAULT_PAGE_INDEX : pageIndex;
|
||||
int safeSize = pageSize == null || pageSize < 1
|
||||
? DEFAULT_PAGE_SIZE : Math.min(pageSize, MAX_PAGE_SIZE);
|
||||
IPage<DramaEpisode> result = dramaEpisodeMapper.selectPage(
|
||||
new Page<>(safeIndex, safeSize), buildListQuery(dramaId, status));
|
||||
return new PageResult<>(result.getTotal(), result.getRecords().stream().map(this::toResp).toList());
|
||||
}
|
||||
|
||||
public List<EpisodeRespVO> listByDrama(Long dramaId, String status) {
|
||||
dramaService.getExisting(dramaId);
|
||||
return dramaEpisodeMapper.selectList(Wrappers.<DramaEpisode>lambdaQuery()
|
||||
.eq(DramaEpisode::getDramaId, dramaId)
|
||||
.eq(status != null && !status.isBlank(), DramaEpisode::getStatus, status)
|
||||
.orderByAsc(DramaEpisode::getSort)
|
||||
.orderByAsc(DramaEpisode::getEpNo))
|
||||
return dramaEpisodeMapper.selectList(buildListQuery(dramaId, status))
|
||||
.stream().map(this::toResp).toList();
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<DramaEpisode> buildListQuery(Long dramaId, String status) {
|
||||
return Wrappers.<DramaEpisode>lambdaQuery()
|
||||
.eq(DramaEpisode::getDramaId, dramaId)
|
||||
.eq(StringUtils.hasText(status), DramaEpisode::getStatus, status)
|
||||
.orderByAsc(DramaEpisode::getSort)
|
||||
.orderByAsc(DramaEpisode::getEpNo);
|
||||
}
|
||||
|
||||
/** C 端:只返回已上线剧集,按播放顺序 */
|
||||
public List<DramaEpisode> listPublishedByDrama(Long dramaId) {
|
||||
return dramaEpisodeMapper.selectList(Wrappers.<DramaEpisode>lambdaQuery()
|
||||
@@ -110,6 +169,7 @@ public class EpisodeService {
|
||||
episode.setLikeCount(nonNegativeOrZero(req.getLikeCount()));
|
||||
episode.setVideoAssetId(0L);
|
||||
dramaEpisodeMapper.insert(episode);
|
||||
bindTranscodeTask(episode);
|
||||
dramaService.syncTotalEpisodes(req.getDramaId());
|
||||
return episode.getId();
|
||||
}
|
||||
@@ -127,6 +187,7 @@ public class EpisodeService {
|
||||
episode.setStatus(req.getStatus());
|
||||
}
|
||||
dramaEpisodeMapper.updateById(episode);
|
||||
bindTranscodeTask(episode);
|
||||
if (!req.getDramaId().equals(episode.getDramaId())) {
|
||||
dramaService.syncTotalEpisodes(req.getDramaId());
|
||||
}
|
||||
@@ -227,6 +288,32 @@ public class EpisodeService {
|
||||
episode.setSort(req.getSort() == null ? (req.getNumber() == null ? 0 : req.getNumber()) : req.getSort());
|
||||
}
|
||||
|
||||
private void bindTranscodeTask(DramaEpisode episode) {
|
||||
Long assetId = transcodeBindingService.bind(
|
||||
episode.getId(), episode.getDramaId(), episode.getVideoUrl());
|
||||
if (assetId != null && assetId > 0
|
||||
&& !Objects.equals(assetId, episode.getVideoAssetId())) {
|
||||
episode.setVideoAssetId(assetId);
|
||||
dramaEpisodeMapper.updateById(episode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markEpisodeReady(Long episodeId, String hlsUrl, Integer durationSec) {
|
||||
if (episodeId == null || episodeId <= 0 || !StringUtils.hasText(hlsUrl)) {
|
||||
return;
|
||||
}
|
||||
var update = Wrappers.<DramaEpisode>lambdaUpdate()
|
||||
.eq(DramaEpisode::getId, episodeId)
|
||||
.set(DramaEpisode::getHlsUrl, hlsUrl)
|
||||
.set(DramaEpisode::getTranscodeStatus, "success");
|
||||
if (durationSec != null && durationSec > 0) {
|
||||
update.set(DramaEpisode::getDurationSec, durationSec);
|
||||
}
|
||||
dramaEpisodeMapper.update(null, update);
|
||||
}
|
||||
|
||||
private EpisodeRespVO toResp(DramaEpisode episode) {
|
||||
EpisodeRespVO vo = new EpisodeRespVO();
|
||||
vo.setId(episode.getId());
|
||||
|
||||
+56
-45
@@ -32,6 +32,7 @@ public class PriceService {
|
||||
private final DramaService dramaService;
|
||||
private final DramaMapper dramaMapper;
|
||||
private final DramaEpisodeMapper dramaEpisodeMapper;
|
||||
private final EpisodePriceSync episodePriceSync;
|
||||
|
||||
/** 读取当前价格配置:后台定价页进入时先看现状再改。 */
|
||||
public PriceRespVO detail(Long dramaId) {
|
||||
@@ -72,55 +73,13 @@ public class PriceService {
|
||||
drama.setUnlockCoin(unlockCoin);
|
||||
dramaMapper.updateById(drama);
|
||||
|
||||
int changed = episodePriceSync.syncByDramaRule(drama.getId(), freeEpisodes, unlockCoin);
|
||||
changed += applyEpisodeOverrides(drama.getId(), unlockCoin, req);
|
||||
|
||||
List<DramaEpisode> episodes = dramaEpisodeMapper.selectList(Wrappers.<DramaEpisode>lambdaQuery()
|
||||
.eq(DramaEpisode::getDramaId, drama.getId())
|
||||
.orderByAsc(DramaEpisode::getEpNo));
|
||||
|
||||
Map<Long, PriceSaveReqVO.EpisodePrice> overrides = new LinkedHashMap<>();
|
||||
if (req.getEpisodes() != null) {
|
||||
for (PriceSaveReqVO.EpisodePrice item : req.getEpisodes()) {
|
||||
if (item != null && item.getEpisodeId() != null) {
|
||||
overrides.put(item.getEpisodeId(), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int changed = 0;
|
||||
for (DramaEpisode episode : episodes) {
|
||||
int epNo = episode.getEpNo() == null ? 0 : episode.getEpNo();
|
||||
int isFree = epNo > 0 && epNo <= freeEpisodes ? 1 : 0;
|
||||
int coin = isFree == 1 ? 0 : unlockCoin;
|
||||
|
||||
PriceSaveReqVO.EpisodePrice override = overrides.get(episode.getId());
|
||||
Integer previewSeconds = null;
|
||||
if (override != null) {
|
||||
if (override.getIsFree() != null) {
|
||||
isFree = override.getIsFree() == 1 ? 1 : 0;
|
||||
coin = isFree == 1 ? 0 : unlockCoin;
|
||||
}
|
||||
if (isFree == 0 && override.getUnlockCoin() != null) {
|
||||
coin = Math.max(0, override.getUnlockCoin());
|
||||
}
|
||||
if (override.getPreviewSeconds() != null) {
|
||||
previewSeconds = Math.max(0, override.getPreviewSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
boolean priceChanged = !Objects.equals(episode.getIsFree(), isFree)
|
||||
|| !Objects.equals(episode.getUnlockCoin(), coin);
|
||||
boolean previewChanged = previewSeconds != null
|
||||
&& !Objects.equals(episode.getPreviewSeconds(), previewSeconds);
|
||||
if (priceChanged || previewChanged) {
|
||||
episode.setIsFree(isFree);
|
||||
episode.setUnlockCoin(coin);
|
||||
if (previewSeconds != null) {
|
||||
episode.setPreviewSeconds(previewSeconds);
|
||||
}
|
||||
dramaEpisodeMapper.updateById(episode);
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
|
||||
PriceRespVO vo = new PriceRespVO();
|
||||
vo.setDramaId(drama.getId());
|
||||
vo.setFreeEpisodes(freeEpisodes);
|
||||
@@ -139,4 +98,56 @@ public class PriceService {
|
||||
}).toList());
|
||||
return vo;
|
||||
}
|
||||
|
||||
/** 在整剧规则同步后再落单集覆盖(含试看秒数)。 */
|
||||
private int applyEpisodeOverrides(Long dramaId, int unlockCoin, PriceSaveReqVO req) {
|
||||
Map<Long, PriceSaveReqVO.EpisodePrice> overrides = new LinkedHashMap<>();
|
||||
if (req.getEpisodes() != null) {
|
||||
for (PriceSaveReqVO.EpisodePrice item : req.getEpisodes()) {
|
||||
if (item != null && item.getEpisodeId() != null) {
|
||||
overrides.put(item.getEpisodeId(), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (overrides.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
List<DramaEpisode> episodes = dramaEpisodeMapper.selectList(Wrappers.<DramaEpisode>lambdaQuery()
|
||||
.eq(DramaEpisode::getDramaId, dramaId)
|
||||
.orderByAsc(DramaEpisode::getEpNo));
|
||||
int changed = 0;
|
||||
for (DramaEpisode episode : episodes) {
|
||||
PriceSaveReqVO.EpisodePrice override = overrides.get(episode.getId());
|
||||
if (override == null) {
|
||||
continue;
|
||||
}
|
||||
int isFree = episode.getIsFree() == null ? 0 : episode.getIsFree();
|
||||
int coin = episode.getUnlockCoin() == null ? 0 : episode.getUnlockCoin();
|
||||
Integer previewSeconds = null;
|
||||
if (override.getIsFree() != null) {
|
||||
isFree = override.getIsFree() == 1 ? 1 : 0;
|
||||
coin = EpisodePriceSync.resolveUnlockCoin(isFree, unlockCoin);
|
||||
}
|
||||
if (isFree == 0 && override.getUnlockCoin() != null) {
|
||||
coin = Math.max(0, override.getUnlockCoin());
|
||||
}
|
||||
if (override.getPreviewSeconds() != null) {
|
||||
previewSeconds = Math.max(0, override.getPreviewSeconds());
|
||||
}
|
||||
boolean priceChanged = !Objects.equals(episode.getIsFree(), isFree)
|
||||
|| !Objects.equals(episode.getUnlockCoin(), coin);
|
||||
boolean previewChanged = previewSeconds != null
|
||||
&& !Objects.equals(episode.getPreviewSeconds(), previewSeconds);
|
||||
if (priceChanged || previewChanged) {
|
||||
episode.setIsFree(isFree);
|
||||
episode.setUnlockCoin(coin);
|
||||
if (previewSeconds != null) {
|
||||
episode.setPreviewSeconds(previewSeconds);
|
||||
}
|
||||
dramaEpisodeMapper.updateById(episode);
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 短剧精简信息:分类关联页列表用。 */
|
||||
@Data
|
||||
public class DramaBriefVO {
|
||||
|
||||
private Long id;
|
||||
private String title;
|
||||
private String cover;
|
||||
private String status;
|
||||
private Integer totalEpisodes;
|
||||
private Integer sort;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 分类列表项:带关联短剧数量。 */
|
||||
@Data
|
||||
public class DramaClassificationRespVO {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
private Integer dramaCount;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/** 分类新增/编辑请求体。 */
|
||||
@Data
|
||||
public class DramaClassificationSaveReqVO {
|
||||
|
||||
@NotBlank(message = "请填写分类名称")
|
||||
private String name;
|
||||
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 批量操作短剧 id 的通用请求体。 */
|
||||
@Data
|
||||
public class DramaIdsReqVO {
|
||||
|
||||
@NotEmpty(message = "请选择短剧")
|
||||
private List<Long> dramaIds;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/** 剧单分类列表项:带该分类下的短剧数量。 */
|
||||
@Data
|
||||
public class DramaPlaylistCategoryRespVO {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
/** 该分类下已关联的短剧数量 */
|
||||
private Integer dramaCount;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/** 剧单分类新增/编辑请求体。 */
|
||||
@Data
|
||||
public class DramaPlaylistCategorySaveReqVO {
|
||||
|
||||
@NotBlank(message = "请填写剧单分类名称")
|
||||
private String name;
|
||||
|
||||
@Size(max = 255, message = "描述最多 255 个字符")
|
||||
private String description;
|
||||
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.dal.mapper.DramaEpisodeMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaReviewRecordMapper;
|
||||
import com.fruitshorts.content.vo.DramaSaveReqVO;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* 短剧保存时免费集数 / 解锁金币须同步分集价格。
|
||||
*/
|
||||
class DramaServiceTest {
|
||||
|
||||
private static final long DRAMA_ID = 1001L;
|
||||
private static final int UNLOCK_COIN = 60;
|
||||
|
||||
private DramaMapper dramaMapper;
|
||||
private DramaEpisodeMapper dramaEpisodeMapper;
|
||||
private DramaService dramaService;
|
||||
private List<DramaEpisode> episodes;
|
||||
|
||||
@BeforeAll
|
||||
static void initTableInfoCache() {
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, Drama.class);
|
||||
TableInfoHelper.initTableInfo(assistant, DramaEpisode.class);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
dramaMapper = mock(DramaMapper.class);
|
||||
dramaEpisodeMapper = mock(DramaEpisodeMapper.class);
|
||||
DramaReviewRecordMapper reviewRecordMapper = mock(DramaReviewRecordMapper.class);
|
||||
DramaCategoryService categoryService = mock(DramaCategoryService.class);
|
||||
EpisodePriceSync episodePriceSync = new EpisodePriceSync(dramaEpisodeMapper);
|
||||
dramaService = new DramaService(
|
||||
dramaMapper, dramaEpisodeMapper, reviewRecordMapper, categoryService, episodePriceSync);
|
||||
episodes = new ArrayList<>();
|
||||
given(dramaEpisodeMapper.selectList(any())).willAnswer(invocation -> List.copyOf(episodes));
|
||||
given(dramaEpisodeMapper.updateById(any(DramaEpisode.class))).willAnswer(invocation -> {
|
||||
DramaEpisode updated = invocation.getArgument(0);
|
||||
for (int i = 0; i < episodes.size(); i++) {
|
||||
if (episodes.get(i).getId().equals(updated.getId())) {
|
||||
episodes.set(i, updated);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_mark_episodes_4_and_5_free_when_free_episodes_increase_from_3_to_5() {
|
||||
givenExistingDrama(3, UNLOCK_COIN);
|
||||
seedEpisodesAlignedToFree(3, 6);
|
||||
|
||||
dramaService.update(DRAMA_ID, saveReq(5, UNLOCK_COIN));
|
||||
|
||||
Map<Integer, DramaEpisode> byEpNo = episodeMap();
|
||||
assertThat(byEpNo.get(4).getIsFree()).isEqualTo(1);
|
||||
assertThat(byEpNo.get(4).getUnlockCoin()).isZero();
|
||||
assertThat(byEpNo.get(5).getIsFree()).isEqualTo(1);
|
||||
assertThat(byEpNo.get(5).getUnlockCoin()).isZero();
|
||||
assertThat(byEpNo.get(6).getIsFree()).isZero();
|
||||
assertThat(byEpNo.get(6).getUnlockCoin()).isEqualTo(UNLOCK_COIN);
|
||||
verify(dramaEpisodeMapper, times(2)).updateById(any(DramaEpisode.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_mark_episodes_3_to_5_paid_when_free_episodes_decrease_from_5_to_2() {
|
||||
givenExistingDrama(5, UNLOCK_COIN);
|
||||
seedEpisodesAlignedToFree(5, 5);
|
||||
|
||||
dramaService.update(DRAMA_ID, saveReq(2, UNLOCK_COIN));
|
||||
|
||||
Map<Integer, DramaEpisode> byEpNo = episodeMap();
|
||||
assertThat(byEpNo.get(3).getIsFree()).isZero();
|
||||
assertThat(byEpNo.get(3).getUnlockCoin()).isEqualTo(UNLOCK_COIN);
|
||||
assertThat(byEpNo.get(4).getIsFree()).isZero();
|
||||
assertThat(byEpNo.get(4).getUnlockCoin()).isEqualTo(UNLOCK_COIN);
|
||||
assertThat(byEpNo.get(5).getIsFree()).isZero();
|
||||
assertThat(byEpNo.get(5).getUnlockCoin()).isEqualTo(UNLOCK_COIN);
|
||||
verify(dramaEpisodeMapper, times(3)).updateById(any(DramaEpisode.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_skip_episode_updates_when_free_episodes_unchanged() {
|
||||
givenExistingDrama(3, UNLOCK_COIN);
|
||||
seedEpisodesAlignedToFree(3, 4);
|
||||
AtomicInteger episodeUpdates = new AtomicInteger();
|
||||
given(dramaEpisodeMapper.updateById(any(DramaEpisode.class))).willAnswer(invocation -> {
|
||||
episodeUpdates.incrementAndGet();
|
||||
return 1;
|
||||
});
|
||||
|
||||
dramaService.update(DRAMA_ID, saveReq(3, UNLOCK_COIN));
|
||||
|
||||
assertThat(episodeUpdates.get()).isZero();
|
||||
verify(dramaEpisodeMapper, times(1)).selectList(any());
|
||||
verify(dramaEpisodeMapper, never()).updateById(any(DramaEpisode.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史漂移:短剧 freeEpisodes/unlockCoin 已是目标值,但分集 is_free 仍是旧规则。
|
||||
* 同值重存必须纠偏,不能因「规则字段未变」短路跳过同步。
|
||||
*/
|
||||
@Test
|
||||
void should_correct_drifted_episode_is_free_when_free_episodes_and_unlock_coin_unchanged() {
|
||||
givenExistingDrama(9, UNLOCK_COIN);
|
||||
// 规则已是免费 9 集,分集仍按旧规则只免费到第 4 集(5~9 仍收费)
|
||||
seedEpisodesAlignedToFree(4, 9);
|
||||
|
||||
dramaService.update(DRAMA_ID, saveReq(9, UNLOCK_COIN));
|
||||
|
||||
Map<Integer, DramaEpisode> byEpNo = episodeMap();
|
||||
for (int epNo = 1; epNo <= 9; epNo++) {
|
||||
assertThat(byEpNo.get(epNo).getIsFree()).isEqualTo(1);
|
||||
assertThat(byEpNo.get(epNo).getUnlockCoin()).isZero();
|
||||
}
|
||||
verify(dramaEpisodeMapper, times(5)).updateById(any(DramaEpisode.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_not_fail_when_drama_has_no_episodes() {
|
||||
givenExistingDrama(3, UNLOCK_COIN);
|
||||
episodes.clear();
|
||||
|
||||
assertThatCode(() -> dramaService.update(DRAMA_ID, saveReq(5, UNLOCK_COIN)))
|
||||
.doesNotThrowAnyException();
|
||||
verify(dramaEpisodeMapper, never()).updateById(any(DramaEpisode.class));
|
||||
}
|
||||
|
||||
private void givenExistingDrama(int freeEpisodes, int unlockCoin) {
|
||||
Drama drama = new Drama();
|
||||
drama.setId(DRAMA_ID);
|
||||
drama.setTitle("测试短剧");
|
||||
drama.setFreeEpisodes(freeEpisodes);
|
||||
drama.setUnlockCoin(unlockCoin);
|
||||
drama.setSubtitle("");
|
||||
drama.setGenre("");
|
||||
drama.setSynopsis("");
|
||||
drama.setCoverUrl("");
|
||||
drama.setTrailerUrl("");
|
||||
drama.setLanguage("id-ID");
|
||||
drama.setIsHot(0);
|
||||
drama.setSort(0);
|
||||
given(dramaMapper.selectById(DRAMA_ID)).willReturn(drama);
|
||||
given(dramaMapper.updateById(any(Drama.class))).willReturn(1);
|
||||
}
|
||||
|
||||
private void seedEpisodesAlignedToFree(int freeEpisodes, int total) {
|
||||
episodes.clear();
|
||||
for (int epNo = 1; epNo <= total; epNo++) {
|
||||
DramaEpisode episode = new DramaEpisode();
|
||||
episode.setId((long) epNo);
|
||||
episode.setDramaId(DRAMA_ID);
|
||||
episode.setEpNo(epNo);
|
||||
episode.setTitle("第" + epNo + "集");
|
||||
boolean free = epNo <= freeEpisodes;
|
||||
episode.setIsFree(free ? 1 : 0);
|
||||
episode.setUnlockCoin(free ? 0 : UNLOCK_COIN);
|
||||
episodes.add(episode);
|
||||
}
|
||||
}
|
||||
|
||||
private DramaSaveReqVO saveReq(int freeEpisodes, int unlockCoin) {
|
||||
DramaSaveReqVO req = new DramaSaveReqVO();
|
||||
req.setTitle("测试短剧");
|
||||
req.setFreeEpisodes(freeEpisodes);
|
||||
req.setUnlockCoin(unlockCoin);
|
||||
return req;
|
||||
}
|
||||
|
||||
private Map<Integer, DramaEpisode> episodeMap() {
|
||||
ArgumentCaptor<DramaEpisode> captor = ArgumentCaptor.forClass(DramaEpisode.class);
|
||||
verify(dramaEpisodeMapper, org.mockito.Mockito.atLeastOnce()).updateById(captor.capture());
|
||||
Map<Integer, DramaEpisode> updated = captor.getAllValues().stream()
|
||||
.collect(Collectors.toMap(DramaEpisode::getEpNo, Function.identity(), (a, b) -> b));
|
||||
for (DramaEpisode episode : episodes) {
|
||||
updated.putIfAbsent(episode.getEpNo(), episode);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.content.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.dal.mapper.DramaEpisodeMapper;
|
||||
import com.fruitshorts.content.vo.EpisodeRespVO;
|
||||
import com.fruitshorts.content.vo.EpisodeSaveReqVO;
|
||||
import com.fruitshorts.media.service.EpisodeTranscodeBindingService;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* 剧集后台分页:默认每页 100、上限 200、越界空列表、stable 排序走 DB selectPage。
|
||||
*/
|
||||
class EpisodeServicePageTest {
|
||||
|
||||
private static final long DRAMA_ID = 2001L;
|
||||
|
||||
private DramaEpisodeMapper dramaEpisodeMapper;
|
||||
private DramaService dramaService;
|
||||
private EpisodeTranscodeBindingService transcodeBindingService;
|
||||
private EpisodeService episodeService;
|
||||
|
||||
@BeforeAll
|
||||
static void initTableInfoCache() {
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, DramaEpisode.class);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
dramaEpisodeMapper = mock(DramaEpisodeMapper.class);
|
||||
dramaService = mock(DramaService.class);
|
||||
transcodeBindingService = mock(EpisodeTranscodeBindingService.class);
|
||||
episodeService = new EpisodeService(
|
||||
dramaEpisodeMapper, dramaService, transcodeBindingService);
|
||||
given(dramaService.getExisting(DRAMA_ID)).willReturn(new Drama());
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_bind_media_asset_and_transcode_task_when_episode_video_is_saved() {
|
||||
Drama drama = new Drama();
|
||||
drama.setId(DRAMA_ID);
|
||||
given(dramaService.getExisting(DRAMA_ID)).willReturn(drama);
|
||||
doAnswer(invocation -> {
|
||||
DramaEpisode episode = invocation.getArgument(0);
|
||||
episode.setId(31L);
|
||||
return 1;
|
||||
}).when(dramaEpisodeMapper).insert(any(DramaEpisode.class));
|
||||
given(transcodeBindingService.bind(
|
||||
31L, DRAMA_ID, "/files/episode/202610/video.mp4")).willReturn(88L);
|
||||
EpisodeSaveReqVO req = new EpisodeSaveReqVO();
|
||||
req.setDramaId(DRAMA_ID);
|
||||
req.setNumber(2);
|
||||
req.setVideoUrl("/files/episode/202610/video.mp4");
|
||||
|
||||
Long id = episodeService.create(req);
|
||||
|
||||
assertThat(id).isEqualTo(31L);
|
||||
verify(transcodeBindingService).bind(
|
||||
31L, DRAMA_ID, "/files/episode/202610/video.mp4");
|
||||
ArgumentCaptor<DramaEpisode> updated = ArgumentCaptor.forClass(DramaEpisode.class);
|
||||
verify(dramaEpisodeMapper).updateById(updated.capture());
|
||||
assertThat(updated.getValue().getVideoAssetId()).isEqualTo(88L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_write_hls_url_and_success_status_when_transcode_finishes() {
|
||||
episodeService.markEpisodeReady(31L, "/files/transcoded/88/master.m3u8", 4);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<LambdaUpdateWrapper<DramaEpisode>> captor =
|
||||
ArgumentCaptor.forClass(LambdaUpdateWrapper.class);
|
||||
verify(dramaEpisodeMapper).update(any(), captor.capture());
|
||||
assertThat(captor.getValue().getSqlSet()).contains("hls_url");
|
||||
assertThat(captor.getValue().getSqlSet()).contains("transcode_status");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_use_default_page_size_100_when_page_size_omitted() {
|
||||
stubSelectPage(0L, List.of());
|
||||
|
||||
episodeService.pageByDrama(DRAMA_ID, null, null, null);
|
||||
|
||||
Page<?> page = capturePageArg();
|
||||
assertThat(page.getCurrent()).isEqualTo(1L);
|
||||
assertThat(page.getSize()).isEqualTo(100L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_cap_page_size_at_200() {
|
||||
stubSelectPage(0L, List.of());
|
||||
|
||||
episodeService.pageByDrama(DRAMA_ID, null, 1, 500);
|
||||
|
||||
Page<?> page = capturePageArg();
|
||||
assertThat(page.getSize()).isEqualTo(200L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_second_page_records_without_overlap_with_first() {
|
||||
DramaEpisode first = episode(1L, 1, 1);
|
||||
DramaEpisode second = episode(2L, 2, 2);
|
||||
DramaEpisode third = episode(3L, 3, 3);
|
||||
DramaEpisode fourth = episode(4L, 4, 4);
|
||||
given(dramaEpisodeMapper.selectPage(any(Page.class), any())).willAnswer(invocation -> {
|
||||
Page<DramaEpisode> page = invocation.getArgument(0);
|
||||
Page<DramaEpisode> result = new Page<>(page.getCurrent(), page.getSize(), 4L);
|
||||
if (page.getCurrent() == 1L) {
|
||||
result.setRecords(List.of(first, second));
|
||||
} else if (page.getCurrent() == 2L) {
|
||||
result.setRecords(List.of(third, fourth));
|
||||
} else {
|
||||
result.setRecords(List.of());
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
PageResult<EpisodeRespVO> page1 = episodeService.pageByDrama(DRAMA_ID, null, 1, 2);
|
||||
PageResult<EpisodeRespVO> page2 = episodeService.pageByDrama(DRAMA_ID, null, 2, 2);
|
||||
|
||||
assertThat(page1.getTotal()).isEqualTo(4L);
|
||||
assertThat(page2.getTotal()).isEqualTo(4L);
|
||||
assertThat(page1.getList()).extracting(EpisodeRespVO::getId).containsExactly(1L, 2L);
|
||||
assertThat(page2.getList()).extracting(EpisodeRespVO::getId).containsExactly(3L, 4L);
|
||||
assertThat(page1.getList()).extracting(EpisodeRespVO::getId)
|
||||
.doesNotContainAnyElementsOf(page2.getList().stream().map(EpisodeRespVO::getId).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_empty_list_with_correct_total_when_page_out_of_range() {
|
||||
given(dramaEpisodeMapper.selectPage(any(Page.class), any())).willAnswer(invocation -> {
|
||||
Page<DramaEpisode> page = invocation.getArgument(0);
|
||||
Page<DramaEpisode> result = new Page<>(page.getCurrent(), page.getSize(), 5L);
|
||||
result.setRecords(List.of());
|
||||
return result;
|
||||
});
|
||||
|
||||
PageResult<EpisodeRespVO> page = episodeService.pageByDrama(DRAMA_ID, "published", 99, 100);
|
||||
|
||||
assertThat(page.getTotal()).isEqualTo(5L);
|
||||
assertThat(page.getList()).isEmpty();
|
||||
verify(dramaEpisodeMapper).selectPage(any(Page.class), any());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void stubSelectPage(long total, List<DramaEpisode> records) {
|
||||
given(dramaEpisodeMapper.selectPage(any(Page.class), any())).willAnswer(invocation -> {
|
||||
Page<DramaEpisode> page = invocation.getArgument(0);
|
||||
Page<DramaEpisode> result = new Page<>(page.getCurrent(), page.getSize(), total);
|
||||
result.setRecords(records);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Page<?> capturePageArg() {
|
||||
ArgumentCaptor<Page> pageCaptor = ArgumentCaptor.forClass(Page.class);
|
||||
verify(dramaEpisodeMapper).selectPage(pageCaptor.capture(), any());
|
||||
return pageCaptor.getValue();
|
||||
}
|
||||
|
||||
private DramaEpisode episode(Long id, int sort, int epNo) {
|
||||
DramaEpisode episode = new DramaEpisode();
|
||||
episode.setId(id);
|
||||
episode.setDramaId(DRAMA_ID);
|
||||
episode.setSort(sort);
|
||||
episode.setEpNo(epNo);
|
||||
episode.setTitle("ep-" + epNo);
|
||||
episode.setStatus("published");
|
||||
episode.setIsFree(1);
|
||||
episode.setUnlockCoin(0);
|
||||
episode.setDurationSec(60);
|
||||
episode.setPlayCount(0L);
|
||||
episode.setLikeCount(0L);
|
||||
return episode;
|
||||
}
|
||||
}
|
||||
@@ -21,5 +21,14 @@
|
||||
<groupId>com.fruitshorts</groupId>
|
||||
<artifactId>fruitshorts-framework</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fruitshorts</groupId>
|
||||
<artifactId>fruitshorts-module-system</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.media.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台可配置的转码档位与雪碧图参数。
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class MediaTranscodeProfile {
|
||||
|
||||
public static final int DEFAULT_SEGMENT_SECONDS = 6;
|
||||
public static final int DEFAULT_SPRITE_INTERVAL = 1;
|
||||
public static final int DEFAULT_SPRITE_COLUMNS = 10;
|
||||
public static final int DEFAULT_THUMB_WIDTH = 160;
|
||||
|
||||
private boolean enabled = true;
|
||||
private int segmentSeconds = DEFAULT_SEGMENT_SECONDS;
|
||||
private List<Rung> ladder = defaultLadder();
|
||||
private Sprite sprite = new Sprite();
|
||||
|
||||
/** 默认四档与第一阶段 yml 保持一致。 */
|
||||
public static List<Rung> defaultLadder() {
|
||||
List<Rung> ladder = new ArrayList<>(4);
|
||||
ladder.add(new Rung("360p", 640, 360, 400, 64, true));
|
||||
ladder.add(new Rung("480p", 854, 480, 800, 64, true));
|
||||
ladder.add(new Rung("720p", 1280, 720, 1600, 96, true));
|
||||
ladder.add(new Rung("1080p", 1920, 1080, 3200, 128, true));
|
||||
return ladder;
|
||||
}
|
||||
|
||||
/** 一档清晰度。 */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class Rung {
|
||||
private String quality;
|
||||
private int width;
|
||||
private int height;
|
||||
private int videoBitrateKbps;
|
||||
private int audioBitrateKbps;
|
||||
private boolean enabled = true;
|
||||
}
|
||||
|
||||
/** 雪碧图采样参数。 */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public static class Sprite {
|
||||
private boolean enabled = true;
|
||||
private int intervalSeconds = DEFAULT_SPRITE_INTERVAL;
|
||||
private int columns = DEFAULT_SPRITE_COLUMNS;
|
||||
private int thumbWidth = DEFAULT_THUMB_WIDTH;
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.media.config;
|
||||
|
||||
import com.fruitshorts.common.exception.ErrorCode;
|
||||
import com.fruitshorts.common.exception.ServiceException;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 转码配置合法性校验。
|
||||
*/
|
||||
public final class MediaTranscodeProfileValidator {
|
||||
|
||||
private static final int MIN_SEGMENT_SECONDS = 2;
|
||||
private static final int MAX_SEGMENT_SECONDS = 10;
|
||||
private static final int MIN_SPRITE_INTERVAL = 1;
|
||||
private static final int MAX_SPRITE_INTERVAL = 10;
|
||||
private static final int MIN_COLUMNS = 5;
|
||||
private static final int MAX_COLUMNS = 20;
|
||||
private static final int MIN_THUMB_WIDTH = 120;
|
||||
private static final int MAX_THUMB_WIDTH = 240;
|
||||
private static final int MAX_QUALITY_LENGTH = 16;
|
||||
private static final int EVEN_DIVISOR = 2;
|
||||
|
||||
private MediaTranscodeProfileValidator() {
|
||||
}
|
||||
|
||||
/** 非法配置转成统一 400;调用方必须在持久化前执行。 */
|
||||
public static void validate(MediaTranscodeProfile profile) {
|
||||
if (profile == null) {
|
||||
throw invalid("转码配置不能为空");
|
||||
}
|
||||
validateSegment(profile.getSegmentSeconds());
|
||||
validateLadder(profile.getLadder());
|
||||
validateSprite(profile.getSprite());
|
||||
}
|
||||
|
||||
private static void validateSegment(int value) {
|
||||
if (value < MIN_SEGMENT_SECONDS || value > MAX_SEGMENT_SECONDS) {
|
||||
throw invalid("segmentSeconds 必须在 2-10 之间");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateLadder(Iterable<MediaTranscodeProfile.Rung> ladder) {
|
||||
if (ladder == null) {
|
||||
throw invalid("ladder 不能为空");
|
||||
}
|
||||
Set<String> qualities = new HashSet<>();
|
||||
boolean hasEnabled = false;
|
||||
for (MediaTranscodeProfile.Rung rung : ladder) {
|
||||
validateRung(rung, qualities);
|
||||
hasEnabled = hasEnabled || rung.isEnabled();
|
||||
}
|
||||
if (!hasEnabled) {
|
||||
throw invalid("至少需要启用一档清晰度");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateRung(MediaTranscodeProfile.Rung rung,
|
||||
Set<String> qualities) {
|
||||
if (rung == null || rung.getQuality() == null || rung.getQuality().isBlank()) {
|
||||
throw invalid("quality 不能为空");
|
||||
}
|
||||
String quality = rung.getQuality().trim();
|
||||
if (quality.length() > MAX_QUALITY_LENGTH || !qualities.add(quality)) {
|
||||
throw invalid("quality 必须唯一且不超过 16 个字符");
|
||||
}
|
||||
if (rung.getWidth() <= 0 || rung.getWidth() % EVEN_DIVISOR != 0
|
||||
|| rung.getHeight() <= 0 || rung.getHeight() % EVEN_DIVISOR != 0) {
|
||||
throw invalid("宽高必须为正偶数");
|
||||
}
|
||||
if (rung.getVideoBitrateKbps() <= 0 || rung.getAudioBitrateKbps() <= 0) {
|
||||
throw invalid("音视频码率必须大于 0");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateSprite(MediaTranscodeProfile.Sprite sprite) {
|
||||
if (sprite == null) {
|
||||
throw invalid("sprite 配置不能为空");
|
||||
}
|
||||
if (sprite.getIntervalSeconds() < MIN_SPRITE_INTERVAL
|
||||
|| sprite.getIntervalSeconds() > MAX_SPRITE_INTERVAL) {
|
||||
throw invalid("intervalSeconds 必须在 1-10 之间");
|
||||
}
|
||||
if (sprite.getColumns() < MIN_COLUMNS || sprite.getColumns() > MAX_COLUMNS) {
|
||||
throw invalid("columns 必须在 5-20 之间");
|
||||
}
|
||||
if (sprite.getThumbWidth() < MIN_THUMB_WIDTH
|
||||
|| sprite.getThumbWidth() > MAX_THUMB_WIDTH) {
|
||||
throw invalid("thumbWidth 必须在 120-240 之间");
|
||||
}
|
||||
}
|
||||
|
||||
private static ServiceException invalid(String message) {
|
||||
return new ServiceException(ErrorCode.BAD_REQUEST, message);
|
||||
}
|
||||
}
|
||||
Loaded 100 of 175 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user