package com.ruoyi.cms.controller.cms;

import com.ruoyi.cms.domain.rc.*;
import com.ruoyi.cms.service.rc.IPublicJobFairService;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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（CMS后台）
 */
@RestController
@RequestMapping("/cms/publicJobFair")
@Api(tags = "后台：公共招聘会管理")
public class CmsPublicJobFairController extends BaseController {

    @Autowired
    private IPublicJobFairService publicJobFairService;

    /**
     * 查询招聘会列表
     */
    @ApiOperation("查询招聘会列表")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:list')")
    @GetMapping("/list")
    public TableDataInfo list(PublicJobFairQuery query) {
        startPage();
        List<PublicJobFair> list = publicJobFairService.selectList(query);
        return getDataTable(list);
    }

    /**
     * 获取招聘会详情
     */
    @ApiOperation("获取招聘会详情")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:query')")
    @GetMapping("/{jobFairId}")
    public AjaxResult getInfo(@ApiParam("招聘会ID") @PathVariable String jobFairId) {
        return success(publicJobFairService.selectById(jobFairId));
    }

    /**
     * 新增招聘会
     */
    @ApiOperation("新增招聘会")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:add')")
    @Log(title = "公共招聘会", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PublicJobFair publicJobFair) {
        return toAjax(publicJobFairService.insert(publicJobFair));
    }

    /**
     * 修改招聘会
     */
    @ApiOperation("修改招聘会")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:edit')")
    @Log(title = "公共招聘会", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PublicJobFair publicJobFair) {
        return toAjax(publicJobFairService.update(publicJobFair));
    }

    /**
     * 删除招聘会
     */
    @ApiOperation("删除招聘会")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:remove')")
    @Log(title = "公共招聘会", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jobFairIds}")
    public AjaxResult remove(@ApiParam("招聘会ID数组") @PathVariable String[] jobFairIds) {
        return toAjax(publicJobFairService.deleteByIds(jobFairIds));
    }

    /**
     * 添加企业到招聘会
     */
    @ApiOperation("添加企业到招聘会")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:edit')")
    @Log(title = "招聘会添加企业", businessType = BusinessType.INSERT)
    @PostMapping("/company")
    public AjaxResult addCompany(@RequestBody PublicJobFairCompany company) {
        return toAjax(publicJobFairService.addCompany(company));
    }

    /**
     * 批量添加企业到招聘会
     */
    @ApiOperation("批量添加企业到招聘会")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:edit')")
    @Log(title = "招聘会批量添加企业", businessType = BusinessType.INSERT)
    @PostMapping("/company/batch")
    public AjaxResult addCompanyBatch(@RequestBody List<PublicJobFairCompany> companies) {
        return toAjax(publicJobFairService.addCompanyBatch(companies));
    }

    /**
     * 移除招聘会企业
     */
    @ApiOperation("移除招聘会企业")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:edit')")
    @Log(title = "移除招聘会企业", businessType = BusinessType.DELETE)
    @DeleteMapping("/company/{id}")
    public AjaxResult removeCompany(@ApiParam("关联ID") @PathVariable String id) {
        return toAjax(publicJobFairService.removeCompany(id));
    }

    /**
     * 添加岗位到招聘会
     */
    @ApiOperation("添加岗位到招聘会")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:edit')")
    @Log(title = "招聘会添加岗位", businessType = BusinessType.INSERT)
    @PostMapping("/job")
    public AjaxResult addJob(@RequestBody PublicJobFairJob job) {
        return toAjax(publicJobFairService.addJob(job));
    }

    /**
     * 批量添加岗位到招聘会
     */
    @ApiOperation("批量添加岗位到招聘会")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:edit')")
    @Log(title = "招聘会批量添加岗位", businessType = BusinessType.INSERT)
    @PostMapping("/job/batch")
    public AjaxResult addJobBatch(@RequestBody List<PublicJobFairJob> jobs) {
        return toAjax(publicJobFairService.addJobBatch(jobs));
    }

    /**
     * 移除招聘会岗位
     */
    @ApiOperation("移除招聘会岗位")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:edit')")
    @Log(title = "移除招聘会岗位", businessType = BusinessType.DELETE)
    @DeleteMapping("/job/{id}")
    public AjaxResult removeJob(@ApiParam("关联ID") @PathVariable String id) {
        return toAjax(publicJobFairService.removeJob(id));
    }

    /**
     * 查询招聘会报名列表
     */
    @ApiOperation("查询招聘会报名列表")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:query')")
    @GetMapping("/signups/{jobFairId}")
    public TableDataInfo getSignUpList(@ApiParam("招聘会ID") @PathVariable String jobFairId) {
        startPage();
        List<JobFairSignUpVO> list = publicJobFairService.selectSignUpList(jobFairId);
        return getDataTable(list);
    }

    /**
     * 查询招聘会关联的企业列表
     */
    @ApiOperation("查询招聘会关联的企业列表")
    @PreAuthorize("@ss.hasPermi('cms:publicJobFair:query')")
    @GetMapping("/companies/{jobFairId}")
    public AjaxResult getCompanyList(@ApiParam("招聘会ID") @PathVariable String jobFairId) {
        return success(publicJobFairService.getEnterprisesWithJobs(jobFairId));
    }
}
