添加runner ,启动时发送获取日航班计划的消息
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.gzzn.omms.msgexchangeapi.dao;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.entiy.Cmoutmsg;
|
||||
|
||||
|
||||
public interface CmoutmsgDao extends CrudRepository<Cmoutmsg, Long> {
|
||||
|
||||
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import java.util.Date;
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="CMINMSGS")
|
||||
@NamedQuery(name="Cminmsg.findAll", query="SELECT c FROM Cminmsg c")
|
||||
public class Cminmsg implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.gzzn.omms.msgexchangeapi.entiy;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* The persistent class for the CMINMSGS database table.
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="CMOUTMSGS")
|
||||
public class Cmoutmsg implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.SEQUENCE)
|
||||
@Column(name="CMINMSGS_ID")
|
||||
private long cminmsgsId;
|
||||
|
||||
@Lob
|
||||
@Column(name="CMINMSGS_CLOB_MSG")
|
||||
private String cminmsgsClobMsg;
|
||||
|
||||
@Temporal(TemporalType.DATE)
|
||||
@Column(name="CMINMSGS_DATE_PROCESSED")
|
||||
private Date cminmsgsDateProcessed;
|
||||
|
||||
@Temporal(TemporalType.DATE)
|
||||
@Column(name="CMINMSGS_DATE_RECEIVED")
|
||||
private Date cminmsgsDateReceived;
|
||||
|
||||
@Column(name="CMINMSGS_STATUS")
|
||||
private String cminmsgsStatus;
|
||||
|
||||
@Temporal(TemporalType.DATE)
|
||||
@Column(name="CMINMSGS_SUBSYSTEM_DATE_SENT")
|
||||
private Date cminmsgsSubsystemDateSent;
|
||||
|
||||
@Column(name="CMINMSGS_SUBSYSTEM_NAME")
|
||||
private String cminmsgsSubsystemName;
|
||||
|
||||
@Column(name="CMINMSGS_SUBSYSTEM_SEQUENCE")
|
||||
private String cminmsgsSubsystemSequence;
|
||||
|
||||
@Column(name="CMINMSGS_SUBSYSTEM_SUBTYPE")
|
||||
private String cminmsgsSubsystemSubtype;
|
||||
|
||||
@Column(name="CMINMSGS_SUBSYSTEM_TYPE")
|
||||
private String cminmsgsSubsystemType;
|
||||
|
||||
public Cmoutmsg() {
|
||||
}
|
||||
|
||||
public long getCminmsgsId() {
|
||||
return this.cminmsgsId;
|
||||
}
|
||||
|
||||
public void setCminmsgsId(long cminmsgsId) {
|
||||
this.cminmsgsId = cminmsgsId;
|
||||
}
|
||||
|
||||
public String getCminmsgsClobMsg() {
|
||||
return this.cminmsgsClobMsg;
|
||||
}
|
||||
|
||||
public void setCminmsgsClobMsg(String cminmsgsClobMsg) {
|
||||
this.cminmsgsClobMsg = cminmsgsClobMsg;
|
||||
}
|
||||
|
||||
public Date getCminmsgsDateProcessed() {
|
||||
return this.cminmsgsDateProcessed;
|
||||
}
|
||||
|
||||
public void setCminmsgsDateProcessed(Date cminmsgsDateProcessed) {
|
||||
this.cminmsgsDateProcessed = cminmsgsDateProcessed;
|
||||
}
|
||||
|
||||
public Date getCminmsgsDateReceived() {
|
||||
return this.cminmsgsDateReceived;
|
||||
}
|
||||
|
||||
public void setCminmsgsDateReceived(Date cminmsgsDateReceived) {
|
||||
this.cminmsgsDateReceived = cminmsgsDateReceived;
|
||||
}
|
||||
|
||||
public String getCminmsgsStatus() {
|
||||
return this.cminmsgsStatus;
|
||||
}
|
||||
|
||||
public void setCminmsgsStatus(String cminmsgsStatus) {
|
||||
this.cminmsgsStatus = cminmsgsStatus;
|
||||
}
|
||||
|
||||
public Date getCminmsgsSubsystemDateSent() {
|
||||
return this.cminmsgsSubsystemDateSent;
|
||||
}
|
||||
|
||||
public void setCminmsgsSubsystemDateSent(Date cminmsgsSubsystemDateSent) {
|
||||
this.cminmsgsSubsystemDateSent = cminmsgsSubsystemDateSent;
|
||||
}
|
||||
|
||||
public String getCminmsgsSubsystemName() {
|
||||
return this.cminmsgsSubsystemName;
|
||||
}
|
||||
|
||||
public void setCminmsgsSubsystemName(String cminmsgsSubsystemName) {
|
||||
this.cminmsgsSubsystemName = cminmsgsSubsystemName;
|
||||
}
|
||||
|
||||
public String getCminmsgsSubsystemSequence() {
|
||||
return this.cminmsgsSubsystemSequence;
|
||||
}
|
||||
|
||||
public void setCminmsgsSubsystemSequence(String cminmsgsSubsystemSequence) {
|
||||
this.cminmsgsSubsystemSequence = cminmsgsSubsystemSequence;
|
||||
}
|
||||
|
||||
public String getCminmsgsSubsystemSubtype() {
|
||||
return this.cminmsgsSubsystemSubtype;
|
||||
}
|
||||
|
||||
public void setCminmsgsSubsystemSubtype(String cminmsgsSubsystemSubtype) {
|
||||
this.cminmsgsSubsystemSubtype = cminmsgsSubsystemSubtype;
|
||||
}
|
||||
|
||||
public String getCminmsgsSubsystemType() {
|
||||
return this.cminmsgsSubsystemType;
|
||||
}
|
||||
|
||||
public void setCminmsgsSubsystemType(String cminmsgsSubsystemType) {
|
||||
this.cminmsgsSubsystemType = cminmsgsSubsystemType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.gzzn.omms.msgexchangeapi.entiy.msg;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class Meta {
|
||||
@JsonProperty("SNDR")
|
||||
private String sndr;
|
||||
|
||||
@JsonProperty("SEQN")
|
||||
private String seqn;
|
||||
|
||||
@JsonProperty("DTTM")
|
||||
private String dttm;
|
||||
|
||||
@JsonProperty("TYPE")
|
||||
private String type;
|
||||
|
||||
@JsonProperty("STYP")
|
||||
private String styp;
|
||||
|
||||
public String getSndr() {
|
||||
return sndr;
|
||||
}
|
||||
public void setSndr(String sndr) {
|
||||
this.sndr = sndr;
|
||||
}
|
||||
public String getSeqn() {
|
||||
return seqn;
|
||||
}
|
||||
public void setSeqn(String seqn) {
|
||||
this.seqn = seqn;
|
||||
}
|
||||
public String getDttm() {
|
||||
return dttm;
|
||||
}
|
||||
public void setDttm(String dttm) {
|
||||
this.dttm = dttm;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
public String getStyp() {
|
||||
return styp;
|
||||
}
|
||||
public void setStyp(String styp) {
|
||||
this.styp = styp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.gzzn.omms.msgexchangeapi.entiy.msg;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Msg {
|
||||
|
||||
@JsonProperty("META")
|
||||
private Meta meta;
|
||||
|
||||
public Meta getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public void setMeta(Meta meta) {
|
||||
this.meta = meta;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.gzzn.omms.msgexchangeapi.entiy.msg.rqfd;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||
import com.gzzn.omms.msgexchangeapi.entiy.msg.Meta;
|
||||
import com.gzzn.omms.msgexchangeapi.entiy.msg.Msg;
|
||||
import com.gzzn.omms.msgexchangeapi.utils.DateTimeUtil;
|
||||
|
||||
@JacksonXmlRootElement(localName="MSG")
|
||||
public class RefdMsg extends Msg {
|
||||
|
||||
@JsonProperty("REFD")
|
||||
private RefdMsgBody refd;
|
||||
|
||||
public RefdMsg()
|
||||
{
|
||||
Meta meta = new Meta();
|
||||
meta.setSndr("OMMS");
|
||||
meta.setSeqn("1"); //消息序号,自增
|
||||
meta.setDttm(DateTimeUtil.gtFormatStr(new Date(), "yyMMddHHmmss", Locale.CHINA));
|
||||
meta.setStyp("NONE");
|
||||
|
||||
this.setMeta(meta);
|
||||
}
|
||||
|
||||
public RefdMsgBody getRefd() {
|
||||
return refd;
|
||||
}
|
||||
|
||||
public void setRefd(RefdMsgBody refd) {
|
||||
this.refd = refd;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.gzzn.omms.msgexchangeapi.entiy.msg.rqfd;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class RefdMsgBody {
|
||||
@JsonProperty("STDB")
|
||||
private String stdb;
|
||||
|
||||
@JsonProperty("STDE")
|
||||
private String stde;
|
||||
|
||||
@JsonProperty("ETDB")
|
||||
private String etdb;
|
||||
|
||||
@JsonProperty("ETDE")
|
||||
private String etde;
|
||||
|
||||
public String getStdb() {
|
||||
return stdb;
|
||||
}
|
||||
public void setStdb(String stdb) {
|
||||
this.stdb = stdb;
|
||||
}
|
||||
public String getStde() {
|
||||
return stde;
|
||||
}
|
||||
public void setStde(String stde) {
|
||||
this.stde = stde;
|
||||
}
|
||||
public String getEtdb() {
|
||||
return etdb;
|
||||
}
|
||||
public void setEtdb(String etdb) {
|
||||
this.etdb = etdb;
|
||||
}
|
||||
public String getEtde() {
|
||||
return etde;
|
||||
}
|
||||
public void setEtde(String etde) {
|
||||
this.etde = etde;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.gzzn.omms.msgexchangeapi.exception;
|
||||
|
||||
public class ExchangeServiceException extends RuntimeException {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ExchangeServiceException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ExchangeServiceException(String message,Throwable cause)
|
||||
{
|
||||
super(message,cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.gzzn.omms.msgexchangeapi.runner;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.dao.CmoutmsgDao;
|
||||
import com.gzzn.omms.msgexchangeapi.entiy.Cmoutmsg;
|
||||
import com.gzzn.omms.msgexchangeapi.entiy.msg.rqfd.RefdMsg;
|
||||
import com.gzzn.omms.msgexchangeapi.entiy.msg.rqfd.RefdMsgBody;
|
||||
import com.gzzn.omms.msgexchangeapi.service.IExchangeService;
|
||||
import com.gzzn.omms.msgexchangeapi.utils.DateTimeUtil;
|
||||
|
||||
|
||||
public class AppRunner implements CommandLineRunner {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AppRunner.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private CmoutmsgDao cmoutmsgDao;
|
||||
|
||||
@Autowired
|
||||
private IExchangeService exchangeService;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
Cmoutmsg cmoutmsg = new Cmoutmsg();
|
||||
|
||||
|
||||
RefdMsgBody body = new RefdMsgBody();
|
||||
body.setStdb(
|
||||
DateTimeUtil.gtFormatStr(
|
||||
new Date(),
|
||||
"ddMMMyyHHmm",
|
||||
Locale.ENGLISH)
|
||||
.toUpperCase()
|
||||
);
|
||||
RefdMsg msg = new RefdMsg();
|
||||
msg.setRefd(body);
|
||||
|
||||
|
||||
cmoutmsg.setCminmsgsClobMsg(exchangeService.objectToXmlstr(msg));
|
||||
cmoutmsg.setCminmsgsStatus("VALID");
|
||||
|
||||
cmoutmsgDao.save(cmoutmsg);
|
||||
}//end function run
|
||||
}
|
||||
@@ -6,23 +6,59 @@ import java.util.Map;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
||||
|
||||
@Service
|
||||
public class ExchangeServiceImpl implements IExchangeService {
|
||||
|
||||
@Override
|
||||
public String xmlToJson(String xml) throws JsonParseException, JsonMappingException, IOException {
|
||||
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
Map map = xmlMapper.readValue(xml, Map.class);
|
||||
|
||||
ObjectMapper jsonMapper = new ObjectMapper();
|
||||
String json = jsonMapper.writeValueAsString(map);
|
||||
|
||||
return json;
|
||||
}
|
||||
public String xmlToJson(String xml) throws ExchangeServiceException {
|
||||
try {
|
||||
Map map;
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
map = xmlMapper.readValue(xml, Map.class);
|
||||
|
||||
ObjectMapper jsonMapper = new ObjectMapper();
|
||||
String json = jsonMapper.writeValueAsString(map);
|
||||
return json;
|
||||
} catch (JsonParseException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
} catch (JsonMappingException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
} catch (IOException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
}
|
||||
} //end function
|
||||
|
||||
@Override
|
||||
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException {
|
||||
try {
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
return xmlMapper.readValue(xml,valueType);
|
||||
} catch (JsonParseException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
} catch (JsonMappingException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
} catch (IOException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
}
|
||||
} //end function
|
||||
|
||||
@Override
|
||||
public String objectToXmlstr(Object object) throws ExchangeServiceException {
|
||||
|
||||
try {
|
||||
String xml;
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
xml = xmlMapper.writeValueAsString(object);
|
||||
return xml;
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
||||
|
||||
/**
|
||||
* 消息转换服务
|
||||
@@ -11,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
*
|
||||
*/
|
||||
public interface IExchangeService {
|
||||
|
||||
public String xmlToJson(String xml)throws JsonParseException, JsonMappingException, IOException;
|
||||
public String xmlToJson(String xml) throws ExchangeServiceException;
|
||||
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException;
|
||||
public String objectToXmlstr(Object object) throws ExchangeServiceException;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.gzzn.omms.msgexchangeapi.task;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -11,10 +10,9 @@ 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.exception.ExchangeServiceException;
|
||||
import com.gzzn.omms.msgexchangeapi.service.IExchangeService;
|
||||
import com.gzzn.omms.msgexchangeapi.service.IKafkaService;
|
||||
|
||||
@@ -49,27 +47,24 @@ public class ExchangeTask {
|
||||
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();
|
||||
for(Cminmsg node:ls)
|
||||
{
|
||||
String strJson = null;
|
||||
try {
|
||||
strJson = exchangeService.xmlToJson(node.getCminmsgsClobMsg());
|
||||
if(!StringUtils.isEmpty(strJson))
|
||||
{
|
||||
kafkaservice.msgSend("topic2", strJson);
|
||||
}
|
||||
});
|
||||
} catch (ExchangeServiceException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
} // end for
|
||||
|
||||
|
||||
lenSend += ls.size();
|
||||
pageIndex++;
|
||||
}
|
||||
}//end while
|
||||
//
|
||||
logger.info("同步完成");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.gzzn.omms.msgexchangeapi.utils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DateTimeUtil {
|
||||
|
||||
/**
|
||||
* 日期格式化成指定格式字符串
|
||||
* @param date
|
||||
* @param locale
|
||||
* @return
|
||||
*/
|
||||
public static String gtFormatStr(Date date,String pattern,Locale locale)
|
||||
{
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern,locale);
|
||||
return sdf.format(date);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.gzzn.omms.msgexchangeapi.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
|
||||
public class JsonUtil {
|
||||
public static String getString(Object object) throws JsonProcessingException
|
||||
{
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
|
||||
java.lang.String jsonStr = ow.writeValueAsString(object);
|
||||
|
||||
return jsonStr;
|
||||
}
|
||||
|
||||
|
||||
public static <T> T getObject(String str,Class<T> valueType) throws JsonParseException, JsonMappingException, IOException
|
||||
{
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
T obj = mapper.readValue(str, valueType);
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user