package com.ruoyi.web.controller;


import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.DataSource;
import com.zkqy.datamodeling.service.IDataSourceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Anonymous
@RestController
@RequestMapping("/dataSource")
public class DataSourceController {

    @Resource
    private IDataSourceService dataSourceService;

    @PostMapping("/changeDataSource")
    public AjaxResult changeDataSource(@RequestBody DataSource dataSource) throws Exception {
        //切换数据源
        dataSourceService.changeDataSource(dataSource);
        return AjaxResult.success();
    }

    /**
     * 根据数据源类型得到当前数据源下所有数据库
     *
     * @param dataSource 数据源信息
     * @return
     */
    @GetMapping("/querySelectDataSource")
    public AjaxResult querySelectDataSource(DataSource dataSource) throws Exception {
        return AjaxResult.success(dataSourceService.querySelectDatasource(dataSource));
    }

}
