Browse Source

新增门类

master
刘力 3 years ago
parent
commit
e04fd9289a
  1. 7
      archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java
  2. 2
      archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java
  3. 2
      archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java
  4. 5
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java
  5. 2
      common/src/main/java/com/storeroom/utils/ApiResponse.java
  6. 104
      common/src/main/java/com/storeroom/utils/ReflectUtils.java

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

@ -28,7 +28,6 @@ public class ArchivesTypeController {
private final ArchivesTypeService archivesTypeService; private final ArchivesTypeService archivesTypeService;
@ApiOperation("门类类型") @ApiOperation("门类类型")
@AnonymousGetMapping("dropdown-list") @AnonymousGetMapping("dropdown-list")
public ApiResponse<Object> getType() { public ApiResponse<Object> getType() {
@ -46,7 +45,7 @@ public class ArchivesTypeController {
@AnonymousPostMapping("create") @AnonymousPostMapping("create")
//TODO:权限未添加 //TODO:权限未添加
public ApiResponse<Object> save(@RequestBody ArchivesTypeDTO archivesTypeDTO) { public ApiResponse<Object> save(@RequestBody ArchivesTypeDTO archivesTypeDTO) {
if (!archivesTypeDTO.getId().isEmpty()) {
if (archivesTypeDTO.getId() != null) {
throw new BaseException("this is not empty Data"); throw new BaseException("this is not empty Data");
} }
if (archivesTypeDTO.getIsType() == null) { if (archivesTypeDTO.getIsType() == null) {
@ -60,9 +59,9 @@ public class ArchivesTypeController {
} }
@ApiOperation("获取门类树状菜单") @ApiOperation("获取门类树状菜单")
@AnonymousGetMapping("menuTree")
@AnonymousGetMapping("menu")
//TODO:权限未添加 //TODO:权限未添加
public ApiResponse<Object> getMenuTree(){
public ApiResponse<Object> getMenuTree() {
return ApiResponse.success(archivesTypeService.buildTree()); return ApiResponse.success(archivesTypeService.buildTree());
} }
} }

2
archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java

@ -41,7 +41,7 @@ public class ArchivesType extends BaseEntity implements Serializable {
@Column(name = "is_type_metic") @Column(name = "is_type_metic")
@ApiModelProperty(value = "是否为模板档案") @ApiModelProperty(value = "是否为模板档案")
private Integer isTypeMetic;
private Boolean isTypeMetic;
@Column(name = "category_seq") @Column(name = "category_seq")
@ApiModelProperty(value = "排序") @ApiModelProperty(value = "排序")

2
archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java

@ -27,7 +27,7 @@ public class ArchivesTypeDTO extends BaseDTO implements Serializable {
private Integer isType; private Integer isType;
private Integer isTypeMetic;
private Boolean isTypeMetic;
private Integer categorySeq; private Integer categorySeq;

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

@ -34,7 +34,7 @@ public class DynamicTableImpl implements DynamicTableService {
@Override @Override
public void DynamicCreate(Integer type, String archiveTypeId,String tableName) {
public void DynamicCreate(Integer type, String archiveTypeId, String tableName) {
List<Integer> integerList = new ArrayList<>(); List<Integer> integerList = new ArrayList<>();
if (type == 4 || type == 5) { if (type == 4 || type == 5) {
integerList.add(1); integerList.add(1);
@ -47,6 +47,7 @@ public class DynamicTableImpl implements DynamicTableService {
integerList.add(3); integerList.add(3);
List<FieldVO> fileList = queryList(integerList); List<FieldVO> fileList = queryList(integerList);
DynamicInsert(fileList, archiveTypeId); DynamicInsert(fileList, archiveTypeId);
fileTableName += DateUtils.getNowDateTime();
DynamicCreateFileTable(fileList, fileTableName); DynamicCreateFileTable(fileList, fileTableName);
} else { } else {
@ -98,7 +99,7 @@ public class DynamicTableImpl implements DynamicTableService {
} }
private void DynamicCreateFileTable(List<FieldVO> list, String tableName) { private void DynamicCreateFileTable(List<FieldVO> list, String tableName) {
tableName += DateUtils.getNowDateTime();
List<Map<String, Object>> maps = ArchivesListToMap.getMaps(list); List<Map<String, Object>> maps = ArchivesListToMap.getMaps(list);
StringBuilder stringBuilder = new StringBuilder("create table " + tableName + " (id varchar(100) primary key,"); StringBuilder stringBuilder = new StringBuilder("create table " + tableName + " (id varchar(100) primary key,");
for (int i = 0; i < maps.size(); i++) { for (int i = 0; i < maps.size(); i++) {

2
common/src/main/java/com/storeroom/utils/ApiResponse.java

@ -4,6 +4,8 @@ package com.storeroom.utils;
import com.storeroom.exception.constant.ResponseStatus; import com.storeroom.exception.constant.ResponseStatus;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
/** /**
* 通用的 API 接口封装 * 通用的 API 接口封装
*/ */

104
common/src/main/java/com/storeroom/utils/ReflectUtils.java

@ -0,0 +1,104 @@
package com.storeroom.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* 反射工具类
*/
public class ReflectUtils {
/**
* 定义静态工具方法使用反射创建对象
* 步骤
* 1 调用Class.forName(className)方法获取Class对象反射入口
* 2 调用Class的getDeclaredConstructor方法获取构造器
* 3 调用构造器的newInstance方法创建对象
* @param className 以字符串表示的类名称通常是包名+类名
* @param <T> 该方法支持泛型
* @return 泛型(不确定的类型)
*/
public static <T> T createObject(String className) throws Exception {
Class<?> clazz = Class.forName(className);
Constructor<?> structor = clazz.getDeclaredConstructor();
return (T)structor.newInstance();
}
/**
* 使用反射创建带有参数对象
* @param className 以字符串表示的类名称通常是包名+类名
* @param params 参数类型列表
* @param values 参数实际值列表
* @param <T> 方法支持泛型
* @return 返回结果是泛型(不确定的类型)
*/
public static <T> T createObject(String className,Class<?>[] params,Object... values) throws Exception{
Class<?> clazz = Class.forName(className);
Constructor<?> struct = clazz.getDeclaredConstructor(params);
return (T)struct.newInstance(values);
}
/**
*
* 使用反射完成方法调用(无参)
* 步骤
* 1 根据方法名称获取方法签名(信息)
* 2 使用反射调用方法
* @param type 对象的实例
* @param methodName 方法名称
* 备注该方法支持两个泛型
* T 参数是一个泛型类型
* R 返回值是一个泛型
*/
public static <T,R> R invokeMethod(T type,String methodName) throws Exception {
Class<?> clazz = type.getClass();
// 根据方法名称获取方法签名
Method method = clazz.getDeclaredMethod(methodName);
return (R)method.invoke(type);
}
/**
* 使用反射调用带有参数的方法
* 步骤
* 1 获取Class对象
* 2 根据方法名称获取方法签名
* 3 调用Method的invoke方法完成方法调用并填写参数类型和参数名称
* 4 返回方法调用的结果
* @param obj 反射创建的对象
* @param methodName 方法名称
* @param params 参数类型列表
* @param value 参数值列表
* @param <T> 参数支持泛型
* @param <R> 返回值支持泛型
* @return 返回方法调用的结果
*/
public static <T,R> R invokeMethod(T obj,String methodName,Class[] params,Object...value) throws Exception{
Class<?> clazz = obj.getClass();
Method method = clazz.getDeclaredMethod(methodName, params);
// 编译错误invoke方法返回Object类型但是我定义的方法返回R需要将返回类型强制转换为R类型
// return method.invoke(type,value);
return (R) method.invoke(obj,value);
}
/**
* 使用反射访问私有属性(暴力破解)
* 步骤
* 1 获取Class对象
* 2 根据属性名称获取属性签名Field
* 3 设置属性签名的可访问性为true
* 4 调用set方法访问私有属性(为私有属性赋值)
* @param obj 对象
* @param fieldName 属性名称
* @param value 属性值
* @param <T> 参数支持泛型此时表示参数类型不确定
* @throws Exception
*/
public static <T> void accessField(T obj,String fieldName,String value) throws Exception {
Class<?> clazz = obj.getClass();
Field stuNameField = clazz.getDeclaredField(fieldName);
// 设置属性可访问性为true就能够访问私有属性
stuNameField.setAccessible(true);
// 为私有属性赋值
stuNameField.set(obj,value);
}
}
Loading…
Cancel
Save