| | |
| | | import com.oying.domain.dto.TableInfo; |
| | | import com.oying.service.GenConfigService; |
| | | import com.oying.service.GeneratorService; |
| | | import com.oying.utils.R; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.List; |
| | |
| | | |
| | | @ApiOperation("查询数据库数据") |
| | | @GetMapping(value = "/tables") |
| | | public ResponseEntity<PageResult<TableInfo>> queryTables(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size){ |
| | | return new ResponseEntity<>(generatorService.getTables(name, new Page<>(page, size)), HttpStatus.OK); |
| | | public ResponseEntity<Object> queryTables(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) { |
| | | return new ResponseEntity<>(R.success(generatorService.getTables(name, new Page<>(page, size))), HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("查询字段数据") |
| | | @GetMapping(value = "/columns") |
| | | public ResponseEntity<PageResult<ColumnInfo>> queryColumns(@RequestParam String tableName){ |
| | | public ResponseEntity<Object> queryColumns(@RequestParam String tableName) { |
| | | List<ColumnInfo> columnInfos = generatorService.getColumns(tableName); |
| | | return new ResponseEntity<>(PageUtil.toPage(columnInfos), HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(PageUtil.toPage(columnInfos)), HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("保存字段数据") |
| | | @PutMapping |
| | | public ResponseEntity<HttpStatus> saveColumn(@RequestBody List<ColumnInfo> columnInfos){ |
| | | public ResponseEntity<Object> saveColumn(@RequestBody List<ColumnInfo> columnInfos) { |
| | | generatorService.save(columnInfos); |
| | | return new ResponseEntity<>(HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("同步字段数据") |
| | | @PostMapping(value = "sync") |
| | | public ResponseEntity<HttpStatus> syncColumn(@RequestBody List<String> tables){ |
| | | public ResponseEntity<Object> syncColumn(@RequestBody List<String> tables) { |
| | | for (String table : tables) { |
| | | generatorService.sync(generatorService.getColumns(table), generatorService.query(table)); |
| | | } |
| | | return new ResponseEntity<>(HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("生成代码") |
| | |
| | | } |
| | | switch (type){ |
| | | // 生成代码 |
| | | case 0: generatorService.generator(genConfigService.find(tableName), generatorService.getColumns(tableName)); |
| | | case 0: |
| | | generatorService.generator(genConfigService.find(tableName), generatorService.getColumns(tableName)); |
| | | break; |
| | | // 预览 |
| | | case 1: return generatorService.preview(genConfigService.find(tableName), generatorService.getColumns(tableName)); |
| | | case 1: |
| | | return generatorService.preview(genConfigService.find(tableName), generatorService.getColumns(tableName)); |
| | | // 打包 |
| | | case 2: generatorService.download(genConfigService.find(tableName), generatorService.getColumns(tableName), request, response); |
| | | case 2: |
| | | generatorService.download(genConfigService.find(tableName), generatorService.getColumns(tableName), request, response); |
| | | break; |
| | | default: throw new BadRequestException("没有这个选项"); |
| | | default: |
| | | throw new BadRequestException("没有这个选项"); |
| | | } |
| | | return new ResponseEntity<>(HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | } |