LogController.java
3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.genersoft.iot.vmp.vmanager.log;
import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.media.zlm.ZLMRunner;
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.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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.web.bind.annotation.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@Api(tags = "日志管理")
@CrossOrigin
@RestController
@RequestMapping("/api/log")
public class LogController {
private final static Logger logger = LoggerFactory.getLogger(LogController.class);
@Autowired
private ILogService logService;
@Autowired
private UserSetup userSetup;
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 分页查询日志
*
* @param query 查询内容
* @param page 当前页
* @param count 每页查询数量
* @param type 类型
* @param startTime 开始时间
* @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(
@RequestParam int page,
@RequestParam int count,
@RequestParam(required = false) String query,
@RequestParam(required = false) String type,
@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 (!userSetup.getLogInDatebase()) {
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);
}
PageInfo<LogDto> allLog = logService.getAll(page, count, query, type, startTime, endTime);
return new ResponseEntity<>(allLog, HttpStatus.OK);
}
/**
* 清空日志
*
*/
@ApiOperation("清空日志")
@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);
}
}