package com.zhongzheng.controller.recruit;

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

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.recruit.bo.RecruitInterviewAddBo;
import com.zhongzheng.modules.recruit.bo.RecruitInterviewEditBo;
import com.zhongzheng.modules.recruit.bo.RecruitInterviewQueryBo;
import com.zhongzheng.modules.recruit.service.IRecruitInterviewService;
import com.zhongzheng.modules.recruit.vo.RecruitInterviewVo;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
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 hjl
 * @date 2021-08-20
 */
@Api(value = "投递简历控制器", tags = {"投递简历管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/interview")
public class RecruitInterviewController extends BaseController {

    private final IRecruitInterviewService iRecruitInterviewService;

    private final WxTokenService wxTokenService;

    /**
     * 查询招聘面试关联列表
     */
    @ApiOperation("查询邀请面试列表")
    @GetMapping("/list")
    public TableDataInfo<RecruitInterviewVo> list(RecruitInterviewQueryBo bo) {
        startPage();
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<RecruitInterviewVo> list = iRecruitInterviewService.queryListAppAll(bo);
        return getDataTable(list);
    }

    /**
     * 查询招聘面试简历列表
     */
    @ApiOperation("全部投递面试简历列表")
    @GetMapping("/listAll")
    public TableDataInfo<RecruitInterviewVo> listAll(RecruitInterviewQueryBo bo) {
        startPage();
        bo.setStatus(0);
        List<RecruitInterviewVo> list = iRecruitInterviewService.queryListAll(bo);
        return  getDataTable(list);
    }


    /**
     * 获取招聘面试关联详细信息
     */
    @ApiOperation("获取招聘面试关联详细信息")
    @GetMapping("/{interviewId}")
    public AjaxResult<RecruitInterviewVo> getInfo(@PathVariable("interviewId" ) Long interviewId) {
        return AjaxResult.success(iRecruitInterviewService.queryById(interviewId));
    }

    /**
     * 新增招聘面试关联
     */
    @ApiOperation("投递简历")
    @Log(title = "投递简历", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody RecruitInterviewAddBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(iRecruitInterviewService.insertByAddBo(bo) ? 1 : 0);
    }




}
