package com.ebts.generator.controller;

import com.ebts.common.core.entity.Result;
import com.ebts.generator.entity.RelColumn;
import com.ebts.generator.entity.RelTable;
import com.ebts.generator.service.RelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @Author 18209
 * @Date 2021/2/24 16:22
 * @Version 1.0
 */
@RestController
@RequestMapping("/rel")
public class RelController {
    @Resource
    private RelService relService;

    /**
     * 获取表的基础信息
     *
     * @return
     */
    @PreAuthorize("@ebts.hasAnyPermi('rel:tableinfo')")
    @GetMapping("/tableinfo")
    public Result<List<Map<String, Object>>> tableInfos() {
        return relService.tableInfos();
    }

    /**
     * 获取表的字段信息
     *
     * @param tableName
     * @param relId
     * @return
     */
    @PreAuthorize("@ebts.hasAnyPermi('rel:tableinfo')")
    @GetMapping("/{tableName}/{relId}")
    public Result<List<RelColumn>> relColumns(@PathVariable("tableName") String tableName, @PathVariable("relId") Long relId) {
        return relService.relColumns(tableName, relId);
    }

    @PreAuthorize("@ebts.hasAnyPermi('rel:colums')")
    @GetMapping("/{tableName}")
    public Result<List<Map<String, Object>>> tableColumns(@PathVariable("tableName") String tableName) {
        return relService.tableColumns(tableName);
    }

    @PreAuthorize("@ebts.hasAnyPermi('rel:colums')")
    @GetMapping("/colums/{tableId}")
    public Result<List<RelTable>> relTableByTableId(@PathVariable("tableId") Long tableId) {
        return relService.relTableByTableId(tableId);
    }


}
