Commit 000322ae authored by qinhu's avatar qinhu

pdf

parent 8cb23f81
......@@ -61,7 +61,7 @@ public class EntityEnclosureController {
} else {
return BaseResponse.errorMsg("登录信息失效");
}
if (!extName.equals(".pdf")) {
if (!extName.equals(".pdf") && (extName.equals(".xls") || extName.equals(".xlsx"))) {
String pdfPath = FastDFSUtils.conventAndUpload(file.getInputStream(), fileName);
map.put("pdfPath", pdfPath);
} else {
......@@ -133,7 +133,7 @@ public class EntityEnclosureController {
mapSub.put("fileUrl", picUrl);
mapSub.put("fileName", fileName);
mapSub.put("extName", extName);
if (!extName.equals(".pdf")) {
if (!extName.equals(".pdf") && (extName.equals(".xls") || extName.equals(".xlsx"))) {
String pdfPath = FastDFSUtils.conventAndUpload(file.getInputStream(), fileName);
mapSub.put("pdfPath", pdfPath);
} else {
......
package cn.wise.sc.cement.business.controller;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.FileExt;
import cn.wise.sc.cement.business.enumation.FileExt;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.query.*;
import cn.wise.sc.cement.business.model.vo.EntrustVo;
......
......@@ -5,7 +5,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.wise.sc.cement.business.entity.EntityEnclosure;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.FileExt;
import cn.wise.sc.cement.business.enumation.FileExt;
import cn.wise.sc.cement.business.model.IndustrialElementKey;
import cn.wise.sc.cement.business.model.IndustrialReport;
import cn.wise.sc.cement.business.model.PageQuery;
......@@ -35,7 +35,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
......
package cn.wise.sc.cement.business.model;
package cn.wise.sc.cement.business.enumation;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @description: 文件扩展名
* @author: qh
* @create: 2020-10-16 13:40
**/
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum FileExt {
//office后缀名
......
package cn.wise.sc.cement.business.util;
import cn.wise.sc.cement.business.model.FileExt;
import cn.wise.sc.cement.business.enumation.FileExt;
import freemarker.template.Configuration;
import freemarker.template.Template;
import lombok.extern.slf4j.Slf4j;
......
......@@ -21,186 +21,186 @@ import java.io.OutputStream;
*/
public class FastDFSUtils {
static {
try {
static {
try {
// ClientGlobal.initByProperties(FastDFSUtils.class.getClassLoader().getResource("fastdfs-client.properties").getPath());
ClientGlobal.initByProperties("fastdfs-client.properties");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
}
}
public static String[] uploadPic(String path, String fileName, long size) {
String[] fileIds = null;
try {
// ClientGloble 读配置文件
// 老大客户端
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
String extName = FilenameUtils.getExtension(fileName);
NameValuePair[] meta_list = new NameValuePair[3];
meta_list[0] = new NameValuePair("fileName", fileName);
meta_list[1] = new NameValuePair("fileExt", extName);
meta_list[2] = new NameValuePair("fileSize", String.valueOf(size));
// http://172.16.15.244:8081/group1/M00/00/00/rBAP9FfFG62AZsuBAADeW7MfEHA287.png
// group1/M00/00/01/wKjIgFWOYc6APpjAAAD-qk29i78248.jpg
fileIds = storageClient.upload_file(path, extName, meta_list);
} catch (Exception e) {
e.printStackTrace();
}
return fileIds;
}
public static String[] uploadPic(InputStream inStream, String fileName, long size) {
String[] fileIds = null;
try {
// ClientGloble 读配置文件
// 老大客户端
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
String extName = FilenameUtils.getExtension(fileName);
NameValuePair[] meta_list = new NameValuePair[3];
meta_list[0] = new NameValuePair("fileName", fileName);
meta_list[1] = new NameValuePair("fileExt", extName);
meta_list[2] = new NameValuePair("fileSize", String.valueOf(size));
// http://172.16.15.244:8081/group1/M00/00/00/rBAP9FfFG62AZsuBAADeW7MfEHA287.png
// group1/M00/00/01/wKjIgFWOYc6APpjAAAD-qk29i78248.jpg
fileIds = storageClient.upload_file(null, size, new UploadFileSender(inStream), extName, meta_list);
} catch (Exception e) {
e.printStackTrace();
}
return fileIds;
}
public static byte[] fileDownload(String fileUrl) {
byte[] by = null;
TrackerClient trackerClient = null;
TrackerServer trackerServer = null;
StorageClient1 storageClient1 = null;
StorageServer storageServer = null;
try {
trackerClient = new TrackerClient();
trackerServer = trackerClient.getConnection();
storageClient1 = new StorageClient1(trackerServer, storageServer);
// 根据文件标识下载文件
by = storageClient1.download_file1(fileUrl);
// 将数据写入输出流
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
}
return by;
}
public static String uploadPic(byte[] pic, String fileName, long size) {
String[] fileIds = null;
try {
// ClientGloble 读配置文件
// 老大客户端
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
String extName = FilenameUtils.getExtension(fileName);
// 设置图片meta信息
NameValuePair[] meta_list = new NameValuePair[3];
meta_list[0] = new NameValuePair("fileName", fileName);
meta_list[1] = new NameValuePair("fileExt", extName);
meta_list[2] = new NameValuePair("fileSize", String.valueOf(size));
// 上传且返回path
fileIds = storageClient.upload_file(pic, extName, meta_list);
return fileIds[0] + "/" + fileIds[1];
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static boolean deletePic(String fileUrl) {
try {
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
StorePath storePath = StorePath.praseFromUrl(fileUrl);
int i = storageClient.delete_file(storePath.getGroup(), storePath.getPath());
System.out.println(i == 0 ? "删除成功" : "删除失败:" + i);
return i == 0;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static String deletePic(String[] fileIds) {
try {
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
int i = storageClient.delete_file(fileIds[0], fileIds[1]);
System.out.println(i == 0 ? "删除成功" : "删除失败:" + i);
} catch (Exception e) {
e.printStackTrace();
}
return fileIds[1];
}
private static class UploadFileSender implements UploadCallback {
private InputStream inStream;
public UploadFileSender(InputStream inStream) {
this.inStream = inStream;
}
@Override
public int send(OutputStream out) throws IOException {
int readBytes;
while ((readBytes = inStream.read()) > 0) {
out.write(readBytes);
}
return 0;
}
}
public static String conventAndUpload(InputStream inputStream, String filename) {
File outputFile = new File(filename + ".pdf");
String filePath = "";
try {
Workbook document = new Workbook(inputStream);
//pdf路径
//操作文档保存
document.save(outputFile.getAbsolutePath(), SaveFormat.PDF);
FileReader fileReader = new FileReader(outputFile.getAbsolutePath());
filePath = uploadPic(fileReader.readBytes(), outputFile.getName(), outputFile.length());
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
//删除创建的输出文件
FileUtil.del(outputFile);
return filePath;
}
}
ClientGlobal.initByProperties("fastdfs-client.properties");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
}
}
public static String[] uploadPic(String path, String fileName, long size) {
String[] fileIds = null;
try {
// ClientGloble 读配置文件
// 老大客户端
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
String extName = FilenameUtils.getExtension(fileName);
NameValuePair[] meta_list = new NameValuePair[3];
meta_list[0] = new NameValuePair("fileName", fileName);
meta_list[1] = new NameValuePair("fileExt", extName);
meta_list[2] = new NameValuePair("fileSize", String.valueOf(size));
// http://172.16.15.244:8081/group1/M00/00/00/rBAP9FfFG62AZsuBAADeW7MfEHA287.png
// group1/M00/00/01/wKjIgFWOYc6APpjAAAD-qk29i78248.jpg
fileIds = storageClient.upload_file(path, extName, meta_list);
} catch (Exception e) {
e.printStackTrace();
}
return fileIds;
}
public static String[] uploadPic(InputStream inStream, String fileName, long size) {
String[] fileIds = null;
try {
// ClientGloble 读配置文件
// 老大客户端
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
String extName = FilenameUtils.getExtension(fileName);
NameValuePair[] meta_list = new NameValuePair[3];
meta_list[0] = new NameValuePair("fileName", fileName);
meta_list[1] = new NameValuePair("fileExt", extName);
meta_list[2] = new NameValuePair("fileSize", String.valueOf(size));
// http://172.16.15.244:8081/group1/M00/00/00/rBAP9FfFG62AZsuBAADeW7MfEHA287.png
// group1/M00/00/01/wKjIgFWOYc6APpjAAAD-qk29i78248.jpg
fileIds = storageClient.upload_file(null, size, new UploadFileSender(inStream), extName, meta_list);
} catch (Exception e) {
e.printStackTrace();
}
return fileIds;
}
public static byte[] fileDownload(String fileUrl) {
byte[] by = null;
TrackerClient trackerClient = null;
TrackerServer trackerServer = null;
StorageClient1 storageClient1 = null;
StorageServer storageServer = null;
try {
trackerClient = new TrackerClient();
trackerServer = trackerClient.getConnection();
storageClient1 = new StorageClient1(trackerServer, storageServer);
// 根据文件标识下载文件
by = storageClient1.download_file1(fileUrl);
// 将数据写入输出流
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
}
return by;
}
public static String uploadPic(byte[] pic, String fileName, long size) {
String[] fileIds = null;
try {
// ClientGloble 读配置文件
// 老大客户端
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
String extName = FilenameUtils.getExtension(fileName);
// 设置图片meta信息
NameValuePair[] meta_list = new NameValuePair[3];
meta_list[0] = new NameValuePair("fileName", fileName);
meta_list[1] = new NameValuePair("fileExt", extName);
meta_list[2] = new NameValuePair("fileSize", String.valueOf(size));
// 上传且返回path
fileIds = storageClient.upload_file(pic, extName, meta_list);
return fileIds[0] + "/" + fileIds[1];
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static boolean deletePic(String fileUrl) {
try {
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
StorePath storePath = StorePath.praseFromUrl(fileUrl);
int i = storageClient.delete_file(storePath.getGroup(), storePath.getPath());
System.out.println(i == 0 ? "删除成功" : "删除失败:" + i);
return i == 0;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static String deletePic(String[] fileIds) {
try {
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
int i = storageClient.delete_file(fileIds[0], fileIds[1]);
System.out.println(i == 0 ? "删除成功" : "删除失败:" + i);
} catch (Exception e) {
e.printStackTrace();
}
return fileIds[1];
}
private static class UploadFileSender implements UploadCallback {
private InputStream inStream;
public UploadFileSender(InputStream inStream) {
this.inStream = inStream;
}
@Override
public int send(OutputStream out) throws IOException {
int readBytes;
while ((readBytes = inStream.read()) > 0) {
out.write(readBytes);
}
return 0;
}
}
public static String conventAndUpload(InputStream inputStream, String filename) {
File outputFile = new File(filename + ".pdf");
String filePath = "";
try {
Workbook document = new Workbook(inputStream);
//pdf路径
//操作文档保存
document.save(outputFile.getAbsolutePath(), SaveFormat.PDF);
FileReader fileReader = new FileReader(outputFile.getAbsolutePath());
filePath = uploadPic(fileReader.readBytes(), outputFile.getName(), outputFile.length());
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
//删除创建的输出文件
FileUtil.del(outputFile);
return filePath;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment