Kaynağa Gözat

需求变更:
存放位置确认;
①文件名称上如维护了存放路径的:规则: 文件名_路径_XXXXX结尾的,根据文件名上的路径进行存放。
②如没有此标识的,根据SHR模版上的路径进行存放 ③如都没维护的,统一放在一个默认的分组

heyuan 1 hafta önce
ebeveyn
işleme
34dceb71ed

+ 1 - 1
src/com/kingdee/eas/custom/esign/app/ESignTemplateFileEntryControllerBean.java

@@ -129,7 +129,7 @@ public class ESignTemplateFileEntryControllerBean extends AbstractESignTemplateF
         }
         FilterInfo filterInfo = new FilterInfo();
         FilterItemCollection filterItems = filterInfo.getFilterItems();
-        filterItems.add(new FilterItemInfo("name", "%" + fileName + "%", CompareType.LIKE));
+        filterItems.add(new FilterItemInfo("name", fileName + "%", CompareType.LIKE));
         filterItems.add(new FilterItemInfo("state", BaseItemStateEnum.ENABLE_VALUE));
         SelectorItemCollection sic = new SelectorItemCollection();
         sic.add("id");

+ 101 - 76
src/com/kingdee/eas/custom/esign/util/SyncSignedFilesUtil.java

@@ -29,9 +29,7 @@ import org.apache.log4j.Logger;
 
 import java.io.IOException;
 import java.text.MessageFormat;
-import java.util.HashSet;
-import java.util.Locale;
-import java.util.Set;
+import java.util.*;
 
 /**
  * @Description 签署文件同步
@@ -130,83 +128,110 @@ public class SyncSignedFilesUtil {
             FileTabInfo fileTabInfo,
             JSONArray attachments
     ) throws IOException, BOSException, EASBizException {
-        IESignTemplateFileEntry ieSignTemplateFileEntry = ESignTemplateFileEntryFactory.getLocalInstance(ctx);
-        IAttachment iAttachment = AttachmentFactory.getLocalInstance(ctx);
-        IBoAttchAsso iBoAttchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
-        ISHRAttachmentExt ishrAttachmentExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
-        UserInfo userInfo = (UserInfo) ctx.get("UserInfo");
-        String userId = userInfo.getId().toString();
-        // 遍历并保存签署生成的正式文件
-        for (int i = 0; null!=attachments && i < attachments.size(); i++) {
-            JSONObject fileMap = attachments.getJSONObject(i);
-            String fileName = fileMap.getString("fileName");
-            String downloadUrl = fileMap.getString("downloadUrl");
-            String fileId = "fileTab" + fileMap.getString("fileId");
-            logger.error("fileId: " + fileId);
-            if (StringUtils.isBlank(downloadUrl)) {
-                logger.error("下载地址为空!");
-                continue;
-            }
-            // 查询对应模板文件的组件ID
-            String componentId = ieSignTemplateFileEntry.findByFileName(fileName);
-            // 查询附件是否存在,如果存在需要删除
-            delAttachment(ctx, fileId);
-            byte[] content = DownloaderUtil.downloadFileToByteArray(downloadUrl);
-            // 检查文件名是否包含脚本攻击
-            fileName = checkScriptAttack(fileName);
-            if( fileName.lastIndexOf(46)<=0) {
-                fileName +=".pdf";
-            }
-            String mainname = fileName.substring(0, fileName.lastIndexOf(46));
-            String extname = fileName.substring(fileName.lastIndexOf(46) + 1, fileName.length());
-            extname = extname.toLowerCase();
-            //附件对象
-            AttachmentInfo ai = new AttachmentInfo();
-            setAttMulNameAndDesc(ctx, ai, mainname, null);
-            ai.setSimpleName(extname);
-            ai.setFile(content);
-            ai.setIsShared(false);
-            //ai.setNumber();
-            ai.setSharedDesc(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "false"));
-            int size = content.length;
-            if (size < 1024) {
-                ai.setSize(size + SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "byte"));
-            } else {
-                ai.setSize(size / 1024 + "KB");
-            }
-            ai.setSizeInByte(size);
-            ai.setAttachID(fileId);//附件id
-            ai.setType(getFileType(fileName));
-            ai.setBeizhu(EMPPAGEUIPK);//uipk
-            //附件扩展
-            SHRAttachmentExtInfo attchExt = new SHRAttachmentExtInfo();
-            attchExt.setAttachment(ai);
-            setAttExtMulNameAndDesc(ctx, attchExt, fileName, "");
-            attchExt.setPropertyName(componentId);
-            attchExt.setType(AttachmentTypeEnum.FORM);
-            attchExt.setState(AttachmentState.SAVE);
-            String bunding = MessageFormat.format("{0}#{1}", userId, EMPPAGEUIPK);
-            attchExt.setBunding(bunding);
-            attchExt.setBoID(fileTabInfo.getId().toString());//业务对象id
-            try {
-                //保存附件对象
-                iAttachment.addnew(ai);
-            } catch (Exception e) {
-                e.printStackTrace();
-                throw e;
+        if (null != attachments) {
+            IESignTemplateFileEntry ieSignTemplateFileEntry = ESignTemplateFileEntryFactory.getLocalInstance(ctx);
+            IAttachment iAttachment = AttachmentFactory.getLocalInstance(ctx);
+            IBoAttchAsso iBoAttchAsso = BoAttchAssoFactory.getLocalInstance(ctx);
+            ISHRAttachmentExt ishrAttachmentExt = SHRAttachmentExtFactory.getLocalInstance(ctx);
+            IAttachmentStoragePathConfig iAttachmentStoragePathConfig = AttachmentStoragePathConfigFactory.getLocalInstance(ctx);
+            UserInfo userInfo = (UserInfo) ctx.get("UserInfo");
+            String userId = userInfo.getId().toString();
+            //附件类别
+            Map<String, String> attachStoragePathConfigMap = new HashMap<String, String>();
+            AttachmentStoragePathConfigCollection attachStoragePathConfigCol =
+                    iAttachmentStoragePathConfig.getAttachmentStoragePathConfigCollection("select name,componentId where state ='1'");
+            for (int i = 0; i < attachStoragePathConfigCol.size(); i++) {
+                AttachmentStoragePathConfigInfo attachmentStoragePathConfigInfo = attachStoragePathConfigCol.get(i);
+                attachStoragePathConfigMap.put(attachmentStoragePathConfigInfo.getName(), attachmentStoragePathConfigInfo.getComponentId());
             }
-            attchExt.setState(AttachmentState.SAVE);
-            //保存附件扩展
-            BoAttchAssoInfo boAttchAssoInfo = new BoAttchAssoInfo();
-            boAttchAssoInfo.setBoID(fileTabInfo.getId().toString());//业务对象id
-            boAttchAssoInfo.setAssoBusObjType(String.valueOf(fileTabInfo.getBOSType()));
+            // 遍历并保存签署生成的正式文件
+            for (int i = 0; i < attachments.size(); i++) {
+                JSONObject fileMap = attachments.getJSONObject(i);
+                String fileName = fileMap.getString("fileName");
+                String downloadUrl = fileMap.getString("downloadUrl");
+                String fileId = "fileTab" + fileMap.getString("fileId");
+                logger.error("fileId: " + fileId);
+                if (StringUtils.isBlank(downloadUrl)) {
+                    logger.error("下载地址为空!");
+                    continue;
+                }
+                logger.error("saveAttachment fileName: " + fileName);
+                String componentId = null;
+                String[] fileNameArr = fileName.split("_");
+                if (fileNameArr.length == 3 && "路径".equals(fileNameArr[1])) {
+                    //文件名携带存储路径:文件名_路径_XXXXX
+                    String[] pathNameArr = fileNameArr[2].split("\\.");
+                    fileName = fileNameArr[0];
+                    if (pathNameArr.length > 1) {
+                        fileName += "." + pathNameArr[pathNameArr.length - 1];
+                    }
+                    componentId = attachStoragePathConfigMap.getOrDefault(pathNameArr[0], "default");
+                } else {
+                    //走模板文件存储路径匹配规则
+                    // 查询对应模板文件的组件ID
+                    componentId = ieSignTemplateFileEntry.findByFileName(fileName);
+                }
+                // 查询附件是否存在,如果存在需要删除
+                delAttachment(ctx, fileId);
+                byte[] content = DownloaderUtil.downloadFileToByteArray(downloadUrl);
+                // 检查文件名是否包含脚本攻击
+                fileName = checkScriptAttack(fileName);
+                //符号"."的索引
+                int index = fileName.lastIndexOf(46);
+                if (index <= 0) {
+                    fileName += ".pdf";
+                }
+                String mainname = fileName.substring(0, index);
+                String extname = fileName.substring(index + 1, fileName.length());
+                extname = extname.toLowerCase();
+                //附件对象
+                AttachmentInfo ai = new AttachmentInfo();
+                setAttMulNameAndDesc(ctx, ai, mainname, null);
+                ai.setSimpleName(extname);
+                ai.setFile(content);
+                ai.setIsShared(false);
+                //ai.setNumber();
+                ai.setSharedDesc(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "false"));
+                int size = content.length;
+                if (size < 1024) {
+                    ai.setSize(size + SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "byte"));
+                } else {
+                    ai.setSize(size / 1024 + "KB");
+                }
+                ai.setSizeInByte(size);
+                ai.setAttachID(fileId);//附件id
+                ai.setType(getFileType(fileName));
+                ai.setBeizhu(EMPPAGEUIPK);//uipk
+                //附件扩展
+                SHRAttachmentExtInfo attchExt = new SHRAttachmentExtInfo();
+                attchExt.setAttachment(ai);
+                setAttExtMulNameAndDesc(ctx, attchExt, fileName, "");
+                attchExt.setPropertyName(componentId);
+                attchExt.setType(AttachmentTypeEnum.FORM);
+                attchExt.setState(AttachmentState.SAVE);
+                String bunding = MessageFormat.format("{0}#{1}", userId, EMPPAGEUIPK);
+                attchExt.setBunding(bunding);
+                attchExt.setBoID(fileTabInfo.getId().toString());//业务对象id
+                try {
+                    //保存附件对象
+                    iAttachment.addnew(ai);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    throw e;
+                }
+                attchExt.setState(AttachmentState.SAVE);
+                //保存附件扩展
+                BoAttchAssoInfo boAttchAssoInfo = new BoAttchAssoInfo();
+                boAttchAssoInfo.setBoID(fileTabInfo.getId().toString());//业务对象id
+                boAttchAssoInfo.setAssoBusObjType(String.valueOf(fileTabInfo.getBOSType()));
 //            boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l1);
 //            boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l2);
 //            boAttchAssoInfo.setAssoType("Added Accessories", LocaleUtils.locale_l3);
-            boAttchAssoInfo.setAttachment(ai);
-            //保存
-            iBoAttchAsso.addnew(boAttchAssoInfo);
-            ishrAttachmentExt.addnew(attchExt);
+                boAttchAssoInfo.setAttachment(ai);
+                //保存
+                iBoAttchAsso.addnew(boAttchAssoInfo);
+                ishrAttachmentExt.addnew(attchExt);
+            }
         }
     }