瀏覽代碼

档案元数据收集优化

lvy 5 天之前
父節點
當前提交
a5bda69303

+ 4 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/MetadataClassification.java

@@ -42,24 +42,28 @@ public class MetadataClassification extends BaseEntity {
     private String code;
     /**
      * 字段数据类型
+     * 1:字符串,4:日期
      */
     @ApiModelProperty(value = "字段数据类型")
     private String fieldType;
 
     /**
      * 容器类型
+     * 100:无,0:来源,1:文件联,2:内容描述,3:文件标识码,4:照片文件,5:电子属性,6:数字化属性,7:电子签名,8:竣工图,9:业务层级
      */
     @ApiModelProperty(value = "容器类型")
     private Integer containerType;
 
     /**
      * 捕获方式
+     * 0:手动,1:自动,2:手动/自动
      */
     @ApiModelProperty(value = "捕获方式")
     private Integer captureMode;
 
     /**
      * 是否必选
+     * 0:可选,1:必选,2:条件选
      */
     @ApiModelProperty(value = "是否必选")
     private Integer mandatoryType;

+ 263 - 215
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/MetadataClassificationServiceImpl.java

@@ -293,216 +293,9 @@ public class MetadataClassificationServiceImpl
 //            ancestors = ancestors.substring(ancestors.indexOf(","));
             ancestors = ancestors + "," + archiveTreeContractById.getId();
             List<ArchiveTreeContract> list = archiveTreeContractClient.getArchiveTreeContractListByIds(ancestors);
-            StringBuffer paperAddress= new StringBuffer();
-            StringBuffer nameStr = new StringBuffer();
-            // 单位工程
-            StringBuffer unitProjectString = new StringBuffer();
-            // 单位工程编码
-            StringBuffer unitProjectIdString = new StringBuffer();
-            // 分部工程
-            StringBuffer divisionProjectString = new StringBuffer();
-            // 分部工程编码
-            StringBuffer divisionProjectIdString = new StringBuffer();
-            // 分项工程
-            StringBuffer itemizedProjectString = new StringBuffer();
-            // 分项工程编码
-            StringBuffer itemizedProjectIdString = new StringBuffer();
-            for (int i = 0 ;i<list.size();i++) {
-                metadataSetting(list.get(i), unitProjectString, unitProjectIdString, divisionProjectString, divisionProjectIdString, itemizedProjectString, itemizedProjectIdString);
-                if(i == 0){
-                    continue;
-                }
-                if(list.get(i).getId().equals(archiveTreeContractById.getParentId())){
-                    paperAddress.append(list.get(i).getNodeName());
-                    paperAddress.append(">");
-                    paperAddress.append(archiveTreeContractById.getNodeName());
-                }
-                nameStr.append(list.get(i).getNodeName());
-                nameStr.append("/");
-            }
-            keyValue.put("聚合层次", nameStr.toString());
-            /**全宗名称 手写**/
-
-            /**立档单位名称**/
-            String dutyUser = "";
-            if (byId.getDutyUser().isEmpty() && !byId.getContractId().isEmpty()) {
-                ContractInfo contractById = contractClient.getContractById(Long.parseLong(byId.getContractId()));
-                if (contractById.getContractType() == 1) {
-                    dutyUser = contractById.getConstructionUnitName();
-                } else if (contractById.getContractType() == 2) {
-                    dutyUser = contractById.getSupervisionUnitName();
-                } else {
-                    dutyUser = contractById.getContractorUnitName();
-                }
-            } else {
-                dutyUser = byId.getDutyUser();
-            }
-            keyValue.put("立档单位名称", dutyUser);
-            /**元数据目录文件 同聚合层次**/
-            keyValue.put("元数据目录文件", nameStr.toString());
-
-            /**电子文件号**/
-            keyValue.put("电子文件号", fileId);
-
-            /**文件页数**/
-            keyValue.put("文件页数", byId.getFilePage());
-            /**生成方式 1原生,2数字化 2**/
-            keyValue.put("生成方式", byId.getSourceType());
-            /**题名**/
-            keyValue.put("题名", byId.getFileName());
-            /**关键词**/
-            String keyWords = "";
-            if (byId.getFileName().length() < 9) {
-                keyWords = byId.getFileName();
-            } else {
-                keyWords = byId.getFileName().substring(0, 8);
-            }
-            keyValue.put("关键词", keyWords);
-            /**摘要**/
-            String zhaiyao = "该文件为【数字化】于【" + byId.getFileTime() + "】形成,共【" + byId.getFilePage() + "】页、【" + byId.getFileName() + "】,责任者为【" + dutyUser + "】";
-            keyValue.put("摘要", zhaiyao);
-            /**文件日期**/
-            keyValue.put("文件日期", byId.getFileTime());
-            /**密级**/
-            if (byId.getArchiveId() != null) {
-                ArchivesAuto archivesAuto = archiveAutoClient.saveArchiveAutoById(byId.getArchiveId());
-                keyValue.put("密级", archivesAuto.getSecretLevel());
-
-                /**档号**/
-                keyValue.put("档号",archivesAuto.getFileNumber());
-                /**移交时间 手写**/
-
-                /**保管期限**/
-                keyValue.put("保管期限",archivesAuto.getStorageTime());
-                /**文件件数**/
-                keyValue.put("文件件数",archivesAuto.getFileN());
-
-                /**验证码**/
-                keyValue.put("验证码",archivesAuto.getId());
-            }
-
-
-            /**文号**/
-            keyValue.put("文号", byId.getFileNumber());
-            /**表单标识码**/
-//            keyValue.put("表单标识码", fileId);
-
-            /**主题**/
-            keyValue.put("主题", byId.getFileName());
-            /**拍摄时间**/
-            keyValue.put("拍摄时间", byId.getFilmingTime());
-            /**拍摄地点**/
-//            keyValue.put("拍摄地点", byId.getFileNumber());
-            /**摄影者**/
-//            keyValue.put("摄影者", byId.getFileNumber());
-            /**背景**/
-//            keyValue.put("背景", byId.getFileNumber());
-            /**分组号**/
-            keyValue.put("分组号", byId.getFilmCode());
-            /**组内照片编号**/
-            keyValue.put("组内照片编号", byId.getReferCode());
-            /**水平分辨率**/
-//            keyValue.put("水平分辨率", byId.getReferCode());
-            /**垂直分辨率**/
-//            keyValue.put("垂直分辨率", byId.getReferCode());
-
-
-            String fileUrl = byId.getFileUrl();
-            if(fileUrl!=null && Func.isNotEmpty(fileUrl)){
-                /**格式名称**/
-               if (fileUrl.contains(".")) {
-                   keyValue.put("格式名称", fileUrl.substring(fileUrl.lastIndexOf(".") + 1));
-               } else {
-                   keyValue.put("格式名称", "");
-               }
-                /**存储位置**/
-                keyValue.put("存储位置", fileUrl);
-                /**计算机文件名**/
-                String substring = fileUrl.substring(fileUrl.lastIndexOf("/") + 1, fileUrl.lastIndexOf("."));
-                keyValue.put("计算机文件名", substring);
-            }
-
-            /**计算机文件大小**/
-            keyValue.put("计算机文件大小", byId.getFileSize());
-            /**扫描分辨率 300dpi**/
-            keyValue.put("扫描分辨率", "300dpi");
-            /**扫描色彩模式 彩色**/
-            keyValue.put("扫描色彩模式", "彩色");
-
-            /**纸质文件位置**/
-            keyValue.put("纸质文件位置", paperAddress);
-
-            /**竣工图**/
-            if ((archiveTreeContractById.getIsBuiltDrawing() != null && archiveTreeContractById.getIsBuiltDrawing() == 1  )|| (archiveTreeContractById.getStorageType() != null && archiveTreeContractById.getStorageType() == 2)) {
-                /**图号**/
-                keyValue.put("图号", byId.getDrawingNo());
-                /**图幅**/
-                keyValue.put("图幅", byId.getSheetType());
-                /**图表来源**/
-                keyValue.put("图表来源", byId.getSheetSource());
-                /**引用变更令 编号**/
-                keyValue.put("引用变更令 编号", byId.getCiteChangeNumber());
-            }
-
-            /**业务事项**/
-            if (archiveTreeContractById.getStorageType() != null && Func.isNotEmpty(archiveTreeContractById.getStorageType())) {
-                keyValue.put("业务事项", StorageTypeEnum.getByCode(archiveTreeContractById.getStorageType()));
-            }
-            /**单位工程**/
-            keyValue.put("单位工程", StringUtils.isNotBlank(unitProjectString.toString()) ? unitProjectString.substring(0, unitProjectString.length()-1) : null);
-            /**单位工程编码**/
-            keyValue.put("单位工程编码", StringUtils.isNotBlank(unitProjectIdString.toString()) ? unitProjectIdString.substring(0, unitProjectIdString.length()-1) : null);
-            /**分部工程**/
-            keyValue.put("分部工程", StringUtils.isNotBlank(divisionProjectString.toString()) ? divisionProjectString.substring(0, divisionProjectString.length()-1) : null);
-            /**分部工程编码**/
-            keyValue.put("分部工程编码", StringUtils.isNotBlank(divisionProjectIdString.toString()) ? divisionProjectIdString.substring(0, divisionProjectIdString.length()-1) : null);
-            /**分项工程**/
-            keyValue.put("分项工程", StringUtils.isNotBlank(itemizedProjectString.toString()) ? itemizedProjectString.substring(0, itemizedProjectString.length()-1) : null);
-            /**分项工程编码**/
-            keyValue.put("分项工程编码", StringUtils.isNotBlank(itemizedProjectIdString.toString()) ? itemizedProjectIdString.substring(0, itemizedProjectIdString.length()-1) : null);
-
-            /**责任者名称**/
-            keyValue.put("责任者名称", byId.getDutyUser());
-            /**关系**/
-            keyValue.put("关系", "引用");
-
-            // 获取签名信息
-            Task task = iTaskService.getTaskByFormDataId(byId.getId().toString());
-            if(ObjectUtil.isNotEmpty(task)){
-                // 拿到processInstanceId,查询电签信息
-                List<TaskParallel> taskParallelList = iTaskParallelService.queryApprovalUser(task.getProcessInstanceId());
-                taskParallelList = taskParallelList.stream().filter(taskParallel -> taskParallel.getEVisaStatus() == 1).collect(Collectors.toList());
-                if(CollectionUtil.isNotEmpty(taskParallelList)){
-                    // 签名者
-                    StringBuffer nameString = new StringBuffer();
-                    // 签名时间
-                    StringBuffer dateString = new StringBuffer();
-                    // 用户id集合
-                    List<Long> userIdList = new ArrayList<>();
-                    for (TaskParallel taskParallel : taskParallelList) {
-                        nameString.append(taskParallel.getTaskUserName());
-                        nameString.append("、");
-                        dateString.append(taskParallel.getUpdateTime());
-                        dateString.append("、");
-                        userIdList.add(Long.valueOf(task.getTaskUser()));
-                    }
-                    // 查询用户
-                    List<User> userList = iUserClient.userInfoByIds(userIdList);
-                    // 岗位id集合
-                    List<String> postIds = userList.stream().map(User::getPostId).collect(Collectors.toList());
-                    R<List<String>> postNames = iSysClient.getPostNames(Func.join(postIds));
-                    if(postNames.getCode() == 200){
-                        /**签名项**/
-                        keyValue.put("签名项", Func.join(postNames.getData()));
-                    }
-                    /**签名者**/
-                    keyValue.put("签名者", StringUtils.isNotBlank(nameString.toString()) ? nameString.substring(0, nameString.length()-1) : null);
-                    /**签名时间**/
-                    keyValue.put("签名时间", StringUtils.isNotBlank(dateString.toString()) ? dateString.substring(0, nameString.length()-1) : null);
-                }
-            }
-
-            // 更新判断
+            ContractInfo contractById = byId.getContractId() != null && StringUtil.isNumeric(byId.getContractId()) ? contractClient.getContractById(Long.parseLong(byId.getContractId())) : null;
+            ArchivesAuto archivesAuto = byId.getArchiveId() == null ? null : archiveAutoClient.saveArchiveAutoById(byId.getArchiveId());
+            keyValue = buildFileMetadata(byId, isAdd, archivesAuto, contractById, archiveTreeContractById, list);
             if (isAdd) {
                 sqlBuild.append("insert into u_metadata_file ");
                 for (MetadataClassification key : metadataClassifications) {
@@ -809,11 +602,12 @@ public class MetadataClassificationServiceImpl
 
                 // 收集元数据值
                 // 收集元数据值 - 传入预处理的数据映射
-                this.collectFileMetadata(
-                        file, type, keyValue, isAdd,
-                        archiveAutoMap, contractInfoMap,
-                        nodeContractMap, ancestorListMap
-                );
+                keyValue = buildFileMetadata(file,isAdd,archiveAutoMap.get(file.getArchiveId()), contractInfoMap.get(file.getContractId()), nodeContractMap.get(file.getNodeId()), ancestorListMap.get(file.getNodeId()));
+//                this.collectFileMetadata(
+//                        file, type, keyValue, isAdd,
+//                        archiveAutoMap, contractInfoMap,
+//                        nodeContractMap, ancestorListMap
+//                );
 
                 if (isAdd) {
                     buildInsertSqlParams(file, keyValue, mapAll, metadataClassifications,
@@ -1177,5 +971,259 @@ public class MetadataClassificationServiceImpl
         }
     }
 
+    /**
+     * 构建文件元数据
+     * @param file  文件
+     * @param isAdd 是否新增
+     * @param archivesAuto 案卷信息
+     * @param contract 合同段信息
+     * @param currentNode 当前节点
+     * @param ancestorList 父级列表
+     */
+    private Map<String, Object>  buildFileMetadata(ArchiveFile file, boolean isAdd, ArchivesAuto archivesAuto,
+                                   ContractInfo contract,ArchiveTreeContract currentNode, List<ArchiveTreeContract> ancestorList) {
+        Map<String, Object> keyValue = new LinkedHashMap<>();
+        if (currentNode == null) return keyValue;
+        if (ancestorList == null || ancestorList.isEmpty()) return keyValue;
+
+        // 准备各种层级结构
+        StringBuffer paperAddress = new StringBuffer();
+        StringBuffer nameStr = new StringBuffer();
+        StringBuffer unitProjectString = new StringBuffer();
+        StringBuffer unitProjectIdString = new StringBuffer();
+        StringBuffer divisionProjectString = new StringBuffer();
+        StringBuffer divisionProjectIdString = new StringBuffer();
+        StringBuffer itemizedProjectString = new StringBuffer();
+        StringBuffer itemizedProjectIdString = new StringBuffer();
+
+        // 处理每个层级
+        for (int i = 0; i < ancestorList.size(); i++) {
+            ArchiveTreeContract node = ancestorList.get(i);
+            metadataSetting(node, unitProjectString, unitProjectIdString,
+                    divisionProjectString, divisionProjectIdString,
+                    itemizedProjectString, itemizedProjectIdString);
+
+            if (i == 0) continue;
+
+            // 构建纸质文件位置
+            if (node.getId().equals(currentNode.getParentId())) {
+                paperAddress.append(node.getNodeName());
+                paperAddress.append(">");
+                paperAddress.append(currentNode.getNodeName());
+            }
+
+            nameStr.append(node.getNodeName());
+            nameStr.append("/");
+        }
+
+        // 设置基础元数据
+        keyValue.put("聚合层次", nameStr.toString());
+        // 全宗名称 手写
+         keyValue.put("全宗名称", "");
+
+        // 立档单位名称
+        String dutyUser = "";
+        if ((file.getDutyUser() == null || file.getDutyUser().isEmpty()) &&
+                (file.getContractId() != null && !file.getContractId().isEmpty())) {
+            if (contract != null) {
+                if (contract.getContractType() == 1) {
+                    dutyUser = contract.getConstructionUnitName();
+                } else if (contract.getContractType() == 2) {
+                    dutyUser = contract.getSupervisionUnitName();
+                } else {
+                    dutyUser = contract.getContractorUnitName();
+                }
+            }
+        } else {
+            dutyUser = file.getDutyUser() != null ? file.getDutyUser() : "";
+        }
+        keyValue.put("立档单位名称", dutyUser);
+
+        // 设置档案信息(如果有)
+        if (file.getArchiveId() != null && archivesAuto != null) {
+            keyValue.put("档号", archivesAuto.getFileNumber());
+            // 移交时间:客户端,元数据入口,用户自己手动著录数据;后期移交接口打通,支持程序自动捕获
+             keyValue.put("移交时间", "");
+            keyValue.put("保管期限", archivesAuto.getStorageTime());
+            keyValue.put("文件件数", archivesAuto.getFileN());
+            keyValue.put("验证码", archivesAuto.getId());
+            keyValue.put("元数据目录文件", nameStr.toString());
+
+            keyValue.put("密级", archivesAuto.getSecretLevel());
+        }
+
+        keyValue.put("电子文件号", file.getId());
+        keyValue.put("文件页数", file.getFilePage());
+        keyValue.put("生成方式", file.getSourceType());
+
+        keyValue.put("题名", file.getFileName());
+        // 关键词生成
+        String keyWords = "";
+        if (file.getSourceType() == 1) {
+            // 原生文件:捕获当前文件所在的工序节点名称
+            keyWords = currentNode.getNodeName();
+        } else {
+            // 数字化文件:捕获当前文件的文件题名前8个字
+            if (file.getFileName() != null && file.getFileName().length() < 9) {
+                keyWords = file.getFileName();
+            } else if (file.getFileName() != null) {
+                keyWords = file.getFileName().substring(0, 8);
+            }
+        }
+        keyValue.put("关键词", keyWords);
+
+        // 摘要生成
+        String zhaiyao = "该文件为【" + (file.getSourceType() == 1 ? "原生" : "数字化") + "】于【" +
+                (file.getFileTime() != null ? file.getFileTime() : "") + "】形成,共【" +
+                (file.getFilePage() != null ? file.getFilePage() : 0) + "】页、【" +
+                (file.getFileName() != null ? file.getFileName() : "") + "】,责任者为【" +
+                dutyUser + "】";
+        keyValue.put("摘要", zhaiyao);
+
+        keyValue.put("文件日期", file.getFileTime());
+
+        // 设置文件基本信息
+        keyValue.put("元数据目录文件", nameStr.toString());
+
+
+
+        // 文件编号和拍摄信息
+        keyValue.put("文号", file.getFileNumber());
+        // 表单标识码 暂时忽略
+         keyValue.put("表单标识码", "");
+        keyValue.put("主题", file.getFileName());
+        keyValue.put("拍摄时间", file.getFilmingTime());
+        // 拍摄地点:捕获当前照片所在部位的分项工程节点名称
+        if (currentNode.getExtNodeType() == 4) {
+            keyValue.put("拍摄地点", currentNode.getNodeName());
+        } else {
+            for (ArchiveTreeContract archiveTreeContract : ancestorList) {
+                if (archiveTreeContract.getExtNodeType() == 4) {
+                    keyValue.put("拍摄地点", archiveTreeContract.getNodeName());
+                    break;
+                }
+            }
+        }
+        // 摄影者: 拍摄者
+         keyValue.put("摄影者", "");
+        // 背景: 捕获【文字说明】
+         keyValue.put("背景", "");
+        keyValue.put("分组号", file.getFilmCode());
+        keyValue.put("组内照片编号", file.getReferCode());
+        // 水平分辨率
+         keyValue.put("水平分辨率", file.getWidth());
+        // 垂直分辨率
+         keyValue.put("垂直分辨率", file.getHeight());
+
+        // 文件路径相关处理
+        if (file.getFileUrl() != null && !file.getFileUrl().isEmpty()) {
+            // 格式名称和存储位置
+            String fileUrl = file.getFileUrl();
+            if (fileUrl.contains(".")) {
+                keyValue.put("格式名称", fileUrl.substring(fileUrl.lastIndexOf(".") + 1));
+            } else {
+                keyValue.put("格式名称", "");
+            }
+
+            keyValue.put("存储位置", fileUrl);
+            keyValue.put("计算机文件名", fileUrl.substring(fileUrl.lastIndexOf("/") + 1));
+        }
+        // 文件大小和扫描信息
+        keyValue.put("计算机文件大小", file.getFileSize());
+
+        keyValue.put("扫描分辨率", "300dpi");
+        keyValue.put("扫描色彩模式", "彩色");
+
+        // 纸质文件位置
+        keyValue.put("纸质文件位置", paperAddress.toString());
+
+        // 签名信息(只有当需要时处理,避免不必要查询)
+        if (isAdd) {
+            Task task = iTaskService.getTaskByFormDataId(file.getId().toString());
+            if (task != null) {
+                List<TaskParallel> taskParallelList = iTaskParallelService.queryApprovalUser(task.getProcessInstanceId());
+                if (taskParallelList != null && !taskParallelList.isEmpty()) {
+                    taskParallelList = taskParallelList.stream()
+                            .filter(taskParallel -> taskParallel.getEVisaStatus() == 1)
+                            .collect(Collectors.toList());
+
+                    if (!taskParallelList.isEmpty()) {
+                        // 处理签名信息
+                        StringBuffer nameString = new StringBuffer();
+                        StringBuffer dateString = new StringBuffer();
+                        List<Long> userIdList = new ArrayList<>();
+
+                        for (TaskParallel taskParallel : taskParallelList) {
+                            nameString.append(taskParallel.getTaskUserName()).append("、");
+                            dateString.append(taskParallel.getUpdateTime()).append("、");
+                            userIdList.add(Long.valueOf(task.getTaskUser()));
+                        }
+
+                        // 查询用户信息
+                        if (!userIdList.isEmpty()) {
+                            List<User> userList = iUserClient.userInfoByIds(userIdList);
+                            if (userList != null && !userList.isEmpty()) {
+                                List<String> postIds = userList.stream()
+                                        .map(User::getPostId)
+                                        .filter(Objects::nonNull)
+                                        .collect(Collectors.toList());
+
+                                R<List<String>> postNames = iSysClient.getPostNames(Func.join(postIds));
+                                if (postNames != null && postNames.getCode() == 200) {
+                                    keyValue.put("签名项", Func.join(postNames.getData()));
+                                }
+                            }
+                        }
+
+                        keyValue.put("签名者", trimLastComma(nameString));
+                        keyValue.put("签名时间", trimLastComma(dateString));
+                    }
+                }
+            }
+        }
+        // 如果是竣工图
+        if ((currentNode.getIsBuiltDrawing() != null && currentNode.getIsBuiltDrawing() == 1) ||
+                (currentNode.getStorageType() != null && currentNode.getStorageType() == 2)) {
+            keyValue.put("图号", file.getDrawingNo());
+            keyValue.put("图幅", file.getSheetType());
+            keyValue.put("图表来源", file.getSheetSource());
+            keyValue.put("引用变更令编号", file.getCiteChangeNumber());
+        }
+
+        // 存储类型处理
+        if (currentNode.getStorageType() != null) {
+            keyValue.put("业务事项", StorageTypeEnum.getByCode(currentNode.getStorageType()));
+        }
+
+        // 单位/分部/分项工程信息
+        keyValue.put("单位工程", trimLastComma(unitProjectString));
+        keyValue.put("分部工程", trimLastComma(divisionProjectString));
+        keyValue.put("分项工程", trimLastComma(itemizedProjectString));
+
+        keyValue.put("单位工程编码", trimLastComma(unitProjectIdString));
+        keyValue.put("分部工程编码", trimLastComma(divisionProjectIdString));
+        keyValue.put("分项工程编码", trimLastComma(itemizedProjectIdString));
+
+        // 责任单位名称
+        keyValue.put("责任者名称", file.getDutyUser());
+
+        // 关系标识
+        keyValue.put("关系标识", "引用");
+
+        // 关系默认值
+        keyValue.put("关系", "引用");
+
+        if (file.getCreateUser() != null || file.getUpdateUser() != null) {
+            List<User> userList = iUserClient.userInfoByIds(Arrays.asList(file.getCreateUser(), file.getUpdateUser()));
+            if (userList != null && !userList.isEmpty()) {
+                Map<Long, User> userMap = userList.stream().distinct().collect(Collectors.toMap(User::getId, Function.identity()));
+                keyValue.put("创建用户", userMap.get(file.getCreateUser()) != null ? userMap.get(file.getCreateUser()).getName() : "");
+                keyValue.put("修改用户",  userMap.get(file.getUpdateUser()) != null ? userMap.get(file.getUpdateUser()).getName() : "");
+            }
+        }
+        keyValue.put("创建时间", DateUtil.formatDateTime(file.getCreateTime()));
+        keyValue.put("修改时间", DateUtil.formatDateTime(file.getUpdateTime()));
+        return keyValue;
+    }
 
 }