1.添加立即下载数据接口代码
							parent
							
								
									3c78de6bc6
								
							
						
					
					
						commit
						a832339ea8
					
				| @ -0,0 +1,16 @@ | |||||||
|  | package com.glxp.api.admin.req.sync; | ||||||
|  | 
 | ||||||
|  | import lombok.Data; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 下载任务信息 | ||||||
|  |  */ | ||||||
|  | @Data | ||||||
|  | public class PostDownloadInfo { | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 下载类型 | ||||||
|  |      */ | ||||||
|  |     private Integer type; | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,77 @@ | |||||||
|  | package com.glxp.api.admin.thread; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import cn.hutool.core.date.DateTime; | ||||||
|  | import cn.hutool.core.date.DateUtil; | ||||||
|  | import cn.hutool.core.util.StrUtil; | ||||||
|  | import cn.hutool.json.JSONUtil; | ||||||
|  | import com.glxp.api.admin.constant.Constant; | ||||||
|  | import com.glxp.api.admin.dao.schedule.ScheduledDao; | ||||||
|  | import com.glxp.api.admin.entity.info.ScheduledEntity; | ||||||
|  | import com.glxp.api.admin.req.info.ScheduledRequest; | ||||||
|  | import com.glxp.api.admin.util.RedisUtil; | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
|  | import org.springframework.scheduling.annotation.EnableScheduling; | ||||||
|  | import org.springframework.scheduling.annotation.SchedulingConfigurer; | ||||||
|  | import org.springframework.scheduling.config.ScheduledTaskRegistrar; | ||||||
|  | import org.springframework.scheduling.support.CronTrigger; | ||||||
|  | import org.springframework.stereotype.Component; | ||||||
|  | 
 | ||||||
|  | import javax.annotation.Resource; | ||||||
|  | import java.util.Map; | ||||||
|  | 
 | ||||||
|  | @Slf4j | ||||||
|  | @Component | ||||||
|  | @EnableScheduling | ||||||
|  | public class DownloadSpDataTask implements SchedulingConfigurer { | ||||||
|  | 
 | ||||||
|  |     @Resource | ||||||
|  |     private ScheduledDao scheduledDao; | ||||||
|  |     @Resource | ||||||
|  |     private RedisUtil redisUtil; | ||||||
|  |     @Resource | ||||||
|  |     private DlBasicService dlBasicService; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { | ||||||
|  |         taskRegistrar.addTriggerTask(this::process, triggerContext -> { | ||||||
|  |             ScheduledRequest scheduledRequest = new ScheduledRequest(); | ||||||
|  |             scheduledRequest.setCronName("downloadSpDataTask"); | ||||||
|  |             ScheduledEntity scheduled = scheduledDao.findScheduled(scheduledRequest); | ||||||
|  |             String cron = scheduled.getCron(); | ||||||
|  |             if (StrUtil.isBlank(cron)) { | ||||||
|  |                 log.error("cron is null"); | ||||||
|  |             } | ||||||
|  |             return new CronTrigger(cron).nextExecutionTime(triggerContext); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void process() { | ||||||
|  |         Object result = redisUtil.get(Constant.SPS_SYNC_DOWNLOAD_INFO); | ||||||
|  |         if (null != result) { | ||||||
|  |             //解析下载参数
 | ||||||
|  |             Map map = JSONUtil.toBean(String.valueOf(result), Map.class); | ||||||
|  |             DateTime taskTime = DateUtil.date(Long.valueOf(String.valueOf(map.get("time")))); | ||||||
|  |             if (DateUtil.date().getTime() <= taskTime.getTime()) { | ||||||
|  |                 Integer type = Integer.valueOf(String.valueOf(map.get("type"))); | ||||||
|  |                 if (type == 1) { | ||||||
|  |                     log.info("开始下载基础信息"); | ||||||
|  |                     dlBasicService.dlAllData(); | ||||||
|  |                     log.info("基础信息下载完毕"); | ||||||
|  |                 } else if (type == 2) { | ||||||
|  |                     log.info("开始下载单据类型"); | ||||||
|  |                     dlBasicService.dlAllBus(); | ||||||
|  |                     log.info("单据类型下载完毕"); | ||||||
|  |                 } else if ((type == 3)) { | ||||||
|  |                     log.info("开始下载扫码单据"); | ||||||
|  |                     dlBasicService.dlAllOrder(); | ||||||
|  |                     log.info("扫码单据下载完毕"); | ||||||
|  |                 } else if (type == 4) { | ||||||
|  |                     log.info("开始下载国家库数据"); | ||||||
|  |                     dlBasicService.dlAllUDI(); | ||||||
|  |                     log.info("国家库数据下载完毕"); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in New Issue