提交 810f0bea 编写于 作者: chenxiang@lab.ibiz5.com's avatar chenxiang@lab.ibiz5.com

接口实体模板

上级 3b784b35
package cn.ibizlab.codegen.model;
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.IPSDEMethodDTO;
import net.ibizsys.model.dataentity.service.IPSDEMethodDTOField;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPI;
import net.ibizsys.model.service.IPSSubSysServiceAPIDTO;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ClientDtoModel extends BaseModel {
}
package cn.ibizlab.codegen.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPIMethod;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPIRS;
import net.ibizsys.model.service.IPSSubSysServiceAPIDE;
import net.ibizsys.model.service.IPSSubSysServiceAPIDEMethod;
import net.ibizsys.model.service.IPSSubSysServiceAPIDERS;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ClientEntityModel extends BaseModel {
private ClientModel client;
public ClientEntityModel(ClientModel clientModel, IPSSubSysServiceAPIDE iPSSubSysServiceAPIDE) {
this.opt = iPSSubSysServiceAPIDE;
this.client = clientModel;
this.setCodeName(iPSSubSysServiceAPIDE.getCodeName());
this.setName(iPSSubSysServiceAPIDE.getName());
this.setId(String.format("%1$s-%2$s", client.getCodeName(), iPSSubSysServiceAPIDE.getCodeName()));
}
public IPSSubSysServiceAPIDE getPSSubSysServiceAPIDE() {
return (IPSSubSysServiceAPIDE) opt;
}
public EntityModel getEntity() {
return this.getClient().getSystem().getEntity(getCodeName());
}
private String apiName;
public String getApiName() {
if (apiName == null)
this.apiName = ObjectUtils.isEmpty(getPSSubSysServiceAPIDE().getLogicName()) ? getEntity().getLogicName() : getPSSubSysServiceAPIDE().getLogicName();
return apiName;
}
public boolean isMajor() {
return getPSSubSysServiceAPIDE().isMajor();
}
public List<ClientMethodModel> getMethods() {
List<ClientMethodModel> methods = new ArrayList<>();
//主接口方法
if (getPSSubSysServiceAPIDE().isMajor() && getPSSubSysServiceAPIDE().getPSSubSysServiceAPIDEMethods() != null) {
for (IPSSubSysServiceAPIDEMethod iPSSubSysServiceAPIDEMethod : getPSSubSysServiceAPIDE().getPSSubSysServiceAPIDEMethods()) {
methods.add(new ClientMethodModel(this, null, iPSSubSysServiceAPIDEMethod));
}
}
//接口关系方法
// if (this.getClient().getPSSubSysServiceAPI().getAllPSSubSysServiceAPIDERSs() != null) {
// for (IPSSubSysServiceAPIDERS iPSSubSysServiceAPIDERS : this.getClient().getPSSubSysServiceAPI().getAllPSSubSysServiceAPIDERSs()) {
// if(!iPSSubSysServiceAPIDERS.getMinorPSSubSysServiceAPIDE().getId().equalsIgnoreCase(this.getPSSubSysServiceAPIDE().getId()))
// continue;
// if (iPSSubSysServiceAPIDERS.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()) {
// if(iPSDEServiceAPIMethod.getPSDEDataSet()!=null && iPSDEServiceAPIMethod.getPSDEDataSet().getPSDEDataQueries()==null)
// continue ;
// methods.add(new ApiMethodModel(this, parentApiEntities, iPSDEServiceAPIMethod));
// }
// }
// }
// }
// }
return methods;
}
/**
* 递归计算接口关系path
* 注意自身关系
*
* @param parentClientEntityList
* @param clientEntityRSModel
* @param parentClientEntities
*/
private void fillDEAPIRSPath(List<List<ClientEntityRSModel>> parentClientEntityList, ClientEntityRSModel clientEntityRSModel, List<ClientEntityRSModel> parentClientEntities) {
if (parentClientEntities == null) {
parentClientEntities = new ArrayList<>();
}
//防止递归
if (parentClientEntities.stream().anyMatch(rs -> rs.getName().equals(clientEntityRSModel.getName()))) {
return;
}
parentClientEntities.add(clientEntityRSModel);
if (clientEntityRSModel.isMajorEntityMajor()) {
List<ClientEntityRSModel> temp = new ArrayList<>();
temp.addAll(parentClientEntities);
parentClientEntityList.add(temp);
}
//递归
// List<ApiEntityRSModel> parents = api.getApiEntityParentRSes(apiEntityRSModel.getMajorEntityCodeName());
List<ClientEntityRSModel> parents = new ArrayList<>();
if (!CollectionUtils.isEmpty(parents)) {
for (ClientEntityRSModel parentRs : parents) {
List<ClientEntityRSModel> tempParentApiEntities = new ArrayList<>();
tempParentApiEntities.addAll(parentClientEntities);
fillDEAPIRSPath(parentClientEntityList, parentRs, tempParentApiEntities);
}
}
}
}
package cn.ibizlab.codegen.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.service.IPSSubSysServiceAPIDERS;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ClientEntityRSModel extends BaseModel {
public ClientEntityRSModel(ClientModel clientModel, IPSSubSysServiceAPIDERS iPSSubSysServiceAPIDERS) {
this.opt = iPSSubSysServiceAPIDERS;
this.clientModel = clientModel;
this.setCodeName(iPSSubSysServiceAPIDERS.getCodeName());
this.setName(iPSSubSysServiceAPIDERS.getName());
}
private ClientModel clientModel;
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().getMajorPSSubSysServiceAPIDE().getCodeName();
}
public boolean isMajorEntityMajor() {
return getPSDEServiceAPIRS().getMajorPSSubSysServiceAPIDE().isMajor();
}
public String getMinorEntityCodeName() {
return getPSDEServiceAPIRS().getMinorPSSubSysServiceAPIDE().getCodeName();
}
private IPSSubSysServiceAPIDERS getPSDEServiceAPIRS() {
return (IPSSubSysServiceAPIDERS) 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.service.IPSDEMethodDTO;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPIMethod;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPIMethodInput;
import net.ibizsys.model.service.IPSSubSysServiceAPIDEMethod;
import net.ibizsys.model.service.IPSSubSysServiceAPIDTO;
import net.ibizsys.model.service.IPSSubSysServiceAPIMethodInput;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ClientMethodModel extends BaseModel {
private static String[] ignoreMethodNames = new String[]{"GET", "CREATE", "UPDATE", "REMOVE"};
private static String[] booleanMethodNames = new String[]{"CREATE", "UPDATE", "SAVE", "CREATEBATCH", "UPDATEBATCH", "REMOVEBATCH", "SAVEBATCH"};
private static Map<String, String> lang = new HashMap<String, String>() {{
put("GET", "获取");
put("CREATE", "创建");
put("UPDATE", "更新");
put("SAVE", "保存");
put("REMOVE", "删除");
put("GETDRAFT", "草稿");
put("CHECKKEY", "校验");
}};
private ClientModel client;
private ClientEntityModel clientEntity;
private List<ClientEntityRSModel> parentClientEntities;
public String getTags() {
return clientEntity.getApiName();
}
private String notes;
private String clientName;
public String getClientName() {
if (lang.containsKey(clientName.toUpperCase()))
return lang.get(clientName.toUpperCase()) + clientName;
else if (clientName.toUpperCase().startsWith("FETCH"))
return "查询" + clientName;
return clientName;
}
public ClientMethodModel(ClientEntityModel clientEntityModel, List<ClientEntityRSModel> parentClientEntities, IPSSubSysServiceAPIDEMethod iPSSubSysServiceAPIDEMethod) {
this.opt = iPSSubSysServiceAPIDEMethod;
this.clientEntity = clientEntityModel;
this.client = clientEntityModel.getClient();
this.parentClientEntities = parentClientEntities;
this.setCodeName(iPSSubSysServiceAPIDEMethod.getCodeName());
this.setName(iPSSubSysServiceAPIDEMethod.getName());
this.clientName = ObjectUtils.isEmpty(iPSSubSysServiceAPIDEMethod.getLogicName()) ? iPSSubSysServiceAPIDEMethod.getName() : iPSSubSysServiceAPIDEMethod.getLogicName();
this.notes = clientEntityModel.getCodeName() + "-" + name;
}
public IPSSubSysServiceAPIDEMethod getPSSubSysServiceAPIDEMethod() {
return (IPSSubSysServiceAPIDEMethod) opt;
}
public String getMethodName() {
String strName = super.getName();
if (!CollectionUtils.isEmpty(parentClientEntities)) {
strName += "By";
for (ClientEntityRSModel parent : parentClientEntities) {
strName += StringAdvUtils.pascalcase(parent.getParentIdFieldCodeName());
}
}
return strName;
}
private String requestPath;
public String getRequestPath() {
if (requestPath == null) {
String path = "";
if (!CollectionUtils.isEmpty(parentClientEntities)) {
for (ClientEntityRSModel apiRs : parentClientEntities) {
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(clientEntity.getCodeName()).toLowerCase());
if (getPSSubSysServiceAPIDEMethod().isNeedResourceKey() && (!"save".equalsIgnoreCase(name))) {
path = path + String.format("/%s/{%s}", strPlurlize, StringAdvUtils.camelcase(clientEntity.getEntity().getKeyField().getCodeName()));
} else {
path = path + String.format("/%s", strPlurlize);
}
//方法名
if (!ArrayUtils.contains(ignoreMethodNames, this.getName().toUpperCase())) {
path = path + String.format("/%s", this.getCodeName().toLowerCase());
}
requestPath = path;
}
return requestPath;
}
public String getRequestPath2() {
if (!ObjectUtils.isEmpty(this.getRequestPath()))
return requestPath.substring(1);
return "";
}
private List pathVariables;
public List getPathVariables() {
if (pathVariables == null) {
pathVariables = new ArrayList();
if (!CollectionUtils.isEmpty(parentClientEntities)) {
for (ClientEntityRSModel apiRs : parentClientEntities) {
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(0, pathVariable);
}
}
if (getPSSubSysServiceAPIDEMethod().isNeedResourceKey() && (!"save".equalsIgnoreCase(name))) {
JSONObject pathVariable = new JSONObject();
pathVariable.put("name", clientEntity.getEntity().getKeyField().getCodeName());
pathVariable.put("type", clientEntity.getEntity().getKeyField().getType());
pathVariables.add(pathVariable);
}
}
return pathVariables;
}
public String getBody() {
if (!ObjectUtils.isEmpty(getInParam())) {
return getInParam() + " " + getInParamName();
}
return null;
}
public IPSSubSysServiceAPIDTO getInputDTO() {
return getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodInput().getPSSubSysServiceAPIDTO();
}
public IPSSubSysServiceAPIDTO getReturnDTO() {
if (getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn() == null || getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getPSSubSysServiceAPIDTO() == null)
return getInputDTO();
return getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getPSSubSysServiceAPIDTO();
}
private String inParam;
private String inParam2;
public String getInParam() {
if (inParam == null) {
String param = this.getClientEntity().getCodeName();
IPSSubSysServiceAPIMethodInput iPSSubSysServiceAPIMethodInput = getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodInput();
if (iPSSubSysServiceAPIMethodInput != null && iPSSubSysServiceAPIMethodInput.getPSSubSysServiceAPIDTO() != null)
param = iPSSubSysServiceAPIMethodInput.getPSSubSysServiceAPIDTO().getName().replace("FilterDTO", "SearchContext");
if ("KEYFIELD".equalsIgnoreCase(iPSSubSysServiceAPIMethodInput.getType()) || this.getName().equalsIgnoreCase("Remove")) {
param = "";
inParam2 = clientEntity.getEntity().getKeyField().getType().java;
inParamName = StringAdvUtils.camelcase(clientEntity.getEntity().getKeyField().getCodeName());
inParamName2 = StringAdvUtils.camelcase(clientEntity.getEntity().getKeyField().getCodeName());
} else if ("KEYFIELDS".equalsIgnoreCase(iPSSubSysServiceAPIMethodInput.getType())) {
param = "List<" + clientEntity.getEntity().getKeyField().getType().java + ">";
inParam2 = param;
inParamName = "list";
inParamName2 = "list";
} else if ("DTO".equalsIgnoreCase(iPSSubSysServiceAPIMethodInput.getType())) {
inParam2 = clientEntity.getEntity().getCodeName();
inParamName = "dto";
inParamName2 = "domain";
} else if ("DTOS".equalsIgnoreCase(iPSSubSysServiceAPIMethodInput.getType())) {
param = "List<" + param + ">";
inParam2 = "List<" + clientEntity.getEntity().getCodeName() + ">";
inParamName = "dtos";
inParamName2 = "domains";
}
inParam = param;
inParam = inParam.replace("DTO","");
}
return inParam;
}
public boolean isNeedDto2Domain() {
if ("FETCH".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getMethodType()))
return false;
IPSSubSysServiceAPIMethodInput iPSSubSysServiceAPIMethodInput = getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodInput();
if (iPSSubSysServiceAPIMethodInput == null)
return false;
return "DTOS".equalsIgnoreCase(iPSSubSysServiceAPIMethodInput.getType()) || "DTO".equalsIgnoreCase(iPSSubSysServiceAPIMethodInput.getType());
}
public boolean isListIn() {
IPSSubSysServiceAPIMethodInput iPSSubSysServiceAPIMethodInput = getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodInput();
if (iPSSubSysServiceAPIMethodInput == null)
return false;
return "KEYFIELDS".equalsIgnoreCase(iPSSubSysServiceAPIMethodInput.getType()) || "DTOS".equalsIgnoreCase(iPSSubSysServiceAPIMethodInput.getType());
}
private String inParamName;
private String inParamName2;
public boolean isListReturn() {
if (getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn() == null)
return false;
if ("DTOS".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType())
|| "OBJECTS".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType())
|| "SIMPLES".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType()))
return true;
return false;
}
public String typeReturn() {
if (isListReturn()) {
if ("SIMPLES".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType()))
return PropType.findType(this.getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getStdDataType()).java;
else if ("DTOS".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType())
|| "OBJECTS".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType()))
return this.getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getName();
}
return "";
}
public boolean isBooleanReturn() {
return ArrayUtils.contains(booleanMethodNames, this.getName().toUpperCase());
}
private boolean needDomain2Dto = true;
private String outParam;
private String outParam2;
public String getOutParam() {
if (outParam == null) {
String param = this.getClientEntity().getCodeName();
if (getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn() != null && getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getPSSubSysServiceAPIDTO() != null)
param = getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getPSSubSysServiceAPIDTO().getName();
if ("Remove".equalsIgnoreCase(getName())) {
needDomain2Dto = false;
param = "Boolean";
outParam2 = "Boolean";
} else if ("VOID".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType())) {
needDomain2Dto = isNeedDto2Domain();
param = getInParam();
outParam2 = getInParam2();
} else if ("SIMPLE".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType())) {
needDomain2Dto = false;
param = PropType.findType(this.getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getStdDataType()).java;
outParam2 = param;
} else if ("SIMPLES".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType())) {
needDomain2Dto = false;
param = "List<" + PropType.findType(this.getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getStdDataType()).java + ">";
outParam2 = param;
} else if ("DTO".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType())) {
needDomain2Dto = false;
outParam2 = clientEntity.getEntity().getCodeName();
} else if ("DTOS".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType())
|| "OBJECTS".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getPSSubSysServiceAPIMethodReturn().getType())) {
needDomain2Dto = false;
param = "List<" + param + ">";
outParam2 = "List<" + clientEntity.getEntity().getCodeName() + ">";
}
if ("FETCH".equalsIgnoreCase(getPSSubSysServiceAPIDEMethod().getMethodType())) {
needDomain2Dto = false;
outParam = "Page<" + param + ">";
}
else
outParam = param;
//
outParam = outParam.replace("DTO","");
}
return outParam;
}
}
...@@ -13,24 +13,59 @@ import java.util.*; ...@@ -13,24 +13,59 @@ import java.util.*;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
public class SubServiceApiModel extends BaseModel { public class ClientModel extends BaseModel {
private SystemModel system; private SystemModel system;
private Map<String, SubEntityApiModel> subEntityApi = new LinkedHashMap<>(); private Map<String, ClientEntityModel> clientEntityMap = new LinkedHashMap<>();
public SubServiceApiModel(IPSSubSysServiceAPI iPSSubSysServiceAPI) { private Map<String, ClientEntityRSModel> clientEntityRSMap = new LinkedHashMap<>();
public Collection<ClientEntityRSModel> getClientEntityRSes() {
return clientEntityRSMap.values();
}
public ClientEntityRSModel getClientEntityRS(String name) {
return clientEntityRSMap.get(name);
}
private Map<String, List<ClientEntityRSModel>> clientEntityParentRSMap = new LinkedHashMap<>();
public List<ClientEntityRSModel> getApiEntityParentRSes(String name) {
return clientEntityParentRSMap.get(name);
}
public String service;
public ClientModel(IPSSubSysServiceAPI iPSSubSysServiceAPI) {
this.opt = iPSSubSysServiceAPI; this.opt = iPSSubSysServiceAPI;
this.setCodeName(iPSSubSysServiceAPI.getCodeName()); this.setCodeName(iPSSubSysServiceAPI.getCodeName());
this.setName(iPSSubSysServiceAPI.getName()); this.setName(iPSSubSysServiceAPI.getName());
if (getPSSubSysServiceAPI().getAllPSSubSysServiceAPIDEs() != null) {
getPSSubSysServiceAPI().getAllPSSubSysServiceAPIDEs().forEach(item -> {
clientEntityMap.put(item.getCodeName(), new ClientEntityModel(this, item));
});
}
service = getPSSubSysServiceAPI().getServiceCodeName().replace("_","-");
if (getPSSubSysServiceAPI().getAllPSSubSysServiceAPIDERSs() != null) {
getPSSubSysServiceAPI().getAllPSSubSysServiceAPIDERSs().forEach(item -> {
ClientEntityRSModel clientEntityRSModel = new ClientEntityRSModel(this, item);
clientEntityRSMap.put(item.getName(), clientEntityRSModel);
if (!clientEntityParentRSMap.containsKey(clientEntityRSModel.getMinorEntityCodeName())) {
clientEntityParentRSMap.put(clientEntityRSModel.getMinorEntityCodeName(), new ArrayList<>());
}
clientEntityParentRSMap.get(clientEntityRSModel.getMinorEntityCodeName()).add(clientEntityRSModel);
});
}
} }
public Collection<SubEntityApiModel> getSubEntityApis() { public Collection<ClientEntityModel> getClientEntities() {
return subEntityApi.values(); return clientEntityMap.values();
} }
public SubEntityApiModel getSubEntityApi(String codeName) { public ClientEntityModel getClientEntity(String codeName) {
return subEntityApi.get(codeName); return clientEntityMap.get(codeName);
} }
public IPSSubSysServiceAPI getPSSubSysServiceAPI() { public IPSSubSysServiceAPI getPSSubSysServiceAPI() {
......
...@@ -36,49 +36,45 @@ public class EntityModel extends BaseModel { ...@@ -36,49 +36,45 @@ public class EntityModel extends BaseModel {
} }
public String getTableName() { public String getTableName() {
return StringUtils.isEmpty(getDataEntity().getTableName())?getDataEntity().getName():getDataEntity().getTableName(); return StringUtils.isEmpty(getDataEntity().getTableName()) ? getDataEntity().getName() : getDataEntity().getTableName();
} }
public String getLogicName() { public String getLogicName() {
return getDataEntity().getLogicName(); return getDataEntity().getLogicName();
} }
public String getModule() { public String getModule() {
if(getDataEntity().getPSSystemModule()!=null) if (getDataEntity().getPSSystemModule() != null)
return getDataEntity().getPSSystemModule().getCodeName().toLowerCase(); return getDataEntity().getPSSystemModule().getCodeName().toLowerCase();
return "ungroup"; return "ungroup";
} }
public IPSDataEntity getDataEntity(){ public IPSDataEntity getDataEntity() {
return (IPSDataEntity)opt; return (IPSDataEntity) opt;
} }
private List<DataSetModel> queries; private List<DataSetModel> queries;
public EntityModel addQueries(DataSetModel dataSet) public EntityModel addQueries(DataSetModel dataSet) {
{ if (queries == null)
if(queries==null) queries = new ArrayList<>();
queries=new ArrayList<>();
queries.add(dataSet); queries.add(dataSet);
return this; return this;
} }
private Map<String,DataSetModel> dataQueries; private Map<String, DataSetModel> dataQueries;
public EntityModel addDataQueries(DataSetModel dataSet) public EntityModel addDataQueries(DataSetModel dataSet) {
{ if (dataQueries == null)
if(dataQueries==null) dataQueries = new LinkedHashMap<>();
dataQueries=new LinkedHashMap<>(); dataQueries.put(dataSet.getDatasetId(), dataSet);
dataQueries.put(dataSet.getDatasetId(),dataSet); if ("View".equalsIgnoreCase(dataSet.codeName) && viewDataQuery == null)
if("View".equalsIgnoreCase(dataSet.codeName)&&viewDataQuery==null) viewDataQuery = dataSet;
viewDataQuery=dataSet; if (getDataEntity().getDefaultPSDEDataSet().getCodeName().equalsIgnoreCase(dataSet.codeName) && defaultDataQuery == null)
if(getDataEntity().getDefaultPSDEDataSet().getCodeName().equalsIgnoreCase(dataSet.codeName)&&defaultDataQuery==null) defaultDataQuery = dataSet;
defaultDataQuery=dataSet;
return this; return this;
} }
...@@ -88,57 +84,50 @@ public class EntityModel extends BaseModel { ...@@ -88,57 +84,50 @@ public class EntityModel extends BaseModel {
private List<DataSetModel> dataSets; private List<DataSetModel> dataSets;
public EntityModel addDataSet(DataSetModel dataSet) public EntityModel addDataSet(DataSetModel dataSet) {
{ if (dataSets == null)
if(dataSets==null) dataSets = new ArrayList<>();
dataSets=new ArrayList<>();
dataSets.add(dataSet); dataSets.add(dataSet);
return this; return this;
} }
private List<FieldModel> fields; private List<FieldModel> fields;
public EntityModel addField(FieldModel fieldModel) public EntityModel addField(FieldModel fieldModel) {
{ if (fields == null)
if(fields==null) fields = new ArrayList<>();
fields=new ArrayList<>();
fields.add(fieldModel); fields.add(fieldModel);
return this; return this;
} }
private List<RelationshipModel> references; private List<RelationshipModel> references;
public EntityModel addReference(RelationshipModel relationshipModel) public EntityModel addReference(RelationshipModel relationshipModel) {
{ if (references == null)
if(references==null) references = new ArrayList<>();
references=new ArrayList<>();
references.add(relationshipModel); references.add(relationshipModel);
return this; return this;
} }
public boolean isHasReferences() public boolean isHasReferences() {
{
return !ObjectUtils.isEmpty(references); return !ObjectUtils.isEmpty(references);
} }
public boolean hasPhisicalLinkField=false; public boolean hasPhisicalLinkField = false;
private Map<String,RelationshipModel> refMaps; private Map<String, RelationshipModel> refMaps;
public Map<String,RelationshipModel> getRefMaps() public Map<String, RelationshipModel> getRefMaps() {
{ if (refMaps == null)
if(refMaps==null) refMaps = new LinkedHashMap<>();
refMaps=new LinkedHashMap<>(); if (references != null) {
if(references!=null) references.forEach(ship -> {
{ if (!StringUtils.isEmpty(ship.getCodeName()))
references.forEach(ship->{ refMaps.put(ship.getCodeName().toString(), ship);
if(!StringUtils.isEmpty(ship.getCodeName())) String fkname = DataObject.getStringValue(ship.getName(), "");
refMaps.put(ship.getCodeName().toString(),ship); if (!StringUtils.isEmpty(fkname))
String fkname= DataObject.getStringValue(ship.getName(),"");
if(!StringUtils.isEmpty(fkname))
refMaps.put(fkname, ship); refMaps.put(fkname, ship);
}); });
} }
...@@ -147,42 +136,38 @@ public class EntityModel extends BaseModel { ...@@ -147,42 +136,38 @@ public class EntityModel extends BaseModel {
private List<RelationshipModel> nesteds; private List<RelationshipModel> nesteds;
public EntityModel addNested(RelationshipModel relationshipModel) public EntityModel addNested(RelationshipModel relationshipModel) {
{ if (nesteds == null)
if(nesteds==null) nesteds = new ArrayList<>();
nesteds=new ArrayList<>();
nesteds.add(relationshipModel); nesteds.add(relationshipModel);
return this; return this;
} }
private Map<String,EntityModel> relEntitiesMap; private Map<String, EntityModel> relEntitiesMap;
public EntityModel addRelEntity(String codeName,EntityModel entityModel) public EntityModel addRelEntity(String codeName, EntityModel entityModel) {
{ if (entityModel == null || StringUtils.isEmpty(codeName) || codeName.equalsIgnoreCase(this.codeName))
if(entityModel==null||StringUtils.isEmpty(codeName)||codeName.equalsIgnoreCase(this.codeName))
return this; return this;
if(relEntitiesMap==null) if (relEntitiesMap == null)
relEntitiesMap=new LinkedHashMap<>(); relEntitiesMap = new LinkedHashMap<>();
relEntitiesMap.put(codeName,entityModel); relEntitiesMap.put(codeName, entityModel);
return this; return this;
} }
public Collection<EntityModel> getRelEntities() public Collection<EntityModel> getRelEntities() {
{ if (relEntitiesMap == null) {
if(relEntitiesMap==null) if (this.references != null)
{ references.forEach(item -> {
if(this.references!=null) this.addRelEntity(item.getEntityCodeName(), item.getRelEntity());
references.forEach(item-> {
this.addRelEntity(item.getEntityCodeName(),item.getRelEntity());
}); });
if(this.nesteds!=null) if (this.nesteds != null)
nesteds.forEach(item-> { nesteds.forEach(item -> {
this.addRelEntity(item.getEntityCodeName(),item.getRelEntity()); this.addRelEntity(item.getEntityCodeName(), item.getRelEntity());
}); });
if(this.indexRelation!=null) if (this.indexRelation != null)
this.addRelEntity(this.indexRelation.getEntityCodeName(),this.indexRelation.getRelEntity()); this.addRelEntity(this.indexRelation.getEntityCodeName(), this.indexRelation.getRelEntity());
} }
if(relEntitiesMap!=null) if (relEntitiesMap != null)
return relEntitiesMap.values(); return relEntitiesMap.values();
return new ArrayList<>(); return new ArrayList<>();
} }
...@@ -190,31 +175,26 @@ public class EntityModel extends BaseModel { ...@@ -190,31 +175,26 @@ public class EntityModel extends BaseModel {
private Map<String, FieldModel> fieldMap = null; private Map<String, FieldModel> fieldMap = null;
public Map<String, FieldModel> getFieldMap() {
public Map<String, FieldModel> getFieldMap() if (fields != null && fieldMap == null) {
{ fieldMap = new LinkedHashMap<>();
if(fields!=null&&fieldMap==null) fields.forEach(field -> {
{ fieldMap.put(field.getFieldName(), field);
fieldMap=new LinkedHashMap<>(); fieldMap.put(field.getCodeName().toString(), field);
fields.forEach(field->{
fieldMap.put(field.getFieldName(),field);
fieldMap.put(field.getCodeName().toString(),field);
}); });
} }
return fieldMap; return fieldMap;
} }
private FieldModel lastModifyField; private FieldModel lastModifyField;
public FieldModel getLastModifyField() { public FieldModel getLastModifyField() {
if(fields!=null&&lastModifyField==null) if (fields != null && lastModifyField == null)
for(FieldModel fieldModel:fields) for (FieldModel fieldModel : fields)
if(fieldModel.isLastModifyField()) if (fieldModel.isLastModifyField()) {
{ lastModifyField = fieldModel;
lastModifyField=fieldModel;
return lastModifyField; return lastModifyField;
} }
return lastModifyField; return lastModifyField;
...@@ -226,21 +206,17 @@ public class EntityModel extends BaseModel { ...@@ -226,21 +206,17 @@ public class EntityModel extends BaseModel {
public FieldModel getOrgField() { public FieldModel getOrgField() {
if(fields!=null&&orgField==null) if (fields != null && orgField == null)
for(FieldModel fieldModel:fields) for (FieldModel fieldModel : fields)
if(fieldModel.isOrgField()) if (fieldModel.isOrgField()) {
{ orgField = fieldModel;
orgField=fieldModel;
return orgField; return orgField;
} }
return orgField; return orgField;
} }
public boolean isLogicValid() {
public boolean isLogicValid()
{
return getDataEntity().isLogicValid(); return getDataEntity().isLogicValid();
} }
...@@ -249,7 +225,7 @@ public class EntityModel extends BaseModel { ...@@ -249,7 +225,7 @@ public class EntityModel extends BaseModel {
public FieldModel getLogicValidField() { public FieldModel getLogicValidField() {
if(isLogicValid()&&logicValidField==null) { if (isLogicValid() && logicValidField == null) {
if (fields != null) { if (fields != null) {
for (FieldModel fieldModel : fields) { for (FieldModel fieldModel : fields) {
if (fieldModel.isLogicValidField()) { if (fieldModel.isLogicValidField()) {
...@@ -263,21 +239,18 @@ public class EntityModel extends BaseModel { ...@@ -263,21 +239,18 @@ public class EntityModel extends BaseModel {
} }
public String getValidLogicValue() {
public String getValidLogicValue() String validLogicValue = this.getDataEntity().getValidLogicValue();
{ if (StringUtils.isEmpty(validLogicValue))
String validLogicValue=this.getDataEntity().getValidLogicValue(); validLogicValue = "1";
if(StringUtils.isEmpty(validLogicValue))
validLogicValue="1";
return validLogicValue; return validLogicValue;
} }
public String getInvalidLogicValue() public String getInvalidLogicValue() {
{ String invalidLogicValue = this.getDataEntity().getInvalidLogicValue();
String invalidLogicValue=this.getDataEntity().getInvalidLogicValue(); if (StringUtils.isEmpty(invalidLogicValue))
if(StringUtils.isEmpty(invalidLogicValue)) invalidLogicValue = "0";
invalidLogicValue="0";
return invalidLogicValue; return invalidLogicValue;
} }
...@@ -286,32 +259,29 @@ public class EntityModel extends BaseModel { ...@@ -286,32 +259,29 @@ public class EntityModel extends BaseModel {
public FieldModel getKeyField() { public FieldModel getKeyField() {
if(fields!=null&&keyField==null) { if (fields != null && keyField == null) {
for(FieldModel fieldModel:fields){ for (FieldModel fieldModel : fields) {
if(fieldModel.isKeyDEField()) { if (fieldModel.isKeyDEField()) {
keyField=fieldModel; keyField = fieldModel;
break; break;
} }
} }
if((!keyField.isPhisicalDEField())&&getUnionKeyFields().size()==1) if ((!keyField.isPhisicalDEField()) && getUnionKeyFields().size() == 1) {
{ keyField = unionKeyFields.get(0);
keyField=unionKeyFields.get(0);
} }
} }
return keyField; return keyField;
} }
private List<FieldModel> unionKeyFields; private List<FieldModel> unionKeyFields;
public List<FieldModel> getUnionKeyFields() { public List<FieldModel> getUnionKeyFields() {
if(fields!=null&&unionKeyFields==null) { if (fields != null && unionKeyFields == null) {
unionKeyFields = new ArrayList<>(); unionKeyFields = new ArrayList<>();
if(getDataEntity().getUnionKeyValuePSDEFields()!=null) if (getDataEntity().getUnionKeyValuePSDEFields() != null) {
{ getDataEntity().getUnionKeyValuePSDEFields().forEach(def -> {
getDataEntity().getUnionKeyValuePSDEFields().forEach(def->{
unionKeyFields.add(getFieldMap().get(def.getCodeName())); unionKeyFields.add(getFieldMap().get(def.getCodeName()));
}); });
} }
...@@ -319,133 +289,124 @@ public class EntityModel extends BaseModel { ...@@ -319,133 +289,124 @@ public class EntityModel extends BaseModel {
return unionKeyFields; return unionKeyFields;
} }
public boolean isUnionKeyMode(){ public boolean isUnionKeyMode() {
return !ObjectUtils.isEmpty(getUnionKeyFields()); return !ObjectUtils.isEmpty(getUnionKeyFields());
} }
public List<FieldModel> getKeyFields() { public List<FieldModel> getKeyFields() {
if(this.getKeyField()!=null&&this.getKeyField().isPhisicalDEField()) { if (this.getKeyField() != null && this.getKeyField().isPhisicalDEField()) {
List<FieldModel> keyFields = new ArrayList<>(); List<FieldModel> keyFields = new ArrayList<>();
keyFields.add(getKeyField()); keyFields.add(getKeyField());
return keyFields; return keyFields;
} } else
else
return getUnionKeyFields(); return getUnionKeyFields();
} }
public List<FieldModel> getQuickSearchFields() { public List<FieldModel> getQuickSearchFields() {
return fields.stream().filter(s->s.getDataEntityField().isEnableQuickSearch()).collect(Collectors.toList()); return fields.stream().filter(s -> s.getDataEntityField().isEnableQuickSearch()).collect(Collectors.toList());
} }
private Map<String, ActionModel> actions; private Map<String, ActionModel> actions;
public EntityModel addAction(ActionModel action) public EntityModel addAction(ActionModel action) {
{ if (actions == null)
if(actions==null) actions = new LinkedHashMap<>();
actions=new LinkedHashMap<>(); actions.put(StringAdvUtils.camelcase(action.getCodeName()), action);
actions.put(StringAdvUtils.camelcase(action.getCodeName()),action);
return this; return this;
} }
private static Set<String> ignoActions=new HashSet<String>(){{ private static Set<String> ignoActions = new HashSet<String>() {{
add("get");add("create");add("update");add("remove");add("save");add("getdraft");add("checkkey"); add("get");
add("createbatch");add("savebatch");add("updatebatch");add("removebatch"); add("create");
add("update");
add("remove");
add("save");
add("getdraft");
add("checkkey");
add("createbatch");
add("savebatch");
add("updatebatch");
add("removebatch");
}}; }};
public List<ActionModel> getExtActions() public List<ActionModel> getExtActions() {
{ return actions.values().stream().filter(s -> !ignoActions.contains(s.getCodeName().toLowerCase())).collect(Collectors.toList());
return actions.values().stream().filter(s->!ignoActions.contains(s.getCodeName().toLowerCase())).collect(Collectors.toList());
} }
public String getDsName() public String getDsName() {
{ String dsName = this.getDataEntity().getDSLink();
String dsName=this.getDataEntity().getDSLink(); if (StringUtils.isEmpty(dsName) || "DEFAULT".equalsIgnoreCase(dsName))
if(StringUtils.isEmpty(dsName)||"DEFAULT".equalsIgnoreCase(dsName)) dsName = null;
dsName=null;
else else
dsName=dsName.toLowerCase(); dsName = dsName.toLowerCase();
return dsName; return dsName;
} }
public String getTableName(String dsType) {
public String getTableName(String dsType) return this.getStringValue("table-" + dsType.toLowerCase(), getTableName());
{
return this.getStringValue("table-"+dsType.toLowerCase(),getTableName());
} }
private String storage = "SQL";
public void setStorage(Integer type) {
switch (type) {
private String storage="SQL";
public void setStorage(Integer type)
{
switch(type){
case 0: case 0:
this.storage="NONE"; this.storage = "NONE";
break; break;
case 1: case 1:
this.storage="SQL"; this.storage = "SQL";
break; break;
case 2: case 2:
this.storage="NoSQL"; this.storage = "NoSQL";
break; break;
case 4: case 4:
this.storage="ServiceAPI"; this.storage = "ServiceAPI";
break; break;
default: default:
this.storage="SQL"; this.storage = "SQL";
break; break;
} }
} }
public void setStorage(String type)
{
this.storage=type;
}
public void setStorage(String type) {
this.storage = type;
}
private RelationshipModel indexRelation; private RelationshipModel indexRelation;
public boolean isIndexSubDE() public boolean isIndexSubDE() {
{ if (this.getIndexRelation() != null)
if(this.getIndexRelation()!=null)
return true; return true;
return false; return false;
} }
public boolean isLogicInherit() public boolean isLogicInherit() {
{ if (this.getIndexRelation() == null)
if(this.getIndexRelation()==null)
return false; return false;
IPSDERBase MinorPSDER = this.getIndexRelation().getDer(); IPSDERBase MinorPSDER = this.getIndexRelation().getDer();
if("DERINHERIT".equals(MinorPSDER.getDERType()) && MinorPSDER instanceof IPSDERInherit) if ("DERINHERIT".equals(MinorPSDER.getDERType()) && MinorPSDER instanceof IPSDERInherit) {
{ return ((IPSDERInherit) MinorPSDER).isLogicInherit();
return ((IPSDERInherit)MinorPSDER).isLogicInherit();
} }
return false; return false;
} }
public boolean isHasPSDERsMapping() public boolean isHasPSDERsMapping() {
{ if (this.getReferences() != null) {
if(this.getReferences()!=null) for (RelationshipModel rel : this.getReferences()) {
{
for(RelationshipModel rel:this.getReferences())
{
if(rel.getRelEntity().getStorage().equals("NONE")) if (rel.getRelEntity().getStorage().equals("NONE"))
continue; continue;
if(!(rel.getDer() instanceof PSDER1NImpl)) if (!(rel.getDer() instanceof PSDER1NImpl))
continue; continue;
if(((PSDER1NImpl)rel.getDer()).getPSDER1NDEFieldMaps()==null) if (((PSDER1NImpl) rel.getDer()).getPSDER1NDEFieldMaps() == null)
continue; continue;
for(IPSDER1NDEFieldMap derField : ((PSDER1NImpl)rel.getDer()).getPSDER1NDEFieldMaps()) for (IPSDER1NDEFieldMap derField : ((PSDER1NImpl) rel.getDer()).getPSDER1NDEFieldMaps()) {
{ if (derField.getMapType().equals("COUNT") || derField.getMapType().equals("SUM")
if(derField.getMapType().equals("COUNT") || derField.getMapType().equals("SUM")
|| derField.getMapType().equals("AVG") || derField.getMapType().equals("MAX") || derField.getMapType().equals("MIN")) || derField.getMapType().equals("AVG") || derField.getMapType().equals("MAX") || derField.getMapType().equals("MIN"))
return true; return true;
} }
...@@ -454,37 +415,30 @@ public class EntityModel extends BaseModel { ...@@ -454,37 +415,30 @@ public class EntityModel extends BaseModel {
return false; return false;
} }
public boolean isEnableES() public boolean isEnableES() {
{
return "elasticsearch".equalsIgnoreCase(this.getDataEntity().getUserTag()); return "elasticsearch".equalsIgnoreCase(this.getDataEntity().getUserTag());
} }
public boolean isHasDupCheck() public boolean isHasDupCheck() {
{ if (this.getDefaultDataQuery() == null)
if(this.getDefaultDataQuery()==null)
return false; return false;
if(getDataEntity().getStorageMode()!=1&&getDataEntity().getStorageMode()!=2) if (getDataEntity().getStorageMode() != 1 && getDataEntity().getStorageMode() != 2)
return false; return false;
for(IPSDEField field:getDataEntity().getAllPSDEFields()) for (IPSDEField field : getDataEntity().getAllPSDEFields()) {
{ if ("ALL".equalsIgnoreCase(field.getDupCheckMode()))
if("ALL".equalsIgnoreCase(field.getDupCheckMode()))
return true; return true;
} }
return false; return false;
} }
public boolean isNeedTypeHandler() public boolean isNeedTypeHandler() {
{ if (!"NONE".equalsIgnoreCase(getStorage()))
if(!"NONE".equalsIgnoreCase(getStorage()))
return false; return false;
if(isHasReferences()) if (isHasReferences()) {
{ for (RelationshipModel ref : getReferences()) {
for(RelationshipModel ref:getReferences()) if (ref.getDer() instanceof IPSDER1N && ref.getRelEntity().getStorage().equalsIgnoreCase("SQL")) {
{ IPSDEField def = ((IPSDER1N) ref.getDer()).getPSOne2ManyDataDEField();
if(ref.getDer() instanceof IPSDER1N && ref.getRelEntity().getStorage().equalsIgnoreCase("SQL")) if (def != null && def.isPhisicalDEField())
{
IPSDEField def=((IPSDER1N) ref.getDer()).getPSOne2ManyDataDEField();
if(def!=null&&def.isPhisicalDEField())
return true; return true;
} }
} }
...@@ -492,23 +446,20 @@ public class EntityModel extends BaseModel { ...@@ -492,23 +446,20 @@ public class EntityModel extends BaseModel {
return false; return false;
} }
public List getMqPublishers() public List getMqPublishers() {
{ List publishers = new ArrayList();
List publishers=new ArrayList(); if (getDataEntity().getAllPSDEDataSyncs() != null) {
if(getDataEntity().getAllPSDEDataSyncs()!=null) getDataEntity().getAllPSDEDataSyncs().forEach(dataSync -> {
{ if (dataSync.getOutPSSysDataSyncAgent() != null && dataSync.getEventType() != 0) {
getDataEntity().getAllPSDEDataSyncs().forEach(dataSync->{ Map map = new HashMap();
if(dataSync.getOutPSSysDataSyncAgent()!=null&&dataSync.getEventType()!=0) map.put("dataSync", dataSync);
{ Set<String> monitors = new LinkedHashSet<>();
Map map=new HashMap(); map.put("monitors", monitors);
map.put("dataSync",dataSync); if ((dataSync.getEventType() & 1) > 0)
Set<String> monitors=new LinkedHashSet<>();
map.put("monitors",monitors);
if((dataSync.getEventType()&1)>0)
monitors.add("create"); monitors.add("create");
if((dataSync.getEventType()&2)>0) if ((dataSync.getEventType() & 2) > 0)
monitors.add("update"); monitors.add("update");
if((dataSync.getEventType()&4)>0) if ((dataSync.getEventType() & 4) > 0)
monitors.add("remove"); monitors.add("remove");
publishers.add(map); publishers.add(map);
} }
...@@ -518,172 +469,151 @@ public class EntityModel extends BaseModel { ...@@ -518,172 +469,151 @@ public class EntityModel extends BaseModel {
} }
private List<OptionItem> dataScopes; private List<OptionItem> dataScopes;
public List<OptionItem> getDataScopes()
{ public List<OptionItem> getDataScopes() {
if(dataScopes==null) if (dataScopes == null) {
{ dataScopes = new ArrayList<>();
dataScopes=new ArrayList<>();
dataScopes.add(new OptionItem().setId("all").setName("全部数据")); dataScopes.add(new OptionItem().setId("all").setName("全部数据"));
boolean hasOrgId=false,hasDetpId=false,hasCreateBy=false; boolean hasOrgId = false, hasDetpId = false, hasCreateBy = false;
for(FieldModel field:getFields()) for (FieldModel field : getFields()) {
{ if ("ORGID".equalsIgnoreCase(field.getDataEntityField().getPredefinedType()))
if("ORGID".equalsIgnoreCase(field.getDataEntityField().getPredefinedType())) hasOrgId = true;
hasOrgId=true; else if ("ORGSECTORID".equalsIgnoreCase(field.getDataEntityField().getPredefinedType()))
else if("ORGSECTORID".equalsIgnoreCase(field.getDataEntityField().getPredefinedType())) hasDetpId = true;
hasDetpId=true; else if ("CREATEMAN".equalsIgnoreCase(field.getDataEntityField().getPredefinedType()))
else if("CREATEMAN".equalsIgnoreCase(field.getDataEntityField().getPredefinedType())) hasCreateBy = true;
hasCreateBy=true; }
} if (hasOrgId) {
if(hasOrgId)
{
dataScopes.add(new OptionItem().setId("curorg").setName("当前单位")); dataScopes.add(new OptionItem().setId("curorg").setName("当前单位"));
dataScopes.add(new OptionItem().setId("porg").setName("上级单位")); dataScopes.add(new OptionItem().setId("porg").setName("上级单位"));
dataScopes.add(new OptionItem().setId("sorg").setName("下级单位")); dataScopes.add(new OptionItem().setId("sorg").setName("下级单位"));
} }
if(hasDetpId) if (hasDetpId) {
{
dataScopes.add(new OptionItem().setId("curorgdept").setName("当前部门")); dataScopes.add(new OptionItem().setId("curorgdept").setName("当前部门"));
dataScopes.add(new OptionItem().setId("porgdept").setName("上级部门")); dataScopes.add(new OptionItem().setId("porgdept").setName("上级部门"));
dataScopes.add(new OptionItem().setId("sorgdept").setName("下级部门")); dataScopes.add(new OptionItem().setId("sorgdept").setName("下级部门"));
} }
if(hasCreateBy) if (hasCreateBy)
dataScopes.add(new OptionItem().setId("createman").setName("创建人")); dataScopes.add(new OptionItem().setId("createman").setName("创建人"));
} }
return dataScopes; return dataScopes;
} }
public boolean isHasScopes() { public boolean isHasScopes() {
return getDataScopes().size()>1; return getDataScopes().size() > 1;
} }
private Map<String, POSchema> poSchemas; private Map<String, POSchema> poSchemas;
public POSchema getDefaultPOSchema() public POSchema getDefaultPOSchema() {
{
return getPOSchema("default"); return getPOSchema("default");
} }
public EntityModel addPOSchema(String name, POSchema poSchema)
{ public EntityModel addPOSchema(String name, POSchema poSchema) {
if(poSchema!=null) if (poSchema != null) {
{ if (poSchemas == null)
if(poSchemas==null) poSchemas = new LinkedHashMap<>();
poSchemas=new LinkedHashMap<>(); poSchemas.put(name, poSchema.build());
poSchemas.put(name,poSchema.build());
} }
return this; return this;
} }
public POSchema getPOSchema(String name)
{
if(StringUtils.isEmpty(name)&&(!StringUtils.isEmpty(this.getDsName()))) public POSchema getPOSchema(String name) {
name=this.getDsName();
if(StringUtils.isEmpty(name)) if (StringUtils.isEmpty(name) && (!StringUtils.isEmpty(this.getDsName())))
name="mysql"; name = this.getDsName();
if (StringUtils.isEmpty(name))
name = "mysql";
if(poSchemas==null) if (poSchemas == null)
poSchemas=new LinkedHashMap<>(); poSchemas = new LinkedHashMap<>();
if(poSchemas.containsKey(name)) if (poSchemas.containsKey(name)) {
{
return poSchemas.get(name); return poSchemas.get(name);
} }
String vendorProvider=POSchema.provider.get(name.toLowerCase()); String vendorProvider = POSchema.provider.get(name.toLowerCase());
if((!StringUtils.isEmpty(vendorProvider))&&(!name.equalsIgnoreCase(vendorProvider))&&poSchemas.containsKey(vendorProvider)) if ((!StringUtils.isEmpty(vendorProvider)) && (!name.equalsIgnoreCase(vendorProvider)) && poSchemas.containsKey(vendorProvider))
return poSchemas.get(vendorProvider); return poSchemas.get(vendorProvider);
if(poSchemas.size()>0) if (poSchemas.size() > 0)
return poSchemas.values().iterator().next(); return poSchemas.values().iterator().next();
return null; return null;
} }
public String getStringValue(String key, String defaultVal) {
public String getStringValue(String key,String defaultVal) return extParams.getStringValue(key, defaultVal);
{
return extParams.getStringValue(key,defaultVal);
} }
private boolean hasResetField=false; private boolean hasResetField = false;
private ClientEntityModel clientEntityModel;
public EntityModel(SystemModel systemModel,IPSDataEntity dataEntity) public EntityModel(SystemModel systemModel, IPSDataEntity dataEntity) {
{ Assert.notNull(dataEntity, "未找到对应的实体模型:" + dataEntity.getId());
Assert.notNull(dataEntity,"未找到对应的实体模型:"+dataEntity.getId()); this.opt = dataEntity;
this.opt=dataEntity; this.system = systemModel;
this.system=systemModel;
this.setCodeName(dataEntity.getCodeName()); this.setCodeName(dataEntity.getCodeName());
this.setName(dataEntity.getName()); this.setName(dataEntity.getName());
this.setStorage(dataEntity.getStorageMode()); this.setStorage(dataEntity.getStorageMode());
List<String> dsTypes=new ArrayList<>(); List<String> dsTypes = new ArrayList<>();
if(dataEntity.getAllPSDEDBConfigs()!=null) if (dataEntity.getAllPSDEDBConfigs() != null) {
{ dataEntity.getAllPSDEDBConfigs().forEach(item -> {
dataEntity.getAllPSDEDBConfigs().forEach(item->{ String dbType = item.getDBType().toLowerCase().replace("mysql5", "mysql");
String dbType=item.getDBType().toLowerCase().replace("mysql5","mysql"); if ("mysql".equals(dbType))
if("mysql".equals(dbType))
system.setEnableMysql(true); system.setEnableMysql(true);
else if("oracle".equals(dbType)) else if ("oracle".equals(dbType))
system.setEnableOracle(true); system.setEnableOracle(true);
else if("postgresql".equals(dbType)) else if ("postgresql".equals(dbType))
system.setEnablePostgreSQL(true); system.setEnablePostgreSQL(true);
else if("dameng".equals(dbType)||"dm".equals(dbType)) else if ("dameng".equals(dbType) || "dm".equals(dbType))
system.setEnableDameng(true); system.setEnableDameng(true);
dsTypes.add(dbType); dsTypes.add(dbType);
if(this.getTableName()!=null && (!this.getTableName().equalsIgnoreCase(item.getTableName()))) if (this.getTableName() != null && (!this.getTableName().equalsIgnoreCase(item.getTableName())))
this.set("table-"+item.getDBType().toLowerCase().replace("mysql5","mysql"),item.getTableName()); this.set("table-" + item.getDBType().toLowerCase().replace("mysql5", "mysql"), item.getTableName());
}); });
} }
if (dataEntity.getMinorPSDERs() != null) {
for (IPSDERBase der : dataEntity.getMinorPSDERs()) {
if(dataEntity.getMinorPSDERs()!=null) RelationshipModel rel = new RelationshipModel(this, der);
{
for(IPSDERBase der : dataEntity.getMinorPSDERs())
{
RelationshipModel rel=new RelationshipModel(this,der);
rel.setRelationType("reference").setCodeName(der.getCodeName()).setEntityId(der.getMajorPSDataEntity().getId()) rel.setRelationType("reference").setCodeName(der.getCodeName()).setEntityId(der.getMajorPSDataEntity().getId())
.setEntityCodeName(der.getMajorPSDataEntity().getCodeName()).setEntityName(der.getMajorPSDataEntity().getName()) .setEntityCodeName(der.getMajorPSDataEntity().getCodeName()).setEntityName(der.getMajorPSDataEntity().getName())
.setEntityLogicName(der.getMajorPSDataEntity().getLogicName()).setTableName(der.getMajorPSDataEntity().getTableName()); .setEntityLogicName(der.getMajorPSDataEntity().getLogicName()).setTableName(der.getMajorPSDataEntity().getTableName());
if(der.getMajorPSDataEntity().getPSSystemModule()!=null) if (der.getMajorPSDataEntity().getPSSystemModule() != null)
rel.setModule(der.getMajorPSDataEntity().getPSSystemModule().getCodeName().toLowerCase()); rel.setModule(der.getMajorPSDataEntity().getPSSystemModule().getCodeName().toLowerCase());
if (der instanceof IPSDER1N) {
IPSDER1N der1n = (IPSDER1N) der;
String refFieldName = der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
String refCodeName = refFieldName;
if (der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("codeName") != null)
refCodeName = der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("codeName").asText();
if(der instanceof IPSDER1N) LookupModel lookupModel = new LookupModel().setRelationid(der.getId())
{
IPSDER1N der1n=(IPSDER1N)der;
String refFieldName=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
String refCodeName=refFieldName;
if(der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("codeName")!=null)
refCodeName=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("codeName").asText();
LookupModel lookupModel=new LookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setCodeName(der1n.getPSPickupDEField().getCodeName()).setReffieldname(refFieldName).setRefCodeName(refCodeName); .setFieldname(der1n.getPickupDEFName()).setCodeName(der1n.getPSPickupDEField().getCodeName()).setReffieldname(refFieldName).setRefCodeName(refCodeName);
rel.addLookup(lookupModel); rel.addLookup(lookupModel);
} } else if (der instanceof IPSDERIndex || der instanceof IPSDERInherit) {
else if (der instanceof IPSDERIndex || der instanceof IPSDERInherit) if (der.getMajorPSDataEntity().getKeyPSDEField() != null) {
{
if(der.getMajorPSDataEntity().getKeyPSDEField()!=null)
{
LookupModel lookupModel = new LookupModel().setRelationid(der.getId()) LookupModel lookupModel = new LookupModel().setRelationid(der.getId())
.setFieldname(this.getDataEntity().getKeyPSDEField().getName()).setCodeName(this.getDataEntity().getKeyPSDEField().getCodeName()) .setFieldname(this.getDataEntity().getKeyPSDEField().getName()).setCodeName(this.getDataEntity().getKeyPSDEField().getCodeName())
.setReffieldname(der.getMajorPSDataEntity().getKeyPSDEField().getName()).setRefCodeName(der.getMajorPSDataEntity().getKeyPSDEField().getCodeName()); .setReffieldname(der.getMajorPSDataEntity().getKeyPSDEField().getName()).setRefCodeName(der.getMajorPSDataEntity().getKeyPSDEField().getCodeName());
rel.addLookup(lookupModel); rel.addLookup(lookupModel);
} }
if(der.getMajorPSDataEntity().getMajorPSDEField()!=null) if (der.getMajorPSDataEntity().getMajorPSDEField() != null) {
{
LookupModel lookupModel = new LookupModel().setRelationid(der.getId()) LookupModel lookupModel = new LookupModel().setRelationid(der.getId())
.setFieldname(this.getDataEntity().getMajorPSDEField().getName()).setCodeName(this.getDataEntity().getMajorPSDEField().getCodeName()) .setFieldname(this.getDataEntity().getMajorPSDEField().getName()).setCodeName(this.getDataEntity().getMajorPSDEField().getCodeName())
.setReffieldname(der.getMajorPSDataEntity().getMajorPSDEField().getName()).setRefCodeName(der.getMajorPSDataEntity().getMajorPSDEField().getCodeName()); .setReffieldname(der.getMajorPSDataEntity().getMajorPSDEField().getName()).setRefCodeName(der.getMajorPSDataEntity().getMajorPSDEField().getCodeName());
rel.addLookup(lookupModel); rel.addLookup(lookupModel);
} }
List<IPSDERIndexDEFieldMap> map = ((IPSDERIndex) der).getPSDERIndexDEFieldMaps(); List<IPSDERIndexDEFieldMap> map = ((IPSDERIndex) der).getPSDERIndexDEFieldMaps();
if(!ObjectUtils.isEmpty(map)) if (!ObjectUtils.isEmpty(map)) {
{ map.forEach(item -> {
map.forEach(item->{ LookupModel lookupModel = new LookupModel().setRelationid(der.getId())
LookupModel lookupModel=new LookupModel().setRelationid(der.getId())
.setFieldname(item.getMinorPSDEField().getName()).setCodeName(item.getMinorPSDEField().getCodeName()) .setFieldname(item.getMinorPSDEField().getName()).setCodeName(item.getMinorPSDEField().getCodeName())
.setReffieldname(item.getMajorPSDEField().getName()).setRefCodeName(item.getMajorPSDEField().getCodeName()); .setReffieldname(item.getMajorPSDEField().getName()).setRefCodeName(item.getMajorPSDEField().getCodeName());
rel.addLookup(lookupModel); rel.addLookup(lookupModel);
...@@ -691,22 +621,18 @@ public class EntityModel extends BaseModel { ...@@ -691,22 +621,18 @@ public class EntityModel extends BaseModel {
} }
} }
//聚合关系 暂时忽略 //聚合关系 暂时忽略
else if (der instanceof IPSDERAggData){ else if (der instanceof IPSDERAggData) {
continue; continue;
} }
if("DERINHERIT".equals(der.getDERType())) if ("DERINHERIT".equals(der.getDERType())) {
{
rel.setRelationType("inherit"); rel.setRelationType("inherit");
this.setIndexRelation(rel); this.setIndexRelation(rel);
} } else if ("DERINDEX".equals(der.getDERType())//&& der.getMajorPSDataEntity().getVirtualMode()!=3
else if("DERINDEX".equals(der.getDERType())//&& der.getMajorPSDataEntity().getVirtualMode()!=3 && der.getMajorPSDataEntity().getIndexTypePSDEField() != null) {
&& der.getMajorPSDataEntity().getIndexTypePSDEField()!=null)
{
rel.setRelationType("index"); rel.setRelationType("index");
this.setIndexRelation(rel); this.setIndexRelation(rel);
} } else {
else {
rel.setRelationType("reference"); rel.setRelationType("reference");
this.addReference(rel); this.addReference(rel);
} }
...@@ -714,52 +640,45 @@ public class EntityModel extends BaseModel { ...@@ -714,52 +640,45 @@ public class EntityModel extends BaseModel {
} }
if(dataEntity.getMajorPSDERs()!=null) if (dataEntity.getMajorPSDERs() != null) {
{ for (IPSDERBase der : dataEntity.getMajorPSDERs()) {
for(IPSDERBase der : dataEntity.getMajorPSDERs()) if (der instanceof IPSDER1N) {
{ IPSDER1N der1n = (IPSDER1N) der;
if(der instanceof IPSDER1N) String codeName = der.getMinorCodeName();
{ boolean nestedRS = false;
IPSDER1N der1n=(IPSDER1N)der; if (der1n.isNestedRS())
String codeName=der.getMinorCodeName(); nestedRS = true;
boolean nestedRS=false; else if (der1n.getPSOne2ManyDataDEField() != null) {
if(der1n.isNestedRS()) nestedRS = true;
nestedRS=true; } else if (der1n.getMinorPSDataEntity().getPSSubSysServiceAPIDE() != null && der1n.getMinorPSDataEntity().getPSSubSysServiceAPIDE().isNested()) {
else if(der1n.getPSOne2ManyDataDEField()!=null) nestedRS = true;
{
nestedRS=true;
}
else if(der1n.getMinorPSDataEntity().getPSSubSysServiceAPIDE()!=null&&der1n.getMinorPSDataEntity().getPSSubSysServiceAPIDE().isNested())
{
nestedRS=true;
} }
if(!nestedRS) if (!nestedRS)
continue; continue;
if(StringUtils.isEmpty(codeName)) if (StringUtils.isEmpty(codeName))
codeName=der.getMinorPSDataEntity().getCodeName(); codeName = der.getMinorPSDataEntity().getCodeName();
RelationshipModel rel=new RelationshipModel(this,der); RelationshipModel rel = new RelationshipModel(this, der);
rel.setRelationType("nested").setCodeName(codeName).setEntityId(der.getMinorPSDataEntity().getId()) rel.setRelationType("nested").setCodeName(codeName).setEntityId(der.getMinorPSDataEntity().getId())
.setEntityCodeName(der.getMinorPSDataEntity().getCodeName()).setEntityName(der.getMinorPSDataEntity().getName()) .setEntityCodeName(der.getMinorPSDataEntity().getCodeName()).setEntityName(der.getMinorPSDataEntity().getName())
.setEntityLogicName(der.getMinorPSDataEntity().getLogicName()).setTableName(der.getMinorPSDataEntity().getTableName()); .setEntityLogicName(der.getMinorPSDataEntity().getLogicName()).setTableName(der.getMinorPSDataEntity().getTableName());
if(der.getMinorPSDataEntity().getPSSystemModule()!=null) if (der.getMinorPSDataEntity().getPSSystemModule() != null)
rel.setModule(der.getMinorPSDataEntity().getPSSystemModule().getCodeName().toLowerCase()); rel.setModule(der.getMinorPSDataEntity().getPSSystemModule().getCodeName().toLowerCase());
if(der1n.getPSOne2ManyDataDEField()!=null&&der1n.getPSOne2ManyDataDEField().isPhisicalDEField()&&der1n.getMinorPSDataEntity().getStorageMode()==0) if (der1n.getPSOne2ManyDataDEField() != null && der1n.getPSOne2ManyDataDEField().isPhisicalDEField() && der1n.getMinorPSDataEntity().getStorageMode() == 0) {
{
rel.setColumnName(der1n.getPSOne2ManyDataDEField().getName().toLowerCase()); rel.setColumnName(der1n.getPSOne2ManyDataDEField().getName().toLowerCase());
rel.setCodeName(der1n.getPSOne2ManyDataDEField().getCodeName()); rel.setCodeName(der1n.getPSOne2ManyDataDEField().getCodeName());
} }
rel.setFkFieldCodeName(der1n.getPSPickupDEField().getCodeName()); rel.setFkFieldCodeName(der1n.getPSPickupDEField().getCodeName());
String refFieldName=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText(); String refFieldName = der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
String refCodeName=refFieldName; String refCodeName = refFieldName;
if(der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("codeName")!=null) if (der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("codeName") != null)
refCodeName=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("codeName").asText(); refCodeName = der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("codeName").asText();
LookupModel lookupModel=new LookupModel().setRelationid(der.getId()) LookupModel lookupModel = new LookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setCodeName(der1n.getPSPickupDEField().getCodeName()).setReffieldname(refFieldName).setRefCodeName(refCodeName); .setFieldname(der1n.getPickupDEFName()).setCodeName(der1n.getPSPickupDEField().getCodeName()).setReffieldname(refFieldName).setRefCodeName(refCodeName);
rel.addLookup(lookupModel); rel.addLookup(lookupModel);
...@@ -770,55 +689,49 @@ public class EntityModel extends BaseModel { ...@@ -770,55 +689,49 @@ public class EntityModel extends BaseModel {
} }
} }
Map<String,FieldModel> fieldMaps=new LinkedHashMap<>(); Map<String, FieldModel> fieldMaps = new LinkedHashMap<>();
for(IPSDEField defield:dataEntity.getAllPSDEFields()) for (IPSDEField defield : dataEntity.getAllPSDEFields()) {
{
if(defield.isPasteReset()) if (defield.isPasteReset())
this.hasResetField=true; this.hasResetField = true;
FieldModel fieldModel=new FieldModel(this,defield); FieldModel fieldModel = new FieldModel(this, defield);
if(defield.isMajorDEField()) if (defield.isMajorDEField())
this.majorField=fieldModel; this.majorField = fieldModel;
try { try {
fieldModel.setDict(defield.getPSCodeList()!=null?defield.getPSCodeList().getCodeName():null); fieldModel.setDict(defield.getPSCodeList() != null ? defield.getPSCodeList().getCodeName() : null);
} catch (Exception ex){} } catch (Exception ex) {
}
if(defield.getAllPSDEFDTColumns()!=null)
{ if (defield.getAllPSDEFDTColumns() != null) {
defield.getAllPSDEFDTColumns().forEach(col->{ defield.getAllPSDEFDTColumns().forEach(col -> {
if(!fieldModel.getFieldName().equalsIgnoreCase(col.getColumnName())) if (!fieldModel.getFieldName().equalsIgnoreCase(col.getColumnName()))
fieldModel.set("column-"+col.getDBType().toLowerCase().replace("mysql5","mysql"),col.getColumnName()); fieldModel.set("column-" + col.getDBType().toLowerCase().replace("mysql5", "mysql"), col.getColumnName());
if(StringUtils.isEmpty(fieldModel)&&defield.isFormulaDEField()&&(!StringUtils.isEmpty(col.getQueryCodeExp()))) if (StringUtils.isEmpty(fieldModel) && defield.isFormulaDEField() && (!StringUtils.isEmpty(col.getQueryCodeExp())))
fieldModel.setExpression(col.getQueryCodeExp().replace("`","").replace("[","").replace("]","")); fieldModel.setExpression(col.getQueryCodeExp().replace("`", "").replace("[", "").replace("]", ""));
}); });
} }
if(defield.isLinkDEField() && defield instanceof IPSLinkDEField) if (defield.isLinkDEField() && defield instanceof IPSLinkDEField) {
{ IPSLinkDEField linkDEField = (IPSLinkDEField) defield;
IPSLinkDEField linkDEField = (IPSLinkDEField)defield; String relfieldname = linkDEField.getObjectNode().get("getRelatedPSDEField").get("name").asText();
String relfieldname=linkDEField.getObjectNode().get("getRelatedPSDEField").get("name").asText(); String relfieldcodename = linkDEField.getObjectNode().get("getRelatedPSDEField").get("codeName").asText();
String relfieldcodename=linkDEField.getObjectNode().get("getRelatedPSDEField").get("codeName").asText();
linkDEField.getRelatedPSDEField(); linkDEField.getRelatedPSDEField();
fieldModel.setRefFieldName(relfieldname).setRefFieldCodeName(relfieldcodename); fieldModel.setRefFieldName(relfieldname).setRefFieldCodeName(relfieldcodename);
if(!StringUtils.isEmpty(linkDEField.getPSDER().getCodeName())) if (!StringUtils.isEmpty(linkDEField.getPSDER().getCodeName())) {
{ RelationshipModel relationshipModel = this.getRefMaps().get(linkDEField.getPSDER().getCodeName());
RelationshipModel relationshipModel=this.getRefMaps().get(linkDEField.getPSDER().getCodeName()); if (relationshipModel != null && (!StringUtils.isEmpty(relationshipModel.getCodeName()))) {
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getCodeName()))) {
relationshipModel.addField(fieldModel); relationshipModel.addField(fieldModel);
fieldModel.setReference(relationshipModel); fieldModel.setReference(relationshipModel);
if("PICKUP".equalsIgnoreCase(defield.getDataType())) { if ("PICKUP".equalsIgnoreCase(defield.getDataType())) {
relationshipModel.setFkField(fieldModel); relationshipModel.setFkField(fieldModel);
relationshipModel.setFkFieldCodeName(fieldModel.getCodeName().toString()); relationshipModel.setFkFieldCodeName(fieldModel.getCodeName().toString());
} } else if (defield.isPhisicalDEField() || (!StringUtils.isEmpty(defield.getUnionKeyValue()))) {
else if(defield.isPhisicalDEField()||(!StringUtils.isEmpty(defield.getUnionKeyValue()))) hasPhisicalLinkField = true;
{
hasPhisicalLinkField=true;
} }
} }
} }
...@@ -826,49 +739,43 @@ public class EntityModel extends BaseModel { ...@@ -826,49 +739,43 @@ public class EntityModel extends BaseModel {
} }
fieldMaps.put(fieldModel.getFieldName(), fieldModel);
fieldMaps.put(fieldModel.getFieldName(),fieldModel);
this.addField(fieldModel); this.addField(fieldModel);
} }
if (dataEntity.getAllPSDEDataQueries() != null) {
if(dataEntity.getAllPSDEDataQueries()!=null) dataEntity.getAllPSDEDataQueries().forEach(dataQuery -> {
{
dataEntity.getAllPSDEDataQueries().forEach(dataQuery->{
try { try {
if(dataQuery.getAllPSDEDataQueryCodes()!=null) if (dataQuery.getAllPSDEDataQueryCodes() != null) {
{ dataQuery.getAllPSDEDataQueryCodes().forEach(dq -> {
dataQuery.getAllPSDEDataQueryCodes().forEach(dq->{ if (StringUtils.isEmpty(dq.getQueryCode()))
if(StringUtils.isEmpty(dq.getQueryCode()))
return; return;
String select=TransUtils.contextParamConvert(dq.getQueryCode()); String select = TransUtils.contextParamConvert(dq.getQueryCode());
String where=null; String where = null;
if(dq.getPSDEDataQueryCodeConds()!=null) if (dq.getPSDEDataQueryCodeConds() != null) {
{ int i = 0;
int i=0; boolean b = TransUtils.checkIgnoreNullvalueCond(dq.getPSDEDataQueryCodeConds());
boolean b=TransUtils.checkIgnoreNullvalueCond(dq.getPSDEDataQueryCodeConds()); for (IPSDEDataQueryCodeCond cond : dq.getPSDEDataQueryCodeConds()) {
for(IPSDEDataQueryCodeCond cond:dq.getPSDEDataQueryCodeConds()) if (i == 0)
{ where = " where ";
if(i==0) else if (i > 0)
where=" where "; where = where.concat(" and ");
else if(i>0)
where=where.concat(" and "); where = where.concat(b ? TransUtils.checkNullContextParamConvert(cond.getCustomCond()) : TransUtils.contextParamConvert(cond.getCustomCond()));
where=where.concat(b?TransUtils.checkNullContextParamConvert(cond.getCustomCond()):TransUtils.contextParamConvert(cond.getCustomCond()));
i++; i++;
} }
} }
DataSetModel dsModel=new DataSetModel(); DataSetModel dsModel = new DataSetModel();
dsModel.setEntity(this); dsModel.setEntity(this);
dsModel.setName(dataQuery.getName()); dsModel.setName(dataQuery.getName());
dsModel.setDatasetId(this.getEntityName().toLowerCase()+"-dq-"+dataQuery.getCodeName()+"-"+dq.getDBType().toLowerCase().replace("mysql5","mysql")) dsModel.setDatasetId(this.getEntityName().toLowerCase() + "-dq-" + dataQuery.getCodeName() + "-" + dq.getDBType().toLowerCase().replace("mysql5", "mysql"))
.setDsType(dq.getDBType().toLowerCase().replace("mysql5","mysql")) .setDsType(dq.getDBType().toLowerCase().replace("mysql5", "mysql"))
.setDatasetName(dataQuery.getLogicName()).setCodeName(dataQuery.getCodeName()) .setDatasetName(dataQuery.getLogicName()).setCodeName(dataQuery.getCodeName())
.setSelect(select).setWhere(where) .setSelect(select).setWhere(where)
.setDsCode(select.concat(where==null?"":where)); .setDsCode(select.concat(where == null ? "" : where));
this.addQueries(dsModel); this.addQueries(dsModel);
this.addDataQueries(dsModel); this.addDataQueries(dsModel);
...@@ -881,65 +788,56 @@ public class EntityModel extends BaseModel { ...@@ -881,65 +788,56 @@ public class EntityModel extends BaseModel {
}); });
} }
if(dataEntity.getAllPSDEDataSets()!=null) if (dataEntity.getAllPSDEDataSets() != null) {
{ dataEntity.getAllPSDEDataSets().forEach(dataSet -> {
dataEntity.getAllPSDEDataSets().forEach(dataSet->{
String select="select t1.*"; String select = "select t1.*";
String from=" from ( %s ) t1 "; String from = " from ( %s ) t1 ";
String where=null; String where = null;
String groupBy=null; String groupBy = null;
String orderBy=null; String orderBy = null;
if(dataSet.getGroupMode()==1||dataSet.getMajorSortPSDEField()!=null) if (dataSet.getGroupMode() == 1 || dataSet.getMajorSortPSDEField() != null) {
{
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams()))) if (dataSet.getGroupMode() == 1 && (!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams()))) {
{ select = "select ";
select="select "; int i = 0;
int i=0; for (IPSDEDataSetGroupParam obj : dataSet.getPSDEDataSetGroupParams()) {
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams()) if (!(obj instanceof PSDEDataSetGroupParamImpl))
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue; continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj; PSDEDataSetGroupParamImpl groupParam = (PSDEDataSetGroupParamImpl) obj;
if(i>0)select=select.concat(","); if (i > 0) select = select.concat(",");
if(groupParam.isEnableGroup()) if (groupParam.isEnableGroup()) {
{ if (!StringUtils.isEmpty(groupParam.getGroupCode()))
if(!StringUtils.isEmpty(groupParam.getGroupCode())) select = select.concat(groupParam.getGroupCode());
select=select.concat(groupParam.getGroupCode());
else
select=select.concat(groupParam.getName());
}
else else
select=select.concat(groupParam.getGroupCode()); select = select.concat(groupParam.getName());
select=select.concat(" as ").concat(groupParam.getName().toLowerCase()); } else
select = select.concat(groupParam.getGroupCode());
select = select.concat(" as ").concat(groupParam.getName().toLowerCase());
i++; i++;
} }
} }
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams()))) if (dataSet.getGroupMode() == 1 && (!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams()))) {
{ groupBy = " group by ";
groupBy= " group by "; int i = 0;
int i=0; for (IPSDEDataSetGroupParam obj : dataSet.getPSDEDataSetGroupParams()) {
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams()) if (!(obj instanceof PSDEDataSetGroupParamImpl))
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue; continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj; PSDEDataSetGroupParamImpl groupParam = (PSDEDataSetGroupParamImpl) obj;
if(groupParam.isEnableGroup()) if (groupParam.isEnableGroup()) {
{ if (i > 0) groupBy = groupBy.concat(",");
if(i>0)groupBy=groupBy.concat(",");
if(!StringUtils.isEmpty(groupParam.getGroupCode())) if (!StringUtils.isEmpty(groupParam.getGroupCode()))
groupBy=groupBy.concat(groupParam.getGroupCode()); groupBy = groupBy.concat(groupParam.getGroupCode());
else else
groupBy=groupBy.concat(groupParam.getName()); groupBy = groupBy.concat(groupParam.getName());
i++; i++;
} }
} }
...@@ -951,34 +849,30 @@ public class EntityModel extends BaseModel { ...@@ -951,34 +849,30 @@ public class EntityModel extends BaseModel {
try { try {
if (dataSet.getPSDEDataQueries() != null) {
if(dataSet.getPSDEDataQueries()!=null) DataSetModel dsModel = new DataSetModel(this, dataSet);
{
DataSetModel dsModel=new DataSetModel(this,dataSet);
dsModel.setDatasetId(dataSet.getCodeName()) dsModel.setDatasetId(dataSet.getCodeName())
.setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName()).setSelect(select).setFrom(from).setGroupBy(groupBy); .setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName()).setSelect(select).setFrom(from).setGroupBy(groupBy);
this.addDataSet(dsModel); this.addDataSet(dsModel);
Map<String, String> map =new HashMap<>(); Map<String, String> map = new HashMap<>();
dataSet.getPSDEDataQueries().forEach(dataQuery->{ dataSet.getPSDEDataQueries().forEach(dataQuery -> {
try { try {
if(dataQuery.getAllPSDEDataQueryCodes()!=null) if (dataQuery.getAllPSDEDataQueryCodes() != null) {
{
dsModel.addQueries(dataQuery.getCodeName()); dsModel.addQueries(dataQuery.getCodeName());
dataQuery.getAllPSDEDataQueryCodes().forEach(dq->{ dataQuery.getAllPSDEDataQueryCodes().forEach(dq -> {
String code=""; String code = "";
if(!map.containsKey(dq.getDBType())) { if (!map.containsKey(dq.getDBType())) {
map.put(dq.getDBType(), ""); map.put(dq.getDBType(), "");
code=""; code = "";
} } else {
else {
code = map.get(dq.getDBType()); code = map.get(dq.getDBType());
code = code+"\r\n union all \r\n"; code = code + "\r\n union all \r\n";
} }
code = code+ TransUtils.getQueryCode(dq); code = code + TransUtils.getQueryCode(dq);
;//"<include refid=\""+this.getEntityName().toLowerCase()+"_dq_"+dataQuery.getCodeName()+"_"+dq.getDBType().toLowerCase()+"\"/>"; ;//"<include refid=\""+this.getEntityName().toLowerCase()+"_dq_"+dataQuery.getCodeName()+"_"+dq.getDBType().toLowerCase()+"\"/>";
map.put(dq.getDBType(),"select t1.* from ("+code+") t1"); map.put(dq.getDBType(), "select t1.* from (" + code + ") t1");
}); });
} }
} catch (Exception exception) { } catch (Exception exception) {
...@@ -987,30 +881,27 @@ public class EntityModel extends BaseModel { ...@@ -987,30 +881,27 @@ public class EntityModel extends BaseModel {
}); });
for(Map.Entry<String, String> entry:map.entrySet()) for (Map.Entry<String, String> entry : map.entrySet()) {
{ if (dataSet.getMajorSortPSDEField() != null) {
if(dataSet.getMajorSortPSDEField()!=null) IPSDEFDTColumn column = dataSet.getMajorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5", "mysql"), false);
{
IPSDEFDTColumn column = dataSet.getMajorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
orderBy=" order by ".concat(column==null?dataSet.getMajorSortPSDEField().getName():column.getColumnName()); orderBy = " order by ".concat(column == null ? dataSet.getMajorSortPSDEField().getName() : column.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMajorSortDir())) if (!StringUtils.isEmpty(dataSet.getMajorSortDir()))
orderBy=orderBy.concat(" ").concat(dataSet.getMajorSortDir()); orderBy = orderBy.concat(" ").concat(dataSet.getMajorSortDir());
if(dataSet.getMinorSortPSDEField()!=null) if (dataSet.getMinorSortPSDEField() != null) {
{ IPSDEFDTColumn subCol = dataSet.getMinorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5", "mysql"), false);
IPSDEFDTColumn subCol = dataSet.getMinorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
orderBy=orderBy.concat(",").concat(subCol==null?dataSet.getMinorSortPSDEField().getName():subCol.getColumnName()); orderBy = orderBy.concat(",").concat(subCol == null ? dataSet.getMinorSortPSDEField().getName() : subCol.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMinorSortDir())) if (!StringUtils.isEmpty(dataSet.getMinorSortDir()))
orderBy=orderBy.concat(" ").concat(dataSet.getMinorSortDir()); orderBy = orderBy.concat(" ").concat(dataSet.getMinorSortDir());
} }
} }
String sqlFormat=select.concat(from).concat(where==null?"":where).concat(groupBy==null?"":groupBy).concat(orderBy==null?"":orderBy); String sqlFormat = select.concat(from).concat(where == null ? "" : where).concat(groupBy == null ? "" : groupBy).concat(orderBy == null ? "" : orderBy);
DataSetModel dqModel=new DataSetModel(this,dataSet); DataSetModel dqModel = new DataSetModel(this, dataSet);
dqModel.setDatasetId(this.getEntityName().toLowerCase()+"-ds-"+dataSet.getCodeName()+"-"+entry.getKey().toLowerCase().replace("mysql5","mysql")) dqModel.setDatasetId(this.getEntityName().toLowerCase() + "-ds-" + dataSet.getCodeName() + "-" + entry.getKey().toLowerCase().replace("mysql5", "mysql"))
.setDsType(entry.getKey().toLowerCase().replace("mysql5","mysql")) .setDsType(entry.getKey().toLowerCase().replace("mysql5", "mysql"))
.setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName()) .setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName())
.setDsCode(entry.getValue()).setDsModel(sqlFormat); .setDsCode(entry.getValue()).setDsModel(sqlFormat);
this.addQueries(dqModel); this.addQueries(dqModel);
...@@ -1019,14 +910,12 @@ public class EntityModel extends BaseModel { ...@@ -1019,14 +910,12 @@ public class EntityModel extends BaseModel {
} }
} }
} catch (Exception exception) { } catch (Exception exception) {
} }
}); });
...@@ -1040,15 +929,23 @@ public class EntityModel extends BaseModel { ...@@ -1040,15 +929,23 @@ public class EntityModel extends BaseModel {
} }
if (this.getDataEntity().getAllPSDEActions() != null) {
if(this.getDataEntity().getAllPSDEActions()!=null) this.getDataEntity().getAllPSDEActions().forEach(item -> {
{ String tag = item.getCodeName().toLowerCase();
this.getDataEntity().getAllPSDEActions().forEach(item->{ addAction(new ActionModel(this, item));
String tag=item.getCodeName().toLowerCase();
addAction(new ActionModel(this,item));
}); });
} }
//外部接口实体
if (this.getDataEntity().getPSSubSysServiceAPI() != null && this.getDataEntity().getPSSubSysServiceAPIDE() != null) {
if (this.getSystem().getClientMap().containsKey(this.getDataEntity().getPSSubSysServiceAPI().getCodeName())) {
ClientModel clientModel = this.getSystem().getClientMap().get(this.getDataEntity().getPSSubSysServiceAPI().getCodeName());
if (clientModel.getClientEntityMap().containsKey(this.getDataEntity().getPSSubSysServiceAPIDE().getCodeName())) {
clientEntityModel = clientModel.getClientEntityMap().get(this.getDataEntity().getPSSubSysServiceAPIDE().getCodeName());
}
}
}
} }
} }
...@@ -124,6 +124,22 @@ public class ModelStorage { ...@@ -124,6 +124,22 @@ public class ModelStorage {
}); });
}); });
}); });
} else if (type.equals(TemplateFileType.clientService)) {
getSystemModel().getClient().forEach(clientService -> {
CliOption opt = newCliOption(TemplateFileType.clientService)
.baseData(clientService, clientService.getCodeName());
rt.addOption(opt);
});
} else if (type.equals(TemplateFileType.clientEntity)) {
getSystemModel().getClient().forEach(client -> {
client.getClientEntities().forEach(clientEntity -> {
CliOption opt = newCliOption(TemplateFileType.clientEntity)
.baseData(clientEntity, clientEntity.getCodeName())
.set("modules", clientEntity.getEntity().getModule().toLowerCase())
.set("clients", clientEntity.getClient().getCodeName().toLowerCase());
rt.addOption(opt);
});
});
} }
else if(type.equals(TemplateFileType.app)) else if(type.equals(TemplateFileType.app))
{ {
......
package cn.ibizlab.codegen.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.service.IPSSubSysServiceAPI;
import net.ibizsys.model.service.IPSSubSysServiceAPIDE;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class SubEntityApiModel extends BaseModel {
private SubServiceApiModel subServiceApi;
public SubEntityApiModel(SubServiceApiModel subServiceApiModel, IPSSubSysServiceAPIDE iPSSubSysServiceAPIDE) {
subServiceApi = subServiceApiModel;
this.opt = iPSSubSysServiceAPIDE;
this.setCodeName(iPSSubSysServiceAPIDE.getCodeName());
this.setName(iPSSubSysServiceAPIDE.getName());
}
}
package cn.ibizlab.codegen.model; package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.templating.TemplateFileType;
import cn.ibizlab.codegen.utils.StringAdvUtils; import cn.ibizlab.codegen.utils.StringAdvUtils;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -8,24 +7,11 @@ import lombok.Setter; ...@@ -8,24 +7,11 @@ import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import net.ibizsys.model.IPSSystem; import net.ibizsys.model.IPSSystem;
import net.ibizsys.model.codelist.IPSCodeList; import net.ibizsys.model.codelist.IPSCodeList;
import net.ibizsys.model.database.IPSDEFDTColumn;
import net.ibizsys.model.dataentity.IPSDataEntity;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import net.ibizsys.model.dataentity.defield.IPSLinkDEField;
import net.ibizsys.model.dataentity.der.IPSDER1N;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCode;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCodeCond;
import net.ibizsys.model.dataentity.ds.IPSDEDataSetGroupParam;
import net.ibizsys.model.dataentity.ds.PSDEDataSetGroupParamImpl;
import net.ibizsys.model.pub.IPSSysSFPub; import net.ibizsys.model.pub.IPSSysSFPub;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Getter @Getter
@Setter @Setter
...@@ -66,7 +52,7 @@ public class SystemModel extends BaseModel { ...@@ -66,7 +52,7 @@ public class SystemModel extends BaseModel {
else else
this.setDeploySysId(system.getDeploySysId()); this.setDeploySysId(system.getDeploySysId());
getEntitiesMap(); getEntitiesMap();
getSubServiceApiMap(); getClientMap();
} }
public IPSSystem getSystem() { public IPSSystem getSystem() {
...@@ -258,38 +244,38 @@ public class SystemModel extends BaseModel { ...@@ -258,38 +244,38 @@ public class SystemModel extends BaseModel {
return getApisMap().values(); return getApisMap().values();
} }
private Map<String, SubServiceApiModel> subServiceApiMap; private Map<String, ClientModel> clientMap;
private Map<String, List<SubServiceApiModel>> subServiceApiModules; private Map<String, List<ClientModel>> moduleClients;
public synchronized Map<String, SubServiceApiModel> getSubServiceApiMap() { public synchronized Map<String, ClientModel> getClientMap() {
if (subServiceApiMap == null) { if (clientMap == null) {
subServiceApiMap = new LinkedHashMap<>(); clientMap = new LinkedHashMap<>();
if(getSystem().getAllPSSubSysServiceAPIs()!=null) if(getSystem().getAllPSSubSysServiceAPIs()!=null)
{ {
getSystem().getAllPSSubSysServiceAPIs().forEach(subSysServiceAPI -> { getSystem().getAllPSSubSysServiceAPIs().forEach(subSysServiceAPI -> {
SubServiceApiModel subapi=new SubServiceApiModel(subSysServiceAPI).setSystem(this); ClientModel subapi=new ClientModel(subSysServiceAPI).setSystem(this);
subServiceApiMap.put(subSysServiceAPI.getCodeName(), subapi); clientMap.put(subSysServiceAPI.getCodeName(), subapi);
String module=subapi.getModule(); String module=subapi.getModule();
if(!StringUtils.isEmpty(module)) if(!StringUtils.isEmpty(module))
{ {
if(subServiceApiModules==null) if(moduleClients ==null)
subServiceApiModules=new LinkedHashMap<>(); moduleClients =new LinkedHashMap<>();
if(!subServiceApiModules.containsKey(module)) if(!moduleClients.containsKey(module))
subServiceApiModules.put(module,new ArrayList<>()); moduleClients.put(module,new ArrayList<>());
subServiceApiModules.get(module).add(subapi); moduleClients.get(module).add(subapi);
} }
}); });
} }
} }
return subServiceApiMap; return clientMap;
} }
public Collection<SubServiceApiModel> getSubServiceApi() { public Collection<ClientModel> getClient() {
return getSubServiceApiMap().values(); return getClientMap().values();
} }
......
...@@ -11,8 +11,8 @@ public enum TemplateFileType { ...@@ -11,8 +11,8 @@ public enum TemplateFileType {
module(Constants.MODULES), module(Constants.MODULES),
workflow(Constants.WORKFLOWS), workflow(Constants.WORKFLOWS),
sysUtil(Constants.SYSUTILS), sysUtil(Constants.SYSUTILS),
subService(Constants.SUB_SERVICEAPIS), clientService(Constants.CLIENTS),
subEntity(Constants.SUB_ENTITIES), clientEntity(Constants.CLIENT_ENTITIES),
api(Constants.APIS), api(Constants.APIS),
app(Constants.APPS), app(Constants.APPS),
dict(Constants.DICTS), dict(Constants.DICTS),
...@@ -56,8 +56,8 @@ public enum TemplateFileType { ...@@ -56,8 +56,8 @@ public enum TemplateFileType {
public static final String ENTITIES = "entities"; public static final String ENTITIES = "entities";
public static final String WORKFLOWS = "workflows"; public static final String WORKFLOWS = "workflows";
public static final String SYSUTILS = "syUtils"; public static final String SYSUTILS = "syUtils";
public static final String SUB_SERVICEAPIS = "subServiceApis"; public static final String CLIENTS = "clients";
public static final String SUB_ENTITIES = "subEntities"; public static final String CLIENT_ENTITIES = "clientEntities";
public static final String API_ENTITIES = "apiEntities"; public static final String API_ENTITIES = "apiEntities";
public static final String API_DTOS = "apiDtos"; public static final String API_DTOS = "apiDtos";
public static final String APP_ENTITIES = "appEntities"; public static final String APP_ENTITIES = "appEntities";
......
package {{packageName}}.core.{{clientEntity.entity.module}}.client;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.math.BigInteger;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.util.security.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.Assert;
import org.springframework.beans.factory.annotation.Value;
import cn.ibizlab.util.errors.BadRequestAlertException;
{{#system.enableGlobalTransaction}}
import io.seata.spring.annotation.GlobalTransactional;
{{/system.enableGlobalTransaction}}
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Lazy;
import {{packageName}}.core.{{clientEntity.entity.module}}.domain.{{clientEntity.entity.codeName}};
import {{packageName}}.core.{{clientEntity.entity.module}}.filter.{{clientEntity.entity.codeName}}SearchContext;
import {{packageName}}.core.{{clientEntity.entity.module}}.service.{{clientEntity.entity.codeName}}Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@FeignClient(value = "${ibiz.ref.service.{{lowerCase clientEntity.client.codeName}}: {{lowerCase clientEntity.client.service}} }", contextId = "{{lowerCase clientEntity.codeName}}")
public interface {{clientEntity.codeName}}FeignClient {
{{#each clientEntity.methods}}
{{#neq name "Select"}}
@RequestMapping(method = RequestMethod.{{requestMethod}}, value = "{{requestPath2}}")
{{#neq codeName "CheckKey"}}{{outParam}}{{/neq}}{{#eq codeName "CheckKey"}}Integer{{/eq}} {{camelCase codeName}}{{#each pathVariables}}{{#if @first}}By{{else}}And{{/if}}{{pascalCase name}}{{/each}}({{#each pathVariables}}{{#unless @first}}, {{/unless}}@PathVariable("{{camelCase name}}") {{type.java}} {{camelCase name}}{{/each}}{{#if body}}{{#if pathVariables}}, {{/if}}{{#neq requestMethod 'GET'}}@Validated @RequestBody {{/neq}}{{body}}{{/if}}) ;
{{/neq}}
{{/each}}
@RequestMapping(method = RequestMethod.POST, value = "{{pluralize clientEntity.codeName}}/batch")
Boolean createBatch(@RequestBody List<{{clientEntity.entity.codeName}}> domains);
@RequestMapping(method = RequestMethod.PUT, value = "{{pluralize clientEntity.codeName}}/batch")
boolean updateBatch(@RequestBody List<{{clientEntity.entity.codeName}}> domains);
@RequestMapping(method = RequestMethod.POST, value = "{{pluralize clientEntity.codeName}}/savebatch")
boolean saveBatch(@RequestBody List<{{clientEntity.entity.codeName}}> domains);
@RequestMapping(method = RequestMethod.POST, value = "{{pluralize clientEntity.codeName}}/import")
Map importData(@RequestParam(value = "config") String config ,@RequestBody List<{{clientEntity.entity.codeName}}> domains);
@RequestMapping(method = RequestMethod.DELETE, value = {"{{pluralize clientEntity.codeName}}","/{{pluralize clientEntity.codeName}}/batch"})
boolean removeBatch(@RequestBody List<{{clientEntity.entity.keyField.type.java}}> ids);
}
\ No newline at end of file
package {{packageName}}.core.{{entity.module}}.client;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.math.BigInteger;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.util.security.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.Assert;
import org.springframework.beans.factory.annotation.Value;
import cn.ibizlab.util.errors.BadRequestAlertException;
{{#system.enableGlobalTransaction}}
import io.seata.spring.annotation.GlobalTransactional;
{{/system.enableGlobalTransaction}}
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Lazy;
import {{packageName}}.core.{{entity.module}}.domain.{{entity.codeName}};
import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchContext;
import {{packageName}}.core.{{entity.module}}.service.{{entity.codeName}}Service;
import cn.ibizlab.util.helper.CachedBeanCopier;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
public interface {{entity.codeName}}FeignClient {
default {{entity.codeName}} get({{entity.codeName}} et){
return get(et.get{{pascalCase entity.keyField.codeName}}());
}
@RequestMapping(method = RequestMethod.GET, value = "/{{pluralize entity.codeName}}/{key}")
{{entity.codeName}} get({{entity.keyField.type.java}} key);
default List<{{entity.codeName}}> getByIds(Collection<{{entity.keyField.type.java}}> ids) {
List<{{entity.codeName}}> entities =new ArrayList();
ids.forEach(key -> {
{{entity.codeName}} et = new {{entity.codeName}}();
et.set{{pascalCase entity.keyField.codeName}}(key);
entities.add(et);
});
return getByEntities(entities);
}
List<{{entity.codeName}}> getByEntities(List<{{entity.codeName}}> entities);
{{entity.codeName}} getDraft({{entity.codeName}} et);
Integer checkKey({{entity.codeName}} et);
boolean create({{entity.codeName}} et);
{{#entity.enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/entity.enableEntityCache}}
boolean createBatch(List<{{entity.codeName}}> list);
boolean update({{entity.codeName}} et);
{{#entity.enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/entity.enableEntityCache}}
boolean updateBatch(List<{{entity.codeName}}> list);
boolean save({{entity.codeName}} et);
{{#entity.enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/entity.enableEntityCache}}
boolean saveBatch(List<{{entity.codeName}}> list);
default boolean remove({{entity.keyField.type.java}} key) {
{{entity.codeName}} et = new {{entity.codeName}}();
et.set{{pascalCase entity.keyField.codeName}}(key);
return remove(et);
}
default boolean remove(List<{{entity.keyField.type.java}}> key) {
return removeBatch(key);
}
boolean remove({{entity.codeName}} et);
{{#entity.enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/entity.enableEntityCache}}
boolean removeBatch(Collection<{{entity.keyField.type.java}}> ids);
{{#each entity.extActions}}
default {{outParam}} {{camelCase codeName}}({{inParam}} {{inParamName}}) {
{{#if voidReturn}}
return {{inParamName}};
{{else}}
return null;
{{/if}}
}
{{/each}}
{{#entity.dataSets}}
Page<{{entity.codeName}}> search{{pascalCase codeName}}({{entity.codeName}}SearchContext context);
List<{{entity.codeName}}> list{{pascalCase codeName}}({{entity.codeName}}SearchContext context);
{{/entity.dataSets}}
{{#entity.references}}
List<{{entity.codeName}}> selectBy{{pascalCase fkField.codeName}}({{fkField.type.java}} {{camelCase fkField.codeName}});
{{#entity.enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/entity.enableEntityCache}}
boolean removeBy{{pascalCase fkField.codeName}}({{fkField.type.java}} {{camelCase fkField.codeName}});
{{#entity.enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/entity.enableEntityCache}}
boolean resetBy{{pascalCase fkField.codeName}}({{fkField.type.java}} {{camelCase fkField.codeName}});
{{#entity.enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/entity.enableEntityCache}}
boolean saveBy{{pascalCase fkField.codeName}}({{fkField.type.java}} {{camelCase fkField.codeName}},List<{{entity.codeName}}> list);
{{/entity.references}}
}
\ No newline at end of file
...@@ -11,8 +11,13 @@ import java.util.Collection; ...@@ -11,8 +11,13 @@ import java.util.Collection;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.math.BigInteger; import java.math.BigInteger;
import lombok.extern.slf4j.Slf4j; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
{{#if entity.clientEntityModel}}
import {{packageName}}.core.{{entity.module}}.client.{{entity.clientEntityModel.codeName}}FeignClient;
{{/if}}
import org.springframework.beans.BeanUtils;
import cn.ibizlab.util.security.SpringContextHolder; import cn.ibizlab.util.security.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier; import org.springframework.cglib.beans.BeanCopier;
...@@ -49,115 +54,73 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; ...@@ -49,115 +54,73 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
@Service("{{entity.codeName}}Service") @Service("{{entity.codeName}}Service")
public class {{entity.codeName}}ServiceBase implements {{entity.codeName}}Service { public class {{entity.codeName}}ServiceBase implements {{entity.codeName}}Service {
{{#entity.relEntities}} {{#if entity.clientEntityModel}}
{{#neq storage "NONE"}}
@Autowired @Autowired
@Lazy {{entity.clientEntityModel.codeName}}FeignClient {{camelCase entity.clientEntityModel.codeName}}FeignClient;
protected {{packageName}}.core.{{module}}.service.{{codeName}}Service {{camelCase codeName}}Service;
{{/neq}}
{{/entity.relEntities}}
{{#if entity.indexSubDE}}
@Autowired
@Lazy
protected {{packageName}}.core.{{entity.module}}.mapping.{{entity.codeName}}InheritMapping {{camelCase entity.codeName}}InheritMapping;
{{/if}} {{/if}}
protected int batchSize = 500; protected int batchSize = 500;
public {{entity.codeName}} get({{entity.codeName}} et) { public {{entity.codeName}} get({{entity.codeName}} et) {
return {{camelCase entity.clientEntityModel.codeName}}FeignClient.getBy{{pascalCase entity.keyField.codeName}}(et.get{{pascalCase entity.keyField.codeName}}());
return et;
} }
public List<{{entity.codeName}}> getByEntities(List<{{entity.codeName}}> entities) { public List<{{entity.codeName}}> getByEntities(List<{{entity.codeName}}> entities) {
return null; return null;
} }
{{#entity.hasReferences}}
public void fillParentData({{entity.codeName}} et) {
}
{{/entity.hasReferences}}
public {{entity.codeName}} getDraft({{entity.codeName}} et) { public {{entity.codeName}} getDraft({{entity.codeName}} et) {
{{#entity.hasReferences}} return {{camelCase entity.clientEntityModel.codeName}}FeignClient.getDraft(et);
fillParentData(et);
{{/entity.hasReferences}}
return et;
} }
public Integer checkKey({{entity.codeName}} et) { public Integer checkKey({{entity.codeName}} et) {
return null; return {{camelCase entity.clientEntityModel.codeName}}FeignClient.checkKey(et);
} }
@Override @Override
{{#eq entity.actions.create.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.create.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.create.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.create.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean create({{entity.codeName}} et) { public boolean create({{entity.codeName}} et) {
{{entity.codeName}} rt = {{camelCase entity.clientEntityModel.codeName}}FeignClient.create(et);
BeanUtils.copyProperties(rt, et);
return true; return true;
} }
{{#eq entity.actions.create.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.create.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.create.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.create.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean createBatch(List<{{entity.codeName}}> list) { public boolean createBatch(List<{{entity.codeName}}> list) {
return true; return {{camelCase entity.clientEntityModel.codeName}}FeignClient.createBatch(list);
} }
{{#eq entity.actions.update.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.update.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.update.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.update.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean update({{entity.codeName}} et) { public boolean update({{entity.codeName}} et) {
{{#entity.hasReferences}} {{entity.codeName}} rt = {{camelCase entity.clientEntityModel.codeName}}FeignClient.updateBy{{pascalCase entity.keyField.codeName}}(et.get{{pascalCase entity.keyField.codeName}}(), et);
fillParentData(et); BeanUtils.copyProperties(rt, et);
{{/entity.hasReferences}}
return true; return true;
} }
{{#eq entity.actions.update.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.update.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.update.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.update.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean updateBatch(List<{{entity.codeName}}> list) { public boolean updateBatch(List<{{entity.codeName}}> list) {
return true; return {{camelCase entity.clientEntityModel.codeName}}FeignClient.updateBatch(list);
} }
{{#eq entity.actions.save.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.save.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.save.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.save.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean save({{entity.codeName}} et) { public boolean save({{entity.codeName}} et) {
if(checkKey(et)==0) {{entity.codeName}} rt = {{camelCase entity.clientEntityModel.codeName}}FeignClient.save(et);
return getSelf().update(et); BeanUtils.copyProperties(rt, et);
else return true;
return getSelf().create(et);
} }
{{#eq entity.actions.save.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.save.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.save.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.save.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean saveBatch(List<{{entity.codeName}}> list) { public boolean saveBatch(List<{{entity.codeName}}> list) {
List<{{entity.codeName}}> rt=this.getByEntities(list); return {{camelCase entity.clientEntityModel.codeName}}FeignClient.saveBatch(list);
Set<Serializable> keys=new HashSet<>();
rt.forEach(et->{
Serializable key = et.get{{pascalCase entity.keyField.codeName}}();
if(!ObjectUtils.isEmpty(key))
keys.add(key);
});
List<{{entity.codeName}}> _create=new ArrayList<>();
List<{{entity.codeName}}> _update=new ArrayList<>();
list.forEach(et-> {
Serializable key = et.get{{pascalCase entity.keyField.codeName}}();
if(keys.contains(key))
_update.add(et);
else
_create.add(et);
});
List rtList=new ArrayList<>();
if(_update.size()>0 && (!getSelf().updateBatch(_update)))
return false;
if(_create.size()>0 && (!getSelf().createBatch(_create)))
return false;
return true;
} }
{{#eq entity.actions.remove.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.remove.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.remove.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.remove.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean remove({{entity.codeName}} et) { public boolean remove({{entity.codeName}} et) {
return {{camelCase entity.clientEntityModel.codeName}}FeignClient.removeBy{{pascalCase entity.keyField.codeName}}(et.get{{pascalCase entity.keyField.codeName}}());
return false ;
} }
{{#eq entity.actions.remove.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.remove.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.remove.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.remove.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean removeByEntities(List<{{entity.codeName}}> entities) { public boolean removeByEntities(List<{{entity.codeName}}> entities) {
return {{camelCase entity.clientEntityModel.codeName}}FeignClient.removeBatch(entities.stream().map(e->e.get{{pascalCase entity.keyField.codeName}}()).collect(Collectors.toList()));
return false;
} }
{{#entity.extActions}} {{#entity.extActions}}
...@@ -173,7 +136,7 @@ public class {{entity.codeName}}ServiceBase implements {{entity.codeName}}Servic ...@@ -173,7 +136,7 @@ public class {{entity.codeName}}ServiceBase implements {{entity.codeName}}Servic
{{/entity.extActions}} {{/entity.extActions}}
{{#entity.dataSets}} {{#entity.dataSets}}
public Page<{{entity.codeName}}> search{{pascalCase codeName}}({{entity.codeName}}SearchContext context) { public Page<{{entity.codeName}}> search{{pascalCase codeName}}({{entity.codeName}}SearchContext context) {
return null; return {{camelCase entity.clientEntityModel.codeName}}FeignClient.fetch{{pascalCase codeName}}(context);
} }
public List<{{entity.codeName}}> list{{pascalCase codeName}}({{entity.codeName}}SearchContext context) { public List<{{entity.codeName}}> list{{pascalCase codeName}}({{entity.codeName}}SearchContext context) {
return null; return null;
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册