Parcourir la source

master 代码同步到 prod

sunhh il y a 1 an
Parent
commit
27ec8a67ed

+ 5 - 0
business-service/src/main/java/com/ozs/service/entity/MsgAppPush.java

@@ -81,4 +81,9 @@ public class MsgAppPush extends BaseEntity implements Serializable {
      * app标识ID registration_id
      */
     private String registrationId;
+
+    /**
+     * 是否推送,1:推送,2:未推
+     */
+    private String online;
 }

+ 2 - 0
business-service/src/main/java/com/ozs/service/mapper/MsgAppPushMapper.java

@@ -37,4 +37,6 @@ public interface MsgAppPushMapper extends BaseMapper<MsgAppPush> {
     int updates(MsgAppPush msgAppPush);
 
     List<MsgAlarm> messageMoreApp(MsgAlarmVo msgAlarmVo);
+
+    List<MsgAppPush> getByUserId(String userId);
 }

+ 1 - 0
business-service/src/main/java/com/ozs/service/service/MsgAppPushService.java

@@ -35,4 +35,5 @@ public interface MsgAppPushService extends IService<MsgAppPush> {
      */
     int updates(MsgAppPush msgAppPush);
 
+    List<MsgAppPush> getByUserId(String userId);
 }

+ 5 - 0
business-service/src/main/java/com/ozs/service/service/impl/MsgAppPushServiceImpl.java

@@ -80,4 +80,9 @@ public class MsgAppPushServiceImpl extends ServiceImpl<MsgAppPushMapper, MsgAppP
         int num = msgAppPushMapper.updates(msgAppPush);
         return num;
     }
+
+    @Override
+    public List<MsgAppPush> getByUserId(String userId) {
+        return msgAppPushMapper.getByUserId(userId);
+    }
 }

+ 2 - 0
business-service/src/main/java/com/ozs/service/service/impl/UserRegistrationidServiceImpl.java

@@ -38,6 +38,8 @@ public class UserRegistrationidServiceImpl extends ServiceImpl<UserRegistrationi
         log.info("userRegistrationids333333333333333:--------" + userRegistrationids.size());
         if (com.ozs.common.utils.StringUtils.isEmpty(userRegistrationids) && userRegistrationids.size() == 0) {
             userRegistrationidMapper.insert(userRegistrationid);
+        } else {
+            userRegistrationidMapper.updateRegistrationID(userRegistrationid);
         }
         return 1;
     }

+ 4 - 0
business-service/src/main/resources/mapper/service/MsgAppPushMapper.xml

@@ -103,4 +103,8 @@
             </if>
         </where>
     </select>
+
+    <select id="getByUserId" parameterType="java.lang.String" resultType="com.ozs.service.entity.MsgAppPush">
+        select * from msg_app_push where online = '2' and receive_by = #{userId}
+    </select>
 </mapper>

+ 50 - 9
hazard-admin/src/main/java/com/ozs/web/controller/websocket/WebSocketConteoller.java

@@ -65,13 +65,44 @@ public class WebSocketConteoller extends BaseController {
         return projectName;
     }
 
+    /**
+     * app 登陆时查询 未登陆时推送的消息 重新推送
+     * @return
+     */
+    @ResponseBody
+    @GetMapping("/getMessageApp")
+    public Map publishApp() {
+        String userId = getUserId();
+        List<MsgAppPush> msgAppPushList = msgAppPushService.getByUserId(userId);
+        for (MsgAppPush msgAppPush : msgAppPushList) {
+            String remark = msgAppPush.getRemark();
+            MsgAlarmResp msgAlarmResp = JSONObject.parseObject(remark, MsgAlarmResp.class);
+            Date alarmTime = msgAlarmResp.getAlarmTime();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            String formatDate = sdf.format(alarmTime != null ? alarmTime : new Date());
+            List<String> userList = new ArrayList<>();
+            userList.add(userId);
+            JPushUtil.sendToRegistrationId(
+                    userList,
+                    "报警通知!", msgAlarmResp.getRailwayName() != null ? msgAlarmResp.getRailwayName() : "",
+                    // content,
+                    formatDate + "     " + (msgAlarmResp.getAlarmType() == 1 ? "泥石流" : msgAlarmResp.getAlarmType()) + "     " + msgAlarmResp.getLineDir() + "     " + msgAlarmResp.getAlarmMile() + "     " + msgAlarmResp.getBeginMile(),
+                    remark);
+            msgAppPush.setOnline("1");
+            msgAppPushService.updateById(msgAppPush);
+        }
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("code", 200);
+        return map;
+    }
+
     /**
      * web 登陆时查询 未登陆时推送的消息 重新推送
      * @return
      */
     @ResponseBody
     @GetMapping("/getMessage")
-    public Map publish() {
+    public Map publishWeb() {
         String userId = getUserId();
         List<MsgWebPush> msgWebPushList = msgWebPushService.getByUserId(userId);
         for (MsgWebPush msgWebPush : msgWebPushList) {
@@ -199,16 +230,26 @@ public class WebSocketConteoller extends BaseController {
                     String formatDate = sdf.format(alarmTime != null ? alarmTime : new Date());
                     log.info("APPcontent-----" + content);
                     log.info("APPuserid-----" + userRegistrationid.getUserId());
-                    List<String> userList = new ArrayList<>();
-                    userList.add(userRegistrationid.getRegistrationId());
-                    JPushUtil.sendToRegistrationId(
-                            userList,
-                            "报警通知!", cameraName != null ? cameraName : "",
-                            // content,
-                            formatDate + "     " + (msgAlarmResp.getAlarmType() == 1 ? "泥石流" : msgAlarmResp.getAlarmType()) + "     " + (baseCameraManagement.getLineDir() == 1 ? "上行" : "下行") + "     " + mile + "     " + endMile,
-                            content);
                     // 存入数据
                     MsgAppPush msgAppPush = new MsgAppPush();
+                    // 推送消息reqMsgAlarmVo
+                    boolean userOnline = webSocketServer.userOnline(userRegistrationid.getUserId());
+                    log.info("userOnline-userOnline-userOnline-userOnline-----::::::" + userOnline);
+                    if (userOnline) {
+                        List<String> userList = new ArrayList<>();
+                        userList.add(userRegistrationid.getRegistrationId());
+                        JPushUtil.sendToRegistrationId(
+                                userList,
+                                "报警通知!", cameraName != null ? cameraName : "",
+                                // content,
+                                formatDate + "     " + (msgAlarmResp.getAlarmType() == 1 ? "泥石流" : msgAlarmResp.getAlarmType()) + "     " + (baseCameraManagement.getLineDir() == 1 ? "上行" : "下行") + "     " + mile + "     " + endMile,
+                                content);
+                        msgAppPush.setOnline("1");
+                    } else {
+                        // online 是否推送,1:推送,2:未推
+                        msgAppPush.setOnline("2");
+                    }
+                    msgAppPush.setRemark(content);
                     // 状态:1未读;2已读
                     msgAppPush.setStatus(1);
                     msgAppPush.setPushId(pushId);

+ 0 - 3
hazard-admin/src/main/java/com/ozs/web/controller/websocket/WebSocketServer.java

@@ -90,14 +90,12 @@ public class WebSocketServer {
      */
     @OnError
     public void onError(Session session, Throwable error) {
-
         log.error("用户错误,原因:" + error.getMessage());
         log.error("用户错误,原因:" + error.getLocalizedMessage());
         log.error("用户错误,原因sessionsessionsession:" + session.getId());
         error.printStackTrace();
     }
 
-
     // 此为广播消息
     public void sendAllMessage(String message) {
         log.info("【websocket消息】广播消息:" + message);
@@ -138,6 +136,5 @@ public class WebSocketServer {
                 }
             }
         }
-
     }
 }