From 896f4a3230fc8faa399ebe2fab4bae620d44babc Mon Sep 17 00:00:00 2001 From: yuxueliang0813 <407010292@qq.com> Date: Wed, 19 Mar 2025 16:41:45 +0800 Subject: [PATCH] =?UTF-8?q?OA=E9=99=84=E4=BB=B6=E8=AF=BB=E5=8F=96=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repc/task/DobeContractAttachmentTask.java | 2 +- main/java/shkd/utils/AttachmentFileUtil.java | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/main/java/shkd/repc/task/DobeContractAttachmentTask.java b/main/java/shkd/repc/task/DobeContractAttachmentTask.java index 6e60ace..3dc493c 100644 --- a/main/java/shkd/repc/task/DobeContractAttachmentTask.java +++ b/main/java/shkd/repc/task/DobeContractAttachmentTask.java @@ -132,7 +132,7 @@ public class DobeContractAttachmentTask extends AbstractTask implements Plugin { DobeDWUtils.saveLog(contractno,"NAS附件",nasPath,e.getMessage(),false,"NAS上传文件至星瀚"); } }else{ - logger.info(contractno+" OA附件接口返回路径为空,fj_oaid"+ fj_oaid); + logger.info(contractno+" OA附件接口返回路径nasPath为空,fj_oaid"+ fj_oaid); } } } diff --git a/main/java/shkd/utils/AttachmentFileUtil.java b/main/java/shkd/utils/AttachmentFileUtil.java index 337d2f8..5f79837 100644 --- a/main/java/shkd/utils/AttachmentFileUtil.java +++ b/main/java/shkd/utils/AttachmentFileUtil.java @@ -124,8 +124,7 @@ public class AttachmentFileUtil { */ public static boolean saveDirFile2Attchment(String appId, String entity, Object pk, String dirpath, String attachKey, JSONArray filenames) throws IOException { logger.info("传入的文件夹路径"+dirpath); - logger.info("传入的文件名称集合"+filenames); - List> attachments = new ArrayList<>(filenames.size()); + List> attachments = new ArrayList<>(1); Map attachItem; String fileName; JSONObject destFile; @@ -133,29 +132,40 @@ public class AttachmentFileUtil { String actUrl;//星瀚正式文件url //获取临时文件缓存 TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); + InputStream inputs; FileService service = FileServiceFactory.getAttachmentFileService(); //遍历目标目录,得到所有文件 for (int i = 0; i < filenames.size(); i++) { destFile = filenames.getJSONObject(i); + attachments.clear(); fileName = destFile.getString("fileName");//文件名称可能涉及字符集转义,需要注意 attachItem = new HashMap<>(); + //附件编号 如果不设置,在前台删除某一个文件时,会把所有编号为空的都删掉 + attachItem.put("uid", "nas"+System.currentTimeMillis()); //文件名称 attachItem.put("name", fileName); + logger.info("文件名称"+fileName); +// service = FileServiceFactory.getAttachmentFileService(); + inputs = service.getInputStream(dirpath+"/"+fileName); +// inputs = service.getInputStream("E:\\dobews\\dobe_cosmic6\\replay_pid13348.log"); //文件大小 - attachItem.put("size", 1); + attachItem.put("size", ""+inputs.available()); + logger.info("文件大小"+inputs.available()); +// cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); //将文件流存入临时文件缓存(拷贝完成)(最后一个参数为缓存有效期,600秒) - tempUrl = cache.saveAsUrl(fileName, service.getInputStream(dirpath+"/"+fileName), 900); + tempUrl = cache.saveAsUrl(fileName, inputs, 600); //修改时间 attachItem.put("lastModified",System.currentTimeMillis()); + logger.info("文件临时路径"+tempUrl); //将文件缓存中的附件文件上传到正式文件服务器 actUrl = AttachmentServiceHelper.saveTempToFileService(tempUrl,appId,entity,pk,fileName); - + logger.info("文件正式路径"+actUrl); //将新文件的物理路径存入map attachItem.put("url", actUrl); attachments.add(attachItem); + //维护单据和附件的关系(非文件上传) + AttachmentServiceHelper.upload(entity, pk, attachKey, attachments); } - //维护单据和附件的关系(非文件上传) - AttachmentServiceHelper.upload(entity, pk, attachKey, attachments); return true; }