sync: 同步 v1.0.4 开源代码并脱敏

This commit is contained in:
MiFaZhan
2026-10-29 14:52:43 +08:00
parent 32e4316ee4
commit 6893e21f07
136 changed files with 9851 additions and 436 deletions
+16 -109
View File
@@ -1,120 +1,27 @@
# iotlcm-worker-svr
iotLCM 物联网卡全生命周期管理平台的**异步执行中枢** —— RabbitMQ 消费者 + 全量同步编排器。
Dedicated RabbitMQ consumer service for IotLCM asynchronous work.
平台的大部分耗时操作(批量开停复机、续费变更、流量/状态/IMEI 全量同步、达量断网、工单自动关闭)都在本服务里异步执行。
## Consumers
## 特性
The service always registers these business consumers when RabbitMQ is enabled:
- **多队列消费者**:注册业务消费者处理重试队列、批次执行、工单等
- **全量同步编排**:卡状态 / 本月流量 / 日流量 / 月流量历史 / IMEI 五条全量同步链路,统一的 Producer(扫描 + 供料)→ Consumer(领取 + 执行)模型
- **通道级并发与限速**:按通道模板配置 QPS,按通道隔离并发度
- **多轮执行**:失败卡进入下一轮重试,单轮上限与轮次上限可配
- **运行归档**:每轮执行产出终态 JSON 归档,供通知与排障使用
- **可观测**:阶段耗时、库存水位、缺料观测等遥测写入归档
- `iotlcm.traffic_usage.daily.retry`
- `iotlcm.traffic_usage.monthly.retry`
- `iotlcm.work_order.auto_close`
## 技术栈
For local Admin-to-Worker integration checks, set `workerDiagnostic.enabled: true` to
register `iotlcm.worker.diagnostic`. Diagnostic messages are logged and acknowledged;
they do not access MySQL, TDengine, or Upstream. The diagnostic consumer is disabled
in the default and build configurations.
- Go 1.25 + GoFrame v2
- RabbitMQ(`github.com/rabbitmq/amqp091-go`)
- MySQL(业务库)、Redis(任务队列与锁)、TDengine(用量时序)
- 支付宝(余额充值)、excelize(Excel 导入导出)
## SIM status synchronization
## 快速开始
Status sync uses run-scoped queues and durable outcome counters. See
[Run accounting and rollout](SIM_STATUS_RUN_ACCOUNTING.md) for the new
`simStatusQueueSync.redisKeyPrefix` setting and tests.
```bash
go mod tidy
go run .
```
## 配置
## 角色权限同步
配置文件在 `config/config_default.yaml`(默认配置)与 `config/config.yaml`(部署时覆盖)。**公开版里的凭据与地址全部是占位符**:
| 配置项 | 占位 | 说明 |
| --- | --- | --- |
| `database.default.link` | `${DB_USER}:${DB_PASSWORD}@tcp(${DB_HOST}:3306)` | 业务库 |
| `redis.default.address` | `${REDIS_ADDR}` | 任务队列 |
| `redis.default.pass` | `${REDIS_PASSWORD}` | 缓存口令 |
上游凭据(AppKey / AppSecret)**不写在本仓**,存放在通道表 `t_sim_channels` 与通道模板表里,由平台写入。
## 目录结构
```text
iotlcm-worker-svr/
├── internal/
│ ├── cmd/ # 启动装配
│ ├── consumer/
│ │ ├── rabbitmq/ # RabbitMQ 消费者(批次、重试、工单等)
│ │ └── zset/ # 全量同步消费者(ZSet 任务队列)
│ ├── producer/
│ │ ├── simstatus/ # 卡状态全量同步
│ │ ├── monthlyusage/ # 本月流量全量同步
│ │ ├── dailyusage/ # 日流量全量同步
│ │ ├── monthlyusagehistory/ # 月流量历史同步
│ │ └── imei/ # IMEI 全量同步
│ ├── fullsync/ # 全量同步运行时、归档、契约、HTTP 诊断
│ ├── service/ # 各业务动作执行器
│ ├── repository/ # 数据访问
│ ├── queue/zset/ # 任务队列与锁
│ └── library/rabbitmq/ # MQ 封装
├── config/ # 配置
├── build/ # Dockerfile 与镜像内配置
├── manifest/deploy/kustomize/ # K8s 部署清单
└── manifest/docker/ # compose 与启动脚本
```
## 全量同步模型
```text
Producer(扫描卡 → 按通道分片入队)
│
▼
ZSet 任务队列(Redis)
│
▼
Consumer(按通道 QPS 领取 → 调上游 → 写库 → 结算)
│
▼
运行归档(终态 JSON,供 Bot 通知与排障)
```
关键设计:
- **通道隔离**:每个通道独立并发与 QPS,一个慢通道不拖垮其他通道
- **供料与消费解耦**:Producer 只负责入队,Consumer 按节奏领取,避免上游被瞬时打满
- **多轮重试**:单卡失败进入下一轮,轮次上限与单轮上限均可配
- **归档去重**:按 `runId` 标识一次执行,Bot 据此去重推送
## 容器化构建
```bash
docker build -f build/Dockerfile -t iotlcm-worker-svr:latest .
```
镜像内不含任何凭据;`config/config.yaml` 以只读方式挂载覆盖。
## 测试
```bash
go test ./...
```
测试使用本地替身,不访问真实运营商接口。
> **已知失败(与上游主分支一致,非本仓引入)**:
> `TestValidateUpstreamBasicInfoAcceptsMatchingIdentifiers`、
> `TestConfiguredInboundBasicInfoClientUsesDedicatedEndpoint`、
> `TestAllocateProcessingRetryAfterHasLargeBatchDefault`。
> 这三项在源仓库同一提交上同样失败,属既有缺陷。
## 相关项目
- [iotlcm-bot](https://git.5iot.com/iotlcm-public/iotlcm-bot) —— 读取归档 JSON 并推送飞书卡片
- [iotlcm-upstream-chan](https://git.5iot.com/iotlcm-public/iotlcm-upstream-chan) —— 运营商上游适配
- [iotlcm-admin-svr](https://git.5iot.com/iotlcm-public/iotlcm-admin-svr) —— 管理后台(发起批次与定时任务)
## License
[Apache License 2.0](./LICENSE)
配置 `roleSync.enabled: true` 后,独立接管管理后端的持久化角色权限任务。部署顺序与回滚见 `docs/角色权限任务切换.md`。默认关闭,必须先执行迁移并移除旧管理后端执行入口。