Commit 68b8f39bd7698b5a47dda7f50c4040717d2566ea

Authored by 雷天福
1 parent 7fbe7215

feat: 新功能开发:大屏公共接口

... ... @@ -31,7 +31,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.
31 31 @RequestMapping("/api/yt/data_view")
32 32 @RequiredArgsConstructor
33 33 @Api(tags = "大屏设计器")
34   -@PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")
  34 +@PreAuthorize("@check.checkPermissions({},{})")
35 35 public class TkDataViewController extends BaseController {
36 36
37 37 private final TkDataViewService tkDataViewService;
... ... @@ -114,4 +114,20 @@ public class TkDataViewController extends BaseController {
114 114 tkDataViewService.getDataViewInfos(
115 115 id, getCurrentUser().getCurrentTenantId()));
116 116 }
  117 +
  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 + }
  125 +
  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()));
  132 + }
117 133 }
... ...
  1 +package org.thingsboard.server.controller.yunteng;
  2 +
  3 +import com.google.common.util.concurrent.ListenableFuture;
  4 +import io.swagger.annotations.Api;
  5 +import io.swagger.annotations.ApiOperation;
  6 +import io.swagger.annotations.ApiParam;
  7 +import lombok.RequiredArgsConstructor;
  8 +import org.apache.commons.lang3.StringUtils;
  9 +import org.springframework.http.MediaType;
  10 +import org.springframework.http.ResponseEntity;
  11 +import org.springframework.security.access.prepost.PreAuthorize;
  12 +import org.springframework.validation.annotation.Validated;
  13 +import org.springframework.web.bind.annotation.*;
  14 +import org.thingsboard.server.common.data.asset.Asset;
  15 +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;
  20 +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
  21 +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
  22 +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
  23 +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;
  26 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
  27 +import org.thingsboard.server.controller.BaseController;
  28 +import org.thingsboard.server.dao.yunteng.service.TkDataViewInterfaceService;
  29 +import org.thingsboard.server.service.security.model.SecurityUser;
  30 +
  31 +import java.util.ArrayList;
  32 +import java.util.HashMap;
  33 +import java.util.List;
  34 +import java.util.Set;
  35 +
  36 +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
  37 +
  38 +/**
  39 + * @author tianfuLei
  40 + */
  41 +@RestController
  42 +@RequestMapping("/api/yt/data_view_interface")
  43 +@RequiredArgsConstructor
  44 +@Api(tags = "大屏公共接口")
  45 +public class TkDataViewInterfaceController extends BaseController {
  46 +
  47 + private final TkDataViewInterfaceService tkDataViewInterfaceService;
  48 +
  49 + @GetMapping(params = {PAGE_SIZE, PAGE})
  50 + @ApiOperation("分页")
  51 + public TkPageData<TkDataViewInterfaceDTO> page(
  52 + @RequestParam(PAGE_SIZE) int pageSize,
  53 + @RequestParam(PAGE) int page,
  54 + @RequestParam(value = "name", required = false) String name,
  55 + @RequestParam(value = "state", required = false) String state,
  56 + @RequestParam(value = ORDER_FILED, required = false) String orderBy,
  57 + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
  58 + throws ThingsboardException {
  59 +
  60 + HashMap<String, Object> queryMap = new HashMap<>();
  61 + queryMap.put(PAGE_SIZE, pageSize);
  62 + queryMap.put(PAGE, page);
  63 + queryMap.put(ORDER_FILED, orderBy);
  64 + queryMap.put("tenantId", getCurrentUser().getCurrentTenantId());
  65 + if (StringUtils.isNotBlank(name)) {
  66 + queryMap.put("name", name);
  67 + }
  68 + if (StringUtils.isNotBlank(state)) {
  69 + queryMap.put("state", state);
  70 + }
  71 + if (null != orderType) {
  72 + queryMap.put(ORDER_TYPE, orderType.name());
  73 + }
  74 + return tkDataViewInterfaceService.page(queryMap);
  75 + }
  76 +
  77 + @PostMapping
  78 + @ApiOperation("新增")
  79 + @PreAuthorize("@check.checkPermissions({},{})")
  80 + public ResponseEntity<TkDataViewInterfaceDTO> save(
  81 + @Validated({AddGroup.class}) @RequestBody TkDataViewInterfaceDTO tkDataViewInterfaceDTO)
  82 + throws ThingsboardException {
  83 + tkDataViewInterfaceDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  84 +
  85 + return ResponseEntity.ok(
  86 + tkDataViewInterfaceService.saveDataViewInterface(tkDataViewInterfaceDTO));
  87 + }
  88 +
  89 + @PutMapping
  90 + @ApiOperation("修改")
  91 + @PreAuthorize("@check.checkPermissions({},{})")
  92 + public ResponseEntity<TkDataViewInterfaceDTO> update(
  93 + @Validated({UpdateGroup.class}) @RequestBody TkDataViewInterfaceDTO TkDataViewInterfaceDTO)
  94 + throws ThingsboardException {
  95 + TkDataViewInterfaceDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  96 + return ResponseEntity.ok(
  97 + tkDataViewInterfaceService.updateDataViewInterface(TkDataViewInterfaceDTO));
  98 + }
  99 +
  100 + @DeleteMapping
  101 + @ApiOperation("删除")
  102 + @PreAuthorize("@check.checkPermissions({},{})")
  103 + public ResponseEntity<Boolean> delete(
  104 + @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)
  105 + throws ThingsboardException {
  106 + deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId());
  107 + return ResponseEntity.ok(tkDataViewInterfaceService.deleteDataViewInterface(deleteDTO));
  108 + }
  109 +
  110 +
  111 + @GetMapping("/publish/{id}")
  112 + @ApiOperation("发布")
  113 + @PreAuthorize("@check.checkPermissions({},{})")
  114 + public ResponseEntity<Boolean> publishInterface(@PathVariable("id") String id) throws ThingsboardException {
  115 + return ResponseEntity.ok(
  116 + tkDataViewInterfaceService.publishInterface(id, getCurrentUser().getCurrentTenantId()));
  117 + }
  118 +
  119 + @GetMapping("/cancel_publish/{id}")
  120 + @ApiOperation("取消发布")
  121 + @PreAuthorize("@check.checkPermissions({},{})")
  122 + public ResponseEntity<Boolean> cancelPublishInterface(@PathVariable("id") String id) throws ThingsboardException {
  123 + return ResponseEntity.ok(
  124 + tkDataViewInterfaceService.cancelPublishInterface(id, getCurrentUser().getCurrentTenantId()));
  125 + }
  126 +
  127 +
  128 + @ApiOperation("根据接口ID,获得接口详情")
  129 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
  130 + @RequestMapping(value = "/get_interface_details", params = {"ids"}, method = RequestMethod.GET)
  131 + @ResponseBody
  132 + public List<TkDataViewInterfaceDTO> getInterfaceDetails(
  133 + @ApiParam(value = "A list of interface ids, separated by comma ','")
  134 + @RequestParam("ids") String[] ids) throws ThingsboardException {
  135 +
  136 + List<String> idsList = new ArrayList<>();
  137 + for (String strId : ids) {
  138 + idsList.add(strId);
  139 + }
  140 + return tkDataViewInterfaceService.getInterfaceDetails(idsList);
  141 + }
  142 +
  143 + @GetMapping("/filter_by_interface_type/{type}")
  144 + @ApiOperation("根据接口类型过滤数据")
  145 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
  146 + public List<TkDataViewInterfaceDTO> filterByInterfaceType(@PathVariable("type") String type) throws ThingsboardException {
  147 + return tkDataViewInterfaceService.filterByInterfaceType(type,getCurrentUser().getCurrentTenantId());
  148 + }
  149 +
  150 +
  151 + @GetMapping("/find_all_interface")
  152 + @ApiOperation("查询所有接口")
  153 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
  154 + public List<TkDataViewInterfaceDTO> findAll() throws ThingsboardException {
  155 + return tkDataViewInterfaceService.findAll(getCurrentUser().getCurrentTenantId());
  156 + }
  157 +
  158 +}
... ...
... ... @@ -82,6 +82,8 @@ public final class ModelConstants {
82 82 public static final String TK_DATA_VIEW_NAME = "tk_data_view";
83 83 /** 大屏设计页面内容 */
84 84 public static final String TK_DATA_VIEW_CONTENT_NAME = "tk_data_view_content";
  85 + /** 大屏公共接口 */
  86 + public static final String TK_DATA_VIEW_INTERFACE_NAME = "tk_data_view_interface";
85 87 /** 组态中心 */
86 88 public static final String TK_CONFIGURATION_CENTER_NAME = "tk_configuration_center";
87 89 /** 组态内容 */
... ...
... ... @@ -5,6 +5,7 @@ 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.common.UpdateGroup;
  8 +import org.thingsboard.server.common.data.yunteng.enums.ViewType;
8 9
9 10 import javax.validation.constraints.NotEmpty;
10 11
... ... @@ -33,4 +34,10 @@ public class TkDataViewDTO extends TenantDTO {
33 34 private String thumbnail;
34 35
35 36 private OrganizationDTO organizationDTO;
  37 +
  38 + @ApiModelProperty(value = "视图类型")
  39 + private ViewType viewType;
  40 +
  41 + @ApiModelProperty(value = "访问凭证")
  42 + private String accessCredentials;
36 43 }
... ...
  1 +package org.thingsboard.server.common.data.yunteng.dto;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import org.thingsboard.server.common.data.yunteng.common.AddGroup;
  7 +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
  8 +
  9 +import javax.validation.constraints.NotEmpty;
  10 +/**
  11 + * @author tianfuLei
  12 + */
  13 +@EqualsAndHashCode(callSuper = true)
  14 +@Data
  15 +public class TkDataViewInterfaceDTO extends TenantDTO {
  16 +
  17 + @ApiModelProperty(value = "接口名称", required = true)
  18 + @NotEmpty(
  19 + message = "名称不能为空或空字符串",
  20 + groups = {UpdateGroup.class, AddGroup.class})
  21 + private String interfaceName;
  22 +
  23 + @ApiModelProperty(value = "请求方式:0普通请求 1SQL请求 2websocket请求")
  24 + private Integer requestContentType;
  25 +
  26 + @ApiModelProperty(value = "源地址")
  27 + private String requestOriginUrl;
  28 +
  29 + @ApiModelProperty(value = "请求类型:GET、PUT、POST", required = true)
  30 + private String requestHttpType;
  31 +
  32 + @ApiModelProperty(value = "接口地址")
  33 + private String requestUrl;
  34 +
  35 + @ApiModelProperty(value = "参数配置")
  36 + private String requestParams;
  37 +
  38 + @ApiModelProperty(value = "状态:0待发布 1已发布")
  39 + private Integer state;
  40 +
  41 + @ApiModelProperty(value = "接口描述")
  42 + private String remark;
  43 +
  44 +}
... ...
... ... @@ -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_DATA_VIEW_NAME)
... ... @@ -16,6 +18,12 @@ public class TkDataViewEntity extends TenantBaseEntity {
16 18 private String remark;
17 19 private String organizationId;
18 20 private Integer state;
  21 +
19 22 @TableField(updateStrategy = FieldStrategy.IGNORED)
20 23 private String thumbnail;
  24 +
  25 + @TableField(typeHandler = EnumTypeHandler.class)
  26 + private ViewType viewType;
  27 +
  28 + private String accessCredentials;
21 29 }
... ...
  1 +package org.thingsboard.server.dao.yunteng.entities;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.FieldStrategy;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableName;
  6 +import io.swagger.annotations.ApiModelProperty;
  7 +import lombok.Data;
  8 +import lombok.EqualsAndHashCode;
  9 +import org.thingsboard.server.common.data.yunteng.constant.ModelConstants;
  10 +
  11 +/**
  12 + * @author tianfuLei
  13 + */
  14 +@EqualsAndHashCode(callSuper = true)
  15 +@TableName(ModelConstants.Table.TK_DATA_VIEW_INTERFACE_NAME)
  16 +@Data
  17 +public class TkDataViewInterfaceEntity extends TenantBaseEntity {
  18 + private static final long serialVersionUID = -7825135358032541445L;
  19 +
  20 + private String interfaceName;
  21 + private Integer requestContentType;
  22 + private String requestOriginUrl;
  23 + private String requestHttpType;
  24 + private String requestUrl;
  25 + private String requestParams;
  26 + private Integer state;
  27 + private String remark;
  28 +
  29 +}
... ...
  1 +package org.thingsboard.server.dao.yunteng.impl;
  2 +
  3 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4 +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5 +import com.baomidou.mybatisplus.core.metadata.IPage;
  6 +import lombok.RequiredArgsConstructor;
  7 +import lombok.extern.slf4j.Slf4j;
  8 +import org.apache.ibatis.annotations.Param;
  9 +import org.springframework.stereotype.Service;
  10 +import org.springframework.transaction.annotation.Transactional;
  11 +import org.thingsboard.server.common.data.id.EntityId;
  12 +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.message.ErrorMessage;
  15 +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.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.mapper.OrganizationMapper;
  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.*;
  24 +
  25 +import java.util.*;
  26 +import java.util.stream.Collectors;
  27 +
  28 +/**
  29 + * @author tianfuLei
  30 + */
  31 +@Slf4j
  32 +@Service
  33 +@RequiredArgsConstructor
  34 +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);
  79 + }
  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 ? true : false;
  129 + }
  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 ? true : false;
  141 + }
  142 +
  143 + @Override
  144 + public List<TkDataViewInterfaceDTO> getInterfaceDetails(List<String> ids) {
  145 + List<TkDataViewInterfaceDTO> lists = baseMapper.getInterfaceDetails(ids);
  146 + return lists;
  147 + }
  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;
  156 + }
  157 +
  158 + @Override
  159 + public List<TkDataViewInterfaceDTO> findAll(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(tenantIds);
  164 + return lists;
  165 + }
  166 +
  167 +}
... ...
... ... @@ -13,6 +13,7 @@ import org.thingsboard.server.common.data.yunteng.dto.*;
13 13 import org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentInfoDTO;
14 14 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
15 15 import org.thingsboard.server.dao.yunteng.entities.TkDataViewEntity;
  16 +import org.thingsboard.server.dao.yunteng.entities.TkDataViewInterfaceEntity;
16 17 import org.thingsboard.server.dao.yunteng.mapper.TkDataViewMapper;
17 18 import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper;
18 19 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
... ... @@ -24,7 +25,9 @@ import java.util.HashSet;
24 25 import java.util.List;
25 26 import java.util.Map;
26 27 import java.util.stream.Collectors;
27   -
  28 +/**
  29 + * @author tianfuLei
  30 + */
28 31 @Slf4j
29 32 @Service
30 33 @RequiredArgsConstructor
... ... @@ -68,12 +71,13 @@ public class TkDataViewServiceImpl
68 71 @Override
69 72 @Transactional
70 73 public TkDataViewDTO saveDataView(TkDataViewDTO TkDataViewDTO) {
71   - TkDataViewEntity DataView =
  74 + TkDataViewEntity dataView =
72 75 TkDataViewDTO.getEntity(TkDataViewEntity.class);
73   - baseMapper.insert(DataView);
  76 + dataView.setState(0);
  77 + baseMapper.insert(dataView);
74 78 TkDataViewContentDTO contentDTO = new TkDataViewContentDTO();
75   - contentDTO.setTenantId(DataView.getTenantId());
76   - contentDTO.setViewId(DataView.getId());
  79 + contentDTO.setTenantId(dataView.getTenantId());
  80 + contentDTO.setViewId(dataView.getId());
77 81 contentDTO.setContent(
78 82 "<mxGraphModel><root><mxCell id=\"0\"/><mxCell id=\"1\" parent=\"0\"/></root></mxGraphModel>");
79 83 ytDataViewContentService.saveDataViewContent(contentDTO);
... ... @@ -114,4 +118,29 @@ public class TkDataViewServiceImpl
114 118 ? list.get(FastIotConstants.MagicNumber.ZERO)
115 119 : null;
116 120 }
  121 +
  122 +
  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;
  133 + }
  134 +
  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;
  145 + }
117 146 }
... ...
  1 +package org.thingsboard.server.dao.yunteng.mapper;
  2 +
  3 +import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +import org.apache.ibatis.annotations.Param;
  6 +import org.thingsboard.server.common.data.yunteng.dto.TkDataViewInterfaceDTO;
  7 +import org.thingsboard.server.dao.yunteng.entities.TkDataViewInterfaceEntity;
  8 +
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * @author tianfuLei
  13 + */
  14 +@Mapper
  15 +public interface TkDataViewInterfaceMapper extends BaseMapper<TkDataViewInterfaceEntity> {
  16 +
  17 + /**
  18 + * 根据ID获得详情
  19 + * @param ids
  20 + * @return
  21 + */
  22 + List<TkDataViewInterfaceDTO> getInterfaceDetails(@Param("ids") List<String> ids);
  23 +
  24 + /**
  25 + * 根据接口类型过滤
  26 + * @param type
  27 + * @param tenantIds
  28 + * @return
  29 + */
  30 + List<TkDataViewInterfaceDTO> filterByInterfaceType(@Param("type") String type,@Param("tenantIds") List<String> tenantIds);
  31 +
  32 + /**
  33 + * 查询所有数据
  34 + * @param tenantIds
  35 + * @return
  36 + */
  37 + List<TkDataViewInterfaceDTO> findAll(@Param("tenantIds") List<String> tenantIds);
  38 +
  39 +}
... ...
... ... @@ -11,6 +11,9 @@ import org.thingsboard.server.dao.yunteng.entities.TkDataViewEntity;
11 11 import java.util.List;
12 12 import java.util.Map;
13 13
  14 +/**
  15 + * @author tianfuLei
  16 + */
14 17 @Mapper
15 18 public interface TkDataViewMapper extends BaseMapper<TkDataViewEntity> {
16 19 IPage<TkDataViewDTO> getDataViewPage(
... ...
  1 +package org.thingsboard.server.dao.yunteng.service;
  2 +
  3 +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
  4 +import org.thingsboard.server.common.data.yunteng.dto.TkDataViewDTO;
  5 +import org.thingsboard.server.common.data.yunteng.dto.TkDataViewInterfaceDTO;
  6 +import org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentInfoDTO;
  7 +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
  8 +
  9 +import java.util.List;
  10 +import java.util.Map;
  11 +
  12 +/**
  13 + * @author tianfuLei
  14 + */
  15 +public interface TkDataViewInterfaceService {
  16 +
  17 + TkPageData<TkDataViewInterfaceDTO> page(Map<String, Object> queryMap);
  18 +
  19 + TkDataViewInterfaceDTO saveDataViewInterface(TkDataViewInterfaceDTO tkDataViewInterfaceDTO);
  20 +
  21 + TkDataViewInterfaceDTO updateDataViewInterface(TkDataViewInterfaceDTO tkDataViewInterfaceDTO);
  22 +
  23 + boolean deleteDataViewInterface(DeleteDTO deleteDTO);
  24 +
  25 + boolean publishInterface(String id, String tenantId);
  26 +
  27 + boolean cancelPublishInterface(String id, String tenantId);
  28 +
  29 + List<TkDataViewInterfaceDTO> getInterfaceDetails(List<String> ids);
  30 +
  31 + List<TkDataViewInterfaceDTO> filterByInterfaceType(String type,String tenantId);
  32 +
  33 + List<TkDataViewInterfaceDTO> findAll(String tenantId);
  34 +
  35 +}
... ...
... ... @@ -6,7 +6,9 @@ import org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentI
6 6 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
7 7
8 8 import java.util.Map;
9   -
  9 +/**
  10 + * @author tianfuLei
  11 + */
10 12 public interface TkDataViewService {
11 13 TkPageData<TkDataViewDTO> page(Map<String, Object> queryMap, boolean tenantAdmin);
12 14
... ... @@ -17,4 +19,8 @@ public interface TkDataViewService {
17 19 boolean deleteDataView(DeleteDTO deleteDTO);
18 20
19 21 TkDataViewContentInfoDTO getDataViewInfos(String id, String tenantId);
  22 +
  23 + boolean publishDataView(String id, String tenantId);
  24 +
  25 + boolean cancelPublishDataView(String id, String tenantId);
20 26 }
... ...
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +
  4 +<mapper namespace="org.thingsboard.server.dao.yunteng.mapper.TkDataViewInterfaceMapper">
  5 +
  6 + <resultMap id="dataViewInterfaceMap" type="org.thingsboard.server.common.data.yunteng.dto.TkDataViewInterfaceDTO">
  7 + <result property="id" column="id"/>
  8 + <result property="interfaceName" column="interface_name"/>
  9 + <result property="requestContentType" column="request_content_type"/>
  10 + <result property="requestOriginUrl" column="request_origin_url"/>
  11 +
  12 + <result property="requestHttpType" column="request_http_type"/>
  13 + <result property="requestUrl" column="request_url"/>
  14 + <result property="requestParams" column="request_params"/>
  15 + <result property="state" column="state"/>
  16 +
  17 + <result property="remark" column="remark"/>
  18 + <result property="updateTime" column="update_time"/>
  19 + <result property="createTime" column="create_time"/>
  20 + <result property="creator" column="creator"/>
  21 + <result property="tenantId" column="tenant_id"/>
  22 + <result property="updater" column="updater"/>
  23 + </resultMap>
  24 +
  25 + <sql id="columns">
  26 + id,interface_name, request_content_type, request_origin_url, request_http_type, request_url, request_params, state, creator, create_time, updater, update_time, tenant_id, remark
  27 + </sql>
  28 +
  29 + <select id="getInterfaceDetails" resultMap="dataViewInterfaceMap">
  30 + SELECT
  31 + <include refid="columns"/>
  32 + FROM tk_data_view_interface
  33 + <where>
  34 + <if test="ids !=null">
  35 + id IN
  36 + <foreach collection="ids" item="id" open="(" separator="," close=")">
  37 + #{id}
  38 + </foreach>
  39 + </if>
  40 + </where>
  41 + </select>
  42 +
  43 +
  44 + <select id="filterByInterfaceType" resultMap="dataViewInterfaceMap">
  45 + SELECT
  46 + <include refid="columns"/>
  47 + FROM tk_data_view_interface
  48 + <where>
  49 + <if test="type !=null and type !=''">
  50 + AND request_http_type = #{type}
  51 + </if>
  52 +
  53 + <if test="tenantIds !=null">
  54 + AND tenant_id IN
  55 + <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  56 + #{tenantId}
  57 + </foreach>
  58 + </if>
  59 + </where>
  60 + </select>
  61 +
  62 +
  63 + <select id="findAll" resultMap="dataViewInterfaceMap">
  64 + SELECT
  65 + <include refid="columns"/>
  66 + FROM tk_data_view_interface
  67 + <where>
  68 + <if test="tenantIds !=null">
  69 + AND tenant_id IN
  70 + <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  71 + #{tenantId}
  72 + </foreach>
  73 + </if>
  74 + </where>
  75 + </select>
  76 +
  77 +</mapper>
... ...