Commit d8ef107bf8eaad947199b7573fc28a142449df24

Authored by xp.Huang
1 parent e6bc09ea

feat: 公共接口增加接口类型,同时允许超级管理员平台管理进行大屏设计

1 package org.thingsboard.server.controller.yunteng; 1 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 lombok.RequiredArgsConstructor; 5 import lombok.RequiredArgsConstructor;
5 import org.apache.commons.lang3.StringUtils; 6 import org.apache.commons.lang3.StringUtils;
6 import org.springframework.http.ResponseEntity; 7 import org.springframework.http.ResponseEntity;
@@ -20,6 +21,8 @@ import org.thingsboard.server.common.data.id.UserId; @@ -20,6 +21,8 @@ import org.thingsboard.server.common.data.id.UserId;
20 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; 21 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
21 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; 22 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
22 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; 23 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
  24 +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
  25 +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
23 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; 26 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
24 import org.thingsboard.server.common.data.yunteng.dto.MenuDTO; 27 import org.thingsboard.server.common.data.yunteng.dto.MenuDTO;
25 import org.thingsboard.server.common.data.yunteng.dto.TenantDTO; 28 import org.thingsboard.server.common.data.yunteng.dto.TenantDTO;
@@ -213,6 +216,21 @@ public class TkAdminController extends BaseController { @@ -213,6 +216,21 @@ public class TkAdminController extends BaseController {
213 return tkTenantService.updateOrCreateTenant(tenantReqDTO); 216 return tkTenantService.updateOrCreateTenant(tenantReqDTO);
214 } 217 }
215 218
  219 + @GetMapping("all/tenants")
  220 + @ApiOperation("获取租户列表")
  221 + @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{})")
  222 + public ResponseEntity<List<TenantDTO>> getAllTenants() {
  223 + return ResponseEntity.ok(tkTenantService.getAllTenant());
  224 + }
  225 +
  226 + @GetMapping("/{tenantId}/all/tenant_admin")
  227 + @ApiOperation("通过租户ID获取所有租户管理员")
  228 + @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{})")
  229 + public ResponseEntity<List<UserDTO>> getAllTenantAdminsByTenantId(
  230 + @PathVariable("tenantId") String tenantId) {
  231 + return ResponseEntity.ok(tkUserService.findAllTenantAdminsByTenantId(tenantId));
  232 + }
  233 +
216 private void deleteTenantAdmin(String strUserId, boolean isPtAdmin) throws ThingsboardException { 234 private void deleteTenantAdmin(String strUserId, boolean isPtAdmin) throws ThingsboardException {
217 try { 235 try {
218 UserId currentUserId = new UserId(toUUID(strUserId)); 236 UserId currentUserId = new UserId(toUUID(strUserId));
@@ -33,7 +33,6 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. @@ -33,7 +33,6 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.
33 @RequestMapping("/api/yt/data_view") 33 @RequestMapping("/api/yt/data_view")
34 @RequiredArgsConstructor 34 @RequiredArgsConstructor
35 @Api(tags = "大屏设计器") 35 @Api(tags = "大屏设计器")
36 -@PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")  
37 public class TkDataViewController extends BaseController { 36 public class TkDataViewController extends BaseController {
38 37
39 private final TkDataViewService tkDataViewService; 38 private final TkDataViewService tkDataViewService;
@@ -68,9 +67,10 @@ public class TkDataViewController extends BaseController { @@ -68,9 +67,10 @@ public class TkDataViewController extends BaseController {
68 queryMap.put(ORDER_TYPE, orderType.name()); 67 queryMap.put(ORDER_TYPE, orderType.name());
69 } 68 }
70 queryMap.put("userId", getCurrentUser().getCurrentUserId()); 69 queryMap.put("userId", getCurrentUser().getCurrentUserId());
71 - TkPageData<TkDataViewDTO> pageData = tkDataViewService.page(queryMap, getCurrentUser().isTenantAdmin());  
72 - if(!pageData.getItems().isEmpty()){  
73 - for(TkDataViewDTO dto : pageData.getItems()){ 70 + TkPageData<TkDataViewDTO> pageData =
  71 + tkDataViewService.page(queryMap, getCurrentUser().isTenantAdmin());
  72 + if (!pageData.getItems().isEmpty()) {
  73 + for (TkDataViewDTO dto : pageData.getItems()) {
74 setPublicCustomerIdToCache(dto); 74 setPublicCustomerIdToCache(dto);
75 } 75 }
76 } 76 }
@@ -80,7 +80,7 @@ public class TkDataViewController extends BaseController { @@ -80,7 +80,7 @@ public class TkDataViewController extends BaseController {
80 @PostMapping 80 @PostMapping
81 @ApiOperation("新增") 81 @ApiOperation("新增")
82 @PreAuthorize( 82 @PreAuthorize(
83 - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:post'})") 83 + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:post'})")
84 public ResponseEntity<TkDataViewDTO> save( 84 public ResponseEntity<TkDataViewDTO> save(
85 @Validated({AddGroup.class}) @RequestBody TkDataViewDTO TkDataViewDTO) 85 @Validated({AddGroup.class}) @RequestBody TkDataViewDTO TkDataViewDTO)
86 throws ThingsboardException { 86 throws ThingsboardException {
@@ -91,7 +91,8 @@ public class TkDataViewController extends BaseController { @@ -91,7 +91,8 @@ public class TkDataViewController extends BaseController {
91 @PutMapping 91 @PutMapping
92 @ApiOperation("修改") 92 @ApiOperation("修改")
93 @PreAuthorize( 93 @PreAuthorize(
94 - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:update'})") 94 + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN','CUSTOMER_USER'}," +
  95 + "{'api:yt:dataview:center:update'})")
95 public ResponseEntity<TkDataViewDTO> update( 96 public ResponseEntity<TkDataViewDTO> update(
96 @Validated({UpdateGroup.class}) @RequestBody TkDataViewDTO TkDataViewDTO) 97 @Validated({UpdateGroup.class}) @RequestBody TkDataViewDTO TkDataViewDTO)
97 throws ThingsboardException { 98 throws ThingsboardException {
@@ -102,7 +103,8 @@ public class TkDataViewController extends BaseController { @@ -102,7 +103,8 @@ public class TkDataViewController extends BaseController {
102 @DeleteMapping 103 @DeleteMapping
103 @ApiOperation("删除") 104 @ApiOperation("删除")
104 @PreAuthorize( 105 @PreAuthorize(
105 - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:delete'})") 106 + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN','CUSTOMER_USER'}," +
  107 + "{'api:yt:dataview:center:delete'})")
106 public ResponseEntity<Boolean> delete( 108 public ResponseEntity<Boolean> delete(
107 @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) 109 @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)
108 throws ThingsboardException { 110 throws ThingsboardException {
@@ -113,7 +115,8 @@ public class TkDataViewController extends BaseController { @@ -113,7 +115,8 @@ public class TkDataViewController extends BaseController {
113 @GetMapping("/get_configuration_info/{id}") 115 @GetMapping("/get_configuration_info/{id}")
114 @ApiOperation("获取大屏信息") 116 @ApiOperation("获取大屏信息")
115 @PreAuthorize( 117 @PreAuthorize(
116 - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:get_dataview_info:design'," 118 + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN','CUSTOMER_USER'}," +
  119 + "{'api:yt:dataview:center:get_dataview_info:design',"
117 + "'api:yt:dataview:center:get_dataview_info:preview'})") 120 + "'api:yt:dataview:center:get_dataview_info:preview'})")
118 public ResponseEntity<TkDataViewContentInfoDTO> getConfigurationInfos( 121 public ResponseEntity<TkDataViewContentInfoDTO> getConfigurationInfos(
119 @PathVariable("id") String id) throws ThingsboardException { 122 @PathVariable("id") String id) throws ThingsboardException {
@@ -123,7 +126,9 @@ public class TkDataViewController extends BaseController { @@ -123,7 +126,9 @@ public class TkDataViewController extends BaseController {
123 126
124 @GetMapping("/publish/{id}") 127 @GetMapping("/publish/{id}")
125 @ApiOperation("发布") 128 @ApiOperation("发布")
126 - @PreAuthorize("@check.checkPermissions({},{})") 129 + @PreAuthorize(
  130 + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN','CUSTOMER_USER'}," +
  131 + "{'api:yt:dataview:center:publish'})")
127 public ResponseEntity<Boolean> publishDataView(@PathVariable("id") String id) 132 public ResponseEntity<Boolean> publishDataView(@PathVariable("id") String id)
128 throws ThingsboardException { 133 throws ThingsboardException {
129 return ResponseEntity.ok( 134 return ResponseEntity.ok(
@@ -132,7 +137,9 @@ public class TkDataViewController extends BaseController { @@ -132,7 +137,9 @@ public class TkDataViewController extends BaseController {
132 137
133 @GetMapping("/cancel_publish/{id}") 138 @GetMapping("/cancel_publish/{id}")
134 @ApiOperation("取消发布") 139 @ApiOperation("取消发布")
135 - @PreAuthorize("@check.checkPermissions({},{})") 140 + @PreAuthorize(
  141 + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN','CUSTOMER_USER'}," +
  142 + "{'api:yt:dataview:center:cancel_publish'})")
136 public ResponseEntity<Boolean> cancelPublishDataView(@PathVariable("id") String id) 143 public ResponseEntity<Boolean> cancelPublishDataView(@PathVariable("id") String id)
137 throws ThingsboardException { 144 throws ThingsboardException {
138 return ResponseEntity.ok( 145 return ResponseEntity.ok(
@@ -141,7 +148,8 @@ public class TkDataViewController extends BaseController { @@ -141,7 +148,8 @@ public class TkDataViewController extends BaseController {
141 148
142 @PostMapping("share/{id}") 149 @PostMapping("share/{id}")
143 @ApiOperation("分享") 150 @ApiOperation("分享")
144 - @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:dataview:center:share'})") 151 + @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN','CUSTOMER_USER'}," +
  152 + "{'api:yt:dataview:center:share'})")
145 public ResponseEntity<Boolean> share( 153 public ResponseEntity<Boolean> share(
146 @PathVariable("id") String id, 154 @PathVariable("id") String id,
147 @RequestParam(value = "accessCredentials", required = false) String accessCredentials, 155 @RequestParam(value = "accessCredentials", required = false) String accessCredentials,
1 package org.thingsboard.server.controller.yunteng; 1 package org.thingsboard.server.controller.yunteng;
2 2
3 -import com.google.common.util.concurrent.ListenableFuture;  
4 import io.swagger.annotations.Api; 3 import io.swagger.annotations.Api;
5 import io.swagger.annotations.ApiOperation; 4 import io.swagger.annotations.ApiOperation;
6 import io.swagger.annotations.ApiParam; 5 import io.swagger.annotations.ApiParam;
7 import lombok.RequiredArgsConstructor; 6 import lombok.RequiredArgsConstructor;
8 -import org.apache.commons.lang3.StringUtils;  
9 -import org.springframework.http.MediaType;  
10 import org.springframework.http.ResponseEntity; 7 import org.springframework.http.ResponseEntity;
11 import org.springframework.security.access.prepost.PreAuthorize; 8 import org.springframework.security.access.prepost.PreAuthorize;
12 import org.springframework.validation.annotation.Validated; 9 import org.springframework.validation.annotation.Validated;
13 import org.springframework.web.bind.annotation.*; 10 import org.springframework.web.bind.annotation.*;
14 -import org.thingsboard.server.common.data.asset.Asset;  
15 import org.thingsboard.server.common.data.exception.ThingsboardException; 11 import org.thingsboard.server.common.data.exception.ThingsboardException;
16 -import org.thingsboard.server.common.data.id.AssetId;  
17 -import org.thingsboard.server.common.data.id.CustomerId;  
18 -import org.thingsboard.server.common.data.id.TenantId;  
19 import org.thingsboard.server.common.data.yunteng.common.AddGroup; 12 import org.thingsboard.server.common.data.yunteng.common.AddGroup;
20 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; 13 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
21 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; 14 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
22 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; 15 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
23 import org.thingsboard.server.common.data.yunteng.dto.TkDataViewInterfaceDTO; 16 import org.thingsboard.server.common.data.yunteng.dto.TkDataViewInterfaceDTO;
24 -import org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentInfoDTO;  
25 import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; 17 import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum;
  18 +import org.thingsboard.server.common.data.yunteng.enums.TkSystemTypeEnum;
26 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; 19 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
27 import org.thingsboard.server.controller.BaseController; 20 import org.thingsboard.server.controller.BaseController;
28 import org.thingsboard.server.dao.yunteng.service.TkDataViewInterfaceService; 21 import org.thingsboard.server.dao.yunteng.service.TkDataViewInterfaceService;
29 -import org.thingsboard.server.service.security.model.SecurityUser;  
30 22
31 import java.util.*; 23 import java.util.*;
32 24
@@ -41,153 +33,154 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. @@ -41,153 +33,154 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.
41 @Api(tags = "大屏公共接口") 33 @Api(tags = "大屏公共接口")
42 public class TkDataViewInterfaceController extends BaseController { 34 public class TkDataViewInterfaceController extends BaseController {
43 35
44 - private final TkDataViewInterfaceService tkDataViewInterfaceService;  
45 -  
46 - @GetMapping(params = {PAGE_SIZE, PAGE})  
47 - @ApiOperation("分页")  
48 - public TkPageData<TkDataViewInterfaceDTO> page(  
49 - @RequestParam(PAGE_SIZE) int pageSize,  
50 - @RequestParam(PAGE) int page,  
51 - @RequestParam(value = "name", required = false) String name,  
52 - @RequestParam(value = "state", required = false) String state,  
53 - @RequestParam(value = ORDER_FILED, required = false) String orderBy,  
54 - @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)  
55 - throws ThingsboardException {  
56 -  
57 - HashMap<String, Object> queryMap = new HashMap<>();  
58 - queryMap.put(PAGE_SIZE, pageSize);  
59 - queryMap.put(PAGE, page);  
60 - queryMap.put(ORDER_FILED, orderBy);  
61 - queryMap.put("tenantId", getCurrentUser().getCurrentTenantId());  
62 - if (StringUtils.isNotBlank(name)) {  
63 - queryMap.put("name", name);  
64 - }  
65 - if (StringUtils.isNotBlank(state)) {  
66 - queryMap.put("state", state);  
67 - }  
68 - if (null != orderType) {  
69 - queryMap.put(ORDER_TYPE, orderType.name());  
70 - }  
71 - return tkDataViewInterfaceService.page(queryMap); 36 + private final TkDataViewInterfaceService tkDataViewInterfaceService;
  37 +
  38 + @GetMapping(params = {PAGE_SIZE, PAGE})
  39 + @ApiOperation("分页")
  40 + public TkPageData<TkDataViewInterfaceDTO> page(
  41 + @RequestParam(PAGE_SIZE) int pageSize,
  42 + @RequestParam(PAGE) int page,
  43 + @RequestParam(value = "name", required = false) String name,
  44 + @RequestParam(value = "state", required = false) Integer state,
  45 + @RequestParam(value = "interfaceType", required = false) TkSystemTypeEnum interfaceType,
  46 + @RequestParam(value = ORDER_FILED, required = false) String orderBy,
  47 + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
  48 + throws ThingsboardException {
  49 +
  50 + HashMap<String, Object> queryMap = new HashMap<>();
  51 + queryMap.put(PAGE_SIZE, pageSize);
  52 + queryMap.put(PAGE, page);
  53 + queryMap.put(ORDER_FILED, orderBy);
  54 + queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId());
  55 + queryMap.put("name", name);
  56 + queryMap.put("state", state);
  57 + if (null != orderType) {
  58 + queryMap.put(ORDER_TYPE, orderType.name());
72 } 59 }
73 -  
74 - @PostMapping  
75 - @ApiOperation("新增")  
76 - @PreAuthorize("@check.checkPermissions({},{})")  
77 - public ResponseEntity<TkDataViewInterfaceDTO> save(  
78 - @Validated({AddGroup.class}) @RequestBody TkDataViewInterfaceDTO tkDataViewInterfaceDTO)  
79 - throws ThingsboardException {  
80 - tkDataViewInterfaceDTO.setTenantId(getCurrentUser().getCurrentTenantId());  
81 -  
82 - return ResponseEntity.ok(  
83 - tkDataViewInterfaceService.saveDataViewInterface(tkDataViewInterfaceDTO));  
84 - }  
85 -  
86 - @PutMapping  
87 - @ApiOperation("修改")  
88 - @PreAuthorize("@check.checkPermissions({},{})")  
89 - public ResponseEntity<TkDataViewInterfaceDTO> update(  
90 - @Validated({UpdateGroup.class}) @RequestBody TkDataViewInterfaceDTO TkDataViewInterfaceDTO)  
91 - throws ThingsboardException {  
92 - TkDataViewInterfaceDTO.setTenantId(getCurrentUser().getCurrentTenantId());  
93 - return ResponseEntity.ok(  
94 - tkDataViewInterfaceService.updateDataViewInterface(TkDataViewInterfaceDTO));  
95 - }  
96 -  
97 - @DeleteMapping  
98 - @ApiOperation("删除")  
99 - @PreAuthorize("@check.checkPermissions({},{})")  
100 - public ResponseEntity<Boolean> delete(  
101 - @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)  
102 - throws ThingsboardException {  
103 - deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId());  
104 - return ResponseEntity.ok(tkDataViewInterfaceService.deleteDataViewInterface(deleteDTO));  
105 - }  
106 -  
107 -  
108 - @GetMapping("/publish/{id}")  
109 - @ApiOperation("发布")  
110 - @PreAuthorize("@check.checkPermissions({},{})")  
111 - public ResponseEntity<Boolean> publishInterface(@PathVariable("id") String id) throws ThingsboardException {  
112 - return ResponseEntity.ok(  
113 - tkDataViewInterfaceService.publishInterface(id, getCurrentUser().getCurrentTenantId()));  
114 - }  
115 -  
116 - @GetMapping("/cancel_publish/{id}")  
117 - @ApiOperation("取消发布")  
118 - @PreAuthorize("@check.checkPermissions({},{})")  
119 - public ResponseEntity<Boolean> cancelPublishInterface(@PathVariable("id") String id) throws ThingsboardException {  
120 - return ResponseEntity.ok(  
121 - tkDataViewInterfaceService.cancelPublishInterface(id, getCurrentUser().getCurrentTenantId()));  
122 - }  
123 -  
124 -  
125 - @ApiOperation("根据接口ID,获得接口详情")  
126 - @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")  
127 - @RequestMapping(value = "/get_interface_details", params = {"ids"}, method = RequestMethod.GET)  
128 - @ResponseBody  
129 - public List<TkDataViewInterfaceDTO> getInterfaceDetails(  
130 - @ApiParam(value = "A list of interface ids, separated by comma ','")  
131 - @RequestParam("ids") String[] ids) throws ThingsboardException {  
132 -  
133 - List<String> idsList = new ArrayList<>();  
134 - for (String strId : ids) {  
135 - idsList.add(strId);  
136 - }  
137 - return tkDataViewInterfaceService.getInterfaceDetails(idsList); 60 + if (null != interfaceType) {
  61 + queryMap.put("interfaceType", interfaceType);
138 } 62 }
139 -  
140 - @GetMapping("/filter_by_interface_type/{type}")  
141 - @ApiOperation("根据接口类型过滤数据")  
142 - @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")  
143 - public List<TkDataViewInterfaceDTO> filterByInterfaceType(@PathVariable("type") String type) throws ThingsboardException {  
144 - return tkDataViewInterfaceService.filterByInterfaceType(type, getCurrentUser().getCurrentTenantId());  
145 - }  
146 -  
147 -  
148 - @GetMapping("/find_all_interface/{state}")  
149 - @ApiOperation("查询所有接口")  
150 - @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")  
151 - public List<TkDataViewInterfaceDTO> findAll(@PathVariable("state") String state) throws ThingsboardException {  
152 - return tkDataViewInterfaceService.findAll(state,getCurrentUser().getCurrentTenantId());  
153 - }  
154 -  
155 -  
156 - @ApiOperation("批量发布")  
157 - @RequestMapping(value = "/batch_publish", params = {"ids"}, method = RequestMethod.PUT)  
158 - @ResponseBody  
159 - public ResponseEntity<Boolean> batchPublishInterface(  
160 - @ApiParam(value = "A list of interface ids, separated by comma ','")  
161 - @RequestParam("ids") String[] ids) throws ThingsboardException {  
162 -  
163 - List<String> idsList = new ArrayList<>();  
164 - for (String strId : ids) {  
165 - idsList.add(strId);  
166 - }  
167 - return ResponseEntity.ok(tkDataViewInterfaceService.batchPublishInterface(idsList, getCurrentUser().getCurrentTenantId()));  
168 - }  
169 -  
170 - @ApiOperation("批量取消发布")  
171 - @RequestMapping(value = "/batch_cancel_publish", params = {"ids"}, method = RequestMethod.PUT)  
172 - @ResponseBody  
173 - public ResponseEntity<Boolean> batchCancelPublishInterface(  
174 - @ApiParam(value = "A list of interface ids, separated by comma ','")  
175 - @RequestParam("ids") String[] ids) throws ThingsboardException {  
176 -  
177 - List<String> idsList = new ArrayList<>();  
178 - for (String strId : ids) {  
179 - idsList.add(strId);  
180 - }  
181 - return ResponseEntity.ok(tkDataViewInterfaceService.batchCancelPublishInterface(idsList, getCurrentUser().getCurrentTenantId()));  
182 - }  
183 -  
184 -  
185 -// @ApiOperation("SQL查询")  
186 -// @RequestMapping(value = "/sql_select", params = {"sql"}, method = RequestMethod.POST)  
187 -// @ResponseBody  
188 -// public List<LinkedHashMap<String, Object>> sqlSelect(  
189 -// @RequestParam("sql") String sql) throws ThingsboardException {  
190 -// return tkDataViewInterfaceService.executeSql(sql);  
191 -// }  
192 - 63 + return tkDataViewInterfaceService.page(queryMap);
  64 + }
  65 +
  66 + @PostMapping
  67 + @ApiOperation("新增")
  68 + @PreAuthorize("@check.checkPermissions({},{})")
  69 + public ResponseEntity<TkDataViewInterfaceDTO> save(
  70 + @Validated({AddGroup.class}) @RequestBody TkDataViewInterfaceDTO tkDataViewInterfaceDTO)
  71 + throws ThingsboardException {
  72 + tkDataViewInterfaceDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  73 +
  74 + return ResponseEntity.ok(
  75 + tkDataViewInterfaceService.saveDataViewInterface(tkDataViewInterfaceDTO));
  76 + }
  77 +
  78 + @PutMapping
  79 + @ApiOperation("修改")
  80 + @PreAuthorize("@check.checkPermissions({},{})")
  81 + public ResponseEntity<TkDataViewInterfaceDTO> update(
  82 + @Validated({UpdateGroup.class}) @RequestBody TkDataViewInterfaceDTO TkDataViewInterfaceDTO)
  83 + throws ThingsboardException {
  84 + TkDataViewInterfaceDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  85 + return ResponseEntity.ok(
  86 + tkDataViewInterfaceService.updateDataViewInterface(TkDataViewInterfaceDTO));
  87 + }
  88 +
  89 + @DeleteMapping
  90 + @ApiOperation("删除")
  91 + @PreAuthorize("@check.checkPermissions({},{})")
  92 + public ResponseEntity<Boolean> delete(
  93 + @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)
  94 + throws ThingsboardException {
  95 + deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  96 + return ResponseEntity.ok(tkDataViewInterfaceService.deleteDataViewInterface(deleteDTO));
  97 + }
  98 +
  99 + @GetMapping("/publish/{id}")
  100 + @ApiOperation("发布")
  101 + @PreAuthorize("@check.checkPermissions({},{})")
  102 + public ResponseEntity<Boolean> publishInterface(@PathVariable("id") String id)
  103 + throws ThingsboardException {
  104 + return ResponseEntity.ok(
  105 + tkDataViewInterfaceService.publishInterface(id, getCurrentUser().getCurrentTenantId()));
  106 + }
  107 +
  108 + @GetMapping("/cancel_publish/{id}")
  109 + @ApiOperation("取消发布")
  110 + @PreAuthorize("@check.checkPermissions({},{})")
  111 + public ResponseEntity<Boolean> cancelPublishInterface(@PathVariable("id") String id)
  112 + throws ThingsboardException {
  113 + return ResponseEntity.ok(
  114 + tkDataViewInterfaceService.cancelPublishInterface(
  115 + id, getCurrentUser().getCurrentTenantId()));
  116 + }
  117 +
  118 + @ApiOperation("根据接口ID,获得接口详情")
  119 + @PreAuthorize("@check.checkPermissions({},{})")
  120 + @RequestMapping(
  121 + value = "/get_interface_details",
  122 + params = {"ids"},
  123 + method = RequestMethod.GET)
  124 + @ResponseBody
  125 + public List<TkDataViewInterfaceDTO> getInterfaceDetails(
  126 + @ApiParam(value = "A list of interface ids, separated by comma ','") @RequestParam("ids")
  127 + String[] ids) {
  128 + return tkDataViewInterfaceService.getInterfaceDetails(new ArrayList<>(Arrays.asList(ids)));
  129 + }
  130 +
  131 + @GetMapping("/filter_by_interface_type/{type}")
  132 + @ApiOperation("根据接口类型过滤数据")
  133 + @PreAuthorize("@check.checkPermissions({},{})")
  134 + public List<TkDataViewInterfaceDTO> filterByInterfaceType(@PathVariable("type") String type)
  135 + throws ThingsboardException {
  136 + return tkDataViewInterfaceService.filterByInterfaceType(
  137 + type, getCurrentUser().getCurrentTenantId());
  138 + }
  139 +
  140 + @GetMapping("/find_all_interface/{state}")
  141 + @ApiOperation("查询所有接口")
  142 + @PreAuthorize("@check.checkPermissions({},{})")
  143 + public List<TkDataViewInterfaceDTO> findAll(@PathVariable("state") String state)
  144 + throws ThingsboardException {
  145 + return tkDataViewInterfaceService.findAll(state, getCurrentUser().getCurrentTenantId());
  146 + }
  147 +
  148 + @GetMapping("/find/can_use_interfaces")
  149 + @ApiOperation("查询当前用户可使用的接口")
  150 + @PreAuthorize("@check.checkPermissions({},{})")
  151 + public List<TkDataViewInterfaceDTO> findCanUseInterfaces() throws ThingsboardException {
  152 + boolean isSysAdminOrPtAdmin = getCurrentUser().isPtAdmin() || getCurrentUser().isSystemAdmin();
  153 + return tkDataViewInterfaceService.findCanUseInterfaces(
  154 + isSysAdminOrPtAdmin, getCurrentUser().getCurrentTenantId());
  155 + }
  156 +
  157 + @ApiOperation("批量发布")
  158 + @RequestMapping(
  159 + value = "/batch_publish",
  160 + params = {"ids"},
  161 + method = RequestMethod.PUT)
  162 + @ResponseBody
  163 + public ResponseEntity<Boolean> batchPublishInterface(
  164 + @ApiParam(value = "A list of interface ids, separated by comma ','") @RequestParam("ids")
  165 + String[] ids)
  166 + throws ThingsboardException {
  167 + return ResponseEntity.ok(
  168 + tkDataViewInterfaceService.batchPublishInterface(
  169 + new ArrayList<>(Arrays.asList(ids)), getCurrentUser().getCurrentTenantId()));
  170 + }
  171 +
  172 + @ApiOperation("批量取消发布")
  173 + @RequestMapping(
  174 + value = "/batch_cancel_publish",
  175 + params = {"ids"},
  176 + method = RequestMethod.PUT)
  177 + @ResponseBody
  178 + public ResponseEntity<Boolean> batchCancelPublishInterface(
  179 + @ApiParam(value = "A list of interface ids, separated by comma ','") @RequestParam("ids")
  180 + String[] ids)
  181 + throws ThingsboardException {
  182 + return ResponseEntity.ok(
  183 + tkDataViewInterfaceService.batchCancelPublishInterface(
  184 + new ArrayList<>(Arrays.asList(ids)), getCurrentUser().getCurrentTenantId()));
  185 + }
193 } 186 }
@@ -5,6 +5,7 @@ import lombok.Data; @@ -5,6 +5,7 @@ import lombok.Data;
5 import lombok.EqualsAndHashCode; 5 import lombok.EqualsAndHashCode;
6 import org.thingsboard.server.common.data.yunteng.common.AddGroup; 6 import org.thingsboard.server.common.data.yunteng.common.AddGroup;
7 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; 7 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
  8 +import org.thingsboard.server.common.data.yunteng.enums.TkSystemTypeEnum;
8 9
9 import javax.validation.constraints.NotEmpty; 10 import javax.validation.constraints.NotEmpty;
10 /** 11 /**
@@ -14,31 +15,33 @@ import javax.validation.constraints.NotEmpty; @@ -14,31 +15,33 @@ import javax.validation.constraints.NotEmpty;
14 @Data 15 @Data
15 public class TkDataViewInterfaceDTO extends TenantDTO { 16 public class TkDataViewInterfaceDTO extends TenantDTO {
16 17
17 - @ApiModelProperty(value = "接口名称", required = true)  
18 - @NotEmpty(  
19 - message = "名称不能为空或空字符串",  
20 - groups = {UpdateGroup.class, AddGroup.class})  
21 - private String interfaceName; 18 + @ApiModelProperty(value = "接口名称", required = true)
  19 + @NotEmpty(
  20 + message = "名称不能为空或空字符串",
  21 + groups = {UpdateGroup.class, AddGroup.class})
  22 + private String interfaceName;
22 23
23 - @ApiModelProperty(value = "请求方式:0普通请求 1SQL请求 2websocket请求")  
24 - private Integer requestContentType; 24 + @ApiModelProperty(value = "请求方式:0普通请求 1SQL请求 2websocket请求")
  25 + private Integer requestContentType;
25 26
26 - @ApiModelProperty(value = "源地址")  
27 - private String requestOriginUrl; 27 + @ApiModelProperty(value = "源地址")
  28 + private String requestOriginUrl;
28 29
29 - @ApiModelProperty(value = "请求类型:GET、PUT、POST", required = true)  
30 - private String requestHttpType; 30 + @ApiModelProperty(value = "请求类型:GET、PUT、POST", required = true)
  31 + private String requestHttpType;
31 32
32 - @ApiModelProperty(value = "接口地址")  
33 - private String requestUrl; 33 + @ApiModelProperty(value = "接口类型:系统、自定义(默认)")
  34 + private TkSystemTypeEnum interfaceType = TkSystemTypeEnum.CUSTOM;
34 35
35 - @ApiModelProperty(value = "参数配置")  
36 - private String requestParams; 36 + @ApiModelProperty(value = "接口地址")
  37 + private String requestUrl;
37 38
38 - @ApiModelProperty(value = "状态:0待发布 1已发布")  
39 - private Integer state; 39 + @ApiModelProperty(value = "参数配置")
  40 + private String requestParams;
40 41
41 - @ApiModelProperty(value = "接口描述")  
42 - private String remark; 42 + @ApiModelProperty(value = "状态:0待发布 1已发布")
  43 + private Integer state;
43 44
  45 + @ApiModelProperty(value = "接口描述")
  46 + private String remark;
44 } 47 }
@@ -10,10 +10,13 @@ public enum StatusEnum { @@ -10,10 +10,13 @@ public enum StatusEnum {
10 DISABLE("禁用", 0), 10 DISABLE("禁用", 0),
11 NORMAL("正常", 1), 11 NORMAL("正常", 1),
12 PAUSE("暂停", 0), 12 PAUSE("暂停", 0),
  13 +
  14 + NOT_RELEASE("未发布", 0),
  15 + RELEASE("发布", 1),
13 FAIL("失败", 0), 16 FAIL("失败", 0),
14 SUCCESS("成功", 1), 17 SUCCESS("成功", 1),
15 - RUNNING("运行中",2),  
16 - NOT_RUNNING("未执行",3); 18 + RUNNING("运行中", 2),
  19 + NOT_RUNNING("未执行", 3);
17 20
18 @Getter @Setter private String name; 21 @Getter @Setter private String name;
19 @Getter @Setter private Integer index; 22 @Getter @Setter private Integer index;
  1 +package org.thingsboard.server.common.data.yunteng.enums;
  2 +
  3 +public enum TkSystemTypeEnum {
  4 + /** 系统默认 */
  5 + SYSTEM,
  6 + /** 自定义 */
  7 + CUSTOM
  8 +}
@@ -40,7 +40,7 @@ public class SysUserEntity extends TenantBaseEntity { @@ -40,7 +40,7 @@ public class SysUserEntity extends TenantBaseEntity {
40 /** TB的UserId */ 40 /** TB的UserId */
41 private String tbUser; 41 private String tbUser;
42 42
43 - /** 0:超级管理员;1:租户账号;2:租户下的账号 */ 43 + /** 0:超级管理员;1:平台管理员;2:租户账号;3:租户下的账号 */
44 private Integer level; 44 private Integer level;
45 45
46 private String remark; 46 private String remark;
1 package org.thingsboard.server.dao.yunteng.entities; 1 package org.thingsboard.server.dao.yunteng.entities;
2 -  
3 -import com.baomidou.mybatisplus.annotation.FieldStrategy;  
4 import com.baomidou.mybatisplus.annotation.TableField; 2 import com.baomidou.mybatisplus.annotation.TableField;
5 import com.baomidou.mybatisplus.annotation.TableName; 3 import com.baomidou.mybatisplus.annotation.TableName;
6 -import io.swagger.annotations.ApiModelProperty;  
7 import lombok.Data; 4 import lombok.Data;
8 import lombok.EqualsAndHashCode; 5 import lombok.EqualsAndHashCode;
  6 +import org.apache.ibatis.type.EnumTypeHandler;
9 import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; 7 import org.thingsboard.server.common.data.yunteng.constant.ModelConstants;
  8 +import org.thingsboard.server.common.data.yunteng.enums.TkSystemTypeEnum;
10 9
11 /** 10 /**
12 * @author tianfuLei 11 * @author tianfuLei
@@ -26,4 +25,6 @@ public class TkDataViewInterfaceEntity extends TenantBaseEntity { @@ -26,4 +25,6 @@ public class TkDataViewInterfaceEntity extends TenantBaseEntity {
26 private Integer state; 25 private Integer state;
27 private String remark; 26 private String remark;
28 27
  28 + @TableField(typeHandler = EnumTypeHandler.class)
  29 + private TkSystemTypeEnum interfaceType;
29 } 30 }
@@ -692,6 +692,21 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE @@ -692,6 +692,21 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE
692 } 692 }
693 693
694 @Override 694 @Override
  695 + public List<UserDTO> findAllTenantAdminsByTenantId(String tenantId) {
  696 + List<SysUserEntity> entities =
  697 + baseMapper.selectList(
  698 + new LambdaQueryWrapper<SysUserEntity>()
  699 + .eq(SysUserEntity::getTenantId, tenantId)
  700 + .eq(SysUserEntity::getLevel, 2));
  701 + if (null != entities && !entities.isEmpty()) {
  702 + return entities.stream()
  703 + .map(entity -> entity.getDTO(UserDTO.class))
  704 + .collect(Collectors.toList());
  705 + }
  706 + return null;
  707 + }
  708 +
  709 + @Override
695 public UserDTO accountExist(String userName) { 710 public UserDTO accountExist(String userName) {
696 if (StringUtils.isEmpty(userName)) { 711 if (StringUtils.isEmpty(userName)) {
697 throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); 712 throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
@@ -5,21 +5,20 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -5,21 +5,20 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 import com.baomidou.mybatisplus.core.metadata.IPage; 5 import com.baomidou.mybatisplus.core.metadata.IPage;
6 import lombok.RequiredArgsConstructor; 6 import lombok.RequiredArgsConstructor;
7 import lombok.extern.slf4j.Slf4j; 7 import lombok.extern.slf4j.Slf4j;
8 -import org.apache.ibatis.annotations.Param; 8 +import org.apache.commons.lang3.StringUtils;
9 import org.springframework.stereotype.Service; 9 import org.springframework.stereotype.Service;
10 import org.springframework.transaction.annotation.Transactional; 10 import org.springframework.transaction.annotation.Transactional;
11 import org.thingsboard.server.common.data.id.EntityId; 11 import org.thingsboard.server.common.data.id.EntityId;
  12 +import org.thingsboard.server.common.data.id.UserId;
12 import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; 13 import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
13 import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; 14 import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
14 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; 15 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
15 import org.thingsboard.server.common.data.yunteng.dto.*; 16 import org.thingsboard.server.common.data.yunteng.dto.*;
16 -import org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentInfoDTO; 17 +import org.thingsboard.server.common.data.yunteng.enums.StatusEnum;
  18 +import org.thingsboard.server.common.data.yunteng.enums.TkSystemTypeEnum;
17 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; 19 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
18 -import org.thingsboard.server.dao.yunteng.entities.*;  
19 import org.thingsboard.server.dao.yunteng.entities.TkDataViewInterfaceEntity; 20 import org.thingsboard.server.dao.yunteng.entities.TkDataViewInterfaceEntity;
20 -import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper;  
21 import org.thingsboard.server.dao.yunteng.mapper.TkDataViewInterfaceMapper; 21 import org.thingsboard.server.dao.yunteng.mapper.TkDataViewInterfaceMapper;
22 -import org.thingsboard.server.dao.yunteng.mapper.TkDataViewMapper;  
23 import org.thingsboard.server.dao.yunteng.service.*; 22 import org.thingsboard.server.dao.yunteng.service.*;
24 23
25 import java.util.*; 24 import java.util.*;
@@ -32,182 +31,186 @@ import java.util.stream.Collectors; @@ -32,182 +31,186 @@ import java.util.stream.Collectors;
32 @Service 31 @Service
33 @RequiredArgsConstructor 32 @RequiredArgsConstructor
34 public class TkDataViewInterfaceServiceImpl 33 public class TkDataViewInterfaceServiceImpl
35 - extends AbstractBaseService<TkDataViewInterfaceMapper, TkDataViewInterfaceEntity>  
36 - implements TkDataViewInterfaceService {  
37 -  
38 - @Override  
39 - public TkPageData<TkDataViewInterfaceDTO> page(  
40 - Map<String, Object> queryMap) {  
41 - IPage<TkDataViewInterfaceEntity> iPage = null;  
42 - if(queryMap.get("state") != null){  
43 - iPage = baseMapper.selectPage(  
44 - getPage(queryMap, "create_time", false),  
45 - new QueryWrapper<TkDataViewInterfaceEntity>()  
46 - .lambda()  
47 - .like(  
48 - queryMap.get("name") != null,  
49 - TkDataViewInterfaceEntity::getInterfaceName,  
50 - String.valueOf(queryMap.get("name")))  
51 - .in(  
52 - queryMap.get("tenantId") != null,  
53 - TkDataViewInterfaceEntity::getTenantId, EntityId.NULL_UUID.toString(),  
54 - String.valueOf(queryMap.get("tenantId")))  
55 - .eq(  
56 - queryMap.get("state") != null,  
57 - TkDataViewInterfaceEntity::getState,  
58 - Integer.parseInt((String)queryMap.get("state"))));  
59 - }else{  
60 - iPage = baseMapper.selectPage(  
61 - getPage(queryMap, "create_time", false),  
62 - new QueryWrapper<TkDataViewInterfaceEntity>()  
63 - .lambda()  
64 - .like(  
65 - queryMap.get("name") != null,  
66 - TkDataViewInterfaceEntity::getInterfaceName,  
67 - String.valueOf(queryMap.get("name")))  
68 - .in(  
69 - queryMap.get("tenantId") != null,  
70 - TkDataViewInterfaceEntity::getTenantId, EntityId.NULL_UUID.toString(),  
71 - String.valueOf(queryMap.get("tenantId")))  
72 - .eq(  
73 - queryMap.get("state") != null,  
74 - TkDataViewInterfaceEntity::getState,  
75 - String.valueOf(queryMap.get("state"))));  
76 - }  
77 -  
78 - return getPageData(iPage, TkDataViewInterfaceDTO.class); 34 + extends AbstractBaseService<TkDataViewInterfaceMapper, TkDataViewInterfaceEntity>
  35 + implements TkDataViewInterfaceService {
  36 +
  37 + @Override
  38 + public TkPageData<TkDataViewInterfaceDTO> page(Map<String, Object> queryMap) {
  39 + String name = null != queryMap.get("name") ? (String) queryMap.get("name") : null;
  40 + Integer state = null != queryMap.get("state") ? (Integer) queryMap.get("state") : null;
  41 + TkSystemTypeEnum interfaceType =
  42 + null != queryMap.get("interfaceType")
  43 + ? (TkSystemTypeEnum) queryMap.get("interfaceType")
  44 + : null;
  45 + String tenantId = (String) queryMap.get("tenantId");
  46 + IPage<TkDataViewInterfaceEntity> iPage =
  47 + baseMapper.selectPage(
  48 + getPage(queryMap, "create_time", false),
  49 + new QueryWrapper<TkDataViewInterfaceEntity>()
  50 + .lambda()
  51 + .eq(TkDataViewInterfaceEntity::getTenantId, tenantId)
  52 + .eq(
  53 + null != interfaceType,
  54 + TkDataViewInterfaceEntity::getInterfaceType,
  55 + interfaceType)
  56 + .like(
  57 + StringUtils.isNotEmpty(name), TkDataViewInterfaceEntity::getInterfaceName, name)
  58 + .eq(state != null, TkDataViewInterfaceEntity::getState, state));
  59 + return getPageData(iPage, TkDataViewInterfaceDTO.class);
  60 + }
  61 +
  62 + @Override
  63 + @Transactional
  64 + public TkDataViewInterfaceDTO saveDataViewInterface(
  65 + TkDataViewInterfaceDTO tkDataViewInterfaceDTO) {
  66 + TkDataViewInterfaceEntity interfaceEntity =
  67 + tkDataViewInterfaceDTO.getEntity(TkDataViewInterfaceEntity.class);
  68 + interfaceEntity.setState(0);
  69 +
  70 + baseMapper.insert(interfaceEntity);
  71 + return tkDataViewInterfaceDTO;
  72 + }
  73 +
  74 + @Override
  75 + @Transactional
  76 + public TkDataViewInterfaceDTO updateDataViewInterface(
  77 + TkDataViewInterfaceDTO tkDataViewInterfaceDTO) {
  78 + TkDataViewInterfaceEntity interfaceEntity =
  79 + baseMapper.selectById(tkDataViewInterfaceDTO.getId());
  80 + if (!interfaceEntity.getTenantId().equals(tkDataViewInterfaceDTO.getTenantId())) {
  81 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
79 } 82 }
80 -  
81 - @Override  
82 - @Transactional  
83 - public TkDataViewInterfaceDTO saveDataViewInterface(TkDataViewInterfaceDTO tkDataViewInterfaceDTO) {  
84 - TkDataViewInterfaceEntity interfaceEntity =  
85 - tkDataViewInterfaceDTO.getEntity(TkDataViewInterfaceEntity.class);  
86 - interfaceEntity.setState(0);  
87 -  
88 - baseMapper.insert(interfaceEntity);  
89 - return tkDataViewInterfaceDTO;  
90 - }  
91 -  
92 - @Override  
93 - @Transactional  
94 - public TkDataViewInterfaceDTO updateDataViewInterface(TkDataViewInterfaceDTO tkDataViewInterfaceDTO) {  
95 - TkDataViewInterfaceEntity interfaceEntity = baseMapper.selectById(tkDataViewInterfaceDTO.getId());  
96 - if (!interfaceEntity.getTenantId().equals(tkDataViewInterfaceDTO.getTenantId())) {  
97 - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());  
98 - }  
99 - baseMapper.updateById(tkDataViewInterfaceDTO.getEntity(TkDataViewInterfaceEntity.class));  
100 - return tkDataViewInterfaceDTO;  
101 - }  
102 -  
103 - @Override  
104 - @Transactional  
105 - public boolean deleteDataViewInterface(DeleteDTO deleteDTO) {  
106 - List<TkDataViewInterfaceEntity> interfaceEntityList =  
107 - baseMapper.selectList(  
108 - new LambdaQueryWrapper<TkDataViewInterfaceEntity>()  
109 - .in(TkDataViewInterfaceEntity::getId, deleteDTO.getIds()));  
110 - for (TkDataViewInterfaceEntity center : interfaceEntityList) {  
111 - if (!center.getTenantId().equals(deleteDTO.getTenantId())) {  
112 - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());  
113 - }  
114 - }  
115 - return baseMapper.deleteBatchIds(deleteDTO.getIds()) > FastIotConstants.MagicNumber.ZERO;  
116 - }  
117 -  
118 -  
119 - @Override  
120 - public boolean publishInterface(String id, String tenantId) {  
121 - TkDataViewInterfaceEntity dataViewInterfaceEntity = baseMapper.selectById(id);  
122 - if (!dataViewInterfaceEntity.getTenantId().equals(tenantId)) {  
123 - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());  
124 - }  
125 - //Modify interface state is publish  
126 - dataViewInterfaceEntity.setState(1);  
127 - int resultInt = baseMapper.updateById(dataViewInterfaceEntity);  
128 - return resultInt > 0 ; 83 + baseMapper.updateById(tkDataViewInterfaceDTO.getEntity(TkDataViewInterfaceEntity.class));
  84 + return tkDataViewInterfaceDTO;
  85 + }
  86 +
  87 + @Override
  88 + @Transactional
  89 + public boolean deleteDataViewInterface(DeleteDTO deleteDTO) {
  90 + List<TkDataViewInterfaceEntity> interfaceEntityList =
  91 + baseMapper.selectList(
  92 + new LambdaQueryWrapper<TkDataViewInterfaceEntity>()
  93 + .in(TkDataViewInterfaceEntity::getId, deleteDTO.getIds()));
  94 + for (TkDataViewInterfaceEntity center : interfaceEntityList) {
  95 + if (!center.getTenantId().equals(deleteDTO.getTenantId())) {
  96 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
  97 + }
129 } 98 }
130 -  
131 - @Override  
132 - public boolean cancelPublishInterface(String id, String tenantId) {  
133 - TkDataViewInterfaceEntity dataViewInterfaceEntity = baseMapper.selectById(id);  
134 - if (!dataViewInterfaceEntity.getTenantId().equals(tenantId)) {  
135 - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());  
136 - }  
137 - //Modify interface state is cancelPublish  
138 - dataViewInterfaceEntity.setState(0);  
139 - int resultInt = baseMapper.updateById(dataViewInterfaceEntity);  
140 - return resultInt > 0 ; 99 + return baseMapper.deleteBatchIds(deleteDTO.getIds()) > FastIotConstants.MagicNumber.ZERO;
  100 + }
  101 +
  102 + @Override
  103 + public boolean publishInterface(String id, String tenantId) {
  104 + TkDataViewInterfaceEntity dataViewInterfaceEntity = baseMapper.selectById(id);
  105 + if (!dataViewInterfaceEntity.getTenantId().equals(tenantId)) {
  106 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
141 } 107 }
142 -  
143 - @Override  
144 - public List<TkDataViewInterfaceDTO> getInterfaceDetails(List<String> ids) {  
145 - List<TkDataViewInterfaceDTO> lists = baseMapper.getInterfaceDetails(ids);  
146 - return lists; 108 + // Modify interface state is publish
  109 + dataViewInterfaceEntity.setState(1);
  110 + int resultInt = baseMapper.updateById(dataViewInterfaceEntity);
  111 + return resultInt > 0;
  112 + }
  113 +
  114 + @Override
  115 + public boolean cancelPublishInterface(String id, String tenantId) {
  116 + TkDataViewInterfaceEntity dataViewInterfaceEntity = baseMapper.selectById(id);
  117 + if (!dataViewInterfaceEntity.getTenantId().equals(tenantId)) {
  118 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
147 } 119 }
148 -  
149 - @Override  
150 - public List<TkDataViewInterfaceDTO> filterByInterfaceType(String type,String tenantId) {  
151 - List<String> tenantIds = new ArrayList<>();  
152 - tenantIds.add(tenantId);  
153 - tenantIds.add(EntityId.NULL_UUID.toString());  
154 - List<TkDataViewInterfaceDTO> lists = baseMapper.filterByInterfaceType(type,tenantIds);  
155 - return lists; 120 + // Modify interface state is cancelPublish
  121 + dataViewInterfaceEntity.setState(0);
  122 + int resultInt = baseMapper.updateById(dataViewInterfaceEntity);
  123 + return resultInt > 0;
  124 + }
  125 +
  126 + @Override
  127 + public List<TkDataViewInterfaceDTO> getInterfaceDetails(List<String> ids) {
  128 + return baseMapper.getInterfaceDetails(ids);
  129 + }
  130 +
  131 + @Override
  132 + public List<TkDataViewInterfaceDTO> filterByInterfaceType(String type, String tenantId) {
  133 + List<String> tenantIds = new ArrayList<>();
  134 + tenantIds.add(tenantId);
  135 + tenantIds.add(EntityId.NULL_UUID.toString());
  136 + return baseMapper.filterByInterfaceType(type, tenantIds);
  137 + }
  138 +
  139 + @Override
  140 + public List<TkDataViewInterfaceDTO> findAll(String state, String tenantId) {
  141 + List<String> tenantIds = new ArrayList<>();
  142 + tenantIds.add(tenantId);
  143 + tenantIds.add(EntityId.NULL_UUID.toString());
  144 + return baseMapper.findAll(Integer.parseInt(state), tenantIds);
  145 + }
  146 +
  147 + @Override
  148 + public List<TkDataViewInterfaceDTO> findCanUseInterfaces(
  149 + boolean isSysAdminOrPtAdmin, String tenantId) {
  150 + List<TkDataViewInterfaceEntity> entities =
  151 + baseMapper.selectList(
  152 + new LambdaQueryWrapper<TkDataViewInterfaceEntity>()
  153 + .eq(TkDataViewInterfaceEntity::getTenantId, tenantId)
  154 + .eq(TkDataViewInterfaceEntity::getState, StatusEnum.RELEASE.getIndex()));
  155 + // 租户或客户可使用的接口包含,超级管理或平台管理员发布的SYSTEM接口
  156 + if (!isSysAdminOrPtAdmin) {
  157 + List<TkDataViewInterfaceEntity> systemEntities =
  158 + baseMapper.selectList(
  159 + new LambdaQueryWrapper<TkDataViewInterfaceEntity>()
  160 + .eq(TkDataViewInterfaceEntity::getTenantId, UserId.NULL_UUID.toString())
  161 + .eq(TkDataViewInterfaceEntity::getInterfaceType, TkSystemTypeEnum.SYSTEM.name())
  162 + .eq(TkDataViewInterfaceEntity::getState, StatusEnum.RELEASE.getIndex()));
  163 + entities.addAll(systemEntities);
156 } 164 }
157 -  
158 - @Override  
159 - public List<TkDataViewInterfaceDTO> findAll(String state,String tenantId){  
160 - List<String> tenantIds = new ArrayList<>();  
161 - tenantIds.add(tenantId);  
162 - tenantIds.add(EntityId.NULL_UUID.toString());  
163 - List<TkDataViewInterfaceDTO> lists =baseMapper.findAll(Integer.parseInt(state),tenantIds);  
164 - return lists; 165 + return Optional.ofNullable(entities)
  166 + .map(
  167 + entityList ->
  168 + entityList.stream()
  169 + .map(entity -> entity.getDTO(TkDataViewInterfaceDTO.class))
  170 + .collect(Collectors.toList()))
  171 + .orElse(null);
  172 + }
  173 +
  174 + @Override
  175 + public boolean batchPublishInterface(List<String> ids, String tenantId) {
  176 + List<TkDataViewInterfaceEntity> interfaceEntityList =
  177 + baseMapper.selectList(
  178 + new LambdaQueryWrapper<TkDataViewInterfaceEntity>()
  179 + .in(TkDataViewInterfaceEntity::getId, ids));
  180 + for (TkDataViewInterfaceEntity center : interfaceEntityList) {
  181 + if (!center.getTenantId().equals(tenantId)) {
  182 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
  183 + }
165 } 184 }
166 -  
167 -  
168 - @Override  
169 - public boolean batchPublishInterface(List<String> ids, String tenantId) {  
170 - List<TkDataViewInterfaceEntity> interfaceEntityList =  
171 - baseMapper.selectList(  
172 - new LambdaQueryWrapper<TkDataViewInterfaceEntity>()  
173 - .in(TkDataViewInterfaceEntity::getId, ids));  
174 - for (TkDataViewInterfaceEntity center : interfaceEntityList) {  
175 - if (!center.getTenantId().equals(tenantId)) {  
176 - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());  
177 - }  
178 - }  
179 - int resultInt = 0;  
180 - for (TkDataViewInterfaceEntity interfaceEntity : interfaceEntityList) {  
181 - interfaceEntity.setState(1);  
182 - resultInt+=baseMapper.updateById(interfaceEntity);  
183 - }  
184 - return resultInt>0; 185 + int resultInt = 0;
  186 + for (TkDataViewInterfaceEntity interfaceEntity : interfaceEntityList) {
  187 + interfaceEntity.setState(1);
  188 + resultInt += baseMapper.updateById(interfaceEntity);
185 } 189 }
186 -  
187 -  
188 - @Override  
189 - public boolean batchCancelPublishInterface(List<String> ids, String tenantId) {  
190 - List<TkDataViewInterfaceEntity> interfaceEntityList =  
191 - baseMapper.selectList(  
192 - new LambdaQueryWrapper<TkDataViewInterfaceEntity>()  
193 - .in(TkDataViewInterfaceEntity::getId, ids));  
194 - for (TkDataViewInterfaceEntity center : interfaceEntityList) {  
195 - if (!center.getTenantId().equals(tenantId)) {  
196 - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());  
197 - }  
198 - }  
199 - int resultInt = 0;  
200 - for (TkDataViewInterfaceEntity interfaceEntity : interfaceEntityList) {  
201 - interfaceEntity.setState(0);  
202 - resultInt+=baseMapper.updateById(interfaceEntity);  
203 - }  
204 - return resultInt>0; 190 + return resultInt > 0;
  191 + }
  192 +
  193 + @Override
  194 + public boolean batchCancelPublishInterface(List<String> ids, String tenantId) {
  195 + List<TkDataViewInterfaceEntity> interfaceEntityList =
  196 + baseMapper.selectList(
  197 + new LambdaQueryWrapper<TkDataViewInterfaceEntity>()
  198 + .in(TkDataViewInterfaceEntity::getId, ids));
  199 + for (TkDataViewInterfaceEntity center : interfaceEntityList) {
  200 + if (!center.getTenantId().equals(tenantId)) {
  201 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
  202 + }
205 } 203 }
206 -  
207 - @Override  
208 - public List<LinkedHashMap<String, Object>> executeSql(String sql){  
209 - List<LinkedHashMap<String, Object>> resultList = baseMapper.executeSql(sql);  
210 - return resultList; 204 + int resultInt = 0;
  205 + for (TkDataViewInterfaceEntity interfaceEntity : interfaceEntityList) {
  206 + interfaceEntity.setState(0);
  207 + resultInt += baseMapper.updateById(interfaceEntity);
211 } 208 }
  209 + return resultInt > 0;
  210 + }
212 211
  212 + @Override
  213 + public List<LinkedHashMap<String, Object>> executeSql(String sql) {
  214 + return baseMapper.executeSql(sql);
  215 + }
213 } 216 }
@@ -12,28 +12,29 @@ import java.util.Map; @@ -12,28 +12,29 @@ import java.util.Map;
12 */ 12 */
13 public interface TkDataViewInterfaceService { 13 public interface TkDataViewInterfaceService {
14 14
15 - TkPageData<TkDataViewInterfaceDTO> page(Map<String, Object> queryMap); 15 + TkPageData<TkDataViewInterfaceDTO> page(Map<String, Object> queryMap);
16 16
17 - TkDataViewInterfaceDTO saveDataViewInterface(TkDataViewInterfaceDTO tkDataViewInterfaceDTO); 17 + TkDataViewInterfaceDTO saveDataViewInterface(TkDataViewInterfaceDTO tkDataViewInterfaceDTO);
18 18
19 - TkDataViewInterfaceDTO updateDataViewInterface(TkDataViewInterfaceDTO tkDataViewInterfaceDTO); 19 + TkDataViewInterfaceDTO updateDataViewInterface(TkDataViewInterfaceDTO tkDataViewInterfaceDTO);
20 20
21 - boolean deleteDataViewInterface(DeleteDTO deleteDTO); 21 + boolean deleteDataViewInterface(DeleteDTO deleteDTO);
22 22
23 - boolean publishInterface(String id, String tenantId); 23 + boolean publishInterface(String id, String tenantId);
24 24
25 - boolean cancelPublishInterface(String id, String tenantId); 25 + boolean cancelPublishInterface(String id, String tenantId);
26 26
27 - List<TkDataViewInterfaceDTO> getInterfaceDetails(List<String> ids); 27 + List<TkDataViewInterfaceDTO> getInterfaceDetails(List<String> ids);
28 28
29 - List<TkDataViewInterfaceDTO> filterByInterfaceType(String type,String tenantId); 29 + List<TkDataViewInterfaceDTO> filterByInterfaceType(String type, String tenantId);
30 30
31 - List<TkDataViewInterfaceDTO> findAll(String state,String tenantId); 31 + List<TkDataViewInterfaceDTO> findAll(String state, String tenantId);
32 32
33 - boolean batchPublishInterface(List<String> ids, String tenantId); 33 + List<TkDataViewInterfaceDTO> findCanUseInterfaces(boolean isSysAdminOrPtAdmin, String tenantId);
34 34
35 - boolean batchCancelPublishInterface(List<String> ids, String tenantId); 35 + boolean batchPublishInterface(List<String> ids, String tenantId);
36 36
37 - List<LinkedHashMap<String, Object>> executeSql(String sql); 37 + boolean batchCancelPublishInterface(List<String> ids, String tenantId);
38 38
  39 + List<LinkedHashMap<String, Object>> executeSql(String sql);
39 } 40 }
@@ -141,4 +141,11 @@ public interface TkUserService { @@ -141,4 +141,11 @@ public interface TkUserService {
141 */ 141 */
142 UserDTO checkAccount(String userId,Integer level); 142 UserDTO checkAccount(String userId,Integer level);
143 143
  144 + /**
  145 + * 根据租户ID查询所有的租户管理员
  146 + * @param tenantId 租户ID
  147 + * @return 租户管理员列表
  148 + */
  149 + List<UserDTO> findAllTenantAdminsByTenantId(String tenantId);
  150 +
144 } 151 }