Commit aec307f9 by guo_minglei@163.com

统计数据接口返回

parent 84f12afb
......@@ -16,7 +16,6 @@ import com.byit.mapper.*;
import com.byit.model.JobTaskRunLog;
import com.byit.model.RunRecording;
import com.byit.model.*;
import com.byit.model.po.StatusPO;
import com.byit.model.vo.RunRecordingVo;
import com.byit.service.ApiFlowService;
import com.byit.util.ApiFlowDagCheck;
......@@ -82,6 +81,9 @@ public class ApiFlowServiceImpl implements ApiFlowService {
private WaitingTaskMapper waitingTaskMapper;
@Resource
private FlowStatusSnapshootMapper flowStatusSnapshootMapper;
@Resource
private CurrentUserUtils currentUserUtils;
private void parseParam(String param, DeleteDto deletDto){
......@@ -726,13 +728,37 @@ public class ApiFlowServiceImpl implements ApiFlowService {
}
}
List<StatusPO> runRecordingList = runRecordingMapper.findStatusByStartAndEndTime(startTime, endTime, flowIdList);
List<StatusPO> runLogList = jobTaskRunLogMapper.findStatusByStartAndEndTime(startTime, endTime, flowIdList);
StatisticData nodeDate = new StatisticData();
runLogList.forEach(statusPO -> {
StatisticData flowStatisticData = runRecordingMapper.findStatusByStartAndEndTime(startTime, endTime, flowIdList);
StatisticData nodeStatisticData = jobTaskRunLogMapper.findStatusByStartAndEndTime(startTime, endTime, flowIdList);
List<FlowStatusSnapshoot> flowStatusSnapshootList = flowStatusSnapshootMapper.findByTime(startTime, endTime);
Map<String, StatisticData> collectMap = new HashMap<>();
flowStatusSnapshootList.forEach(flowStatusSnapshoot -> {
String key = flowStatusSnapshoot.getDay() + " " + flowStatusSnapshoot.getHour();
StatisticData statisticData = collectMap.get(key);
if (null == statisticData){
statisticData = new StatisticData();
statisticData.setUnstart(flowStatusSnapshoot.getUnstartNode());
statisticData.setRunIng(flowStatusSnapshoot.getRuningNode());
statisticData.setSuccess(flowStatusSnapshoot.getSuccessNode());
statisticData.setFail(flowStatusSnapshoot.getFailNode());
statisticData.setKill(flowStatusSnapshoot.getKillNode());
collectMap.put(key, statisticData);
}else {
statisticData.setUnstart(statisticData.getUnstart() + flowStatusSnapshoot.getUnstartNode());
statisticData.setRunIng(statisticData.getRunIng() + flowStatusSnapshoot.getRuningNode());
statisticData.setSuccess(statisticData.getSuccess() + flowStatusSnapshoot.getSuccessNode());
statisticData.setFail(statisticData.getFail() + flowStatusSnapshoot.getFailNode());
statisticData.setKill(statisticData.getKill() + flowStatusSnapshoot.getKillNode());
collectMap.put(key, statisticData);
}
});
return null;
CollectData collectData = new CollectData();
collectData.setFlowData(flowStatisticData);
collectData.setNodeData(nodeStatisticData);
collectData.setCollectMap(collectMap);
return collectData;
}
public static void main(String[] args) throws ParseException {
......
......@@ -38,4 +38,12 @@ public interface FlowStatusSnapshootMapper {
* @return
*/
int deleteOutSnapShoot(Long outTime);
/**
* 根据时间范围查询
* @param startTime
* @param endTime
* @return
*/
List<FlowStatusSnapshoot> findByTime(Long startTime, Long endTime);
}
\ No newline at end of file
......@@ -3,7 +3,6 @@ package com.byit.mapper;
import com.byit.dto.plugin.StatisticData;
import com.byit.model.JobTaskRunLog;
import com.byit.model.JobTaskRunLogWithBLOBs;
import com.byit.model.po.StatusPO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
......@@ -120,7 +119,7 @@ public interface JobTaskRunLogMapper {
* @param flowIdList
* @return
*/
List<StatusPO> findStatusByStartAndEndTime(@Param("startTime")Long startTime,
StatisticData findStatusByStartAndEndTime(@Param("startTime")Long startTime,
@Param("endTime")Long endTime,
@Param("flowIdList")List<Integer> flowIdList);
......
package com.byit.mapper;
import com.byit.dto.plugin.StatisticData;
import com.byit.model.RunRecording;
import com.byit.model.po.StatusPO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
......@@ -166,9 +166,9 @@ public interface RunRecordingMapper {
* @param flowIdList
* @return
*/
List<StatusPO> findStatusByStartAndEndTime(@Param("startTime")Long startTime,
@Param("endTime")Long endTime,
@Param("flowIdList")List<Integer> flowIdList);
StatisticData findStatusByStartAndEndTime(@Param("startTime")Long startTime,
@Param("endTime")Long endTime,
@Param("flowIdList")List<Integer> flowIdList);
RunRecording findMaxByFlowId(@Param("flowId")Integer flowId);
}
\ No newline at end of file
package com.byit.model.po;
import lombok.Data;
/**
* @Description
* @Author guo_m
* @Date 2020-04-01
*/
@Data
public class StatusPO {
private Integer flowId;
private Integer nodeId;
private Integer status;
private Long startTime;
}
package com.byit.thread.helper;
import com.alibaba.fastjson.JSON;
import com.byit.dto.plugin.StatisticData;
import com.byit.mapper.FlowMapper;
import com.byit.mapper.FlowStatusSnapshootMapper;
......
......@@ -198,6 +198,13 @@
from flow_status_snapshoot
where 'day' = #{date} and `hour` = #{hour}
</select>
<select id="findByTime" resultType="com.byit.model.FlowStatusSnapshoot">
select
<include refid="Base_Column_List" />
from flow_status_snapshoot
where snapshoot_time &gt;= ${startDate}
and snapshoot_time &lt;= ${endDate}
</select>
<delete id="deleteOutSnapShoot" parameterType="java.lang.Long">
delete from flow_status_snapshoot
where snapshoot_time = #{outTime,jdbcType=BIGINT}
......
......@@ -121,20 +121,13 @@
from job_task_run_log
where log_id = #{logId,jdbcType=INTEGER}
</select>
<select id="findStatusByStartAndEndTime" resultType="com.byit.model.po.StatusPO">
select case run_code
when 0 then 2
when 1 then 3
when 2 then 4
when 3 then 3
when 4 then 4
when 5 then 5
when 5 then 4
else 0
end status,
start_time
from job_task_run_log
where start_time &gt;= ${startDate}
<select id="findStatusByStartAndEndTime" resultType="com.byit.dto.plugin.StatisticData">
select sum(case when run_code = '0' then 1 else 0 end) as runIng,
sum(case when run_code = '1' or run_code = '3' then 1 else 0 end) as success,
sum(case when run_code = '2' or run_code = '4' or run_code = '6' then 1 else 0 end) as fail,
sum(case when run_code = '5' then 1 else 0 end) as 'kill'
from job_task_run_log
where start_time &gt;= ${startDate}
and end_time &lt;= ${endDate}
<if test="flowIds != null">
and flow_id in (
......
......@@ -148,26 +148,14 @@
where flow_id = #{flowId}
and flow_status != '4'
</select>
<select id="findStatusByStartAndEndTime" resultType="com.byit.model.po.StatusPO">
select flowStatus + results as status, start_time as startTime, flow_id as flowId
from (
select
case flow_status
when 1 then 1
when 2 then 2
else 0
end flowStatus,
case flow_run_result
when 1 then 3
when 2 then 4
when 3 then 3
when 4 then 4
when 5 then 5
else 0
end results,
start_time,
flow_id
from run_recording
<select id="findStatusByStartAndEndTime" resultType="com.byit.dto.plugin.StatisticData">
select sum(case when flow_status = '1' then 1 else 0 end ) unstart,
sum(case when flow_status='2' then 1 else 0 end ) runing,
sum(case when flow_status='3' then 1 else 0 end ) stop,
sum(case when flow_status='4' and (flow_run_result = '1' or flow_run_result = '3') then 1 else 0 end ) success,
sum(case when flow_status='4' and (flow_run_result = '2' or flow_run_result = '4') then 1 else 0 end ) fail,
sum(case when flow_run_result='5' then 1 else 0 end ) 'kill'
from run_recording
where start_time &gt;= ${startDate}
and end_time &lt;= ${endDate}
<if test="flowIds != null">
......@@ -177,7 +165,6 @@
</foreach>
)
</if>
) recording
</select>
<select id="findMaxByFlowId" resultType="com.byit.model.RunRecording">
select <include refid="Base_Column_List" />
......
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