新增通用接口
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>hcframe-base</artifactId>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ResultVO<T> {
|
||||
* @return ResultVO
|
||||
*/
|
||||
public static <T> ResultVO<T> getSuccess() {
|
||||
return new ResultVO<>();
|
||||
return new ResultVO<T>();
|
||||
}
|
||||
/**
|
||||
* 请求成功 状态码 1
|
||||
@@ -88,7 +88,7 @@ public class ResultVO<T> {
|
||||
* @return ResultVO
|
||||
*/
|
||||
public static <T> ResultVO<T> getFailed(String msg) {
|
||||
return new ResultVO<>(FAILED, msg);
|
||||
return new ResultVO<T>(FAILED, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,24 @@ public class TableController {
|
||||
return tableService.saveWithDate(tableNameUtil.getTableName(typeName), map);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取单条数据")
|
||||
@GetMapping("/{typeName}/one/{id}")
|
||||
public ResultVO<Map<String, Object>> getOne(@PathVariable String typeName, @PathVariable String id) {
|
||||
return ResultVO.getSuccess(tableService.getOne(tableNameUtil.getTableName(typeName), id));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取多条数据")
|
||||
@GetMapping("/{typeName}/many/{ids}")
|
||||
public ResultVO<List<Map<String, Object>>> getMany(@PathVariable String typeName, @PathVariable String ids) {
|
||||
return ResultVO.getSuccess(tableService.getMany(tableNameUtil.getTableName(typeName), ids));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取多条数据")
|
||||
@GetMapping("/{typeName}/reference/{id}")
|
||||
public ResultVO<PageInfo<Map<String, Object>>> getReference(@PathVariable String typeName, String target, String data, WebPageInfo webPageInfo,@PathVariable String id) {
|
||||
return ResultVO.getSuccess(tableService.getReference(tableNameUtil.getTableName(typeName), data, webPageInfo, target,id));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新接口")
|
||||
@PutMapping({"/{typeName}/{version}", "/{typeName}"})
|
||||
public ResultVO<Integer> update(@PathVariable String typeName, @RequestParam Map<String, Object> map, @PathVariable(required = false) Integer version) {
|
||||
|
||||
@@ -42,4 +42,10 @@ public interface TableService {
|
||||
ResultVO<Integer> logicDelete(OsSysTable tableName, String ids);
|
||||
|
||||
Condition.ConditionBuilder getQueryBuilder(JSONArray query, Condition.ConditionBuilder builder);
|
||||
|
||||
Map<String, Object> getOne(OsSysTable tableName, String id);
|
||||
|
||||
PageInfo<Map<String, Object>> getReference(OsSysTable tableName, String data, WebPageInfo webPageInfo, String target, String id);
|
||||
|
||||
List<Map<String, Object>> getMany(OsSysTable tableName, String ids);
|
||||
}
|
||||
|
||||
@@ -178,19 +178,7 @@ public class TableServiceImpl implements TableService {
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> searchSingleTables(String map, OsSysTable tableName, WebPageInfo webPageInfo) {
|
||||
DataMap dataMap = DataMap.builder().sysOsTable(tableName).build();
|
||||
Condition.ConditionBuilder builder = Condition.creatCriteria(dataMap);
|
||||
if (!StringUtils.isEmpty(map)) {
|
||||
try {
|
||||
map = URLDecoder.decode(map, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
JSONArray jsonArray = JSON.parseArray(map);
|
||||
builder = getQueryBuilder(jsonArray, builder);
|
||||
}
|
||||
builder.andEqual("DELETED", 1);
|
||||
return baseMapper.selectByCondition(builder.build(), webPageInfo);
|
||||
return baseMapper.selectByCondition(getMapList(tableName, map).build(), webPageInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -249,6 +237,42 @@ public class TableServiceImpl implements TableService {
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getOne(OsSysTable tableName, String id) {
|
||||
Condition condition = Condition.creatCriteria().andEqual("DELETED", 1).andEqual(tableName.getTablePk(), id).build();
|
||||
return baseMapper.selectOneByCondition(tableName.getTableName(), condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> getReference(OsSysTable tableName, String data, WebPageInfo webPageInfo, String target, String id) {
|
||||
Condition.ConditionBuilder builder = getMapList(tableName, data);
|
||||
builder.andEqual(target, id);
|
||||
return baseMapper.selectByCondition(builder.build(), webPageInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getMany(OsSysTable tableName, String ids) {
|
||||
DataMap dataMap = DataMap.builder().sysOsTable(tableName).ids(ids).build();
|
||||
Condition condition = Condition.creatCriteria(dataMap).andIn(dataMap.getPkName(), dataMap.getIdList()).build();
|
||||
return baseMapper.selectByCondition(condition);
|
||||
}
|
||||
|
||||
private Condition.ConditionBuilder getMapList(OsSysTable tableName, String data) {
|
||||
DataMap dataMap = DataMap.builder().sysOsTable(tableName).build();
|
||||
Condition.ConditionBuilder builder = Condition.creatCriteria(dataMap);
|
||||
if (!StringUtils.isEmpty(data)) {
|
||||
try {
|
||||
data = URLDecoder.decode(data, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
JSONArray jsonArray = JSON.parseArray(data);
|
||||
builder = getQueryBuilder(jsonArray, builder);
|
||||
}
|
||||
builder.andEqual("DELETED", 1);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(SelectCondition.builder().tableName("table").build().getSql());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user