From 43fe078723f71dd797bcd7c2ebaac66170febb39 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 25 Aug 2023 15:49:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=9A=E9=81=93=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/common.sql | 8 +- .../iot/vmp/common/CommonGbChannel.java | 38 ++- .../vmp/service/ICommonGbChannelService.java | 10 +- .../impl/BusinessGroupServiceImpl.java | 3 +- .../impl/CommonGbChannelServiceImpl.java | 147 +++++++++- .../storager/dao/CommonGbChannelMapper.java | 260 +++++++++++++++++- 6 files changed, 448 insertions(+), 18 deletions(-) diff --git a/sql/common.sql b/sql/common.sql index 54cc46ef..2aab4e13 100644 --- a/sql/common.sql +++ b/sql/common.sql @@ -2,11 +2,11 @@ CREATE TABLE `wvp_common_gb_channel` ( `common_gb_id` bigint unsigned NOT NULL AUTO_INCREMENT, `common_gb_device_id` varchar(50) NOT NULL, - `common_gb_name` varchar(255) NOT NULL, + `common_gb_name` varchar(255) DEFAULT NULL, `common_gb_manufacturer` varchar(255) DEFAULT NULL, `common_gb_model` varchar(255) DEFAULT NULL, `common_gb_owner` varchar(255) DEFAULT NULL, - `common_gb_civilCode` varchar(50) NOT NULL, + `common_gb_civilCode` varchar(50) DEFAULT NULL, `common_gb_block` varchar(255) DEFAULT NULL, `common_gb_address` varchar(255) DEFAULT NULL, `common_gb_parental` integer, @@ -21,7 +21,7 @@ CREATE TABLE `wvp_common_gb_channel` `common_gb_ip_address` varchar(50) DEFAULT NULL, `common_gb_port` integer, `common_gb_password` varchar(50) DEFAULT NULL, - `common_gb_status` varchar(50) DEFAULT 'OFF', + `common_gb_status` bool default false, `common_gb_longitude` double, `common_gb_latitude` double, `common_gb_ptz_type` integer, @@ -35,6 +35,8 @@ CREATE TABLE `wvp_common_gb_channel` `common_gb_download_speed` varchar(255) DEFAULT NULL, `common_gb_svc_time_support_mode` integer, `type` varchar(255) NOT NULL, + `updateTime` varchar(50) NOT NULL, + `createTime` varchar(50) NOT NULL, PRIMARY KEY (`common_gb_id`), UNIQUE KEY `common_gb_device_id` (`common_gb_device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; diff --git a/src/main/java/com/genersoft/iot/vmp/common/CommonGbChannel.java b/src/main/java/com/genersoft/iot/vmp/common/CommonGbChannel.java index 2a4198c2..a2462269 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/CommonGbChannel.java +++ b/src/main/java/com/genersoft/iot/vmp/common/CommonGbChannel.java @@ -144,7 +144,7 @@ public class CommonGbChannel { * 设备状态(必选) */ @Schema(description = "设备状态(必选)") - private String commonGbStatus; + private Boolean commonGbStatus; /** * 国标字段:经度(可选) @@ -290,6 +290,18 @@ public class CommonGbChannel { @Schema(description = "类型: 28181, push, proxy") private String type; + /** + * 更新时间 + */ + @Schema(description = "更新时间") + private String updateTime; + + /** + * 创建时间 + */ + @Schema(description = "创建时间") + private String createTime; + public int getCommonGbId() { return commonGbId; } @@ -458,11 +470,11 @@ public class CommonGbChannel { this.commonGbPassword = commonGbPassword; } - public String getCommonGbStatus() { + public boolean getCommonGbStatus() { return commonGbStatus; } - public void setCommonGbStatus(String commonGbStatus) { + public void setCommonGbStatus(boolean commonGbStatus) { this.commonGbStatus = commonGbStatus; } @@ -569,4 +581,24 @@ public class CommonGbChannel { public void setType(String type) { this.type = type; } + + public void setCommonGbStatus(Boolean commonGbStatus) { + this.commonGbStatus = commonGbStatus; + } + + public String getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } } 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 80ee9a69..f0025ede 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java @@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.service; import com.genersoft.iot.vmp.common.CommonGbChannel; +import java.util.List; + public interface ICommonGbChannelService { CommonGbChannel getChannel(String channelId); @@ -17,10 +19,8 @@ public interface ICommonGbChannelService { /** * 从国标设备中同步通道 * - * @param gbDeviceId 国标设备编号 - * @param syncCoordinate 是否同步位置信息,TRUE 则使用国标设备里的位置信息, 第一次同步按照TRUE执行,此参数无效 - * @param syncBusinessGroup 是否同步业务分组,TRUE则使用国标设备的业务分组 - * @param syncRegion 是否同步行政区划,TRUE则使用国标设备的行政区划 + * @param gbDeviceId 国标设备编号 + * @param syncKeys 要同步的字段 */ - boolean SyncChannelFromGb28181Device(String gbDeviceId, boolean syncCoordinate, boolean syncBusinessGroup, boolean syncRegion); + boolean SyncChannelFromGb28181Device(String gbDeviceId, List syncKeys); } 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 index 6cdbf3cb..755cbedc 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/BusinessGroupServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/BusinessGroupServiceImpl.java @@ -84,7 +84,7 @@ public class BusinessGroupServiceImpl implements IBusinessGroupService { boolean result = false; if (!businessGroupInDb.getCommonBusinessGroupPath().equals(businessGroup.getCommonBusinessGroupPath())) { // 需要更新通道信息 - int updateCount = commonGbChannelDao.updateBusinessGroupPath(businessGroup.getCommonBusinessGroupPath()); + int updateCount = commonGbChannelDao.updateBusinessGroupPath(businessGroupInDb.getCommonBusinessGroupPath(), businessGroup.getCommonBusinessGroupPath()); if (updateCount > 0) { dataSourceTransactionManager.rollback(transactionStatus); return false; @@ -94,6 +94,7 @@ public class BusinessGroupServiceImpl implements IBusinessGroupService { } else { result = businessGroupDao.update(businessGroup) > 0; } + dataSourceTransactionManager.commit(transactionStatus); return result; } 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 82c8915e..15c8857d 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 @@ -5,9 +5,14 @@ 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.apache.commons.lang3.math.NumberUtils; 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.ArrayList; import java.util.List; @Service @@ -19,6 +24,12 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { @Autowired private DeviceChannelMapper deviceChannelMapper; + @Autowired + DataSourceTransactionManager dataSourceTransactionManager; + + @Autowired + TransactionDefinition transactionDefinition; + @Override public CommonGbChannel getChannel(String channelId) { @@ -42,16 +53,146 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { @Override public boolean checkChannelInPlatform(String channelId, String platformServerId) { - return commonGbChannelMapper.checkChannelInPlatform(channelId, platformServerId); + return commonGbChannelMapper.checkChannelInPlatform(channelId, platformServerId) > 0; } @Override - public boolean SyncChannelFromGb28181Device(String gbDeviceId, boolean syncCoordinate, boolean syncBusinessGroup, boolean syncRegion) { + public boolean SyncChannelFromGb28181Device(String gbDeviceId, List syncKeys) { List deviceChannels = deviceChannelMapper.queryAllChannels(gbDeviceId); if (deviceChannels.isEmpty()) { return false; } + List commonGbChannelList = new ArrayList<>(deviceChannels.size()); + for (DeviceChannel deviceChannel : deviceChannels) { + CommonGbChannel commonGbChannel = getCommonChannelFromDeviceChannel(deviceChannel, syncKeys); + commonGbChannelList.add(commonGbChannel); + } + int limit = 300; + boolean result; + if (commonGbChannelList.size() <= limit) { + result = commonGbChannelMapper.addAll(commonGbChannelList) > 0; + } else { + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); + for (int i = 0; i < commonGbChannelList.size(); i += limit) { + int toIndex = i + limit; + if (i + limit > commonGbChannelList.size()) { + toIndex = commonGbChannelList.size(); + } + List commonGbChannelListSub = commonGbChannelList.subList(i, toIndex); + int currentResult = commonGbChannelMapper.addAll(commonGbChannelListSub); + if (currentResult <= 0) { + dataSourceTransactionManager.rollback(transactionStatus); + return false; + } + } + dataSourceTransactionManager.commit(transactionStatus); + result = true; + } + return result; + } - return false; + private CommonGbChannel getCommonChannelFromDeviceChannel(DeviceChannel deviceChannel, List syncKeys) { + if (deviceChannel == null || syncKeys == null || syncKeys.isEmpty()) { + return null; + } + CommonGbChannel commonGbChannel = new CommonGbChannel(); + commonGbChannel.setCommonGbDeviceID(deviceChannel.getChannelId()); + for (String key : syncKeys) { + switch (key) { + case "commonGbName": + commonGbChannel.setCommonGbName(deviceChannel.getName()); + break; + case "commonGbManufacturer": + commonGbChannel.setCommonGbManufacturer(deviceChannel.getManufacture()); + break; + case "commonGbModel": + commonGbChannel.setCommonGbModel(deviceChannel.getModel()); + break; + case "commonGbOwner": + commonGbChannel.setCommonGbOwner(deviceChannel.getOwner()); + break; + case "commonGbCivilCode": + commonGbChannel.setCommonGbCivilCode(deviceChannel.getCivilCode()); + break; + case "commonGbBlock": + commonGbChannel.setCommonGbBlock(deviceChannel.getBlock()); + break; + case "commonGbAddress": + commonGbChannel.setCommonGbAddress(deviceChannel.getAddress()); + break; + case "commonGbParental": + commonGbChannel.setCommonGbParental(deviceChannel.getParental()); + break; + case "commonGbParentID": + commonGbChannel.setCommonGbParentID(deviceChannel.getParentId()); + break; + case "commonGbSafetyWay": + commonGbChannel.setCommonGbSafetyWay(deviceChannel.getSafetyWay()); + break; + case "commonGbRegisterWay": + commonGbChannel.setCommonGbRegisterWay(deviceChannel.getRegisterWay()); + break; + case "commonGbCertNum": + commonGbChannel.setCommonGbCertNum(deviceChannel.getCertNum()); + break; + case "commonGbCertifiable": + commonGbChannel.setCommonGbCertifiable(deviceChannel.getCertifiable()); + break; + case "commonGbErrCode": + commonGbChannel.setCommonGbErrCode(deviceChannel.getErrCode()); + break; + case "commonGbEndTime": + commonGbChannel.setCommonGbEndTime(deviceChannel.getEndTime()); + break; + case "commonGbSecrecy": + if (NumberUtils.isParsable(deviceChannel.getSecrecy())) { + commonGbChannel.setCommonGbSecrecy(Integer.parseInt(deviceChannel.getSecrecy())); + } + break; + case "commonGbIPAddress": + commonGbChannel.setCommonGbIPAddress(deviceChannel.getIpAddress()); + break; + case "commonGbPort": + commonGbChannel.setCommonGbPort(deviceChannel.getPort()); + break; + case "commonGbPassword": + commonGbChannel.setCommonGbPassword(deviceChannel.getPassword()); + break; + case "commonGbStatus": + commonGbChannel.setCommonGbStatus(deviceChannel.isStatus()); + break; + case "commonGbLongitude": + commonGbChannel.setCommonGbLongitude(deviceChannel.getLongitude()); + break; + case "commonGbLatitude": + commonGbChannel.setCommonGbLatitude(deviceChannel.getLatitude()); + break; + case "commonGbPtzType": + commonGbChannel.setCommonGbPtzType(deviceChannel.getPTZType()); + break; + case "commonGbPositionType": + commonGbChannel.setCommonGbPositionType(deviceChannel.getCommonGbPositionType()); + break; + case "commonGbRoomType": + break; + case "commonGbUseType": + break; + case "commonGbSupplyLightType": + break; + case "commonGbDirectionType": + break; + case "commonGbResolution": + break; + case "commonGbBusinessGroupID": + commonGbChannel.setCommonGbBusinessGroupID(deviceChannel.getBusinessGroupId()); + break; + case "commonGbDownloadSpeed": + break; + case "commonGbSVCTimeSupportMode": + break; + + } + } + return commonGbChannel; } } 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 index e23e7124..bcd81da9 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java @@ -1,7 +1,7 @@ package com.genersoft.iot.vmp.storager.dao; import com.genersoft.iot.vmp.common.CommonGbChannel; -import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; import java.util.List; @@ -9,21 +9,275 @@ import java.util.List; @Mapper @Repository public interface CommonGbChannelMapper { + + @Select(value = "select * from wvp_common_gb_channel where common_gb_business_group_id = '#{commonBusinessGroupPath}'") List getChannels(String commonBusinessGroupPath); + @Update(value = "") int updateChanelForBusinessGroup(List channels); + + @Delete(value = "") int removeChannelsForBusinessGroup(List channels); - int updateBusinessGroupPath(String commonBusinessGroupPath); + @Update("update wvp_common_gb_channel set common_gb_business_group_id = #{newPath} where common_gb_business_group_id = #{oldPath}") + int updateBusinessGroupPath(String oldPath, String newPath); + @Select("select * from wvp_common_gb_channel where common_gb_device_id=#{channelId}") CommonGbChannel queryByDeviceID(String channelId); + @Insert(value = "") int add(CommonGbChannel channel); + @Delete("delete from wvp_common_gb_channel where common_gb_device_id = #{channelId}") int deleteByDeviceID(String channelId); + @Update(value = "") int update(CommonGbChannel channel); - boolean checkChannelInPlatform(String channelId, String platformServerId); + @Select("select count(1)\n" + + "from wvp_common_gb_channel gc " + + "right join wvp_common_platform_channel pc " + + "on gc.common_gb_device_id = pc.common_gb_channel_id" + + "where gc.common_gb_device_id=#{channelId} and pc.platform_id=#{platformServerId}") + int checkChannelInPlatform(String channelId, String platformServerId); + + @Insert(value = "") + int addAll(List commonGbChannelList); }