SupplementUploadJob.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.yihu.hos.central.rest.job;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.yihu.hos.central.rest.constants.RedisCollection;
  4. import com.yihu.hos.central.rest.services.crawler.CrawlerManager;
  5. import com.yihu.hos.central.rest.services.qc.EsSimplePackage;
  6. import com.yihu.hos.core.log.Logger;
  7. import com.yihu.hos.core.log.LoggerFactory;
  8. import com.yihu.hos.web.framework.util.springutil.SpringBeanUtil;
  9. import org.quartz.DisallowConcurrentExecution;
  10. import org.quartz.InterruptableJob;
  11. import org.quartz.JobExecutionContext;
  12. import org.quartz.UnableToInterruptJobException;
  13. import org.springframework.data.redis.core.RedisTemplate;
  14. import org.springframework.stereotype.Component;
  15. import java.io.Serializable;
  16. /**
  17. * 补传省平台任务。(获取补传队列中数据,上传省平台)
  18. *
  19. * @author hzy
  20. * @version 1.0
  21. * @created 2018.06.12
  22. */
  23. @Component
  24. @DisallowConcurrentExecution
  25. public class SupplementUploadJob implements InterruptableJob {
  26. private static final Logger logger = LoggerFactory.getLogger(SupplementUploadJob.class);
  27. static CrawlerManager crawlerManager = null;
  28. static {
  29. crawlerManager = SpringBeanUtil.getService(CrawlerManager.class);
  30. // if (!crawlerManager.getDataForPrepare(null)) {
  31. // logger.info("缓存默认适配版本失败");
  32. // //将机构字典缓存起来
  33. // } else {
  34. // logger.info("缓存默认适配版本成功");
  35. // }
  36. }
  37. @Override
  38. public void interrupt() throws UnableToInterruptJobException {
  39. logger.info("interrup============================================================");
  40. }
  41. @Override
  42. public void execute(JobExecutionContext context) {
  43. //该对象要采用名称的方式获取,否则:expected single matching bean but found 3: redisTemplate,sessionRedisTemplate,stringRedisTemplate
  44. CrawlerManager crawlerManager = SpringBeanUtil.getService(CrawlerManager.class);
  45. if (!crawlerManager.getDataForPrepare(null)) {
  46. logger.info("缓存默认适配版本失败__补传");
  47. throw new RuntimeException("缓存默认适配版本失败——补传");
  48. //将机构字典缓存起来
  49. }
  50. RedisTemplate<String, Serializable> redisTemplate = SpringBeanUtil.getService("redisTemplate");
  51. ObjectMapper objectMapper = SpringBeanUtil.getService(ObjectMapper.class);
  52. Serializable serializable = redisTemplate.opsForList().rightPop(RedisCollection.PROVINCIAL_PLATFORM_QUEUE_SUPPLEMENT);
  53. EsSimplePackage pack = null;
  54. try {
  55. if (serializable != null) {
  56. String packStr = serializable.toString();
  57. pack = objectMapper.readValue(packStr, EsSimplePackage.class);
  58. }
  59. if (pack != null) {
  60. //上传省平台
  61. Boolean aBoolean = crawlerManager.collectProcessByRowkey(pack);
  62. if (!aBoolean) {
  63. logger.error("补传--获取资源数据上传省平台失败~!");
  64. }
  65. }
  66. } catch (Exception e) {
  67. e.printStackTrace();
  68. }
  69. }
  70. }