Commit fac10f3a by hewei

Merge branch '1.3_delPushToken' into '1.3'

移除旧的设备token

See merge request !2
parents 2cc48e6b ec3e4e3f
......@@ -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 不在线
......
......@@ -37,4 +37,8 @@ public interface ImClientMapper extends BaseMapper<ImClient> {
*/
IPage<ImClientQueryVo> getImClientPageList(@Param("page") Page page, @Param("param") ImClientPageParam imClientPageParam);
int removeOldToken(@Param("appId") Long appId, @Param("deviceToken") String deviceToken);
}
......@@ -32,6 +32,9 @@ public interface ImClientService extends BaseService<ImClient> {
*/
boolean updateDeviceInfo(ImClientDeviceInfoAdd imClientDevice);
boolean logout();
/**
* 修改
*
......@@ -60,6 +63,15 @@ public interface ImClientService extends BaseService<ImClient> {
ImClientQueryVo getImClientById(Long id) throws Exception;
/**
* 移除旧的设备token
*
* @param appId
* @param deviceToken
* @return
*/
int removeOldToken(Long appId, String deviceToken);
/**
* 获取分页对象
*
* @param imClientPageParam
......
package com.wecloud.im.service.impl;
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.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
......@@ -51,18 +52,53 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
@Override
@Transactional(rollbackFor = Exception.class)
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 clientNew = new ImClient();
BeanUtils.copyProperties(imClientDevice, clientNew);
clientNew.setId(client.getId());
// 清缓存
// 清除新client的redis缓存
deleteCacheImClient(client.getFkAppid(), client.getClientId());
// 修改
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)
@Override
public boolean updateImClient(ImClient imClient) {
......@@ -75,6 +111,13 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
return super.removeById(id);
}
@Transactional(rollbackFor = Exception.class)
@Override
public int removeOldToken(Long appId, String deviceToken) {
return imClientMapper.removeOldToken(appId, deviceToken);
}
@Override
public ImClientQueryVo getImClientById(Long id) throws Exception {
return imClientMapper.getImClientById(id);
......
......@@ -7,6 +7,12 @@
id
, create_time, update_time, fk_appid, attributes,device_type,valid
</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
......
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