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