feat: 在线编辑保存10份

This commit is contained in:
2024-01-24 09:22:43 +08:00
parent 8a161f9cab
commit b28cf1b1e5
5 changed files with 347 additions and 346 deletions
@@ -1,5 +1,6 @@
package com.jero.modules.oss.service; package com.jero.modules.oss.service;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@@ -1,24 +1,28 @@
package com.jero.modules.oss.service.impl; package com.jero.modules.oss.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.constant.enums.LanguageEnum; import com.jero.common.constant.enums.LanguageEnum;
import com.jero.common.exception.JeroBootException; import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.LoginUser; import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.CommonUtils; import com.jero.common.util.CommonUtils;
import com.jero.common.util.MinioUtil; import com.jero.common.util.MinioUtil;
import com.jero.common.util.UUIDUtils;
import com.jero.common.util.oss.OssBootUtil; import com.jero.common.util.oss.OssBootUtil;
import com.jero.modules.oss.entity.OSSFile; import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.mapper.OSSFileMapper; import com.jero.modules.oss.mapper.OSSFileMapper;
import com.jero.modules.oss.service.IOSSFileService; import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.system.util.MyStringUtils; import com.jero.modules.system.util.MyStringUtils;
import me.zhyd.oauth.utils.UuidUtils; import me.zhyd.oauth.utils.UuidUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -27,80 +31,81 @@ import java.util.List;
@Service("ossFileService") @Service("ossFileService")
public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> implements IOSSFileService { public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> implements IOSSFileService {
@Value(value = "${jero.path.upload}") @Value(value = "${jero.path.upload}")
private String uploadpath; private String uploadpath;
@Value(value = "${jero.path.uploadCos}") @Value(value = "${jero.path.uploadCos}")
private String uploadCospath; private String uploadCospath;
/**
* 文件后缀黑名单
*/
@Value(value = "${jero.fileSuffixLimits}")
private String[] fileSuffixLimits;
/** // 文档拆分条款图片访问路径
* 文件后缀黑名单 @Value(value = "${jero.splitUrl}")
*/ private String splitUrl;
@Value(value = "${jero.fileSuffixLimits}")
private String[] fileSuffixLimits;
// 文档拆分条款图片访问路径 @Override
@Value(value = "${jero.splitUrl}") public void upload(MultipartFile multipartFile) throws IOException {
private String splitUrl; String fileName = multipartFile.getOriginalFilename();
@Override fileName = CommonUtils.getFileName(fileName);
public void upload(MultipartFile multipartFile) throws IOException { OSSFile ossFile = new OSSFile();
String fileName = multipartFile.getOriginalFilename(); ossFile.setFileName(fileName);
fileName = CommonUtils.getFileName(fileName); String url = OssBootUtil.upload(multipartFile, "upload/test");
OSSFile ossFile = new OSSFile(); //update-begin--Author:scott Date:20201227 forJT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
ossFile.setFileName(fileName); // 返回阿里云原生域名前缀URL
String url = OssBootUtil.upload(multipartFile,"upload/test"); ossFile.setUrl(OssBootUtil.getOriginalUrl(url));
//update-begin--Author:scott Date:20201227 forJT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败------------------- //update-end--Author:scott Date:20201227 forJT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
// 返回阿里云原生域名前缀URL this.save(ossFile);
ossFile.setUrl(OssBootUtil.getOriginalUrl(url)); }
//update-end--Author:scott Date:20201227 forJT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败-------------------
this.save(ossFile);
}
@Override @Override
public boolean delete(OSSFile ossFile) { public boolean delete(OSSFile ossFile) {
try { try {
this.removeById(ossFile.getId()); this.removeById(ossFile.getId());
OssBootUtil.deleteUrl(ossFile.getUrl()); OssBootUtil.deleteUrl(ossFile.getUrl());
} } catch (Exception ex) {
catch (Exception ex) { return false;
return false; }
} return true;
return true; }
}
@Override
public List<OSSFile> getFileInfosByConnectId(String connectId) {
if(StringUtils.isBlank(connectId)){
return new ArrayList<>();
}
LambdaQueryWrapper<OSSFile> wrapper = new LambdaQueryWrapper<>();
if (connectId.contains(",")) {
wrapper.in(OSSFile::getConnectId, Arrays.asList(connectId.split(",")));
} else {
wrapper.eq(OSSFile::getConnectId, connectId);
}
List<OSSFile> list = this.list(wrapper); @Override
return list; public List<OSSFile> getFileInfosByConnectId(String connectId) {
} if (StringUtils.isBlank(connectId)) {
return new ArrayList<>();
}
LambdaQueryWrapper<OSSFile> wrapper = new LambdaQueryWrapper<>();
if (connectId.contains(",")) {
wrapper.in(OSSFile::getConnectId, Arrays.asList(connectId.split(",")));
} else {
wrapper.eq(OSSFile::getConnectId, connectId);
}
@Override List<OSSFile> list = this.list(wrapper);
public void deleteByConnectIdList(List<String> connectIdList) { return list;
if (connectIdList.size() != 0) { }
LambdaQueryWrapper<OSSFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(OSSFile::getConnectId, connectIdList);
this.remove(lambdaQueryWrapper);
}
}
/**
* 本地文件上传-文档拆分专用
*
* @param mf 文件
* @param bizPath 自定义路径
* @return
*/
@Override
public OSSFile uploadLocalForSplit(MultipartFile mf, String bizPath, String state, String cut) {
//处理文件大小,大于100M抛出异常 @Override
public void deleteByConnectIdList(List<String> connectIdList) {
if (connectIdList.size() != 0) {
LambdaQueryWrapper<OSSFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(OSSFile::getConnectId, connectIdList);
this.remove(lambdaQueryWrapper);
}
}
/**
* 本地文件上传-文档拆分专用
*
* @param mf 文件
* @param bizPath 自定义路径
* @return
*/
@Override
public OSSFile uploadLocalForSplit(MultipartFile mf, String bizPath, String state, String cut) {
//处理文件大小,大于100M抛出异常
// long fileSize = mf.getSize() / 1024 / 1024; // long fileSize = mf.getSize() / 1024 / 1024;
// String originalFilename = mf.getOriginalFilename(); // String originalFilename = mf.getOriginalFilename();
// if (fileSize >= 100) { // if (fileSize >= 100) {
@@ -111,129 +116,130 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
// } // }
// } // }
OSSFile oSSFile = new OSSFile(); OSSFile oSSFile = new OSSFile();
String ctxPath = uploadCospath; String ctxPath = uploadCospath;
String fileName = null; String fileName = null;
String fileType = null; String fileType = null;
String orgName = mf.getOriginalFilename();// 获取文件名 String orgName = mf.getOriginalFilename();// 获取文件名
orgName = CommonUtils.getFileName(orgName); orgName = CommonUtils.getFileName(orgName);
if (orgName.indexOf(".") != -1) { if (orgName.indexOf(".") != -1) {
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf("."));
} else { } else {
fileName = orgName + "_" + System.currentTimeMillis(); fileName = orgName + "_" + System.currentTimeMillis();
} }
String filePath = ctxPath + "/" + fileName; String filePath = ctxPath + "/" + fileName;
fileType = orgName.substring(orgName.lastIndexOf(".")); fileType = orgName.substring(orgName.lastIndexOf("."));
String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF"; String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF";
//判断文件类型 //判断文件类型
if ("1".equals(state)) { if ("1".equals(state)) {
//固定文件 //固定文件
if (!fileTypeStr.contains(fileType)) { if (!fileTypeStr.contains(fileType)) {
if (cut.equals(LanguageEnum.CN.getValue())) { if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!"); throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!");
} else { } else {
throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again"); throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again");
} }
} }
} else { } else {
if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) { if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) {
if (cut.equals(LanguageEnum.CN.getValue())) { if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("不能上传" + StringUtils.join(fileSuffixLimits, ",") + "类型的文件。请重新选择文件!"); throw new JeroBootException("不能上传" + StringUtils.join(fileSuffixLimits, ",") + "类型的文件。请重新选择文件!");
} else { } else {
throw new JeroBootException("Can't upload" + StringUtils.join(fileSuffixLimits, ",") + "type of file Please select the file again"); throw new JeroBootException("Can't upload" + StringUtils.join(fileSuffixLimits, ",") + "type of file Please select the file again");
} }
} }
} }
if (StringUtils.isNotEmpty(fileType)) { if (StringUtils.isNotEmpty(fileType)) {
String[] fileTypeArr = {".doc", ".DOC", ".txt", ".TXT", ".docx", ".DOCX", String[] fileTypeArr = {".doc", ".DOC", ".txt", ".TXT", ".docx", ".DOCX",
".xls", ".XLS", ".xlsx", ".XLSX", ".pdf", ".PDF", ".png", ".PNG", ".xls", ".XLS", ".xlsx", ".XLSX", ".pdf", ".PDF", ".png", ".PNG",
".jfif", ".JFIF", ".pjpeg", ".PJPEG", ".jpeg", ".JPEG", ".pjp", ".PJP", ".jfif", ".JFIF", ".pjpeg", ".PJPEG", ".jpeg", ".JPEG", ".pjp", ".PJP",
".jpg", ".JPG", ".swf", ".SWF", ".bmp", ".BMP", ".rar", ".RAR", ".zip", ".ZIP", ".ppt", ".PPT", ".pptx", ".PPTX", ".csv", ".CSV"}; ".jpg", ".JPG", ".swf", ".SWF", ".bmp", ".BMP", ".rar", ".RAR", ".zip", ".ZIP", ".ppt", ".PPT", ".pptx", ".PPTX", ".csv", ".CSV"};
boolean flag = true; boolean flag = true;
for (String fileTypeTemp : fileTypeArr) { for (String fileTypeTemp : fileTypeArr) {
if (fileTypeTemp.equalsIgnoreCase(fileType)) { if (fileTypeTemp.equalsIgnoreCase(fileType)) {
flag = false; flag = false;
} }
} }
if (flag) { if (flag) {
if (cut.equals(LanguageEnum.CN.getValue())) { if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!");
} else { } else {
throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/Static image type file. Please re select the file!"); throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/Static image type file. Please re select the file!");
} }
} }
} }
// 将文件上传至腾讯云 cos // 将文件上传至腾讯云 cos
String upload = MinioUtil.upload(mf, "/" + uploadCospath); String upload = MinioUtil.upload(mf, "/" + uploadCospath);
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//存入文件表 //存入文件表
oSSFile.setFileName(orgName); oSSFile.setFileName(orgName);
oSSFile.setId(UuidUtils.getUUID()); oSSFile.setId(UuidUtils.getUUID());
oSSFile.setCreateBy(loginUser.getUsername()); oSSFile.setCreateBy(loginUser.getUsername());
oSSFile.setCreateTime(new Date()); oSSFile.setCreateTime(new Date());
this.save(oSSFile); this.save(oSSFile);
// 文件路径做特殊处理 // 文件路径做特殊处理
// BASE64Encoder base64Encoder = new BASE64Encoder(); // BASE64Encoder base64Encoder = new BASE64Encoder();
// String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8)); // String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8));
String imgUrl = upload.split("/")[1]; String imgUrl = upload.split("/")[1];
oSSFile.setUrl(splitUrl + imgUrl); oSSFile.setUrl(splitUrl + imgUrl);
return oSSFile; return oSSFile;
} }
@Override @Override
public List<OSSFile> getFileInfos(String id) { public List<OSSFile> getFileInfos(String id) {
if (MyStringUtils.isEmpty(id)) { if (MyStringUtils.isEmpty(id)) {
return new ArrayList<>(); return new ArrayList<>();
} }
LambdaQueryWrapper<OSSFile> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<OSSFile> wrapper = new LambdaQueryWrapper<>();
wrapper.in(OSSFile::getId, id.split(",")); wrapper.in(OSSFile::getId, id.split(","));
wrapper.orderByAsc(OSSFile::getCreateTime); wrapper.orderByAsc(OSSFile::getCreateTime);
List<OSSFile> list = this.list(wrapper); List<OSSFile> list = this.list(wrapper);
if (list.size() == 0) { if (list.size() == 0) {
LambdaQueryWrapper<OSSFile> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<OSSFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(OSSFile::getConnectId, id.split(",")); lambdaQueryWrapper.in(OSSFile::getConnectId, id.split(","));
lambdaQueryWrapper.orderByAsc(OSSFile::getCreateTime); lambdaQueryWrapper.orderByAsc(OSSFile::getCreateTime);
list = this.list(lambdaQueryWrapper); list = this.list(lambdaQueryWrapper);
} }
return list; return list;
} }
@Override
public List<OSSFile> getFileInfoAll(String id) { @Override
if (MyStringUtils.isEmpty(id)) { public List<OSSFile> getFileInfoAll(String id) {
return new ArrayList<>(); if (MyStringUtils.isEmpty(id)) {
} return new ArrayList<>();
LambdaQueryWrapper<OSSFile> wrapper = new LambdaQueryWrapper<>(); }
wrapper.in(OSSFile::getId, id.split(",")); LambdaQueryWrapper<OSSFile> wrapper = new LambdaQueryWrapper<>();
List<OSSFile> list = this.list(wrapper); wrapper.in(OSSFile::getId, id.split(","));
LambdaQueryWrapper<OSSFile> lambdaQueryWrapper = new LambdaQueryWrapper<>(); List<OSSFile> list = this.list(wrapper);
lambdaQueryWrapper.in(OSSFile::getConnectId, id.split(",")); LambdaQueryWrapper<OSSFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
list.addAll(this.list(lambdaQueryWrapper)); lambdaQueryWrapper.in(OSSFile::getConnectId, id.split(","));
return list; list.addAll(this.list(lambdaQueryWrapper));
} return list;
}
@Override
public void updateFileInfo(List<OSSFile> ossFileList) {
this.updateBatchById(ossFileList);
}
@Override /**
public void updateFileInfo(List<OSSFile> ossFileList) { * 本地文件上传 cos
this.updateBatchById(ossFileList); *
} * @param mf 文件
/** * @param bizPath 自定义路径
* 本地文件上传 cos * @return
* */
* @param mf 文件 @Override
* @param bizPath 自定义路径 public OSSFile uploadLocalOfCos(MultipartFile mf, String bizPath, String state, String cut) {
* @return
*/
@Override
public OSSFile uploadLocalOfCos(MultipartFile mf, String bizPath, String state, String cut) {
//处理文件大小,大于100M抛出异常 //处理文件大小,大于100M抛出异常
// long fileSize = mf.getSize() / 1024 / 1024; // long fileSize = mf.getSize() / 1024 / 1024;
// String originalFilename = mf.getOriginalFilename(); // String originalFilename = mf.getOriginalFilename();
// if (fileSize >= 100) { // if (fileSize >= 100) {
@@ -244,90 +250,90 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
// } // }
// } // }
OSSFile oSSFile = new OSSFile(); OSSFile oSSFile = new OSSFile();
String ctxPath = uploadCospath; String ctxPath = uploadCospath;
if (StringUtils.isNotBlank(bizPath)) { if (StringUtils.isNotBlank(bizPath)) {
ctxPath += bizPath; ctxPath += bizPath;
} }
String fileName = null; String fileName = null;
String fileType = null; String fileType = null;
String orgName = mf.getOriginalFilename();// 获取文件名 String orgName = mf.getOriginalFilename();// 获取文件名
orgName = CommonUtils.getFileName(orgName); orgName = CommonUtils.getFileName(orgName);
if (orgName.indexOf(".") != -1) { if (orgName.indexOf(".") != -1) {
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf("."));
} else { } else {
fileName = orgName + "_" + System.currentTimeMillis(); fileName = orgName + "_" + System.currentTimeMillis();
} }
String filePath = ctxPath + "/" + fileName; String filePath = ctxPath + "/" + fileName;
fileType = orgName.substring(orgName.lastIndexOf(".")); fileType = orgName.substring(orgName.lastIndexOf("."));
String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF"; String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF";
//判断文件类型 //判断文件类型
if ("1".equals(state)) { if ("1".equals(state)) {
//固定文件 //固定文件
if (!fileTypeStr.contains(fileType)) { if (!fileTypeStr.contains(fileType)) {
if (cut.equals(LanguageEnum.CN.getValue())) { if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!"); throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!");
} else { } else {
throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again"); throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again");
} }
} }
} else if ("2".equals(state)) { // 认证-参数导出模板上传 专用 } else if ("2".equals(state)) { // 认证-参数导出模板上传 专用
String fileTypeStrTwo = ".docx,.DOCX,.xlsx,.XLSX"; String fileTypeStrTwo = ".docx,.DOCX,.xlsx,.XLSX";
List<String> fileTypeStrTwoList = Arrays.asList(fileTypeStrTwo.split(",")); List<String> fileTypeStrTwoList = Arrays.asList(fileTypeStrTwo.split(","));
//固定文件 //固定文件
if (!fileTypeStrTwoList.contains(fileType)) { if (!fileTypeStrTwoList.contains(fileType)) {
if (cut.equals(LanguageEnum.CN.getValue())) { if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传.docx,.DOCX,.xlsx,.XLSX后缀类型的文件。请重新选择文件!"); throw new JeroBootException("只能够上传.docx,.DOCX,.xlsx,.XLSX后缀类型的文件。请重新选择文件!");
} else { } else {
throw new JeroBootException("Only upload .docx,.DOCX,.xlsx,.XLSX suffix type of file Please select the file again"); throw new JeroBootException("Only upload .docx,.DOCX,.xlsx,.XLSX suffix type of file Please select the file again");
} }
} }
} else { } else {
if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) { if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) {
if (cut.equals(LanguageEnum.CN.getValue())) { if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("不能上传" + StringUtils.join(fileSuffixLimits, ",") + "类型的文件。请重新选择文件!"); throw new JeroBootException("不能上传" + StringUtils.join(fileSuffixLimits, ",") + "类型的文件。请重新选择文件!");
} else { } else {
throw new JeroBootException("Can't upload" + StringUtils.join(fileSuffixLimits, ",") + "type of file Please select the file again"); throw new JeroBootException("Can't upload" + StringUtils.join(fileSuffixLimits, ",") + "type of file Please select the file again");
} }
} }
} }
if (StringUtils.isNotEmpty(fileType)) { if (StringUtils.isNotEmpty(fileType)) {
String[] fileTypeArr = {".doc", ".DOC", ".txt", ".TXT", ".docx", ".DOCX", String[] fileTypeArr = {".doc", ".DOC", ".txt", ".TXT", ".docx", ".DOCX",
".xls", ".XLS", ".xlsx", ".XLSX", ".pdf", ".PDF", ".png", ".PNG", ".xls", ".XLS", ".xlsx", ".XLSX", ".pdf", ".PDF", ".png", ".PNG",
".jfif", ".JFIF", ".pjpeg", ".PJPEG", ".jpeg", ".JPEG", ".pjp", ".PJP", ".jfif", ".JFIF", ".pjpeg", ".PJPEG", ".jpeg", ".JPEG", ".pjp", ".PJP",
".jpg", ".JPG", ".swf", ".SWF", ".bmp", ".BMP", ".rar", ".RAR", ".zip", ".jpg", ".JPG", ".swf", ".SWF", ".bmp", ".BMP", ".rar", ".RAR", ".zip",
".ZIP", ".ppt", ".PPT", ".pptx", ".PPTX", ".csv", ".CSV", ".gif", ".GIF", ".ZIP", ".ppt", ".PPT", ".pptx", ".PPTX", ".csv", ".CSV", ".gif", ".GIF",
".msg", ".MSG"}; ".msg", ".MSG"};
boolean flag = true; boolean flag = true;
for (String fileTypeTemp : fileTypeArr) { for (String fileTypeTemp : fileTypeArr) {
if (fileTypeTemp.equalsIgnoreCase(fileType)) { if (fileTypeTemp.equalsIgnoreCase(fileType)) {
flag = false; flag = false;
} }
} }
if (flag) { if (flag) {
if (cut.equals(LanguageEnum.CN.getValue())) { if (cut.equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/msg/gif/静态图片类型的文件。请重新选择文件!"); throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/msg/gif/静态图片类型的文件。请重新选择文件!");
} else { } else {
throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/msg/gif/Static image type file. Please re select the file!"); throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/msg/gif/Static image type file. Please re select the file!");
} }
} }
} }
// 将文件上传至腾讯云 cos // 将文件上传至腾讯云 cos
MinioUtil.upload(mf, filePath); MinioUtil.upload(mf, filePath);
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//存入文件表 //存入文件表
oSSFile.setFileName(orgName); oSSFile.setFileName(orgName);
oSSFile.setId(UuidUtils.getUUID()); oSSFile.setId(UuidUtils.getUUID());
oSSFile.setUrl(filePath); oSSFile.setUrl(filePath);
oSSFile.setCreateBy(loginUser.getUsername()); oSSFile.setCreateBy(loginUser.getUsername());
oSSFile.setCreateTime(new Date()); oSSFile.setCreateTime(new Date());
this.save(oSSFile); this.save(oSSFile);
oSSFile.setUrl(null); oSSFile.setUrl(null);
return oSSFile; return oSSFile;
} }
} }
@@ -159,13 +159,12 @@ public class OnlyOfficeController {
downloadUri = downloadUri.replace("onlyoffice.sinotruk.com", "onlyoffice-sa2of.yf-grp:8080"); downloadUri = downloadUri.replace("onlyoffice.sinotruk.com", "onlyoffice-sa2of.yf-grp:8080");
BusProcessModelHis modelHis = busProcessModelHisService.getById(fileId); BusProcessModelHis modelHis = busProcessModelHisService.getById(fileId);
String editFilePath = modelHis.getEditFilePath(); String editFilePath = modelHis.getEditFilePath();
String saveFileUrl = standEditFilePath + String saveFileUrl = standEditFilePath + editFilePath;
editFilePath;
logger.info("**********onlyoffice文档下载路径************" + downloadUri); logger.info("**********onlyoffice文档下载路径************" + downloadUri);
logger.info("**********onlyoffice文档保存本地路径************" + saveFileUrl); logger.info("**********onlyoffice文档保存本地路径************" + saveFileUrl);
HttpUtil.downloadFileFromUrl(downloadUri, saveFileUrl); HttpUtil.downloadFileFromUrl(downloadUri, saveFileUrl);
//File file = new File(saveFileUrl); File file = new File(saveFileUrl);
//downloadNetFile(downloadUri, file); downloadNetFile(downloadUri, file);
// 更新在线编辑当前节点编辑状态 // 更新在线编辑当前节点编辑状态
busProcessModelHisService.modelHisOneUpdStatusById(fileId); busProcessModelHisService.modelHisOneUpdStatusById(fileId);
Object keyObj = jsonObj.get("key"); Object keyObj = jsonObj.get("key");
@@ -191,7 +190,6 @@ public class OnlyOfficeController {
} catch (IOException e) { } catch (IOException e) {
logger.info("**********onlyoffice接收文档接口异常************" + e.getMessage()); logger.info("**********onlyoffice接收文档接口异常************" + e.getMessage());
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return;
} }
} }
@@ -1,19 +1,22 @@
package com.jero.modules.onlyoffice.service; package com.jero.modules.onlyoffice.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jero.common.util.MinioUtil;
import com.jero.common.util.UUIDUtils;
import com.jero.modules.onlyoffice.entity.AttFileEO; import com.jero.modules.onlyoffice.entity.AttFileEO;
import com.jero.modules.onlyoffice.entity.AttFileVo; import com.jero.modules.onlyoffice.entity.AttFileVo;
import com.jero.modules.onlyoffice.entity.OnlineFileLog; import com.jero.modules.onlyoffice.entity.OnlineFileLog;
import com.jero.modules.onlyoffice.mapper.AttFileEODao; import com.jero.modules.onlyoffice.mapper.AttFileEODao;
import com.jero.modules.onlyoffice.mapper.BusProcessModelHisMapper;
import com.jero.modules.onlyoffice.mapper.OnlineFileLogDao; import com.jero.modules.onlyoffice.mapper.OnlineFileLogDao;
import com.jero.modules.onlyoffice.service.impl.AttFileEOServiceImpl; import com.jero.modules.onlyoffice.service.impl.AttFileEOServiceImpl;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -28,45 +31,50 @@ import java.util.List;
@Service @Service
@Slf4j @Slf4j
public class LawsUserInfoService { public class LawsUserInfoService {
@Value("${file.path}") @Value("${file.path}")
private String standEditFilePath; private String standEditFilePath;
@Autowired
@Resource
private IBusProcessModelHisService busProcessModelHisService; private IBusProcessModelHisService busProcessModelHisService;
@Autowired
private AttFileEOServiceImpl attFileEOService; @Resource
@Autowired
private OnlineFileLogDao onlineFileLogDao; private OnlineFileLogDao onlineFileLogDao;
@Autowired
private AttFileEODao attFileEODao; @Resource
private IOSSFileService ossFileService;
/** /**
* 查找在线编辑文件 * 查找在线编辑文件
*
* @param onlineFileId * @param onlineFileId
* @param standName * @param standName
* @param key * @param key
*/ */
public void selectOnlineFile(String onlineFileId, String standName, String key) { public void selectOnlineFile(String onlineFileId, String standName, String key) {
log.info("======================standName===============================!!!!!!!!!!!!!!!!!!!!!!"+standName); log.info("======================standName===============================!!!!!!!!!!!!!!!!!!!!!!" + standName);
String path = standEditFilePath+"/hisFile/"; String path = standEditFilePath + "hisFile/";
File file = null; File file = null;
FileOutputStream fileOutputStream = null; FileOutputStream fileOutputStream = null;
BufferedOutputStream bufferedOutputStream = null; BufferedOutputStream bufferedOutputStream = null;
//下载位置 //下载位置
OnlineFileLog onlineFileLog = busProcessModelHisService.selectOnlineFile(onlineFileId); OnlineFileLog onlineFileLog = busProcessModelHisService.selectOnlineFile(onlineFileId);
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
if(onlineFileLog == null){ if (onlineFileLog == null) {
return ; return;
} }
String fileName = UUIDUtils.randomUUID(20);
try { try {
file = new File(path+onlineFileLog.getOldFileName()); file = new File(path + onlineFileLog.getOldFileName());
boolean directory = file.isDirectory(); boolean directory = file.isDirectory();
log.info("**********path+onlineFileLog.getOldFileName()本地路径************" + path+onlineFileLog.getOldFileName()); log.info("**********path+onlineFileLog.getOldFileName()本地路径************" + path + onlineFileLog.getOldFileName());
//目录是否存在 //目录是否存在
if(!directory){ if (!directory) {
file.mkdirs(); file.mkdirs();
} }
file = new File(path+"/"+onlineFileLog.getOldFileName(),onlineFileLog.getOldFileName()+"."+onlineFileLog.getFileSuffix()); file = new File(path + "/" + onlineFileLog.getOldFileName(), fileName + "." + onlineFileLog.getFileSuffix());
log.info("**********parent路径************" + path+"/"+onlineFileLog.getOldFileName()); log.info("**********parent路径************" + path + "/" + onlineFileLog.getOldFileName());
log.info("**********child路径************" + onlineFileLog.getOldFileName()+"."+onlineFileLog.getFileSuffix()); log.info("**********child路径************" + onlineFileLog.getOldFileName() + "." + onlineFileLog.getFileSuffix());
fileOutputStream = new FileOutputStream(file); fileOutputStream = new FileOutputStream(file);
bufferedOutputStream = new BufferedOutputStream(fileOutputStream); bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
fileOutputStream.write(onlineFileLog.getBytes()); fileOutputStream.write(onlineFileLog.getBytes());
@@ -74,80 +82,69 @@ public class LawsUserInfoService {
//把文件下载到本地 然后获得文件的名称 通过文件名称 调用 filesave接口 获取id 进行日志存入 //把文件下载到本地 然后获得文件的名称 通过文件名称 调用 filesave接口 获取id 进行日志存入
log.info("======================文件存储到本地成功,作为存储与Att表的桥梁==============================="); log.info("======================文件存储到本地成功,作为存储与Att表的桥梁===============================");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.info("======================文件存储到本地失败===============================");
}finally { } finally {
try { try {
if(bufferedOutputStream!=null){ if (bufferedOutputStream != null) {
bufferedOutputStream.close(); bufferedOutputStream.close();
} }
if(fileOutputStream!=null){ if (fileOutputStream != null) {
fileOutputStream.close(); fileOutputStream.close();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); log.info("======================文件流关闭失败===============================");
} }
} }
//把文件放置到本地 // 把文件放置到本地
AttFileVo attFileVo = attFileEOService.saveFileInfo(file); OSSFile ossFile = new OSSFile();
log.info("======================文件成功存储到Att中==============================="+attFileVo.toString()); // 开始存储文件信息
//储存文件 一个文件夹 储存十个 ossFile.setFileName(onlineFileLog.getOldFileName());
if(attFileVo!=null) { String fileUrl = "hisFile/" + onlineFileLog.getOldFileName() + "/" + fileName + "." + onlineFileLog.getFileSuffix();
onlineFileLog.setAttFileId(attFileVo.getId()); ossFile.setUrl(fileUrl);
onlineFileLog.setUpdateTime(new Date()); ossFileService.save(ossFile);
onlineFileLog.setCreateTime(new Date()); log.info("======================文件成功存储到Oss中===============================" + ossFile.toString());
onlineFileLog.setFileName(String.valueOf(time)); // 储存文件 一个文件夹 储存十个
onlineFileLog.setValidFlag("0"); onlineFileLog.setAttFileId(ossFile.getId());
onlineFileLog.setFileKey(key); onlineFileLog.setUpdateTime(new Date());
onlineFileLogDao.insert(onlineFileLog); onlineFileLog.setCreateTime(new Date());
log.info("======================日志存入成功==============================="); onlineFileLog.setFileName(String.valueOf(time));
if(StringUtils.isNotBlank(standName)) { onlineFileLog.setValidFlag("0");
AttFileEO attFileEO = new AttFileEO(); onlineFileLog.setFileKey(key);
attFileEO.setId(attFileVo.getId()); onlineFileLogDao.insert(onlineFileLog);
attFileEO.setOldFileName(standName+".docx"); log.info("======================日志存入成功===============================");
// TODO 等在线编辑正式上线时,需要替换成oss_file表 if (StringUtils.isNotBlank(standName)) {
attFileEODao.updateFileInfoById(attFileEO); ossFile.setFileName(standName + ".docx");
log.info("======================文件名称修改成功==============================="+standName+".docx"+"======"+"传入对象为:"+attFileEO.getOldFileName()); ossFileService.updateById(ossFile);
} log.info("======================文件名称修改成功===============================" + standName + ".docx" + "======" + "传入对象为:" + ossFile.getFileName());
//删除媒介桥梁文件 }
if(file.delete()){ QueryWrapper<OnlineFileLog> onlineFileLogQueryWrapperHis = new QueryWrapper<>();
//删除文件名称 onlineFileLogQueryWrapperHis.eq("HIS_ID", onlineFileId);
File fileTOW = new File(path+onlineFileLog.getOldFileName()); onlineFileLogQueryWrapperHis.eq("VALID_FLAG", "0");
if(fileTOW.delete()){ onlineFileLogQueryWrapperHis.orderByAsc("CREATE_TIME");
File fileInfo = new File(path); List<OnlineFileLog> onlineFileLogs = onlineFileLogDao.selectList(onlineFileLogQueryWrapperHis);
if(fileInfo.delete()){ // 只保留最近的10个文件
log.info("======================桥梁文件删除成功==============================="+path+onlineFileLog.getOldFileName()); if (onlineFileLogs.size() > 10) {
log.info("======================文件日志记录小于10===============================" + onlineFileLogs.size());
QueryWrapper<OnlineFileLog> onlineFileLogQueryWrapper = new QueryWrapper<>();
onlineFileLogQueryWrapper.eq("ID", onlineFileLogs.get(0).getId());
OnlineFileLog onlineFileLogIsNot = onlineFileLogDao.selectOne(onlineFileLogQueryWrapper);
if (onlineFileLogIsNot != null) {
// 删除此处有关的数据
OSSFile ossFileInfo = ossFileService.getById(onlineFileLogIsNot.getAttFileId());
if (ossFileInfo != null) {
// 删除所有相关文件和记录
File fileAtt = new File(standEditFilePath + ossFileInfo.getUrl());
boolean delete = fileAtt.delete();
if (delete) {
log.info("======================文件删除成功===============================" + ossFileInfo.getUrl());
ossFileService.removeById(onlineFileLogIsNot.getAttFileId());
onlineFileLogDao.deleteById(onlineFileLogs.get(0).getId());
} }
} }
}else {
log.info("======================桥梁文件删除失败!!!!!!!!===============================");
}
QueryWrapper<OnlineFileLog> onlineFileLogQueryWrapperHis = new QueryWrapper<>();
onlineFileLogQueryWrapperHis.eq("HIS_ID",onlineFileId);
onlineFileLogQueryWrapperHis.eq("VALID_FLAG","0");
onlineFileLogQueryWrapperHis.orderByAsc("CREATE_TIME");
List<OnlineFileLog> onlineFileLogs = onlineFileLogDao.selectList(onlineFileLogQueryWrapperHis);
//建立删除
// File deleteFileInfo = new File(path + onlineFileLog.getOLdFileName()+"/",onlineFileLogs.get(0).getFileName()+"."+onlineFileLogs.get(0).getFileSuffix());
if(onlineFileLogs.size()>10){
log.info("======================文件日志记录小于10==============================="+onlineFileLogs.size());
QueryWrapper<OnlineFileLog> onlineFileLogQueryWrapper = new QueryWrapper<>();
onlineFileLogQueryWrapper.eq("FILE_NAME",onlineFileLogs.get(0).getFileName());
OnlineFileLog onlineFileLogIsNot = onlineFileLogDao.selectOne(onlineFileLogQueryWrapper);
if(onlineFileLogIsNot!=null){
//删除此处有关的数据
AttFileEO fileInfo = attFileEOService.getFileInfo(onlineFileLogIsNot.getAttFileId());
if(fileInfo!=null){
File fileAtt = new File(standEditFilePath+fileInfo.getFilePath()+fileInfo.getFileName());
if(fileAtt.delete()){
attFileEOService.deleteById(onlineFileLogIsNot.getAttFileId());
onlineFileLogDao.deleteById(onlineFileLogs.get(0).getId());
}
}
}
log.info("删除成功"+onlineFileLogs.get(0).getId());
}else {
log.info("======================文件日志记录小于10==============================="+onlineFileLogs.size());
} }
log.info("删除成功" + onlineFileLogs.get(0).getId());
} else {
log.info("======================文件日志记录小于10===============================" + onlineFileLogs.size());
} }
} }
} }
@@ -80,7 +80,6 @@ public class BusProcessModelHisServiceImpl extends ServiceImpl<BusProcessModelHi
File targetFile = new File(filePath + targetPath); File targetFile = new File(filePath + targetPath);
FileUtils.copyFile(sourceFile, targetFile); FileUtils.copyFile(sourceFile, targetFile);
SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
modelHis.setTaskId(taskId); modelHis.setTaskId(taskId);
modelHis.setPId(topId); modelHis.setPId(topId);
modelHis.setEditFilePath(targetPath); modelHis.setEditFilePath(targetPath);