14 changed files with 370 additions and 46 deletions
			
			
		- 
					39archives/src/main/java/com/storeroom/modules/common/ArchivesListToMap.java
- 
					58archives/src/main/java/com/storeroom/modules/common/DynamicSQLTable.java
- 
					2archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java
- 
					28archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java
- 
					3archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/FieldVO.java
- 
					11archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java
- 
					15archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java
- 
					18archives/src/main/java/com/storeroom/modules/dictionary/service/DynamicTableService.java
- 
					85archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesDictionaryDTO.java
- 
					19archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java
- 
					49archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java
- 
					63archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java
- 
					20archives/src/test/java/ArchivesTypeTest.java
- 
					6system/src/main/resources/application.yml
| @ -0,0 +1,58 @@ | |||||
|  | package com.storeroom.modules.common; | ||||
|  | 
 | ||||
|  | import com.storeroom.utils.DateUtils; | ||||
|  | import org.springframework.beans.factory.annotation.Value; | ||||
|  | import org.springframework.jdbc.core.JdbcTemplate; | ||||
|  | 
 | ||||
|  | import java.util.List; | ||||
|  | import java.util.Map; | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | public class DynamicSQLTable { | ||||
|  | 
 | ||||
|  | 
 | ||||
|  |     @Value("${table-template.archive}") | ||||
|  |     private static String tbName; | ||||
|  | 
 | ||||
|  |     @Value("${table-template.file}") | ||||
|  |     private static String fileTbname; | ||||
|  | 
 | ||||
|  |     private static JdbcTemplate jdbcTemplate; | ||||
|  | 
 | ||||
|  |     /** | ||||
|  |      * 生成表 | ||||
|  |      * | ||||
|  |      * @param listMap | ||||
|  |      */ | ||||
|  |     public static void CreateTable(List<Map<String, Object>> listMap) { | ||||
|  |         tbName += DateUtils.getNowDateTime(); | ||||
|  |         StringBuilder stringBuilder = new StringBuilder("create table " + tbName + "(id varchar(100) primary key not null,"); | ||||
|  |         //List<Map<String, Object>> list = listMap; | ||||
|  |         for (int i = 0; i < listMap.size(); i++) { | ||||
|  |             stringBuilder.append(listMap.get(i).get("fieldName")); | ||||
|  |             stringBuilder.append(" "); | ||||
|  |             stringBuilder.append(listMap.get(i).get("isDataTypeDetails")); | ||||
|  |             stringBuilder.append("("); | ||||
|  |             stringBuilder.append(listMap.get(i).get("isColumnLength")); | ||||
|  |             stringBuilder.append(")"); | ||||
|  |             if (listMap.size() - 1 != i) { | ||||
|  |                 stringBuilder.append(","); | ||||
|  |             } | ||||
|  |             if (listMap.size() - 1 == i) { | ||||
|  |                 stringBuilder.append(")"); | ||||
|  |             } | ||||
|  |         } | ||||
|  |         jdbcTemplate.execute(stringBuilder.toString()); | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     /** | ||||
|  |      * 修改表 | ||||
|  |      * | ||||
|  |      * @param listMap / | ||||
|  |      * @return / | ||||
|  |      */ | ||||
|  |     public Integer UpdataTable(List<Map<String, Object>> listMap) { | ||||
|  |         StringBuilder stringBuilder=new StringBuilder("insert into archives_dictionary"); | ||||
|  |         return 0; | ||||
|  |     } | ||||
|  | } | ||||
| @ -0,0 +1,15 @@ | |||||
|  | package com.storeroom.modules.dictionary.service; | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO; | ||||
|  | 
 | ||||
|  | import java.util.List; | ||||
|  | 
 | ||||
|  | public interface ArchivesDictionaryService { | ||||
|  | 
 | ||||
|  |     /** | ||||
|  |      * 批量保存 | ||||
|  |      * @param list | ||||
|  |      */ | ||||
|  |     void saveAll(List<ArchivesDictionaryDTO> list); | ||||
|  | } | ||||
| @ -0,0 +1,18 @@ | |||||
|  | package com.storeroom.modules.dictionary.service; | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | import com.storeroom.modules.dictionary.service.dto.FieldDTO; | ||||
|  | 
 | ||||
|  | import java.io.File; | ||||
|  | import java.util.List; | ||||
|  | 
 | ||||
|  | public interface DynamicTableService { | ||||
|  | 
 | ||||
|  |     /* | ||||
|  |      * 生成表 | ||||
|  |      */ | ||||
|  |     void DynamicCreate(Integer type,String archiveTypeId); | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | } | ||||
| @ -0,0 +1,85 @@ | |||||
|  | package com.storeroom.modules.dictionary.service.dto; | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | import com.storeroom.base.BaseDTO; | ||||
|  | import lombok.Getter; | ||||
|  | import lombok.Setter; | ||||
|  | 
 | ||||
|  | import java.io.Serializable; | ||||
|  | import java.util.Objects; | ||||
|  | 
 | ||||
|  | @Getter | ||||
|  | @Setter | ||||
|  | public class ArchivesDictionaryDTO extends BaseDTO implements Serializable { | ||||
|  | 
 | ||||
|  |     private String id; | ||||
|  | 
 | ||||
|  |     private String categoryId; | ||||
|  | 
 | ||||
|  |     private String sysDictionaryId; | ||||
|  | 
 | ||||
|  |     private String fieldName; | ||||
|  | 
 | ||||
|  |     private String fieldCnName; | ||||
|  | 
 | ||||
|  |     private String isDefaultValue; | ||||
|  | 
 | ||||
|  |     private String isInputClass; | ||||
|  | 
 | ||||
|  |     private Integer isDataType; | ||||
|  | 
 | ||||
|  |     private String isDataTypeDetails; | ||||
|  | 
 | ||||
|  |     private Integer isColumnLength; | ||||
|  | 
 | ||||
|  |     private Integer isColumnType; | ||||
|  | 
 | ||||
|  |     private Integer isSequence; | ||||
|  | 
 | ||||
|  |     private Integer isType; | ||||
|  | 
 | ||||
|  |     private Boolean isSystem; | ||||
|  | 
 | ||||
|  |     private Boolean isLine; | ||||
|  | 
 | ||||
|  |     private Boolean isInput; | ||||
|  | 
 | ||||
|  |     private Boolean isRequired; | ||||
|  | 
 | ||||
|  |     private Boolean isAutomatic; | ||||
|  | 
 | ||||
|  |     private Boolean isAdd; | ||||
|  | 
 | ||||
|  |     private Boolean isSearch; | ||||
|  | 
 | ||||
|  |     private Boolean isInherit; | ||||
|  | 
 | ||||
|  |     private Boolean isFilling; | ||||
|  | 
 | ||||
|  |     private Integer fillingDigit; | ||||
|  | 
 | ||||
|  |     private Boolean isRepeat; | ||||
|  | 
 | ||||
|  |     private Boolean isDisplay; | ||||
|  | 
 | ||||
|  |     private Integer displayOrder; | ||||
|  | 
 | ||||
|  |     private Boolean isDisplayformat; | ||||
|  | 
 | ||||
|  |     private String displayformatType; | ||||
|  | 
 | ||||
|  |     private Integer displayformatWidth; | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public boolean equals(Object o) { | ||||
|  |         if (this == o) return true; | ||||
|  |         if (o == null || getClass() != o.getClass()) return false; | ||||
|  |         ArchivesDictionaryDTO that = (ArchivesDictionaryDTO) o; | ||||
|  |         return Objects.equals(id, that.id) && Objects.equals(categoryId, that.categoryId) && Objects.equals(sysDictionaryId, that.sysDictionaryId) && Objects.equals(fieldName, that.fieldName) && Objects.equals(fieldCnName, that.fieldCnName) && Objects.equals(isDefaultValue, that.isDefaultValue) && Objects.equals(isInputClass, that.isInputClass) && Objects.equals(isDataType, that.isDataType) && Objects.equals(isDataTypeDetails, that.isDataTypeDetails) && Objects.equals(isColumnLength, that.isColumnLength) && Objects.equals(isColumnType, that.isColumnType) && Objects.equals(isSequence, that.isSequence) && Objects.equals(isType, that.isType) && Objects.equals(isSystem, that.isSystem) && Objects.equals(isLine, that.isLine) && Objects.equals(isInput, that.isInput) && Objects.equals(isRequired, that.isRequired) && Objects.equals(isAutomatic, that.isAutomatic) && Objects.equals(isAdd, that.isAdd) && Objects.equals(isSearch, that.isSearch) && Objects.equals(isInherit, that.isInherit) && Objects.equals(isFilling, that.isFilling) && Objects.equals(fillingDigit, that.fillingDigit) && Objects.equals(isRepeat, that.isRepeat) && Objects.equals(isDisplay, that.isDisplay) && Objects.equals(displayOrder, that.displayOrder) && Objects.equals(isDisplayformat, that.isDisplayformat) && Objects.equals(displayformatType, that.displayformatType) && Objects.equals(displayformatWidth, that.displayformatWidth); | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public int hashCode() { | ||||
|  |         return Objects.hash(id, categoryId, sysDictionaryId, fieldName, fieldCnName, isDefaultValue, isInputClass, isDataType, isDataTypeDetails, isColumnLength, isColumnType, isSequence, isType, isSystem, isLine, isInput, isRequired, isAutomatic, isAdd, isSearch, isInherit, isFilling, fillingDigit, isRepeat, isDisplay, displayOrder, isDisplayformat, displayformatType, displayformatWidth); | ||||
|  |     } | ||||
|  | } | ||||
| @ -0,0 +1,19 @@ | |||||
|  | package com.storeroom.modules.dictionary.service.impl; | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | import com.storeroom.modules.dictionary.service.ArchivesDictionaryService; | ||||
|  | import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO; | ||||
|  | import org.springframework.stereotype.Service; | ||||
|  | 
 | ||||
|  | import java.util.List; | ||||
|  | 
 | ||||
|  | @Service | ||||
|  | public class ArchivesDictionaryImpl implements ArchivesDictionaryService { | ||||
|  | 
 | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public void saveAll(List<ArchivesDictionaryDTO> list) { | ||||
|  | 
 | ||||
|  | 
 | ||||
|  |     } | ||||
|  | } | ||||
| @ -0,0 +1,63 @@ | |||||
|  | package com.storeroom.modules.dictionary.service.impl; | ||||
|  | 
 | ||||
|  | import com.storeroom.modules.dictionary.domain.vo.FieldVO; | ||||
|  | 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.dto.FieldDTO; | ||||
|  | import lombok.RequiredArgsConstructor; | ||||
|  | import org.springframework.stereotype.Service; | ||||
|  | 
 | ||||
|  | import java.util.ArrayList; | ||||
|  | import java.util.List; | ||||
|  | import java.util.Map; | ||||
|  | 
 | ||||
|  | @Service | ||||
|  | @RequiredArgsConstructor | ||||
|  | public class DynamicTableImpl implements DynamicTableService { | ||||
|  | 
 | ||||
|  | 
 | ||||
|  |     private final FieldService fieldService; | ||||
|  |     private final ArchivesDictionaryService archivesDictionaryService; | ||||
|  |     private ArchivesDictionaryDTO archivesDictionaryDTO; | ||||
|  | 
 | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public void DynamicCreate(Integer type, String archiveTypeId) { | ||||
|  |         // if (type == 1 || type == 2){ | ||||
|  |         List<Integer> integerList = new ArrayList<>(); | ||||
|  |         integerList.add(1); | ||||
|  |         integerList.add(2); | ||||
|  |         integerList.add(3); | ||||
|  | 
 | ||||
|  |         //获取基础字典表数据 | ||||
|  |         List<FieldVO> list = fieldService.findGroupType(integerList); | ||||
|  |         List<ArchivesDictionaryDTO> newList = new ArrayList<>(); | ||||
|  | 
 | ||||
|  |         if (!list.isEmpty()) { | ||||
|  |             for (FieldVO j : list) { | ||||
|  |                 j.setCategoryId(archiveTypeId); | ||||
|  |                 archivesDictionaryDTO.setFieldName(j.getFieldName()); | ||||
|  |                 archivesDictionaryDTO.setFieldCnName(j.getFieldCnName()); | ||||
|  |                 archivesDictionaryDTO.setIsDefaultValue(j.getIsDefaultValue()); | ||||
|  |                 //archivesDictionaryDTO.setIsDataType(); | ||||
|  | 
 | ||||
|  |             } | ||||
|  |             // archivesDictionaryService.saveAll(); | ||||
|  |             //根据基础字典表创建数据 | ||||
|  |             // DynamicSQLTable.CreateTable(ArchivesListToMap.getMapList(newList)); | ||||
|  |         } | ||||
|  |         //  } | ||||
|  |     } | ||||
|  | 
 | ||||
|  | 
 | ||||
|  |     public void DynamicInsert(List<FieldVO> list) { | ||||
|  | 
 | ||||
|  | 
 | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     private void DynamicCreateFileTable(List<FieldDTO> list) { | ||||
|  | 
 | ||||
|  |     } | ||||
|  | } | ||||
| @ -1,9 +1,23 @@ | |||||
|  | import com.storeroom.modules.dictionary.domain.Field; | ||||
|  | import com.storeroom.modules.dictionary.domain.vo.FieldVO; | ||||
|  | import com.storeroom.modules.dictionary.service.FieldService; | ||||
|  | import lombok.RequiredArgsConstructor; | ||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||
| 
 | 
 | ||||
|  | import java.util.ArrayList; | ||||
|  | import java.util.List; | ||||
|  | 
 | ||||
|  | 
 | ||||
| public class ArchivesTypeTest { | public class ArchivesTypeTest { | ||||
| 
 | 
 | ||||
|     @Test |  | ||||
|     public void dynamicSystemTableTest() { |  | ||||
| 
 | 
 | ||||
|     } |  | ||||
|  | 
 | ||||
|  | //    @Test | ||||
|  | //    public void dynamicSystemTableTest() { | ||||
|  | //        List<Integer> list = new ArrayList<>(); | ||||
|  | //        list.add(1); | ||||
|  | //        list.add(2); | ||||
|  | //        List<FieldVO> vo = service.findGroupType(list); | ||||
|  | //        System.out.println(vo); | ||||
|  | //    } | ||||
| } | } | ||||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue