From ad7cbfd8fd19fcce4345a4907c1f059a34c2869b Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期四, 11 十二月 2025 15:49:15 +0800
Subject: [PATCH] 工作台

---
 business/src/main/java/com/ycl/service/impl/WorkStationScheduleServiceImpl.java |  102 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 94 insertions(+), 8 deletions(-)

diff --git a/business/src/main/java/com/ycl/service/impl/WorkStationScheduleServiceImpl.java b/business/src/main/java/com/ycl/service/impl/WorkStationScheduleServiceImpl.java
index 7d20cd7..2939a71 100644
--- a/business/src/main/java/com/ycl/service/impl/WorkStationScheduleServiceImpl.java
+++ b/business/src/main/java/com/ycl/service/impl/WorkStationScheduleServiceImpl.java
@@ -3,8 +3,12 @@
 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;
@@ -13,6 +17,9 @@
 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;
@@ -22,8 +29,9 @@
 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;
 
 /**
@@ -39,6 +47,10 @@
     private final WorkStationScheduleMapper workStationScheduleMapper;
 
     private final FlowServiceFactory flowServiceFactory;
+
+    private final TaskCommonService taskCommonService;
+    private final IndexHomeServiceImpl indexHomeServiceImpl;
+
     /**
      * 娣诲姞
      * @param form
@@ -47,6 +59,9 @@
     @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("娣诲姞鎴愬姛");
     }
@@ -101,6 +116,39 @@
         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
@@ -123,6 +171,7 @@
         List<WorkStationScheduleVO> vos = entities.stream()
                 .map(entity -> WorkStationScheduleVO.getVoByEntity(entity, null))
                 .collect(Collectors.toList());
+
         return Result.ok().data(vos);
     }
 
@@ -142,9 +191,18 @@
         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;
@@ -163,7 +221,8 @@
         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);
@@ -183,10 +242,37 @@
         }
 
         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);
+    }
+
 }

--
Gitblit v1.8.0