Browse Source

no message

FengChaoYu 1 month ago
parent
commit
f0cbbaaa81

+ 54 - 53
src/main/java/com/gree/mall/manager/config/aop/ZfireFiledAop.java

@@ -53,11 +53,12 @@ public class ZfireFiledAop {
 
 
     @Pointcut("@annotation(com.gree.mall.manager.annotation.ZfireList)")
-    public void auth() {}
+    public void auth() {
+    }
 
-    @AfterReturning(value = "auth()",returning = "result")
+    @AfterReturning(value = "auth()", returning = "result")
     public void doAfter(JoinPoint joinPoint, Object result) throws Exception {
-        start(joinPoint,result);
+        start(joinPoint, result);
     }
 
     @Before("auth()")
@@ -71,6 +72,7 @@ public class ZfireFiledAop {
 
     /**
      * 解析返回值{@code ResponseHelper<IPage<Obj>>}中的Obj的类型
+     *
      * @param zfireParam
      * @param joinPoint
      */
@@ -116,20 +118,20 @@ public class ZfireFiledAop {
 
     /**
      * {
-     * 	moduleId:"菜单id"      //不为空
-     * 	jName:"java字段名"     //前端渲染使用的字段名,不为空
-     * 	label:"字段title"      //字段标题
-     * 	placeholder:"提示语"
-     * 	type:"输入类型【input/select】"
-     * 	option:[{
-     * 		value:"",
-     * 		name:""
-     *        }]
-     * 	multiple:true          //true=多选,false=单选
-     * 	frontCode:""           //前端预留code,由前端自定义,默认为空
-     * 	sortNum:1              //排序字段
-     * 	tbName:"表名"          //可能为空(查询组装参数用)
-     * 	colName:"字段名"       //可能为空(查询组装参数用)
+     * moduleId:"菜单id"      //不为空
+     * jName:"java字段名"     //前端渲染使用的字段名,不为空
+     * label:"字段title"      //字段标题
+     * placeholder:"提示语"
+     * type:"输入类型【input/select】"
+     * option:[{
+     * value:"",
+     * name:""
+     * }]
+     * multiple:true          //true=多选,false=单选
+     * frontCode:""           //前端预留code,由前端自定义,默认为空
+     * sortNum:1              //排序字段
+     * tbName:"表名"          //可能为空(查询组装参数用)
+     * colName:"字段名"       //可能为空(查询组装参数用)
      * }
      */
     private void start(JoinPoint joinPoint, Object result) throws Exception {
@@ -141,15 +143,15 @@ public class ZfireFiledAop {
         //当前用户id
         String adminUserId = CommonUtils.getUserId(request);
 
-        if(!(result instanceof ResponseHelper)){
+        if (!(result instanceof ResponseHelper)) {
             return;
         }
-        ResponseHelper responseHelper = (ResponseHelper)result;
-        if(responseHelper.getCode() != ResponseHelper.ResponseCode_Success){
+        ResponseHelper responseHelper = (ResponseHelper) result;
+        if (responseHelper.getCode() != ResponseHelper.ResponseCode_Success) {
             return;
         }
         Object data = responseHelper.getData();
-        if(!(data instanceof Page)){
+        if (!(data instanceof Page)) {
             return;
         }
         Page page = (Page) data;
@@ -157,7 +159,7 @@ public class ZfireFiledAop {
         //当前菜单当前用户的配置
         Map<String, AdminField> fieldMap = adminFieldService.lambdaQuery()
                 .eq(AdminField::getAdminUserId, adminUserId)
-                .eq(AdminField::getModuleId,moduleId)
+                .eq(AdminField::getModuleId, moduleId)
                 .orderByAsc(AdminField::getSortNum)
                 .list()
                 .stream()
@@ -165,11 +167,11 @@ public class ZfireFiledAop {
 
         //返回的内容的对象
         Object bean = null;
-        if(!CollectionUtils.isEmpty(records)){
+        if (!CollectionUtils.isEmpty(records)) {
             bean = records.get(0);
-        }else{
+        } else {
             records = new ArrayList<>();
-            List list1 = this.newInstance(records,responseHelper.typeReference);
+            List list1 = this.newInstance(records, responseHelper.typeReference);
             bean = list1.get(0);
             // records.getClass().getTypeName();
         }
@@ -183,7 +185,7 @@ public class ZfireFiledAop {
         List<AdminField> fieldBeans = new ArrayList<>();
         //反射获取返回对象中的属性
         Field[] fields = bean.getClass().getDeclaredFields();
-        for(Field field:fields){
+        for (Field field : fields) {
             field.setAccessible(true);
 
             AdminField fieldBean = this.getTbCol(field, fieldMap, tbName, bean);
@@ -195,7 +197,7 @@ public class ZfireFiledAop {
         }
         //排序
         fieldBeans = fieldBeans.stream()
-                .sorted(Comparator.comparing(AdminField::getSortNum,Comparator.nullsFirst(Integer::compareTo)))
+                .sorted(Comparator.comparing(AdminField::getSortNum, Comparator.nullsFirst(Integer::compareTo)))
                 .collect(Collectors.toList());
         //填充字段集
         responseHelper.setFieldBeans(fieldBeans);
@@ -220,9 +222,9 @@ public class ZfireFiledAop {
 
 
         Annotation[] annotations = field.getAnnotations();
-        for(Annotation annotation : annotations){
+        for (Annotation annotation : annotations) {
 
-            if(annotation instanceof ZfireField){
+            if (annotation instanceof ZfireField) {
                 ZfireField zfireField = (ZfireField) annotation;
                 String colName = zfireField.colName();
                 String tbName = zfireField.tbName();
@@ -251,21 +253,21 @@ public class ZfireFiledAop {
                 fieldBean.setMultiple(zfireField.multiple());
                 fieldBean.setIsCutting(zfireField.isCutting());
 
-            }else if(annotation instanceof ApiModelProperty){
+            } else if (annotation instanceof ApiModelProperty) {
                 ApiModelProperty property = (ApiModelProperty) annotation;
                 fieldBean.setLabel(property.value());
             }
         }
 
         //处理枚举类型
-        Map<String,String> enumMap = Maps.newHashMap();
-        if(field.getType().isEnum()) {
+        Map<String, String> enumMap = Maps.newHashMap();
+        if (field.getType().isEnum()) {
             for (Object enumO : field.getType().getEnumConstants()) {
                 Class<?> c = enumO.getClass();
                 if (!BaseEnum.class.isAssignableFrom(c)) {
                     break;
                 }
-                BaseEnum baseEnum = (BaseEnum)enumO;
+                BaseEnum baseEnum = (BaseEnum) enumO;
                 if (!hasJsonIgnoreAnnotation((Enum<?>) baseEnum)) {
                     enumMap.put(baseEnum.getKey(), baseEnum.getRemark());
                 }
@@ -276,21 +278,21 @@ public class ZfireFiledAop {
         fieldBean.setEnumMap(JSONObject.toJSONString(enumMap));
 
         //拿db的配置来覆盖默认的配置
-        if(fieldMap != null) {
+        if (fieldMap != null) {
             AdminField adminField = fieldMap.get(fieldName);
             if (adminField != null) {
-                BeanUtil.copyProperties(adminField, fieldBean, "label","frontCode","type", "hide", "enumMap","isQuery","pk","multiple","jName","colName","tbName","fixed");
+                BeanUtil.copyProperties(adminField, fieldBean, "label", "frontCode", "type", "hide", "enumMap", "isQuery", "pk", "multiple", "jName", "colName", "tbName", "fixed");
             }
         }
 
-        if(StringUtils.equals(typeName,"java.math.BigDecimal")){
+        if (StringUtils.equals(typeName, "java.math.BigDecimal")) {
             fieldBean.setType("amount");
-        }else if(fieldBean.getType().equals("input") && (StringUtils.equals(typeName,"java.util.Date") || StringUtils.equals(typeName,"java.time.LocalDateTime"))){
+        } else if (fieldBean.getType().equals("input") && (StringUtils.equals(typeName, "java.util.Date") || StringUtils.equals(typeName, "java.time.LocalDateTime"))) {
             fieldBean.setType("datetime");
-        }else if(StringUtils.equals(typeName,"java.lang.Integer")){
+        } else if (StringUtils.equals(typeName, "java.lang.Integer")) {
             fieldBean.setType("number");
         }
-        if(fieldBean.getSortNum() == null) {
+        if (fieldBean.getSortNum() == null) {
             fieldBean.setSortNum(999);
         }
         return fieldBean;
@@ -315,49 +317,48 @@ public class ZfireFiledAop {
 
 
     /**
-     * @author Howe
-     * @Description 将驼峰转为下划线
      * @param str
      * @return java.lang.String
-     * @Date   2022/4/22 13:11
-     * @since  1.0.0
+     * @author Howe
+     * @Description 将驼峰转为下划线
+     * @Date 2022/4/22 13:11
+     * @since 1.0.0
      */
     public static String xX2x_x(String str) {
         Pattern compile = Pattern.compile("[A-Z]");
         Matcher matcher = compile.matcher(str);
         StringBuffer sb = new StringBuffer();
-        while(matcher.find()) {
-            matcher.appendReplacement(sb,  "_" + matcher.group(0).toLowerCase());
+        while (matcher.find()) {
+            matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
         }
         matcher.appendTail(sb);
         return sb.toString();
     }
 
     /**
-     * @author Howe
-     * @Description 将下划线转为驼峰
      * @param str
      * @return java.lang.String
-     * @Date   2022/4/22 13:12
-     * @since  1.0.0
+     * @author Howe
+     * @Description 将下划线转为驼峰
+     * @Date 2022/4/22 13:12
+     * @since 1.0.0
      */
     public static String x_x2xX(String str) {
         str = str.toLowerCase();
         Pattern compile = Pattern.compile("_[a-z]");
         Matcher matcher = compile.matcher(str);
         StringBuffer sb = new StringBuffer();
-        while(matcher.find()) {
-            matcher.appendReplacement(sb,  matcher.group(0).toUpperCase().replace("_",""));
+        while (matcher.find()) {
+            matcher.appendReplacement(sb, matcher.group(0).toUpperCase().replace("_", ""));
         }
         matcher.appendTail(sb);
         return sb.toString();
     }
 
 
-
     public <T> List newInstance(List<T> list, TypeReference<T> typeReference) throws IllegalAccessException, InstantiationException {
         Type tp = typeReference.getClass().getGenericSuperclass();
-        Class<T> type = (Class<T>)((ParameterizedType) tp).getActualTypeArguments()[0];
+        Class<T> type = (Class<T>) ((ParameterizedType) tp).getActualTypeArguments()[0];
         T t = type.newInstance();
         list.add(t);
         return list;

+ 4 - 0
src/main/java/com/gree/mall/manager/helper/ResponseHelper.java

@@ -92,4 +92,8 @@ public class ResponseHelper<T> {
         this.fieldBeans = fieldBeans;
     }
 
+    public List<AdminField> getFieldBeans() {
+        return this.fieldBeans;
+    }
+
 }