feat: migrate workbench services
This commit is contained in:
@@ -1,146 +1,70 @@
|
||||
# im_workbench
|
||||
# Workbench
|
||||
|
||||
工作台服务从 `im_server` 拆分后的独立 Go 工程。当前阶段只拆服务和接口边界,数据库暂不迁移,继续访问现有租户库中的工作台表。
|
||||
移动端任务与账户平台后端。项目是独立应用,业务数据以 MySQL `olons_admin` 库中的 `hg_*` 表为唯一事实源。
|
||||
|
||||
## 路由
|
||||
## 当前接口
|
||||
|
||||
- `POST /v1/auth/register`
|
||||
- `POST /v1/auth/login`
|
||||
- `POST /v1/auth/logout`
|
||||
- `GET /v1/me`
|
||||
- `PATCH /v1/me/avatar`
|
||||
- `PUT /v1/me/password`
|
||||
- `PUT /v1/me/trade-password`
|
||||
- `GET /v1/home`
|
||||
- `GET /v1/banners`
|
||||
- `GET /v1/contents/{content_key}`
|
||||
- `GET /v1/member-levels`
|
||||
- `GET /v1/task-halls`
|
||||
- `GET /v1/tasks/eligibility`
|
||||
- `GET /v1/tasks/stats`
|
||||
- `POST /v1/task-orders/claim`
|
||||
- `GET /v1/task-orders`
|
||||
- `GET /v1/task-orders/{order_id}`
|
||||
- `POST /v1/task-orders/{order_id}/submissions`
|
||||
- `GET /v1/manual-products`
|
||||
- `GET /v1/manual-products/{product_id}`
|
||||
- `GET /v1/payment-accounts`
|
||||
- `POST /v1/payment-accounts`
|
||||
- `POST /v1/withdrawal-orders/quote`
|
||||
- `POST /v1/withdrawal-orders`
|
||||
- `GET /v1/withdrawal-orders`
|
||||
- `GET /v1/withdrawal-orders/{order_id}`
|
||||
- `GET /healthz`
|
||||
- `GET /metrics`
|
||||
- `GET /v1/workbench`
|
||||
- `/v1/workbench/organization/*`
|
||||
- `/v1/workbench/attendance/*`
|
||||
- `/v1/workbench/meetings*`
|
||||
- `/v1/workbench/meeting-notes`
|
||||
- `/v1/workbench/reports/daily*`
|
||||
- `/v1/workbench/reports/monthly*`
|
||||
- `/v1/workbench/executive-mailbox/*`
|
||||
- `/internal/admin/workbench/*`,HotGo 后台内部管理接口,使用服务间 HMAC 鉴权
|
||||
|
||||
## 本地运行
|
||||
注册使用 `hg_app_member` 作为账户主档,并在同一事务中创建 `hg_app_member_profile` 和 `hg_wallet_account` 记录。登录按 `mobile_hash` 查找会员,校验 bcrypt 密码后在 Redis 中创建独立会话。
|
||||
|
||||
## 启动配置
|
||||
|
||||
核心环境变量:
|
||||
|
||||
```bash
|
||||
IM_WORKBENCH_CONFIG=configs/workbench.local.json \
|
||||
IM_WORKBENCH_INTERNAL_SECRET=local-workbench-secret \
|
||||
go run ./cmd/workbench
|
||||
WORKBENCH_CONFIG=configs/workbench.local.json
|
||||
WORKBENCH_MYSQL_DSN='user:password@tcp(host:3306)/olons_admin?parseTime=true&charset=utf8mb4&loc=Local'
|
||||
WORKBENCH_REDIS_ADDR='127.0.0.1:6379'
|
||||
WORKBENCH_DATA_ENCRYPTION_KEY='<32 字节随机密钥的 Base64>'
|
||||
WORKBENCH_LOOKUP_HMAC_KEY='<至少 32 字节随机密钥的 Base64>'
|
||||
WORKBENCH_API_KEYS='<API Key,多个以逗号分隔>'
|
||||
```
|
||||
|
||||
默认监听 `:6061`,默认连接本地 `workbench` 库和本地 Redis。
|
||||
`WORKBENCH_DATA_ENCRYPTION_KEY` 用于生成 `mobile_cipher`,`WORKBENCH_LOOKUP_HMAC_KEY` 用于生成 `mobile_hash`。两个密钥必须分开生成、通过部署 Secret 注入,并与已有数据的加密配置保持一致。
|
||||
|
||||
开发联调可在 `configs/workbench.local.json` 打开 `allow_dev_header_auth`,请求头带:
|
||||
## 请求头
|
||||
|
||||
```text
|
||||
X-User-ID: 1
|
||||
X-Tenant-ID: 1
|
||||
X-Tenant-Code: default
|
||||
```http
|
||||
X-API-Key: <api key>
|
||||
X-Request-ID: <request id>
|
||||
X-Device-ID: <optional device id>
|
||||
```
|
||||
|
||||
正式链路使用:
|
||||
默认租户通过 `WORKBENCH_DEFAULT_TENANT_ID` 配置,现有 `olons_admin` 数据使用 `tenant_id=0`。服务不接受客户端传入租户身份。
|
||||
|
||||
```text
|
||||
Authorization: Bearer {token}
|
||||
X-MeetingIM-APIKey: {apikey}
|
||||
X-Tenant-Code: default
|
||||
X-IM-Schema: 1
|
||||
X-Request-ID: {uuid}
|
||||
```
|
||||
|
||||
服务从 Redis 读取 `im:session:token:{sha256(token)}` 校验登录态。
|
||||
|
||||
`usr...` 用户 ID 编解码优先从 IM Manager 内部配置接口读取 UID 加密 key,读不到时回退到
|
||||
`auth.uid_key` 或环境变量 `IM_WORKBENCH_UID_KEY`。测试环境需要配置:
|
||||
|
||||
```text
|
||||
IM_WORKBENCH_MANAGER_BASE_URL=https://admin.118im.com
|
||||
IM_WORKBENCH_MANAGER_SERVICE_NAME=im-workbench
|
||||
IM_WORKBENCH_MANAGER_SECRET={IM_CONFIG_API_SECRET}
|
||||
```
|
||||
|
||||
默认读取 `GET /internal/im-config/third-party/im?keys=uid_encryption_key,UID_ENCRYPTION_KEY,uid_key`。
|
||||
如果后台配置使用了其他 group/key,可通过 `IM_WORKBENCH_MANAGER_UID_KEY_GROUP` 和
|
||||
`IM_WORKBENCH_MANAGER_UID_KEY_KEYS` 调整。
|
||||
|
||||
HotGo 后台访问 `/internal/admin/workbench/*` 时需要配置同一组内部鉴权参数:
|
||||
|
||||
```text
|
||||
IM_WORKBENCH_INTERNAL_SERVICE_NAME=hotgo-admin
|
||||
IM_WORKBENCH_INTERNAL_SECRET={shared-secret}
|
||||
```
|
||||
|
||||
测试环境也可以复用已有内部服务密钥:HotGo 的 `IM_WORKBENCH_API_SECRET` 为空时会使用
|
||||
`IM_INTERNAL_API_SECRET`,`im_workbench` 的 `IM_WORKBENCH_INTERNAL_SECRET` 为空时也会使用
|
||||
`IM_INTERNAL_API_SECRET`。
|
||||
|
||||
HotGo 后台在测试集群中建议直连工作台服务内网地址:
|
||||
|
||||
```text
|
||||
IM_WORKBENCH_API_BASE_URL=http://im-workbench.workbench-system.svc.cluster.local:6061
|
||||
```
|
||||
|
||||
测试镜像默认使用 `hotgo-workbench-internal` 作为工作台内部签名密钥;正式环境建议通过
|
||||
`IM_WORKBENCH_API_SECRET` 和 `IM_WORKBENCH_INTERNAL_SECRET` 覆盖为真实密钥。
|
||||
|
||||
## Kafka 事件
|
||||
|
||||
工作台写操作统一投递到 `im.workbench.event`。本地配置默认关闭 Kafka:
|
||||
|
||||
```bash
|
||||
IM_WORKBENCH_KAFKA_ENABLED=true \
|
||||
IM_WORKBENCH_KAFKA_BROKERS=127.0.0.1:9092 \
|
||||
IM_WORKBENCH_CONFIG=configs/workbench.local.json \
|
||||
go run ./cmd/workbench
|
||||
```
|
||||
|
||||
测试环境使用 `configs/workbench.test.json`,Kafka 为明文 PLAINTEXT 直连,不配置 SASL/TLS。
|
||||
|
||||
## AI / DeepSeek 本地配置
|
||||
|
||||
工作台 AI 首版接入 DeepSeek。默认配置已在 `configs/workbench.local.json` 中给出,实际调用前需要配置 API Key:
|
||||
|
||||
```bash
|
||||
DEEPSEEK_API_KEY=sk-xxx \
|
||||
IM_WORKBENCH_CONFIG=configs/workbench.local.json \
|
||||
go run ./cmd/workbench
|
||||
```
|
||||
|
||||
可选参数:
|
||||
|
||||
```bash
|
||||
DEEPSEEK_BASE_URL=https://api.deepseek.com
|
||||
DEEPSEEK_DEFAULT_MODEL=deepseek-flash
|
||||
DEEPSEEK_COMPLEX_MODEL=deepseek-v4-pro
|
||||
DEEPSEEK_TIMEOUT_MS=60000
|
||||
DEEPSEEK_MAX_RETRIES=2
|
||||
DEEPSEEK_TEMPERATURE=0.2
|
||||
DEEPSEEK_MAX_OUTPUT_TOKENS=4096
|
||||
```
|
||||
|
||||
事件体字段:
|
||||
|
||||
```json
|
||||
{
|
||||
"event_id": "wbe_xxx",
|
||||
"trace_id": "request-id",
|
||||
"tenant_id": 1,
|
||||
"tenant_code": "default",
|
||||
"actor_user_id": 42,
|
||||
"module": "meeting",
|
||||
"action": "meeting.created",
|
||||
"resource_id": "mtg_xxx",
|
||||
"target_user_ids": [42, 43],
|
||||
"title": "会议通知",
|
||||
"summary": "项目周会",
|
||||
"occurred_at": "2026-09-13T14:00:00Z",
|
||||
"data": {}
|
||||
}
|
||||
```
|
||||
|
||||
## 构建
|
||||
## 验证
|
||||
|
||||
```bash
|
||||
make test
|
||||
make build
|
||||
```
|
||||
|
||||
## 数据库原则
|
||||
|
||||
服务启动不自动建库建表,不执行 `CREATE TABLE` / `ALTER TABLE`。所有表结构和种子数据继续通过 SQL 审核后人工执行。
|
||||
前后端完整对接契约见 [`docs/移动端任务与账户平台前后端对接文档.md`](docs/移动端任务与账户平台前后端对接文档.md),已实现的注册登录简版契约见 [`docs/注册登录对接文档.md`](docs/注册登录对接文档.md)。
|
||||
|
||||
Reference in New Issue
Block a user