jiapeng 7 ans auparavant
Parent
commit
37bf92954b

+ 16 - 0
src/main/java/com/ekexiu/portal/msg/ActorItem.java

@ -6,30 +6,46 @@ public class ActorItem {
6 6
	private String timeStr;
7 7
	private String cnt;
8 8
	private int num;
9
	/**
10
	 * @return 会话参与人ID
11
	 */
9 12
	public String getId() {
10 13
		return id;
11 14
	}
12 15
	public void setId(String id) {
13 16
		this.id = id;
14 17
	}
18
	/**
19
	 * @return 会话最近活动时间 UTC MilliSecond since UTC1970-01-01 00:00:00:000
20
	 */
15 21
	public long getTime() {
16 22
		return time;
17 23
	}
24

18 25
	public void setTime(long time) {
19 26
		this.time = time;
20 27
	}
28
	/**
29
	 * @return 会话最近活动时间 YYYYMMDDHH24MISSZZZ
30
	 */
21 31
	public String getTimeStr() {
22 32
		return timeStr;
23 33
	}
24 34
	public void setTimeStr(String timeStr) {
25 35
		this.timeStr = timeStr;
26 36
	}
37
	/**
38
	 * @return 会话最近活动内空
39
	 */
27 40
	public String getCnt() {
28 41
		return cnt;
29 42
	}
30 43
	public void setCnt(String cnt) {
31 44
		this.cnt = cnt;
32 45
	}
46
	/**
47
	 * @return 会话未读数
48
	 */
33 49
	public int getNum() {
34 50
		return num;
35 51
	}

+ 120 - 10
src/main/java/com/ekexiu/portal/msg/Service.java

@ -49,6 +49,8 @@ public class Service {
49 49
	public static ActorItem build(WebMsgIdx wmi, String owner, SimpleDateFormat sf) {
50 50
		ActorItem item = new ActorItem();
51 51
		item.setCnt(wmi.getLastCnt());
52
		item.setTime(wmi.getLastTime());
53
		item.setTimeStr(sf.format(new Date(wmi.getLastTime())));
52 54
		String actor = wmi.getActor();
53 55
		if (owner.equals(actor)) {
54 56
			item.setId(wmi.getOwner());
@ -57,8 +59,7 @@ public class Service {
57 59
			item.setId(actor);
58 60
			item.setNum(wmi.getNumOfActor());
59 61
		}
60
		item.setTime(wmi.getLastTime());
61
		item.setTimeStr(sf.format(new Date(wmi.getLastTime())));
62

62 63
		return item;
63 64
	}
64 65

@ -79,6 +80,15 @@ public class Service {
79 80
			throw new JfwBaseException(ERROR_OWNER_OR_ACTOR, "消息的参与人不合法");
80 81
	}
81 82

83
	/**
84
	 * 查询指定用户的未删除会话
85
	 * 
86
	 * @param con
87
	 * @param id
88
	 *            用户ID
89
	 * @return
90
	 * @throws SQLException
91
	 */
82 92
	@Get
83 93
	@Path("/idx/qm")
84 94
	public List<ActorItem> query(@JdbcConn Connection con, String id) throws SQLException {
@ -86,10 +96,20 @@ public class Service {
86 96
		return build(list, id);
87 97
	}
88 98

99
	/**
100
	 * 查询指定的未删除会话
101
	 * 
102
	 * @param con
103
	 * @param owner
104
	 *            会话所有人
105
	 * @param actor
106
	 *            会话参与人
107
	 * @return
108
	 * @throws SQLException
109
	 */
89 110
	@Get
90 111
	@Path("/idx/qo")
91
	public ActorItem query(@JdbcConn Connection con, String owner, String actor) throws SQLException, JfwBaseException {
92
		checkActors(owner, owner);
112
	public ActorItem query(@JdbcConn Connection con, String owner, String actor) throws SQLException {
93 113
		WebMsgIdx wmi = null;
94 114
		if (owner.compareTo(actor) < 0) {
95 115
			wmi = webMsgDao.query(con, owner, actor);
@ -103,6 +123,15 @@ public class Service {
103 123
		return null;
104 124
	}
105 125

126
	/**
127
	 * 查询指定用户的未删除会话(分页,最后活动时间倒序)
128
	 * 
129
	 * @param con
130
	 * @param id
131
	 *            用户ID
132
	 * @return
133
	 * @throws SQLException
134
	 */
106 135
	@Get
107 136
	@Path("/idx/pq")
108 137
	public PageQueryResult<ActorItem> query(@JdbcConn Connection con, String id, @DefaultValue("1") int pageNo, @DefaultValue("10") int pageSize)
@ -116,6 +145,15 @@ public class Service {
116 145
		return ret;
117 146
	}
118 147

148
	/**
149
	 * 查询指定用户的未读消息数
150
	 * 
151
	 * @param con
152
	 * @param id
153
	 *            用户id
154
	 * @return
155
	 * @throws SQLException
156
	 */
119 157
	@Get
120 158
	@Path("/unReadedCount")
121 159
	public Integer queryUnReadedCount(@JdbcConn Connection con, final String id) throws SQLException {
@ -139,9 +177,23 @@ public class Service {
139 177
				});
140 178
	}
141 179

180
	/**
181
	 * 发送消息
182
	 * 
183
	 * @param con
184
	 * @param sender
185
	 *            发送人ID
186
	 * @param reciver
187
	 *            接收人ID
188
	 * @param cnt
189
	 *            内容
190
	 * @return 发送时间(YYYYMMDDHH24MISSZZZ)
191
	 * @throws SQLException
192
	 * @throws JfwBaseException
193
	 */
142 194
	@Post
143 195
	@Path
144
	public void send(@JdbcConn Connection con, String sender, String reciver, String cnt) throws SQLException, JfwBaseException {
196
	public String send(@JdbcConn Connection con, String sender, String reciver, String cnt) throws SQLException, JfwBaseException {
145 197
		checkActors(sender, reciver);
146 198
		boolean ownerSend = true;
147 199
		String owner = sender;
@ -195,19 +247,69 @@ public class Service {
195 247
				throw e;
196 248
			}
197 249
		}
250
		return wmc.getSendTime();
198 251
	}
199 252

253
	/**
254
	 * 查询消息内容
255
	 * 
256
	 * @param con
257
	 * @param sender
258
	 *            发送人ID
259
	 * @param reciver
260
	 *            接收人ID
261
	 * @param bt
262
	 *            >=开始时间(YYYYMMDDHH24MISSZZZ)
263
	 * @param et
264
	 *            <=结束时间(YYYYMMDDHH24MISSZZZ)
265
	 * @param both
266
	 *            是否包含反向消息
267
	 * @return
268
	 * @throws SQLException
269
	 */
200 270
	@Get
201 271
	@Path("/cnt/load")
202
	public List<WebMsgCnt> load(@JdbcConn Connection con, String sender, String reciver, @Nullable String bt, @DefaultValue("true") boolean all)
203
			throws SQLException {
204
		if (all) {
205
			return webMsgDao.queryAll(con, sender, reciver, bt);
272
	public List<WebMsgCnt> load(@JdbcConn Connection con, String sender, String reciver, @Nullable String bt, @Nullable String et,
273
			@DefaultValue("false") boolean both) throws SQLException {
274
		if (both) {
275
			return webMsgDao.queryAll(con, sender, reciver, bt, et);
206 276
		} else {
207
			return webMsgDao.query(con, sender, reciver, bt);
277
			return webMsgDao.query(con, sender, reciver, bt, et);
208 278
		}
209 279
	}
210 280

281
	/**
282
	 * 倒序查询消息内容
283
	 * 
284
	 * @param con
285
	 * @param sender
286
	 *            发送人
287
	 * @param reciver
288
	 *            接收人
289
	 * @param sendTime
290
	 *            <最后发送时间
291
	 * @param rows
292
	 *            返加数据最大条数
293
	 * @param both
294
	 *            是否包含反向消息
295
	 * @return
296
	 * @throws SQLException
297
	 */
298
	@Get
299
	@Path("/cnt/deload")
300
	public List<WebMsgCnt> deLoad(@JdbcConn Connection con, String sender, String reciver, @Nullable String sendTime, @DefaultValue("10") int rows,
301
			@DefaultValue("false") boolean both) throws SQLException {
302
		return both ? webMsgDao.queryAll4Desc(con, sender, reciver, sendTime, rows) : webMsgDao.query4Desc(con, sender, reciver, sendTime, rows);
303
	}
304
/**
305
 * 置消息为已读
306
 * @param con
307
 * @param sender
308
 * @param reciver
309
 * @param time  <=send_time 
310
 * @throws SQLException
311
 * @throws JfwBaseException
312
 */
211 313
	@Post
212 314
	@Path("/readed")
213 315
	public void readed(@JdbcConn(true) Connection con, String sender, String reciver, String time) throws SQLException, JfwBaseException {
@ -230,6 +332,14 @@ public class Service {
230 332
		}
231 333
	}
232 334

335
	/**
336
	 * 删除会话
337
	 * @param con
338
	 * @param owner  要删除的会话的参与人ID
339
	 * @param actor    另一个参与人ID
340
	 * @throws SQLException
341
	 * @throws JfwBaseException
342
	 */
233 343
	@Post
234 344
	@Path("/disable/show")
235 345
	public void disableShow(@JdbcConn(true) Connection con, String owner, String actor) throws SQLException, JfwBaseException {

+ 2 - 2
src/main/java/com/ekexiu/portal/msg/WebMsgCnt.java

@ -35,14 +35,14 @@ public class WebMsgCnt {
35 35
	public void setSendTime(String sendTime) {
36 36
		this.sendTime = sendTime;
37 37
	}
38
	@Column(DE.id_32)
38
	@Column(DE.text_de)
39 39
	public String getSender() {
40 40
		return sender;
41 41
	}
42 42
	public void setSender(String sender) {
43 43
		this.sender = sender;
44 44
	}
45
	@Column(DE.id_32)
45
	@Column(DE.text_de)
46 46
	public String getReciver() {
47 47
		return reciver;
48 48
	}

+ 56 - 43
src/main/java/com/ekexiu/portal/msg/WebMsgDao.java

@ -2,7 +2,7 @@ package com.ekexiu.portal.msg;
2 2

3 3
import java.sql.Connection;
4 4
import java.sql.SQLException;
5
import java.util.List; 
5
import java.util.List;
6 6

7 7
import org.jfw.apt.annotation.Nullable;
8 8
import org.jfw.apt.orm.annotation.dao.DAO;
@ -12,12 +12,15 @@ import org.jfw.apt.orm.annotation.dao.method.OrderBy;
12 12
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
13 13
import org.jfw.apt.orm.annotation.dao.method.Where;
14 14
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
15
import org.jfw.apt.orm.annotation.dao.method.operator.LimitSelect;
15 16
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
16 17
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
17 18
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
18 19
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
20
import org.jfw.apt.orm.annotation.dao.param.Alias;
19 21
import org.jfw.apt.orm.annotation.dao.param.GroupSqlColumn;
20 22
import org.jfw.apt.orm.annotation.dao.param.GtEq;
23
import org.jfw.apt.orm.annotation.dao.param.LessThan;
21 24
import org.jfw.apt.orm.annotation.dao.param.LtEq;
22 25
import org.jfw.apt.orm.annotation.dao.param.Set;
23 26
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
@ -26,81 +29,91 @@ import org.jfw.util.PageQueryResult;
26 29
@DAO
27 30
public interface WebMsgDao {
28 31

29
	@Exclude({"showOfOwner","showOfActor"})
32
	@Exclude({ "showOfOwner", "showOfActor" })
30 33
	@SelectList
31 34
	@OrderBy("ORDER BY LAST_TIME DESC")
32 35
	List<WebMsgIdx> query(Connection con, @GroupSqlColumn(handlerClass = StringHandler.class, isAnd = false, value = { "OWNER=? AND SHOW_OF_OWNER='1'",
33
			"ACTOR=? AND SHOW_OF_ACTOR='1'" },force=false) String id) throws SQLException;
34
	
36
			"ACTOR=? AND SHOW_OF_ACTOR='1'" }, force = false) String id) throws SQLException;
37

35 38
	@SelectOne
36 39
	@Nullable
37
	WebMsgIdx query(Connection con,String owner,String actor)throws SQLException;
38
	
39
	@Exclude({"showOfOwner","showOfActor"})
40
	WebMsgIdx query(Connection con, String owner, String actor) throws SQLException;
41

42
	@Exclude({ "showOfOwner", "showOfActor" })
40 43
	@PageSelect
41
	@OrderBy("ORDER BY LAST_TIME DESC,OWNER ASC")
42
	PageQueryResult<WebMsgIdx>  query(Connection con, @GroupSqlColumn(handlerClass = StringHandler.class, isAnd = false, value = { "OWNER=? AND SHOW_OF_OWNER='1'",
43
	"ACTOR=? AND SHOW_OF_ACTOR='1'" },force=false) String id,int pageSize,int pageNo) throws SQLException;
44
	
45
	
46
	
47
	
48
	@Insert 
49
	int insert(Connection con,WebMsgCnt cnt)throws SQLException;
44
	@OrderBy("ORDER BY LAST_TIME DESC,OWNER DESC")
45
	PageQueryResult<WebMsgIdx> query(Connection con, @GroupSqlColumn(handlerClass = StringHandler.class, isAnd = false, value = {
46
			"OWNER=? AND SHOW_OF_OWNER='1'", "ACTOR=? AND SHOW_OF_ACTOR='1'" }, force = false) String id, int pageSize, int pageNo) throws SQLException;
47

50 48
	@Insert
51
	int insert(Connection con,WebMsgIdx idx)throws SQLException;
52
	
49
	int insert(Connection con, WebMsgCnt cnt) throws SQLException;
50

51
	@Insert
52
	int insert(Connection con, WebMsgIdx idx) throws SQLException;
53

53 54
	@UpdateWith
54 55
	@From(WebMsgIdx.class)
55 56
	@SetSentence("NUM_OF_ACTOR = NUM_OF_ACTOR + 1,SHOW_OF_ACTOR='1'")
56
	int incActorNum(Connection con,String owner,String actor,@Set String lastCnt,@Set long lastTime) throws SQLException;
57
	
58
	
59
	
57
	int incActorNum(Connection con, String owner, String actor, @Set String lastCnt, @Set long lastTime) throws SQLException;
58

60 59
	@UpdateWith
61 60
	@From(WebMsgIdx.class)
62 61
	@SetSentence("NUM_OF_OWNER = NUM_OF_OWNER + 1,SHOW_OF_OWNER='1'")
63
	int incOwnerNum(Connection con,String owner,String actor,@Set String lastCnt,@Set long lastTime) throws SQLException;
64
	
65
	
66
	
67
	
62
	int incOwnerNum(Connection con, String owner, String actor, @Set String lastCnt, @Set long lastTime) throws SQLException;
63

68 64
	@UpdateWith
69 65
	@From(WebMsgIdx.class)
70 66

71
	int decActorNum(Connection con,String owner,String actor,@Set("= NUM_OF_ACTOR - ?") int numOfActor) throws SQLException;
72
	
73
	
74
	
67
	int decActorNum(Connection con, String owner, String actor, @Set("= NUM_OF_ACTOR - ?") int numOfActor) throws SQLException;
68

75 69
	@UpdateWith
76 70
	@From(WebMsgIdx.class)
77
	int decOwnerNum(Connection con,String owner,String actor,@Set("= NUM_OF_OWNER - ?") int numOfOwner) throws SQLException;
71
	int decOwnerNum(Connection con, String owner, String actor, @Set("= NUM_OF_OWNER - ?") int numOfOwner) throws SQLException;
72

73
	@SelectList
74
	@OrderBy("ORDER BY SEND_TIME ASC")
75
	List<WebMsgCnt> query(Connection con, String sender, String reciver, @Nullable @GtEq @Alias("sendTime") String bt,
76
			@Nullable @LtEq @Alias("sendTime") String et) throws SQLException;
78 77
	
79 78
	
80
	@SelectList
81
	@OrderBy("ORDER BY SEND_TIME SEND_TIME ASC")
82
	List<WebMsgCnt> query(Connection con,String sender,String reciver,@Nullable @GtEq String sendTime)throws SQLException;
83 79
	
80
	@LimitSelect
81
	@OrderBy("ORDER BY SEND_TIME DESC")
82
	List<WebMsgCnt> query4Desc(Connection con, String sender, String reciver,@Nullable @LessThan String sendTime,int rows) throws SQLException;
83
	
84

84 85
	@SelectList
85
	@OrderBy("ORDER BY SEND_TIME SEND_TIME ASC")
86
	List<WebMsgCnt> queryAll(Connection con, @GroupSqlColumn(handlerClass = StringHandler.class, value = { "SENDER=?","RECIVER=?" },isAnd=false) String actor1,@GroupSqlColumn(handlerClass = StringHandler.class, value = { "SENDER=?","RECIVER=?" },isAnd=false) String actor2,@Nullable @GtEq String sendTime)throws SQLException;
86
	@OrderBy("ORDER BY SEND_TIME ASC")
87
	List<WebMsgCnt> queryAll(Connection con,
88
			@GroupSqlColumn(handlerClass = StringHandler.class, value = { "SENDER=?", "RECIVER=?" }, isAnd = false) String actor1,
89
			@GroupSqlColumn(handlerClass = StringHandler.class, value = { "SENDER=?", "RECIVER=?" }, isAnd = false) String actor2,
90
			@Nullable @GtEq @Alias("sendTime") String bt, @Nullable @LtEq @Alias("sendTime") String et) throws SQLException;
87 91

92
	@LimitSelect
93
	@OrderBy("ORDER BY SEND_TIME DESC")
94
	List<WebMsgCnt> queryAll4Desc(Connection con,
95
			@GroupSqlColumn(handlerClass = StringHandler.class, value = { "SENDER=?", "RECIVER=?" }, isAnd = false) String actor1,
96
			@GroupSqlColumn(handlerClass = StringHandler.class, value = { "SENDER=?", "RECIVER=?" }, isAnd = false) String actor2,
97
			@Nullable @LessThan String sendTime,int rows) throws SQLException;
98
	
88 99
	
100

89 101
	@UpdateWith
90 102
	@From(WebMsgCnt.class)
91 103
	@SetSentence("READED='1'")
92
	int readed(Connection con,String sender,String reciver,@LtEq String sendTime)throws SQLException;
93
	
104
	@Where("READED='0'")
105
	int readed(Connection con, String sender, String reciver, @LtEq String sendTime) throws SQLException;
106

94 107
	@UpdateWith
95 108
	@From(WebMsgIdx.class)
96 109
	@SetSentence("SHOW_OF_OWNER='0'")
97 110
	@Where("SHOW_OF_OWNER='1'")
98
	int disableOwnerShow(Connection con,String owner,String actor) throws SQLException;
99
	
111
	int disableOwnerShow(Connection con, String owner, String actor) throws SQLException;
112

100 113
	@UpdateWith
101 114
	@From(WebMsgIdx.class)
102 115
	@SetSentence("SHOW_OF_ACTOR='0'")
103 116
	@Where("SHOW_OF_ACTOR='1'")
104
	int disableActorShow(Connection con,String owner,String actor) throws SQLException;
105
	
117
	int disableActorShow(Connection con, String owner, String actor) throws SQLException;
118

106 119
}

+ 2 - 2
src/main/java/com/ekexiu/portal/msg/WebMsgIdx.java

@ -24,7 +24,7 @@ public class WebMsgIdx {
24 24
	 * 所有者(两个ID相比小的是Owner)
25 25
	 * @return
26 26
	 */
27
	@Column(DE.id_32)
27
	@Column(DE.text_de)
28 28
	public String getOwner() {
29 29
		return owner;
30 30
	}
@ -35,7 +35,7 @@ public class WebMsgIdx {
35 35
	 *参与者
36 36
	 * @return
37 37
	 */
38
	@Column(DE.id_32)
38
	@Column(DE.text_de)
39 39
	public String getActor() {
40 40
		return actor;
41 41
	}

+ 28 - 2
src/main/resources/database.sql

@ -2069,10 +2069,36 @@ COMMENT ON COLUMN organization.res_mgr IS '是否是资源管理者 0:不是
2069 2069

2070 2070
--- modify begin at version 2.1
2071 2071

2072
CREATE TABLE WEB_MSG_IDX (OWNER CHAR(32) NOT NULL,ACTOR CHAR(32) NOT NULL,LAST_TIME BIGINT NOT NULL,NUM_OF_OWNER INTEGER NOT NULL,NUM_OF_ACTOR INTEGER NOT NULL,LAST_CNT TEXT NOT NULL,SHOW_OF_OWNER CHAR(1) NOT NULL,SHOW_OF_ACTOR CHAR(1) NOT NULL);
2072
CREATE TABLE WEB_MSG_IDX (
2073
	OWNER TEXT NOT NULL,
2074
	ACTOR TEXT NOT NULL,
2075
	LAST_TIME BIGINT NOT NULL,
2076
	NUM_OF_OWNER INTEGER NOT NULL,
2077
	NUM_OF_ACTOR INTEGER NOT NULL,
2078
	LAST_CNT TEXT NOT NULL,
2079
	SHOW_OF_OWNER CHAR(1) NOT NULL,
2080
	SHOW_OF_ACTOR CHAR(1) NOT NULL);
2073 2081
ALTER TABLE WEB_MSG_IDX ADD PRIMARY KEY (OWNER,ACTOR);
2074
CREATE TABLE WEB_MSG_CNT (CNT TEXT NOT NULL,SEND_TIME TEXT NOT NULL,SENDER CHAR(32) NOT NULL,RECIVER CHAR(32) NOT NULL,READED CHAR(1) NOT NULL);
2082
CREATE TABLE WEB_MSG_CNT (CNT TEXT NOT NULL,SEND_TIME TEXT NOT NULL,SENDER TEXT NOT NULL,RECIVER TEXT NOT NULL,READED CHAR(1) NOT NULL);
2075 2083
ALTER TABLE WEB_MSG_CNT ADD PRIMARY KEY (SENDER,RECIVER,SEND_TIME);
2084
COMMENT ON TABLE WEB_MSG_IDX is '消息会话表';
2085
COMMENT ON COLUMN WEB_MSG_IDX.OWNER IS '会话所有人ID(两个人中ID小的为会话所有人)';
2086
COMMENT ON COLUMN WEB_MSG_IDX.ACTOR IS '会话参与人ID(两个人中ID大的为会话参与人)';
2087
COMMENT ON COLUMN WEB_MSG_IDX.LAST_TIME IS '会话最后活动时间';
2088
COMMENT ON COLUMN WEB_MSG_IDX.NUM_OF_OWNER IS '会话所有人未读消息数';
2089
COMMENT ON COLUMN WEB_MSG_IDX.NUM_OF_ACTOR IS '会话参与人未读消息数';
2090
COMMENT ON COLUMN WEB_MSG_IDX.LAST_CNT IS '会话最后内容';
2091
COMMENT ON COLUMN WEB_MSG_IDX.SHOW_OF_OWNER IS '是否存在与所有的人会话列表中';
2092
COMMENT ON COLUMN WEB_MSG_IDX.SHOW_OF_ACTOR IS '是否存在与参与的人会话列表中';
2093
COMMENT ON TABLE WEB_MSG_CNT IS '消息内容表';
2094
COMMENT ON COLUMN WEB_MSG_CNT.SENDER is '消息发送人ID';
2095
COMMENT ON COLUMN WEB_MSG_CNT.RECIVER is '消息接收人ID';
2096
COMMENT ON COLUMN WEB_MSG_CNT.CNT is '消息内容';
2097
COMMENT ON COLUMN WEB_MSG_CNT.SEND_TIME is '消息发送时间';
2098
COMMENT ON COLUMN WEB_MSG_CNT.READED is '消息是否已读';
2099

2100

2101

2076 2102

2077 2103

2078 2104