| package com.vincent.rsf.server.manager.schedules; | 
|   | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 
| 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.manager.service.impl.TaskItemServiceImpl; | 
| 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 com.vincent.rsf.server.system.utils.SystemAuthUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.scheduling.annotation.Scheduled; | 
| import org.springframework.stereotype.Component; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.*; | 
| import java.util.stream.Collectors; | 
|   | 
| /** | 
|  * @param | 
|  * @author Ryan | 
|  * @description 波次定时任务 | 
|  * @return | 
|  * @time 2025/6/23 13:49 | 
|  */ | 
| @Component | 
| public class WaveSchedules { | 
|   | 
|   | 
|     @Autowired | 
|     private WaveService waveService; | 
|   | 
|     @Autowired | 
|     private WaveItemService waveItemService; | 
|   | 
|     @Autowired | 
|     private ConfigService configService; | 
|     @Autowired | 
|     private TaskItemServiceImpl taskItemService; | 
|   | 
|   | 
|     /** | 
|      * @param | 
|      * @return | 
|      * @author Ryan | 
|      * @description 自动下发波次任务 | 
|      * @time 2025/6/23 13:52 | 
|      */ | 
|     @Scheduled(cron = "0/15 * * * * ?") | 
| //    @Transactional(rollbackFor = Exception.class) | 
|     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) | 
|                 .in(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_INIT.val | 
|                         , WaveExceStatus.WAVE_EXCE_STATUS_EXCING.val)); | 
|         if (list.isEmpty()) { | 
|             return; | 
|         } | 
|   | 
|         List<Long> longs = list.stream().map(Wave::getId).collect(Collectors.toList()); | 
|   | 
|         waveItemService.update(new LambdaUpdateWrapper<WaveItem>() | 
|                 .in(WaveItem::getWaveId, longs) | 
|                 .set(WaveItem::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_EXCING.val) | 
|                 .apply("anfme > work_qty")); | 
|   | 
|         Long loginUserId = SystemAuthUtils.getLoginUserId(); | 
|         Map<String, Object> params = new HashMap<>(); | 
|         params.put("ids", longs); | 
|         waveService.waveToTask(params, loginUserId); | 
|     } | 
|   | 
| } |