Commit 5dc6af87 authored by qinhu's avatar qinhu

上传pdf的cell包

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