package com.tofly.base.controller;

import com.tofly.base.service.CommonService;
import com.tofly.common.core.constant.TableFkConstans;
import com.tofly.common.core.entity.ResultRespone;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.Map;

/**
 * @author tuonbed
 * @date 2019/11/11  16:12
 */
@RequestMapping("/common")
@RestController
@Api(tags="公共处理")
public class CommonController {

    @Autowired
    private CommonService commonService;

    @GetMapping("/isExists" )
    @ApiOperation(value = "判断字段是否存在")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "table", value = "表名（例如user）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "columnValue", value = "列值（例如admin）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "parentId", value = "父级ID，菜单判断时使用", required = false, dataType = "String"),
            @ApiImplicitParam(name = "sysId", value = "子系统ID，菜单判断时使用", required = false, dataType = "String")
    })
    public ResultRespone<Boolean> isExists(@RequestParam Map map){
        Map pmap= TableFkConstans.tables.get(map.get("table"));
//        pmap.put("columnValue",map.get("columnValue"));
//        pmap.put("parentId",map.get("parentId"));
//        pmap.put("sysId",map.get("sysId"));
        pmap.putAll(map);
        return ResultRespone.success(commonService.getExistsNum(pmap));
    }
//
//    @GetMapping("/isExists/{path}" )
//    @ApiOperation(value = "判断字段是否存在")
//    public ResultRespone<Boolean> isExists(@PathVariable String path, String value){
//
//    }
}
