Showing
6 changed files
with
46 additions
and
36 deletions
@@ -21,7 +21,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. | @@ -21,7 +21,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. | ||
21 | 21 | ||
22 | 22 | ||
23 | @RestController | 23 | @RestController |
24 | -@RequestMapping("api/v1/role") | 24 | +@RequestMapping("api/yt/role") |
25 | @RequiredArgsConstructor | 25 | @RequiredArgsConstructor |
26 | public class RoleController extends BaseController { | 26 | public class RoleController extends BaseController { |
27 | 27 | ||
@@ -50,7 +50,7 @@ public class RoleController extends BaseController { | @@ -50,7 +50,7 @@ public class RoleController extends BaseController { | ||
50 | if (orderType != null) { | 50 | if (orderType != null) { |
51 | queryMap.put(ORDER_TYPE, orderType.name()); | 51 | queryMap.put(ORDER_TYPE, orderType.name()); |
52 | } | 52 | } |
53 | - return roleService.page(getCurrentUser().isSysadmin(), getCurrentUser().isPlatformAdmin(), getCurrentUser().getCurrentTenantId(),queryMap); | 53 | + return roleService.page(getCurrentUser().isPtSysadmin(), getCurrentUser().isPtmAdmin(), getCurrentUser().getCurrentTenantId(),queryMap); |
54 | } | 54 | } |
55 | 55 | ||
56 | @DeleteMapping | 56 | @DeleteMapping |
@@ -60,27 +60,27 @@ public class RoleController extends BaseController { | @@ -60,27 +60,27 @@ public class RoleController extends BaseController { | ||
60 | 60 | ||
61 | @GetMapping("/me/permissions") | 61 | @GetMapping("/me/permissions") |
62 | public Set<String> getPermissions() throws ThingsboardException { | 62 | public Set<String> getPermissions() throws ThingsboardException { |
63 | - return roleService.getPermissions(getCurrentUser().isSysadmin(), getCurrentUser().isTenantAdmin(), getCurrentUser().getCurrentTenantId(), getCurrentUser().getCurrentUserId()); | 63 | + return roleService.getPermissions(getCurrentUser().isPtSysadmin(), getCurrentUser().isPtTenantAdmin(), getCurrentUser().getCurrentTenantId(), getCurrentUser().getCurrentUserId()); |
64 | } | 64 | } |
65 | 65 | ||
66 | @PutMapping("updateRoleStatus/{roleId}/{status}") | 66 | @PutMapping("updateRoleStatus/{roleId}/{status}") |
67 | public void updateRoleStatus( | 67 | public void updateRoleStatus( |
68 | @PathVariable("roleId") String roleId, @PathVariable("status") int status) throws ThingsboardException { | 68 | @PathVariable("roleId") String roleId, @PathVariable("status") int status) throws ThingsboardException { |
69 | Assert.isTrue(status == 0 || status == 1, "role status is not correct"); | 69 | Assert.isTrue(status == 0 || status == 1, "role status is not correct"); |
70 | - roleService.updateRoleStatus(roleId, status, getCurrentUser().isSysadmin() ,getCurrentUser().getCurrentTenantId()); | 70 | + roleService.updateRoleStatus(roleId, status, getCurrentUser().isPtSysadmin() ,getCurrentUser().getCurrentTenantId()); |
71 | } | 71 | } |
72 | 72 | ||
73 | @PostMapping("saveOrUpdateRoleInfoWithMenu") | 73 | @PostMapping("saveOrUpdateRoleInfoWithMenu") |
74 | public RoleDTO saveOrUpdateRoleInfoWithMenu(@RequestBody RoleReqDTO roleReqDTO) throws ThingsboardException { | 74 | public RoleDTO saveOrUpdateRoleInfoWithMenu(@RequestBody RoleReqDTO roleReqDTO) throws ThingsboardException { |
75 | return roleService.saveOrUpdateRoleInfoWithMenu( | 75 | return roleService.saveOrUpdateRoleInfoWithMenu( |
76 | roleReqDTO, | 76 | roleReqDTO, |
77 | - getCurrentUser().isSysadmin(), | ||
78 | - getCurrentUser().isPlatformAdmin(), | 77 | + getCurrentUser().isPtSysadmin(), |
78 | + getCurrentUser().isPtmAdmin(), | ||
79 | getCurrentUser().getCurrentTenantId()); | 79 | getCurrentUser().getCurrentTenantId()); |
80 | } | 80 | } |
81 | 81 | ||
82 | @PostMapping("/find/list") | 82 | @PostMapping("/find/list") |
83 | public List<RoleDTO> findRoleInfoList(@RequestBody RoleDTO roleDTO) throws ThingsboardException { | 83 | public List<RoleDTO> findRoleInfoList(@RequestBody RoleDTO roleDTO) throws ThingsboardException { |
84 | - return roleService.findRoleInfo(getCurrentUser().isTenantAdmin(), getCurrentUser().getCurrentTenantId(),getCurrentUser().getCurrentUserId(), roleDTO); | 84 | + return roleService.findRoleInfo(getCurrentUser().isPtTenantAdmin(), getCurrentUser().getCurrentTenantId(),getCurrentUser().getCurrentUserId(), roleDTO); |
85 | } | 85 | } |
86 | } | 86 | } |
@@ -27,7 +27,7 @@ import java.util.*; | @@ -27,7 +27,7 @@ import java.util.*; | ||
27 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | 27 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
28 | 28 | ||
29 | @RestController | 29 | @RestController |
30 | -@RequestMapping("api/v1/admin") | 30 | +@RequestMapping("api/yt/admin") |
31 | @RequiredArgsConstructor | 31 | @RequiredArgsConstructor |
32 | @PreAuthorize("hasAnyRole('SYS_ADMIN','PLATFORM_ADMIN')") | 32 | @PreAuthorize("hasAnyRole('SYS_ADMIN','PLATFORM_ADMIN')") |
33 | public class YtAdminController extends BaseController { | 33 | public class YtAdminController extends BaseController { |
@@ -94,7 +94,7 @@ public class YtAdminController extends BaseController { | @@ -94,7 +94,7 @@ public class YtAdminController extends BaseController { | ||
94 | Assert.notNull(ids, "ids cannot be null"); | 94 | Assert.notNull(ids, "ids cannot be null"); |
95 | userService.deleteUser( | 95 | userService.deleteUser( |
96 | new HashSet<>(Arrays.asList(ids)), | 96 | new HashSet<>(Arrays.asList(ids)), |
97 | - getCurrentUser().isSysadmin(), | 97 | + getCurrentUser().isPtSysadmin(), |
98 | getCurrentUser().getCurrentTenantId()); | 98 | getCurrentUser().getCurrentTenantId()); |
99 | } | 99 | } |
100 | 100 | ||
@@ -115,12 +115,12 @@ public class YtAdminController extends BaseController { | @@ -115,12 +115,12 @@ public class YtAdminController extends BaseController { | ||
115 | userDTO, | 115 | userDTO, |
116 | sendEmail, | 116 | sendEmail, |
117 | sendMsg, | 117 | sendMsg, |
118 | - getCurrentUser().isSysadmin(), | 118 | + getCurrentUser().isPtSysadmin(), |
119 | getCurrentUser().getCurrentTenantId()); | 119 | getCurrentUser().getCurrentTenantId()); |
120 | Optional<UserDTO> optional = | 120 | Optional<UserDTO> optional = |
121 | userService.getUser( | 121 | userService.getUser( |
122 | newUserDTO.getId(), | 122 | newUserDTO.getId(), |
123 | - getCurrentUser().isSysadmin(), | 123 | + getCurrentUser().isPtSysadmin(), |
124 | getCurrentUser().getCurrentTenantId()); | 124 | getCurrentUser().getCurrentTenantId()); |
125 | return ResponseEntity.ok(optional.get()); | 125 | return ResponseEntity.ok(optional.get()); |
126 | } | 126 | } |
@@ -130,13 +130,13 @@ public class YtAdminController extends BaseController { | @@ -130,13 +130,13 @@ public class YtAdminController extends BaseController { | ||
130 | return ResponseEntity.ok(menuService.getAllMenus(getCurrentUser().getCurrentTenantId())); | 130 | return ResponseEntity.ok(menuService.getAllMenus(getCurrentUser().getCurrentTenantId())); |
131 | } | 131 | } |
132 | 132 | ||
133 | - @GetMapping("me/menus") | 133 | + @GetMapping("/me/menus") |
134 | public ResponseEntity<List<MenuDTO>> getMyMenus() throws ThingsboardException { | 134 | public ResponseEntity<List<MenuDTO>> getMyMenus() throws ThingsboardException { |
135 | return ResponseEntity.ok( | 135 | return ResponseEntity.ok( |
136 | menuService.getMyMenus( | 136 | menuService.getMyMenus( |
137 | getCurrentUser().getCurrentTenantId(), | 137 | getCurrentUser().getCurrentTenantId(), |
138 | getCurrentUser().getCurrentUserId(), | 138 | getCurrentUser().getCurrentUserId(), |
139 | - getCurrentUser().isSysadmin(), getCurrentUser().isTenantAdmin())); | 139 | + getCurrentUser().isPtSysadmin(), getCurrentUser().isPtTenantAdmin())); |
140 | } | 140 | } |
141 | 141 | ||
142 | @PutMapping("/menu/assign/{tenantCode}") | 142 | @PutMapping("/menu/assign/{tenantCode}") |
@@ -39,7 +39,7 @@ import java.util.List; | @@ -39,7 +39,7 @@ import java.util.List; | ||
39 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | 39 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
40 | 40 | ||
41 | @RestController | 41 | @RestController |
42 | -@RequestMapping("api/v1/user") | 42 | +@RequestMapping("api/yt/user") |
43 | @RequiredArgsConstructor | 43 | @RequiredArgsConstructor |
44 | @Api(value = "用户接口") | 44 | @Api(value = "用户接口") |
45 | public class YtUserController extends BaseController { | 45 | public class YtUserController extends BaseController { |
@@ -51,7 +51,7 @@ public class YtUserController extends BaseController { | @@ -51,7 +51,7 @@ public class YtUserController extends BaseController { | ||
51 | throws ThingsboardException { | 51 | throws ThingsboardException { |
52 | return ResponseEntity.of( | 52 | return ResponseEntity.of( |
53 | userService.getUser( | 53 | userService.getUser( |
54 | - userId, getCurrentUser().isSysadmin(), getCurrentUser().getCurrentTenantId())); | 54 | + userId, getCurrentUser().isPtSysadmin(), getCurrentUser().getCurrentTenantId())); |
55 | } | 55 | } |
56 | 56 | ||
57 | @GetMapping("me/info") | 57 | @GetMapping("me/info") |
@@ -83,7 +83,7 @@ public class YtUserController extends BaseController { | @@ -83,7 +83,7 @@ public class YtUserController extends BaseController { | ||
83 | queryMap.put(ORDER_FILED, orderBy); | 83 | queryMap.put(ORDER_FILED, orderBy); |
84 | queryMap.put("realName", realName); | 84 | queryMap.put("realName", realName); |
85 | queryMap.put("username", username); | 85 | queryMap.put("username", username); |
86 | - if (getCurrentUser().isSysadmin()) { | 86 | + if (getCurrentUser().isPtSysadmin()) { |
87 | if (StringUtils.isEmpty(tenantCode)) { | 87 | if (StringUtils.isEmpty(tenantCode)) { |
88 | tenantCode = getCurrentUser().getCurrentTenantId(); | 88 | tenantCode = getCurrentUser().getCurrentTenantId(); |
89 | } | 89 | } |
@@ -97,16 +97,16 @@ public class YtUserController extends BaseController { | @@ -97,16 +97,16 @@ public class YtUserController extends BaseController { | ||
97 | } | 97 | } |
98 | return userService.page( | 98 | return userService.page( |
99 | queryMap, | 99 | queryMap, |
100 | - getCurrentUser().isSysadmin(), | ||
101 | - getCurrentUser().isPlatformAdmin(), | ||
102 | - getCurrentUser().isTenantAdmin(), | 100 | + getCurrentUser().isPtSysadmin(), |
101 | + getCurrentUser().isPtmAdmin(), | ||
102 | + getCurrentUser().isPtTenantAdmin(), | ||
103 | getCurrentUser().getCurrentTenantId()); | 103 | getCurrentUser().getCurrentTenantId()); |
104 | } | 104 | } |
105 | 105 | ||
106 | @PutMapping | 106 | @PutMapping |
107 | public UserDTO updateUser(@RequestBody UserDTO userDTO) throws ThingsboardException { | 107 | public UserDTO updateUser(@RequestBody UserDTO userDTO) throws ThingsboardException { |
108 | return userService.updateUser( | 108 | return userService.updateUser( |
109 | - userDTO, getCurrentUser().isSysadmin(), getCurrentUser().getCurrentTenantId()); | 109 | + userDTO, getCurrentUser().isPtSysadmin(), getCurrentUser().getCurrentTenantId()); |
110 | } | 110 | } |
111 | 111 | ||
112 | @PostMapping | 112 | @PostMapping |
@@ -121,7 +121,7 @@ public class YtUserController extends BaseController { | @@ -121,7 +121,7 @@ public class YtUserController extends BaseController { | ||
121 | userDTO, | 121 | userDTO, |
122 | sendEmail, | 122 | sendEmail, |
123 | sendMsg, | 123 | sendMsg, |
124 | - getCurrentUser().isSysadmin(), | 124 | + getCurrentUser().isPtSysadmin(), |
125 | getCurrentUser().getCurrentTenantId()); | 125 | getCurrentUser().getCurrentTenantId()); |
126 | URI location = | 126 | URI location = |
127 | ServletUriComponentsBuilder.fromCurrentRequest() | 127 | ServletUriComponentsBuilder.fromCurrentRequest() |
@@ -138,14 +138,14 @@ public class YtUserController extends BaseController { | @@ -138,14 +138,14 @@ public class YtUserController extends BaseController { | ||
138 | Assert.notNull(userDTO.getUsername(), "username must exist"); | 138 | Assert.notNull(userDTO.getUsername(), "username must exist"); |
139 | Assert.notNull(userDTO.getRealName(), "real name must exist"); | 139 | Assert.notNull(userDTO.getRealName(), "real name must exist"); |
140 | return userService.saveTenantAdmin( | 140 | return userService.saveTenantAdmin( |
141 | - userDTO, getCurrentUser().isSysadmin(), getCurrentUser().getCurrentTenantId()); | 141 | + userDTO, getCurrentUser().isPtSysadmin(), getCurrentUser().getCurrentTenantId()); |
142 | } | 142 | } |
143 | 143 | ||
144 | @DeleteMapping | 144 | @DeleteMapping |
145 | public void deleteUser(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) | 145 | public void deleteUser(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) |
146 | throws ThingsboardException { | 146 | throws ThingsboardException { |
147 | userService.deleteUser( | 147 | userService.deleteUser( |
148 | - deleteDTO.getIds(), getCurrentUser().isSysadmin(), getCurrentUser().getCurrentTenantId()); | 148 | + deleteDTO.getIds(), getCurrentUser().isPtSysadmin(), getCurrentUser().getCurrentTenantId()); |
149 | } | 149 | } |
150 | 150 | ||
151 | @RequestMapping( | 151 | @RequestMapping( |
@@ -28,11 +28,8 @@ import org.thingsboard.server.common.data.id.UserId; | @@ -28,11 +28,8 @@ import org.thingsboard.server.common.data.id.UserId; | ||
28 | import org.thingsboard.server.common.data.security.Authority; | 28 | import org.thingsboard.server.common.data.security.Authority; |
29 | import org.thingsboard.server.common.data.validation.Length; | 29 | import org.thingsboard.server.common.data.validation.Length; |
30 | import org.thingsboard.server.common.data.validation.NoXss; | 30 | import org.thingsboard.server.common.data.validation.NoXss; |
31 | -import org.thingsboard.server.common.data.yunteng.dto.UserDetailRoleDTO; | ||
32 | import org.thingsboard.server.common.data.yunteng.dto.UserDetailsDTO; | 31 | import org.thingsboard.server.common.data.yunteng.dto.UserDetailsDTO; |
33 | 32 | ||
34 | -import java.util.Set; | ||
35 | - | ||
36 | @ApiModel | 33 | @ApiModel |
37 | @EqualsAndHashCode(callSuper = true) | 34 | @EqualsAndHashCode(callSuper = true) |
38 | public class User extends SearchTextBasedWithAdditionalInfo<UserId> | 35 | public class User extends SearchTextBasedWithAdditionalInfo<UserId> |
@@ -48,7 +48,7 @@ public interface FastIotConstants { | @@ -48,7 +48,7 @@ public interface FastIotConstants { | ||
48 | } | 48 | } |
49 | 49 | ||
50 | interface CacheConfigKey { | 50 | interface CacheConfigKey { |
51 | - String CACHE_CONFIG_KEY = "FAST_IOT_CACHE"; | 51 | + String CACHE_CONFIG_KEY = "YUN_TENG_IOT_CACHE"; |
52 | String USER_PERMISSION_PREFIX = "user_permission_for_"; | 52 | String USER_PERMISSION_PREFIX = "user_permission_for_"; |
53 | String MOBILE_LOGIN_SMS_CODE = "mobile_login_sms_code"; | 53 | String MOBILE_LOGIN_SMS_CODE = "mobile_login_sms_code"; |
54 | String DEFAULT_RULE_CHAIN = "default_rule_chain"; | 54 | String DEFAULT_RULE_CHAIN = "default_rule_chain"; |
1 | package org.thingsboard.server.common.data.yunteng.core.cache; | 1 | package org.thingsboard.server.common.data.yunteng.core.cache; |
2 | - | 2 | +import org.springframework.cache.Cache; |
3 | import org.springframework.cache.CacheManager; | 3 | import org.springframework.cache.CacheManager; |
4 | import org.springframework.stereotype.Component; | 4 | import org.springframework.stereotype.Component; |
5 | - | ||
6 | import java.util.Objects; | 5 | import java.util.Objects; |
7 | import java.util.Optional; | 6 | import java.util.Optional; |
8 | 7 | ||
@@ -22,30 +21,44 @@ public class CacheUtils { | @@ -22,30 +21,44 @@ public class CacheUtils { | ||
22 | } | 21 | } |
23 | 22 | ||
24 | public void put(String cacheName, String key, Object value) { | 23 | public void put(String cacheName, String key, Object value) { |
25 | - Objects.requireNonNull(cacheManager.getCache(cacheName)).put(key, value); | 24 | + Cache cache = cacheManager.getCache(cacheName); |
25 | + if (null != cache) { | ||
26 | + cache.put(key, value); | ||
27 | + } | ||
26 | } | 28 | } |
27 | 29 | ||
28 | public void invalidateCacheName(String cacheName) { | 30 | public void invalidateCacheName(String cacheName) { |
29 | - Objects.requireNonNull(cacheManager.getCache(cacheName)).invalidate(); | 31 | + Cache cache = cacheManager.getCache(cacheName); |
32 | + if (null != cache) { | ||
33 | + cache.invalidate(); | ||
34 | + } | ||
30 | } | 35 | } |
36 | + | ||
31 | public void invalidate(String key) { | 37 | public void invalidate(String key) { |
32 | - Objects.requireNonNull(cacheManager.getCache(COMMON_STORE_AREA)).evictIfPresent(key); | 38 | + Cache cache = cacheManager.getCache(COMMON_STORE_AREA); |
39 | + if (null != cache) { | ||
40 | + cache.evictIfPresent(key); | ||
41 | + } | ||
33 | } | 42 | } |
34 | 43 | ||
35 | public void invalidate(String cacheName, String key) { | 44 | public void invalidate(String cacheName, String key) { |
36 | - Objects.requireNonNull(cacheManager.getCache(cacheName)).evictIfPresent(key); | 45 | + Cache cache = cacheManager.getCache(cacheName); |
46 | + if (null != cache) { | ||
47 | + cache.evictIfPresent(key); | ||
48 | + } | ||
37 | } | 49 | } |
38 | 50 | ||
39 | @SuppressWarnings("unchecked") | 51 | @SuppressWarnings("unchecked") |
40 | public <T> Optional<T> get(String key) { | 52 | public <T> Optional<T> get(String key) { |
41 | - return Optional.ofNullable( | ||
42 | - Objects.requireNonNull(cacheManager.getCache(COMMON_STORE_AREA)).get(key)) | 53 | + return Optional.ofNullable(cacheManager.getCache(COMMON_STORE_AREA)) |
54 | + .map(cache -> Objects.requireNonNull(cache).get(key)) | ||
43 | .map(v -> (T) v.get()); | 55 | .map(v -> (T) v.get()); |
44 | } | 56 | } |
45 | 57 | ||
46 | @SuppressWarnings("unchecked") | 58 | @SuppressWarnings("unchecked") |
47 | public <T> Optional<T> get(String cacheName, String key) { | 59 | public <T> Optional<T> get(String cacheName, String key) { |
48 | - return Optional.ofNullable(Objects.requireNonNull(cacheManager.getCache(cacheName)).get(key)) | 60 | + return Optional.ofNullable(cacheManager.getCache(cacheName)) |
61 | + .map(cache -> Objects.requireNonNull(cache).get(key)) | ||
49 | .map(v -> (T) v.get()); | 62 | .map(v -> (T) v.get()); |
50 | } | 63 | } |
51 | } | 64 | } |