SysLogController.java 9.58 KB
Newer Older
liqin's avatar
liqin committed
1 2
package cn.wisenergy.chnmuseum.party.web.controller;

wzp's avatar
wzp committed
3
import cn.wisenergy.chnmuseum.party.common.log.OperType;
liqin's avatar
liqin committed
4
import cn.wisenergy.chnmuseum.party.common.util.DateUtil80;
liqin's avatar
liqin committed
5
import cn.wisenergy.chnmuseum.party.common.util.NetWorkUtil;
wzp's avatar
wzp committed
6
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
liqin's avatar
liqin committed
7 8 9
import cn.wisenergy.chnmuseum.party.model.RunLog;
import cn.wisenergy.chnmuseum.party.model.SysLog;
import cn.wisenergy.chnmuseum.party.model.TOperationLog;
wzp's avatar
wzp committed
10
import cn.wisenergy.chnmuseum.party.service.TOperationLogService;
11
import cn.wisenergy.chnmuseum.party.service.impl.RunLogServiceImpl;
liqin's avatar
liqin committed
12 13
import cn.wisenergy.chnmuseum.party.service.impl.SysLogServiceImpl;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
wzp's avatar
wzp committed
14
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
15
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
wzp's avatar
wzp committed
16
import io.swagger.annotations.Api;
liqin's avatar
liqin committed
17 18 19
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
wzp's avatar
wzp committed
20
import org.apache.commons.lang3.StringUtils;
liqin's avatar
liqin committed
21 22 23 24 25 26 27 28 29 30
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
wzp's avatar
wzp committed
31 32 33
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Map;
liqin's avatar
liqin committed
34 35 36

@RestController
@RequestMapping("/sysLog")
wzp's avatar
wzp committed
37
@Api(tags = {"日志管理接口"})
liqin's avatar
liqin committed
38 39 40 41 42
public class SysLogController extends BaseController {

    @Resource
    private SysLogServiceImpl sysLogService;

43 44 45
    @Resource
    private RunLogServiceImpl runLogService;

wzp's avatar
wzp committed
46 47 48
    @Resource
    private TOperationLogService operationLogService;

liqin's avatar
liqin committed
49 50 51 52 53
    /**
     * 插入系统日志表
     */
    @ApiOperation(value = "插入系统日志", notes = "插入系统日志")
    @PostMapping(value = "/insertSysLog")
wzp's avatar
wzp committed
54
    public Boolean insertSysLog(String operationContent, String username, String id) {
liqin's avatar
liqin committed
55 56
        SysLog sysLog = new SysLog();
        //日志时间
liqin's avatar
liqin committed
57
        sysLog.setOperationTime(DateUtil80.getDateTimeOfTimestamp(System.currentTimeMillis()));
liqin's avatar
liqin committed
58 59 60 61 62 63 64 65 66 67 68
        //获取登录IP并插入
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String operationIp = NetWorkUtil.getLoggableAddress(request);
        sysLog.setOperationIp(operationIp);
        if (username == null) {
            //操作者用户名
            sysLog.setOperator(this.getUserName());
        } else {
            sysLog.setOperator(username);
        }
69 70
        if ("1".equals(id)) {
            sysLog.setType(1);
wzp's avatar
wzp committed
71
        } else {
72 73
            sysLog.setType(2);
        }
liqin's avatar
liqin committed
74 75
        //日志内容
        sysLog.setOperationContent(operationContent);
76 77
        sysLog.setOperationObject("登录管理");
        sysLog.setOperationType("登录");
liqin's avatar
liqin committed
78 79 80 81 82 83 84 85
        Boolean ret = this.sysLogService.save(sysLog);
        return ret;
    }

    /**
     * 查询系统日志
     */
    @ApiOperation(value = "查询系统日志", notes = "查询系统日志")
wzp's avatar
wzp committed
86 87 88 89 90 91 92 93 94
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "nameOrCode", value = "名称或编码", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startDate", value = "创建时间-开始", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "创建时间-结束", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "日志类型", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "operationType", value = "操作类型", paramType = "query", dataType = "String")
    })
liqin's avatar
liqin committed
95 96
    @GetMapping(value = "/querySysLogList")
    @RequiresPermissions("/sysLog/querySysLogList")
wzp's avatar
wzp committed
97
    public Map<String, Object> querySysLogList(GenericPageParam genericPageParam) {
liqin's avatar
liqin committed
98
        try {
wzp's avatar
wzp committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
            LambdaQueryWrapper<SysLog> queryWrapper = new LambdaQueryWrapper<>();
            // 对名称或编码模糊查询
            if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
                queryWrapper.like(SysLog::getOperator, genericPageParam.getNameOrCode());
            }
            if (StringUtils.isNotBlank(genericPageParam.getType())) {
                queryWrapper.eq(SysLog::getType, genericPageParam.getType());
            }
            if (StringUtils.isNotBlank(genericPageParam.getOperationType())) {
                queryWrapper.eq(SysLog::getOperationType,genericPageParam.getOperationType());
            }
            // 根据创建时间区间检索
            if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
                queryWrapper.ge(SysLog::getOperationTime, genericPageParam.getStartDate().atTime(0, 0, 0))
                        .le(SysLog::getOperationTime, genericPageParam.getEndDate().atTime(23, 59, 59));
            }
            // 设置排序规则
            queryWrapper.orderByDesc(SysLog::getOperationTime);
            Page<SysLog> page = sysLogService.page(getPage(), queryWrapper);
wzp's avatar
wzp committed
118
            return getResult(page);
liqin's avatar
liqin committed
119 120 121
        } catch (Exception e) {
            logger.error("查询系统日志列表出错!", e);
        }
wzp's avatar
wzp committed
122
        return getFailResult();
liqin's avatar
liqin committed
123 124
    }

125 126 127
    /**
     * 插入机顶盒日志表
     */
wzp's avatar
wzp committed
128
    @ApiOperation(value = "插入机顶盒日志表", notes = "插入机顶盒日志表")
129 130
    @PostMapping(value = "/insertRunLog")
    public Boolean insertRunLog(RunLog runLog) {
wzp's avatar
wzp committed
131 132 133 134 135 136 137
        boolean b = false;
        try {
            b = runLogService.insertRunLog(runLog);
            return b;
        } catch (Exception e) {
            e.printStackTrace();
        }
138 139 140
        return b;
    }

wzp's avatar
wzp committed
141 142 143 144 145 146 147
    /**
     * 插入运维日志表
     */
    @ApiOperation(value = "插入运维日志表", notes = "插入运维日志表")
    @PostMapping(value = "/insertOperationLog")
    public Boolean insertOperationLog(TOperationLog tOperationLog) {
        tOperationLog.setCreateTime(LocalDateTime.now());
wzp's avatar
wzp committed
148 149 150 151 152 153 154
        boolean b = false;
        try {
            b = operationLogService.save(tOperationLog);
            return b;
        } catch (Exception e) {
            e.printStackTrace();
        }
wzp's avatar
wzp committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
        return b;
    }

    /**
     * 查询运维日志
     */
    @ApiOperation(value = "查询运维日志", notes = "查询运维日志")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "userName", value = "运维账号", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startDate", value = "创建时间-开始", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "创建时间-结束", paramType = "query", dataType = "String")
    })
    @GetMapping(value = "/OperationLog")
    @RequiresPermissions("/sysLog/OperationLog")
wzp's avatar
wzp committed
171
    public Map<String, Object> OperationLog(TOperationLog operationLog) {
wzp's avatar
wzp committed
172 173
        try {
            Page<TOperationLog> page = operationLogService.pageList(getPage(), operationLog);
wzp's avatar
wzp committed
174
            return getResult(page);
wzp's avatar
wzp committed
175 176 177
        } catch (Exception e) {
            logger.error("查询系统日志列表出错!", e);
        }
wzp's avatar
wzp committed
178
        return getFailResult();
wzp's avatar
wzp committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    }

    /**
     * 查询机顶盒日志
     */
    @ApiOperation(value = "查询机顶盒日志", notes = "查询机顶盒日志")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "nameOrCode", value = "名称或编码", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startDate", value = "创建时间-开始", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "创建时间-结束", paramType = "query", dataType = "String")
    })
    @GetMapping(value = "/runLogList")
    @RequiresPermissions("/sysLog/runLogList")
wzp's avatar
wzp committed
194
    public Map<String, Object> runLogList(RunLog runLog) {
wzp's avatar
wzp committed
195 196
        try {
            Page<RunLog> page = runLogService.pageList(getPage(), runLog);
wzp's avatar
wzp committed
197
            return getResult(page);
wzp's avatar
wzp committed
198 199 200
        } catch (Exception e) {
            logger.error("查询系统日志列表出错!", e);
        }
wzp's avatar
wzp committed
201
        return getFailResult();
wzp's avatar
wzp committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
    }


    /**
     * 返回日志操作类型
     * @param
     * @return
     */
    @PostMapping("/getOperationType")
    @RequiresPermissions("/sysLog/getOperationType")
    @ApiOperation(value = "返回日志操作类型", notes = "返回日志操作类型")
    public Map<String, Object> getTInteractionPageList() {
        OperType[] values = OperType.values();
        ArrayList<String> list = new ArrayList<>();
        for (OperType value : values) {
            list.add(value.getMsg());
        }
        return getResult(list);
    }

liqin's avatar
liqin committed
222 223
}