From ce420a54a7309d786b9129847c3842256d196442 Mon Sep 17 00:00:00 2001 From: lmk <1095689763@qq.com> Date: Thu, 21 May 2026 11:21:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YIDUN_API_DOCUMENTATION.md | 1131 ----------------- consts/app/application_status.go | 13 - consts/app/application_type.go | 17 - consts/data/api_method.go | 18 - consts/data/fetch_status.go | 16 - consts/data/limit_type.go | 14 - consts/data/platform_status.go | 13 - consts/data/platform_type.go | 21 - consts/mapping/mapping_status.go | 13 - consts/mapping/transform_type.go | 16 - controller/app/application_controller.go | 47 - controller/data/api_interface_controller.go | 47 - controller/data/data_fetch_controller.go | 37 - controller/data/platform_controller.go | 47 - controller/mapping/data_mapping_controller.go | 51 - dao/app/application_dao.go | 117 -- dao/data/api_interface_dao.go | 118 -- dao/data/data_fetch_log_dao.go | 135 -- dao/data/platform_dao.go | 115 -- dao/mapping/data_mapping_dao.go | 138 -- main.go | 13 +- model/dto/app/application_dto.go | 95 -- model/dto/data/api_interface_dto.go | 102 -- model/dto/data/data_fetch_dto.go | 99 -- model/dto/data/platform_dto.go | 91 -- model/dto/mapping/data_mapping_dto.go | 125 -- model/entity/app/application.go | 49 - model/entity/data/api_interface.go | 56 - model/entity/data/data_fetch_log.go | 58 - model/entity/data/platform.go | 46 - model/entity/mapping/data_mapping.go | 52 - service/app/application_service.go | 178 --- service/data/api_interface_service.go | 191 --- service/data/data_fetch_service.go | 316 ----- service/data/platform_service.go | 189 --- service/mapping/data_mapping_service.go | 306 ----- update.sql | 129 -- 37 files changed, 2 insertions(+), 4217 deletions(-) delete mode 100644 YIDUN_API_DOCUMENTATION.md delete mode 100644 consts/app/application_status.go delete mode 100644 consts/app/application_type.go delete mode 100644 consts/data/api_method.go delete mode 100644 consts/data/fetch_status.go delete mode 100644 consts/data/limit_type.go delete mode 100644 consts/data/platform_status.go delete mode 100644 consts/data/platform_type.go delete mode 100644 consts/mapping/mapping_status.go delete mode 100644 consts/mapping/transform_type.go delete mode 100644 controller/app/application_controller.go delete mode 100644 controller/data/api_interface_controller.go delete mode 100644 controller/data/data_fetch_controller.go delete mode 100644 controller/data/platform_controller.go delete mode 100644 controller/mapping/data_mapping_controller.go delete mode 100644 dao/app/application_dao.go delete mode 100644 dao/data/api_interface_dao.go delete mode 100644 dao/data/data_fetch_log_dao.go delete mode 100644 dao/data/platform_dao.go delete mode 100644 dao/mapping/data_mapping_dao.go delete mode 100644 model/dto/app/application_dto.go delete mode 100644 model/dto/data/api_interface_dto.go delete mode 100644 model/dto/data/data_fetch_dto.go delete mode 100644 model/dto/data/platform_dto.go delete mode 100644 model/dto/mapping/data_mapping_dto.go delete mode 100644 model/entity/app/application.go delete mode 100644 model/entity/data/api_interface.go delete mode 100644 model/entity/data/data_fetch_log.go delete mode 100644 model/entity/data/platform.go delete mode 100644 model/entity/mapping/data_mapping.go delete mode 100644 service/app/application_service.go delete mode 100644 service/data/api_interface_service.go delete mode 100644 service/data/data_fetch_service.go delete mode 100644 service/data/platform_service.go delete mode 100644 service/mapping/data_mapping_service.go delete mode 100644 update.sql diff --git a/YIDUN_API_DOCUMENTATION.md b/YIDUN_API_DOCUMENTATION.md deleted file mode 100644 index 8a64eab..0000000 --- a/YIDUN_API_DOCUMENTATION.md +++ /dev/null @@ -1,1131 +0,0 @@ -# 易盾内容安全 API 调用文档 - -## 📋 目录 - -- [概述](#概述) -- [配置说明](#配置说明) -- [模式切换](#模式切换) -- [API接口列表](#api接口列表) -- [文本检测](#1-文本检测) -- [图片检测](#2-图片检测) -- [视频检测](#3-视频检测) -- [回调与轮询接口](#回调与轮询接口) -- [错误码说明](#错误码说明) -- [常见问题](#常见问题) - ---- - -## 概述 - -本项目集成了网易易盾内容安全SDK,提供文本、图片、视频的内容安全检测服务。 - -### 产品凭证 - -| 检测类型 | SecretID | SecretKey | BusinessID | -|---------|----------|-----------|------------| -| **音视频检测** | f58a38341ca6227014df7c3bf0e6f16f | 526aa631ba5d518aedeb70b5a3b67371 | 需从易盾控制台获取 | -| **图片检测** | 9a82f90bfec61eb40d1c95605b894817 | f73a78954417a3713c36ec2d14eb2b5f | 需从易盾控制台获取 | -| **文本检测** | 待配置 | 待配置 | 待配置 | - -### 服务地址 - -``` -http://localhost:3001 -``` - ---- - -## 配置说明 - -配置文件位置:`config.yml` - -```yaml -yidun: - # 回调模式开关: true=使用回调模式(需要公网地址), false=使用轮询模式 - callback_mode: false - - # 视频检测配置 - video: - secret_id: "f58a38341ca6227014df7c3bf0e6f16f" - secret_key: "526aa631ba5d518aedeb70b5a3b67371" - callback_url: "http://your-domain.com:3001/yidun/callback/receiveVideo" - - # 图片检测配置 - image: - business_id: "your_image_business_id" - secret_id: "9a82f90bfec61eb40d1c95605b894817" - secret_key: "f73a78954417a3713c36ec2d14eb2b5f" - callback_url: "http://your-domain.com:3001/yidun/callback/receiveImage" - - # 文本检测配置 - text: - business_id: "YOUR_TEXT_BUSINESS_ID" - secret_id: "YOUR_TEXT_SECRET_ID" - secret_key: "YOUR_TEXT_SECRET_KEY" - -# 内容送检定时任务配置 -content_check: - batch_size: 10 # 每批处理数量 - image_enabled: true # 是否启用图片检测 - video_enabled: true # 是否启用视频检测 - interval_seconds: 30 # 定时任务执行间隔(秒) -``` - ---- - -## 模式切换 - -### 轮询模式(无公网地址) - -适用于开发测试环境或没有公网地址的场景。 - -```yaml -yidun: - callback_mode: false # 使用轮询模式 -``` - -**工作流程**: -``` -定时任务 → 提交检测 → 保存taskId → 手动轮询 → 获取结果 → 更新状态 -``` - -### 回调模式(有公网地址) - -适用于生产环境,需要配置公网可访问的回调地址。 - -```yaml -yidun: - callback_mode: true # 使用回调模式 - image: - callback_url: "http://your-public-domain.com:3001/yidun/callback/receiveImage" - video: - callback_url: "http://your-public-domain.com:3001/yidun/callback/receiveVideo" -``` - -**工作流程**: -``` -定时任务 → 提交检测 → 易盾检测完成 → 易盾推送结果 → 自动更新状态 -``` - ---- - -## API接口列表 - -### 送检接口 - -| 接口名称 | 请求方法 | 路径 | 说明 | -|---------|---------|------|------| -| 文本检测提交 | POST | `/yidun/detect-text` | 提交文本进行异步检测 | -| 图片检测提交 | POST | `/yidun/detect-image` | 提交图片进行异步检测 | -| 视频检测提交 | POST | `/yidun/detect-video` | 提交视频进行检测 | - -### 回调模式接口 - -| 接口名称 | 请求方法 | 路径 | 说明 | -|---------|---------|------|------| -| 接收图片回调 | POST | `/yidun/callback/receiveImage` | 接收易盾图片检测结果推送 | -| 接收视频回调 | POST | `/yidun/callback/receiveVideo` | 接收易盾视频检测结果推送 | - -### 轮询模式接口 - -| 接口名称 | 请求方法 | 路径 | 说明 | -|---------|---------|------|------| -| 轮询所有结果 | POST | `/yidun/callback/poll` | 轮询所有待处理结果(图片+视频) | -| 轮询图片结果 | POST | `/yidun/callback/pollImage` | 仅轮询图片待处理结果 | -| 轮询视频结果 | POST | `/yidun/callback/pollVideo` | 仅轮询视频待处理结果 | -| 查询单个结果 | POST | `/yidun/callback/pollTask` | 根据taskId查询单个结果 | -| 获取待处理数量 | GET | `/yidun/callback/pendingCount` | 查看待处理结果数量 | - -**注意**:检测结果是异步的,提交接口只返回 `task_id`,需要通过回调或轮询获取结果。 - ---- - -## 1. 文本检测 - -### 提交文本检测任务 - -**接口地址**: `POST /yidun/detect-text` - -**请求参数**: - -| 参数名 | 类型 | 必填 | 说明 | -|--------|------|------|------| -| data_id | string | 是 | 数据唯一标识 | -| content | string | 是 | 待检测的文本内容 | -| ip | string | 否 | 用户IP地址 | -| token | string | 否 | 用户token(反作弊) | - -**请求示例**: - -```bash -curl -X POST http://localhost:3002/yidun/detect-text \ - -H "Content-Type: application/json" \ - -d '{ - "data_id": "text-001", - "content": "这是一段需要检测的文本内容", - "ip": "192.168.1.100" - }' -``` - -**响应示例**: - -```json -{ - "code": 0, - "message": "", - "data": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6" -} -``` - -**响应说明**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| data | string | 任务ID (task_id),用于后续查询检测结果 | - ---- - -## 2. 图片检测 - -### 2.1 提交图片检测任务 - -**接口地址**: `POST /yidun/detect-image` - -**请求参数**: - -| 参数名 | 类型 | 必填 | 说明 | -|--------|------|------|------| -| data_id | string | 是 | 数据唯一标识 | -| image_url | string | 是 | 图片URL地址 | -| callback_url | string | 否 | 回调地址 | - -**请求示例**: - -```bash -curl -X POST http://localhost:3002/yidun/detect-image \ - -H "Content-Type: application/json" \ - -d '{ - "data_id": "img-001", - "image_url": "https://example.com/image.jpg" - }' -``` - -**响应示例**: - -```json -{ - "code": 0, - "message": "", - "data": { - "taskId": "b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7", - "name": "img-001", - "dataId": "img-001", - "dealingCount": 0 - } -} -``` - -**响应说明**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| taskId | string | 任务ID,用于后续查询检测结果 | -| name | string | 图片唯一标识 | -| dataId | string | 客户图片唯一标识 | -| dealingCount | int64 | 缓冲池排队待处理数据量 | - -### 2.2 查询图片检测结果(轮询模式) - -**接口地址**: `POST /yidun/GetImageResult` - -**SDK调用信息**: -- SDK方法: `ImageClient.ImageCallback(request)` -- 请求地址: `http://as.dun.163.com/v5/image/callback/results` -- 请求参数: `yidunRequestId` (taskId) - -**请求示例**: - -```bash -curl -X POST "http://localhost:3002/yidun/GetImageResult" \ - -H "Content-Type: application/json" \ - -d '{"taskId": "b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7"}' -``` - -**响应示例**: - -```json -{ - "code": 0, - "message": "", - "data": { - "taskId": "b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7", - "status": 2, - "suggestion": 0, - "label": 100, - "resultType": 2, - "dataId": "img-001", - "name": "img-001", - "censorTime": 1629426386079, - "url": "https://example.com/image.jpg", - "antispam": { - "taskId": "b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7", - "name": "img-001", - "dataId": "img-001", - "status": 2, - "suggestion": 0, - "label": 100, - "resultType": 2, - "censorTime": 1629426386079, - "censorSource": 0, - "censorRound": 1, - "labels": [ - { - "label": 400, - "level": 2, - "rate": 1.0 - } - ], - "censorLabels": [ - { - "code": "审核标签编码", - "customCode": "自定义标签编码", - "name": "审核标签名称", - "desc": "风景" - } - ], - "remark": "人审备注信息" - }, - "ocr": { ... }, - "face": { ... }, - "quality": { ... }, - "logo": { ... }, - "discern": { ... }, - "ad": { ... }, - "userRisk": { ... }, - "anticheat": { ... }, - "riskControl": { ... }, - "aigc": { ... }, - "llmCheckInfo": [ ... ] - } -} -``` - -**antispam 字段完整说明**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| taskId | string | 任务ID | -| name | string | 图片名称 | -| dataId | string | 客户数据ID | -| status | int | 检测状态:0=未开始,1=检测中,2=检测成功,3=检测失败 | -| suggestion | int | 处置建议:0=通过,1=嫌疑,2=不通过 | -| label | int | 一级分类 | -| secondLabel | string | 二级分类 | -| thirdLabel | string | 三级分类 | -| riskDescription | string | 风险描述 | -| resultType | int | 结果类型:1=机器结果,2=人审结果 | -| censorTime | int64 | 审核完成时间(毫秒时间戳) | -| censorSource | int | 审核来源 | -| censorRound | int | 审核轮数 | -| censorLabels | array | 审核标签数组 | -| remark | string | 审核备注 | -| overAllMarkDesc | string | 整体审核备注 | -| detailMarks | array | 细节标注 | -| labels | array | 分类标签详情 | -| url | string | 图片URL | -| imgMd5 | string | 图片MD5 | -| frameSize | int | 分帧数 | -| customLabels | array | 客户自定义标签 | -| censorExtension | object | 人审拓展字段 | -| strategyVersions | array | 策略版本 | -| hitType | int | 命中策略类型 | -| strategyType | int | 策略类型:1=公有策略,2=私有策略 | -| hitResult | string | 命中结果 | -| hitSource | int | 特征添加来源 | -| hidden | bool | 是否有隐藏文件 | -| hiddenFormat | string | 隐藏文件格式 | -| publicOpinionInfo | string | 舆情信息 | - -**labels 数组结构**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| label | int | 标签类型 | -| level | int | 判断结果:0=正常,1=不确定,2=确定 | -| rate | float | 置信度 | -| subLabels | array | 二级分类详情 | -| explain | string | LLM解释说明 | -| isLlmCheck | bool | 是否LLM检测命中 | - -**censorLabels 数组结构**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| code | string | 审核标签编码 | -| customCode | string | 自定义标签编码 | -| name | string | 审核标签名称 | -| desc | string | 审核标签描述 | -| parentLabelId | string | 父标签ID | -| depth | int | 标签深度 | - -### 2.3 接收图片检测回调(推送模式) - -**接口地址**: `POST /yidun/receive-image-callback` - -**易盾回调配置**: -- HTTP URL: 回调地址 `callbackUrl` -- HTTP Method: POST -- Content-Type: application/x-www-form-urlencoded - -**请求参数** (form-data): - -| 参数名 | 类型 | 必填 | 说明 | -|--------|------|------|------| -| secretId | string | 是 | 产品密钥ID | -| businessId | string | 是 | 业务ID | -| signature | string | 是 | 请求签名 | -| callbackData | string | 是 | 回调数据(JSON字符串) | - -**请求体示例**: - -``` -callbackData={"antispam":{...}}&signature=xxx&secretId=xxx&businessId=xxx -``` - -**回调数据格式**: - -```json -{ - "antispam": { - "taskId": "a2e53718f9c348d09206e4671304ca7c", - "suggestion": 2, - "remark": "人审备注信息,填写才会返回", - "dataId": "dataId", - "name": "name", - "labels": [ - { - "label": 400, - "level": 2, - "rate": 1.0 - }, - { - "label": 500, - "level": 0, - "rate": 1.0 - } - ], - "censorLabels": [ - { - "code": "审核标签编码", - "customCode": "自定义标签编码", - "name": "审核标签名称", - "desc": "风景" - } - ], - "resultType": 2, - "censorTime": 1622036595467, - "censorSource": 0, - "censorRound": 1 - } -} -``` - -**Suggestion值说明**: - -| 值 | 含义 | -|----|------| -| 0 | 通过 | -| 1 | 嫌疑,需人工审核 | -| 2 | 不通过 | - -**Status值说明**: - -| 值 | 含义 | -|----|------| -| 0 | 未开始 | -| 1 | 检测中 | -| 2 | 检测成功 | -| 3 | 检测失败 | - ---- - -## 3. 视频检测 - -### 提交视频检测任务 - -**接口地址**: `POST /yidun/detect-video` - -**请求参数**: - -| 参数名 | 类型 | 必填 | 说明 | -|--------|------|------|------| -| data_id | string | 是 | 数据唯一标识 | -| video_url | string | 是 | 视频URL地址 | -| callback_url | string | 否 | 回调地址 | - -**请求示例**: - -```bash -curl -X POST http://localhost:3002/yidun/detect-video \ - -H "Content-Type: application/json" \ - -d '{ - "data_id": "video-001", - "video_url": "https://example.com/video.mp4" - }' -``` - -**响应示例**: - -```json -{ - "code": 0, - "message": "", - "data": { - "taskId": "c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8", - "dataId": "video-001", - "dealingCount": 0 - } -} -``` - -**响应说明**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| taskId | string | 任务ID,用于后续查询检测结果 | -| dataId | string | 调用检测时传递的数据ID | -| dealingCount | int64 | 缓冲池排队待处理数据量 | - -**注意**: 视频检测是异步的,检测时间取决于视频长度(几分钟到几十分钟)。建议配置回调地址接收结果。 - -### 3.2 查询视频检测结果(轮询模式) - -**接口地址**: `POST /yidun/GetVideoResult` - -**SDK调用信息**: -- SDK方法: `VideoClient.Callback(request)` -- 请求地址: `http://as.dun.163.com/v2/videosolution/callback/results` -- 请求参数: `yidunRequestId` (taskId) - -**请求示例**: - -```bash -curl -X POST "http://localhost:3002/yidun/GetVideoResult" \ - -H "Content-Type: application/json" \ - -d '{"taskId": "c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8"}' -``` - -**响应示例**: - -```json -{ - "code": 0, - "message": "", - "data": { - "taskId": "18xrunm6fr35t49nnv506ukg02009q66", - "status": 2, - "suggestion": 2, - "label": 100, - "resultType": 1, - "dataId": "video-001", - "censorTime": 1633759853762, - "duration": 71339, - "antispam": { - "taskId": "18xrunm6fr35t49nnv506ukg02009q66", - "suggestion": 2, - "status": 2, - "resultType": 1, - "censorSource": 2, - "checkTime": 1633759861164, - "censorTime": 1633759853762, - "duration": 71339, - "censorLabels": [ - { - "code": "101", - "desc": "自定义标签", - "customCode": "68684" - } - ], - "evidences": { - "images": [...], - "text": {...}, - "audio": {...}, - "video": {...} - } - }, - "language": { ... }, - "voice": { ... }, - "asr": { ... }, - "ocr": { ... }, - "discern": { ... }, - "logo": { ... }, - "face": { ... }, - "aigc": { ... }, - "quality": { ... } - } -} -``` - -**antispam 字段完整说明**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| taskId | string | 任务ID | -| dataId | string | 客户数据ID | -| callback | string | 回调参数 | -| suggestion | int | 处置建议:0=通过,1=嫌疑,2=不通过 | -| status | int | 检测状态:0=未开始,1=检测中,2=检测成功,3=检测失败 | -| resultType | int | 结果类型:1=机器结果,2=人审结果 | -| censorRound | int | 人审轮次 | -| censor | string | 人审操作人 | -| censorSource | int | 审核来源:0=易盾人审,1=客户人审,2=易盾机审 | -| checkTime | int64 | 机器检测结束时间 | -| censorTime | int64 | 人工审核完成时间 | -| duration | int64 | 音视频时长(毫秒) | -| durationMs | int64 | 音频时长(毫秒) | -| label | int | 一级垃圾类型 | -| secondLabel | string | 二级垃圾类型 | -| thirdLabel | string | 三级垃圾类型 | -| riskDescription | string | 风险描述 | -| picCount | int64 | 截图数量 | -| censorLabels | array | 审核标签数组 | -| censorExtension | object | 质检扩展结果 | -| evidences | object | 机器检测证据信息 | -| solutionExtra | object | 额外信息 | -| reviewEvidences | object | 人审证据信息 | - -**evidences 对象说明**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| text | object | 文本证据(标题、简介等) | -| images | array | 图片证据(封面、截图中的图片) | -| audio | object | 音频证据(人声内容) | -| video | object | 视频证据(视频画面) | - -**CensorSource值说明**: - -| 值 | 含义 | -|----|------| -| 0 | 易盾人审 | -| 1 | 客户人审 | -| 2 | 易盾机审 | - -### 3.3 接收视频检测回调(推送模式) - -**接口地址**: `POST /yidun/receive-video-callback` - -**易盾回调配置**: -- HTTP URL: 回调地址 `callbackUrl` -- HTTP Method: POST -- Content-Type: application/x-www-form-urlencoded - -**请求参数** (form-data): - -| 参数名 | 类型 | 必填 | 说明 | -|--------|------|------|------| -| secretId | string | 是 | 产品密钥ID | -| signature | string | 是 | 请求签名 | -| callbackData | string | 是 | 回调数据(JSON字符串) | - -**请求体示例**: - -``` -callbackData={"antispam":{...}}&signature=xxx&secretId=xxx -``` - -**回调数据格式**: - -```json -{ - "antispam": { - "taskId": "18xrunm6fr35t49nnv506ukg02009q66", - "suggestion": 2, - "status": 2, - "resultType": 1, - "censorSource": 2, - "checkTime": 1633759861164, - "censorTime": 1633759853762, - "duration": 71339, - "censorLabels": [ - { - "code": "101", - "desc": "自定义标签", - "customCode": "68684" - } - ], - "evidences": { - "images": [ - { - "censorType": 0, - "labels": [ - { - "label": 100, - "level": 2, - "rate": 0.9999, - "subLabels": [ - { - "details": { - "hitInfos": [ - { - "group": "色情部位分组", - "value": "女胸" - } - ] - }, - "rate": 1, - "subLabel": 10002 - } - ] - } - ], - "name": "gpqis0e92czvfliemjpa3neg02009q6a", - "resultType": 1, - "status": 2, - "suggestion": 2, - "taskId": "0b2dd0e561a8457fbfcf7d79378eec37" - } - ], - "text": { - "taskId": "44i3effo1j5w5for9l8xtdjg02009q6a", - "suggestion": 2, - "resultType": 1, - "censorType": 0, - "isRelatedHit": false, - "labels": [ - { - "label": 200, - "level": 2, - "subLabels": [ - { - "subLabel": "200009", - "details": { - "hitInfos": [ - { - "value": "加我", - "positions": [ - { - "fieldName": "content", - "startPos": 5, - "endPos": 8 - } - ] - } - ] - } - } - ] - } - ] - }, - "audio": { - "taskId": "18xrunm6fr35t49nnv506ukg02009q66", - "dataId": "", - "status": 2, - "suggestion": 2, - "label": 100, - "resultType": 1, - "callback": "", - "censorSource": 2, - "censorTime": 1633759861065, - "segments": [ - { - "startTime": 0, - "endTime": 6, - "content": "第一次用这个软件上了半天,全是长得漂亮呢?", - "type": 0, - "labels": [ - { - "label": 100, - "level": 2, - "subLabels": [ - { - "subLabel": "100001", - "details": { - "hitInfos": [ - { - "value": "120", - "startTime": 1684201, - "endTime": 1684201 - } - ], - "keywords": [ - { - "word": "自定义敏感词" - } - ], - "libInfos": [ - { - "listType": 1, - "entity": "127.0.0.1" - } - ] - } - } - ] - } - ] - } - ], - "duration": 71 - }, - "video": { - "taskId": "18xrunm6fr35t49nnv506ukg02009q66", - "dataId": "", - "status": 2, - "suggestion": 2, - "resultType": 1, - "censorSource": 2, - "censorTime": 1633759858920, - "pictures": [ - { - "type": 1, - "url": "https://xxx.nosdn.127.net/xxx.jpg", - "startTime": 5000, - "endTime": 5000, - "labels": [ - { - "label": 100, - "level": 2, - "rate": 0.95157, - "subLabels": [ - { - "subLabel": 10007, - "rate": 0.926, - "details": { - "hitInfos": [ - { - "value": "卡通色情", - "group": "色情部位分组" - } - ] - } - } - ] - } - ], - "censorSource": 2, - "frontPics": [ - { - "url": "https://xxx.nosdn.127.net/xxx_0_0.jpg" - } - ], - "backPics": [ - { - "url": "https://xxx.nosdn.127.net/xxx_2_10000.jpg" - } - ] - } - ] - } - } - } -} -``` - -**Suggestion值说明**: - -| 值 | 含义 | -|----|------| -| 0 | 通过 | -| 1 | 嫌疑,需人工审核 | -| 2 | 不通过 | - -**Status值说明**: - -| 值 | 含义 | -|----|------| -| 0 | 未开始 | -| 1 | 检测中 | -| 2 | 检测成功 | -| 3 | 检测失败 | - -**images/images.labels 结构说明**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| label | int | 标签类型 | -| level | int | 级别:0=正常,1=嫌疑,2=确定违规 | -| rate | float | 置信度 | -| subLabels | array | 二级分类详情 | -| subLabels.details.hitInfos | array | 命中信息 | -| subLabels.details.hitInfos.group | string | 分组名称 | -| subLabels.details.hitInfos.value | string | 命中值 | - -**audio.segments 结构说明**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| startTime | int | 开始时间(秒) | -| endTime | int | 结束时间(秒) | -| content | string | 语音识别原文 | -| type | int | 片段类型:0=语音识别,1=声纹检测 | -| labels | array | 分类标签 | -| labels.details.keywords | array | 自定义敏感词 | -| labels.details.libInfos | array | 自定义名单 | -| labels.details.hitInfos | array | 命中内容 | - -**video.pictures 结构说明**: - -| 字段名 | 类型 | 说明 | -|--------|------|------| -| type | int | 截图类型 | -| url | string | 截图URL | -| startTime | int64 | 开始时间(毫秒) | -| endTime | int64 | 结束时间(毫秒) | -| labels | array | 分类标签 | -| frontPics | array | 关联前帧图片 | -| backPics | array | 关联后帧图片 | - ---- - -## 回调与轮询接口 - -### 轮询模式接口详解 - -#### 轮询所有待处理结果 - -``` -POST /yidun/callback/poll -``` - -**说明**:轮询所有图片和视频的待处理检测结果 - -**响应示例**: -```json -{ - "code": 200, - "msg": "轮询完成,成功处理 5 条,失败 1 条", - "data": { - "success_count": 5, - "fail_count": 1, - "pending_count": 10 - } -} -``` - -#### 获取待处理数量 - -``` -GET /yidun/callback/pendingCount -``` - -**响应示例**: -```json -{ - "code": 200, - "data": { - "pending_count": 15, - "description": "待查询结果的日志数量(状态为pending且有taskID)" - } -} -``` - -#### 查询单个结果 - -``` -POST /yidun/callback/pollTask?taskId=xxx&type=image -``` - -**参数说明**: - -| 参数 | 类型 | 必填 | 说明 | -|------|------|------|------| -| taskId | string | 是 | 易盾任务ID | -| type | string | 否 | 类型:`image`/`video`,不填则自动识别 | - -**响应示例**: -```json -{ - "code": 200, - "msg": "查询并处理成功" -} -``` - ---- - -## 使用示例 - -### 轮询模式使用流程 - -```bash -# 1. 查看待处理数量 -curl http://localhost:3001/yidun/callback/pendingCount - -# 2. 执行轮询(所有) -curl -X POST http://localhost:3001/yidun/callback/poll - -# 3. 或分别轮询 -curl -X POST http://localhost:3001/yidun/callback/pollImage -curl -X POST http://localhost:3001/yidun/callback/pollVideo - -# 4. 查询单个结果 -curl -X POST "http://localhost:3001/yidun/callback/pollTask?taskId=abc123&type=image" -``` - -### 配置定时轮询 - -```bash -# 每分钟轮询一次 -*/1 * * * * curl -X POST http://localhost:3001/yidun/callback/poll - -# 或更保守的频率(每5分钟) -*/5 * * * * curl -X POST http://localhost:3001/yidun/callback/poll -``` - ---- - -## 状态说明 - -### 检测状态转换 - -``` -┌─────────────────────────────────────────────────────────────┐ -│ 送检前 │ -│ tencent_image/tencent_video: status = "pending" │ -└─────────────────────────────────────────────────────────────┘ - ↓ - ↓ 定时任务/手动送检 - ↓ -┌─────────────────────────────────────────────────────────────┐ -│ 提交检测 │ -│ material_verify_log: verify_status = "PENDING" │ -│ material_verify_log: task_id = "易盾任务ID" │ -│ tencent_xxx: status = "submitting" │ -└─────────────────────────────────────────────────────────────┘ - ↓ - ↓ 等待检测完成 - ↓ (回调模式)或(轮询查询) - ↓ -┌─────────────────────────────────────────────────────────────┐ -│ 检测完成 │ -│ material_verify_log: verify_status = "VERIFIED" (通过) │ -│ 或 "REJECTED" (不通过) │ -│ 或 "PENDING" (嫌疑,需人工审核) │ -│ tencent_xxx: status = "VERIFIED"/"REJECTED"/"PENDING" │ -└─────────────────────────────────────────────────────────────┘ -``` - -### 状态值说明 - -| 状态值 | 说明 | 触发条件 | -|--------|------|----------| -| `pending` / `PENDING` | 待检测 | 素材创建时 | -| `submitting` | 送检中 | 提交至易盾检测 | -| `VERIFIED` | 校验通过 | 易盾建议通过(suggestion=0)| -| `REJECTED` | 校验不通过 | 易盾建议不通过(suggestion=2)或检测失败 | -| `PENDING` (人审) | 嫌疑待审 | 易盾建议人工审核(suggestion=1)| - -### 易盾处置建议对照 - -| suggestion值 | 说明 | 系统状态 | -|-------------|------|----------| -| 0 | 通过 | VERIFIED | -| 1 | 嫌疑,需人工审核 | PENDING | -| 2 | 不通过 | REJECTED | - ---- - -## 常见问题 - -### Q1: 轮询后待处理数量没有减少? - -**可能原因**: -1. 检测仍在进行中(易盾尚未返回结果) -2. 上次查询出错,状态已更新为 REJECTED - -**排查方法**: -```bash -# 查看日志 -grep "检测仍在进行中" resource/log/server/cid.log - -# 查看数据库状态 -SELECT id, task_id, verify_status FROM material_verify_log WHERE task_id = 'xxx'; -``` - -### Q2: 如何判断是图片还是视频? - -```bash -# 方法1:查询日志 -SELECT id, material_type, task_id, verify_status FROM material_verify_log WHERE task_id = 'xxx'; - -# 方法2:调用接口指定类型 -curl -X POST "http://localhost:3001/yidun/callback/pollTask?taskId=xxx&type=image" -``` - -### Q3: 回调模式收不到回调? - -**排查步骤**: -1. 确认公网地址可访问:`curl http://your-domain.com:3001/yidun/callback/receiveImage` -2. 确认易盾控制台配置了正确的回调地址 -3. 检查服务器防火墙/安全组是否开放端口 -4. 查看日志确认请求是否到达:`grep "收到易盾" resource/log/server/cid.log` - -### Q4: 状态不一致? - -如果 `material_verify_log` 和 `tencent_image/video` 表状态不一致,检查: -1. 代码执行过程中是否有报错 -2. 是否有并发更新导致覆盖 -3. 日志表和原表更新是否在同一事务中 - ---- - -## 错误码说明 - -| code | 说明 | -|------|------| -| 0 | 成功 | -| 400 | 请求参数错误 | -| 500 | 服务器内部错误 | - -**易盾API错误码**: - -| 错误码 | 说明 | -|--------|------| -| 200 | 成功 | -| 401 | 认证失败(SecretID/SecretKey错误) | -| 403 | 权限不足 | -| 429 | 请求频率超限 | - ---- - -## Go代码调用示例 - -```go -// 文本检测 -func detectText() (string, error) { - req := map[string]interface{}{ - "data_id": "text-001", - "content": "这是一段测试文本", - } - jsonData, _ := json.Marshal(req) - resp, err := http.Post("http://localhost:3002/yidun/detect-text", "application/json", bytes.NewBuffer(jsonData)) - // ... -} - -// 图片检测 -func detectImage() (string, error) { - req := map[string]interface{}{ - "data_id": "img-001", - "image_url": "https://example.com/image.jpg", - } - jsonData, _ := json.Marshal(req) - resp, err := http.Post("http://localhost:3002/yidun/detect-image", "application/json", bytes.NewBuffer(jsonData)) - // ... -} - -// 视频检测 -func detectVideo() (string, error) { - req := map[string]interface{}{ - "data_id": "video-001", - "video_url": "https://example.com/video.mp4", - } - jsonData, _ := json.Marshal(req) - resp, err := http.Post("http://localhost:3002/yidun/detect-video", "application/json", bytes.NewBuffer(jsonData)) - // ... -} -``` - ---- - -**最后更新**: 2026-05-14 diff --git a/consts/app/application_status.go b/consts/app/application_status.go deleted file mode 100644 index 44f1384..0000000 --- a/consts/app/application_status.go +++ /dev/null @@ -1,13 +0,0 @@ -package app - -// AppStatus 应用状态 -type AppStatus string - -const ( - AppStatusActive AppStatus = "active" // 启用 - AppStatusInactive AppStatus = "inactive" // 停用 -) - -func (s AppStatus) String() string { - return string(s) -} diff --git a/consts/app/application_type.go b/consts/app/application_type.go deleted file mode 100644 index aab6888..0000000 --- a/consts/app/application_type.go +++ /dev/null @@ -1,17 +0,0 @@ -package app - -// AppType 应用类型 -type AppType string - -const ( - AppTypeWeb AppType = "web" // Web应用 - AppTypeMobile AppType = "mobile" // 移动应用 - AppTypeMiniApp AppType = "mini_app" // 小程序 - AppTypeH5 AppType = "h5" // H5应用 - AppTypeDesktop AppType = "desktop" // 桌面应用 - AppTypeThirdParty AppType = "third_party" // 第三方应用 -) - -func (s AppType) String() string { - return string(s) -} diff --git a/consts/data/api_method.go b/consts/data/api_method.go deleted file mode 100644 index e3a0125..0000000 --- a/consts/data/api_method.go +++ /dev/null @@ -1,18 +0,0 @@ -package data - -// ApiMethod 接口请求方法 -type ApiMethod string - -const ( - ApiMethodGet ApiMethod = "GET" // GET请求 - ApiMethodPost ApiMethod = "POST" // POST请求 - ApiMethodPut ApiMethod = "PUT" // PUT请求 - ApiMethodDelete ApiMethod = "DELETE" // DELETE请求 - ApiMethodPatch ApiMethod = "PATCH" // PATCH请求 - ApiMethodHead ApiMethod = "HEAD" // HEAD请求 - ApiMethodOptions ApiMethod = "OPTIONS" // OPTIONS请求 -) - -func (m ApiMethod) String() string { - return string(m) -} diff --git a/consts/data/fetch_status.go b/consts/data/fetch_status.go deleted file mode 100644 index 79fc657..0000000 --- a/consts/data/fetch_status.go +++ /dev/null @@ -1,16 +0,0 @@ -package data - -// FetchStatus 数据获取状态 -type FetchStatus string - -const ( - FetchStatusPending FetchStatus = "pending" // 待执行 - FetchStatusRunning FetchStatus = "running" // 执行中 - FetchStatusSuccess FetchStatus = "success" // 成功 - FetchStatusFailed FetchStatus = "failed" // 失败 - FetchStatusRateLimit FetchStatus = "rate_limit" // 触发限流 -) - -func (f FetchStatus) String() string { - return string(f) -} diff --git a/consts/data/limit_type.go b/consts/data/limit_type.go deleted file mode 100644 index b666690..0000000 --- a/consts/data/limit_type.go +++ /dev/null @@ -1,14 +0,0 @@ -package data - -// LimitType 限流类型 -type LimitType string - -const ( - LimitTypeApp LimitType = "app" // 应用维度限流 - LimitTypeTenant LimitType = "tenant" // 租户维度限流 - LimitTypeApi LimitType = "api" // 接口维度限流 -) - -func (l LimitType) String() string { - return string(l) -} diff --git a/consts/data/platform_status.go b/consts/data/platform_status.go deleted file mode 100644 index 0edc02a..0000000 --- a/consts/data/platform_status.go +++ /dev/null @@ -1,13 +0,0 @@ -package data - -// PlatformStatus 平台状态 -type PlatformStatus string - -const ( - PlatformStatusActive PlatformStatus = "active" // 启用 - PlatformStatusInactive PlatformStatus = "inactive" // 停用 -) - -func (s PlatformStatus) String() string { - return string(s) -} diff --git a/consts/data/platform_type.go b/consts/data/platform_type.go deleted file mode 100644 index 82ed3a5..0000000 --- a/consts/data/platform_type.go +++ /dev/null @@ -1,21 +0,0 @@ -package data - -// SyncPlatform 同步平台类型 -type SyncPlatform string - -const ( - PlatformTaobao SyncPlatform = "taobao" // 淘宝 - PlatformJD SyncPlatform = "jd" // 京东 - PlatformKuaishou SyncPlatform = "kuaishou" // 快手 - PlatformDouyin SyncPlatform = "douyin" // 抖音 - PlatformXhs SyncPlatform = "xhs" // 小红书 - PlatformPdd SyncPlatform = "pdd" // 拼多多 - PlatformXianyu SyncPlatform = "xianyu" // 闲鱼 - PlatformTmall SyncPlatform = "tmall" // 天猫 - PlatformWechat SyncPlatform = "wechat" // 微信 - PlatformCustom SyncPlatform = "custom" // 自定义平台 -) - -func (s SyncPlatform) String() string { - return string(s) -} diff --git a/consts/mapping/mapping_status.go b/consts/mapping/mapping_status.go deleted file mode 100644 index f6cd94a..0000000 --- a/consts/mapping/mapping_status.go +++ /dev/null @@ -1,13 +0,0 @@ -package mapping - -// MappingStatus 映射状态 -type MappingStatus string - -const ( - MappingStatusActive MappingStatus = "active" // 启用 - MappingStatusInactive MappingStatus = "inactive" // 停用 -) - -func (s MappingStatus) String() string { - return string(s) -} diff --git a/consts/mapping/transform_type.go b/consts/mapping/transform_type.go deleted file mode 100644 index 3847f9a..0000000 --- a/consts/mapping/transform_type.go +++ /dev/null @@ -1,16 +0,0 @@ -package mapping - -// TransformType 转换类型 -type TransformType string - -const ( - TransformTypeFixed TransformType = "fixed" // 固定值 - TransformTypeMapping TransformType = "mapping" // 值映射 - TransformTypeRegex TransformType = "regex" // 正则转换 - TransformTypeFunction TransformType = "function" // 函数转换 - TransformTypeScript TransformType = "script" // 脚本转换 -) - -func (t TransformType) String() string { - return string(t) -} diff --git a/controller/app/application_controller.go b/controller/app/application_controller.go deleted file mode 100644 index e960b44..0000000 --- a/controller/app/application_controller.go +++ /dev/null @@ -1,47 +0,0 @@ -package app - -import ( - dto "cid/model/dto/app" - service "cid/service/app" - "context" - - "gitea.com/red-future/common/beans" -) - -type applicationController struct{} - -// Application 应用控制器 -var Application = new(applicationController) - -// CreateApplication 创建应用 -func (c *applicationController) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (res *dto.CreateApplicationRes, err error) { - return service.Application.Create(ctx, req) -} - -// ListApplication 获取应用列表 -func (c *applicationController) ListApplication(ctx context.Context, req *dto.ListApplicationReq) (res *dto.ListApplicationRes, err error) { - return service.Application.List(ctx, req) -} - -// GetApplication 获取应用详情 -func (c *applicationController) GetApplication(ctx context.Context, req *dto.GetApplicationReq) (res *dto.GetApplicationRes, err error) { - return service.Application.GetOne(ctx, req) -} - -// UpdateApplication 更新应用 -func (c *applicationController) UpdateApplication(ctx context.Context, req *dto.UpdateApplicationReq) (res *beans.ResponseEmpty, err error) { - err = service.Application.Update(ctx, req) - return -} - -// UpdateApplicationStatus 更新应用状态 -func (c *applicationController) UpdateApplicationStatus(ctx context.Context, req *dto.UpdateApplicationStatusReq) (res *beans.ResponseEmpty, err error) { - err = service.Application.UpdateStatus(ctx, req) - return -} - -// DeleteApplication 删除应用 -func (c *applicationController) DeleteApplication(ctx context.Context, req *dto.DeleteApplicationReq) (res *beans.ResponseEmpty, err error) { - err = service.Application.Delete(ctx, req) - return -} diff --git a/controller/data/api_interface_controller.go b/controller/data/api_interface_controller.go deleted file mode 100644 index 96b92e7..0000000 --- a/controller/data/api_interface_controller.go +++ /dev/null @@ -1,47 +0,0 @@ -package data - -import ( - dto "cid/model/dto/data" - service "cid/service/data" - "context" - - "gitea.com/red-future/common/beans" -) - -type apiInterfaceController struct{} - -// ApiInterface 接口控制器 -var ApiInterface = new(apiInterfaceController) - -// CreateApiInterface 创建接口 -func (c *apiInterfaceController) CreateApiInterface(ctx context.Context, req *dto.CreateApiInterfaceReq) (res *dto.CreateApiInterfaceRes, err error) { - return service.ApiInterface.Create(ctx, req) -} - -// ListApiInterface 获取接口列表 -func (c *apiInterfaceController) ListApiInterface(ctx context.Context, req *dto.ListApiInterfaceReq) (res *dto.ListApiInterfaceRes, err error) { - return service.ApiInterface.List(ctx, req) -} - -// GetApiInterface 获取接口详情 -func (c *apiInterfaceController) GetApiInterface(ctx context.Context, req *dto.GetApiInterfaceReq) (res *dto.GetApiInterfaceRes, err error) { - return service.ApiInterface.GetOne(ctx, req) -} - -// UpdateApiInterface 更新接口 -func (c *apiInterfaceController) UpdateApiInterface(ctx context.Context, req *dto.UpdateApiInterfaceReq) (res *beans.ResponseEmpty, err error) { - err = service.ApiInterface.Update(ctx, req) - return -} - -// UpdateApiInterfaceStatus 更新接口状态 -func (c *apiInterfaceController) UpdateApiInterfaceStatus(ctx context.Context, req *dto.UpdateApiInterfaceStatusReq) (res *beans.ResponseEmpty, err error) { - err = service.ApiInterface.UpdateStatus(ctx, req) - return -} - -// DeleteApiInterface 删除接口 -func (c *apiInterfaceController) DeleteApiInterface(ctx context.Context, req *dto.DeleteApiInterfaceReq) (res *beans.ResponseEmpty, err error) { - err = service.ApiInterface.Delete(ctx, req) - return -} diff --git a/controller/data/data_fetch_controller.go b/controller/data/data_fetch_controller.go deleted file mode 100644 index d09d41c..0000000 --- a/controller/data/data_fetch_controller.go +++ /dev/null @@ -1,37 +0,0 @@ -package data - -import ( - dto "cid/model/dto/data" - service "cid/service/data" - "context" -) - -type dataFetchController struct{} - -// DataFetch 数据获取控制器 -var DataFetch = new(dataFetchController) - -// ExecuteDataFetch 执行数据获取 -func (c *dataFetchController) ExecuteDataFetch(ctx context.Context, req *dto.ExecuteDataFetchReq) (res *dto.ExecuteDataFetchRes, err error) { - return service.DataFetch.Execute(ctx, req) -} - -// BatchExecuteDataFetch 批量执行数据获取 -func (c *dataFetchController) BatchExecuteDataFetch(ctx context.Context, req *dto.BatchExecuteDataFetchReq) (res *dto.BatchExecuteDataFetchRes, err error) { - return service.DataFetch.BatchExecute(ctx, req) -} - -// ListDataFetchLog 获取数据获取日志列表 -func (c *dataFetchController) ListDataFetchLog(ctx context.Context, req *dto.ListDataFetchLogReq) (res *dto.ListDataFetchLogRes, err error) { - return service.DataFetch.List(ctx, req) -} - -// GetDataFetchLog 获取数据获取日志详情 -func (c *dataFetchController) GetDataFetchLog(ctx context.Context, req *dto.GetDataFetchLogReq) (res *dto.GetDataFetchLogRes, err error) { - return service.DataFetch.GetOne(ctx, req) -} - -// ReExecuteDataFetch 重新执行数据获取 -func (c *dataFetchController) ReExecuteDataFetch(ctx context.Context, req *dto.ReExecuteDataFetchReq) (res *dto.ReExecuteDataFetchRes, err error) { - return service.DataFetch.ReExecute(ctx, req) -} diff --git a/controller/data/platform_controller.go b/controller/data/platform_controller.go deleted file mode 100644 index 2a58427..0000000 --- a/controller/data/platform_controller.go +++ /dev/null @@ -1,47 +0,0 @@ -package data - -import ( - dto "cid/model/dto/data" - service "cid/service/data" - "context" - - "gitea.com/red-future/common/beans" -) - -type platformController struct{} - -// Platform 平台控制器 -var Platform = new(platformController) - -// CreatePlatform 创建平台 -func (c *platformController) CreatePlatform(ctx context.Context, req *dto.CreatePlatformReq) (res *dto.CreatePlatformRes, err error) { - return service.Platform.Create(ctx, req) -} - -// ListPlatform 获取平台列表 -func (c *platformController) ListPlatform(ctx context.Context, req *dto.ListPlatformReq) (res *dto.ListPlatformRes, err error) { - return service.Platform.List(ctx, req) -} - -// GetPlatform 获取平台详情 -func (c *platformController) GetPlatform(ctx context.Context, req *dto.GetPlatformReq) (res *dto.GetPlatformRes, err error) { - return service.Platform.GetOne(ctx, req) -} - -// UpdatePlatform 更新平台 -func (c *platformController) UpdatePlatform(ctx context.Context, req *dto.UpdatePlatformReq) (res *beans.ResponseEmpty, err error) { - err = service.Platform.Update(ctx, req) - return -} - -// UpdatePlatformStatus 更新平台状态 -func (c *platformController) UpdatePlatformStatus(ctx context.Context, req *dto.UpdatePlatformStatusReq) (res *beans.ResponseEmpty, err error) { - err = service.Platform.UpdateStatus(ctx, req) - return -} - -// DeletePlatform 删除平台 -func (c *platformController) DeletePlatform(ctx context.Context, req *dto.DeletePlatformReq) (res *beans.ResponseEmpty, err error) { - err = service.Platform.Delete(ctx, req) - return -} diff --git a/controller/mapping/data_mapping_controller.go b/controller/mapping/data_mapping_controller.go deleted file mode 100644 index 345d812..0000000 --- a/controller/mapping/data_mapping_controller.go +++ /dev/null @@ -1,51 +0,0 @@ -package mapping - -import ( - dto "cid/model/dto/mapping" - service "cid/service/mapping" - "context" - - "gitea.com/red-future/common/beans" -) - -type dataMappingController struct{} - -// DataMapping 数据映射控制器 -var DataMapping = new(dataMappingController) - -// CreateDataMapping 创建数据映射 -func (c *dataMappingController) CreateDataMapping(ctx context.Context, req *dto.CreateDataMappingReq) (res *dto.CreateDataMappingRes, err error) { - return service.DataMapping.Create(ctx, req) -} - -// BatchCreateDataMappings 批量创建数据映射 -func (c *dataMappingController) BatchCreateDataMappings(ctx context.Context, req *dto.BatchCreateDataMappingReq) (res *dto.BatchCreateDataMappingRes, err error) { - return service.DataMapping.BatchCreate(ctx, req) -} - -// ListDataMapping 获取数据映射列表 -func (c *dataMappingController) ListDataMapping(ctx context.Context, req *dto.ListDataMappingReq) (res *dto.ListDataMappingRes, err error) { - return service.DataMapping.List(ctx, req) -} - -// GetDataMapping 获取数据映射详情 -func (c *dataMappingController) GetDataMapping(ctx context.Context, req *dto.GetDataMappingReq) (res *dto.GetDataMappingRes, err error) { - return service.DataMapping.GetOne(ctx, req) -} - -// UpdateDataMapping 更新数据映射 -func (c *dataMappingController) UpdateDataMapping(ctx context.Context, req *dto.UpdateDataMappingReq) (res *beans.ResponseEmpty, err error) { - err = service.DataMapping.Update(ctx, req) - return -} - -// DeleteDataMapping 删除数据映射 -func (c *dataMappingController) DeleteDataMapping(ctx context.Context, req *dto.DeleteDataMappingReq) (res *beans.ResponseEmpty, err error) { - err = service.DataMapping.Delete(ctx, req) - return -} - -// ExecuteDataMapping 执行数据映射 -func (c *dataMappingController) ExecuteDataMapping(ctx context.Context, req *dto.ExecuteDataMappingReq) (res *dto.ExecuteDataMappingRes, err error) { - return service.DataMapping.Execute(ctx, req) -} diff --git a/dao/app/application_dao.go b/dao/app/application_dao.go deleted file mode 100644 index 494fae6..0000000 --- a/dao/app/application_dao.go +++ /dev/null @@ -1,117 +0,0 @@ -package app - -import ( - consts "cid/consts/public" - dto "cid/model/dto/app" - entity "cid/model/entity/app" - "context" - - "gitea.com/red-future/common/db/gfdb" - "github.com/gogf/gf/v2/database/gdb" - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/util/gconv" -) - -var Application = new(applicationDao) - -type applicationDao struct{} - -// Insert 插入应用 -func (d *applicationDao) Insert(ctx context.Context, req *dto.CreateApplicationReq) (id int64, err error) { - var res *entity.Application - if err = gconv.Struct(req, &res); err != nil { - return - } - r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Data(&res).Insert() - if err != nil { - return - } - return r.LastInsertId() -} - -// Update 更新应用 -func (d *applicationDao) Update(ctx context.Context, req *dto.UpdateApplicationReq) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Data(&req).OmitEmpty().Where(entity.ApplicationCols.Id, req.Id).Update() - if err != nil { - return - } - return r.RowsAffected() -} - -// Delete 删除应用 -func (d *applicationDao) Delete(ctx context.Context, req *dto.DeleteApplicationReq) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Where(entity.ApplicationCols.Id, req.Id).Delete() - if err != nil { - return - } - return r.RowsAffected() -} - -// GetOne 获取单个应用 -func (d *applicationDao) GetOne(ctx context.Context, req *dto.GetApplicationReq) (res *entity.Application, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Where(entity.ApplicationCols.Id, req.Id).One() - if err != nil { - return - } - err = r.Struct(&res) - return -} - -// Count 获取应用数量 -func (d *applicationDao) Count(ctx context.Context, req *dto.ListApplicationReq) (count int, err error) { - return d.buildListFilter(ctx, req).Count() -} - -// List 获取应用列表 -func (d *applicationDao) List(ctx context.Context, req *dto.ListApplicationReq) (res []entity.Application, total int, err error) { - model := d.buildListFilter(ctx, req) - model.OrderDesc(entity.ApplicationCols.CreatedAt) - if req.Page != nil { - model.Page(int(req.Page.PageNum), int(req.Page.PageSize)) - } - r, total, err := model.AllAndCount(false) - if err != nil { - return - } - err = r.Structs(&res) - return -} - -// buildListFilter 构建列表查询的过滤条件 -func (d *applicationDao) buildListFilter(ctx context.Context, req *dto.ListApplicationReq) *gdb.Model { - model := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable).Model - if !g.IsEmpty(req.Keyword) { - model.WhereLike(entity.ApplicationCols.Name, "%"+req.Keyword+"%") - model.WhereOrLike(entity.ApplicationCols.AppCode, "%"+req.Keyword+"%") - } - model.Where(entity.ApplicationCols.Name, req.Name) - model.Where(entity.ApplicationCols.AppCode, req.AppCode) - model.Where(entity.ApplicationCols.Type, req.Type) - model.Where(entity.ApplicationCols.Status, req.Status) - model.OmitEmptyWhere() - return model -} - -// UpdateStatus 更新应用状态 -func (d *applicationDao) UpdateStatus(ctx context.Context, id int64, status string) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable). - Data(map[string]interface{}{"status": status}). - Where(entity.ApplicationCols.Id, id). - Update() - if err != nil { - return - } - return r.RowsAffected() -} - -// GetByAppCode 根据应用编码获取应用 -func (d *applicationDao) GetByAppCode(ctx context.Context, appCode string) (res *entity.Application, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApplicationTable). - Where(entity.ApplicationCols.AppCode, appCode). - One() - if err != nil { - return - } - err = r.Struct(&res) - return -} diff --git a/dao/data/api_interface_dao.go b/dao/data/api_interface_dao.go deleted file mode 100644 index 65ea0bd..0000000 --- a/dao/data/api_interface_dao.go +++ /dev/null @@ -1,118 +0,0 @@ -package data - -import ( - consts "cid/consts/public" - dto "cid/model/dto/data" - entity "cid/model/entity/data" - "context" - - "gitea.com/red-future/common/db/gfdb" - "github.com/gogf/gf/v2/database/gdb" - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/util/gconv" -) - -var ApiInterface = new(apiInterfaceDao) - -type apiInterfaceDao struct{} - -// Insert 插入接口 -func (d *apiInterfaceDao) Insert(ctx context.Context, req *dto.CreateApiInterfaceReq) (id int64, err error) { - var res *entity.ApiInterface - if err = gconv.Struct(req, &res); err != nil { - return - } - r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Data(&res).Insert() - if err != nil { - return - } - return r.LastInsertId() -} - -// Update 更新接口 -func (d *apiInterfaceDao) Update(ctx context.Context, req *dto.UpdateApiInterfaceReq) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Data(&req).OmitEmpty().Where(entity.ApiInterfaceCols.Id, req.Id).Update() - if err != nil { - return - } - return r.RowsAffected() -} - -// Delete 删除接口 -func (d *apiInterfaceDao) Delete(ctx context.Context, req *dto.DeleteApiInterfaceReq) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Where(entity.ApiInterfaceCols.Id, req.Id).Delete() - if err != nil { - return - } - return r.RowsAffected() -} - -// GetOne 获取单个接口 -func (d *apiInterfaceDao) GetOne(ctx context.Context, req *dto.GetApiInterfaceReq) (res *entity.ApiInterface, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Where(entity.ApiInterfaceCols.Id, req.Id).One() - if err != nil { - return - } - err = r.Struct(&res) - return -} - -// Count 获取接口数量 -func (d *apiInterfaceDao) Count(ctx context.Context, req *dto.ListApiInterfaceReq) (count int, err error) { - return d.buildListFilter(ctx, req).Count() -} - -// List 获取接口列表 -func (d *apiInterfaceDao) List(ctx context.Context, req *dto.ListApiInterfaceReq) (res []entity.ApiInterface, total int, err error) { - model := d.buildListFilter(ctx, req) - model.OrderDesc(entity.ApiInterfaceCols.CreatedAt) - if req.Page != nil { - model.Page(int(req.Page.PageNum), int(req.Page.PageSize)) - } - r, total, err := model.AllAndCount(false) - if err != nil { - return - } - err = r.Structs(&res) - return -} - -// buildListFilter 构建列表查询的过滤条件 -func (d *apiInterfaceDao) buildListFilter(ctx context.Context, req *dto.ListApiInterfaceReq) *gdb.Model { - model := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Model - if !g.IsEmpty(req.Keyword) { - model.WhereLike(entity.ApiInterfaceCols.Name, "%"+req.Keyword+"%") - model.WhereOrLike(entity.ApiInterfaceCols.Code, "%"+req.Keyword+"%") - } - model.Where(entity.ApiInterfaceCols.PlatformId, req.PlatformId) - model.Where(entity.ApiInterfaceCols.Name, req.Name) - model.Where(entity.ApiInterfaceCols.Code, req.Code) - model.Where(entity.ApiInterfaceCols.Method, req.Method) - model.Where(entity.ApiInterfaceCols.Status, req.Status) - model.OmitEmptyWhere() - return model -} - -// UpdateStatus 更新接口状态 -func (d *apiInterfaceDao) UpdateStatus(ctx context.Context, id int64, status string) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable). - Data(map[string]interface{}{"status": status}). - Where(entity.ApiInterfaceCols.Id, id). - Update() - if err != nil { - return - } - return r.RowsAffected() -} - -// GetByIds 根据ID列表获取接口列表 -func (d *apiInterfaceDao) GetByIds(ctx context.Context, ids []int64) (res []entity.ApiInterface, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable). - WhereIn(entity.ApiInterfaceCols.Id, ids). - All() - if err != nil { - return - } - err = r.Structs(&res) - return -} diff --git a/dao/data/data_fetch_log_dao.go b/dao/data/data_fetch_log_dao.go deleted file mode 100644 index bdc3075..0000000 --- a/dao/data/data_fetch_log_dao.go +++ /dev/null @@ -1,135 +0,0 @@ -package data - -import ( - consts "cid/consts/public" - dto "cid/model/dto/data" - entity "cid/model/entity/data" - "context" - - "gitea.com/red-future/common/db/gfdb" - "github.com/gogf/gf/v2/database/gdb" -) - -var DataFetchLog = new(dataFetchLogDao) - -type dataFetchLogDao struct{} - -// Insert 插入数据获取日志 -func (d *dataFetchLogDao) Insert(ctx context.Context, log *entity.DataFetchLog) (id int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).Data(&log).Insert() - if err != nil { - return - } - return r.LastInsertId() -} - -// Update 更新数据获取日志 -func (d *dataFetchLogDao) Update(ctx context.Context, id int64, data map[string]interface{}) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable). - Data(data). - OmitEmpty(). - Where(entity.DataFetchLogCols.Id, id). - Update() - if err != nil { - return - } - return r.RowsAffected() -} - -// GetOne 获取单个数据获取日志 -func (d *dataFetchLogDao) GetOne(ctx context.Context, req *dto.GetDataFetchLogReq) (res *entity.DataFetchLog, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).Where(entity.DataFetchLogCols.Id, req.Id).One() - if err != nil { - return - } - err = r.Struct(&res) - return -} - -// Count 获取数据获取日志数量 -func (d *dataFetchLogDao) Count(ctx context.Context, req *dto.ListDataFetchLogReq) (count int, err error) { - return d.buildListFilter(ctx, req).Count() -} - -// List 获取数据获取日志列表 -func (d *dataFetchLogDao) List(ctx context.Context, req *dto.ListDataFetchLogReq) (res []entity.DataFetchLog, total int, err error) { - model := d.buildListFilter(ctx, req) - model.OrderDesc(entity.DataFetchLogCols.CreatedAt) - if req.Page != nil { - model.Page(int(req.Page.PageNum), int(req.Page.PageSize)) - } - r, total, err := model.AllAndCount(false) - if err != nil { - return - } - err = r.Structs(&res) - return -} - -// buildListFilter 构建列表查询的过滤条件 -func (d *dataFetchLogDao) buildListFilter(ctx context.Context, req *dto.ListDataFetchLogReq) *gdb.Model { - model := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).Model - model.Where(entity.DataFetchLogCols.PlatformId, req.PlatformId) - model.Where(entity.DataFetchLogCols.InterfaceId, req.InterfaceId) - model.Where(entity.DataFetchLogCols.RequestId, req.RequestId) - model.Where(entity.DataFetchLogCols.Status, req.Status) - if req.StartTime > 0 { - model.WhereGTE(entity.DataFetchLogCols.StartTime, req.StartTime) - } - if req.EndTime > 0 { - model.WhereLTE(entity.DataFetchLogCols.StartTime, req.EndTime) - } - model.OmitEmptyWhere() - return model -} - -// GetByRequestId 根据请求ID获取日志 -func (d *dataFetchLogDao) GetByRequestId(ctx context.Context, requestId string) (res *entity.DataFetchLog, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable). - Where(entity.DataFetchLogCols.RequestId, requestId). - One() - if err != nil { - return - } - err = r.Struct(&res) - return -} - -// UpdateStatus 更新日志状态 -func (d *dataFetchLogDao) UpdateStatus(ctx context.Context, id int64, status string, endTime int64, duration int, responseData, errorMessage string) (rows int64, err error) { - updateData := map[string]interface{}{ - "status": status, - } - if endTime > 0 { - updateData["end_time"] = endTime - } - if duration > 0 { - updateData["duration"] = duration - } - if responseData != "" { - updateData["response_data"] = responseData - } - if errorMessage != "" { - updateData["error_message"] = errorMessage - } - r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable). - Data(updateData). - Where(entity.DataFetchLogCols.Id, id). - Update() - if err != nil { - return - } - return r.RowsAffected() -} - -// IncrementRetryCount 增加重试次数 -func (d *dataFetchLogDao) IncrementRetryCount(ctx context.Context, id int64) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable). - Where(entity.DataFetchLogCols.Id, id). - Data(gdb.Raw(entity.DataFetchLogCols.RetryCount + " + 1")). - Update() - if err != nil { - return - } - return r.RowsAffected() -} diff --git a/dao/data/platform_dao.go b/dao/data/platform_dao.go deleted file mode 100644 index 7718107..0000000 --- a/dao/data/platform_dao.go +++ /dev/null @@ -1,115 +0,0 @@ -package data - -import ( - consts "cid/consts/public" - dto "cid/model/dto/data" - entity "cid/model/entity/data" - "context" - - "gitea.com/red-future/common/db/gfdb" - "github.com/gogf/gf/v2/database/gdb" - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/util/gconv" -) - -var Platform = new(platformDao) - -type platformDao struct{} - -// Insert 插入平台 -func (d *platformDao) Insert(ctx context.Context, req *dto.CreatePlatformReq) (id int64, err error) { - var res *entity.Platform - if err = gconv.Struct(req, &res); err != nil { - return - } - r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Data(&res).Insert() - if err != nil { - return - } - return r.LastInsertId() -} - -// Update 更新平台 -func (d *platformDao) Update(ctx context.Context, req *dto.UpdatePlatformReq) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Data(&req).OmitEmpty().Where(entity.PlatformCols.Id, req.Id).Update() - if err != nil { - return - } - return r.RowsAffected() -} - -// Delete 删除平台 -func (d *platformDao) Delete(ctx context.Context, req *dto.DeletePlatformReq) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Where(entity.PlatformCols.Id, req.Id).Delete() - if err != nil { - return - } - return r.RowsAffected() -} - -// GetOne 获取单个平台 -func (d *platformDao) GetOne(ctx context.Context, req *dto.GetPlatformReq) (res *entity.Platform, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Where(entity.PlatformCols.Id, req.Id).One() - if err != nil { - return - } - err = r.Struct(&res) - return -} - -// Count 获取平台数量 -func (d *platformDao) Count(ctx context.Context, req *dto.ListPlatformReq) (count int, err error) { - return d.buildListFilter(ctx, req).Count() -} - -// List 获取平台列表 -func (d *platformDao) List(ctx context.Context, req *dto.ListPlatformReq) (res []entity.Platform, total int, err error) { - model := d.buildListFilter(ctx, req) - model.OrderDesc(entity.PlatformCols.CreatedAt) - if req.Page != nil { - model.Page(int(req.Page.PageNum), int(req.Page.PageSize)) - } - r, total, err := model.AllAndCount(false) - if err != nil { - return - } - err = r.Structs(&res) - return -} - -// buildListFilter 构建列表查询的过滤条件 -func (d *platformDao) buildListFilter(ctx context.Context, req *dto.ListPlatformReq) *gdb.Model { - model := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Model - if !g.IsEmpty(req.Keyword) { - model.WhereLike(entity.PlatformCols.Name, "%"+req.Keyword+"%") - } - model.Where(entity.PlatformCols.Name, req.Name) - model.Where(entity.PlatformCols.Type, req.Type) - model.Where(entity.PlatformCols.Status, req.Status) - model.OmitEmptyWhere() - return model -} - -// UpdateStatus 更新平台状态 -func (d *platformDao) UpdateStatus(ctx context.Context, id int64, status string) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable). - Data(map[string]interface{}{"status": status}). - Where(entity.PlatformCols.Id, id). - Update() - if err != nil { - return - } - return r.RowsAffected() -} - -// GetByType 根据类型获取平台 -func (d *platformDao) GetByType(ctx context.Context, platformType string) (res *entity.Platform, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable). - Where(entity.PlatformCols.Type, platformType). - One() - if err != nil { - return - } - err = r.Struct(&res) - return -} diff --git a/dao/mapping/data_mapping_dao.go b/dao/mapping/data_mapping_dao.go deleted file mode 100644 index 11b4bab..0000000 --- a/dao/mapping/data_mapping_dao.go +++ /dev/null @@ -1,138 +0,0 @@ -package mapping - -import ( - consts "cid/consts/public" - dto "cid/model/dto/mapping" - entity "cid/model/entity/mapping" - "context" - - "gitea.com/red-future/common/db/gfdb" - "github.com/gogf/gf/v2/database/gdb" - "github.com/gogf/gf/v2/util/gconv" -) - -var DataMapping = new(dataMappingDao) - -type dataMappingDao struct{} - -// Insert 插入数据映射 -func (d *dataMappingDao) Insert(ctx context.Context, req *dto.CreateDataMappingReq) (id int64, err error) { - var res *entity.DataMapping - if err = gconv.Struct(req, &res); err != nil { - return - } - r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Data(&res).Insert() - if err != nil { - return - } - return r.LastInsertId() -} - -// BatchInsert 批量插入数据映射 -func (d *dataMappingDao) BatchInsert(ctx context.Context, mappings []entity.DataMapping) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Data(&mappings).Insert() - if err != nil { - return - } - return r.RowsAffected() -} - -// Update 更新数据映射 -func (d *dataMappingDao) Update(ctx context.Context, req *dto.UpdateDataMappingReq) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Data(&req).OmitEmpty().Where(entity.DataMappingCols.Id, req.Id).Update() - if err != nil { - return - } - return r.RowsAffected() -} - -// Delete 删除数据映射 -func (d *dataMappingDao) Delete(ctx context.Context, req *dto.DeleteDataMappingReq) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Where(entity.DataMappingCols.Id, req.Id).Delete() - if err != nil { - return - } - return r.RowsAffected() -} - -// GetOne 获取单个数据映射 -func (d *dataMappingDao) GetOne(ctx context.Context, req *dto.GetDataMappingReq) (res *entity.DataMapping, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Where(entity.DataMappingCols.Id, req.Id).One() - if err != nil { - return - } - err = r.Struct(&res) - return -} - -// Count 获取数据映射数量 -func (d *dataMappingDao) Count(ctx context.Context, req *dto.ListDataMappingReq) (count int, err error) { - return d.buildListFilter(ctx, req).Count() -} - -// List 获取数据映射列表 -func (d *dataMappingDao) List(ctx context.Context, req *dto.ListDataMappingReq) (res []entity.DataMapping, total int, err error) { - model := d.buildListFilter(ctx, req) - model.OrderAsc(entity.DataMappingCols.Priority) - model.OrderDesc(entity.DataMappingCols.CreatedAt) - if req.Page != nil { - model.Page(int(req.Page.PageNum), int(req.Page.PageSize)) - } - r, total, err := model.AllAndCount(false) - if err != nil { - return - } - err = r.Structs(&res) - return -} - -// buildListFilter 构建列表的过滤条件 -func (d *dataMappingDao) buildListFilter(ctx context.Context, req *dto.ListDataMappingReq) *gdb.Model { - model := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable).Model - model.Where(entity.DataMappingCols.PlatformId, req.PlatformId) - model.Where(entity.DataMappingCols.InterfaceId, req.InterfaceId) - model.Where(entity.DataMappingCols.SourceField, req.SourceField) - model.Where(entity.DataMappingCols.TargetField, req.TargetField) - model.Where(entity.DataMappingCols.Status, req.Status) - model.OmitEmptyWhere() - return model -} - -// GetByInterfaceId 根据接口ID获取映射规则列表(按优先级排序) -func (d *dataMappingDao) GetByInterfaceId(ctx context.Context, interfaceId int64) (res []entity.DataMapping, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable). - Where(entity.DataMappingCols.InterfaceId, interfaceId). - Where("status", "active"). - OrderAsc(entity.DataMappingCols.Priority). - All() - if err != nil { - return - } - err = r.Structs(&res) - return -} - -// GetByInterfaceIdAndTargetField 根据接口ID和目标字段获取映射规则 -func (d *dataMappingDao) GetByInterfaceIdAndTargetField(ctx context.Context, interfaceId int64, targetField string) (res *entity.DataMapping, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable). - Where(entity.DataMappingCols.InterfaceId, interfaceId). - Where(entity.DataMappingCols.TargetField, targetField). - Where("status", "active"). - One() - if err != nil { - return - } - err = r.Struct(&res) - return -} - -// DeleteByInterfaceId 根据接口ID删除所有映射规则 -func (d *dataMappingDao) DeleteByInterfaceId(ctx context.Context, interfaceId int64) (rows int64, err error) { - r, err := gfdb.DB(ctx).Model(ctx, consts.DataMappingTable). - Where(entity.DataMappingCols.InterfaceId, interfaceId). - Delete() - if err != nil { - return - } - return r.RowsAffected() -} diff --git a/main.go b/main.go index 1651578..4e663c1 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,8 @@ package main import ( - "cid/controller/app" - "cid/controller/data" "cid/controller/dataengine" - "cid/controller/mapping" "cid/controller/yidun" - controllerYidun "cid/controller/yidun" serviceDataengine "cid/service/dataengine" serviceYidun "cid/service/yidun" "context" @@ -55,13 +51,8 @@ func main() { // 注册 API 路由并启动服务器 http.RouteRegister([]interface{}{ - data.Platform, - data.ApiInterface, - data.DataFetch, - mapping.DataMapping, - app.Application, - controllerYidun.YidunController, - controllerYidun.YidunCallback, + yidun.YidunController, + yidun.YidunCallback, yidun.ContentCheck, dataengine.MaterialVerify, }) diff --git a/model/dto/app/application_dto.go b/model/dto/app/application_dto.go deleted file mode 100644 index 9356d61..0000000 --- a/model/dto/app/application_dto.go +++ /dev/null @@ -1,95 +0,0 @@ -package app - -import ( - "cid/consts/app" - entity "cid/model/entity/app" - - "gitea.com/red-future/common/beans" - "github.com/gogf/gf/v2/frame/g" -) - -// CreateApplicationReq 创建应用请求 -type CreateApplicationReq struct { - g.Meta `path:"/createApplication" method:"post" tags:"应用管理" summary:"创建应用" dc:"创建新的应用"` - Name string `json:"name" v:"required" dc:"应用名称"` - AppCode string `json:"appCode" v:"required" dc:"应用编码(唯一标识)"` - Type app.AppType `json:"type" v:"required" dc:"应用类型"` - Status app.AppStatus `json:"status" dc:"应用状态" d:"active"` - Description string `json:"description" dc:"应用描述"` - AccessConfig map[string]interface{} `json:"accessConfig" dc:"接入配置"` - LimitConfig map[string]interface{} `json:"limitConfig" dc:"限流配置"` - CallbackConfig map[string]interface{} `json:"callbackConfig" dc:"回调配置"` -} - -// CreateApplicationRes 创建应用响应 -type CreateApplicationRes struct { - Id int64 `json:"id" dc:"应用ID"` -} - -// ListApplicationReq 获取应用列表请求 -type ListApplicationReq struct { - g.Meta `path:"/listApplications" method:"get" tags:"应用管理" summary:"获取应用列表" dc:"分页查询应用列表"` - *beans.Page - Name string `json:"name" dc:"应用名称"` - AppCode string `json:"appCode" dc:"应用编码"` - Type app.AppType `json:"type" dc:"应用类型"` - Status app.AppStatus `json:"status" dc:"应用状态"` - Keyword string `json:"keyword" dc:"关键字(搜索应用名称或编码)"` -} - -// ListApplicationRes 获取应用列表响应 -type ListApplicationRes struct { - List []ApplicationItem `json:"list" dc:"应用列表"` - Total int `json:"total" dc:"总数"` -} - -type ApplicationItem struct { - Id int64 `json:"id,string"` - Name string `json:"name"` - AppCode string `json:"appCode"` - Type app.AppType `json:"type"` - TypeName string `json:"typeName"` - Status app.AppStatus `json:"status"` - StatusName string `json:"statusName"` - Description string `json:"description"` - CreatedAt int64 `json:"createdAt"` - UpdatedAt int64 `json:"updatedAt"` -} - -// GetApplicationReq 获取应用详情请求 -type GetApplicationReq struct { - g.Meta `path:"/getApplication" method:"get" tags:"应用管理" summary:"获取应用详情" dc:"获取应用详情"` - Id int64 `json:"id" v:"required" dc:"应用ID"` -} - -// GetApplicationRes 获取应用详情响应 -type GetApplicationRes struct { - *entity.Application -} - -// UpdateApplicationReq 更新应用请求 -type UpdateApplicationReq struct { - g.Meta `path:"/updateApplication" method:"put" tags:"应用管理" summary:"更新应用" dc:"更新应用信息"` - Id int64 `json:"id" v:"required" dc:"应用ID"` - Name string `json:"name" dc:"应用名称"` - AppCode string `json:"appCode" dc:"应用编码"` - Type app.AppType `json:"type" dc:"应用类型"` - Status app.AppStatus `json:"status,omitempty" dc:"应用状态"` - Description string `json:"description" dc:"应用描述"` - AccessConfig map[string]interface{} `json:"accessConfig" dc:"接入配置"` - LimitConfig map[string]interface{} `json:"limitConfig" dc:"限流配置"` - CallbackConfig map[string]interface{} `json:"callbackConfig" dc:"回调配置"` -} - -// DeleteApplicationReq 删除应用请求 -type DeleteApplicationReq struct { - g.Meta `path:"/deleteApplication" method:"delete" tags:"应用管理" summary:"删除应用" dc:"删除应用"` - Id int64 `json:"id" v:"required" dc:"应用ID"` -} - -// UpdateApplicationStatusReq 更新应用状态请求 -type UpdateApplicationStatusReq struct { - g.Meta `path:"/updateApplicationStatus" method:"put" tags:"应用管理" summary:"更新应用状态" dc:"更新应用状态"` - Id int64 `json:"id" v:"required" dc:"应用ID"` - Status app.AppStatus `json:"status" v:"required|in:active,inactive" dc:"状态:active启用/inactive停用"` -} diff --git a/model/dto/data/api_interface_dto.go b/model/dto/data/api_interface_dto.go deleted file mode 100644 index e040366..0000000 --- a/model/dto/data/api_interface_dto.go +++ /dev/null @@ -1,102 +0,0 @@ -package data - -import ( - "cid/consts/data" - entity "cid/model/entity/data" - - "gitea.com/red-future/common/beans" - "github.com/gogf/gf/v2/frame/g" -) - -// CreateApiInterfaceReq 创建接口请求 -type CreateApiInterfaceReq struct { - g.Meta `path:"/createApiInterface" method:"post" tags:"接口管理" summary:"创建接口" dc:"创建新的数据接口"` - PlatformId int64 `json:"platformId" v:"required" dc:"所属平台ID"` - Name string `json:"name" v:"required" dc:"接口名称"` - Code string `json:"code" v:"required" dc:"接口编码"` - Url string `json:"url" v:"required" dc:"接口地址"` - Method data.ApiMethod `json:"method" v:"required" dc:"请求方法"` - Status data.PlatformStatus `json:"status" dc:"接口状态" d:"active"` - AuthType string `json:"authType" dc:"认证类型"` - RequestConfig map[string]interface{} `json:"requestConfig" dc:"请求配置"` - ResponseConfig map[string]interface{} `json:"responseConfig" dc:"响应配置"` - LimitConfig map[string]interface{} `json:"limitConfig" dc:"接口独立限流配置"` -} - -// CreateApiInterfaceRes 创建接口响应 -type CreateApiInterfaceRes struct { - Id int64 `json:"id" dc:"接口ID"` -} - -// ListApiInterfaceReq 获取接口列表请求 -type ListApiInterfaceReq struct { - g.Meta `path:"/listApiInterfaces" method:"get" tags:"接口管理" summary:"获取接口列表" dc:"分页查询接口列表"` - *beans.Page - PlatformId int64 `json:"platformId" dc:"平台ID"` - Name string `json:"name" dc:"接口名称"` - Code string `json:"code" dc:"接口编码"` - Method data.ApiMethod `json:"method" dc:"请求方法"` - Status data.PlatformStatus `json:"status" dc:"接口状态"` - Keyword string `json:"keyword" dc:"关键字(搜索名称或编码)"` -} - -// ListApiInterfaceRes 获取接口列表响应 -type ListApiInterfaceRes struct { - List []ApiInterfaceItem `json:"list" dc:"接口列表"` - Total int `json:"total" dc:"总数"` -} - -type ApiInterfaceItem struct { - Id int64 `json:"id,string"` - PlatformId int64 `json:"platformId"` - PlatformName string `json:"platformName"` - Name string `json:"name"` - Code string `json:"code"` - Url string `json:"url"` - Method data.ApiMethod `json:"method"` - Status data.PlatformStatus `json:"status"` - StatusName string `json:"statusName"` - CreatedAt int64 `json:"createdAt"` - UpdatedAt int64 `json:"updatedAt"` -} - -// GetApiInterfaceReq 获取接口详情请求 -type GetApiInterfaceReq struct { - g.Meta `path:"/getApiInterface" method:"get" tags:"接口管理" summary:"获取接口详情" dc:"获取接口详情"` - Id int64 `json:"id" v:"required" dc:"接口ID"` -} - -// GetApiInterfaceRes 获取接口详情响应 -type GetApiInterfaceRes struct { - *entity.ApiInterface - PlatformName string `json:"platformName,omitempty"` -} - -// UpdateApiInterfaceReq 更新接口请求 -type UpdateApiInterfaceReq struct { - g.Meta `path:"/updateApiInterface" method:"put" tags:"接口管理" summary:"更新接口" dc:"更新接口信息"` - Id int64 `json:"id" v:"required" dc:"接口ID"` - PlatformId int64 `json:"platformId" dc:"所属平台ID"` - Name string `json:"name" dc:"接口名称"` - Code string `json:"code" dc:"接口编码"` - Url string `json:"url" dc:"接口地址"` - Method data.ApiMethod `json:"method" dc:"请求方法"` - Status data.PlatformStatus `json:"status,omitempty" dc:"接口状态"` - AuthType string `json:"authType" dc:"认证类型"` - RequestConfig map[string]interface{} `json:"requestConfig" dc:"请求配置"` - ResponseConfig map[string]interface{} `json:"responseConfig" dc:"响应配置"` - LimitConfig map[string]interface{} `json:"limitConfig" dc:"接口独立限流配置"` -} - -// DeleteApiInterfaceReq 删除接口请求 -type DeleteApiInterfaceReq struct { - g.Meta `path:"/deleteApiInterface" method:"delete" tags:"接口管理" summary:"删除接口" dc:"删除接口"` - Id int64 `json:"id" v:"required" dc:"接口ID"` -} - -// UpdateApiInterfaceStatusReq 更新接口状态请求 -type UpdateApiInterfaceStatusReq struct { - g.Meta `path:"/updateApiInterfaceStatus" method:"put" tags:"接口管理" summary:"更新接口状态" dc:"更新接口状态"` - Id int64 `json:"id" v:"required" dc:"接口ID"` - Status data.PlatformStatus `json:"status" v:"required|in:active,inactive" dc:"状态:active启用/inactive停用"` -} diff --git a/model/dto/data/data_fetch_dto.go b/model/dto/data/data_fetch_dto.go deleted file mode 100644 index ea268d5..0000000 --- a/model/dto/data/data_fetch_dto.go +++ /dev/null @@ -1,99 +0,0 @@ -package data - -import ( - "cid/consts/data" - entity "cid/model/entity/data" - - "gitea.com/red-future/common/beans" - "github.com/gogf/gf/v2/frame/g" -) - -// ExecuteDataFetchReq 执行数据获取请求 -type ExecuteDataFetchReq struct { - g.Meta `path:"/executeDataFetch" method:"post" tags:"数据获取" summary:"执行数据获取" dc:"执行接口数据获取"` - PlatformId int64 `json:"platformId" v:"required" dc:"平台ID"` - InterfaceId int64 `json:"interfaceId" v:"required" dc:"接口ID"` - RequestParams map[string]interface{} `json:"requestParams" dc:"请求参数"` -} - -// ExecuteDataFetchRes 执行数据获取响应 -type ExecuteDataFetchRes struct { - RequestId string `json:"requestId" dc:"请求ID"` - Status string `json:"status" dc:"状态"` - Message string `json:"message" dc:"消息"` -} - -// ListDataFetchLogReq 获取数据获取日志列表请求 -type ListDataFetchLogReq struct { - g.Meta `path:"/listDataFetchLogs" method:"get" tags:"数据获取" summary:"获取数据获取日志" dc:"分页查询数据获取日志"` - *beans.Page - PlatformId int64 `json:"platformId" dc:"平台ID"` - InterfaceId int64 `json:"interfaceId" dc:"接口ID"` - RequestId string `json:"requestId" dc:"请求ID"` - Status data.FetchStatus `json:"status" dc:"执行状态"` - StartTime int64 `json:"startTime" dc:"开始时间(时间戳)"` - EndTime int64 `json:"endTime" dc:"结束时间(时间戳)"` -} - -// ListDataFetchLogRes 获取数据获取日志列表响应 -type ListDataFetchLogRes struct { - List []DataFetchLogItem `json:"list" dc:"日志列表"` - Total int `json:"total" dc:"总数"` -} - -type DataFetchLogItem struct { - Id int64 `json:"id,string"` - PlatformId int64 `json:"platformId"` - PlatformName string `json:"platformName"` - InterfaceId int64 `json:"interfaceId"` - InterfaceName string `json:"interfaceName"` - RequestId string `json:"requestId"` - Status data.FetchStatus `json:"status"` - StatusName string `json:"statusName"` - StartTime int64 `json:"startTime"` - EndTime int64 `json:"endTime"` - Duration int `json:"duration"` - ErrorMessage string `json:"errorMessage"` - RetryCount int `json:"retryCount"` - CreatedAt int64 `json:"createdAt"` -} - -// GetDataFetchLogReq 获取数据获取日志详情请求 -type GetDataFetchLogReq struct { - g.Meta `path:"/getDataFetchLog" method:"get" tags:"数据获取" summary:"获取数据获取日志详情" dc:"获取数据获取日志详情"` - Id int64 `json:"id" v:"required" dc:"日志ID"` -} - -// GetDataFetchLogRes 获取数据获取日志详情响应 -type GetDataFetchLogRes struct { - *entity.DataFetchLog - PlatformName string `json:"platformName,omitempty"` - InterfaceName string `json:"interfaceName,omitempty"` -} - -// BatchExecuteDataFetchReq 批量执行数据获取请求 -type BatchExecuteDataFetchReq struct { - g.Meta `path:"/batchExecuteDataFetch" method:"post" tags:"数据获取" summary:"批量执行数据获取" dc:"批量执行接口数据获取"` - InterfaceIds []int64 `json:"interfaceIds" v:"required" dc:"接口ID列表"` - RequestParams map[string]interface{} `json:"requestParams" dc:"请求参数(所有接口共用)"` -} - -// BatchExecuteDataFetchRes 批量执行数据获取响应 -type BatchExecuteDataFetchRes struct { - SuccessCount int `json:"successCount" dc:"成功数量"` - FailedCount int `json:"failedCount" dc:"失败数量"` - RequestIds []string `json:"requestIds" dc:"请求ID列表"` -} - -// ReExecuteDataFetchReq 重新执行数据获取请求 -type ReExecuteDataFetchReq struct { - g.Meta `path:"/reExecuteDataFetch" method:"post" tags:"数据获取" summary:"重新执行数据获取" dc:"重新执行失败的数据获取"` - LogId int64 `json:"logId" v:"required" dc:"日志ID"` -} - -// ReExecuteDataFetchRes 重新执行数据获取响应 -type ReExecuteDataFetchRes struct { - RequestId string `json:"requestId" dc:"请求ID"` - Status string `json:"status" dc:"状态"` - Message string `json:"message" dc:"消息"` -} diff --git a/model/dto/data/platform_dto.go b/model/dto/data/platform_dto.go deleted file mode 100644 index 3d77fc7..0000000 --- a/model/dto/data/platform_dto.go +++ /dev/null @@ -1,91 +0,0 @@ -package data - -import ( - "cid/consts/data" - entity "cid/model/entity/data" - - "gitea.com/red-future/common/beans" - "github.com/gogf/gf/v2/frame/g" -) - -// CreatePlatformReq 创建平台请求 -type CreatePlatformReq struct { - g.Meta `path:"/createPlatform" method:"post" tags:"平台管理" summary:"创建平台" dc:"创建新的数据源平台"` - Name string `json:"name" v:"required" dc:"平台名称"` - Type data.SyncPlatform `json:"type" v:"required" dc:"平台类型"` - Status data.PlatformStatus `json:"status" dc:"平台状态" d:"active"` - Description string `json:"description" dc:"平台描述"` - AuthConfig map[string]interface{} `json:"authConfig" dc:"认证配置"` - LimitConfig map[string]interface{} `json:"limitConfig" dc:"限流配置"` - PlatformConfig map[string]interface{} `json:"platformConfig" dc:"平台专用配置"` -} - -// CreatePlatformRes 创建平台响应 -type CreatePlatformRes struct { - Id int64 `json:"id" dc:"平台ID"` -} - -// ListPlatformReq 获取平台列表请求 -type ListPlatformReq struct { - g.Meta `path:"/listPlatforms" method:"get" tags:"平台管理" summary:"获取平台列表" dc:"分页查询平台列表"` - *beans.Page - Name string `json:"name" dc:"平台名称"` - Type data.SyncPlatform `json:"type" dc:"平台类型"` - Status data.PlatformStatus `json:"status" dc:"平台状态"` - Keyword string `json:"keyword" dc:"关键字(搜索平台名称)"` -} - -// ListPlatformRes 获取平台列表响应 -type ListPlatformRes struct { - List []PlatformItem `json:"list" dc:"平台列表"` - Total int `json:"total" dc:"总数"` -} - -type PlatformItem struct { - Id int64 `json:"id,string"` - Name string `json:"name"` - Type data.SyncPlatform `json:"type"` - TypeName string `json:"typeName"` - Status data.PlatformStatus `json:"status"` - StatusName string `json:"statusName"` - Description string `json:"description"` - CreatedAt int64 `json:"createdAt"` - UpdatedAt int64 `json:"updatedAt"` -} - -// GetPlatformReq 获取平台详情请求 -type GetPlatformReq struct { - g.Meta `path:"/getPlatform" method:"get" tags:"平台管理" summary:"获取平台详情" dc:"获取平台详情"` - Id int64 `json:"id" v:"required" dc:"平台ID"` -} - -// GetPlatformRes 获取平台详情响应 -type GetPlatformRes struct { - *entity.Platform -} - -// UpdatePlatformReq 更新平台请求 -type UpdatePlatformReq struct { - g.Meta `path:"/updatePlatform" method:"put" tags:"平台管理" summary:"更新平台" dc:"更新平台信息"` - Id int64 `json:"id" v:"required" dc:"平台ID"` - Name string `json:"name" dc:"平台名称"` - Type data.SyncPlatform `json:"type" dc:"平台类型"` - Status data.PlatformStatus `json:"status,omitempty" dc:"平台状态"` - Description string `json:"description" dc:"平台描述"` - AuthConfig map[string]interface{} `json:"authConfig" dc:"认证配置"` - LimitConfig map[string]interface{} `json:"limitConfig" dc:"限流配置"` - PlatformConfig map[string]interface{} `json:"platformConfig" dc:"平台专用配置"` -} - -// DeletePlatformReq 删除平台请求 -type DeletePlatformReq struct { - g.Meta `path:"/deletePlatform" method:"delete" tags:"平台管理" summary:"删除平台" dc:"删除平台"` - Id int64 `json:"id" v:"required" dc:"平台ID"` -} - -// UpdatePlatformStatusReq 更新平台状态请求 -type UpdatePlatformStatusReq struct { - g.Meta `path:"/updatePlatformStatus" method:"put" tags:"平台管理" summary:"更新平台状态" dc:"更新平台状态"` - Id int64 `json:"id" v:"required" dc:"平台ID"` - Status data.PlatformStatus `json:"status" v:"required|in:active,inactive" dc:"状态:active启用/inactive停用"` -} diff --git a/model/dto/mapping/data_mapping_dto.go b/model/dto/mapping/data_mapping_dto.go deleted file mode 100644 index c8022ba..0000000 --- a/model/dto/mapping/data_mapping_dto.go +++ /dev/null @@ -1,125 +0,0 @@ -package mapping - -import ( - "cid/consts/mapping" - entity "cid/model/entity/mapping" - - "gitea.com/red-future/common/beans" - "github.com/gogf/gf/v2/frame/g" -) - -// CreateDataMappingReq 创建数据映射请求 -type CreateDataMappingReq struct { - g.Meta `path:"/createDataMapping" method:"post" tags:"数据映射" summary:"创建数据映射" dc:"创建数据映射规则"` - PlatformId int64 `json:"platformId" v:"required" dc:"平台ID"` - InterfaceId int64 `json:"interfaceId" v:"required" dc:"接口ID"` - SourceField string `json:"sourceField" v:"required" dc:"源字段"` - TargetField string `json:"targetField" v:"required" dc:"目标字段"` - FieldType string `json:"fieldType" v:"required" dc:"字段类型"` - DefaultValue string `json:"defaultValue" dc:"默认值"` - TransformRule map[string]interface{} `json:"transformRule" dc:"转换规则"` - Priority int `json:"priority" dc:"优先级" d:"0"` - Status mapping.MappingStatus `json:"status" dc:"状态" d:"active"` -} - -// CreateDataMappingRes 创建数据映射响应 -type CreateDataMappingRes struct { - Id int64 `json:"id" dc:"映射ID"` -} - -// ListDataMappingReq 获取数据映射列表请求 -type ListDataMappingReq struct { - g.Meta `path:"/listDataMappings" method:"get" tags:"数据映射" summary:"获取数据映射列表" dc:"分页查询数据映射列表"` - *beans.Page - PlatformId int64 `json:"platformId" dc:"平台ID"` - InterfaceId int64 `json:"interfaceId" dc:"接口ID"` - SourceField string `json:"sourceField" dc:"源字段"` - TargetField string `json:"targetField" dc:"目标字段"` - Status mapping.MappingStatus `json:"status" dc:"状态"` -} - -// ListDataMappingRes 获取数据映射列表响应 -type ListDataMappingRes struct { - List []DataMappingItem `json:"list" dc:"映射列表"` - Total int `json:"total" dc:"总数"` -} - -type DataMappingItem struct { - Id int64 `json:"id,string"` - PlatformId int64 `json:"platformId"` - PlatformName string `json:"platformName"` - InterfaceId int64 `json:"interfaceId"` - InterfaceName string `json:"interfaceName"` - SourceField string `json:"sourceField"` - TargetField string `json:"targetField"` - FieldType string `json:"fieldType"` - DefaultValue string `json:"defaultValue"` - TransformRule map[string]interface{} `json:"transformRule"` - Priority int `json:"priority"` - Status mapping.MappingStatus `json:"status"` - StatusName string `json:"statusName"` - CreatedAt int64 `json:"createdAt"` - UpdatedAt int64 `json:"updatedAt"` -} - -// GetDataMappingReq 获取数据映射详情请求 -type GetDataMappingReq struct { - g.Meta `path:"/getDataMapping" method:"get" tags:"数据映射" summary:"获取数据映射详情" dc:"获取数据映射详情"` - Id int64 `json:"id" v:"required" dc:"映射ID"` -} - -// GetDataMappingRes 获取数据映射详情响应 -type GetDataMappingRes struct { - *entity.DataMapping - PlatformName string `json:"platformName,omitempty"` - InterfaceName string `json:"interfaceName,omitempty"` -} - -// UpdateDataMappingReq 更新数据映射请求 -type UpdateDataMappingReq struct { - g.Meta `path:"/updateDataMapping" method:"put" tags:"数据映射" summary:"更新数据映射" dc:"更新数据映射规则"` - Id int64 `json:"id" v:"required" dc:"映射ID"` - PlatformId int64 `json:"platformId" dc:"平台ID"` - InterfaceId int64 `json:"interfaceId" dc:"接口ID"` - SourceField string `json:"sourceField" dc:"源字段"` - TargetField string `json:"targetField" dc:"目标字段"` - FieldType string `json:"fieldType" dc:"字段类型"` - DefaultValue string `json:"defaultValue" dc:"默认值"` - TransformRule map[string]interface{} `json:"transformRule" dc:"转换规则"` - Priority int `json:"priority" dc:"优先级"` - Status mapping.MappingStatus `json:"status,omitempty" dc:"状态"` -} - -// DeleteDataMappingReq 删除数据映射请求 -type DeleteDataMappingReq struct { - g.Meta `path:"/deleteDataMapping" method:"delete" tags:"数据映射" summary:"删除数据映射" dc:"删除数据映射"` - Id int64 `json:"id" v:"required" dc:"映射ID"` -} - -// BatchCreateDataMappingReq 批量创建数据映射请求 -type BatchCreateDataMappingReq struct { - g.Meta `path:"/batchCreateDataMappings" method:"post" tags:"数据映射" summary:"批量创建数据映射" dc:"批量创建数据映射规则"` - PlatformId int64 `json:"platformId" v:"required" dc:"平台ID"` - InterfaceId int64 `json:"interfaceId" v:"required" dc:"接口ID"` - Mappings []CreateDataMappingReq `json:"mappings" v:"required" dc:"映射规则列表"` -} - -// BatchCreateDataMappingRes 批量创建数据映射响应 -type BatchCreateDataMappingRes struct { - SuccessCount int `json:"successCount" dc:"成功数量"` - FailedCount int `json:"failedCount" dc:"失败数量"` - Ids []int64 `json:"ids" dc:"映射ID列表"` -} - -// ExecuteDataMappingReq 执行数据映射请求 -type ExecuteDataMappingReq struct { - g.Meta `path:"/executeDataMapping" method:"post" tags:"数据映射" summary:"执行数据映射" dc:"执行数据字段映射"` - InterfaceId int64 `json:"interfaceId" v:"required" dc:"接口ID"` - SourceData map[string]interface{} `json:"sourceData" v:"required" dc:"源数据"` -} - -// ExecuteDataMappingRes 执行数据映射响应 -type ExecuteDataMappingRes struct { - TargetData map[string]interface{} `json:"targetData" dc:"目标数据"` - AppliedRules []string `json:"appliedRules" dc:"应用的映射规则"` -} diff --git a/model/entity/app/application.go b/model/entity/app/application.go deleted file mode 100644 index 0fb2ff6..0000000 --- a/model/entity/app/application.go +++ /dev/null @@ -1,49 +0,0 @@ -package app - -import ( - consts "cid/consts/app" - "gitea.com/red-future/common/beans" -) - -// Application 应用管理实体 -type Application struct { - beans.SQLBaseDO `orm:",inherit"` - // 基础信息 - Name string `orm:"name" json:"name" description:"应用名称"` - AppCode string `orm:"app_code" json:"appCode" description:"应用编码(唯一标识)"` - Type consts.AppType `orm:"type" json:"type" description:"应用类型"` - Status consts.AppStatus `orm:"status" json:"status" description:"应用状态:active启用/inactive停用"` - Description string `orm:"description" json:"description" description:"应用描述"` - // 接入配置 (JSONB) - AccessConfig map[string]interface{} `orm:"access_config" json:"accessConfig" description:"接入配置"` - // 限流配置 (JSONB) - LimitConfig map[string]interface{} `orm:"limit_config" json:"limitConfig" description:"限流配置"` - // 回调配置 (JSONB) - CallbackConfig map[string]interface{} `orm:"callback_config" json:"callbackConfig" description:"回调配置"` -} - -// ApplicationCol 应用表字段定义 -type ApplicationCol struct { - beans.SQLBaseCol - Name string - AppCode string - Type string - Status string - Description string - AccessConfig string - LimitConfig string - CallbackConfig string -} - -// ApplicationCols 应用表字段常量 -var ApplicationCols = ApplicationCol{ - SQLBaseCol: beans.DefSQLBaseCol, - Name: "name", - AppCode: "app_code", - Type: "type", - Status: "status", - Description: "description", - AccessConfig: "access_config", - LimitConfig: "limit_config", - CallbackConfig: "callback_config", -} diff --git a/model/entity/data/api_interface.go b/model/entity/data/api_interface.go deleted file mode 100644 index ea35de6..0000000 --- a/model/entity/data/api_interface.go +++ /dev/null @@ -1,56 +0,0 @@ -package data - -import ( - consts "cid/consts/data" - "gitea.com/red-future/common/beans" -) - -// ApiInterface 接口管理实体 -type ApiInterface struct { - beans.SQLBaseDO `orm:",inherit"` - // 基础信息 - PlatformId int64 `orm:"platform_id" json:"platformId" description:"所属平台ID"` - Name string `orm:"name" json:"name" description:"接口名称"` - Code string `orm:"code" json:"code" description:"接口编码"` - Url string `orm:"url" json:"url" description:"接口地址"` - Method consts.ApiMethod `orm:"method" json:"method" description:"请求方法:GET/POST/PUT/DELETE等"` - Status consts.PlatformStatus `orm:"status" json:"status" description:"接口状态:active启用/inactive停用"` - // 认证类型 - AuthType string `orm:"auth_type" json:"authType" description:"认证类型:oauth2/apikey/basic等"` - // 请求配置 (JSONB) - RequestConfig map[string]interface{} `orm:"request_config" json:"requestConfig" description:"请求配置"` - // 响应配置 (JSONB) - ResponseConfig map[string]interface{} `orm:"response_config" json:"responseConfig" description:"响应配置"` - // 独立限流配置 (JSONB) - LimitConfig map[string]interface{} `orm:"limit_config" json:"limitConfig" description:"接口独立限流配置(可选,覆盖平台配置)"` -} - -// ApiInterfaceCol 接口表字段定义 -type ApiInterfaceCol struct { - beans.SQLBaseCol - PlatformId string - Name string - Code string - Url string - Method string - Status string - AuthType string - RequestConfig string - ResponseConfig string - LimitConfig string -} - -// ApiInterfaceCols 接口表字段常量 -var ApiInterfaceCols = ApiInterfaceCol{ - SQLBaseCol: beans.DefSQLBaseCol, - PlatformId: "platform_id", - Name: "name", - Code: "code", - Url: "url", - Method: "method", - Status: "status", - AuthType: "auth_type", - RequestConfig: "request_config", - ResponseConfig: "response_config", - LimitConfig: "limit_config", -} diff --git a/model/entity/data/data_fetch_log.go b/model/entity/data/data_fetch_log.go deleted file mode 100644 index 16227ba..0000000 --- a/model/entity/data/data_fetch_log.go +++ /dev/null @@ -1,58 +0,0 @@ -package data - -import ( - consts "cid/consts/data" - "gitea.com/red-future/common/beans" -) - -// DataFetchLog 数据获取日志实体 -type DataFetchLog struct { - beans.SQLBaseDO `orm:",inherit"` - // 关联信息 - PlatformId int64 `orm:"platform_id" json:"platformId" description:"平台ID"` - InterfaceId int64 `orm:"interface_id" json:"interfaceId" description:"接口ID"` - RequestId string `orm:"request_id" json:"requestId" description:"请求ID"` - // 执行状态 - Status consts.FetchStatus `orm:"status" json:"status" description:"执行状态:pending/running/success/failed/rate_limit"` - StartTime int64 `orm:"start_time" json:"startTime" description:"开始时间(时间戳)"` - EndTime int64 `orm:"end_time" json:"endTime" description:"结束时间(时间戳)"` - Duration int `orm:"duration" json:"duration" description:"执行时长(毫秒)"` - // 请求响应数据 - RequestConfig map[string]interface{} `orm:"request_config" json:"requestConfig" description:"请求配置参数"` - ResponseData string `orm:"response_data" json:"responseData" description:"响应数据(JSON)"` - ErrorMessage string `orm:"error_message" json:"errorMessage" description:"错误信息"` - // 重试信息 - RetryCount int `orm:"retry_count" json:"retryCount" description:"重试次数"` -} - -// DataFetchLogCol 数据获取日志表字段定义 -type DataFetchLogCol struct { - beans.SQLBaseCol - PlatformId string - InterfaceId string - RequestId string - Status string - StartTime string - EndTime string - Duration string - RequestConfig string - ResponseData string - ErrorMessage string - RetryCount string -} - -// DataFetchLogCols 数据获取日志表字段常量 -var DataFetchLogCols = DataFetchLogCol{ - SQLBaseCol: beans.DefSQLBaseCol, - PlatformId: "platform_id", - InterfaceId: "interface_id", - RequestId: "request_id", - Status: "status", - StartTime: "start_time", - EndTime: "end_time", - Duration: "duration", - RequestConfig: "request_config", - ResponseData: "response_data", - ErrorMessage: "error_message", - RetryCount: "retry_count", -} diff --git a/model/entity/data/platform.go b/model/entity/data/platform.go deleted file mode 100644 index cedb058..0000000 --- a/model/entity/data/platform.go +++ /dev/null @@ -1,46 +0,0 @@ -package data - -import ( - consts "cid/consts/data" - "gitea.com/red-future/common/beans" -) - -// Platform 平台管理实体 -type Platform struct { - beans.SQLBaseDO `orm:",inherit"` - // 基础信息 - Name string `orm:"name" json:"name" description:"平台名称"` - Type consts.SyncPlatform `orm:"type" json:"type" description:"平台类型"` - Status consts.PlatformStatus `orm:"status" json:"status" description:"平台状态:active启用/inactive停用"` - Description string `orm:"description" json:"description" description:"平台描述"` - // 认证配置 (JSONB) - AuthConfig map[string]interface{} `orm:"auth_config" json:"authConfig" description:"认证配置"` - // 限流配置 (JSONB) - LimitConfig map[string]interface{} `orm:"limit_config" json:"limitConfig" description:"限流配置"` - // 平台专用配置 (JSONB) - PlatformConfig map[string]interface{} `orm:"platform_config" json:"platformConfig" description:"平台专用配置"` -} - -// PlatformCol 平台表字段定义 -type PlatformCol struct { - beans.SQLBaseCol - Name string - Type string - Status string - Description string - AuthConfig string - LimitConfig string - PlatformConfig string -} - -// PlatformCols 平台表字段常量 -var PlatformCols = PlatformCol{ - SQLBaseCol: beans.DefSQLBaseCol, - Name: "name", - Type: "type", - Status: "status", - Description: "description", - AuthConfig: "auth_config", - LimitConfig: "limit_config", - PlatformConfig: "platform_config", -} diff --git a/model/entity/mapping/data_mapping.go b/model/entity/mapping/data_mapping.go deleted file mode 100644 index 542b6f3..0000000 --- a/model/entity/mapping/data_mapping.go +++ /dev/null @@ -1,52 +0,0 @@ -package mapping - -import ( - "cid/consts/mapping" - "gitea.com/red-future/common/beans" -) - -// DataMapping 数据映射实体 -type DataMapping struct { - beans.SQLBaseDO `orm:",inherit"` - // 关联信息 - PlatformId int64 `orm:"platform_id" json:"platformId" description:"平台ID"` - InterfaceId int64 `orm:"interface_id" json:"interfaceId" description:"接口ID"` - // 映射规则 - SourceField string `orm:"source_field" json:"sourceField" description:"源字段(接口返回字段)"` - TargetField string `orm:"target_field" json:"targetField" description:"目标字段(本地表字段)"` - FieldType string `orm:"field_type" json:"fieldType" description:"字段类型:string/int/float/bool/array/object"` - DefaultValue string `orm:"default_value" json:"defaultValue" description:"默认值"` - // 转换规则 (JSONB) - TransformRule map[string]interface{} `orm:"transform_rule" json:"transformRule" description:"转换规则"` - // 优先级和状态 - Priority int `orm:"priority" json:"priority" description:"优先级(数字越小优先级越高)"` - Status mapping.MappingStatus `orm:"status" json:"status" description:"状态:active启用/inactive停用"` -} - -// DataMappingCol 数据映射表字段定义 -type DataMappingCol struct { - beans.SQLBaseCol - PlatformId string - InterfaceId string - SourceField string - TargetField string - FieldType string - DefaultValue string - TransformRule string - Priority string - Status string -} - -// DataMappingCols 数据映射表字段常量 -var DataMappingCols = DataMappingCol{ - SQLBaseCol: beans.DefSQLBaseCol, - PlatformId: "platform_id", - InterfaceId: "interface_id", - SourceField: "source_field", - TargetField: "target_field", - FieldType: "field_type", - DefaultValue: "default_value", - TransformRule: "transform_rule", - Priority: "priority", - Status: "status", -} diff --git a/service/app/application_service.go b/service/app/application_service.go deleted file mode 100644 index 4b057c1..0000000 --- a/service/app/application_service.go +++ /dev/null @@ -1,178 +0,0 @@ -package app - -import ( - consts "cid/consts/app" - dao "cid/dao/app" - dto "cid/model/dto/app" - entity "cid/model/entity/app" - "context" - "errors" - - "github.com/gogf/gf/v2/util/gconv" -) - -type applicationService struct{} - -// Application 应用服务 -var Application = new(applicationService) - -// Create 创建应用 -func (s *applicationService) Create(ctx context.Context, req *dto.CreateApplicationReq) (res *dto.CreateApplicationRes, err error) { - // 检查应用名称是否重复 - count, err := dao.Application.Count(ctx, &dto.ListApplicationReq{Name: req.Name}) - if err != nil { - return - } - if count > 0 { - return nil, errors.New("应用名称已存在") - } - - // 检查应用编码是否重复 - count, err = dao.Application.Count(ctx, &dto.ListApplicationReq{AppCode: req.AppCode}) - if err != nil { - return - } - if count > 0 { - return nil, errors.New("应用编码已存在") - } - - // 插入数据库 - id, err := dao.Application.Insert(ctx, req) - if err != nil { - return - } - res = &dto.CreateApplicationRes{ - Id: id, - } - return -} - -// List 获取应用列表 -func (s *applicationService) List(ctx context.Context, req *dto.ListApplicationReq) (res *dto.ListApplicationRes, err error) { - applicationList, total, err := dao.Application.List(ctx, req) - if err != nil { - return - } - - // 组装响应数据 - list := make([]dto.ApplicationItem, 0, len(applicationList)) - for _, item := range applicationList { - list = append(list, dto.ApplicationItem{ - Id: item.Id, - Name: item.Name, - AppCode: item.AppCode, - Type: item.Type, - TypeName: s.getTypeName(item.Type), - Status: item.Status, - StatusName: s.getStatusName(item.Status), - Description: item.Description, - CreatedAt: item.CreatedAt.Unix(), - UpdatedAt: item.UpdatedAt.Unix(), - }) - } - - res = &dto.ListApplicationRes{ - List: list, - Total: total, - } - return -} - -// GetOne 获取单个应用 -func (s *applicationService) GetOne(ctx context.Context, req *dto.GetApplicationReq) (res *dto.GetApplicationRes, err error) { - application, err := dao.Application.GetOne(ctx, req) - if err != nil { - return - } - - var applicationEntity *entity.Application - if err = gconv.Struct(application, &applicationEntity); err != nil { - return - } - - return &dto.GetApplicationRes{ - Application: applicationEntity, - }, nil -} - -// Update 更新应用 -func (s *applicationService) Update(ctx context.Context, req *dto.UpdateApplicationReq) (err error) { - // 检查应用是否存在 - exist, err := dao.Application.GetOne(ctx, &dto.GetApplicationReq{Id: req.Id}) - if err != nil || exist == nil { - return errors.New("应用不存在") - } - - // 如果修改了名称,检查新名称是否重复 - if req.Name != "" && req.Name != exist.Name { - count, err := dao.Application.Count(ctx, &dto.ListApplicationReq{Name: req.Name}) - if err != nil { - return err - } - if count > 0 { - return errors.New("应用名称已存在") - } - } - - // 如果修改了应用编码,检查新编码是否重复 - if req.AppCode != "" && req.AppCode != exist.AppCode { - count, err := dao.Application.Count(ctx, &dto.ListApplicationReq{AppCode: req.AppCode}) - if err != nil { - return err - } - if count > 0 { - return errors.New("应用编码已存在") - } - } - - _, err = dao.Application.Update(ctx, req) - return -} - -// UpdateStatus 更新应用状态 -func (s *applicationService) UpdateStatus(ctx context.Context, req *dto.UpdateApplicationStatusReq) (err error) { - _, err = dao.Application.UpdateStatus(ctx, req.Id, req.Status.String()) - return -} - -// Delete 删除应用 -func (s *applicationService) Delete(ctx context.Context, req *dto.DeleteApplicationReq) (err error) { - // TODO: 检查是否存在关联的数据,防止误删 - // 例如: 检查该应用是否有关联的广告活动等 - - _, err = dao.Application.Delete(ctx, req) - return -} - -// GetByAppCode 根据应用编码获取应用 -func (s *applicationService) GetByAppCode(ctx context.Context, appCode string) (res *entity.Application, err error) { - return dao.Application.GetByAppCode(ctx, appCode) -} - -// getTypeName 获取类型名称 -func (s *applicationService) getTypeName(appType consts.AppType) string { - typeNames := map[consts.AppType]string{ - consts.AppTypeWeb: "Web应用", - consts.AppTypeMobile: "移动应用", - consts.AppTypeMiniApp: "小程序", - consts.AppTypeH5: "H5应用", - consts.AppTypeDesktop: "桌面应用", - consts.AppTypeThirdParty: "第三方应用", - } - if name, ok := typeNames[appType]; ok { - return name - } - return string(appType) -} - -// getStatusName 获取状态名称 -func (s *applicationService) getStatusName(status consts.AppStatus) string { - statusNames := map[consts.AppStatus]string{ - consts.AppStatusActive: "启用", - consts.AppStatusInactive: "停用", - } - if name, ok := statusNames[status]; ok { - return name - } - return string(status) -} diff --git a/service/data/api_interface_service.go b/service/data/api_interface_service.go deleted file mode 100644 index dddc3c3..0000000 --- a/service/data/api_interface_service.go +++ /dev/null @@ -1,191 +0,0 @@ -package data - -import ( - consts "cid/consts/data" - dao "cid/dao/data" - dto "cid/model/dto/data" - entity "cid/model/entity/data" - "context" - "errors" -) - -type apiInterfaceService struct{} - -// ApiInterface 接口服务 -var ApiInterface = new(apiInterfaceService) - -// Create 创建接口 -func (s *apiInterfaceService) Create(ctx context.Context, req *dto.CreateApiInterfaceReq) (res *dto.CreateApiInterfaceRes, err error) { - // 检查平台是否存在 - _, err = dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: req.PlatformId}) - if err != nil { - return nil, errors.New("平台不存在") - } - - // 检查接口编码在同一平台下是否重复 - interfaces, _, err := dao.ApiInterface.List(ctx, &dto.ListApiInterfaceReq{ - PlatformId: req.PlatformId, - Code: req.Code, - }) - if err != nil { - return - } - if len(interfaces) > 0 { - return nil, errors.New("接口编码在该平台下已存在") - } - - // 插入数据库 - id, err := dao.ApiInterface.Insert(ctx, req) - if err != nil { - return - } - res = &dto.CreateApiInterfaceRes{ - Id: id, - } - return -} - -// List 获取接口列表 -func (s *apiInterfaceService) List(ctx context.Context, req *dto.ListApiInterfaceReq) (res *dto.ListApiInterfaceRes, err error) { - apiList, total, err := dao.ApiInterface.List(ctx, req) - if err != nil { - return - } - - // 获取平台ID列表用于批量查询 - platformIds := make([]int64, 0) - for _, item := range apiList { - if item.PlatformId > 0 { - platformIds = append(platformIds, item.PlatformId) - } - } - - // 批量获取平台信息 - platformMap := make(map[int64]string) - if len(platformIds) > 0 { - platforms, _, err := dao.Platform.List(ctx, &dto.ListPlatformReq{}) - if err == nil { - for _, p := range platforms { - platformMap[p.Id] = p.Name - } - } - } - - // 组装响应数据 - list := make([]dto.ApiInterfaceItem, 0, len(apiList)) - for _, item := range apiList { - platformName := "" - if name, ok := platformMap[item.PlatformId]; ok { - platformName = name - } - - list = append(list, dto.ApiInterfaceItem{ - Id: item.Id, - PlatformId: item.PlatformId, - PlatformName: platformName, - Name: item.Name, - Code: item.Code, - Url: item.Url, - Method: item.Method, - Status: item.Status, - StatusName: s.getStatusName(item.Status), - CreatedAt: item.CreatedAt.Unix(), - UpdatedAt: item.UpdatedAt.Unix(), - }) - } - - res = &dto.ListApiInterfaceRes{ - List: list, - Total: total, - } - return -} - -// GetOne 获取单个接口 -func (s *apiInterfaceService) GetOne(ctx context.Context, req *dto.GetApiInterfaceReq) (res *dto.GetApiInterfaceRes, err error) { - apiInterface, err := dao.ApiInterface.GetOne(ctx, req) - if err != nil { - return - } - - // 获取平台名称 - var platformName string - if apiInterface.PlatformId > 0 { - platform, _ := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: apiInterface.PlatformId}) - if platform != nil { - platformName = platform.Name - } - } - - return &dto.GetApiInterfaceRes{ - ApiInterface: apiInterface, - PlatformName: platformName, - }, nil -} - -// Update 更新接口 -func (s *apiInterfaceService) Update(ctx context.Context, req *dto.UpdateApiInterfaceReq) (err error) { - // 检查接口是否存在 - exist, err := dao.ApiInterface.GetOne(ctx, &dto.GetApiInterfaceReq{Id: req.Id}) - if err != nil || exist == nil { - return errors.New("接口不存在") - } - - // 如果修改了平台,检查平台是否存在 - if req.PlatformId > 0 && req.PlatformId != exist.PlatformId { - _, err := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: req.PlatformId}) - if err != nil { - return errors.New("平台不存在") - } - } - - // 如果修改了编码,检查编码是否重复 - if req.Code != "" && req.Code != exist.Code { - platformId := req.PlatformId - if platformId == 0 { - platformId = exist.PlatformId - } - interfaces, _, err := dao.ApiInterface.List(ctx, &dto.ListApiInterfaceReq{ - PlatformId: platformId, - Code: req.Code, - }) - if err != nil { - return err - } - if len(interfaces) > 0 { - return errors.New("接口编码在该平台下已存在") - } - } - - _, err = dao.ApiInterface.Update(ctx, req) - return -} - -// UpdateStatus 更新接口状态 -func (s *apiInterfaceService) UpdateStatus(ctx context.Context, req *dto.UpdateApiInterfaceStatusReq) (err error) { - _, err = dao.ApiInterface.UpdateStatus(ctx, req.Id, req.Status.String()) - return -} - -// Delete 删除接口 -func (s *apiInterfaceService) Delete(ctx context.Context, req *dto.DeleteApiInterfaceReq) (err error) { - _, err = dao.ApiInterface.Delete(ctx, req) - return -} - -// GetByIds 根据ID列表获取接口 -func (s *apiInterfaceService) GetByIds(ctx context.Context, ids []int64) (res []entity.ApiInterface, err error) { - return dao.ApiInterface.GetByIds(ctx, ids) -} - -// getStatusName 获取状态名称 -func (s *apiInterfaceService) getStatusName(status consts.PlatformStatus) string { - statusNames := map[consts.PlatformStatus]string{ - consts.PlatformStatusActive: "启用", - consts.PlatformStatusInactive: "停用", - } - if name, ok := statusNames[status]; ok { - return name - } - return string(status) -} diff --git a/service/data/data_fetch_service.go b/service/data/data_fetch_service.go deleted file mode 100644 index da08fea..0000000 --- a/service/data/data_fetch_service.go +++ /dev/null @@ -1,316 +0,0 @@ -package data - -import ( - consts "cid/consts/data" - dao "cid/dao/data" - dto "cid/model/dto/data" - entity "cid/model/entity/data" - "context" - "fmt" - "time" - - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/os/grpool" - "github.com/gogf/gf/v2/util/guid" -) - -type dataFetchService struct{} - -// DataFetch 数据获取服务 -var DataFetch = new(dataFetchService) - -// FetchPool 数据获取协程池,限制并发数避免goroutine爆炸 -var FetchPool = grpool.New(10) - -// Execute 执行数据获取 -func (s *dataFetchService) Execute(ctx context.Context, req *dto.ExecuteDataFetchReq) (res *dto.ExecuteDataFetchRes, err error) { - // 检查接口是否存在 - apiInterface, err := dao.ApiInterface.GetOne(ctx, &dto.GetApiInterfaceReq{Id: req.InterfaceId}) - if err != nil || apiInterface == nil { - return nil, fmt.Errorf("接口不存在") - } - - // 检查接口状态 - if apiInterface.Status != consts.PlatformStatusActive { - return nil, fmt.Errorf("接口未启用") - } - - // 检查平台是否存在 - platform, err := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: apiInterface.PlatformId}) - if err != nil || platform == nil { - return nil, fmt.Errorf("平台不存在") - } - - // 检查平台状态 - if platform.Status != consts.PlatformStatusActive { - return nil, fmt.Errorf("平台未启用") - } - - // 生成请求ID - requestId := guid.S() - startTime := time.Now().UnixMilli() - - // 创建数据获取日志 - fetchLog := &entity.DataFetchLog{ - PlatformId: req.PlatformId, - InterfaceId: req.InterfaceId, - RequestId: requestId, - Status: consts.FetchStatusPending, - StartTime: startTime, - RequestConfig: req.RequestParams, - RetryCount: 0, - } - - logId, err := dao.DataFetchLog.Insert(ctx, fetchLog) - if err != nil { - return nil, fmt.Errorf("创建日志失败: %v", err) - } - - // 使用协程池异步执行数据获取 - asyncCtx := context.WithoutCancel(ctx) - FetchPool.Add(asyncCtx, func(ctx context.Context) { - s.executeFetch(ctx, logId, requestId, platform, apiInterface, req.RequestParams, startTime) - }) - - return &dto.ExecuteDataFetchRes{ - RequestId: requestId, - Status: string(consts.FetchStatusPending), - Message: "任务已提交", - }, nil -} - -// BatchExecute 批量执行数据获取 -func (s *dataFetchService) BatchExecute(ctx context.Context, req *dto.BatchExecuteDataFetchReq) (res *dto.BatchExecuteDataFetchRes, err error) { - var requestIds []string - successCount := 0 - failedCount := 0 - - for _, interfaceId := range req.InterfaceIds { - executeReq := &dto.ExecuteDataFetchReq{ - PlatformId: 0, // 接口服务会自动获取 - InterfaceId: interfaceId, - RequestParams: req.RequestParams, - } - - executeRes, err := s.Execute(ctx, executeReq) - if err != nil { - failedCount++ - g.Log().Error(ctx, "批量执行失败", g.Map{ - "interfaceId": interfaceId, - "error": err.Error(), - }) - } else { - successCount++ - requestIds = append(requestIds, executeRes.RequestId) - } - } - - return &dto.BatchExecuteDataFetchRes{ - SuccessCount: successCount, - FailedCount: failedCount, - RequestIds: requestIds, - }, nil -} - -// List 获取数据获取日志列表 -func (s *dataFetchService) List(ctx context.Context, req *dto.ListDataFetchLogReq) (res *dto.ListDataFetchLogRes, err error) { - logList, total, err := dao.DataFetchLog.List(ctx, req) - if err != nil { - return - } - - // 获取平台和接口ID列表 - platformIds := make([]int64, 0) - interfaceIds := make([]int64, 0) - for _, item := range logList { - if item.PlatformId > 0 { - platformIds = append(platformIds, item.PlatformId) - } - if item.InterfaceId > 0 { - interfaceIds = append(interfaceIds, item.InterfaceId) - } - } - - // 批量获取平台和接口信息 - platformMap := make(map[int64]string) - interfaceMap := make(map[int64]string) - if len(platformIds) > 0 { - platforms, _, err := dao.Platform.List(ctx, &dto.ListPlatformReq{}) - if err == nil { - for _, p := range platforms { - platformMap[p.Id] = p.Name - } - } - } - if len(interfaceIds) > 0 { - interfaces, _, err := dao.ApiInterface.List(ctx, &dto.ListApiInterfaceReq{}) - if err == nil { - for _, i := range interfaces { - interfaceMap[i.Id] = i.Name - } - } - } - - // 组装响应数据 - list := make([]dto.DataFetchLogItem, 0, len(logList)) - for _, item := range logList { - platformName := "" - if name, ok := platformMap[item.PlatformId]; ok { - platformName = name - } - interfaceName := "" - if name, ok := interfaceMap[item.InterfaceId]; ok { - interfaceName = name - } - - list = append(list, dto.DataFetchLogItem{ - Id: item.Id, - PlatformId: item.PlatformId, - PlatformName: platformName, - InterfaceId: item.InterfaceId, - InterfaceName: interfaceName, - RequestId: item.RequestId, - Status: item.Status, - StatusName: s.getStatusName(item.Status), - StartTime: item.StartTime, - EndTime: item.EndTime, - Duration: item.Duration, - ErrorMessage: item.ErrorMessage, - RetryCount: item.RetryCount, - CreatedAt: item.CreatedAt.Unix(), - }) - } - - res = &dto.ListDataFetchLogRes{ - List: list, - Total: total, - } - return -} - -// GetOne 获取单个数据获取日志 -func (s *dataFetchService) GetOne(ctx context.Context, req *dto.GetDataFetchLogReq) (res *dto.GetDataFetchLogRes, err error) { - fetchLog, err := dao.DataFetchLog.GetOne(ctx, req) - if err != nil { - return - } - - // 获取平台和接口名称 - var platformName, interfaceName string - if fetchLog.PlatformId > 0 { - platform, _ := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: fetchLog.PlatformId}) - if platform != nil { - platformName = platform.Name - } - } - if fetchLog.InterfaceId > 0 { - apiInterface, _ := dao.ApiInterface.GetOne(ctx, &dto.GetApiInterfaceReq{Id: fetchLog.InterfaceId}) - if apiInterface != nil { - interfaceName = apiInterface.Name - } - } - - return &dto.GetDataFetchLogRes{ - DataFetchLog: fetchLog, - PlatformName: platformName, - InterfaceName: interfaceName, - }, nil -} - -// ReExecute 重新执行数据获取 -func (s *dataFetchService) ReExecute(ctx context.Context, req *dto.ReExecuteDataFetchReq) (res *dto.ReExecuteDataFetchRes, err error) { - // 获取原日志 - oldLog, err := dao.DataFetchLog.GetOne(ctx, &dto.GetDataFetchLogReq{Id: req.LogId}) - if err != nil || oldLog == nil { - return nil, fmt.Errorf("日志不存在") - } - - // 检查接口是否存在 - apiInterface, err := dao.ApiInterface.GetOne(ctx, &dto.GetApiInterfaceReq{Id: oldLog.InterfaceId}) - if err != nil || apiInterface == nil { - return nil, fmt.Errorf("接口不存在") - } - - // 检查平台是否存在 - platform, err := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: apiInterface.PlatformId}) - if err != nil || platform == nil { - return nil, fmt.Errorf("平台不存在") - } - - // 生成新的请求ID - requestId := guid.S() - startTime := time.Now().UnixMilli() - - // 创建新的数据获取日志 - fetchLog := &entity.DataFetchLog{ - PlatformId: oldLog.PlatformId, - InterfaceId: oldLog.InterfaceId, - RequestId: requestId, - Status: consts.FetchStatusPending, - StartTime: startTime, - RequestConfig: oldLog.RequestConfig, - RetryCount: oldLog.RetryCount + 1, - } - - logId, err := dao.DataFetchLog.Insert(ctx, fetchLog) - if err != nil { - return nil, fmt.Errorf("创建日志失败: %v", err) - } - - // 使用协程池异步执行数据获取 - asyncCtx := context.WithoutCancel(ctx) - FetchPool.Add(asyncCtx, func(ctx context.Context) { - s.executeFetch(ctx, logId, requestId, platform, apiInterface, oldLog.RequestConfig, startTime) - }) - - return &dto.ReExecuteDataFetchRes{ - RequestId: requestId, - Status: string(consts.FetchStatusPending), - Message: "任务已重新提交", - }, nil -} - -// executeFetch 执行实际的数据获取(在协程池中运行) -func (s *dataFetchService) executeFetch(ctx context.Context, logId int64, requestId string, platform *entity.Platform, apiInterface *entity.ApiInterface, requestParams map[string]interface{}, startTime int64) { - // 更新状态为执行中 - dao.DataFetchLog.UpdateStatus(ctx, logId, string(consts.FetchStatusRunning), 0, 0, "", "") - - // TODO: 根据平台和接口配置执行HTTP请求 - // 这里需要根据平台的限流配置进行限流控制 - // 根据接口的请求配置组装请求参数 - // 调用接口获取数据 - - // 模拟接口调用 - time.Sleep(time.Second * 2) - - // 模拟成功响应 - responseData := `{"code": 0, "message": "success", "data": {"items": []}}` - endTime := time.Now().UnixMilli() - duration := int(endTime - startTime) - - // 更新状态为成功 - dao.DataFetchLog.UpdateStatus(ctx, logId, string(consts.FetchStatusSuccess), endTime, duration, responseData, "") - - g.Log().Info(ctx, "数据获取成功", g.Map{ - "logId": logId, - "requestId": requestId, - "platform": platform.Name, - "interface": apiInterface.Name, - "duration": duration, - }) -} - -// getStatusName 获取状态名称 -func (s *dataFetchService) getStatusName(status consts.FetchStatus) string { - statusNames := map[consts.FetchStatus]string{ - consts.FetchStatusPending: "待执行", - consts.FetchStatusRunning: "执行中", - consts.FetchStatusSuccess: "成功", - consts.FetchStatusFailed: "失败", - consts.FetchStatusRateLimit: "触发限流", - } - if name, ok := statusNames[status]; ok { - return name - } - return string(status) -} diff --git a/service/data/platform_service.go b/service/data/platform_service.go deleted file mode 100644 index 9ab10af..0000000 --- a/service/data/platform_service.go +++ /dev/null @@ -1,189 +0,0 @@ -package data - -import ( - consts "cid/consts/data" - dao "cid/dao/data" - dto "cid/model/dto/data" - entity "cid/model/entity/data" - "context" - "errors" - - "github.com/gogf/gf/v2/util/gconv" -) - -type platformService struct{} - -// Platform 平台服务 -var Platform = new(platformService) - -// Create 创建平台 -func (s *platformService) Create(ctx context.Context, req *dto.CreatePlatformReq) (res *dto.CreatePlatformRes, err error) { - // 检查平台名称是否重复 - count, err := dao.Platform.Count(ctx, &dto.ListPlatformReq{Name: req.Name}) - if err != nil { - return - } - if count > 0 { - return nil, errors.New("平台名称已存在") - } - - // 检查平台类型是否重复 - count, err = dao.Platform.Count(ctx, &dto.ListPlatformReq{Type: req.Type}) - if err != nil { - return - } - if count > 0 { - return nil, errors.New("该类型平台已存在") - } - - // 插入数据库 - id, err := dao.Platform.Insert(ctx, req) - if err != nil { - return - } - res = &dto.CreatePlatformRes{ - Id: id, - } - return -} - -// List 获取平台列表 -func (s *platformService) List(ctx context.Context, req *dto.ListPlatformReq) (res *dto.ListPlatformRes, err error) { - platformList, total, err := dao.Platform.List(ctx, req) - if err != nil { - return - } - - // 组装响应数据 - list := make([]dto.PlatformItem, 0, len(platformList)) - for _, item := range platformList { - list = append(list, dto.PlatformItem{ - Id: item.Id, - Name: item.Name, - Type: item.Type, - TypeName: s.getTypeName(item.Type), - Status: item.Status, - StatusName: s.getStatusName(item.Status), - Description: item.Description, - CreatedAt: item.CreatedAt.Unix(), - UpdatedAt: item.UpdatedAt.Unix(), - }) - } - - res = &dto.ListPlatformRes{ - List: list, - Total: total, - } - return -} - -// GetOne 获取单个平台 -func (s *platformService) GetOne(ctx context.Context, req *dto.GetPlatformReq) (res *dto.GetPlatformRes, err error) { - platform, err := dao.Platform.GetOne(ctx, req) - if err != nil { - return - } - - var platformEntity *entity.Platform - if err = gconv.Struct(platform, &platformEntity); err != nil { - return - } - - return &dto.GetPlatformRes{ - Platform: platformEntity, - }, nil -} - -// Update 更新平台 -func (s *platformService) Update(ctx context.Context, req *dto.UpdatePlatformReq) (err error) { - // 检查平台是否存在 - exist, err := dao.Platform.GetOne(ctx, &dto.GetPlatformReq{Id: req.Id}) - if err != nil || exist == nil { - return errors.New("平台不存在") - } - - // 如果修改了名称,检查新名称是否重复 - if req.Name != "" && req.Name != exist.Name { - count, err := dao.Platform.Count(ctx, &dto.ListPlatformReq{Name: req.Name}) - if err != nil { - return err - } - if count > 0 { - return errors.New("平台名称已存在") - } - } - - // 如果修改了类型,检查新类型是否重复 - if req.Type != "" && req.Type != exist.Type { - count, err := dao.Platform.Count(ctx, &dto.ListPlatformReq{Type: req.Type}) - if err != nil { - return err - } - if count > 0 { - return errors.New("该类型平台已存在") - } - } - - _, err = dao.Platform.Update(ctx, req) - return -} - -// UpdateStatus 更新平台状态 -func (s *platformService) UpdateStatus(ctx context.Context, req *dto.UpdatePlatformStatusReq) (err error) { - _, err = dao.Platform.UpdateStatus(ctx, req.Id, req.Status.String()) - return -} - -// Delete 删除平台 -func (s *platformService) Delete(ctx context.Context, req *dto.DeletePlatformReq) (err error) { - // 检查是否存在关联的接口 - interfaces, _, err := dao.ApiInterface.List(ctx, &dto.ListApiInterfaceReq{ - PlatformId: req.Id, - }) - if err != nil { - return err - } - if len(interfaces) > 0 { - return errors.New("该平台下存在接口,无法删除") - } - - _, err = dao.Platform.Delete(ctx, req) - return -} - -// GetByType 根据类型获取平台 -func (s *platformService) GetByType(ctx context.Context, platformType consts.SyncPlatform) (res *entity.Platform, err error) { - return dao.Platform.GetByType(ctx, platformType.String()) -} - -// getTypeName 获取类型名称 -func (s *platformService) getTypeName(platformType consts.SyncPlatform) string { - typeNames := map[consts.SyncPlatform]string{ - consts.PlatformTaobao: "淘宝", - consts.PlatformJD: "京东", - consts.PlatformKuaishou: "快手", - consts.PlatformDouyin: "抖音", - consts.PlatformXhs: "小红书", - consts.PlatformPdd: "拼多多", - consts.PlatformXianyu: "闲鱼", - consts.PlatformTmall: "天猫", - consts.PlatformWechat: "微信", - consts.PlatformCustom: "自定义", - } - if name, ok := typeNames[platformType]; ok { - return name - } - return string(platformType) -} - -// getStatusName 获取状态名称 -func (s *platformService) getStatusName(status consts.PlatformStatus) string { - statusNames := map[consts.PlatformStatus]string{ - consts.PlatformStatusActive: "启用", - consts.PlatformStatusInactive: "停用", - } - if name, ok := statusNames[status]; ok { - return name - } - return string(status) -} diff --git a/service/mapping/data_mapping_service.go b/service/mapping/data_mapping_service.go deleted file mode 100644 index 2cb5910..0000000 --- a/service/mapping/data_mapping_service.go +++ /dev/null @@ -1,306 +0,0 @@ -package mapping - -import ( - consts "cid/consts/mapping" - dao "cid/dao/mapping" - dto "cid/model/dto/mapping" - entity "cid/model/entity/mapping" - "context" - "errors" - - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/util/gconv" -) - -type dataMappingService struct{} - -// DataMapping 数据映射服务 -var DataMapping = new(dataMappingService) - -// Create 创建数据映射 -func (s *dataMappingService) Create(ctx context.Context, req *dto.CreateDataMappingReq) (res *dto.CreateDataMappingRes, err error) { - // 检查接口是否存在 - // TODO: 这里需要调用data层的ApiInterface服务,暂时跳过 - - // 检查同一接口下目标字段是否重复 - existing, err := dao.DataMapping.GetByInterfaceIdAndTargetField(ctx, req.InterfaceId, req.TargetField) - if err == nil && existing != nil { - return nil, errors.New("该接口下目标字段已存在") - } - - // 插入数据库 - id, err := dao.DataMapping.Insert(ctx, req) - if err != nil { - return - } - res = &dto.CreateDataMappingRes{ - Id: id, - } - return -} - -// BatchCreate 批量创建数据映射 -func (s *dataMappingService) BatchCreate(ctx context.Context, req *dto.BatchCreateDataMappingReq) (res *dto.BatchCreateDataMappingRes, err error) { - var ids []int64 - successCount := 0 - failedCount := 0 - - for _, mappingReq := range req.Mappings { - // 设置平台和接口ID - mappingReq.PlatformId = req.PlatformId - mappingReq.InterfaceId = req.InterfaceId - - createRes, err := s.Create(ctx, &mappingReq) - if err != nil { - failedCount++ - g.Log().Error(ctx, "批量创建映射失败", g.Map{ - "sourceField": mappingReq.SourceField, - "targetField": mappingReq.TargetField, - "error": err.Error(), - }) - } else { - successCount++ - ids = append(ids, createRes.Id) - } - } - - return &dto.BatchCreateDataMappingRes{ - SuccessCount: successCount, - FailedCount: failedCount, - Ids: ids, - }, nil -} - -// List 获取数据映射列表 -func (s *dataMappingService) List(ctx context.Context, req *dto.ListDataMappingReq) (res *dto.ListDataMappingRes, err error) { - mappingList, total, err := dao.DataMapping.List(ctx, req) - if err != nil { - return - } - - // 获取平台和接口ID列表 - platformIds := make([]int64, 0) - interfaceIds := make([]int64, 0) - for _, item := range mappingList { - if item.PlatformId > 0 { - platformIds = append(platformIds, item.PlatformId) - } - if item.InterfaceId > 0 { - interfaceIds = append(interfaceIds, item.InterfaceId) - } - } - - // TODO: 批量获取平台和接口信息(需要调用data层服务) - platformMap := make(map[int64]string) - interfaceMap := make(map[int64]string) - - // 组装响应数据 - list := make([]dto.DataMappingItem, 0, len(mappingList)) - for _, item := range mappingList { - platformName := "" - if name, ok := platformMap[item.PlatformId]; ok { - platformName = name - } - interfaceName := "" - if name, ok := interfaceMap[item.InterfaceId]; ok { - interfaceName = name - } - - list = append(list, dto.DataMappingItem{ - Id: item.Id, - PlatformId: item.PlatformId, - PlatformName: platformName, - InterfaceId: item.InterfaceId, - InterfaceName: interfaceName, - SourceField: item.SourceField, - TargetField: item.TargetField, - FieldType: item.FieldType, - DefaultValue: item.DefaultValue, - TransformRule: item.TransformRule, - Priority: item.Priority, - Status: item.Status, - StatusName: s.getStatusName(item.Status), - CreatedAt: item.CreatedAt.Unix(), - UpdatedAt: item.UpdatedAt.Unix(), - }) - } - - res = &dto.ListDataMappingRes{ - List: list, - Total: total, - } - return -} - -// GetOne 获取单个数据映射 -func (s *dataMappingService) GetOne(ctx context.Context, req *dto.GetDataMappingReq) (res *dto.GetDataMappingRes, err error) { - mapping, err := dao.DataMapping.GetOne(ctx, req) - if err != nil { - return - } - - // TODO: 获取平台和接口名称 - platformName := "" - interfaceName := "" - - return &dto.GetDataMappingRes{ - DataMapping: mapping, - PlatformName: platformName, - InterfaceName: interfaceName, - }, nil -} - -// Update 更新数据映射 -func (s *dataMappingService) Update(ctx context.Context, req *dto.UpdateDataMappingReq) (err error) { - // 检查映射是否存在 - exist, err := dao.DataMapping.GetOne(ctx, &dto.GetDataMappingReq{Id: req.Id}) - if err != nil || exist == nil { - return errors.New("映射不存在") - } - - // 如果修改了目标字段,检查是否重复 - if req.TargetField != "" && req.TargetField != exist.TargetField { - interfaceId := req.InterfaceId - if interfaceId == 0 { - interfaceId = exist.InterfaceId - } - existing, err := dao.DataMapping.GetByInterfaceIdAndTargetField(ctx, interfaceId, req.TargetField) - if err == nil && existing != nil && existing.Id != req.Id { - return errors.New("该接口下目标字段已存在") - } - } - - _, err = dao.DataMapping.Update(ctx, req) - return -} - -// Delete 删除数据映射 -func (s *dataMappingService) Delete(ctx context.Context, req *dto.DeleteDataMappingReq) (err error) { - _, err = dao.DataMapping.Delete(ctx, req) - return -} - -// Execute 执行数据映射 -func (s *dataMappingService) Execute(ctx context.Context, req *dto.ExecuteDataMappingReq) (res *dto.ExecuteDataMappingRes, err error) { - // 获取接口的所有映射规则 - mappings, err := dao.DataMapping.GetByInterfaceId(ctx, req.InterfaceId) - if err != nil { - return nil, err - } - - if len(mappings) == 0 { - return &dto.ExecuteDataMappingRes{ - TargetData: map[string]interface{}{}, - AppliedRules: []string{}, - }, nil - } - - // 初始化目标数据 - targetData := make(map[string]interface{}) - appliedRules := make([]string, 0) - - // 遍历映射规则进行转换 - for _, mapping := range mappings { - if mapping.Status != consts.MappingStatusActive { - continue - } - - // 获取源数据值 - sourceValue, exists := req.SourceData[mapping.SourceField] - - // 应用转换规则 - targetValue := s.applyTransformRule(ctx, sourceValue, exists, mapping) - - // 设置目标数据 - targetData[mapping.TargetField] = targetValue - - appliedRules = append(appliedRules, gconv.String(mapping.SourceField)+" -> "+gconv.String(mapping.TargetField)) - } - - return &dto.ExecuteDataMappingRes{ - TargetData: targetData, - AppliedRules: appliedRules, - }, nil -} - -// applyTransformRule 应用转换规则 -func (s *dataMappingService) applyTransformRule(ctx context.Context, sourceValue interface{}, exists bool, mapping entity.DataMapping) interface{} { - // 如果源字段不存在,使用默认值 - if !exists { - if mapping.DefaultValue != "" { - return mapping.DefaultValue - } - return nil - } - - // 如果没有转换规则,直接返回源值 - if mapping.TransformRule == nil || len(mapping.TransformRule) == 0 { - return sourceValue - } - - // 获取转换类型 - transformType := "" - if t, ok := mapping.TransformRule["type"].(string); ok { - transformType = t - } - - // 根据转换类型应用不同的转换逻辑 - switch consts.TransformType(transformType) { - case consts.TransformTypeFixed: - // 固定值 - if v, ok := mapping.TransformRule["rule"].(string); ok { - return v - } - case consts.TransformTypeMapping: - // 值映射 - if mappingMap, ok := mapping.TransformRule["mappingMap"].(map[string]interface{}); ok { - if sourceKey := gconv.String(sourceValue); sourceKey != "" { - if v, ok := mappingMap[sourceKey]; ok { - return v - } - } - } - case consts.TransformTypeRegex: - // 正则转换 - if regex, ok := mapping.TransformRule["regex"].(string); ok { - // TODO: 实现正则替换逻辑 - g.Log().Warning(ctx, "正则转换暂未实现", g.Map{ - "regex": regex, - "sourceValue": sourceValue, - }) - } - case consts.TransformTypeFunction: - // 函数转换 - if functionName, ok := mapping.TransformRule["functionName"].(string); ok { - // TODO: 实现函数调用逻辑 - g.Log().Warning(ctx, "函数转换暂未实现", g.Map{ - "function": functionName, - "sourceValue": sourceValue, - }) - } - case consts.TransformTypeScript: - // 脚本转换 - if script, ok := mapping.TransformRule["script"].(string); ok { - // TODO: 实现脚本执行逻辑 - g.Log().Warning(ctx, "脚本转换暂未实现", g.Map{ - "script": script, - "sourceValue": sourceValue, - }) - } - } - - // 默认返回源值 - return sourceValue -} - -// getStatusName 获取状态名称 -func (s *dataMappingService) getStatusName(status consts.MappingStatus) string { - statusNames := map[consts.MappingStatus]string{ - consts.MappingStatusActive: "启用", - consts.MappingStatusInactive: "停用", - } - if name, ok := statusNames[status]; ok { - return name - } - return string(status) -} diff --git a/update.sql b/update.sql deleted file mode 100644 index ea23b19..0000000 --- a/update.sql +++ /dev/null @@ -1,129 +0,0 @@ --- CID数据库表结构 - --- 应用管理表 -CREATE TABLE IF NOT EXISTS cid_application ( - id BIGSERIAL PRIMARY KEY, - tenant_id VARCHAR(64) DEFAULT '', - name VARCHAR(255) NOT NULL COMMENT '应用名称', - app_code VARCHAR(100) NOT NULL COMMENT '应用编码(唯一标识)', - type VARCHAR(50) NOT NULL COMMENT '应用类型', - status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '应用状态:active启用/inactive停用', - description TEXT COMMENT '应用描述', - access_config JSONB COMMENT '接入配置', - limit_config JSONB COMMENT '限流配置', - callback_config JSONB COMMENT '回调配置', - created_at BIGINT NOT NULL, - updated_at BIGINT NOT NULL, - deleted_at BIGINT DEFAULT 0, - CONSTRAINT uk_cid_application_app_code UNIQUE (app_code, deleted_at) -); - -CREATE INDEX idx_cid_application_tenant ON cid_application(tenant_id); -CREATE INDEX idx_cid_application_type ON cid_application(type); -CREATE INDEX idx_cid_application_status ON cid_application(status); -CREATE INDEX idx_cid_application_name ON cid_application(name); -CREATE INDEX idx_cid_application_app_code ON cid_application(app_code); - --- 平台管理表 -CREATE TABLE IF NOT EXISTS cid_platform ( - id BIGSERIAL PRIMARY KEY, - tenant_id VARCHAR(64) DEFAULT '', - name VARCHAR(255) NOT NULL COMMENT '平台名称', - type VARCHAR(50) NOT NULL COMMENT '平台类型', - status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '平台状态:active启用/inactive停用', - description TEXT COMMENT '平台描述', - auth_config JSONB COMMENT '认证配置', - limit_config JSONB COMMENT '限流配置', - platform_config JSONB COMMENT '平台专用配置', - created_at BIGINT NOT NULL, - updated_at BIGINT NOT NULL, - deleted_at BIGINT DEFAULT 0 -); - -CREATE INDEX idx_cid_platform_tenant ON cid_platform(tenant_id); -CREATE INDEX idx_cid_platform_type ON cid_platform(type); -CREATE INDEX idx_cid_platform_status ON cid_platform(status); -CREATE INDEX idx_cid_platform_name ON cid_platform(name); - --- 接口管理表 -CREATE TABLE IF NOT EXISTS cid_api_interface ( - id BIGSERIAL PRIMARY KEY, - tenant_id VARCHAR(64) DEFAULT '', - platform_id BIGINT NOT NULL COMMENT '所属平台ID', - name VARCHAR(255) NOT NULL COMMENT '接口名称', - code VARCHAR(100) NOT NULL COMMENT '接口编码', - url VARCHAR(500) NOT NULL COMMENT '接口地址', - method VARCHAR(10) NOT NULL COMMENT '请求方法:GET/POST/PUT/DELETE等', - status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '接口状态:active启用/inactive停用', - auth_type VARCHAR(50) COMMENT '认证类型:oauth2/apikey/basic等', - request_config JSONB COMMENT '请求配置', - response_config JSONB COMMENT '响应配置', - limit_config JSONB COMMENT '接口独立限流配置(可选,覆盖平台配置)', - created_at BIGINT NOT NULL, - updated_at BIGINT NOT NULL, - deleted_at BIGINT DEFAULT 0, - CONSTRAINT fk_cid_api_interface_platform FOREIGN KEY (platform_id) REFERENCES cid_platform(id) -); - -CREATE INDEX idx_cid_api_interface_tenant ON cid_api_interface(tenant_id); -CREATE INDEX idx_cid_api_interface_platform ON cid_api_interface(platform_id); -CREATE INDEX idx_cid_api_interface_code ON cid_api_interface(code); -CREATE INDEX idx_cid_api_interface_status ON cid_api_interface(status); -CREATE INDEX idx_cid_api_interface_name ON cid_api_interface(name); - --- 数据获取日志表 -CREATE TABLE IF NOT EXISTS cid_data_fetch_log ( - id BIGSERIAL PRIMARY KEY, - tenant_id VARCHAR(64) DEFAULT '', - platform_id BIGINT NOT NULL COMMENT '平台ID', - interface_id BIGINT NOT NULL COMMENT '接口ID', - request_id VARCHAR(100) NOT NULL COMMENT '请求ID', - status VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT '执行状态:pending/running/success/failed/rate_limit', - start_time BIGINT NOT NULL COMMENT '开始时间(时间戳)', - end_time BIGINT DEFAULT 0 COMMENT '结束时间(时间戳)', - duration INT DEFAULT 0 COMMENT '执行时长(毫秒)', - request_config JSONB COMMENT '请求配置参数', - response_data TEXT COMMENT '响应数据(JSON)', - error_message TEXT COMMENT '错误信息', - retry_count INT DEFAULT 0 COMMENT '重试次数', - created_at BIGINT NOT NULL, - updated_at BIGINT NOT NULL, - deleted_at BIGINT DEFAULT 0, - CONSTRAINT fk_cid_data_fetch_log_platform FOREIGN KEY (platform_id) REFERENCES cid_platform(id), - CONSTRAINT fk_cid_data_fetch_log_interface FOREIGN KEY (interface_id) REFERENCES cid_api_interface(id) -); - -CREATE INDEX idx_cid_data_fetch_log_tenant ON cid_data_fetch_log(tenant_id); -CREATE INDEX idx_cid_data_fetch_log_platform ON cid_data_fetch_log(platform_id); -CREATE INDEX idx_cid_data_fetch_log_interface ON cid_data_fetch_log(interface_id); -CREATE INDEX idx_cid_data_fetch_log_request_id ON cid_data_fetch_log(request_id); -CREATE INDEX idx_cid_data_fetch_log_status ON cid_data_fetch_log(status); -CREATE INDEX idx_cid_data_fetch_log_start_time ON cid_data_fetch_log(start_time); - --- 数据映射表 -CREATE TABLE IF NOT EXISTS cid_data_mapping ( - id BIGSERIAL PRIMARY KEY, - tenant_id VARCHAR(64) DEFAULT '', - platform_id BIGINT NOT NULL COMMENT '平台ID', - interface_id BIGINT NOT NULL COMMENT '接口ID', - source_field VARCHAR(255) NOT NULL COMMENT '源字段(接口返回字段)', - target_field VARCHAR(255) NOT NULL COMMENT '目标字段(本地表字段)', - field_type VARCHAR(50) NOT NULL COMMENT '字段类型:string/int/float/bool/array/object', - default_value VARCHAR(500) COMMENT '默认值', - transform_rule JSONB COMMENT '转换规则', - priority INT DEFAULT 0 COMMENT '优先级(数字越小优先级越高)', - status VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT '状态:active启用/inactive停用', - created_at BIGINT NOT NULL, - updated_at BIGINT NOT NULL, - deleted_at BIGINT DEFAULT 0, - CONSTRAINT fk_cid_data_mapping_platform FOREIGN KEY (platform_id) REFERENCES cid_platform(id), - CONSTRAINT fk_cid_data_mapping_interface FOREIGN KEY (interface_id) REFERENCES cid_api_interface(id), - CONSTRAINT uk_cid_data_mapping_interface_target UNIQUE (interface_id, target_field, deleted_at) -); - -CREATE INDEX idx_cid_data_mapping_tenant ON cid_data_mapping(tenant_id); -CREATE INDEX idx_cid_data_mapping_platform ON cid_data_mapping(platform_id); -CREATE INDEX idx_cid_data_mapping_interface ON cid_data_mapping(interface_id); -CREATE INDEX idx_cid_data_mapping_source_field ON cid_data_mapping(source_field); -CREATE INDEX idx_cid_data_mapping_status ON cid_data_mapping(status); -CREATE INDEX idx_cid_data_mapping_priority ON cid_data_mapping(priority);