Showing
11 changed files
with
447 additions
and
16 deletions
1 | +package org.thingsboard.server.controller.yunteng; | ||
2 | + | ||
3 | +import io.swagger.annotations.Api; | ||
4 | +import lombok.RequiredArgsConstructor; | ||
5 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
6 | +import org.springframework.validation.annotation.Validated; | ||
7 | +import org.springframework.web.bind.annotation.*; | ||
8 | +import org.thingsboard.server.common.data.StringUtils; | ||
9 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
10 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | ||
11 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | ||
12 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | ||
13 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
14 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | ||
15 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
16 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
17 | +import org.thingsboard.server.common.data.yunteng.dto.ReportFormConfigDTO; | ||
18 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | ||
19 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | ||
20 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
21 | +import org.thingsboard.server.controller.BaseController; | ||
22 | +import org.thingsboard.server.dao.yunteng.service.YtReportFormConfigService; | ||
23 | + | ||
24 | +import java.util.HashMap; | ||
25 | + | ||
26 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
27 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE; | ||
28 | + | ||
29 | +@RestController | ||
30 | +@RequestMapping("api/yt/report_form/config") | ||
31 | +@Api(tags = "报表配置信息") | ||
32 | +@RequiredArgsConstructor | ||
33 | +@PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | ||
34 | +public class YtReportFormConfigController extends BaseController { | ||
35 | + | ||
36 | + private final YtReportFormConfigService reportFormConfigService; | ||
37 | + | ||
38 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | ||
39 | + public YtPageData<ReportFormConfigDTO> page( | ||
40 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
41 | + @RequestParam(PAGE) int page, | ||
42 | + @RequestParam(value = "name", required = false) String name, | ||
43 | + @RequestParam(value = "organizationId", required = false) String organizationId, | ||
44 | + @RequestParam(value = "status", required = false) Integer status, | ||
45 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
46 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
47 | + throws ThingsboardException { | ||
48 | + | ||
49 | + HashMap<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("name", name); | ||
54 | + queryMap.put("organizationId", organizationId); | ||
55 | + queryMap.put("status", status); | ||
56 | + queryMap.put("tenantId", getCurrentUser().getCurrentTenantId()); | ||
57 | + if (orderType != null) { | ||
58 | + queryMap.put(ORDER_TYPE, orderType.name()); | ||
59 | + } | ||
60 | + return reportFormConfigService.page(queryMap); | ||
61 | + } | ||
62 | + | ||
63 | + @PostMapping | ||
64 | + public ResponseResult<ReportFormConfigDTO> saveReportFromConfig( | ||
65 | + @Validated({AddGroup.class}) @RequestBody ReportFormConfigDTO configDTO) | ||
66 | + throws ThingsboardException { | ||
67 | + if (StringUtils.isNotEmpty(configDTO.getId())) { | ||
68 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
69 | + } | ||
70 | + return saveOrUpdate(configDTO); | ||
71 | + } | ||
72 | + | ||
73 | + @PutMapping | ||
74 | + public ResponseResult<ReportFormConfigDTO> updateReportFromConfig( | ||
75 | + @Validated({UpdateGroup.class}) @RequestBody ReportFormConfigDTO configDTO) | ||
76 | + throws ThingsboardException { | ||
77 | + return saveOrUpdate(configDTO); | ||
78 | + } | ||
79 | + | ||
80 | + @PutMapping("/{id}/{status}") | ||
81 | + public ResponseResult<ReportFormConfigDTO> updateStatusById( | ||
82 | + @PathVariable String id, @PathVariable Integer status) throws ThingsboardException { | ||
83 | + return ResponseResult.success( | ||
84 | + reportFormConfigService.updateStatusById( | ||
85 | + getCurrentUser().getCurrentTenantId(), status, id)); | ||
86 | + } | ||
87 | + | ||
88 | + @DeleteMapping | ||
89 | + public ResponseResult<Boolean> deleteMessageConfig( | ||
90 | + @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) { | ||
91 | + return reportFormConfigService.deleteReportFromConfig(deleteDTO) | ||
92 | + ? ResponseResult.success(FastIotConstants.StateValue.DELETE_SUCCESS) | ||
93 | + : ResponseResult.failed(FastIotConstants.StateValue.DELETE_FAILED); | ||
94 | + } | ||
95 | + | ||
96 | + private ResponseResult<ReportFormConfigDTO> saveOrUpdate(ReportFormConfigDTO configDTO) | ||
97 | + throws ThingsboardException { | ||
98 | + configDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
99 | + ReportFormConfigDTO newDTO = reportFormConfigService.saveOrUpdateReportFromConfig(configDTO); | ||
100 | + return ResponseResult.success(newDTO); | ||
101 | + } | ||
102 | +} |
@@ -89,6 +89,8 @@ public final class ModelConstants { | @@ -89,6 +89,8 @@ public final class ModelConstants { | ||
89 | public static final String IOTFS_THIRD_USER_TABLE_NAME = "iotfs_third_user"; | 89 | public static final String IOTFS_THIRD_USER_TABLE_NAME = "iotfs_third_user"; |
90 | /** frp内网穿透信息表 */ | 90 | /** frp内网穿透信息表 */ |
91 | public static final String IOTFS_FRP_INFO_NAME = "iotfs_frp_info"; | 91 | public static final String IOTFS_FRP_INFO_NAME = "iotfs_frp_info"; |
92 | + /** 报表配置表 */ | ||
93 | + public static final String IOTFS_REPORT_FORM_CONFIG_NAME = "iotfs_report_form_config"; | ||
92 | } | 94 | } |
93 | 95 | ||
94 | public static class TableFields { | 96 | public static class TableFields { |
@@ -55,7 +55,7 @@ public enum ErrorMessage { | @@ -55,7 +55,7 @@ public enum ErrorMessage { | ||
55 | NOT_EXITED_OR_PERMISSION(400036,"【%s】没有修改权限或不存在"), | 55 | NOT_EXITED_OR_PERMISSION(400036,"【%s】没有修改权限或不存在"), |
56 | FILE_NOT_FOUND(400036,"文件未找到"), | 56 | FILE_NOT_FOUND(400036,"文件未找到"), |
57 | STORE_FILE_FAILED(400037,"文件存储失败"), | 57 | STORE_FILE_FAILED(400037,"文件存储失败"), |
58 | - NOT_BELONG_CURRENT_TENANT(400038,"不属于当前租户"), | 58 | + NOT_BELONG_CURRENT_TENANT(400038,"该数据不属于当前租户"), |
59 | DEVICE_LOSED(400039,"设备相关参数丢失"), | 59 | DEVICE_LOSED(400039,"设备相关参数丢失"), |
60 | SCENE_REACT_NOT_EXTIED(400040,"场景联动不存在"), | 60 | SCENE_REACT_NOT_EXTIED(400040,"场景联动不存在"), |
61 | DEVICE_USED_SCENE_REACT(400041,"场景联动【%s】正在使用该设备"), | 61 | DEVICE_USED_SCENE_REACT(400041,"场景联动【%s】正在使用该设备"), |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/ReportFormConfigDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | ||
2 | + | ||
3 | +import com.fasterxml.jackson.databind.JsonNode; | ||
4 | +import io.swagger.annotations.ApiModel; | ||
5 | +import io.swagger.annotations.ApiModelProperty; | ||
6 | +import lombok.Data; | ||
7 | +import lombok.EqualsAndHashCode; | ||
8 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | ||
9 | +import org.thingsboard.server.common.data.yunteng.dto.request.QueryConditionDTO; | ||
10 | + | ||
11 | +import javax.validation.constraints.NotEmpty; | ||
12 | +import javax.validation.constraints.NotNull; | ||
13 | +import java.util.List; | ||
14 | + | ||
15 | +@EqualsAndHashCode(callSuper = false) | ||
16 | +@Data | ||
17 | +@ApiModel("报表配置") | ||
18 | +public class ReportFormConfigDTO extends TenantDTO { | ||
19 | + | ||
20 | + /** 报表配置名称 */ | ||
21 | + @ApiModelProperty(value = "报表配置名称", required = true) | ||
22 | + @NotEmpty(message = "报表配置名称不能为null或空字符串", groups = AddGroup.class) | ||
23 | + private String name; | ||
24 | + | ||
25 | + /** 组织ID */ | ||
26 | + @ApiModelProperty(value = "组织ID", required = true) | ||
27 | + @NotEmpty(message = "组织不能为null或空字符串", groups = AddGroup.class) | ||
28 | + private String organizationId; | ||
29 | + | ||
30 | + /** 执行方式:0立即执行 1定时执行 */ | ||
31 | + @ApiModelProperty(value = "执行方式", required = true) | ||
32 | + @NotNull(message = "执行方式不能为null", groups = AddGroup.class) | ||
33 | + private Integer executeWay; | ||
34 | + | ||
35 | + /** cron表达式:执行方式 1 生效 */ | ||
36 | + private String executeContent; | ||
37 | + | ||
38 | + /** 设备:json数组格式 */ | ||
39 | + @ApiModelProperty(value = "执行设备", required = true) | ||
40 | + @NotNull(message = "执行设备不能为null", groups = AddGroup.class) | ||
41 | + private List<String> devices; | ||
42 | + | ||
43 | + /** 属性性质:0共有属性 1全部属性 */ | ||
44 | + @ApiModelProperty(value = "属性性质", required = true) | ||
45 | + @NotNull(message = "属性性质不能为null", groups = AddGroup.class) | ||
46 | + private Integer attributeNature; | ||
47 | + | ||
48 | + /** 属性 */ | ||
49 | + @ApiModelProperty(value = "属性", required = true) | ||
50 | + @NotNull(message = "属性不能为null", groups = AddGroup.class) | ||
51 | + private List<String> attributes; | ||
52 | + | ||
53 | + /** 数据对比:0历史数据 1环比 2同比 */ | ||
54 | + @ApiModelProperty(value = "数据对比", required = true) | ||
55 | + @NotNull(message = "数据对比不能为null", groups = AddGroup.class) | ||
56 | + private Integer dataCompare; | ||
57 | + | ||
58 | + /** 数据周期:单位毫秒 */ | ||
59 | + @ApiModelProperty(value = "开始时间", required = true) | ||
60 | + @NotNull(message = "开始时间不能为null", groups = AddGroup.class) | ||
61 | + private Long startTs; | ||
62 | + | ||
63 | + /** 时间间隔:单位毫秒 */ | ||
64 | + @ApiModelProperty(value = "结束时间", required = true) | ||
65 | + @NotNull(message = "结束时间不能为null", groups = AddGroup.class) | ||
66 | + private Long endTs ; | ||
67 | + | ||
68 | + @ApiModelProperty(value = "查询条件", required = true) | ||
69 | + @NotNull(message = "查询条件不能为null", groups = AddGroup.class) | ||
70 | + private QueryConditionDTO queryCondition; | ||
71 | + | ||
72 | + /** 配置状态:0禁用 1启用 */ | ||
73 | + @ApiModelProperty(value = "配置状态:0禁用 1启用") | ||
74 | + private Integer status; | ||
75 | + | ||
76 | + /** 备注 */ | ||
77 | + private String remark; | ||
78 | +} |
1 | +package org.thingsboard.server.common.data.yunteng.dto.request; | ||
2 | + | ||
3 | +import io.swagger.annotations.ApiModel; | ||
4 | +import io.swagger.annotations.ApiModelProperty; | ||
5 | +import lombok.Data; | ||
6 | + | ||
7 | +@Data | ||
8 | +@ApiModel(value = "查询条件") | ||
9 | +public class QueryConditionDTO { | ||
10 | + @ApiModelProperty("聚合间隔:单位毫秒") | ||
11 | + private Long interval; | ||
12 | + | ||
13 | + @ApiModelProperty("查询的最大数量:该参数仅在'agg'参数设置为'NONE'的情况下使用") | ||
14 | + private Integer limit; | ||
15 | + | ||
16 | + @ApiModelProperty("聚合条件:AVG, COUNT, MAX, MIN, NONE, SUM") | ||
17 | + private String agg; | ||
18 | + | ||
19 | + @ApiModelProperty("排序:ASC, DESC") | ||
20 | + private String orderBy; | ||
21 | + | ||
22 | + @ApiModelProperty("启用/禁用遥测值到字符串的转换。默认情况下启用转换。设置参数为'true'以禁用转换") | ||
23 | + private boolean useStrictDataTypes; | ||
24 | +} |
@@ -4,19 +4,16 @@ import lombok.Getter; | @@ -4,19 +4,16 @@ import lombok.Getter; | ||
4 | import lombok.Setter; | 4 | import lombok.Setter; |
5 | 5 | ||
6 | public enum StatusEnum { | 6 | public enum StatusEnum { |
7 | - OFFLINE("离线",0), | ||
8 | - ONLINE("在线",1); | 7 | + OFFLINE("离线", 0), |
8 | + ONLINE("在线", 1), | ||
9 | + ENABLE("启用", 1), | ||
10 | + DISABLE("禁用", 0); | ||
9 | 11 | ||
10 | - @Getter | ||
11 | - @Setter | ||
12 | - private String name; | ||
13 | - @Getter | ||
14 | - @Setter | ||
15 | - private Integer index; | ||
16 | - | ||
17 | - StatusEnum(String name, Integer index) { | ||
18 | - this.name = name; | ||
19 | - this.index = index; | ||
20 | - } | 12 | + @Getter @Setter private String name; |
13 | + @Getter @Setter private Integer index; | ||
21 | 14 | ||
15 | + StatusEnum(String name, Integer index) { | ||
16 | + this.name = name; | ||
17 | + this.index = index; | ||
18 | + } | ||
22 | } | 19 | } |
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 com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | ||
7 | +import com.fasterxml.jackson.databind.JsonNode; | ||
8 | +import lombok.Data; | ||
9 | +import lombok.EqualsAndHashCode; | ||
10 | +import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | ||
11 | + | ||
12 | +@Data | ||
13 | +@EqualsAndHashCode(callSuper = true) | ||
14 | +@TableName(value = ModelConstants.Table.IOTFS_REPORT_FORM_CONFIG_NAME, autoResultMap = true) | ||
15 | +public class ReportFormConfig extends TenantBaseEntity { | ||
16 | + | ||
17 | + private static final long serialVersionUID = -1678849271872511953L; | ||
18 | + | ||
19 | + /** 报表配置名称 */ | ||
20 | + private String name; | ||
21 | + | ||
22 | + /** 组织ID */ | ||
23 | + private String organizationId; | ||
24 | + | ||
25 | + /** 执行方式:0立即执行 1定时执行 */ | ||
26 | + private Integer executeWay; | ||
27 | + | ||
28 | + /** cron表达式:执行方式 1 生效 修改时允许设置为null*/ | ||
29 | + @TableField(updateStrategy = FieldStrategy.IGNORED) | ||
30 | + private String executeContent; | ||
31 | + | ||
32 | + /** 设备:json数组格式 */ | ||
33 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
34 | + private JsonNode devices; | ||
35 | + | ||
36 | + /** 属性性质:0共有属性 1全部属性 */ | ||
37 | + private Integer attributeNature; | ||
38 | + | ||
39 | + /** 属性 */ | ||
40 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
41 | + private JsonNode attributes; | ||
42 | + | ||
43 | + /** 数据对比:0历史数据 1环比 2同比 */ | ||
44 | + private Integer dataCompare; | ||
45 | + | ||
46 | + /** 查询开始时间:单位毫秒 */ | ||
47 | + private Long startTs; | ||
48 | + | ||
49 | + /** 查询结束时间:单位毫秒 */ | ||
50 | + private Long endTs ; | ||
51 | + | ||
52 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
53 | + private JsonNode queryCondition; | ||
54 | + | ||
55 | + /** 配置状态:0禁用 1启用 */ | ||
56 | + private Integer status; | ||
57 | + | ||
58 | + /** 备注 */ | ||
59 | + private String remark; | ||
60 | +} |
@@ -3,8 +3,8 @@ package org.thingsboard.server.dao.yunteng.impl; | @@ -3,8 +3,8 @@ package org.thingsboard.server.dao.yunteng.impl; | ||
3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | import com.baomidou.mybatisplus.core.metadata.IPage; | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | import com.fasterxml.jackson.databind.node.ObjectNode; | 5 | import com.fasterxml.jackson.databind.node.ObjectNode; |
6 | +import lombok.RequiredArgsConstructor; | ||
6 | import org.apache.commons.lang3.StringUtils; | 7 | import org.apache.commons.lang3.StringUtils; |
7 | -import org.springframework.beans.factory.annotation.Autowired; | ||
8 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
9 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | 9 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
10 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 10 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
@@ -24,10 +24,11 @@ import java.util.Map; | @@ -24,10 +24,11 @@ import java.util.Map; | ||
24 | import java.util.Optional; | 24 | import java.util.Optional; |
25 | 25 | ||
26 | @Service | 26 | @Service |
27 | +@RequiredArgsConstructor | ||
27 | public class YtFrpInfoServiceImpl extends AbstractBaseService<FrpInfoMapper, FrpInfo> | 28 | public class YtFrpInfoServiceImpl extends AbstractBaseService<FrpInfoMapper, FrpInfo> |
28 | implements YtFrpInfoService { | 29 | implements YtFrpInfoService { |
29 | 30 | ||
30 | - @Autowired private FrpServerProperties frpServerProperties; | 31 | + private final FrpServerProperties frpServerProperties; |
31 | 32 | ||
32 | @Override | 33 | @Override |
33 | public YtPageData<FrpInfoDTO> page(Map<String, Object> queryMap) { | 34 | public YtPageData<FrpInfoDTO> page(Map<String, Object> queryMap) { |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/YtReportFromConfigServiceImpl.java
0 → 100644
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 lombok.RequiredArgsConstructor; | ||
7 | +import lombok.extern.slf4j.Slf4j; | ||
8 | +import org.apache.commons.lang3.StringUtils; | ||
9 | +import org.springframework.stereotype.Service; | ||
10 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | ||
12 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
13 | +import org.thingsboard.server.common.data.yunteng.dto.BaseDTO; | ||
14 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
15 | +import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; | ||
16 | +import org.thingsboard.server.common.data.yunteng.dto.ReportFormConfigDTO; | ||
17 | +import org.thingsboard.server.common.data.yunteng.enums.StatusEnum; | ||
18 | +import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; | ||
19 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
20 | +import org.thingsboard.server.dao.yunteng.entities.ReportFormConfig; | ||
21 | +import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; | ||
22 | +import org.thingsboard.server.dao.yunteng.mapper.ReportFromConfigMapper; | ||
23 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ||
24 | +import org.thingsboard.server.dao.yunteng.service.YtReportFormConfigService; | ||
25 | + | ||
26 | +import java.util.HashMap; | ||
27 | +import java.util.List; | ||
28 | +import java.util.Map; | ||
29 | +import java.util.Optional; | ||
30 | +import java.util.stream.Collectors; | ||
31 | + | ||
32 | +@Slf4j | ||
33 | +@Service | ||
34 | +@RequiredArgsConstructor | ||
35 | +public class YtReportFromConfigServiceImpl | ||
36 | + extends AbstractBaseService<ReportFromConfigMapper, ReportFormConfig> | ||
37 | + implements YtReportFormConfigService { | ||
38 | + private final OrganizationMapper organizationMapper; | ||
39 | + | ||
40 | + @Override | ||
41 | + public YtPageData<ReportFormConfigDTO> page(Map<String, Object> queryMap) { | ||
42 | + String tenantId = | ||
43 | + Optional.ofNullable(queryMap.get("tenantId")).map(Object::toString).orElse(null); | ||
44 | + String name = Optional.ofNullable(queryMap.get("name")).map(Object::toString).orElse(null); | ||
45 | + Integer status = | ||
46 | + Optional.ofNullable(queryMap.get("status")) | ||
47 | + .map(value -> Integer.valueOf(value.toString())) | ||
48 | + .orElse(null); | ||
49 | + List<String> organizationIds = | ||
50 | + Optional.ofNullable(queryMap.get("organizationId")) | ||
51 | + .map( | ||
52 | + value -> { | ||
53 | + String organizationId = value.toString(); | ||
54 | + List<OrganizationDTO> list = | ||
55 | + organizationMapper.findOrganizationTreeList( | ||
56 | + tenantId, List.of(organizationId)); | ||
57 | + // 查询组织及其子组织 | ||
58 | + if (list.size() > 0) { | ||
59 | + return list.stream().map(BaseDTO::getId).collect(Collectors.toList()); | ||
60 | + } | ||
61 | + return null; | ||
62 | + }) | ||
63 | + .orElse(null); | ||
64 | + IPage<ReportFormConfig> page = | ||
65 | + baseMapper.selectPage( | ||
66 | + getPage(queryMap, "create_time", false), | ||
67 | + new LambdaQueryWrapper<ReportFormConfig>() | ||
68 | + .eq(StringUtils.isNotEmpty(tenantId), ReportFormConfig::getTenantId, tenantId) | ||
69 | + .eq(null != status, ReportFormConfig::getStatus, status) | ||
70 | + .like(null != name, ReportFormConfig::getName, name) | ||
71 | + .in( | ||
72 | + null != organizationIds && organizationIds.size() > 0, | ||
73 | + ReportFormConfig::getOrganizationId, | ||
74 | + organizationIds)); | ||
75 | + return getPageData(page, ReportFormConfigDTO.class); | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public ReportFormConfigDTO saveOrUpdateReportFromConfig(ReportFormConfigDTO report) { | ||
80 | + ReportFormConfig reportFormConfig = report.getEntity(ReportFormConfig.class); | ||
81 | + if (report.getExecuteWay() == FastIotConstants.MagicNumber.ONE | ||
82 | + && StringUtils.isEmpty(report.getExecuteContent())) { | ||
83 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
84 | + } | ||
85 | + if (!report.getAttributes().isEmpty()) { | ||
86 | + Map<String, Object> map = new HashMap<>(); | ||
87 | + map.put("value", report.getAttributes()); | ||
88 | + reportFormConfig.setAttributes(JacksonUtil.convertValue(map, JsonNode.class)); | ||
89 | + } | ||
90 | + if (!report.getDevices().isEmpty()) { | ||
91 | + Map<String, Object> map = new HashMap<>(); | ||
92 | + map.put("value", report.getDevices()); | ||
93 | + reportFormConfig.setDevices(JacksonUtil.convertValue(map, JsonNode.class)); | ||
94 | + } | ||
95 | + reportFormConfig.setQueryCondition( | ||
96 | + JacksonUtil.convertValue(report.getQueryCondition(), JsonNode.class)); | ||
97 | + if (StringUtils.isEmpty(report.getId())) { | ||
98 | + reportFormConfig.setStatus(StatusEnum.DISABLE.getIndex()); | ||
99 | + baseMapper.insert(reportFormConfig); | ||
100 | + } else { | ||
101 | + ReportFormConfig queryEntity = baseMapper.selectById(report.getId()); | ||
102 | + if (!report.getTenantId().equals(queryEntity.getTenantId())) { | ||
103 | + throw new YtDataValidationException(ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); | ||
104 | + } | ||
105 | + // 需要调用修改转台接口修改状态 | ||
106 | + reportFormConfig.setStatus(null); | ||
107 | + baseMapper.updateById(reportFormConfig); | ||
108 | + } | ||
109 | + return report; | ||
110 | + } | ||
111 | + | ||
112 | + @Override | ||
113 | + public boolean deleteReportFromConfig(DeleteDTO deleteDTO) { | ||
114 | + if (deleteDTO.getIds().isEmpty()) { | ||
115 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
116 | + } | ||
117 | + return baseMapper.deleteBatchIds(deleteDTO.getIds()) > 0; | ||
118 | + } | ||
119 | + | ||
120 | + @Override | ||
121 | + public ReportFormConfigDTO updateStatusById(String tenantId, Integer status, String id) { | ||
122 | + if (StringUtils.isEmpty(tenantId) || status == null || StringUtils.isEmpty(id)) { | ||
123 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
124 | + } | ||
125 | + ReportFormConfig queryEntity = | ||
126 | + baseMapper.selectOne( | ||
127 | + new LambdaQueryWrapper<ReportFormConfig>() | ||
128 | + .eq(ReportFormConfig::getId, id) | ||
129 | + .eq(ReportFormConfig::getTenantId, tenantId)); | ||
130 | + return Optional.ofNullable(queryEntity) | ||
131 | + .map( | ||
132 | + entity -> { | ||
133 | + entity.setStatus(status); | ||
134 | + baseMapper.updateById(entity); | ||
135 | + return entity.getDTO(ReportFormConfigDTO.class); | ||
136 | + }) | ||
137 | + .orElse(null); | ||
138 | + } | ||
139 | +} |
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.FrpInfo; | ||
6 | +import org.thingsboard.server.dao.yunteng.entities.ReportFormConfig; | ||
7 | + | ||
8 | +@Mapper | ||
9 | +public interface ReportFromConfigMapper extends BaseMapper<ReportFormConfig> { | ||
10 | + | ||
11 | +} |
dao/src/main/java/org/thingsboard/server/dao/yunteng/service/YtReportFormConfigService.java
0 → 100644
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.ReportFormConfigDTO; | ||
5 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
6 | + | ||
7 | +import java.util.Map; | ||
8 | + | ||
9 | +public interface YtReportFormConfigService { | ||
10 | + YtPageData<ReportFormConfigDTO> page(Map<String, Object> queryMap); | ||
11 | + | ||
12 | + ReportFormConfigDTO saveOrUpdateReportFromConfig(ReportFormConfigDTO report); | ||
13 | + | ||
14 | + boolean deleteReportFromConfig(DeleteDTO deleteDTO); | ||
15 | + | ||
16 | + ReportFormConfigDTO updateStatusById(String tenantId,Integer status,String id); | ||
17 | +} |