From b5ccb1636fc0efb0ea9d87c38995fee14cfd45d3 Mon Sep 17 00:00:00 2001
From: AlphaWu <wp@zafu.edu.cn>
Date: 星期日, 20 八月 2023 15:50:24 +0800
Subject: [PATCH] 修正Database拼写错误。

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java |  155 +++++++++++++++++++++++++--------------------------
 1 files changed, 76 insertions(+), 79 deletions(-)

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
old mode 100644
new mode 100755
index 7d11b15..684708c
--- 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,40 +1,36 @@
 package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition;
 
-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.WVPResult;
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
 import com.github.pagehelper.util.StringUtil;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
+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;
 
 /**
  *  浣嶇疆淇℃伅绠$悊
  */
-@Api(tags = "浣嶇疆淇℃伅绠$悊")
-@CrossOrigin
+@Tag(name  = "浣嶇疆淇℃伅绠$悊")
+
 @RestController
 @RequestMapping("/api/position")
 public class MobilePositionController {
@@ -53,27 +49,26 @@
 	@Autowired
 	private IDeviceService deviceService;
 
+	@Autowired
+	private IDeviceChannelService deviceChannelService;
+
     /**
-     *  鏌ヨ鍘嗗彶杞ㄨ抗
+     * 鏌ヨ鍘嗗彶杞ㄨ抗
      * @param deviceId 璁惧ID
      * @param start 寮�濮嬫椂闂�
      * @param end 缁撴潫鏃堕棿
      * @return
      */
-    @ApiOperation("鏌ヨ鍘嗗彶杞ㄨ抗")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "deviceId", value = "璁惧ID", required = true, dataTypeClass = String.class),
-            @ApiImplicitParam(name = "start", value = "寮�濮嬫椂闂�", required = true, dataTypeClass = String.class),
-            @ApiImplicitParam(name = "end", value = "缁撴潫鏃堕棿", required = true, dataTypeClass = String.class),
-    })
-    @GetMapping("/history/{deviceId}/{channelId}")
-    public ResponseEntity<WVPResult<List<MobilePosition>>> positions(@PathVariable String deviceId,
-                                                                     @PathVariable String channelId,
+    @Operation(summary = "鏌ヨ鍘嗗彶杞ㄨ抗")
+    @Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
+    @Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿")
+    @Parameter(name = "start", description = "寮�濮嬫椂闂�")
+    @Parameter(name = "end", description = "缁撴潫鏃堕棿")
+    @GetMapping("/history/{deviceId}")
+    public List<MobilePosition> positions(@PathVariable String deviceId,
+                                                                     @RequestParam(required = false) String channelId,
                                                                      @RequestParam(required = false) String start,
                                                                      @RequestParam(required = false) String end) {
-//        if (logger.isDebugEnabled()) {
-//            logger.debug("鏌ヨ璁惧" + deviceId + "鐨勫巻鍙茶建杩�");
-//        }
 
         if (StringUtil.isEmpty(start)) {
             start = null;
@@ -81,11 +76,7 @@
         if (StringUtil.isEmpty(end)) {
             end = null;
         }
-        WVPResult<List<MobilePosition>> wvpResult = new WVPResult<>();
-        wvpResult.setCode(0);
-        List<MobilePosition> result = storager.queryMobilePositions(deviceId, channelId, start, end);
-        wvpResult.setData(result);
-        return new ResponseEntity<>(wvpResult, HttpStatus.OK);
+        return storager.queryMobilePositions(deviceId, channelId, start, end);
     }
 
     /**
@@ -93,17 +84,11 @@
      * @param deviceId 璁惧ID
      * @return
      */
-    @ApiOperation("鏌ヨ璁惧鏈�鏂颁綅缃�")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "deviceId", value = "璁惧ID", required = true, dataTypeClass = String.class),
-    })
+    @Operation(summary = "鏌ヨ璁惧鏈�鏂颁綅缃�")
+    @Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
     @GetMapping("/latest/{deviceId}")
-    public ResponseEntity<MobilePosition> latestPosition(@PathVariable String deviceId) {
-//        if (logger.isDebugEnabled()) {
-//            logger.debug("鏌ヨ璁惧" + deviceId + "鐨勬渶鏂颁綅缃�");
-//        }
-        MobilePosition result = storager.queryLatestPosition(deviceId);
-        return new ResponseEntity<>(result, HttpStatus.OK);
+    public MobilePosition latestPosition(@PathVariable String deviceId) {
+        return storager.queryLatestPosition(deviceId);
     }
 
     /**
@@ -111,23 +96,26 @@
      * @param deviceId 璁惧ID
      * @return
      */
-    @ApiOperation("鑾峰彇绉诲姩浣嶇疆淇℃伅")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "deviceId", value = "璁惧ID", required = true, dataTypeClass = String.class),
-    })
+    @Operation(summary = "鑾峰彇绉诲姩浣嶇疆淇℃伅")
+    @Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
     @GetMapping("/realtime/{deviceId}")
-    public DeferredResult<ResponseEntity<MobilePosition>> realTimePosition(@PathVariable String deviceId) {
+    public DeferredResult<MobilePosition> realTimePosition(@PathVariable String deviceId) {
         Device device = storager.queryVideoDevice(deviceId);
         String uuid = UUID.randomUUID().toString();
-        String key = DeferredResultHolder.CALLBACK_CMD_MOBILEPOSITION + deviceId;
-        cmder.mobilePostitionQuery(device, event -> {
-			RequestMessage msg = new RequestMessage();
-			msg.setId(uuid);
-            msg.setKey(key);
-			msg.setData(String.format("鑾峰彇绉诲姩浣嶇疆淇℃伅澶辫触锛岄敊璇爜锛� %s, %s", event.statusCode, event.msg));
-			resultHolder.invokeResult(msg);
-		});
-        DeferredResult<ResponseEntity<MobilePosition>> result = new DeferredResult<ResponseEntity<MobilePosition>>(5*1000L);
+        String key = DeferredResultHolder.CALLBACK_CMD_MOBILE_POSITION + deviceId;
+        try {
+            cmder.mobilePostitionQuery(device, event -> {
+                RequestMessage msg = new RequestMessage();
+                msg.setId(uuid);
+                msg.setKey(key);
+                msg.setData(String.format("鑾峰彇绉诲姩浣嶇疆淇℃伅澶辫触锛岄敊璇爜锛� %s, %s", event.statusCode, event.msg));
+                resultHolder.invokeResult(msg);
+            });
+        } catch (InvalidArgumentException | SipException | ParseException e) {
+            logger.error("[鍛戒护鍙戦�佸け璐 鑾峰彇绉诲姩浣嶇疆淇℃伅: {}", e.getMessage());
+            throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage());
+        }
+        DeferredResult<MobilePosition> result = new DeferredResult<MobilePosition>(5*1000L);
 		result.onTimeout(()->{
 			logger.warn(String.format("鑾峰彇绉诲姩浣嶇疆淇℃伅瓒呮椂"));
 			// 閲婃斁rtpserver
@@ -148,20 +136,14 @@
      * @param interval 涓婃姤鏃堕棿闂撮殧
      * @return true = 鍛戒护鍙戦�佹垚鍔�
      */
-    @ApiOperation("璁㈤槄浣嶇疆淇℃伅")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "deviceId", value = "璁惧ID", required = true, dataTypeClass = String.class),
-            @ApiImplicitParam(name = "expires", value = "璁㈤槄瓒呮椂鏃堕棿", dataTypeClass = String.class),
-            @ApiImplicitParam(name = "interval", value = "涓婃姤鏃堕棿闂撮殧", dataTypeClass = String.class),
-    })
+    @Operation(summary = "璁㈤槄浣嶇疆淇℃伅")
+    @Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
+    @Parameter(name = "expires", description = "璁㈤槄瓒呮椂鏃堕棿", required = true)
+    @Parameter(name = "interval", description = "涓婃姤鏃堕棿闂撮殧", required = true)
     @GetMapping("/subscribe/{deviceId}")
-    public ResponseEntity<String> positionSubscribe(@PathVariable String deviceId,
+    public void positionSubscribe(@PathVariable String deviceId,
                                                     @RequestParam String expires,
                                                     @RequestParam String interval) {
-        String msg = ((expires.equals("0")) ? "鍙栨秷" : "") + "璁㈤槄璁惧" + deviceId + "鐨勭Щ鍔ㄤ綅缃�";
-        if (logger.isDebugEnabled()) {
-            logger.debug(msg);
-        }
 
         if (StringUtil.isEmpty(interval)) {
             interval = "5";
@@ -169,14 +151,29 @@
         Device device = storager.queryVideoDevice(deviceId);
         device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires));
         device.setMobilePositionSubmissionInterval(Integer.parseInt(interval));
-        storager.updateDevice(device);
-        String result = msg;
-        if (deviceService.removeMobilePositionSubscribe(device)) {
-            result += "锛屾垚鍔�";
-        } else {
-            result += "锛屽け璐�";
+        deviceService.updateDevice(device);
+        if (!deviceService.removeMobilePositionSubscribe(device)) {
+            throw new ControllerException(ErrorCode.ERROR100);
         }
+    }
 
-        return new ResponseEntity<>(result, HttpStatus.OK);
+    /**
+     * 鏁版嵁浣嶇疆淇℃伅鏍煎紡澶勭悊
+     * @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);
+        }
     }
 }

--
Gitblit v1.8.0