|
@@ -0,0 +1,193 @@
|
|
|
+package org.jeecg.modules.datasourceConfig.controller;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
+import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.modules.datasourceConfig.entity.DatasourceConfig;
|
|
|
+import org.jeecg.modules.datasourceConfig.entity.GetDataParam;
|
|
|
+import org.jeecg.modules.datasourceConfig.service.DatasourceConfigService;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * (DatasourceConfig)数据源配置
|
|
|
+ *
|
|
|
+ * @author makejava
|
|
|
+ * @since 2024-10-21 09:46:48
|
|
|
+ */
|
|
|
+@Api(tags="数据源配置")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/datasourceConfig")
|
|
|
+@Slf4j
|
|
|
+public class DatasourceConfigController extends JeecgController<DatasourceConfig, DatasourceConfigService> {
|
|
|
+ /**
|
|
|
+ * 服务对象
|
|
|
+ */
|
|
|
+ @Resource
|
|
|
+ private DatasourceConfigService datasourceConfigService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询所有数据
|
|
|
+ *
|
|
|
+ * @param datasourceConfig 查询实体
|
|
|
+ * @return 所有数据
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "数据源配置表-分页列表查询")
|
|
|
+ @ApiOperation(value="数据源配置-分页列表查询", notes="数据源配置-分页列表查询")
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<IPage<DatasourceConfig>> selectAll(DatasourceConfig datasourceConfig,
|
|
|
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ QueryWrapper<DatasourceConfig> queryWrapper = QueryGenerator.initQueryWrapper(datasourceConfig, req.getParameterMap());
|
|
|
+ Page<DatasourceConfig> page = new Page<DatasourceConfig>(pageNo, pageSize);
|
|
|
+ IPage<DatasourceConfig> pageList = datasourceConfigService.page(page, queryWrapper);
|
|
|
+ return Result.OK(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ *
|
|
|
+ * @param datasourceConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "数据源配置表-添加")
|
|
|
+ @ApiOperation(value="数据源配置表-添加", notes="数据源配置表-添加")
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ public Result<String> add(@RequestBody DatasourceConfig datasourceConfig) {
|
|
|
+ datasourceConfigService.save(datasourceConfig);
|
|
|
+ return Result.OK("添加成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ *
|
|
|
+ * @param datasourceConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "数据源配置表-编辑")
|
|
|
+ @ApiOperation(value="数据源配置表-编辑", notes="数据源配置表-编辑")
|
|
|
+ @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
+ public Result<String> edit(@RequestBody DatasourceConfig datasourceConfig) {
|
|
|
+ datasourceConfigService.updateById(datasourceConfig);
|
|
|
+ return Result.OK("编辑成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "数据源配置表-通过id删除")
|
|
|
+ @ApiOperation(value="数据源配置表-通过id删除", notes="数据源配置表-通过id删除")
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
+ datasourceConfigService.removeById(id);
|
|
|
+ return Result.OK("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "数据源配置表-批量删除")
|
|
|
+ @ApiOperation(value="数据源配置表-批量删除", notes="数据源配置表-批量删除")
|
|
|
+ @DeleteMapping(value = "/deleteBatch")
|
|
|
+ public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
+ this.datasourceConfigService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
+ return Result.OK("批量删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "数据源配置表-通过id查询")
|
|
|
+ @ApiOperation(value="数据源配置表-通过id查询", notes="数据源配置表-通过id查询")
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<DatasourceConfig> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
+ DatasourceConfig datasourceConfig = datasourceConfigService.getById(id);
|
|
|
+ if(datasourceConfig==null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ return Result.OK(datasourceConfig);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param datasourceConfig
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/exportXls")
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request, DatasourceConfig datasourceConfig) {
|
|
|
+ return super.exportXls(request, datasourceConfig, DatasourceConfig.class, "数据源配置表");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ return super.importExcel(request, response, DatasourceConfig.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 连接测试
|
|
|
+ *
|
|
|
+ * @param datasourceConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "数据源配置表-通过id查询")
|
|
|
+ @ApiOperation(value="数据源配置表-连接测试", notes="数据源配置表-连接测试")
|
|
|
+ @PostMapping(value = "/testConn")
|
|
|
+ public Result<String> testConn(@RequestBody DatasourceConfig datasourceConfig) {
|
|
|
+ Boolean testConn = datasourceConfigService.testConn(datasourceConfig);
|
|
|
+ if(testConn){
|
|
|
+ return Result.OK("连接成功");
|
|
|
+ }else {
|
|
|
+ return Result.error("连接失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过数据源获取数据
|
|
|
+ *
|
|
|
+ * @param getDataParam
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="数据源配置表-通过数据源获取数据", notes="数据源配置表-通过数据源获取数据")
|
|
|
+ @GetMapping(value = "/getDataByDatasourceConfig")
|
|
|
+ public Result<List<Map>> getDataByDatasourceConfig(GetDataParam getDataParam){
|
|
|
+ return Result.OK(datasourceConfigService.getDataByDatasourceConfig(getDataParam));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|