package com.boman.web.core.controller;

import com.boman.common.redis.RedisKey;
import com.boman.domain.dto.AjaxResult;
import com.boman.domain.GenTable;
import com.boman.web.core.service.TableServiceCmdService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author shiqian
 * @description
 * @date 2021年03月22日 09:19
 **/
@RestController
@RequestMapping("/p/cs/table/")
public class TableController {

    @Autowired
    private TableServiceCmdService cmdService;

    /**
     * 功能描述: 根据表名获取表信息、表字段和表字段对应的字典值
     *
     * @param tableName tableName
     * @return com.boman.domain.dto.AjaxResult
     */
    @ApiOperation(value = "根据表名获取表单所有信息")
    @GetMapping("/getByTableName/{tableName}")
    public AjaxResult getByTableName(@PathVariable("tableName") String tableName) {
        return AjaxResult.success(cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName));
    }

    /**
     * 功能描述: 根据表名获取表信息、表字段和表字段对应的字典值
     *                          {
     *                              "tableId": 1
     *                          }
     *
     * @param table table
     * @return com.boman.domain.dto.AjaxResult
     */
    @ApiOperation(value = "根据表名获取表单所有信息, 没有过滤")
    @PostMapping("/listAllColumnsByTableId")
    public AjaxResult listAllColumnsByTableId(@RequestBody GenTable table) {
        return cmdService.listAllColumnsByTableId(table);
    }


}
