Commit 7c6d01940ed5f02044651b0d896ca1e69e1a0249
Merge branch '20220615' into 'master'
20220615 See merge request huang/thingsboard3.3.2!107
Showing
12 changed files
with
531 additions
and
26 deletions
@@ -331,7 +331,7 @@ public abstract class BaseController { | @@ -331,7 +331,7 @@ public abstract class BaseController { | ||
331 | } | 331 | } |
332 | 332 | ||
333 | <T> T checkNotNull(Optional<T> reference) throws ThingsboardException { | 333 | <T> T checkNotNull(Optional<T> reference) throws ThingsboardException { |
334 | - return checkNotNull(reference, "Requested item wasn't found!"); | 334 | + return checkNotNull(reference, "请求的内容不存在!"); |
335 | } | 335 | } |
336 | 336 | ||
337 | <T> T checkNotNull(Optional<T> reference, String notFoundMessage) throws ThingsboardException { | 337 | <T> T checkNotNull(Optional<T> reference, String notFoundMessage) throws ThingsboardException { |
@@ -344,13 +344,13 @@ public abstract class BaseController { | @@ -344,13 +344,13 @@ public abstract class BaseController { | ||
344 | 344 | ||
345 | void checkParameter(String name, String param) throws ThingsboardException { | 345 | void checkParameter(String name, String param) throws ThingsboardException { |
346 | if (StringUtils.isEmpty(param)) { | 346 | if (StringUtils.isEmpty(param)) { |
347 | - throw new ThingsboardException("Parameter '" + name + "' can't be empty!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); | 347 | + throw new ThingsboardException("参数【 " + name + "】不能为空!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); |
348 | } | 348 | } |
349 | } | 349 | } |
350 | 350 | ||
351 | void checkArrayParameter(String name, String[] params) throws ThingsboardException { | 351 | void checkArrayParameter(String name, String[] params) throws ThingsboardException { |
352 | if (params == null || params.length == 0) { | 352 | if (params == null || params.length == 0) { |
353 | - throw new ThingsboardException("Parameter '" + name + "' can't be empty!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); | 353 | + throw new ThingsboardException("参数【 " + name + "】不能为空!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); |
354 | } else { | 354 | } else { |
355 | for (String param : params) { | 355 | for (String param : params) { |
356 | checkParameter(name, param); | 356 | checkParameter(name, param); |
@@ -369,7 +369,7 @@ public abstract class BaseController { | @@ -369,7 +369,7 @@ public abstract class BaseController { | ||
369 | try { | 369 | try { |
370 | direction = SortOrder.Direction.valueOf(sortOrder.toUpperCase()); | 370 | direction = SortOrder.Direction.valueOf(sortOrder.toUpperCase()); |
371 | } catch (IllegalArgumentException e) { | 371 | } catch (IllegalArgumentException e) { |
372 | - throw new ThingsboardException("Unsupported sort order '" + sortOrder + "'! Only 'ASC' or 'DESC' types are allowed.", ThingsboardErrorCode.BAD_REQUEST_PARAMS); | 372 | + throw new ThingsboardException("不支持的排序规则【" + sortOrder + "】!只支持 'ASC' 或 'DESC'.", ThingsboardErrorCode.BAD_REQUEST_PARAMS); |
373 | } | 373 | } |
374 | } | 374 | } |
375 | SortOrder sort = new SortOrder(sortProperty, direction); | 375 | SortOrder sort = new SortOrder(sortProperty, direction); |
@@ -390,7 +390,7 @@ public abstract class BaseController { | @@ -390,7 +390,7 @@ public abstract class BaseController { | ||
390 | if (authentication != null && authentication.getPrincipal() instanceof SecurityUser) { | 390 | if (authentication != null && authentication.getPrincipal() instanceof SecurityUser) { |
391 | return (SecurityUser) authentication.getPrincipal(); | 391 | return (SecurityUser) authentication.getPrincipal(); |
392 | } else { | 392 | } else { |
393 | - throw new ThingsboardException("You aren't authorized to perform this operation!", ThingsboardErrorCode.AUTHENTICATION); | 393 | + throw new ThingsboardException("你没有权限执行改操作!", ThingsboardErrorCode.AUTHENTICATION); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | 396 | ||
@@ -398,7 +398,7 @@ public abstract class BaseController { | @@ -398,7 +398,7 @@ public abstract class BaseController { | ||
398 | try { | 398 | try { |
399 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | 399 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
400 | Tenant tenant = tenantService.findTenantById(tenantId); | 400 | Tenant tenant = tenantService.findTenantById(tenantId); |
401 | - checkNotNull(tenant, "Tenant with id [" + tenantId + "] is not found"); | 401 | + checkNotNull(tenant, "ID【" + tenantId + "】相关的租户不存在"); |
402 | accessControlService.checkPermission(getCurrentUser(), Resource.TENANT, operation, tenantId, tenant); | 402 | accessControlService.checkPermission(getCurrentUser(), Resource.TENANT, operation, tenantId, tenant); |
403 | return tenant; | 403 | return tenant; |
404 | } catch (Exception e) { | 404 | } catch (Exception e) { |
@@ -410,7 +410,7 @@ public abstract class BaseController { | @@ -410,7 +410,7 @@ public abstract class BaseController { | ||
410 | try { | 410 | try { |
411 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | 411 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
412 | TenantInfo tenant = tenantService.findTenantInfoById(tenantId); | 412 | TenantInfo tenant = tenantService.findTenantInfoById(tenantId); |
413 | - checkNotNull(tenant, "Tenant with id [" + tenantId + "] is not found"); | 413 | + checkNotNull(tenant, "ID【" + tenantId + "】相关的租户不存在"); |
414 | accessControlService.checkPermission(getCurrentUser(), Resource.TENANT, operation, tenantId, tenant); | 414 | accessControlService.checkPermission(getCurrentUser(), Resource.TENANT, operation, tenantId, tenant); |
415 | return tenant; | 415 | return tenant; |
416 | } catch (Exception e) { | 416 | } catch (Exception e) { |
@@ -420,9 +420,9 @@ public abstract class BaseController { | @@ -420,9 +420,9 @@ public abstract class BaseController { | ||
420 | 420 | ||
421 | TenantProfile checkTenantProfileId(TenantProfileId tenantProfileId, Operation operation) throws ThingsboardException { | 421 | TenantProfile checkTenantProfileId(TenantProfileId tenantProfileId, Operation operation) throws ThingsboardException { |
422 | try { | 422 | try { |
423 | - validateId(tenantProfileId, "Incorrect tenantProfileId " + tenantProfileId); | 423 | + validateId(tenantProfileId, "错误的租户配置ID " + tenantProfileId); |
424 | TenantProfile tenantProfile = tenantProfileService.findTenantProfileById(getTenantId(), tenantProfileId); | 424 | TenantProfile tenantProfile = tenantProfileService.findTenantProfileById(getTenantId(), tenantProfileId); |
425 | - checkNotNull(tenantProfile, "Tenant profile with id [" + tenantProfileId + "] is not found"); | 425 | + checkNotNull(tenantProfile, "ID【" + tenantProfileId + "】相关的租户配置不存在"); |
426 | accessControlService.checkPermission(getCurrentUser(), Resource.TENANT_PROFILE, operation); | 426 | accessControlService.checkPermission(getCurrentUser(), Resource.TENANT_PROFILE, operation); |
427 | return tenantProfile; | 427 | return tenantProfile; |
428 | } catch (Exception e) { | 428 | } catch (Exception e) { |
@@ -436,9 +436,9 @@ public abstract class BaseController { | @@ -436,9 +436,9 @@ public abstract class BaseController { | ||
436 | 436 | ||
437 | protected Customer checkCustomerId(CustomerId customerId, Operation operation) throws ThingsboardException { | 437 | protected Customer checkCustomerId(CustomerId customerId, Operation operation) throws ThingsboardException { |
438 | try { | 438 | try { |
439 | - validateId(customerId, "Incorrect customerId " + customerId); | 439 | + validateId(customerId, "客户ID不正确 " + customerId); |
440 | Customer customer = customerService.findCustomerById(getTenantId(), customerId); | 440 | Customer customer = customerService.findCustomerById(getTenantId(), customerId); |
441 | - checkNotNull(customer, "Customer with id [" + customerId + "] is not found"); | 441 | + checkNotNull(customer, "ID【" + customerId + "】相关的客户不存在"); |
442 | accessControlService.checkPermission(getCurrentUser(), Resource.CUSTOMER, operation, customerId, customer); | 442 | accessControlService.checkPermission(getCurrentUser(), Resource.CUSTOMER, operation, customerId, customer); |
443 | return customer; | 443 | return customer; |
444 | } catch (Exception e) { | 444 | } catch (Exception e) { |
@@ -448,9 +448,9 @@ public abstract class BaseController { | @@ -448,9 +448,9 @@ public abstract class BaseController { | ||
448 | 448 | ||
449 | protected User checkUserId(UserId userId, Operation operation) throws ThingsboardException { | 449 | protected User checkUserId(UserId userId, Operation operation) throws ThingsboardException { |
450 | try { | 450 | try { |
451 | - validateId(userId, "Incorrect userId " + userId); | 451 | + validateId(userId, "用户ID不正确 " + userId); |
452 | User user = userService.findUserById(getCurrentUser().getTenantId(), userId); | 452 | User user = userService.findUserById(getCurrentUser().getTenantId(), userId); |
453 | - checkNotNull(user, "User with id [" + userId + "] is not found"); | 453 | + checkNotNull(user, "ID【" + userId + "】相关的用户不存在"); |
454 | accessControlService.checkPermission(getCurrentUser(), Resource.USER, operation, userId, user); | 454 | accessControlService.checkPermission(getCurrentUser(), Resource.USER, operation, userId, user); |
455 | return user; | 455 | return user; |
456 | } catch (Exception e) { | 456 | } catch (Exception e) { |
@@ -470,9 +470,9 @@ public abstract class BaseController { | @@ -470,9 +470,9 @@ public abstract class BaseController { | ||
470 | protected void checkEntityId(EntityId entityId, Operation operation) throws ThingsboardException { | 470 | protected void checkEntityId(EntityId entityId, Operation operation) throws ThingsboardException { |
471 | try { | 471 | try { |
472 | if (entityId == null) { | 472 | if (entityId == null) { |
473 | - throw new ThingsboardException("Parameter entityId can't be empty!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); | 473 | + throw new ThingsboardException("参数entityId不能为空!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); |
474 | } | 474 | } |
475 | - validateId(entityId.getId(), "Incorrect entityId " + entityId); | 475 | + validateId(entityId.getId(), "entityId不正确 " + entityId); |
476 | switch (entityId.getEntityType()) { | 476 | switch (entityId.getEntityType()) { |
477 | case ALARM: | 477 | case ALARM: |
478 | checkAlarmId(new AlarmId(entityId.getId()), operation); | 478 | checkAlarmId(new AlarmId(entityId.getId()), operation); |
@@ -526,7 +526,7 @@ public abstract class BaseController { | @@ -526,7 +526,7 @@ public abstract class BaseController { | ||
526 | checkOtaPackageId(new OtaPackageId(entityId.getId()), operation); | 526 | checkOtaPackageId(new OtaPackageId(entityId.getId()), operation); |
527 | return; | 527 | return; |
528 | default: | 528 | default: |
529 | - throw new IllegalArgumentException("Unsupported entity type: " + entityId.getEntityType()); | 529 | + throw new IllegalArgumentException("不支持的资源类型: " + entityId.getEntityType()); |
530 | } | 530 | } |
531 | } catch (Exception e) { | 531 | } catch (Exception e) { |
532 | throw handleException(e, false); | 532 | throw handleException(e, false); |
@@ -535,9 +535,9 @@ public abstract class BaseController { | @@ -535,9 +535,9 @@ public abstract class BaseController { | ||
535 | 535 | ||
536 | public Device checkDeviceId(DeviceId deviceId, Operation operation) throws ThingsboardException { | 536 | public Device checkDeviceId(DeviceId deviceId, Operation operation) throws ThingsboardException { |
537 | try { | 537 | try { |
538 | - validateId(deviceId, "Incorrect deviceId " + deviceId); | 538 | + validateId(deviceId, "deviceId不正确 " + deviceId); |
539 | Device device = deviceService.findDeviceById(getCurrentUser().getTenantId(), deviceId); | 539 | Device device = deviceService.findDeviceById(getCurrentUser().getTenantId(), deviceId); |
540 | - checkNotNull(device, "Device with id [" + deviceId + "] is not found"); | 540 | + checkNotNull(device, "ID【" + deviceId + "】相关的设备不存在"); |
541 | accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, operation, deviceId, device); | 541 | accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, operation, deviceId, device); |
542 | return device; | 542 | return device; |
543 | } catch (Exception e) { | 543 | } catch (Exception e) { |
@@ -547,9 +547,9 @@ public abstract class BaseController { | @@ -547,9 +547,9 @@ public abstract class BaseController { | ||
547 | 547 | ||
548 | DeviceInfo checkDeviceInfoId(DeviceId deviceId, Operation operation) throws ThingsboardException { | 548 | DeviceInfo checkDeviceInfoId(DeviceId deviceId, Operation operation) throws ThingsboardException { |
549 | try { | 549 | try { |
550 | - validateId(deviceId, "Incorrect deviceId " + deviceId); | 550 | + validateId(deviceId, "deviceId不正确" + deviceId); |
551 | DeviceInfo device = deviceService.findDeviceInfoById(getCurrentUser().getTenantId(), deviceId); | 551 | DeviceInfo device = deviceService.findDeviceInfoById(getCurrentUser().getTenantId(), deviceId); |
552 | - checkNotNull(device, "Device with id [" + deviceId + "] is not found"); | 552 | + checkNotNull(device, "ID【" + deviceId + "】相关的设备不存在"); |
553 | accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, operation, deviceId, device); | 553 | accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, operation, deviceId, device); |
554 | return device; | 554 | return device; |
555 | } catch (Exception e) { | 555 | } catch (Exception e) { |
@@ -559,9 +559,9 @@ public abstract class BaseController { | @@ -559,9 +559,9 @@ public abstract class BaseController { | ||
559 | 559 | ||
560 | protected DeviceProfile checkDeviceProfileId(DeviceProfileId deviceProfileId, Operation operation) throws ThingsboardException { | 560 | protected DeviceProfile checkDeviceProfileId(DeviceProfileId deviceProfileId, Operation operation) throws ThingsboardException { |
561 | try { | 561 | try { |
562 | - validateId(deviceProfileId, "Incorrect deviceProfileId " + deviceProfileId); | 562 | + validateId(deviceProfileId, "设备配置Id不正确 " + deviceProfileId); |
563 | DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(getCurrentUser().getTenantId(), deviceProfileId); | 563 | DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(getCurrentUser().getTenantId(), deviceProfileId); |
564 | - checkNotNull(deviceProfile, "Device profile with id [" + deviceProfileId + "] is not found"); | 564 | + checkNotNull(deviceProfile, "ID【" + deviceProfileId + "】相关的设备配置不存在"); |
565 | accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE_PROFILE, operation, deviceProfileId, deviceProfile); | 565 | accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE_PROFILE, operation, deviceProfileId, deviceProfile); |
566 | return deviceProfile; | 566 | return deviceProfile; |
567 | } catch (Exception e) { | 567 | } catch (Exception e) { |
@@ -84,7 +84,7 @@ public class YtMenuController extends BaseController { | @@ -84,7 +84,7 @@ public class YtMenuController extends BaseController { | ||
84 | @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | 84 | @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") |
85 | public void deleteMenus(@RequestBody String[] ids) throws ThingsboardException { | 85 | public void deleteMenus(@RequestBody String[] ids) throws ThingsboardException { |
86 | if (ids.length == 0) { | 86 | if (ids.length == 0) { |
87 | - throw new YtDataValidationException("please provide menu ids to delete"); | 87 | + throw new YtDataValidationException("需要删除的菜单不能为空"); |
88 | } | 88 | } |
89 | menuService.deleteMenus(getCurrentUser().getCurrentTenantId(), ids); | 89 | menuService.deleteMenus(getCurrentUser().getCurrentTenantId(), ids); |
90 | } | 90 | } |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtSyslogController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | +import io.swagger.annotations.Api; | ||
5 | +import io.swagger.annotations.ApiOperation; | ||
6 | +import lombok.RequiredArgsConstructor; | ||
7 | +import org.apache.commons.lang3.StringUtils; | ||
8 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
9 | +import org.springframework.web.bind.annotation.*; | ||
10 | +import org.thingsboard.server.common.data.EntityType; | ||
11 | +import org.thingsboard.server.common.data.audit.ActionType; | ||
12 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
13 | +import org.thingsboard.server.common.data.yunteng.dto.SysLogDTO; | ||
14 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | ||
15 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
16 | +import org.thingsboard.server.controller.BaseController; | ||
17 | +import org.thingsboard.server.dao.model.ModelConstants; | ||
18 | +import org.thingsboard.server.dao.yunteng.entities.SysLogEntity; | ||
19 | +import org.thingsboard.server.dao.yunteng.service.YtSysLogService; | ||
20 | + | ||
21 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
22 | + | ||
23 | +@RestController | ||
24 | +@RequestMapping("api/yt/log") | ||
25 | +@Api(tags = {"日志管理"}) | ||
26 | +@RequiredArgsConstructor | ||
27 | +public class YtSyslogController extends BaseController { | ||
28 | + | ||
29 | + private final YtSysLogService logService; | ||
30 | + | ||
31 | + @GetMapping("{entityId}") | ||
32 | + @PreAuthorize("@check.checkPermissions({},{})") | ||
33 | + @ApiOperation("详情") | ||
34 | + public SysLogDTO detail(@PathVariable("entityId") String entityId) | ||
35 | + throws ThingsboardException { | ||
36 | + return logService.detail(entityId); | ||
37 | + } | ||
38 | + | ||
39 | + @GetMapping(value = "exception", params = {PAGE_SIZE, PAGE}) | ||
40 | + @ApiOperation("异常日志列表") | ||
41 | + @PreAuthorize("@check.checkPermissions({},{})") | ||
42 | + public YtPageData<SysLogDTO> pageExceptions( | ||
43 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
44 | + @RequestParam(PAGE) int page, | ||
45 | + @RequestParam(value = "startTime", required = false) Long startTime, | ||
46 | + @RequestParam(value = "endTime", required = false) Long endTime, | ||
47 | + @RequestParam(value = "actionType", required = false) ActionType actionType, | ||
48 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
49 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
50 | + throws ThingsboardException { | ||
51 | + | ||
52 | + | ||
53 | + if (StringUtils.isEmpty(orderBy)) { | ||
54 | + orderBy = ModelConstants.CREATED_TIME_PROPERTY; | ||
55 | + } | ||
56 | + IPage<SysLogEntity> pageInfrom = logService.getPage(page, pageSize, orderBy, orderType); | ||
57 | + return logService.exceptionPage(pageInfrom, startTime, endTime | ||
58 | + , getCurrentUser().isPtTenantAdmin() ? getCurrentUser().getCurrentTenantId() : null | ||
59 | + , getCurrentUser().isCustomerUser() ? getCurrentUser().getCurrentUserId() : null | ||
60 | + , actionType); | ||
61 | + } | ||
62 | + | ||
63 | + @GetMapping(value = "operate", params = {PAGE_SIZE, PAGE}) | ||
64 | + @ApiOperation("操作日志列表") | ||
65 | + @PreAuthorize("@check.checkPermissions({},{})") | ||
66 | + public YtPageData<SysLogDTO> pageOperate( | ||
67 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
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, | ||
72 | + @RequestParam(value = "actionType", required = false) ActionType actionType, | ||
73 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
74 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
75 | + throws ThingsboardException { | ||
76 | + if (StringUtils.isEmpty(orderBy)) { | ||
77 | + orderBy = ModelConstants.CREATED_TIME_PROPERTY; | ||
78 | + } | ||
79 | + IPage<SysLogEntity> pageInfrom = logService.getPage(page, pageSize, orderBy, orderType); | ||
80 | + return logService.operatePage(pageInfrom, startTime, endTime | ||
81 | + , getCurrentUser().isPtTenantAdmin() ? getCurrentUser().getCurrentTenantId() : null | ||
82 | + , getCurrentUser().isCustomerUser() ? getCurrentUser().getCurrentUserId() : null | ||
83 | + , entityType, actionType); | ||
84 | + } | ||
85 | + | ||
86 | + @GetMapping(value = "user", params = {PAGE_SIZE, PAGE}) | ||
87 | + @ApiOperation("登录登出列表") | ||
88 | + @PreAuthorize("@check.checkPermissions({},{})") | ||
89 | + public YtPageData<SysLogDTO> pageLogin( | ||
90 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
91 | + @RequestParam(PAGE) int page, | ||
92 | + @RequestParam(value = "startTime", required = false) Long startTime, | ||
93 | + @RequestParam(value = "endTime", required = false) Long endTime, | ||
94 | + @RequestParam(value = "actionType", required = false) ActionType actionType, | ||
95 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
96 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
97 | + throws ThingsboardException { | ||
98 | + | ||
99 | + | ||
100 | + if (StringUtils.isEmpty(orderBy)) { | ||
101 | + orderBy = ModelConstants.CREATED_TIME_PROPERTY; | ||
102 | + } | ||
103 | + IPage<SysLogEntity> pageInfrom = logService.getPage(page, pageSize, orderBy, orderType); | ||
104 | + return logService.loginPage(pageInfrom, startTime, endTime | ||
105 | + , getCurrentUser().isPtTenantAdmin() ? getCurrentUser().getCurrentTenantId() : null | ||
106 | + , getCurrentUser().isCustomerUser() ? getCurrentUser().getCurrentUserId() : null | ||
107 | + , actionType); | ||
108 | + } | ||
109 | + | ||
110 | + | ||
111 | +} |
@@ -150,7 +150,7 @@ public class OperateLogAspect { | @@ -150,7 +150,7 @@ public class OperateLogAspect { | ||
150 | if (authentication != null && authentication.getPrincipal() instanceof SecurityUser) { | 150 | if (authentication != null && authentication.getPrincipal() instanceof SecurityUser) { |
151 | return (SecurityUser) authentication.getPrincipal(); | 151 | return (SecurityUser) authentication.getPrincipal(); |
152 | } else { | 152 | } else { |
153 | - throw new ThingsboardException("You aren't authorized to perform this operation!", ThingsboardErrorCode.AUTHENTICATION); | 153 | + throw new ThingsboardException("你没有权限执行该操作!", ThingsboardErrorCode.AUTHENTICATION); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * <p> | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * <p> | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * <p> | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.common.data.yunteng.dto; | ||
17 | + | ||
18 | + | ||
19 | +import com.fasterxml.jackson.databind.JsonNode; | ||
20 | +import io.swagger.annotations.ApiModelProperty; | ||
21 | +import lombok.Data; | ||
22 | +import lombok.EqualsAndHashCode; | ||
23 | +import org.thingsboard.server.common.data.EntityType; | ||
24 | +import org.thingsboard.server.common.data.audit.ActionStatus; | ||
25 | +import org.thingsboard.server.common.data.audit.ActionType; | ||
26 | + | ||
27 | +import java.util.UUID; | ||
28 | + | ||
29 | + | ||
30 | +@EqualsAndHashCode(callSuper = true) | ||
31 | +@Data | ||
32 | +public class SysLogDTO extends BaseDTO { | ||
33 | + | ||
34 | + @ApiModelProperty(value = "操作时间") | ||
35 | + private long createdTime; | ||
36 | + | ||
37 | + | ||
38 | + private UUID tenantId; | ||
39 | + @ApiModelProperty(value = "租户名称") | ||
40 | + private String tenantName; | ||
41 | + | ||
42 | + private UUID customerId; | ||
43 | + @ApiModelProperty(value = "客户名称") | ||
44 | + private String customerName; | ||
45 | + | ||
46 | + @ApiModelProperty(value = "资源类型") | ||
47 | + private EntityType entityType; | ||
48 | + private UUID entityId; | ||
49 | + @ApiModelProperty(value = "资源名称") | ||
50 | + private String entityName; | ||
51 | + | ||
52 | + private UUID userId; | ||
53 | + @ApiModelProperty(value = "操作人员") | ||
54 | + private String userName; | ||
55 | + | ||
56 | + @ApiModelProperty(value = "操作类型") | ||
57 | + private ActionType actionType; | ||
58 | + | ||
59 | + @ApiModelProperty(value = "操作数据") | ||
60 | + private JsonNode actionData; | ||
61 | + | ||
62 | + @ApiModelProperty(value = "操作状态") | ||
63 | + private ActionStatus actionStatus; | ||
64 | + | ||
65 | + @ApiModelProperty(value = "失败信息") | ||
66 | + private String actionFailureDetails; | ||
67 | + | ||
68 | + | ||
69 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.dao.yunteng.entities; | ||
17 | + | ||
18 | +import com.baomidou.mybatisplus.annotation.TableField; | ||
19 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
20 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | ||
21 | +import com.fasterxml.jackson.databind.JsonNode; | ||
22 | +import lombok.Data; | ||
23 | +import lombok.EqualsAndHashCode; | ||
24 | +import org.hibernate.annotations.Type; | ||
25 | +import org.hibernate.annotations.TypeDef; | ||
26 | +import org.thingsboard.server.common.data.EntityType; | ||
27 | +import org.thingsboard.server.common.data.audit.ActionStatus; | ||
28 | +import org.thingsboard.server.common.data.audit.ActionType; | ||
29 | +import org.thingsboard.server.common.data.audit.AuditLog; | ||
30 | +import org.thingsboard.server.common.data.id.*; | ||
31 | +import org.thingsboard.server.common.data.yunteng.dto.TenantDTO; | ||
32 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
33 | +import org.thingsboard.server.dao.model.ModelConstants; | ||
34 | +import org.thingsboard.server.dao.util.mapping.JsonStringType; | ||
35 | + | ||
36 | +import javax.persistence.*; | ||
37 | +import java.util.UUID; | ||
38 | + | ||
39 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
40 | + | ||
41 | +@Data | ||
42 | +@EqualsAndHashCode(callSuper = true) | ||
43 | +@TableName(ModelConstants.AUDIT_LOG_COLUMN_FAMILY_NAME) | ||
44 | +public class SysLogEntity extends BaseEntity { | ||
45 | + | ||
46 | + | ||
47 | + private UUID tenantId; | ||
48 | + | ||
49 | + private long createdTime; | ||
50 | + private UUID customerId; | ||
51 | + | ||
52 | + private EntityType entityType; | ||
53 | + | ||
54 | + | ||
55 | + private UUID entityId; | ||
56 | + | ||
57 | + | ||
58 | + private String entityName; | ||
59 | + | ||
60 | + | ||
61 | + private UUID userId; | ||
62 | + | ||
63 | + private String userName; | ||
64 | + | ||
65 | + | ||
66 | + private ActionType actionType; | ||
67 | + | ||
68 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
69 | + private JsonNode actionData; | ||
70 | + | ||
71 | + private ActionStatus actionStatus; | ||
72 | + | ||
73 | + | ||
74 | + private String actionFailureDetails; | ||
75 | + | ||
76 | + | ||
77 | +} |
@@ -71,7 +71,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple | @@ -71,7 +71,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple | ||
71 | baseMapper.selectCount( | 71 | baseMapper.selectCount( |
72 | new QueryWrapper<Role>().lambda().ne(Role::getTenantId, tenantId).in(Role::getId, ids)); | 72 | new QueryWrapper<Role>().lambda().ne(Role::getTenantId, tenantId).in(Role::getId, ids)); |
73 | if (notTenantMenuCount > 0) { | 73 | if (notTenantMenuCount > 0) { |
74 | - throw new AccessDeniedException("cannot delete role that not create by you"); | 74 | + throw new AccessDeniedException("只能删除自己创建的角色"); |
75 | } | 75 | } |
76 | // 判断该角色下面是否有用户 | 76 | // 判断该角色下面是否有用户 |
77 | Set<String> userIds = baseMapper.checkRoleUserMappingByRoleIds(ids); | 77 | Set<String> userIds = baseMapper.checkRoleUserMappingByRoleIds(ids); |
1 | +package org.thingsboard.server.dao.yunteng.impl; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | +import lombok.RequiredArgsConstructor; | ||
5 | +import lombok.extern.slf4j.Slf4j; | ||
6 | +import org.springframework.stereotype.Service; | ||
7 | +import org.thingsboard.server.common.data.EntityType; | ||
8 | +import org.thingsboard.server.common.data.audit.ActionType; | ||
9 | +import org.thingsboard.server.common.data.yunteng.dto.SysLogDTO; | ||
10 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
11 | +import org.thingsboard.server.dao.yunteng.entities.SysLogEntity; | ||
12 | +import org.thingsboard.server.dao.yunteng.mapper.YtSysLogMapper; | ||
13 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ||
14 | +import org.thingsboard.server.dao.yunteng.service.YtSysLogService; | ||
15 | + | ||
16 | +import java.util.ArrayList; | ||
17 | +import java.util.List; | ||
18 | + | ||
19 | +@Slf4j | ||
20 | +@Service | ||
21 | +@RequiredArgsConstructor | ||
22 | +public class YtSysLogServiceImpl extends AbstractBaseService<YtSysLogMapper, SysLogEntity> | ||
23 | + implements YtSysLogService { | ||
24 | + | ||
25 | + | ||
26 | + @Override | ||
27 | + public SysLogDTO detail(String entityId) { | ||
28 | + return baseMapper.detailById(entityId); | ||
29 | + } | ||
30 | + | ||
31 | + @Override | ||
32 | + public YtPageData<SysLogDTO> exceptionPage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, ActionType actionType) { | ||
33 | + IPage<SysLogDTO> page = | ||
34 | + baseMapper.getPageDatasMatched(pageInfrom, tenantId, customerId, startTime, endTime, EntityType.RUNNING_EXCEPTION, actionType); | ||
35 | + return getPageData(page, SysLogDTO.class); | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + @Override | ||
40 | + public YtPageData<SysLogDTO> operatePage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, EntityType entityType, ActionType actionType) { | ||
41 | + List<EntityType> entityTypes = new ArrayList<>(); | ||
42 | + entityTypes.add(EntityType.RUNNING_EXCEPTION); | ||
43 | + entityTypes.add(EntityType.USER); | ||
44 | + | ||
45 | + IPage<SysLogDTO> page = | ||
46 | + baseMapper.getPageDatasNot(pageInfrom, tenantId, customerId, startTime, endTime, entityType, actionType, entityTypes); | ||
47 | + return getPageData(page, SysLogDTO.class); | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + public YtPageData<SysLogDTO> loginPage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, ActionType actionType) { | ||
52 | + IPage<SysLogDTO> page = | ||
53 | + baseMapper.getPageDatasMatched(pageInfrom, tenantId, customerId, startTime, endTime, EntityType.USER, actionType); | ||
54 | + return getPageData(page, SysLogDTO.class); | ||
55 | + } | ||
56 | +} |
1 | +package org.thingsboard.server.dao.yunteng.mapper; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
5 | +import org.apache.ibatis.annotations.Mapper; | ||
6 | +import org.apache.ibatis.annotations.Param; | ||
7 | +import org.thingsboard.server.common.data.EntityType; | ||
8 | +import org.thingsboard.server.common.data.audit.ActionType; | ||
9 | +import org.thingsboard.server.common.data.yunteng.dto.SysLogDTO; | ||
10 | +import org.thingsboard.server.dao.yunteng.entities.SysLogEntity; | ||
11 | + | ||
12 | +import java.util.List; | ||
13 | + | ||
14 | +/** | ||
15 | + * @author Administrator | ||
16 | + */ | ||
17 | +@Mapper | ||
18 | +public interface YtSysLogMapper extends BaseMapper<SysLogEntity> { | ||
19 | + IPage<SysLogDTO> getPageDatasMatched(IPage<?> page, @Param("tenantId") String tenantId, @Param("customerId") String customerId | ||
20 | + , @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("entityType") EntityType entityType, @Param("actionType") ActionType actionType); | ||
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); | ||
24 | + | ||
25 | + | ||
26 | + SysLogDTO detailById(@Param("entityId") String entityId); | ||
27 | +} |
1 | +package org.thingsboard.server.dao.yunteng.service; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | +import org.thingsboard.server.common.data.EntityType; | ||
5 | +import org.thingsboard.server.common.data.audit.ActionType; | ||
6 | +import org.thingsboard.server.common.data.yunteng.dto.SysLogDTO; | ||
7 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
8 | +import org.thingsboard.server.dao.yunteng.entities.SysLogEntity; | ||
9 | + | ||
10 | +public interface YtSysLogService extends BaseService<SysLogEntity> { | ||
11 | + | ||
12 | + | ||
13 | + /** | ||
14 | + * 日志详细信息 | ||
15 | + * | ||
16 | + * @param entityId 日志ID | ||
17 | + * @return | ||
18 | + */ | ||
19 | + SysLogDTO detail(String entityId); | ||
20 | + | ||
21 | + /** | ||
22 | + * 异常日志列表 | ||
23 | + * | ||
24 | + * @param pageInfrom 分页配置信息 | ||
25 | + * @param startTime 时间过滤窗口起点 | ||
26 | + * @param endTime 时间过滤窗口终点 | ||
27 | + * @param tenantId 租户ID,超级管理员该值为null | ||
28 | + * @param customerId 客户ID,租户管理员该值为null | ||
29 | + * @param actionType 日志类型 | ||
30 | + * @return | ||
31 | + */ | ||
32 | + YtPageData<SysLogDTO> exceptionPage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, ActionType actionType); | ||
33 | + | ||
34 | + /** | ||
35 | + * 操作日志列表 | ||
36 | + * | ||
37 | + * @param pageInfrom 分页配置信息 | ||
38 | + * @param startTime 时间过滤窗口起点 | ||
39 | + * @param endTime 时间过滤窗口终点 | ||
40 | + * @param tenantId 租户ID,超级管理员该值为null | ||
41 | + * @param customerId 客户ID,租户管理员该值为null | ||
42 | + * @param actionType 日志类型 | ||
43 | + * @return | ||
44 | + */ | ||
45 | + YtPageData<SysLogDTO> operatePage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, EntityType entityType, ActionType actionType); | ||
46 | + | ||
47 | + /** | ||
48 | + * 登录日志列表 | ||
49 | + * | ||
50 | + * @param pageInfrom 分页配置信息 | ||
51 | + * @param startTime 时间过滤窗口起点 | ||
52 | + * @param endTime 时间过滤窗口终点 | ||
53 | + * @param tenantId 租户ID,超级管理员该值为null | ||
54 | + * @param customerId 客户ID,租户管理员该值为null | ||
55 | + * @param actionType 日志类型 | ||
56 | + * @return | ||
57 | + */ | ||
58 | + YtPageData<SysLogDTO> loginPage(IPage<SysLogEntity> pageInfrom, Long startTime, Long endTime, String tenantId, String customerId, ActionType actionType); | ||
59 | + | ||
60 | +} |
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
3 | + | ||
4 | +<mapper namespace="org.thingsboard.server.dao.yunteng.mapper.YtSysLogMapper"> | ||
5 | + <resultMap id="logDto" type="org.thingsboard.server.common.data.yunteng.dto.SysLogDTO"> | ||
6 | + <result property="id" column="id"/> | ||
7 | + <result property="entityType" column="entity_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> | ||
8 | + | ||
9 | + <result property="entityId" column="entity_id" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/> | ||
10 | + <result property="entityName" column="entity_name" /> | ||
11 | + <result property="tenantId" column="tenant_id" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/> | ||
12 | + <result property="tenantName" column="tenant_name"/> | ||
13 | + <result property="customerId" column="customer_id" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/> | ||
14 | + <result property="customerName" column="customer_name"/> | ||
15 | + <result property="userId" column="user_id" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/> | ||
16 | + <result property="userName" column="user_name" /> | ||
17 | + | ||
18 | + <result property="actionData" column="action_data" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/> | ||
19 | + <result property="actionType" column="action_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> | ||
20 | + <result property="actionStatus" column="action_status" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> | ||
21 | + <result property="actionFailureDetails" column="action_failure_details"/> | ||
22 | + <result property="createdTime" column="created_time"/> | ||
23 | + | ||
24 | + </resultMap> | ||
25 | + | ||
26 | + <sql id="baseColumn"> | ||
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,cus.title customer_name | ||
29 | + </sql> | ||
30 | + <sql id="detailColumn"> | ||
31 | + <include refid="baseColumn"></include> | ||
32 | + , base.action_data,base.action_failure_details | ||
33 | + </sql> | ||
34 | + | ||
35 | + <select id="getPageDatasMatched" resultMap="logDto"> | ||
36 | + SELECT <include refid="baseColumn"/> | ||
37 | + FROM audit_log base | ||
38 | + LEFT JOIN tenant ten ON base.tenant_id = ten.id | ||
39 | + LEFT JOIN customer cus ON base.customer_id = cus.id | ||
40 | + <where> | ||
41 | + base.entity_type = #{entityType} | ||
42 | + <if test="tenantId !=null and tenantId !=''"> | ||
43 | + AND base.tenant_id = #{tenantId}::uuid | ||
44 | + </if> | ||
45 | + <if test="customerId !=null "> | ||
46 | + AND base.customer_id = #{customerId}::uuid | ||
47 | + </if> | ||
48 | + <if test="startTime !=null"> | ||
49 | + AND base.created_time >= #{startTime} | ||
50 | + </if> | ||
51 | + <if test="endTime !=null"> | ||
52 | + AND base.created_time < #{endTime} | ||
53 | + </if> | ||
54 | + <if test="actionType !=null"> | ||
55 | + AND base.action_type = #{actionType} | ||
56 | + </if> | ||
57 | + </where> | ||
58 | + </select> | ||
59 | + | ||
60 | + | ||
61 | + <select id="getPageDatasNot" resultMap="logDto"> | ||
62 | + SELECT <include refid="baseColumn"/> | ||
63 | + FROM audit_log base | ||
64 | + LEFT JOIN tenant ten ON base.tenant_id = ten.id | ||
65 | + LEFT JOIN customer cus ON base.customer_id = cus.id | ||
66 | + <where> | ||
67 | + base.entity_type | ||
68 | + NOT IN | ||
69 | + <foreach collection="entityType" item="item" open="(" separator="," close=")"> | ||
70 | + #{item} | ||
71 | + </foreach> | ||
72 | + <if test="entityFilter !=null"> | ||
73 | + AND base.entity_type = #{entityFilter} | ||
74 | + </if> | ||
75 | + <if test="tenantId !=null and tenantId !=''"> | ||
76 | + AND base.tenant_id = #{tenantId}::uuid | ||
77 | + </if> | ||
78 | + <if test="customerId !=null "> | ||
79 | + AND base.customer_id = #{customerId}::uuid | ||
80 | + </if> | ||
81 | + <if test="startTime !=null"> | ||
82 | + AND base.created_time >= #{startTime} | ||
83 | + </if> | ||
84 | + <if test="endTime !=null"> | ||
85 | + AND base.created_time < #{endTime} | ||
86 | + </if> | ||
87 | + <if test="actionType !=null"> | ||
88 | + AND base.action_type = #{actionType} | ||
89 | + </if> | ||
90 | + </where> | ||
91 | + </select> | ||
92 | + | ||
93 | + <select id="detailById" resultMap="logDto"> | ||
94 | + SELECT <include refid="detailColumn"/> | ||
95 | + FROM audit_log base | ||
96 | + LEFT JOIN tenant ten ON base.tenant_id = ten.id | ||
97 | + LEFT JOIN customer cus ON base.customer_id = cus.id | ||
98 | + <where> | ||
99 | + base.id = #{entityId}::uuid | ||
100 | + | ||
101 | + </where> | ||
102 | + </select> | ||
103 | + | ||
104 | +</mapper> |