Răsfoiți Sursa

【feat】【第一版开发】
1.增加README.md文件

1.完善代码逻辑

ChenYL 1 an în urmă
părinte
comite
36c3364dc9

+ 4 - 0
README.md

@@ -14,9 +14,13 @@
 
 ## 待办列表
 
+* uniapp环境配置分离
+* 对接前端
+* certbot自动续期
 * 结算任务增加定时任务自动执行
 * 数据库脚本审计字段(creation_time、last_update_time)增加默认值
 * ~~功能开发~~
+* ~~前端开发~~
 * ~~表设计~~
 * ~~前端原型图设计~~
 * ~~需求文档编写~~

+ 7 - 0
src/main/java/com/punchsettle/server/atomic/service/IPunchInService.java

@@ -19,6 +19,13 @@ public interface IPunchInService {
      */
     List<PunchIn> listByCreatedBy(Long createdBy);
 
+    /**
+     * 根据主键查询打卡任务
+     * @param id
+     * @return
+     */
+    PunchIn getById(Long id);
+
     /**
      * 根据创建人查询所有的打卡结算任务数据
      * @param userIds 创建人id

+ 8 - 0
src/main/java/com/punchsettle/server/atomic/service/impl/PunchInServiceImpl.java

@@ -38,6 +38,14 @@ public class PunchInServiceImpl implements IPunchInService {
         return punchInMapper.select(query);
     }
 
+    @Override
+    public PunchIn getById(Long id) {
+        if (Objects.isNull(id)) {
+            return null;
+        }
+        return punchInMapper.selectByPrimaryKey(id);
+    }
+
     @Override
     public List<PunchIn> listByCreatedBy(List<Long> userIds) {
         if (CollectionUtils.isEmpty(userIds)) {

+ 9 - 5
src/main/java/com/punchsettle/server/constant/PunchInStatusEnum.java

@@ -1,5 +1,6 @@
 package com.punchsettle.server.constant;
 
+import com.fasterxml.jackson.annotation.JsonValue;
 import lombok.Getter;
 
 /**
@@ -11,9 +12,11 @@ import lombok.Getter;
 @Getter
 public enum PunchInStatusEnum {
 
-    UNCREATED("未创建打卡任务", 0),
-    PUNCHIN("已打卡", 1),
-    UNPUNCHIN("没打卡", 2);
+    UNCREATED("未创建打卡任务", "uncreated"),
+    PUNCH_IN("已打卡", "punchIn"),
+    UN_PUNCH_IN("没打卡", "unPunchIn"),
+    TODAY_UNKNOWN("当天打卡状态未知", "todayUnknown"),
+    FUTURE_TIME("未到打卡时间", "futureTime");
 
     /**
      * 名称
@@ -23,9 +26,10 @@ public enum PunchInStatusEnum {
     /**
      * 值
      */
-    private Integer value;
+    @JsonValue
+    private String value;
 
-    PunchInStatusEnum(String name, Integer value) {
+    PunchInStatusEnum(String name, String value) {
         this.name = name;
         this.value = value;
     }

+ 19 - 0
src/main/java/com/punchsettle/server/core/config/WebMvcConfig.java

@@ -3,6 +3,7 @@ package com.punchsettle.server.core.config;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.format.FormatterRegistry;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@@ -20,9 +21,27 @@ public class WebMvcConfig implements WebMvcConfigurer {
         registry.addConverterFactory(new IntegerToEnumConverterFactory());
     }
 
+    /**
+     * 登录校验拦截
+     * @param registry
+     */
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         registry.addInterceptor(authInterceptor)
                 .excludePathPatterns("/health/**", "/login/**");
     }
+
+    /**
+     * 跨域配置
+     * @param registry
+     */
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        registry.addMapping("/**") // 对所有路径生效
+                .allowedOriginPatterns("*") // 允许所有来源
+                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的HTTP方法
+                .allowedHeaders("*") // 允许的头部
+                .allowCredentials(true) // 是否允许发送Cookie
+                .maxAge(3600); // 预检请求的有效期,单位为秒
+    }
 }

+ 2 - 1
src/main/java/com/punchsettle/server/dto/PunchInDto.java

@@ -1,5 +1,6 @@
 package com.punchsettle.server.dto;
 
+import com.punchsettle.server.common.valid.Query;
 import org.hibernate.validator.constraints.Length;
 
 import com.punchsettle.server.common.valid.Delete;
@@ -26,7 +27,7 @@ public class PunchInDto {
     /**
      * 打卡结算主键
      */
-    @NotNull(message = "打卡结算主键不能为空", groups = {Update.class, Delete.class, DoSomething.class})
+    @NotNull(message = "打卡结算主键不能为空", groups = {Query.class, Update.class, Delete.class, DoSomething.class})
     private Long id;
 
     /**

+ 4 - 2
src/main/java/com/punchsettle/server/dto/PunchInRecordDto.java

@@ -1,5 +1,6 @@
 package com.punchsettle.server.dto;
 
+import com.punchsettle.server.constant.PunchInStatusEnum;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -19,7 +20,8 @@ public class PunchInRecordDto {
     private String punchInDate;
 
     /**
-     * 打卡状态(1-待打卡,2-完成、3-未完成)
+     * 打卡状态
+     * @see PunchInStatusEnum
      */
-    private Integer punchInStatus;
+    private PunchInStatusEnum punchInStatus;
 }

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

@@ -5,7 +5,7 @@ import lombok.Data;
 /**
  * @author tyuio
  * @version 1.0.0
- * @description TODO
+ * @description 用户奖励
  * @date 2024/11/25 20:55
  */
 @Data

+ 0 - 1
src/main/java/com/punchsettle/server/service/controller/LoginController.java

@@ -17,7 +17,6 @@ import com.punchsettle.server.service.manager.ILoginManager;
  * @version V1.0
  **/
 @RestController
-@RequestMapping("/wechat/miniprogram")
 public class LoginController {
 
     @Autowired

+ 11 - 5
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.common.valid.Query;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -34,23 +35,28 @@ public class PunchInController {
     /**
      * 查询打卡任务
      */
-    @GetMapping("/query")
+    @GetMapping("/queryPunchIn")
     public List<PunchInWithRecordDto> query() {
         return punchInManager.queryPunchInAndRecord();
     }
 
+    @PostMapping("queryPunchInById")
+    public PunchInDto queryPunchInById(@RequestBody @Validated({Query.class}) PunchInDto dto) {
+        return punchInManager.queryPunchInById(dto.getId());
+    }
+
     /**
      * 新增打卡任务
      */
-    @PostMapping("/save")
+    @PostMapping("/savePunchIn")
     public void save(@RequestBody @Validated({Save.class}) PunchInDto dto) {
         punchInManager.saveOrUpdatePunchIn(dto);
     }
 
     /**
-     * 新增或更新打卡任务
+     * 更新打卡任务
      */
-    @PostMapping("/update")
+    @PostMapping("/updatePunchIn")
     public void update(@RequestBody @Validated({Update.class}) PunchInDto dto) {
         punchInManager.saveOrUpdatePunchIn(dto);
     }
@@ -58,7 +64,7 @@ public class PunchInController {
     /**
      * 删除打卡任务
      */
-    @PostMapping("/delete")
+    @PostMapping("/deletePunchIn")
     public void delete(@RequestBody @Validated({Delete.class}) PunchInDto dto) {
         punchInManager.deletePunchIn(dto.getId());
     }

+ 5 - 0
src/main/java/com/punchsettle/server/service/manager/IPunchInManager.java

@@ -19,6 +19,11 @@ public interface IPunchInManager {
      */
     List<PunchInWithRecordDto> queryPunchInAndRecord();
 
+    /**
+     * 根据ID获取打卡任务
+     */
+    PunchInDto queryPunchInById(Long punchInId);
+
     /**
      * 新增或更新打卡结算任务
      * @param dto 打卡结算

+ 19 - 10
src/main/java/com/punchsettle/server/service/manager/impl/PunchInManagerImpl.java

@@ -114,18 +114,17 @@ public class PunchInManagerImpl implements IPunchInManager {
                 punchInRecordDto.setPunchInDate(currentDateStr);
                 recordDtos.add(punchInRecordDto);
 
-                // 还没到当前日期则跳过
+                // 还没到当前日期则跳过,根据过往打卡记录设置打卡状态
                 if (currentDate.isAfter(today)) {
-                    continue;
-                }
-
-                // 根据过往打卡记录设置打卡状态
-                if (currentDate.isBefore(punchInCreationDate)) {
-                    punchInRecordDto.setPunchInStatus(PunchInStatusEnum.UNCREATED.getValue());
+                    punchInRecordDto.setPunchInStatus(PunchInStatusEnum.FUTURE_TIME);
+                } else if (currentDate.isBefore(punchInCreationDate)) {
+                    punchInRecordDto.setPunchInStatus(PunchInStatusEnum.UNCREATED);
                 } else if (recordWeekMap.containsKey(currentDateStr)) {
-                    punchInRecordDto.setPunchInStatus(PunchInStatusEnum.PUNCHIN.getValue());
+                    punchInRecordDto.setPunchInStatus(PunchInStatusEnum.PUNCH_IN);
+                } else if (currentDate.isEqual(today) && !recordWeekMap.containsKey(currentDateStr)) {
+                    punchInRecordDto.setPunchInStatus(PunchInStatusEnum.TODAY_UNKNOWN);
                 } else {
-                    punchInRecordDto.setPunchInStatus(PunchInStatusEnum.UNPUNCHIN.getValue());
+                    punchInRecordDto.setPunchInStatus(PunchInStatusEnum.UN_PUNCH_IN);
                 }
 
             }
@@ -135,9 +134,19 @@ public class PunchInManagerImpl implements IPunchInManager {
         return punchInWithRecordDtos;
     }
 
+    @Override
+    public PunchInDto queryPunchInById(Long punchInId) {
+        Assert.isNullInBusiness(punchInId, "请传入待查询的任务ID");
+        return Optional.ofNullable(punchInService.getById(punchInId)).map(punchIn -> {
+            PunchInDto dto = new PunchInDto();
+            BeanUtils.copyProperties(punchIn, dto);
+            return dto;
+        }).orElseThrow(() -> BusinessException.fail("无法查询到该打卡任务"));
+    }
+
     @Override
     public void saveOrUpdatePunchIn(PunchInDto dto) {
-        Assert.isNullInBusiness(dto.getId(), "请传入任务信息");
+        Assert.isNullInBusiness(dto, "请传入任务信息");
 
         PunchIn punchIn = new PunchIn();
         BeanUtils.copyProperties(dto, punchIn);

+ 12 - 0
src/main/resources/application-dev.yaml

@@ -0,0 +1,12 @@
+spring:
+  datasource:
+    username: root
+    url: jdbc:mysql://localhost:3306/punch_settle?useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
+
+logging:
+  level:
+    com.punchsettle.server: debug
+
+biz:
+  token:
+    password: 12123

+ 8 - 0
src/main/resources/application-prod.yaml

@@ -0,0 +1,8 @@
+spring:
+  datasource:
+#    username: root
+#    url: url=jdbc:mysql://localhost:3306/punch_settle?useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
+
+biz:
+  token:
+    password: 12123

+ 2 - 8
src/main/resources/application.yaml

@@ -1,20 +1,15 @@
 server:
   port: 8080
-
 spring:
+  profiles:
+    active: prod
   application:
     name: punch-settle-server
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
-    username: root
-    url: jdbc:mysql://localhost:3306/punch_settle?useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
   cache:
     type: caffeine
 
-logging:
-  level:
-    com.punchsettle.server: debug
-
 biz:
   wechat:
     mini-program:
@@ -23,4 +18,3 @@ biz:
       secret: ENC(i2ZFfTtFRvAUqpXSW4CQd6HEAMTc0Ltc1dVbhDiIxe4a5H7BbTV3bfiGhFvtRszOMIgyQDoxeZI=)
   token:
     expire: 7
-    password: 12123