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,6 +2,7 @@ package org.thingsboard.server.controller.yunteng; | ||
2 | 2 | ||
3 | import io.swagger.annotations.Api; | 3 | import io.swagger.annotations.Api; |
4 | import io.swagger.annotations.ApiOperation; | 4 | import io.swagger.annotations.ApiOperation; |
5 | +import io.swagger.annotations.ApiParam; | ||
5 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
6 | import org.apache.commons.lang3.StringUtils; | 7 | import org.apache.commons.lang3.StringUtils; |
7 | import org.springframework.http.ResponseEntity; | 8 | import org.springframework.http.ResponseEntity; |
@@ -27,6 +28,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidatio | @@ -27,6 +28,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidatio | ||
27 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 28 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
28 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | 29 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
29 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | 30 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
31 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | ||
30 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 32 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
31 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 33 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
32 | import org.thingsboard.server.common.msg.queue.ServiceQueue; | 34 | import org.thingsboard.server.common.msg.queue.ServiceQueue; |
@@ -158,15 +160,18 @@ public class TkDeviceProfileController extends BaseController { | @@ -158,15 +160,18 @@ public class TkDeviceProfileController extends BaseController { | ||
158 | @GetMapping("/me/list") | 160 | @GetMapping("/me/list") |
159 | @ApiOperation("选项列表") | 161 | @ApiOperation("选项列表") |
160 | @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})") | 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 | List<DeviceProfileDTO> results; | 167 | List<DeviceProfileDTO> results; |
163 | String tenantId = getCurrentUser().getCurrentTenantId(); | 168 | String tenantId = getCurrentUser().getCurrentTenantId(); |
164 | if (getCurrentUser().isTenantAdmin()) { | 169 | if (getCurrentUser().isTenantAdmin()) { |
165 | - results = ytDeviceProfileService.findDeviceProfile(tenantId, null); | 170 | + results = ytDeviceProfileService.findDeviceProfile(tenantId, null,deviceType); |
166 | } else { | 171 | } else { |
167 | results = | 172 | results = |
168 | ytDeviceProfileService.findCustomerDeviceProfiles( | 173 | ytDeviceProfileService.findCustomerDeviceProfiles( |
169 | - tenantId, getCurrentUser().getCustomerId()); | 174 | + tenantId, getCurrentUser().getCustomerId(),deviceType); |
170 | } | 175 | } |
171 | 176 | ||
172 | return ResponseEntity.ok(results); | 177 | return ResponseEntity.ok(results); |
@@ -103,7 +103,7 @@ public class TkDeviceScriptController extends BaseController { | @@ -103,7 +103,7 @@ public class TkDeviceScriptController extends BaseController { | ||
103 | convertJs = scriptDTO.getConvertJs(); | 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 | for (DeviceProfileDTO profile : usedProfiles) { | 107 | for (DeviceProfileDTO profile : usedProfiles) { |
108 | DeviceProfile tbDeviceProfile = | 108 | DeviceProfile tbDeviceProfile = |
109 | buildTbDeviceProfileFromDeviceProfileDTO( | 109 | buildTbDeviceProfileFromDeviceProfileDTO( |
@@ -18,6 +18,7 @@ import org.thingsboard.server.common.data.yunteng.constant.QueryConstant; | @@ -18,6 +18,7 @@ import org.thingsboard.server.common.data.yunteng.constant.QueryConstant; | ||
18 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | 18 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
19 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 19 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
20 | import org.thingsboard.server.common.data.yunteng.dto.*; | 20 | import org.thingsboard.server.common.data.yunteng.dto.*; |
21 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | ||
21 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 22 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
22 | import org.thingsboard.server.dao.yunteng.entities.*; | 23 | import org.thingsboard.server.dao.yunteng.entities.*; |
23 | import org.thingsboard.server.dao.yunteng.jpa.dao.YtJpaDeviceProfileDao; | 24 | import org.thingsboard.server.dao.yunteng.jpa.dao.YtJpaDeviceProfileDao; |
@@ -198,19 +199,23 @@ public class TkDeviceProfileServiceImpl | @@ -198,19 +199,23 @@ public class TkDeviceProfileServiceImpl | ||
198 | } | 199 | } |
199 | 200 | ||
200 | @Override | 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 | @Override | 207 | @Override |
206 | - public List<DeviceProfileDTO> findCustomerDeviceProfiles(String tenantId, CustomerId customerId) { | 208 | + public List<DeviceProfileDTO> findCustomerDeviceProfiles( |
209 | + String tenantId, CustomerId customerId, DeviceTypeEnum deviceType) { | ||
207 | List<DeviceDTO> deviceDTOS = | 210 | List<DeviceDTO> deviceDTOS = |
208 | deviceMapper.findDeviceInfoByCustomerId(tenantId, customerId.toString()); | 211 | deviceMapper.findDeviceInfoByCustomerId(tenantId, customerId.toString()); |
209 | List<String> deviceProfileIds = | 212 | List<String> deviceProfileIds = |
210 | Optional.ofNullable(deviceDTOS) | 213 | Optional.ofNullable(deviceDTOS) |
211 | .map( | 214 | .map( |
212 | devices -> | 215 | devices -> |
213 | - devices.stream().map(DeviceDTO::getDeviceProfileId).collect(Collectors.toList())) | 216 | + devices.stream() |
217 | + .map(DeviceDTO::getDeviceProfileId) | ||
218 | + .collect(Collectors.toList())) | ||
214 | .orElse(null); | 219 | .orElse(null); |
215 | if (null == deviceProfileIds || deviceProfileIds.isEmpty()) { | 220 | if (null == deviceProfileIds || deviceProfileIds.isEmpty()) { |
216 | return null; | 221 | return null; |
@@ -219,6 +224,7 @@ public class TkDeviceProfileServiceImpl | @@ -219,6 +224,7 @@ public class TkDeviceProfileServiceImpl | ||
219 | baseMapper.selectList( | 224 | baseMapper.selectList( |
220 | new LambdaQueryWrapper<TkDeviceProfileEntity>() | 225 | new LambdaQueryWrapper<TkDeviceProfileEntity>() |
221 | .eq(TkDeviceProfileEntity::getTenantId, tenantId) | 226 | .eq(TkDeviceProfileEntity::getTenantId, tenantId) |
227 | + .eq(null !=deviceType,TkDeviceProfileEntity::getDeviceType,deviceType) | ||
222 | .in(TkDeviceProfileEntity::getId, deviceProfileIds)); | 228 | .in(TkDeviceProfileEntity::getId, deviceProfileIds)); |
223 | if (null != entities && !entities.isEmpty()) { | 229 | if (null != entities && !entities.isEmpty()) { |
224 | return entities.stream() | 230 | return entities.stream() |
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; | @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; | ||
5 | import org.apache.ibatis.annotations.Mapper; | 5 | import org.apache.ibatis.annotations.Mapper; |
6 | import org.apache.ibatis.annotations.Param; | 6 | import org.apache.ibatis.annotations.Param; |
7 | import org.thingsboard.server.common.data.yunteng.dto.*; | 7 | import org.thingsboard.server.common.data.yunteng.dto.*; |
8 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | ||
8 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; | 9 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; |
9 | 10 | ||
10 | import java.util.List; | 11 | import java.util.List; |
@@ -27,5 +28,7 @@ public interface TkDeviceProfileMapper extends BaseMapper<TkDeviceProfileEntity> | @@ -27,5 +28,7 @@ public interface TkDeviceProfileMapper extends BaseMapper<TkDeviceProfileEntity> | ||
27 | @Param("deviceProfileIds") List<String> deviceProfileIds); | 28 | @Param("deviceProfileIds") List<String> deviceProfileIds); |
28 | 29 | ||
29 | List<DeviceProfileDTO> profileByScriptId( | 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,6 +2,7 @@ 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.id.CustomerId; |
4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
5 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | ||
5 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 6 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
6 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; | 7 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; |
7 | 8 | ||
@@ -10,43 +11,44 @@ import java.util.Map; | @@ -10,43 +11,44 @@ import java.util.Map; | ||
10 | import java.util.Optional; | 11 | import java.util.Optional; |
11 | import java.util.Set; | 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 | } |
@@ -80,6 +80,9 @@ | @@ -80,6 +80,9 @@ | ||
80 | <if test="scriptId !=null and scriptId !=''"> | 80 | <if test="scriptId !=null and scriptId !=''"> |
81 | AND iot.script_id = #{scriptId} | 81 | AND iot.script_id = #{scriptId} |
82 | </if> | 82 | </if> |
83 | + <if test="deviceType !=null"> | ||
84 | + AND iot.device_type = #{deviceType} | ||
85 | + </if> | ||
83 | </where> | 86 | </where> |
84 | </select> | 87 | </select> |
85 | </mapper> | 88 | </mapper> |