add
yj
2024-12-05 b9900893177c78fc559223521fe839aa21000017
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
package com.dobbinsoft.fw.launcher.manager;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dobbinsoft.fw.core.Const;
import com.dobbinsoft.fw.core.annotation.HttpMethod;
import com.dobbinsoft.fw.core.annotation.HttpOpenApi;
import com.dobbinsoft.fw.core.annotation.HttpParam;
import com.dobbinsoft.fw.core.annotation.doc.ApiEntity;
import com.dobbinsoft.fw.core.annotation.doc.ApiField;
import com.dobbinsoft.fw.core.annotation.param.NotNull;
import com.dobbinsoft.fw.core.enums.BaseEnums;
import com.dobbinsoft.fw.core.enums.EmptyEnums;
import com.dobbinsoft.fw.core.exception.ServiceException;
import com.dobbinsoft.fw.launcher.exception.LauncherExceptionDefinition;
import com.dobbinsoft.fw.launcher.exception.LauncherServiceException;
import com.dobbinsoft.fw.launcher.inter.AfterRegisterApiComplete;
import com.dobbinsoft.fw.support.model.PermissionPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
 
import java.lang.reflect.*;
import java.util.*;
 
/**
 * Created with IntelliJ IDEA.
 * Description: 集群版 ApiManager 实现
 * User: rize
 * Date: 2018-08-08
 * Time: 下午10:52
 */
@Component
public class ClusterApiManager implements InitializingBean, ApplicationContextAware, IApiManager {
 
    private static final Logger logger = LoggerFactory.getLogger(ClusterApiManager.class);
 
    private Map<String, Map<String, Method>> methodCacheMap = new HashMap<>();
 
    private Map<String, String> groupDescCacheMap = new HashMap<>();
 
    private ApplicationContext applicationContext;
 
    private List<PermissionPoint> permDTOs = new LinkedList<>();
 
    private Set<Class> interfaceClassList = new TreeSet<>(Comparator.comparing(Class::getName));
 
    private Map<String, String> permissionRouteMap = new HashMap<>();
 
    private ApiDocumentModel apiDocumentModelCache = null;
 
    private ApiDocumentModel openApiDocumentModelCache = null;
 
    @Autowired(required = false)
    private AfterRegisterApiComplete afterRegisterApiComplete;
 
    @Override
    public void afterPropertiesSet() throws Exception {
        List<Class> classList = new LinkedList<>();
        String[] beanArray = applicationContext.getBeanNamesForAnnotation(Service.class);
        for (String service : beanArray) {
            Object bean = applicationContext.getBean(service);
            String className = bean.toString().split("@")[0];
            Class<?> serviceClazz = Class.forName(className);
            Class<?>[] interfaces = serviceClazz.getInterfaces();
            if (interfaces != null && interfaces.length > 0) {
                for (Class clazz : interfaces) {
                    if (clazz.getAnnotation(HttpOpenApi.class) != null) {
                        classList.add(clazz);
                    }
                }
            }
        }
        for (Class clazz : classList) {
            this.registerService(clazz);
        }
        if (afterRegisterApiComplete != null) {
            afterRegisterApiComplete.after(permDTOs);
        }
    }
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
 
    private void registerService(Class<?> targetClass) throws ServiceException {
        HttpOpenApi httpOpenApiAnnotation = targetClass.getDeclaredAnnotation(HttpOpenApi.class);
        if (httpOpenApiAnnotation != null) {
            interfaceClassList.add(targetClass);
            String group = httpOpenApiAnnotation.group();
            Method[] methods = targetClass.getMethods();
            Map<String, Method> tempMap = methodCacheMap.get(group);
            if (tempMap == null) {
                tempMap = new TreeMap<>();
                methodCacheMap.put(group, tempMap);
                groupDescCacheMap.put(group, httpOpenApiAnnotation.description());
            }
            for (Method method : methods) {
                HttpMethod httpMethod = method.getAnnotation(HttpMethod.class);
                if (httpMethod != null) {
                    String permission = httpMethod.permission();
                    if (!StringUtils.isEmpty(permission)) {
                        //若此接口需要权限
                        if (StringUtils.isEmpty(httpMethod.permissionParentName()) || StringUtils.isEmpty(httpMethod.permissionName())) {
                            throw new LauncherServiceException(LauncherExceptionDefinition.LAUNCHER_API_REGISTER_FAILED);
                        }
                        //迭代已有接口
                        boolean hasParent = false;
                        permDTOLoop:
                        for (PermissionPoint pointDTO : permDTOs) {
                            if (pointDTO.getLabel().equals(httpMethod.permissionParentName())) {
                                //若已经存在父分组,则将其追加在后面即可
                                hasParent = true;
                                addChildPermissionPoint(pointDTO, httpMethod, httpOpenApiAnnotation, method);
                                break permDTOLoop;
                            }
                        }
                        if (!hasParent) {
                            //若不存在父分组,则新建父分组
                            PermissionPoint parentDTO = new PermissionPoint();
                            parentDTO.setLabel(httpMethod.permissionParentName());
                            parentDTO.setId(httpMethod.permissionParentName());
                            parentDTO.setChildren(new LinkedList<>());
                            permDTOs.add(parentDTO);
                            //然后在parentDTO后面添加子类目,以及孙类目
                            addChildPermissionPoint(parentDTO, httpMethod, httpOpenApiAnnotation, method);
                        }
                    }
                    String key = method.getName();
                    Method methodQuery = tempMap.get(key);
                    if (methodQuery != null) {
                        throw new LauncherServiceException(LauncherExceptionDefinition.LAUNCHER_API_REGISTER_FAILED);
                    }
                    tempMap.put(key, method);
                    logger.info("[注册OpenApi] " + group + "." + method.getName());
                } else {
                    logger.info("[注册OpenApi 失败] 没有注解." + method.getName());
                }
 
            }
        } else {
            throw new LauncherServiceException(LauncherExceptionDefinition.LAUNCHER_API_REGISTER_FAILED);
        }
    }
 
    private void addChildPermissionPoint(PermissionPoint parentDTO, HttpMethod httpMethod, HttpOpenApi httpOpenApi, Method method) throws ServiceException {
        if (CollectionUtils.isEmpty(parentDTO.getChildren())) {
            parentDTO.setChildren(new LinkedList<>());
        }
 
        boolean hasChild = false;
 
        for (PermissionPoint childDTO : parentDTO.getChildren()) {
            if (childDTO.getLabel().equals(httpMethod.permissionName())) {
                //若存在
                hasChild = true;
                addGrandChildPermissionPoint(childDTO, httpMethod, httpOpenApi, method);
            }
        }
        if (!hasChild) {
            //添加child
            PermissionPoint childDTO = new PermissionPoint();
            childDTO.setId(httpMethod.permissionName());
            childDTO.setLabel(httpMethod.permissionName());
            childDTO.setChildren(new LinkedList<>());
            parentDTO.getChildren().add(childDTO);
            addGrandChildPermissionPoint(childDTO, httpMethod, httpOpenApi, method);
        }
 
 
    }
 
    private void addGrandChildPermissionPoint(PermissionPoint childDTO, HttpMethod httpMethod, HttpOpenApi httpOpenApi, Method method) throws ServiceException {
        //遍历权限点是否有重复
        for (PermissionPoint pointDTO : childDTO.getChildren()) {
            if (pointDTO.getId().equals(httpMethod.permission())) {
                //不允许重复权限点
//                throw new LauncherServiceException(LauncherExceptionDefinition.LAUNCHER_API_REGISTER_FAILED);
                return;
            }
        }
        //若无重复权限点
        PermissionPoint pointDTO = new PermissionPoint();
        permissionRouteMap.put(httpMethod.permission(), httpMethod.permissionParentName() + "-" + httpMethod.permissionName() + "-" + httpMethod.description());
        pointDTO.setId(httpMethod.permission());
        pointDTO.setLabel(httpMethod.description());
        pointDTO.setApi(httpOpenApi.group() + "." + method.getName());
        childDTO.getChildren().add(pointDTO);
    }
 
    @Override
    public Method getMethod(String app, String group, String name) {
        Map<String, Method> tempMap = methodCacheMap.get(group);
        if (tempMap != null) {
            return tempMap.get(name);
        }
        return null;
    }
 
    @Override
    public Object getServiceBean(Method method) {
        Object serviceBean = applicationContext.getBean(method.getDeclaringClass());
        return serviceBean;
    }
 
    @Override
    public Set<Class> getRegisteredInterfaces() {
        return this.interfaceClassList;
    }
 
    @Override
    public String getPermissionRoute(String permission) {
        return permissionRouteMap.get(permission);
    }
 
    @Override
    public List<PermissionPoint> getPermissions() {
        return this.permDTOs;
    }
 
    /**
     * 获取开放平台文档模型
     * @return
     */
    public ApiDocumentModel generateOpenDocumentModel() {
        if (this.openApiDocumentModelCache != null) {
            return this.openApiDocumentModelCache;
        }
        ApiDocumentModel apiDocumentModel = this.generateDocumentModel();
        ApiDocumentModel openApiDocumentModel = new ApiDocumentModel();
        List<ApiDocumentModel.Group> groups = apiDocumentModel.getGroups();
        for (ApiDocumentModel.Group group : groups) {
            List<ApiDocumentModel.Method> methods = group.getMethods();
            for (ApiDocumentModel.Method method : methods) {
                if (method.getOpenPlatform()) {
                    // 若是开放平台,怼入 openApiDocumentModel
                    List<ApiDocumentModel.Group> apiGroups = openApiDocumentModel.getGroups();
                    if (apiGroups == null) {
                        apiGroups = new ArrayList<>();
                        openApiDocumentModel.setGroups(apiGroups);
                    }
                    ApiDocumentModel.Group apiGroup = null;
                    for (ApiDocumentModel.Group item : apiGroups) {
                        if (item.getName().equals(group.getName())) {
                            apiGroup = item;
                        }
                    }
                    if (apiGroup == null) {
                        apiGroup = new ApiDocumentModel.Group();
                        apiGroup.setName(group.getName());
                        apiGroup.setDescription(group.getDescription());
                        apiGroups.add(apiGroup);
                    }
                    List<ApiDocumentModel.Method> apiMethods = apiGroup.getMethods();
                    if (apiMethods == null) {
                        apiMethods = new ArrayList<>();
                        apiGroup.setMethods(apiMethods);
                    }
                    apiMethods.add(method);
                }
            }
        }
        this.openApiDocumentModelCache = openApiDocumentModel;
        return openApiDocumentModel;
    }
 
    public ApiDocumentModel.Group generateOpenGroupModel(String group) {
        ApiDocumentModel apiDocumentModel = generateOpenDocumentModel();
        List<ApiDocumentModel.Group> groups = apiDocumentModel.getGroups();
        for (ApiDocumentModel.Group gp : groups) {
            if (gp.getName().equals(group)) {
                return gp;
            }
        }
        return null;
    }
 
    public ApiDocumentModel.Method generateOpenMethodModel(String gp, String mt) {
        ApiDocumentModel apiDocumentModel = generateOpenDocumentModel();
        List<ApiDocumentModel.Group> groups = apiDocumentModel.getGroups();
        for (ApiDocumentModel.Group group : groups) {
            if (group.getName().equals(gp)) {
                List<ApiDocumentModel.Method> methods = group.getMethods();
                for (ApiDocumentModel.Method method : methods) {
                    if (method.getName().equals(mt)) {
                        return method;
                    }
                }
            }
        }
        return null;
    }
 
    /**
     * 获取文档模型的方法
     *
     * @return
     */
    public ApiDocumentModel generateDocumentModel() {
        if (apiDocumentModelCache != null) {
            return apiDocumentModelCache;
        }
        Set<String> gpKeys = methodCacheMap.keySet();
        ApiDocumentModel apiDocumentModel = new ApiDocumentModel();
        List<ApiDocumentModel.Group> groups = new LinkedList<>();
        apiDocumentModel.setGroups(groups);
        for (String gpKey : gpKeys) {
            ApiDocumentModel.Group group = new ApiDocumentModel.Group();
            groups.add(group);
            group.setName(gpKey);
            group.setDescription(groupDescCacheMap.getOrDefault(gpKey, ""));
            List<ApiDocumentModel.Method> docMethods = new LinkedList<>();
            group.setMethods(docMethods);
            Map<String, Method> methodMap = methodCacheMap.get(gpKey);
            Set<String> methodNameKeys = methodMap.keySet();
            for (String methodNameKey : methodNameKeys) {
                Method method = methodMap.get(methodNameKey);
                //获取参数
                List<ApiDocumentModel.Parameter> docParameters = new LinkedList<>();
                Set<ApiDocumentModel.Entity> docEntities = new HashSet<>();
                Parameter[] parameters = method.getParameters();
                if (parameters != null && parameters.length > 0) {
                    for (Parameter parameter : parameters) {
                        HttpParam httpParam = parameter.getAnnotation(HttpParam.class);
                        ApiDocumentModel.Parameter docParameter = new ApiDocumentModel.Parameter();
                        if (docParameter == null) {
                            logger.info("[Api] 参数未注解:" + method.getName());
                        }
                        if (httpParam == null) {
                            logger.info("[Api] 参数未注解");
                        }
                        docParameter.setName(httpParam.name());
                        docParameter.setDescription(httpParam.description());
                        String typeName = parameter.getType().getTypeName();
                        if (typeName.startsWith("[L")) {
                            typeName = typeName.substring(2) + "[]";
                        }
                        docParameter.setParamType(typeName);
                        docParameter.setType(httpParam.type());
                        docParameter.setRequired(parameter.getAnnotation(NotNull.class) != null);
                        docParameter.setJson(!Const.IGNORE_PARAM_LIST.contains(parameter.getType()));
                        docParameters.add(docParameter);
                        Set<ApiDocumentModel.Entity> entities = this.generateEntityModel(parameter.getType());
                        docEntities.addAll(entities);
                    }
                }
                ApiDocumentModel.Method docMethod = new ApiDocumentModel.Method();
                docMethod.setParameters(docParameters);
                HttpMethod httpMethod = method.getAnnotation(HttpMethod.class);
                if (httpMethod != null) {
                    docMethod.setOpenPlatform(httpMethod.openPlatform());
                    docMethod.setDescription(httpMethod.description());
                    docMethod.setName(method.getName());
                    Type returnType = method.getGenericReturnType();
                    String retType = returnType.toString();
                    if (retType.startsWith("interface")) {
                        if (retType.startsWith("interface [L")) {
                            retType = retType.substring(12);
                        } else {
                            retType = retType.substring(10);
                        }
                    } else if (retType.startsWith("class")) {
                        if (retType.startsWith("class [L")) {
                            retType = retType.substring(8);
                        } else {
                            retType = retType.substring(6);
                        }
                    }
                    docMethod.setRetType(retType);
                    // 生成返回值文档
                    Class returnClass = null;
                    if (returnType instanceof Class) {
                        returnClass = (Class) returnType;
                    } else if (returnType instanceof ParameterizedType) {
                        ParameterizedType parameterizedType = (ParameterizedType) returnType;
                        Type[] types = parameterizedType.getActualTypeArguments();
                        if (types.length > 1) {
                            returnClass = (Class) (parameterizedType.getRawType());
                        } else {
                            Type type = types[0];
                            if (type instanceof ParameterizedType) {
                                returnClass = (Class) ((ParameterizedType) type).getRawType();
                            } else {
                                returnClass = (Class) type;
                            }
                        }
                    }
                    ApiEntity apiEntity = (ApiEntity) returnClass.getAnnotation(ApiEntity.class);
                    if (apiEntity != null) {
                        //若返回值类型为复杂类型
                        List<ApiDocumentModel.Field> fieldList = new ArrayList<>();
                        if (returnClass != null) {
                            Field[] declaredFields = returnClass.getDeclaredFields();
                            for (Field field : declaredFields) {
                                ApiDocumentModel.Field docField = new ApiDocumentModel.Field();
                                ApiField apiField = field.getAnnotation(ApiField.class);
                                if (apiField != null) {
                                    BaseEnums[] enumConstants = apiField.enums().getEnumConstants();
                                    if (apiField.enums() != EmptyEnums.class && enumConstants.length > 0) {
                                        Class<? extends BaseEnums> enums = apiField.enums();
                                        docField.setDescription(apiField.description() + ":" + this.getEnumsMemo(enums));
                                        docField.setMap(enumConstants[0].getMap().replace("\n", "\\n").replace("'", "\\'"));
                                        docField.setFilter(enumConstants[0].getFilter().replace("\n", "\\n").replace("'", "\\'"));
                                        docField.setEnums(enumConstants);
                                    } else {
                                        docField.setDescription(apiField.description());
                                    }
                                } else {
                                    docField.setDescription("暂无描述");
                                }
                                docField.setName(field.getName());
 
                                Class type;
                                if (Collection.class.isAssignableFrom(field.getType())
                                        || IPage.class.isAssignableFrom(field.getType())) {
                                    // List 派生
                                    Type actualTypeArgument = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
                                    if (actualTypeArgument instanceof ParameterizedType) {
                                        type = (Class) ((ParameterizedType) actualTypeArgument).getRawType();
                                    } else {
                                        type = (Class) actualTypeArgument;
                                    }
                                    docField.setType(field.getGenericType().toString().replace("<", "&lt;").replace(">", "&gt;"));
                                } else {
                                    type = field.getType();
                                    docField.setType(field.getType().getTypeName());
                                }
                                fieldList.add(docField);
                                // 生成实体文档
                                docEntities.addAll(generateEntityModel(type));
                            }
                            docMethod.setRetObj(fieldList);
                        }
                    }
                    if (returnClass == null && returnType != null) {
                        ApiDocumentModel.Field docField = new ApiDocumentModel.Field();
                        docField.setDescription("未知类型");
                        docField.setType(returnType.toString());
                        docField.setName("unanme");
                        docMethod.setRetObj(Arrays.asList(docField));
                    }
                    docMethod.setEntityList(new ArrayList<>(docEntities));
                    docMethods.add(docMethod);
 
                } else {
                    logger.info("生成文档失败:" + method.getName());
                }
            }
        }
        apiDocumentModelCache = apiDocumentModel;
        return apiDocumentModel;
    }
 
    public ApiDocumentModel.Group generateGroupModel(String group) {
        ApiDocumentModel apiDocumentModel = generateDocumentModel();
        List<ApiDocumentModel.Group> groups = apiDocumentModel.getGroups();
        for (ApiDocumentModel.Group gp : groups) {
            if (gp.getName().equals(group)) {
                return gp;
            }
        }
        return null;
    }
 
    public ApiDocumentModel.Method generateMethodModel(String gp, String mt) {
        ApiDocumentModel apiDocumentModel = generateDocumentModel();
        List<ApiDocumentModel.Group> groups = apiDocumentModel.getGroups();
        for (ApiDocumentModel.Group group : groups) {
            if (group.getName().equals(gp)) {
                List<ApiDocumentModel.Method> methods = group.getMethods();
                for (ApiDocumentModel.Method method : methods) {
                    if (method.getName().equals(mt)) {
                        return method;
                    }
                }
            }
        }
        return null;
    }
 
    /**
     * 生成实例模型
     *
     * @param clazz
     * @return
     */
    public Set<ApiDocumentModel.Entity> generateEntityModel(Class clazz) {
        HashSet<ApiDocumentModel.Entity> entities = new HashSet<>();
        return generateEntityModel(clazz, entities);
    }
 
    private Set<ApiDocumentModel.Entity> generateEntityModel(Class clazz, HashSet<ApiDocumentModel.Entity> entities) {
        ApiEntity apiEntity = (ApiEntity) clazz.getAnnotation(ApiEntity.class);
        if (apiEntity != null) {
            ApiDocumentModel.Entity entity = new ApiDocumentModel.Entity();
            entity.setDescription(apiEntity.description());
            entity.setType(clazz.getTypeName());
            if (!entities.contains(entity)) {
                entities.add(entity);
                Field[] declaredFields = clazz.getDeclaredFields();
                List<ApiDocumentModel.Field> fieldList = new LinkedList<>();
                for (Field field : declaredFields) {
                    ApiDocumentModel.Field docField = new ApiDocumentModel.Field();
                    ApiField apiField = field.getAnnotation(ApiField.class);
                    if (apiField != null) {
                        BaseEnums[] enumConstants = apiField.enums().getEnumConstants();
                        if (apiField.enums() != EmptyEnums.class && enumConstants.length > 0) {
                            Class<? extends BaseEnums> enums = apiField.enums();
                            docField.setDescription(apiField.description() + ":" + this.getEnumsMemo(enums));
                            docField.setMap(enumConstants[0].getMap().replace("\n", "\\n").replace("'", "\\'"));
                            docField.setFilter(enumConstants[0].getFilter().replace("\n", "\\n").replace("'", "\\'"));
                            docField.setEnums(enumConstants);
                        } else {
                            docField.setDescription(apiField.description());
                        }
                    } else {
                        docField.setDescription("暂无描述");
                    }
                    docField.setName(field.getName());
                    Class type;
                    if (Collection.class.isAssignableFrom(field.getType())
                            || IPage.class.isAssignableFrom(field.getType())) {
                        // List 派生
                        Type actualTypeArgument = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
                        if (actualTypeArgument instanceof ParameterizedType) {
                            type = (Class) ((ParameterizedType) actualTypeArgument).getRawType();
                        } else {
                            type = (Class) actualTypeArgument;
                        }
                        docField.setType(field.getGenericType().toString().replace("<", "&lt;").replace(">", "&gt;"));
                    } else {
                        type = field.getType();
                        docField.setType(field.getType().getTypeName());
                    }
                    fieldList.add(docField);
                    // 递归生成子文档 无限树结构问题?
                    entities.addAll(generateEntityModel(type, entities));
                }
                entity.setFields(fieldList);
            }
        }
        return entities;
    }
 
    private String getEnumsMemo(Class<? extends BaseEnums> clazz) {
        BaseEnums[] enumConstants = clazz.getEnumConstants();
        StringBuilder sb = new StringBuilder();
        for (BaseEnums e : enumConstants) {
            sb.append(e.getCode());
            sb.append("-");
            sb.append(e.getMsg());
            sb.append(" ");
        }
        return sb.toString();
    }
 
    public List<ApiDocumentModel.Method> methods(String gp) {
        for (ApiDocumentModel.Group group : generateDocumentModel().getGroups()) {
            if (group.getName().equals(gp)) {
                return group.getMethods();
            }
        }
        return null;
    }
 
}