提交 a03c6ef1 编写于 作者: xignzi006's avatar xignzi006

Resource发布

上级 d2544b9f
...@@ -156,7 +156,7 @@ ...@@ -156,7 +156,7 @@
<dependency> <dependency>
<groupId>net.ibizsys.model</groupId> <groupId>net.ibizsys.model</groupId>
<artifactId>ibiz-model</artifactId> <artifactId>ibiz-model</artifactId>
<version>0.2.6</version> <version>0.2.8</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId>slf4j-simple</artifactId> <artifactId>slf4j-simple</artifactId>
......
...@@ -6,6 +6,9 @@ import lombok.Setter; ...@@ -6,6 +6,9 @@ import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.service.IPSDEMethodDTO; import net.ibizsys.model.dataentity.service.IPSDEMethodDTO;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPI; import net.ibizsys.model.dataentity.service.IPSDEServiceAPI;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPIMethod;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPIRS;
import org.apache.commons.collections.CollectionUtils;
import java.util.*; import java.util.*;
...@@ -15,6 +18,8 @@ import java.util.*; ...@@ -15,6 +18,8 @@ import java.util.*;
@Accessors(chain = true) @Accessors(chain = true)
public class ApiEntityModel extends BaseModel { public class ApiEntityModel extends BaseModel {
private List<ApiDtoModel> dtos = new ArrayList<>();
public ApiEntityModel(ApiModel apiModel, IPSDEServiceAPI apiDataEntity) { public ApiEntityModel(ApiModel apiModel, IPSDEServiceAPI apiDataEntity) {
this.opt = apiDataEntity; this.opt = apiDataEntity;
this.api = apiModel; this.api = apiModel;
...@@ -23,9 +28,10 @@ public class ApiEntityModel extends BaseModel { ...@@ -23,9 +28,10 @@ public class ApiEntityModel extends BaseModel {
this.setId(String.format("%1$s-%2$s", api.getCodeName(), apiDataEntity.getCodeName())); this.setId(String.format("%1$s-%2$s", api.getCodeName(), apiDataEntity.getCodeName()));
if (apiDataEntity.getPSDataEntity() != null && apiDataEntity.getPSDataEntity().getAllPSDEMethodDTOs() != null) { if (apiDataEntity.getPSDataEntity() != null && apiDataEntity.getPSDataEntity().getAllPSDEMethodDTOs() != null) {
for (IPSDEMethodDTO iPSDEMethodDTO : apiDataEntity.getPSDataEntity().getAllPSDEMethodDTOs()) { for (IPSDEMethodDTO iPSDEMethodDTO : apiDataEntity.getPSDataEntity().getAllPSDEMethodDTOs()) {
apiDtosMap.put(iPSDEMethodDTO.getName(), new ApiDtoModel(this,iPSDEMethodDTO)); dtos.add(new ApiDtoModel(this, iPSDEMethodDTO));
} }
} }
} }
public IPSDEServiceAPI getApiDataEntity() { public IPSDEServiceAPI getApiDataEntity() {
...@@ -50,10 +56,72 @@ public class ApiEntityModel extends BaseModel { ...@@ -50,10 +56,72 @@ public class ApiEntityModel extends BaseModel {
return properties; return properties;
} }
private Map<String, ApiDtoModel> apiDtosMap = new LinkedHashMap<>();
public Collection<ApiDtoModel> getDtos() { public boolean isMajor() {
return apiDtosMap.values(); return getApiDataEntity().isMajor();
}
public List<ApiMethodModel> getMethods() {
if (this.getCodeName().equals("District")) {
getApiDataEntity().isMajor();
}
List<ApiMethodModel> methods = new ArrayList<>();
//主接口方法
if (getApiDataEntity().isMajor() && getApiDataEntity().getPSDEServiceAPIMethods() != null) {
for (IPSDEServiceAPIMethod iPSDEServiceAPIMethod : getApiDataEntity().getPSDEServiceAPIMethods()) {
methods.add(new ApiMethodModel(this, null, iPSDEServiceAPIMethod));
}
}
//接口关系方法
if (getApiDataEntity().getMinorPSDEServiceAPIRSs() != null) {
for (IPSDEServiceAPIRS iPSDEServiceAPIRS : getApiDataEntity().getMinorPSDEServiceAPIRSs()) {
if (iPSDEServiceAPIRS.getPSDEServiceAPIMethods() != null) {
ApiEntityRSModel apiEntityRSModel = api.getApiEntityRS(iPSDEServiceAPIRS.getName());
//计算父路径
List<List<ApiEntityRSModel>> parentApiEntityList = new ArrayList<>();
fillDEAPIRSPath(parentApiEntityList, apiEntityRSModel, null);
for (List<ApiEntityRSModel> parentApiEntities : parentApiEntityList) {
for (IPSDEServiceAPIMethod iPSDEServiceAPIMethod : iPSDEServiceAPIRS.getPSDEServiceAPIMethods()) {
methods.add(new ApiMethodModel(this, parentApiEntities, iPSDEServiceAPIMethod));
}
}
}
}
}
return methods;
}
/**
* 递归计算接口关系path
* 注意自身关系
*
* @param parentApiEntityList
* @param apiEntityRSModel
* @param parentApiEntities
*/
private void fillDEAPIRSPath(List<List<ApiEntityRSModel>> parentApiEntityList, ApiEntityRSModel apiEntityRSModel, List<ApiEntityRSModel> parentApiEntities) {
if (parentApiEntities == null) {
parentApiEntities = new ArrayList<>();
}
//防止递归
if (parentApiEntities.stream().anyMatch(rs -> rs.getName().equals(apiEntityRSModel.getName()))) {
return;
}
parentApiEntities.add(apiEntityRSModel);
if (apiEntityRSModel.isMajorEntityMajor()) {
List<ApiEntityRSModel> temp = new ArrayList<>();
temp.addAll(parentApiEntities);
parentApiEntityList.add(temp);
}
//递归
List<ApiEntityRSModel> parents = api.getApiEntityParentRSes(apiEntityRSModel.getMajorEntityCodeName());
if (!CollectionUtils.isEmpty(parents)) {
for (ApiEntityRSModel parentRs : parents) {
fillDEAPIRSPath(parentApiEntityList, parentRs, parentApiEntities);
}
}
} }
} }
package cn.ibizlab.codegen.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.service.IPSDEMethodDTO;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPI;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPIMethod;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPIRS;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ApiEntityRSModel extends BaseModel {
public ApiEntityRSModel(ApiModel apiModel, IPSDEServiceAPIRS iPSDEServiceAPIRS) {
this.opt = iPSDEServiceAPIRS;
this.api = apiModel;
this.setCodeName(iPSDEServiceAPIRS.getCodeName());
this.setName(iPSDEServiceAPIRS.getName());
}
private ApiModel api;
public String getParentIdFieldCodeName() {
if (getPSDEServiceAPIRS().getParentIdPSDEField() != null)
return getPSDEServiceAPIRS().getParentIdPSDEField().getCodeName();
return "";
}
public int getParentIdFieldType() {
if (getPSDEServiceAPIRS().getParentIdPSDEField() != null)
return getPSDEServiceAPIRS().getParentIdPSDEField().getStdDataType();
return PropType.VARCHAR.code;
}
public String getMajorEntityCodeName() {
return getPSDEServiceAPIRS().getMajorPSDEServiceAPI().getCodeName();
}
public boolean isMajorEntityMajor() {
return getPSDEServiceAPIRS().getMajorPSDEServiceAPI().isMajor();
}
public String getMinorEntityCodeName() {
return getPSDEServiceAPIRS().getMinorPSDEServiceAPI().getCodeName();
}
private IPSDEServiceAPIRS getPSDEServiceAPIRS() {
return (IPSDEServiceAPIRS) opt;
}
}
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.utils.Inflector;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.IPSDataEntity;
import net.ibizsys.model.dataentity.service.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ApiMethodModel extends BaseModel {
private String[] ignoreMethodNames = new String[]{"GET", "CREATE", "UPDATE", "REMOVE"};
private ApiModel api;
private ApiEntityModel apiEntity;
private List<ApiEntityRSModel> parentApiEntities;
public ApiMethodModel(ApiEntityModel apiEntityModel, List<ApiEntityRSModel> parentApiEntities, IPSDEServiceAPIMethod iPSDEServiceAPIMethod) {
this.opt = iPSDEServiceAPIMethod;
this.apiEntity = apiEntityModel;
this.api = apiEntityModel.getApi();
this.parentApiEntities = parentApiEntities;
this.setCodeName(iPSDEServiceAPIMethod.getCodeName());
this.setName(iPSDEServiceAPIMethod.getName());
}
public IPSDEServiceAPIMethod getPSDEServiceAPIMethod() {
return (IPSDEServiceAPIMethod) opt;
}
public String getRequestPath() {
String path = "";
if (!CollectionUtils.isEmpty(parentApiEntities)) {
for (ApiEntityRSModel apiRs : parentApiEntities) {
String strMajorEntityPlurlize = Inflector.getInstance().pluralize(StringAdvUtils.camelcase(apiRs.getMajorEntityCodeName()).toLowerCase());
path = String.format("/%s/{%s}", strMajorEntityPlurlize,StringAdvUtils.camelcase(apiRs.getParentIdFieldCodeName())) + path;
}
}
//主键
String strPlurlize = Inflector.getInstance().pluralize(StringAdvUtils.camelcase(apiEntity.getCodeName()).toLowerCase());
if (getPSDEServiceAPIMethod().isNeedResourceKey()) {
path = path + String.format("/%s/{%s}", strPlurlize, StringAdvUtils.camelcase(apiEntity.getEntity().getKeyField().getCodeName()));
} else {
path = path + String.format("/%s", strPlurlize);
}
//方法名
if (!ArrayUtils.contains(ignoreMethodNames, this.getName().toUpperCase())) {
path = path + String.format("/%s", this.getName().toLowerCase());
}
return path;
}
public List getPathVariables() {
List pathVariables = new ArrayList();
if (!CollectionUtils.isEmpty(parentApiEntities)) {
for (ApiEntityRSModel apiRs : parentApiEntities) {
String strMajorEntityPlurlize = Inflector.getInstance().pluralize(StringAdvUtils.camelcase(apiRs.getMajorEntityCodeName()).toLowerCase());
JSONObject pathVariable = new JSONObject();
pathVariable.put("name", apiRs.getParentIdFieldCodeName());
pathVariable.put("type", PropType.findType(apiRs.getParentIdFieldType()));
pathVariables.add(pathVariable);
}
}
if (getPSDEServiceAPIMethod().isNeedResourceKey()) {
JSONObject pathVariable = new JSONObject();
pathVariable.put("name", apiEntity.getEntity().getKeyField().getCodeName());
pathVariable.put("type", apiEntity.getEntity().getKeyField().getType());
pathVariables.add(pathVariable);
}
return pathVariables;
}
public String getBody() {
IPSDEServiceAPIMethodInput iPSDEServiceAPIMethodInput = getPSDEServiceAPIMethod().getPSDEServiceAPIMethodInput();
if (iPSDEServiceAPIMethodInput != null) {
if ("DTO".equals(iPSDEServiceAPIMethodInput.getType())) {
try {
iPSDEServiceAPIMethodInput.getPSDEMethodDTO();
} catch (Exception e) {
int i = 0;
}
if ("DEFAULT".equals(iPSDEServiceAPIMethodInput.getPSDEMethodDTO().getType()))
return iPSDEServiceAPIMethodInput.getPSDEMethodDTO().getName();
else if ("DEFILTER".equals(iPSDEServiceAPIMethodInput.getPSDEMethodDTO().getType()))
return iPSDEServiceAPIMethodInput.getPSDEMethodDTO().getName().replace("FilterDTO", "SearchContext");
}
}
return null;
}
public IPSDEServiceAPIMethodInput getInput() {
return getPSDEServiceAPIMethod().getPSDEServiceAPIMethodInput();
}
public IPSDEServiceAPIMethodReturn getReturn() {
return getPSDEServiceAPIMethod().getPSDEServiceAPIMethodReturn();
}
}
...@@ -12,38 +12,62 @@ import java.util.*; ...@@ -12,38 +12,62 @@ import java.util.*;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
public class ApiModel extends BaseModel{ public class ApiModel extends BaseModel {
public ApiModel(IPSSysServiceAPI api) public ApiModel(IPSSysServiceAPI api) {
{ this.opt = api;
this.opt=api;
this.setCodeName(api.getCodeName()); this.setCodeName(api.getCodeName());
this.setName(api.getName()); this.setName(api.getName());
if(getSysServiceApi().getPSDEServiceAPIs()!=null) if (getSysServiceApi().getPSDEServiceAPIs() != null) {
{ getSysServiceApi().getPSDEServiceAPIs().forEach(item -> {
getSysServiceApi().getPSDEServiceAPIs().forEach(item->{ apiEntitiesMap.put(item.getCodeName(), new ApiEntityModel(this, item));
apiEntitiesMap.put(item.getCodeName(),new ApiEntityModel(this, item));
}); });
} }
if (getSysServiceApi().getPSDEServiceAPIRSs() != null) {
getSysServiceApi().getPSDEServiceAPIRSs().forEach(item -> {
ApiEntityRSModel apiEntityRSModel = new ApiEntityRSModel(this, item);
apiEntityRSMap.put(item.getName(), apiEntityRSModel);
if (!apiEntityParentRSMap.containsKey(apiEntityRSModel.getMinorEntityCodeName())) {
apiEntityParentRSMap.put(apiEntityRSModel.getMinorEntityCodeName(), new ArrayList<>());
}
apiEntityParentRSMap.get(apiEntityRSModel.getMinorEntityCodeName()).add(apiEntityRSModel);
});
}
} }
private SystemModel system; private SystemModel system;
public IPSSysServiceAPI getSysServiceApi() public IPSSysServiceAPI getSysServiceApi() {
{ return (IPSSysServiceAPI) opt;
return (IPSSysServiceAPI)opt;
} }
private Map<String,ApiEntityModel> apiEntitiesMap=new LinkedHashMap<>(); private Map<String, ApiEntityModel> apiEntitiesMap = new LinkedHashMap<>();
public Collection<ApiEntityModel> getApiEntities() { public Collection<ApiEntityModel> getApiEntities() {
return apiEntitiesMap.values(); return apiEntitiesMap.values();
} }
public ApiEntityModel getApiEntity(String codeName) public ApiEntityModel getApiEntity(String codeName) {
{
return apiEntitiesMap.get(codeName); return apiEntitiesMap.get(codeName);
} }
private Map<String, ApiEntityRSModel> apiEntityRSMap = new LinkedHashMap<>();
public Collection<ApiEntityRSModel> getapiEntityRSes() {
return apiEntityRSMap.values();
}
public ApiEntityRSModel getApiEntityRS(String name) {
return apiEntityRSMap.get(name);
}
private Map<String, List<ApiEntityRSModel>> apiEntityParentRSMap = new LinkedHashMap<>();
public List<ApiEntityRSModel> getApiEntityParentRSes(String name) {
return apiEntityParentRSMap.get(name);
}
} }
...@@ -102,16 +102,7 @@ public class ModelStorage { ...@@ -102,16 +102,7 @@ public class ModelStorage {
if(!templateData.containsKey(type)) if(!templateData.containsKey(type))
{ {
CliData rt=new CliData(); CliData rt=new CliData();
if(type.equals(TemplateFileType.api)) if(type.equals(TemplateFileType.apiEntity))
{
getSystemModel().getApis().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.api).baseData(item,item.getCodeName().toLowerCase());
rt.addOption(opt);
});
}
else if(type.equals(TemplateFileType.apiEntity))
{ {
getSystemModel().getApis().forEach(api->{ getSystemModel().getApis().forEach(api->{
api.getApiEntities().forEach(item->{ api.getApiEntities().forEach(item->{
...@@ -120,79 +111,97 @@ public class ModelStorage { ...@@ -120,79 +111,97 @@ public class ModelStorage {
}); });
}); });
} }
else if (type.equals(TemplateFileType.apiDto)) { // if(type.equals(TemplateFileType.api))
getSystemModel().getApis().forEach(api -> { // {
api.getApiEntities().forEach(item -> { //
item.getDtos().forEach(dto -> { // getSystemModel().getApis().forEach(item->{
CliOption opt = newCliOption(TemplateFileType.apiDto) // CliOption opt=newCliOption(TemplateFileType.api).baseData(item,item.getCodeName().toLowerCase());
.setCliSubType(dto.getType()) // rt.addOption(opt);
.baseData(dto, dto.getCodeName()) // });
.set("apiDtos",dto.getCodeName()).set("apis",dto.getApi().getCodeName().toLowerCase()); //
rt.addOption(opt); // }
}); // else if(type.equals(TemplateFileType.apiEntity))
}); // {
}); // getSystemModel().getApis().forEach(api->{
} // api.getApiEntities().forEach(item->{
else if(type.equals(TemplateFileType.app)) // CliOption opt=newCliOption(TemplateFileType.apiEntity).baseData(item,item.getCodeName().toString()).set("apis",api.getCodeName().toLowerCase());
{ // rt.addOption(opt);
getSystemModel().getApps().forEach(item->{ // });
CliOption opt=newCliOption(TemplateFileType.app).baseData(item,item.getCodeName().toLowerCase()); // });
rt.addOption(opt); // }
}); // else if (type.equals(TemplateFileType.apiDto)) {
} // getSystemModel().getApis().forEach(api -> {
else if(type.equals(TemplateFileType.appEntity)) // api.getApiEntities().forEach(item -> {
{ // item.getDtos().forEach(dto -> {
getSystemModel().getApps().forEach(app->{ // CliOption opt = newCliOption(TemplateFileType.apiDto)
app.getAppEntities().forEach(item->{ // .setCliSubType(dto.getType())
CliOption opt=newCliOption(TemplateFileType.appEntity).baseData(item, StringAdvUtils.spinalcase(item.getCodeName())).set("apps",app.getCodeName().toLowerCase()); // .baseData(dto, dto.getCodeName())
rt.addOption(opt); // .set("apiDtos",dto.getCodeName()).set("apis",dto.getApi().getCodeName().toLowerCase());
}); // rt.addOption(opt);
}); // });
} // });
else if(type.equals(TemplateFileType.entity)) // });
{ // }
getSystemModel().getEntities().forEach(item->{ // else if(type.equals(TemplateFileType.app))
CliOption opt=newCliOption(TemplateFileType.entity).setCliSubType(item.getStorage()).setModule(item.getModule()) // {
.baseData(item,item.getCodeName().toString()); // getSystemModel().getApps().forEach(item->{
rt.addOption(opt); // CliOption opt=newCliOption(TemplateFileType.app).baseData(item,item.getCodeName().toLowerCase());
}); // rt.addOption(opt);
} // });
else if(type.equals(TemplateFileType.module)) // }
{ // else if(type.equals(TemplateFileType.appEntity))
getSystemModel().getSystem().getAllPSSystemModules().forEach(item->{ // {
CliOption opt=newCliOption(TemplateFileType.module) // getSystemModel().getApps().forEach(app->{
.baseData(item,item.getCodeName()); // app.getAppEntities().forEach(item->{
rt.addOption(opt); // CliOption opt=newCliOption(TemplateFileType.appEntity).baseData(item, StringAdvUtils.spinalcase(item.getCodeName())).set("apps",app.getCodeName().toLowerCase());
}); // rt.addOption(opt);
} // });
else if(type.equals(TemplateFileType.page)) // });
{ // }
getSystemModel().getApps().forEach(app->{ // else if(type.equals(TemplateFileType.entity))
app.getPages().forEach(item->{ // {
CliOption opt=newCliOption(TemplateFileType.page).setCliSubType(item.getAppView().getViewType()).baseData(item,StringAdvUtils.spinalcase(item.getCodeName())).set("apps",app.getCodeName().toLowerCase()).set("appModules",item.getAppModule().toSpinalCase()); // getSystemModel().getEntities().forEach(item->{
// CliOption opt=newCliOption(TemplateFileType.entity).setCliSubType(item.getStorage()).setModule(item.getModule())
rt.addOption(opt); // .baseData(item,item.getCodeName().toString());
}); // rt.addOption(opt);
}); // });
} // }
else if(type.equals(TemplateFileType.ctrl)) // else if(type.equals(TemplateFileType.module))
{ // {
getSystemModel().getApps().forEach(app->{ // getSystemModel().getSystem().getAllPSSystemModules().forEach(item->{
app.getCtrls().forEach(item->{ // CliOption opt=newCliOption(TemplateFileType.module)
CliOption opt=newCliOption(TemplateFileType.ctrl).setCliSubType(item.getControl().getControlType()).baseData(item,StringAdvUtils.spinalcase(item.getCodeName())).set("apps",app.getCodeName().toLowerCase()).set("appEntities",item.getFolder().toSpinalCase()); // .baseData(item,item.getCodeName());
rt.addOption(opt); // rt.addOption(opt);
}); // });
}); // }
} // else if(type.equals(TemplateFileType.page))
else if(type.equals(TemplateFileType.supportingFiles)) // {
{ // getSystemModel().getApps().forEach(app->{
CliOption opt=newCliOption(TemplateFileType.supportingFiles) // app.getPages().forEach(item->{
.set(TemplateFileType.app.value(),getTemplateData(TemplateFileType.app).getOptions()) // CliOption opt=newCliOption(TemplateFileType.page).setCliSubType(item.getAppView().getViewType()).baseData(item,StringAdvUtils.spinalcase(item.getCodeName())).set("apps",app.getCodeName().toLowerCase()).set("appModules",item.getAppModule().toSpinalCase());
.set(TemplateFileType.api.value(),getTemplateData(TemplateFileType.api).getOptions()) //
.set(TemplateFileType.module.value(),getTemplateData(TemplateFileType.module).getOptions()); // rt.addOption(opt);
// });
rt.addOption(opt); // });
} // }
// else if(type.equals(TemplateFileType.ctrl))
// {
// getSystemModel().getApps().forEach(app->{
// app.getCtrls().forEach(item->{
// CliOption opt=newCliOption(TemplateFileType.ctrl).setCliSubType(item.getControl().getControlType()).baseData(item,StringAdvUtils.spinalcase(item.getCodeName())).set("apps",app.getCodeName().toLowerCase()).set("appEntities",item.getFolder().toSpinalCase());
// rt.addOption(opt);
// });
// });
// }
// else if(type.equals(TemplateFileType.supportingFiles))
// {
// CliOption opt=newCliOption(TemplateFileType.supportingFiles)
// .set(TemplateFileType.app.value(),getTemplateData(TemplateFileType.app).getOptions())
// .set(TemplateFileType.api.value(),getTemplateData(TemplateFileType.api).getOptions())
// .set(TemplateFileType.module.value(),getTemplateData(TemplateFileType.module).getOptions());
//
// rt.addOption(opt);
// }
templateData.put(type,rt); templateData.put(type,rt);
} }
return templateData.get(type); return templateData.get(type);
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册