Exemplo n.º 1
0
 public String getNotificationList() {
   if (!isUserLogined()) {
     plsLogin();
     return LOGIN;
   }
   List<Notification> list = getAccountMgr().getNotificationList(getCurUserId());
   List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
   for (Notification o : list) {
     Map<String, Object> m = new HashMap<String, Object>();
     m.put("id", o.getId());
     m.put("param1", o.getParam1());
     m.put("param2", o.getParam1());
     m.put("param3", o.getParam1());
     Map<String, Object> user = new HashMap<String, Object>();
     user.put("name", o.getUser().getName());
     user.put("id", o.getUser().getId());
     m.put("user", user);
     m.put("createTime", o.getCreateTime().getTime());
     m.put("typeId", o.getTypeId());
     result.add(m);
   }
   Gson gson = new Gson();
   String json = gson.toJson(result);
   setJson(json);
   return SUCCESS;
 }
Exemplo n.º 2
0
  @Override
  public int addProject(Project project) {
    project.setUpdateTime(new Date());
    project.setCreateDate(new Date());
    List<User> usersInformed = new ArrayList<User>();
    for (String account : project.getMemberAccountList()) {
      User user = accountDao.getUser(account);
      if (user != null) {
        boolean addSuccess = project.addMember(user);
        if (addSuccess) {
          usersInformed.add(user);
        }
      }
    }
    int result = projectDao.addProject(project);
    for (User u : usersInformed) {
      Notification o = new Notification();
      o.setTypeId((short) 2);
      o.setTargetUser(project.getUser());
      o.setUser(u);
      o.setParam1(new Integer(result).toString());
      o.setParam2(project.getName());
      accountMgr.addNotification(o);
    }

    Group g = organizationDao.getGroup(project.getGroupId());
    if (g.getProductionLineId() > 0) {
      organizationDao.updateCountersInProductionLine(g.getProductionLineId());
    }

    return result;
  }
Exemplo n.º 3
0
  @Override
  public int updateProject(Project outerProject) {
    Project project = getProject(outerProject.getId());
    project.setName(outerProject.getName());
    project.setIntroduction(outerProject.getIntroduction());
    project.setUpdateTime(new Date());

    if (outerProject.getMemberAccountList() != null) {
      // adding new ones
      for (String account : outerProject.getMemberAccountList()) {
        User user = accountDao.getUser(account);
        if (user != null) {
          boolean addSuccess = project.addMember(user);
          if (addSuccess) {
            Notification o = new Notification();
            o.setTypeId((short) 2);
            o.setTargetUser(outerProject.getUser());
            o.setUser(user);
            o.setParam1(new Integer(outerProject.getId()).toString());
            o.setParam2(outerProject.getName());
            accountMgr.addNotification(o);
          }
        }
      }

      if (project.getUserList() != null) {
        // remove old ones
        List<User> userListToBeRemoved = new ArrayList<User>();
        for (User user : project.getUserList()) {
          if (!outerProject.getMemberAccountList().contains(user.getAccount())) {
            userListToBeRemoved.add(user);
          }
        }

        for (User user : userListToBeRemoved) {
          project.removeMember(user);
        }
      }
    }

    return projectDao.updateProject(project);
  }
Exemplo n.º 4
0
  public String getUnreadNotificationList() {
    if (!isUserLogined()) {
      plsLogin();
      return LOGIN;
    }

    String[] cacheKey =
        new String[] {CacheUtils.KEY_NOTIFICATION, new Integer(getCurUserId()).toString()};

    String cache = CacheUtils.get(cacheKey);
    if (cache != null) {
      setJson(cache);
    } else {

      List<Notification> list = getAccountMgr().getUnreadNotificationList(getCurUserId());
      List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
      for (Notification o : list) {
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("id", o.getId());
        m.put("param1", o.getParam1());
        m.put("param2", o.getParam2());
        m.put("param3", o.getParam3());

        Map<String, Object> user = new HashMap<String, Object>();
        user.put("name", o.getUser().getName());
        user.put("id", o.getUser().getId());
        m.put("user", user);

        Map<String, Object> targetUser = new HashMap<String, Object>();
        targetUser.put("name", o.getTargetUser().getName());
        targetUser.put("id", o.getTargetUser().getId());

        m.put("targetUser", targetUser);

        m.put("createTime", o.getCreateTime().getTime());
        m.put("createTimeStr", o.getCreateTimeStr());
        m.put("typeId", o.getTypeId());
        result.add(m);
      }
      Gson gson = new Gson();
      String json = gson.toJson(result);
      setJson(json);
      CacheUtils.put(cacheKey, json, 60 * 10);
    }
    return SUCCESS;
  }