Commit 01ed914a85e25b82a82e06986d3b9338c89f944f

Authored by xp.Huang
2 parents bc9115b5 eb984510

Merge branch 'master_dev' into 'fix_rule_chain'

Master dev

See merge request yunteng/thingskit!429
@@ -383,15 +383,23 @@ public class TkDeviceController extends BaseController { @@ -383,15 +383,23 @@ public class TkDeviceController extends BaseController {
383 @ApiParam(value = "传输协议类型") @RequestParam(value = "transportType", required = false) 383 @ApiParam(value = "传输协议类型") @RequestParam(value = "transportType", required = false)
384 TransportTypeEnum transportType, 384 TransportTypeEnum transportType,
385 @ApiParam(value = "是否场景联动调用,是true") @RequestParam(value = "isSceneLinkage", required = false) 385 @ApiParam(value = "是否场景联动调用,是true") @RequestParam(value = "isSceneLinkage", required = false)
386 - Boolean isSceneLinkage) 386 + Boolean isSceneLinkage,
  387 + @ApiParam(value = "是否边缘分配设备调用,是true") @RequestParam(value = "isEdgeDistribution", required = false)
  388 + Boolean isEdgeDistribution,
  389 + @ApiParam(value = "edgeId") @RequestParam(value = "edgeId", required = false)
  390 + String edgeId)
387 throws ThingsboardException { 391 throws ThingsboardException {
388 return tkdeviceService.findDevicesByDeviceTypeAndOrganizationId( 392 return tkdeviceService.findDevicesByDeviceTypeAndOrganizationId(
389 deviceType, 393 deviceType,
390 getCurrentUser().getTenantId().getId(), 394 getCurrentUser().getTenantId().getId(),
391 organizationId, 395 organizationId,
392 deviceLabel, 396 deviceLabel,
393 - StringUtils.isEmpty(deviceProfileId)?null:UUID.fromString(deviceProfileId),transportType,isSceneLinkage);  
394 - } 397 + StringUtils.isEmpty(deviceProfileId)?null:UUID.fromString(deviceProfileId),
  398 + transportType,
  399 + isSceneLinkage,
  400 + isEdgeDistribution,
  401 + StringUtils.isEmpty(edgeId)?null:UUID.fromString(edgeId));
  402 + }
395 403
396 404
397 @PostMapping("/getListByDeviceProfileIds") 405 @PostMapping("/getListByDeviceProfileIds")
@@ -324,15 +324,17 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD @@ -324,15 +324,17 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD
324 String deviceLabel, 324 String deviceLabel,
325 UUID deviceProfileId, 325 UUID deviceProfileId,
326 TransportTypeEnum transportTypeEnum, 326 TransportTypeEnum transportTypeEnum,
327 - Boolean isSceneLinkage) { 327 + Boolean isSceneLinkage,
  328 + Boolean isEdgeDistribution,
  329 + UUID edgeId) {
328 List<String> orgIds = organizationService.organizationAllIds(tenantId.toString(), organizationId); 330 List<String> orgIds = organizationService.organizationAllIds(tenantId.toString(), organizationId);
329 if (orgIds.isEmpty()) { 331 if (orgIds.isEmpty()) {
330 throw new TkDataValidationException(ErrorMessage.ORGANIZATION_NOT_EXTIED.getMessage()); 332 throw new TkDataValidationException(ErrorMessage.ORGANIZATION_NOT_EXTIED.getMessage());
331 } 333 }
332 334
333 List<TkDeviceEntity> listEntity = baseMapper.findDevicesByDeviceTypeAndOrganizationId(orgIds, 335 List<TkDeviceEntity> listEntity = baseMapper.findDevicesByDeviceTypeAndOrganizationId(orgIds,
334 - deviceType == null ? null : deviceType.name()  
335 - , deviceLabel, deviceProfileId, transportTypeEnum,isSceneLinkage); 336 + deviceType == null ? null : deviceType.name(),
  337 + deviceLabel, deviceProfileId, transportTypeEnum,isSceneLinkage,isEdgeDistribution,edgeId);
336 return listEntity.stream().map(entity -> { 338 return listEntity.stream().map(entity -> {
337 return CopyUtils.copyAndReturn(entity, new DeviceDTO()); 339 return CopyUtils.copyAndReturn(entity, new DeviceDTO());
338 } 340 }
@@ -61,7 +61,7 @@ public class TkDeviceStateLogServiceImpl @@ -61,7 +61,7 @@ public class TkDeviceStateLogServiceImpl
61 } 61 }
62 if(isPtCommonTenant){ 62 if(isPtCommonTenant){
63 List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId((List<String>) queryMap.get("orgIds"), 63 List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId((List<String>) queryMap.get("orgIds"),
64 - null,null,null,null,false); 64 + null,null,null,null,false,false,null);
65 List<String> finalTbDevices = new ArrayList<>(); 65 List<String> finalTbDevices = new ArrayList<>();
66 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString())); 66 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString()));
67 deviceIds = finalTbDevices; 67 deviceIds = finalTbDevices;
@@ -216,7 +216,7 @@ public class TkHomePageServiceImpl implements HomePageService { @@ -216,7 +216,7 @@ public class TkHomePageServiceImpl implements HomePageService {
216 totalFilter.put("organizationIds",organizationIds); 216 totalFilter.put("organizationIds",organizationIds);
217 //查询所有设备 217 //查询所有设备
218 List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId(organizationIds,null, 218 List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId(organizationIds,null,
219 - null,null,null,false); 219 + null,null,null,false,false,null);
220 List<String> finalTbDevices = new ArrayList<>(); 220 List<String> finalTbDevices = new ArrayList<>();
221 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString())); 221 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString()));
222 todayFilter.put("deviceIds",finalTbDevices); 222 todayFilter.put("deviceIds",finalTbDevices);
@@ -111,7 +111,8 @@ public class TkVideoServiceImpl extends AbstractBaseService<TkVideoMapper, TkVid @@ -111,7 +111,8 @@ public class TkVideoServiceImpl extends AbstractBaseService<TkVideoMapper, TkVid
111 String organizationId = dto.getOrganizationId(); 111 String organizationId = dto.getOrganizationId();
112 List<TkVideoGbtDeviceDTO> deviceList = new ArrayList<>(); 112 List<TkVideoGbtDeviceDTO> deviceList = new ArrayList<>();
113 List<DeviceDTO> deviceDTOS = tkdeviceService.findDevicesByDeviceTypeAndOrganizationId( 113 List<DeviceDTO> deviceDTOS = tkdeviceService.findDevicesByDeviceTypeAndOrganizationId(
114 - null, UUID.fromString(dto.getTenantId()),organizationId,null,null, TransportTypeEnum.GBT28181,false); 114 + null, UUID.fromString(dto.getTenantId()),organizationId,null,
  115 + null, TransportTypeEnum.GBT28181,false,false,null);
115 if(deviceDTOS.isEmpty()){ 116 if(deviceDTOS.isEmpty()){
116 return dto; 117 return dto;
117 } 118 }
@@ -162,7 +162,9 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { @@ -162,7 +162,9 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> {
162 @Param("deviceLabel") String deviceLabel, 162 @Param("deviceLabel") String deviceLabel,
163 @Param("deviceProfileId") UUID deviceProfileId, 163 @Param("deviceProfileId") UUID deviceProfileId,
164 @Param("transportType")TransportTypeEnum transportType, 164 @Param("transportType")TransportTypeEnum transportType,
165 - @Param("isSceneLinkage")Boolean isSceneLinkage) ; 165 + @Param("isSceneLinkage")Boolean isSceneLinkage,
  166 + @Param("isEdgeDistribution")Boolean isEdgeDistribution,
  167 + @Param("edgeId")UUID edgeId) ;
166 168
167 169
168 List<DeviceDTO> findDevicesByProfileIdAndOrganizationId( 170 List<DeviceDTO> findDevicesByProfileIdAndOrganizationId(
@@ -67,6 +67,9 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> { @@ -67,6 +67,9 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> {
67 * 67 *
68 * @param deviceType 设备类型 68 * @param deviceType 设备类型
69 * @param organizationId 组织ID 69 * @param organizationId 组织ID
  70 + * @param isSceneLinkage 是否场景联动调用 用于过滤边缘设备
  71 + * @param isEdgeDistribution 是否分配边缘调用 用于过滤场景联动已使用设备
  72 + * @param edgeId 是否分配边缘调用 用于过滤已分配给此边端的设备
70 * @return 设备列表 73 * @return 设备列表
71 */ 74 */
72 List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId( 75 List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId(
@@ -76,7 +79,9 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> { @@ -76,7 +79,9 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> {
76 String deviceLabel, 79 String deviceLabel,
77 UUID deviceProfileId, 80 UUID deviceProfileId,
78 TransportTypeEnum transportTypeEnum, 81 TransportTypeEnum transportTypeEnum,
79 - Boolean isSceneLinkage); 82 + Boolean isSceneLinkage,
  83 + Boolean isEdgeDistribution,
  84 + UUID edgeId);
80 85
81 86
82 List<DeviceDTO> findDevicesByOrganizationIds( 87 List<DeviceDTO> findDevicesByOrganizationIds(
@@ -568,14 +568,35 @@ @@ -568,14 +568,35 @@
568 FROM device ifd 568 FROM device ifd
569 left join device_profile dev on ifd.device_profile_id = dev.id 569 left join device_profile dev on ifd.device_profile_id = dev.id
570 <if test="isSceneLinkage == true"> 570 <if test="isSceneLinkage == true">
571 -<!-- 此设备是边端创建或者已经分配给边端--> 571 + <!--此设备是边端创建或者已经分配给边端-->
572 LEFT JOIN relation re on re.to_id = ifd.id and re.from_type = 'EDGE' and( re.relation_type = 'ManagedByEdge' or re.relation_type = 'Contains') 572 LEFT JOIN relation re on re.to_id = ifd.id and re.from_type = 'EDGE' and( re.relation_type = 'ManagedByEdge' or re.relation_type = 'Contains')
573 </if> 573 </if>
  574 + <if test="edgeId != null">
  575 + LEFT JOIN relation re on re.to_id = ifd.id
  576 + and re.from_id =#{edgeId}
  577 + and re.from_type = 'EDGE'
  578 + and re.relation_type_group = 'EDGE'
  579 + and re.relation_type = 'Contains'
  580 + </if>
  581 + <if test="isEdgeDistribution == true">
  582 + <!--此设备是否已被场景联动使用-->
  583 + LEFT JOIN tk_do_action action on action.device_id LIKE CONCAT('%',ifd.id ,'%')
  584 + LEFT JOIN tk_do_condition cond on cond.entity_id LIKE CONCAT('%',ifd.id ,'%')
  585 + LEFT JOIN tk_trigger trigger on trigger.entity_id LIKE CONCAT('%',ifd.id ,'%')
  586 + </if>
574 where 587 where
575 1=1 588 1=1
576 <if test="isSceneLinkage == true"> 589 <if test="isSceneLinkage == true">
577 and re.to_id is null 590 and re.to_id is null
578 </if> 591 </if>
  592 + <if test="edgeId != null">
  593 + and re.from_id is null
  594 + </if>
  595 + <if test="isEdgeDistribution == true">
  596 + and action.device_id is null
  597 + and cond.entity_id is null
  598 + and trigger.entity_id is null
  599 + </if>
579 <if test="deviceType !=null and deviceType !=''"> 600 <if test="deviceType !=null and deviceType !=''">
580 AND ifd.device_type = #{deviceType} 601 AND ifd.device_type = #{deviceType}
581 </if> 602 </if>