WsPublishUtils.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.coffee.bus.utils;
  2. import cn.hutool.json.JSONObject;
  3. import cn.hutool.json.JSONUtil;
  4. import com.coffee.bus.enums.PatientAlarmEnum;
  5. import com.coffee.bus.service.LocalBusPatientService;
  6. import com.coffee.bus.service.dto.MonitorStatusStatsCountResult;
  7. import com.coffee.bus.service.dto.PatientMonitorResult;
  8. import com.coffee.common.config.websocket.TopicMessage;
  9. import com.coffee.common.config.websocket.WebSocketConstant;
  10. import com.coffee.common.util.RedissonUtil;
  11. import lombok.AllArgsConstructor;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.scheduling.annotation.Async;
  14. import org.springframework.stereotype.Component;
  15. import org.springframework.util.Assert;
  16. import java.io.Serializable;
  17. /**
  18. * @author lifang
  19. * @version 1.0.0
  20. * @ClassName WsPushUtils.java
  21. * @Description ws发布消息工具类
  22. * @createTime 2022年05月07日 11:34:00
  23. */
  24. @Component
  25. @AllArgsConstructor
  26. @Slf4j
  27. public class WsPublishUtils implements Serializable{
  28. private final LocalBusPatientService patientService;
  29. private final RedissonUtil redissonUtil;
  30. private void publish(String topic,TopicMessage msg){
  31. redissonUtil.getTopic(topic).publishAsync(msg);
  32. }
  33. /**
  34. * 描述: 推送设备输注消息
  35. * @author lifang
  36. * @date 2022/5/13 9:39
  37. * @param patientCode
  38. * @param tenantId
  39. * @return void
  40. */
  41. @Async
  42. public void publishPatientMonitor(String patientCode,String tenantId){
  43. Assert.hasText(tenantId,"医院id不能为空");
  44. log.info("推送病号数据【{}】", JSONUtil.toJsonStr(patientCode));
  45. PatientMonitorResult message = patientService.lookMonitorByPatientCode(patientCode, tenantId);
  46. if (log.isDebugEnabled()) {
  47. log.debug("推送病号当前状态,【{}】",JSONUtil.toJsonStr(message));
  48. }
  49. if(message!=null){
  50. message.handleWarn();
  51. this.publish(WebSocketConstant.getPatientMonitor(null, patientCode, tenantId).getTopic(),
  52. TopicMessage.of(message,patientCode)
  53. );
  54. }
  55. }
  56. /**
  57. * 描述: 推送医院设备状态统计数量
  58. * @author lifang
  59. * @date 2022/5/13 9:39
  60. * @param
  61. * @return void
  62. */
  63. @Async
  64. public void publishMonitorStateCount(String tenantId){
  65. Assert.hasText(tenantId,"医院id不能为空");
  66. MonitorStatusStatsCountResult message = patientService.statusStats(tenantId);
  67. this.publish(WebSocketConstant.getMonitorStateCount(tenantId).getTopic(),
  68. TopicMessage.of(message,tenantId)
  69. );
  70. }
  71. /**
  72. * 描述: 新增病人订阅
  73. * @author lifang
  74. * @date 2022/5/13 9:39
  75. * @param
  76. * @return void
  77. */
  78. @Async
  79. public void publishPatientAdd(String patientCode,String tenantId){
  80. Assert.hasText(tenantId,"医院id不能为空");
  81. JSONObject message = new JSONObject().putOpt("patientCode", patientCode);
  82. this.publish(WebSocketConstant.getPatientAdd(tenantId).getTopic(),
  83. TopicMessage.of(message,tenantId));
  84. }
  85. /**
  86. * 描述: 推送医院临床设备重复数量统计
  87. * @author lifang
  88. * @date 2022/5/13 9:39
  89. * @param
  90. * @return void
  91. */
  92. @Async
  93. public void publishDeviceRepeat(String tenantId){
  94. Assert.hasText(tenantId,"医院id不能为空");
  95. JSONObject message = new JSONObject().putOpt("count", patientService.patientAlarmCount(tenantId,PatientAlarmEnum.DEVICE_REPEAT));
  96. this.publish(WebSocketConstant.getDeviceRepeat(tenantId).getTopic(),
  97. TopicMessage.of(message,tenantId)
  98. );
  99. }
  100. /**
  101. * 描述: 推送临床设备无绑定数量统计
  102. * @author lifang
  103. * @date 2022/5/13 9:39
  104. * @param
  105. * @return void
  106. */
  107. @Async
  108. public void publishDeviceNone(String tenantId){
  109. Assert.hasText(tenantId,"医院id不能为空");
  110. JSONObject message = new JSONObject().putOpt("count",patientService.patientAlarmCount(tenantId,PatientAlarmEnum.DEVICE_NONE));
  111. this.publish(WebSocketConstant.getDeviceNone(tenantId).getTopic(),
  112. TopicMessage.of(message,tenantId)
  113. );
  114. }
  115. /**
  116. * 描述: 推送临床设备总数量统计
  117. * @author lifang
  118. * @date 2022/5/13 9:39
  119. * @param
  120. * @return void
  121. */
  122. @Async
  123. public void publishMonitorTotalCount(String tenantId){
  124. Assert.hasText(tenantId,"医院id不能为空");
  125. JSONObject message = new JSONObject().putOpt("count",
  126. patientService.monitorTotalCount(tenantId));
  127. this.publish(WebSocketConstant.getMonitorTotalCount(tenantId).getTopic(),
  128. TopicMessage.of(message,tenantId)
  129. );
  130. }
  131. }