package com.wechat.controller;

import com.wechat.global.message.InfoMsg;
import com.wechat.model.requestDto.*;
import com.wechat.model.responseDto.AlreadyPublishResp;
import com.wechat.model.responseDto.ContactUserInfoResp;
import com.wechat.model.responseDto.ResultEntity;
import com.wechat.service.CommonService;
import com.wechat.service.EnterpriseService;
import com.wechat.service.MdeJobAdvertisedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Map;

/**
 * 企业查看简历
 *
 * @author zhouyd
 */
@Controller
@RequestMapping(value = "enterprise")
public class EnterpriseController {

    @Autowired
    private EnterpriseService enterpriseService;
    @Autowired
    private CommonService commonService;
    @Resource
    private MdeJobAdvertisedService jobAdvertisedService;
    /**
     * 企业点击收到的简历
     *
     * @return
     * @throws Exception
     */
/*	@RequestMapping(value = "receive", method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity<Map<String, Object>> receiveUserCv(HttpServletRequest req, HttpServletResponse resp,
			@RequestBody Page page) throws Exception {

		Map<String, Object> maps = enterpriseService.receiveUserCv(req, page);
		return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, maps);
	}*/

    /**
     * 查看简历
     *
     * @param userCode
     * @return
     */
    @RequestMapping(value = "lookUserCv", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<ContactUserInfoResp> lookUserCv(@RequestBody Map<String, String> param, HttpServletRequest req) {
        String lang = commonService.getLanguage(req);
        String hotelCode = commonService.getUserCode(req);
        ContactUserInfoResp contactUserInfoResp = enterpriseService.lookUserCv(hotelCode, param, lang);
        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, contactUserInfoResp);
    }

    /**
     * 更新职位发布状态
     *
     * @param req
     * @param resp
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "updateJobAdvertisedStatus", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> updateJobAdvertisedStatus(HttpServletRequest req, HttpServletResponse resp,
                                                          @RequestBody Map<String, String> params) throws Exception {
        return enterpriseService.updateJobAdvertisedStatus(req, params);
    }

    /**
     * 更新职位首推状态
     *
     * @param req
     * @param resp
     * @param params
     * @return
     */
    @RequestMapping(value = "updateJobRecommend", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> updateJobRecommend(HttpServletRequest req, HttpServletResponse resp,
                                                   @RequestBody Map<String, String> params) {
        return enterpriseService.updateJobRecommend(req, params);
    }

    /**
     * 下载简历
     *
     * @param req
     * @param resp
     * @return
     * @throws IOException
     * @throws Exception
     */
    @RequestMapping(value = "download", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> downloadUserCv(HttpServletRequest req, HttpServletResponse resp,
                                               @RequestBody Map<String, Object> param) {
        String infoMsg = enterpriseService.downloadUserCv(req, resp, param);
        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, infoMsg);
    }

    /**
     * 切换简历类型 根据类型判断 （ 0-新投递；1-已查看；2-已下载；3-邀请面试；4-录取；5-淘汰；6-储备）
     *
     * @param req
     * @param resp
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getUserCvStateListInfo", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Map<String, Object>> getUserCvStateListInfo(HttpServletRequest req,
                                                                    @Valid @RequestBody UserCvStatusReq param) {
        Map<String, Object> maps = enterpriseService.getUserCvStateListInfo2(req, param, "0");
        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, maps);
    }

    /**
     * PC端专用
     * 切换简历类型 根据类型判断 （ 0-新投递；1-已查看；2-已下载；3-邀请面试；4-录取；5-淘汰；6-储备）
     *
     * @param req
     * @param resp
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getUserCvStateListInfoPc", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Map<String, Object>> getUserCvStateListInfoPc(HttpServletRequest req,
                                                                      @Valid @RequestBody UserCvStatusReq param) {
        Map<String, Object> maps = enterpriseService.getUserCvStateListInfo2(req, param, "1");
        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, maps);
    }

    /**
     * PC端专用
     * 按职位显示投递列表
     *
     * @param req
     * @param resp
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getUserCvListInfoByJobPc", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Map<String, Object>> getUserCvListInfoByJobPc(HttpServletRequest req,
                                                                      @RequestBody UserCvByJobReq param) {
        Map<String, Object> maps = enterpriseService.getUserCvStateListInfoByJob(req, param, "1");
        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, maps);
    }


    /**
     * 邀请面试/录用/淘汰 更新简历状态 type （ 0-新投递；1-已查看；2-已下载；3-邀请面试；4-录取；5-淘汰；6-储备）
     *
     * @param req
     * @param resp
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "updateUserCvStatus", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> updateUserCvStatus(HttpServletRequest req, @RequestBody UpdUserCvReq param)
            throws Exception {
        InfoMsg infoMsg = enterpriseService.updateUserCvStatus(req, param, new InterviewCreateReq());
        return new ResultEntity<>(infoMsg);
    }

    /**
     * 已发布信息
     *
     * @param req
     * @param resp
     * @return
     */
    @RequestMapping(value = "alreadyPublish", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<AlreadyPublishResp> alreadyPublish(@RequestBody JobAdvertisedReqDto jobReq,
                                                           HttpServletRequest req, HttpServletResponse resp) {
        String userCode = commonService.getUserCode(req);
        AlreadyPublishResp response = new AlreadyPublishResp();
        // 获取已发布职位信息
        response.setList(enterpriseService.alreadyPublish(req, resp, userCode, jobReq));
        // 获取首推数据
        response.setRecommendNum(jobAdvertisedService.getAvailableAndUsedCount(userCode));

        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, response);
    }


    /**
     * @param req
     * @param resp
     * @param keyWordReq 关键词
     * @return ResultEntity<AlreadyPublishResp>
     * @description 已发职位关键词检索
     * @author rayson
     * @date 2023-09-12 14:41
     **/
    @RequestMapping(value = "searchKeyWord", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<AlreadyPublishResp> searchPersonAbility(HttpServletRequest req,
                                                                HttpServletResponse resp, @RequestBody KeyWordReq keyWordReq) {
        String userCode = commonService.getUserCode(req);
        AlreadyPublishResp response = new AlreadyPublishResp();
        // 检索已发职位
        response.setList(enterpriseService.searchKeyWord(keyWordReq, userCode, req));
        // 获取首推数据
        response.setRecommendNum(jobAdvertisedService.getAvailableAndUsedCount(userCode));

        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, response);
    }


}
