Commit ed4219d0 by huangfusuper

重构折线图

parent cf84567e
...@@ -170,6 +170,8 @@ public class ApiFlowController { ...@@ -170,6 +170,8 @@ public class ApiFlowController {
return ResponseResult.ok("SUCCESS"); return ResponseResult.ok("SUCCESS");
} }
/** /**
* 获取整体运行的统计数据 * 获取整体运行的统计数据
* @param param * @param param
......
package com.byit.service.impl; package com.byit.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.byit.dto.StatisticsConditionDto;
import com.byit.dto.api.DeleteDto; import com.byit.dto.api.DeleteDto;
import com.byit.dto.plugin.*; import com.byit.dto.plugin.*;
import com.byit.enums.*; import com.byit.enums.*;
...@@ -31,6 +33,7 @@ import javax.annotation.Resource; ...@@ -31,6 +33,7 @@ import javax.annotation.Resource;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName; import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
...@@ -768,11 +771,166 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -768,11 +771,166 @@ public class ApiFlowServiceImpl implements ApiFlowService {
} }
//如果工作空间下面有数据 //如果工作空间下面有数据
if (flowIdList.size() > 0){ if (flowIdList.size() > 0){
return buildStatisticDate(startTime, endTime, flowIdList); return buildStatisticAllDate(startTime, endTime, workspace.getWorkspaceId(),null);
} }
return null; return null;
} }
//--------------------------------------------------------------------
private CollectData buildStatisticAllDate (Long startTime, Long endTime, Integer workspaceId, String flowName) {
StatisticsConditionDto statisticsConditionDto = new StatisticsConditionDto();
statisticsConditionDto.setStartTime(startTime);
statisticsConditionDto.setEndTime(endTime);
statisticsConditionDto.setWorkspaceId(workspaceId);
statisticsConditionDto.setFlowName(flowName);
//查询固定工作空间下 时间范围内的的所由工作流实例数目
List<RunRecording> betweenRunRecording = runRecordingMapper.findThisDayRunRecording(statisticsConditionDto);
Map<String, Long> resultMap = betweenRunRecording.stream().collect(Collectors.groupingBy(RunRecording::getFlowRunResult, Collectors.counting()));
Map<String, Long> statusMap = betweenRunRecording.stream().collect(Collectors.groupingBy(RunRecording::getFlowStatus, Collectors.counting()));
//成功的
long successCount = resultMap.get("1");
long reSuccessCount = resultMap.get("3");
long successTotal = successCount+reSuccessCount;
//失败的
long errorCount = resultMap.get("2");
long reErrorCount = resultMap.get("4");
long killCount = resultMap.get("5");
long errorTotal = errorCount+reErrorCount +killCount;
//运行中的
long runingFlow = statusMap.get("2");
long stopFlow = statusMap.get("3");
long runTotal = runingFlow+stopFlow;
//统计待运行的实例
//统计固定时间内所有flow表的数据 查询所有待运行的工作流
List<Flow> allFlow = flowMapper.findAllByThisDayFlow(statisticsConditionDto);
//统计视力表啊的数据
long notStartFlowCount = statusMap.get("1");
//统计等待表哦数据
List<WaitingRecord> allByCondition = waitingRecordMapper.findAllByCondition(statisticsConditionDto);
int waitFlowCount = 0;
if(CollectionUtil.isNotEmpty(allFlow)) {
waitFlowCount = allFlow.size();
}
int allWaitRecount = 0;
if(CollectionUtil.isNotEmpty(allByCondition)) {
allWaitRecount = allByCondition.size();
}
//待运行的数据
long waitTotal = notStartFlowCount + waitFlowCount + allWaitRecount;
CollectData collectData = new CollectData();
//工作流数据灌输
StatisticData statisticData = new StatisticData();
statisticData.setUnstart((int)waitTotal);
statisticData.setFail((int) errorTotal);
statisticData.setRunIng((int)runTotal);
statisticData.setSuccess((int)successTotal);
collectData.setFlowData(statisticData);
//节点数据灌输
StatisticData nodeStatisticData = statisticsNodeData(betweenRunRecording);
collectData.setNodeData(nodeStatisticData);
List<FlowStatusSnapshoot> aallByCon = flowStatusSnapshootMapper.findAallByCon(statisticsConditionDto);
Map<String, StatisticData> flowCollectMap = new HashMap<>(8);
Map<String, StatisticData> nodeCollectMap = new HashMap<>(8);
Map<String, List<FlowStatusSnapshoot>> collect = aallByCon.stream().collect(Collectors.groupingBy(flowStatusSnapshoot -> flowStatusSnapshoot.getDay() + "/" + flowStatusSnapshoot.getHour()));
collect.forEach((key,value) ->{
List<FlowStatusSnapshoot> flowStatusSnapshoots = collect.get(key);
StatisticData figFlowStatisticData = new StatisticData();
Map<Integer, Long> integerLongMap = flowStatusSnapshoots.stream().collect(Collectors.groupingBy(FlowStatusSnapshoot::getFlowStatus, Collectors.counting()));
//未运行的
long waitFigFlowCount = integerLongMap.get("1");
//运行中的 暂停的
long runFigFlowCount = integerLongMap.get("2");
long stopFigFlowCount = integerLongMap.get("3");
long figRunTotal = runFigFlowCount + stopFigFlowCount;
//成功的
long successFigFlowCount = integerLongMap.get("4");
//失败的
long errorFigFlowCount = integerLongMap.get("5");
long killFigFlowCount = integerLongMap.get("6");
long figErrorTotal = errorFigFlowCount + killFigFlowCount;
figFlowStatisticData.setUnstart((int)waitFigFlowCount);
figFlowStatisticData.setFail((int)figErrorTotal);
figFlowStatisticData.setSuccess((int)successFigFlowCount);
figFlowStatisticData.setRunIng((int)figRunTotal);
flowCollectMap.put(key,figFlowStatisticData);
long nodeError = 0;
long nodeRun = 0;
long nodeWaitRun = 0;
long nodeSuccess = 0;
for (FlowStatusSnapshoot flowStatusSnapshoot : flowStatusSnapshoots) {
nodeError += flowStatusSnapshoot.getFailNode() + flowStatusSnapshoot.getKillNode();
nodeRun += flowStatusSnapshoot.getRuningNode();
nodeWaitRun+=flowStatusSnapshoot.getUnstartNode();
nodeSuccess+=flowStatusSnapshoot.getSuccessNode();
}
StatisticData nodeFigStatisticData = new StatisticData();
nodeFigStatisticData.setSuccess((int)nodeSuccess);
nodeFigStatisticData.setFail((int)nodeError);
nodeFigStatisticData.setRunIng((int)nodeRun);
nodeFigStatisticData.setUnstart((int)nodeWaitRun);
nodeCollectMap.put(key,nodeFigStatisticData);
});
collectData.setFlowCollectMap(flowCollectMap);
collectData.setNodeCollectMap(nodeCollectMap);
return collectData;
}
/**
* 统计非未运行实例的节点数据
* @param betweenRunRecording
* @return
*/
public StatisticData statisticsNodeData (List<RunRecording> betweenRunRecording) {
//剔除未运行状态的实例
List<RunRecording> runRecordings = betweenRunRecording.stream().filter(recording -> !recording.getFlowStatus().equals("1")).collect(Collectors.toList());
List<JobTaskRunLogWithBLOBs> logWithBLOBs = new ArrayList<>(32);
int total = 0;
//查询所有的节点
for (RunRecording runRecording : runRecordings) {
total += runRecording.getFlowNodeCount();
String runId = runRecording.getRunId();
Integer flowId = runRecording.getFlowId();
List<JobTaskRunLogWithBLOBs> flowIdAndRunId = jobTaskRunLogMapper.findJobTaskRunLogWithBLOBsByFlowIdAndRunId(flowId, runId);
if (CollectionUtil.isNotEmpty(flowIdAndRunId)) {
logWithBLOBs.addAll(flowIdAndRunId);
}
}
StatisticData statisticData = new StatisticData();
Map<String, Long> stringLongMap = logWithBLOBs.stream().collect(Collectors.groupingBy(JobTaskRunLogWithBLOBs::getRunCode, Collectors.counting()));
//成功的
long successCount = stringLongMap.get("1");
long reSuccessCount = stringLongMap.get("3");
long successTotal = successCount + reSuccessCount;
//执行中的
long runIngCount = stringLongMap.get("0");
//失败的
long errorCount = stringLongMap.get("2");
long reErorCount = stringLongMap.get("4");
long killCount = stringLongMap.get("5");
long upErrorCount = stringLongMap.get("6");
long errorTotal = errorCount + reErorCount + upErrorCount + killCount;
//待运行的
long waitTotal = total - (successTotal + runIngCount + errorTotal);
statisticData.setSuccess((int)successTotal);
statisticData.setRunIng((int)runIngCount);
statisticData.setFail((int)errorTotal);
statisticData.setUnstart((int)waitTotal);
return statisticData;
}
//--------------------------------------------------------------------
private CollectData buildStatisticDate(Long startTime, Long endTime, List<Integer> flowIdList){ private CollectData buildStatisticDate(Long startTime, Long endTime, List<Integer> flowIdList){
Date startDate = new Date(startTime); Date startDate = new Date(startTime);
Date endDate = new Date(endTime); Date endDate = new Date(endTime);
...@@ -875,7 +1033,7 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -875,7 +1033,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
ValidationUtil.dataNotBank(flowName, "工作流名称不允许为空!"); ValidationUtil.dataNotBank(flowName, "工作流名称不允许为空!");
Flow flow = flowMapper.getByWorkSpaceAndName(workspace.getWorkspaceId(), flowName); Flow flow = flowMapper.getByWorkSpaceAndName(workspace.getWorkspaceId(), flowName);
ValidationUtil.dataNotNull(flow, "工作流不存在!"); ValidationUtil.dataNotNull(flow, "工作流不存在!");
List<Integer> flowIdList = new ArrayList<>(); /*List<Integer> flowIdList = new ArrayList<>();
Queue<Integer> queue = new LinkedList<>(); Queue<Integer> queue = new LinkedList<>();
flowIdList.add(flow.getFlowId()); flowIdList.add(flow.getFlowId());
queue.offer(flow.getFlowId()); queue.offer(flow.getFlowId());
...@@ -889,7 +1047,8 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -889,7 +1047,8 @@ public class ApiFlowServiceImpl implements ApiFlowService {
} }
} }
return buildStatisticDate(startTime, endTime, flowIdList); return buildStatisticDate(startTime, endTime, flowIdList);*/
return buildStatisticAllDate(startTime, endTime, workspace.getWorkspaceId(),flowName);
} }
@Override @Override
......
package com.byit.dto;
import lombok.Data;
@Data
public class StatisticsConditionDto {
private long startTime;
private long endTime;
private Integer workspaceId;
private String flowName;
}
...@@ -7,21 +7,23 @@ package com.byit.enums; ...@@ -7,21 +7,23 @@ package com.byit.enums;
*/ */
public enum ScheduleStatusEnum { public enum ScheduleStatusEnum {
UN_START(1, "未运行"), UN_START("1", "未运行"),
STARTING(2, "运行中"), STARTING("2", "运行中"),
FINISH(4, "暂停"), FINISH("4", "成功"),
STOP(3, "完成"), STOP("3", "暂停"),
ERROR("5", "失败"),
KILL("6", "杀死"),
; ;
private Integer code; private String code;
private String msg; private String msg;
private ScheduleStatusEnum(Integer code, String msg){ ScheduleStatusEnum(String code, String msg){
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;
} }
public Integer getCode(){ public String getCode(){
return this.code; return this.code;
} }
......
...@@ -37,13 +37,13 @@ public class DaemonScanThreadRunHelperRedisLock extends BaseDaemonScanThreadRunH ...@@ -37,13 +37,13 @@ public class DaemonScanThreadRunHelperRedisLock extends BaseDaemonScanThreadRunH
dateAligned(INIT_SLEEP_DATE,threadName); dateAligned(INIT_SLEEP_DATE,threadName);
log.info("---------------{}线程启动成功----------------",threadName); log.info("---------------{}线程启动成功----------------",threadName);
while (!THREAD_GROUP_STOP){ while (!THREAD_GROUP_STOP){
dateAligned(CYCLE_INTERVAL,threadName);
//定义睡眠变量 //定义睡眠变量
Long sleepTime = 0L; Long sleepTime = 0L;
try{ try{
//加锁 //加锁
RedissLockUtil.lock(lockName,120); RedissLockUtil.lock(lockName,120);
log.debug("------------{},加锁成功,锁名称为{}----------",threadName,lockName); log.debug("------------{},加锁成功,锁名称为{}----------",threadName,lockName);
dateAligned(CYCLE_INTERVAL,threadName);
//调用业务操作 //调用业务操作
sleepTime = examplesValue.start(); sleepTime = examplesValue.start();
}catch (Exception e) { }catch (Exception e) {
......
package com.byit.mapper; package com.byit.mapper;
import com.byit.dto.FlowConditionDto; import com.byit.dto.FlowConditionDto;
import com.byit.dto.StatisticsConditionDto;
import com.byit.model.Flow; import com.byit.model.Flow;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -8,6 +9,12 @@ import java.util.List; ...@@ -8,6 +9,12 @@ import java.util.List;
public interface FlowMapper { public interface FlowMapper {
/** /**
* 查询当天将要运行的工作流
* @param statisticsConditionDto
* @return 所有的流信息
*/
List<Flow> findAllByThisDayFlow(StatisticsConditionDto statisticsConditionDto);
/**
* 查询全部的任务流数据 * 查询全部的任务流数据
* @return * @return
*/ */
......
package com.byit.mapper; package com.byit.mapper;
import com.byit.dto.StatisticsConditionDto;
import com.byit.model.FlowStatusSnapshoot; import com.byit.model.FlowStatusSnapshoot;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository
public interface FlowStatusSnapshootMapper { public interface FlowStatusSnapshootMapper {
List<FlowStatusSnapshoot> findAallByCon(StatisticsConditionDto statisticsConditionDto);
/**
* 删除当前时间的工作流快照
*/
void removeThisDateFlowStatusSnapshoot (@Param("thisDay") String thisDay,@Param("thisHour") String thisHour);
int deleteById(Integer statusId); int deleteById(Integer statusId);
int insert(FlowStatusSnapshoot record); int insert(FlowStatusSnapshoot record);
......
package com.byit.mapper; package com.byit.mapper;
import com.byit.dto.FlowConditionDto; import com.byit.dto.FlowConditionDto;
import com.byit.dto.StatisticsConditionDto;
import com.byit.dto.plugin.StatisticData; import com.byit.dto.plugin.StatisticData;
import com.byit.model.RunRecording; import com.byit.model.RunRecording;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -15,6 +16,13 @@ import java.util.List; ...@@ -15,6 +16,13 @@ import java.util.List;
*/ */
@Repository @Repository
public interface RunRecordingMapper { public interface RunRecordingMapper {
/**
* 查询一个时间段的数据
* @param statisticsConditionDto 查询条件
* @return 一个时间段的数据
*/
List<RunRecording> findThisDayRunRecording(StatisticsConditionDto statisticsConditionDto);
/** /**
* 查询全部的数据 * 查询全部的数据
* @return * @return
......
package com.byit.mapper; package com.byit.mapper;
import com.byit.dto.StatisticsConditionDto;
import com.byit.dto.plugin.StatisticData; import com.byit.dto.plugin.StatisticData;
import com.byit.model.WaitingRecord; import com.byit.model.WaitingRecord;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -13,6 +14,12 @@ import java.util.List; ...@@ -13,6 +14,12 @@ import java.util.List;
@Repository @Repository
public interface WaitingRecordMapper { public interface WaitingRecordMapper {
/** /**
*
* @param statisticsConditionDto
* @return
*/
List<WaitingRecord> findAllByCondition(StatisticsConditionDto statisticsConditionDto);
/**
* 查询全部的工作流,同时根据执行时间查询对应的工作流数据 * 查询全部的工作流,同时根据执行时间查询对应的工作流数据
* @param triggerTime 本次的执行时间 * @param triggerTime 本次的执行时间
* @return 即将执行的数据 * @return 即将执行的数据
......
...@@ -89,6 +89,9 @@ public class FlowStatusSnapshoot implements Serializable { ...@@ -89,6 +89,9 @@ public class FlowStatusSnapshoot implements Serializable {
@ApiModelProperty("杀死的节点数目") @ApiModelProperty("杀死的节点数目")
private int killNode; private int killNode;
@ApiModelProperty("工作流快照的时间戳")
private Long triggerTime;
/** /**
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -117,6 +117,9 @@ public class WaitingRecord implements Serializable { ...@@ -117,6 +117,9 @@ public class WaitingRecord implements Serializable {
*/ */
@ApiModelProperty("补批时间") @ApiModelProperty("补批时间")
private String repeatTime; private String repeatTime;
@ApiModelProperty("工作空间id")
private Integer workspaceId;
/** /**
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -19,6 +19,13 @@ import java.util.List; ...@@ -19,6 +19,13 @@ import java.util.List;
public interface FlowService { public interface FlowService {
/** /**
* 查询当天将要运行的工作流
* @param triggerNextTime 下次运行中
* @return 所有的流信息
*/
List<Flow> findAllByThisDayFlow(Long triggerNextTime);
/**
* 查询全部的任务流数据 * 查询全部的任务流数据
* @return * @return
*/ */
......
package com.byit.service;
import com.byit.model.FlowStatusSnapshoot;
import java.util.List;
/**
* 工作流快照业务接口
* @author huangfu
*/
public interface FlowStatusSnapshootService {
/**
* 删除和保存新的工作流快照
* @param allFlow
*/
void removeAndSaveSnapshoot(List<FlowStatusSnapshoot> allFlow);
}
...@@ -11,6 +11,14 @@ import java.util.List; ...@@ -11,6 +11,14 @@ import java.util.List;
* @author huangfu * @author huangfu
*/ */
public interface RunRecordingService { public interface RunRecordingService {
/**
* 查询当天的实例 查询一个时间段的范围
* @param startTime 开始时间
* @param endTime 结束时间
* @return 一个时间段的数据
*/
List<RunRecording> findThisDayRunRecording(Long startTime,Long endTime);
/** /**
* 查询全部数据 映射成VO * 查询全部数据 映射成VO
* @return * @return
......
...@@ -4,6 +4,7 @@ import cn.hutool.http.HttpUtil; ...@@ -4,6 +4,7 @@ import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.byit.dto.FlowConditionDto; import com.byit.dto.FlowConditionDto;
import com.byit.dto.StatisticsConditionDto;
import com.byit.dto.web.ResponseResult; import com.byit.dto.web.ResponseResult;
import com.byit.enums.FlowPropertyEnum; import com.byit.enums.FlowPropertyEnum;
import com.byit.enums.NodePropertyEnum; import com.byit.enums.NodePropertyEnum;
...@@ -53,6 +54,19 @@ public class FlowServiceImpl implements FlowService { ...@@ -53,6 +54,19 @@ public class FlowServiceImpl implements FlowService {
private WorkspaceMapper workspaceMapper; private WorkspaceMapper workspaceMapper;
/**
* 查询当天所有待运行的任务流
* @param triggerNextTime 下次运行中
* @return
*/
@Override
public List<Flow> findAllByThisDayFlow(Long triggerNextTime) {
StatisticsConditionDto statisticsConditionDto = new StatisticsConditionDto();
statisticsConditionDto.setStartTime(0L);
statisticsConditionDto.setEndTime(triggerNextTime);
return flowMapper.findAllByThisDayFlow(statisticsConditionDto);
}
@Override @Override
public List<FlowViewVo> findAllFlowViewVo(FlowConditionDto flowConditionDto) { public List<FlowViewVo> findAllFlowViewVo(FlowConditionDto flowConditionDto) {
List<Flow> allFlow = findAllFlow(flowConditionDto); List<Flow> allFlow = findAllFlow(flowConditionDto);
......
package com.byit.service.impl;
import cn.hutool.core.date.DateUnit;
import com.byit.job.utils.DateUtil;
import com.byit.mapper.FlowStatusSnapshootMapper;
import com.byit.model.FlowStatusSnapshoot;
import com.byit.service.FlowStatusSnapshootService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* 工作流快照操作
*/
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class FlowStatusSnapshootServiceImpl implements FlowStatusSnapshootService {
private final FlowStatusSnapshootMapper flowStatusSnapshootMapper;
public FlowStatusSnapshootServiceImpl(FlowStatusSnapshootMapper flowStatusSnapshootMapper) {
this.flowStatusSnapshootMapper = flowStatusSnapshootMapper;
}
@Override
public void removeAndSaveSnapshoot(List<FlowStatusSnapshoot> allFlow) {
//获取当天的日期
String thisDateStr = DateUtil.dateFormat(new Date(), "yyyyMMdd");
String thisHourStr = DateUtil.dateFormat(new Date(), "HH");
String hourBefStr = String.valueOf(Integer.parseInt(thisHourStr)+1);
//20201212 12:12:12
Date date = DateUtil.strFormatDate(thisDateStr + " " + hourBefStr + ":00:00", "yyyyMMdd HH:mm:dd");
long between = cn.hutool.core.date.DateUtil.between(new Date(), date, DateUnit.MINUTE);
if (between > 3) {
log.info("--------开始删除当前点数的工作流快照----------");
flowStatusSnapshootMapper.removeThisDateFlowStatusSnapshoot(thisDateStr,thisHourStr);
log.info("------删除成功,保存新的工作流快照---------");
flowStatusSnapshootMapper.saveList(allFlow);
}else {
log.info("---------------------------距离下个小时数小于三分钟,跳过本次快照记录-----------------");
}
}
}
package com.byit.service.impl; package com.byit.service.impl;
import com.byit.dto.FlowConditionDto; import com.byit.dto.FlowConditionDto;
import com.byit.dto.StatisticsConditionDto;
import com.byit.enums.RunRecordingEnum; import com.byit.enums.RunRecordingEnum;
import com.byit.mapper.RunRecordingMapper; import com.byit.mapper.RunRecordingMapper;
import com.byit.model.RunRecording; import com.byit.model.RunRecording;
import com.byit.model.vo.RunRecordingViewVo; import com.byit.model.vo.RunRecordingViewVo;
import com.byit.service.RunRecordingService; import com.byit.service.RunRecordingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
...@@ -21,6 +24,8 @@ import java.util.stream.Collectors; ...@@ -21,6 +24,8 @@ import java.util.stream.Collectors;
* @date: 2019/12/26 15:08 * @date: 2019/12/26 15:08
**/ **/
@Service @Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class RunRecordingServiceImpl implements RunRecordingService { public class RunRecordingServiceImpl implements RunRecordingService {
private final RunRecordingMapper runRecordingMapper; private final RunRecordingMapper runRecordingMapper;
...@@ -29,6 +34,21 @@ public class RunRecordingServiceImpl implements RunRecordingService { ...@@ -29,6 +34,21 @@ public class RunRecordingServiceImpl implements RunRecordingService {
this.runRecordingMapper = runRecordingMapper; this.runRecordingMapper = runRecordingMapper;
} }
/**
* 查询当天的数据
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
@Override
public List<RunRecording> findThisDayRunRecording(Long startTime, Long endTime) {
log.debug("--------------查询时间范围为:{} --> {} 的数据--------------",startTime,endTime);
StatisticsConditionDto statisticsConditionDto = new StatisticsConditionDto();
statisticsConditionDto.setStartTime(startTime);
statisticsConditionDto.setEndTime(endTime);
return runRecordingMapper.findThisDayRunRecording(statisticsConditionDto);
}
@Override @Override
public List<RunRecordingViewVo> findAllRunRecordingViewVo(FlowConditionDto flowConditionDt) { public List<RunRecordingViewVo> findAllRunRecordingViewVo(FlowConditionDto flowConditionDt) {
List<RunRecording> runRecordings = findAll(flowConditionDt); List<RunRecording> runRecordings = findAll(flowConditionDt);
......
...@@ -102,7 +102,7 @@ public class ScriptExecutorJobTask implements TimerTask { ...@@ -102,7 +102,7 @@ public class ScriptExecutorJobTask implements TimerTask {
scriptDto.setRunId(mythJobTaskSchedule.getRunId()); scriptDto.setRunId(mythJobTaskSchedule.getRunId());
scriptDto.setRemotePath(mythJobTaskSchedule.getScriptUrls()); scriptDto.setRemotePath(mythJobTaskSchedule.getScriptUrls());
scriptDto.setCallbackUrl(HTTP_PRE+ ServiceInfoUtil.getIpAndPort()+HTTP_SUFFIX); scriptDto.setCallbackUrl(HTTP_PRE+ ServiceInfoUtil.getIpAndPort()+HTTP_SUFFIX);
//二次执行的情况下 会有这个信息 //二次执行的情况下 会有这个信息 //TODO 还是有问题
scriptDto.setLogRemotePath(jobTaskRunLogById.getLogRemotelyPath()); scriptDto.setLogRemotePath(jobTaskRunLogById.getLogRemotelyPath());
DispatchResponseDto dispatchResponseDto = new DispatchResponseDto(); DispatchResponseDto dispatchResponseDto = new DispatchResponseDto();
try{ try{
......
package com.byit.thread.helper;
import com.byit.dto.StatisticsConditionDto;
import com.byit.enums.NodeRunStatusPropertyEnum;
import com.byit.enums.ScheduleStatusEnum;
import com.byit.job.utils.DateUtil;
import com.byit.mapper.FlowStatusSnapshootMapper;
import com.byit.mapper.WaitingRecordMapper;
import com.byit.model.*;
import com.byit.service.*;
import com.byit.thread.BaseThreadRunHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author huangfu
*/
@Slf4j
@Component
public class JobSnapshotThreadRunHelper extends BaseThreadRunHelper {
@Value("${myth-job.snapshoot-date}")
private Long snapshootDate;
private final FlowStatusSnapshootMapper flowStatusSnapshootMapper;
private static final String LOCK_NAME = "JobSnapshotThreadRunHelper";
private static final Long SELLP_TIME = 600000L;
private final DataSource dataSource;
private final FlowService flowService;
private final RunRecordingService runRecordingService;
private final JobTaskRunLogService logService;
private final FlowStatusSnapshootService flowStatusSnapshootService;
private final WaitingRecordMapper waitingRecordMapper;
public JobSnapshotThreadRunHelper(FlowStatusSnapshootMapper flowStatusSnapshootMapper, DataSource dataSource,
FlowService flowService, RunRecordingService runRecordingService, JobTaskRunLogService logService,
FlowStatusSnapshootService flowStatusSnapshootService, WaitingRecordMapper waitingRecordMapper) {
this.flowStatusSnapshootMapper = flowStatusSnapshootMapper;
this.dataSource = dataSource;
this.flowService = flowService;
this.runRecordingService = runRecordingService;
this.logService = logService;
this.flowStatusSnapshootService = flowStatusSnapshootService;
this.waitingRecordMapper = waitingRecordMapper;
}
@Override
public Long start() {
log.info("---------com.byit.thread.helper.JobSnapshotThreadRunHelper.start-------");
log.info("---------当前任务快照计算器启动-------");
//先查找待运行的工作流 也就是查找今天要运行的工作流,理论来说
//运行中的以及成功的失败的都会被加载进实例表,所以这里面遗留的都是今天未运行的工作流,查询今天晚上零点之前的数据
//获取开始时间
long startTime = DateUtil.getThisDayStartDate().getTime();
//获取结束时间
long endTime = DateUtil.getThisDayEndDate().getTime();
//这个是运行状态为待运行的节点
List<Flow> thisDayFlow = flowService.findAllByThisDayFlow(endTime);
//查询当天所有的运行实例
List<RunRecording> thisDayRunRecording = runRecordingService.findThisDayRunRecording(startTime, endTime);
StatisticsConditionDto statisticsConditionDto = new StatisticsConditionDto();
statisticsConditionDto.setStartTime(startTime);
statisticsConditionDto.setEndTime(endTime);
List<WaitingRecord> waitingRecordsList = waitingRecordMapper.findAllByCondition(statisticsConditionDto);
//未运行的工作流
List<FlowStatusSnapshoot> waitFlow = new ArrayList<>(15);
//运行中的工作流
List<FlowStatusSnapshoot> runIngFlow = new ArrayList<>(15);
//暂停的工作流
List<FlowStatusSnapshoot> stopFlow = new ArrayList<>(15);
//成功的工作流
List<FlowStatusSnapshoot> successFlow = new ArrayList<>(15);
//失败的工作流
List<FlowStatusSnapshoot> errorFlow = new ArrayList<>(15);
//杀死的工作流
List<FlowStatusSnapshoot> killFlow = new ArrayList<>(15);
//筛选数据
log.info("------------开始筛选数据---------");
//筛选等待中的数据
log.debug("------------开始筛选等待的工作流---------");
filterWaitFlow(thisDayRunRecording,waitFlow);
flowToFlowStatusSnapshoot(thisDayFlow,waitFlow);
filterWaitingRecordFlow(waitingRecordsList,waitFlow);
log.debug("------------开始筛选运行中的工作流---------");
filterRuningFlow(thisDayRunRecording,runIngFlow);
log.debug("------------开始暂停运行的工作流---------");
filterStopFlow(thisDayRunRecording,stopFlow);
log.debug("------------开始成功运行的工作流---------");
filterSuccessFlow(thisDayRunRecording,successFlow);
log.debug("------------开始失败运行的工作流---------");
filterErrorFlow(thisDayRunRecording,errorFlow);
log.debug("------------开始杀死运行的工作流---------");
filterKillFlow(thisDayRunRecording,killFlow);
List<FlowStatusSnapshoot> allFlow = new ArrayList<>(16);
allFlow.addAll(waitFlow);
allFlow.addAll(runIngFlow);
allFlow.addAll(stopFlow);
allFlow.addAll(successFlow);
allFlow.addAll(errorFlow);
allFlow.addAll(killFlow);
flowStatusSnapshootService.removeAndSaveSnapshoot(allFlow);
//删除超过期限的快照
flowStatusSnapshootMapper.deleteOutSnapShoot(snapshootDate);
return SELLP_TIME;
}
/**
*
* guolvbupichongopai
* @param waitingRecordsList
* @param waitFlow
*/
public void filterWaitingRecordFlow(List<WaitingRecord> waitingRecordsList, List<FlowStatusSnapshoot> waitFlow){
waitingRecordsList.forEach(waitingRecord -> {
FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot();
flowStatusSnapshoot.setWorkspaceId(waitingRecord.getWorkspaceId());
flowStatusSnapshoot.setFlowId(waitingRecord.getFlowId());
flowStatusSnapshoot.setFlowName(waitingRecord.getFlowName());
setThisDate(flowStatusSnapshoot);
flowStatusSnapshoot.setFlowStatus(1);
flowStatusSnapshoot.setSnapshootTime(System.currentTimeMillis());
flowStatusSnapshoot.setTriggerTime(waitingRecord.getTriggerTime());
//未开始节点等于其工作所有节点数
flowStatusSnapshoot.setUnstartNode(waitingRecord.getFlowNodeCount());
flowStatusSnapshoot.setRuningNode(0);
flowStatusSnapshoot.setSuccessNode(0);
flowStatusSnapshoot.setFailNode(0);
flowStatusSnapshoot.setKillNode(0);
waitFlow.add(flowStatusSnapshoot);
});
}
/**
* 统计筛选杀死的工作流
* @param thisDayRunRecording
* @param killFlow
*/
public void filterKillFlow(List<RunRecording> thisDayRunRecording, List<FlowStatusSnapshoot> killFlow) {
List<RunRecording> collect = thisDayRunRecording.stream()
.filter(runRecording -> ScheduleStatusEnum.ERROR.getCode().equals(runRecording.getFlowStatus()))
.collect(Collectors.toList());
collect.forEach(runRecording ->{
FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot();
flowStatusSnapshoot.setFlowStatus(5);
calculationFlowNodeCount(runRecording, flowStatusSnapshoot);
killFlow.add(flowStatusSnapshoot);
});
}
/**
* 筛选统计失败运行的工作流
* @param thisDayRunRecording
* @param errorFlow
*/
public void filterErrorFlow(List<RunRecording> thisDayRunRecording, List<FlowStatusSnapshoot> errorFlow) {
List<RunRecording> collect = thisDayRunRecording.stream()
.filter(runRecording -> ScheduleStatusEnum.ERROR.getCode().equals(runRecording.getFlowStatus()))
.collect(Collectors.toList());
collect.forEach(runRecording ->{
FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot();
flowStatusSnapshoot.setFlowStatus(5);
calculationFlowNodeCount(runRecording, flowStatusSnapshoot);
errorFlow.add(flowStatusSnapshoot);
});
}
/**
* 过滤成功的工作流
* @param thisDayRunRecording 当前世间所有的工作流实例
* @param successFlow 成功的工作流列表
*/
public void filterSuccessFlow (List<RunRecording> thisDayRunRecording, List<FlowStatusSnapshoot> successFlow) {
List<RunRecording> collect = thisDayRunRecording.stream()
.filter(runRecording -> ScheduleStatusEnum.FINISH.getCode().equals(runRecording.getFlowStatus()))
.collect(Collectors.toList());
collect.forEach(runRecording ->{
FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot();
flowStatusSnapshoot.setWorkspaceId(runRecording.getWorkspaceId());
flowStatusSnapshoot.setFlowId(runRecording.getFlowId());
flowStatusSnapshoot.setFlowName(runRecording.getFlowName());
setThisDate(flowStatusSnapshoot);
flowStatusSnapshoot.setFlowStatus(4);
flowStatusSnapshoot.setSnapshootTime(System.currentTimeMillis());
flowStatusSnapshoot.setTriggerTime(runRecording.getTriggerTime());
//成功节点等于其工作所有节点数
flowStatusSnapshoot.setUnstartNode(0);
flowStatusSnapshoot.setRuningNode(0);
flowStatusSnapshoot.setSuccessNode(runRecording.getFlowNodeCount());
flowStatusSnapshoot.setFailNode(0);
flowStatusSnapshoot.setKillNode(0);
successFlow.add(flowStatusSnapshoot);
});
}
/**
* 筛选统计暂停中的工作流
* @param thisDayRunRecording
* @param stopFlow
*/
public void filterStopFlow(List<RunRecording> thisDayRunRecording, List<FlowStatusSnapshoot> stopFlow) {
List<RunRecording> collect = thisDayRunRecording.stream()
.filter(runRecording -> ScheduleStatusEnum.STOP.getCode().equals(runRecording.getFlowStatus()))
.collect(Collectors.toList());
collect.forEach(runRecording ->{
FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot();
flowStatusSnapshoot.setFlowStatus(3);
calculationFlowNodeCount(runRecording, flowStatusSnapshoot);
stopFlow.add(flowStatusSnapshoot);
});
}
/**
* 工作流和快照的相互转换
*/
public void flowToFlowStatusSnapshoot(List<Flow> thisDayFlow, List<FlowStatusSnapshoot> waitFlow){
thisDayFlow.forEach(flow -> {
//获取当天的日期
FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot();
flowStatusSnapshoot.setWorkspaceId(flow.getWorkspaceId());
flowStatusSnapshoot.setFlowId(flow.getFlowId());
flowStatusSnapshoot.setFlowName(flow.getFlowName());
setThisDate(flowStatusSnapshoot);
flowStatusSnapshoot.setFlowStatus(1);
flowStatusSnapshoot.setSnapshootTime(System.currentTimeMillis());
flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount());
flowStatusSnapshoot.setRuningNode(0);
flowStatusSnapshoot.setSuccessNode(0);
flowStatusSnapshoot.setFailNode(0);
flowStatusSnapshoot.setKillNode(0);
waitFlow.add(flowStatusSnapshoot);
});
}
/**
* 统计计算个状态节点的个数
* @param runRecording
* @param flowStatusSnapshoot
*/
private void calculationFlowNodeCount (RunRecording runRecording, FlowStatusSnapshoot flowStatusSnapshoot) {
flowStatusSnapshoot.setWorkspaceId(runRecording.getWorkspaceId());
flowStatusSnapshoot.setFlowId(runRecording.getFlowId());
flowStatusSnapshoot.setFlowName(runRecording.getFlowName());
setThisDate(flowStatusSnapshoot);
flowStatusSnapshoot.setSnapshootTime(System.currentTimeMillis());
flowStatusSnapshoot.setTriggerTime(runRecording.getTriggerTime());
List<JobTaskRunLogWithBLOBs> jobTaskRunLogWithBLOBs = logService.findJobTaskRunLogWithBLOBsByFlowIdAndRunId(runRecording.getFlowId(), runRecording.getRunId());
Map<String, Long> longMap = jobTaskRunLogWithBLOBs.stream().collect(Collectors.groupingBy(JobTaskRunLogWithBLOBs::getRunCode, Collectors.counting()));
//成功的统计
long successCount = longMap.get(NodeRunStatusPropertyEnum.RUN_SUCCESS.getCode());
long reSuccessCount = longMap.get(NodeRunStatusPropertyEnum.RE_RUN_SUCCESS.getCode());
long successTotilCount = successCount + reSuccessCount;
flowStatusSnapshoot.setSuccessNode((int)successTotilCount);
//失败的统计
long erroeCount = longMap.get(NodeRunStatusPropertyEnum.RUN_FAILURE.getCode());
long reErroeCount = longMap.get(NodeRunStatusPropertyEnum.RE_RUN_FAILURE.getCode());
long upNodeErroeCount = longMap.get(NodeRunStatusPropertyEnum.PARENT_NODE_FAILED.getCode());
long errorTotilCount = erroeCount + reErroeCount + upNodeErroeCount;
flowStatusSnapshoot.setFailNode((int)errorTotilCount);
//kill的统计
long killCount = longMap.get(NodeRunStatusPropertyEnum.KILL.getCode());
flowStatusSnapshoot.setKillNode((int)killCount);
//运行中的统计
long runIng = longMap.get(NodeRunStatusPropertyEnum.RUN_ING.getCode());
flowStatusSnapshoot.setRuningNode((int)runIng);
//未运行的统计
Integer totalNodeCount = runRecording.getFlowNodeCount();
long notRunNodeCount = totalNodeCount - (successTotilCount + errorTotilCount + killCount + runIng);
flowStatusSnapshoot.setUnstartNode((int)notRunNodeCount);
}
/**
* 运行中的工作流筛选统计
* @param thisDayRunRecording 今天的所有实例
* @param runIngFlow 运行中的工作流实例列表
*/
public void filterRuningFlow (List<RunRecording> thisDayRunRecording, List<FlowStatusSnapshoot> runIngFlow){
List<RunRecording> collect = thisDayRunRecording.stream()
.filter(runRecording -> ScheduleStatusEnum.STARTING.getCode().equals(runRecording.getFlowStatus()))
.collect(Collectors.toList());
collect.forEach(runRecording ->{
FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot();
flowStatusSnapshoot.setFlowStatus(2);
calculationFlowNodeCount(runRecording, flowStatusSnapshoot);
runIngFlow.add(flowStatusSnapshoot);
});
}
/**
* 从运行实例表中筛选出未运行的
* @param thisDayRunRecording
* @param waitFlow
*/
public void filterWaitFlow (List<RunRecording> thisDayRunRecording, List<FlowStatusSnapshoot> waitFlow){
List<RunRecording> collect = thisDayRunRecording.stream()
.filter(runRecording -> ScheduleStatusEnum.UN_START.getCode().equals(runRecording.getFlowStatus()))
.collect(Collectors.toList());
collect.forEach(runRecording -> {
FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot();
flowStatusSnapshoot.setWorkspaceId(runRecording.getWorkspaceId());
flowStatusSnapshoot.setFlowId(runRecording.getFlowId());
flowStatusSnapshoot.setFlowName(runRecording.getFlowName());
setThisDate(flowStatusSnapshoot);
flowStatusSnapshoot.setFlowStatus(1);
flowStatusSnapshoot.setSnapshootTime(System.currentTimeMillis());
flowStatusSnapshoot.setTriggerTime(runRecording.getTriggerTime());
//未开始节点等于其工作所有节点数
flowStatusSnapshoot.setUnstartNode(runRecording.getFlowNodeCount());
flowStatusSnapshoot.setRuningNode(0);
flowStatusSnapshoot.setSuccessNode(0);
flowStatusSnapshoot.setFailNode(0);
flowStatusSnapshoot.setKillNode(0);
waitFlow.add(flowStatusSnapshoot);
});
}
private void setThisDate(FlowStatusSnapshoot flowStatusSnapshoot){
//获取当天的日期
String thisDateStr = DateUtil.dateFormat(new Date(), "yyyyMMdd");
String thisHourStr = DateUtil.dateFormat(new Date(), "HH");
flowStatusSnapshoot.setDay(thisDateStr);
flowStatusSnapshoot.setHour(thisHourStr);
}
@Override
public DataSource getDataSource() {
return dataSource;
}
@Override
public String getLockName() {
return LOCK_NAME;
}
}
package com.byit.thread.helper; package com.byit.thread.helper;
import com.byit.dto.plugin.StatisticData; import com.byit.dto.plugin.StatisticData;
import com.byit.enums.ScheduleStatusEnum; import com.byit.mapper.FlowMapper;
import com.byit.mapper.*; import com.byit.mapper.FlowStatusSnapshootMapper;
import com.byit.model.*; import com.byit.mapper.JobTaskRunLogMapper;
import com.byit.mapper.RunRecordingMapper;
import com.byit.model.Flow;
import com.byit.model.FlowStatusSnapshoot;
import com.byit.model.RunRecording;
import com.byit.thread.BaseThreadRunHelper; import com.byit.thread.BaseThreadRunHelper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -13,7 +17,10 @@ import org.springframework.stereotype.Component; ...@@ -13,7 +17,10 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.time.*; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
......
...@@ -34,6 +34,23 @@ ...@@ -34,6 +34,23 @@
schedule_follow, is_update, scan_mark schedule_follow, is_update, scan_mark
</sql> </sql>
<select id="findAllByThisDayFlow" resultMap="BaseResultMap" parameterType="com.byit.dto.StatisticsConditionDto">
select
<include refid="Base_Column_List" />
from flow
where
trigger_next_time between #{startTime} and #{endTime}
and remaining_count != 0
and start_up = '0'
<if test="workspaceId != null">
and workspace_id = #{workspaceId}
</if>
<if test="flowName != null and flowName != ''">
flow_name = #{flowName}
</if>
</select>
<select id="findAllFlow" resultMap="BaseResultMap"> <select id="findAllFlow" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
......
...@@ -16,12 +16,32 @@ ...@@ -16,12 +16,32 @@
<result column="success_node" jdbcType="INTEGER" property="successNode" /> <result column="success_node" jdbcType="INTEGER" property="successNode" />
<result column="fail_node" jdbcType="INTEGER" property="failNode" /> <result column="fail_node" jdbcType="INTEGER" property="failNode" />
<result column="kill_node" jdbcType="INTEGER" property="killNode" /> <result column="kill_node" jdbcType="INTEGER" property="killNode" />
<result column="trigger_time" jdbcType="BIGINT" property="triggerTime" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!-- generated @mbg.generated date: 2020-04-02 --> <!-- generated @mbg.generated date: 2020-04-02 -->
status_id, workspace_id, flow_id, flow_name, `day`, `hour`, flow_status, snapshoot_time, status_id, workspace_id, flow_id, flow_name, `day`, `hour`, flow_status, snapshoot_time,
unstart_node, runing_node, success_node, fail_node, kill_node unstart_node, runing_node, success_node, fail_node, kill_node, trigger_time
</sql> </sql>
<select id="findAallByCon" resultMap="BaseResultMap" parameterType="com.byit.dto.StatisticsConditionDto">
select
<include refid="Base_Column_List" />
from flow_status_snapshoot
where trigger_time between #{startTime} and #{endTime}
<if test="workspaceId != null">
and workspace_id = #{workspaceId}
</if>
<if test="flowName != null and flowName != ''">
flow_name = #{flowName}
</if>
</select>
<delete id="removeThisDateFlowStatusSnapshoot">
delete from flow_status_snapshoot where day=#{thisDay} and hour=#{thisHour}
</delete>
<select id="getById" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="getById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!-- generated @mbg.generated date: 2020-04-02 --> <!-- generated @mbg.generated date: 2020-04-02 -->
select select
...@@ -40,12 +60,12 @@ ...@@ -40,12 +60,12 @@
flow_name, `day`, `hour`, flow_name, `day`, `hour`,
flow_status, snapshoot_time, unstart_node, flow_status, snapshoot_time, unstart_node,
runing_node, success_node, fail_node, runing_node, success_node, fail_node,
kill_node) kill_node,trigger_time)
values (#{statusId,jdbcType=INTEGER}, #{workspaceId,jdbcType=INTEGER}, #{flowId,jdbcType=INTEGER}, values (#{statusId,jdbcType=INTEGER}, #{workspaceId,jdbcType=INTEGER}, #{flowId,jdbcType=INTEGER},
#{flowName,jdbcType=VARCHAR}, #{day,jdbcType=VARCHAR}, #{hour,jdbcType=VARCHAR}, #{flowName,jdbcType=VARCHAR}, #{day,jdbcType=VARCHAR}, #{hour,jdbcType=VARCHAR},
#{flowStatus,jdbcType=INTEGER}, #{snapshootTime,jdbcType=BIGINT}, #{unstartNode,jdbcType=INTEGER}, #{flowStatus,jdbcType=INTEGER}, #{snapshootTime,jdbcType=BIGINT}, #{unstartNode,jdbcType=INTEGER},
#{runingNode,jdbcType=INTEGER}, #{successNode,jdbcType=INTEGER}, #{failNode,jdbcType=INTEGER}, #{runingNode,jdbcType=INTEGER}, #{successNode,jdbcType=INTEGER}, #{failNode,jdbcType=INTEGER},
#{killNode,jdbcType=INTEGER}) #{killNode,jdbcType=INTEGER},#{triggerTime,jdbcType=BIGINT})
</insert> </insert>
<insert id="insertSelective" parameterType="com.byit.model.FlowStatusSnapshoot"> <insert id="insertSelective" parameterType="com.byit.model.FlowStatusSnapshoot">
<!-- generated @mbg.generated date: 2020-04-02 --> <!-- generated @mbg.generated date: 2020-04-02 -->
...@@ -173,6 +193,9 @@ ...@@ -173,6 +193,9 @@
<if test="killNode != null"> <if test="killNode != null">
kill_node = #{killNode,jdbcType=INTEGER}, kill_node = #{killNode,jdbcType=INTEGER},
</if> </if>
<if test="triggerTime != null">
trigger_time = #{triggerTime,jdbcType=BIGINT},
</if>
</set> </set>
where status_id = #{statusId,jdbcType=INTEGER} where status_id = #{statusId,jdbcType=INTEGER}
</update> </update>
...@@ -190,7 +213,8 @@ ...@@ -190,7 +213,8 @@
runing_node = #{runingNode,jdbcType=INTEGER}, runing_node = #{runingNode,jdbcType=INTEGER},
success_node = #{successNode,jdbcType=INTEGER}, success_node = #{successNode,jdbcType=INTEGER},
fail_node = #{failNode,jdbcType=INTEGER}, fail_node = #{failNode,jdbcType=INTEGER},
kill_node = #{killNode,jdbcType=INTEGER} kill_node = #{killNode,jdbcType=INTEGER},
trigger_time = #{triggerTime,jdbcType=BIGINT},
where status_id = #{statusId,jdbcType=INTEGER} where status_id = #{statusId,jdbcType=INTEGER}
</update> </update>
<select id="exist" resultType="java.lang.Integer"> <select id="exist" resultType="java.lang.Integer">
...@@ -228,7 +252,7 @@ ...@@ -228,7 +252,7 @@
flow_name, `day`, `hour`, flow_name, `day`, `hour`,
flow_status, snapshoot_time, unstart_node, flow_status, snapshoot_time, unstart_node,
runing_node, success_node, fail_node, runing_node, success_node, fail_node,
kill_node kill_node,trigger_time
) )
VALUES VALUES
<foreach collection="flowStatusSnapshootList" item="flowStatusSnapshoot" separator=","> <foreach collection="flowStatusSnapshootList" item="flowStatusSnapshoot" separator=",">
...@@ -244,7 +268,8 @@ ...@@ -244,7 +268,8 @@
#{flowStatusSnapshoot.runingNode,jdbcType=INTEGER}, #{flowStatusSnapshoot.runingNode,jdbcType=INTEGER},
#{flowStatusSnapshoot.successNode,jdbcType=INTEGER}, #{flowStatusSnapshoot.successNode,jdbcType=INTEGER},
#{flowStatusSnapshoot.failNode,jdbcType=INTEGER}, #{flowStatusSnapshoot.failNode,jdbcType=INTEGER},
#{flowStatusSnapshoot.killNode,jdbcType=INTEGER} #{flowStatusSnapshoot.killNode,jdbcType=INTEGER},
#{flowStatusSnapshoot.triggerTime,jdbcType=BIGINT},
) )
</foreach> </foreach>
</insert> </insert>
......
...@@ -35,6 +35,21 @@ ...@@ -35,6 +35,21 @@
,workspace_id, repeat_time ,workspace_id, repeat_time
</sql> </sql>
<select id="findThisDayRunRecording" resultMap="BaseResultMap" parameterType="com.byit.dto.StatisticsConditionDto">
select
<include refid="Base_Column_List" />
from run_recording
where trigger_time between #{startTime} and #{endTime}
<if test="workspaceId != null">
and workspace_id = #{workspaceId}
</if>
<if test="flowName != null and flowName != ''">
flow_name = #{flowName}
</if>
</select>
<select id="findAll" parameterType="com.byit.dto.FlowConditionDto" resultMap="BaseResultMap"> <select id="findAll" parameterType="com.byit.dto.FlowConditionDto" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
......
...@@ -20,14 +20,31 @@ ...@@ -20,14 +20,31 @@
<result column="wait_order" jdbcType="INTEGER" property="waitOrder" /> <result column="wait_order" jdbcType="INTEGER" property="waitOrder" />
<result column="run_id" jdbcType="VARCHAR" property="runId" /> <result column="run_id" jdbcType="VARCHAR" property="runId" />
<result column="repeat_time" jdbcType="VARCHAR" property="repeatTime" /> <result column="repeat_time" jdbcType="VARCHAR" property="repeatTime" />
<result column="workspace_id" jdbcType="INTEGER" property="workspaceId" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!-- generated @mbg.generated date: 2020-03-12 --> <!-- generated @mbg.generated date: 2020-03-12 -->
wait_id, flow_id, flow_name, flow_version_name, flow_timeout, alarm_email, alarml_action, wait_id, flow_id, flow_name, flow_version_name, flow_timeout, alarm_email, alarml_action,
priority, trigger_time, principal, is_inner, flow_node_count, schedule_type, `operator`, priority, trigger_time, principal, is_inner, flow_node_count, schedule_type, `operator`,
wait_order, run_id, repeat_time wait_order, run_id, repeat_time, workspace_id
</sql> </sql>
<select id="findAllByCondition" resultMap="BaseResultMap" parameterType="com.byit.dto.StatisticsConditionDto">
select
<include refid="Base_Column_List" />
from waiting_record
where trigger_time
between #{startTime} and #{endTime}
<if test="workspaceId != null">
and workspace_id = #{workspaceId}
</if>
<if test="flowName != null and flowName != ''">
flow_name = #{flowName}
</if>
</select>
<select id="findAllByTriggerTime" resultMap="BaseResultMap"> <select id="findAllByTriggerTime" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
...@@ -129,6 +146,9 @@ ...@@ -129,6 +146,9 @@
<if test="repeatTime != null"> <if test="repeatTime != null">
repeat_time, repeat_time,
</if> </if>
<if test="workspaceId != null">
workspace_id,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="waitId != null"> <if test="waitId != null">
...@@ -182,6 +202,9 @@ ...@@ -182,6 +202,9 @@
<if test="repeatTime != null"> <if test="repeatTime != null">
#{repeatTime,jdbcType=VARCHAR}, #{repeatTime,jdbcType=VARCHAR},
</if> </if>
<if test="workspaceId != null">
#{workspaceId,jdbcType=INTEGER},
</if>
</trim> </trim>
</insert> </insert>
<update id="updateByIdSelective" parameterType="com.byit.model.WaitingRecord"> <update id="updateByIdSelective" parameterType="com.byit.model.WaitingRecord">
...@@ -236,6 +259,9 @@ ...@@ -236,6 +259,9 @@
<if test="repeatTime != null"> <if test="repeatTime != null">
repeat_time = #{repeatTime,jdbcType=VARCHAR}, repeat_time = #{repeatTime,jdbcType=VARCHAR},
</if> </if>
<if test="workspaceId != null">
workspace_id = #{workspaceId,jdbcType=INTEGER},
</if>
</set> </set>
where wait_id = #{waitId,jdbcType=INTEGER} where wait_id = #{waitId,jdbcType=INTEGER}
</update> </update>
......
...@@ -21,7 +21,7 @@ public class DateUtil { ...@@ -21,7 +21,7 @@ public class DateUtil {
* @param formatStr 转换格式 * @param formatStr 转换格式
* @return 标准的时间格式 * @return 标准的时间格式
*/ */
public static String dateFormat(Date date,@NotNull String formatStr){ public static String dateFormat(Date date, String formatStr){
LocalDateTime localDateTime = dateToLocalDateTime(date); LocalDateTime localDateTime = dateToLocalDateTime(date);
String dateFormat; String dateFormat;
if(StringUtils.isNotBlank(formatStr)){ if(StringUtils.isNotBlank(formatStr)){
...@@ -134,6 +134,18 @@ public class DateUtil { ...@@ -134,6 +134,18 @@ public class DateUtil {
} }
/** /**
* 字符串转换时间
* @param dateStr 标准时间字符串
* @param dateFormat 时间字符串的格式
* @return 标准时间类型
*/
public static Date strFormatDate(String dateStr,String dateFormat){
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(dateFormat);
LocalDateTime parse = LocalDateTime.parse(dateStr, dtf);
return localDateTimeToDate(parse);
}
/**
* 时间运算 天数相减 * 时间运算 天数相减
* @param date 标准的时间格式 * @param date 标准的时间格式
* @param day 相加天数 * @param day 相加天数
...@@ -148,16 +160,6 @@ public class DateUtil { ...@@ -148,16 +160,6 @@ public class DateUtil {
/** /**
* 字符串转换时间
* @param dateStr 标准时间字符串
* @return 标准时间类型
*/
public static Date strToDate(String dateStr){
LocalDateTime parse = LocalDateTime.parse(dateStr);
return localDateTimeToDate(parse);
}
/**
* date转换为java8的localDate * date转换为java8的localDate
* @param date 标准时间 * @param date 标准时间
* @return java8的时间类型 * @return java8的时间类型
...@@ -192,8 +194,32 @@ public class DateUtil { ...@@ -192,8 +194,32 @@ public class DateUtil {
return Date.from(zonedDateTime.toInstant()); return Date.from(zonedDateTime.toInstant());
} }
/**
* 获取当天结束时间 xxxx-xx-xx 23:59:59
* @return
*/
public static Date getThisDayEndDate(){
LocalDateTime todayEnd = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
return localDateTimeToDate(todayEnd);
}
// public static void main(String[] args) { public static Date getThisDayStartDate() {
// System.out.println(DateUtil.dateLessDayStr(new Date(), "yyyyMMddHHmmss", 1)); //当天零点
// } LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
return localDateTimeToDate(todayStart);
}
public static void main(String[] args) {
String hh = DateUtil.dateFormat(new Date(), "HH");
System.out.println(hh);
String thisDateStr = DateUtil.dateFormat(new Date(), "yyyyMMdd");
String test = thisDateStr + " " + hh + ":00:00";
System.out.println(test);
Date date = DateUtil.strFormatDate(test, "yyyyMMdd HH:mm:ss");
System.out.println(DateUtil.dateFormat(date,"yyyy-MM-dd HH:mm:ss"));
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment