Merge remote-tracking branch 'origin/dev' into test
commit
11fb13ae5b
@ -1,108 +0,0 @@
|
|||||||
package cn.estsh.i3plus.core.apiservice.util;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description : 文件工具类
|
|
||||||
* @Reference :
|
|
||||||
* @Author : yunhao
|
|
||||||
* @CreateDate : 2019-01-11 13:34
|
|
||||||
* @Modify:
|
|
||||||
**/
|
|
||||||
public class FileUtil {
|
|
||||||
|
|
||||||
private FileUtil(){}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 对临时生成的文件夹和文件夹下的文件进行删除
|
|
||||||
*/
|
|
||||||
public static void deletefile(String delpath) {
|
|
||||||
try {
|
|
||||||
File file = new File(delpath);
|
|
||||||
if (!file.isDirectory()) {
|
|
||||||
file.delete();
|
|
||||||
} else if (file.isDirectory()) {
|
|
||||||
String[] filelist = file.list();
|
|
||||||
for (int i = 0; i < filelist.length; i++) {
|
|
||||||
File delfile = new File(delpath + File.separator + filelist[i]);
|
|
||||||
if (!delfile.isDirectory()) {
|
|
||||||
delfile.delete();
|
|
||||||
} else if (delfile.isDirectory()) {
|
|
||||||
deletefile(delpath + File.separator + filelist[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* File 转 byte[]
|
|
||||||
*
|
|
||||||
* @param filePath
|
|
||||||
* @return byte[]
|
|
||||||
*/
|
|
||||||
public static byte[] file2Byte(String filePath){
|
|
||||||
byte[] buffer = null;
|
|
||||||
try {
|
|
||||||
File file = new File(filePath);
|
|
||||||
FileInputStream fis = new FileInputStream(file);
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
|
|
||||||
byte[] b = new byte[1000];
|
|
||||||
int n;
|
|
||||||
while ((n = fis.read(b)) != -1) {
|
|
||||||
bos.write(b, 0, n);
|
|
||||||
}
|
|
||||||
fis.close();
|
|
||||||
bos.close();
|
|
||||||
buffer = bos.toByteArray();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* byte[] 转 File
|
|
||||||
* @param buf byte[]
|
|
||||||
* @param filePath 文件地址
|
|
||||||
* @param fileName 文件名称
|
|
||||||
*/
|
|
||||||
public static void byte2File(byte[] buf, String filePath, String fileName) {
|
|
||||||
BufferedOutputStream bos = null;
|
|
||||||
FileOutputStream fos = null;
|
|
||||||
File file = null;
|
|
||||||
try {
|
|
||||||
File dir = new File(filePath);
|
|
||||||
if (!dir.exists() && dir.isDirectory()) {
|
|
||||||
dir.mkdirs();
|
|
||||||
}
|
|
||||||
file = new File(filePath + File.separator + fileName);
|
|
||||||
fos = new FileOutputStream(file);
|
|
||||||
bos = new BufferedOutputStream(fos);
|
|
||||||
bos.write(buf);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (bos != null) {
|
|
||||||
try {
|
|
||||||
bos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fos != null) {
|
|
||||||
try {
|
|
||||||
fos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
@ -0,0 +1,45 @@
|
|||||||
|
package test.cn.estsh.i3plus.core.apiservice.serviceimpl.busi;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysLocaleResourceService;
|
||||||
|
import cn.estsh.i3plus.core.apiservice.serviceimpl.busi.TestBase;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SysLocaleResource;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :
|
||||||
|
* @Reference :
|
||||||
|
* @Author : yunhao
|
||||||
|
* @CreateDate : 2019-05-22 16:37
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
public class TestSysLocaleResourceService extends TestBase {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ISysLocaleResourceService sysLocaleResourceService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void exportSysLocaleResourceData() throws IOException {
|
||||||
|
SysLocaleResource ds = new SysLocaleResource();
|
||||||
|
System.out.println(ExcelTool.getColName(SysLocaleResource.class));
|
||||||
|
String[] colName = new String[]{
|
||||||
|
"resourceType","languageCode","languageNameRdd","resourceKey","resourceValue","isSystem"
|
||||||
|
};
|
||||||
|
File file = File.createTempFile(SysLocaleResource.class.getSimpleName() + new Date().getTime(), "Tp.xls");
|
||||||
|
try {
|
||||||
|
ExcelTool.exportData(file,sysLocaleResourceService.listSysLocaleResource(),SysLocaleResource.class,colName);
|
||||||
|
System.out.println(file.getPath());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(ExcelTool.getColName(SysLocaleResource.class));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue