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

提交

上级 7c019597
......@@ -115,6 +115,8 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers( HttpMethod.GET, "/"+logoutPath).permitAll()
// 文件操作
.antMatchers("/"+downloadpath+"/**").permitAll()
.antMatchers("/ibiz-repository/**").permitAll()
.antMatchers("/ibiz-repo/**").permitAll()
.antMatchers("/"+uploadpath).permitAll()
.antMatchers("/"+previewpath+"/**").permitAll();
......
......@@ -97,7 +97,11 @@
<groupId>com.baomidou</groupId>
<artifactId>jobs-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>net.ibizsys.model</groupId>
<artifactId>ibizlab-model</artifactId>
<version>1.1.60</version>
</dependency>
</dependencies>
......
......@@ -6,10 +6,12 @@ import java.math.BigInteger;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -139,21 +141,124 @@ public class DOModel extends EntityBase implements Serializable {
@JsonIgnore
public String getKeyPropertyName()
{
if(this.getSchema()!=null&&(!ObjectUtils.isEmpty(this.schema.getKeyMap().values())))
return this.schema.getKeyMap().values().iterator().next();
PojoSchema keyProperty=getKeyProperty();
if(keyProperty!=null)
return keyProperty.getName().toLowerCase();
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)
@JsonIgnore
public String getKeyFieldName()
{
if(this.getSchema()!=null&&(!ObjectUtils.isEmpty(this.schema.getKeyMap().keySet())))
return this.schema.getKeyMap().keySet().iterator().next();
if(!ObjectUtils.isEmpty(this.getKeyMap().keySet()))
return this.getKeyMap().keySet().iterator().next().toLowerCase();
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)
......
......@@ -22,66 +22,74 @@ public class RequestData<T> extends BaseData
public RequestData setKey(Object key)
{
return this.set("key",key);
this.key=key;
return this;
}
public Serializable getKey()
{
Object key=this.get("key");
Object key=this.key;
if(key==null)
key=this.get("key");
if(key!=null)
return (Serializable)key;
else
return null;
}
public RequestData setSystem(String system)
{
return this.set("system",system);
private Object key;
private String system;
private String scope;
private String entity;
private String method;
private String dataSource;
public String getSystem() {
return system;
}
public String getSystem()
{
return this.getStringValue("system");
public RequestData setSystem(String system) {
this.system = system;
return this;
}
public RequestData setScope(String scope)
{
return this.set("scope",scope);
public String getScope() {
return scope;
}
public String getScope()
{
return this.getStringValue("scope","default");
public RequestData setScope(String scope) {
this.scope = scope;
return this;
}
public RequestData setEntity(String entity)
{
return this.set("entity",entity);
public String getEntity() {
return entity;
}
public String getEntity()
{
return this.getStringValue("entity",this.getStringValue("dename"));
public RequestData setEntity(String entity) {
this.entity = entity;
return this;
}
public RequestData setMethod(String method)
{
return this.set("method",method);
public String getMethod() {
return method;
}
public String getMethod()
{
return this.getStringValue("method",this.getStringValue("action"));
public RequestData setMethod(String method) {
this.method = method;
return this;
}
public RequestData setDataSource(String datasource)
{
return this.set("datasource",datasource);
public String getDataSource() {
return dataSource;
}
public String getDataSource()
{
return this.getStringValue("datasource");
public RequestData setDataSource(String dataSource) {
this.dataSource = dataSource;
return this;
}
public RequestData setBody(T data)
......
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.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
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
public class LiteStorage {
......@@ -20,6 +32,12 @@ public class LiteStorage {
return service;
}
public static EntityModel getEntityModel(String system,String entity)
{
return service.getProxyEntityModel(system,entity);
}
@Autowired
private LiteModelFeignClient client;
......@@ -28,4 +46,72 @@ public class LiteStorage {
public void init(){
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;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.sql.Timestamp;
......@@ -16,6 +17,7 @@ import java.sql.Timestamp;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
public class MetaEntityModel{
......
......@@ -21,6 +21,10 @@ public interface DbDataMapper {
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);
......
package cn.ibizlab.core.data.model;
import cn.ibizlab.core.data.dto.BaseData;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
......@@ -32,15 +33,51 @@ public class POSchema {
private String logicVal;
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> 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)
{
if(columns==null)
columns=new ArrayList<>();
columns.add(column);
if(columnMaps!=null)
columnMaps=null;
refreshColumn(column);
return this;
}
public POSchema addTransient(Column column)
{
if(transients==null)
transients=new ArrayList<>();
transients.add(column);
refreshColumn(column);
return this;
}
......@@ -59,6 +96,12 @@ public class POSchema {
@JSONField(serialize = false)
private Map<String,Column> columnMaps;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,String> baseColumnMap;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,String> resultMap;
......@@ -71,29 +114,90 @@ public class POSchema {
@JSONField(serialize = false)
public Map<String, Column> getColumnMaps() {
if(columns!=null&&columnMaps==null)
{
refreshColumnMaps();
}
return columnMaps;
}
public boolean needTrans = false;
public void refreshColumnMaps()
{
columnMaps=new LinkedHashMap<>();
resultMap=new LinkedHashMap<>();
baseColumnMap=new LinkedHashMap<>();
keyMap=new LinkedHashMap<>();
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);
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()))
{
needTrans=true;
columnMaps.put(column.getAlias().toLowerCase(), column);
resultMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase());
if(!column.isComputed())
{
baseColumnMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase());
if(column.isPrimaryKey())
keyMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase());
}
}
else
{
resultMap.put(column.getName().toLowerCase(), column.getName().toLowerCase());
if(!column.isComputed())
{
baseColumnMap.put(column.getName().toLowerCase(), column.getName().toLowerCase());
if(column.isPrimaryKey())
keyMap.put(column.getName().toLowerCase(),column.getName().toLowerCase());
}
});
}
return columnMaps;
}
@JsonIgnore
......@@ -101,18 +205,29 @@ public class POSchema {
public Map<String, String> getResultMap() {
if(columns!=null&&resultMap==null)
{
getColumnMaps();
refreshColumnMaps();
}
return resultMap;
}
@JsonIgnore
@JSONField(serialize = false)
public Map<String, String> getBaseColumnMap() {
if(columns!=null&&baseColumnMap==null)
{
refreshColumnMaps();
}
return baseColumnMap;
}
@JsonIgnore
@JSONField(serialize = false)
public Map<String, String> getKeyMap() {
if(columns!=null&&keyMap==null)
{
getColumnMaps();
refreshColumnMaps();
}
return keyMap;
}
......@@ -129,54 +244,21 @@ public class POSchema {
@JsonIgnore
@JSONField(serialize = false)
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
@JSONField(serialize = false)
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
@JSONField(serialize = false)
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
@JSONField(serialize = false)
private boolean logicValid=true;
private boolean logicValid=false;
@JsonIgnore
@JSONField(serialize = false)
public boolean isLogicValid()
......@@ -198,22 +280,7 @@ public class POSchema {
@JsonIgnore
@JSONField(serialize = false)
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
@Setter
......@@ -229,14 +296,37 @@ public class POSchema {
private Integer precision;
private String defaultValue;
private Boolean autoIncrement;
private Boolean computed;
private String alias;
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
@JSONField(serialize = false)
public boolean isPrimaryKey()
{
return this.getConstraints()!=null&&this.getConstraints().getPrimaryKey()!=null&&this.getConstraints().getPrimaryKey()==true;
return this.getConstraints()!=null&&this.getConstraints().isPrimaryKey();
}
@JsonIgnore
......@@ -271,19 +361,22 @@ public class POSchema {
@JSONField(serialize = false)
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
@JSONField(serialize = false)
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
@JSONField(serialize = false)
public boolean isInt()
{
return this.getType().toUpperCase().indexOf("INT")==0;
String type=this.getType().toUpperCase();
return type.indexOf("INT")==0;
}
private Constraints constraints;
......@@ -314,6 +407,20 @@ public class POSchema {
private String referencedTableName;
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
......@@ -400,7 +507,20 @@ public class POSchema {
defaultQueryScript.setVendorProvider("mysql,oracle,postgresql");
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())
{
......@@ -419,59 +539,7 @@ public class POSchema {
@JsonIgnore
@JSONField(serialize = false)
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 {
{
if(!built)
{
getColumnMaps();
getBaseColumns();
getLastModifyField();
getCreateTimeColumn();
getLogicValidColumn();
getLogicValidCond();
getTenantColumn();
refreshColumnMaps();
built=true;
}
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 {
@JsonIgnore
@JSONField(serialize = false)
private Map<String,String> keyMap;
private Map<String,PojoSchema> keyMap;
@JsonIgnore
@JSONField(serialize = false)
public synchronized Map<String,String> getKeyMap()
public synchronized Map<String,PojoSchema> getKeyMap()
{
if(Type.object.getCode().equals(this.type))
{
......@@ -218,13 +218,13 @@ public class PojoSchema {
keyMap=new LinkedHashMap<>();
getProperties().values().forEach(sub->{
if(sub.getOptions().isKeyField()&&sub.getOptions().isPhysicalField())
keyMap.put(sub.getOptions().getFieldName(),sub.getName());
keyMap.put(sub.getOptions().getFieldName(),sub);
});
if(keyMap.isEmpty())
{
getProperties().values().forEach(sub->{
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 {
for(String name:pojoSchema.getProperties().keySet())
{
PojoSchema sub=pojoSchema.getProperties().get(name);
if(!sub.getOptions().isPhysicalField())
continue;
String dataType=sub.getOptions().getDataType();
Integer length=sub.getOptions().getDataLength();
......@@ -171,6 +170,9 @@ public class TransUtils {
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";
column.setType(dataType);
column.setLength(null);
......@@ -230,6 +232,9 @@ public class TransUtils {
}
}
if(!sub.getOptions().isPhysicalField())
poSchema.addTransient(column.setComputed(true));
else
poSchema.addColumn(column);
}
......
......@@ -18,7 +18,9 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
......@@ -35,4 +37,5 @@ public class ModelService {
return doModelService.get(system+".domain."+entity);
}
}
......@@ -6,15 +6,20 @@ import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.DbDataQuery;
import cn.ibizlab.core.data.filter.DOModelSearchContext;
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.IDataService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.filter.SearchContextBase;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.io.Serializable;
import java.util.ArrayList;
......@@ -35,7 +40,12 @@ public class DbDataServiceImpl extends BaseDataService {
@Override
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
......@@ -47,7 +57,11 @@ public class DbDataServiceImpl extends BaseDataService {
@Override
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;
}
......@@ -60,7 +74,13 @@ public class DbDataServiceImpl extends BaseDataService {
@Override
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
......@@ -72,7 +92,18 @@ public class DbDataServiceImpl extends BaseDataService {
@Override
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
......@@ -84,13 +115,23 @@ public class DbDataServiceImpl extends BaseDataService {
@Override
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;
}
@Override
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
......
......@@ -18,13 +18,13 @@
<insert id="insertData" parameterType="cn.ibizlab.core.data.dto.BaseData">
INSERT INTO ${schema.name}
(
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">
${key}
</foreach>
)
VALUES
(
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">
#{data[${value}]}
</foreach>
)
......@@ -33,7 +33,7 @@
<update id="updateData" parameterType="cn.ibizlab.core.data.dto.BaseData" >
update ${schema.name}
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>
</foreach>
where
......@@ -42,14 +42,38 @@
</foreach>
</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" >
<if test="schema.logicValidColumn!=null">
update ${schema.name}
set
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
${schema.logicValidDelCond}
</foreach>
where
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #{data[${value}]}
......
......@@ -29,9 +29,12 @@ public class DataResource
public IDataService dataService;
@ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据")
@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) {
ResponseData<BaseData> responseData=dataService.call(system,scope,entity,method,datasource,new RequestData().setBody(baseData));
@RequestMapping(method = RequestMethod.POST, value = {"/{system}/{entity}/{method}","/{system}/{scope}/{entity}/{method}",
"/ibiz-repository/{system}/{entity}/{method}",
"/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());
}
......
......@@ -31,9 +31,7 @@ public class DataObject {
if(rt.endsWith(" 00:00:00")) {
rt=dayFormat.format(objValue);
}
else if(rt.endsWith(":00")) {
rt=datetimeFormat2.format(objValue);
}
return rt;
}
if(objValue instanceof BigDecimal)
......
......@@ -47,6 +47,20 @@
<updatePolicy>always</updatePolicy>
</snapshots>
</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>
</project>
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册