Commit f353d9c1c40b2f4f098d869c8ba5261d3195298b

Authored by 云中非
1 parent 7a8e5274

fix: 获取统计信息

1、登录时只取告警数据
2、首页获取全部数据
@@ -2,14 +2,12 @@ package org.thingsboard.server.controller.yunteng; @@ -2,14 +2,12 @@ package org.thingsboard.server.controller.yunteng;
2 2
3 import io.swagger.annotations.Api; 3 import io.swagger.annotations.Api;
4 import io.swagger.annotations.ApiOperation; 4 import io.swagger.annotations.ApiOperation;
  5 +import io.swagger.annotations.ApiParam;
5 import lombok.RequiredArgsConstructor; 6 import lombok.RequiredArgsConstructor;
6 import org.springframework.http.HttpStatus; 7 import org.springframework.http.HttpStatus;
7 import org.springframework.http.ResponseEntity; 8 import org.springframework.http.ResponseEntity;
8 import org.springframework.security.access.prepost.PreAuthorize; 9 import org.springframework.security.access.prepost.PreAuthorize;
9 -import org.springframework.web.bind.annotation.GetMapping;  
10 -import org.springframework.web.bind.annotation.RequestMapping;  
11 -import org.springframework.web.bind.annotation.RequestParam;  
12 -import org.springframework.web.bind.annotation.RestController; 10 +import org.springframework.web.bind.annotation.*;
13 import org.springframework.web.context.request.async.DeferredResult; 11 import org.springframework.web.context.request.async.DeferredResult;
14 import org.thingsboard.server.common.data.exception.ThingsboardException; 12 import org.thingsboard.server.common.data.exception.ThingsboardException;
15 import org.thingsboard.server.common.data.query.TsValue; 13 import org.thingsboard.server.common.data.query.TsValue;
@@ -18,6 +16,7 @@ import org.thingsboard.server.common.data.yunteng.dto.HomePageLeftTopDTO; @@ -18,6 +16,7 @@ import org.thingsboard.server.common.data.yunteng.dto.HomePageLeftTopDTO;
18 import org.thingsboard.server.common.data.yunteng.dto.TenantDTO; 16 import org.thingsboard.server.common.data.yunteng.dto.TenantDTO;
19 import org.thingsboard.server.common.data.yunteng.dto.TenantTransportMessageDTO; 17 import org.thingsboard.server.common.data.yunteng.dto.TenantTransportMessageDTO;
20 import org.thingsboard.server.common.data.yunteng.dto.statistics.HomePageAppDTO; 18 import org.thingsboard.server.common.data.yunteng.dto.statistics.HomePageAppDTO;
  19 +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
21 import org.thingsboard.server.common.data.yunteng.enums.TrendType; 20 import org.thingsboard.server.common.data.yunteng.enums.TrendType;
22 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; 21 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
23 import org.thingsboard.server.controller.BaseController; 22 import org.thingsboard.server.controller.BaseController;
@@ -103,13 +102,13 @@ public class HomePageController extends BaseController { @@ -103,13 +102,13 @@ public class HomePageController extends BaseController {
103 102
104 @GetMapping("app") 103 @GetMapping("app")
105 @ApiOperation(value = "小程序首页统计信息") 104 @ApiOperation(value = "小程序首页统计信息")
106 - public ResponseEntity<HomePageAppDTO> appStatistics() 105 + public ResponseEntity<HomePageAppDTO> appStatistics(@ApiParam(value = "只取告警数据") @RequestParam("login") Boolean login)
107 throws ThingsboardException, ExecutionException, InterruptedException { 106 throws ThingsboardException, ExecutionException, InterruptedException {
108 SecurityUser user = getCurrentUser(); 107 SecurityUser user = getCurrentUser();
109 if(user == null){ 108 if(user == null){
110 return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); 109 return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
111 } 110 }
112 - HomePageAppDTO app = homePageService.app(user.isPtSysadmin(),user.isPtAdmin(),user.isPtTenantAdmin(),user.getTenantId(),user.getCustomerId()); 111 + HomePageAppDTO app = homePageService.app(login,user.isPtSysadmin(),user.isPtAdmin(),user.isPtTenantAdmin(),user.getTenantId(),user.getCustomerId());
113 return ResponseEntity.ok(app); 112 return ResponseEntity.ok(app);
114 } 113 }
115 } 114 }
@@ -115,7 +115,7 @@ public class HomePageServiceImpl implements HomePageService { @@ -115,7 +115,7 @@ public class HomePageServiceImpl implements HomePageService {
115 } 115 }
116 116
117 @Override 117 @Override
118 - public HomePageAppDTO app(boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId) { 118 + public HomePageAppDTO app(Boolean login,boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId) {
119 /** 119 /**
120 * 如果当前用户是超级管理员或平台管理员,查询所有的租户数量、客户、设备 120 * 如果当前用户是超级管理员或平台管理员,查询所有的租户数量、客户、设备
121 * 如果当前用户是租户管理员,查询租户下的所有 客户、设备、告警、消息量 121 * 如果当前用户是租户管理员,查询租户下的所有 客户、设备、告警、消息量
@@ -135,6 +135,15 @@ public class HomePageServiceImpl implements HomePageService { @@ -135,6 +135,15 @@ public class HomePageServiceImpl implements HomePageService {
135 Map<String, Object> todayFilter = buildCountFilter(entityId,startTime,endTime); 135 Map<String, Object> todayFilter = buildCountFilter(entityId,startTime,endTime);
136 136
137 HomePageAppDTO app = new HomePageAppDTO(); 137 HomePageAppDTO app = new HomePageAppDTO();
  138 +
  139 + if (!isPtSysAdmin && !isPtAdmin ) {
  140 + app.setTotalAlarm(getAlarmInfo(totalFilter));
  141 + app.setTodayAlarm(getAlarmInfo(todayFilter));
  142 + }
  143 + if(login){
  144 + return app;
  145 + }
  146 +
138 if (isPtSysAdmin || isPtAdmin) { 147 if (isPtSysAdmin || isPtAdmin) {
139 List<TenantDTO> tenants = getTenantInfo(); 148 List<TenantDTO> tenants = getTenantInfo();
140 AtomicInteger totalExpired = new AtomicInteger(); 149 AtomicInteger totalExpired = new AtomicInteger();
@@ -192,10 +201,7 @@ public class HomePageServiceImpl implements HomePageService { @@ -192,10 +201,7 @@ public class HomePageServiceImpl implements HomePageService {
192 app.setTodayCustomer(today); 201 app.setTodayCustomer(today);
193 } 202 }
194 203
195 - if (!isPtSysAdmin && !isPtAdmin ) {  
196 - app.setTotalAlarm(getAlarmInfo(totalFilter));  
197 - app.setTodayAlarm(getAlarmInfo(todayFilter));  
198 - } 204 +
199 205
200 if (!isPtSysAdmin && !isPtAdmin ) { 206 if (!isPtSysAdmin && !isPtAdmin ) {
201 app.setTotalMsg(getFlowStatistics(totalFilter)); 207 app.setTotalMsg(getFlowStatistics(totalFilter));
@@ -81,7 +81,7 @@ public interface HomePageService { @@ -81,7 +81,7 @@ public interface HomePageService {
81 * @param customerId 81 * @param customerId
82 * @return 82 * @return
83 */ 83 */
84 - HomePageAppDTO app(boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId); 84 + HomePageAppDTO app(Boolean login,boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId);
85 } 85 }
86 86
87 87