|
@@ -0,0 +1,48 @@
|
|
|
+package com.customs.cq.datacenter.host.web.controller.common;
|
|
|
+
|
|
|
+import com.customs.cq.datacenter.common.ExecutedResult;
|
|
|
+import com.customs.cq.datacenter.common.core.controller.BasicController;
|
|
|
+import com.customs.cq.datacenter.common.model.NameValueDto;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 140.基础功能
|
|
|
+ * @order 140
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("base")
|
|
|
+public class BaseController extends BasicController {
|
|
|
+ /**
|
|
|
+ * 获取指定枚举类型的所有值
|
|
|
+ * @param enumName 枚举类型名称
|
|
|
+ */
|
|
|
+ @GetMapping("listEnumValue/{enumName}")
|
|
|
+ public ExecutedResult<List<NameValueDto>> listEnumValue(@PathVariable String enumName) {
|
|
|
+ try {
|
|
|
+ Class<?> enumClass = Class.forName("com.customs.cq.datacenter.common.enums." + enumName);
|
|
|
+ Method valuesMethod = enumClass.getMethod("values");
|
|
|
+ Method getValueMethod = enumClass.getMethod("getValue");
|
|
|
+ Method getDescMethod = enumClass.getMethod("getDesc");
|
|
|
+
|
|
|
+ Object valuesObj = valuesMethod.invoke(enumClass);
|
|
|
+ Object[] values = (Object[]) valuesObj;
|
|
|
+
|
|
|
+ List<NameValueDto> result = new ArrayList<>();
|
|
|
+ for(Object c : values) {
|
|
|
+ String value = getValueMethod.invoke(c).toString();
|
|
|
+ String desc = getDescMethod.invoke(c).toString();
|
|
|
+ result.add(new NameValueDto(desc, value));
|
|
|
+ }
|
|
|
+ return ExecutedResult.success(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return ExecutedResult.failed("获取枚举类型失败(" + enumName + "): " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|