From 10f4ec15a1c147ff85658677d4f154b8cef404f0 Mon Sep 17 00:00:00 2001 From: zhouxiunai <154707516@qq.com> Date: Wed, 9 Jan 2019 10:17:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86BDPB=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E4=BD=93=E5=8F=AA=E5=8C=85=E5=90=AB=E7=A9=BA=E7=99=BD=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=E7=AC=A6=E5=AF=BC=E8=87=B4=E8=BD=AC=E6=8D=A2=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=E3=80=82=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msgexchangeapi/dao/CminmsgTestDao.java | 11 ++ .../msgexchangeapi/entity/CminmsgTest.java | 136 ++++++++++++++++++ .../service/exchange/ExchangeServiceImpl.java | 5 + .../service/ExchangeServiceImplTest.java | 23 ++- 4 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/gzzn/omms/msgexchangeapi/dao/CminmsgTestDao.java create mode 100644 src/main/java/com/gzzn/omms/msgexchangeapi/entity/CminmsgTest.java diff --git a/src/main/java/com/gzzn/omms/msgexchangeapi/dao/CminmsgTestDao.java b/src/main/java/com/gzzn/omms/msgexchangeapi/dao/CminmsgTestDao.java new file mode 100644 index 00000000..4e31d869 --- /dev/null +++ b/src/main/java/com/gzzn/omms/msgexchangeapi/dao/CminmsgTestDao.java @@ -0,0 +1,11 @@ +package com.gzzn.omms.msgexchangeapi.dao; + +import org.springframework.data.repository.CrudRepository; + +import com.gzzn.omms.msgexchangeapi.entity.CminmsgTest; + + + +public interface CminmsgTestDao extends CrudRepository { + +} diff --git a/src/main/java/com/gzzn/omms/msgexchangeapi/entity/CminmsgTest.java b/src/main/java/com/gzzn/omms/msgexchangeapi/entity/CminmsgTest.java new file mode 100644 index 00000000..bdfc7dfa --- /dev/null +++ b/src/main/java/com/gzzn/omms/msgexchangeapi/entity/CminmsgTest.java @@ -0,0 +1,136 @@ +package com.gzzn.omms.msgexchangeapi.entity; + +import java.io.Serializable; +import javax.persistence.*; +import java.util.Date; + + +/** + * The persistent class for the CMINMSGS database table. + * + */ +@Entity +@Table(name="CMINMSGS_TEST") +public class CminmsgTest implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="CMINMSGS_ID") + private long cminmsgsId; + + @Lob + @Column(name="CMINMSGS_CLOB_MSG") + private String cminmsgsClobMsg; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="CMINMSGS_DATE_PROCESSED") + private Date cminmsgsDateProcessed; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="CMINMSGS_DATE_RECEIVED") + private Date cminmsgsDateReceived; + + @Column(name="CMINMSGS_STATUS") + private String cminmsgsStatus; + + @Temporal(TemporalType.TIMESTAMP) + @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 CminmsgTest() { + } + + 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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/gzzn/omms/msgexchangeapi/service/exchange/ExchangeServiceImpl.java b/src/main/java/com/gzzn/omms/msgexchangeapi/service/exchange/ExchangeServiceImpl.java index 2b52e980..708ce764 100644 --- a/src/main/java/com/gzzn/omms/msgexchangeapi/service/exchange/ExchangeServiceImpl.java +++ b/src/main/java/com/gzzn/omms/msgexchangeapi/service/exchange/ExchangeServiceImpl.java @@ -13,6 +13,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonEncoding; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser.Feature; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonMappingException; @@ -103,6 +104,10 @@ public class ExchangeServiceImpl implements IExchangeService { XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); xmlMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance())); + + //tofix: 暂时单独对BDPB做容错处理 ,可能为 jackson xml 的bug 或配置问题 + xmlStr = xmlStr.replace("\n", ""); + return xmlMapper.readValue(xmlStr, MSG.class); } catch (Exception e) { throw new ExchangeServiceException(e.getMessage(),e); diff --git a/src/test/java/com/gzzn/omms/msgexchangeapi/service/ExchangeServiceImplTest.java b/src/test/java/com/gzzn/omms/msgexchangeapi/service/ExchangeServiceImplTest.java index 964095a8..9c07a94f 100644 --- a/src/test/java/com/gzzn/omms/msgexchangeapi/service/ExchangeServiceImplTest.java +++ b/src/test/java/com/gzzn/omms/msgexchangeapi/service/ExchangeServiceImplTest.java @@ -1,7 +1,5 @@ package com.gzzn.omms.msgexchangeapi.service; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.math.BigInteger; import java.util.Date; @@ -18,6 +16,7 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.gzzn.omms.msgexchangeapi.dao.CminmsgDao; +import com.gzzn.omms.msgexchangeapi.dao.CminmsgTestDao; import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGESUBTYPES; import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGETYPES; import com.gzzn.omms.msgexchangeapi.entity.msg.MSG; @@ -38,6 +37,8 @@ public class ExchangeServiceImplTest { @Autowired private CminmsgDao cminmsgDao; + @Autowired + private CminmsgTestDao cminmsgTestDao; @Test public void testXmlToJson() throws JsonParseException, JsonMappingException, IOException { @@ -94,27 +95,19 @@ public class ExchangeServiceImplTest { @Test - public void testXmlToDNLDMsg() throws JsonParseException, JsonMappingException, IOException + public void testXmlToMsg() throws JsonParseException, JsonMappingException, IOException { - String xml = cminmsgDao.findOne(300L).getCminmsgsClobMsg(); + String xml = cminmsgTestDao.findOne(847328L).getCminmsgsClobMsg();//847325L + MSG msg = exchangeService.xmlToMsg(xml); - MSG dNLDMsg = exchangeService.xmlToMsg(xml); - String jsonString=JsonUtil.getString(dNLDMsg); - - File file = new File("schd.json"); - FileOutputStream fos = new FileOutputStream(file); - fos.write(jsonString.getBytes("utf-8")); - fos.close(); - - - System.out.println(jsonString); + System.out.println(JsonUtil.getStringWithNoneKey(msg)); } /** * POJO 转xml字符串 */ @Test - public void testObjectToXmlstr() + public void testMsgToXml() { Long nowtime = System.currentTimeMillis(); MSG rqfdMsg = new MSGBuilder().