mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 10:57:13 +08:00 
			
		
		
		
	chore: continew-starter 2.3.0 => 2.4.0
1.IBaseEnum => BaseEnum 2.移除 Jackson BaseEnum 配置(已迁移到 Starter 项目) 3.修复导出报错 4.接口文档枚举显示增强
This commit is contained in:
		| @@ -1,76 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
|  | ||||
| package top.continew.admin.common.config.jackson; | ||||
|  | ||||
| import cn.hutool.core.util.ClassUtil; | ||||
| import cn.hutool.core.util.ReflectUtil; | ||||
| import com.fasterxml.jackson.core.JsonParser; | ||||
| import com.fasterxml.jackson.databind.DeserializationContext; | ||||
| import com.fasterxml.jackson.databind.JsonDeserializer; | ||||
| import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; | ||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.lang.reflect.Field; | ||||
|  | ||||
| /** | ||||
|  * 通用枚举接口 IBaseEnum 反序列化器 | ||||
|  * | ||||
|  * @author Charles7c | ||||
|  * @see IBaseEnum | ||||
|  * @since 2023/1/8 13:56 | ||||
|  */ | ||||
| @JacksonStdImpl | ||||
| public class BaseEnumDeserializer extends JsonDeserializer<IBaseEnum> { | ||||
|  | ||||
|     /** | ||||
|      * 静态实例 | ||||
|      */ | ||||
|     public static final BaseEnumDeserializer SERIALIZER_INSTANCE = new BaseEnumDeserializer(); | ||||
|  | ||||
|     @Override | ||||
|     public IBaseEnum deserialize(JsonParser jsonParser, | ||||
|                                  DeserializationContext deserializationContext) throws IOException { | ||||
|         Class<?> targetClass = jsonParser.getCurrentValue().getClass(); | ||||
|         String fieldName = jsonParser.getCurrentName(); | ||||
|         String value = jsonParser.getText(); | ||||
|         return this.getEnum(targetClass, value, fieldName); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 通过某字段对应值获取枚举实例,获取不到时为 {@code null} | ||||
|      * | ||||
|      * @param targetClass 目标类型 | ||||
|      * @param value       字段值 | ||||
|      * @param fieldName   字段名 | ||||
|      * @return 对应枚举实例 ,获取不到时为 {@code null} | ||||
|      */ | ||||
|     private IBaseEnum getEnum(Class<?> targetClass, String value, String fieldName) { | ||||
|         Field field = ReflectUtil.getField(targetClass, fieldName); | ||||
|         Class<?> fieldTypeClass = field.getType(); | ||||
|         Object[] enumConstants = fieldTypeClass.getEnumConstants(); | ||||
|         for (Object enumConstant : enumConstants) { | ||||
|             if (ClassUtil.isAssignable(IBaseEnum.class, fieldTypeClass)) { | ||||
|                 IBaseEnum baseEnum = (IBaseEnum)enumConstant; | ||||
|                 if (baseEnum.getValue().equals(Integer.valueOf(value))) { | ||||
|                     return baseEnum; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
| @@ -1,46 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
|  | ||||
| package top.continew.admin.common.config.jackson; | ||||
|  | ||||
| import com.fasterxml.jackson.core.JsonGenerator; | ||||
| import com.fasterxml.jackson.databind.JsonSerializer; | ||||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||||
| import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; | ||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * 通用枚举接口 IBaseEnum 序列化器 | ||||
|  * | ||||
|  * @author Charles7c | ||||
|  * @see IBaseEnum | ||||
|  * @since 2023/1/8 13:56 | ||||
|  */ | ||||
| @JacksonStdImpl | ||||
| public class BaseEnumSerializer extends JsonSerializer<IBaseEnum> { | ||||
|  | ||||
|     /** | ||||
|      * 静态实例 | ||||
|      */ | ||||
|     public static final BaseEnumSerializer SERIALIZER_INSTANCE = new BaseEnumSerializer(); | ||||
|  | ||||
|     @Override | ||||
|     public void serialize(IBaseEnum value, JsonGenerator generator, SerializerProvider serializers) throws IOException { | ||||
|         generator.writeObject(value.getValue()); | ||||
|     } | ||||
| } | ||||
| @@ -1,54 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
|  | ||||
| package top.continew.admin.common.config.jackson; | ||||
|  | ||||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||||
| import com.fasterxml.jackson.databind.module.SimpleModule; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | ||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
|  | ||||
| /** | ||||
|  * Jackson 配置 | ||||
|  * | ||||
|  * @author Charles7c | ||||
|  * @see IBaseEnum | ||||
|  * @since 2022/12/11 13:23 | ||||
|  */ | ||||
| @Slf4j | ||||
| @Configuration | ||||
| public class JacksonConfiguration { | ||||
|  | ||||
|     /** | ||||
|      * 针对枚举接口 IBaseEnum 的序列化和反序列化 | ||||
|      */ | ||||
|     @Bean | ||||
|     public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) { | ||||
|         SimpleModule simpleModule = new SimpleModule(); | ||||
|         simpleModule.addSerializer(IBaseEnum.class, BaseEnumSerializer.SERIALIZER_INSTANCE); | ||||
|  | ||||
|         SimpleDeserializersWrapper deserializers = new SimpleDeserializersWrapper(); | ||||
|         deserializers.addDeserializer(IBaseEnum.class, BaseEnumDeserializer.SERIALIZER_INSTANCE); | ||||
|         simpleModule.setDeserializers(deserializers); | ||||
|  | ||||
|         ObjectMapper objectMapper = builder.createXmlMapper(false).build(); | ||||
|         objectMapper.registerModule(simpleModule); | ||||
|         return objectMapper; | ||||
|     } | ||||
| } | ||||
| @@ -1,68 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
|  | ||||
| package top.continew.admin.common.config.jackson; | ||||
|  | ||||
| import com.fasterxml.jackson.databind.BeanDescription; | ||||
| import com.fasterxml.jackson.databind.DeserializationConfig; | ||||
| import com.fasterxml.jackson.databind.JsonDeserializer; | ||||
| import com.fasterxml.jackson.databind.JsonMappingException; | ||||
| import com.fasterxml.jackson.databind.module.SimpleDeserializers; | ||||
| import com.fasterxml.jackson.databind.type.ClassKey; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
|  | ||||
| /** | ||||
|  * 反序列化器包装类(重写 Jackson 反序列化枚举方法,参阅:FasterXML/jackson-databind#2842) | ||||
|  * | ||||
|  * <p> | ||||
|  * 默认处理:<br> | ||||
|  * 1. Jackson 会先查找指定枚举类型对应的反序列化器(例如:GenderEnum 枚举类型,则是找 GenderEnum 枚举类型的对应反序列化器);<br> | ||||
|  * 2. 如果找不到则开始查找 Enum 类型(所有枚举父类)的反序列化器;<br> | ||||
|  * 3. 如果都找不到则会采用默认的枚举反序列化器(它仅能根据枚举类型的 name、ordinal 来进行反序列化)。 | ||||
|  * </p> | ||||
|  * <p> | ||||
|  * 重写增强后:<br> | ||||
|  * 1. 同默认 1;<br> | ||||
|  * 2. 同默认 2;<br> | ||||
|  * 3. 如果也找不到 Enum 类型(所有枚举父类)的反序列化器,开始查找指定枚举类型的接口的反序列化器(例如:GenderEnum 枚举类型,则是找它的接口 IBaseEnum 的反序列化器);<br> | ||||
|  * 4. 同默认 3。 | ||||
|  * </p> | ||||
|  * | ||||
|  * @author Charles7c | ||||
|  * @since 2023/1/8 13:28 | ||||
|  */ | ||||
| @Slf4j | ||||
| public class SimpleDeserializersWrapper extends SimpleDeserializers { | ||||
|  | ||||
|     @Override | ||||
|     public JsonDeserializer<?> findEnumDeserializer(Class<?> type, | ||||
|                                                     DeserializationConfig config, | ||||
|                                                     BeanDescription beanDesc) throws JsonMappingException { | ||||
|         JsonDeserializer<?> deser = super.findEnumDeserializer(type, config, beanDesc); | ||||
|         if (null != deser) { | ||||
|             return deser; | ||||
|         } | ||||
|  | ||||
|         // 重写增强:开始查找指定枚举类型的接口的反序列化器(例如:GenderEnum 枚举类型,则是找它的接口 BaseEnum 的反序列化器) | ||||
|         for (Class<?> typeInterface : type.getInterfaces()) { | ||||
|             deser = this._classMappings.get(new ClassKey(typeInterface)); | ||||
|             if (null != deser) { | ||||
|                 return deser; | ||||
|             } | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
| @@ -18,7 +18,7 @@ package top.continew.admin.common.enums; | ||||
|  | ||||
| import lombok.Getter; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
| import top.continew.starter.core.enums.BaseEnum; | ||||
|  | ||||
| /** | ||||
|  * 数据权限枚举 | ||||
| @@ -28,7 +28,7 @@ import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
|  */ | ||||
| @Getter | ||||
| @RequiredArgsConstructor | ||||
| public enum DataScopeEnum implements IBaseEnum<Integer> { | ||||
| public enum DataScopeEnum implements BaseEnum<Integer> { | ||||
|  | ||||
|     /** | ||||
|      * 全部数据权限 | ||||
|   | ||||
| @@ -19,7 +19,7 @@ package top.continew.admin.common.enums; | ||||
| import lombok.Getter; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import top.continew.admin.common.constant.UiConstants; | ||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
| import top.continew.starter.core.enums.BaseEnum; | ||||
|  | ||||
| /** | ||||
|  * 启用/禁用状态枚举 | ||||
| @@ -29,7 +29,7 @@ import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
|  */ | ||||
| @Getter | ||||
| @RequiredArgsConstructor | ||||
| public enum DisEnableStatusEnum implements IBaseEnum<Integer> { | ||||
| public enum DisEnableStatusEnum implements BaseEnum<Integer> { | ||||
|  | ||||
|     /** | ||||
|      * 启用 | ||||
|   | ||||
| @@ -18,7 +18,7 @@ package top.continew.admin.common.enums; | ||||
|  | ||||
| import lombok.Getter; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
| import top.continew.starter.core.enums.BaseEnum; | ||||
|  | ||||
| /** | ||||
|  * 性别枚举 | ||||
| @@ -28,7 +28,7 @@ import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
|  */ | ||||
| @Getter | ||||
| @RequiredArgsConstructor | ||||
| public enum GenderEnum implements IBaseEnum<Integer> { | ||||
| public enum GenderEnum implements BaseEnum<Integer> { | ||||
|  | ||||
|     /** | ||||
|      * 未知 | ||||
|   | ||||
| @@ -18,7 +18,7 @@ package top.continew.admin.common.enums; | ||||
|  | ||||
| import lombok.Getter; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
| import top.continew.starter.core.enums.BaseEnum; | ||||
|  | ||||
| /** | ||||
|  * 菜单类型枚举 | ||||
| @@ -28,7 +28,7 @@ import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
|  */ | ||||
| @Getter | ||||
| @RequiredArgsConstructor | ||||
| public enum MenuTypeEnum implements IBaseEnum<Integer> { | ||||
| public enum MenuTypeEnum implements BaseEnum<Integer> { | ||||
|  | ||||
|     /** | ||||
|      * 目录 | ||||
|   | ||||
| @@ -19,7 +19,7 @@ package top.continew.admin.common.enums; | ||||
| import lombok.Getter; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import top.continew.admin.common.constant.UiConstants; | ||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
| import top.continew.starter.core.enums.BaseEnum; | ||||
|  | ||||
| /** | ||||
|  * 消息类型枚举 | ||||
| @@ -29,7 +29,7 @@ import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
|  */ | ||||
| @Getter | ||||
| @RequiredArgsConstructor | ||||
| public enum MessageTypeEnum implements IBaseEnum<Integer> { | ||||
| public enum MessageTypeEnum implements BaseEnum<Integer> { | ||||
|  | ||||
|     /** | ||||
|      * 安全消息 | ||||
|   | ||||
| @@ -19,7 +19,7 @@ package top.continew.admin.common.enums; | ||||
| import lombok.Getter; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import top.continew.admin.common.constant.UiConstants; | ||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
| import top.continew.starter.core.enums.BaseEnum; | ||||
|  | ||||
| /** | ||||
|  * 成功/失败状态枚举 | ||||
| @@ -29,7 +29,7 @@ import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | ||||
|  */ | ||||
| @Getter | ||||
| @RequiredArgsConstructor | ||||
| public enum SuccessFailureStatusEnum implements IBaseEnum<Integer> { | ||||
| public enum SuccessFailureStatusEnum implements BaseEnum<Integer> { | ||||
|  | ||||
|     /** | ||||
|      * 成功 | ||||
|   | ||||
| @@ -30,6 +30,7 @@ import top.continew.starter.core.util.ExceptionUtils; | ||||
| import top.continew.starter.core.util.IpUtils; | ||||
| import top.continew.starter.extension.crud.service.CommonUserService; | ||||
| import top.continew.starter.web.util.ServletUtils; | ||||
| import top.continew.starter.web.util.SpringWebUtils; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| @@ -53,7 +54,7 @@ public class LoginHelper { | ||||
|      */ | ||||
|     public static String login(LoginUser loginUser) { | ||||
|         // 记录登录信息 | ||||
|         HttpServletRequest request = ServletUtils.getRequest(); | ||||
|         HttpServletRequest request = SpringWebUtils.getRequest(); | ||||
|         loginUser.setIp(JakartaServletUtil.getClientIP(request)); | ||||
|         loginUser.setAddress(ExceptionUtils.exToNull(() -> IpUtils.getIpv4Address(loginUser.getIp()))); | ||||
|         loginUser.setBrowser(ServletUtils.getBrowser(request)); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user