新增航班动态信息处理
This commit is contained in:
@@ -3,7 +3,10 @@ package com.gzzn.omms.msgexchangeapi.tools;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -35,56 +38,93 @@ public class ToolTest {
|
||||
@Autowired
|
||||
private IExchangeService exchangeService;
|
||||
|
||||
/**
|
||||
* 每种消息类型导出一个xml文件即可
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
public void exportOneTypeToJsonFiles() {
|
||||
List<Cminmsg> lsCmin = (List<Cminmsg>) cminmsgDao.findAll();
|
||||
Map<String, Cminmsg> mapCminmsg = new HashMap();
|
||||
|
||||
for(Cminmsg x : lsCmin)
|
||||
{
|
||||
Msg msg = exchangeService.xmlstrToObject(x.getCminmsgsClobMsg(),Msg.class);
|
||||
mapCminmsg.putIfAbsent(msg.getMeta().getType() + "_" + msg.getMeta().getStyp(), x);
|
||||
}
|
||||
|
||||
List<Cminmsg> ls = new ArrayList(mapCminmsg.values());
|
||||
toJsonFiles(ls);
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* 导出CMINMSGS数据中的消息到单独的Xml文件
|
||||
* @throws JsonParseException
|
||||
* @throws JsonMappingException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void exportToXmlFiles() throws JsonParseException, JsonMappingException, IOException
|
||||
{
|
||||
List<Cminmsg> lsCmin = (List<Cminmsg>) cminmsgDao.findAll();
|
||||
|
||||
for(Cminmsg x : lsCmin)
|
||||
{
|
||||
String json = exchangeService.xmlToJson(x.getCminmsgsClobMsg());
|
||||
Msg msg =JsonUtil.getObject(json,Msg.class);
|
||||
String Dttm = msg.getMeta().getDttm();
|
||||
|
||||
String dir = "xml/" + Dttm.substring(0, 10);
|
||||
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append(dir);
|
||||
path.append("/");
|
||||
path.append(msg.getMeta().getDttm().substring(10, Dttm.length()));//time
|
||||
path.append("-"+x.getCminmsgsId());
|
||||
path.append("-"+msg.getMeta().getType());//Type
|
||||
path.append("-"+msg.getMeta().getStyp());//Subtype
|
||||
path.append(".xml");
|
||||
|
||||
//父目录是否存在
|
||||
File fileDir = new File(dir);
|
||||
if(fileDir.exists() == false)
|
||||
{
|
||||
fileDir.mkdirs();
|
||||
}
|
||||
|
||||
//
|
||||
File f = new File(path.toString());
|
||||
try (FileOutputStream fop = new FileOutputStream(f)) {
|
||||
byte[] contentInBytes = x.getCminmsgsClobMsg().getBytes("UTF-8");
|
||||
|
||||
fop.write(contentInBytes);
|
||||
fop.flush();
|
||||
fop.close();
|
||||
}
|
||||
catch (ExchangeServiceException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
toJsonFiles(lsCmin);
|
||||
|
||||
} //end function
|
||||
|
||||
/**
|
||||
* 生成xml文件
|
||||
* @param lsCmin
|
||||
*/
|
||||
private void toJsonFiles(List<Cminmsg> lsCmin)
|
||||
{
|
||||
try {
|
||||
for(Cminmsg x : lsCmin)
|
||||
{
|
||||
String json = exchangeService.xmlToJson(x.getCminmsgsClobMsg());
|
||||
Msg msg;
|
||||
|
||||
msg = JsonUtil.getObject(json,Msg.class);
|
||||
String Dttm = msg.getMeta().getDttm();
|
||||
|
||||
String dir = "json";
|
||||
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append(dir);
|
||||
path.append("/");
|
||||
path.append(msg.getMeta().getType());//Type
|
||||
path.append("-"+msg.getMeta().getStyp());//Subtype
|
||||
path.append(".json");
|
||||
|
||||
//父目录是否存在
|
||||
File fileDir = new File(dir);
|
||||
if(fileDir.exists() == false)
|
||||
{
|
||||
fileDir.mkdirs();
|
||||
}
|
||||
|
||||
//
|
||||
File f = new File(path.toString());
|
||||
try (FileOutputStream fop = new FileOutputStream(f)) {
|
||||
String jsonString = exchangeService.xmlToJson(x.getCminmsgsClobMsg());
|
||||
jsonString = jsonString.replace("\"noNamespaceSchemaLocation\":\"unisysaodbsis.xsd\",", "");
|
||||
byte[] contentInBytes = jsonString.getBytes("UTF-8");
|
||||
|
||||
fop.write(contentInBytes);
|
||||
fop.flush();
|
||||
fop.close();
|
||||
}
|
||||
catch (ExchangeServiceException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (JsonParseException e1) {
|
||||
throw new RuntimeException(e1.getMessage());
|
||||
} catch (JsonMappingException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
} catch (IOException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user