package com.ruoyi.web.controller.system;


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

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@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();
    }

    /**
     * 得到当前数据源的所有表
     */
    @PostMapping("/getAllTable")
    public com.ruoyi.common.config.datasource.utils.AjaxResult queryAll(@RequestBody Map<String, Object> query) {
        return dataSourceService.tableInfoList(query);
    }

    /**
     * 得到当前表中的所有字段
     */

    @PostMapping("/getInfoTable")
    public List<TableInfo> queryTableInfo(@RequestBody Map<String, Object> map) {
        return dataSourceService.tableFieldInfo(map);
    }

}
