From 9e5e460b282066261f0c54b04e2d3c1bf6214d2e Mon Sep 17 00:00:00 2001 From: ycjx <897804105@qq.com> Date: Sun, 23 Jun 2019 18:33:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AE=BF=E9=97=AE=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/SystemLogController.java | 56 ++++++++++++++++++ .../application/convert/AccessLogConvert.java | 36 ++++++++++++ .../application/vo/log/AccessLogPageVo.java | 25 ++++++++ .../admin/application/vo/log/AccessLogVo.java | 58 +++++++++++++++++++ .../mall/admin/api/SystemLogService.java | 4 ++ .../admin/api/bo/systemlog/AccessLogBO.java | 41 +++++++++++++ .../api/bo/systemlog/AccessLogPageBO.java | 27 +++++++++ .../api/dto/systemlog/AccessLogPageDTO.java | 28 +++++++++ .../mall/admin/convert/AccessLogConvert.java | 10 ++++ .../mall/admin/dao/AccessLogMapper.java | 11 ++++ .../admin/service/SystemLogServiceImpl.java | 15 +++++ .../service/SystemLogServiceImplTest.java | 35 +++++++++++ 12 files changed, 346 insertions(+) create mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/SystemLogController.java create mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AccessLogConvert.java create mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/log/AccessLogPageVo.java create mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/log/AccessLogVo.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/systemlog/AccessLogBO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/systemlog/AccessLogPageBO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/AccessLogPageDTO.java create mode 100644 system/system-service-impl/src/test/java/cn/iocoder/mall/admin/service/SystemLogServiceImplTest.java diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/SystemLogController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/SystemLogController.java new file mode 100644 index 000000000..c2b67e7b3 --- /dev/null +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/SystemLogController.java @@ -0,0 +1,56 @@ +package cn.iocoder.mall.admin.application.controller.admins; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.api.SystemLogService; +import cn.iocoder.mall.admin.api.bo.systemlog.AccessLogPageBO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogPageDTO; +import cn.iocoder.mall.admin.application.convert.AccessLogConvert; +import cn.iocoder.mall.admin.application.vo.log.AccessLogPageVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.apache.dubbo.config.annotation.Reference; +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; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** + * @author:ycjx + * @descriptio + * @create:2019-06-23 16:42 + */ +@RestController +@RequestMapping("admins/system/logs") +@Api("系统日志") +public class SystemLogController { + + @Reference(validation = "true", version = "${dubbo.provider.AdminAccessLogService.version}") + 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 = "userId", required = false) Integer userId, + @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + + + AccessLogPageDTO accessLogPageDTO = new AccessLogPageDTO().setUserId(userId) + .setPageNo(pageNo).setPageSize(pageSize); + // 查询分页 + AccessLogPageBO result = systemLogService.getAccessLogPage(accessLogPageDTO); + // 转换结果 + return success(AccessLogConvert.INSTANCE.convert(result)); + + } + + +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AccessLogConvert.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AccessLogConvert.java new file mode 100644 index 000000000..f48db4be4 --- /dev/null +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AccessLogConvert.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.admin.application.convert; + +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.admin.api.bo.admin.AdminBO; +import cn.iocoder.mall.admin.api.bo.systemlog.AccessLogBO; +import cn.iocoder.mall.admin.api.bo.systemlog.AccessLogPageBO; +import cn.iocoder.mall.admin.application.vo.log.AccessLogPageVo; +import cn.iocoder.mall.admin.application.vo.log.AccessLogVo; +import cn.iocoder.mall.admin.dataobject.AccessLogDO; +import cn.iocoder.mall.admin.dataobject.AdminDO; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +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({}) + AccessLogPageVo convert(AccessLogPageBO result); + + @Mappings({}) + AccessLogVo convert(AccessLogBO result); + + + +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/log/AccessLogPageVo.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/log/AccessLogPageVo.java new file mode 100644 index 000000000..872205100 --- /dev/null +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/log/AccessLogPageVo.java @@ -0,0 +1,25 @@ +package cn.iocoder.mall.admin.application.vo.log; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + * @author:ycjx + * @descriptio + * @create:2019-06-23 17:03 + */ +@ApiModel("访问日志分页 VO") +@Data +@Accessors(chain = true) +public class AccessLogPageVo { + + + @ApiModelProperty(value = "访问数据") + private List list; + @ApiModelProperty(value = "访问总数") + private Integer total; +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/log/AccessLogVo.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/log/AccessLogVo.java new file mode 100644 index 000000000..146ba23c1 --- /dev/null +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/log/AccessLogVo.java @@ -0,0 +1,58 @@ +package cn.iocoder.mall.admin.application.vo.log; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +/** + * @author:yuxj + * @descriptio + * @create:2019-06-23 17:04 + */ + +@ApiModel("访问日志 VO") +@Data +@Accessors(chain = true) +public class AccessLogVo { + + + @ApiModelProperty(value = "链路追踪编号", required = true, example = "1") + private String traceId; + + @ApiModelProperty(value = "用户编号", required = true, example = "1") + private Integer userId; + + @ApiModelProperty(value = "用户类型", required = true, example = "1") + private Integer userType; + + @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; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SystemLogService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SystemLogService.java index f39fbfc4f..fb57da530 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SystemLogService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SystemLogService.java @@ -1,6 +1,9 @@ package cn.iocoder.mall.admin.api; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.admin.api.bo.systemlog.AccessLogPageBO; import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogPageDTO; import cn.iocoder.mall.admin.api.dto.systemlog.ExceptionLogAddDTO; /** @@ -14,4 +17,5 @@ public interface SystemLogService { void addExceptionLog(ExceptionLogAddDTO exceptionLogAddDTO); + AccessLogPageBO getAccessLogPage(AccessLogPageDTO accessLogPageDTO); } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/systemlog/AccessLogBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/systemlog/AccessLogBO.java new file mode 100644 index 000000000..2a68864af --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/systemlog/AccessLogBO.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.admin.api.bo.systemlog; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author:ycjx + * @descriptio + * @create:2019-06-23 17:26 + */ +@Data +@Accessors(chain = true) +public class AccessLogBO implements Serializable { + + private String traceId; + + private Integer userId; + + private Integer userType; + + 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; +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/systemlog/AccessLogPageBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/systemlog/AccessLogPageBO.java new file mode 100644 index 000000000..92c0a46c5 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/systemlog/AccessLogPageBO.java @@ -0,0 +1,27 @@ +package cn.iocoder.mall.admin.api.bo.systemlog; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.List; + +/** + * @author:ycjx + * @descriptio + * @create:2019-06-23 17:26 + */ +@Data +@Accessors(chain = true) +public class AccessLogPageBO implements Serializable { + + /** + * 日志数组 + */ + private List list; + /** + * 总量 + */ + private Integer total; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/AccessLogPageDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/AccessLogPageDTO.java new file mode 100644 index 000000000..c4047da63 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/AccessLogPageDTO.java @@ -0,0 +1,28 @@ +package cn.iocoder.mall.admin.api.dto.systemlog; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; + +/** + * @author:ycjx + * @descriptio + * @create:2019-06-23 16:53 + */ +@Data +@Accessors(chain = true) +public class AccessLogPageDTO { + + + /** + * 用户id + */ + private Integer userId; + + @NotNull(message = "页码不能为空") + private Integer pageNo; + @NotNull(message = "每页条数不能为空") + private Integer pageSize; + +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AccessLogConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AccessLogConvert.java index 7dcdd4c90..ef62fc71c 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AccessLogConvert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AccessLogConvert.java @@ -1,10 +1,15 @@ package cn.iocoder.mall.admin.convert; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.admin.api.bo.systemlog.AccessLogBO; +import cn.iocoder.mall.admin.api.bo.systemlog.AccessLogPageBO; import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; import cn.iocoder.mall.admin.api.dto.systemlog.ExceptionLogAddDTO; import cn.iocoder.mall.admin.dataobject.AccessLogDO; import cn.iocoder.mall.admin.dataobject.ExceptionLogDO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -19,4 +24,9 @@ public interface AccessLogConvert { @Mappings({}) ExceptionLogDO convert(ExceptionLogAddDTO exceptionLogAddDTO); + @Mappings({ + @Mapping(source = "records", target = "list"), + }) + PageResult convert(IPage page); + } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AccessLogMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AccessLogMapper.java index f7c19272f..6d21d7a6d 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AccessLogMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AccessLogMapper.java @@ -1,10 +1,21 @@ package cn.iocoder.mall.admin.dao; +import cn.iocoder.common.framework.mybatis.QueryWrapperX; +import cn.iocoder.mall.admin.api.dto.admin.AdminPageDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogPageDTO; import cn.iocoder.mall.admin.dataobject.AccessLogDO; +import cn.iocoder.mall.admin.dataobject.AdminDO; 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; @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())); + } + } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SystemLogServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SystemLogServiceImpl.java index e21525a54..8ae00b41a 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SystemLogServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SystemLogServiceImpl.java @@ -1,8 +1,12 @@ package cn.iocoder.mall.admin.service; import cn.iocoder.common.framework.util.StringUtil; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.admin.api.SystemLogService; +import cn.iocoder.mall.admin.api.bo.systemlog.AccessLogBO; +import cn.iocoder.mall.admin.api.bo.systemlog.AccessLogPageBO; import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogPageDTO; import cn.iocoder.mall.admin.api.dto.systemlog.ExceptionLogAddDTO; import cn.iocoder.mall.admin.convert.AccessLogConvert; import cn.iocoder.mall.admin.dao.AccessLogMapper; @@ -76,4 +80,15 @@ public class SystemLogServiceImpl implements SystemLogService { exceptionLogMapper.insert(exceptionLog); } + @Override + @SuppressWarnings("Duplicates") + public AccessLogPageBO getAccessLogPage(AccessLogPageDTO accessLogPageDTO) { + AccessLogPageBO accessLogPageBO = new AccessLogPageBO(); + PageResult accessLogPageBOPageResult = AccessLogConvert.INSTANCE.convert( + accessLogMapper.selectPage(accessLogPageDTO)); + accessLogPageBO.setList(accessLogPageBOPageResult.getList()); + accessLogPageBO.setTotal(accessLogPageBOPageResult.getTotal()); + return accessLogPageBO; + } + } diff --git a/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/service/SystemLogServiceImplTest.java b/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/service/SystemLogServiceImplTest.java new file mode 100644 index 000000000..a4b34a207 --- /dev/null +++ b/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/service/SystemLogServiceImplTest.java @@ -0,0 +1,35 @@ +package cn.iocoder.mall.admin.service; + +import cn.iocoder.mall.admin.api.SystemLogService; +import cn.iocoder.mall.admin.api.bo.systemlog.AccessLogPageBO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogPageDTO; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author:ycjx + * @descriptio + * @create:2019-06-23 18:08 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SystemLogServiceImplTest.class) +public class SystemLogServiceImplTest { + + @Autowired + private SystemLogService systemLogService; + + @Test + public void getAccessLogPageTest(){ + AccessLogPageDTO accessLogPageDTO = new AccessLogPageDTO(); + accessLogPageDTO.setPageNo(1); + accessLogPageDTO.setPageSize(10); + AccessLogPageBO accessLogPage = systemLogService.getAccessLogPage(accessLogPageDTO); + System.out.println(accessLogPage.getTotal()); + + } + + +}