admin
2019-09-02 245f369b980e7d6f34a5a1aa9fb0bdaba1f63f5f
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -10,7 +10,9 @@
import javax.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.DateUtil;
@@ -105,6 +107,7 @@
   private UserSystemCouponRecordService userSystemCouponRecordService;
   @Resource
   @Lazy
   private HongBaoV2Service hongBaoV2Service;
   @Resource
@@ -141,6 +144,7 @@
   private CommonOrderCountService commonOrderCountService;
   
   @Resource
   @Lazy
   private PushCouponService pushCouponService;
   
   @Resource
@@ -245,7 +249,10 @@
      // 结束日期
      // 今天在内  减去一天
      String endDay = DateUtil.plusDay(expiryDay - 1, new Date());
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      if (endDay != null && endDay.trim().length() > 0) {
         endDay += " 23:59:59";
      }
      Date endTime = format.parse(endDay);
      UserSystemCoupon userCoupon = new UserSystemCoupon();
@@ -1374,7 +1381,10 @@
         // 结束日期
         // 今天在内  减去一天
         String endDay = DateUtil.plusDay(systemCoupon.getExpiryDay() - 1, new Date());
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         if (endDay != null && endDay.trim().length() > 0) {
            endDay += " 23:59:59";
         }
         Date endTime = format.parse(endDay);
         UserSystemCoupon userCoupon = new UserSystemCoupon();
@@ -1449,7 +1459,10 @@
         
         // 结束日期 今天在内  减去一天
         String endDay = DateUtil.plusDay(systemCoupon.getExpiryDay() - 1, new Date());
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         if (endDay != null && endDay.trim().length() > 0) {
            endDay += " 23:59:59";
         }
         Date endTime = format.parse(endDay);
         
         UserSystemCoupon userCoupon = new UserSystemCoupon();
@@ -1586,7 +1599,10 @@
         
      //  计算结束日期:今天在内  减去一天
      String endDay = DateUtil.plusDay(expiryDay - 1, new Date());
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      if (endDay != null && endDay.trim().length() > 0) {
         endDay += " 23:59:59";
      }
      Date endTime = format.parse(endDay);
      UserSystemCoupon userCoupon = new UserSystemCoupon();
@@ -2021,7 +2037,10 @@
         try {
            Integer expiryDay =  systemCoupon.getExpiryDay();
            String endDay = DateUtil.plusDay(expiryDay - 1, nowDate);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (endDay != null && endDay.trim().length() > 0) {
               endDay += " 23:59:59";
            }
            Date endTime = format.parse(endDay);
            
            UserSystemCoupon userCoupon = new UserSystemCoupon();
@@ -2147,16 +2166,10 @@
      userSystemCoupon.setUseTime(null);
      userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
      userSystemCoupon.setUpdateTime(new Date());
      userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
      userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
      
      // 使用记录
      if  (record != null) {
         UserSystemCouponRecord useRecordUpdate = new UserSystemCouponRecord();
         useRecordUpdate.setId(record.getId());
         useRecordUpdate.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
         useRecordUpdate.setUpdateTime(new Date());
         userSystemCouponRecordService.updateByPrimaryKeySelective(useRecordUpdate);
         if (CouponTypeEnum.welfareFreeCoupon.name().equals(record.getCouponType())) {
            userOtherMsgNotificationService.welfareCouponDrawBack(userSystemCoupon, record.getOrderNo());
         } else if (CouponTypeEnum.freeCoupon.name().equals(record.getCouponType())) {
@@ -2168,27 +2181,44 @@
   }
   
   
   @Async()
   @Transactional
   @Override
   public void sendBackTimeOutCoupon(Long uid) {
      // 超过10分钟   未被匹配的券
      List<UserSystemCouponRecord> list = userSystemCouponRecordService.getCouponByUsingTimeOut(uid, 600L);
      if (list == null || list.size() == 0) {
      // 商品相关的券
      List<SystemCoupon> couponList = systemCouponService.getGoodsCouponList();
      if (couponList == null || couponList.size() == 0) {
         return;
      }
      for (UserSystemCouponRecord couponRecord : list) {
         // 更新状态:匹配超时
         couponRecord.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
         couponRecord.setUpdateTime(new Date());
         userSystemCouponRecordService.updateByPrimaryKeySelective(couponRecord);
      List<Long> list = new ArrayList<Long>();
      for (SystemCoupon systemCoupon: couponList) {
         list.add(systemCoupon.getId());
      }
      // 超过10分钟   未被匹配的免单券
      List<UserSystemCoupon> listUserCoupon = userSystemCouponMapper.getCouponByUsingTimeOut(uid, list, 600L);
      if (listUserCoupon == null || listUserCoupon.size() == 0) {
         return;
      }
      for (UserSystemCoupon userCoupon : listUserCoupon) {
         // 状态初始化
         UserSystemCoupon userSystemCoupon = couponRecord.getUserSystemCoupon();
         UserSystemCoupon userSystemCoupon = new UserSystemCoupon();
         userSystemCoupon.setId(userCoupon.getId());
         userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
         userSystemCoupon.setUseTime(null);
         userSystemCoupon.setUpdateTime(new Date());
         userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
         userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
         UserSystemCouponRecord record = userSystemCouponRecordService.getNearByUserCouponId(userCoupon.getId());
         if (record != null) {
            UserSystemCouponRecord couponRecord = new UserSystemCouponRecord();
            couponRecord.setId(record.getId());
            couponRecord.setUpdateTime(new Date());
            couponRecord.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
            userSystemCouponRecordService.updateByPrimaryKeySelective(couponRecord);
         }
      }
   }
@@ -2243,7 +2273,7 @@
         userSystemCoupon.setUseTime(null);
         userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
         userSystemCoupon.setUpdateTime(new Date());
         userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
         userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
         
         // 使用记录
         UserSystemCouponRecord useRecord = userSystemCouponRecordService.getNearByUserCouponId(couponId);