Prechádzať zdrojové kódy

益寿缘app新增发送奖励接口

cgp 1 týždeň pred
rodič
commit
44fb85fe3c

+ 23 - 0
fs-service/src/main/java/com/fs/his/domain/FsUserRewards.java

@@ -0,0 +1,23 @@
+package com.fs.his.domain;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 用户活动奖品表实体类
+ */
+@Data
+public class FsUserRewards {
+    private Long id;
+    private Long fsUserId;
+    private String activityType;
+    private Integer rewardType;  // 1-红包 2-积分 3-商品
+    private Integer status;      // 0-待领取 1-已领取 2-已失效
+    private String orderCode;
+    private Long goodsId;        //商品/套餐包id
+    private Integer productType; //1-商品 2-套餐包
+    private Date grantTime;
+    private Date createTime;
+    private Date updateTime;
+}

+ 114 - 0
fs-service/src/main/java/com/fs/his/enums/ActivityTypeEnum.java

@@ -0,0 +1,114 @@
+package com.fs.his.enums;
+
+/**
+ * App用户活动类型枚举
+ * 
+ * @author
+ * @date 2026-02-25
+ */
+public enum ActivityTypeEnum {
+
+    /**
+     * 首次登录奖励
+     */
+    FIRST_LOGIN("FIRST_LOGIN", "首次登录奖励"),
+
+    /**
+     * 看课奖励
+     */
+    WATCH_COURSE("WATCH_COURSE", "看课奖励"),
+
+//    /**
+//     * 邀请好友奖励(预留)
+//     */
+//    INVITE_FRIEND("INVITE_FRIEND", "邀请好友奖励"),
+//
+//    /**
+//     * 签到奖励(预留)
+//     */
+//    SIGN_IN("SIGN_IN", "签到奖励")
+    ;
+
+    /**
+     * 类型编码(对应数据库 activity_type 字段)
+     */
+    private final String code;
+
+    /**
+     * 类型描述
+     */
+    private final String desc;
+
+    /**
+     * 构造函数
+     *
+     * @param code 编码
+     * @param desc 描述
+     */
+    ActivityTypeEnum(String code, String desc) {
+        this.code = code;
+        this.desc = desc;
+    }
+
+    /**
+     * 获取编码
+     *
+     * @return 编码
+     */
+    public String getCode() {
+        return code;
+    }
+
+    /**
+     * 获取描述
+     *
+     * @return 描述
+     */
+    public String getDesc() {
+        return desc;
+    }
+
+    /**
+     * 根据编码获取枚举
+     *
+     * @param code 编码
+     * @return 枚举对象,未找到返回null
+     */
+    public static ActivityTypeEnum getByCode(String code) {
+        if (code == null) {
+            return null;
+        }
+        for (ActivityTypeEnum value : values()) {
+            if (value.getCode().equals(code)) {
+                return value;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 判断编码是否有效
+     *
+     * @param code 编码
+     * @return true-有效 false-无效
+     */
+    public static boolean isValid(String code) {
+        return getByCode(code) != null;
+    }
+
+    /**
+     * 获取描述
+     *
+     * @param code 编码
+     * @return 描述,未找到返回编码本身
+     */
+    public static String getDescByCode(String code) {
+        ActivityTypeEnum enumItem = getByCode(code);
+        return enumItem != null ? enumItem.getDesc() : code;
+    }
+
+    @Override
+    public String toString() {
+        return this.code;
+    }
+}

+ 119 - 0
fs-service/src/main/java/com/fs/his/mapper/FsUserRewardsMapper.java

@@ -0,0 +1,119 @@
+package com.fs.his.mapper;
+
+import com.fs.his.domain.FsUserRewards;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import java.util.List;
+
+/**
+ * 用户活动奖品表 Mapper 接口
+ * 
+ * @author yourname
+ * @date 2026-02-25
+ */
+@Mapper
+public interface FsUserRewardsMapper {
+    
+    /**
+     * 根据ID查询
+     *
+     * @param id 主键ID
+     * @return 用户活动奖品信息
+     */
+    public FsUserRewards selectFsUserRewardsById(Long id);
+    
+    /**
+     * 根据用户ID和活动类型查询
+     *
+     * @param fsUserId 用户ID
+     * @param activityType 活动类型
+     * @return 用户活动奖品信息
+     */
+    public FsUserRewards selectByUserIdAndActivityType(@Param("fsUserId") Long fsUserId, @Param("activityType") String activityType);
+
+    /**
+     * 根据用户ID和奖品id查询
+     *
+     * @param fsUserId 用户ID
+     * @param rewardsId 奖品ID
+     * @return 用户活动奖品信息
+     */
+    public FsUserRewards selectByUserIdAndRewardsId(@Param("fsUserId") Long fsUserId, @Param("rewardsId") Long rewardsId);
+    
+    /**
+     * 查询用户的所有活动记录
+     *
+     * @param fsUserId 用户ID
+     * @return 用户活动奖品列表
+     */
+    public List<FsUserRewards> selectByUserId(Long fsUserId);
+    
+    /**
+     * 查询指定活动的所有用户记录
+     *
+     * @param activityType 活动类型
+     * @return 活动奖品列表
+     */
+    public List<FsUserRewards> selectByActivityType(String activityType);
+    
+    /**
+     * 查询待领取的记录
+     *
+     * @return 待领取列表
+     */
+    public List<FsUserRewards> selectPendingRewards();
+    
+    /**
+     * 查询列表(支持条件查询)
+     *
+     * @param fsUserRewards 查询条件
+     * @return 列表
+     */
+    public List<FsUserRewards> selectFsUserRewardsList(FsUserRewards fsUserRewards);
+    
+    /**
+     * 新增记录
+     *
+     * @param fsUserRewards 用户活动奖品信息
+     * @return 结果
+     */
+    public int insertFsUserRewards(FsUserRewards fsUserRewards);
+    
+    /**
+     * 修改记录
+     *
+     * @param fsUserRewards 用户活动奖品信息
+     * @return 结果
+     */
+    public int updateFsUserRewards(FsUserRewards fsUserRewards);
+    
+    /**
+     * 更新状态(专门用于领取操作)
+     *
+     * @param id 主键ID
+     * @param status 新状态
+     * @param orderCode 订单号(可选)
+     * @param grantTime 发放时间
+     * @return 结果
+     */
+    public int updateStatus(@Param("id") Long id, 
+                           @Param("status") Integer status, 
+                           @Param("orderCode") String orderCode,
+                           @Param("grantTime") java.util.Date grantTime);
+    
+    /**
+     * 删除记录
+     *
+     * @param id 主键ID
+     * @return 结果
+     */
+    public int deleteFsUserRewardsById(Long id);
+    
+    /**
+     * 批量删除
+     *
+     * @param ids 需要删除的数据ID
+     * @return 结果
+     */
+    public int deleteFsUserRewardsByIds(Long[] ids);
+}

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

@@ -0,0 +1,10 @@
+package com.fs.his.service;
+
+public interface IAppUserRewardService {
+    /**
+     * 用户领取奖励
+     * @param fsUserId 用户ID
+     * @param rewardsId 奖品ID
+     * */
+    void claimRewards(Long fsUserId,Long rewardsId);
+}

+ 61 - 0
fs-service/src/main/java/com/fs/his/service/impl/AppUserRewardServiceImpl.java

@@ -0,0 +1,61 @@
+package com.fs.his.service.impl;
+
+import com.fs.common.exception.CustomException;
+import com.fs.his.domain.FsUserRewards;
+import com.fs.his.enums.ActivityTypeEnum;
+import com.fs.his.mapper.FsUserRewardsMapper;
+import com.fs.his.service.IAppUserRewardService;
+import com.fs.his.strategy.RewardResult;
+import com.fs.his.strategy.RewardStrategy;
+import com.fs.his.strategy.RewardStrategyFactory;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+
+@Slf4j
+@Service
+public class AppUserRewardServiceImpl implements IAppUserRewardService {
+
+    @Autowired
+    private FsUserRewardsMapper rewardsMapper;
+
+    @Autowired
+    private RewardStrategyFactory strategyFactory;
+
+    @Override
+    public void claimRewards(Long fsUserId,Long rewardsId) {
+        FsUserRewards reward = rewardsMapper.selectByUserIdAndRewardsId(fsUserId, rewardsId);
+        if (reward==null){
+            log.info("用户:{}没有奖品:{}", fsUserId, rewardsId);
+            return;
+        }
+        // 校验是否过期(目前只有看课奖励需要校验过期)
+        if (ActivityTypeEnum.WATCH_COURSE.getCode().equals(reward.getActivityType())) {
+            if (isExpired(reward.getCreateTime())) {
+                log.info("奖品已过期: rewardId={}", rewardsId);
+                // 更新奖品状态为已过期
+                rewardsMapper.updateStatus(reward.getId(), 2, null, new Date());
+                return;
+            }
+        }
+        //执行奖品发放逻辑
+        RewardStrategy strategy = strategyFactory.getStrategy(reward.getActivityType(), reward.getRewardType());
+        RewardResult result = strategy.process(reward);
+        if (result.isSuccess()) {
+            // 更新奖品状态
+            rewardsMapper.updateStatus(rewardsId, 1, result.getOrderCode(), new Date());
+            log.info("奖品发放成功: rewardId={}, orderCode={}", rewardsId, result.getOrderCode());
+        } else {
+            log.error("奖品发放失败: rewardId={}, reason={}", rewardsId, result.getMessage());
+            throw new CustomException(result.getMessage());
+        }
+    }
+
+    //奖品过期的判断方法
+    private boolean isExpired(Date createTime) {
+        // TODO 实现过期判断逻辑
+        return false;
+    }
+}

+ 55 - 0
fs-service/src/main/java/com/fs/his/strategy/RewardResult.java

@@ -0,0 +1,55 @@
+package com.fs.his.strategy;
+
+import lombok.Data;
+
+/**
+ * 奖品发放结果
+ */
+@Data
+public class RewardResult {
+    /**
+     * 是否成功
+     */
+    private boolean success;
+    
+    /**
+     * 订单号(商品类型使用)
+     */
+    private String orderCode;
+    
+    /**
+     * 发放金额/数量(红包/积分使用)
+     */
+    private Long amount;
+    
+    /**
+     * 结果消息
+     */
+    private String message;
+    
+    /**
+     * 成功静态工厂方法
+     */
+    public static RewardResult success() {
+        RewardResult result = new RewardResult();
+        result.setSuccess(true);
+        return result;
+    }
+    
+    public static RewardResult success(String orderCode) {
+        RewardResult result = new RewardResult();
+        result.setSuccess(true);
+        result.setOrderCode(orderCode);
+        return result;
+    }
+    
+    /**
+     * 失败静态工厂方法
+     */
+    public static RewardResult fail(String message) {
+        RewardResult result = new RewardResult();
+        result.setSuccess(false);
+        result.setMessage(message);
+        return result;
+    }
+}

+ 32 - 0
fs-service/src/main/java/com/fs/his/strategy/RewardStrategy.java

@@ -0,0 +1,32 @@
+package com.fs.his.strategy;
+
+import com.fs.his.domain.FsUserRewards;
+
+/**
+ * App用户奖品策略接口
+ */
+public interface RewardStrategy {
+    /**
+     * 处理奖品发放
+     * @param reward 奖品信息
+     * @return 发放结果
+     */
+    RewardResult process(FsUserRewards reward);
+
+    /**
+     * 获取支持的活动类型
+     */
+    String getActivityType();
+
+    /**
+     * 获取支持的奖品类型
+     */
+    Integer getRewardType();
+
+    /**
+     * 是否支持该奖品发送条件
+     */
+    default boolean support(String activityType, Integer rewardType) {
+        return getActivityType().equals(activityType) && getRewardType().equals(rewardType);
+    }
+}

+ 39 - 0
fs-service/src/main/java/com/fs/his/strategy/RewardStrategyFactory.java

@@ -0,0 +1,39 @@
+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;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+@Slf4j
+@Component
+public class RewardStrategyFactory {
+
+    @Autowired
+    private List<RewardStrategy> strategyList;
+
+    private Map<String, RewardStrategy> strategyMap = new ConcurrentHashMap<>();
+
+    @PostConstruct
+    public void init() {
+        for (RewardStrategy strategy : strategyList) {
+            String key = strategy.getActivityType() + "_" + strategy.getRewardType();
+            strategyMap.put(key, strategy);
+        }
+        log.info("策略工厂初始化完成,共加载 {} 个策略", strategyMap.size());
+    }
+
+    public RewardStrategy getStrategy(String activityType, Integer rewardType) {
+        String key = activityType + "_" + rewardType;
+        RewardStrategy strategy = strategyMap.get(key);
+
+        if (strategy == null) {
+            throw new CustomException("不支持的奖品类型: " + key);
+        }
+        return strategy;
+    }
+}

+ 35 - 0
fs-service/src/main/java/com/fs/his/strategy/impl/FirstLoginPointsStrategy.java

@@ -0,0 +1,35 @@
+package com.fs.his.strategy.impl;
+
+import com.fs.his.domain.FsUserRewards;
+import com.fs.his.enums.ActivityTypeEnum;
+import com.fs.his.strategy.RewardResult;
+import com.fs.his.strategy.RewardStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class FirstLoginPointsStrategy  implements RewardStrategy {
+    @Override
+    public RewardResult process(FsUserRewards reward) {
+        log.info("处理首次登录积分发放: rewardId={}", reward.getId());
+        try {
+            //TODO 调用发送积分逻辑
+            return RewardResult.success();
+
+        } catch (Exception e) {
+            log.error("发送积分失败", e);
+            return RewardResult.fail("发送积分失败:" + e.getMessage());
+        }
+    }
+
+    @Override
+    public String getActivityType() {
+        return ActivityTypeEnum.FIRST_LOGIN.getCode();
+    }
+
+    @Override
+    public Integer getRewardType() {
+        return 2;
+    }
+}

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

@@ -0,0 +1,38 @@
+package com.fs.his.strategy.impl;
+
+import com.fs.his.domain.FsUserRewards;
+import com.fs.his.enums.ActivityTypeEnum;
+import com.fs.his.strategy.RewardResult;
+import com.fs.his.strategy.RewardStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class FirstLoginProductStrategy implements RewardStrategy {
+    @Override
+    public RewardResult process(FsUserRewards reward) {
+        log.info("处理首次登录商品发放: rewardId={}", reward.getId());
+        try {
+            //TODO 调用创建订单逻辑,返回 orderCode
+            String orderCode = "123";
+
+            log.info("商品订单创建成功: orderCode={}", orderCode);
+            return RewardResult.success(orderCode);
+
+        } catch (Exception e) {
+            log.error("商品订单创建失败", e);
+            return RewardResult.fail("订单创建失败:" + e.getMessage());
+        }
+    }
+
+    @Override
+    public String getActivityType() {
+        return ActivityTypeEnum.FIRST_LOGIN.getCode();
+    }
+
+    @Override
+    public Integer getRewardType() {
+        return 3;
+    }
+}

+ 35 - 0
fs-service/src/main/java/com/fs/his/strategy/impl/FirstLoginRedPacketStrategy.java

@@ -0,0 +1,35 @@
+package com.fs.his.strategy.impl;
+
+import com.fs.his.domain.FsUserRewards;
+import com.fs.his.enums.ActivityTypeEnum;
+import com.fs.his.strategy.RewardResult;
+import com.fs.his.strategy.RewardStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class FirstLoginRedPacketStrategy implements RewardStrategy {
+    @Override
+    public RewardResult process(FsUserRewards reward) {
+        log.info("处理首次登录红包发放: rewardId={}", reward.getId());
+        try {
+            //TODO 调用红包接口逻辑
+            return RewardResult.success();
+
+        } catch (Exception e) {
+            return RewardResult.fail("红包发放失败");
+        }
+    }
+
+    @Override
+    public String getActivityType() {
+        return ActivityTypeEnum.FIRST_LOGIN.getCode();
+    }
+
+    @Override
+    public Integer getRewardType() {
+        return 1;
+    }
+
+}

+ 35 - 0
fs-service/src/main/java/com/fs/his/strategy/impl/WatchCoursePointsStrategy.java

@@ -0,0 +1,35 @@
+package com.fs.his.strategy.impl;
+
+import com.fs.his.domain.FsUserRewards;
+import com.fs.his.enums.ActivityTypeEnum;
+import com.fs.his.strategy.RewardResult;
+import com.fs.his.strategy.RewardStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WatchCoursePointsStrategy  implements RewardStrategy {
+    @Override
+    public RewardResult process(FsUserRewards reward) {
+        log.info("处理看课积分发放: rewardId={}", reward.getId());
+        try {
+            //TODO 调用发送积分逻辑
+            return RewardResult.success();
+
+        } catch (Exception e) {
+            log.error("发送积分失败", e);
+            return RewardResult.fail("发送积分失败:" + e.getMessage());
+        }
+    }
+
+    @Override
+    public String getActivityType() {
+        return ActivityTypeEnum.WATCH_COURSE.getCode();
+    }
+
+    @Override
+    public Integer getRewardType() {
+        return 2;
+    }
+}

+ 38 - 0
fs-service/src/main/java/com/fs/his/strategy/impl/WatchCourseProductStrategy.java

@@ -0,0 +1,38 @@
+package com.fs.his.strategy.impl;
+
+import com.fs.his.domain.FsUserRewards;
+import com.fs.his.enums.ActivityTypeEnum;
+import com.fs.his.strategy.RewardResult;
+import com.fs.his.strategy.RewardStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WatchCourseProductStrategy  implements RewardStrategy {
+    @Override
+    public RewardResult process(FsUserRewards reward) {
+        log.info("处理看课商品发放: rewardId={}", reward.getId());
+        try {
+            //TODO 调用创建订单逻辑,返回 orderCode
+            String orderCode = "123";
+
+            log.info("商品订单创建成功: orderCode={}", orderCode);
+            return RewardResult.success(orderCode);
+
+        } catch (Exception e) {
+            log.error("商品订单创建失败", e);
+            return RewardResult.fail("订单创建失败:" + e.getMessage());
+        }
+    }
+
+    @Override
+    public String getActivityType() {
+        return ActivityTypeEnum.WATCH_COURSE.getCode();
+    }
+
+    @Override
+    public Integer getRewardType() {
+        return 3;
+    }
+}

+ 34 - 0
fs-service/src/main/java/com/fs/his/strategy/impl/WatchCourseRedPacketStrategy.java

@@ -0,0 +1,34 @@
+package com.fs.his.strategy.impl;
+
+import com.fs.his.domain.FsUserRewards;
+import com.fs.his.enums.ActivityTypeEnum;
+import com.fs.his.strategy.RewardResult;
+import com.fs.his.strategy.RewardStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WatchCourseRedPacketStrategy implements RewardStrategy {
+    @Override
+    public RewardResult process(FsUserRewards reward) {
+        log.info("处理看课红包发放: rewardId={}", reward.getId());
+        try {
+            //TODO 调用红包接口逻辑
+            return RewardResult.success();
+
+        } catch (Exception e) {
+            return RewardResult.fail("红包发放失败");
+        }
+    }
+
+    @Override
+    public String getActivityType() {
+        return ActivityTypeEnum.WATCH_COURSE.getCode();
+    }
+
+    @Override
+    public Integer getRewardType() {
+        return 2;
+    }
+}

+ 151 - 0
fs-service/src/main/resources/mapper/his/FsUserRewardsMapper.xml

@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fs.his.mapper.FsUserRewardsMapper">
+
+    <resultMap type="com.fs.his.domain.FsUserRewards" id="FsUserRewardsResult">
+        <id property="id" column="id"/>
+        <result property="fsUserId" column="fs_user_id"/>
+        <result property="activityType" column="activity_type"/>
+        <result property="rewardType" column="reward_type"/>
+        <result property="status" column="status"/>
+        <result property="orderCode" column="order_code"/>
+        <result property="goodsId" column="goods_id"/>
+        <result property="productType" column="product_type"/>
+        <result property="grantTime" column="grant_time"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateTime" column="update_time"/>
+    </resultMap>
+
+    <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
+        from fs_user_rewards
+    </sql>
+
+    <!-- 根据ID查询 -->
+    <select id="selectFsUserRewardsById" parameterType="Long" resultMap="FsUserRewardsResult">
+        <include refid="selectFsUserRewardsVo"/>
+        where id = #{id}
+    </select>
+
+    <!-- 根据用户ID和活动类型查询 -->
+    <select id="selectByUserIdAndActivityType" resultMap="FsUserRewardsResult">
+        <include refid="selectFsUserRewardsVo"/>
+        where fs_user_id = #{fsUserId} and activity_type = #{activityType}
+    </select>
+
+    <!-- 根据用户ID和奖品id查询 -->
+    <select id="selectByUserIdAndRewardsId" resultMap="FsUserRewardsResult">
+        <include refid="selectFsUserRewardsVo"/>
+        where id = #{rewardsId} and fs_user_id = #{fsUserId}
+    </select>
+
+    <!-- 查询用户的所有活动记录 -->
+    <select id="selectByUserId" parameterType="Long" resultMap="FsUserRewardsResult">
+        <include refid="selectFsUserRewardsVo"/>
+        where fs_user_id = #{fsUserId}
+        order by create_time desc
+    </select>
+
+    <!-- 查询指定活动的所有用户记录 -->
+    <select id="selectByActivityType" parameterType="String" resultMap="FsUserRewardsResult">
+        <include refid="selectFsUserRewardsVo"/>
+        where activity_type = #{activityType}
+        order by create_time desc
+    </select>
+
+    <!-- 查询待领取的记录 -->
+    <select id="selectPendingRewards" resultMap="FsUserRewardsResult">
+        <include refid="selectFsUserRewardsVo"/>
+        where status = 0
+        order by create_time asc
+    </select>
+
+    <!-- 更新条件查询列表 -->
+    <select id="selectFsUserRewardsList" parameterType="com.fs.his.domain.FsUserRewards" resultMap="FsUserRewardsResult">
+        <include refid="selectFsUserRewardsVo"/>
+        <where>
+            <if test="fsUserId != null"> and fs_user_id = #{fsUserId}</if>
+            <if test="activityType != null and activityType != ''"> and activity_type = #{activityType}</if>
+            <if test="rewardType != null"> and reward_type = #{rewardType}</if>
+            <if test="status != null"> and status = #{status}</if>
+            <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="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>
+        </where>
+        order by create_time desc
+    </select>
+
+    <!-- 更新新增记录 -->
+    <insert id="insertFsUserRewards" parameterType="com.fs.his.domain.FsUserRewards" useGeneratedKeys="true" keyProperty="id">
+        insert into fs_user_rewards
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="fsUserId != null">fs_user_id,</if>
+            <if test="activityType != null">activity_type,</if>
+            <if test="rewardType != null">reward_type,</if>
+            <if test="status != null">status,</if>
+            <if test="orderCode != null">order_code,</if>
+            <if test="goodsId != null">goods_id,</if>
+            <if test="productType != null">product_type,</if>
+            <if test="grantTime != null">grant_time,</if>
+            create_time,
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="fsUserId != null">#{fsUserId},</if>
+            <if test="activityType != null">#{activityType},</if>
+            <if test="rewardType != null">#{rewardType},</if>
+            <if test="status != null">#{status},</if>
+            <if test="orderCode != null">#{orderCode},</if>
+            <if test="goodsId != null">#{goodsId},</if>
+            <if test="productType != null">#{productType},</if>
+            <if test="grantTime != null">#{grantTime},</if>
+            sysdate(),
+        </trim>
+    </insert>
+
+    <!-- 更新修改记录 -->
+    <update id="updateFsUserRewards" parameterType="com.fs.his.domain.FsUserRewards">
+        update fs_user_rewards
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="fsUserId != null">fs_user_id = #{fsUserId},</if>
+            <if test="activityType != null">activity_type = #{activityType},</if>
+            <if test="rewardType != null">reward_type = #{rewardType},</if>
+            <if test="status != null">status = #{status},</if>
+            <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="grantTime != null">grant_time = #{grantTime},</if>
+            update_time = sysdate()
+        </trim>
+        where id = #{id}
+    </update>
+
+    <!-- 更新状态方法 -->
+    <update id="updateStatus">
+        update fs_user_rewards
+        set status = #{status},
+            order_code = #{orderCode},
+            grant_time = #{grantTime},
+            update_time = sysdate()
+        where id = #{id}
+    </update>
+
+    <!-- 删除记录 -->
+    <delete id="deleteFsUserRewardsById" parameterType="Long">
+        delete from fs_user_rewards where id = #{id}
+    </delete>
+
+    <!-- 批量删除-->
+    <delete id="deleteFsUserRewardsByIds" parameterType="String">
+        delete from fs_user_rewards where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+
+</mapper>

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

@@ -0,0 +1,37 @@
+package com.fs.app.controller;
+
+import com.fs.app.annotation.Login;
+import com.fs.common.core.domain.R;
+import com.fs.common.utils.StringUtils;
+import com.fs.his.service.IAppUserRewardService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+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.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api("App用户奖励")
+@RestController
+@RequestMapping(value="/app/reward")
+public class AppUserRewardController  extends AppBaseController{
+
+    @Autowired
+    private IAppUserRewardService appUserRewardService;
+
+    /**
+     * 领取奖励
+     */
+    @Login
+    @ApiOperation("用户领取奖励")
+    @GetMapping("/claim")
+    public R claimRewards(@RequestParam("rewardsId") Long rewardsId) {
+        String loginUserId = getUserId();
+        if (StringUtils.isEmpty(loginUserId)){
+            return R.error("请登录");
+        }
+        appUserRewardService.claimRewards(Long.valueOf(loginUserId),rewardsId);
+        return R.ok();
+    }
+}