fix(video): 修复 CommonGBChannel 子类 @TableId 冲突与主键列映射

问题:
1. CommonGBChannel.gbId 的 @TableId 按驼峰转 snake_case 映射到 gb_id 列,
   但实际所有相关表的主键列都是 id
2. StreamProxy/StreamPush 子类自己声明 @TableId(id),与父类 gbId 的
   @TableId 同时扫描到 MyBatis-Plus 会报 "@TableId can't more than one"
3. DeviceChannel/PlatformChannel 没自己的 @TableId,运行时会用父类 gbId
   作为主键查 gb_id 列 → Unknown column 运行时错误

修复:
- CommonGBChannel.gbId 的 @TableId 加 value="id" 显式映射到 id 列
  保证 CommonGBChannelMapper 操作 video_common_gb_channel 时主键正确
- 4 个子类(StreamProxy/StreamPush/DeviceChannel/PlatformChannel)均
  shadow 父类 gbId 字段:
    @TableField(exist = false)
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private Long gbId;
  让 MyBatis-Plus 反射扫描时只看到子类 gbId(标记 exist=false 跳过),
  父类 @TableId 不参与扫描;Lombok 禁用子类 getter/setter,所有业务
  代码的 setGbId/getGbId 继续走父类访问器,字段存储在父类
- DeviceChannel 和 PlatformChannel 给自己的 id 字段加 @TableId(IdType.AUTO)
  显式声明各子表主键

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
lzh
2026-04-22 14:40:13 +08:00
parent d876d0387a
commit b3d76ad00c
5 changed files with 46 additions and 1 deletions

View File

@@ -15,7 +15,8 @@ import lombok.EqualsAndHashCode;
@Schema(description = "国标通道")
public class CommonGBChannel extends ProjectBaseDO {
@TableId(type = IdType.AUTO)
// video_common_gb_channel 主键列是 id显式指定避免驼峰转换成 gb_id
@TableId(value = "id", type = IdType.AUTO)
@Schema(description = "国标-数据库自增ID")
private Long gbId;

View File

@@ -1,13 +1,18 @@
package com.viewsh.module.video.gb28181.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.viewsh.module.video.common.enums.ChannelDataType;
import com.viewsh.module.video.gb28181.utils.MessageElementForCatalog;
import com.viewsh.module.video.gb28181.utils.XmlUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Element;
import org.springframework.util.ObjectUtils;
@@ -21,6 +26,13 @@ import java.lang.reflect.InvocationTargetException;
@EqualsAndHashCode(callSuper = true)
public class DeviceChannel extends CommonGBChannel {
// shadow 父类 gbId仅让 MyBatis-Plus 跳过父类 @TableIdLombok 禁用子类访问器保留父类 getter/setter
@TableField(exist = false)
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private Long gbId;
@TableId(type = IdType.AUTO)
@Schema(description = "数据库自增ID")
private Long id;

View File

@@ -1,16 +1,28 @@
package com.viewsh.module.video.gb28181.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@TableName("video_platform_channel")
@EqualsAndHashCode(callSuper = true)
@Data
public class PlatformChannel extends CommonGBChannel {
// shadow 父类 gbId仅让 MyBatis-Plus 跳过父类 @TableIdLombok 禁用子类访问器保留父类 getter/setter
@TableField(exist = false)
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private Long gbId;
@TableId(type = IdType.AUTO)
@Schema(description = "Id")
private Long id;

View File

@@ -1,13 +1,17 @@
package com.viewsh.module.video.streamProxy.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.viewsh.module.video.common.enums.ChannelDataType;
import com.viewsh.module.video.gb28181.bean.CommonGBChannel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.ObjectUtils;
/**
@@ -19,6 +23,13 @@ import org.springframework.util.ObjectUtils;
@EqualsAndHashCode(callSuper = true)
public class StreamProxy extends CommonGBChannel {
// shadow 父类 gbId 字段:仅让 MyBatis-Plus 扫描时跳过父类 @TableId
// Lombok 禁用 getter/setter 确保父类访问器继续工作(所有业务代码通过父类 getGbId/setGbId 操作同一字段)
@TableField(exist = false)
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private Long gbId;
/**
* 数据库自增ID
*/

View File

@@ -9,9 +9,12 @@ import com.viewsh.module.video.common.enums.ChannelDataType;
import com.viewsh.module.video.gb28181.bean.CommonGBChannel;
import com.viewsh.module.video.media.event.media.MediaArrivalEvent;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.springframework.util.ObjectUtils;
@@ -23,6 +26,12 @@ import org.springframework.util.ObjectUtils;
@NoArgsConstructor
public class StreamPush extends CommonGBChannel implements Comparable<StreamPush>{
// shadow 父类 gbId仅让 MyBatis-Plus 跳过父类 @TableIdLombok 禁用子类访问器保留父类 getter/setter
@TableField(exist = false)
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private Long gbId;
/**
* id
*/