Pu Zhibing
5 天以前 ea1a62ba6484d6c6cb1ca67dcea938a95ba18fc6
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
package com.ruoyi.goods.service.impl.lottery;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.goods.api.domain.LotteryEventQuestionsAnswers;
import com.ruoyi.goods.api.domain.UserLotteryEventQuestionsAnswers;
import com.ruoyi.goods.mapper.lottery.UserLotteryEventQuestionsAnswersMapper;
import com.ruoyi.goods.service.lottery.ILotteryEventQuestionsAnswersService;
import com.ruoyi.goods.service.lottery.IUserLotteryEventQuestionsAnswersService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
 
 
 
/**
 * @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;
    }
 
 
}