|
|
@@ -11,12 +11,16 @@ import cn.tr.module.mobile.enums.MsgContentType;
|
|
|
import cn.tr.module.mobile.po.ImGroupUserPO;
|
|
|
import cn.tr.module.mobile.repository.ImGroupUserRepository;
|
|
|
import cn.tr.module.mobile.utils.UserUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import net.x52im.mobileimsdk.server.network.MBObserver;
|
|
|
import net.x52im.mobileimsdk.server.processor.OnlineProcessor;
|
|
|
import net.x52im.mobileimsdk.server.protocal.Protocal;
|
|
|
import net.x52im.mobileimsdk.server.protocal.ProtocalFactory;
|
|
|
import net.x52im.mobileimsdk.server.utils.LocalSendHelper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cache.annotation.CacheEvict;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
@@ -34,6 +38,7 @@ import javax.annotation.PostConstruct;
|
|
|
* @date 2025/08/20 10:14
|
|
|
**/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ImMsgReceivedServiceImpl implements IImMsgReceivedService {
|
|
|
@Autowired
|
|
|
private ImMsgReceivedRepository baseRepository;
|
|
|
@@ -41,6 +46,9 @@ public class ImMsgReceivedServiceImpl implements IImMsgReceivedService {
|
|
|
@Autowired
|
|
|
private ImGroupUserRepository groupUserRepository;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private ImMsgReceivedServiceImpl self;
|
|
|
@PostConstruct
|
|
|
public void init(){
|
|
|
ServerEventCallbackHandler.onTransferMessage4C2S= msgDTO -> {
|
|
|
@@ -48,8 +56,10 @@ public class ImMsgReceivedServiceImpl implements IImMsgReceivedService {
|
|
|
if(p!=null){
|
|
|
return;
|
|
|
}
|
|
|
- if(MsgContentType.DOCTOR_IN.equals(msgDTO.getType())||MsgContentType.DOCTOR_OUT.equals(msgDTO.getType())){
|
|
|
-
|
|
|
+ if(MsgContentType.DOCTOR_IN.equals(msgDTO.getType())){
|
|
|
+ self.doctorOnLine(msgDTO.getClinicId());
|
|
|
+ }else if(MsgContentType.DOCTOR_OUT.equals(msgDTO.getType())){
|
|
|
+ self.doctorOffLine(msgDTO.getClinicId());
|
|
|
}else {
|
|
|
ImMsgReceivedPO receivedPO = new ImMsgReceivedPO();
|
|
|
receivedPO.setMsgId(msgDTO.getMsgId());
|
|
|
@@ -79,6 +89,14 @@ public class ImMsgReceivedServiceImpl implements IImMsgReceivedService {
|
|
|
TenantContextHolder.setIgnore(Boolean.TRUE);
|
|
|
groupUserRepository.readAllMsg(loginInfo.getClinicId(), loginInfo.getUserId());
|
|
|
TenantContextHolder.setIgnore(Boolean.FALSE);
|
|
|
+ //判断医生是否在线
|
|
|
+ if (self.doctorIsOnline(loginInfo.getClinicId())) {
|
|
|
+ try{
|
|
|
+ sendMsg(MsgDTO.onlineMsg(loginInfo.getClinicId(),loginInfo.getUserId()));
|
|
|
+ }catch (Exception e){
|
|
|
+ log.warn("发送消息失败:{%s}",e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
ServerEventCallbackHandler.onGetGroupUserIds=clinicId->baseRepository.selectAllUserId(clinicId);
|
|
|
@@ -157,4 +175,19 @@ public class ImMsgReceivedServiceImpl implements IImMsgReceivedService {
|
|
|
.filter(count->count>0)
|
|
|
.count();
|
|
|
}
|
|
|
+
|
|
|
+ @Cacheable(value = "global:sys::doctorIsOnline#86400",key = "'groupId:' + #groupId")
|
|
|
+ public Boolean doctorIsOnline(String groupId){
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Cacheable(value = "global:sys::doctorIsOnline#86400",key = "'groupId:' + #groupId")
|
|
|
+ public Boolean doctorOnLine(String groupId){
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @CacheEvict(value = "global:sys::doctorIsOnline#86400",key = "'groupId:' + #groupId")
|
|
|
+ public Boolean doctorOffLine(String groupId){
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
}
|