From bc507a4754773d724908b9c97840777fa58b9891 Mon Sep 17 00:00:00 2001 From: 2447007062 <2447007062@qq.com> Date: Wed, 13 May 2020 22:51:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=B3=BB=E7=BB=9F=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/biz/bo/systemlog/AccessLogBO.java | 41 ++++++++++++++ .../convert/systemlog/SystemLogConvert.java | 8 +++ .../biz/dao/system/AccessLogMapper.java | 18 ++++-- .../biz/dto/system/AccessLogPageDTO.java | 33 +++++++++++ .../service/systemlog/SystemLogService.java | 5 ++ .../systemlog/SystemLogServiceImpl.java | 11 ++++ .../systemlog/SystemLogController.java | 55 +++++++++++++++++++ .../convert/systemlog/AccessLogConvert.java | 27 +++++++++ .../systemlog/AccessLogPageResponse.java | 53 ++++++++++++++++++ 9 files changed, 247 insertions(+), 4 deletions(-) create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/systemlog/AccessLogBO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/system/AccessLogPageDTO.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/systemlog/SystemLogController.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/systemlog/AccessLogConvert.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/systemlog/AccessLogPageResponse.java diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/systemlog/AccessLogBO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/systemlog/AccessLogBO.java new file mode 100644 index 000000000..c423596f5 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/systemlog/AccessLogBO.java @@ -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 20:43:00 + */ +@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; +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/systemlog/SystemLogConvert.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/systemlog/SystemLogConvert.java index bcd750a9d..6c6aa8bb5 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/systemlog/SystemLogConvert.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/systemlog/SystemLogConvert.java @@ -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 convertPage(IPage page); + + AccessLogBO convert(AccessLogDO bean); } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/system/AccessLogMapper.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/system/AccessLogMapper.java index e73c8a8b4..1b627e6d8 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/system/AccessLogMapper.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/system/AccessLogMapper.java @@ -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 20:43:00 + */ @Repository public interface AccessLogMapper extends BaseMapper { -// default IPage selectPage(AccessLogPageDTO accessLogPageDTO) { -// return selectPage(new Page<>(accessLogPageDTO.getPageNo(), accessLogPageDTO.getPageSize()), -// new QueryWrapperX().eqIfPresent("user_id", accessLogPageDTO.getUserId())); -// } + default IPage selectPage(AccessLogPageDTO accessLogPageDTO) { + return selectPage(new Page<>(accessLogPageDTO.getPageNo(), accessLogPageDTO.getPageSize()), + new QueryWrapperX().eqIfPresent("account_id", accessLogPageDTO.getAccountId())); + } } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/system/AccessLogPageDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/system/AccessLogPageDTO.java new file mode 100644 index 000000000..4af88b553 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/system/AccessLogPageDTO.java @@ -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; +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/systemlog/SystemLogService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/systemlog/SystemLogService.java index 3a7fc0a2b..887d590ea 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/systemlog/SystemLogService.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/systemlog/SystemLogService.java @@ -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 getAccessLogPage(AccessLogPageDTO accessLogPageDTO); + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/systemlog/SystemLogServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/systemlog/SystemLogServiceImpl.java index 436d7592b..85c86f71d 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/systemlog/SystemLogServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/systemlog/SystemLogServiceImpl.java @@ -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 getAccessLogPage(AccessLogPageDTO accessLogPageDTO) { + PageResult accessLogPageBOPageResult = SystemLogConvert.INSTANCE.convertPage( + accessLogMapper.selectPage(accessLogPageDTO)); + return accessLogPageBOPageResult; + } } diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/systemlog/SystemLogController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/systemlog/SystemLogController.java new file mode 100644 index 000000000..5f7a1d471 --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/systemlog/SystemLogController.java @@ -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> 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 result = systemLogService.getAccessLogPage(accessLogPageDTO); + // 转换结果 + return CommonResult.success(AccessLogConvert.INSTANCE.convert(result)); + + } + + +} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/systemlog/AccessLogConvert.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/systemlog/AccessLogConvert.java new file mode 100644 index 000000000..a07b36c4e --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/systemlog/AccessLogConvert.java @@ -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 convert(PageResult result); + + + +} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/systemlog/AccessLogPageResponse.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/systemlog/AccessLogPageResponse.java new file mode 100644 index 000000000..83f5c2368 --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/systemlog/AccessLogPageResponse.java @@ -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; + +}