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.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 @@ continue; } DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice, device, null); deviceChannel = SipUtils.updateGps(deviceChannel, device.getGeoCoordSys()); deviceChannel.setDeviceId(take.getDevice().getDeviceId()); channelList.add(deviceChannel); 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 @@ 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; } } 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 @@ } else { deviceChannel.setLatitude(0.00); } deviceChannel.setGpsTime(DateUtil.getNow()); @@ -414,6 +413,7 @@ } else { deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType"))); } return deviceChannel; } src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java
@@ -46,4 +46,9 @@ * @return */ List<ChannelReduce> queryAllChannelList(String platformId); /** * 数据位置信息格式处理 */ boolean updateAllGps(Device device); } src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
@@ -176,5 +176,29 @@ return channelMapper.queryChannelListInAll(null, null, null, platformId, null); } @Override public boolean updateAllGps(Device device) { List<DeviceChannel> deviceChannels = channelMapper.getChannelsWithoutTransform(device.getDeviceId()); List<DeviceChannel> 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; } } src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -357,4 +357,8 @@ @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<DeviceChannel> getChannelsWithoutTransform(String deviceId); } 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; /** * 位置信息管理 @@ -57,6 +48,9 @@ @Autowired private IDeviceService deviceService; @Autowired private IDeviceChannelService deviceChannelService; /** * 查询历史轨迹 @@ -162,4 +156,24 @@ 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); } } }