Showing
18 changed files
with
722 additions
and
0 deletions
application/src/main/java/org/thingsboard/server/controller/yunteng/YtDataBoardController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | ||
2 | + | ||
3 | +import io.swagger.annotations.Api; | ||
4 | +import io.swagger.annotations.ApiOperation; | ||
5 | +import lombok.RequiredArgsConstructor; | ||
6 | +import org.apache.commons.lang3.StringUtils; | ||
7 | +import org.quartz.SchedulerException; | ||
8 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
9 | +import org.springframework.validation.annotation.Validated; | ||
10 | +import org.springframework.web.bind.annotation.*; | ||
11 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
12 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | ||
13 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | ||
14 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | ||
15 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | ||
16 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
17 | +import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO; | ||
18 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
19 | +import org.thingsboard.server.common.data.yunteng.dto.board.ComponentLayoutDTO; | ||
20 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | ||
21 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | ||
22 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
23 | +import org.thingsboard.server.controller.BaseController; | ||
24 | +import org.thingsboard.server.dao.yunteng.service.YtDataBoardService; | ||
25 | + | ||
26 | +import java.util.HashMap; | ||
27 | +import java.util.List; | ||
28 | +import java.util.Map; | ||
29 | + | ||
30 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
31 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE; | ||
32 | + | ||
33 | +@RestController | ||
34 | +@RequiredArgsConstructor | ||
35 | +@PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | ||
36 | +@RequestMapping("api/yt/data_board") | ||
37 | +@Api(tags = {"数据看板"}) | ||
38 | +public class YtDataBoardController extends BaseController { | ||
39 | + private final YtDataBoardService ytDataBoardService; | ||
40 | + | ||
41 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | ||
42 | + @ApiOperation("分页查询") | ||
43 | + public YtPageData<DataBoardDTO> page( | ||
44 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
45 | + @RequestParam(PAGE) int page, | ||
46 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
47 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
48 | + throws ThingsboardException { | ||
49 | + Map<String, Object> queryMap = new HashMap<>(); | ||
50 | + queryMap.put(PAGE_SIZE, pageSize); | ||
51 | + queryMap.put(PAGE, page); | ||
52 | + queryMap.put(ORDER_FILED, orderBy); | ||
53 | + queryMap.put(ORDER_TYPE, orderType); | ||
54 | + queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId()); | ||
55 | + return ytDataBoardService.dataBoardPage(queryMap); | ||
56 | + } | ||
57 | + | ||
58 | + @DeleteMapping | ||
59 | + @ApiOperation(value = "删除数据看板") | ||
60 | + public ResponseResult<Boolean> deleteDataBoard( | ||
61 | + @Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { | ||
62 | + deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
63 | + return ResponseResult.success(ytDataBoardService.deleteDataBoard(deleteDTO)); | ||
64 | + } | ||
65 | + | ||
66 | + @PostMapping("/add") | ||
67 | + @ApiOperation(value = "新增数据看板") | ||
68 | + public ResponseResult<DataBoardDTO> save( | ||
69 | + @RequestBody @Validated(AddGroup.class) DataBoardDTO dataBoard) | ||
70 | + throws SchedulerException, ThingsboardException { | ||
71 | + if (StringUtils.isNotEmpty(dataBoard.getId())) { | ||
72 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
73 | + } | ||
74 | + return saveOrUpdate(dataBoard); | ||
75 | + } | ||
76 | + | ||
77 | + @PostMapping("/update") | ||
78 | + @ApiOperation(value = "编辑数据看板") | ||
79 | + public ResponseResult<DataBoardDTO> update( | ||
80 | + @RequestBody @Validated(UpdateGroup.class) DataBoardDTO dataBoard) | ||
81 | + throws SchedulerException, ThingsboardException { | ||
82 | + if (StringUtils.isEmpty(dataBoard.getId())) { | ||
83 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
84 | + } | ||
85 | + return saveOrUpdate(dataBoard); | ||
86 | + } | ||
87 | + | ||
88 | + @PostMapping("/{boardId}/layout/") | ||
89 | + @ApiOperation(value = "保存看板的组件布局") | ||
90 | + public ResponseResult<Boolean> saveLayout( | ||
91 | + @PathVariable("boardId") String boardId, @RequestBody List<ComponentLayoutDTO> layoutDTOList) | ||
92 | + throws ThingsboardException { | ||
93 | + return ResponseResult.success( | ||
94 | + ytDataBoardService.saveComponentLayout( | ||
95 | + layoutDTOList, boardId, getCurrentUser().getCurrentTenantId())); | ||
96 | + } | ||
97 | + | ||
98 | + private ResponseResult<DataBoardDTO> saveOrUpdate(DataBoardDTO dataBoard) | ||
99 | + throws ThingsboardException { | ||
100 | + dataBoard.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
101 | + return ResponseResult.success(ytDataBoardService.saveOrUpdateDataBoard(dataBoard)); | ||
102 | + } | ||
103 | +} |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtDataComponentController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | ||
2 | + | ||
3 | +import io.swagger.annotations.Api; | ||
4 | +import io.swagger.annotations.ApiOperation; | ||
5 | +import lombok.RequiredArgsConstructor; | ||
6 | +import org.apache.commons.lang3.StringUtils; | ||
7 | +import org.quartz.SchedulerException; | ||
8 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
9 | +import org.springframework.validation.annotation.Validated; | ||
10 | +import org.springframework.web.bind.annotation.*; | ||
11 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
12 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | ||
13 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | ||
14 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | ||
15 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | ||
16 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
17 | +import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO; | ||
18 | +import org.thingsboard.server.common.data.yunteng.dto.DataComponentDTO; | ||
19 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
20 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | ||
21 | +import org.thingsboard.server.controller.BaseController; | ||
22 | +import org.thingsboard.server.dao.yunteng.service.YtDataBoardService; | ||
23 | +import org.thingsboard.server.dao.yunteng.service.YtDataComponentService; | ||
24 | + | ||
25 | +import java.util.List; | ||
26 | + | ||
27 | +@RestController | ||
28 | +@RequiredArgsConstructor | ||
29 | +@PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | ||
30 | +@RequestMapping("api/yt/data_component") | ||
31 | +@Api(tags = {"数据组件"}) | ||
32 | +public class YtDataComponentController extends BaseController { | ||
33 | + private final YtDataComponentService ytDataComponentService; | ||
34 | + private final YtDataBoardService ytDataBoardService; | ||
35 | + | ||
36 | + @GetMapping("/{boardId}") | ||
37 | + @ApiOperation(value = "查询看板下的所有组件信息") | ||
38 | + public ResponseResult<List<DataComponentDTO>> getDataComponentsByBoardId( | ||
39 | + @PathVariable("boardId") String boardId) throws ThingsboardException { | ||
40 | + checkDataBoardInfo(boardId); | ||
41 | + return ResponseResult.success( | ||
42 | + ytDataComponentService.getDataComponentsByBoardId( | ||
43 | + getCurrentUser().getCurrentTenantId(), boardId)); | ||
44 | + } | ||
45 | + | ||
46 | + @PostMapping("/{boardId}/add") | ||
47 | + @ApiOperation(value = "新增组件") | ||
48 | + public ResponseResult<DataComponentDTO> save( | ||
49 | + @PathVariable("boardId") String boardId, | ||
50 | + @RequestBody @Validated(AddGroup.class) DataComponentDTO dataComponent) | ||
51 | + throws SchedulerException, ThingsboardException { | ||
52 | + if (StringUtils.isNotEmpty(dataComponent.getId())) { | ||
53 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
54 | + } | ||
55 | + checkDataBoardInfo(boardId); | ||
56 | + dataComponent.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
57 | + dataComponent.setDataBoardId(boardId); | ||
58 | + return saveOrUpdate(dataComponent); | ||
59 | + } | ||
60 | + | ||
61 | + @PostMapping("/{boardId}/update") | ||
62 | + @ApiOperation(value = "编辑组件") | ||
63 | + public ResponseResult<DataComponentDTO> update( | ||
64 | + @PathVariable("boardId") String boardId, | ||
65 | + @RequestBody @Validated(UpdateGroup.class) DataComponentDTO dataComponent) | ||
66 | + throws SchedulerException, ThingsboardException { | ||
67 | + if (StringUtils.isEmpty(dataComponent.getId())) { | ||
68 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
69 | + } | ||
70 | + checkDataBoardInfo(boardId); | ||
71 | + dataComponent.setDataBoardId(boardId); | ||
72 | + dataComponent.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
73 | + return saveOrUpdate(dataComponent); | ||
74 | + } | ||
75 | + | ||
76 | + @DeleteMapping | ||
77 | + @ApiOperation(value = "删除数据组件") | ||
78 | + public ResponseResult<Boolean> deleteDataBoard( | ||
79 | + @Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { | ||
80 | + deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
81 | + return ResponseResult.success(ytDataComponentService.deleteDataComponent(deleteDTO)); | ||
82 | + } | ||
83 | + | ||
84 | + private ResponseResult<DataComponentDTO> saveOrUpdate(DataComponentDTO dataComponent) | ||
85 | + throws ThingsboardException { | ||
86 | + dataComponent.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
87 | + return ResponseResult.success(ytDataComponentService.saveOrUpdateDataBoard(dataComponent)); | ||
88 | + } | ||
89 | + | ||
90 | + private void checkDataBoardInfo(String boardId) throws ThingsboardException { | ||
91 | + DataBoardDTO dto = | ||
92 | + ytDataBoardService.findDataBoardInfoById(boardId, getCurrentUser().getCurrentTenantId()); | ||
93 | + if (null == dto) { | ||
94 | + throw new YtDataValidationException(ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); | ||
95 | + } | ||
96 | + } | ||
97 | +} |
@@ -97,6 +97,10 @@ public final class ModelConstants { | @@ -97,6 +97,10 @@ public final class ModelConstants { | ||
97 | public static final String IOTFS_REPORT_FORM_CONFIG_NAME = "iotfs_report_form_config"; | 97 | public static final String IOTFS_REPORT_FORM_CONFIG_NAME = "iotfs_report_form_config"; |
98 | /** 报表生成记录表 */ | 98 | /** 报表生成记录表 */ |
99 | public static final String IOTFS_REPORT_GENERATE_RECORD_NAME = "iotfs_report_generate_record"; | 99 | public static final String IOTFS_REPORT_GENERATE_RECORD_NAME = "iotfs_report_generate_record"; |
100 | + /** 数据看板 */ | ||
101 | + public static final String IOTFS_DATA_BOARD_NAME = "iotfs_data_board"; | ||
102 | + /** 数据组件 */ | ||
103 | + public static final String IOTFS_DATA_COMPONENT_NAME = "iotfs_data_component"; | ||
100 | } | 104 | } |
101 | 105 | ||
102 | public static class TableFields { | 106 | public static class TableFields { |
@@ -6,4 +6,5 @@ public class QueryConstant { | @@ -6,4 +6,5 @@ public class QueryConstant { | ||
6 | public static final String ORDER_FILED = "orderFiled"; | 6 | public static final String ORDER_FILED = "orderFiled"; |
7 | public static final String ORDER_TYPE = "orderType"; | 7 | public static final String ORDER_TYPE = "orderType"; |
8 | public static final String CREATE_TIME="createTime"; | 8 | public static final String CREATE_TIME="createTime"; |
9 | + public static final String TENANT_ID = "tenantId"; | ||
9 | } | 10 | } |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/DataBoardDTO.java
0 → 100644
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.dto.board.ComponentLayoutDTO; | ||
8 | +import org.thingsboard.server.common.data.yunteng.enums.ViewType; | ||
9 | + | ||
10 | +import javax.validation.constraints.NotEmpty; | ||
11 | +import java.util.List; | ||
12 | + | ||
13 | +@EqualsAndHashCode(callSuper = true) | ||
14 | +@Data | ||
15 | +public class DataBoardDTO extends TenantDTO { | ||
16 | + @ApiModelProperty(value = "数据看板名称", required = true) | ||
17 | + @NotEmpty(message = "数据看板名称不能为空或者空字符串",groups = AddGroup.class) | ||
18 | + private String name; | ||
19 | + | ||
20 | + @ApiModelProperty(value = "视图类型") | ||
21 | + private ViewType viewType = ViewType.PRIVATE_VIEW; | ||
22 | + | ||
23 | + @ApiModelProperty(value = "公有视图URL") | ||
24 | + private String openUrl; | ||
25 | + | ||
26 | + @ApiModelProperty(value = "组件布局") | ||
27 | + private List<ComponentLayoutDTO> layout; | ||
28 | + | ||
29 | + @ApiModelProperty(value = "备注") | ||
30 | + private String remark; | ||
31 | +} |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/DataComponentDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | ||
2 | +import io.swagger.annotations.ApiModelProperty; | ||
3 | +import lombok.Data; | ||
4 | +import org.thingsboard.server.common.data.yunteng.dto.board.DataSourceInfoDTO; | ||
5 | + | ||
6 | +import java.util.List; | ||
7 | + | ||
8 | +@Data | ||
9 | +public class DataComponentDTO extends TenantDTO { | ||
10 | + @ApiModelProperty(value = "组件名称", required = true) | ||
11 | + private String name; | ||
12 | + | ||
13 | + @ApiModelProperty(value = "数据看板ID", required = true) | ||
14 | + private String dataBoardId; | ||
15 | + | ||
16 | + @ApiModelProperty(value = "前端组件ID", required = true) | ||
17 | + private String frontId; | ||
18 | + | ||
19 | + @ApiModelProperty(value = "数据源", required = true) | ||
20 | + private List<DataSourceInfoDTO> dataSource; | ||
21 | + | ||
22 | + @ApiModelProperty(value = "备注") | ||
23 | + private String remark; | ||
24 | +} |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/board/ComponentInfoDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto.board; | ||
2 | + | ||
3 | +import io.swagger.annotations.ApiModelProperty; | ||
4 | +import lombok.Data; | ||
5 | + | ||
6 | +import java.io.Serializable; | ||
7 | +import java.util.List; | ||
8 | + | ||
9 | +@Data | ||
10 | +public class ComponentInfoDTO implements Serializable { | ||
11 | + | ||
12 | + private static final long serialVersionUID = -1383423212190365330L; | ||
13 | + | ||
14 | + @ApiModelProperty(value = "数值字体颜色", required = true) | ||
15 | + private String fontColor; | ||
16 | + | ||
17 | + @ApiModelProperty(value = "数值单位") | ||
18 | + private String unit; | ||
19 | + | ||
20 | + @ApiModelProperty(value = "icon图标") | ||
21 | + private String icon; | ||
22 | + | ||
23 | + @ApiModelProperty(value = "icon图标颜色") | ||
24 | + private String iconColor; | ||
25 | + | ||
26 | + @ApiModelProperty(value = "梯度信息") | ||
27 | + private List<GradientInfo> gradientInfo; | ||
28 | + | ||
29 | + @Data | ||
30 | + class GradientInfo { | ||
31 | + | ||
32 | + @ApiModelProperty(value = "梯度key") | ||
33 | + private String key; | ||
34 | + | ||
35 | + @ApiModelProperty(value = "梯度值") | ||
36 | + private Integer value; | ||
37 | + } | ||
38 | +} |
1 | +package org.thingsboard.server.common.data.yunteng.dto.board; | ||
2 | + | ||
3 | +import io.swagger.annotations.ApiModelProperty; | ||
4 | +import lombok.Data; | ||
5 | + | ||
6 | +import java.io.Serializable; | ||
7 | + | ||
8 | +@Data | ||
9 | +public class ComponentLayoutDTO implements Serializable { | ||
10 | + | ||
11 | + private static final long serialVersionUID = 8166034261704947504L; | ||
12 | + | ||
13 | + @ApiModelProperty(value = "组件元素ID", required = true) | ||
14 | + private String id; | ||
15 | + | ||
16 | + @ApiModelProperty(value = "X坐标", required = true) | ||
17 | + private Integer x; | ||
18 | + | ||
19 | + @ApiModelProperty(value = "Y坐标", required = true) | ||
20 | + private Integer y; | ||
21 | + | ||
22 | + @ApiModelProperty(value = "宽度", required = true) | ||
23 | + private Integer w; | ||
24 | + | ||
25 | + @ApiModelProperty(value = "高度", required = true) | ||
26 | + private Integer h; | ||
27 | +} |
1 | +package org.thingsboard.server.common.data.yunteng.dto.board; | ||
2 | + | ||
3 | +import io.swagger.annotations.ApiModelProperty; | ||
4 | +import lombok.Data; | ||
5 | + | ||
6 | +import java.io.Serializable; | ||
7 | + | ||
8 | +@Data | ||
9 | +public class DataSourceInfoDTO implements Serializable { | ||
10 | + | ||
11 | + private static final long serialVersionUID = -8044628645505274772L; | ||
12 | + | ||
13 | + @ApiModelProperty(value = "组织ID", required = true) | ||
14 | + private String organizationId; | ||
15 | + | ||
16 | + @ApiModelProperty(value = "设备ID", required = true) | ||
17 | + private String deviceId; | ||
18 | + | ||
19 | + @ApiModelProperty(value = "属性", required = true) | ||
20 | + private String attribute; | ||
21 | + | ||
22 | + @ApiModelProperty(value = "设备重命名") | ||
23 | + private String deviceRename; | ||
24 | + | ||
25 | + @ApiModelProperty(value = "属性重命名") | ||
26 | + private String attributeRename; | ||
27 | + | ||
28 | + @ApiModelProperty(value = "组件选项信息") | ||
29 | + private ComponentInfoDTO componentInfo; | ||
30 | +} |
1 | +package org.thingsboard.server.dao.yunteng.entities; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.annotation.TableField; | ||
4 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
5 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | ||
6 | +import com.fasterxml.jackson.databind.JsonNode; | ||
7 | +import lombok.Data; | ||
8 | +import lombok.EqualsAndHashCode; | ||
9 | +import org.apache.ibatis.type.EnumTypeHandler; | ||
10 | +import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | ||
11 | +import org.thingsboard.server.common.data.yunteng.enums.ViewType; | ||
12 | +@EqualsAndHashCode(callSuper = true) | ||
13 | +@TableName(value = ModelConstants.Table.IOTFS_DATA_BOARD_NAME, autoResultMap = true) | ||
14 | +@Data | ||
15 | +public class DataBoard extends TenantBaseEntity { | ||
16 | + | ||
17 | + private static final long serialVersionUID = 1438007769925112807L; | ||
18 | + | ||
19 | + private String name; | ||
20 | + | ||
21 | + @TableField(typeHandler = EnumTypeHandler.class) | ||
22 | + private ViewType viewType; | ||
23 | + | ||
24 | + private String openUrl; | ||
25 | + | ||
26 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
27 | + private JsonNode layout; | ||
28 | + | ||
29 | + private String remark; | ||
30 | +} |
1 | +package org.thingsboard.server.dao.yunteng.entities; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.annotation.TableField; | ||
4 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
5 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | ||
6 | +import com.fasterxml.jackson.databind.JsonNode; | ||
7 | +import lombok.Data; | ||
8 | +import lombok.EqualsAndHashCode; | ||
9 | +import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | ||
10 | + | ||
11 | +@Data | ||
12 | +@EqualsAndHashCode(callSuper = true) | ||
13 | +@TableName(value = ModelConstants.Table.IOTFS_DATA_COMPONENT_NAME, autoResultMap = true) | ||
14 | +public class DataComponent extends TenantBaseEntity { | ||
15 | + | ||
16 | + private static final long serialVersionUID = -1500982711916168023L; | ||
17 | + /** 组件名称 */ | ||
18 | + private String name; | ||
19 | + | ||
20 | + /** 数据看板ID */ | ||
21 | + private String dataBoardId; | ||
22 | + | ||
23 | + /** 前端组件ID */ | ||
24 | + private String frontId; | ||
25 | + | ||
26 | + /** 数据源 */ | ||
27 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
28 | + private JsonNode dataSource; | ||
29 | + | ||
30 | + /** 备注 */ | ||
31 | + private String remark; | ||
32 | +} |
1 | +package org.thingsboard.server.dao.yunteng.impl; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
5 | +import com.fasterxml.jackson.databind.JsonNode; | ||
6 | +import org.apache.commons.lang3.StringUtils; | ||
7 | +import org.springframework.stereotype.Service; | ||
8 | +import org.springframework.transaction.annotation.Transactional; | ||
9 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
10 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | ||
11 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
12 | +import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO; | ||
13 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
14 | +import org.thingsboard.server.common.data.yunteng.dto.board.ComponentLayoutDTO; | ||
15 | +import org.thingsboard.server.common.data.yunteng.enums.ViewType; | ||
16 | +import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; | ||
17 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
18 | +import org.thingsboard.server.dao.yunteng.entities.DataBoard; | ||
19 | +import org.thingsboard.server.dao.yunteng.mapper.DataBoardMapper; | ||
20 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ||
21 | +import org.thingsboard.server.dao.yunteng.service.YtDataBoardService; | ||
22 | + | ||
23 | +import java.util.List; | ||
24 | +import java.util.Map; | ||
25 | +import java.util.Optional; | ||
26 | + | ||
27 | +@Service | ||
28 | +public class YtDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper, DataBoard> | ||
29 | + implements YtDataBoardService { | ||
30 | + @Override | ||
31 | + public YtPageData<DataBoardDTO> dataBoardPage(Map<String, Object> queryMap) { | ||
32 | + String tenantId = | ||
33 | + Optional.ofNullable(queryMap.get("tenantId")) | ||
34 | + .map(obj -> queryMap.get("tenantId").toString()) | ||
35 | + .orElseThrow( | ||
36 | + () -> { | ||
37 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
38 | + }); | ||
39 | + IPage<DataBoard> page = | ||
40 | + baseMapper.selectPage( | ||
41 | + getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false), | ||
42 | + new LambdaQueryWrapper<DataBoard>().eq(DataBoard::getTenantId, tenantId)); | ||
43 | + return getPageData(page, DataBoardDTO.class); | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + @Transactional | ||
48 | + public DataBoardDTO saveOrUpdateDataBoard(DataBoardDTO dataBoardDTO) { | ||
49 | + DataBoard dataBoard = dataBoardDTO.getEntity(DataBoard.class); | ||
50 | + if (StringUtils.isEmpty(dataBoardDTO.getId())) { | ||
51 | + try { | ||
52 | + baseMapper.insert(dataBoard); | ||
53 | + } catch (Exception e) { | ||
54 | + e.printStackTrace(); | ||
55 | + } | ||
56 | + } else { | ||
57 | + DataBoard board = | ||
58 | + baseMapper.selectOne( | ||
59 | + new LambdaQueryWrapper<DataBoard>() | ||
60 | + .eq(DataBoard::getId, dataBoardDTO.getId()) | ||
61 | + .eq(DataBoard::getTenantId, dataBoardDTO.getTenantId())); | ||
62 | + Optional.ofNullable(board) | ||
63 | + .map(obj -> baseMapper.updateById(dataBoard)) | ||
64 | + .orElseThrow( | ||
65 | + () -> { | ||
66 | + throw new YtDataValidationException(ErrorMessage.INTERNAL_ERROR.getMessage()); | ||
67 | + }); | ||
68 | + } | ||
69 | + // 公有视图,生成访问路径 | ||
70 | + if (dataBoard.getViewType() == ViewType.PUBLIC_VIEW) {} | ||
71 | + | ||
72 | + return dataBoard.getDTO(DataBoardDTO.class); | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + @Transactional | ||
77 | + public boolean deleteDataBoard(DeleteDTO deleteDTO) { | ||
78 | + return baseMapper.delete( | ||
79 | + new LambdaQueryWrapper<DataBoard>() | ||
80 | + .eq(DataBoard::getTenantId, deleteDTO.getTenantId()) | ||
81 | + .in(DataBoard::getId, deleteDTO.getIds())) | ||
82 | + > FastIotConstants.MagicNumber.ZERO; | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + @Transactional | ||
87 | + public boolean saveComponentLayout( | ||
88 | + List<ComponentLayoutDTO> layoutDTOList, String boardId, String tenantId) { | ||
89 | + DataBoard dataBoard = | ||
90 | + baseMapper.selectOne( | ||
91 | + new LambdaQueryWrapper<DataBoard>() | ||
92 | + .eq(DataBoard::getTenantId, tenantId) | ||
93 | + .eq(DataBoard::getId, boardId)); | ||
94 | + return Optional.ofNullable(dataBoard) | ||
95 | + .map( | ||
96 | + obj -> { | ||
97 | + dataBoard.setLayout(JacksonUtil.convertValue(layoutDTOList, JsonNode.class)); | ||
98 | + return baseMapper.updateById(dataBoard) > 0; | ||
99 | + }) | ||
100 | + .orElseThrow( | ||
101 | + () -> { | ||
102 | + throw new YtDataValidationException( | ||
103 | + ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); | ||
104 | + }); | ||
105 | + } | ||
106 | + | ||
107 | + @Override | ||
108 | + public DataBoardDTO findDataBoardInfoById(String id, String tenantId) { | ||
109 | + return Optional.ofNullable( | ||
110 | + baseMapper.selectOne( | ||
111 | + new LambdaQueryWrapper<DataBoard>() | ||
112 | + .eq(DataBoard::getTenantId, tenantId) | ||
113 | + .eq(DataBoard::getId, id))) | ||
114 | + .map(obj -> obj.getDTO(DataBoardDTO.class)) | ||
115 | + .orElse(null); | ||
116 | + } | ||
117 | +} |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/YtDataComponentServiceImpl.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.impl; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
4 | +import com.fasterxml.jackson.databind.JsonNode; | ||
5 | +import org.apache.commons.lang3.StringUtils; | ||
6 | +import org.springframework.stereotype.Service; | ||
7 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
8 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | ||
9 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
10 | +import org.thingsboard.server.common.data.yunteng.dto.DataComponentDTO; | ||
11 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
12 | +import org.thingsboard.server.common.data.yunteng.dto.board.DataSourceInfoDTO; | ||
13 | +import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; | ||
14 | +import org.thingsboard.server.dao.yunteng.entities.DataComponent; | ||
15 | +import org.thingsboard.server.dao.yunteng.mapper.DataComponentMapper; | ||
16 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ||
17 | +import org.thingsboard.server.dao.yunteng.service.YtDataComponentService; | ||
18 | + | ||
19 | +import java.util.ArrayList; | ||
20 | +import java.util.List; | ||
21 | +import java.util.Optional; | ||
22 | +import java.util.stream.Collectors; | ||
23 | + | ||
24 | +@Service | ||
25 | +public class YtDataComponentServiceImpl | ||
26 | + extends AbstractBaseService<DataComponentMapper, DataComponent> | ||
27 | + implements YtDataComponentService { | ||
28 | + @Override | ||
29 | + public List<DataComponentDTO> getDataComponentsByBoardId(String tenantId, String boardId) { | ||
30 | + List<DataComponent> dataComponentList = | ||
31 | + baseMapper.selectList( | ||
32 | + new LambdaQueryWrapper<DataComponent>() | ||
33 | + .eq(DataComponent::getTenantId, tenantId) | ||
34 | + .eq(DataComponent::getDataBoardId, boardId)); | ||
35 | + if (dataComponentList.isEmpty()) { | ||
36 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
37 | + } | ||
38 | + return dataComponentList.stream() | ||
39 | + .map( | ||
40 | + obj -> { | ||
41 | + DataComponentDTO dto = obj.getDTO(DataComponentDTO.class); | ||
42 | + List<DataSourceInfoDTO> list = new ArrayList<>(); | ||
43 | + if (null != obj.getDataSource() && obj.getDataSource().isArray()) { | ||
44 | + for (JsonNode jsonNode : obj.getDataSource()) { | ||
45 | + list.add(JacksonUtil.convertValue(jsonNode, DataSourceInfoDTO.class)); | ||
46 | + } | ||
47 | + } | ||
48 | + dto.setDataSource(list); | ||
49 | + return dto; | ||
50 | + }) | ||
51 | + .collect(Collectors.toList()); | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public DataComponentDTO saveOrUpdateDataBoard(DataComponentDTO dataComponentDTO) { | ||
56 | + DataComponent dataComponent = dataComponentDTO.getEntity(DataComponent.class); | ||
57 | + dataComponent.setDataSource( | ||
58 | + JacksonUtil.convertValue(dataComponentDTO.getDataSource(), JsonNode.class)); | ||
59 | + if (StringUtils.isEmpty(dataComponentDTO.getId())) { | ||
60 | + baseMapper.insert(dataComponent); | ||
61 | + } else { | ||
62 | + DataComponent queryEntity = | ||
63 | + baseMapper.selectOne( | ||
64 | + new LambdaQueryWrapper<DataComponent>() | ||
65 | + .eq(DataComponent::getId, dataComponentDTO.getId()) | ||
66 | + .eq(DataComponent::getTenantId, dataComponentDTO.getTenantId())); | ||
67 | + Optional.ofNullable(queryEntity) | ||
68 | + .map(obj -> baseMapper.updateById(dataComponent)) | ||
69 | + .orElseThrow( | ||
70 | + () -> { | ||
71 | + throw new YtDataValidationException( | ||
72 | + ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); | ||
73 | + }); | ||
74 | + } | ||
75 | + return dataComponent.getDTO(DataComponentDTO.class); | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public boolean deleteDataComponent(DeleteDTO deleteDTO) { | ||
80 | + return baseMapper.delete( | ||
81 | + new LambdaQueryWrapper<DataComponent>() | ||
82 | + .eq(DataComponent::getTenantId, deleteDTO.getTenantId()) | ||
83 | + .in(DataComponent::getId, deleteDTO.getIds())) | ||
84 | + > FastIotConstants.MagicNumber.ZERO; | ||
85 | + } | ||
86 | +} |
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.thingsboard.server.dao.yunteng.entities.DataBoard; | ||
6 | + | ||
7 | +@Mapper | ||
8 | +public interface DataBoardMapper extends BaseMapper<DataBoard> { | ||
9 | +} |
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.thingsboard.server.dao.yunteng.entities.DataComponent; | ||
6 | + | ||
7 | +@Mapper | ||
8 | +public interface DataComponentMapper extends BaseMapper<DataComponent> {} |
1 | +package org.thingsboard.server.dao.yunteng.service; | ||
2 | + | ||
3 | +import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO; | ||
4 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
5 | +import org.thingsboard.server.common.data.yunteng.dto.board.ComponentLayoutDTO; | ||
6 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
7 | + | ||
8 | +import java.util.List; | ||
9 | +import java.util.Map; | ||
10 | + | ||
11 | +public interface YtDataBoardService { | ||
12 | + /** | ||
13 | + * 数据看板分页 | ||
14 | + * | ||
15 | + * @param queryMap 分页查询条件 | ||
16 | + * @return 分页数据 | ||
17 | + */ | ||
18 | + YtPageData<DataBoardDTO> dataBoardPage(Map<String, Object> queryMap); | ||
19 | + | ||
20 | + /** | ||
21 | + * 修改或保存数据看板 | ||
22 | + * | ||
23 | + * @param dataBoardDTO 数据看板信息 | ||
24 | + */ | ||
25 | + DataBoardDTO saveOrUpdateDataBoard(DataBoardDTO dataBoardDTO); | ||
26 | + | ||
27 | + /** | ||
28 | + * 删除数据看板 | ||
29 | + * | ||
30 | + * @param deleteDTO 删除IDS | ||
31 | + */ | ||
32 | + boolean deleteDataBoard(DeleteDTO deleteDTO); | ||
33 | + | ||
34 | + /** | ||
35 | + * 保存看板的组件布局 | ||
36 | + * @param layoutDTOList 组件布局 | ||
37 | + * @param boardId 看板ID | ||
38 | + * @return true成功 false失败 | ||
39 | + */ | ||
40 | + boolean saveComponentLayout(List<ComponentLayoutDTO> layoutDTOList,String boardId,String tenantId); | ||
41 | + | ||
42 | + | ||
43 | + /** | ||
44 | + * 根据租户ID和看板ID查询看板信息 | ||
45 | + * @param id | ||
46 | + * @param tenantId | ||
47 | + * @return | ||
48 | + */ | ||
49 | + DataBoardDTO findDataBoardInfoById(String id,String tenantId); | ||
50 | +} |
1 | +package org.thingsboard.server.dao.yunteng.service; | ||
2 | + | ||
3 | +import org.thingsboard.server.common.data.yunteng.dto.DataComponentDTO; | ||
4 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
5 | + | ||
6 | +import java.util.List; | ||
7 | + | ||
8 | +public interface YtDataComponentService { | ||
9 | + /** | ||
10 | + * 查询数据看板下的所有组件 | ||
11 | + * @param tenantId 租户id | ||
12 | + * @param boardId 看板ID | ||
13 | + * @return 组件列表 | ||
14 | + */ | ||
15 | + List<DataComponentDTO> getDataComponentsByBoardId(String tenantId, String boardId); | ||
16 | + | ||
17 | + /** | ||
18 | + * 修改或保存数据看板 | ||
19 | + * | ||
20 | + * @param dataComponentDTO 数据看板信息 | ||
21 | + */ | ||
22 | + DataComponentDTO saveOrUpdateDataBoard(DataComponentDTO dataComponentDTO); | ||
23 | + | ||
24 | + /** | ||
25 | + * 删除组件 | ||
26 | + * | ||
27 | + * @param deleteDTO 删除IDS | ||
28 | + */ | ||
29 | + boolean deleteDataComponent(DeleteDTO deleteDTO); | ||
30 | +} |