Showing
6 changed files
with
49 additions
and
24 deletions
@@ -93,7 +93,7 @@ public class TkDeviceScriptController extends BaseController { | @@ -93,7 +93,7 @@ public class TkDeviceScriptController extends BaseController { | ||
93 | } | 93 | } |
94 | 94 | ||
95 | /**脚本引擎启用/禁用时,刷新规则引擎中缓存的脚本ID对应的脚本内容,禁用时为默认脚本*/ | 95 | /**脚本引擎启用/禁用时,刷新规则引擎中缓存的脚本ID对应的脚本内容,禁用时为默认脚本*/ |
96 | - List<DeviceProfileDTO> usedProfiles = ytDeviceProfileService.findDeviceProfile(tenantId, id,null); | 96 | +// List<DeviceProfileDTO> usedProfiles = ytDeviceProfileService.findDeviceProfile(tenantId, id,null); |
97 | // for (DeviceProfileDTO profile : usedProfiles) { | 97 | // for (DeviceProfileDTO profile : usedProfiles) { |
98 | // DeviceProfile tbDeviceProfile = | 98 | // DeviceProfile tbDeviceProfile = |
99 | // buildTbDeviceProfileFromDeviceProfileDTO( | 99 | // buildTbDeviceProfileFromDeviceProfileDTO( |
@@ -19,6 +19,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidatio | @@ -19,6 +19,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidatio | ||
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.enums.DeviceTypeEnum; |
22 | +import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; | ||
22 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 23 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
23 | import org.thingsboard.server.dao.yunteng.entities.*; | 24 | import org.thingsboard.server.dao.yunteng.entities.*; |
24 | import org.thingsboard.server.dao.yunteng.jpa.dao.TkJpaDeviceProfileDao; | 25 | import org.thingsboard.server.dao.yunteng.jpa.dao.TkJpaDeviceProfileDao; |
@@ -244,22 +245,11 @@ public class TkDeviceProfileServiceImpl | @@ -244,22 +245,11 @@ public class TkDeviceProfileServiceImpl | ||
244 | } | 245 | } |
245 | 246 | ||
246 | @Override | 247 | @Override |
247 | - public List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId, List<String> ids) { | 248 | + public List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId, List<String> ids, TransportTypeEnum transportType) { |
248 | if (StringUtils.isEmpty(tenantId) || null == ids) { | 249 | if (StringUtils.isEmpty(tenantId) || null == ids) { |
249 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 250 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
250 | } | 251 | } |
251 | - List<TkDeviceProfileEntity> entities = | ||
252 | - baseMapper.selectList( | ||
253 | - new LambdaQueryWrapper<TkDeviceProfileEntity>() | ||
254 | - .eq(TkDeviceProfileEntity::getTenantId, tenantId) | ||
255 | - .in(TkDeviceProfileEntity::getId, ids)); | ||
256 | - | ||
257 | - if (null == entities || entities.isEmpty()) { | ||
258 | - return null; | ||
259 | - } | ||
260 | - return entities.stream() | ||
261 | - .map(obj -> obj.getDTO(DeviceProfileDTO.class)) | ||
262 | - .collect(Collectors.toList()); | 252 | + return baseMapper.profileByTransportAndIds(tenantId,ids,transportType); |
263 | } | 253 | } |
264 | 254 | ||
265 | @Override | 255 | @Override |
@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; | @@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; | ||
8 | import org.apache.commons.lang3.StringUtils; | 8 | import org.apache.commons.lang3.StringUtils; |
9 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
10 | import org.springframework.transaction.annotation.Transactional; | 10 | import org.springframework.transaction.annotation.Transactional; |
11 | +import org.thingsboard.server.common.data.device.profile.TkTcpDeviceProfileTransportConfiguration; | ||
11 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | 12 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
12 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | 13 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
13 | import org.thingsboard.server.common.data.yunteng.constant.QueryConstant; | 14 | import org.thingsboard.server.common.data.yunteng.constant.QueryConstant; |
@@ -17,6 +18,7 @@ import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | @@ -17,6 +18,7 @@ import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | ||
17 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | 18 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
18 | import org.thingsboard.server.common.data.yunteng.dto.TkCustomerDeviceDTO; | 19 | import org.thingsboard.server.common.data.yunteng.dto.TkCustomerDeviceDTO; |
19 | import org.thingsboard.server.common.data.yunteng.dto.TkDeviceScriptDTO; | 20 | import org.thingsboard.server.common.data.yunteng.dto.TkDeviceScriptDTO; |
21 | +import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; | ||
20 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 22 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
21 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; | 23 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; |
22 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceScriptEntity; | 24 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceScriptEntity; |
@@ -264,13 +266,19 @@ public class TkDeviceScriptServiceImpl | @@ -264,13 +266,19 @@ public class TkDeviceScriptServiceImpl | ||
264 | .map(DeviceDTO::getDeviceProfileId) | 266 | .map(DeviceDTO::getDeviceProfileId) |
265 | .collect(Collectors.toList()); | 267 | .collect(Collectors.toList()); |
266 | List<DeviceProfileDTO> deviceProfileDTOList = | 268 | List<DeviceProfileDTO> deviceProfileDTOList = |
267 | - tkDeviceProfileService.findDeviceProfileByIds(tenantId, deviceProfiles); | 269 | + tkDeviceProfileService.findDeviceProfileByIds(tenantId, deviceProfiles, TransportTypeEnum.TCP); |
268 | return Optional.ofNullable(deviceProfileDTOList) | 270 | return Optional.ofNullable(deviceProfileDTOList) |
269 | .map( | 271 | .map( |
270 | - deviceProfileDTOS -> | ||
271 | - deviceProfileDTOS.stream() | ||
272 | - .map(DeviceProfileDTO::getScriptId) | ||
273 | - .collect(Collectors.toSet())) | 272 | + deviceProfileDTOS ->{ |
273 | + Set<String> tcpScriptes = new HashSet<>(); | ||
274 | + deviceProfileDTOS.forEach(p->{ | ||
275 | + TkTcpDeviceProfileTransportConfiguration config = (TkTcpDeviceProfileTransportConfiguration) p.getProfileData().getTransportConfiguration(); | ||
276 | + tcpScriptes.add(config.getUpScriptId()); | ||
277 | + tcpScriptes.add(config.getUpScriptId()); | ||
278 | + tcpScriptes.add(config.getUpScriptId()); | ||
279 | + }); | ||
280 | + return tcpScriptes; | ||
281 | + }) | ||
274 | .orElse(null); | 282 | .orElse(null); |
275 | } | 283 | } |
276 | return null; | 284 | return null; |
@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param; | @@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param; | ||
7 | import org.thingsboard.server.common.data.DeviceTransportType; | 7 | import org.thingsboard.server.common.data.DeviceTransportType; |
8 | import org.thingsboard.server.common.data.yunteng.dto.*; | 8 | import org.thingsboard.server.common.data.yunteng.dto.*; |
9 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | 9 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
10 | +import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; | ||
10 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; | 11 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; |
11 | 12 | ||
12 | import java.util.List; | 13 | import java.util.List; |
@@ -28,10 +29,17 @@ public interface TkDeviceProfileMapper extends BaseMapper<TkDeviceProfileEntity> | @@ -28,10 +29,17 @@ public interface TkDeviceProfileMapper extends BaseMapper<TkDeviceProfileEntity> | ||
28 | @Param("transportType") String transportType, | 29 | @Param("transportType") String transportType, |
29 | @Param("deviceProfileIds") List<String> deviceProfileIds); | 30 | @Param("deviceProfileIds") List<String> deviceProfileIds); |
30 | 31 | ||
32 | + @Deprecated | ||
31 | List<DeviceProfileDTO> profileByScriptId( | 33 | List<DeviceProfileDTO> profileByScriptId( |
32 | - @Param("tenantId") String tenantId, | ||
33 | - @Param("scriptId") String scriptId, | ||
34 | - @Param("deviceType") DeviceTypeEnum deviceType); | 34 | + @Param("tenantId") String tenantId, |
35 | + @Param("scriptId") String scriptId, | ||
36 | + @Param("deviceType") DeviceTypeEnum deviceType); | ||
37 | + | ||
38 | + List<DeviceProfileDTO> profileByTransportAndIds( | ||
39 | + @Param("tenantId") String tenantId, | ||
40 | + @Param("projectIds") List<String> projectIds, | ||
41 | + @Param("deviceType") TransportTypeEnum transportType); | ||
42 | + | ||
35 | 43 | ||
36 | List<String> getDeviceProfileIds( | 44 | List<String> getDeviceProfileIds( |
37 | @Param("tenantId") String tenantId, | 45 | @Param("tenantId") String tenantId, |
@@ -3,6 +3,7 @@ package org.thingsboard.server.dao.yunteng.service; | @@ -3,6 +3,7 @@ package org.thingsboard.server.dao.yunteng.service; | ||
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.enums.DeviceTypeEnum; |
6 | +import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; | ||
6 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 7 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
7 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; | 8 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity; |
8 | 9 | ||
@@ -29,7 +30,7 @@ public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntit | @@ -29,7 +30,7 @@ public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntit | ||
29 | List<DeviceProfileDTO> findCustomerDeviceProfiles( | 30 | List<DeviceProfileDTO> findCustomerDeviceProfiles( |
30 | String tenantId, CustomerId customerId, DeviceTypeEnum deviceType); | 31 | String tenantId, CustomerId customerId, DeviceTypeEnum deviceType); |
31 | 32 | ||
32 | - List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId, List<String> ids); | 33 | + List<DeviceProfileDTO> findDeviceProfileByIds(String tenantId, List<String> ids, TransportTypeEnum transportType); |
33 | 34 | ||
34 | List<DeviceProfileDTO> findDeviceProfile(String tenantId); | 35 | List<DeviceProfileDTO> findDeviceProfile(String tenantId); |
35 | /** 验证表单数据有效性 */ | 36 | /** 验证表单数据有效性 */ |
@@ -12,7 +12,6 @@ | @@ -12,7 +12,6 @@ | ||
12 | <result property="image" column="image"/> | 12 | <result property="image" column="image"/> |
13 | <result property="description" column="description"/> | 13 | <result property="description" column="description"/> |
14 | <result property="tenantId" column="tenant_id"/> | 14 | <result property="tenantId" column="tenant_id"/> |
15 | - <result property="scriptId" column="script_id"/> | ||
16 | <result property="transportType" column="transport_type"/> | 15 | <result property="transportType" column="transport_type"/> |
17 | <result property="provisionType" column="provision_type"/> | 16 | <result property="provisionType" column="provision_type"/> |
18 | <result property="deviceType" column="device_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> | 17 | <result property="deviceType" column="device_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> |
@@ -86,6 +85,25 @@ | @@ -86,6 +85,25 @@ | ||
86 | </where> | 85 | </where> |
87 | </select> | 86 | </select> |
88 | 87 | ||
88 | + <select id="profileByTransportAndIds" resultMap="detail"> | ||
89 | + SELECT | ||
90 | + <include refid="basicColumns"/> | ||
91 | + FROM device_profile base | ||
92 | + LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT | ||
93 | + <where> | ||
94 | + iot.tenant_id = #{tenantId} | ||
95 | + <if test="projectIds != null"> | ||
96 | + AND iot.id IN | ||
97 | + <foreach collection="projectIds" item="id" open="(" separator="," close=")"> | ||
98 | + #{id} | ||
99 | + </foreach> | ||
100 | + </if> | ||
101 | + <if test="transportType !=null"> | ||
102 | + AND iot.transport_type = #{transportType} | ||
103 | + </if> | ||
104 | + </where> | ||
105 | + </select> | ||
106 | + | ||
89 | <select id="getDeviceProfileIds" resultType="java.lang.String"> | 107 | <select id="getDeviceProfileIds" resultType="java.lang.String"> |
90 | SELECT iot.id | 108 | SELECT iot.id |
91 | FROM device_profile base | 109 | FROM device_profile base |