yujian
2019-08-12 6d44a9cdd5b2549a392516b25f2d1068c9aaf984
积分兑换
1个文件已修改
13个文件已添加
969 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/integral/IntegralExchangeMapper.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/integral/IntegralExchangeRecordMapper.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/integral/IntegralExchange.java 211 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/integral/IntegralExchangeRecord.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/integral/IntegralExchangeException.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/integral/IntegralExchangeMapper.xml 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/integral/IntegralExchangeRecordMapper.xml 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeRecordServiceImpl.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java 154 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/integral/IntegralExchangeRecordService.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/integral/IntegralExchangeService.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/mybatishandler/integral/ExchangeTypeEnumHandler.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/vo/integral/ExchangeTipVO.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java
@@ -19,17 +19,22 @@
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserRank;
import com.yeshi.fanli.entity.integral.IntegralExchange;
import com.yeshi.fanli.entity.integral.IntegralTaskClass;
import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum;
import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
import com.yeshi.fanli.exception.integral.IntegralExchangeException;
import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.vo.integral.DailySignVO;
import com.yeshi.fanli.vo.integral.ExchangeTipVO;
import com.yeshi.fanli.vo.integral.IntegralTaskClassVO;
import com.yeshi.fanli.vo.user.UserInfoExtraVO;
@@ -51,6 +56,11 @@
    @Resource
    private IntegralTaskRecordService integralTaskRecordService;
     
    @Resource
    private IntegralExchangeService integralExchangeService;
    @Resource
    private IntegralExchangeRecordService integralExchangeRecordService;
    /**
     * 获取任务列表
@@ -181,4 +191,92 @@
        }
    }
    
    /**
     *  金币兑换列表
     * @param acceptData
     * @param uid
     * @param ids
     * @param out
     */
    @RequestMapping(value = "getExchangeList", method = RequestMethod.POST)
    public void getExchangeList(AcceptData acceptData, Long uid, Integer page, PrintWriter out) {
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
        if (page == null || page < 1) {
            out.print(JsonUtil.loadFalseResult(1, "页码不正确"));
            return;
        }
        UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
        if (extraVO == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户相关信息不存在"));
            return;
        }
        List<IntegralExchange> list = integralExchangeRecordService.listExchange((page - 1) * Constant.PAGE_SIZE,
                Constant.PAGE_SIZE, uid);
        if (list == null)
            list = new ArrayList<IntegralExchange>();
        Long count = integralExchangeService.countValid();
        GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
        Gson gson = gsonBuilder.create();
        JSONObject data = new JSONObject();
        data.put("goldCoin", extraVO.getGoldCoin());
        data.put("count", count);
        data.put("list", gson.toJson(list));
        out.print(JsonUtil.loadTrueResult(data));
    }
    /**
     * 兑换金币检验
     * @param acceptData
     * @param uid
     * @param id
     * @param out
     */
    @RequestMapping(value = "verifyExchange", method = RequestMethod.POST)
    public void verifyExchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
        try {
            ExchangeTipVO exchange = integralExchangeService.verifyExchange(uid, id);
            GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
            Gson gson = gsonBuilder.create();
            JSONObject data = new JSONObject();
            data.put("result", gson.toJson(exchange));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (IntegralExchangeException e) {
            e.printStackTrace();
        }
    }
    /**
     * 兑换金币
     * @param acceptData
     * @param uid
     * @param id
     * @param out
     */
    @RequestMapping(value = "exchange", method = RequestMethod.POST)
    public void exchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
        try {
            ExchangeTipVO exchange = integralExchangeService.verifyExchange(uid, id);
            GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
            Gson gson = gsonBuilder.create();
            JSONObject data = new JSONObject();
            data.put("result", gson.toJson(exchange));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (IntegralExchangeException e) {
            e.printStackTrace();
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/integral/IntegralExchangeMapper.java
New file
@@ -0,0 +1,18 @@
package com.yeshi.fanli.dao.mybatis.integral;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.integral.IntegralExchange;
public interface IntegralExchangeMapper extends BaseMapper<IntegralExchange> {
    /**
     * 查询有效兑换
     */
    List<IntegralExchange> listValid(@Param("start") long start, @Param("count") int count);
    Long countValid();
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/integral/IntegralExchangeRecordMapper.java
New file
@@ -0,0 +1,19 @@
package com.yeshi.fanli.dao.mybatis.integral;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.integral.IntegralExchangeRecord;
public interface IntegralExchangeRecordMapper extends BaseMapper<IntegralExchangeRecord> {
    /**
     * 查询今日兑换情况
     * @param list
     * @return
     */
    List<Long> listRecordByExchangeIds(@Param("list") List<Long> list);
}
fanli/src/main/java/com/yeshi/fanli/entity/integral/IntegralExchange.java
New file
@@ -0,0 +1,211 @@
package com.yeshi.fanli.entity.integral;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
import com.google.gson.annotations.Expose;
/**
 * 积分兑换
 *
 * @author Administrator
 *
 */
@Table("yeshi_ec_integral_exchange")
public class IntegralExchange implements Serializable {
    private static final long serialVersionUID = 1L;
    public enum ExchangeTypeEnum {
        freeCouponBuy("自购免单券"), freeCouponGive("赠送免单券"), rebateCoupon("返利奖励券"), inviteCodeActivate("邀请码激活卡"),
        inviteCodePublish("邀请码发布卡"), taoLiJin("推广红包"), cash("现金红包");
        private final String desc;
        private ExchangeTypeEnum(String desc) {
            this.desc = desc;
        }
        public String getDesc() {
            return desc;
        }
    }
    @Expose
    @Column(name = "ex_id")
    private Long id;
    @Expose
    @Column(name = "ex_name")
    private String name;// 名称
    @Expose
    @Column(name = "ex_picture")
    private String picture; // 图片
    @Expose
    @Column(name = "ex_gold_coin")
    private Integer goldCoin; // 兑换数量
    @Expose
    @Column(name = "ex_tip")
    private String tip; // 提示
    @Expose
    @Column(name = "ex_btn_name")
    private String btnName; // 按钮名称
    @Expose
    @Column(name = "ex_amount")
    private BigDecimal amount; // 面额: 推广红包、现金红包
    @Column(name = "ex_upper_limit")
    private Integer upperLimit; // 上限
    @Expose
    @Column(name = "ex_rule_link")
    private String ruleLink; // 规则链接
    @Column(name = "ex_orderby")
    private Integer orderby; // 排序
    @Expose
    @Column(name = "ex_type")
    private ExchangeTypeEnum type; // 类型
    @Expose
    @Column(name = "ex_progress")
    private String progress; // 兑换情况
    @Column(name = "ex_state")
    private Integer state; // 状态: 1启用 0停用
    @Column(name = "ex_create_time")
    private Date createTime;
    @Column(name = "ex_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPicture() {
        return picture;
    }
    public void setPicture(String picture) {
        this.picture = picture;
    }
    public Integer getGoldCoin() {
        return goldCoin;
    }
    public void setGoldCoin(Integer goldCoin) {
        this.goldCoin = goldCoin;
    }
    public String getTip() {
        return tip;
    }
    public void setTip(String tip) {
        this.tip = tip;
    }
    public BigDecimal getAmount() {
        return amount;
    }
    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }
    public Integer getUpperLimit() {
        return upperLimit;
    }
    public void setUpperLimit(Integer upperLimit) {
        this.upperLimit = upperLimit;
    }
    public String getRuleLink() {
        return ruleLink;
    }
    public void setRuleLink(String ruleLink) {
        this.ruleLink = ruleLink;
    }
    public ExchangeTypeEnum getType() {
        return type;
    }
    public void setType(ExchangeTypeEnum type) {
        this.type = type;
    }
    public Integer getState() {
        return state;
    }
    public void setState(Integer state) {
        this.state = state;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public Integer getOrderby() {
        return orderby;
    }
    public void setOrderby(Integer orderby) {
        this.orderby = orderby;
    }
    public String getBtnName() {
        return btnName;
    }
    public void setBtnName(String btnName) {
        this.btnName = btnName;
    }
    public String getProgress() {
        return progress;
    }
    public void setProgress(String progress) {
        this.progress = progress;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/integral/IntegralExchangeRecord.java
New file
@@ -0,0 +1,63 @@
package com.yeshi.fanli.entity.integral;
import java.io.Serializable;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
/**
 * 积分兑换记录
 *
 * @author Administrator
 *
 */
@Table("yeshi_ec_integral_exchange_record")
public class IntegralExchangeRecord implements Serializable {
    private static final long serialVersionUID = 1L;
    @Column(name = "er_id")
    private Long id;
    @Column(name = "er_uid")
    private Long uid;
    @Column(name = "er_exchange_id")
    private Long exchangeId;
    @Column(name = "er_create_time")
    private Date createTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public Long getExchangeId() {
        return exchangeId;
    }
    public void setExchangeId(Long exchangeId) {
        this.exchangeId = exchangeId;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}
fanli/src/main/java/com/yeshi/fanli/exception/integral/IntegralExchangeException.java
New file
@@ -0,0 +1,32 @@
package com.yeshi.fanli.exception.integral;
public class IntegralExchangeException extends Exception {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    public int getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
    public IntegralExchangeException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public IntegralExchangeException() {
    }
    @Override
    public String getMessage() {
        return this.msg;
    }
}
fanli/src/main/java/com/yeshi/fanli/mapping/integral/IntegralExchangeMapper.xml
New file
@@ -0,0 +1,95 @@
<?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.yeshi.fanli.dao.mybatis.integral.IntegralExchangeMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.integral.IntegralExchange">
    <id column="ex_id" property="id" jdbcType="BIGINT"/>
    <result column="ex_name" property="name" jdbcType="VARCHAR"/>
    <result column="ex_picture" property="picture" jdbcType="VARCHAR"/>
    <result column="ex_gold_coin" property="goldCoin" jdbcType="INTEGER"/>
    <result column="ex_tip" property="tip" jdbcType="VARCHAR"/>
    <result column="ex_btn_name" property="btnName" jdbcType="VARCHAR"/>
    <result column="ex_amount" property="amount" jdbcType="DECIMAL"/>
    <result column="ex_upper_limit" property="upperLimit" jdbcType="INTEGER"/>
    <result column="ex_rule_link" property="ruleLink" jdbcType="VARCHAR"/>
    <result column="ex_orderby" property="orderby" jdbcType="INTEGER"/>
    <result column="ex_progress" property="progress" jdbcType="VARCHAR"/>
    <result column="ex_state" property="state" jdbcType="INTEGER"/>
    <result column="ex_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="ex_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    <result column="ex_type" property="type" typeHandler="com.yeshi.fanli.util.mybatishandler.integral.ExchangeTypeEnumHandler"/>
  </resultMap>
  <sql id="Base_Column_List">ex_id,ex_name,ex_picture,ex_gold_coin,ex_tip,ex_btn_name,ex_amount,ex_upper_limit,ex_rule_link,ex_orderby,ex_type,ex_progress,ex_state,ex_create_time,ex_update_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_integral_exchange where ex_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_integral_exchange where ex_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.integral.IntegralExchange" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_integral_exchange (ex_id,ex_name,ex_picture,ex_gold_coin,ex_tip,ex_btn_name,ex_amount,ex_upper_limit,ex_rule_link,ex_orderby,ex_type,ex_progress,ex_state,ex_create_time,ex_update_time) values (#{id,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{picture,jdbcType=VARCHAR},#{goldCoin,jdbcType=INTEGER},#{tip,jdbcType=VARCHAR},#{btnName,jdbcType=VARCHAR},#{amount,jdbcType=DECIMAL},#{upperLimit,jdbcType=INTEGER},#{ruleLink,jdbcType=VARCHAR},#{orderby,jdbcType=INTEGER},#{type,jdbcType=VARCHAR},#{progress,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.integral.IntegralExchange" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_integral_exchange
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">ex_id,</if>
      <if test="name != null">ex_name,</if>
      <if test="picture != null">ex_picture,</if>
      <if test="goldCoin != null">ex_gold_coin,</if>
      <if test="tip != null">ex_tip,</if>
      <if test="btnName != null">ex_btn_name,</if>
      <if test="amount != null">ex_amount,</if>
      <if test="upperLimit != null">ex_upper_limit,</if>
      <if test="ruleLink != null">ex_rule_link,</if>
      <if test="orderby != null">ex_orderby,</if>
      <if test="type != null">ex_type,</if>
      <if test="progress != null">ex_progress,</if>
      <if test="state != null">ex_state,</if>
      <if test="createTime != null">ex_create_time,</if>
      <if test="updateTime != null">ex_update_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="name != null">#{name,jdbcType=VARCHAR},</if>
      <if test="picture != null">#{picture,jdbcType=VARCHAR},</if>
      <if test="goldCoin != null">#{goldCoin,jdbcType=INTEGER},</if>
      <if test="tip != null">#{tip,jdbcType=VARCHAR},</if>
      <if test="btnName != null">#{btnName,jdbcType=VARCHAR},</if>
      <if test="amount != null">#{amount,jdbcType=DECIMAL},</if>
      <if test="upperLimit != null">#{upperLimit,jdbcType=INTEGER},</if>
      <if test="ruleLink != null">#{ruleLink,jdbcType=VARCHAR},</if>
      <if test="orderby != null">#{orderby,jdbcType=INTEGER},</if>
      <if test="type != null">#{type,jdbcType=VARCHAR},</if>
      <if test="progress != null">#{progress,jdbcType=VARCHAR},</if>
      <if test="state != null">#{state,jdbcType=INTEGER},</if>
      <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.integral.IntegralExchange">update yeshi_ec_integral_exchange set ex_name = #{name,jdbcType=VARCHAR},ex_picture = #{picture,jdbcType=VARCHAR},ex_gold_coin = #{goldCoin,jdbcType=INTEGER},ex_tip = #{tip,jdbcType=VARCHAR},ex_btn_name = #{btnName,jdbcType=VARCHAR},ex_amount = #{amount,jdbcType=DECIMAL},ex_upper_limit = #{upperLimit,jdbcType=INTEGER},ex_rule_link = #{ruleLink,jdbcType=VARCHAR},ex_orderby = #{orderby,jdbcType=INTEGER},ex_type = #{type,jdbcType=VARCHAR},ex_progress = #{progress,jdbcType=VARCHAR},ex_state = #{state,jdbcType=INTEGER},ex_create_time = #{createTime,jdbcType=TIMESTAMP},ex_update_time = #{updateTime,jdbcType=TIMESTAMP} where ex_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.integral.IntegralExchange">update yeshi_ec_integral_exchange
    <set>
      <if test="name != null">ex_name=#{name,jdbcType=VARCHAR},</if>
      <if test="picture != null">ex_picture=#{picture,jdbcType=VARCHAR},</if>
      <if test="goldCoin != null">ex_gold_coin=#{goldCoin,jdbcType=INTEGER},</if>
      <if test="tip != null">ex_tip=#{tip,jdbcType=VARCHAR},</if>
      <if test="btnName != null">ex_btn_name=#{btnName,jdbcType=VARCHAR},</if>
      <if test="amount != null">ex_amount=#{amount,jdbcType=DECIMAL},</if>
      <if test="upperLimit != null">ex_upper_limit=#{upperLimit,jdbcType=INTEGER},</if>
      <if test="ruleLink != null">ex_rule_link=#{ruleLink,jdbcType=VARCHAR},</if>
      <if test="orderby != null">ex_orderby=#{orderby,jdbcType=INTEGER},</if>
      <if test="type != null">ex_type=#{type,jdbcType=VARCHAR},</if>
      <if test="progress != null">ex_progress=#{progress,jdbcType=VARCHAR},</if>
      <if test="state != null">ex_state=#{state,jdbcType=INTEGER},</if>
      <if test="createTime != null">ex_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">ex_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
    </set> where ex_id = #{id,jdbcType=BIGINT}
  </update>
  <select id="listValid" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_integral_exchange
    WHERE ex_state = 1
    ORDER BY ex_orderby
    LIMIT #{start},#{count}
  </select>
  <select id="countValid" resultType="Long">
      SELECT IFNULL(COUNT(ex_id),0) FROM yeshi_ec_integral_exchange
    WHERE ex_state = 1
  </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/integral/IntegralExchangeRecordMapper.xml
New file
@@ -0,0 +1,45 @@
<?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.yeshi.fanli.dao.mybatis.integral.IntegralExchangeRecordMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.integral.IntegralExchangeRecord">
    <id column="er_id" property="id" jdbcType="BIGINT"/>
    <result column="er_uid" property="uid" jdbcType="BIGINT"/>
    <result column="er_exchange_id" property="exchangeId" jdbcType="BIGINT"/>
    <result column="er_create_time" property="createTime" jdbcType="TIMESTAMP"/>
  </resultMap>
  <sql id="Base_Column_List">er_id,er_uid,er_exchange_id,er_create_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_integral_exchange_record where er_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_integral_exchange_record where er_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.integral.IntegralExchangeRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_integral_exchange_record (er_id,er_uid,er_exchange_id,er_create_time) values (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{exchangeId,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.integral.IntegralExchangeRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_integral_exchange_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">er_id,</if>
      <if test="uid != null">er_uid,</if>
      <if test="exchangeId != null">er_exchange_id,</if>
      <if test="createTime != null">er_create_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
      <if test="exchangeId != null">#{exchangeId,jdbcType=BIGINT},</if>
      <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.integral.IntegralExchangeRecord">update yeshi_ec_integral_exchange_record set er_uid = #{uid,jdbcType=BIGINT},er_exchange_id = #{exchangeId,jdbcType=BIGINT},er_create_time = #{createTime,jdbcType=TIMESTAMP} where er_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.integral.IntegralExchangeRecord">update yeshi_ec_integral_exchange_record
    <set>
      <if test="uid != null">er_uid=#{uid,jdbcType=BIGINT},</if>
      <if test="exchangeId != null">er_exchange_id=#{exchangeId,jdbcType=BIGINT},</if>
      <if test="createTime != null">er_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
    </set> where er_id = #{id,jdbcType=BIGINT}
  </update>
  <select id="listRecordByExchangeIds" resultType="Long">
      SELECT er_exchange_id FROM yeshi_ec_integral_exchange_record
    WHERE er_uid = 1 AND TO_DAYS(er_create_time) = TO_DAYS(NOW())
         AND er_exchange_id in <foreach collection="list" item="item" open="(" separator="," close=")">#{item}</foreach>
  </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeRecordServiceImpl.java
New file
@@ -0,0 +1,54 @@
package com.yeshi.fanli.service.impl.integral;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.yeshi.utils.JsonUtil;
import com.yeshi.fanli.dao.mybatis.integral.IntegralExchangeRecordMapper;
import com.yeshi.fanli.entity.integral.IntegralExchange;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.vo.user.UserInfoExtraVO;
@Service
public class IntegralExchangeRecordServiceImpl implements IntegralExchangeRecordService {
    @Resource
    private IntegralExchangeRecordMapper integralExchangeRecordMapper;
    @Resource
    private IntegralExchangeService integralExchangeService;
    @Override
    public List<IntegralExchange> listExchange(long start, int count, Long uid){
        List<IntegralExchange> listValid = integralExchangeService.listValidCache(start, count);
        if (listValid == null || listValid.size() == 0) {
            return listValid;
        }
        List<Long> listId = new ArrayList<Long>();
        for(IntegralExchange integralExchange: listValid) {
            listId.add(integralExchange.getId());
        }
        List<Long> listRecord = integralExchangeRecordMapper.listRecordByExchangeIds(listId);
        for(IntegralExchange integralExchange: listValid) {
            String progress = integralExchange.getProgress();
            if (StringUtil.isNullOrEmpty(progress))
                continue;
            int exchange = 0;
            if (listRecord != null && listRecord.size() >0 && listRecord.contains(integralExchange.getId()))
                exchange = 1;
            progress = progress.replace("{已兑换}", exchange + "").replace("{上限数}", integralExchange.getUpperLimit() + "");
            integralExchange.setProgress(progress);
        }
        return listValid;
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java
New file
@@ -0,0 +1,154 @@
package com.yeshi.fanli.service.impl.integral;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.integral.IntegralExchangeMapper;
import com.yeshi.fanli.entity.integral.IntegralExchange;
import com.yeshi.fanli.entity.integral.IntegralExchange.ExchangeTypeEnum;
import com.yeshi.fanli.exception.integral.IntegralExchangeException;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.vo.integral.ExchangeTipVO;
import com.yeshi.fanli.vo.user.UserInfoExtraVO;
@Service
public class IntegralExchangeServiceImpl implements IntegralExchangeService {
    @Resource
    private IntegralExchangeMapper integralExchangeMapper;
    @Resource
    private UserInfoExtraService userInfoExtraService;
    @Override
    public List<IntegralExchange> listValidCache(long start, int count){
        return integralExchangeMapper.listValid(start, count);
    }
    @Override
    public Long countValid(){
        return integralExchangeMapper.countValid();
    }
    @Override
    public ExchangeTipVO verifyExchange(Long uid, Long id) throws IntegralExchangeException{
        if (uid == null || uid <= 0)
            throw new IntegralExchangeException(1, "用户未登录");
        if (id == null || id <= 0)
            throw new IntegralExchangeException(1, "兑换id不正确");
        UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
        if (extraVO == null)
            throw new IntegralExchangeException(1, "用户相关信息不存在");
        IntegralExchange exchange = integralExchangeMapper.selectByPrimaryKey(id);
        if (exchange == null)
            throw new IntegralExchangeException(1, "兑换方式不存在");
        ExchangeTipVO exchangeTip = new ExchangeTipVO();
        Integer goldCoin = exchange.getGoldCoin();
        Integer goldCoinHas = extraVO.getGoldCoin();
        if (goldCoin.intValue() > goldCoinHas.intValue()) {
            exchangeTip.setType("notEnough");
            exchangeTip.setTip("当前账户中可用金币不足,无法兑换该奖品!");
            exchangeTip.setGoldCoin((goldCoin.intValue() - goldCoinHas.intValue()) + "金币");
            return exchangeTip;
        }
        ExchangeTypeEnum type = exchange.getType();
        if (ExchangeTypeEnum.freeCouponBuy == type) {
            exchangeTip.setTip("自购免单券仅能自己使用,且每个用户ID只能兑换一次。\r\n注:兑换成功后请到“我的-福利中心”中查看");
        } else if (ExchangeTypeEnum.freeCouponGive == type) {
            exchangeTip.setTip("赠送免单券兑换次数不限,赠送次数不限,受赠人若无“邀请人”成功领取后将成为你的一级队员。\r\n注:兑换成功后请到“我的-福利中心”中查看");
        } else if (ExchangeTypeEnum.rebateCoupon == type) {
            exchangeTip.setTip("返利奖励券兑换次数不限,赠送次数不限,受赠人若无“邀请人”成功领取后将成为你的一级队员。\r\n注:兑换成功后请到“我的-福利中心”中查看");
        } else if (ExchangeTypeEnum.inviteCodeActivate == type) {
            exchangeTip.setTip("注:兑换成功后请到“消息-系统消息”查看");
        } else if (ExchangeTypeEnum.inviteCodePublish == type) {
            exchangeTip.setInviteCode(extraVO.getInviteCode());
            exchangeTip.setTip("兑换成功后,将发布于“激活邀请码兑换功能中”,需激活邀请的用户可用金币兑换,本次展示有效期为3天。");
        } else if (ExchangeTypeEnum.taoLiJin == type) {
            exchangeTip.setName(exchange.getAmount() + "元推广红包");
            exchangeTip.setTip("注:兑换成功后请到“我的-推广红包”中查看");
        } else if (ExchangeTypeEnum.cash == type) {
            exchangeTip.setName(exchange.getAmount() + "元现金红包");
            exchangeTip.setTip("注:兑换成功后请到“我的-账户余额”中查看");
        } else {
            throw new IntegralExchangeException(1, "兑换方式不存在");
        }
        exchangeTip.setGoldCoin(goldCoin + "金币");
        exchangeTip.setType(type.name());
        return exchangeTip;
    }
    @Override
    public void exchange(Long uid, Long id, Long inviteId) throws IntegralExchangeException{
        if (uid == null || uid <= 0)
            throw new IntegralExchangeException(1, "用户未登录");
        if (id == null || id <= 0)
            throw new IntegralExchangeException(1, "兑换id不正确");
        UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
        if (extraVO == null)
            throw new IntegralExchangeException(1, "用户相关信息不存在");
        IntegralExchange exchange = integralExchangeMapper.selectByPrimaryKey(id);
        if (exchange == null)
            throw new IntegralExchangeException(1, "兑换方式不存在");
        Integer goldCoin = exchange.getGoldCoin();
        Integer goldCoinHas = extraVO.getGoldCoin();
        if (goldCoin.intValue() > goldCoinHas.intValue()) {
            throw new IntegralExchangeException(1, "当前账户中可用金币不足,无法兑换该奖品!");
        }
        ExchangeTypeEnum type = exchange.getType();
        if (ExchangeTypeEnum.freeCouponBuy == type) {
            // 自购免单券
        } else if (ExchangeTypeEnum.freeCouponGive == type) {
            // 赠送免单券
        } else if (ExchangeTypeEnum.rebateCoupon == type) {
            // 奖励免单券
        } else if (ExchangeTypeEnum.inviteCodeActivate == type) {
            if (inviteId == null || inviteId <= 0)
                throw new IntegralExchangeException(1, "传递参数不正确");
            // 激活邀请码
            UserInfoExtraVO inviteExtra = userInfoExtraService.getInfoExtraVOByUid(inviteId);
            if (inviteExtra == null || StringUtil.isNullOrEmpty(inviteExtra.getInviteCode()))
                throw new IntegralExchangeException(1, "兑换失败,该用户邀请码不存在");
        } else if (ExchangeTypeEnum.inviteCodePublish == type) {
            // 邀请码发布
        } else if (ExchangeTypeEnum.taoLiJin == type) {
            // 推广红包
        } else if (ExchangeTypeEnum.cash == type) {
            // 现金红包
        } else {
            throw new IntegralExchangeException(1, "兑换方式不存在");
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/service/inter/integral/IntegralExchangeRecordService.java
New file
@@ -0,0 +1,20 @@
package com.yeshi.fanli.service.inter.integral;
import java.util.List;
import com.yeshi.fanli.entity.integral.IntegralExchange;
public interface IntegralExchangeRecordService {
    /**
     * 查询兑换列表
     * @param start
     * @param count
     * @param uid
     * @return
     */
    public List<IntegralExchange> listExchange(long start, int count, Long uid);
}
fanli/src/main/java/com/yeshi/fanli/service/inter/integral/IntegralExchangeService.java
New file
@@ -0,0 +1,39 @@
package com.yeshi.fanli.service.inter.integral;
import java.util.List;
import com.yeshi.fanli.entity.integral.IntegralExchange;
import com.yeshi.fanli.exception.integral.IntegralExchangeException;
import com.yeshi.fanli.vo.integral.ExchangeTipVO;
public interface IntegralExchangeService {
    /**
     * 查询有效的
     * @param start
     * @param count
     * @return
     */
    public List<IntegralExchange> listValidCache(long start, int count);
    public Long countValid();
    /**
     * 金币兑换检验
     * @param uid
     * @param id
     * @return
     * @throws IntegralExchangeException
     */
    public ExchangeTipVO verifyExchange(Long uid, Long id) throws IntegralExchangeException;
    /**
     * 金币兑换
     * @param uid
     * @param id
     * @param inviteId
     * @throws IntegralExchangeException
     */
    public void exchange(Long uid, Long id, Long inviteId) throws IntegralExchangeException;
}
fanli/src/main/java/com/yeshi/fanli/util/mybatishandler/integral/ExchangeTypeEnumHandler.java
New file
@@ -0,0 +1,53 @@
package com.yeshi.fanli.util.mybatishandler.integral;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import com.yeshi.fanli.entity.integral.IntegralExchange.ExchangeTypeEnum;
public class ExchangeTypeEnumHandler extends BaseTypeHandler<ExchangeTypeEnum> {
    @Override
    public ExchangeTypeEnum getNullableResult(ResultSet arg0, String arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            return ExchangeTypeEnum.valueOf(key);
        }
    }
    @Override
    public ExchangeTypeEnum getNullableResult(ResultSet arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return ExchangeTypeEnum.valueOf(key);
        }
    }
    @Override
    public ExchangeTypeEnum getNullableResult(CallableStatement arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return ExchangeTypeEnum.valueOf(key);
        }
    }
    @Override
    public void setNonNullParameter(PreparedStatement arg0, int arg1, ExchangeTypeEnum arg2, JdbcType arg3)
            throws SQLException {
        arg0.setString(arg1, arg2.name());
    }
}
fanli/src/main/java/com/yeshi/fanli/vo/integral/ExchangeTipVO.java
New file
@@ -0,0 +1,66 @@
package com.yeshi.fanli.vo.integral;
import java.io.Serializable;
import com.google.gson.annotations.Expose;
public class ExchangeTipVO implements Serializable {
    private static final long serialVersionUID = 1L;
    // 类型
    @Expose
    private String type;
    // 金币数量
    @Expose
    private String goldCoin;
    // 兑换名称
    @Expose
    private String name;
    // 邀请码
    @Expose
    private String inviteCode;
    // 提示
    @Expose
    private String tip;
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getGoldCoin() {
        return goldCoin;
    }
    public void setGoldCoin(String goldCoin) {
        this.goldCoin = goldCoin;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getInviteCode() {
        return inviteCode;
    }
    public void setInviteCode(String inviteCode) {
        this.inviteCode = inviteCode;
    }
    public String getTip() {
        return tip;
    }
    public void setTip(String tip) {
        this.tip = tip;
    }
}