Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
御承扬
Campus
提交
7f394e90
C
Campus
项目概览
御承扬
/
Campus
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Campus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7f394e90
编写于
12月 31, 2020
作者:
7
7wc98#14
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add function
上级
168c0318
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
194 addition
and
6 deletion
+194
-6
src/main/java/com/pyc/campus/config/WebMVCConfig.java
src/main/java/com/pyc/campus/config/WebMVCConfig.java
+1
-0
src/main/java/com/pyc/campus/config/WebSocketConfig.java
src/main/java/com/pyc/campus/config/WebSocketConfig.java
+2
-1
src/main/java/com/pyc/campus/controller/ChatController.java
src/main/java/com/pyc/campus/controller/ChatController.java
+13
-0
src/main/java/com/pyc/campus/controller/WebController.java
src/main/java/com/pyc/campus/controller/WebController.java
+62
-0
src/main/java/com/pyc/campus/dao/FriendListRepository.java
src/main/java/com/pyc/campus/dao/FriendListRepository.java
+6
-1
src/main/java/com/pyc/campus/dao/StudentRepository.java
src/main/java/com/pyc/campus/dao/StudentRepository.java
+3
-0
src/main/resources/templates/page/MyFriend.html
src/main/resources/templates/page/MyFriend.html
+4
-2
src/main/resources/templates/page/PrivateChat.html
src/main/resources/templates/page/PrivateChat.html
+73
-0
src/main/resources/templates/page/VerifyFriend.html
src/main/resources/templates/page/VerifyFriend.html
+30
-2
未找到文件。
src/main/java/com/pyc/campus/config/WebMVCConfig.java
浏览文件 @
7f394e90
...
...
@@ -25,5 +25,6 @@ public class WebMVCConfig extends WebMvcConfigurerAdapter {
// registry.addViewController("/home").setViewName("page/Home");
registry
.
addViewController
(
"/aboutLearn"
).
setViewName
(
"page/AboutLearn"
);
registry
.
addViewController
(
"/publicChatRoom"
).
setViewName
(
"PublicChatRoom"
);
registry
.
addViewController
(
"/chat"
).
setViewName
(
"page/PrivateChat"
);
}
}
src/main/java/com/pyc/campus/config/WebSocketConfig.java
浏览文件 @
7f394e90
...
...
@@ -20,10 +20,11 @@ public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public
void
registerStompEndpoints
(
StompEndpointRegistry
registry
)
{
registry
.
addEndpoint
(
"/endpointPublicChat"
).
withSockJS
();
registry
.
addEndpoint
(
"/endPointChat"
).
withSockJS
();
}
@Override
public
void
configureMessageBroker
(
MessageBrokerRegistry
registry
)
{
registry
.
enableSimpleBroker
(
"/publicChat"
);
registry
.
enableSimpleBroker
(
"/
queue"
,
"/
publicChat"
);
}
}
src/main/java/com/pyc/campus/controller/ChatController.java
浏览文件 @
7f394e90
...
...
@@ -9,10 +9,16 @@ package com.pyc.campus.controller;
import
com.pyc.campus.domain.PublishMessage
;
import
com.pyc.campus.domain.ResponseMessage
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.repository.query.Param
;
import
org.springframework.messaging.handler.annotation.DestinationVariable
;
import
org.springframework.messaging.handler.annotation.MessageMapping
;
import
org.springframework.messaging.handler.annotation.SendTo
;
import
org.springframework.messaging.simp.SimpMessagingTemplate
;
import
org.springframework.stereotype.Controller
;
import
java.security.Principal
;
@Controller
public
class
ChatController
{
@MessageMapping
(
"/publicChatRoom"
)
...
...
@@ -21,4 +27,11 @@ public class ChatController {
Thread
.
sleep
(
500
);
return
new
ResponseMessage
(
message
.
getName
()+
":"
+
message
.
getContent
());
}
@Autowired
private
SimpMessagingTemplate
messagingTemplate
;
@MessageMapping
(
value
=
"/chat/{name}"
)
public
void
handleChat
(
Principal
principal
,
String
msg
,
@DestinationVariable
String
name
){
messagingTemplate
.
convertAndSendToUser
(
name
,
"/queue/notification"
,
principal
.
getName
()+
"-send:"
+
msg
);
}
}
src/main/java/com/pyc/campus/controller/WebController.java
浏览文件 @
7f394e90
...
...
@@ -163,6 +163,68 @@ public class WebController {
model
.
addAttribute
(
"fl"
,
fl
);
return
"page/VerifyFriend"
;
}
@RequestMapping
(
"/verifyFriend"
)
public
String
verifyFried
(
Model
model
,
HttpSession
session
,
@Param
(
"fromName"
)
String
fromName
){
SecurityContextImpl
securityContext
=
(
SecurityContextImpl
)
session
.
getAttribute
(
"SPRING_SECURITY_CONTEXT"
);
String
currentStudentId
=
((
UserDetails
)
securityContext
.
getAuthentication
().
getPrincipal
()).
getUsername
();
Student
s
=
studentRepository
.
findNameByStudentID
(
currentStudentId
);
int
result
=
friendListRepository
.
setStatus
(
fromName
,
currentStudentId
);
List
<
FriendList
>
fl
=
friendListRepository
.
toNameIsFalseByToName
(
currentStudentId
);
int
len
=
fl
.
size
();
if
(
result
!=
0
){
Msg
msg
=
new
Msg
(
"待验证好友申请数量:"
,
"一共"
+
len
+
"个"
,
""
);
model
.
addAttribute
(
"msg"
,
msg
);
model
.
addAttribute
(
"curUse"
,
s
);
model
.
addAttribute
(
"fl"
,
fl
);
return
"page/VerifyFriend"
;
}
Msg
msg
=
new
Msg
(
"错误:"
,
"请检查输入的学号"
,
""
);
model
.
addAttribute
(
"msg"
,
msg
);
model
.
addAttribute
(
"curUse"
,
s
);
model
.
addAttribute
(
"fl"
,
fl
);
return
"page/VerifyFriend"
;
}
@RequestMapping
(
"/toPrivateChat"
)
public
String
toPrivateChat
(
Model
model
,
HttpSession
session
,
@Param
(
"toName"
)
String
toName
){
SecurityContextImpl
securityContext
=
(
SecurityContextImpl
)
session
.
getAttribute
(
"SPRING_SECURITY_CONTEXT"
);
String
currentStudentId
=
((
UserDetails
)
securityContext
.
getAuthentication
().
getPrincipal
()).
getUsername
();
boolean
s
;
FriendList
s1
=
friendListRepository
.
getStatus
(
currentStudentId
,
toName
);
FriendList
s2
=
friendListRepository
.
getStatus
(
toName
,
currentStudentId
);
if
(
s1
!=
null
)
s
=
s1
.
getStatus
();
else
if
(
s2
!=
null
)
s
=
s2
.
getStatus
();
else
s
=
false
;
model
.
addAttribute
(
"friendStatus"
,
s
);
if
(
s
)
{
boolean
stu
=
studentRepository
.
getOnlineStatus
(
toName
).
isOnlineStatus
();
model
.
addAttribute
(
"onlineStatus"
,
stu
);
if
(
stu
)
{
Msg
msg
=
new
Msg
(
"提示:"
,
"对方在线,当前只提供临时聊天,不保存聊天记录,见谅"
,
""
);
model
.
addAttribute
(
"fromName"
,
currentStudentId
);
model
.
addAttribute
(
"toName"
,
toName
);
model
.
addAttribute
(
"msg"
,
msg
);
return
"page/PrivateChat"
;
}
Msg
msg
=
new
Msg
(
"提示:"
,
"对方不在线,你所发送的消息,可能无法被及时回复"
,
""
);
model
.
addAttribute
(
"fromName"
,
currentStudentId
);
model
.
addAttribute
(
"toName"
,
toName
);
model
.
addAttribute
(
"msg"
,
msg
);
return
"page/PrivateChat"
;
}
Msg
msg
=
new
Msg
(
"提示:"
,
"对方不是你的好友,无法进行私聊"
,
""
);
model
.
addAttribute
(
"fromName"
,
currentStudentId
);
model
.
addAttribute
(
"toName"
,
toName
);
model
.
addAttribute
(
"msg"
,
msg
);
return
"page/PrivateChat"
;
}
@RequestMapping
(
"/toChangePWD"
)
public
String
toChangePWD
(
Model
model
,
HttpSession
session
){
SecurityContextImpl
securityContext
=
(
SecurityContextImpl
)
session
.
getAttribute
(
"SPRING_SECURITY_CONTEXT"
);
...
...
src/main/java/com/pyc/campus/dao/FriendListRepository.java
浏览文件 @
7f394e90
...
...
@@ -33,5 +33,10 @@ public interface FriendListRepository extends JpaRepository<FriendList,Long> {
@Transactional
@Query
(
"select fl from FriendList fl where fl.toName=?1 and fl.status=true"
)
List
<
FriendList
>
findMyFriendsByToName
(
String
toName
);
@Modifying
@Transactional
@Query
(
"update FriendList fl set fl.status=true where fl.fromName=?1 and fl.toName=?2"
)
int
setStatus
(
String
fromName
,
String
toName
);
@Query
(
"select fl from FriendList fl where fl.fromName=?1 and fl.toName=?2"
)
FriendList
getStatus
(
String
fromName
,
String
toName
);
}
src/main/java/com/pyc/campus/dao/StudentRepository.java
浏览文件 @
7f394e90
...
...
@@ -31,6 +31,9 @@ public interface StudentRepository extends JpaRepository<Student,Long> {
@Transactional
@Query
(
"update Student s set s.onlineStatus=?1 where s.studentID=?2"
)
void
setOnlineStatus
(
Boolean
onlineStatus
,
String
studentID
);
@Query
(
"select s from Student s where s.studentID=?1"
)
Student
getOnlineStatus
(
String
studentID
);
// 根据Student ID前缀查询
@Modifying
@Transactional
...
...
src/main/resources/templates/page/MyFriend.html
浏览文件 @
7f394e90
...
...
@@ -150,10 +150,12 @@
<h3
class=
"panel-title"
>
好友列表
</h3>
</div>
<div
class=
"panel-body"
>
<ul
class=
"list-group"
th:if=
"${not #lists.isEmpty(Fl)
or #lists.isEmpty(Fl1)
}"
>
<ul
class=
"list-group"
th:if=
"${not #lists.isEmpty(Fl)}"
>
<li
class=
"list-group-item list-group-item-info"
th:each=
"FL:${Fl}"
>
<span
th:text=
"${FL.getToName()}"
></span>
</li>
</ul>
<ul
class=
"list-group"
th:if=
"${not #lists.isEmpty(Fl1)}"
>
<li
class=
"list-group-item list-group-item-info"
th:each=
"FL1:${Fl1}"
>
<span
th:text=
"${FL1.getFromName()}"
></span>
</li>
...
...
@@ -181,7 +183,7 @@
</li>
<li
class=
"list-group-item-heading"
>
请输入要发起私聊的好友学号:
</li>
<li
class=
"list-group-item-text"
>
<form
name=
"chatFrom"
method=
"post"
action=
"
#"
onsubmit=
"check()
"
>
<form
name=
"chatFrom"
method=
"post"
action=
"
/toPrivateChat"
th:action=
"@{/toPrivateChat}"
onsubmit=
"check()"
target=
"_blank
"
>
<label>
<input
type=
"text"
name=
"toName"
placeholder=
"示例:201724073161"
>
</label>
...
...
src/main/resources/templates/page/PrivateChat.html
0 → 100644
浏览文件 @
7f394e90
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
lang=
"en"
>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
/>
<title>
私聊
</title>
<script
src=
"js/stomp.min.js"
></script>
<script
src=
"js/sockjs.min.js"
></script>
<script
src=
"js/jquery.js"
></script>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link
rel=
"stylesheet"
href=
"https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
integrity=
"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin=
"anonymous"
>
<!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
<link
rel=
"stylesheet"
href=
"https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css"
integrity=
"sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin=
"anonymous"
>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script
src=
"https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
integrity=
"sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin=
"anonymous"
></script>
<script
src=
"https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"
></script>
</head>
<body>
<div
class=
"panel panel-primary"
>
<div
class=
"page-header"
>
<h3
class=
"panel-title"
>
注意
</h3>
</div>
<div
class=
"panel-body"
>
<div
class=
"panel-heading"
th:text=
"${msg.title}"
></div>
<div
class=
"panel-info"
th:text=
"${msg.content}"
></div>
</div>
</div>
<div
th:if=
"${friendStatus}"
>
<p>
聊天室
</p>
<form
id=
"chatForm"
>
<label
for=
"fromName"
>
我:
</label>
<input
type=
"text"
id=
"fromName"
name=
"fromName"
th:value=
"${fromName}"
readonly=
"readonly"
>
<br>
<label
for=
"toName"
>
对方:
</label>
<input
type=
"text"
id=
"toName"
name=
"toName"
th:value=
"${toName}"
readonly=
"readonly"
>
<br>
<label>
<textarea
rows=
"4"
cols=
"60"
name=
"text"
></textarea>
</label>
<br>
<input
type=
"submit"
value=
"发送"
>
</form>
<div
class=
"col-md-8"
id=
"output"
></div>
</div>
<script
th:inline=
"javascript"
>
$
(
'
#chatForm
'
).
submit
(
function
(
e
)
{
e
.
preventDefault
();
var
text
=
$
(
'
#chatForm
'
).
find
(
'
textarea[name="text"]
'
).
val
();
var
fromName
=
$
(
'
#chatForm
'
).
find
(
'
input[name="fromName"]
'
).
val
();
var
toName
=
$
(
'
#chatForm
'
).
find
(
'
input[name="toName"]
'
).
val
();
sendSpittle
(
text
,
fromName
,
toName
);
});
var
sock
=
new
SockJS
(
"
/endPointChat
"
);
var
stomp
=
Stomp
.
over
(
sock
);
stomp
.
connect
(
'
guest
'
,
'
guest
'
,
function
(
frame
)
{
stomp
.
subscribe
(
"
/user/queue/notification
"
,
handleNotification
);
});
function
handleNotification
(
message
)
{
$
(
'
#output
'
).
append
(
"
</br>Received:
"
+
message
.
body
+
"
</b></br>
"
)
}
function
sendSpittle
(
text
,
fromName
,
toName
)
{
stomp
.
send
(
"
/chat/
"
+
toName
,{},
text
);
}
$
(
'
#stop
'
).
click
(
function
()
{
sock
.
close
()
});
</script>
</body>
\ No newline at end of file
src/main/resources/templates/page/VerifyFriend.html
浏览文件 @
7f394e90
...
...
@@ -138,6 +138,7 @@
<div
class=
"panel-body"
>
<ul
class=
"list-group"
th:if=
"${not #lists.isEmpty(fl)}"
>
<li
class=
"list-group-item list-group-item-info"
th:each=
"TFL:${fl}"
>
<!--/*@thymesVar id="getFromName" type="com.pyc.campus.domain.FriendList"*/-->
<span
th:text=
"${TFL.getFromName()}"
></span>
</li>
</ul>
...
...
@@ -145,10 +146,37 @@
</div>
</div>
</div>
<!--TODO:编辑通过好友申请的功能-->
<div
class=
"col-md-8"
>
<div
class=
"col-md-6"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<h3
class=
"panel-title"
>
好友申请确认
</h3>
</div>
<div
class=
"panel-body"
>
<ul
class=
"list-group"
>
<li
class=
"list-group-item-heading"
>
请输入通过好友申请的学号:
</li>
<li
class=
"list-group-item-text"
>
<form
name=
"browseFriendInfo"
method=
"post"
th:action=
"@{/verifyFriend}"
action=
"/verifyFriend"
onsubmit=
"return check(browseFriendInfo.toName.value)"
>
<label>
<input
type=
"text"
name=
"fromName"
placeholder=
"示例:201724073161"
>
</label>
<input
class=
"btn-primary"
type=
"submit"
value=
"确认"
>
</form>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script
type=
"text/javascript"
>
function
check
(
value
)
{
if
(
value
!==
""
)
return
true
;
return
false
;
}
</script>
<div
id=
"after_sale"
>
<div
class=
"container"
>
<ul>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录