From c26b26ce1c4f980519ac5ae76a2c2b4d1c824ae2 Mon Sep 17 00:00:00 2001 From: xiwa Date: Wed, 19 Jul 2023 10:05:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=A7=84=E5=88=99=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E3=80=81=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iotkit/data/service/RuleInfoDataImpl.java | 9 +++++ .../iotkit/data/service/TaskInfoDataImpl.java | 15 +++++++- .../temporal/es/dao/RuleLogRepository.java | 2 +- .../temporal/es/dao/TaskLogRepository.java | 2 +- .../temporal/es/service/RuleLogDataImpl.java | 2 +- .../temporal/es/service/TaskLogDataImpl.java | 2 +- .../controller/RuleEngineController.java | 15 ++++---- .../manager/dto/bo/ruleinfo/RuleLogBo.java | 4 -- .../manager/dto/vo/ruleinfo/RuleLogVo.java | 36 +++++++++--------- .../manager/dto/vo/taskinfo/TaskLogVo.java | 19 +++++---- .../service/impl/RuleEngineServiceImpl.java | 2 - .../iotkit/ruleengine/task/TaskManager.java | 7 +--- iot-starter/.DS_Store | Bin 0 -> 6148 bytes 13 files changed, 63 insertions(+), 52 deletions(-) create mode 100644 iot-starter/.DS_Store diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/RuleInfoDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/RuleInfoDataImpl.java index b3faa10e..3c870a2c 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/RuleInfoDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/RuleInfoDataImpl.java @@ -9,6 +9,7 @@ */ package cc.iotkit.data.service; +import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.utils.JsonUtils; import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.data.dao.IJPACommData; @@ -16,6 +17,8 @@ import cc.iotkit.data.manager.IRuleInfoData; import cc.iotkit.data.dao.RuleInfoRepository; import cc.iotkit.data.model.TbRuleInfo; import cc.iotkit.common.api.Paging; +import cc.iotkit.data.model.TbTaskInfo; +import cc.iotkit.data.util.PageBuilder; import cc.iotkit.model.rule.FilterConfig; import cc.iotkit.model.rule.RuleAction; import cc.iotkit.model.rule.RuleInfo; @@ -105,6 +108,12 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData findAll(PageRequest pageRequest) { + Page ret = ruleInfoRepository.findAll(PageBuilder.toPageable(pageRequest)); + return new Paging<>(ret.getTotalElements(), fromTb(ret.getContent())); + } + @Override public RuleInfo save(RuleInfo data) { if (StringUtils.isBlank(data.getId())) { diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/TaskInfoDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/TaskInfoDataImpl.java index d30ac36f..80defb89 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/TaskInfoDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/TaskInfoDataImpl.java @@ -9,13 +9,15 @@ */ package cc.iotkit.data.service; +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; import cc.iotkit.common.utils.JsonUtils; import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.data.dao.IJPACommData; -import cc.iotkit.data.manager.ITaskInfoData; import cc.iotkit.data.dao.TaskInfoRepository; +import cc.iotkit.data.manager.ITaskInfoData; import cc.iotkit.data.model.TbTaskInfo; -import cc.iotkit.common.api.Paging; +import cc.iotkit.data.util.PageBuilder; import cc.iotkit.model.rule.RuleAction; import cc.iotkit.model.rule.TaskInfo; import lombok.RequiredArgsConstructor; @@ -80,6 +82,15 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData findAll(PageRequest pageRequest) { + Page ret = taskInfoRepository.findAll(PageBuilder.toPageable(pageRequest)); + return new Paging<>(ret.getTotalElements(), + ret.getContent().stream().map(this::to) + .collect(Collectors.toList()) + ); + } + @Override public TaskInfo save(TaskInfo data) { if (StringUtils.isBlank(data.getId())) { diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/RuleLogRepository.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/RuleLogRepository.java index 89f0aab9..8d7979e9 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/RuleLogRepository.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/RuleLogRepository.java @@ -18,6 +18,6 @@ public interface RuleLogRepository extends ElasticsearchRepository findByRuleId(String ruleId, Pageable pageable); + Page findByRuleIdOrderByLogAtDesc(String ruleId, Pageable pageable); } diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/TaskLogRepository.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/TaskLogRepository.java index 729751e0..4e161036 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/TaskLogRepository.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/TaskLogRepository.java @@ -18,6 +18,6 @@ public interface TaskLogRepository extends ElasticsearchRepository findByTaskId(String taskId, Pageable pageable); + Page findByTaskIdOrderByLogAtDesc(String taskId, Pageable pageable); } diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java index f40daa0b..7aadd877 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java @@ -35,7 +35,7 @@ public class RuleLogDataImpl implements IRuleLogData { @Override public Paging findByRuleId(String ruleId, int page, int size) { - Page paged = ruleLogRepository.findByRuleId(ruleId, Pageable.ofSize(size).withPage(page - 1)); + Page paged = ruleLogRepository.findByRuleIdOrderByLogAtDesc(ruleId, Pageable.ofSize(size).withPage(page - 1)); return new Paging<>(paged.getTotalElements(), paged.getContent().stream().map(o -> MapstructUtils.convert(o, RuleLog.class)) .collect(Collectors.toList())); diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java index 798250f6..6a96273e 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java @@ -35,7 +35,7 @@ public class TaskLogDataImpl implements ITaskLogData { @Override public Paging findByTaskId(String taskId, int page, int size) { - Page paged = taskLogRepository.findByTaskId(taskId, Pageable.ofSize(size).withPage(page - 1)); + Page paged = taskLogRepository.findByTaskIdOrderByLogAtDesc(taskId, Pageable.ofSize(size).withPage(page - 1)); return new Paging<>(paged.getTotalElements(), paged.getContent().stream().map(o -> MapstructUtils.convert(o, TaskLog.class)) .collect(Collectors.toList())); diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java index 62f63532..2ccd54b0 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java @@ -44,14 +44,14 @@ public class RuleEngineController { @PostMapping("/list") public Paging rules( @Validated @RequestBody - PageRequest request + PageRequest request ) { return ruleEngineService.selectPageList(request); } @ApiOperation("保存规则") @PostMapping("/edit") - public boolean saveRule(@RequestBody @Validated Request ruleInfoBo) { + public boolean saveRule(@RequestBody @Validated Request ruleInfoBo) { return ruleEngineService.saveRule(ruleInfoBo.getData()); } @@ -80,7 +80,7 @@ public class RuleEngineController { @ApiOperation("规则日志") @PostMapping("/ruleLog/list") public Paging getRuleLogs( - @Validated @RequestBody PageRequest request + @Validated @RequestBody PageRequest request ) { return ruleEngineService.selectRuleLogPageList(request); } @@ -102,7 +102,7 @@ public class RuleEngineController { @ApiOperation("保存定时任务") @PostMapping("/task/save") public boolean saveTask(@Validated @RequestBody Request taskInfo) { - return ruleEngineService.saveTask(taskInfo.getData()); + return ruleEngineService.saveTask(taskInfo.getData()); } @ApiOperation("停止定时任务") @@ -122,7 +122,7 @@ public class RuleEngineController { @PostMapping("/task/renew") public boolean renewTask(@Validated @RequestBody Request request) { String taskId = request.getData(); - return ruleEngineService.renewTask(taskId); + return ruleEngineService.renewTask(taskId); } @@ -140,13 +140,12 @@ public class RuleEngineController { @Validated @RequestBody PageRequest request ) { return ruleEngineService.selectTaskLogPageList(request); - } @ApiOperation("清除定时任务日志") @PostMapping("/taskLogs/clear") - public boolean clearTaskLogs( @Validated @RequestBody Request request) { - return ruleEngineService.clearTaskLogs(request.getData()); + public boolean clearTaskLogs(@Validated @RequestBody Request request) { + return ruleEngineService.clearTaskLogs(request.getData()); } } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleLogBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleLogBo.java index 1005b87c..8491d327 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleLogBo.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleLogBo.java @@ -20,19 +20,15 @@ public class RuleLogBo extends BaseDto { private Long time; @ApiModelProperty(value="规则id") - private String ruleId; @ApiModelProperty(value="状态") - private String state1; @ApiModelProperty(value="内容") - private String content; @ApiModelProperty(value="是否成功") - private Boolean success; } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleLogVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleLogVo.java index fcc0c6a8..23098668 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleLogVo.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleLogVo.java @@ -1,38 +1,36 @@ package cc.iotkit.manager.dto.vo.ruleinfo; -import cc.iotkit.common.api.BaseDto; import cc.iotkit.model.rule.RuleInfo; import io.github.linpeilie.annotations.AutoMapper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import lombok.EqualsAndHashCode; -@ApiModel(value = "RuleLogBo") +import java.io.Serializable; + +@ApiModel(value = "RuleLogVo") @Data -@EqualsAndHashCode(callSuper = true) -@AutoMapper(target = RuleInfo.class, reverseConvertGenerate = false) -public class RuleLogVo extends BaseDto { +@AutoMapper(target = RuleInfo.class) +public class RuleLogVo implements Serializable { + private static final long serialVersionUID = -1L; - private static final long serialVersionUID = -1L; + @ApiModelProperty(value = "时间") + private Long time; - @ApiModelProperty(value="时间") - private Long time; + @ApiModelProperty(value = "规则id") - @ApiModelProperty(value="规则id") + private String ruleId; - private String ruleId; + @ApiModelProperty(value = "状态") - @ApiModelProperty(value="状态") + private String state1; - private String state1; + @ApiModelProperty(value = "内容") - @ApiModelProperty(value="内容") + private String content; - private String content; + @ApiModelProperty(value = "是否成功") - @ApiModelProperty(value="是否成功") + private Boolean success; - private Boolean success; - - } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskLogVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskLogVo.java index 35275534..d4e410e5 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskLogVo.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskLogVo.java @@ -9,16 +9,19 @@ */ package cc.iotkit.manager.dto.vo.taskinfo; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import cc.iotkit.model.rule.TaskLog; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.*; +import java.io.Serializable; + + +@ApiModel(value = "TaskLogVo") @Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class TaskLogVo { +@AutoMapper(target = TaskLog.class) +public class TaskLogVo implements Serializable { + private static final long serialVersionUID = -1L; private String id; diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/RuleEngineServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/RuleEngineServiceImpl.java index 34b5c6a2..462a527e 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/RuleEngineServiceImpl.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/RuleEngineServiceImpl.java @@ -257,9 +257,7 @@ public class RuleEngineServiceImpl implements IRuleEngineService { @Override public Paging selectTaskLogPageList(PageRequest request) { - TaskLog taskLog = request.getData().to(TaskLog.class); - Paging byTaskId = taskLogData.findByTaskId(taskLog.getTaskId(), request.getPageNum(), request.getPageSize()); return byTaskId.to(TaskLogVo.class); } diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java index 1dad57e5..8191afa4 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java @@ -55,7 +55,7 @@ public class TaskManager implements ApplicationContextAware { int idx = 1; while (true) { PageRequest pageRequest = new PageRequest<>(); - pageRequest.setPageNum(idx+=1); + pageRequest.setPageNum(idx); pageRequest.setPageSize(100); Paging all = taskInfoData.findAll(pageRequest); List tasks = all.getRows(); @@ -134,7 +134,7 @@ public class TaskManager implements ApplicationContextAware { TriggerKey triggerKey = new TriggerKey(task.getId(), task.getUid()); Trigger oldTrigger = getScheduler().getTrigger(triggerKey); if (oldTrigger == null) { - log.warn("task isn't exists,to add"); + log.warn("saveTask:trigger does not exist"); addTask(task); return; } @@ -147,9 +147,6 @@ public class TaskManager implements ApplicationContextAware { } public void renewTask(TaskInfo task) throws SchedulerException { - if (!TaskInfo.TYPE_DELAY.equals(task.getType())) { - throw new BizException(ErrCode.TASK_NOT_SUPPORT_RENEW); - } saveTask(task); } diff --git a/iot-starter/.DS_Store b/iot-starter/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ee771938787a1bb39cadddab0eb4f7463f2ead2b GIT binary patch literal 6148 zcmeHKI|>3Z5S>vG!N$@uSMUZw^aOhW1;s`bM6I{-TprCgpGH?ZZR8D1UNV`NkXP*N zh=|TFo0-T&L`HB!x!KS)+c)o6FCz+si0p zwti-h{ zq5pp-aYY5Fz+Wk#gGIBL<4IXtJCCzkTi`3W<=o+Bm^%f7mt&xpV=Sy3PdzE}ip{ZK V6Wc(iBkpt{e+En!8Ws4p0uNe26{i3I literal 0 HcmV?d00001