package com.zhongzheng.controller.recruit;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.common.core.domain.model.LoginUser;
import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.TokenService;
import com.zhongzheng.modules.recruit.bo.RecruitNeedsAddBo;
import com.zhongzheng.modules.recruit.bo.RecruitNeedsEditBo;
import com.zhongzheng.modules.recruit.bo.RecruitNeedsQueryBo;
import com.zhongzheng.modules.recruit.domain.RecruitNeeds;
import com.zhongzheng.modules.recruit.service.IRecruitNeedsService;
import com.zhongzheng.modules.recruit.vo.RecruitNeedsVo;
import lombok.RequiredArgsConstructor;
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.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 招聘需求Controller
 *
 * @author ruoyi
 * @date 2021-08-12
 */
@Api(value = "招聘需求控制器", tags = {"招聘需求管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/recruit/needs")
public class RecruitNeedsController extends BaseController {

    private final IRecruitNeedsService iRecruitNeedsService;

    private final TokenService tokenService;

    /**
     * 查询招聘需求列表
     */
    @ApiOperation("查询招聘需求列表")
    @PreAuthorize("@ss.hasPermi('recruit:needs:list')")
    @GetMapping("/list")
    public TableDataInfo<RecruitNeeds> list(RecruitNeedsQueryBo bo) {
        startPage();
        List<RecruitNeeds> list = iRecruitNeedsService.queryRecruitNeedsList(bo);
        return getDataTable(list);
    }

    /**
     * 导出招聘需求列表
     */
    /*@ApiOperation("导出招聘需求列表")
    @PreAuthorize("@ss.hasPermi('recruit:needs:export')")
    @Log(title = "招聘需求", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<RecruitNeedsVo> export(RecruitNeedsQueryBo bo) {
        List<RecruitNeedsVo> list = iRecruitNeedsService.queryList(bo);
        ExcelUtil<RecruitNeedsVo> util = new ExcelUtil<RecruitNeedsVo>(RecruitNeedsVo.class);
        return util.exportExcel(list, "招聘需求");
    }*/

    /**
     * 获取招聘需求详细信息
     */
    @ApiOperation("获取招聘需求详细信息")
    @PreAuthorize("@ss.hasPermi('recruit:needs:query')")
    @GetMapping("/{id}")
    public AjaxResult<RecruitNeedsVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iRecruitNeedsService.queryById(id));
    }

    /**
     * 新增招聘需求
     */
    @ApiOperation("新增招聘需求")
    @PreAuthorize("@ss.hasPermi('recruit:needs:add')")
    @Log(title = "招聘需求", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody RecruitNeedsAddBo bo) {
        return toAjax(iRecruitNeedsService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改招聘需求
     */
    @ApiOperation("修改招聘需求")
    @PreAuthorize("@ss.hasPermi('recruit:needs:edit')")
    @Log(title = "招聘需求", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody RecruitNeedsEditBo bo) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        return toAjax(iRecruitNeedsService.updateByEditBo(bo,loginUser.getUser().getNickName()) ? 1 : 0);
    }

    /**
     * 删除招聘需求
     */
   /* @ApiOperation("删除招聘需求")
    @PreAuthorize("@ss.hasPermi('system:needs:remove')")
    @Log(title = "招聘需求" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iRecruitNeedsService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }*/
}
