diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java index 75a301c0..3cbab872 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java @@ -67,11 +67,12 @@ public interface DeviceChannelMapper { ", download_speed=#{downloadSpeed}" + ", svc_space_support_mod=#{svcSpaceSupportMod}" + ", svc_time_support_mode=#{svcTimeSupportMode}" + - ", sub_count,stream_id=#{subCount,streamId}" + + ", sub_count=#{subCount}" + + ", stream_id=#{streamId}" + ", has_audio=#{hasAudio}" + ", gps_time=#{gpsTime}" + ", stream_identification=#{streamIdentification}" + - "WHERE id=#{id}"+ + "WHERE id=#{id}" + " "}) int update(DeviceChannel channel); @@ -111,7 +112,7 @@ public interface DeviceChannelMapper { ", gb_download_speed = #{gbDownloadSpeed}" + ", gb_svc_space_support_mod = #{gbSvcSpaceSupportMod}" + ", gb_svc_time_support_mode = #{gbSvcTimeSupportMode}" + - "WHERE id = #{id}"+ + "WHERE id = #{id}" + " "}) int updateCustomInfo(DeviceChannel channel); @@ -231,7 +232,6 @@ public interface DeviceChannelMapper { List queryChannelsByDeviceDbId(@Param("deviceDbId") int deviceDbId); - @Select(value = {" "}) List queryChannelListInAll(@Param("query") String query, @Param("online") Boolean online, @Param("hasSubChannel") Boolean hasSubChannel, @Param("platformId") String platformId, @Param("catalogId") String catalogId); - @Select(value = {" "}) - List queryChannelByPlatformId(String platformId); + @Select("SELECT " + + " id,\n" + + " device_db_id,\n" + + " create_time,\n" + + " update_time,\n" + + " sub_count,\n" + + " stream_id,\n" + + " has_audio,\n" + + " gps_time,\n" + + " stream_identification,\n" + + " coalesce(gb_device_id, device_id) as device_id,\n" + + " coalesce(gb_name, name) as name,\n" + + " coalesce(gb_manufacturer, manufacturer) as manufacturer,\n" + + " coalesce(gb_model, model) as model,\n" + + " coalesce(gb_owner, owner) as owner,\n" + + " coalesce(gb_civil_code, civil_code) as civil_code,\n" + + " coalesce(gb_block, block) as block,\n" + + " coalesce(gb_address, address) as address,\n" + + " coalesce(gb_parental, parental) as parental,\n" + + " coalesce(gb_parent_id, parent_id) as parent_id,\n" + + " coalesce(gb_safety_way, safety_way) as safety_way,\n" + + " coalesce(gb_register_way, register_way) as register_way,\n" + + " coalesce(gb_cert_num, cert_num) as cert_num,\n" + + " coalesce(gb_certifiable, certifiable) as certifiable,\n" + + " coalesce(gb_err_code, err_code) as err_code,\n" + + " coalesce(gb_end_time, end_time) as end_time,\n" + + " coalesce(gb_secrecy, secrecy) as secrecy,\n" + + " coalesce(gb_ip_address, ip_address) as ip_address,\n" + + " coalesce(gb_port, port) as port,\n" + + " coalesce(gb_password, password) as password,\n" + + " coalesce(gb_status, status) as status,\n" + + " coalesce(gb_longitude, longitude) as longitude,\n" + + " coalesce(gb_latitude, latitude) as latitude,\n" + + " coalesce(gb_ptz_type, ptz_type) as ptz_type,\n" + + " coalesce(gb_position_type, position_type) as position_type,\n" + + " coalesce(gb_room_type, room_type) as room_type,\n" + + " coalesce(gb_use_type, use_type) as use_type,\n" + + " coalesce(gb_supply_light_type, supply_light_type) as supply_light_type,\n" + + " coalesce(gb_direction_type, direction_type) as direction_type,\n" + + " coalesce(gb_resolution, resolution) as resolution,\n" + + " coalesce(gb_business_group_id, business_group_id) as business_group_id,\n" + + " coalesce(gb_download_speed, download_speed) as download_speed,\n" + + " coalesce(gb_svc_space_support_mod, svc_space_support_mod) as svc_space_support_mod,\n" + + " coalesce(gb_svc_time_support_mode svc_time_support_mode) as svc_time_support_mode\n" + + " FROM wvp_device_channel WHERE device_id=#{channelId}") + List queryChannelByChannelId(@Param("channelId") String channelId); - - @Select("SELECT * FROM wvp_device_channel WHERE channel_id=#{channelId}") - List queryChannelByChannelId( String channelId); - - @Update(value = {"UPDATE wvp_device_channel SET status=false WHERE device_id=#{deviceId} AND channel_id=#{channelId}"}) - void offline(@Param("deviceId") String deviceId, @Param("channelId") String channelId); - - @Update(value = {"UPDATE wvp_device_channel SET status=false WHERE device_id=#{deviceId}"}) - void offlineByDeviceId(String deviceId); + @Update(value = {"UPDATE wvp_device_channel SET status=0 WHERE id=#{id}"}) + void offline(@Param("id") int id); @Insert("") int batchAdd(@Param("addChannels") List addChannels); - @Insert("") - int batchAddOrUpdate(List addChannels); - - @Update(value = {"UPDATE wvp_device_channel SET status=true WHERE device_id=#{deviceId} AND channel_id=#{channelId}"}) - void online(@Param("deviceId") String deviceId, @Param("channelId") String channelId); + @Update(value = {"UPDATE wvp_device_channel SET status=0 WHERE id=#{id}"}) + void online(@Param("id") int id); @Update({""}) int batchUpdate(List updateChannels); - - @Select("SELECT * FROM wvp_device_channel WHERE device_id=#{deviceId} AND status=true") - List queryOnlineChannelsByDeviceId(String deviceId); - - @Delete(value = {" "}) - int cleanChannelsNotInList(@Param("deviceId") String deviceId, @Param("channels") List channels); - @Update(" update wvp_device_channel" + " set sub_count = (select *" + " from (select count(0)" + " from wvp_device_channel" + - " where device_id = #{deviceId} and parent_id = #{channelId}) as temp)" + - " where device_id = #{deviceId} " + - " and channel_id = #{channelId}") - int updateChannelSubCount(@Param("deviceId") String deviceId, @Param("channelId") String channelId); + " where device_db_id = #{deviceDbId} and parent_id = #{channelId}) as temp)" + + " where device_db_id = #{deviceDbId} and device_id = #{channelId}") + int updateChannelSubCount(@Param("deviceDbId") int deviceDbId, @Param("channelId") String channelId); @Update(value = {" "}) int updatePosition(DeviceChannel deviceChannel); - @Select("SELECT * FROM wvp_device_channel WHERE length(trim(stream_id)) > 0") - List getAllChannelInPlay(); - - @Select("select * from wvp_device_channel where longitude*latitude > 0 and device_id = #{deviceId}") - List getAllChannelWithCoordinate(String deviceId); - - - @Select(value = {" "}) - List getChannelsWithCivilCodeAndLength(@Param("deviceId") String deviceId, @Param("parentId") String parentId, @Param("length") Integer length); - - @Select(value = {" "}) - List getChannelsByCivilCode(@Param("deviceId") String deviceId, @Param("parentId") String parentId); - - @Select("select min(length(channel_id)) as minLength " + - "from wvp_device_channel " + - "where device_id=#{deviceId}") - Integer getChannelMinLength(String deviceId); - - @Select("select * from wvp_device_channel where device_id=#{deviceId} and civil_code not in " + - "(select civil_code from wvp_device_channel where device_id=#{deviceId} group by civil_code)") - List getChannelWithoutCivilCode(String deviceId); - - @Select("select * from wvp_device_channel where device_id=#{deviceId} and SUBSTRING(channel_id, 11, 3)=#{typeCode}") - List getBusinessGroups(@Param("deviceId") String deviceId, @Param("typeCode") String typeCode); - - @Select("select dc.id, dc.channel_id, dc.device_id, COALESCE(dc.custom_name, dc.name) AS name, dc.manufacture,dc.model,dc.owner, pc.civil_code,dc.block, " + - " dc.address, '0' as parental,'0' as channel_type, pc.id as parent_id, dc.safety_way, dc.register_way,dc.cert_num, dc.certifiable, " + - " dc.err_code,dc.end_time, dc.secrecy, dc.ip_address, dc.port, COALESCE(dc.custom_ptz_type, dc.ptz_type) AS ptz_type, dc.password, dc.status, " + - " COALESCE(dc.custom_longitude, dc.longitude) AS longitude, COALESCE(dc.custom_latitude, dc.latitude) AS latitude, pc.business_group_id " + - " from wvp_device_channel dc" + - " LEFT JOIN wvp_platform_gb_channel pgc on dc.id = pgc.device_channel_id" + - " LEFT JOIN wvp_platform_catalog pc on pgc.catalog_id = pc.id and pgc.platform_id = pc.platform_id" + - " where pgc.platform_id=#{serverGBId}") - List queryChannelWithCatalog(String serverGBId); - - @Select("select * from wvp_device_channel where device_id = #{deviceId}") - List queryAllChannels(String deviceId); - - - @Select("select channelId" + - ", device_id" + - ", latitude" + - ", longitude"+ - ",latitude_wgs84"+ - ",longitude_wgs84"+ - ",latitude_gcj02"+ - ",longitude_gcj02"+ - "from wvp_device_channel where device_id = #{deviceId} " + - "and latitude != 0 " + - "and longitude != 0 " + - "and(latitude_gcj02=0 or latitude_wgs84=0 or longitude_wgs84= 0 or longitude_gcj02 = 0)") - List getChannelsWithoutTransform(String deviceId); + @Select("select " + + " id,\n" + + " device_db_id,\n" + + " create_time,\n" + + " update_time,\n" + + " sub_count,\n" + + " stream_id,\n" + + " has_audio,\n" + + " gps_time,\n" + + " stream_identification,\n" + + " coalesce(gb_device_id, device_id) as device_id,\n" + + " coalesce(gb_name, name) as name,\n" + + " coalesce(gb_manufacturer, manufacturer) as manufacturer,\n" + + " coalesce(gb_model, model) as model,\n" + + " coalesce(gb_owner, owner) as owner,\n" + + " coalesce(gb_civil_code, civil_code) as civil_code,\n" + + " coalesce(gb_block, block) as block,\n" + + " coalesce(gb_address, address) as address,\n" + + " coalesce(gb_parental, parental) as parental,\n" + + " coalesce(gb_parent_id, parent_id) as parent_id,\n" + + " coalesce(gb_safety_way, safety_way) as safety_way,\n" + + " coalesce(gb_register_way, register_way) as register_way,\n" + + " coalesce(gb_cert_num, cert_num) as cert_num,\n" + + " coalesce(gb_certifiable, certifiable) as certifiable,\n" + + " coalesce(gb_err_code, err_code) as err_code,\n" + + " coalesce(gb_end_time, end_time) as end_time,\n" + + " coalesce(gb_secrecy, secrecy) as secrecy,\n" + + " coalesce(gb_ip_address, ip_address) as ip_address,\n" + + " coalesce(gb_port, port) as port,\n" + + " coalesce(gb_password, password) as password,\n" + + " coalesce(gb_status, status) as status,\n" + + " coalesce(gb_longitude, longitude) as longitude,\n" + + " coalesce(gb_latitude, latitude) as latitude,\n" + + " coalesce(gb_ptz_type, ptz_type) as ptz_type,\n" + + " coalesce(gb_position_type, position_type) as position_type,\n" + + " coalesce(gb_room_type, room_type) as room_type,\n" + + " coalesce(gb_use_type, use_type) as use_type,\n" + + " coalesce(gb_supply_light_type, supply_light_type) as supply_light_type,\n" + + " coalesce(gb_direction_type, direction_type) as direction_type,\n" + + " coalesce(gb_resolution, resolution) as resolution,\n" + + " coalesce(gb_business_group_id, business_group_id) as business_group_id,\n" + + " coalesce(gb_download_speed, download_speed) as download_speed,\n" + + " coalesce(gb_svc_space_support_mod, svc_space_support_mod) as svc_space_support_mod,\n" + + " coalesce(gb_svc_time_support_mode svc_time_support_mode) as svc_time_support_mode\n" + + " from wvp_device_channel where device_db_id = #{deviceDbId}") + List queryAllChannels(@Param("deviceDbId") int deviceDbId); @Select("select de.* from wvp_device de left join wvp_device_channel dc on de.device_id = dc.deviceId where dc.channel_id=#{channelId}") List getDeviceByChannelId(String channelId); @@ -597,21 +537,21 @@ public interface DeviceChannelMapper { @Delete({""}) int batchDel(@Param("deleteChannelList") List deleteChannelList); @Update({""}) int batchOnline(@Param("channels") List channels); @Update({""}) int batchOffline(List channels); @@ -623,60 +563,61 @@ public interface DeviceChannelMapper { @Select("select count(1) from wvp_device_channel") int getAllChannelCount(); - // 设备主子码流逻辑START - @Update(value = {"UPDATE wvp_device_channel SET stream_id=null WHERE device_id=#{deviceId}"}) - void clearPlay(String deviceId); - // 设备主子码流逻辑END @Select(value = {" "}) - List getSubChannelsByDeviceId(@Param("deviceId") String deviceId, @Param("parentId") String parentId, @Param("onlyCatalog") boolean onlyCatalog); + List getSubChannelsByDeviceId(@Param("deviceDbId") int deviceDbId, @Param("parentId") String parentId, @Param("onlyCatalog") boolean onlyCatalog); @Update("") void updateChannelStreamIdentification(DeviceChannel channel); @@ -688,13 +629,9 @@ public interface DeviceChannelMapper { " SET update_time=#{item.updateTime}" + ", longitude=#{item.longitude}" + ", latitude=#{item.latitude}" + - ", longitude_gcj02=#{item.longitudeGcj02}" + - ", latitude_gcj02=#{item.latitudeGcj02}" + - ", longitude_wgs84=#{item.longitudeWgs84}" + - ", latitude_wgs84=#{item.latitudeWgs84}" + ", gps_time=#{item.gpsTime}" + "WHERE id=#{item.id}" + - "WHERE device_id=#{item.deviceId} AND channel_id=#{item.channelId}" + + "WHERE device_db_id=#{item.deviceDbId} AND device_id=#{item.deviceId}" + "" + ""}) void batchUpdatePosition(List channelList); diff --git a/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java index 81aa1d84..60a75526 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java @@ -40,11 +40,6 @@ public interface IDeviceChannelService { */ List queryAllChannelList(String platformId); - /** - * 数据位置信息格式处理 - */ - boolean updateAllGps(Device device); - /** * 查询通道所属的设备 */ diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java index a33e3a92..d7a95eee 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java @@ -82,7 +82,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { }else { channelMapper.update(channel); } - channelMapper.updateChannelSubCount(deviceId,channel.getParentId()); + channelMapper.updateChannelSubCount(channel.getDeviceDbId(),channel.getParentId()); } @Override @@ -170,34 +170,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { return channelMapper.queryChannelListInAll(null, null, null, platformId, null); } - @Override - public boolean updateAllGps(Device device) { - List deviceChannels = channelMapper.getChannelsWithoutTransform(device.getDeviceId()); - List result = new CopyOnWriteArrayList<>(); - if (deviceChannels.size() == 0) { - return true; - } - String now = DateUtil.getNow(); - deviceChannels.parallelStream().forEach(deviceChannel -> { - deviceChannel.setUpdateTime(now); - result.add(deviceChannel); - }); - int limitCount = 50; - if (result.size() > limitCount) { - for (int i = 0; i < result.size(); i += limitCount) { - int toIndex = i + limitCount; - if (i + limitCount > result.size()) { - toIndex = result.size(); - } - channelMapper.batchUpdate(result.subList(i, toIndex)); - } - }else { - channelMapper.batchUpdate(result); - } - - return true; - } - @Override public List getDeviceByChannelId(String channelId) { @@ -216,7 +188,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @Override public void online(DeviceChannel channel) { - channelMapper.online(channel.getDeviceId(), channel.getDeviceId()); + channelMapper.online(channel.getId()); } @Override @@ -227,7 +199,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @Override public void offline(DeviceChannel channel) { - channelMapper.offline(channel.getDeviceId(), channel.getDeviceId()); + channelMapper.offline(channel.getId()); } @Override @@ -267,14 +239,14 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { channelMapper.batchAdd(channels); for (DeviceChannel channel : channels) { if (channel.getParentId() != null) { - channelMapper.updateChannelSubCount(channel.getDeviceId(), channel.getParentId()); + channelMapper.updateChannelSubCount(channel.getDeviceDbId(), channel.getParentId()); } } } @Override public void updateChannelStreamIdentification(DeviceChannel channel) { - assert !ObjectUtils.isEmpty(channel.getDeviceId()); + assert !ObjectUtils.isEmpty(channel.getId()); assert !ObjectUtils.isEmpty(channel.getStreamIdentification()); if (ObjectUtils.isEmpty(channel.getStreamIdentification())) { log.info("[重置通道码流类型] 设备: {}, 码流: {}", channel.getDeviceId(), channel.getStreamIdentification()); @@ -287,7 +259,11 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @Override public List queryChaneListByDeviceId(String deviceId) { - return channelMapper.queryAllChannels(deviceId); + Device device = deviceMapper.getDeviceByDeviceId(deviceId); + if (device == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到通道:" + deviceId); + } + return channelMapper.queryAllChannels(device.getId()); } @Override @@ -417,7 +393,11 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { if (CollectionUtils.isEmpty(deviceChannelList)) { return false; } - List allChannels = channelMapper.queryAllChannels(deviceId); + Device device = deviceMapper.getDeviceByDeviceId(deviceId); + if (device == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备: " +deviceId); + } + List allChannels = channelMapper.queryAllChannels(device.getId()); Map allChannelMap = new ConcurrentHashMap<>(); if (allChannels.size() > 0) { for (DeviceChannel deviceChannel : allChannels) { diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java index 5b2c63b5..be7ccc7b 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java @@ -171,7 +171,7 @@ public class DeviceServiceImpl implements IDeviceService { } }else { - if (deviceChannelMapper.queryAllChannels(device.getDeviceId()).size() == 0) { + if (deviceChannelMapper.queryAllChannels(device.getId()).isEmpty()) { log.info("[设备上线]: {},通道数为0,查询通道信息", device.getDeviceId()); sync(device); } @@ -402,20 +402,6 @@ public class DeviceServiceImpl implements IDeviceService { redisCatchStorage.updateDevice(device); } } - - /** - * 更新通道坐标系 - */ - private void updateDeviceChannelGeoCoordSys(Device device) { - List deviceChannels = deviceChannelMapper.getAllChannelWithCoordinate(device.getDeviceId()); - if (!deviceChannels.isEmpty()) { - List deviceChannelsForStore = new ArrayList<>(); - deviceChannelsForStore.addAll(deviceChannels); - deviceChannelService.updateChannels(device, deviceChannelsForStore); - } - } - - @Override public List queryVideoDeviceInTreeNode(String deviceId, String parentId) { Device device = deviceMapper.getDeviceByDeviceId(deviceId); @@ -423,9 +409,9 @@ public class DeviceServiceImpl implements IDeviceService { return null; } if (ObjectUtils.isEmpty(parentId) || parentId.equals(deviceId)) { - return deviceChannelMapper.getSubChannelsByDeviceId(deviceId, null, false); + return deviceChannelMapper.getSubChannelsByDeviceId(device.getId(), null, false); }else { - return deviceChannelMapper.getSubChannelsByDeviceId(deviceId, parentId, false); + return deviceChannelMapper.getSubChannelsByDeviceId(device.getId(), parentId, false); } } @@ -528,7 +514,6 @@ public class DeviceServiceImpl implements IDeviceService { // 坐标系变化,需要重新计算GCJ02坐标和WGS84坐标 if (!deviceInStore.getGeoCoordSys().equals(device.getGeoCoordSys())) { deviceInStore.setGeoCoordSys(device.getGeoCoordSys()); - updateDeviceChannelGeoCoordSys(deviceInStore); } }else { deviceInStore.setGeoCoordSys("WGS84"); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java index fda8e438..9459fb29 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java @@ -152,24 +152,4 @@ public class MobilePositionController { device.setMobilePositionSubmissionInterval(Integer.parseInt(interval)); deviceService.updateCustomDevice(device); } - - /** - * 数据位置信息格式处理 - * @param deviceId 设备ID - * @return true = 命令发送成功 - */ - @Operation(summary = "数据位置信息格式处理", security = @SecurityRequirement(name = JwtUtils.HEADER)) - @Parameter(name = "deviceId", description = "设备国标编号", required = true) - @GetMapping("/transform/{deviceId}") - public void positionTransform(@PathVariable String deviceId) { - - Device device = deviceService.getDevice(deviceId); - if (device == null) { - throw new ControllerException(ErrorCode.ERROR400.getCode(), "未找到设备: " + deviceId); - } - boolean result = deviceChannelService.updateAllGps(device); - if (!result) { - throw new ControllerException(ErrorCode.ERROR100); - } - } }