提交 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 {
}
public POSchema getPOSchema(String name)
{
name="mysql5";
if(StringUtils.isEmpty(name)&&this.getSchema()!=null)
name=this.getSchema().getDefaultDataSoruce();
......
......@@ -6,6 +6,8 @@ import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema;
import com.alibaba.fastjson.JSON;
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.JsonInclude;
......@@ -41,26 +43,20 @@ public class BaseData extends DataObj
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private POSchema _poschema;
@JsonIgnore
@JSONField(serialize = false)
public POSchema getPOSchema()
{
Object obj=this.get("_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;
return _poschema;
}
public BaseData setPOSchema(POSchema poSchema)
{
return this.set("_poschema",poSchema);
this._poschema=poSchema;
return this;
}
public DOModel getDOModel()
......
package cn.ibizlab.core.data.dto;
import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.filter.QueryFilter;
import cn.ibizlab.util.filter.QueryWrapperContext;
import cn.ibizlab.util.helper.DEFieldCacheMap;
import cn.ibizlab.util.helper.DataObject;
import cn.ibizlab.util.security.AuthenticationUser;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.JsonProperty;
import org.springframework.data.domain.PageRequest;
......@@ -144,22 +149,43 @@ public class FilterData<T> extends BaseData
@JsonIgnore
@JSONField(serialize = false)
public Map<String,Object> getDatacontext() {
public BaseData getDatacontext() {
return getParams();
}
@JsonIgnore
@JSONField(serialize = false)
public Map<String,Object> getWebcontext() {
public BaseData getWebcontext() {
return getParams();
}
@JsonIgnore
@JSONField(serialize = false)
public Map<String,Object> getSessioncontext() {
return AuthenticationUser.getAuthenticationUser().getSessionParams();
public BaseData sessioncontext;
@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() {
return this.getStringValue("userTaskId",this.getParams().getStringValue("userTaskId"));
......@@ -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){
......@@ -233,35 +263,96 @@ public class FilterData<T> extends BaseData
@JsonIgnore
@JSONField(serialize = false)
private QueryWrapper searchCond=null;
public QueryWrapper getSearchCond()
private QueryWrapper<BaseData> searchCond=null;
public QueryWrapper<BaseData> getSearchCond()
{
if(searchCond==null)
{
if(this.getFilter()!=null)
{
QueryWrapperContext context=new QueryWrapperContext();
QueryWrapperContext<BaseData> context=new QueryWrapperContext<>();
context.setFilter(this.getFilter());
searchCond = context.getSelectCond();
}
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();
if(key.startsWith("n_")&&key.endsWith("_like"))
searchCond.and(qw-> {
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;
}
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();
QueryWrapper qw=this.getSearchCond();
......@@ -271,6 +362,9 @@ public class FilterData<T> extends BaseData
sql=sql.concat(" where ");
sql = sql.concat(qw.getSqlSegment());
}
if(!StringUtils.isEmpty(segment.getFormat()))
return String.format(segment.getFormat(),sql);
return sql;
}
......
......@@ -13,6 +13,8 @@ import net.ibizsys.model.dataentity.der.IPSDER1N;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCode;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCodeCond;
import net.ibizsys.model.dataentity.ds.IPSDEDataSetGroupParam;
import net.ibizsys.model.dataentity.ds.PSDEDataSetGroupParamImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
......@@ -27,6 +29,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service
public class DynamicModelService {
......@@ -232,6 +236,15 @@ public class DynamicModelService {
.setRelationName(linkDEField.getPSDER().getName()).setRelationCodeName(linkDEField.getPSDER().getCodeName()).setRefEntityName(linkDEField.getPSDER().getMajorPSDataEntity().getName());
}
if(!ObjectUtils.isEmpty(defield.getAllPSDEFSearchModes()))
{
List<String> modes=new ArrayList<>();
defield.getAllPSDEFSearchModes().forEach(item->modes.add(item.getValueOP().toLowerCase()));
if(defield.isEnableQuickSearch())
modes.add("query");
metaFieldModel.set("search_modes",String.join(",",modes));
}
fieldModel.setCodeName(metaFieldModel.getCodeName()).setColumnName(metaFieldModel.getFieldName()).setUnionName(metaFieldModel.getFieldUniName()).setShowName(metaFieldModel.getFieldShowName())
.setComment(metaFieldModel.getFieldLogicName()).setField(metaFieldModel);
......@@ -350,7 +363,7 @@ public class DynamicModelService {
}
code = code+ getQueryCode(dq);
;//"<include refid=\""+entityModel.getEntityName().toLowerCase()+"_dq_"+dataQuery.getCodeName()+"_"+dq.getDBType().toLowerCase()+"\"/>";
map.put(dq.getDBType(),code);
map.put(dq.getDBType(),"select t1.* from ("+code+") t1");
});
}
} catch (Exception exception) {
......@@ -361,7 +374,61 @@ public class DynamicModelService {
for(Map.Entry<String,String> entry:map.entrySet())
{
String sql="select t1.* from (\r\n".concat(entry.getValue()).concat("\r\n) t1");
String sql=null;
if(dataSet.getGroupMode()==1||dataSet.getMajorSortPSDEField()!=null)
{
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
{
sql="select ";
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(i>0)sql=sql.concat(",");
if(groupParam.isEnableGroup())
{
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
sql=sql.concat(groupParam.getGroupCode());
else
sql=sql.concat(groupParam.getName());
}
else
sql=sql.concat(groupParam.getGroupCode());
sql=sql.concat(" as ").concat(groupParam.getName().toLowerCase());
i++;
}
sql=sql.concat(" from ( %s ) t1");
}
else
sql="select t1.* from ( %s ) t1";
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
{
sql=sql.concat(" group by ");
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(groupParam.isEnableGroup())
{
if(i>0)sql=sql.concat(",");
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
sql=sql.concat(groupParam.getGroupCode());
else
sql=sql.concat(groupParam.getName());
i++;
}
}
}
if(dataSet.getMajorSortPSDEField()!=null)
{
IPSDEFDTColumn column = dataSet.getMajorSortPSDEField().getPSDEFDTColumn(entry.getKey(),false);
......@@ -379,9 +446,10 @@ public class DynamicModelService {
}
}
}
MetaDataSetModel dsModel=new MetaDataSetModel().setDatasetId(entityModel.getEntityName().toLowerCase()+"-ds-"+dataSet.getCodeName()+"-"+entry.getKey().toLowerCase())
.setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName())
.setEntityId(entityModel.getEntityId()).setEntityName(entityModel.getEntityName()).setDsCode(sql);
.setEntityId(entityModel.getEntityId()).setEntityName(entityModel.getEntityName()).setDsCode(entry.getValue()).setDsModel(sql);
entityModel.addDataSet(dsModel);
}
......@@ -468,50 +536,81 @@ public class DynamicModelService {
}
/*
<#function contextParamConvert contextParam>
<#comment>补充上下文的IN查询(in通过$获取参数,其余为#): IN (${srfdatacontext('cityid','{"defname":"CITYID","dename":"CITY"}')}) -->IN ( ${srf.srfdatacontext.cityid} ) </#comment>
<#assign resultParam=contextParam?replace("(IN|in) \\(\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}\\)","$1 (\\$\{srf.$2.$3})","r")>
<#comment>平台配置格式替换${srfdatacontext('cityid','{"defname":"CITYID","dename":"CITY"}')} --> #{srf.srfdatacontext.cityid} </#comment>
<#assign resultParam=resultParam?replace("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}","#\{srf.$1.$2}","r")>
<#comment>用户配置格式替换${srfdatacontext('cityid')} --> #{srf.srfdatacontext.cityid} </#comment>
<#assign resultParam=resultParam?replace("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)'\\)}","#\{srf.$1.$2}","r")>
<#comment>将上下文参数转小写 #{srf.srfdatacontext.SRFORGID} --> #{srf.srfdatacontext.srforgid}</#comment>
<#assign params=resultParam?matches('srf.(datacontext|sessioncontext|webcontext).(\\w+)')>
<#list params as param>
<#assign resultParam=resultParam?replace(param,param?lower_case,'i')>
</#list>
<#if sys.getSaaSMode()==1 && item.getSaaSMode()==1>
<#assign resultParam=resultParam?replace("AND t11.SRFDCID = '__SRFSAASDCID__'","")>
</#if>
<#return resultParam>
</#function>
*/
private String contextParamConvert(String contextParam)
{
String resultParam=contextParam.replaceAll("(IN|in) \\(\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}\\)","$1 (\\${srf.$2.$3})");
String resultParam=getJavaSqlCode(contextParam).replaceAll("(IN|in) \\(\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}\\)","$1 (\\${srf.$2.$3})");
resultParam=resultParam.replaceAll("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}","#{srf.$1.$2}");
resultParam=resultParam.replaceAll("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)'\\)}","#{srf.$1.$2}");
Pattern p = Pattern.compile("srf.(datacontext|sessioncontext|webcontext).(\\w+)");
Matcher m = p.matcher(resultParam);
StringBuffer sb = new StringBuffer();
while(m.find()){
String match = m.group();
resultParam=resultParam.replace(match,match.toLowerCase());
}
resultParam=resultParam.replace("AND t11.SRFDCID = '__SRFSAASDCID__'","");
return resultParam;
}
private String getQueryCode(IPSDEDataQueryCode dq)
{
String code=contextParamConvert(dq.getQueryCode());
if(dq.getPSDEDataQueryCodeConds()!=null)
{
int i=0;
boolean b=checkIgnoreNullvalueCond(dq.getPSDEDataQueryCodeConds());
for(IPSDEDataQueryCodeCond cond:dq.getPSDEDataQueryCodeConds())
{
if(i==0)
code=code.concat(" where ");
else if(i>0)
code=code.concat(" and ");
code=code.concat(contextParamConvert(cond.getCustomCond()));
code=code.concat(b?checkNullContextParamConvert(cond.getCustomCond()):contextParamConvert(cond.getCustomCond()));
i++;
}
}
return code;
}
private String getJavaSqlCode(String strSQLCode)
{
strSQLCode = strSQLCode.replace("\r\n", " ");
strSQLCode = strSQLCode.replace("\r", " ");
strSQLCode = strSQLCode.replace("\n", " ");
strSQLCode = strSQLCode.replace("\"", "\\\"");
return strSQLCode;
}
private String checkNullContextParamConvert(String contextParam) {
String resultParam = getJavaSqlCode(contextParam).replaceAll("<#assign _value=srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)><#if _value\\?length gt 0>(.*?)\\(\\$\\{_value}\\)<#else>1=1</#if>"," ('${srf.$1.$2}'=null or '${srf.$1.$2}'='' or $4 \\${srf.$1.$2} ");
resultParam = resultParam.replaceAll("<#assign _value=srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)><#if _value\\?length gt 0>(.*?)\\$\\{_value}(.*?)?<#else>1=1</#if>", " (#{srf.$1.$2}=null or #{srf.$1.$2}='' or $4#{srf.$1.$2}$5)");
resultParam=contextParamConvert(resultParam);
return resultParam;
}
private boolean checkIgnoreNullvalueCond(List<IPSDEDataQueryCodeCond> list)
{
if(list!=null)
{
for(IPSDEDataQueryCodeCond cond:list)
{
if(getJavaSqlCode(cond.getCustomCond()).matches("(.*?)srf(datacontext|sessioncontext|webcontext)(.*?)\\\\\"ignoreempty\\\\\":true(.*?)"))
return true;
}
}
return false;
}
}
......@@ -18,10 +18,16 @@ public interface DbDataMapper {
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 updateBathData(@Param("schema") POSchema schema, @Param("list") List<BaseData> list);
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 saveBatch(@Param("schema") POSchema schema, @Param("list") List<BaseData> list);
......@@ -30,6 +36,10 @@ public interface DbDataMapper {
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);
Page<BaseData> selectData(@Param("schema") POSchema schema, @Param("data") BaseData data, IPage page);
......
......@@ -13,6 +13,7 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.File;
......@@ -126,6 +127,14 @@ public class POSchema {
@JSONField(serialize = false)
private Map<String,String> keyMap;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,Column> searchMap;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,Column> quickSearch;
@JsonIgnore
@JSONField(serialize = false)
public Map<String, Column> getColumnMaps() {
......@@ -145,6 +154,8 @@ public class POSchema {
resultMap=new LinkedHashMap<>();
baseColumnMap=new LinkedHashMap<>();
keyMap=new LinkedHashMap<>();
searchMap=new LinkedHashMap<>();
quickSearch=new LinkedHashMap<>();
columns.forEach(column -> {
refreshColumn(column);
});
......@@ -162,9 +173,23 @@ public class POSchema {
baseColumnMap=new LinkedHashMap<>();
if(keyMap==null)
keyMap=new LinkedHashMap<>();
if(searchMap==null)
searchMap=new LinkedHashMap<>();
if(quickSearch==null)
quickSearch=new LinkedHashMap<>();
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.isLogicValid()) {
......@@ -203,6 +228,13 @@ public class POSchema {
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
{
......@@ -249,6 +281,26 @@ public class POSchema {
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)
{
if(getColumnMaps()!=null)
......@@ -306,16 +358,41 @@ public class POSchema {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Column{
@JSONField(ordinal = 1)
private String name;
@JSONField(ordinal = 2)
private String remarks;
@JSONField(ordinal = 3)
private String type;
@JSONField(ordinal = 4)
private Integer length;
@JSONField(ordinal = 5)
private Integer precision;
@JSONField(ordinal = 6)
private String defaultValue;
@JSONField(ordinal = 7)
private Boolean autoIncrement;
@JSONField(ordinal = 8)
private Boolean computed;
@JSONField(ordinal = 9)
private String alias;
@JSONField(ordinal = 10)
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)
{
......@@ -402,6 +479,15 @@ public class POSchema {
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;
public Constraints getConstraints(boolean createWhenNotExist)
......@@ -475,6 +561,7 @@ public class POSchema {
private String vendorProvider;
private String declare;
private String body;
private String format;
private Map params;
public Segment setVendorProvider(String vendorProvider)
......
......@@ -253,6 +253,13 @@ public class PojoOption extends DataObj
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
@JSONField(serialize = false)
......
......@@ -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);
order++;
}
......@@ -275,6 +278,8 @@ public class TransUtils {
else
column.setDefaultValue("1");
}
if(!StringUtils.isEmpty(sub.getOptions().getSearchModes()))
column.putSearchModes(sub.getOptions().getSearchModes());
if("PICKUP".equals(sub.getOptions().getFieldType())&&sub.getOptions().isPhysicalField())
{
......@@ -346,6 +351,10 @@ public class TransUtils {
column.setDefaultValue("1");
}
Object searchModes=fieldModel.getField().get("search_modes");
if(searchModes!=null)
column.putSearchModes(searchModes.toString());
if("PICKUP".equals(sub.getFieldType())&&fieldModel.isPhysicalField())
{
RelationshipModel relationshipModel=relationshipModelMap.get(sub.getRelationName());
......@@ -378,11 +387,15 @@ public class TransUtils {
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());
if(!StringUtils.isEmpty(dataSet.getDsModel()))
segment.setFormat(dataSet.getDsModel());
poSchema.addSegment(segment);
}
else if(!dataSet.getDatasetId().startsWith(entityModel.getEntityName().toLowerCase()+"-"))
{
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);
}
});
......
......@@ -78,7 +78,7 @@ public class BaseDataService implements IDataService {
{
Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyPropertyName());
key=model.getKeyValue(requestBody.getBaseData(),false);
if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入");
if(remove(model, scope, datasource, key))
......@@ -90,7 +90,7 @@ public class BaseDataService implements IDataService {
{
Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyPropertyName());
key=model.getKeyValue(requestBody.getBaseData(),false);
if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入");
BaseData data=get(model,scope,datasource,key);
......
......@@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import lombok.extern.slf4j.Slf4j;
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.PageImpl;
import org.springframework.data.domain.Pageable;
......@@ -24,9 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.*;
/**
* 实体[业务实体] 无存储服务对象接口实现
......@@ -35,6 +34,8 @@ import java.util.List;
@Service
public class DbDataServiceImpl implements IDataService {
@Value("${ibiz.data.batchsize:500}")
private int BATCH_SIZE;
@Autowired
private DbDataMapper dbDataMapper;
......@@ -59,7 +60,24 @@ public class DbDataServiceImpl implements IDataService {
@Override
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
......@@ -76,7 +94,24 @@ public class DbDataServiceImpl implements IDataService {
@Override
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
......@@ -94,7 +129,24 @@ public class DbDataServiceImpl implements IDataService {
@Override
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
......@@ -126,7 +178,26 @@ public class DbDataServiceImpl implements IDataService {
@Override
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
......@@ -172,6 +243,47 @@ public class DbDataServiceImpl implements IDataService {
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
......@@ -193,23 +305,21 @@ public class DbDataServiceImpl implements IDataService {
public List<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context)
{
POSchema poSchema=model.getPOSchema(datasource);
POSchema.Segment segment=poSchema.getSegment("-dq-"+dataQuery+"-","");
return dbDataMapper.queryData(poSchema,context.getSql(segment),context,context.getSearchCond());
context.setPOSchema(poSchema);
return dbDataMapper.queryData(poSchema,context.getSql("-dq-"+dataQuery+"-"),context,context.getSearchCond());
}
@Override
public Page<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context, Pageable pageable)
{
POSchema poSchema=model.getPOSchema(datasource);
POSchema.Segment segment=poSchema.getSegment("-dq-"+dataQuery+"-","");
context.setPOSchema(poSchema);
if(pageable!=null)
context.setPageable(pageable);
else
pageable=context.getPageable();
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());
}
......@@ -231,22 +341,21 @@ public class DbDataServiceImpl implements IDataService {
public List<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context)
{
POSchema poSchema=model.getPOSchema(datasource);
POSchema.Segment segment=poSchema.getSegment("-ds-"+dataSet+"-","");
return dbDataMapper.queryData(poSchema,context.getSql(segment),context,context.getSearchCond());
context.setPOSchema(poSchema);
return dbDataMapper.queryData(poSchema,context.getSql("-ds-"+dataSet+"-"),context,context.getSearchCond());
}
@Override
public Page<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context, Pageable pageable)
{
POSchema poSchema=model.getPOSchema(datasource);
POSchema.Segment segment=poSchema.getSegment("-ds-"+dataSet+"-","");
context.setPOSchema(poSchema);
if(pageable!=null)
context.setPageable(pageable);
else
pageable=context.getPageable();
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());
}
......
......@@ -2,43 +2,29 @@
<!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">
<!--数据集合[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 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}]}
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>)
</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>)
</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}]}
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>
<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>
</foreach>
</update>
......@@ -60,6 +46,30 @@
</foreach>
</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 t1.* from
<choose>
......@@ -73,7 +83,7 @@
</if>
</otherwise>
</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>
</foreach>
</select>
......@@ -90,25 +100,24 @@
</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[${value}]}</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[${value}]}</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>
</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>
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册