/**
   * <b>[WebAction]</b> <br>
   * 收到的消息
   */
  public ActionForward pageMessageReceivedIndex(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    try {
      ModelShortMessage formEntity = (ModelShortMessage) form;

      PagingBean pagingBean = this.getPagingBean(request);
      PaginationSupport<ModelInMessage> inMsgs =
          this.serviceInMessage.getPaginationByUser(
              ContextUtil.getCurrentUser().getEmployee().getId(),
              formEntity,
              request.getParameter("readFlag"),
              pagingBean);

      request.setAttribute("dataList", inMsgs);
      request.setAttribute("formEntity", formEntity);
      request.setAttribute("readFlag", request.getParameter("readFlag"));

      // 首页我的消息加载视图渲染...
      if (request.getParameter("objOut") != null) {
        response.getWriter().write(ObjectToString(inMsgs));
        return null;
      }

      // 输出分页信息至客户端
      outWritePagination(request, pagingBean, inMsgs);

      return mapping.findForward("page.info.msg.index");
    } catch (Exception e) {
      LOGGER.error("Exception raised when open my received message page..", e);
      return ajaxPrint(response, getErrorCallback("页面加载失败:" + e.getMessage()));
    }
  }
  /**
   * <b>[WebAction]</b> <br>
   * 获取未读短消息数
   */
  public ActionForward actionObtainMyUnreadMessageNum(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    try {
      int msgCount = 0;

      if (ContextUtil.getCurrentUser().getEmployee() != null) {
        msgCount =
            this.serviceInMessage.getUnreadMessageCountByUser(
                ContextUtil.getCurrentUser().getEmployee().getId());
      } else {
        LOGGER.error("Only employee can obtain my unread message number.");
      }

      return ajaxPrint(response, String.valueOf(msgCount));
    } catch (Exception e) {
      LOGGER.error("Exception raised when getting unread message count.", e);
      return ajaxPrint(response, "0");
    }
  }
  /**
   * Obtains my interviews with the specified status.
   *
   * @param status
   * @return
   */
  private PaginationSupport<ModelHrmJobHireInterview> getMyInterviewsByStatus(
      Integer[] status, PagingBean pagingBean) throws Exception {
    ModelAppUser user = ContextUtil.getCurrentUser();
    if (user != null) {
      try {
        return this.serviceHrmJobHireInterview.getPaginationByInterviewerAndStatus(
            user.getId(), status, pagingBean);
      } catch (ServiceException e) {
        LOGGER.error("Exception raised when obtaining the interview with owner and status.", e);

        throw new Exception(e);
      }
    } else {
      throw new Exception("用户Session不存在, 请登录后再进行操作.");
    }
  }
  /**
   * <b>[WebAction]</b> <br>
   * 发送的消息
   */
  public ActionForward pageMessageSentIndex(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    try {
      PagingBean pagingBean = this.getPagingBean(request);
      PaginationSupport<ModelShortMessage> sentMsgs =
          this.serviceShortMessage.getPaginationByUser(
              ContextUtil.getCurrentUser().getEmployee().getId(), pagingBean);

      request.setAttribute("dataList", sentMsgs);

      // 输出分页信息至客户端
      outWritePagination(request, pagingBean, sentMsgs);

      request.setAttribute("mailSent", "true");

      return mapping.findForward("page.info.msg.index");
    } catch (Exception e) {
      LOGGER.error("Exception raised when open my sent message page..", e);
      return ajaxPrint(response, getErrorCallback("页面加载失败:" + e.getMessage()));
    }
  }
  /**
   * <b>[WebAction]</b> <br>
   * 消息详细页面
   */
  public ActionForward dialogMessagePage(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    String msgId = request.getParameter("msgId");

    if (UtilString.isNotEmpty(msgId)) {
      if (this.isObjectIdValid(msgId)) {
        try {
          ModelShortMessage entity = this.serviceShortMessage.get(msgId);
          if (entity != null) {
            String msgInId = request.getParameter("msgInId");
            if (UtilString.isNotEmpty(msgInId)) {
              if (this.isObjectIdValid(msgInId)) {
                ModelInMessage msgIn = this.serviceInMessage.get(msgInId);
                if (msgIn == null) {
                  return ajaxPrint(response, getErrorCallback("消息不存在或者已删除..."));
                } else {
                  if (msgIn.getReadFlag().equals(ModelInMessage.FLAG_UNREAD)) {
                    msgIn.setReadFlag(ModelInMessage.FLAG_READ);
                    this.serviceInMessage.save(msgIn);

                    ModelAppUser user = this.serviceAppUser.get(String.valueOf(msgIn.getUserId()));
                    if (user != null) {
                      // 消息推送, 减少消息提醒数量
                      this.messagePush.pushMessage(
                          user.getEmployeeId(),
                          WebActionUtil.scriptMessageNotify,
                          WebActionUtil.scriptArgMessageKey,
                          -1);
                    }
                  }
                }
              } else {
                return ajaxPrint(response, getErrorCallback("需传入合法的接收消息Id..."));
              }
            }

            request.setAttribute("entity", entity);

            // 回复动作.
            String action = request.getParameter("op");
            if (UtilString.isNotEmpty(action) && "reply".equalsIgnoreCase(action)) {
              request.setAttribute("reply", true);

              ModelHrmEmployee employee =
                  this.serviceHrmEmployee.get(String.valueOf(entity.getSenderId()));
              if (employee != null) {
                StringBuilder receiver = new StringBuilder();
                receiver.append("[");
                receiver.append(
                    "{\"id\":\""
                        + employee.getId()
                        + "\", \"empName\":\""
                        + employee.getEmpName()
                        + "\", \"empNo\":\""
                        + employee.getEmpNo()
                        + "\"}");
                receiver.append("]");
                request.setAttribute("receiver", receiver.toString());
              }
            }
          } else {
            return ajaxPrint(response, getErrorCallback("消息(id:" + msgId + ")不存在..."));
          }
        } catch (Exception e) {
          LOGGER.error("Exception raised when open the dialog page of message.", e);
          return ajaxPrint(response, getErrorCallback("页面加载失败:" + e.getMessage()));
        }
      } else {
        return ajaxPrint(response, getErrorCallback("您传入的消息Id不合法..."));
      }

      request.setAttribute("msgId", msgId);
    } else {

      // 填充短消息内容...
      String msgSubject = request.getParameter("msubject");
      if (UtilString.isNotEmpty(msgSubject)) {
        if (msgSubject.indexOf("msg.subject.conference") == -1) {
          request.setAttribute("subject", this.getMessageFromResource(request, msgSubject, null));
        } else {
          String conferenceName = null;
          String mid = request.getParameter("mid");
          if (this.isObjectIdValid(mid)) {
            try {
              ModelConference conference = this.serviceConference.get(mid);
              if (conference != null) {
                conferenceName = conference.getConferenceName();

                ModelHrmEmployee employee = conference.getSponsor().getEmployee();

                StringBuilder receiver = new StringBuilder();
                receiver.append("[");
                receiver.append(
                    "{\"id\":\""
                        + employee.getId()
                        + "\", \"empName\":\""
                        + employee.getEmpName()
                        + "\", \"empNo\":\""
                        + employee.getEmpNo()
                        + "\"}");

                // Temporary solution and it should be enhanced in the future.
                // (Regarding to the entity field not defined employee object).
                List<ModelHrmEmployee> contractor =
                    this.serviceHrmEmployee.findByFullName(conference.getContactor());
                if (contractor != null && contractor.size() > 0) {
                  receiver.append(",");
                  receiver.append(
                      "{\"id\":\""
                          + contractor.get(0).getId()
                          + "\", \"empName\":\""
                          + contractor.get(0).getEmpName()
                          + "\"}");
                  receiver.append("]");
                } else {
                  receiver.append("]");
                }

                request.setAttribute("receiver", receiver.toString());
              }
            } catch (Exception e) {
              LOGGER.error("Exception raised when fetching conference object.", e);
            }
          }

          request.setAttribute(
              "subject",
              this.getMessageFromResource(
                  request,
                  msgSubject,
                  new Object[] {
                    ContextUtil.getCurrentUser().getEmployee().getEmpName(), conferenceName
                  }));
        }

        String msgBody = request.getParameter("mbody");
        if (UtilString.isNotEmpty(msgBody)) {
          request.setAttribute("body", this.getMessageFromResource(request, msgBody));
        }
      }

      try {
        // 设置为个人消息发送
        request.setAttribute("msgType", ModelShortMessage.EMessageType.TYPE_PERSONAL.getValue());

        this.loadOrganizationTree(request);
      } catch (Exception e) {
        LOGGER.error("Exception raised when open the dialog page of message..", e);
        return ajaxPrint(response, getErrorCallback("页面加载失败: " + e.getMessage()));
      }
    }

    return mapping.findForward("dialog.info.msg.page");
  }