Showing
1 changed file
with
57 additions
and
0 deletions
application/src/main/java/org/thingsboard/server/controller/yunteng/YtTenantProfilesController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | ||
2 | + | ||
3 | +import lombok.RequiredArgsConstructor; | ||
4 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
5 | +import org.springframework.web.bind.annotation.GetMapping; | ||
6 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
7 | +import org.springframework.web.bind.annotation.RequestParam; | ||
8 | +import org.springframework.web.bind.annotation.RestController; | ||
9 | +import org.thingsboard.server.common.data.TenantProfile; | ||
10 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
11 | +import org.thingsboard.server.common.data.page.PageData; | ||
12 | +import org.thingsboard.server.common.data.page.PageLink; | ||
13 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | ||
14 | +import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | ||
15 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
16 | +import org.thingsboard.server.controller.BaseController; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
21 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE; | ||
22 | + | ||
23 | +@RestController | ||
24 | +@RequestMapping("/api/yt/tenantProfiles") | ||
25 | +@RequiredArgsConstructor | ||
26 | +public class YtTenantProfilesController extends BaseController { | ||
27 | + | ||
28 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN')") | ||
29 | + @GetMapping( | ||
30 | + name = "page", | ||
31 | + params = {PAGE_SIZE, PAGE}) | ||
32 | + public YtPageData<TenantProfile> pageDevice( | ||
33 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
34 | + @RequestParam(PAGE) int page, | ||
35 | + @RequestParam(value = "name", required = false) String name, | ||
36 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
37 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
38 | + throws ThingsboardException { | ||
39 | + try { | ||
40 | + page -= 1; | ||
41 | + PageLink pageLink = | ||
42 | + createPageLink( | ||
43 | + pageSize, | ||
44 | + page, | ||
45 | + name, | ||
46 | + orderBy, | ||
47 | + null == orderType ? OrderTypeEnum.DESC.name() : orderType.name()); | ||
48 | + PageData<TenantProfile> tenantProfilePageData = | ||
49 | + tenantProfileService.findTenantProfiles(getTenantId(), pageLink); | ||
50 | + List<TenantProfile> targetList = | ||
51 | + ReflectUtils.sourceToTarget(tenantProfilePageData.getData(), TenantProfile.class); | ||
52 | + return new YtPageData<>(targetList, tenantProfilePageData.getTotalElements()); | ||
53 | + } catch (Exception e) { | ||
54 | + throw handleException(e); | ||
55 | + } | ||
56 | + } | ||
57 | +} |