Commit 95abf9f1 by giaogiao

Merge branch '1.3' of https://gitlab.aillo.cc/hewei/wecloud_im_server into feature-cluster

 Conflicts:
	common/src/main/java/com/wecloud/im/ws/sender/SystemPush.java
parents 19d280e3 6f7ab054
...@@ -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 不在线
......
...@@ -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);
} }
package com.wecloud.im.param.add; package com.wecloud.im.param.add;
import com.wecloud.im.ws.model.request.PushModel;
import io.geekidea.springbootplus.framework.common.entity.BaseEntity; import io.geekidea.springbootplus.framework.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -7,8 +8,6 @@ import lombok.Data; ...@@ -7,8 +8,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.util.HashMap;
/** /**
* 撤回消息 * 撤回消息
* *
...@@ -26,6 +25,6 @@ public class ImMsgRecall extends BaseEntity { ...@@ -26,6 +25,6 @@ public class ImMsgRecall extends BaseEntity {
private Long msgId; private Long msgId;
@ApiModelProperty("自定义推送字段") @ApiModelProperty("自定义推送字段")
private HashMap pushMap; private PushModel push;
} }
...@@ -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
......
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);
......
...@@ -24,6 +24,7 @@ import com.wecloud.im.service.ImMessageService; ...@@ -24,6 +24,7 @@ import com.wecloud.im.service.ImMessageService;
import com.wecloud.im.vo.ImMessageOfflineListVo; import com.wecloud.im.vo.ImMessageOfflineListVo;
import com.wecloud.im.vo.OfflineMsgDto; import com.wecloud.im.vo.OfflineMsgDto;
import com.wecloud.im.ws.model.ResponseModel; import com.wecloud.im.ws.model.ResponseModel;
import com.wecloud.im.ws.model.request.PushModel;
import com.wecloud.im.ws.sender.PushTask; import com.wecloud.im.ws.sender.PushTask;
import com.wecloud.im.ws.service.WriteDataService; import com.wecloud.im.ws.service.WriteDataService;
import io.geekidea.springbootplus.framework.common.api.ApiCode; import io.geekidea.springbootplus.framework.common.api.ApiCode;
...@@ -39,11 +40,8 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -39,11 +40,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import static com.wecloud.im.ws.strategy.concrete.ImConcreteReceiveStrategy.PUSH_KEY;
/** /**
* 消息存储表 服务实现类 * 消息存储表 服务实现类
* *
...@@ -106,11 +104,7 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes ...@@ -106,11 +104,7 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
boolean saveOk = this.updateById(messageById); boolean saveOk = this.updateById(messageById);
if (saveOk) { if (saveOk) {
// 获取自定义推送字段
HashMap<String, String> pushMap = null;
if (imMsgRecall.getPushMap().get(PUSH_KEY) != null) {
pushMap = (HashMap<String, String>) imMsgRecall.getPushMap().get(PUSH_KEY);
}
// 查询该会话所有成员 // 查询该会话所有成员
List<ImConversationMembers> membersList = imConversationMembersService.list( List<ImConversationMembers> membersList = imConversationMembersService.list(
...@@ -166,8 +160,11 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes ...@@ -166,8 +160,11 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
responseModel.setReqId(null); responseModel.setReqId(null);
writeDataService.write(responseModel, imApplication.getAppKey(), imClientReceiver.getClientId()); writeDataService.write(responseModel, imApplication.getAppKey(), imClientReceiver.getClientId());
// 获取自定义推送字段
PushModel pushModel = imMsgRecall.getPush();
// 异步推送系统通知消息 // 异步推送系统通知消息
pushTask.push(pushMap, imClientReceiver, imApplication); pushTask.push(pushModel, imClientReceiver, imApplication);
} }
return ApiResult.ok(); return ApiResult.ok();
......
package com.wecloud.im.ws.model.request; package com.wecloud.im.ws.model.request;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
...@@ -12,8 +10,6 @@ import java.io.Serializable; ...@@ -12,8 +10,6 @@ import java.io.Serializable;
* @Date 2019-12-05 * @Date 2019-12-05
*/ */
@Data @Data
@NoArgsConstructor
@AllArgsConstructor
public class PushModel implements Serializable { public class PushModel implements Serializable {
/** /**
......
...@@ -31,7 +31,7 @@ import java.util.Map; ...@@ -31,7 +31,7 @@ import java.util.Map;
*/ */
@Component @Component
@Slf4j @Slf4j
public class SystemPush { public class PushTask {
@Autowired @Autowired
private ImIosApnsService imIosApnsService; private ImIosApnsService imIosApnsService;
...@@ -58,23 +58,20 @@ public class SystemPush { ...@@ -58,23 +58,20 @@ public class SystemPush {
private static final String title = "title"; private static final String title = "title";
private static final String subTitle = "subTitle"; private static final String subTitle = "subTitle";
/** /**
* 异步系统推送 * 异步系统推送
* *
* @param imClientReceiver * @param imClientReceiver
*/ */
@Async @Async
public void push(HashMap<String, String> pushMap, ImClient imClientReceiver, ImApplication imApplication, PushType pushType) { public void push(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) {
log.info("push:" + imClientReceiver.getClientId()); log.info("push:" + imClientReceiver.getClientId());
PushModel pushModel = new PushModel(); if (pushModel == null) {
pushModel = new PushModel();
if (pushMap == null || pushMap.isEmpty()) {
pushModel.setTitle(PUSH_TITLE); pushModel.setTitle(PUSH_TITLE);
pushModel.setSubTitle(PUSH_BODY); pushModel.setSubTitle(PUSH_BODY);
} else {
pushModel.setTitle(pushMap.get(title));
pushModel.setSubTitle(pushMap.get(subTitle));
} }
// 校验参数 // 校验参数
...@@ -90,13 +87,37 @@ public class SystemPush { ...@@ -90,13 +87,37 @@ public class SystemPush {
// 设备类型1:ios; 2:android // 设备类型1:ios; 2:android
if (imClientReceiver.getDeviceType() == 1) { if (imClientReceiver.getDeviceType() == 1) {
ios(pushModel, imClientReceiver, imApplication, pushType); ios(pushModel, imClientReceiver, imApplication);
} else if (imClientReceiver.getDeviceType() == 2) { } else {
android(pushModel, imClientReceiver, imApplication); android(pushModel, imClientReceiver, imApplication);
} }
} }
/**
* 异步系统推送
*
* @param imClientReceiver
*/
@Async
public void push(HashMap<String, String> pushMap, ImClient imClientReceiver, ImApplication imApplication) {
log.info("push:" + imClientReceiver.getClientId());
PushModel pushModel = new PushModel();
if (pushMap == null || pushMap.isEmpty()) {
pushModel.setTitle(PUSH_TITLE);
pushModel.setSubTitle(PUSH_BODY);
} else {
pushModel.setTitle(pushMap.get(title));
pushModel.setSubTitle(pushMap.get(subTitle));
}
this.push(pushModel, imClientReceiver, imApplication);
}
private void android(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) { private void android(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) {
// 安卓推送通道,友盟:1;firebase:2; 信鸽3 // 安卓推送通道,友盟:1;firebase:2; 信鸽3
if (imApplication.getAndroidPushChannel() == 1) { if (imApplication.getAndroidPushChannel() == 1) {
...@@ -130,7 +151,7 @@ public class SystemPush { ...@@ -130,7 +151,7 @@ public class SystemPush {
} }
} }
private void ios(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication, PushType pushType) { private void ios(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) {
// ios推送通道,友盟:1;firebase:2; apns原生:3 // ios推送通道,友盟:1;firebase:2; apns原生:3
if (imApplication.getIosPushChannel() == 1) { if (imApplication.getIosPushChannel() == 1) {
log.info("友盟"); log.info("友盟");
...@@ -161,7 +182,7 @@ public class SystemPush { ...@@ -161,7 +182,7 @@ public class SystemPush {
// apns原生:3 // apns原生:3
log.info("apns原生"); log.info("apns原生");
apnsPush(pushModel, imClientReceiver, imApplication, pushType); apnsPush(pushModel, imClientReceiver, imApplication);
} else { } else {
log.info("没有找到推送类型"); log.info("没有找到推送类型");
} }
...@@ -208,7 +229,7 @@ public class SystemPush { ...@@ -208,7 +229,7 @@ public class SystemPush {
} }
} }
private void apnsPush(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication, PushType pushType) { private void apnsPush(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) {
// 查询apns证书 // 查询apns证书
ImIosApns apns = imIosApnsService.getImIosApnsByAppId(imApplication.getId()); ImIosApns apns = imIosApnsService.getImIosApnsByAppId(imApplication.getId());
Map<String, Object> customProperty = new HashMap<String, Object>(1); Map<String, Object> customProperty = new HashMap<String, Object>(1);
...@@ -236,7 +257,7 @@ public class SystemPush { ...@@ -236,7 +257,7 @@ public class SystemPush {
IosPush.push(certificatePassword, inputStream2, productFlag, deviceToken, alertTitle, alertBody, IosPush.push(certificatePassword, inputStream2, productFlag, deviceToken, alertTitle, alertBody,
contentAvailable, customProperty, badge contentAvailable, customProperty, badge
, DeliveryPriority.IMMEDIATE, pushType, topicBundleId, , DeliveryPriority.IMMEDIATE, PushType.ALERT, topicBundleId,
sound); sound);
} }
......
...@@ -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