From 71fe60d885b09d53fcd4c58afcfccf18d24a94c2 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 11 四月 2024 15:34:56 +0800
Subject: [PATCH] 更新README
---
src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java | 88 +++++++++++++++++--------------------------
1 files changed, 35 insertions(+), 53 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 44b1688..7ad595d
--- 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,25 @@
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.conf.security.JwtUtils;
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.security.SecurityRequirement;
+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 +32,6 @@
@Autowired
private UserSetting userSetting;
- private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
/**
* 鍒嗛〉鏌ヨ鏃ュ織
*
@@ -47,17 +43,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 = "鍒嗛〉鏌ヨ鏃ュ織", security = @SecurityRequirement(name = JwtUtils.HEADER))
+ @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,49 +59,37 @@
@RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime
) {
- if (StringUtils.isEmpty(query)) {
+ if (ObjectUtils.isEmpty(query)) {
query = null;
}
- if (StringUtils.isEmpty(startTime)) {
- startTime = null;
- }
- if (StringUtils.isEmpty(endTime)) {
- endTime = null;
- }
- if (!userSetting.getLogInDatebase()) {
+
+ 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 = "娓呯┖鏃ュ織", security = @SecurityRequirement(name = JwtUtils.HEADER))
@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