/**
   * 禁用学员账号(冻结)
   *
   * @param user
   * @return
   */
  @RequestMapping("/user/updateIsavalible")
  @ResponseBody
  public Map<String, Object> updateIsavalible(
      HttpServletRequest request, @ModelAttribute User user) {
    try {
      userService.updateUserForIsavalibleById(user);
      this.setJson(true, "success", null);

      // 记录系统用户操作
      Map<String, Object> descMap = new HashMap<String, Object>();
      descMap.put("optuser", "操作id_" + SingletonLoginUtils.getSysUserId(request));
      descMap.put("optType", user.getIsavalible() == 1 ? "禁用" : "正常");
      descMap.put("userId", "用户id_" + user.getId());
      userService.addUserOptRecord(
          user.getId(),
          user.getIsavalible() == 1
              ? UserOptType.DISABLE.toString()
              : UserOptType.ACTIVE.toString(),
          SingletonLoginUtils.getSysUserId(request),
          this.getSysLoginLoginName(request),
          user.getId(),
          gson.toJson(descMap));
    } catch (Exception e) {
      logger.error("AdminUserController.updateIsavalible", e);
    }
    return json;
  }
  /**
   * 修改密码
   *
   * @return
   */
  @RequestMapping("/user/updatepwd")
  @ResponseBody
  public Map<String, Object> updatePwd(HttpServletRequest request, @ModelAttribute User user) {
    try {
      userService.updatePwdById(user, null);
      this.setJson(true, "success", null);

      // 记录系统用户操作
      Map<String, Object> descMap = new HashMap<String, Object>();
      descMap.put("optuser", "操作id_" + SingletonLoginUtils.getSysUserId(request));
      descMap.put("optType", "操作_修改用户密码");
      descMap.put("userId", "用户id_" + user.getId());
      userService.addUserOptRecord(
          user.getId(),
          UserOptType.CHANGEPWD.toString(),
          SingletonLoginUtils.getSysUserId(request),
          this.getSysLoginLoginName(request),
          user.getId(),
          gson.toJson(descMap));
    } catch (Exception e) {
      logger.error("AdminUserController.updatePwd", e);
    }
    return json;
  }
  /**
   * 发送邮件
   *
   * @param request
   * @return
   */
  @RequestMapping("/user/sendEmailMsg")
  @ResponseBody
  public Map<String, Object> sendEmailMsg(HttpServletRequest request) {
    try {
      String linksman = request.getParameter("linksman"); // 获取联系人
      String title = request.getParameter("title"); // 获取标题
      String content = request.getParameter("content"); // 获取内容

      int type = Integer.valueOf(request.getParameter("type")); // 邮件类型
      String startTime = request.getParameter("startTime"); // 发送时间
      Date starttime = new Date();
      // 如果是定时短信发送时间要大于当前时间
      if (type == 2) {
        if ("".equals(startTime)) {
          this.setJson(false, "请输入发送时间", "");
          return json;
        }
        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        starttime = formatDate.parse(startTime);
        if (!starttime.after(new Date())) {
          this.setJson(false, "定时发送的时间要大于当前日期", "");
          return json;
        }
      }

      if (StringUtils.isNotEmpty(linksman)
          && StringUtils.isNotEmpty(content)
          && StringUtils.isNotEmpty(title)) {
        // 验证邮箱
        Map<String, Object> returnMap = checkEmail(linksman);
        // 错误信息
        String errorEmail = returnMap.get("errorMessage").toString();
        if (Boolean.parseBoolean(returnMap.get("flag").toString()) == false) {
          this.setJson(false, errorEmail, "");
          return json;
        } else {
          JsonObject user = SingletonLoginUtils.getSysUser(request);
          List<UserEmailMsg> emailMsgList = new ArrayList<UserEmailMsg>();
          UserEmailMsg userEmailMsg = new UserEmailMsg();
          userEmailMsg.setId(0);
          userEmailMsg.setTitle(title);
          userEmailMsg.setContent(content);
          userEmailMsg.setEmail(returnMap.get("returnList").toString());
          userEmailMsg.setType(type);
          userEmailMsg.setSendTime(starttime);
          if (type == 1) {
            // 发送邮件
            userEmailMsgService.batchSendEmail(
                returnMap.get("returnList").toString().split(","), content, title, 3);
            // emailService.sendBatchMail(returnMap.get("returnList").toString().split(","),
            // content, title);
            userEmailMsg.setStatus(1);
          } else {
            userEmailMsg.setStatus(2);
          }
          if (ObjectUtils.isNotNull(user)) {
            userEmailMsg.setUserId(user.get("userId").getAsLong());
          } else {
            userEmailMsg.setUserId(0L);
          }
          userEmailMsg.setCreateTime(new Date());
          emailMsgList.add(userEmailMsg);
          userEmailMsgService.addUserEmailMsg(emailMsgList);
          errorEmail = "发送成功";
        }
        this.setJson(Boolean.parseBoolean(returnMap.get("flag").toString()), errorEmail, "");
      } else {
        this.setJson(false, "联系人、标题或内容不能为空", null);
      }
    } catch (Exception e) {
      logger.error("sendEmailMsg", e);
    }
    return json;
  }
  /**
   * 发送短信
   *
   * @param request
   * @return
   */
  @RequestMapping("/user/sendMsg")
  @ResponseBody
  public Map<String, Object> sendMobileMsg(HttpServletRequest request) {
    try {

      List<UserMobileMsg> msgList = new ArrayList<UserMobileMsg>();

      String linksman = request.getParameter("linksman"); // 获取联系人
      String content = request.getParameter("content"); // 获取内容
      Integer type = Integer.parseInt(request.getParameter("sendType")); // 发送方式

      Date now = new Date();
      Date sendTime = now;
      if (type == 2) { // 定时发送

        if (StringUtils.isEmpty(request.getParameter("sendTime"))) {
          this.setJson(false, "定时发送时间不能为空", "");
          return json;
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        sendTime = df.parse(request.getParameter("sendTime")); // 定时发送时间
      }
      if (StringUtils.isNotEmpty(linksman) && StringUtils.isNotEmpty(content)) {
        // 验证手机
        Map<String, Object> returnMap = checkMobile(linksman);
        // 错误信息
        String errorMobile = returnMap.get("errorMobile").toString();
        if (Boolean.parseBoolean(returnMap.get("flag").toString()) == false) {
          this.setJson(false, errorMobile, "");
          return json;
        } else {
          // 添加发送记录
          JsonObject user = SingletonLoginUtils.getSysUser(request);
          UserMobileMsg userMobileMsg = new UserMobileMsg();
          userMobileMsg.setSendTime(sendTime);
          if (type == 1) { // 正常发送
            userMobileMsg.setStatus(1);
          } else { // 定时发送
            userMobileMsg.setStatus(2);
          }
          userMobileMsg.setId(0);
          userMobileMsg.setType(type);

          userMobileMsg.setContent(content);
          userMobileMsg.setMobile(returnMap.get("mobileList").toString());
          if (ObjectUtils.isNotNull(user)) {
            userMobileMsg.setUserId(user.get("userId").getAsLong());
          } else {
            userMobileMsg.setUserId(0L);
          }
          userMobileMsg.setCreateTime(now);
          msgList.add(userMobileMsg);
          // 添加记录 暂不发送
          userMobileMsgService.addUserMobileMsg(msgList);
          if (type == 1) { // 正常发送
            userMobileMsgService.batchSendMobileMsg(
                content, returnMap.get("mobileList").toString().split(","), 3);
          }
          errorMobile = "发送成功";
        }
        this.setJson(Boolean.parseBoolean(returnMap.get("flag").toString()), errorMobile, "");
      } else {
        this.setJson(false, "联系人或内容不能为空", null);
      }
    } catch (Exception e) {
      logger.error("sendMobileMsg", e);
    }
    return json;
  }