新增通用接口

This commit is contained in:
lhc
2021-09-16 15:14:01 +08:00
parent 5af5f0b163
commit 2db346f74b
5 changed files with 83 additions and 35 deletions

View File

@@ -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>

View File

@@ -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);
}
/**

View File

@@ -42,20 +42,38 @@ public class TableController {
@ApiOperation(value = "保存接口(带保存日期)")
@PostMapping("/{typeName}/date")
public ResultVO<Map<String,Object>> saveWithDate(@PathVariable String typeName, @RequestParam Map<String, Object> map) {
public ResultVO<Map<String, Object>> saveWithDate(@PathVariable String typeName, @RequestParam Map<String, Object> map) {
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) {
return tableService.update(tableNameUtil.getTableName(typeName), map,version);
@PutMapping({"/{typeName}/{version}", "/{typeName}"})
public ResultVO<Integer> update(@PathVariable String typeName, @RequestParam Map<String, Object> map, @PathVariable(required = false) Integer version) {
return tableService.update(tableNameUtil.getTableName(typeName), map, version);
}
@ApiOperation(value = "更新接口(带更改日期)")
@PutMapping({"/{typeName}/{version}/date","/{typeName}/date"})
public ResultVO<Integer> updateWithDate(@PathVariable String typeName, @RequestParam Map<String, Object> map,@PathVariable(required = false) Integer version) {
return tableService.updateWithDate(tableNameUtil.getTableName(typeName), map,version);
@PutMapping({"/{typeName}/{version}/date", "/{typeName}/date"})
public ResultVO<Integer> updateWithDate(@PathVariable String typeName, @RequestParam Map<String, Object> map, @PathVariable(required = false) Integer version) {
return tableService.updateWithDate(tableNameUtil.getTableName(typeName), map, version);
}
@ApiOperation(value = "删除接口(可批量)")
@@ -69,7 +87,7 @@ public class TableController {
@ApiOperation(value = "逻辑删除(可批量)")
@DeleteMapping("/{typeName}/logic")
@ApiImplicitParam(name = "ids", value = "id主键的数组的toString", required = true)
public ResultVO<Integer> logicDelete(@PathVariable String typeName,String ids) {
public ResultVO<Integer> logicDelete(@PathVariable String typeName, String ids) {
return tableService.logicDelete(tableNameUtil.getTableName(typeName), ids);
}
@@ -79,7 +97,7 @@ public class TableController {
@ApiImplicitParam(name = "typeName", value = " 类型", type = "path", required = true),
@ApiImplicitParam(name = "data", value = " JSON.stringify()后的数据,主要为查询条件"),
})
public ResultVO<PageInfo<Map<String,Object>>> searchTables(@PathVariable String typeName, String data, WebPageInfo webPageInfo) {
public ResultVO<PageInfo<Map<String, Object>>> searchTables(@PathVariable String typeName, String data, WebPageInfo webPageInfo) {
return ResultVO.getSuccess(tableService.searchSingleTables(data, tableNameUtil.getTableName(typeName), webPageInfo));
}
@@ -89,13 +107,13 @@ public class TableController {
@ApiImplicitParam(name = "typeName", value = " 类型", type = "path", required = true),
@ApiImplicitParam(name = "data", value = " JSON.stringify()后的数据,主要为查询条件"),
})
public ResultVO<PageInfo<Map<String,Object>>> searchJoinTables(@PathVariable String typeName, String data, WebPageInfo webPageInfo) {
return ResultVO.getSuccess(tableService.searchJoinTables(data, webPageInfo,tableNameUtil.getTableName(typeName)));
public ResultVO<PageInfo<Map<String, Object>>> searchJoinTables(@PathVariable String typeName, String data, WebPageInfo webPageInfo) {
return ResultVO.getSuccess(tableService.searchJoinTables(data, webPageInfo, tableNameUtil.getTableName(typeName)));
}
@ApiOperation(value = "获取单表接口(不带分页)")
@GetMapping("/getListNoPage/{typeName}")
public ResultVO<List<Map<String,Object>>> getListNoPage(@PathVariable String typeName, @RequestParam Map<String, Object> map) {
public ResultVO<List<Map<String, Object>>> getListNoPage(@PathVariable String typeName, @RequestParam Map<String, Object> map) {
return tableService.getListNoPage(tableNameUtil.getTableName(typeName), map);
}
@@ -131,7 +149,7 @@ public class TableController {
@ApiOperation(value = "获取基表信息")
@GetMapping("/getBaseTableInfo")
public ResultVO<Map<String,Object>> getBaseTableInfo(String tableNames) {
public ResultVO<Map<String, Object>> getBaseTableInfo(String tableNames) {
return tableService.getBaseTableInfo(tableNames);
}

View File

@@ -14,7 +14,7 @@ public interface TableService {
int save(OsSysTable osSysTable, Map<String, Object> map);
ResultVO<Map<String,Object>> saveWithDate(OsSysTable osSysTable, Map<String, Object> map);
ResultVO<Map<String, Object>> saveWithDate(OsSysTable osSysTable, Map<String, Object> map);
ResultVO<Integer> update(OsSysTable osSysTable, Map<String, Object> map, Integer version);
@@ -22,7 +22,7 @@ public interface TableService {
ResultVO<Integer> delete(OsSysTable tableName, String ids);
ResultVO<List<Map<String,Object>>> getListNoPage(OsSysTable tableName, Map<String, Object> map);
ResultVO<List<Map<String, Object>>> getListNoPage(OsSysTable tableName, Map<String, Object> map);
ResultVO<Integer> updateBatch(OsSysTable osSysTable, Map<String, Object> map);
@@ -32,14 +32,20 @@ public interface TableService {
ResultVO<Integer> saveBatchWithDate(OsSysTable osSysTable, String data);
ResultVO<Map<String,Object>> getBaseTableInfo(String tableNames);
ResultVO<Map<String, Object>> getBaseTableInfo(String tableNames);
PageInfo<Map<String,Object>> searchSingleTables(String map, OsSysTable tableName, WebPageInfo webPageInfo);
PageInfo<Map<String, Object>> searchSingleTables(String map, OsSysTable tableName, WebPageInfo webPageInfo);
PageInfo<Map<String,Object>> searchJoinTables(String data, WebPageInfo webPageInfo, OsSysTable tableName);
PageInfo<Map<String, Object>> searchJoinTables(String data, WebPageInfo webPageInfo, OsSysTable tableName);
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);
}

View File

@@ -111,7 +111,7 @@ public class TableServiceImpl implements TableService {
@Override
public ResultVO<Integer> delete(OsSysTable osSysTable, String ids) {
JudgeException.isNull(ids,"ids 不能为空");
JudgeException.isNull(ids, "ids 不能为空");
int i = baseMapper.deleteInPk(DataMap.builder().sysOsTable(osSysTable).ids(ids).build());
SqlException.operation(i, "删除失败");
return ResultVO.getSuccess(i);
@@ -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());
}