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

提交

上级 59cbb66b
version: "3.2"
services:
iBizRT4EBSX-mysql:
image: mysql:5.7.20
volumes:
- $PWD/../../../../volumes/mysql/:/var/lib/mysql/
networks:
- agent_network
environment:
- TZ=Asia/Shanghai
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=a_A_5d9d78509
ports:
- 3306:3306
command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8 --explicit_defaults_for_timestamp
networks:
agent_network:
attachable: true
...@@ -292,6 +292,7 @@ public class DOModel extends EntityBase implements Serializable { ...@@ -292,6 +292,7 @@ public class DOModel extends EntityBase implements Serializable {
} }
public POSchema getPOSchema(String name) public POSchema getPOSchema(String name)
{ {
name="mysql5";
if(StringUtils.isEmpty(name)&&this.getSchema()!=null) if(StringUtils.isEmpty(name)&&this.getSchema()!=null)
name=this.getSchema().getDefaultDataSoruce(); name=this.getSchema().getDefaultDataSoruce();
......
...@@ -6,6 +6,8 @@ import cn.ibizlab.core.data.model.POSchema; ...@@ -6,6 +6,8 @@ import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema; import cn.ibizlab.core.data.model.PojoSchema;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
...@@ -41,26 +43,20 @@ public class BaseData extends DataObj ...@@ -41,26 +43,20 @@ public class BaseData extends DataObj
return this; return this;
} }
@JsonIgnore
@JSONField(serialize = false)
private POSchema _poschema;
@JsonIgnore
@JSONField(serialize = false)
public POSchema getPOSchema() public POSchema getPOSchema()
{ {
Object obj=this.get("_poschema"); return _poschema;
if(obj!=null)
{
if (obj instanceof POSchema)
return (POSchema) obj;
else if(obj instanceof Map)
{
POSchema poSchema= JSONObject.parseObject(JSON.toJSONString(obj),POSchema.class);
this.put("_poschema",poSchema);
return poSchema;
}
}
return null;
} }
public BaseData setPOSchema(POSchema poSchema) public BaseData setPOSchema(POSchema poSchema)
{ {
return this.set("_poschema",poSchema); this._poschema=poSchema;
return this;
} }
public DOModel getDOModel() public DOModel getDOModel()
......
package cn.ibizlab.core.data.dto; package cn.ibizlab.core.data.dto;
import cn.ibizlab.core.data.model.POSchema; import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.filter.QueryFilter; import cn.ibizlab.util.filter.QueryFilter;
import cn.ibizlab.util.filter.QueryWrapperContext; import cn.ibizlab.util.filter.QueryWrapperContext;
import cn.ibizlab.util.helper.DEFieldCacheMap; import cn.ibizlab.util.helper.DEFieldCacheMap;
import cn.ibizlab.util.helper.DataObject;
import cn.ibizlab.util.security.AuthenticationUser; import cn.ibizlab.util.security.AuthenticationUser;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
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 org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
...@@ -144,22 +149,43 @@ public class FilterData<T> extends BaseData ...@@ -144,22 +149,43 @@ public class FilterData<T> extends BaseData
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public Map<String,Object> getDatacontext() { public BaseData getDatacontext() {
return getParams(); return getParams();
} }
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public Map<String,Object> getWebcontext() { public BaseData getWebcontext() {
return getParams(); return getParams();
} }
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public Map<String,Object> getSessioncontext() { public BaseData sessioncontext;
return AuthenticationUser.getAuthenticationUser().getSessionParams(); @JsonIgnore
@JSONField(serialize = false)
public BaseData getSessioncontext() {
if(sessioncontext==null)
sessioncontext=new BaseData().setAll(AuthenticationUser.getAuthenticationUser().getSessionParams());
return sessioncontext;
} }
@Override
public Object get(Object key) {
if(key==null)
return null;
if(key.toString().equalsIgnoreCase("datacontext"))
return getDatacontext();
else if(key.toString().equalsIgnoreCase("webcontext"))
return getWebcontext();
else if(key.toString().equalsIgnoreCase("sessioncontext"))
return getSessioncontext();
return super.get(key);
}
public String getUserTaskId() { public String getUserTaskId() {
return this.getStringValue("userTaskId",this.getParams().getStringValue("userTaskId")); return this.getStringValue("userTaskId",this.getParams().getStringValue("userTaskId"));
...@@ -193,9 +219,13 @@ public class FilterData<T> extends BaseData ...@@ -193,9 +219,13 @@ public class FilterData<T> extends BaseData
} }
public Page getPages(POSchema poSchema)
@JsonIgnore
@JSONField(serialize = false)
public Page getPages()
{ {
return getPages(poSchema,this.getPageable()); return getPages(getPOSchema(),this.getPageable());
} }
public static Page getPages(POSchema poSchema,Pageable pageable){ public static Page getPages(POSchema poSchema,Pageable pageable){
...@@ -233,35 +263,96 @@ public class FilterData<T> extends BaseData ...@@ -233,35 +263,96 @@ public class FilterData<T> extends BaseData
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private QueryWrapper searchCond=null; private QueryWrapper<BaseData> searchCond=null;
public QueryWrapper getSearchCond() public QueryWrapper<BaseData> getSearchCond()
{ {
if(searchCond==null) if(searchCond==null)
{ {
if(this.getFilter()!=null) if(this.getFilter()!=null)
{ {
QueryWrapperContext context=new QueryWrapperContext(); QueryWrapperContext<BaseData> context=new QueryWrapperContext<>();
context.setFilter(this.getFilter()); context.setFilter(this.getFilter());
searchCond = context.getSelectCond(); searchCond = context.getSelectCond();
} }
else else
{ {
searchCond=new QueryWrapper(); searchCond=new QueryWrapper<>();
} }
for(Object obj:this.keySet())
if(this.getPOSchema()!=null)
{
if(!StringUtils.isEmpty(this.getQuery()))
{
if(ObjectUtils.isEmpty(this.getPOSchema().getQuickSearch()))
{ {
String key=obj.toString().toLowerCase(); searchCond.and(qw-> {
if(key.startsWith("n_")&&key.endsWith("_like")) int i=0;
for(String column:this.getPOSchema().getQuickSearch().keySet())
{ {
searchCond.like(key.substring(2).replace("_like",""),this.get(obj)); if(i>0)
qw.or();
qw.like(column,this.getQuery());
i++;
} }
});
}
}
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"))
searchCond.like(name,obj);
else if(key.endsWith("_leftlike"))
searchCond.likeRight(name,obj);
else if(key.endsWith("_rightlike"))
searchCond.likeLeft(name,obj);
else if(key.endsWith("_eq"))
searchCond.eq(name,obj);
else if(key.endsWith("_noteq"))
searchCond.ne(name,obj);
else if(key.endsWith("_gt"))
searchCond.gt(name,obj);
else if(key.endsWith("_gtandeq"))
searchCond.ge(name,obj);
else if(key.endsWith("_lt"))
searchCond.lt(name,obj);
else if(key.endsWith("_ltandeq"))
searchCond.le(name,obj);
else if(key.endsWith("_isnotnull")&& DataObject.getIntegerValue(obj,1)==1)
searchCond.isNotNull(name);
else if(key.endsWith("_isnull")&& DataObject.getIntegerValue(obj,1)==1)
searchCond.isNull(name);
else if(key.endsWith("_in"))
searchCond.in(name,DataObject.getStringValue(obj,"").split(";|,"));
else if(key.endsWith("_notin"))
searchCond.notIn(name,DataObject.getStringValue(obj,"").split(";|,"));
}
}
}
}
} }
} }
return searchCond; return searchCond;
} }
public String getSql(POSchema.Segment segment) public String getSql(String codename)
{ {
if(getPOSchema()==null)
throw new BadRequestAlertException("未找到存储配置","FilterData",codename);
POSchema.Segment segment=getPOSchema().getSegment(codename,"");
if(segment==null)
throw new BadRequestAlertException("未找到查询方法配置","FilterData",codename);
String sql=segment.getBody(); String sql=segment.getBody();
QueryWrapper qw=this.getSearchCond(); QueryWrapper qw=this.getSearchCond();
...@@ -271,6 +362,9 @@ public class FilterData<T> extends BaseData ...@@ -271,6 +362,9 @@ public class FilterData<T> extends BaseData
sql=sql.concat(" where "); sql=sql.concat(" where ");
sql = sql.concat(qw.getSqlSegment()); sql = sql.concat(qw.getSqlSegment());
} }
if(!StringUtils.isEmpty(segment.getFormat()))
return String.format(segment.getFormat(),sql);
return sql; return sql;
} }
......
...@@ -18,10 +18,16 @@ public interface DbDataMapper { ...@@ -18,10 +18,16 @@ public interface DbDataMapper {
int insertData(@Param("schema") POSchema schema, @Param("data") BaseData data); int insertData(@Param("schema") POSchema schema, @Param("data") BaseData data);
int insertBathData(@Param("schema") POSchema schema, @Param("list") List<BaseData> list);
int updateData(@Param("schema") POSchema schema, @Param("data") BaseData data); int updateData(@Param("schema") POSchema schema, @Param("data") BaseData data);
int updateBathData(@Param("schema") POSchema schema, @Param("list") List<BaseData> list);
int removeData(@Param("schema") POSchema schema, @Param("data") BaseData data); int removeData(@Param("schema") POSchema schema, @Param("data") BaseData data);
int removeBathData(@Param("schema") POSchema schema, @Param("list") List<BaseData> list);
int save(@Param("schema") POSchema schema, @Param("data") BaseData data); int save(@Param("schema") POSchema schema, @Param("data") BaseData data);
int saveBatch(@Param("schema") POSchema schema, @Param("list") List<BaseData> list); int saveBatch(@Param("schema") POSchema schema, @Param("list") List<BaseData> list);
...@@ -30,6 +36,10 @@ public interface DbDataMapper { ...@@ -30,6 +36,10 @@ public interface DbDataMapper {
List<BaseData> getData(@Param("schema") POSchema schema, @Param("data") BaseData data); List<BaseData> getData(@Param("schema") POSchema schema, @Param("data") BaseData data);
List<BaseData> getBatchData(@Param("schema") POSchema schema, @Param("list") List<BaseData> list);
List<BaseData> getBatchKey(@Param("schema") POSchema schema, @Param("list") List<BaseData> list);
List<BaseData> selectData(@Param("schema") POSchema schema, @Param("data") BaseData data); List<BaseData> selectData(@Param("schema") POSchema schema, @Param("data") BaseData data);
Page<BaseData> selectData(@Param("schema") POSchema schema, @Param("data") BaseData data, IPage page); Page<BaseData> selectData(@Param("schema") POSchema schema, @Param("data") BaseData data, IPage page);
......
...@@ -13,6 +13,7 @@ import lombok.NoArgsConstructor; ...@@ -13,6 +13,7 @@ import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider; import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.io.File; import java.io.File;
...@@ -126,6 +127,14 @@ public class POSchema { ...@@ -126,6 +127,14 @@ public class POSchema {
@JSONField(serialize = false) @JSONField(serialize = false)
private Map<String,String> keyMap; private Map<String,String> keyMap;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,Column> searchMap;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,Column> quickSearch;
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public Map<String, Column> getColumnMaps() { public Map<String, Column> getColumnMaps() {
...@@ -145,6 +154,8 @@ public class POSchema { ...@@ -145,6 +154,8 @@ public class POSchema {
resultMap=new LinkedHashMap<>(); resultMap=new LinkedHashMap<>();
baseColumnMap=new LinkedHashMap<>(); baseColumnMap=new LinkedHashMap<>();
keyMap=new LinkedHashMap<>(); keyMap=new LinkedHashMap<>();
searchMap=new LinkedHashMap<>();
quickSearch=new LinkedHashMap<>();
columns.forEach(column -> { columns.forEach(column -> {
refreshColumn(column); refreshColumn(column);
}); });
...@@ -162,9 +173,23 @@ public class POSchema { ...@@ -162,9 +173,23 @@ public class POSchema {
baseColumnMap=new LinkedHashMap<>(); baseColumnMap=new LinkedHashMap<>();
if(keyMap==null) if(keyMap==null)
keyMap=new LinkedHashMap<>(); keyMap=new LinkedHashMap<>();
if(searchMap==null)
searchMap=new LinkedHashMap<>();
if(quickSearch==null)
quickSearch=new LinkedHashMap<>();
columnMaps.put(column.getName().toLowerCase(),column); columnMaps.put(column.getName().toLowerCase(),column);
if(!ObjectUtils.isEmpty(column.getSearchModes()))
{
column.getSearchModes().forEach(mode->{
if(!mode.equalsIgnoreCase("query"))
searchMap.put("n_"+column.getName().toLowerCase()+"_"+mode,column);
else
quickSearch.put(column.getName().toLowerCase(),column);
});
}
if(!column.isComputed()) if(!column.isComputed())
{ {
if(column.isLogicValid()) { if(column.isLogicValid()) {
...@@ -203,6 +228,13 @@ public class POSchema { ...@@ -203,6 +228,13 @@ public class POSchema {
keyMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase()); keyMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase());
} }
if(!ObjectUtils.isEmpty(column.getSearchModes()))
{
column.getSearchModes().forEach(mode->{
if(!mode.equalsIgnoreCase("query"))
searchMap.put("n_"+column.getAlias().toLowerCase()+"_"+mode,column);
});
}
} }
else else
{ {
...@@ -249,6 +281,26 @@ public class POSchema { ...@@ -249,6 +281,26 @@ public class POSchema {
return keyMap; return keyMap;
} }
@JsonIgnore
@JSONField(serialize = false)
public Map<String, Column> getSearchMap() {
if(columns!=null&&searchMap==null)
{
refreshColumnMaps();
}
return searchMap;
}
@JsonIgnore
@JSONField(serialize = false)
public Map<String, Column> getQuickSearch() {
if(columns!=null&&quickSearch==null)
{
refreshColumnMaps();
}
return quickSearch;
}
public Column getColumn(String name) public Column getColumn(String name)
{ {
if(getColumnMaps()!=null) if(getColumnMaps()!=null)
...@@ -306,16 +358,41 @@ public class POSchema { ...@@ -306,16 +358,41 @@ public class POSchema {
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public static class Column{ public static class Column{
@JSONField(ordinal = 1)
private String name; private String name;
@JSONField(ordinal = 2)
private String remarks; private String remarks;
@JSONField(ordinal = 3)
private String type; private String type;
@JSONField(ordinal = 4)
private Integer length; private Integer length;
@JSONField(ordinal = 5)
private Integer precision; private Integer precision;
@JSONField(ordinal = 6)
private String defaultValue; private String defaultValue;
@JSONField(ordinal = 7)
private Boolean autoIncrement; private Boolean autoIncrement;
@JSONField(ordinal = 8)
private Boolean computed; private Boolean computed;
@JSONField(ordinal = 9)
private String alias; private String alias;
@JSONField(ordinal = 10)
private String predefined; private String predefined;
@JSONField(ordinal = 11)
private Set<String> searchModes;
public Column putSearchModes(String searchModes)
{
if(!StringUtils.isEmpty(searchModes))
{
if(this.searchModes==null)
this.searchModes=new LinkedHashSet<>();
for(String mode:searchModes.split(","))
this.searchModes.add(mode);
}
return this;
}
public Column setAlias(String alias) public Column setAlias(String alias)
{ {
...@@ -402,6 +479,15 @@ public class POSchema { ...@@ -402,6 +479,15 @@ public class POSchema {
return type.indexOf("INT")==0; return type.indexOf("INT")==0;
} }
@JsonIgnore
@JSONField(serialize = false)
public boolean isDateTime()
{
String type=this.getType().toUpperCase();
return type.indexOf("DATE")>=0||type.indexOf("TIME")>=0;
}
@JSONField(ordinal = 12)
private Constraints constraints; private Constraints constraints;
public Constraints getConstraints(boolean createWhenNotExist) public Constraints getConstraints(boolean createWhenNotExist)
...@@ -475,6 +561,7 @@ public class POSchema { ...@@ -475,6 +561,7 @@ public class POSchema {
private String vendorProvider; private String vendorProvider;
private String declare; private String declare;
private String body; private String body;
private String format;
private Map params; private Map params;
public Segment setVendorProvider(String vendorProvider) public Segment setVendorProvider(String vendorProvider)
......
...@@ -253,6 +253,13 @@ public class PojoOption extends DataObj ...@@ -253,6 +253,13 @@ public class PojoOption extends DataObj
return this.set("expression",expression); return this.set("expression",expression);
} }
public String getSearchModes() {
return this.getStringValue("search_modes");
}
public PojoOption setSearchModes(String search_modes) {
return this.set("search_modes",search_modes);
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
......
...@@ -149,6 +149,9 @@ public class TransUtils { ...@@ -149,6 +149,9 @@ public class TransUtils {
} }
} }
Object searchModes=fieldModel.getField().get("search_modes");
if(searchModes!=null)
sub.getOptions().setSearchModes(searchModes.toString());
pojoSchema.addProperty(sub.getName(),sub); pojoSchema.addProperty(sub.getName(),sub);
order++; order++;
} }
...@@ -275,6 +278,8 @@ public class TransUtils { ...@@ -275,6 +278,8 @@ public class TransUtils {
else else
column.setDefaultValue("1"); column.setDefaultValue("1");
} }
if(!StringUtils.isEmpty(sub.getOptions().getSearchModes()))
column.putSearchModes(sub.getOptions().getSearchModes());
if("PICKUP".equals(sub.getOptions().getFieldType())&&sub.getOptions().isPhysicalField()) if("PICKUP".equals(sub.getOptions().getFieldType())&&sub.getOptions().isPhysicalField())
{ {
...@@ -346,6 +351,10 @@ public class TransUtils { ...@@ -346,6 +351,10 @@ public class TransUtils {
column.setDefaultValue("1"); column.setDefaultValue("1");
} }
Object searchModes=fieldModel.getField().get("search_modes");
if(searchModes!=null)
column.putSearchModes(searchModes.toString());
if("PICKUP".equals(sub.getFieldType())&&fieldModel.isPhysicalField()) if("PICKUP".equals(sub.getFieldType())&&fieldModel.isPhysicalField())
{ {
RelationshipModel relationshipModel=relationshipModelMap.get(sub.getRelationName()); RelationshipModel relationshipModel=relationshipModelMap.get(sub.getRelationName());
...@@ -378,11 +387,15 @@ public class TransUtils { ...@@ -378,11 +387,15 @@ public class TransUtils {
if(dataSet.getDatasetId().startsWith(entityModel.getEntityName().toLowerCase()+"-")&&dataSet.getDatasetId().endsWith(dataSourceType)) if(dataSet.getDatasetId().startsWith(entityModel.getEntityName().toLowerCase()+"-")&&dataSet.getDatasetId().endsWith(dataSourceType))
{ {
POSchema.Segment segment=new POSchema.Segment().setName(dataSet.getDatasetId()).setVendorProvider(dataSourceType).setBody(dataSet.getDsCode()); POSchema.Segment segment=new POSchema.Segment().setName(dataSet.getDatasetId()).setVendorProvider(dataSourceType).setBody(dataSet.getDsCode());
if(!StringUtils.isEmpty(dataSet.getDsModel()))
segment.setFormat(dataSet.getDsModel());
poSchema.addSegment(segment); poSchema.addSegment(segment);
} }
else if(!dataSet.getDatasetId().startsWith(entityModel.getEntityName().toLowerCase()+"-")) else if(!dataSet.getDatasetId().startsWith(entityModel.getEntityName().toLowerCase()+"-"))
{ {
POSchema.Segment segment=new POSchema.Segment().setName(dataSet.getCodeName()).setVendorProvider(dataSourceType).setBody(dataSet.getDsCode()); POSchema.Segment segment=new POSchema.Segment().setName(dataSet.getCodeName()).setVendorProvider(dataSourceType).setBody(dataSet.getDsCode());
if(!StringUtils.isEmpty(dataSet.getDsModel()))
segment.setFormat(dataSet.getDsModel());
poSchema.addSegment(segment); poSchema.addSegment(segment);
} }
}); });
......
...@@ -78,7 +78,7 @@ public class BaseDataService implements IDataService { ...@@ -78,7 +78,7 @@ public class BaseDataService implements IDataService {
{ {
Serializable key=requestBody.getKey(); Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyPropertyName()); key=model.getKeyValue(requestBody.getBaseData(),false);
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入"); return ResponseData.error(400,"key 没有输入");
if(remove(model, scope, datasource, key)) if(remove(model, scope, datasource, key))
...@@ -90,7 +90,7 @@ public class BaseDataService implements IDataService { ...@@ -90,7 +90,7 @@ public class BaseDataService implements IDataService {
{ {
Serializable key=requestBody.getKey(); Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyPropertyName()); key=model.getKeyValue(requestBody.getBaseData(),false);
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入"); return ResponseData.error(400,"key 没有输入");
BaseData data=get(model,scope,datasource,key); BaseData data=get(model,scope,datasource,key);
......
...@@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; 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.beans.factory.annotation.Value;
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.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -24,9 +25,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -24,9 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.List;
/** /**
* 实体[业务实体] 无存储服务对象接口实现 * 实体[业务实体] 无存储服务对象接口实现
...@@ -35,6 +34,8 @@ import java.util.List; ...@@ -35,6 +34,8 @@ import java.util.List;
@Service @Service
public class DbDataServiceImpl implements IDataService { public class DbDataServiceImpl implements IDataService {
@Value("${ibiz.data.batchsize:500}")
private int BATCH_SIZE;
@Autowired @Autowired
private DbDataMapper dbDataMapper; private DbDataMapper dbDataMapper;
...@@ -59,7 +60,24 @@ public class DbDataServiceImpl implements IDataService { ...@@ -59,7 +60,24 @@ public class DbDataServiceImpl implements IDataService {
@Override @Override
public void createBatch(DOModel model, String scope, String datasource, List<BaseData> list) public void createBatch(DOModel model, String scope, String datasource, List<BaseData> list)
{ {
List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource);
list.forEach(et->{
Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
dbDataMapper.insertBathData(poSchema,batch);
batch.clear();
}
});
if(batch.size()>=0)
{
dbDataMapper.insertBathData(poSchema,batch);
batch.clear();
}
} }
@Override @Override
...@@ -76,7 +94,24 @@ public class DbDataServiceImpl implements IDataService { ...@@ -76,7 +94,24 @@ public class DbDataServiceImpl implements IDataService {
@Override @Override
public void updateBatch(DOModel model, String scope, String datasource, List<BaseData> list) public void updateBatch(DOModel model, String scope, String datasource, List<BaseData> list)
{ {
List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource);
list.forEach(et->{
Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
dbDataMapper.updateBathData(poSchema,batch);
batch.clear();
}
});
if(batch.size()>=0)
{
dbDataMapper.updateBathData(poSchema,batch);
batch.clear();
}
} }
@Override @Override
...@@ -94,7 +129,24 @@ public class DbDataServiceImpl implements IDataService { ...@@ -94,7 +129,24 @@ public class DbDataServiceImpl implements IDataService {
@Override @Override
public void removeBatch(DOModel model, String scope, String datasource, List<Serializable> idList) public void removeBatch(DOModel model, String scope, String datasource, List<Serializable> idList)
{ {
List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource);
idList.forEach(key->{
BaseData et = model.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",model.getName(),null);
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
dbDataMapper.removeBathData(poSchema,batch);
batch.clear();
}
});
if(batch.size()>=0)
{
dbDataMapper.removeBathData(poSchema,batch);
batch.clear();
}
} }
@Override @Override
...@@ -126,7 +178,26 @@ public class DbDataServiceImpl implements IDataService { ...@@ -126,7 +178,26 @@ public class DbDataServiceImpl implements IDataService {
@Override @Override
public List<BaseData> getBatch(DOModel model, String scope, String datasource, List<Serializable> idList) public List<BaseData> getBatch(DOModel model, String scope, String datasource, List<Serializable> idList)
{ {
return null; List<BaseData> rt=new ArrayList<>();
List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource);
idList.forEach(key->{
BaseData et = model.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",model.getName(),null);
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
rt.addAll(dbDataMapper.getBatchData(poSchema,batch));
batch.clear();
}
});
if(batch.size()>=0)
{
rt.addAll(dbDataMapper.getBatchData(poSchema,batch));
batch.clear();
}
return rt;
} }
@Override @Override
...@@ -172,6 +243,47 @@ public class DbDataServiceImpl implements IDataService { ...@@ -172,6 +243,47 @@ public class DbDataServiceImpl implements IDataService {
public void saveBatch(DOModel model, String scope, String datasource, List<BaseData> list) public void saveBatch(DOModel model, String scope, String datasource, List<BaseData> list)
{ {
List<BaseData> rt=new ArrayList<>();
List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource);
list.forEach(et->{
Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
rt.addAll(dbDataMapper.getBatchData(poSchema,batch));
batch.clear();
}
});
if(batch.size()>=0)
{
rt.addAll(dbDataMapper.getBatchData(poSchema,batch));
batch.clear();
}
Map<Serializable,Integer> keys=new LinkedHashMap<>();
rt.forEach(et->{
Serializable key=model.getKeyValue(et,false);
if(!ObjectUtils.isEmpty(key))
keys.put(key,1);
});
List<BaseData> create=new ArrayList<>();
List<BaseData> update=new ArrayList<>();
list.forEach(et-> {
Serializable key = model.getKeyValue(et, false);
if(keys.containsKey(key))
update.add(et);
else
create.add(et);
});
if(update.size()>0)
this.updateBatch(model,scope,datasource,update);
if(create.size()>0)
this.createBatch(model,scope,datasource,create);
} }
@Override @Override
...@@ -193,23 +305,21 @@ public class DbDataServiceImpl implements IDataService { ...@@ -193,23 +305,21 @@ public class DbDataServiceImpl implements IDataService {
public List<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context) public List<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context)
{ {
POSchema poSchema=model.getPOSchema(datasource); POSchema poSchema=model.getPOSchema(datasource);
POSchema.Segment segment=poSchema.getSegment("-dq-"+dataQuery+"-",""); context.setPOSchema(poSchema);
return dbDataMapper.queryData(poSchema,context.getSql(segment),context,context.getSearchCond()); return dbDataMapper.queryData(poSchema,context.getSql("-dq-"+dataQuery+"-"),context,context.getSearchCond());
} }
@Override @Override
public Page<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context, Pageable pageable) public Page<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context, Pageable pageable)
{ {
POSchema poSchema=model.getPOSchema(datasource); POSchema poSchema=model.getPOSchema(datasource);
POSchema.Segment segment=poSchema.getSegment("-dq-"+dataQuery+"-",""); context.setPOSchema(poSchema);
if(pageable!=null) if(pageable!=null)
context.setPageable(pageable); context.setPageable(pageable);
else else
pageable=context.getPageable(); pageable=context.getPageable();
com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages= com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages=
dbDataMapper.queryData(poSchema,context.getSql(segment),context,context.getSearchCond(),context.getPages(poSchema)); dbDataMapper.queryData(poSchema,context.getSql("-dq-"+dataQuery+"-"),context,context.getSearchCond(),context.getPages());
return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal()); return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal());
} }
...@@ -231,22 +341,21 @@ public class DbDataServiceImpl implements IDataService { ...@@ -231,22 +341,21 @@ public class DbDataServiceImpl implements IDataService {
public List<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context) public List<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context)
{ {
POSchema poSchema=model.getPOSchema(datasource); POSchema poSchema=model.getPOSchema(datasource);
POSchema.Segment segment=poSchema.getSegment("-ds-"+dataSet+"-",""); context.setPOSchema(poSchema);
return dbDataMapper.queryData(poSchema,context.getSql("-ds-"+dataSet+"-"),context,context.getSearchCond());
return dbDataMapper.queryData(poSchema,context.getSql(segment),context,context.getSearchCond());
} }
@Override @Override
public Page<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context, Pageable pageable) public Page<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context, Pageable pageable)
{ {
POSchema poSchema=model.getPOSchema(datasource); POSchema poSchema=model.getPOSchema(datasource);
POSchema.Segment segment=poSchema.getSegment("-ds-"+dataSet+"-",""); context.setPOSchema(poSchema);
if(pageable!=null) if(pageable!=null)
context.setPageable(pageable); context.setPageable(pageable);
else else
pageable=context.getPageable(); pageable=context.getPageable();
com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages= com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages=
dbDataMapper.queryData(poSchema,context.getSql(segment),context,context.getSearchCond(),context.getPages(poSchema)); dbDataMapper.queryData(poSchema,context.getSql("-ds-"+dataSet+"-"),context,context.getSearchCond(),context.getPages());
return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal()); return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal());
} }
......
...@@ -2,43 +2,29 @@ ...@@ -2,43 +2,29 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.ibizlab.core.data.mapper.DbDataMapper"> <mapper namespace="cn.ibizlab.core.data.mapper.DbDataMapper">
<!--数据集合[Default]-->
<select id="search" parameterType="cn.ibizlab.core.data.dto.DbDataQuery" resultType="cn.ibizlab.core.data.dto.BaseData">
${sql}
<where><if test="ew!=null and ew.sqlSegment!=null and !ew.emptyOfWhere">${ew.sqlSegment}</if></where>
<if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
</select>
<select id="searchCount" parameterType="cn.ibizlab.core.data.dto.DbDataQuery" resultType="Integer">
${sql}
<where><if test="ew!=null and ew.sqlSegment!=null and !ew.emptyOfWhere">${ew.sqlSegment}</if></where>
<if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
</select>
<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.baseColumnMap" item="value" index="key" separator=",">${key}</foreach>)
( VALUES (<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">#{data[${value}]}</foreach>)
<foreach collection="schema.baseColumnMap" item="value" index="key" separator=","> </insert>
${key}
</foreach>
) <insert id="insertBatchData" parameterType="java.util.List">
VALUES <foreach collection="list" item="item" index="index" separator=";">
( INSERT INTO ${schema.name} (<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">${key}</foreach>)
<foreach collection="schema.baseColumnMap" item="value" index="key" separator=","> VALUES (<foreach collection="schema.baseColumnMap" item="value" index="key" separator=",">#{item[${value}]}</foreach>)
#{data[${value}]}
</foreach> </foreach>
)
</insert> </insert>
<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 <foreach collection="schema.baseColumnMap" item="value" index="key" separator=","><if test="data.keys.contains(value)">${key}= #{data[${value}]}</if></foreach>
set WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{data[${value}]}</foreach>
<foreach collection="schema.baseColumnMap" item="value" index="key" separator=","> </update>
<if test="data.keys.contains(value)">${key}= #{data[${value}]}</if>
</foreach> <update id="updateBatchData" parameterType="java.util.List" >
where <foreach collection="list" item="item" index="index" separator=";">
<foreach collection="schema.keyMap" item="value" index="key" separator="and"> UPDATE ${schema.name} SET <foreach collection="schema.baseColumnMap" item="value" index="key" separator=","><if test="data.keys.contains(value)">${key}= #{item[${value}]}</if></foreach>
${key}= #{data[${value}]} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{item[${value}]}</foreach>
</foreach> </foreach>
</update> </update>
...@@ -60,6 +46,30 @@ ...@@ -60,6 +46,30 @@
</foreach> </foreach>
</select> </select>
<select id="getBatchData" parameterType="java.util.List" resultType="cn.ibizlab.core.data.dto.BaseData">
select t1.* from
<choose>
<when test="schema.defaultQueryScript!=null">
( ${schema.defaultQueryScript.body} ) t1 where
</when>
<otherwise>
${schema.name} t1 where
<if test="schema.logicValidColumn!=null">
${schema.logicValidCond} and
</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>)
</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}</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>)
</select>
<select id="selectData" parameterType="cn.ibizlab.core.data.dto.BaseData" resultType="cn.ibizlab.core.data.dto.BaseData"> <select id="selectData" parameterType="cn.ibizlab.core.data.dto.BaseData" resultType="cn.ibizlab.core.data.dto.BaseData">
select t1.* from select t1.* from
<choose> <choose>
...@@ -73,7 +83,7 @@ ...@@ -73,7 +83,7 @@
</if> </if>
</otherwise> </otherwise>
</choose> </choose>
<foreach collection="schema.resultMap" item="value" index="key" separator=","> <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[${value}]}</if>
</foreach> </foreach>
</select> </select>
...@@ -90,25 +100,24 @@ ...@@ -90,25 +100,24 @@
</select> </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 ${schema.logicValidDelCond} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{data[${value}]}</foreach>
set
${schema.logicValidDelCond}
where
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #{data[${value}]}
</foreach>
</if> </if>
<if test="schema.logicValidColumn==null"> <if test="schema.logicValidColumn==null">
delete from ${schema.name} where DELETE FROM ${schema.name} WHERE <foreach collection="schema.keyMap" item="value" index="key" separator="and">${key}= #{data[${value}]}</foreach>
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #{data[${value}]}
</foreach>
</if> </if>
</update> </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>
</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>
</if>
</foreach>
</update>
</mapper> </mapper>
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册