소스 검색

消息推送

sunhh 1 년 전
부모
커밋
4caf76be29

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

@@ -72,4 +72,9 @@ public class MsgWebPush extends BaseEntity {
      * 备注
      */
     private String remark;
+
+    /**
+     * 是否推送,1:推送,2:未推
+     */
+    private String online;
 }

+ 2 - 0
business-service/src/main/java/com/ozs/entity/vo/MsgAlarmResp.java

@@ -22,6 +22,8 @@ public class MsgAlarmResp implements Serializable {
 
     private long id;
 
+    private String alarmId;
+
     /**
      * web,app 唯一标识-uuid
      */

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

@@ -39,4 +39,6 @@ public interface BaseUserMapper extends BaseMapper<BaseUser> {
     List<String> getRoleName(@Param("userId")String userId);
 
     BaseUser getUserById(@Param("id")Long id);
+
+    List<String> getUserListAll();
 }

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

@@ -27,4 +27,6 @@ public interface MsgWebPushMapper extends BaseMapper<MsgWebPush> {
     int updateByPushId(MsgWebPush msgWebPush);
 
     int readAll(@Param("userId") String userId);
+
+    List<MsgWebPush> getByUserId(@Param("userId") String userId);
 }

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

@@ -21,4 +21,6 @@ public interface BaseUserService extends IService<BaseUser> {
     BaseUser getUserName(@Param("userName") String userName);
 
     List<String> getRoleName(@Param("userId")String userId);
+
+    List<String> getUserListAll();
 }

+ 3 - 0
business-service/src/main/java/com/ozs/service/MsgWebPushService.java

@@ -6,6 +6,7 @@ import com.ozs.entity.MsgAlarm;
 import com.ozs.entity.MsgWebPush;
 import com.ozs.entity.vo.MsgAlarmVo;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -22,4 +23,6 @@ public interface MsgWebPushService extends IService<MsgWebPush> {
     Map<String, Integer> messageMoreNum(String userId);
 
     int readAll(String userId);
+
+    List<MsgWebPush> getByUserId(String userId);
 }

+ 6 - 0
business-service/src/main/java/com/ozs/service/impl/BaseUserServiceImpl.java

@@ -72,4 +72,10 @@ public class BaseUserServiceImpl extends ServiceImpl<BaseUserMapper, BaseUser> i
     public List<String> getRoleName(String userId) {
         return baseUserMapper.getRoleName(userId);
     }
+
+    @Override
+    public List<String> getUserListAll() {
+        List<String> userIdsList = baseUserMapper.getUserListAll();
+        return userIdsList;
+    }
 }

+ 9 - 4
business-service/src/main/java/com/ozs/service/impl/MsgWebPushServiceImpl.java

@@ -1,9 +1,12 @@
 package com.ozs.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
+import com.ozs.common.core.domain.entity.SysUser;
+import com.ozs.common.utils.AppendUtils;
 import com.ozs.common.utils.StringUtils;
 import com.ozs.entity.MsgAlarm;
 import com.ozs.entity.MsgWebPush;
@@ -17,10 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -132,4 +132,9 @@ public class MsgWebPushServiceImpl extends ServiceImpl<MsgWebPushMapper, MsgWebP
     public int readAll(String userId) {
         return msgWebPushMapper.readAll(userId);
     }
+
+    @Override
+    public List<MsgWebPush> getByUserId(String userId) {
+        return msgWebPushMapper.getByUserId(userId);
+    }
 }

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

@@ -78,4 +78,8 @@
     <select id="getUserById" resultType="com.ozs.entity.BaseUser">
     select user_id userId, dept_id deptId, data_permission dataPermission,nick_name nickName,user_name userName from sys_user where id = #{id}
     </select>
+    <select id="getUserListAll" resultType="java.lang.String">
+        select user_id
+        from sys_user
+    </select>
 </mapper>

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

@@ -88,4 +88,8 @@
         </set>
         where receive_by = #{userId} and status = 1
     </update>
+
+    <select id="getByUserId" parameterType="java.lang.String" resultType="com.ozs.service.entity.MsgWebPush">
+        select * from msg_web_push where online = '2' and receive_by = #{userId}
+    </select>
 </mapper>

+ 0 - 16
vehicle-admin/pom.xml

@@ -35,22 +35,6 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-websocket</artifactId>
         </dependency>
-        <!-- 极光推送 -->
-        <dependency>
-            <groupId>cn.jpush.api</groupId>
-            <artifactId>jpush-client</artifactId>
-            <version>3.3.8</version>
-        </dependency>
-        <dependency>
-            <groupId>cn.jpush.api</groupId>
-            <artifactId>jmessage-client</artifactId>
-            <version>1.1.8</version>
-        </dependency>
-        <dependency>
-            <groupId>cn.jpush.api</groupId>
-            <artifactId>jiguang-common</artifactId>
-            <version>1.1.3</version>
-        </dependency>
 
         <!-- swagger3-->
         <!--        <dependency>-->

+ 0 - 470
vehicle-admin/src/main/java/com/ozs/web/controller/websocket/JPushUtil.java

@@ -1,470 +0,0 @@
-package com.ozs.web.controller.websocket;
-
-import cn.jiguang.common.resp.APIConnectionException;
-import cn.jiguang.common.resp.APIRequestException;
-import cn.jpush.api.JPushClient;
-import cn.jpush.api.push.PushResult;
-import cn.jpush.api.push.model.Message;
-import cn.jpush.api.push.model.Options;
-import cn.jpush.api.push.model.Platform;
-import cn.jpush.api.push.model.PushPayload;
-import cn.jpush.api.push.model.audience.Audience;
-import cn.jpush.api.push.model.notification.AndroidNotification;
-import cn.jpush.api.push.model.notification.IosNotification;
-import cn.jpush.api.push.model.notification.Notification;
-import cn.jpush.api.schedule.ScheduleResult;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-
-/**
- * @Author : sunhh
- * @create 2023/3/14 11:20
- */
-@Slf4j
-@Component
-public class JPushUtil {
-
-    private final static String APPKER = "1712ced750e33d75d18cb577";
-    private final static String MASTERSECRET = "e4b8ba2eda2acd0f75177b88";
-    // 极光demo
-    // private final static String APPKER = "2a59ed096611fb4b82f08a44";
-    // private final static String MASTERSECRET = "a121413e4b89b0a4b3998fe0";
-
-    /**
-     * 推送给设备标识参数的用户
-     */
-    public static int sendToRegistrationId(List<String> alias, String notification_title, String msg_title, String msg_content, String extrasparam) {
-        JPushClient jPushClient = new JPushClient(MASTERSECRET, APPKER);
-        int result = 0;
-        try {
-            PushPayload pushPayload = JPushUtil.buildPushObjectAllAliasAlertWithTitle(alias, notification_title, msg_title, msg_content, extrasparam);
-            PushResult pushResult = jPushClient.sendPush(pushPayload);
-            if (pushResult.getResponseCode() == 200) {
-                result = 1;
-            }
-            log.info("[极光推送]PushResult result is " + pushResult);
-        } catch (APIConnectionException e) {
-            log.error("[极光推送]Connection error. Should retry later. ", e);
-        } catch (APIRequestException e) {
-            log.error("[极光推送]Error response from JPush server. Should review and fix it. ", e);
-            log.info("[极光推送]HTTP Status: " + e.getStatus());
-            log.info("[极光推送]Error Code: " + e.getErrorCode());
-            log.info("[极光推送]Error Message: " + e.getErrorMessage());
-        }
-        return result;
-    }
-
-    /**
-     * 推送给指定设备标识参数的用户(自定义消息通知)
-     *
-     * @param alias              设备标识 用户ID 别名
-     * @param notification_title 通知内容标题
-     * @param msg_title          消息内容标题
-     * @param msg_content        消息内容
-     * @param extrasparam        扩展字段(通常传跳转的链接)
-     * @return 0推送失败,1推送成功
-     */
-    public static int sendToRegistrationId(String alias, String notification_title, String msg_title, String msg_content, String extrasparam) {
-        JPushClient jPushClient = new JPushClient(MASTERSECRET, APPKER);
-        int result = 0;
-        try {
-            PushPayload pushPayload = JPushUtil.buildPushObject_all_alias_alertWithTitle(alias, notification_title, msg_title, msg_content, extrasparam);
-            PushResult pushResult = jPushClient.sendPush(pushPayload);
-            if (pushResult.getResponseCode() == 200) {
-                result = 1;
-            }
-            log.info("[极光推送]PushResult result is " + pushResult);
-        } catch (APIConnectionException e) {
-            log.error("[极光推送]Connection error. Should retry later. ", e);
-        } catch (APIRequestException e) {
-            log.error("[极光推送]Error response from JPush server. Should review and fix it. ", e);
-            log.info("[极光推送]HTTP Status: " + e.getStatus());
-            log.info("[极光推送]Error Code: " + e.getErrorCode());
-            log.info("[极光推送]Error Message: " + e.getErrorMessage());
-        }
-        return result;
-    }
-
-    /**
-     * 推送给设备标识参数的用户(定时)
-     */
-    public static int sendToRegistrationId2(List<String> alias, String notification_title, String msg_title, String msg_content, String extrasparam, String time) {
-        JPushClient jPushClient = new JPushClient(MASTERSECRET, APPKER);
-        int result = 0;
-        try {
-            PushPayload pushPayload = JPushUtil.buildPushObjectAllAliasAlertWithTitle(alias, notification_title, msg_title, msg_content, extrasparam);
-            ScheduleResult scheduleResult = jPushClient.createSingleSchedule("测试", time, pushPayload);
-            if (scheduleResult.getResponseCode() == 200) {
-                result = 1;
-            }
-            log.info("[极光推送]ScheduleResult result is " + scheduleResult);
-        } catch (APIConnectionException e) {
-            log.error("[极光推送]Connection error. Should retry later. ", e);
-        } catch (APIRequestException e) {
-            log.error("[极光推送]Error response from JPush server. Should review and fix it. ", e);
-            log.info("[极光推送]HTTP Status: " + e.getStatus());
-            log.info("[极光推送]Error Code: " + e.getErrorCode());
-            log.info("[极光推送]Error Message: " + e.getErrorMessage());
-        }
-        return result;
-    }
-
-    /**
-     * 发送给所有安卓用户
-     */
-    public static int sendToAllAndroid(String notification_title, String msg_title, String msg_content, String extrasparam) {
-        JPushClient jPushClient = new JPushClient(MASTERSECRET, APPKER);
-        int result = 0;
-        try {
-            PushPayload pushPayload = JPushUtil.buildPushObjectAndroidAllAlertWithTitle(notification_title, msg_title, msg_content, extrasparam);
-            PushResult pushResult = jPushClient.sendPush(pushPayload);
-            if (pushResult.getResponseCode() == 200) {
-                result = 1;
-            }
-            log.info("[极光推送]PushResult result is " + pushResult);
-        } catch (APIConnectionException e) {
-            log.error("[极光推送]Connection error. Should retry later. ", e);
-        } catch (APIRequestException e) {
-            log.error("[极光推送]Error response from JPush server. Should review and fix it. ", e);
-            log.info("[极光推送]HTTP Status: " + e.getStatus());
-            log.info("[极光推送]Error Code: " + e.getErrorCode());
-            log.info("[极光推送]Error Message: " + e.getErrorMessage());
-        }
-        return result;
-    }
-
-    /**
-     * 发送给所有IOS用户
-     */
-    public static int sendToAllIos(String notification_title, String msg_title, String msg_content, String extrasparam) {
-        JPushClient jPushClient = new JPushClient(MASTERSECRET, APPKER);
-        int result = 0;
-        try {
-            PushPayload pushPayload = JPushUtil.buildPushObjectIosAllAlertWithTitle(notification_title, msg_title, msg_content, extrasparam);
-            PushResult pushResult = jPushClient.sendPush(pushPayload);
-            if (pushResult.getResponseCode() == 200) {
-                result = 1;
-            }
-            log.info("[极光推送]PushResult result is " + pushResult);
-        } catch (APIConnectionException e) {
-            log.error("[极光推送]Connection error. Should retry later. ", e);
-        } catch (APIRequestException e) {
-            log.error("[极光推送]Error response from JPush server. Should review and fix it. ", e);
-            log.info("[极光推送]HTTP Status: " + e.getStatus());
-            log.info("[极光推送]Error Code: " + e.getErrorCode());
-            log.info("[极光推送]Error Message: " + e.getErrorMessage());
-        }
-        return result;
-    }
-
-    /**
-     * 发送给所有用户
-     */
-    public static int sendToAll(String notification_title, String msg_title, String msg_content, String extrasparam) {
-        JPushClient jPushClient = new JPushClient(MASTERSECRET, APPKER);
-        int result = 0;
-        try {
-            PushPayload pushPayload = JPushUtil.buildPushObjectAndroidAndIos(notification_title, msg_title, msg_content, extrasparam);
-            PushResult pushResult = jPushClient.sendPush(pushPayload);
-            if (pushResult.getResponseCode() == 200) {
-                result = 1;
-            }
-            log.info("[极光推送]PushResult result is " + pushResult);
-        } catch (APIConnectionException e) {
-            log.error("[极光推送]Connection error. Should retry later. ", e);
-        } catch (APIRequestException e) {
-            log.error("[极光推送]Error response from JPush server. Should review and fix it. ", e);
-            log.info("[极光推送]HTTP Status: " + e.getStatus());
-            log.info("[极光推送]Error Code: " + e.getErrorCode());
-            log.info("[极光推送]Error Message: " + e.getErrorMessage());
-        }
-        return result;
-    }
-
-    /**
-     * 发送给所有用户(定时推送)
-     */
-    public static int sendToAll2(String notification_title, String msg_title, String msg_content, String extrasparam, String time) {
-        JPushClient jPushClient = new JPushClient(MASTERSECRET, APPKER);
-        int result = 0;
-        try {
-            PushPayload pushPayload = JPushUtil.buildPushObjectAndroidAndIos(notification_title, msg_title, msg_content, extrasparam);
-            ScheduleResult scheduleResult = jPushClient.createSingleSchedule("测试", time, pushPayload);
-            if (scheduleResult.getResponseCode() == 200) {
-                result = 1;
-            }
-            log.info("[极光推送]scheduleResult result is " + scheduleResult);
-        } catch (APIConnectionException e) {
-            log.error("[极光推送]Connection error. Should retry later. ", e);
-        } catch (APIRequestException e) {
-            log.error("[极光推送]Error response from JPush server. Should review and fix it. ", e);
-            log.info("[极光推送]HTTP Status: " + e.getStatus());
-            log.info("[极光推送]Error Code: " + e.getErrorCode());
-            log.info("[极光推送]Error Message: " + e.getErrorMessage());
-        }
-        return result;
-    }
-
-    /**
-     * 推送自定义消息 指定别名推送
-     *
-     * @param alias
-     * @param notification_title
-     * @param msg_title
-     * @param msg_content
-     * @param extrasparam
-     * @return
-     */
-    private static PushPayload buildPushObject_all_alias_alertWithTitle(String alias, String notification_title, String msg_title, String msg_content, String extrasparam) {
-        //创建一个IosAlert对象,可指定APNs的alert、title等字段
-        //IosAlert iosAlert =  IosAlert.newBuilder().setTitleAndBody("title", "alert body").build();
-        return PushPayload.newBuilder()
-                //指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台
-                .setPlatform(Platform.all())
-                //指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
-                .setAudience(Audience.alias(alias))
-                //.setAudience(Audience.all()) //所有人
-                //.setAudience(Audience.registrationId(registrationId)) //注册ID
-                //jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发
-                .setNotification(Notification.newBuilder()
-                        //指定当前推送的android通知
-                        .addPlatformNotification(AndroidNotification.newBuilder()
-                                .setAlert(msg_content)
-                                .setTitle(notification_title)
-                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
-                                .addExtra("url", extrasparam)
-                                .build())
-                        //指定当前推送的iOS通知
-                        .addPlatformNotification(IosNotification.newBuilder()
-                                //传一个IosAlert对象,指定apns title、title、subtitle等
-                                .setAlert(msg_content)
-                                //直接传alert
-                                //此项是指定此推送的badge自动加1
-                                .incrBadge(1)
-                                //此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,
-                                // 如果系统没有此音频则以系统默认声音提醒;此字段如果传空字符串,iOS9及以上的系统是无声音提醒,以下的系统是默认声音
-                                .setSound("sound.caf")
-                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
-                                .addExtra("url", extrasparam)
-                                //此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification
-                                //取消此注释,消息推送时ios将无法在锁屏情况接收
-                                // .setContentAvailable(true)
-                                .build())
-                        .build())
-                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
-                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
-                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
-                .setMessage(Message.newBuilder()
-                        .setMsgContent(msg_content)
-                        .setTitle(msg_title)
-                        //.addExtra("url", extrasparam) //释放该字段会发送两次消息,第二次消息内容是扩展字段
-                        .build())
-                .setOptions(Options.newBuilder()
-                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义
-                        .setApnsProduction(true)
-                        //此字段是给开发者自己给推送编号,方便推送者分辨推送记录
-                        .setSendno(1)
-                        //此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天; 秒为单位
-                        .setTimeToLive(1 * 60 * 60 * 24)
-                        .build())
-                .build();
-    }
-
-    public static PushPayload buildPushObjectAndroidAndIos(String notification_title, String msg_title, String msg_content, String extrasparam) {
-        return PushPayload.newBuilder()
-                .setPlatform(Platform.android_ios())
-                .setAudience(Audience.all())
-                .setNotification(Notification.newBuilder()
-                        .setAlert(msg_content)
-                        .addPlatformNotification(AndroidNotification.newBuilder()
-                                .setAlert(msg_content)
-                                .setTitle(notification_title)
-                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
-                                .addExtra("url", extrasparam)
-                                .build()
-                        )
-                        .addPlatformNotification(IosNotification.newBuilder()
-                                //传一个IosAlert对象,指定apns title、title、subtitle等
-                                .setAlert(msg_content)
-                                //直接传alert
-                                //此项是指定此推送的badge自动加1
-                                .incrBadge(1)
-                                //此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,
-                                // 如果系统没有此音频则以系统默认声音提醒;此字段如果传空字符串,iOS9及以上的系统是无声音提醒,以下的系统是默认声音
-                                .setSound("sound.caf")
-                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
-                                .addExtra("url", extrasparam)
-                                //此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification
-                                // .setContentAvailable(true)
-                                .build()
-                        )
-                        .build()
-                )
-                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
-                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
-                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
-                .setMessage(Message.newBuilder()
-                        .setMsgContent(msg_content)
-                        .setTitle(msg_title)
-                        .addExtra("url", extrasparam)
-                        .build())
-                .setOptions(Options.newBuilder()
-                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义
-                        .setApnsProduction(true)
-                        //此字段是给开发者自己给推送编号,方便推送者分辨推送记录
-                        .setSendno(1)
-                        //此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天,单位为秒
-                        .setTimeToLive(86400)
-                        .build()
-                )
-                .build();
-    }
-
-    private static PushPayload buildPushObjectAllAliasAlertWithTitle(List<String> alias, String notification_title, String msg_title, String msg_content, String extrasparam) {
-        //创建一个IosAlert对象,可指定APNs的alert、title等字段
-        //IosAlert iosAlert =  IosAlert.newBuilder().setTitleAndBody("title", "alert body").build();
-        return PushPayload.newBuilder()
-                //指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台
-                .setPlatform(Platform.all())
-                //指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
-                .setAudience(Audience.registrationId(alias))
-//                .setAudience(Audience.registrationId(registrationId))
-                //jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发
-                .setNotification(Notification.newBuilder()
-                        //指定当前推送的android通知
-                        .addPlatformNotification(AndroidNotification.newBuilder()
-                                .setAlert(msg_content)
-                                .setTitle(notification_title)
-                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
-                                .addExtra("url", extrasparam)
-                                .build())
-                        //指定当前推送的iOS通知
-                        .addPlatformNotification(IosNotification.newBuilder()
-                                //传一个IosAlert对象,指定apns title、title、subtitle等
-                                .setAlert(msg_content)
-                                //直接传alert
-                                //此项是指定此推送的badge自动加1
-                                .incrBadge(1)
-                                //此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,
-                                // 如果系统没有此音频则以系统默认声音提醒;此字段如果传空字符串,iOS9及以上的系统是无声音提醒,以下的系统是默认声音
-                                .setSound("sound.caf")
-                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
-                                .addExtra("url", extrasparam)
-                                //此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification
-                                //取消此注释,消息推送时ios将无法在锁屏情况接收
-                                // .setContentAvailable(true)
-                                .build())
-                        .build())
-                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
-                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
-                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
-                .setMessage(Message.newBuilder()
-                        .setMsgContent(msg_content)
-                        .setTitle(msg_title)
-                        .addExtra("url", extrasparam)
-                        .build())
-                .setOptions(Options.newBuilder()
-                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义
-                        .setApnsProduction(true)
-                        //此字段是给开发者自己给推送编号,方便推送者分辨推送记录
-                        .setSendno(1)
-                        //此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天;
-                        .setTimeToLive(86400)
-                        .build())
-                .build();
-    }
-
-    private static PushPayload buildPushObjectAndroidAllAlertWithTitle(String notification_title, String msg_title, String msg_content, String extrasparam) {
-        return PushPayload.newBuilder()
-                //指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台
-                .setPlatform(Platform.android())
-                //指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
-                .setAudience(Audience.all())
-                //jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发
-                .setNotification(Notification.newBuilder()
-                        //指定当前推送的android通知
-                        .addPlatformNotification(AndroidNotification.newBuilder()
-                                .setAlert(msg_content)
-                                .setTitle(notification_title)
-                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
-                                .addExtra("url", extrasparam)
-                                .build())
-                        .build()
-                )
-                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
-                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
-                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
-                .setMessage(Message.newBuilder()
-                        .setMsgContent(msg_content)
-                        .setTitle(msg_title)
-                        .addExtra("url", extrasparam)
-                        .build())
-                .setOptions(Options.newBuilder()
-                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义
-                        .setApnsProduction(true)
-                        //此字段是给开发者自己给推送编号,方便推送者分辨推送记录
-                        .setSendno(1)
-                        //此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天,单位为秒
-                        .setTimeToLive(86400)
-                        .build())
-                .build();
-    }
-
-    private static PushPayload buildPushObjectIosAllAlertWithTitle(String notification_title, String msg_title, String msg_content, String extrasparam) {
-        return PushPayload.newBuilder()
-                //指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台
-                .setPlatform(Platform.ios())
-                //指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
-                .setAudience(Audience.all())
-                //jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发
-                .setNotification(Notification.newBuilder()
-                        //指定当前推送的android通知
-                        .addPlatformNotification(IosNotification.newBuilder()
-                                //传一个IosAlert对象,指定apns title、title、subtitle等
-                                .setAlert(msg_content)
-                                //直接传alert
-                                //此项是指定此推送的badge自动加1
-                                .incrBadge(1)
-                                //此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,
-                                // 如果系统没有此音频则以系统默认声音提醒;此字段如果传空字符串,iOS9及以上的系统是无声音提醒,以下的系统是默认声音
-                                .setSound("sound.caf")
-                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
-                                .addExtra("url", extrasparam)
-                                //此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification
-                                // .setContentAvailable(true)
-                                .build())
-                        .build()
-                )
-                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
-                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
-                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
-                .setMessage(Message.newBuilder()
-                        .setMsgContent(msg_content)
-                        .setTitle(msg_title)
-                        .addExtra("url", extrasparam)
-                        .build())
-                .setOptions(Options.newBuilder()
-                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义
-                        .setApnsProduction(true)
-                        //此字段是给开发者自己给推送编号,方便推送者分辨推送记录
-                        .setSendno(1)
-                        //此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天,单位为秒
-                        .setTimeToLive(86400)
-                        .build())
-                .build();
-    }
-
-//    public static void main(String[] args) {
-//        List<String> alias = new ArrayList<String>();
-//        alias.add("sunhh");
-////        alias.add("wangyy");
-//        //sendToRegistrationId(alias, "中奖通知", "中奖通知", "恭喜你中了100个亿!", "https://www.baidu.com");
-//        //sendToRegistrationId2(alias,"中奖通知", "中奖通知", "恭喜你中了100个亿!", "https://www.baidu.com","2021-07-14 17:54:00");
-////        sendToAllAndroid("中奖通知!!!!", "中奖通知!!!!!", "恭喜你中了100000000个亿!!!!", "https://www.baidu.com");
-//         sendToAllIos("中奖通知", "中奖通知", "恭喜你中了100个亿", "https://www.baidu.com");
-//         // sendToAll("中奖通知", "中奖通知", "恭喜你中了100个亿!", "https://www.baidu.com");
-//        //sendToAll2("中奖通知", "中奖通知", "恭喜你中了100个亿!", "https://www.baidu.com","2021-07-14 17:54:00");
-//    }
-}

+ 142 - 0
vehicle-admin/src/main/java/com/ozs/web/controller/websocket/WebSocketCommon.java

@@ -0,0 +1,142 @@
+package com.ozs.web.controller.websocket;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ozs.common.core.domain.entity.SysUser;
+import com.ozs.common.utils.AppendUtils;
+import com.ozs.common.utils.StringUtils;
+import com.ozs.entity.MsgAlarm;
+import com.ozs.entity.MsgWebPush;
+import com.ozs.entity.vo.MsgAlarmResp;
+import com.ozs.service.BaseRailwayManagementService;
+import com.ozs.service.BaseUserService;
+import com.ozs.service.MsgWebPushService;
+import com.ozs.system.service.ISysDictDataService;
+import com.ozs.system.service.ISysUserService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+/**
+ * @Author : sunhh
+ * @create 2023/6/5 17:04
+ */
+@Slf4j
+public class WebSocketCommon {
+
+    @Autowired
+    private WebSocketServer webSocketServer;
+    @Resource
+    private BaseRailwayManagementService baseRailwayManagementService;
+    @Autowired
+    private ISysUserService userService;
+    @Autowired
+    private MsgWebPushService msgWebPushService;
+    @Autowired
+    private BaseUserService baseUserService;
+    @Autowired
+    private ISysDictDataService dictDataService;
+
+    public Map publish(@RequestBody MsgAlarm msgAlarm) {
+        String endMile = null;
+        log.info("消息推送:" + msgAlarm.toString());
+//        LambdaQueryWrapper<BaseCameraManagement> wrapper = new LambdaQueryWrapper<BaseCameraManagement>();
+//        if (!ObjectUtils.isEmpty(msgAlarm.getCameraCode())) {
+//            wrapper.eq(BaseCameraManagement::getCameraCode, msgAlarm.getCameraCode());
+//        }
+//        BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(wrapper);
+//        log.info("baseCameraManagement-----" + baseCameraManagement);
+
+//        String[] list = set.toArray(new String[set.size()]);
+//        List<String> userIdList = new ArrayList<>(set);
+        MsgAlarmResp msgAlarmResp = new MsgAlarmResp();
+        if (!StringUtils.isEmptySunhh(msgAlarm.getEndMile()) && !StringUtils.isEmptySunhh((msgAlarm.getBeginMile()))) {
+            String begin = AppendUtils.stringAppend(Integer.valueOf(msgAlarm.getBeginMile()));
+            String end = AppendUtils.stringAppend(Integer.valueOf(msgAlarm.getEndMile()));
+            endMile = begin + "-" + end;
+            msgAlarmResp.setBeginMile(endMile);
+        }
+        msgAlarmResp.setAlarmType(msgAlarm.getAlarmType());
+        String mile = AppendUtils.stringAppend(Integer.valueOf(msgAlarm.getAlarmMile()));
+        msgAlarmResp.setAlarmMile(mile);
+//        String cameraCode = msgAlarm.getCameraCode();
+//        msgAlarmResp.setCameraCode(cameraCode);
+
+        String cameraName = baseRailwayManagementService.getCameraNameByCameraCode(msgAlarm.getRailwayCode());
+        msgAlarmResp.setRailwayName(cameraName != null ? cameraName : "");
+        msgAlarmResp.setLineDirStr(msgAlarm.getLineDir() == 1 ? "上行" : "下行");
+        msgAlarmResp.setAlarmTime(msgAlarm.getAlarmTime() != null ? msgAlarm.getAlarmTime() : new Date());
+        // 图片
+        if (!StringUtils.isEmptySunhh(msgAlarm.getImageUrls())) {
+            msgAlarmResp.setImageUrls(msgAlarm.getImageUrls());
+        }
+        if (!StringUtils.isEmptySunhh(msgAlarm.getId())) {
+            msgAlarmResp.setId(msgAlarm.getId());
+        }
+        String userIdLogin = "admin编码";
+        SysUser user = userService.selectUserById(1L);
+        if (!ObjectUtils.isEmpty(user)) {
+            userIdLogin = user.getUserId();
+        }
+        String alarmId = msgAlarm.getAlarmId();
+        msgAlarmResp.setAlarmId(alarmId);
+
+        LambdaQueryWrapper<MsgWebPush> lwMsgWebPush = new LambdaQueryWrapper<MsgWebPush>();
+        if (!ObjectUtils.isEmpty(msgAlarm.getAlarmId())) {
+            lwMsgWebPush.eq(MsgWebPush::getAlarmId, msgAlarm.getAlarmId());
+        }
+        List<MsgWebPush> msgWebPushList = msgWebPushService.list(lwMsgWebPush);
+
+        // 获取推送人ID列表
+//        log.info("publish-----" + baseCameraManagement.getCreateBy() + "-------------" + baseCameraManagement.getDeptId());
+        List<String> usetIdList = baseUserService.getUserListAll();
+        log.info("set-----" + usetIdList);
+        if (StringUtils.isEmpty(msgWebPushList) || msgWebPushList.size() == 0) {
+            for (String userid : usetIdList) {
+                String pushId = UUID.randomUUID().toString();
+                msgAlarmResp.setPushId(pushId);
+                String content = objStr(msgAlarmResp);
+                log.info("WEBcontent-----" + content);
+                log.info("WEBuserid-----" + userid);
+                // 存入数据
+                MsgWebPush msgWebPush = new MsgWebPush();
+                // 推送消息reqMsgAlarmVo
+                boolean userOnline = webSocketServer.userOnline(userid);
+                log.info("userOnline-userOnline-userOnline-userOnline-----::::::" + userOnline);
+                if (userOnline) {
+                    webSocketServer.sendOneMessage(userid, content);
+                    msgWebPush.setOnline("1");
+                } else {
+                    // online 是否推送,1:推送,2:未推
+                    msgWebPush.setOnline("2");
+                }
+                msgWebPush.setRemark(content);
+                // 状态:1未读;2已读
+                msgWebPush.setStatus(1);
+                msgWebPush.setPushId(pushId);
+                msgWebPush.setAlarmId(alarmId);
+                msgWebPush.setReceiveBy(userid);
+                msgWebPush.setCreateBy(userIdLogin);
+                msgWebPush.setCreateTime(new Date());
+                msgWebPush.setUpdateBy(userIdLogin);
+                msgWebPush.setUpdateTime(new Date());
+                msgWebPushService.save(msgWebPush);
+            }
+        }
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("code", 200);
+        return map;
+    }
+
+    private String objStr(MsgAlarmResp msgAlarmResp) {
+        JSONObject obj = new JSONObject();
+        obj.put("data", msgAlarmResp); //data
+        obj.put("code", 110); //code
+        log.info("【websocket消息】 单点消息:" + obj.toJSONString());
+        return obj.toJSONString();
+    }
+}

+ 185 - 0
vehicle-admin/src/main/java/com/ozs/web/controller/websocket/WebSocketConteoller.java

@@ -0,0 +1,185 @@
+package com.ozs.web.controller.websocket;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ozs.common.core.controller.BaseController;
+import com.ozs.common.core.domain.entity.SysUser;
+import com.ozs.common.utils.AppendUtils;
+import com.ozs.common.utils.StringUtils;
+import com.ozs.entity.*;
+import com.ozs.entity.vo.MsgAlarmResp;
+import com.ozs.service.BaseRailwayManagementService;
+import com.ozs.service.BaseUserService;
+import com.ozs.service.MsgWebPushService;
+import com.ozs.system.service.ISysDictDataService;
+import com.ozs.system.service.ISysUserService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * @Author : sunhh
+ * @create 2023/6/5 15:36
+ */
+@Slf4j
+@Controller
+@RequestMapping("/sdk")
+public class WebSocketConteoller extends BaseController {
+    @Autowired
+    private WebSocketServer webSocketServer;
+    @Resource
+    private BaseRailwayManagementService baseRailwayManagementService;
+    @Autowired
+    private ISysUserService userService;
+    @Autowired
+    private MsgWebPushService msgWebPushService;
+    @Autowired
+    private BaseUserService baseUserService;
+    @Autowired
+    private ISysDictDataService dictDataService;
+
+    /**
+     * 获取项目名称
+     */
+    @ResponseBody
+    @GetMapping("/projectName")
+    public String projectName() {
+        String projectName = dictDataService.selectDictLabel("sys_name", "name");
+//        HashMap<String, Object> map = new HashMap<>();
+//        map.put("name", projectName);
+        return projectName;
+    }
+
+    /**
+     * web 登陆时查询 未登陆时推送的消息 重新推送
+     *
+     * @return
+     */
+    @ResponseBody
+    @GetMapping("/getMessage")
+    public Map publishWeb() {
+        String userId = getUserId();
+        List<MsgWebPush> msgWebPushList = msgWebPushService.getByUserId(userId);
+        for (MsgWebPush msgWebPush : msgWebPushList) {
+            webSocketServer.sendOneMessage(userId, msgWebPush.getRemark());
+            msgWebPush.setOnline("1");
+            msgWebPushService.updateById(msgWebPush);
+        }
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("code", 200);
+        return map;
+    }
+
+    /**
+     * 推送消息
+     *
+     * @param msgAlarm
+     * @return
+     */
+    @ResponseBody
+    @PostMapping("/publish")
+    public Map publish(@RequestBody MsgAlarm msgAlarm) {
+        String endMile = null;
+        log.info("消息推送:" + msgAlarm.toString());
+//        LambdaQueryWrapper<BaseCameraManagement> wrapper = new LambdaQueryWrapper<BaseCameraManagement>();
+//        if (!ObjectUtils.isEmpty(msgAlarm.getCameraCode())) {
+//            wrapper.eq(BaseCameraManagement::getCameraCode, msgAlarm.getCameraCode());
+//        }
+//        BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(wrapper);
+//        log.info("baseCameraManagement-----" + baseCameraManagement);
+
+//        String[] list = set.toArray(new String[set.size()]);
+//        List<String> userIdList = new ArrayList<>(set);
+        MsgAlarmResp msgAlarmResp = new MsgAlarmResp();
+        if (!StringUtils.isEmptySunhh(msgAlarm.getEndMile()) && !StringUtils.isEmptySunhh((msgAlarm.getBeginMile()))) {
+            String begin = AppendUtils.stringAppend(Integer.valueOf(msgAlarm.getBeginMile()));
+            String end = AppendUtils.stringAppend(Integer.valueOf(msgAlarm.getEndMile()));
+            endMile = begin + "-" + end;
+            msgAlarmResp.setBeginMile(endMile);
+        }
+        msgAlarmResp.setAlarmType(msgAlarm.getAlarmType());
+        String mile = AppendUtils.stringAppend(Integer.valueOf(msgAlarm.getAlarmMile()));
+        msgAlarmResp.setAlarmMile(mile);
+//        String cameraCode = msgAlarm.getCameraCode();
+//        msgAlarmResp.setCameraCode(cameraCode);
+
+        String cameraName = baseRailwayManagementService.getCameraNameByCameraCode(msgAlarm.getRailwayCode());
+        msgAlarmResp.setRailwayName(cameraName != null ? cameraName : "");
+        msgAlarmResp.setLineDirStr(msgAlarm.getLineDir() == 1 ? "上行" : "下行");
+        msgAlarmResp.setAlarmTime(msgAlarm.getAlarmTime() != null ? msgAlarm.getAlarmTime() : new Date());
+        // 图片
+        if (!StringUtils.isEmptySunhh(msgAlarm.getImageUrls())) {
+            msgAlarmResp.setImageUrls(msgAlarm.getImageUrls());
+        }
+        if (!StringUtils.isEmptySunhh(msgAlarm.getId())) {
+            msgAlarmResp.setId(msgAlarm.getId());
+        }
+        String userIdLogin = "admin编码";
+        SysUser user = userService.selectUserById(1L);
+        if (!ObjectUtils.isEmpty(user)) {
+            userIdLogin = user.getUserId();
+        }
+        String alarmId = msgAlarm.getAlarmId();
+        msgAlarmResp.setAlarmId(alarmId);
+
+        LambdaQueryWrapper<MsgWebPush> lwMsgWebPush = new LambdaQueryWrapper<MsgWebPush>();
+        if (!ObjectUtils.isEmpty(msgAlarm.getAlarmId())) {
+            lwMsgWebPush.eq(MsgWebPush::getAlarmId, msgAlarm.getAlarmId());
+        }
+        List<MsgWebPush> msgWebPushList = msgWebPushService.list(lwMsgWebPush);
+
+        // 获取推送人ID列表
+//        log.info("publish-----" + baseCameraManagement.getCreateBy() + "-------------" + baseCameraManagement.getDeptId());
+        List<String> usetIdList = baseUserService.getUserListAll();
+        log.info("set-----" + usetIdList);
+        if (StringUtils.isEmpty(msgWebPushList) || msgWebPushList.size() == 0) {
+            for (String userid : usetIdList) {
+                String pushId = UUID.randomUUID().toString();
+                msgAlarmResp.setPushId(pushId);
+                String content = objStr(msgAlarmResp);
+                log.info("WEBcontent-----" + content);
+                log.info("WEBuserid-----" + userid);
+                // 存入数据
+                MsgWebPush msgWebPush = new MsgWebPush();
+                // 推送消息reqMsgAlarmVo
+                boolean userOnline = webSocketServer.userOnline(userid);
+                log.info("userOnline-userOnline-userOnline-userOnline-----::::::" + userOnline);
+                if (userOnline) {
+                    webSocketServer.sendOneMessage(userid, content);
+                    msgWebPush.setOnline("1");
+                } else {
+                    // online 是否推送,1:推送,2:未推
+                    msgWebPush.setOnline("2");
+                }
+                msgWebPush.setRemark(content);
+                // 状态:1未读;2已读
+                msgWebPush.setStatus(1);
+                msgWebPush.setPushId(pushId);
+                msgWebPush.setAlarmId(alarmId);
+                msgWebPush.setReceiveBy(userid);
+                msgWebPush.setCreateBy(userIdLogin);
+                msgWebPush.setCreateTime(new Date());
+                msgWebPush.setUpdateBy(userIdLogin);
+                msgWebPush.setUpdateTime(new Date());
+                msgWebPushService.save(msgWebPush);
+            }
+        }
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("code", 200);
+        return map;
+    }
+
+    private String objStr(MsgAlarmResp msgAlarmResp) {
+        JSONObject obj = new JSONObject();
+        obj.put("data", msgAlarmResp); //data
+        obj.put("code", 110); //code
+        log.info("【websocket消息】 单点消息:" + obj.toJSONString());
+        return obj.toJSONString();
+    }
+}