Procházet zdrojové kódy

元数据查看与编辑

“zhifk” před 2 roky
rodič
revize
cb2beb784b

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

@@ -1,10 +1,13 @@
 package org.springblade.business.feign;
 
+import org.springblade.business.vo.MetadataClassificationVO;
 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.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.util.List;
 import java.util.Map;
 
 @FeignClient(value =
@@ -16,4 +19,10 @@ public interface MetadataClassificationClient {
 
     @PostMapping(API_PREFIX + "/createMetadataFile")
     boolean createMetadataFile(@RequestParam Long fileId,@RequestParam Integer type);
+
+    @PostMapping(API_PREFIX + "/getMetadataFile")
+    List<MetadataClassificationVO> getMetadataFile(@RequestParam Long fileId);
+
+    @PostMapping(API_PREFIX + "/updateMetadata")
+    boolean updateMetadata(@RequestBody List<MetadataClassificationVO> vos);
 }

+ 44 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/vo/MetadataClassificationVO.java

@@ -0,0 +1,44 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.vo;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.business.entity.MetadataClassification;
+
+
+/**
+ * 视图实体类
+ *
+ * @author zhifk
+ * @since 2023-05-22
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class MetadataClassificationVO extends MetadataClassification {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 字段值
+	 */
+	private String keyValue;
+
+	/**
+	 * 文件id
+	 */
+	private Long fileId;
+}

+ 6 - 2
blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ArchiveFileAutoController.java

@@ -168,9 +168,13 @@ public class ArchiveFileAutoController extends BladeController {
             }
         }
         /**先删除对应工程文件在删除案卷**/
-        boolean b = this.archiveFileClient.removeFile(Func.toLongList(fileIds.toString()));
-        if(b){
+        if(fileIds.toString().isEmpty()) {
             return R.status(archivesAutoService.deleteLogic(Func.toLongList(ids)));
+        }else{
+            boolean b = this.archiveFileClient.removeFile(Func.toLongList(fileIds.toString()));
+            if (b) {
+                return R.status(archivesAutoService.deleteLogic(Func.toLongList(ids)));
+            }
         }
         return R.status(false);
     }

+ 44 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ArchiveFileController.java

@@ -14,7 +14,10 @@ import org.apache.commons.lang.StringUtils;
 import org.springblade.archive.utils.FileUtils;
 import org.springblade.business.entity.ArchiveFile;
 import org.springblade.business.feign.ArchiveFileClient;
+import org.springblade.business.feign.MetadataClassificationClient;
 import org.springblade.business.vo.ArchiveFileVO;
+import org.springblade.business.vo.MetadataClassificationVO;
+import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.boot.ctrl.BladeController;
 
 import org.springblade.core.oss.model.BladeFile;
@@ -57,6 +60,7 @@ public class ArchiveFileController extends BladeController {
     private final EVisaClient eVisaClient;
     private final WbsTreeContractClient wbsTreeContractClient;
     private final ContractClient contractClient;
+    private final MetadataClassificationClient metadataClassificationClient;
     /**
      * 上传文件
      *
@@ -89,6 +93,7 @@ public class ArchiveFileController extends BladeController {
             if(saveList != null && saveList.size() > 0){
                 int i = 1;
                 for(ArchiveFileVO saveVo : saveList){
+                    saveVo.setId(SnowFlakeUtil.getId());
                     saveVo.setSort(l+i);
                     saveVo.setStatus(new Integer("0").equals(saveVo.getIsApproval()) ? 2 : 0);
                     saveVo.setIsCertification(new Integer("0").equals(saveVo.getIsNeedCertification()) ? 1 : 0);
@@ -102,6 +107,13 @@ public class ArchiveFileController extends BladeController {
                 }
             }
             this.archiveFileClient.saveArchiveFile(vo);
+            try {
+                for(ArchiveFileVO saveVo : saveList){
+                    metadataClassificationClient.createMetadataFile(saveVo.getId(),0);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         } catch (NumberFormatException e) {
             e.printStackTrace();
             return R.data(false);
@@ -136,6 +148,13 @@ public class ArchiveFileController extends BladeController {
     public R<Boolean> batchUpdateSort(@RequestBody ArchiveFileVO vo){
         try {
             this.archiveFileClient.updateArchiveFileSort(vo);
+            try {
+                for(ArchiveFileVO saveVo : vo.getList()){
+                    metadataClassificationClient.createMetadataFile(saveVo.getId(),0);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         } catch (Exception e) {
             e.printStackTrace();
             return R.data(false);
@@ -334,4 +353,29 @@ public class ArchiveFileController extends BladeController {
         ContractInfo contractById = contractClient.getContractById(contractId);
         return R.data(contractById);
     }
+
+    /**
+     * 获取当前文件元数据
+     */
+    @GetMapping("/getMetadataFile")
+    @ApiOperationSupport(order = 16)
+    @ApiOperation(value = "文件收集-上传文件责任者")
+    public R getMetadataFile(Long fileId) {
+        return R.data(metadataClassificationClient.getMetadataFile(fileId));
+    }
+    /**
+     * 编辑元数据
+     */
+    @PostMapping("/updateMetadata")
+    @ApiOperationSupport(order = 17)
+    @ApiOperation(value = "编辑")
+    public R<Boolean> updateMetadata(@RequestBody List<MetadataClassificationVO> vos){
+        try {
+            this.metadataClassificationClient.updateMetadata(vos);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return R.data(false);
+        }
+        return R.data(true);
+    }
 }

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

@@ -3,8 +3,12 @@ package org.springblade.business.feignClient;
 import lombok.AllArgsConstructor;
 import org.springblade.business.feign.MetadataClassificationClient;
 import org.springblade.business.service.IMetadataClassificationService;
+import org.springblade.business.vo.MetadataClassificationVO;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+import java.util.Map;
+
 
 @RestController
 @AllArgsConstructor
@@ -16,4 +20,14 @@ public class MetadataClassificationClientImpl implements MetadataClassificationC
     public boolean createMetadataFile(Long fileId, Integer type) {
         return iMetadataClassificationService.createMetadataFile(fileId,type);
     }
+
+    @Override
+    public List<MetadataClassificationVO> getMetadataFile(Long fileId) {
+        return iMetadataClassificationService.getMetadataFile(fileId);
+    }
+
+    @Override
+    public boolean updateMetadata(List<MetadataClassificationVO> vos) {
+        return iMetadataClassificationService.updateMetadata(vos);
+    }
 }

+ 1 - 1
blade-service/blade-business/src/main/java/org/springblade/business/mapper/ArchiveFileMapper.xml

@@ -271,7 +271,7 @@
 
     <select id="selectBoxNameAndBoxNumber" resultType="java.util.Map">
         select box_name as boxName,box_number as boxNumber,group_concat(DISTINCT id ORDER BY id ASC SEPARATOR ',') as ids
-         from u_archive_file where node_id = #{nodeId} and (box_number is not null or box_number != '')
+         from u_archive_file where node_id = #{nodeId} and (box_number is not null and box_number != '' and box_number != -1)
          group by box_name order by box_number asc
     </select>
 

+ 1 - 1
blade-service/blade-business/src/main/java/org/springblade/business/mapper/MetadataClassificationMapper.xml

@@ -83,7 +83,7 @@
         where  locate(#{type},file_storage_type) > 0
     </update>
     <select id="getMetadaFileByFileId" resultType="java.util.HashMap" >
-        select * from u_metadata_file where and file_id != #{fileId}
+        select * from u_metadata_file where file_id = #{fileId}
         order by create_time desc limit 1
     </select>
 </mapper>

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

@@ -2,9 +2,11 @@ package org.springblade.business.service;
 
 
 import org.springblade.business.entity.MetadataClassification;
+import org.springblade.business.vo.MetadataClassificationVO;
 import org.springblade.core.mp.base.BaseService;
 
 import java.util.List;
+import java.util.Map;
 
 public interface IMetadataClassificationService extends BaseService<MetadataClassification> {
 
@@ -18,4 +20,8 @@ public interface IMetadataClassificationService extends BaseService<MetadataClas
     boolean deleteTableField(Long ids);
 
     boolean createMetadataFile(Long fileId,Integer type);
+
+    List<MetadataClassificationVO> getMetadataFile(Long fileId);
+
+    boolean updateMetadata(List<MetadataClassificationVO> vos);
 }

+ 53 - 5
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/MetadataClassificationServiceImpl.java

@@ -12,16 +12,21 @@ import org.springblade.business.mapper.MetadataClassificationMapper;
 import org.springblade.business.service.IArchiveFileService;
 import org.springblade.business.service.IMetadataClassificationService;
 
+import org.springblade.business.vo.MetadataClassificationVO;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.constant.BladeConstant;
+import org.springblade.core.tool.utils.BeanUtil;
+import org.springblade.core.tool.utils.DateUtil;
 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.springblade.manager.vo.WbsTreeVO;
+import org.springframework.dao.DataAccessException;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
@@ -167,6 +172,49 @@ public class MetadataClassificationServiceImpl
             return false;
         }
     }
+
+    @Override
+    public List<MetadataClassificationVO> getMetadataFile(Long fileId) {
+        List<HashMap<String,Object>> metadataMapList = baseMapper.getMetadaFileByFileId(fileId);
+        if(metadataMapList != null && metadataMapList.size()>0) {
+            Map<String,Object> map = metadataMapList.get(0);
+            QueryWrapper<MetadataClassification> metadata = new QueryWrapper<>();
+            metadata.lambda().eq(MetadataClassification::getIsDeleted, 0);
+            List<MetadataClassification> metadataClassifications = baseMapper.selectList(metadata);
+            if(metadataClassifications != null && metadataClassifications.size()>0) {
+                List<MetadataClassificationVO> metadataClassificationVOS = Objects.requireNonNull(BeanUtil.copy(metadataClassifications, MetadataClassificationVO.class));
+                for (MetadataClassificationVO vo : metadataClassificationVOS) {
+                    vo.setKeyValue(map.get(vo.getFieldKey()) == null?null:map.get(vo.getFieldKey()).toString());
+                    vo.setFileId(fileId);
+                }
+                return metadataClassificationVOS;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean updateMetadata(List<MetadataClassificationVO> vos) {
+        try {
+            BladeUser user = AuthUtil.getUser();
+            StringBuilder sqlBuild = new StringBuilder();
+            sqlBuild.append("update u_metadata_file set ");
+            for(MetadataClassificationVO key : vos){
+                if(key.getFileId() != null){
+                    sqlBuild.append(" "+key.getFieldKey() + " = '"+key.getKeyValue()+"' , ");
+                }
+            }
+            sqlBuild.append(" update_user = '"+user.getUserId()+"' , ");
+            sqlBuild.append(" update_time = '"+DateUtil.formatDateTime(new Date())+"' ");
+            sqlBuild.append(" where file_id = "+vos.get(0).getFileId());
+            jdbcTemplate.execute(sqlBuild.toString());
+        } catch (DataAccessException e) {
+            e.printStackTrace();
+            return false;
+        }
+        return true;
+    }
+
     /**文件收集上传**/
     private void archiveFileMetadata(Long fileId,List<MetadataClassification> metadataClassifications,BladeUser user,boolean isAdd,Map<String,Object> metadataMap){
         ArchiveFile byId = iArchiveFileService.getById(fileId);
@@ -231,11 +279,11 @@ public class MetadataClassificationServiceImpl
             /**文号**/
             keyValue.put("文号", byId.getFileNumber());
             /**格式名称**/
-            keyValue.put("格式名称", byId.getFileUrl().substring(byId.getFileUrl().lastIndexOf(".")));
+            keyValue.put("格式名称", byId.getFileUrl().substring(byId.getFileUrl().lastIndexOf(".")+1));
             /**存储位置**/
             keyValue.put("存储位置", byId.getFileUrl());
             /**计算机文件名**/
-            String substring = byId.getFileUrl().substring(byId.getFileUrl().lastIndexOf("/"), byId.getFileUrl().lastIndexOf("."));
+            String substring = byId.getFileUrl().substring(byId.getFileUrl().lastIndexOf("/")+1, byId.getFileUrl().lastIndexOf("."));
             keyValue.put("计算机文件名", substring);
             /**计算机文件大小**/
             keyValue.put("计算机文件大小", byId.getFileSize());
@@ -261,16 +309,16 @@ public class MetadataClassificationServiceImpl
                     }
                 }
                 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() + ")");
+                sqlBuild.append("values('" + SnowFlakeUtil.getId() + "','" + user.getTenantId() + "','" + user.getUserId() + "', '" + DateUtil.formatDateTime(new Date()) + "', '" + user.getUserId() + "', '" + DateUtil.formatDateTime(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(" "+key.getFieldKey() + " = '"+keyValue.get(key.getContainerName())+"' , ");
                     }
                 }
                 sqlBuild.append(" update_user = '"+user.getUserId()+"' , ");
-                sqlBuild.append(" update_time = '"+new Date()+"' , ");
+                sqlBuild.append(" update_time = '"+DateUtil.formatDateTime(new Date())+"' ");
                 sqlBuild.append(" where id = "+metadataMap.get("id"));
             }
             jdbcTemplate.execute(sqlBuild.toString());