|
@@ -22,6 +22,7 @@ import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.websocket.Session;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -51,6 +52,30 @@ public class WebSocketConteoller extends BaseController {
|
|
|
@Autowired
|
|
|
private MsgAppPushService msgAppPushService;
|
|
|
|
|
|
+ /**
|
|
|
+ * web 登陆时查询 未登陆时推送的消息 重新推送
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @GetMapping("/getMessage")
|
|
|
+ public Map publish() {
|
|
|
+ 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) {
|
|
@@ -109,11 +134,18 @@ public class WebSocketConteoller extends BaseController {
|
|
|
String content = objStr(msgAlarmResp);
|
|
|
log.info("WEBcontent-----" + content);
|
|
|
log.info("WEBuserid-----" + userid);
|
|
|
- // 推送消息reqMsgAlarmVo
|
|
|
- webSocketServer.sendOneMessage(userid, content);
|
|
|
-
|
|
|
// 存入数据
|
|
|
MsgWebPush msgWebPush = new MsgWebPush();
|
|
|
+ // 推送消息reqMsgAlarmVo
|
|
|
+ boolean userOnline = webSocketServer.userOnline(userid);
|
|
|
+ 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);
|