引入多数据源及内存数据库

This commit is contained in:
zhouxiunai
2018-11-28 20:32:19 +08:00
parent 799544ff9c
commit f8d392d5af
23 changed files with 424 additions and 72 deletions
@@ -0,0 +1,26 @@
package com.gzzn.omms.msgexchangeapi.tools;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DatetimeFormatTest {
@Test
public void testFormat()
{
SimpleDateFormat sdf = new SimpleDateFormat("ddMMMyyHHmm",Locale.ENGLISH);
System.out.println(sdf.format(new Date()).toUpperCase());
SimpleDateFormat sdf1 = new SimpleDateFormat("yyMMddHHmmss",Locale.CHINA);
System.out.println(sdf1.format(new Date()));
}
}
@@ -0,0 +1,90 @@
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
}