admin
2019-11-13 221b5c8d0de3f6b17a00d543503a79c13b28ba12
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -21,6 +21,7 @@
import org.yeshi.utils.entity.DateInfo;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.SendResult;
import com.aliyun.openservices.ons.api.transaction.LocalTransactionExecuter;
import com.aliyun.openservices.ons.api.transaction.TransactionProducer;
@@ -174,6 +175,11 @@
   @Resource
   private UserSystemCouponActivateService userSystemCouponActivateService;
   @Resource(name = "producer")
   private Producer producer;
   @Override
   public int insertSelective(UserSystemCoupon record) {
@@ -2071,7 +2077,20 @@
      }
      tips = tips.replace("{口令}", token).replace("{下载链接}", configService.get("app_down_link"));
      return createUserCouponVOo(userSystemCoupon, systemCoupon, giveRecord, tips);
      UserSystemCouponVO couponVO = createUserCouponVOo(userSystemCoupon, systemCoupon, giveRecord, tips);
      UserSystemCouponUseMQMsg msg = new UserSystemCouponUseMQMsg();
      msg.setUserSystemCouponId(id);
      msg.setCouponType(type.name());
      Message message = new Message(MQTopicName.TOPIC_USER.name(), UserTopicTagEnum.systemCouponDrawback.name(),
            new Gson().toJson(msg).getBytes());
      try {
         producer.send(message);
      } catch (Exception e) {
         throw new UserSystemCouponException(1, "创建赠送信息失败");
      }
      return couponVO;
   }
   private UserSystemCouponVO createUserCouponVOo(UserSystemCoupon userSystemCoupon, SystemCoupon systemCoupon,
@@ -2258,30 +2277,10 @@
   
   @Override
   @RequestSerializableByKeyService(key = "#giveid")
   @RequestSerializableByKeyService(key = "#id")
   @Transactional(rollbackFor = Exception.class)
   public void sendBackByGiveId(Long giveid) {
      if (giveid == null)
         return;
      UserSystemCouponGiveRecord giveRecord = userSystemCouponGiveRecordService.selectByPrimaryKey(giveid);
      if (giveRecord == null)
         return;
      if (giveRecord.getState() != null && giveRecord.getState() != UserSystemCouponGiveRecord.STATE_INIT)
         return;
      // 更新赠送记录
      UserSystemCouponGiveRecord updateRecord = new UserSystemCouponGiveRecord();
      updateRecord.setId(giveid);
      updateRecord.setState(UserSystemCouponGiveRecord.STATE_OVERDUE);
      userSystemCouponGiveRecordService.updateByPrimaryKeySelective(updateRecord);
      // 口令失效
      tokenRecordService.invalidByCoupon(giveid);
      Long couponId = giveRecord.getCouponId();
      if (couponId == null)
   public void sendBackByGiveId(Long couponId) {
      if (couponId == null)
         return;
      
      UserSystemCoupon userCoupon = userSystemCouponMapper.selectByPrimaryKey(couponId);
@@ -2291,6 +2290,23 @@
      Integer state = userCoupon.getState();
      if (state != UserSystemCoupon.STATE_IN_USE)
         return;
      UserSystemCouponGiveRecord giveRecord = userSystemCouponGiveRecordService.getByCouponId(couponId);
      if (giveRecord == null)
         return;
      if (giveRecord.getState() != null && giveRecord.getState() != UserSystemCouponGiveRecord.STATE_INIT)
         return;
      // 更新赠送记录
      UserSystemCouponGiveRecord updateRecord = new UserSystemCouponGiveRecord();
      updateRecord.setId(giveRecord.getId());
      updateRecord.setState(UserSystemCouponGiveRecord.STATE_OVERDUE);
      userSystemCouponGiveRecordService.updateByPrimaryKeySelective(updateRecord);
      // 口令失效
      tokenRecordService.invalidByCoupon(giveRecord.getId());
      Date now = new Date();
      Date endTime = userCoupon.getEndTime();