From 7be636f8b850c2554d9071876820579ce631dc25 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Wed, 15 Feb 2023 18:30:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0=E9=80=9A?= =?UTF-8?q?=E9=81=93=E6=98=AF=E6=9B=B4=E6=96=B0=E5=90=84=E4=B8=AA=E5=9D=90?= =?UTF-8?q?=E6=A0=87=E7=B3=BB=E5=BE=B7=E4=BD=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cmd/CatalogResponseMessageHandler.java | 2 + .../iot/vmp/gb28181/utils/SipUtils.java | 34 +++++++++++++++ .../iot/vmp/gb28181/utils/XmlUtil.java | 4 +- .../vmp/service/IDeviceChannelService.java | 5 +++ .../impl/DeviceChannelServiceImpl.java | 24 +++++++++++ .../vmp/storager/dao/DeviceChannelMapper.java | 4 ++ .../MobilePositionController.java | 42 ++++++++++++------- 7 files changed, 99 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java index 761481be..a9079991 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.session.CatalogDataCatch; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import gov.nist.javax.sip.message.SIPRequest; @@ -107,6 +108,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp continue; } DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice, device, null); + deviceChannel = SipUtils.updateGps(deviceChannel, device.getGeoCoordSys()); deviceChannel.setDeviceId(take.getDevice().getDeviceId()); channelList.add(deviceChannel); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java index f3fbbb41..afe11838 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.utils; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.RemoteAddressInfo; import com.genersoft.iot.vmp.utils.GitUtil; import gov.nist.javax.sip.address.AddressImpl; @@ -148,4 +149,37 @@ public class SipUtils { return new RemoteAddressInfo(remoteAddress, remotePort); } + + public static DeviceChannel updateGps(DeviceChannel deviceChannel, String geoCoordSys) { + if (deviceChannel.getLongitude()*deviceChannel.getLatitude() > 0) { + + if (geoCoordSys == null) { + geoCoordSys = "WGS84"; + } + if ("WGS84".equals(geoCoordSys)) { + deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); + deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); + Double[] position = Coordtransform.WGS84ToGCJ02(deviceChannel.getLongitude(), deviceChannel.getLatitude()); + deviceChannel.setLongitudeGcj02(position[0]); + deviceChannel.setLatitudeGcj02(position[1]); + }else if ("GCJ02".equals(geoCoordSys)) { + deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude()); + deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude()); + Double[] position = Coordtransform.GCJ02ToWGS84(deviceChannel.getLongitude(), deviceChannel.getLatitude()); + deviceChannel.setLongitudeWgs84(position[0]); + deviceChannel.setLatitudeWgs84(position[1]); + }else { + deviceChannel.setLongitudeGcj02(0.00); + deviceChannel.setLatitudeGcj02(0.00); + deviceChannel.setLongitudeWgs84(0.00); + deviceChannel.setLatitudeWgs84(0.00); + } + }else { + deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude()); + deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude()); + deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); + deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); + } + return deviceChannel; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java index 0ea6d877..d51ab9f5 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java @@ -1,11 +1,9 @@ package com.genersoft.iot.vmp.gb28181.utils; -import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; -import com.genersoft.iot.vmp.gb28181.bean.TreeType; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.utils.DateUtil; import org.dom4j.Attribute; @@ -400,6 +398,7 @@ public class XmlUtil { } else { deviceChannel.setLatitude(0.00); } + deviceChannel.setGpsTime(DateUtil.getNow()); @@ -414,6 +413,7 @@ public class XmlUtil { } else { deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType"))); } + return deviceChannel; } 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 31e568a3..57605bb1 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java @@ -46,4 +46,9 @@ public interface IDeviceChannelService { * @return */ 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 880b6971..75276319 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java @@ -176,5 +176,29 @@ 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 ArrayList<>(); + if (deviceChannels.size() == 0) { + return true; + } + deviceChannels.parallelStream().forEach(deviceChannel -> { + result.add(updateGps(deviceChannel, device)); + }); + int limitCount = 300; + 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; + } } 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 8da1a09b..4fe0a226 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java @@ -357,4 +357,8 @@ public interface DeviceChannelMapper { @Select("select count(1) as total, sum(status) as online from device_channel") ResourceBaceInfo getOverview(); + + @Select("select * from device_channel where deviceId = #{deviceId} " + + "and latitude * longitude > 0 and latitudeGcj02 * latitudeWgs84 * longitudeWgs84 * longitudeGcj02 = 0") + List getChannelsWithoutTransform(String deviceId); } 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 f399f300..305d488a 100644 --- 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 @@ -1,39 +1,30 @@ package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition; -import java.text.ParseException; -import java.util.List; -import java.util.UUID; - import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.MobilePosition; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; +import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.service.IDeviceService; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; -import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.github.pagehelper.util.StringUtil; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; 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.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.async.DeferredResult; import javax.sip.InvalidArgumentException; import javax.sip.SipException; +import java.text.ParseException; +import java.util.List; +import java.util.UUID; /** * 位置信息管理 @@ -58,6 +49,9 @@ public class MobilePositionController { @Autowired private IDeviceService deviceService; + @Autowired + private IDeviceChannelService deviceChannelService; + /** * 查询历史轨迹 * @param deviceId 设备ID @@ -162,4 +156,24 @@ public class MobilePositionController { throw new ControllerException(ErrorCode.ERROR100); } } + + /** + * 数据位置信息格式处理 + * @param deviceId 设备ID + * @return true = 命令发送成功 + */ + @Operation(summary = "数据位置信息格式处理") + @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); + } + } }