/*
  * 检查code是否核查不合法返回null
  */
 @Override
 public UserCode checkUserCode(String code) throws Exception {
   // 获取加密后的信息解密
   String msg = PurseSecurityUtils.decryption(code, CommonConstants.SecurityKey);
   // 解密后的json格式验证是否正确
   JsonParser jsonParser = new JsonParser();
   JsonObject jsonObject = jsonParser.parse(msg).getAsJsonObject();
   String createTime = jsonObject.get("createTime").getAsString();
   Long userId = jsonObject.get("userId").getAsLong();
   Long id = jsonObject.get("id").getAsLong();
   // 验证信息为空
   if (StringUtils.isEmpty(createTime) || ObjectUtils.isNull(userId) || ObjectUtils.isNull(id)) {
     return null;
   }
   UserCode userCode = userCodeDao.getUserCodeById(id);
   // 查询userCode 状态是否已经使用过
   if (ObjectUtils.isNotNull(userCode) && userCode.getStatus().longValue() == 0) {
     Calendar c = Calendar.getInstance();
     c.setTime(userCode.getCreateTime());
     c.add(Calendar.DAY_OF_MONTH, 3);
     if (new Date().getTime() > c.getTime().getTime()) { // 超过三天
       return null;
     }
     return userCode;
   }
   return null;
 }
  @RequestMapping("/Subjectmajor/addlist")
  @ResponseBody
  public Map<String, Object> addSubjectMajorByids(HttpServletRequest request) {
    try {
      String ids = request.getParameter("ids");
      Long subjectId = Long.parseLong(request.getParameter("subjectId"));
      Subject subject = new Subject();
      subject.setSubjectId(subjectId);
      subject = subjectService.getSubjectBySubjectId(subject);
      if (ObjectUtils.isNull(subject.getParentId()) || subject.getParentId().intValue() == 0) {
        this.setJson(false, "subjectIdError", null);
        return json;
      }
      ids = ids.replace(",", " ").trim().replace(" ", ",");
      if (ObjectUtils.isNotNull(ids)) {
        String[] idsArray = ids.split(",");
        List<SubjectMajor> subList = new ArrayList<SubjectMajor>();
        for (int i = 0; i < idsArray.length; i++) {
          SubjectMajor subjectMajor = new SubjectMajor();

          subjectMajor.setMajorid(Long.parseLong(idsArray[i]));
          subjectMajor.setSubjectid(subjectId);
          subList.add(subjectMajor);
        }
        subjectMajorService.addSubjectMajorBatch(subList);

        this.setJson(true, "success", null);
      }

    } catch (Exception e) {
      this.setJson(false, "error", null);
      logger.info("MagorController------addSubjectMajorByids");
    }
    return json;
  }
  /**
   * 修改用户信息
   *
   * @param user
   * @return
   */
  @RequestMapping("/user/updateUserInfo")
  @ResponseBody
  public Map<String, Object> updateUserInfo(@ModelAttribute("user") User user) {
    try {
      // 修改用户信息
      if (ObjectUtils.isNull(user)) {
        this.setJson(false, "信息错误", null);
        return json;
      }

      userService.updateUser(user);
      this.setJson(true, "修改成功", null);
    } catch (Exception e) {
      logger.error("updateUserInfo:" + e);
    }
    return json;
  }