skyouc
15 小时以前 0b2e709d64339f06b4ede5ef1c8f17345aa8e653
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.vincent.rsf.server.manager.schedules;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.common.constant.Constants;
import com.vincent.rsf.server.manager.entity.Wave;
import com.vincent.rsf.server.manager.entity.WaveItem;
import com.vincent.rsf.server.manager.enums.WaveExceStatus;
import com.vincent.rsf.server.manager.enums.WaveItemExceStatus;
import com.vincent.rsf.server.manager.service.WaveItemService;
import com.vincent.rsf.server.manager.service.WaveService;
import com.vincent.rsf.server.system.constant.GlobalConfigCode;
import com.vincent.rsf.server.system.entity.Config;
import com.vincent.rsf.server.system.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
* @author Ryan
* @description 波次定时任务
* @param
* @return
* @time 2025/6/23 13:49
*/
@Component
public class WaveSchedules {
 
 
    @Autowired
    private WaveService waveService;
 
    @Autowired
    private WaveItemService waveItemService;
 
    @Autowired
    private ConfigService configService;
 
 
 
    /**
    * @author Ryan
    * @description 自动下发波次任务
    * @param
    * @return
    * @time 2025/6/23 13:52
    */
    @Scheduled(cron = "0/15 * * * * ?")
    public void autoGenerateTask() {
        Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.WAVE_AUTO_EXCE_TASK));
        if (Objects.isNull(config) || !Boolean.parseBoolean(config.getVal())) {
            return;
        }
        List<Wave> list = waveService.list(new LambdaQueryWrapper<Wave>()
                        .select(Wave::getId)
                .eq(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_INIT.val));
        if (list.isEmpty()) {
            return;
        }
        List<Long> longs = list.stream().map(Wave::getId).collect(Collectors.toList());
 
        List<WaveItem> waveItems = waveItemService.list(new LambdaQueryWrapper<WaveItem>()
                .in(WaveItem::getId, longs)
                .eq(WaveItem::getExceStatus, WaveItemExceStatus.WAVE_ITEM_EXCE_STATUS_UN.val)
        );
        if (waveItems.isEmpty()) {
            return;
        }
        Map<Long, List<WaveItem>> listMap = waveItems.stream().collect(Collectors.groupingBy(WaveItem::getWaveId));
        listMap.keySet().forEach(waveId -> {
            Map<String, Object> params = new HashMap<>();
            params.put("wave", waveId);
            params.put("waveItems", waveItems);
            waveService.waveToTask(params, waveId);
        });
    }
}