From 42a2772d1aa7493bcc4fac3e24ee8eda4eebc23d Mon Sep 17 00:00:00 2001
From: xubinbin <1323875150@qq.com>
Date: 星期二, 12 十二月 2023 17:09:04 +0800
Subject: [PATCH] bugfix:请求头带token, SecurityUtils 获取用户id 一直为0 #1195

---
 src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java |   80 +++++++++++++++++----------------------
 1 files changed, 35 insertions(+), 45 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
old mode 100644
new mode 100755
index c147a9d..937bc08
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
@@ -1,27 +1,23 @@
 package com.genersoft.iot.vmp.vmanager.log;
 
 import com.genersoft.iot.vmp.conf.UserSetting;
+import com.genersoft.iot.vmp.conf.exception.ControllerException;
 import com.genersoft.iot.vmp.service.ILogService;
 import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
-import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
+import com.genersoft.iot.vmp.utils.DateUtil;
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
 import com.github.pagehelper.PageInfo;
-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.util.StringUtils;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.*;
 
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
+@Tag(name  = "鏃ュ織绠$悊")
 
-@Api(tags = "鏃ュ織绠$悊")
-@CrossOrigin
 @RestController
 @RequestMapping("/api/log")
 public class LogController {
@@ -34,8 +30,6 @@
     @Autowired
     private UserSetting userSetting;
 
-    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
     /**
      *  鍒嗛〉鏌ヨ鏃ュ織
      *
@@ -47,17 +41,15 @@
      * @param endTime 缁撴潫鏃堕棿
      * @return
      */
-    @ApiOperation("鍒嗛〉鏌ヨ鎶ヨ")
     @GetMapping("/all")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name="query", value = "鏌ヨ鍐呭", dataTypeClass = String.class),
-            @ApiImplicitParam(name="page", value = "褰撳墠椤�", required = true ,dataTypeClass = Integer.class),
-            @ApiImplicitParam(name="count", value = "姣忛〉鏌ヨ鏁伴噺", required = true ,dataTypeClass = Integer.class),
-            @ApiImplicitParam(name="type", value = "绫诲瀷" ,dataTypeClass = String.class),
-            @ApiImplicitParam(name="startTime", value = "鏌ヨ鍐呭" ,dataTypeClass = String.class),
-            @ApiImplicitParam(name="endTime", value = "鏌ヨ鍐呭" ,dataTypeClass = String.class),
-    })
-    public ResponseEntity<PageInfo<LogDto>> getAll(
+    @Operation(summary = "鍒嗛〉鏌ヨ鏃ュ織")
+    @Parameter(name = "query", description = "鏌ヨ鍐呭", required = true)
+    @Parameter(name = "page", description = "褰撳墠椤�", required = true)
+    @Parameter(name = "count", description = "姣忛〉鏌ヨ鏁伴噺", required = true)
+    @Parameter(name = "type", description = "绫诲瀷", required = true)
+    @Parameter(name = "startTime", description = "寮�濮嬫椂闂�", required = true)
+    @Parameter(name = "endTime", description = "缁撴潫鏃堕棿", required = true)
+    public PageInfo<LogDto> getAll(
             @RequestParam int page,
             @RequestParam int count,
             @RequestParam(required = false)  String query,
@@ -65,39 +57,37 @@
             @RequestParam(required = false) String startTime,
             @RequestParam(required = false) String endTime
     ) {
-        if (StringUtils.isEmpty(query)) query = null;
-        if (StringUtils.isEmpty(startTime)) startTime = null;
-        if (StringUtils.isEmpty(endTime)) endTime = null;
-        if (!userSetting.getLogInDatebase()) {
+        if (ObjectUtils.isEmpty(query)) {
+            query = null;
+        }
+
+        if (!userSetting.getLogInDatabase()) {
             logger.warn("鑷姩璁板綍鏃ュ織鍔熻兘宸插叧闂紝鏌ヨ缁撴灉鍙兘涓嶅畬鏁淬��");
         }
 
-        try {
-            if (startTime != null)  format.parse(startTime);
-            if (endTime != null)  format.parse(endTime);
-        } catch (ParseException e) {
-            return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
+        if (ObjectUtils.isEmpty(startTime)) {
+            startTime = null;
+        }else if (!DateUtil.verification(startTime, DateUtil.formatter) ){
+            throw new ControllerException(ErrorCode.ERROR400.getCode(), "startTime鏍煎紡涓�" + DateUtil.PATTERN);
         }
 
-        PageInfo<LogDto> allLog = logService.getAll(page, count, query, type, startTime, endTime);
-        return new ResponseEntity<>(allLog, HttpStatus.OK);
+        if (ObjectUtils.isEmpty(endTime)) {
+            endTime = null;
+        }else if (!DateUtil.verification(endTime, DateUtil.formatter) ){
+            throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime鏍煎紡涓�" + DateUtil.PATTERN);
+        }
+
+        return logService.getAll(page, count, query, type, startTime, endTime);
     }
 
     /**
      *  娓呯┖鏃ュ織
      *
      */
-    @ApiOperation("娓呯┖鏃ュ織")
+    @Operation(summary = "娓呯┖鏃ュ織")
     @DeleteMapping("/clear")
-    @ApiImplicitParams({})
-    public ResponseEntity<WVPResult<String>> clear() {
-
-        int count = logService.clear();
-        WVPResult wvpResult = new WVPResult();
-        wvpResult.setCode(0);
-        wvpResult.setMsg("success");
-        wvpResult.setData(count);
-        return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
+    public void clear() {
+        logService.clear();
     }
 
 }

--
Gitblit v1.8.0