Commit e61d92046f38f01e598f799a2bb12b12cb3cba2d

Authored by xp.Huang
1 parent 2f57617d

feat: 新增数据看板、组态、大屏设计器的分享

Showing 30 changed files with 821 additions and 264 deletions
... ... @@ -57,8 +57,11 @@ import org.thingsboard.server.common.data.rule.RuleNode;
57 57 import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
58 58 import org.thingsboard.server.common.data.widget.WidgetsBundle;
59 59 import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
  60 +import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils;
60 61 import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
61 62 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
  63 +import org.thingsboard.server.common.data.yunteng.dto.PublicCustomerDTO;
  64 +import org.thingsboard.server.common.data.yunteng.enums.ViewType;
62 65 import org.thingsboard.server.dao.asset.AssetService;
63 66 import org.thingsboard.server.dao.attributes.AttributesService;
64 67 import org.thingsboard.server.dao.audit.AuditLogService;
... ... @@ -242,6 +245,10 @@ public abstract class BaseController {
242 245 @Getter
243 246 protected boolean edgesEnabled;
244 247
  248 + //thingskit
  249 + @Autowired
  250 + private CacheUtils cacheUtils;
  251 +
245 252 @ExceptionHandler(ThingsboardException.class)
246 253 public void handleThingsboardException(ThingsboardException ex, HttpServletResponse response) {
247 254 errorResponseHandler.handle(ex, response);
... ... @@ -950,4 +957,27 @@ public abstract class BaseController {
950 957 getTenantId(), savedDeviceProfile.getId(), EdgeEventActionType.UPDATED);
951 958 return savedDeviceProfile;
952 959 }
  960 +
  961 + /**
  962 + * 获取租户的公共ID并设置缓存
  963 + * @param tenantId 租户ID
  964 + * @return 公共ID
  965 + */
  966 + private String findPublicCustomerId(TenantId tenantId){
  967 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  968 + String cacheKey =
  969 + FastIotConstants.CacheConfigKey.PUBLIC_ID + tenantId.getId().toString();
  970 + Optional<String> publicId = cacheUtils.get(cacheKey);
  971 + return publicId.orElseGet(
  972 + () -> Optional.ofNullable(customerService.findOrCreatePublicCustomer(tenantId)).
  973 + map(customer -> customer.getId().getId().toString()).orElse(null));
  974 + }
  975 +
  976 + protected void setPublicCustomerIdToCache(PublicCustomerDTO dto) throws ThingsboardException {
  977 + String publicCustomerId = findPublicCustomerId(getTenantId());
  978 + if (Objects.equals(dto.getViewType(), ViewType.PUBLIC_VIEW)
  979 + && !StringUtils.isEmpty(publicCustomerId)) {
  980 + dto.setPublicId(publicCustomerId);
  981 + }
  982 + }
953 983 }
... ...
... ... @@ -8,10 +8,13 @@ import org.springframework.http.ResponseEntity;
8 8 import org.springframework.security.access.prepost.PreAuthorize;
9 9 import org.springframework.validation.annotation.Validated;
10 10 import org.springframework.web.bind.annotation.*;
  11 +import org.thingsboard.server.common.data.Customer;
11 12 import org.thingsboard.server.common.data.exception.ThingsboardException;
12 13 import org.thingsboard.server.common.data.yunteng.common.AddGroup;
13 14 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
14 15 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
  16 +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
  17 +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
15 18 import org.thingsboard.server.common.data.yunteng.dto.ConfigurationCenterDTO;
16 19 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
17 20 import org.thingsboard.server.common.data.yunteng.dto.request.ConfigurationContentInfoDTO;
... ... @@ -31,7 +34,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.
31 34 @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")
32 35 public class TkConfigurationCenterController extends BaseController {
33 36
34   - private final TkConfigurationCenterService ytConfigurationCenterService;
  37 + private final TkConfigurationCenterService tkConfigurationCenterService;
35 38
36 39 @GetMapping(params = {PAGE_SIZE, PAGE})
37 40 @ApiOperation("分页")
... ... @@ -62,8 +65,15 @@ public class TkConfigurationCenterController extends BaseController {
62 65 if (null != orderType) {
63 66 queryMap.put(ORDER_TYPE, orderType.name());
64 67 }
65   - queryMap.put("userId",getCurrentUser().getCurrentUserId());
66   - return ytConfigurationCenterService.page(queryMap, getCurrentUser().isTenantAdmin());
  68 + queryMap.put("userId", getCurrentUser().getCurrentUserId());
  69 + TkPageData<ConfigurationCenterDTO> pageData =
  70 + tkConfigurationCenterService.page(queryMap, getCurrentUser().isTenantAdmin());
  71 + if (!pageData.getItems().isEmpty()) {
  72 + for (ConfigurationCenterDTO dto : pageData.getItems()) {
  73 + setPublicCustomerIdToCache(dto);
  74 + }
  75 + }
  76 + return pageData;
67 77 }
68 78
69 79 @PostMapping
... ... @@ -75,7 +85,7 @@ public class TkConfigurationCenterController extends BaseController {
75 85 throws ThingsboardException {
76 86 configurationCenterDTO.setTenantId(getCurrentUser().getCurrentTenantId());
77 87 return ResponseEntity.ok(
78   - ytConfigurationCenterService.saveConfiguration(configurationCenterDTO));
  88 + tkConfigurationCenterService.saveConfiguration(configurationCenterDTO));
79 89 }
80 90
81 91 @PutMapping
... ... @@ -87,7 +97,7 @@ public class TkConfigurationCenterController extends BaseController {
87 97 throws ThingsboardException {
88 98 configurationCenterDTO.setTenantId(getCurrentUser().getCurrentTenantId());
89 99 return ResponseEntity.ok(
90   - ytConfigurationCenterService.updateConfiguration(configurationCenterDTO));
  100 + tkConfigurationCenterService.updateConfiguration(configurationCenterDTO));
91 101 }
92 102
93 103 @DeleteMapping
... ... @@ -98,17 +108,34 @@ public class TkConfigurationCenterController extends BaseController {
98 108 @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)
99 109 throws ThingsboardException {
100 110 deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId());
101   - return ResponseEntity.ok(ytConfigurationCenterService.deleteConfigurationCenter(deleteDTO));
  111 + return ResponseEntity.ok(tkConfigurationCenterService.deleteConfigurationCenter(deleteDTO));
102 112 }
103 113
104 114 @GetMapping("/get_configuration_info/{id}")
105 115 @ApiOperation("获取组态信息")
106 116 @PreAuthorize(
107   - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:configuration:center:get_configuration_info:design','api:yt:configuration:center:get_configuration_info:preview'})")
  117 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:configuration:center:get_configuration_info:design'"
  118 + + ",'api:yt:configuration:center:get_configuration_info:preview'})")
108 119 public ResponseEntity<ConfigurationContentInfoDTO> getConfigurationInfos(
109 120 @PathVariable("id") String id) throws ThingsboardException {
110 121 return ResponseEntity.ok(
111   - ytConfigurationCenterService.getConfigurationInfos(
  122 + tkConfigurationCenterService.getConfigurationInfos(
112 123 id, getCurrentUser().getCurrentTenantId()));
113 124 }
  125 +
  126 + @PostMapping("share/{id}")
  127 + @ApiOperation("分享")
  128 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:configuration:center:share'})")
  129 + public ResponseEntity<Boolean> share(
  130 + @PathVariable("id") String id,
  131 + @RequestParam(value = "accessCredentials", required = false) String accessCredentials,
  132 + @RequestParam(value = "isShare") boolean isShare)
  133 + throws ThingsboardException {
  134 + if (StringUtils.isEmpty(id)) {
  135 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  136 + }
  137 + return ResponseEntity.ok(
  138 + tkConfigurationCenterService.shareOrMonopolyConfigurationCenter(
  139 + isShare, id, accessCredentials, getCurrentUser().getCurrentTenantId()));
  140 + }
114 141 }
... ...
... ... @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiOperation;
5 5 import lombok.RequiredArgsConstructor;
6 6 import org.apache.commons.lang3.StringUtils;
7 7 import org.quartz.SchedulerException;
  8 +import org.springframework.http.ResponseEntity;
8 9 import org.springframework.security.access.prepost.PreAuthorize;
9 10 import org.springframework.validation.annotation.Validated;
10 11 import org.springframework.web.bind.annotation.*;
... ... @@ -23,9 +24,7 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
23 24 import org.thingsboard.server.controller.BaseController;
24 25 import org.thingsboard.server.dao.yunteng.service.TkDataBoardService;
25 26
26   -import java.util.HashMap;
27   -import java.util.List;
28   -import java.util.Map;
  27 +import java.util.*;
29 28
30 29 import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
31 30
... ... @@ -35,7 +34,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.
35 34 @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")
36 35 @Api(tags = {"数据看板"})
37 36 public class TkDataBoardController extends BaseController {
38   - private final TkDataBoardService ytDataBoardService;
  37 + private final TkDataBoardService tkDataBoardService;
39 38
40 39 @GetMapping(params = {PAGE_SIZE, PAGE})
41 40 @ApiOperation("分页查询")
... ... @@ -59,22 +58,31 @@ public class TkDataBoardController extends BaseController {
59 58 if (StringUtils.isNotBlank(name)) {
60 59 queryMap.put("name", name);
61 60 }
62   - queryMap.put("userId",getCurrentUser().getCurrentUserId());
63   - return ytDataBoardService.dataBoardPage(queryMap, getCurrentUser().isTenantAdmin());
  61 + queryMap.put("userId", getCurrentUser().getCurrentUserId());
  62 + TkPageData<DataBoardDTO> pageData =
  63 + tkDataBoardService.dataBoardPage(queryMap, getCurrentUser().isTenantAdmin());
  64 + if(!pageData.getItems().isEmpty()){
  65 + for (DataBoardDTO dto : pageData.getItems()) {
  66 + setPublicCustomerIdToCache(dto);
  67 + }
  68 + }
  69 + return pageData;
64 70 }
65 71
66 72 @DeleteMapping
67 73 @ApiOperation(value = "删除数据看板")
68   - @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_board:delete'})")
  74 + @PreAuthorize(
  75 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_board:delete'})")
69 76 public ResponseResult<Boolean> deleteDataBoard(
70 77 @Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException {
71 78 deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId());
72   - return ResponseResult.success(ytDataBoardService.deleteDataBoard(deleteDTO));
  79 + return ResponseResult.success(tkDataBoardService.deleteDataBoard(deleteDTO));
73 80 }
74 81
75 82 @PostMapping("/add")
76 83 @ApiOperation(value = "新增数据看板")
77   - @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_board:add:post'})")
  84 + @PreAuthorize(
  85 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_board:add:post'})")
78 86 public ResponseResult<DataBoardDTO> save(
79 87 @RequestBody @Validated(AddGroup.class) DataBoardDTO dataBoard)
80 88 throws SchedulerException, ThingsboardException {
... ... @@ -85,7 +93,8 @@ public class TkDataBoardController extends BaseController {
85 93 }
86 94
87 95 @PostMapping("/update")
88   - @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_board:update:update'})")
  96 + @PreAuthorize(
  97 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_board:update:update'})")
89 98 @ApiOperation(value = "编辑数据看板")
90 99 public ResponseResult<DataBoardDTO> update(
91 100 @RequestBody @Validated(UpdateGroup.class) DataBoardDTO dataBoard)
... ... @@ -102,13 +111,29 @@ public class TkDataBoardController extends BaseController {
102 111 @PathVariable("boardId") String boardId, @RequestBody List<ComponentLayoutDTO> layoutDTOList)
103 112 throws ThingsboardException {
104 113 return ResponseResult.success(
105   - ytDataBoardService.saveComponentLayout(
  114 + tkDataBoardService.saveComponentLayout(
106 115 layoutDTOList, boardId, getCurrentUser().getCurrentTenantId()));
107 116 }
108 117
  118 + @PostMapping("share/{id}")
  119 + @ApiOperation("分享")
  120 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:data_board:share'})")
  121 + public ResponseEntity<Boolean> share(
  122 + @PathVariable("id") String id,
  123 + @RequestParam(value = "accessCredentials", required = false) String accessCredentials,
  124 + @RequestParam(value = "isShare") boolean isShare)
  125 + throws ThingsboardException {
  126 + if (StringUtils.isEmpty(id)) {
  127 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  128 + }
  129 + return ResponseEntity.ok(
  130 + tkDataBoardService.shareOrMonopolyDataBoard(
  131 + isShare, id, accessCredentials, getCurrentUser().getCurrentTenantId()));
  132 + }
  133 +
109 134 private ResponseResult<DataBoardDTO> saveOrUpdate(DataBoardDTO dataBoard)
110 135 throws ThingsboardException {
111 136 dataBoard.setTenantId(getCurrentUser().getCurrentTenantId());
112   - return ResponseResult.success(ytDataBoardService.saveOrUpdateDataBoard(dataBoard));
  137 + return ResponseResult.success(tkDataBoardService.saveOrUpdateDataBoard(dataBoard));
113 138 }
114 139 }
... ...
... ... @@ -12,6 +12,8 @@ import org.thingsboard.server.common.data.exception.ThingsboardException;
12 12 import org.thingsboard.server.common.data.yunteng.common.AddGroup;
13 13 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
14 14 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
  15 +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
  16 +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
15 17 import org.thingsboard.server.common.data.yunteng.dto.TkDataViewDTO;
16 18 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
17 19 import org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentInfoDTO;
... ... @@ -31,103 +33,125 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.
31 33 @RequestMapping("/api/yt/data_view")
32 34 @RequiredArgsConstructor
33 35 @Api(tags = "大屏设计器")
34   -@PreAuthorize("@check.checkPermissions({},{})")
  36 +@PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")
35 37 public class TkDataViewController extends BaseController {
36 38
37   - private final TkDataViewService tkDataViewService;
  39 + private final TkDataViewService tkDataViewService;
38 40
39   - @GetMapping(params = {PAGE_SIZE, PAGE})
40   - @ApiOperation("分页")
41   - public TkPageData<TkDataViewDTO> page(
42   - @RequestParam(PAGE_SIZE) int pageSize,
43   - @RequestParam(PAGE) int page,
44   - @RequestParam(value = "name", required = false) String name,
45   - @RequestParam(value = "state", required = false) String state,
46   - @RequestParam(value = "organizationId", required = false) String organizationId,
47   - @RequestParam(value = ORDER_FILED, required = false) String orderBy,
48   - @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
49   - throws ThingsboardException {
  41 + @GetMapping(params = {PAGE_SIZE, PAGE})
  42 + @ApiOperation("分页")
  43 + public TkPageData<TkDataViewDTO> page(
  44 + @RequestParam(PAGE_SIZE) int pageSize,
  45 + @RequestParam(PAGE) int page,
  46 + @RequestParam(value = "name", required = false) String name,
  47 + @RequestParam(value = "state", required = false) String state,
  48 + @RequestParam(value = "organizationId", required = false) String organizationId,
  49 + @RequestParam(value = ORDER_FILED, required = false) String orderBy,
  50 + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
  51 + throws ThingsboardException {
50 52
51   - HashMap<String, Object> queryMap = new HashMap<>();
52   - queryMap.put(PAGE_SIZE, pageSize);
53   - queryMap.put(PAGE, page);
54   - queryMap.put(ORDER_FILED, orderBy);
55   - queryMap.put("tenantId", getCurrentUser().getCurrentTenantId());
56   - if (StringUtils.isNotBlank(name)) {
57   - queryMap.put("name", name);
58   - }
59   - if (StringUtils.isNotBlank(organizationId)) {
60   - queryMap.put("organizationId", organizationId);
61   - }
62   - if (StringUtils.isNotBlank(state)) {
63   - queryMap.put("state", state);
64   - }
65   - if (null != orderType) {
66   - queryMap.put(ORDER_TYPE, orderType.name());
67   - }
68   - queryMap.put("userId", getCurrentUser().getCurrentUserId());
69   - return tkDataViewService.page(queryMap, getCurrentUser().isTenantAdmin());
  53 + HashMap<String, Object> queryMap = new HashMap<>();
  54 + queryMap.put(PAGE_SIZE, pageSize);
  55 + queryMap.put(PAGE, page);
  56 + queryMap.put(ORDER_FILED, orderBy);
  57 + queryMap.put("tenantId", getCurrentUser().getCurrentTenantId());
  58 + if (StringUtils.isNotBlank(name)) {
  59 + queryMap.put("name", name);
70 60 }
71   -
72   - @PostMapping
73   - @ApiOperation("新增")
74   - @PreAuthorize(
75   - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:post'})")
76   - public ResponseEntity<TkDataViewDTO> save(
77   - @Validated({AddGroup.class}) @RequestBody TkDataViewDTO TkDataViewDTO)
78   - throws ThingsboardException {
79   - TkDataViewDTO.setTenantId(getCurrentUser().getCurrentTenantId());
80   - return ResponseEntity.ok(
81   - tkDataViewService.saveDataView(TkDataViewDTO));
  61 + if (StringUtils.isNotBlank(organizationId)) {
  62 + queryMap.put("organizationId", organizationId);
82 63 }
83   -
84   - @PutMapping
85   - @ApiOperation("修改")
86   - @PreAuthorize(
87   - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:update'})")
88   - public ResponseEntity<TkDataViewDTO> update(
89   - @Validated({UpdateGroup.class}) @RequestBody TkDataViewDTO TkDataViewDTO)
90   - throws ThingsboardException {
91   - TkDataViewDTO.setTenantId(getCurrentUser().getCurrentTenantId());
92   - return ResponseEntity.ok(
93   - tkDataViewService.updateDataView(TkDataViewDTO));
  64 + if (StringUtils.isNotBlank(state)) {
  65 + queryMap.put("state", state);
94 66 }
95   -
96   - @DeleteMapping
97   - @ApiOperation("删除")
98   - @PreAuthorize(
99   - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:delete'})")
100   - public ResponseEntity<Boolean> delete(
101   - @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)
102   - throws ThingsboardException {
103   - deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId());
104   - return ResponseEntity.ok(tkDataViewService.deleteDataView(deleteDTO));
  67 + if (null != orderType) {
  68 + queryMap.put(ORDER_TYPE, orderType.name());
105 69 }
106   -
107   - @GetMapping("/get_configuration_info/{id}")
108   - @ApiOperation("获取大屏信息")
109   - @PreAuthorize(
110   - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:get_dataview_info:design','api:yt:dataview:center:get_dataview_info:preview'})")
111   - public ResponseEntity<TkDataViewContentInfoDTO> getConfigurationInfos(
112   - @PathVariable("id") String id) throws ThingsboardException {
113   - return ResponseEntity.ok(
114   - tkDataViewService.getDataViewInfos(
115   - id, getCurrentUser().getCurrentTenantId()));
  70 + 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()){
  74 + setPublicCustomerIdToCache(dto);
  75 + }
116 76 }
  77 + return pageData;
  78 + }
117 79
118   - @GetMapping("/publish/{id}")
119   - @ApiOperation("发布")
120   - @PreAuthorize("@check.checkPermissions({},{})")
121   - public ResponseEntity<Boolean> publishDataView(@PathVariable("id") String id) throws ThingsboardException {
122   - return ResponseEntity.ok(
123   - tkDataViewService.publishDataView(id, getCurrentUser().getCurrentTenantId()));
124   - }
  80 + @PostMapping
  81 + @ApiOperation("新增")
  82 + @PreAuthorize(
  83 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:post'})")
  84 + public ResponseEntity<TkDataViewDTO> save(
  85 + @Validated({AddGroup.class}) @RequestBody TkDataViewDTO TkDataViewDTO)
  86 + throws ThingsboardException {
  87 + TkDataViewDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  88 + return ResponseEntity.ok(tkDataViewService.saveDataView(TkDataViewDTO));
  89 + }
  90 +
  91 + @PutMapping
  92 + @ApiOperation("修改")
  93 + @PreAuthorize(
  94 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:update'})")
  95 + public ResponseEntity<TkDataViewDTO> update(
  96 + @Validated({UpdateGroup.class}) @RequestBody TkDataViewDTO TkDataViewDTO)
  97 + throws ThingsboardException {
  98 + TkDataViewDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  99 + return ResponseEntity.ok(tkDataViewService.updateDataView(TkDataViewDTO));
  100 + }
  101 +
  102 + @DeleteMapping
  103 + @ApiOperation("删除")
  104 + @PreAuthorize(
  105 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:delete'})")
  106 + public ResponseEntity<Boolean> delete(
  107 + @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)
  108 + throws ThingsboardException {
  109 + deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  110 + return ResponseEntity.ok(tkDataViewService.deleteDataView(deleteDTO));
  111 + }
  112 +
  113 + @GetMapping("/get_configuration_info/{id}")
  114 + @ApiOperation("获取大屏信息")
  115 + @PreAuthorize(
  116 + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:dataview:center:get_dataview_info:design',"
  117 + + "'api:yt:dataview:center:get_dataview_info:preview'})")
  118 + public ResponseEntity<TkDataViewContentInfoDTO> getConfigurationInfos(
  119 + @PathVariable("id") String id) throws ThingsboardException {
  120 + return ResponseEntity.ok(
  121 + tkDataViewService.getDataViewInfos(id, getCurrentUser().getCurrentTenantId()));
  122 + }
  123 +
  124 + @GetMapping("/publish/{id}")
  125 + @ApiOperation("发布")
  126 + @PreAuthorize("@check.checkPermissions({},{})")
  127 + public ResponseEntity<Boolean> publishDataView(@PathVariable("id") String id)
  128 + throws ThingsboardException {
  129 + return ResponseEntity.ok(
  130 + tkDataViewService.publishDataView(id, getCurrentUser().getCurrentTenantId()));
  131 + }
  132 +
  133 + @GetMapping("/cancel_publish/{id}")
  134 + @ApiOperation("取消发布")
  135 + @PreAuthorize("@check.checkPermissions({},{})")
  136 + public ResponseEntity<Boolean> cancelPublishDataView(@PathVariable("id") String id)
  137 + throws ThingsboardException {
  138 + return ResponseEntity.ok(
  139 + tkDataViewService.cancelPublishDataView(id, getCurrentUser().getCurrentTenantId()));
  140 + }
125 141
126   - @GetMapping("/cancel_publish/{id}")
127   - @ApiOperation("取消发布")
128   - @PreAuthorize("@check.checkPermissions({},{})")
129   - public ResponseEntity<Boolean> cancelPublishDataView(@PathVariable("id") String id) throws ThingsboardException {
130   - return ResponseEntity.ok(
131   - tkDataViewService.cancelPublishDataView(id, getCurrentUser().getCurrentTenantId()));
  142 + @PostMapping("share/{id}")
  143 + @ApiOperation("分享")
  144 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:dataview:center:share'})")
  145 + public ResponseEntity<Boolean> share(
  146 + @PathVariable("id") String id,
  147 + @RequestParam(value = "accessCredentials", required = false) String accessCredentials,
  148 + @RequestParam(value = "isShare") boolean isShare)
  149 + throws ThingsboardException {
  150 + if (StringUtils.isEmpty(id)) {
  151 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
132 152 }
  153 + return ResponseEntity.ok(
  154 + tkDataViewService.shareOrMonopolyDataViewCenter(
  155 + isShare, id, accessCredentials, getCurrentUser().getCurrentTenantId()));
  156 + }
133 157 }
... ...
  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.springframework.web.bind.annotation.*;
  7 +import org.thingsboard.server.common.data.StringUtils;
  8 +import org.thingsboard.server.common.data.exception.ThingsboardException;
  9 +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
  10 +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
  11 +import org.thingsboard.server.common.data.yunteng.enums.ShareViewType;
  12 +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult;
  13 +import org.thingsboard.server.controller.BaseController;
  14 +import org.thingsboard.server.dao.yunteng.service.TkShareViewService;
  15 +
  16 +@RestController
  17 +@RequiredArgsConstructor
  18 +@RequestMapping("api/yt/share")
  19 +@Api(tags = {"分享的视图"})
  20 +public class TkShareViewController extends BaseController {
  21 + private final TkShareViewService tkShareViewService;
  22 +
  23 + @GetMapping("/check/{type}/{viewId}")
  24 + @ApiOperation(value = "检查分享视图是否需要访问凭证")
  25 + public ResponseResult<Boolean> checkPublicViewNeedCredentials(
  26 + @PathVariable("type") ShareViewType type, @PathVariable("viewId") String viewId)
  27 + throws ThingsboardException {
  28 + if (StringUtils.isEmpty(viewId)) {
  29 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  30 + }
  31 + return ResponseResult.success(
  32 + tkShareViewService.checkPublicViewNeedCredentials(
  33 + type, viewId, getCurrentUser().getCurrentTenantId()));
  34 + }
  35 +
  36 + @GetMapping("/{share_view_type}/share_data/{id}")
  37 + @ApiOperation(value = "查看分享的数据")
  38 + public ResponseResult<Object> viewDataComponentsByBoardId(
  39 + @PathVariable("id") String id,
  40 + @PathVariable("share_view_type") ShareViewType shareViewType,
  41 + @RequestParam(value = "accessCredentials",required = false) String accessCredentials)
  42 + throws ThingsboardException {
  43 + if (StringUtils.isEmpty(id) || null == shareViewType) {
  44 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  45 + }
  46 + return ResponseResult.success(
  47 + tkShareViewService.viewShareDataById(
  48 + shareViewType, id, accessCredentials, getCurrentUser().getCurrentTenantId()));
  49 + }
  50 +}
... ...
... ... @@ -19,13 +19,17 @@ public interface FastIotConstants {
19 19 Pattern EMAIL_PATTERN = Pattern.compile(EMAIL, Pattern.CASE_INSENSITIVE);
20 20 Pattern CHINA_MOBILE_PATTERN = Pattern.compile(MOBILE);
21 21 String DEFAULT_DELIMITER = "#";
  22 + String RPC_COMMAND = "rpcCommand";
  23 +
22 24 interface CacheConfigKey {
23 25 String CACHE_CONFIG_KEY = "yunTengIotCache";
24 26 String USER_PERMISSION_PREFIX = "userPermissionFor_";
25 27 String MOBILE_LOGIN_SMS_CODE = "mobileLoginSmsCode";
26   -
27 28 String AREA = "thingsArea";
  29 + String PUBLIC_ID = "publicId_";
  30 + String TASK_CENTER_INFOS = "taskCenterInfos_";
28 31 }
  32 +
29 33 interface TBCacheConfig {
30 34 String TB_CACHE_CONFIG_KEY = "TB_CONNECT_CACHE";
31 35 String EXISTING_TENANT = "EXISTING_TENANT";
... ... @@ -48,7 +52,6 @@ public interface FastIotConstants {
48 52 int DRAFT = 0;
49 53 }
50 54
51   -
52 55 interface ConfigureLevel {
53 56 String CONFIGURE = "CONFIGURE";
54 57 String CONTENT = "CONTENT";
... ... @@ -130,6 +133,12 @@ public interface FastIotConstants {
130 133 /** 在线 */
131 134 public static final int ONLINE = 1;
132 135
  136 + /** 发布 */
  137 + public static final int PUBLISH = 1;
  138 +
  139 + /** 取消发布 */
  140 + public static final int CANCEL_PUBLISH = 0;
  141 +
133 142 /** 删除成功 */
134 143 public static final String DELETE_SUCCESS = "删除成功";
135 144
... ...
... ... @@ -2,13 +2,14 @@ package org.thingsboard.server.common.data.yunteng.core.cache;
2 2 import org.springframework.cache.Cache;
3 3 import org.springframework.cache.CacheManager;
4 4 import org.springframework.stereotype.Component;
  5 +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
5 6 import java.util.Objects;
6 7 import java.util.Optional;
7 8
8 9 @Component
9 10 public class CacheUtils {
10 11
11   - private final String COMMON_STORE_AREA = "yun-teng-iot-common";
  12 + private final String COMMON_STORE_AREA = FastIotConstants.CacheConfigKey.CACHE_CONFIG_KEY;
12 13
13 14 private final CacheManager cacheManager;
14 15
... ...
... ... @@ -89,6 +89,11 @@ public enum ErrorMessage {
89 89 INVALID_TOPIC(400065,"无效Topic。"),
90 90 BUCKET_NOT_CONFORM_RENAME_RULE(400066,"存储桶不符合命名规范!!"),
91 91 MINIO_KEY_AND_SIGNATURE_ERROR(400067,"Minio签名不匹配!!"),
  92 + CURRENT_VIEW_IS_PRIVATE(400068,"当前视图为私有视图,拒绝访问!"),
  93 + CURRENT_URL_REQUIRES_PERMISSION(400069,"当前视图需要访问凭证或凭证验证失败!"),
  94 + SHARE_VIEW_TYPE_NOT_EXIST(400070,"分享视图类型不存在"),
  95 + DATA_STATE_ENABLE_NOT_DELETE(400071,"【%s】数据为启用状态不能删除!!"),
  96 + EXECUTE_COMMAND_IS_NULL(400072,"执行命令不能为空"),
92 97 HAVE_NO_PERMISSION(500002,"没有修改权限");
93 98 private final int code;
94 99 private String message;
... ...
... ... @@ -10,7 +10,7 @@ import javax.validation.constraints.NotEmpty;
10 10
11 11 @EqualsAndHashCode(callSuper = true)
12 12 @Data
13   -public class ConfigurationCenterDTO extends TenantDTO {
  13 +public class ConfigurationCenterDTO extends PublicCustomerDTO {
14 14 @ApiModelProperty(value = "组态名称", required = true)
15 15 @NotEmpty(
16 16 message = "组态名称不能为空或空字符串",
... ...
... ... @@ -5,14 +5,13 @@ import lombok.Data;
5 5 import lombok.EqualsAndHashCode;
6 6 import org.thingsboard.server.common.data.yunteng.common.AddGroup;
7 7 import org.thingsboard.server.common.data.yunteng.dto.board.ComponentLayoutDTO;
8   -import org.thingsboard.server.common.data.yunteng.enums.ViewType;
9 8
10 9 import javax.validation.constraints.NotEmpty;
11 10 import java.util.List;
12 11
13 12 @EqualsAndHashCode(callSuper = true)
14 13 @Data
15   -public class DataBoardDTO extends TenantDTO {
  14 +public class DataBoardDTO extends PublicCustomerDTO {
16 15 @ApiModelProperty(value = "数据看板名称", required = true)
17 16 @NotEmpty(message = "数据看板名称不能为空或者空字符串", groups = AddGroup.class)
18 17 private String name;
... ... @@ -21,9 +20,6 @@ public class DataBoardDTO extends TenantDTO {
21 20 @NotEmpty(message = "组织ID不能为空或者空字符串", groups = AddGroup.class)
22 21 private String organizationId;
23 22
24   - @ApiModelProperty(value = "视图类型")
25   - private ViewType viewType = ViewType.PRIVATE_VIEW;
26   -
27 23 @ApiModelProperty(value = "组件布局")
28 24 private List<ComponentLayoutDTO> layout;
29 25
... ...
... ... @@ -121,6 +121,8 @@ public class DeviceDTO extends TenantDTO {
121 121 @ApiModelProperty(value = "启用/禁用")
122 122 private boolean enable;
123 123
  124 + private JsonNode customerAdditionalInfo;
  125 +
124 126 public DeviceState getDeviceState() {
125 127 if (lastOnlineTime == null) {
126 128 return DeviceState.INACTIVE;
... ...
  1 +package org.thingsboard.server.common.data.yunteng.dto;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +import org.thingsboard.server.common.data.yunteng.enums.ViewType;
  6 +
  7 +@Data
  8 +public class PublicCustomerDTO extends TenantDTO {
  9 + @ApiModelProperty(value = "分享公共ID")
  10 + private String publicId;
  11 +
  12 + @ApiModelProperty(value = "视图类型")
  13 + private ViewType viewType = ViewType.PRIVATE_VIEW;
  14 +
  15 + @ApiModelProperty(value = "访问凭证")
  16 + private String accessCredentials;
  17 +}
... ...
... ... @@ -11,33 +11,27 @@ import javax.validation.constraints.NotEmpty;
11 11
12 12 @EqualsAndHashCode(callSuper = true)
13 13 @Data
14   -public class TkDataViewDTO extends TenantDTO {
15   - @ApiModelProperty(value = "大屏名称", required = true)
16   - @NotEmpty(
17   - message = "大屏名称不能为空或空字符串",
18   - groups = {UpdateGroup.class, AddGroup.class})
19   - private String name;
  14 +public class TkDataViewDTO extends PublicCustomerDTO {
  15 + @ApiModelProperty(value = "大屏名称", required = true)
  16 + @NotEmpty(
  17 + message = "大屏名称不能为空或空字符串",
  18 + groups = {UpdateGroup.class, AddGroup.class})
  19 + private String name;
20 20
21   - @ApiModelProperty(value = "状态:0待发布 1发布")
22   - private Integer state;
  21 + @ApiModelProperty(value = "状态:0待发布 1发布")
  22 + private Integer state;
23 23
24   - @ApiModelProperty(value = "大屏描述")
25   - private String remark;
  24 + @ApiModelProperty(value = "大屏描述")
  25 + private String remark;
26 26
27   - @ApiModelProperty(value = "组织ID", required = true)
28   - @NotEmpty(
29   - message = "组织ID不能为空或空字符串",
30   - groups = {UpdateGroup.class, AddGroup.class})
31   - private String organizationId;
  27 + @ApiModelProperty(value = "组织ID", required = true)
  28 + @NotEmpty(
  29 + message = "组织ID不能为空或空字符串",
  30 + groups = {UpdateGroup.class, AddGroup.class})
  31 + private String organizationId;
32 32
33   - @ApiModelProperty(value = "组态缩略图")
34   - private String thumbnail;
  33 + @ApiModelProperty(value = "组态缩略图")
  34 + private String thumbnail;
35 35
36   - private OrganizationDTO organizationDTO;
37   -
38   - @ApiModelProperty(value = "视图类型")
39   - private ViewType viewType;
40   -
41   - @ApiModelProperty(value = "访问凭证")
42   - private String accessCredentials;
  36 + private OrganizationDTO organizationDTO;
43 37 }
... ...
  1 +package org.thingsboard.server.common.data.yunteng.enums;
  2 +
  3 +public enum ShareViewType {
  4 + DATA_BOARD,
  5 + SCADA,
  6 + LARGE_SCREEN
  7 +}
... ...
... ... @@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.annotation.TableField;
5 5 import com.baomidou.mybatisplus.annotation.TableName;
6 6 import lombok.Data;
7 7 import lombok.EqualsAndHashCode;
  8 +import org.apache.ibatis.type.EnumTypeHandler;
8 9 import org.thingsboard.server.common.data.yunteng.constant.ModelConstants;
  10 +import org.thingsboard.server.common.data.yunteng.enums.ViewType;
9 11
10 12 @EqualsAndHashCode(callSuper = true)
11 13 @TableName(ModelConstants.Table.TK_CONFIGURATION_CENTER_NAME)
... ... @@ -16,6 +18,13 @@ public class TkConfigurationCenterEntity extends TenantBaseEntity {
16 18 private String remark;
17 19 private String organizationId;
18 20 private String platform;
  21 +
19 22 @TableField(updateStrategy = FieldStrategy.IGNORED)
20 23 private String thumbnail;
  24 +
  25 + @TableField(typeHandler = EnumTypeHandler.class)
  26 + private ViewType viewType;
  27 +
  28 + @TableField(updateStrategy = FieldStrategy.IGNORED)
  29 + private String accessCredentials;
21 30 }
... ...
1 1 package org.thingsboard.server.dao.yunteng.entities;
2 2
  3 +import com.baomidou.mybatisplus.annotation.FieldStrategy;
3 4 import com.baomidou.mybatisplus.annotation.TableField;
4 5 import com.baomidou.mybatisplus.annotation.TableName;
5 6 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
... ... @@ -30,4 +31,7 @@ public class TkDataBoardEntity extends TenantBaseEntity {
30 31 private Integer componentNum;
31 32
32 33 private String organizationId;
  34 +
  35 + @TableField(updateStrategy = FieldStrategy.IGNORED)
  36 + private String accessCredentials;
33 37 }
... ...
... ... @@ -25,5 +25,6 @@ public class TkDataViewEntity extends TenantBaseEntity {
25 25 @TableField(typeHandler = EnumTypeHandler.class)
26 26 private ViewType viewType;
27 27
  28 + @TableField(updateStrategy = FieldStrategy.IGNORED)
28 29 private String accessCredentials;
29 30 }
... ...
... ... @@ -12,6 +12,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidatio
12 12 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
13 13 import org.thingsboard.server.common.data.yunteng.dto.*;
14 14 import org.thingsboard.server.common.data.yunteng.dto.request.ConfigurationContentInfoDTO;
  15 +import org.thingsboard.server.common.data.yunteng.enums.ViewType;
15 16 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
16 17 import org.thingsboard.server.dao.yunteng.entities.TkConfigurationCenterEntity;
17 18 import org.thingsboard.server.dao.yunteng.mapper.ConfigurationCenterMapper;
... ... @@ -128,4 +129,52 @@ public class TkConfigurationCenterServiceImpl
128 129 ? list.get(FastIotConstants.MagicNumber.ZERO)
129 130 : null;
130 131 }
  132 +
  133 + @Override
  134 + public ConfigurationCenterDTO getConfigurationCenterInfoById(String id, String tenantId) {
  135 + TkConfigurationCenterEntity entity =
  136 + baseMapper.selectOne(
  137 + new LambdaQueryWrapper<TkConfigurationCenterEntity>()
  138 + .eq(TkConfigurationCenterEntity::getTenantId, tenantId)
  139 + .eq(TkConfigurationCenterEntity::getId, id));
  140 + if (null == entity) {
  141 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  142 + }
  143 + return entity.getDTO(ConfigurationCenterDTO.class);
  144 + }
  145 +
  146 + @Override
  147 + public boolean isNeedCredentialsForPublicView(String id, String tenantId) {
  148 + TkConfigurationCenterEntity entity =
  149 + baseMapper.selectOne(
  150 + new LambdaQueryWrapper<TkConfigurationCenterEntity>()
  151 + .eq(TkConfigurationCenterEntity::getTenantId, tenantId)
  152 + .eq(TkConfigurationCenterEntity::getId, id));
  153 + if (null == entity) {
  154 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  155 + }
  156 + return StringUtils.isNotEmpty(entity.getAccessCredentials());
  157 + }
  158 +
  159 + @Override
  160 + @Transactional
  161 + public boolean shareOrMonopolyConfigurationCenter(
  162 + boolean isShare, String id, String accessCredentials, String tenantId) {
  163 + TkConfigurationCenterEntity entity =
  164 + baseMapper.selectOne(
  165 + new LambdaQueryWrapper<TkConfigurationCenterEntity>()
  166 + .eq(TkConfigurationCenterEntity::getTenantId, tenantId)
  167 + .eq(TkConfigurationCenterEntity::getId, id));
  168 + if (null == entity) {
  169 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  170 + }
  171 + if (isShare) {
  172 + entity.setViewType(ViewType.PUBLIC_VIEW);
  173 + entity.setAccessCredentials(accessCredentials);
  174 + } else {
  175 + entity.setViewType(ViewType.PRIVATE_VIEW);
  176 + entity.setAccessCredentials(null);
  177 + }
  178 + return baseMapper.updateById(entity) > FastIotConstants.MagicNumber.ZERO;
  179 + }
131 180 }
... ...
... ... @@ -12,6 +12,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidatio
12 12 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
13 13 import org.thingsboard.server.common.data.yunteng.dto.*;
14 14 import org.thingsboard.server.common.data.yunteng.dto.board.ComponentLayoutDTO;
  15 +import org.thingsboard.server.common.data.yunteng.enums.ViewType;
15 16 import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil;
16 17 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
17 18 import org.thingsboard.server.dao.yunteng.entities.TkDataBoardEntity;
... ... @@ -82,12 +83,11 @@ public class TkDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper,
82 83 @Transactional
83 84 public DataBoardDTO saveOrUpdateDataBoard(DataBoardDTO dataBoardDTO) {
84 85 TkDataBoardEntity dataBoard = dataBoardDTO.getEntity(TkDataBoardEntity.class);
  86 + if(dataBoardDTO.getViewType().equals(ViewType.PRIVATE_VIEW)){
  87 + dataBoard.setAccessCredentials(null);
  88 + }
85 89 if (StringUtils.isEmpty(dataBoardDTO.getId())) {
86   - try {
87   - baseMapper.insert(dataBoard);
88   - } catch (Exception e) {
89   - e.printStackTrace();
90   - }
  90 + baseMapper.insert(dataBoard);
91 91 } else {
92 92 if (null != dataBoardDTO.getLayout() && !dataBoardDTO.getLayout().isEmpty()) {
93 93 dataBoard.setLayout(JacksonUtil.convertValue(dataBoardDTO.getLayout(), JsonNode.class));
... ... @@ -111,9 +111,9 @@ public class TkDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper,
111 111 @Transactional
112 112 public boolean deleteDataBoard(DeleteDTO deleteDTO) {
113 113 dataComponentMapper.delete(
114   - new LambdaQueryWrapper<TkDataComponentEntity>()
115   - .eq(TkDataComponentEntity::getTenantId, deleteDTO.getTenantId())
116   - .in(TkDataComponentEntity::getDataBoardId, deleteDTO.getIds()));
  114 + new LambdaQueryWrapper<TkDataComponentEntity>()
  115 + .eq(TkDataComponentEntity::getTenantId, deleteDTO.getTenantId())
  116 + .in(TkDataComponentEntity::getDataBoardId, deleteDTO.getIds()));
117 117 return baseMapper.delete(
118 118 new LambdaQueryWrapper<TkDataBoardEntity>()
119 119 .eq(TkDataBoardEntity::getTenantId, deleteDTO.getTenantId())
... ... @@ -170,4 +170,38 @@ public class TkDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper,
170 170 public boolean updateDataBoardComponentNum(String id, String tenantId, int count) {
171 171 return baseMapper.updateDataBoardComponentNum(id, tenantId, count);
172 172 }
  173 +
  174 + @Override
  175 + public boolean isNeedCredentialsForPublicView(String id, String tenantId) {
  176 + TkDataBoardEntity entity =
  177 + baseMapper.selectOne(
  178 + new LambdaQueryWrapper<TkDataBoardEntity>()
  179 + .eq(TkDataBoardEntity::getTenantId, tenantId)
  180 + .eq(TkDataBoardEntity::getId, id));
  181 + if (null == entity) {
  182 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  183 + }
  184 + return StringUtils.isNotEmpty(entity.getAccessCredentials());
  185 + }
  186 +
  187 + @Override
  188 + public boolean shareOrMonopolyDataBoard(
  189 + boolean isShare, String id, String accessCredentials, String tenantId) {
  190 + TkDataBoardEntity entity =
  191 + baseMapper.selectOne(
  192 + new LambdaQueryWrapper<TkDataBoardEntity>()
  193 + .eq(TkDataBoardEntity::getTenantId, tenantId)
  194 + .eq(TkDataBoardEntity::getId, id));
  195 + if (null == entity) {
  196 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  197 + }
  198 + if (isShare) {
  199 + entity.setViewType(ViewType.PUBLIC_VIEW);
  200 + entity.setAccessCredentials(accessCredentials);
  201 + } else {
  202 + entity.setViewType(ViewType.PRIVATE_VIEW);
  203 + entity.setAccessCredentials(null);
  204 + }
  205 + return baseMapper.updateById(entity) > FastIotConstants.MagicNumber.ZERO;
  206 + }
173 207 }
... ...
... ... @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5 import lombok.RequiredArgsConstructor;
6 6 import lombok.extern.slf4j.Slf4j;
  7 +import org.apache.commons.lang3.StringUtils;
7 8 import org.springframework.stereotype.Service;
8 9 import org.springframework.transaction.annotation.Transactional;
9 10 import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
... ... @@ -11,9 +12,9 @@ import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidatio
11 12 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
12 13 import org.thingsboard.server.common.data.yunteng.dto.*;
13 14 import org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentInfoDTO;
  15 +import org.thingsboard.server.common.data.yunteng.enums.ViewType;
14 16 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
15 17 import org.thingsboard.server.dao.yunteng.entities.TkDataViewEntity;
16   -import org.thingsboard.server.dao.yunteng.entities.TkDataViewInterfaceEntity;
17 18 import org.thingsboard.server.dao.yunteng.mapper.TkDataViewMapper;
18 19 import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper;
19 20 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
... ... @@ -31,116 +32,161 @@ import java.util.stream.Collectors;
31 32 @Slf4j
32 33 @Service
33 34 @RequiredArgsConstructor
34   -public class TkDataViewServiceImpl
35   - extends AbstractBaseService<TkDataViewMapper, TkDataViewEntity>
36   - implements TkDataViewService {
37   - private final OrganizationMapper organizationMapper;
38   - private final TkDataViewContentService ytDataViewContentService;
39   - private final UserOrganizationMappingService userOrganizationMappingService;
  35 +public class TkDataViewServiceImpl extends AbstractBaseService<TkDataViewMapper, TkDataViewEntity>
  36 + implements TkDataViewService {
  37 + private final OrganizationMapper organizationMapper;
  38 + private final TkDataViewContentService ytDataViewContentService;
  39 + private final UserOrganizationMappingService userOrganizationMappingService;
40 40
41   - @Override
42   - public TkPageData<TkDataViewDTO> page(
43   - Map<String, Object> queryMap, boolean tenantAdmin) {
44   - List<String> organizationIds = null;
45   - if (null != queryMap.get("organizationId")) {
46   - String organizationId = (String) queryMap.get("organizationId");
47   - List<OrganizationDTO> organizationList =
48   - organizationMapper.findOrganizationTreeList(
49   - (String) queryMap.get("tenantId"), new HashSet<>(List.of(organizationId)));
50   - if (organizationList.size() == FastIotConstants.MagicNumber.ZERO) {
51   - throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
52   - }
53   - organizationIds =
54   - organizationList.stream().map(BaseDTO::getId).distinct().collect(Collectors.toList());
55   - }
56   - if (!tenantAdmin && null != queryMap.get("userId")) {
57   - // 获取客户的组织关系
58   - String userId = (String) queryMap.get("userId");
59   - organizationIds = userOrganizationMappingService.compareOrganizationIdsByCustomerId(organizationIds, userId);
60   - }
61   - if (null != organizationIds && organizationIds.size() > FastIotConstants.MagicNumber.ZERO) {
62   - queryMap.put("organizationIds", organizationIds);
63   - }
64   - IPage<TkDataViewEntity> page =
65   - getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false);
66   - IPage<TkDataViewDTO> DataViewIPage =
67   - baseMapper.getDataViewPage(page, queryMap);
68   - return getPageData(DataViewIPage, TkDataViewDTO.class);
  41 + @Override
  42 + public TkPageData<TkDataViewDTO> page(Map<String, Object> queryMap, boolean tenantAdmin) {
  43 + List<String> organizationIds = null;
  44 + if (null != queryMap.get("organizationId")) {
  45 + String organizationId = (String) queryMap.get("organizationId");
  46 + List<OrganizationDTO> organizationList =
  47 + organizationMapper.findOrganizationTreeList(
  48 + (String) queryMap.get("tenantId"), new HashSet<>(List.of(organizationId)));
  49 + if (organizationList.size() == FastIotConstants.MagicNumber.ZERO) {
  50 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  51 + }
  52 + organizationIds =
  53 + organizationList.stream().map(BaseDTO::getId).distinct().collect(Collectors.toList());
69 54 }
  55 + if (!tenantAdmin && null != queryMap.get("userId")) {
  56 + // 获取客户的组织关系
  57 + String userId = (String) queryMap.get("userId");
  58 + organizationIds =
  59 + userOrganizationMappingService.compareOrganizationIdsByCustomerId(
  60 + organizationIds, userId);
  61 + }
  62 + if (null != organizationIds && organizationIds.size() > FastIotConstants.MagicNumber.ZERO) {
  63 + queryMap.put("organizationIds", organizationIds);
  64 + }
  65 + IPage<TkDataViewEntity> page =
  66 + getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false);
  67 + IPage<TkDataViewDTO> DataViewIPage = baseMapper.getDataViewPage(page, queryMap);
  68 + return getPageData(DataViewIPage, TkDataViewDTO.class);
  69 + }
  70 +
  71 + @Override
  72 + @Transactional
  73 + public TkDataViewDTO saveDataView(TkDataViewDTO tkDataViewDTO) {
  74 + TkDataViewEntity dataView = tkDataViewDTO.getEntity(TkDataViewEntity.class);
  75 + dataView.setState(0);
  76 + baseMapper.insert(dataView);
  77 + TkDataViewContentDTO contentDTO = new TkDataViewContentDTO();
  78 + contentDTO.setTenantId(dataView.getTenantId());
  79 + contentDTO.setViewId(dataView.getId());
  80 + ytDataViewContentService.saveDataViewContent(contentDTO);
  81 + return tkDataViewDTO;
  82 + }
70 83
71   - @Override
72   - @Transactional
73   - public TkDataViewDTO saveDataView(TkDataViewDTO TkDataViewDTO) {
74   - TkDataViewEntity dataView =
75   - TkDataViewDTO.getEntity(TkDataViewEntity.class);
76   - dataView.setState(0);
77   - baseMapper.insert(dataView);
78   - TkDataViewContentDTO contentDTO = new TkDataViewContentDTO();
79   - contentDTO.setTenantId(dataView.getTenantId());
80   - contentDTO.setViewId(dataView.getId());
81   - contentDTO.setContent(
82   - "<mxGraphModel><root><mxCell id=\"0\"/><mxCell id=\"1\" parent=\"0\"/></root></mxGraphModel>");
83   - ytDataViewContentService.saveDataViewContent(contentDTO);
84   - return TkDataViewDTO;
  84 + @Override
  85 + @Transactional
  86 + public TkDataViewDTO updateDataView(TkDataViewDTO tkDataViewDTO) {
  87 + TkDataViewEntity dataView = baseMapper.selectById(tkDataViewDTO.getId());
  88 + if (!dataView.getTenantId().equals(tkDataViewDTO.getTenantId())) {
  89 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
85 90 }
  91 + //设计不修改状态
  92 + tkDataViewDTO.setViewType(null);
  93 + baseMapper.updateById(tkDataViewDTO.getEntity(TkDataViewEntity.class));
  94 + return tkDataViewDTO;
  95 + }
86 96
87   - @Override
88   - @Transactional
89   - public TkDataViewDTO updateDataView(TkDataViewDTO TkDataViewDTO) {
90   - TkDataViewEntity DataView = baseMapper.selectById(TkDataViewDTO.getId());
91   - if (!DataView.getTenantId().equals(TkDataViewDTO.getTenantId())) {
92   - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
93   - }
94   - baseMapper.updateById(TkDataViewDTO.getEntity(TkDataViewEntity.class));
95   - return TkDataViewDTO;
  97 + @Override
  98 + @Transactional
  99 + public boolean deleteDataView(DeleteDTO deleteDTO) {
  100 + List<TkDataViewEntity> centerList =
  101 + baseMapper.selectList(
  102 + new LambdaQueryWrapper<TkDataViewEntity>()
  103 + .in(TkDataViewEntity::getId, deleteDTO.getIds()));
  104 + for (TkDataViewEntity center : centerList) {
  105 + if (!center.getTenantId().equals(deleteDTO.getTenantId())) {
  106 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
  107 + }
96 108 }
  109 + ytDataViewContentService.deleteDataViewContentByCenterId(deleteDTO.getIds());
  110 + return baseMapper.deleteBatchIds(deleteDTO.getIds()) > FastIotConstants.MagicNumber.ZERO;
  111 + }
97 112
98   - @Override
99   - @Transactional
100   - public boolean deleteDataView(DeleteDTO deleteDTO) {
101   - List<TkDataViewEntity> centerList =
102   - baseMapper.selectList(
103   - new LambdaQueryWrapper<TkDataViewEntity>()
104   - .in(TkDataViewEntity::getId, deleteDTO.getIds()));
105   - for (TkDataViewEntity center : centerList) {
106   - if (!center.getTenantId().equals(deleteDTO.getTenantId())) {
107   - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
108   - }
109   - }
110   - ytDataViewContentService.deleteDataViewContentByCenterId(deleteDTO.getIds());
111   - return baseMapper.deleteBatchIds(deleteDTO.getIds()) > FastIotConstants.MagicNumber.ZERO;
  113 + @Override
  114 + public TkDataViewContentInfoDTO getDataViewInfos(String id, String tenantId) {
  115 + List<TkDataViewContentInfoDTO> list = baseMapper.getDataViewInfoById(id, tenantId);
  116 + return list.size() > FastIotConstants.MagicNumber.ZERO
  117 + ? list.get(FastIotConstants.MagicNumber.ZERO)
  118 + : null;
  119 + }
  120 +
  121 + @Override
  122 + public TkDataViewDTO getDataViewById(String id, String tenantId) {
  123 + TkDataViewEntity entity =
  124 + baseMapper.selectOne(
  125 + new LambdaQueryWrapper<TkDataViewEntity>()
  126 + .eq(TkDataViewEntity::getTenantId, tenantId)
  127 + .eq(TkDataViewEntity::getId, id));
  128 + if (null == entity) {
  129 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
112 130 }
  131 + return entity.getDTO(TkDataViewDTO.class);
  132 + }
113 133
114   - @Override
115   - public TkDataViewContentInfoDTO getDataViewInfos(String id, String tenantId) {
116   - List<TkDataViewContentInfoDTO> list = baseMapper.getDataViewInfoById(id, tenantId);
117   - return list.size() > FastIotConstants.MagicNumber.ZERO
118   - ? list.get(FastIotConstants.MagicNumber.ZERO)
119   - : null;
  134 + @Override
  135 + public boolean isNeedCredentialsForPublicView(String id, String tenantId) {
  136 + TkDataViewEntity entity =
  137 + baseMapper.selectOne(
  138 + new LambdaQueryWrapper<TkDataViewEntity>()
  139 + .eq(TkDataViewEntity::getTenantId, tenantId)
  140 + .eq(TkDataViewEntity::getId, id));
  141 + if (null == entity) {
  142 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
120 143 }
  144 + return StringUtils.isNotEmpty(entity.getAccessCredentials());
  145 + }
121 146
  147 + @Override
  148 + @Transactional
  149 + public boolean shareOrMonopolyDataViewCenter(
  150 + boolean isShare, String id, String accessCredentials, String tenantId) {
  151 + TkDataViewEntity entity =
  152 + baseMapper.selectOne(
  153 + new LambdaQueryWrapper<TkDataViewEntity>()
  154 + .eq(TkDataViewEntity::getTenantId, tenantId)
  155 + .eq(TkDataViewEntity::getId, id));
  156 + if (null == entity) {
  157 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  158 + }
  159 + if (isShare) {
  160 + entity.setViewType(ViewType.PUBLIC_VIEW);
  161 + entity.setAccessCredentials(accessCredentials);
  162 + } else {
  163 + entity.setViewType(ViewType.PRIVATE_VIEW);
  164 + entity.setAccessCredentials(null);
  165 + }
  166 + return baseMapper.updateById(entity) > FastIotConstants.MagicNumber.ZERO;
  167 + }
122 168
123   - @Override
124   - public boolean publishDataView(String id, String tenantId) {
125   - TkDataViewEntity dataView = baseMapper.selectById(id);
126   - if (!dataView.getTenantId().equals(tenantId)) {
127   - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
128   - }
129   - //Modify dataView state is publish
130   - dataView.setState(1);
131   - int resultInt = baseMapper.updateById(dataView);
132   - return resultInt > 0 ? true : false;
  169 + @Override
  170 + public boolean publishDataView(String id, String tenantId) {
  171 + TkDataViewEntity dataView = baseMapper.selectById(id);
  172 + if (!dataView.getTenantId().equals(tenantId)) {
  173 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
133 174 }
  175 + // Modify dataView state is publish
  176 + dataView.setState(FastIotConstants.StateValue.PUBLISH);
  177 + int resultInt = baseMapper.updateById(dataView);
  178 + return resultInt > FastIotConstants.MagicNumber.ZERO;
  179 + }
134 180
135   - @Override
136   - public boolean cancelPublishDataView(String id, String tenantId) {
137   - TkDataViewEntity dataView = baseMapper.selectById(id);
138   - if (!dataView.getTenantId().equals(tenantId)) {
139   - throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
140   - }
141   - //Modify dataView state is cancelPublish
142   - dataView.setState(0);
143   - int resultInt = baseMapper.updateById(dataView);
144   - return resultInt > 0 ? true : false;
  181 + @Override
  182 + public boolean cancelPublishDataView(String id, String tenantId) {
  183 + TkDataViewEntity dataView = baseMapper.selectById(id);
  184 + if (!dataView.getTenantId().equals(tenantId)) {
  185 + throw new TkDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
145 186 }
  187 + // Modify dataView state is cancelPublish
  188 + dataView.setState(FastIotConstants.StateValue.CANCEL_PUBLISH);
  189 + int resultInt = baseMapper.updateById(dataView);
  190 + return resultInt > FastIotConstants.MagicNumber.ZERO;
  191 + }
146 192 }
... ...
... ... @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 5 import com.baomidou.mybatisplus.core.metadata.IPage;
6 6 import com.fasterxml.jackson.databind.JsonNode;
  7 +import com.google.common.util.concurrent.Futures;
  8 +import com.google.common.util.concurrent.ListenableFuture;
7 9 import lombok.RequiredArgsConstructor;
8 10 import lombok.extern.slf4j.Slf4j;
9 11 import org.apache.commons.lang3.StringUtils;
... ... @@ -365,7 +367,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
365 367 List<String> queryOrganizationIds = organizationAllIds(tenantId, organizationId);
366 368 queryMap.put("organizationIds", queryOrganizationIds);
367 369 }
368   - //用于数据流转已选,待选过滤============开始
  370 + // 用于数据流转已选,待选过滤============开始
369 371 if (StringUtils.isNotEmpty(convertConfigId)) {
370 372 ConvertConfigDTO configDTO =
371 373 convertConfigService.findConvertConfigDTOById(tenantId, convertConfigId);
... ... @@ -382,7 +384,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
382 384 }
383 385 }
384 386 }
385   - //用于数据流转已选,待选过滤============结束
  387 + // 用于数据流转已选,待选过滤============结束
386 388 IPage<TkDeviceEntity> page =
387 389 getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false);
388 390 IPage<DeviceDTO> deviceIPage = baseMapper.getDevicePage(page, queryMap);
... ... @@ -668,12 +670,16 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
668 670 public List<String> rpcDevices(String tenantId, String organizationId, String projectId) {
669 671 List<String> orgIds = organizationAllIds(tenantId, organizationId);
670 672
671   - List<TkDeviceEntity> organizationDevices = baseMapper.selectList(new LambdaQueryWrapper<TkDeviceEntity>().eq(TkDeviceEntity::getDeviceProfileId, projectId).in(TkDeviceEntity::getOrganizationId,orgIds));
  673 + List<TkDeviceEntity> organizationDevices =
  674 + baseMapper.selectList(
  675 + new LambdaQueryWrapper<TkDeviceEntity>()
  676 + .eq(TkDeviceEntity::getDeviceProfileId, projectId)
  677 + .in(TkDeviceEntity::getOrganizationId, orgIds));
672 678 List<String> allDevices = new ArrayList<>();
673   - if(organizationDevices != null && !organizationDevices.isEmpty()){
  679 + if (organizationDevices != null && !organizationDevices.isEmpty()) {
674 680 for (TkDeviceEntity item : organizationDevices) {
675 681 DeviceTypeEnum deviceType = item.getDeviceType();
676   - if(DeviceTypeEnum.SENSOR.equals(deviceType)){
  682 + if (DeviceTypeEnum.SENSOR.equals(deviceType)) {
677 683 allDevices.add(item.getGatewayId());
678 684 continue;
679 685 }
... ... @@ -682,4 +688,26 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
682 688 }
683 689 return allDevices;
684 690 }
  691 +
  692 + @Override
  693 + public ListenableFuture<List<DeviceDTO>> findDeviceListByDeviceProfileId(
  694 + String deviceProfileId, String tenantId) {
  695 + if (StringUtils.isEmpty(deviceProfileId) || StringUtils.isEmpty(tenantId)) {
  696 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  697 + }
  698 + List<DeviceDTO> devices = new ArrayList<>();
  699 + List<TkDeviceEntity> entityList =
  700 + baseMapper.selectList(
  701 + new LambdaQueryWrapper<TkDeviceEntity>()
  702 + .eq(TkDeviceEntity::getTenantId, tenantId)
  703 + .eq(TkDeviceEntity::getDeviceProfileId, deviceProfileId));
  704 + return Optional.ofNullable(entityList)
  705 + .map(
  706 + list ->
  707 + Futures.immediateFuture(
  708 + list.stream()
  709 + .map(obj -> obj.getDTO(DeviceDTO.class))
  710 + .collect(Collectors.toList())))
  711 + .orElse(Futures.immediateFuture(devices));
  712 + }
685 713 }
... ...
  1 +package org.thingsboard.server.dao.yunteng.impl;
  2 +
  3 +import com.google.common.base.Objects;
  4 +import lombok.RequiredArgsConstructor;
  5 +import org.springframework.stereotype.Service;
  6 +import org.thingsboard.server.common.data.StringUtils;
  7 +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
  8 +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
  9 +import org.thingsboard.server.common.data.yunteng.dto.ConfigurationCenterDTO;
  10 +import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO;
  11 +import org.thingsboard.server.common.data.yunteng.dto.DataComponentDTO;
  12 +import org.thingsboard.server.common.data.yunteng.dto.TkDataViewDTO;
  13 +import org.thingsboard.server.common.data.yunteng.dto.board.MoreDataComponentInfoDTO;
  14 +import org.thingsboard.server.common.data.yunteng.dto.request.ConfigurationContentInfoDTO;
  15 +import org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentInfoDTO;
  16 +import org.thingsboard.server.common.data.yunteng.enums.ShareViewType;
  17 +import org.thingsboard.server.common.data.yunteng.enums.ViewType;
  18 +import org.thingsboard.server.dao.yunteng.service.*;
  19 +
  20 +import java.util.List;
  21 +
  22 +@Service
  23 +@RequiredArgsConstructor
  24 +public class TkShareViewServiceImpl implements TkShareViewService {
  25 +
  26 + private final TkDataComponentService tkDataComponentService;
  27 + private final TkDataBoardService tkDataBoardService;
  28 + private final TkDataViewService tkDataViewService;
  29 + private final TkConfigurationCenterService tkConfigurationCenterService;
  30 +
  31 + private MoreDataComponentInfoDTO viewDataComponentsByBoardId(
  32 + String boardId, String accessCredentials, String tenantId) {
  33 + DataBoardDTO dto = tkDataBoardService.findDataBoardInfoById(boardId, tenantId);
  34 + checkParams(dto, dto.getViewType(), dto.getAccessCredentials(), accessCredentials);
  35 + MoreDataComponentInfoDTO moreDataComponentInfoDTO = new MoreDataComponentInfoDTO();
  36 + List<DataComponentDTO> data =
  37 + tkDataComponentService.getDataComponentsByBoardId(tenantId, boardId);
  38 + moreDataComponentInfoDTO.setComponentLayout(dto.getLayout());
  39 + moreDataComponentInfoDTO.setComponentData(data);
  40 + return moreDataComponentInfoDTO;
  41 + }
  42 +
  43 + private ConfigurationContentInfoDTO viewConfigurationById(
  44 + String id, String accessCredentials, String tenantId) {
  45 + ConfigurationCenterDTO centerDTO =
  46 + tkConfigurationCenterService.getConfigurationCenterInfoById(id, tenantId);
  47 + checkParams(
  48 + centerDTO, centerDTO.getViewType(), centerDTO.getAccessCredentials(), accessCredentials);
  49 + return tkConfigurationCenterService.getConfigurationInfos(id, tenantId);
  50 + }
  51 +
  52 + private TkDataViewContentInfoDTO viewDataViewInfosById(
  53 + String id, String accessCredentials, String tenantId) {
  54 + TkDataViewDTO dto = tkDataViewService.getDataViewById(id, tenantId);
  55 + checkParams(dto, dto.getViewType(), dto.getAccessCredentials(), accessCredentials);
  56 + return tkDataViewService.getDataViewInfos(id, tenantId);
  57 + }
  58 +
  59 + private void checkParams(
  60 + Object dto, ViewType viewType, String targetCredentials, String sourceCredentials) {
  61 + if (null == dto) {
  62 + throw new TkDataValidationException(ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage());
  63 + }
  64 + if (!Objects.equal(viewType, ViewType.PUBLIC_VIEW)) {
  65 + throw new TkDataValidationException(ErrorMessage.CURRENT_VIEW_IS_PRIVATE.getMessage());
  66 + }
  67 + if (StringUtils.isNotEmpty(targetCredentials)) {
  68 + if (!Objects.equal(targetCredentials, sourceCredentials)) {
  69 + throw new TkDataValidationException(
  70 + ErrorMessage.CURRENT_URL_REQUIRES_PERMISSION.getMessage());
  71 + }
  72 + }
  73 + }
  74 +
  75 + @Override
  76 + public Object viewShareDataById(
  77 + ShareViewType shareViewType, String id, String accessCredentials, String tenantId) {
  78 + Object result;
  79 + switch (shareViewType) {
  80 + case DATA_BOARD:
  81 + result = viewDataComponentsByBoardId(id, accessCredentials, tenantId);
  82 + break;
  83 + case SCADA:
  84 + result = viewConfigurationById(id, accessCredentials, tenantId);
  85 + break;
  86 + case LARGE_SCREEN:
  87 + result = viewDataViewInfosById(id, accessCredentials, tenantId);
  88 + break;
  89 + default:
  90 + throw new TkDataValidationException(ErrorMessage.SHARE_VIEW_TYPE_NOT_EXIST.getMessage());
  91 + }
  92 + return result;
  93 + }
  94 +
  95 + @Override
  96 + public boolean checkPublicViewNeedCredentials(
  97 + ShareViewType type, String viewId, String tenantId) {
  98 + boolean result;
  99 + switch (type) {
  100 + case SCADA:
  101 + result = tkConfigurationCenterService.isNeedCredentialsForPublicView(viewId, tenantId);
  102 + break;
  103 + case DATA_BOARD:
  104 + result = tkDataBoardService.isNeedCredentialsForPublicView(viewId, tenantId);
  105 + break;
  106 + case LARGE_SCREEN:
  107 + result = tkDataViewService.isNeedCredentialsForPublicView(viewId, tenantId);
  108 + break;
  109 + default:
  110 + throw new TkDataValidationException(ErrorMessage.SHARE_VIEW_TYPE_NOT_EXIST.getMessage());
  111 + }
  112 + return result;
  113 + }
  114 +}
... ...
... ... @@ -16,5 +16,28 @@ public interface TkConfigurationCenterService {
16 16
17 17 boolean deleteConfigurationCenter(DeleteDTO deleteDTO);
18 18
19   - ConfigurationContentInfoDTO getConfigurationInfos(String id,String tenantId);
  19 + ConfigurationContentInfoDTO getConfigurationInfos(String id, String tenantId);
  20 +
  21 + ConfigurationCenterDTO getConfigurationCenterInfoById(String id,String tenantId);
  22 +
  23 + /**
  24 + * 根据租户ID和数据看板ID,判断是否需要密码
  25 + *
  26 + * @param id 数据看板ID
  27 + * @param tenantId 租户ID
  28 + * @return 需要true,不需要false
  29 + */
  30 + boolean isNeedCredentialsForPublicView(String id, String tenantId);
  31 +
  32 + /**
  33 + * 分享或取消分享组态中心
  34 + *
  35 + * @param isShare true分享 false取消分享
  36 + * @param id 组态ID
  37 + * @param accessCredentials 分享的密码:不用密码则为null
  38 + * @param tenantId 租户ID
  39 + * @return true成功 false失败
  40 + */
  41 + boolean shareOrMonopolyConfigurationCenter(
  42 + boolean isShare, String id, String accessCredentials, String tenantId);
20 43 }
... ...
... ... @@ -56,4 +56,23 @@ public interface TkDataBoardService {
56 56 * @return false失败 true成功
57 57 */
58 58 boolean updateDataBoardComponentNum(String id,String tenantId,int count);
  59 +
  60 + /**
  61 + * 根据租户ID和数据看板ID,判断是否需要密码
  62 + * @param id 数据看板ID
  63 + * @param tenantId 租户ID
  64 + * @return 需要true,不需要false
  65 + */
  66 + boolean isNeedCredentialsForPublicView(String id,String tenantId);
  67 +
  68 + /**
  69 + * 分享或取消分享数据刊本
  70 + * @param isShare 分享
  71 + * @param id 数据看板ID
  72 + * @param accessCredentials 访问凭证
  73 + * @param tenantId 租户ID
  74 + * @return true成功 false失败
  75 + */
  76 + boolean shareOrMonopolyDataBoard(
  77 + boolean isShare, String id, String accessCredentials, String tenantId);
59 78 }
... ...
... ... @@ -10,17 +10,40 @@ import java.util.Map;
10 10 * @author tianfuLei
11 11 */
12 12 public interface TkDataViewService {
13   - TkPageData<TkDataViewDTO> page(Map<String, Object> queryMap, boolean tenantAdmin);
  13 + TkPageData<TkDataViewDTO> page(Map<String, Object> queryMap, boolean tenantAdmin);
14 14
15   - TkDataViewDTO saveDataView(TkDataViewDTO TkDataViewDTO);
  15 + TkDataViewDTO saveDataView(TkDataViewDTO TkDataViewDTO);
16 16
17   - TkDataViewDTO updateDataView(TkDataViewDTO TkDataViewDTO);
  17 + TkDataViewDTO updateDataView(TkDataViewDTO TkDataViewDTO);
18 18
19   - boolean deleteDataView(DeleteDTO deleteDTO);
  19 + boolean deleteDataView(DeleteDTO deleteDTO);
20 20
21   - TkDataViewContentInfoDTO getDataViewInfos(String id, String tenantId);
  21 + TkDataViewContentInfoDTO getDataViewInfos(String id, String tenantId);
22 22
23   - boolean publishDataView(String id, String tenantId);
  23 + TkDataViewDTO getDataViewById(String id, String tenantId);
24 24
25   - boolean cancelPublishDataView(String id, String tenantId);
  25 + /**
  26 + * 根据租户ID和大屏ID,判断是否需要密码
  27 + *
  28 + * @param id 大屏ID
  29 + * @param tenantId 租户ID
  30 + * @return 需要true,不需要false
  31 + */
  32 + boolean isNeedCredentialsForPublicView(String id, String tenantId);
  33 +
  34 + /**
  35 + * 分享或取消分享大屏
  36 + *
  37 + * @param isShare true分享 false取消分享
  38 + * @param id 大屏ID
  39 + * @param accessCredentials 分享的密码:不用密码则为null
  40 + * @param tenantId 租户ID
  41 + * @return true成功 false失败
  42 + */
  43 + boolean shareOrMonopolyDataViewCenter(
  44 + boolean isShare, String id, String accessCredentials, String tenantId);
  45 +
  46 + boolean publishDataView(String id, String tenantId);
  47 +
  48 + boolean cancelPublishDataView(String id, String tenantId);
26 49 }
... ...
1 1 package org.thingsboard.server.dao.yunteng.service;
2 2
3 3 import com.fasterxml.jackson.databind.JsonNode;
4   -import org.thingsboard.server.common.data.DeviceTransportType;
  4 +import com.google.common.util.concurrent.ListenableFuture;import org.thingsboard.server.common.data.DeviceTransportType;
5 5 import org.thingsboard.server.common.data.id.EntityId;
6 6 import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO;
7 7 import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO;
... ... @@ -202,4 +202,6 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> {
202 202 * @return 需要接收RPC控制的网关设备或直连设备的ID
203 203 */
204 204 List<String> rpcDevices(String tenantId,String organizationId,String projectId);
  205 +
  206 + ListenableFuture<List<DeviceDTO>> findDeviceListByDeviceProfileId(String deviceProfileId,String tenantId);
205 207 }
... ...
  1 +package org.thingsboard.server.dao.yunteng.service;
  2 +
  3 +import org.thingsboard.server.common.data.yunteng.enums.ShareViewType;
  4 +
  5 +public interface TkShareViewService {
  6 +
  7 + Object viewShareDataById(ShareViewType shareViewType,String id, String accessCredentials, String tenantId);
  8 +
  9 + boolean checkPublicViewNeedCredentials(ShareViewType type, String viewId, String tenantId);
  10 +}
... ...
... ... @@ -14,6 +14,8 @@
14 14 <result property="tenantId" column="tenant_id"/>
15 15 <result property="updater" column="updater"/>
16 16 <result property="thumbnail" column="thumbnail"/>
  17 + <result property="viewType" column="view_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
  18 + <result property="accessCredentials" column="access_credentials"/>
17 19 <association property="organizationDTO"
18 20 javaType="org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO">
19 21 <result property="name" column="organization_name"/>
... ... @@ -30,7 +32,8 @@
30 32 </resultMap>
31 33
32 34 <sql id="columns">
33   - a.id,a.name,a.platform,a.organization_id,a.thumbnail, a.remark,a.update_time,a.create_time,a.creator,a.tenant_id,a.updater,io.name AS organization_name
  35 + a.id,a.name,a.platform,a.organization_id,a.thumbnail, a.remark,a.update_time,a.create_time,a.creator,a.tenant_id,
  36 + a.updater,io.name AS organization_name,a.view_type,a.access_credentials
34 37 </sql>
35 38 <select id="getConfigurationCenterPage" resultMap="configurationCenterMap">
36 39 SELECT
... ...
... ... @@ -35,7 +35,9 @@
35 35 <result property="updater" column="updater"/>
36 36 <result property="description" column="description"/>
37 37 <result property="customerId" column="customer_id"/>
38   - <result property="customerName" column="cusotomer_name"/>
  38 + <result property="customerName" column="customer_name"/>
  39 + <result property="customerAdditionalInfo" column="customer_additional_info"
  40 + typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
39 41 <result property="organizationId" column="organization_id"/>
40 42 <result property="gatewayId" column="gateway_id"/>
41 43 <result property="gatewayName" column="gateway_name"/>
... ... @@ -83,7 +85,7 @@
83 85 </sql>
84 86 <select id="getDevicePage" resultMap="deviceMap">
85 87 SELECT
86   - <include refid="pageColumns"/>,d.customer_id::TEXT AS customer_id,cus.title AS cusotomer_name
  88 + <include refid="pageColumns"/>,d.customer_id::TEXT AS customer_id,cus.title AS customer_name,cus.additional_info AS customer_additional_info
87 89 FROM tk_device ifd
88 90 LEFT JOIN device_profile ifdp ON ifd.profile_id = ifdp.id::TEXT
89 91 LEFT JOIN tk_organization io ON io.id = ifd.organization_id
... ...
... ... @@ -14,6 +14,8 @@
14 14 <result property="tenantId" column="tenant_id"/>
15 15 <result property="updater" column="updater"/>
16 16 <result property="thumbnail" column="thumbnail"/>
  17 + <result property="accessCredentials" column="access_credentials"/>
  18 + <result property="viewType" column="view_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
17 19 <association property="organizationDTO"
18 20 javaType="org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO">
19 21 <result property="name" column="organization_name"/>
... ... @@ -34,7 +36,8 @@
34 36 </resultMap>
35 37
36 38 <sql id="columns">
37   - a.id,a.name, a.remark,a.state,a.tenant_id,a.organization_id,a.thumbnail,a.updater,a.update_time,a.create_time,a.creator,io.name AS organization_name
  39 + a.id,a.name, a.remark,a.state,a.tenant_id,a.organization_id,a.thumbnail,a.updater,a.update_time,a.create_time,
  40 + a.creator,io.name AS organization_name,a.access_credentials,a.view_type
38 41 </sql>
39 42 <select id="getDataViewPage" resultMap="dataViewMap">
40 43 SELECT
... ...