Commit Graph

17 Commits

Author SHA1 Message Date
lzh
4f0c8f7162 fix(video): Mapper 移除多数据库方言分支(仅保留 MySQL)
WVP 原支持 MySQL / H2 / KingBase / PostgreSQL,使用 databaseId 属性
区分 SQL 方言,但本项目 MyBatis 未配置 databaseIdProvider,运行时
databaseId 为 null 导致 "Could not find a statement annotation that
correspond a current database" 启动失败。

改动:
- CommonGBChannelMapper.queryListInCircle / queryListInPolygon:
  仅保留 queryListInCircleForMysql / queryListInPolygonForMysql
  对应的 @SelectProvider,删除 h2/kingbase/postgresql 变体
- GroupMapper.updateParentId / updateParentIdWithBusinessGroup /
  fixParentId:仅保留 MySQL JOIN 语法,删除 3 种方言 UPDATE
- RegionMapper.updateParentId:同上

项目固定使用 MySQL,这些方言变体在本仓库永远不会命中,删除后启动
不再需要依赖 databaseIdProvider 配置。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 14:00:29 +08:00
lzh
3a3f7b78d4 refactor(video): 预置 AI 算法改为 SQL 种子数据,移除 @PostConstruct 初始化
原 AiAlgorithmServiceImpl.initPresetAlgorithms() 在 @PostConstruct
里插入 4 条预置算法,带来两个问题:
1. 启动时无登录上下文,MP 自动填充 creator 失效 → 启动失败
2. 算法清单硬编码在 Java 代码,迭代要重编译发布

改为 video.sql 种子数据管理:
- video.sql 的预置算法 INSERT 扩展为 4 条(leave_post / intrusion /
  illegal_parking / vehicle_congestion),参数 schema 与边缘端对齐
- 使用 ON DUPLICATE KEY UPDATE 保证幂等:新库初始化 + 存量库升级
  都走同一条语句,param_schema / description 会被自动校正
- 保留用户侧可修改的字段(is_active / global_params)不被覆盖

代码层:
- 删除 initPresetAlgorithms() 方法与 PRESET_ALGORITHMS 静态 Map
- 删除 SYSTEM_USER 常量
- 删除 @PostConstruct / HashMap 相关 import
- 保留 syncFromEdge() 作为边缘端主动同步的运行时入口

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 13:54:39 +08:00
lzh
1ac72b23c5 fix(video): AI 算法预置数据 @PostConstruct 插入时显式设置 creator/updater
启动时 initPresetAlgorithms() 在 @PostConstruct 执行,此时无登录上下文:
- DefaultDBFieldHandler.insertFill 在 getLoginUserId()==null 时不填充
  creator/updater
- SQL video_ai_algorithm.creator NOT NULL 约束触发
  "Column 'creator' cannot be null" 启动失败

手动设置 creator/updater = "1"(系统用户)作为系统级初始化的占位,
同时 update 分支也显式设置 updater 避免同类问题。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 13:48:52 +08:00
lzh
42cb3d9d57 chore(video): 数据源改用统一 aiot-platform 库,与 ops/iot 对齐
原 video 模块 application-local.yaml 默认 MYSQL_DATABASE 是 aiot-video
(设计初衷是 WVP 独立库)。运维按单库部署,26 张 video_* 业务表
已执行到 aiot-platform 库,因此默认值改为 aiot-platform,
避免启动时 "Unknown database 'aiot-video'" 报错。

同步 master / slave 两个数据源默认值。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 11:33:49 +08:00
lzh
8ae7b1a823 docs(video): 遗留项防御性加固 — GB2022 扩展字段 exist=false + Mapper 继承警告
基于遗留项调研结论(三项均无当前运行时风险,真正价值是防御未来
误用 BaseMapperX 高层方法),执行最小化防御性修复:

PlatformChannel 的 20 个 GB2022 扩展字段加 @TableField(exist=false):
- customSecurityLevelCode / customPhotoelectricImagingTyp /
  customCapturePositionType / customStreamNumberList /
  customSsvcRatioSupportList / customMobileDeviceType /
  customHorizontalFieldAngle / customVerticalFieldAngle /
  customMaxViewDistance / customGrassrootsCode / customPoType /
  customPoCommonName / customMac / customFunctionType /
  customEncodeType / customInstallTime / customManagementUnit /
  customContactInfo / customRecordSaveDays / customIndustrialClassification
这些是 WVP 预占位字段,SQL 尚未建列,加 exist=false 消除
BaseMapperX 反射写入时 "Unknown column" 的潜在风险,
待业务方决定是否推进 GB2022 自定义属性持久化再补 SQL 列。

StreamProxyMapper / StreamPushMapper 加接口级 Javadoc 警告:
- StreamProxy/StreamPush 继承 CommonGBChannel 带入 40+ 个 gb_* 字段,
  但 video_stream_proxy / video_stream_push 表不含这些列
  (gb 通道信息由 GbChannelService 写入 video_common_gb_channel)
- 警告开发者严禁使用 BaseMapperX 的 insert/updateById/selectByMap
  自动映射方法,写入必须走显式 SQL 方法(add/update/addAll)
- 读取 selectById/selectList 可用(SELECT 时 gb_* 字段返回 null 不报错)

未改动(零当前风险 + 改动成本高):
- SIP 协议时间字段(register_time 等 varchar):Mapper 全显式 SQL
  用 #{} 绑定 String,与 varchar 列自洽;DateUtil.getNow() 返回
  "yyyy-MM-dd HH:mm:ss" 格式字符串,时间比较查询的字符串排序
  与 datetime 排序结果一致;改造涉及 72+ 处调用链
- StreamProxy/StreamPush 继承架构:改组合式重构代价大,
  通过 Javadoc 警告防御未来误用即可

编译通过(mvn compile BUILD SUCCESS)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 13:43:23 +08:00
lzh
0ca1adf2a4 refactor(video): P2 应用层时间字段 varchar → datetime / String → LocalDateTime
SQL 类型优化(应用层生成的业务时间改为标准 datetime):
- video_ai_edge_device: last_heartbeat / updated_at
- video_ai_config_log: updated_at
- video_ai_config_snapshot: created_at
- video_ai_algorithm: sync_time
- video_ai_alert: received_at
- video_media_server: last_keepalive_time

DO 字段 String → LocalDateTime 对齐:AiEdgeDevice / AiConfigLog /
AiConfigSnapshot / AiAlgorithm / AiAlert / MediaServer

调用点适配:
- Service 层 new Date() 字符串格式化赋值统一改为 LocalDateTime.now()
- AiAlertController.edgeReport / MqttService.handleAlert 新增
  parseEventTime / parseTimestamp 私有方法,外部字符串防御性解析

保留 varchar(本批次暂不动,SIP 协议原生字符串,改动涉及 72+ 处
Mapper 与 SIP 处理器,单独迭代):
- video_device.register_time / keepalive_time
- video_device_channel.end_time / gps_time
- video_device_mobile_position.time
- video_stream_push.push_time

编译通过(mvn compile BUILD SUCCESS)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 12:32:23 +08:00
lzh
64dcdd8d4c refactor(video): P1 类型规范化 — varchar 数值转 int / Integer 布尔转 Boolean
SQL 类型修正(数值语义列不再用 varchar):
- video_platform: device_port / expires / keep_timeout varchar(50) → int
- video_platform_channel: custom_cert_num / custom_end_time varchar(50) → int

DO 布尔语义字段 Integer → Boolean(SQL 早已是 tinyint(1),DO 对齐语义):
- AiAlgorithm.isActive
- AiRoi.enabled
- AiRoiAlgoBind.enabled
同步修复 ~20 处调用点的布尔判断,setEnabled(1) → setEnabled(true),
getEnabled() == 1 → Boolean.TRUE.equals(getEnabled())

MediaServer.hookAliveInterval Float → Integer(SQL 是 int,Float 精度丢失)
同步修复 MediaConfig、ABL/ZLM 两个 StatusManager 的 10F → 10 字面量

编译通过(mvn compile BUILD SUCCESS)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 12:13:56 +08:00
lzh
1698c71d84 fix(video): P0 修复 @TableName 映射错误、字段命名、补缺列与 exist=false
@TableName 修正:
- CommonGBChannel: "video_device_channel" → "video_common_gb_channel"
- DeviceChannel: 显式加 @TableName("video_device_channel")
- PlatformChannel: 补充 @TableName("video_platform_channel")
  避免因继承 CommonGBChannel 而写入错误表

字段命名规范化(修复驼峰转 snake_case 错位):
- CommonGBChannel.recordPLan → recordPlanId(对应 record_plan_id)
- MediaServer.httpSSlPort / flvSSLPort / wsFlvSSLPort
  → httpSslPort / flvSslPort / wsFlvSslPort
  (原命名 L 大写/双大写导致转 snake 变 http_s_sl_port)
- 同步更新 Mapper SQL 中的 #{xxx} 引用和 ZLM/ABL 节点服务调用点

@TableField(exist=false) 标注(JOIN 显示字段/业务计算值/内存对象):
- DeviceChannel: parentDeviceId、parentName、ptzTypeText
- DeviceAlarm: deviceName、alarmPriorityDescription、alarmMethodDescription、
  alarmTypeDescription
- AiAlert: cameraName、roiName
- Device: sipTransactionInfo
- MobilePosition: channelDeviceId
- StreamPush: uniqueKey

补齐 SQL 缺失列(需持久化的业务状态字段):
- video_device: channel_count
- video_platform: channel_count / catalog_subscribe / alarm_subscribe
  / mobile_position_subscribe
- video_media_server: status / last_keepalive_time
- video_cloud_record: reserve
- video_device_mobile_position.channel_id: varchar(50) → bigint
  (DO 字段是 Long,作为外键引用 video_device_channel.id)

补齐 DO 缺失字段:
- AiAlgorithm: 新增 globalParams(对应 SQL global_params)
- StreamPush: 新增 status(对应 SQL status)

编译通过(mvn compile BUILD SUCCESS)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 12:07:47 +08:00
lzh
43becf998c refactor(video): projectId 两级隔离适配 + SQL 融合到 video.sql
SQL 融合:
- sql/mysql/video.sql 作为最终主脚本(26 张表),整合用户改造版表前缀 video_
  与 cherry-pick 版的框架字段(tenant_id/creator/updater/deleted/datetime)
- 新增 video_ai_camera_snapshot(AI 抓拍)、video_common_gb_channel(国标通道抽象)
- 删除旧的 aiot-video.sql(被 video.sql 替代)
- 17 张业务表 + 6 张 AI 业务表加 project_id 列(项目级隔离)
- 2 张字典表(video_ai_algorithm/video_ai_algo_template)仅租户级
- video_media_server 全局共享,无多租户字段

代码改造:
- 21 个 DO 的 @TableName 从 wvp_* 改为 video_*
- 16 个业务 DO 改继承 ProjectBaseDO(StreamProxy/StreamPush 通过
  CommonGBChannel 自动获得),字典 DO 保留 TenantBaseDO,
  MediaServer 保留 BaseDO
- 28 个 Mapper/Provider 的 SQL 表名全部更新为 video_*
- application.yaml 新增 tenant.ignore-project-tables 配置,
  列出 video_media_server/video_ai_algorithm/video_ai_algo_template
  不参与项目隔离
- 编译通过(mvn compile BUILD SUCCESS)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 11:10:27 +08:00
lzh
fe5bbbe8c6 refactor(video): 清理 Security/User stub,替换为框架 SecurityFrameworkUtils
- 删除 SecurityUtils/LoginUser/JwtUtils 3 个空壳 stub
- 删除 UserMapper/RoleMapper/UserApiKeyMapper 3 个废弃 Mapper 及 DTO
- 删除 IUserService/IRoleService/IUserApiKeyService 及实现类
- MediaController 改用 SecurityFrameworkUtils.getLoginUserId()
- 21 个 Controller 的 JwtUtils.HEADER 替换为 "Authorization" 字面量

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 10:15:20 +08:00
lzh
3c752aeb89 refactor(video): PageHelper → PageResult 分页迁移,删除 shim 兼容类
- 54 个文件从 PageHelper.startPage() + PageInfo 迁移到 MyBatis Plus Page + PageResult
- 复杂 @Select 查询加 IPage 参数实现自动分页
- 删除 PageHelper/PageInfo/StringUtil 3 个 shim 文件

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 10:15:20 +08:00
lzh
f48c1846fb refactor(video): Media/Stream 域 ORM 改造 + 全域硬删除转逻辑删除
- MediaServer 继承 BaseDO(共享表无 tenant_id)
- StreamProxy/StreamPush/CloudRecord/RecordPlan DO 改造
- 5 个 Mapper 继承 BaseMapperX
- 32 处 @Delete 硬删除转为逻辑删除(default 方法或 @Update SET deleted=1)
- Service/Controller/RPC 适配 int→Long 类型变化

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 10:15:19 +08:00
lzh
0b0c264dca refactor(video): GB28181 域 ORM 改造 — DO 继承 TenantBaseDO + Mapper 继承 BaseMapperX
- Device/Platform/Channel/Group/Region/Alarm/MobilePosition 等 DO 改造
- 9 个 Mapper 继承 BaseMapperX,简单 CRUD 改为 default 方法
- 复杂多表 JOIN/动态 SQL 保留 @Select 注解
- Service/Controller 适配 int→Long 类型变化

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 10:15:17 +08:00
lzh
0c061ad74c refactor(video): AI 域 ORM 改造 — DO 继承 TenantBaseDO + Mapper 继承 BaseMapperX
- 8 个 AI DO 加 @TableName、继承 TenantBaseDO、主键改 Long
- 9 个 AI Mapper 继承 BaseMapperX,简单 CRUD 改为 default 方法
- Service/Controller 适配类型变化(Integer→Long、删除手动 setCreateTime)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 10:15:15 +08:00
lzh
a604471e6f feat(video): Phase 5-9 编译修复、Controller 路径、数据库 SQL
Phase 5: 全局编译修复 — Security 引用清理、JT1078 引用移除
         PageInfo shim 兼容类(后续迁移到 PageResult)
         web/custom 和 web/gb28181 补充迁移
Phase 6: SecurityConfiguration 更新放行 Hook/SSE 路径
Phase 7: 32 个 Controller 路径 /api/ → /video/
Phase 8: aiot-video 数据库 SQL(25 张表,含多租户 tenant_id + 逻辑删除 deleted)
Phase 9: mvn compile BUILD SUCCESS

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 10:15:14 +08:00
lzh
d2c82d52c9 feat(video): Phase 0-4 WVP 代码搬迁、依赖、Redis 隔离、多租户配置
Phase 0: 前置检查完成(Java 21 语法无风险)
Phase 1: 574 个 Java 文件搬迁,包名替换 com.genersoft.iot.vmp → com.viewsh.module.video
Phase 2: pom.xml 添加 JAIN SIP/dom4j/okhttp/bouncycastle/fastjson2 等依赖
         application.yaml 添加 SIP/Media/UserSettings 配置段
Phase 3: RedisTemplate Bean 隔离(videoRedisTemplate),30+ 文件加 @Qualifier
Phase 4: 多租户配置(ignore-tables: wvp_media_server)

待 Phase 5: ORM 改造 + 编译修复

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 10:15:07 +08:00
lzh
948d2c6a41 feat(video): 新建 viewsh-module-video 服务模块骨架
新增视频管理模块,用于后续迁移 WVP-Platform(GB28181 视频监控平台)。
- viewsh-module-video-api: 契约层(Feign RPC 接口、枚举、错误码)
- viewsh-module-video-server: 业务层(端口 48093)
- 网关路由: video-admin-api / video-app-api
- SecurityConfiguration: 放行 Swagger/Actuator/Druid/RPC

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 10:15:02 +08:00