yujian
2019-08-27 d8359ddb48dab5cc797a9d552e11fde571f4920c
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;
@@ -76,6 +80,14 @@
   @Resource
   private UserOtherMsgNotificationService userOtherMsgNotificationService;
   @Lazy
   @Resource
   private IntegralGetService  integralGetService;
   @Resource
   private SystemCouponService systemCouponService;
   @Override
   public void insertSelective(TokenRecord record) {
@@ -102,10 +114,14 @@
      if (StringUtil.isNullOrEmpty(parseToken)) 
         throw new TokenRecordException(1, "未发现口令");
      
      TokenRecord rokenRecord = tokenRecordMapper.getByToken(token);
      TokenRecord rokenRecord = tokenRecordMapper.getByToken(parseToken);
      if (rokenRecord == null)
         throw new TokenRecordException(1, "口令不存在");
      Long uidToken = rokenRecord.getUid();
      if (uid != null && uidToken != null && uid.longValue() == uidToken.longValue())
         throw new TokenRecordException(1, "不能自己赠送给自己");
      Date now = new Date();
      Date endTimeToken = rokenRecord.getEndTime();
      Integer stateTtoken = rokenRecord.getState();
@@ -252,7 +268,7 @@
      
      TokenVO tokenVO = new TokenVO();
      tokenVO.setAmount(num);
      tokenVO.setToken(token);
      tokenVO.setToken(parseToken);
      tokenVO.setNickName(nickName + "赠送");
      tokenVO.setPortrait(portrait);
      tokenVO.setTips(tips);
@@ -274,7 +290,11 @@
      TokenRecord rokenRecord = tokenRecordMapper.getByToken(token);
      if (rokenRecord == null)
         throw new TokenRecordException(1, "口令已失效");
      Long uidToken = rokenRecord.getUid();
      if (uidToken != null && uid.longValue() == uidToken.longValue())
         throw new TokenRecordException(1, "不能自己赠送给自己");
      Date now = new Date();
      Date endTimeToken = rokenRecord.getEndTime();
      if (endTimeToken != null && endTimeToken.getTime() < now.getTime())
@@ -312,9 +332,11 @@
               || userCoupon.getState() != UserSystemCoupon.STATE_IN_USE)
            throw new TokenRecordException(1, "该券不存在或非赠送");
         try {
            userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCoupon.name(),
                  UserSystemCoupon.SOURCE_GIVE);
                  UserSystemCoupon.SOURCE_GIVE, null);
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            throw new TokenRecordException(1, "领取失败");
@@ -345,12 +367,14 @@
         updateGiveRecord.setState(UserSystemCouponGiveRecord.STATE_RECEIVE);
         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)
@@ -365,7 +389,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);
@@ -387,9 +411,17 @@
               || 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, "该券不存在");
         try {
            userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCoupon.name(),
                  UserSystemCoupon.SOURCE_GIVE);
            userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.rebatePercentCoupon.name(),
                  UserSystemCoupon.SOURCE_GIVE, systemCoupon.getPercent());
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            throw new TokenRecordException(1, "领取失败");
@@ -420,12 +452,14 @@
         updateGiveRecord.setState(UserSystemCouponGiveRecord.STATE_RECEIVE);
         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)
@@ -469,13 +503,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)
@@ -487,7 +523,7 @@
                     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);