package com.zkqy.web.controller.system;



import com.zkqy.common.config.datasource.utils.AjaxResult;
import com.zkqy.system.entity.DataSource;
import com.zkqy.system.entity.TableInfo;
import com.zkqy.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 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);
    }
}
