@steedos-labs/content-compliance 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/IMAGE_COMPARISON_FEATURE.md +275 -0
- package/IMAGE_COMPARISON_README.md +250 -0
- package/dist/index.js +1 -1
- package/lib/actions/imageComparison.d.ts +34 -0
- package/lib/actions/imageComparison.js +95 -0
- package/lib/actions/imageComparison.js.map +1 -0
- package/lib/actions/index.d.ts +1 -0
- package/lib/actions/index.js +1 -0
- package/lib/actions/index.js.map +1 -1
- package/lib/index.js +123 -39
- package/lib/index.js.map +1 -1
- package/lib/methods/approval_engine.js +5 -1
- package/lib/methods/approval_engine.js.map +1 -1
- package/lib/methods/consts.d.ts +3 -1
- package/lib/methods/consts.js.map +1 -1
- package/lib/methods/image_comparison.d.ts +39 -0
- package/lib/methods/image_comparison.js +456 -0
- package/lib/methods/image_comparison.js.map +1 -0
- package/lib/methods/index.d.ts +1 -0
- package/lib/methods/index.js +1 -0
- package/lib/methods/index.js.map +1 -1
- package/main/default/objects/pepsico_material/buttons/pepsico_bypass_material.button.yml +2 -2
- package/main/default/objects/pepsico_material/fields/image_comparison_at.field.yml +12 -0
- package/main/default/objects/pepsico_material/fields/image_comparison_error.field.yml +8 -0
- package/main/default/objects/pepsico_material/fields/image_comparison_reason.field.yml +9 -0
- package/main/default/objects/pepsico_material/fields/image_comparison_result.field.yml +14 -0
- package/main/default/objects/pepsico_material/fields/image_comparison_status.field.yml +21 -0
- package/main/default/objects/pepsico_material/fields/result_image.field.yml +4 -0
- package/main/default/objects/pepsico_material_approval/buttons/pepsico_bypass_approval.button.yml +1 -1
- package/main/default/objects/pepsico_material_approval/fields/can_pass_users.field.yml +11 -0
- package/main/default/objects/pepsico_material_approval/fields/classification.field.yml +5 -0
- package/main/default/objects/pepsico_material_approval/fields/image_comparison_at.field.yml +6 -0
- package/main/default/objects/pepsico_material_approval/fields/image_comparison_stats.field.yml +8 -0
- package/main/default/objects/pepsico_material_approval/fields/image_comparison_status.field.yml +15 -0
- package/main/default/objects/pepsico_material_approval/fields/product.field.yml +5 -0
- package/main/default/objects/pepsico_reviewer/fields/can_pass_users.field.yml +8 -0
- package/main/default/pages/pepsico_material_detail.page.amis.json +316 -0
- package/package.json +1 -1
- package/public/content-review/amis.css +36 -1
- package/test_image_comparison.js +172 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# 图片版本对比功能文档 (Image Comparison Feature Documentation)
|
|
2
|
+
|
|
3
|
+
## 功能概述 (Feature Overview)
|
|
4
|
+
|
|
5
|
+
本功能实现了审批流程中前后两次提交的图片内容对比功能。当审批单被驳回修改后重新提交时,系统会自动识别图片素材,并调用AI算法对当前版本和上一版本进行对比分析,标注出差异点。
|
|
6
|
+
|
|
7
|
+
The feature implements image comparison between different versions in the approval workflow. When an approval is rejected and resubmitted, the system automatically identifies image materials and calls an AI algorithm to compare the current version with the previous version, marking the differences.
|
|
8
|
+
|
|
9
|
+
## 功能特性 (Features)
|
|
10
|
+
|
|
11
|
+
### 1. 智能识别修改场景 (Smart Detection of Modified Submissions)
|
|
12
|
+
- 自动识别审批单的"修改后提交"场景(submitter_revisions 步骤)
|
|
13
|
+
- 区分首次提交和驳回后重新提交的场景
|
|
14
|
+
- Automatically detects "modified submission" scenarios (submitter_revisions step)
|
|
15
|
+
- Distinguishes between first-time submissions and resubmissions after rejection
|
|
16
|
+
|
|
17
|
+
### 2. 图片素材筛选 (Image Material Filtering)
|
|
18
|
+
- 根据扩展名自动筛选图片类型素材
|
|
19
|
+
- 支持的图片格式:JPG, JPEG, PNG, GIF, BMP, TIFF, TIF, SVG, WEBP, ICO, HEIF, HEIC
|
|
20
|
+
- 排除已作废和已跳过的素材
|
|
21
|
+
- Automatically filters image materials by extension
|
|
22
|
+
- Supported formats: JPG, JPEG, PNG, GIF, BMP, TIFF, TIF, SVG, WEBP, ICO, HEIF, HEIC
|
|
23
|
+
- Excludes voided and bypassed materials
|
|
24
|
+
|
|
25
|
+
### 3. 版本管理 (Version Management)
|
|
26
|
+
- 自动获取素材的当前版本和历史版本
|
|
27
|
+
- 支持从 OneDrive 历史记录中提取版本信息
|
|
28
|
+
- 如无历史记录,则使用原始素材作为对比基准
|
|
29
|
+
- Automatically retrieves current and historical versions of materials
|
|
30
|
+
- Supports extracting version information from OneDrive history
|
|
31
|
+
- Uses original material as baseline if no history exists
|
|
32
|
+
|
|
33
|
+
### 4. 异步处理机制 (Async Processing)
|
|
34
|
+
- 采用异步任务机制,不阻塞审批主流程
|
|
35
|
+
- 完整的异常捕获和错误处理
|
|
36
|
+
- 详细的日志记录,便于追踪和排查问题
|
|
37
|
+
- Uses async task mechanism to avoid blocking the approval workflow
|
|
38
|
+
- Complete exception handling and error recovery
|
|
39
|
+
- Detailed logging for tracking and troubleshooting
|
|
40
|
+
|
|
41
|
+
### 5. 前端展示 (Frontend Display)
|
|
42
|
+
- 在素材详情页新增"版本对比" Tab
|
|
43
|
+
- 并排展示当前版本和上一版本
|
|
44
|
+
- 显示标注差异的对比图
|
|
45
|
+
- 展示差异详情列表(类型、描述、置信度)
|
|
46
|
+
- 显示相似度评分
|
|
47
|
+
- New "Version Comparison" tab in material detail page
|
|
48
|
+
- Side-by-side display of current and previous versions
|
|
49
|
+
- Shows diff image with marked differences
|
|
50
|
+
- Displays difference details list (type, description, confidence)
|
|
51
|
+
- Shows similarity score
|
|
52
|
+
|
|
53
|
+
## 技术架构 (Technical Architecture)
|
|
54
|
+
|
|
55
|
+
### Backend Components
|
|
56
|
+
|
|
57
|
+
#### 1. Core Module (`src/methods/image_comparison.ts`)
|
|
58
|
+
主要功能模块:
|
|
59
|
+
- `isModifiedSubmission()`: 判断是否为修改后提交场景
|
|
60
|
+
- `getImageMaterials()`: 获取审批单中的所有图片素材
|
|
61
|
+
- `getMaterialVersions()`: 获取素材的版本信息
|
|
62
|
+
- `prepareImageComparisonData()`: 准备调用AI接口的数据
|
|
63
|
+
- `callImageComparisonAPI()`: 调用AI图片对比接口
|
|
64
|
+
- `storeComparisonResult()`: 存储对比结果到数据库
|
|
65
|
+
- `processImageComparison()`: 处理单个素材的对比
|
|
66
|
+
- `processBulkImageComparison()`: 批量处理审批单中的所有图片素材
|
|
67
|
+
- `triggerImageComparisonAsync()`: 异步触发图片对比任务
|
|
68
|
+
|
|
69
|
+
#### 2. Workflow Integration (`src/methods/approval_engine.ts`)
|
|
70
|
+
集成点:
|
|
71
|
+
- 在 `advanceApproval()` 函数中,当审批单从 `submitter_revisions` 步骤提交时触发
|
|
72
|
+
- 使用 `triggerImageComparisonAsync()` 异步触发对比任务
|
|
73
|
+
|
|
74
|
+
#### 3. API Actions (`src/actions/imageComparison.ts`)
|
|
75
|
+
提供的API接口:
|
|
76
|
+
- `POST /api/pepsico-content/image-comparison/trigger/:recordId` - 手动触发图片对比
|
|
77
|
+
- `GET /api/pepsico-content/image-comparison/status/:recordId` - 获取对比状态
|
|
78
|
+
|
|
79
|
+
### Database Schema
|
|
80
|
+
|
|
81
|
+
#### pepsico_material 对象新增字段:
|
|
82
|
+
- `image_comparison_status` (select): 对比状态 (pending/completed/skipped/failed)
|
|
83
|
+
- `image_comparison_result` (json): 对比结果数据
|
|
84
|
+
- `image_comparison_at` (datetime): 对比时间
|
|
85
|
+
- `image_comparison_reason` (text): 跳过原因
|
|
86
|
+
- `image_comparison_error` (textarea): 错误信息
|
|
87
|
+
|
|
88
|
+
#### pepsico_material_approval 对象新增字段:
|
|
89
|
+
- `image_comparison_status` (select): 批量对比状态 (pending/completed/partial/failed)
|
|
90
|
+
- `image_comparison_stats` (json): 对比统计信息
|
|
91
|
+
- `image_comparison_at` (datetime): 对比时间
|
|
92
|
+
|
|
93
|
+
### Frontend Components
|
|
94
|
+
|
|
95
|
+
#### Material Detail Page (`main/default/pages/pepsico_material_detail.page.amis.json`)
|
|
96
|
+
新增"版本对比" Tab:
|
|
97
|
+
- 对比状态展示
|
|
98
|
+
- 并排图片对比显示
|
|
99
|
+
- 差异标注图展示
|
|
100
|
+
- 差异详情表格
|
|
101
|
+
- 相似度评分
|
|
102
|
+
|
|
103
|
+
#### Styles (`public/content-review/amis.css`)
|
|
104
|
+
添加图片对比 Tab 的样式定义
|
|
105
|
+
|
|
106
|
+
## AI 接口规范 (AI API Specification)
|
|
107
|
+
|
|
108
|
+
### 请求接口 (Request Endpoint)
|
|
109
|
+
```
|
|
110
|
+
POST {AI_HOST}/api/v1/image-comparison
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 请求头 (Request Headers)
|
|
114
|
+
```
|
|
115
|
+
X-API-Key: {API_KEY}
|
|
116
|
+
Content-Type: application/json
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 请求体 (Request Body)
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"material_id": "素材ID",
|
|
123
|
+
"approval_id": "审批单ID",
|
|
124
|
+
"name": "素材名称",
|
|
125
|
+
"current_version": {
|
|
126
|
+
"file_id": "当前版本文件ID",
|
|
127
|
+
"url": "当前版本URL"
|
|
128
|
+
},
|
|
129
|
+
"previous_version": {
|
|
130
|
+
"file_id": "上一版本文件ID",
|
|
131
|
+
"url": "上一版本URL"
|
|
132
|
+
},
|
|
133
|
+
"extension_type": "文件扩展名"
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 响应体 (Response Body)
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"current_image_url": "当前版本图片URL",
|
|
141
|
+
"previous_image_url": "上一版本图片URL",
|
|
142
|
+
"diff_image_url": "差异标注图URL",
|
|
143
|
+
"similarity_score": 0.95,
|
|
144
|
+
"differences": [
|
|
145
|
+
{
|
|
146
|
+
"type": "颜色变化",
|
|
147
|
+
"description": "背景色由蓝色变为红色",
|
|
148
|
+
"confidence": 0.98,
|
|
149
|
+
"location": {
|
|
150
|
+
"x": 100,
|
|
151
|
+
"y": 200,
|
|
152
|
+
"width": 50,
|
|
153
|
+
"height": 50
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 环境变量配置 (Environment Variables)
|
|
161
|
+
|
|
162
|
+
在 `.env` 文件中配置:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# AI 图片对比服务地址
|
|
166
|
+
PEPSICO_AI_COMPARISON_HOST=https://ai-service.example.com
|
|
167
|
+
|
|
168
|
+
# AI API 密钥
|
|
169
|
+
PEPSICO_AI_COMPARISON_API_KEY=your-api-key-here
|
|
170
|
+
|
|
171
|
+
# 如果未设置上述变量,将回退使用以下变量
|
|
172
|
+
PEPSICO_AI_HOST=https://ai-service.example.com
|
|
173
|
+
PEPSICO_AI_API_KEY=your-api-key-here
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## 使用流程 (Usage Flow)
|
|
177
|
+
|
|
178
|
+
### 自动触发场景 (Automatic Trigger)
|
|
179
|
+
1. 审批单在审核阶段被驳回
|
|
180
|
+
2. 审批单进入 `submitter_revisions` 状态
|
|
181
|
+
3. 提交人修改素材后重新提交
|
|
182
|
+
4. 系统自动触发图片对比(在 `advanceApproval` 时)
|
|
183
|
+
5. 异步处理图片对比任务
|
|
184
|
+
6. 结果存储到数据库
|
|
185
|
+
7. 用户在素材详情页查看对比结果
|
|
186
|
+
|
|
187
|
+
### 手动触发场景 (Manual Trigger)
|
|
188
|
+
可以通过API手动触发图片对比:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
curl -X POST \
|
|
192
|
+
https://your-domain.com/api/pepsico-content/image-comparison/trigger/{approvalId} \
|
|
193
|
+
-H 'Authorization: Bearer YOUR_TOKEN'
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
查询对比状态:
|
|
197
|
+
```bash
|
|
198
|
+
curl -X GET \
|
|
199
|
+
https://your-domain.com/api/pepsico-content/image-comparison/status/{approvalId} \
|
|
200
|
+
-H 'Authorization: Bearer YOUR_TOKEN'
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## 错误处理 (Error Handling)
|
|
204
|
+
|
|
205
|
+
### 常见错误场景
|
|
206
|
+
1. **无历史版本**: 素材没有历史版本,状态标记为 `skipped`
|
|
207
|
+
2. **API 调用失败**: 网络错误或AI服务不可用,状态标记为 `failed`,记录错误信息
|
|
208
|
+
3. **超时**: 60秒超时限制,超时后标记为 `failed`
|
|
209
|
+
4. **数据格式错误**: AI返回数据格式不符合预期,记录错误日志
|
|
210
|
+
|
|
211
|
+
### 日志记录
|
|
212
|
+
- 所有关键操作都有详细日志记录
|
|
213
|
+
- 使用 `ctx.logger` 记录到系统日志
|
|
214
|
+
- 使用 `console.log` 输出到控制台便于开发调试
|
|
215
|
+
|
|
216
|
+
## 性能优化 (Performance Optimization)
|
|
217
|
+
|
|
218
|
+
1. **异步处理**: 图片对比采用异步处理,不阻塞审批流程
|
|
219
|
+
2. **批量处理**: 一次处理审批单中所有图片素材
|
|
220
|
+
3. **错误隔离**: 单个素材对比失败不影响其他素材
|
|
221
|
+
4. **状态跟踪**: 详细记录处理统计信息(总数、成功、跳过、失败)
|
|
222
|
+
|
|
223
|
+
## 测试建议 (Testing Recommendations)
|
|
224
|
+
|
|
225
|
+
### 单元测试
|
|
226
|
+
- 测试图片素材筛选逻辑
|
|
227
|
+
- 测试版本获取逻辑
|
|
228
|
+
- 测试数据准备函数
|
|
229
|
+
|
|
230
|
+
### 集成测试
|
|
231
|
+
- 测试与AI服务的接口调用
|
|
232
|
+
- 测试异步任务执行
|
|
233
|
+
- 测试数据库存储
|
|
234
|
+
|
|
235
|
+
### 端到端测试
|
|
236
|
+
1. 创建审批单并添加图片素材
|
|
237
|
+
2. 提交审批
|
|
238
|
+
3. 驳回审批
|
|
239
|
+
4. 修改图片素材
|
|
240
|
+
5. 重新提交
|
|
241
|
+
6. 验证图片对比自动触发
|
|
242
|
+
7. 在素材详情页验证对比结果展示
|
|
243
|
+
|
|
244
|
+
## 故障排查 (Troubleshooting)
|
|
245
|
+
|
|
246
|
+
### 图片对比未触发
|
|
247
|
+
- 检查审批单是否处于 `submitter_revisions` 步骤
|
|
248
|
+
- 检查是否有图片类型的素材
|
|
249
|
+
- 查看系统日志中的触发记录
|
|
250
|
+
|
|
251
|
+
### 对比失败
|
|
252
|
+
- 检查AI服务地址和API密钥配置
|
|
253
|
+
- 检查网络连接
|
|
254
|
+
- 查看错误日志获取详细错误信息
|
|
255
|
+
- 验证素材版本是否存在
|
|
256
|
+
|
|
257
|
+
### 前端显示异常
|
|
258
|
+
- 检查 `image_comparison_result` 数据格式
|
|
259
|
+
- 验证图片URL是否可访问
|
|
260
|
+
- 检查浏览器控制台错误信息
|
|
261
|
+
|
|
262
|
+
## 未来优化方向 (Future Improvements)
|
|
263
|
+
|
|
264
|
+
1. **重试机制**: 添加自动重试失败的对比任务
|
|
265
|
+
2. **优先级队列**: 根据素材重要性排序处理
|
|
266
|
+
3. **缓存机制**: 缓存对比结果避免重复计算
|
|
267
|
+
4. **增量对比**: 只对修改过的素材进行对比
|
|
268
|
+
5. **多版本对比**: 支持比较更多历史版本
|
|
269
|
+
6. **自定义规则**: 允许配置对比敏感度和关注点
|
|
270
|
+
|
|
271
|
+
## 相关文档 (Related Documentation)
|
|
272
|
+
|
|
273
|
+
- [AI-API-INTEGRATIONS.md](../../../AI-API-INTEGRATIONS.md) - API集成文档
|
|
274
|
+
- [AI-ARCHITECTURE.md](../../../AI-ARCHITECTURE.md) - 架构设计文档
|
|
275
|
+
- [AI-PROJECT-OVERVIEW.md](../../../AI-PROJECT-OVERVIEW.md) - 项目概览
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# 🎨 Image Comparison Feature - Quick Start Guide
|
|
2
|
+
|
|
3
|
+
> Automatic image version comparison for approval workflow resubmissions
|
|
4
|
+
|
|
5
|
+
## 🚀 What Does It Do?
|
|
6
|
+
|
|
7
|
+
When an approval is **rejected** and the submitter **modifies images** before resubmitting:
|
|
8
|
+
1. ✅ System automatically detects the resubmission
|
|
9
|
+
2. ✅ Identifies all image materials in the approval
|
|
10
|
+
3. ✅ Retrieves current and previous versions
|
|
11
|
+
4. ✅ Calls AI service to compare images
|
|
12
|
+
5. ✅ Stores detailed comparison results
|
|
13
|
+
6. ✅ Displays differences in a beautiful UI tab
|
|
14
|
+
|
|
15
|
+
## 📦 Quick Facts
|
|
16
|
+
|
|
17
|
+
- **Supported Formats**: 12+ (JPG, PNG, GIF, BMP, etc.)
|
|
18
|
+
- **Processing**: Async (non-blocking)
|
|
19
|
+
- **Trigger**: Automatic on resubmission
|
|
20
|
+
- **UI Location**: Material detail page → "版本对比" tab
|
|
21
|
+
- **Status Tracking**: Real-time with detailed logs
|
|
22
|
+
|
|
23
|
+
## 🎯 Key Benefits
|
|
24
|
+
|
|
25
|
+
| For | Benefit |
|
|
26
|
+
|-----|---------|
|
|
27
|
+
| 👔 **Reviewers** | See exactly what changed; make better decisions |
|
|
28
|
+
| ✍️ **Submitters** | Verify changes were captured correctly |
|
|
29
|
+
| 🏢 **Business** | Audit trail; reduced manual comparison time |
|
|
30
|
+
| 💻 **System** | Automated, scalable, traceable |
|
|
31
|
+
|
|
32
|
+
## 📁 File Structure
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
steedos-packages/content-review/
|
|
36
|
+
├── src/
|
|
37
|
+
│ ├── methods/
|
|
38
|
+
│ │ └── image_comparison.ts ⭐ Core logic (340 lines)
|
|
39
|
+
│ └── actions/
|
|
40
|
+
│ └── imageComparison.ts 🔌 API endpoints
|
|
41
|
+
├── main/default/
|
|
42
|
+
│ ├── objects/
|
|
43
|
+
│ │ ├── pepsico_material/fields/ 📊 5 new fields
|
|
44
|
+
│ │ └── pepsico_material_approval/fields/ 📊 3 new fields
|
|
45
|
+
│ └── pages/
|
|
46
|
+
│ └── pepsico_material_detail.page.amis.json 🎨 UI tab
|
|
47
|
+
├── public/content-review/
|
|
48
|
+
│ └── amis.css 💅 Styles
|
|
49
|
+
├── test_image_comparison.js 🧪 Tests
|
|
50
|
+
├── IMAGE_COMPARISON_FEATURE.md 📖 Full docs
|
|
51
|
+
└── README (this file) 📄 Quick start
|
|
52
|
+
|
|
53
|
+
Root directory:
|
|
54
|
+
├── IMAGE_COMPARISON_IMPLEMENTATION.md 📋 Summary
|
|
55
|
+
└── IMAGE_COMPARISON_ARCHITECTURE_DIAGRAMS.md 📐 Diagrams
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## ⚙️ Setup (3 Steps)
|
|
59
|
+
|
|
60
|
+
### 1. Configure Environment
|
|
61
|
+
Add to `.env`:
|
|
62
|
+
```bash
|
|
63
|
+
PEPSICO_AI_COMPARISON_HOST=https://your-ai-service.com
|
|
64
|
+
PEPSICO_AI_COMPARISON_API_KEY=your-secret-key
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. Build & Deploy
|
|
68
|
+
```bash
|
|
69
|
+
cd steedos-packages/content-review
|
|
70
|
+
npm run build
|
|
71
|
+
# Deploy to your environment
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. Test
|
|
75
|
+
```bash
|
|
76
|
+
node test_image_comparison.js
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 🔧 API Endpoints
|
|
80
|
+
|
|
81
|
+
### Trigger Comparison (Manual)
|
|
82
|
+
```bash
|
|
83
|
+
POST /api/pepsico-content/image-comparison/trigger/:approvalId
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Check Status
|
|
87
|
+
```bash
|
|
88
|
+
GET /api/pepsico-content/image-comparison/status/:approvalId
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 🎓 How to Use
|
|
92
|
+
|
|
93
|
+
### Automatic Flow
|
|
94
|
+
1. Create approval with images
|
|
95
|
+
2. Submit → gets rejected
|
|
96
|
+
3. Modify images
|
|
97
|
+
4. Resubmit → **comparison auto-triggers** 🎯
|
|
98
|
+
5. View results in "版本对比" tab
|
|
99
|
+
|
|
100
|
+
### Manual Trigger (for testing)
|
|
101
|
+
```bash
|
|
102
|
+
curl -X POST \
|
|
103
|
+
http://localhost:5000/api/pepsico-content/image-comparison/trigger/{approvalId}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 📊 Database Fields
|
|
107
|
+
|
|
108
|
+
### On `pepsico_material`
|
|
109
|
+
- `image_comparison_status` - Status: pending/completed/skipped/failed
|
|
110
|
+
- `image_comparison_result` - Full comparison data (JSON)
|
|
111
|
+
- `image_comparison_at` - Timestamp
|
|
112
|
+
- `image_comparison_reason` - Why skipped (if applicable)
|
|
113
|
+
- `image_comparison_error` - Error details (if failed)
|
|
114
|
+
|
|
115
|
+
### On `pepsico_material_approval`
|
|
116
|
+
- `image_comparison_status` - Batch status
|
|
117
|
+
- `image_comparison_stats` - Statistics: {total, processed, skipped, failed}
|
|
118
|
+
- `image_comparison_at` - Timestamp
|
|
119
|
+
|
|
120
|
+
## 🎨 UI Features
|
|
121
|
+
|
|
122
|
+
The "版本对比" tab shows:
|
|
123
|
+
- ✅ Status badge (with color coding)
|
|
124
|
+
- ✅ Comparison timestamp
|
|
125
|
+
- ✅ Side-by-side images (previous vs current)
|
|
126
|
+
- ✅ Diff image with marked differences
|
|
127
|
+
- ✅ Detailed difference table
|
|
128
|
+
- ✅ Similarity score percentage
|
|
129
|
+
- ✅ Error/skip reasons (if applicable)
|
|
130
|
+
|
|
131
|
+
## 🐛 Troubleshooting
|
|
132
|
+
|
|
133
|
+
### Comparison not triggering?
|
|
134
|
+
- Check: Is approval in `submitter_revisions` step?
|
|
135
|
+
- Check: Are there image materials?
|
|
136
|
+
- Check: View logs for trigger message
|
|
137
|
+
|
|
138
|
+
### Comparison failed?
|
|
139
|
+
- Check: AI service URL and API key
|
|
140
|
+
- Check: Network connectivity
|
|
141
|
+
- Check: Error field on material record
|
|
142
|
+
- Check: System logs for details
|
|
143
|
+
|
|
144
|
+
### UI not showing?
|
|
145
|
+
- Check: Is material an image type?
|
|
146
|
+
- Check: Does `image_comparison_status` exist?
|
|
147
|
+
- Refresh page and clear cache
|
|
148
|
+
|
|
149
|
+
## 📚 Documentation
|
|
150
|
+
|
|
151
|
+
| Document | Purpose |
|
|
152
|
+
|----------|---------|
|
|
153
|
+
| [IMAGE_COMPARISON_FEATURE.md](./IMAGE_COMPARISON_FEATURE.md) | Complete feature guide |
|
|
154
|
+
| [IMAGE_COMPARISON_IMPLEMENTATION.md](../../IMAGE_COMPARISON_IMPLEMENTATION.md) | Implementation summary |
|
|
155
|
+
| [IMAGE_COMPARISON_ARCHITECTURE_DIAGRAMS.md](../../IMAGE_COMPARISON_ARCHITECTURE_DIAGRAMS.md) | Visual diagrams |
|
|
156
|
+
|
|
157
|
+
## 🧪 Testing
|
|
158
|
+
|
|
159
|
+
Run the test suite:
|
|
160
|
+
```bash
|
|
161
|
+
cd steedos-packages/content-review
|
|
162
|
+
node test_image_comparison.js
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Expected output:
|
|
166
|
+
```
|
|
167
|
+
✓ Modified submission detection: PASS
|
|
168
|
+
✓ Image material filtering: PASS
|
|
169
|
+
✓ Version retrieval: PASS
|
|
170
|
+
✓ Data preparation: PASS
|
|
171
|
+
All tests passed!
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## 🔍 Code Examples
|
|
175
|
+
|
|
176
|
+
### Import and Use
|
|
177
|
+
```typescript
|
|
178
|
+
import {
|
|
179
|
+
getImageMaterials,
|
|
180
|
+
processBulkImageComparison,
|
|
181
|
+
triggerImageComparisonAsync
|
|
182
|
+
} from './methods/image_comparison';
|
|
183
|
+
|
|
184
|
+
// Get all image materials in an approval
|
|
185
|
+
const images = await getImageMaterials(ctx, approvalId);
|
|
186
|
+
|
|
187
|
+
// Process all images (sync)
|
|
188
|
+
const result = await processBulkImageComparison(ctx, approvalId);
|
|
189
|
+
|
|
190
|
+
// Trigger async (recommended)
|
|
191
|
+
await triggerImageComparisonAsync(ctx, approvalId);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Check Results
|
|
195
|
+
```typescript
|
|
196
|
+
const material = await ctx.getObject('pepsico_material').findOne(materialId);
|
|
197
|
+
|
|
198
|
+
if (material.image_comparison_status === 'completed') {
|
|
199
|
+
const result = material.image_comparison_result;
|
|
200
|
+
console.log('Similarity:', result.similarity_score);
|
|
201
|
+
console.log('Differences:', result.differences);
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## 🎯 Status Meanings
|
|
206
|
+
|
|
207
|
+
| Status | Meaning |
|
|
208
|
+
|--------|---------|
|
|
209
|
+
| `pending` | Comparison queued or in progress |
|
|
210
|
+
| `completed` | Successfully compared |
|
|
211
|
+
| `skipped` | No previous version to compare |
|
|
212
|
+
| `failed` | Error during comparison |
|
|
213
|
+
| `partial` | Some materials succeeded, some failed (batch only) |
|
|
214
|
+
|
|
215
|
+
## 🚦 Next Steps
|
|
216
|
+
|
|
217
|
+
1. ✅ Code is complete and committed
|
|
218
|
+
2. ⏳ Deploy AI comparison service
|
|
219
|
+
3. ⏳ Configure environment variables
|
|
220
|
+
4. ⏳ Test in staging
|
|
221
|
+
5. ⏳ User acceptance testing
|
|
222
|
+
6. ⏳ Production deployment
|
|
223
|
+
7. ⏳ Monitor and optimize
|
|
224
|
+
|
|
225
|
+
## 💡 Tips
|
|
226
|
+
|
|
227
|
+
- **Performance**: Async processing means no workflow delay
|
|
228
|
+
- **Scalability**: Can handle many images in one approval
|
|
229
|
+
- **Reliability**: Individual failures don't affect others
|
|
230
|
+
- **Debugging**: Check logs with approval/material IDs
|
|
231
|
+
- **Recovery**: Use manual trigger API if needed
|
|
232
|
+
|
|
233
|
+
## 🆘 Support
|
|
234
|
+
|
|
235
|
+
Need help? Check:
|
|
236
|
+
1. System logs with approval/material ID
|
|
237
|
+
2. Material record's error fields
|
|
238
|
+
3. AI service health status
|
|
239
|
+
4. Network connectivity
|
|
240
|
+
5. Documentation files above
|
|
241
|
+
|
|
242
|
+
## 📝 License
|
|
243
|
+
|
|
244
|
+
Part of Steedos PepsiCo Content Review System
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
**Version**: 1.0.0
|
|
249
|
+
**Last Updated**: 2026-02-05
|
|
250
|
+
**Status**: ✅ Production Ready (pending AI service)
|