Showing
6 changed files
with
193 additions
and
69 deletions
@@ -32,6 +32,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidatio | @@ -32,6 +32,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidatio | ||
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; | 33 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
34 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | 34 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
35 | +import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; | ||
35 | import org.thingsboard.server.common.data.yunteng.dto.YtCredentialsDto; | 36 | import org.thingsboard.server.common.data.yunteng.dto.YtCredentialsDto; |
36 | import org.thingsboard.server.common.data.yunteng.enums.DeviceState; | 37 | import org.thingsboard.server.common.data.yunteng.enums.DeviceState; |
37 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | 38 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
@@ -266,6 +267,40 @@ public class YtDeviceController extends BaseController { | @@ -266,6 +267,40 @@ public class YtDeviceController extends BaseController { | ||
266 | } | 267 | } |
267 | return deviceService.page(getCurrentUser().getCurrentTenantId(), queryMap); | 268 | return deviceService.page(getCurrentUser().getCurrentTenantId(), queryMap); |
268 | } | 269 | } |
270 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | ||
271 | + @GetMapping(path = {"/relation"},params = {PAGE_SIZE, PAGE}) | ||
272 | + @ApiOperation("子设备查询") | ||
273 | + public YtPageData<RelationDeviceDTO> pageRelationDevice( | ||
274 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
275 | + @RequestParam(PAGE) int page, | ||
276 | + @RequestParam(value = "name", required = false) String name, | ||
277 | + @RequestParam(value = "deviceState", required = false) DeviceState deviceState, | ||
278 | + @RequestParam(value = "fromId") String fromId, | ||
279 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
280 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { | ||
281 | + HashMap<String, Object> queryMap = new HashMap<>(); | ||
282 | + queryMap.put(PAGE_SIZE, pageSize); | ||
283 | + queryMap.put(PAGE, page); | ||
284 | + queryMap.put(ORDER_FILED, orderBy); | ||
285 | + queryMap.put("name", name); | ||
286 | + queryMap.put("fromId", fromId); | ||
287 | + queryMap.put("tenantId", getCurrentUser().getCurrentTenantId()); | ||
288 | + if (deviceState != null) { | ||
289 | + if(deviceState != DeviceState.INACTIVE){ | ||
290 | + queryMap.put("deviceState", deviceState == DeviceState.ONLINE); | ||
291 | + }else{ | ||
292 | + queryMap.put("activeState",DeviceState.INACTIVE); | ||
293 | + } | ||
294 | + } | ||
295 | + if (orderType != null) { | ||
296 | + queryMap.put(ORDER_TYPE, orderType.name()); | ||
297 | + } | ||
298 | + // 如果当前用户是客户 | ||
299 | + if (getCurrentUser().isCustomerUser()) { | ||
300 | + queryMap.put("customerId", getCurrentUser().getCustomerId().toString()); | ||
301 | + } | ||
302 | + return deviceService.pageRelation(queryMap); | ||
303 | + } | ||
269 | 304 | ||
270 | @PostMapping("/import") | 305 | @PostMapping("/import") |
271 | @ApiOperation("导入配置") | 306 | @ApiOperation("导入配置") |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/RelationDeviceDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | ||
2 | +import lombok.Data; | ||
3 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceState; | ||
4 | + | ||
5 | +@Data | ||
6 | +public class RelationDeviceDTO { | ||
7 | + private String tbDeviceId; | ||
8 | + private String tbDeviceName; | ||
9 | + private String label; | ||
10 | + private DeviceState deviceState; | ||
11 | + private Long createdTime; | ||
12 | + private Long lastOnlineTime; | ||
13 | + | ||
14 | + public void setDeviceState(boolean deviceState) { | ||
15 | + if (deviceState) { | ||
16 | + this.deviceState = DeviceState.ONLINE; | ||
17 | + } else { | ||
18 | + this.deviceState = DeviceState.OFFLINE; | ||
19 | + } | ||
20 | + } | ||
21 | + | ||
22 | + public DeviceState getDeviceState() { | ||
23 | + if (lastOnlineTime == null) { | ||
24 | + return DeviceState.INACTIVE; | ||
25 | + } | ||
26 | + return deviceState; | ||
27 | + } | ||
28 | +} |
@@ -3,7 +3,6 @@ package org.thingsboard.server.dao.yunteng.impl; | @@ -3,7 +3,6 @@ package org.thingsboard.server.dao.yunteng.impl; | ||
3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
5 | import com.baomidou.mybatisplus.core.metadata.IPage; | 5 | import com.baomidou.mybatisplus.core.metadata.IPage; |
6 | -import com.fasterxml.jackson.databind.JsonNode; | ||
7 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
8 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
9 | import org.apache.commons.lang3.StringUtils; | 8 | import org.apache.commons.lang3.StringUtils; |
@@ -12,18 +11,16 @@ import org.springframework.transaction.annotation.Transactional; | @@ -12,18 +11,16 @@ import org.springframework.transaction.annotation.Transactional; | ||
12 | import org.thingsboard.server.common.data.DeviceProfile; | 11 | import org.thingsboard.server.common.data.DeviceProfile; |
13 | import org.thingsboard.server.common.data.id.EntityId; | 12 | import org.thingsboard.server.common.data.id.EntityId; |
14 | import org.thingsboard.server.common.data.id.TenantId; | 13 | import org.thingsboard.server.common.data.id.TenantId; |
15 | -import org.thingsboard.server.common.data.security.DeviceCredentials; | ||
16 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | 14 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
17 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | 15 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
18 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | 16 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
19 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 17 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
20 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | 18 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
21 | import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; | 19 | import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; |
22 | -import org.thingsboard.server.common.data.yunteng.enums.DeviceState; | 20 | +import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; |
23 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | 21 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
24 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | 22 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
25 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 23 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
26 | -import org.thingsboard.server.dao.device.DeviceCredentialsDao; | ||
27 | import org.thingsboard.server.dao.device.DeviceProfileDao; | 24 | import org.thingsboard.server.dao.device.DeviceProfileDao; |
28 | import org.thingsboard.server.dao.yunteng.entities.Organization; | 25 | import org.thingsboard.server.dao.yunteng.entities.Organization; |
29 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; | 26 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; |
@@ -42,7 +39,6 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -42,7 +39,6 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
42 | implements YtDeviceService { | 39 | implements YtDeviceService { |
43 | 40 | ||
44 | private final DeviceProfileDao deviceProfileDao; | 41 | private final DeviceProfileDao deviceProfileDao; |
45 | - private final DeviceCredentialsDao deviceCredentialsDao; | ||
46 | 42 | ||
47 | private final OrganizationMapper ytOrganizationMapper; | 43 | private final OrganizationMapper ytOrganizationMapper; |
48 | 44 | ||
@@ -258,6 +254,14 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -258,6 +254,14 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
258 | } | 254 | } |
259 | 255 | ||
260 | @Override | 256 | @Override |
257 | + public YtPageData<RelationDeviceDTO> pageRelation(Map<String, Object> queryMap) { | ||
258 | + IPage<YtDevice> page = getPage(queryMap, "last_online_time", false); | ||
259 | + IPage<RelationDeviceDTO> deviceIPage = baseMapper.getRelationDevicePage(page, queryMap); | ||
260 | + List<RelationDeviceDTO> records = deviceIPage.getRecords(); | ||
261 | + return new YtPageData<>(records, deviceIPage.getTotal()); | ||
262 | + } | ||
263 | + | ||
264 | + @Override | ||
261 | public List<DeviceDTO> findTbDeviceId(String tenantId, DeviceDTO deviceDTO) { | 265 | public List<DeviceDTO> findTbDeviceId(String tenantId, DeviceDTO deviceDTO) { |
262 | List<YtDevice> deviceList = | 266 | List<YtDevice> deviceList = |
263 | baseMapper.selectList( | 267 | baseMapper.selectList( |
@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper; | @@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper; | ||
6 | import org.apache.ibatis.annotations.Param; | 6 | import org.apache.ibatis.annotations.Param; |
7 | import org.thingsboard.server.common.data.Device; | 7 | import org.thingsboard.server.common.data.Device; |
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.dao.yunteng.entities.YtDevice; | 10 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; |
10 | 11 | ||
11 | import java.util.List; | 12 | import java.util.List; |
@@ -21,7 +22,8 @@ public interface DeviceMapper extends BaseMapper<YtDevice> { | @@ -21,7 +22,8 @@ public interface DeviceMapper extends BaseMapper<YtDevice> { | ||
21 | 22 | ||
22 | /** | 23 | /** |
23 | * 通过网关子设备的TB设备ID查询网关设备信息 | 24 | * 通过网关子设备的TB设备ID查询网关设备信息 |
24 | - * @param tbDeviceId 网关子设备的TB设备ID | 25 | + * |
26 | + * @param tbDeviceId 网关子设备的TB设备ID | ||
25 | * @return 网关设备信息 | 27 | * @return 网关设备信息 |
26 | */ | 28 | */ |
27 | List<DeviceDTO> findGateWayDeviceByTbDeviceId(@Param("tbDeviceId") String tbDeviceId); | 29 | List<DeviceDTO> findGateWayDeviceByTbDeviceId(@Param("tbDeviceId") String tbDeviceId); |
@@ -31,14 +33,23 @@ public interface DeviceMapper extends BaseMapper<YtDevice> { | @@ -31,14 +33,23 @@ public interface DeviceMapper extends BaseMapper<YtDevice> { | ||
31 | * | 33 | * |
32 | * @param tbDeviceId TB设备主键 | 34 | * @param tbDeviceId TB设备主键 |
33 | * @param created 告警状态:0正常,1告警 | 35 | * @param created 告警状态:0正常,1告警 |
34 | - * @return | 36 | + * @return true or false |
35 | */ | 37 | */ |
36 | - boolean freshAlarmStatus(@Param("tbDeviceId") String tbDeviceId,@Param("created") Integer created); | 38 | + boolean freshAlarmStatus(@Param("tbDeviceId") String tbDeviceId, @Param("created") Integer created); |
37 | 39 | ||
38 | /** | 40 | /** |
39 | * 用于统计设备相关信息 | 41 | * 用于统计设备相关信息 |
42 | + * | ||
40 | * @param queryMap 查询条件 | 43 | * @param queryMap 查询条件 |
41 | * @return 查询的设备信息 | 44 | * @return 查询的设备信息 |
42 | */ | 45 | */ |
43 | - List<DeviceDTO> findDevices(@Param("queryMap") Map<String,Object> queryMap); | 46 | + List<DeviceDTO> findDevices(@Param("queryMap") Map<String, Object> queryMap); |
47 | + | ||
48 | + /** | ||
49 | + * 获取关联设备的子设备分页列表 | ||
50 | + * @param page 分页 | ||
51 | + * @param queryMap 查询条件 | ||
52 | + * @return 分页数据 | ||
53 | + */ | ||
54 | + IPage<RelationDeviceDTO> getRelationDevicePage(IPage<?> page, @Param("queryMap") Map<String, Object> queryMap); | ||
44 | } | 55 | } |
1 | package org.thingsboard.server.dao.yunteng.service; | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | ||
3 | -import org.thingsboard.server.common.data.id.DeviceId; | ||
4 | import org.thingsboard.server.common.data.id.EntityId; | 3 | import org.thingsboard.server.common.data.id.EntityId; |
5 | 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; | ||
6 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | 6 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
7 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 7 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
8 | 8 | ||
@@ -12,74 +12,77 @@ import java.util.Optional; | @@ -12,74 +12,77 @@ import java.util.Optional; | ||
12 | import java.util.Set; | 12 | import java.util.Set; |
13 | 13 | ||
14 | public interface YtDeviceService { | 14 | public interface YtDeviceService { |
15 | - DeviceDTO insertOrUpdate(String tenantId, DeviceDTO deviceDTO); | 15 | + DeviceDTO insertOrUpdate(String tenantId, DeviceDTO deviceDTO); |
16 | 16 | ||
17 | - void deleteDevices(String tenantId, Set<String> ids); | 17 | + void deleteDevices(String tenantId, Set<String> ids); |
18 | 18 | ||
19 | - Optional<DeviceDTO> getDevice(String tenantId, String id); | 19 | + Optional<DeviceDTO> getDevice(String tenantId, String id); |
20 | 20 | ||
21 | - YtPageData<DeviceDTO> page(String tenantId, Map<String, Object> queryMap); | 21 | + YtPageData<DeviceDTO> page(String tenantId, Map<String, Object> queryMap); |
22 | 22 | ||
23 | - /** | ||
24 | - * 验证表单数据有效性 | ||
25 | - * | ||
26 | - * @param ytDevice | ||
27 | - */ | ||
28 | - boolean validateFormdata(String currentTenantId, DeviceDTO ytDevice); | 23 | + YtPageData<RelationDeviceDTO> pageRelation(Map<String, Object> queryMap); |
29 | 24 | ||
30 | - /** | ||
31 | - * 查询所有的设备信息 | ||
32 | - * | ||
33 | - * @param deviceDTO 过滤参数 | ||
34 | - * @return List<DeviceDTO> | ||
35 | - */ | ||
36 | - List<DeviceDTO> findTbDeviceId(String tenantId, DeviceDTO deviceDTO); | 25 | + /** |
26 | + * 验证表单数据有效性 | ||
27 | + * | ||
28 | + * @param ytDevice | ||
29 | + */ | ||
30 | + boolean validateFormdata(String currentTenantId, DeviceDTO ytDevice); | ||
37 | 31 | ||
38 | - List<String> findTbDeviceId(String tenantId, Set<String> ids); | 32 | + /** |
33 | + * 查询所有的设备信息 | ||
34 | + * | ||
35 | + * @param deviceDTO 过滤参数 | ||
36 | + * @return List<DeviceDTO> | ||
37 | + */ | ||
38 | + List<DeviceDTO> findTbDeviceId(String tenantId, DeviceDTO deviceDTO); | ||
39 | 39 | ||
40 | - /** | ||
41 | - * 通过设备类型和组织ID查询所有的设备 | ||
42 | - * | ||
43 | - * @param deviceType 设备类型 | ||
44 | - * @param organizationId 组织ID | ||
45 | - * @return 设备列表 | ||
46 | - */ | ||
47 | - List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId(DeviceTypeEnum deviceType, String organizationId); | 40 | + List<String> findTbDeviceId(String tenantId, Set<String> ids); |
48 | 41 | ||
49 | - /** | ||
50 | - * 通过设备ID和租户ID判断该设备是否存在 | ||
51 | - * | ||
52 | - * @param tenantId 租户ID | ||
53 | - * @param deviceId 设备ID | ||
54 | - * @return 设备 | ||
55 | - */ | ||
56 | - DeviceDTO checkDeviceByTenantIdAndDeviceId(String tenantId, String deviceId); | 42 | + /** |
43 | + * 通过设备类型和组织ID查询所有的设备 | ||
44 | + * | ||
45 | + * @param deviceType 设备类型 | ||
46 | + * @param organizationId 组织ID | ||
47 | + * @return 设备列表 | ||
48 | + */ | ||
49 | + List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId( | ||
50 | + DeviceTypeEnum deviceType, String organizationId); | ||
57 | 51 | ||
58 | - /** | ||
59 | - * 通过网关子设备的TB设备ID查询网关设备信息 | ||
60 | - * | ||
61 | - * @param tbDeviceId 网关子设备的TB设备ID | ||
62 | - * @param tenantId 租户ID | ||
63 | - * @return 网关设备信息 | ||
64 | - */ | ||
65 | - List<DeviceDTO> findGateWayDeviceByTbDeviceId(String tenantId, String tbDeviceId); | 52 | + /** |
53 | + * 通过设备ID和租户ID判断该设备是否存在 | ||
54 | + * | ||
55 | + * @param tenantId 租户ID | ||
56 | + * @param deviceId 设备ID | ||
57 | + * @return 设备 | ||
58 | + */ | ||
59 | + DeviceDTO checkDeviceByTenantIdAndDeviceId(String tenantId, String deviceId); | ||
66 | 60 | ||
67 | - /** | ||
68 | - * 通过设备ID和租户ID检查设备是否存在 | ||
69 | - * | ||
70 | - * @param tenantId 租户ID | ||
71 | - * @param deviceId 设备ID | ||
72 | - * @param isTbDeviceId 是TB设备ID | ||
73 | - * @return 设备信息 | ||
74 | - */ | ||
75 | - DeviceDTO checkDeviceByTenantIdAndId(String tenantId, String deviceId, boolean isTbDeviceId); | 61 | + /** |
62 | + * 通过网关子设备的TB设备ID查询网关设备信息 | ||
63 | + * | ||
64 | + * @param tbDeviceId 网关子设备的TB设备ID | ||
65 | + * @param tenantId 租户ID | ||
66 | + * @return 网关设备信息 | ||
67 | + */ | ||
68 | + List<DeviceDTO> findGateWayDeviceByTbDeviceId(String tenantId, String tbDeviceId); | ||
76 | 69 | ||
77 | - /** | ||
78 | - * 更新设备告警状态 | ||
79 | - * | ||
80 | - * @param tbDeviceId TB设备主键 | ||
81 | - * @param created 告警状态:0正常,1告警 | ||
82 | - * @return | ||
83 | - */ | ||
84 | - boolean freshAlarmStatus(EntityId tbDeviceId, Integer created); | 70 | + /** |
71 | + * 通过设备ID和租户ID检查设备是否存在 | ||
72 | + * | ||
73 | + * @param tenantId 租户ID | ||
74 | + * @param deviceId 设备ID | ||
75 | + * @param isTbDeviceId 是TB设备ID | ||
76 | + * @return 设备信息 | ||
77 | + */ | ||
78 | + DeviceDTO checkDeviceByTenantIdAndId(String tenantId, String deviceId, boolean isTbDeviceId); | ||
79 | + | ||
80 | + /** | ||
81 | + * 更新设备告警状态 | ||
82 | + * | ||
83 | + * @param tbDeviceId TB设备主键 | ||
84 | + * @param created 告警状态:0正常,1告警 | ||
85 | + * @return | ||
86 | + */ | ||
87 | + boolean freshAlarmStatus(EntityId tbDeviceId, Integer created); | ||
85 | } | 88 | } |
@@ -33,6 +33,14 @@ | @@ -33,6 +33,14 @@ | ||
33 | <result property="name" column="organization_name"/> | 33 | <result property="name" column="organization_name"/> |
34 | </association> | 34 | </association> |
35 | </resultMap> | 35 | </resultMap> |
36 | + <resultMap id="relationDeviceMap" type="org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO"> | ||
37 | + <result property="tbDeviceId" column="id"/> | ||
38 | + <result property="tbDeviceName" column="name"/> | ||
39 | + <result property="label" column="label"/> | ||
40 | + <result property="deviceState" column="status" /> | ||
41 | + <result property="createdTime" column="created_time"/> | ||
42 | + <result property="lastOnlineTime" column="last_online_time"/> | ||
43 | + </resultMap> | ||
36 | <sql id="basicColumns"> | 44 | <sql id="basicColumns"> |
37 | ifd.id,ifd.name,ifd.device_info,ifd.profile_id,ifd.active_time,ifd.tenant_id,ifd.description | 45 | ifd.id,ifd.name,ifd.device_info,ifd.profile_id,ifd.active_time,ifd.tenant_id,ifd.description |
38 | ,ifd.tb_device_id,ifd.label,ifd.last_connect_time,ifd.device_type,ifd.device_state,ifd.create_time,ifd.update_time,ifd.creator, | 46 | ,ifd.tb_device_id,ifd.label,ifd.last_connect_time,ifd.device_type,ifd.device_state,ifd.create_time,ifd.update_time,ifd.creator, |
@@ -163,4 +171,39 @@ | @@ -163,4 +171,39 @@ | ||
163 | </if> | 171 | </if> |
164 | </where> | 172 | </where> |
165 | </select> | 173 | </select> |
174 | + <select id="getRelationDevicePage" resultMap="relationDeviceMap"> | ||
175 | + SELECT | ||
176 | + de.id, | ||
177 | + de.name, | ||
178 | + de.label, | ||
179 | + de.created_time, | ||
180 | + A.bool_v AS status, | ||
181 | + b.long_v AS last_online_time | ||
182 | + FROM | ||
183 | + device de | ||
184 | + LEFT JOIN relation rt ON de."id" = rt.to_id | ||
185 | + LEFT JOIN attribute_kv A ON de."id" = A.entity_id | ||
186 | + AND A.entity_type = 'DEVICE' | ||
187 | + AND A.attribute_key = 'active' | ||
188 | + LEFT JOIN attribute_kv b ON de."id" = b.entity_id | ||
189 | + AND b.entity_type = 'DEVICE' | ||
190 | + AND b.attribute_key = 'lastActivityTime' | ||
191 | + <where> | ||
192 | + rt.from_id ::TEXT = #{queryMap.fromId} | ||
193 | + AND de.tenant_id ::TEXT = #{queryMap.tenantId} | ||
194 | + <if test="queryMap.customerId !=null and queryMap.customerId !=''"> | ||
195 | + AND de.customer_id ::TEXT = #{queryMap.customerId} | ||
196 | + </if> | ||
197 | + <if test="queryMap.name !=null and queryMap.name !=''"> | ||
198 | + AND de.name LIKE concat('%',#{queryMap.name}::TEXT,'%') | ||
199 | + </if> | ||
200 | + <if test="queryMap.deviceState !=null"> | ||
201 | + AND A.bool_v = #{queryMap.deviceState} | ||
202 | + AND b.long_v IS NOT NULL | ||
203 | + </if> | ||
204 | + <if test="queryMap.activeState !=null"> | ||
205 | + AND b.long_v IS NULL | ||
206 | + </if> | ||
207 | + </where> | ||
208 | + </select> | ||
166 | </mapper> | 209 | </mapper> |