Commit d27f9d3cac012af38182b028543e233d87067e35
Merge branch '20220523' into 'master'
20220523 See merge request huang/thingsboard3.3.2!103
Showing
14 changed files
with
231 additions
and
9 deletions
@@ -10,9 +10,12 @@ import org.springframework.web.bind.annotation.*; | @@ -10,9 +10,12 @@ import org.springframework.web.bind.annotation.*; | ||
10 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 10 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; | 11 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
12 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | 12 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
13 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | ||
14 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
13 | import org.thingsboard.server.common.data.yunteng.dto.ConfigurationActDTO; | 15 | import org.thingsboard.server.common.data.yunteng.dto.ConfigurationActDTO; |
14 | import org.thingsboard.server.common.data.yunteng.dto.ConfigurationDatasourceDTO; | 16 | import org.thingsboard.server.common.data.yunteng.dto.ConfigurationDatasourceDTO; |
15 | import org.thingsboard.server.common.data.yunteng.dto.ConfigurationEventDTO; | 17 | import org.thingsboard.server.common.data.yunteng.dto.ConfigurationEventDTO; |
18 | +import org.thingsboard.server.common.data.yunteng.dto.ConfigurationNodeDTO; | ||
16 | import org.thingsboard.server.controller.BaseController; | 19 | import org.thingsboard.server.controller.BaseController; |
17 | import org.thingsboard.server.dao.yunteng.service.YtConfigurationActService; | 20 | import org.thingsboard.server.dao.yunteng.service.YtConfigurationActService; |
18 | import org.thingsboard.server.dao.yunteng.service.YtConfigurationDatasourceService; | 21 | import org.thingsboard.server.dao.yunteng.service.YtConfigurationDatasourceService; |
@@ -21,6 +24,7 @@ import org.thingsboard.server.dao.yunteng.service.YtConfigurationEventService; | @@ -21,6 +24,7 @@ import org.thingsboard.server.dao.yunteng.service.YtConfigurationEventService; | ||
21 | import java.util.HashMap; | 24 | import java.util.HashMap; |
22 | import java.util.List; | 25 | import java.util.List; |
23 | import java.util.Map; | 26 | import java.util.Map; |
27 | +import java.util.Optional; | ||
24 | 28 | ||
25 | /** | 29 | /** |
26 | * @author Administrator | 30 | * @author Administrator |
@@ -35,6 +39,39 @@ public class YtConfigurationNodeController extends BaseController { | @@ -35,6 +39,39 @@ public class YtConfigurationNodeController extends BaseController { | ||
35 | private final YtConfigurationEventService eventService; | 39 | private final YtConfigurationEventService eventService; |
36 | private final YtConfigurationActService actService; | 40 | private final YtConfigurationActService actService; |
37 | 41 | ||
42 | + @PostMapping | ||
43 | + @ApiOperation("编辑节点信息") | ||
44 | + public ResponseEntity<ConfigurationNodeDTO> saveNode( | ||
45 | + @Validated({AddGroup.class}) @RequestBody ConfigurationNodeDTO nodeDTO) | ||
46 | + throws ThingsboardException { | ||
47 | + String tenantId = getCurrentUser().getCurrentTenantId(); | ||
48 | + Optional.ofNullable(nodeDTO.getDataSources()).ifPresent(datas ->{ | ||
49 | + datas.forEach(one -> { | ||
50 | + if(!one.getTenantId().equals(tenantId)){ | ||
51 | + throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | ||
52 | + } | ||
53 | + datasourceService.saveConfigurationDatasource(one); | ||
54 | + }); | ||
55 | + }); | ||
56 | + Optional.ofNullable(nodeDTO.getEvent()).ifPresent(datas ->{ | ||
57 | + datas.forEach(one -> { | ||
58 | + if(!one.getTenantId().equals(tenantId)){ | ||
59 | + throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | ||
60 | + } | ||
61 | + eventService.saveConfigurationEvent(one); | ||
62 | + }); | ||
63 | + }); | ||
64 | + Optional.ofNullable(nodeDTO.getAct()).ifPresent(datas ->{ | ||
65 | + datas.forEach(one -> { | ||
66 | + if(!one.getTenantId().equals(tenantId)){ | ||
67 | + throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | ||
68 | + } | ||
69 | + actService.saveConfigurationAct(one); | ||
70 | + }); | ||
71 | + }); | ||
72 | + return ResponseEntity.ok(nodeDTO); | ||
73 | + } | ||
74 | + | ||
38 | @PostMapping("datascource") | 75 | @PostMapping("datascource") |
39 | @ApiOperation("编辑数据源") | 76 | @ApiOperation("编辑数据源") |
40 | public ResponseEntity<ConfigurationDatasourceDTO> saveDatascource( | 77 | public ResponseEntity<ConfigurationDatasourceDTO> saveDatascource( |
@@ -92,7 +129,7 @@ public class YtConfigurationNodeController extends BaseController { | @@ -92,7 +129,7 @@ public class YtConfigurationNodeController extends BaseController { | ||
92 | 129 | ||
93 | @GetMapping("/{levelType}/{levelId}") | 130 | @GetMapping("/{levelType}/{levelId}") |
94 | @ApiOperation("组件信息") | 131 | @ApiOperation("组件信息") |
95 | - public ResponseEntity<Map<String, List>> nodeInform( | 132 | + public ResponseEntity<ConfigurationNodeDTO> nodeInform( |
96 | @ApiParam(value = "组态资源类型,例如:CONFIGURE、CONTENT、NODE", required = true, defaultValue = "NODE") @PathVariable("levelType") String levelType, | 133 | @ApiParam(value = "组态资源类型,例如:CONFIGURE、CONTENT、NODE", required = true, defaultValue = "NODE") @PathVariable("levelType") String levelType, |
97 | @ApiParam(value = "组态资源ID", required = true) @PathVariable("levelId") String levelId) throws ThingsboardException { | 134 | @ApiParam(value = "组态资源ID", required = true) @PathVariable("levelId") String levelId) throws ThingsboardException { |
98 | String tenantId = getCurrentUser().getCurrentTenantId(); | 135 | String tenantId = getCurrentUser().getCurrentTenantId(); |
@@ -100,15 +137,15 @@ public class YtConfigurationNodeController extends BaseController { | @@ -100,15 +137,15 @@ public class YtConfigurationNodeController extends BaseController { | ||
100 | List<ConfigurationDatasourceDTO> sources = datasourceService.listConfigurationDatasource(tenantId, levelType, levelId); | 137 | List<ConfigurationDatasourceDTO> sources = datasourceService.listConfigurationDatasource(tenantId, levelType, levelId); |
101 | List<ConfigurationEventDTO> events = eventService.listConfigurationEvent(tenantId, levelType, levelId); | 138 | List<ConfigurationEventDTO> events = eventService.listConfigurationEvent(tenantId, levelType, levelId); |
102 | List<ConfigurationActDTO> acts = actService.listConfigurationAct(tenantId, levelType, levelId); | 139 | List<ConfigurationActDTO> acts = actService.listConfigurationAct(tenantId, levelType, levelId); |
103 | - Map<String, List> result = new HashMap<>(); | 140 | + ConfigurationNodeDTO result = new ConfigurationNodeDTO(); |
104 | if (sources != null && sources.size() > 0) { | 141 | if (sources != null && sources.size() > 0) { |
105 | - result.put("dataSources", sources); | 142 | + result.setDataSources(sources); |
106 | } | 143 | } |
107 | if (events != null && events.size() > 0) { | 144 | if (events != null && events.size() > 0) { |
108 | - result.put("event", events); | 145 | + result.setEvent(events); |
109 | } | 146 | } |
110 | if (acts != null && acts.size() > 0) { | 147 | if (acts != null && acts.size() > 0) { |
111 | - result.put("act", acts); | 148 | + result.setAct(acts); |
112 | } | 149 | } |
113 | return ResponseEntity.ok(result); | 150 | return ResponseEntity.ok(result); |
114 | } | 151 | } |
@@ -30,10 +30,7 @@ import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | @@ -30,10 +30,7 @@ import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | ||
30 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | 30 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
31 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | 31 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
32 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 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 | import org.thingsboard.server.common.data.yunteng.enums.DeviceState; | 34 | import org.thingsboard.server.common.data.yunteng.enums.DeviceState; |
38 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | 35 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
39 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 36 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
@@ -357,6 +354,26 @@ public class YtDeviceController extends BaseController { | @@ -357,6 +354,26 @@ public class YtDeviceController extends BaseController { | ||
357 | return deviceService.findDevicesByDeviceTypeAndOrganizationId(deviceType,getCurrentUser().getCurrentTenantId(), organizationId); | 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 | @GetMapping("/gateway/{tbDeviceId}") | 377 | @GetMapping("/gateway/{tbDeviceId}") |
361 | @ApiOperation("获取网关设备") | 378 | @ApiOperation("获取网关设备") |
362 | public DeviceDTO findGateWayDeviceByTbDeviceId( | 379 | public DeviceDTO findGateWayDeviceByTbDeviceId( |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/ConfigurationNodeDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | ||
2 | + | ||
3 | +import com.fasterxml.jackson.databind.JsonNode; | ||
4 | +import io.swagger.annotations.ApiModelProperty; | ||
5 | +import lombok.Data; | ||
6 | +import lombok.EqualsAndHashCode; | ||
7 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | ||
8 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | ||
9 | +import org.thingsboard.server.common.data.yunteng.enums.ActTypeEnum; | ||
10 | + | ||
11 | +import javax.validation.constraints.NotEmpty; | ||
12 | +import java.util.List; | ||
13 | + | ||
14 | +/** | ||
15 | + * 组态节点动画效果 | ||
16 | + * @author Administrator | ||
17 | + */ | ||
18 | +@EqualsAndHashCode(callSuper = true) | ||
19 | +@Data | ||
20 | +public class ConfigurationNodeDTO extends TenantDTO { | ||
21 | + @ApiModelProperty(value = "数据源") | ||
22 | + private List<ConfigurationDatasourceDTO> dataSources; | ||
23 | + | ||
24 | + @ApiModelProperty(value = "事件集合") | ||
25 | + private List<ConfigurationEventDTO> event; | ||
26 | + | ||
27 | + @ApiModelProperty(value = "动画集合") | ||
28 | + private List<ConfigurationActDTO> act; | ||
29 | +} |
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 | +} |
@@ -29,4 +29,6 @@ public class ConfigurationAct extends TenantBaseEntity { | @@ -29,4 +29,6 @@ public class ConfigurationAct extends TenantBaseEntity { | ||
29 | private String attr; | 29 | private String attr; |
30 | @TableField(typeHandler = JacksonTypeHandler.class) | 30 | @TableField(typeHandler = JacksonTypeHandler.class) |
31 | private JsonNode condition; | 31 | private JsonNode condition; |
32 | + private boolean enabled; | ||
33 | + | ||
32 | } | 34 | } |
@@ -28,4 +28,6 @@ public class ConfigurationDatasource extends TenantBaseEntity { | @@ -28,4 +28,6 @@ public class ConfigurationDatasource extends TenantBaseEntity { | ||
28 | @TableField(typeHandler = ListStringTypeHandler.class) | 28 | @TableField(typeHandler = ListStringTypeHandler.class) |
29 | private List<String> attr; | 29 | private List<String> attr; |
30 | private String remark; | 30 | private String remark; |
31 | + private boolean enabled; | ||
32 | + | ||
31 | } | 33 | } |
@@ -25,4 +25,5 @@ public class ConfigurationEvent extends TenantBaseEntity { | @@ -25,4 +25,5 @@ public class ConfigurationEvent extends TenantBaseEntity { | ||
25 | @TableField(typeHandler = EnumTypeHandler.class) | 25 | @TableField(typeHandler = EnumTypeHandler.class) |
26 | private EventTypeEnum type; | 26 | private EventTypeEnum type; |
27 | private String remark; | 27 | private String remark; |
28 | + private boolean enabled; | ||
28 | } | 29 | } |
@@ -39,6 +39,7 @@ public class YtConfigurationActServiceImpl | @@ -39,6 +39,7 @@ public class YtConfigurationActServiceImpl | ||
39 | ConfigurationAct old = baseMapper.selectOne(filter); | 39 | ConfigurationAct old = baseMapper.selectOne(filter); |
40 | ConfigurationAct newData = actDTO.getEntity(ConfigurationAct.class); | 40 | ConfigurationAct newData = actDTO.getEntity(ConfigurationAct.class); |
41 | if (old == null) { | 41 | if (old == null) { |
42 | + newData.setEnabled(false); | ||
42 | baseMapper.insert(newData); | 43 | baseMapper.insert(newData); |
43 | } else if(!actDTO.getTenantId().equals(old.getTenantId())){ | 44 | } else if(!actDTO.getTenantId().equals(old.getTenantId())){ |
44 | throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | 45 | throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); |
@@ -37,6 +37,7 @@ public class YtConfigurationDatasourceServiceImpl | @@ -37,6 +37,7 @@ public class YtConfigurationDatasourceServiceImpl | ||
37 | ConfigurationDatasource old = baseMapper.selectOne(filter); | 37 | ConfigurationDatasource old = baseMapper.selectOne(filter); |
38 | ConfigurationDatasource newData = sourceDTO.getEntity(ConfigurationDatasource.class); | 38 | ConfigurationDatasource newData = sourceDTO.getEntity(ConfigurationDatasource.class); |
39 | if (old == null) { | 39 | if (old == null) { |
40 | + newData.setEnabled(false); | ||
40 | baseMapper.insert(newData); | 41 | baseMapper.insert(newData); |
41 | } else if(!sourceDTO.getTenantId().equals(old.getTenantId())){ | 42 | } else if(!sourceDTO.getTenantId().equals(old.getTenantId())){ |
42 | throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | 43 | throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); |
@@ -40,6 +40,7 @@ public class YtConfigurationEventServiceImpl | @@ -40,6 +40,7 @@ public class YtConfigurationEventServiceImpl | ||
40 | ConfigurationEvent old = baseMapper.selectOne(filter); | 40 | ConfigurationEvent old = baseMapper.selectOne(filter); |
41 | ConfigurationEvent newData = eventDTO.getEntity(ConfigurationEvent.class); | 41 | ConfigurationEvent newData = eventDTO.getEntity(ConfigurationEvent.class); |
42 | if (old == null) { | 42 | if (old == null) { |
43 | + newData.setEnabled(false); | ||
43 | baseMapper.insert(newData); | 44 | baseMapper.insert(newData); |
44 | } else if(!eventDTO.getTenantId().equals(old.getTenantId())){ | 45 | } else if(!eventDTO.getTenantId().equals(old.getTenantId())){ |
45 | throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | 46 | throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); |
@@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | @@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
20 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | 20 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
21 | import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; | 21 | import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; |
22 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; | 22 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; |
23 | +import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; | ||
23 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | 24 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
24 | import org.thingsboard.server.common.data.yunteng.enums.ScopeEnum; | 25 | import org.thingsboard.server.common.data.yunteng.enums.ScopeEnum; |
25 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | 26 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
@@ -429,4 +430,19 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -429,4 +430,19 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
429 | } | 430 | } |
430 | return false; | 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,6 +7,7 @@ import org.apache.ibatis.annotations.Param; | ||
7 | import org.thingsboard.server.common.data.yunteng.dto.BaseHomePageTop; | 7 | import org.thingsboard.server.common.data.yunteng.dto.BaseHomePageTop; |
8 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | 8 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
9 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; | 9 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; |
10 | +import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; | ||
10 | import org.thingsboard.server.common.data.yunteng.dto.statistics.AggregationDTO; | 11 | import org.thingsboard.server.common.data.yunteng.dto.statistics.AggregationDTO; |
11 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; | 12 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; |
12 | 13 | ||
@@ -84,4 +85,24 @@ public interface DeviceMapper extends BaseMapper<YtDevice> { | @@ -84,4 +85,24 @@ public interface DeviceMapper extends BaseMapper<YtDevice> { | ||
84 | Integer countMsgs(@Param("queryMap") Map<String, Object> queryMap); | 85 | Integer countMsgs(@Param("queryMap") Map<String, Object> queryMap); |
85 | 86 | ||
86 | Integer countDataPoints(@Param("queryMap") Map<String, Object> queryMap); | 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,6 +3,7 @@ package org.thingsboard.server.dao.yunteng.service; | ||
3 | import org.thingsboard.server.common.data.id.EntityId; | 3 | import org.thingsboard.server.common.data.id.EntityId; |
4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
5 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; | 5 | import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; |
6 | +import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; | ||
6 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | 7 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
7 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 8 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
8 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; | 9 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; |
@@ -103,4 +104,21 @@ public interface YtDeviceService extends BaseService<YtDevice> { | @@ -103,4 +104,21 @@ public interface YtDeviceService extends BaseService<YtDevice> { | ||
103 | * @return | 104 | * @return |
104 | */ | 105 | */ |
105 | Boolean otherUsing(String deviceId,String tenantId); | 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,6 +2,11 @@ | ||
2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
3 | 3 | ||
4 | <mapper namespace="org.thingsboard.server.dao.yunteng.mapper.DeviceMapper"> | 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 | <resultMap type="org.thingsboard.server.common.data.yunteng.dto.DeviceDTO" id="deviceMap"> | 10 | <resultMap type="org.thingsboard.server.common.data.yunteng.dto.DeviceDTO" id="deviceMap"> |
6 | <result property="id" column="id"/> | 11 | <result property="id" column="id"/> |
7 | <result property="name" column="name"/> | 12 | <result property="name" column="name"/> |
@@ -325,4 +330,53 @@ | @@ -325,4 +330,53 @@ | ||
325 | </if> | 330 | </if> |
326 | </where> | 331 | </where> |
327 | </select> | 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 :: TEXT = #{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 | </mapper> | 382 | </mapper> |