package com.fs.app.controller;

import java.util.List;

import com.fs.app.vo.FsAppRoleVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.app.domain.FsAppRole;
import com.fs.app.service.IFsAppRoleService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * APP角色Controller
 * 
 * @author fs
 * @date 2026-02-26
 */
@RestController
@RequestMapping("/app/role")
public class FsAppRoleController extends BaseController
{
    @Autowired
    private IFsAppRoleService fsAppRoleService;

    /**
     * 查询APP角色列表
     */
    @PreAuthorize("@ss.hasPermi('app:role:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsAppRole fsAppRole)
    {
        startPage();
        List<FsAppRole> list = fsAppRoleService.selectFsAppRoleList(fsAppRole);
        return getDataTable(list);
    }

    /**
     * 导出APP角色列表
     */
    @PreAuthorize("@ss.hasPermi('app:role:export')")
    @Log(title = "APP角色", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsAppRole fsAppRole)
    {
        List<FsAppRole> list = fsAppRoleService.selectFsAppRoleList(fsAppRole);
        ExcelUtil<FsAppRole> util = new ExcelUtil<FsAppRole>(FsAppRole.class);
        return util.exportExcel(list, "APP角色数据");
    }

    /**
     * 获取APP角色详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:role:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsAppRoleService.selectFsAppRoleById(id));
    }

    /**
     * 新增APP角色
     */
    @PreAuthorize("@ss.hasPermi('app:role:add')")
    @Log(title = "APP角色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsAppRoleVO fsAppRole)
    {
        return toAjax(fsAppRoleService.insertFsAppRole(fsAppRole));
    }

    /**
     * 修改APP角色
     */
    @PreAuthorize("@ss.hasPermi('app:role:edit')")
    @Log(title = "APP角色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsAppRoleVO fsAppRole)
    {
        return toAjax(fsAppRoleService.updateFsAppRole(fsAppRole));
    }

    /**
     * 删除APP角色
     */
    @PreAuthorize("@ss.hasPermi('app:role:remove')")
    @Log(title = "APP角色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsAppRoleService.deleteFsAppRoleByIds(ids));
    }
}
