package com.coffee.bus.utils; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.coffee.bus.enums.PatientAlarmEnum; import com.coffee.bus.service.LocalBusPatientService; import com.coffee.bus.service.dto.MonitorStatusStatsCountResult; import com.coffee.bus.service.dto.PatientMonitorResult; import com.coffee.common.config.websocket.TopicMessage; import com.coffee.common.config.websocket.WebSocketConstant; import com.coffee.common.util.RedissonUtil; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.util.Assert; import java.io.Serializable; /** * @author lifang * @version 1.0.0 * @ClassName WsPushUtils.java * @Description ws发布消息工具类 * @createTime 2022年05月07日 11:34:00 */ @Component @AllArgsConstructor @Slf4j public class WsPublishUtils implements Serializable{ private final LocalBusPatientService patientService; private final RedissonUtil redissonUtil; private void publish(String topic,TopicMessage msg){ redissonUtil.getTopic(topic).publishAsync(msg); } /** * 描述: 推送设备输注消息 * @author lifang * @date 2022/5/13 9:39 * @param patientCode * @param tenantId * @return void */ @Async public void publishPatientMonitor(String patientCode,String tenantId){ Assert.hasText(tenantId,"医院id不能为空"); log.info("推送病号数据【{}】", JSONUtil.toJsonStr(patientCode)); PatientMonitorResult message = patientService.lookMonitorByPatientCode(patientCode, tenantId); if (log.isDebugEnabled()) { log.debug("推送病号当前状态,【{}】",JSONUtil.toJsonStr(message)); } if(message!=null){ message.handleWarn(); this.publish(WebSocketConstant.getPatientMonitor(null, patientCode, tenantId).getTopic(), TopicMessage.of(message,patientCode) ); } } /** * 描述: 推送医院设备状态统计数量 * @author lifang * @date 2022/5/13 9:39 * @param * @return void */ @Async public void publishMonitorStateCount(String tenantId){ Assert.hasText(tenantId,"医院id不能为空"); MonitorStatusStatsCountResult message = patientService.statusStats(tenantId); this.publish(WebSocketConstant.getMonitorStateCount(tenantId).getTopic(), TopicMessage.of(message,tenantId) ); } /** * 描述: 新增病人订阅 * @author lifang * @date 2022/5/13 9:39 * @param * @return void */ @Async public void publishPatientAdd(String patientCode,String tenantId){ Assert.hasText(tenantId,"医院id不能为空"); JSONObject message = new JSONObject().putOpt("patientCode", patientCode); this.publish(WebSocketConstant.getPatientAdd(tenantId).getTopic(), TopicMessage.of(message,tenantId)); } /** * 描述: 推送医院临床设备重复数量统计 * @author lifang * @date 2022/5/13 9:39 * @param * @return void */ @Async public void publishDeviceRepeat(String tenantId){ Assert.hasText(tenantId,"医院id不能为空"); JSONObject message = new JSONObject().putOpt("count", patientService.patientAlarmCount(tenantId,PatientAlarmEnum.DEVICE_REPEAT)); this.publish(WebSocketConstant.getDeviceRepeat(tenantId).getTopic(), TopicMessage.of(message,tenantId) ); } /** * 描述: 推送临床设备无绑定数量统计 * @author lifang * @date 2022/5/13 9:39 * @param * @return void */ @Async public void publishDeviceNone(String tenantId){ Assert.hasText(tenantId,"医院id不能为空"); JSONObject message = new JSONObject().putOpt("count",patientService.patientAlarmCount(tenantId,PatientAlarmEnum.DEVICE_NONE)); this.publish(WebSocketConstant.getDeviceNone(tenantId).getTopic(), TopicMessage.of(message,tenantId) ); } /** * 描述: 推送临床设备总数量统计 * @author lifang * @date 2022/5/13 9:39 * @param * @return void */ @Async public void publishMonitorTotalCount(String tenantId){ Assert.hasText(tenantId,"医院id不能为空"); JSONObject message = new JSONObject().putOpt("count", patientService.monitorTotalCount(tenantId)); this.publish(WebSocketConstant.getMonitorTotalCount(tenantId).getTopic(), TopicMessage.of(message,tenantId) ); } }