提交 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;
}
}
...@@ -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() {
......
...@@ -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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册