政企WPS

This commit is contained in:
zhangqinbin
2023-12-22 10:57:09 +08:00
parent 41a00dd31f
commit 7413176431
3 changed files with 18 additions and 25 deletions

View File

@ -318,7 +318,7 @@ public class WpsController {
businessIdList2.add(tempDocFileId); businessIdList2.add(tempDocFileId);
Optional<AttachmentDetail> optional2 = attachmentClient.findByBusinessId(businessIdList2); Optional<AttachmentDetail> optional2 = attachmentClient.findByBusinessId(businessIdList2);
AttachmentDetail detail = optional2.get(); AttachmentDetail detail = optional2.get();
List<AttachmentEntity> entityList = detail.get(fileId[0]); List<AttachmentEntity> entityList = detail.get(tempDocFileId);
Optional<byte[]> optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId()); Optional<byte[]> optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId());
if(optional1!=null&&optional1.isPresent()) { if(optional1!=null&&optional1.isPresent()) {
fileLength = String.valueOf(optional1.get().length); fileLength = String.valueOf(optional1.get().length);

View File

@ -29,6 +29,4 @@ public interface WpsService{
String downloadDecrypt(String key); String downloadDecrypt(String key);
Map<String,String> saveKSFile(KingSoftFileSaveVo vo); Map<String,String> saveKSFile(KingSoftFileSaveVo vo);
public byte[] uploadTempFile(String fileExtension);
} }

View File

@ -130,6 +130,8 @@ public class WpsServiceImpl implements WpsService {
private String kswpsurl; private String kswpsurl;
@Value("${KingSoftWps.kswpsurl-preview}") @Value("${KingSoftWps.kswpsurl-preview}")
private String kswpsurl_preview; private String kswpsurl_preview;
@Value("${KingSoftWps.tempDocFileId}")
private String tempDocFileId;
@Resource @Resource
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@ -716,37 +718,30 @@ public class WpsServiceImpl implements WpsService {
} }
} }
} }
//没有文件 上传模板一份
if(uploadB){ if(uploadB){
buf = uploadTempFile(fileExtension); log.info(" 没有文件 上传模板一份 "+id+" | "+fileName+" | "+fileExtension);
uploadTempFile(id,fileName,fileExtension);
log.info(" 没有文件 上传模板一份 成功");
} }
return buf; return buf;
} }
@Override private void uploadTempFile(String fileid,String fileName,String fileExtension){
public byte[] uploadTempFile(String fileExtension){
String text = "1111";
byte buf[] = text.getBytes();
File tempFile = null;
try { try {
tempFile = File.createTempFile("tempDoc", "."+fileExtension); List<String> businessIdList2 = new ArrayList<>();
tempFile.deleteOnExit(); // 在程序退出时删除临时文件 businessIdList2.add(tempDocFileId);
Optional<AttachmentDetail> optional2 = attachmentClient.findByBusinessId(businessIdList2);
byte[] b = " ".getBytes(); AttachmentDetail detail = optional2.get();
OutputStream out = new FileOutputStream(tempFile); List<AttachmentEntity> entityList = detail.get(tempDocFileId);
out.write(b); Optional<byte[]> optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId());
out.close(); if(optional1!=null&&optional1.isPresent()) {
byte buf[] = optional1.get();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(tempFile)); Optional<UploadObject> op=attachmentClient.upload(fileid,fileName+"."+fileExtension,buf);
buf = IOUtils.toByteArray(bis); }
log.info("buf:"+buf.length);
}catch (Exception e){ }catch (Exception e){
log.error("读取异常",e); log.error("读取异常",e);
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("模板文件读取异常",true); CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("模板文件读取异常",true);
}finally {
if(tempFile!=null) {
tempFile.deleteOnExit();
}
} }
return buf;
} }
@Override @Override