首次提交代码

This commit is contained in:
zhouxiunai
2018-11-23 09:08:15 +08:00
commit 047ae94f64
21 changed files with 857 additions and 0 deletions
@@ -0,0 +1,76 @@
package com.gzzn.omms.msgexchangeapi.task;
import java.io.IOException;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.gzzn.omms.msgexchangeapi.dao.CminmsgDao;
import com.gzzn.omms.msgexchangeapi.entiy.Cminmsg;
import com.gzzn.omms.msgexchangeapi.service.IExchangeService;
import com.gzzn.omms.msgexchangeapi.service.IKafkaService;
/**
* 转换任务,获取cim的消息,转换成json,写入到kafka队列中
* @author Administrator
*
*/
@Component
public class ExchangeTask {
private static Logger logger = LoggerFactory.getLogger(ExchangeTask.class);
@Autowired
private IKafkaService kafkaservice;
@Autowired
IExchangeService exchangeService;
@Autowired
private CminmsgDao cminmsgDao;
@Scheduled(cron="0 0/1 * * * ?")
public void corn()
{
logger.info("定时任务启动....");
Long maxPerLong = 1000L; //每次最大发送多少条消息
Long lenTotal = cminmsgDao.getCminmsgsDateProcessedIsNotNullCount();
Long lenSend = 0L;
Integer pageIndex = 0;
Integer pageSize = 50;
while(lenSend < lenTotal && lenSend < maxPerLong)
{
List<Cminmsg> ls = cminmsgDao.findByCminmsgsDateProcessedIsNotNull(new PageRequest(pageIndex,pageSize));
ls.forEach(x -> {
String strJson = null;
try {
strJson = exchangeService.xmlToJson(x.getCminmsgsClobMsg());
if(!StringUtils.isEmpty(strJson))
{
kafkaservice.msgSend("topic2", strJson);
}
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
});
lenSend += ls.size();
pageIndex++;
}
//
logger.info("同步完成");
}
}