From a336d4cb95257ffb59df871239bfb4e01ad30494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8A=9B?= Date: Mon, 26 Sep 2022 15:32:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=A8=A1=E6=9D=BF=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/FieldRepository.java | 2 +- .../service/ArchivesDictionaryService.java | 4 +-- .../service/DynamicTableService.java | 5 ++-- .../dictionary/service/FieldService.java | 2 +- .../service/impl/ArchivesDictionaryImpl.java | 4 +-- .../service/impl/ArchivesTypeServiceImpl.java | 18 ++++++------- .../service/impl/DynamicTableImpl.java | 26 ++++++++++++------- .../service/impl/FieldServiceImpl.java | 4 +-- 8 files changed, 36 insertions(+), 29 deletions(-) diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/repository/FieldRepository.java b/archives/src/main/java/com/storeroom/modules/dictionary/repository/FieldRepository.java index 76b7d8f..cc66c8c 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/repository/FieldRepository.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/repository/FieldRepository.java @@ -31,6 +31,6 @@ public interface FieldRepository extends JpaRepository{ * @param fieldCnName * @return */ - Field findByFieldCnName(String fieldCnName); + Field findByFieldCnNameAndIsType(String fieldCnName,Integer isType); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java index 16413f0..d8e613c 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java @@ -116,8 +116,8 @@ public interface ArchivesDictionaryService { /** * 根据门类id 查询门类字典 - * @param archiveTypeid 门类id + * @param categoryId 门类id * @return */ - List queryCategoryId(String categoryId); + List queryCategoryIdAndIsType(String categoryId,Integer IsType); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/DynamicTableService.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/DynamicTableService.java index c32586d..ddbe212 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/DynamicTableService.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/DynamicTableService.java @@ -23,10 +23,11 @@ public interface DynamicTableService { /** * 生成模版表 - * @param categoryId 门类id + * @param arcTypeId 新的关联门类id + * @param categoryId 复制对象的门类id * @param tableName 表名 */ - void DynamicTemplateTable(String categoryId, String tableName); + void DynamicTemplateTable(String arcTypeId,String categoryId,Integer isType, String tableName); diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java index 596b027..6103542 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java @@ -22,6 +22,6 @@ public interface FieldService { /** * 根据字段名查询 */ - Field findByCNName(String fieldCnName); + Field findByCNName(String fieldCnName,Integer isType); } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java index 472e73e..2f940b1 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java @@ -275,8 +275,8 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { } @Override - public List queryCategoryId(String categoryId) { - return archivesDictionaryRepository.findByCategoryId(categoryId); + public List queryCategoryIdAndIsType(String categoryId,Integer isType) { + return archivesDictionaryRepository.findByCategoryIdAndIsType(categoryId,isType); } } 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 2ad1c9c..c233443 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 @@ -43,7 +43,7 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { //#生成表名称 String tableName = "tb_"; ArchivesType archivesType = archivesTypeMapper.toEntity(archivesTypeDTO); - List artChilder= archivesType.getChildren(); + List artChilder = archivesType.getChildren(); List archivesType1 = archivesTypeRepository.findByCnName(archivesType.getCnName()); if (archivesType1.size() == 0) { @@ -59,15 +59,15 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { archivesType.getChildren().forEach(item -> { //如果模板类型为项目 if (item.getIsType() == 2) { - ArchivesType ar = createTemplateRoot(archivesTypeDTO.getPid(),cnName, item); + ArchivesType ar = createTemplateRoot(archivesTypeDTO.getPid(), cnName, item); createArchives(ar.getId(), cnName, item.getChildren()); } //如果模板类型为案卷 if (item.getIsType() == 3) { - createArchives(archivesTypeDTO.getPid(),cnName, artChilder); + createArchives(archivesTypeDTO.getPid(), cnName, artChilder); } //如果是文件级 - if (item.getIsType() == 5){ + if (item.getIsType() == 5) { ArchivesType arcProject = new ArchivesType(); String tableName1 = "tb_"; tableName1 += DateUtils.getNowDateTime(); @@ -97,7 +97,7 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { } } - private ArchivesType createTemplateRoot(String pid,String cnName, ArchivesType item) { + private ArchivesType createTemplateRoot(String pid, String cnName, ArchivesType item) { ArchivesType arcProject = new ArchivesType(); String tableName1 = "tb_"; tableName1 += DateUtils.getNowDateTime(); @@ -105,11 +105,11 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { arcProject.setIsType(item.getIsType()); arcProject.setPid(pid); arcProject.setCategorySeq(item.getCategorySeq()); - arcProject.setCnName(cnName+"(项目)"); + arcProject.setCnName(cnName + "(项目)"); arcProject.setRemark(item.getRemark()); arcProject.setEnName(tableName1); arcProject.setTypeMetic(item.isTypeMetic()); - dynamicTableService.DynamicTemplateTable(arcProject.getId(), tableName1); + dynamicTableService.DynamicTemplateTable(arcProject.getId(), item.getId(), item.getIsType(), tableName1); archivesTypeRepository.save(arcProject); return arcProject; } @@ -137,7 +137,7 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { archivesType1.setTypeMetic(arc.isTypeMetic()); archivesType1.setEnName(tableName); archivesTypeRepository.save(archivesType1); - dynamicTableService.DynamicCreate(archivesType1.getIsType(), archivesType1.getId(), tableName); + dynamicTableService.DynamicTemplateTable(archivesType1.getId(), arc.getId(), arc.getIsType(), tableName); createInChive(archivesType1.getId(), cnName, arc.getChildren()); } } @@ -161,7 +161,7 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { archivesType1.setCategorySeq(arc.getCategorySeq()); archivesType1.setTypeMetic(arc.isTypeMetic()); archivesType1.setEnName(tableName); - dynamicTableService.DynamicCreate(archivesType1.getIsType(), archivesType1.getId(), tableName); + dynamicTableService.DynamicTemplateTable(archivesType1.getId(), arc.getId(), arc.getIsType(), tableName); archivesTypeRepository.save(archivesType1); } } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java index 68f1dd5..d50ccb9 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java @@ -9,6 +9,7 @@ import com.storeroom.modules.dictionary.service.ArchivesDictionaryService; import com.storeroom.modules.dictionary.service.DynamicTableService; import com.storeroom.modules.dictionary.service.FieldService; import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO; +import com.storeroom.utils.NanoIdUtils; import com.storeroom.utils.StringUtils; import lombok.RequiredArgsConstructor; @@ -16,6 +17,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.sql.DataSource; @@ -37,6 +39,7 @@ public class DynamicTableImpl implements DynamicTableService { @Override + @Transactional(rollbackFor = Exception.class) public void DynamicCreate(Integer type, String archiveTypeId, String tableName) { List integerList = new ArrayList<>(); @@ -76,37 +79,40 @@ public class DynamicTableImpl implements DynamicTableService { /** * 生成模版表 * - * @param categoryId - * @param tableName + * @param categoryId 查询门类id + * @param tableName 表明 */ @Override - public void DynamicTemplateTable(String categoryId, String tableName) { - List arcList = archivesDictionaryService.queryCategoryId(categoryId); + @Transactional(rollbackFor = Exception.class) + public void DynamicTemplateTable(String arcTypeId, String categoryId,Integer isType, String tableName) { + List arcList = archivesDictionaryService.queryCategoryIdAndIsType(categoryId,2); //#生成文件表名称 - String fileTableName = "file_" + tableName; + // String fileTableName = "file_" + tableName; List fieldVOList = new ArrayList<>(); arcList.forEach(item -> { FieldVO fieldVO = new FieldVO(); - Field field = fieldService.findByCNName(item.getFieldCnName()); + Field field = fieldService.findByCNName(item.getFieldCnName(), item.getIsType()); + //如果系统默认字段里面不为空就为复制数据 if (!ObjectUtil.isEmpty(field)) { fieldVO.setId(field.getId()); fieldVO.setIsSystem(field.getIsSystem()); + fieldVO.setDictionaryId(field.getDictionaryId()); } fieldVO.setFieldName(item.getFieldName()); fieldVO.setFieldCnName(item.getFieldCnName()); fieldVO.setIsDefaultValue(item.getIsDefaultValue()); fieldVO.setIsDataType(item.getIsDataType()); fieldVO.setIsDataTypeDetails(item.getIsDataTypeDetails()); - fieldVO.setIsDefaultValue(item.getIsDefaultValue()); fieldVO.setIsColumnLength(item.getIsColumnLength()); fieldVO.setIsSequence(item.getIsSequence()); fieldVO.setIsType(item.getIsType()); + fieldVO.setCategoryId(arcTypeId); fieldVOList.add(fieldVO); }); - DynamicInsert(fieldVOList, categoryId); - DynamicCreateFileTable(fieldVOList, categoryId); + DynamicInsert(fieldVOList, arcTypeId); + DynamicCreateFileTable(fieldVOList, tableName); } @@ -163,7 +169,6 @@ public class DynamicTableImpl implements DynamicTableService { * @param list * @param archiveTypeId */ - private void DynamicInsert(List list, String archiveTypeId) { List newList = new ArrayList<>(); for (FieldVO j : list) { @@ -190,6 +195,7 @@ public class DynamicTableImpl implements DynamicTableService { archivesDictionaryService.saveAll(newList); } + private void DynamicCreateFileTable(List list, String tableName) { List> maps = ArchivesListToMap.getMaps(list); diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java index 0d54804..eb76366 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java @@ -76,10 +76,10 @@ public class FieldServiceImpl implements FieldService { } @Override - public Field findByCNName(String fieldCNName){ + public Field findByCNName(String fieldCNName,Integer isType){ if (StringUtils.isEmpty(fieldCNName)){ throw new BaseException("字段名不能为空"); } - return fieldRepository.findByFieldCnName(fieldCNName); + return fieldRepository.findByFieldCnNameAndIsType(fieldCNName,isType); } }