12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package com.yihu.hos.central.rest.job;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.yihu.hos.central.rest.constants.RedisCollection;
- import com.yihu.hos.central.rest.services.crawler.CrawlerManager;
- import com.yihu.hos.central.rest.services.qc.EsSimplePackage;
- import com.yihu.hos.core.log.Logger;
- import com.yihu.hos.core.log.LoggerFactory;
- import com.yihu.hos.web.framework.util.springutil.SpringBeanUtil;
- import org.quartz.DisallowConcurrentExecution;
- import org.quartz.InterruptableJob;
- import org.quartz.JobExecutionContext;
- import org.quartz.UnableToInterruptJobException;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.stereotype.Component;
- import java.io.Serializable;
- /**
- * 补传省平台任务。(获取补传队列中数据,上传省平台)
- *
- * @author hzy
- * @version 1.0
- * @created 2018.06.12
- */
- @Component
- @DisallowConcurrentExecution
- public class SupplementUploadJob implements InterruptableJob {
- private static final Logger logger = LoggerFactory.getLogger(SupplementUploadJob.class);
- static CrawlerManager crawlerManager = null;
- static {
- crawlerManager = SpringBeanUtil.getService(CrawlerManager.class);
- // if (!crawlerManager.getDataForPrepare(null)) {
- // logger.info("缓存默认适配版本失败");
- // //将机构字典缓存起来
- // } else {
- // logger.info("缓存默认适配版本成功");
- // }
- }
- @Override
- public void interrupt() throws UnableToInterruptJobException {
- logger.info("interrup============================================================");
- }
- @Override
- public void execute(JobExecutionContext context) {
- //该对象要采用名称的方式获取,否则:expected single matching bean but found 3: redisTemplate,sessionRedisTemplate,stringRedisTemplate
- CrawlerManager crawlerManager = SpringBeanUtil.getService(CrawlerManager.class);
- if (!crawlerManager.getDataForPrepare(null)) {
- logger.info("缓存默认适配版本失败__补传");
- throw new RuntimeException("缓存默认适配版本失败——补传");
- //将机构字典缓存起来
- }
- RedisTemplate<String, Serializable> redisTemplate = SpringBeanUtil.getService("redisTemplate");
- ObjectMapper objectMapper = SpringBeanUtil.getService(ObjectMapper.class);
- Serializable serializable = redisTemplate.opsForList().rightPop(RedisCollection.PROVINCIAL_PLATFORM_QUEUE_SUPPLEMENT);
- EsSimplePackage pack = null;
- try {
- if (serializable != null) {
- String packStr = serializable.toString();
- pack = objectMapper.readValue(packStr, EsSimplePackage.class);
- }
- if (pack != null) {
- //上传省平台
- Boolean aBoolean = crawlerManager.collectProcessByRowkey(pack);
- if (!aBoolean) {
- logger.error("补传--获取资源数据上传省平台失败~!");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
|