提交 39476b17 编写于 作者: sq3536's avatar sq3536

提交

上级 7c019597
...@@ -115,6 +115,8 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -115,6 +115,8 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers( HttpMethod.GET, "/"+logoutPath).permitAll() .antMatchers( HttpMethod.GET, "/"+logoutPath).permitAll()
// 文件操作 // 文件操作
.antMatchers("/"+downloadpath+"/**").permitAll() .antMatchers("/"+downloadpath+"/**").permitAll()
.antMatchers("/ibiz-repository/**").permitAll()
.antMatchers("/ibiz-repo/**").permitAll()
.antMatchers("/"+uploadpath).permitAll() .antMatchers("/"+uploadpath).permitAll()
.antMatchers("/"+previewpath+"/**").permitAll(); .antMatchers("/"+previewpath+"/**").permitAll();
......
...@@ -97,7 +97,11 @@ ...@@ -97,7 +97,11 @@
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
<artifactId>jobs-spring-boot-starter</artifactId> <artifactId>jobs-spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>net.ibizsys.model</groupId>
<artifactId>ibizlab-model</artifactId>
<version>1.1.60</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -6,10 +6,12 @@ import java.math.BigInteger; ...@@ -6,10 +6,12 @@ import java.math.BigInteger;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.model.POSchema; import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema; import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils; import cn.ibizlab.core.data.model.TransUtils;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
...@@ -139,21 +141,124 @@ public class DOModel extends EntityBase implements Serializable { ...@@ -139,21 +141,124 @@ public class DOModel extends EntityBase implements Serializable {
@JsonIgnore @JsonIgnore
public String getKeyPropertyName() public String getKeyPropertyName()
{ {
if(this.getSchema()!=null&&(!ObjectUtils.isEmpty(this.schema.getKeyMap().values()))) PojoSchema keyProperty=getKeyProperty();
return this.schema.getKeyMap().values().iterator().next(); if(keyProperty!=null)
return keyProperty.getName().toLowerCase();
return "id"; return "id";
} }
@JSONField(serialize = false)
@JsonIgnore
public PojoSchema getKeyProperty()
{
if(!ObjectUtils.isEmpty(this.getKeyMap().values()))
return this.getKeyMap().values().iterator().next();
return null;
}
@JSONField(serialize = false) @JSONField(serialize = false)
@JsonIgnore @JsonIgnore
public String getKeyFieldName() public String getKeyFieldName()
{ {
if(this.getSchema()!=null&&(!ObjectUtils.isEmpty(this.schema.getKeyMap().keySet()))) if(!ObjectUtils.isEmpty(this.getKeyMap().keySet()))
return this.schema.getKeyMap().keySet().iterator().next(); return this.getKeyMap().keySet().iterator().next().toLowerCase();
return "id"; return "id";
} }
@JSONField(serialize = false)
@JsonIgnore
public Map<String,PojoSchema> getKeyMap()
{
if(this.getSchema()!=null&&this.getSchema().getKeyMap()!=null)
return this.getSchema().getKeyMap();
return null;
}
public Serializable getKeyValue(BaseData data,boolean genKeyWhenNotExists)
{
Map<String,PojoSchema> keyMap= this.getKeyMap();
if(keyMap!=null)
{
if (keyMap.size()==1)
{
PojoSchema keyProperty=this.getKeyProperty();
Object key=data.get(this.getKeyPropertyName());
if(ObjectUtils.isEmpty(key))
{
if(genKeyWhenNotExists)
{
if(PojoSchema.Type.integer.getCode().equals(keyProperty.getType())||PojoSchema.Type.number.getCode().equals(keyProperty.getType()))
key=IdWorker.getId();
else
key=IdWorker.get32UUID();
data.set(this.getKeyPropertyName(),key);
}
else
return null;
}
return (Serializable)key;
}
else if(keyMap.size()>1)
{
String key="";
for(PojoSchema keySchema:keyMap.values())
{
if(ObjectUtils.isEmpty(data.get(keySchema.getName().toLowerCase())))
return null;
if(!StringUtils.isEmpty(key))
key+="||";
else
key+=data.getStringValue(keySchema.getName().toLowerCase());
}
return key;
}
}
return null;
}
public BaseData newData(Object keyValue)
{
return setKeyValue(new BaseData(),keyValue);
}
public BaseData setKeyValue(BaseData data,Object keyValue)
{
Map<String,PojoSchema> keyMap= this.getKeyMap();
if(keyMap!=null)
{
if (keyMap.size()==1)
{
PojoSchema keyProperty=this.getKeyProperty();
data.set(keyProperty.getName().toLowerCase(),keyValue);
return data;
}
else if(keyMap.size()>1)
{
String key=DataObject.getStringValue(keyValue,"");
String[] keys=key.split("||");
if(keyMap.size()!=keys.length)
return null;
int i=0;
for(PojoSchema keySchema:keyMap.values())
{
if(PojoSchema.Type.integer.getCode().equals(keySchema.getType()))
data.set(keySchema.getName().toLowerCase(),DataObject.getLongValue(keys[i],null));
else if(PojoSchema.Type.number.getCode().equals(keySchema.getType()))
data.set(keySchema.getName().toLowerCase(),DataObject.getBigDecimalValue(keys[i],null));
else if(PojoSchema.Type.string.getCode().equals(keySchema.getType())&&(!StringUtils.isEmpty(keySchema.getFormat()))&&keySchema.getFormat().indexOf("data")==0)
data.set(keySchema.getName().toLowerCase(),DataObject.getTimestampValue(keys[i],null));
else
data.set(keySchema.getName().toLowerCase(),keys[i]);
}
return data;
}
}
return null;
}
@JSONField(serialize = false) @JSONField(serialize = false)
......
...@@ -22,66 +22,74 @@ public class RequestData<T> extends BaseData ...@@ -22,66 +22,74 @@ public class RequestData<T> extends BaseData
public RequestData setKey(Object key) public RequestData setKey(Object key)
{ {
return this.set("key",key); this.key=key;
return this;
} }
public Serializable getKey() public Serializable getKey()
{ {
Object key=this.get("key"); Object key=this.key;
if(key==null)
key=this.get("key");
if(key!=null) if(key!=null)
return (Serializable)key; return (Serializable)key;
else else
return null; return null;
} }
public RequestData setSystem(String system)
{ private Object key;
return this.set("system",system);
private String system;
private String scope;
private String entity;
private String method;
private String dataSource;
public String getSystem() {
return system;
} }
public String getSystem() public RequestData setSystem(String system) {
{ this.system = system;
return this.getStringValue("system"); return this;
} }
public RequestData setScope(String scope) public String getScope() {
{ return scope;
return this.set("scope",scope);
} }
public String getScope() public RequestData setScope(String scope) {
{ this.scope = scope;
return this.getStringValue("scope","default"); return this;
} }
public RequestData setEntity(String entity) public String getEntity() {
{ return entity;
return this.set("entity",entity);
} }
public String getEntity() public RequestData setEntity(String entity) {
{ this.entity = entity;
return this.getStringValue("entity",this.getStringValue("dename")); return this;
} }
public RequestData setMethod(String method) public String getMethod() {
{ return method;
return this.set("method",method);
} }
public String getMethod() public RequestData setMethod(String method) {
{ this.method = method;
return this.getStringValue("method",this.getStringValue("action")); return this;
} }
public RequestData setDataSource(String datasource) public String getDataSource() {
{ return dataSource;
return this.set("datasource",datasource);
} }
public String getDataSource() public RequestData setDataSource(String dataSource) {
{ this.dataSource = dataSource;
return this.getStringValue("datasource"); return this;
} }
public RequestData setBody(T data) public RequestData setBody(T data)
......
package cn.ibizlab.core.data.lite; package cn.ibizlab.core.data.lite;
import com.alibaba.fastjson.JSON;
import net.ibizsys.model.IPSSystem;
import net.ibizsys.model.PSModelServiceImpl;
import net.ibizsys.model.dataentity.IPSDataEntity;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component @Component
public class LiteStorage { public class LiteStorage {
...@@ -20,6 +32,12 @@ public class LiteStorage { ...@@ -20,6 +32,12 @@ public class LiteStorage {
return service; return service;
} }
public static EntityModel getEntityModel(String system,String entity)
{
return service.getProxyEntityModel(system,entity);
}
@Autowired @Autowired
private LiteModelFeignClient client; private LiteModelFeignClient client;
...@@ -28,4 +46,72 @@ public class LiteStorage { ...@@ -28,4 +46,72 @@ public class LiteStorage {
public void init(){ public void init(){
LiteStorage.setLiteModelService(client); LiteStorage.setLiteModelService(client);
} }
@Value("${ibiz.model.path:/app/file/model/}")
private String modelPath;
private Map<String, IPSSystem> dynamicSystems;
public synchronized IPSSystem getDynamicSystem(String system)
{
if(dynamicSystems==null)
dynamicSystems=new HashMap<>();
if(dynamicSystems.containsKey(system))
return dynamicSystems.get(system);
return initDynamicSystem(system);
}
public synchronized IPSSystem initDynamicSystem(String system)
{
if(dynamicSystems==null)
dynamicSystems=new HashMap<>();
PSModelServiceImpl psModelService = new PSModelServiceImpl();
psModelService.setPSModelFolderPath(modelPath+ File.separator+system+File.separator+"model");
IPSSystem iPSSystem = null;
try {
iPSSystem = psModelService.getPSSystem();
dynamicSystems.put(system,iPSSystem);
} catch (Exception e) {
throw new RuntimeException(String.format("加载系统模型错误:%s", e.getMessage()));
}
return iPSSystem;
}
public synchronized EntityModel getDynamicEntity(String system,String entity) throws Exception
{
IPSSystem iPSSystem=getDynamicSystem(system);
if(iPSSystem==null)
return null;
IPSDataEntity dataEntity = iPSSystem.getPSDataEntity(entity,true);
if(dataEntity==null)
return null;
EntityModel entityModel=new EntityModel();
MetaEntityModel metaEntityModel=new MetaEntityModel();
metaEntityModel.setEntityId(dataEntity.getId()).setEntityName(dataEntity.getName())
.setLogicName(dataEntity.getLogicName()).setCodeName(dataEntity.getCodeName()).setTableName(dataEntity.getTableName())
.setSystemId(system).setSystemName(iPSSystem.getLogicName()).setShowOrder(0);
if(dataEntity.isLogicValid())
{
List<Setting> settingList=new ArrayList<>();
String val=dataEntity.getValidLogicValue();
if(StringUtils.isEmpty(val))val="1";
String deVal=dataEntity.getInvalidLogicValue();
if(StringUtils.isEmpty(deVal))deVal="0";
settingList.add(new Setting().setProperty("logicval").setValue(val));
settingList.add(new Setting().setProperty("logicdelval").setValue(deVal));
metaEntityModel.setExtParams(JSON.toJSONString(settingList));
}
entityModel.setEntity(metaEntityModel);
for(IPSDEField defield:dataEntity.getAllPSDEFields())
{
}
return entityModel;
}
} }
...@@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; ...@@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -16,6 +17,7 @@ import java.sql.Timestamp; ...@@ -16,6 +17,7 @@ import java.sql.Timestamp;
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler") @JsonIgnoreProperties(value = "handler")
public class MetaEntityModel{ public class MetaEntityModel{
......
...@@ -21,6 +21,10 @@ public interface DbDataMapper { ...@@ -21,6 +21,10 @@ public interface DbDataMapper {
int save(@Param("schema") POSchema schema, @Param("data") BaseData data); int save(@Param("schema") POSchema schema, @Param("data") BaseData data);
List<BaseData> checkData(@Param("schema") POSchema schema, @Param("data") BaseData data);
List<BaseData> getData(@Param("schema") POSchema schema, @Param("data") BaseData data);
int insertData(@Param("schema") POSchema schema, @Param("data") BaseData data); int insertData(@Param("schema") POSchema schema, @Param("data") BaseData data);
......
package cn.ibizlab.core.data.model; package cn.ibizlab.core.data.model;
import cn.ibizlab.core.data.dto.BaseData;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
...@@ -32,15 +33,51 @@ public class POSchema { ...@@ -32,15 +33,51 @@ public class POSchema {
private String logicVal; private String logicVal;
private String logicDelVal; private String logicDelVal;
public String getLogicVal() {
if(StringUtils.isEmpty(logicVal))
return "1";
return logicVal;
}
public String getLogicDelVal() {
if(StringUtils.isEmpty(logicDelVal))
return "0";
return logicDelVal;
}
private List<Column> columns; private List<Column> columns;
private List<Column> transients;
public POSchema setColumns(List<Column> columns)
{
this.columns=columns;
refreshColumnMaps();
return this;
}
public POSchema setTransients(List<Column> transients)
{
this.transients=transients;
refreshColumnMaps();
return this;
}
public POSchema addColumn(Column column) public POSchema addColumn(Column column)
{ {
if(columns==null) if(columns==null)
columns=new ArrayList<>(); columns=new ArrayList<>();
columns.add(column); columns.add(column);
if(columnMaps!=null) refreshColumn(column);
columnMaps=null; return this;
}
public POSchema addTransient(Column column)
{
if(transients==null)
transients=new ArrayList<>();
transients.add(column);
refreshColumn(column);
return this; return this;
} }
...@@ -59,6 +96,12 @@ public class POSchema { ...@@ -59,6 +96,12 @@ public class POSchema {
@JSONField(serialize = false) @JSONField(serialize = false)
private Map<String,Column> columnMaps; private Map<String,Column> columnMaps;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,String> baseColumnMap;
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private Map<String,String> resultMap; private Map<String,String> resultMap;
...@@ -71,29 +114,90 @@ public class POSchema { ...@@ -71,29 +114,90 @@ public class POSchema {
@JSONField(serialize = false) @JSONField(serialize = false)
public Map<String, Column> getColumnMaps() { public Map<String, Column> getColumnMaps() {
if(columns!=null&&columnMaps==null) if(columns!=null&&columnMaps==null)
{
refreshColumnMaps();
}
return columnMaps;
}
public boolean needTrans = false;
public void refreshColumnMaps()
{ {
columnMaps=new LinkedHashMap<>(); columnMaps=new LinkedHashMap<>();
resultMap=new LinkedHashMap<>(); resultMap=new LinkedHashMap<>();
baseColumnMap=new LinkedHashMap<>();
keyMap=new LinkedHashMap<>(); keyMap=new LinkedHashMap<>();
columns.forEach(column -> { columns.forEach(column -> {
refreshColumn(column);
});
if(logicValid&&logicValidColumn==null)
logicValid=false;
}
public void refreshColumn(Column column)
{
if(columnMaps==null)
columnMaps=new LinkedHashMap<>();
if(resultMap==null)
resultMap=new LinkedHashMap<>();
if(baseColumnMap==null)
baseColumnMap=new LinkedHashMap<>();
if(keyMap==null)
keyMap=new LinkedHashMap<>();
columnMaps.put(column.getName().toLowerCase(),column); columnMaps.put(column.getName().toLowerCase(),column);
if(!column.isComputed())
{
if(column.isLogicValid()) {
this.setLogicValid(true);
this.setLogicValidColumn(column);
if(StringUtils.isEmpty(column.getDefaultValue()))
column.setDefaultValue(this.getLogicVal());
logicValidCond = " "+column.getName()+"=";
logicValidDelCond = " "+column.getName()+"=";
if(column.isText()) {
logicValidCond += ("'" + this.getLogicVal() + "' ");
logicValidDelCond += ("'" + this.getLogicDelVal() + "' ");
}
else {
logicValidCond += (this.getLogicVal() + " ");
logicValidDelCond += (this.getLogicDelVal() + " ");
}
}
if(column.isTenant())
this.setTenantColumn(column);
if(column.isCreateTime())
this.setCreateTimeColumn(column);
if(column.isLastModify())
this.setLastModifyColumn(column);
}
if((!StringUtils.isEmpty(column.getAlias()))&&column.getAlias().equalsIgnoreCase(column.getName())) if((!StringUtils.isEmpty(column.getAlias()))&&column.getAlias().equalsIgnoreCase(column.getName()))
{ {
needTrans=true;
columnMaps.put(column.getAlias().toLowerCase(), column); columnMaps.put(column.getAlias().toLowerCase(), column);
resultMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase()); resultMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase());
if(!column.isComputed())
{
baseColumnMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase());
if(column.isPrimaryKey()) if(column.isPrimaryKey())
keyMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase()); keyMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase());
} }
}
else else
{ {
resultMap.put(column.getName().toLowerCase(), column.getName().toLowerCase()); resultMap.put(column.getName().toLowerCase(), column.getName().toLowerCase());
if(!column.isComputed())
{
baseColumnMap.put(column.getName().toLowerCase(), column.getName().toLowerCase());
if(column.isPrimaryKey()) if(column.isPrimaryKey())
keyMap.put(column.getName().toLowerCase(),column.getName().toLowerCase()); keyMap.put(column.getName().toLowerCase(),column.getName().toLowerCase());
} }
});
} }
return columnMaps;
} }
@JsonIgnore @JsonIgnore
...@@ -101,18 +205,29 @@ public class POSchema { ...@@ -101,18 +205,29 @@ public class POSchema {
public Map<String, String> getResultMap() { public Map<String, String> getResultMap() {
if(columns!=null&&resultMap==null) if(columns!=null&&resultMap==null)
{ {
getColumnMaps(); refreshColumnMaps();
} }
return resultMap; return resultMap;
} }
@JsonIgnore
@JSONField(serialize = false)
public Map<String, String> getBaseColumnMap() {
if(columns!=null&&baseColumnMap==null)
{
refreshColumnMaps();
}
return baseColumnMap;
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public Map<String, String> getKeyMap() { public Map<String, String> getKeyMap() {
if(columns!=null&&keyMap==null) if(columns!=null&&keyMap==null)
{ {
getColumnMaps(); refreshColumnMaps();
} }
return keyMap; return keyMap;
} }
...@@ -129,54 +244,21 @@ public class POSchema { ...@@ -129,54 +244,21 @@ public class POSchema {
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private Column lastModifyColumn; private Column lastModifyColumn;
@JsonIgnore
@JSONField(serialize = false)
public Column getLastModifyField() {
if(columns!=null&&lastModifyColumn==null)
for(Column col:columns)
if(col.isLastModify())
{
lastModifyColumn=col;
return lastModifyColumn;
}
return lastModifyColumn;
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private Column createTimeColumn; private Column createTimeColumn;
@JsonIgnore
@JSONField(serialize = false)
public Column getCreateTimeColumn() {
if(columns!=null&&createTimeColumn==null)
for(Column col:columns)
if(col.isCreateTime())
{
createTimeColumn=col;
return createTimeColumn;
}
return createTimeColumn;
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private Column tenantColumn; private Column tenantColumn;
@JsonIgnore
@JSONField(serialize = false)
public Column getTenantColumn() {
if(columns!=null&&tenantColumn==null)
for(Column col:columns)
if(col.isTenant())
{
tenantColumn=col;
return tenantColumn;
}
return tenantColumn;
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private boolean logicValid=true; private boolean logicValid=false;
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public boolean isLogicValid() public boolean isLogicValid()
...@@ -198,22 +280,7 @@ public class POSchema { ...@@ -198,22 +280,7 @@ public class POSchema {
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private Column logicValidColumn; private Column logicValidColumn;
@JsonIgnore
@JSONField(serialize = false)
public Column getLogicValidColumn() {
if(logicValid&&logicValidColumn==null) {
if (columns != null) {
for (Column col:columns) {
if (col.isLogicValid()) {
logicValidColumn = col;
return logicValidColumn;
}
}
}
logicValid = false;
}
return logicValidColumn;
}
@Getter @Getter
@Setter @Setter
...@@ -229,14 +296,37 @@ public class POSchema { ...@@ -229,14 +296,37 @@ public class POSchema {
private Integer precision; private Integer precision;
private String defaultValue; private String defaultValue;
private Boolean autoIncrement; private Boolean autoIncrement;
private Boolean computed;
private String alias; private String alias;
private String predefined; private String predefined;
@JsonIgnore
@JSONField(serialize = false)
public boolean isComputed()
{
return this.getComputed()!=null&&this.getComputed();
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isAutoIncrement()
{
return this.getAutoIncrement()!=null&&this.getAutoIncrement();
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isNullable()
{
return this.getConstraints()!=null&&this.getConstraints().isNullable();
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public boolean isPrimaryKey() public boolean isPrimaryKey()
{ {
return this.getConstraints()!=null&&this.getConstraints().getPrimaryKey()!=null&&this.getConstraints().getPrimaryKey()==true; return this.getConstraints()!=null&&this.getConstraints().isPrimaryKey();
} }
@JsonIgnore @JsonIgnore
...@@ -271,19 +361,22 @@ public class POSchema { ...@@ -271,19 +361,22 @@ public class POSchema {
@JSONField(serialize = false) @JSONField(serialize = false)
public boolean isText() public boolean isText()
{ {
return this.getType().toUpperCase().indexOf("TEXT")>=0||this.getType().toUpperCase().indexOf("CHAR")>=0||this.getType().toUpperCase().indexOf("LOB")>=0; String type=this.getType().toUpperCase();
return type.indexOf("TEXT")>=0||type.indexOf("CHAR")>=0||type.indexOf("LOB")>=0;
} }
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public boolean isNumber() public boolean isNumber()
{ {
return this.getType().toUpperCase().indexOf("NUM")>=0||this.getType().toUpperCase().indexOf("FLOAT")>=0||this.getType().toUpperCase().indexOf("DOUBLE")>=0||this.getType().toUpperCase().indexOf("DECIMAL")>=0; String type=this.getType().toUpperCase();
return type.indexOf("NUM")>=0||type.indexOf("FLOAT")>=0||type.indexOf("DOUBLE")>=0||type.indexOf("DECIMAL")>=0;
} }
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public boolean isInt() public boolean isInt()
{ {
return this.getType().toUpperCase().indexOf("INT")==0; String type=this.getType().toUpperCase();
return type.indexOf("INT")==0;
} }
private Constraints constraints; private Constraints constraints;
...@@ -314,6 +407,20 @@ public class POSchema { ...@@ -314,6 +407,20 @@ public class POSchema {
private String referencedTableName; private String referencedTableName;
private String referencedColumnNames; private String referencedColumnNames;
@JsonIgnore
@JSONField(serialize = false)
public boolean isNullable()
{
return this.getNullable()!=null&&this.getNullable();
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isPrimaryKey()
{
return this.getPrimaryKey()!=null&&this.getPrimaryKey();
}
} }
@Getter @Getter
...@@ -400,7 +507,20 @@ public class POSchema { ...@@ -400,7 +507,20 @@ public class POSchema {
defaultQueryScript.setVendorProvider("mysql,oracle,postgresql"); defaultQueryScript.setVendorProvider("mysql,oracle,postgresql");
String sql="select "; String sql="select ";
sql += (getBaseColumns()+" from "+name+" t "); String cols="";
if(getBaseColumnMap()!=null)
{
for(String key:baseColumnMap.keySet())
{
if(!StringUtils.isEmpty(cols))
cols+=",";
cols+=("t."+key+" as "+baseColumnMap.get(key));
}
}
else
cols="*";
sql += (cols+" from "+name+" t ");
if(isLogicValid()) if(isLogicValid())
{ {
...@@ -419,59 +539,7 @@ public class POSchema { ...@@ -419,59 +539,7 @@ public class POSchema {
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public String logicValidDelCond; public String logicValidDelCond;
@JsonIgnore
@JSONField(serialize = false)
public synchronized String getLogicValidCond()
{
if(isLogicValid()&&logicValidCond==null)
{
if(logicVal==null)
logicVal="1";
if(logicDelVal==null)
logicDelVal="0";
logicValidCond = this.getLogicValidColumn().getName()+"=";
logicValidDelCond = this.getLogicValidColumn().getName()+"=";
if(this.getLogicValidColumn().isText()) {
logicValidCond += ("'" + logicVal + "'");
logicValidDelCond += ("'" + logicDelVal + "'");
}
else {
logicValidCond += (logicVal + " ");
logicValidDelCond += (logicDelVal + " ");
}
}
else
logicValidCond="";
return logicValidCond;
}
@JsonIgnore
@JSONField(serialize = false)
private String baseColumns;
@JsonIgnore
@JSONField(serialize = false)
public String getBaseColumns()
{
if(StringUtils.isEmpty(baseColumns))
{
String cols="";
if(columns!=null)
{
for(Column col:columns)
{
if(!StringUtils.isEmpty(cols))
cols+=",";
cols+=(col.getName());
if((!StringUtils.isEmpty(col.getAlias()))&&col.getAlias().equalsIgnoreCase(col.getName()))
cols+=(" as "+col.getAlias());
}
}
else
cols="*";
baseColumns=cols;
}
return baseColumns;
}
...@@ -486,16 +554,24 @@ public class POSchema { ...@@ -486,16 +554,24 @@ public class POSchema {
{ {
if(!built) if(!built)
{ {
getColumnMaps(); refreshColumnMaps();
getBaseColumns();
getLastModifyField();
getCreateTimeColumn();
getLogicValidColumn();
getLogicValidCond();
getTenantColumn();
built=true; built=true;
} }
return this; return this;
} }
public BaseData trans(BaseData source)
{
if(!needTrans)
return source;
else {
BaseData target = new BaseData();
for (Map.Entry<String, String> entry : resultMap.entrySet()) {
if(source.keySet().contains(entry.getKey()))
target.set(entry.getValue(),source.get(entry.getKey()));
}
return target;
}
}
} }
...@@ -205,11 +205,11 @@ public class PojoSchema { ...@@ -205,11 +205,11 @@ public class PojoSchema {
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private Map<String,String> keyMap; private Map<String,PojoSchema> keyMap;
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public synchronized Map<String,String> getKeyMap() public synchronized Map<String,PojoSchema> getKeyMap()
{ {
if(Type.object.getCode().equals(this.type)) if(Type.object.getCode().equals(this.type))
{ {
...@@ -218,13 +218,13 @@ public class PojoSchema { ...@@ -218,13 +218,13 @@ public class PojoSchema {
keyMap=new LinkedHashMap<>(); keyMap=new LinkedHashMap<>();
getProperties().values().forEach(sub->{ getProperties().values().forEach(sub->{
if(sub.getOptions().isKeyField()&&sub.getOptions().isPhysicalField()) if(sub.getOptions().isKeyField()&&sub.getOptions().isPhysicalField())
keyMap.put(sub.getOptions().getFieldName(),sub.getName()); keyMap.put(sub.getOptions().getFieldName(),sub);
}); });
if(keyMap.isEmpty()) if(keyMap.isEmpty())
{ {
getProperties().values().forEach(sub->{ getProperties().values().forEach(sub->{
if(sub.getOptions().isUnionKeyField()&&sub.getOptions().isPhysicalField()) if(sub.getOptions().isUnionKeyField()&&sub.getOptions().isPhysicalField())
keyMap.put(sub.getOptions().getFieldName(),sub.getName()); keyMap.put(sub.getOptions().getFieldName(),sub);
}); });
} }
} }
......
...@@ -160,8 +160,7 @@ public class TransUtils { ...@@ -160,8 +160,7 @@ public class TransUtils {
for(String name:pojoSchema.getProperties().keySet()) for(String name:pojoSchema.getProperties().keySet())
{ {
PojoSchema sub=pojoSchema.getProperties().get(name); PojoSchema sub=pojoSchema.getProperties().get(name);
if(!sub.getOptions().isPhysicalField())
continue;
String dataType=sub.getOptions().getDataType(); String dataType=sub.getOptions().getDataType();
Integer length=sub.getOptions().getDataLength(); Integer length=sub.getOptions().getDataLength();
...@@ -171,6 +170,9 @@ public class TransUtils { ...@@ -171,6 +170,9 @@ public class TransUtils {
if(PojoSchema.Type.object.getCode().equals(sub.getType())||PojoSchema.Type.array.getCode().equals(sub.getType())) if(PojoSchema.Type.object.getCode().equals(sub.getType())||PojoSchema.Type.array.getCode().equals(sub.getType()))
{ {
if(!sub.getOptions().isPhysicalField())
continue;
if(StringUtils.isEmpty(dataType))dataType="TEXT"; if(StringUtils.isEmpty(dataType))dataType="TEXT";
column.setType(dataType); column.setType(dataType);
column.setLength(null); column.setLength(null);
...@@ -230,6 +232,9 @@ public class TransUtils { ...@@ -230,6 +232,9 @@ public class TransUtils {
} }
} }
if(!sub.getOptions().isPhysicalField())
poSchema.addTransient(column.setComputed(true));
else
poSchema.addColumn(column); poSchema.addColumn(column);
} }
......
...@@ -18,7 +18,9 @@ import java.nio.charset.StandardCharsets; ...@@ -18,7 +18,9 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
@Slf4j @Slf4j
...@@ -35,4 +37,5 @@ public class ModelService { ...@@ -35,4 +37,5 @@ public class ModelService {
return doModelService.get(system+".domain."+entity); return doModelService.get(system+".domain."+entity);
} }
} }
...@@ -6,15 +6,20 @@ import cn.ibizlab.core.data.dto.BaseData; ...@@ -6,15 +6,20 @@ import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.DbDataQuery; import cn.ibizlab.core.data.dto.DbDataQuery;
import cn.ibizlab.core.data.filter.DOModelSearchContext; import cn.ibizlab.core.data.filter.DOModelSearchContext;
import cn.ibizlab.core.data.mapper.DbDataMapper; import cn.ibizlab.core.data.mapper.DbDataMapper;
import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.service.IDOModelService; import cn.ibizlab.core.data.service.IDOModelService;
import cn.ibizlab.core.data.service.IDataService; import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.filter.SearchContextBase; import cn.ibizlab.util.filter.SearchContextBase;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -35,7 +40,12 @@ public class DbDataServiceImpl extends BaseDataService { ...@@ -35,7 +40,12 @@ public class DbDataServiceImpl extends BaseDataService {
@Override @Override
public boolean create(DOModel model, String datasource, BaseData et) public boolean create(DOModel model, String datasource, BaseData et)
{ {
return dbDataMapper.insertData(model.getDefaultPOSchema().build(),et)==1; Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
if(dbDataMapper.insertData(model.getDefaultPOSchema(),et)==1)
et.setAll(get(model,datasource,key));
return true;
} }
@Override @Override
...@@ -47,7 +57,11 @@ public class DbDataServiceImpl extends BaseDataService { ...@@ -47,7 +57,11 @@ public class DbDataServiceImpl extends BaseDataService {
@Override @Override
public boolean update(DOModel model, String datasource, BaseData et) public boolean update(DOModel model, String datasource, BaseData et)
{ {
dbDataMapper.updateData(model.getDefaultPOSchema().build(),et); Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
dbDataMapper.updateData(model.getDefaultPOSchema(),et);
et.setAll(get(model,datasource,(Serializable)key));
return true; return true;
} }
...@@ -60,7 +74,13 @@ public class DbDataServiceImpl extends BaseDataService { ...@@ -60,7 +74,13 @@ public class DbDataServiceImpl extends BaseDataService {
@Override @Override
public boolean remove(DOModel model, String datasource, Serializable key) public boolean remove(DOModel model, String datasource, Serializable key)
{ {
return false; if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
BaseData et = model.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",model.getName(),null);
dbDataMapper.removeData(model.getDefaultPOSchema(),et);
return true;
} }
@Override @Override
...@@ -72,7 +92,18 @@ public class DbDataServiceImpl extends BaseDataService { ...@@ -72,7 +92,18 @@ public class DbDataServiceImpl extends BaseDataService {
@Override @Override
public BaseData get(DOModel model, String datasource, Serializable key) public BaseData get(DOModel model, String datasource, Serializable key)
{ {
return null; if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
BaseData et = model.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",model.getName(),null);
POSchema poSchema=model.getDefaultPOSchema();
List<BaseData> list=dbDataMapper.getData(poSchema,et);
if(ObjectUtils.isEmpty(list)||list.size()>1)
throw new BadRequestAlertException("未找到数据",model.getName(),key.toString());
if(list.size()>1)
throw new BadRequestAlertException("数据不唯一",model.getName(),key.toString());
return poSchema.trans(list.get(0));
} }
@Override @Override
...@@ -84,13 +115,23 @@ public class DbDataServiceImpl extends BaseDataService { ...@@ -84,13 +115,23 @@ public class DbDataServiceImpl extends BaseDataService {
@Override @Override
public boolean checkKey(DOModel model, String datasource, BaseData et) public boolean checkKey(DOModel model, String datasource, BaseData et)
{ {
Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key))
return false;
List<BaseData> list=dbDataMapper.getData(model.getDefaultPOSchema(),et);
if(ObjectUtils.isEmpty(list)&&list.size()==1)
return list.get(0).getIntegerValue("cnt",0)==1;
return false; return false;
} }
@Override @Override
public boolean save(DOModel model, String datasource, BaseData et) public boolean save(DOModel model, String datasource, BaseData et)
{ {
return false; if(checkKey(model,datasource,et))
return update(model,datasource,et);
else
return create(model,datasource,et);
} }
@Override @Override
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
<insert id="insertData" parameterType="cn.ibizlab.core.data.dto.BaseData"> <insert id="insertData" parameterType="cn.ibizlab.core.data.dto.BaseData">
INSERT INTO ${schema.name} INSERT INTO ${schema.name}
( (
<foreach collection="schema.resultMap" item="value" index="key" separator=","> <foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">
${key} ${key}
</foreach> </foreach>
) )
VALUES VALUES
( (
<foreach collection="schema.resultMap" item="value" index="key" separator=","> <foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">
#{data[${value}]} #{data[${value}]}
</foreach> </foreach>
) )
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<update id="updateData" parameterType="cn.ibizlab.core.data.dto.BaseData" > <update id="updateData" parameterType="cn.ibizlab.core.data.dto.BaseData" >
update ${schema.name} update ${schema.name}
set set
<foreach collection="schema.resultMap" item="value" index="key" separator=","> <foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">
<if test="data.keys.contains(value)">${key}= #{data[${value}]}</if> <if test="data.keys.contains(value)">${key}= #{data[${value}]}</if>
</foreach> </foreach>
where where
...@@ -42,14 +42,38 @@ ...@@ -42,14 +42,38 @@
</foreach> </foreach>
</update> </update>
<select id="getData" parameterType="cn.ibizlab.core.data.dto.BaseData" resultType="cn.ibizlab.core.data.dto.BaseData">
select
<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">
${key}
</foreach>
from ${schema.name}
where
<if test="schema.logicValidColumn!=null">
${schema.logicValidCond} and
</if>
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #{data[${value}]}
</foreach>
</select>
<select id="checkData" parameterType="cn.ibizlab.core.data.dto.BaseData" resultType="cn.ibizlab.core.data.dto.BaseData">
select count(1) as cnt from ${schema.name}
where
<if test="schema.logicValidColumn!=null">
${schema.logicValidCond} and
</if>
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #{data[${value}]}
</foreach>
</select>
<update id="removeData" parameterType="cn.ibizlab.core.data.dto.BaseData" > <update id="removeData" parameterType="cn.ibizlab.core.data.dto.BaseData" >
<if test="schema.logicValidColumn!=null"> <if test="schema.logicValidColumn!=null">
update ${schema.name} update ${schema.name}
set set
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
${schema.logicValidDelCond} ${schema.logicValidDelCond}
</foreach>
where where
<foreach collection="schema.keyMap" item="value" index="key" separator="and"> <foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #{data[${value}]} ${key}= #{data[${value}]}
......
...@@ -29,9 +29,12 @@ public class DataResource ...@@ -29,9 +29,12 @@ public class DataResource
public IDataService dataService; public IDataService dataService;
@ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据") @ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据")
@RequestMapping(method = RequestMethod.POST, value = {"/{system}/{entity}/{method}","/{system}/{scope}/{entity}/{method}"}) @RequestMapping(method = RequestMethod.POST, value = {"/{system}/{entity}/{method}","/{system}/{scope}/{entity}/{method}",
public ResponseEntity<BaseData> call(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,@PathVariable(name = "method",required = true) String method,@RequestParam(name = "datasource",required = false) String datasource,@RequestBody BaseData baseData) { "/ibiz-repository/{system}/{entity}/{method}",
ResponseData<BaseData> responseData=dataService.call(system,scope,entity,method,datasource,new RequestData().setBody(baseData)); "/ibiz-repository/{system}/{scope}/{entity}/{method}"
,"/ibiz-repo/{system}/{entity}/{method}","/ibiz-repo/{system}/{scope}/{entity}/{method}"})
public ResponseEntity call(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,@PathVariable(name = "method",required = true) String method,@RequestParam(name = "datasource",required = false) String datasource,@RequestBody RequestData requestData) {
ResponseData responseData=dataService.call(system,scope,entity,method,datasource,requestData);
return ResponseEntity.status(HttpStatus.OK).body(responseData.getBody()); return ResponseEntity.status(HttpStatus.OK).body(responseData.getBody());
} }
......
...@@ -31,9 +31,7 @@ public class DataObject { ...@@ -31,9 +31,7 @@ public class DataObject {
if(rt.endsWith(" 00:00:00")) { if(rt.endsWith(" 00:00:00")) {
rt=dayFormat.format(objValue); rt=dayFormat.format(objValue);
} }
else if(rt.endsWith(":00")) {
rt=datetimeFormat2.format(objValue);
}
return rt; return rt;
} }
if(objValue instanceof BigDecimal) if(objValue instanceof BigDecimal)
......
...@@ -47,6 +47,20 @@ ...@@ -47,6 +47,20 @@
<updatePolicy>always</updatePolicy> <updatePolicy>always</updatePolicy>
</snapshots> </snapshots>
</repository> </repository>
<repository>
<id>ibizmvnrepository</id>
<name>ibizmvnrepository</name>
<url>http://172.16.240.220:8081/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories> </repositories>
</project> </project>
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册