Commit 7be636f8b850c2554d9071876820579ce631dc25

Authored by 648540858
1 parent 2c7ed82b

修复更新通道是更新各个坐标系德位置信息

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;
5 5 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
6 6 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
7 7 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
  8 +import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
8 9 import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
9 10 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
10 11 import gov.nist.javax.sip.message.SIPRequest;
... ... @@ -107,6 +108,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
107 108 continue;
108 109 }
109 110 DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice, device, null);
  111 + deviceChannel = SipUtils.updateGps(deviceChannel, device.getGeoCoordSys());
110 112 deviceChannel.setDeviceId(take.getDevice().getDeviceId());
111 113  
112 114 channelList.add(deviceChannel);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
1 1 package com.genersoft.iot.vmp.gb28181.utils;
2 2  
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
3 4 import com.genersoft.iot.vmp.gb28181.bean.RemoteAddressInfo;
4 5 import com.genersoft.iot.vmp.utils.GitUtil;
5 6 import gov.nist.javax.sip.address.AddressImpl;
... ... @@ -148,4 +149,37 @@ public class SipUtils {
148 149  
149 150 return new RemoteAddressInfo(remoteAddress, remotePort);
150 151 }
  152 +
  153 + public static DeviceChannel updateGps(DeviceChannel deviceChannel, String geoCoordSys) {
  154 + if (deviceChannel.getLongitude()*deviceChannel.getLatitude() > 0) {
  155 +
  156 + if (geoCoordSys == null) {
  157 + geoCoordSys = "WGS84";
  158 + }
  159 + if ("WGS84".equals(geoCoordSys)) {
  160 + deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude());
  161 + deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude());
  162 + Double[] position = Coordtransform.WGS84ToGCJ02(deviceChannel.getLongitude(), deviceChannel.getLatitude());
  163 + deviceChannel.setLongitudeGcj02(position[0]);
  164 + deviceChannel.setLatitudeGcj02(position[1]);
  165 + }else if ("GCJ02".equals(geoCoordSys)) {
  166 + deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude());
  167 + deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude());
  168 + Double[] position = Coordtransform.GCJ02ToWGS84(deviceChannel.getLongitude(), deviceChannel.getLatitude());
  169 + deviceChannel.setLongitudeWgs84(position[0]);
  170 + deviceChannel.setLatitudeWgs84(position[1]);
  171 + }else {
  172 + deviceChannel.setLongitudeGcj02(0.00);
  173 + deviceChannel.setLatitudeGcj02(0.00);
  174 + deviceChannel.setLongitudeWgs84(0.00);
  175 + deviceChannel.setLatitudeWgs84(0.00);
  176 + }
  177 + }else {
  178 + deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude());
  179 + deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude());
  180 + deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude());
  181 + deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude());
  182 + }
  183 + return deviceChannel;
  184 + }
151 185 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
1 1 package com.genersoft.iot.vmp.gb28181.utils;
2 2  
3   -import com.alibaba.fastjson2.JSON;
4 3 import com.alibaba.fastjson2.JSONArray;
5 4 import com.alibaba.fastjson2.JSONObject;
6 5 import com.genersoft.iot.vmp.gb28181.bean.Device;
7 6 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
8   -import com.genersoft.iot.vmp.gb28181.bean.TreeType;
9 7 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
10 8 import com.genersoft.iot.vmp.utils.DateUtil;
11 9 import org.dom4j.Attribute;
... ... @@ -400,6 +398,7 @@ public class XmlUtil {
400 398 } else {
401 399 deviceChannel.setLatitude(0.00);
402 400 }
  401 +
403 402 deviceChannel.setGpsTime(DateUtil.getNow());
404 403  
405 404  
... ... @@ -414,6 +413,7 @@ public class XmlUtil {
414 413 } else {
415 414 deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
416 415 }
  416 +
417 417 return deviceChannel;
418 418 }
419 419  
... ...
src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java
... ... @@ -46,4 +46,9 @@ public interface IDeviceChannelService {
46 46 * @return
47 47 */
48 48 List<ChannelReduce> queryAllChannelList(String platformId);
  49 +
  50 + /**
  51 + * 数据位置信息格式处理
  52 + */
  53 + boolean updateAllGps(Device device);
49 54 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
... ... @@ -176,5 +176,29 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
176 176 return channelMapper.queryChannelListInAll(null, null, null, platformId, null);
177 177 }
178 178  
  179 + @Override
  180 + public boolean updateAllGps(Device device) {
  181 + List<DeviceChannel> deviceChannels = channelMapper.getChannelsWithoutTransform(device.getDeviceId());
  182 + List<DeviceChannel> result = new ArrayList<>();
  183 + if (deviceChannels.size() == 0) {
  184 + return true;
  185 + }
  186 + deviceChannels.parallelStream().forEach(deviceChannel -> {
  187 + result.add(updateGps(deviceChannel, device));
  188 + });
  189 + int limitCount = 300;
  190 + if (result.size() > limitCount) {
  191 + for (int i = 0; i < result.size(); i += limitCount) {
  192 + int toIndex = i + limitCount;
  193 + if (i + limitCount > result.size()) {
  194 + toIndex = result.size();
  195 + }
  196 + channelMapper.batchUpdate(result.subList(i, toIndex));
  197 + }
  198 + }else {
  199 + channelMapper.batchUpdate(result);
  200 + }
179 201  
  202 + return true;
  203 + }
180 204 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
... ... @@ -357,4 +357,8 @@ public interface DeviceChannelMapper {
357 357  
358 358 @Select("select count(1) as total, sum(status) as online from device_channel")
359 359 ResourceBaceInfo getOverview();
  360 +
  361 + @Select("select * from device_channel where deviceId = #{deviceId} " +
  362 + "and latitude * longitude > 0 and latitudeGcj02 * latitudeWgs84 * longitudeWgs84 * longitudeGcj02 = 0")
  363 + List<DeviceChannel> getChannelsWithoutTransform(String deviceId);
360 364 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
1 1 package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition;
2 2  
3   -import java.text.ParseException;
4   -import java.util.List;
5   -import java.util.UUID;
6   -
7 3 import com.genersoft.iot.vmp.conf.exception.ControllerException;
8 4 import com.genersoft.iot.vmp.gb28181.bean.Device;
9 5 import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
10 6 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
11 7 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
12 8 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
  9 +import com.genersoft.iot.vmp.service.IDeviceChannelService;
13 10 import com.genersoft.iot.vmp.service.IDeviceService;
14 11 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
15 12 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
16   -import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
17 13 import com.github.pagehelper.util.StringUtil;
18   -
19 14 import io.swagger.v3.oas.annotations.Operation;
20 15 import io.swagger.v3.oas.annotations.Parameter;
21 16 import io.swagger.v3.oas.annotations.tags.Tag;
22 17 import org.slf4j.Logger;
23 18 import org.slf4j.LoggerFactory;
24 19 import org.springframework.beans.factory.annotation.Autowired;
25   -import org.springframework.http.HttpStatus;
26   -import org.springframework.http.ResponseEntity;
27   -import org.springframework.web.bind.annotation.CrossOrigin;
28   -import org.springframework.web.bind.annotation.GetMapping;
29   -import org.springframework.web.bind.annotation.PathVariable;
30   -import org.springframework.web.bind.annotation.RequestMapping;
31   -import org.springframework.web.bind.annotation.RequestParam;
32   -import org.springframework.web.bind.annotation.RestController;
  20 +import org.springframework.web.bind.annotation.*;
33 21 import org.springframework.web.context.request.async.DeferredResult;
34 22  
35 23 import javax.sip.InvalidArgumentException;
36 24 import javax.sip.SipException;
  25 +import java.text.ParseException;
  26 +import java.util.List;
  27 +import java.util.UUID;
37 28  
38 29 /**
39 30 * 位置信息管理
... ... @@ -58,6 +49,9 @@ public class MobilePositionController {
58 49 @Autowired
59 50 private IDeviceService deviceService;
60 51  
  52 + @Autowired
  53 + private IDeviceChannelService deviceChannelService;
  54 +
61 55 /**
62 56 * 查询历史轨迹
63 57 * @param deviceId 设备ID
... ... @@ -162,4 +156,24 @@ public class MobilePositionController {
162 156 throw new ControllerException(ErrorCode.ERROR100);
163 157 }
164 158 }
  159 +
  160 + /**
  161 + * 数据位置信息格式处理
  162 + * @param deviceId 设备ID
  163 + * @return true = 命令发送成功
  164 + */
  165 + @Operation(summary = "数据位置信息格式处理")
  166 + @Parameter(name = "deviceId", description = "设备国标编号", required = true)
  167 + @GetMapping("/transform/{deviceId}")
  168 + public void positionTransform(@PathVariable String deviceId) {
  169 +
  170 + Device device = deviceService.getDevice(deviceId);
  171 + if (device == null) {
  172 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "未找到设备: " + deviceId);
  173 + }
  174 + boolean result = deviceChannelService.updateAllGps(device);
  175 + if (!result) {
  176 + throw new ControllerException(ErrorCode.ERROR100);
  177 + }
  178 + }
165 179 }
... ...