Ver Fonte

文件上传元数据

“zhifk” há 1 ano atrás
pai
commit
f10c8f907c

+ 4 - 0
blade-service-api/blade-archive-api/src/main/java/org/springblade/archive/feign/ArchiveAutoClient.java

@@ -9,6 +9,7 @@ import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import java.util.List;
 
@@ -21,4 +22,7 @@ public interface ArchiveAutoClient {
     @PostMapping(API_PREFIX + "/saveListByNodes")
     @Transactional(rollbackFor = Exception.class)
     R saveArchiveAutoByNodes(@RequestBody List<ArchivesAuto> list);
+
+    @PostMapping(API_PREFIX + "/saveArchiveAutoById")
+    ArchivesAuto saveArchiveAutoById(@RequestParam Long id);
 }

+ 19 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/feign/MetadataClassificationClient.java

@@ -0,0 +1,19 @@
+package org.springblade.business.feign;
+
+import org.springblade.common.constant.BusinessConstant;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.Map;
+
+@FeignClient(value =
+        BusinessConstant.APPLICATION_WEATHER_NAME
+)
+public interface MetadataClassificationClient {
+
+    String API_PREFIX = "/metadataClassificationClient";
+
+    @PostMapping(API_PREFIX + "/createMetadataFile")
+    boolean createMetadataFile(@RequestParam Long fileId,@RequestParam Integer type);
+}

+ 5 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/feign/ArchiveAutoClientImpl.java

@@ -23,4 +23,9 @@ public class ArchiveAutoClientImpl implements ArchiveAutoClient {
 
         return  R.status(archivesAutoService.saveBatch(list));
     }
+
+    @Override
+    public ArchivesAuto saveArchiveAutoById(Long id) {
+        return archivesAutoService.getById(id);
+    }
 }

+ 6 - 0
blade-service/blade-business/pom.xml

@@ -160,6 +160,12 @@
             <artifactId>metadata-extractor</artifactId>
             <version>2.16.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.springblade</groupId>
+            <artifactId>blade-archive-api</artifactId>
+            <version>2.9.1.RELEASE</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 19 - 0
blade-service/blade-business/src/main/java/org/springblade/business/feignClient/MetadataClassificationClientImpl.java

@@ -0,0 +1,19 @@
+package org.springblade.business.feignClient;
+
+import lombok.AllArgsConstructor;
+import org.springblade.business.feign.MetadataClassificationClient;
+import org.springblade.business.service.IMetadataClassificationService;
+import org.springframework.web.bind.annotation.RestController;
+
+
+@RestController
+@AllArgsConstructor
+public class MetadataClassificationClientImpl implements MetadataClassificationClient {
+    private final IMetadataClassificationService iMetadataClassificationService;
+
+
+    @Override
+    public boolean createMetadataFile(Long fileId, Integer type) {
+        return iMetadataClassificationService.createMetadataFile(fileId,type);
+    }
+}

+ 2 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/IMetadataClassificationService.java

@@ -16,4 +16,6 @@ public interface IMetadataClassificationService extends BaseService<MetadataClas
     boolean updateMetadataBytype(List<Long> ids,String type);
 
     boolean deleteTableField(Long ids);
+
+    boolean createMetadataFile(Long fileId,Integer type);
 }

+ 139 - 34
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/MetadataClassificationServiceImpl.java

@@ -4,6 +4,8 @@ package org.springblade.business.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.AllArgsConstructor;
 
+import org.springblade.archive.entity.ArchivesAuto;
+import org.springblade.archive.feign.ArchiveAutoClient;
 import org.springblade.business.entity.ArchiveFile;
 import org.springblade.business.entity.MetadataClassification;
 import org.springblade.business.mapper.MetadataClassificationMapper;
@@ -17,7 +19,10 @@ import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.constant.BladeConstant;
 import org.springblade.core.tool.utils.ObjectUtil;
 import org.springblade.manager.entity.ArchiveTreeContract;
+import org.springblade.manager.entity.ContractInfo;
 import org.springblade.manager.feign.ArchiveTreeContractClient;
+import org.springblade.manager.feign.ContractClient;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -29,6 +34,9 @@ public class MetadataClassificationServiceImpl
         implements IMetadataClassificationService {
     private final IArchiveFileService iArchiveFileService;
     private final ArchiveTreeContractClient archiveTreeContractClient;
+    private final ContractClient contractClient;
+    private final ArchiveAutoClient archiveAutoClient;
+    private final JdbcTemplate jdbcTemplate;
 
     @Override
     public MetadataClassification classificationDetail(Integer type) {
@@ -119,56 +127,153 @@ public class MetadataClassificationServiceImpl
 
     /**
      * fileId 文件id
-     * cs 施工监理
      * type 管理端的元数据分类
-     * is true 归档前,false 归档后
-     * istask 0 为审批,1已审批
      * **/
 
-    public void createMetadataFile(String ipAddress,Long fileId,Integer cs,Integer type,boolean is,Integer istask){
-        BladeUser user = AuthUtil.getUser();
-        if(fileId != null){
-            /**判断是否已经获取过**/
-            List<HashMap<String,Object>> metadataMapList = baseMapper.getMetadaFileByFileId(fileId);
-            Map<String,Object> metadataMap = null;
-            if(metadataMapList != null && metadataMapList.size()>0){
-                metadataMap = metadataMapList.get(0);
-            }else{
-                metadataMap = new HashMap<>();
-            }
-            /**获取对应分类的字段**/
-            QueryWrapper<MetadataClassification> metadata = new QueryWrapper<>();
-            metadata.lambda().like(MetadataClassification :: getFileStorageType,type).eq(MetadataClassification::getIsDeleted,0);
-            List<MetadataClassification> metadataClassifications = baseMapper.selectList(metadata);
-            Map<String,MetadataClassification> map = new LinkedHashMap<>();
-            for(MetadataClassification m : metadataClassifications){
-                map.put(m.getContainerName(),m);
-            }
-            Long id = null;
-            switch (type){
-                case 0:
-                    break;
-            }
-
-            /**聚合层次**/
-            map.get("聚合层次");
-
-            /**全宗名称**/
+    public boolean createMetadataFile(Long fileId,Integer type){
+        try {
+            BladeUser user = AuthUtil.getUser();
+            if(fileId != null){
+                /**判断是否已经获取过**/
+                List<HashMap<String,Object>> metadataMapList = baseMapper.getMetadaFileByFileId(fileId);
+                Map<String,Object> metadataMap = null;
+                boolean isAdd = true;
+                if(metadataMapList != null && metadataMapList.size()>0){
+                    metadataMap = metadataMapList.get(0);
+                    isAdd = false;
+                }else{
+                    metadataMap = new HashMap<>();
+                }
+                /**获取全部的字段**/
+                QueryWrapper<MetadataClassification> metadata = new QueryWrapper<>();
+                metadata.lambda().eq(MetadataClassification::getIsDeleted,0);
+                List<MetadataClassification> metadataClassifications = baseMapper.selectList(metadata);
+                //全部字段
+                Map<String,MetadataClassification> mapAll = new LinkedHashMap<>();
+                for(MetadataClassification m : metadataClassifications){
+                    mapAll.put(m.getContainerName(),m);
+                }
+                Long id = null;
+                switch (type){
+                    case 0:
+                        this.archiveFileMetadata(fileId,metadataClassifications,user,isAdd,metadataMap);
+                        break;
+                }
 
+            }
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
         }
     }
     /**文件收集上传**/
-    private void archiveFileMetadata(Long fileId){
+    private void archiveFileMetadata(Long fileId,List<MetadataClassification> metadataClassifications,BladeUser user,boolean isAdd,Map<String,Object> metadataMap){
         ArchiveFile byId = iArchiveFileService.getById(fileId);
+        StringBuilder sqlBuild = new StringBuilder();
+        StringBuilder fieldBuild = new StringBuilder();
+        StringBuilder valueBuild = new StringBuilder();
         if(byId != null && !byId.getNodeId().isEmpty()) {
+            Map<String,Object> keyValue = new LinkedHashMap<>();
+
+            /**聚合层次**/
             ArchiveTreeContract archiveTreeContractById = archiveTreeContractClient.getArchiveTreeContractById(Long.parseLong(byId.getNodeId()));
-            archiveTreeContractById.getAncestors();
             List<ArchiveTreeContract> list = archiveTreeContractClient.getArchiveTreeContractListByIds(archiveTreeContractById.getAncestors());
             StringBuffer nameStr = new StringBuffer();
             for(ArchiveTreeContract treeContract : list){
                 nameStr.append(treeContract.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("文件页数",byId.getFilePage());
+            /**生成方式 1原生,2数字化 2**/
+            keyValue.put("生成方式", byId.getSourceType());
+            /**题名**/
+            keyValue.put("题名", byId.getFileName());
+            /**关键词**/
+            String keyWords = "";
+            if(byId.getFileName().length()<8){
+                keyWords = byId.getFileName();
+            }else{
+                keyWords = byId.getFileName().substring(0,7);
+            }
+            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("文号", byId.getFileNumber());
+            /**格式名称**/
+            keyValue.put("格式名称", byId.getFileUrl().substring(byId.getFileUrl().lastIndexOf(".")));
+            /**存储位置**/
+            keyValue.put("存储位置", byId.getFileUrl());
+            /**计算机文件名**/
+            String substring = byId.getFileUrl().substring(byId.getFileUrl().lastIndexOf("/"), byId.getFileUrl().lastIndexOf("."));
+            keyValue.put("计算机文件名", substring);
+            /**计算机文件大小**/
+            keyValue.put("计算机文件大小", byId.getFileSize());
+            /**扫描分辨率 300dpi**/
+            keyValue.put("扫描分辨率", "300dpi");
+            /**扫描色彩模式 彩色**/
+            keyValue.put("扫描色彩模式", "彩色");
+            /**责任者名称**/
+            keyValue.put("责任者名称", byId.getDutyUser());
+            if(isAdd) {
+                sqlBuild.append("insert into u_metadata_file ");
+                for (MetadataClassification key : metadataClassifications) {
+                    fieldBuild.append(" , ");
+                    fieldBuild.append(key.getFieldKey());
+                    if (keyValue.get(key.getContainerName()) != null) {
+                        valueBuild.append(" , ");
+                        valueBuild.append("'");
+                        valueBuild.append(keyValue.get(key.getContainerName()));
+                        valueBuild.append("'");
+                    } else {
+                        valueBuild.append(" , ");
+                        valueBuild.append(" NULL ");
+                    }
+                }
+                sqlBuild.append("(id,tenant_id, create_user, create_time, update_user, update_time, status, is_deleted,contract_id, file_id " + fieldBuild.toString() + " ) ");
+                sqlBuild.append("values('" + SnowFlakeUtil.getId() + "','" + user.getTenantId() + "','" + user.getUserId() + "', '" + new Date() + "', '" + user.getUserId() + "', '" + new Date() + "', '0', '0','" + byId.getContractId() + "', '" + fileId + "'," + valueBuild.toString() + ")");
+            }else{
+                sqlBuild.append("update u_metadata_file set ");
+                for(MetadataClassification key : metadataClassifications){
+                    if(keyValue.get(key.getContainerName()) != null){
+                        fieldBuild.append(" "+key.getFieldKey() + " = '"+keyValue.get(key.getContainerName())+"' , ");
+                    }
+                }
+                sqlBuild.append(" update_user = '"+user.getUserId()+"' , ");
+                sqlBuild.append(" update_time = '"+new Date()+"' , ");
+                sqlBuild.append(" where id = "+metadataMap.get("id"));
+            }
+            jdbcTemplate.execute(sqlBuild.toString());
         }
     }
 }