智电改造网关表:electric\_gatway(ICC同步) | 字段 | 类型 | 键 | 说明 | | :--------- | :---------- | :----- | :--------------- | | id | BIGSERIAL | PK | 自增主键 | | iccImei | VARCHAR(64) | UNIQUE | 设备唯一标识码,设备的imei号 | | deviceCode | VARCHAR(64) | UNIQUE | 设备编码 | | deviceName | VARCHAR(64) |
| 设备名称 | |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| 智电改造线路表:electric_line(ICC探测器同步) | 字段 | 类型 | 键 | 说明 | | :------------------ | :----------- | :----- | :------------------------------------------------------- | | id | BIGSERIAL | PK | 自增主键 | | line_code | VARCHAR(64) | UNIQUE | 探测器编码(ICC detectorCode,唯一幂等键) | | equip_id | BIGINT | FK | 客户设备 ID(→ customer_equipment,可空,同步不填充) | | gateway_id | BIGINT | FK | 网关设备 ID(→ electric_gateway,由 parentCode↔device_code 匹配) | | customer_id | BIGINT | FK | 客户 ID(orgCode→customer.icc_code 解析,逻辑隔离键) | | line_name | VARCHAR(128) | | 探测器名称(ICC detectorName) | | imei | VARCHAR(64) | | 设备唯一标识码(ICC imei) | | type_code | VARCHAR(32) | | 探测器类型编码 | | type_name | VARCHAR(64) | | 探测器类型名称 | | fire_system_code | VARCHAR(64) | | 消防系统编码 | | fire_system_name | VARCHAR(128) | | 消防系统名称 | | part_unit_loop_code | VARCHAR(64) | | 探测器回路号 | | channel_no | VARCHAR(64) | | 探测器通道号 | | channel_sn | VARCHAR(64) | | 通道唯一标识码 | | produce_date | VARCHAR(16) | | 生产日期(yyyy-MM-dd) | | status | SMALLINT | | 探测器状态:1在线 0离线(detectorStatus 01→1 / 02→0) | | 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) - 不做前端页面/菜单