Browse Source

commit code

master
刘力 3 years ago
parent
commit
10844941b5
  1. 94
      archives/src/main/java/com/storeroom/modules/common/ArchivesListToMap.java
  2. 13
      archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java
  3. 8
      archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesTypeRepository.java
  4. 18
      archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeQueryCriteria.java
  5. 21
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesDictionaryImpl.java
  6. 39
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/ArchivesTypeServiceImpl.java
  7. 89
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java
  8. 12
      archives/src/main/java/com/storeroom/modules/dictionary/service/mapstruct/ArchivesDictionaryMapper.java
  9. 26
      archives/src/test/java/ArchivesTypeTest.java
  10. 1
      system/src/main/resources/application.yml
  11. 20
      system/src/test/java/TestOnlineUserService.java

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

@ -15,54 +15,54 @@ import java.util.Map;
public class ArchivesListToMap {
public static String getMaps(List<FieldVO> lists, String tableName) {
// public static String getMaps(List<FieldVO> lists, String tableName) {
//
// StringBuilder stringBuilder = new StringBuilder("create table " + tableName + "(id varchar(100) primary key not null,");
//
// List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
// for (Object obj : lists) {
// 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);
// }
// List<Map<String, Object>> list = maps;
// for (int i = 0; i < list.size(); i++) {
// stringBuilder.append(list.get(i).get("fieldName"));
// stringBuilder.append(" ");
// stringBuilder.append(list.get(i).get("isDataTypeDetails"));
// stringBuilder.append("(");
// stringBuilder.append(list.get(i).get("isColumnLength"));
// stringBuilder.append(")");
// if (list.size() - 1 != i) {
// stringBuilder.append(",");
// }
// if (list.size() - 1 == i) {
// stringBuilder.append(")");
// }
// }
// return stringBuilder.toString();
// }
StringBuilder stringBuilder = new StringBuilder("create table " + tableName + "(id varchar(100) primary key not null,");
List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
for (Object obj : lists) {
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);
}
List<Map<String, Object>> list = maps;
for (int i = 0; i < list.size(); i++) {
stringBuilder.append(list.get(i).get("fieldName"));
stringBuilder.append(" ");
stringBuilder.append(list.get(i).get("isDataTypeDetails"));
stringBuilder.append("(");
stringBuilder.append(list.get(i).get("isColumnLength"));
stringBuilder.append(")");
if (list.size() - 1 != i) {
stringBuilder.append(",");
}
if (list.size() - 1 == i) {
stringBuilder.append(")");
}
}
return stringBuilder.toString();
}
public static List<Map<String,Object>> getMapList(List<FieldVO> list){
public static List<Map<String,Object>> getMaps(List<FieldVO> list){
List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
for (Object obj : list) {

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

@ -21,7 +21,6 @@ public class ArchivesDictionary extends BaseEntity implements Serializable {
@Id
@Column(name = "id")
@NotNull(groups = Update.class)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(value = "ID", hidden = true)
private String id;
@ -141,9 +140,13 @@ public class ArchivesDictionary extends BaseEntity implements Serializable {
@ApiModelProperty(value = "显示格式")
private String displayformatType;
@Column(name = "displayformat_width")
@Column(name = "edit_length")
@ApiModelProperty(value = "编辑长度")
private Integer editLength;
@Column(name = "display_length")
@ApiModelProperty(value = "显示长度")
private Integer displayformatWidth;
private Integer displayLength;
@Override
@ -151,11 +154,11 @@ public class ArchivesDictionary extends BaseEntity implements Serializable {
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(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);
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(editLength, that.editLength) && Objects.equals(displayLength, that.displayLength);
}
@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);
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, editLength, displayLength);
}
}

8
archives/src/main/java/com/storeroom/modules/dictionary/repository/ArchivesTypeRepository.java

@ -3,6 +3,12 @@ package com.storeroom.modules.dictionary.repository;
import com.storeroom.modules.dictionary.domain.ArchivesType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
public interface ArchivesTypeRepository extends JpaRepository<ArchivesType,String>, JpaSpecificationExecutor<ArchivesType> {
import java.util.List;
public interface ArchivesTypeRepository extends JpaRepository<ArchivesType, String>, JpaSpecificationExecutor<ArchivesType> {
List<ArchivesType> findByCnName(String cn);
}

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

@ -0,0 +1,18 @@
package com.storeroom.modules.dictionary.service.dto;
import com.storeroom.annotaion.DataPermission;
import com.storeroom.annotaion.Query;
import lombok.Data;
@Data
@DataPermission(fieldName = "id")
public class ArchivesTypeQueryCriteria {
@Query(type = Query.Type.INNER_LIKE)
private String cnName;
@Query(type = Query.Type.INNER_LIKE)
private String enName;
}

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

@ -1,19 +1,38 @@
package com.storeroom.modules.dictionary.service.impl;
import com.storeroom.modules.dictionary.domain.ArchivesDictionary;
import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository;
import com.storeroom.modules.dictionary.service.ArchivesDictionaryService;
import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO;
import com.storeroom.modules.dictionary.service.mapstruct.ArchivesDictionaryMapper;
import com.storeroom.utils.NanoIdUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
@RequiredArgsConstructor
public class ArchivesDictionaryImpl implements ArchivesDictionaryService {
private final ArchivesDictionaryRepository archivesDictionaryRepository;
private final ArchivesDictionaryMapper archivesDictionaryMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveAll(List<ArchivesDictionaryDTO> list) {
List<ArchivesDictionary> list1=new ArrayList<>();
for (ArchivesDictionaryDTO o : list) {
ArchivesDictionary a = archivesDictionaryMapper.toEntity(o);
a.setId(NanoIdUtils.randomNanoId());
//this.archivesDictionaryRepository.saveAndFlush(a);
list1.add(a);
}
archivesDictionaryRepository.saveAll(list1);
}
}

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

@ -1,12 +1,10 @@
package com.storeroom.modules.dictionary.service.impl;
import com.storeroom.modules.common.ArchivesListToMap;
import com.storeroom.exception.BaseException;
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;
@ -14,17 +12,12 @@ import com.storeroom.utils.NanoIdUtils;
import lombok.RequiredArgsConstructor;
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;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@ -33,8 +26,6 @@ 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;
@ -48,27 +39,19 @@ public class ArchivesTypeServiceImpl implements ArchivesTypeService {
@Override
@Transactional(rollbackFor = Exception.class)
public void create(ArchivesTypeDTO archivesTypeDTO) {
ArchivesType archivesType = archivesTypeMapper.toEntity(archivesTypeDTO);
//注入nonaid
List<ArchivesType> archivesType1 = archivesTypeRepository.findByCnName(archivesType.getCnName());
if (archivesType1 == null) {
tableName += DateUtils.getNowDateTime();
archivesType.setId(NanoIdUtils.randomNanoId());
archivesType.setEnName(tableName);
archivesTypeRepository.save(archivesType);
dynamicTableService.DynamicCreate(archivesType.getIsType(),archivesType.getId());
dynamicTableService.DynamicCreate(archivesType.getIsType(), archivesType.getId());
} else {
throw new BaseException("门类名称不能重复");
}
// 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();
//
// }
}
}

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

@ -1,12 +1,18 @@
package com.storeroom.modules.dictionary.service.impl;
import com.storeroom.exception.BaseException;
import com.storeroom.modules.common.ArchivesListToMap;
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 com.storeroom.utils.DateUtils;
import com.storeroom.utils.NanoIdUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -20,22 +26,62 @@ public class DynamicTableImpl implements DynamicTableService {
private final FieldService fieldService;
private final ArchivesDictionaryService archivesDictionaryService;
private ArchivesDictionaryDTO archivesDictionaryDTO;
private final JdbcTemplate jdbcTemplate;
@Value("${table-template.archive}")
private String tableName;
@Value("${table-template.file}")
private String fileTableName;
@Override
public void DynamicCreate(Integer type, String archiveTypeId) {
// if (type == 1 || type == 2){
List<Integer> integerList = new ArrayList<>();
if (type == 4 || type == 5) {
integerList.add(1);
integerList.add(2);
List<FieldVO> fieldList = queryList(integerList);
DynamicInsert(fieldList, archiveTypeId);
DynamicCreateFileTable(fieldList, tableName);
integerList.clear();
integerList.add(3);
List<FieldVO> fileList = queryList(integerList);
DynamicInsert(fileList, archiveTypeId);
DynamicCreateFileTable(fileList, fileTableName);
//获取基础字典表数据
List<FieldVO> list = fieldService.findGroupType(integerList);
List<ArchivesDictionaryDTO> newList = new ArrayList<>();
} else {
integerList.add(1);
integerList.add(2);
List<FieldVO> fieldList = fieldService.findGroupType(integerList);
DynamicInsert(fieldList, archiveTypeId);
DynamicCreateFileTable(fieldList, tableName);
}
}
/**
* 查询字典字段
*
* @param type /
* @return /
*/
private List<FieldVO> queryList(List<Integer> type) {
List<FieldVO> list = fieldService.findGroupType(type);
return list;
}
if (!list.isEmpty()) {
/**
* 插入档案字典表数据
*
* @param list
* @param archiveTypeId
*/
private void DynamicInsert(List<FieldVO> list, String archiveTypeId) {
List<ArchivesDictionaryDTO> newList = new ArrayList<>();
ArchivesDictionaryDTO archivesDictionaryDTO = new ArchivesDictionaryDTO();
for (FieldVO j : list) {
j.setCategoryId(archiveTypeId);
archivesDictionaryDTO.setFieldName(j.getFieldName());
@ -49,25 +95,28 @@ public class DynamicTableImpl implements DynamicTableService {
archivesDictionaryDTO.setIsType(j.getIsType());
archivesDictionaryDTO.setIsSystem(j.getIsSystem());
newList.add(archivesDictionaryDTO);
//archivesDictionaryDTO.setIsDataType();
}
archivesDictionaryService.saveAll(newList);
}
// archivesDictionaryService.saveAll();
//根据基础字典表创建数据
// DynamicSQLTable.CreateTable(ArchivesListToMap.getMapList(newList));
private void DynamicCreateFileTable(List<FieldVO> list, String tableName) {
tableName += DateUtils.getNowDateTime();
List<Map<String, Object>> maps = ArchivesListToMap.getMaps(list);
StringBuilder stringBuilder = new StringBuilder("create table " + tableName + " (id varchar(100) primary key,");
for (int i = 0; i < maps.size(); i++) {
stringBuilder.append(maps.get(i).get("fieldName"));
stringBuilder.append(" ");
stringBuilder.append(maps.get(i).get("isDataTypeDetails"));
stringBuilder.append("(");
stringBuilder.append(maps.get(i).get("isColumnLength"));
stringBuilder.append(")");
if (maps.size() - 1 != i) {
stringBuilder.append(",");
}
// }
if (maps.size() - 1 == i) {
stringBuilder.append(")");
}
public void DynamicInsert(List<FieldVO> list) {
}
private void DynamicCreateFileTable(List<FieldDTO> list) {
jdbcTemplate.execute(stringBuilder.toString());
}
}

12
archives/src/main/java/com/storeroom/modules/dictionary/service/mapstruct/ArchivesDictionaryMapper.java

@ -0,0 +1,12 @@
package com.storeroom.modules.dictionary.service.mapstruct;
import com.storeroom.base.BaseMapper;
import com.storeroom.modules.dictionary.domain.ArchivesDictionary;
import com.storeroom.modules.dictionary.service.dto.ArchivesDictionaryDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ArchivesDictionaryMapper extends BaseMapper<ArchivesDictionaryDTO, ArchivesDictionary> {
}

26
archives/src/test/java/ArchivesTypeTest.java

@ -1,26 +0,0 @@
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest
public class ArchivesTypeTest {
// @Autowired
// private FieldService fieldService;
// @Test
// public void dynamicSystemTableTest() {
// List<Integer> list = new ArrayList<>();
// list.add(1);
// list.add(2);
// List<FieldVO> vo = fieldService.findGroupType(list);
// System.out.println(vo);
// }
}

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

@ -22,6 +22,7 @@ spring:
hibernate:
ddl-auto: none
open-in-view: true
show-sql: true
redis:
#数据库索引

20
system/src/test/java/TestOnlineUserService.java

@ -1,7 +1,15 @@
import com.storeroom.AppRun;
import com.storeroom.modules.dictionary.domain.vo.FieldVO;
import com.storeroom.modules.dictionary.service.FieldService;
import com.storeroom.modules.security.service.OnlineUserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
public class TestOnlineUserService {
@ -15,4 +23,16 @@ public class TestOnlineUserService {
}
}
// @Autowired
// private FieldService fieldService;
//
// @Test
// public void dynamicSystemTableTest() {
// List<Integer> list = new ArrayList<>();
// list.add(1);
// list.add(2);
// List<FieldVO> vo = fieldService.findGroupType(list);
// System.out.println(vo);
// }
}
Loading…
Cancel
Save