| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.ycl.common.enums.business.WorkStationEnum; |
| | | import com.ycl.common.utils.DateUtils; |
| | | import com.ycl.common.utils.SecurityUtils; |
| | | import com.ycl.common.utils.StringUtils; |
| | | import com.ycl.domain.entity.ProjectInfo; |
| | | import com.ycl.domain.entity.WorkStationSchedule; |
| | | import com.ycl.domain.vo.DailyStatVO; |
| | | import com.ycl.factory.FlowServiceFactory; |
| | | import com.ycl.mapper.WorkStationScheduleMapper; |
| | | import com.ycl.service.WorkStationScheduleService; |
| | |
| | | import com.ycl.domain.form.WorkStationScheduleForm; |
| | | import com.ycl.domain.vo.WorkStationScheduleVO; |
| | | import com.ycl.domain.query.WorkStationScheduleQuery; |
| | | import com.ycl.service.common.TaskCommonService; |
| | | import org.flowable.task.api.Task; |
| | | import org.flowable.task.api.TaskQuery; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.flowable.task.api.history.HistoricTaskInstanceQuery; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private final WorkStationScheduleMapper workStationScheduleMapper; |
| | | |
| | | private final FlowServiceFactory flowServiceFactory; |
| | | |
| | | private final TaskCommonService taskCommonService; |
| | | private final IndexHomeServiceImpl indexHomeServiceImpl; |
| | | |
| | | /** |
| | | * 添加 |
| | | * @param form |
| | |
| | | @Override |
| | | public Result add(WorkStationScheduleForm form) { |
| | | WorkStationSchedule entity = WorkStationScheduleForm.getEntityByForm(form, null); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | entity.setUserId(userId); |
| | | entity.setStatus(WorkStationEnum.Incomplete.name()); |
| | | baseMapper.insert(entity); |
| | | return Result.ok("添加成功"); |
| | | } |
| | |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | @Override |
| | | public Result listByDate(WorkStationScheduleQuery query) { |
| | | |
| | | Integer projectId = null; |
| | | if (!"all".equals(query.getProjectId())){ |
| | | projectId = Integer.valueOf(query.getProjectId()); |
| | | } |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //查询出指定时间段内的数据 |
| | | List<WorkStationScheduleVO> list = baseMapper.groupByProjectAndDate(userId,projectId, DateUtils.getMonthStartTime(query.getCompletedTime()), DateUtils.getMonthEndTime(query.getCompletedTime())); |
| | | |
| | | List<DailyStatVO> dailyStatVOList = new ArrayList<>(); |
| | | for (WorkStationScheduleVO vo : list) { |
| | | if (vo == null) { |
| | | continue; |
| | | } |
| | | DailyStatVO statVO = new DailyStatVO(); |
| | | statVO.setId(vo.getId() == null ? -1 : vo.getId()); |
| | | statVO.setTitle(StringUtils.isBlank(vo.getContent()) ? "无内容" : vo.getContent()); |
| | | Map<String, String> stringTimeMap = DateUtils.splitDateToDateAndTime(vo.getCompletedTime()); |
| | | String date = StringUtils.defaultIfBlank(stringTimeMap.get("date"), ""); |
| | | String time = StringUtils.defaultIfBlank(stringTimeMap.get("time"), ""); |
| | | statVO.setDate(date); |
| | | statVO.setTime(time); |
| | | statVO.setProject(StringUtils.isBlank(vo.getProjectName()) ? "未关联项目" : vo.getProjectName()); |
| | | statVO.setProjectId(vo.getProjectId()); |
| | | statVO.setCompletedTime(vo.getCompletedTime()); |
| | | dailyStatVOList.add(statVO); |
| | | } |
| | | |
| | | return Result.ok().data(dailyStatVOList); |
| | | } |
| | | |
| | | /** |
| | | * 根据id查找 |
| | | * @param id |
| | |
| | | List<WorkStationScheduleVO> vos = entities.stream() |
| | | .map(entity -> WorkStationScheduleVO.getVoByEntity(entity, null)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return Result.ok().data(vos); |
| | | } |
| | | |
| | |
| | | HistoricTaskInstanceQuery query = flowServiceFactory.getHistoryService() |
| | | .createHistoricTaskInstanceQuery() |
| | | .finished() |
| | | .taskAssignee(userId.toString()) |
| | | .taskAssignee(SecurityUtils.getUserId() + "") |
| | | .orderByHistoricTaskInstanceEndTime() |
| | | .desc(); |
| | | if (!SecurityUtils.getLoginUser().getUser().isAdmin()) { |
| | | query |
| | | .or() |
| | | .taskCandidateGroupIn(taskCommonService.getCurrentUserGroups()) |
| | | .taskCandidateUser(SecurityUtils.getUserId() + "") |
| | | .taskAssignee(SecurityUtils.getUserId() + "") |
| | | .endOr(); |
| | | } |
| | | |
| | | List<HistoricTaskInstance> taskList = query.list(); |
| | | long totalDuration = 0L; |
| | | int taskCount = 0; |
| | |
| | | double avgDurationMs = (double) totalDuration / taskCount; // 平均耗时(毫秒) |
| | | double avgDurationSec = avgDurationMs / 1000; // 转换为秒 |
| | | double avgDurationMin = avgDurationSec / 60; // 转换为分钟 |
| | | double avgDurationHour = avgDurationMin / 60; // 转换为分钟 |
| | | BigDecimal avgDurationHour = new BigDecimal(avgDurationMin / 60).setScale(2, RoundingMode.HALF_UP); // 转换为分钟 |
| | | |
| | | System.out.println("用户完成任务总数:" + taskCount); |
| | | System.out.println("平均耗时(秒):" + avgDurationSec); |
| | | System.out.println("平均耗时(分钟):" + avgDurationMin); |
| | |
| | | } |
| | | |
| | | HashMap<String,Object> map = new HashMap<>(); |
| | | map.put("totalDuration",totalDuration); |
| | | map.put("avgDurationHour",avgDurationHour); |
| | | map.put("scheduleCount",list.size()); |
| | | map.put("completedCount",count); |
| | | map.put("totalSchedules",list.size()); |
| | | map.put("completedSchedules",count); |
| | | map.put("avgDuration",avgDurationHour.doubleValue()); |
| | | map.put("completedTasks",taskCount); |
| | | return Result.ok().data(map); |
| | | } |
| | | |
| | | @Override |
| | | public Result countTodayTask() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | Date now = new Date(); |
| | | Date dayStart = DateUtils.getDayStart(now); |
| | | Date dayEnd = DateUtils.getDayEnd(now); |
| | | List<WorkStationSchedule> list = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(WorkStationSchedule::getUserId, SecurityUtils.getUserId()) |
| | | .eq(WorkStationSchedule::getDeleted, Boolean.FALSE) |
| | | .between(WorkStationSchedule::getCompletedTime, dayStart, dayEnd) |
| | | .list(); |
| | | HashMap<String,Object> map = new HashMap<>(); |
| | | map.put("todaySchedules",list.size()); |
| | | //查询今日处理的 的任务 |
| | | long claimedAndCompletedCount = flowServiceFactory.getHistoryService().createHistoricTaskInstanceQuery() |
| | | .finished() |
| | | .taskAssignee(userId+"") // 任务由当前用户认领(处理人是该用户) |
| | | .taskCompletedAfter(dayStart) |
| | | .taskCompletedBefore(dayEnd) |
| | | .count(); |
| | | map.put("totalActiveTasks",claimedAndCompletedCount); |
| | | int distinctTotal = indexHomeServiceImpl.countWaitTask(); |
| | | map.put("todayTasks",distinctTotal); |
| | | return Result.ok().data(map); |
| | | } |
| | | |
| | | } |