jiapeng преди 6 години
родител
ревизия
78150f65df

+ 135 - 0
src/main/java/com/ekexiu/portal/platform/PlatformMsgService.java

@ -0,0 +1,135 @@
1
package com.ekexiu.portal.platform;
2

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

7
import org.jfw.apt.annotation.Autowrie;
8
import org.jfw.apt.web.annotation.Path;
9
import org.jfw.apt.web.annotation.operate.Get;
10
import org.jfw.apt.web.annotation.operate.Post;
11
import org.jfw.apt.web.annotation.param.JdbcConn;
12
import org.jfw.util.DateUtil;
13
import org.jfw.util.exception.JfwBaseException;
14
import org.jfw.util.jdbc.JdbcUtil;
15

16
import com.ekexiu.portal.platform.msg.PlatformMsgDao;
17
import com.ekexiu.portal.platform.msg.PlatformMsgIdx;
18
import com.ekexiu.portal.platform.msg.PlatformMsgRec;
19

20
@Path("/platform/msg")
21
public class PlatformMsgService {
22

23
	@Autowrie
24
	private PlatformMsgDao platformMsgDao;
25

26
	public PlatformMsgDao getPlatformMsgDao() {
27
		return platformMsgDao;
28
	}
29

30
	public void setPlatformMsgDao(PlatformMsgDao platformMsgDao) {
31
		this.platformMsgDao = platformMsgDao;
32
	}
33

34
	@Get
35
	@Path("/idx")
36
	public List<PlatformMsgIdx> query(@JdbcConn Connection con, String provider) throws SQLException {
37
		return this.platformMsgDao.query(con, provider);
38
	}
39

40
	@Get
41
	@Path("/rec")
42
	public List<PlatformMsgRec> query(@JdbcConn Connection con, String provider, String pid, String requestor) throws SQLException {
43
		return this.platformMsgDao.query(con, provider, pid, requestor);
44
	}
45

46
	@Post
47
	@Path("/readed")
48
	public int readed(@JdbcConn(true) Connection con, String provider, String pid, String requestor) throws SQLException {
49
		return this.platformMsgDao.readed(con, provider, pid, requestor);
50
	}
51

52
	@Post
53
	@Path("/delete")
54
	public int delete(@JdbcConn(true) Connection con, String provider, String pid, String requestor) throws SQLException {
55
		return this.platformMsgDao.delete(con, provider, pid, requestor);
56
	}
57

58
	@Post
59
	@Path("/send")
60
	public int send(@JdbcConn(true) Connection con, String provider, String pid, String requestor, String cnt) throws SQLException, JfwBaseException {
61
		String time = DateUtil.formatDateTime(System.currentTimeMillis());
62
		PlatformMsgRec mr = new PlatformMsgRec();
63
		mr.setCnt(cnt);
64
		mr.setOpTime(time);
65
		mr.setPid(pid);
66
		mr.setProvider(provider);
67
		mr.setRequestor(requestor);
68
		try {
69
			this.platformMsgDao.insert(con, mr);
70
		} catch (SQLException ee) {
71
			if ("23505".equals(ee.getSQLState())) {
72
				throw new JfwBaseException(-60001, "interval to small");
73
			}
74
		}
75
		this.platformMsgDao.updateActivedIdx(con, requestor, provider, pid, time, cnt, time);
76
		return 1;
77
	}
78

79
	@Post
80
	@Path("/frecv")
81
	public void frecv(@JdbcConn(true) Connection con, String provider, String pid, String requestor, String cnt, String time)
82
			throws SQLException, JfwBaseException {
83
		PlatformMsgRec mr = new PlatformMsgRec();
84
		mr.setCnt(cnt);
85
		mr.setOpTime(time);
86
		mr.setPid(pid);
87
		mr.setProvider(provider);
88
		mr.setRequestor(requestor);
89
		this.platformMsgDao.insert(con, mr);
90
		PlatformMsgIdx mi = new PlatformMsgIdx();
91
		mi.setActived(true);
92
		mi.setCnt(cnt);
93
		mi.setOpTime(time);
94
		mi.setPid(pid);
95
		mi.setProvider(provider);
96
		mi.setRequestor(requestor);
97
		mi.setUnread(1);
98
		this.platformMsgDao.insert(con, mi);
99
	}
100

101
	@Post
102
	@Path("/recv")
103
	public void recv(@JdbcConn Connection con, String provider, String pid, String requestor, String cnt, String time) throws SQLException, JfwBaseException {
104
		try {
105
			PlatformMsgRec mr = new PlatformMsgRec();
106
			mr.setCnt(cnt);
107
			mr.setOpTime(time);
108
			mr.setPid(pid);
109
			mr.setProvider(provider);
110
			mr.setRequestor(requestor);
111
			try {
112
				this.platformMsgDao.insert(con, mr);
113
			} catch (SQLException ee) {
114
				if ("23505".equals(ee.getSQLState())) {
115
					JdbcUtil.rollback(con);
116
					return;
117
				}
118
			}
119
			if (this.platformMsgDao.updateIdxFlag(con, provider, pid, requestor, time) == 0) {
120
				this.platformMsgDao.updateIdxFull(con, provider, pid, requestor, time, cnt, time);
121
			}
122
			con.commit();
123
		} catch (SQLException e) {
124
			JdbcUtil.rollback(con);
125
		} finally {
126
			JdbcUtil.close(con);
127
		}
128
	}
129
	
130
	@Get
131
	@Path("/sync")
132
	public List<PlatformMsgRec> syncData(@JdbcConn Connection con,String pid,String requestor,String provider,String opTime,int rows)throws SQLException{
133
		return this.platformMsgDao.queryOld(con, pid, opTime, provider, requestor, rows);
134
	}
135
}

+ 74 - 0
src/main/java/com/ekexiu/portal/platform/msg/PlatformMsgDao.java

@ -0,0 +1,74 @@
1
package com.ekexiu.portal.platform.msg;
2

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

7
import org.jfw.apt.orm.annotation.dao.DAO;
8
import org.jfw.apt.orm.annotation.dao.method.From;
9
import org.jfw.apt.orm.annotation.dao.method.LimitColumn;
10
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
11
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
12
import org.jfw.apt.orm.annotation.dao.method.Where;
13
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
14
import org.jfw.apt.orm.annotation.dao.method.operator.LimitSelect;
15
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
16
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
17
import org.jfw.apt.orm.annotation.dao.param.Alias;
18
import org.jfw.apt.orm.annotation.dao.param.GtEq;
19
import org.jfw.apt.orm.annotation.dao.param.LessThan;
20
import org.jfw.apt.orm.annotation.dao.param.Set;
21

22

23
@DAO
24
public interface PlatformMsgDao {
25

26
	
27
	@SelectList
28
	@OrderBy("ORDER BY OP_TIME DESC")
29
	@Where("ACTIVED ='1'")
30
	List<PlatformMsgIdx> query(Connection con,String provider)throws SQLException;
31
	
32
	@SelectList
33
	@OrderBy("ORDER BY OP_TIME DESC")
34

35
	List<PlatformMsgRec> query(Connection con,String provider,String pid,String requestor)throws SQLException;
36
	
37
	@LimitSelect
38
	@OrderBy(cols={ @LimitColumn(value = "opTime", asc = true), 
39
		@LimitColumn(value = "provider", asc = false),
40
		@LimitColumn(value = "requestor", asc = false) }, value = "")
41
	List<PlatformMsgRec> queryOld(Connection con,String pid,String opTime,String provider,String requestor,int rows)throws SQLException;
42
	
43
	@Insert
44
	int insert(Connection con,PlatformMsgRec mr)throws SQLException;
45
	@Insert
46
	int insert(Connection con,PlatformMsgIdx mi)throws SQLException;
47
	
48
	@UpdateWith
49
	@From(PlatformMsgIdx.class)
50
	@SetSentence("UNREAD=0")
51
	int readed(Connection con,String provider,String pid,String requestor)throws SQLException;
52
	@UpdateWith
53
	@From(PlatformMsgIdx.class)
54
	@SetSentence("ACTIVED='0' ,UNREAD=0")
55
	int delete(Connection con,String provider,String pid,String requestor)throws SQLException;
56
	
57
	
58
	
59
	@UpdateWith
60
	@From(PlatformMsgIdx.class)
61
	int updateActivedIdx(Connection con,String requestor,String provider,String pid, @LessThan @Alias("opTime") String time ,@Set String cnt,@Set String opTime  )throws SQLException;
62
	
63
	
64
	@UpdateWith
65
	@From(PlatformMsgIdx.class)
66
	@SetSentence("ACTIVED='1' ,UNREAD=UNREAD+1")
67
	int updateIdxFlag(Connection con,String provider,String pid,String requestor,@GtEq String opTime)throws SQLException;
68
	
69
	@UpdateWith
70
	@From(PlatformMsgIdx.class)
71
	@SetSentence("ACTIVED='1' ,UNREAD=UNREAD+1")
72
	int updateIdxFull(Connection con,String provider,String pid,String requestor, @LessThan @Alias("opTime") String time,@Set String cnt,@Set String opTime)throws SQLException;
73
	
74
}

+ 72 - 0
src/main/java/com/ekexiu/portal/platform/msg/PlatformMsgIdx.java

@ -0,0 +1,72 @@
1
package com.ekexiu.portal.platform.msg;
2

3
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
5
import org.jfw.apt.orm.annotation.entry.Table;
6
import org.jfw.apt.orm.core.enums.DE;
7

8
@PrimaryKey({"pid","requestor","provider"})
9
@Table
10
public class PlatformMsgIdx {
11
	private String pid;
12
	private String requestor;
13
	private String provider;
14
	private String cnt;
15
	private String  opTime;
16
	private int unread;
17
	private boolean actived;
18
	
19
	@Column(DE.text_de)
20
	public String getPid() {
21
		return pid;
22
	}
23
	public void setPid(String pid) {
24
		this.pid = pid;
25
	}
26
	@Column(DE.text_de)
27
	public String getRequestor() {
28
		return requestor;
29
	}
30
	public void setRequestor(String requestor) {
31
		this.requestor = requestor;
32
	}
33
	@Column(DE.text_de)
34
	public String getProvider() {
35
		return provider;
36
	}
37
	public void setProvider(String provider) {
38
		this.provider = provider;
39
	}
40
	@Column(DE.text_de)
41
	public String getCnt() {
42
		return cnt;
43
	}
44
	public void setCnt(String cnt) {
45
		this.cnt = cnt;
46
	}
47
	@Column(DE.text_de)
48
	public String getOpTime() {
49
		return opTime;
50
	}
51
	public void setOpTime(String opTime) {
52
		this.opTime = opTime;
53
	}
54
	@Column(DE.int_de)
55
	public int getUnread() {
56
		return unread;
57
	}
58
	public void setUnread(int unread) {
59
		this.unread = unread;
60
	}
61
	@Column(DE.boolean_de)
62
	public boolean isActived() {
63
		return actived;
64
	}
65
	public void setActived(boolean actived) {
66
		this.actived = actived;
67
	}
68
	
69
	
70
	
71
	
72
}

+ 50 - 0
src/main/java/com/ekexiu/portal/platform/msg/PlatformMsgRec.java

@ -0,0 +1,50 @@
1
package com.ekexiu.portal.platform.msg;
2

3
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.Table;
5
import org.jfw.apt.orm.core.enums.DE;
6

7
@Table
8
public class PlatformMsgRec {
9
	private String pid;
10
	private String requestor;
11
	private String provider;
12
	private String cnt;
13
	private String  opTime;
14
	
15
	@Column(DE.text_de)
16
	public String getPid() {
17
		return pid;
18
	}
19
	public void setPid(String pid) {
20
		this.pid = pid;
21
	}
22
	@Column(DE.text_de)
23
	public String getRequestor() {
24
		return requestor;
25
	}
26
	public void setRequestor(String requestor) {
27
		this.requestor = requestor;
28
	}
29
	@Column(DE.text_de)
30
	public String getProvider() {
31
		return provider;
32
	}
33
	public void setProvider(String provider) {
34
		this.provider = provider;
35
	}
36
	@Column(DE.text_de)
37
	public String getCnt() {
38
		return cnt;
39
	}
40
	public void setCnt(String cnt) {
41
		this.cnt = cnt;
42
	}
43
	@Column(DE.text_de)
44
	public String getOpTime() {
45
		return opTime;
46
	}
47
	public void setOpTime(String opTime) {
48
		this.opTime = opTime;
49
	}
50
}