增加系统日志查询功能

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,41 @@
package cn.iocoder.mall.system.biz.bo.systemlog;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* @author:mac
* @descriptio
* @create: 2020-5-12 204300
*/
@Data
@Accessors(chain = true)
public class AccessLogBO implements Serializable {
private String traceId;
private Integer accountId;
private String applicationName;
private String uri;
private String queryString;
private String method;
private String userAgent;
private String ip;
private Date startTime;
private Integer responseTime;
private Integer errorCode;
private String errorMessage;
}

View File

@ -1,10 +1,14 @@
package cn.iocoder.mall.system.biz.convert.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.systemlog.AccessLogBO;
import cn.iocoder.mall.system.biz.dataobject.systemlog.AccessLogDO;
import cn.iocoder.mall.system.biz.dataobject.systemlog.ExceptionLogDO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogAddDTO;
import cn.iocoder.mall.system.biz.dto.system.ExceptionLogAddDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
@ -16,4 +20,8 @@ public interface SystemLogConvert {
ExceptionLogDO convert(ExceptionLogAddDTO bean);
@Mapping(source = "records", target = "list")
PageResult<AccessLogBO> convertPage(IPage<AccessLogDO> page);
AccessLogBO convert(AccessLogDO bean);
}

View File

@ -1,15 +1,25 @@
package cn.iocoder.mall.system.biz.dao.system;
import cn.iocoder.mall.mybatis.query.QueryWrapperX;
import cn.iocoder.mall.system.biz.dataobject.systemlog.AccessLogDO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogPageDTO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Repository;
/**
* 访问日志
* @author:mac
* @descriptio
* @create: 2020-5-12 204300
*/
@Repository
public interface AccessLogMapper extends BaseMapper<AccessLogDO> {
// default IPage<AccessLogDO> selectPage(AccessLogPageDTO accessLogPageDTO) {
// return selectPage(new Page<>(accessLogPageDTO.getPageNo(), accessLogPageDTO.getPageSize()),
// new QueryWrapperX<AccessLogDO>().eqIfPresent("user_id", accessLogPageDTO.getUserId()));
// }
default IPage<AccessLogDO> selectPage(AccessLogPageDTO accessLogPageDTO) {
return selectPage(new Page<>(accessLogPageDTO.getPageNo(), accessLogPageDTO.getPageSize()),
new QueryWrapperX<AccessLogDO>().eqIfPresent("account_id", accessLogPageDTO.getAccountId()));
}
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.mall.system.biz.dto.system;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* 访问日志添加 DTO
*/
@Data
@Accessors(chain = true)
public class AccessLogPageDTO {
/**
* 账号编号
*/
private Integer accountId;
/**
* 页码 1 开始
*/
@NotNull(message = "页码不能为空")
private Integer pageNo;
/**
* 每页条数
*/
@NotNull(message = "每页条数不能为空")
private Integer pageSize;
}

View File

@ -1,6 +1,9 @@
package cn.iocoder.mall.system.biz.service.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.systemlog.AccessLogBO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogAddDTO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogPageDTO;
import cn.iocoder.mall.system.biz.dto.system.ExceptionLogAddDTO;
public interface SystemLogService {
@ -9,4 +12,6 @@ public interface SystemLogService {
void addExceptionLog(ExceptionLogAddDTO exceptionLogAddDTO);
PageResult<AccessLogBO> getAccessLogPage(AccessLogPageDTO accessLogPageDTO);
}

View File

@ -1,11 +1,14 @@
package cn.iocoder.mall.system.biz.service.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.systemlog.AccessLogBO;
import cn.iocoder.mall.system.biz.convert.systemlog.SystemLogConvert;
import cn.iocoder.mall.system.biz.dao.system.AccessLogMapper;
import cn.iocoder.mall.system.biz.dao.system.ExceptionLogMapper;
import cn.iocoder.mall.system.biz.dataobject.systemlog.AccessLogDO;
import cn.iocoder.mall.system.biz.dataobject.systemlog.ExceptionLogDO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogAddDTO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogPageDTO;
import cn.iocoder.mall.system.biz.dto.system.ExceptionLogAddDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -40,4 +43,12 @@ public class SystemLogServiceImpl implements SystemLogService {
exceptionLogMapper.insert(logDO);
}
@Override
@SuppressWarnings("Duplicates")
public PageResult<AccessLogBO> getAccessLogPage(AccessLogPageDTO accessLogPageDTO) {
PageResult<AccessLogBO> accessLogPageBOPageResult = SystemLogConvert.INSTANCE.convertPage(
accessLogMapper.selectPage(accessLogPageDTO));
return accessLogPageBOPageResult;
}
}

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;
}