在线编辑pdf版本
This commit is contained in:
+23
-19
@@ -4895,28 +4895,32 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
||||
QueryWrapper<SarBussStandFile> objectQueryWrapper = new QueryWrapper<>();
|
||||
objectQueryWrapper.eq("ORI_ATT_ID",fileId);
|
||||
objectQueryWrapper.eq("USE_MODEL","SOURCE_FILE");
|
||||
objectQueryWrapper.ne("FILE_SUFFIX","pdf");
|
||||
objectQueryWrapper.ne("FILE_SUFFIX","PDF");
|
||||
objectQueryWrapper.eq("FILE_SUFFIX","docx");
|
||||
// objectQueryWrapper.ne("FILE_SUFFIX","pdf");
|
||||
// objectQueryWrapper.ne("FILE_SUFFIX","PDF");
|
||||
List<SarBussStandFile> sarBussStandFiles = sarBussStandFileEODao.selectList(objectQueryWrapper);
|
||||
// 为空暂不处理 不为空则意味pdf生成失败
|
||||
if(!sarBussStandFiles.isEmpty() && sarBussStandFiles.size()==1){
|
||||
// createStandFileAppend(\);
|
||||
AttFileEO fileInfo = attFileEOService.getFileInfo(sarBussStandFiles.get(0).getOriAttId());
|
||||
String filePath = fileInfo.getFilePath() + fileInfo.getFileName();
|
||||
OtConvertMq convert = new OtConvertMq();
|
||||
convert.setLawsId(sarBussStandFiles.get(0).getStandId());
|
||||
convert.setAttId(fileInfo.getId());
|
||||
convert.setFilePath(filePath);
|
||||
convert.setAddOrUp("0");
|
||||
convert.setFileSuffix(fileInfo.getFileSuffix());
|
||||
convert.setStandFileClassify(sarBussStandFiles.get(0).getStandFileClassify());
|
||||
convert.setConvertType(SarTypeEnum.BUSINESS.getValue());
|
||||
if(elasflag) {
|
||||
try {
|
||||
convertMq.sendMQ(convert);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
AttFileVo attFileVo = attFileEOService.wordConversionFilePdf(sarBussStandFiles.get(0).getOriAttId());
|
||||
if(attFileVo!=null){
|
||||
SarBussStandFile sarBussStandFile = new SarBussStandFile();
|
||||
//sarBussStandFile.setId();
|
||||
String uuId = com.adc.da.util.utils.UUID.randomUUID(20);
|
||||
sarBussStandFile.setId(uuId);
|
||||
sarBussStandFile.setStandId(sarBussStandFiles.get(0).getStandId());
|
||||
sarBussStandFile.setStandFileClassify(sarBussStandFiles.get(0).getStandFileClassify());
|
||||
sarBussStandFile.setAttId(attFileVo.getId());
|
||||
sarBussStandFile.setFileName(filePath+attFileVo.getFilePath()+attFileVo.getFileName());
|
||||
sarBussStandFile.setFileSuffix(attFileVo.getFileSuffix());
|
||||
sarBussStandFile.setUseModel(UseModuleEnum.WEB_FILE.getValue());
|
||||
sarBussStandFile.setPassword(sarBussStandFiles.get(0).getPassword());
|
||||
sarBussStandFile.setValidFlag(0);
|
||||
sarBussStandFile.setCreationTime(new Date());
|
||||
sarBussStandFile.setModifyTime(new Date());
|
||||
sarBussStandFile.setOriAttId(sarBussStandFiles.get(0).getOriAttId());
|
||||
sarBussStandFileEODao.insert(sarBussStandFile);
|
||||
}else {
|
||||
logger.info("======================================word.doc转换失败=================================");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,17 @@
|
||||
</properties>
|
||||
|
||||
<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>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
|
||||
@@ -761,4 +761,11 @@ public class AttFileEOController {
|
||||
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 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.UUIDUtils;
|
||||
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 org.apache.commons.io.FileUtils;
|
||||
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.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
@Service("attFileEOService")
|
||||
@@ -594,5 +594,47 @@ public class AttFileEOServiceImpl extends ServiceImpl<AttFileEODao, AttFileEO> i
|
||||
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