|
|
|
@ -57,14 +57,26 @@ public class StatisticalController {
|
|
|
|
|
@PostMapping("/statisticalInformation") |
|
|
|
|
@ApiOperation("农场数据统计接口") |
|
|
|
|
public CommonResult<StatisticalVo> statisticalInformation(@RequestBody RequestDTO searchDTO){ |
|
|
|
|
TimeLimitDTO time = FarmTimeUtil.getStartTimeAndEndTime(searchDTO.getTimeEnum()); |
|
|
|
|
StatisticalVo vo = new StatisticalVo(); |
|
|
|
|
//获取时间内的所有工时记录
|
|
|
|
|
List<WorkHourDO> workList = workHourMapper.selectList(Wrappers.<WorkHourDO>lambdaQuery().ge(WorkHourDO::getCreateTime, time.getStartTime()).le(WorkHourDO::getCreateTime, time.getEndTime())); |
|
|
|
|
//工时统计
|
|
|
|
|
this.workHourMsg(searchDTO, vo); |
|
|
|
|
//任务数据
|
|
|
|
|
List<TaskDO> taskList = this.projectMsg(vo); |
|
|
|
|
//种植数量 饼状图
|
|
|
|
|
this.cakeMsg(vo, taskList); |
|
|
|
|
return CommonResult.success(vo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 工时统计 |
|
|
|
|
*/ |
|
|
|
|
public void workHourMsg(RequestDTO searchDTO, StatisticalVo vo){ |
|
|
|
|
TimeLimitDTO time = FarmTimeUtil.getStartTimeAndEndTime(searchDTO.getTimeEnum()); |
|
|
|
|
vo.setStartTime(DateUtil.format(time.getStartTime(), "yyyy/MM/dd" )); |
|
|
|
|
vo.setEndTime(DateUtil.format(time.getEndTime(), "yyyy/MM/dd" )); |
|
|
|
|
|
|
|
|
|
//获取时间内的所有工时记录
|
|
|
|
|
List<WorkHourDO> workList = workHourMapper.selectList(Wrappers.<WorkHourDO>lambdaQuery().ge(WorkHourDO::getCreateTime, time.getStartTime()).le(WorkHourDO::getCreateTime, time.getEndTime())); |
|
|
|
|
//工时统计 条形图
|
|
|
|
|
List<WorkMsg> workMsgList = new ArrayList<>(); |
|
|
|
|
if (ObjectUtil.isEmpty(workList)){ |
|
|
|
@ -74,11 +86,8 @@ public class StatisticalController {
|
|
|
|
|
List<Long> workUserIdList = workList.stream().map(WorkHourDO::getUserId).collect(Collectors.toList()); |
|
|
|
|
//获取工时所有人信息
|
|
|
|
|
List<CpUserDO> userList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, workUserIdList)); |
|
|
|
|
|
|
|
|
|
Map<Long, List<WorkHourDO>> workMap = workList.stream().collect(Collectors.groupingBy(WorkHourDO::getUserId)); |
|
|
|
|
Iterator<Map.Entry<Long, List<WorkHourDO>>> iterator = workMap.entrySet().iterator(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (iterator.hasNext()){ |
|
|
|
|
Entry<Long, List<WorkHourDO>> entry = iterator.next(); |
|
|
|
|
Long userId = entry.getKey(); |
|
|
|
@ -93,10 +102,12 @@ public class StatisticalController {
|
|
|
|
|
workMsgList = workMsgList.stream().sorted(Comparator.comparing(WorkMsg::getHour).reversed()).collect(Collectors.toList()); |
|
|
|
|
vo.setWorkMsgList(workMsgList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//任务数据
|
|
|
|
|
/** |
|
|
|
|
* 项目数据 |
|
|
|
|
*/ |
|
|
|
|
public List<TaskDO> projectMsg(StatisticalVo vo){ |
|
|
|
|
List<TaskDO> taskList = taskMapper.selectList(Wrappers.<TaskDO>lambdaQuery().eq(TaskDO::getPretendDelete, false).eq(TaskDO::getDraft, false)); |
|
|
|
|
vo.setTaskTotalCount(taskList.size()); |
|
|
|
|
Long planeCount = taskList.stream().filter(plane -> plane.getStatus().equals(TaskStatus.PLAN) || plane.getStatus().equals(TaskStatus.READY)).count(); |
|
|
|
@ -106,57 +117,52 @@ public class StatisticalController {
|
|
|
|
|
vo.setTaskStartingCount(startCount.intValue()); |
|
|
|
|
Long completeCount = taskList.stream().filter(plane -> plane.getStatus().equals(TaskStatus.COMPLETE) || plane.getStatus().equals(TaskStatus.END)).count(); |
|
|
|
|
vo.setTaskCompleteCount(completeCount.intValue()); |
|
|
|
|
return taskList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 饼状图数据 |
|
|
|
|
*/ |
|
|
|
|
public void cakeMsg(StatisticalVo vo, List<TaskDO> taskList){ |
|
|
|
|
//种植数量 饼状图
|
|
|
|
|
//根据工时获取所有的活动
|
|
|
|
|
List<TaskDO> finishTaskList = taskList.stream().filter(item -> item.getStatus().equals(TaskStatus.COMPLETE)).collect(Collectors.toList()); |
|
|
|
|
List<Long> cropIdList = finishTaskList.stream().map(TaskDO::getCropId).collect(Collectors.toList()); |
|
|
|
|
List<Long> cropIdList = finishTaskList.stream().map(TaskDO::getCropId).distinct().collect(Collectors.toList()); |
|
|
|
|
if (ObjectUtils.isEmpty(cropIdList)){ |
|
|
|
|
vo.setCakeSeries(new ArrayList<>()); |
|
|
|
|
}else { |
|
|
|
|
List<CropDO> cropList = cropMapper.selectList(Wrappers.<CropDO>lambdaQuery().in(CropDO::getId, cropIdList)); |
|
|
|
|
List<AreaDO> areaList = areaMapper.selectList(Wrappers.<AreaDO>lambdaQuery().eq(AreaDO::getPretendDelete, false).ne(AreaDO::getParentId, 0)); |
|
|
|
|
Map<Long, CakeSeries> cropMap = new HashMap<>(); |
|
|
|
|
for (TaskDO taskDO : finishTaskList) { |
|
|
|
|
for (CropDO cropDO : cropList) { |
|
|
|
|
if (taskDO.getCropId().equals(cropDO.getId())){ |
|
|
|
|
//这里是算 这个任务所选区域的总面积
|
|
|
|
|
Double areaSum = new Double(0); |
|
|
|
|
cropList.forEach(item ->{ |
|
|
|
|
//初始化cropMap, key = 作物id, value是饼状图属性
|
|
|
|
|
cropMap.put(item.getId(), new CakeSeries().setName(item.getName()).setValue(0d).setLabelText("0")); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
List<Long> areaIdList = new ArrayList<>(); |
|
|
|
|
finishTaskList.stream().forEach(item ->{ |
|
|
|
|
areaIdList.addAll(item.getAreas()); |
|
|
|
|
}); |
|
|
|
|
List<Long> distinctIdList = areaIdList.stream().distinct().collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
List<AreaDO> areaDOList = areaMapper.selectList(Wrappers.<AreaDO>lambdaQuery().in(AreaDO::getId, distinctIdList)); |
|
|
|
|
finishTaskList.forEach(taskDO -> { |
|
|
|
|
//先算出每个完成的任务所选区域的面积和
|
|
|
|
|
Double areaSum = 0d; |
|
|
|
|
for (Long areaId : taskDO.getAreas()) { |
|
|
|
|
List<AreaDO> areaDOS = areaList.stream().filter(area -> area.getId().equals(areaId)).collect(Collectors.toList()); |
|
|
|
|
if (ObjectUtil.isNotEmpty(areaDOS)){ |
|
|
|
|
areaSum += areaDOS.stream().mapToDouble(AreaDO::getArea).sum(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//饼状图 作物名
|
|
|
|
|
if (cropMap.containsKey(cropDO.getId())){ |
|
|
|
|
CakeSeries cakeSeries = cropMap.get(cropDO.getId()); |
|
|
|
|
cakeSeries.setValue(cakeSeries.getValue() + areaSum); |
|
|
|
|
cakeSeries.setLabelText(cakeSeries.getValue().toString()); |
|
|
|
|
}else{ |
|
|
|
|
CakeSeries cakeSeries = CakeSeries.builder() |
|
|
|
|
.name(cropDO.getName()) |
|
|
|
|
.value(areaSum) |
|
|
|
|
.labelText(areaSum.toString()) |
|
|
|
|
.build(); |
|
|
|
|
cropMap.put(cropDO.getId(), cakeSeries); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Optional<AreaDO> areaDO = areaDOList.stream().filter(item -> item.getId().equals(areaId)).collect(Collectors.toList()).stream().findFirst(); |
|
|
|
|
areaSum += areaDO.isPresent() ? areaDO.get().getArea() : 0; |
|
|
|
|
} |
|
|
|
|
List<CakeSeries> cakeList = new ArrayList<>(); |
|
|
|
|
Iterator<Entry<Long, CakeSeries>> cropItertor = cropMap.entrySet().iterator(); |
|
|
|
|
while (cropItertor.hasNext()){ |
|
|
|
|
cakeList.add(cropItertor.next().getValue()); |
|
|
|
|
//再与cropMap 进行 累加面积
|
|
|
|
|
if (cropMap.containsKey(taskDO.getCropId())){ |
|
|
|
|
CakeSeries ck = cropMap.get(taskDO.getCropId()); |
|
|
|
|
ck.setValue(ck.getValue() + areaSum); |
|
|
|
|
ck.setLabelText(ck.getValue().toString()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
List<CakeSeries> cakeList = cropMap.values().stream().collect(Collectors.toList()); |
|
|
|
|
vo.setCakeSeries(cakeList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
vo.setCakeTitle("总数量"); |
|
|
|
|
vo.setCakeSubtitle(vo.getCakeSeries().stream().mapToDouble(CakeSeries::getValue).sum()+"平方"); |
|
|
|
|
|
|
|
|
|
return CommonResult.success(vo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|