|  |  |  | @ -1,6 +1,7 @@ | 
			
		
	
		
			
				
					|  |  |  |  | package com.glxp.api.task; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.collection.CollUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.thread.ExecutorBuilder; | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.thread.ThreadUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.inv.InvRemindSetDao; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.schedule.ScheduledDao; | 
			
		
	
	
		
			
				
					|  |  |  | @ -16,6 +17,8 @@ import org.springframework.stereotype.Component; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import javax.annotation.Resource; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.List; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.concurrent.ExecutorService; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.concurrent.LinkedBlockingDeque; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | @Slf4j | 
			
		
	
		
			
				
					|  |  |  |  | @Component | 
			
		
	
	
		
			
				
					|  |  |  | @ -28,6 +31,8 @@ public class InvRemindMsgTask implements SchedulingConfigurer { | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     private InvRemindSetDao invRemindSetDao; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private static ExecutorService executor; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { | 
			
		
	
		
			
				
					|  |  |  |  |         taskRegistrar.addTriggerTask(this::process, triggerContext -> { | 
			
		
	
	
		
			
				
					|  |  |  | @ -39,10 +44,19 @@ public class InvRemindMsgTask implements SchedulingConfigurer { | 
			
		
	
		
			
				
					|  |  |  |  |                 return null; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             String cron = scheduled.getCron(); | 
			
		
	
		
			
				
					|  |  |  |  |             initExecutor(); | 
			
		
	
		
			
				
					|  |  |  |  |             return new CronTrigger(cron).nextExecutionTime(triggerContext); | 
			
		
	
		
			
				
					|  |  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void initExecutor() { | 
			
		
	
		
			
				
					|  |  |  |  |         executor = ExecutorBuilder.create() | 
			
		
	
		
			
				
					|  |  |  |  |                 .setCorePoolSize(10) | 
			
		
	
		
			
				
					|  |  |  |  |                 .setMaxPoolSize(300) | 
			
		
	
		
			
				
					|  |  |  |  |                 .setWorkQueue(new LinkedBlockingDeque<>()) | 
			
		
	
		
			
				
					|  |  |  |  |                 .build(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void process() { | 
			
		
	
		
			
				
					|  |  |  |  |         log.info("开始扫描库存信息,生成库存预警消息"); | 
			
		
	
		
			
				
					|  |  |  |  |         List<InvRemindSetEntity> invRemindSetEntities = invRemindSetDao.selectList(null); | 
			
		
	
	
		
			
				
					|  |  |  | @ -50,7 +64,7 @@ public class InvRemindMsgTask implements SchedulingConfigurer { | 
			
		
	
		
			
				
					|  |  |  |  |             log.info("库存预警设置条数:{}", invRemindSetEntities.size()); | 
			
		
	
		
			
				
					|  |  |  |  |             //开始生成库存信息
 | 
			
		
	
		
			
				
					|  |  |  |  |             for (InvRemindSetEntity invRemindSetEntity : invRemindSetEntities) { | 
			
		
	
		
			
				
					|  |  |  |  |                 ThreadUtil.execAsync(ThreadUtil.newThread(() -> invRemindMsgService.createRemindMsg(invRemindSetEntity), "createInvRemindThread")); | 
			
		
	
		
			
				
					|  |  |  |  |                 executor.execute(ThreadUtil.newThread(() -> invRemindMsgService.createRemindMsg(invRemindSetEntity), "createInvRemindThread")); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             log.info("无库存预警设置,结束库存扫描"); | 
			
		
	
	
		
			
				
					|  |  |  | 
 |