package com.zhongzheng.controller.recruit;

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

import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.recruit.bo.RecruitResumeAddBo;
import com.zhongzheng.modules.recruit.bo.RecruitResumeEditBo;
import com.zhongzheng.modules.recruit.bo.RecruitResumeQueryBo;
import com.zhongzheng.modules.recruit.service.IRecruitResumeService;
import com.zhongzheng.modules.recruit.vo.RecruitResumeVo;
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-18
 */
@Api(value = "招聘用户简历控制器", tags = {"招聘用户简历管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/recruit/resume")
public class RecruitResumeController extends BaseController {

    private final IRecruitResumeService iRecruitResumeService;

    private final WxTokenService wxTokenService;

    /**
     * 查询招聘用户简历列表
     */
    @ApiOperation("查询招聘用户简历列表")
    @GetMapping("/list")
    public TableDataInfo<RecruitResumeVo> list(RecruitResumeQueryBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        bo.setStatus(1);
        startPage();
        List<RecruitResumeVo> list = iRecruitResumeService.queryList(bo);
        return getDataTable(list);
    }



    /**
     * 获取招聘用户简历详细信息
     */
    @ApiOperation("获取招聘用户简历详细信息")
    @GetMapping("/{resumeId}")
    public AjaxResult<RecruitResumeVo> getInfo(@PathVariable("resumeId" ) Long resumeId) {
        return AjaxResult.success(iRecruitResumeService.queryById(resumeId));
    }

    /**
     * 新增招聘用户简历
     */
    @ApiOperation("新增招聘用户简历")
    @Log(title = "招聘用户简历", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody RecruitResumeAddBo bo) throws IllegalAccessException {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(iRecruitResumeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改招聘用户简历
     */
    @ApiOperation("修改招聘用户简历")
    @Log(title = "招聘用户简历", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody RecruitResumeEditBo bo) throws IllegalAccessException {
        return toAjax(iRecruitResumeService.updateByEditBo(bo) ? 1 : 0);
    }


}
