Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hel-developer-guide
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hel-guide
hel-developer-guide
Commits
736e47c7
Commit
736e47c7
authored
Aug 02, 2017
by
Jefferyne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creates assets/11341.png
Auto commit by GitBook Editor
parent
d3dba8cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
0 deletions
+117
-0
11341.png
assets/11341.png
+0
-0
消息机制.md
后端开发/消息机制.md
+117
-0
No files found.
assets/11341.png
0 → 100644
View file @
736e47c7
30.1 KB
后端开发/消息机制.md
0 → 100644
View file @
736e47c7
# 消息机制
简介:实时弹出提示消息或待办
### 1.消息机制入口
对任何需要提示的操作,都需要将这个消息以键-值对的形式存入到redis中,调用setNoticeCache()方法即可
```
java
SysEventServieImpl
.
java
@Override
public
void
setNoticeCache
(
HlsSystemNotice
hlsSystemNotice
)
{
sysNoticePushService
.
sendUserNotice
(
hlsSystemNotice
.
getSource_user_id
(),
hlsSystemNotice
);
List
<
HlsSystemNotice
>
noticeToList
=
hlsSystemNoticeService
.
selectSendNotice
(
hlsSystemNotice
);
if
(
noticeToList
!=
null
){
for
(
HlsSystemNotice
hlsSystemNotice1:
noticeToList
){
sysNoticePushService
.
sendUserNotice
(
hlsSystemNotice1
.
getUserId
(),
hlsSystemNotice
);
}
}
}
```
redis中的存在形式:
```
java
SysNoticePushServiceImpl
.
java
@Override
public
void
sendUserNotice
(
Long
userId
,
HlsSystemNotice
hlsSystemNotice
)
{
String
hashKey
=
"messageBox-"
+
userId
.
toString
()
+
"-"
+
System
.
currentTimeMillis
()
+
"-"
+
Math
.
random
();
String
key
=
"messageBox-"
+
userId
.
toString
();
hashOperations
.
put
(
hashKey
,
"userId"
,
hlsSystemNotice
);
listOperations
.
rightPush
(
key
,
hashKey
);
}
```
前端以ajax轮询的方法发送请求获取需要展示的消息:
```
js
<
script
>
setInterval
(
moment_show
,
6000
);
function
moment_show
(
contextPath
){
$
.
ajax
({
type
:
'POST'
,
async
:
false
,
//设为同步
url
:
'${base.contextPath}/hls/user/send/notice'
,
contentType
:
"application/json; charset=utf-8"
,
dataType
:
"json"
,
success
:
function
(
datas
)
{
if
(
datas
.
length
>
0
)
{
push_float_msg
(
datas
);
setTimeout
(
function
(){
moment_hide
(
msgLength
);},
3000
);
}
}
});
};
<
/script
>
```
redis中取值机制:
```
java
SysNoticePushServiceImpl
.
java
@Override
public
List
<
HlsSystemNotice
>
getUserNotice
(
Long
userId
)
{
String
key
=
"messageBox-"
+
userId
.
toString
();
List
<
HlsSystemNotice
>
retList
=
new
ArrayList
<
HlsSystemNotice
>();
if
(
listOperations
!=
null
){
List
<
String
>
keys
=
listOperations
.
range
(
key
,
0
,
-
1
);
for
(
int
i
=
0
;
i
<
keys
.
size
();
i
++)
{
if
(
i
==
5
)
{
break
;
}
boolean
rep
=
true
;
boolean
currentUserTodo
=
false
;
if
(
hashOperations
!=
null
){
HlsSystemNotice
hlsSystemNotice
=
(
HlsSystemNotice
)
hashOperations
.
get
(
keys
.
get
(
i
),
"userId"
);
for
(
int
m
=
0
;
m
<
retList
.
size
();
m
++)
{
if
(
retList
.
get
(
m
).
getNotice_id
()
==
hlsSystemNotice
.
getNotice_id
())
{
rep
=
false
;
}
}
if
(
hlsSystemNotice
.
getNotice_type
()
==
"TO_DO"
)
{
if
(
hlsSystemNotice
.
getSource_user_id
()
==
userId
)
{
currentUserTodo
=
true
;
}
else
{
currentUserTodo
=
false
;
}
}
else
{
currentUserTodo
=
true
;
}
if
(
rep
&&
currentUserTodo
)
{
retList
.
add
(
hlsSystemNotice
);
}
listOperations
.
remove
(
key
,
1
,
keys
.
get
(
i
));
hashOperations
.
delete
(
keys
.
get
(
i
),
"userId"
);
}
}
}
else
{
HlsSystemNotice
notice
=
new
HlsSystemNotice
();
notice
.
setNotice_title
(
"test"
);
notice
.
setUserId
(
Long
.
parseLong
(
"10172"
));
notice
.
setRead_flag
(
"N"
);
notice
.
setDone_flag
(
"N"
);
notice
.
setNotice_message
(
"test-msg"
);
retList
.
add
(
notice
);
}
return
retList
;
}
}
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment