@Component public class BudgetAdjustmentScheduled { @Resource private IebBudgetAdjustmentMapper budgetAdjustmentMapper;
@Scheduled(cron = "0 0 23 * * ? ") public void budgetAdjustmentScheduled() {
List<IebBudgetAdjustmentPO> budgetAdjustmentPOList = budgetAdjustmentMapper.selectList( new QueryWrapper<IebBudgetAdjustmentPO>() .eq("flow_status", "COMPLETED_PASS") .and( i -> i .eq("adjustment_list_status", "3") .or() .eq("adjustment_list_status", "0") ) );
List<IebBudgetAdjustmentPO> errorList = new ArrayList<>();
if (!CollectionUtils.isEmpty(budgetAdjustmentPOList)) {
for (IebBudgetAdjustmentPO budgetAdjustmentPO : budgetAdjustmentPOList) { int update = 0; try { budgetAdjustmentPO.setLastModifiedBy("系统调整"); budgetAdjustmentPO.setLastModifiedDate(new Date()); budgetAdjustmentPO.setAdjustmentListStatus(IebBudgetAdjustmentAdjustmentListStatusEnum.ADJUSTMENTLISTSTATUS_2); update = budgetAdjustmentMapper.update( new UpdateWrapper<IebBudgetAdjustmentPO>() .eq("id", budgetAdjustmentPO.getId()) ); } catch (Exception exception) { exception.printStackTrace(); } finally { if (update != 1) { errorList.add(budgetAdjustmentPO); } } } }
if (!CollectionUtils.isEmpty(errorList)) { asyncBudgetAdjustmentScheduled(errorList); }
}
public void asyncBudgetAdjustmentScheduled(List<IebBudgetAdjustmentPO> errorList) {
CountDownLatch countDownLatch = new CountDownLatch(1);
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(errorList.size());
ScheduledFuture<?> scheduledFuture = scheduledThreadPoolExecutor.scheduleAtFixedRate( () -> { new BudgetAdjustmentListTask(errorList, countDownLatch); }, 0, 5, TimeUnit.MINUTES );
try {
countDownLatch.await();
scheduledFuture.cancel(true); } catch (Exception e) { e.printStackTrace(); }finally {
scheduledThreadPoolExecutor.shutdown(); }
}
}
|