ApiController.java 2.08 KB
package com.uccc.log.controller;

import com.alibaba.fastjson.JSONObject;
import com.uccc.log.service.LogService;
import com.uccc.pretty.common.Result;
import com.uccc.pretty.common.SystemLogEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.uccc.pretty.constants.ResultEnum.RESULT_OK;

/**
 * Created by bert on 2021-09-28 10:05
 */

@RestController
@RequestMapping("/sys_log/")
public class ApiController {
    private Logger logger = LoggerFactory.getLogger(ApiController.class);
    @Autowired
    private LogService logService;

    @RequestMapping(value = "log_list",method = RequestMethod.GET)
    public Result sysLogList (@RequestParam(name = "limit") Integer limit,
                              @RequestParam(name = "page") Integer page,
                              @RequestParam(name = "operator", required = false) Long operator,
                              @RequestParam(name = "action", required = false) String action,
                              @RequestParam(name = "ip", required = false) String ip,
                              @RequestParam(name = "time", required = false) String[] time
                              ) throws NullPointerException{
        Result result = new Result();
        List<SystemLogEntity> systemLogs = logService.getSysLogByCondition(limit,page,operator,action,ip,time);
        if (systemLogs.size() > 0) {
            int count = logService.getSysLogCountByCondition(operator,action,ip,time);
            result.setCode(RESULT_OK.getCode());
            result.setMessage(RESULT_OK.getMessage());
            JSONObject json = new JSONObject();
            json.put("count", count);
            json.put("rows", systemLogs);
            result.setData(json);
        }
        return result;
    }
}