diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java index 8fb5d6e..1e319c8 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/controller/ArchivesTypeController.java @@ -28,7 +28,6 @@ public class ArchivesTypeController { private final ArchivesTypeService archivesTypeService; - @ApiOperation("门类类型") @AnonymousGetMapping("dropdown-list") public ApiResponse getType() { @@ -46,7 +45,7 @@ public class ArchivesTypeController { @AnonymousPostMapping("create") //TODO:权限未添加 public ApiResponse save(@RequestBody ArchivesTypeDTO archivesTypeDTO) { - if (!archivesTypeDTO.getId().isEmpty()) { + if (archivesTypeDTO.getId() != null) { throw new BaseException("this is not empty Data"); } if (archivesTypeDTO.getIsType() == null) { @@ -60,9 +59,9 @@ public class ArchivesTypeController { } @ApiOperation("获取门类树状菜单") - @AnonymousGetMapping("menuTree") + @AnonymousGetMapping("menu") //TODO:权限未添加 - public ApiResponse getMenuTree(){ + public ApiResponse getMenuTree() { return ApiResponse.success(archivesTypeService.buildTree()); } } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java b/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java index 164b73a..1f4494b 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesType.java +++ b/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") @ApiModelProperty(value = "是否为模板档案") - private Integer isTypeMetic; + private Boolean isTypeMetic; @Column(name = "category_seq") @ApiModelProperty(value = "排序") diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java index 7e80d6f..ee1d605 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/dto/ArchivesTypeDTO.java +++ b/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 isTypeMetic; + private Boolean isTypeMetic; private Integer categorySeq; diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java index c73c9fd..881a968 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DynamicTableImpl.java @@ -34,7 +34,7 @@ public class DynamicTableImpl implements DynamicTableService { @Override - public void DynamicCreate(Integer type, String archiveTypeId,String tableName) { + public void DynamicCreate(Integer type, String archiveTypeId, String tableName) { List integerList = new ArrayList<>(); if (type == 4 || type == 5) { integerList.add(1); @@ -47,6 +47,7 @@ public class DynamicTableImpl implements DynamicTableService { integerList.add(3); List fileList = queryList(integerList); DynamicInsert(fileList, archiveTypeId); + fileTableName += DateUtils.getNowDateTime(); DynamicCreateFileTable(fileList, fileTableName); } else { @@ -94,11 +95,11 @@ public class DynamicTableImpl implements DynamicTableService { archivesDictionaryDTO.setIsSystem(j.getIsSystem()); newList.add(archivesDictionaryDTO); } - archivesDictionaryService.saveAll(newList); + archivesDictionaryService.saveAll(newList); } private void DynamicCreateFileTable(List list, String tableName) { - tableName += DateUtils.getNowDateTime(); + List> maps = ArchivesListToMap.getMaps(list); StringBuilder stringBuilder = new StringBuilder("create table " + tableName + " (id varchar(100) primary key,"); for (int i = 0; i < maps.size(); i++) { @@ -115,6 +116,6 @@ public class DynamicTableImpl implements DynamicTableService { stringBuilder.append(")"); } } - jdbcTemplate.execute(stringBuilder.toString()); + jdbcTemplate.execute(stringBuilder.toString()); } } diff --git a/common/src/main/java/com/storeroom/utils/ApiResponse.java b/common/src/main/java/com/storeroom/utils/ApiResponse.java index ae224fa..1e51008 100644 --- a/common/src/main/java/com/storeroom/utils/ApiResponse.java +++ b/common/src/main/java/com/storeroom/utils/ApiResponse.java @@ -4,6 +4,8 @@ package com.storeroom.utils; import com.storeroom.exception.constant.ResponseStatus; import lombok.Data; +import java.time.LocalDateTime; + /** * 通用的 API 接口封装 */ diff --git a/common/src/main/java/com/storeroom/utils/ReflectUtils.java b/common/src/main/java/com/storeroom/utils/ReflectUtils.java new file mode 100644 index 0000000..d49fbcd --- /dev/null +++ b/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 该方法支持泛型 + * @return 泛型(不确定的类型) + */ + public static 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 方法支持泛型 + * @return 返回结果是泛型(不确定的类型) + */ + public static 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 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 参数支持泛型 + * @param 返回值支持泛型 + * @return 返回方法调用的结果 + */ + public static 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 参数支持泛型,此时表示参数类型不确定 + * @throws Exception + */ + public static 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); + } +}