提交整体消息转换分发处理框架
This commit is contained in:
@@ -4,9 +4,15 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -15,6 +21,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
@@ -46,6 +53,7 @@ public class ToolTest {
|
||||
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);
|
||||
@@ -62,16 +70,27 @@ public class ToolTest {
|
||||
* @throws JsonMappingException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void exportToXmlFiles() throws JsonParseException, JsonMappingException, IOException
|
||||
{
|
||||
List<Cminmsg> lsCmin = (List<Cminmsg>) cminmsgDao.findAll();
|
||||
|
||||
toJsonFiles(lsCmin);
|
||||
|
||||
//提取某个航班的信息
|
||||
List<Cminmsg> lsFlopTypeCmin = lsCmin.parallelStream()
|
||||
.filter(node->{
|
||||
Msg msg = exchangeService.xmlstrToObject(node.getCminmsgsClobMsg(), Msg.class);
|
||||
return msg.getMeta().getType().equals("FLOP");
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
|
||||
flopMsgToXmlFiles(lsFlopTypeCmin);
|
||||
|
||||
} //end function
|
||||
|
||||
/**
|
||||
* 生成xml文件
|
||||
* 生成json文件
|
||||
* @param lsCmin
|
||||
*/
|
||||
private void toJsonFiles(List<Cminmsg> lsCmin)
|
||||
@@ -126,5 +145,85 @@ public class ToolTest {
|
||||
} catch (IOException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
} //end function
|
||||
|
||||
|
||||
private void flopMsgToXmlFiles(List<Cminmsg> lsCmin)
|
||||
{
|
||||
FileOutputStream fop = null;
|
||||
try {
|
||||
for(Cminmsg x : lsCmin)
|
||||
{
|
||||
Msg msg = exchangeService.xmlstrToObject(x.getCminmsgsClobMsg(), Msg.class);
|
||||
Map msgMap = exchangeService.xmlstrToObject(x.getCminmsgsClobMsg(), Map.class);
|
||||
|
||||
|
||||
Map mapFlop = (Map)msgMap.get("FLOP");
|
||||
String flid = String.valueOf(mapFlop.get("FLID"));
|
||||
if(null == flid || flid.equalsIgnoreCase("null") || flid.equals("")) {
|
||||
logger.warn("没有flid的消息:"+x.getCminmsgsClobMsg());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
String type = "xml";
|
||||
String path = getPathGroupByFlid(msg,type,flid);
|
||||
|
||||
//父目录是否存在
|
||||
File fileDir = new File(path);
|
||||
if(fileDir.getParentFile().exists() == false)
|
||||
{
|
||||
fileDir.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
//
|
||||
byte[] contentInBytes = x.getCminmsgsClobMsg().getBytes("UTF-8");
|
||||
|
||||
File f = new File(path.toString());
|
||||
fop = new FileOutputStream(f);
|
||||
fop.write(contentInBytes);
|
||||
fop.flush();
|
||||
fop.close();
|
||||
}//end for
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error(""+JsonUtil.getString(e));
|
||||
}
|
||||
} //end function
|
||||
|
||||
|
||||
private String getPath(Msg msg,String type)
|
||||
{
|
||||
String dir = type;
|
||||
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append(dir);
|
||||
path.append("/");
|
||||
path.append(msg.getMeta().getType());//Type
|
||||
path.append("-"+msg.getMeta().getStyp());//Subtype
|
||||
path.append("."+dir);
|
||||
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
|
||||
private String getPathGroupByFlid(Msg msg,String type,String flid)
|
||||
{
|
||||
String dir = type;
|
||||
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append(dir);
|
||||
path.append("/");
|
||||
path.append(flid);
|
||||
path.append("/");
|
||||
path.append(msg.getMeta().getDttm());//dttm
|
||||
path.append("-"+msg.getMeta().getType());//Type
|
||||
path.append("-"+msg.getMeta().getStyp());//Subtype
|
||||
path.append("."+dir);
|
||||
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user