Showing
29 changed files
with
220 additions
and
43 deletions
... | ... | @@ -1004,8 +1004,8 @@ public abstract class BaseController { |
1004 | 1004 | } |
1005 | 1005 | } |
1006 | 1006 | |
1007 | - protected List<String> commonTenantOrganizationAllIds(String currentUserId) { | |
1008 | - return organizationService.currentUserOrganizationAllIds(currentUserId); | |
1007 | + protected List<String> commonTenantOrganizationAllIds() throws ThingsboardException { | |
1008 | + return organizationService.currentUserOrganizationAllIds(getCurrentUser().getCurrentUserId()); | |
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | } | ... | ... |
... | ... | @@ -45,6 +45,7 @@ public class HomePageController extends BaseController { |
45 | 45 | getCurrentUser().isPtSysadmin(), |
46 | 46 | getCurrentUser().isPtAdmin(), |
47 | 47 | getCurrentUser().isPtTenantAdmin(), |
48 | + getCurrentUser().isPtCommonTenant(), | |
48 | 49 | getCurrentUser().getCurrentTenantId(), |
49 | 50 | getCurrentUser().getCurrentUserId()); |
50 | 51 | } | ... | ... |
... | ... | @@ -174,6 +174,7 @@ public class TkAdminController extends BaseController { |
174 | 174 | sendEmail, |
175 | 175 | sendMsg, |
176 | 176 | getCurrentUser().isPtSysadmin(), |
177 | + getCurrentUser().isPtCommonTenant(), | |
177 | 178 | getCurrentUser().getCurrentTenantId()); |
178 | 179 | Optional<UserDTO> optional = |
179 | 180 | tkUserService.getUser( | ... | ... |
... | ... | @@ -75,6 +75,10 @@ public class TkAlarmInfoController extends BaseController { |
75 | 75 | if (getCurrentUser().isCustomerUser()) { |
76 | 76 | customerId = getCurrentUser().getCustomerId().getId(); |
77 | 77 | } |
78 | + List<String> orgIds = null; | |
79 | + if(getCurrentUser().isPtCommonTenant()){ | |
80 | + orgIds = commonTenantOrganizationAllIds(); | |
81 | + } | |
78 | 82 | return alarmInfoService.alarmPage( |
79 | 83 | pageFilter, |
80 | 84 | getCurrentUser().getTenantId(), |
... | ... | @@ -88,7 +92,8 @@ public class TkAlarmInfoController extends BaseController { |
88 | 92 | deviceName, |
89 | 93 | deviceType, |
90 | 94 | EntityType.DEVICE, |
91 | - organizationId); | |
95 | + organizationId, | |
96 | + orgIds); | |
92 | 97 | } |
93 | 98 | @ApiOperation(value = "组态告警查询") |
94 | 99 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
... | ... | @@ -115,6 +120,10 @@ public class TkAlarmInfoController extends BaseController { |
115 | 120 | String deviceName = page.getDeviceName(); |
116 | 121 | String organizationId = page.getOrganizationId(); |
117 | 122 | DeviceTypeEnum deviceType = page.getDeviceType(); |
123 | + List<String> orgIds = null; | |
124 | + if(getCurrentUser().isPtCommonTenant()){ | |
125 | + orgIds = commonTenantOrganizationAllIds(); | |
126 | + } | |
118 | 127 | return alarmInfoService.alarmPage( |
119 | 128 | pageFilter, |
120 | 129 | getCurrentUser().getTenantId(), |
... | ... | @@ -128,7 +137,8 @@ public class TkAlarmInfoController extends BaseController { |
128 | 137 | deviceName, |
129 | 138 | deviceType, |
130 | 139 | EntityType.DEVICE, |
131 | - organizationId); | |
140 | + organizationId, | |
141 | + orgIds); | |
132 | 142 | } |
133 | 143 | |
134 | 144 | @ApiOperation(value = "告警类型") | ... | ... |
... | ... | @@ -68,6 +68,10 @@ public class TkConfigurationCenterController extends BaseController { |
68 | 68 | if (null != orderType) { |
69 | 69 | queryMap.put(ORDER_TYPE, orderType.name()); |
70 | 70 | } |
71 | + //如果是普通租户在最外层默认放入组织id | |
72 | + if(getCurrentUser().isPtCommonTenant()){ | |
73 | + queryMap.put("organizationIds",commonTenantOrganizationAllIds()); | |
74 | + } | |
71 | 75 | queryMap.put("userId", getCurrentUser().getCurrentUserId()); |
72 | 76 | queryMap.put("isTemplate", isTemplate); |
73 | 77 | TkPageData<ConfigurationCenterDTO> pageData = | ... | ... |
... | ... | @@ -2,8 +2,12 @@ package org.thingsboard.server.controller.yunteng; |
2 | 2 | |
3 | 3 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
4 | 4 | |
5 | +import com.amazonaws.util.json.Jackson; | |
6 | +import com.eclipsesource.json.Json; | |
5 | 7 | import com.fasterxml.jackson.databind.JsonNode; |
6 | 8 | import com.fasterxml.jackson.databind.node.ObjectNode; |
9 | +import com.google.gson.JsonArray; | |
10 | +import com.google.gson.JsonObject; | |
7 | 11 | import io.swagger.annotations.Api; |
8 | 12 | import io.swagger.annotations.ApiOperation; |
9 | 13 | import io.swagger.annotations.ApiParam; |
... | ... | @@ -31,12 +35,16 @@ import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
31 | 35 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
32 | 36 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
33 | 37 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
38 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
39 | +import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; | |
34 | 40 | import org.thingsboard.server.common.data.yunteng.dto.convert.ConvertConfigDTO; |
35 | 41 | import org.thingsboard.server.common.data.yunteng.dto.convert.ConvertConfigReqDTO; |
36 | 42 | import org.thingsboard.server.common.data.yunteng.dto.convert.ConvertReqDTO; |
43 | +import org.thingsboard.server.common.data.yunteng.enums.DatasourceTypeEnum; | |
37 | 44 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
38 | 45 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
39 | 46 | import org.thingsboard.server.controller.BaseController; |
47 | +import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper; | |
40 | 48 | import org.thingsboard.server.dao.yunteng.service.ConvertConfigService; |
41 | 49 | import org.thingsboard.server.dao.yunteng.service.SceneLinkageService; |
42 | 50 | import org.thingsboard.server.dao.yunteng.service.TkRuleChainService; |
... | ... | @@ -61,6 +69,8 @@ public class TkConvertDataToController extends BaseController { |
61 | 69 | |
62 | 70 | @Autowired private TbRuleChainService tbRuleChainService; |
63 | 71 | |
72 | + @Autowired private DeviceMapper deviceMapper; | |
73 | + | |
64 | 74 | @GetMapping(params = {PAGE_SIZE, PAGE}) |
65 | 75 | @ApiOperation("分页查询") |
66 | 76 | public TkPageData<ConvertConfigDTO> pageMessageConfig( |
... | ... | @@ -107,6 +117,26 @@ public class TkConvertDataToController extends BaseController { |
107 | 117 | public ResponseEntity<ConvertConfigDTO> createOrUpdateConvertData( |
108 | 118 | @Validated @RequestBody ConvertConfigDTO convertConfigDTO) throws ThingsboardException { |
109 | 119 | 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 | + } | |
110 | 140 | convertConfigDTO.setNodeType(FastIotConstants.CONVERT_DATA); |
111 | 141 | return ResponseEntity.ok(convertConfigService.createOrUpdate(convertConfigDTO)); |
112 | 142 | } | ... | ... |
... | ... | @@ -53,6 +53,9 @@ public class TkDataBoardController extends BaseController { |
53 | 53 | queryMap.put(ORDER_FILED, orderBy); |
54 | 54 | queryMap.put(ORDER_TYPE, orderType); |
55 | 55 | queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId()); |
56 | + if(getCurrentUser().isPtCommonTenant()){ | |
57 | + queryMap.put("organizationIds", commonTenantOrganizationAllIds()); | |
58 | + } | |
56 | 59 | if (StringUtils.isNotBlank(organizationId)) { |
57 | 60 | queryMap.put("organizationId", organizationId); |
58 | 61 | } | ... | ... |
... | ... | @@ -66,6 +66,10 @@ public class TkDataViewController extends BaseController { |
66 | 66 | if (null != orderType) { |
67 | 67 | queryMap.put(ORDER_TYPE, orderType.name()); |
68 | 68 | } |
69 | + //如果是普通租户在最外层默认放入组织id | |
70 | + if(getCurrentUser().isPtCommonTenant()){ | |
71 | + queryMap.put("organizationIds",commonTenantOrganizationAllIds()); | |
72 | + } | |
69 | 73 | queryMap.put("userId", getCurrentUser().getCurrentUserId()); |
70 | 74 | TkPageData<TkDataViewDTO> pageData = |
71 | 75 | tkDataViewService.page(queryMap, getCurrentUser().isTenantAdmin()); | ... | ... |
... | ... | @@ -254,7 +254,7 @@ public class TkDeviceController extends BaseController { |
254 | 254 | } |
255 | 255 | //如果当前用户是普通租户 |
256 | 256 | if (getCurrentUser().isPtCommonTenant()) { |
257 | - List<String> organizationIds =commonTenantOrganizationAllIds(getCurrentUser().getCurrentUserId()); | |
257 | + List<String> organizationIds =commonTenantOrganizationAllIds(); | |
258 | 258 | if(null!=organizationIds&&organizationIds.size()>0){ |
259 | 259 | queryMap.put("organizationIds", organizationIds); |
260 | 260 | } |
... | ... | @@ -429,7 +429,7 @@ public class TkDeviceController extends BaseController { |
429 | 429 | throws ThingsboardException { |
430 | 430 | List<String> orgIds = null; |
431 | 431 | if(getCurrentUser().isPtCommonTenant()){ |
432 | - orgIds= commonTenantOrganizationAllIds(getCurrentUser().getCurrentUserId()); | |
432 | + orgIds= commonTenantOrganizationAllIds(); | |
433 | 433 | } |
434 | 434 | return tkdeviceService.findDevicesByTransportTypeAndOrganizationId( |
435 | 435 | getCurrentUser().getCurrentTenantId(), orgIds,organizationId, transportType); | ... | ... |
... | ... | @@ -63,8 +63,11 @@ public class TkDeviceStateLogController extends BaseController { |
63 | 63 | if(getCurrentUser().isCustomerUser()){ |
64 | 64 | queryMap.put(CUSTOMER_ID, getCurrentUser().getCustomerId().getId().toString()); |
65 | 65 | } |
66 | + if(getCurrentUser().isPtCommonTenant()){ | |
67 | + queryMap.put("orgIds", commonTenantOrganizationAllIds()); | |
68 | + } | |
66 | 69 | return tkDeviceStateLogService.page( |
67 | - getCurrentUser().isCustomerUser(), getCurrentUser().getCurrentTenantId(), queryMap); | |
70 | + getCurrentUser().isCustomerUser(),getCurrentUser().isPtCommonTenant(), getCurrentUser().getCurrentTenantId(), queryMap); | |
68 | 71 | } |
69 | 72 | |
70 | 73 | @DeleteMapping | ... | ... |
... | ... | @@ -64,6 +64,10 @@ public class TkReportFormConfigController extends BaseController { |
64 | 64 | queryMap.put(ORDER_TYPE, orderType.name()); |
65 | 65 | } |
66 | 66 | queryMap.put("userId",getCurrentUser().getCurrentUserId()); |
67 | + //如果是普通租户在最外层默认放入组织id | |
68 | + if(getCurrentUser().isPtCommonTenant()){ | |
69 | + queryMap.put("organizationIds",commonTenantOrganizationAllIds()); | |
70 | + } | |
67 | 71 | checkTimeAndPut(queryMap,startTime,endTime); |
68 | 72 | return reportFormConfigService.page(queryMap, getCurrentUser().isTenantAdmin()); |
69 | 73 | } | ... | ... |
... | ... | @@ -71,6 +71,9 @@ public class TkReportGenerateRecordController extends BaseController { |
71 | 71 | if(getCurrentUser().isCustomerUser()){ |
72 | 72 | queryMap.put("customerId", getCurrentUser().getCustomerId().toString()); |
73 | 73 | } |
74 | + if(getCurrentUser().isPtCommonTenant()){ | |
75 | + queryMap.put("organizationIds",commonTenantOrganizationAllIds()); | |
76 | + } | |
74 | 77 | return reportFormGenerateRecordService.page(queryMap, getCurrentUser().isTenantAdmin()); |
75 | 78 | } |
76 | 79 | ... | ... |
... | ... | @@ -106,6 +106,10 @@ public class TkSceneLinkageController extends BaseController { |
106 | 106 | queryMap.put("organizationId", organizationId); |
107 | 107 | queryMap.put("triggers", triggers); |
108 | 108 | queryMap.put("currentUser",getCurrentUser().getCurrentUserId()); |
109 | + //如果是普通租户在最外层默认放入组织id | |
110 | + if(getCurrentUser().isPtCommonTenant()){ | |
111 | + queryMap.put("organizationIds",commonTenantOrganizationAllIds()); | |
112 | + } | |
109 | 113 | return sceneLinkageService.page(queryMap, getCurrentUser().getCurrentTenantId(),getCurrentUser().isCustomerUser()); |
110 | 114 | } |
111 | 115 | ... | ... |
... | ... | @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiOperation; |
5 | 5 | import lombok.RequiredArgsConstructor; |
6 | 6 | import org.apache.commons.lang3.StringUtils; |
7 | 7 | import org.quartz.SchedulerException; |
8 | +import org.springframework.beans.factory.annotation.Autowired; | |
8 | 9 | import org.springframework.security.access.prepost.PreAuthorize; |
9 | 10 | import org.springframework.validation.annotation.Validated; |
10 | 11 | import org.springframework.web.bind.annotation.*; |
... | ... | @@ -14,6 +15,7 @@ import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; |
14 | 15 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
15 | 16 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
16 | 17 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
18 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
17 | 19 | import org.thingsboard.server.common.data.yunteng.dto.task.TaskImmediateExecuteDTO; |
18 | 20 | import org.thingsboard.server.common.data.yunteng.dto.task.TkTaskCenterDTO; |
19 | 21 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
... | ... | @@ -21,9 +23,12 @@ import org.thingsboard.server.common.data.yunteng.enums.TargetTypeEnum; |
21 | 23 | import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; |
22 | 24 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
23 | 25 | import org.thingsboard.server.controller.BaseController; |
26 | +import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper; | |
24 | 27 | import org.thingsboard.server.dao.yunteng.service.TkTaskCenterService; |
25 | 28 | |
29 | +import java.util.ArrayList; | |
26 | 30 | import java.util.HashMap; |
31 | +import java.util.List; | |
27 | 32 | |
28 | 33 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
29 | 34 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE; |
... | ... | @@ -34,6 +39,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
34 | 39 | @RequiredArgsConstructor |
35 | 40 | public class TkTaskCenterController extends BaseController { |
36 | 41 | private final TkTaskCenterService tkTaskCenterService; |
42 | + @Autowired private DeviceMapper deviceMapper; | |
37 | 43 | |
38 | 44 | @GetMapping( |
39 | 45 | name = "page", |
... | ... | @@ -57,6 +63,14 @@ public class TkTaskCenterController extends BaseController { |
57 | 63 | if (!StringUtils.isEmpty(tbDeviceId)) { |
58 | 64 | queryMap.put("tbDeviceId", tbDeviceId); |
59 | 65 | } |
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 | + } | |
73 | + } | |
60 | 74 | return tkTaskCenterService.taskCenterPage(queryMap, getCurrentUser().getCurrentTenantId()); |
61 | 75 | } |
62 | 76 | ... | ... |
... | ... | @@ -54,6 +54,7 @@ import java.util.HashMap; |
54 | 54 | import java.util.List; |
55 | 55 | import java.util.Objects; |
56 | 56 | import java.util.UUID; |
57 | +import java.util.stream.Collectors; | |
57 | 58 | |
58 | 59 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
59 | 60 | |
... | ... | @@ -131,6 +132,9 @@ public class TkUserController extends AbstractUserAccount { |
131 | 132 | } |
132 | 133 | queryMap.put("currentUserId", getCurrentUser().getCurrentUserId()); |
133 | 134 | queryMap.put("tenantId", tenantId); |
135 | + if(getCurrentUser().isPtCommonTenant()){ | |
136 | + queryMap.put("organizationIds", commonTenantOrganizationAllIds()); | |
137 | + } | |
134 | 138 | return userService.page( |
135 | 139 | queryMap, getCurrentUser().isPtSysadmin(), getCurrentUser().isTenantAdmin()); |
136 | 140 | } |
... | ... | @@ -199,7 +203,8 @@ public class TkUserController extends AbstractUserAccount { |
199 | 203 | userService.validateUserNameAndPhoneNumberAndEmail(userDTO); |
200 | 204 | // 如果当前用户是租户管理员,则代表创建的用户为CUSTOMER_USER,则需要调用TB,否则为本平台的管理员不需要调用TB |
201 | 205 | boolean isTenantAdminOperator = getCurrentUser().isPtTenantAdmin(); |
202 | - if (isTenantAdminOperator) { | |
206 | + boolean isPtCommonTenantOperator = getCurrentUser(). isPtCommonTenant(); | |
207 | + if (isTenantAdminOperator||isPtCommonTenantOperator) { | |
203 | 208 | // 创建CUSTOMER_USER用户 |
204 | 209 | Customer customer = createCustomer(userDTO.getUsername()); |
205 | 210 | // 创建CUSTOMER_USER的管理员 |
... | ... | @@ -216,6 +221,7 @@ public class TkUserController extends AbstractUserAccount { |
216 | 221 | sendEmail, |
217 | 222 | sendMsg, |
218 | 223 | getCurrentUser().isPtTenantAdmin(), |
224 | + getCurrentUser().isPtCommonTenant(), | |
219 | 225 | getCurrentUser().getCurrentTenantId())); |
220 | 226 | } |
221 | 227 | ... | ... |
... | ... | @@ -92,8 +92,8 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
92 | 92 | @Override |
93 | 93 | @Transactional |
94 | 94 | public UserDTO saveAccount( |
95 | - UserDTO userDTO, boolean sendEmail, boolean sendMsg, boolean isTenantAdmin, String tenantId) { | |
96 | - boolean isTenantAdminOperate = isTenantAdmin; | |
95 | + UserDTO userDTO, boolean sendEmail, boolean sendMsg, boolean isTenantAdmin, boolean isCommonTenant,String tenantId) { | |
96 | + boolean isTenantAdminOperate = isTenantAdmin||isCommonTenant; | |
97 | 97 | if (sendMsg && StringUtils.isEmpty(userDTO.getPhoneNumber())) { |
98 | 98 | throw new TkDataValidationException( |
99 | 99 | "you must specify user phone number if you want send activate email to this user"); |
... | ... | @@ -328,10 +328,16 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE |
328 | 328 | IPage<SysUserEntity> userIPage = getPage(queryMap, "create_time", false); |
329 | 329 | String organizationId = |
330 | 330 | queryMap.get("organizationId") != null ? (String) queryMap.get("organizationId") : null; |
331 | + List<String> organizationIds = | |
332 | + queryMap.get("organizationIds") != null ? (List<String>) queryMap.get("organizationIds") : null; | |
331 | 333 | List<String> userIds = null; |
334 | + | |
332 | 335 | if (null != organizationId) { |
333 | 336 | userIds = userOrganizationMappingService.getUserIdByOrganizationIds(tenantId,null, organizationId); |
334 | 337 | queryMap.put("userIds", userIds); |
338 | + }else if(null!=organizationIds){ | |
339 | + userIds = userOrganizationMappingService.getUserIdByOrganizationIds(tenantId,null, organizationIds.toArray(new String[0])); | |
340 | + queryMap.put("userIds", userIds); | |
335 | 341 | } |
336 | 342 | if (isPtSysadmin) { |
337 | 343 | if (null != organizationId && (userIds.size() == FastIotConstants.MagicNumber.ZERO)) { | ... | ... |
... | ... | @@ -55,19 +55,22 @@ public class TkAlarmInfoServiceImpl implements TkAlarmInfoService { |
55 | 55 | String deviceName, |
56 | 56 | DeviceTypeEnum deviceType, |
57 | 57 | EntityType originatorType, |
58 | - String organizationId) { | |
58 | + String organizationId, | |
59 | + List<String> organizationIds) { | |
59 | 60 | StringBuilder defaultOrderFields = new StringBuilder("status asc,"); |
60 | 61 | defaultOrderFields.append(ModelConstants.CREATED_TIME_PROPERTY); |
61 | 62 | IPage<TkAlarmEntity> page = getPage(pageMap, defaultOrderFields.toString(), OrderTypeEnum.DESC); |
62 | - List<String> ids = new ArrayList<>(); | |
63 | + List<String> ids = null!= organizationIds ? organizationIds : null; | |
63 | 64 | if (StringUtils.isNotBlank(organizationId)) { |
64 | 65 | List<String> filter = new ArrayList<>(); |
65 | 66 | filter.add(organizationId); |
67 | + List<String> orgIds = new ArrayList<>(); | |
66 | 68 | List<OrganizationDTO> all = |
67 | 69 | organizationService.findOrganizationTreeList(tenantId.getId().toString(),null, filter); |
68 | 70 | for (OrganizationDTO item : all) { |
69 | - ids.add(item.getId()); | |
71 | + orgIds.add(item.getId()); | |
70 | 72 | } |
73 | + ids = orgIds; | |
71 | 74 | } |
72 | 75 | |
73 | 76 | IPage<TkAlarmEntity> tbDatas = |
... | ... | @@ -84,7 +87,7 @@ public class TkAlarmInfoServiceImpl implements TkAlarmInfoService { |
84 | 87 | deviceName, |
85 | 88 | deviceType, |
86 | 89 | originatorType, |
87 | - ids.size() > 0 ? ids : null); | |
90 | + null!=ids&&ids.size() > 0 ? ids : null); | |
88 | 91 | return new TkPageData<>(tbDatas.getRecords(), tbDatas.getTotal()); |
89 | 92 | } |
90 | 93 | ... | ... |
... | ... | @@ -47,7 +47,8 @@ public class TkDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper, |
47 | 47 | () -> new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage())); |
48 | 48 | String organizationId = |
49 | 49 | null != queryMap.get("organizationId") ? queryMap.get("organizationId").toString() : null; |
50 | - List<String> organizationIds = null; | |
50 | + List<String> organizationIds = | |
51 | + null!= queryMap.get("organizationIds")?(List<String>)queryMap.get("organizationIds"):null; | |
51 | 52 | if (null != organizationId) { |
52 | 53 | List<OrganizationDTO> list = |
53 | 54 | organizationService.findOrganizationTreeList( | ... | ... |
... | ... | @@ -11,6 +11,7 @@ import org.thingsboard.server.common.data.yunteng.constant.QueryConstant; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
14 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
14 | 15 | import org.thingsboard.server.common.data.yunteng.dto.TkDeviceStateLogDTO; |
15 | 16 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
16 | 17 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceStateLogEntity; |
... | ... | @@ -31,7 +32,7 @@ public class TkDeviceStateLogServiceImpl |
31 | 32 | |
32 | 33 | @Override |
33 | 34 | public TkPageData<TkDeviceStateLogDTO> page( |
34 | - boolean isCustomer, String tenantId, Map<String, Object> queryMap) { | |
35 | + boolean isCustomer,boolean isPtCommonTenant, String tenantId, Map<String, Object> queryMap) { | |
35 | 36 | String deviceName = |
36 | 37 | Optional.ofNullable(queryMap.get("deviceName")).map(Object::toString).orElse(null); |
37 | 38 | String organizationName = |
... | ... | @@ -49,19 +50,26 @@ public class TkDeviceStateLogServiceImpl |
49 | 50 | List<String> deviceIds = null; |
50 | 51 | if (isCustomer) { |
51 | 52 | String customerId = |
52 | - null != queryMap.get(QueryConstant.CUSTOMER_ID) | |
53 | - ? (String) queryMap.get(QueryConstant.CUSTOMER_ID) | |
54 | - : null; | |
53 | + null != queryMap.get(QueryConstant.CUSTOMER_ID) | |
54 | + ? (String) queryMap.get(QueryConstant.CUSTOMER_ID) | |
55 | + : null; | |
55 | 56 | deviceIds = deviceMapper.findDeviceIdsByCustomerId(customerId); |
56 | 57 | if (null == deviceIds || deviceIds.isEmpty()) { |
57 | 58 | return new TkPageData<>(new ArrayList<>(), 0); |
58 | 59 | } |
59 | 60 | } |
61 | + if(isPtCommonTenant){ | |
62 | + List<DeviceDTO> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId((List<String>) queryMap.get("orgIds"), | |
63 | + null,null,null,null); | |
64 | + List<String> finalTbDevices = new ArrayList<>(); | |
65 | + devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId())); | |
66 | + deviceIds = finalTbDevices; | |
67 | + } | |
60 | 68 | LambdaQueryWrapper<TkDeviceStateLogEntity> queryWrapper = |
61 | 69 | new LambdaQueryWrapper<TkDeviceStateLogEntity>() |
62 | 70 | .eq(TkDeviceStateLogEntity::getTenantId, tenantId) |
63 | 71 | .eq(null != status, TkDeviceStateLogEntity::getStatus, status) |
64 | - .in(isCustomer, TkDeviceStateLogEntity::getTbDeviceId, deviceIds) | |
72 | + .in(isCustomer||isPtCommonTenant, TkDeviceStateLogEntity::getTbDeviceId, deviceIds) | |
65 | 73 | .like( |
66 | 74 | StringUtils.isNotEmpty(deviceName), |
67 | 75 | TkDeviceStateLogEntity::getDeviceName, | ... | ... |
... | ... | @@ -45,10 +45,7 @@ import org.thingsboard.server.dao.usagerecord.ApiUsageStateService; |
45 | 45 | import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper; |
46 | 46 | import org.thingsboard.server.dao.yunteng.mapper.TkAlarmMapper; |
47 | 47 | import org.thingsboard.server.dao.yunteng.mapper.UserMapper; |
48 | -import org.thingsboard.server.dao.yunteng.service.HomePageService; | |
49 | -import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService; | |
50 | -import org.thingsboard.server.dao.yunteng.service.TkTenantService; | |
51 | -import org.thingsboard.server.dao.yunteng.service.TkUserService; | |
48 | +import org.thingsboard.server.dao.yunteng.service.*; | |
52 | 49 | |
53 | 50 | @Service |
54 | 51 | @RequiredArgsConstructor |
... | ... | @@ -74,11 +71,14 @@ public class TkHomePageServiceImpl implements HomePageService { |
74 | 71 | |
75 | 72 | private final TkDeviceProfileService tkDeviceProfileService; |
76 | 73 | |
74 | + private final TkOrganizationService organizationService; | |
75 | + | |
77 | 76 | @Override |
78 | 77 | public HomePageLeftTopDTO getHomePageLeftTopInfo( |
79 | 78 | boolean isPtSysAdmin, |
80 | 79 | boolean isPtAdmin, |
81 | 80 | boolean isTenantAdmin, |
81 | + boolean isPtCommonTenant, | |
82 | 82 | String tenantId, |
83 | 83 | String currentUserId) |
84 | 84 | throws ExecutionException, InterruptedException { |
... | ... | @@ -99,6 +99,7 @@ public class TkHomePageServiceImpl implements HomePageService { |
99 | 99 | TenantId currentTenantId = TenantId.fromUUID(UUID.fromString(tenantId)); |
100 | 100 | String customerId = null; |
101 | 101 | List<DeviceDTO> deviceList; |
102 | + List<String> orgIds = null; | |
102 | 103 | if (isPtSysAdmin || isPtAdmin) { |
103 | 104 | setTenantInfoData(homePageLeftTopDTO, todayBegin, todayEnd); |
104 | 105 | setCustomerInfoData(homePageLeftTopDTO, todayBegin, todayEnd); |
... | ... | @@ -112,26 +113,40 @@ public class TkHomePageServiceImpl implements HomePageService { |
112 | 113 | setTodayAlarmAndMessageInfo( |
113 | 114 | todayBegin, todayEnd, currentTenantId, apiUsageState.getId(), messageInfo, alarm); |
114 | 115 | |
115 | - } else { | |
116 | - customerId = userMapper.findCustomerIdByUserId(currentUserId); | |
117 | - if (StringUtils.isNotEmpty(customerId)) { | |
118 | - // 查询customerId | |
119 | - queryMap.put("customerId", customerId); | |
120 | - List<String> tbDevices = deviceMapper.findDeviceIdsByCustomerId(customerId); | |
116 | + }else { | |
117 | + List<String> tbDevices = null; | |
118 | + List<BaseHomePageTop> alarmList = null; | |
119 | + long startTs = todayBegin.toInstant(ZoneOffset.of("+8")).toEpochMilli(); | |
120 | + if(isPtCommonTenant){ | |
121 | + //查询所有组织id | |
122 | + orgIds = organizationService.currentUserOrganizationAllIds(currentUserId); | |
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 | + alarmList = deviceMapper.findDeviceAlarmInfoByCustomer(startTs, null,orgIds); | |
131 | + }else{ | |
132 | + customerId = userMapper.findCustomerIdByUserId(currentUserId); | |
133 | + if (StringUtils.isNotEmpty(customerId)) { | |
134 | + // 查询customerId | |
135 | + queryMap.put("customerId", customerId); | |
136 | + tbDevices = deviceMapper.findDeviceIdsByCustomerId(customerId); | |
137 | + } | |
138 | + alarmList = deviceMapper.findDeviceAlarmInfoByCustomer(startTs, customerId,null); | |
139 | + } | |
121 | 140 | for (String devId : tbDevices) { |
122 | 141 | setCustomerMessageInfo( |
123 | 142 | todayBegin, todayEnd, currentTenantId, DeviceId.fromString(devId), messageInfo); |
124 | 143 | } |
125 | - long startTs = todayBegin.toInstant(ZoneOffset.of("+8")).toEpochMilli(); | |
126 | - List<BaseHomePageTop> alarmList = | |
127 | - deviceMapper.findDeviceAlarmInfoByCustomer(startTs, customerId); | |
128 | 144 | if (alarmList.size() > zero) { |
129 | 145 | BaseHomePageTop baseHomePageTop = alarmList.get(0); |
130 | 146 | alarm.setSumCount(baseHomePageTop.getSumCount()); |
131 | 147 | alarm.setTodayAdd( |
132 | 148 | baseHomePageTop.getTodayAdd() == null ? zero : baseHomePageTop.getTodayAdd()); |
133 | 149 | } |
134 | - } | |
135 | 150 | } |
136 | 151 | deviceList = deviceMapper.findDevices(queryMap); |
137 | 152 | homeDeviceInfo = new HomeDeviceInfoDTO(zero); |
... | ... | @@ -140,7 +155,7 @@ public class TkHomePageServiceImpl implements HomePageService { |
140 | 155 | } |
141 | 156 | if (!isPtSysAdmin && !isPtAdmin) { |
142 | 157 | List<DeviceProfileDTO> deviceProfileDTOList = null; |
143 | - if (isTenantAdmin) { | |
158 | + if (isTenantAdmin||isPtCommonTenant) { | |
144 | 159 | deviceProfileDTOList = tkDeviceProfileService.findDeviceProfile(tenantId); |
145 | 160 | |
146 | 161 | } else { | ... | ... |
... | ... | @@ -67,7 +67,9 @@ public class TkReportFromConfigServiceImpl |
67 | 67 | userOrganizationMappingService.compareOrganizationIdsByCustomerId( |
68 | 68 | organizationIds, userId); |
69 | 69 | } |
70 | - queryMap.put("organizationIds", organizationIds); | |
70 | + if(null!=organizationIds){ | |
71 | + queryMap.put("organizationIds", organizationIds); | |
72 | + } | |
71 | 73 | IPage<ReportFormConfigDTO> page = |
72 | 74 | baseMapper.getReportFormConfigPage( |
73 | 75 | getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false), queryMap); | ... | ... |
... | ... | @@ -79,7 +79,7 @@ public class TkReportGenerateRecordServiceImpl |
79 | 79 | Optional.ofNullable(queryMap.get("executeStatus")) |
80 | 80 | .map(obj -> Integer.valueOf(obj.toString())) |
81 | 81 | .orElse(null); |
82 | - List<String> organizationIds = null; | |
82 | + List<String> organizationIds = null!= queryMap.get("organizationIds") ? (List<String>)queryMap.get("organizationIds") : null; | |
83 | 83 | boolean isCustomer =!tenantAdmin && null != queryMap.get("userId"); |
84 | 84 | if (isCustomer) { |
85 | 85 | organizationIds = | ... | ... |
... | ... | @@ -73,7 +73,10 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { |
73 | 73 | @Param("todayTime") Long todayTime, @Param("customerId") String customerId); |
74 | 74 | |
75 | 75 | List<BaseHomePageTop> findDeviceAlarmInfoByCustomer( |
76 | - @Param("todayTime") Long todayTime, @Param("customerId") String customerId); | |
76 | + @Param("todayTime") Long todayTime, | |
77 | + @Param("customerId") String customerId, | |
78 | + @Param("organizationIds") List<String> organizationIds | |
79 | + ); | |
77 | 80 | |
78 | 81 | @Deprecated |
79 | 82 | Integer findDeviceMessageInfoByTs( |
... | ... | @@ -158,4 +161,11 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { |
158 | 161 | @Param("deviceLabel") String deviceLabel, |
159 | 162 | @Param("deviceProfileId") String deviceProfileId, |
160 | 163 | @Param("transportType")TransportTypeEnum transportType) ; |
164 | + | |
165 | + | |
166 | + List<DeviceDTO> findDevicesByProfileIdAndOrganizationId( | |
167 | + @Param("orgIds")List<String> orgIds, | |
168 | + @Param("profileId") String profileId) ; | |
169 | + | |
170 | + | |
161 | 171 | } | ... | ... |
... | ... | @@ -8,7 +8,7 @@ import org.thingsboard.server.dao.yunteng.entities.TkDeviceStateLogEntity; |
8 | 8 | import java.util.Map; |
9 | 9 | |
10 | 10 | public interface TkDeviceStateLogService extends BaseService<TkDeviceStateLogEntity> { |
11 | - TkPageData<TkDeviceStateLogDTO> page(boolean isCustomer,String tenantId,Map<String, Object> queryMap); | |
11 | + TkPageData<TkDeviceStateLogDTO> page(boolean isCustomer,boolean isPtCommonTenant,String tenantId,Map<String, Object> queryMap); | |
12 | 12 | |
13 | 13 | boolean deleteTkDeviceStateLog(DeleteDTO deleteDTO); |
14 | 14 | ... | ... |
... | ... | @@ -23,7 +23,7 @@ public interface TkUserService { |
23 | 23 | List<UserDetailsDTO> findUserDetailsByUsername(String username, String tenantId); |
24 | 24 | |
25 | 25 | UserDTO saveAccount( |
26 | - UserDTO userDTO, boolean sendEmail, boolean sendMsg, boolean isTenantAdmin, String tenantId); | |
26 | + UserDTO userDTO, boolean sendEmail, boolean sendMsg, boolean isTenantAdmin, boolean isCommonTenant, String tenantId); | |
27 | 27 | |
28 | 28 | String getActivationLink(String userId, boolean isPtSysadmin, String tenantId); |
29 | 29 | ... | ... |
... | ... | @@ -245,6 +245,12 @@ |
245 | 245 | <if test="queryMap.customerId !=null and queryMap.customerId !=''"> |
246 | 246 | AND d.customer_id :: TEXT = #{queryMap.customerId} |
247 | 247 | </if> |
248 | + <if test="queryMap.organizationIds !=null"> | |
249 | + AND ifd.organization_id IN | |
250 | + <foreach collection="queryMap.organizationIds" item="orgId" open="(" separator="," close=")"> | |
251 | + #{orgId} | |
252 | + </foreach> | |
253 | + </if> | |
248 | 254 | </where> |
249 | 255 | </select> |
250 | 256 | <select id="getRelationDevicePage" resultMap="relationDeviceMap"> |
... | ... | @@ -302,8 +308,16 @@ |
302 | 308 | FROM alarm m |
303 | 309 | LEFT JOIN tk_device d ON m.originator_id = d.tb_device_id::uuid |
304 | 310 | LEFT JOIN device bd ON bd.id = d.tb_device_id::uuid |
305 | - WHERE bd.customer_id ::TEXT = #{customerId} | |
306 | - AND m.originator_type = 5; | |
311 | + WHERE m.originator_type = 5 | |
312 | + <if test="customerId !=null"> | |
313 | + AND bd.customer_id ::TEXT = #{customerId} | |
314 | + </if> | |
315 | + <if test="organizationIds !=null"> | |
316 | + AND d.organization_id IN | |
317 | + <foreach collection="organizationIds" item="orgId" open="(" separator="," close=")"> | |
318 | + #{orgId} | |
319 | + </foreach> | |
320 | + </if> | |
307 | 321 | </select> |
308 | 322 | |
309 | 323 | <select id="findDeviceMessageInfoByTs" resultType="java.lang.Integer"> |
... | ... | @@ -518,4 +532,20 @@ |
518 | 532 | AND ifd.tenant_id = #{tenantId} |
519 | 533 | AND d.id::TEXT = #{tbDeviceId} |
520 | 534 | </select> |
535 | + | |
536 | + <select id="findDevicesByProfileIdAndOrganizationId" resultMap="deviceMap"> | |
537 | + SELECT | |
538 | + <include refid="basicColumns"/>,dev.transport_type | |
539 | + FROM tk_device ifd | |
540 | + left join device_profile dev on ifd.profile_id = dev.id :: TEXT | |
541 | + where | |
542 | + 1=1 | |
543 | + <if test="profileId !=null and profileId !=''"> | |
544 | + AND ifd.profile_id = #{profileId} | |
545 | + </if> | |
546 | + and ifd.organization_id in | |
547 | + <foreach collection="orgIds" item="orgId" open="(" separator="," close=")"> | |
548 | + #{orgId} | |
549 | + </foreach> | |
550 | + </select> | |
521 | 551 | </mapper> | ... | ... |
... | ... | @@ -37,10 +37,16 @@ |
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> | |
40 | 43 | FROM tk_task_center tc |
41 | 44 | <if test="queryMap.tbDeviceId !=null and queryMap.tbDeviceId !=''"> |
42 | 45 | LEFT JOIN tk_device_task_center tdc ON tc.id = tdc.task_center_id |
43 | 46 | </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> | |
44 | 50 | <where> |
45 | 51 | <if test="queryMap.tenantId !=null and queryMap.tenantId !=''"> |
46 | 52 | AND tc.tenant_id = #{queryMap.tenantId} |
... | ... | @@ -54,6 +60,12 @@ |
54 | 60 | <if test="queryMap.tbDeviceId !=null and queryMap.tbDeviceId !=''"> |
55 | 61 | AND tdc.tb_device_id = #{queryMap.tbDeviceId} |
56 | 62 | </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> | |
57 | 69 | </where> |
58 | 70 | </select> |
59 | 71 | </mapper> | ... | ... |