增加国标通道同步到资源管理

结构优化
648540858 2023-09-19 17:55:13 +08:00
parent 074dbd69a2
commit be527a4bd1
10 changed files with 147 additions and 95 deletions

View File

@ -1,2 +1,5 @@
alter table wvp_device_channel
change stream_id stream_id varying(255)
change stream_id stream_id varying(255)
alter table wvp_device_channel
add common_gb_channel_id int

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ public interface ICommonGbChannelService {
* @param gbDeviceId
* @param syncKeys
*/
boolean SyncChannelFromGb28181Device(String gbDeviceId, List<String> syncKeys);
boolean SyncChannelFromGb28181Device(String gbDeviceId, List<String> syncKeys, Boolean syncGroup, Boolean syncRegion);
List<CommonGbChannel> getChannelsInRegion(String civilCode);

View File

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

View File

@ -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<String> syncKeys) {
public boolean SyncChannelFromGb28181Device(String gbDeviceId, List<String> syncKeys, Boolean syncGroup, Boolean syncRegion) {
logger.info("同步通用通道]来自国标设备,国标编号: {}", gbDeviceId);
List<DeviceChannel> deviceChannels = deviceChannelMapper.queryAllChannels(gbDeviceId);
if (deviceChannels.isEmpty()) {
return false;
}
List<CommonGbChannel> commonGbChannelList = new ArrayList<>(deviceChannels.size());
List<DeviceChannel> 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<DeviceChannel> 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;

View File

@ -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 {
"<foreach collection='channels' item='item' separator=';'>" +
"UPDATE wvp_common_gb_channel SET " +
"updateTime= #{ item.updateTime} " +
" <if test='commonGbDeviceID != null' > ,common_gb_device_id= #{ item.commonGbDeviceID} </if>" +
" <if test='commonGbName != null' > ,common_gb_name= #{ item.commonGbName} </if>" +
" <if test='commonGbManufacturer != null' > ,common_gb_manufacturer= #{ item.commonGbManufacturer} </if>" +
" <if test='commonGbModel != null' > ,common_gb_model= #{ item.commonGbModel} </if>" +
" <if test='commonGbOwner != null' > ,common_gb_owner= #{ item.commonGbOwner} </if>" +
" <if test='commonGbCivilCode != null' > ,common_gb_civilCode= #{ item.commonGbCivilCode} </if>" +
" <if test='commonGbBlock != null' > ,common_gb_block= #{ item.commonGbBlock} </if>" +
" <if test='commonGbAddress != null' > ,common_gb_address= #{ item.commonGbAddress} </if>" +
" <if test='common_gb_parental != null' > ,common_gb_parental= #{ item.commonGbParental} </if>" +
" <if test='commonGbParentID != null' > ,common_gb_parent_id= #{ item.commonGbParentID} </if>" +
" <if test='commonGbSafetyWay != null' > ,common_gb_safety_way= #{ item.commonGbSafetyWay} </if>" +
" <if test='commonGbRegisterWay != null' > ,common_gb_register_way= #{ item.commonGbRegisterWay} </if>" +
" <if test='commonGbCertNum != null' > ,common_gb_cert_num= #{ item.commonGbCertNum} </if>" +
" <if test='commonGbCertifiable != null' > ,common_gb_certifiable= #{ item.commonGbCertifiable} </if>" +
" <if test='commonGbErrCode != null' > ,common_gb_err_code= #{ item.commonGbErrCode} </if>" +
" <if test='commonGbEndTime != null' > ,common_gb_end_time= #{ item.commonGbEndTime} </if>" +
" <if test='commonGbSecrecy != null' > ,common_gb_secrecy= #{ item.commonGbSecrecy} </if>" +
" <if test='commonGbIPAddress != null' > ,common_gb_ip_address= #{ item.commonGbIPAddress} </if>" +
" <if test='commonGbPort != null' > ,common_gb_port= #{ item.commonGbPort} </if>" +
" <if test='commonGbPassword != null' > ,common_gb_password= #{ item.commonGbPassword} </if>" +
" <if test='commonGbStatus != null' > ,common_gb_status= #{ item.commonGbStatus} </if>" +
" <if test='commonGbLongitude != null' > ,common_gb_longitude= #{ item.commonGbLongitude} </if>" +
" <if test='commonGbLatitude != null' > ,common_gb_latitude= #{ item.commonGbLatitude} </if>" +
" <if test='commonGbPtzType != null' > ,common_gb_ptz_type= #{ item.commonGbPtzType} </if>" +
" <if test='commonGbPositionType != null' > ,common_gb_position_type= #{ item.commonGbPositionType} </if>" +
" <if test='commonGbRoomType != null' > ,common_gb_room_type= #{ item.commonGbRoomType} </if>" +
" <if test='commonGbUseType != null' > ,common_gb_use_type= #{ item.commonGbUseType} </if>" +
" <if test='commonGbEndTime != null' > ,common_gb_supply_light_type= #{ item.commonGbSupplyLightType} </if>" +
" <if test='commonGbSupplyLightType != null' > ,common_gb_direction_type= #{ item.commonGbDirectionType} </if>" +
" <if test='commonGbResolution != null' > ,common_gb_resolution= #{ item.commonGbResolution} </if>" +
" <if test='commonGbBusinessGroupID != null' > ,common_gb_business_group_id= #{ item.commonGbBusinessGroupID} </if>" +
" <if test='commonGbDownloadSpeed != null' > ,common_gb_download_speed= #{ item.commonGbDownloadSpeed} </if>" +
" <if test='commonGbSVCTimeSupportMode != null' > ,common_gb_svc_time_support_mode= #{ item.commonGbSVCTimeSupportMode} </if>" +
" <if test='type != null' > ,type= #{ item.type} </if>" +
" <if test='item.commonGbDeviceID != null' > ,common_gb_device_id= #{ item.commonGbDeviceID} </if>" +
" <if test='item.commonGbName != null' > ,common_gb_name= #{ item.commonGbName} </if>" +
" <if test='item.commonGbManufacturer != null' > ,common_gb_manufacturer= #{ item.commonGbManufacturer} </if>" +
" <if test='item.commonGbModel != null' > ,common_gb_model= #{ item.commonGbModel} </if>" +
" <if test='item.commonGbOwner != null' > ,common_gb_owner= #{ item.commonGbOwner} </if>" +
" <if test='item.commonGbCivilCode != null' > ,common_gb_civilCode= #{ item.commonGbCivilCode} </if>" +
" <if test='item.commonGbBlock != null' > ,common_gb_block= #{ item.commonGbBlock} </if>" +
" <if test='item.commonGbAddress != null' > ,common_gb_address= #{ item.commonGbAddress} </if>" +
" <if test='item.common_gb_parental != null' > ,common_gb_parental= #{ item.commonGbParental} </if>" +
" <if test='item.commonGbParentID != null' > ,common_gb_parent_id= #{ item.commonGbParentID} </if>" +
" <if test='item.commonGbSafetyWay != null' > ,common_gb_safety_way= #{ item.commonGbSafetyWay} </if>" +
" <if test='item.commonGbRegisterWay != null' > ,common_gb_register_way= #{ item.commonGbRegisterWay} </if>" +
" <if test='item.commonGbCertNum != null' > ,common_gb_cert_num= #{ item.commonGbCertNum} </if>" +
" <if test='item.commonGbCertifiable != null' > ,common_gb_certifiable= #{ item.commonGbCertifiable} </if>" +
" <if test='item.commonGbErrCode != null' > ,common_gb_err_code= #{ item.commonGbErrCode} </if>" +
" <if test='item.commonGbEndTime != null' > ,common_gb_end_time= #{ item.commonGbEndTime} </if>" +
" <if test='item.commonGbSecrecy != null' > ,common_gb_secrecy= #{ item.commonGbSecrecy} </if>" +
" <if test='item.commonGbIPAddress != null' > ,common_gb_ip_address= #{ item.commonGbIPAddress} </if>" +
" <if test='item.commonGbPort != null' > ,common_gb_port= #{ item.commonGbPort} </if>" +
" <if test='item.commonGbPassword != null' > ,common_gb_password= #{ item.commonGbPassword} </if>" +
" <if test='item.commonGbStatus != null' > ,common_gb_status= #{ item.commonGbStatus} </if>" +
" <if test='item.commonGbLongitude != null' > ,common_gb_longitude= #{ item.commonGbLongitude} </if>" +
" <if test='item.commonGbLatitude != null' > ,common_gb_latitude= #{ item.commonGbLatitude} </if>" +
" <if test='item.commonGbPtzType != null' > ,common_gb_ptz_type= #{ item.commonGbPtzType} </if>" +
" <if test='item.commonGbPositionType != null' > ,common_gb_position_type= #{ item.commonGbPositionType} </if>" +
" <if test='item.commonGbRoomType != null' > ,common_gb_room_type= #{ item.commonGbRoomType} </if>" +
" <if test='item.commonGbUseType != null' > ,common_gb_use_type= #{ item.commonGbUseType} </if>" +
" <if test='item.commonGbEndTime != null' > ,common_gb_supply_light_type= #{ item.commonGbSupplyLightType} </if>" +
" <if test='item.commonGbSupplyLightType != null' > ,common_gb_direction_type= #{ item.commonGbDirectionType} </if>" +
" <if test='item.commonGbResolution != null' > ,common_gb_resolution= #{ item.commonGbResolution} </if>" +
" <if test='item.commonGbBusinessGroupID != null' > ,common_gb_business_group_id= #{ item.commonGbBusinessGroupID} </if>" +
" <if test='item.commonGbDownloadSpeed != null' > ,common_gb_download_speed= #{ item.commonGbDownloadSpeed} </if>" +
" <if test='item.commonGbSVCTimeSupportMode != null' > ,common_gb_svc_time_support_mode= #{ item.commonGbSVCTimeSupportMode} </if>" +
" <if test='item.type != null' > ,type= #{ item.type} </if>" +
" WHERE common_gb_id=#{item.commonGbId}" +
"</foreach>" +
"</script>")
@ -239,45 +240,52 @@ public interface CommonGbChannelMapper {
"updateTime, " +
"createTime " +
") values " +
"<foreach collection='addChannels' index='index' item='item' separator=','> " +
"( #{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}" +
"<foreach collection='commonGbChannelList' index='index' item='item' separator=','> " +
"( " +
"#{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}" +
")" +
"</foreach>" +
"</script>")
int addAll(List<CommonGbChannel> commonGbChannelList);
@Delete("<script> "+
"DELETE from wvp_common_gb_channel WHERE common_gb_id in" +
"<foreach collection='clearChannels' item='item' open='(' separator=',' close=')' > #{item.commonGbChannelId}</foreach>" +
"</script>")
int deleteByDeviceIDs(List<DeviceChannel> clearChannels);
}

View File

@ -466,4 +466,11 @@ public interface DeviceChannelMapper {
" </script>"})
List<DeviceChannel> 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);
}

View File

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