diff --git a/sql/common.sql b/sql/common.sql index e839e125..54cc46ef 100644 --- a/sql/common.sql +++ b/sql/common.sql @@ -45,10 +45,10 @@ CREATE TABLE `wvp_common_business_group` `common_business_group_id` bigint unsigned NOT NULL AUTO_INCREMENT, `common_business_group_device_id` varchar(50) NOT NULL, `common_business_group_name` varchar(255) NOT NULL, - `common_business_group_civilCode` varchar(50) DEFAULT NULL, `common_business_group_parent_id` varchar(50) DEFAULT NULL, `common_business_group_path` varchar(500) DEFAULT NULL, - `type` varchar(255) NOT NULL, + `common_business_group_create_time` varchar(50) NOT NULL, + `common_business_group_update_time` varchar(50) NOT NULL, PRIMARY KEY (`common_business_group_id`), UNIQUE KEY `common_business_group_device_id` (`common_business_group_device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; @@ -60,6 +60,8 @@ CREATE TABLE `wvp_common_region` `common_region_name` varchar(255) NOT NULL, `common_region_parent_id` varchar(50) DEFAULT NULL, `common_region_path` varchar(255) NOT NULL, + `common_region_create_time` varchar(50) NOT NULL, + `common_region_update_time` varchar(50) NOT NULL, PRIMARY KEY (`common_region_id`), UNIQUE KEY `common_region_device_id` (`common_region_device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; @@ -67,22 +69,26 @@ CREATE TABLE `wvp_common_region` CREATE TABLE `wvp_common_platform_channel` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, - `platform_id` varchar(50) DEFAULT NULL, - `common_gb_channel_id` int DEFAULT NULL, + `platform_id` varchar(50) NOT NULL, + `common_gb_channel_id` varchar(50) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), UNIQUE KEY `uk_platform_id_common_gb_channel_id` (`platform_id`,`common_gb_channel_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_0900_ai_ci; CREATE TABLE `wvp_common_platform_region` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, - `platform_id` varchar(50) DEFAULT NULL, - `region_id` int DEFAULT NULL, + `platform_id` varchar(50) NOT NULL, + `region_id` varchar(50) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), UNIQUE KEY `uk_platform_region_id` (`platform_id`,`region_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_0900_ai_ci; diff --git a/src/main/java/com/genersoft/iot/vmp/service/IBusinessGroupService.java b/src/main/java/com/genersoft/iot/vmp/service/IBusinessGroupService.java new file mode 100644 index 00000000..3dd77638 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/IBusinessGroupService.java @@ -0,0 +1,64 @@ +package com.genersoft.iot.vmp.service; + +import com.genersoft.iot.vmp.common.CommonGbChannel; +import com.genersoft.iot.vmp.service.bean.BusinessGroup; + +import java.util.List; + +/** + * 业务分组 + */ +public interface IBusinessGroupService { + + /** + * 查询业务分组 + */ + List getNodes(String parentId); + + /** + * 查询业务分组下的通道 + */ + List getChannels(int id); + + /** + * 查询业务分组下的通道 + */ + List getChannels(String deviceId); + + /** + * 添加业务分组 + */ + boolean add(BusinessGroup businessGroup); + + /** + * 移除业务分组 + */ + boolean remove(int id); + + /** + * 移除业务分组 + */ + boolean remove(String deviceId); + + /** + * 更新业务分组 + */ + boolean update(BusinessGroup businessGroup); + + /** + * 设置国标设备到相关的分组中 + */ + boolean updateChannelsToBusinessGroup(int id, List channels); + + /** + * 设置国标设备到相关的分组中 + */ + boolean updateChannelsToBusinessGroup(String deviceId, List channels); + + /** + * 移除分组分组中的通道 + */ + boolean removeChannelsFromBusinessGroup(List channels); + + +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java index aa06d0a5..80ee9a69 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java @@ -13,4 +13,14 @@ public interface ICommonGbChannelService { int update(CommonGbChannel channel); boolean checkChannelInPlatform(String channelId, String platformServerId); + + /** + * 从国标设备中同步通道 + * + * @param gbDeviceId 国标设备编号 + * @param syncCoordinate 是否同步位置信息,TRUE 则使用国标设备里的位置信息, 第一次同步按照TRUE执行,此参数无效 + * @param syncBusinessGroup 是否同步业务分组,TRUE则使用国标设备的业务分组 + * @param syncRegion 是否同步行政区划,TRUE则使用国标设备的行政区划 + */ + boolean SyncChannelFromGb28181Device(String gbDeviceId, boolean syncCoordinate, boolean syncBusinessGroup, boolean syncRegion); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/BusinessGroup.java b/src/main/java/com/genersoft/iot/vmp/service/bean/BusinessGroup.java new file mode 100644 index 00000000..f9723bd8 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/bean/BusinessGroup.java @@ -0,0 +1,98 @@ +package com.genersoft.iot.vmp.service.bean; + +/** + * 业务分组数据 + */ +public class BusinessGroup { + + /** + * 数据库自增ID + */ + private int commonBusinessGroupId; + + /** + * 分组国标编号 + */ + private String commonBusinessGroupDeviceId; + + /** + * 分组名称 + */ + private String commonBusinessGroupName; + + /** + * 分组名称 + */ + private String commonBusinessGroupParentId; + + /** + * 分组树的路径 + */ + private String commonBusinessGroupPath; + + /** + * 创建时间 + */ + private String commonBusinessGroupCreateTime; + + /** + * 更新时间 + */ + private String commonBusinessGroupUpdateTime; + + public int getCommonBusinessGroupId() { + return commonBusinessGroupId; + } + + public void setCommonBusinessGroupId(int commonBusinessGroupId) { + this.commonBusinessGroupId = commonBusinessGroupId; + } + + public String getCommonBusinessGroupDeviceId() { + return commonBusinessGroupDeviceId; + } + + public void setCommonBusinessGroupDeviceId(String commonBusinessGroupDeviceId) { + this.commonBusinessGroupDeviceId = commonBusinessGroupDeviceId; + } + + public String getCommonBusinessGroupName() { + return commonBusinessGroupName; + } + + public void setCommonBusinessGroupName(String commonBusinessGroupName) { + this.commonBusinessGroupName = commonBusinessGroupName; + } + + public String getCommonBusinessGroupPath() { + return commonBusinessGroupPath; + } + + public void setCommonBusinessGroupPath(String commonBusinessGroupPath) { + this.commonBusinessGroupPath = commonBusinessGroupPath; + } + + public String getCommonBusinessGroupParentId() { + return commonBusinessGroupParentId; + } + + public void setCommonBusinessGroupParentId(String commonBusinessGroupParentId) { + this.commonBusinessGroupParentId = commonBusinessGroupParentId; + } + + public String getCommonBusinessGroupCreateTime() { + return commonBusinessGroupCreateTime; + } + + public void setCommonBusinessGroupCreateTime(String commonBusinessGroupCreateTime) { + this.commonBusinessGroupCreateTime = commonBusinessGroupCreateTime; + } + + public String getCommonBusinessGroupUpdateTime() { + return commonBusinessGroupUpdateTime; + } + + public void setCommonBusinessGroupUpdateTime(String commonBusinessGroupUpdateTime) { + this.commonBusinessGroupUpdateTime = commonBusinessGroupUpdateTime; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/BusinessGroupServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/BusinessGroupServiceImpl.java new file mode 100644 index 00000000..6cdbf3cb --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/BusinessGroupServiceImpl.java @@ -0,0 +1,138 @@ +package com.genersoft.iot.vmp.service.impl; + +import com.genersoft.iot.vmp.common.CommonGbChannel; +import com.genersoft.iot.vmp.service.IBusinessGroupService; +import com.genersoft.iot.vmp.service.bean.BusinessGroup; +import com.genersoft.iot.vmp.storager.dao.BusinessGroupMapper; +import com.genersoft.iot.vmp.storager.dao.CommonGbChannelMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.stereotype.Service; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.TransactionStatus; + +import java.util.List; + +@Service +public class BusinessGroupServiceImpl implements IBusinessGroupService { + + private final static Logger logger = LoggerFactory.getLogger(BusinessGroupServiceImpl.class); + + @Autowired + private CommonGbChannelMapper commonGbChannelDao; + + @Autowired + private BusinessGroupMapper businessGroupDao; + + @Autowired + DataSourceTransactionManager dataSourceTransactionManager; + + @Autowired + TransactionDefinition transactionDefinition; + + + @Override + public List getNodes(String parentId) { + return businessGroupDao.getNodes(parentId); + } + + @Override + public List getChannels(int id) { + BusinessGroup businessGroup = businessGroupDao.query(id); + if (businessGroup == null) { + return null; + } + return commonGbChannelDao.getChannels(businessGroup.getCommonBusinessGroupPath()); + } + + @Override + public List getChannels(String deviceId) { + BusinessGroup businessGroup = businessGroupDao.queryByDeviceId(deviceId); + if (businessGroup == null) { + return null; + } + return commonGbChannelDao.getChannels(businessGroup.getCommonBusinessGroupPath()); + } + + @Override + public boolean add(BusinessGroup businessGroup) { + return businessGroupDao.add(businessGroup) > 0; + } + + @Override + public boolean remove(int id) { + return businessGroupDao.remove(id) > 0; + } + + @Override + public boolean remove(String deviceId) { + return businessGroupDao.removeByDeviceId(deviceId) > 0; + } + + @Override + public boolean update(BusinessGroup businessGroup) { + if (businessGroup.getCommonBusinessGroupId() == 0) { + return false; + } + BusinessGroup businessGroupInDb = businessGroupDao.query(businessGroup.getCommonBusinessGroupId()); + if (businessGroupInDb == null) { + return false; + } + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); + boolean result = false; + if (!businessGroupInDb.getCommonBusinessGroupPath().equals(businessGroup.getCommonBusinessGroupPath())) { + // 需要更新通道信息 + int updateCount = commonGbChannelDao.updateBusinessGroupPath(businessGroup.getCommonBusinessGroupPath()); + if (updateCount > 0) { + dataSourceTransactionManager.rollback(transactionStatus); + return false; + } else { + result = businessGroupDao.update(businessGroup) > 0; + } + } else { + result = businessGroupDao.update(businessGroup) > 0; + } + return result; + } + + @Override + public boolean updateChannelsToBusinessGroup(int id, List channels) { + if (channels.isEmpty()) { + return false; + } + BusinessGroup businessGroup = businessGroupDao.query(id); + if (businessGroup == null) { + return false; + } + for (CommonGbChannel channel : channels) { + channel.setCommonGbBusinessGroupID(businessGroup.getCommonBusinessGroupPath()); + } + // TODO 增加对数量的判断,分批处理 + return commonGbChannelDao.updateChanelForBusinessGroup(channels) > 1; + } + + @Override + public boolean updateChannelsToBusinessGroup(String deviceId, List channels) { + if (channels.isEmpty()) { + return false; + } + BusinessGroup businessGroup = businessGroupDao.queryByDeviceId(deviceId); + if (businessGroup == null) { + return false; + } + for (CommonGbChannel channel : channels) { + channel.setCommonGbBusinessGroupID(businessGroup.getCommonBusinessGroupPath()); + } + // TODO 增加对数量的判断,分批处理 + return commonGbChannelDao.updateChanelForBusinessGroup(channels) > 1; + } + + @Override + public boolean removeChannelsFromBusinessGroup(List channels) { + // TODO 增加对数量的判断,分批处理 + return commonGbChannelDao.removeChannelsForBusinessGroup(channels) > 1; + } + +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java index 53873069..82c8915e 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java @@ -1,33 +1,57 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.common.CommonGbChannel; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.service.ICommonGbChannelService; +import com.genersoft.iot.vmp.storager.dao.CommonGbChannelMapper; +import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Service public class CommonGbChannelServiceImpl implements ICommonGbChannelService { + + @Autowired + private CommonGbChannelMapper commonGbChannelMapper; + + @Autowired + private DeviceChannelMapper deviceChannelMapper; + + @Override public CommonGbChannel getChannel(String channelId) { - return null; + return commonGbChannelMapper.queryByDeviceID(channelId); } @Override public int add(CommonGbChannel channel) { - return 0; + return commonGbChannelMapper.add(channel); } @Override public int delete(String channelId) { - return 0; + return commonGbChannelMapper.deleteByDeviceID(channelId); } @Override public int update(CommonGbChannel channel) { - return 0; + return commonGbChannelMapper.update(channel); } @Override public boolean checkChannelInPlatform(String channelId, String platformServerId) { + return commonGbChannelMapper.checkChannelInPlatform(channelId, platformServerId); + } + + @Override + public boolean SyncChannelFromGb28181Device(String gbDeviceId, boolean syncCoordinate, boolean syncBusinessGroup, boolean syncRegion) { + List deviceChannels = deviceChannelMapper.queryAllChannels(gbDeviceId); + if (deviceChannels.isEmpty()) { + return false; + } + return false; } } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/BusinessGroupMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/BusinessGroupMapper.java new file mode 100644 index 00000000..c1704c28 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/BusinessGroupMapper.java @@ -0,0 +1,65 @@ +package com.genersoft.iot.vmp.storager.dao; + +import com.genersoft.iot.vmp.service.bean.BusinessGroup; +import org.apache.ibatis.annotations.*; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Mapper +@Repository +public interface BusinessGroupMapper { + + @Select(value = {" "}) + List getNodes(String parentId); + + @Select(" select * from wvp_common_business_group " + + " WHERE common_business_group_id = #{id} ") + BusinessGroup query(int id); + + @Select(" select * from wvp_common_business_group " + + " WHERE common_business_group_device_id = #{deviceId} ") + BusinessGroup queryByDeviceId(String deviceId); + + @Insert("INSERT INTO wvp_common_business_group (" + + "common_business_group_device_id, " + + "common_business_group_name, " + + "common_business_group_parent_id, " + + "common_business_group_path, " + + "common_business_group_update_time, " + + "common_business_group_create_time ) " + + "VALUES (" + + "#{commonBusinessGroupDeviceId}, " + + "#{commonBusinessGroupName}, " + + "#{commonBusinessGroupParentId}, " + + "#{commonBusinessGroupPath}, " + + "#{commonBusinessGroupUpdateTime}, " + + "#{commonBusinessGroupCreateTime})") + int add(BusinessGroup businessGroup); + + @Delete("delete from wvp_common_business_group where common_business_group_id = #{id}") + int remove(int id); + + + @Delete("delete from wvp_common_business_group where common_business_group_device_id = #{deviceId}") + int removeByDeviceId(String deviceId); + + + @Update(value = {" "}) + int update(BusinessGroup businessGroup); +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java new file mode 100644 index 00000000..e23e7124 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java @@ -0,0 +1,29 @@ +package com.genersoft.iot.vmp.storager.dao; + +import com.genersoft.iot.vmp.common.CommonGbChannel; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Mapper +@Repository +public interface CommonGbChannelMapper { + List getChannels(String commonBusinessGroupPath); + + int updateChanelForBusinessGroup(List channels); + + int removeChannelsForBusinessGroup(List channels); + + int updateBusinessGroupPath(String commonBusinessGroupPath); + + CommonGbChannel queryByDeviceID(String channelId); + + int add(CommonGbChannel channel); + + int deleteByDeviceID(String channelId); + + int update(CommonGbChannel channel); + + boolean checkChannelInPlatform(String channelId, String platformServerId); +}