package com.wechat.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wechat.global.base.dao.PagingResult;
import com.wechat.global.message.InfoMsg;
import com.wechat.model.dbEntity.MdeJobAdvertised;
import com.wechat.model.dbEntity.MdeJobInvitationRel;
import com.wechat.model.dbEntity.MdeUser;
import com.wechat.model.dto.TalentRetrievalDto;
import com.wechat.model.requestDto.AlentRetrievalReq;
import com.wechat.model.requestDto.KeyWordReq;
import com.wechat.model.requestDto.PageReq;
import com.wechat.model.responseDto.ContactUserInfoResp;
import com.wechat.model.responseDto.ResultEntity;
import com.wechat.service.CommonService;
import com.wechat.service.MdeJobInvitationRelService;
import com.wechat.service.TalentRetrievalService;

/**
 * 人才检索
 * 
 * @author zhouyd
 *
 */
@Controller
@RequestMapping(value = "talentRetrieval")
public class TalentRetrievalController {

	@Autowired
	private TalentRetrievalService talentRetrievalService;

	@Autowired
	private MdeJobInvitationRelService mdeJobInvitationRelService;
	
	@Autowired
	private CommonService commonService;

	/**
	 * 人才页面初始化
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity<Map<String, Object>> initTalen(HttpServletRequest request) throws Exception {
		Map<String, Object> map = talentRetrievalService.init(request);
		return new ResultEntity<Map<String, Object>>(InfoMsg.SUCCESS_REQUEST, map);
	}
	
	/**
	 * 优选人才-分页查询
	 * @param userCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="getPagingRecmtPep", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<PagingResult<TalentRetrievalDto>> getPagingRecmtPep(HttpServletRequest request,@RequestBody PageReq page) throws Exception {
		ResultEntity<PagingResult<TalentRetrievalDto>> rest = new ResultEntity<PagingResult<TalentRetrievalDto>>();
		String userCode = commonService.getUserCode(request);
		PagingResult<TalentRetrievalDto>  talentList= talentRetrievalService.getPagingRecmtPep(page,userCode);
		rest.setResult(talentList);
		return rest;
	}
	

	/**
	 * 人才检索
	 * 
	 * @param req
	 * @param resp
	 * @param alentReq
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "searchKeyWord", method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity<PagingResult<TalentRetrievalDto>> searchPersonAbility(HttpServletRequest req,
			HttpServletResponse resp, @RequestBody KeyWordReq keyWordReq) throws Exception {
		PagingResult<TalentRetrievalDto> page = talentRetrievalService.searchKeyWord(keyWordReq,req);
		return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, page);
	}

	/**
	 * 筛选人才
	 * 
	 * @param req
	 * @param resp
	 * @param alentRetrievalReq
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "filterPersonAbility", method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity<PagingResult<TalentRetrievalDto>> filterPersonAbility(HttpServletRequest req,
			HttpServletResponse resp, @RequestBody AlentRetrievalReq alentRetrievalReq) throws Exception {
		PagingResult<TalentRetrievalDto> page = talentRetrievalService.filterPersonAbility(alentRetrievalReq,req);
		return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, page);
	}

	/**
	 * 查看联系方式
	 * 
	 * @param userCode
	 * @return
	 */
	@RequestMapping(value = "getContactNumber", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity<ContactUserInfoResp> getContactNumber(@RequestParam String userCode, HttpServletRequest req) {
		String lang = commonService.getLanguage(req);
		ContactUserInfoResp contactUserInfoResp = talentRetrievalService.getContactNumber(userCode,lang);

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

	/**
	 * 邀请投递简历
	 * 
	 * @param mdeJobInvitationRel
	 * @param req
	 * @param resp
	 * @return
	 */
	@RequestMapping(value = "invitationDeliver", method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity<String> invitationDeliver(@Valid @RequestBody MdeJobInvitationRel mdeJobInvitationRel,
			HttpServletRequest req, HttpServletResponse resp) {
		return mdeJobInvitationRelService.invitationDeliver(req, mdeJobInvitationRel);
	}

	/**
	 * 点击邀请投递简历 获取企业正在招聘的职位
	 * 
	 * @param req
	 * @param resp
	 * @return List<MdeJobInvitationRel>
	 */
	@RequestMapping(value = "clickInvitation")
	@ResponseBody
	public ResultEntity<List<MdeJobAdvertised>> clickInvitation(HttpServletRequest req, HttpServletResponse resp) {

		List<MdeJobAdvertised> mdeJobAdvertised = mdeJobInvitationRelService.clickInvitation(req);
		return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, mdeJobAdvertised);
	}
}
