|
|
@ -7,17 +7,20 @@ import com.ccsens.recovery.bean.dto.HospitalDto; |
|
|
|
import com.ccsens.recovery.bean.dto.PatientDto; |
|
|
|
import com.ccsens.recovery.bean.message.RecoveryWithActionFeedBack; |
|
|
|
import com.ccsens.recovery.bean.message.RecoveryWithCountdown; |
|
|
|
import com.ccsens.recovery.bean.message.RecoveryWithEndDrill; |
|
|
|
import com.ccsens.recovery.bean.message.RecoveryWithStartDrill; |
|
|
|
import com.ccsens.recovery.bean.po.*; |
|
|
|
import com.ccsens.recovery.bean.vo.PatientVo; |
|
|
|
import com.ccsens.recovery.bean.vo.RecipeVo; |
|
|
|
import com.ccsens.recovery.netty.ChannelManager; |
|
|
|
import com.ccsens.recovery.persist.dao.PatientDao; |
|
|
|
import com.ccsens.recovery.persist.dao.RecDrillDao; |
|
|
|
import com.ccsens.recovery.persist.mapper.*; |
|
|
|
import com.ccsens.recovery.util.Constant; |
|
|
|
import com.ccsens.util.JacksonUtil; |
|
|
|
import com.ccsens.util.bean.message.common.InMessage; |
|
|
|
import com.ccsens.util.bean.message.common.MessageConstant; |
|
|
|
import com.ccsens.util.bean.message.common.MessageRule; |
|
|
|
import com.ccsens.util.RedisUtil; |
|
|
|
import com.ccsens.util.bean.message.common.*; |
|
|
|
import com.ccsens.util.bean.message.server.ChannelStatusMessage; |
|
|
|
import com.ccsens.util.config.RabbitMQConfig; |
|
|
|
import com.ccsens.util.message.SwitchoverProjectUtil; |
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
@ -63,6 +66,8 @@ public class PatientService implements IPatientService{ |
|
|
|
private RecipeProjectDecomposeMapper projectDecomposeMapper; |
|
|
|
@Resource |
|
|
|
private IHospitalService hospitalService; |
|
|
|
@Resource |
|
|
|
private RedisUtil redisUtil; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<PatientVo.Patient> queryPatientByDoctorId(HospitalDto.DoctorId param, Long userId) { |
|
|
@ -142,28 +147,27 @@ public class PatientService implements IPatientService{ |
|
|
|
recRecord.setRemoteDoctorId(param.getRemoteDoctorId()); |
|
|
|
recRecord.setSubTaskId(param.getSubTaskId()); |
|
|
|
recipeRecordMapper.insertSelective(recRecord); |
|
|
|
//发送消息
|
|
|
|
//生成消息内容
|
|
|
|
RecoveryWithStartDrill recoveryWithStartDrill = new RecoveryWithStartDrill(); |
|
|
|
RecoveryWithStartDrill.Data data = new RecoveryWithStartDrill.Data(); |
|
|
|
data.setPatientId(param.getPatientId()); |
|
|
|
data.setRecordId(recRecord.getId()); |
|
|
|
data.setGameId(param.getGameId()); |
|
|
|
data.setProjectId(patient.getProjectId()); |
|
|
|
// data.setTaskDetailId(projectDecompose.getTaskId());
|
|
|
|
data.setStartTime(recRecord.getStartTime()); |
|
|
|
Object o = redisUtil.get(Constant.Redis.RECORD_SCORE + recRecord.getId()); |
|
|
|
data.setScore(o == null ? 0 : (Integer) o); |
|
|
|
data.setSubTaskId(projectDecompose.getTaskId()); |
|
|
|
recoveryWithStartDrill.setData(data); |
|
|
|
|
|
|
|
//用pt的WS发送消息
|
|
|
|
//查询接收者
|
|
|
|
Set<String> userIdSet = new HashSet<>(); |
|
|
|
userIdSet.add(patient.getUserId().toString()); |
|
|
|
// RecoveryRobot recoveryRobot = patientDao.getRobotByPatientId(param.getPatientId());
|
|
|
|
// if(ObjectUtil.isNotNull(recoveryRobot)){
|
|
|
|
// userIdSet.add(recoveryRobot.getUserid().toString());
|
|
|
|
// }
|
|
|
|
//封装成inMessage
|
|
|
|
//消息规则
|
|
|
|
MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User); |
|
|
|
messageRule.setAckRule(MessageRule.AckRule.NONE); |
|
|
|
messageRule.setOfflineDiscard((byte) 1); |
|
|
|
|
|
|
|
//封装成inMessage
|
|
|
|
InMessage inMessage = new InMessage(); |
|
|
|
inMessage.setToDomain(MessageConstant.DomainType.User); |
|
|
|
inMessage.setTos(userIdSet); |
|
|
@ -172,7 +176,11 @@ public class PatientService implements IPatientService{ |
|
|
|
log.info("开始训练消息:{}",inMessage); |
|
|
|
rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME, |
|
|
|
JacksonUtil.beanToJson(inMessage)); |
|
|
|
|
|
|
|
//给机器人发送消息,用新的WS
|
|
|
|
RecoveryRobot recoveryRobot = patientDao.getRobotByPatientId(param.getPatientId()); |
|
|
|
if(ObjectUtil.isNotNull(recoveryRobot)){ |
|
|
|
ChannelManager.sendTo(recoveryRobot.getUserid().toString(), OutMessageSet.newInstance().ackId(null).add(new OutMessage(JacksonUtil.beanToJson(recoveryWithStartDrill)))); |
|
|
|
} |
|
|
|
//返回
|
|
|
|
PatientVo.RecipeRecordId recipeRecordId = new PatientVo.RecipeRecordId(); |
|
|
|
recipeRecordId.setId(recRecord.getId()); |
|
|
@ -180,14 +188,32 @@ public class PatientService implements IPatientService{ |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void endDrill(PatientDto.EndDrill param, Long userId) { |
|
|
|
public void endDrill(PatientDto.EndDrill param, Long userId) throws Exception { |
|
|
|
//查找训练记录
|
|
|
|
RecipeRecord recipeRecord = recipeRecordMapper.selectByPrimaryKey(param.getId()); |
|
|
|
if(ObjectUtil.isNotNull(recipeRecord)){ |
|
|
|
//添加结束时间和分数
|
|
|
|
Object o = redisUtil.get(Constant.Redis.RECORD_SCORE + param.getPatientId()); |
|
|
|
int score = ObjectUtil.isNotNull(o) ? (int) o : 0; |
|
|
|
recipeRecord.setEndTime(System.currentTimeMillis()); |
|
|
|
recipeRecord.setScore(param.getScore()); |
|
|
|
recipeRecord.setScore(score); |
|
|
|
|
|
|
|
recipeRecordMapper.updateByPrimaryKeySelective(recipeRecord); |
|
|
|
//TODO 发送结束消息,给患者和机器人发送消息
|
|
|
|
RecoveryWithEndDrill.Data data = new RecoveryWithEndDrill.Data(); |
|
|
|
data.setRecordId(param.getId()); |
|
|
|
data.setScore(score); |
|
|
|
RecoveryWithEndDrill recoveryWithEndDrill = new RecoveryWithEndDrill(data); |
|
|
|
//查找患者信息
|
|
|
|
Patient patient = patientDao.selectByPrimaryKey(param.getId()); |
|
|
|
if(ObjectUtil.isNotNull(patient)) { |
|
|
|
ChannelManager.sendTo(patient.getUserId().toString(), OutMessageSet.newInstance().ackId(null).add(new OutMessage(JacksonUtil.beanToJson(recoveryWithEndDrill)))); |
|
|
|
} |
|
|
|
//查找患者关联的机器人信息
|
|
|
|
RecoveryRobot recoveryRobot = patientDao.getRobotByPatientId(patient.getId()); |
|
|
|
if(ObjectUtil.isNotNull(recipeRecord)){ |
|
|
|
ChannelManager.sendTo(recoveryRobot.getUserid().toString(), OutMessageSet.newInstance().ackId(null).add(new OutMessage(JacksonUtil.beanToJson(recoveryWithEndDrill)))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -215,7 +241,7 @@ public class PatientService implements IPatientService{ |
|
|
|
RecoveryWithActionFeedBack actionFeedBack = new RecoveryWithActionFeedBack(); |
|
|
|
RecoveryWithActionFeedBack.Data data = new RecoveryWithActionFeedBack.Data(); |
|
|
|
data.setRecordId(param.getRecordId()); |
|
|
|
data.setResult(param.isResult()); |
|
|
|
data.setResult(param.isResult() ? 1 : 0); |
|
|
|
actionFeedBack.setData(data); |
|
|
|
|
|
|
|
InMessage inMessage = new InMessage(); |
|
|
@ -305,27 +331,39 @@ public class PatientService implements IPatientService{ |
|
|
|
|
|
|
|
@Override |
|
|
|
public void countdown(PatientDto.PatientId param, Long userId) throws Exception { |
|
|
|
Set<String> userIdSet = new HashSet<>(); |
|
|
|
//用新ws发送消息
|
|
|
|
String patientUserId = null; |
|
|
|
//查询患者信息
|
|
|
|
Patient patient = patientDao.selectByPrimaryKey(param.getId()); |
|
|
|
if(ObjectUtil.isNotNull(patient)){ |
|
|
|
userIdSet.add(patient.getUserId().toString()); |
|
|
|
|
|
|
|
patientUserId = patient.getUserId().toString(); |
|
|
|
} |
|
|
|
//消息规则
|
|
|
|
MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User); |
|
|
|
messageRule.setAckRule(MessageRule.AckRule.NONE); |
|
|
|
messageRule.setOfflineDiscard((byte) 1); |
|
|
|
//生成消息
|
|
|
|
RecoveryWithCountdown recoveryWithCountdown = new RecoveryWithCountdown(); |
|
|
|
log.info("倒计时结束消息:{}",recoveryWithCountdown); |
|
|
|
ChannelManager.sendTo(patientUserId, OutMessageSet.newInstance().ackId(null).add(new OutMessage(JacksonUtil.beanToJson(recoveryWithCountdown)))); |
|
|
|
|
|
|
|
InMessage inMessage = new InMessage(); |
|
|
|
inMessage.setToDomain(MessageConstant.DomainType.User); |
|
|
|
inMessage.setTos(userIdSet); |
|
|
|
inMessage.setData(JacksonUtil.beanToJson(recoveryWithCountdown)); |
|
|
|
inMessage.setRule(messageRule); |
|
|
|
log.info("倒计时结束:{}",inMessage); |
|
|
|
rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME, |
|
|
|
JacksonUtil.beanToJson(inMessage)); |
|
|
|
|
|
|
|
// Set<String> userIdSet = new HashSet<>();
|
|
|
|
// //查询患者信息
|
|
|
|
// Patient patient = patientDao.selectByPrimaryKey(param.getId());
|
|
|
|
// if(ObjectUtil.isNotNull(patient)){
|
|
|
|
// userIdSet.add(patient.getUserId().toString());
|
|
|
|
// }
|
|
|
|
// //消息规则
|
|
|
|
// MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User);
|
|
|
|
// messageRule.setAckRule(MessageRule.AckRule.NONE);
|
|
|
|
// messageRule.setOfflineDiscard((byte) 1);
|
|
|
|
// //生成消息
|
|
|
|
// RecoveryWithCountdown recoveryWithCountdown = new RecoveryWithCountdown();
|
|
|
|
//
|
|
|
|
// InMessage inMessage = new InMessage();
|
|
|
|
// inMessage.setToDomain(MessageConstant.DomainType.User);
|
|
|
|
// inMessage.setTos(userIdSet);
|
|
|
|
// inMessage.setData(JacksonUtil.beanToJson(recoveryWithCountdown));
|
|
|
|
// inMessage.setRule(messageRule);
|
|
|
|
// log.info("倒计时结束:{}",inMessage);
|
|
|
|
// rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME,
|
|
|
|
// JacksonUtil.beanToJson(inMessage));
|
|
|
|
} |
|
|
|
} |
|
|
|