|
|
@@ -2,6 +2,7 @@ package com.nb.app.doctor.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
@@ -9,16 +10,25 @@ import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
|
import com.nb.app.doctor.api.entity.AppDoctorUserEntity;
|
|
|
import com.nb.app.doctor.api.feign.IAppDoctorUserClient;
|
|
|
import com.nb.app.doctor.api.feign.result.AppDoctorUserResult;
|
|
|
-import com.nb.app.doctor.controller.UserController;
|
|
|
import com.nb.app.doctor.entity.AppUserConsultConfigEntity;
|
|
|
-import com.nb.app.doctor.entity.AppUserReplyEntity;
|
|
|
import com.nb.app.doctor.mapper.AppDoctorUserMapper;
|
|
|
+import com.nb.app.msg.enums.MsgEnum;
|
|
|
import com.nb.auth.utils.SecurityUtil;
|
|
|
import com.nb.common.crud.BaseService;
|
|
|
import com.nb.core.enums.StatusEnum;
|
|
|
import com.nb.core.exception.CustomException;
|
|
|
+import com.nb.im.entity.ImMsgEntity;
|
|
|
+import com.nb.im.entity.ImRoomEntity;
|
|
|
+import com.nb.im.enums.ImMsgType;
|
|
|
+import com.nb.im.enums.ImStatusEnum;
|
|
|
+import com.nb.im.enums.SponsorEnum;
|
|
|
+import com.nb.im.event.ImMsgEvent;
|
|
|
+import com.nb.im.service.LocalImRoomService;
|
|
|
+import com.nb.im.utils.ImUtils;
|
|
|
+import com.nb.im.ws.PubMsgInfo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -42,8 +52,11 @@ public class LocalAppDoctorUserService extends BaseService<AppDoctorUserMapper,
|
|
|
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
- private LocalUserReplyService replyService;
|
|
|
+ private LocalImRoomService roomService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private ImUtils imUtils;
|
|
|
@Override
|
|
|
public void validateBeforeSave(AppDoctorUserEntity entity) {
|
|
|
if(StrUtil.isEmpty(entity.getUsername())){
|
|
|
@@ -80,7 +93,6 @@ public class LocalAppDoctorUserService extends BaseService<AppDoctorUserMapper,
|
|
|
@Override
|
|
|
public void postSave(AppDoctorUserEntity entity) {
|
|
|
consultConfigService.save( AppUserConsultConfigEntity.createDefault(entity.getId()));
|
|
|
- replyService.save(AppUserReplyEntity.createDefault(entity.getId()));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -122,14 +134,11 @@ public class LocalAppDoctorUserService extends BaseService<AppDoctorUserMapper,
|
|
|
boolean result = executeBatch(sources, DEFAULT_BATCH_SIZE, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
|
|
|
if(result){
|
|
|
ArrayList<AppUserConsultConfigEntity> consultConfigs = new ArrayList<>();
|
|
|
- ArrayList<AppUserReplyEntity> userReplies = new ArrayList<>();
|
|
|
|
|
|
sources.forEach(userEntity->{
|
|
|
consultConfigs.add(AppUserConsultConfigEntity.createDefault(userEntity.getId()));
|
|
|
- userReplies.add(AppUserReplyEntity.createDefault(userEntity.getId()));
|
|
|
});
|
|
|
consultConfigService.saveBatch(consultConfigs);
|
|
|
- replyService.saveBatch(userReplies);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
@@ -176,4 +185,61 @@ public class LocalAppDoctorUserService extends BaseService<AppDoctorUserMapper,
|
|
|
AppDoctorUserEntity user = this.getById(id);
|
|
|
return user==null?null:BeanUtil.copyProperties(this.getById(id),AppDoctorUserResult.class);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @EventListener
|
|
|
+ public void assistListener(ImMsgEvent event){
|
|
|
+ //判断当前发送人是否为患者,若为患者发送,则判断是否存在自动回复
|
|
|
+ ImMsgEntity entity = event.getMsg();
|
|
|
+ String payload=null;
|
|
|
+ if(!SponsorEnum.assist.equals(entity.getSponsor())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //判断是否处于勿扰模式
|
|
|
+ String imRoomId = entity.getImRoomId();
|
|
|
+ ImRoomEntity room = roomService.getById(imRoomId);
|
|
|
+ if(!ImStatusEnum.SUCCESS.equals(room.getStatus())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ AppUserConsultConfigEntity consultConfig = consultConfigService.getOne(new QueryWrapper<AppUserConsultConfigEntity>().lambda()
|
|
|
+ .eq(AppUserConsultConfigEntity::getUserId, room.getDoctorId())
|
|
|
+ .last("limit 1"));
|
|
|
+ boolean disturb=false;
|
|
|
+ if(Boolean.TRUE.equals(consultConfig.getNoDisturb())){
|
|
|
+ //开启勿扰模式,判断当前时间是否存在于勿扰时间区间
|
|
|
+ List<Integer> noDisturbTime = consultConfig.getNoDisturbTime();
|
|
|
+ int currentHour = DateUtil.hour(new Date(), true);
|
|
|
+ if(CollectionUtil.size(noDisturbTime)==2){
|
|
|
+ //是否打扰到了医生
|
|
|
+ Integer startTime = noDisturbTime.get(0);
|
|
|
+ Integer endTime = noDisturbTime.get(1);
|
|
|
+ if(startTime<endTime){
|
|
|
+ disturb=startTime<=currentHour&¤tHour<=endTime;
|
|
|
+ }else {
|
|
|
+ disturb=startTime<=currentHour||currentHour<=endTime;
|
|
|
+ }
|
|
|
+ if(disturb){
|
|
|
+ payload=StrUtil.isNotBlank(consultConfig.getNoDisturbReply())?consultConfig.getNoDisturbReply():String.format("您好,当前时间我可能收不到消息,请在 %s - %s 期间向我发起咨询。",endTime+":00",startTime+":00");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!disturb&&MsgEnum.CONSUL.equals(entity.getOperationType())){
|
|
|
+ payload=StrUtil.isNotBlank(consultConfig.getConsultReply())?consultConfig.getConsultReply():"您好,我已经收到您的咨询,请稍等";
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(payload)){
|
|
|
+ PubMsgInfo pubMsgInfo = PubMsgInfo
|
|
|
+ .builder()
|
|
|
+ .roomId(entity.getImRoomId())
|
|
|
+ .payload(payload)
|
|
|
+ .senderType(entity.getSponsor())
|
|
|
+ .senderId(entity.getSenderId())
|
|
|
+ .senderNickname(entity.getSenderNickname())
|
|
|
+ .senderAvatar(entity.getSenderAvatar())
|
|
|
+ .msgType(ImMsgType.txt)
|
|
|
+ .build();
|
|
|
+ imUtils.send(entity.getImRoomId(),pubMsgInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|