|
|
|
@ -1,29 +1,37 @@
|
|
|
|
|
package cn.iocoder.yudao.module.farm.controller.admin.statistical; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DatePattern; |
|
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil; |
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|
|
|
|
import cn.iocoder.yudao.framework.security.core.LoginUser; |
|
|
|
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
|
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.CakeSeries; |
|
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.ChartData; |
|
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.Series; |
|
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.StatisticalVo; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.project.ProjectMapper; |
|
|
|
|
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.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.crop.CropMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.task.TaskMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.service.project.ProjectService; |
|
|
|
|
import cn.iocoder.yudao.module.farm.service.task.TaskService; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.workHour.WorkHourMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.enums.TaskStatus; |
|
|
|
|
import cn.iocoder.yudao.module.farm.util.FarmTimeUtil; |
|
|
|
|
import cn.iocoder.yudao.module.farm.util.TimeLimitDTO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.Map.Entry; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
|
@RestController |
|
|
|
@ -32,44 +40,113 @@ import java.util.ArrayList;
|
|
|
|
|
@Validated |
|
|
|
|
public class StatisticalController { |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private ProjectMapper projectMapper; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private TaskMapper taskMapper; |
|
|
|
|
|
|
|
|
|
@GetMapping("/index") |
|
|
|
|
@ApiOperation("统计首页接口") |
|
|
|
|
public CommonResult<StatisticalVo> index(){ |
|
|
|
|
LoginUser user = SecurityFrameworkUtils.getLoginUser(); |
|
|
|
|
@Resource |
|
|
|
|
private WorkHourMapper workHourMapper; |
|
|
|
|
@Resource |
|
|
|
|
private CpUserMapper cpUserMapper; |
|
|
|
|
@Resource |
|
|
|
|
private CropMapper cropMapper; |
|
|
|
|
|
|
|
|
|
@PostMapping("/statisticalInformation") |
|
|
|
|
@ApiOperation("农场数据统计接口") |
|
|
|
|
public CommonResult<StatisticalVo> statisticalInformation(@RequestBody RequestDTO searchDTO){ |
|
|
|
|
LocalDateTime currentTime = LocalDateTime.now(); |
|
|
|
|
LocalDateTime beforeTime ; |
|
|
|
|
if (searchDTO.getTimeSearch() == 1){ |
|
|
|
|
//本周
|
|
|
|
|
DateTime time = DateUtil.beginOfWeek(new Date()); |
|
|
|
|
String timeStr = DateUtil.format(time, DatePattern.NORM_DATETIME_PATTERN); |
|
|
|
|
beforeTime = LocalDateTimeUtil.parse(timeStr, DatePattern.NORM_DATETIME_PATTERN); |
|
|
|
|
}else if (searchDTO.getTimeSearch() == 2){ |
|
|
|
|
//前一个月
|
|
|
|
|
beforeTime = LocalDateTimeUtil.offset(currentTime, -30, ChronoUnit.DAYS); |
|
|
|
|
}else{ |
|
|
|
|
//前三个月
|
|
|
|
|
beforeTime = LocalDateTimeUtil.offset(currentTime, -90, ChronoUnit.DAYS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TimeLimitDTO time = FarmTimeUtil.getStartTimeAndEndTime(searchDTO.getTimeEnum()); |
|
|
|
|
|
|
|
|
|
StatisticalVo vo = new StatisticalVo(); |
|
|
|
|
vo.setProjectTotalCount(111); |
|
|
|
|
vo.setProjectPlanCount(23); |
|
|
|
|
vo.setProjectStartingCount(12); |
|
|
|
|
vo.setProjectCompleteCount(69); |
|
|
|
|
|
|
|
|
|
ChartData chartData = new ChartData(); |
|
|
|
|
chartData.setCategories(Lists.newArrayList("a","b","c")); |
|
|
|
|
|
|
|
|
|
Series series = new Series(); |
|
|
|
|
series.setName("销量"); |
|
|
|
|
series.setData(Lists.newArrayList(1L,2L,3L,4L,5L)); |
|
|
|
|
chartData.setSeries(Lists.newArrayList(series)); |
|
|
|
|
|
|
|
|
|
vo.setStripData(chartData); |
|
|
|
|
|
|
|
|
|
vo.setCakeTitle("总面积"); |
|
|
|
|
vo.setCakeSubtitle("333m²"); |
|
|
|
|
|
|
|
|
|
CakeSeries cakeSeries1 = CakeSeries.builder().name("A").value(10.00).labelText("A类").build(); |
|
|
|
|
CakeSeries cakeSeries2 = CakeSeries.builder().name("B").value(20.00).labelText("B类").build(); |
|
|
|
|
CakeSeries cakeSeries3 = CakeSeries.builder().name("C").value(30.00).labelText("C类").build(); |
|
|
|
|
CakeSeries cakeSeries4 = CakeSeries.builder().name("D").value(40.00).labelText("D类").build(); |
|
|
|
|
|
|
|
|
|
ArrayList<CakeSeries> cakeSeriesList = Lists.newArrayList(cakeSeries1, cakeSeries2, cakeSeries3, cakeSeries4); |
|
|
|
|
|
|
|
|
|
vo.setCakeSeries(cakeSeriesList); |
|
|
|
|
//获取时间内的所有工时记录
|
|
|
|
|
List<WorkHourDO> workList = workHourMapper.selectList(Wrappers.<WorkHourDO>lambdaQuery().ge(WorkHourDO::getCreateTime, beforeTime).le(WorkHourDO::getCreateTime, currentTime)); |
|
|
|
|
//工时的userId
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
//工时统计 条形图
|
|
|
|
|
List<WorkMsg> workMsgList = new ArrayList<>(); |
|
|
|
|
while (iterator.hasNext()){ |
|
|
|
|
Entry<Long, List<WorkHourDO>> entry = iterator.next(); |
|
|
|
|
Long userId = entry.getKey(); |
|
|
|
|
Optional<CpUserDO> userDO = userList.stream().filter(user -> user.getId().equals(userId)).findFirst(); |
|
|
|
|
if (userDO.isPresent()){ |
|
|
|
|
List<WorkHourDO> oneUserWorkList = entry.getValue(); |
|
|
|
|
Integer oneTotalHour = oneUserWorkList.stream().mapToInt(WorkHourDO::getHour).sum(); |
|
|
|
|
WorkMsg workMsg = WorkMsg.builder().name(userDO.get().getName()).hour(oneTotalHour).build(); |
|
|
|
|
workMsgList.add(workMsg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
workMsgList = workMsgList.stream().sorted(Comparator.comparing(WorkMsg::getHour).reversed()).collect(Collectors.toList()); |
|
|
|
|
vo.setWorkMsgList(workMsgList); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//任务数据
|
|
|
|
|
List<TaskDO> taskList = taskMapper.selectList(); |
|
|
|
|
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()); |
|
|
|
|
Long startCount = taskList.stream().filter(plane -> |
|
|
|
|
plane.getStatus().equals(TaskStatus.STARTED) || plane.getStatus().equals(TaskStatus.EXCEPTION) || plane.getStatus().equals(TaskStatus.RETRY)).count(); |
|
|
|
|
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()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//种植数量 饼状图
|
|
|
|
|
//根据工时获取所有的活动
|
|
|
|
|
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()); |
|
|
|
|
if (ObjectUtils.isEmpty(cropIdList)){ |
|
|
|
|
vo.setCakeSeries(new ArrayList<>()); |
|
|
|
|
}else { |
|
|
|
|
List<CropDO> cropList = cropMapper.selectList(Wrappers.<CropDO>lambdaQuery().in(CropDO::getId, cropIdList)); |
|
|
|
|
Map<Long, CakeSeries> cropMap = new HashMap<>(); |
|
|
|
|
for (TaskDO taskDO : finishTaskList) { |
|
|
|
|
for (CropDO cropDO : cropList) { |
|
|
|
|
if (taskDO.getCropId().equals(cropDO.getId())){ |
|
|
|
|
if (cropMap.containsKey(cropDO.getId())){ |
|
|
|
|
CakeSeries cakeSeries = cropMap.get(cropDO.getId()); |
|
|
|
|
cakeSeries.setValue(cakeSeries.getValue() + taskDO.getCropNum()); |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
CakeSeries cakeSeries = CakeSeries.builder() |
|
|
|
|
.name(cropDO.getName()) |
|
|
|
|
.value(taskDO.getCropNum()) |
|
|
|
|
.labelText("不知道说啥") |
|
|
|
|
.build(); |
|
|
|
|
cropMap.put(cropDO.getId(), cakeSeries); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
List<CakeSeries> cakeList = new ArrayList<>(); |
|
|
|
|
Iterator<Entry<Long, CakeSeries>> cropItertor = cropMap.entrySet().iterator(); |
|
|
|
|
while (cropItertor.hasNext()){ |
|
|
|
|
cakeList.add(cropItertor.next().getValue()); |
|
|
|
|
} |
|
|
|
|
vo.setCakeSeries(cakeList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
vo.setCakeTitle("总数量"); |
|
|
|
|
vo.setCakeSubtitle(vo.getCakeSeries().stream().mapToInt(CakeSeries::getValue).sum() + "颗"); |
|
|
|
|
|
|
|
|
|
return CommonResult.success(vo); |
|
|
|
|
} |
|
|
|
|