Commit 3d32d119840d1ff17fd2e6a0c345dd247405c701

Authored by 云中非
1 parent bf4fa8bc

refactor: 异常提示信息汉化

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