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

url 兼容map

上级 578ff47f
......@@ -27,6 +27,20 @@ public class FilterData<T> extends BaseData
return this;
}
public FilterData setAll(Map map)
{
if(map!=null)
this.putAll(map);
else if(this.size()==0)
return null;
return this;
}
public boolean needPage()
{
return this.keySet().contains("page")||this.keySet().contains("size");
}
public String getDataSource()
{
return this.getStringValue("datasource");
......
......@@ -9,6 +9,7 @@ import org.springframework.util.ObjectUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class RequestData<T> extends BaseData
{
......@@ -18,7 +19,14 @@ public class RequestData<T> extends BaseData
return this;
}
public RequestData setAll(Map map)
{
if(map!=null)
this.putAll(map);
else if(this.size()==0)
return null;
return this;
}
public RequestData setKey(Object key)
{
......
......@@ -19,6 +19,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@Slf4j
@Api(tags = {"数据" })
......@@ -30,25 +31,35 @@ public class DataResource
public IDataService dataService;
@ApiOperation(value = "callMethod数据", tags = {"数据" }, notes = "callMethod数据")
@RequestMapping(method = {RequestMethod.POST,RequestMethod.GET}, value = {"/ibiz-repository/{system}/{scope}/{entity}/{method}","/ibiz-repo/{system}/{entity}/{method}",
@RequestMapping(method = {RequestMethod.GET}, value = {"/ibiz-repository/{system}/{scope}/{entity}/{method}","/ibiz-repo/{system}/{entity}/{method}",
"/ibiz-repository/{system}/{scope}/{entity}/{key}/{method}","/ibiz-repo/{system}/{entity}/{key}/{method}"})
public ResponseEntity call(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "method",required = true) String method,
@PathVariable(name = "key",required = false) String key,
@RequestParam Map map) {
RequestData requestData=new RequestData().setAll(map);
ResponseData responseData=dataService.call(system,scope,entity,datasource,method,requestData.setKey(key));
return ResponseEntity.status(HttpStatus.OK).body(responseData.getBody());
}
@ApiOperation(value = "callMethod数据", tags = {"数据" }, notes = "callMethod数据")
@RequestMapping(method = {RequestMethod.POST}, value = {"/ibiz-repository/{system}/{scope}/{entity}/{method}","/ibiz-repo/{system}/{entity}/{method}",
"/ibiz-repository/{system}/{scope}/{entity}/{key}/{method}","/ibiz-repo/{system}/{entity}/{key}/{method}"})
public ResponseEntity callPost(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "method",required = true) String method,
@PathVariable(name = "key",required = false) String key,@RequestBody(required = false) RequestData requestData) {
if(requestData==null)
{
if(StringUtils.isEmpty(key))
throw new BadRequestAlertException("未找到要检查的键值信息",entity,null);
requestData=new RequestData();
}
ResponseData responseData=dataService.call(system,scope,entity,datasource,method,requestData.setKey(key));
return ResponseEntity.status(HttpStatus.OK).body(responseData.getBody());
}
@ApiOperation(value = "批量callMethod数据", tags = {"数据" }, notes = "批量callMethod数据")
@RequestMapping(method = {RequestMethod.POST,RequestMethod.GET}, value = {"/ibiz-repository/{system}/{scope}/{entity}/{method}batch","/ibiz-repo/{system}/{entity}/{method}batch"})
@RequestMapping(method = {RequestMethod.POST}, value = {"/ibiz-repository/{system}/{scope}/{entity}/{method}batch","/ibiz-repo/{system}/{entity}/{method}batch"})
public ResponseEntity callBatch(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
......@@ -94,7 +105,13 @@ public class DataResource
public ResponseEntity<BaseData> get(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "key",required = false) String key,@Validated @RequestBody BaseData baseData) {
@PathVariable(name = "key",required = false) String key,@Validated @RequestBody(required = false) BaseData baseData) {
if(baseData==null)
{
if(StringUtils.isEmpty(key))
throw new BadRequestAlertException("未找到要获取的键值信息",entity,null);
baseData=new BaseData();
}
return ResponseEntity.status(HttpStatus.OK).body(dataService.getByMap(system,scope,entity,datasource,baseData.setKey(key)));
}
......@@ -108,7 +125,7 @@ public class DataResource
if(baseData==null)
{
if(StringUtils.isEmpty(key))
throw new BadRequestAlertException("未找到要检查的键值信息",entity,null);
throw new BadRequestAlertException("未找到要删除的键值信息",entity,null);
baseData=new BaseData();
}
return ResponseEntity.status(HttpStatus.OK).body(dataService.removeByMap(system,scope,entity,datasource,baseData.setKey(key)));
......@@ -117,10 +134,16 @@ public class DataResource
@ApiOperation(value = "删除数据", tags = {"数据" }, notes = "删除数据")
@RequestMapping(method = RequestMethod.POST, value = {"/ibiz-repository/{system}/{scope}/{entity}/remove","/ibiz-repo/{system}/{entity}/remove",
"/ibiz-repository/{system}/{scope}/{entity}/{key}/remove","/ibiz-repo/{system}/{entity}/{key}/remove"})
public ResponseEntity<Boolean> remove2(@PathVariable(name = "system",required = true) String system,
public ResponseEntity<Boolean> removePost(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "key",required = false) String key,@Validated @RequestBody BaseData baseData) {
@PathVariable(name = "key",required = false) String key,@Validated @RequestBody(required = false) BaseData baseData) {
if(baseData==null)
{
if(StringUtils.isEmpty(key))
throw new BadRequestAlertException("未找到要删除的键值信息",entity,null);
baseData=new BaseData();
}
return ResponseEntity.status(HttpStatus.OK).body(dataService.removeByMap(system,scope,entity,datasource,baseData.setKey(key)));
}
......@@ -135,7 +158,7 @@ public class DataResource
@ApiOperation(value = "批量删除数据", tags = {"数据" }, notes = "批量删除数据")
@RequestMapping(method = RequestMethod.POST, value = {"/ibiz-repository/{system}/{scope}/{entity}/removebatch","/ibiz-repo/{system}/{entity}/removebatch"})
public ResponseEntity<Boolean> removeBatch2(@PathVariable(name = "system",required = true) String system,
public ResponseEntity<Boolean> removeBatchPost(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource, @RequestBody List ids) {
dataService.removeBatch(system,scope,entity,datasource,ids);
......@@ -156,7 +179,7 @@ public class DataResource
@ApiOperation(value = "更新数据", tags = {"数据" }, notes = "更新数据")
@RequestMapping(method = RequestMethod.POST, value = {"/ibiz-repository/{system}/{scope}/{entity}/update","/ibiz-repo/{system}/{entity}/update",
"/ibiz-repository/{system}/{scope}/{entity}/{key}/update","/ibiz-repo/{system}/{entity}/{key}/update"})
public ResponseEntity<BaseData> update2(@PathVariable(name = "system",required = true) String system,
public ResponseEntity<BaseData> updatePost(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "key",required = false) String key, @RequestBody BaseData baseData) {
......@@ -175,7 +198,7 @@ public class DataResource
@ApiOperation(value = "批量更新数据", tags = {"数据" }, notes = "批量更新数据")
@RequestMapping(method = RequestMethod.POST, value = {"/ibiz-repository/{system}/{scope}/{entity}/updatebatch","/ibiz-repo/{system}/{entity}/updatebatch"})
public ResponseEntity<Boolean> updateBatch2(@PathVariable(name = "system",required = true) String system,
public ResponseEntity<Boolean> updateBatchPost(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource, @RequestBody List<BaseData> baseDatas) {
dataService.updateBatch(system,scope,entity,datasource,baseDatas);
......@@ -183,9 +206,26 @@ public class DataResource
}
@ApiOperation(value = "检查数据", tags = {"数据" }, notes = "检查数据")
@RequestMapping(method = {RequestMethod.GET,RequestMethod.POST}, value = {"/ibiz-repository/{system}/{scope}/{entity}/checkkey","/ibiz-repo/{system}/{entity}/checkkey",
@RequestMapping(method = {RequestMethod.GET}, value = {"/ibiz-repository/{system}/{scope}/{entity}/checkkey","/ibiz-repo/{system}/{entity}/checkkey",
"/ibiz-repository/{system}/{scope}/{entity}/{key}/checkkey","/ibiz-repo/{system}/{entity}/{key}/checkkey"})
public ResponseEntity<Boolean> checkKey(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "key",required = false) String key,
@RequestParam Map map) {
BaseData baseData=new BaseData().setAll(map);
if(baseData.size()==0)
{
if(StringUtils.isEmpty(key))
throw new BadRequestAlertException("未找到要检查的键值信息",entity,null);
}
return ResponseEntity.status(HttpStatus.OK).body(dataService.checkKey(system,scope,entity,datasource,baseData.setKey(key)));
}
@ApiOperation(value = "检查数据", tags = {"数据" }, notes = "检查数据")
@RequestMapping(method = {RequestMethod.POST}, value = {"/ibiz-repository/{system}/{scope}/{entity}/checkkey","/ibiz-repo/{system}/{entity}/checkkey",
"/ibiz-repository/{system}/{scope}/{entity}/{key}/checkkey","/ibiz-repo/{system}/{entity}/{key}/checkkey"})
public ResponseEntity<Boolean> checkKeyPost(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "key",required = false) String key,@RequestBody(required = false) BaseData baseData) {
......@@ -200,9 +240,21 @@ public class DataResource
@ApiOperation(value = "获取数据草稿", tags = {"数据" }, notes = "获取数据草稿")
@RequestMapping(method = {RequestMethod.GET,RequestMethod.POST}, value = {"/ibiz-repository/{system}/{scope}/{entity}/getdraft","/ibiz-repo/{system}/{entity}/getdraft",
@RequestMapping(method = {RequestMethod.GET}, value = {"/ibiz-repository/{system}/{scope}/{entity}/getdraft","/ibiz-repo/{system}/{entity}/getdraft",
"/ibiz-repository/{system}/{scope}/{entity}/{key}/getdraft","/ibiz-repo/{system}/{entity}/{key}/getdraft"})
public ResponseEntity<BaseData> getDraft(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "key",required = false) String key,
@RequestParam Map map) {
BaseData baseData=new BaseData().setAll(map);
return ResponseEntity.status(HttpStatus.OK).body(dataService.getDraft(system,scope,entity,datasource,baseData.setKey(key)));
}
@ApiOperation(value = "获取数据草稿", tags = {"数据" }, notes = "获取数据草稿")
@RequestMapping(method = {RequestMethod.POST}, value = {"/ibiz-repository/{system}/{scope}/{entity}/getdraft","/ibiz-repo/{system}/{entity}/getdraft",
"/ibiz-repository/{system}/{scope}/{entity}/{key}/getdraft","/ibiz-repo/{system}/{entity}/{key}/getdraft"})
public ResponseEntity<BaseData> getDraftPost(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "key",required = false) String key, @RequestBody(required = false) BaseData baseData) {
......@@ -210,7 +262,7 @@ public class DataResource
return ResponseEntity.status(HttpStatus.OK).body(dataService.getDraft(system,scope,entity,datasource,baseData.setKey(key)));
}
@ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据")
@ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据,自动判断插入和更新")
@RequestMapping(method = RequestMethod.POST, value = {"/ibiz-repository/{system}/{scope}/{entity}/save","/ibiz-repo/{system}/{entity}/save",
"/ibiz-repository/{system}/{scope}/{entity}/{key}/save","/ibiz-repo/{system}/{entity}/{key}/save"})
public ResponseEntity<BaseData> save(@PathVariable(name = "system",required = true) String system,
......@@ -221,7 +273,7 @@ public class DataResource
return ResponseEntity.status(HttpStatus.OK).body(baseData);
}
@ApiOperation(value = "批量保存数据", tags = {"数据" }, notes = "批量保存数据")
@ApiOperation(value = "批量保存数据", tags = {"数据" }, notes = "批量保存数据,自动判断插入和更新")
@RequestMapping(method = RequestMethod.POST, value = {"/ibiz-repository/{system}/{scope}/{entity}/savebatch","/ibiz-repo/{system}/{entity}/savebatch"})
public ResponseEntity<Boolean> saveBatch(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
......@@ -230,13 +282,15 @@ public class DataResource
return ResponseEntity.status(HttpStatus.OK).body(true);
}
@ApiOperation(value = "获取数据集", tags = {"数据" } ,notes = "获取数据集")
@ApiOperation(value = "获取数据集", tags = {"数据" } ,notes = "获取数据集,GET,返回body<list>+header<page,total>")
@RequestMapping(method= RequestMethod.GET , value={"/ibiz-repository/{system}/{scope}/{entity}/fetch{dataset}","/ibiz-repo/{system}/{entity}/fetch{dataset}"})
public ResponseEntity<List<BaseData>> fetch(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,@PathVariable(name = "dataset",required = true) String dataset,
FilterData context) {
Page<BaseData> baseDatas = dataService.fetch(system,scope,entity,context.getDataSource(),dataset,context,context.getPageable()) ;
@RequestParam Map map) {
FilterData context=new FilterData().setAll(map);
if(context.needPage()) {
Page<BaseData> baseDatas = dataService.fetch(system, scope, entity, context.getDataSource(), dataset, context, context.getPageable());
List<BaseData> list = baseDatas.getContent();
return ResponseEntity.status(HttpStatus.OK)
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
......@@ -244,14 +298,24 @@ public class DataResource
.header("x-total", String.valueOf(baseDatas.getTotalElements()))
.body(list);
}
else {
List<BaseData> list = dataService.fetch(system,scope,entity,datasource,dataset,context) ;
return ResponseEntity.status(HttpStatus.OK)
.header("x-page", "0")
.header("x-per-page", String.valueOf(list.size()))
.header("x-total", String.valueOf(list.size()))
.body(list);
}
}
@ApiOperation(value = "获取数据集", tags = {"数据" } ,notes = "获取数据集")
@ApiOperation(value = "获取数据集", tags = {"数据" } ,notes = "获取数据集,POST,返回body<list>+header<page,total>")
@RequestMapping(method= RequestMethod.POST , value={"/ibiz-repository/{system}/{scope}/{entity}/fetch{dataset}","/ibiz-repo/{system}/{entity}/fetch{dataset}"})
public ResponseEntity<List<BaseData>> fetch2(@PathVariable(name = "system",required = true) String system,
public ResponseEntity<List<BaseData>> fetchPost(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,@PathVariable(name = "dataset",required = true) String dataset,
@RequestBody FilterData context) {
Page<BaseData> baseDatas = dataService.fetch(system,scope,entity,datasource,dataset,context,context.getPageable()) ;
if(context.needPage()) {
Page<BaseData> baseDatas = dataService.fetch(system, scope, entity, datasource, dataset, context, context.getPageable());
List<BaseData> list = baseDatas.getContent();
return ResponseEntity.status(HttpStatus.OK)
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
......@@ -259,8 +323,17 @@ public class DataResource
.header("x-total", String.valueOf(baseDatas.getTotalElements()))
.body(list);
}
else {
List<BaseData> list = dataService.fetch(system,scope,entity,datasource,dataset,context) ;
return ResponseEntity.status(HttpStatus.OK)
.header("x-page", "0")
.header("x-per-page", String.valueOf(list.size()))
.header("x-total", String.valueOf(list.size()))
.body(list);
}
}
@ApiOperation(value = "查询数据集", tags = {"数据" } ,notes = "查询数据集")
@ApiOperation(value = "获取数据集", tags = {"数据" } ,notes = "获取数据集,POST,返回body<page,total,list>")
@RequestMapping(method= RequestMethod.POST , value={"/ibiz-repository/{system}/{scope}/{entity}/search{dataset}","/ibiz-repo/{system}/{entity}/search{dataset}"})
public ResponseEntity<Page<BaseData>> search(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
......@@ -273,5 +346,68 @@ public class DataResource
@ApiOperation(value = "查询数据", tags = {"数据" } ,notes = "查询数据,GET,返回body<list>+header<page,total>")
@RequestMapping(method= RequestMethod.GET , value={"/ibiz-repository/{system}/{scope}/{entity}/query{dataquery}","/ibiz-repo/{system}/{entity}/query{dataquery}"})
public ResponseEntity<List<BaseData>> query(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,@PathVariable(name = "dataquery",required = true) String dataquery,
@RequestParam Map map) {
FilterData context=new FilterData().setAll(map);
if(context.needPage()) {
Page<BaseData> baseDatas = dataService.fetch(system, scope, entity, context.getDataSource(), dataquery, context, context.getPageable());
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);
}
else {
List<BaseData> list = dataService.query(system,scope,entity,datasource,dataquery,context) ;
return ResponseEntity.status(HttpStatus.OK)
.header("x-page", "0")
.header("x-per-page", String.valueOf(list.size()))
.header("x-total", String.valueOf(list.size()))
.body(list);
}
}
@ApiOperation(value = "查询数据", tags = {"数据" } ,notes = "查询数据,POST,返回body<list>+header<page,total>")
@RequestMapping(method= RequestMethod.POST , value={"/ibiz-repository/{system}/{scope}/{entity}/query{dataquery}","/ibiz-repo/{system}/{entity}/query{dataquery}"})
public ResponseEntity<List<BaseData>> queryPost(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,@PathVariable(name = "dataquery",required = true) String dataquery,
@RequestBody FilterData context) {
if(context.needPage()) {
Page<BaseData> baseDatas = dataService.query(system,scope,entity,datasource,dataquery,context,context.getPageable()) ;
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);
}
else {
List<BaseData> list = dataService.query(system,scope,entity,datasource,dataquery,context) ;
return ResponseEntity.status(HttpStatus.OK)
.header("x-page", "0")
.header("x-per-page", String.valueOf(list.size()))
.header("x-total", String.valueOf(list.size()))
.body(list);
}
}
@ApiOperation(value = "查询数据", tags = {"数据" } ,notes = "查询数据,POST,返回body<page,total,list>")
@RequestMapping(method= RequestMethod.POST , value={"/ibiz-repository/{system}/{scope}/{entity}/page{dataquery}","/ibiz-repo/{system}/{entity}/page{dataquery}"})
public ResponseEntity<Page<BaseData>> queryPage(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,@PathVariable(name = "dataquery",required = true) String dataquery,
@RequestBody FilterData context) {
Page<BaseData> baseDatas = dataService.fetch(system,scope,entity,datasource,dataquery,context,context.getPageable()) ;
return ResponseEntity.status(HttpStatus.OK)
.body(new PageImpl(baseDatas.getContent(), context.getPageable(), baseDatas.getTotalElements()));
}
}
package cn.ibizlab.core.util.config;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.FilterData;
import cn.ibizlab.core.data.filter.SearchContextBase;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -26,8 +27,10 @@ public class FilterDataResolver implements HandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return SearchContextBase.class.isAssignableFrom(parameter.getParameterType())
|| FilterData.class.isAssignableFrom(parameter.getParameterType());
Class<?> type = parameter.getParameterType();
return SearchContextBase.class==type
|| FilterData.class==type
|| BaseData.class==type;
}
@Override
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册