|
|
|
|
package com.ipsos.datasource.controller;
|
|
|
|
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
|
|
|
|
import com.ipsos.base.domain.Datasource;
|
|
|
|
|
import com.ipsos.datasource.dto.TableFiled;
|
|
|
|
|
import com.ipsos.dto.DatasourceDTO;
|
|
|
|
|
import com.ipsos.commons.utils.AuthUtils;
|
|
|
|
|
import com.ipsos.commons.utils.PageUtils;
|
|
|
|
|
import com.ipsos.commons.utils.Pager;
|
|
|
|
|
import com.ipsos.controller.ResultHolder;
|
|
|
|
|
import com.ipsos.controller.request.DatasourceUnionRequest;
|
|
|
|
|
import com.ipsos.controller.sys.base.BaseGridRequest;
|
|
|
|
|
import com.ipsos.datasource.dto.DBTableDTO;
|
|
|
|
|
import com.ipsos.datasource.service.DatasourceService;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Api(tags = "数据源:数据源管理")
|
|
|
|
|
@ApiSupport(order = 30)
|
|
|
|
|
@RequestMapping("datasource")
|
|
|
|
|
@RestController
|
|
|
|
|
public class DatasourceController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private DatasourceService datasourceService;
|
|
|
|
|
|
|
|
|
|
@ApiOperation("新增数据源")
|
|
|
|
|
@PostMapping("/add")
|
|
|
|
|
public Datasource addDatasource(@RequestBody Datasource datasource) {
|
|
|
|
|
return datasourceService.addDatasource(datasource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("验证数据源")
|
|
|
|
|
@PostMapping("/validate")
|
|
|
|
|
public ResultHolder validate(@RequestBody Datasource datasource) throws Exception {
|
|
|
|
|
return datasourceService.validate(datasource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("验证数据源")
|
|
|
|
|
@GetMapping("/validate/{datasourceId}")
|
|
|
|
|
public ResultHolder validate(@PathVariable String datasourceId) {
|
|
|
|
|
return datasourceService.validate(datasourceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查询当前用户数据源")
|
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
public List<DatasourceDTO> getDatasourceList() throws Exception {
|
|
|
|
|
DatasourceUnionRequest request = new DatasourceUnionRequest();
|
|
|
|
|
request.setUserId(String.valueOf(AuthUtils.getUser().getUserId()));
|
|
|
|
|
return datasourceService.getDatasourceList(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiIgnore
|
|
|
|
|
@PostMapping("/list/{goPage}/{pageSize}")
|
|
|
|
|
public Pager<List<DatasourceDTO>> getDatasourceList(@RequestBody BaseGridRequest request, @PathVariable int goPage, @PathVariable int pageSize) throws Exception {
|
|
|
|
|
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
|
|
|
|
// return PageUtils.setPageInfo(page, datasourceService.getDatasourceList(request));
|
|
|
|
|
return PageUtils.setPageInfo(page, datasourceService.gridQuery(request));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("删除数据源")
|
|
|
|
|
@PostMapping("/delete/{datasourceID}")
|
|
|
|
|
public void deleteDatasource(@PathVariable(value = "datasourceID") String datasourceID) throws Exception {
|
|
|
|
|
datasourceService.deleteDatasource(datasourceID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("更新数据源")
|
|
|
|
|
@PostMapping("/update")
|
|
|
|
|
public void updateDatasource(@RequestBody Datasource Datasource) {
|
|
|
|
|
datasourceService.updateDatasource(Datasource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查询数据源下属所有表")
|
|
|
|
|
@PostMapping("/getTables")
|
|
|
|
|
public List<DBTableDTO> getTables(@RequestBody Datasource datasource) throws Exception {
|
|
|
|
|
return datasourceService.getTables(datasource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查询表字段")
|
|
|
|
|
@PostMapping("/getFields/{tableName}")
|
|
|
|
|
public List<TableFiled> getFields(@RequestBody Datasource datasource, @PathVariable String tableName) throws Exception {
|
|
|
|
|
return datasourceService.getFields(datasource, tableName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查询表字段")
|
|
|
|
|
@PostMapping("/getData/{tableName}/{fetchSize}")
|
|
|
|
|
public Map<String, List> getData(@RequestBody Datasource datasource, @PathVariable String tableName, @PathVariable Integer fetchSize) throws Exception {
|
|
|
|
|
return datasourceService.getDataByDatasource(datasource, tableName, fetchSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiIgnore
|
|
|
|
|
@PostMapping("/getSchema")
|
|
|
|
|
public List<String> getSchema(@RequestBody Datasource datasource) throws Exception {
|
|
|
|
|
return datasourceService.getSchema(datasource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|