Переглянути джерело

Merge remote-tracking branch 'origin/dev' into dev

cr 2 днів тому
батько
коміт
94c6cce352

+ 3 - 0
blade-service-api/blade-archive-api/src/main/java/org/springblade/archive/entity/ArchivesAuto.java

@@ -189,6 +189,9 @@ public class ArchivesAuto extends BaseEntity {
 
     @ApiModelProperty("颜色状态")
     private Integer colourStatus;
+
+    @ApiModelProperty("案卷操作(0:无,1:正在并卷,2:正在重组)")
+    private Integer actionType;
     //是否是影音
     public boolean isMedia() {
         return (this.getCarrierType() != null &&

+ 53 - 0
blade-service-api/blade-archive-api/src/main/java/org/springblade/archive/vo/ArchivesAutoInsertVO.java

@@ -0,0 +1,53 @@
+/*
+ *      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.archive.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 视图实体类
+ *
+ * @author BladeX
+ * @since 2023-02-17
+ */
+@Data
+public class ArchivesAutoInsertVO implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	@ApiModelProperty("目标案卷id")
+	private Long targetId;
+
+//	@ApiModelProperty("type, 0:后,1:前")
+//	private Integer type;
+
+	@ApiModelProperty("被选择的案卷id")
+	private Long sourceId;
+
+	@ApiModelProperty("被插入的文件ids")
+	private String sourceArchiveFileIds;
+
+//	@ApiModelProperty("选择位置的文件id")
+//	private Long targetIndexFileId;
+
+	@ApiModelProperty("ids")
+	private String sortFileList;
+
+}

+ 129 - 46
blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ArchivesAutoController.java

@@ -18,6 +18,7 @@ package org.springblade.archive.controller;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import io.swagger.annotations.*;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import lombok.AllArgsConstructor;
@@ -43,9 +44,11 @@ import org.springblade.archive.utils.CallBgrsjk;
 import org.springblade.archive.vo.*;
 import org.springblade.business.entity.ArchiveFile;
 import org.springblade.business.feign.ArchiveFileClient;
+import org.springblade.business.vo.ArchiveFileVO;
 import org.springblade.business.vo.NeiYeLedgerVO1;
 //import org.springblade.common.utils.DeepSeekClient;
 import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.secure.BladeUser;
@@ -658,59 +661,36 @@ public class ArchivesAutoController extends BladeController {
 			if(archivesAutoList.size()<=1){
 				return R.fail("请选择多个案卷进行合并");
 			}
-			//根据档号后缀排序 拿到第一个
-			ArchivesAuto auto = archivesAutoList.get(0);
-			archivesAutoList.sort(Comparator.comparingInt(a -> {
-				String fileNumber = a.getFileNumber();
-				if (fileNumber == null || fileNumber.isEmpty()) {
-					return Integer.MAX_VALUE;
-				}
-				String[] parts;
-				if (fileNumber.indexOf("_") > 0) {
-					parts = fileNumber.split("_");
-				} else if (fileNumber.indexOf("-") > 0) {
-					parts = fileNumber.split("-");
-				} else {
-					return Integer.MAX_VALUE;
-				}
-				if (parts.length > 0) {
-					try {
-						return Integer.parseInt(parts[parts.length - 1]);
-					} catch (NumberFormatException e) {
-						return Integer.MAX_VALUE;
-					}
-				}
-				return Integer.MAX_VALUE;
-			}));
-			//将除第一个以外的案卷文件archiveId 设置成第一个的id
-			List<ArchiveFile>updateArchiveFileList=new ArrayList<>();
-			//查出所有案卷文件
-			List<ArchiveFile>archiveFileList=new ArrayList<>();
-			List<Long> longList = Func.toLongList(ids);
-			for (Long id : longList) {
-				archiveFileList.addAll(archiveFileClient.getArchiveFileByArchiveIds(id+""));
-			}
-			int i=1;
-			for (ArchiveFile file : archiveFileList) {
-				if (!file.getArchiveId().equals(auto.getId())) {
-					file.setArchiveId(auto.getId());
-				}
-				file.setArchiveSort(i++);
-				updateArchiveFileList.add(file);
-			}
-			archiveFileClient.updateArchiveFile(updateArchiveFileList);
-			auto.setName(name);
-			//删除其他案卷
-			archivesAutoList.remove(auto);
-			archivesAutoService.deleteLogic(archivesAutoList.stream().map(o->o.getId()).collect(Collectors.toList()));
+			checkAndUpdateArchiveAction(archivesAutoList,1);
 			//设置案卷页码和四要素
-			archivesAutoService.reCreateArchiveAuto(auto, archiveFileList);
+			archivesAutoService.reCreateArchiveAuto2(archivesAutoList, ids, name);
 			return R.status(true);
 		}else {
+			List<ArchivesAuto> archivesAutoList=archivesAutoService.listByIds(Func.toLongList(ids));
+			if(archivesAutoList.isEmpty()){
+				return R.fail("选择的案卷不存在");
+			}
+			checkAndUpdateArchiveAction(archivesAutoList, 2);
 			archivesAutoService.reCreateArchiveAuto1(ids);
 			return R.success("正在重组,请稍后查看");
 		}
 	}
+	private void checkAndUpdateArchiveAction(List<ArchivesAuto> archivesAutoList, int type){
+		if (archivesAutoList == null || archivesAutoList.isEmpty()) {
+			return;
+		}
+		List<ArchivesAuto> collect = archivesAutoList.stream().filter(item -> item.getActionType() != null && item.getActionType() != 0 && item.getActionType() != 3).collect(Collectors.toList());
+		if (!collect.isEmpty()) {
+			String names = collect.stream().map(ArchivesAuto::getName).collect(Collectors.joining(","));
+			throw  new ServiceException("【" + names + "】案卷正在重组或者并卷,请稍后在进行相关操作");
+		}
+		Set<Long> ids = archivesAutoList.stream().map(ArchivesAuto::getId).collect(Collectors.toSet());
+		boolean update = archivesAutoService.update(Wrappers.<ArchivesAuto>lambdaUpdate().set(ArchivesAuto::getActionType, type).in(ArchivesAuto::getId, ids)
+				.and(item -> item.in(ArchivesAuto::getActionType, 0,3).or().isNull(ArchivesAuto::getActionType)));
+		if (!update) {
+			throw new ServiceException("操作失败,案卷可能正在重组或者并卷,请稍后在进行相关操作");
+		}
+	}
 
 	@PostMapping("/creatFileNameFormAI")
 	@ApiOperationSupport(order = 10)
@@ -1221,4 +1201,107 @@ public class ArchivesAutoController extends BladeController {
         return R.status(archivesAutoService.sortRule(projectId,type));
     }
 
+
+	@PostMapping("/insertArchives")
+	@ApiOperationSupport(order = 43)
+	@ApiModelProperty(value = "插入案卷")
+	public R<Boolean> insertArchives(@RequestBody ArchivesAutoInsertVO vo){
+		// 校验
+		if (vo ==  null || vo.getTargetId() == null) {
+			return R.fail("参数错误");
+		}
+		if (vo.getTargetId().equals(vo.getSourceId())) {
+			return R.fail("自己不能选择自己");
+		}
+		String archiveFileIds = vo.getSourceArchiveFileIds();
+		if (StringUtils.isBlank(archiveFileIds)) {
+			return R.fail("请选择要插入的文件");
+		}
+		String[] split = archiveFileIds.split(",");
+		List<String> sourceFileIds = new ArrayList<>();
+		for (String s : split) {
+			if (StringUtils.isNumeric(s)) {
+				sourceFileIds.add(s);
+			}
+		}
+		if (sourceFileIds.isEmpty()) {
+			return R.fail("请选择要插入的文件");
+		}
+		ArchivesAuto target = archivesAutoService.getById(vo.getTargetId());
+		ArchivesAuto source = archivesAutoService.getById(vo.getSourceId());
+		if (target == null || source == null) {
+			return R.fail("插入或选择的案卷不存在");
+		}
+		if (target.getActionType() != null && (target.getActionType() == 1 || target.getActionType() == 2)) {
+			return R.fail("案卷【"+ target.getName() + "进行重组或者并卷,请稍后再试");
+		}
+		if (source.getActionType() != null && (source.getActionType() == 1 || source.getActionType() == 2)) {
+			return R.fail("案卷【"+ source.getName() + "进行重组或者并卷,请稍后再试");
+		}
+		List<ArchiveFile> sourceArchiveFileList = archiveFileClient.getAllArchiveFileByIds(sourceFileIds);
+		if (sourceArchiveFileList == null || sourceArchiveFileList.isEmpty()) {
+			return R.fail("请择要插入的文件不存在");
+		}
+		for (ArchiveFile archiveFile : sourceArchiveFileList) {
+			if (!vo.getSourceId().equals(archiveFile.getArchiveId())) {
+				return R.fail("文件【" + archiveFile.getFileName() + "】不属于【" + source.getName() + "】案卷,请重新选择");
+			}
+		}
+		if ((vo.getSortFileList() ==  null || !vo.getSortFileList().contains(","))) {
+			return R.fail("参数错误");
+		}
+		List<ArchiveFileVO> updateArchiveFileList = new ArrayList<>();
+		String[] split1 = vo.getSortFileList().split(",");
+		List<ArchiveFile> targetArchiveFileList = archiveFileClient.getArchiveFileByArchiveIds(target.getId() + "");
+		targetArchiveFileList.addAll(sourceArchiveFileList);
+		Map<Long, ArchiveFile> targetMap = targetArchiveFileList.stream().collect(Collectors.toMap(ArchiveFile::getId, item -> item, (k1, k2) -> k1));
+		Map<Long, ArchiveFile> map = sourceArchiveFileList.stream().collect(Collectors.toMap(ArchiveFile::getId, item -> item));
+		for (int i = 0; i < split1.length; i++) {
+			if (StringUtils.isNumeric(split1[i])) {
+				ArchiveFile tempFile = targetMap.get(Long.parseLong(split1[i]));
+				if (tempFile != null) {
+					ArchiveFileVO file = new ArchiveFileVO();
+					file.setId(tempFile.getId());
+					file.setSort(tempFile.getSort());
+					file.setArchiveSort(tempFile.getArchiveSort());
+					updateArchiveFileList.add(file);
+					if (map.containsKey(file.getId())) {
+						file.setPageNum("");
+						file.setArchiveId(target.getId());
+						for (int j = i + 1; j < split1.length; j++) {
+							if (StringUtils.isNumeric(split1[j])) {
+								ArchiveFile tempFile1 = targetMap.get(Long.parseLong(split1[j]));
+								if (tempFile1 != null && !map.containsKey(tempFile1.getId())) {
+									file.setNodeId(tempFile1.getNodeId());
+								}
+							}
+						}
+						if (file.getNodeId() == null) {
+							for (int j = i - 1; j >= 0; j--) {
+								if (StringUtils.isNumeric(split1[j])) {
+									ArchiveFile tempFile1 = targetMap.get(Long.parseLong(split1[j]));
+									if (tempFile1 != null && !map.containsKey(tempFile1.getId())) {
+										file.setNodeId(tempFile1.getNodeId());
+									}
+								}
+							}
+						}
+						if (file.getNodeId() == null) {
+							file.setNodeId(target.getNodeId() + "");
+						}
+					}
+				}
+			}
+		}
+		// 修改标识
+		boolean update = archivesAutoService.update(Wrappers.<ArchivesAuto>lambdaUpdate().in(ArchivesAuto::getId, vo.getTargetId(), vo.getSourceId()).set(ArchivesAuto::getActionType, 3).last("and (action_type is null or action_type in (0,3))"));
+		if (!update) {
+			return R.fail("案卷【" + target.getName() + "】或【" + source.getName() + "】正在被其他用户操作,请稍后再试");
+		}
+		ArchiveFileVO fileVO = new ArchiveFileVO();
+		fileVO.setList(updateArchiveFileList);
+		archiveFileClient.updateArchiveFileSort(fileVO);
+		return R.status(true);
+	}
+
 }

+ 2 - 2
blade-service/blade-archive/src/main/java/org/springblade/archive/mapper/ArchivesAutoMapper.xml

@@ -375,12 +375,12 @@
                 ORDER BY
                     m.tree_sort,
                     CASE WHEN u.file_number IS NULL THEN 1 ELSE 0 END,
-                    trailing_number
+                    trailing_number,u.create_time
             </when>
             <when test="vo.sortRuleType != null and vo.sortRuleType == 2 and vo.isArchive != null and vo.isArchive != ''">
                 order by
                     CASE WHEN u.file_number IS NULL THEN 1 ELSE 0 END,
-                    trailing_number
+                    trailing_number,u.create_time
             </when>
             <otherwise>
                 order by m.tree_sort,u.auto_file_sort is null ,u.auto_file_sort,u.file_number is null,

+ 2 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/service/IArchivesAutoService.java

@@ -187,4 +187,6 @@ public interface IArchivesAutoService extends BaseService<ArchivesAuto> {
 	void reomoveArchiveAndFile(List<Long> archiveIds);
 
     void reCreateArchiveAuto1(String ids);
+
+	void reCreateArchiveAuto2(List<ArchivesAuto> archivesAutoList, String ids, String name);
 }

+ 76 - 1
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java

@@ -3015,6 +3015,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 		List orgIds = Func.toLongList(ids);
 
 		List<String> strIds = new ArrayList<>();
+		List<Long> emptyIds = new ArrayList<>();
 		List<Long> lIds = new ArrayList<>();
 
 		//排除锁定的和单文件案卷这种
@@ -3024,11 +3025,27 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 				continue;
 			}
 			if (ar.getIsAutoFile() != null && ar.getIsAutoFile() == 1) {
+				emptyIds.add(ar.getId());
 				continue;
 			}
 			lIds.add(ar.getId());
 			strIds.add(ar.getId().toString());
 		}
+		if (!emptyIds.isEmpty()) {
+			List<ArchiveFile> files = archiveFileClient.getAllArchiveFileByArchiveIds(emptyIds.stream().map(id -> id + "").collect(Collectors.toList()));
+			if (files == null || files.isEmpty()) {
+				this.deleteLogic(emptyIds);
+			} else {
+				Map<Long, List<ArchiveFile>> groupArchiveFiles = files.stream().collect(Collectors.groupingBy(ArchiveFile::getArchiveId));
+				emptyIds.removeIf(groupArchiveFiles::containsKey);
+				if (!emptyIds.isEmpty()) {
+					this.deleteLogic(emptyIds);
+				}
+			}
+			if (strIds.isEmpty()) {
+				return true;
+			}
+		}
 
 		if (strIds.size() == 0) {
 			return false;
@@ -5160,14 +5177,72 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 	@Override
 	@Async
 	public void reCreateArchiveAuto1(String ids) {
+		Set<Long> idsSet = new HashSet<>();
 		for (Long id : Func.toLongList(ids)) {
+			idsSet.add(id);
 			//先查出勾选的案卷
 			ArchivesAuto archivesAuto=this.getById(id);
 			//查出所有案卷文件
 			List<ArchiveFile>archiveFileList=archiveFileClient.getArchiveFileByArchiveIds(id+"");
 			//设置案卷页码和四要素
-			this.reCreateArchiveAuto(archivesAuto, archiveFileList);
+			if (archiveFileList != null && !archiveFileList.isEmpty()) {
+				this.reCreateArchiveAuto(archivesAuto, archiveFileList);
+			}
 		}
+		if (!idsSet.isEmpty()) {
+			this.update(Wrappers.<ArchivesAuto>lambdaUpdate().set(ArchivesAuto::getActionType, 0).in(ArchivesAuto::getId, idsSet));
+		}
+	}
+	@Override
+	@Async
+	public void reCreateArchiveAuto2(List<ArchivesAuto> archivesAutoList, String ids, String name) {
+		//根据档号后缀排序 拿到第一个
+		ArchivesAuto archivesAuto = archivesAutoList.get(0);
+		archivesAutoList.sort(Comparator.comparingInt(a -> {
+			String fileNumber = a.getFileNumber();
+			if (fileNumber == null || fileNumber.isEmpty()) {
+				return Integer.MAX_VALUE;
+			}
+			String[] parts;
+			if (fileNumber.indexOf("_") > 0) {
+				parts = fileNumber.split("_");
+			} else if (fileNumber.indexOf("-") > 0) {
+				parts = fileNumber.split("-");
+			} else {
+				return Integer.MAX_VALUE;
+			}
+			if (parts.length > 0) {
+				try {
+					return Integer.parseInt(parts[parts.length - 1]);
+				} catch (NumberFormatException e) {
+					return Integer.MAX_VALUE;
+				}
+			}
+			return Integer.MAX_VALUE;
+		}));
+		//将除第一个以外的案卷文件archiveId 设置成第一个的id
+		List<ArchiveFile> waitArchiveFiles = new ArrayList<>();
+		//查出所有案卷文件
+		List<ArchiveFile>archiveFileList=new ArrayList<>();
+		List<Long> longList = Func.toLongList(ids);
+		for (Long id : longList) {
+			archiveFileList.addAll(archiveFileClient.getArchiveFileByArchiveIds(id+""));
+		}
+		int i=1;
+		for (ArchiveFile file : archiveFileList) {
+			if (!file.getArchiveId().equals(archivesAuto.getId())) {
+				file.setArchiveId(archivesAuto.getId());
+			}
+			file.setArchiveSort(i++);
+			waitArchiveFiles.add(file);
+		}
+		archiveFileClient.updateArchiveFile(waitArchiveFiles);
+		archivesAuto.setName(name);
+		//删除其他案卷
+		archivesAutoList.remove(archivesAuto);
+		this.deleteLogic(archivesAutoList.stream().map(o->o.getId()).collect(Collectors.toList()));
+		this.reCreateArchiveAuto(archivesAuto, archiveFileList);
+		this.update(Wrappers.<ArchivesAuto>lambdaUpdate().set(ArchivesAuto::getActionType, 0).in(ArchivesAuto::getId, ids));
 	}
 
 	/**