lvy 1 settimana fa
parent
commit
57a2770742

+ 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, targetIndexFileId 和 sortFileList 二选一")
+	private List<Long> sortFileList;
+
+}

+ 120 - 47
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;
@@ -46,6 +47,7 @@ import org.springblade.business.feign.ArchiveFileClient;
 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;
@@ -665,60 +667,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);
-			auto.setFileN(archiveFileList.size());
-			//删除其他案卷
-			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.eq(ArchivesAuto::getActionType, 0).or().isNull(ArchivesAuto::getActionType)));
+		if (!update) {
+			throw new ServiceException("操作失败,案卷可能正在重组或者并卷,请稍后在进行相关操作");
+		}
+	}
 
 	@PostMapping("/creatFileNameFormAI")
 	@ApiOperationSupport(order = 10)
@@ -1229,4 +1207,99 @@ 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("插入或选择的案卷不存在");
+		}
+		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.getTargetIndexFileId() ==  null || vo.getTargetIndexFileId() <= 0) && (vo.getSortFileList() == null || vo.getSortFileList().isEmpty())) {
+			return R.fail("请选择要插入的位置");
+		}
+		List<ArchiveFile> targetArchiveFileList = archiveFileClient.getArchiveFileByArchiveIds(vo.getTargetId() + "");
+		targetArchiveFileList.sort(Comparator.comparingInt(ArchiveFile::getArchiveSort));
+		List<ArchiveFile> updateArchiveFileList = new ArrayList<>();
+		int sort = 0;
+		if (vo.getTargetIndexFileId() != null && vo.getTargetIndexFileId() > 0) {
+			for (ArchiveFile archiveFile : targetArchiveFileList) {
+				if (archiveFile.getId().equals(vo.getTargetIndexFileId())) {
+					sort = archiveFile.getArchiveSort();
+					ArchiveFile file = new ArchiveFile();
+					file.setId(archiveFile.getId());
+					file.setArchiveId(archiveFile.getArchiveId());
+					sourceArchiveFileList.sort(Comparator.comparingInt(ArchiveFile::getArchiveSort));
+					if (vo.getType() == null || vo.getType() == 0) {
+						updateArchiveFileList.add(file);
+						for (ArchiveFile file1 : sourceArchiveFileList) {
+							ArchiveFile file2 = new ArchiveFile();
+							file2.setId(file1.getId());
+							file2.setArchiveId(archiveFile.getArchiveId());
+							file2.setPageNum("");
+							updateArchiveFileList.add(file2);
+						}
+					} else {
+						for (ArchiveFile file1 : sourceArchiveFileList) {
+							ArchiveFile file2 = new ArchiveFile();
+							file2.setId(file1.getId());
+							file2.setArchiveId(archiveFile.getArchiveId());
+							file2.setPageNum("");
+							updateArchiveFileList.add(file2);
+						}
+						updateArchiveFileList.add(file);
+					}
+				} else if (!updateArchiveFileList.isEmpty()) {
+					ArchiveFile file = new ArchiveFile();
+					file.setId(archiveFile.getId());
+					updateArchiveFileList.add(file);
+				}
+			}
+		} else {
+			return R.fail("暂不支持");
+		}
+		// 修改排序
+		// 修改标识
+		for (ArchiveFile archiveFile : updateArchiveFileList) {
+			archiveFile.setArchiveSort(sort);
+			archiveFile.setArchiveId(vo.getTargetId());
+			sort++;
+		}
+		archiveFileClient.updateArchiveFile(updateArchiveFileList);
+		archivesAutoService.update(Wrappers.<ArchivesAuto>lambdaUpdate().in(ArchivesAuto::getId,vo.getTargetId(), vo.getSourceId()).set(ArchivesAuto::getActionType, 3));
+		return R.status(true);
+	}
+
 }

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

@@ -189,4 +189,6 @@ public interface IArchivesAutoService extends BaseService<ArchivesAuto> {
     void reCreateArchiveAuto1(String ids);
 
 	boolean atuoOCR(String ids) throws Exception;
+
+	void reCreateArchiveAuto2(List<ArchivesAuto> archivesAutoList, String ids, String name);
 }

+ 56 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java

@@ -5166,7 +5166,9 @@ 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);
 			//查出所有案卷文件
@@ -5174,6 +5176,60 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 			//设置案卷页码和四要素
 			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));
 	}
 
 	/**