From be527a4bd1cc0be868e5c07fd7dfd1768acd4e53 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 19 Sep 2023 17:55:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9B=BD=E6=A0=87=E9=80=9A?= =?UTF-8?q?=E9=81=93=E5=90=8C=E6=AD=A5=E5=88=B0=E8=B5=84=E6=BA=90=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/2.6.9更新.sql | 5 +- sql/初始化.sql | 1 + .../iot/vmp/common/CommonGbChannel.java | 8 +- .../iot/vmp/gb28181/bean/DeviceChannel.java | 6 +- .../vmp/service/ICommonGbChannelService.java | 2 +- .../vmp/service/bean/CommonGbChannelType.java | 7 + .../impl/CommonGbChannelServiceImpl.java | 41 ++++- .../storager/dao/CommonGbChannelMapper.java | 150 +++++++++--------- .../vmp/storager/dao/DeviceChannelMapper.java | 7 + .../channel/CommonChannelController.java | 15 +- 10 files changed, 147 insertions(+), 95 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/service/bean/CommonGbChannelType.java diff --git a/sql/2.6.9更新.sql b/sql/2.6.9更新.sql index 2e047948..89899bda 100644 --- a/sql/2.6.9更新.sql +++ b/sql/2.6.9更新.sql @@ -1,2 +1,5 @@ alter table wvp_device_channel - change stream_id stream_id varying(255) \ No newline at end of file + change stream_id stream_id varying(255) + +alter table wvp_device_channel + add common_gb_channel_id int diff --git a/sql/初始化.sql b/sql/初始化.sql index 93eef4ed..23797af6 100644 --- a/sql/初始化.sql +++ b/sql/初始化.sql @@ -92,6 +92,7 @@ create table wvp_device_channel ( latitude_wgs84 double precision, business_group_id character varying(50), gps_time character varying(50), + common_gb_channel_id integer, constraint uk_wvp_device_channel_unique_device_channel unique (device_id, channel_id) ); 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 a2462269..8d607e82 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/CommonGbChannel.java +++ b/src/main/java/com/genersoft/iot/vmp/common/CommonGbChannel.java @@ -470,11 +470,11 @@ public class CommonGbChannel { this.commonGbPassword = commonGbPassword; } - public boolean getCommonGbStatus() { + public Boolean getCommonGbStatus() { return commonGbStatus; } - public void setCommonGbStatus(boolean commonGbStatus) { + public void setCommonGbStatus(Boolean commonGbStatus) { this.commonGbStatus = commonGbStatus; } @@ -582,10 +582,6 @@ public class CommonGbChannel { this.type = type; } - public void setCommonGbStatus(Boolean commonGbStatus) { - this.commonGbStatus = commonGbStatus; - } - public String getUpdateTime() { return updateTime; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java index abbdc8b4..5bc9e334 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java @@ -257,7 +257,7 @@ public class DeviceChannel { * 国标通用信息ID */ @Schema(description = "国标通用信息ID") - private int CommonGbChannelId; + private int commonGbChannelId; public int getId() { return id; @@ -597,10 +597,10 @@ public class DeviceChannel { } public int getCommonGbChannelId() { - return CommonGbChannelId; + return commonGbChannelId; } public void setCommonGbChannelId(int commonGbChannelId) { - CommonGbChannelId = commonGbChannelId; + commonGbChannelId = commonGbChannelId; } } 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 f10cb07f..d4195462 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java @@ -25,7 +25,7 @@ public interface ICommonGbChannelService { * @param gbDeviceId 国标设备编号 * @param syncKeys 要同步的字段 */ - boolean SyncChannelFromGb28181Device(String gbDeviceId, List syncKeys); + boolean SyncChannelFromGb28181Device(String gbDeviceId, List syncKeys, Boolean syncGroup, Boolean syncRegion); List getChannelsInRegion(String civilCode); diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/CommonGbChannelType.java b/src/main/java/com/genersoft/iot/vmp/service/bean/CommonGbChannelType.java new file mode 100644 index 00000000..e71be517 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/bean/CommonGbChannelType.java @@ -0,0 +1,7 @@ +package com.genersoft.iot.vmp.service.bean; + +public class CommonGbChannelType { + public final static String GB28181 = "28181"; + public final static String PUSH = "push"; + public final static String PROXY = "proxy"; +} 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 dc83d809..32b1f361 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 @@ -3,8 +3,10 @@ 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.service.bean.CommonGbChannelType; import com.genersoft.iot.vmp.storager.dao.CommonGbChannelMapper; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; +import com.genersoft.iot.vmp.utils.DateUtil; import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,23 +75,45 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { } @Override - public boolean SyncChannelFromGb28181Device(String gbDeviceId, List syncKeys) { + public boolean SyncChannelFromGb28181Device(String gbDeviceId, List syncKeys, Boolean syncGroup, Boolean syncRegion) { logger.info("同步通用通道]来自国标设备,国标编号: {}", gbDeviceId); List deviceChannels = deviceChannelMapper.queryAllChannels(gbDeviceId); if (deviceChannels.isEmpty()) { return false; } List commonGbChannelList = new ArrayList<>(deviceChannels.size()); + List clearChannels = new ArrayList<>(); for (DeviceChannel deviceChannel : deviceChannels) { + if (deviceChannel.getCommonGbChannelId() > 0) { + clearChannels.add(deviceChannel); + } CommonGbChannel commonGbChannel = getCommonChannelFromDeviceChannel(deviceChannel, syncKeys); commonGbChannelList.add(commonGbChannel); } - int limit = 300; + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); + int limit = 50; + if (!clearChannels.isEmpty()) { + if (clearChannels.size() <= limit) { + commonGbChannelMapper.deleteByDeviceIDs(clearChannels); + } else { + for (int i = 0; i < clearChannels.size(); i += limit) { + int toIndex = i + limit; + if (i + limit > clearChannels.size()) { + toIndex = clearChannels.size(); + } + List clearChannelsSun = clearChannels.subList(i, toIndex); + int currentResult = commonGbChannelMapper.deleteByDeviceIDs(clearChannelsSun); + if (currentResult <= 0) { + dataSourceTransactionManager.rollback(transactionStatus); + return false; + } + } + } + } 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()) { @@ -102,9 +126,10 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { return false; } } - dataSourceTransactionManager.commit(transactionStatus); result = true; } + deviceChannelMapper.updateCommonChannelId(gbDeviceId); + dataSourceTransactionManager.commit(transactionStatus); return result; } @@ -114,6 +139,10 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { } CommonGbChannel commonGbChannel = new CommonGbChannel(); commonGbChannel.setCommonGbDeviceID(deviceChannel.getChannelId()); + commonGbChannel.setCommonGbStatus(deviceChannel.isStatus()); + commonGbChannel.setType(CommonGbChannelType.GB28181); + commonGbChannel.setCreateTime(DateUtil.getNow()); + commonGbChannel.setUpdateTime(DateUtil.getNow()); if (syncKeys == null || syncKeys.isEmpty()) { commonGbChannel.setCommonGbName(deviceChannel.getName()); commonGbChannel.setCommonGbManufacturer(deviceChannel.getManufacture()); @@ -136,7 +165,6 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { commonGbChannel.setCommonGbIPAddress(deviceChannel.getIpAddress()); commonGbChannel.setCommonGbPort(deviceChannel.getPort()); commonGbChannel.setCommonGbPassword(deviceChannel.getPassword()); - commonGbChannel.setCommonGbStatus(deviceChannel.isStatus()); commonGbChannel.setCommonGbLongitude(deviceChannel.getLongitude()); commonGbChannel.setCommonGbLatitude(deviceChannel.getLatitude()); commonGbChannel.setCommonGbPtzType(deviceChannel.getPTZType()); @@ -204,9 +232,6 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { case "commonGbPassword": commonGbChannel.setCommonGbPassword(deviceChannel.getPassword()); break; - case "commonGbStatus": - commonGbChannel.setCommonGbStatus(deviceChannel.isStatus()); - break; case "commonGbLongitude": commonGbChannel.setCommonGbLongitude(deviceChannel.getLongitude()); break; 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 bcd81da9..44ac660a 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,6 +1,7 @@ package com.genersoft.iot.vmp.storager.dao; import com.genersoft.iot.vmp.common.CommonGbChannel; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; @@ -17,40 +18,40 @@ public interface CommonGbChannelMapper { "" + "UPDATE wvp_common_gb_channel SET " + "updateTime= #{ item.updateTime} " + - " ,common_gb_device_id= #{ item.commonGbDeviceID} " + - " ,common_gb_name= #{ item.commonGbName} " + - " ,common_gb_manufacturer= #{ item.commonGbManufacturer} " + - " ,common_gb_model= #{ item.commonGbModel} " + - " ,common_gb_owner= #{ item.commonGbOwner} " + - " ,common_gb_civilCode= #{ item.commonGbCivilCode} " + - " ,common_gb_block= #{ item.commonGbBlock} " + - " ,common_gb_address= #{ item.commonGbAddress} " + - " ,common_gb_parental= #{ item.commonGbParental} " + - " ,common_gb_parent_id= #{ item.commonGbParentID} " + - " ,common_gb_safety_way= #{ item.commonGbSafetyWay} " + - " ,common_gb_register_way= #{ item.commonGbRegisterWay} " + - " ,common_gb_cert_num= #{ item.commonGbCertNum} " + - " ,common_gb_certifiable= #{ item.commonGbCertifiable} " + - " ,common_gb_err_code= #{ item.commonGbErrCode} " + - " ,common_gb_end_time= #{ item.commonGbEndTime} " + - " ,common_gb_secrecy= #{ item.commonGbSecrecy} " + - " ,common_gb_ip_address= #{ item.commonGbIPAddress} " + - " ,common_gb_port= #{ item.commonGbPort} " + - " ,common_gb_password= #{ item.commonGbPassword} " + - " ,common_gb_status= #{ item.commonGbStatus} " + - " ,common_gb_longitude= #{ item.commonGbLongitude} " + - " ,common_gb_latitude= #{ item.commonGbLatitude} " + - " ,common_gb_ptz_type= #{ item.commonGbPtzType} " + - " ,common_gb_position_type= #{ item.commonGbPositionType} " + - " ,common_gb_room_type= #{ item.commonGbRoomType} " + - " ,common_gb_use_type= #{ item.commonGbUseType} " + - " ,common_gb_supply_light_type= #{ item.commonGbSupplyLightType} " + - " ,common_gb_direction_type= #{ item.commonGbDirectionType} " + - " ,common_gb_resolution= #{ item.commonGbResolution} " + - " ,common_gb_business_group_id= #{ item.commonGbBusinessGroupID} " + - " ,common_gb_download_speed= #{ item.commonGbDownloadSpeed} " + - " ,common_gb_svc_time_support_mode= #{ item.commonGbSVCTimeSupportMode} " + - " ,type= #{ item.type} " + + " ,common_gb_device_id= #{ item.commonGbDeviceID} " + + " ,common_gb_name= #{ item.commonGbName} " + + " ,common_gb_manufacturer= #{ item.commonGbManufacturer} " + + " ,common_gb_model= #{ item.commonGbModel} " + + " ,common_gb_owner= #{ item.commonGbOwner} " + + " ,common_gb_civilCode= #{ item.commonGbCivilCode} " + + " ,common_gb_block= #{ item.commonGbBlock} " + + " ,common_gb_address= #{ item.commonGbAddress} " + + " ,common_gb_parental= #{ item.commonGbParental} " + + " ,common_gb_parent_id= #{ item.commonGbParentID} " + + " ,common_gb_safety_way= #{ item.commonGbSafetyWay} " + + " ,common_gb_register_way= #{ item.commonGbRegisterWay} " + + " ,common_gb_cert_num= #{ item.commonGbCertNum} " + + " ,common_gb_certifiable= #{ item.commonGbCertifiable} " + + " ,common_gb_err_code= #{ item.commonGbErrCode} " + + " ,common_gb_end_time= #{ item.commonGbEndTime} " + + " ,common_gb_secrecy= #{ item.commonGbSecrecy} " + + " ,common_gb_ip_address= #{ item.commonGbIPAddress} " + + " ,common_gb_port= #{ item.commonGbPort} " + + " ,common_gb_password= #{ item.commonGbPassword} " + + " ,common_gb_status= #{ item.commonGbStatus} " + + " ,common_gb_longitude= #{ item.commonGbLongitude} " + + " ,common_gb_latitude= #{ item.commonGbLatitude} " + + " ,common_gb_ptz_type= #{ item.commonGbPtzType} " + + " ,common_gb_position_type= #{ item.commonGbPositionType} " + + " ,common_gb_room_type= #{ item.commonGbRoomType} " + + " ,common_gb_use_type= #{ item.commonGbUseType} " + + " ,common_gb_supply_light_type= #{ item.commonGbSupplyLightType} " + + " ,common_gb_direction_type= #{ item.commonGbDirectionType} " + + " ,common_gb_resolution= #{ item.commonGbResolution} " + + " ,common_gb_business_group_id= #{ item.commonGbBusinessGroupID} " + + " ,common_gb_download_speed= #{ item.commonGbDownloadSpeed} " + + " ,common_gb_svc_time_support_mode= #{ item.commonGbSVCTimeSupportMode} " + + " ,type= #{ item.type} " + " WHERE common_gb_id=#{item.commonGbId}" + "" + "") @@ -239,45 +240,52 @@ public interface CommonGbChannelMapper { "updateTime, " + "createTime " + ") values " + - " " + - "( #{commonGbDeviceID}, " + - "#{commonGbName}, " + - "#{commonGbManufacturer}, " + - "#{commonGbModel}, " + - "#{commonGbOwner}, " + - "#{commonGbCivilCode}, " + - "#{commonGbBlock}," + - "#{commonGbAddress}," + - "#{commonGbParental}," + - "#{commonGbParentID}," + - "#{commonGbSafetyWay}," + - "#{commonGbRegisterWay}," + - "#{commonGbCertNum}," + - "#{commonGbCertifiable}," + - "#{commonGbErrCode}," + - "#{commonGbEndTime}," + - "#{commonGbSecrecy}," + - "#{commonGbIPAddress}," + - "#{commonGbPort}," + - "#{commonGbPassword}," + - "#{commonGbStatus}," + - "#{commonGbLongitude}," + - "#{commonGbLatitude}," + - "#{commonGbPtzType}," + - "#{commonGbPositionType}," + - "#{commonGbRoomType}," + - "#{commonGbUseType}," + - "#{commonGbSupplyLightType}," + - "#{commonGbDirectionType}," + - "#{commonGbResolution}," + - "#{commonGbBusinessGroupID}," + - "#{commonGbDownloadSpeed}," + - "#{commonGbSVCTimeSupportMode}," + - "#{type}," + - "#{updateTime}," + - "#{createTime}" + + " " + + "( " + + "#{item.commonGbDeviceID}, " + + "#{item.commonGbName}, " + + "#{item.commonGbManufacturer}, " + + "#{item.commonGbModel}, " + + "#{item.commonGbOwner}, " + + "#{item.commonGbCivilCode}, " + + "#{item.commonGbBlock}," + + "#{item.commonGbAddress}," + + "#{item.commonGbParental}," + + "#{item.commonGbParentID}," + + "#{item.commonGbSafetyWay}," + + "#{item.commonGbRegisterWay}," + + "#{item.commonGbCertNum}," + + "#{item.commonGbCertifiable}," + + "#{item.commonGbErrCode}," + + "#{item.commonGbEndTime}," + + "#{item.commonGbSecrecy}," + + "#{item.commonGbIPAddress}," + + "#{item.commonGbPort}," + + "#{item.commonGbPassword}," + + "#{item.commonGbStatus}," + + "#{item.commonGbLongitude}," + + "#{item.commonGbLatitude}," + + "#{item.commonGbPtzType}," + + "#{item.commonGbPositionType}," + + "#{item.commonGbRoomType}," + + "#{item.commonGbUseType}," + + "#{item.commonGbSupplyLightType}," + + "#{item.commonGbDirectionType}," + + "#{item.commonGbResolution}," + + "#{item.commonGbBusinessGroupID}," + + "#{item.commonGbDownloadSpeed}," + + "#{item.commonGbSVCTimeSupportMode}," + + "#{item.type}," + + "#{item.updateTime}," + + "#{item.createTime}" + ")" + "" + "") int addAll(List commonGbChannelList); + + @Delete("") + int deleteByDeviceIDs(List clearChannels); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java index 1bdae76b..869031a3 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java @@ -466,4 +466,11 @@ public interface DeviceChannelMapper { " "}) List getSubChannelsByDeviceId(@Param("deviceId") String deviceId, @Param("parentId") String parentId, @Param("onlyCatalog") boolean onlyCatalog); + @Update(" update wvp_device_channel wdc " + + " set " + + " common_gb_channel_id=" + + " (select wcgc.common_gb_id from wvp_common_gb_channel wcgc where wdc.channel_id = wcgc.common_gb_device_id) " + + " where wdc.device_id = #{deviceId}") + int updateCommonChannelId(@Param("deviceId") String deviceId); + } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java index daf203db..e6ed68d6 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java @@ -9,10 +9,9 @@ import io.swagger.v3.oas.annotations.tags.Tag; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import java.util.Arrays; import java.util.List; @Tag(name = "通用国标通道") @@ -61,7 +60,13 @@ public class CommonChannelController { @Operation(summary = "从下级设备中同步通道") @Parameter(name = "deviceId", description = "设备编号") @Parameter(name = "syncKeys", description = "选择性同步的字段") - public boolean syncFromDevice(String deviceId, String[] syncKeys) { - return commonGbChannelService.SyncChannelFromGb28181Device(deviceId, Lists.newArrayList(syncKeys)); + public boolean syncFromDevice(String deviceId, String[] syncKeys, + @RequestParam(required = false) Boolean syncGroup, + @RequestParam(required = false) Boolean syncRegion) { + System.out.println("deviceId===" + deviceId); + System.out.println("syncKeys===" + Arrays.toString(syncKeys)); + System.out.println("syncGroup===" + syncGroup); + System.out.println("syncRegion===" + syncRegion); + return commonGbChannelService.SyncChannelFromGb28181Device(deviceId, Lists.newArrayList(syncKeys), syncGroup, syncRegion); } }