package com.ruoyi.cms.controller.cms;

import com.ruoyi.cms.domain.Job;
import com.ruoyi.cms.domain.vo.CandidateVO;
import com.ruoyi.cms.service.IJobService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 岗位Controller
 * 
 * @author lishundong
 * @date 2024-09-03
 */
@RestController
@RequestMapping("/cms/job")
@Api(tags = "后台：岗位管理")
@Anonymous
public class CmsJobController extends BaseController
{
    @Autowired
    private IJobService jobService;
    /**
     * 查询岗位列表
     */
    @ApiOperation("查询岗位列表")
    @PreAuthorize("@ss.hasPermi('bussiness:job:list')")
    @GetMapping("/list")
    public TableDataInfo list(Job job)
    {
        startPage();
        List<Job> list = jobService.selectJobList(job);
        return getDataTable(list);
    }

    /**
     * 获取岗位详细信息
     */
    @ApiOperation("获取岗位详细信息")
    @PreAuthorize("@ss.hasPermi('bussiness:job:query')")
    @GetMapping(value = "/{jobId}")
    public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
    {
        return success(jobService.selectJobByJobId(jobId));
    }

    /**
     * 导出岗位列表
     */
    @ApiOperation("导出岗位列表")
    @PreAuthorize("@ss.hasPermi('app:job:export')")
    @Log(title = "岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Job job)
    {
        List<Job> list = jobService.selectJobList(job);
        ExcelUtil<Job> util = new ExcelUtil<Job>(Job.class);
        util.exportExcel(response, list, "岗位数据");
    }
    /**
     * 新增岗位
     */
    @ApiOperation("新增岗位")
    @PreAuthorize("@ss.hasPermi('app:job:add')")
    @Log(title = "岗位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Job job)
    {
        return toAjax(jobService.insertJob(job));
    }

    /**
     * 修改岗位
     */
    @ApiOperation("修改岗位")
    @PreAuthorize("@ss.hasPermi('app:job:edit')")
    @Log(title = "岗位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Job job)
    {
        return toAjax(jobService.updateJob(job));
    }

    /**
     * 删除岗位
     */
    @ApiOperation("删除岗位")
    @PreAuthorize("@ss.hasPermi('app:job:remove')")
    @Log(title = "岗位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jobIds}")
    public AjaxResult remove(@PathVariable Long[] jobIds)
    {
        return toAjax(jobService.deleteJobByJobIds(jobIds));
    }
    @ApiOperation("候选人查询")
    @Log(title = "岗位", businessType = BusinessType.DELETE)
    @GetMapping("/candidates")
    public TableDataInfo candidates(Long jobId)
    {
        startPage();
        List<CandidateVO> list = jobService.candidates(jobId);
        return getDataTable(list);
    }
    @GetMapping("/import")
    public AjaxResult importData()
    {
        jobService.importData();
        return success();
    }
    @GetMapping("/importRow")
    public AjaxResult importRow(@RequestParam String path)
    {
        jobService.importRow(path);
        return success();
    }
}
