fix: eps生成修复

This commit is contained in:
ruying408
2025-04-30 11:48:41 +08:00
parent a39a4ea772
commit 4c18020fd7
4 changed files with 54 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
package com.cool.core.annotation; package com.cool.core.annotation;
import com.cool.core.enums.AdminComponentsEnum;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -8,5 +10,5 @@ import java.lang.annotation.Target;
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface EpsField { public @interface EpsField {
String component() default "input"; String component() default AdminComponentsEnum.INPUT;
} }

View File

@@ -11,6 +11,7 @@ import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.cool.core.annotation.EpsField; import com.cool.core.annotation.EpsField;
import com.cool.core.annotation.TokenIgnore;
import com.cool.core.config.CustomOpenApiResource; import com.cool.core.config.CustomOpenApiResource;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine; import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
@@ -90,10 +91,12 @@ public class CoolEps {
private void urls() { private void urls() {
Dict admin = Dict.create(); Dict admin = Dict.create();
Dict app = Dict.create(); Dict app = Dict.create();
ArrayList<Object> emptyList = new ArrayList<>();
Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods(); Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
for (Map.Entry<RequestMappingInfo, HandlerMethod> methodEntry : map.entrySet()) { for (Map.Entry<RequestMappingInfo, HandlerMethod> methodEntry : map.entrySet()) {
RequestMappingInfo info = methodEntry.getKey(); RequestMappingInfo info = methodEntry.getKey();
HandlerMethod method = methodEntry.getValue(); HandlerMethod method = methodEntry.getValue();
TokenIgnore tokenIgnore = method.getMethodAnnotation(TokenIgnore.class);
String module = getModule(method); String module = getModule(method);
if (StrUtil.isNotEmpty(module)) { if (StrUtil.isNotEmpty(module)) {
String entityName = getEntity(method.getBeanType()); String entityName = getEntity(method.getBeanType());
@@ -126,17 +129,24 @@ public class CoolEps {
} }
}); });
if (item != null) { if (item != null) {
item.set("api", apis(prefix, methodPath, item.getBean("api"))); item.set("api", apis(prefix, methodPath, item.getBean("api"), tokenIgnore));
} else { } else {
item = Dict.create(); item = Dict.create();
item.set("controller", method.getBeanType().getSimpleName()); item.set("controller", method.getBeanType().getSimpleName());
item.set("module", module); item.set("module", module);
item.set("info", Dict.create().set("type",
Dict.create()
.set("name", getLastPathSegment(prefix))
.set("description", "")
));
item.set("api", apis(prefix, methodPath, item.getBean("api"), tokenIgnore));
item.set("name", entityName); item.set("name", entityName);
item.set("api", new ArrayList<Dict>());
item.set("prefix", prefix);
item.set("columns", entityInfo.get(entityName)); item.set("columns", entityInfo.get(entityName));
item.set("menu", menuInfo.get( entityName ) ); item.set("pageQueryOp", Dict.create().set("keyWordLikeFields", emptyList)
item.set("api", apis(prefix, methodPath, item.getBean("api"))); .set("fieldEq", emptyList)
.set("fieldLike", emptyList));
item.set("prefix", prefix);
item.set("menu", menuInfo.get(entityName));
urls.add(item); urls.add(item);
} }
if (type == 0) { if (type == 0) {
@@ -152,6 +162,28 @@ public class CoolEps {
this.app = app; this.app = app;
} }
/**
* 提取URL路径中的最后一个路径段
* 示例:输入 "/api/getData" 返回 "getData"
*/
private String getLastPathSegment(String url) {
if (StrUtil.isBlank(url)) {
return "";
}
int queryIndex = url.indexOf('?');
if (queryIndex != -1) {
url = url.substring(0, queryIndex);
}
int slashIndex = url.lastIndexOf('/');
if (slashIndex != -1 && slashIndex < url.length() - 1) {
return url.substring(slashIndex + 1);
} else {
return url;
}
}
/** /**
* 设置所有的api * 设置所有的api
@@ -161,13 +193,18 @@ public class CoolEps {
* @param list api列表 * @param list api列表
* @return api列表 * @return api列表
*/ */
private List<Dict> apis(String prefix, String methodPath, List<Dict> list) { private List<Dict> apis(String prefix, String methodPath, List<Dict> list, TokenIgnore tokenIgnore) {
if (ObjUtil.isNull(list)) {
list = new ArrayList<>();
}
Dict item = Dict.create(); Dict item = Dict.create();
item.set("method", "");
item.set("path", methodPath); item.set("path", methodPath);
item.set("summary", "");
item.set("tag", ""); item.set("tag", "");
item.set("dts", new Object()); item.set("dts", Dict.create());
item.set("ignoreToken", false);
if (tokenIgnore != null) {
item.set("ignoreToken", true);
}
setSwaggerInfo(item, prefix + methodPath); setSwaggerInfo(item, prefix + methodPath);
list.add(item); list.add(item);
return list; return list;
@@ -184,10 +221,8 @@ public class CoolEps {
JSONObject urlInfo = paths.getJSONObject(url); JSONObject urlInfo = paths.getJSONObject(url);
String method = urlInfo.keySet().iterator().next(); String method = urlInfo.keySet().iterator().next();
JSONObject methodInfo = urlInfo.getJSONObject(method); JSONObject methodInfo = urlInfo.getJSONObject(method);
item.set("dts", methodInfo);
item.set("method", method); item.set("method", method);
item.set("summary", methodInfo.getStr("summary")); item.set("summary", methodInfo.getStr("summary"));
item.set("description", methodInfo.get("description"));
} }
/** /**
@@ -351,6 +386,7 @@ public class CoolEps {
dict.set("propertyName", field.getName()); dict.set("propertyName", field.getName());
dict.set("type", matchType(field.getType().getName())); dict.set("type", matchType(field.getType().getName()));
dict.set("nullable", !columnInfo.notNull()); dict.set("nullable", !columnInfo.notNull());
dict.set("source", "a." + field.getName());
dictList.add(dict); dictList.add(dict);
} }
return dictList; return dictList;

View File

@@ -65,7 +65,7 @@ public class R<T> implements Serializable {
} }
public static <B> R<B> ok(B data) { public static <B> R<B> ok(B data) {
return new R<B>(1000 , "ok", data); return new R<B>(1000 , "success", data);
} }

View File

@@ -1,6 +1,8 @@
package com.cool.modules.base.entity.sys; package com.cool.modules.base.entity.sys;
import com.cool.core.annotation.EpsField;
import com.cool.core.base.TenantEntity; import com.cool.core.base.TenantEntity;
import com.cool.core.enums.AdminComponentsEnum;
import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine; import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
@@ -41,6 +43,7 @@ public class BaseSysUserEntity extends TenantEntity<BaseSysUserEntity> {
private String headImg; private String headImg;
@ColumnDefine(comment = "手机号") @ColumnDefine(comment = "手机号")
@EpsField(component = AdminComponentsEnum.TEXTAREA)
private String phone; private String phone;
@ColumnDefine(comment = "邮箱") @ColumnDefine(comment = "邮箱")