From 12bfe3a9f4922855b1e63b113157454edd72d089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Mon, 22 May 2023 11:25:26 +0800 Subject: [PATCH] =?UTF-8?q?remove=20=E7=A7=BB=E9=99=A4=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dict/annotation/DictDataMapper.java | 29 ---------- .../dict/jackson/DictDataJsonSerializer.java | 58 ------------------- 2 files changed, 87 deletions(-) delete mode 100644 ruoyi-common/ruoyi-common-dict/src/main/java/org/dromara/common/dict/annotation/DictDataMapper.java delete mode 100644 ruoyi-common/ruoyi-common-dict/src/main/java/org/dromara/common/dict/jackson/DictDataJsonSerializer.java diff --git a/ruoyi-common/ruoyi-common-dict/src/main/java/org/dromara/common/dict/annotation/DictDataMapper.java b/ruoyi-common/ruoyi-common-dict/src/main/java/org/dromara/common/dict/annotation/DictDataMapper.java deleted file mode 100644 index a575c181..00000000 --- a/ruoyi-common/ruoyi-common-dict/src/main/java/org/dromara/common/dict/annotation/DictDataMapper.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.dromara.common.dict.annotation; - -import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import org.dromara.common.dict.jackson.DictDataJsonSerializer; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 字典数据映射注解 - * - * @author itino - * @deprecated 建议使用通用翻译注解 - */ -@Deprecated -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD, ElementType.METHOD}) -@JacksonAnnotationsInside -@JsonSerialize(using = DictDataJsonSerializer.class) -public @interface DictDataMapper { - - /** - * 设置字典的type值 (如: sys_user_sex) - */ - String dictType() default ""; -} diff --git a/ruoyi-common/ruoyi-common-dict/src/main/java/org/dromara/common/dict/jackson/DictDataJsonSerializer.java b/ruoyi-common/ruoyi-common-dict/src/main/java/org/dromara/common/dict/jackson/DictDataJsonSerializer.java deleted file mode 100644 index e66e6e27..00000000 --- a/ruoyi-common/ruoyi-common-dict/src/main/java/org/dromara/common/dict/jackson/DictDataJsonSerializer.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.dromara.common.dict.jackson; - -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.ContextualSerializer; -import org.dromara.common.core.service.DictService; -import org.dromara.common.core.utils.SpringUtils; -import org.dromara.common.core.utils.StringUtils; -import org.dromara.common.dict.annotation.DictDataMapper; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeansException; - -import java.io.IOException; -import java.util.Objects; - -/** - * 字典数据json序列化工具 - * - * @author itino - * @deprecated 建议使用通用翻译注解 - */ -@Deprecated -@Slf4j -public class DictDataJsonSerializer extends JsonSerializer implements ContextualSerializer { - - private String dictType; - - @Override - public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - try { - DictService dictService = SpringUtils.getBean(DictService.class); - if (ObjectUtil.isNotNull(dictService)) { - String label = dictService.getDictLabel(dictType, value); - gen.writeString(StringUtils.isNotBlank(label) ? label : value); - } else { - gen.writeString(value); - } - } catch (BeansException e) { - log.error("字典数据未查到, 采用默认处理 => {}", e.getMessage()); - gen.writeString(value); - } - } - - @Override - public JsonSerializer createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException { - DictDataMapper anno = property.getAnnotation(DictDataMapper.class); - if (Objects.nonNull(anno) && StrUtil.isNotBlank(anno.dictType())) { - this.dictType = anno.dictType(); - return this; - } - return prov.findValueSerializer(property.getType(), property); - } -}