LogController.java 2.2 KB
Newer Older
1 2
package me.zhengjie.rest;

3 4
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
5
import me.zhengjie.service.LogService;
6
import me.zhengjie.service.dto.LogQueryCriteria;
Z
zhengjie 已提交
7
import me.zhengjie.utils.SecurityUtils;
8 9 10 11 12
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
13
import org.springframework.web.bind.annotation.PathVariable;
14 15 16 17
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
18
 * @author Zheng Jie
19 20 21
 * @date 2018-11-24
 */
@RestController
22 23
@RequestMapping("/api/logs")
@Api(tags = "监控:日志管理")
24 25
public class LogController {

26
    private final LogService logService;
27

28 29 30 31 32 33
    public LogController(LogService logService) {
        this.logService = logService;
    }

    @GetMapping
    @ApiOperation("日志查询")
34
    @PreAuthorize("hasAnyRole('ADMIN')")
35 36
    public ResponseEntity getLogs(LogQueryCriteria criteria, Pageable pageable){
        criteria.setLogType("INFO");
37
        return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
38 39
    }

40 41
    @GetMapping(value = "/user")
    @ApiOperation("用户日志查询")
42 43
    public ResponseEntity getUserLogs(LogQueryCriteria criteria, Pageable pageable){
        criteria.setLogType("INFO");
44
        criteria.setBlurry(SecurityUtils.getUsername());
45
        return new ResponseEntity<>(logService.queryAllByUser(criteria,pageable), HttpStatus.OK);
46 47
    }

48 49
    @GetMapping(value = "/error")
    @ApiOperation("错误日志查询")
50
    @PreAuthorize("hasAnyRole('ADMIN')")
51 52
    public ResponseEntity getErrorLogs(LogQueryCriteria criteria, Pageable pageable){
        criteria.setLogType("ERROR");
53
        return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
54
    }
55

56 57
    @GetMapping(value = "/error/{id}")
    @ApiOperation("日志异常详情查询")
58 59
    @PreAuthorize("hasAnyRole('ADMIN')")
    public ResponseEntity getErrorLogs(@PathVariable Long id){
60
        return new ResponseEntity<>(logService.findByErrDetail(id), HttpStatus.OK);
61
    }
62
}