diff --git a/yudao-server/src/main/resources/application-prod.yaml b/yudao-server/src/main/resources/application-prod.yaml index bd1f5d24..e64d949c 100644 --- a/yudao-server/src/main/resources/application-prod.yaml +++ b/yudao-server/src/main/resources/application-prod.yaml @@ -63,12 +63,12 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver username: vue_pro password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- -# farm: # 农场数据源 -# name: zsw-farm -# 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 -# driver-class-name: com.mysql.jdbc.Driver -# username: root -# password: root + erp: # 农场数据源 + name: vue_pro_erp + 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.cj.jdbc.Driver + username: vue_pro + password: CrnPu&g8HqbBikrA&DH-llRgtvpIrG#- # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: diff --git a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/FarmTimeEnum.java b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/FarmTimeEnum.java new file mode 100644 index 00000000..77345801 --- /dev/null +++ b/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; + } + + +} diff --git a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/util/FarmTimeUtil.java b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/util/FarmTimeUtil.java new file mode 100644 index 00000000..29cbd325 --- /dev/null +++ b/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(); + + + } + +} diff --git a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/util/TimeLimitDTO.java b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/util/TimeLimitDTO.java new file mode 100644 index 00000000..b7ee32e0 --- /dev/null +++ b/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; +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/dto/DiscussDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/dto/DiscussDTO.java index 96d2b957..c9251a3d 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/dto/DiscussDTO.java +++ b/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; - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="Asia/Shanghai") Date publishTime; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java index 3917d53d..5ff869bd 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java +++ b/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; +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,45 +40,114 @@ import java.util.ArrayList; @Validated public class StatisticalController { - @Resource - private ProjectMapper projectMapper; - @Resource private TaskMapper taskMapper; - - @GetMapping("/index") - @ApiOperation("统计首页接口") - public CommonResult index(){ - LoginUser user = SecurityFrameworkUtils.getLoginUser(); + @Resource + private WorkHourMapper workHourMapper; + @Resource + private CpUserMapper cpUserMapper; + @Resource + private CropMapper cropMapper; + + @PostMapping("/statisticalInformation") + @ApiOperation("农场数据统计接口") + public CommonResult 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 cakeSeriesList = Lists.newArrayList(cakeSeries1, cakeSeries2, cakeSeries3, cakeSeries4); - - vo.setCakeSeries(cakeSeriesList); - + //获取时间内的所有工时记录 + List workList = workHourMapper.selectList(Wrappers.lambdaQuery().ge(WorkHourDO::getCreateTime, beforeTime).le(WorkHourDO::getCreateTime, currentTime)); + //工时的userId + List workUserIdList = workList.stream().map(WorkHourDO::getUserId).collect(Collectors.toList()); + //获取工时所有人信息 + List userList = cpUserMapper.selectList(Wrappers.lambdaQuery().in(CpUserDO::getId, workUserIdList)); + + Map> workMap = workList.stream().collect(Collectors.groupingBy(WorkHourDO::getUserId)); + Iterator>> iterator = workMap.entrySet().iterator(); + + //工时统计 条形图 + List workMsgList = new ArrayList<>(); + while (iterator.hasNext()){ + Entry> entry = iterator.next(); + Long userId = entry.getKey(); + Optional userDO = userList.stream().filter(user -> user.getId().equals(userId)).findFirst(); + if (userDO.isPresent()){ + List 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 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 workTaskIdList = workList.stream().map(WorkHourDO::getTaskId).collect(Collectors.toList()); + List finishTaskList = taskList.stream().filter(item -> workTaskIdList.contains(item.getId())).collect(Collectors.toList()); + List 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 cropList = cropMapper.selectList(Wrappers.lambdaQuery().in(CropDO::getId, cropIdList)); + Map 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 cakeList = new ArrayList<>(); + Iterator> 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); } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/dto/RequestDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/dto/RequestDTO.java new file mode 100644 index 00000000..d53c097d --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/dto/WorkStaticDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/dto/WorkStaticDTO.java new file mode 100644 index 00000000..023000c4 --- /dev/null +++ b/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 userIdList; +} \ No newline at end of file diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/CakeSeries.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/CakeSeries.java index f8b8d334..17f1756a 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/CakeSeries.java +++ b/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 Double value; + private Integer value; private String labelText; } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/ChartData.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/ChartData.java deleted file mode 100644 index 3ff30251..00000000 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/ChartData.java +++ /dev/null @@ -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 categories; - private List series; -} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/Series.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/Series.java deleted file mode 100644 index 97b1cde0..00000000 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/Series.java +++ /dev/null @@ -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 data; - -} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/StatisticalVo.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/StatisticalVo.java index bdd4d3b0..7f252c80 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/StatisticalVo.java +++ b/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 public class StatisticalVo { - @ApiModelProperty("项目总数") - private Integer projectTotalCount; + @ApiModelProperty("工时统计") + private List workMsgList; - @ApiModelProperty("项目计划数量") - private Integer projectPlanCount; + @ApiModelProperty("任务总数") + private Integer taskTotalCount; - @ApiModelProperty("项目启动数") - private Integer projectStartingCount; + @ApiModelProperty("任务计划数量") + private Integer taskPlanCount; - @ApiModelProperty("项目完成数") - private Integer projectCompleteCount; + @ApiModelProperty("任务进行中数量") + private Integer taskStartingCount; - @ApiModelProperty("条状数据图") - private ChartData stripData; + @ApiModelProperty("任务完成数") + private Integer taskCompleteCount; + + @ApiModelProperty("饼图数据") + private List cakeSeries; @ApiModelProperty("饼图中间标题") private String cakeTitle; - @ApiModelProperty("饼图值") + @ApiModelProperty("饼图中间子标题") private String cakeSubtitle; - @ApiModelProperty("饼图数据") - private List cakeSeries; - } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/WorkMsg.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/WorkMsg.java new file mode 100644 index 00000000..37748848 --- /dev/null +++ b/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; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/WorkHourController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/WorkHourController.java index f383cff4..cf541e20 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/WorkHourController.java +++ b/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; +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 javax.annotation.Resource; import org.springframework.validation.annotation.Validated; import org.springframework.security.access.prepost.PreAuthorize; import io.swagger.annotations.*; -import javax.validation.constraints.*; import javax.validation.*; import javax.servlet.http.*; import java.util.*; @@ -97,4 +98,12 @@ public class WorkHourController { ExcelUtils.write(response, ".xls", "数据", WorkHourExcelVO.class, datas); } + + + @PostMapping("/statistical") + @ApiOperation("农场工时统计") + public CommonResult> statistical(@RequestBody WorkStaticDTO staticDTO){ + return workHourService.statistical(staticDTO); + } + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/dto/UserWorkHourDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/dto/UserWorkHourDTO.java new file mode 100644 index 00000000..0d463976 --- /dev/null +++ b/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; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/dto/WorkTotalDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/workHour/dto/WorkTotalDTO.java new file mode 100644 index 00000000..a6de785f --- /dev/null +++ b/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 userWorkList; +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java index c5003763..a33017d0 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java +++ b/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; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.google.gson.JsonArray; import org.springframework.stereotype.Service; @@ -89,20 +91,23 @@ public class AreaServiceImpl implements AreaService { public List findAreaName(List areaList, JSONArray areaArray){ List areaNameList = new ArrayList<>(); JSONArray array = JSONArray.parseArray(areaArray.toString()); - Long areaParent = Long.valueOf(String.valueOf(array.get(0))); - Long areaSon = Long.valueOf(String.valueOf(array.get(1))); - StringBuilder areaName = new StringBuilder(); - for (AreaDO areaDO : areaList) { - if (areaDO.getId().equals(areaParent)){ - areaName.append(areaDO.getName()); + for (Object selectArea : array) { + 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(); + for (AreaDO areaDO : areaList) { + if (areaDO.getId().equals(areaParent)){ + areaName.append(areaDO.getName()); + } + if (areaDO.getId().equals(areaSon)){ + areaName.append(areaDO.getName()); + } } - if (areaDO.getId().equals(areaSon)){ - areaName.append(areaDO.getName()); + if (ObjectUtil.isNotEmpty(areaName)){ + areaNameList.add(areaName.toString()); } } - if (ObjectUtil.isNotEmpty(areaName)){ - areaNameList.add(areaName.toString()); - } return areaNameList; } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java index eb354be4..382aa781 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java +++ b/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.util.ObjectUtil; +import cn.hutool.system.oshi.CpuInfo; import cn.iocoder.yudao.framework.common.page.PageUtil; import cn.iocoder.yudao.framework.common.page.PageVO; 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.mysql.CpUser.CpUserMapper; 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.zsw.base.R; import org.springframework.stereotype.Service; @@ -52,6 +54,8 @@ public class DiscussServiceImpl implements DiscussService { @Resource private CpUserMapper cpUserMapper; @Resource + private CpUserService cpUserService; + @Resource private AdminUserMapper adminUserMapper; @Resource private WorkHourMapper workHourMapper; @@ -65,6 +69,35 @@ public class DiscussServiceImpl implements DiscussService { // 插入 DiscussDO discuss = DiscussConvert.INSTANCE.convert(createReqVO); discussMapper.insert(discuss); + + if (ObjectUtil.isNotEmpty(createReqVO.getWorkHourList())){ + List workUserIdList = createReqVO.getWorkHourList().stream().map(WorkHourBaseVO::getUserId).collect(Collectors.toList()); + List userList = cpUserMapper.selectList(Wrappers.lambdaQuery().in(CpUserDO::getId, workUserIdList)); + + //传了工时 + List 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(); } @@ -133,7 +166,7 @@ public class DiscussServiceImpl implements DiscussService { List cpUserList = cpUserMapper.selectList(Wrappers.lambdaQuery()); //工时List List workIdList = discussList.stream().map(DiscussDO::getId).collect(Collectors.toList()); - List workHourList = workHourMapper.selectList(Wrappers.lambdaQuery().in(WorkHourDO::getProjectId, workIdList)); + List workHourList = workHourMapper.selectList(Wrappers.lambdaQuery().in(WorkHourDO::getDiscussId, workIdList)); //全部区域List List areaList = areaMapper.selectList(); diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourService.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourService.java index e6a6b14a..a041cd75 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourService.java +++ b/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 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.dal.dataobject.workHour.WorkHourDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -67,4 +71,6 @@ public interface WorkHourService { */ List getWorkHourList(WorkHourExportReqVO exportReqVO); + CommonResult> statistical(WorkStaticDTO staticDTO); + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourServiceImpl.java index 4eea0e12..964cca36 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/workHour/WorkHourServiceImpl.java +++ b/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; +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 javax.annotation.Resource; import org.springframework.validation.annotation.Validated; +import java.time.LocalDateTime; import java.util.*; +import java.util.stream.Collectors; + import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*; import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -26,6 +44,10 @@ public class WorkHourServiceImpl implements WorkHourService { @Resource private WorkHourMapper workHourMapper; + @Resource + private CpUserMapper cpUserMapper; + @Resource + private ProjectMapper projectMapper; @Override public Long createWorkHour(WorkHourCreateReqVO createReqVO) { @@ -79,4 +101,66 @@ public class WorkHourServiceImpl implements WorkHourService { return workHourMapper.selectList(exportReqVO); } + public CommonResult> statistical(WorkStaticDTO staticDTO){ + LambdaQueryWrapperX 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 workHourList = workHourMapper.selectList(queryWrapperX); + + List cpIdList = workHourList.stream().map(WorkHourDO::getUserId).collect(Collectors.toList()); + List userList = cpUserMapper.selectList(Wrappers.lambdaQuery().in(CpUserDO::getId, cpIdList)); + List projectIdList = workHourList.stream().map(WorkHourDO::getProjectId).collect(Collectors.toList()); + List projectList = projectMapper.selectList(Wrappers.lambdaQuery().in(ProjectDO::getId, projectIdList)); + + List list = new ArrayList<>(); + Map> map = workHourList.stream().collect(Collectors.groupingBy(item -> DateUtil.formatDate(item.getCreateTime()))); + Iterator>> iterator = map.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry> entry = iterator.next(); + WorkTotalDTO dto = new WorkTotalDTO(); + //日期 + dto.setDate(DateUtil.parseDate(entry.getKey())); + List workList = entry.getValue(); + Integer sumHour = workList.stream().mapToInt(WorkHourDO::getHour).sum(); + //日期总工时 + dto.setTotalHour(sumHour); + + List 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); + } + }