添加资源管理

结构优化
648540858 2023-08-24 16:15:58 +08:00
parent ca89fe85b7
commit 0701791902
8 changed files with 446 additions and 12 deletions

View File

@ -45,10 +45,10 @@ CREATE TABLE `wvp_common_business_group`
`common_business_group_id` bigint unsigned NOT NULL AUTO_INCREMENT, `common_business_group_id` bigint unsigned NOT NULL AUTO_INCREMENT,
`common_business_group_device_id` varchar(50) NOT NULL, `common_business_group_device_id` varchar(50) NOT NULL,
`common_business_group_name` varchar(255) 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_parent_id` varchar(50) DEFAULT NULL,
`common_business_group_path` varchar(500) 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`), PRIMARY KEY (`common_business_group_id`),
UNIQUE KEY `common_business_group_device_id` (`common_business_group_device_id`) UNIQUE KEY `common_business_group_device_id` (`common_business_group_device_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) 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_name` varchar(255) NOT NULL,
`common_region_parent_id` varchar(50) DEFAULT NULL, `common_region_parent_id` varchar(50) DEFAULT NULL,
`common_region_path` varchar(255) NOT 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`), PRIMARY KEY (`common_region_id`),
UNIQUE KEY `common_region_device_id` (`common_region_device_id`) UNIQUE KEY `common_region_device_id` (`common_region_device_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) 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` CREATE TABLE `wvp_common_platform_channel`
( (
`id` bigint unsigned NOT NULL AUTO_INCREMENT, `id` bigint unsigned NOT NULL AUTO_INCREMENT,
`platform_id` varchar(50) DEFAULT NULL, `platform_id` varchar(50) NOT NULL,
`common_gb_channel_id` int DEFAULT NULL, `common_gb_channel_id` varchar(50) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`), UNIQUE KEY `id` (`id`),
UNIQUE KEY `uk_platform_id_common_gb_channel_id` (`platform_id`,`common_gb_channel_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` CREATE TABLE `wvp_common_platform_region`
( (
`id` bigint unsigned NOT NULL AUTO_INCREMENT, `id` bigint unsigned NOT NULL AUTO_INCREMENT,
`platform_id` varchar(50) DEFAULT NULL, `platform_id` varchar(50) NOT NULL,
`region_id` int DEFAULT NULL, `region_id` varchar(50) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`), UNIQUE KEY `id` (`id`),
UNIQUE KEY `uk_platform_region_id` (`platform_id`,`region_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;

View File

@ -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<BusinessGroup> getNodes(String parentId);
/**
*
*/
List<CommonGbChannel> getChannels(int id);
/**
*
*/
List<CommonGbChannel> getChannels(String deviceId);
/**
*
*/
boolean add(BusinessGroup businessGroup);
/**
*
*/
boolean remove(int id);
/**
*
*/
boolean remove(String deviceId);
/**
*
*/
boolean update(BusinessGroup businessGroup);
/**
*
*/
boolean updateChannelsToBusinessGroup(int id, List<CommonGbChannel> channels);
/**
*
*/
boolean updateChannelsToBusinessGroup(String deviceId, List<CommonGbChannel> channels);
/**
*
*/
boolean removeChannelsFromBusinessGroup(List<CommonGbChannel> channels);
}

View File

@ -13,4 +13,14 @@ public interface ICommonGbChannelService {
int update(CommonGbChannel channel); int update(CommonGbChannel channel);
boolean checkChannelInPlatform(String channelId, String platformServerId); 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);
} }

View File

@ -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;
}
}

View File

@ -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<BusinessGroup> getNodes(String parentId) {
return businessGroupDao.getNodes(parentId);
}
@Override
public List<CommonGbChannel> getChannels(int id) {
BusinessGroup businessGroup = businessGroupDao.query(id);
if (businessGroup == null) {
return null;
}
return commonGbChannelDao.getChannels(businessGroup.getCommonBusinessGroupPath());
}
@Override
public List<CommonGbChannel> 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<CommonGbChannel> 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<CommonGbChannel> 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<CommonGbChannel> channels) {
// TODO 增加对数量的判断,分批处理
return commonGbChannelDao.removeChannelsForBusinessGroup(channels) > 1;
}
}

View File

@ -1,33 +1,57 @@
package com.genersoft.iot.vmp.service.impl; package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.common.CommonGbChannel; 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.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 org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public class CommonGbChannelServiceImpl implements ICommonGbChannelService { public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
@Autowired
private CommonGbChannelMapper commonGbChannelMapper;
@Autowired
private DeviceChannelMapper deviceChannelMapper;
@Override @Override
public CommonGbChannel getChannel(String channelId) { public CommonGbChannel getChannel(String channelId) {
return null; return commonGbChannelMapper.queryByDeviceID(channelId);
} }
@Override @Override
public int add(CommonGbChannel channel) { public int add(CommonGbChannel channel) {
return 0; return commonGbChannelMapper.add(channel);
} }
@Override @Override
public int delete(String channelId) { public int delete(String channelId) {
return 0; return commonGbChannelMapper.deleteByDeviceID(channelId);
} }
@Override @Override
public int update(CommonGbChannel channel) { public int update(CommonGbChannel channel) {
return 0; return commonGbChannelMapper.update(channel);
} }
@Override @Override
public boolean checkChannelInPlatform(String channelId, String platformServerId) { 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<DeviceChannel> deviceChannels = deviceChannelMapper.queryAllChannels(gbDeviceId);
if (deviceChannels.isEmpty()) {
return false;
}
return false; return false;
} }
} }

View File

@ -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 = {" <script>" +
" select * from wvp_common_business_group " +
" WHERE 1=1 " +
" <if test='parentId != null' > AND common_business_group_parent_id = #{parentId}</if>" +
" <if test='parentId == null' > AND common_business_group_parent_id is null </if>" +
" order by common_business_group_id ASC " +
" </script>"})
List<BusinessGroup> 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 = {" <script>" +
"UPDATE wvp_common_business_group " +
"SET common_business_group_update_time=#{commonBusinessGroupUpdateTime}" +
"<if test='commonBusinessGroupName != null'>, common_business_group_name=#{commonBusinessGroupName}</if>" +
"<if test='commonBusinessGroupDeviceId != null'>, common_business_group_device_id=#{commonBusinessGroupDeviceId}</if>" +
"<if test='commonBusinessGroupParentId != null'>, common_business_group_parent_id=#{commonBusinessGroupParentId}</if>" +
"<if test='commonBusinessGroupPath != null'>, common_business_group_path=#{commonBusinessGroupPath}</if>" +
"<if test='commonBusinessGroupUpdateTime != null'>, common_business_group_update_time=#{commonBusinessGroupUpdateTime}</if>" +
"WHERE common_business_group_id=#{commonBusinessGroupId}" +
" </script>"})
int update(BusinessGroup businessGroup);
}

View File

@ -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<CommonGbChannel> getChannels(String commonBusinessGroupPath);
int updateChanelForBusinessGroup(List<CommonGbChannel> channels);
int removeChannelsForBusinessGroup(List<CommonGbChannel> 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);
}