diff --git a/archives/src/main/java/com/storeroom/modules/common/ArchivesTypeEnum.java b/archives/src/main/java/com/storeroom/modules/common/ArchivesTypeEnum.java index 84a703f..f70414a 100644 --- a/archives/src/main/java/com/storeroom/modules/common/ArchivesTypeEnum.java +++ b/archives/src/main/java/com/storeroom/modules/common/ArchivesTypeEnum.java @@ -8,6 +8,7 @@ public enum ArchivesTypeEnum { folder(1, "文件夹"), project(2, "项目"), + archives(3, "案卷"), inChive(4, "卷内"), files(5, "文件"), diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java index c92c669..2b0c815 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java @@ -62,6 +62,9 @@ public class ArchivesTypeController { if (StringUtils.isEmpty(archivesTypeDTO.getCnName())) { throw new BaseException("名称不能为空"); } + if (archivesTypeDTO.getIsType() == 1 || archivesTypeDTO.getIsType() == 4) { + throw new BaseException("文件夹或卷内不能被选中"); + } return ApiResponse.success(archivesTypeService.create(archivesTypeDTO)); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java index 571555e..7547af8 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java @@ -44,20 +44,105 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { ArchivesType archivesType = archivesTypeMapper.toEntity(archivesTypeDTO); List archivesType1 = archivesTypeRepository.findByCnName(archivesType.getCnName()); if (archivesType1.size() == 0) { - tableName += DateUtils.getNowDateTime(); + + //如果pid 为空就是顶级菜单 if (archivesType.getPid() == null) { archivesType.setPid("0"); } + //如果类型为模版 + if (archivesType.getIsType() == 6) { + createProject(archivesType, tableName); + return archivesType; + } + + tableName += DateUtils.getNowDateTime(); archivesType.setId(NanoIdUtils.randomNanoId()); archivesType.setEnName(tableName); archivesType = archivesTypeRepository.save(archivesType); dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId(), tableName); + } else { throw new BaseException("门类名称不能重复"); } return archivesType; } + /** + * 创建项目级门类 + */ + private void createProject(ArchivesType archivesType, String tableName) { + String cnName = archivesType.getCnName(); + tableName += DateUtils.getNowDateTime(); + archivesType.setId(NanoIdUtils.randomNanoId()); + archivesType.setEnName(tableName); + archivesType = archivesTypeRepository.save(archivesType); + dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId(), tableName); + + //获取项目级ID + String pid = archivesType.getId(); + //重新赋值表名 + tableName = "tb_"; + tableName += DateUtils.getNowDateTime(); + + archivesType.setId(NanoIdUtils.randomNanoId()); + archivesType.setCnName(cnName + "(案卷)"); + archivesType.setEnName(tableName); + archivesType.setPid(pid); + //修改门类类型为案卷 + archivesType.setIsType(3); + //保存案卷级 + archivesTypeRepository.save(archivesType); + dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId(), tableName); + + //重新赋值表名 + tableName = "tb_"; + tableName += DateUtils.getNowDateTime(); + + archivesType.setId(NanoIdUtils.randomNanoId()); + archivesType.setCnName(cnName + "(卷内)"); + archivesType.setEnName(tableName); + archivesType.setPid(pid); + //修改门类类型为案卷 + archivesType.setIsType(4); + //保存案卷级 + archivesTypeRepository.save(archivesType); + dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId(), tableName); + } + + /** + * 创建案卷级门类 + * + * @param archivesType + * @param tableName + */ + private void createArchives(ArchivesType archivesType, String tableName) { + //获取门类名称方便创建子集门类 + String cnName = archivesType.getCnName(); + + tableName += DateUtils.getNowDateTime(); + archivesType.setId(NanoIdUtils.randomNanoId()); + archivesType.setEnName(tableName); + archivesType = archivesTypeRepository.save(archivesType); + dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId(), tableName); + + //获取项目级ID + String pid = archivesType.getId(); + //重新赋值表名 + tableName = "tb_"; + tableName += DateUtils.getNowDateTime(); + + archivesType.setId(NanoIdUtils.randomNanoId()); + archivesType.setCnName(cnName + "(卷内)"); + archivesType.setEnName(tableName); + archivesType.setPid(pid); + //修改门类类型为案卷 + archivesType.setIsType(4); + //保存案卷级 + archivesTypeRepository.save(archivesType); + dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId(), tableName); + + } + @Override public List buildTree() { @@ -100,19 +185,18 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { @Override @Transactional(rollbackFor = Exception.class) public void delete(String id) { - ArchivesType archivesType=archivesTypeRepository.findById(id).orElseGet(ArchivesType::new); - if(archivesType.isTypeMetic()) + ArchivesType archivesType = archivesTypeRepository.findById(id).orElseGet(ArchivesType::new); + if (archivesType.isTypeMetic()) throw new BaseException("系统门类不可删除"); Integer count = archivesTypeRepository.findContextCount(archivesType.getId()); - if(count!=0) + if (count != 0) throw new BaseException("该门类存在档案信息,不可删除"); //查询子类 - if(archivesType.getIsType()!=ArchivesTypeEnum.files.getCode() && archivesType.getIsType() != ArchivesTypeEnum.inChive.getCode()) - { + if (archivesType.getIsType() != ArchivesTypeEnum.files.getCode() && archivesType.getIsType() != ArchivesTypeEnum.inChive.getCode()) { Integer sonCount = archivesTypeRepository.findSonContextCount(archivesType.getId()); - if(sonCount>0) + if (sonCount > 0) throw new BaseException("该门类其子级门类存在档案信息,不可删除"); } @@ -120,27 +204,27 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { dynamicTableService.DeleteTable(tableName); archivesTypeRepository.deleteById(id); archivesDictionaryRepository.deleteByCategoryId(id); - if(archivesType.getIsType()==ArchivesTypeEnum.files.getCode() || archivesType.getIsType() == ArchivesTypeEnum.inChive.getCode()) - dynamicTableService.DeleteTable("file_"+tableName); + if (archivesType.getIsType() == ArchivesTypeEnum.files.getCode() || archivesType.getIsType() == ArchivesTypeEnum.inChive.getCode()) + dynamicTableService.DeleteTable("file_" + tableName); - Set sonIds = this.findSonCategoryIds(archivesType.getId(),new HashSet()); - for(ArchivesType thisType:sonIds){ + Set sonIds = this.findSonCategoryIds(archivesType.getId(), new HashSet()); + for (ArchivesType thisType : sonIds) { String tableName1 = thisType.getEnName(); dynamicTableService.DeleteTable(tableName1); archivesTypeRepository.deleteById(thisType.getId()); archivesDictionaryRepository.deleteByCategoryId(thisType.getId()); - if(thisType.getIsType()==ArchivesTypeEnum.files.getCode() || thisType.getIsType() == ArchivesTypeEnum.inChive.getCode()) - dynamicTableService.DeleteTable("file_"+tableName1); + if (thisType.getIsType() == ArchivesTypeEnum.files.getCode() || thisType.getIsType() == ArchivesTypeEnum.inChive.getCode()) + dynamicTableService.DeleteTable("file_" + tableName1); } } - public Set findSonCategoryIds(String categoryIds,Set setIds){ - if(StringUtils.isEmpty(categoryIds)) + public Set findSonCategoryIds(String categoryIds, Set setIds) { + if (StringUtils.isEmpty(categoryIds)) return setIds; List list = archivesTypeRepository.findAllByPid(categoryIds); - for(ArchivesType archivesType:list){ + for (ArchivesType archivesType : list) { setIds.add(archivesType); - this.findSonCategoryIds(archivesType.getId(),setIds); + this.findSonCategoryIds(archivesType.getId(), setIds); } return setIds; } @@ -169,17 +253,17 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { @Override public Set findArchivesTypeByIds(List ids) { Set dtos = new HashSet<>(); - for(String id:ids){ + for (String id : ids) { Optional optional = archivesTypeRepository.findById(id); - if(optional.isPresent()){ + if (optional.isPresent()) { ArchivesType archivesType = optional.get(); //当该门类是文件集或案卷级 - if(archivesType.getIsType()== ArchivesTypeEnum.archives.getCode() || archivesType.getIsType()== ArchivesTypeEnum.files.getCode()){ + if (archivesType.getIsType() == ArchivesTypeEnum.archives.getCode() || archivesType.getIsType() == ArchivesTypeEnum.files.getCode()) { dtos.add(archivesTypeMapper.toDto(archivesType)); - //当门类为文件夹或项目 轮询出下面所有文件集/案卷级档案 - }else if(archivesType.getIsType() == ArchivesTypeEnum.folder.getCode() || archivesType.getIsType() == ArchivesTypeEnum.project.getCode()){ - Set thidDtos = this.findThisArchivesFileAllChild(archivesType.getId(),null); - if(null!=thidDtos && thidDtos.size()!=0){ + //当门类为文件夹或项目 轮询出下面所有文件集/案卷级档案 + } else if (archivesType.getIsType() == ArchivesTypeEnum.folder.getCode() || archivesType.getIsType() == ArchivesTypeEnum.project.getCode()) { + Set thidDtos = this.findThisArchivesFileAllChild(archivesType.getId(), null); + if (null != thidDtos && thidDtos.size() != 0) { dtos.addAll(thidDtos); } } @@ -194,40 +278,40 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { ArchivesType root = archivesTypeRepository.findByPid("0"); //获取门类信息 Optional optional = archivesTypeRepository.findById(id); - if(!optional.isPresent()) + if (!optional.isPresent()) return null; - ArchivesType archivesType = optional.get(); - if(root.getId().equals(archivesType.getPid())){ + ArchivesType archivesType = optional.get(); + if (root.getId().equals(archivesType.getPid())) { return archivesTypeMapper.toDto(archivesType); - }else{ - return this.findBelongById(archivesType.getPid(),root.getId()); + } else { + return this.findBelongById(archivesType.getPid(), root.getId()); } } - public ArchivesTypeDTO findBelongById(String id,String rootId) { + public ArchivesTypeDTO findBelongById(String id, String rootId) { //获取门类信息 Optional optional = archivesTypeRepository.findById(id); - if(!optional.isPresent()) + if (!optional.isPresent()) return null; - ArchivesType archivesType = optional.get(); - if(rootId.equals(archivesType.getPid())){ + ArchivesType archivesType = optional.get(); + if (rootId.equals(archivesType.getPid())) { return archivesTypeMapper.toDto(archivesType); - }else{ - return this.findBelongById(archivesType.getPid(),rootId); + } else { + return this.findBelongById(archivesType.getPid(), rootId); } } - public Set findThisArchivesFileAllChild(String categoryId,Set dtos){ - if(dtos == null) + public Set findThisArchivesFileAllChild(String categoryId, Set dtos) { + if (dtos == null) dtos = new HashSet<>(); List archivesTypes = archivesTypeRepository.findAllByPid(categoryId); - for(ArchivesType archivesType : archivesTypes){ - if(archivesType.getIsType() == ArchivesTypeEnum.folder.getCode() || archivesType.getIsType() == ArchivesTypeEnum.project.getCode()){ - Set thidDtos = this.findThisArchivesFileAllChild(archivesType.getId(),dtos); - if(null!=thidDtos && thidDtos.size()!=0){ + for (ArchivesType archivesType : archivesTypes) { + if (archivesType.getIsType() == ArchivesTypeEnum.folder.getCode() || archivesType.getIsType() == ArchivesTypeEnum.project.getCode()) { + Set thidDtos = this.findThisArchivesFileAllChild(archivesType.getId(), dtos); + if (null != thidDtos && thidDtos.size() != 0) { dtos.addAll(thidDtos); } - }else if(archivesType.getIsType()== ArchivesTypeEnum.archives.getCode() || archivesType.getIsType()== ArchivesTypeEnum.files.getCode()){ + } else if (archivesType.getIsType() == ArchivesTypeEnum.archives.getCode() || archivesType.getIsType() == ArchivesTypeEnum.files.getCode()) { dtos.add(archivesTypeMapper.toDto(archivesType)); } } @@ -235,5 +319,4 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { } - }