diff --git a/hcframe-parent/hcframe-base/pom.xml b/hcframe-parent/hcframe-base/pom.xml index 56da938..4e709a9 100644 --- a/hcframe-parent/hcframe-base/pom.xml +++ b/hcframe-parent/hcframe-base/pom.xml @@ -10,7 +10,7 @@ 4.0.0 hcframe-base - 1.2.1-SNAPSHOT + 1.2.2-SNAPSHOT 8 diff --git a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/ResultVO.java b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/ResultVO.java index c28a110..ff67400 100644 --- a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/ResultVO.java +++ b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/ResultVO.java @@ -66,7 +66,7 @@ public class ResultVO { * @return ResultVO */ public static ResultVO getSuccess() { - return new ResultVO<>(); + return new ResultVO(); } /** * 请求成功 状态码 1 @@ -88,7 +88,7 @@ public class ResultVO { * @return ResultVO */ public static ResultVO getFailed(String msg) { - return new ResultVO<>(FAILED, msg); + return new ResultVO(FAILED, msg); } /** diff --git a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/controller/TableController.java b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/controller/TableController.java index 24ceb70..a64f57c 100644 --- a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/controller/TableController.java +++ b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/controller/TableController.java @@ -42,20 +42,38 @@ public class TableController { @ApiOperation(value = "保存接口(带保存日期)") @PostMapping("/{typeName}/date") - public ResultVO> saveWithDate(@PathVariable String typeName, @RequestParam Map map) { + public ResultVO> saveWithDate(@PathVariable String typeName, @RequestParam Map map) { return tableService.saveWithDate(tableNameUtil.getTableName(typeName), map); } + @ApiOperation(value = "获取单条数据") + @GetMapping("/{typeName}/one/{id}") + public ResultVO> getOne(@PathVariable String typeName, @PathVariable String id) { + return ResultVO.getSuccess(tableService.getOne(tableNameUtil.getTableName(typeName), id)); + } + + @ApiOperation(value = "获取多条数据") + @GetMapping("/{typeName}/many/{ids}") + public ResultVO>> getMany(@PathVariable String typeName, @PathVariable String ids) { + return ResultVO.getSuccess(tableService.getMany(tableNameUtil.getTableName(typeName), ids)); + } + + @ApiOperation(value = "获取多条数据") + @GetMapping("/{typeName}/reference/{id}") + public ResultVO>> 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 update(@PathVariable String typeName, @RequestParam Map map,@PathVariable(required = false) Integer version) { - return tableService.update(tableNameUtil.getTableName(typeName), map,version); + @PutMapping({"/{typeName}/{version}", "/{typeName}"}) + public ResultVO update(@PathVariable String typeName, @RequestParam Map map, @PathVariable(required = false) Integer version) { + return tableService.update(tableNameUtil.getTableName(typeName), map, version); } @ApiOperation(value = "更新接口(带更改日期)") - @PutMapping({"/{typeName}/{version}/date","/{typeName}/date"}) - public ResultVO updateWithDate(@PathVariable String typeName, @RequestParam Map map,@PathVariable(required = false) Integer version) { - return tableService.updateWithDate(tableNameUtil.getTableName(typeName), map,version); + @PutMapping({"/{typeName}/{version}/date", "/{typeName}/date"}) + public ResultVO updateWithDate(@PathVariable String typeName, @RequestParam Map 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 logicDelete(@PathVariable String typeName,String ids) { + public ResultVO 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>> searchTables(@PathVariable String typeName, String data, WebPageInfo webPageInfo) { + public ResultVO>> 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>> searchJoinTables(@PathVariable String typeName, String data, WebPageInfo webPageInfo) { - return ResultVO.getSuccess(tableService.searchJoinTables(data, webPageInfo,tableNameUtil.getTableName(typeName))); + public ResultVO>> 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>> getListNoPage(@PathVariable String typeName, @RequestParam Map map) { + public ResultVO>> getListNoPage(@PathVariable String typeName, @RequestParam Map map) { return tableService.getListNoPage(tableNameUtil.getTableName(typeName), map); } @@ -131,7 +149,7 @@ public class TableController { @ApiOperation(value = "获取基表信息") @GetMapping("/getBaseTableInfo") - public ResultVO> getBaseTableInfo(String tableNames) { + public ResultVO> getBaseTableInfo(String tableNames) { return tableService.getBaseTableInfo(tableNames); } diff --git a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/service/TableService.java b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/service/TableService.java index 30302b9..8ce7708 100644 --- a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/service/TableService.java +++ b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/service/TableService.java @@ -14,7 +14,7 @@ public interface TableService { int save(OsSysTable osSysTable, Map map); - ResultVO> saveWithDate(OsSysTable osSysTable, Map map); + ResultVO> saveWithDate(OsSysTable osSysTable, Map map); ResultVO update(OsSysTable osSysTable, Map map, Integer version); @@ -22,7 +22,7 @@ public interface TableService { ResultVO delete(OsSysTable tableName, String ids); - ResultVO>> getListNoPage(OsSysTable tableName, Map map); + ResultVO>> getListNoPage(OsSysTable tableName, Map map); ResultVO updateBatch(OsSysTable osSysTable, Map map); @@ -32,14 +32,20 @@ public interface TableService { ResultVO saveBatchWithDate(OsSysTable osSysTable, String data); - ResultVO> getBaseTableInfo(String tableNames); + ResultVO> getBaseTableInfo(String tableNames); - PageInfo> searchSingleTables(String map, OsSysTable tableName, WebPageInfo webPageInfo); + PageInfo> searchSingleTables(String map, OsSysTable tableName, WebPageInfo webPageInfo); - PageInfo> searchJoinTables(String data, WebPageInfo webPageInfo, OsSysTable tableName); + PageInfo> searchJoinTables(String data, WebPageInfo webPageInfo, OsSysTable tableName); ResultVO logicDelete(OsSysTable tableName, String ids); Condition.ConditionBuilder getQueryBuilder(JSONArray query, Condition.ConditionBuilder builder); + + Map getOne(OsSysTable tableName, String id); + + PageInfo> getReference(OsSysTable tableName, String data, WebPageInfo webPageInfo, String target, String id); + + List> getMany(OsSysTable tableName, String ids); } diff --git a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/service/impl/TableServiceImpl.java b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/service/impl/TableServiceImpl.java index ae6e9ef..69a6941 100644 --- a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/service/impl/TableServiceImpl.java +++ b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/module/data/service/impl/TableServiceImpl.java @@ -111,7 +111,7 @@ public class TableServiceImpl implements TableService { @Override public ResultVO 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> 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 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> 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> 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()); }