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,7 +124,8 @@ public class TkDeviceProfileController extends BaseController { | ||
124 | 124 | ||
125 | @GetMapping("{id}") | 125 | @GetMapping("{id}") |
126 | @ApiOperation("详情") | 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 | public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id) | 129 | public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id) |
129 | throws ThingsboardException { | 130 | throws ThingsboardException { |
130 | return ResponseEntity.of( | 131 | return ResponseEntity.of( |
@@ -142,23 +143,32 @@ public class TkDeviceProfileController extends BaseController { | @@ -142,23 +143,32 @@ public class TkDeviceProfileController extends BaseController { | ||
142 | @RequestParam(value = ORDER_FILED, required = false) String orderBy, | 143 | @RequestParam(value = ORDER_FILED, required = false) String orderBy, |
143 | @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | 144 | @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) |
144 | throws ThingsboardException { | 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 | @GetMapping("/me/list") | 158 | @GetMapping("/me/list") |
158 | @ApiOperation("选项列表") | 159 | @ApiOperation("选项列表") |
160 | + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})") | ||
159 | public ResponseEntity listDeviceProfile() throws ThingsboardException { | 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 | return ResponseEntity.ok(results); | 172 | return ResponseEntity.ok(results); |
163 | } | 173 | } |
164 | 174 | ||
@@ -177,18 +187,20 @@ public class TkDeviceProfileController extends BaseController { | @@ -177,18 +187,20 @@ public class TkDeviceProfileController extends BaseController { | ||
177 | } | 187 | } |
178 | 188 | ||
179 | private void deleteTbDeviceProfile(String profileId) throws ThingsboardException { | 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 | DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(dto.getTbProfileId())); | 194 | DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(dto.getTbProfileId())); |
183 | DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.DELETE); | 195 | DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.DELETE); |
184 | deviceProfileService.deleteDeviceProfile(getTenantId(), deviceProfileId); | 196 | deviceProfileService.deleteDeviceProfile(getTenantId(), deviceProfileId); |
185 | 197 | ||
186 | tbClusterService.onDeviceProfileDelete(deviceProfile, null); | 198 | tbClusterService.onDeviceProfileDelete(deviceProfile, null); |
187 | tbClusterService.broadcastEntityStateChangeEvent( | 199 | tbClusterService.broadcastEntityStateChangeEvent( |
188 | - deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED); | 200 | + deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED); |
189 | 201 | ||
190 | logEntityAction( | 202 | logEntityAction( |
191 | - deviceProfileId, deviceProfile, null, ActionType.DELETED, null, deviceProfileId); | 203 | + deviceProfileId, deviceProfile, null, ActionType.DELETED, null, deviceProfileId); |
192 | 204 | ||
193 | sendEntityNotificationMsg(getTenantId(), deviceProfile.getId(), EdgeEventActionType.DELETED); | 205 | sendEntityNotificationMsg(getTenantId(), deviceProfile.getId(), EdgeEventActionType.DELETED); |
194 | } | 206 | } |
@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils; | @@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils; | ||
10 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
11 | import org.springframework.transaction.annotation.Transactional; | 11 | import org.springframework.transaction.annotation.Transactional; |
12 | import org.thingsboard.server.common.data.DeviceProfile; | 12 | import org.thingsboard.server.common.data.DeviceProfile; |
13 | +import org.thingsboard.server.common.data.id.CustomerId; | ||
13 | import org.thingsboard.server.common.data.id.TenantId; | 14 | import org.thingsboard.server.common.data.id.TenantId; |
14 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | 15 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
15 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | 16 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
@@ -178,24 +179,21 @@ public class TkDeviceProfileServiceImpl | @@ -178,24 +179,21 @@ public class TkDeviceProfileServiceImpl | ||
178 | IPage<DeviceProfileDTO> result = new Page<>(); | 179 | IPage<DeviceProfileDTO> result = new Page<>(); |
179 | if (!isTenantAdmin) { | 180 | if (!isTenantAdmin) { |
180 | List<DeviceDTO> deviceDTOS = deviceMapper.findDeviceInfoByCustomerId(tenantIdStr, customerId); | 181 | List<DeviceDTO> deviceDTOS = deviceMapper.findDeviceInfoByCustomerId(tenantIdStr, customerId); |
181 | - if(null == deviceDTOS || deviceDTOS.isEmpty()){ | 182 | + if (null == deviceDTOS || deviceDTOS.isEmpty()) { |
182 | return getPageData(result, DeviceProfileDTO.class); | 183 | return getPageData(result, DeviceProfileDTO.class); |
183 | } | 184 | } |
184 | deviceProfileIds = | 185 | deviceProfileIds = |
185 | - Optional.ofNullable(deviceDTOS) | 186 | + Optional.of(deviceDTOS) |
186 | .map( | 187 | .map( |
187 | devices -> | 188 | devices -> |
188 | - devices.stream().map(obj -> obj.getProfileId()).collect(Collectors.toList())) | 189 | + devices.stream().map(DeviceDTO::getDeviceProfileId).collect(Collectors.toList())) |
189 | .orElse(null); | 190 | .orElse(null); |
190 | } | 191 | } |
191 | IPage<TkDeviceProfileEntity> currentPage = | 192 | IPage<TkDeviceProfileEntity> currentPage = |
192 | getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false); | 193 | getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false); |
193 | result = | 194 | result = |
194 | baseMapper.getProfilePage( | 195 | baseMapper.getProfilePage( |
195 | - currentPage, | ||
196 | - tenantIdStr, | ||
197 | - profileName, | ||
198 | - transportType,deviceProfileIds); | 196 | + currentPage, tenantIdStr, profileName, transportType, deviceProfileIds); |
199 | return getPageData(result, DeviceProfileDTO.class); | 197 | return getPageData(result, DeviceProfileDTO.class); |
200 | } | 198 | } |
201 | 199 | ||
@@ -205,6 +203,32 @@ public class TkDeviceProfileServiceImpl | @@ -205,6 +203,32 @@ public class TkDeviceProfileServiceImpl | ||
205 | } | 203 | } |
206 | 204 | ||
207 | @Override | 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 | public List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId, List<String> ids) { | 232 | public List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId, List<String> ids) { |
209 | if (StringUtils.isEmpty(tenantId) || null == ids) { | 233 | if (StringUtils.isEmpty(tenantId) || null == ids) { |
210 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 234 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
1 | package org.thingsboard.server.dao.yunteng.service; | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | ||
3 | +import org.thingsboard.server.common.data.id.CustomerId; | ||
3 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
4 | -import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | ||
5 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 5 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
6 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; | 6 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; |
7 | 7 | ||
@@ -24,6 +24,8 @@ public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntit | @@ -24,6 +24,8 @@ public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntit | ||
24 | 24 | ||
25 | List<DeviceProfileDTO> findDeviceProfile(String tenantId,String scriptId); | 25 | List<DeviceProfileDTO> findDeviceProfile(String tenantId,String scriptId); |
26 | 26 | ||
27 | + List<DeviceProfileDTO> findCustomerDeviceProfiles(String tenantId, CustomerId customerId); | ||
28 | + | ||
27 | List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId,List<String> ids); | 29 | List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId,List<String> ids); |
28 | 30 | ||
29 | /** | 31 | /** |