Showing
6 changed files
with
152 additions
and
4 deletions
... | ... | @@ -30,10 +30,7 @@ import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
30 | 30 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
31 | 31 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
32 | 32 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
33 | -import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
34 | -import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
35 | -import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; | |
36 | -import org.thingsboard.server.common.data.yunteng.dto.YtCredentialsDto; | |
33 | +import org.thingsboard.server.common.data.yunteng.dto.*; | |
37 | 34 | import org.thingsboard.server.common.data.yunteng.enums.DeviceState; |
38 | 35 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
39 | 36 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
... | ... | @@ -357,6 +354,26 @@ public class YtDeviceController extends BaseController { |
357 | 354 | return deviceService.findDevicesByDeviceTypeAndOrganizationId(deviceType,getCurrentUser().getCurrentTenantId(), organizationId); |
358 | 355 | } |
359 | 356 | |
357 | + @GetMapping("/list/master/{organizationId}") | |
358 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
359 | + @ApiOperation("主设备列表") | |
360 | + public List<SelectItemDTO> getMasterDevices( | |
361 | + @ApiParam(value = "组织ID") @PathVariable("organizationId") String organizationId) throws ThingsboardException { | |
362 | + return deviceService.findMasterDevices(getCurrentUser().getCurrentTenantId() | |
363 | + ,getCurrentUser().isCustomerUser()?getCurrentUser().getCurrentUserId():null | |
364 | + , organizationId); | |
365 | + } | |
366 | + @GetMapping("/list/slave/{organizationId}") | |
367 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | |
368 | + @ApiOperation("从设备列表") | |
369 | + public List<SelectItemDTO> getSlaveDevices( | |
370 | + @ApiParam(value = "组织ID") @PathVariable("organizationId") String organizationId, | |
371 | + @ApiParam(value = "主设备ID") @RequestParam(value = "masterId",required = false) String masterId) throws ThingsboardException { | |
372 | + return deviceService.findSlaveDevices(masterId,getCurrentUser().getCurrentTenantId() | |
373 | + ,getCurrentUser().isCustomerUser()?getCurrentUser().getCurrentUserId():null | |
374 | + , organizationId); | |
375 | + } | |
376 | + | |
360 | 377 | @GetMapping("/gateway/{tbDeviceId}") |
361 | 378 | @ApiOperation("获取网关设备") |
362 | 379 | public DeviceDTO findGateWayDeviceByTbDeviceId( | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/SelectItemDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModelProperty; | |
4 | +import lombok.Data; | |
5 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | |
6 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | |
7 | + | |
8 | +import javax.validation.constraints.NotNull; | |
9 | +import javax.validation.constraints.Size; | |
10 | +import java.util.Set; | |
11 | + | |
12 | +@Data | |
13 | +public class SelectItemDTO { | |
14 | + @ApiModelProperty("下拉选项值") | |
15 | + private String id; | |
16 | + | |
17 | + @ApiModelProperty("下拉选项名") | |
18 | + private String name; | |
19 | + | |
20 | + @ApiModelProperty("设备类型") | |
21 | + private DeviceTypeEnum deviceType; | |
22 | +} | ... | ... |
... | ... | @@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
20 | 20 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
21 | 21 | import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; |
22 | 22 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; |
23 | +import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; | |
23 | 24 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
24 | 25 | import org.thingsboard.server.common.data.yunteng.enums.ScopeEnum; |
25 | 26 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
... | ... | @@ -429,4 +430,19 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
429 | 430 | } |
430 | 431 | return false; |
431 | 432 | } |
433 | + | |
434 | + | |
435 | + @Override | |
436 | + public List<SelectItemDTO> findMasterDevices(String tenantId, String customerId, String organizationId) { | |
437 | + List<String> orgIds = organizationAllIds(tenantId,organizationId); | |
438 | + List<SelectItemDTO> result = baseMapper.masterDevices(customerId,tenantId,orgIds); | |
439 | + return result; | |
440 | + } | |
441 | + | |
442 | + @Override | |
443 | + public List<SelectItemDTO> findSlaveDevices(String masterId,String tenantId,String customerId, String organizationId){ | |
444 | + List<String> orgIds = organizationAllIds(tenantId,organizationId); | |
445 | + List<SelectItemDTO> result = baseMapper.slaveDevices(customerId,tenantId,orgIds,masterId); | |
446 | + return result; | |
447 | + } | |
432 | 448 | } | ... | ... |
... | ... | @@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param; |
7 | 7 | import org.thingsboard.server.common.data.yunteng.dto.BaseHomePageTop; |
8 | 8 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
9 | 9 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; |
10 | +import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; | |
10 | 11 | import org.thingsboard.server.common.data.yunteng.dto.statistics.AggregationDTO; |
11 | 12 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; |
12 | 13 | |
... | ... | @@ -84,4 +85,24 @@ public interface DeviceMapper extends BaseMapper<YtDevice> { |
84 | 85 | Integer countMsgs(@Param("queryMap") Map<String, Object> queryMap); |
85 | 86 | |
86 | 87 | Integer countDataPoints(@Param("queryMap") Map<String, Object> queryMap); |
88 | + | |
89 | + /** | |
90 | + * 主设备列表 | |
91 | + * @param customerId 客户ID | |
92 | + * @param tenantId 租户ID | |
93 | + * @param organizationIds 组织ID | |
94 | + * @return | |
95 | + */ | |
96 | + List<SelectItemDTO> masterDevices(@Param("customerId") String customerId,@Param("tenantId") String tenantId,@Param("organizationIds") List<String> organizationIds); | |
97 | + | |
98 | + /** | |
99 | + * 从设备列表 | |
100 | + * @param customerId 客户ID | |
101 | + * @param tenantId 租户ID | |
102 | + * @param organizationIds 组织ID | |
103 | + * @param masterId 主设备ID | |
104 | + * @return | |
105 | + */ | |
106 | + List<SelectItemDTO> slaveDevices(@Param("customerId") String customerId,@Param("tenantId") String tenantId | |
107 | + ,@Param("organizationIds") List<String> organizationIds,@Param("masterId") String masterId); | |
87 | 108 | } | ... | ... |
... | ... | @@ -3,6 +3,7 @@ package org.thingsboard.server.dao.yunteng.service; |
3 | 3 | import org.thingsboard.server.common.data.id.EntityId; |
4 | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
5 | 5 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; |
6 | +import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; | |
6 | 7 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
7 | 8 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
8 | 9 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; |
... | ... | @@ -103,4 +104,21 @@ public interface YtDeviceService extends BaseService<YtDevice> { |
103 | 104 | * @return |
104 | 105 | */ |
105 | 106 | Boolean otherUsing(String deviceId,String tenantId); |
107 | + | |
108 | + /** | |
109 | + * 主设备信息 | |
110 | + * @param tenantId 租户ID | |
111 | + * @param organizationId 组织ID | |
112 | + * @return 设备列表 | |
113 | + */ | |
114 | + List<SelectItemDTO> findMasterDevices(String tenantId, String customerId, String organizationId); | |
115 | + | |
116 | + /** | |
117 | + * 从设备信息 | |
118 | + * @param masterId 主设备ID | |
119 | + * @param tenantId 租户ID | |
120 | + * @param organizationId 组织ID | |
121 | + * @return 设备列表 | |
122 | + */ | |
123 | + List<SelectItemDTO> findSlaveDevices(String masterId,String tenantId,String customerId, String organizationId); | |
106 | 124 | } | ... | ... |
... | ... | @@ -2,6 +2,11 @@ |
2 | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
3 | 3 | |
4 | 4 | <mapper namespace="org.thingsboard.server.dao.yunteng.mapper.DeviceMapper"> |
5 | + <resultMap type="org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO" id="listInform"> | |
6 | + <result property="id" column="id"/> | |
7 | + <result property="name" column="name"/> | |
8 | + <result property="deviceType" column="device_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> | |
9 | + </resultMap> | |
5 | 10 | <resultMap type="org.thingsboard.server.common.data.yunteng.dto.DeviceDTO" id="deviceMap"> |
6 | 11 | <result property="id" column="id"/> |
7 | 12 | <result property="name" column="name"/> |
... | ... | @@ -325,4 +330,53 @@ |
325 | 330 | </if> |
326 | 331 | </where> |
327 | 332 | </select> |
333 | + | |
334 | + <select id="masterDevices" resultMap="listInform"> | |
335 | + SELECT | |
336 | + base.tb_device_id as id,base.name,base.device_type | |
337 | + FROM iotfs_device base | |
338 | + LEFT JOIN device tde ON tde.ID :: TEXT = base.tb_device_id | |
339 | + <where> | |
340 | + base.device_type != 'SENSOR' | |
341 | + <if test="tenantId !=null and tenantId !=''"> | |
342 | + AND base.tenant_id = #{tenantId} | |
343 | + </if> | |
344 | + <if test="customerId !=null and customerId !=''"> | |
345 | + AND tde.customer_id :: TEXT = #{customerId} | |
346 | + </if> | |
347 | + <if test="organizationIds !=null"> | |
348 | + AND base.organization_id IN | |
349 | + <foreach collection="organizationIds" item="orgId" open="(" separator="," close=")"> | |
350 | + #{orgId} | |
351 | + </foreach> | |
352 | + </if> | |
353 | + </where> | |
354 | + </select> | |
355 | + | |
356 | + <select id="slaveDevices" resultMap="listInform"> | |
357 | + SELECT | |
358 | + ide.tb_device_id as id,ide.name,ide.device_type | |
359 | + FROM (select * from relation where relation_type_group = 'COMMON' AND relation_type = 'Created' AND from_type = 'DEVICE' AND to_type = 'DEVICE' | |
360 | + <if test="masterId !=null and masterId !=''"> | |
361 | + AND from_id = #{masterId} | |
362 | + </if> | |
363 | + ) base | |
364 | + LEFT JOIN device tde ON base.to_id = tde.id | |
365 | + LEFT JOIN iotfs_device ide ON tde.ID :: TEXT = ide.tb_device_id | |
366 | + <where> | |
367 | + ide.device_type = 'SENSOR' | |
368 | + <if test="tenantId !=null and tenantId !=''"> | |
369 | + AND ide.tenant_id = #{tenantId} | |
370 | + </if> | |
371 | + <if test="organizationIds !=null"> | |
372 | + AND ide.organization_id IN | |
373 | + <foreach collection="organizationIds" item="orgId" open="(" separator="," close=")"> | |
374 | + #{orgId} | |
375 | + </foreach> | |
376 | + </if> | |
377 | + <if test="customerId !=null and customerId !=''"> | |
378 | + AND tde.customer_id :: TEXT = #{customerId} | |
379 | + </if> | |
380 | + </where> | |
381 | + </select> | |
328 | 382 | </mapper> | ... | ... |