提交 226656b2 编写于 作者: sq3536's avatar sq3536

action

上级 239662ae
......@@ -156,7 +156,7 @@
<dependency>
<groupId>net.ibizsys.model</groupId>
<artifactId>ibiz-model</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<exclusions>
<exclusion>
<artifactId>slf4j-simple</artifactId>
......
......@@ -11,6 +11,9 @@ import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.ds.IPSDEDataSet;
import java.util.ArrayList;
import java.util.List;
/**
* 实体[数据集]
*/
......@@ -46,6 +49,9 @@ public class DataSetModel extends BaseModel{
this.setId(String.format("%1$s-%2$s",entity.getCodeName(),codeName));
return this;
}
private String dsType;
/**
* 代码
*/
......@@ -60,6 +66,24 @@ public class DataSetModel extends BaseModel{
return (IPSDEDataSet)opt;
}
private String select="";
private String from="";
private String groupBy="";
private String orderBy="";
private List<String> queries;
public DataSetModel addQueries(String queryCodeName)
{
if(queries==null)
queries=new ArrayList<>();
queries.add(queryCodeName);
return this;
}
}
......@@ -59,6 +59,26 @@ public class EntityModel extends BaseModel {
return (IPSDataEntity)opt;
}
private List<DataSetModel> queries;
public EntityModel addQueries(DataSetModel dataSet)
{
if(queries==null)
queries=new ArrayList<>();
queries.add(dataSet);
return this;
}
private List<DataSetModel> dataQueries;
public EntityModel addDataQueries(DataSetModel dataSet)
{
if(dataQueries==null)
dataQueries=new ArrayList<>();
dataQueries.add(dataSet);
return this;
}
private List<DataSetModel> dataSets;
public EntityModel addDataSet(DataSetModel dataSet)
......@@ -69,6 +89,7 @@ public class EntityModel extends BaseModel {
return this;
}
private List<FieldModel> fields;
public EntityModel addField(FieldModel fieldModel)
......@@ -121,7 +142,35 @@ public class EntityModel extends BaseModel {
return this;
}
private Map<String,EntityModel> relEntitiesMap;
public EntityModel addRelEntity(String codeName,EntityModel entityModel)
{
if(entityModel==null||StringUtils.isEmpty(codeName)||codeName.equalsIgnoreCase(this.codeName))
return this;
if(relEntitiesMap==null)
relEntitiesMap=new LinkedHashMap<>();
relEntitiesMap.put(codeName,entityModel);
return this;
}
public Collection<EntityModel> getRelEntities()
{
if(relEntitiesMap==null)
{
if(this.references!=null)
references.forEach(item-> {
this.addRelEntity(item.getEntityCodeName(),item.getRelEntity());
});
if(this.nesteds!=null)
nesteds.forEach(item-> {
this.addRelEntity(item.getEntityCodeName(),item.getRelEntity());
});
}
if(relEntitiesMap!=null)
return relEntitiesMap.values();
return new ArrayList<>();
}
private Map<String, FieldModel> fieldMap = null;
......@@ -255,16 +304,6 @@ public class EntityModel extends BaseModel {
}
public String getDsName()
{
String dsName=this.getDataEntity().getDSLink();
if(StringUtils.isEmpty(dsName)||"DEFAULT".equalsIgnoreCase(dsName))
{
dsName="master";
}
return dsName;
}
public String getDataSource()
{
String dsName=this.getDataEntity().getDSLink();
if(StringUtils.isEmpty(dsName)||"DEFAULT".equalsIgnoreCase(dsName))
......@@ -531,19 +570,110 @@ public class EntityModel extends BaseModel {
if(dataEntity.getAllPSDEDataQueries()!=null)
{
dataEntity.getAllPSDEDataQueries().forEach(dataQuery->{
try {
if(dataQuery.getAllPSDEDataQueryCodes()!=null)
{
dataQuery.getAllPSDEDataQueryCodes().forEach(dq->{
String code=TransUtils.getQueryCode(dq);
DataSetModel dsModel=new DataSetModel();
dsModel.setEntity(this);
dsModel.setName(dataQuery.getName());
dsModel.setDatasetId(this.getEntityName().toLowerCase()+"-dq-"+dataQuery.getCodeName()+"-"+dq.getDBType().toLowerCase().replace("mysql5","mysql"))
.setDatasetName(dataQuery.getLogicName()).setCodeName(dataQuery.getCodeName())
.setDsCode(code);
this.addQueries(dsModel);
this.addDataQueries(dsModel);
});
}
} catch (Exception exception) {
}
});
}
if(dataEntity.getAllPSDEDataSets()!=null)
{
dataEntity.getAllPSDEDataSets().forEach(dataSet->{
String select="select t1.*";
try {
String from=" from ( %s ) t1 ";
if(dataSet.getPSDEDataQueries()!=null)
String groupBy=null;
String orderBy=null;
if(dataSet.getGroupMode()==1||dataSet.getMajorSortPSDEField()!=null)
{
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
{
select="select ";
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(i>0)select=select.concat(",");
if(groupParam.isEnableGroup())
{
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
select=select.concat(groupParam.getGroupCode());
else
select=select.concat(groupParam.getName());
}
else
select=select.concat(groupParam.getGroupCode());
select=select.concat(" as ").concat(groupParam.getName().toLowerCase());
i++;
}
}
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
{
groupBy= " group by ";
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(groupParam.isEnableGroup())
{
if(i>0)groupBy=groupBy.concat(",");
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
groupBy=groupBy.concat(groupParam.getGroupCode());
else
groupBy=groupBy.concat(groupParam.getName());
i++;
}
}
}
}
try {
if(dataSet.getPSDEDataQueries()!=null)
{
DataSetModel dsModel=new DataSetModel(this,dataSet);
dsModel.setDatasetId(dataSet.getCodeName())
.setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName()).setSelect(select).setFrom(from).setGroupBy(groupBy);
this.addDataSet(dsModel);
Map<String, String> map =new HashMap<>();
dataSet.getPSDEDataQueries().forEach(dataQuery->{
......@@ -551,6 +681,7 @@ public class EntityModel extends BaseModel {
try {
if(dataQuery.getAllPSDEDataQueryCodes()!=null)
{
dsModel.addQueries(dataQuery.getCodeName());
dataQuery.getAllPSDEDataQueryCodes().forEach(dq->{
String code="";
if(!map.containsKey(dq.getDBType())) {
......@@ -574,91 +705,44 @@ public class EntityModel extends BaseModel {
for(Map.Entry<String, String> entry:map.entrySet())
{
String sql=null;
if(dataSet.getGroupMode()==1||dataSet.getMajorSortPSDEField()!=null)
if(dataSet.getMajorSortPSDEField()!=null)
{
IPSDEFDTColumn column = dataSet.getMajorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
orderBy=" order by ".concat(column==null?dataSet.getMajorSortPSDEField().getName():column.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMajorSortDir()))
orderBy=orderBy.concat(" ").concat(dataSet.getMajorSortDir());
if(dataSet.getMinorSortPSDEField()!=null)
{
sql="select ";
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(i>0)sql=sql.concat(",");
if(groupParam.isEnableGroup())
{
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
sql=sql.concat(groupParam.getGroupCode());
else
sql=sql.concat(groupParam.getName());
}
else
sql=sql.concat(groupParam.getGroupCode());
sql=sql.concat(" as ").concat(groupParam.getName().toLowerCase());
i++;
}
sql=sql.concat(" from ( %s ) t1");
}
else
sql="select t1.* from ( %s ) t1";
IPSDEFDTColumn subCol = dataSet.getMinorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
orderBy=orderBy.concat(",").concat(subCol==null?dataSet.getMinorSortPSDEField().getName():subCol.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMinorSortDir()))
orderBy=orderBy.concat(" ").concat(dataSet.getMinorSortDir());
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
{
sql=sql.concat(" group by ");
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(groupParam.isEnableGroup())
{
if(i>0)sql=sql.concat(",");
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
sql=sql.concat(groupParam.getGroupCode());
else
sql=sql.concat(groupParam.getName());
i++;
}
}
}
}
if(dataSet.getMajorSortPSDEField()!=null)
{
IPSDEFDTColumn column = dataSet.getMajorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
String sqlFormat=select.concat(from).concat(groupBy==null?"":groupBy).concat(orderBy==null?"":orderBy);
DataSetModel dqModel=new DataSetModel(this,dataSet);
dqModel.setDatasetId(this.getEntityName().toLowerCase()+"-ds-"+dataSet.getCodeName()+"-"+entry.getKey().toLowerCase().replace("mysql5","mysql"))
.setDsType(entry.getKey().toLowerCase().replace("mysql5","mysql"))
.setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName())
.setDsCode(entry.getValue()).setDsModel(sqlFormat);
this.addQueries(dqModel);
sql=sql.concat(" order by ").concat(column==null?dataSet.getMajorSortPSDEField().getName():column.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMajorSortDir()))
sql=sql.concat(" ").concat(dataSet.getMajorSortDir());
if(dataSet.getMinorSortPSDEField()!=null)
{
IPSDEFDTColumn subCol = dataSet.getMinorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
dsModel.setOrderBy(orderBy).setDsModel(sqlFormat);
}
sql=sql.concat(",").concat(subCol==null?dataSet.getMinorSortPSDEField().getName():subCol.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMinorSortDir()))
sql=sql.concat(" ").concat(dataSet.getMinorSortDir());
}
}
}
DataSetModel dsModel=new DataSetModel(this,dataSet);
dsModel.setDatasetId(this.getEntityName().toLowerCase()+"-ds-"+dataSet.getCodeName()+"-"+entry.getKey().toLowerCase().replace("mysql5","mysql"))
.setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName())
.setDsCode(entry.getValue()).setDsModel(sql);
this.addDataSet(dsModel);
}
}
} catch (Exception exception) {
}
});
......
......@@ -7,6 +7,7 @@ import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
......@@ -20,18 +21,29 @@ public class RelationshipModel extends BaseModel{
public RelationshipModel(EntityModel entityModel, IPSDERBase der)
{
this.opt=der;
this.entity=entityModel;
this.ownerEntity=entityModel;
this.setName(der.getName());
}
@Override
public RelationshipModel setCodeName(String codeName) {
super.setCodeName(codeName);
this.setId(String.format("%1$s-%2$s",entity.getCodeName(),codeName));
this.setId(String.format("%1$s-%2$s",ownerEntity.getCodeName(),codeName));
return this;
}
private EntityModel entity;
private EntityModel ownerEntity;
private EntityModel relEntity;
public EntityModel getRelEntity()
{
if(relEntity==null&&ownerEntity!=null&&(!StringUtils.isEmpty(entityCodeName)))
{
relEntity=ownerEntity.getSystem().getEntity(entityCodeName);
}
return relEntity;
}
private String entityName;
......
......@@ -16,6 +16,7 @@ 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 org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
......@@ -33,12 +34,32 @@ public class SystemModel extends BaseModel {
public SystemModel(IPSSystem system)
{
this.opt=system;
this.setCodeName(system.getCodeName());
this.setName(system.getName());
getEntitiesMap();
system.getAllPSSystemModules().forEach(item->{
});
if(!ObjectUtils.isEmpty(system.getAllPSSysSFPubs()))
{
system.getAllPSSysSFPubs().forEach(pub->{
if(pub.isMainPSSysSFPub())
this.pub=pub;
});
if(this.pub==null)
this.pub=system.getAllPSSysSFPubs().get(0);
}
if(this.pub!=null)
{
this.setCodeName(this.pub.getCodeName());
this.setName(this.pub.getName());
this.setPackageName(this.pub.getPKGCodeName());
}
else
{
this.setCodeName(system.getCodeName());
this.setName(system.getName());
this.setPackageName(system.getCodeName().toLowerCase());
}
getEntitiesMap();
}
public IPSSystem getSystem()
......@@ -48,18 +69,15 @@ public class SystemModel extends BaseModel {
public String getProjectName()
{
return getSystem().getCodeName().toLowerCase();
return this.codeName.toLowerCase();
}
public String getProjectDesc()
{
return getSystem().getName();
return this.name;
}
public String getPackageName()
{
return getSystem().getCodeName().toLowerCase();
}
private String packageName;
private boolean enableDS=false;
private boolean enableES=false;
......@@ -72,6 +90,8 @@ public class SystemModel extends BaseModel {
private boolean enablePostgreSQL=false;
private boolean enableDyna=false;
private IPSSysSFPub pub;
private Map<String,EntityModel> entitiesMap;
public synchronized Map<String, EntityModel> getEntitiesMap() {
if(entitiesMap==null) {
......
......@@ -283,10 +283,10 @@ public class TransUtils {
order++;
}
if(entityModel.getDataSets()!=null)
if(entityModel.getQueries()!=null)
{
entityModel.getDataSets().forEach(dataSet->{
entityModel.getQueries().forEach(dataSet->{
if(dataSet.getDatasetId().startsWith(entityModel.getEntityName().toLowerCase()+"-")&&dataSet.getDatasetId().endsWith(dataSourceType))
{
......
......@@ -21,9 +21,9 @@ impott om.baomidou.dynamic.datasource.annotation.DS;
import {{packageName}}.{{entity.module}}.domain.{{entity.codeName}};
import {{packageName}}.{{entity.module}}.filter.{{entity.codeName}}SearchContext;
{{#dataSource}}
{{#dsName}}
@DS("{{entity.dataSource}}")
{{/dataSource}}
{{/dsName}}
public interface I{{entity.codeName}}Service extends IService<{{entity.codeName}}> {
{{entity.codeName}} get({{entity.keyField.type.java}} key);
......@@ -63,14 +63,21 @@ public interface I{{entity.codeName}}Service extends IService<{{entity.codeName}
boolean {{codeName.camelCase}}Batch(List<{{entity.codeName}}> list);
{{/entity.actions}}
{{#entity.dataSets}}
Page<{{entity.codeName}}> search{{codeName}}({{entity.codeName}}SearchContext context);
List<{{entity.codeName}}> list{{codeName}}({{entity.codeName}}SearchContext context);
{{/entity.dataSets}}
{{#entity.references}}
List<{{entity.codeName}}> selectBy{{fkField.codeName.pascalCase}}({{fkField.type.java}} {{fkField.codeName.camelCase}});
{{#enableEntityCache}}
@CacheEvict(value = "{{entity.codeName.lowerCase}}", allEntries = true)
{{/enableEntityCache}}
boolean removeBy{{fkField.codeName.pascalCase}}({{fkField.type.java}} {{fkField.codeName.camelCase}});
{{#enableEntityCache}}
@CacheEvict(value = "{{entity.codeName.lowerCase}}", allEntries = true)
{{/enableEntityCache}}
boolean saveBy{{fkField.codeName.pascalCase}}({{fkField.type.java}} {{fkField.codeName.camelCase}},List<{{entity.codeName}}> list);
{{/entity.references}}
}
\ No newline at end of file
package {{packageName}}.core.{{entity.module}}.service.impl;
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 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.beans.factory.annotation.Value;
import {{packageName}}.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.I{{entity.codeName}}Service;
import {{packageName}}.core.{{entity.module}}.mapper.${item.getCodeName()}Mapper;
import {{packageName}}.util.helper.CachedBeanCopier;
import {{packageName}}.util.helper.DEFieldCacheMap;
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.conditions.Wrapper;
public class {{entity.codeName}}ServiceImpl implements I{{entity.codeName}}Service
{
}
\ No newline at end of file
......@@ -346,31 +346,63 @@
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
</dependency>
{{/system.enableDS}}
{{/system.enableDS}}
{{#system.enableES}}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
{{/system.enableES}}
{{/system.enableES}}
{{#system.enableMQ}}
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client</artifactId>
<version>${rocketmq.version}</version>
</dependency>
{{/system.enableMQ}}
{{/system.enableMQ}}
{{#system.enableGlobalTransaction}}
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>${r'${alibaba-seata.version}'}</version>
<exclusions>
<exclusion>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version>${r'${spring-cloud-alibaba.version}'}</version>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
{{/system.enableGlobalTransaction}}
{{#system.enableOAuth2}}
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.6.RELEASE</version>
</dependency>
{{/system.enableGlobalTransaction}}
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.0.10.RELEASE</version>
</dependency>
{{/system.enableOAuth2}}
{{#system.enableOracle}}
<!-- Oracle驱动包 -->
<dependency>
......@@ -378,11 +410,13 @@
<artifactId>ojdbc8</artifactId>
<version>${oracle.version}</version>
</dependency>
<dependency>
<groupId>com.oracle.database.nls</groupId>
<artifactId>orai18n</artifactId>
<version>${oracle.version}</version>
</dependency>
{{/system.enableOracle}}
{{#system.enablePostgreSQL}}
<!-- PostgreSQL驱动包 -->
......@@ -391,6 +425,7 @@
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
{{/system.enablePostgreSQL}}
{{#system.enableMysql}}
<!-- MySQL驱动包 -->
......@@ -398,6 +433,7 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
{{/system.enableMysql}}
</dependencies>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册