Browse Source

统计接口, prod-erp

zyh
小久哥 3 years ago
parent
commit
b4fc7db6d0
  1. 12
      yudao-server/src/main/resources/application-prod.yaml
  2. 30
      zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/FarmTimeEnum.java
  3. 61
      zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/util/FarmTimeUtil.java
  4. 18
      zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/util/TimeLimitDTO.java
  5. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/dto/DiscussDTO.java
  6. 171
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java
  7. 17
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/dto/RequestDTO.java
  8. 31
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/dto/WorkStaticDTO.java
  9. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/CakeSeries.java
  10. 12
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/ChartData.java
  11. 13
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/Series.java
  12. 28
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/StatisticalVo.java
  13. 21
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/WorkMsg.java
  14. 11
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/WorkHourController.java
  15. 23
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/dto/UserWorkHourDTO.java
  16. 31
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/dto/WorkTotalDTO.java
  17. 9
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java
  18. 35
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java
  19. 6
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourService.java
  20. 84
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourServiceImpl.java

12
yudao-server/src/main/resources/application-prod.yaml

@ -63,12 +63,12 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
username: vue_pro username: vue_pro
password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#-
# farm: # 农场数据源 erp: # 农场数据源
# name: zsw-farm name: vue_pro_erp
# url: jdbc:p6spy:mysql://192.168.10.129:3306/${spring.datasource.dynamic.datasource.farm.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true url: jdbc:mysql://rm-2zey92ofhilzm3p4j0o.mysql.rds.aliyuncs.com:3306/${spring.datasource.dynamic.datasource.erp.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true
# driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
# username: root username: vue_pro
# password: root password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#-
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
redis: redis:

30
zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/FarmTimeEnum.java

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.farm.enums;
import lombok.Getter;
@Getter
public enum FarmTimeEnum {
ALL(0,"全部时间"),
TODAY(1,"今天"),
THREE_DAY(2,"三天内"),
CURRENT_WEEK(3,"本周,周一到今天"),
ONE_WEEK(4,"一周内,往前推7天"),
TWO_WEEK(5,"两周内,往前推14天"),
ONE_MONTH(6,"一个月,往前30天"),
THREE_MONTH(7,"三个月,往前90天");
private final Integer code;
private final String desc;
FarmTimeEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
}

61
zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/util/FarmTimeUtil.java

@ -0,0 +1,61 @@
package cn.iocoder.yudao.module.farm.util;
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.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.farm.enums.FarmTimeEnum;
import lombok.experimental.UtilityClass;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Date;
/**
* @Created by jiu on 2022/6/10.
*/
@UtilityClass
public class FarmTimeUtil {
/**
* 传递查询时间 返回查询开始和结束时间
**/
public TimeLimitDTO getStartTimeAndEndTime(FarmTimeEnum timeEnum){
LocalDateTime currentTime = LocalDateTime.now();
LocalDateTime startTime = LocalDateTime.now();
if (ObjectUtil.isEmpty(timeEnum)){
return TimeLimitDTO.builder().startTime(null).endTime(null).build();
}else if (timeEnum.equals(FarmTimeEnum.TODAY)){
//当天
startTime = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
}else if (timeEnum.equals(FarmTimeEnum.THREE_DAY)){
//三天内
startTime = currentTime.minusDays(3);
}else if (timeEnum.equals(FarmTimeEnum.CURRENT_WEEK)){
//本周,周一到今天
DateTime time = DateUtil.beginOfWeek(new Date());
String timeStr = DateUtil.format(time, DatePattern.NORM_DATETIME_PATTERN);
startTime = LocalDateTimeUtil.parse(timeStr, DatePattern.NORM_DATETIME_PATTERN);
}else if (timeEnum.equals(FarmTimeEnum.ONE_WEEK)){
//一周内,往前推7天
startTime = currentTime.minusWeeks(1);
}else if (timeEnum.equals(FarmTimeEnum.TWO_WEEK)){
//两周内,往前推14天
startTime = currentTime.minusDays(14);
}else if (timeEnum.equals(FarmTimeEnum.ONE_MONTH)){
//前一个月
startTime = currentTime.minusDays(30);
}else if (timeEnum.equals(FarmTimeEnum.THREE_MONTH)){
//前三个月
startTime = currentTime.minusDays(90);
}else{
// 传null 默认查全部时间
return null;
}
return TimeLimitDTO.builder().startTime(startTime).endTime(currentTime).build();
}
}

18
zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/util/TimeLimitDTO.java

@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.farm.util;
import lombok.Builder;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @Created by jiu on 2022/6/10.
*/
@Data
@Builder
public class TimeLimitDTO {
private LocalDateTime startTime;
private LocalDateTime endTime;
}

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/dto/DiscussDTO.java

@ -23,7 +23,7 @@ public class DiscussDTO extends DiscussDO {
String publishIcon; String publishIcon;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="Asia/Shanghai")
Date publishTime; Date publishTime;

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

@ -1,29 +1,37 @@
package cn.iocoder.yudao.module.farm.controller.admin.statistical; 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.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.RequestDTO;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.*;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.CakeSeries; import cn.iocoder.yudao.module.farm.dal.dataobject.crop.CropDO;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.ChartData; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.Series; import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.StatisticalVo; import cn.iocoder.yudao.module.farm.dal.mysql.crop.CropMapper;
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.dal.mysql.task.TaskMapper; 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.dal.mysql.workHour.WorkHourMapper;
import cn.iocoder.yudao.module.farm.service.task.TaskService; 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.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; 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 @Slf4j
@RestController @RestController
@ -32,44 +40,113 @@ import java.util.ArrayList;
@Validated @Validated
public class StatisticalController { public class StatisticalController {
@Resource
private ProjectMapper projectMapper;
@Resource @Resource
private TaskMapper taskMapper; private TaskMapper taskMapper;
@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);
}
@GetMapping("/index") TimeLimitDTO time = FarmTimeUtil.getStartTimeAndEndTime(searchDTO.getTimeEnum());
@ApiOperation("统计首页接口")
public CommonResult<StatisticalVo> index(){
LoginUser user = SecurityFrameworkUtils.getLoginUser();
StatisticalVo vo = new StatisticalVo(); StatisticalVo vo = new StatisticalVo();
vo.setProjectTotalCount(111); //获取时间内的所有工时记录
vo.setProjectPlanCount(23); List<WorkHourDO> workList = workHourMapper.selectList(Wrappers.<WorkHourDO>lambdaQuery().ge(WorkHourDO::getCreateTime, beforeTime).le(WorkHourDO::getCreateTime, currentTime));
vo.setProjectStartingCount(12); //工时的userId
vo.setProjectCompleteCount(69); List<Long> workUserIdList = workList.stream().map(WorkHourDO::getUserId).collect(Collectors.toList());
//获取工时所有人信息
ChartData chartData = new ChartData(); List<CpUserDO> userList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, workUserIdList));
chartData.setCategories(Lists.newArrayList("a","b","c"));
Map<Long, List<WorkHourDO>> workMap = workList.stream().collect(Collectors.groupingBy(WorkHourDO::getUserId));
Series series = new Series(); Iterator<Map.Entry<Long, List<WorkHourDO>>> iterator = workMap.entrySet().iterator();
series.setName("销量");
series.setData(Lists.newArrayList(1L,2L,3L,4L,5L)); //工时统计 条形图
chartData.setSeries(Lists.newArrayList(series)); List<WorkMsg> workMsgList = new ArrayList<>();
while (iterator.hasNext()){
vo.setStripData(chartData); Entry<Long, List<WorkHourDO>> entry = iterator.next();
Long userId = entry.getKey();
vo.setCakeTitle("总面积"); Optional<CpUserDO> userDO = userList.stream().filter(user -> user.getId().equals(userId)).findFirst();
vo.setCakeSubtitle("333m²"); if (userDO.isPresent()){
List<WorkHourDO> oneUserWorkList = entry.getValue();
CakeSeries cakeSeries1 = CakeSeries.builder().name("A").value(10.00).labelText("A类").build(); Integer oneTotalHour = oneUserWorkList.stream().mapToInt(WorkHourDO::getHour).sum();
CakeSeries cakeSeries2 = CakeSeries.builder().name("B").value(20.00).labelText("B类").build(); WorkMsg workMsg = WorkMsg.builder().name(userDO.get().getName()).hour(oneTotalHour).build();
CakeSeries cakeSeries3 = CakeSeries.builder().name("C").value(30.00).labelText("C类").build(); workMsgList.add(workMsg);
CakeSeries cakeSeries4 = CakeSeries.builder().name("D").value(40.00).labelText("D类").build(); }
}
ArrayList<CakeSeries> cakeSeriesList = Lists.newArrayList(cakeSeries1, cakeSeries2, cakeSeries3, cakeSeries4); 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.setCakeSeries(cakeSeriesList); vo.setCakeTitle("总数量");
vo.setCakeSubtitle(vo.getCakeSeries().stream().mapToInt(CakeSeries::getValue).sum() + "颗");
return CommonResult.success(vo); return CommonResult.success(vo);
} }

17
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/dto/RequestDTO.java

@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.farm.controller.admin.statistical.dto;
import cn.iocoder.yudao.module.farm.enums.FarmTimeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class RequestDTO {
private static final long serialVersionUID = 1L;
@ApiModelProperty("统计查询时间 1本周 2一个月 3三个月")
private Integer timeSearch;
@ApiModelProperty("便捷时间查询 3本周 6一个月 7三个月")
private FarmTimeEnum timeEnum;
}

31
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/dto/WorkStaticDTO.java

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.farm.controller.admin.statistical.dto;
import cn.iocoder.yudao.module.farm.enums.FarmTimeEnum;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class WorkStaticDTO {
private static final long serialVersionUID = 1L;
@ApiModelProperty("便捷时间查询 4近一周 6三个月")
private FarmTimeEnum timeEnum;
@ApiModelProperty("指定查询开始时间 例'2022-06-01 00:00'")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="Asia/Shanghai")
private Date startDate;
@ApiModelProperty("指定查询结束时间 例'2022-06-10 18:18'")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="Asia/Shanghai")
private Date endDate;
@ApiModelProperty("指定查询用户id")
private List<Long> userIdList;
}

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 { public class CakeSeries {
private String name; private String name;
private Double value; private Integer value;
private String labelText; private String labelText;
} }

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

@ -1,12 +0,0 @@
package cn.iocoder.yudao.module.farm.controller.admin.statistical.vo;
import lombok.Data;
import java.util.List;
@Data
public class ChartData {
private List<String> categories;
private List<Series> series;
}

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

@ -1,13 +0,0 @@
package cn.iocoder.yudao.module.farm.controller.admin.statistical.vo;
import lombok.Data;
import java.util.List;
@Data
public class Series {
private String name;
private List<Long> data;
}

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

@ -8,28 +8,28 @@ import java.util.List;
@Data @Data
public class StatisticalVo { public class StatisticalVo {
@ApiModelProperty("项目总数") @ApiModelProperty("工时统计")
private Integer projectTotalCount; private List<WorkMsg> workMsgList;
@ApiModelProperty("项目计划数量") @ApiModelProperty("任务总数")
private Integer projectPlanCount; private Integer taskTotalCount;
@ApiModelProperty("项目启动数") @ApiModelProperty("任务计划数量")
private Integer projectStartingCount; private Integer taskPlanCount;
@ApiModelProperty("项目完成数") @ApiModelProperty("任务进行中数量")
private Integer projectCompleteCount; private Integer taskStartingCount;
@ApiModelProperty("条状数据图") @ApiModelProperty("任务完成数")
private ChartData stripData; private Integer taskCompleteCount;
@ApiModelProperty("饼图数据")
private List<CakeSeries> cakeSeries;
@ApiModelProperty("饼图中间标题") @ApiModelProperty("饼图中间标题")
private String cakeTitle; private String cakeTitle;
@ApiModelProperty("饼图") @ApiModelProperty("饼图中间子标题")
private String cakeSubtitle; private String cakeSubtitle;
@ApiModelProperty("饼图数据")
private List<CakeSeries> cakeSeries;
} }

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

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.farm.controller.admin.statistical.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WorkMsg {
@ApiModelProperty("姓名")
private String name;
@ApiModelProperty("工时")
private Integer hour;
}

11
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/WorkHourController.java

@ -1,12 +1,13 @@
package cn.iocoder.yudao.module.farm.controller.admin.workHour; package cn.iocoder.yudao.module.farm.controller.admin.workHour;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.WorkStaticDTO;
import cn.iocoder.yudao.module.farm.controller.admin.workHour.dto.WorkTotalDTO;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import javax.validation.constraints.*;
import javax.validation.*; import javax.validation.*;
import javax.servlet.http.*; import javax.servlet.http.*;
import java.util.*; import java.util.*;
@ -97,4 +98,12 @@ public class WorkHourController {
ExcelUtils.write(response, ".xls", "数据", WorkHourExcelVO.class, datas); ExcelUtils.write(response, ".xls", "数据", WorkHourExcelVO.class, datas);
} }
@PostMapping("/statistical")
@ApiOperation("农场工时统计")
public CommonResult<List<WorkTotalDTO>> statistical(@RequestBody WorkStaticDTO staticDTO){
return workHourService.statistical(staticDTO);
}
} }

23
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/dto/UserWorkHourDTO.java

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.farm.controller.admin.workHour.dto;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.WorkMsg;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @Created by jiu on 2022/6/10.
*/
@Data
public class UserWorkHourDTO extends WorkMsg {
@ApiModelProperty("项目名")
private String projectName;
@ApiModelProperty("工时记录时间")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="Asia/Shanghai")
private Date workTime;
}

31
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/dto/WorkTotalDTO.java

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.farm.controller.admin.workHour.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
* @Created by jiu on 2022/6/10.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WorkTotalDTO {
@ApiModelProperty("日期")
@JsonFormat(pattern="yyyy-MM-dd",timezone="Asia/Shanghai")
private Date date;
@ApiModelProperty("当日工时合计")
private Integer totalHour;
@ApiModelProperty("当日员工工时")
List<UserWorkHourDTO> userWorkList;
}

9
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.farm.service.area; package cn.iocoder.yudao.module.farm.service.area;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -89,8 +91,10 @@ public class AreaServiceImpl implements AreaService {
public List<String> findAreaName(List<AreaDO> areaList, JSONArray areaArray){ public List<String> findAreaName(List<AreaDO> areaList, JSONArray areaArray){
List<String> areaNameList = new ArrayList<>(); List<String> areaNameList = new ArrayList<>();
JSONArray array = JSONArray.parseArray(areaArray.toString()); JSONArray array = JSONArray.parseArray(areaArray.toString());
Long areaParent = Long.valueOf(String.valueOf(array.get(0))); for (Object selectArea : array) {
Long areaSon = Long.valueOf(String.valueOf(array.get(1))); JSONArray array123 = JSONArray.parseArray(JSON.toJSONString( selectArea));
Long areaParent = Long.valueOf(String.valueOf(array123.get(0)));
Long areaSon = Long.valueOf(String.valueOf(array123.get(1)));
StringBuilder areaName = new StringBuilder(); StringBuilder areaName = new StringBuilder();
for (AreaDO areaDO : areaList) { for (AreaDO areaDO : areaList) {
if (areaDO.getId().equals(areaParent)){ if (areaDO.getId().equals(areaParent)){
@ -103,6 +107,7 @@ public class AreaServiceImpl implements AreaService {
if (ObjectUtil.isNotEmpty(areaName)){ if (ObjectUtil.isNotEmpty(areaName)){
areaNameList.add(areaName.toString()); areaNameList.add(areaName.toString());
} }
}
return areaNameList; return areaNameList;
} }

35
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.farm.service.discuss;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.system.oshi.CpuInfo;
import cn.iocoder.yudao.framework.common.page.PageUtil; import cn.iocoder.yudao.framework.common.page.PageUtil;
import cn.iocoder.yudao.framework.common.page.PageVO; import cn.iocoder.yudao.framework.common.page.PageVO;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -19,6 +20,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper;
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
import cn.iocoder.yudao.module.system.service.CpUser.CpUserService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zsw.base.R; import com.zsw.base.R;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -52,6 +54,8 @@ public class DiscussServiceImpl implements DiscussService {
@Resource @Resource
private CpUserMapper cpUserMapper; private CpUserMapper cpUserMapper;
@Resource @Resource
private CpUserService cpUserService;
@Resource
private AdminUserMapper adminUserMapper; private AdminUserMapper adminUserMapper;
@Resource @Resource
private WorkHourMapper workHourMapper; private WorkHourMapper workHourMapper;
@ -65,6 +69,35 @@ public class DiscussServiceImpl implements DiscussService {
// 插入 // 插入
DiscussDO discuss = DiscussConvert.INSTANCE.convert(createReqVO); DiscussDO discuss = DiscussConvert.INSTANCE.convert(createReqVO);
discussMapper.insert(discuss); discussMapper.insert(discuss);
if (ObjectUtil.isNotEmpty(createReqVO.getWorkHourList())){
List<Long> workUserIdList = createReqVO.getWorkHourList().stream().map(WorkHourBaseVO::getUserId).collect(Collectors.toList());
List<CpUserDO> userList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, workUserIdList));
//传了工时
List<WorkHourDO> workSaveList = new ArrayList<>();
for (WorkHourBaseVO work : createReqVO.getWorkHourList()) {
WorkHourDO workHourDO = WorkHourDO.builder()
.userId(work.getUserId())
.discussId(discuss.getId())
.projectId(work.getProjectId())
.taskId(work.getTaskId())
.hour(work.getHour())
.build();
workSaveList.add(workHourDO);
userList.forEach(user ->{
if (work.getUserId().equals(user.getId())){
user.setWorkHour(user.getWorkHour() + work.getHour());
}
});
}
//插入工时记录
workHourMapper.insertBatch(workSaveList);
//更新员工工时合计
cpUserService.updateBatchById(userList);
}
// 返回 // 返回
return discuss.getId(); return discuss.getId();
} }
@ -133,7 +166,7 @@ public class DiscussServiceImpl implements DiscussService {
List<CpUserDO> cpUserList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery()); List<CpUserDO> cpUserList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery());
//工时List //工时List
List<Long> workIdList = discussList.stream().map(DiscussDO::getId).collect(Collectors.toList()); List<Long> workIdList = discussList.stream().map(DiscussDO::getId).collect(Collectors.toList());
List<WorkHourDO> workHourList = workHourMapper.selectList(Wrappers.<WorkHourDO>lambdaQuery().in(WorkHourDO::getProjectId, workIdList)); List<WorkHourDO> workHourList = workHourMapper.selectList(Wrappers.<WorkHourDO>lambdaQuery().in(WorkHourDO::getDiscussId, workIdList));
//全部区域List //全部区域List
List<AreaDO> areaList = areaMapper.selectList(); List<AreaDO> areaList = areaMapper.selectList();

6
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourService.java

@ -2,6 +2,10 @@ package cn.iocoder.yudao.module.farm.service.workHour;
import java.util.*; import java.util.*;
import javax.validation.*; import javax.validation.*;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.WorkStaticDTO;
import cn.iocoder.yudao.module.farm.controller.admin.workHour.dto.WorkTotalDTO;
import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*; import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*;
import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -67,4 +71,6 @@ public interface WorkHourService {
*/ */
List<WorkHourDO> getWorkHourList(WorkHourExportReqVO exportReqVO); List<WorkHourDO> getWorkHourList(WorkHourExportReqVO exportReqVO);
CommonResult<List<WorkTotalDTO>> statistical(WorkStaticDTO staticDTO);
} }

84
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourServiceImpl.java

@ -1,10 +1,28 @@
package cn.iocoder.yudao.module.farm.service.workHour; package cn.iocoder.yudao.module.farm.service.workHour;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.WorkStaticDTO;
import cn.iocoder.yudao.module.farm.controller.admin.workHour.dto.UserWorkHourDTO;
import cn.iocoder.yudao.module.farm.controller.admin.workHour.dto.WorkTotalDTO;
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.enums.FarmTimeEnum;
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 org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*; import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*;
import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -26,6 +44,10 @@ public class WorkHourServiceImpl implements WorkHourService {
@Resource @Resource
private WorkHourMapper workHourMapper; private WorkHourMapper workHourMapper;
@Resource
private CpUserMapper cpUserMapper;
@Resource
private ProjectMapper projectMapper;
@Override @Override
public Long createWorkHour(WorkHourCreateReqVO createReqVO) { public Long createWorkHour(WorkHourCreateReqVO createReqVO) {
@ -79,4 +101,66 @@ public class WorkHourServiceImpl implements WorkHourService {
return workHourMapper.selectList(exportReqVO); return workHourMapper.selectList(exportReqVO);
} }
public CommonResult<List<WorkTotalDTO>> statistical(WorkStaticDTO staticDTO){
LambdaQueryWrapperX<WorkHourDO> queryWrapperX = new LambdaQueryWrapperX<>();
if (ObjectUtil.isNotEmpty(staticDTO.getStartDate()) || ObjectUtil.isNotEmpty(staticDTO.getEndDate())){
//指定时间查询
queryWrapperX.leIfPresent(WorkHourDO::getCreateTime, staticDTO.getEndDate());
queryWrapperX.geIfPresent(WorkHourDO::getCreateTime, staticDTO.getStartDate());
}else{
//便捷时间查询
if (!staticDTO.getTimeEnum().equals(FarmTimeEnum.ALL)){
TimeLimitDTO time = FarmTimeUtil.getStartTimeAndEndTime(staticDTO.getTimeEnum());
queryWrapperX.leIfPresent(WorkHourDO::getCreateTime, time.getEndTime());
queryWrapperX.geIfPresent(WorkHourDO::getCreateTime, time.getStartTime());
}
}
queryWrapperX.inIfPresent(WorkHourDO::getUserId, staticDTO.getUserIdList());
List<WorkHourDO> workHourList = workHourMapper.selectList(queryWrapperX);
List<Long> cpIdList = workHourList.stream().map(WorkHourDO::getUserId).collect(Collectors.toList());
List<CpUserDO> userList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, cpIdList));
List<Long> projectIdList = workHourList.stream().map(WorkHourDO::getProjectId).collect(Collectors.toList());
List<ProjectDO> projectList = projectMapper.selectList(Wrappers.<ProjectDO>lambdaQuery().in(ProjectDO::getId, projectIdList));
List<WorkTotalDTO> list = new ArrayList<>();
Map<String, List<WorkHourDO>> map = workHourList.stream().collect(Collectors.groupingBy(item -> DateUtil.formatDate(item.getCreateTime())));
Iterator<Map.Entry<String, List<WorkHourDO>>> iterator = map.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String, List<WorkHourDO>> entry = iterator.next();
WorkTotalDTO dto = new WorkTotalDTO();
//日期
dto.setDate(DateUtil.parseDate(entry.getKey()));
List<WorkHourDO> workList = entry.getValue();
Integer sumHour = workList.stream().mapToInt(WorkHourDO::getHour).sum();
//日期总工时
dto.setTotalHour(sumHour);
List<UserWorkHourDTO> userWorkList = new ArrayList<>();
for (WorkHourDO workHourDO : workList) {
UserWorkHourDTO userWork = new UserWorkHourDTO();
//工时
userWork.setHour(workHourDO.getHour());
//创建时间
userWork.setWorkTime(workHourDO.getCreateTime());
//名字
userList.stream().filter(userDO -> userDO.getId().equals(workHourDO.getUserId())).findAny()
.ifPresent(item ->{
userWork.setName(item.getName());
});
//项目名
projectList.stream().filter(projectDO -> projectDO.getId().equals(workHourDO.getProjectId())).findAny()
.ifPresent(item ->{
userWork.setProjectName(item.getName());
});
userWorkList.add(userWork);
}
//日期 所有工时记录
dto.setUserWorkList(userWorkList);
list.add(dto);
}
list = list.stream().sorted(Comparator.comparing(WorkTotalDTO::getDate).reversed()).collect(Collectors.toList());
return CommonResult.success(list);
}
} }

Loading…
Cancel
Save