Commit 7a162b4e11358b3f356d9632fac6bdfac1d458e0

Authored by 云中非
1 parent 7a8e5274

refactor: 条件过滤设备信息

1、设备类型过滤
2、组织过滤
3、设备标签过滤
... ... @@ -2,14 +2,12 @@ package org.thingsboard.server.controller.yunteng;
2 2
3 3 import io.swagger.annotations.Api;
4 4 import io.swagger.annotations.ApiOperation;
  5 +import io.swagger.annotations.ApiParam;
5 6 import lombok.RequiredArgsConstructor;
6 7 import org.springframework.http.HttpStatus;
7 8 import org.springframework.http.ResponseEntity;
8 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 11 import org.springframework.web.context.request.async.DeferredResult;
14 12 import org.thingsboard.server.common.data.exception.ThingsboardException;
15 13 import org.thingsboard.server.common.data.query.TsValue;
... ... @@ -18,6 +16,7 @@ import org.thingsboard.server.common.data.yunteng.dto.HomePageLeftTopDTO;
18 16 import org.thingsboard.server.common.data.yunteng.dto.TenantDTO;
19 17 import org.thingsboard.server.common.data.yunteng.dto.TenantTransportMessageDTO;
20 18 import org.thingsboard.server.common.data.yunteng.dto.statistics.HomePageAppDTO;
  19 +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
21 20 import org.thingsboard.server.common.data.yunteng.enums.TrendType;
22 21 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
23 22 import org.thingsboard.server.controller.BaseController;
... ... @@ -103,13 +102,13 @@ public class HomePageController extends BaseController {
103 102
104 103 @GetMapping("app")
105 104 @ApiOperation(value = "小程序首页统计信息")
106   - public ResponseEntity<HomePageAppDTO> appStatistics()
  105 + public ResponseEntity<HomePageAppDTO> appStatistics(@ApiParam(value = "只取告警数据") @RequestParam("login") Boolean login)
107 106 throws ThingsboardException, ExecutionException, InterruptedException {
108 107 SecurityUser user = getCurrentUser();
109 108 if(user == null){
110 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 112 return ResponseEntity.ok(app);
114 113 }
115 114 }
... ...
... ... @@ -115,7 +115,7 @@ public class HomePageServiceImpl implements HomePageService {
115 115 }
116 116
117 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 135 Map<String, Object> todayFilter = buildCountFilter(entityId,startTime,endTime);
136 136
137 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 147 if (isPtSysAdmin || isPtAdmin) {
139 148 List<TenantDTO> tenants = getTenantInfo();
140 149 AtomicInteger totalExpired = new AtomicInteger();
... ... @@ -192,10 +201,7 @@ public class HomePageServiceImpl implements HomePageService {
192 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 206 if (!isPtSysAdmin && !isPtAdmin ) {
201 207 app.setTotalMsg(getFlowStatistics(totalFilter));
... ...
... ... @@ -81,7 +81,7 @@ public interface HomePageService {
81 81 * @param customerId
82 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
... ...