// 删除志愿
 @RequestMapping(value = "/deleteMyApply")
 public ModelAndView deleteMyApply(HttpServletRequest request) {
   String myGuid = (String) request.getParameter("myGuid").trim();
   ModelAndView mv = new ModelAndView();
   MyApply myapply = new MyApply();
   myapply.setMYGUID(myGuid);
   myApplyService.deleteApplyByGuid(myGuid);
   mv.setViewName("forward:/jobinfo/apply-record.html");
   return mv;
 }
  // 修改志愿
  @RequestMapping(value = "/updateMyApply")
  public ModelAndView updateMyApply(HttpServletRequest request, HttpServletResponse response) {
    // String choiceType = (String) request.getParameter("choose");
    String myGuidFirst = (String) request.getParameter("myGuid").trim();
    String myGuidSecond = (String) request.getParameter("myGuid1").trim();
    String type = (String) request.getParameter("type");
    ModelAndView mv = new ModelAndView();
    mv.setViewName("forward:/jobinfo/apply-record.html");
    MyApply myapplyFirst = new MyApply();
    MyApply myapplySecond = new MyApply();
    HttpSession session = request.getSession();
    String currentOpenId = (String) session.getAttribute("currentOpenId");
    // currentOpenId = "oxSyKwTtvEyDDoBnxLsfpWnK7kCY";
    List<MyApply> listMyApply = myApplyService.selectMyApplyByOpenId(currentOpenId);
    if (type.equals("FC")) {
      myapplyFirst.setMYGUID(myGuidFirst);
      myapplyFirst.setType("SC");
      myApplyService.updateMyApply(myapplyFirst);
      // 判断第二志愿存不存在
      if (listMyApply.size() == 2) {
        myapplySecond.setMYGUID(myGuidSecond);
        myapplySecond.setType("FC");
        myApplyService.updateMyApply(myapplySecond);
      }
    }

    if (type.equals("SC")) {
      myapplyFirst.setMYGUID(myGuidFirst);
      myapplyFirst.setType("FC");
      myApplyService.updateMyApply(myapplyFirst);
      // 判断第二志愿存不存在
      if (listMyApply.size() == 2) {
        myapplySecond.setMYGUID(myGuidSecond);
        myapplySecond.setType("SC");
        myApplyService.updateMyApply(myapplySecond);
      }
    }

    return mv;
  }
  @RequestMapping(value = "volunter")
  @ResponseBody
  public Map<String, Object> selectVolunteer(
      HttpServletRequest request, @RequestBody Map<String, Object> params) {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("success", true);
    String choiceType = (String) params.get("choice");
    String jobGuid = (String) params.get("jobGuid");
    String jrGuid = (String) params.get("jrGuid");
    HttpSession session = request.getSession();
    String currentOpenId = (String) session.getAttribute("currentOpenId");
    // currentOpenId = "oxSyKwTtvEyDDoBnxLsfpWnK7kCY";
    List<MyApply> listMyApply = myApplyService.selectMyApplyByOpenId(currentOpenId);
    if (currentOpenId != null && currentOpenId != "") {

      MyApply nMyApply = new MyApply();
      nMyApply.setJobguid(jobGuid);
      nMyApply.setOpenid(currentOpenId);
      nMyApply.setType(choiceType);
      nMyApply.setJrGuid(jrGuid);
      if (listMyApply == null || listMyApply.size() == 0) {
        myApplyService.insertMyApply(nMyApply);
      } else {
        MyApply ma = listMyApply.get(0);
        String type = ma.getType();
        if (type.equals(choiceType) && type.equals("FC")) {
          ma.setType("SC");
          myApplyService.updateMyApply(ma);
        }
        if (type.equals(choiceType) && type.equals("SC")) {
          ma.setType("FC");
          myApplyService.updateMyApply(ma);
        }
        myApplyService.insertMyApply(nMyApply);
      }
    }
    return map;
  }
  // 判断简历是否存在和有没有志愿
  @RequestMapping(value = "resumeVerification")
  @ResponseBody
  public Map<String, Object> apply(
      HttpServletRequest request, @RequestBody Map<String, Object> params) {
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("success", true);
    HttpSession session = request.getSession();

    String jobGuid = (String) params.get("jobGuid");
    String currentOpenId = (String) session.getAttribute("currentOpenId");

    if (currentOpenId == null) {
      result.put("success", false);
      result.put("type", "openId");
      result.put("message", "openId 为空");
      return result;
    }

    Resume resumeRow = resumeService.getResumeByOpenId(currentOpenId);
    if (resumeRow == null) {
      result.put("success", false);
      result.put("type", "reusumenull");
      result.put("message", "你还未填写简历!");
      return result;
    }

    List<MyApply> listMyApply = myApplyService.selectMyApplyByOpenId(currentOpenId);
    // 判断是否已经申请了2个职位
    if (listMyApply != null && listMyApply.size() == 2) {
      result.put("success", false);
      result.put("type", "MyApply");
      result.put("message", "您已经申请了2个职位,不能再申请");
      return result;
    }

    // 判断是否已经申请过该职位
    Boolean existApply = false;
    for (MyApply ma : listMyApply) {
      if (jobGuid.equals(ma.getJobguid())) {
        existApply = true;
      }
    }
    if (existApply) {
      result.put("success", false);
      result.put("type", "existAppy");
      result.put("message", "您已经申请了该职位");
      return result;
    }
    return result;
  }
 @RequestMapping(value = "/apply-record.html")
 public ModelAndView applyRecord(HttpServletRequest request) {
   ModelAndView mv = new ModelAndView();
   mv.setViewName("jobs/apply-record");
   // 1.获取用户的openId
   HttpSession session = request.getSession();
   String code = (String) request.getParameter("code");
   String currentOpenId = (String) session.getAttribute("currentOpenId");
   if (currentOpenId == null || currentOpenId.equals("")) {
     currentOpenId =
         WeixinUtil.getOpenidByOauth(JobAppConfig.APP_ID, JobAppConfig.APP_SECRET, code);
     session.setAttribute("currentOpenId", currentOpenId);
   }
   List<MyApply> listMyApply = myApplyService.selectMyApplyByOpenId(currentOpenId);
   int count = listMyApply.size();
   mv.addObject("CONTENT", count);
   mv.addObject("MYAPPLYS", listMyApply);
   return mv;
 }