소스 검색

【feat】【v3】
1.完善代码逻辑

ChenYL 10 달 전
부모
커밋
8ba4eb6133

+ 49 - 0
src/main/java/com/punchsettle/server/pojo/punchIn/PiTaskHistoryVO.java

@@ -0,0 +1,49 @@
+package com.punchsettle.server.pojo.punchIn;
+
+import java.time.LocalTime;
+
+import com.punchsettle.server.constant.PunchInMethodEnum;
+import com.punchsettle.server.constant.PunchInResultEnum;
+
+import lombok.Data;
+
+/**
+ * @author tyuio
+ * @version 1.0.0
+ * @date 2025/5/9 9:27
+ * @description 打卡记录 VO
+ */
+@Data
+public class PiTaskHistoryVO {
+
+    /**
+     * 任务名称
+     */
+    private String taskName;
+
+    /**
+     * 打卡方式
+     */
+    private PunchInMethodEnum punchInMethod;
+
+    /**
+     * 打卡日期
+     */
+    private String punchInDate;
+
+    /**
+     * 次数记录
+     */
+    private Integer countTrack;
+
+    /**
+     * 时间记录
+     */
+    private LocalTime timeTrack;
+
+    /**
+     * 打卡结果(DONE-完成,UNDONE-未完成)
+     * @see PunchInResultEnum
+     */
+    private PunchInResultEnum punchInResult;
+}

+ 26 - 0
src/main/java/com/punchsettle/server/pojo/punchIn/PunchInHistoryVO.java

@@ -0,0 +1,26 @@
+package com.punchsettle.server.pojo.punchIn;
+
+import com.punchsettle.server.pojo.uniapp.CalendarSelectedVO;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author tyuio
+ * @version 1.0.0
+ * @date 2025/5/9 9:34
+ * @description 打卡记录 VO
+ */
+@Data
+public class PunchInHistoryVO {
+
+    /**
+     * 日历打点信息
+     */
+    private List<CalendarSelectedVO> calendarSelectedVOS;
+
+    /**
+     * 打卡记录
+     */
+    private List<PiTaskHistoryVO> piTaskHistoryVOS;
+}

+ 23 - 0
src/main/java/com/punchsettle/server/pojo/uniapp/CalendarSelectedVO.java

@@ -0,0 +1,23 @@
+package com.punchsettle.server.pojo.uniapp;
+
+import lombok.Data;
+
+/**
+ * @author tyuio
+ * @version 1.0.0
+ * @date 2025/5/9 9:12
+ * @description 日历打点显示 VO
+ */
+@Data
+public class CalendarSelectedVO {
+
+    /**
+     * 打卡日期
+     */
+    private String date;
+
+    /**
+     * 信息
+     */
+    private String info;
+}

+ 2 - 1
src/main/java/com/punchsettle/server/service/controller/PunchInController.java

@@ -2,6 +2,7 @@ package com.punchsettle.server.service.controller;
 
 import java.util.List;
 
+import com.punchsettle.server.pojo.punchIn.PunchInHistoryVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -122,7 +123,7 @@ public class PunchInController {
      * @return
      */
     @GetMapping("/queryPunchInHistory")
-    public List<PiTaskHistoryStatVO> queryPunchInHistory(@NotNull(message = "打卡日期不能为空") String punchInDate) {
+    public PunchInHistoryVO queryPunchInHistory(@NotNull(message = "打卡日期不能为空") String punchInDate) {
         return punchInManager.queryPunchInHistory(punchInDate);
     }
 }

+ 2 - 1
src/main/java/com/punchsettle/server/service/manager/IPunchInManager.java

@@ -11,6 +11,7 @@ import com.punchsettle.server.pojo.punchIn.PiTaskStatQuery;
 import com.punchsettle.server.pojo.punchIn.PiTaskStatVO;
 import com.punchsettle.server.pojo.punchIn.PiTaskToDoVO;
 import com.punchsettle.server.pojo.punchIn.PiTaskVO;
+import com.punchsettle.server.pojo.punchIn.PunchInHistoryVO;
 import com.punchsettle.server.pojo.punchIn.PunchInRequest;
 
 /**
@@ -79,7 +80,7 @@ public interface IPunchInManager {
     /**
      * 查询打卡历史
      */
-    List<PiTaskHistoryStatVO> queryPunchInHistory(String punchInDate);
+    PunchInHistoryVO queryPunchInHistory(String punchInDate);
 
     /**
      * 从缓存获取指定用户的任务列表

+ 57 - 7
src/main/java/com/punchsettle/server/service/manager/impl/PunchInManagerImpl.java

@@ -46,6 +46,7 @@ import com.punchsettle.server.constant.VersionStatusEnum;
 import com.punchsettle.server.pojo.punchIn.PiTaskHistoryQuery;
 import com.punchsettle.server.pojo.punchIn.PiTaskHistorySimpleVO;
 import com.punchsettle.server.pojo.punchIn.PiTaskHistoryStatVO;
+import com.punchsettle.server.pojo.punchIn.PiTaskHistoryVO;
 import com.punchsettle.server.pojo.punchIn.PiTaskQuery;
 import com.punchsettle.server.pojo.punchIn.PiTaskRequest;
 import com.punchsettle.server.pojo.punchIn.PiTaskSimpleVO;
@@ -53,10 +54,12 @@ import com.punchsettle.server.pojo.punchIn.PiTaskStatQuery;
 import com.punchsettle.server.pojo.punchIn.PiTaskStatVO;
 import com.punchsettle.server.pojo.punchIn.PiTaskToDoVO;
 import com.punchsettle.server.pojo.punchIn.PiTaskVO;
+import com.punchsettle.server.pojo.punchIn.PunchInHistoryVO;
 import com.punchsettle.server.pojo.punchIn.PunchInRequest;
 import com.punchsettle.server.pojo.stat.StatPiTaskQuery;
 import com.punchsettle.server.pojo.ucharts.LineSeriesVO;
 import com.punchsettle.server.pojo.ucharts.LineVO;
+import com.punchsettle.server.pojo.uniapp.CalendarSelectedVO;
 import com.punchsettle.server.service.manager.ICacheManager;
 import com.punchsettle.server.service.manager.ICalendarManager;
 import com.punchsettle.server.service.manager.IPunchInCoreManager;
@@ -636,23 +639,70 @@ public class PunchInManagerImpl implements IPunchInManager {
 
     @Override
     @Cacheable(cacheNames = CacheNameConstant.TASK_PUNCH_IN_HISTORY, key = "T(com.punchsettle.server.utiis.UserUtils).getCurrentUserId()+'_'+#punchInDate", condition = "#punchInDate != null && !#punchInDate.isBlank()")
-    public List<PiTaskHistoryStatVO> queryPunchInHistory(String punchInDate) {
+    public PunchInHistoryVO queryPunchInHistory(String punchInDate) {
         Assert.isNullInBusiness(punchInDate, "打卡日期不能为空");
 
         // 查询打卡记录
         PiTaskHistoryQuery piTaskHistoryQuery = new PiTaskHistoryQuery();
         piTaskHistoryQuery.setUserIds(Arrays.asList(UserUtils.getCurrentUserId()));
-        piTaskHistoryQuery.setPunchInDate(punchInDate);
+        piTaskHistoryQuery.setPunchInDateLike(punchInDate.substring(0, 7));
         List<PiTaskHistory> piTaskHistories = piTaskHistoryService.queryByCondition(piTaskHistoryQuery);
+
+        // 打卡数据直接返回
         if (CollectionUtils.isEmpty(piTaskHistories)) {
-            return List.of();
+            return new PunchInHistoryVO();
         }
 
-        return piTaskHistories.stream().map(piTaskHistory -> {
-            PiTaskHistoryStatVO piTaskHistoryStatVO = new PiTaskHistoryStatVO();
-            BeanUtils.copyProperties(piTaskHistory, piTaskHistoryStatVO);
-            return piTaskHistoryStatVO;
+        // 打卡日期 - 打卡记录关联
+        Map<String, List<PiTaskHistory>> piTaskHistoryMap = piTaskHistories.stream().collect(Collectors.groupingBy(PiTaskHistory::getPunchInDate));
+
+        PunchInHistoryVO punchInHistoryVO = new PunchInHistoryVO();
+
+        // 日历打点信息
+        List<CalendarSelectedVO> calendarSelectedVOS = piTaskHistoryMap.keySet().stream().map(tempPunchInDate -> {
+            // 获取打卡记录
+            List<PiTaskHistory> tempPiTaskHistories = piTaskHistoryMap.get(tempPunchInDate);
+            // 打卡完成数
+            long punchInDoneCount = tempPiTaskHistories.stream().filter(piTaskHistory -> PunchInResultEnum.DONE.equals(piTaskHistory.getPunchInResult())).count();
+
+            CalendarSelectedVO calendarSelectedVO = new CalendarSelectedVO();
+            calendarSelectedVO.setDate(tempPunchInDate);
+            calendarSelectedVO.setInfo(String.valueOf(punchInDoneCount));
+            return calendarSelectedVO;
+        }).toList();
+        // 设置日历打点信息
+        punchInHistoryVO.setCalendarSelectedVOS(calendarSelectedVOS);
+
+        // 获取任务信息
+        List<PiTaskHistory> tempPiTaskHistories = piTaskHistoryMap.get(punchInDate);
+        // 当天没有直接返回
+        if (CollectionUtils.isEmpty(tempPiTaskHistories)) {
+            return punchInHistoryVO;
+        }
+        Set<Long> taskIds = tempPiTaskHistories.stream().map(PiTaskHistory::getTaskId).collect(Collectors.toSet());
+        PiTaskQuery piTaskQuery = new PiTaskQuery();
+        piTaskQuery.setIds(taskIds);
+        List<PiTask> piTasks = piTaskService.queryByCondition(piTaskQuery);
+        // 任务ID - 任务信息
+        Map<Long, PiTask> piTaskMap = piTasks.stream().collect(Collectors.toMap(PiTask::getId, Function.identity(), (key1, key2) -> key1));
+        // 打卡记录
+        List<PiTaskHistoryVO> piTaskHistoryVOS = tempPiTaskHistories.stream().map(piTaskHistory -> {
+            PiTask piTask = piTaskMap.get(piTaskHistory.getTaskId());
+
+            PiTaskHistoryVO piTaskHistoryVO = new PiTaskHistoryVO();
+            if (Objects.nonNull(piTask)) {
+                piTaskHistoryVO.setTaskName(piTask.getTaskName());
+                piTaskHistoryVO.setPunchInMethod(piTask.getPunchInMethod());
+            }
+            piTaskHistoryVO.setTimeTrack(piTaskHistory.getTimeTrack());
+            piTaskHistoryVO.setCountTrack(piTaskHistory.getCountTrack());
+            piTaskHistoryVO.setPunchInResult(piTaskHistory.getPunchInResult());
+            return piTaskHistoryVO;
         }).collect(Collectors.toList());
+        // 设置打卡记录
+        punchInHistoryVO.setPiTaskHistoryVOS(piTaskHistoryVOS);
+
+        return punchInHistoryVO;
     }
 
     @Override

+ 3 - 3
src/main/java/com/punchsettle/server/service/manager/impl/StatManagerImpl.java

@@ -121,7 +121,7 @@ public class StatManagerImpl implements IStatManager {
     public LineVO queryStatPointsLine() {
         Long currentUserId = UserUtils.getCurrentUserId();
 
-        LocalDate endDate = LocalDate.now();
+        LocalDate endDate = LocalDate.now().minusDays(1);
         LocalDate startDate = endDate.minusDays(bizProperties.getLineItemCount());
 
         // 获取折线图时间范围
@@ -170,7 +170,7 @@ public class StatManagerImpl implements IStatManager {
             return null;
         }
 
-        LocalDate endDate = LocalDate.now();
+        LocalDate endDate = LocalDate.now().minusDays(1);
         LocalDate startDate = endDate.minusDays(bizProperties.getLineItemCount());
 
         // 获取折线图时间范围
@@ -204,7 +204,7 @@ public class StatManagerImpl implements IStatManager {
     public LineVO queryStatTaskLine() {
         Long currentUserId = UserUtils.getCurrentUserId();
 
-        LocalDate endDate = LocalDate.now();
+        LocalDate endDate = LocalDate.now().minusDays(1);
         LocalDate startDate = endDate.minusDays(bizProperties.getLineItemCount());
 
         // 获取折线图时间范围