提交 58416c04 编写于 作者: sq3536's avatar sq3536

填充地址栏上下文

上级 277ba0e5
......@@ -3,6 +3,7 @@ package cn.ibizlab.core.data.domain;
import java.util.*;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.FilterData;
import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils;
......@@ -132,156 +133,41 @@ public class DOModel implements Serializable {
return poModels;
}
@JSONField(serialize = false)
@JsonIgnore
public String getKeyPropertyName()
{
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(!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)
{
PojoSchema keyProperty=this.getKeyProperty();
String keyPropertyName=keyProperty.getName().toLowerCase();
Object key=data.get(keyPropertyName);
if(ObjectUtils.isEmpty(key))
{
key=data.getKey();
if(!ObjectUtils.isEmpty(key))
data.set(keyPropertyName, key);
}
if(ObjectUtils.isEmpty(key))
{
if (keyMap.size()==1)
{
if(genKeyWhenNotExists)
{
if(PojoSchema.Type.integer.getCode().equals(keyProperty.getType())||PojoSchema.Type.number.getCode().equals(keyProperty.getType()))
key=IdWorker.getId();
else
{
Set<String> unionKeys=this.getSchema().getUnionKeys();
if(!ObjectUtils.isEmpty(unionKeys))
{
for(String unionkey:unionKeys)
{
if(ObjectUtils.isEmpty(data.get(unionkey.toLowerCase())))
return null;
if(!StringUtils.isEmpty(key))
key+="||";
else
key+=data.getStringValue(unionkey.toLowerCase());
}
key=DigestUtils.md5DigestAsHex(key.toString().getBytes());
}
else
key=IdWorker.get32UUID();
}
data.set(keyPropertyName,key);
data.setKey(key);
}
else
return null;
}
else if(keyMap.size()>1)
{
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());
}
data.setKey(key);
}
}
return (Serializable)key;
if(this.getSchema()!=null) {
this.getSchema().fillParentKey(data);
return this.getSchema().getKeyValue(data, genKeyWhenNotExists);
}
return null;
}
public BaseData newData(Object keyValue)
{
return setKeyValue(new BaseData(),keyValue);
if(this.getSchema()!=null)
return this.getSchema().setKeyValue(new BaseData(),keyValue);
return null;
}
public BaseData setKeyValue(BaseData data,Object keyValue)
public BaseData fillParentKey(BaseData data)
{
Map<String,PojoSchema> keyMap= this.getKeyMap();
data.setKey(keyValue);
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;
}
}
if(this.getSchema()!=null)
return this.getSchema().fillParentKey(data);
return null;
}
public FilterData fillParentFilter(FilterData data)
{
if(this.getSchema()!=null)
return this.getSchema().fillParentFilter(data);
return null;
}
@JSONField(serialize = false)
@JsonIgnore
public String getDefaultDataSource()
......@@ -330,6 +216,15 @@ public class DOModel implements Serializable {
return poSchemas.get(vendorProvider);
if(this.getSchema()!=null&&("mongodb".equals(name)))
{
POSchema defaultPOSchema= TransUtils.PojoSchema2PO(this.getSchema());
if(defaultPOSchema!=null) {
poSchemas.put("mongodb", defaultPOSchema);
return defaultPOSchema;
}
}
if(this.getSchema()!=null&&("default".equals(name)||this.getSchema().getDefaultDataSoruce().equalsIgnoreCase(name)))
{
POSchema defaultPOSchema= TransUtils.PojoSchema2PO(this.getSchema());
......
......@@ -13,6 +13,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
......@@ -45,6 +46,17 @@ public class BaseData extends DataObj
return this;
}
@Override
public Object put(Object key, Object value) {
if(key instanceof String)
return super.put(key.toString().toLowerCase(), value);
return super.put(key, value);
}
@Override
public BaseData remove(Object key) {
super.remove(key);
......@@ -184,6 +196,8 @@ public class BaseData extends DataObj
return getWebcontext();
else if(key.toString().equalsIgnoreCase("sessioncontext"))
return getSessioncontext();
else if(key instanceof String)
return super.get(key.toString().toLowerCase());
return super.get(key);
}
......
......@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mongodb.BasicDBObject;
import com.mongodb.QueryBuilder;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
......@@ -20,6 +21,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.regex.Pattern;
public class FilterData<T> extends BaseData
{
......@@ -313,6 +315,71 @@ public class FilterData<T> extends BaseData
queryBuilder=new QueryBuilder();
}
if(this.getPOSchema()!=null)
{
if(!StringUtils.isEmpty(this.getQuery()))
{
if(!ObjectUtils.isEmpty(this.getPOSchema().getQuickSearch()))
{
Pattern pattern = Pattern.compile("^.*" + this.getQuery() + ".*$", Pattern.CASE_INSENSITIVE);
QueryBuilder qw=new QueryBuilder();
for(String column:this.getPOSchema().getQuickSearch().keySet())
qw.or(new BasicDBObject(column,pattern));
queryBuilder.and(qw.get());
}
}
if(!ObjectUtils.isEmpty(this.getPOSchema().getSearchMap()))
{
for(Map.Entry<String, POSchema.Column> search:this.getPOSchema().getSearchMap().entrySet())
{
String key=search.getKey().toLowerCase();
String name=search.getValue().getName().toLowerCase();
if(this.keySet().contains(key))
{
POSchema.Column column=search.getValue();
Object obj=column.isDateTime()?this.getTimestampValue(key,null):this.get(key);
if(!ObjectUtils.isEmpty(obj)) {
if(key.endsWith("_like")) {
Pattern pattern = Pattern.compile("^.*" + obj.toString() + ".*$", Pattern.CASE_INSENSITIVE);
queryBuilder.and(name).regex(pattern);
}
else if(key.endsWith("_leftlike")){
Pattern pattern = Pattern.compile(obj.toString() + ".*$", Pattern.CASE_INSENSITIVE);
queryBuilder.and(name).regex(pattern);
}
else if(key.endsWith("_rightlike")){
Pattern pattern = Pattern.compile("^.*" + obj.toString() , Pattern.CASE_INSENSITIVE);
queryBuilder.and(name).regex(pattern);
}
else if(key.endsWith("_eq"))
queryBuilder.and(name).is(obj);
else if(key.endsWith("_noteq"))
queryBuilder.and(name).notEquals(obj);
else if(key.endsWith("_gt"))
queryBuilder.and(name).greaterThan(obj);
else if(key.endsWith("_gtandeq"))
queryBuilder.and(name).greaterThanEquals(obj);
else if(key.endsWith("_lt"))
queryBuilder.and(name).lessThan(obj);
else if(key.endsWith("_ltandeq"))
queryBuilder.and(name).lessThanEquals(obj);
else if(key.endsWith("_isnotnull")&& DataObject.getIntegerValue(obj,1)==1)
queryBuilder.and(name).exists(true).and(name).notEquals("").and(name).notEquals(null);
else if(key.endsWith("_isnull")&& DataObject.getIntegerValue(obj,1)==1)
queryBuilder.and(name).exists(null);
else if(key.endsWith("_in"))
queryBuilder.and(name).in(DataObject.getStringValue(obj,"").split(";|,"));
else if(key.endsWith("_notin"))
queryBuilder.and(name).notIn(DataObject.getStringValue(obj,"").split(";|,"));
}
}
}
}
}
return queryBuilder;
}
......@@ -346,7 +413,22 @@ public class FilterData<T> extends BaseData
map.remove("datasource");
if(map.size()==0)
return null;
return new FilterData().setAll(map);
String srfparentdename=DataObject.getStringValue(map.get("srfparentdename"),DataObject.getStringValue(map.get("data[srfparentdename]"),""));
String srfparentkey=DataObject.getStringValue(map.get("srfparentkey"),DataObject.getStringValue(map.get("data[srfparentkey]"),""));
FilterData filterData=null;
if((!StringUtils.isEmpty(srfparentdename))&&(!StringUtils.isEmpty(srfparentkey)))
{
map.remove("srfparentdename");
map.remove("data[srfparentdename]");
map.remove("srfparentkey");
map.remove("data[srfparentkey]");
filterData=new FilterData().setAll(map);
filterData.addParent(srfparentdename,srfparentkey);
}
else
filterData=new FilterData().setAll(map);
return filterData;
}
}
......@@ -2,9 +2,11 @@ package cn.ibizlab.core.data.model;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
......@@ -13,10 +15,12 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
......@@ -127,6 +131,21 @@ public class POSchema {
@JSONField(serialize = false)
private Map<String,String> keyMap;
@JsonIgnore
@JSONField(serialize = false)
private Column keyColumn;
@JsonIgnore
@JSONField(serialize = false)
public Column getKeyColumn() {
if(keyColumn==null)
{
if((!ObjectUtils.isEmpty(getKeyMap()))&&getKeyMap().size()==1)
keyColumn = this.getColumn(keyMap.values().iterator().next());
}
return keyColumn;
}
@JsonIgnore
@JSONField(serialize = false)
private Map<String,Column> searchMap;
......@@ -135,6 +154,8 @@ public class POSchema {
@JSONField(serialize = false)
private Map<String,Column> quickSearch;
@JsonIgnore
@JSONField(serialize = false)
public Map<String, Column> getColumnMaps() {
......@@ -716,61 +737,54 @@ public class POSchema {
public BaseData trans(BaseData source)
{
if(!needTrans)
{
for (String key : resultMap.keySet()) {
if(!source.keySet().contains(key))
return source;
else {
for (Map.Entry<String, String> entry : resultMap.entrySet()) {
if(!entry.getKey().equalsIgnoreCase(entry.getValue()))
{
if((!key.equals(key.toUpperCase()))&&source.keySet().contains(key.toUpperCase()))
{
needTrans=true;
break;
}
else if((!key.equals(key.toLowerCase()))&&source.keySet().contains(key.toLowerCase()))
{
needTrans=true;
break;
}
Object obj=source.get(entry.getKey());
source.remove(entry.getKey().toLowerCase());
source.set(entry.getValue().toLowerCase(),obj);
}
}
return source;
}
}
public List<BaseData> trans(List<BaseData> source)
{
if(!needTrans)
return source;
else {
BaseData target = new BaseData();
for (Map.Entry<String, String> entry : resultMap.entrySet()) {
target.set(entry.getValue().toLowerCase(),source.get(entry.getKey()));
}
return target;
source.forEach(item->trans(item));
return source;
}
}
public List<BaseData> trans(List<BaseData> source)
public BaseData trans2PO(BaseData source)
{
if(!needTrans&&source.size()>0)
{
BaseData src=source.get(0);
for (String key : resultMap.keySet()) {
if(!src.keySet().contains(key))
if(!needTrans)
return source;
else {
for (Map.Entry<String, String> entry : resultMap.entrySet()) {
if(!entry.getKey().equalsIgnoreCase(entry.getValue()))
{
if((!key.equals(key.toUpperCase()))&&src.keySet().contains(key.toUpperCase()))
{
needTrans=true;
break;
}
else if((!key.equals(key.toLowerCase()))&&src.keySet().contains(key.toLowerCase()))
{
needTrans=true;
break;
}
Object obj=source.get(entry.getValue());
source.remove(entry.getValue().toLowerCase());
source.set(entry.getKey().toLowerCase(),obj);
}
}
return source;
}
}
public List<BaseData> trans2PO(List<BaseData> source)
{
if(!needTrans)
return source;
else {
List<BaseData> target = new ArrayList<>();
source.forEach(item->target.add(trans(item)));
return target;
source.forEach(item->trans2PO(item));
return source;
}
}
......@@ -805,5 +819,97 @@ public class POSchema {
return poSchema;
}
public Serializable getKeyValue(BaseData data, boolean genKeyWhenNotExists)
{
Object key=data.getKey();
Map<String,String> keyMap= this.getKeyMap();
if(keyMap!=null)
{
Column keyColumn=this.getKeyColumn();
if(ObjectUtils.isEmpty(key)&&keyColumn!=null) {
key = data.get(keyColumn.getName().toLowerCase());
if(ObjectUtils.isEmpty(key)&&(!StringUtils.isEmpty(keyColumn.getAlias()))&&(!keyColumn.getName().equalsIgnoreCase(keyColumn.getAlias())))
key=data.get(keyColumn.getAlias().toLowerCase());
}
if(ObjectUtils.isEmpty(key)&&keyMap.size()>1)
{
for(Map.Entry<String,String> entry:keyMap.entrySet())
{
Object obj=data.get(entry.getKey().toLowerCase());
if(ObjectUtils.isEmpty(obj)&&(!entry.getKey().equalsIgnoreCase(entry.getValue())))
obj=data.get(entry.getValue().toLowerCase());
if(ObjectUtils.isEmpty(obj)) {
key=null;
break;
}
if(!StringUtils.isEmpty(key))
key+="||";
else
key+=DataObject.getStringValue(obj,"");
}
}
if(ObjectUtils.isEmpty(key)&&genKeyWhenNotExists&&keyColumn!=null)
{
if(keyColumn.isInt()||keyColumn.isNumber())
key= IdWorker.getId();
else
key=IdWorker.get32UUID();
}
if(ObjectUtils.isEmpty(key))
return null;
setKeyValue(data,key);
}
return (Serializable)key;
}
public BaseData newData(Object keyValue)
{
return setKeyValue(new BaseData(),keyValue);
}
public BaseData setKeyValue(BaseData data,Object keyValue)
{
Map<String,String> keyMap= this.getKeyMap();
data.setKey(keyValue);
if(keyMap!=null)
{
Column keyColumn=this.getKeyColumn();
if(keyColumn!=null) {
data.set(keyColumn.getName().toLowerCase(), keyValue);
}
if(keyMap.size()>1)
{
String[] keys=DataObject.getStringValue(keyValue,"").split("\\|\\|");
if(keyMap.size()!=keys.length)
return null;
int i=0;
for(String keyCol:keyMap.keySet())
{
Column uniColumn=this.getColumn(keyCol);
if(ObjectUtils.isEmpty(data.get(uniColumn.getName().toLowerCase()))) {
if(uniColumn.isInt()) {
data.set(uniColumn.getName().toLowerCase(), DataObject.getLongValue(keys[i], null));
}
else if(uniColumn.isNumber()) {
data.set(uniColumn.getName().toLowerCase(), DataObject.getBigDecimalValue(keys[i], null));
}
else if(uniColumn.isDateTime()) {
data.set(uniColumn.getName().toLowerCase(), DataObject.getTimestampValue(keys[i], null));
}
else{
data.set(uniColumn.getName().toLowerCase(),keys[i]);
}
}
i++;
}
}
return data;
}
return null;
}
}
......@@ -53,6 +53,16 @@ public class PojoOption extends DataObj
return this.getStringValue("table_name",getName());
}
public String getEntityName(){
return this.getStringValue("entity_name","");
}
public String getCodeName(){
return this.getStringValue("code_name","");
}
public String getDefaultDataSoruce(){
return this.getStringValue("ds_name",this.getSystem()+"-master");
}
......
......@@ -138,7 +138,14 @@ public class TransUtils {
sub=new PojoSchema().setType(propType);
sub.setName(fieldModel.getCodeName()).setTitle(fieldModel.getField().getFieldLogicName()).setPropertyOrder(order)
.setOptions(new PojoOption().setAll(JSONObject.parseObject(JSON.toJSONString(fieldModel.getField()))));
Object searchModes=fieldModel.getField().get("search_modes");
if(searchModes!=null)
sub.getOptions().setSearchModes(searchModes.toString());
sub.getOptions().remove("ext_params");
if("PICKUP".equals(fieldModel.getField().getFieldType())&&fieldModel.isPhysicalField())
{
if(!StringUtils.isEmpty(sub.getOptions().getRelationCodeName()))
......@@ -147,11 +154,13 @@ public class TransUtils {
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getTableName())))
sub.getOptions().setRefTableName(relationshipModel.getTableName());
}
String smode=sub.getOptions().getSearchModes();
if((!smode.startsWith("eq"))&&smode.indexOf(",eq")<0)
sub.getOptions().setSearchModes(smode.concat(StringUtils.isEmpty(smode)?"":",").concat("eq"));
}
Object searchModes=fieldModel.getField().get("search_modes");
if(searchModes!=null)
sub.getOptions().setSearchModes(searchModes.toString());
pojoSchema.addProperty(sub.getName(),sub);
order++;
}
......@@ -166,7 +175,9 @@ public class TransUtils {
.set("entity_name",rel.getEntityName())
.set("system_id",(StringUtils.isEmpty(rel.getSystemId())?entityModel.getSystemId():rel.getSystemId()))
.set("entity_id",rel.getEntityId()).set("code_name",rel.getEntityCodeName())
.set("table_name",rel.getTableName()).set("ds_name",rel.getDataSourceName()).set("relation",JSONObject.parseObject(JSON.toJSONString(rel.getRelation()), MetaRelationshipModel.class))
.set("table_name",rel.getTableName()).set("ds_name",rel.getDataSourceName())
.set("relation_name",rel.getRelation().getName())
.set("relation",JSONObject.parseObject(JSON.toJSONString(rel.getRelation()), MetaRelationshipModel.class))
)
.setRef("domain."+rel.getEntityName());
......@@ -186,7 +197,9 @@ public class TransUtils {
.set("entity_name",nest.getEntityName())
.set("system_id",(StringUtils.isEmpty(nest.getSystemId())?entityModel.getSystemId():nest.getSystemId()))
.set("entity_id",nest.getEntityId()).set("code_name",nest.getEntityCodeName())
.set("table_name",nest.getTableName()).set("ds_name",nest.getDataSourceName()).set("relation",JSONObject.parseObject(JSON.toJSONString(nest.getRelation()), MetaRelationshipModel.class))
.set("table_name",nest.getTableName()).set("ds_name",nest.getDataSourceName())
.set("relation_name",nest.getRelation().getName())
.set("relation",JSONObject.parseObject(JSON.toJSONString(nest.getRelation()), MetaRelationshipModel.class))
)
.setItems(new PojoSchema().setType(PojoSchema.Type.object.getCode()).setName(nest.getEntityName()).setTitle(nest.getEntityLogicName())
.setRef("domain."+nest.getEntityName())
......@@ -215,7 +228,6 @@ public class TransUtils {
.setRemarks(pojoSchema.getTitle()).setLogicVal(pojoSchema.getOptions().getLogicVal()).setLogicDelVal(pojoSchema.getOptions().getLogicDelVal());
for(String name:pojoSchema.getProperties().keySet())
{
PojoSchema sub=pojoSchema.getProperties().get(name);
......@@ -281,11 +293,18 @@ public class TransUtils {
if("PICKUP".equals(sub.getOptions().getFieldType())&&sub.getOptions().isPhysicalField())
{
PojoSchema relationshipModel=pojoSchema.getRefSchema(sub.getOptions().getRelationName());
String fkName=sub.getOptions().getRelationName().toUpperCase();
if((!StringUtils.isEmpty(sub.getOptions().getRefTableName()))&&(!StringUtils.isEmpty(fkName))) {
column.getConstraints(true).setReferencedTableName(sub.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()).setForeignKeyName(fkName);
poSchema.addForeignKeyConstraint(new POSchema.ForeignKeyConstraint().setConstraintName(fkName).setBaseTableName(poSchema.getName()).setBaseColumnNames(column.getName()).setReferencedTableName(sub.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()));
if((!StringUtils.isEmpty(relationshipModel.getOptions().getRefTableName()))&&(!StringUtils.isEmpty(fkName))) {
column.getConstraints(true).setReferencedTableName(relationshipModel.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()).setForeignKeyName(fkName);
poSchema.addForeignKeyConstraint(new POSchema.ForeignKeyConstraint().setConstraintName(fkName).setBaseTableName(poSchema.getName()).setBaseColumnNames(column.getName()).setReferencedTableName(relationshipModel.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()));
}
}
else if((!StringUtils.isEmpty(sub.getOptions().getRelationName()))) {
PojoSchema relationshipModel=pojoSchema.getRefSchema(sub.getOptions().getRelationName());
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getOptions().getTableName()))) {
column.getConstraints(true).setReferencedTableName(relationshipModel.getOptions().getTableName())
.setReferencedColumnNames(sub.getOptions().getRefFieldName());
}
}
......@@ -303,6 +322,7 @@ public class TransUtils {
}
public static POSchema EntityModelModel2PO(EntityModel entityModel,String dsType) {
final String dataSourceType=dsType.toLowerCase();
......@@ -360,6 +380,9 @@ public class TransUtils {
.setBaseTableName(poSchema.getName()).setBaseColumnNames(column.getName())
.setReferencedTableName(relationshipModel.getTableName()).setReferencedColumnNames(sub.getRefFieldName()));
}
if(!column.getSearchModes().contains("eq"))
column.getSearchModes().add("eq");
}
else if((!StringUtils.isEmpty(sub.getRelationName()))) {
RelationshipModel relationshipModel = relationshipModelMap.get(sub.getRelationName());
......
......@@ -3,6 +3,8 @@ package cn.ibizlab.core.data.mongodb;
import cn.ibizlab.core.data.model.DSLink;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.SimpleMongoClientDbFactory;
import org.springframework.stereotype.Component;
......@@ -48,7 +50,7 @@ public class DynamicMongoContextHolder
MONGO_CLIENT_DB_FACTORY_MAP.remove(ds);
}
@Value("${spring.data.mongodb.uri}")
@Value("${spring.data.mongodb.uri:mongodb://localhost:27017/admin}")
private String uri;
@PostConstruct
......@@ -59,12 +61,14 @@ public class DynamicMongoContextHolder
}
@Bean(name = "mongoTemplate")
@Lazy(true)
public DynamicMongoTemplate dynamicMongoTemplate() {
Iterator<MongoDbFactory> iterator = MONGO_CLIENT_DB_FACTORY_MAP.values().iterator();
return new DynamicMongoTemplate(iterator.next());
}
@Bean(name = "mongoDbFactory")
@Lazy(true)
public MongoDbFactory mongoDbFactory() {
Iterator<MongoDbFactory> iterator = MONGO_CLIENT_DB_FACTORY_MAP.values().iterator();
return iterator.next();
......
......@@ -11,21 +11,26 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.*;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.util.*;
@Slf4j
@Component
public abstract class MongoDataRepository {
@Autowired
@Lazy
private MongoTemplate mongoTemplate;
/**
......@@ -35,199 +40,6 @@ public abstract class MongoDataRepository {
*/
protected abstract Class<BaseData> getEntityClass();
/**
* 保存
*
* @param t
* @param collectionName 集合名称
*/
public void save(BaseData t, String collectionName) {
this.mongoTemplate.save(t, collectionName);
}
/**
* 批量保存
* @param objectsToSave
* @param collectionName
*/
public Collection<BaseData> batchSave(Collection<BaseData> objectsToSave, String collectionName) {
log.info("-------------->MongoDB batch save start");
return this.mongoTemplate.insert(objectsToSave,collectionName);
}
/**
* 根据id从几何中查询对象
* @param id
* @param collectionName
* @return
*/
public BaseData queryById(String id,String collectionName) {
Query query = new Query(Criteria.where("_id").is(id));
log.info("-------------->MongoDB find start");
return this.mongoTemplate.findOne(query, this.getEntityClass(),collectionName);
}
/**
* 根据条件查询集合
* @param object
* @param collectionName
* @return
*/
public List<BaseData> queryList(BaseData object,String collectionName) {
Query query = getQueryByObject(object);
log.info("-------------->MongoDB find start");
return mongoTemplate.find(query, this.getEntityClass(),collectionName);
}
/**
* 根据条件查询只返回一个文档
* @param object
* @param collectionName
* @return
*/
public BaseData queryOne(BaseData object,String collectionName) {
Query query = getQueryByObject(object);
log.info("-------------->MongoDB find start");
return mongoTemplate.findOne(query, this.getEntityClass(),collectionName);
}
/**
* 根据条件分页查询
* @param object
* @param start
* @param size
* @param collectionName
* @return
*/
public List<BaseData> getPage(BaseData object, int start, int size,String collectionName) {
Query query = getQueryByObject(object);
if(start >0)
{
start --;
}
query.skip(start);
query.limit(size);
log.info("-------------->MongoDB queryPage start");
return this.mongoTemplate.find(query, this.getEntityClass(),collectionName);
}
/**
* 根据条件查询库中符合条件的记录数量
* @param object
* @param collectionName
* @return
*/
public Long getCount(BaseData object,String collectionName) {
Query query = getQueryByObject(object);
log.info("-------------->MongoDB Count start");
return this.mongoTemplate.count(query, this.getEntityClass(),collectionName);
}
/*MongoDB中更新操作分为三种
* 1:updateFirst 修改第一条
* 2:updateMulti 修改所有匹配的记录
* 3:upsert 修改时如果不存在则进行添加操作
* */
/**
* 删除对象
*
* @param t
* @param collectionName
* @return
*/
public int delete(BaseData t, String collectionName) {
log.info("-------------->MongoDB delete start");
return (int) this.mongoTemplate.remove(t, collectionName).getDeletedCount();
}
/**
* 根据id列表批量删除
* @param ids
* @param collectionName
* @return
*/
public int delete(List<String> ids,String collectionName) {
Criteria criteria = Criteria.where("_id").in(ids);
Query query = new Query(criteria);
return (int) this.mongoTemplate.remove(query, this.getEntityClass(),collectionName).getDeletedCount();
}
/**
* 根据id删除
*
* @param id
* @param collectionName 集合名称
*/
public void deleteById(String id, String collectionName) {
Criteria criteria = Criteria.where("_id").is(id);
if (null != criteria) {
Query query = new Query(criteria);
BaseData obj = this.mongoTemplate.findOne(query, this.getEntityClass(),collectionName);
log.info("-------------->MongoDB deleteById start");
if (obj != null) {
this.delete(obj, collectionName);
}
}
}
/**
* 修改匹配到的第一条记录
*
* @param srcObj
* @param targetObj
* @param collectionName 集合名称
*/
public void updateFirst(BaseData srcObj, BaseData targetObj, String collectionName) {
Query query = getQueryByObject(srcObj);
Update update = getUpdateByObject(targetObj);
log.info("-------------->MongoDB updateFirst start");
this.mongoTemplate.updateFirst(query, update, collectionName);
}
/**
* 修改匹配到的所有记录
*
* @param srcObj
* @param targetObj
* @param collectionName 集合名称
*/
public void updateMulti(BaseData srcObj, BaseData targetObj, String collectionName) {
Query query = getQueryByObject(srcObj);
Update update = getUpdateByObject(targetObj);
log.info("-------------->MongoDB updateFirst start");
this.mongoTemplate.updateMulti(query, update, collectionName);
}
/**
* 修改匹配到的记录,若不存在该记录则进行添加
*
* @param srcObj
* @param targetObj
* @param collectionName 集合名字
*/
public void updateInsert(BaseData srcObj, BaseData targetObj, String collectionName) {
Query query = getQueryByObject(srcObj);
Update update = getUpdateByObject(targetObj);
log.info("-------------->MongoDB updateInsert start");
this.mongoTemplate.upsert(query, update, collectionName);
}
/**
* 将查询条件对象转换为query
......@@ -269,20 +81,8 @@ public abstract class MongoDataRepository {
Query query = new Query();
if(!ObjectUtils.isEmpty(data.getKey()))
return query.addCriteria(new Criteria().and("_id").is(data.getKey()));
Criteria criteria = new Criteria();
if(!ObjectUtils.isEmpty(schema.getKeyMap()))
{
for(Map.Entry<String,String> entry:schema.getKeyMap().entrySet())
{
Object obj=data.get(entry.getValue());
if(!ObjectUtils.isEmpty(obj))
criteria.and(entry.getKey()).is(obj);
else
throw new BadRequestAlertException("未找到主键",schema.getName(),entry.getValue());
}
}
query.addCriteria(criteria);
return query;
else
throw new BadRequestAlertException("未找到主键",schema.getName(),null);
}
public Query getKeyQuery(POSchema schema,List list)
......@@ -295,20 +95,11 @@ public abstract class MongoDataRepository {
{
list.forEach(item -> {
BaseData data = (BaseData) item;
if (ObjectUtils.isEmpty(data.getKey()))
{
if (!ObjectUtils.isEmpty(schema.getKeyMap()))
{
for (Map.Entry<String, String> entry : schema.getKeyMap().entrySet())
{
Object obj = data.get(entry.getValue());
if (ObjectUtils.isEmpty(obj))
throw new BadRequestAlertException("未找到主键", schema.getName(), entry.getValue());
}
}
}
if (!ObjectUtils.isEmpty(data.getKey()))
ids.add(data.getKey().toString());
Serializable key=data.getKey();
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",schema.getName(),null);
ids.add(key.toString());
});
}
else
......@@ -317,12 +108,13 @@ public abstract class MongoDataRepository {
}
public void insertData(String ds,POSchema schema, BaseData data){
public int insertData(String ds,POSchema schema, BaseData data){
try
{
DynamicDataSourceContextHolder.push(ds);
this.mongoTemplate.save(data, schema.getName());
return 1;
}
finally {
DynamicDataSourceContextHolder.poll();
......@@ -391,7 +183,7 @@ public abstract class MongoDataRepository {
}
}
public int save(String ds,POSchema schema, BaseData data){
public int saveData(String ds,POSchema schema, BaseData data){
try
{
DynamicDataSourceContextHolder.push(ds);
......@@ -404,7 +196,7 @@ public abstract class MongoDataRepository {
}
}
public void saveBatch(String ds,POSchema schema, List<BaseData> list){
public void saveBatchData(String ds,POSchema schema, List<BaseData> list){
try
{
DynamicDataSourceContextHolder.push(ds);
......@@ -452,16 +244,7 @@ public abstract class MongoDataRepository {
}
}
public List<BaseData> getBatchKey(String ds,POSchema schema, List<BaseData> list){
try
{
DynamicDataSourceContextHolder.push(ds);
return mongoTemplate.find(getKeyQuery(schema,list),getEntityClass(),schema.getName());
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
public List<BaseData> selectData(String ds,POSchema schema, BaseData data){
try
......
......@@ -48,7 +48,7 @@ public class DataResource
RequestData requestData=new RequestData().setAll(map);
if(requestData!=null)
requestData.addParent(parentEntity,parentKey).addParent(parentEntity2,parentKey2);
return doCall(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,method,key,requestData);
return doCall(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,method,key,requestData);
}
@ApiOperation(value = "callMethod数据", tags = {"数据" }, notes = "callMethod数据")
......@@ -135,7 +135,7 @@ public class DataResource
@PathVariable(name = "key",required = false) String key,
@RequestParam Map map) {
BaseData baseData=BaseData.fromContext(map);
return doGet(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,key,baseData);
return doGet(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,key,baseData);
}
@ApiOperation(value = "获取数据", tags = {"数据" }, notes = "获取数据")
......@@ -188,7 +188,7 @@ public class DataResource
@PathVariable(name = "key",required = false) String key,
@RequestParam Map map) {
BaseData baseData=BaseData.fromContext(map);
return doRemove(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,key,baseData);
return doRemove(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,key,baseData);
}
@ApiOperation(value = "删除数据", tags = {"数据" }, notes = "删除数据")
......@@ -224,7 +224,7 @@ public class DataResource
@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@RequestBody List ids) {
return doRemoveBatch(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,ids);
return doRemoveBatch(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,ids);
}
@ApiOperation(value = "批量删除数据", tags = {"数据" }, notes = "批量删除数据")
......@@ -254,7 +254,7 @@ public class DataResource
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "key",required = false) String key,
@RequestBody BaseData baseData) {
return doUpdate(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,key,baseData);
return doUpdate(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,key,baseData);
}
@ApiOperation(value = "更新数据", tags = {"数据" }, notes = "更新数据")
......@@ -285,7 +285,7 @@ public class DataResource
@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@RequestBody List<BaseData> baseDatas) {
return doUpdateBatch(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,baseDatas);
return doUpdateBatch(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,baseDatas);
}
@ApiOperation(value = "批量更新数据", tags = {"数据" }, notes = "批量更新数据")
......@@ -317,7 +317,7 @@ public class DataResource
@PathVariable(name = "key",required = false) String key,
@RequestParam Map map) {
BaseData baseData=BaseData.fromContext(map);
return doCheckKey(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,key,baseData);
return doCheckKey(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,key,baseData);
}
@ApiOperation(value = "检查数据", tags = {"数据" }, notes = "检查数据")
......@@ -356,7 +356,7 @@ public class DataResource
@PathVariable(name = "key",required = false) String key,
@RequestParam Map map) {
BaseData baseData=BaseData.fromContext(map);
return doGetDraft(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,key,baseData);
return doGetDraft(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,key,baseData);
}
@ApiOperation(value = "获取数据草稿", tags = {"数据" }, notes = "获取数据草稿")
......@@ -423,7 +423,7 @@ public class DataResource
@PathVariable(name = "dataquery",required = true) String dataquery,
@RequestParam Map map) {
FilterData context=FilterData.fromContext(map);
return doSelect(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,dataquery,context);
return doSelect(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,dataquery,context);
}
@ApiOperation(value = "查询数据", tags = {"数据" } ,notes = "查询数据,POST,返回body<list>+header<page,total>")
......@@ -473,7 +473,7 @@ public class DataResource
@PathVariable(name = "dataset",required = true) String dataset,
@RequestParam Map map) {
FilterData context=FilterData.fromContext(map);
return doFetch(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,dataset,context);
return doFetch(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,dataset,context);
}
@ApiOperation(value = "获取数据集", tags = {"数据" } ,notes = "获取数据集,POST,返回body<list>+header<page,total>")
......@@ -543,7 +543,7 @@ public class DataResource
@PathVariable(name = "dataquery",required = true) String dataquery,
@RequestParam Map map) {
FilterData context=FilterData.fromContext(map);
return doQuery(system,scope,entity,parentEntity,parentKey,parentEntity2,parentKey2,datasource,dataquery,context);
return doQuery(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,dataquery,context);
}
@ApiOperation(value = "查询数据", tags = {"数据" } ,notes = "查询数据,POST,返回body<list>+header<page,total>")
......
......@@ -56,7 +56,7 @@ public class DbDataServiceImpl implements IDataService {
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
if(dbDataMapper.insertData(link.getName(),poSchema,et)==1)
if(dbDataMapper.insertData(link.getName(),poSchema,poSchema.trans2PO(et))==1)
et.setAll(get(model,scope,datasource,key));
return true;
}
......@@ -75,12 +75,14 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
poSchema.trans2PO(batch);
dbDataMapper.insertBathData(link.getName(),poSchema,batch);
batch.clear();
}
});
if(batch.size()>=0)
{
poSchema.trans2PO(batch);
dbDataMapper.insertBathData(link.getName(),poSchema,batch);
batch.clear();
}
......@@ -95,7 +97,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
dbDataMapper.updateData(link.getName(),poSchema,et);
dbDataMapper.updateData(link.getName(),poSchema,poSchema.trans2PO(et));
et.setAll(get(model,scope,datasource,(Serializable)key));
return true;
}
......@@ -114,12 +116,14 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
poSchema.trans2PO(batch);
dbDataMapper.updateBathData(link.getName(),poSchema,batch);
batch.clear();
}
});
if(batch.size()>=0)
{
poSchema.trans2PO(batch);
dbDataMapper.updateBathData(link.getName(),poSchema,batch);
batch.clear();
}
......@@ -136,7 +140,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
dbDataMapper.removeData(link.getName(),poSchema,et);
dbDataMapper.removeData(link.getName(),poSchema,poSchema.trans2PO(et));
return true;
}
......@@ -154,12 +158,14 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
poSchema.trans2PO(batch);
dbDataMapper.removeBathData(link.getName(),poSchema,batch);
batch.clear();
}
});
if(batch.size()>=0)
{
poSchema.trans2PO(batch);
dbDataMapper.removeBathData(link.getName(),poSchema,batch);
batch.clear();
}
......@@ -174,7 +180,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
dbDataMapper.removeData(link.getName(),poSchema,et);
dbDataMapper.removeData(link.getName(),poSchema,poSchema.trans2PO(et));
return true;
}
......@@ -189,7 +195,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
List<BaseData> list=dbDataMapper.getData(link.getName(),poSchema,et);
List<BaseData> list=dbDataMapper.getData(link.getName(),poSchema,poSchema.trans2PO(et));
if(ObjectUtils.isEmpty(list)||list.size()>1)
throw new BadRequestAlertException("未找到数据",model.getName(),key.toString());
return poSchema.trans(list.get(0));
......@@ -210,12 +216,14 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
poSchema.trans2PO(batch);
rt.addAll(dbDataMapper.getBatchData(link.getName(),poSchema,batch));
batch.clear();
}
});
if(batch.size()>=0)
{
poSchema.trans2PO(batch);
rt.addAll(dbDataMapper.getBatchData(link.getName(),poSchema,batch));
batch.clear();
}
......@@ -231,7 +239,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
List<BaseData> list=dbDataMapper.getData(link.getName(),poSchema,et);
List<BaseData> list=dbDataMapper.getData(link.getName(),poSchema,poSchema.trans2PO(et));
if(ObjectUtils.isEmpty(list)||list.size()>1)
throw new BadRequestAlertException("未找到数据",model.getName(),key.toString());
return poSchema.trans(list.get(0));
......@@ -253,7 +261,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
int cnt=dbDataMapper.countData(link.getName(),poSchema,et);
int cnt=dbDataMapper.countData(link.getName(),poSchema,poSchema.trans2PO(et));
return cnt==1;
}
......@@ -282,17 +290,20 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
poSchema.trans2PO(batch);
rt.addAll(dbDataMapper.getBatchKey(link.getName(),poSchema,batch));
batch.clear();
}
});
if(batch.size()>=0)
{
poSchema.trans2PO(batch);
rt.addAll(dbDataMapper.getBatchKey(link.getName(),poSchema,batch));
batch.clear();
}
Map<Serializable,Integer> keys=new LinkedHashMap<>();
rt.forEach(et->{
poSchema.trans(et);
Serializable key=model.getKeyValue(et,false);
if(!ObjectUtils.isEmpty(key))
keys.put(key,1);
......@@ -321,7 +332,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
return poSchema.trans(dbDataMapper.selectData(link.getName(),poSchema,et));
return poSchema.trans(dbDataMapper.selectData(link.getName(),poSchema,poSchema.trans2PO(et)));
}
@Override
......@@ -330,7 +341,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages=dbDataMapper.selectData(link.getName(),poSchema,et,FilterData.getPages(poSchema,pageable));
com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages=dbDataMapper.selectData(link.getName(),poSchema,poSchema.trans2PO(et),FilterData.getPages(poSchema,pageable));
return new PageImpl<BaseData>(poSchema.trans(pages.getRecords()), pageable, pages.getTotal());
}
......@@ -340,6 +351,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
model.fillParentFilter(context);
context.setPOSchema(poSchema);
return poSchema.trans(dbDataMapper.queryData(link.getName(),poSchema,context.getSql("-dq-"+dataQuery+"-"),context,context.getSearchCond()));
}
......@@ -350,6 +362,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
model.fillParentFilter(context);
context.setPOSchema(poSchema);
if(pageable!=null)
context.setPageable(pageable);
......@@ -384,6 +397,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
model.fillParentFilter(context);
context.setPOSchema(poSchema);
return poSchema.trans(dbDataMapper.queryData(link.getName(),poSchema,context.getSql("-ds-"+dataSet+"-"),context,context.getSearchCond()));
}
......@@ -394,6 +408,7 @@ public class DbDataServiceImpl implements IDataService {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
model.fillParentFilter(context);
context.setPOSchema(poSchema);
if(pageable!=null)
context.setPageable(pageable);
......
......@@ -5,26 +5,26 @@
<insert id="insertData" parameterType="cn.ibizlab.core.data.dto.BaseData">
INSERT INTO ${schema.name} (<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">${key}</foreach>)
VALUES (<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">#{data[${value}]}</foreach>)
VALUES (<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">#{data[${key}]}</foreach>)
</insert>
<insert id="insertBatchData" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" separator=";">
INSERT INTO ${schema.name} (<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">${key}</foreach>)
VALUES (<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">#{item[${value}]}</foreach>)
VALUES (<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">#{item[${key}]}</foreach>)
</foreach>
</insert>
<update id="updateData" parameterType="cn.ibizlab.core.data.dto.BaseData" >
UPDATE ${schema.name} SET <foreach collection="schema.baseColumnMap" item="value" index="key" separator=","><if test="data.keys.contains(value)">${key}= #{data[${value}]}</if></foreach>
WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{data[${value}]}</foreach>
UPDATE ${schema.name} SET <foreach collection="schema.baseColumnMap" item="value" index="key" separator=","><if test="data.keys.contains(value)">${key}= #{data[${key}]}</if></foreach>
WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{data[${key}]}</foreach>
</update>
<update id="updateBatchData" parameterType="java.util.List" >
<foreach collection="list" item="item" index="index" separator=";">
UPDATE ${schema.name} SET <foreach collection="schema.baseColumnMap" item="value" index="key" separator=","><if test="data.keys.contains(value)">${key}= #{item[${value}]}</if></foreach>
WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{item[${value}]}</foreach>
UPDATE ${schema.name} SET <foreach collection="schema.baseColumnMap" item="value" index="key" separator=","><if test="data.keys.contains(value)">${key}= #{item[${key}]}</if></foreach>
WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{item[${key}]}</foreach>
</foreach>
</update>
......@@ -42,7 +42,7 @@
</otherwise>
</choose>
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #{data[${value}]}
${key}= #{data[${key}]}
</foreach>
</select>
......@@ -59,15 +59,15 @@
</if>
</otherwise>
</choose>
(<foreach collection="schema.keyMap" item="value" index="key" separator=",">${key}</foreach>) in (<foreach collection="list" item="item" index="index" separator=",">(<foreach collection="schema.keyMap" item="value" index="key" separator=",">#{item[${value}]}</foreach>)</foreach>)
(<foreach collection="schema.keyMap" item="value" index="key" separator=",">${key}</foreach>) in (<foreach collection="list" item="item" index="index" separator=",">(<foreach collection="schema.keyMap" item="value" index="key" separator=",">#{item[${key}]}</foreach>)</foreach>)
</select>
<select id="getBatchKey" parameterType="java.util.List" resultType="cn.ibizlab.core.data.dto.BaseData">
select <foreach collection="schema.keyMap" item="value" index="key" separator=",">${key} as ${value}</foreach> from ${schema.name} t1 where
select <foreach collection="schema.keyMap" item="value" index="key" separator=",">${key} as ${key}</foreach> from ${schema.name} t1 where
<if test="schema.logicValidColumn!=null">
${schema.logicValidCond} and
</if>
(<foreach collection="schema.keyMap" item="value" index="key" separator=",">${key}</foreach>) in (<foreach collection="list" item="item" index="index" separator=",">(<foreach collection="schema.keyMap" item="value" index="key" separator=",">#{item[${value}]}</foreach>)</foreach>)
(<foreach collection="schema.keyMap" item="value" index="key" separator=",">${key}</foreach>) in (<foreach collection="list" item="item" index="index" separator=",">(<foreach collection="schema.keyMap" item="value" index="key" separator=",">#{item[${key}]}</foreach>)</foreach>)
</select>
<select id="selectData" parameterType="cn.ibizlab.core.data.dto.BaseData" resultType="cn.ibizlab.core.data.dto.BaseData">
......@@ -84,7 +84,7 @@
</otherwise>
</choose>
<foreach collection="schema.resultMap" item="value" index="key" separator="and">
<if test="data.keys.contains(value)">${key}= #{data[${value}]}</if>
<if test="data.keys.contains(value)">${key}= #{data[${key}]}</if>
</foreach>
</select>
......@@ -95,26 +95,26 @@
${schema.logicValidCond} and
</if>
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #{data[${value}]}
${key}= #{data[${key}]}
</foreach>
</select>
<update id="removeData" parameterType="cn.ibizlab.core.data.dto.BaseData" >
<if test="schema.logicValidColumn!=null">
UPDATE ${schema.name} SET ${schema.logicValidDelCond} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{data[${value}]}</foreach>
UPDATE ${schema.name} SET ${schema.logicValidDelCond} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{data[${key}]}</foreach>
</if>
<if test="schema.logicValidColumn==null">
DELETE FROM ${schema.name} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{data[${value}]}</foreach>
DELETE FROM ${schema.name} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{data[${key}]}</foreach>
</if>
</update>
<update id="removeBatchData" parameterType="java.util.List" >
<foreach collection="list" item="item" index="index" separator=";">
<if test="schema.logicValidColumn!=null">
UPDATE ${schema.name} SET ${schema.logicValidDelCond} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{item[${value}]}</foreach>
UPDATE ${schema.name} SET ${schema.logicValidDelCond} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{item[${key}]}</foreach>
</if>
<if test="schema.logicValidColumn==null">
DELETE FROM ${schema.name} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{item[${value}]}</foreach>
DELETE FROM ${schema.name} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{item[${key}]}</foreach>
</if>
</foreach>
</update>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册