张天森
2022-10-12 3c884ccd7b51edf3b36840bf99de5edaa41a38a7
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActRaffleServiceImpl.java
@@ -1,5 +1,7 @@
package com.panzhihua.service_community.service.impl;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -15,7 +17,9 @@
import com.panzhihua.service_community.entity.ComActRaffleRecord;
import com.panzhihua.service_community.service.ComActRaffleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -39,6 +43,8 @@
    private ComActRafflePrizeDao comActRafflePrizeDao;
    @Resource
    private ComActRaffleRecordDao comActRaffleRecordDao;
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Override
    public R pageList(CommonPage commonPage) {
        return R.ok(this.baseMapper.pageList(new Page(commonPage.getPage(),commonPage.getSize()),commonPage));
@@ -53,6 +59,10 @@
        comActRaffle.setStatus(0);
        int count= this.baseMapper.insert(comActRaffle);
        if(count>0){
            rabbitTemplate.convertAndSend("raffle.exchange", "raffle.key", comActRaffle, message -> {
                message.getMessageProperties().setHeader("x-delay", dateToSecond(comActRaffle.getStartTime()));
                return message;
            });
            if(!CollectionUtils.isEmpty(comActRaffleVO.getComActRafflePrizeVOList())){
                comActRaffleVO.getComActRafflePrizeVOList().forEach(comActRafflePrizeVO -> {
                    ComActRafflePrize comActRafflePrize=new ComActRafflePrize();
@@ -112,8 +122,20 @@
          ComActRaffleRecordVO comActRaffleRecordVO=comActRaffleRecordDao.selectByUserId(userId,id);
          if(comActRaffleRecordVO!=null){
              comActRaffleVO.setComActRaffleRecordVO(comActRaffleRecordVO);
              comActRaffleVO.setJoinStatus(0);
          }
          else {
              if(comActRaffleVO.getStatus()==1){
                  comActRaffleVO.setJoinStatus(1);
              }
              else {
                  comActRaffleVO.setJoinStatus(0);
              }
          }
        }
        return R.ok(comActRaffleVO);
    }
    private Long dateToSecond(Date expireTime){
        return DateUtil.between(new Date(),expireTime, DateUnit.MS);
    }
}