Commit 2cac34d598681ccbc2e35ee329743b3cf678d463
1 parent
31331cee
feat: add query param deviceType for device profile
Showing
6 changed files
with
56 additions
and
37 deletions
... | ... | @@ -2,6 +2,7 @@ package org.thingsboard.server.controller.yunteng; |
2 | 2 | |
3 | 3 | import io.swagger.annotations.Api; |
4 | 4 | import io.swagger.annotations.ApiOperation; |
5 | +import io.swagger.annotations.ApiParam; | |
5 | 6 | import lombok.RequiredArgsConstructor; |
6 | 7 | import org.apache.commons.lang3.StringUtils; |
7 | 8 | import org.springframework.http.ResponseEntity; |
... | ... | @@ -27,6 +28,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidatio |
27 | 28 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
28 | 29 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
29 | 30 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
31 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | |
30 | 32 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
31 | 33 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
32 | 34 | import org.thingsboard.server.common.msg.queue.ServiceQueue; |
... | ... | @@ -158,15 +160,18 @@ public class TkDeviceProfileController extends BaseController { |
158 | 160 | @GetMapping("/me/list") |
159 | 161 | @ApiOperation("选项列表") |
160 | 162 | @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})") |
161 | - public ResponseEntity listDeviceProfile() throws ThingsboardException { | |
163 | + public ResponseEntity listDeviceProfile( | |
164 | + @ApiParam(value = "设备类型") @RequestParam(value = "deviceType", required = false) | |
165 | + DeviceTypeEnum deviceType) | |
166 | + throws ThingsboardException { | |
162 | 167 | List<DeviceProfileDTO> results; |
163 | 168 | String tenantId = getCurrentUser().getCurrentTenantId(); |
164 | 169 | if (getCurrentUser().isTenantAdmin()) { |
165 | - results = ytDeviceProfileService.findDeviceProfile(tenantId, null); | |
170 | + results = ytDeviceProfileService.findDeviceProfile(tenantId, null,deviceType); | |
166 | 171 | } else { |
167 | 172 | results = |
168 | 173 | ytDeviceProfileService.findCustomerDeviceProfiles( |
169 | - tenantId, getCurrentUser().getCustomerId()); | |
174 | + tenantId, getCurrentUser().getCustomerId(),deviceType); | |
170 | 175 | } |
171 | 176 | |
172 | 177 | return ResponseEntity.ok(results); | ... | ... |
... | ... | @@ -103,7 +103,7 @@ public class TkDeviceScriptController extends BaseController { |
103 | 103 | convertJs = scriptDTO.getConvertJs(); |
104 | 104 | } |
105 | 105 | } |
106 | - List<DeviceProfileDTO> usedProfiles = ytDeviceProfileService.findDeviceProfile(tenantId, id); | |
106 | + List<DeviceProfileDTO> usedProfiles = ytDeviceProfileService.findDeviceProfile(tenantId, id,null); | |
107 | 107 | for (DeviceProfileDTO profile : usedProfiles) { |
108 | 108 | DeviceProfile tbDeviceProfile = |
109 | 109 | buildTbDeviceProfileFromDeviceProfileDTO( | ... | ... |
... | ... | @@ -18,6 +18,7 @@ import org.thingsboard.server.common.data.yunteng.constant.QueryConstant; |
18 | 18 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
19 | 19 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
20 | 20 | import org.thingsboard.server.common.data.yunteng.dto.*; |
21 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | |
21 | 22 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
22 | 23 | import org.thingsboard.server.dao.yunteng.entities.*; |
23 | 24 | import org.thingsboard.server.dao.yunteng.jpa.dao.YtJpaDeviceProfileDao; |
... | ... | @@ -198,19 +199,23 @@ public class TkDeviceProfileServiceImpl |
198 | 199 | } |
199 | 200 | |
200 | 201 | @Override |
201 | - public List<DeviceProfileDTO> findDeviceProfile(String tenantId, String scriptId) { | |
202 | - return baseMapper.profileByScriptId(tenantId, scriptId); | |
202 | + public List<DeviceProfileDTO> findDeviceProfile( | |
203 | + String tenantId, String scriptId, DeviceTypeEnum deviceType) { | |
204 | + return baseMapper.profileByScriptId(tenantId, scriptId, deviceType); | |
203 | 205 | } |
204 | 206 | |
205 | 207 | @Override |
206 | - public List<DeviceProfileDTO> findCustomerDeviceProfiles(String tenantId, CustomerId customerId) { | |
208 | + public List<DeviceProfileDTO> findCustomerDeviceProfiles( | |
209 | + String tenantId, CustomerId customerId, DeviceTypeEnum deviceType) { | |
207 | 210 | List<DeviceDTO> deviceDTOS = |
208 | 211 | deviceMapper.findDeviceInfoByCustomerId(tenantId, customerId.toString()); |
209 | 212 | List<String> deviceProfileIds = |
210 | 213 | Optional.ofNullable(deviceDTOS) |
211 | 214 | .map( |
212 | 215 | devices -> |
213 | - devices.stream().map(DeviceDTO::getDeviceProfileId).collect(Collectors.toList())) | |
216 | + devices.stream() | |
217 | + .map(DeviceDTO::getDeviceProfileId) | |
218 | + .collect(Collectors.toList())) | |
214 | 219 | .orElse(null); |
215 | 220 | if (null == deviceProfileIds || deviceProfileIds.isEmpty()) { |
216 | 221 | return null; |
... | ... | @@ -219,6 +224,7 @@ public class TkDeviceProfileServiceImpl |
219 | 224 | baseMapper.selectList( |
220 | 225 | new LambdaQueryWrapper<TkDeviceProfileEntity>() |
221 | 226 | .eq(TkDeviceProfileEntity::getTenantId, tenantId) |
227 | + .eq(null !=deviceType,TkDeviceProfileEntity::getDeviceType,deviceType) | |
222 | 228 | .in(TkDeviceProfileEntity::getId, deviceProfileIds)); |
223 | 229 | if (null != entities && !entities.isEmpty()) { |
224 | 230 | return entities.stream() | ... | ... |
... | ... | @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | 5 | import org.apache.ibatis.annotations.Mapper; |
6 | 6 | import org.apache.ibatis.annotations.Param; |
7 | 7 | import org.thingsboard.server.common.data.yunteng.dto.*; |
8 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | |
8 | 9 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; |
9 | 10 | |
10 | 11 | import java.util.List; |
... | ... | @@ -27,5 +28,7 @@ public interface TkDeviceProfileMapper extends BaseMapper<TkDeviceProfileEntity> |
27 | 28 | @Param("deviceProfileIds") List<String> deviceProfileIds); |
28 | 29 | |
29 | 30 | List<DeviceProfileDTO> profileByScriptId( |
30 | - @Param("tenantId") String tenantId, @Param("scriptId") String scriptId); | |
31 | + @Param("tenantId") String tenantId, | |
32 | + @Param("scriptId") String scriptId, | |
33 | + @Param("deviceType") DeviceTypeEnum deviceType); | |
31 | 34 | } | ... | ... |
... | ... | @@ -2,6 +2,7 @@ package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | |
3 | 3 | import org.thingsboard.server.common.data.id.CustomerId; |
4 | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
5 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | |
5 | 6 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
6 | 7 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; |
7 | 8 | |
... | ... | @@ -10,43 +11,44 @@ import java.util.Map; |
10 | 11 | import java.util.Optional; |
11 | 12 | import java.util.Set; |
12 | 13 | |
13 | -public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntity>{ | |
14 | +public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntity> { | |
14 | 15 | |
15 | - DeviceProfileDTO insertOrUpdate(DeviceProfileDTO deviceDTO); | |
16 | + DeviceProfileDTO insertOrUpdate(DeviceProfileDTO deviceDTO); | |
16 | 17 | |
17 | - void deleteDeviceProfiles(String tenantId, Set<String> ids); | |
18 | + void deleteDeviceProfiles(String tenantId, Set<String> ids); | |
18 | 19 | |
19 | - void checkDeviceProfiles(String tenantId, Set<String> ids); | |
20 | + void checkDeviceProfiles(String tenantId, Set<String> ids); | |
20 | 21 | |
21 | - Optional<DeviceProfileDTO> getDeviceProfile(String tenantId, String id); | |
22 | + Optional<DeviceProfileDTO> getDeviceProfile(String tenantId, String id); | |
22 | 23 | |
23 | - YtPageData<DeviceProfileDTO> page(Map<String,Object> queryMap,boolean isTenantAdmin); | |
24 | + YtPageData<DeviceProfileDTO> page(Map<String, Object> queryMap, boolean isTenantAdmin); | |
24 | 25 | |
25 | - List<DeviceProfileDTO> findDeviceProfile(String tenantId,String scriptId); | |
26 | + List<DeviceProfileDTO> findDeviceProfile( | |
27 | + String tenantId, String scriptId, DeviceTypeEnum deviceType); | |
26 | 28 | |
27 | - List<DeviceProfileDTO> findCustomerDeviceProfiles(String tenantId, CustomerId customerId); | |
29 | + List<DeviceProfileDTO> findCustomerDeviceProfiles( | |
30 | + String tenantId, CustomerId customerId, DeviceTypeEnum deviceType); | |
28 | 31 | |
29 | - List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId,List<String> ids); | |
32 | + List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId, List<String> ids); | |
30 | 33 | |
31 | - /** | |
32 | - * 验证表单数据有效性 | |
33 | - * | |
34 | - */ | |
35 | - boolean validateFormData(DeviceProfileDTO ytDeviceProfileDTO); | |
34 | + /** 验证表单数据有效性 */ | |
35 | + boolean validateFormData(DeviceProfileDTO ytDeviceProfileDTO); | |
36 | 36 | |
37 | - /** | |
38 | - * 根据设备配置ID获取设备配置信息 | |
39 | - * @param tenantId 租户ID | |
40 | - * @param id 设备配置ID | |
41 | - * @return 设备配置信息 | |
42 | - */ | |
43 | - DeviceProfileDTO findDeviceProfileById(String tenantId, String id); | |
37 | + /** | |
38 | + * 根据设备配置ID获取设备配置信息 | |
39 | + * | |
40 | + * @param tenantId 租户ID | |
41 | + * @param id 设备配置ID | |
42 | + * @return 设备配置信息 | |
43 | + */ | |
44 | + DeviceProfileDTO findDeviceProfileById(String tenantId, String id); | |
44 | 45 | |
45 | - /** | |
46 | - * *根据tb设备ID获取设备配置信息 | |
47 | - * @param tenantId 租户ID | |
48 | - * @param tbProfileId tb设备配置ID | |
49 | - * @return 设备配置信息 | |
50 | - */ | |
51 | - DeviceProfileDTO findByTbDeviceProfileId(String tenantId,String tbProfileId); | |
46 | + /** | |
47 | + * *根据tb设备ID获取设备配置信息 | |
48 | + * | |
49 | + * @param tenantId 租户ID | |
50 | + * @param tbProfileId tb设备配置ID | |
51 | + * @return 设备配置信息 | |
52 | + */ | |
53 | + DeviceProfileDTO findByTbDeviceProfileId(String tenantId, String tbProfileId); | |
52 | 54 | } | ... | ... |