Commit 2aaca61da5aaecac72e0c930f56d9c58b563c573

Authored by 云中非
1 parent 63acf7d8

fix: 日志管理过滤字段完善

... ... @@ -7,8 +7,8 @@ import lombok.RequiredArgsConstructor;
7 7 import org.apache.commons.lang3.StringUtils;
8 8 import org.springframework.security.access.prepost.PreAuthorize;
9 9 import org.springframework.web.bind.annotation.*;
  10 +import org.thingsboard.server.common.data.EntityType;
10 11 import org.thingsboard.server.common.data.audit.ActionType;
11   -import org.thingsboard.server.common.data.audit.AuditLog;
12 12 import org.thingsboard.server.common.data.exception.ThingsboardException;
13 13 import org.thingsboard.server.common.data.yunteng.dto.SysLogDTO;
14 14 import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum;
... ... @@ -36,72 +36,76 @@ public class YtSyslogController extends BaseController {
36 36 return logService.detail(entityId);
37 37 }
38 38
39   - @GetMapping(value="exception",params = {PAGE_SIZE, PAGE})
  39 + @GetMapping(value = "exception", params = {PAGE_SIZE, PAGE})
40 40 @ApiOperation("异常日志列表")
41 41 @PreAuthorize("@check.checkPermissions({},{})")
42 42 public YtPageData<SysLogDTO> pageExceptions(
43 43 @RequestParam(PAGE_SIZE) int pageSize,
44 44 @RequestParam(PAGE) int page,
  45 + @RequestParam(value = "startTime", required = false) Long startTime,
  46 + @RequestParam(value = "endTime", required = false) Long endTime,
45 47 @RequestParam(value = "actionType", required = false) ActionType actionType,
46 48 @RequestParam(value = ORDER_FILED, required = false) String orderBy,
47 49 @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
48 50 throws ThingsboardException {
49 51
50 52
51   - if(StringUtils.isEmpty(orderBy)){
  53 + if (StringUtils.isEmpty(orderBy)) {
52 54 orderBy = ModelConstants.CREATED_TIME_PROPERTY;
53 55 }
54 56 IPage<SysLogEntity> pageInfrom = logService.getPage(page, pageSize, orderBy, orderType);
55   - return logService.exceptionPage(pageInfrom, null,null
56   - ,getCurrentUser().isPtTenantAdmin()?getCurrentUser().getCurrentTenantId():null
57   - ,getCurrentUser().isCustomerUser()?getCurrentUser().getCurrentUserId():null
58   - ,actionType);
  57 + return logService.exceptionPage(pageInfrom, startTime, endTime
  58 + , getCurrentUser().isPtTenantAdmin() ? getCurrentUser().getCurrentTenantId() : null
  59 + , getCurrentUser().isCustomerUser() ? getCurrentUser().getCurrentUserId() : null
  60 + , actionType);
59 61 }
60 62
61   - @GetMapping(value="operate",params = {PAGE_SIZE, PAGE})
  63 + @GetMapping(value = "operate", params = {PAGE_SIZE, PAGE})
62 64 @ApiOperation("操作日志列表")
63 65 @PreAuthorize("@check.checkPermissions({},{})")
64 66 public YtPageData<SysLogDTO> pageOperate(
65 67 @RequestParam(PAGE_SIZE) int pageSize,
66 68 @RequestParam(PAGE) int page,
  69 + @RequestParam(value = "startTime", required = false) Long startTime,
  70 + @RequestParam(value = "endTime", required = false) Long endTime,
  71 + @RequestParam(value = "entityType", required = false) EntityType entityType,
67 72 @RequestParam(value = "actionType", required = false) ActionType actionType,
68 73 @RequestParam(value = ORDER_FILED, required = false) String orderBy,
69 74 @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
70 75 throws ThingsboardException {
71   - if(StringUtils.isEmpty(orderBy)){
  76 + if (StringUtils.isEmpty(orderBy)) {
72 77 orderBy = ModelConstants.CREATED_TIME_PROPERTY;
73 78 }
74 79 IPage<SysLogEntity> pageInfrom = logService.getPage(page, pageSize, orderBy, orderType);
75   - return logService.operatePage(pageInfrom, null,null
76   - ,getCurrentUser().isPtTenantAdmin()?getCurrentUser().getCurrentTenantId():null
77   - ,getCurrentUser().isCustomerUser()?getCurrentUser().getCurrentUserId():null
78   - ,actionType);
  80 + return logService.operatePage(pageInfrom, startTime, endTime
  81 + , getCurrentUser().isPtTenantAdmin() ? getCurrentUser().getCurrentTenantId() : null
  82 + , getCurrentUser().isCustomerUser() ? getCurrentUser().getCurrentUserId() : null
  83 + , entityType, actionType);
79 84 }
80 85
81   - @GetMapping(value="user",params = {PAGE_SIZE, PAGE})
  86 + @GetMapping(value = "user", params = {PAGE_SIZE, PAGE})
82 87 @ApiOperation("登录登出列表")
83 88 @PreAuthorize("@check.checkPermissions({},{})")
84 89 public YtPageData<SysLogDTO> pageLogin(
85 90 @RequestParam(PAGE_SIZE) int pageSize,
86 91 @RequestParam(PAGE) int page,
  92 + @RequestParam(value = "startTime", required = false) Long startTime,
  93 + @RequestParam(value = "endTime", required = false) Long endTime,
87 94 @RequestParam(value = "actionType", required = false) ActionType actionType,
88 95 @RequestParam(value = ORDER_FILED, required = false) String orderBy,
89 96 @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
90 97 throws ThingsboardException {
91 98
92 99
93   - if(StringUtils.isEmpty(orderBy)){
  100 + if (StringUtils.isEmpty(orderBy)) {
94 101 orderBy = ModelConstants.CREATED_TIME_PROPERTY;
95 102 }
96 103 IPage<SysLogEntity> pageInfrom = logService.getPage(page, pageSize, orderBy, orderType);
97   - return logService.loginPage(pageInfrom, null,null
98   - ,getCurrentUser().isPtTenantAdmin()?getCurrentUser().getCurrentTenantId():null
99   - ,getCurrentUser().isCustomerUser()?getCurrentUser().getCurrentUserId():null
100   - ,actionType);
  104 + return logService.loginPage(pageInfrom, startTime, endTime
  105 + , getCurrentUser().isPtTenantAdmin() ? getCurrentUser().getCurrentTenantId() : null
  106 + , getCurrentUser().isCustomerUser() ? getCurrentUser().getCurrentUserId() : null
  107 + , actionType);
101 108 }
102 109
103 110
104   -
105   -
106   -
107 111 }
... ...
1 1 /**
2 2 * Copyright © 2016-2021 The Thingsboard Authors
3   - *
  3 + * <p>
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
6 6 * You may obtain a copy of the License at
7   - *
8   - * http://www.apache.org/licenses/LICENSE-2.0
9   - *
  7 + * <p>
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + * <p>
10 10 * Unless required by applicable law or agreed to in writing, software
11 11 * distributed under the License is distributed on an "AS IS" BASIS,
12 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.common.data.yunteng.dto;
17 17
18 18
19 19 import com.fasterxml.jackson.databind.JsonNode;
  20 +import io.swagger.annotations.ApiModelProperty;
20 21 import lombok.Data;
21 22 import lombok.EqualsAndHashCode;
22 23 import org.thingsboard.server.common.data.EntityType;
... ... @@ -30,31 +31,38 @@ import java.util.UUID;
30 31 @Data
31 32 public class SysLogDTO extends BaseDTO {
32 33
33   -
  34 + @ApiModelProperty(value = "操作时间")
34 35 private long createdTime;
35 36
36   - private EntityType entityType;
37 37
38 38 private UUID tenantId;
  39 + @ApiModelProperty(value = "租户名称")
39 40 private String tenantName;
40 41
41 42 private UUID customerId;
  43 + @ApiModelProperty(value = "客户名称")
42 44 private String customerName;
43 45
  46 + @ApiModelProperty(value = "资源类型")
  47 + private EntityType entityType;
44 48 private UUID entityId;
  49 + @ApiModelProperty(value = "资源名称")
45 50 private String entityName;
46 51
47 52 private UUID userId;
  53 + @ApiModelProperty(value = "操作人员")
48 54 private String userName;
49 55
50   -
  56 + @ApiModelProperty(value = "操作类型")
51 57 private ActionType actionType;
52 58
  59 + @ApiModelProperty(value = "操作数据")
53 60 private JsonNode actionData;
54 61
  62 + @ApiModelProperty(value = "操作状态")
55 63 private ActionStatus actionStatus;
56 64
57   -
  65 + @ApiModelProperty(value = "失败信息")
58 66 private String actionFailureDetails;
59 67
60 68
... ...
1 1 package org.thingsboard.server.dao.yunteng.impl;
2 2
3   -import com.baomidou.mybatisplus.core.conditions.Wrapper;
4   -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
5   -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
6 3 import com.baomidou.mybatisplus.core.metadata.IPage;
7 4 import lombok.RequiredArgsConstructor;
8 5 import lombok.extern.slf4j.Slf4j;
9 6 import org.springframework.stereotype.Service;
10 7 import org.thingsboard.server.common.data.EntityType;
11   -import org.thingsboard.server.common.data.StringUtils;
12 8 import org.thingsboard.server.common.data.audit.ActionType;
13   -import org.thingsboard.server.common.data.audit.AuditLog;
14 9 import org.thingsboard.server.common.data.yunteng.dto.SysLogDTO;
15   -import org.thingsboard.server.common.data.yunteng.dto.YtOpinionDTO;
16 10 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
17 11 import org.thingsboard.server.dao.yunteng.entities.SysLogEntity;
18   -import org.thingsboard.server.dao.yunteng.entities.YtOpinionEntity;
19 12 import org.thingsboard.server.dao.yunteng.mapper.YtSysLogMapper;
20 13 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
21 14 import org.thingsboard.server.dao.yunteng.service.YtSysLogService;
22 15
23 16 import java.util.ArrayList;
24 17 import java.util.List;
25   -import java.util.UUID;
26 18
27 19 @Slf4j
28 20 @Service
... ... @@ -39,26 +31,26 @@ public class YtSysLogServiceImpl extends AbstractBaseService<YtSysLogMapper, Sys
39 31 @Override
40 32 public YtPageData<SysLogDTO> exceptionPage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, ActionType actionType) {
41 33 IPage<SysLogDTO> page =
42   - baseMapper.getPageDatasMatched(pageInfrom, tenantId,customerId,startTime,endTime,EntityType.RUNNING_EXCEPTION,actionType);
  34 + baseMapper.getPageDatasMatched(pageInfrom, tenantId, customerId, startTime, endTime, EntityType.RUNNING_EXCEPTION, actionType);
43 35 return getPageData(page, SysLogDTO.class);
44 36 }
45 37
46 38
47 39 @Override
48   - public YtPageData<SysLogDTO> operatePage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, ActionType actionType) {
  40 + public YtPageData<SysLogDTO> operatePage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, EntityType entityType, ActionType actionType) {
49 41 List<EntityType> entityTypes = new ArrayList<>();
50 42 entityTypes.add(EntityType.RUNNING_EXCEPTION);
51 43 entityTypes.add(EntityType.USER);
52 44
53 45 IPage<SysLogDTO> page =
54   - baseMapper.getPageDatasNot(pageInfrom, tenantId,customerId,startTime,endTime,actionType, entityTypes);
  46 + baseMapper.getPageDatasNot(pageInfrom, tenantId, customerId, startTime, endTime, entityType, actionType, entityTypes);
55 47 return getPageData(page, SysLogDTO.class);
56 48 }
57 49
58 50 @Override
59 51 public YtPageData<SysLogDTO> loginPage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, ActionType actionType) {
60 52 IPage<SysLogDTO> page =
61   - baseMapper.getPageDatasMatched(pageInfrom, tenantId,customerId,startTime,endTime,EntityType.USER,actionType);
  53 + baseMapper.getPageDatasMatched(pageInfrom, tenantId, customerId, startTime, endTime, EntityType.USER, actionType);
62 54 return getPageData(page, SysLogDTO.class);
63 55 }
64 56 }
... ...
... ... @@ -6,12 +6,8 @@ import org.apache.ibatis.annotations.Mapper;
6 6 import org.apache.ibatis.annotations.Param;
7 7 import org.thingsboard.server.common.data.EntityType;
8 8 import org.thingsboard.server.common.data.audit.ActionType;
9   -import org.thingsboard.server.common.data.audit.AuditLog;
10   -import org.thingsboard.server.common.data.rpc.RpcStatus;
11 9 import org.thingsboard.server.common.data.yunteng.dto.SysLogDTO;
12   -import org.thingsboard.server.common.data.yunteng.dto.YtRpcRecordDTO;
13 10 import org.thingsboard.server.dao.yunteng.entities.SysLogEntity;
14   -import org.thingsboard.server.dao.yunteng.entities.YtOpinionEntity;
15 11
16 12 import java.util.List;
17 13
... ... @@ -21,12 +17,11 @@ import java.util.List;
21 17 @Mapper
22 18 public interface YtSysLogMapper extends BaseMapper<SysLogEntity> {
23 19 IPage<SysLogDTO> getPageDatasMatched(IPage<?> page, @Param("tenantId") String tenantId, @Param("customerId") String customerId
24   - , @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("entityType") EntityType entityType, @Param("actionType") ActionType actionType);
25   - IPage<SysLogDTO> getPageDatasNot(IPage<?> page, @Param("tenantId") String tenantId, @Param("customerId") String customerId
26   - , @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("actionType") ActionType actionType, @Param("entityType") List<EntityType> entityType);
27   -
  20 + , @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("entityType") EntityType entityType, @Param("actionType") ActionType actionType);
28 21
  22 + IPage<SysLogDTO> getPageDatasNot(IPage<?> page, @Param("tenantId") String tenantId, @Param("customerId") String customerId
  23 + , @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("entityFilter") EntityType entityFilter, @Param("actionType") ActionType actionType, @Param("entityType") List<EntityType> entityType);
29 24
30 25
31   - SysLogDTO detailById( @Param("entityId") String entityId);
  26 + SysLogDTO detailById(@Param("entityId") String entityId);
32 27 }
... ...
1 1 package org.thingsboard.server.dao.yunteng.service;
2 2
3 3 import com.baomidou.mybatisplus.core.metadata.IPage;
  4 +import org.thingsboard.server.common.data.EntityType;
4 5 import org.thingsboard.server.common.data.audit.ActionType;
5   -import org.thingsboard.server.common.data.audit.AuditLog;
6 6 import org.thingsboard.server.common.data.yunteng.dto.SysLogDTO;
7 7 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
8 8 import org.thingsboard.server.dao.yunteng.entities.SysLogEntity;
9   -import org.thingsboard.server.dao.yunteng.entities.YtOpinionEntity;
10 9
11 10 public interface YtSysLogService extends BaseService<SysLogEntity> {
12 11
... ... @@ -43,7 +42,7 @@ public interface YtSysLogService extends BaseService<SysLogEntity> {
43 42 * @param actionType 日志类型
44 43 * @return
45 44 */
46   - YtPageData<SysLogDTO> operatePage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, ActionType actionType);
  45 + YtPageData<SysLogDTO> operatePage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, EntityType entityType, ActionType actionType);
47 46
48 47 /**
49 48 * 登录日志列表
... ...
... ... @@ -25,7 +25,7 @@
25 25
26 26 <sql id="baseColumn">
27 27 base.id, base.tenant_id, base.created_time, base.customer_id, base.entity_type, base.entity_id, base.entity_name, base.user_id, base.user_name, base.action_type, base.action_status
28   - ,ten.title tenant_name
  28 + ,ten.title tenant_name,cus.title customer_name
29 29 </sql>
30 30 <sql id="detailColumn">
31 31 <include refid="baseColumn"></include>
... ... @@ -36,6 +36,7 @@
36 36 SELECT <include refid="baseColumn"/>
37 37 FROM audit_log base
38 38 LEFT JOIN tenant ten ON base.tenant_id = ten.id
  39 + LEFT JOIN customer cus ON base.customer_id = cus.id
39 40 <where>
40 41 base.entity_type = #{entityType}
41 42 <if test="tenantId !=null and tenantId !=''">
... ... @@ -61,12 +62,16 @@
61 62 SELECT <include refid="baseColumn"/>
62 63 FROM audit_log base
63 64 LEFT JOIN tenant ten ON base.tenant_id = ten.id
  65 + LEFT JOIN customer cus ON base.customer_id = cus.id
64 66 <where>
65 67 base.entity_type
66 68 NOT IN
67 69 <foreach collection="entityType" item="item" open="(" separator="," close=")">
68 70 #{item}
69 71 </foreach>
  72 + <if test="entityFilter !=null">
  73 + AND base.entity_type = #{entityFilter}
  74 + </if>
70 75 <if test="tenantId !=null and tenantId !=''">
71 76 AND base.tenant_id = #{tenantId}::uuid
72 77 </if>
... ... @@ -89,6 +94,7 @@
89 94 SELECT <include refid="detailColumn"/>
90 95 FROM audit_log base
91 96 LEFT JOIN tenant ten ON base.tenant_id = ten.id
  97 + LEFT JOIN customer cus ON base.customer_id = cus.id
92 98 <where>
93 99 base.id = #{entityId}::uuid
94 100
... ...