|
|
@@ -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;
|
|
|
+ }
|
|
|
+}
|