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;
|
}
|
}
|
}
|
}
|