From ada1632e4dd438a6eff16eb867c4ddd611c06bac Mon Sep 17 00:00:00 2001 From: yuxueliang0813 <407010292@qq.com> Date: Wed, 19 Mar 2025 11:45:33 +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 | 23 ++++++++++++------- main/java/shkd/utils/AttachmentFileUtil.java | 9 +------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/main/java/shkd/repc/task/DobeContractAttachmentTask.java b/main/java/shkd/repc/task/DobeContractAttachmentTask.java index c6f60e3..6e60ace 100644 --- a/main/java/shkd/repc/task/DobeContractAttachmentTask.java +++ b/main/java/shkd/repc/task/DobeContractAttachmentTask.java @@ -1,5 +1,6 @@ package shkd.repc.task; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; @@ -65,13 +66,14 @@ public class DobeContractAttachmentTask extends AbstractTask implements Plugin { String requrl; String nasPath = null; JSONObject resultjsonObject; + JSONArray filenames; for (int i = 0; i < cons.length; i++) { contractinfo = cons[i]; //根据合同中的编号、附件oa id、正文oa id三个字段调用OA附件接口,记录日志 contractid = contractinfo.getLong("id"); contractno = contractinfo.getString("billno"); - fj_oaid = contractinfo.getString("qeug_fjoaid"); - fj_zwid = contractinfo.getString("qeug_fjzwid"); + fj_oaid = contractinfo.getString("qeug_fjoaid");//流程ID(Excel导入模板中的附件字段) 必填 + fj_zwid = contractinfo.getString("qeug_fjzwid");//正文ID(Excel导入模板中的合同正文字段) 非必填 //拿到OA附件接口返回的NAS文件存放路径 requrl = oaUrl+oa_menthod+contractno+"?summaryId="+fj_oaid+"&subReference="+fj_zwid; @@ -103,22 +105,27 @@ public class DobeContractAttachmentTask extends AbstractTask implements Plugin { if(!DobeDWUtils.isEmpty(nasPath)){ //处理表单附件目录 nasPath = nasPath.substring(2).replace("\\","/"); -// resultjsonObject.getJSONArray(""); try { + boolean upresult = false; //nasPath+fj_oaid; - logger.info(contractno+" OA附件接口返回nasPath\n{}", nasPath+"/"+fj_oaid); - boolean upresult = AttachmentFileUtil.saveDirFile2Attchment(appId,entityName,contractid,nasPath+"/"+fj_oaid,attachKey,null); + filenames = resultjsonObject.getJSONArray("att_fileNames");//流程附件文件名称清单 + if(filenames != null && !filenames.isEmpty()){ + upresult = AttachmentFileUtil.saveDirFile2Attchment(appId,entityName,contractid,nasPath+"/"+fj_oaid,attachKey,filenames); + } //处理合同正文附件目录 if(!DobeDWUtils.isEmpty(fj_zwid)){ - //nasPath+fj_zwid; -// AttachmentFileUtil.saveDirFile2Attchment(appId,entityName,contractid,nasPath+"/"+fj_zwid,zwattKey); + filenames = resultjsonObject.getJSONArray("contract_fileNames");//合同正文文件名称清单 + if(filenames != null && !filenames.isEmpty()){ + AttachmentFileUtil.saveDirFile2Attchment(appId,entityName,contractid,nasPath+"/"+fj_zwid,zwattKey,filenames); + } } //上传成功后更新合同未上传附件的标记为false if(upresult){ DB.update(DBRoute.of("scm"), updatesql, new Object[]{contractid}); //记录成功日志 - DobeDWUtils.saveLog(contractno,"NAS附件",nasPath,null,true,"NAS上传文件至星瀚"); + DobeDWUtils.saveLog(contractno,"NAS附件",null,null,true,"NAS上传文件至星瀚"); } + } catch (Exception e) { //记录附件上传异常信息 logger.info(contractno+" 从NAS上传文件至星瀚异常"+e.getMessage()); diff --git a/main/java/shkd/utils/AttachmentFileUtil.java b/main/java/shkd/utils/AttachmentFileUtil.java index 2e87afd..337d2f8 100644 --- a/main/java/shkd/utils/AttachmentFileUtil.java +++ b/main/java/shkd/utils/AttachmentFileUtil.java @@ -124,13 +124,6 @@ public class AttachmentFileUtil { */ public static boolean saveDirFile2Attchment(String appId, String entity, Object pk, String dirpath, String attachKey, JSONArray filenames) throws IOException { logger.info("传入的文件夹路径"+dirpath); - filenames = new JSONArray(); - JSONObject f1 = new JSONObject(); - f1.put("filename","1.docx"); - filenames.add(f1); - JSONObject f2 = new JSONObject(); - f2.put("filename","2.docx"); - filenames.add(f2); logger.info("传入的文件名称集合"+filenames); List> attachments = new ArrayList<>(filenames.size()); Map attachItem; @@ -144,7 +137,7 @@ public class AttachmentFileUtil { //遍历目标目录,得到所有文件 for (int i = 0; i < filenames.size(); i++) { destFile = filenames.getJSONObject(i); - fileName = destFile.getString("filename");//TODO 文件名称可能涉及字符集转义,需要注意 + fileName = destFile.getString("fileName");//文件名称可能涉及字符集转义,需要注意 attachItem = new HashMap<>(); //文件名称 attachItem.put("name", fileName);