package com.fs.company.controller;

import com.fs.common.annotation.Log;
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.company.domain.CompanyRole;
import com.fs.company.service.ICompanyRoleService;
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 2021-10-04
 */
@RestController
@RequestMapping("/company/companyRole")
public class CompanyRoleController extends BaseController
{
    @Autowired
    private ICompanyRoleService companyRoleService;

    /**
     * 查询角色信息列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyRole:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyRole companyRole)
    {
        startPage();
        List<CompanyRole> list = companyRoleService.selectCompanyRoleList(companyRole);
        return getDataTable(list);
    }

    /**
     * 导出角色信息列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyRole:export')")
    @Log(title = "角色信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyRole companyRole)
    {
        List<CompanyRole> list = companyRoleService.selectCompanyRoleList(companyRole);
        ExcelUtil<CompanyRole> util = new ExcelUtil<CompanyRole>(CompanyRole.class);
        return util.exportExcel(list, "companyRole");
    }

    /**
     * 获取角色信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyRole:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId)
    {
        return AjaxResult.success(companyRoleService.selectCompanyRoleById(roleId));
    }

    /**
     * 新增角色信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyRole:add')")
    @Log(title = "角色信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyRole companyRole)
    {
        return toAjax(companyRoleService.insertCompanyRole(companyRole));
    }

    /**
     * 修改角色信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyRole:edit')")
    @Log(title = "角色信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyRole companyRole)
    {
        return toAjax(companyRoleService.updateCompanyRole(companyRole));
    }

    /**
     * 删除角色信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyRole:remove')")
    @Log(title = "角色信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
        return toAjax(companyRoleService.deleteCompanyRoleByIds(roleIds));
    }
}
