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

提交

上级 b413a71c
spring:
datasource:
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/a_A_5d9d78509?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&allowMultiQueries=true&useTimezone=true&serverTimezone=GMT%2B8
isSyncDBSchema: false
dynamic:
druid: #以下是全局默认值,可以全局更改
filters: stat,wall,log4j2
#配置初始化大小/最小/最大
initial-size: 1
min-idle: 1
max-active: 20
#获取连接等待超时时间
max-wait: 60000
#间隔多久进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 60000
#一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
#打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
pool-prepared-statements: false
max-pool-prepared-statement-per-connection-size: 20
datasource:
master:
username: ${spring.datasource.username}
password: ${spring.datasource.password}
url: ${spring.datasource.url}
driver-class-name: ${spring.datasource.driver-class-name}
conf: classpath:liquibase/master.xml
isSyncDBSchema: ${spring.datasource.isSyncDBSchema}
defaultSchema: ${spring.datasource.defaultSchema}
cloud:
nacos:
discovery:
server-addr: 172.16.100.77:8848
redis:
host: 172.16.100.77
cache:
caffeine:
spec: initialCapacity=5,maximumSize=50000,expireAfterWrite=3600s
......@@ -115,8 +115,22 @@ public class DOModel extends EntityBase implements Serializable {
private String poModels;
@JSONField(serialize = false)
@JsonIgnore
public String getKeyFieldName()
{
return "";
}
@JSONField(serialize = false)
@JsonIgnore
public String getDefaultDataSource()
{
return "";
}
}
package cn.ibizlab.core.data.dto;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.domain.DTOModel;
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.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.Map;
@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonIgnoreProperties(ignoreUnknown = true)
public class BaseData extends DataObj
{
public BaseData set(String key, Object value)
{
this.put(key,value);
return this;
}
public Serializable getSerializableValue(String key)
{
Object obj=this.get(key);
if(obj!=null)
return (Serializable)obj;
else
return null;
}
public BaseData setAll(Map map)
{
if(map!=null)
this.putAll(map);
else if(this.size()==0)
return null;
return this;
}
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;
}
public BaseData setPOSchema(POSchema poSchema)
{
return this.set("_poschema",poSchema);
}
public DOModel getDOModel()
{
Object obj=this.get("_domodel");
if(obj!=null)
{
if (obj instanceof DOModel)
return (DOModel) obj;
else if(obj instanceof Map)
{
DOModel _domodel= JSONObject.parseObject(JSON.toJSONString(obj),DOModel.class);
this.put("_domodel",_domodel);
return _domodel;
}
}
return null;
}
public BaseData setDOModel(DOModel doModel)
{
return this.set("_domodel",doModel);
}
public DTOModel getDTOModel()
{
Object obj=this.get("_dtomodel");
if(obj!=null)
{
if (obj instanceof DTOModel)
return (DTOModel) obj;
else if(obj instanceof Map)
{
DTOModel _dtomodel= JSONObject.parseObject(JSON.toJSONString(obj),DTOModel.class);
this.put("_dtomodel",_dtomodel);
return _dtomodel;
}
}
return null;
}
public BaseData setDTOModel(DTOModel dtoModel)
{
return this.set("_dtomodel",dtoModel);
}
public PojoSchema getPojoSchema()
{
Object obj=this.get("_pojoschema");
if(obj==null)
{
DOModel doModel=this.getDOModel();
if(doModel!=null)
obj=doModel.getSchema();
}
if(obj==null)
{
DTOModel dtoModel=this.getDTOModel();
if(dtoModel!=null)
obj=dtoModel.getSchema();
}
if(obj!=null)
{
if (obj instanceof PojoSchema)
return (PojoSchema) obj;
else if(obj instanceof Map)
{
PojoSchema _pojoschema= JSONObject.parseObject(JSON.toJSONString(obj),PojoSchema.class);
this.put("_pojoschema",_pojoschema);
return _pojoschema;
}
}
return null;
}
public BaseData setKey(Object key)
{
return this.set("key",key);
}
}
package cn.ibizlab.core.data.model;
package cn.ibizlab.core.data.dto;
import cn.ibizlab.util.domain.DTOBase;
import cn.ibizlab.util.domain.EntityBase;
......
package cn.ibizlab.core.data.dto;
import cn.ibizlab.util.filter.QueryWrapperContext;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
/**
* 关系型数据实体[MetaEntity] 查询条件对象
*/
@Slf4j
@Data
public class DbDataQuery extends QueryWrapperContext<BaseData>
{
}
package cn.ibizlab.core.data.dto;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.util.ObjectUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class RequestData<T> extends BaseData
{
public RequestData set(String key, Object value)
{
this.put(key,value);
return this;
}
public RequestData setKey(Object key)
{
return this.set("key",key);
}
public Serializable getKey()
{
Object key=this.get("key");
if(key!=null)
return (Serializable)key;
else
return null;
}
public RequestData setSystem(String system)
{
return this.set("system",system);
}
public String getSystem()
{
return this.getStringValue("system");
}
public RequestData setEntity(String entity)
{
return this.set("entity",entity);
}
public String getEntity()
{
return this.getStringValue("entity",this.getStringValue("dename"));
}
public RequestData setMethod(String method)
{
return this.set("method",method);
}
public String getMethod()
{
return this.getStringValue("method",this.getStringValue("action"));
}
public RequestData setDataSource(String datasource)
{
return this.set("datasource",datasource);
}
public String getDataSource()
{
return this.getStringValue("datasource");
}
public RequestData setBody(T data)
{
return this.set("data",data);
}
public T getBody()
{
if(this.get("data")!=null)
return (T)this.get("data");
else
return null;
}
public BaseData getBaseData()
{
Object body=getBody();
if(body!=null&&body instanceof BaseData)
return (BaseData)body;
return this;
}
public List<BaseData> getListData()
{
Object body=getBody();
if(body!=null&&body instanceof List)
{
if(((List) body).size()==0)
return new ArrayList<>();
else if(((List) body).get(0) instanceof BaseData)
return (List<BaseData> )body;
else
return JSONArray.parseArray(JSON.toJSONString(body),BaseData.class);
}
return new ArrayList<>();
}
}
package cn.ibizlab.core.data.dto;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.lang.Nullable;
public class ResponseData<T> extends BaseData
{
public ResponseData set(String key, Object value)
{
this.put(key,value);
return this;
}
public Integer getCode() {
return this.getIntegerValue("code",1);
}
public String getMessage() {
return this.getStringValue("message",this.getStringValue("info",""));
}
public Boolean isSuccess() {
return this.get("success")!=null&&this.get("success").equals(true);
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isOk()
{
if(isSuccess()||getCode().equals("0"))
return true;
return false;
}
public ResponseData ok()
{
return this.set("success",true).set("code",0);
}
public ResponseData body(T data)
{
return this.set("data",data);
}
public T getBody()
{
if(this.get("data")!=null)
return (T)this.get("data");
else
return null;
}
public ResponseData error(Integer code)
{
return this.set("success",false).set("code",code);
}
public ResponseData error(String info)
{
return this.set("success",false).set("code",this.getCode()).set("message",info);
}
public static <T> ResponseData<T> ok(@Nullable T body)
{
ResponseData<T> responseBody = new ResponseData<T>();
return responseBody.ok().body(body);
}
public static ResponseData error(int code,String info)
{
ResponseData responseBody = new ResponseData();
return responseBody.error(code).error(info);
}
}
package cn.ibizlab.core.data.mapper;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.model.POSchema;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DbDataMapper {
List<BaseData> search(@Param("sql") String sql, @Param("ew") Wrapper<BaseData> wrapper);
int searchCount(@Param("sql") String sql, @Param("ew") Wrapper<BaseData> wrapper);
int saveBatch(@Param("schema") POSchema schema, @Param("list") List<BaseData> list);
int save(@Param("schema") POSchema schema, @Param("data") BaseData data);
int insert(@Param("schema") POSchema schema, @Param("data") BaseData data);
int update(@Param("schema") POSchema schema, @Param("data") BaseData data);
int remove(@Param("schema") POSchema schema, @Param("data") BaseData data);
}
\ No newline at end of file
......@@ -11,10 +11,7 @@ import lombok.experimental.Accessors;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Getter
@Setter
......@@ -30,6 +27,8 @@ public class POSchema {
private String dsType;
private String defaultDataSource;
private List<Column> columns;
private List<ForeignKeyConstraint> foreignKeyConstraints;
......@@ -38,19 +37,64 @@ public class POSchema {
@JSONField(serialize = false)
private Map<String,Column> columnMaps;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,String> resultMap;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,String> keyMap;
@JsonIgnore
@JSONField(serialize = false)
public Map<String, Column> getColumnMaps() {
if(columns!=null&&columnMaps==null)
{
columnMaps=new LinkedHashMap<>();
resultMap=new LinkedHashMap<>();
keyMap=new LinkedHashMap<>();
columns.forEach(column -> {
columnMaps.put(column.getName().toLowerCase(),column);
if((!StringUtils.isEmpty(column.getAlias()))&&column.getAlias().equalsIgnoreCase(column.getName()))
columnMaps.put(column.getAlias().toLowerCase(),column);
{
columnMaps.put(column.getAlias().toLowerCase(), column);
resultMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase());
if(column.isPrimaryKey())
keyMap.put(column.getName().toLowerCase(),column.getAlias().toLowerCase());
}
else
{
resultMap.put(column.getName().toLowerCase(), column.getName().toLowerCase());
if(column.isPrimaryKey())
keyMap.put(column.getName().toLowerCase(),column.getName().toLowerCase());
}
});
}
return columnMaps;
}
@JsonIgnore
@JSONField(serialize = false)
public Map<String, String> getResultMap() {
if(columns!=null&&resultMap==null)
{
getColumnMaps();
}
return resultMap;
}
@JsonIgnore
@JSONField(serialize = false)
public Map<String, String> getKeyMap() {
if(columns!=null&&keyMap==null)
{
getColumnMaps();
}
return keyMap;
}
public Column getColumn(String name)
{
if(getColumnMaps()!=null)
......@@ -165,7 +209,13 @@ public class POSchema {
private Boolean autoIncrement;
private String alias;
private String predefined;
private Boolean tenant;
@JsonIgnore
@JSONField(serialize = false)
public boolean isPrimaryKey()
{
return this.getConstraints()!=null&&this.getConstraints().getPrimaryKey();
}
@JsonIgnore
@JSONField(serialize = false)
......@@ -279,10 +329,14 @@ public class POSchema {
vendorProvider=provider.get(type.toLowerCase());
for(Script script:scripts)
{
if(name.equalsIgnoreCase(script.getName())&&(vendorProvider.equals(script.getVendorProvider())||StringUtils.isEmpty(script.getVendorProvider())))
if(name.equalsIgnoreCase(script.getName())&&((script.getVendorProvider().indexOf(vendorProvider)>=0)||StringUtils.isEmpty(script.getVendorProvider())))
return script;
}
}
else
{
scripts=new ArrayList<>();
}
return getDefaultQueryScript();
}
......@@ -297,26 +351,11 @@ public class POSchema {
if(defaultQueryScript==null)
{
defaultQueryScript=new Script();
defaultQueryScript.setName("default");
defaultQueryScript.setVendorProvider("mysql,oracle,postgresql");
String sql="select ";
if(columns!=null)
{
String cols="";
for(Column col:columns)
{
if(!StringUtils.isEmpty(cols))
cols+=",";
cols+=(col.getName());
if((!StringUtils.isEmpty(col.getAlias()))&&col.getAlias().equalsIgnoreCase(col.getName()))
cols+=(" as "+col.getAlias());
}
sql+=cols;
}
else
sql+=" * ";
sql += (" from "+name+" t ");
sql += (getBaseColumns()+" from "+name+" t ");
if(isLogicValid())
{
......@@ -330,10 +369,50 @@ public class POSchema {
sql+=(defaultVal+" ");
}
defaultQueryScript.setBody(sql);
}
return defaultQueryScript;
}
@JsonIgnore
@JSONField(serialize = false)
private String baseColumns;
@JsonIgnore
@JSONField(serialize = false)
public String getBaseColumns()
{
if(StringUtils.isEmpty(baseColumns))
{
String cols="";
if(columns!=null)
{
for(Column col:columns)
{
if(!StringUtils.isEmpty(cols))
cols+=",";
cols+=(col.getName());
if((!StringUtils.isEmpty(col.getAlias()))&&col.getAlias().equalsIgnoreCase(col.getName()))
cols+=(" as "+col.getAlias());
}
}
else
cols="*";
baseColumns=cols;
}
return baseColumns;
}
@JsonIgnore
@JSONField(serialize = false)
public Script getDefaultInsertScript()
{
Script defaultInsertScrip=new Script();
defaultInsertScrip.setName("insert");
defaultInsertScrip.setVendorProvider("mysql,oracle,postgresql");
String sql="";
defaultInsertScrip.setBody(sql);
return defaultInsertScrip;
}
}
package cn.ibizlab.core.data.model;
import cn.ibizlab.core.data.dto.DataObj;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
......@@ -10,7 +11,8 @@ import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PojoOption extends DataObj{
public class PojoOption extends DataObj
{
public PojoOption set(String key, Object value)
......
package cn.ibizlab.core.data.service;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.RequestData;
import cn.ibizlab.core.data.dto.ResponseData;
import cn.ibizlab.util.filter.SearchContextBase;
import org.springframework.data.domain.Page;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.List;
public interface IDataService
{
default ResponseData call(String system,String entity,String method,RequestData requestData)
{
return call(system,entity,method,"",requestData);
}
default ResponseData call(RequestData requestData)
{
return call(getDOModel(requestData.getSystem(),requestData.getEntity()),requestData.getMethod(),requestData.getDataSource(),requestData);
}
default boolean create(String system,String entity,BaseData et)
{
return create(getDOModel(system,entity),"",et);
}
default void createBatch(String system,String entity,List<BaseData> list)
{
createBatch(getDOModel(system,entity),"",list);
}
default boolean update(String system,String entity,BaseData et)
{
return update(getDOModel(system,entity),"",et);
}
default void updateBatch(String system,String entity,List<BaseData> list)
{
updateBatch(getDOModel(system,entity),"",list);
}
default boolean remove(String system,String entity,Serializable key)
{
return remove(getDOModel(system,entity),"",key);
}
default void removeBatch(String system,String entity,List<Serializable> idList)
{
removeBatch(getDOModel(system,entity),"",idList);
}
default BaseData get(String system,String entity,Serializable key)
{
return get(getDOModel(system,entity),"",key);
}
default BaseData getDraft(String system,String entity,BaseData et)
{
return getDraft(getDOModel(system,entity),"",et);
}
default boolean checkKey(String system,String entity,BaseData et)
{
return checkKey(getDOModel(system,entity),"",et);
}
default boolean save(String system,String entity,BaseData et)
{
return save(getDOModel(system,entity),"",et);
}
default void saveBatch(String system,String entity,List<BaseData> list)
{
saveBatch(getDOModel(system,entity),"",list);
}
default Page<BaseData> fetch(String system,String entity, String dataSet,SearchContextBase context)
{
return fetch(getDOModel(system,entity),dataSet,"",context);
}
default List<BaseData> list(String system,String entity, String dataSet,SearchContextBase context)
{
return list(getDOModel(system,entity),dataSet,"",context);
}
default Page<BaseData> fetchDefault(String system,String entity,SearchContextBase context)
{
return fetchDefault(getDOModel(system,entity),"",context);
}
default List<BaseData> listDefault(String system,String entity,SearchContextBase context)
{
return listDefault(getDOModel(system,entity),"",context);
}
DOModel getDOModel(String system,String entity);
ResponseData call(DOModel model,String method,String datasource, RequestData requestData);
boolean create(DOModel model,String datasource,BaseData et);
void createBatch(DOModel model,String datasource,List<BaseData> list);
boolean update(DOModel model,String datasource,BaseData et);
void updateBatch(DOModel model,String datasource,List<BaseData> list);
boolean remove(DOModel model,String datasource, Serializable key);
void removeBatch(DOModel model,String datasource,List<Serializable> idList);
BaseData get(DOModel model,String datasource,Serializable key);
BaseData getDraft(DOModel model,String datasource,BaseData et);
boolean checkKey(DOModel model,String datasource,BaseData et);
boolean save(DOModel model,String datasource,BaseData et);
void saveBatch(DOModel model,String datasource,List<BaseData> list);
Page<BaseData> fetch(DOModel model,String dataSet,String datasource,SearchContextBase context);
List<BaseData> list(DOModel model,String dataSet,String datasource,SearchContextBase context);
default Page<BaseData> fetchDefault(DOModel model,String datasource,SearchContextBase context){
return fetch(model,"default",datasource,context);
}
default List<BaseData> listDefault(DOModel model,String datasource,SearchContextBase context){
return list(model,"default",datasource,context);
}
default ResponseData call(String system,String entity,String method,String datasource,RequestData requestData)
{
requestData.setSystem(system).setEntity(entity).setMethod(method).setDataSource(datasource);
return call(getDOModel(system,entity),method,datasource,requestData);
}
default boolean create(String system,String entity,String datasource,BaseData et)
{
return create(getDOModel(system,entity),datasource,et);
}
default void createBatch(String system,String entity,String datasource,List<BaseData> list)
{
createBatch(getDOModel(system,entity),datasource,list);
}
default boolean update(String system,String entity,String datasource,BaseData et)
{
return update(getDOModel(system,entity),datasource,et);
}
default void updateBatch(String system,String entity,String datasource,List<BaseData> list)
{
updateBatch(getDOModel(system,entity),datasource,list);
}
default boolean remove(String system,String entity,String datasource,Serializable key)
{
return remove(getDOModel(system,entity),datasource,key);
}
default void removeBatch(String system,String entity,String datasource,List<Serializable> idList)
{
removeBatch(getDOModel(system,entity),datasource,idList);
}
default BaseData get(String system,String entity,String datasource,Serializable key)
{
return get(getDOModel(system,entity),datasource,key);
}
default BaseData getDraft(String system,String entity,String datasource,BaseData et)
{
return getDraft(getDOModel(system,entity),datasource,et);
}
default boolean checkKey(String system,String entity,String datasource,BaseData et)
{
return checkKey(getDOModel(system,entity),datasource,et);
}
default boolean save(String system,String entity,String datasource,BaseData et)
{
return save(getDOModel(system,entity),datasource,et);
}
default void saveBatch(String system,String entity,String datasource,List<BaseData> list)
{
saveBatch(getDOModel(system,entity),datasource,list);
}
default Page<BaseData> fetch(String system,String entity,String dataSet,String datasource,SearchContextBase context)
{
return fetch(getDOModel(system,entity),dataSet,datasource,context);
}
default List<BaseData> list(String system,String entity,String dataSet,String datasource,SearchContextBase context)
{
return list(getDOModel(system,entity),dataSet,datasource,context);
}
default Page<BaseData> fetchDefault(String system,String entity,String datasource,SearchContextBase context)
{
return fetchDefault(getDOModel(system,entity),datasource,context);
}
default List<BaseData> listDefault(String system,String entity,String datasource,SearchContextBase context)
{
return listDefault(getDOModel(system,entity),datasource,context);
}
}
package cn.ibizlab.core.data.service.impl;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.DbDataQuery;
import cn.ibizlab.core.data.dto.RequestData;
import cn.ibizlab.core.data.dto.ResponseData;
import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.util.filter.SearchContextBase;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
/**
* 实体[业务实体] 无存储服务对象接口实现
*/
@Slf4j
@Primary
@Service
public class BaseDataService implements IDataService {
@Override
public DOModel getDOModel(String system, String entity)
{
return null;
}
@Autowired
private DbDataServiceImpl dbProxyService;
@Autowired
private MongoDataServiceImpl mongoProxyService;
public IDataService getProxyService(String datasource)
{
if(datasource.indexOf("mongo")>0)
return mongoProxyService;
else
return dbProxyService;
}
@Override
public ResponseData call(DOModel model, String method, String datasource, RequestData requestBody)
{
if("create".equalsIgnoreCase(method))
{
if(create(model, datasource, requestBody.getBaseData()))
return ResponseData.ok(requestBody.getBaseData());
else
return ResponseData.error(1,"");
}
else if("update".equalsIgnoreCase(method))
{
if(update(model, datasource, requestBody.getBaseData()))
return ResponseData.ok(requestBody.getBaseData());
else
return ResponseData.error(1,"");
}
else if("save".equalsIgnoreCase(method))
{
if(save(model, datasource, requestBody.getBaseData()))
return ResponseData.ok(requestBody.getBaseData());
else
return ResponseData.error(1,"");
}
else if("remove".equalsIgnoreCase(method))
{
Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyFieldName());
if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入");
if(remove(model, datasource, key))
return ResponseData.ok(requestBody.getBaseData());
else
return ResponseData.error(1,"");
}
else if("get".equalsIgnoreCase(method))
{
Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyFieldName());
if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入");
BaseData data=get(model,datasource,key);
if(data!=null)
return ResponseData.ok(data);
else
return ResponseData.error(404,"");
}
else if("checkKey".equalsIgnoreCase(method))
{
if(checkKey(model, datasource, requestBody.getBaseData()))
return ResponseData.ok(requestBody.getBaseData());
else
return ResponseData.error(1,"");
}
else if("getDraft".equalsIgnoreCase(method))
{
return ResponseData.ok(getDraft(model, datasource, requestBody.getBaseData()));
}
else if("createBatch".equalsIgnoreCase(method))
{
createBatch(model, datasource, requestBody.getListData());
return ResponseData.ok(true);
}
else if("updateBatch".equalsIgnoreCase(method))
{
updateBatch(model, datasource, requestBody.getListData());
return ResponseData.ok(true);
}
else if("saveBatch".equalsIgnoreCase(method))
{
saveBatch(model, datasource, requestBody.getListData());
return ResponseData.ok(true);
}
return null;
}
@Override
public boolean create(DOModel model, String datasource, BaseData et)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).create(model,datasource,et);
}
@Override
public void createBatch(DOModel model, String datasource, List<BaseData> list)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
getProxyService(datasource).createBatch(model,datasource,list);
}
@Override
public boolean update(DOModel model, String datasource, BaseData et)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).update(model,datasource,et);
}
@Override
public void updateBatch(DOModel model, String datasource, List<BaseData> list)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
getProxyService(datasource).updateBatch(model,datasource,list);
}
@Override
public boolean remove(DOModel model, String datasource, Serializable key)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).remove(model,datasource,key);
}
@Override
public void removeBatch(DOModel model, String datasource, List<Serializable> idList)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
getProxyService(datasource).removeBatch(model,datasource,idList);
}
@Override
public BaseData get(DOModel model, String datasource, Serializable key)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).get(model,datasource,key);
}
@Override
public BaseData getDraft(DOModel model, String datasource, BaseData et)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).getDraft(model,datasource,et);
}
@Override
public boolean checkKey(DOModel model, String datasource, BaseData et)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).checkKey(model,datasource,et);
}
@Override
public boolean save(DOModel model, String datasource, BaseData et)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).save(model,datasource,et);
}
@Override
public void saveBatch(DOModel model, String datasource, List<BaseData> list)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
getProxyService(datasource).saveBatch(model,datasource,list);
}
@Override
public Page<BaseData> fetch(DOModel model, String dataSet, String datasource, SearchContextBase context)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).fetch(model,dataSet,datasource,context);
}
@Override
public List<BaseData> list(DOModel model, String dataSet, String datasource, SearchContextBase context)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).list(model,dataSet,datasource,context);
}
}
package cn.ibizlab.core.data.service.impl;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.DbDataQuery;
import cn.ibizlab.core.data.filter.DOModelSearchContext;
import cn.ibizlab.core.data.mapper.DbDataMapper;
import cn.ibizlab.core.data.service.IDOModelService;
import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.util.filter.SearchContextBase;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* 实体[业务实体] 无存储服务对象接口实现
*/
@Slf4j
@Service
public class DbDataServiceImpl extends BaseDataService {
@Autowired
private DbDataMapper dbDataMapper;
@Override
public boolean create(DOModel model, String datasource, BaseData et)
{
return false;
}
@Override
public void createBatch(DOModel model, String datasource, List<BaseData> list)
{
}
@Override
public boolean update(DOModel model, String datasource, BaseData et)
{
return false;
}
@Override
public void updateBatch(DOModel model, String datasource, List<BaseData> list)
{
}
@Override
public boolean remove(DOModel model, String datasource, Serializable key)
{
return false;
}
@Override
public void removeBatch(DOModel model, String datasource, List<Serializable> idList)
{
}
@Override
public BaseData get(DOModel model, String datasource, Serializable key)
{
return null;
}
@Override
public BaseData getDraft(DOModel model, String datasource, BaseData et)
{
return null;
}
@Override
public boolean checkKey(DOModel model, String datasource, BaseData et)
{
return false;
}
@Override
public boolean save(DOModel model, String datasource, BaseData et)
{
return false;
}
@Override
public void saveBatch(DOModel model, String datasource, List<BaseData> list)
{
}
@Override
public Page<BaseData> fetch(DOModel model, String dataSet, String datasource, SearchContextBase context)
{
return null;
}
@Override
public List<BaseData> list(DOModel model, String dataSet, String datasource, SearchContextBase context)
{
return null;
}
}
package cn.ibizlab.core.data.service.impl;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.util.filter.SearchContextBase;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;
/**
* 实体[业务实体] 无存储服务对象接口实现
*/
@Slf4j
@Service
public class MongoDataServiceImpl extends BaseDataService {
@Override
public boolean create(DOModel model, String datasource, BaseData et)
{
return false;
}
@Override
public void createBatch(DOModel model, String datasource, List<BaseData> list)
{
}
@Override
public boolean update(DOModel model, String datasource, BaseData et)
{
return false;
}
@Override
public void updateBatch(DOModel model, String datasource, List<BaseData> list)
{
}
@Override
public boolean remove(DOModel model, String datasource, Serializable key)
{
return false;
}
@Override
public void removeBatch(DOModel model, String datasource, List<Serializable> idList)
{
}
@Override
public BaseData get(DOModel model, String datasource, Serializable key)
{
return null;
}
@Override
public BaseData getDraft(DOModel model, String datasource, BaseData et)
{
return null;
}
@Override
public boolean checkKey(DOModel model, String datasource, BaseData et)
{
return false;
}
@Override
public boolean save(DOModel model, String datasource, BaseData et)
{
return false;
}
@Override
public void saveBatch(DOModel model, String datasource, List<BaseData> list)
{
}
@Override
public Page<BaseData> fetch(DOModel model, String dataSet, String datasource, SearchContextBase context)
{
return null;
}
@Override
public List<BaseData> list(DOModel model, String dataSet, String datasource, SearchContextBase context)
{
return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!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="insert" parameterType="cn.ibizlab.core.data.dto.BaseData" >
INSERT INTO ${schema.name}
(
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
${key}
</foreach>
)
VALUES
(
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
#data[${value}]
</foreach>
)
</insert>
<update id="update" parameterType="cn.ibizlab.core.data.dto.BaseData" >
update ${schema.name}
set
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
<if test="data['_'+value+'dirtyflag']==true">${key}= #data[${value}]</if>
</foreach>
where
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #data[${value}]
</foreach>
</update>
<update id="remove" parameterType="cn.ibizlab.core.data.dto.BaseData" >
<if test="schema.logicValidColumn!=null">
update ${schema.name}
set
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
${schema.logicValidColumn.name}= 0
</foreach>
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>
</if>
</update>
</mapper>
package cn.ibizlab.api.rest;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.RequestData;
import cn.ibizlab.core.data.dto.ResponseData;
import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.util.filter.SearchContextBase;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@Api(tags = {"数据" })
@RestController("api-data")
@RequestMapping("")
public class DataResource
{
@Autowired
public IDataService dataService;
@ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}/{method}")
public ResponseEntity<BaseData> call(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@PathVariable(name = "method",required = true) String method,@RequestParam(name = "datasource",required = false) String datasource,@RequestBody BaseData baseData) {
ResponseData<BaseData> responseData=dataService.call(system,entity,method,datasource,new RequestData().setBody(baseData));
return ResponseEntity.status(HttpStatus.OK).body(responseData.getBody());
}
@ApiOperation(value = "新建数据", tags = {"数据" }, notes = "新建数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}")
public ResponseEntity<BaseData> create(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @Validated @RequestBody BaseData baseData) {
dataService.create(system,entity,datasource,baseData);
return ResponseEntity.status(HttpStatus.OK).body(baseData);
}
@ApiOperation(value = "批量新建数据", tags = {"数据" }, notes = "批量新建数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}/batch")
public ResponseEntity<Boolean> createBatch(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @RequestBody List<BaseData> baseDatas) {
dataService.createBatch(system,entity,datasource,baseDatas);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
@ApiOperation(value = "获取数据", tags = {"数据" }, notes = "获取数据")
@RequestMapping(method = RequestMethod.GET, value = "/{system}/{entity}/{key}")
public ResponseEntity<BaseData> get(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @PathVariable(name = "key",required = true) String key) {
BaseData baseData = dataService.get(system,entity,datasource,key);
return ResponseEntity.status(HttpStatus.OK).body(baseData);
}
@ApiOperation(value = "删除数据", tags = {"数据" }, notes = "删除数据")
@RequestMapping(method = RequestMethod.DELETE, value = "/{system}/{entity}/{key}")
public ResponseEntity<Boolean> remove(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @PathVariable(name = "key",required = true) String key) {
return ResponseEntity.status(HttpStatus.OK).body(dataService.remove(system,entity,datasource,key));
}
@ApiOperation(value = "批量删除数据", tags = {"数据" }, notes = "批量删除数据")
@RequestMapping(method = RequestMethod.DELETE, value = "/{system}/{entity}/batch")
public ResponseEntity<Boolean> removeBatch(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @RequestBody List ids) {
dataService.removeBatch(system,entity,datasource,ids);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
@ApiOperation(value = "更新数据", tags = {"数据" }, notes = "更新数据")
@RequestMapping(method = RequestMethod.PUT, value = "/{system}/{entity}/{key}")
public ResponseEntity<BaseData> update(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @PathVariable(name = "key",required = true) String key, @RequestBody BaseData baseData) {
dataService.update(system,entity,datasource,baseData.setKey(key));
return ResponseEntity.status(HttpStatus.OK).body(baseData);
}
@ApiOperation(value = "批量更新数据", tags = {"数据" }, notes = "批量更新数据")
@RequestMapping(method = RequestMethod.PUT, value = "/{system}/{entity}/batch")
public ResponseEntity<Boolean> updateBatch(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @RequestBody List<BaseData> baseDatas) {
dataService.updateBatch(system,entity,datasource,baseDatas);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
@ApiOperation(value = "检查数据", tags = {"数据" }, notes = "检查数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}/checkkey")
public ResponseEntity<Boolean> checkKey(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @RequestBody BaseData baseData) {
return ResponseEntity.status(HttpStatus.OK).body(dataService.checkKey(system,entity,datasource,baseData));
}
@ApiOperation(value = "获取数据草稿", tags = {"数据" }, notes = "获取数据草稿")
@RequestMapping(method = RequestMethod.GET, value = "/{system}/{entity}/getdraft")
public ResponseEntity<BaseData> getDraft(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @RequestBody(required = false) BaseData baseData) {
dataService.getDraft(system,entity,datasource,baseData);
return ResponseEntity.status(HttpStatus.OK).body(baseData);
}
@ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}/save")
public ResponseEntity<BaseData> save(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource,@RequestBody BaseData baseData) {
dataService.save(system,entity,datasource,baseData);
return ResponseEntity.status(HttpStatus.OK).body(baseData);
}
@ApiOperation(value = "批量保存数据", tags = {"数据" }, notes = "批量保存数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}/savebatch")
public ResponseEntity<Boolean> saveBatch(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource,@RequestBody List<BaseData> baseDatas) {
dataService.saveBatch(system,entity,datasource,baseDatas);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
@ApiOperation(value = "获取数据集", tags = {"数据" } ,notes = "获取数据集")
@RequestMapping(method= RequestMethod.GET , value="/{system}/{entity}/fetch{dataset}")
public ResponseEntity<List<BaseData>> fetchDefault(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@PathVariable(name = "dataset",required = true) String dataset,@RequestParam(name = "datasource",required = false) String datasource,
SearchContextBase context) {
Page<BaseData> baseDatas = dataService.fetch(system,entity,dataset,datasource,context) ;
List<BaseData> list = baseDatas.getContent();
return ResponseEntity.status(HttpStatus.OK)
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
.header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
.header("x-total", String.valueOf(baseDatas.getTotalElements()))
.body(list);
}
@ApiOperation(value = "查询数据集", tags = {"数据" } ,notes = "查询数据集")
@RequestMapping(method= RequestMethod.POST , value="/{system}/{entity}/search{dataset}")
public ResponseEntity<Page<BaseData>> searchDefault(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@PathVariable(name = "dataset",required = true) String dataset,@RequestParam(name = "datasource",required = false) String datasource,@RequestBody SearchContextBase context) {
Page<BaseData> baseDatas = dataService.fetch(system,entity,dataset,datasource,context) ;
return ResponseEntity.status(HttpStatus.OK)
.body(new PageImpl(baseDatas.getContent(), context.getPageable(), baseDatas.getTotalElements()));
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册