Commit 72c89096708613f550085ab30fb22c8eb4199e93
1 parent
065f8225
fix: provider query device relation
Showing
5 changed files
with
45 additions
and
5 deletions
@@ -438,6 +438,13 @@ public class TkDeviceController extends BaseController { | @@ -438,6 +438,13 @@ public class TkDeviceController extends BaseController { | ||
438 | getCurrentUser().getCurrentTenantId(), tbDeviceId); | 438 | getCurrentUser().getCurrentTenantId(), tbDeviceId); |
439 | } | 439 | } |
440 | 440 | ||
441 | + @GetMapping("/device/relation") | ||
442 | + public String getDeviceRelation( | ||
443 | + @ApiParam(value = "网关子设备:true 非网关子设备:false") @RequestParam(value = "isSlave") boolean isSlave, | ||
444 | + @ApiParam(value = "设备ID") @RequestParam(value = "deviceId") String deviceId) { | ||
445 | + return tkdeviceService.getDeviceRelation(isSlave, deviceId); | ||
446 | + } | ||
447 | + | ||
441 | private Device buildTbDeviceFromDeviceDTO(TenantId tenantId, DeviceDTO deviceDTO) { | 448 | private Device buildTbDeviceFromDeviceDTO(TenantId tenantId, DeviceDTO deviceDTO) { |
442 | Device tbDevice = new Device(); | 449 | Device tbDevice = new Device(); |
443 | String deviceId = deviceDTO.getTbDeviceId(); | 450 | String deviceId = deviceDTO.getTbDeviceId(); |
@@ -286,12 +286,12 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | @@ -286,12 +286,12 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | ||
286 | baseMapper.selectList( | 286 | baseMapper.selectList( |
287 | new LambdaQueryWrapper<TkDeviceEntity>() | 287 | new LambdaQueryWrapper<TkDeviceEntity>() |
288 | .eq(TkDeviceEntity::getTenantId, tenantId) | 288 | .eq(TkDeviceEntity::getTenantId, tenantId) |
289 | - .eq(TkDeviceEntity::getDeviceType,DeviceTypeEnum.GATEWAY) | 289 | + .eq(TkDeviceEntity::getDeviceType, DeviceTypeEnum.GATEWAY) |
290 | .in(TkDeviceEntity::getOrganizationId, orgIds)); | 290 | .in(TkDeviceEntity::getOrganizationId, orgIds)); |
291 | - if(null != deviceProfileIds && !deviceProfileIds.isEmpty()){ | 291 | + if (null != deviceProfileIds && !deviceProfileIds.isEmpty()) { |
292 | List<TkDeviceEntity> result = new ArrayList<>(); | 292 | List<TkDeviceEntity> result = new ArrayList<>(); |
293 | - for (TkDeviceEntity entity :entities){ | ||
294 | - if(deviceProfileIds.contains(entity.getDeviceProfileId())){ | 293 | + for (TkDeviceEntity entity : entities) { |
294 | + if (deviceProfileIds.contains(entity.getDeviceProfileId())) { | ||
295 | result.add(entity); | 295 | result.add(entity); |
296 | } | 296 | } |
297 | } | 297 | } |
@@ -625,4 +625,12 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | @@ -625,4 +625,12 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | ||
625 | } | 625 | } |
626 | return jsonNode; | 626 | return jsonNode; |
627 | } | 627 | } |
628 | + | ||
629 | + @Override | ||
630 | + public String getDeviceRelation(boolean isSlave, String deviceId) { | ||
631 | + if (StringUtils.isEmpty(deviceId)) { | ||
632 | + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
633 | + } | ||
634 | + return baseMapper.getDeviceRelation(isSlave, deviceId); | ||
635 | + } | ||
628 | } | 636 | } |
@@ -64,7 +64,8 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { | @@ -64,7 +64,8 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { | ||
64 | */ | 64 | */ |
65 | List<String> findDeviceIdsByCustomerId(@Param("customerId") String customerId); | 65 | List<String> findDeviceIdsByCustomerId(@Param("customerId") String customerId); |
66 | 66 | ||
67 | - List<DeviceDTO> findDeviceInfoByCustomerId(@Param("tenantId") String tenantId,@Param("customerId") String customerId); | 67 | + List<DeviceDTO> findDeviceInfoByCustomerId( |
68 | + @Param("tenantId") String tenantId, @Param("customerId") String customerId); | ||
68 | 69 | ||
69 | List<BaseHomePageTop> findDeviceMessageInfo( | 70 | List<BaseHomePageTop> findDeviceMessageInfo( |
70 | @Param("todayTime") Long todayTime, @Param("customerId") String customerId); | 71 | @Param("todayTime") Long todayTime, @Param("customerId") String customerId); |
@@ -141,4 +142,6 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { | @@ -141,4 +142,6 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { | ||
141 | @Param("customerId") String customerId, | 142 | @Param("customerId") String customerId, |
142 | @Param("organizationIds") List<String> organizationIds, | 143 | @Param("organizationIds") List<String> organizationIds, |
143 | @Param("deviceIds") List<String> deviceIds); | 144 | @Param("deviceIds") List<String> deviceIds); |
145 | + | ||
146 | + String getDeviceRelation(@Param("isSlave") boolean isSlave, @Param("deviceId") String deviceId); | ||
144 | } | 147 | } |
@@ -188,4 +188,6 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> { | @@ -188,4 +188,6 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> { | ||
188 | * @return 属性信息de | 188 | * @return 属性信息de |
189 | */ | 189 | */ |
190 | JsonNode getDeviceAttributes(String deviceProfileId, String tenantId, DataTypeEnum dataType); | 190 | JsonNode getDeviceAttributes(String deviceProfileId, String tenantId, DataTypeEnum dataType); |
191 | + | ||
192 | + String getDeviceRelation(boolean isSlave,String deviceId); | ||
191 | } | 193 | } |
@@ -424,4 +424,24 @@ | @@ -424,4 +424,24 @@ | ||
424 | </if> | 424 | </if> |
425 | </where> | 425 | </where> |
426 | </select> | 426 | </select> |
427 | + | ||
428 | + <select id="getDeviceRelation" resultType="java.lang.String"> | ||
429 | + SELECT | ||
430 | + <if test="isSlave !=null and isSlave == true"> | ||
431 | + from_id | ||
432 | + </if> | ||
433 | + <if test="isSlave !=null and isSlave == false"> | ||
434 | + to_id | ||
435 | + </if> | ||
436 | + FROM relation | ||
437 | + WHERE | ||
438 | + from_type = 'DEVICE' | ||
439 | + AND relation_type_group = 'COMMON' | ||
440 | + <if test="isSlave !=null and isSlave == false"> | ||
441 | + AND from_id :: TEXT = #{deviceId} | ||
442 | + </if> | ||
443 | + <if test="isSlave !=null and isSlave == true"> | ||
444 | + AND to_id :: TEXT = #{deviceId} | ||
445 | + </if> | ||
446 | + </select> | ||
427 | </mapper> | 447 | </mapper> |