hjl
2024-06-06 81714ac84eb9cf515c0dbf701b5b87d02bafb6bd
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
package com.ruoyi.study.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.study.domain.TGame;
import com.ruoyi.study.domain.TIntegralRecord;
import com.ruoyi.study.dto.CompleteGameDTO;
import com.ruoyi.study.mapper.TGameMapper;
import com.ruoyi.study.service.ITGameService;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 自主游戏 服务实现类
 * </p>
 *
 * @author 无关风月
 * @since 2024-04-26
 */
@Service
public class TGameServiceImpl extends ServiceImpl<TGameMapper, TGame> implements ITGameService {
 
    @Override
    public Integer countIntegral(Integer userid, TGame game, CompleteGameDTO completeStudy, List<TIntegralRecord> integralRecordList) {
        // 本次游戏可获得积分数量
        Integer availableIntegral = completeStudy.getAvailableIntegral();
        // 积分明细集合为空,当前为第一次完成游戏
        if (integralRecordList.isEmpty()) {
            return availableIntegral;
        } else {
            // 积分明细不为空,根据正确率及已获取积分数量计算本次答题可获取的积分数量
            List<Integer> integralList = integralRecordList.stream().map(TIntegralRecord::getIntegral).collect(Collectors.toList())
                    .stream().map(Integer::parseInt).collect(Collectors.toList());
            int sumIntegral = integralList.stream().mapToInt(Integer::intValue).sum();
            if (availableIntegral > sumIntegral) {
                return availableIntegral - sumIntegral;
            } else {
                return null;
            }
        }
    }
}