Browse Source

解决模板创建问题

master
刘力 2 years ago
parent
commit
a336d4cb95
  1. 2
      archives/src/main/java/com/storeroom/modules/dictionary/repository/FieldRepository.java
  2. 4
      archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java
  3. 5
      archives/src/main/java/com/storeroom/modules/dictionary/service/DynamicTableService.java
  4. 2
      archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java
  5. 4
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java
  6. 6
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java
  7. 26
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java
  8. 4
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java

2
archives/src/main/java/com/storeroom/modules/dictionary/repository/FieldRepository.java

@ -31,6 +31,6 @@ public interface FieldRepository extends JpaRepository<Field, String>{
* @param fieldCnName
* @return
*/
Field findByFieldCnName(String fieldCnName);
Field findByFieldCnNameAndIsType(String fieldCnName,Integer isType);
}

4
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<ArchivesDictionary> queryCategoryId(String categoryId);
List<ArchivesDictionary> queryCategoryIdAndIsType(String categoryId,Integer IsType);
}

5
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);

2
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);
}

4
archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java

@ -275,8 +275,8 @@ public class ArchivesDictionaryImpl implements ArchivesDictionaryService {
}
@Override
public List<ArchivesDictionary> queryCategoryId(String categoryId) {
return archivesDictionaryRepository.findByCategoryId(categoryId);
public List<ArchivesDictionary> queryCategoryIdAndIsType(String categoryId,Integer isType) {
return archivesDictionaryRepository.findByCategoryIdAndIsType(categoryId,isType);
}
}

6
archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java

@ -109,7 +109,7 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService {
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);
}
}

26
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<Integer> 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<ArchivesDictionary> arcList = archivesDictionaryService.queryCategoryId(categoryId);
@Transactional(rollbackFor = Exception.class)
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<>();
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<FieldVO> list, String archiveTypeId) {
List<ArchivesDictionaryDTO> newList = new ArrayList<>();
for (FieldVO j : list) {
@ -190,6 +195,7 @@ public class DynamicTableImpl implements DynamicTableService {
archivesDictionaryService.saveAll(newList);
}
private void DynamicCreateFileTable(List<FieldVO> list, String tableName) {
List<Map<String, Object>> maps = ArchivesListToMap.getMaps(list);

4
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);
}
}
Loading…
Cancel
Save