Пример #1
0
  /**
   * 查询用户消息列表接口 消息列表:同步返回每个用户的已读回执 公告列表:只需要返回公告标题和内容,不需要返回已读回执,已读回执在详情页展示 CustomDocinfo.java
   *
   * @param id
   * @param user_type 0:发送用户;1:接收用户;其他:全部
   * @param notice_type 0:公告;1:消息;公告获取全部, 消息只能获取自己发送或接受到的消息
   * @param if_read 是否已读;0:未读;1:已读 2015年6月15日
   */
  public static ResultInfo getNoticeList(
      Integer user_id,
      Integer notice_type,
      Integer if_read,
      String keywords,
      Integer p,
      Integer ps,
      Request request) {
    ResultInfo info = new ResultInfo();
    AndroidUserInfo androidUserInfo = AndroidUserInfo.findById(user_id);
    if (androidUserInfo == null) {
      info.setCodeAndMsg(400);
      info.setRequest(request.path);
      return info;
    }
    if (keywords != null && keywords.length() > 0) { // 首先将keyword去空格
      keywords = keywords.replaceAll(" ", ""); // 半角空格
      if (keywords != null && keywords.length() > 0) {
        keywords = keywords.replaceAll(" ", ""); // 全角空格
      }
    }

    List<AndroidNoticeInfo> androidNoticeInfoList = new ArrayList<AndroidNoticeInfo>();
    //	    if (notice_type == 0) {//公告
    List<AndroidReceiveNoticeUser> androidReceiveNoticeUserList = null;
    String notice_ids = "";
    if (if_read == null || if_read > 1) { // 获取全部公告
      //	    		androidNoticeInfoList = AndroidNoticeInfo.find(" notice_type = ? order by id desc",
      // notice_type).fetch(p, ps);
      // 查询本人接收的所有公告
      androidReceiveNoticeUserList =
          AndroidReceiveNoticeUser.findByNoticeTypeAndUser(
              notice_type, user_id /*, p, ps,keywords*/);
    } else {
      // 查询本人接收的所有公告
      androidReceiveNoticeUserList =
          AndroidReceiveNoticeUser.findByNoticeTypeAndUserAndIfRead(
              notice_type, user_id, if_read /*, p, ps,keywords*/);
    }
    if (androidReceiveNoticeUserList != null && androidReceiveNoticeUserList.size() > 0) {
      for (AndroidReceiveNoticeUser androidReceiveNoticeUser : androidReceiveNoticeUserList) {
        if (androidReceiveNoticeUser != null) {
          notice_ids += androidReceiveNoticeUser.notice_id;
          notice_ids += ",";
        }
      }
    }
    if (notice_ids.endsWith(",")) {
      notice_ids = notice_ids.substring(0, notice_ids.length() - 1);
    }
    if (keywords != null && keywords.length() > 0) {
      if (notice_ids.length() > 0) {
        androidNoticeInfoList =
            AndroidNoticeInfo.find(
                    " title LIKE '%"
                        + keywords
                        + "%' AND (id IN ("
                        + notice_ids
                        + ") or (notice_type = ? and push_user_id = ? )) "
                        + " group by id order by id desc",
                    notice_type,
                    user_id)
                .fetch(p, ps);
      } else {
        androidNoticeInfoList =
            AndroidNoticeInfo.find(
                    " title LIKE '%"
                        + keywords
                        + "%' AND (notice_type = ? and push_user_id = ?) "
                        + " group by id order by id desc",
                    notice_type,
                    user_id)
                .fetch(p, ps);
      }
    } else {
      if (notice_ids.length() > 0) {
        androidNoticeInfoList =
            AndroidNoticeInfo.find(
                    " id IN ("
                        + notice_ids
                        + ") or (notice_type = ? and push_user_id = ? ) "
                        + " group by id order by id desc",
                    notice_type,
                    user_id)
                .fetch(p, ps);
      } else {
        androidNoticeInfoList =
            AndroidNoticeInfo.find(
                    " notice_type = ? and push_user_id = ? " + " group by id order by id desc",
                    notice_type,
                    user_id)
                .fetch(p, ps);
      }
    }

    //	    }else {// 消息只能获取自己发送或接受到的消息
    //
    //	    	if (if_read == null || if_read > 0) {//全部消息
    //	    		List<AndroidReceiveNoticeUser> androidReceiveNoticeUserList = AndroidReceiveNoticeUser
    //				.find("notice_type = ? AND (receive_user_id = ? OR push_user_id = ? OR "
    //					+ "(receive_user_id = 0 AND receive_user_type = 1) OR "
    //					+ "(receive_user_id = 0 AND receive_user_type = 2 AND department_id = ?))"
    //				+ "group by notice_id  order by id desc",notice_type, user_id,
    //				user_id,androidUserInfo.department_id).fetch(p,ps);
    //
    //				//获取消息编号列表
    //				String noticeIds = "";
    //				if (androidReceiveNoticeUserList != null && androidReceiveNoticeUserList.size() > 0) {
    //				    for (AndroidReceiveNoticeUser androidReceiveNoticeUser : androidReceiveNoticeUserList)
    // {
    //					if (androidReceiveNoticeUser != null) {
    //					    noticeIds += androidReceiveNoticeUser.notice_id;
    //					    noticeIds += ",";
    //					}
    //				    }
    //				}
    //				if (noticeIds.endsWith(",")) {
    //				    noticeIds = noticeIds.substring(0, noticeIds.length() - 1);
    //				}
    //				if (noticeIds.length() > 0) {
    //				    androidNoticeInfoList = AndroidNoticeInfo.find("id IN (" + noticeIds + ") order by
    // create_time desc").fetch();
    //				}
    //			}else {
    //				List<AndroidReceiveNoticeUser> androidReceiveNoticeUserList = AndroidReceiveNoticeUser
    //				.find("notice_type = ? AND if_read = ? AND (receive_user_id = ? OR push_user_id = ? OR "
    //					+ "(receive_user_id = 0 AND receive_user_type = 1) OR "
    //					+ "(receive_user_id = 0 AND receive_user_type = 2 AND department_id = ?))"
    //				+ "group by notice_id  order by id desc",notice_type,if_read, user_id,
    //				user_id,androidUserInfo.department_id).fetch(p,ps);
    //
    //				//获取消息编号列表
    //				String noticeIds = "";
    //				if (androidReceiveNoticeUserList != null && androidReceiveNoticeUserList.size() > 0) {
    //				    for (AndroidReceiveNoticeUser androidReceiveNoticeUser : androidReceiveNoticeUserList)
    // {
    //					if (androidReceiveNoticeUser != null) {
    //					    noticeIds += androidReceiveNoticeUser.notice_id;
    //					    noticeIds += ",";
    //					}
    //				    }
    //				}
    //				if (noticeIds.endsWith(",")) {
    //				    noticeIds = noticeIds.substring(0, noticeIds.length() - 1);
    //				}
    //				if (noticeIds.length() > 0) {
    //				    androidNoticeInfoList = AndroidNoticeInfo.find("id IN (" + noticeIds + ") order by
    // create_time desc").fetch();
    //				}
    //			}
    //
    //
    //	    }

    // 取消息已读未读状态
    if (androidNoticeInfoList != null && androidNoticeInfoList.size() > 0) {
      //		    String receive_user_names = "";
      //		    receive_user_names += androidReceiveNoticeUser.receive_user_name;
      //		    receive_user_names += ",";
      //
      //		if (receive_user_names.endsWith(",")) {
      //		    receive_user_names = receive_user_names.substring(0, news_ids.length() - 1);
      //		}
      //		for (AndroidNoticeInfo androidNoticeInfo : androidNoticeInfoList) {
      //		    String create_time_string = DateUtil.date2String(androidNoticeInfo.create_time,
      // "yyyy-MM-dd HH:mm:ss");
      //
      //		    try {
      //			androidNoticeInfo.create_time = DateUtil.string2UtilDate(create_time_string, "yyyy-MM-dd
      // HH:mm:ss");
      //		    } catch (Exception e) {
      //			// TODO Auto-generated catch block
      //			e.printStackTrace();
      //		    }
      //
      //		}

      for (AndroidNoticeInfo androidNoticeInfo : androidNoticeInfoList) {
        if (androidNoticeInfo != null) {
          if (androidNoticeInfo.push_user_id != user_id) { // 如果本人是接收人,取已读未读状态
            AndroidReceiveNoticeUser androidReceiveNoticeUser =
                AndroidReceiveNoticeUser.findByNoticeAndUser(androidNoticeInfo.id, user_id);
            if (androidReceiveNoticeUser != null) {
              androidNoticeInfo.if_read = androidReceiveNoticeUser.if_read;
            } else {
              androidNoticeInfo.if_read = 1;
            }
          } else { // 本人发送的公告消息默认为已读
            androidNoticeInfo.if_read = 1;
          }
          androidNoticeInfo.create_time_string =
              DateUtil.date2String(androidNoticeInfo.create_time, "yyyy-MM-dd HH:mm:ss");
          String create_time_string =
              DateUtil.date2String(androidNoticeInfo.create_time, "yyyy-MM-dd HH:mm:ss");
          try {
            androidNoticeInfo.create_time =
                DateUtil.string2UtilDate(create_time_string, "yyyy-MM-dd HH:mm:ss");
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
      info.setCodeAndMsg(200);
      info.setInfo(androidNoticeInfoList);
      info.setCount(androidNoticeInfoList.size());
      info.setRequest(request.path);

    } else {
      info.setCodeAndMsg(200);
      info.setInfo(androidNoticeInfoList);
      info.setRequest(request.path);
    }
    return info;
  }
Пример #2
0
  /**
   * 查询用户消息详情, 公告:对于发布人查看公告消息,同步返回已读和未读用户列表; 对于接收人查看公告消息,不返回已读和未读用户列表; CustomDocinfoService.java
   *
   * @param id
   * @param user_id 阅读人
   * @param request
   * @return 2015年6月15日
   */
  public static ResultInfo getNoticeInfo(Integer id, Integer user_id, Request request) {
    ResultInfo info = new ResultInfo();
    AndroidNoticeInfo androidNoticeInfo = AndroidNoticeInfo.findById(id);
    if (androidNoticeInfo == null) {
      info.setCodeAndMsg(12001);
      info.setRequest(request.path);
      return info;
    }
    // 修改已读标志
    AndroidReceiveNoticeUser receiveNoticeUser =
        AndroidReceiveNoticeUser.findByNoticeAndUser(id, user_id);
    if (receiveNoticeUser != null) {
      receiveNoticeUser.if_read = 1;
      receiveNoticeUser.read_time = new Date();
      receiveNoticeUser.save();
    }
    if (
    /*androidNoticeInfo.notice_type == 0 && */ androidNoticeInfo.push_user_id.equals(
        user_id)) { // 对于发布人查看公告消息,同步返回已读和未读用户列表;
      // 取公告已读接收人记录
      List<AndroidReceiveNoticeUser> androidReceiveNoticeUserList =
          AndroidReceiveNoticeUser.find(
                  "notice_id = ? and receive_user_id != ? and if_read = 1",
                  id,
                  androidNoticeInfo.push_user_id)
              .fetch();
      String receive_user_ids = "";
      String receive_user_names = "";
      if (androidReceiveNoticeUserList != null && androidReceiveNoticeUserList.size() > 0) {
        for (AndroidReceiveNoticeUser androidReceiveNoticeUser : androidReceiveNoticeUserList) {
          if (androidReceiveNoticeUser != null) {
            receive_user_ids += androidReceiveNoticeUser.receive_user_id;
            receive_user_ids += ",";
            receive_user_names += androidReceiveNoticeUser.receive_user_name;
            receive_user_names += ",";
          }
        }
      }
      if (receive_user_ids.endsWith(",")) {
        receive_user_ids = receive_user_ids.substring(0, receive_user_ids.length() - 1);
      }
      if (receive_user_names.endsWith(",")) {
        receive_user_names = receive_user_names.substring(0, receive_user_names.length() - 1);
      }
      androidNoticeInfo.receive_user_ids = receive_user_ids;
      androidNoticeInfo.receive_user_names = receive_user_names;

      // 取公告未读接收人记录
      List<AndroidReceiveNoticeUser> unReadAndroidReceiveNoticeUserList =
          AndroidReceiveNoticeUser.find(
                  "notice_id = ? and receive_user_id != ? and if_read = 0",
                  id,
                  androidNoticeInfo.push_user_id)
              .fetch();
      String unreceive_user_ids = "";
      String unreceive_user_names = "";
      if (unReadAndroidReceiveNoticeUserList != null
          && unReadAndroidReceiveNoticeUserList.size() > 0) {
        for (AndroidReceiveNoticeUser androidReceiveNoticeUser :
            unReadAndroidReceiveNoticeUserList) {
          if (androidReceiveNoticeUser != null) {
            unreceive_user_ids += androidReceiveNoticeUser.receive_user_id;
            unreceive_user_ids += ",";
            unreceive_user_names += androidReceiveNoticeUser.receive_user_name;
            unreceive_user_names += ",";
          }
        }
      }
      if (unreceive_user_ids.endsWith(",")) {
        unreceive_user_ids = unreceive_user_ids.substring(0, unreceive_user_ids.length() - 1);
      }
      if (unreceive_user_names.endsWith(",")) {
        unreceive_user_names = unreceive_user_names.substring(0, unreceive_user_names.length() - 1);
      }
      //		if(receive_user_ids.equals("null")){
      //			receive_user_ids = "";
      //		}
      androidNoticeInfo.unreceive_user_ids = unreceive_user_ids;
      androidNoticeInfo.unreceive_user_names = unreceive_user_names;
    }

    androidNoticeInfo.create_time_string =
        DateUtil.date2String(androidNoticeInfo.create_time, "yyyy-MM-dd HH:mm:ss");
    String create_time_string =
        DateUtil.date2String(androidNoticeInfo.create_time, "yyyy-MM-dd HH:mm:ss");

    try {
      androidNoticeInfo.create_time =
          DateUtil.string2UtilDate(create_time_string, "yyyy-MM-dd HH:mm:ss");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    info.setCodeAndMsg(200);
    info.setInfo(androidNoticeInfo);
    info.setRequest(request.path);
    return info;
  }