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.CompanyUserPost;
import com.fs.company.service.ICompanyUserPostService;
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/companyUserPost")
public class CompanyUserPostController extends BaseController
{
    @Autowired
    private ICompanyUserPostService companyUserPostService;

    /**
     * 查询用户与岗位关联列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserPost:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyUserPost companyUserPost)
    {
        startPage();
        List<CompanyUserPost> list = companyUserPostService.selectCompanyUserPostList(companyUserPost);
        return getDataTable(list);
    }

    /**
     * 导出用户与岗位关联列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserPost:export')")
    @Log(title = "用户与岗位关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyUserPost companyUserPost)
    {
        List<CompanyUserPost> list = companyUserPostService.selectCompanyUserPostList(companyUserPost);
        ExcelUtil<CompanyUserPost> util = new ExcelUtil<CompanyUserPost>(CompanyUserPost.class);
        return util.exportExcel(list, "companyUserPost");
    }

    /**
     * 获取用户与岗位关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserPost:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(companyUserPostService.selectCompanyUserPostById(userId));
    }

    /**
     * 新增用户与岗位关联
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserPost:add')")
    @Log(title = "用户与岗位关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyUserPost companyUserPost)
    {
        return toAjax(companyUserPostService.insertCompanyUserPost(companyUserPost));
    }

    /**
     * 修改用户与岗位关联
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserPost:edit')")
    @Log(title = "用户与岗位关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyUserPost companyUserPost)
    {
        return toAjax(companyUserPostService.updateCompanyUserPost(companyUserPost));
    }

    /**
     * 删除用户与岗位关联
     */
    @PreAuthorize("@ss.hasPermi('company:companyUserPost:remove')")
    @Log(title = "用户与岗位关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(companyUserPostService.deleteCompanyUserPostByIds(userIds));
    }
}
