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.CompanyUserRole;
import com.fs.company.service.ICompanyUserRoleService;
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/companyUserRole")
public class CompanyUserRoleController extends BaseController
{
    @Autowired
    private ICompanyUserRoleService companyUserRoleService;

    /**
     * 查询用户和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserRole:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyUserRole companyUserRole)
    {
        startPage();
        List<CompanyUserRole> list = companyUserRoleService.selectCompanyUserRoleList(companyUserRole);
        return getDataTable(list);
    }

    /**
     * 导出用户和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserRole:export')")
    @Log(title = "用户和角色关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyUserRole companyUserRole)
    {
        List<CompanyUserRole> list = companyUserRoleService.selectCompanyUserRoleList(companyUserRole);
        ExcelUtil<CompanyUserRole> util = new ExcelUtil<CompanyUserRole>(CompanyUserRole.class);
        return util.exportExcel(list, "companyUserRole");
    }

    /**
     * 获取用户和角色关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserRole:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(companyUserRoleService.selectCompanyUserRoleById(userId));
    }

    /**
     * 新增用户和角色关联
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserRole:add')")
    @Log(title = "用户和角色关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyUserRole companyUserRole)
    {
        return toAjax(companyUserRoleService.insertCompanyUserRole(companyUserRole));
    }

    /**
     * 修改用户和角色关联
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserRole:edit')")
    @Log(title = "用户和角色关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyUserRole companyUserRole)
    {
        return toAjax(companyUserRoleService.updateCompanyUserRole(companyUserRole));
    }

    /**
     * 删除用户和角色关联
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserRole:remove')")
    @Log(title = "用户和角色关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(companyUserRoleService.deleteCompanyUserRoleByIds(userIds));
    }
}
