hjl
2024-05-21 f0d8f535a4c09dee9d786d8fb13c9b9918addaa9
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
package com.ruoyi.study.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.study.domain.TUserStudy;
import com.ruoyi.study.mapper.TUserStudyMapper;
import com.ruoyi.study.service.ITUserStudyService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * <p>
 * 自主游戏 服务实现类
 * </p>
 *
 * @author 无关风月
 * @since 2024-04-26
 */
@Service
public class TUserStudyServiceImpl extends ServiceImpl<TUserStudyMapper, TUserStudy> implements ITUserStudyService {
 
    @Override
    public TUserStudy studySchedule(String userId, Integer week, Integer day) {
        return lambdaQuery().eq(TUserStudy::getUserId, userId)
                .eq(TUserStudy::getDay, day).eq(TUserStudy::getWeek, week)
                .eq(TUserStudy::getDisabled, 0).one();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void resettingStudyRecord(String time) {
        List<TUserStudy> list = lambdaQuery().eq(TUserStudy::getDisabled, 0).list();
        switch (time) {
            case Constants.DAY:
                list.forEach(data -> data.setTodayStudy(0));
                break;
            case Constants.WEEK:
                list.forEach(data -> data.setWeekStudy(0));
                break;
            case Constants.MONTH:
                list.forEach(data -> data.setMonthStudy(0));
                break;
            default:
        }
        int number = 0;
        boolean update = this.updateBatchById(list);
        while (!update) {
            if (number >= 3) {
                break;
            }
            update = this.updateBatchById(list);
            number++;
        }
    }
}