Bladeren bron

add
苹果手机报警推送

18339543638 1 jaar geleden
bovenliggende
commit
8005f735bb

+ 33 - 0
nb-service-api/app-assistant-api/src/main/java/com/nb/app/assistant/api/bean/DeviceAlarmBean.java

@@ -0,0 +1,33 @@
+package com.nb.app.assistant.api.bean;
+
+import com.nb.web.api.enums.DeviceAlarmEnum;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.ToString;
+
+import java.util.Date;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName BusDeviceAlarmEntity.java
+ * @Description 设备报警信息
+ * @createTime 2022年04月08日 16:18:00
+ */
+@Data
+@ApiModel(value="设备报警信息", description="设备报警信息记录")
+@ToString
+public class DeviceAlarmBean{
+    @ApiModelProperty(value = "设备唯一编码")
+    private String deviceId;
+
+    @ApiModelProperty(value = "报警信息")
+    private DeviceAlarmEnum alarmState;
+
+    @ApiModelProperty("住院号")
+    private String patientCode;
+
+    @ApiModelProperty("报警时间")
+    private Date uploadTime;
+}

+ 14 - 0
nb-service-api/app-assistant-api/src/main/java/com/nb/app/assistant/api/feign/IAppIphoneClient.java

@@ -0,0 +1,14 @@
+package com.nb.app.assistant.api.feign;
+
+import com.nb.app.assistant.api.bean.DeviceAlarmBean;
+
+/**
+ * @ClassName : IAppIphoneClient
+ * @Description :
+ * @Author : LF
+ * @Date: 2024年10月12日
+ */
+
+public interface IAppIphoneClient {
+    void sendAlarmMsg(String tenantId, DeviceAlarmBean source);
+}

+ 6 - 0
nb-service-api/web-service-api/src/main/java/com/nb/web/api/entity/BusDeviceAlarmEntity.java

@@ -83,6 +83,10 @@ public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
     @TableField(updateStrategy = FieldStrategy.IGNORED)
     private FlowStatusEnum warnFlow;
 
+    @ApiModelProperty("住院号")
+    @TableField(exist = false)
+    private String patientCode;
+
     public static BusDeviceAlarmEntity parseHistory(BusDeviceHistoryEntity history){
         BusDeviceAlarmEntity entity = new BusDeviceAlarmEntity();
         entity.setDeviceId(history.getDeviceId());
@@ -100,6 +104,7 @@ public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
         entity.setWarnFlow(history.getWarnFlow());
         entity.setTenantId(history.getTenantId());
         entity.setDeviceType(history.getType());
+        entity.setPatientCode(history.getPatientCode());
         return entity;
     }
 
@@ -120,6 +125,7 @@ public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
         entity.setWarnFlow(source.getWarnFlow());
         entity.setTenantId(source.getTenantId());
         entity.setDeviceType(source.getType());
+        entity.setPatientCode(source.getPatientCode());
         return entity;
     }
 

+ 24 - 5
nb-service/app-assistant/src/main/java/com/nb/app/assistant/service/LocalAppIphoneService.java

@@ -1,10 +1,14 @@
 package com.nb.app.assistant.service;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.nb.app.assistant.api.bean.DeviceAlarmBean;
+import com.nb.app.assistant.api.feign.IAppIphoneClient;
 import com.nb.app.assistant.dto.IphoneDeviceDTO;
 import com.nb.app.assistant.utils.ApnsUtils;
 import lombok.AllArgsConstructor;
 import org.redisson.api.RSet;
 import org.redisson.api.RedissonClient;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.util.Set;
@@ -17,10 +21,9 @@ import java.util.Set;
  */
 @Service
 @AllArgsConstructor
-public class LocalAppIphoneService {
+public class LocalAppIphoneService implements IAppIphoneClient {
     private final RedissonClient redissonClient;
 
-
     public void addDeviceToken(IphoneDeviceDTO source){
         RSet<String> tenantSet = redissonClient.getSet(source.getTenantId());
         tenantSet.add(source.getDeviceToken());
@@ -31,9 +34,25 @@ public class LocalAppIphoneService {
         tenantSet.remove(source.getDeviceToken());
     }
 
-    public void sendMsg(String tenantId){
+    @Override
+    @Async
+    public void sendAlarmMsg(String tenantId, DeviceAlarmBean source) {
+        this.sendMsg(tenantId,source);
+    }
+
+    private void sendMsg(String tenantId, DeviceAlarmBean source){
         RSet<String> tenantSet = redissonClient.getSet(tenantId);
-        tenantSet.readAll();
-//        ApnsUtils.sendMsg();
+        Set<String> deviceTokenSet = tenantSet.readAll();
+        if (CollectionUtil.isNotEmpty(deviceTokenSet)) {
+            deviceTokenSet.parallelStream()
+                    .forEach(deviceToken->{
+                        try {
+                            ApnsUtils.sendMsg(deviceToken,source);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    });
+        }
     }
+
 }

+ 31 - 12
nb-service/app-assistant/src/main/java/com/nb/app/assistant/utils/ApnsUtils.java

@@ -1,12 +1,16 @@
 package com.nb.app.assistant.utils;
 
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.json.JSONUtil;
+import com.nb.app.assistant.api.bean.DeviceAlarmBean;
 import com.turo.pushy.apns.*;
 import com.turo.pushy.apns.auth.ApnsSigningKey;
 import com.turo.pushy.apns.util.SimpleApnsPushNotification;
 import com.turo.pushy.apns.util.concurrent.PushNotificationFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
+import lombok.AllArgsConstructor;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.File;
@@ -20,7 +24,7 @@ import static com.turo.pushy.apns.PushType.ALERT;
 @Slf4j
 public class ApnsUtils {
     private static ApnsClient apnsClient = null;
-    public static void sendMsg(String deviceToken,String msgContent) throws Exception {
+    public static void sendMsg(String deviceToken, DeviceAlarmBean source) throws Exception {
         //IOS等终端设备注册后返回的DeviceToken
         /**
          * Use the voip push type for notifications that provide information about an incoming Voice-over-IP (VoIP)
@@ -34,17 +38,9 @@ public class ApnsUtils {
         //此处可以参考https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns?language=objc
 
         String topic = "tuoren.PumpIOS";
-        String payload = "{  \n" +
-                "   \"aps\":{  \n" +
-                "      \"alert\":{  \n" +
-                "         \"title\":\"驼人镇痛泵报警\",\n" +
-                "         \"subtitle\":\"75415123E11248\",\n" +
-                "         \"body\":\"故障报警\"\n" +
-                "      },\n" +
-                "      \"badge\":1, \n" +
-                "      \"sound\":\"default\", \n" +
-                "   }\n" +
-                "}\n" ;
+
+        ApsEntity aps = ApsEntity.createDefault(ApsEntity.AlertEntity.of("驼人镇痛泵报警", String.format("设备号:%s,住院号:%s", source.getDeviceId(), source.getPatientCode()), source.getAlarmState().getText()));
+        String payload = JSONUtil.toJsonStr(aps);
         //有效时间
         Date invalidationTime= new Date(System.currentTimeMillis() + 60 * 60 * 1000L );
         //发送策略 apns-priority 10为立即 5为省电
@@ -92,4 +88,27 @@ public class ApnsUtils {
         }
         return apnsClient;
     }
+
+    @Data
+    public static class ApsEntity {
+
+        private AlertEntity alert;
+        private Integer badge;
+        private String sound;
+
+        public static ApsEntity createDefault(AlertEntity alert){
+            ApsEntity apsEntity = new ApsEntity();
+            apsEntity.setBadge(1);
+            apsEntity.setSound("default");
+            apsEntity.setAlert(alert);
+            return apsEntity;
+        }
+        @Data
+        @AllArgsConstructor(staticName = "of")
+        public static class AlertEntity {
+            private String title;
+            private String subtitle;
+            private String body;
+        }
+    }
 }

+ 5 - 0
nb-service/web-service/pom.xml

@@ -99,6 +99,11 @@
             <version>3.12.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.tuoren</groupId>
+            <artifactId>app-assistant-api</artifactId>
+        </dependency>
+
 
     </dependencies>
 </project>

+ 9 - 1
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/LocalBusDeviceAlarmService.java

@@ -1,11 +1,14 @@
 package com.nb.web.service.bus.service;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.nb.app.assistant.api.bean.DeviceAlarmBean;
+import com.nb.app.assistant.api.feign.IAppIphoneClient;
 import com.nb.web.api.entity.BusDeviceAlarmEntity;
 import com.nb.web.api.feign.IDeviceAlarmClient;
 import com.nb.web.api.feign.query.AlarmQuery;
@@ -39,7 +42,9 @@ import java.util.Map;
 @Slf4j
 @AllArgsConstructor
 public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper, BusDeviceAlarmEntity,String> implements IDeviceAlarmClient {
-
+    @Autowired
+    @Lazy
+    private IAppIphoneClient appIphoneService;
     @Autowired
     @Lazy
     private LocalBusHospitalService hospitalService;
@@ -99,6 +104,9 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
            }
        }
 
+       if(Boolean.TRUE.equals(entity.getAlarm())){
+           appIphoneService.sendAlarmMsg(entity.getTenantId(), BeanUtil.copyProperties(entity, DeviceAlarmBean.class));
+       }
         //再判断是否报警或提示是否发生重复
         //满足以上条件进行保存
         return super.save(entity);