package com.tofly.common.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.service.CommonInterfaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * @author tuonbed
 * @date 2020/4/20  10:51
 */
@RestController
@RequestMapping("/common")
@Api(tags="公共接口")
@AllArgsConstructor
@Slf4j
public class CommonInterfaceController {
    private final CommonInterfaceService commonInterfaceService;

    @GetMapping("/isExists" )
    @ApiOperation(value = "判断字段是否存在")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableName", value = "表名（例如user）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "tableColumn", value = "列名（例如name）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "columnValue", value = "列值（例如admin）", required = true, dataType = "String")
    })
    public ResultRespone<Boolean> isExists(@RequestParam @ApiIgnore Map map){
        return ResultRespone.success(commonInterfaceService.getExistsNum(map));
    }

    @GetMapping("/getDBTable")
    @ApiOperation(value = "获取数据库表名及描述")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "filter", value = "表的描述信息(可选参数,模糊查询)", required = false, dataType = "String")
    })
    public ResultRespone getDBTable(@RequestParam(required = false) String filter) {
        return ResultRespone.success(commonInterfaceService.getDBTable(filter));
    }
}
