├── .classpath
├── .project
├── .settings
├── .jsdtscope
├── org.eclipse.core.resources.prefs
├── org.eclipse.jdt.core.prefs
├── org.eclipse.m2e.core.prefs
├── org.eclipse.wst.common.component
├── org.eclipse.wst.common.project.facet.core.prefs.xml
├── org.eclipse.wst.common.project.facet.core.xml
├── org.eclipse.wst.jsdt.ui.superType.container
├── org.eclipse.wst.jsdt.ui.superType.name
├── org.eclipse.wst.validation.prefs
└── org.eclipse.wst.ws.service.policy.prefs
├── LICENSE
├── README.md
├── pom.xml
├── sql
├── .DS_Store
└── mybatis
│ ├── mybatis-generator-core-1.3.2.jar
│ ├── mysql-connector-java-5.1.40-bin.jar
│ └── run.sh
└── src
├── main
├── java
│ └── com
│ │ └── ices
│ │ └── yangengzhe
│ │ ├── controller
│ │ ├── ApiController.java
│ │ └── MessageController.java
│ │ ├── persistence
│ │ ├── dao
│ │ │ ├── ApplyMapper.java
│ │ │ ├── FriendgroupDetailMapper.java
│ │ │ ├── FriendgroupMapper.java
│ │ │ ├── GroupDetailMapper.java
│ │ │ ├── GroupMapper.java
│ │ │ ├── MessageBoxMapper.java
│ │ │ ├── MsgMapper.java
│ │ │ ├── MsgUnreadMapper.java
│ │ │ ├── UserLogMapper.java
│ │ │ └── UserMapper.java
│ │ ├── mapping
│ │ │ ├── ApplyMapper.xml
│ │ │ ├── FriendgroupDetailMapper.xml
│ │ │ ├── FriendgroupMapper.xml
│ │ │ ├── GroupDetailMapper.xml
│ │ │ ├── GroupMapper.xml
│ │ │ ├── MessageBoxMapper.xml
│ │ │ ├── MsgMapper.xml
│ │ │ ├── MsgUnreadMapper.xml
│ │ │ ├── UserLogMapper.xml
│ │ │ └── UserMapper.xml
│ │ └── pojo
│ │ │ ├── Apply.java
│ │ │ ├── ApplyKey.java
│ │ │ ├── Friendgroup.java
│ │ │ ├── FriendgroupDetail.java
│ │ │ ├── Group.java
│ │ │ ├── GroupDetail.java
│ │ │ ├── MessageBox.java
│ │ │ ├── Msg.java
│ │ │ ├── MsgUnread.java
│ │ │ ├── User.java
│ │ │ └── UserLog.java
│ │ ├── service
│ │ ├── api
│ │ │ ├── IFriend.java
│ │ │ ├── IGroup.java
│ │ │ ├── IInformation.java
│ │ │ ├── IMessage.java
│ │ │ └── impl
│ │ │ │ ├── Friend.java
│ │ │ │ ├── Group.java
│ │ │ │ ├── Information.java
│ │ │ │ └── Message.java
│ │ └── persistence
│ │ │ ├── IApplyService.java
│ │ │ ├── IFriendgroupDetailService.java
│ │ │ ├── IFriendgroupService.java
│ │ │ ├── IGroupService.java
│ │ │ ├── IMessageService.java
│ │ │ ├── IMessageboxService.java
│ │ │ ├── IUserLogService.java
│ │ │ ├── IUserService.java
│ │ │ └── impl
│ │ │ ├── ApplyService.java
│ │ │ ├── FriendgroupDetailService.java
│ │ │ ├── FriendgroupService.java
│ │ │ ├── GroupService.java
│ │ │ ├── MessageService.java
│ │ │ ├── MessageboxService.java
│ │ │ ├── UserLogService.java
│ │ │ └── UserService.java
│ │ ├── socket
│ │ ├── SocketConfigurator.java
│ │ ├── SocketServletListener.java
│ │ ├── manager
│ │ │ ├── GroupUserManager.java
│ │ │ ├── IUserManager.java
│ │ │ ├── OnLineUserManager.java
│ │ │ └── UserManager.java
│ │ ├── sender
│ │ │ ├── MessageParse.java
│ │ │ └── MessageSender.java
│ │ └── webServer.java
│ │ └── util
│ │ ├── Parse.java
│ │ ├── cache
│ │ ├── ChatCache.java
│ │ └── EHCacheUtil.java
│ │ ├── enums
│ │ ├── AvatorType.java
│ │ ├── ChatType.java
│ │ ├── OnlineStatus.java
│ │ ├── ResponseType.java
│ │ ├── ToClientMessageType.java
│ │ └── UserLogType.java
│ │ ├── factory
│ │ └── WebChatFactory.java
│ │ ├── pojo
│ │ ├── JsonPageResult.java
│ │ ├── JsonResult.java
│ │ ├── SocketUser.java
│ │ └── message
│ │ │ ├── ToClientMessageResult.java
│ │ │ ├── ToClientTextMessage.java
│ │ │ ├── ToServerMessageMine.java
│ │ │ ├── ToServerMessageTo.java
│ │ │ └── ToServerTextMessage.java
│ │ └── serializer
│ │ ├── FastJsonSerializer.java
│ │ └── IJsonSerializer.java
├── resources
│ ├── jdbc.properties
│ ├── log4j.properties
│ ├── spring-mvc.xml
│ └── spring-mybatis.xml
└── webapp
│ ├── WEB-INF
│ └── web.xml
│ ├── images
│ ├── avator-qun.png
│ ├── avator-sf.jpg
│ ├── avator-sm.jpg
│ ├── avator-tf.jpg
│ └── avator-tm.jpg
│ └── index.jsp
└── test
└── java
└── com
└── ices
└── yangengzhe
└── mybatis
├── TestUser.java
└── TestUserLog.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | webchat
4 | NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.wst.common.project.facet.core.builder
15 |
16 |
17 |
18 |
19 | org.eclipse.wst.validation.validationbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.core.springbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jem.workbench.JavaEMFNature
37 | org.eclipse.wst.common.modulecore.ModuleCoreNature
38 | org.eclipse.jdt.core.javanature
39 | org.eclipse.m2e.core.maven2Nature
40 | org.eclipse.wst.common.project.facet.core.nature
41 | org.eclipse.wst.jsdt.core.jsNature
42 |
43 |
44 |
--------------------------------------------------------------------------------
/.settings/.jsdtscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources/jdbc.properties=UTF-8
4 | encoding//src/main/resources/log4j.properties=UTF-8
5 | encoding//src/test/java=UTF-8
6 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.6
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
13 | org.eclipse.jdt.core.compiler.source=1.6
14 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.common.component:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.jsdt.ui.superType.container:
--------------------------------------------------------------------------------
1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.jsdt.ui.superType.name:
--------------------------------------------------------------------------------
1 | Window
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.validation.prefs:
--------------------------------------------------------------------------------
1 | disabled=06target
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.ws.service.policy.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.wst.ws.service.policy.projectEnabled=false
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # webChat
2 |
3 | 基于layim 3.x的web聊天系统,采用Java技术 WebSocket+mysql,利用spring mvc框架+MyBatis实现
4 |
5 | **注意:由于layim非开源,故本项目中移除该部分功能,无法导入直接运行。需要将layui文件夹拷贝到/webapp/js/目录下**
6 |
7 | IP地址修改:Global.java URL index.jsp jdbc.properties
8 |
9 | ## 在线示例
10 |
11 | 用户yan:[点击登录](http://www.7tool.cn:8090/webchat/?uid=10000&key=10000)
12 | 用户张三:[点击登录](http://www.7tool.cn:8090/webchat/?uid=10001&key=10001)
13 | 用户李四:[点击登录](http://www.7tool.cn:8090/webchat/?uid=10002&key=10002)
14 |
15 | 测试步骤:同时点击多个链接,登陆多个账户进行相互消息测试。**若提示“未登录”刷新界面两次即可!**
16 |
17 | ## 功能
18 |
19 | 1. 私聊、群聊
20 | 2. 离线消息
21 | 3. 实时上线、下线状态更新
22 | 4. 好友查找添加
23 | 5. 消息盒子
24 |
25 | ## 更新
26 |
27 | 2017.1.29
28 |
29 | 1. 完成 查找好友、消息盒子的前端模板
30 | 2. 完成 查找、添加好友和消息盒子的api设计
31 | 3. 完成好友查找添加、消息盒子的逻辑和功能
32 |
33 | ---
34 |
35 | 2017.1.28
36 |
37 | 1. 完成群离线消息的处理
38 | 2. 完成Restful的member接口(获取群成员信息)
39 | 3. 完成Restful的init接口(获取群信息)
40 |
41 | ---
42 |
43 | 2017.1.26
44 |
45 | 1. 离线消息功能完成
46 | 2. 实时上线、下线状态更新
47 |
48 | ---
49 |
50 | 2017.1.24
51 |
52 | 1. 完成WebSocket私聊功能
53 | 2. 完成Restful的init接口(获取个人信息、好友列表)
54 |
55 | ---
56 |
57 | 2017.1.22
58 |
59 | 基本框架搭设
60 |
61 | ## 结构图
62 |
63 | ### com.ices.yangengzhe.service.api
64 |
65 | Information
66 | init - 初始化方法 返回用户信息和好友列表
67 | addUser - 添加用户
68 | findUserByUid - 根据UID找用户
69 |
70 | Friend
71 | // 创建好友分组
72 | int addFriendgroup(Integer uid, String groupname);
73 | // 创建好友分组
74 | int addFriendgroup(Integer uid, String groupname, List members);
75 | // 添加好友
76 | void addFriend(Integer user1,Integer user1_group,Integer user2,Integer user2_group);
77 | //向分组加成员
78 | void addMemberToFG(Integer groupId,Integer uid);
79 | // 获取分组列表
80 | public List getFriendgroupList(Integer uid);
81 | // 获取分组列表(含成员)
82 | public List> getFriendgroupDetaillist(Integer uid);
83 | // 获取好友分组的成员
84 | public List> getFridengroupMember(Integer fid);
85 |
86 | ### com.ices.yangengzhe.socket
87 |
88 | webServer.java webSocket服务器,用于与客户端消息的交互
89 | manager 利用缓存管理会员列表
90 | GroupUserManager.java 组成员管理
91 | UserManager.java 会员session管理
92 | OnLineUserManager.java 在线会员管理
93 | sender 消息发送
94 | MessageParse.java 消息生成工具类
95 | MessageSender.java 消息发送类
96 |
97 | ## 设计模式
98 |
99 | 工厂模式、单列模式、代理模式、过滤器模式
100 |
101 | ## 注意
102 |
103 | 本项目中缺少两部分:com.ices.yangengzhe.util.security.Security类和SQL文件
104 |
105 | - Security:用于用户的权限验证,包含:getPassword、authentication和isLogin方法。
106 | - SQL文件:mysql数据库,包含:结构+测试数据+存储过程
107 |
108 | 以上部分由于其他原因暂不公开,但是不影响整体的功能逻辑,对于学习者不会有任何影响。
109 | 本项目只是供学习使用,相信根据代码也有能力完善以上两部分,故不再讨论或索取以上两部分相关内容。
110 |
111 | ## 帮助支持
112 |
113 | 可在该项目的Issues中讨论 或 加入QQ群:194895016
114 |
115 | by 爱上极客(http://www.i3geek.com)
116 |
117 | ---
118 |
119 | 喜欢的请点击star or fork
120 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.ices.yangengzhe
5 | webchat
6 | war
7 | 0.0.1-SNAPSHOT
8 | webchat Maven Webapp
9 | http://maven.apache.org
10 |
11 |
12 | 4.0.2.RELEASE
13 |
14 | 3.2.6
15 |
16 | 1.7.7
17 | 1.2.17
18 |
19 |
20 |
21 | junit
22 | junit
23 | 4.11
24 |
25 | test
26 |
27 |
28 |
29 | org.springframework
30 | spring-core
31 | ${spring.version}
32 |
33 |
34 | org.springframework
35 | spring-web
36 | ${spring.version}
37 |
38 |
39 |
40 | org.springframework
41 | spring-oxm
42 | ${spring.version}
43 |
44 |
45 | org.springframework
46 | spring-tx
47 | ${spring.version}
48 |
49 |
50 | org.springframework
51 | spring-jdbc
52 | ${spring.version}
53 |
54 |
55 | org.springframework
56 | spring-webmvc
57 | ${spring.version}
58 |
59 |
60 | org.springframework
61 | spring-aop
62 | ${spring.version}
63 |
64 |
65 | org.springframework
66 | spring-context-support
67 | ${spring.version}
68 |
69 |
70 | org.springframework
71 | spring-test
72 | ${spring.version}
73 |
74 |
75 |
76 | org.mybatis
77 | mybatis
78 | ${mybatis.version}
79 |
80 |
81 |
82 | org.mybatis
83 | mybatis-spring
84 | 1.2.2
85 |
86 |
87 |
88 | javax
89 | javaee-api
90 | 7.0
91 |
92 |
93 |
94 | mysql
95 | mysql-connector-java
96 | 5.1.30
97 |
98 |
99 |
100 | commons-dbcp
101 | commons-dbcp
102 | 1.4
103 |
104 |
105 |
106 | jstl
107 | jstl
108 | 1.2
109 |
110 |
111 |
112 |
113 | log4j
114 | log4j
115 | ${log4j.version}
116 |
117 |
118 |
119 | com.alibaba
120 | fastjson
121 | 1.1.41
122 |
123 |
124 | org.slf4j
125 | slf4j-api
126 | ${slf4j.version}
127 |
128 |
129 | org.slf4j
130 | slf4j-log4j12
131 | ${slf4j.version}
132 |
133 |
134 |
135 |
136 | org.codehaus.jackson
137 | jackson-mapper-asl
138 | 1.9.13
139 |
140 |
141 |
142 | commons-fileupload
143 | commons-fileupload
144 | 1.3.1
145 |
146 |
147 | commons-io
148 | commons-io
149 | 2.4
150 |
151 |
152 | commons-codec
153 | commons-codec
154 | 1.9
155 |
156 |
157 | org.ehcache
158 | ehcache
159 | 3.2.0
160 |
161 |
162 |
163 |
164 |
165 | org.apache.maven.plugins
166 | maven-compiler-plugin
167 | 3.5.1
168 |
169 | 1.6
170 | 1.6
171 | UTF-8
172 |
173 |
174 |
175 | webchat
176 |
177 |
178 |
--------------------------------------------------------------------------------
/sql/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangengzhe/webChat/6ba3f24054a7b06a305709fb9d39e633784a6734/sql/.DS_Store
--------------------------------------------------------------------------------
/sql/mybatis/mybatis-generator-core-1.3.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangengzhe/webChat/6ba3f24054a7b06a305709fb9d39e633784a6734/sql/mybatis/mybatis-generator-core-1.3.2.jar
--------------------------------------------------------------------------------
/sql/mybatis/mysql-connector-java-5.1.40-bin.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangengzhe/webChat/6ba3f24054a7b06a305709fb9d39e633784a6734/sql/mybatis/mysql-connector-java-5.1.40-bin.jar
--------------------------------------------------------------------------------
/sql/mybatis/run.sh:
--------------------------------------------------------------------------------
1 | java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
2 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/controller/ApiController.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.controller;
2 |
3 | import java.io.IOException;
4 | import javax.servlet.http.HttpServletRequest;
5 | import javax.servlet.http.HttpServletResponse;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Controller;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 |
11 | import com.ices.yangengzhe.service.api.IGroup;
12 | import com.ices.yangengzhe.service.api.IInformation;
13 | import com.ices.yangengzhe.util.factory.WebChatFactory;
14 | import com.ices.yangengzhe.util.pojo.JsonResult;
15 | import com.ices.yangengzhe.util.serializer.IJsonSerializer;
16 |
17 | @Controller
18 | @RequestMapping("/api")
19 | public class ApiController {
20 |
21 | @Autowired
22 | private IInformation information;
23 | @Autowired
24 | private IGroup group;
25 |
26 | @RequestMapping("/init")
27 | public void init(HttpServletRequest request, HttpServletResponse response) throws IOException {
28 |
29 | String id = request.getParameter("id");
30 | String key = request.getParameter("key");
31 | JsonResult result = information.init(Integer.valueOf(id), key);
32 | sendResult(response,result);
33 | }
34 |
35 | @RequestMapping("/member")
36 | public void getGroupMember(HttpServletRequest request, HttpServletResponse response) throws IOException {
37 |
38 | String id = request.getParameter("id");
39 | JsonResult result = group.getGroupMembers(Integer.valueOf(id));
40 | sendResult(response,result);
41 | }
42 |
43 | @RequestMapping("/searchUser")
44 | public void searchUser(HttpServletRequest request, HttpServletResponse response) throws IOException {
45 | String keyword = request.getParameter("keyword");
46 | keyword =new String(keyword.getBytes("ISO-8859-1"), "UTF-8");
47 | JsonResult result = information.searchUserByKeyword(keyword);
48 | sendResult(response,result);
49 | }
50 |
51 | public void sendResult(HttpServletResponse response,JsonResult result) throws IOException{
52 | response.setCharacterEncoding("UTF-8");
53 | IJsonSerializer serializer = WebChatFactory.createSerializer();
54 | response.setHeader("Access-Control-Allow-Origin", "*");//允许跨域
55 | response.getWriter().write(serializer.toJSON(result));
56 | }
57 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/controller/MessageController.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.controller;
2 |
3 | import java.io.IOException;
4 | import javax.servlet.http.HttpServletRequest;
5 | import javax.servlet.http.HttpServletResponse;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Controller;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 |
11 | import com.ices.yangengzhe.service.api.IMessage;
12 | import com.ices.yangengzhe.util.factory.WebChatFactory;
13 | import com.ices.yangengzhe.util.pojo.JsonPageResult;
14 | import com.ices.yangengzhe.util.pojo.JsonResult;
15 | import com.ices.yangengzhe.util.serializer.IJsonSerializer;
16 |
17 | @Controller
18 | @RequestMapping("/message")
19 | public class MessageController {
20 |
21 | @Autowired
22 | private IMessage message;
23 |
24 | @RequestMapping("/applyAddFriend")
25 | public void applyAddFriend(HttpServletRequest request, HttpServletResponse response) throws IOException {
26 | Integer uid = Integer.valueOf(request.getParameter("uid"));
27 | Integer toUid = Integer.valueOf(request.getParameter("toUid"));
28 | Integer from_group = Integer.valueOf(request.getParameter("from_group"));
29 | String remark = request.getParameter("remark");
30 | JsonResult result = message.applyAddFriend(uid, toUid, from_group, remark);
31 | sendResult(response,result);
32 | }
33 |
34 | @RequestMapping("/getMsgbox")
35 | public void getMsgbox(HttpServletRequest request, HttpServletResponse response) throws IOException {
36 | Integer uid = Integer.valueOf(request.getParameter("uid"));
37 | Integer page = Integer.valueOf(request.getParameter("page"));
38 | JsonPageResult result = message.getMessageBox(uid,page);
39 | sendResult(response,result);
40 | }
41 |
42 | @RequestMapping("/agreeFriend")
43 | public void agreeFriend(HttpServletRequest request, HttpServletResponse response) throws IOException {
44 | Integer uid = Integer.valueOf(request.getParameter("uid"));
45 | Integer from_uid = Integer.valueOf(request.getParameter("from_uid"));
46 | Integer group = Integer.valueOf(request.getParameter("group"));
47 | JsonResult result = message.agreeAddFriend(uid, from_uid, group);
48 | sendResult(response,result);
49 | }
50 |
51 | @RequestMapping("/ignoreAddFriend")
52 | public void ignoreAddFriend(HttpServletRequest request, HttpServletResponse response) throws IOException {
53 | Integer uid = Integer.valueOf(request.getParameter("uid"));
54 | Integer from_uid = Integer.valueOf(request.getParameter("from_uid"));
55 | JsonResult result = message.ignoreAddFriend(uid, from_uid);
56 | sendResult(response,result);
57 | }
58 | // @RequestMapping("/searchUser")
59 | // public void searchUser(HttpServletRequest request, HttpServletResponse response) throws IOException {
60 | // String keyword = request.getParameter("keyword");
61 | // keyword =new String(keyword.getBytes("ISO-8859-1"), "UTF-8");
62 | // JsonResult result = information.searchUserByKeyword(keyword);
63 | // sendResult(response,result);
64 | // }
65 |
66 | public void sendResult(HttpServletResponse response,Object result) throws IOException{
67 | response.setCharacterEncoding("UTF-8");
68 | IJsonSerializer serializer = WebChatFactory.createSerializer();
69 | response.getWriter().write(serializer.toJSON(result));
70 | }
71 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/ApplyMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.ices.yangengzhe.persistence.pojo.Apply;
8 | import com.ices.yangengzhe.persistence.pojo.ApplyKey;
9 |
10 | public interface ApplyMapper {
11 | int deleteByPrimaryKey(ApplyKey key);
12 |
13 | int insert(Apply record);
14 |
15 | int insertSelective(Apply record);
16 |
17 | Apply selectByPrimaryKey(ApplyKey key);
18 |
19 | int updateByPrimaryKeySelective(Apply record);
20 |
21 | int updateByPrimaryKey(Apply record);
22 |
23 | List selectByUID(@Param("uid")Integer uid,@Param("offset")Integer offset,@Param("count")Integer count);
24 |
25 | int countByUID(@Param("uid")Integer uid);
26 |
27 | int countByFromUid(@Param("fromuser")Integer fromuser,@Param("uid")Integer uid);
28 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/FriendgroupDetailMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.ices.yangengzhe.persistence.pojo.FriendgroupDetail;
8 |
9 | public interface FriendgroupDetailMapper {
10 |
11 | List selectUsersByFID(Integer fid);
12 |
13 | List selectUsersByFIDUID(@Param("fid")Integer fid,@Param("uid")Integer uid);
14 |
15 | int deleteByPrimaryKey(Integer id);
16 |
17 | int insert(FriendgroupDetail record);
18 |
19 | FriendgroupDetail selectByPrimaryKey(Integer id);
20 |
21 | int countfidOwnerUid(@Param("fidOwner")Integer fidOwner,@Param("uid")Integer uid);
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/FriendgroupMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.ices.yangengzhe.persistence.pojo.Friendgroup;
8 |
9 | public interface FriendgroupMapper {
10 |
11 | List selectByUID(Integer uid);
12 |
13 | int deleteByPrimaryKey(Integer id);
14 |
15 | int insert(Friendgroup record);
16 |
17 | int insertSelective(Friendgroup record);
18 |
19 | List selectByNameUID(@Param("name")String name,@Param("uid")Integer uid);
20 |
21 | Friendgroup selectByPrimaryKey(Integer id);
22 |
23 | int updateByPrimaryKeySelective(Friendgroup record);
24 |
25 | int updateByPrimaryKey(Friendgroup record);
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/GroupDetailMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.ices.yangengzhe.persistence.pojo.GroupDetail;
8 |
9 | public interface GroupDetailMapper {
10 | int deleteByUIDGID(@Param("uid") Integer uid,@Param("gid") Integer gid);
11 |
12 | int insert(GroupDetail record);
13 |
14 | List selectByUID(Integer uid);
15 |
16 | List selectByGID(Integer gid);
17 |
18 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/GroupMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import com.ices.yangengzhe.persistence.pojo.Group;
4 |
5 | public interface GroupMapper {
6 | int deleteByPrimaryKey(Integer id);
7 |
8 | int insert(Group record);
9 |
10 | int insertSelective(Group record);
11 |
12 | Group selectByPrimaryKey(Integer id);
13 |
14 | int updateByPrimaryKeySelective(Group record);
15 |
16 | int updateByPrimaryKey(Group record);
17 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/MessageBoxMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.ices.yangengzhe.persistence.pojo.MessageBox;
8 |
9 | public interface MessageBoxMapper {
10 | int deleteByPrimaryKey(Integer id);
11 |
12 | int insert(MessageBox record);
13 |
14 | int insertSelective(MessageBox record);
15 |
16 | MessageBox selectByPrimaryKey(Integer id);
17 |
18 | int updateByPrimaryKeySelective(MessageBox record);
19 |
20 | int updateByPrimaryKey(MessageBox record);
21 |
22 | int countByUid(int uid);
23 |
24 | List selectByUid(@Param("uid")Integer uid,@Param("offset")Integer offset,@Param("count")Integer count);
25 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/MsgMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.ices.yangengzhe.persistence.pojo.Msg;
8 |
9 | public interface MsgMapper {
10 |
11 | List selectByUIDTop(@Param("uid")Integer uid,@Param("num")Integer num);
12 | List selectByFUIDTop(@Param("fromuser")Integer fromuser,@Param("uid")Integer uid,@Param("num")Integer num);
13 | List selectByGIDTop(@Param("gid")Integer gid,@Param("num")Integer num);
14 | List selectByFromIDTop(@Param("fromuser")Integer fromuser,@Param("num")Integer num);
15 |
16 | int deleteByPrimaryKey(Integer id);
17 |
18 | int insert(Msg record);
19 |
20 | int insertSelective(Msg record);
21 |
22 | Msg selectByPrimaryKey(Integer id);
23 |
24 | int updateByPrimaryKeySelective(Msg record);
25 |
26 | int updateByPrimaryKey(Msg record);
27 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/MsgUnreadMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.ices.yangengzhe.persistence.pojo.MsgUnread;
8 |
9 | public interface MsgUnreadMapper {
10 | //id 接收者(好友或群) gid 0代表好友 1代表群 fromuser表示发送者
11 |
12 | //删除
13 | int deleteMsg(@Param("id")Integer id,@Param("gid")Integer gid,@Param("fromuser")Integer fromuser,@Param("uid")Integer uid);
14 | //自动插入
15 | int countMsg(@Param("id")Integer id,@Param("gid")Integer gid,@Param("fromuser")Integer fromuser,@Param("uid")Integer uid);
16 |
17 | //自己的好友: id = 自己UID 且 gid=0
18 | //自己的群: id = 自己群ID 且 gid=1
19 | List selectByGidId(@Param("gid")Integer gid,@Param("id")Integer id,@Param("uid")Integer uid);
20 |
21 | int insertSelective(MsgUnread record);
22 |
23 | int updateByPrimaryKeySelective(MsgUnread record);
24 |
25 | int updateByPrimaryKey(MsgUnread record);
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/UserLogMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import com.ices.yangengzhe.persistence.pojo.UserLog;
4 |
5 | public interface UserLogMapper {
6 | int deleteByPrimaryKey(Integer id);
7 |
8 | int insert(UserLog record);
9 |
10 | int insertSelective(UserLog record);
11 |
12 | UserLog selectByPrimaryKey(Integer id);
13 |
14 | int updateByPrimaryKeySelective(UserLog record);
15 |
16 | int updateByPrimaryKey(UserLog record);
17 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/dao/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.dao;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.ices.yangengzhe.persistence.pojo.User;
8 |
9 | public interface UserMapper {
10 |
11 | User selectByUID(Integer uid);
12 |
13 | int deleteByPrimaryKey(Integer id);
14 |
15 | int insert(User record);
16 |
17 | int insertSelective(User record);
18 |
19 | User selectByPrimaryKey(Integer id);
20 |
21 | int updateByPrimaryKeySelective(User record);
22 |
23 | int updateByPrimaryKey(User record);
24 |
25 | List searchUserByKeyword(@Param("keyword")String keyword);
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/ApplyMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | fromuser, uid, fromuser_fid, addtime, msg
13 |
14 |
21 |
22 |
30 |
31 |
37 |
38 |
44 |
45 |
46 | delete from webchat_apply
47 | where fromuser = #{fromuser,jdbcType=INTEGER}
48 | and uid = #{uid,jdbcType=INTEGER}
49 |
50 |
51 | insert into webchat_apply (fromuser, uid, fromuser_fid,
52 | addtime, msg)
53 | values (#{fromuser,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{fromuserFid,jdbcType=INTEGER},
54 | #{addtime,jdbcType=TIMESTAMP}, #{msg,jdbcType=VARCHAR})
55 |
56 |
57 | insert into webchat_apply
58 |
59 |
60 | fromuser,
61 |
62 |
63 | uid,
64 |
65 |
66 | fromuser_fid,
67 |
68 |
69 | addtime,
70 |
71 |
72 | msg,
73 |
74 |
75 |
76 |
77 | #{fromuser,jdbcType=INTEGER},
78 |
79 |
80 | #{uid,jdbcType=INTEGER},
81 |
82 |
83 | #{fromuserFid,jdbcType=INTEGER},
84 |
85 |
86 | #{addtime,jdbcType=TIMESTAMP},
87 |
88 |
89 | #{msg,jdbcType=VARCHAR},
90 |
91 |
92 |
93 |
94 | update webchat_apply
95 |
96 |
97 | fromuser_fid = #{fromuserFid,jdbcType=INTEGER},
98 |
99 |
100 | addtime = #{addtime,jdbcType=TIMESTAMP},
101 |
102 |
103 | msg = #{msg,jdbcType=VARCHAR},
104 |
105 |
106 | where fromuser = #{fromuser,jdbcType=INTEGER}
107 | and uid = #{uid,jdbcType=INTEGER}
108 |
109 |
110 | update webchat_apply
111 | set fromuser_fid = #{fromuserFid,jdbcType=INTEGER},
112 | addtime = #{addtime,jdbcType=TIMESTAMP},
113 | msg = #{msg,jdbcType=VARCHAR}
114 | where fromuser = #{fromuser,jdbcType=INTEGER}
115 | and uid = #{uid,jdbcType=INTEGER}
116 |
117 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/FriendgroupDetailMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | id, fid_owner,fid, uid
15 |
16 |
22 |
28 |
34 |
40 |
41 | delete from webchat_friendgroup_detail
42 | where id = #{id,jdbcType=INTEGER}
43 |
44 |
45 | insert into webchat_friendgroup_detail (id, fid_owner,fid, uid)
46 | values (#{id,jdbcType=INTEGER}, #{fidOwner,jdbcType=INTEGER}, #{fid,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER})
47 |
48 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/FriendgroupMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | id, name, uid, addtime, sort
13 |
14 |
20 |
26 |
32 |
33 | delete from webchat_friendgroup
34 | where id = #{id,jdbcType=INTEGER}
35 |
36 |
37 | insert into webchat_friendgroup (id, name, uid,
38 | addtime, sort)
39 | values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{uid,jdbcType=INTEGER},
40 | #{addtime,jdbcType=TIMESTAMP}, #{sort,jdbcType=INTEGER})
41 |
42 |
43 | insert into webchat_friendgroup
44 |
45 |
46 | id,
47 |
48 |
49 | name,
50 |
51 |
52 | uid,
53 |
54 |
55 | addtime,
56 |
57 |
58 | sort,
59 |
60 |
61 |
62 |
63 | #{id,jdbcType=INTEGER},
64 |
65 |
66 | #{name,jdbcType=VARCHAR},
67 |
68 |
69 | #{uid,jdbcType=INTEGER},
70 |
71 |
72 | #{addtime,jdbcType=TIMESTAMP},
73 |
74 |
75 | #{sort,jdbcType=INTEGER},
76 |
77 |
78 |
79 |
80 | update webchat_friendgroup
81 |
82 |
83 | name = #{name,jdbcType=VARCHAR},
84 |
85 |
86 | uid = #{uid,jdbcType=INTEGER},
87 |
88 |
89 | addtime = #{addtime,jdbcType=TIMESTAMP},
90 |
91 |
92 | sort = #{sort,jdbcType=INTEGER},
93 |
94 |
95 | where id = #{id,jdbcType=INTEGER}
96 |
97 |
98 | update webchat_friendgroup
99 | set name = #{name,jdbcType=VARCHAR},
100 | uid = #{uid,jdbcType=INTEGER},
101 | addtime = #{addtime,jdbcType=TIMESTAMP},
102 | sort = #{sort,jdbcType=INTEGER}
103 | where id = #{id,jdbcType=INTEGER}
104 |
105 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/GroupDetailMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | gid, uid, addtime
11 |
12 |
18 |
24 |
25 | delete from webchat_group_detail
26 | where gid = #{gid,jdbcType=INTEGER} and uid = #{uid,jdbcType=INTEGER}
27 |
28 |
29 | insert into webchat_group_detail (gid, uid,
30 | addtime)
31 | values (#{gid,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
32 | #{addtime,jdbcType=TIMESTAMP})
33 |
34 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/GroupMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | id, name, headphoto, _desc, owner_uid, addtime
14 |
15 |
21 |
22 | delete from webchat_groups
23 | where id = #{id,jdbcType=INTEGER}
24 |
25 |
26 | insert into webchat_groups (id, name,
27 | headphoto, _desc, owner_uid,
28 | addtime)
29 | values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
30 | #{headphoto,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}, #{ownerUid,jdbcType=INTEGER},
31 | #{addtime,jdbcType=TIMESTAMP})
32 |
33 |
34 | insert into webchat_groups
35 |
36 |
37 | id,
38 |
39 |
40 | name,
41 |
42 |
43 | headphoto,
44 |
45 |
46 | _desc,
47 |
48 |
49 | owner_uid,
50 |
51 |
52 | addtime,
53 |
54 |
55 |
56 |
57 | #{id,jdbcType=INTEGER},
58 |
59 |
60 | #{name,jdbcType=VARCHAR},
61 |
62 |
63 | #{headphoto,jdbcType=VARCHAR},
64 |
65 |
66 | #{desc,jdbcType=VARCHAR},
67 |
68 |
69 | #{ownerUid,jdbcType=INTEGER},
70 |
71 |
72 | #{addtime,jdbcType=TIMESTAMP},
73 |
74 |
75 |
76 |
77 | update webchat_groups
78 |
79 |
80 | name = #{name,jdbcType=VARCHAR},
81 |
82 |
83 | headphoto = #{headphoto,jdbcType=VARCHAR},
84 |
85 |
86 | _desc = #{desc,jdbcType=VARCHAR},
87 |
88 |
89 | owner_uid = #{ownerUid,jdbcType=INTEGER},
90 |
91 |
92 | addtime = #{addtime,jdbcType=TIMESTAMP},
93 |
94 |
95 | where id = #{id,jdbcType=INTEGER}
96 |
97 |
98 | update webchat_groups
99 | set
100 | name = #{name,jdbcType=VARCHAR},
101 | headphoto = #{headphoto,jdbcType=VARCHAR},
102 | _desc = #{desc,jdbcType=VARCHAR},
103 | owner_uid = #{ownerUid,jdbcType=INTEGER},
104 | addtime = #{addtime,jdbcType=TIMESTAMP}
105 | where id = #{id,jdbcType=INTEGER}
106 |
107 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/MessageBoxMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | id, uid, content, addtime
12 |
13 |
19 |
25 |
26 |
34 |
35 |
36 | delete from webchat_messagebox
37 | where id = #{id,jdbcType=INTEGER}
38 |
39 |
40 | insert into webchat_messagebox (id, uid, content,
41 | addtime)
42 | values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR},
43 | #{addtime,jdbcType=TIMESTAMP})
44 |
45 |
46 | insert into webchat_messagebox
47 |
48 |
49 | id,
50 |
51 |
52 | uid,
53 |
54 |
55 | content,
56 |
57 |
58 | addtime,
59 |
60 |
61 |
62 |
63 | #{id,jdbcType=INTEGER},
64 |
65 |
66 | #{uid,jdbcType=INTEGER},
67 |
68 |
69 | #{content,jdbcType=VARCHAR},
70 |
71 |
72 | #{addtime,jdbcType=TIMESTAMP},
73 |
74 |
75 |
76 |
77 | update webchat_messagebox
78 |
79 |
80 | uid = #{uid,jdbcType=INTEGER},
81 |
82 |
83 | content = #{content,jdbcType=VARCHAR},
84 |
85 |
86 | addtime = #{addtime,jdbcType=TIMESTAMP},
87 |
88 |
89 | where id = #{id,jdbcType=INTEGER}
90 |
91 |
92 | update webchat_messagebox
93 | set uid = #{uid,jdbcType=INTEGER},
94 | content = #{content,jdbcType=VARCHAR},
95 | addtime = #{addtime,jdbcType=TIMESTAMP}
96 | where id = #{id,jdbcType=INTEGER}
97 |
98 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/MsgMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | id, uid, fromuser, gid, msg, addtime
14 |
15 |
23 |
31 |
32 |
40 |
41 |
49 |
50 |
56 |
57 | delete from webchat_msg
58 | where id = #{id,jdbcType=INTEGER}
59 |
60 |
61 | insert into webchat_msg (id, uid, fromuser,
62 | gid, msg, addtime
63 | )
64 | values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{fromuser,jdbcType=INTEGER},
65 | #{gid,jdbcType=INTEGER}, #{msg,jdbcType=VARCHAR}, #{addtime,jdbcType=TIMESTAMP}
66 | )
67 |
68 |
69 | insert into webchat_msg
70 |
71 |
72 | id,
73 |
74 |
75 | uid,
76 |
77 |
78 | fromuser,
79 |
80 |
81 | gid,
82 |
83 |
84 | msg,
85 |
86 |
87 | addtime,
88 |
89 |
90 |
91 |
92 | #{id,jdbcType=INTEGER},
93 |
94 |
95 | #{uid,jdbcType=INTEGER},
96 |
97 |
98 | #{fromuser,jdbcType=INTEGER},
99 |
100 |
101 | #{gid,jdbcType=INTEGER},
102 |
103 |
104 | #{msg,jdbcType=VARCHAR},
105 |
106 |
107 | #{addtime,jdbcType=TIMESTAMP},
108 |
109 |
110 |
111 |
112 | update webchat_msg
113 |
114 |
115 | uid = #{uid,jdbcType=INTEGER},
116 |
117 |
118 | fromuser = #{fromuser,jdbcType=INTEGER},
119 |
120 |
121 | gid = #{gid,jdbcType=INTEGER},
122 |
123 |
124 | msg = #{msg,jdbcType=VARCHAR},
125 |
126 |
127 | addtime = #{addtime,jdbcType=TIMESTAMP},
128 |
129 |
130 | where id = #{id,jdbcType=INTEGER}
131 |
132 |
133 | update webchat_msg
134 | set uid = #{uid,jdbcType=INTEGER},
135 | fromuser = #{fromuser,jdbcType=INTEGER},
136 | gid = #{gid,jdbcType=INTEGER},
137 | msg = #{msg,jdbcType=VARCHAR},
138 | addtime = #{addtime,jdbcType=TIMESTAMP}
139 | where id = #{id,jdbcType=INTEGER}
140 |
141 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/MsgUnreadMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | id, uid, fromuser, gid, updatetime, msgcount
15 |
16 |
22 |
23 | delete from
24 | webchat_msg_unread
25 | where id = #{id,jdbcType=INTEGER} and gid = #{gid,jdbcType=INTEGER} and fromuser = #{fromuser,jdbcType=INTEGER} and uid = #{uid,jdbcType=INTEGER}
26 |
27 |
28 | {
29 | call msgcounts(
30 | #{id,jdbcType=INTEGER,mode=IN},
31 | #{gid,jdbcType=INTEGER,mode=IN},
32 | #{fromuser,jdbcType=INTEGER,mode=IN},
33 | #{uid,jdbcType=INTEGER,mode=IN}
34 | )
35 | }
36 |
37 |
38 |
39 | insert into webchat_msg_unread
40 |
41 |
42 | id,
43 |
44 |
45 | uid,
46 |
47 |
48 | fromuser,
49 |
50 |
51 | gid,
52 |
53 |
54 | updatetime,
55 |
56 |
57 | msgcount,
58 |
59 |
60 |
61 |
62 | #{id,jdbcType=INTEGER},
63 |
64 |
65 | #{uid,jdbcType=INTEGER},
66 |
67 |
68 | #{fromuser,jdbcType=INTEGER},
69 |
70 |
71 | #{gid,jdbcType=INTEGER},
72 |
73 |
74 | #{updatetime,jdbcType=TIMESTAMP},
75 |
76 |
77 | #{msgcount,jdbcType=INTEGER},
78 |
79 |
80 |
81 |
82 | update webchat_msg_unread
83 |
84 |
85 | uid = #{uid,jdbcType=INTEGER},
86 |
87 |
88 | fromuser = #{fromuser,jdbcType=INTEGER},
89 |
90 |
91 | gid = #{gid,jdbcType=INTEGER},
92 |
93 |
94 | updatetime = #{updatetime,jdbcType=TIMESTAMP},
95 |
96 |
97 | msgcount = #{msgcount,jdbcType=INTEGER},
98 |
99 |
100 | where id = #{id,jdbcType=INTEGER}
101 |
102 |
103 | update webchat_msg_unread
104 | set uid = #{uid,jdbcType=INTEGER},
105 | fromuser =
106 | #{fromuser,jdbcType=INTEGER},
107 | gid = #{gid,jdbcType=INTEGER},
108 | updatetime
109 | = #{updatetime,jdbcType=TIMESTAMP},
110 | msgcount =
111 | #{msgcount,jdbcType=INTEGER}
112 | where id = #{id,jdbcType=INTEGER}
113 |
114 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/UserLogMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | id, uid, ip, addtime, log
13 |
14 |
20 |
21 | delete from webchat_user_log
22 | where id = #{id,jdbcType=INTEGER}
23 |
24 |
25 | insert into webchat_user_log (id, uid, ip,
26 | addtime, log)
27 | values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{ip,jdbcType=VARCHAR},
28 | #{addtime,jdbcType=TIMESTAMP}, #{log,jdbcType=VARCHAR})
29 |
30 |
31 | insert into webchat_user_log
32 |
33 |
34 | id,
35 |
36 |
37 | uid,
38 |
39 |
40 | ip,
41 |
42 |
43 | addtime,
44 |
45 |
46 | log,
47 |
48 |
49 |
50 |
51 | #{id,jdbcType=INTEGER},
52 |
53 |
54 | #{uid,jdbcType=INTEGER},
55 |
56 |
57 | #{ip,jdbcType=VARCHAR},
58 |
59 |
60 | #{addtime,jdbcType=TIMESTAMP},
61 |
62 |
63 | #{log,jdbcType=VARCHAR},
64 |
65 |
66 |
67 |
68 | update webchat_user_log
69 |
70 |
71 | uid = #{uid,jdbcType=INTEGER},
72 |
73 |
74 | ip = #{ip,jdbcType=VARCHAR},
75 |
76 |
77 | addtime = #{addtime,jdbcType=TIMESTAMP},
78 |
79 |
80 | log = #{log,jdbcType=VARCHAR},
81 |
82 |
83 | where id = #{id,jdbcType=INTEGER}
84 |
85 |
86 | update webchat_user_log
87 | set uid = #{uid,jdbcType=INTEGER},
88 | ip = #{ip,jdbcType=VARCHAR},
89 | addtime = #{addtime,jdbcType=TIMESTAMP},
90 | log = #{log,jdbcType=VARCHAR}
91 | where id = #{id,jdbcType=INTEGER}
92 |
93 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/mapping/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | id, uid, name, password, sign, headphoto, addtime, online
16 |
17 |
23 |
29 |
36 |
37 | delete from webchat_user
38 | where id = #{id,jdbcType=INTEGER}
39 |
40 |
41 | insert into webchat_user (id, uid, name,
42 | password, sign, headphoto,
43 | addtime, online)
44 | values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
45 | #{password,jdbcType=VARCHAR}, #{sign,jdbcType=VARCHAR}, #{headphoto,jdbcType=VARCHAR},
46 | #{addtime,jdbcType=TIMESTAMP}, #{online,jdbcType=INTEGER})
47 |
48 |
49 | insert into webchat_user
50 |
51 |
52 | id,
53 |
54 |
55 | uid,
56 |
57 |
58 | name,
59 |
60 |
61 | password,
62 |
63 |
64 | sign,
65 |
66 |
67 | headphoto,
68 |
69 |
70 | addtime,
71 |
72 |
73 | online,
74 |
75 |
76 |
77 |
78 | #{id,jdbcType=INTEGER},
79 |
80 |
81 | #{uid,jdbcType=INTEGER},
82 |
83 |
84 | #{name,jdbcType=VARCHAR},
85 |
86 |
87 | #{password,jdbcType=VARCHAR},
88 |
89 |
90 | #{sign,jdbcType=VARCHAR},
91 |
92 |
93 | #{headphoto,jdbcType=VARCHAR},
94 |
95 |
96 | #{addtime,jdbcType=TIMESTAMP},
97 |
98 |
99 | #{online,jdbcType=INTEGER},
100 |
101 |
102 |
103 |
104 | update webchat_user
105 |
106 |
107 | uid = #{uid,jdbcType=INTEGER},
108 |
109 |
110 | name = #{name,jdbcType=VARCHAR},
111 |
112 |
113 | password = #{password,jdbcType=VARCHAR},
114 |
115 |
116 | sign = #{sign,jdbcType=VARCHAR},
117 |
118 |
119 | headphoto = #{headphoto,jdbcType=VARCHAR},
120 |
121 |
122 | addtime = #{addtime,jdbcType=TIMESTAMP},
123 |
124 |
125 | online = #{online,jdbcType=INTEGER},
126 |
127 |
128 | where id = #{id,jdbcType=INTEGER}
129 |
130 |
131 | update webchat_user
132 | set uid = #{uid,jdbcType=INTEGER},
133 | name = #{name,jdbcType=VARCHAR},
134 | password = #{password,jdbcType=VARCHAR},
135 | sign = #{sign,jdbcType=VARCHAR},
136 | headphoto = #{headphoto,jdbcType=VARCHAR},
137 | addtime = #{addtime,jdbcType=TIMESTAMP},
138 | online = #{online,jdbcType=INTEGER}
139 | where id = #{id,jdbcType=INTEGER}
140 |
141 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/Apply.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class Apply extends ApplyKey {
6 | private Integer fromuserFid;
7 |
8 | private Date addtime;
9 |
10 | private String msg;
11 |
12 | public Integer getFromuserFid() {
13 | return fromuserFid;
14 | }
15 |
16 | public void setFromuserFid(Integer fromuserFid) {
17 | this.fromuserFid = fromuserFid;
18 | }
19 |
20 | public Date getAddtime() {
21 | return addtime;
22 | }
23 |
24 | public void setAddtime(Date addtime) {
25 | this.addtime = addtime;
26 | }
27 |
28 | public String getMsg() {
29 | return msg;
30 | }
31 |
32 | public void setMsg(String msg) {
33 | this.msg = msg == null ? null : msg.trim();
34 | }
35 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/ApplyKey.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | public class ApplyKey {
4 | private Integer fromuser;
5 |
6 | private Integer uid;
7 |
8 | public Integer getFromuser() {
9 | return fromuser;
10 | }
11 |
12 | public void setFromuser(Integer fromuser) {
13 | this.fromuser = fromuser;
14 | }
15 |
16 | public Integer getUid() {
17 | return uid;
18 | }
19 |
20 | public void setUid(Integer uid) {
21 | this.uid = uid;
22 | }
23 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/Friendgroup.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class Friendgroup {
6 | private Integer id;
7 |
8 | private String name;
9 |
10 | private Integer uid;
11 |
12 | private Date addtime;
13 |
14 | private Integer sort;
15 |
16 | public Integer getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Integer id) {
21 | this.id = id;
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name == null ? null : name.trim();
30 | }
31 |
32 | public Integer getUid() {
33 | return uid;
34 | }
35 |
36 | public void setUid(Integer uid) {
37 | this.uid = uid;
38 | }
39 |
40 | public Date getAddtime() {
41 | return addtime;
42 | }
43 |
44 | public void setAddtime(Date addtime) {
45 | this.addtime = addtime;
46 | }
47 |
48 | public Integer getSort() {
49 | return sort;
50 | }
51 |
52 | public void setSort(Integer sort) {
53 | this.sort = sort;
54 | }
55 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/FriendgroupDetail.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | public class FriendgroupDetail {
4 | private Integer id;
5 |
6 | private Integer fidOwner;
7 |
8 | private Integer fid;
9 |
10 | private Integer uid;
11 |
12 | private User user;
13 |
14 |
15 | public User getUser() {
16 | return user;
17 | }
18 |
19 |
20 | public void setUser(User user) {
21 | this.user = user;
22 | }
23 |
24 |
25 | public Integer getFidOwner() {
26 | return fidOwner;
27 | }
28 |
29 |
30 |
31 | public void setFidOwner(Integer fidOwner) {
32 | this.fidOwner = fidOwner;
33 | }
34 |
35 |
36 | public Integer getId() {
37 | return id;
38 | }
39 |
40 | public void setId(Integer id) {
41 | this.id = id;
42 | }
43 |
44 | public Integer getFid() {
45 | return fid;
46 | }
47 |
48 | public void setFid(Integer fid) {
49 | this.fid = fid;
50 | }
51 |
52 | public Integer getUid() {
53 | return uid;
54 | }
55 |
56 | public void setUid(Integer uid) {
57 | this.uid = uid;
58 | }
59 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/Group.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class Group {
6 | private Integer id;
7 |
8 | private String name;
9 |
10 | private String headphoto;
11 |
12 | private String desc;
13 |
14 | private Integer ownerUid;
15 |
16 | private Date addtime;
17 |
18 | public Integer getId() {
19 | return id;
20 | }
21 |
22 | public void setId(Integer id) {
23 | this.id = id;
24 | }
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name == null ? null : name.trim();
32 | }
33 |
34 | public String getHeadphoto() {
35 | return headphoto;
36 | }
37 |
38 | public void setHeadphoto(String headphoto) {
39 | this.headphoto = headphoto == null ? null : headphoto.trim();
40 | }
41 |
42 | public String getDesc() {
43 | return desc;
44 | }
45 |
46 | public void setDesc(String desc) {
47 | this.desc = desc == null ? null : desc.trim();
48 | }
49 |
50 | public Integer getOwnerUid() {
51 | return ownerUid;
52 | }
53 |
54 | public void setOwnerUid(Integer ownerUid) {
55 | this.ownerUid = ownerUid;
56 | }
57 |
58 | public Date getAddtime() {
59 | return addtime;
60 | }
61 |
62 | public void setAddtime(Date addtime) {
63 | this.addtime = addtime;
64 | }
65 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/GroupDetail.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class GroupDetail {
6 | private Integer gid;
7 |
8 | private Integer uid;
9 |
10 | private Date addtime;
11 |
12 | public Integer getGid() {
13 | return gid;
14 | }
15 |
16 | public void setGid(Integer gid) {
17 | this.gid = gid;
18 | }
19 |
20 | public Integer getUid() {
21 | return uid;
22 | }
23 |
24 | public void setUid(Integer uid) {
25 | this.uid = uid;
26 | }
27 |
28 | public Date getAddtime() {
29 | return addtime;
30 | }
31 |
32 | public void setAddtime(Date addtime) {
33 | this.addtime = addtime;
34 | }
35 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/MessageBox.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class MessageBox {
6 | private Integer id;
7 |
8 | private Integer uid;
9 |
10 | private String content;
11 |
12 | private Date addtime;
13 |
14 | public Integer getId() {
15 | return id;
16 | }
17 |
18 | public void setId(Integer id) {
19 | this.id = id;
20 | }
21 |
22 | public Integer getUid() {
23 | return uid;
24 | }
25 |
26 | public void setUid(Integer uid) {
27 | this.uid = uid;
28 | }
29 |
30 | public String getContent() {
31 | return content;
32 | }
33 |
34 | public void setContent(String content) {
35 | this.content = content == null ? null : content.trim();
36 | }
37 |
38 | public Date getAddtime() {
39 | return addtime;
40 | }
41 |
42 | public void setAddtime(Date addtime) {
43 | this.addtime = addtime;
44 | }
45 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/Msg.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class Msg {
6 | private Integer id;
7 |
8 | private Integer uid;
9 |
10 | private Integer fromuser;
11 |
12 | private Integer gid;
13 |
14 | private String msg;
15 |
16 | private Date addtime;
17 |
18 | public Integer getId() {
19 | return id;
20 | }
21 |
22 | public void setId(Integer id) {
23 | this.id = id;
24 | }
25 |
26 | public Integer getUid() {
27 | return uid;
28 | }
29 |
30 | public void setUid(Integer uid) {
31 | this.uid = uid;
32 | }
33 |
34 | public Integer getFromuser() {
35 | return fromuser;
36 | }
37 |
38 | public void setFromuser(Integer fromuser) {
39 | this.fromuser = fromuser;
40 | }
41 |
42 | public Integer getGid() {
43 | return gid;
44 | }
45 |
46 | public void setGid(Integer gid) {
47 | this.gid = gid;
48 | }
49 |
50 | public String getMsg() {
51 | return msg;
52 | }
53 |
54 | public void setMsg(String msg) {
55 | this.msg = msg == null ? null : msg.trim();
56 | }
57 |
58 | public Date getAddtime() {
59 | return addtime;
60 | }
61 |
62 | public void setAddtime(Date addtime) {
63 | this.addtime = addtime;
64 | }
65 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/MsgUnread.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class MsgUnread {
6 | private Integer id;
7 |
8 | private Integer uid;
9 |
10 | private Integer fromuser;
11 |
12 | private Integer gid;
13 |
14 | private Date updatetime;
15 |
16 | private Integer msgcount;
17 |
18 | public Integer getId() {
19 | return id;
20 | }
21 |
22 | public void setId(Integer id) {
23 | this.id = id;
24 | }
25 |
26 | public Integer getUid() {
27 | return uid;
28 | }
29 |
30 | public void setUid(Integer uid) {
31 | this.uid = uid;
32 | }
33 |
34 | public Integer getFromuser() {
35 | return fromuser;
36 | }
37 |
38 | public void setFromuser(Integer fromuser) {
39 | this.fromuser = fromuser;
40 | }
41 |
42 | public Integer getGid() {
43 | return gid;
44 | }
45 |
46 | public void setGid(Integer gid) {
47 | this.gid = gid;
48 | }
49 |
50 | public Date getUpdatetime() {
51 | return updatetime;
52 | }
53 |
54 | public void setUpdatetime(Date updatetime) {
55 | this.updatetime = updatetime;
56 | }
57 |
58 | public Integer getMsgcount() {
59 | return msgcount;
60 | }
61 |
62 | public void setMsgcount(Integer msgcount) {
63 | this.msgcount = msgcount;
64 | }
65 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/User.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class User {
6 | private Integer id;
7 |
8 | private Integer uid;
9 |
10 | private String name;
11 |
12 | private String password;
13 |
14 | private String sign;
15 |
16 | private String headphoto;
17 |
18 | private Date addtime;
19 |
20 | private Integer online;
21 |
22 | public Integer getId() {
23 | return id;
24 | }
25 |
26 | public void setId(Integer id) {
27 | this.id = id;
28 | }
29 |
30 | public Integer getUid() {
31 | return uid;
32 | }
33 |
34 | public void setUid(Integer uid) {
35 | this.uid = uid;
36 | }
37 |
38 | public String getName() {
39 | return name;
40 | }
41 |
42 | public void setName(String name) {
43 | this.name = name == null ? null : name.trim();
44 | }
45 |
46 | public String getPassword() {
47 | return password;
48 | }
49 |
50 | public void setPassword(String password) {
51 | this.password = password == null ? null : password.trim();
52 | }
53 |
54 | public String getSign() {
55 | return sign;
56 | }
57 |
58 | public void setSign(String sign) {
59 | this.sign = sign == null ? null : sign.trim();
60 | }
61 |
62 | public String getHeadphoto() {
63 | return headphoto;
64 | }
65 |
66 | public void setHeadphoto(String headphoto) {
67 | this.headphoto = headphoto == null ? null : headphoto.trim();
68 | }
69 |
70 | public Date getAddtime() {
71 | return addtime;
72 | }
73 |
74 | public void setAddtime(Date addtime) {
75 | this.addtime = addtime;
76 | }
77 |
78 | public Integer getOnline() {
79 | return online;
80 | }
81 |
82 | public void setOnline(Integer online) {
83 | this.online = online;
84 | }
85 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/persistence/pojo/UserLog.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.persistence.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class UserLog {
6 | private Integer id;
7 |
8 | private Integer uid;
9 |
10 | private String ip;
11 |
12 | private Date addtime;
13 |
14 | private String log;
15 |
16 | public Integer getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Integer id) {
21 | this.id = id;
22 | }
23 |
24 | public Integer getUid() {
25 | return uid;
26 | }
27 |
28 | public void setUid(Integer uid) {
29 | this.uid = uid;
30 | }
31 |
32 | public String getIp() {
33 | return ip;
34 | }
35 |
36 | public void setIp(String ip) {
37 | this.ip = ip == null ? null : ip.trim();
38 | }
39 |
40 | public Date getAddtime() {
41 | return addtime;
42 | }
43 |
44 | public void setAddtime(Date addtime) {
45 | this.addtime = addtime;
46 | }
47 |
48 | public String getLog() {
49 | return log;
50 | }
51 |
52 | public void setLog(String log) {
53 | this.log = log == null ? null : log.trim();
54 | }
55 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/api/IFriend.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.api;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 |
6 | import com.ices.yangengzhe.persistence.pojo.Friendgroup;
7 | import com.ices.yangengzhe.persistence.pojo.User;
8 |
9 | /**
10 | * @date 2017年1月24日 下午2:00:02
11 | * @author yangengzhe
12 | */
13 | public interface IFriend {
14 |
15 | // 创建好友分组
16 | int addFriendgroup(Integer uid, String groupname);
17 |
18 | // 创建好友分组
19 | int addFriendgroup(Integer uid, String groupname, List members);
20 |
21 | // 添加好友
22 | void addFriend(Integer user1,Integer user1_group,Integer user2,Integer user2_group);
23 | //向分组加成员
24 | void addMemberToFG(Integer groupId,Integer uid);
25 |
26 | // 获取分组列表
27 | public List getFriendgroupList(Integer uid);
28 |
29 | // 获取分组列表(含成员)
30 | public List> getFriendgroupDetaillist(Integer uid);
31 |
32 | // 获取好友分组的成员
33 | public List> getFridengroupMember(Integer fid);
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/api/IGroup.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.api;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 |
6 | import com.ices.yangengzhe.util.pojo.JsonResult;
7 |
8 | /**
9 | * @date 2017年1月27日 上午10:02:36
10 | * @author yangengzhe
11 | *
12 | */
13 | public interface IGroup {
14 | //创建空群
15 | int addGroup(Integer uid,String name);
16 |
17 | //创建带好友的群
18 | int addGroup(Integer uid,String name,List uids);
19 |
20 | //向群内添加成员
21 | void addMemberToGroup(Integer gid,Integer uid);
22 |
23 | //获取群列表
24 | List> getAllGroup(Integer uid);
25 |
26 | //查看群成员
27 | JsonResult getGroupMembers(Integer gid);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/api/IInformation.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.api;
2 |
3 | import java.util.HashMap;
4 |
5 | import com.ices.yangengzhe.persistence.pojo.User;
6 | import com.ices.yangengzhe.util.enums.ResponseType;
7 | import com.ices.yangengzhe.util.pojo.JsonResult;
8 |
9 | /**
10 | * @date 2017年1月23日 下午10:47:37
11 | * @author yangengzhe
12 | */
13 | public interface IInformation {
14 |
15 | public ResponseType getMyInformation(Integer uid, String password,HashMap map);
16 |
17 | //初始化方法
18 | public JsonResult init(Integer uid, String password);
19 |
20 | public void addUser(Integer uid,String name,String photo,String sign);
21 |
22 | public User findUserByUid(Integer uid);
23 |
24 | //查找好友
25 | public JsonResult searchUserByKeyword(String Keyword);
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/api/IMessage.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.api;
2 |
3 | import com.ices.yangengzhe.util.pojo.JsonPageResult;
4 | import com.ices.yangengzhe.util.pojo.JsonResult;
5 |
6 | /**
7 | * webChat
8 | * @date 2017年1月28日 下午10:00:30
9 | * @author gengzhe.ygz
10 | *
11 | */
12 | public interface IMessage {
13 | //消息盒子内容
14 | JsonPageResult getMessageBox(int uid,int page);
15 |
16 | //申请添加好友
17 | JsonResult applyAddFriend(int uid,int toUid,int from_group,String remark);
18 |
19 | //同意并添加好友
20 | JsonResult agreeAddFriend(int uid,int fromUid,int group);
21 |
22 | //忽略添加请求
23 | JsonResult ignoreAddFriend(int uid,int fromUid);
24 |
25 | //获得未处理消息数
26 | Integer countUnreadMessage(int uid);
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/api/impl/Friend.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.api.impl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | import com.ices.yangengzhe.persistence.pojo.Friendgroup;
11 | import com.ices.yangengzhe.persistence.pojo.FriendgroupDetail;
12 | import com.ices.yangengzhe.persistence.pojo.User;
13 | import com.ices.yangengzhe.service.api.IFriend;
14 | import com.ices.yangengzhe.service.persistence.IFriendgroupDetailService;
15 | import com.ices.yangengzhe.service.persistence.IFriendgroupService;
16 | import com.ices.yangengzhe.util.Global;
17 | import com.ices.yangengzhe.util.security.Security;
18 |
19 | @Service
20 | public class Friend implements IFriend {
21 |
22 | @Autowired
23 | private IFriendgroupService friendgroupService;
24 | @Autowired
25 | private IFriendgroupDetailService friendgroupDetailService;
26 |
27 | @Override
28 | public int addFriendgroup(Integer uid, String groupname) {
29 | return friendgroupService.insertFG(groupname, uid);
30 | }
31 |
32 | @Override
33 | public int addFriendgroup(Integer uid, String groupname, List members) {
34 | int groupId = addFriendgroup(uid,groupname);
35 | for (User user : members) {
36 | addMemberToFG(groupId, user.getUid());
37 | }
38 | return groupId;
39 | }
40 |
41 | @Override
42 | public void addFriend(Integer user1, Integer user1_group, Integer user2, Integer user2_group) {
43 | addMemberToFG(user1_group, user2);
44 | addMemberToFG(user2_group, user1);
45 | }
46 |
47 | @Override
48 | public void addMemberToFG(Integer groupId, Integer uid) {
49 | friendgroupDetailService.insertFG(groupId, uid);
50 | }
51 |
52 | @Override
53 | public List getFriendgroupList(Integer uid) {
54 | List friendgroups = friendgroupService.getFGByUID(uid);
55 | return friendgroups;
56 | }
57 |
58 | @Override
59 | public List> getFridengroupMember(Integer fid) {
60 | List> friend = new ArrayList>();
61 |
62 | List friendList = friendgroupDetailService.getFGMemberByFID(fid);
63 | for (FriendgroupDetail friendgroupDetail : friendList) {
64 | HashMap friendgroupDetail_map = new HashMap();
65 | friendgroupDetail_map.put("username", friendgroupDetail.getUser().getName());
66 | friendgroupDetail_map.put("id", friendgroupDetail.getUser().getUid());
67 | friendgroupDetail_map.put("avatar", Global.URL+friendgroupDetail.getUser().getHeadphoto());
68 | friendgroupDetail_map.put("sign", friendgroupDetail.getUser().getSign());
69 | if (Security.isLogin(friendgroupDetail.getUser().getUid())) friendgroupDetail_map.put("status", "online");
70 | else friendgroupDetail_map.put("status", "offline");
71 | friend.add(friendgroupDetail_map);
72 | }
73 | return friend;
74 | }
75 |
76 | @Override
77 | public List> getFriendgroupDetaillist(Integer uid) {
78 | List> friendgrouplist = new ArrayList>();
79 |
80 | List friendgroups = friendgroupService.getFGByUID(uid);
81 | for (Friendgroup friendgroup : friendgroups) {
82 | HashMap friendgroup_map = new HashMap();
83 | friendgroup_map.put("groupname", friendgroup.getName());
84 | friendgroup_map.put("id", friendgroup.getId());
85 | List> friend = getFridengroupMember(friendgroup.getId());
86 | friendgroup_map.put("list", friend);
87 | friendgrouplist.add(friendgroup_map);
88 | }
89 |
90 | return friendgrouplist;
91 | }
92 |
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/api/impl/Group.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.api.impl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | import com.ices.yangengzhe.persistence.pojo.User;
11 | import com.ices.yangengzhe.service.api.IGroup;
12 | import com.ices.yangengzhe.service.persistence.IGroupService;
13 | import com.ices.yangengzhe.util.Global;
14 | import com.ices.yangengzhe.util.enums.ResponseType;
15 | import com.ices.yangengzhe.util.pojo.JsonResult;
16 |
17 |
18 | /**
19 | * @date 2017年1月27日 上午10:03:27
20 | * @author yangengzhe
21 | *
22 | */
23 | @Service
24 | public class Group implements IGroup {
25 | @Autowired
26 | IGroupService groupService;
27 |
28 | @Override
29 | public int addGroup(Integer uid,String name) {
30 | return groupService.insertGroup(uid, name);
31 | }
32 |
33 | @Override
34 | public int addGroup(Integer uid,String name, List uids) {
35 | int groupId = groupService.insertGroup(uid, name);
36 | for (Integer integer : uids) {
37 | groupService.addMember(groupId, integer);
38 | }
39 | return groupId;
40 | }
41 |
42 | @Override
43 | public void addMemberToGroup(Integer gid, Integer uid) {
44 | groupService.addMember(gid, uid);
45 | }
46 |
47 | @Override
48 | public List> getAllGroup(Integer uid) {
49 | List groups = groupService.selectGroup(uid);
50 | List> result = new ArrayList>();
51 | for (com.ices.yangengzhe.persistence.pojo.Group group : groups) {
52 | HashMap map = new HashMap();
53 | map.put("groupname", group.getName());
54 | map.put("id", group.getId());
55 | map.put("avatar", Global.URL+group.getHeadphoto());
56 | result.add(map);
57 | }
58 | return result;
59 | }
60 |
61 | @Override
62 | public JsonResult getGroupMembers(Integer gid) {
63 |
64 | HashMap data = new HashMap();
65 | //owner
66 | HashMap owner =new HashMap();
67 | User user = groupService.getGroupOwner(gid);
68 | owner.put("username", user.getName());
69 | owner.put("id", user.getUid());
70 | owner.put("avatar", Global.URL+user.getHeadphoto());
71 | owner.put("sign", user.getSign());
72 | data.put("owner", owner);
73 |
74 | //list
75 | List> memberslist = new ArrayList>();
76 | List userlist = groupService.getAllMember(gid);
77 | for (User user2 : userlist) {
78 | HashMap userMap =new HashMap();
79 | userMap.put("username", user2.getName());
80 | userMap.put("id", user2.getUid());
81 | userMap.put("avatar", Global.URL+user2.getHeadphoto());
82 | userMap.put("sign", user2.getSign());
83 | memberslist.add(userMap);
84 | }
85 | data.put("list", memberslist);
86 | return new JsonResult(ResponseType.SUCCESS,data);
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/api/impl/Information.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.api.impl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | import com.ices.yangengzhe.persistence.pojo.User;
11 | import com.ices.yangengzhe.service.api.IFriend;
12 | import com.ices.yangengzhe.service.api.IGroup;
13 | import com.ices.yangengzhe.service.api.IInformation;
14 | import com.ices.yangengzhe.service.persistence.IUserService;
15 | import com.ices.yangengzhe.util.Global;
16 | import com.ices.yangengzhe.util.enums.ResponseType;
17 | import com.ices.yangengzhe.util.pojo.JsonResult;
18 | import com.ices.yangengzhe.util.security.Security;
19 |
20 | /**
21 | * @date 2017年1月24日 上午10:16:49
22 | * @author yangengzhe
23 | *
24 | */
25 | @Service
26 | public class Information implements IInformation {
27 |
28 | @Autowired
29 | private IUserService userService;
30 | @Autowired
31 | private IFriend friend;
32 | @Autowired
33 | private IGroup group;
34 |
35 | @Override
36 | public ResponseType getMyInformation(Integer uid, String password,HashMap map) {
37 | if(!Security.isLogin(uid)) return ResponseType.LOGIN_NO;
38 |
39 | User user = userService.getUserByUID(uid);
40 | if(user == null) return ResponseType.USER_NOTFOUND;
41 | //if(!Security.authentication(uid, password)) return ResponseType.USER_WRONG;
42 |
43 | //个人信息
44 | HashMap mine = new HashMap();
45 | mine.put("username", user.getName());
46 | mine.put("id", user.getUid());
47 | mine.put("status", "online");
48 | mine.put("sign", user.getSign());
49 | mine.put("avatar", Global.URL+user.getHeadphoto());
50 | map.put("mine", mine);
51 |
52 | //好友分组
53 | List> friendgrouplist =friend.getFriendgroupDetaillist(uid);
54 | map.put("friend",friendgrouplist);
55 |
56 | //群
57 | List> grouplist = group.getAllGroup(uid);
58 | map.put("group", grouplist);
59 | return ResponseType.SUCCESS;
60 | }
61 |
62 |
63 |
64 | @Override
65 | public JsonResult init(Integer uid, String password) {
66 | HashMap data = new HashMap();
67 | ResponseType responseType = getMyInformation(uid,password,data);
68 | return new JsonResult(responseType,data);
69 | }
70 |
71 |
72 | @Override
73 | public void addUser(Integer uid, String name, String photo, String sign) {
74 | userService.insertUser(uid,name,photo,sign);
75 | }
76 |
77 |
78 |
79 | @Override
80 | public User findUserByUid(Integer uid) {
81 | return userService.getUserByUID(uid);
82 | }
83 |
84 |
85 |
86 | @Override
87 | public JsonResult searchUserByKeyword(String keyword) {
88 | HashMap data = new HashMap();
89 | List users = userService.searchUsersByKeyword(keyword);
90 | List> list = new ArrayList>();
91 | for (User user : users) {
92 | HashMap map = new HashMap();
93 | map.put("username", user.getName());
94 | map.put("id", user.getUid());
95 | map.put("avatar", Global.URL+user.getHeadphoto());
96 | map.put("sign", user.getSign());
97 | map.put("status", "online");
98 | list.add(map);
99 | }
100 | data.put("list", list);
101 | return new JsonResult(ResponseType.SUCCESS,data);
102 | }
103 |
104 |
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/api/impl/Message.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.api.impl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | import com.ices.yangengzhe.persistence.pojo.Apply;
11 | import com.ices.yangengzhe.persistence.pojo.MessageBox;
12 | import com.ices.yangengzhe.persistence.pojo.User;
13 | import com.ices.yangengzhe.service.api.IMessage;
14 | import com.ices.yangengzhe.service.persistence.IApplyService;
15 | import com.ices.yangengzhe.service.persistence.IFriendgroupDetailService;
16 | import com.ices.yangengzhe.service.persistence.IMessageboxService;
17 | import com.ices.yangengzhe.service.persistence.IUserService;
18 | import com.ices.yangengzhe.util.Global;
19 | import com.ices.yangengzhe.util.Parse;
20 | import com.ices.yangengzhe.util.enums.ResponseType;
21 | import com.ices.yangengzhe.util.pojo.JsonPageResult;
22 | import com.ices.yangengzhe.util.pojo.JsonResult;
23 |
24 |
25 | /**
26 | * webChat
27 | * @date 2017年1月28日 下午10:13:40
28 | * @author gengzhe.ygz
29 | *
30 | */
31 | @Service
32 | public class Message implements IMessage {
33 | @Autowired
34 | IApplyService applyService;
35 | @Autowired
36 | IFriendgroupDetailService friendgroupDetailService;
37 | @Autowired
38 | IMessageboxService messageService;
39 | @Autowired
40 | IUserService userService;
41 |
42 | @Override
43 | public JsonPageResult getMessageBox(int uid, int page) {
44 | final int pagesize = 5;
45 | List> data = new ArrayList>();
46 | int applyCount = applyService.countApplyByUid(uid);
47 | int msgCount = messageService.countMessageboxByUID(uid);
48 | int pages = (int) Math.ceil( (applyCount+msgCount)/Double.valueOf(pagesize) );
49 | //获得偏移量
50 | int offset = (page-1)*pagesize;
51 | //获得申请列表
52 | if(offset + pagesize <= applyCount)//全是申请列表
53 | {
54 | List applyList = applyService.selectApplyByUid(uid, offset);
55 | for (Apply apply : applyList) {
56 | HashMap map = new HashMap();
57 | map.put("id", 0);
58 | map.put("content", "添加你为好友");
59 | map.put("uid", uid);
60 | map.put("from", apply.getFromuser());
61 | map.put("from_group", apply.getFromuserFid());
62 | map.put("remark", apply.getMsg());
63 | map.put("time", Parse.showTime(apply.getAddtime()));
64 | User user = userService.getUserByUID(apply.getFromuser());
65 | HashMap userMap = new HashMap();
66 | userMap.put("id", user.getUid());
67 | userMap.put("avatar", Global.URL+user.getHeadphoto());
68 | userMap.put("username", user.getName());
69 | userMap.put("sign", user.getSign());
70 | map.put("user", userMap);
71 | data.add(map);
72 | }
73 | }else if(offset <= applyCount){ //申请列表最后一页+历史第一页
74 | int count = 0;
75 | List applyList = applyService.selectApplyByUid(uid, offset);
76 | for (Apply apply : applyList) {
77 | HashMap map = new HashMap();
78 | map.put("id", 0);
79 | map.put("content", "添加你为好友");
80 | map.put("uid", uid);
81 | map.put("from", apply.getFromuser());
82 | map.put("from_group", apply.getFromuserFid());
83 | map.put("remark", apply.getMsg());
84 | map.put("time", Parse.showTime(apply.getAddtime()));
85 | User user = userService.getUserByUID(apply.getFromuser());
86 | HashMap userMap = new HashMap();
87 | userMap.put("id", user.getUid());
88 | userMap.put("avatar", Global.URL+user.getHeadphoto());
89 | userMap.put("username", user.getName());
90 | userMap.put("sign", user.getSign());
91 | map.put("user", userMap);
92 | data.add(map);
93 | count++;
94 | }
95 | List msgList = messageService.selectMessagebox(uid,0);
96 | for (MessageBox messageBox : msgList) {
97 | HashMap map = new HashMap();
98 | map.put("id", messageBox.getId());
99 | map.put("content", messageBox.getContent());
100 | map.put("uid", messageBox.getUid());
101 | map.put("time", Parse.showTime(messageBox.getAddtime()));
102 | data.add(map);
103 | if(++count == 5) break;
104 | }
105 | }else{//获得历史消息盒子
106 | offset -=applyCount;
107 | List msgList = messageService.selectMessagebox(uid,offset);
108 | for (MessageBox messageBox : msgList) {
109 | HashMap map = new HashMap();
110 | map.put("id", messageBox.getId());
111 | map.put("content", messageBox.getContent());
112 | map.put("uid", messageBox.getUid());
113 | map.put("time", Parse.showTime(messageBox.getAddtime()));
114 | data.add(map);
115 | }
116 | }
117 |
118 | JsonPageResult result = new JsonPageResult(ResponseType.SUCCESS,pages,data);
119 | return result;
120 | }
121 |
122 | @Override
123 | public JsonResult applyAddFriend(int uid, int toUid, int from_group, String remark) {
124 | JsonResult jsonResult = null;
125 | if(friendgroupDetailService.isFriend(uid, toUid)){
126 | System.out.println("已经是好友");
127 | jsonResult = new JsonResult(ResponseType.APPLY_EXIST, null);
128 | return jsonResult;
129 | }
130 | try {
131 | applyService.insertApply(uid, from_group, toUid, remark);
132 | friendgroupDetailService.insertFG(from_group, toUid);
133 | //添加好友
134 | User user = userService.getUserByUID(toUid);
135 | messageService.insertMessagebox(uid, "您已添加 "+user.getName()+" 为好友");
136 | jsonResult = new JsonResult(ResponseType.SUCCESS, null);
137 | } catch (Exception e) {
138 | System.out.println("已经存在");
139 | jsonResult = new JsonResult(ResponseType.APPLY_REPERT, null);
140 | }
141 | return jsonResult;
142 | }
143 |
144 | @Override
145 | public JsonResult agreeAddFriend(int uid, int fromUid, int group) {
146 | JsonResult jsonResult = null;
147 | if(friendgroupDetailService.isFriend(uid, fromUid)){
148 | System.out.println("已经是好友");
149 | jsonResult = new JsonResult(ResponseType.APPLY_EXIST, null);
150 | return jsonResult;
151 | }
152 | try {
153 | friendgroupDetailService.insertFG(group, fromUid);
154 | User user = userService.getUserByUID(fromUid);
155 | messageService.insertMessagebox(uid, "您已添加 "+user.getName()+" 为好友");
156 | applyService.deleteApply(fromUid, uid);
157 | jsonResult = new JsonResult(ResponseType.SUCCESS, null);
158 | } catch (Exception e) {
159 | System.out.println("已经存在");
160 | jsonResult = new JsonResult(ResponseType.APPLY_REPERT, null);
161 | }
162 | return jsonResult;
163 | }
164 |
165 | @Override
166 | public JsonResult ignoreAddFriend(int uid, int fromUid) {
167 | User user = userService.getUserByUID(fromUid);
168 | messageService.insertMessagebox(uid, "您已忽略 "+user.getName()+" 的好友请求");
169 | applyService.deleteApply(fromUid, uid);
170 | return new JsonResult(ResponseType.SUCCESS, null);
171 | }
172 |
173 | @Override
174 | public Integer countUnreadMessage(int uid) {
175 | // return messageService.countMessageboxByUID(uid);
176 | return applyService.countApplyByUid(uid);
177 | }
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/IApplyService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence;
2 |
3 | import java.util.List;
4 |
5 | import com.ices.yangengzhe.persistence.pojo.Apply;
6 |
7 | /**
8 | * webChat
9 | * @date 2017年1月28日 下午9:22:06
10 | * @author gengzhe.ygz
11 | *
12 | */
13 | public interface IApplyService {
14 | //增加
15 | void insertApply(int fromuser,int fromuser_fid,int uid,String msg) throws Exception;
16 |
17 | //删除
18 | void deleteApply(int fromuser,int uid);
19 |
20 | //根据目标人查找
21 | List selectApplyByUid(int uid,int offset);
22 |
23 | //根据目标人查找数量
24 | int countApplyByUid(int uid);
25 |
26 | //验证是否存在
27 | boolean isExist(int fromuser,int uid);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/IFriendgroupDetailService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence;
2 |
3 | import java.util.List;
4 |
5 | import com.ices.yangengzhe.persistence.pojo.FriendgroupDetail;
6 |
7 | public interface IFriendgroupDetailService {
8 |
9 | public List getFGMemberByFID(int FID);
10 |
11 | public void insertFG(int fid,int userUID);
12 |
13 | //判断A好友内是否有B
14 | public boolean isFriend(int uidA,int uidB);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/IFriendgroupService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence;
2 |
3 | import java.util.List;
4 |
5 | import com.ices.yangengzhe.persistence.pojo.Friendgroup;
6 |
7 | public interface IFriendgroupService {
8 |
9 | public List getFGByUID(int userUID);
10 |
11 | public int insertFG(String name,int userUID);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/IGroupService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence;
2 |
3 | import java.util.List;
4 |
5 | import com.ices.yangengzhe.persistence.pojo.Group;
6 | import com.ices.yangengzhe.persistence.pojo.User;
7 |
8 | /**
9 | * webChat
10 | * @date 2017年1月27日 上午10:19:40
11 | * @author gengzhe.ygz
12 | *
13 | */
14 | public interface IGroupService {
15 |
16 | int insertGroup(Integer uid,String name);
17 |
18 | void addMember(Integer gid, Integer uid);
19 |
20 | List selectGroup(Integer uid);
21 |
22 | List getAllMember(Integer gid);
23 |
24 | List getAllMemberToString(Integer gid);
25 |
26 | Group selectGroupById(Integer gid);
27 |
28 | User getGroupOwner(Integer gid);
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/IMessageService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence;
2 |
3 | import java.util.List;
4 |
5 | import com.ices.yangengzhe.util.pojo.message.ToServerTextMessage;
6 |
7 | /**
8 | * @date 2017年1月24日 下午3:11:08
9 | * @author yangengzhe
10 | */
11 | public interface IMessageService {
12 |
13 | // 保存消息
14 | void insertMessage(ToServerTextMessage message);
15 |
16 | // 根据接收好友id读取
17 | List getMessageByUIDTop(int uid, int num);
18 |
19 | // 根据接收好友id 和发送好友id 读取
20 | List getMessageByUIDTop(int fromuser,int uid, int num);
21 |
22 | // 根据接收群id读取
23 | List getMessageByGIDTop(int gid, int num);
24 |
25 | // 根据发送人id读取
26 | List getMessageByFromIDTop(int fromuser, int num);
27 |
28 |
29 |
30 | // 插入未读信息数据
31 | void offlineMessage(Integer recvUid,ToServerTextMessage message);
32 |
33 | // 获取未读好友信息
34 | List> getFriendUnreadMessage(Integer id);
35 |
36 | // 获取未读群信息
37 | List> getGroupUnreadMessage(Integer id);
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/IMessageboxService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence;
2 |
3 | import java.util.List;
4 |
5 | import com.ices.yangengzhe.persistence.pojo.MessageBox;
6 |
7 | /**
8 | * webChat
9 | * @date 2017年1月29日 下午5:22:16
10 | * @author gengzhe.ygz
11 | *
12 | */
13 | public interface IMessageboxService {
14 | //插入一条消息
15 | void insertMessagebox(int uid,String content);
16 |
17 | //根据UID获得消息数量
18 | int countMessageboxByUID(int uid);
19 |
20 | //根据UID获取消息
21 | List selectMessagebox(int uid,int offset);
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/IUserLogService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence;
2 |
3 | import com.ices.yangengzhe.util.enums.UserLogType;
4 | import com.ices.yangengzhe.util.pojo.SocketUser;
5 |
6 | /**
7 | * @date 2017年1月23日 下午7:27:09
8 | * @author yangengzhe
9 | *
10 | */
11 | public interface IUserLogService {
12 |
13 | public void insertLog(SocketUser user, UserLogType type);
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/IUserService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence;
2 |
3 | import java.util.List;
4 |
5 | import com.ices.yangengzhe.persistence.pojo.User;
6 |
7 | /**
8 | * @date 2017年1月22日 下午7:27:13
9 | * @author yangengzhe
10 | *
11 | */
12 | public interface IUserService {
13 |
14 | public User getUserById(int userId);
15 |
16 | public User getUserByUID(int userUID);
17 |
18 | public String insertUser(Integer Uid,String name,String photo,String sign);
19 |
20 | public List searchUsersByKeyword(String keyword);
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/impl/ApplyService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence.impl;
2 |
3 | import java.util.Date;
4 | import java.util.List;
5 |
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import com.ices.yangengzhe.persistence.dao.ApplyMapper;
10 | import com.ices.yangengzhe.persistence.pojo.Apply;
11 | import com.ices.yangengzhe.persistence.pojo.ApplyKey;
12 | import com.ices.yangengzhe.service.persistence.IApplyService;
13 |
14 |
15 | /**
16 | * webChat
17 | * @date 2017年1月28日 下午9:28:15
18 | * @author gengzhe.ygz
19 | *
20 | */
21 | @Service
22 | public class ApplyService implements IApplyService {
23 |
24 | @Autowired
25 | ApplyMapper applyDao;
26 |
27 | @Override
28 | public void insertApply(int fromuser, int fromuser_fid, int uid, String msg) throws Exception {
29 | Apply apply = new Apply();
30 | apply.setAddtime(new Date());
31 | apply.setFromuser(fromuser);
32 | apply.setFromuserFid(fromuser_fid);
33 | apply.setMsg(msg);
34 | apply.setUid(uid);
35 | try {
36 | applyDao.insert(apply);
37 | } catch (Exception e) {
38 | throw new Exception();
39 | }
40 |
41 | }
42 |
43 | @Override
44 | public void deleteApply(int fromuser, int uid) {
45 | ApplyKey applyKey = new ApplyKey();
46 | applyKey.setFromuser(fromuser);
47 | applyKey.setUid(uid);
48 | applyDao.deleteByPrimaryKey(applyKey);
49 | }
50 |
51 | @Override
52 | public List selectApplyByUid(int uid,int offset) {
53 | offset = offset<0?0:offset;
54 | int count = 5;//每页五个
55 | return applyDao.selectByUID(uid, offset, count);
56 | }
57 |
58 | @Override
59 | public int countApplyByUid(int uid) {
60 | return applyDao.countByUID(uid);
61 | }
62 |
63 | @Override
64 | public boolean isExist(int fromuser, int uid) {
65 | return applyDao.countByFromUid(fromuser, uid) == 0 ?false:true;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/impl/FriendgroupDetailService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence.impl;
2 |
3 | import java.util.List;
4 |
5 | import javax.annotation.Resource;
6 |
7 | import org.springframework.stereotype.Service;
8 |
9 | import com.ices.yangengzhe.persistence.dao.FriendgroupDetailMapper;
10 | import com.ices.yangengzhe.persistence.dao.FriendgroupMapper;
11 | import com.ices.yangengzhe.persistence.pojo.Friendgroup;
12 | import com.ices.yangengzhe.persistence.pojo.FriendgroupDetail;
13 | import com.ices.yangengzhe.service.persistence.IFriendgroupDetailService;
14 |
15 | @Service
16 | public class FriendgroupDetailService implements IFriendgroupDetailService {
17 |
18 | @Resource
19 | private FriendgroupDetailMapper friendgroupDetailDao;
20 | @Resource
21 | private FriendgroupMapper friendgroupDao;
22 |
23 | @Override
24 | public List getFGMemberByFID(int FID) {
25 | return friendgroupDetailDao.selectUsersByFID(FID);
26 | }
27 |
28 | @Override
29 | public void insertFG(int fid, int userUID) {
30 | List list = friendgroupDetailDao.selectUsersByFIDUID(fid,userUID);
31 | if(list!=null && list.size()>0)
32 | return;
33 | FriendgroupDetail fd = new FriendgroupDetail();
34 | fd.setFid(fid);
35 | fd.setUid(userUID);
36 | Friendgroup fgroup = friendgroupDao.selectByPrimaryKey(fid);
37 | fd.setFidOwner(fgroup.getUid());
38 | if(!isFriend(fgroup.getUid(), userUID))
39 | friendgroupDetailDao.insert(fd);
40 | }
41 |
42 | @Override
43 | public boolean isFriend(int uidA, int uidB) {
44 | return friendgroupDetailDao.countfidOwnerUid(uidA, uidB) >0?true:false;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/impl/FriendgroupService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence.impl;
2 |
3 | import java.util.Date;
4 | import java.util.List;
5 |
6 | import javax.annotation.Resource;
7 |
8 | import org.springframework.stereotype.Service;
9 |
10 | import com.ices.yangengzhe.persistence.dao.FriendgroupMapper;
11 | import com.ices.yangengzhe.persistence.pojo.Friendgroup;
12 | import com.ices.yangengzhe.service.persistence.IFriendgroupService;
13 |
14 | @Service
15 | public class FriendgroupService implements IFriendgroupService {
16 |
17 | @Resource
18 | private FriendgroupMapper friendgroupDao;
19 |
20 | @Override
21 | public List getFGByUID(int userUID) {
22 | return friendgroupDao.selectByUID(userUID);
23 | }
24 |
25 | @Override
26 | public int insertFG(String name,int userUID) {
27 | List list = friendgroupDao.selectByNameUID(name, userUID);
28 | if(list!=null && list.size()>0)
29 | return list.get(0).getId();
30 | Friendgroup friendgroup = new Friendgroup();
31 | friendgroup.setAddtime(new Date());
32 | friendgroup.setName(name);
33 | friendgroup.setSort(99);
34 | friendgroup.setUid(userUID);
35 | friendgroupDao.insert(friendgroup);
36 | return friendgroup.getId();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/impl/GroupService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence.impl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Date;
5 | import java.util.List;
6 |
7 | import javax.annotation.Resource;
8 |
9 | import org.springframework.stereotype.Service;
10 |
11 | import com.ices.yangengzhe.persistence.dao.GroupDetailMapper;
12 | import com.ices.yangengzhe.persistence.dao.GroupMapper;
13 | import com.ices.yangengzhe.persistence.dao.UserMapper;
14 | import com.ices.yangengzhe.persistence.pojo.Group;
15 | import com.ices.yangengzhe.persistence.pojo.GroupDetail;
16 | import com.ices.yangengzhe.persistence.pojo.User;
17 | import com.ices.yangengzhe.service.persistence.IGroupService;
18 |
19 |
20 | /**
21 | * webChat
22 | * @date 2017年1月27日 上午10:23:48
23 | * @author gengzhe.ygz
24 | *
25 | */
26 | @Service
27 | public class GroupService implements IGroupService {
28 |
29 | @Resource
30 | GroupMapper groupDao;
31 | @Resource
32 | GroupDetailMapper groupDetailDao;
33 | @Resource
34 | UserMapper userDao;
35 |
36 | @Override
37 | public int insertGroup(Integer uid, String name) {
38 | Group group = new Group();
39 | group.setAddtime(new Date());
40 | group.setHeadphoto("");
41 | group.setName(name);
42 | group.setOwnerUid(uid);
43 | groupDao.insert(group);
44 | addMember(group.getId(), uid);
45 | return group.getId();
46 | }
47 |
48 | @Override
49 | public void addMember(Integer gid, Integer uid) {
50 | GroupDetail groupDetail = new GroupDetail();
51 | groupDetail.setAddtime(new Date());
52 | groupDetail.setGid(gid);
53 | groupDetail.setUid(uid);
54 | groupDetailDao.insert(groupDetail);
55 | }
56 |
57 | @Override
58 | public List selectGroup(Integer uid) {
59 | List groupDetails = groupDetailDao.selectByUID(uid);
60 | List result = new ArrayList();
61 | for (GroupDetail groupDetail : groupDetails) {
62 | Group group = groupDao.selectByPrimaryKey(groupDetail.getGid());
63 | result.add(group);
64 | }
65 | return result;
66 | }
67 |
68 | @Override
69 | public List getAllMember(Integer gid) {
70 | List groupDetails = groupDetailDao.selectByGID(gid);
71 | List result = new ArrayList();
72 | for (GroupDetail groupDetail : groupDetails) {
73 | User user = userDao.selectByUID(groupDetail.getUid());
74 | result.add(user);
75 | }
76 | return result;
77 | }
78 |
79 | @Override
80 | public Group selectGroupById(Integer gid) {
81 | return groupDao.selectByPrimaryKey(gid);
82 | }
83 |
84 | @Override
85 | public User getGroupOwner(Integer gid) {
86 | return userDao.selectByUID(selectGroupById(gid).getOwnerUid());
87 | }
88 |
89 | @Override
90 | public List getAllMemberToString(Integer gid) {
91 | List groupDetails = groupDetailDao.selectByGID(gid);
92 | List result = new ArrayList();
93 | for (GroupDetail groupDetail : groupDetails) {
94 | result.add(String.valueOf(groupDetail.getUid()));
95 | }
96 | return result;
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/impl/MessageService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence.impl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Date;
5 | import java.util.List;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | import com.ices.yangengzhe.persistence.dao.MsgMapper;
11 | import com.ices.yangengzhe.persistence.dao.MsgUnreadMapper;
12 | import com.ices.yangengzhe.persistence.dao.UserMapper;
13 | import com.ices.yangengzhe.persistence.pojo.Msg;
14 | import com.ices.yangengzhe.persistence.pojo.MsgUnread;
15 | import com.ices.yangengzhe.persistence.pojo.User;
16 | import com.ices.yangengzhe.service.persistence.IGroupService;
17 | import com.ices.yangengzhe.service.persistence.IMessageService;
18 | import com.ices.yangengzhe.util.Parse;
19 | import com.ices.yangengzhe.util.enums.ChatType;
20 | import com.ices.yangengzhe.util.pojo.message.ToServerTextMessage;
21 |
22 | /**
23 | * @date 2017年1月26日 下午3:54:01
24 | * @author yangengzhe
25 | *
26 | */
27 | @Service
28 | public class MessageService implements IMessageService {
29 |
30 | @Autowired
31 | MsgMapper msgDao;
32 | @Autowired
33 | UserMapper userDao;
34 | @Autowired
35 | MsgUnreadMapper msgUnreadDao;
36 | @Autowired
37 | IGroupService groupService;
38 |
39 | @Override
40 | public void insertMessage(ToServerTextMessage message) {
41 | Msg msg = new Msg();
42 | msg.setAddtime(new Date());
43 | msg.setFromuser(message.getMine().getId());
44 | msg.setMsg(message.getMine().getContent());
45 | if(message.getTo().getType().equals(ChatType.FRINED.getName())){
46 | msg.setUid(message.getTo().getId());
47 | }else{
48 | msg.setGid(message.getTo().getId());
49 | }
50 | msgDao.insert(msg);
51 | }
52 |
53 | @Override
54 | public List getMessageByUIDTop(int uid, int num) {
55 | List msgList = msgDao.selectByUIDTop(uid, num);
56 | User sender = null;
57 | if(msgList.size()>0)
58 | sender = userDao.selectByUID(msgList.get(0).getFromuser());
59 | return Parse.getStringListToClientMessage(sender,msgList);
60 | }
61 |
62 | @Override
63 | public List getMessageByUIDTop(int fromuser,int uid, int num) {
64 | List msgList = msgDao.selectByFUIDTop(fromuser, uid, num);
65 | User sender = null;
66 | if(msgList.size()>0)
67 | sender = userDao.selectByUID(msgList.get(0).getFromuser());
68 | return Parse.getStringListToClientMessage(sender,msgList);
69 | }
70 |
71 | @Override
72 | public List getMessageByGIDTop(int gid, int num) {
73 | List msgList = msgDao.selectByGIDTop(gid, num);
74 | List resultlist = new ArrayList();
75 |
76 | User sender = null;
77 | for(int i = msgList.size()-1;i>=0;i--){
78 | sender = userDao.selectByUID(msgList.get(i).getFromuser());
79 | resultlist.add(Parse.getStringToClientMessage(sender, msgList.get(i)));
80 | }
81 |
82 | return resultlist;
83 | }
84 |
85 | @Override
86 | public List getMessageByFromIDTop(int fromuser, int num) {
87 | List msgList = msgDao.selectByFromIDTop(fromuser, num);
88 | User sender = null;
89 | if(msgList.size()>0)
90 | sender = userDao.selectByUID(msgList.get(0).getFromuser());
91 | return Parse.getStringListToClientMessage(sender,msgList);
92 | }
93 |
94 | @Override
95 | public void offlineMessage(Integer recvUid,ToServerTextMessage message) {
96 | Integer id = message.getTo().getId();
97 | Integer gid = message.getTo().getType().equals(ChatType.FRINED.getName()) ? 0:1;
98 | Integer fromuser = gid.equals(1)? 0 : message.getMine().getId(); //如果是组 则发出者为0
99 | msgUnreadDao.countMsg(id, gid, fromuser,recvUid);
100 | }
101 |
102 | @Override
103 | public List> getFriendUnreadMessage(Integer id) {
104 | List list= msgUnreadDao.selectByGidId(ChatType.FRINED.getOrdinal(), id, id);
105 | List> result = new ArrayList>();
106 | for (MsgUnread msgUnread : list) {
107 | Integer fromuser = msgUnread.getFromuser();
108 | Integer uid = msgUnread.getId();
109 | Integer num = msgUnread.getMsgcount();
110 | List result_list = getMessageByUIDTop(fromuser, uid, num);
111 | msgUnreadDao.deleteMsg(uid, ChatType.FRINED.getOrdinal(), fromuser,uid);
112 | result.add(result_list);
113 | }
114 | return result;
115 | }
116 |
117 | @Override
118 | public List> getGroupUnreadMessage(Integer id) {
119 | List> result = new ArrayList>();
120 | List grouplist = groupService.selectGroup(id);
121 | for (com.ices.yangengzhe.persistence.pojo.Group group : grouplist) {
122 | List unreadList= msgUnreadDao.selectByGidId(ChatType.GROUP.getOrdinal(), group.getId(),id);
123 | MsgUnread msgUnread = null;
124 | if(unreadList!=null && unreadList.size()>0)
125 | msgUnread = unreadList.get(0);
126 | else
127 | continue;
128 | Integer gid = msgUnread.getId();
129 | Integer num = msgUnread.getMsgcount();
130 | List result_list = getMessageByGIDTop(gid, num);
131 | msgUnreadDao.deleteMsg(gid, ChatType.GROUP.getOrdinal(), 0,id);
132 | result.add(result_list);
133 | }
134 | return result;
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/impl/MessageboxService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence.impl;
2 |
3 | import java.util.Date;
4 | import java.util.List;
5 |
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import com.ices.yangengzhe.persistence.dao.MessageBoxMapper;
10 | import com.ices.yangengzhe.persistence.pojo.MessageBox;
11 | import com.ices.yangengzhe.service.persistence.IMessageboxService;
12 |
13 |
14 | /**
15 | * webChat
16 | * @date 2017年1月29日 下午5:24:31
17 | * @author gengzhe.ygz
18 | *
19 | */
20 | @Service
21 | public class MessageboxService implements IMessageboxService {
22 | @Autowired
23 | MessageBoxMapper messageboxDao;
24 |
25 | @Override
26 | public void insertMessagebox(int uid, String content) {
27 | MessageBox messageBox = new MessageBox();
28 | messageBox.setAddtime(new Date());
29 | messageBox.setContent(content);
30 | messageBox.setUid(uid);
31 | messageboxDao.insert(messageBox);
32 | }
33 |
34 | @Override
35 | public int countMessageboxByUID(int uid) {
36 | return messageboxDao.countByUid(uid);
37 | }
38 |
39 | @Override
40 | public List selectMessagebox(int uid,int offset) {
41 | int pageSize = 5;
42 | return messageboxDao.selectByUid(uid,offset,pageSize);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/impl/UserLogService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence.impl;
2 |
3 | import java.util.Date;
4 |
5 | import javax.annotation.Resource;
6 |
7 | import org.springframework.stereotype.Service;
8 |
9 | import com.ices.yangengzhe.persistence.dao.UserLogMapper;
10 | import com.ices.yangengzhe.persistence.pojo.UserLog;
11 | import com.ices.yangengzhe.service.persistence.IUserLogService;
12 | import com.ices.yangengzhe.util.enums.UserLogType;
13 | import com.ices.yangengzhe.util.pojo.SocketUser;
14 |
15 | /**
16 | * @date 2017年1月23日 下午7:27:20
17 | * @author yangengzhe
18 | *
19 | */
20 | @Service
21 | public class UserLogService implements IUserLogService {
22 |
23 | @Resource
24 | private UserLogMapper userLogDao;
25 |
26 | @Override
27 | public void insertLog(SocketUser user, UserLogType type) {
28 | UserLog userlog = new UserLog();
29 | userlog.setAddtime(new Date());
30 | String ipaddr=(String) user.getSession().getUserProperties().get("ClientIP");
31 | userlog.setIp(ipaddr);
32 | userlog.setLog(type.getValue());
33 | userlog.setUid(user.getUserId());
34 | userLogDao.insert(userlog);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/service/persistence/impl/UserService.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.service.persistence.impl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Date;
5 | import java.util.List;
6 |
7 | import javax.annotation.Resource;
8 |
9 | import org.springframework.stereotype.Service;
10 |
11 | import com.ices.yangengzhe.persistence.dao.UserMapper;
12 | import com.ices.yangengzhe.persistence.pojo.User;
13 | import com.ices.yangengzhe.service.persistence.IUserService;
14 | import com.ices.yangengzhe.util.security.Security;
15 |
16 |
17 | /**
18 | * @date 2017年1月22日 下午7:27:24
19 | * @author yangengzhe
20 | *
21 | */
22 | @Service("userService")
23 | public class UserService implements IUserService {
24 |
25 | @Resource
26 | private UserMapper userDao;
27 |
28 | @Override
29 | public User getUserById(int userId) {
30 | return this.userDao.selectByPrimaryKey(userId);
31 | }
32 |
33 | @Override
34 | public User getUserByUID(int userUID) {
35 | return this.userDao.selectByUID(userUID);
36 | }
37 |
38 | @Override
39 | public String insertUser(Integer uid, String name, String photo, String sign) {
40 | User u = getUserByUID(uid);
41 | if(u!=null && u.getUid().equals(uid))
42 | return null;
43 | User user = new User();
44 | user.setAddtime(new Date());
45 | user.setHeadphoto(photo);
46 | user.setName(name);
47 | user.setOnline(0);
48 | user.setSign(sign);
49 | user.setUid(uid);
50 | user.setPassword(Security.getPassword(uid));
51 | this.userDao.insert(user);
52 | return null;
53 | }
54 |
55 | @Override
56 | public List searchUsersByKeyword(String keyword) {
57 | if(keyword==null || keyword.equals(""))
58 | return new ArrayList();
59 | return userDao.searchUserByKeyword(keyword);
60 | }
61 |
62 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/socket/SocketConfigurator.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.socket;
2 |
3 | import javax.servlet.http.HttpSession;
4 | import javax.websocket.HandshakeResponse;
5 | import javax.websocket.server.HandshakeRequest;
6 | import javax.websocket.server.ServerEndpointConfig;
7 | import javax.websocket.server.ServerEndpointConfig.Configurator;
8 | /**
9 | * @date 2017年1月27日 上午8:37:38
10 | * @author yangengzhe
11 | *
12 | */
13 | public class SocketConfigurator extends Configurator {
14 | @Override
15 | public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
16 | HttpSession httpSession = (HttpSession) request.getHttpSession();
17 | config.getUserProperties().put("ClientIP", httpSession.getAttribute("ClientIPadd"));//把HttpSession中保存的ClientIP放到ServerEndpointConfig中,关键字可以跟之前不同
18 | }
19 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/socket/SocketServletListener.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.socket;
2 |
3 | import javax.servlet.ServletRequestEvent;
4 | import javax.servlet.ServletRequestListener;
5 | import javax.servlet.annotation.WebListener;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpSession;
8 |
9 | /**
10 | * @date 2017年1月27日 上午8:37:41
11 | * @author yangengzhe
12 | *
13 | */
14 | @WebListener()
15 | public class SocketServletListener implements ServletRequestListener {
16 | @Override
17 | public void requestDestroyed(ServletRequestEvent sre) {
18 | }
19 | @Override
20 | public void requestInitialized(ServletRequestEvent sre) {
21 | HttpServletRequest request=(HttpServletRequest) sre.getServletRequest();
22 | HttpSession session=request.getSession();
23 | session.setAttribute("ClientIPadd", sre.getServletRequest().getRemoteAddr());//把HttpServletRequest中的IP地址放入HttpSession中,关键字可任取,此处为ClientIP
24 | }
25 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/socket/manager/GroupUserManager.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.socket.manager;
2 |
3 | import java.util.List;
4 |
5 | import com.ices.yangengzhe.service.persistence.IGroupService;
6 | import com.ices.yangengzhe.util.cache.ChatCache;
7 | import com.ices.yangengzhe.util.factory.WebChatFactory;
8 |
9 | /**
10 | * 群组成员管理
11 | * 根据群id(gid)获得该群中全部成员,若缓存没有 则从数据库中都到缓存
12 | * @date 2017年1月22日 下午1:28:56
13 | * @author yangengzhe
14 | *
15 | */
16 | public class GroupUserManager {
17 | private static final String cacheName = "WEBCHAT_GROUP";
18 | private static final String cacheKey = "GM_";
19 |
20 | //每个群存一个
21 | private String getCacheKey(int groupId){
22 | return cacheKey + groupId;
23 | }
24 |
25 | //将某个群的用户id存入缓存 key=》list
26 | public boolean saveGroupMemeberIds(int groupId, List userIds) {
27 | String key = getCacheKey(groupId);
28 | ChatCache.getInstance().setListCache(cacheName,key,userIds);
29 | return true;
30 | }
31 |
32 | //获得群成员的状态
33 | public List getGroupMembers(int groupId){
34 | String key = getCacheKey(groupId);
35 | List list = ChatCache.getInstance().getListCache(cacheName,key);
36 | if (list == null || list.size()==0) {
37 | System.out.println("缓存中没有数据,需要从数据库读取");
38 | //从数据库中读取群成员
39 | IGroupService groupService = (IGroupService) WebChatFactory.beanFactory("groupService");
40 | List memebers = groupService.getAllMemberToString(groupId);
41 | saveGroupMemeberIds(groupId, memebers);
42 | return memebers;
43 | }else{
44 | System.out.println("直接从缓存中读取出来");
45 | }
46 | return list;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/socket/manager/IUserManager.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.socket.manager;
2 |
3 | import java.util.List;
4 |
5 | import com.ices.yangengzhe.util.pojo.SocketUser;
6 |
7 | /**
8 | * @date 2017年1月22日 下午1:06:43
9 | * @author yangengzhe
10 | *
11 | */
12 | public interface IUserManager {
13 |
14 | boolean addUser(SocketUser user);
15 |
16 | int removeUser(SocketUser user);
17 |
18 | int getOnlineCount();
19 |
20 | SocketUser getUser(int userId);
21 |
22 | List getOnlineUser();
23 |
24 | void notifyOthers(SocketUser user,String message);
25 |
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/socket/manager/OnLineUserManager.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.socket.manager;
2 |
3 | import java.util.Map;
4 |
5 | import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
6 |
7 | import com.ices.yangengzhe.util.cache.ChatCache;
8 |
9 | /**
10 | * 利用缓存管理在线用户session
11 | * @date 2017年1月22日 下午1:10:11
12 | * @author yangengzhe
13 | *
14 | */
15 | public class OnLineUserManager {
16 | static final String cacheName = "WEBCHAT";
17 | static final String cacheKey = "ONLINE_USER";
18 |
19 | public void addUser(String userId,String sessionId){
20 | Map map = ChatCache.getInstance().get(cacheName,cacheKey);
21 | if(map == null){
22 | map = new ConcurrentHashMap();
23 | }
24 | map.put(userId,sessionId);
25 | ChatCache.getInstance().set(cacheName,cacheKey,map);
26 | }
27 |
28 | public void removeUser(String userId){
29 | Map map = ChatCache.getInstance().get(cacheName,cacheKey);
30 |
31 | if (map == null){ return; }
32 |
33 | map.remove(userId);
34 | ChatCache.getInstance().set(cacheName,cacheKey,map);
35 | }
36 |
37 | public Map getOnLineUsers(){
38 | Map map = ChatCache.getInstance().get(cacheName,cacheKey);
39 | return map;
40 | }
41 |
42 | public int getOnlineUsersCount(){
43 | Map map = ChatCache.getInstance().get(cacheName, cacheKey);
44 | return map.size();
45 | }
46 | //
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/socket/manager/UserManager.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.socket.manager;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
8 |
9 | import com.ices.yangengzhe.util.pojo.SocketUser;
10 |
11 |
12 | /**
13 | * 管理登陆用户session
14 | * @date 2017年1月22日 下午1:09:11
15 | * @author yangengzhe
16 | *
17 | */
18 | public class UserManager implements IUserManager {
19 |
20 | private static Map socketUserMap;
21 |
22 |
23 | private OnLineUserManager onLineUserManager;
24 |
25 | private UserManager(){
26 | socketUserMap = new ConcurrentHashMap();
27 | onLineUserManager = new OnLineUserManager();
28 | }
29 |
30 | private static UserManager manager = new UserManager();
31 |
32 | public static IUserManager getInstance(){
33 | return manager;
34 | }
35 |
36 |
37 | @Override
38 | public boolean addUser(SocketUser user) {
39 |
40 | String sessionId = user.getSession().getId();
41 | removeUser(sessionId);
42 | socketUserMap.put(sessionId, user);
43 | //加入在线列表缓存
44 | onLineUserManager.addUser(Integer.toString(user.getUserId()),sessionId);
45 | return true;
46 | }
47 |
48 |
49 | @Override
50 | public int removeUser(SocketUser user) {
51 | String sessionId = user.getSession().getId();
52 | int userid = removeUser(sessionId);
53 | onLineUserManager.removeUser(Integer.toString(userid));
54 | return userid;
55 | }
56 |
57 |
58 | @Override
59 | public int getOnlineCount() {
60 | return socketUserMap.size();
61 | }
62 |
63 | @Override
64 | public SocketUser getUser(int userId){
65 | String key = Integer.toString(userId);
66 | Map map = onLineUserManager.getOnLineUsers();
67 | if(map!=null && map.containsKey(key)){
68 | return socketUserMap.get(map.get(key));
69 | }
70 | return new SocketUser();
71 | }
72 |
73 | private int removeUser(String sessionId) {
74 | SocketUser user = socketUserMap.get(sessionId);
75 | if(user!=null){
76 | socketUserMap.remove(sessionId);
77 | return user.getUserId();
78 | }else
79 | return 0;
80 | }
81 |
82 |
83 | @Override
84 | public List getOnlineUser() {
85 | List String = new ArrayList(onLineUserManager.getOnLineUsers().values());
86 | List result = new ArrayList();
87 | for (String value : String) {
88 | result.add(socketUserMap.get(value));
89 | }
90 | return result;
91 | }
92 |
93 |
94 | @Override
95 | public void notifyOthers(SocketUser user, String message) {
96 | List users = getOnlineUser();
97 | for (SocketUser socketUser : users) {
98 | if(user.equals(socketUser))
99 | continue;
100 | socketUser.getSession().getAsyncRemote().sendText(message);
101 | }
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/socket/sender/MessageParse.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.socket.sender;
2 |
3 | import java.util.HashMap;
4 |
5 | import com.ices.yangengzhe.util.enums.OnlineStatus;
6 | import com.ices.yangengzhe.util.enums.ToClientMessageType;
7 | import com.ices.yangengzhe.util.factory.WebChatFactory;
8 | import com.ices.yangengzhe.util.pojo.message.ToClientMessageResult;
9 |
10 | /**
11 | * @date 2017年1月26日 下午11:06:54
12 | * @author yangengzhe
13 | *
14 | */
15 | public class MessageParse {
16 | public static String ServiceOnlineStatus(Integer uid , OnlineStatus status){
17 | //返回统一消息接口
18 | ToClientMessageResult result = new ToClientMessageResult();
19 | HashMap msg = new HashMap();
20 | msg.put("id", uid);
21 | msg.put("status", status.getName());
22 | result.setMsg(msg);
23 | result.setType(ToClientMessageType.SERVICE_ONLINE_STATUS);
24 |
25 | return WebChatFactory.createSerializer().toJSON(result);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/socket/sender/MessageSender.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.socket.sender;
2 |
3 | import java.io.IOException;
4 | import java.util.Date;
5 | import java.util.List;
6 |
7 | import javax.websocket.Session;
8 |
9 | import com.ices.yangengzhe.service.persistence.IMessageService;
10 | import com.ices.yangengzhe.socket.manager.GroupUserManager;
11 | import com.ices.yangengzhe.util.enums.ChatType;
12 | import com.ices.yangengzhe.util.enums.ToClientMessageType;
13 | import com.ices.yangengzhe.util.factory.WebChatFactory;
14 | import com.ices.yangengzhe.util.pojo.SocketUser;
15 | import com.ices.yangengzhe.util.pojo.message.ToClientMessageResult;
16 | import com.ices.yangengzhe.util.pojo.message.ToClientTextMessage;
17 | import com.ices.yangengzhe.util.pojo.message.ToServerMessageMine;
18 | import com.ices.yangengzhe.util.pojo.message.ToServerTextMessage;
19 |
20 | /**
21 | * 发送信息类
22 | * 所有从客户端到服务端的消息转发到此类进行消息处理
23 | * ToServerTextMessage转换为ToClientTextMessage
24 | * 如果是单聊,直接从缓存取出对象的session进行消息发送,群聊则需要从缓存中取出该群里所有人的id进行遍历发送消息,
25 | * 遍历过后需要优化在线与否,假如100人中只有一个人在线,则会浪费99次(未做优化)
26 | */
27 | public class MessageSender {
28 | private IMessageService messageService = (IMessageService) WebChatFactory.beanFactory("messageService");
29 | //发送信息业务逻辑
30 | public void sendMessage(ToServerTextMessage message){
31 |
32 | int toUserId = message.getTo().getId();
33 | //获取发送人
34 | String sendUserId = Integer.toString(message.getMine().getId());
35 | String type = message.getTo().getType();
36 | //消息提前生成,否则进行循环内生成会浪费资源
37 | String toClientMessage = getToClientMessage(message);
38 |
39 | System.out.println("当前消息类型是"+type);
40 | //不能用==做比较,因为一个是static final 值,另外一个是在对象中 == 为false
41 | if(type.equals(ChatType.GROUP.getName())){
42 | //群聊,需要遍历该群组里的所有人
43 | //第一次从缓存中取userId,否则,从数据库中取在存到缓存中
44 | List users = new GroupUserManager().getGroupMembers(message.getTo().getId());
45 | for (String userid : users) {
46 | //遍历发送消息 自己过滤,不给自己发送(发送人id和群成员内的某个id相同)
47 | if (!sendUserId.equals(userid)) {
48 | sendMessage(Integer.parseInt(userid), toClientMessage,message);
49 | }
50 | }
51 | }else {
52 | sendMessage(toUserId, toClientMessage,message);
53 | }
54 |
55 | //最后保存到数据库
56 | saveMessage(message);
57 |
58 | }
59 |
60 | //给单个用户发
61 | private void sendMessage(Integer userId,String message,ToServerTextMessage toServerTextMessage){
62 | SocketUser user = WebChatFactory.createManager().getUser(userId);
63 | if (user.isExist()) {
64 | if (user.getSession() == null) {
65 | // LayIMLog.info("该用户不在线 ");
66 | saveOfflineMessage(userId,toServerTextMessage);
67 | } else {
68 | Session session = user.getSession();
69 | if (session.isOpen()) {
70 | //构造用户需要接收到的消息
71 | session.getAsyncRemote().sendText(message);
72 | }
73 | }
74 | }else{
75 | // LayIMLog.info("该用户不在线 ");
76 | saveOfflineMessage(userId,toServerTextMessage);
77 | }
78 | }
79 |
80 | //同步给单个用户发(离线推送)
81 | public void sendMessage(Integer userId,String message){
82 | SocketUser user = WebChatFactory.createManager().getUser(userId);
83 | if (user.isExist()) {
84 | if (user.getSession() == null) {
85 | } else {
86 | Session session = user.getSession();
87 | if (session.isOpen()) {
88 | try {
89 | session.getBasicRemote().sendText(message);
90 | } catch (IOException e) {
91 | e.printStackTrace();
92 | }
93 | }
94 | }
95 | }else{
96 | }
97 | }
98 |
99 | //发送离线消息
100 | public void sendOfflineMessage(Integer userId){
101 | //获取好友的离线消息
102 | List> msgList = messageService.getFriendUnreadMessage(userId);
103 | for (List list : msgList) {
104 | for (String string : list) {
105 | sendMessage(userId,string);
106 | }
107 | }
108 | //获取群组的离校消息
109 | msgList = messageService.getGroupUnreadMessage(userId);
110 | for (List list : msgList) {
111 | for (String string : list) {
112 | sendMessage(userId,string);
113 | }
114 | }
115 | }
116 |
117 | public void saveOfflineMessage(Integer recevUid,ToServerTextMessage message){
118 | if(message==null)
119 | return;
120 | messageService.offlineMessage(recevUid,message);
121 | }
122 |
123 | //保存到数据库
124 | //需要加入到队列
125 | private void saveMessage(ToServerTextMessage message){
126 |
127 | messageService.insertMessage(message);
128 |
129 | }
130 |
131 | //根据客户端发送来的消息,构造发送出去的消息
132 | /*
133 | * username: data.mine.username
134 | , avatar: data.mine.avatar
135 | , id: data.mine.id
136 | , type: data.to.type
137 | , content:data.mine.content
138 | , timestamp: new Date().getTime()
139 | * */
140 | private String getToClientMessage(ToServerTextMessage message) {
141 |
142 | ToClientTextMessage toClientTextMessage = new ToClientTextMessage();
143 |
144 | ToServerMessageMine mine = message.getMine();
145 |
146 | toClientTextMessage.setUsername(mine.getUsername());
147 | toClientTextMessage.setAvatar(mine.getAvatar());
148 | toClientTextMessage.setContent(mine.getContent());
149 | toClientTextMessage.setType(message.getTo().getType());
150 |
151 | //群组和好友直接聊天不同,群组的id 是 组id,否则是发送人的id
152 | if (toClientTextMessage.getType().equals(ChatType.GROUP.getName())) {
153 | toClientTextMessage.setId(message.getTo().getId());
154 | } else {
155 | toClientTextMessage.setId(mine.getId());
156 | }
157 | toClientTextMessage.setTimestamp(new Date().getTime());
158 |
159 | //返回统一消息接口
160 | ToClientMessageResult result = new ToClientMessageResult();
161 | result.setMsg(toClientTextMessage);
162 | result.setType(ToClientMessageType.TYPE_TEXT_MESSAGE);
163 |
164 | return WebChatFactory.createSerializer().toJSON(result);
165 | }
166 |
167 | //生成对应的groupId
168 | private long getGroupId(int sendUserId,int toUserId,String type){
169 |
170 | //如果是组内聊天,直接返回组id,否则返回 两个id的组合
171 | if (type.equals(ChatType.GROUP.getName())){
172 | return toUserId;
173 | }
174 |
175 |
176 | String sendUserIdStr = Integer.toString(sendUserId);
177 | String toUserIdStr = Integer.toString(toUserId);
178 |
179 | String groupIdStr = "";
180 | //按照固定次序生成相应的聊天组
181 | if (sendUserId > toUserId){
182 | groupIdStr = sendUserIdStr + toUserIdStr;
183 | }else{
184 | groupIdStr = toUserIdStr + sendUserIdStr;
185 | }
186 |
187 | long groupId = Long.parseLong(groupIdStr);
188 | return groupId;
189 | }
190 | }
191 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/socket/webServer.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.socket;
2 |
3 | import javax.websocket.OnClose;
4 | import javax.websocket.OnError;
5 | import javax.websocket.OnMessage;
6 | import javax.websocket.OnOpen;
7 | import javax.websocket.Session;
8 | import javax.websocket.server.PathParam;
9 | import javax.websocket.server.ServerEndpoint;
10 |
11 | import com.ices.yangengzhe.service.api.IMessage;
12 | import com.ices.yangengzhe.service.persistence.IUserLogService;
13 | import com.ices.yangengzhe.socket.manager.OnLineUserManager;
14 | import com.ices.yangengzhe.socket.sender.MessageSender;
15 | import com.ices.yangengzhe.socket.sender.MessageParse;
16 | import com.ices.yangengzhe.util.Parse;
17 | import com.ices.yangengzhe.util.enums.OnlineStatus;
18 | import com.ices.yangengzhe.util.enums.ToClientMessageType;
19 | import com.ices.yangengzhe.util.enums.UserLogType;
20 | import com.ices.yangengzhe.util.factory.WebChatFactory;
21 | import com.ices.yangengzhe.util.pojo.SocketUser;
22 | import com.ices.yangengzhe.util.pojo.message.ToServerTextMessage;
23 |
24 | /**
25 | * webSocket服务器
26 | *
27 | * @date 2017年1月22日 上午11:21:17
28 | * @author yangengzhe
29 | */
30 | @ServerEndpoint(value = "/websocket/{uid}", configurator = SocketConfigurator.class)
31 | public class webServer {
32 |
33 | private IUserLogService userLogService = (IUserLogService) WebChatFactory.beanFactory("userLogService");
34 |
35 | private IMessage messageService = (IMessage) WebChatFactory.beanFactory("message");
36 |
37 | @OnOpen
38 | public void open(Session session, @PathParam("uid") int uid) {
39 | SocketUser user = new SocketUser();
40 | user.setSession(session);
41 | user.setUserId(uid);
42 |
43 | // 保存在线列表
44 | WebChatFactory.createManager().addUser(user);
45 | userLogService.insertLog(user, UserLogType.LOGIN);
46 | print("当前在线用户:" + WebChatFactory.createManager().getOnlineCount());
47 | print("缓存中的用户个数:" + new OnLineUserManager().getOnLineUsers().size());
48 | //通知所有人
49 | String message = MessageParse.ServiceOnlineStatus(uid, OnlineStatus.ONLINE);
50 | WebChatFactory.createManager().notifyOthers(user, message);
51 | }
52 |
53 | @OnMessage
54 | public void receiveMessage(String message, Session session) {
55 | if (message.startsWith("_online_user_")) {
56 | String uidStr = message.substring("_online_user_".length());
57 | // 发送离线消息
58 | MessageSender sender = new MessageSender();
59 | sender.sendOfflineMessage(Integer.valueOf(uidStr));
60 | return;
61 | }else if (message.startsWith("_unread_mesg_")) {
62 | String uidStr = message.substring("_unread_mesg_".length());
63 | // 发送消息数量
64 | String resultCount = Parse.getResultToString(ToClientMessageType.SERVICE_MESSAGE_COUNT, messageService.countUnreadMessage(Integer.valueOf(uidStr)));
65 | session.getAsyncRemote().sendText(resultCount);
66 | return;
67 | }
68 | ToServerTextMessage toServerTextMessage = WebChatFactory.createSerializer().toObject(message,
69 | ToServerTextMessage.class);
70 | System.out.println(2);
71 | // 得到接收的对象
72 | MessageSender sender = new MessageSender();
73 | sender.sendMessage(toServerTextMessage);
74 | }
75 |
76 | @OnError
77 | public void error(Throwable t) {
78 | print(t.getMessage());
79 | }
80 |
81 | @OnClose
82 | public void close(Session session) {
83 |
84 | SocketUser user = new SocketUser();
85 | user.setSession(session);
86 | user.setUserId(0);
87 | // 移除该用户
88 | int uid = WebChatFactory.createManager().removeUser(user);
89 | user.setUserId(uid);
90 | userLogService.insertLog(user, UserLogType.LOGOUT);
91 | System.out.println("用户掉线" + uid);
92 | // print("当前在线用户:" + WebChatFactory.createManager().getOnlineCount());
93 | // print("缓存中的用户个数:" + new OnLineUserManager().getOnLineUsers().size());
94 | //通知所有人
95 | String message = MessageParse.ServiceOnlineStatus(uid, OnlineStatus.OFFLINE);
96 | WebChatFactory.createManager().notifyOthers(user, message);
97 | }
98 |
99 | private void print(String msg) {
100 | System.out.println(msg);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/Parse.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util;
2 |
3 |
4 | import java.text.SimpleDateFormat;
5 | import java.util.ArrayList;
6 | import java.util.Calendar;
7 | import java.util.Date;
8 | import java.util.List;
9 | import java.util.TimeZone;
10 |
11 | import com.ices.yangengzhe.persistence.pojo.Msg;
12 | import com.ices.yangengzhe.persistence.pojo.User;
13 | import com.ices.yangengzhe.util.enums.ChatType;
14 | import com.ices.yangengzhe.util.enums.ToClientMessageType;
15 | import com.ices.yangengzhe.util.factory.WebChatFactory;
16 | import com.ices.yangengzhe.util.pojo.message.ToClientMessageResult;
17 | import com.ices.yangengzhe.util.pojo.message.ToClientTextMessage;
18 |
19 | public class Parse {
20 |
21 | public static String getStringToClientMessage(User sender,Msg message) {
22 |
23 | ToClientTextMessage toClientTextMessage = new ToClientTextMessage();
24 |
25 | toClientTextMessage.setUsername(sender.getName());
26 | toClientTextMessage.setAvatar(Global.URL+sender.getHeadphoto());
27 | toClientTextMessage.setContent(message.getMsg());
28 | if(message.getGid()!=null && message.getGid()>0)
29 | toClientTextMessage.setType(ChatType.GROUP.getName());
30 | else
31 | toClientTextMessage.setType(ChatType.FRINED.getName());
32 | //群组和好友直接聊天不同,群组的id 是 组id,否则是发送人的id
33 | if (toClientTextMessage.getType().equals(ChatType.GROUP.getName())) {
34 | toClientTextMessage.setId(message.getGid());
35 | } else {
36 | toClientTextMessage.setId(message.getFromuser());
37 | }
38 | toClientTextMessage.setTimestamp(message.getAddtime().getTime());
39 |
40 | //返回统一消息接口
41 | ToClientMessageResult result = new ToClientMessageResult();
42 | result.setMsg(toClientTextMessage);
43 | result.setType(ToClientMessageType.TYPE_TEXT_MESSAGE);
44 |
45 | return WebChatFactory.createSerializer().toJSON(result);
46 | }
47 |
48 | public static List getStringListToClientMessage(User sender,List message) {
49 | List resultlist = new ArrayList();
50 | for(int i = message.size()-1;i>=0;i--)
51 | resultlist.add(getStringToClientMessage(sender, message.get(i)));
52 | return resultlist;
53 | }
54 |
55 | public static String getResultToString(ToClientMessageType type,Object message){
56 | //返回统一消息接口
57 | ToClientMessageResult result = new ToClientMessageResult();
58 | result.setMsg(message);
59 | result.setType(type);
60 | return WebChatFactory.createSerializer().toJSON(result);
61 | }
62 |
63 | public static String showTime(Date date){
64 | long dataTime = date.getTime();
65 | Calendar calendar = Calendar.getInstance();
66 | calendar.setTimeInMillis(dataTime);
67 | long now=System.currentTimeMillis();//当前时间毫秒数
68 | long today=now/(1000*3600*24)*(1000*3600*24)-TimeZone.getDefault().getRawOffset();//今天零点零分零秒的毫秒数
69 | if(dataTimenow-1000*60l){
82 | return "刚刚";
83 | }
84 | if(dataTime>now-1000*60*2l){
85 | return "一分钟前";
86 | }
87 | if(dataTime>now-1000*60*3l){
88 | return "两分钟前";
89 | }
90 | SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
91 | return formatter.format(date);
92 | }
93 | public static void main(String args[]){
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/cache/ChatCache.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.cache;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 | import java.util.concurrent.ConcurrentHashMap;
6 | import java.util.concurrent.locks.Lock;
7 | import java.util.concurrent.locks.ReentrantLock;
8 |
9 | import org.ehcache.Cache;
10 | import org.ehcache.CacheManager;
11 |
12 |
13 | /**
14 | * 聊天缓存
15 | * @date 2017年1月22日 上午11:24:18
16 | * @author yangengzhe
17 | *
18 | */
19 | public class ChatCache {
20 | private ChatCache() {}
21 |
22 | private static ChatCache _instance;
23 |
24 | //加锁
25 | static final Lock instanceLock = new ReentrantLock();
26 | //缓存的实例
27 | public static Map CacheManagerContext = new ConcurrentHashMap();
28 |
29 | public static ChatCache getInstance(){
30 |
31 | if (_instance == null){
32 | instanceLock.lock();
33 | if(_instance == null) {
34 | _instance = new ChatCache();
35 | }
36 | instanceLock.unlock();
37 | }
38 | return _instance;
39 | }
40 |
41 | final String HASHMAP_CONFIGURE = "HASHMAP_CONFIGURE";
42 | final String LIST_CONFIGURE = "LIST_CONFIGURE";
43 |
44 | private EHCacheUtil cacheUtil = new EHCacheUtil();
45 |
46 |
47 | private CacheManager getManager(Class kClass,Class vClass,String key){
48 |
49 | if (CacheManagerContext.containsKey(key)){
50 | return CacheManagerContext.get(key);
51 | }
52 | CacheManager manager = cacheUtil.getCacheManager(kClass,vClass,key);
53 | CacheManagerContext.put(key,manager);
54 |
55 | return manager;
56 | }
57 |
58 |
59 | private CacheManager getHashMapManager(){
60 |
61 | return getManager(String.class,Map.class,HASHMAP_CONFIGURE);
62 | }
63 |
64 | private CacheManager getListManager(){
65 | return getManager(String.class, List.class,LIST_CONFIGURE);
66 | }
67 |
68 | private Cache getListCache(String cacheName){
69 | CacheManager manager = getListManager();
70 | return cacheUtil.getCache(String.class,List.class,cacheName,LIST_CONFIGURE,manager);
71 | }
72 |
73 | private Cache getHashMapCache(String cacheName){
74 | CacheManager manager = getHashMapManager();
75 | return cacheUtil.getCache(String.class,Map.class,cacheName,HASHMAP_CONFIGURE,manager);
76 | }
77 |
78 | /*public void closeHashMapCache(){
79 | CacheManager manager = getHashMapManager();
80 | cacheUtil.closeCache(manager,HASHMAP_CONFIGURE);
81 | }*/
82 |
83 | public void set(String cacheName,String key,Map value){
84 | Cache cache = getHashMapCache(cacheName);
85 | cache.put(key,value);
86 | }
87 |
88 | public Map get(String cacheName,String key){
89 | Cache cache = getHashMapCache(cacheName);
90 | Map map = cache.get(key);
91 | return map;
92 | }
93 |
94 | public void setListCache(String cacheName,String key,List value){
95 | Cache cache = getListCache(cacheName);
96 | cache.put(key,value);
97 | }
98 |
99 | public List getListCache(String cacheName,String key){
100 | Cache cache = getListCache(cacheName);
101 | List list = cache.get(key);
102 | return list;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/cache/EHCacheUtil.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.cache;
2 |
3 | import org.ehcache.Cache;
4 | import org.ehcache.CacheManager;
5 | import org.ehcache.config.builders.CacheConfigurationBuilder;
6 | import org.ehcache.config.builders.CacheManagerBuilder;
7 | import org.ehcache.config.builders.ResourcePoolsBuilder;
8 |
9 | /**
10 | * @date 2017年1月22日 下午12:17:19
11 | * @author yangengzhe
12 | *
13 | */
14 | public class EHCacheUtil {
15 | public CacheManager getCacheManager(Class kClass,Class vClass,String configureName){
16 | CacheManager manager = CacheManagerBuilder.newCacheManagerBuilder()
17 | .withCache(configureName,
18 | CacheConfigurationBuilder.newCacheConfigurationBuilder(kClass, vClass, ResourcePoolsBuilder.heap(10)))
19 | .build();
20 | manager.init();
21 | return manager;
22 | }
23 |
24 | public Cache getCache(Class kClass,Class vClass,String cacheName,String configureName,CacheManager manager) {
25 |
26 | Cache cache =
27 | manager.getCache(configureName, kClass, vClass);
28 | /*Cache cache = manager.createCache(cacheName,
29 | CacheConfigurationBuilder.newCacheConfigurationBuilder(kClass, vClass, ResourcePoolsBuilder.heap(10)).build());*/
30 | return cache;
31 | }
32 |
33 | public void closeCache(CacheManager manager,String configureName){
34 | manager.removeCache(configureName);
35 | manager.close();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/enums/AvatorType.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.enums;
2 |
3 |
4 | /**
5 | * webchat
6 | * @date 2017年1月30日 下午3:24:49
7 | * @author gengzhe.ygz
8 | *
9 | */
10 | public enum AvatorType {
11 | STUDENT_M("sm","images/avator-sm.jpg"),
12 | STUDENT_F("sf","images/avator-sf.jpg"),
13 | TEACHER_M("tm","images/avator-tm.jpg"),
14 | TEACHER_F("tf","images/avator-tf.jpg"),
15 | QUN("qun","images/avator-qun.jpg");
16 |
17 | String typeName;
18 | String headphoto;
19 |
20 | private AvatorType(String typeName, String headphoto){
21 | this.typeName = typeName;
22 | this.headphoto = headphoto;
23 | }
24 |
25 | public static AvatorType getMatchByName(String typeName) {
26 | for (AvatorType routeState : values()){
27 | if (routeState.typeName.equalsIgnoreCase(typeName)){
28 | return routeState;
29 | }
30 | }
31 | return null;
32 | }
33 |
34 |
35 | public String getTypeName() {
36 | return typeName;
37 | }
38 |
39 |
40 | public String getHeadphoto() {
41 | return headphoto;
42 | }
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/enums/ChatType.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.enums;
2 |
3 |
4 | /**
5 | * 聊天类型
6 | * @date 2017年1月22日 上午11:24:29
7 | * @author yangengzhe
8 | *
9 | */
10 | public enum ChatType {
11 | FRINED("friend"),
12 | GROUP("group");
13 |
14 |
15 | String name;
16 |
17 | ChatType(String name){
18 | this.name= name;
19 | }
20 |
21 | public String getName(){
22 | return this.name;
23 | }
24 |
25 | public int getOrdinal(){
26 | return this.ordinal();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/enums/OnlineStatus.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.enums;
2 |
3 |
4 |
5 | /**
6 | * @date 2017年1月26日 下午11:13:08
7 | * @author yangengzhe
8 | *
9 | */
10 | public enum OnlineStatus {
11 | ONLINE("online"),
12 | OFFLINE("offline");
13 |
14 |
15 | String name;
16 |
17 | OnlineStatus(String name){
18 | this.name= name;
19 | }
20 |
21 | public String getName(){
22 | return this.name;
23 | }
24 |
25 | public int getOrdinal(){
26 | return this.ordinal();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/enums/ResponseType.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.enums;
2 |
3 |
4 | public enum ResponseType {
5 | SUCCESS(0,"成功"),
6 | USER_NOTFOUND(10,"用户不存在"),
7 | USER_WRONG(11,"用户名或密码不存在"),
8 | USER_DISABLE(12,"用户不可用"),
9 | LOGIN_NO(20,"未登录"),
10 | ERROR_DATABASE(30,"数据库错误"),
11 | APPLY_REPERT(40,"已经发送过好友申请,请勿重复!"),
12 | APPLY_EXIST(41,"您已经添加该好友,请勿重复添加!");
13 |
14 | String msg;
15 | Integer code;
16 |
17 | private ResponseType(Integer code,String msg){
18 | this.msg = msg;
19 | this.code = code;
20 | }
21 |
22 |
23 | public String getMsg() {
24 | return msg;
25 | }
26 |
27 |
28 | public void setMsg(String msg) {
29 | this.msg = msg;
30 | }
31 |
32 |
33 | public Integer getCode() {
34 | return code;
35 | }
36 |
37 |
38 | public void setCode(Integer code) {
39 | this.code = code;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/enums/ToClientMessageType.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.enums;
2 |
3 |
4 | public enum ToClientMessageType {
5 |
6 | TYPE_SYSTEM("系统消息",0)
7 |
8 | ,TYPE_TEXT_MESSAGE("普通文本消息",1)
9 |
10 | ,SERVICE_ONLINE_STATUS("用户状态服务",2)
11 |
12 | ,SERVICE_MESSAGE_COUNT("消息提醒数量服务",3);
13 |
14 | ToClientMessageType(String s,int i){
15 |
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/enums/UserLogType.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.enums;
2 |
3 |
4 | /**
5 | * @date 2017年1月23日 下午7:27:32
6 | * @author yangengzhe
7 | *
8 | */
9 | public enum UserLogType {
10 |
11 | LOGIN("登陆"),
12 | LOGOUT("退出");
13 |
14 | String value;
15 |
16 | UserLogType(String value){
17 | this.value = value;
18 | }
19 |
20 | public String getValue(){
21 | return value;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/factory/WebChatFactory.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.factory;
2 |
3 | import org.springframework.web.context.ContextLoader;
4 |
5 | import com.ices.yangengzhe.socket.manager.IUserManager;
6 | import com.ices.yangengzhe.socket.manager.UserManager;
7 | import com.ices.yangengzhe.util.serializer.FastJsonSerializer;
8 | import com.ices.yangengzhe.util.serializer.IJsonSerializer;
9 |
10 | /**
11 | * @date 2017年1月22日 下午1:23:51
12 | * @author yangengzhe
13 | *
14 | */
15 | public class WebChatFactory {
16 | //创建序列化器
17 | public static IJsonSerializer createSerializer(){
18 | return new FastJsonSerializer();
19 | }
20 |
21 | //创建在线人员管理工具
22 | public static IUserManager createManager(){
23 | return UserManager.getInstance();
24 | }
25 |
26 | //Bean工厂
27 | public static Object beanFactory(String bean){
28 | return ContextLoader.getCurrentWebApplicationContext().getBean(bean);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/pojo/JsonPageResult.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.pojo;
2 |
3 | import com.ices.yangengzhe.util.enums.ResponseType;
4 |
5 | /**
6 | * @date 2017年1月24日 上午10:19:44
7 | * @author yangengzhe
8 | */
9 | public class JsonPageResult {
10 |
11 | private int code;
12 | private int pages;
13 | private Object data;
14 |
15 | public JsonPageResult(ResponseType type, Integer pages,Object obj){
16 | code = type.getCode();
17 | this.pages = pages;
18 | data = obj;
19 | }
20 |
21 | public int getCode() {
22 | return code;
23 | }
24 |
25 | public void setCode(int code) {
26 | this.code = code;
27 | }
28 |
29 | public int getPages() {
30 | return pages;
31 | }
32 |
33 |
34 | public void setPages(int pages) {
35 | this.pages = pages;
36 | }
37 |
38 | public Object getData() {
39 | return data;
40 | }
41 |
42 | public void setData(Object data) {
43 | this.data = data;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/pojo/JsonResult.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.pojo;
2 |
3 | import com.ices.yangengzhe.util.enums.ResponseType;
4 |
5 | /**
6 | * @date 2017年1月24日 上午10:19:44
7 | * @author yangengzhe
8 | */
9 | public class JsonResult {
10 |
11 | private int code;
12 | private String msg;
13 | private Object data;
14 |
15 | public JsonResult(ResponseType type, Object obj){
16 | code = type.getCode();
17 | msg = type.getMsg();
18 | data = obj;
19 | }
20 |
21 | public int getCode() {
22 | return code;
23 | }
24 |
25 | public void setCode(int code) {
26 | this.code = code;
27 | }
28 |
29 | public String getMsg() {
30 | return msg;
31 | }
32 |
33 | public void setMsg(String msg) {
34 | this.msg = msg;
35 | }
36 |
37 | public Object getData() {
38 | return data;
39 | }
40 |
41 | public void setData(Object data) {
42 | this.data = data;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/pojo/SocketUser.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.pojo;
2 |
3 | import javax.websocket.Session;
4 |
5 | /**
6 | * @date 2017年1月22日 下午1:08:37
7 | * @author yangengzhe
8 | *
9 | */
10 | public class SocketUser {
11 |
12 | private Session session;
13 | private int userId;
14 |
15 | public Session getSession() {
16 | return session;
17 | }
18 |
19 | public void setSession(Session session) {
20 | this.session = session;
21 | }
22 |
23 | public int getUserId() {
24 | return userId;
25 | }
26 |
27 | public boolean isExist() {
28 | return this.userId > 0;
29 | }
30 |
31 | public void setUserId(int userId) {
32 | this.userId = userId;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return session.getId() + "_" + userId;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/pojo/message/ToClientMessageResult.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.pojo.message;
2 |
3 | import com.ices.yangengzhe.util.enums.ToClientMessageType;
4 |
5 | /**
6 | * @date 2017年1月22日 下午2:22:30
7 | * @author yangengzhe
8 | *
9 | */
10 | public class ToClientMessageResult {
11 |
12 | public ToClientMessageType getType() {
13 | return type;
14 | }
15 |
16 | public void setType(ToClientMessageType type) {
17 | this.type = type;
18 | }
19 |
20 | public Object getMsg() {
21 | return msg;
22 | }
23 |
24 | public void setMsg(Object msg) {
25 | this.msg = msg;
26 | }
27 |
28 | private ToClientMessageType type;
29 | private Object msg;
30 | }
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/pojo/message/ToClientTextMessage.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.pojo.message;
2 |
3 |
4 | /**
5 | * 发送给客户端的消息
6 | *
7 | * layim.getMessage({
8 | username: "纸飞机" //消息来源用户名
9 | ,avatar: "http://tp1.sinaimg.cn/1571889140/180/40030060651/1" //消息来源用户头像
10 | ,id: "100000" //消息的来源ID(如果是私聊,则是用户id,如果是群聊,则是群组id)
11 | ,type: "friend" //聊天窗口来源类型,从发送消息传递的to里面获取
12 | ,content: "嗨,你好!本消息系离线消息。" //消息内容
13 | ,cid: 0 //消息id,可不传。除非你要对消息进行一些操作(如撤回)
14 | ,mine: false //是否我发送的消息,如果为true,则会显示在右方
15 | ,fromid: "100000" //消息的发送者id(比如群组中的某个消息发送者),可用于自动解决浏览器多窗口时的一些问题
16 | ,timestamp: 1467475443306 //服务端动态时间戳
17 | });
18 |
19 | * @date 2017年1月22日 下午1:56:56
20 | * @author yangengzhe
21 | *
22 | */
23 | public class ToClientTextMessage {
24 | public String getUsername() {
25 | return username;
26 | }
27 |
28 | public void setUsername(String username) {
29 | this.username = username;
30 | }
31 |
32 | public int getId() {
33 | return id;
34 | }
35 |
36 | public void setId(int id) {
37 | this.id = id;
38 | }
39 |
40 | public String getType() {
41 | return type;
42 | }
43 |
44 | public void setType(String type) {
45 | this.type = type;
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 long getTimestamp() {
57 | return timestamp;
58 | }
59 |
60 | public void setTimestamp(long timestamp) {
61 | this.timestamp = timestamp;
62 | }
63 |
64 | private String username;
65 | private int id;
66 | private String type;
67 | private String content;
68 | private long timestamp;
69 |
70 | public String getAvatar() {
71 | return avatar;
72 | }
73 |
74 | public void setAvatar(String avatar) {
75 | this.avatar = avatar;
76 | }
77 |
78 | private String avatar;
79 |
80 | @Override
81 | public String toString() {
82 | return "ToClientTextMessage{" +
83 | "username='" + username + '\'' +
84 | ", id=" + id +
85 | ", type='" + type + '\'' +
86 | ", content='" + content + '\'' +
87 | ", timestamp=" + timestamp +
88 | ", avatar='" + avatar + '\'' +
89 | '}';
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/pojo/message/ToServerMessageMine.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.pojo.message;
2 |
3 |
4 | /**
5 | * 客户端发出的消息: 发出方的信息
6 | * //mine的结构如下:
7 | {
8 | avatar: "avatar.jpg" //我的头像
9 | ,content: "你好吗" //消息内容
10 | ,id: "100000" //我的id
11 | ,mine: true //是否我发送的消息
12 | ,username: "纸飞机" //我的昵称
13 | }
14 | * @date 2017年1月22日 下午2:01:10
15 | * @author yangengzhe
16 | *
17 | */
18 | public class ToServerMessageMine {
19 | public String getAvatar() {
20 | return avatar;
21 | }
22 |
23 | public void setAvatar(String avatar) {
24 | this.avatar = avatar;
25 | }
26 |
27 | public int getId() {
28 | return id;
29 | }
30 |
31 | public void setId(int id) {
32 | this.id = id;
33 | }
34 |
35 | public String getContent() {
36 | return content;
37 | }
38 |
39 | public void setContent(String content) {
40 | this.content = content;
41 | }
42 |
43 | public String getUsername() {
44 | return username;
45 | }
46 |
47 | public void setUsername(String username) {
48 | this.username = username;
49 | }
50 |
51 | private String avatar;
52 | private int id;
53 | private String content;
54 | private String username;
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/pojo/message/ToServerMessageTo.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.pojo.message;
2 |
3 |
4 | /**
5 | * 客户端发出的信息: 接收者的信息
6 | * //to的结构如下:
7 | {
8 | avatar: "avatar.jpg"
9 | ,id: "100001"
10 | ,name: "贤心"
11 | ,sign: "这些都是测试数据,实际使用请严格按照该格式返回"
12 | ,type: "friend" //聊天类型,一般分friend和group两种,group即群聊
13 | ,username: "贤心"
14 | }
15 | * @date 2017年1月22日 下午1:59:57
16 | * @author yangengzhe
17 | *
18 | */
19 | public class ToServerMessageTo {
20 | public int getId() {
21 | return id;
22 | }
23 |
24 | public void setId(int id) {
25 | this.id = id;
26 | }
27 |
28 | public String getAvatar() {
29 | return avatar;
30 | }
31 |
32 | public void setAvatar(String avatar) {
33 | this.avatar = avatar;
34 | }
35 |
36 | public String getSign() {
37 | return sign;
38 | }
39 |
40 | public void setSign(String sign) {
41 | this.sign = sign;
42 | }
43 |
44 | public String getType() {
45 | return type;
46 | }
47 |
48 | public void setType(String type) {
49 | this.type = type;
50 | }
51 |
52 | public String getName() {
53 | return name;
54 | }
55 |
56 | public void setName(String username) {
57 | this.name = username;
58 | }
59 |
60 | private int id;
61 | private String avatar;
62 | private String sign;
63 | private String type;
64 | private String name;
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/pojo/message/ToServerTextMessage.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.pojo.message;
2 |
3 |
4 | /**
5 | * Created by pz on 16/11/23.
6 | */
7 | public class ToServerTextMessage {
8 | public ToServerMessageMine getMine() {
9 | return mine;
10 | }
11 |
12 | public void setMine(ToServerMessageMine mine) {
13 | this.mine = mine;
14 | }
15 |
16 | public ToServerMessageTo getTo() {
17 | return to;
18 | }
19 |
20 | public void setTo(ToServerMessageTo to) {
21 | this.to = to;
22 | }
23 |
24 | private ToServerMessageMine mine;
25 | private ToServerMessageTo to;
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/serializer/FastJsonSerializer.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.serializer;
2 |
3 |
4 |
5 | import java.util.List;
6 |
7 | import com.alibaba.fastjson.JSON;
8 | import com.alibaba.fastjson.serializer.SerializerFeature;
9 |
10 | /**
11 | * Created by pz on 16/11/23.
12 | */
13 | public class FastJsonSerializer implements IJsonSerializer {
14 | /*
15 | * 使用fastjson序列化
16 | * */
17 | @Override
18 | public String toJSON(T t){
19 | if(t==null){
20 | return null;
21 | }
22 | //加上WriteMapNullValue 使得null值也被序列化
23 | return JSON.toJSONString(t, SerializerFeature.WriteMapNullValue);
24 | }
25 |
26 | /*
27 | * 使用fastjson反序列化
28 | * */
29 | @Override
30 | public T toObject(String json,Class clazz){
31 | T t = null;
32 | try {
33 | t = JSON.parseObject(json,clazz);
34 | }catch (Exception e){
35 | e.printStackTrace();
36 | }
37 | return t;
38 | }
39 | /*
40 | * tojsonArray
41 | * */
42 | @Override
43 | public List toArray(String json,Class clazz){
44 | try {
45 | List list = JSON.parseArray(json, clazz);
46 | return list;
47 | }catch (Exception e){
48 | e.printStackTrace();
49 | }
50 | return null;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/ices/yangengzhe/util/serializer/IJsonSerializer.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.util.serializer;
2 |
3 |
4 | import java.util.List;
5 |
6 | /**
7 | * Created by pz on 16/11/23.
8 | */
9 | public interface IJsonSerializer {
10 | /*
11 | * 序列化某个对象
12 | * */
13 | String toJSON(T t);
14 |
15 | /*
16 | * 反序列化
17 | * */
18 | T toObject(String json,Class clazz);
19 |
20 | /*
21 | * 序列化成数组
22 | * */
23 | List toArray(String json, Class clazz);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/resources/jdbc.properties:
--------------------------------------------------------------------------------
1 | driver=com.mysql.jdbc.Driver
2 | url=jdbc:mysql://localhost:3306/webchat?useUnicode=true&characterEncoding=UTF-8
3 | username=root
4 | password=root
5 | #定义初始连接数
6 | initialSize=1
7 | #定义最大连接数
8 | maxActive=20
9 | #定义最大空闲
10 | maxIdle=20
11 | #定义最小空闲
12 | minIdle=1
13 | #定义最长等待时间
14 | maxWait=60000
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | #定义LOG输出级别
2 | log4j.rootLogger=INFO,Console,File
3 | #定义日志输出目的地为控制台
4 | log4j.appender.Console=org.apache.log4j.ConsoleAppender
5 | log4j.appender.Console.Target=System.out
6 | #可以灵活地指定日志输出格式,下面一行是指定具体的格式
7 | log4j.appender.Console.layout = org.apache.log4j.PatternLayout
8 | log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n
9 |
10 | #文件大小到达指定尺寸的时候产生一个新的文件
11 | log4j.appender.File = org.apache.log4j.RollingFileAppender
12 | #指定输出目录
13 | log4j.appender.File.File = logs/springmvcMybist/webchat.log
14 | #定义文件最大大小
15 | log4j.appender.File.MaxFileSize = 10MB
16 | #输出所以日志,如果换成DEBUG表示输出DEBUG以上级别日志
17 | log4j.appender.File.Threshold = ALL
18 | log4j.appender.File.layout = org.apache.log4j.PatternLayout
19 | log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n
--------------------------------------------------------------------------------
/src/main/resources/spring-mvc.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
16 |
17 |
18 | text/html;charset=UTF-8
19 |
20 |
21 |
22 |
23 |
24 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
69 |
70 |
73 |
74 |
77 |
78 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/src/main/resources/spring-mybatis.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
18 |
19 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Archetype Created Web Application
4 |
5 | contextConfigLocation
6 | classpath:spring-mybatis.xml
7 |
8 |
9 | encodingFilter
10 | org.springframework.web.filter.CharacterEncodingFilter
11 | true
12 |
13 | encoding
14 | UTF-8
15 |
16 |
17 |
18 | encodingFilter
19 | /*
20 |
21 |
22 | org.springframework.web.context.ContextLoaderListener
23 |
24 |
25 | org.springframework.web.util.IntrospectorCleanupListener
26 |
27 |
28 | SpringMVC
29 | org.springframework.web.servlet.DispatcherServlet
30 |
31 | contextConfigLocation
32 | classpath:spring-mvc.xml
33 |
34 | 1
35 | true
36 |
37 |
38 | SpringMVC
39 | /
40 |
41 |
42 | /index.html
43 | /index.jsp
44 |
45 |
--------------------------------------------------------------------------------
/src/main/webapp/images/avator-qun.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangengzhe/webChat/6ba3f24054a7b06a305709fb9d39e633784a6734/src/main/webapp/images/avator-qun.png
--------------------------------------------------------------------------------
/src/main/webapp/images/avator-sf.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangengzhe/webChat/6ba3f24054a7b06a305709fb9d39e633784a6734/src/main/webapp/images/avator-sf.jpg
--------------------------------------------------------------------------------
/src/main/webapp/images/avator-sm.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangengzhe/webChat/6ba3f24054a7b06a305709fb9d39e633784a6734/src/main/webapp/images/avator-sm.jpg
--------------------------------------------------------------------------------
/src/main/webapp/images/avator-tf.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangengzhe/webChat/6ba3f24054a7b06a305709fb9d39e633784a6734/src/main/webapp/images/avator-tf.jpg
--------------------------------------------------------------------------------
/src/main/webapp/images/avator-tm.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangengzhe/webChat/6ba3f24054a7b06a305709fb9d39e633784a6734/src/main/webapp/images/avator-tm.jpg
--------------------------------------------------------------------------------
/src/main/webapp/index.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" language="java"%>
2 |
3 |
4 |
5 |
6 |
8 | webChat_LayIM by yangengzhe
9 |
10 |
11 |
16 |
17 |
18 |
310 |
311 |
312 |
313 |
--------------------------------------------------------------------------------
/src/test/java/com/ices/yangengzhe/mybatis/TestUser.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.mybatis;
2 |
3 | import org.apache.log4j.Logger;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.test.context.ContextConfiguration;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 |
10 | import com.alibaba.fastjson.JSON;
11 | import com.ices.yangengzhe.persistence.pojo.User;
12 | import com.ices.yangengzhe.service.persistence.IUserService;
13 |
14 | @RunWith(SpringJUnit4ClassRunner.class) // 表示继承了SpringJUnit4ClassRunner类
15 | @ContextConfiguration(locations = { "classpath:spring-mybatis.xml","classpath:spring-mvc.xml" })
16 |
17 | public class TestUser {
18 |
19 | private static Logger logger = Logger.getLogger(TestUser.class);
20 | // private ApplicationContext ac = null;
21 | @Autowired
22 | private IUserService userService;
23 |
24 | // @Before
25 | // public void before() {
26 | // ac = new ClassPathXmlApplicationContext("applicationContext.xml");
27 | // userService = (IUserService) ac.getBean("userService");
28 | // }
29 |
30 | // @Test
31 | public void testAdd() {
32 | try {
33 | userService.insertUser(10003,"王五","","签名3");
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 |
38 | // System.out.println(user.getUserName());
39 | // logger.info("值:"+user.getUserName());
40 | // logger.info(JSON.toJSONString(user));
41 | }
42 |
43 | @Test
44 | public void testFindByUID() {
45 | try {
46 | // User user = userService.getUserByUID(10000);
47 | User user = userService.searchUsersByKeyword("2").get(0);
48 | System.out.println(user.getName());
49 | System.out.println(JSON.toJSONString(user));
50 | } catch (Exception e) {
51 | e.printStackTrace();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/com/ices/yangengzhe/mybatis/TestUserLog.java:
--------------------------------------------------------------------------------
1 | package com.ices.yangengzhe.mybatis;
2 |
3 | import java.util.Date;
4 |
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.test.context.ContextConfiguration;
9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 |
11 | import com.ices.yangengzhe.persistence.pojo.User;
12 | import com.ices.yangengzhe.service.persistence.IUserLogService;
13 |
14 | @RunWith(SpringJUnit4ClassRunner.class) // 表示继承了SpringJUnit4ClassRunner类
15 | @ContextConfiguration(locations = { "classpath:spring-mybatis.xml" })
16 |
17 | public class TestUserLog { // private ApplicationContext ac = null;
18 | @Autowired
19 | private IUserLogService userLogService;
20 |
21 | @Test
22 | public void testAdd() {
23 | try {
24 | User user = new User();
25 | user.setAddtime(new Date());
26 | user.setHeadphoto("");
27 | user.setName("闫庚哲");
28 | user.setOnline(0);
29 | user.setPassword("123456");
30 | user.setSign("签名");
31 | user.setUid(10000);
32 | // userLogService.insertLog(user, "127.0.0.1", UserLogType.LOGIN);
33 | } catch (Exception e) {
34 | e.printStackTrace();
35 | }
36 |
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------