Browse Source

修改门类模版生成方法

master
liu_li 2 years ago
parent
commit
ac8a118868
  1. 1
      archives/src/main/java/com/storeroom/modules/common/ArchivesTypeEnum.java
  2. 3
      archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java
  3. 163
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java

1
archives/src/main/java/com/storeroom/modules/common/ArchivesTypeEnum.java

@ -8,6 +8,7 @@ public enum ArchivesTypeEnum {
folder(1, "文件夹"), folder(1, "文件夹"),
project(2, "项目"), project(2, "项目"),
archives(3, "案卷"), archives(3, "案卷"),
inChive(4, "卷内"), inChive(4, "卷内"),
files(5, "文件"), files(5, "文件"),

3
archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java

@ -62,6 +62,9 @@ public class ArchivesTypeController {
if (StringUtils.isEmpty(archivesTypeDTO.getCnName())) { if (StringUtils.isEmpty(archivesTypeDTO.getCnName())) {
throw new BaseException("名称不能为空"); throw new BaseException("名称不能为空");
} }
if (archivesTypeDTO.getIsType() == 1 || archivesTypeDTO.getIsType() == 4) {
throw new BaseException("文件夹或卷内不能被选中");
}
return ApiResponse.success(archivesTypeService.create(archivesTypeDTO)); return ApiResponse.success(archivesTypeService.create(archivesTypeDTO));
} }

163
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); ArchivesType archivesType = archivesTypeMapper.toEntity(archivesTypeDTO);
List<ArchivesType> archivesType1 = archivesTypeRepository.findByCnName(archivesType.getCnName()); List<ArchivesType> archivesType1 = archivesTypeRepository.findByCnName(archivesType.getCnName());
if (archivesType1.size() == 0) { if (archivesType1.size() == 0) {
tableName += DateUtils.getNowDateTime();
//如果pid 为空就是顶级菜单
if (archivesType.getPid() == null) { if (archivesType.getPid() == null) {
archivesType.setPid("0"); archivesType.setPid("0");
} }
//如果类型为模版
if (archivesType.getIsType() == 6) {
createProject(archivesType, tableName);
return archivesType;
}
tableName += DateUtils.getNowDateTime();
archivesType.setId(NanoIdUtils.randomNanoId()); archivesType.setId(NanoIdUtils.randomNanoId());
archivesType.setEnName(tableName); archivesType.setEnName(tableName);
archivesType = archivesTypeRepository.save(archivesType); archivesType = archivesTypeRepository.save(archivesType);
dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId(), tableName); dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId(), tableName);
} else { } else {
throw new BaseException("门类名称不能重复"); throw new BaseException("门类名称不能重复");
} }
return archivesType; 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 @Override
public List<ArchivesType> buildTree() { public List<ArchivesType> buildTree() {
@ -100,19 +185,18 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void delete(String id) { 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("系统门类不可删除"); throw new BaseException("系统门类不可删除");
Integer count = archivesTypeRepository.findContextCount(archivesType.getId()); Integer count = archivesTypeRepository.findContextCount(archivesType.getId());
if(count!=0)
if (count != 0)
throw new BaseException("该门类存在档案信息,不可删除"); 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()); Integer sonCount = archivesTypeRepository.findSonContextCount(archivesType.getId());
if(sonCount>0)
if (sonCount > 0)
throw new BaseException("该门类其子级门类存在档案信息,不可删除"); throw new BaseException("该门类其子级门类存在档案信息,不可删除");
} }
@ -120,27 +204,27 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService {
dynamicTableService.DeleteTable(tableName); dynamicTableService.DeleteTable(tableName);
archivesTypeRepository.deleteById(id); archivesTypeRepository.deleteById(id);
archivesDictionaryRepository.deleteByCategoryId(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<ArchivesType> sonIds = this.findSonCategoryIds(archivesType.getId(),new HashSet<ArchivesType>());
for(ArchivesType thisType:sonIds){
Set<ArchivesType> sonIds = this.findSonCategoryIds(archivesType.getId(), new HashSet<ArchivesType>());
for (ArchivesType thisType : sonIds) {
String tableName1 = thisType.getEnName(); String tableName1 = thisType.getEnName();
dynamicTableService.DeleteTable(tableName1); dynamicTableService.DeleteTable(tableName1);
archivesTypeRepository.deleteById(thisType.getId()); archivesTypeRepository.deleteById(thisType.getId());
archivesDictionaryRepository.deleteByCategoryId(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<ArchivesType> findSonCategoryIds(String categoryIds,Set<ArchivesType> setIds){
if(StringUtils.isEmpty(categoryIds))
public Set<ArchivesType> findSonCategoryIds(String categoryIds, Set<ArchivesType> setIds) {
if (StringUtils.isEmpty(categoryIds))
return setIds; return setIds;
List<ArchivesType> list = archivesTypeRepository.findAllByPid(categoryIds); List<ArchivesType> list = archivesTypeRepository.findAllByPid(categoryIds);
for(ArchivesType archivesType:list){
for (ArchivesType archivesType : list) {
setIds.add(archivesType); setIds.add(archivesType);
this.findSonCategoryIds(archivesType.getId(),setIds);
this.findSonCategoryIds(archivesType.getId(), setIds);
} }
return setIds; return setIds;
} }
@ -169,17 +253,17 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService {
@Override @Override
public Set<ArchivesTypeDTO> findArchivesTypeByIds(List<String> ids) { public Set<ArchivesTypeDTO> findArchivesTypeByIds(List<String> ids) {
Set<ArchivesTypeDTO> dtos = new HashSet<>(); Set<ArchivesTypeDTO> dtos = new HashSet<>();
for(String id:ids){
for (String id : ids) {
Optional<ArchivesType> optional = archivesTypeRepository.findById(id); Optional<ArchivesType> optional = archivesTypeRepository.findById(id);
if(optional.isPresent()){
if (optional.isPresent()) {
ArchivesType archivesType = optional.get(); 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)); dtos.add(archivesTypeMapper.toDto(archivesType));
//当门类为文件夹或项目 轮询出下面所有文件集/案卷级档案 //当门类为文件夹或项目 轮询出下面所有文件集/案卷级档案
}else if(archivesType.getIsType() == ArchivesTypeEnum.folder.getCode() || archivesType.getIsType() == ArchivesTypeEnum.project.getCode()){
Set<ArchivesTypeDTO> 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<ArchivesTypeDTO> thidDtos = this.findThisArchivesFileAllChild(archivesType.getId(), null);
if (null != thidDtos && thidDtos.size() != 0) {
dtos.addAll(thidDtos); dtos.addAll(thidDtos);
} }
} }
@ -194,40 +278,40 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService {
ArchivesType root = archivesTypeRepository.findByPid("0"); ArchivesType root = archivesTypeRepository.findByPid("0");
//获取门类信息 //获取门类信息
Optional<ArchivesType> optional = archivesTypeRepository.findById(id); Optional<ArchivesType> optional = archivesTypeRepository.findById(id);
if(!optional.isPresent())
if (!optional.isPresent())
return null; return null;
ArchivesType archivesType = optional.get(); ArchivesType archivesType = optional.get();
if(root.getId().equals(archivesType.getPid())){
if (root.getId().equals(archivesType.getPid())) {
return archivesTypeMapper.toDto(archivesType); 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<ArchivesType> optional = archivesTypeRepository.findById(id); Optional<ArchivesType> optional = archivesTypeRepository.findById(id);
if(!optional.isPresent())
if (!optional.isPresent())
return null; return null;
ArchivesType archivesType = optional.get(); ArchivesType archivesType = optional.get();
if(rootId.equals(archivesType.getPid())){
if (rootId.equals(archivesType.getPid())) {
return archivesTypeMapper.toDto(archivesType); return archivesTypeMapper.toDto(archivesType);
}else{
return this.findBelongById(archivesType.getPid(),rootId);
} else {
return this.findBelongById(archivesType.getPid(), rootId);
} }
} }
public Set<ArchivesTypeDTO> findThisArchivesFileAllChild(String categoryId,Set<ArchivesTypeDTO> dtos){
if(dtos == null)
public Set<ArchivesTypeDTO> findThisArchivesFileAllChild(String categoryId, Set<ArchivesTypeDTO> dtos) {
if (dtos == null)
dtos = new HashSet<>(); dtos = new HashSet<>();
List<ArchivesType> archivesTypes = archivesTypeRepository.findAllByPid(categoryId); List<ArchivesType> archivesTypes = archivesTypeRepository.findAllByPid(categoryId);
for(ArchivesType archivesType : archivesTypes){
if(archivesType.getIsType() == ArchivesTypeEnum.folder.getCode() || archivesType.getIsType() == ArchivesTypeEnum.project.getCode()){
Set<ArchivesTypeDTO> 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<ArchivesTypeDTO> thidDtos = this.findThisArchivesFileAllChild(archivesType.getId(), dtos);
if (null != thidDtos && thidDtos.size() != 0) {
dtos.addAll(thidDtos); 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)); dtos.add(archivesTypeMapper.toDto(archivesType));
} }
} }
@ -235,5 +319,4 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService {
} }
} }
Loading…
Cancel
Save