minio存储文件方式修改为local存储。
This commit is contained in:
+130
-25
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.CommonUtils;
|
||||
import com.jero.common.util.DateUtils;
|
||||
import com.jero.common.util.MinioUtil;
|
||||
import com.jero.common.util.UUIDUtils;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
@@ -21,6 +23,7 @@ import com.jero.modules.split.util.ReadWordTable;
|
||||
import com.jero.modules.split.vo.TitleNumberVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
@@ -118,6 +121,17 @@ public class FileSpiltService {
|
||||
@Value("${byd.downLoadFileUrl}")
|
||||
private String bydDownLoadFileUrl;
|
||||
|
||||
/**
|
||||
* 本地:local minio:minio 阿里:alioss
|
||||
*/
|
||||
@Value(value = "${jero.uploadType}")
|
||||
private String uploadType;
|
||||
/**
|
||||
* 拆分图片文件路径
|
||||
*/
|
||||
@Value(value = "${jero.path.splitImgPath}")
|
||||
private String splitImgPath;
|
||||
|
||||
/**
|
||||
* 中国标准数据拆分
|
||||
*
|
||||
@@ -187,10 +201,19 @@ public class FileSpiltService {
|
||||
}
|
||||
OSSFile ossFile = ossFileList.get(0);
|
||||
String readFilePath = ossFile.getUrl();
|
||||
if (StringUtils.isEmpty(readFilePath) || !MinioUtil.doesObjectExist(readFilePath)) {
|
||||
throw new JeroBootException("当前文件未找到,请重新选择!");
|
||||
if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)) {
|
||||
if (StringUtils.isEmpty(readFilePath) || !MinioUtil.doesObjectExist(readFilePath)) {
|
||||
throw new JeroBootException("当前文件未找到,请重新选择!");
|
||||
}
|
||||
splitFileIs = MinioUtil.download(readFilePath);
|
||||
} else if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
try {
|
||||
splitFileIs = new FileInputStream(readFilePath);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new JeroBootException("当前文件未找到,请重新选择!");
|
||||
}
|
||||
}
|
||||
splitFileIs = MinioUtil.download(readFilePath);
|
||||
} else {
|
||||
log.info("下载文档开始=========================================================");
|
||||
try {
|
||||
@@ -276,7 +299,7 @@ public class FileSpiltService {
|
||||
// addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, imageName);
|
||||
//}
|
||||
File mathToImgFile = this.getMathToImgUrl(ctoMath.xmlText());
|
||||
if (messageList.size() > 0) {
|
||||
if (null != mathToImgFile && messageList.size() > 0) {
|
||||
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, mathToImgFile);
|
||||
}
|
||||
} else if (child instanceof CTOMathPara) {
|
||||
@@ -287,7 +310,7 @@ public class FileSpiltService {
|
||||
//}
|
||||
|
||||
File mathToImgFile = this.getMathToImgUrl(ctoMathPara.xmlText());
|
||||
if (messageList.size() > 0) {
|
||||
if (null != mathToImgFile && messageList.size() > 0) {
|
||||
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, mathToImgFile);
|
||||
}
|
||||
}
|
||||
@@ -1204,18 +1227,42 @@ public class FileSpiltService {
|
||||
|
||||
// 像每个条款中依次插入每一段的内容
|
||||
private void addItermsMathImage(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, File file) {
|
||||
byte[] bytev = null;
|
||||
try (FileInputStream fis = new FileInputStream(file)){
|
||||
bytev = new byte[(int) file.length()];
|
||||
fis.read(bytev);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String imageName = UUIDUtils.randomUUID10() + file.getName();
|
||||
String path = splitUrl + imageName;
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
MinioUtil.uploadByte(bytev, filepathandname);
|
||||
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
File splitImgFolder = new File(splitImgPath);
|
||||
if (!splitImgFolder.exists()) {
|
||||
splitImgFolder.mkdirs();
|
||||
}
|
||||
|
||||
String newFilePath = splitImgPath + imageName;
|
||||
try {
|
||||
File newFile = new File(newFilePath);
|
||||
FileUtils.copyFile(file, newFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//上传成功 进行数据库存储
|
||||
OSSFile ossFile = new OSSFile();
|
||||
// 文件名
|
||||
String fileName = file.getName();
|
||||
fileName = CommonUtils.getFileName(fileName);
|
||||
ossFile.setFileName(fileName);
|
||||
ossFile.setUrl(newFilePath);
|
||||
ossFile.setId(imageName);
|
||||
iossFileService.save(ossFile);
|
||||
} else if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){
|
||||
byte[] bytev = null;
|
||||
try (FileInputStream fis = new FileInputStream(file)){
|
||||
bytev = new byte[(int) file.length()];
|
||||
fis.read(bytev);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
MinioUtil.uploadByte(bytev, filepathandname);
|
||||
}
|
||||
|
||||
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
||||
message.getItemsCondi().add(imgConVal);
|
||||
@@ -1228,13 +1275,42 @@ public class FileSpiltService {
|
||||
for (String pictureId : imageBundleList) {
|
||||
XWPFPictureData pictureData = p.getDocument().getPictureDataByID(pictureId);
|
||||
String imageName = UUIDUtils.randomUUID10() + pictureData.getFileName();
|
||||
String path = splitUrl + imageName;
|
||||
|
||||
byte[] bytev = pictureData.getData();
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
try {
|
||||
String path = splitUrl+imageName;
|
||||
String imgConVal = "";
|
||||
String imgCon = "";
|
||||
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
String fileName = pictureData.getFileName();
|
||||
File splitImgFolder = new File(splitImgPath);
|
||||
if (!splitImgFolder.exists()) {
|
||||
splitImgFolder.mkdirs();
|
||||
}
|
||||
|
||||
String newFilePath = splitImgPath + imageName;
|
||||
try (FileOutputStream fos = new FileOutputStream(newFilePath)) {
|
||||
fos.write(bytev);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("写入图片时发生错误:" + e.getMessage());
|
||||
}
|
||||
|
||||
//上传成功 进行数据库存储
|
||||
OSSFile ossFile = new OSSFile();
|
||||
// 文件名
|
||||
fileName = CommonUtils.getFileName(fileName);
|
||||
ossFile.setFileName(fileName);
|
||||
ossFile.setUrl(newFilePath);
|
||||
ossFile.setId(imageName);
|
||||
iossFileService.save(ossFile);
|
||||
} else if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)) {
|
||||
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
MinioUtil.uploadByte(bytev, filepathandname);
|
||||
String imgCon = path;
|
||||
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
||||
}
|
||||
imgCon = path;
|
||||
imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
||||
try {
|
||||
message.getItemsCondi().add(imgConVal);
|
||||
message.setItemContent(message.getItemContent() + imgConVal);
|
||||
itemsValList.add(getSplitItemsValObject(message.getId(), SplitFilePragraTypeEnum.IMG.getValue(), imgCon, message.getItemsCondi().size(), null));
|
||||
@@ -1250,12 +1326,39 @@ public class FileSpiltService {
|
||||
XWPFPictureData pictureData = p.getDocument().getPictureDataByID(pictureId);
|
||||
String imageName = UUIDUtils.randomUUID10() + pictureData.getFileName();
|
||||
byte[] bytev = pictureData.getData();
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
try {
|
||||
String path = splitUrl+imageName;
|
||||
String path = splitUrl+imageName;
|
||||
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
String fileName = pictureData.getFileName();
|
||||
|
||||
File splitImgFolder = new File(splitImgPath);
|
||||
if (!splitImgFolder.exists()) {
|
||||
splitImgFolder.mkdirs();
|
||||
}
|
||||
|
||||
String newFilePath = splitImgPath + imageName;
|
||||
try (FileOutputStream fos = new FileOutputStream(newFilePath)) {
|
||||
fos.write(bytev);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("写入图片时发生错误:" + e.getMessage());
|
||||
}
|
||||
|
||||
//上传成功 进行数据库存储
|
||||
OSSFile ossFile = new OSSFile();
|
||||
// 文件名
|
||||
fileName = CommonUtils.getFileName(fileName);
|
||||
ossFile.setFileName(fileName);
|
||||
ossFile.setUrl(newFilePath);
|
||||
ossFile.setId(imageName);
|
||||
iossFileService.save(ossFile);
|
||||
|
||||
} else if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)) {
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
MinioUtil.uploadByte(bytev, filepathandname);
|
||||
}
|
||||
try {
|
||||
String imgCon = path;
|
||||
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
||||
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\"></img>";
|
||||
stringBuilder.append(imgConVal);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -1374,7 +1477,9 @@ public class FileSpiltService {
|
||||
HttpResponse res = client.execute(post);
|
||||
String results = EntityUtils.toString(res.getEntity());
|
||||
|
||||
result = new File(results);
|
||||
if (StringUtils.isNotEmpty(results)) {
|
||||
result = new File(results);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+39
-8
@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.constant.enums.ModuleEnum;
|
||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||
@@ -139,6 +140,13 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
private String splitUrl;
|
||||
@Value(value = "${jero.path.uploadCos}")
|
||||
private String uploadCospath;
|
||||
@Value("${jero.uploadType}")
|
||||
private String uploadType;
|
||||
/**
|
||||
* 拆分图片文件路径
|
||||
*/
|
||||
@Value(value = "${jero.path.splitImgPath}")
|
||||
private String splitImgPath;
|
||||
|
||||
@Override
|
||||
public int addItemContent(Map<String, Object> parameter){
|
||||
@@ -556,7 +564,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
IPage infoPage = dao.getInfoPage(page, " " + "sar_file_split_menu.display_seq,laws_document_split.*", condition);
|
||||
|
||||
//树形数据字典
|
||||
List<SysCategory> categoryList = sysCategoryService.list();
|
||||
List<SysCategory> categoryList = sysCategoryService.getList();
|
||||
//过滤出树形字段
|
||||
List<OnlCgformField> treeFieldList = fieldList.stream()
|
||||
.filter(e -> FieldTypeEnum.TREE.getValue().equals(e.getFieldShowType()))
|
||||
@@ -3278,7 +3286,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
}
|
||||
|
||||
//树形数据字典
|
||||
List<SysCategory> categoryList = sysCategoryService.list();
|
||||
List<SysCategory> categoryList = sysCategoryService.getList();
|
||||
//过滤出树形字段
|
||||
List<LawsTag> treeFieldList = fieldList.stream()
|
||||
.filter(e -> FieldTypeEnum.TREE.getValue().equals(e.getFieldShowType()))
|
||||
@@ -3459,15 +3467,27 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
@Override
|
||||
public void downLoadImgList(List<FileSplitValImgExportDto> allImgList, String fileNowPath) {
|
||||
for(FileSplitValImgExportDto imgExportDto : allImgList){
|
||||
String oldPath = uploadCospath + "/" + imgExportDto.getImgPath();
|
||||
|
||||
String newPath = fileNowPath + File.separator + imgExportDto.getImgName();
|
||||
if (MinioUtil.doesObjectExist(oldPath)){
|
||||
try (InputStream in = MinioUtil.download(oldPath);) {
|
||||
if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
|
||||
String oldPath = splitImgPath + "/" + imgExportDto.getImgPath();
|
||||
try {
|
||||
InputStream in = new FileInputStream(oldPath);
|
||||
copyFile1(in, newPath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
} else if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)) {
|
||||
String oldPath = uploadCospath + "/" + imgExportDto.getImgPath();
|
||||
if (MinioUtil.doesObjectExist(oldPath)){
|
||||
try (InputStream in = MinioUtil.download(oldPath);) {
|
||||
copyFile1(in, newPath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3476,15 +3496,26 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
@Override
|
||||
public void downLoadFileList(List<OSSFile> allRelevFileList, String fileNowPath) {
|
||||
for(OSSFile fileExportDto : allRelevFileList){
|
||||
String oldPath = fileExportDto.getUrl();
|
||||
String newPath = fileNowPath + File.separator + fileExportDto.getFileName();
|
||||
if (MinioUtil.doesObjectExist(oldPath)){
|
||||
try (InputStream in = MinioUtil.download(oldPath);) {
|
||||
String oldPath = fileExportDto.getUrl();
|
||||
|
||||
if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
|
||||
try {
|
||||
InputStream in = new FileInputStream(oldPath);
|
||||
copyFile1(in, newPath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
} else if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)) {
|
||||
if (MinioUtil.doesObjectExist(oldPath)){
|
||||
try (InputStream in = MinioUtil.download(oldPath);) {
|
||||
copyFile1(in, newPath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user