Commit a498f998 by xmh

<feat> 数据概览

1 parent 5281b59d
...@@ -22,6 +22,7 @@ import org.springframework.util.Assert; ...@@ -22,6 +22,7 @@ import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -130,11 +131,14 @@ public class TrafficController extends TrafficBaseController { ...@@ -130,11 +131,14 @@ public class TrafficController extends TrafficBaseController {
/** /**
* 数据概览某个任务某天数据各分析了多少 * 数据概览某个任务某天数据各分析了多少
*/ */
@GetMapping("overView") @GetMapping("overview")
@ResponseBody @ResponseBody
public JsonMessageUtil.JsonMessage<List<DataOverViewModel>> overView() { public JsonMessageUtil.JsonMessage<Collection<DataOverViewModel>> overview(@RequestParam(required = false) Date date
, @RequestParam(required = false) Long taskId) {
List<DataOverViewModel> dataOverViewModels = trafficService.dataOverView(new Date()); if (date == null) {
date = new Date();
}
Collection<DataOverViewModel> dataOverViewModels = trafficService.dataOverview(date, taskId);
return JsonMessageUtil.getSuccessJsonMsg(dataOverViewModels); return JsonMessageUtil.getSuccessJsonMsg(dataOverViewModels);
} }
......
package com.viontech.fanxing.query.model;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/30
*/
@Getter
@Setter
public class DataOverViewModel {
private Long taskId;
private Long traffic;
private Long flow;
private Long behavior;
private Integer hour;
}
package com.viontech.fanxing.query.service.adapter; package com.viontech.fanxing.query.service.adapter;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseService; import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.Traffic; import com.viontech.fanxing.commons.model.Traffic;
import com.viontech.fanxing.commons.vo.TrafficVo; import com.viontech.fanxing.commons.vo.TrafficVo;
import com.viontech.fanxing.query.model.DataOverViewModel;
import java.util.Collection;
import java.util.Date;
public interface TrafficService extends BaseService<Traffic> { public interface TrafficService extends BaseService<Traffic> {
PageInfo<TrafficVo> getJsonData(BaseExample example, int pageNum, int pageSize); PageInfo<TrafficVo> getJsonData(BaseExample example, int pageNum, int pageSize);
Collection<DataOverViewModel> dataOverview(Date date,Long taskId);
} }
\ No newline at end of file \ No newline at end of file
...@@ -7,14 +7,20 @@ import com.github.pagehelper.PageInfo; ...@@ -7,14 +7,20 @@ import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseMapper; import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl; import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.model.Traffic; import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.model.TrafficExample;
import com.viontech.fanxing.commons.vo.TrafficVo; import com.viontech.fanxing.commons.vo.TrafficVo;
import com.viontech.fanxing.query.mapper.TrafficMapper; import com.viontech.fanxing.query.mapper.TrafficMapper;
import com.viontech.fanxing.query.model.DataOverViewModel;
import com.viontech.fanxing.query.service.adapter.BehaviorService;
import com.viontech.fanxing.query.service.adapter.FlowEventService;
import com.viontech.fanxing.query.service.adapter.TrafficService; import com.viontech.fanxing.query.service.adapter.TrafficService;
import com.viontech.keliu.util.DateUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -22,6 +28,10 @@ import java.util.stream.Collectors; ...@@ -22,6 +28,10 @@ import java.util.stream.Collectors;
public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements TrafficService { public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements TrafficService {
@Resource @Resource
private TrafficMapper trafficMapper; private TrafficMapper trafficMapper;
@Resource
private FlowEventService flowEventService;
@Resource
private BehaviorService behaviorService;
@Override @Override
public BaseMapper<Traffic> getMapper() { public BaseMapper<Traffic> getMapper() {
...@@ -50,4 +60,66 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf ...@@ -50,4 +60,66 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
page.addAll(collect); page.addAll(collect);
return new PageInfo<>(page); return new PageInfo<>(page);
} }
@Override
public Collection<DataOverViewModel> dataOverview(Date date, Long taskId) {
Date min = DateUtil.setDayMinTime(date);
Date max = DateUtil.setDayMaxTime(date);
HashMap<Long, DataOverViewModel> resultMap = new HashMap<>();
TrafficExample trafficExample = new TrafficExample();
TrafficExample.Criteria criteria = trafficExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max);
if (taskId != null) {
criteria.andTaskIdEqualTo(taskId);
}
trafficExample.createColumns().hasTaskIdColumn().addColumnStr("count(*) as count");
trafficExample.setGroupByClause("task_id");
trafficExample.setOrderByClause("task_id");
List<Traffic> traffic = trafficMapper.selectByExample(trafficExample);
for (Traffic t : traffic) {
DataOverViewModel dov = resultMap.computeIfAbsent(t.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
return temp;
});
dov.setTraffic(t.getCount());
}
FlowEventExample flowEventExample = new FlowEventExample();
FlowEventExample.Criteria criteria1 = flowEventExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max);
if (taskId != null) {
criteria1.andTaskIdEqualTo(taskId);
}
flowEventExample.createColumns().hasTaskIdColumn().addColumnStr("count(*) as count");
flowEventExample.setGroupByClause("task_id");
flowEventExample.setOrderByClause("task_id");
List<FlowEvent> flowEvents = flowEventService.getMapper().selectByExample(flowEventExample);
for (FlowEvent f : flowEvents) {
DataOverViewModel dov = resultMap.computeIfAbsent(f.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
return temp;
});
dov.setFlow(f.getCount());
}
BehaviorExample behaviorExample = new BehaviorExample();
BehaviorExample.Criteria criteria2 = behaviorExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max);
if (taskId != null) {
criteria2.andTaskIdEqualTo(taskId);
}
behaviorExample.createColumns().hasTaskIdColumn().addColumnStr("count(*) as count");
behaviorExample.setGroupByClause("task_id");
behaviorExample.setOrderByClause("task_id");
List<Behavior> behaviors = behaviorService.getMapper().selectByExample(behaviorExample);
for (Behavior b : behaviors) {
DataOverViewModel dov = resultMap.computeIfAbsent(b.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
return temp;
});
dov.setBehavior(b.getCount());
}
return resultMap.values();
}
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!