Skip to content

Commit 22ec3dd

Browse files
author
JunLuo903
committed
个推以及单聊功能开发
1 parent 21349a3 commit 22ec3dd

12 files changed

+779
-5
lines changed

build.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ version '1.0'
88

99
repositories {
1010
mavenCentral()
11+
maven{
12+
name "getui-nexus"
13+
url "http://mvn.gt.igexin.com/nexus/content/repositories/releases/"
14+
}
1115
}
1216

1317
dependencies {
@@ -16,6 +20,9 @@ dependencies {
1620
// Guava java 类封装
1721
compile 'com.google.guava:guava:21.0'
1822

23+
// 推送依赖
24+
compile 'com.gexin.platform:gexin-rp-sdk-http:4.0.1.7'
25+
1926
// Jersey 轻量级Restful接口框架
2027
compile 'org.glassfish.jersey.core:jersey-client:2.26-b03'
2128
compile 'org.glassfish.jersey.core:jersey-server:2.26-b03'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.mengxiang.im.push.bean.api.base;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.mengxiang.im.push.utils.TextUtil;
5+
6+
7+
import java.time.LocalDateTime;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
/**
12+
* 一个推送的具体Model,内部维持了一个数组,可以添加多个实体
13+
* 每次推送的详细数据是:把实体数组进行Json操作,然后发送Json字符串
14+
* 这样做的目的是:减少多次推送,如果有多个消息需要推送可以合并进行
15+
*
16+
* @author qiujuer Email:qiujuer.live.cn
17+
*/
18+
@SuppressWarnings("WeakerAccess")
19+
public class PushModel {
20+
public static final int ENTITY_TYPE_LOGOUT = -1;
21+
public static final int ENTITY_TYPE_MESSAGE = 200;
22+
public static final int ENTITY_TYPE_ADD_FRIEND = 1001;
23+
public static final int ENTITY_TYPE_ADD_GROUP = 1002;
24+
public static final int ENTITY_TYPE_ADD_GROUP_MEMBERS = 1003;
25+
public static final int ENTITY_TYPE_MODIFY_GROUP_MEMBERS = 2001;
26+
public static final int ENTITY_TYPE_EXIT_GROUP_MEMBERS = 3001;
27+
28+
private List<Entity> entities = new ArrayList<>();
29+
30+
public PushModel add(Entity entity) {
31+
entities.add(entity);
32+
return this;
33+
}
34+
35+
public PushModel add(int type, String content) {
36+
return add(new Entity(type, content));
37+
}
38+
39+
// 拿到一个推送的字符串
40+
public String getPushString() {
41+
if (entities.size() == 0){
42+
return null;}
43+
return TextUtil.toJson(entities);
44+
}
45+
46+
/**
47+
* 具体的实体类型,在这个实体中包装了实体的内容和类型
48+
* 比如添加好友的推送:
49+
* content:用户信息的Json字符串
50+
* type=ENTITY_TYPE_ADD_FRIEND
51+
*/
52+
public static class Entity {
53+
public Entity(int type, String content) {
54+
this.type = type;
55+
this.content = content;
56+
}
57+
58+
// 消息类型
59+
@Expose
60+
public int type;
61+
// 消息实体
62+
@Expose
63+
public String content;
64+
// 消息生成时间
65+
@Expose
66+
public LocalDateTime createAt = LocalDateTime.now();
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.mengxiang.im.push.bean.api.messsage;
2+
3+
import com.google.common.base.Strings;
4+
import com.google.gson.annotations.Expose;
5+
import com.mengxiang.im.push.bean.db.Message;
6+
7+
public class MessageCreateModel {
8+
// ID从客户端生产,一个UUID
9+
@Expose
10+
private String id;
11+
@Expose
12+
private String content;
13+
@Expose
14+
private String attach;
15+
16+
// 消息类型
17+
@Expose
18+
private int type = Message.TYPE_STR;
19+
20+
// 接收者 可为空
21+
@Expose
22+
private String receiverId;
23+
24+
// 接收者类型,群,人, 默认为人
25+
@Expose
26+
private int receiverType = Message.RECEIVER_TYPE_NONE;
27+
28+
public String getId() {
29+
return id;
30+
}
31+
32+
public void setId(String id) {
33+
this.id = id;
34+
}
35+
36+
public String getContent() {
37+
return content;
38+
}
39+
40+
public void setContent(String content) {
41+
this.content = content;
42+
}
43+
44+
public String getAttach() {
45+
return attach;
46+
}
47+
48+
public void setAttach(String attach) {
49+
this.attach = attach;
50+
}
51+
52+
public int getType() {
53+
return type;
54+
}
55+
56+
public void setType(int type) {
57+
this.type = type;
58+
}
59+
60+
public String getReceiverId() {
61+
return receiverId;
62+
}
63+
64+
public void setReceiverId(String receiverId) {
65+
this.receiverId = receiverId;
66+
}
67+
68+
public int getReceiverType() {
69+
return receiverType;
70+
}
71+
72+
public void setReceiverType(int receiverType) {
73+
this.receiverType = receiverType;
74+
}
75+
76+
// 校验消息
77+
public static boolean check(MessageCreateModel model) {
78+
return model != null
79+
&& !(Strings.isNullOrEmpty(model.id)
80+
|| Strings.isNullOrEmpty(model.content)
81+
|| Strings.isNullOrEmpty(model.receiverId))
82+
83+
&& (model.receiverType == Message.RECEIVER_TYPE_NONE
84+
|| model.receiverType == Message.RECEIVER_TYPE_GROUP)
85+
86+
&& (model.type == Message.TYPE_STR
87+
|| model.type == Message.TYPE_AUDIO
88+
|| model.type == Message.TYPE_FILE
89+
|| model.type == Message.TYPE_PIC);
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.mengxiang.im.push.bean.card;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.mengxiang.im.push.bean.db.Message;
5+
6+
import java.time.LocalDateTime;
7+
8+
/**
9+
* 消息的卡片Model
10+
*/
11+
public class MessageCard {
12+
@Expose
13+
private String id; // Id
14+
@Expose
15+
private String content;// 内容
16+
@Expose
17+
private String attach;// 附件,附属信息
18+
@Expose
19+
private int type;// 消息类型
20+
@Expose
21+
private LocalDateTime createAt;// 创建时间
22+
@Expose
23+
private String groupId;// 如果是群信息,对应群Id
24+
@Expose
25+
private String senderId;// 发送者Id,不为空
26+
@Expose
27+
private String receiverId;// 接收者Id
28+
29+
public MessageCard(Message message) {
30+
this.id = message.getId();
31+
this.content = message.getContent();
32+
this.type = message.getType();
33+
this.attach = message.getAttach();
34+
this.createAt = message.getCreateAt();
35+
this.groupId = message.getGroupId();
36+
this.senderId = message.getSenderId();
37+
this.receiverId = message.getReceiverId();
38+
}
39+
40+
public String getId() {
41+
return id;
42+
}
43+
44+
public void setId(String id) {
45+
this.id = id;
46+
}
47+
48+
public String getContent() {
49+
return content;
50+
}
51+
52+
public void setContent(String content) {
53+
this.content = content;
54+
}
55+
56+
public String getAttach() {
57+
return attach;
58+
}
59+
60+
public void setAttach(String attach) {
61+
this.attach = attach;
62+
}
63+
64+
public int getType() {
65+
return type;
66+
}
67+
68+
public void setType(int type) {
69+
this.type = type;
70+
}
71+
72+
public LocalDateTime getCreateAt() {
73+
return createAt;
74+
}
75+
76+
public void setCreateAt(LocalDateTime createAt) {
77+
this.createAt = createAt;
78+
}
79+
80+
public String getGroupId() {
81+
return groupId;
82+
}
83+
84+
public void setGroupId(String groupId) {
85+
this.groupId = groupId;
86+
}
87+
88+
public String getSenderId() {
89+
return senderId;
90+
}
91+
92+
public void setSenderId(String senderId) {
93+
this.senderId = senderId;
94+
}
95+
96+
public String getReceiverId() {
97+
return receiverId;
98+
}
99+
100+
public void setReceiverId(String receiverId) {
101+
this.receiverId = receiverId;
102+
}
103+
}

src/main/java/com/mengxiang/im/push/bean/db/Message.java

+29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mengxiang.im.push.bean.db;
22

3+
import com.mengxiang.im.push.bean.api.messsage.MessageCreateModel;
34
import org.hibernate.annotations.CreationTimestamp;
45
import org.hibernate.annotations.GenericGenerator;
56

@@ -17,6 +18,9 @@ public class Message {
1718
public static final int TYPE_FILE = 3;//文件
1819
public static final int TYPE_AUDIO = 4;//语音
1920

21+
// 定义发送的类别,发送给人还是发送给群
22+
public static final int RECEIVER_TYPE_NONE = 1;//人
23+
public static final int RECEIVER_TYPE_GROUP = 2;//群
2024

2125
//主键
2226
@Id
@@ -78,6 +82,31 @@ public class Message {
7882
@Column(updatable = false, insertable = false)
7983
private String groupId;
8084

85+
public Message() {
86+
87+
}
88+
89+
// 发送给朋友的构造函数
90+
public Message(User sender, User receiver, MessageCreateModel model) {
91+
this.id = model.getId();
92+
this.content = model.getContent();
93+
this.attach = model.getAttach();
94+
this.type = model.getType();
95+
96+
this.sender = sender;
97+
this.receiver = receiver;
98+
}
99+
100+
// 发送给群的构造函数
101+
public Message(User sender, Group group, MessageCreateModel model) {
102+
this.id = model.getId();
103+
this.content = model.getContent();
104+
this.attach = model.getAttach();
105+
this.type = model.getType();
106+
107+
this.sender = sender;
108+
this.group = group;
109+
}
81110
public String getId() {
82111
return id;
83112
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.mengxiang.im.push.factory;
2+
3+
import com.mengxiang.im.push.bean.db.Group;
4+
import com.mengxiang.im.push.bean.db.GroupMember;
5+
import com.mengxiang.im.push.bean.db.User;
6+
import com.mengxiang.im.push.utils.Hib;
7+
8+
import java.util.Set;
9+
10+
public class GroupFactory {
11+
public static Group findById(String groupId) {
12+
// TODO 查询一个群
13+
return null;
14+
}
15+
16+
public static Group findById(User user, String groupId) {
17+
// TODO 查询一个群, 同时该User必须为群的成员,否则返回null
18+
return null;
19+
}
20+
21+
public static Set<GroupMember> getMembers(Group group) {
22+
// TODO 查询一个群的成员
23+
return null;
24+
}
25+
}

0 commit comments

Comments
 (0)