Showing
7 changed files
with
133 additions
and
114 deletions
@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestParam; | @@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestParam; | ||
10 | import org.springframework.web.bind.annotation.RestController; | 10 | import org.springframework.web.bind.annotation.RestController; |
11 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 11 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
12 | import org.thingsboard.server.common.data.rpc.RpcStatus; | 12 | import org.thingsboard.server.common.data.rpc.RpcStatus; |
13 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | ||
14 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
13 | import org.thingsboard.server.common.data.yunteng.dto.TkRpcRecordDTO; | 15 | import org.thingsboard.server.common.data.yunteng.dto.TkRpcRecordDTO; |
14 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 16 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
15 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 17 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
@@ -17,6 +19,8 @@ import org.thingsboard.server.controller.BaseController; | @@ -17,6 +19,8 @@ import org.thingsboard.server.controller.BaseController; | ||
17 | import org.thingsboard.server.dao.yunteng.entities.TkRpcRecordEntity; | 19 | import org.thingsboard.server.dao.yunteng.entities.TkRpcRecordEntity; |
18 | import org.thingsboard.server.dao.yunteng.service.TkRpcRecordService; | 20 | import org.thingsboard.server.dao.yunteng.service.TkRpcRecordService; |
19 | 21 | ||
22 | +import java.sql.Timestamp; | ||
23 | + | ||
20 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | 24 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
21 | 25 | ||
22 | /** | 26 | /** |
@@ -27,26 +31,38 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. | @@ -27,26 +31,38 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. | ||
27 | @Api(tags = {"命令下发记录"}) | 31 | @Api(tags = {"命令下发记录"}) |
28 | @RequiredArgsConstructor | 32 | @RequiredArgsConstructor |
29 | public class TkRpcRecordController extends BaseController { | 33 | public class TkRpcRecordController extends BaseController { |
30 | - private final TkRpcRecordService recordService; | ||
31 | - | ||
32 | - @GetMapping(params = {PAGE_SIZE, PAGE}) | ||
33 | - @ApiOperation("分页") | ||
34 | - public TkPageData<TkRpcRecordDTO> pageAlarmProfile( | ||
35 | - @RequestParam(PAGE_SIZE) int pageSize, | ||
36 | - @RequestParam(PAGE) int page, | ||
37 | - @RequestParam(value = "status", required = false) RpcStatus status, | ||
38 | - @RequestParam(value = "name", required = false) String name, | ||
39 | - @RequestParam(value = "tbDeviceId", required = false) String tbDeviceId, | ||
40 | -// @RequestParam(value = "oneway", required = false) Boolean oneway, | ||
41 | - @RequestParam(value = "organizationId", required = false) String organizationId, | ||
42 | - @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
43 | - @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
44 | - throws ThingsboardException { | 34 | + private final TkRpcRecordService recordService; |
45 | 35 | ||
46 | - | ||
47 | - IPage<TkRpcRecordEntity> pageInfrom = recordService.getPage(page, pageSize, orderBy, orderType); | ||
48 | - return recordService.pageDatas(pageInfrom, getCurrentUser().getCurrentTenantId(), tbDeviceId,null, status, organizationId, name); | 36 | + @GetMapping(params = {PAGE_SIZE, PAGE}) |
37 | + @ApiOperation("分页") | ||
38 | + public TkPageData<TkRpcRecordDTO> pageAlarmProfile( | ||
39 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
40 | + @RequestParam(PAGE) int page, | ||
41 | + @RequestParam(value = "status", required = false) RpcStatus status, | ||
42 | + @RequestParam(value = "name", required = false) String name, | ||
43 | + @RequestParam(value = "tbDeviceId", required = false) String tbDeviceId, | ||
44 | + @RequestParam(value = "organizationId", required = false) String organizationId, | ||
45 | + @RequestParam(value = "startTime", required = false) Long startTime, | ||
46 | + @RequestParam(value = "endTime", required = false) Long endTime, | ||
47 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
48 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
49 | + throws ThingsboardException { | ||
50 | + if (null != startTime && null != endTime) { | ||
51 | + if (startTime > endTime) { | ||
52 | + throw new TkDataValidationException( | ||
53 | + ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getMessage()); | ||
54 | + } | ||
49 | } | 55 | } |
50 | 56 | ||
51 | - | 57 | + IPage<TkRpcRecordEntity> pageInfo = recordService.getPage(page, pageSize, orderBy, orderType); |
58 | + return recordService.page( | ||
59 | + pageInfo, | ||
60 | + getCurrentUser().getCurrentTenantId(), | ||
61 | + tbDeviceId, | ||
62 | + status, | ||
63 | + organizationId, | ||
64 | + name, | ||
65 | + startTime, | ||
66 | + endTime); | ||
67 | + } | ||
52 | } | 68 | } |
1 | -/** | ||
2 | - * Copyright © 2016-2022 The Thingsboard Authors | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | package org.thingsboard.server.common.data.yunteng.enums; | 1 | package org.thingsboard.server.common.data.yunteng.enums; |
17 | 2 | ||
18 | public enum TkRpcStatus { | 3 | public enum TkRpcStatus { |
19 | - QUEUED("队列中"), SENT("已发送"), DELIVERED("处理中"), SUCCESSFUL("成功"), TIMEOUT("超时"), EXPIRED("过期"), FAILED("失败"); | 4 | + QUEUED("队列中"), |
5 | + SENT("已发送"), | ||
6 | + DELIVERED("发送成功"), | ||
7 | + SUCCESSFUL("响应成功"), | ||
8 | + TIMEOUT("超时"), | ||
9 | + EXPIRED("已过期"), | ||
10 | + FAILED("响应失败"), | ||
11 | + DELETED("已删除"); | ||
12 | + String label; | ||
20 | 13 | ||
21 | - String label; | ||
22 | - TkRpcStatus(String label){ | ||
23 | - this.label= label; | ||
24 | - } | ||
25 | - public static String getLabel(String name){ | ||
26 | - for(TkRpcStatus type:values()){ | ||
27 | - if(type.name().equals(name)){ | ||
28 | - return type.label; | ||
29 | - } | ||
30 | - } | ||
31 | - return null; | 14 | + TkRpcStatus(String label) { |
15 | + this.label = label; | ||
16 | + } | ||
17 | + | ||
18 | + public static String getLabel(String name) { | ||
19 | + for (TkRpcStatus type : values()) { | ||
20 | + if (type.name().equals(name)) { | ||
21 | + return type.label; | ||
22 | + } | ||
32 | } | 23 | } |
24 | + return null; | ||
25 | + } | ||
33 | } | 26 | } |
@@ -24,24 +24,33 @@ import java.util.stream.Collectors; | @@ -24,24 +24,33 @@ import java.util.stream.Collectors; | ||
24 | @Slf4j | 24 | @Slf4j |
25 | @Service | 25 | @Service |
26 | @RequiredArgsConstructor | 26 | @RequiredArgsConstructor |
27 | -public class TkRpcRecordServiceImpl extends AbstractBaseService<TkRpcRecordMapper, TkRpcRecordEntity> | ||
28 | - implements TkRpcRecordService { | ||
29 | - | ||
30 | - | ||
31 | - private final OrganizationMapper organizationMapper; | ||
32 | - | ||
33 | - @Override | ||
34 | - public TkPageData<TkRpcRecordDTO> pageDatas(IPage<TkRpcRecordEntity> pageInfrom, String tenantId, String deviceId, Boolean oneway, RpcStatus status, String organizationId, String name) { | ||
35 | - List<String> organization = null; | ||
36 | - if (StringUtils.isNotEmpty(organizationId)) { | ||
37 | - List<String> organizationFilter = new ArrayList<>(); | ||
38 | - organizationFilter.add(organizationId); | ||
39 | - organization = organizationMapper.findOrganizationTreeList(tenantId, organizationFilter).stream().map(org -> org.getId()).collect(Collectors.toList()); | ||
40 | - } | ||
41 | - | ||
42 | - IPage<TkRpcRecordDTO> page = baseMapper.getPageDatas(pageInfrom, tenantId, deviceId,name, status, organization, null); | ||
43 | - return getPageData(page, TkRpcRecordDTO.class); | 27 | +public class TkRpcRecordServiceImpl |
28 | + extends AbstractBaseService<TkRpcRecordMapper, TkRpcRecordEntity> | ||
29 | + implements TkRpcRecordService { | ||
30 | + | ||
31 | + private final OrganizationMapper organizationMapper; | ||
32 | + | ||
33 | + @Override | ||
34 | + public TkPageData<TkRpcRecordDTO> page( | ||
35 | + IPage<TkRpcRecordEntity> pageInfo, | ||
36 | + String tenantId, | ||
37 | + String deviceId, | ||
38 | + RpcStatus status, | ||
39 | + String organizationId, | ||
40 | + String name,Long startTime, | ||
41 | + Long endTime) { | ||
42 | + List<String> organization = null; | ||
43 | + if (StringUtils.isNotEmpty(organizationId)) { | ||
44 | + List<String> organizationFilter = new ArrayList<>(); | ||
45 | + organizationFilter.add(organizationId); | ||
46 | + organization = | ||
47 | + organizationMapper.findOrganizationTreeList(tenantId, organizationFilter).stream() | ||
48 | + .map(org -> org.getId()) | ||
49 | + .collect(Collectors.toList()); | ||
44 | } | 50 | } |
45 | 51 | ||
46 | - | 52 | + IPage<TkRpcRecordDTO> page = |
53 | + baseMapper.getPageData(pageInfo, tenantId, deviceId, name, status, organization,startTime,endTime); | ||
54 | + return getPageData(page, TkRpcRecordDTO.class); | ||
55 | + } | ||
47 | } | 56 | } |
@@ -15,13 +15,21 @@ import java.util.List; | @@ -15,13 +15,21 @@ import java.util.List; | ||
15 | */ | 15 | */ |
16 | @Mapper | 16 | @Mapper |
17 | public interface TkRpcRecordMapper extends BaseMapper<TkRpcRecordEntity> { | 17 | public interface TkRpcRecordMapper extends BaseMapper<TkRpcRecordEntity> { |
18 | - /** | ||
19 | - * @param page | ||
20 | - * @param tenantId | ||
21 | - * @param name | ||
22 | - * @param status | ||
23 | - * @param organizationId | ||
24 | - * @return | ||
25 | - */ | ||
26 | - IPage<TkRpcRecordDTO> getPageDatas(IPage<?> page, @Param("tenantId") String tenantId, @Param("tbDeviceId") String tbDeviceId, @Param("name") String name, @Param("status") RpcStatus status, @Param("organization") List<String> organizationId, @Param("oneway") String oneway); | 18 | + /** |
19 | + * @param page | ||
20 | + * @param tenantId | ||
21 | + * @param name | ||
22 | + * @param status | ||
23 | + * @param organizationId | ||
24 | + * @return | ||
25 | + */ | ||
26 | + IPage<TkRpcRecordDTO> getPageData( | ||
27 | + IPage<?> page, | ||
28 | + @Param("tenantId") String tenantId, | ||
29 | + @Param("tbDeviceId") String tbDeviceId, | ||
30 | + @Param("name") String name, | ||
31 | + @Param("status") RpcStatus status, | ||
32 | + @Param("organization") List<String> organizationId, | ||
33 | + @Param("startTime")Long startTime, | ||
34 | + @Param("endTime")Long endTime); | ||
27 | } | 35 | } |
1 | package org.thingsboard.server.dao.yunteng.service; | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | ||
3 | - | ||
4 | - | ||
5 | import com.baomidou.mybatisplus.core.metadata.IPage; | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; |
6 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 4 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
7 | import org.thingsboard.server.dao.yunteng.entities.BaseEntity; | 5 | import org.thingsboard.server.dao.yunteng.entities.BaseEntity; |
@@ -10,9 +8,12 @@ import java.util.Collection; | @@ -10,9 +8,12 @@ import java.util.Collection; | ||
10 | import java.util.List; | 8 | import java.util.List; |
11 | import java.util.Set; | 9 | import java.util.Set; |
12 | 10 | ||
13 | -public interface BaseService<T extends BaseEntity>{ | ||
14 | - List<T> findAllByTenant(String tenantId); | ||
15 | - boolean deleteDataByTenantIds(Set<String> tenantIds); | ||
16 | - boolean insertBatch(Collection<T> entityList, int batchSize); | ||
17 | - IPage<T> getPage(Integer pageNum, Integer pageSize, String orderField, OrderTypeEnum orderType); | 11 | +public interface BaseService<T extends BaseEntity> { |
12 | + List<T> findAllByTenant(String tenantId); | ||
13 | + | ||
14 | + boolean deleteDataByTenantIds(Set<String> tenantIds); | ||
15 | + | ||
16 | + boolean insertBatch(Collection<T> entityList, int batchSize); | ||
17 | + | ||
18 | + IPage<T> getPage(Integer pageNum, Integer pageSize, String orderField, OrderTypeEnum orderType); | ||
18 | } | 19 | } |
@@ -7,24 +7,29 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | @@ -7,24 +7,29 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | ||
7 | import org.thingsboard.server.dao.yunteng.entities.TkRpcRecordEntity; | 7 | import org.thingsboard.server.dao.yunteng.entities.TkRpcRecordEntity; |
8 | 8 | ||
9 | /** | 9 | /** |
10 | - * 第三方平台用户管理相关接口 | ||
11 | - * 例如:微信小程序、钉钉等。 | 10 | + * 第三方平台用户管理相关接口 例如:微信小程序、钉钉等。 |
11 | + * | ||
12 | * @author Administrator | 12 | * @author Administrator |
13 | */ | 13 | */ |
14 | public interface TkRpcRecordService extends BaseService<TkRpcRecordEntity> { | 14 | public interface TkRpcRecordService extends BaseService<TkRpcRecordEntity> { |
15 | 15 | ||
16 | - /** | ||
17 | - * | ||
18 | - * RPC记录分页数据 | ||
19 | - * @param pageInfrom 分页信息 | ||
20 | - * @param tenantId 租户ID | ||
21 | - * @param oneway 响应方式:是否单向 | ||
22 | - * @param status RPC状态 | ||
23 | - * @param organizationId 组织ID | ||
24 | - * @param name 名称,例如:设备、命令、组织、租户 | ||
25 | - * @return | ||
26 | - */ | ||
27 | - TkPageData<TkRpcRecordDTO> pageDatas(IPage<TkRpcRecordEntity> pageInfrom, String tenantId, String deviceId, Boolean oneway, RpcStatus status, String organizationId, String name); | ||
28 | - | ||
29 | - | 16 | + /** |
17 | + * RPC记录分页数据 | ||
18 | + * | ||
19 | + * @param pageInfo 分页信息 | ||
20 | + * @param tenantId 租户ID | ||
21 | + * @param status RPC状态 | ||
22 | + * @param organizationId 组织ID | ||
23 | + * @param name 名称,例如:设备、命令、组织、租户 | ||
24 | + * @return | ||
25 | + */ | ||
26 | + TkPageData<TkRpcRecordDTO> page( | ||
27 | + IPage<TkRpcRecordEntity> pageInfo, | ||
28 | + String tenantId, | ||
29 | + String deviceId, | ||
30 | + RpcStatus status, | ||
31 | + String organizationId, | ||
32 | + String name, | ||
33 | + Long startTime, | ||
34 | + Long endTime); | ||
30 | } | 35 | } |
@@ -22,12 +22,6 @@ | @@ -22,12 +22,6 @@ | ||
22 | <result property="organizationName" column="organization_name"/> | 22 | <result property="organizationName" column="organization_name"/> |
23 | <result column="tenant_name" property="tenantName"/> | 23 | <result column="tenant_name" property="tenantName"/> |
24 | <result column="tenant_id" property="tenantId"/> | 24 | <result column="tenant_id" property="tenantId"/> |
25 | -<!-- <association property="request" javaType="org.thingsboard.server.common.data.yunteng.dto.YtRpcRequestDTO">--> | ||
26 | -<!-- <result column="deviceId" property="deviceId" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/>--> | ||
27 | -<!-- <result column="oneway" property="oneway"/>--> | ||
28 | -<!-- <result column="tenant_enabled" property="retries"/>--> | ||
29 | -<!-- <result column="tenant_expire_time" property="body" />--> | ||
30 | -<!-- </association>--> | ||
31 | </resultMap> | 25 | </resultMap> |
32 | 26 | ||
33 | 27 | ||
@@ -42,20 +36,22 @@ | @@ -42,20 +36,22 @@ | ||
42 | ,dev.name AS device_name,dev.tb_device_id,dev.device_type,dev.sn,dev.tenant_id,dev.id AS device_id | 36 | ,dev.name AS device_name,dev.tb_device_id,dev.device_type,dev.sn,dev.tenant_id,dev.id AS device_id |
43 | ,ten.title AS tenant_name | 37 | ,ten.title AS tenant_name |
44 | </sql> | 38 | </sql> |
45 | - <select id="getPageDatas" resultMap="dataMap"> | 39 | + <select id="getPageData" resultMap="dataMap"> |
46 | SELECT <include refid="detailColumns"/> | 40 | SELECT <include refid="detailColumns"/> |
47 | FROM rpc base | 41 | FROM rpc base |
48 | LEFT JOIN tk_device dev ON base.device_id =dev.tb_device_id::uuid | 42 | LEFT JOIN tk_device dev ON base.device_id =dev.tb_device_id::uuid |
49 | LEFT JOIN tk_organization org ON dev.organization_id = org.id | 43 | LEFT JOIN tk_organization org ON dev.organization_id = org.id |
50 | LEFT JOIN tenant ten ON base.tenant_id = ten.id | 44 | LEFT JOIN tenant ten ON base.tenant_id = ten.id |
51 | <where> | 45 | <where> |
52 | - 1=1 | ||
53 | <if test="tenantId !=null and tenantId !=''"> | 46 | <if test="tenantId !=null and tenantId !=''"> |
54 | AND base.tenant_id = #{tenantId}::uuid | 47 | AND base.tenant_id = #{tenantId}::uuid |
55 | </if> | 48 | </if> |
56 | <if test="tbDeviceId !=null "> | 49 | <if test="tbDeviceId !=null "> |
57 | AND base.device_id = #{tbDeviceId}::uuid | 50 | AND base.device_id = #{tbDeviceId}::uuid |
58 | </if> | 51 | </if> |
52 | + <if test="endTime !=null and startTime !=null"> | ||
53 | + AND base.created_time >= #{startTime} AND base.created_time < #{endTime} | ||
54 | + </if> | ||
59 | <if test="name !=null and name !=''"> | 55 | <if test="name !=null and name !=''"> |
60 | AND ( | 56 | AND ( |
61 | dev.name LIKE concat('%',#{name}::TEXT,'%') | 57 | dev.name LIKE concat('%',#{name}::TEXT,'%') |
@@ -67,17 +63,8 @@ | @@ -67,17 +63,8 @@ | ||
67 | base.request LIKE concat('%',#{name}::TEXT,'%') | 63 | base.request LIKE concat('%',#{name}::TEXT,'%') |
68 | ) | 64 | ) |
69 | </if> | 65 | </if> |
70 | - <if test="oneway !=null and name !=''"> | ||
71 | - AND base.request LIKE concat('%',#{oneway}::TEXT,'%') | ||
72 | - </if> | ||
73 | <if test="status !=null"> | 66 | <if test="status !=null"> |
74 | - AND base.status | ||
75 | - <if test="status.toString() == 'SUCCESSFUL'"> | ||
76 | - = #{status} | ||
77 | - </if> | ||
78 | - <if test="status.toString() != 'SUCCESSFUL'"> | ||
79 | - != 'SUCCESSFUL' | ||
80 | - </if> | 67 | + AND base.status = #{status} |
81 | </if> | 68 | </if> |
82 | <if test="organization !=null"> | 69 | <if test="organization !=null"> |
83 | AND dev.organization_id IN | 70 | AND dev.organization_id IN |