|
@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.itextpdf.text.*;
|
|
@@ -35,6 +36,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
import org.springblade.archive.dto.ArchiveWarningDTO;
|
|
|
+import org.springblade.archive.dto.FindAndReplaceDto;
|
|
|
import org.springblade.archive.dto.JiLinQueryDto;
|
|
|
import org.springblade.archive.dto.SaveApplyDTO;
|
|
|
import org.springblade.archive.entity.*;
|
|
@@ -73,6 +75,7 @@ import org.springblade.system.entity.DictBiz;
|
|
|
import org.springblade.system.feign.IDictBizClient;
|
|
|
import org.springblade.system.user.entity.User;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -4102,8 +4105,152 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void deleteFile(String defaultDir,Long id){
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void fileNumberFlush(Long projectId, Long contractId, List<String> nodeIds,Integer isArchive) {
|
|
|
+ ArchiveProjectConfig config = archiveProjectConfigService.getByProjectIdOrNew(projectId);
|
|
|
+ List<ArchivesAutoVO4>list=baseMapper.selectAllArchiveAuto(projectId,contractId,nodeIds,isArchive);
|
|
|
+ if(list!=null && list.size()>0){
|
|
|
+ if(config.getDirType()==null||config.getDirType()==0){
|
|
|
+ List<ArchivesAuto> archivesAutos = setFileNumberByConfig(config, list);
|
|
|
+ this.updateBatchById(archivesAutos);
|
|
|
+ }else {
|
|
|
+ Map<Long, List<ArchivesAutoVO4>> map = list.stream().collect(Collectors.groupingBy(ArchivesAutoVO4::getParentId));
|
|
|
+ for (Map.Entry<Long, List<ArchivesAutoVO4>> entry : map.entrySet()) {
|
|
|
+ List<ArchivesAutoVO4> value = entry.getValue();
|
|
|
+ List<ArchivesAuto> archivesAutos = setFileNumberByConfig(config, value);
|
|
|
+ this.updateBatchById(archivesAutos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean reBuildArchiveFrontPdfs(String archiveIds, Long projectId) {
|
|
|
+ if(StringUtils.isEmpty(archiveIds)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ archiveAutoPdfService.assignArchiveTableUrl();
|
|
|
+ String[] ids = archiveIds.split(",");
|
|
|
+ for (String archiveId : ids) {
|
|
|
+ ArchivesAuto auto = baseMapper.selectById(archiveId);
|
|
|
+ List<ArchiveFile> archiveFiles = archiveFileClient.getArchiveFileByArchiveID(Long.valueOf(archiveId));
|
|
|
+ archiveAutoPdfService.buildArchiveFrontPdfs(projectId,auto,archiveFiles,true);
|
|
|
+ baseMapper.updateById(auto);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean findAndReplace(List<ArchivesAuto> archivesAutos, FindAndReplaceDto dto) {
|
|
|
+ List<ArchivesAuto>updates = new ArrayList<>();
|
|
|
+ for (ArchivesAuto archivesAuto : archivesAutos) {
|
|
|
+ ArchivesAuto auto = new ArchivesAuto();
|
|
|
+ if(dto.getType()==1){
|
|
|
+ if(StringUtils.isNotEmpty(dto.getQuery())&&StringUtils.isNotEmpty(dto.getReplace())){
|
|
|
+ String name = archivesAuto.getName();
|
|
|
+ if (StringUtils.isNotEmpty(name)&&name.contains(dto.getQuery())) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ int lastIndex = 0;
|
|
|
+ // 查找所有匹配的位置
|
|
|
+ int index = name.indexOf(dto.getQuery());
|
|
|
+ while (index != -1) {
|
|
|
+ // 添加未处理部分(从上一个 lastIndex 到当前 index)
|
|
|
+ sb.append(name, lastIndex, index);
|
|
|
+
|
|
|
+ // 根据位置插入替换内容
|
|
|
+ if (dto.getPosition() != null) {
|
|
|
+ switch (dto.getPosition()) {
|
|
|
+ case 1: // 在查询内容前插入
|
|
|
+ sb.append(dto.getReplace());
|
|
|
+ sb.append(dto.getQuery());
|
|
|
+ break;
|
|
|
+ case 2: // 在查询内容后插入
|
|
|
+ sb.append(dto.getQuery());
|
|
|
+ sb.append(dto.getReplace());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new ServiceException("请选择正确的定位条件");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sb.append(dto.getQuery()); // 没有指定位置时保留原内容
|
|
|
+ }
|
|
|
+ // 更新 lastIndex 到当前匹配结束位置
|
|
|
+ lastIndex = index + dto.getQuery().length();
|
|
|
+ // 继续查找下一个匹配项
|
|
|
+ index = name.indexOf(dto.getQuery(), lastIndex);
|
|
|
+ }
|
|
|
+ // 添加剩余的部分
|
|
|
+ sb.append(name.substring(lastIndex));
|
|
|
+ // 更新名称
|
|
|
+ archivesAuto.setName(sb.toString());
|
|
|
+ auto.setId(archivesAuto.getId());
|
|
|
+ auto.setName(archivesAuto.getName());
|
|
|
+ updates.add(auto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (dto.getType()==2) {
|
|
|
+ if(StringUtils.isNotEmpty(dto.getQuery())&&StringUtils.isNotEmpty(dto.getReplace())){
|
|
|
+ String name = archivesAuto.getName();
|
|
|
+ if (StringUtils.isNotEmpty(name)&&name.contains(dto.getQuery())) {
|
|
|
+ String newName = name.replaceAll(dto.getQuery(), dto.getReplace());
|
|
|
+ archivesAuto.setName(newName);
|
|
|
+ auto.setId(archivesAuto.getId());
|
|
|
+ auto.setName(archivesAuto.getName());
|
|
|
+ updates.add(auto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(StringUtils.isNotEmpty(dto.getQuery())){
|
|
|
+ String name = archivesAuto.getName();
|
|
|
+ if (StringUtils.isNotEmpty(name)&&name.contains(dto.getQuery())) {
|
|
|
+ String newName = name.replaceAll(dto.getQuery(), "");
|
|
|
+ archivesAuto.setName(newName);
|
|
|
+ auto.setId(archivesAuto.getId());
|
|
|
+ auto.setName(archivesAuto.getName());
|
|
|
+ updates.add(auto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!updates.isEmpty()){
|
|
|
+ return this.updateBatchById(archivesAutos);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ArchivesAuto> setFileNumberByConfig(ArchiveProjectConfig config,List<ArchivesAutoVO4> value){
|
|
|
+ int i=1;
|
|
|
+ List<ArchivesAuto>list=new ArrayList<>();
|
|
|
+ for (ArchivesAutoVO4 v:value) {
|
|
|
+ ArchivesAuto auto = new ArchivesAuto();
|
|
|
+ if(config.getIndexType()==null||config.getIndexType()==0){
|
|
|
+ v.setFileNumber(v.getFileNumberPrefix()+"_"+i);
|
|
|
+ }else {
|
|
|
+ String prefix = v.getFileNumberPrefix();
|
|
|
+ int index = i; // 编号从 1 开始
|
|
|
+ // 获取配置中的编号长度(最多多少位)
|
|
|
+ int numLength = config.getIndexNum();
|
|
|
+ // 默认最多4位,防止过长或无效值
|
|
|
+ if (numLength > 10) { // 限制最大为10位
|
|
|
+ numLength = 4;
|
|
|
+ }
|
|
|
+ // 使用 %0xd 格式化数字,x 表示总长度
|
|
|
+ String formattedIndex = String.format("%0" + numLength + "d", index);
|
|
|
+ // 设置最终档号
|
|
|
+ v.setFileNumber(prefix + "_" + formattedIndex);
|
|
|
+ }
|
|
|
+ auto.setId(v.getId());
|
|
|
+ auto.setFileNumber(v.getFileNumber());
|
|
|
+ list.add(auto);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteFile(String defaultDir,Long id){
|
|
|
String dir = defaultDir+"/"+id;
|
|
|
String file = defaultDir+"/"+id+".zip";
|
|
|
// 多条命令执行
|