|
|
|
@ -0,0 +1,521 @@
|
|
|
|
|
package jnpf.util;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.http.ContentType;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
|
|
|
import jnpf.base.ActionResult;
|
|
|
|
|
import jnpf.controller.UtilsController;
|
|
|
|
|
import jnpf.model.UploaderVO;
|
|
|
|
|
import jnpf.model.voucher.VehiclePictureFolder;
|
|
|
|
|
import jnpf.util.context.SpringContext;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.ss.util.NumberToTextConverter;
|
|
|
|
|
import org.springframework.util.FileCopyUtils;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import sun.misc.BASE64Encoder;
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author: WangChuang
|
|
|
|
|
* @Date: 22/2/2023 上午11:00
|
|
|
|
|
* @Description // TODO:实现文件或文件夹的复制到指定目录
|
|
|
|
|
* @Version 1.0
|
|
|
|
|
*/
|
|
|
|
|
public class FileCopy {
|
|
|
|
|
|
|
|
|
|
public static ArrayList<Object> getInfoAndUpFile(File[] fileList, HttpServletRequest httpServletRequest) throws Exception {
|
|
|
|
|
String fileName = "";
|
|
|
|
|
// 磅单图片对应的信息
|
|
|
|
|
HashMap<String, Object> fileMap = new HashMap<>();
|
|
|
|
|
// 车辆图片对应的信息
|
|
|
|
|
HashMap<String, Object> carFileMap = new HashMap<>();
|
|
|
|
|
HashMap<String, VehiclePictureFolder> folderHashMap = new HashMap<>();
|
|
|
|
|
ArrayList<Object> resultList = new ArrayList<>();
|
|
|
|
|
File excelFile = null;
|
|
|
|
|
for (int i = 0; i < fileList.length; i++) {
|
|
|
|
|
File file = fileList[i];
|
|
|
|
|
String name = file.getName();
|
|
|
|
|
|
|
|
|
|
int xlsIndex = 0;
|
|
|
|
|
// 将文件夹中的文件上传到文件服务器
|
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
|
String path = file.getPath();
|
|
|
|
|
String parentName = path.substring(path.lastIndexOf("\\") + 1, path.length());
|
|
|
|
|
|
|
|
|
|
VehiclePictureFolder vehiclePictureFolder = VehiclePictureFolderUtils.getVehiclePictureFolder(parentName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 序号
|
|
|
|
|
parentName=vehiclePictureFolder.getSerialNumber();
|
|
|
|
|
if (!folderHashMap.containsKey(parentName)){
|
|
|
|
|
folderHashMap.put(parentName,vehiclePictureFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArrayList<Object> resultListt = getInfoAndUpFile(file.listFiles(), httpServletRequest);
|
|
|
|
|
if (resultListt.get(0) != null) {
|
|
|
|
|
fileName = fileName+String.valueOf(resultListt.get(0));
|
|
|
|
|
}
|
|
|
|
|
if (resultListt.get(1) != null) {
|
|
|
|
|
carFileMap.putAll ((HashMap<String, Object>) resultListt.get(1));
|
|
|
|
|
}
|
|
|
|
|
if (resultListt.get(2) != null) {
|
|
|
|
|
fileMap.putAll ((HashMap<String, Object>) resultListt.get(2));
|
|
|
|
|
}
|
|
|
|
|
if (resultListt.get(3)!=null){
|
|
|
|
|
folderHashMap.putAll((HashMap<String,VehiclePictureFolder>) resultListt.get(3));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (file.isFile()) {
|
|
|
|
|
String indexString = name.substring(0, name.lastIndexOf("."));
|
|
|
|
|
String parent = file.getParent();
|
|
|
|
|
String parentName = parent.substring(parent.lastIndexOf("\\") + 1, parent.length());
|
|
|
|
|
|
|
|
|
|
VehiclePictureFolder vehiclePictureFolder = VehiclePictureFolderUtils.getVehiclePictureFolder(parentName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 序号
|
|
|
|
|
parentName=vehiclePictureFolder.getSerialNumber();
|
|
|
|
|
if (!folderHashMap.containsKey(parentName)){
|
|
|
|
|
folderHashMap.put(parentName,vehiclePictureFolder);
|
|
|
|
|
}
|
|
|
|
|
// if (parentName.contains("-")){
|
|
|
|
|
// parentName=parentName.substring(0,parentName.lastIndexOf("-"));
|
|
|
|
|
// }
|
|
|
|
|
String substring = name.substring(name.lastIndexOf(".") + 1, name.length());
|
|
|
|
|
if (substring.contains("xls") || substring.contains("xlsx")) {
|
|
|
|
|
// 进行word操作
|
|
|
|
|
excelFile = file;
|
|
|
|
|
xlsIndex = i;
|
|
|
|
|
} else {
|
|
|
|
|
// 这个文件图片的信息
|
|
|
|
|
ArrayList<Object> list = new ArrayList<>();
|
|
|
|
|
InputStream input = new FileInputStream(file);
|
|
|
|
|
|
|
|
|
|
// MultipartFile multipartFile = new MultipartFileDto(file.getName(),input);
|
|
|
|
|
MultipartFile multipartFile = new MultipartFileDto(file.getName(), file.getName(), ContentType.JSON.toString(), FileCopyUtils.copyToByteArray(input));
|
|
|
|
|
UtilsController utilsController = SpringContext.getBean(UtilsController.class);
|
|
|
|
|
ActionResult annex = utilsController.uploader("annex", multipartFile, httpServletRequest);
|
|
|
|
|
|
|
|
|
|
UploaderVO data = (UploaderVO)annex.getData();
|
|
|
|
|
|
|
|
|
|
String url = data.getUrl();
|
|
|
|
|
Map<String,Object> dataMap= JsonUtil.entityToMap(annex.getData());
|
|
|
|
|
if (!dataMap.containsKey("fileId")) {
|
|
|
|
|
dataMap.put("fileId",url.substring(url.lastIndexOf("/")+1,url.length()));
|
|
|
|
|
}
|
|
|
|
|
list.add(dataMap);
|
|
|
|
|
|
|
|
|
|
// 将磅单照片存在磅单列表中
|
|
|
|
|
if (indexString.equals("1")||indexString.equals(parentName)) {
|
|
|
|
|
if (fileMap.containsKey(parentName)) {
|
|
|
|
|
List<Object> o = (List<Object>) fileMap.get(parentName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
o.add(dataMap);
|
|
|
|
|
fileMap.put(parentName, o);
|
|
|
|
|
} else {
|
|
|
|
|
fileMap.put(parentName, list);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (carFileMap.containsKey(parentName)) {
|
|
|
|
|
List<Object> o = (List<Object>) carFileMap.get(parentName);
|
|
|
|
|
o.add(dataMap);
|
|
|
|
|
carFileMap.put(parentName, o);
|
|
|
|
|
} else {
|
|
|
|
|
carFileMap.put(parentName, list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 将车辆照片存在车辆照片中
|
|
|
|
|
input.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == fileList.length - 1) {
|
|
|
|
|
if (excelFile != null) {
|
|
|
|
|
ExcelReader reader = ExcelUtil.getReader(excelFile);
|
|
|
|
|
|
|
|
|
|
reader.setIgnoreEmptyRow(true);
|
|
|
|
|
// List<HashMap> read = reader.read(3, reader.read().size(), HashMap.class);
|
|
|
|
|
// List<Object> objects1 = reader.readRow(0);
|
|
|
|
|
// System.out.println(objects1);
|
|
|
|
|
List<Object> objects2 = reader.readColumn(0, 0, 1);
|
|
|
|
|
// 公司名字
|
|
|
|
|
// String companyStr = String.valueOf(objects2.get(0));
|
|
|
|
|
// companyStr=companyStr.substring(0,companyStr.lastIndexOf("公司")+2);
|
|
|
|
|
// 销售合同编码
|
|
|
|
|
String infoStr = String.valueOf(objects2.get(1));
|
|
|
|
|
|
|
|
|
|
infoStr = infoStr.replaceAll(" ", "");
|
|
|
|
|
// 销售合同编码
|
|
|
|
|
String str = infoStr.substring(7, infoStr.indexOf("采购合同编码"));
|
|
|
|
|
// 采购合同编码
|
|
|
|
|
String str3 = infoStr.substring(infoStr.lastIndexOf(":") + 1, infoStr.length());
|
|
|
|
|
List<Object> objects = reader.readColumn(0, 3);
|
|
|
|
|
// 写入工具类
|
|
|
|
|
ExcelWriter writer = reader.getWriter();
|
|
|
|
|
// Workbook workbook = writer.getWorkbook();
|
|
|
|
|
Sheet sheet = writer.getSheet();
|
|
|
|
|
for (int i1 = 0; i1 < objects.size(); i1++) {
|
|
|
|
|
Object o = objects.get(i1);
|
|
|
|
|
Row row = sheet.getRow(i1 + 3);
|
|
|
|
|
if (String.valueOf(o).isEmpty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//// System.out.println(row.getCell(0).getStringCellValue());
|
|
|
|
|
// if ( row.getCell(0).getStringCellValue().isEmpty()){
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cell cell111 = row.createCell(19);
|
|
|
|
|
Cell cell222 = row.createCell(20);
|
|
|
|
|
Cell cell333 = row.createCell(21);
|
|
|
|
|
Cell cell444 = row.createCell(22);
|
|
|
|
|
/*Cell cell6 = row.createCell(25);
|
|
|
|
|
Cell cell7 = row.createCell(26);
|
|
|
|
|
Cell cell8 = row.createCell(27);*/
|
|
|
|
|
Cell strCell7 = row.getCell(1);//日期时间
|
|
|
|
|
/*Cell cell5 = row.getCell(9);
|
|
|
|
|
Cell strCell1 = row.getCell(8);
|
|
|
|
|
Cell strCell2 = row.getCell(7);
|
|
|
|
|
Cell strCell3 = row.getCell(6);
|
|
|
|
|
Cell strCell4 = row.getCell(5);
|
|
|
|
|
Cell strCell5 = row.getCell(11);
|
|
|
|
|
Cell strCell6 = row.getCell(12);
|
|
|
|
|
Cell strCell7 = row.getCell(1);
|
|
|
|
|
Cell strCell8 = row.getCell(3);*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (i1 == 0) {
|
|
|
|
|
Row row1 = sheet.getRow(2);
|
|
|
|
|
Cell cell11 = row1.createCell(19);
|
|
|
|
|
cell11.setCellValue("业务类型");
|
|
|
|
|
Cell cell22 = row1.createCell(20);
|
|
|
|
|
cell22.setCellValue("单据类型");
|
|
|
|
|
Cell cell33 = row1.createCell(21);
|
|
|
|
|
cell33.setCellValue("凭证图片");
|
|
|
|
|
Cell cell44 = row1.createCell(22);
|
|
|
|
|
cell44.setCellValue("车辆信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object o1 = fileMap.get(String.valueOf(o));
|
|
|
|
|
Object o2 = carFileMap.get(String.valueOf(o));
|
|
|
|
|
VehiclePictureFolder vehiclePictureFolder1 = folderHashMap.get(String.valueOf(o));
|
|
|
|
|
|
|
|
|
|
cell111.setCellValue(httpServletRequest.getParameter("businessType"));
|
|
|
|
|
cell222.setCellValue(httpServletRequest.getParameter("documentType"));
|
|
|
|
|
cell333.setCellValue(String.valueOf(o1).equals("null") ? "" : JsonUtil.getListToJsonArray((List<Map<String,Object>>)o1).toString());
|
|
|
|
|
cell444.setCellValue(String.valueOf(o2).equals("null") ? "" :JsonUtil.getListToJsonArray((List<Map<String,Object>>)o2).toString());
|
|
|
|
|
/*if (vehiclePictureFolder1!=null){
|
|
|
|
|
cell6.setCellValue(vehiclePictureFolder1.getDriverName()!=null?vehiclePictureFolder1.getDriverName():"");
|
|
|
|
|
cell7.setCellValue(vehiclePictureFolder1.getPhoneNumber()!=null?vehiclePictureFolder1.getPhoneNumber():"");
|
|
|
|
|
cell8.setCellValue(vehiclePictureFolder1.getCarNumber()!=null?vehiclePictureFolder1.getCarNumber():"");
|
|
|
|
|
}*/
|
|
|
|
|
String stringCellValue = VehiclePictureFolderUtils.getValue(strCell7);
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义新的日期格式
|
|
|
|
|
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");//定义新的日期格式
|
|
|
|
|
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy/MM/dd K:mm:ss a");//定义新的日期格式
|
|
|
|
|
SimpleDateFormat formatter3 = new SimpleDateFormat("yyyy.MM.dd");//定义新的日期格式
|
|
|
|
|
//format():将给定的 Date 格式化为日期/时间字符串。即:date--->String
|
|
|
|
|
try {
|
|
|
|
|
if (stringCellValue.contains("/")){
|
|
|
|
|
Date date = formatter2.parse(stringCellValue);//parse():String--->date
|
|
|
|
|
strCell7.setCellValue(formatter.format(date));
|
|
|
|
|
}
|
|
|
|
|
else if (stringCellValue.contains("-")&&stringCellValue.contains(":")){
|
|
|
|
|
Date date = formatter.parse(stringCellValue);//parse():String--->date
|
|
|
|
|
strCell7.setCellValue(formatter.format(date));
|
|
|
|
|
} else if (stringCellValue.contains("-")) {
|
|
|
|
|
Date date = formatter1.parse(stringCellValue);//parse():String--->date
|
|
|
|
|
strCell7.setCellValue(formatter.format(date));
|
|
|
|
|
} else if (stringCellValue.contains(".")) {
|
|
|
|
|
Date date = formatter3.parse(stringCellValue);//parse():String--->date
|
|
|
|
|
strCell7.setCellValue(formatter.format(date));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
writer.flush(excelFile);
|
|
|
|
|
writer.close();
|
|
|
|
|
reader.close();
|
|
|
|
|
InputStream input = new FileInputStream(excelFile);
|
|
|
|
|
|
|
|
|
|
// MultipartFile multipartFile = new MultipartFileDto(file.getName(),input);
|
|
|
|
|
MultipartFile multipartFile = new MultipartFileDto(excelFile.getName(), excelFile.getName(), ContentType.JSON.toString(), FileCopyUtils.copyToByteArray(input));
|
|
|
|
|
UtilsController utilsController = SpringContext.getBean(UtilsController.class);
|
|
|
|
|
System.out.println(multipartFile.getName());
|
|
|
|
|
ActionResult annex = utilsController.uploader("annex", multipartFile, httpServletRequest);
|
|
|
|
|
if (annex.getCode() == 200) {
|
|
|
|
|
UploaderVO fileLoader = (UploaderVO) annex.getData();
|
|
|
|
|
System.out.println(fileLoader);
|
|
|
|
|
System.out.println(fileLoader.getName());
|
|
|
|
|
resultList.add(fileLoader.getName());
|
|
|
|
|
resultList.add(carFileMap);
|
|
|
|
|
|
|
|
|
|
resultList.add(fileMap);
|
|
|
|
|
resultList.add(folderHashMap);
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
|
|
|
|
input.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resultList.add(fileName);
|
|
|
|
|
resultList.add(carFileMap);
|
|
|
|
|
resultList.add(fileMap);
|
|
|
|
|
resultList.add(folderHashMap);
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void createFile(String path) {
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
file.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param path
|
|
|
|
|
* @return
|
|
|
|
|
* @TODO 删除文件夹下的文件
|
|
|
|
|
*/
|
|
|
|
|
public static boolean delAllFile(String path) {
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
if (!file.isDirectory()) {
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
String[] tempList = file.list();
|
|
|
|
|
File temp = null;
|
|
|
|
|
for (int i = 0; i < tempList.length; i++) {
|
|
|
|
|
if (path.endsWith(File.separator)) {
|
|
|
|
|
temp = new File(path + tempList[i]);
|
|
|
|
|
} else {
|
|
|
|
|
temp = new File(path + File.separator + tempList[i]);
|
|
|
|
|
}
|
|
|
|
|
if (temp.isFile()) {
|
|
|
|
|
temp.delete();
|
|
|
|
|
}
|
|
|
|
|
if (temp.isDirectory()) {
|
|
|
|
|
delAllFile(path + "/" + tempList[i]);//先删除文件夹里面的文件
|
|
|
|
|
// delFolder(path + "/" + tempList[i]);//再删除空文件夹
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取图片的base64
|
|
|
|
|
*
|
|
|
|
|
* @param picturesInfo
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public static List<Map<String, Object>> getImageInfo(String picturesInfo) throws Exception {
|
|
|
|
|
List<Map<String, Object>> imageBaseList = new ArrayList<>();
|
|
|
|
|
if (!picturesInfo.equals("null")) {
|
|
|
|
|
for (Object o : JsonUtil.getJsonToJsonArray(picturesInfo)) {
|
|
|
|
|
Map<String, String> map = (Map<String, String>) o;
|
|
|
|
|
String url = map.get("url");
|
|
|
|
|
// System.out.println(url);
|
|
|
|
|
String fileName=url.substring(url.lastIndexOf("/")+1,url.length());
|
|
|
|
|
int i = url.indexOf("/", 16);
|
|
|
|
|
String type = url.substring(16, i);
|
|
|
|
|
// System.out.println("type"+type);
|
|
|
|
|
// System.out.println("type.toLowerCase()"+type.toLowerCase());
|
|
|
|
|
// String fileId = map.get("name");
|
|
|
|
|
// 本地文件路径
|
|
|
|
|
String filePath = FilePathUtil.getFilePath(type.toLowerCase()) + fileName;
|
|
|
|
|
// 获得图片的base64码
|
|
|
|
|
String imageBase = FileCopy.getImageBase(filePath);
|
|
|
|
|
int[] imgWidthHeight = FileCopy.getImgWidthHeight(filePath);
|
|
|
|
|
HashMap<String, Object> map1 = new HashMap<>();
|
|
|
|
|
map1.put("imgBase", imageBase);
|
|
|
|
|
map1.put("name", fileName);
|
|
|
|
|
map1.put("filePath", filePath);
|
|
|
|
|
if (imgWidthHeight != null) {
|
|
|
|
|
map1.put("width", String.valueOf(imgWidthHeight[0]));
|
|
|
|
|
map1.put("height", String.valueOf(imgWidthHeight[1]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imageBaseList.add(map1);
|
|
|
|
|
// System.out.println(filePath);
|
|
|
|
|
// System.out.println(imageBase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return imageBaseList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取图片宽度和高度
|
|
|
|
|
*
|
|
|
|
|
* @param
|
|
|
|
|
* @return 返回图片的宽度
|
|
|
|
|
*/
|
|
|
|
|
public static int[] getImgWidthHeight(String srcc) {
|
|
|
|
|
if (srcc == null || srcc == "") {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
File file = new File(srcc);
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
InputStream is = null;
|
|
|
|
|
BufferedImage src = null;
|
|
|
|
|
int result[] = {0, 0};
|
|
|
|
|
try {
|
|
|
|
|
// 获得文件输入流
|
|
|
|
|
is = new FileInputStream(file);
|
|
|
|
|
// 从流里将图片写入缓冲图片区
|
|
|
|
|
src = ImageIO.read(is);
|
|
|
|
|
result[0] = src.getWidth(null); // 得到源图片宽
|
|
|
|
|
result[1] = src.getHeight(null);// 得到源图片高
|
|
|
|
|
is.close(); //关闭输入流
|
|
|
|
|
src = null;
|
|
|
|
|
} catch (Exception ef) {
|
|
|
|
|
ef.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
System.gc();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获得图片的base64码
|
|
|
|
|
public static String getImageBase(String src) throws Exception {
|
|
|
|
|
if (src == null || src == "") {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
File file = new File(src);
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
InputStream in = null;
|
|
|
|
|
byte[] data = null;
|
|
|
|
|
try {
|
|
|
|
|
in = new FileInputStream(file);
|
|
|
|
|
data = new byte[in.available()];
|
|
|
|
|
in.read(data);
|
|
|
|
|
in.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
BASE64Encoder encoder = new BASE64Encoder();
|
|
|
|
|
return encoder.encode(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String setSteColumn(Cell cell){
|
|
|
|
|
String cellValue=null;
|
|
|
|
|
// 判断数据的类型
|
|
|
|
|
switch ( cell.getCellType()) {
|
|
|
|
|
case NUMERIC: // 数字
|
|
|
|
|
cellValue = String.valueOf(cell.getNumericCellValue());
|
|
|
|
|
break;
|
|
|
|
|
case STRING: // 字符串
|
|
|
|
|
cellValue = String.valueOf(cell.getStringCellValue());
|
|
|
|
|
break;
|
|
|
|
|
case BOOLEAN: // Boolean
|
|
|
|
|
cellValue = String.valueOf(cell.getBooleanCellValue());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FORMULA: // 公式
|
|
|
|
|
cellValue =NumberToTextConverter.toText(cell.getNumericCellValue());//重点,无精度缺失的确切值.
|
|
|
|
|
break;
|
|
|
|
|
case BLANK: // 空值
|
|
|
|
|
cellValue = "";
|
|
|
|
|
break;
|
|
|
|
|
case ERROR: // 故障
|
|
|
|
|
cellValue = "非法字符";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
cellValue = "未知类型";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return cellValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void copySCMFile(File source, String dest) throws IOException {
|
|
|
|
|
File parentFile = source.getParentFile();
|
|
|
|
|
if (!parentFile.exists()) {
|
|
|
|
|
parentFile.mkdirs();
|
|
|
|
|
copyFile(source, dest);
|
|
|
|
|
} else {
|
|
|
|
|
copyFile(source, dest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void copyFile(File source, String dest) throws IOException {
|
|
|
|
|
|
|
|
|
|
if (source.exists()) {
|
|
|
|
|
//创建目的地文件夹
|
|
|
|
|
File destfile = new File(dest);
|
|
|
|
|
if (!destfile.exists()) {
|
|
|
|
|
destfile.mkdir();
|
|
|
|
|
}
|
|
|
|
|
//如果source是文件夹,则在目的地址中创建新的文件夹
|
|
|
|
|
if (source.isDirectory()) {
|
|
|
|
|
File file = new File(dest + "\\" + source.getName());//用目的地址加上source的文件夹名称,创建新的文件夹
|
|
|
|
|
file.mkdir();
|
|
|
|
|
//得到source文件夹的所有文件及目录
|
|
|
|
|
File[] files = source.listFiles();
|
|
|
|
|
if (files.length == 0) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
|
|
copyFile(files[i], file.getPath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//source是文件,则用字节输入输出流复制文件
|
|
|
|
|
else if (source.isFile()) {
|
|
|
|
|
FileInputStream fis = new FileInputStream(source);
|
|
|
|
|
//创建新的文件,保存复制内容,文件名称与源文件名称一致
|
|
|
|
|
File dfile = new File(dest + "\\" + source.getName());
|
|
|
|
|
if (!dfile.exists()) {
|
|
|
|
|
dfile.createNewFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileOutputStream fos = new FileOutputStream(dfile);
|
|
|
|
|
// 读写数据
|
|
|
|
|
// 定义数组
|
|
|
|
|
byte[] b = new byte[1024];
|
|
|
|
|
// 定义长度
|
|
|
|
|
int len;
|
|
|
|
|
// 循环读取
|
|
|
|
|
while ((len = fis.read(b)) != -1) {
|
|
|
|
|
// 写出数据
|
|
|
|
|
fos.write(b, 0, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//关闭资源
|
|
|
|
|
fos.close();
|
|
|
|
|
fis.close();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|