huliguo
14 小时以前 60e726c81966b042db4f7b108d06bd36109794de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.ruoyi.goods.service.impl.lottery;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.goods.api.domain.LotteryEvent;
import com.ruoyi.goods.api.domain.LotteryEventQuestionsAnswers;
import com.ruoyi.goods.api.domain.UserLotteryEventQuestionsAnswers;
import com.ruoyi.goods.domain.vo.MgtUserAnswersPageVO;
import com.ruoyi.goods.mapper.lottery.UserLotteryEventQuestionsAnswersMapper;
import com.ruoyi.goods.service.lottery.ILotteryEventQuestionsAnswersService;
import com.ruoyi.goods.service.lottery.ILotteryEventService;
import com.ruoyi.goods.service.lottery.IUserLotteryEventQuestionsAnswersService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
 
 
/**
 * @author zhibing.pu
 * @Date 2025/5/19 16:08
 */
@Service
public class UserLotteryEventQuestionsAnswersServiceImpl extends ServiceImpl<UserLotteryEventQuestionsAnswersMapper, UserLotteryEventQuestionsAnswers> implements IUserLotteryEventQuestionsAnswersService {
    
    @Resource
    private ILotteryEventQuestionsAnswersService lotteryEventQuestionsAnswersService;
    
    
    
    
    
    /**
     * 获取答题正确率
     * @param userId
     * @param lotteryEventId
     * @return
     */
    @Override
    public BigDecimal getCorrectAnswerRate(Long userId, String lotteryEventId) {
        int count = this.count(new QueryWrapper<UserLotteryEventQuestionsAnswers>().eq("user_id", userId).eq("lottery_event_id", lotteryEventId).eq("is_correct", 1));
        if (count > 0) {
            int count1 = lotteryEventQuestionsAnswersService.count(new QueryWrapper<LotteryEventQuestionsAnswers>().eq("lottery_event_id", lotteryEventId));
            return new BigDecimal(count).divide(new BigDecimal(count1), 2, BigDecimal.ROUND_HALF_UP);
        }
        return BigDecimal.ZERO;
    }
 
    @Override
    public List<MgtUserAnswersPageVO> getUserAnswersPage(Page<MgtUserAnswersPageVO> page, String lotteryEventId, Long userId) {
        //获取分页信息
        return  this.getBaseMapper().getUserAnswersPage(page,lotteryEventId,userId);
    }
 
 
}