Commit 083209fdf571d63ae1dd3afbd954e0fe323cc99a
1 parent
e6ecaf0b
fix: fix report form config json format
Showing
4 changed files
with
47 additions
and
38 deletions
1 | package org.thingsboard.server.common.data.yunteng.dto; | 1 | package org.thingsboard.server.common.data.yunteng.dto; |
2 | - | ||
3 | -import com.fasterxml.jackson.databind.JsonNode; | ||
4 | import io.swagger.annotations.ApiModel; | 2 | import io.swagger.annotations.ApiModel; |
5 | import io.swagger.annotations.ApiModelProperty; | 3 | import io.swagger.annotations.ApiModelProperty; |
6 | import lombok.Data; | 4 | import lombok.Data; |
7 | import lombok.EqualsAndHashCode; | 5 | import lombok.EqualsAndHashCode; |
8 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; | 6 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
7 | +import org.thingsboard.server.common.data.yunteng.dto.request.ExecuteAttributesDTO; | ||
9 | import org.thingsboard.server.common.data.yunteng.dto.request.QueryConditionDTO; | 8 | import org.thingsboard.server.common.data.yunteng.dto.request.QueryConditionDTO; |
10 | - | ||
11 | import javax.validation.constraints.NotEmpty; | 9 | import javax.validation.constraints.NotEmpty; |
12 | import javax.validation.constraints.NotNull; | 10 | import javax.validation.constraints.NotNull; |
11 | +import javax.validation.constraints.Size; | ||
13 | import java.util.List; | 12 | import java.util.List; |
14 | 13 | ||
15 | @EqualsAndHashCode(callSuper = false) | 14 | @EqualsAndHashCode(callSuper = false) |
@@ -19,54 +18,49 @@ public class ReportFormConfigDTO extends TenantDTO { | @@ -19,54 +18,49 @@ public class ReportFormConfigDTO extends TenantDTO { | ||
19 | 18 | ||
20 | /** 报表配置名称 */ | 19 | /** 报表配置名称 */ |
21 | @ApiModelProperty(value = "报表配置名称", required = true) | 20 | @ApiModelProperty(value = "报表配置名称", required = true) |
22 | - @NotEmpty(message = "报表配置名称不能为null或空字符串", groups = AddGroup.class) | 21 | + @NotEmpty(message = "报表配置名称不能为空或空字符串", groups = AddGroup.class) |
23 | private String name; | 22 | private String name; |
24 | 23 | ||
25 | /** 组织ID */ | 24 | /** 组织ID */ |
26 | @ApiModelProperty(value = "组织ID", required = true) | 25 | @ApiModelProperty(value = "组织ID", required = true) |
27 | - @NotEmpty(message = "组织不能为null或空字符串", groups = AddGroup.class) | 26 | + @NotEmpty(message = "组织不能为空或空字符串", groups = AddGroup.class) |
28 | private String organizationId; | 27 | private String organizationId; |
29 | 28 | ||
30 | /** 执行方式:0立即执行 1定时执行 */ | 29 | /** 执行方式:0立即执行 1定时执行 */ |
31 | @ApiModelProperty(value = "执行方式", required = true) | 30 | @ApiModelProperty(value = "执行方式", required = true) |
32 | - @NotNull(message = "执行方式不能为null", groups = AddGroup.class) | 31 | + @NotNull(message = "执行方式不能为空", groups = AddGroup.class) |
33 | private Integer executeWay; | 32 | private Integer executeWay; |
34 | 33 | ||
35 | /** cron表达式:执行方式 1 生效 */ | 34 | /** cron表达式:执行方式 1 生效 */ |
36 | private String executeContent; | 35 | private String executeContent; |
37 | 36 | ||
38 | /** 设备:json数组格式 */ | 37 | /** 设备:json数组格式 */ |
39 | - @ApiModelProperty(value = "执行设备", required = true) | ||
40 | - @NotNull(message = "执行设备不能为null", groups = AddGroup.class) | ||
41 | - private List<String> devices; | 38 | + @ApiModelProperty(value = "执行设备及属性", required = true) |
39 | + @Size(message = "至少需要一个执行设备及属性", min = 1,groups = {AddGroup.class}) | ||
40 | + private List<ExecuteAttributesDTO> executeAttributes; | ||
42 | 41 | ||
43 | /** 属性性质:0共有属性 1全部属性 */ | 42 | /** 属性性质:0共有属性 1全部属性 */ |
44 | @ApiModelProperty(value = "属性性质", required = true) | 43 | @ApiModelProperty(value = "属性性质", required = true) |
45 | - @NotNull(message = "属性性质不能为null", groups = AddGroup.class) | 44 | + @NotNull(message = "属性性质不能为空", groups = AddGroup.class) |
46 | private Integer attributeNature; | 45 | private Integer attributeNature; |
47 | 46 | ||
48 | - /** 属性 */ | ||
49 | - @ApiModelProperty(value = "属性", required = true) | ||
50 | - @NotNull(message = "属性不能为null", groups = AddGroup.class) | ||
51 | - private List<String> attributes; | ||
52 | - | ||
53 | /** 数据对比:0历史数据 1环比 2同比 */ | 47 | /** 数据对比:0历史数据 1环比 2同比 */ |
54 | @ApiModelProperty(value = "数据对比", required = true) | 48 | @ApiModelProperty(value = "数据对比", required = true) |
55 | - @NotNull(message = "数据对比不能为null", groups = AddGroup.class) | 49 | + @NotNull(message = "数据对比不能为空", groups = AddGroup.class) |
56 | private Integer dataCompare; | 50 | private Integer dataCompare; |
57 | 51 | ||
58 | /** 数据周期:单位毫秒 */ | 52 | /** 数据周期:单位毫秒 */ |
59 | @ApiModelProperty(value = "开始时间", required = true) | 53 | @ApiModelProperty(value = "开始时间", required = true) |
60 | - @NotNull(message = "开始时间不能为null", groups = AddGroup.class) | 54 | + @NotNull(message = "开始时间不能为空", groups = AddGroup.class) |
61 | private Long startTs; | 55 | private Long startTs; |
62 | 56 | ||
63 | /** 时间间隔:单位毫秒 */ | 57 | /** 时间间隔:单位毫秒 */ |
64 | @ApiModelProperty(value = "结束时间", required = true) | 58 | @ApiModelProperty(value = "结束时间", required = true) |
65 | - @NotNull(message = "结束时间不能为null", groups = AddGroup.class) | 59 | + @NotNull(message = "结束时间不能为空", groups = AddGroup.class) |
66 | private Long endTs ; | 60 | private Long endTs ; |
67 | 61 | ||
68 | @ApiModelProperty(value = "查询条件", required = true) | 62 | @ApiModelProperty(value = "查询条件", required = true) |
69 | - @NotNull(message = "查询条件不能为null", groups = AddGroup.class) | 63 | + @NotNull(message = "查询条件不能为空", groups = AddGroup.class) |
70 | private QueryConditionDTO queryCondition; | 64 | private QueryConditionDTO queryCondition; |
71 | 65 | ||
72 | /** 配置状态:0禁用 1启用 */ | 66 | /** 配置状态:0禁用 1启用 */ |
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 ExecuteAttributesDTO { | ||
10 | + @ApiModelProperty(value = "执行设备", required = true) | ||
11 | + private String device; | ||
12 | + | ||
13 | + @ApiModelProperty(value = "执行属性", required = true) | ||
14 | + private String attribute; | ||
15 | +} |
@@ -29,17 +29,13 @@ public class ReportFormConfig extends TenantBaseEntity { | @@ -29,17 +29,13 @@ public class ReportFormConfig extends TenantBaseEntity { | ||
29 | @TableField(updateStrategy = FieldStrategy.IGNORED) | 29 | @TableField(updateStrategy = FieldStrategy.IGNORED) |
30 | private String executeContent; | 30 | private String executeContent; |
31 | 31 | ||
32 | - /** 设备:json数组格式 */ | 32 | + /** 执行设备及属性:json数组格式 */ |
33 | @TableField(typeHandler = JacksonTypeHandler.class) | 33 | @TableField(typeHandler = JacksonTypeHandler.class) |
34 | - private JsonNode devices; | 34 | + private JsonNode executeAttributes; |
35 | 35 | ||
36 | /** 属性性质:0共有属性 1全部属性 */ | 36 | /** 属性性质:0共有属性 1全部属性 */ |
37 | private Integer attributeNature; | 37 | private Integer attributeNature; |
38 | 38 | ||
39 | - /** 属性 */ | ||
40 | - @TableField(typeHandler = JacksonTypeHandler.class) | ||
41 | - private JsonNode attributes; | ||
42 | - | ||
43 | /** 数据对比:0历史数据 1环比 2同比 */ | 39 | /** 数据对比:0历史数据 1环比 2同比 */ |
44 | private Integer dataCompare; | 40 | private Integer dataCompare; |
45 | 41 |
@@ -22,8 +22,6 @@ import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; | @@ -22,8 +22,6 @@ import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; | ||
22 | import org.thingsboard.server.dao.yunteng.mapper.ReportFromConfigMapper; | 22 | import org.thingsboard.server.dao.yunteng.mapper.ReportFromConfigMapper; |
23 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | 23 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
24 | import org.thingsboard.server.dao.yunteng.service.YtReportFormConfigService; | 24 | import org.thingsboard.server.dao.yunteng.service.YtReportFormConfigService; |
25 | - | ||
26 | -import java.util.HashMap; | ||
27 | import java.util.List; | 25 | import java.util.List; |
28 | import java.util.Map; | 26 | import java.util.Map; |
29 | import java.util.Optional; | 27 | import java.util.Optional; |
@@ -78,20 +76,26 @@ public class YtReportFromConfigServiceImpl | @@ -78,20 +76,26 @@ public class YtReportFromConfigServiceImpl | ||
78 | @Override | 76 | @Override |
79 | public ReportFormConfigDTO saveOrUpdateReportFromConfig(ReportFormConfigDTO report) { | 77 | public ReportFormConfigDTO saveOrUpdateReportFromConfig(ReportFormConfigDTO report) { |
80 | ReportFormConfig reportFormConfig = report.getEntity(ReportFormConfig.class); | 78 | ReportFormConfig reportFormConfig = report.getEntity(ReportFormConfig.class); |
81 | - if (report.getExecuteWay() == FastIotConstants.MagicNumber.ONE | ||
82 | - && StringUtils.isEmpty(report.getExecuteContent())) { | 79 | + if ((report.getExecuteWay() == FastIotConstants.MagicNumber.ONE |
80 | + && StringUtils.isEmpty(report.getExecuteContent())) | ||
81 | + || null == report.getExecuteAttributes()) { | ||
83 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 82 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
84 | } | 83 | } |
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)); | 84 | + if (null != report.getExecuteAttributes() |
85 | + && report.getExecuteAttributes().size() > FastIotConstants.MagicNumber.ZERO) { | ||
86 | + report | ||
87 | + .getExecuteAttributes() | ||
88 | + .forEach( | ||
89 | + item -> { | ||
90 | + if (StringUtils.isEmpty(item.getDevice()) | ||
91 | + || StringUtils.isEmpty(item.getAttribute())) { | ||
92 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
93 | + } | ||
94 | + }); | ||
94 | } | 95 | } |
96 | + | ||
97 | + reportFormConfig.setExecuteAttributes( | ||
98 | + JacksonUtil.convertValue(report.getExecuteAttributes(), JsonNode.class)); | ||
95 | reportFormConfig.setQueryCondition( | 99 | reportFormConfig.setQueryCondition( |
96 | JacksonUtil.convertValue(report.getQueryCondition(), JsonNode.class)); | 100 | JacksonUtil.convertValue(report.getQueryCondition(), JsonNode.class)); |
97 | if (StringUtils.isEmpty(report.getId())) { | 101 | if (StringUtils.isEmpty(report.getId())) { |