Commit d691a9a5 by guominglei

修改统计快照的方法

parent 52b5f3fe
...@@ -47,4 +47,13 @@ public interface FlowStatusSnapshootMapper { ...@@ -47,4 +47,13 @@ public interface FlowStatusSnapshootMapper {
* @return * @return
*/ */
List<FlowStatusSnapshoot> findByTime(@Param("startTime")Long startTime, @Param("endTime")Long endTime); List<FlowStatusSnapshoot> findByTime(@Param("startTime")Long startTime, @Param("endTime")Long endTime);
/**
* 根据天、小时、工作流id获取快照信息
* @param date
* @param hour
* @param flowId
* @return
*/
List<FlowStatusSnapshoot> findByDateAndHourAndFlowId(@Param("date")String date, @Param("hour")String hour, @Param("flowId")Integer flowId);
} }
\ No newline at end of file
...@@ -37,10 +37,6 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -37,10 +37,6 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
@Resource @Resource
private JobTaskRunLogMapper jobTaskRunLogMapper; private JobTaskRunLogMapper jobTaskRunLogMapper;
@Resource @Resource
private WaitingRecordMapper waitingRecordMapper;
@Resource
private WaitingTaskMapper waitingTaskMapper;
@Resource
private DataSource dataSource; private DataSource dataSource;
@Value("${myth-job.snapshoot-date}") @Value("${myth-job.snapshoot-date}")
private Integer snapshootDate; private Integer snapshootDate;
...@@ -79,16 +75,21 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -79,16 +75,21 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
//统计运行实例的数据 //统计运行实例的数据
//如果存在实例 //如果存在实例
if (maxRunRecording != null){ if (maxRunRecording != null){
//获取上一个时间 //获取今天凌晨的时间戳
Long preHourTime = hourDateTime.minusHours(1).toInstant(ZoneOffset.of("+8")).toEpochMilli(); Long time = LocalDate.now().atStartOfDay(ZoneOffset.ofHours(8)).toInstant().toEpochMilli();
//从凌晨到现在是否有运行实例 //从凌晨到现在是否有运行实例
if (preHourTime.longValue() > maxRunRecording.getTriggerTime().longValue() && ScheduleStatusEnum.FINISH.getCode().equals(maxRunRecording.getFlowStatus())){ if (time.longValue() > maxRunRecording.getTriggerTime().longValue()){
flowStatusSnapshoot.setFlowStatus(1); flowStatusSnapshoot.setFlowStatus(1);
flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount()); flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount());
flowStatusSnapshootList.add(flowStatusSnapshoot); flowStatusSnapshootList.add(flowStatusSnapshoot);
} else { //存在工作流的运行实例 } else { //从凌晨到现在存在工作流的运行实例
//获取上一个小时的时间戳
Long preHourTime = hourDateTime.minusHours(1).toInstant(ZoneOffset.of("+8")).toEpochMilli();
//查询过去一个小时的和未完成的工作流实例 //查询过去一个小时的和未完成的工作流实例
List<RunRecording> runRecordingList = runRecordingMapper.findByPreTime(new Date(preHourTime), flow.getFlowId()); List<RunRecording> runRecordingList = runRecordingMapper.findByPreTime(new Date(preHourTime), flow.getFlowId());
//判断是否存在过去一个小时的和未完成的工作流实例
if(null != runRecordingList && runRecordingList.size() > 0){
//如果存在,记录快照
runRecordingList.forEach(runRecording -> { runRecordingList.forEach(runRecording -> {
FlowStatusSnapshoot hourFlowStatusSnapshoot = new FlowStatusSnapshoot(); FlowStatusSnapshoot hourFlowStatusSnapshoot = new FlowStatusSnapshoot();
BeanUtils.copyProperties(flowStatusSnapshoot, hourFlowStatusSnapshoot); BeanUtils.copyProperties(flowStatusSnapshoot, hourFlowStatusSnapshoot);
...@@ -122,37 +123,20 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -122,37 +123,20 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
} }
flowStatusSnapshootList.add(hourFlowStatusSnapshoot); flowStatusSnapshootList.add(hourFlowStatusSnapshoot);
}); });
}else {
//如果不存在实例,获取上一个小时的运行快照保存
LocalDateTime preHourLocalDateTime = localDateTime.minusHours(1);
String preHourDate = preHourLocalDateTime.format(DATE_FORMATTER);
String preHourHour = String.valueOf(preHourLocalDateTime.getHour());
List<FlowStatusSnapshoot> preHourFlowStatusSnapshootList = flowStatusSnapshootMapper.findByDateAndHourAndFlowId(preHourDate, preHourHour, flow.getFlowId());
flowStatusSnapshootList.addAll(preHourFlowStatusSnapshootList);
}
} }
}else { }else {
//如果不存在运行实例 //如果不存在运行实例
flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount()); flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount());
flowStatusSnapshootList.add(flowStatusSnapshoot); flowStatusSnapshootList.add(flowStatusSnapshoot);
} }
/*
排队的运行实例已经放在run_recording表中,无需二次记录
//获取排队的运行实例
List<WaitingRecord> waitingRecordList = waitingRecordMapper.findByFlowId(flow.getFlowId());
if (waitingRecordList != null && waitingRecordList.size() > 0){
//如果存在正在排队的实例
waitingRecordList.forEach(waitingRecord -> {
//创建工作流快照
FlowStatusSnapshoot waitingStatusSnapshoot = new FlowStatusSnapshoot();
waitingStatusSnapshoot.setDay(date);
waitingStatusSnapshoot.setFlowId(flow.getFlowId());
waitingStatusSnapshoot.setHour(hour);
waitingStatusSnapshoot.setFlowName(flow.getFlowName());
waitingStatusSnapshoot.setWorkspaceId(flow.getWorkspaceId());
waitingStatusSnapshoot.setSnapshootTime(hourTime);
waitingStatusSnapshoot.setFlowStatus(1);
//获取排队的节点数目
List<WaitingTask> waitingTaskList = waitingTaskMapper.findAllByWaitId(waitingRecord.getWaitId());
if (waitingTaskList != null && waitingTaskList.size() > 0){
waitingStatusSnapshoot.setUnstartNode(waitingTaskList.size());
}
flowStatusSnapshootList.add(waitingStatusSnapshoot);
});
}*/
}); });
if (flowList != null && flowList.size() > 0){ if (flowList != null && flowList.size() > 0){
flowStatusSnapshootMapper.saveList(flowStatusSnapshootList); flowStatusSnapshootMapper.saveList(flowStatusSnapshootList);
......
...@@ -205,6 +205,11 @@ ...@@ -205,6 +205,11 @@
where snapshoot_time &gt;= #{startTime} where snapshoot_time &gt;= #{startTime}
and snapshoot_time &lt;= #{endTime} and snapshoot_time &lt;= #{endTime}
</select> </select>
<select id="findByDateAndHourAndFlowId" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from flow_status_snapshoot
where `day` = #{date} and `hour` = #{hour} and flow_id = #{flowId}
</select>
<delete id="deleteOutSnapShoot" parameterType="java.lang.Long"> <delete id="deleteOutSnapShoot" parameterType="java.lang.Long">
delete from flow_status_snapshoot delete from flow_status_snapshoot
where snapshoot_time = #{outTime,jdbcType=BIGINT} where snapshoot_time = #{outTime,jdbcType=BIGINT}
......
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