Browse Source

统计图优化

zyh
WIN-IDGBLFHC1K6\Administrator 3 years ago
parent
commit
a71bc7d6b2
  1. 27
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java
  2. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/CakeSeries.java
  3. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java

27
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java

@ -5,9 +5,11 @@ import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.RequestDTO;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.*;
import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.crop.CropDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO;
import cn.iocoder.yudao.module.farm.dal.mysql.area.AreaMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.crop.CropMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.task.TaskMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.workHour.WorkHourMapper;
@ -45,6 +47,8 @@ public class StatisticalController {
private CpUserMapper cpUserMapper;
@Resource
private CropMapper cropMapper;
@Resource
private AreaMapper areaMapper;
@PostMapping("/statisticalInformation")
@ApiOperation("农场数据统计接口")
@ -89,7 +93,7 @@ public class StatisticalController {
//任务数据
List<TaskDO> taskList = taskMapper.selectList();
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();
vo.setTaskPlanCount(planeCount.intValue());
@ -102,25 +106,34 @@ public class StatisticalController {
//种植数量 饼状图
//根据工时获取所有的活动
List<Long> workTaskIdList = workList.stream().map(WorkHourDO::getTaskId).collect(Collectors.toList());
List<TaskDO> finishTaskList = taskList.stream().filter(item -> workTaskIdList.contains(item.getId())).collect(Collectors.toList());
List<Long> cropIdList = finishTaskList.stream().filter(item -> item.getStatus().equals(TaskStatus.COMPLETE)).map(TaskDO::getCropId).collect(Collectors.toList());
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());
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);
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() + (taskDO.getCropNum() == null ? 0 : taskDO.getCropNum()));
cakeSeries.setValue(cakeSeries.getValue() + areaSum);
}else{
CakeSeries cakeSeries = CakeSeries.builder()
.name(cropDO.getName())
.value(taskDO.getCropNum() == null ? 0 : taskDO.getCropNum())
.value(areaSum)
.labelText("不知道说啥")
.build();
cropMap.put(cropDO.getId(), cakeSeries);
@ -137,7 +150,7 @@ public class StatisticalController {
}
vo.setCakeTitle("总数量");
vo.setCakeSubtitle(vo.getCakeSeries().stream().mapToInt(CakeSeries::getValue).sum() + "颗");
vo.setCakeSubtitle(vo.getCakeSeries().stream().mapToDouble(CakeSeries::getValue).sum()+"平方");
return CommonResult.success(vo);
}

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/CakeSeries.java

@ -12,7 +12,7 @@ import lombok.NoArgsConstructor;
public class CakeSeries {
private String name;
private Integer value;
private Double value;
private String labelText;
}

3
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java

@ -164,9 +164,6 @@ public class ProjectServiceImpl implements ProjectService {
pageParam.setPageNo(pageDTO.getPageNum());
pageParam.setPageSize(pageDTO.getPageSize());
List<ProjectDO> list = projectMapper.selectPage(pageParam, queryWrapperX).getList();
// List<ProjectDO> list = projectMapper.selectPage(new Page<>(pageDTO.getPageNum(), pageDTO.getPageSize()), queryWrapperX).getRecords();
if (ObjectUtil.isEmpty(list)){
return R.success(PageUtil.emptyPage(pageDTO, ProjectListDTO.class));
}

Loading…
Cancel
Save