Browse Source

修改新增模板功能

master
刘力 2 years ago
parent
commit
7f8493c0f3
  1. 39
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java
  2. 12
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java
  3. 54
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java

39
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); ArchivesDictionary a = archivesDictionaryMapper.toEntity(o);
a.setId(NanoIdUtils.randomNanoId()); a.setId(NanoIdUtils.randomNanoId());
list1.add(a); list1.add(a);
archivesDictionaryRepository.save(a);
} }
archivesDictionaryRepository.saveAll(list1); archivesDictionaryRepository.saveAll(list1);
} }
@ -65,20 +66,20 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService {
@Override @Override
public boolean isFieldRepeat(String categoryId, String fieldName, String id) { 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; return true;
if(archivesDictionary.getId().equals(id))
return true;
return false; return false;
} }
@Override @Override
public boolean isFieldCnRepeat(String categoryId, String fieldCnName, String id) { 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; return true;
if(archivesDictionary.getId().equals(id))
if (archivesDictionary.getId().equals(id))
return true; return true;
return false; return false;
} }
@ -134,26 +135,26 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService {
@Transactional @Transactional
public void create(ArchivesDictionaryDTO arcdicDto) { public void create(ArchivesDictionaryDTO arcdicDto) {
ArchivesDictionary arc = archivesDictionaryMapper.toEntity(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("字段标识不能重复"); throw new BaseException("字段标识不能重复");
if(fieldCnName!=null)
if (fieldCnName != null)
throw new BaseException("字段名称不能重复"); throw new BaseException("字段名称不能重复");
arc.setId(NanoIdUtils.randomNanoId()); arc.setId(NanoIdUtils.randomNanoId());
arc.setIsInput(true); arc.setIsInput(true);
archivesDictionaryRepository.save(arc); 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 = " "; String adddefault = " ";
if(!StringUtils.isEmpty(arcdicDto.getIsDefaultValue())){
if (!StringUtils.isEmpty(arcdicDto.getIsDefaultValue())) {
adddefault = " default "; 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(); 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(); entityManager.createNativeQuery(sql).executeUpdate();
} }
@ -163,7 +164,7 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService {
ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findById(id).get(); ArchivesDictionary archivesDictionary = archivesDictionaryRepository.findById(id).get();
ArchivesType archivesType = archivesTypeRepository.findById(archivesDictionary.getCategoryId()).get(); ArchivesType archivesType = archivesTypeRepository.findById(archivesDictionary.getCategoryId()).get();
archivesDictionaryRepository.deleteById(id); 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(); entityManager.createNativeQuery(sql).executeUpdate();
} }
@ -275,8 +276,8 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService {
} }
@Override @Override
public List<ArchivesDictionary> queryCategoryIdAndIsType(String categoryId,Integer isType) {
return archivesDictionaryRepository.findByCategoryIdAndIsType(categoryId,isType);
public List<ArchivesDictionary> queryCategoryIdAndIsType(String categoryId, Integer isType) {
return archivesDictionaryRepository.findByCategoryIdAndIsType(categoryId, isType);
} }
} }

12
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 { } else {
throw new BaseException("门类名称不能重复"); throw new BaseException("门类名称不能重复");
} }

54
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.DynamicTableService;
import com.storeroom.modules.dictionary.service.FieldService; import com.storeroom.modules.dictionary.service.FieldService;
import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO; 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.NanoIdUtils;
import com.storeroom.utils.StringUtils; import com.storeroom.utils.StringUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -36,6 +37,7 @@ public class DynamicTableImpl implements DynamicTableService {
private final ArchivesDictionaryService archivesDictionaryService; private final ArchivesDictionaryService archivesDictionaryService;
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
private final DataSource dataSource; private final DataSource dataSource;
private final ArchivesDictionaryMapper archivesDictionaryMapper;
@Override @Override
@ -80,12 +82,12 @@ public class DynamicTableImpl implements DynamicTableService {
* 生成模版表 * 生成模版表
* *
* @param categoryId 查询门类id * @param categoryId 查询门类id
* @param tableName 表明
* @param tableName 表明
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void DynamicTemplateTable(String arcTypeId, String categoryId,Integer isType, String tableName) {
List<ArchivesDictionary> arcList = archivesDictionaryService.queryCategoryIdAndIsType(categoryId,2);
public void DynamicTemplateTable(String arcTypeId, String categoryId, Integer isType, String tableName) {
List<ArchivesDictionary> arcList = archivesDictionaryService.queryCategoryIdAndIsType(categoryId, 2);
//#生成文件表名称 //#生成文件表名称
// String fileTableName = "file_" + tableName; // String fileTableName = "file_" + tableName;
List<FieldVO> fieldVOList = new ArrayList<>(); List<FieldVO> fieldVOList = new ArrayList<>();
@ -111,7 +113,7 @@ public class DynamicTableImpl implements DynamicTableService {
fieldVOList.add(fieldVO); fieldVOList.add(fieldVO);
}); });
DynamicInsert(fieldVOList, arcTypeId);
DynamicInsertTemplateTable(arcList, arcTypeId);
DynamicCreateFileTable(fieldVOList, tableName); DynamicCreateFileTable(fieldVOList, tableName);
} }
@ -191,10 +193,52 @@ public class DynamicTableImpl implements DynamicTableService {
newList.add(archivesDictionaryDTO); newList.add(archivesDictionaryDTO);
} }
archivesDictionaryService.saveAll(newList); archivesDictionaryService.saveAll(newList);
} }
/**
* 插入模板数据
*/
private void DynamicInsertTemplateTable(List<ArchivesDictionary> archivesDictionaryList, String archiveTypeId) {
List<ArchivesDictionary> 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<FieldVO> list, String tableName) { private void DynamicCreateFileTable(List<FieldVO> list, String tableName) {

Loading…
Cancel
Save