feat(analog): 新增ICC模拟量数据同步 - 重建electricity_data表(迁移20261024_icc_analog_data.sql:删除equip_id与electricity占位列、icc_device_code更名imei、新增analog_type/analog_name/analog_unit/analog_value、collect_time以同步时间填充、按月分区2026_10~2027_03、唯一键(line_code,analog_type,collect_time));同步服务IccAnalogSyncService复用OAuth2鉴权,按已同步线路line_code分批(≤50)拉取最新模拟量(POST /analog/subsystem/page,pageSize=500短页停止)幂等upsert并写icc_sync_log(sync_type=electricity_data);新增POST /api/electricity-data/sync手动同步(RBAC device:list);注册icc_analog_sync每5分钟定时任务与sys_job种子;同步db_init/db_seed与设计文档;无前端改动
This commit is contained in:
1 parent
160ad85051
commit
c92fc7f298
15 files changed
+701
-27
No files matched your search
@@ -38,3 +38,53 @@
|
||||
| synced_at | TIMESTAMPTZ | | ICC 同步时间 |
|
||||
| created_at | TIMESTAMPTZ | | 创建时间 |
|
||||
|
||||
electricity_data 表结构重建(ICC 模拟量同步)
|
||||
|
||||
原 `electricity_data`(线路用电信息表)仅有一版占位定义(单列 `electricity`),与 ICC 平台「消防最新模拟量信息分页查询」接口(`POST /evo-apigw/evo-fdbu/{version}/analog/subsystem/page`,实际返回 `AnalogInfoVO{deviceCode, uniqueCode, analogType, analogValue, analogUnit, analogName}`,无 reportTime)不对应,本次按接口返回数据重建表结构,并实现真实同步服务与定时任务。
|
||||
|
||||
| 字段 | 类型 | 键 | 说明 |
|
||||
| :---------- | :------------ | :----------------- | :---------------------------------------------- |
|
||||
| id | BIGSERIAL | PK(复合) | 自增主键(与 collect_time 组成复合主键) |
|
||||
| line_id | BIGINT NOT NULL | FK | 线路 ID(→ electric_line.id) |
|
||||
| line_code | VARCHAR(64) NOT NULL | UNIQUE(复合) | 线路编码(= ICC deviceCode,冗余 + 幂等键) |
|
||||
| imei | VARCHAR(64) | | 设备唯一标识码(= ICC uniqueCode) |
|
||||
| line_name | VARCHAR(128) | | 线路名称(冗余展示) |
|
||||
| customer_id | BIGINT NOT NULL | | 客户 ID(逻辑隔离键 → customer.id) |
|
||||
| analog_type | VARCHAR(64) | | 模拟量类型(= ICC analogType) |
|
||||
| analog_name | VARCHAR(128) | | 模拟量名称(= ICC analogName,如"剩余电流") |
|
||||
| analog_unit | VARCHAR(32) | | 模拟量单位(= ICC analogUnit,如"mA") |
|
||||
| analog_value | NUMERIC(14,4) | | 模拟量值(= ICC analogValue) |
|
||||
| collect_time | TIMESTAMPTZ NOT NULL | PK(复合)/分区键 | 采集时间 = 同步拉取时间(ICC 最新模拟量接口实际不返回 reportTime,经确认以同步时间作为分区键与采集时间) |
|
||||
|
||||
键与分区:
|
||||
|
||||
- 主键:`(id, collect_time)`(复合主键,兼容按月分区)
|
||||
- 唯一键:`UNIQUE(line_code, analog_type, collect_time)`,作幂等键(同键重复上报覆盖更新)
|
||||
- 分区:按 `collect_time` 按月 RANGE 分区,初始分区 `2026_10`~`2027_03`(`electricity_data_2026_10`~`electricity_data_2027_03`,共 6 个),后续按月自动/手动创建
|
||||
- 索引:`idx_ed_customer(customer_id)`、`idx_ed_line(line_id)`、`idx_ed_time(collect_time)`、`idx_ed_customer_time(customer_id, collect_time)`(父表创建,自动继承到各分区)
|
||||
|
||||
关联关系:
|
||||
|
||||
- `line_id` → `electric_line.id`(再由 electric_line 关联 customer 与 customer_equipment)
|
||||
- `customer_id` → `customer.id`(逻辑隔离键)
|
||||
- **明确注明:按需求确认,`equip_id` 字段已删除,本表不再直接关联 customer_equipment。**
|
||||
|
||||
变更说明:
|
||||
|
||||
- 删除旧占位列 `electricity`(重建为通用模拟量行:analog_type / analog_value)与 `equip_id`
|
||||
- 原 `icc_device_code` 更名 `imei`(映射 uniqueCode)
|
||||
- 迁移文件:`database/migrations/20261024_icc_analog_data.sql`(建表/分区/索引/注释 + sys_job 种子,2026-10-24 已执行到生产库),`database/db_init.sql` 同步更新
|
||||
|
||||
同步服务说明:
|
||||
|
||||
- 默认每 5 分钟执行一次;复用 ICC OAuth2 鉴权(`getIccAccessToken`/`iccFetch`)
|
||||
- 先读取已同步 `electric_line` 的 line_code(= detectorCode),按 deviceCodes 分批(每批 ≤50 个)POST 模拟量接口(pageSize=500,短页停止全量拉取)
|
||||
- 字段映射:imei=uniqueCode、analog_type=analogType、analog_name=analogName、analog_unit=analogUnit、analog_value=analogValue;collect_time = 同步拉取时间(ICC 最新模拟量接口实际不返回 reportTime,经确认以同步时间作为分区键与采集时间);预取 deviceCode→(line_id, customer_id) 映射避免 N+1
|
||||
- 按 `(line_code, analog_type, collect_time)` 幂等 upsert(同一次同步内重复则覆盖更新);写 `icc_sync_log`(sync_type=electricity_data);拉取失败仅记日志不抛业务错
|
||||
|
||||
定时任务:
|
||||
|
||||
- jobKey=`icc_analog_sync`,cron `*/5 * * * *`(默认每 5 分钟,sys_job 种子幂等,注册进 job_registry/JobRuntime)
|
||||
- 手动同步接口:`POST /api/electricity-data/sync`(JWT+RBAC `device:list`,返回 pulled/inserted/updated/skipped/synced)
|
||||
- 不做前端页面/菜单
|
||||
|
||||
Reference in new issue
Block a user