소스 검색

Merge branch 'master' of http://git.zhixinghe1.top/zkpk/PunchSettle-Server

ChenYL 1 년 전
부모
커밋
1668f6abc8

+ 1 - 0
.idea/misc.xml

@@ -7,6 +7,7 @@
         <option value="$PROJECT_DIR$/pom.xml" />
       </list>
     </option>
+    <option name="workspaceImportForciblyTurnedOn" value="true" />
   </component>
   <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/out" />

+ 5 - 4
README.md

@@ -14,11 +14,12 @@
 
 ## 待办列表
 
-* uniapp环境配置分离
-* 对接前端
+* 前端样式和使用细节优化
+* ~~uniapp环境配置分离~~
+* ~~对接前端~~
 * certbot自动续期
-* 结算任务增加定时任务自动执行
-* 数据库脚本审计字段(creation_time、last_update_time)增加默认值
+* ~~结算任务增加定时任务自动执行~~
+* ~~数据库脚本审计字段(creation_time、last_update_time)增加默认值~~
 * ~~功能开发~~
 * ~~前端开发~~
 * ~~表设计~~

+ 1 - 0
doc/sql/db.sql

@@ -0,0 +1 @@
+CREATE DATABASE `punch_settle` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;

+ 18 - 20
doc/sql/punch_settle-ddl.sql → doc/sql/schema.sql

@@ -1,6 +1,4 @@
 -- punch_settle.punch_in definition
-CREATE DATABASE `punch_settle` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
-
 CREATE TABLE `punch_in` (
   `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
   `task_name` varchar(128) NOT NULL COMMENT '任务名称',
@@ -9,9 +7,9 @@ CREATE TABLE `punch_in` (
   `full_attendance_flag` tinyint NOT NULL DEFAULT '0' COMMENT '是否启用全勤奖励标志(0-不是,1-是)',
   `archive_flag` tinyint NOT NULL DEFAULT '0' COMMENT '是否归档标志(0-不是,1-是)',
   `created_by` bigint NOT NULL COMMENT '创建人',
-  `creation_time` timestamp NOT NULL COMMENT '创建时间',
+  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
-  `last_update_time` timestamp NOT NULL COMMENT '最后更新时间',
+  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
   `version` bigint NOT NULL DEFAULT '1' COMMENT '版本号',
   `delete_flag` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标志(0-未删除,1-已删除)',
   PRIMARY KEY (`id`)
@@ -25,9 +23,9 @@ CREATE TABLE `punch_in_record` (
   `punch_in_id` bigint NOT NULL COMMENT '打卡任务表主键',
   `punch_in_date` varchar(10) NOT NULL COMMENT '打卡日期',
   `created_by` bigint NOT NULL COMMENT '创建人',
-  `creation_time` timestamp NOT NULL COMMENT '创建时间',
+  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
-  `last_update_time` timestamp NOT NULL COMMENT '最后更新时间',
+  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
   `version` bigint NOT NULL DEFAULT '1' COMMENT '版本号',
   `delete_flag` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标志(0-未删除,1-已删除)',
   PRIMARY KEY (`id`)
@@ -40,9 +38,9 @@ CREATE TABLE `punch_in_record_settlement_rela` (
   `record_id` bigint NOT NULL COMMENT '打卡任务记录表ID',
   `settlement_id` bigint NOT NULL COMMENT '打卡任务结算表ID',
   `created_by` bigint NOT NULL COMMENT '创建人',
-  `creation_time` timestamp NOT NULL COMMENT '创建时间',
+  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
-  `last_update_time` timestamp NOT NULL COMMENT '最后更新时间',
+  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
   `version` bigint NOT NULL DEFAULT '1' COMMENT '版本号',
   `delete_flag` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标志(0-未删除,1-已删除)',
   PRIMARY KEY (`id`)
@@ -63,9 +61,9 @@ CREATE TABLE `punch_in_settlement` (
   `notify_status` varchar(20) DEFAULT NULL COMMENT '结算通知状态(fail-通知失败,success-成功通知,pending-待通知)',
   `notify_time` timestamp NULL DEFAULT NULL COMMENT '结算通知时间',
   `created_by` bigint NOT NULL COMMENT '创建人',
-  `creation_time` timestamp NOT NULL COMMENT '创建时间',
+  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
-  `last_update_time` timestamp NOT NULL COMMENT '最后更新时间',
+  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
   `version` bigint NOT NULL DEFAULT '1' COMMENT '版本号',
   `delete_flag` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标志(0-未删除,1-已删除)',
   PRIMARY KEY (`id`)
@@ -84,9 +82,9 @@ CREATE TABLE `settlement_notify_task` (
   `notify_fail_num` int NOT NULL DEFAULT '0' COMMENT '通知失败数量',
   `error_message` text COMMENT '失败异常信息',
   `created_by` bigint NOT NULL COMMENT '创建人',
-  `creation_time` timestamp NOT NULL COMMENT '创建时间',
+  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
-  `last_update_time` timestamp NOT NULL COMMENT '最后更新时间',
+  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
   `version` bigint NOT NULL DEFAULT '1' COMMENT '版本号',
   `delete_flag` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标志(0-未删除,1-已删除)',
   PRIMARY KEY (`id`)
@@ -105,9 +103,9 @@ CREATE TABLE `settlement_task` (
   `processed_unsettle_num` int NOT NULL DEFAULT '0' COMMENT '处理没结算数量',
   `error_message` text COMMENT '失败异常信息',
   `created_by` bigint NOT NULL COMMENT '创建人',
-  `creation_time` timestamp NOT NULL COMMENT '创建时间',
+  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
-  `last_update_time` timestamp NOT NULL COMMENT '最后更新时间',
+  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
   `version` bigint NOT NULL DEFAULT '1' COMMENT '版本号',
   `delete_flag` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标志(0-未删除,1-已删除)',
   PRIMARY KEY (`id`)
@@ -124,9 +122,9 @@ CREATE TABLE `user` (
   `reward_num` int NOT NULL DEFAULT '0',
   `claimed_reward_num` int NOT NULL DEFAULT '0' COMMENT '已领取奖励数',
   `created_by` bigint NOT NULL COMMENT '创建人',
-  `creation_time` timestamp NOT NULL COMMENT '创建时间',
+  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
-  `last_update_time` timestamp NOT NULL COMMENT '最后更新时间',
+  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
   `version` bigint NOT NULL DEFAULT '1' COMMENT '版本号',
   `delete_flag` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标志(0-未删除,1-已删除)',
   PRIMARY KEY (`id`)
@@ -142,9 +140,9 @@ CREATE TABLE `user_reward` (
   `unclaimed_reward_num` int NOT NULL DEFAULT '0' COMMENT '未领取奖励数',
   `claimed_reward_num` int NOT NULL DEFAULT '0' COMMENT '已领取奖励数',
   `created_by` bigint NOT NULL COMMENT '创建人',
-  `creation_time` timestamp NOT NULL COMMENT '创建时间',
+  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
-  `last_update_time` timestamp NOT NULL COMMENT '最后更新时间',
+  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
   `version` bigint NOT NULL DEFAULT '1' COMMENT '版本号',
   `delete_flag` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标志(0-未删除,1-已删除)',
   PRIMARY KEY (`id`)
@@ -161,9 +159,9 @@ CREATE TABLE `user_claim_reward_record` (
   `before_claim_reward_num` int NOT NULL DEFAULT '0' COMMENT '领取前用户拥有的奖励数',
   `after_claim_reward_num` int NOT NULL DEFAULT '0' COMMENT '领取后用户拥有的奖励数',
   `created_by` bigint NOT NULL COMMENT '创建人',
-  `creation_time` timestamp NOT NULL COMMENT '创建时间',
+  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
-  `last_update_time` timestamp NOT NULL COMMENT '最后更新时间',
+  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
   `version` bigint NOT NULL DEFAULT '1' COMMENT '版本号',
   `delete_flag` tinyint NOT NULL DEFAULT '0' COMMENT '逻辑删除标志(0-未删除,1-已删除)',
   PRIMARY KEY (`id`)

+ 7 - 0
doc/技术文档.md

@@ -275,18 +275,25 @@ mysqld --initialize-insecure
 
 # 注册mysql服务(需要管理员权限)
 mysqld -install
+# 注册mysql服务并指定配置文件(需要管理员权限)
+mysqld --install MySQL --defaults-file="配置文件路径\mysql-lts\current\my.ini"
 
 # 启动mysql服务(需要管理员权限)
+# 如果启动报错:"服务没有响应控制功能。请键入 NET HELPMSG 2186 以获得更多的帮助。",则看下面的参考文章看是否缺少组件
 net start mysql
 
 # 关闭mysql服务(需要管理员权限)
 net stop mysql
+
+# 如果mysql服务无法启动,则可以手动启动mysql
+mysqld --standalone
 ```
 
 参考:
 
 * [MySQL中的basedir和datadir的作用](https://blog.csdn.net/wolfalcon/article/details/80528678)
 * [MYSQL8.0安装、配置、启动、登入与卸载详细步骤总结](https://blog.csdn.net/qq_51688022/article/details/137105751)
+* [mysql服务没有响应控制功能](https://blog.csdn.net/m0_72160374/article/details/143462612)
 
 
 

+ 6 - 0
pom.xml

@@ -23,6 +23,7 @@
         <spring-cloud.version>2023.0.3</spring-cloud.version>
         <jwt.version>4.4.0</jwt.version>
         <tk-mybatis.version>5.0.1</tk-mybatis.version>
+        <jasypt.version>3.0.5</jasypt.version>
     </properties>
 
     <dependencyManagement>
@@ -91,6 +92,11 @@
             <artifactId>java-jwt</artifactId>
             <version>${jwt.version}</version>
         </dependency>
+        <dependency>
+            <groupId>com.github.ulisesbocchio</groupId>
+            <artifactId>jasypt-spring-boot-starter</artifactId>
+            <version>${jasypt.version}</version>
+        </dependency>
     </dependencies>
 
     <!-- 配置阿里云仓库 -->

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

@@ -4,11 +4,13 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 /**
  * @author tyuio
  */
 @EnableCaching
+@EnableScheduling
 @EnableFeignClients
 @SpringBootApplication
 public class Application {

+ 6 - 0
src/main/java/com/punchsettle/server/atomic/service/IUserRewardService.java

@@ -37,4 +37,10 @@ public interface IUserRewardService {
      * @param userRewards
      */
     void batchUpdateUserReward(List<UserReward> userRewards);
+
+    /**
+     * 新增用户奖励记录
+     * @param userReward
+     */
+    void insert(UserReward userReward);
 }

+ 8 - 2
src/main/java/com/punchsettle/server/atomic/service/IUserService.java

@@ -20,11 +20,17 @@ public interface IUserService {
     User getById(Long id);
 
     /**
-     * 获取ID获取用户,不存在时新增
+     * 根据openId获取用户
      * @param openId 微信openid
      * @return
      */
-    User getAndAdd(String openId);
+    User getByOpenId(String openId);
+
+    /**
+     * 新增用户
+     * @param user
+     */
+    void insert(User user);
 
     /**
      * 查询所有用户

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

@@ -0,0 +1,7 @@
+package com.punchsettle.server.atomic.service;
+
+/**
+ * 打卡任务记录表 service
+ */
+public interface PunchInRecordService {
+}

+ 6 - 0
src/main/java/com/punchsettle/server/atomic/service/impl/UserRewardServiceImpl.java

@@ -66,4 +66,10 @@ public class UserRewardServiceImpl implements IUserRewardService {
         Assert.notEmpty(userRewards);
         userRewardMapper.batchUpdateSelective(userRewards);
     }
+
+    @Override
+    public void insert(UserReward userReward) {
+        Assert.isNull(userReward);
+        userRewardMapper.insert(userReward);
+    }
 }

+ 8 - 1
src/main/java/com/punchsettle/server/atomic/service/impl/UserServiceImpl.java

@@ -3,6 +3,7 @@ package com.punchsettle.server.atomic.service.impl;
 import java.util.List;
 import java.util.Objects;
 
+import com.punchsettle.server.common.utils.Assert;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -33,7 +34,7 @@ public class UserServiceImpl implements IUserService {
     }
 
     @Override
-    public User getAndAdd(String openId) {
+    public User getByOpenId(String openId) {
         if (StringUtils.isBlank(openId)) {
             return null;
         }
@@ -43,6 +44,12 @@ public class UserServiceImpl implements IUserService {
         return userMapper.selectOne(queryUser);
     }
 
+    @Override
+    public void insert(User user) {
+        Assert.isNull(user);
+        userMapper.insert(user);
+    }
+
     @Override
     public List<User> list() {
         return userMapper.selectAll();

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

@@ -28,7 +28,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         registry.addInterceptor(authInterceptor)
-                .excludePathPatterns("/health/**", "/login/**");
+                .excludePathPatterns("/health/**", "/wechat/miniprogram/login");
     }
 
     /**

+ 10 - 0
src/main/java/com/punchsettle/server/dto/wechat/LoginRequest.java

@@ -18,4 +18,14 @@ public class LoginRequest {
      */
     @NotBlank(message = "微信code不能为空")
     private String code;
+
+    /**
+     * 头像
+     */
+    private String avatar;
+
+    /**
+     * 昵称
+     */
+    private String nickname;
 }

+ 24 - 0
src/main/java/com/punchsettle/server/service/controller/HealthController.java

@@ -1,5 +1,8 @@
 package com.punchsettle.server.service.controller;
 
+import com.punchsettle.server.atomic.entity.PunchIn;
+import com.punchsettle.server.atomic.mapper.PunchInMapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -17,8 +20,29 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/health")
 public class HealthController {
 
+    @Autowired
+    private PunchInMapper punchInMapper;
+
     @GetMapping("/info")
     public String info() {
         return "打卡结算后端服务 正在运行";
     }
+
+    @GetMapping("/test")
+    public String test() {
+        // 新增
+        // 查询
+        // 删除
+        // 修改
+        PunchIn punchIn = new PunchIn();
+        punchIn.setTaskName("任务名");
+        punchIn.setArchiveFlag(true);
+        punchIn.setRewardNum(12);
+        punchIn.setFullAttendanceFlag(true);
+        punchIn.setWeekendDoubleFlag(false);
+        punchIn.setVersion(1);
+//        punchInMapper.insert(punchIn);
+        punchInMapper.updateByPrimaryKey(punchIn);
+        return "测试";
+    }
 }

+ 18 - 0
src/main/java/com/punchsettle/server/service/manager/IUserManager.java

@@ -0,0 +1,18 @@
+package com.punchsettle.server.service.manager;
+
+import com.punchsettle.server.atomic.entity.User;
+
+/**
+ * @author tyuio
+ * @version 1.0.0
+ * @description 用户 服务类
+ * @date 2024/11/30 14:28
+ */
+public interface IUserManager {
+
+    /**
+     * 根据openId获取用户,如果没有则新增
+     * @param user
+     */
+    User getAndAddUser(User user);
+}

+ 8 - 6
src/main/java/com/punchsettle/server/service/manager/impl/LoginManagerImpl.java

@@ -7,9 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.punchsettle.server.atomic.entity.User;
-import com.punchsettle.server.atomic.service.IUserService;
 import com.punchsettle.server.common.exception.BusinessException;
-import com.punchsettle.server.common.utils.Assert;
 import com.punchsettle.server.constant.CacheConstant;
 import com.punchsettle.server.core.config.BizConfig;
 import com.punchsettle.server.dto.wechat.Code2SessionRequest;
@@ -17,6 +15,7 @@ import com.punchsettle.server.dto.wechat.Code2SessionResponse;
 import com.punchsettle.server.dto.wechat.LoginRequest;
 import com.punchsettle.server.feign.WechatMiniProgramFeign;
 import com.punchsettle.server.service.manager.ILoginManager;
+import com.punchsettle.server.service.manager.IUserManager;
 import com.punchsettle.server.utiis.CacheUtils;
 import com.punchsettle.server.utiis.TokenUtils;
 
@@ -33,7 +32,7 @@ public class LoginManagerImpl implements ILoginManager {
     private WechatMiniProgramFeign wechatMiniProgramFeign;
 
     @Autowired
-    private IUserService userService;
+    private IUserManager userManager;
 
     @Autowired
     private BizConfig bizConfig;
@@ -49,9 +48,12 @@ public class LoginManagerImpl implements ILoginManager {
             throw BusinessException.fail(loginResponse.getErrMsg());
         }
 
-        // 获取用户记录
-        User user = userService.getAndAdd(loginResponse.getOpenId());
-        Assert.isNullInBusiness(user, String.format("不存在的用户,且无法新增,openid: %s", loginResponse.getOpenId()));
+        // 获取用户
+        User loginUserInfo = new User();
+        loginUserInfo.setOpenId(loginResponse.getOpenId());
+        loginUserInfo.setNickname(request.getNickname());
+        loginUserInfo.setAvatar(request.getAvatar());
+        User user = userManager.getAndAddUser(loginUserInfo);
 
         // 缓存微信用户对应的session_key
         CacheUtils.put(CacheConstant.WECHAT_MINI_PROGRAM_SESSION_KEY, user.getId().toString(),

+ 13 - 0
src/main/java/com/punchsettle/server/service/manager/impl/PunchInManagerImpl.java

@@ -3,6 +3,7 @@ package com.punchsettle.server.service.manager.impl;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -164,6 +165,18 @@ public class PunchInManagerImpl implements IPunchInManager {
     @Transactional(rollbackFor = Exception.class)
     public void doPunchIn(Long punchInId) {
         Assert.isNullInBusiness(punchInId, "请传入待打卡的任务");
+
+        // 判断是否重复打卡
+        LocalDate today = LocalDate.now();
+        PunchInRecordQuery punchInRecordQuery = new PunchInRecordQuery();
+        punchInRecordQuery.setPunchInIds(Arrays.asList(punchInId));
+        punchInRecordQuery.setStartDate(today.toString());
+        punchInRecordQuery.setEndDate(today.toString());
+        List<PunchInRecord> punchInRecords = punchInRecordService.listByCondition(punchInRecordQuery);
+        if (!CollectionUtils.isEmpty(punchInRecords)) {
+            throw BusinessException.fail("已打卡");
+        }
+
         // 创建打卡记录
         PunchInRecord punchInRecord = new PunchInRecord();
         punchInRecord.setPunchInId(punchInId);

+ 2 - 0
src/main/java/com/punchsettle/server/service/manager/impl/TaskManagerImpl.java

@@ -11,6 +11,7 @@ import java.util.function.Function;
 import java.util.stream.Collectors;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -62,6 +63,7 @@ public class TaskManagerImpl implements ITaskManager {
     private IPunchInRecordSettlementRelaService punchInRecordSettlementRelaService;
 
     @Override
+    @Scheduled(cron = "0 5 0 * * ?")
     @Transactional(rollbackFor = Exception.class)
     public void autoSettle() {
         log.info("结算任务开始");

+ 58 - 0
src/main/java/com/punchsettle/server/service/manager/impl/UserManagerImpl.java

@@ -0,0 +1,58 @@
+package com.punchsettle.server.service.manager.impl;
+
+import java.util.Objects;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.punchsettle.server.atomic.entity.User;
+import com.punchsettle.server.atomic.entity.UserReward;
+import com.punchsettle.server.atomic.service.IUserRewardService;
+import com.punchsettle.server.atomic.service.IUserService;
+import com.punchsettle.server.common.utils.Assert;
+import com.punchsettle.server.service.manager.IUserManager;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * @author tyuio
+ * @version 1.0.0
+ * @description 用户 服务类
+ * @date 2024/11/30 14:28
+ */
+@Slf4j
+@Service
+public class UserManagerImpl implements IUserManager {
+
+    @Autowired
+    private IUserService userService;
+
+    @Autowired
+    private IUserRewardService userRewardService;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public User getAndAddUser(User loginUserInfo) {
+        Assert.isNullInBusiness(loginUserInfo, "传入了空的登录对象");
+        Assert.isNullInBusiness(loginUserInfo.getOpenId(), "传入了空的openId");
+
+        // 获取用户记录
+        User user = userService.getByOpenId(loginUserInfo.getOpenId());
+        if (!Objects.isNull(user)) {
+            return user;
+        }
+
+        // 没有则创建新用户
+        userService.insert(loginUserInfo);
+        // 为新用户创建奖励数据
+        UserReward userReward = new UserReward();
+        userReward.setUserId(loginUserInfo.getId());
+        userReward.setUnclaimedRewardNum(0);
+        userReward.setClaimedRewardNum(0);
+        userReward.setTotalRewardNum(0);
+        userRewardService.insert(userReward);
+
+        return loginUserInfo;
+    }
+}

+ 6 - 0
src/main/resources/application.yaml

@@ -10,6 +10,12 @@ spring:
   cache:
     type: caffeine
 
+jasypt:
+  encryptor:
+    algorithm: PBEWithMD5AndDES
+    salt-generator-classname: org.jasypt.salt.RandomSaltGenerator
+    iv-generator-classname: org.jasypt.iv.RandomIvGenerator
+
 biz:
   wechat:
     mini-program: