Showing
11 changed files
with
60 additions
and
66 deletions
... | ... | @@ -138,7 +138,7 @@ public class TkAdminController extends BaseController { |
138 | 138 | |
139 | 139 | @DeleteMapping("/user/deleteTenantAdmin") |
140 | 140 | @PreAuthorize( |
141 | - "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:user:deleteTenantAdmin:delete'})") | |
141 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN'},{'api:yt:admin:user:deleteTenantAdmin:delete'})") | |
142 | 142 | public ResponseEntity<Boolean> deleteTenantAdmin( |
143 | 143 | @Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { |
144 | 144 | for (String strUserId : deleteDTO.getIds()) { | ... | ... |
... | ... | @@ -69,8 +69,6 @@ public class TkConvertDataToController extends BaseController { |
69 | 69 | |
70 | 70 | @Autowired private TbRuleChainService tbRuleChainService; |
71 | 71 | |
72 | - @Autowired private DeviceMapper deviceMapper; | |
73 | - | |
74 | 72 | @GetMapping(params = {PAGE_SIZE, PAGE}) |
75 | 73 | @ApiOperation("分页查询") |
76 | 74 | public TkPageData<ConvertConfigDTO> pageMessageConfig( |
... | ... | @@ -117,26 +115,27 @@ public class TkConvertDataToController extends BaseController { |
117 | 115 | public ResponseEntity<ConvertConfigDTO> createOrUpdateConvertData( |
118 | 116 | @Validated @RequestBody ConvertConfigDTO convertConfigDTO) throws ThingsboardException { |
119 | 117 | convertConfigDTO.setTenantId(getCurrentUser().getCurrentTenantId()); |
120 | - if(getCurrentUser().isPtCommonTenant()){ | |
121 | - convertConfigDTO.setDatasourceType(DatasourceTypeEnum.DEVICES); | |
122 | - JsonArray convertDevices = new JsonArray(); | |
123 | - JsonNode productNode = convertConfigDTO.getDatasourceContent().get("convertProducts"); | |
124 | - List<String> orgIds = commonTenantOrganizationAllIds(); | |
125 | - for (JsonNode deviceProfileId: productNode ) { | |
126 | - JsonObject product =new JsonObject(); | |
127 | - JsonArray devices = new JsonArray(); | |
128 | - List<DeviceDTO> dto=deviceMapper.findDevicesByProfileIdAndOrganizationId(orgIds,deviceProfileId.asText()); | |
129 | - if(null!=dto&&dto.size()>0){ | |
130 | - dto.forEach(device ->{devices.add(device.getTbDeviceId());}); | |
131 | - product.addProperty("product",deviceProfileId.asText()); | |
132 | - product.add("devices",devices); | |
133 | - convertDevices.add(product); | |
134 | - } | |
135 | - } | |
136 | - ObjectNode convertProducts = (ObjectNode) convertConfigDTO.getDatasourceContent(); | |
137 | - convertProducts.set("convertDevices",JacksonUtil.toJsonNode(convertDevices.toString())); | |
138 | - convertConfigDTO.setDatasourceContent(convertProducts); | |
139 | - } | |
118 | + //这里针对普通租户管理员的代码 暂时屏蔽根据后续清空看是否开启或删除 | |
119 | +// if(getCurrentUser().isPtCommonTenant()){ | |
120 | +// convertConfigDTO.setDatasourceType(DatasourceTypeEnum.DEVICES); | |
121 | +// JsonArray convertDevices = new JsonArray(); | |
122 | +// JsonNode productNode = convertConfigDTO.getDatasourceContent().get("convertProducts"); | |
123 | +// List<String> orgIds = commonTenantOrganizationAllIds(); | |
124 | +// for (JsonNode deviceProfileId: productNode ) { | |
125 | +// JsonObject product =new JsonObject(); | |
126 | +// JsonArray devices = new JsonArray(); | |
127 | +// List<DeviceDTO> dto=deviceMapper.findDevicesByProfileIdAndOrganizationId(orgIds,deviceProfileId.asText()); | |
128 | +// if(null!=dto&&dto.size()>0){ | |
129 | +// dto.forEach(device ->{devices.add(device.getTbDeviceId());}); | |
130 | +// product.addProperty("product",deviceProfileId.asText()); | |
131 | +// product.add("devices",devices); | |
132 | +// convertDevices.add(product); | |
133 | +// } | |
134 | +// } | |
135 | +// ObjectNode convertProducts = (ObjectNode) convertConfigDTO.getDatasourceContent(); | |
136 | +// convertProducts.set("convertDevices",JacksonUtil.toJsonNode(convertDevices.toString())); | |
137 | +// convertConfigDTO.setDatasourceContent(convertProducts); | |
138 | +// } | |
140 | 139 | convertConfigDTO.setNodeType(FastIotConstants.CONVERT_DATA); |
141 | 140 | return ResponseEntity.ok(convertConfigService.createOrUpdate(convertConfigDTO)); |
142 | 141 | } | ... | ... |
... | ... | @@ -46,7 +46,7 @@ public class TkRoleController extends BaseController { |
46 | 46 | @GetMapping( |
47 | 47 | path = "/tenant", |
48 | 48 | params = {PAGE_SIZE, PAGE}) |
49 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | |
49 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN')") | |
50 | 50 | public TkPageData<RoleDTO> pageTenantRole( |
51 | 51 | @RequestParam(PAGE_SIZE) int pageSize, |
52 | 52 | @RequestParam(PAGE) int page, | ... | ... |
... | ... | @@ -64,12 +64,7 @@ public class TkTaskCenterController extends BaseController { |
64 | 64 | queryMap.put("tbDeviceId", tbDeviceId); |
65 | 65 | } |
66 | 66 | if(getCurrentUser().isPtCommonTenant()){ |
67 | - List<DeviceDTO> dto = deviceMapper.findDevicesByProfileIdAndOrganizationId(commonTenantOrganizationAllIds(),null); | |
68 | - if(null!=dto&&dto.size()>0) { | |
69 | - List<String> tbDeviceIds = new ArrayList<>(); | |
70 | - dto.forEach(device -> {tbDeviceIds.add(device.getTbDeviceId());}); | |
71 | - queryMap.put("tbDeviceIds",tbDeviceIds); | |
72 | - } | |
67 | + queryMap.put("orgIds",commonTenantOrganizationAllIds()); | |
73 | 68 | } |
74 | 69 | return tkTaskCenterService.taskCenterPage(queryMap, getCurrentUser().getCurrentTenantId()); |
75 | 70 | } | ... | ... |
... | ... | @@ -139,7 +139,7 @@ public class TkUserController extends AbstractUserAccount { |
139 | 139 | queryMap, getCurrentUser().isPtSysadmin(), getCurrentUser().isTenantAdmin()); |
140 | 140 | } |
141 | 141 | |
142 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | |
142 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN')") | |
143 | 143 | @GetMapping( |
144 | 144 | path = "/tenant/page", |
145 | 145 | params = {PAGE_SIZE, PAGE}) |
... | ... | @@ -158,7 +158,7 @@ public class TkUserController extends AbstractUserAccount { |
158 | 158 | queryMap.put(ORDER_TYPE, orderType.name()); |
159 | 159 | } |
160 | 160 | queryMap.put(ORDER_FILED, orderBy); |
161 | - if (getCurrentUser().isPtCommonTenant()) { | |
161 | + if (getCurrentUser().isPtTenantAdmin()) { | |
162 | 162 | queryMap.put("level", FastIotConstants.MagicNumber.FOUR); |
163 | 163 | }else{ |
164 | 164 | queryMap.put("level", FastIotConstants.MagicNumber.TWO); |
... | ... | @@ -234,7 +234,7 @@ public class TkUserController extends AbstractUserAccount { |
234 | 234 | } |
235 | 235 | |
236 | 236 | @PreAuthorize( |
237 | - "@check.checkPermissions({'TENANT_ADMIN'},{''})")//todo | |
237 | + "@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:user:saveCommonTenant:post'})")//todo | |
238 | 238 | @PostMapping("save_common_tenant") |
239 | 239 | public UserDTO saveCommonTenant(@Validated(AddGroup.class) @RequestBody UserDTO userDTO) |
240 | 240 | throws ThingsboardException { |
... | ... | @@ -265,7 +265,7 @@ public class TkUserController extends AbstractUserAccount { |
265 | 265 | throw handleException(e); |
266 | 266 | } |
267 | 267 | UserDTO result = |
268 | - userService.saveTenantAdmin( | |
268 | + userService.saveTenantAdmin( | |
269 | 269 | userDTO, getCurrentUser().isPtSysadmin(), tenantId.getId().toString()); |
270 | 270 | |
271 | 271 | userService.updateTenantAdminUserCredentials( |
... | ... | @@ -352,7 +352,8 @@ public class TkUserController extends AbstractUserAccount { |
352 | 352 | userService.getMyCustomers( |
353 | 353 | organizationId, |
354 | 354 | getCurrentUser().getCurrentTenantId(), |
355 | - getCurrentUser().isPtTenantAdmin())); | |
355 | + getCurrentUser().isPtTenantAdmin(), | |
356 | + getCurrentUser().isPtCommonTenant())); | |
356 | 357 | } |
357 | 358 | |
358 | 359 | @PostMapping("/reset_password/{userId}") | ... | ... |
... | ... | @@ -285,6 +285,7 @@ public class SysRoleServiceImpl extends AbstractBaseService<RoleMapper, SysRoleE |
285 | 285 | .collect(Collectors.toList()); |
286 | 286 | roleDTO.setRoleIds(roleIds.toArray(new String[roleIds.size()])); |
287 | 287 | } |
288 | + | |
288 | 289 | return baseMapper.findRoleInfo(roleDTO); |
289 | 290 | } |
290 | 291 | ... | ... |
... | ... | @@ -462,15 +462,19 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
462 | 462 | throw new TkDataValidationException("用户已存在"); |
463 | 463 | } |
464 | 464 | baseMapper.insert(user); |
465 | - //查询租户的角色 | |
466 | - List<SysTenantRoleEntity> tenantRoleList = validateTenantRole(userDTO.getTenantId()); | |
467 | - for (SysTenantRoleEntity tenantRole : tenantRoleList) { | |
468 | - roleMapper.saveUserRoleMapping(user.getId(), tenantRole.getRoleId()); | |
469 | - } | |
470 | - // 如果为普通租户绑定用户和组织的关系 | |
465 | + // 如果为普通租户绑定用户和组织的关系和角色 | |
471 | 466 | if(null!=user.getLevel()&&user.getLevel()==FastIotConstants.LevelValue.IS_CUSTOMER_TENANT){ |
472 | 467 | organizationService.bindUserToOrganization( |
473 | 468 | tenantId, user.getId(), userDTO.getOrganizationIds()); |
469 | + for (String tenantRole : userDTO.getRoleIds()) { | |
470 | + roleMapper.saveUserRoleMapping(user.getId(), tenantRole); | |
471 | + } | |
472 | + }else{ | |
473 | + //查询租户的角色 | |
474 | + List<SysTenantRoleEntity> tenantRoleList = validateTenantRole(userDTO.getTenantId()); | |
475 | + for (SysTenantRoleEntity tenantRole : tenantRoleList) { | |
476 | + roleMapper.saveUserRoleMapping(user.getId(), tenantRole.getRoleId()); | |
477 | + } | |
474 | 478 | } |
475 | 479 | |
476 | 480 | user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN); |
... | ... | @@ -677,11 +681,11 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
677 | 681 | |
678 | 682 | @Override |
679 | 683 | public List<UserDTO> getMyCustomers( |
680 | - String organizationId, String tenantId, boolean isTenantAdmin) { | |
684 | + String organizationId, String tenantId, boolean isTenantAdmin,boolean isPtCommonTenant) { | |
681 | 685 | if (StringUtils.isEmpty(organizationId)) { |
682 | 686 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
683 | 687 | } |
684 | - if (isTenantAdmin) { | |
688 | + if (isTenantAdmin||isPtCommonTenant) { | |
685 | 689 | List<String> userList = |
686 | 690 | userOrganizationMappingService.getUserIdByOrganizationIds(tenantId, OrganizationEnum.UP, organizationId); |
687 | 691 | if (null != userList && userList.size() > FastIotConstants.MagicNumber.ZERO) { | ... | ... |
... | ... | @@ -121,12 +121,6 @@ public class TkHomePageServiceImpl implements HomePageService { |
121 | 121 | //查询所有组织id |
122 | 122 | orgIds = organizationService.currentUserOrganizationAllIds(currentUserId); |
123 | 123 | queryMap.put("organizationIds",orgIds); |
124 | - //查询所有设备 | |
125 | - List<DeviceDTO> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId(orgIds,null, | |
126 | - null,null,null); | |
127 | - List<String> finalTbDevices = new ArrayList<>(); | |
128 | - devices.forEach(item -> finalTbDevices.add(item.getId())); | |
129 | - tbDevices = finalTbDevices; | |
130 | 124 | alarmList = deviceMapper.findDeviceAlarmInfoByCustomer(startTs, null,orgIds); |
131 | 125 | }else{ |
132 | 126 | customerId = userMapper.findCustomerIdByUserId(currentUserId); |
... | ... | @@ -136,10 +130,10 @@ public class TkHomePageServiceImpl implements HomePageService { |
136 | 130 | tbDevices = deviceMapper.findDeviceIdsByCustomerId(customerId); |
137 | 131 | } |
138 | 132 | alarmList = deviceMapper.findDeviceAlarmInfoByCustomer(startTs, customerId,null); |
139 | - } | |
140 | - for (String devId : tbDevices) { | |
141 | - setCustomerMessageInfo( | |
142 | - todayBegin, todayEnd, currentTenantId, DeviceId.fromString(devId), messageInfo); | |
133 | + for (String devId : tbDevices) { | |
134 | + setCustomerMessageInfo( | |
135 | + todayBegin, todayEnd, currentTenantId, DeviceId.fromString(devId), messageInfo); | |
136 | + } | |
143 | 137 | } |
144 | 138 | if (alarmList.size() > zero) { |
145 | 139 | BaseHomePageTop baseHomePageTop = alarmList.get(0); | ... | ... |
... | ... | @@ -54,6 +54,18 @@ public class TkTaskCenterServiceImpl |
54 | 54 | IPage<TkTaskCenterEntity> page = |
55 | 55 | getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false); |
56 | 56 | IPage<TkTaskCenterDTO> iPage = baseMapper.getPageData(page, queryMap); |
57 | + List<String> orgIds = (List<String>) queryMap.get("orgIds"); | |
58 | + if(null!=orgIds&&!iPage.getRecords().isEmpty()){ | |
59 | + List<TkTaskCenterDTO> list = new ArrayList<>(); | |
60 | + iPage.getRecords().stream().forEach(dto->{ | |
61 | + orgIds.forEach(orgId-> { | |
62 | + if(dto.getExecuteTarget().getOrganizationId().equals(orgId)){ | |
63 | + list.add(dto); | |
64 | + } | |
65 | + }); | |
66 | + }); | |
67 | + iPage.setRecords(list); | |
68 | + } | |
57 | 69 | if (!iPage.getRecords().isEmpty()) { |
58 | 70 | iPage.setRecords( |
59 | 71 | iPage.getRecords().stream() | ... | ... |
... | ... | @@ -126,7 +126,7 @@ public interface TkUserService { |
126 | 126 | * @param isTenantAdmin 是否是租户管理员 |
127 | 127 | * @return 租户创建的所有用户 |
128 | 128 | */ |
129 | - List<UserDTO> getMyCustomers(String organizationId, String tenantId, boolean isTenantAdmin); | |
129 | + List<UserDTO> getMyCustomers(String organizationId, String tenantId, boolean isTenantAdmin,boolean isPtCommonTenant); | |
130 | 130 | |
131 | 131 | /** |
132 | 132 | * 异步获取用户列表 | ... | ... |
... | ... | @@ -37,16 +37,10 @@ |
37 | 37 | <if test="queryMap.tbDeviceId !=null and queryMap.tbDeviceId !=''"> |
38 | 38 | ,tdc.allow_state,tdc.task_center_id,tdc.tb_device_id |
39 | 39 | </if> |
40 | - <if test="queryMap.tbDeviceIds !=null and queryMap.tbDeviceIds !=''"> | |
41 | - ,tdc.allow_state,tdc.task_center_id,tdc.tb_device_id | |
42 | - </if> | |
43 | 40 | FROM tk_task_center tc |
44 | 41 | <if test="queryMap.tbDeviceId !=null and queryMap.tbDeviceId !=''"> |
45 | 42 | LEFT JOIN tk_device_task_center tdc ON tc.id = tdc.task_center_id |
46 | 43 | </if> |
47 | - <if test="queryMap.tbDeviceIds !=null and queryMap.tbDeviceIds !=''"> | |
48 | - LEFT JOIN tk_device_task_center tdc ON tc.id = tdc.task_center_id | |
49 | - </if> | |
50 | 44 | <where> |
51 | 45 | <if test="queryMap.tenantId !=null and queryMap.tenantId !=''"> |
52 | 46 | AND tc.tenant_id = #{queryMap.tenantId} |
... | ... | @@ -60,12 +54,6 @@ |
60 | 54 | <if test="queryMap.tbDeviceId !=null and queryMap.tbDeviceId !=''"> |
61 | 55 | AND tdc.tb_device_id = #{queryMap.tbDeviceId} |
62 | 56 | </if> |
63 | - <if test="queryMap.tbDeviceIds !=null and queryMap.tbDeviceIds !=''"> | |
64 | - AND tdc.tb_device_id IN | |
65 | - <foreach collection="queryMap.tbDeviceIds" item="tbDeviceId" open="(" separator="," close=")"> | |
66 | - #{tbDeviceId} | |
67 | - </foreach> | |
68 | - </if> | |
69 | 57 | </where> |
70 | 58 | </select> |
71 | 59 | </mapper> | ... | ... |