2021 lines
79 KiB
Markdown
2021 lines
79 KiB
Markdown
# 景区素材共享优化方案
|
||||
|
|
|
|||
|
|
> 版本: v2.0
|
|||
|
|
> 日期: 2024-12-02
|
|||
|
|
> 作者: dzc
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 一、问题背景
|
|||
|
|
|
|||
|
|
### 1.1 当前架构
|
|||
|
|
|
|||
|
|
在租户层级体系中,同一个物理景区可能创建多个子租户(区分不同入口、不同业务线),导游也是独立的子租户:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
父租户A(景区运营商 - 如:上海迪士尼度假区)
|
|||
|
|
├── 子租户B(景区-东门入口) ← tourismType = 1
|
|||
|
|
├── 子租户C(景区-西门入口) ← tourismType = 1 ← 同一物理景区!
|
|||
|
|
├── 子租户D(导游张三) ← tourismType = 2
|
|||
|
|
└── 子租户E(导游李四) ← tourismType = 2
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**关键认知**:子租户B和子租户C虽然是两个独立租户,但属于**同一个物理景区**,应该共享同一套景区素材。
|
|||
|
|
|
|||
|
|
### 1.2 现存问题
|
|||
|
|
|
|||
|
|
| 问题 | 描述 | 影响 |
|
|||
|
|
|------|------|------|
|
|||
|
|
| **重复上传** | B、C、D、E四个子租户各自上传景区素材 | 操作繁琐,工作量×4 |
|
|||
|
|
| **数据冗余** | 同一套素材(7张图片)存储4份 | 浪费28张图片的空间 |
|
|||
|
|
| **维护困难** | 更新素材需要在4个地方逐一操作 | 容易遗漏,数据不一致 |
|
|||
|
|
| **逻辑混乱** | 素材归属于"扫码点"而非"物理景区" | 概念不清晰 |
|
|||
|
|
|
|||
|
|
### 1.3 问题本质
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
当前模型(错误):
|
|||
|
|
tourisms_files.tourism_id → tourisms.id (子租户级别)
|
|||
|
|
|
|||
|
|
期望模型(正确):
|
|||
|
|
tourisms_files → 父租户级别的素材库(所有子租户共享)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 二、解决方案
|
|||
|
|
|
|||
|
|
### 2.1 核心思路
|
|||
|
|
|
|||
|
|
**将素材从"子租户级别"提升到"父租户级别"**,创建一个归属于父租户的**景区素材库**。
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
优化后架构:
|
|||
|
|
┌─────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 父租户A(景区运营商) │
|
|||
|
|
│ │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ 景区素材库 (scenic_material_library) │ │
|
|||
|
|
│ │ ┌───────────────────────────────────────────────┐ │ │
|
|||
|
|
│ │ │ 素材1 素材2 素材3 素材4 素材5 素材6 素材7 │ │ │
|
|||
|
|
│ │ └───────────────────────────────────────────────┘ │ │
|
|||
|
|
│ │ 仅存储1份 │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ ▲ ▲ ▲ ▲ │
|
|||
|
|
│ │共享 │共享 │共享 │共享 │
|
|||
|
|
│ ┌──────┴───┐ ┌──────┴───┐ ┌──────┴───┐ ┌──────┴───┐ │
|
|||
|
|
│ │ 子租户B │ │ 子租户C │ │ 子租户D │ │ 子租户E │ │
|
|||
|
|
│ │ (东门) │ │ (西门) │ │ (导游) │ │ (导游) │ │
|
|||
|
|
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
|
|||
|
|
└─────────────────────────────────────────────────────────────┘
|
|||
|
|
|
|||
|
|
结果:4个子租户共享1套素材
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2.2 方案对比
|
|||
|
|
|
|||
|
|
| 方案 | 描述 | 优点 | 缺点 | 推荐度 |
|
|||
|
|
|------|------|------|------|--------|
|
|||
|
|
| **方案A: 新建素材库表** | 创建独立的素材库表,归属父租户 | 概念清晰,彻底解决 | 需要数据迁移 | ★★★★★ |
|
|||
|
|
| **方案B: 复用现有表+父租户字段** | tourisms_files加parent_tenant_id | 改动小 | 概念不够清晰 | ★★★★ |
|
|||
|
|
| **方案C: 素材引用机制** | 子租户引用父租户素材 | 兼容现有数据 | 查询复杂 | ★★★ |
|
|||
|
|
|
|||
|
|
**推荐方案A**:新建`scenic_material_library`素材库表,归属于父租户。
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 三、详细设计
|
|||
|
|
|
|||
|
|
### 3.1 数据模型设计
|
|||
|
|
|
|||
|
|
#### 3.1.1 新增表:景区素材库 (scenic_material_library)
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
CREATE TABLE scenic_material_library (
|
|||
|
|
id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
|
|||
|
|
library_name VARCHAR(100) NOT NULL COMMENT '素材库名称',
|
|||
|
|
parent_tenant_id VARCHAR(32) NOT NULL COMMENT '归属父租户ID',
|
|||
|
|
description VARCHAR(500) COMMENT '素材库描述',
|
|||
|
|
cover_url VARCHAR(500) COMMENT '封面图URL',
|
|||
|
|
material_count INT DEFAULT 0 COMMENT '素材数量',
|
|||
|
|
status TINYINT DEFAULT 1 COMMENT '状态:0-禁用 1-启用',
|
|||
|
|
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|||
|
|
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|||
|
|
|
|||
|
|
KEY idx_parent_tenant (parent_tenant_id),
|
|||
|
|
KEY idx_status (status)
|
|||
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='景区素材库';
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3.1.2 新增表:素材库素材 (scenic_material)
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
CREATE TABLE scenic_material (
|
|||
|
|
id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
|
|||
|
|
library_id BIGINT NOT NULL COMMENT '所属素材库ID',
|
|||
|
|
material_name VARCHAR(100) COMMENT '素材名称',
|
|||
|
|
material_url VARCHAR(500) NOT NULL COMMENT '素材URL',
|
|||
|
|
material_type TINYINT DEFAULT 1 COMMENT '素材类型:1-图片 2-视频',
|
|||
|
|
sort_order INT DEFAULT 0 COMMENT '排序序号',
|
|||
|
|
description VARCHAR(500) COMMENT '素材描述',
|
|||
|
|
file_size BIGINT COMMENT '文件大小(字节)',
|
|||
|
|
width INT COMMENT '宽度(像素)',
|
|||
|
|
height INT COMMENT '高度(像素)',
|
|||
|
|
duration INT COMMENT '视频时长(秒)',
|
|||
|
|
status TINYINT DEFAULT 1 COMMENT '状态:0-禁用 1-启用',
|
|||
|
|
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|||
|
|
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|||
|
|
|
|||
|
|
KEY idx_library_id (library_id),
|
|||
|
|
KEY idx_material_type (material_type),
|
|||
|
|
KEY idx_status (status)
|
|||
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='景区素材';
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3.1.3 修改表:tourisms 添加素材库关联
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
ALTER TABLE tourisms
|
|||
|
|
ADD COLUMN material_library_id BIGINT COMMENT '关联素材库ID';
|
|||
|
|
|
|||
|
|
CREATE INDEX idx_material_library ON tourisms(material_library_id);
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3.1.4 表关系图
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
scenic_material_library (素材库)
|
|||
|
|
├─ id = 1
|
|||
|
|
├─ library_name = "迪士尼景区素材"
|
|||
|
|
├─ parent_tenant_id = "tenant_A" ← 归属父租户
|
|||
|
|
│
|
|||
|
|
└─► scenic_material (素材)
|
|||
|
|
├─ id=1, library_id=1, url=...
|
|||
|
|
├─ id=2, library_id=1, url=...
|
|||
|
|
└─ ... (共7条)
|
|||
|
|
▲
|
|||
|
|
│ 引用 (material_library_id = 1)
|
|||
|
|
┌─────────────────────┼─────────────────────┐
|
|||
|
|
│ │ │
|
|||
|
|
tourisms (id=100) tourisms (id=101) tourisms (id=102)
|
|||
|
|
子租户B-东门 子租户C-西门 子租户D-导游
|
|||
|
|
material_library_id=1 material_library_id=1 material_library_id=1
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 3.2 业务流程设计
|
|||
|
|
|
|||
|
|
#### 3.2.1 素材库管理流程
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
┌─────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 父租户管理后台 │
|
|||
|
|
├─────────────────────────────────────────────────────────────┤
|
|||
|
|
│ │
|
|||
|
|
│ 【素材库管理】 │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ + 新建素材库 │ │
|
|||
|
|
│ ├─────────────────────────────────────────────────────┤ │
|
|||
|
|
│ │ ┌─────────────────────────────────────────────────┐ │ │
|
|||
|
|
│ │ │ 📁 迪士尼乐园素材库 │ │ │
|
|||
|
|
│ │ │ 素材数量: 12 | 状态: 启用 | [管理] [删除] │ │ │
|
|||
|
|
│ │ └─────────────────────────────────────────────────┘ │ │
|
|||
|
|
│ │ ┌─────────────────────────────────────────────────┐ │ │
|
|||
|
|
│ │ │ 📁 星愿公园素材库 │ │ │
|
|||
|
|
│ │ │ 素材数量: 8 | 状态: 启用 | [管理] [删除] │ │ │
|
|||
|
|
│ │ └─────────────────────────────────────────────────┘ │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
│ 提示:素材库创建后,可被所有子租户(景区入口、导游)共享使用 │
|
|||
|
|
└─────────────────────────────────────────────────────────────┘
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3.2.2 子租户创建/编辑时选择素材库
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
┌─────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 创建/编辑 景区入口 │
|
|||
|
|
├─────────────────────────────────────────────────────────────┤
|
|||
|
|
│ │
|
|||
|
|
│ 景区名称: [迪士尼东门入口 ] │
|
|||
|
|
│ 景区地址: [上海市浦东新区... ] │
|
|||
|
|
│ │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ 选择素材库 * │ │
|
|||
|
|
│ │ ┌─────────────────────────────────────────────────┐ │ │
|
|||
|
|
│ │ │ ● 迪士尼乐园素材库 (12张) ← 选中 │ │ │
|
|||
|
|
│ │ │ ○ 星愿公园素材库 (8张) │ │ │
|
|||
|
|
│ │ └─────────────────────────────────────────────────┘ │ │
|
|||
|
|
│ │ [预览素材] │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
│ [取消] [保存] │
|
|||
|
|
└─────────────────────────────────────────────────────────────┘
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3.2.3 二维码创建时自动获取素材
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
┌─────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 创建二维码 │
|
|||
|
|
├─────────────────────────────────────────────────────────────┤
|
|||
|
|
│ │
|
|||
|
|
│ 所属景区/导游: [迪士尼东门入口 ▼] │
|
|||
|
|
│ 二维码名称: [检票口1号 ] │
|
|||
|
|
│ │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ 景区素材 (来源: 迪士尼乐园素材库) │ │
|
|||
|
|
│ │ │ │
|
|||
|
|
│ │ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ... │ │
|
|||
|
|
│ │ │ ☑ │ │ ☑ │ │ ☑ │ │ ☐ │ │ ☐ │ │ │
|
|||
|
|
│ │ │城堡 │ │烟花 │ │巡游 │ │商店 │ │餐厅 │ │ │
|
|||
|
|
│ │ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘ │ │
|
|||
|
|
│ │ │ │
|
|||
|
|
│ │ 已选择 3/12 张 [全选] [取消全选] │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
│ [取消] [创建] │
|
|||
|
|
└─────────────────────────────────────────────────────────────┘
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 3.3 API接口设计
|
|||
|
|
|
|||
|
|
#### 3.3.1 素材库管理接口
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
# 创建素材库
|
|||
|
|
POST /scenic/material-library
|
|||
|
|
Request:
|
|||
|
|
{
|
|||
|
|
"libraryName": "迪士尼乐园素材库",
|
|||
|
|
"description": "上海迪士尼乐园官方素材",
|
|||
|
|
"parentTenantId": "tenant_A"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 获取父租户下的素材库列表
|
|||
|
|
GET /scenic/material-library/list?parentTenantId={parentTenantId}
|
|||
|
|
Response:
|
|||
|
|
{
|
|||
|
|
"code": 0,
|
|||
|
|
"data": [
|
|||
|
|
{
|
|||
|
|
"id": 1,
|
|||
|
|
"libraryName": "迪士尼乐园素材库",
|
|||
|
|
"materialCount": 12,
|
|||
|
|
"coverUrl": "https://...",
|
|||
|
|
"status": 1
|
|||
|
|
}
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 获取素材库详情(含所有素材)
|
|||
|
|
GET /scenic/material-library/{libraryId}
|
|||
|
|
Response:
|
|||
|
|
{
|
|||
|
|
"code": 0,
|
|||
|
|
"data": {
|
|||
|
|
"id": 1,
|
|||
|
|
"libraryName": "迪士尼乐园素材库",
|
|||
|
|
"materials": [
|
|||
|
|
{
|
|||
|
|
"id": 1,
|
|||
|
|
"materialName": "城堡",
|
|||
|
|
"materialUrl": "https://...",
|
|||
|
|
"materialType": 1
|
|||
|
|
},
|
|||
|
|
// ...
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3.3.2 素材管理接口
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
# 上传素材到素材库
|
|||
|
|
POST /scenic/material
|
|||
|
|
Request:
|
|||
|
|
{
|
|||
|
|
"libraryId": 1,
|
|||
|
|
"materialName": "城堡夜景",
|
|||
|
|
"materialUrl": "https://...",
|
|||
|
|
"materialType": 1
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 批量上传素材
|
|||
|
|
POST /scenic/material/batch
|
|||
|
|
Request:
|
|||
|
|
{
|
|||
|
|
"libraryId": 1,
|
|||
|
|
"materials": [
|
|||
|
|
{"materialName": "素材1", "materialUrl": "..."},
|
|||
|
|
{"materialName": "素材2", "materialUrl": "..."}
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 删除素材
|
|||
|
|
DELETE /scenic/material/{materialId}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3.3.3 获取可用素材接口(核心)
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
# 根据tourismId获取可用素材(自动从关联的素材库获取)
|
|||
|
|
GET /scenic/material/available/{tourismId}
|
|||
|
|
Response:
|
|||
|
|
{
|
|||
|
|
"code": 0,
|
|||
|
|
"data": {
|
|||
|
|
"libraryId": 1,
|
|||
|
|
"libraryName": "迪士尼乐园素材库",
|
|||
|
|
"materials": [
|
|||
|
|
{
|
|||
|
|
"id": 1,
|
|||
|
|
"materialName": "城堡",
|
|||
|
|
"materialUrl": "https://cdn.example.com/scenic/castle.jpg",
|
|||
|
|
"materialType": 1
|
|||
|
|
},
|
|||
|
|
// ...
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 3.4 核心代码实现
|
|||
|
|
|
|||
|
|
#### 3.4.1 获取可用素材Service
|
|||
|
|
|
|||
|
|
```java
|
|||
|
|
@Service
|
|||
|
|
@RequiredArgsConstructor
|
|||
|
|
public class ScenicMaterialServiceImpl implements IScenicMaterialService {
|
|||
|
|
|
|||
|
|
private final TourismMapper tourismMapper;
|
|||
|
|
private final ScenicMaterialLibraryMapper libraryMapper;
|
|||
|
|
private final ScenicMaterialMapper materialMapper;
|
|||
|
|
private final FileCenterService fileCenterService;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取tourism可用的素材列表
|
|||
|
|
* 逻辑:tourism → material_library_id → scenic_material
|
|||
|
|
*/
|
|||
|
|
@Override
|
|||
|
|
public MaterialLibraryVO getAvailableMaterials(Long tourismId) {
|
|||
|
|
// 1. 查询tourism
|
|||
|
|
Tourism tourism = tourismMapper.selectById(tourismId);
|
|||
|
|
if (tourism == null) {
|
|||
|
|
throw new RuntimeException("景区/导游不存在");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 2. 获取关联的素材库ID
|
|||
|
|
Long libraryId = tourism.getMaterialLibraryId();
|
|||
|
|
if (libraryId == null) {
|
|||
|
|
log.warn("tourism未关联素材库: tourismId={}", tourismId);
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 3. 查询素材库
|
|||
|
|
ScenicMaterialLibrary library = libraryMapper.selectById(libraryId);
|
|||
|
|
if (library == null || library.getStatus() != 1) {
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 4. 查询素材列表
|
|||
|
|
List<ScenicMaterial> materials = materialMapper.selectByLibraryId(libraryId);
|
|||
|
|
|
|||
|
|
// 5. 转换URL
|
|||
|
|
for (ScenicMaterial m : materials) {
|
|||
|
|
m.setMaterialUrl(fileCenterService.getViewUrlByPath(m.getMaterialUrl()));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 6. 组装返回
|
|||
|
|
MaterialLibraryVO vo = new MaterialLibraryVO();
|
|||
|
|
vo.setLibraryId(library.getId());
|
|||
|
|
vo.setLibraryName(library.getLibraryName());
|
|||
|
|
vo.setMaterials(materials);
|
|||
|
|
return vo;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3.4.2 二维码创建时获取素材
|
|||
|
|
|
|||
|
|
```java
|
|||
|
|
// QrCodeController 修改
|
|||
|
|
@PostMapping("/withPlan")
|
|||
|
|
public Result<QrCode> saveOrUpdateQrcodeWithPlan(@RequestBody QrcodeWithPlanDTO body) {
|
|||
|
|
QrCode qrCode = body.getQrCode();
|
|||
|
|
|
|||
|
|
// 获取tourism关联的素材库中的素材
|
|||
|
|
MaterialLibraryVO libraryVO = scenicMaterialService.getAvailableMaterials(qrCode.getTourismId());
|
|||
|
|
|
|||
|
|
if (libraryVO == null) {
|
|||
|
|
return Result.failed("请先为该景区/导游关联素材库");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 前端传入选中的素材ID列表
|
|||
|
|
List<Long> selectedMaterialIds = body.getMaterialIds();
|
|||
|
|
|
|||
|
|
// 验证选中的素材都属于该素材库
|
|||
|
|
Set<Long> validIds = libraryVO.getMaterials().stream()
|
|||
|
|
.map(ScenicMaterial::getId)
|
|||
|
|
.collect(Collectors.toSet());
|
|||
|
|
|
|||
|
|
for (Long id : selectedMaterialIds) {
|
|||
|
|
if (!validIds.contains(id)) {
|
|||
|
|
return Result.failed("选择了无效的素材");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ... 继续创建二维码逻辑
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 四、数据库变更
|
|||
|
|
|
|||
|
|
### 4.1 完整DDL脚本
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- ============================================
|
|||
|
|
-- 景区素材共享优化 - 数据库迁移脚本 v2.0
|
|||
|
|
-- 创建日期: 2024-12-02
|
|||
|
|
-- ============================================
|
|||
|
|
|
|||
|
|
-- 1. 创建景区素材库表
|
|||
|
|
CREATE TABLE IF NOT EXISTS scenic_material_library (
|
|||
|
|
id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
|
|||
|
|
library_name VARCHAR(100) NOT NULL COMMENT '素材库名称',
|
|||
|
|
parent_tenant_id VARCHAR(32) NOT NULL COMMENT '归属父租户ID',
|
|||
|
|
description VARCHAR(500) COMMENT '素材库描述',
|
|||
|
|
cover_url VARCHAR(500) COMMENT '封面图URL',
|
|||
|
|
material_count INT DEFAULT 0 COMMENT '素材数量',
|
|||
|
|
status TINYINT DEFAULT 1 COMMENT '状态:0-禁用 1-启用',
|
|||
|
|
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|||
|
|
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|||
|
|
|
|||
|
|
KEY idx_parent_tenant (parent_tenant_id),
|
|||
|
|
KEY idx_status (status)
|
|||
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='景区素材库';
|
|||
|
|
|
|||
|
|
-- 2. 创建素材表
|
|||
|
|
CREATE TABLE IF NOT EXISTS scenic_material (
|
|||
|
|
id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
|
|||
|
|
library_id BIGINT NOT NULL COMMENT '所属素材库ID',
|
|||
|
|
material_name VARCHAR(100) COMMENT '素材名称',
|
|||
|
|
material_url VARCHAR(500) NOT NULL COMMENT '素材URL',
|
|||
|
|
material_type TINYINT DEFAULT 1 COMMENT '素材类型:1-图片 2-视频',
|
|||
|
|
sort_order INT DEFAULT 0 COMMENT '排序序号',
|
|||
|
|
description VARCHAR(500) COMMENT '素材描述',
|
|||
|
|
file_size BIGINT COMMENT '文件大小(字节)',
|
|||
|
|
width INT COMMENT '宽度(像素)',
|
|||
|
|
height INT COMMENT '高度(像素)',
|
|||
|
|
duration INT COMMENT '视频时长(秒)',
|
|||
|
|
status TINYINT DEFAULT 1 COMMENT '状态:0-禁用 1-启用',
|
|||
|
|
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|||
|
|
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|||
|
|
|
|||
|
|
KEY idx_library_id (library_id),
|
|||
|
|
KEY idx_material_type (material_type),
|
|||
|
|
KEY idx_sort_order (sort_order),
|
|||
|
|
KEY idx_status (status)
|
|||
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='景区素材';
|
|||
|
|
|
|||
|
|
-- 3. tourisms表添加素材库关联字段
|
|||
|
|
ALTER TABLE tourisms
|
|||
|
|
ADD COLUMN material_library_id BIGINT COMMENT '关联素材库ID';
|
|||
|
|
|
|||
|
|
CREATE INDEX idx_material_library ON tourisms(material_library_id);
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 4.2 数据迁移脚本
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- ============================================
|
|||
|
|
-- 数据迁移:将现有tourisms_files迁移到新的素材库结构
|
|||
|
|
-- ============================================
|
|||
|
|
|
|||
|
|
-- Step 1: 按父租户分组创建素材库
|
|||
|
|
INSERT INTO scenic_material_library (library_name, parent_tenant_id, description, status)
|
|||
|
|
SELECT DISTINCT
|
|||
|
|
CONCAT(st.tenant_name, '素材库') as library_name,
|
|||
|
|
st.tenant_id as parent_tenant_id,
|
|||
|
|
'从历史数据迁移' as description,
|
|||
|
|
1 as status
|
|||
|
|
FROM tourisms t
|
|||
|
|
INNER JOIN sys_tenant st ON t.tenant_id = st.tenant_id
|
|||
|
|
WHERE EXISTS (
|
|||
|
|
SELECT 1 FROM tourisms_files tf WHERE tf.tourism_id = t.id
|
|||
|
|
)
|
|||
|
|
GROUP BY st.parent_tenant_id;
|
|||
|
|
|
|||
|
|
-- Step 2: 迁移素材数据(去重:同一父租户下相同URL只保留一份)
|
|||
|
|
INSERT INTO scenic_material (library_id, material_name, material_url, material_type, description)
|
|||
|
|
SELECT DISTINCT
|
|||
|
|
sml.id as library_id,
|
|||
|
|
tf.description as material_name,
|
|||
|
|
tf.image_url as material_url,
|
|||
|
|
tf.type as material_type,
|
|||
|
|
tf.description
|
|||
|
|
FROM tourisms_files tf
|
|||
|
|
INNER JOIN tourisms t ON tf.tourism_id = t.id
|
|||
|
|
INNER JOIN sys_tenant st ON t.tenant_id = st.tenant_id
|
|||
|
|
INNER JOIN scenic_material_library sml ON st.parent_tenant_id = sml.parent_tenant_id
|
|||
|
|
OR st.tenant_id = sml.parent_tenant_id
|
|||
|
|
WHERE tf.is_del = 0 OR tf.is_del IS NULL
|
|||
|
|
GROUP BY sml.id, tf.image_url; -- 按素材库+URL去重
|
|||
|
|
|
|||
|
|
-- Step 3: 更新tourisms关联素材库
|
|||
|
|
UPDATE tourisms t
|
|||
|
|
INNER JOIN sys_tenant st ON t.tenant_id = st.tenant_id
|
|||
|
|
INNER JOIN scenic_material_library sml ON st.parent_tenant_id = sml.parent_tenant_id
|
|||
|
|
OR st.tenant_id = sml.parent_tenant_id
|
|||
|
|
SET t.material_library_id = sml.id;
|
|||
|
|
|
|||
|
|
-- Step 4: 更新素材库的素材数量
|
|||
|
|
UPDATE scenic_material_library sml
|
|||
|
|
SET material_count = (
|
|||
|
|
SELECT COUNT(*) FROM scenic_material sm WHERE sm.library_id = sml.id
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
-- Step 5: (可选) 验证迁移结果
|
|||
|
|
SELECT
|
|||
|
|
sml.id,
|
|||
|
|
sml.library_name,
|
|||
|
|
sml.parent_tenant_id,
|
|||
|
|
sml.material_count,
|
|||
|
|
COUNT(DISTINCT t.id) as tourism_count
|
|||
|
|
FROM scenic_material_library sml
|
|||
|
|
LEFT JOIN tourisms t ON t.material_library_id = sml.id
|
|||
|
|
GROUP BY sml.id;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 五、实现步骤
|
|||
|
|
|
|||
|
|
### Phase 1: 数据库与实体 (1-2天)
|
|||
|
|
|
|||
|
|
| 序号 | 任务 | 说明 |
|
|||
|
|
|------|------|------|
|
|||
|
|
| 1.1 | 执行DDL创建新表 | scenic_material_library, scenic_material |
|
|||
|
|
| 1.2 | tourisms表添加字段 | material_library_id |
|
|||
|
|
| 1.3 | 创建实体类 | ScenicMaterialLibrary.java, ScenicMaterial.java |
|
|||
|
|
| 1.4 | 创建Mapper | ScenicMaterialLibraryMapper, ScenicMaterialMapper |
|
|||
|
|
| 1.5 | 修改Tourism实体 | 添加materialLibraryId字段 |
|
|||
|
|
|
|||
|
|
### Phase 2: 后端服务 (2-3天)
|
|||
|
|
|
|||
|
|
| 序号 | 任务 | 说明 |
|
|||
|
|
|------|------|------|
|
|||
|
|
| 2.1 | 素材库CRUD接口 | 创建、查询、删除素材库 |
|
|||
|
|
| 2.2 | 素材管理接口 | 上传、删除、排序素材 |
|
|||
|
|
| 2.3 | 获取可用素材接口 | 根据tourismId返回关联素材库的素材 |
|
|||
|
|
| 2.4 | 修改二维码创建逻辑 | 从素材库获取素材 |
|
|||
|
|
|
|||
|
|
### Phase 3: 前端开发 (2-3天)
|
|||
|
|
|
|||
|
|
| 序号 | 任务 | 说明 |
|
|||
|
|
|------|------|------|
|
|||
|
|
| 3.1 | 素材库管理页面 | 父租户后台新增菜单 |
|
|||
|
|
| 3.2 | 素材上传组件 | 支持批量上传、拖拽排序 |
|
|||
|
|
| 3.3 | tourism创建/编辑 | 添加素材库选择器 |
|
|||
|
|
| 3.4 | 二维码创建页面 | 适配新的素材获取逻辑 |
|
|||
|
|
|
|||
|
|
### Phase 4: 数据迁移 (1天)
|
|||
|
|
|
|||
|
|
| 序号 | 任务 | 说明 |
|
|||
|
|
|------|------|------|
|
|||
|
|
| 4.1 | 备份现有数据 | tourisms_files表 |
|
|||
|
|
| 4.2 | 执行迁移脚本 | 生成素材库+迁移素材 |
|
|||
|
|
| 4.3 | 验证迁移结果 | 检查数据完整性 |
|
|||
|
|
| 4.4 | 功能测试 | 全流程测试 |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 六、预期收益
|
|||
|
|
|
|||
|
|
### 6.1 量化对比
|
|||
|
|
|
|||
|
|
假设场景:1个父租户,3个景区入口 + 5个导游 = 8个子租户
|
|||
|
|
|
|||
|
|
| 指标 | 优化前 | 优化后 | 收益 |
|
|||
|
|
|------|--------|--------|------|
|
|||
|
|
| 素材存储份数 | 8份 | 1份 | 减少87.5% |
|
|||
|
|
| 素材记录数(7张/套) | 56条 | 7条 | 减少87.5% |
|
|||
|
|
| 存储空间(2MB/张) | 112MB | 14MB | 节省98MB |
|
|||
|
|
| 新增子租户操作 | 上传7张 | 选择素材库 | 节省10分钟 |
|
|||
|
|
| 素材更新操作 | 8处 | 1处 | 减少87.5% |
|
|||
|
|
|
|||
|
|
### 6.2 流程对比
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
优化前(每个子租户独立上传):
|
|||
|
|
父租户创建 → 子租户A创建 → 上传7张素材
|
|||
|
|
→ 子租户B创建 → 上传7张素材(重复)
|
|||
|
|
→ 子租户C创建 → 上传7张素材(重复)
|
|||
|
|
→ ...
|
|||
|
|
|
|||
|
|
优化后(素材库共享):
|
|||
|
|
父租户创建 → 创建素材库 → 上传7张素材(仅一次)
|
|||
|
|
→ 子租户A创建 → 选择素材库 ✓
|
|||
|
|
→ 子租户B创建 → 选择素材库 ✓
|
|||
|
|
→ 子租户C创建 → 选择素材库 ✓
|
|||
|
|
→ ...
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 七、扩展能力
|
|||
|
|
|
|||
|
|
### 7.1 支持多素材库
|
|||
|
|
|
|||
|
|
一个父租户可以创建多个素材库,适用于:
|
|||
|
|
- 不同主题(春节、圣诞、日常)
|
|||
|
|
- 不同区域(乐园区、商业区、酒店区)
|
|||
|
|
- 不同用途(宣传素材、活动素材)
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
父租户A
|
|||
|
|
├── 素材库1: 迪士尼乐园-日常
|
|||
|
|
├── 素材库2: 迪士尼乐园-圣诞节
|
|||
|
|
└── 素材库3: 星愿公园
|
|||
|
|
|
|||
|
|
子租户可按需选择不同的素材库
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 7.2 素材库模板
|
|||
|
|
|
|||
|
|
未来可支持素材库模板功能:
|
|||
|
|
- 预设行业模板(景区、酒店、商场)
|
|||
|
|
- 一键创建标准素材库结构
|
|||
|
|
- 素材分类(入口、游玩、出口、商业)
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 八、兼容性说明
|
|||
|
|
|
|||
|
|
### 8.1 旧数据兼容
|
|||
|
|
|
|||
|
|
- **tourisms_files表保留**:迁移完成后可选择保留或归档
|
|||
|
|
- **packages.tourism_file_ids**:需要迁移为新的scenic_material ID
|
|||
|
|
- **前端兼容**:提供新旧接口并存期,逐步切换
|
|||
|
|
|
|||
|
|
### 8.2 API兼容
|
|||
|
|
|
|||
|
|
| 旧接口 | 新接口 | 说明 |
|
|||
|
|
|--------|--------|------|
|
|||
|
|
| GET /tourism-file/byTourism/{id} | GET /scenic/material/available/{id} | 返回格式兼容 |
|
|||
|
|
| POST /tourism-file | POST /scenic/material | 需要指定libraryId |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 九、附录
|
|||
|
|
|
|||
|
|
### 9.1 文件清单
|
|||
|
|
|
|||
|
|
| 文件 | 路径 |
|
|||
|
|
|------|------|
|
|||
|
|
| 素材库实体 | `model/scenic/ScenicMaterialLibrary.java` |
|
|||
|
|
| 素材实体 | `model/scenic/ScenicMaterial.java` |
|
|||
|
|
| 素材库Mapper | `mapper/scenic/ScenicMaterialLibraryMapper.java` |
|
|||
|
|
| 素材Mapper | `mapper/scenic/ScenicMaterialMapper.java` |
|
|||
|
|
| 素材服务 | `service/scenic/IScenicMaterialService.java` |
|
|||
|
|
| 素材控制器 | `controller/scenic/ScenicMaterialController.java` |
|
|||
|
|
| DDL脚本 | `sql/scenic_material_library.sql` |
|
|||
|
|
|
|||
|
|
### 9.2 相关文档
|
|||
|
|
|
|||
|
|
- [导游佣金系统设计](./GUIDE_COMMISSION_SYSTEM.md)
|
|||
|
|
- [租户层级体系设计](../../zlt-doc/doc/TENANT_HIERARCHY_DESIGN.md)
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 十、租户层级与素材库归属设计
|
|||
|
|
|
|||
|
|
### 10.1 实际业务场景分析
|
|||
|
|
|
|||
|
|
以神农架景区为例,完整的业务层级如下:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
神农架旅游集团(运营商)
|
|||
|
|
│
|
|||
|
|
├── 神农架景区(大景区品牌)
|
|||
|
|
│ │
|
|||
|
|
│ ├── 天燕景区(子景区)
|
|||
|
|
│ │ ├── 天燕入口打卡点 → 二维码A
|
|||
|
|
│ │ ├── 燕子洞打卡点 → 二维码B
|
|||
|
|
│ │ └── 红坪画廊打卡点 → 二维码C
|
|||
|
|
│ │
|
|||
|
|
│ ├── 神农坛景区(子景区)
|
|||
|
|
│ │ ├── 神农坛入口打卡点 → 二维码D
|
|||
|
|
│ │ ├── 千年杉王打卡点 → 二维码E
|
|||
|
|
│ │ └── 祭坛广场打卡点 → 二维码F
|
|||
|
|
│ │
|
|||
|
|
│ └── 神农顶景区(子景区)
|
|||
|
|
│ ├── 神农顶入口打卡点 → 二维码G
|
|||
|
|
│ ├── 板壁岩打卡点 → 二维码H
|
|||
|
|
│ └── 金猴岭打卡点 → 二维码I
|
|||
|
|
│
|
|||
|
|
└── 其他景区品牌...
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**业务需求**:
|
|||
|
|
1. 天燕、神农坛、神农顶各自有独立账户,方便各景区人员查账、统计
|
|||
|
|
2. 素材可能在大景区级别共享(神农架整体宣传),也可能各子景区独立(各有特色)
|
|||
|
|
3. 导游可能服务整个神农架,也可能只服务特定子景区
|
|||
|
|
|
|||
|
|
### 10.2 租户层级设计方案
|
|||
|
|
|
|||
|
|
#### 方案推荐:5级租户体系
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
Level 0: 平台(webApp)
|
|||
|
|
│
|
|||
|
|
Level 1: 运营商(神农架旅游集团)
|
|||
|
|
│ - 可查看所有下级数据
|
|||
|
|
│ - 财务汇总统计
|
|||
|
|
│
|
|||
|
|
Level 2: 大景区/品牌(神农架景区)
|
|||
|
|
│ - 汇总下级子景区数据
|
|||
|
|
│
|
|||
|
|
Level 3: 子景区(天燕/神农坛/神农顶)
|
|||
|
|
│ - 独立账户,独立查账
|
|||
|
|
│ - 独立订单统计
|
|||
|
|
│ - 创建自己的素材库 ← 【素材库创建层级】
|
|||
|
|
│
|
|||
|
|
Level 4: 导游(独立子租户)
|
|||
|
|
- 独立账户,可登录系统
|
|||
|
|
- 查看自己的订单、佣金数据
|
|||
|
|
- 数据按租户隔离
|
|||
|
|
- 自动继承父级(子景区)的素材库 ← 【素材共享关键】
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**关键设计**:
|
|||
|
|
- **导游是独立的子租户**(Level 4),拥有独立账户,可以登录系统查看自己的数据
|
|||
|
|
- **素材库归属于子景区**(Level 3),导游通过 parent_tenant_id 自动继承使用
|
|||
|
|
- **数据隔离正常工作**:导游的订单、佣金等数据按 tenant_id 隔离
|
|||
|
|
- 例如:神农坛导游张三 → parent_tenant_id = SUB002 → 自动使用神农坛的素材库
|
|||
|
|
|
|||
|
|
#### 数据表示
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- sys_tenant 租户层级
|
|||
|
|
INSERT INTO sys_tenant (tenant_id, tenant_name, parent_tenant_id, tenant_level, tenant_path) VALUES
|
|||
|
|
-- Level 1: 运营商
|
|||
|
|
('OP001', '神农架旅游集团', NULL, 1, '/OP001/'),
|
|||
|
|
|
|||
|
|
-- Level 2: 大景区品牌
|
|||
|
|
('SC001', '神农架景区', 'OP001', 2, '/OP001/SC001/'),
|
|||
|
|
|
|||
|
|
-- Level 3: 子景区(独立账户,各自有素材库)
|
|||
|
|
('SUB001', '天燕景区', 'SC001', 3, '/OP001/SC001/SUB001/'),
|
|||
|
|
('SUB002', '神农坛景区', 'SC001', 3, '/OP001/SC001/SUB002/'),
|
|||
|
|
('SUB003', '神农顶景区', 'SC001', 3, '/OP001/SC001/SUB003/'),
|
|||
|
|
|
|||
|
|
-- Level 4: 导游(独立子租户,parent指向所属子景区)
|
|||
|
|
('GUIDE001', '导游张三', 'SUB002', 4, '/OP001/SC001/SUB002/GUIDE001/'), -- 神农坛的导游
|
|||
|
|
('GUIDE002', '导游李四', 'SUB002', 4, '/OP001/SC001/SUB002/GUIDE002/'), -- 神农坛的导游
|
|||
|
|
('GUIDE003', '导游王五', 'SUB001', 4, '/OP001/SC001/SUB001/GUIDE003/'), -- 天燕的导游
|
|||
|
|
('GUIDE004', '导游赵六', 'SUB003', 4, '/OP001/SC001/SUB003/GUIDE004/'); -- 神农顶的导游
|
|||
|
|
|
|||
|
|
-- tourisms 表(打卡点 + 导游对应的景区记录)
|
|||
|
|
INSERT INTO tourisms (tourism_name, tenant_id, tourism_type) VALUES
|
|||
|
|
-- 天燕景区的打卡点
|
|||
|
|
('天燕入口打卡点', 'SUB001', 1),
|
|||
|
|
('燕子洞打卡点', 'SUB001', 1),
|
|||
|
|
('红坪画廊打卡点', 'SUB001', 1),
|
|||
|
|
|
|||
|
|
-- 神农坛景区的打卡点
|
|||
|
|
('神农坛入口打卡点', 'SUB002', 1),
|
|||
|
|
('千年杉王打卡点', 'SUB002', 1),
|
|||
|
|
|
|||
|
|
-- 神农顶景区的打卡点
|
|||
|
|
('神农顶入口打卡点', 'SUB003', 1),
|
|||
|
|
('板壁岩打卡点', 'SUB003', 1),
|
|||
|
|
|
|||
|
|
-- 导游对应的tourisms记录(tenant_id是导游自己的租户ID)
|
|||
|
|
('导游张三', 'GUIDE001', 2), -- 导游租户
|
|||
|
|
('导游李四', 'GUIDE002', 2),
|
|||
|
|
('导游王五', 'GUIDE003', 2),
|
|||
|
|
('导游赵六', 'GUIDE004', 2);
|
|||
|
|
|
|||
|
|
-- 素材库(归属于子景区 Level 3)
|
|||
|
|
INSERT INTO scenic_material_library (library_name, owner_tenant_id) VALUES
|
|||
|
|
('天燕景区素材库', 'SUB001'), -- ID=1
|
|||
|
|
('神农坛景区素材库', 'SUB002'), -- ID=2
|
|||
|
|
('神农顶景区素材库', 'SUB003'); -- ID=3
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 导游数据查询与隔离
|
|||
|
|
|
|||
|
|
```java
|
|||
|
|
// 导游登录后,通过自己的 tenant_id 查询数据
|
|||
|
|
// 数据隔离完全正常工作!
|
|||
|
|
|
|||
|
|
// 查询导游自己的订单
|
|||
|
|
SELECT * FROM orders WHERE tenant_id = 'GUIDE001';
|
|||
|
|
|
|||
|
|
// 查询导游自己的佣金
|
|||
|
|
SELECT * FROM guide_commission WHERE tenant_id = 'GUIDE001';
|
|||
|
|
|
|||
|
|
// 导游获取可用素材时,向上查找父租户的素材库
|
|||
|
|
// 导游 GUIDE001 → parent_tenant_id = SUB002 → 使用神农坛素材库
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 10.3 素材库归属设计
|
|||
|
|
|
|||
|
|
#### 核心原则
|
|||
|
|
|
|||
|
|
**素材库在 Level 3(子景区)创建**,导游(Level 4)通过 parent_tenant_id 向上查找并继承使用父级的素材库。
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
素材库归属层级设计:
|
|||
|
|
|
|||
|
|
scenic_material_library
|
|||
|
|
├── owner_tenant_id: 素材库所属租户(子景区,Level 3)
|
|||
|
|
└── 下级导游租户通过 parent_tenant_id 自动继承使用
|
|||
|
|
|
|||
|
|
sys_tenant 表
|
|||
|
|
├── tenant_id: 租户ID
|
|||
|
|
├── parent_tenant_id: 父租户ID(导游指向子景区)
|
|||
|
|
└── tenant_level: 3=子景区, 4=导游
|
|||
|
|
|
|||
|
|
tourisms 表
|
|||
|
|
├── tenant_id: 归属租户(打卡点=子景区ID,导游=导游租户ID)
|
|||
|
|
└── tourism_type: 1=打卡点, 2=导游
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 素材库表结构
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
CREATE TABLE scenic_material_library (
|
|||
|
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
|||
|
|
library_name VARCHAR(100) NOT NULL COMMENT '素材库名称',
|
|||
|
|
owner_tenant_id VARCHAR(32) NOT NULL COMMENT '所属租户ID(子景区 Level 3)',
|
|||
|
|
|
|||
|
|
description VARCHAR(500),
|
|||
|
|
cover_url VARCHAR(500),
|
|||
|
|
material_count INT DEFAULT 0,
|
|||
|
|
status TINYINT DEFAULT 1,
|
|||
|
|
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|||
|
|
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|||
|
|
|
|||
|
|
KEY idx_owner_tenant (owner_tenant_id)
|
|||
|
|
) COMMENT='景区素材库';
|
|||
|
|
|
|||
|
|
-- 素材库归属于子景区(Level 3)
|
|||
|
|
-- 打卡点:直接使用所属子景区的素材库
|
|||
|
|
-- 导游:通过 parent_tenant_id 向上查找子景区的素材库
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 10.4 素材库使用场景示例
|
|||
|
|
|
|||
|
|
#### 核心场景:子景区级素材库 + 导游继承
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
神农坛景区(SUB002,Level 3,独立租户):
|
|||
|
|
├── 📁 素材库: "神农坛景区素材库" (owner_tenant_id = 'SUB002')
|
|||
|
|
│ ├── 包含:神农坛入口、千年杉王、祭坛广场等7张照片
|
|||
|
|
│ │
|
|||
|
|
│ ├── 直接使用(打卡点,tenant_id = 'SUB002'):
|
|||
|
|
│ │ ├── 神农坛入口打卡点 (tourism_type=1)
|
|||
|
|
│ │ └── 千年杉王打卡点 (tourism_type=1)
|
|||
|
|
│ │
|
|||
|
|
│ ├── 继承使用(导游,parent_tenant_id = 'SUB002'):
|
|||
|
|
│ │ ├── 导游张三 (tenant_id='GUIDE001', parent='SUB002') ✓ 继承素材
|
|||
|
|
│ │ └── 导游李四 (tenant_id='GUIDE002', parent='SUB002') ✓ 继承素材
|
|||
|
|
│ │
|
|||
|
|
│ └── 不会共享给:
|
|||
|
|
│ ├── 天燕景区的打卡点 (tenant_id='SUB001')
|
|||
|
|
│ └── 神农顶的导游 (parent_tenant_id='SUB003')
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 完整示例:导游独立租户 + 素材继承
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
神农架景区(SC001,Level 2)
|
|||
|
|
│
|
|||
|
|
├── 天燕景区(SUB001,Level 3,独立租户)
|
|||
|
|
│ ├── 📁 天燕素材库(天燕特有风景)
|
|||
|
|
│ │ ├── 天燕入口.jpg
|
|||
|
|
│ │ ├── 燕子洞.jpg
|
|||
|
|
│ │ └── 红坪画廊.jpg
|
|||
|
|
│ │
|
|||
|
|
│ ├── 打卡点(tenant_id='SUB001')→ 直接使用天燕素材库
|
|||
|
|
│ │
|
|||
|
|
│ └── 导游王五(GUIDE003,Level 4,独立租户)
|
|||
|
|
│ ├── parent_tenant_id = 'SUB001'
|
|||
|
|
│ ├── 可登录系统查看自己的订单、佣金
|
|||
|
|
│ └── 创建二维码时 → 继承使用天燕素材库 ✓
|
|||
|
|
│
|
|||
|
|
├── 神农坛景区(SUB002,Level 3,独立租户)
|
|||
|
|
│ ├── 📁 神农坛素材库(神农坛特有风景)
|
|||
|
|
│ │
|
|||
|
|
│ ├── 打卡点(tenant_id='SUB002')→ 直接使用神农坛素材库
|
|||
|
|
│ │
|
|||
|
|
│ ├── 导游张三(GUIDE001,Level 4,独立租户)
|
|||
|
|
│ │ ├── parent_tenant_id = 'SUB002'
|
|||
|
|
│ │ └── 创建二维码时 → 继承使用神农坛素材库 ✓
|
|||
|
|
│ │
|
|||
|
|
│ └── 导游李四(GUIDE002,Level 4,独立租户)
|
|||
|
|
│ ├── parent_tenant_id = 'SUB002'
|
|||
|
|
│ └── 创建二维码时 → 继承使用神农坛素材库 ✓
|
|||
|
|
│
|
|||
|
|
└── 神农顶景区(SUB003,Level 3,独立租户)
|
|||
|
|
├── 📁 神农顶素材库(神农顶特有风景)
|
|||
|
|
│
|
|||
|
|
└── 导游赵六(GUIDE004,Level 4,独立租户)
|
|||
|
|
├── parent_tenant_id = 'SUB003'
|
|||
|
|
└── 创建二维码时 → 继承使用神农顶素材库 ✓
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 10.5 素材库获取逻辑(核心)
|
|||
|
|
|
|||
|
|
```java
|
|||
|
|
/**
|
|||
|
|
* 获取某个tourism可用的素材
|
|||
|
|
*
|
|||
|
|
* 逻辑:
|
|||
|
|
* 1. 打卡点(tourism_type=1):直接用tenant_id查找素材库
|
|||
|
|
* 2. 导游(tourism_type=2):通过parent_tenant_id向上查找子景区的素材库
|
|||
|
|
*/
|
|||
|
|
public MaterialLibraryVO getAvailableMaterials(Long tourismId) {
|
|||
|
|
// 1. 查询tourism
|
|||
|
|
Tourism tourism = tourismMapper.selectById(tourismId);
|
|||
|
|
String tenantId = tourism.getTenantId();
|
|||
|
|
|
|||
|
|
// 2. 确定素材库所属的租户ID
|
|||
|
|
String libraryOwnerTenantId;
|
|||
|
|
|
|||
|
|
if (tourism.getTourismType() == 1) {
|
|||
|
|
// 打卡点:直接使用当前租户(子景区)的素材库
|
|||
|
|
libraryOwnerTenantId = tenantId;
|
|||
|
|
} else {
|
|||
|
|
// 导游:向上查找父租户(子景区)的素材库
|
|||
|
|
SysTenant tenant = tenantMapper.selectById(tenantId);
|
|||
|
|
if (tenant == null || tenant.getParentTenantId() == null) {
|
|||
|
|
log.warn("导游租户未找到父租户: tenantId={}", tenantId);
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
libraryOwnerTenantId = tenant.getParentTenantId();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 3. 查询素材库
|
|||
|
|
ScenicMaterialLibrary library = libraryMapper.selectByOwnerTenantId(libraryOwnerTenantId);
|
|||
|
|
if (library == null || library.getStatus() != 1) {
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 4. 查询素材列表
|
|||
|
|
List<ScenicMaterial> materials = materialMapper.selectByLibraryId(library.getId());
|
|||
|
|
|
|||
|
|
return buildVO(library, materials);
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**核心逻辑**:
|
|||
|
|
- **打卡点**:`tenant_id` = 子景区ID,直接使用该子景区的素材库
|
|||
|
|
- **导游**:`tenant_id` = 导游租户ID,通过 `parent_tenant_id` 向上查找子景区的素材库
|
|||
|
|
- 素材库归属于子景区(Level 3),导游通过继承关系使用
|
|||
|
|
|
|||
|
|
### 10.6 前端展示逻辑
|
|||
|
|
|
|||
|
|
#### 子景区管理后台
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
┌─────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 神农坛景区 管理后台 (SUB002) │
|
|||
|
|
├─────────────────────────────────────────────────────────────┤
|
|||
|
|
│ │
|
|||
|
|
│ 【素材库管理】 │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ 📁 神农坛景区素材库 │ │
|
|||
|
|
│ │ 素材数量: 7 | [管理素材] │ │
|
|||
|
|
│ │ │ │
|
|||
|
|
│ │ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ... │ │
|
|||
|
|
│ │ │神农坛││千年 ││祭坛 ││ ││ │ │ │
|
|||
|
|
│ │ │入口 ││杉王 ││广场 ││ ││ │ │ │
|
|||
|
|
│ │ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘ │ │
|
|||
|
|
│ │ │ │
|
|||
|
|
│ │ 提示:下级导游将自动继承使用此素材库 │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
│ 【打卡点管理】(tenant_id = SUB002,直接使用素材库) │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ • 神农坛入口打卡点 [编辑] [二维码] │ │
|
|||
|
|
│ │ • 千年杉王打卡点 [编辑] [二维码] │ │
|
|||
|
|
│ │ • 祭坛广场打卡点 [编辑] [二维码] │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
│ 【导游管理】(独立租户,parent_tenant_id = SUB002) │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ • 导游张三 (GUIDE001) 佣金:15% [编辑] [二维码] [登录] │ │
|
|||
|
|
│ │ • 导游李四 (GUIDE002) 佣金:12% [编辑] [二维码] [登录] │ │
|
|||
|
|
│ │ │ │
|
|||
|
|
│ │ 提示:导游可独立登录系统查看自己的订单和佣金 │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
└─────────────────────────────────────────────────────────────┘
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 导游管理后台(独立登录)
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
┌─────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 导游张三 个人中心 (GUIDE001) │
|
|||
|
|
├─────────────────────────────────────────────────────────────┤
|
|||
|
|
│ │
|
|||
|
|
│ 【我的订单】 │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ 订单号: 202412010001 金额: ¥199 状态: 已完成 │ │
|
|||
|
|
│ │ 订单号: 202412010002 金额: ¥299 状态: 已完成 │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
│ 【我的佣金】 │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ 累计佣金: ¥1,520.00 │ │
|
|||
|
|
│ │ 可提现: ¥1,200.00 [申请提现] │ │
|
|||
|
|
│ │ 冻结中: ¥320.00 │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
│ 【我的二维码】 │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ [二维码图片] │ │
|
|||
|
|
│ │ 使用素材: 神农坛景区素材库(继承自父级景区) │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
└─────────────────────────────────────────────────────────────┘
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 创建二维码时(导游)
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
┌─────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 创建二维码 - 导游张三 (GUIDE001) │
|
|||
|
|
├─────────────────────────────────────────────────────────────┤
|
|||
|
|
│ │
|
|||
|
|
│ 景区素材(继承自:神农坛景区素材库) │
|
|||
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|||
|
|
│ │ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ │ │
|
|||
|
|
│ │ │ ☑ │ │ ☑ │ │ ☑ │ │ ☐ │ │ ☐ │ │ │
|
|||
|
|
│ │ │神农坛││千年 ││祭坛 ││ ││ │ │ │
|
|||
|
|
│ │ │入口 ││杉王 ││广场 ││ ││ │ │ │
|
|||
|
|
│ │ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘ │ │
|
|||
|
|
│ │ │ │
|
|||
|
|
│ │ 已选择 3/7 张 [全选] [取消全选] │ │
|
|||
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|||
|
|
│ │
|
|||
|
|
│ ℹ️ 素材来源:通过 parent_tenant_id 继承神农坛景区的素材库 │
|
|||
|
|
│ │
|
|||
|
|
│ [取消] [创建二维码] │
|
|||
|
|
└─────────────────────────────────────────────────────────────┘
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 10.7 权限与数据隔离
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
数据查看权限(导游是独立租户,数据正常隔离):
|
|||
|
|
|
|||
|
|
Level 1 (运营商) 可查看:
|
|||
|
|
├── 所有下级素材库
|
|||
|
|
├── 所有子景区订单汇总
|
|||
|
|
└── 所有导游佣金汇总
|
|||
|
|
|
|||
|
|
Level 2 (大景区/品牌) 可查看:
|
|||
|
|
├── 所有下级子景区的素材库
|
|||
|
|
├── 下级子景区订单汇总
|
|||
|
|
└── 下级导游佣金汇总
|
|||
|
|
|
|||
|
|
Level 3 (子景区) 可查看和管理:
|
|||
|
|
├── 自己的素材库 ← 【素材库创建和管理入口】
|
|||
|
|
├── 自己的打卡点
|
|||
|
|
├── 下级导游列表(可创建导游租户)
|
|||
|
|
├── 自己的订单(含下级导游订单汇总)
|
|||
|
|
└── 自己的统计数据
|
|||
|
|
|
|||
|
|
Level 4 (导游,独立租户) 可查看:
|
|||
|
|
├── 自己的订单 (tenant_id = 'GUIDE001')
|
|||
|
|
├── 自己的佣金 (tenant_id = 'GUIDE001')
|
|||
|
|
├── 继承使用父级(子景区)的素材库 ← 【只读,不能修改】
|
|||
|
|
├── 自己的二维码
|
|||
|
|
└── 自己的统计数据
|
|||
|
|
|
|||
|
|
数据隔离示例:
|
|||
|
|
├── 导游张三 (GUIDE001) 只能看到 tenant_id='GUIDE001' 的数据
|
|||
|
|
├── 导游李四 (GUIDE002) 只能看到 tenant_id='GUIDE002' 的数据
|
|||
|
|
└── 神农坛景区 (SUB002) 可以看到所有下级导游的汇总数据
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 10.8 完整的租户与素材库关系图
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
┌─────────────────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 平台 (Level 0) │
|
|||
|
|
└─────────────────────────────────────────────────────────────────────────┘
|
|||
|
|
│
|
|||
|
|
▼
|
|||
|
|
┌─────────────────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 运营商: 神农架旅游集团 (Level 1) │
|
|||
|
|
│ 可查看所有下级数据 │
|
|||
|
|
└─────────────────────────────────────────────────────────────────────────┘
|
|||
|
|
│
|
|||
|
|
▼
|
|||
|
|
┌─────────────────────────────────────────────────────────────────────────┐
|
|||
|
|
│ 大景区: 神农架景区 (Level 2) │
|
|||
|
|
│ 可汇总下级子景区数据 │
|
|||
|
|
└─────────────────────────────────────────────────────────────────────────┘
|
|||
|
|
│
|
|||
|
|
┌───────────────────────────┼───────────────────────────┐
|
|||
|
|
│ │ │
|
|||
|
|
▼ ▼ ▼
|
|||
|
|
┌───────────────────┐ ┌───────────────────┐ ┌───────────────────┐
|
|||
|
|
│ 天燕景区 (SUB001) │ │ 神农坛景区(SUB002)│ │ 神农顶景区(SUB003)│
|
|||
|
|
│ Level 3 (独立租户)│ │ Level 3 (独立租户)│ │ Level 3 (独立租户)│
|
|||
|
|
├───────────────────┤ ├───────────────────┤ ├───────────────────┤
|
|||
|
|
│ 📁 天燕素材库 │ │ 📁 神农坛素材库 │ │ 📁 神农顶素材库 │
|
|||
|
|
│ (天燕特有风景) │ │ (神农坛特有风景) │ │ (神农顶特有风景) │
|
|||
|
|
├───────────────────┤ ├───────────────────┤ ├───────────────────┤
|
|||
|
|
│ 打卡点: │ │ 打卡点: │ │ 打卡点: │
|
|||
|
|
│ tenant=SUB001 │ │ tenant=SUB002 │ │ tenant=SUB003 │
|
|||
|
|
│ • 天燕入口 │ │ • 神农坛入口 │ │ • 神农顶入口 │
|
|||
|
|
│ • 燕子洞 │ │ • 千年杉王 │ │ • 板壁岩 │
|
|||
|
|
├───────────────────┤ ├───────────────────┤ ├───────────────────┤
|
|||
|
|
│ │ │ │ │ │ │ │ │
|
|||
|
|
│ ▼ │ │ ┌────┴────┐ │ │ ▼ │
|
|||
|
|
│ ┌─────────────┐ │ │ ▼ ▼ │ │ ┌─────────────┐ │
|
|||
|
|
│ │导游王五 │ │ │ ┌──────┐ ┌──────┐│ │ │导游赵六 │ │
|
|||
|
|
│ │GUIDE003 │ │ │ │张三 │ │李四 ││ │ │GUIDE004 │ │
|
|||
|
|
│ │Level4 租户 │ │ │ │GUIDE │ │GUIDE ││ │ │Level4 租户 │ │
|
|||
|
|
│ │parent=SUB01│ │ │ │001 │ │002 ││ │ │parent=SUB03│ │
|
|||
|
|
│ │继承素材库✓ │ │ │ │L4租户│ │L4租户││ │ │继承素材库✓ │ │
|
|||
|
|
│ └─────────────┘ │ │ │继承✓ │ │继承✓ ││ │ └─────────────┘ │
|
|||
|
|
│ │ │ └──────┘ └──────┘│ │ │
|
|||
|
|
└───────────────────┘ └───────────────────┘ └───────────────────┘
|
|||
|
|
|
|||
|
|
关键点:
|
|||
|
|
1. 每个子景区(Level 3)有自己的素材库(风景不同)
|
|||
|
|
2. 打卡点直接使用所属子景区的素材库(tenant_id = 子景区ID)
|
|||
|
|
3. 导游是独立租户(Level 4),通过 parent_tenant_id 继承使用父级素材库
|
|||
|
|
4. 导游可独立登录,查看自己的订单、佣金,数据按 tenant_id 隔离
|
|||
|
|
5. 子景区可管理下级导游,查看汇总数据
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 十一、过渡方案设计
|
|||
|
|
|
|||
|
|
### 11.1 过渡策略
|
|||
|
|
|
|||
|
|
采用**渐进式迁移**策略,新旧系统并存,逐步切换:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
Phase 1: 新建素材库功能(不影响现有功能)
|
|||
|
|
↓
|
|||
|
|
Phase 2: 新建租户使用新素材库,旧租户继续使用旧方式
|
|||
|
|
↓
|
|||
|
|
Phase 3: 批量迁移旧数据到新素材库
|
|||
|
|
↓
|
|||
|
|
Phase 4: 全部切换到新系统,废弃旧接口
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 11.2 后端过渡方案
|
|||
|
|
|
|||
|
|
#### 11.2.1 接口兼容层设计
|
|||
|
|
|
|||
|
|
```java
|
|||
|
|
/**
|
|||
|
|
* 素材获取统一入口 - 兼容新旧两种模式
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/available/{tourismId}")
|
|||
|
|
public Result<MaterialResultVO> getAvailableMaterials(@PathVariable Long tourismId) {
|
|||
|
|
Tourism tourism = tourismMapper.selectById(tourismId);
|
|||
|
|
if (tourism == null) {
|
|||
|
|
return Result.failed("景区/导游不存在");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
MaterialResultVO result = new MaterialResultVO();
|
|||
|
|
|
|||
|
|
// 优先使用新素材库
|
|||
|
|
if (tourism.getMaterialLibraryId() != null) {
|
|||
|
|
// 新模式:从素材库获取
|
|||
|
|
ScenicMaterialLibrary library = libraryMapper.selectById(tourism.getMaterialLibraryId());
|
|||
|
|
List<ScenicMaterial> materials = materialMapper.selectByLibraryId(library.getId());
|
|||
|
|
|
|||
|
|
result.setMode("library"); // 标识使用新模式
|
|||
|
|
result.setLibraryId(library.getId());
|
|||
|
|
result.setLibraryName(library.getLibraryName());
|
|||
|
|
result.setMaterials(convertToVO(materials));
|
|||
|
|
} else {
|
|||
|
|
// 旧模式:从tourisms_files获取
|
|||
|
|
List<TourismFile> files = tourismFileMapper.getByTourismId(tourismId);
|
|||
|
|
|
|||
|
|
result.setMode("legacy"); // 标识使用旧模式
|
|||
|
|
result.setMaterials(convertLegacyToVO(files));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return Result.succeed(result);
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 11.2.2 统一返回格式
|
|||
|
|
|
|||
|
|
```java
|
|||
|
|
@Data
|
|||
|
|
public class MaterialResultVO {
|
|||
|
|
/** 模式: library=新素材库, legacy=旧方式 */
|
|||
|
|
private String mode;
|
|||
|
|
|
|||
|
|
/** 素材库ID (新模式才有) */
|
|||
|
|
private Long libraryId;
|
|||
|
|
|
|||
|
|
/** 素材库名称 (新模式才有) */
|
|||
|
|
private String libraryName;
|
|||
|
|
|
|||
|
|
/** 素材列表 (统一格式) */
|
|||
|
|
private List<MaterialItemVO> materials;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Data
|
|||
|
|
public class MaterialItemVO {
|
|||
|
|
private Long id;
|
|||
|
|
private String name;
|
|||
|
|
private String url;
|
|||
|
|
private Integer type; // 1-图片 2-视频
|
|||
|
|
private Integer sortOrder;
|
|||
|
|
|
|||
|
|
// 兼容旧字段
|
|||
|
|
private Long tourismId; // 旧模式需要
|
|||
|
|
private Long libraryId; // 新模式需要
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 11.2.3 二维码保存逻辑兼容
|
|||
|
|
|
|||
|
|
```java
|
|||
|
|
@PostMapping("/withPlan")
|
|||
|
|
public Result<QrCode> saveOrUpdateQrcodeWithPlan(@RequestBody QrcodeWithPlanDTO body) {
|
|||
|
|
// 前端传入的可能是 tourismFileIds (旧) 或 materialIds (新)
|
|||
|
|
List<Long> materialIds = body.getMaterialIds();
|
|||
|
|
List<Long> tourismFileIds = body.getTourismFileIds();
|
|||
|
|
|
|||
|
|
// 统一处理
|
|||
|
|
String idsToSave;
|
|||
|
|
if (materialIds != null && !materialIds.isEmpty()) {
|
|||
|
|
// 新模式
|
|||
|
|
idsToSave = materialIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|||
|
|
// 标记使用新素材库
|
|||
|
|
plan.setMaterialSource("library");
|
|||
|
|
} else if (tourismFileIds != null && !tourismFileIds.isEmpty()) {
|
|||
|
|
// 旧模式
|
|||
|
|
idsToSave = tourismFileIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|||
|
|
plan.setMaterialSource("legacy");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
plan.setTourismFileIds(idsToSave); // 复用现有字段存储
|
|||
|
|
// ...
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 11.3 数据迁移方案
|
|||
|
|
|
|||
|
|
#### 11.3.1 迁移前准备
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- 1. 备份现有数据
|
|||
|
|
CREATE TABLE tourisms_files_backup AS SELECT * FROM tourisms_files;
|
|||
|
|
CREATE TABLE packages_backup AS SELECT * FROM packages;
|
|||
|
|
|
|||
|
|
-- 2. 添加迁移标记字段
|
|||
|
|
ALTER TABLE tourisms ADD COLUMN material_migrated TINYINT DEFAULT 0 COMMENT '素材迁移标记: 0-未迁移 1-已迁移';
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 11.3.2 分批迁移脚本
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- 按父租户逐个迁移,避免一次性操作过多数据
|
|||
|
|
|
|||
|
|
-- Step 1: 获取需要迁移的父租户列表
|
|||
|
|
SELECT DISTINCT
|
|||
|
|
COALESCE(st.parent_tenant_id, st.tenant_id) as parent_tenant_id,
|
|||
|
|
COUNT(DISTINCT t.id) as tourism_count,
|
|||
|
|
COUNT(DISTINCT tf.id) as file_count
|
|||
|
|
FROM tourisms t
|
|||
|
|
INNER JOIN sys_tenant st ON t.tenant_id = st.tenant_id
|
|||
|
|
LEFT JOIN tourisms_files tf ON tf.tourism_id = t.id
|
|||
|
|
WHERE t.material_migrated = 0
|
|||
|
|
GROUP BY COALESCE(st.parent_tenant_id, st.tenant_id);
|
|||
|
|
|
|||
|
|
-- Step 2: 为每个父租户创建素材库(执行存储过程或逐个执行)
|
|||
|
|
DELIMITER //
|
|||
|
|
CREATE PROCEDURE migrate_tenant_materials(IN p_parent_tenant_id VARCHAR(32))
|
|||
|
|
BEGIN
|
|||
|
|
DECLARE v_library_id BIGINT;
|
|||
|
|
|
|||
|
|
-- 创建素材库
|
|||
|
|
INSERT INTO scenic_material_library (library_name, parent_tenant_id, description, status)
|
|||
|
|
SELECT
|
|||
|
|
CONCAT((SELECT tenant_name FROM sys_tenant WHERE tenant_id = p_parent_tenant_id), '-素材库'),
|
|||
|
|
p_parent_tenant_id,
|
|||
|
|
'从历史数据迁移',
|
|||
|
|
1;
|
|||
|
|
|
|||
|
|
SET v_library_id = LAST_INSERT_ID();
|
|||
|
|
|
|||
|
|
-- 迁移素材(去重)
|
|||
|
|
INSERT INTO scenic_material (library_id, material_name, material_url, material_type, sort_order, description)
|
|||
|
|
SELECT DISTINCT
|
|||
|
|
v_library_id,
|
|||
|
|
COALESCE(tf.description, CONCAT('素材-', tf.id)),
|
|||
|
|
tf.image_url,
|
|||
|
|
tf.type,
|
|||
|
|
tf.id, -- 用原ID作为排序
|
|||
|
|
tf.description
|
|||
|
|
FROM tourisms_files tf
|
|||
|
|
INNER JOIN tourisms t ON tf.tourism_id = t.id
|
|||
|
|
INNER JOIN sys_tenant st ON t.tenant_id = st.tenant_id
|
|||
|
|
WHERE (st.parent_tenant_id = p_parent_tenant_id OR st.tenant_id = p_parent_tenant_id)
|
|||
|
|
AND (tf.is_del = 0 OR tf.is_del IS NULL)
|
|||
|
|
GROUP BY tf.image_url; -- 按URL去重
|
|||
|
|
|
|||
|
|
-- 更新tourisms关联素材库
|
|||
|
|
UPDATE tourisms t
|
|||
|
|
INNER JOIN sys_tenant st ON t.tenant_id = st.tenant_id
|
|||
|
|
SET t.material_library_id = v_library_id,
|
|||
|
|
t.material_migrated = 1
|
|||
|
|
WHERE (st.parent_tenant_id = p_parent_tenant_id OR st.tenant_id = p_parent_tenant_id);
|
|||
|
|
|
|||
|
|
-- 更新素材库计数
|
|||
|
|
UPDATE scenic_material_library
|
|||
|
|
SET material_count = (SELECT COUNT(*) FROM scenic_material WHERE library_id = v_library_id)
|
|||
|
|
WHERE id = v_library_id;
|
|||
|
|
|
|||
|
|
END //
|
|||
|
|
DELIMITER ;
|
|||
|
|
|
|||
|
|
-- Step 3: 执行迁移(逐个父租户)
|
|||
|
|
CALL migrate_tenant_materials('tenant_001');
|
|||
|
|
CALL migrate_tenant_materials('tenant_002');
|
|||
|
|
-- ...
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 11.3.3 迁移后验证
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- 验证迁移完整性
|
|||
|
|
SELECT
|
|||
|
|
'tourisms' as table_name,
|
|||
|
|
COUNT(*) as total,
|
|||
|
|
SUM(CASE WHEN material_migrated = 1 THEN 1 ELSE 0 END) as migrated,
|
|||
|
|
SUM(CASE WHEN material_migrated = 0 THEN 1 ELSE 0 END) as pending
|
|||
|
|
FROM tourisms;
|
|||
|
|
|
|||
|
|
-- 验证素材数量对比
|
|||
|
|
SELECT
|
|||
|
|
sml.library_name,
|
|||
|
|
sml.material_count as new_count,
|
|||
|
|
(SELECT COUNT(DISTINCT tf.image_url)
|
|||
|
|
FROM tourisms_files tf
|
|||
|
|
INNER JOIN tourisms t ON tf.tourism_id = t.id
|
|||
|
|
INNER JOIN sys_tenant st ON t.tenant_id = st.tenant_id
|
|||
|
|
WHERE (st.parent_tenant_id = sml.parent_tenant_id OR st.tenant_id = sml.parent_tenant_id)
|
|||
|
|
AND (tf.is_del = 0 OR tf.is_del IS NULL)
|
|||
|
|
) as old_count_unique
|
|||
|
|
FROM scenic_material_library sml;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 十二、前端修改方案
|
|||
|
|
|
|||
|
|
### 12.1 涉及文件清单
|
|||
|
|
|
|||
|
|
| 文件路径 | 修改内容 |
|
|||
|
|
|----------|----------|
|
|||
|
|
| `src/services/orders.ts` | 新增素材库相关API |
|
|||
|
|
| `src/pages/orders/Tourism/index.tsx` | 景区列表增加素材库关联 |
|
|||
|
|
| `src/pages/orders/Tourism/components/TourismForm.tsx` | 景区表单增加素材库选择 |
|
|||
|
|
| `src/pages/orders/Tourism/components/QrcodeTourismForm.tsx` | 二维码表单适配新素材获取 |
|
|||
|
|
| `src/pages/orders/MaterialLibrary/index.tsx` | **新增**:素材库管理页面 |
|
|||
|
|
| `src/pages/orders/MaterialLibrary/components/` | **新增**:素材库相关组件 |
|
|||
|
|
|
|||
|
|
### 12.2 API接口新增
|
|||
|
|
|
|||
|
|
```typescript
|
|||
|
|
// src/services/orders.ts 新增接口
|
|||
|
|
|
|||
|
|
export const ordersApi = {
|
|||
|
|
// ... 现有接口
|
|||
|
|
|
|||
|
|
// ========== 素材库管理 ==========
|
|||
|
|
|
|||
|
|
/** 获取素材库列表 */
|
|||
|
|
getMaterialLibraryList: async (params: {
|
|||
|
|
parentTenantId?: string;
|
|||
|
|
current?: number;
|
|||
|
|
pageSize?: number;
|
|||
|
|
}) => {
|
|||
|
|
const { current, pageSize, ...rest } = params || {};
|
|||
|
|
const res = await request('/api-order/scenic/material-library/list', {
|
|||
|
|
method: 'GET',
|
|||
|
|
params: { page: current, limit: pageSize, ...rest },
|
|||
|
|
});
|
|||
|
|
return { data: (res as any).data, total: (res as any).count };
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/** 获取素材库详情(含素材列表) */
|
|||
|
|
getMaterialLibraryDetail: async (libraryId: number) => {
|
|||
|
|
const res = await request(`/api-order/scenic/material-library/${libraryId}`, {
|
|||
|
|
method: 'GET',
|
|||
|
|
});
|
|||
|
|
return (res as any).data || res;
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/** 创建素材库 */
|
|||
|
|
createMaterialLibrary: async (data: {
|
|||
|
|
libraryName: string;
|
|||
|
|
parentTenantId: string;
|
|||
|
|
description?: string;
|
|||
|
|
}) => {
|
|||
|
|
const res = await request('/api-order/scenic/material-library', {
|
|||
|
|
method: 'POST',
|
|||
|
|
data,
|
|||
|
|
});
|
|||
|
|
return (res as any).data || res;
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/** 更新素材库 */
|
|||
|
|
updateMaterialLibrary: async (id: number, data: any) => {
|
|||
|
|
const res = await request(`/api-order/scenic/material-library/${id}`, {
|
|||
|
|
method: 'PUT',
|
|||
|
|
data,
|
|||
|
|
});
|
|||
|
|
return (res as any).data || res;
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/** 删除素材库 */
|
|||
|
|
deleteMaterialLibrary: async (id: number) => {
|
|||
|
|
const res = await request(`/api-order/scenic/material-library/${id}`, {
|
|||
|
|
method: 'DELETE',
|
|||
|
|
});
|
|||
|
|
return (res as any).data || res;
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// ========== 素材管理 ==========
|
|||
|
|
|
|||
|
|
/** 获取素材库下的素材列表 */
|
|||
|
|
getMaterialsByLibrary: async (libraryId: number) => {
|
|||
|
|
const res = await request(`/api-order/scenic/material/list/${libraryId}`, {
|
|||
|
|
method: 'GET',
|
|||
|
|
});
|
|||
|
|
return (res as any).data || [];
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/** 上传素材到素材库 */
|
|||
|
|
addMaterialToLibrary: async (data: {
|
|||
|
|
libraryId: number;
|
|||
|
|
materialName?: string;
|
|||
|
|
materialUrl: string;
|
|||
|
|
materialType: number;
|
|||
|
|
description?: string;
|
|||
|
|
}) => {
|
|||
|
|
const res = await request('/api-order/scenic/material', {
|
|||
|
|
method: 'POST',
|
|||
|
|
data,
|
|||
|
|
});
|
|||
|
|
return (res as any).data || res;
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/** 批量上传素材 */
|
|||
|
|
batchAddMaterials: async (data: {
|
|||
|
|
libraryId: number;
|
|||
|
|
materials: Array<{
|
|||
|
|
materialName?: string;
|
|||
|
|
materialUrl: string;
|
|||
|
|
materialType: number;
|
|||
|
|
}>;
|
|||
|
|
}) => {
|
|||
|
|
const res = await request('/api-order/scenic/material/batch', {
|
|||
|
|
method: 'POST',
|
|||
|
|
data,
|
|||
|
|
});
|
|||
|
|
return (res as any).data || res;
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/** 删除素材 */
|
|||
|
|
deleteMaterial: async (id: number) => {
|
|||
|
|
const res = await request(`/api-order/scenic/material/${id}`, {
|
|||
|
|
method: 'DELETE',
|
|||
|
|
});
|
|||
|
|
return (res as any).data || res;
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/** 更新素材排序 */
|
|||
|
|
updateMaterialSort: async (data: { id: number; sortOrder: number }[]) => {
|
|||
|
|
const res = await request('/api-order/scenic/material/sort', {
|
|||
|
|
method: 'PUT',
|
|||
|
|
data,
|
|||
|
|
});
|
|||
|
|
return (res as any).data || res;
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// ========== 统一素材获取(兼容新旧) ==========
|
|||
|
|
|
|||
|
|
/** 获取可用素材(自动判断新旧模式) */
|
|||
|
|
getAvailableMaterials: async (tourismId: number) => {
|
|||
|
|
const res = await request(`/api-order/scenic/material/available/${tourismId}`, {
|
|||
|
|
method: 'GET',
|
|||
|
|
});
|
|||
|
|
return (res as any).data || res;
|
|||
|
|
},
|
|||
|
|
};
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 12.3 素材库管理页面(新增)
|
|||
|
|
|
|||
|
|
```typescript
|
|||
|
|
// src/pages/orders/MaterialLibrary/index.tsx
|
|||
|
|
|
|||
|
|
import React, { useState, useRef } from 'react';
|
|||
|
|
import { PageContainer } from '@ant-design/pro-layout';
|
|||
|
|
import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table';
|
|||
|
|
import { Button, Modal, message, Space, Tag, Image, Popconfirm } from 'antd';
|
|||
|
|
import { PlusOutlined, EditOutlined, DeleteOutlined, PictureOutlined } from '@ant-design/icons';
|
|||
|
|
import { ordersApi } from '@/services/orders';
|
|||
|
|
import { useModel } from 'umi';
|
|||
|
|
import MaterialLibraryForm from './components/MaterialLibraryForm';
|
|||
|
|
import MaterialManageModal from './components/MaterialManageModal';
|
|||
|
|
|
|||
|
|
interface LibraryItem {
|
|||
|
|
id: number;
|
|||
|
|
libraryName: string;
|
|||
|
|
parentTenantId: string;
|
|||
|
|
description?: string;
|
|||
|
|
coverUrl?: string;
|
|||
|
|
materialCount: number;
|
|||
|
|
status: number;
|
|||
|
|
createTime: string;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const MaterialLibrary: React.FC = () => {
|
|||
|
|
const actionRef = useRef<ActionType>();
|
|||
|
|
const { initialState } = useModel('@@initialState');
|
|||
|
|
const currentTenantId = initialState?.currentUser?.tenantId;
|
|||
|
|
|
|||
|
|
const [formOpen, setFormOpen] = useState(false);
|
|||
|
|
const [editingItem, setEditingItem] = useState<LibraryItem | null>(null);
|
|||
|
|
const [materialModalOpen, setMaterialModalOpen] = useState(false);
|
|||
|
|
const [selectedLibrary, setSelectedLibrary] = useState<LibraryItem | null>(null);
|
|||
|
|
|
|||
|
|
const columns: ProColumns<LibraryItem>[] = [
|
|||
|
|
{
|
|||
|
|
title: '素材库名称',
|
|||
|
|
dataIndex: 'libraryName',
|
|||
|
|
render: (_, record) => (
|
|||
|
|
<Space>
|
|||
|
|
{record.coverUrl ? (
|
|||
|
|
<Image src={record.coverUrl} width={40} height={40} style={{ objectFit: 'cover', borderRadius: 4 }} />
|
|||
|
|
) : (
|
|||
|
|
<div style={{ width: 40, height: 40, background: '#f5f5f5', borderRadius: 4, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|||
|
|
<PictureOutlined style={{ color: '#999' }} />
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
<span>{record.libraryName}</span>
|
|||
|
|
</Space>
|
|||
|
|
),
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
title: '素材数量',
|
|||
|
|
dataIndex: 'materialCount',
|
|||
|
|
width: 100,
|
|||
|
|
render: (count) => <Tag color="blue">{count} 个</Tag>,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
title: '状态',
|
|||
|
|
dataIndex: 'status',
|
|||
|
|
width: 80,
|
|||
|
|
render: (status) => (
|
|||
|
|
<Tag color={status === 1 ? 'green' : 'red'}>
|
|||
|
|
{status === 1 ? '启用' : '禁用'}
|
|||
|
|
</Tag>
|
|||
|
|
),
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
title: '描述',
|
|||
|
|
dataIndex: 'description',
|
|||
|
|
ellipsis: true,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
title: '创建时间',
|
|||
|
|
dataIndex: 'createTime',
|
|||
|
|
width: 180,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
title: '操作',
|
|||
|
|
width: 200,
|
|||
|
|
render: (_, record) => (
|
|||
|
|
<Space>
|
|||
|
|
<Button
|
|||
|
|
type="primary"
|
|||
|
|
size="small"
|
|||
|
|
icon={<PictureOutlined />}
|
|||
|
|
onClick={() => {
|
|||
|
|
setSelectedLibrary(record);
|
|||
|
|
setMaterialModalOpen(true);
|
|||
|
|
}}
|
|||
|
|
>
|
|||
|
|
管理素材
|
|||
|
|
</Button>
|
|||
|
|
<Button
|
|||
|
|
size="small"
|
|||
|
|
icon={<EditOutlined />}
|
|||
|
|
onClick={() => {
|
|||
|
|
setEditingItem(record);
|
|||
|
|
setFormOpen(true);
|
|||
|
|
}}
|
|||
|
|
/>
|
|||
|
|
<Popconfirm
|
|||
|
|
title="确定删除此素材库?"
|
|||
|
|
description="删除后,使用此素材库的景区/导游将无法获取素材"
|
|||
|
|
onConfirm={async () => {
|
|||
|
|
await ordersApi.deleteMaterialLibrary(record.id);
|
|||
|
|
message.success('删除成功');
|
|||
|
|
actionRef.current?.reload();
|
|||
|
|
}}
|
|||
|
|
>
|
|||
|
|
<Button size="small" danger icon={<DeleteOutlined />} />
|
|||
|
|
</Popconfirm>
|
|||
|
|
</Space>
|
|||
|
|
),
|
|||
|
|
},
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
return (
|
|||
|
|
<PageContainer>
|
|||
|
|
<ProTable<LibraryItem>
|
|||
|
|
actionRef={actionRef}
|
|||
|
|
columns={columns}
|
|||
|
|
rowKey="id"
|
|||
|
|
search={false}
|
|||
|
|
request={async (params) => {
|
|||
|
|
const { data, total } = await ordersApi.getMaterialLibraryList({
|
|||
|
|
parentTenantId: currentTenantId,
|
|||
|
|
current: params.current,
|
|||
|
|
pageSize: params.pageSize,
|
|||
|
|
});
|
|||
|
|
return { data, total, success: true };
|
|||
|
|
}}
|
|||
|
|
toolBarRender={() => [
|
|||
|
|
<Button
|
|||
|
|
key="add"
|
|||
|
|
type="primary"
|
|||
|
|
icon={<PlusOutlined />}
|
|||
|
|
onClick={() => {
|
|||
|
|
setEditingItem(null);
|
|||
|
|
setFormOpen(true);
|
|||
|
|
}}
|
|||
|
|
>
|
|||
|
|
新建素材库
|
|||
|
|
</Button>,
|
|||
|
|
]}
|
|||
|
|
/>
|
|||
|
|
|
|||
|
|
{/* 素材库表单弹框 */}
|
|||
|
|
<MaterialLibraryForm
|
|||
|
|
open={formOpen}
|
|||
|
|
initialValues={editingItem}
|
|||
|
|
onCancel={() => setFormOpen(false)}
|
|||
|
|
onSuccess={() => {
|
|||
|
|
setFormOpen(false);
|
|||
|
|
actionRef.current?.reload();
|
|||
|
|
}}
|
|||
|
|
/>
|
|||
|
|
|
|||
|
|
{/* 素材管理弹框 */}
|
|||
|
|
<MaterialManageModal
|
|||
|
|
open={materialModalOpen}
|
|||
|
|
library={selectedLibrary}
|
|||
|
|
onCancel={() => setMaterialModalOpen(false)}
|
|||
|
|
onSuccess={() => {
|
|||
|
|
actionRef.current?.reload();
|
|||
|
|
}}
|
|||
|
|
/>
|
|||
|
|
</PageContainer>
|
|||
|
|
);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
export default MaterialLibrary;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 12.4 景区表单增加素材库选择
|
|||
|
|
|
|||
|
|
```typescript
|
|||
|
|
// src/pages/orders/Tourism/components/TourismForm.tsx 修改
|
|||
|
|
|
|||
|
|
import { Select, Divider, Button } from 'antd';
|
|||
|
|
import { PlusOutlined } from '@ant-design/icons';
|
|||
|
|
|
|||
|
|
// 在表单中新增素材库选择字段
|
|||
|
|
<ProForm.Item
|
|||
|
|
label="关联素材库"
|
|||
|
|
name="materialLibraryId"
|
|||
|
|
tooltip="选择素材库后,该景区/导游创建二维码时将使用此素材库的素材"
|
|||
|
|
>
|
|||
|
|
<Select
|
|||
|
|
placeholder="请选择素材库"
|
|||
|
|
allowClear
|
|||
|
|
showSearch
|
|||
|
|
optionFilterProp="label"
|
|||
|
|
options={libraryOptions}
|
|||
|
|
dropdownRender={(menu) => (
|
|||
|
|
<>
|
|||
|
|
{menu}
|
|||
|
|
<Divider style={{ margin: '8px 0' }} />
|
|||
|
|
<Button
|
|||
|
|
type="link"
|
|||
|
|
icon={<PlusOutlined />}
|
|||
|
|
onClick={() => {
|
|||
|
|
// 跳转到素材库管理页面
|
|||
|
|
window.open('/orders/materialLibrary.html', '_blank');
|
|||
|
|
}}
|
|||
|
|
>
|
|||
|
|
新建素材库
|
|||
|
|
</Button>
|
|||
|
|
</>
|
|||
|
|
)}
|
|||
|
|
/>
|
|||
|
|
</ProForm.Item>
|
|||
|
|
|
|||
|
|
// 加载素材库列表
|
|||
|
|
const [libraryOptions, setLibraryOptions] = useState<{ label: string; value: number }[]>([]);
|
|||
|
|
|
|||
|
|
useEffect(() => {
|
|||
|
|
const loadLibraries = async () => {
|
|||
|
|
try {
|
|||
|
|
const { data } = await ordersApi.getMaterialLibraryList({
|
|||
|
|
parentTenantId: currentTenantId,
|
|||
|
|
});
|
|||
|
|
setLibraryOptions(
|
|||
|
|
(data || []).map((lib: any) => ({
|
|||
|
|
label: `${lib.libraryName} (${lib.materialCount}个素材)`,
|
|||
|
|
value: lib.id,
|
|||
|
|
}))
|
|||
|
|
);
|
|||
|
|
} catch (e) {
|
|||
|
|
console.error('加载素材库失败', e);
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
loadLibraries();
|
|||
|
|
}, [currentTenantId]);
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 12.5 二维码表单适配新素材获取
|
|||
|
|
|
|||
|
|
```typescript
|
|||
|
|
// src/pages/orders/Tourism/components/QrcodeTourismForm.tsx 修改
|
|||
|
|
|
|||
|
|
// 替换原有的素材加载逻辑
|
|||
|
|
useEffect(() => {
|
|||
|
|
if (!open || !tourismIdForFetch) {
|
|||
|
|
setTourismFiles([]);
|
|||
|
|
setMaterialMode('legacy');
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
let canceled = false;
|
|||
|
|
(async () => {
|
|||
|
|
try {
|
|||
|
|
// 使用新的统一接口
|
|||
|
|
const result = await ordersApi.getAvailableMaterials(tourismIdForFetch as number);
|
|||
|
|
|
|||
|
|
if (canceled) return;
|
|||
|
|
|
|||
|
|
if (result?.mode === 'library') {
|
|||
|
|
// 新模式:素材库
|
|||
|
|
setMaterialMode('library');
|
|||
|
|
setLibraryInfo({
|
|||
|
|
id: result.libraryId,
|
|||
|
|
name: result.libraryName,
|
|||
|
|
});
|
|||
|
|
setTourismFiles(result.materials || []);
|
|||
|
|
} else {
|
|||
|
|
// 旧模式:tourisms_files
|
|||
|
|
setMaterialMode('legacy');
|
|||
|
|
setLibraryInfo(null);
|
|||
|
|
setTourismFiles(result?.materials || []);
|
|||
|
|
}
|
|||
|
|
} catch (e) {
|
|||
|
|
if (!canceled) {
|
|||
|
|
setTourismFiles([]);
|
|||
|
|
setMaterialMode('legacy');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})();
|
|||
|
|
|
|||
|
|
return () => {
|
|||
|
|
canceled = true;
|
|||
|
|
};
|
|||
|
|
}, [open, tourismIdForFetch]);
|
|||
|
|
|
|||
|
|
// 状态定义
|
|||
|
|
const [materialMode, setMaterialMode] = useState<'library' | 'legacy'>('legacy');
|
|||
|
|
const [libraryInfo, setLibraryInfo] = useState<{ id: number; name: string } | null>(null);
|
|||
|
|
|
|||
|
|
// 素材选择区域增加提示
|
|||
|
|
<ProForm.Item label="景区素材" shouldUpdate>
|
|||
|
|
{({ getFieldValue, setFieldsValue }) => {
|
|||
|
|
const selected: number[] = getFieldValue('tourismFileIds') || [];
|
|||
|
|
const list = tourismFiles;
|
|||
|
|
|
|||
|
|
return (
|
|||
|
|
<div>
|
|||
|
|
{/* 素材来源提示 */}
|
|||
|
|
<div style={{ marginBottom: 12, padding: '8px 12px', background: '#f6ffed', border: '1px solid #b7eb8f', borderRadius: 4 }}>
|
|||
|
|
{materialMode === 'library' ? (
|
|||
|
|
<span>
|
|||
|
|
📁 素材来源:<strong>{libraryInfo?.name}</strong>
|
|||
|
|
<span style={{ color: '#999', marginLeft: 8 }}>(素材库模式)</span>
|
|||
|
|
</span>
|
|||
|
|
) : (
|
|||
|
|
<span>
|
|||
|
|
📁 素材来源:当前景区独立素材
|
|||
|
|
<span style={{ color: '#faad14', marginLeft: 8 }}>(建议迁移到素材库)</span>
|
|||
|
|
</span>
|
|||
|
|
)}
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
{/* 全选/取消按钮 */}
|
|||
|
|
<div style={{ display: 'flex', gap: 12, alignItems: 'center', marginBottom: 8 }}>
|
|||
|
|
<Button type="primary" size="small" onClick={() => {
|
|||
|
|
const ids = list.map((f: any) => f?.id).filter(Boolean);
|
|||
|
|
setFieldsValue({ tourismFileIds: ids });
|
|||
|
|
}}>
|
|||
|
|
全部选择
|
|||
|
|
</Button>
|
|||
|
|
<Button size="small" onClick={() => setFieldsValue({ tourismFileIds: [] })}>
|
|||
|
|
取消选择
|
|||
|
|
</Button>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div style={{ marginBottom: 8, fontSize: 12, color: '#666' }}>
|
|||
|
|
已选 {selected.length} 个;共 {list.length} 个
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
{/* 素材网格 */}
|
|||
|
|
<div style={{ maxHeight: 420, overflow: 'auto', padding: 8, background: '#fafafa', border: '1px solid #f0f0f0', borderRadius: 6 }}>
|
|||
|
|
{list.length === 0 ? (
|
|||
|
|
<div style={{ textAlign: 'center', padding: 40, color: '#999' }}>
|
|||
|
|
暂无素材,请先
|
|||
|
|
{materialMode === 'library' ? '在素材库中添加素材' : '上传景区素材'}
|
|||
|
|
</div>
|
|||
|
|
) : (
|
|||
|
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(140px, 1fr))', gap: 12 }}>
|
|||
|
|
{list.map((f: any) => {
|
|||
|
|
const id = f?.id;
|
|||
|
|
const url = f?.url || f?.materialUrl || f?.imageUrl;
|
|||
|
|
const isSel = selected.includes(id);
|
|||
|
|
return (
|
|||
|
|
<div
|
|||
|
|
key={id}
|
|||
|
|
onClick={() => {
|
|||
|
|
const exists = selected.includes(id);
|
|||
|
|
setFieldsValue({
|
|||
|
|
tourismFileIds: exists
|
|||
|
|
? selected.filter((x) => x !== id)
|
|||
|
|
: [...selected, id],
|
|||
|
|
});
|
|||
|
|
}}
|
|||
|
|
style={{
|
|||
|
|
borderWidth: 2,
|
|||
|
|
borderStyle: 'solid',
|
|||
|
|
borderColor: isSel ? '#52c41a' : '#f0f0f0',
|
|||
|
|
borderRadius: 6,
|
|||
|
|
cursor: 'pointer',
|
|||
|
|
background: '#fff',
|
|||
|
|
boxShadow: isSel ? '0 0 0 2px rgba(82,196,26,0.12) inset' : 'none',
|
|||
|
|
}}
|
|||
|
|
>
|
|||
|
|
<div style={{ position: 'relative', width: '100%', aspectRatio: '4 / 3', background: '#fafafa' }}>
|
|||
|
|
{url ? (
|
|||
|
|
<img src={url} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
|
|||
|
|
) : (
|
|||
|
|
<div style={{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#999' }}>
|
|||
|
|
无图片
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
{isSel && (
|
|||
|
|
<div style={{ position: 'absolute', top: 6, right: 6, width: 18, height: 18, borderRadius: '50%', background: '#52c41a' }} />
|
|||
|
|
)}
|
|||
|
|
</div>
|
|||
|
|
<div style={{ padding: '6px 8px', fontSize: 12, color: '#555' }}>
|
|||
|
|
{f?.name || f?.materialName || f?.description || `素材-${id}`}
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
);
|
|||
|
|
})}
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
);
|
|||
|
|
}}
|
|||
|
|
</ProForm.Item>
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 12.6 路由配置
|
|||
|
|
|
|||
|
|
```typescript
|
|||
|
|
// config/routes.ts 新增路由
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
path: '/orders',
|
|||
|
|
routes: [
|
|||
|
|
// ... 现有路由
|
|||
|
|
{
|
|||
|
|
path: '/orders/materialLibrary',
|
|||
|
|
name: '素材库管理',
|
|||
|
|
component: './orders/MaterialLibrary',
|
|||
|
|
},
|
|||
|
|
],
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 12.7 菜单配置
|
|||
|
|
|
|||
|
|
```typescript
|
|||
|
|
// 在菜单配置中添加(根据实际菜单结构调整)
|
|||
|
|
{
|
|||
|
|
name: '素材库管理',
|
|||
|
|
path: '/orders/materialLibrary.html',
|
|||
|
|
icon: 'picture',
|
|||
|
|
// 仅父租户可见(可通过权限控制)
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 十三、测试方案
|
|||
|
|
|
|||
|
|
### 13.1 后端测试用例
|
|||
|
|
|
|||
|
|
| 测试项 | 测试内容 | 预期结果 |
|
|||
|
|
|--------|----------|----------|
|
|||
|
|
| 素材库创建 | 父租户创建素材库 | 创建成功,返回ID |
|
|||
|
|
| 素材上传 | 上传图片/视频到素材库 | 上传成功,素材数+1 |
|
|||
|
|
| 素材获取(新模式) | tourism已关联素材库 | 返回mode=library,素材列表正确 |
|
|||
|
|
| 素材获取(旧模式) | tourism未关联素材库 | 返回mode=legacy,从tourisms_files获取 |
|
|||
|
|
| 二维码创建(新模式) | 选择素材库中的素材 | 保存成功,package记录正确 |
|
|||
|
|
| 二维码创建(旧模式) | 选择tourisms_files | 兼容旧逻辑,保存成功 |
|
|||
|
|
| 数据迁移 | 执行迁移脚本 | 素材去重正确,关联正确 |
|
|||
|
|
|
|||
|
|
### 13.2 前端测试用例
|
|||
|
|
|
|||
|
|
| 测试项 | 操作步骤 | 预期结果 |
|
|||
|
|
|--------|----------|----------|
|
|||
|
|
| 素材库管理 | 新建/编辑/删除素材库 | 操作成功,列表刷新 |
|
|||
|
|
| 素材上传 | 拖拽上传多张图片 | 批量上传成功 |
|
|||
|
|
| 景区关联 | 编辑景区,选择素材库 | 保存成功 |
|
|||
|
|
| 二维码创建(新) | 选择已关联素材库的景区 | 显示素材库名称,素材列表正确 |
|
|||
|
|
| 二维码创建(旧) | 选择未关联素材库的景区 | 显示旧素材,提示迁移 |
|
|||
|
|
| 兼容性 | 旧数据编辑 | 正常显示和保存 |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 十四、上线计划
|
|||
|
|
|
|||
|
|
### 14.1 灰度发布步骤
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
Week 1: 开发环境验证
|
|||
|
|
├── 后端:素材库API + 兼容层
|
|||
|
|
├── 前端:素材库管理页面
|
|||
|
|
└── 测试:全量功能测试
|
|||
|
|
|
|||
|
|
Week 2: 测试环境 + 小范围试用
|
|||
|
|
├── 选择1-2个租户试用新功能
|
|||
|
|
├── 收集反馈,修复问题
|
|||
|
|
└── 准备数据迁移脚本
|
|||
|
|
|
|||
|
|
Week 3: 生产环境灰度
|
|||
|
|
├── 新建租户默认使用新模式
|
|||
|
|
├── 旧租户可选择性迁移
|
|||
|
|
└── 监控系统稳定性
|
|||
|
|
|
|||
|
|
Week 4: 全量推广
|
|||
|
|
├── 批量迁移剩余租户
|
|||
|
|
├── 废弃旧素材管理入口
|
|||
|
|
└── 保留旧API兼容(3个月后下线)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 14.2 回滚方案
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- 如需回滚,执行以下操作
|
|||
|
|
|
|||
|
|
-- 1. 清除tourisms的素材库关联
|
|||
|
|
UPDATE tourisms SET material_library_id = NULL, material_migrated = 0;
|
|||
|
|
|
|||
|
|
-- 2. 前端切换回旧接口(通过配置开关)
|
|||
|
|
-- 3. 旧接口保持可用,无需额外操作
|
|||
|
|
```
|