package com.fs.project.controller;

import com.fs.common.annotation.Log;
import com.fs.common.config.LoginContextManager;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.project.domain.ProjectPermission;
import com.fs.project.service.IProjectPermissionService;
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 fs
 * @date 2025-12-30
 */
@RestController
@RequestMapping("/project/permission")
public class ProjectPermissionController extends BaseController
{
    @Autowired
    private IProjectPermissionService projectPermissionService;

    /**
     * 查询项目权限列表
     */
    @PreAuthorize("@ss.hasPermi('project:permission:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectPermission projectPermission)
    {
        startPage();
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        projectPermission.setCompanyId(currentCompanyId);
         List<ProjectPermission> list = projectPermissionService.selectProjectPermissionList(projectPermission);
        return getDataTable(list);
    }

    /**
     * 导出项目权限列表
     */
    @PreAuthorize("@ss.hasPermi('project:permission:export')")
    @Log(title = "项目权限", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProjectPermission projectPermission)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        projectPermission.setCompanyId(currentCompanyId);
        List<ProjectPermission> list = projectPermissionService.selectProjectPermissionList(projectPermission);
        ExcelUtil<ProjectPermission> util = new ExcelUtil<ProjectPermission>(ProjectPermission.class);
        return util.exportExcel(list, "项目权限数据");
    }

    /**
     * 获取项目权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:permission:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectPermissionService.selectProjectPermissionById(id));
    }

    /**
     * 新增项目权限
     */
    @PreAuthorize("@ss.hasPermi('project:permission:add')")
    @Log(title = "项目权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectPermission projectPermission)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        projectPermission.setCompanyId(currentCompanyId);
        return toAjax(projectPermissionService.insertProjectPermission(projectPermission));
    }

    /**
     * 修改项目权限
     */
    @PreAuthorize("@ss.hasPermi('project:permission:edit')")
    @Log(title = "项目权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectPermission projectPermission)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        projectPermission.setCompanyId(currentCompanyId);
        return toAjax(projectPermissionService.updateProjectPermission(projectPermission));
    }

    /**
     * 删除项目权限
     */
    @PreAuthorize("@ss.hasPermi('project:permission:remove')")
    @Log(title = "项目权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectPermissionService.deleteProjectPermissionByIds(ids));
    }
}
