提交 8a90de77 authored 作者: HASEE's avatar HASEE

model layer 优化(2) 填补swagger文档

上级 ba353842
package com.tykj.workflowcore.model_layer.controller; package com.tykj.workflowcore.model_layer.controller;
import com.tykj.workflowcore.base.result.ResultUtil;
import com.tykj.workflowcore.model_layer.model.ColumnInfo; import com.tykj.workflowcore.model_layer.model.ColumnInfo;
import com.tykj.workflowcore.model_layer.model.TableInfo; import com.tykj.workflowcore.model_layer.model.TableInfo;
import com.tykj.workflowcore.model_layer.model.TableVO; import com.tykj.workflowcore.model_layer.model.TableVO;
import com.tykj.workflowcore.model_layer.service.ModelService; import com.tykj.workflowcore.model_layer.service.ModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -23,21 +27,22 @@ import java.util.Map; ...@@ -23,21 +27,22 @@ import java.util.Map;
*/ */
@RestController @RestController
@RequestMapping("/model") @RequestMapping("/model")
@Api("数据模型层接口")
public class ModelController { public class ModelController {
@Autowired @Autowired
private ModelService modelService; private ModelService modelService;
@Autowired
private ClassLoader classLoader; /**
/** * @param
* @Author WWW * @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo>
* @Description 得到所有数据库信息 * @Author WWW
* @Date 16:19 2021/3/4 * @Description 得到所有数据库信息
* @param * @Date 16:19 2021/3/4
* @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo> **/
**/ @ApiOperation("得到所有数据表信息")
@RequestMapping("/getAllEntity") @RequestMapping("/getAllEntity")
public List<TableInfo> getAllEntity() { public ResponseEntity getAllEntity() {
List<TableInfo> tableInfos = null; List<TableInfo> tableInfos = null;
try { try {
...@@ -46,62 +51,63 @@ public class ModelController { ...@@ -46,62 +51,63 @@ public class ModelController {
throwables.printStackTrace(); throwables.printStackTrace();
} }
return tableInfos; return ResultUtil.success(tableInfos);
} }
/**
* @Author WWW /**
* @Description 根据表名得到所有字段名 * @param tableName
* @Date 16:20 2021/3/4 * @return java.util.List<com.tykj.workflowcore.model_layer.model.ColumnInfo>
* @param tableName * @Author WWW
* @return java.util.List<com.tykj.workflowcore.model_layer.model.ColumnInfo> * @Description 根据表名得到所有字段名
**/ * @Date 16:20 2021/3/4
**/
@ApiOperation("根据表名获得表所有字段")
@GetMapping("/getAllField") @GetMapping("/getAllField")
public List<ColumnInfo> getFields(String tableName) { public ResponseEntity getFields(String tableName) {
if (tableName!=null&&tableName!=""){ if (tableName != null && tableName != "") {
return modelService.showModelFields(tableName); return ResultUtil.failed("没有表名");
} }
return null; return ResultUtil.success(modelService.showModelFields(tableName));
} }
/**
* @Author WWW /**
* @Description 新增数据模型 * @param
* @Date 16:21 2021/3/4 * @return org.springframework.http.ResponseEntity
* @param * @Author WWW
* @return org.springframework.http.ResponseEntity * @Description 新增数据模型
**/ * @Date 16:21 2021/3/4
**/
@ApiOperation("新增数据模型")
@PostMapping("/addModel") @PostMapping("/addModel")
//入参使用VO直接接收即可 //入参使用VO直接接收即可
//jsonStr -> TableVo //jsonStr -> TableVo
public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception { public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception {
List<TableInfo> tableInfos = modelService.ListAllEntities(); List<TableInfo> tableInfos = modelService.ListAllEntities();
for (TableInfo tableInfo : tableInfos) { for (TableInfo tableInfo : tableInfos) {
if (tableVO.getModelName().equals(tableInfo.getName())){ if (tableVO.getModelName().equals(tableInfo.getName())) {
return new ResponseEntity(HttpStatus.BAD_GATEWAY); return ResultUtil.failed("表已经存在!");
} }
} }
modelService.NewTable(tableVO); modelService.NewTable(tableVO);
return new ResponseEntity(HttpStatus.OK); return ResultUtil.success("新建成功");
} }
/** /**
* @Author WWW * @param map
* @Description 对应表插入数据 * @return int
* @Author WWW
* @Description 对应表插入数据
* map (表名,字段数据) * map (表名,字段数据)
* @Date 16:22 2021/3/4 * @Date 16:22 2021/3/4
* @param map **/
* @return int @ApiOperation(value = "根据表名表插入数据")
**/
@PostMapping("/insertValues") @PostMapping("/insertValues")
public int insertValues(@RequestBody Map<String,Object> map){ public ResponseEntity insertValues(@RequestBody Map<String, Object> map) {
int i = modelService.putValueByEntityName(map); modelService.putValueByEntityName(map);
return i; return ResultUtil.success("数据插入成功");
} }
@GetMapping("/getPackge")
public String testPack(){
String name = this.getClass().getPackage().getName();
return name;
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论