Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
fac10f3a
Commit
fac10f3a
authored
Oct 28, 2021
by
hewei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3_delPushToken' into '1.3'
移除旧的设备token See merge request
!2
parents
2cc48e6b
ec3e4e3f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
1 deletions
+79
-1
common/src/main/java/com/wecloud/im/controller/ImClientController.java
+13
-0
common/src/main/java/com/wecloud/im/mapper/ImClientMapper.java
+4
-0
common/src/main/java/com/wecloud/im/service/ImClientService.java
+12
-0
common/src/main/java/com/wecloud/im/service/impl/ImClientServiceImpl.java
+44
-1
common/src/main/resources/mapper/ImClientMapper.xml
+6
-0
No files found.
common/src/main/java/com/wecloud/im/controller/ImClientController.java
View file @
fac10f3a
...
@@ -58,6 +58,19 @@ public class ImClientController extends BaseController {
...
@@ -58,6 +58,19 @@ public class ImClientController extends BaseController {
/**
/**
* 退出登陆
*
* @return
* @throws Exception
*/
@PostMapping
(
"/logout"
)
@ApiOperation
(
value
=
"退出登陆 清除推送token等"
)
public
ApiResult
<
Boolean
>
logout
()
throws
Exception
{
boolean
flag
=
imClientService
.
logout
();
return
ApiResult
.
result
(
flag
);
}
/**
* 获取用户在线状态(批量)
* 获取用户在线状态(批量)
*
*
* @return true:在线, false 不在线
* @return true:在线, false 不在线
...
...
common/src/main/java/com/wecloud/im/mapper/ImClientMapper.java
View file @
fac10f3a
...
@@ -37,4 +37,8 @@ public interface ImClientMapper extends BaseMapper<ImClient> {
...
@@ -37,4 +37,8 @@ public interface ImClientMapper extends BaseMapper<ImClient> {
*/
*/
IPage
<
ImClientQueryVo
>
getImClientPageList
(
@Param
(
"page"
)
Page
page
,
@Param
(
"param"
)
ImClientPageParam
imClientPageParam
);
IPage
<
ImClientQueryVo
>
getImClientPageList
(
@Param
(
"page"
)
Page
page
,
@Param
(
"param"
)
ImClientPageParam
imClientPageParam
);
int
removeOldToken
(
@Param
(
"appId"
)
Long
appId
,
@Param
(
"deviceToken"
)
String
deviceToken
);
}
}
common/src/main/java/com/wecloud/im/service/ImClientService.java
View file @
fac10f3a
...
@@ -32,6 +32,9 @@ public interface ImClientService extends BaseService<ImClient> {
...
@@ -32,6 +32,9 @@ public interface ImClientService extends BaseService<ImClient> {
*/
*/
boolean
updateDeviceInfo
(
ImClientDeviceInfoAdd
imClientDevice
);
boolean
updateDeviceInfo
(
ImClientDeviceInfoAdd
imClientDevice
);
boolean
logout
();
/**
/**
* 修改
* 修改
*
*
...
@@ -60,6 +63,15 @@ public interface ImClientService extends BaseService<ImClient> {
...
@@ -60,6 +63,15 @@ public interface ImClientService extends BaseService<ImClient> {
ImClientQueryVo
getImClientById
(
Long
id
)
throws
Exception
;
ImClientQueryVo
getImClientById
(
Long
id
)
throws
Exception
;
/**
/**
* 移除旧的设备token
*
* @param appId
* @param deviceToken
* @return
*/
int
removeOldToken
(
Long
appId
,
String
deviceToken
);
/**
* 获取分页对象
* 获取分页对象
*
*
* @param imClientPageParam
* @param imClientPageParam
...
...
common/src/main/java/com/wecloud/im/service/impl/ImClientServiceImpl.java
View file @
fac10f3a
package
com
.
wecloud
.
im
.
service
.
impl
;
package
com
.
wecloud
.
im
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
...
@@ -51,18 +52,53 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
...
@@ -51,18 +52,53 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
boolean
updateDeviceInfo
(
ImClientDeviceInfoAdd
imClientDevice
)
{
public
boolean
updateDeviceInfo
(
ImClientDeviceInfoAdd
imClientDevice
)
{
// shiro线程中获取当前token
JwtToken
curentJwtToken
=
JwtUtil
.
getCurentJwtToken
();
// 根据appKey查询appid
ImApplication
imApplication
=
imApplicationService
.
getOneByAppKey
(
curentJwtToken
.
getAppKey
());
// 清除旧client的redis缓存
ImClient
imClient
=
this
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
imApplication
.
getId
())
.
eq
(
ImClient:
:
getDeviceToken
,
imClientDevice
.
getDeviceToken
()));
if
(
imClient
!=
null
)
{
deleteCacheImClient
(
imClient
.
getFkAppid
(),
imClient
.
getClientId
());
// client登陆的时候 判断数据库内是否已经存在这个设备token,如果存在就清空旧的
this
.
removeOldToken
(
imApplication
.
getId
(),
curentJwtToken
.
getToken
());
}
ImClient
client
=
getCurentClient
();
ImClient
client
=
getCurentClient
();
ImClient
clientNew
=
new
ImClient
();
ImClient
clientNew
=
new
ImClient
();
BeanUtils
.
copyProperties
(
imClientDevice
,
clientNew
);
BeanUtils
.
copyProperties
(
imClientDevice
,
clientNew
);
clientNew
.
setId
(
client
.
getId
());
clientNew
.
setId
(
client
.
getId
());
// 清
楚
缓存
// 清
除新client的redis
缓存
deleteCacheImClient
(
client
.
getFkAppid
(),
client
.
getClientId
());
deleteCacheImClient
(
client
.
getFkAppid
(),
client
.
getClientId
());
// 修改
// 修改
return
this
.
updateImClient
(
clientNew
);
return
this
.
updateImClient
(
clientNew
);
}
}
@Override
public
boolean
logout
()
{
ImClient
curentClient
=
getCurentClient
();
// 清除设备token
boolean
update
=
this
.
update
(
new
UpdateWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
curentClient
.
getFkAppid
())
.
eq
(
ImClient:
:
getId
,
curentClient
.
getId
())
.
set
(
ImClient:
:
getDeviceToken
,
null
)
);
if
(
update
)
{
// 清除新client的redis缓存
deleteCacheImClient
(
curentClient
.
getFkAppid
(),
curentClient
.
getClientId
());
}
return
update
;
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
@Override
public
boolean
updateImClient
(
ImClient
imClient
)
{
public
boolean
updateImClient
(
ImClient
imClient
)
{
...
@@ -75,6 +111,13 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
...
@@ -75,6 +111,13 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
return
super
.
removeById
(
id
);
return
super
.
removeById
(
id
);
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
int
removeOldToken
(
Long
appId
,
String
deviceToken
)
{
return
imClientMapper
.
removeOldToken
(
appId
,
deviceToken
);
}
@Override
@Override
public
ImClientQueryVo
getImClientById
(
Long
id
)
throws
Exception
{
public
ImClientQueryVo
getImClientById
(
Long
id
)
throws
Exception
{
return
imClientMapper
.
getImClientById
(
id
);
return
imClientMapper
.
getImClientById
(
id
);
...
...
common/src/main/resources/mapper/ImClientMapper.xml
View file @
fac10f3a
...
@@ -7,6 +7,12 @@
...
@@ -7,6 +7,12 @@
id
id
, create_time, update_time, fk_appid, attributes,device_type,valid
, create_time, update_time, fk_appid, attributes,device_type,valid
</sql>
</sql>
<update
id=
"removeOldToken"
>
UPDATE im_client
SET device_token = NULL
WHERE device_token = #{deviceToken}
AND fk_appid = #{appId}
</update>
<select
id=
"getImClientById"
resultType=
"com.wecloud.im.param.ImClientQueryVo"
>
<select
id=
"getImClientById"
resultType=
"com.wecloud.im.param.ImClientQueryVo"
>
select
select
...
...
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