Merge remote-tracking branch 'origin/master'
						commit
						3c685f15b4
					
				| @ -0,0 +1,49 @@ | |||||||
|  | package com.glxp.api.task; | ||||||
|  | 
 | ||||||
|  | import com.glxp.api.constant.AsyncDiDlHelper; | ||||||
|  | import com.glxp.api.entity.basic.UdiCompanyEntity; | ||||||
|  | import com.glxp.api.service.basic.UdiCompanyService; | ||||||
|  | import org.slf4j.Logger; | ||||||
|  | import org.slf4j.LoggerFactory; | ||||||
|  | import org.springframework.beans.factory.annotation.Value; | ||||||
|  | import org.springframework.scheduling.annotation.Async; | ||||||
|  | import org.springframework.stereotype.Service; | ||||||
|  | 
 | ||||||
|  | import javax.annotation.Resource; | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | @Service | ||||||
|  | public class AsyncCompanyDlHelper { | ||||||
|  |     @Resource | ||||||
|  |     UdiCompanyService udiCompanyService; | ||||||
|  |     @Resource | ||||||
|  |     AsyncDiDlHelper asyncDiDlHelper; | ||||||
|  |     @Value("${UDI_SERVER_URL}") | ||||||
|  |     private String udiUrl; | ||||||
|  | 
 | ||||||
|  |     private static final Logger logger = LoggerFactory.getLogger(AsyncCompanyDlHelper.class); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Async | ||||||
|  |     public void asyncDiByTime(String updateTime) { | ||||||
|  |         int page = 1; | ||||||
|  |         int limit = 300; | ||||||
|  |         while (true) { | ||||||
|  |             logger.info("更新时间:" + updateTime + "----" + page + "----" + limit); | ||||||
|  |             List<UdiCompanyEntity> udiCompanyEntities = asyncDiDlHelper.dlCompanyByTime(udiUrl, page, limit, updateTime); | ||||||
|  |             if (udiCompanyEntities != null && udiCompanyEntities.size() > 0) { | ||||||
|  |                 udiCompanyService.insertUdiCompanys(udiCompanyEntities); | ||||||
|  |                 if (udiCompanyEntities.size() < limit) { | ||||||
|  |                     break; | ||||||
|  |                 } else { | ||||||
|  |                     page++; | ||||||
|  |                 } | ||||||
|  |             } else { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         logger.info("更新时间:" + updateTime + "----" + "下载结束"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,60 @@ | |||||||
|  | package com.glxp.api.task; | ||||||
|  | 
 | ||||||
|  | import com.glxp.api.dao.schedule.ScheduledDao; | ||||||
|  | import com.glxp.api.entity.system.ScheduledEntity; | ||||||
|  | import com.glxp.api.req.system.ScheduledRequest; | ||||||
|  | import com.glxp.api.util.DateUtil; | ||||||
|  | import com.glxp.api.util.RedisUtil; | ||||||
|  | import org.slf4j.Logger; | ||||||
|  | import org.slf4j.LoggerFactory; | ||||||
|  | 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.Date; | ||||||
|  | 
 | ||||||
|  | @Component | ||||||
|  | @EnableScheduling | ||||||
|  | public class AsyncCompanyDlTask implements SchedulingConfigurer { | ||||||
|  | 
 | ||||||
|  |     final Logger logger = LoggerFactory.getLogger(AsyncDiDlTask.class); | ||||||
|  |     @Resource | ||||||
|  |     AsyncCompanyDlHelper udiCompanyTask; | ||||||
|  |     @Resource | ||||||
|  |     RedisUtil redisUtil; | ||||||
|  | 
 | ||||||
|  |     @Resource | ||||||
|  |     private ScheduledDao scheduledDao; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { | ||||||
|  |         scheduledTaskRegistrar.addTriggerTask(() -> process(), | ||||||
|  |                 triggerContext -> { | ||||||
|  |                     ScheduledRequest scheduledRequest = new ScheduledRequest(); | ||||||
|  |                     scheduledRequest.setCronName("syncCompany"); | ||||||
|  |                     ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); | ||||||
|  |                     if (scheduledEntity == null) { | ||||||
|  |                         return null; | ||||||
|  |                     } | ||||||
|  |                     String cron = scheduledEntity.getCron(); | ||||||
|  |                     if (cron.isEmpty()) { | ||||||
|  |                         logger.error("cron is null"); | ||||||
|  |                     } | ||||||
|  |                     return new CronTrigger(cron).nextExecutionTime(triggerContext); | ||||||
|  |                 }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void process() { | ||||||
|  | 
 | ||||||
|  |         String lastUpDiTime = (String) redisUtil.get("lastUpCompanyTime"); | ||||||
|  |         if (lastUpDiTime == null) { | ||||||
|  |             lastUpDiTime = DateUtil.getLastDayFormat(-10); | ||||||
|  |         } | ||||||
|  |         udiCompanyTask.asyncDiByTime(lastUpDiTime); | ||||||
|  |         redisUtil.set("lastUpCompanyTime", DateUtil.formatDate(new Date())); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,52 @@ | |||||||
|  | package com.glxp.api.task; | ||||||
|  | 
 | ||||||
|  | import com.alibaba.fastjson.JSONArray; | ||||||
|  | import com.glxp.api.constant.AsyncDiDlHelper; | ||||||
|  | import com.glxp.api.entity.basic.ProductInfoEntity; | ||||||
|  | import com.glxp.api.service.basic.ProductInfoService; | ||||||
|  | import com.glxp.api.util.CustomUtil; | ||||||
|  | import org.slf4j.Logger; | ||||||
|  | import org.slf4j.LoggerFactory; | ||||||
|  | import org.springframework.beans.factory.annotation.Value; | ||||||
|  | import org.springframework.scheduling.annotation.Async; | ||||||
|  | import org.springframework.stereotype.Service; | ||||||
|  | 
 | ||||||
|  | import javax.annotation.Resource; | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | @Service | ||||||
|  | public class AsyncDiDlService { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Value("${UDI_SERVER_URL}") | ||||||
|  |     private String udiUrl; | ||||||
|  | 
 | ||||||
|  |     @Resource | ||||||
|  |     ProductInfoService productInfoService; | ||||||
|  |     @Resource | ||||||
|  |     AsyncDiDlHelper asyncDiDlHelper; | ||||||
|  |     private static final Logger logger = LoggerFactory.getLogger(AsyncDiDlService.class); | ||||||
|  | 
 | ||||||
|  |     @Async | ||||||
|  |     public void asyncDiByTime(String updateTime) { | ||||||
|  |         int page = 1; | ||||||
|  |         int limit = 200; | ||||||
|  |         while (true) { | ||||||
|  |             logger.info("更新时间:" + updateTime + "----" + page + "----" + limit); | ||||||
|  |             List<ProductInfoEntity> productInfoEntityList = asyncDiDlHelper.dlByTime(udiUrl, page, limit, updateTime); | ||||||
|  |             if (productInfoEntityList != null && productInfoEntityList.size() > 0) { | ||||||
|  |                 productInfoService.insertProductInfos(productInfoEntityList); | ||||||
|  |                 if (productInfoEntityList.size() < limit) { | ||||||
|  |                     break; | ||||||
|  |                 } else { | ||||||
|  |                     page++; | ||||||
|  |                 } | ||||||
|  |             } else { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         logger.info("更新时间:" + updateTime + "----" + "下载结束"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,63 @@ | |||||||
|  | package com.glxp.api.task; | ||||||
|  | 
 | ||||||
|  | import com.glxp.api.dao.schedule.ScheduledDao; | ||||||
|  | import com.glxp.api.entity.system.ScheduledEntity; | ||||||
|  | import com.glxp.api.req.system.ScheduledRequest; | ||||||
|  | import com.glxp.api.util.DateUtil; | ||||||
|  | import com.glxp.api.util.RedisUtil; | ||||||
|  | import org.slf4j.Logger; | ||||||
|  | import org.slf4j.LoggerFactory; | ||||||
|  | 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.Date; | ||||||
|  | 
 | ||||||
|  | @Component | ||||||
|  | @EnableScheduling | ||||||
|  | public class AsyncDiDlTask implements SchedulingConfigurer { | ||||||
|  | 
 | ||||||
|  |     final Logger logger = LoggerFactory.getLogger(AsyncDiDlTask.class); | ||||||
|  |     @Resource | ||||||
|  |     RedisUtil redisUtil; | ||||||
|  |     @Resource | ||||||
|  |     private ScheduledDao scheduledDao; | ||||||
|  |     @Resource | ||||||
|  |     AsyncDiDlService asyncDiDlService; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { | ||||||
|  |         scheduledTaskRegistrar.addTriggerTask(() -> process(), | ||||||
|  |                 triggerContext -> { | ||||||
|  |                     ScheduledRequest scheduledRequest = new ScheduledRequest(); | ||||||
|  |                     scheduledRequest.setCronName("syncDi"); | ||||||
|  |                     ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); | ||||||
|  |                     if (scheduledEntity == null) { | ||||||
|  |                         return null; | ||||||
|  |                     } | ||||||
|  |                     String cron = scheduledEntity.getCron();//"0 55 5 * * ?";
 | ||||||
|  |                     if (cron.isEmpty()) { | ||||||
|  |                         logger.error("cron is null"); | ||||||
|  |                     } | ||||||
|  |                     return new CronTrigger(cron).nextExecutionTime(triggerContext); | ||||||
|  |                 }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void process() { | ||||||
|  |         String day = DateUtil.getLastDayFormat(-1); | ||||||
|  |         asyncDiDlService.asyncDiByTime(day); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         String lastUpDiTime = (String) redisUtil.get("lastDiUpTime"); | ||||||
|  |         if (lastUpDiTime == null) { | ||||||
|  |             lastUpDiTime = DateUtil.getLastDayFormat(-10); | ||||||
|  |         } | ||||||
|  |         asyncDiDlService.asyncDiByTime(lastUpDiTime); | ||||||
|  |         redisUtil.set("lastDiUpTime", DateUtil.formatDate(new Date())); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in New Issue