Commit 982703953acebdd86da5d489ded03f7e0b39a0e2

Authored by xp.Huang
2 parents facdb01a 9baa7da7

Merge branch 'ljl1207' into 'master'

docs: 设备配置相关接口

See merge request huang/thingsboard3.3.2!9
@@ -52,7 +52,7 @@ public class YtDeviceController extends BaseController { @@ -52,7 +52,7 @@ public class YtDeviceController extends BaseController {
52 private final DeviceService tbDeviceService; 52 private final DeviceService tbDeviceService;
53 53
54 @PostMapping 54 @PostMapping
55 - @ApiOperation("刷新=保存+更新") 55 + @ApiOperation("创建|编辑")
56 public ResponseEntity<DeviceDTO> saveDevice(@Validated(AddGroup.class)@RequestBody DeviceDTO deviceDTO) 56 public ResponseEntity<DeviceDTO> saveDevice(@Validated(AddGroup.class)@RequestBody DeviceDTO deviceDTO)
57 throws ThingsboardException { 57 throws ThingsboardException {
58 String currentTenantId = getCurrentUser().getCurrentTenantId(); 58 String currentTenantId = getCurrentUser().getCurrentTenantId();
@@ -96,11 +96,13 @@ public class YtDeviceController extends BaseController { @@ -96,11 +96,13 @@ public class YtDeviceController extends BaseController {
96 } 96 }
97 97
98 @GetMapping("{id}") 98 @GetMapping("{id}")
  99 + @ApiOperation("详情")
99 public ResponseEntity<DeviceDTO> getDevice(@PathVariable("id") String id) throws ThingsboardException { 100 public ResponseEntity<DeviceDTO> getDevice(@PathVariable("id") String id) throws ThingsboardException {
100 return ResponseEntity.of(deviceService.getDevice(getCurrentUser().getCurrentTenantId(), id)); 101 return ResponseEntity.of(deviceService.getDevice(getCurrentUser().getCurrentTenantId(), id));
101 } 102 }
102 103
103 @GetMapping(params = {PAGE_SIZE, PAGE}) 104 @GetMapping(params = {PAGE_SIZE, PAGE})
  105 + @ApiOperation("查询")
104 public YtPageData<DeviceDTO> pageDevice( 106 public YtPageData<DeviceDTO> pageDevice(
105 @RequestParam(PAGE_SIZE) int pageSize, 107 @RequestParam(PAGE_SIZE) int pageSize,
106 @RequestParam(PAGE) int page, 108 @RequestParam(PAGE) int page,
@@ -133,8 +135,21 @@ public class YtDeviceController extends BaseController { @@ -133,8 +135,21 @@ public class YtDeviceController extends BaseController {
133 } 135 }
134 return deviceService.page(getCurrentUser().getCurrentTenantId(), queryMap); 136 return deviceService.page(getCurrentUser().getCurrentTenantId(), queryMap);
135 } 137 }
  138 + @PostMapping("/import")
  139 + @ApiOperation("导入配置")
  140 + public ResponseEntity<String> importDeviceProfile(){
  141 + //TODO 实现的业务功能
  142 + return ResponseEntity.ok("");
  143 + }
136 144
  145 + @PostMapping("/export")
  146 + @ApiOperation("导出")
  147 + public ResponseEntity<String> exportDeviceProfile(){
  148 + //TODO 实现的业务功能
  149 + return ResponseEntity.ok("");
  150 + }
137 @DeleteMapping 151 @DeleteMapping
  152 + @ApiOperation("删除")
138 public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { 153 public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException {
139 String currentTenantId = getCurrentUser().getCurrentTenantId(); 154 String currentTenantId = getCurrentUser().getCurrentTenantId();
140 List<String> tdIds = deviceService.findTbDeviceId(currentTenantId, deleteDTO.getIds()); 155 List<String> tdIds = deviceService.findTbDeviceId(currentTenantId, deleteDTO.getIds());
@@ -34,6 +34,7 @@ import org.thingsboard.server.dao.yunteng.service.YtDeviceProfileService; @@ -34,6 +34,7 @@ import org.thingsboard.server.dao.yunteng.service.YtDeviceProfileService;
34 import org.thingsboard.server.service.security.permission.Operation; 34 import org.thingsboard.server.service.security.permission.Operation;
35 35
36 import java.net.URI; 36 import java.net.URI;
  37 +import java.sql.ResultSet;
37 import java.time.LocalDateTime; 38 import java.time.LocalDateTime;
38 import java.time.ZoneOffset; 39 import java.time.ZoneOffset;
39 import java.util.*; 40 import java.util.*;
@@ -47,9 +48,9 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. @@ -47,9 +48,9 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.
47 public class YtDeviceProfileController extends BaseController { 48 public class YtDeviceProfileController extends BaseController {
48 private final YtDeviceProfileService ytDeviceProfileService; 49 private final YtDeviceProfileService ytDeviceProfileService;
49 50
50 - @PostMapping 51 + @PostMapping()
51 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") 52 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
52 - @ApiOperation("刷新=保存+更新") 53 + @ApiOperation("创建 | 编辑")
53 public ResponseEntity<DeviceProfileDTO> saveDeviceProfile( 54 public ResponseEntity<DeviceProfileDTO> saveDeviceProfile(
54 @RequestBody DeviceProfileDTO deviceProfileDTO) throws ThingsboardException { 55 @RequestBody DeviceProfileDTO deviceProfileDTO) throws ThingsboardException {
55 56
@@ -61,15 +62,13 @@ public class YtDeviceProfileController extends BaseController { @@ -61,15 +62,13 @@ public class YtDeviceProfileController extends BaseController {
61 * 2/3.处理TB业务逻辑 62 * 2/3.处理TB业务逻辑
62 * 3/3.处理业务平台的业务逻辑 63 * 3/3.处理业务平台的业务逻辑
63 */ 64 */
64 - //TODO 1/3.验证业务平台中表单数据的合法性  
65 65
66 - //TODO 2/3.处理TB业务逻辑  
67 deviceProfileDTO.setTenantId(getCurrentUser().getCurrentTenantId()); 66 deviceProfileDTO.setTenantId(getCurrentUser().getCurrentTenantId());
68 DeviceProfile tbDeviceProfile = buildTbDeviceProfileFromDeviceProfileDTO(deviceProfileDTO); 67 DeviceProfile tbDeviceProfile = buildTbDeviceProfileFromDeviceProfileDTO(deviceProfileDTO);
69 DeviceProfile savedDeviceProfile = updateTbDeviceProfile(tbDeviceProfile, created); 68 DeviceProfile savedDeviceProfile = updateTbDeviceProfile(tbDeviceProfile, created);
70 69
71 70
72 - //TODO 3/3.处理业务平台的业务逻辑 71 +
73 72
74 DeviceProfileDTO newDeviceProfileDTO = ytDeviceProfileService.insertOrUpdate(savedDeviceProfile.getId().getId().toString(), deviceProfileDTO); 73 DeviceProfileDTO newDeviceProfileDTO = ytDeviceProfileService.insertOrUpdate(savedDeviceProfile.getId().getId().toString(), deviceProfileDTO);
75 return Optional.ofNullable(newDeviceProfileDTO) 74 return Optional.ofNullable(newDeviceProfileDTO)
@@ -123,12 +122,14 @@ public class YtDeviceProfileController extends BaseController { @@ -123,12 +122,14 @@ public class YtDeviceProfileController extends BaseController {
123 } 122 }
124 123
125 @GetMapping("{id}") 124 @GetMapping("{id}")
  125 + @ApiOperation("详情")
126 public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id) throws ThingsboardException { 126 public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id) throws ThingsboardException {
127 return ResponseEntity.of(ytDeviceProfileService.getDeviceProfile(getCurrentUser().getCurrentTenantId(), id)); 127 return ResponseEntity.of(ytDeviceProfileService.getDeviceProfile(getCurrentUser().getCurrentTenantId(), id));
128 } 128 }
129 129
130 @GetMapping(params = {PAGE_SIZE, PAGE}) 130 @GetMapping(params = {PAGE_SIZE, PAGE})
131 - public YtPageData<DeviceProfileDTO> pageDevice( 131 + @ApiOperation("查询")
  132 + public YtPageData<DeviceProfileDTO> pageDeviceProfile(
132 @RequestParam(PAGE_SIZE) int pageSize, 133 @RequestParam(PAGE_SIZE) int pageSize,
133 @RequestParam(PAGE) int page, 134 @RequestParam(PAGE) int page,
134 @RequestParam(value = "name", required = false) String name, 135 @RequestParam(value = "name", required = false) String name,
@@ -140,7 +141,15 @@ public class YtDeviceProfileController extends BaseController { @@ -140,7 +141,15 @@ public class YtDeviceProfileController extends BaseController {
140 return ytDeviceProfileService.page(pageLink, getCurrentUser().getCurrentTenantId(), transportType); 141 return ytDeviceProfileService.page(pageLink, getCurrentUser().getCurrentTenantId(), transportType);
141 } 142 }
142 143
  144 + @GetMapping("/me/list")
  145 + @ApiOperation("选项列表")
  146 + public ResponseEntity listDeviceProfile() throws ThingsboardException {
  147 + List<DeviceProfileDTO> results = ytDeviceProfileService.findDeviceProfile(getCurrentUser().getCurrentTenantId());
  148 + return ResponseEntity.ok(results);
  149 + }
  150 +
143 @DeleteMapping 151 @DeleteMapping
  152 + @ApiOperation("删除")
144 public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { 153 public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException {
145 for (String id : deleteDTO.getIds()) { 154 for (String id : deleteDTO.getIds()) {
146 deleteTbDeviceProfile(id); 155 deleteTbDeviceProfile(id);
@@ -163,12 +172,29 @@ public class YtDeviceProfileController extends BaseController { @@ -163,12 +172,29 @@ public class YtDeviceProfileController extends BaseController {
163 sendEntityNotificationMsg(getTenantId(), deviceProfile.getId(), EdgeEventActionType.DELETED); 172 sendEntityNotificationMsg(getTenantId(), deviceProfile.getId(), EdgeEventActionType.DELETED);
164 } 173 }
165 174
166 - @GetMapping("/me")  
167 - public ResponseEntity<List<DeviceProfileDTO>> findCurrentTenantDeviceProfiles() throws ThingsboardException { 175 + @GetMapping("/me/default")
  176 + @ApiOperation("默认设备配置")
  177 + public ResponseEntity<DeviceProfile> findCurrentTenantDeviceProfiles() throws ThingsboardException {
  178 + DeviceProfile result = deviceProfileService.findDefaultDeviceProfile(getCurrentUser().getTenantId());
  179 + return ResponseEntity.ok(result);
  180 + }
  181 +
  182 + @PostMapping("/import")
  183 + @ApiOperation("导入配置")
  184 + public ResponseEntity<String> importDeviceProfile(){
  185 + //TODO 实现的业务功能
  186 + return ResponseEntity.ok("");
  187 + }
168 188
169 - return ResponseEntity.ok(ytDeviceProfileService.findDeviceProfile(getCurrentUser().getCurrentTenantId())); 189 + @PostMapping("/export")
  190 + @ApiOperation("导出")
  191 + public ResponseEntity<String> exportDeviceProfile(){
  192 + //TODO 实现的业务功能
  193 + return ResponseEntity.ok("");
170 } 194 }
171 195
  196 +
  197 +
172 /** 198 /**
173 * 构造调用TBDeviceProfile需要的参数 199 * 构造调用TBDeviceProfile需要的参数
174 * 200 *
1 package org.thingsboard.server.controller.yunteng; 1 package org.thingsboard.server.controller.yunteng;
  2 +import io.swagger.annotations.Api;
  3 +import io.swagger.annotations.ApiOperation;
2 import lombok.RequiredArgsConstructor; 4 import lombok.RequiredArgsConstructor;
3 import org.springframework.http.HttpStatus; 5 import org.springframework.http.HttpStatus;
4 import org.springframework.http.ResponseEntity; 6 import org.springframework.http.ResponseEntity;
@@ -19,6 +21,7 @@ import java.util.Optional; @@ -19,6 +21,7 @@ import java.util.Optional;
19 21
20 @RestController 22 @RestController
21 @RequestMapping("api/yt/organization") 23 @RequestMapping("api/yt/organization")
  24 +@Api(tags = "组织管理")
22 @RequiredArgsConstructor 25 @RequiredArgsConstructor
23 public class YtOrganizationController extends BaseController { 26 public class YtOrganizationController extends BaseController {
24 27
@@ -49,17 +52,19 @@ public class YtOrganizationController extends BaseController { @@ -49,17 +52,19 @@ public class YtOrganizationController extends BaseController {
49 organizationService.deleteOrganizations(deleteDTO, getCurrentUser().getCurrentTenantId())); 52 organizationService.deleteOrganizations(deleteDTO, getCurrentUser().getCurrentTenantId()));
50 } 53 }
51 54
52 - @GetMapping("/me/organizations")  
53 - public List<OrganizationDTO> getMyOrganizations() throws ThingsboardException {  
54 - return organizationService.getMyOrganizations(  
55 - getCurrentUser().isPtTenantAdmin(),  
56 - getCurrentUser().getCurrentTenantId(),  
57 - getCurrentUser().getCurrentUserId()); 55 + @GetMapping("/me/list")
  56 + @ApiOperation("下拉列表")
  57 + public ResponseEntity getMyOrganizations() throws ThingsboardException {
  58 + List<OrganizationDTO> result = organizationService.getMyOrganizations(
  59 + getCurrentUser().isPtTenantAdmin(),
  60 + getCurrentUser().getCurrentTenantId(),
  61 + getCurrentUser().getCurrentUserId());
  62 + return ResponseEntity.ok(result);
58 } 63 }
59 64
60 @PutMapping 65 @PutMapping
61 - public OrganizationDTO updateOrganization(@Validated(UpdateGroup.class) @RequestBody OrganizationDTO groupDTO) throws ThingsboardException {  
62 - return organizationService.updateOrganization(groupDTO, getCurrentUser().getCurrentTenantId()); 66 + public ResponseEntity updateOrganization(@Validated(UpdateGroup.class) @RequestBody OrganizationDTO groupDTO) throws ThingsboardException {
  67 + return ResponseEntity.ok(organizationService.updateOrganization(groupDTO, getCurrentUser().getCurrentTenantId()));
63 } 68 }
64 69
65 @PutMapping("saveOrUpdateUserOrganizationMapping/{userId}") 70 @PutMapping("saveOrUpdateUserOrganizationMapping/{userId}")
  1 +package org.thingsboard.server.controller.yunteng;
  2 +
  3 +import io.swagger.annotations.Api;
  4 +import io.swagger.annotations.ApiOperation;
  5 +import lombok.RequiredArgsConstructor;
  6 +import org.apache.commons.lang3.StringUtils;
  7 +import org.springframework.http.HttpStatus;
  8 +import org.springframework.http.ResponseEntity;
  9 +import org.springframework.security.access.prepost.PreAuthorize;
  10 +import org.springframework.validation.annotation.Validated;
  11 +import org.springframework.web.bind.annotation.*;
  12 +import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
  13 +import org.thingsboard.server.common.data.DeviceProfile;
  14 +import org.thingsboard.server.common.data.DeviceProfileProvisionType;
  15 +import org.thingsboard.server.common.data.DeviceProfileType;
  16 +import org.thingsboard.server.common.data.DeviceTransportType;
  17 +import org.thingsboard.server.common.data.audit.ActionType;
  18 +import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
  19 +import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration;
  20 +import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
  21 +import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration;
  22 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
  23 +import org.thingsboard.server.common.data.exception.ThingsboardException;
  24 +import org.thingsboard.server.common.data.id.DeviceProfileId;
  25 +import org.thingsboard.server.common.data.id.RuleChainId;
  26 +import org.thingsboard.server.common.data.id.TenantId;
  27 +import org.thingsboard.server.common.data.page.PageLink;
  28 +import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
  29 +import org.thingsboard.server.common.data.rule.RuleChain;
  30 +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
  31 +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
  32 +import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO;
  33 +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum;
  34 +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
  35 +import org.thingsboard.server.common.msg.queue.ServiceQueue;
  36 +import org.thingsboard.server.controller.BaseController;
  37 +import org.thingsboard.server.dao.rule.RuleChainService;
  38 +import org.thingsboard.server.dao.yunteng.service.YtDeviceProfileService;
  39 +import org.thingsboard.server.service.security.permission.Operation;
  40 +
  41 +import java.net.URI;
  42 +import java.time.LocalDateTime;
  43 +import java.time.ZoneOffset;
  44 +import java.util.List;
  45 +import java.util.Objects;
  46 +import java.util.Optional;
  47 +import java.util.UUID;
  48 +
  49 +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
  50 +
  51 +@RestController
  52 +@RequiredArgsConstructor
  53 +@RequestMapping("api/yt/rulechain")
  54 +@Api(tags = {"规则链管理"})
  55 +public class YtRuleChainController extends BaseController {
  56 + private final RuleChainService chainService;
  57 +
  58 +
  59 +
  60 +
  61 +
  62 + @GetMapping("/me/list")
  63 + @ApiOperation("下拉列表")
  64 + public ResponseEntity listDeviceProfile() throws ThingsboardException {
  65 + TenantId tenantId = getCurrentUser().getTenantId();
  66 + return ResponseEntity.ok(chainService.getRootTenantRuleChain(tenantId));
  67 + }
  68 +
  69 +
  70 +}