Просмотр исходного кода

Add 添加类目的自动翻译功能

Yue 2 лет назад
Родитель
Сommit
3fb11352ec

+ 1 - 1
SERVER/YanZhongXYH/xyh-common/src/main/java/cn/xyh/common/constant/TransConstant.java

@@ -22,5 +22,5 @@ public interface TransConstant {
      */
     String DICT_TYPE_TO_LABEL = "dict_type_to_label";
 
-
+    String CATEGORY_ID_TO_NAME = "category_id_to_name";
 }

+ 15 - 0
SERVER/YanZhongXYH/xyh-common/src/main/java/cn/xyh/common/core/service/ICategoryService.java

@@ -0,0 +1,15 @@
+package cn.xyh.common.core.service;
+
+/**
+ * 通用 类目服务
+ *
+ * @author Yue
+ */
+public interface ICategoryService {
+
+    /**
+     * 通过类目ID查询用户账户
+     */
+    String selectNameById(Long id);
+
+}

+ 2 - 0
SERVER/YanZhongXYH/xyh-common/src/main/java/cn/xyh/common/core/service/IUserService.java

@@ -16,3 +16,5 @@ public interface IUserService {
     String selectUserNameById(Long userId);
 
 }
+
+

+ 35 - 0
SERVER/YanZhongXYH/xyh-common/src/main/java/cn/xyh/common/translation/impl/CategoryNameTranslationImpl.java

@@ -0,0 +1,35 @@
+package cn.xyh.common.translation.impl;
+
+import cn.xyh.common.annotation.TranslationType;
+import cn.xyh.common.constant.TransConstant;
+import cn.xyh.common.core.service.ICategoryService;
+import cn.xyh.common.translation.TranslationInterface;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Component;
+
+/**
+ * 用户名翻译实现
+ *
+ * @author Yue
+ */
+@Component
+@AllArgsConstructor
+@TranslationType(type = TransConstant.CATEGORY_ID_TO_NAME)
+public class CategoryNameTranslationImpl implements TranslationInterface<String> {
+
+    private final ICategoryService categoryService;
+
+    @Override
+    public String translation(Object key, String other) {
+        if (key instanceof Long) {
+            return categoryService.selectNameById((Long) key);
+        } else if (key instanceof String) {
+            try {
+                return categoryService.selectNameById(Long.parseLong((String) key));
+            } catch (NumberFormatException e) {
+                return null;
+            }
+        }
+        return null;
+    }
+}