Explorar el Código

【feat】【第二版开发】
1.增加功能代码
2.完善第二版的计数文档
3.完善第二版的ddl语句

1.功能开发

ChenYL hace 1 año
padre
commit
4f3c88b5c5

+ 0 - 1
src/main/java/com/punchsettle/server/constant/PunchInStatusViewEnum.java

@@ -17,7 +17,6 @@ public enum PunchInStatusViewEnum {
     UNCREATED("未创建打卡任务", "uncreated"),
     PUNCH_IN("已打卡", "punchIn"),
     UN_PUNCH_IN("没打卡", "unPunchIn"),
-    TODAY_UNKNOWN("当天打卡状态未知", "todayUnknown"),
     FUTURE_TIME("未到打卡时间", "futureTime");
 
     /**

+ 1 - 8
src/main/java/com/punchsettle/server/dto/UserInfoDto.java

@@ -1,12 +1,5 @@
 package com.punchsettle.server.dto;
 
-/**
- * @author tyuio
- * @version 1.0.0
- * @description TODO
- * @date 2024/12/13 15:11
- */
-
 import java.math.BigDecimal;
 
 import lombok.Data;
@@ -15,7 +8,7 @@ import lombok.EqualsAndHashCode;
 /**
  * @author tyuio
  * @version 1.0.0
- * @description 领取结算奖励 dto
+ * @description 用户信息 dto
  * @date 2024/11/25 19:42
  */
 @Data

+ 35 - 0
src/main/java/com/punchsettle/server/dto/punchin/PunchInDataQuery.java

@@ -0,0 +1,35 @@
+package com.punchsettle.server.dto.punchin;
+
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * @author tyuio
+ * @version 1.0.0
+ * @description 打卡数据查询
+ * @date 2024/12/16 20:09
+ */
+@Data
+@EqualsAndHashCode
+public class PunchInDataQuery {
+
+    /**
+     * 打卡任务ID
+     */
+    @NotNull(message = "待查询的打卡任务ID不能为空")
+    private Long id;
+
+    /**
+     * 打卡年份
+     */
+    @NotNull(message = "待查询的打卡年份不能为空")
+    private Integer year;
+
+    /**
+     * 打卡月份
+     */
+    @NotNull(message = "待查询的打卡月份不能为空")
+    private Integer month;
+}

+ 44 - 0
src/main/java/com/punchsettle/server/dto/punchin/PunchInDataResult.java

@@ -0,0 +1,44 @@
+package com.punchsettle.server.dto.punchin;
+
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * @author tyuio
+ * @version 1.0.0
+ * @description 打卡数据查询结果
+ * @date 2024/12/16 20:09
+ */
+@Data
+@EqualsAndHashCode
+public class PunchInDataResult {
+
+    /**
+     * 打卡任务开始显示日期
+     */
+    private String startDate;
+
+    /**
+     * 打卡任务结束显示日期
+     */
+    private String endDate;
+
+    /**
+     * 打卡次数
+     */
+    private Integer punchInNum;
+
+    /**
+     * 打卡完成率
+     */
+    private BigDecimal punchInRate;
+
+    /**
+     * 打卡记录
+     */
+    private List<PunchInRecordDataResult> punchInRecords;
+}

+ 29 - 0
src/main/java/com/punchsettle/server/dto/punchin/PunchInRecordDataResult.java

@@ -0,0 +1,29 @@
+package com.punchsettle.server.dto.punchin;
+
+import java.math.BigDecimal;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * @author tyuio
+ * @version 1.0.0
+ * @description 打卡数据查询结果
+ * @date 2024/12/16 20:09
+ */
+@Data
+@EqualsAndHashCode
+public class PunchInRecordDataResult {
+
+    /**
+     * 打卡日期
+     */
+    private String date;
+
+    /**
+     * 信息
+     */
+    private String info;
+
+    // TODO 这里加打卡日志信息
+}

+ 6 - 0
src/main/java/com/punchsettle/server/dto/punchin/PunchInWithRecordDto.java

@@ -4,6 +4,7 @@ import java.time.LocalTime;
 import java.util.List;
 
 import com.punchsettle.server.constant.PunchInCategoryEnum;
+import com.punchsettle.server.constant.PunchInStatusViewEnum;
 import lombok.Data;
 
 /**
@@ -69,4 +70,9 @@ public class PunchInWithRecordDto {
      * 打卡记录
      */
     private List<PunchInRecordDto> punchInRecords;
+
+    /**
+     * 打卡状态(今天)
+     */
+    private PunchInStatusViewEnum punchInStatus;
 }

+ 22 - 0
src/main/java/com/punchsettle/server/service/controller/PunchInController.java

@@ -1,8 +1,12 @@
 package com.punchsettle.server.service.controller;
 
+import java.time.LocalDate;
+import java.time.YearMonth;
 import java.util.List;
 
 import com.punchsettle.server.common.valid.Query;
+import com.punchsettle.server.dto.punchin.PunchInDataQuery;
+import com.punchsettle.server.dto.punchin.PunchInDataResult;
 import com.punchsettle.server.dto.punchin.PunchInRecordDto;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
@@ -102,4 +106,22 @@ public class PunchInController {
     public void revokePunchIn(@RequestBody @Validated PunchInDto dto) {
         punchInManager.revokePunchIn(dto);
     }
+
+    /**
+     * 查询历史打卡数据
+     * @param query
+     */
+    @PostMapping("/queryPunchInData")
+    public List<PunchInDataResult> queryPunchInData(@RequestBody @Validated PunchInDataQuery query) {
+
+    }
+
+    public static void main(String[] args) {
+        YearMonth yearMonth = YearMonth.of(2024, 12);
+        LocalDate localDate = yearMonth.atDay(1);
+        LocalDate localDate1 = yearMonth.atEndOfMonth();
+        System.out.println(localDate);
+        System.out.println(localDate1);
+        System.out.println(yearMonth.lengthOfMonth());
+    }
 }

+ 11 - 0
src/main/java/com/punchsettle/server/service/manager/ISettleManager.java

@@ -3,7 +3,10 @@ package com.punchsettle.server.service.manager;
 import java.time.LocalDate;
 import java.util.List;
 
+import com.punchsettle.server.atomic.entity.PunchIn;
+import com.punchsettle.server.atomic.entity.PunchInRecord;
 import com.punchsettle.server.constant.PunchInSettleTypeEnum;
+import com.punchsettle.server.constant.PunchInStatusEnum;
 import com.punchsettle.server.dto.settle.SettleDto;
 import com.punchsettle.server.dto.settle.SettleQuery;
 import com.punchsettle.server.dto.settle.SettleRequest;
@@ -25,6 +28,14 @@ public interface ISettleManager {
      */
     void settleHandler(PunchInSettleTypeEnum settleType, LocalDate settleDate, List<Long> userIds, List<Long> punchInIds);
 
+    /**
+     * 判断是否满足打卡规则完成打卡
+     * @param punchIn
+     * @param punchInRecord
+     * @return PunchInStatusEnum
+     */
+    PunchInStatusEnum judgePunchInStatus(PunchIn punchIn, PunchInRecord punchInRecord);
+
     /**
      * 手动结算
      * @param settleRequest

+ 65 - 32
src/main/java/com/punchsettle/server/service/manager/impl/PunchInManagerImpl.java

@@ -2,6 +2,7 @@ package com.punchsettle.server.service.manager.impl;
 
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
+import java.time.LocalTime;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -11,6 +12,7 @@ import java.util.Optional;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
+import com.punchsettle.server.constant.PunchInStatusEnum;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -73,7 +75,7 @@ public class PunchInManagerImpl implements IPunchInManager {
             return List.of();
         }
 
-        // 获取一周的起始日期范围
+        // 获取一周的起始日期范围
         List<LocalDate> weeklyDateRange = DateUtils.getWeeklyDateRange();
         // 获取打卡任务ID
         List<Long> punchInIds = punchIns.stream().map(PunchIn::getId).collect(Collectors.toList());
@@ -84,7 +86,7 @@ public class PunchInManagerImpl implements IPunchInManager {
         query.setEndDate(weeklyDateRange.getLast().toString());
         List<PunchInRecord> punchInRecords = punchInRecordService.listByCondition(query);
 
-        // 按打卡任务任务分组
+        // 打卡任务-打卡记录 分组
         Map<Long, List<PunchInRecord>> recordMap =
             punchInRecords.stream().collect(Collectors.groupingBy(PunchInRecord::getPunchInId));
 
@@ -97,55 +99,86 @@ public class PunchInManagerImpl implements IPunchInManager {
         // 构建打卡记录
         List<PunchInWithRecordDto> punchInWithRecordDtos = new ArrayList<>();
         for (PunchIn punchIn : punchIns) {
+            // 一周的打卡记录容器
+            List<PunchInRecordDto> weeklyRecords = new ArrayList<>();
+            // 打卡任务信息
             PunchInWithRecordDto punchInWithRecordDto = new PunchInWithRecordDto();
             BeanUtils.copyProperties(punchIn, punchInWithRecordDto);
             punchInWithRecordDto.setPunchInId(punchIn.getId());
+            // 设置一个默认的页面显示值
+            punchInWithRecordDto.setTimeTrack(LocalTime.parse("00:00:00.000"));
+            punchInWithRecordDto.setCountTrack(0);
+            punchInWithRecordDto.setPunchInRecords(weeklyRecords);
+            punchInWithRecordDtos.add(punchInWithRecordDto);
 
             // 打卡任务创建日期
             LocalDate punchInCreationDate = LocalDate.parse(sdf.format(punchIn.getCreationTime()));
 
-            // 获取打卡任务对应的打卡记录,并按打卡日期转为map
+            // 获取打卡任务对应的打卡记录,并转为打卡日期-打卡记录map
             List<PunchInRecord> records =
                 Optional.ofNullable(recordMap.get(punchInWithRecordDto.getPunchInId())).orElse(List.of());
-            Map<String, PunchInRecord> recordWeekMap = records.stream()
+            Map<String, PunchInRecord> weeklyRecordMap = records.stream()
                 .collect(Collectors.toMap(PunchInRecord::getPunchInDate, Function.identity(), (key1, key2) -> key1));
 
-            // 设置打卡记录
-            List<PunchInRecordDto> recordDtos = new ArrayList<>();
-            punchInWithRecordDto.setPunchInRecords(recordDtos);
-
-            // 知道任务什么时候创建
-            // 在这之前(不包含)的记录的状态值都为0-任务未创建
-            // 在这之后如果打卡则状态为1-任务已创建已打卡
-            // 在这之后如果没打卡则状态为2-任务已创建但未打卡
-            // 如果当前日期超过一周中的某天则跳过
-            for (LocalDate currentDate : weeklyDateRange) {
-                String currentDateStr = currentDate.toString();
+            for (LocalDate weeklyDate : weeklyDateRange) {
+                String weeklyDateStr = weeklyDate.toString();
+
+                // 获取打卡记录
+                PunchInRecord punchInRecord = weeklyRecordMap.get(weeklyDateStr);
+
+                // 根据过往打卡记录设置打卡状态
+                PunchInStatusViewEnum punchInStatus = judgePunchInStatus(today, weeklyDate, punchInCreationDate, punchIn, punchInRecord);
+
                 // 设置打卡记录
                 PunchInRecordDto punchInRecordDto = new PunchInRecordDto();
-                punchInRecordDto.setPunchInDate(currentDateStr);
-                recordDtos.add(punchInRecordDto);
-
-                // 还没到当前日期则跳过,根据过往打卡记录设置打卡状态
-                if (currentDate.isAfter(today)) {
-                    punchInRecordDto.setPunchInStatus(PunchInStatusViewEnum.FUTURE_TIME);
-                } else if (currentDate.isBefore(punchInCreationDate)) {
-                    punchInRecordDto.setPunchInStatus(PunchInStatusViewEnum.UNCREATED);
-                } else if (recordWeekMap.containsKey(currentDateStr)) {
-                    punchInRecordDto.setPunchInStatus(PunchInStatusViewEnum.PUNCH_IN);
-                } else if (currentDate.isEqual(today) && !recordWeekMap.containsKey(currentDateStr)) {
-                    punchInRecordDto.setPunchInStatus(PunchInStatusViewEnum.TODAY_UNKNOWN);
-                } else {
-                    punchInRecordDto.setPunchInStatus(PunchInStatusViewEnum.UN_PUNCH_IN);
+                punchInRecordDto.setPunchInDate(weeklyDateStr);
+                punchInRecordDto.setPunchInStatus(punchInStatus);
+                weeklyRecords.add(punchInRecordDto);
+
+                // 如果是今天的打卡记录,设置计数/计时属性
+                if (!Objects.isNull(punchInRecord) && today.isEqual(weeklyDate)) {
+                    punchInWithRecordDto.setTimeTrack(punchInRecord.getTimeTrack());
+                    punchInWithRecordDto.setCountTrack(punchInRecord.getCountTrack());
+                    punchInWithRecordDto.setPunchInStatus(punchInStatus);
                 }
-
             }
-            punchInWithRecordDtos.add(punchInWithRecordDto);
         }
 
         return punchInWithRecordDtos;
     }
 
+    private PunchInStatusViewEnum judgePunchInStatus(LocalDate today, LocalDate weeklyDate, LocalDate punchInCreationDate, PunchIn punchIn, PunchInRecord punchInRecord) {
+        // 一周某天还没到,无法打卡
+        if (weeklyDate.isAfter(today)) {
+            return PunchInStatusViewEnum.FUTURE_TIME;
+        }
+
+        // 一周某天早于任务创建时间,无法打卡
+        if (weeklyDate.isBefore(punchInCreationDate)) {
+            return PunchInStatusViewEnum.UNCREATED;
+        }
+
+        // 一周某天在今天之前存在打卡记录,则需要判断是否完成打卡
+        if (!Objects.isNull(punchInRecord) && weeklyDate.isBefore(today)) {
+            if (PunchInStatusEnum.FINISH.equals(punchInRecord.getPunchInStatus())
+                    ||PunchInStatusEnum.REMAKE_FINISH.equals(punchInRecord.getPunchInStatus())) {
+                return PunchInStatusViewEnum.PUNCH_IN;
+            }
+        }
+
+        // 一周的某天是今天,且存在打卡记录,则判断是否完成打卡
+        if (weeklyDate.isEqual(today) && !Objects.isNull(punchInRecord)) {
+            PunchInStatusEnum punchInStatusEnum = settleManager.judgePunchInStatus(punchIn, punchInRecord);
+            if (PunchInStatusEnum.FINISH.equals(punchInStatusEnum)
+                || PunchInStatusEnum.REMAKE_FINISH.equals(punchInStatusEnum)) {
+                return PunchInStatusViewEnum.PUNCH_IN;
+            }
+        }
+
+        // 不符合任何情况则是未打卡
+        return PunchInStatusViewEnum.UN_PUNCH_IN;
+    }
+
     @Override
     public PunchInDto queryPunchInById(Long punchInId) {
         Assert.isNullInBusiness(punchInId, "请传入待查询的任务ID");
@@ -209,7 +242,7 @@ public class PunchInManagerImpl implements IPunchInManager {
 
         // 打卡类型:单次打卡,需要判断是否重复打卡
         if (PunchInCategoryEnum.SINGLE.equals(punchIn.getCategory()) && !Objects.isNull(oldPunchInRecord)) {
-            throw BusinessException.fail("已打卡");
+            throw BusinessException.fail("已打卡,无须重复打卡");
         }
 
         // 获取或创建打卡记录

+ 1 - 1
src/main/java/com/punchsettle/server/service/manager/impl/RewardManagerImpl.java

@@ -71,7 +71,7 @@ public class RewardManagerImpl implements IRewardManager {
         updateUser.setId(user.getId());
         updateUser.setUnclaimedRewardNum(unclaimedRewardNum);
         updateUser.setClaimedRewardNum(claimedRewardNum);
-        userService.updateById(user);
+        userService.updateById(updateUser);
     }
 
     @Override

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

@@ -305,18 +305,18 @@ public class SettleManagerImpl implements ISettleManager {
         return settleResultDto;
     }
 
-    /**
-     * 判断是否满足打卡规则完成打卡
-     * @param punchIn
-     * @param punchInRecord
-     * @return PunchInStatusEnum
-     */
-    private PunchInStatusEnum judgePunchInStatus(PunchIn punchIn, PunchInRecord punchInRecord) {
+    @Override
+    public PunchInStatusEnum judgePunchInStatus(PunchIn punchIn, PunchInRecord punchInRecord) {
         // 没有打卡记录,直接没完成,包含单次打卡的情况无需额外判断
         if (Objects.isNull(punchInRecord)) {
             return PunchInStatusEnum.UN_FINISH;
         }
 
+        // 单次打卡
+        if (PunchInCategoryEnum.SINGLE.equals(punchIn.getCategory())) {
+            return PunchInStatusEnum.FINISH;
+        }
+
         // 计数打卡
         if (PunchInCategoryEnum.COUNT.equals(punchIn.getCategory())) {
             if (PunchInRuleEnum.GREATER.equals(punchIn.getRule()) && punchInRecord.getCountTrack().compareTo(punchIn.getCountTrack()) < 1) {

+ 2 - 0
src/main/java/com/punchsettle/server/utiis/DateUtils.java

@@ -1,5 +1,7 @@
 package com.punchsettle.server.utiis;
 
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
 import java.time.DayOfWeek;
 import java.time.LocalDate;
 import java.time.temporal.TemporalAdjusters;