Commit 3d32d119840d1ff17fd2e6a0c345dd247405c701

Authored by 云中非
1 parent bf4fa8bc

refactor: 异常提示信息汉化

... ... @@ -331,7 +331,7 @@ public abstract class BaseController {
331 331 }
332 332
333 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 337 <T> T checkNotNull(Optional<T> reference, String notFoundMessage) throws ThingsboardException {
... ... @@ -344,13 +344,13 @@ public abstract class BaseController {
344 344
345 345 void checkParameter(String name, String param) throws ThingsboardException {
346 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 351 void checkArrayParameter(String name, String[] params) throws ThingsboardException {
352 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 354 } else {
355 355 for (String param : params) {
356 356 checkParameter(name, param);
... ... @@ -369,7 +369,7 @@ public abstract class BaseController {
369 369 try {
370 370 direction = SortOrder.Direction.valueOf(sortOrder.toUpperCase());
371 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 375 SortOrder sort = new SortOrder(sortProperty, direction);
... ... @@ -390,7 +390,7 @@ public abstract class BaseController {
390 390 if (authentication != null && authentication.getPrincipal() instanceof SecurityUser) {
391 391 return (SecurityUser) authentication.getPrincipal();
392 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 398 try {
399 399 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
400 400 Tenant tenant = tenantService.findTenantById(tenantId);
401   - checkNotNull(tenant, "Tenant with id [" + tenantId + "] is not found");
  401 + checkNotNull(tenant, "ID【" + tenantId + "】相关的租户不存在");
402 402 accessControlService.checkPermission(getCurrentUser(), Resource.TENANT, operation, tenantId, tenant);
403 403 return tenant;
404 404 } catch (Exception e) {
... ... @@ -410,7 +410,7 @@ public abstract class BaseController {
410 410 try {
411 411 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
412 412 TenantInfo tenant = tenantService.findTenantInfoById(tenantId);
413   - checkNotNull(tenant, "Tenant with id [" + tenantId + "] is not found");
  413 + checkNotNull(tenant, "ID【" + tenantId + "】相关的租户不存在");
414 414 accessControlService.checkPermission(getCurrentUser(), Resource.TENANT, operation, tenantId, tenant);
415 415 return tenant;
416 416 } catch (Exception e) {
... ... @@ -420,9 +420,9 @@ public abstract class BaseController {
420 420
421 421 TenantProfile checkTenantProfileId(TenantProfileId tenantProfileId, Operation operation) throws ThingsboardException {
422 422 try {
423   - validateId(tenantProfileId, "Incorrect tenantProfileId " + tenantProfileId);
  423 + validateId(tenantProfileId, "错误的租户配置ID " + tenantProfileId);
424 424 TenantProfile tenantProfile = tenantProfileService.findTenantProfileById(getTenantId(), tenantProfileId);
425   - checkNotNull(tenantProfile, "Tenant profile with id [" + tenantProfileId + "] is not found");
  425 + checkNotNull(tenantProfile, "ID【" + tenantProfileId + "】相关的租户配置不存在");
426 426 accessControlService.checkPermission(getCurrentUser(), Resource.TENANT_PROFILE, operation);
427 427 return tenantProfile;
428 428 } catch (Exception e) {
... ... @@ -436,9 +436,9 @@ public abstract class BaseController {
436 436
437 437 protected Customer checkCustomerId(CustomerId customerId, Operation operation) throws ThingsboardException {
438 438 try {
439   - validateId(customerId, "Incorrect customerId " + customerId);
  439 + validateId(customerId, "客户ID不正确 " + customerId);
440 440 Customer customer = customerService.findCustomerById(getTenantId(), customerId);
441   - checkNotNull(customer, "Customer with id [" + customerId + "] is not found");
  441 + checkNotNull(customer, "ID【" + customerId + "】相关的客户不存在");
442 442 accessControlService.checkPermission(getCurrentUser(), Resource.CUSTOMER, operation, customerId, customer);
443 443 return customer;
444 444 } catch (Exception e) {
... ... @@ -448,9 +448,9 @@ public abstract class BaseController {
448 448
449 449 protected User checkUserId(UserId userId, Operation operation) throws ThingsboardException {
450 450 try {
451   - validateId(userId, "Incorrect userId " + userId);
  451 + validateId(userId, "用户ID不正确 " + userId);
452 452 User user = userService.findUserById(getCurrentUser().getTenantId(), userId);
453   - checkNotNull(user, "User with id [" + userId + "] is not found");
  453 + checkNotNull(user, "ID【" + userId + "】相关的用户不存在");
454 454 accessControlService.checkPermission(getCurrentUser(), Resource.USER, operation, userId, user);
455 455 return user;
456 456 } catch (Exception e) {
... ... @@ -470,9 +470,9 @@ public abstract class BaseController {
470 470 protected void checkEntityId(EntityId entityId, Operation operation) throws ThingsboardException {
471 471 try {
472 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 476 switch (entityId.getEntityType()) {
477 477 case ALARM:
478 478 checkAlarmId(new AlarmId(entityId.getId()), operation);
... ... @@ -526,7 +526,7 @@ public abstract class BaseController {
526 526 checkOtaPackageId(new OtaPackageId(entityId.getId()), operation);
527 527 return;
528 528 default:
529   - throw new IllegalArgumentException("Unsupported entity type: " + entityId.getEntityType());
  529 + throw new IllegalArgumentException("不支持的资源类型: " + entityId.getEntityType());
530 530 }
531 531 } catch (Exception e) {
532 532 throw handleException(e, false);
... ... @@ -535,9 +535,9 @@ public abstract class BaseController {
535 535
536 536 public Device checkDeviceId(DeviceId deviceId, Operation operation) throws ThingsboardException {
537 537 try {
538   - validateId(deviceId, "Incorrect deviceId " + deviceId);
  538 + validateId(deviceId, "deviceId不正确 " + deviceId);
539 539 Device device = deviceService.findDeviceById(getCurrentUser().getTenantId(), deviceId);
540   - checkNotNull(device, "Device with id [" + deviceId + "] is not found");
  540 + checkNotNull(device, "ID【" + deviceId + "】相关的设备不存在");
541 541 accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, operation, deviceId, device);
542 542 return device;
543 543 } catch (Exception e) {
... ... @@ -547,9 +547,9 @@ public abstract class BaseController {
547 547
548 548 DeviceInfo checkDeviceInfoId(DeviceId deviceId, Operation operation) throws ThingsboardException {
549 549 try {
550   - validateId(deviceId, "Incorrect deviceId " + deviceId);
  550 + validateId(deviceId, "deviceId不正确" + deviceId);
551 551 DeviceInfo device = deviceService.findDeviceInfoById(getCurrentUser().getTenantId(), deviceId);
552   - checkNotNull(device, "Device with id [" + deviceId + "] is not found");
  552 + checkNotNull(device, "ID【" + deviceId + "】相关的设备不存在");
553 553 accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, operation, deviceId, device);
554 554 return device;
555 555 } catch (Exception e) {
... ... @@ -559,9 +559,9 @@ public abstract class BaseController {
559 559
560 560 protected DeviceProfile checkDeviceProfileId(DeviceProfileId deviceProfileId, Operation operation) throws ThingsboardException {
561 561 try {
562   - validateId(deviceProfileId, "Incorrect deviceProfileId " + deviceProfileId);
  562 + validateId(deviceProfileId, "设备配置Id不正确 " + deviceProfileId);
563 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 565 accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE_PROFILE, operation, deviceProfileId, deviceProfile);
566 566 return deviceProfile;
567 567 } catch (Exception e) {
... ...
... ... @@ -84,7 +84,7 @@ public class YtMenuController extends BaseController {
84 84 @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')")
85 85 public void deleteMenus(@RequestBody String[] ids) throws ThingsboardException {
86 86 if (ids.length == 0) {
87   - throw new YtDataValidationException("please provide menu ids to delete");
  87 + throw new YtDataValidationException("需要删除的菜单不能为空");
88 88 }
89 89 menuService.deleteMenus(getCurrentUser().getCurrentTenantId(), ids);
90 90 }
... ...
... ... @@ -150,7 +150,7 @@ public class OperateLogAspect {
150 150 if (authentication != null && authentication.getPrincipal() instanceof SecurityUser) {
151 151 return (SecurityUser) authentication.getPrincipal();
152 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 71 baseMapper.selectCount(
72 72 new QueryWrapper<Role>().lambda().ne(Role::getTenantId, tenantId).in(Role::getId, ids));
73 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 77 Set<String> userIds = baseMapper.checkRoleUserMappingByRoleIds(ids);
... ...