yujian
2019-08-21 54b0dd1b6f8230799b0b4490f8b39afdd53a4e4c
积分明细
9个文件已修改
207 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/integral/IntegralDetailMapper.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/integral/IntegralDetailMapper.xml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralDetailServiceImpl.java 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/integral/IntegralDetailService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/TokenRecordService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java
@@ -617,9 +617,9 @@
        }
        // 查询列表
        List<IntegralDetailVO> list = integralDetailService.listDetailForClient(uid, index, date);
        List<IntegralDetailVO> list = integralDetailService.listDetailForClient(uid, index, date, type);
        // 统计总条数
        long count = integralDetailService.countDetailForClient(uid, index, date);
        long count = integralDetailService.countDetailForClient(uid, index, date, type);
        GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
        gsonBuilder.registerTypeAdapter(TaoLiJinDetailTypeEnum.class, new TypeAdapter<TaoLiJinDetailTypeEnum>() {
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/integral/IntegralDetailMapper.java
@@ -17,7 +17,7 @@
     * @param uid
     * @return
     */
    Long selectCountByUid(@Param("uid") Long uid);
    Long selectCountByUid(@Param("uid") Long uid, @Param("type")Integer type);
    
    /**
     * 按用户ID和最大时间检索月份的数量
@@ -26,7 +26,7 @@
     * @param maxDate
     * @return
     */
    int selectMonthCountByUid(@Param("uid") Long uid, @Param("date") Date maxDate);
    int selectMonthCountByUid(@Param("uid") Long uid, @Param("date") Date maxDate, @Param("type")Integer type);
    
    
    /**
@@ -36,7 +36,7 @@
     * @param date
     * @return
     */
    Long selectCountByUidAndMaxCreateTime(@Param("uid") Long uid, @Param("date") Date date);
    Long selectCountByUidAndMaxCreateTime(@Param("uid") Long uid, @Param("date") Date date, @Param("type")Integer type);
    
    
    /**
@@ -46,7 +46,7 @@
     * @param date
     * @return
     */
    List<IntegralDetail> selectByMaxCreateTime(@Param("uid") Long uid, @Param("date") Date date, @Param("count") int count);
    List<IntegralDetail> selectByMaxCreateTime(@Param("uid") Long uid, @Param("date") Date date, @Param("count") int count, @Param("type")Integer type);
    
    
    /**
@@ -57,7 +57,7 @@
     * @param count
     * @return
     */
    List<IntegralDetail> selectByUidWithIndexId(@Param("uid") Long uid, @Param("id") Long id, @Param("count") int count);
    List<IntegralDetail> selectByUidWithIndexId(@Param("uid") Long uid, @Param("id") Long id, @Param("count") int count, @Param("type")Integer type);
    
    
    /**
@@ -67,6 +67,6 @@
     * @param dateFormat
     * @return
     */
    List<IntegralMonthVO> selectMonthMoneyByUid(@Param("uid") Long uid, @Param("dateFormat") List<String> dateFormat);
    List<IntegralMonthVO> selectMonthMoneyByUid(@Param("uid") Long uid, @Param("dateFormat") List<String> dateFormat, @Param("type")Integer type);
    
}
fanli/src/main/java/com/yeshi/fanli/mapping/integral/IntegralDetailMapper.xml
@@ -58,13 +58,17 @@
  
   <select id="selectCountByUid" resultType="java.lang.Long"  parameterType="java.lang.Long">
    SELECT count(td_id) FROM yeshi_ec_integral_detail
    WHERE td_uid = #{uid}
    WHERE td_uid = #{uid}
     <if test="type == 1">AND td_money <![CDATA[>]]> 0</if>
     <if test="type == 2">AND td_money <![CDATA[<]]> 0</if>
  </select>
  
   <select id="selectMonthCountByUid" resultType="java.lang.Integer">
    SELECT COUNT(*) FROM 
            (SELECT * FROM yeshi_ec_integral_detail d 
             WHERE d.`td_uid`=#{uid} AND d.`td_create_time` <![CDATA[<=]]> #{date} 
                  <if test="type == 1">AND d.td_money <![CDATA[>]]> 0</if>
                   <if test="type == 2">AND d.td_money <![CDATA[<]]> 0</if>
             GROUP BY DATE_FORMAT(d.`td_create_time`,'%y-%m')
             ) a
  </select>
@@ -73,11 +77,15 @@
  <select id="selectCountByUidAndMaxCreateTime" resultType="java.lang.Long">
    SELECT count(utd_id) FROM yeshi_ec_integral_detail
    WHERE td_uid=#{uid} and `td_create_time`<![CDATA[<=]]>#{date}
          <if test="type == 1">AND td_money <![CDATA[>]]> 0</if>
          <if test="type == 2">AND td_money <![CDATA[<]]> 0</if>
 </select>
  
   <select id="selectByMaxCreateTime" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_integral_detail t
    WHERE t.`td_uid`=#{uid} AND t.`td_create_time`<![CDATA[<=]]> #{date}
          <if test="type == 1">AND t.td_money <![CDATA[>]]> 0</if>
          <if test="type == 2">AND t.td_money <![CDATA[<]]> 0</if>
    ORDER BY t.`td_create_time` DESC,t.td_id DESC
    LIMIT #{count}
  </select>
@@ -86,6 +94,8 @@
    SELECT <include refid="Base_Column_List" />    FROM yeshi_ec_integral_detail t 
    WHERE t.`td_uid`=#{uid}
        AND t.`td_create_time`<![CDATA[<=]]>(SELECT td_create_time FROM yeshi_ec_integral_detail WHERE td_id =#{id})
        <if test="type == 1">AND t.td_money <![CDATA[>]]> 0</if>
        <if test="type == 2">AND t.td_money <![CDATA[<]]> 0</if>
    ORDER BY t.`td_create_time` DESC,t.td_id DESC
    LIMIT #{count}
  </select>
@@ -99,12 +109,16 @@
                LEFT JOIN (SELECT DATE_FORMAT(d.`td_create_time`,'%Y-%m') AS `time`,SUM(d.`td_money`)AS money
                               FROM `yeshi_ec_integral_detail` d
                               WHERE d.`td_uid`=#{uid} AND  d.`td_money`<![CDATA[>=]]>0 AND DATE_FORMAT(d.`td_create_time`,'%Y-%m')=#{item} 
                               <if test="type == 1">AND d.td_money <![CDATA[>]]> 0</if>
                            <if test="type == 2">AND d.td_money <![CDATA[<]]> 0</if>
                               GROUP BY DATE_FORMAT(d.`td_create_time`,'%Y-%m')
                               ) a ON a.time=c.time
                LEFT JOIN(SELECT DATE_FORMAT(d.`td_create_time`,'%Y-%m') AS `time`,SUM(d.`td_money`) AS money
                              FROM `yeshi_ec_integral_detail` d
                            WHERE d.`td_uid`=#{uid} AND d.`td_money` <![CDATA[<]]>0 AND DATE_FORMAT(d.`td_create_time`,'%Y-%m')=#{item} 
                                     <if test="type == 1">AND d.td_money <![CDATA[>]]> 0</if>
                                <if test="type == 2">AND d.td_money <![CDATA[<]]> 0</if>
                              GROUP BY DATE_FORMAT(d.`td_create_time`,'%Y-%m')
                              ) b ON c.time=b.time
           </trim>
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralDetailServiceImpl.java
@@ -30,16 +30,16 @@
    
    @Override
    public List<IntegralDetailVO> listDetailForClient(Long uid, Long detailId, Date maxTime) {
    public List<IntegralDetailVO> listDetailForClient(Long uid, Long detailId, Date maxTime, Integer type) {
        List<IntegralDetailVO> finalList = new ArrayList<>();
        List<IntegralDetail> list = null;
        if (detailId == null) {// 首次请求
            if (maxTime == null)// 没有筛选时间
            {
                list = integralDetailMapper.selectByMaxCreateTime(uid,
                        new Date(System.currentTimeMillis() + 1000 * 60 * 60L), 20);
                        new Date(System.currentTimeMillis() + 1000 * 60 * 60L), 20, type);
            } else {// 筛选了时间
                list = integralDetailMapper.selectByMaxCreateTime(uid, maxTime, 20);
                list = integralDetailMapper.selectByMaxCreateTime(uid, maxTime, 20, type);
            }
            if (list != null && list.size() > 0) {
                Calendar calendar = Calendar.getInstance();
@@ -62,7 +62,7 @@
        } else {// 二次请求
            int size = 21;
            List<IntegralDetail> tempList = integralDetailMapper.selectByUidWithIndexId(uid, detailId, size);
            List<IntegralDetail> tempList = integralDetailMapper.selectByUidWithIndexId(uid, detailId, size, type);
            Set<Date> dateSet = new HashSet<>();// 用于储存是否在同一时间上面(精确到秒)
            if (tempList.size() > 0) {
                for (IntegralDetail umd : tempList) {
@@ -73,7 +73,7 @@
                while (dateSet.size() == 1 && tempList2.size() != tempList.size() && size < 40) {// 只有一个时间点的数据
                    tempList = tempList2;
                    size += 10;
                    tempList2 = integralDetailMapper.selectByUidWithIndexId(uid, detailId, size);
                    tempList2 = integralDetailMapper.selectByUidWithIndexId(uid, detailId, size, type);
                    dateSet.clear();
                    for (IntegralDetail umd : tempList2) {
                        dateSet.add(umd.getCreateTime());
@@ -144,7 +144,7 @@
                        ? "0" + monthMap.get(key).getMonth().getMonth() : monthMap.get(key).getMonth().getMonth();
                dateFormat.add(date);
            }
            List<IntegralMonthVO> voList = integralDetailMapper.selectMonthMoneyByUid(uid, dateFormat);
            List<IntegralMonthVO> voList = integralDetailMapper.selectMonthMoneyByUid(uid, dateFormat, type);
            int p = 0;
            keys = monthMap.keySet().iterator();
@@ -165,17 +165,17 @@
    
    @Override
    public long countDetailForClient(Long uid, Long detailId, Date maxTime) {
    public long countDetailForClient(Long uid, Long detailId, Date maxTime, Integer type) {
        long monthCount = 0L;
        long detailCount = 0L;
        // 未通过时间筛选,查询所有
        if (maxTime == null) {
            detailCount = integralDetailMapper.selectCountByUid(uid);
            detailCount = integralDetailMapper.selectCountByUid(uid, type);
            // 用于表示当前所有
            monthCount = integralDetailMapper.selectMonthCountByUid(uid, new Date(System.currentTimeMillis() + 1000 * 60 * 60L));
            monthCount = integralDetailMapper.selectMonthCountByUid(uid, new Date(System.currentTimeMillis() + 1000 * 60 * 60L), type);
        } else {// 通过时间筛选了的,需要查询所有
            detailCount = integralDetailMapper.selectCountByUidAndMaxCreateTime(uid, maxTime);
            monthCount = integralDetailMapper.selectMonthCountByUid(uid, maxTime);
            detailCount = integralDetailMapper.selectCountByUidAndMaxCreateTime(uid, maxTime, type);
            monthCount = integralDetailMapper.selectMonthCountByUid(uid, maxTime, type);
        }
        return monthCount + detailCount;
fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java
@@ -53,7 +53,7 @@
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.TokenUtil;
import com.yeshi.fanli.util.factory.CommonGoodsFactory;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.util.taobao.TaoLiJinUtil;
@@ -533,53 +533,32 @@
        if (amount.compareTo(tlj) > 0)
            throw new UserTaoLiJinRecordException(1, "红包余额不足");
        
        Long giveId = null;
        Date nowDate = new Date();
        try {
            // 赠送记录
            UserTaoLiJinGiveRecord giveRecord = new UserTaoLiJinGiveRecord();
            giveRecord.setAmount(amount);
            giveRecord.setGiveUid(uid);
            giveRecord.setState(UserTaoLiJinGiveRecord.STATE_INIT);
            giveRecord.setGiveTime(nowDate);
            giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, new Date()));
            userTaoLiJinGiveRecordService.insertSelective(giveRecord);
            giveId = giveRecord.getId();
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            throw new UserTaoLiJinRecordException(1, "赠送记录创建失败");
        }
        // 赠送记录
        UserTaoLiJinGiveRecord giveRecord = new UserTaoLiJinGiveRecord();
        giveRecord.setAmount(amount);
        giveRecord.setGiveUid(uid);
        giveRecord.setState(UserTaoLiJinGiveRecord.STATE_INIT);
        giveRecord.setGiveTime(nowDate);
        giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, new Date()));
        userTaoLiJinGiveRecordService.insertSelective(giveRecord);
        
        String token = null;
        for (int i = 0; i < 5; i++) {
            try {
                // TODO 口令生成规则待定
                long num = 10000 + (long) (Math.random() * 10000);
                token = UserUtil.getInviteCode(num);
                TokenRecord tokenRecord = new TokenRecord();
                tokenRecord.setUid(uid);
                tokenRecord.setIdentify(giveId + ""); // 记录id
                tokenRecord.setType(TokenTypeEnum.taoLiJin);
                tokenRecord.setStartTime(nowDate);
                tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, new Date()));
                tokenRecord.setToken(token);
                tokenRecord.setState(0);
                tokenRecordService.insertSelective(tokenRecord);
            } catch (Exception e) {
                LogHelper.errorDetailInfo(e);
                token = null;
            }
            if(!StringUtil.isNullOrEmpty(token)) {
                break;
            }
        }
        // 口令记录
        TokenRecord tokenRecord = new TokenRecord();
        tokenRecord.setUid(uid);
        tokenRecord.setIdentify(giveRecord.getId() + "");
        tokenRecord.setType(TokenTypeEnum.taoLiJin);
        tokenRecord.setStartTime(nowDate);
        tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, new Date()));
        tokenRecord.setState(0);
        tokenRecordService.insertSelective(tokenRecord);
        
        if(StringUtil.isNullOrEmpty(token))
            throw new UserTaoLiJinRecordException(1, "口令生成失败");
        // 创建口令
        String token = TokenUtil.createToken(tokenRecord.getId());
        tokenRecord.setToken(token);
        tokenRecordService.updateByPrimaryKeySelective(tokenRecord);
        
        // 更新余额
        UserMoneyExtra updateExtra = new UserMoneyExtra();
        updateExtra.setUid(uid);
        updateExtra.setTlj(MoneyBigDecimalUtil.sub(tlj, amount));
fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java
@@ -38,6 +38,7 @@
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TokenUtil;
import com.yeshi.fanli.vo.msg.TokenVO;
@Service
@@ -83,6 +84,12 @@
        tokenRecordMapper.insertSelective(record);
    }
    @Override
    public void updateByPrimaryKeySelective(TokenRecord record) {
        tokenRecordMapper.updateByPrimaryKeySelective(record);
    }
    @Override
    public TokenRecord getNearByTypeAndIdentify(String type, String identify) {
        return tokenRecordMapper.getNearByTypeAndIdentify(type, identify);
@@ -90,8 +97,11 @@
    @Override
    public TokenVO discernToken(String token, Long uid) throws TokenRecordException {
        // TODO token 验证
        // 解析口令
        String parseToken = TokenUtil.parseToken(token);
        if (StringUtil.isNullOrEmpty(parseToken))
            throw new TokenRecordException(1, "未发现口令");
        TokenRecord rokenRecord = tokenRecordMapper.getByToken(token);
        if (rokenRecord == null)
            throw new TokenRecordException(1, "口令不存在");
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -62,7 +62,7 @@
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.TokenUtil;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
@@ -1926,52 +1926,31 @@
        }
        
        
        Long giveRecordId = null;
        Date nowDate = new Date();
        // 插入赠送记录
        try {
            UserSystemCouponGiveRecord giveRecord = new UserSystemCouponGiveRecord();
            giveRecord.setCouponId(id);
            giveRecord.setGiveUid(uid);
            giveRecord.setGiveTime(nowDate);
            giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, nowDate));
            userSystemCouponGiveRecordService.insertSelective(giveRecord);
            giveRecordId = giveRecord.getId();
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            throw new UserSystemCouponException(1, "赠送记录创建失败");
        }
        UserSystemCouponGiveRecord giveRecord = new UserSystemCouponGiveRecord();
        giveRecord.setCouponId(id);
        giveRecord.setGiveUid(uid);
        giveRecord.setGiveTime(nowDate);
        giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, nowDate));
        userSystemCouponGiveRecordService.insertSelective(giveRecord);
        
        String token = null;
        for (int i = 0; i < 5; i++) {
            try {
                // TODO 口令生成规则待定
                long num = 10000 + (long) (Math.random() * 10000);
                token = UserUtil.getInviteCode(num);
                TokenRecord tokenRecord = new TokenRecord();
                tokenRecord.setUid(uid);
                tokenRecord.setIdentify(giveRecordId+"");
                tokenRecord.setType(tokenTypeEnum);
                tokenRecord.setStartTime(nowDate);
                tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, nowDate));
                tokenRecord.setToken(token);
                tokenRecord.setState(0);
                tokenRecordService.insertSelective(tokenRecord);
            } catch (Exception e) {
                LogHelper.errorDetailInfo(e);
                token = null;
            }
        // 创建记录
        TokenRecord tokenRecord = new TokenRecord();
        tokenRecord.setUid(uid);
        tokenRecord.setIdentify(giveRecord.getId()+"");
        tokenRecord.setType(tokenTypeEnum);
        tokenRecord.setStartTime(nowDate);
        tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, nowDate));
        tokenRecord.setState(0);
        tokenRecordService.insertSelective(tokenRecord);
        // 创建口令
        String token = TokenUtil.createToken(tokenRecord.getId());
        tokenRecord.setToken(token);
        tokenRecordService.updateByPrimaryKeySelective(tokenRecord);
            
            if(!StringUtil.isNullOrEmpty(token)) {
                break;
            }
        }
        if(StringUtil.isNullOrEmpty(token))
            throw new UserSystemCouponException(1, "口令生成失败");
        // 券状态
        userSystemCoupon.setState(UserSystemCoupon.STATE_IN_USE);
        userSystemCoupon.setGive(true);
        userSystemCoupon.setUpdateTime(nowDate);
fanli/src/main/java/com/yeshi/fanli/service/inter/integral/IntegralDetailService.java
@@ -14,7 +14,7 @@
     * @param maxTime
     * @return
     */
    public List<IntegralDetailVO> listDetailForClient(Long uid, Long detailId, Date maxTime);
    public List<IntegralDetailVO> listDetailForClient(Long uid, Long detailId, Date maxTime, Integer type);
    /**
     * 明细统计
@@ -23,7 +23,7 @@
     * @param maxTime
     * @return
     */
    public long countDetailForClient(Long uid, Long detailId, Date maxTime);
    public long countDetailForClient(Long uid, Long detailId, Date maxTime, Integer type);
    
fanli/src/main/java/com/yeshi/fanli/service/inter/user/TokenRecordService.java
@@ -34,4 +34,7 @@
     */
    public String receiveToken(String token, Long uid) throws TokenRecordException;
    public void updateByPrimaryKeySelective(TokenRecord record);
}