Commit 4dd5e69e7588c52902e34b3f3156a239c4a41178

Authored by 黄 x
1 parent 3231a48a

fix: fix ReportFormConfig and SysJob bug

... ... @@ -55,7 +55,6 @@ public class SysJobController extends BaseController {
55 55
56 56 HashMap<String, Object> queryMap = new HashMap<>();
57 57 boolean isPtAdmin = getCurrentUser().isPtAdmin();
58   - String tenantId = isPtAdmin ? null : getCurrentUser().getCurrentTenantId();
59 58 queryMap.put(PAGE_SIZE, pageSize);
60 59 queryMap.put(PAGE, page);
61 60 queryMap.put(ORDER_FILED, orderBy);
... ... @@ -65,7 +64,7 @@ public class SysJobController extends BaseController {
65 64 queryMap.put("jobName", jobName);
66 65 queryMap.put("jobGroup", jobGroup);
67 66 queryMap.put("status", status);
68   - return jobService.sysJobPage(queryMap, tenantId);
  67 + return jobService.sysJobPage(queryMap);
69 68 }
70 69
71 70 @DeleteMapping
... ... @@ -144,8 +143,7 @@ public class SysJobController extends BaseController {
144 143 }
145 144
146 145 private ResponseResult<SysJobDTO> saveOrUpdate(SysJobDTO job)
147   - throws SchedulerException, ThingsboardException {
148   - job.setTenantId(getCurrentUser().getCurrentTenantId());
  146 + throws SchedulerException{
149 147 String message = StringUtils.isEmpty(job.getId()) ? "新增任务'" : "修改任务'";
150 148 if (!CronUtils.isValid(job.getCronExpression())) {
151 149 throw new YtDataValidationException(message + job.getJobName() + "'失败,Cron表达式不正确");
... ...
... ... @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
5 5 import lombok.Data;
6 6 import lombok.EqualsAndHashCode;
7 7 import org.thingsboard.server.common.data.yunteng.common.AddGroup;
  8 +import org.thingsboard.server.common.data.yunteng.dto.report.CycleParameterDTO;
8 9 import org.thingsboard.server.common.data.yunteng.dto.request.ExecuteAttributesDTO;
9 10 import org.thingsboard.server.common.data.yunteng.dto.request.QueryConditionDTO;
10 11 import javax.validation.constraints.NotEmpty;
... ... @@ -34,6 +35,9 @@ public class ReportFormConfigDTO extends TenantDTO {
34 35 @NotNull(message = "执行方式不能为空", groups = AddGroup.class)
35 36 private Integer executeWay;
36 37
  38 + @ApiModelProperty(value = "周期参数", required = true)
  39 + private CycleParameterDTO cycle;
  40 +
37 41 /** cron表达式:执行方式 1 生效 */
38 42 private String executeContent;
39 43
... ...
  1 +package org.thingsboard.server.common.data.yunteng.dto.report;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +/** 报表配置:周期参数 */
  7 +@Data
  8 +public class CycleParameterDTO {
  9 + @ApiModelProperty(value = "周期类型:0每日 1每周 2每月",required = true)
  10 + private Integer cycleType;
  11 +
  12 + @ApiModelProperty(value = "当前周期")
  13 + private String currentCycle;
  14 +
  15 + @ApiModelProperty(value = "时间",required = true)
  16 + private String cycleTime;
  17 +}
... ...
... ... @@ -29,6 +29,10 @@ public class ReportFormConfig extends TenantBaseEntity {
29 29 @TableField(updateStrategy = FieldStrategy.IGNORED)
30 30 private String executeContent;
31 31
  32 + /** 周期参数:json数组格式 */
  33 + @TableField(typeHandler = JacksonTypeHandler.class)
  34 + private JsonNode cycle;
  35 +
32 36 /** 执行设备及属性:json数组格式 */
33 37 @TableField(typeHandler = JacksonTypeHandler.class)
34 38 private JsonNode executeAttributes;
... ...
... ... @@ -42,7 +42,7 @@ public class SysJobServiceImpl extends AbstractBaseService<SysJobMapper, SysJob>
42 42 }
43 43
44 44 @Override
45   - public YtPageData<SysJobDTO> sysJobPage(Map<String, Object> queryMap, String tenantId) {
  45 + public YtPageData<SysJobDTO> sysJobPage(Map<String, Object> queryMap) {
46 46 String jobGroup = queryMap.get("jobGroup") != null ? queryMap.get("jobGroup").toString() : null;
47 47 String jobName = queryMap.get("jobName") != null ? queryMap.get("jobName").toString() : null;
48 48 Integer status =
... ... @@ -51,7 +51,6 @@ public class SysJobServiceImpl extends AbstractBaseService<SysJobMapper, SysJob>
51 51 baseMapper.selectPage(
52 52 getPage(queryMap, "create_time", false),
53 53 new LambdaQueryWrapper<SysJob>()
54   - .eq(SysJob::getTenantId, tenantId)
55 54 .like(StringUtils.isNotEmpty(jobName), SysJob::getJobName, jobName)
56 55 .eq(StringUtils.isNotEmpty(jobGroup), SysJob::getJobGroup, jobGroup)
57 56 .eq(null != status, SysJob::getStatus, status));
... ... @@ -204,6 +203,7 @@ public class SysJobServiceImpl extends AbstractBaseService<SysJobMapper, SysJob>
204 203 throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
205 204 }
206 205 newJob.setSourceId(job.getSourceId());
  206 + newJob.setTenantId(job.getTenantId());
207 207 baseMapper.updateById(newJob);
208 208 updateSchedulerJob(newJob, job.getJobGroup());
209 209 }
... ...
... ... @@ -13,6 +13,7 @@ import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
13 13 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
14 14 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
15 15 import org.thingsboard.server.common.data.yunteng.dto.*;
  16 +import org.thingsboard.server.common.data.yunteng.dto.report.CycleParameterDTO;
16 17 import org.thingsboard.server.common.data.yunteng.dto.request.ExecuteAttributesDTO;
17 18 import org.thingsboard.server.common.data.yunteng.dto.request.QueryConditionDTO;
18 19 import org.thingsboard.server.common.data.yunteng.enums.JobGroupEnum;
... ... @@ -37,8 +38,9 @@ public class YtReportFromConfigServiceImpl
37 38 private final YtSysJobService ytSysJobService;
38 39 private final YtReportGenerateRecordService ytReportGenerateRecordService;
39 40 private final UserOrganizationMappingService userOrganizationMappingService;
  41 +
40 42 @Override
41   - public YtPageData<ReportFormConfigDTO> page(Map<String, Object> queryMap,boolean tenantAdmin) {
  43 + public YtPageData<ReportFormConfigDTO> page(Map<String, Object> queryMap, boolean tenantAdmin) {
42 44 String tenantId =
43 45 Optional.ofNullable(queryMap.get("tenantId")).map(Object::toString).orElse(null);
44 46 List<String> organizationIds =
... ... @@ -56,9 +58,11 @@ public class YtReportFromConfigServiceImpl
56 58 return null;
57 59 })
58 60 .orElse(null);
59   - if(!tenantAdmin && null != queryMap.get("userId")){
  61 + if (!tenantAdmin && null != queryMap.get("userId")) {
60 62 String userId = queryMap.get("userId").toString();
61   - organizationIds = userOrganizationMappingService.compareOrganizationIdsByCustomerId(organizationIds,userId);
  63 + organizationIds =
  64 + userOrganizationMappingService.compareOrganizationIdsByCustomerId(
  65 + organizationIds, userId);
62 66 }
63 67 queryMap.put("organizationIds", organizationIds);
64 68 IPage<ReportFormConfigDTO> page =
... ... @@ -88,7 +92,9 @@ public class YtReportFromConfigServiceImpl
88 92 }
89 93 });
90 94 }
91   -
  95 + if (null != report.getCycle()) {
  96 + reportFormConfig.setCycle(JacksonUtil.convertValue(report.getCycle(), JsonNode.class));
  97 + }
92 98 reportFormConfig.setExecuteAttributes(
93 99 JacksonUtil.convertValue(report.getExecuteAttributes(), JsonNode.class));
94 100 reportFormConfig.setQueryCondition(
... ... @@ -280,6 +286,8 @@ public class YtReportFromConfigServiceImpl
280 286 getExecuteConditionAndAttribute(jsonNode, list);
281 287 QueryConditionDTO queryCondition =
282 288 JacksonUtil.convertValue(obj.getQueryCondition(), QueryConditionDTO.class);
  289 + CycleParameterDTO cycle = JacksonUtil.convertValue(obj.getCycle(), CycleParameterDTO.class);
  290 + dto.setCycle(cycle);
283 291 dto.setExecuteAttributes(list);
284 292 dto.setQueryCondition(queryCondition);
285 293 return dto;
... ...
... ... @@ -14,10 +14,9 @@ public interface YtSysJobService
14 14 * 获取quartz调度器的计划任务
15 15 *
16 16 * @param queryMap 查询参数
17   - * @param tenantId 租户ID
18 17 * @return 分页数据
19 18 */
20   - YtPageData<SysJobDTO> sysJobPage(Map<String, Object> queryMap, String tenantId);
  19 + YtPageData<SysJobDTO> sysJobPage(Map<String, Object> queryMap);
21 20
22 21 /**
23 22 * 通过调度任务ID查询调度信息
... ...