@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; }
@Override public List<Corporation> getCorporationListWithPager(int pageNum, int pageSize) { List<Corporation> list = organizationDao.getCorporationListWithPager(pageNum, pageSize); for (Corporation c : list) { long memberNum = organizationDao.getMemberNumOfCorporation(c.getId()); c.setMemberNum(memberNum + 1); // +1 project creator c.setHasAccess(true); c.setCreatorName(accountMgr.getUser(c.getUserId()).getName()); } return list; }
@Override public int removeProject(int id) { Project p = getProject(id); Group g = organizationDao.getGroup(p.getGroupId()); int result = projectDao.removeProject(id); if (g != null) { int pId = g.getProductionLineId(); if (pId > 0) { organizationDao.updateCountersInProductionLine(pId); } } return result; }
@Override public int addTeam(Corporation team) { int corpId = organizationDao.addCorporation(team); for (String account : team.getAccountList()) { if (account == null || account.trim().isEmpty()) continue; User u = accountMgr.getUser(account); if (u.getId() == team.getUserId()) { // if the user is creator, there's no need to add again continue; } organizationDao.addUserToCorp(corpId, u.getId(), 3); // 3, normal member } return corpId; }
@Override public List<Corporation> getCorporationListWithPager(long userId, int pageNum, int pageSize) { User user = accountMgr.getUser(userId); if (user.isAdmin()) { return getCorporationListWithPager(pageNum, pageSize); } List<Corporation> list = organizationDao.getCorporationListWithPager(userId, pageNum, pageSize); for (Corporation c : list) { long memberNum = organizationDao.getMemberNumOfCorporation(c.getId()); c.setMemberNum(memberNum + 1); // +1 project creator c.setHasAccess(canUserManageCorp(userId, c.getId())); c.setCreatorName(accountMgr.getUser(c.getUserId()).getName()); } return list; }
@Override public boolean addTeamMembers(long curUserId, int corpId, String accountList) { if (!canUserManageCorp(curUserId, corpId)) return false; String[] accs = accountList.split(","); Corporation c = getCorporation(corpId); for (String acc : accs) { User u = accountMgr.getUser(acc); if (u != null) { if (!organizationDao.isUserInCorp(u.getId(), corpId) && u.getId() != c.getUserId()) { organizationDao.addUserToCorp(corpId, u.getId(), 3); } } } return true; }
@Override public long getCorporationListWithPagerNum(long userId) { User user = accountMgr.getUser(userId); if (user.isAdmin()) { return getCorporationListWithPagerNum(); } return organizationDao.getCorporationListWithPagerNum(userId); }
@Override public boolean canUserAccessCorp(long userId, int corpId) { Corporation c = getCorporation(corpId); if (c == null) return false; if (c.getUserId() == userId) return true; User user = accountMgr.getUser(userId); if (user != null && user.isAdmin()) return true; return organizationDao.isUserInCorp(userId, corpId); }
@Override public boolean setUserRoleInCorp(long curUserId, long userId, int corpId, int roleId) { if (canUserManageUserInCorp(curUserId, userId, corpId)) { organizationDao.setUserRoleInCorp(userId, corpId, roleId); return true; } else { return false; } }
@Override public RapError removeProductionLine(int productionLineId) { if (!productionLineCanBeDeleted(productionLineId)) { return new RapError(RapError.ERR_HAS_CHILDREN, "为确保您的数据安全,请先删除业务线下的分组及项目,再删除该业务线。"); } else { organizationDao.removeProductionLine(productionLineId); return new RapError(); } }
@Override public RapError removeGroup(int groupId) { if (!groupCanBeDeleted(groupId)) { return new RapError(RapError.ERR_HAS_CHILDREN, "为确保您的数据安全,请先删除分组下的项目,再删除该分组。"); } else { organizationDao.removeGroup(groupId); return new RapError(); } }
@Override public boolean removeMemberFromCorp(long curUserId, long userId, int corpId) { int roleId = getUserRoleInCorp(userId, corpId); // if user can't manage team, or the user to be deleted is super admin, failed if (!canUserManageCorp(curUserId, corpId) || roleId == 1) { return false; } organizationDao.deleteMembershipFromCorp(curUserId, userId, corpId); return true; }
@Override public List<User> getUserLisOfCorp(int corpId) { List<User> list = organizationDao.getUserLisOfCorp(corpId); Corporation c = getCorporation(corpId); User u = accountMgr.getUser(c.getUserId()); list.add(u); for (User user : list) { int roleId = getUserRoleInCorp(user.getId(), corpId); if (user.isAdmin()) { roleId = 1; // user is the RAP platform admin } else if (user.getId() == c.getUserId()) { roleId = 1; // user is the author } user.setRoleId(roleId); } return list; }
@Override public List<ProductionLine> getProductionLineList(int corpId) { return organizationDao.getProductionLineList(corpId); }
@Override public List<Group> getGroupList(int productionLineId) { return organizationDao.getGroupList(productionLineId); }
@Override public long getCorporationListWithPagerNum() { return organizationDao.getCorporationListWithPagerNum(); }
@Override public int addGroup(Group group) { return organizationDao.addGroup(group); }
@Override public List<Corporation> getCorporationList() { return organizationDao.getCorporationList(); }
@Override public int addProductionLine(ProductionLine productionLine) { return organizationDao.addProductionLine(productionLine); }
@Override public void updateGroup(Group group) { organizationDao.updateGroup(group); }
@Override public void updateCorporation(Corporation c) { organizationDao.updateCorporation(c); }
@Override public void updateProductionLine(ProductionLine productionLine) { organizationDao.updateProductionLine(productionLine); }
@Override public ProductionLine getProductionLine(int plid) { return organizationDao.getProductionLine(plid); }
@Override public Corporation getCorporation(int id) { return organizationDao.getCorporation(id); }
@Override public int getUserRoleInCorp(long userId, int corpId) { return organizationDao.getUserRoleInCorp(userId, corpId); }
@Override public boolean canUserManageCorp(long userId, int corpId) { int roleId = organizationDao.getUserRoleInCorp(userId, corpId); return (roleId >= 1 && roleId <= 2 || userId == getCorporation(corpId).getUserId()) || accountMgr.getUser(userId).isAdmin(); }