Showing
18 changed files
with
700 additions
and
156 deletions
... | ... | @@ -3,6 +3,7 @@ package org.thingsboard.server.controller.yunteng; |
3 | 3 | import io.swagger.annotations.Api; |
4 | 4 | import io.swagger.annotations.ApiOperation; |
5 | 5 | import lombok.RequiredArgsConstructor; |
6 | +import org.springframework.http.HttpStatus; | |
6 | 7 | import org.springframework.http.ResponseEntity; |
7 | 8 | import org.springframework.security.access.prepost.PreAuthorize; |
8 | 9 | import org.springframework.web.bind.annotation.GetMapping; |
... | ... | @@ -14,11 +15,13 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; |
14 | 15 | import org.thingsboard.server.common.data.query.TsValue; |
15 | 16 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
16 | 17 | import org.thingsboard.server.common.data.yunteng.dto.*; |
18 | +import org.thingsboard.server.common.data.yunteng.dto.statistics.HomePageAppDTO; | |
17 | 19 | import org.thingsboard.server.common.data.yunteng.enums.TrendType; |
18 | 20 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
19 | 21 | import org.thingsboard.server.controller.BaseController; |
20 | 22 | import org.thingsboard.server.dao.exception.DataValidationException; |
21 | 23 | import org.thingsboard.server.dao.yunteng.service.HomePageService; |
24 | +import org.thingsboard.server.service.security.model.SecurityUser; | |
22 | 25 | |
23 | 26 | import java.util.HashMap; |
24 | 27 | import java.util.List; |
... | ... | @@ -33,66 +36,78 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
33 | 36 | @RestController |
34 | 37 | public class HomePageController extends BaseController { |
35 | 38 | |
36 | - private final HomePageService homePageService; | |
39 | + private final HomePageService homePageService; | |
37 | 40 | |
38 | - @GetMapping("left/top") | |
39 | - @ApiOperation(value = "获取左侧顶部信息") | |
40 | - public HomePageLeftTopDTO getLeftTopInfo() | |
41 | - throws ThingsboardException, ExecutionException, InterruptedException { | |
42 | - return homePageService.getHomePageLeftTopInfo( | |
43 | - getCurrentUser().isPtSysadmin(), | |
44 | - getCurrentUser().isPtAdmin(), | |
45 | - getCurrentUser().isPtTenantAdmin(), | |
46 | - getCurrentUser().getCurrentTenantId(), | |
47 | - getCurrentUser().getCurrentUserId()); | |
48 | - } | |
49 | - | |
50 | - @GetMapping("right/overdue") | |
51 | - @ApiOperation(value = "获取右侧过期租户信息") | |
52 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | |
53 | - public ResponseEntity<YtPageData<TenantDTO>> getRightTopInfo( | |
54 | - @RequestParam(PAGE) int page, @RequestParam(PAGE_SIZE) int pageSize) { | |
55 | - HashMap<String, Object> queryMap = new HashMap<>(); | |
56 | - queryMap.put(PAGE_SIZE, pageSize); | |
57 | - queryMap.put(PAGE, page); | |
58 | - return ResponseEntity.ok(homePageService.getHomePageRightInfo(queryMap)); | |
59 | - } | |
41 | + @GetMapping("left/top") | |
42 | + @ApiOperation(value = "获取左侧顶部信息") | |
43 | + public HomePageLeftTopDTO getLeftTopInfo() | |
44 | + throws ThingsboardException, ExecutionException, InterruptedException { | |
45 | + return homePageService.getHomePageLeftTopInfo( | |
46 | + getCurrentUser().isPtSysadmin(), | |
47 | + getCurrentUser().isPtAdmin(), | |
48 | + getCurrentUser().isPtTenantAdmin(), | |
49 | + getCurrentUser().getCurrentTenantId(), | |
50 | + getCurrentUser().getCurrentUserId()); | |
51 | + } | |
60 | 52 | |
61 | - @GetMapping("right/top10") | |
62 | - @ApiOperation(value = "获取右侧Top10") | |
63 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | |
64 | - public DeferredResult<List<TenantTransportMessageDTO>> getTop10() { | |
65 | - return homePageService.getTop10(); | |
66 | - } | |
53 | + @GetMapping("right/overdue") | |
54 | + @ApiOperation(value = "获取右侧过期租户信息") | |
55 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | |
56 | + public ResponseEntity<YtPageData<TenantDTO>> getRightTopInfo( | |
57 | + @RequestParam(PAGE) int page, @RequestParam(PAGE_SIZE) int pageSize) { | |
58 | + HashMap<String, Object> queryMap = new HashMap<>(); | |
59 | + queryMap.put(PAGE_SIZE, pageSize); | |
60 | + queryMap.put(PAGE, page); | |
61 | + return ResponseEntity.ok(homePageService.getHomePageRightInfo(queryMap)); | |
62 | + } | |
67 | 63 | |
68 | - @GetMapping("left/bottom") | |
69 | - @ApiOperation(value = "获取左侧底部信息") | |
70 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN','CUSTOMER_USER')") | |
71 | - public DeferredResult<List<TsValue>> getLeftBottomInfo( | |
72 | - @RequestParam(value = "startTs") long startTs, | |
73 | - @RequestParam("endTs") long endTs, | |
74 | - @RequestParam("interval") long interval, | |
75 | - @RequestParam("trend") TrendType trend) | |
76 | - throws ThingsboardException { | |
77 | - String customerId; | |
78 | - if (getCurrentUser().isPtAdmin()) { | |
79 | - customerId = getCurrentUser().getCurrentTenantId(); | |
80 | - } else { | |
81 | - customerId = getCurrentUser().getCustomerId().getId().toString(); | |
64 | + @GetMapping("right/top10") | |
65 | + @ApiOperation(value = "获取右侧Top10") | |
66 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | |
67 | + public DeferredResult<List<TenantTransportMessageDTO>> getTop10() { | |
68 | + return homePageService.getTop10(); | |
82 | 69 | } |
83 | - boolean isCustomer = getCurrentUser().isCustomerUser(); | |
84 | - if (TrendType.CUSTOMER_MESSAGE_STATISTICAL == trend | |
85 | - || TrendType.CUSTOMER_ALARM_STATISTICAL == trend) { | |
86 | - if (!isCustomer) { | |
87 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
88 | - } | |
70 | + | |
71 | + @GetMapping("left/bottom") | |
72 | + @ApiOperation(value = "获取左侧底部信息") | |
73 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN','CUSTOMER_USER')") | |
74 | + public DeferredResult<List<TsValue>> getLeftBottomInfo( | |
75 | + @RequestParam(value = "startTs") long startTs, | |
76 | + @RequestParam("endTs") long endTs, | |
77 | + @RequestParam("interval") long interval, | |
78 | + @RequestParam("trend") TrendType trend) | |
79 | + throws ThingsboardException { | |
80 | + String customerId; | |
81 | + if (getCurrentUser().isPtAdmin()) { | |
82 | + customerId = getCurrentUser().getCurrentTenantId(); | |
83 | + } else { | |
84 | + customerId = getCurrentUser().getCustomerId().getId().toString(); | |
85 | + } | |
86 | + boolean isCustomer = getCurrentUser().isCustomerUser(); | |
87 | + if (TrendType.CUSTOMER_MESSAGE_STATISTICAL == trend | |
88 | + || TrendType.CUSTOMER_ALARM_STATISTICAL == trend) { | |
89 | + if (!isCustomer) { | |
90 | + throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
91 | + } | |
92 | + } | |
93 | + if (TrendType.TENANT_TREND == trend || TrendType.CUSTOMER_TREND == trend) { | |
94 | + if (isCustomer) { | |
95 | + throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
96 | + } | |
97 | + } | |
98 | + return homePageService.getHomePageLeftBottomInfo( | |
99 | + customerId, startTs, endTs, interval, trend, isCustomer); | |
89 | 100 | } |
90 | - if (TrendType.TENANT_TREND == trend || TrendType.CUSTOMER_TREND == trend) { | |
91 | - if (isCustomer) { | |
92 | - throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
93 | - } | |
101 | + | |
102 | + @GetMapping("app") | |
103 | + @ApiOperation(value = "小程序首页统计信息") | |
104 | + public ResponseEntity<HomePageAppDTO> appStatistics() | |
105 | + throws ThingsboardException, ExecutionException, InterruptedException { | |
106 | + SecurityUser user = getCurrentUser(); | |
107 | + if(user == null){ | |
108 | + return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); | |
109 | + } | |
110 | + HomePageAppDTO app = homePageService.app(user.isPtSysadmin(),user.isPtAdmin(),user.isPtTenantAdmin(),user.getTenantId(),user.getCustomerId()); | |
111 | + return ResponseEntity.ok(app); | |
94 | 112 | } |
95 | - return homePageService.getHomePageLeftBottomInfo( | |
96 | - customerId, startTs, endTs, interval, trend, isCustomer); | |
97 | - } | |
98 | 113 | } | ... | ... |
... | ... | @@ -3,21 +3,22 @@ package org.thingsboard.server.common.data.yunteng.dto; |
3 | 3 | import io.swagger.annotations.ApiModel; |
4 | 4 | import io.swagger.annotations.ApiModelProperty; |
5 | 5 | import lombok.Data; |
6 | + | |
6 | 7 | @Data |
7 | -@ApiModel("首页左边顶部信息") | |
8 | -public class HomePageLeftTopDTO{ | |
9 | - @ApiModelProperty("顶部设备统计") | |
10 | - private HomeDeviceInfoDTO deviceInfo; | |
8 | +@ApiModel("首页统计信息") | |
9 | +public class HomePageLeftTopDTO { | |
10 | + @ApiModelProperty("设备统计") | |
11 | + private HomeDeviceInfoDTO deviceInfo; | |
11 | 12 | |
12 | - @ApiModelProperty("顶部告警统计") | |
13 | - private BaseHomePageTop alarmInfo; | |
13 | + @ApiModelProperty("告警统计") | |
14 | + private BaseHomePageTop alarmInfo; | |
14 | 15 | |
15 | - @ApiModelProperty("顶部租户统计") | |
16 | - private BaseHomePageTop tenantInfo; | |
16 | + @ApiModelProperty("租户统计") | |
17 | + private BaseHomePageTop tenantInfo; | |
17 | 18 | |
18 | - @ApiModelProperty("顶部客户统计") | |
19 | - private BaseHomePageTop customerInfo; | |
19 | + @ApiModelProperty("客户统计") | |
20 | + private BaseHomePageTop customerInfo; | |
20 | 21 | |
21 | - @ApiModelProperty("顶部消息统计") | |
22 | - private HomePageTopMessage messageInfo; | |
22 | + @ApiModelProperty("消息统计") | |
23 | + private HomePageTopMessage messageInfo; | |
23 | 24 | } | ... | ... |
... | ... | @@ -8,7 +8,7 @@ import java.util.Set; |
8 | 8 | |
9 | 9 | /** for authentication */ |
10 | 10 | @Data |
11 | -public class UserDetailsDTO implements Serializable { | |
11 | +public class UserDetailsDTO extends BaseDTO implements Serializable { | |
12 | 12 | |
13 | 13 | private static final long serialVersionUID = -515966143236266646L; |
14 | 14 | private String id; | ... | ... |
1 | +package org.thingsboard.server.common.data.yunteng.dto.statistics; | |
2 | + | |
3 | +import lombok.Data; | |
4 | + | |
5 | +/** | |
6 | + * @Description : 数据聚合统计对象 | |
7 | + * 1.其它地方抛出异常,交由控制层统一处理 | |
8 | + * 2.服务层注意持久化的事务管理 | |
9 | + * @Dependency: 依赖包 | |
10 | + * @Author: junlianglee | |
11 | + * @Date Created in 2022/4/14$ | |
12 | + * @Copyright 2016-2018 - Powered By 李唐源研发中心 | |
13 | + */ | |
14 | +@Data | |
15 | +public class AggregationDTO { | |
16 | + private String key; | |
17 | + private Integer value; | |
18 | +} | ... | ... |
1 | +package org.thingsboard.server.common.data.yunteng.dto.statistics; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModel; | |
4 | +import io.swagger.annotations.ApiModelProperty; | |
5 | +import lombok.Data; | |
6 | + | |
7 | +/** | |
8 | + * @Description 告警基础统计信息 | |
9 | + * @Author cxy | |
10 | + * @Date 2021/11/24 17:32 | |
11 | + */ | |
12 | +@ApiModel("告警基础统计信息") | |
13 | +@Data | |
14 | +public class AlarmStatisticsDTO { | |
15 | + @ApiModelProperty("告警总数") | |
16 | + private Integer total; | |
17 | + | |
18 | + @ApiModelProperty("未处理告警数量") | |
19 | + private Integer activedAlarm; | |
20 | + | |
21 | + @ApiModelProperty("已处理告警数量") | |
22 | + private Integer clearedAck; | |
23 | + | |
24 | + @ApiModelProperty("误报告警数量") | |
25 | + private Integer clearedUnack; | |
26 | + | |
27 | + | |
28 | + public AlarmStatisticsDTO(Integer defaultValue) { | |
29 | + this.total = defaultValue; | |
30 | + this.activedAlarm = defaultValue; | |
31 | + this.clearedAck = defaultValue; | |
32 | + this.clearedUnack = defaultValue; | |
33 | + } | |
34 | + | |
35 | +} | ... | ... |
1 | +package org.thingsboard.server.common.data.yunteng.dto.statistics; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModel; | |
4 | +import io.swagger.annotations.ApiModelProperty; | |
5 | +import lombok.Data; | |
6 | + | |
7 | +/** | |
8 | + * @Description 租户的客户基础统计信息 | |
9 | + * @Author cxy | |
10 | + * @Date 2021/11/24 17:32 | |
11 | + */ | |
12 | +@ApiModel("客户基础统计信息") | |
13 | +@Data | |
14 | +public class CustomerStatisticsDTO { | |
15 | + @ApiModelProperty("客户总数") | |
16 | + private Integer total; | |
17 | + | |
18 | + @ApiModelProperty("活跃用户数") | |
19 | + private Integer loginUse; | |
20 | + | |
21 | + @ApiModelProperty("禁用或过期客户数量") | |
22 | + private Integer cancellation; | |
23 | + | |
24 | + @ApiModelProperty("正常用户") | |
25 | + private Integer normal; | |
26 | + | |
27 | + | |
28 | + public CustomerStatisticsDTO(Integer defaultValue) { | |
29 | + this.total = defaultValue; | |
30 | + this.loginUse = defaultValue; | |
31 | + this.normal = defaultValue; | |
32 | + this.cancellation = defaultValue; | |
33 | + } | |
34 | + | |
35 | +} | ... | ... |
1 | +package org.thingsboard.server.common.data.yunteng.dto.statistics; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModel; | |
4 | +import io.swagger.annotations.ApiModelProperty; | |
5 | +import lombok.Data; | |
6 | + | |
7 | +/** | |
8 | + * @Description 设备基础统计信息 | |
9 | + * @Author cxy | |
10 | + * @Date 2021/11/24 17:32 | |
11 | + */ | |
12 | +@ApiModel("设备基础统计信息") | |
13 | +@Data | |
14 | +public class DeviceStatisticsDTO { | |
15 | + @ApiModelProperty("设备总数") | |
16 | + private Integer total; | |
17 | + | |
18 | + @ApiModelProperty("在线设备数量") | |
19 | + private Integer onLine; | |
20 | + | |
21 | + @ApiModelProperty("离线设备数量") | |
22 | + private Integer offLine; | |
23 | + | |
24 | + @ApiModelProperty("未激活设备数量") | |
25 | + private Integer inActive; | |
26 | + | |
27 | + | |
28 | + public DeviceStatisticsDTO(Integer defaultValue) { | |
29 | + this.total = defaultValue; | |
30 | + this.onLine = defaultValue; | |
31 | + this.offLine = defaultValue; | |
32 | + this.inActive = defaultValue; | |
33 | + } | |
34 | + | |
35 | +} | ... | ... |
1 | +package org.thingsboard.server.common.data.yunteng.dto.statistics; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModel; | |
4 | +import io.swagger.annotations.ApiModelProperty; | |
5 | +import lombok.Data; | |
6 | + | |
7 | +/** | |
8 | + * @Description 系统流量基础统计信息 | |
9 | + * @Author cxy | |
10 | + * @Date 2021/11/24 17:32 | |
11 | + */ | |
12 | +@ApiModel("流量基础统计信息") | |
13 | +@Data | |
14 | +public class FlowStatisticsDTO { | |
15 | + | |
16 | + @ApiModelProperty("收发消息数量") | |
17 | + private Integer message; | |
18 | + | |
19 | + @ApiModelProperty("数据点数量") | |
20 | + private Integer dataPoints; | |
21 | + | |
22 | + | |
23 | + public FlowStatisticsDTO(Integer defaultValue) { | |
24 | + this.message = defaultValue; | |
25 | + this.dataPoints = defaultValue; | |
26 | + } | |
27 | + | |
28 | +} | ... | ... |
1 | +package org.thingsboard.server.common.data.yunteng.dto.statistics; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModel; | |
4 | +import io.swagger.annotations.ApiModelProperty; | |
5 | +import lombok.Data; | |
6 | +import org.thingsboard.server.common.data.yunteng.dto.BaseHomePageTop; | |
7 | +import org.thingsboard.server.common.data.yunteng.dto.HomeDeviceInfoDTO; | |
8 | +import org.thingsboard.server.common.data.yunteng.dto.HomePageTopMessage; | |
9 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceState; | |
10 | + | |
11 | +@Data | |
12 | +@ApiModel("首页统计信息") | |
13 | +public class HomePageAppDTO { | |
14 | + @ApiModelProperty("租户统计") | |
15 | + private TenantStatisticsDTO totalTenant; | |
16 | + private TenantStatisticsDTO todayTenant; | |
17 | + | |
18 | + @ApiModelProperty("客户统计") | |
19 | + private CustomerStatisticsDTO totalCustomer; | |
20 | + private CustomerStatisticsDTO todayCustomer; | |
21 | + | |
22 | + @ApiModelProperty("设备统计") | |
23 | + private DeviceStatisticsDTO totalDevice; | |
24 | + private DeviceStatisticsDTO todayDevice; | |
25 | + | |
26 | + @ApiModelProperty("告警统计") | |
27 | + private AlarmStatisticsDTO totalAlarm; | |
28 | + private AlarmStatisticsDTO todayAlarm; | |
29 | + | |
30 | + | |
31 | + @ApiModelProperty("消息统计") | |
32 | + private FlowStatisticsDTO totalMsg; | |
33 | + private FlowStatisticsDTO todayMsg; | |
34 | +} | ... | ... |
1 | +package org.thingsboard.server.common.data.yunteng.dto.statistics; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModel; | |
4 | +import io.swagger.annotations.ApiModelProperty; | |
5 | +import lombok.Data; | |
6 | + | |
7 | +/** | |
8 | + * @Description 租户基础统计信息 | |
9 | + * @Author cxy | |
10 | + * @Date 2021/11/24 17:32 | |
11 | + */ | |
12 | +@ApiModel("租户基础统计信息") | |
13 | +@Data | |
14 | +public class TenantStatisticsDTO { | |
15 | + @ApiModelProperty("租户总数") | |
16 | + private Integer total; | |
17 | + | |
18 | + @ApiModelProperty("过期租户数量") | |
19 | + private Integer expired; | |
20 | + | |
21 | + @ApiModelProperty("正常租户数量") | |
22 | + private Integer normal; | |
23 | + | |
24 | + | |
25 | + public TenantStatisticsDTO(Integer defaultValue) { | |
26 | + this.total = defaultValue; | |
27 | + this.expired = defaultValue; | |
28 | + this.normal = defaultValue; | |
29 | + } | |
30 | + | |
31 | +} | ... | ... |
... | ... | @@ -8,6 +8,7 @@ import org.springframework.scheduling.annotation.Async; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | 9 | import org.springframework.web.context.request.async.DeferredResult; |
10 | 10 | import org.thingsboard.server.common.data.ApiUsageState; |
11 | +import org.thingsboard.server.common.data.alarm.AlarmStatus; | |
11 | 12 | import org.thingsboard.server.common.data.id.CustomerId; |
12 | 13 | import org.thingsboard.server.common.data.id.EntityId; |
13 | 14 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -19,6 +20,7 @@ import org.thingsboard.server.common.data.page.PageData; |
19 | 20 | import org.thingsboard.server.common.data.query.*; |
20 | 21 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
21 | 22 | import org.thingsboard.server.common.data.yunteng.dto.*; |
23 | +import org.thingsboard.server.common.data.yunteng.dto.statistics.*; | |
22 | 24 | import org.thingsboard.server.common.data.yunteng.enums.RoleEnum; |
23 | 25 | import org.thingsboard.server.common.data.yunteng.enums.TrendType; |
24 | 26 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
... | ... | @@ -27,6 +29,7 @@ import org.thingsboard.server.dao.timeseries.TimeseriesService; |
27 | 29 | import org.thingsboard.server.dao.usagerecord.ApiUsageStateService; |
28 | 30 | import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper; |
29 | 31 | import org.thingsboard.server.dao.yunteng.mapper.UserMapper; |
32 | +import org.thingsboard.server.dao.yunteng.mapper.YtAlarmMapper; | |
30 | 33 | import org.thingsboard.server.dao.yunteng.service.HomePageService; |
31 | 34 | import org.thingsboard.server.dao.yunteng.service.YtTenantService; |
32 | 35 | import org.thingsboard.server.dao.yunteng.service.YtUserService; |
... | ... | @@ -38,6 +41,7 @@ import java.time.ZoneOffset; |
38 | 41 | import java.util.*; |
39 | 42 | import java.util.concurrent.CompletableFuture; |
40 | 43 | import java.util.concurrent.ExecutionException; |
44 | +import java.util.concurrent.atomic.AtomicInteger; | |
41 | 45 | import java.util.stream.Collectors; |
42 | 46 | |
43 | 47 | @Service |
... | ... | @@ -58,6 +62,8 @@ public class HomePageServiceImpl implements HomePageService { |
58 | 62 | |
59 | 63 | private final YtUserService ytUserService; |
60 | 64 | |
65 | + private final YtAlarmMapper ytJpaAarmDao; | |
66 | + | |
61 | 67 | @Override |
62 | 68 | public HomePageLeftTopDTO getHomePageLeftTopInfo(boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, String tenantId, String currentUserId) throws ExecutionException, InterruptedException { |
63 | 69 | // 如果当前用户是超级管理员或平台管理员,查询所有的设备数量、租户数量、客户数量 |
... | ... | @@ -109,6 +115,234 @@ public class HomePageServiceImpl implements HomePageService { |
109 | 115 | } |
110 | 116 | |
111 | 117 | @Override |
118 | + public HomePageAppDTO app(boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId) { | |
119 | + /** | |
120 | + * 如果当前用户是超级管理员或平台管理员,查询所有的租户数量、客户、设备 | |
121 | + * 如果当前用户是租户管理员,查询租户下的所有 客户、设备、告警、消息量 | |
122 | + * 如果当前用户是客户,查询客户可以查看的 设备、告警、消息量 | |
123 | + */ | |
124 | + LocalDateTime nowTime = LocalDateTime.now(); | |
125 | + LocalDateTime startTime = LocalDateTime.of(nowTime.toLocalDate(), LocalTime.MIN); | |
126 | + LocalDateTime endTime = LocalDateTime.of(nowTime.toLocalDate(), LocalTime.MAX); | |
127 | + EntityId entityId = customerId; | |
128 | + if(isPtSysAdmin || isPtAdmin){ | |
129 | + entityId = null; | |
130 | + }else if(isTenantAdmin){ | |
131 | + entityId = tenantId; | |
132 | + } | |
133 | + | |
134 | + Map<String, Object> totalFilter = buildCountFilter(entityId,null,null); | |
135 | + Map<String, Object> todayFilter = buildCountFilter(entityId,startTime,endTime); | |
136 | + | |
137 | + HomePageAppDTO app = new HomePageAppDTO(); | |
138 | + if (isPtSysAdmin || isPtAdmin) { | |
139 | + List<TenantDTO> tenants = getTenantInfo(); | |
140 | + AtomicInteger totalExpired = new AtomicInteger(); | |
141 | + AtomicInteger totalNormal = new AtomicInteger(); | |
142 | + int todayAdd = (int) tenants.stream().filter(tenant -> { | |
143 | + if(tenant.getTenantExpireTime()==null || tenant.getTenantExpireTime().isAfter(nowTime)){ | |
144 | + totalNormal.getAndIncrement(); | |
145 | + }else{ | |
146 | + totalExpired.getAndIncrement(); | |
147 | + } | |
148 | + return tenant.getCreateTime().isAfter(startTime) && tenant.getCreateTime().isBefore(endTime); | |
149 | + }).count(); | |
150 | + | |
151 | + TenantStatisticsDTO today = new TenantStatisticsDTO(0); | |
152 | + today.setTotal(todayAdd); | |
153 | + app.setTodayTenant(today); | |
154 | + | |
155 | + TenantStatisticsDTO total = new TenantStatisticsDTO(0); | |
156 | + total.setTotal(tenants.size()); | |
157 | + total.setExpired(totalExpired.get()); | |
158 | + total.setNormal(totalNormal.get()); | |
159 | + app.setTotalTenant(total); | |
160 | + } | |
161 | + | |
162 | + if (isPtSysAdmin || isPtAdmin || isTenantAdmin) { | |
163 | + List<UserDetailsDTO> customers = getCustomerInfo(totalFilter); | |
164 | + AtomicInteger totalExpired = new AtomicInteger(); | |
165 | + AtomicInteger totalNormal = new AtomicInteger(); | |
166 | + AtomicInteger totalActivity = new AtomicInteger(); | |
167 | + int todayAdd = (int) customers.stream().filter(customer -> { | |
168 | + if(customer.isEnabled() | |
169 | + && (customer.getAccountExpireTime() == null|| customer.getAccountExpireTime().isAfter(nowTime)) | |
170 | + && customer.getTenant().isEnabled() | |
171 | + && (customer.getTenant().getTenantExpireTime() == null|| customer.getTenant().getTenantExpireTime().isAfter(nowTime)) | |
172 | + ){ | |
173 | + totalNormal.getAndIncrement(); | |
174 | + }else{ | |
175 | + totalExpired.getAndIncrement(); | |
176 | + } | |
177 | + if(endTime.isAfter(customer.getUpdateTime()) && startTime.isBefore(customer.getUpdateTime())){ | |
178 | + totalActivity.incrementAndGet(); | |
179 | + } | |
180 | + | |
181 | + return customer.getCreateTime().isAfter(startTime) && customer.getCreateTime().isBefore(endTime); | |
182 | + }).count(); | |
183 | + | |
184 | + CustomerStatisticsDTO today = new CustomerStatisticsDTO(0); | |
185 | + today.setTotal(todayAdd); | |
186 | + CustomerStatisticsDTO total = new CustomerStatisticsDTO(0); | |
187 | + total.setTotal(customers.size()); | |
188 | + total.setLoginUse(totalActivity.get()); | |
189 | + total.setNormal(totalNormal.get()); | |
190 | + total.setCancellation(totalExpired.get()); | |
191 | + app.setTotalCustomer(total); | |
192 | + app.setTodayCustomer(today); | |
193 | + } | |
194 | + | |
195 | + if (!isPtSysAdmin && !isPtAdmin ) { | |
196 | + app.setTotalAlarm(getAlarmInfo(totalFilter)); | |
197 | + app.setTodayAlarm(getAlarmInfo(todayFilter)); | |
198 | + } | |
199 | + | |
200 | + if (!isPtSysAdmin && !isPtAdmin ) { | |
201 | + app.setTotalMsg(getFlowStatistics(totalFilter)); | |
202 | + app.setTodayMsg(getFlowStatistics(todayFilter)); | |
203 | + } | |
204 | + | |
205 | + List<DeviceDTO> devices = getDeviceInfo(todayFilter); | |
206 | + AtomicInteger totalOnline = new AtomicInteger(); | |
207 | + AtomicInteger totalOffline = new AtomicInteger(); | |
208 | + AtomicInteger totalinactive = new AtomicInteger(); | |
209 | + int todayAdd = (int) devices.stream().filter(device -> { | |
210 | + switch (device.getDeviceState()){ | |
211 | + case ONLINE: | |
212 | + totalOnline.incrementAndGet(); | |
213 | + break; | |
214 | + case OFFLINE: | |
215 | + totalOffline.incrementAndGet(); | |
216 | + break; | |
217 | + case INACTIVE: | |
218 | + totalinactive.incrementAndGet(); | |
219 | + break; | |
220 | + } | |
221 | + | |
222 | + return device.getCreateTime().isAfter(startTime) && device.getCreateTime().isBefore(endTime); | |
223 | + }).count(); | |
224 | + DeviceStatisticsDTO today = new DeviceStatisticsDTO(0); | |
225 | + today.setTotal(todayAdd); | |
226 | + DeviceStatisticsDTO total = new DeviceStatisticsDTO(0); | |
227 | + total.setTotal(devices.size()); | |
228 | + total.setInActive(totalinactive.get()); | |
229 | + total.setOffLine(totalOffline.get()); | |
230 | + total.setOnLine(totalOnline.get()); | |
231 | + app.setTotalDevice(total); | |
232 | + app.setTodayDevice(today); | |
233 | + | |
234 | + | |
235 | + return app; | |
236 | + } | |
237 | + /** | |
238 | + * 获取当前用户权限下的租户信息 | |
239 | + * | |
240 | + * @return | |
241 | + */ | |
242 | + private List<TenantDTO> getTenantInfo() { | |
243 | + List<TenantDTO> tenants = tenantService.getAllTenant(); | |
244 | + return tenants; | |
245 | + } | |
246 | + | |
247 | + | |
248 | + | |
249 | + /** | |
250 | + * 统计数据的过滤参数 | |
251 | + * @param entityId 实体ID,例如:租户ID、客户ID | |
252 | + * @param startTime 数据开始时间 | |
253 | + * @param endTime 数据结束时间 | |
254 | + * @return | |
255 | + */ | |
256 | + private Map<String, Object> buildCountFilter(EntityId entityId,LocalDateTime startTime,LocalDateTime endTime){ | |
257 | + Map<String, Object> filter = new HashMap<>(); | |
258 | + if(entityId != null){ | |
259 | + String idStr = entityId.getId().toString(); | |
260 | + switch (entityId.getEntityType()){ | |
261 | + case TENANT: | |
262 | + filter.put("tenantId", idStr); | |
263 | + break; | |
264 | + case CUSTOMER: | |
265 | + filter.put("customerId", idStr); | |
266 | + break; | |
267 | + default: | |
268 | + } | |
269 | + } | |
270 | + if(startTime !=null){ | |
271 | + filter.put("startTime", startTime.toInstant(ZoneOffset.of("+8")).toEpochMilli()); | |
272 | + } | |
273 | + if(endTime !=null){ | |
274 | + filter.put("startTime", endTime.toInstant(ZoneOffset.of("+8")).toEpochMilli()); | |
275 | + } | |
276 | + | |
277 | + return filter; | |
278 | + } | |
279 | + /** | |
280 | + * 获取当前用户权限下的客户信息 | |
281 | + * | |
282 | + * @return | |
283 | + */ | |
284 | + private List<UserDetailsDTO> getCustomerInfo(Map<String, Object> filter) { | |
285 | + List<UserDetailsDTO> userList = userMapper.findCustomers(filter); | |
286 | + return userList; | |
287 | + } | |
288 | + /** | |
289 | + * 查询实体ID的设备 | |
290 | + * @param filter 数据过滤参数 | |
291 | + * @return | |
292 | + */ | |
293 | + private List<DeviceDTO> getDeviceInfo(Map<String, Object> filter) { | |
294 | + List<DeviceDTO> deviceDTOS = deviceMapper.findDevices(filter);; | |
295 | + return deviceDTOS; | |
296 | + } | |
297 | + | |
298 | + /** | |
299 | + * 统计实体的告警信息 | |
300 | + * @param filter 数据过滤参数 | |
301 | + * @return | |
302 | + */ | |
303 | + private AlarmStatisticsDTO getAlarmInfo(Map<String, Object> filter) { | |
304 | + List<AggregationDTO> alarms = ytJpaAarmDao.countAlarms(filter); | |
305 | + AlarmStatisticsDTO statistics = new AlarmStatisticsDTO(0); | |
306 | + statistics.setTotal(alarms.size()); | |
307 | + AtomicInteger totalActived = new AtomicInteger(); | |
308 | + for(AggregationDTO item:alarms){ | |
309 | + AlarmStatus status = AlarmStatus.valueOf(item.getKey()); | |
310 | + switch (status){ | |
311 | + case CLEARED_UNACK: | |
312 | + statistics.setClearedUnack(item.getValue()); | |
313 | + break; | |
314 | + case CLEARED_ACK: | |
315 | + statistics.setClearedAck(item.getValue()); | |
316 | + break; | |
317 | + case ACTIVE_ACK: | |
318 | + totalActived.addAndGet(item.getValue()); | |
319 | + break; | |
320 | + case ACTIVE_UNACK: | |
321 | + totalActived.addAndGet(item.getValue()); | |
322 | + break; | |
323 | + | |
324 | + } | |
325 | + } | |
326 | + statistics.setActivedAlarm(totalActived.get()); | |
327 | + return statistics; | |
328 | + } | |
329 | + | |
330 | + /** | |
331 | + * 获取实体的流量统计信息 | |
332 | + * @param filter 数据过滤参数 | |
333 | + * @return | |
334 | + */ | |
335 | + private FlowStatisticsDTO getFlowStatistics(Map<String, Object> filter) { | |
336 | + FlowStatisticsDTO flow = new FlowStatisticsDTO(0); | |
337 | + flow.setMessage(deviceMapper.countMsgs(filter)); | |
338 | + flow.setDataPoints(deviceMapper.countDataPoints(filter)); | |
339 | + return flow; | |
340 | + } | |
341 | + | |
342 | + | |
343 | + | |
344 | + | |
345 | + @Override | |
112 | 346 | public YtPageData<TenantDTO> getHomePageRightInfo(Map<String, Object> queryMap) { |
113 | 347 | return tenantService.getCurrentMonthExpireTenantPage(queryMap); |
114 | 348 | } |
... | ... | @@ -238,40 +472,7 @@ public class HomePageServiceImpl implements HomePageService { |
238 | 472 | }); |
239 | 473 | } |
240 | 474 | |
241 | - /** | |
242 | - * 获取当前用户权限下的租户信息 | |
243 | - * | |
244 | - * @return | |
245 | - */ | |
246 | - private List<TenantDTO> getTenantInfo() { | |
247 | - List<TenantDTO> tenants = tenantService.getAllTenant(); | |
248 | - return tenants; | |
249 | - } | |
250 | 475 | |
251 | - /** | |
252 | - * 获取当前用户权限下的客户信息 | |
253 | - * | |
254 | - * @return | |
255 | - */ | |
256 | - private List<UserDTO> getCustomerInfo() { | |
257 | - List<UserDTO> userList = userMapper.getUserCountByRoleType(RoleEnum.CUSTOMER_USER); | |
258 | - return userList; | |
259 | - } | |
260 | - | |
261 | - private List<TenantDTO> getApiUsageInfo() { | |
262 | - List<TenantDTO> tenants = tenantService.getAllTenant(); | |
263 | - return tenants; | |
264 | - } | |
265 | - | |
266 | - private List<TenantDTO> getDeviceInfo() { | |
267 | - List<TenantDTO> tenants = tenantService.getAllTenant(); | |
268 | - return tenants; | |
269 | - } | |
270 | - | |
271 | - private List<TenantDTO> getAlarmInfo() { | |
272 | - List<TenantDTO> tenants = tenantService.getAllTenant(); | |
273 | - return tenants; | |
274 | - } | |
275 | 476 | |
276 | 477 | /** |
277 | 478 | * 设置租户返回信息 |
... | ... | @@ -522,4 +723,5 @@ public class HomePageServiceImpl implements HomePageService { |
522 | 723 | } |
523 | 724 | return CompletableFuture.supplyAsync(() -> new TsValue(ts, String.valueOf(value))); |
524 | 725 | } |
726 | + | |
525 | 727 | } | ... | ... |
... | ... | @@ -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.statistics.AggregationDTO; | |
10 | 11 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; |
11 | 12 | |
12 | 13 | import java.util.List; |
... | ... | @@ -78,4 +79,9 @@ public interface DeviceMapper extends BaseMapper<YtDevice> { |
78 | 79 | @Param("customerId") String customerId, |
79 | 80 | @Param("startTime") Long startTime, |
80 | 81 | @Param("endTime") Long endTime); |
82 | + | |
83 | + | |
84 | + Integer countMsgs(@Param("queryMap") Map<String, Object> queryMap); | |
85 | + | |
86 | + Integer countDataPoints(@Param("queryMap") Map<String, Object> queryMap); | |
81 | 87 | } | ... | ... |
... | ... | @@ -44,4 +44,6 @@ public interface UserMapper extends BaseMapper<User> { |
44 | 44 | List<UserDTO> findUsersAsyncByTs(@Param("startTs") String startTs, @Param("endTs") String endTs); |
45 | 45 | |
46 | 46 | String findCustomerIdByUserId(@Param("id") String id); |
47 | + | |
48 | + List<UserDetailsDTO> findCustomers(@Param("queryMap") Map<String, Object> queryMap); | |
47 | 49 | } | ... | ... |
... | ... | @@ -8,17 +8,16 @@ import org.thingsboard.server.common.data.EntityType; |
8 | 8 | import org.thingsboard.server.common.data.alarm.AlarmInfo; |
9 | 9 | import org.thingsboard.server.common.data.alarm.AlarmStatus; |
10 | 10 | import org.thingsboard.server.common.data.id.TenantId; |
11 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
11 | 12 | import org.thingsboard.server.common.data.yunteng.dto.MenuDTO; |
12 | 13 | import org.thingsboard.server.common.data.yunteng.dto.TenantDTO; |
14 | +import org.thingsboard.server.common.data.yunteng.dto.statistics.AggregationDTO; | |
13 | 15 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
14 | 16 | import org.thingsboard.server.dao.yunteng.entities.Menu; |
15 | 17 | import org.thingsboard.server.dao.yunteng.entities.SysDict; |
16 | 18 | import org.thingsboard.server.dao.yunteng.entities.YtAlarmEntity; |
17 | 19 | |
18 | -import java.util.Collection; | |
19 | -import java.util.List; | |
20 | -import java.util.Set; | |
21 | -import java.util.UUID; | |
20 | +import java.util.*; | |
22 | 21 | |
23 | 22 | @Mapper |
24 | 23 | public interface YtAlarmMapper extends BaseMapper<YtAlarmEntity> { |
... | ... | @@ -37,4 +36,5 @@ public interface YtAlarmMapper extends BaseMapper<YtAlarmEntity> { |
37 | 36 | ); |
38 | 37 | |
39 | 38 | List<SysDict> alarmType(@Param("tenantId") UUID tenantId); |
39 | + List<AggregationDTO> countAlarms(@Param("queryMap") Map<String, Object> queryMap); | |
40 | 40 | } | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | |
3 | 3 | import org.springframework.web.context.request.async.DeferredResult; |
4 | +import org.thingsboard.server.common.data.id.EntityId; | |
4 | 5 | import org.thingsboard.server.common.data.id.TenantId; |
5 | 6 | import org.thingsboard.server.common.data.query.TsValue; |
6 | 7 | import org.thingsboard.server.common.data.yunteng.dto.HomePageLeftTopDTO; |
7 | 8 | import org.thingsboard.server.common.data.yunteng.dto.TenantDTO; |
8 | 9 | import org.thingsboard.server.common.data.yunteng.dto.TenantTransportMessageDTO; |
10 | +import org.thingsboard.server.common.data.yunteng.dto.statistics.HomePageAppDTO; | |
9 | 11 | import org.thingsboard.server.common.data.yunteng.enums.TrendType; |
10 | 12 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
11 | 13 | |
... | ... | @@ -15,58 +17,71 @@ import java.util.concurrent.CompletableFuture; |
15 | 17 | import java.util.concurrent.ExecutionException; |
16 | 18 | |
17 | 19 | public interface HomePageService { |
18 | - /** | |
19 | - * 通过租户ID获取首页左边顶部信息 | |
20 | - * | |
21 | - * @param isPtSysAdmin 是否超级管理员 | |
22 | - * @param isPtAdmin 是否平台管理员 | |
23 | - * @param isTenantAdmin 是否租户管理员 | |
24 | - * @param tenantId 租户ID | |
25 | - * @param currentUserId 当前用户ID | |
26 | - * @return 首页左边顶部信息 | |
27 | - */ | |
28 | - HomePageLeftTopDTO getHomePageLeftTopInfo( | |
29 | - boolean isPtSysAdmin, | |
30 | - boolean isPtAdmin, | |
31 | - boolean isTenantAdmin, | |
32 | - String tenantId, | |
33 | - String currentUserId) | |
34 | - throws ExecutionException, InterruptedException; | |
20 | + /** | |
21 | + * 通过租户ID获取首页左边顶部信息 | |
22 | + * | |
23 | + * @param isPtSysAdmin 是否超级管理员 | |
24 | + * @param isPtAdmin 是否平台管理员 | |
25 | + * @param isTenantAdmin 是否租户管理员 | |
26 | + * @param tenantId 租户ID | |
27 | + * @param currentUserId 当前用户ID | |
28 | + * @return 首页左边顶部信息 | |
29 | + */ | |
30 | + HomePageLeftTopDTO getHomePageLeftTopInfo( | |
31 | + boolean isPtSysAdmin, | |
32 | + boolean isPtAdmin, | |
33 | + boolean isTenantAdmin, | |
34 | + String tenantId, | |
35 | + String currentUserId) | |
36 | + throws ExecutionException, InterruptedException; | |
35 | 37 | |
36 | - /** | |
37 | - * 获取首页右侧信息 | |
38 | - * | |
39 | - * @param queryMap 查询条件 | |
40 | - * @return 右侧信息 | |
41 | - */ | |
42 | - YtPageData<TenantDTO> getHomePageRightInfo(Map<String, Object> queryMap); | |
38 | + /** | |
39 | + * 获取首页右侧信息 | |
40 | + * | |
41 | + * @param queryMap 查询条件 | |
42 | + * @return 右侧信息 | |
43 | + */ | |
44 | + YtPageData<TenantDTO> getHomePageRightInfo(Map<String, Object> queryMap); | |
43 | 45 | |
44 | - /** | |
45 | - * 获取首页左侧底部信息 | |
46 | - * | |
47 | - * @param startTs 开始时间 | |
48 | - * @param endTs 结束时间 | |
49 | - * @param interval 时间间隔 | |
50 | - * @param trend 趋势类型 | |
51 | - * @return 左侧底部信息 | |
52 | - */ | |
53 | - DeferredResult<List<TsValue>> getHomePageLeftBottomInfo( | |
54 | - String customerId, long startTs, long endTs, long interval, TrendType trend,boolean isCustomer); | |
46 | + /** | |
47 | + * 获取首页左侧底部信息 | |
48 | + * | |
49 | + * @param startTs 开始时间 | |
50 | + * @param endTs 结束时间 | |
51 | + * @param interval 时间间隔 | |
52 | + * @param trend 趋势类型 | |
53 | + * @return 左侧底部信息 | |
54 | + */ | |
55 | + DeferredResult<List<TsValue>> getHomePageLeftBottomInfo( | |
56 | + String customerId, long startTs, long endTs, long interval, TrendType trend, boolean isCustomer); | |
55 | 57 | |
56 | - /** | |
57 | - * 获取首页TOP10 | |
58 | - * | |
59 | - * @return top10 | |
60 | - */ | |
61 | - DeferredResult<List<TenantTransportMessageDTO>> getTop10(); | |
58 | + /** | |
59 | + * 获取首页TOP10 | |
60 | + * | |
61 | + * @return top10 | |
62 | + */ | |
63 | + DeferredResult<List<TenantTransportMessageDTO>> getTop10(); | |
62 | 64 | |
63 | - /** | |
64 | - * 获取租户的传输信息 | |
65 | - * | |
66 | - * @param tenantId 租户ID | |
67 | - * @param tenantName 租户姓名 | |
68 | - * @return 传输信息 | |
69 | - */ | |
70 | - CompletableFuture<TenantTransportMessageDTO> getTransportMessageByTenantId( | |
71 | - TenantId tenantId, String tenantName); | |
65 | + /** | |
66 | + * 获取租户的传输信息 | |
67 | + * | |
68 | + * @param tenantId 租户ID | |
69 | + * @param tenantName 租户姓名 | |
70 | + * @return 传输信息 | |
71 | + */ | |
72 | + CompletableFuture<TenantTransportMessageDTO> getTransportMessageByTenantId( | |
73 | + TenantId tenantId, String tenantName); | |
74 | + | |
75 | + /** | |
76 | + * app首页统计信息 | |
77 | + * @param isPtSysAdmin | |
78 | + * @param isPtAdmin | |
79 | + * @param isTenantAdmin | |
80 | + * @param tenantId | |
81 | + * @param customerId | |
82 | + * @return | |
83 | + */ | |
84 | + HomePageAppDTO app(boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId); | |
72 | 85 | } |
86 | + | |
87 | + | ... | ... |
... | ... | @@ -280,4 +280,42 @@ |
280 | 280 | < #{endTime} |
281 | 281 | AND originator_type = 5; |
282 | 282 | </select> |
283 | + | |
284 | + <select id="countMsgs" resultType="int"> | |
285 | + SELECT COUNT(1) FROM ts_kv v LEFT JOIN device d ON d.id = v.entity_id | |
286 | + <where> | |
287 | + 1=1 | |
288 | + <if test="queryMap.tenantId !=null"> | |
289 | + AND d.tenant_id= #{queryMap.tenantId}::uuid | |
290 | + </if> | |
291 | + <if test="queryMap.customerId !=null"> | |
292 | + AND d.customer_id= #{queryMap.customerId}::uuid | |
293 | + </if> | |
294 | + <if test="queryMap.startTime !=null"> | |
295 | + AND v.ts >= #{queryMap.startTime} | |
296 | + </if> | |
297 | + <if test="queryMap.endTime !=null"> | |
298 | + AND v.ts < #{queryMap.endTime} | |
299 | + </if> | |
300 | + </where> | |
301 | + </select> | |
302 | + | |
303 | + <select id="countDataPoints" resultType="int"> | |
304 | + SELECT COUNT(DISTINCT v.key) FROM ts_kv v LEFT JOIN device d ON d.id = v.entity_id | |
305 | + <where> | |
306 | + 1=1 | |
307 | + <if test="queryMap.tenantId !=null"> | |
308 | + AND tenant_id= #{queryMap.tenantId}::uuid | |
309 | + </if> | |
310 | + <if test="queryMap.customerId !=null"> | |
311 | + AND customer_id= #{queryMap.customerId}::uuid | |
312 | + </if> | |
313 | + <if test="queryMap.startTime !=null"> | |
314 | + AND ts >= #{queryMap.startTime} | |
315 | + </if> | |
316 | + <if test="queryMap.endTime !=null"> | |
317 | + AND ts < #{queryMap.endTime} | |
318 | + </if> | |
319 | + </where> | |
320 | + </select> | |
283 | 321 | </mapper> | ... | ... |
... | ... | @@ -8,6 +8,8 @@ |
8 | 8 | <result property="password" column="password"/> |
9 | 9 | <result property="enabled" column="enabled"/> |
10 | 10 | <result property="accountExpireTime" column="account_expire_time"/> |
11 | + <result property="updateTime" column="update_time"/> | |
12 | + <result property="createTime" column="create_time"/> | |
11 | 13 | <association property="tenant" javaType="org.thingsboard.server.common.data.yunteng.dto.TenantDTO"> |
12 | 14 | <result column="tenant_name" property="name"/> |
13 | 15 | <result column="tenant_id" property="tenantId"/> |
... | ... | @@ -207,4 +209,27 @@ |
207 | 209 | <select id="findCustomerIdByUserId" resultType="java.lang.String"> |
208 | 210 | SELECT tu.customer_id FROM sys_user su LEFT JOIN tb_user tu ON su.tb_user = tu.id::TEXT WHERE su.id = #{id} |
209 | 211 | </select> |
212 | + | |
213 | + | |
214 | + <select id="findCustomers" resultMap="userDetailsMap"> | |
215 | + SELECT u.enabled,u.account_expire_time,u.create_time | |
216 | + ,t.enabled as tenant_enabled,t.tenant_expire_time as tenant_expire_time | |
217 | + ,al.update_time FROM sys_user u | |
218 | + LEFT JOIN sys_tenant t ON u.tenant_id = t.tenant_id | |
219 | + LEFT JOIN sys_user_role r ON u.id = r.user_id | |
220 | + LEFT JOIN sys_role ro ON ro.id = r.role_id | |
221 | + LEFT JOIN (SELECT MAX(to_timestamp(created_time/1000)::TIMESTAMP)update_time, entity_id FROM audit_log GROUP BY entity_id)al ON al.entity_id = u.tb_user::uuid | |
222 | + <where> | |
223 | + ro.role_type = 'CUSTOMER_USER' | |
224 | + <if test="queryMap.tenantId !=null"> | |
225 | + AND u.tenant_id= #{queryMap.tenantId} | |
226 | + </if> | |
227 | + <if test="queryMap.startTime !=null"> | |
228 | + AND u.create_time >= #{queryMap.startTime} | |
229 | + </if> | |
230 | + <if test="queryMap.endTime !=null"> | |
231 | + AND u.create_time < #{queryMap.endTime} | |
232 | + </if> | |
233 | + </where> | |
234 | + </select> | |
210 | 235 | </mapper> | ... | ... |
... | ... | @@ -27,6 +27,11 @@ |
27 | 27 | <result property="dictCode" column="dict_code"/> |
28 | 28 | </resultMap> |
29 | 29 | |
30 | + <resultMap type="org.thingsboard.server.common.data.yunteng.dto.statistics.AggregationDTO" id="aggregationMap"> | |
31 | + <result property="key" column="status"/> | |
32 | + <result property="value" column="value"/> | |
33 | + </resultMap> | |
34 | + | |
30 | 35 | |
31 | 36 | <select id="alarmPage" resultMap="alarmInfo"> |
32 | 37 | SELECT d.name AS device_name,d.id device_id,m.* |
... | ... | @@ -73,4 +78,23 @@ |
73 | 78 | </where> |
74 | 79 | </select> |
75 | 80 | |
81 | + <select id="countAlarms" resultMap="aggregationMap"> | |
82 | + SELECT status ,COUNT(id) AS value FROM alarm | |
83 | + <where> | |
84 | + 1=1 | |
85 | + <if test="queryMap.tenantId !=null"> | |
86 | + AND tenant_id= #{queryMap.tenantId}::uuid | |
87 | + </if> | |
88 | + <if test="queryMap.customerId !=null"> | |
89 | + AND customer_id= #{queryMap.customerId}::uuid | |
90 | + </if> | |
91 | + <if test="queryMap.startTime !=null"> | |
92 | + AND created_time >= #{queryMap.startTime} | |
93 | + </if> | |
94 | + <if test="queryMap.endTime !=null"> | |
95 | + AND created_time < #{queryMap.endTime} | |
96 | + </if> | |
97 | + </where> | |
98 | + GROUP BY status; | |
99 | + </select> | |
76 | 100 | </mapper> | ... | ... |