Commit 083209fdf571d63ae1dd3afbd954e0fe323cc99a

Authored by 黄 x
1 parent e6ecaf0b

fix: fix report form config json format

1 1 package org.thingsboard.server.common.data.yunteng.dto;
2   -
3   -import com.fasterxml.jackson.databind.JsonNode;
4 2 import io.swagger.annotations.ApiModel;
5 3 import io.swagger.annotations.ApiModelProperty;
6 4 import lombok.Data;
7 5 import lombok.EqualsAndHashCode;
8 6 import org.thingsboard.server.common.data.yunteng.common.AddGroup;
  7 +import org.thingsboard.server.common.data.yunteng.dto.request.ExecuteAttributesDTO;
9 8 import org.thingsboard.server.common.data.yunteng.dto.request.QueryConditionDTO;
10   -
11 9 import javax.validation.constraints.NotEmpty;
12 10 import javax.validation.constraints.NotNull;
  11 +import javax.validation.constraints.Size;
13 12 import java.util.List;
14 13
15 14 @EqualsAndHashCode(callSuper = false)
... ... @@ -19,54 +18,49 @@ public class ReportFormConfigDTO extends TenantDTO {
19 18
20 19 /** 报表配置名称 */
21 20 @ApiModelProperty(value = "报表配置名称", required = true)
22   - @NotEmpty(message = "报表配置名称不能为null或空字符串", groups = AddGroup.class)
  21 + @NotEmpty(message = "报表配置名称不能为或空字符串", groups = AddGroup.class)
23 22 private String name;
24 23
25 24 /** 组织ID */
26 25 @ApiModelProperty(value = "组织ID", required = true)
27   - @NotEmpty(message = "组织不能为null或空字符串", groups = AddGroup.class)
  26 + @NotEmpty(message = "组织不能为或空字符串", groups = AddGroup.class)
28 27 private String organizationId;
29 28
30 29 /** 执行方式:0立即执行 1定时执行 */
31 30 @ApiModelProperty(value = "执行方式", required = true)
32   - @NotNull(message = "执行方式不能为null", groups = AddGroup.class)
  31 + @NotNull(message = "执行方式不能为", groups = AddGroup.class)
33 32 private Integer executeWay;
34 33
35 34 /** cron表达式:执行方式 1 生效 */
36 35 private String executeContent;
37 36
38 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 42 /** 属性性质:0共有属性 1全部属性 */
44 43 @ApiModelProperty(value = "属性性质", required = true)
45   - @NotNull(message = "属性性质不能为null", groups = AddGroup.class)
  44 + @NotNull(message = "属性性质不能为", groups = AddGroup.class)
46 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 47 /** 数据对比:0历史数据 1环比 2同比 */
54 48 @ApiModelProperty(value = "数据对比", required = true)
55   - @NotNull(message = "数据对比不能为null", groups = AddGroup.class)
  49 + @NotNull(message = "数据对比不能为", groups = AddGroup.class)
56 50 private Integer dataCompare;
57 51
58 52 /** 数据周期:单位毫秒 */
59 53 @ApiModelProperty(value = "开始时间", required = true)
60   - @NotNull(message = "开始时间不能为null", groups = AddGroup.class)
  54 + @NotNull(message = "开始时间不能为", groups = AddGroup.class)
61 55 private Long startTs;
62 56
63 57 /** 时间间隔:单位毫秒 */
64 58 @ApiModelProperty(value = "结束时间", required = true)
65   - @NotNull(message = "结束时间不能为null", groups = AddGroup.class)
  59 + @NotNull(message = "结束时间不能为", groups = AddGroup.class)
66 60 private Long endTs ;
67 61
68 62 @ApiModelProperty(value = "查询条件", required = true)
69   - @NotNull(message = "查询条件不能为null", groups = AddGroup.class)
  63 + @NotNull(message = "查询条件不能为", groups = AddGroup.class)
70 64 private QueryConditionDTO queryCondition;
71 65
72 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 29 @TableField(updateStrategy = FieldStrategy.IGNORED)
30 30 private String executeContent;
31 31
32   - /** 设备:json数组格式 */
  32 + /** 执行设备及属性:json数组格式 */
33 33 @TableField(typeHandler = JacksonTypeHandler.class)
34   - private JsonNode devices;
  34 + private JsonNode executeAttributes;
35 35
36 36 /** 属性性质:0共有属性 1全部属性 */
37 37 private Integer attributeNature;
38 38
39   - /** 属性 */
40   - @TableField(typeHandler = JacksonTypeHandler.class)
41   - private JsonNode attributes;
42   -
43 39 /** 数据对比:0历史数据 1环比 2同比 */
44 40 private Integer dataCompare;
45 41
... ...
... ... @@ -22,8 +22,6 @@ import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper;
22 22 import org.thingsboard.server.dao.yunteng.mapper.ReportFromConfigMapper;
23 23 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
24 24 import org.thingsboard.server.dao.yunteng.service.YtReportFormConfigService;
25   -
26   -import java.util.HashMap;
27 25 import java.util.List;
28 26 import java.util.Map;
29 27 import java.util.Optional;
... ... @@ -78,20 +76,26 @@ public class YtReportFromConfigServiceImpl
78 76 @Override
79 77 public ReportFormConfigDTO saveOrUpdateReportFromConfig(ReportFormConfigDTO report) {
80 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 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 99 reportFormConfig.setQueryCondition(
96 100 JacksonUtil.convertValue(report.getQueryCondition(), JsonNode.class));
97 101 if (StringUtils.isEmpty(report.getId())) {
... ...