Commit b295848f by giaogiao

移除旧的设备token: client登陆的时候 判断数据库内是否已经存在这个设备token,如果存在就清空旧的

parent 2cc48e6b
...@@ -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);
} }
...@@ -60,6 +60,15 @@ public interface ImClientService extends BaseService<ImClient> { ...@@ -60,6 +60,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
......
...@@ -51,12 +51,29 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien ...@@ -51,12 +51,29 @@ 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());
// 修改 // 修改
...@@ -75,6 +92,13 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien ...@@ -75,6 +92,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);
......
...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment