Browse Source

commit code

master
刘力 3 years ago
parent
commit
8c9f631036
  1. 39
      archives/src/main/java/com/storeroom/modules/common/ArchivesListToMap.java
  2. 58
      archives/src/main/java/com/storeroom/modules/common/DynamicSQLTable.java
  3. 2
      archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java
  4. 28
      archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java
  5. 3
      archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/FieldVO.java
  6. 11
      archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java
  7. 15
      archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java
  8. 18
      archives/src/main/java/com/storeroom/modules/dictionary/service/DynamicTableService.java
  9. 85
      archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesDictionaryDTO.java
  10. 19
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java
  11. 49
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java
  12. 63
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java
  13. 20
      archives/src/test/java/ArchivesTypeTest.java
  14. 6
      system/src/main/resources/application.yml

39
archives/src/main/java/com/storeroom/modules/common/ArchivesListToMap.java

@ -27,11 +27,11 @@ public class ArchivesListToMap {
for (Field fie : f) {
try {
fie.setAccessible(true);
String s = fie.getName();
map.put(fie.getName(), fie.get(obj));
} catch (Exception e) {
e.printStackTrace();
}
}
//获取父类的私有属性
for (Field fie : c.getSuperclass().getDeclaredFields()) {
@ -48,9 +48,9 @@ public class ArchivesListToMap {
for (int i = 0; i < list.size(); i++) {
stringBuilder.append(list.get(i).get("fieldName"));
stringBuilder.append(" ");
stringBuilder.append(list.get(i).get("fieldType"));
stringBuilder.append(list.get(i).get("isDataTypeDetails"));
stringBuilder.append("(");
stringBuilder.append(list.get(i).get("fieldExtent"));
stringBuilder.append(list.get(i).get("isColumnLength"));
stringBuilder.append(")");
if (list.size() - 1 != i) {
stringBuilder.append(",");
@ -58,10 +58,41 @@ public class ArchivesListToMap {
if (list.size() - 1 == i) {
stringBuilder.append(")");
}
}
return stringBuilder.toString();
}
public static List<Map<String,Object>> getMapList(List<FieldVO> list){
List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
for (Object obj : list) {
Class c = obj.getClass();
Field[] f = c.getDeclaredFields();
Map<String, Object> map = new HashMap<String, Object>();
for (Field fie : f) {
try {
fie.setAccessible(true);
String s = fie.getName();
map.put(fie.getName(), fie.get(obj));
} catch (Exception e) {
e.printStackTrace();
}
}
//获取父类的私有属性
for (Field fie : c.getSuperclass().getDeclaredFields()) {
try {
fie.setAccessible(true);//取消语言访问检查
map.put(fie.getName(), fie.get(obj));//获取私有变量值
} catch (Exception e) {
e.printStackTrace();
}
}
maps.add(map);
}
return maps;
}
}

58
archives/src/main/java/com/storeroom/modules/common/DynamicSQLTable.java

@ -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;
}
}

2
archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java

@ -27,6 +27,8 @@ public class ArchivesTypeController {
private final ArchivesTypeService archivesTypeService;
@ApiOperation("门类类型")
@AnonymousGetMapping("dropdown-list")
public ApiResponse<Object> getType() {

28
archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java

@ -128,32 +128,34 @@ public class ArchivesDictionary extends BaseEntity implements Serializable {
@ApiModelProperty(value = "是否浏览")
private Boolean isDisplay;
@Column(name = "is_displayorder")
@ApiModelProperty(value = "是否浏览排序")
private Boolean isDisplayorder;
@Column(name = "display_order")
@ApiModelProperty(value = "排序")
private Integer displayOrder;
@Column(name = "is_displayformat")
@ApiModelProperty(value = "是否有显示格式")
private Boolean isDisplayformat;
@Column(name = "displayorder")
@ApiModelProperty(value = "浏览排序")
private Boolean displayorder;
@Column(name = "displayformat_type")
@ApiModelProperty(value = "显示格式")
private String displayformatType;
@Column(name = "displayformat_width")
@ApiModelProperty(value = "显示长度")
private Integer displayformatWidth;
@Column(name = "displayorder_type")
@ApiModelProperty(value = "浏览排序状态")
private String displayorderType;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ArchivesDictionary that = (ArchivesDictionary) o;
return Objects.equals(id, that.id) && Objects.equals(fieldName, that.fieldName) && Objects.equals(fieldCnName, that.fieldCnName) && Objects.equals(isDefaultValue, that.isDefaultValue) && Objects.equals(isDataType, that.isDataType) && Objects.equals(isColumnLength, that.isColumnLength) && 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(isDisplayorder, that.isDisplayorder) && Objects.equals(displayorder, that.displayorder) && Objects.equals(displayorderType, that.displayorderType);
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, fieldName, fieldCnName, isDefaultValue, isDataType, isColumnLength, isSequence, isType, isSystem, isLine, isInput, isRequired, isAutomatic, isAdd, isSearch, isInherit, isFilling, fillingDigit, isRepeat, isDisplay, isDisplayorder, displayorder, displayorderType);
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);
}
}

3
archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/FieldVO.java

@ -67,4 +67,7 @@ public class FieldVO {
@JsonProperty("isSystem")
private Boolean isSystem;
private String categoryId;
}

11
archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesDictionaryRepository.java

@ -7,12 +7,19 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface ArchivesDictionaryRepository extends JpaRepository<ArchivesDictionary,String>, JpaSpecificationExecutor<ArchivesDictionary> {
public interface ArchivesDictionaryRepository extends JpaRepository<ArchivesDictionary, String>, JpaSpecificationExecutor<ArchivesDictionary> {
@Query(nativeQuery = true,
value = "select field_name from archives_dictionary where category_id = ?1 and is_display is true order by is_displayorder asc")
List<String> findDisPlayField(String categoryId);
List<ArchivesDictionary> findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(String categoryId,boolean isInput);
List<ArchivesDictionary> findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(String categoryId, boolean isInput);
@Query(value = "INSERT INTO yxk_storeroom.archives_dictionary(id,category_id,field_name,field_cn_name,dictionary_id,is_data_type,is_data_type_details,is_column_length,is_sequence,is_type,is_system VALUES ())", nativeQuery = true)
void insertData(String id,String categoryId,
String fieldName,String fieldCnName,
String isDefaultValue,Integer isDataType,
String isDataTypeDetails,String isColumnLength,
Integer isSequence,Integer isType,Integer isSystem);
}

15
archives/src/main/java/com/storeroom/modules/dictionary/service/ArchivesDictionaryService.java

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

18
archives/src/main/java/com/storeroom/modules/dictionary/service/DynamicTableService.java

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

85
archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesDictionaryDTO.java

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

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

@ -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) {
}
}

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

@ -3,11 +3,14 @@ package com.storeroom.modules.dictionary.service.impl;
import com.storeroom.modules.common.ArchivesListToMap;
import com.storeroom.modules.dictionary.domain.ArchivesType;
import com.storeroom.modules.dictionary.domain.vo.FieldVO;
import com.storeroom.modules.dictionary.repository.ArchivesTypeRepository;
import com.storeroom.modules.dictionary.service.ArchivesTypeService;
import com.storeroom.modules.dictionary.service.DynamicTableService;
import com.storeroom.modules.dictionary.service.FieldService;
import com.storeroom.modules.dictionary.service.dto.ArchivesTypeDTO;
import com.storeroom.modules.dictionary.service.mapstruct.ArchivesTypeMapper;
import com.storeroom.utils.DateUtils;
import com.storeroom.utils.NanoIdUtils;
import lombok.RequiredArgsConstructor;
@ -15,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Field;
import java.util.ArrayList;
@ -29,41 +33,42 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService {
private final ArchivesTypeMapper archivesTypeMapper;
private final FieldService fieldService;
private final JdbcTemplate jdbcTemplate;
private final ArchivesTypeRepository archivesTypeRepository;
private final DynamicTableService dynamicTableService;
@Value("${table-template.name}")
@Value("${table-template.archive}")
private String tableName;
@Value("${table-template.file}")
private String fileTableName;
@Override
@Transactional(rollbackFor = Exception.class)
public void create(ArchivesTypeDTO archivesTypeDTO) {
ArchivesType archivesType = archivesTypeMapper.toEntity(archivesTypeDTO);
switch (archivesType.getIsType()) {
case 1 -> dynamicSystemTable(archivesType.getIsType());
case 2 -> dynameicTemplateTable(archivesType.getIsType());
}
//注入nonaid
archivesType.setId(NanoIdUtils.randomNanoId());
archivesTypeRepository.save(archivesType);
dynamicTableService.DynamicCreate(archivesType.getIsType(),archivesType.getId());
}
public void dynamicSystemTable(Integer type) {
tableName += tableName + DateUtils.getNowDateTime();
List<FieldVO> list = fieldService.findGroupType(type);
if (!list.isEmpty()) {
String sqlstr = ArchivesListToMap.getMaps(list, tableName);
jdbcTemplate.execute(sqlstr);
}
}
public void dynameicTemplateTable(Integer type) {
}
// public void dynamicSystemTable(Integer type) {
// tableName += DateUtils.getNowDateTime();
// List<FieldVO> list = fieldService.findGroupType(type);
// if (!list.isEmpty()) {
// String sqlstr = ArchivesListToMap.getMaps(list, tableName);
// jdbcTemplate.execute(sqlstr);
// }
// }
//
// public void dynameicTemplateTable(Integer type) {
// fileTableName += DateUtils.getNowDateTime();
//
// }
}

63
archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java

@ -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) {
}
}

20
archives/src/test/java/ArchivesTypeTest.java

@ -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 java.util.ArrayList;
import java.util.List;
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);
// }
}

6
system/src/main/resources/application.yml

@ -73,5 +73,7 @@ user-cache:
# 生成表模板
table-template:
#表名称
name: tb_
#生成表名称
archive: tb_
#生成文件表
file: file_tb_
Loading…
Cancel
Save