package com.ruoyi.generator.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.generator.domain.SysProjectTable;
import com.ruoyi.generator.service.ISysProjectTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目与表关联Controller
 *
 * @author ruoyi
 * @date {DATE}
 */
@RestController
@RequestMapping("/generator/project/table")
public class SysProjectTableController extends BaseController
{
    @Autowired
    private ISysProjectTableService sysProjectTableService;

    /**
     * 查询项目与表关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:projectTable:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysProjectTable sysProjectTable)
    {
        startPage();
        List<SysProjectTable> list = sysProjectTableService.selectSysProjectTableList(sysProjectTable);
        return getDataTable(list);
    }

    /**
     * 获取项目与表关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:projectTable:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysProjectTableService.selectSysProjectTableById(id));
    }

    /**
     * 新增项目与表关联
     */
    @PreAuthorize("@ss.hasPermi('system:projectTable:add')")
    @Log(title = "项目与表关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysProjectTable sysProjectTable)
    {
        return toAjax(sysProjectTableService.insertSysProjectTable(sysProjectTable));
    }

    /**
     * 修改项目与表关联
     */
    @PreAuthorize("@ss.hasPermi('system:projectTable:edit')")
    @Log(title = "项目与表关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysProjectTable sysProjectTable)
    {
        return toAjax(sysProjectTableService.updateSysProjectTable(sysProjectTable));
    }

    /**
     * 删除项目与表关联
     */
    @PreAuthorize("@ss.hasPermi('system:projectTable:remove')")
    @Log(title = "项目与表关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysProjectTableService.deleteSysProjectTableByIds(ids));
    }

    /**
     * 根据项目ID删除关联关系
     */
    @PreAuthorize("@ss.hasPermi('system:projectTable:removeByProjectId')")
    @Log(title = "项目与表关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/project/{projectId}")
    public AjaxResult removeByProjectId(@PathVariable Long projectId)
    {
        return toAjax(sysProjectTableService.deleteSysProjectTableByProjectId(projectId));
    }

    /**
     * 根据表ID删除关联关系
     */
    @PreAuthorize("@ss.hasPermi('system:projectTable:removeByTableId')")
    @Log(title = "项目与表关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/table/{tableId}")
    public AjaxResult removeByTableId(@PathVariable Long tableId)
    {
        return toAjax(sysProjectTableService.deleteSysProjectTableByTableId(tableId));
    }
} 