yujian
2019-09-03 d1dccd08a249b830a95eeeb04af25f87d5c056be
fanli/src/main/java/com/yeshi/fanli/service/impl/user/TokenRecordServiceImpl.java
@@ -8,6 +8,7 @@
import javax.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
@@ -21,12 +22,15 @@
import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponGiveRecord;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord;
import com.yeshi.fanli.entity.system.SystemCoupon;
import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
import com.yeshi.fanli.exception.tlj.UserTaoLiJinOriginException;
import com.yeshi.fanli.exception.user.TokenRecordException;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.SystemCouponService;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.integral.IntegralGetService;
import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinGiveRecordService;
import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
@@ -54,6 +58,7 @@
   private UserInfoService userInfoService;
   @Resource
   @Lazy
   private UserSystemCouponService userSystemCouponService;
   @Resource
@@ -76,6 +81,14 @@
   @Resource
   private UserOtherMsgNotificationService userOtherMsgNotificationService;
   @Lazy
   @Resource
   private IntegralGetService  integralGetService;
   @Resource
   private SystemCouponService systemCouponService;
   @Override
   public void insertSelective(TokenRecord record) {
@@ -245,7 +258,7 @@
      }
      if (StringUtil.isNullOrEmpty(nickName))
         nickName = Constant.systemCommonConfig.getDefaultNickName();
         nickName = Constant.systemCommonConfig.getDefaultNickName() + inviteId;
      if (StringUtil.isNullOrEmpty(portrait))
         portrait = Constant.systemCommonConfig.getDefaultPortrait();
@@ -256,7 +269,7 @@
      
      TokenVO tokenVO = new TokenVO();
      tokenVO.setAmount(num);
      tokenVO.setToken(token);
      tokenVO.setToken(parseToken);
      tokenVO.setNickName(nickName + "赠送");
      tokenVO.setPortrait(portrait);
      tokenVO.setTips(tips);
@@ -319,10 +332,11 @@
         if (userCoupon == null || userCoupon.getGive() == null || !userCoupon.getGive()
               || userCoupon.getState() != UserSystemCoupon.STATE_IN_USE)
            throw new TokenRecordException(1, "该券不存在或非赠送");
         UserSystemCoupon userSystemCoupon= null;
         try {
            userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCoupon.name(),
                  UserSystemCoupon.SOURCE_GIVE);
            userSystemCoupon = userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCoupon.name(),
                  UserSystemCoupon.SOURCE_GIVE, null);
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            throw new TokenRecordException(1, "领取失败");
@@ -348,17 +362,23 @@
         // 更新赠送记录
         UserSystemCouponGiveRecord updateGiveRecord = new UserSystemCouponGiveRecord();
         updateGiveRecord.setId(giveRecord.getId());
         updateGiveRecord.setReceiveUid(uid);
         updateGiveRecord.setReceiveTime(new Date());
         updateGiveRecord.setState(UserSystemCouponGiveRecord.STATE_RECEIVE);
         if (userSystemCoupon != null) {
            updateGiveRecord.setReceiveId(userSystemCoupon.getId());
         }
         userSystemCouponGiveRecordService.updateByPrimaryKeySelective(updateGiveRecord);
         integralGetService.addGiveFreeCoupon(giveUid);
         msg = "领取成功[免单券]成功,请到[我的-福利中心]中查看";
         // 消息 + 队员
         executor.execute(new Runnable() {
            @Override
            public void run() {
               SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH.mm");
               SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
               boolean addTeam = addInviteTeam(uid, giveUid, userInfoExtra);
               String beiZhu = "无";
               if (addTeam)
@@ -373,7 +393,7 @@
               msgOther.setType(MsgOtherGiveContentDTO.TYEP_COUPON);
               msgOther.setTitle("赠送免单券");
               msgOther.setGiveType("你赠送的免单券被成功领取");
               msgOther.setReceiveInfo("昵称:  " + userName + " ID:" + uid);
               msgOther.setReceiveInfo("昵称: :" + userName + " ID:" + uid);
               msgOther.setGiveTime(sd.format(giveRecord.getGiveTime()));
               msgOther.setReceiveTime(sd.format(new Date()));
               userOtherMsgNotificationService.tokenGiveMsg(giveUid, beiZhu, msgOther);
@@ -395,9 +415,18 @@
               || userCoupon.getState() != UserSystemCoupon.STATE_IN_USE)
            throw new TokenRecordException(1, "该券不存在或非赠送");
         SystemCoupon systemCoupon = userCoupon.getSystemCoupon();
         if (systemCoupon == null)
            throw new TokenRecordException(1, "该券不存在");
         systemCoupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
         if (systemCoupon == null)
            throw new TokenRecordException(1, "该券不存在");
         UserSystemCoupon userSystemCoupon= null;
         try {
            userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCoupon.name(),
                  UserSystemCoupon.SOURCE_GIVE);
            userSystemCoupon = userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.rebatePercentCoupon.name(),
                  UserSystemCoupon.SOURCE_GIVE, systemCoupon.getPercent());
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            throw new TokenRecordException(1, "领取失败");
@@ -423,17 +452,23 @@
         // 更新赠送记录
         UserSystemCouponGiveRecord updateGiveRecord = new UserSystemCouponGiveRecord();
         updateGiveRecord.setId(giveRecord.getId());
         updateGiveRecord.setReceiveUid(uid);
         updateGiveRecord.setReceiveTime(new Date());
         updateGiveRecord.setState(UserSystemCouponGiveRecord.STATE_RECEIVE);
         if (userSystemCoupon != null) {
            updateGiveRecord.setReceiveId(userSystemCoupon.getId());
         }
         userSystemCouponGiveRecordService.updateByPrimaryKeySelective(updateGiveRecord);
         integralGetService.addGiveRebateCoupon(giveUid);
         msg = "领取成功[返利奖励券]成功,请到[我的-福利中心]中查看";
         // 消息 + 队员
         executor.execute(new Runnable() {
            @Override
            public void run() {
               SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH.mm");
               SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
               boolean addTeam = addInviteTeam(uid, giveUid, userInfoExtra);
               String beiZhu = "无";
               if (addTeam)
@@ -448,7 +483,7 @@
               msgOther.setType(MsgOtherGiveContentDTO.TYEP_COUPON);
               msgOther.setTitle("赠送奖励券");
               msgOther.setGiveType("你赠送的奖励券被成功领取");
               msgOther.setReceiveInfo("昵称:  " + userName + " ID:" + uid);
               msgOther.setReceiveInfo("昵称: " + userName + " ID:" + uid);
               msgOther.setGiveTime(sd.format(giveRecord.getGiveTime()));
               msgOther.setReceiveTime(sd.format(new Date()));
               userOtherMsgNotificationService.tokenGiveMsg(giveUid, beiZhu, msgOther);
@@ -477,13 +512,15 @@
            updateRecord.setState(UserTaoLiJinGiveRecord.STATE_RECEIVE);
            userTaoLiJinGiveRecordService.updateByPrimaryKeySelective(updateRecord);
            integralGetService.addGiveTaoLiJin(giveUid);
            msg = "领取成功[推广红包]成功,请到[我的-推广红包]中查看";
            // 消息 + 队员
            executor.execute(new Runnable() {
               @Override
               public void run() {
                  SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH.mm");
                  SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                  boolean addTeam = addInviteTeam(uid, giveUid, userInfoExtra);
                  String beiZhu = "无";
                  if (addTeam)
@@ -495,10 +532,10 @@
                     userName = user.getNickName();
                  MsgOtherGiveContentDTO msgOther = new MsgOtherGiveContentDTO();
                  msgOther.setType(MsgOtherGiveContentDTO.TYEP_COUPON);
                  msgOther.setType(MsgOtherGiveContentDTO.TYEP_TLJ);
                  msgOther.setTitle("赠送推广红包");
                  msgOther.setGiveType("你赠送的推广红包被成功领取");
                  msgOther.setReceiveInfo("昵称:  " + userName + " ID:" + uid);
                  msgOther.setReceiveInfo("昵称:" + userName + " ID:" + uid);
                  msgOther.setGiveTime(sd.format(giveRecord.getGiveTime()));
                  msgOther.setReceiveTime(sd.format(new Date()));
                  userOtherMsgNotificationService.tokenGiveMsg(giveUid, beiZhu, msgOther);
@@ -540,5 +577,23 @@
      }
      return invite;
   }
   @Override
   public List<TokenRecord> overdueList(int count) {
      return tokenRecordMapper.overdueList(count);
   }
   @Override
   public void overdue(List<TokenRecord> list) {
      if (list == null || list.size() == 0)
         return;
      Date date = new Date();
      for (TokenRecord tokenRecord: list) {
         tokenRecord.setState(1);
         tokenRecord.setUpdateTime(date);
         tokenRecordMapper.updateByPrimaryKeySelective(tokenRecord);
      }
   }
}