diff --git a/src/com/taobao/rigel/rap/account/bo/Notification.java b/src/com/taobao/rigel/rap/account/bo/Notification.java index c637b63..28a5628 100644 --- a/src/com/taobao/rigel/rap/account/bo/Notification.java +++ b/src/com/taobao/rigel/rap/account/bo/Notification.java @@ -8,6 +8,7 @@ public class Notification { private long id; private long userId; + private long targetUserId; private short typeId; private String param1; private String param2; @@ -15,6 +16,7 @@ public class Notification { private Date createTime; private boolean isRead; + public String getCreateTimeStr() { PrettyTime p = new PrettyTime(new Locale("zh")); return p.format(this.createTime); @@ -93,6 +95,17 @@ public User getUser() { public void setUser(User user) { this.user = user; } + + private User targetUser; + + + public User getTargetUser() { + return targetUser; + } + + public void setTargetUser(User targetUser) { + this.targetUser = targetUser; + } diff --git a/src/com/taobao/rigel/rap/account/dao/impl/AccountDaoImpl.java b/src/com/taobao/rigel/rap/account/dao/impl/AccountDaoImpl.java index 37b9647..6e172d1 100644 --- a/src/com/taobao/rigel/rap/account/dao/impl/AccountDaoImpl.java +++ b/src/com/taobao/rigel/rap/account/dao/impl/AccountDaoImpl.java @@ -224,6 +224,7 @@ public void readNotificationList(long userId) { getSession().createQuery(hql).setLong("userId", userId).executeUpdate(); } + @SuppressWarnings("unchecked") @Override public boolean notificationExists(Notification notification) { String hql = "from Notification where user.id = :userId and typeId = :typeId and param1 = :param1"; @@ -232,8 +233,17 @@ public boolean notificationExists(Notification notification) { query.setLong("userId", notification.getUser().getId()) .setShort("typeId", notification.getTypeId()) .setString("param1", notification.getParam1()); - int size = query.list().size(); - return size > 0; + List list =(List) query.list(); + int size = list.size(); + if (size > 0) { + for (Notification o : list) { + o.setCreateTime(new Date()); + session.update(o); + } + return true; + } else { + return false; + } } } diff --git a/src/com/taobao/rigel/rap/account/mapping/Notification.hbm.xml b/src/com/taobao/rigel/rap/account/mapping/Notification.hbm.xml index ef430c6..c123db2 100644 --- a/src/com/taobao/rigel/rap/account/mapping/Notification.hbm.xml +++ b/src/com/taobao/rigel/rap/account/mapping/Notification.hbm.xml @@ -3,28 +3,29 @@ "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> - - - - - - - - + + + + + + + + 项目相关ID - + 项目相关ID - + 创建时间 - - + + + diff --git a/src/com/taobao/rigel/rap/project/applicationContext.xml b/src/com/taobao/rigel/rap/project/applicationContext.xml index 9809c75..45a1116 100644 --- a/src/com/taobao/rigel/rap/project/applicationContext.xml +++ b/src/com/taobao/rigel/rap/project/applicationContext.xml @@ -4,6 +4,7 @@ + diff --git a/src/com/taobao/rigel/rap/project/bo/Project.java b/src/com/taobao/rigel/rap/project/bo/Project.java index 68931e4..5cecb1b 100644 --- a/src/com/taobao/rigel/rap/project/bo/Project.java +++ b/src/com/taobao/rigel/rap/project/bo/Project.java @@ -471,10 +471,10 @@ public void removeParameter(int id, Session session) { } } - public void addMember(User user) { + public boolean addMember(User user) { // if member added is the creator, ignore if (user.getId() == getUser().getId()) - return; + return false; // if member already exists, ignore boolean exist = false; for (User item : getUserList()) { @@ -482,10 +482,11 @@ public void addMember(User user) { exist = true; } } - if (exist) return; + if (exist) return false; // validation complete, add this user getUserList().add(user); user.getJoinedProjectList().add(this); + return true; } public void removeMember(User user) { diff --git a/src/com/taobao/rigel/rap/project/service/impl/ProjectMgrImpl.java b/src/com/taobao/rigel/rap/project/service/impl/ProjectMgrImpl.java index 98058bf..74eb4ea 100644 --- a/src/com/taobao/rigel/rap/project/service/impl/ProjectMgrImpl.java +++ b/src/com/taobao/rigel/rap/project/service/impl/ProjectMgrImpl.java @@ -5,8 +5,10 @@ import java.util.List; import java.util.Set; +import com.taobao.rigel.rap.account.bo.Notification; import com.taobao.rigel.rap.account.bo.User; import com.taobao.rigel.rap.account.dao.AccountDao; +import com.taobao.rigel.rap.account.service.AccountMgr; import com.taobao.rigel.rap.common.ArrayUtils; import com.taobao.rigel.rap.organization.bo.Group; import com.taobao.rigel.rap.organization.dao.OrganizationDao; @@ -22,6 +24,15 @@ public class ProjectMgrImpl implements ProjectMgr { private ProjectDao projectDao; private OrganizationDao organizationDao; + private AccountMgr accountMgr; + + public AccountMgr getAccountMgr() { + return accountMgr; + } + + public void setAccountMgr(AccountMgr accountMgr) { + this.accountMgr = accountMgr; + } public OrganizationDao getOrganizationDao() { return organizationDao; @@ -108,7 +119,16 @@ public int updateProject(Project outerProject) { for (String account : outerProject.getMemberAccountList()) { User user = accountDao.getUser(account); if (user != null) { - project.addMember(user); + 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); + } } } diff --git a/src/com/taobao/rigel/rap/project/web/action/ProjectAction.java b/src/com/taobao/rigel/rap/project/web/action/ProjectAction.java index 923e662..f83f6bd 100644 --- a/src/com/taobao/rigel/rap/project/web/action/ProjectAction.java +++ b/src/com/taobao/rigel/rap/project/web/action/ProjectAction.java @@ -326,7 +326,7 @@ public String update() { project.setId(getId()); project.setIntroduction(getDesc()); project.setName(getName()); - + project.setUser(getCurUser()); List memberAccountList = new ArrayList(); String[] list = getAccounts().split(","); // format: mashengbo(大灰狼堡森), linpanhui(林攀辉), diff --git a/src/com/taobao/rigel/rap/workspace/web/action/WorkspaceAction.java b/src/com/taobao/rigel/rap/workspace/web/action/WorkspaceAction.java index 31a416e..b7dd4b3 100644 --- a/src/com/taobao/rigel/rap/workspace/web/action/WorkspaceAction.java +++ b/src/com/taobao/rigel/rap/workspace/web/action/WorkspaceAction.java @@ -379,13 +379,24 @@ public String checkIn() throws Exception { // notification for doc change + for (User user : project.getUserList()) { + Notification notification = new Notification(); + notification.setParam1(new Integer(id).toString()); + notification.setParam2(project.getName()); + notification.setTypeId((short)1); + notification.setTargetUser(getCurUser()); + notification.setUser(user); + getAccountMgr().addNotification(notification); + } + Notification notification = new Notification(); notification.setParam1(new Integer(id).toString()); notification.setParam2(project.getName()); notification.setTypeId((short)1); - notification.setUser(getCurUser()); + notification.setTargetUser(getCurUser()); + notification.setUser(project.getUser()); getAccountMgr().addNotification(notification); - + // generate one check-in of VSS mode submit CheckIn checkIn = new CheckIn(); checkIn.setCreateDate(new Date()); diff --git a/src/database/create-table.sql b/src/database/create-table.sql index 5d5cbbd..a574a60 100644 --- a/src/database/create-table.sql +++ b/src/database/create-table.sql @@ -329,10 +329,11 @@ CREATE TABLE tb_notification ( id int(10) AUTO_INCREMENT NOT NULL PRIMARY KEY, - user_id int(10) NOT NULL, - type_id smallint NOT NULL, -- 1-project, - param1 varchar(128) NULL, -- 对应operator - param2 varchar(128) NULL, + user_id int(10) NOT NULL, -- 接受通知的用户id + target_user_id int(10) NOT NULL, -- 上下文用户id + type_id smallint NOT NULL, -- 1-文档修改,2-被加入新项目 + param1 varchar(128) NULL, -- 1,2-项目id + param2 varchar(128) NULL, -- 1,2-项目名称 param3 text NULL, create_time timestamp NOT NULL DEFAULT now(), @@ -340,7 +341,8 @@ CREATE TABLE tb_notification is_read smallint NOT NULL DEFAULT 0, - FOREIGN KEY(user_id) REFERENCES tb_user(id) + FOREIGN KEY(user_id) REFERENCES tb_user(id), + FOREIGN KEY(target_user_id) REFERENCES tb_user(id) )ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE tb_corporation diff --git a/src/database/update.v0.9.sql b/src/database/update.v0.9.sql index 4a115da..03a8bad 100644 --- a/src/database/update.v0.9.sql +++ b/src/database/update.v0.9.sql @@ -23,4 +23,9 @@ CREATE TABLE tb_notification DEFAULT 0, FOREIGN KEY(user_id) REFERENCES tb_user(id) -)ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file +)ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +-- add target_user_id +ALTER TABLE tb_notification +ADD COLUMN target_user_id int(10) NOT NULL