Commit b295848f by giaogiao

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

parent 2cc48e6b
......@@ -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);
}
......@@ -60,6 +60,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
......
......@@ -51,12 +51,29 @@ 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());
// 修改
......@@ -75,6 +92,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