refactor(iot): 重构客流计数器为增量累加模式,支持 people_out
- 删除旧 TrafficCounterBaseRedisDAO(基准值模式),新增 TrafficCounterRedisDAO 支持阈值计数器(达标后重置)和当日累积统计(用于报表) - TrafficThresholdRuleProcessor 改为增量原子累加,消除基准值校准逻辑 - CleanRuleProcessorManager 路由增加 people_out 支持 - TrafficCounterBaseResetJob 改为每日清除阈值计数器,持久化职责移交 Ops 模块 - 使用 SCAN 替代 KEYS 避免阻塞 Redis Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
28
sql/mysql/aiot_ops_traffic_statistics.sql
Normal file
28
sql/mysql/aiot_ops_traffic_statistics.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
-- Ops 模块:客流统计小时汇总表
|
||||
-- 用于业务报表统计,数据来源于 IoT 设备的客流计数器
|
||||
-- 每小时由 Ops 的 TrafficStatisticsPersistJob 从 Redis 持久化到 MySQL
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ops_traffic_statistics` (
|
||||
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
`device_id` BIGINT NOT NULL COMMENT '设备ID(数据来源)',
|
||||
`area_id` BIGINT NOT NULL COMMENT '区域ID(主查询维度)',
|
||||
`stat_hour` DATETIME NOT NULL COMMENT '统计小时(精确到小时,如 2026-02-03 10:00:00)',
|
||||
`people_in` INT NOT NULL DEFAULT 0 COMMENT '进入人数',
|
||||
`people_out` INT NOT NULL DEFAULT 0 COMMENT '离开人数',
|
||||
`tenant_id` BIGINT NOT NULL DEFAULT 0 COMMENT '租户ID',
|
||||
`creator` VARCHAR(64) DEFAULT '' COMMENT '创建者',
|
||||
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updater` VARCHAR(64) DEFAULT '' COMMENT '更新者',
|
||||
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`deleted` BIT(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
|
||||
|
||||
-- 唯一约束:同一设备、同一小时、同一租户,只有一条记录
|
||||
UNIQUE KEY `uk_device_hour_tenant` (`device_id`, `stat_hour`, `tenant_id`, `deleted`),
|
||||
|
||||
-- 区域+小时索引:用于按区域统计客流
|
||||
INDEX `idx_area_hour` (`area_id`, `stat_hour`),
|
||||
|
||||
-- 设备+小时索引:用于按设备查询历史
|
||||
INDEX `idx_device_hour` (`device_id`, `stat_hour`)
|
||||
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='客流统计小时汇总表(Ops业务统计)';
|
||||
Reference in New Issue
Block a user