From 7f8493c0f38e8f1b1331acac3c2cc2718e0de913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8A=9B?= Date: Mon, 26 Sep 2022 19:43:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E5=A2=9E=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ArchivesDictionaryImpl.java | 39 +++++++------- .../service/impl/ArchivesTypeServiceImpl.java | 12 ++--- .../service/impl/DynamicTableImpl.java | 54 +++++++++++++++++-- 3 files changed, 75 insertions(+), 30 deletions(-) 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 2f940b1..7d80615 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 @@ -42,6 +42,7 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { ArchivesDictionary a = archivesDictionaryMapper.toEntity(o); a.setId(NanoIdUtils.randomNanoId()); list1.add(a); + archivesDictionaryRepository.save(a); } archivesDictionaryRepository.saveAll(list1); } @@ -65,20 +66,20 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { @Override public boolean isFieldRepeat(String categoryId, String fieldName, String id) { - ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findFirstByCategoryIdAndFieldName(categoryId,fieldName); - if(archivesDictionary == null) + ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findFirstByCategoryIdAndFieldName(categoryId, fieldName); + if (archivesDictionary == null) + return true; + if (archivesDictionary.getId().equals(id)) return true; - if(archivesDictionary.getId().equals(id)) - return true; return false; } @Override public boolean isFieldCnRepeat(String categoryId, String fieldCnName, String id) { - ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findFirstByCategoryIdAndFieldCnName(categoryId,fieldCnName); - if(archivesDictionary == null) + ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findFirstByCategoryIdAndFieldCnName(categoryId, fieldCnName); + if (archivesDictionary == null) return true; - if(archivesDictionary.getId().equals(id)) + if (archivesDictionary.getId().equals(id)) return true; return false; } @@ -134,26 +135,26 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { @Transactional public void create(ArchivesDictionaryDTO arcdicDto) { ArchivesDictionary arc = archivesDictionaryMapper.toEntity(arcdicDto); - ArchivesDictionary fieldName = archivesDictionaryRepository.findFirstByCategoryIdAndFieldName(arcdicDto.getCategoryId(),arcdicDto.getFieldName()); - ArchivesDictionary fieldCnName = archivesDictionaryRepository.findFirstByCategoryIdAndFieldCnName(arcdicDto.getCategoryId(),arcdicDto.getFieldCnName()); + ArchivesDictionary fieldName = archivesDictionaryRepository.findFirstByCategoryIdAndFieldName(arcdicDto.getCategoryId(), arcdicDto.getFieldName()); + ArchivesDictionary fieldCnName = archivesDictionaryRepository.findFirstByCategoryIdAndFieldCnName(arcdicDto.getCategoryId(), arcdicDto.getFieldCnName()); - if(fieldName != null) + if (fieldName != null) throw new BaseException("字段标识不能重复"); - if(fieldCnName!=null) + if (fieldCnName != null) throw new BaseException("字段名称不能重复"); arc.setId(NanoIdUtils.randomNanoId()); arc.setIsInput(true); archivesDictionaryRepository.save(arc); - String colType = arcdicDto.getIsDataType() == 1?"varchar":"int"; - colType = colType+"("+arcdicDto.getIsColumnLength()+") "; + String colType = arcdicDto.getIsDataType() == 1 ? "varchar" : "int"; + colType = colType + "(" + arcdicDto.getIsColumnLength() + ") "; String adddefault = " "; - if(!StringUtils.isEmpty(arcdicDto.getIsDefaultValue())){ + if (!StringUtils.isEmpty(arcdicDto.getIsDefaultValue())) { adddefault = " default "; - adddefault = arcdicDto.getIsDataType() == 2 ? adddefault+arcdicDto.getIsDefaultValue() : adddefault+"'"+arcdicDto.getIsDefaultValue()+"'"; + adddefault = arcdicDto.getIsDataType() == 2 ? adddefault + arcdicDto.getIsDefaultValue() : adddefault + "'" + arcdicDto.getIsDefaultValue() + "'"; } ArchivesType archivesType = archivesTypeRepository.findById(arcdicDto.getCategoryId()).get(); - String sql = "alter table "+archivesType.getEnName()+" add "+arc.getFieldName()+" "+colType+adddefault+" comment '"+arc.getFieldCnName()+"'"; + String sql = "alter table " + archivesType.getEnName() + " add " + arc.getFieldName() + " " + colType + adddefault + " comment '" + arc.getFieldCnName() + "'"; entityManager.createNativeQuery(sql).executeUpdate(); } @@ -163,7 +164,7 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findById(id).get(); ArchivesType archivesType = archivesTypeRepository.findById(archivesDictionary.getCategoryId()).get(); archivesDictionaryRepository.deleteById(id); - String sql = "alter table "+archivesType.getEnName()+" DROP COLUMN "+archivesDictionary.getFieldName(); + String sql = "alter table " + archivesType.getEnName() + " DROP COLUMN " + archivesDictionary.getFieldName(); entityManager.createNativeQuery(sql).executeUpdate(); } @@ -275,8 +276,8 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService { } @Override - public List queryCategoryIdAndIsType(String categoryId,Integer isType) { - return archivesDictionaryRepository.findByCategoryIdAndIsType(categoryId,isType); + 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 c233443..6fc2911 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 @@ -84,14 +84,14 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService { } }); } + } else { + tableName += DateUtils.getNowDateTime(); + archivesType.setId(NanoIdUtils.randomNanoId()); + archivesType.setEnName(tableName); + archivesType = archivesTypeRepository.save(archivesType); + dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId(), tableName); } - 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("门类名称不能重复"); } 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 d50ccb9..196df8f 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.modules.dictionary.service.mapstruct.ArchivesDictionaryMapper; import com.storeroom.utils.NanoIdUtils; import com.storeroom.utils.StringUtils; import lombok.RequiredArgsConstructor; @@ -36,6 +37,7 @@ public class DynamicTableImpl implements DynamicTableService { private final ArchivesDictionaryService archivesDictionaryService; private final JdbcTemplate jdbcTemplate; private final DataSource dataSource; + private final ArchivesDictionaryMapper archivesDictionaryMapper; @Override @@ -80,12 +82,12 @@ public class DynamicTableImpl implements DynamicTableService { * 生成模版表 * * @param categoryId 查询门类id - * @param tableName 表明 + * @param tableName 表明 */ @Override @Transactional(rollbackFor = Exception.class) - public void DynamicTemplateTable(String arcTypeId, String categoryId,Integer isType, String tableName) { - List arcList = archivesDictionaryService.queryCategoryIdAndIsType(categoryId,2); + public void DynamicTemplateTable(String arcTypeId, String categoryId, Integer isType, String tableName) { + List arcList = archivesDictionaryService.queryCategoryIdAndIsType(categoryId, 2); //#生成文件表名称 // String fileTableName = "file_" + tableName; List fieldVOList = new ArrayList<>(); @@ -111,7 +113,7 @@ public class DynamicTableImpl implements DynamicTableService { fieldVOList.add(fieldVO); }); - DynamicInsert(fieldVOList, arcTypeId); + DynamicInsertTemplateTable(arcList, arcTypeId); DynamicCreateFileTable(fieldVOList, tableName); } @@ -191,10 +193,52 @@ public class DynamicTableImpl implements DynamicTableService { newList.add(archivesDictionaryDTO); } - archivesDictionaryService.saveAll(newList); } + /** + * 插入模板数据 + */ + private void DynamicInsertTemplateTable(List archivesDictionaryList, String archiveTypeId) { + List newList = new ArrayList<>(); + archivesDictionaryList.forEach(item -> { + ArchivesDictionary archivesDictionary=new ArchivesDictionary(); + archivesDictionary.setCategoryId(archiveTypeId); + archivesDictionary.setDictionaryConfigId(item.getDictionaryConfigId()); + archivesDictionary.setFieldName(item.getFieldName()); + archivesDictionary.setFieldCnName(item.getFieldCnName()); + archivesDictionary.setIsDefaultValue(item.getIsDefaultValue()); + archivesDictionary.setIsInputClass(item.getIsInputClass()); + archivesDictionary.setIsDataType(item.getIsDataType()); + archivesDictionary.setIsDataTypeDetails(item.getIsDataTypeDetails()); + archivesDictionary.setIsColumnLength(item.getIsColumnLength()); + archivesDictionary.setIsColumnType(item.getIsColumnType()); + archivesDictionary.setIsSequence(item.getIsSequence()); + archivesDictionary.setIsType(item.getIsType()); + archivesDictionary.setIsSystem(item.getIsSystem()); + archivesDictionary.setIsLine(item.getIsLine()); + archivesDictionary.setIsInput(item.getIsInput()); + archivesDictionary.setIsRequired(item.getIsRequired()); + archivesDictionary.setIsAutomatic(item.getIsAutomatic()); + archivesDictionary.setIsAdd(item.getIsAdd()); + archivesDictionary.setIsSearch(item.getIsSearch()); + archivesDictionary.setIsInherit(item.getIsInherit()); + archivesDictionary.setIsFilling(item.getIsFilling()); + archivesDictionary.setFillingDigit(item.getFillingDigit()); + archivesDictionary.setIsRepeat(item.getIsRepeat()); + archivesDictionary.setIsDisplay(item.getIsDisplay()); + archivesDictionary.setDisplayOrder(item.getDisplayOrder()); + archivesDictionary.setDisplayOrderBy(item.getDisplayOrderBy()); + archivesDictionary.setIsDisplayformat(item.getIsDisplayformat()); + archivesDictionary.setDisplayformatType(item.getDisplayformatType()); + archivesDictionary.setEditLength(item.getEditLength()); + archivesDictionary.setDisplayLength(item.getDisplayLength()); + archivesDictionary.setQueue(item.getQueue()); + newList.add(archivesDictionary); + }); + archivesDictionaryService.saveAll(archivesDictionaryMapper.toDto(newList)); + } + private void DynamicCreateFileTable(List list, String tableName) {