package com.zhongzheng.controller.recruit;

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.RecruitAttachResumeAddBo;
import com.zhongzheng.modules.recruit.bo.RecruitAttachResumeEditBo;
import com.zhongzheng.modules.recruit.bo.RecruitAttachResumeQueryBo;
import com.zhongzheng.modules.recruit.service.IRecruitAttachResumeService;
import com.zhongzheng.modules.recruit.vo.RecruitAttachResumeVo;
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("/recruit/attach")
public class RecruitAttachResumeController extends BaseController {

    private final IRecruitAttachResumeService iRecruitAttachResumeService;

    private final WxTokenService wxTokenService;

    /**
     * 查询附件简历列表
     */
    @ApiOperation("查询附件简历列表")
    @GetMapping("/list")
    public TableDataInfo<RecruitAttachResumeVo> list(RecruitAttachResumeQueryBo bo) {
        startPage();
        List<RecruitAttachResumeVo> list = iRecruitAttachResumeService.queryList(bo);
        return getDataTable(list);
    }



    /**
     * 获取附件简历详细信息
     */
    @ApiOperation("获取附件简历详细信息")
    @GetMapping("/{attachResumeId}")
    public AjaxResult<RecruitAttachResumeVo> getInfo(@PathVariable("attachResumeId" ) Long attachResumeId) {
        return AjaxResult.success(iRecruitAttachResumeService.queryById(attachResumeId));
    }

    /**
     * 新增附件简历
     */
    @ApiOperation("新增附件简历")
    @Log(title = "附件简历", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody RecruitAttachResumeAddBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(iRecruitAttachResumeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改附件简历
     */
    @ApiOperation("修改附件简历")
    @Log(title = "附件简历", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody RecruitAttachResumeEditBo bo) {
        return toAjax(iRecruitAttachResumeService.updateByEditBo(bo) ? 1 : 0);
    }


}
