91 lines
2.6 KiB
Java
91 lines
2.6 KiB
Java
package com.gzzn.omms.msgexchangeapi.tools;
|
|||
|
|
|
||
|
|
import java.io.File;
|
||
|
|
import java.io.FileOutputStream;
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
import org.junit.Test;
|
||
|
|
import org.junit.runner.RunWith;
|
||
|
|
import org.slf4j.Logger;
|
||
|
|
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 com.fasterxml.jackson.core.JsonParseException;
|
||
|
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||
|
|
import com.gzzn.omms.msgexchangeapi.domain.primary.dao.CminmsgDao;
|
||
|
|
import com.gzzn.omms.msgexchangeapi.domain.primary.entity.Cminmsg;
|
||
|
|
import com.gzzn.omms.msgexchangeapi.domain.primary.entity.msg.Msg;
|
||
|
|
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
||
|
|
import com.gzzn.omms.msgexchangeapi.service.IExchangeService;
|
||
|
|
import com.gzzn.omms.msgexchangeapi.utils.JsonUtil;
|
||
|
|
|
||
|
|
|
||
|
|
@RunWith(SpringRunner.class)
|
||
|
|
@SpringBootTest
|
||
|
|
public class ToolTest {
|
||
|
|
|
||
|
|
private static Logger logger = LoggerFactory.getLogger(ToolTest.class);
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private CminmsgDao cminmsgDao;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private IExchangeService exchangeService;
|
||
|
|
|
||
|
|
@Test
|
||
|
|
public void test() {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
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());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
} //end function
|
||
|
|
}
|