|
|
@ -1,26 +1,41 @@ |
|
|
|
package com.ccsens.carbasics.mq; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.carbasics.bean.dto.ButtonDto; |
|
|
|
import com.ccsens.carbasics.bean.dto.PatientDto; |
|
|
|
import com.ccsens.carbasics.bean.po.EquipmentInform; |
|
|
|
import com.ccsens.carbasics.bean.po.EquipmentStatus; |
|
|
|
import com.ccsens.carbasics.bean.po.FirstAid; |
|
|
|
import com.ccsens.carbasics.bean.vo.EquipmentVo; |
|
|
|
import com.ccsens.carbasics.bean.vo.message.ButtonStartVo; |
|
|
|
import com.ccsens.carbasics.bean.vo.message.UpdateStatusVo; |
|
|
|
import com.ccsens.carbasics.persist.dao.*; |
|
|
|
import com.ccsens.carbasics.service.IFirstAidService; |
|
|
|
import com.ccsens.carbasics.util.Constant; |
|
|
|
import com.ccsens.carbasics.util.DefaultCodeError; |
|
|
|
import com.ccsens.util.JacksonUtil; |
|
|
|
import com.ccsens.util.RedisUtil; |
|
|
|
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.config.RabbitMQConfig; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.amqp.core.AmqpTemplate; |
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
/** |
|
|
|
* 暴风眼接收qcp一键通知相关消息 |
|
|
@ -47,6 +62,10 @@ public class QcpButtonReceive { |
|
|
|
private EquipmentInformDao equipmentInformDao; |
|
|
|
@Resource |
|
|
|
private FirstAidDao firstAidDao; |
|
|
|
@Resource |
|
|
|
private AmqpTemplate amqpTemplate; |
|
|
|
@Resource |
|
|
|
private OrganizationMemberDao organizationMemberDao; |
|
|
|
|
|
|
|
@RabbitHandler |
|
|
|
public void process(String messageJson) throws Exception { |
|
|
@ -71,13 +90,14 @@ public class QcpButtonReceive { |
|
|
|
* 身份证识别处理 |
|
|
|
* @param param 参数 |
|
|
|
*/ |
|
|
|
public void idCardDiscern(ButtonDto.IdCardInfoMq param) { |
|
|
|
public void idCardDiscern(ButtonDto.IdCardInfoMq param) throws Exception { |
|
|
|
log.info("暴风眼身份证识别接收到的参数{}",param); |
|
|
|
String idCard = (String) redisUtil.get(param.getName() + param.getIdcard()); |
|
|
|
if (StrUtil.isNotBlank(idCard)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
redisUtil.set(param.getName()+param.getIdcard(),param.getIdcard(),300); |
|
|
|
|
|
|
|
//根据设备userId查询项目id
|
|
|
|
Long projectId = qcpDao.queryProjectByUserId(param.getUserId()); |
|
|
|
log.info("查询到的项目id:{}",projectId); |
|
|
@ -89,8 +109,20 @@ public class QcpButtonReceive { |
|
|
|
PatientDto.SavePatient savePatient = new PatientDto.SavePatient(); |
|
|
|
BeanUtil.copyProperties(param,savePatient); |
|
|
|
savePatient.setGender(param.getSex()); |
|
|
|
firstAidService.getFirstAid(savePatient,param.getUserId(), (byte) 5,organizationId); |
|
|
|
FirstAid firstAid = firstAidService.getFirstAid(savePatient, param.getUserId(), (byte) 5, organizationId); |
|
|
|
//查询设备信息,并保存状态
|
|
|
|
EquipmentVo.ButtonInfo buttonInfo = qcpDao.queryEquipmentInfoByUserId(param.getUserId()); |
|
|
|
if (ObjectUtil.isNotNull(buttonInfo)) { |
|
|
|
EquipmentStatus equipmentStatus = new EquipmentStatus(); |
|
|
|
equipmentStatus.setId(snowflake.nextId()); |
|
|
|
equipmentStatus.setEquipmentId(buttonInfo.getId()); |
|
|
|
equipmentStatus.setEquipmentStatus((byte) 0); |
|
|
|
equipmentStatus.setFirstAidId(firstAid.getId()); |
|
|
|
equipmentStatus.setTime(System.currentTimeMillis()); |
|
|
|
} |
|
|
|
sendDoctor(firstAid.getId(), firstAid.getName(), firstAid.getHospitalId()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@ -99,14 +131,63 @@ public class QcpButtonReceive { |
|
|
|
* 一键启动处理 |
|
|
|
* @param param 参数 |
|
|
|
*/ |
|
|
|
public void buttonStart(ButtonDto.ButtonStartMq param) { |
|
|
|
public void buttonStart(ButtonDto.ButtonStartMq param) throws Exception { |
|
|
|
log.info("暴风眼一键启动接收到的参数{}",param); |
|
|
|
Long projectId = qcpDao.queryProjectByUserId(param.getUserId()); |
|
|
|
Long organizationId = organizationProjectDao.queryByProjectId(projectId); |
|
|
|
FirstAid firstAid = firstAidDao.queryByOidAndIdcard(organizationId,param.getIdcard()); |
|
|
|
if (ObjectUtil.isNotNull(firstAid)) { |
|
|
|
EquipmentStatus equipmentStatus = new EquipmentStatus(); |
|
|
|
equipmentStatus.setId(snowflake.nextId()); |
|
|
|
//查询设备信息
|
|
|
|
EquipmentVo.ButtonInfo buttonInfo = qcpDao.queryEquipmentInfoByUserId(param.getUserId()); |
|
|
|
if (ObjectUtil.isNotNull(buttonInfo)) { |
|
|
|
Long projectId = qcpDao.queryProjectByUserId(param.getUserId()); |
|
|
|
Long organizationId = organizationProjectDao.queryByProjectId(projectId); |
|
|
|
FirstAid firstAid = firstAidDao.queryByOidAndIdcard(organizationId,param.getIdcard()); |
|
|
|
if (ObjectUtil.isNotNull(firstAid)) { |
|
|
|
Long firstAidId = firstAid.getId(); |
|
|
|
EquipmentStatus equipmentStatus = equipmentStatusDao.queryByEidAndFid(buttonInfo.getId(), firstAidId); |
|
|
|
if (ObjectUtil.isNotNull(equipmentStatus)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
EquipmentStatus triageStatus = new EquipmentStatus(); |
|
|
|
triageStatus.setId(snowflake.nextId()); |
|
|
|
triageStatus.setFirstAidId(firstAidId); |
|
|
|
triageStatus.setEquipmentId(buttonInfo.getId()); |
|
|
|
triageStatus.setEquipmentStatus(Constant.Equipment.RUNNING_STATUS); |
|
|
|
triageStatus.setTime(param.getTime()); |
|
|
|
equipmentStatusDao.insertSelective(equipmentStatus); |
|
|
|
Long hospitalId = buttonInfo.getHospitalId(); |
|
|
|
String name = firstAid.getName(); |
|
|
|
Long time = param.getTime(); |
|
|
|
sendEquipmentStart(firstAidId, hospitalId, name, time); |
|
|
|
sendDoctor(firstAidId, firstAid.getName(), firstAid.getHospitalId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void sendEquipmentStart(Long firstAidId, Long hospitalId, String name, Long time) throws JsonProcessingException { |
|
|
|
//查询医院其他设备
|
|
|
|
List<EquipmentVo.ButtonInfo> buttonInfoList = qcpDao.queryOtherEquipment(hospitalId); |
|
|
|
log.info("查询医院其他设备:{}",buttonInfoList); |
|
|
|
if (CollectionUtil.isNotEmpty(buttonInfoList)) { |
|
|
|
for (EquipmentVo.ButtonInfo info : buttonInfoList) { |
|
|
|
//查询需要发送的消息内容
|
|
|
|
EquipmentInform equipmentInform = equipmentInformDao.queryByType(info.getType()); |
|
|
|
HashSet<String> userSet = new HashSet<>(); |
|
|
|
userSet.add(info.getUserId().toString()); |
|
|
|
ButtonStartVo.Data data = new ButtonStartVo.Data(); |
|
|
|
data.setName(name); |
|
|
|
data.setContent(name + equipmentInform.getContent()); |
|
|
|
data.setFirstAidId(firstAidId); |
|
|
|
data.setTotalCountdown(equipmentInform.getTotalCountdown()); |
|
|
|
data.setRealCountdown(System.currentTimeMillis() - time); |
|
|
|
data.setTime(time); |
|
|
|
ButtonStartVo buttonStartVo = new ButtonStartVo(); |
|
|
|
buttonStartVo.setData(data); |
|
|
|
InMessage inMessage = new InMessage(); |
|
|
|
inMessage.setTos(userSet); |
|
|
|
inMessage.setData(JacksonUtil.beanToJson(buttonStartVo)); |
|
|
|
inMessage.setToDomain(MessageConstant.DomainType.User); |
|
|
|
log.info("一键启动调用消息系统传参{}",inMessage); |
|
|
|
amqpTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME,JacksonUtil.beanToJson(inMessage)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -115,8 +196,96 @@ public class QcpButtonReceive { |
|
|
|
* 修改状态处理 |
|
|
|
* @param param 参数 |
|
|
|
*/ |
|
|
|
public void updateStatus(ButtonDto.UpDateStatusMq param) { |
|
|
|
public void updateStatus(ButtonDto.UpDateStatusMq param) throws Exception { |
|
|
|
log.info("暴风眼修改状态接收到的参数{}",param); |
|
|
|
EquipmentVo.ButtonInfo buttonInfo = qcpDao.queryEquipmentInfoByUserId(param.getUserId()); |
|
|
|
if (ObjectUtil.isNull(buttonInfo)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
FirstAid firstAid = firstAidDao.selectByPrimaryKey(param.getFirstAidId()); |
|
|
|
if (firstAid == null) { |
|
|
|
log.info("{}未找到急救", param.getFirstAidId()); |
|
|
|
return; |
|
|
|
} |
|
|
|
EquipmentStatus equipmentStatus = equipmentStatusDao.queryByEidAndFidAndStatus(buttonInfo.getId(),param.getFirstAidId(),param.getStatus()); |
|
|
|
if (ObjectUtil.isNotNull(equipmentStatus)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if (1 == buttonInfo.getType()) { |
|
|
|
if (param.getStatus() ==1 || param.getStatus() == 2) { |
|
|
|
//查询分诊台的设备id
|
|
|
|
List<EquipmentVo.ButtonInfo> triageTableList = qcpDao.queryTriageTable(buttonInfo.getHospitalId()); |
|
|
|
log.info("查询分诊台的设备id列表:{}",triageTableList); |
|
|
|
if (CollectionUtil.isNotEmpty(triageTableList)) { |
|
|
|
HashSet<String> userSet = new HashSet<>(); |
|
|
|
for (EquipmentVo.ButtonInfo triageTable : triageTableList) { |
|
|
|
userSet.add(triageTable.getUserId().toString()); |
|
|
|
//保存分诊台关闭的信息
|
|
|
|
EquipmentStatus triageTableStatus = new EquipmentStatus(); |
|
|
|
triageTableStatus.setId(snowflake.nextId()); |
|
|
|
triageTableStatus.setTime(System.currentTimeMillis()); |
|
|
|
triageTableStatus.setEquipmentStatus((byte) 2); |
|
|
|
triageTableStatus.setEquipmentId(triageTable.getId()); |
|
|
|
triageTableStatus.setFirstAidId(param.getFirstAidId()); |
|
|
|
equipmentStatusDao.insertSelective(triageTableStatus); |
|
|
|
} |
|
|
|
UpdateStatusVo.Data data = new UpdateStatusVo.Data(System.currentTimeMillis(), (byte) 2,param.getFirstAidId()); |
|
|
|
UpdateStatusVo updateStatusVo = new UpdateStatusVo(); |
|
|
|
updateStatusVo.setData(data); |
|
|
|
InMessage inMessage = new InMessage(); |
|
|
|
inMessage.setTos(userSet); |
|
|
|
inMessage.setData(JacksonUtil.beanToJson(updateStatusVo)); |
|
|
|
inMessage.setToDomain(MessageConstant.DomainType.User); |
|
|
|
log.info("更改状态调用消息系统传参{}",inMessage); |
|
|
|
amqpTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME,JacksonUtil.beanToJson(inMessage)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
//保存设备更改状态的信息
|
|
|
|
EquipmentStatus saveEquipmentStatus = new EquipmentStatus(); |
|
|
|
saveEquipmentStatus.setId(snowflake.nextId()); |
|
|
|
saveEquipmentStatus.setTime(System.currentTimeMillis()); |
|
|
|
saveEquipmentStatus.setEquipmentStatus(param.getStatus()); |
|
|
|
saveEquipmentStatus.setEquipmentId(buttonInfo.getId()); |
|
|
|
saveEquipmentStatus.setFirstAidId(param.getFirstAidId()); |
|
|
|
equipmentStatusDao.insertSelective(saveEquipmentStatus); |
|
|
|
|
|
|
|
sendDoctor(param.getFirstAidId(), firstAid.getName(), firstAid.getHospitalId()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 通知医院的所有成员病例进度 |
|
|
|
* @param firstAidId 病例 |
|
|
|
*/ |
|
|
|
private void sendDoctor(Long firstAidId, String firstAidName, Long organizationId) throws Exception { |
|
|
|
// 查询医院所有成员
|
|
|
|
List<Long> userIds = organizationMemberDao.queryUserIdsByOrganizationId(organizationId); |
|
|
|
// 查询当前未完成的状态
|
|
|
|
EquipmentVo.Unfinished inform = equipmentStatusDao.getUnfinished(firstAidId); |
|
|
|
log.info("未完成的设备:{}", inform); |
|
|
|
if (inform == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
Set<String> userIdSet = new HashSet<>(); |
|
|
|
userIds.forEach(userId -> userIdSet.add(userId + "")); |
|
|
|
// 封装对象
|
|
|
|
ButtonStartVo.Data data = new ButtonStartVo.Data(); |
|
|
|
data.setName(firstAidName); |
|
|
|
data.setContent(inform.getEquipmentStatus() == Constant.Equipment.ID_CARD_IDENTIFY_STATUS ? firstAidName : firstAidName + inform.getContent()); |
|
|
|
data.setFirstAidId(firstAidId); |
|
|
|
data.setTotalCountdown(inform.getTotalCountdown()); |
|
|
|
data.setRealCountdown(System.currentTimeMillis() - inform.getTime()); |
|
|
|
data.setTime(inform.getTime()); |
|
|
|
ButtonStartVo buttonStartVo = new ButtonStartVo(); |
|
|
|
buttonStartVo.setData(data); |
|
|
|
MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User); |
|
|
|
messageRule.setAckRule(MessageRule.AckRule.NONE); |
|
|
|
messageRule.setOfflineDiscard((byte) 1); |
|
|
|
InMessage inMessage = InMessage.newToUserMessage(null, userIdSet, null, messageRule, ""); |
|
|
|
log.info("发送消息:{}", inMessage); |
|
|
|
//发送消息
|
|
|
|
amqpTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME,JacksonUtil.beanToJson(inMessage)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|