diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Region.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Region.java index 627fca6cd..60c860084 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Region.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Region.java @@ -15,50 +15,50 @@ public class Region implements Comparable{ * 数据库自增ID */ @Schema(description = "数据库自增ID") - private int commonRegionId; + private int id; /** * 区域国标编号 */ @Schema(description = "区域国标编号") - private String commonRegionDeviceId; + private String deviceId; /** * 区域名称 */ @Schema(description = "区域名称") - private String commonRegionName; + private String name; /** * 父区域国标ID */ @Schema(description = "父区域国标ID") - private String commonRegionParentId; + private String parentDeviceId; /** * 创建时间 */ @Schema(description = "创建时间") - private String commonRegionCreateTime; + private String createTime; /** * 更新时间 */ @Schema(description = "更新时间") - private String commonRegionUpdateTime; + private String updateTime; public static Region getInstance(String commonRegionDeviceId, String commonRegionName, String commonRegionParentId) { Region region = new Region(); - region.setCommonRegionDeviceId(commonRegionDeviceId); - region.setCommonRegionName(commonRegionName); - region.setCommonRegionParentId(commonRegionParentId); - region.setCommonRegionCreateTime(DateUtil.getNow()); - region.setCommonRegionUpdateTime(DateUtil.getNow()); + region.setDeviceId(commonRegionDeviceId); + region.setName(commonRegionName); + region.setParentDeviceId(commonRegionParentId); + region.setCreateTime(DateUtil.getNow()); + region.setUpdateTime(DateUtil.getNow()); return region; } @Override public int compareTo(@NotNull Region region) { - return Integer.compare(Integer.parseInt(this.commonRegionDeviceId), Integer.parseInt(region.getCommonRegionDeviceId())); + return Integer.compare(Integer.parseInt(this.deviceId), Integer.parseInt(region.getDeviceId())); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java index 1c8e10607..71f56db3f 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java @@ -1,17 +1,37 @@ package com.genersoft.iot.vmp.gb28181.dao; import com.genersoft.iot.vmp.gb28181.bean.Region; -import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.*; import java.util.List; @Mapper public interface RegionMapper { + + @Insert("INSERT INTO wvp_common_region (device_id, name, parent_device_id, create_time, update_time) " + + "VALUES (#{deviceId}, #{name}, #{parentDeviceId}, #{createTime}, #{updateTime})") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void add(Region region); - List query(String query); + @Delete("DELETE FROM wvp_common_region WHERE id=#{id}") + int delete(@Param("id") int id); - List getChildren(String regionParentId); + @Update(" UPDATE wvp_common_region " + + " SET update_time=#{updateTime}, device_id=#{deviceId}, name=#{name}, parent_device_id=#{parentDeviceId}" + + " WHERE id = #{id}") + int update(Region region); - Region queryRegion(int id); + @Select(value = {" "}) + List query(@Param("query") String query, @Param("parentId") String parentId); + + @Select("SELECT * from wvp_common_region WHERE parent_device_id = #{parentId} ORDER BY id ") + List getChildren(String parentId); + + @Select("SELECT * from wvp_common_region WHERE id = #{id} ") + Region queryOne(int id); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/RegionServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/RegionServiceImpl.java index a3cd6b710..56053bad9 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/RegionServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/RegionServiceImpl.java @@ -35,13 +35,13 @@ public class RegionServiceImpl implements IRegionService { @Override public void add(Region region) { - assert region.getCommonRegionName() != null; - assert region.getCommonRegionDeviceId() != null; - if (ObjectUtils.isEmpty(region.getCommonRegionParentId().trim())) { - region.setCommonRegionParentId(null); + assert region.getName() != null; + assert region.getDeviceId() != null; + if (ObjectUtils.isEmpty(region.getParentDeviceId().trim())) { + region.setParentDeviceId(null); } - region.setCommonRegionCreateTime(DateUtil.getNow()); - region.setCommonRegionUpdateTime(DateUtil.getNow()); + region.setCreateTime(DateUtil.getNow()); + region.setUpdateTime(DateUtil.getNow()); regionMapper.add(region); } diff --git a/数据库/2.7.2-重构/初始化-mysql-2.7.2.sql b/数据库/2.7.2-重构/初始化-mysql-2.7.2.sql index 73d5a8410..673ae0332 100644 --- a/数据库/2.7.2-重构/初始化-mysql-2.7.2.sql +++ b/数据库/2.7.2-重构/初始化-mysql-2.7.2.sql @@ -381,5 +381,26 @@ create table wvp_user_api_key ( INSERT INTO wvp_user VALUES (1, 'admin','21232f297a57a5a743894a0e4a801fc3',1,'2021-04-13 14:14:57','2021-04-13 14:14:57','3e80d1762a324d5b0ff636e0bd16f1e3'); INSERT INTO wvp_user_role VALUES (1, 'admin','0','2021-04-13 14:14:57','2021-04-13 14:14:57'); +CREATE TABLE wvp_common_group +( + id serial primary key, + device_id varchar(50) NOT NULL, + name varchar(255) NOT NULL, + parent_device_id varchar(50) DEFAULT NULL, + business_group varchar(50) DEFAULT NULL, + create_time varchar(50) NOT NULL, + update_time varchar(50) NOT NULL, + UNIQUE KEY common_group_device_id (device_id) +); +CREATE TABLE wvp_common_region +( + id serial primary key, + device_id varchar(50) NOT NULL, + name varchar(255) NOT NULL, + parent_device_id varchar(50) DEFAULT NULL, + create_time varchar(50) NOT NULL, + update_time varchar(50) NOT NULL, + UNIQUE KEY common_region_device_id (device_id) +);