Commit 2ef7cd76a307e28b36878a260a0cd6b93d4c01c8
1 parent
e98ba3e1
fix: [DEFECT-878] customer query device profile
Showing
3 changed files
with
63 additions
and
25 deletions
... | ... | @@ -124,7 +124,8 @@ public class TkDeviceProfileController extends BaseController { |
124 | 124 | |
125 | 125 | @GetMapping("{id}") |
126 | 126 | @ApiOperation("详情") |
127 | - @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:deviceProfile:get'})") | |
127 | + @PreAuthorize( | |
128 | + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:deviceProfile:get'})") | |
128 | 129 | public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id) |
129 | 130 | throws ThingsboardException { |
130 | 131 | return ResponseEntity.of( |
... | ... | @@ -142,23 +143,32 @@ public class TkDeviceProfileController extends BaseController { |
142 | 143 | @RequestParam(value = ORDER_FILED, required = false) String orderBy, |
143 | 144 | @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) |
144 | 145 | throws ThingsboardException { |
145 | - Map<String,Object> queryMap = new HashMap<>(); | |
146 | - queryMap.put(PAGE,page); | |
147 | - queryMap.put(PAGE_SIZE,pageSize); | |
148 | - queryMap.put(ORDER_FILED,orderBy); | |
149 | - queryMap.put(ORDER_TYPE,orderType); | |
150 | - queryMap.put("name",name); | |
151 | - queryMap.put("transportType",transportType); | |
152 | - queryMap.put(TENANT_ID,getCurrentUser().getCurrentTenantId()); | |
153 | - queryMap.put(CUSTOMER_ID,getCurrentUser().getCustomerId().toString()); | |
154 | - return ytDeviceProfileService.page(queryMap,getCurrentUser().isTenantAdmin()); | |
146 | + Map<String, Object> queryMap = new HashMap<>(); | |
147 | + queryMap.put(PAGE, page); | |
148 | + queryMap.put(PAGE_SIZE, pageSize); | |
149 | + queryMap.put(ORDER_FILED, orderBy); | |
150 | + queryMap.put(ORDER_TYPE, orderType); | |
151 | + queryMap.put("name", name); | |
152 | + queryMap.put("transportType", transportType); | |
153 | + queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId()); | |
154 | + queryMap.put(CUSTOMER_ID, getCurrentUser().getCustomerId().toString()); | |
155 | + return ytDeviceProfileService.page(queryMap, getCurrentUser().isTenantAdmin()); | |
155 | 156 | } |
156 | 157 | |
157 | 158 | @GetMapping("/me/list") |
158 | 159 | @ApiOperation("选项列表") |
160 | + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})") | |
159 | 161 | public ResponseEntity listDeviceProfile() throws ThingsboardException { |
160 | - List<DeviceProfileDTO> results = | |
161 | - ytDeviceProfileService.findDeviceProfile(getCurrentUser().getCurrentTenantId(), null); | |
162 | + List<DeviceProfileDTO> results; | |
163 | + String tenantId = getCurrentUser().getCurrentTenantId(); | |
164 | + if (getCurrentUser().isTenantAdmin()) { | |
165 | + results = ytDeviceProfileService.findDeviceProfile(tenantId, null); | |
166 | + } else { | |
167 | + results = | |
168 | + ytDeviceProfileService.findCustomerDeviceProfiles( | |
169 | + tenantId, getCurrentUser().getCustomerId()); | |
170 | + } | |
171 | + | |
162 | 172 | return ResponseEntity.ok(results); |
163 | 173 | } |
164 | 174 | |
... | ... | @@ -177,18 +187,20 @@ public class TkDeviceProfileController extends BaseController { |
177 | 187 | } |
178 | 188 | |
179 | 189 | private void deleteTbDeviceProfile(String profileId) throws ThingsboardException { |
180 | - DeviceProfileDTO dto = ytDeviceProfileService.findDeviceProfileById(getCurrentUser().getCurrentTenantId(), profileId); | |
181 | - if(null != dto){ | |
190 | + DeviceProfileDTO dto = | |
191 | + ytDeviceProfileService.findDeviceProfileById( | |
192 | + getCurrentUser().getCurrentTenantId(), profileId); | |
193 | + if (null != dto) { | |
182 | 194 | DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(dto.getTbProfileId())); |
183 | 195 | DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.DELETE); |
184 | 196 | deviceProfileService.deleteDeviceProfile(getTenantId(), deviceProfileId); |
185 | 197 | |
186 | 198 | tbClusterService.onDeviceProfileDelete(deviceProfile, null); |
187 | 199 | tbClusterService.broadcastEntityStateChangeEvent( |
188 | - deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED); | |
200 | + deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED); | |
189 | 201 | |
190 | 202 | logEntityAction( |
191 | - deviceProfileId, deviceProfile, null, ActionType.DELETED, null, deviceProfileId); | |
203 | + deviceProfileId, deviceProfile, null, ActionType.DELETED, null, deviceProfileId); | |
192 | 204 | |
193 | 205 | sendEntityNotificationMsg(getTenantId(), deviceProfile.getId(), EdgeEventActionType.DELETED); |
194 | 206 | } | ... | ... |
... | ... | @@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils; |
10 | 10 | import org.springframework.stereotype.Service; |
11 | 11 | import org.springframework.transaction.annotation.Transactional; |
12 | 12 | import org.thingsboard.server.common.data.DeviceProfile; |
13 | +import org.thingsboard.server.common.data.id.CustomerId; | |
13 | 14 | import org.thingsboard.server.common.data.id.TenantId; |
14 | 15 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
15 | 16 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
... | ... | @@ -178,24 +179,21 @@ public class TkDeviceProfileServiceImpl |
178 | 179 | IPage<DeviceProfileDTO> result = new Page<>(); |
179 | 180 | if (!isTenantAdmin) { |
180 | 181 | List<DeviceDTO> deviceDTOS = deviceMapper.findDeviceInfoByCustomerId(tenantIdStr, customerId); |
181 | - if(null == deviceDTOS || deviceDTOS.isEmpty()){ | |
182 | + if (null == deviceDTOS || deviceDTOS.isEmpty()) { | |
182 | 183 | return getPageData(result, DeviceProfileDTO.class); |
183 | 184 | } |
184 | 185 | deviceProfileIds = |
185 | - Optional.ofNullable(deviceDTOS) | |
186 | + Optional.of(deviceDTOS) | |
186 | 187 | .map( |
187 | 188 | devices -> |
188 | - devices.stream().map(obj -> obj.getProfileId()).collect(Collectors.toList())) | |
189 | + devices.stream().map(DeviceDTO::getDeviceProfileId).collect(Collectors.toList())) | |
189 | 190 | .orElse(null); |
190 | 191 | } |
191 | 192 | IPage<TkDeviceProfileEntity> currentPage = |
192 | 193 | getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false); |
193 | 194 | result = |
194 | 195 | baseMapper.getProfilePage( |
195 | - currentPage, | |
196 | - tenantIdStr, | |
197 | - profileName, | |
198 | - transportType,deviceProfileIds); | |
196 | + currentPage, tenantIdStr, profileName, transportType, deviceProfileIds); | |
199 | 197 | return getPageData(result, DeviceProfileDTO.class); |
200 | 198 | } |
201 | 199 | |
... | ... | @@ -205,6 +203,32 @@ public class TkDeviceProfileServiceImpl |
205 | 203 | } |
206 | 204 | |
207 | 205 | @Override |
206 | + public List<DeviceProfileDTO> findCustomerDeviceProfiles(String tenantId, CustomerId customerId) { | |
207 | + List<DeviceDTO> deviceDTOS = | |
208 | + deviceMapper.findDeviceInfoByCustomerId(tenantId, customerId.toString()); | |
209 | + List<String> deviceProfileIds = | |
210 | + Optional.ofNullable(deviceDTOS) | |
211 | + .map( | |
212 | + devices -> | |
213 | + devices.stream().map(DeviceDTO::getDeviceProfileId).collect(Collectors.toList())) | |
214 | + .orElse(null); | |
215 | + if (null == deviceProfileIds || deviceProfileIds.isEmpty()) { | |
216 | + return null; | |
217 | + } | |
218 | + List<TkDeviceProfileEntity> entities = | |
219 | + baseMapper.selectList( | |
220 | + new LambdaQueryWrapper<TkDeviceProfileEntity>() | |
221 | + .eq(TkDeviceProfileEntity::getTenantId, tenantId) | |
222 | + .in(TkDeviceProfileEntity::getId, deviceProfileIds)); | |
223 | + if (null != entities && !entities.isEmpty()) { | |
224 | + return entities.stream() | |
225 | + .map(obj -> obj.getDTO(DeviceProfileDTO.class)) | |
226 | + .collect(Collectors.toList()); | |
227 | + } | |
228 | + return null; | |
229 | + } | |
230 | + | |
231 | + @Override | |
208 | 232 | public List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId, List<String> ids) { |
209 | 233 | if (StringUtils.isEmpty(tenantId) || null == ids) { |
210 | 234 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | |
3 | +import org.thingsboard.server.common.data.id.CustomerId; | |
3 | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
4 | -import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
5 | 5 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
6 | 6 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; |
7 | 7 | |
... | ... | @@ -24,6 +24,8 @@ public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntit |
24 | 24 | |
25 | 25 | List<DeviceProfileDTO> findDeviceProfile(String tenantId,String scriptId); |
26 | 26 | |
27 | + List<DeviceProfileDTO> findCustomerDeviceProfiles(String tenantId, CustomerId customerId); | |
28 | + | |
27 | 29 | List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId,List<String> ids); |
28 | 30 | |
29 | 31 | /** | ... | ... |