增加系统日志查询功能

This commit is contained in:
2447007062
2020-05-13 22:51:06 +08:00
parent 03857426aa
commit bc507a4754
9 changed files with 247 additions and 4 deletions

View File

@@ -0,0 +1,55 @@
package cn.iocoder.mall.system.rest.controller.systemlog;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.systemlog.AccessLogBO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogPageDTO;
import cn.iocoder.mall.system.biz.service.systemlog.SystemLogService;
import cn.iocoder.mall.system.rest.convert.systemlog.AccessLogConvert;
import cn.iocoder.mall.system.rest.response.systemlog.AccessLogPageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author:ycjx
* @descriptio
* @create:2019-06-23 16:42
*/
@RestController
@RequestMapping("admins/system/logs")
@Api("系统日志")
public class SystemLogController {
@Autowired
private SystemLogService systemLogService;
@GetMapping("/access/page")
@ApiOperation(value = "访问日志分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", example = "1"),
@ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
})
public CommonResult<PageResult<AccessLogPageResponse>> page(@RequestParam(value = "accountId", required = false) Integer accountId,
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
AccessLogPageDTO accessLogPageDTO = new AccessLogPageDTO().setAccountId(accountId)
.setPageNo(pageNo).setPageSize(pageSize);
// 查询分页
PageResult<AccessLogBO> result = systemLogService.getAccessLogPage(accessLogPageDTO);
// 转换结果
return CommonResult.success(AccessLogConvert.INSTANCE.convert(result));
}
}

View File

@@ -0,0 +1,27 @@
package cn.iocoder.mall.system.rest.convert.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.systemlog.AccessLogBO;
import cn.iocoder.mall.system.rest.response.systemlog.AccessLogPageResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
/**
* @author:ycjx
* @descriptio
* @create:2019-06-23 17:36
*/
@Mapper
public interface AccessLogConvert {
AccessLogConvert INSTANCE = Mappers.getMapper(AccessLogConvert.class);
@Mappings({})
PageResult<AccessLogPageResponse> convert(PageResult<AccessLogBO> result);
}

View File

@@ -0,0 +1,53 @@
package cn.iocoder.mall.system.rest.response.systemlog;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* @author mxc
* @date 2020/5/11 22:11
*/
@ApiModel("访问日志 VO")
@Data
@Accessors(chain = true)
public class AccessLogPageResponse {
@ApiModelProperty(value = "链路追踪编号", required = true, example = "1")
private String traceId;
@ApiModelProperty(value = "账号编号", required = true, example = "1")
private Integer accountId;;
@ApiModelProperty(value = "应用名", required = true, example = "1")
private String applicationName;
@ApiModelProperty(value = "访问地址", required = true, example = "1")
private String uri;
@ApiModelProperty(value = "请求参数", required = true, example = "1")
private String queryString;
@ApiModelProperty(value = "http 请求方法", required = true, example = "1")
private String method;
@ApiModelProperty(value = "User-Agent ", required = true, example = "1")
private String userAgent;
@ApiModelProperty(value = "ip", required = true, example = "1")
private String ip;
@ApiModelProperty(value = "请求时间", required = true, example = "1")
private Date startTime;
@ApiModelProperty(value = "响应时长", required = true, example = "1")
private Integer responseTime;
@ApiModelProperty(value = "错误码", required = true, example = "1")
private Integer errorCode;
}