101captain
2022-02-22 fd22a2c83f60ff0daebff5fdb78f637f17d58cee
三社功能提交
10个文件已修改
135 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/ComActRaffleRecordApi.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/raffle/ComActRaffleRecordVO.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/community/CommunityService.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/ComActRaffleRecordApi.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComActRafflePrizeDao.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComActRaffleRecordDao.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/RaffleMessage.java 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActRaffleRecordService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActRaffleRecordServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/resources/mapper/ComActRaffleRecordMapper.xml 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/ComActRaffleRecordApi.java
@@ -91,4 +91,15 @@
        comActRaffleRecordVO.setStatus(0);
        return communityService.insertRaffleRecord(comActRaffleRecordVO);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("详情")
    @GetMapping("{id}")
    public R selectOne(@PathVariable("id") Long id) {
        return this.communityService.selectOneRaffleRecord(id);
    }
}
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/raffle/ComActRaffleRecordVO.java
@@ -1,5 +1,6 @@
package com.panzhihua.common.model.vos.community.raffle;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
@@ -81,4 +82,18 @@
    @ApiModelProperty(value = "联系电话")
    private String phone;
    /**
     * 兑奖开始时间
     */
    @ApiModelProperty(value = "兑奖开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date raffleStartTime;
    /**
     * 兑奖结束时间
     */
    @ApiModelProperty(value = "兑奖结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date raffleStopTime;
}
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/community/CommunityService.java
@@ -8129,6 +8129,15 @@
    @PostMapping("/comActRaffleRecord")
    R insertRaffleRecord(@RequestBody ComActRaffleRecordVO comActRaffleRecordVO);
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/comActRaffleRecord/{id}")
    R selectOneRaffleRecord(@PathVariable("id") Long id);
    /**
     * 导出
     *
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/ComActRaffleRecordApi.java
@@ -68,8 +68,8 @@
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable("id") Serializable id) {
        return R.ok(this.comActRaffleRecordService.getById(id));
    public R selectOne(@PathVariable("id") Long id) {
        return R.ok(this.comActRaffleRecordService.selectById(id));
    }
    /**
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComActRafflePrizeDao.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.panzhihua.common.model.vos.community.raffle.ComActRafflePrizeCount;
import com.panzhihua.common.model.vos.community.raffle.ComActRafflePrizeVO;
import com.panzhihua.common.model.vos.community.raffle.ComActRaffleRecordVO;
import org.apache.ibatis.annotations.Mapper;
import com.panzhihua.service_community.entity.ComActRafflePrize;
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComActRaffleRecordDao.java
@@ -45,4 +45,12 @@
     * @return
     */
    List<ComActRaffleRecordExcelVO> export(@Param("commonPage")CommonPage commonPage);
    /**
     * 根据id查询
     * @param id
     * @return
     */
    ComActRaffleRecordVO selectById(Long id);
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/message/RaffleMessage.java
@@ -1,14 +1,25 @@
package com.panzhihua.service_community.message;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.panzhihua.common.model.vos.community.raffle.ComActRaffleVO;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.ComActRaffleDao;
import com.panzhihua.service_community.dao.ComActRafflePrizeDao;
import com.panzhihua.service_community.dao.ComActRaffleRecordDao;
import com.panzhihua.service_community.entity.ComActRaffle;
import com.panzhihua.service_community.entity.ComActRafflePrize;
import com.panzhihua.service_community.entity.ComActRaffleRecord;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
/**
 * @author zzj
@@ -19,12 +30,61 @@
    @Resource
    private ComActRaffleDao comActRaffleDao;
    @Resource
    private ComActRaffleRecordDao comActRaffleRecordDao;
    @Resource
    private ComActRafflePrizeDao comActRafflePrizeDao;
    @Resource
    private RabbitTemplate rabbitTemplate;
    @RabbitListener(queues=DELAYED_QUEUE)
    public void doRaffle(ComActRaffleVO comActRaffleVO){
        ComActRaffle comActRaffle=comActRaffleDao.selectOne(new QueryWrapper<ComActRaffle>().lambda().eq(ComActRaffle::getId,comActRaffleVO.getId()));
        if(comActRaffle!=null&&comActRaffle.getStatus()==0&&comActRaffle.getLotteryTime().before(new Date())){
        if(comActRaffle!=null&&comActRaffle.getStatus()==2&&comActRaffle.getLotteryTime().before(new Date())){
            List<ComActRafflePrize> comActRafflePrizeList=comActRafflePrizeDao.selectList(new QueryWrapper<ComActRafflePrize>().lambda().eq(ComActRafflePrize::getRaffleId,comActRaffleVO.getId()));
            if(StringUtils.isNotEmpty(comActRafflePrizeList)){
                List<ComActRaffleRecord> comActRaffleRecords=comActRaffleRecordDao.selectList(new QueryWrapper<ComActRaffleRecord>().lambda().eq(ComActRaffleRecord::getRaffleId,comActRaffleVO.getId()));
                if(StringUtils.isNotEmpty(comActRaffleRecords)){
                    Random random=new Random();
                    comActRafflePrizeList.forEach(comActRafflePrize -> {
                        int a=0;
                        for(int i=1;i<=comActRafflePrize.getSurplus();i++){
                            if(comActRaffleRecords.size()>0){
                                ComActRaffleRecord comActRaffleRecord=comActRaffleRecords.get(random.nextInt(comActRaffleRecords.size()));
                                comActRaffleRecord.setPrizeId(comActRafflePrize.getId());
                                comActRaffleRecord.setStatus(1);
                                comActRaffleRecordDao.updateById(comActRaffleRecord);
                                comActRaffleRecords.remove(comActRaffleRecord);
                                a++;
                            }
                        }
                        comActRafflePrize.setSurplus(comActRafflePrize.getSurplus()-a);
                        comActRafflePrizeDao.updateById(comActRafflePrize);
                    });
                }
            }
            comActRaffle.setStatus(3);
            comActRaffleDao.updateById(comActRaffle);
        }
        if(comActRaffle!=null&&comActRaffle.getStatus()==0&&comActRaffle.getStartTime().before(new Date())){
            comActRaffle.setStatus(1);
            comActRaffleDao.updateById(comActRaffle);
            rabbitTemplate.convertAndSend("raffle.exchange", "raffle.key", comActRaffleVO, message -> {
                message.getMessageProperties().setHeader("x-delay", dateToSecond(comActRaffle.getStopTime()));
                return message;
            });
        }
        if(comActRaffle!=null&&comActRaffle.getStatus()==1&&comActRaffle.getStopTime().before(new Date())){
            comActRaffle.setStatus(2);
            comActRaffleDao.updateById(comActRaffle);
            rabbitTemplate.convertAndSend("raffle.exchange", "raffle.key", comActRaffleVO, message -> {
                message.getMessageProperties().setHeader("x-delay", dateToSecond(comActRaffle.getLotteryTime()));
                return message;
            });
        }
    }
    private Long dateToSecond(Date expireTime){
        return DateUtil.between(new Date(),expireTime, DateUnit.MS);
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActRaffleRecordService.java
@@ -44,4 +44,11 @@
     * @return
     */
    R export(CommonPage commonPage);
    /**
     * 根据Id查询
     * @param id
     * @return
     */
    R selectById(Long id);
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActRaffleRecordServiceImpl.java
@@ -56,4 +56,9 @@
    public R export(CommonPage commonPage) {
        return R.ok(this.baseMapper.export(commonPage));
    }
    @Override
    public R selectById(Long id) {
        return R.ok(this.baseMapper.selectById(id));
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/resources/mapper/ComActRaffleRecordMapper.xml
@@ -21,11 +21,12 @@
    </select>
    <select id="pageList" resultType="com.panzhihua.common.model.vos.community.raffle.ComActRaffleRecordVO">
        select t.*, t1.image, t1.name as prizeName, t2.nick_name, t2.phone, t2.`name` as username, t3.name as staffName
        select t.*, t1.image, t1.name as prizeName, t2.nick_name, t2.phone, t2.`name` as username, t3.name as staffName,t4.raffle_start_time as raffleStartTime,t4.raffle_stop_time as raffleStopTime
        from com_act_raffle_record t
        left join com_act_raffle_prize t1 on t.prize_id = t1.id
        left join sys_user t2 on t.user_id = t2.user_id
        left join sys_user t3 on t.staff_id = t3.user_id
        left join com_act_raffle t4 on t.raffle_id = t4.id
        <where>
            <if test="commonPage.status!=null">
                and t.status = #{commonPage.status}
@@ -39,6 +40,9 @@
            </if>
            <if test="commonPage.userId !=null">
                and t.user_id = #{commonPage.userId}
            </if>
            <if test="commonPage.paramId2 !=null">
                and t.staff_id = #{commonPage.paramId2}
            </if>
        </where>
        order by t.create_time desc
@@ -67,4 +71,11 @@
        </where>
        order by t.create_time desc
    </select>
    <select id="selectById" resultType="com.panzhihua.common.model.vos.community.raffle.ComActRaffleRecordVO">
        select t.*, t1.`name`, t1.image
        from com_act_raffle_record t
        LEFT JOIN com_act_raffle_prize t1 on t.prize_id = t1.id
        where t.id=#{id}
    </select>
</mapper>