fix:规则引擎、定时任务问题修复
parent
104c193951
commit
c26b26ce1c
|
@ -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<RuleInfo, S
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paging<RuleInfo> findAll(PageRequest<RuleInfo> pageRequest) {
|
||||
Page<TbRuleInfo> 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())) {
|
||||
|
|
|
@ -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<TaskInfo, S
|
|||
return to(taskInfoRepository.findById(s).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paging<TaskInfo> findAll(PageRequest<TaskInfo> pageRequest) {
|
||||
Page<TbTaskInfo> 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())) {
|
||||
|
|
|
@ -18,6 +18,6 @@ public interface RuleLogRepository extends ElasticsearchRepository<DocRuleLog, S
|
|||
|
||||
void deleteByRuleId(String ruleId);
|
||||
|
||||
Page<DocRuleLog> findByRuleId(String ruleId, Pageable pageable);
|
||||
Page<DocRuleLog> findByRuleIdOrderByLogAtDesc(String ruleId, Pageable pageable);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,6 @@ public interface TaskLogRepository extends ElasticsearchRepository<DocTaskLog, S
|
|||
|
||||
void deleteByTaskId(String taskId);
|
||||
|
||||
Page<DocTaskLog> findByTaskId(String taskId, Pageable pageable);
|
||||
Page<DocTaskLog> findByTaskIdOrderByLogAtDesc(String taskId, Pageable pageable);
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class RuleLogDataImpl implements IRuleLogData {
|
|||
|
||||
@Override
|
||||
public Paging<RuleLog> findByRuleId(String ruleId, int page, int size) {
|
||||
Page<DocRuleLog> paged = ruleLogRepository.findByRuleId(ruleId, Pageable.ofSize(size).withPage(page - 1));
|
||||
Page<DocRuleLog> 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()));
|
||||
|
|
|
@ -35,7 +35,7 @@ public class TaskLogDataImpl implements ITaskLogData {
|
|||
|
||||
@Override
|
||||
public Paging<TaskLog> findByTaskId(String taskId, int page, int size) {
|
||||
Page<DocTaskLog> paged = taskLogRepository.findByTaskId(taskId, Pageable.ofSize(size).withPage(page - 1));
|
||||
Page<DocTaskLog> 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()));
|
||||
|
|
|
@ -140,7 +140,6 @@ public class RuleEngineController {
|
|||
@Validated @RequestBody PageRequest<TaskLogBo> request
|
||||
) {
|
||||
return ruleEngineService.selectTaskLogPageList(request);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation("清除定时任务日志")
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
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;
|
||||
|
||||
@ApiModelProperty(value = "时间")
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -257,9 +257,7 @@ public class RuleEngineServiceImpl implements IRuleEngineService {
|
|||
|
||||
@Override
|
||||
public Paging<TaskLogVo> selectTaskLogPageList(PageRequest<TaskLogBo> request) {
|
||||
|
||||
TaskLog taskLog = request.getData().to(TaskLog.class);
|
||||
|
||||
Paging<TaskLog> byTaskId = taskLogData.findByTaskId(taskLog.getTaskId(), request.getPageNum(), request.getPageSize());
|
||||
return byTaskId.to(TaskLogVo.class);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class TaskManager implements ApplicationContextAware {
|
|||
int idx = 1;
|
||||
while (true) {
|
||||
PageRequest<TaskInfo> pageRequest = new PageRequest<>();
|
||||
pageRequest.setPageNum(idx+=1);
|
||||
pageRequest.setPageNum(idx);
|
||||
pageRequest.setPageSize(100);
|
||||
Paging<TaskInfo> all = taskInfoData.findAll(pageRequest);
|
||||
List<TaskInfo> 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);
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue