无关风月
2024-07-03 f138375f15c072d10335c20ecec9b35f1da78ee4
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TIntegralRecordServiceImpl.java
@@ -1,13 +1,17 @@
package com.ruoyi.study.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.study.domain.TGameRecord;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.study.domain.TIntegralRecord;
import com.ruoyi.study.mapper.TGameRecordMapper;
import com.ruoyi.study.mapper.TIntegralRecordMapper;
import com.ruoyi.study.service.ITGameRecordService;
import com.ruoyi.study.service.ITIntegralRecordService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
 * <p>
@@ -20,4 +24,33 @@
@Service
public class TIntegralRecordServiceImpl extends ServiceImpl<TIntegralRecordMapper, TIntegralRecord> implements ITIntegralRecordService {
    @Resource
    private TokenService tokenService;
    @Override
    public IPage<TIntegralRecord> integralDetail(Page<TIntegralRecord> page, Integer userId, String time) {
        IPage<TIntegralRecord> tIntegralRecordIPage = baseMapper.integralDetail(userId, time, page);
        List<TIntegralRecord> records = tIntegralRecordIPage.getRecords();
        for (TIntegralRecord record : records) {
            if (!record.getIntegral().equals("0") && (!record.getIntegral().contains("-"))){
                record.setIntegral("+" + record.getIntegral());
            }
        }
        tIntegralRecordIPage.setRecords(records);
        return tIntegralRecordIPage;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean add(String integral, String method, Integer gameId, Integer storyId, Integer difficulty, Integer storyType) {
        TIntegralRecord integralRecord = new TIntegralRecord();
        integralRecord.setIntegral(integral);
        integralRecord.setMethod(method);
        integralRecord.setUserId(tokenService.getLoginUserStudy().getUserid());
        integralRecord.setGameId(gameId);
        integralRecord.setStoryId(storyId);
        integralRecord.setGameDifficulty(difficulty);
        integralRecord.setStoryType(storyType);
        return this.save(integralRecord);
    }
}