add: 添加根据文件ID将文件转换为PDF文件接口,用于其他处理文件转换逻辑
This commit is contained in:
@@ -1,19 +1,37 @@
|
||||
package com.adc.da.convert.mq;
|
||||
|
||||
import com.adc.da.att.entity.AttFileEO;
|
||||
import com.adc.da.att.service.IAttFileEOService;
|
||||
import com.adc.da.att.vo.AttFileVo;
|
||||
import com.adc.da.convert.common.AsposeOfficeConvertUtils;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.core.AmqpTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Component
|
||||
public class CreateConvertMQService {
|
||||
|
||||
|
||||
@Value("${file.path}")
|
||||
private String localFilePath;
|
||||
|
||||
@Autowired
|
||||
private AmqpTemplate rabbitTemplate;
|
||||
|
||||
@Autowired
|
||||
private IAttFileEOService attFileEOService;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CreateConvertMQService.class);
|
||||
/**
|
||||
*
|
||||
* @param attFileEO 文件对象
|
||||
@@ -24,4 +42,40 @@ public class CreateConvertMQService {
|
||||
//发送消息队列
|
||||
// this.rabbitTemplate.convertAndSend("convert-exchange_SQ_GSAR", "convert-key_SQ_GSAR", attFileEO);
|
||||
}
|
||||
|
||||
|
||||
public AttFileVo convertWordFileToPdfFile(String attId){
|
||||
AttFileVo pdfFileVO = new AttFileVo();
|
||||
if(StringUtils.isNotBlank(attId)){
|
||||
try {
|
||||
AttFileEO sourceFileEO = attFileEOService.getFileInfo(attId);
|
||||
if(sourceFileEO!=null){
|
||||
String fileType = sourceFileEO.getFileSuffix();
|
||||
String path = localFilePath + sourceFileEO.getFilePath();
|
||||
String convertfilename = path +sourceFileEO.getFileName();
|
||||
String savePdfFileName = convertfilename.substring(0, convertfilename.lastIndexOf("."));
|
||||
String savePdfPath = savePdfFileName+".pdf";
|
||||
AsposeOfficeConvertUtils.convertOfficeFileToPDF(fileType,convertfilename,savePdfPath);
|
||||
File pdfFile = new File(savePdfPath);
|
||||
if(!savePdfPath.isEmpty() && pdfFile.length()>0){
|
||||
// 上传转换后文件
|
||||
pdfFileVO = attFileEOService.saveFileInfo(pdfFile);
|
||||
}else{
|
||||
pdfFileVO.setStandName("文件转换失败");
|
||||
logger.error("文件转换失败啦!!!");
|
||||
}
|
||||
}else{
|
||||
pdfFileVO.setStandName("当前文件ID未能找到对应的文件");
|
||||
logger.error("当前文件ID[{0}]未能找到对应文件 ",attId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
pdfFileVO.setStandName("文件转换过程中报错啦");
|
||||
logger.error("文件转换失败啦");
|
||||
}
|
||||
}else{
|
||||
pdfFileVO.setStandName("当前文件ID为空,不做处理");
|
||||
logger.error("当前文件ID为空,不做处理");
|
||||
}
|
||||
return pdfFileVO;
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -102,4 +102,23 @@ public class OtConvertController extends BaseController<OtConvert> {
|
||||
createConvertMQService.sendConvertMQ(attFileEO);
|
||||
return Result.success("");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Author zhangyanduan
|
||||
* @Description 根据ATTID将文件转换为PDF文件并归档返回ATTID
|
||||
* Date 2022年4月18日
|
||||
* @Param [fileId]
|
||||
* @return com.adc.da.util.http.ResponseMessage<com.adc.da.att.entity.AttFileEO>
|
||||
**/
|
||||
@ApiOperation(value = "根据ATTID将文件转换为PDF文件并归档返回ATTID")
|
||||
@GetMapping("/convertFileToFileId")
|
||||
public ResponseMessage<AttFileVo> convertFileToFileId(String attId){
|
||||
AttFileVo attFileVo = createConvertMQService.convertWordFileToPdfFile(attId);
|
||||
return Result.success(attFileVo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user