Forráskód Böngészése

益寿缘app-优化奖品接口

cgp 1 hete
szülő
commit
fbde5afc2e

+ 62 - 8
fs-service/src/main/java/com/fs/his/domain/FsUserRewards.java

@@ -1,7 +1,7 @@
 package com.fs.his.domain;
 
 import lombok.Data;
-
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
@@ -9,16 +9,70 @@ import java.util.Date;
  */
 @Data
 public class FsUserRewards {
+    /**
+     * 主键ID
+     */
     private Long id;
+
+    /**
+     * 用户ID
+     */
     private Long fsUserId;
-    private String activityType; //活动类型:FIRST_LOGIN-首次登录,WATCH_COURSE-看课
-    private Integer rewardType;  //奖品类型: 1-红包 2-积分 3-商品
-    private Integer status;      //奖品状态: 0-待领取 1-已领取 2-已失效
+
+    /**
+     * 活动类型:FIRST_LOGIN-首次登录,WATCH_COURSE-看课
+     */
+    private String activityType;
+
+    /**
+     * 奖品类型: 1-红包 2-积分 3-商品
+     */
+    private Integer rewardType;
+
+    /**
+     * 奖品状态: 0-待领取 1-已领取 2-已失效
+     */
+    private Integer status;
+
+    /**
+     * 订单号
+     */
     private String orderCode;
-    private Integer productType; //产品类型: 1-药品 2-套餐包
-    private Long goodsId;        //产品id: 药品/套餐包id
-    private Date grantTime;      //奖品实际领取时间
+
+    /**
+     * 产品类型: 1-药品 2-套餐包
+     */
+    private Integer productType;
+
+    /**
+     * 产品id: 药品/套餐包id
+     */
+    private Long goodsId;
+
+    /**
+     * 新增:奖励金额/数量
+     * 红包:金额(元),可含小数
+     * 积分:数量(分),整数
+     */
+    private BigDecimal rewardAmount;
+
+    /**
+     * 奖品实际领取时间
+     */
+    private Date grantTime;
+
+    /**
+     * 创建时间
+     */
     private Date createTime;
+
+    /**
+     * 更新时间
+     */
     private Date updateTime;
-    private Integer isFirstLogin; //是否是首次注册奖励:0-否 1-是
+
+    /**
+     * 是否是首次注册奖励:0-否 1-是
+     */
+    private Integer isFirstLogin;
 }

+ 1 - 0
fs-service/src/main/java/com/fs/his/service/IAppUserRewardService.java

@@ -25,6 +25,7 @@ public interface IAppUserRewardService {
      * @return 奖励列表
      * */
     public List<FsUserRewards> getMyRewardList(FsUserRewards fsUserRewards);
+
     /**
      * 用户领取奖励
      * @param fsUserId 用户ID

+ 41 - 15
fs-service/src/main/java/com/fs/his/service/impl/AppUserRewardServiceImpl.java

@@ -19,6 +19,7 @@ import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -62,10 +63,11 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
 
         // TODO 根据配置获取奖品类型
         Integer rewardType = RandomUtil.randomInt(1, 4);
-
+        Integer productType=1;
+        Long goodsId=1L;
+        BigDecimal rewardAmount=new BigDecimal("10");
         // 构建奖品记录
-        FsUserRewards reward = buildFirstLoginReward(fsUserId, activityType, rewardType);
-
+        FsUserRewards reward = buildFirstLoginReward(fsUserId, activityType, rewardType, productType, goodsId, rewardAmount);
         try {
             // 插入奖品表
             int insertResult = rewardsMapper.insertFsUserRewards(reward);
@@ -101,29 +103,53 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
         return fsUserRewardsList;
     }
 
-    private FsUserRewards buildFirstLoginReward(Long fsUserId, String activityType, Integer rewardType) {
+    /**
+     * @param fsUserId 用户ID
+     * @param activityType 活动类型
+     * @param rewardType 奖品类型
+     * @param productType  产品类型 1-药品 2-套餐包
+     * @param goodsId  1-红包 2-积分 3-商品
+     * @param rewardAmount 红包或积分金额
+     * */
+    private FsUserRewards buildFirstLoginReward(Long fsUserId, String activityType, Integer rewardType, Integer productType, Long goodsId,BigDecimal rewardAmount) {
         FsUserRewards reward = new FsUserRewards();
         reward.setFsUserId(fsUserId);
         reward.setActivityType(activityType);
         reward.setRewardType(rewardType);
         reward.setStatus(0); // 待领取
         reward.setCreateTime(DateUtils.getNowDate());
-        reward.setIsFirstLogin(1); // 标记为首次注册奖励(用于虚拟列索引)
-
-        if (rewardType == 3) {
-            // TODO 根据配置设置具体的商品
-            reward.setProductType(1); // 1-药品
-            reward.setGoodsId(1L);    // 默认商品ID
+        if (ActivityTypeEnum.FIRST_LOGIN.getCode().equals(activityType)){
+            reward.setIsFirstLogin(1); // 标记为首次注册奖励(用于虚拟列索引),首次登录奖励 必传1!!!
+        }
+        if (rewardType == 3){//实物商品类型
+            reward.setProductType(productType); // 1-药品 2-套餐包
+            reward.setGoodsId(goodsId);    // 药品/套餐包id
+        }else {
+            reward.setRewardAmount(rewardAmount);//红包或积分
         }
-
         return reward;
     }
 
-    //为当前用户新增看课奖励
+    //为当前用户新增看课类型的奖励
+    @Transactional(rollbackFor = Exception.class)
     public void addUserWatchCourseRewards(Long fsUserId) {
-        //看课奖励可以有多个
-
-        //TODO 根据用户id从配置获取用户领取奖品类型、产品类型是
+        String activityType = ActivityTypeEnum.WATCH_COURSE.getCode();
+        // TODO 根据配置获取奖品类型、金额等
+        Integer rewardType = RandomUtil.randomInt(1, 4);
+        Integer productType=1;
+        Long goodsId=1L;
+        BigDecimal rewardAmount=new BigDecimal("10");
+        // 构建奖品记录
+        FsUserRewards reward = buildFirstLoginReward(fsUserId, activityType, rewardType, productType, goodsId, rewardAmount);
+        // 插入奖品表
+        int insertResult = rewardsMapper.insertFsUserRewards(reward);
+        if (insertResult > 0) {
+            log.info("用户看课奖励发放成功: userId={}, rewardType={}, rewardsId={}",
+                    fsUserId, rewardType, reward.getId());
+        } else {
+            log.error("用户看课奖励发放失败: userId={}, 但奖品已发放, rewardsId={}",
+                    fsUserId, reward.getId());
+        }
     }
 
     @Override

+ 1 - 2
fs-service/src/main/java/com/fs/his/strategy/RewardStrategyFactory.java

@@ -1,6 +1,5 @@
 package com.fs.his.strategy;
 
-import com.fs.common.exception.CustomException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -32,7 +31,7 @@ public class RewardStrategyFactory {
         RewardStrategy strategy = strategyMap.get(key);
 
         if (strategy == null) {
-            throw new CustomException("不支持的奖品类型: " + key);
+            log.error("不支持的奖品类型: {}", key);
         }
         return strategy;
     }

+ 1 - 1
fs-service/src/main/java/com/fs/his/strategy/impl/FirstLoginProductStrategy.java

@@ -14,7 +14,7 @@ public class FirstLoginProductStrategy implements RewardStrategy {
     public RewardResult process(FsUserRewards reward) {
         log.info("处理首次登录商品发放: rewardId={}", reward.getId());
         try {
-            //TODO 调用创建订单逻辑,返回 orderCode
+            //TODO 调用创建0元订单逻辑,返回 orderCode
             String orderCode = "123";
 
             log.info("商品订单创建成功: orderCode={}", orderCode);

+ 17 - 5
fs-service/src/main/resources/mapper/his/FsUserRewardsMapper.xml

@@ -13,14 +13,18 @@
         <result property="orderCode" column="order_code"/>
         <result property="goodsId" column="goods_id"/>
         <result property="productType" column="product_type"/>
+        <result property="rewardAmount" column="reward_amount"/>
         <result property="grantTime" column="grant_time"/>
         <result property="createTime" column="create_time"/>
         <result property="updateTime" column="update_time"/>
+        <result property="isFirstLogin" column="is_first_login"/>
     </resultMap>
 
+    <!-- 基础字段列表 - 添加 reward_amount 和 is_first_login -->
     <sql id="selectFsUserRewardsVo">
         select id, fs_user_id, activity_type, reward_type, status,
-               order_code, goods_id, product_type, grant_time, create_time, update_time
+               order_code, goods_id, product_type, reward_amount,
+               grant_time, create_time, update_time, is_first_login
         from fs_user_rewards
     </sql>
 
@@ -74,9 +78,11 @@
             <if test="orderCode != null and orderCode != ''"> and order_code = #{orderCode}</if>
             <if test="goodsId != null"> and goods_id = #{goodsId}</if>
             <if test="productType != null"> and product_type = #{productType}</if>
+            <if test="rewardAmount != null"> and reward_amount = #{rewardAmount}</if>
             <if test="grantTime != null"> and grant_time = #{grantTime}</if>
             <if test="createTime != null"> and create_time = #{createTime}</if>
             <if test="updateTime != null"> and update_time = #{updateTime}</if>
+            <if test="isFirstLogin != null"> and is_first_login = #{isFirstLogin}</if>
         </where>
         order by create_time desc
     </select>
@@ -92,7 +98,9 @@
             <if test="orderCode != null">order_code,</if>
             <if test="goodsId != null">goods_id,</if>
             <if test="productType != null">product_type,</if>
+            <if test="rewardAmount != null">reward_amount,</if>
             <if test="grantTime != null">grant_time,</if>
+            <if test="isFirstLogin != null">is_first_login,</if>
             create_time,
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -103,12 +111,14 @@
             <if test="orderCode != null">#{orderCode},</if>
             <if test="goodsId != null">#{goodsId},</if>
             <if test="productType != null">#{productType},</if>
+            <if test="rewardAmount != null">#{rewardAmount},</if>
             <if test="grantTime != null">#{grantTime},</if>
+            <if test="isFirstLogin != null">#{isFirstLogin},</if>
             sysdate(),
         </trim>
     </insert>
 
-    <!-- 修改记录 -->
+    <!-- 修改记录-->
     <update id="updateFsUserRewards" parameterType="com.fs.his.domain.FsUserRewards">
         update fs_user_rewards
         <trim prefix="SET" suffixOverrides=",">
@@ -119,7 +129,9 @@
             <if test="orderCode != null">order_code = #{orderCode},</if>
             <if test="goodsId != null">goods_id = #{goodsId},</if>
             <if test="productType != null">product_type = #{productType},</if>
+            <if test="rewardAmount != null">reward_amount = #{rewardAmount},</if>
             <if test="grantTime != null">grant_time = #{grantTime},</if>
+            <if test="isFirstLogin != null">is_first_login = #{isFirstLogin},</if>
             update_time = sysdate()
         </trim>
         where id = #{id}
@@ -129,9 +141,9 @@
     <update id="updateStatus">
         update fs_user_rewards
         set status = #{status},
-        <if test="orderCode != null">order_code = #{orderCode},</if>
-            grant_time = #{grantTime},
-            update_time = sysdate()
+        <if test="orderCode != null and orderCode != ''">order_code = #{orderCode},</if>
+        grant_time = #{grantTime},
+        update_time = sysdate()
         where id = #{id}
     </update>
 

+ 0 - 1
fs-user-app/src/main/java/com/fs/app/controller/AppUserRewardController.java

@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.*;
-import java.util.stream.Collectors;
 
 @Api("App用户奖励")
 @RestController