lifang 3 miesięcy temu
rodzic
commit
5c39261955

+ 1 - 2
tr-modules/tr-module-mobile/src/main/java/cn/tr/module/mobile/config/ServerEventCallbackHandler.java

@@ -2,6 +2,7 @@ package cn.tr.module.mobile.config;
 
 import cn.tr.module.mobile.dto.ImLoginSuccessDTO;
 import cn.tr.module.mobile.dto.MsgDTO;
+import com.sun.org.apache.xpath.internal.operations.Bool;
 import lombok.extern.slf4j.Slf4j;
 import net.x52im.mobileimsdk.server.protocal.Protocal;
 
@@ -107,6 +108,4 @@ public class ServerEventCallbackHandler {
         log.debug("用户登录成功: userId={}, clinicId={}",
                 loginInfo.getUserId(), loginInfo.getClinicId());
     };
-
-
 }

+ 11 - 0
tr-modules/tr-module-mobile/src/main/java/cn/tr/module/mobile/dto/MsgDTO.java

@@ -1,5 +1,7 @@
 package cn.tr.module.mobile.dto;
 
+import cn.tr.module.mobile.enums.MsgContentType;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import lombok.Data;
 
 @Data
@@ -28,4 +30,13 @@ public class MsgDTO {
     private String toUserId;
 
     private String tenantId;
+
+    public static MsgDTO onlineMsg(String clinicId,String fromUserId){
+        MsgDTO msgDTO = new MsgDTO();
+        msgDTO.setClinicId(clinicId);
+        msgDTO.setType(MsgContentType.DOCTOR_IN);
+        msgDTO.setFromUserId(fromUserId);
+        msgDTO.setMsgId(IdWorker.getIdStr());
+        return msgDTO;
+    }
 }

+ 35 - 2
tr-modules/tr-module-mobile/src/main/java/cn/tr/module/mobile/service/impl/ImMsgReceivedServiceImpl.java

@@ -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;
+    }
 }