package com.fs.company.controller;

import java.util.List;
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.company.domain.CompanyRoleDept;
import com.fs.company.service.ICompanyRoleDeptService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 角色和部门关联Controller
 * 
 * @author fs
 * @date 2021-10-04
 */
@RestController
@RequestMapping("/company/companyRoleDept")
public class CompanyRoleDeptController extends BaseController
{
    @Autowired
    private ICompanyRoleDeptService companyRoleDeptService;

    /**
     * 查询角色和部门关联列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyRoleDept:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyRoleDept companyRoleDept)
    {
        startPage();
        List<CompanyRoleDept> list = companyRoleDeptService.selectCompanyRoleDeptList(companyRoleDept);
        return getDataTable(list);
    }

    /**
     * 导出角色和部门关联列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyRoleDept:export')")
    @Log(title = "角色和部门关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyRoleDept companyRoleDept)
    {
        List<CompanyRoleDept> list = companyRoleDeptService.selectCompanyRoleDeptList(companyRoleDept);
        ExcelUtil<CompanyRoleDept> util = new ExcelUtil<CompanyRoleDept>(CompanyRoleDept.class);
        return util.exportExcel(list, "companyRoleDept");
    }

    /**
     * 获取角色和部门关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyRoleDept:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId)
    {
        return AjaxResult.success(companyRoleDeptService.selectCompanyRoleDeptById(roleId));
    }

    /**
     * 新增角色和部门关联
     */
    @PreAuthorize("@ss.hasPermi('company:companyRoleDept:add')")
    @Log(title = "角色和部门关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyRoleDept companyRoleDept)
    {
        return toAjax(companyRoleDeptService.insertCompanyRoleDept(companyRoleDept));
    }

    /**
     * 修改角色和部门关联
     */
    @PreAuthorize("@ss.hasPermi('company:companyRoleDept:edit')")
    @Log(title = "角色和部门关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyRoleDept companyRoleDept)
    {
        return toAjax(companyRoleDeptService.updateCompanyRoleDept(companyRoleDept));
    }

    /**
     * 删除角色和部门关联
     */
    @PreAuthorize("@ss.hasPermi('company:companyRoleDept:remove')")
    @Log(title = "角色和部门关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
        return toAjax(companyRoleDeptService.deleteCompanyRoleDeptByIds(roleIds));
    }
}
