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 383 @ApiParam(value = "传输协议类型") @RequestParam(value = "transportType", required = false)
384 384 TransportTypeEnum transportType,
385 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 391 throws ThingsboardException {
388 392 return tkdeviceService.findDevicesByDeviceTypeAndOrganizationId(
389 393 deviceType,
390 394 getCurrentUser().getTenantId().getId(),
391 395 organizationId,
392 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 405 @PostMapping("/getListByDeviceProfileIds")
... ...
... ... @@ -324,15 +324,17 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD
324 324 String deviceLabel,
325 325 UUID deviceProfileId,
326 326 TransportTypeEnum transportTypeEnum,
327   - Boolean isSceneLinkage) {
  327 + Boolean isSceneLinkage,
  328 + Boolean isEdgeDistribution,
  329 + UUID edgeId) {
328 330 List<String> orgIds = organizationService.organizationAllIds(tenantId.toString(), organizationId);
329 331 if (orgIds.isEmpty()) {
330 332 throw new TkDataValidationException(ErrorMessage.ORGANIZATION_NOT_EXTIED.getMessage());
331 333 }
332 334
333 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 338 return listEntity.stream().map(entity -> {
337 339 return CopyUtils.copyAndReturn(entity, new DeviceDTO());
338 340 }
... ...
... ... @@ -61,7 +61,7 @@ public class TkDeviceStateLogServiceImpl
61 61 }
62 62 if(isPtCommonTenant){
63 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 65 List<String> finalTbDevices = new ArrayList<>();
66 66 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString()));
67 67 deviceIds = finalTbDevices;
... ...
... ... @@ -216,7 +216,7 @@ public class TkHomePageServiceImpl implements HomePageService {
216 216 totalFilter.put("organizationIds",organizationIds);
217 217 //查询所有设备
218 218 List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId(organizationIds,null,
219   - null,null,null,false);
  219 + null,null,null,false,false,null);
220 220 List<String> finalTbDevices = new ArrayList<>();
221 221 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString()));
222 222 todayFilter.put("deviceIds",finalTbDevices);
... ...
... ... @@ -111,7 +111,8 @@ public class TkVideoServiceImpl extends AbstractBaseService<TkVideoMapper, TkVid
111 111 String organizationId = dto.getOrganizationId();
112 112 List<TkVideoGbtDeviceDTO> deviceList = new ArrayList<>();
113 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 116 if(deviceDTOS.isEmpty()){
116 117 return dto;
117 118 }
... ...
... ... @@ -162,7 +162,9 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> {
162 162 @Param("deviceLabel") String deviceLabel,
163 163 @Param("deviceProfileId") UUID deviceProfileId,
164 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 170 List<DeviceDTO> findDevicesByProfileIdAndOrganizationId(
... ...
... ... @@ -67,6 +67,9 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> {
67 67 *
68 68 * @param deviceType 设备类型
69 69 * @param organizationId 组织ID
  70 + * @param isSceneLinkage 是否场景联动调用 用于过滤边缘设备
  71 + * @param isEdgeDistribution 是否分配边缘调用 用于过滤场景联动已使用设备
  72 + * @param edgeId 是否分配边缘调用 用于过滤已分配给此边端的设备
70 73 * @return 设备列表
71 74 */
72 75 List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId(
... ... @@ -76,7 +79,9 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> {
76 79 String deviceLabel,
77 80 UUID deviceProfileId,
78 81 TransportTypeEnum transportTypeEnum,
79   - Boolean isSceneLinkage);
  82 + Boolean isSceneLinkage,
  83 + Boolean isEdgeDistribution,
  84 + UUID edgeId);
80 85
81 86
82 87 List<DeviceDTO> findDevicesByOrganizationIds(
... ...
... ... @@ -568,14 +568,35 @@
568 568 FROM device ifd
569 569 left join device_profile dev on ifd.device_profile_id = dev.id
570 570 <if test="isSceneLinkage == true">
571   -<!-- 此设备是边端创建或者已经分配给边端-->
  571 + <!--此设备是边端创建或者已经分配给边端-->
572 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 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 587 where
575 588 1=1
576 589 <if test="isSceneLinkage == true">
577 590 and re.to_id is null
578 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 600 <if test="deviceType !=null and deviceType !=''">
580 601 AND ifd.device_type = #{deviceType}
581 602 </if>
... ...