在线编辑pdf版本
This commit is contained in:
+23
-19
@@ -4895,28 +4895,32 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
|||||||
QueryWrapper<SarBussStandFile> objectQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<SarBussStandFile> objectQueryWrapper = new QueryWrapper<>();
|
||||||
objectQueryWrapper.eq("ORI_ATT_ID",fileId);
|
objectQueryWrapper.eq("ORI_ATT_ID",fileId);
|
||||||
objectQueryWrapper.eq("USE_MODEL","SOURCE_FILE");
|
objectQueryWrapper.eq("USE_MODEL","SOURCE_FILE");
|
||||||
objectQueryWrapper.ne("FILE_SUFFIX","pdf");
|
objectQueryWrapper.eq("FILE_SUFFIX","docx");
|
||||||
objectQueryWrapper.ne("FILE_SUFFIX","PDF");
|
// objectQueryWrapper.ne("FILE_SUFFIX","pdf");
|
||||||
|
// objectQueryWrapper.ne("FILE_SUFFIX","PDF");
|
||||||
List<SarBussStandFile> sarBussStandFiles = sarBussStandFileEODao.selectList(objectQueryWrapper);
|
List<SarBussStandFile> sarBussStandFiles = sarBussStandFileEODao.selectList(objectQueryWrapper);
|
||||||
// 为空暂不处理 不为空则意味pdf生成失败
|
// 为空暂不处理 不为空则意味pdf生成失败
|
||||||
if(!sarBussStandFiles.isEmpty() && sarBussStandFiles.size()==1){
|
if(!sarBussStandFiles.isEmpty() && sarBussStandFiles.size()==1){
|
||||||
// createStandFileAppend(\);
|
AttFileVo attFileVo = attFileEOService.wordConversionFilePdf(sarBussStandFiles.get(0).getOriAttId());
|
||||||
AttFileEO fileInfo = attFileEOService.getFileInfo(sarBussStandFiles.get(0).getOriAttId());
|
if(attFileVo!=null){
|
||||||
String filePath = fileInfo.getFilePath() + fileInfo.getFileName();
|
SarBussStandFile sarBussStandFile = new SarBussStandFile();
|
||||||
OtConvertMq convert = new OtConvertMq();
|
//sarBussStandFile.setId();
|
||||||
convert.setLawsId(sarBussStandFiles.get(0).getStandId());
|
String uuId = com.adc.da.util.utils.UUID.randomUUID(20);
|
||||||
convert.setAttId(fileInfo.getId());
|
sarBussStandFile.setId(uuId);
|
||||||
convert.setFilePath(filePath);
|
sarBussStandFile.setStandId(sarBussStandFiles.get(0).getStandId());
|
||||||
convert.setAddOrUp("0");
|
sarBussStandFile.setStandFileClassify(sarBussStandFiles.get(0).getStandFileClassify());
|
||||||
convert.setFileSuffix(fileInfo.getFileSuffix());
|
sarBussStandFile.setAttId(attFileVo.getId());
|
||||||
convert.setStandFileClassify(sarBussStandFiles.get(0).getStandFileClassify());
|
sarBussStandFile.setFileName(filePath+attFileVo.getFilePath()+attFileVo.getFileName());
|
||||||
convert.setConvertType(SarTypeEnum.BUSINESS.getValue());
|
sarBussStandFile.setFileSuffix(attFileVo.getFileSuffix());
|
||||||
if(elasflag) {
|
sarBussStandFile.setUseModel(UseModuleEnum.WEB_FILE.getValue());
|
||||||
try {
|
sarBussStandFile.setPassword(sarBussStandFiles.get(0).getPassword());
|
||||||
convertMq.sendMQ(convert);
|
sarBussStandFile.setValidFlag(0);
|
||||||
} catch (Exception e) {
|
sarBussStandFile.setCreationTime(new Date());
|
||||||
e.printStackTrace();
|
sarBussStandFile.setModifyTime(new Date());
|
||||||
}
|
sarBussStandFile.setOriAttId(sarBussStandFiles.get(0).getOriAttId());
|
||||||
|
sarBussStandFileEODao.insert(sarBussStandFile);
|
||||||
|
}else {
|
||||||
|
logger.info("======================================word.doc转换失败=================================");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,17 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.documents4j</groupId>
|
||||||
|
<artifactId>documents4j-local</artifactId>
|
||||||
|
<version>1.0.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.documents4j</groupId>
|
||||||
|
<artifactId>documents4j-transformer-msoffice-word</artifactId>
|
||||||
|
<version>1.0.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
|
|||||||
@@ -761,4 +761,11 @@ public class AttFileEOController {
|
|||||||
return Result.success(attFileEO);
|
return Result.success(attFileEO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "word转换pdf")
|
||||||
|
@GetMapping("/wordConversionFilePdf")
|
||||||
|
public ResponseMessage<AttFileVo> wordConversionFilePdf(@Param("fileId") String fileId) {
|
||||||
|
AttFileVo attFileVo = attFileEOService.wordConversionFilePdf(fileId);
|
||||||
|
return Result.success(attFileVo);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,4 +34,6 @@ public interface IAttFileEOService extends IService<AttFileEO> {
|
|||||||
void downLoadFileList(List<AttFileEO> multiFileInfos, String fileNowPath) throws IOException;
|
void downLoadFileList(List<AttFileEO> multiFileInfos, String fileNowPath) throws IOException;
|
||||||
|
|
||||||
void deleteById(String id);
|
void deleteById(String id);
|
||||||
|
|
||||||
|
AttFileVo wordConversionFilePdf(String fileId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import com.adc.da.sys.constant.ValidFlagEnum;
|
|||||||
import com.adc.da.util.FileUtil;
|
import com.adc.da.util.FileUtil;
|
||||||
import com.adc.da.util.UUIDUtils;
|
import com.adc.da.util.UUIDUtils;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.documents4j.api.DocumentType;
|
||||||
|
import com.documents4j.api.IConverter;
|
||||||
|
import com.documents4j.job.LocalConverter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -19,10 +22,7 @@ import org.springframework.transaction.annotation.Propagation;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Service("attFileEOService")
|
@Service("attFileEOService")
|
||||||
@@ -594,5 +594,47 @@ public class AttFileEOServiceImpl extends ServiceImpl<AttFileEODao, AttFileEO> i
|
|||||||
return attFileVo;
|
return attFileVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttFileVo wordConversionFilePdf(String fileId) {
|
||||||
|
String src = "/data/slrs/file";
|
||||||
|
AttFileEO fileInfo = getFileInfo(fileId);
|
||||||
|
AttFileVo attFileVoPdf = null;
|
||||||
|
if(fileInfo != null){
|
||||||
|
File fileWord = new File(src+fileInfo.getFilePath()+fileInfo.getFileName());
|
||||||
|
AttFileVo attFileVo = saveFileInfo(fileWord);
|
||||||
|
// 保存后 开始转换为 pdf版本
|
||||||
|
File inputWord = new File(src+attFileVo.getFilePath()+attFileVo.getFileName());
|
||||||
|
String filePdfName = "";
|
||||||
|
if(StringUtils.isNotBlank(attFileVo.getFileName())){
|
||||||
|
String[] split = attFileVo.getFileName().split("\\.");
|
||||||
|
filePdfName = split[0]+".pdf";
|
||||||
|
}
|
||||||
|
File outputFile = new File(src+fileInfo.getFilePath(),filePdfName);
|
||||||
|
try {
|
||||||
|
InputStream docxInputStream = new FileInputStream(inputWord);
|
||||||
|
OutputStream outputStream = new FileOutputStream(outputFile);
|
||||||
|
IConverter converter = LocalConverter.builder().build();
|
||||||
|
converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
|
||||||
|
outputStream.close();
|
||||||
|
// 合法存入当前文件
|
||||||
|
if(outputFile.exists()){
|
||||||
|
logger.info("==================================word.docx转换成功========================");
|
||||||
|
attFileVoPdf = saveFileInfo(outputFile);
|
||||||
|
//存入成功以后 删除word 版本
|
||||||
|
if(attFileVoPdf != null) {
|
||||||
|
if (inputWord.exists()) {
|
||||||
|
inputWord.delete();
|
||||||
|
deleteById(attFileVo.getId());
|
||||||
|
logger.info("==================================word.docx删除成功========================");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(),e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attFileVoPdf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user