Commit 5dc6af87 authored by qinhu's avatar qinhu

上传pdf的cell包

parent 000322ae
...@@ -138,22 +138,7 @@ ...@@ -138,22 +138,7 @@
<version>2.8.5</version> <version>2.8.5</version>
</dependency> </dependency>
<dependency>
<groupId>com.aspose</groupId> <!--自定义-->
<artifactId>words</artifactId> <!--自定义-->
<version>1.0</version> <!--自定义-->
<scope>system</scope> <!--system,类似provided,需要显式提供依赖的jar以后,Maven就不会在Repository中查找它-->
<systemPath>${basedir}/lib/words.jar</systemPath> <!--项目根目录下的lib文件夹下-->
</dependency>
<!-- https://mvnrepository.com/artifact/com.aspose/aspose-slides --> <!-- https://mvnrepository.com/artifact/com.aspose/aspose-slides -->
<dependency>
<groupId>com.aspose</groupId> <!--自定义-->
<artifactId>sliders</artifactId> <!--自定义-->
<version>1.0</version> <!--自定义-->
<scope>system</scope> <!--system,类似provided,需要显式提供依赖的jar以后,Maven就不会在Repository中查找它-->
<systemPath>${basedir}/lib/aspose.slides-15.9.0.jar</systemPath> <!--项目根目录下的lib文件夹下-->
</dependency>
<dependency> <dependency>
<groupId>com.aspose</groupId> <!--自定义--> <groupId>com.aspose</groupId> <!--自定义-->
<artifactId>cells</artifactId> <!--自定义--> <artifactId>cells</artifactId> <!--自定义-->
......
package cn.wise.sc.cement.business.controller; package cn.wise.sc.cement.business.controller;
import cn.wise.sc.cement.business.enumation.FileExt;
import cn.wise.sc.cement.business.model.BaseResponse; import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.LoginUser; import cn.wise.sc.cement.business.model.LoginUser;
import cn.wise.sc.cement.business.service.ISysUserService; import cn.wise.sc.cement.business.service.ISysUserService;
...@@ -36,198 +37,198 @@ import java.util.Map; ...@@ -36,198 +37,198 @@ import java.util.Map;
@RequestMapping("/enclosure") @RequestMapping("/enclosure")
public class EntityEnclosureController { public class EntityEnclosureController {
private static final Logger logger = LoggerFactory.getLogger("EntityEnclosureController"); private static final Logger logger = LoggerFactory.getLogger("EntityEnclosureController");
@Autowired @Autowired
protected HttpServletResponse response; protected HttpServletResponse response;
@Autowired @Autowired
protected HttpServletRequest request; protected HttpServletRequest request;
@Autowired @Autowired
private ISysUserService userService; private ISysUserService userService;
@ApiOperation(value = "单个文件上传") @ApiOperation(value = "单个文件上传")
@PostMapping("/fileUpLoad") @PostMapping("/fileUpLoad")
public BaseResponse fileUpLoad(MultipartFile file) { public BaseResponse fileUpLoad(MultipartFile file) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
String filePath = null; String filePath = null;
String fileName = null; String fileName = null;
String extName = null; String extName = null;
try { try {
LoginUser loginUser = userService.getLoginUser(); LoginUser loginUser = userService.getLoginUser();
if (loginUser != null) { if (loginUser != null) {
filePath = FastDFSUtils.uploadPic(file.getBytes(), file.getOriginalFilename(), file.getSize()); filePath = FastDFSUtils.uploadPic(file.getBytes(), file.getOriginalFilename(), file.getSize());
fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")); fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));
extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
} else { } else {
return BaseResponse.errorMsg("登录信息失效"); return BaseResponse.errorMsg("登录信息失效");
} }
if (!extName.equals(".pdf") && (extName.equals(".xls") || extName.equals(".xlsx"))) { if (extName.contains(FileExt.EXCL.getName()) || extName.contains(FileExt.EXCLX.getName())) {
String pdfPath = FastDFSUtils.conventAndUpload(file.getInputStream(), fileName); String pdfPath = FastDFSUtils.conventAndUpload(file.getInputStream(), fileName);
map.put("pdfPath", pdfPath); map.put("pdfPath", pdfPath);
} else { } else {
map.put("pdfPath", filePath); map.put("pdfPath", filePath);
} }
String picUrl = filePath; String picUrl = filePath;
map.put("fileUrl", picUrl); map.put("fileUrl", picUrl);
map.put("fileName", fileName); map.put("fileName", fileName);
map.put("extName", extName); map.put("extName", extName);
return BaseResponse.okData(map); return BaseResponse.okData(map);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString()); logger.error(e.toString());
} }
return BaseResponse.errorMsg("失败"); return BaseResponse.errorMsg("失败");
} }
@ApiOperation(value = "单个图片上传") @ApiOperation(value = "单个图片上传")
@PostMapping("/imgUpLoad") @PostMapping("/imgUpLoad")
public BaseResponse imgUpLoad(MultipartFile file) { public BaseResponse imgUpLoad(MultipartFile file) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
String filePath = null; String filePath = null;
String fileName = null; String fileName = null;
String extName = null; String extName = null;
try { try {
LoginUser loginUser = userService.getLoginUser(); LoginUser loginUser = userService.getLoginUser();
if (loginUser != null) { if (loginUser != null) {
if (!FileTypeUtil.isImageByExtension(file.getOriginalFilename())) { if (!FileTypeUtil.isImageByExtension(file.getOriginalFilename())) {
return BaseResponse.errorMsg("请上传有效图片"); return BaseResponse.errorMsg("请上传有效图片");
} }
filePath = FastDFSUtils.uploadPic(file.getBytes(), file.getOriginalFilename(), file.getSize()); filePath = FastDFSUtils.uploadPic(file.getBytes(), file.getOriginalFilename(), file.getSize());
fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")); fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));
extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
} else { } else {
return BaseResponse.errorMsg("登录信息失效"); return BaseResponse.errorMsg("登录信息失效");
} }
String picUrl = filePath; String picUrl = filePath;
map.put("fileUrl", picUrl); map.put("fileUrl", picUrl);
map.put("fileName", fileName); map.put("fileName", fileName);
map.put("extName", extName); map.put("extName", extName);
map.put("pdfPath", filePath); map.put("pdfPath", filePath);
return BaseResponse.okData(map); return BaseResponse.okData(map);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString()); logger.error(e.toString());
} }
return BaseResponse.errorMsg("失败"); return BaseResponse.errorMsg("失败");
} }
@ApiOperation(value = "多个文件上传") @ApiOperation(value = "多个文件上传")
@PostMapping("/filesUpLoad") @PostMapping("/filesUpLoad")
public BaseResponse filesUpLoad(HttpServletRequest request) { public BaseResponse filesUpLoad(HttpServletRequest request) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
List<MultipartFile> files = null; List<MultipartFile> files = null;
String filePath = null; String filePath = null;
String fileName = null; String fileName = null;
String extName = null; String extName = null;
List<Map<String, Object>> filePathList = null; List<Map<String, Object>> filePathList = null;
try { try {
filePathList = new ArrayList<>(); filePathList = new ArrayList<>();
files = ((MultipartHttpServletRequest) request).getFiles("files"); files = ((MultipartHttpServletRequest) request).getFiles("files");
LoginUser loginUser = userService.getLoginUser(); LoginUser loginUser = userService.getLoginUser();
if (loginUser != null) { if (loginUser != null) {
if (files != null && files.size() > 0) { if (files != null && files.size() > 0) {
for (MultipartFile file : files) { for (MultipartFile file : files) {
Map<String, Object> mapSub = new HashMap<>(); Map<String, Object> mapSub = new HashMap<>();
filePath = FastDFSUtils.uploadPic(file.getBytes(), file.getOriginalFilename(), file.getSize()); filePath = FastDFSUtils.uploadPic(file.getBytes(), file.getOriginalFilename(), file.getSize());
fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")); fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));
extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
String picUrl = filePath; String picUrl = filePath;
mapSub.put("fileUrl", picUrl); mapSub.put("fileUrl", picUrl);
mapSub.put("fileName", fileName); mapSub.put("fileName", fileName);
mapSub.put("extName", extName); mapSub.put("extName", extName);
if (!extName.equals(".pdf") && (extName.equals(".xls") || extName.equals(".xlsx"))) { if (extName.contains(FileExt.EXCL.getName()) || extName.contains(FileExt.EXCLX.getName())) {
String pdfPath = FastDFSUtils.conventAndUpload(file.getInputStream(), fileName); String pdfPath = FastDFSUtils.conventAndUpload(file.getInputStream(), fileName);
mapSub.put("pdfPath", pdfPath); mapSub.put("pdfPath", pdfPath);
} else { } else {
mapSub.put("pdfPath", filePath); mapSub.put("pdfPath", filePath);
} }
filePathList.add(mapSub); filePathList.add(mapSub);
} }
} else { } else {
return BaseResponse.errorMsg("没有文件"); return BaseResponse.errorMsg("没有文件");
} }
} else { } else {
return BaseResponse.errorMsg("登录信息失效"); return BaseResponse.errorMsg("登录信息失效");
} }
return BaseResponse.okData(map); return BaseResponse.okData(map);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString()); logger.error(e.toString());
} }
return BaseResponse.errorMsg("失败"); return BaseResponse.errorMsg("失败");
} }
@ApiOperation(value = "单个文件下载") @ApiOperation(value = "单个文件下载")
@PostMapping("/fileDownload") @PostMapping("/fileDownload")
public BaseResponse fileDownload(String fileUrl, String fileName, String extName) { public BaseResponse fileDownload(String fileUrl, String fileName, String extName) {
OutputStream out = null; OutputStream out = null;
try { try {
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + extName); response.setHeader("Content-Disposition", "attachment;filename=" + fileName + extName);
response.setContentType("application/force-download"); response.setContentType("application/force-download");
out = response.getOutputStream(); out = response.getOutputStream();
LoginUser loginUser = userService.getLoginUser(); LoginUser loginUser = userService.getLoginUser();
if (loginUser != null) { if (loginUser != null) {
fileUrl = fileUrl.substring(fileUrl.indexOf("g")); fileUrl = fileUrl.substring(fileUrl.indexOf("g"));
byte[] by = FastDFSUtils.fileDownload(fileUrl); byte[] by = FastDFSUtils.fileDownload(fileUrl);
out.write(by); out.write(by);
out.close(); out.close();
// BASE64Encoder encoder = new BASE64Encoder(); // BASE64Encoder encoder = new BASE64Encoder();
// String data = encoder.encode(by); // String data = encoder.encode(by);
// return BaseResponse.okMsg(data); // return BaseResponse.okMsg(data);
} else { } else {
return BaseResponse.errorMsg("登录信息失效"); return BaseResponse.errorMsg("登录信息失效");
} }
return BaseResponse.okMsg("成功"); return BaseResponse.okMsg("成功");
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString()); logger.error(e.toString());
} }
return BaseResponse.errorMsg("失败"); return BaseResponse.errorMsg("失败");
} }
@ApiOperation(value = "app扫描二维码下载") @ApiOperation(value = "app扫描二维码下载")
@GetMapping("/appDownload") @GetMapping("/appDownload")
public BaseResponse appDownload(String fileUrl) { public BaseResponse appDownload(String fileUrl) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
OutputStream out = null; OutputStream out = null;
try { try {
response.setHeader("Content-Disposition", "attachment;filename=app-release.apk"); response.setHeader("Content-Disposition", "attachment;filename=app-release.apk");
response.setContentType("application/force-download"); response.setContentType("application/force-download");
out = response.getOutputStream(); out = response.getOutputStream();
fileUrl = fileUrl.substring(fileUrl.indexOf("g")); fileUrl = fileUrl.substring(fileUrl.indexOf("g"));
byte[] by = FastDFSUtils.fileDownload(fileUrl); byte[] by = FastDFSUtils.fileDownload(fileUrl);
out.write(by); out.write(by);
out.close(); out.close();
return BaseResponse.okMsg("成功"); return BaseResponse.okMsg("成功");
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString()); logger.error(e.toString());
} }
return BaseResponse.errorMsg("失败"); return BaseResponse.errorMsg("失败");
} }
@ApiOperation(value = "删除相关文件") @ApiOperation(value = "删除相关文件")
@PostMapping("/fileDeleted") @PostMapping("/fileDeleted")
public BaseResponse fileDeleted(String[] filePaths) { public BaseResponse fileDeleted(String[] filePaths) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
String filePath = null; String filePath = null;
boolean rel = false; boolean rel = false;
try { try {
LoginUser loginUser = userService.getLoginUser(); LoginUser loginUser = userService.getLoginUser();
if (loginUser != null) { if (loginUser != null) {
for (String url : filePaths) { for (String url : filePaths) {
/*filePath = url.substring(0,url.indexOf("g"));*/ /*filePath = url.substring(0,url.indexOf("g"));*/
rel = FastDFSUtils.deletePic(url); rel = FastDFSUtils.deletePic(url);
if (!rel) { if (!rel) {
return BaseResponse.errorMsg("删除失败"); return BaseResponse.errorMsg("删除失败");
} }
} }
} else { } else {
return BaseResponse.errorMsg("登录信息失效"); return BaseResponse.errorMsg("登录信息失效");
} }
return BaseResponse.okMsg("成功"); return BaseResponse.okMsg("成功");
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString()); logger.error(e.toString());
} }
return BaseResponse.errorMsg("失败"); return BaseResponse.errorMsg("失败");
} }
} }
package cn.wise.sc.cement.business.enumation; package cn.wise.sc.cement.business.enumation;
import com.alibaba.fastjson.annotation.JSONType;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import lombok.AllArgsConstructor;
import lombok.Getter;
/** /**
* @description: 文件扩展名 * @description: 文件扩展名
...@@ -9,21 +12,18 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; ...@@ -9,21 +12,18 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
* @create: 2020-10-16 13:40 * @create: 2020-10-16 13:40
**/ **/
@JsonFormat(shape = JsonFormat.Shape.OBJECT) @JsonFormat(shape = JsonFormat.Shape.OBJECT)
@JSONType(serializeEnumAsJavaBean = true)
@Getter
@AllArgsConstructor
public enum FileExt { public enum FileExt {
//office后缀名 //office后缀名
DOC(".doc"), DOC(".doc"),
EXCL(".xls"), EXCL(".xls"),
PDF("pdf"),
EXCLX(".xlsx"); EXCLX(".xlsx");
@EnumValue
private String name; private String name;
FileExt(String name) {
this.name = name;
}
public String getName() {
return name;
}
} }
...@@ -4,7 +4,6 @@ import cn.hutool.core.io.FileUtil; ...@@ -4,7 +4,6 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileReader; import cn.hutool.core.io.file.FileReader;
import com.aspose.cells.SaveFormat; import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook; import com.aspose.cells.Workbook;
import com.aspose.words.Document;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.csource.common.MyException; import org.csource.common.MyException;
import org.csource.common.NameValuePair; import org.csource.common.NameValuePair;
......
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