xuefei
2020-12-10 eeeb7233935ea9b10e99043bdbf740ef86c9bf20
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
package cn.cetc54.platform.base.controller.manage;
 
import cn.cetc54.platform.core.common.utils.PageUtil;
import cn.cetc54.platform.core.common.utils.ResultUtil;
import cn.cetc54.platform.core.common.vo.PageVo;
import cn.cetc54.platform.core.common.vo.Result;
import cn.cetc54.platform.core.entity.Log;
import cn.cetc54.platform.core.service.LogService;
import cn.cetc54.platform.core.service.elasticsearch.EsLogService;
import cn.cetc54.platform.core.common.vo.SearchVo;
import cn.cetc54.platform.core.entity.elasticsearch.EsLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
 
/**
 * @author
 */
@Slf4j
@RestController
@Api(description = "日志管理接口")
@RequestMapping("/platform/log")
@Transactional
public class LogController{
 
    @Value("${platform.logRecord.es:false}")
    private Boolean esRecord;
 
    @Autowired
    private EsLogService esLogService;
 
    @Autowired
    private LogService logService;
 
    @RequestMapping(value = "/getAllByPage", method = RequestMethod.GET)
    @ApiOperation(value = "分页获取全部")
    public Result<Object> getAllByPage(@RequestParam(required = false) Integer type,
                                       @RequestParam String key,
                                       SearchVo searchVo,
                                       PageVo pageVo){
 
        if(esRecord){
            Page<EsLog> es = esLogService.findByConfition(type, key, searchVo, PageUtil.initPage(pageVo));
            return ResultUtil.data(es);
        }else{
            Page<Log> log = logService.findByConfition(type, key, searchVo, PageUtil.initPage(pageVo));
            return ResultUtil.data(log);
        }
    }
 
    @RequestMapping(value = "/delByIds", method = RequestMethod.POST)
    @ApiOperation(value = "批量删除")
    public Result<Object> delByIds(@RequestParam String[] ids){
 
        for(String id : ids){
            if(esRecord){
                esLogService.deleteLog(id);
            }else{
                logService.delete(id);
            }
        }
        return ResultUtil.success("删除成功");
    }
 
    @RequestMapping(value = "/delAll", method = RequestMethod.POST)
    @ApiOperation(value = "全部删除")
    public Result<Object> delAll(){
 
        if(esRecord){
            esLogService.deleteAll();
        }else{
            logService.deleteAll();
        }
        return ResultUtil.success("删除成功");
    }
}