|
@@ -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) {
|
|
@@ -96,108 +121,90 @@ public class WebSocketConteoller extends BaseController {
|
|
|
userIdLogin = user.getUserId();
|
|
|
}
|
|
|
String alarmId = msgAlarm.getAlarmId();
|
|
|
- for (String userid : list) {
|
|
|
- String pushId = UUID.randomUUID().toString();
|
|
|
- msgAlarmResp.setPushId(pushId);
|
|
|
- String content = objStr(msgAlarmResp);
|
|
|
- log.info("WEBcontent-----" + content);
|
|
|
- log.info("WEBuserid-----" + userid);
|
|
|
- // 推送消息reqMsgAlarmVo
|
|
|
- webSocketServer.sendOneMessage(userid, content);
|
|
|
|
|
|
- // 存入数据
|
|
|
- MsgWebPush msgWebPush = new MsgWebPush();
|
|
|
- // 状态: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);
|
|
|
- }
|
|
|
-// String content = objStr(msgAlarmResp);
|
|
|
-// // 推送消息reqMsgAlarmVo
|
|
|
-// webSocketServer.sendMoreMessage(list, content);
|
|
|
- // app 消息推送
|
|
|
- List<String> alias = new ArrayList<>();
|
|
|
- if (!StringUtils.isEmpty(userIdList) || userIdList.size() > 0) {
|
|
|
- alias = userRegistrationidService.selectRegistrationID(userIdList);
|
|
|
+ LambdaQueryWrapper<MsgWebPush> lwMsgWebPush = new LambdaQueryWrapper<MsgWebPush>();
|
|
|
+ if (!ObjectUtils.isEmpty(msgAlarm.getCameraCode())) {
|
|
|
+ lwMsgWebPush.eq(MsgWebPush::getAlarmId, msgAlarm.getAlarmId());
|
|
|
}
|
|
|
- // List<String> alias = new ArrayList<String>();
|
|
|
- // alias.add("sunhh");
|
|
|
- // list去重
|
|
|
- List<String> listString = distinct(alias);
|
|
|
- if (!StringUtils.isEmpty(listString) || listString.size() > 0) {
|
|
|
- for (String userid : listString) {
|
|
|
+ List<MsgWebPush> msgWebPushList = msgWebPushService.list(lwMsgWebPush);
|
|
|
+ if (StringUtils.isEmpty(msgWebPushList) || msgWebPushList.size() == 0) {
|
|
|
+ for (String userid : list) {
|
|
|
String pushId = UUID.randomUUID().toString();
|
|
|
- msgAlarmResp.setPushId(UUID.randomUUID().toString());
|
|
|
+ msgAlarmResp.setPushId(pushId);
|
|
|
String content = objStr(msgAlarmResp);
|
|
|
- Date alarmTime = msgAlarm.getAlarmTime();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- String formatDate = sdf.format(alarmTime != null ? alarmTime : new Date());
|
|
|
- log.info("APPcontent-----" + content);
|
|
|
- log.info("APPuserid-----" + userid);
|
|
|
- List<String> userList = new ArrayList<>();
|
|
|
- userList.add(userid);
|
|
|
- JPushUtil.sendToRegistrationId(
|
|
|
- userList,
|
|
|
- "报警通知!", cameraName != null ? cameraName : "",
|
|
|
- // content,
|
|
|
- formatDate + " " + (msgAlarmResp.getAlarmType() == 1 ? "泥石流" : msgAlarmResp.getAlarmType()) + " " + (baseCameraManagement.getLineDir() == 1 ? "上行" : "下行") + " " + mile + " " + endMile,
|
|
|
- content);
|
|
|
-
|
|
|
+ log.info("WEBcontent-----" + content);
|
|
|
+ log.info("WEBuserid-----" + userid);
|
|
|
// 存入数据
|
|
|
- MsgAppPush msgAppPush = new MsgAppPush();
|
|
|
+ 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已读
|
|
|
- msgAppPush.setStatus(1);
|
|
|
- msgAppPush.setPushId(pushId);
|
|
|
- msgAppPush.setAlarmId(alarmId);
|
|
|
- msgAppPush.setReceiveBy(userid);
|
|
|
- msgAppPush.setCreateBy(userIdLogin);
|
|
|
- msgAppPush.setCreateTime(new Date());
|
|
|
- msgAppPush.setUpdateBy(userIdLogin);
|
|
|
- msgAppPush.setUpdateTime(new Date());
|
|
|
- msgAppPushService.save(msgAppPush);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // app 消息推送
|
|
|
+ LambdaQueryWrapper<MsgAppPush> lwMsgAppPush = new LambdaQueryWrapper<MsgAppPush>();
|
|
|
+ if (!ObjectUtils.isEmpty(msgAlarm.getCameraCode())) {
|
|
|
+ lwMsgAppPush.eq(MsgAppPush::getAlarmId, msgAlarm.getAlarmId());
|
|
|
+ }
|
|
|
+ List<MsgAppPush> msgAppPushList = msgAppPushService.list(lwMsgAppPush);
|
|
|
+ if (StringUtils.isEmpty(msgAppPushList) || msgAppPushList.size() == 0) {
|
|
|
+ List<String> alias = new ArrayList<>();
|
|
|
+ if (!StringUtils.isEmpty(userIdList) || userIdList.size() > 0) {
|
|
|
+ alias = userRegistrationidService.selectRegistrationID(userIdList);
|
|
|
+ }
|
|
|
+ List<String> listString = distinct(alias);
|
|
|
+ if (!StringUtils.isEmpty(listString) || listString.size() > 0) {
|
|
|
+ for (String userid : listString) {
|
|
|
+ String pushId = UUID.randomUUID().toString();
|
|
|
+ msgAlarmResp.setPushId(UUID.randomUUID().toString());
|
|
|
+ String content = objStr(msgAlarmResp);
|
|
|
+ Date alarmTime = msgAlarm.getAlarmTime();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formatDate = sdf.format(alarmTime != null ? alarmTime : new Date());
|
|
|
+ log.info("APPcontent-----" + content);
|
|
|
+ log.info("APPuserid-----" + userid);
|
|
|
+ List<String> userList = new ArrayList<>();
|
|
|
+ userList.add(userid);
|
|
|
+ JPushUtil.sendToRegistrationId(
|
|
|
+ userList,
|
|
|
+ "报警通知!", cameraName != null ? cameraName : "",
|
|
|
+ // content,
|
|
|
+ formatDate + " " + (msgAlarmResp.getAlarmType() == 1 ? "泥石流" : msgAlarmResp.getAlarmType()) + " " + (baseCameraManagement.getLineDir() == 1 ? "上行" : "下行") + " " + mile + " " + endMile,
|
|
|
+ content);
|
|
|
+ // 存入数据
|
|
|
+ MsgAppPush msgAppPush = new MsgAppPush();
|
|
|
+ // 状态:1未读;2已读
|
|
|
+ msgAppPush.setStatus(1);
|
|
|
+ msgAppPush.setPushId(pushId);
|
|
|
+ msgAppPush.setAlarmId(alarmId);
|
|
|
+ msgAppPush.setReceiveBy(userid);
|
|
|
+ msgAppPush.setCreateBy(userIdLogin);
|
|
|
+ msgAppPush.setCreateTime(new Date());
|
|
|
+ msgAppPush.setUpdateBy(userIdLogin);
|
|
|
+ msgAppPush.setUpdateTime(new Date());
|
|
|
+ msgAppPushService.save(msgAppPush);
|
|
|
+ }
|
|
|
}
|
|
|
-// Date alarmTime = msgAlarm.getAlarmTime();
|
|
|
-// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
-// String formatDate = sdf.format(alarmTime != null ? alarmTime : new Date());
|
|
|
-// JPushUtil.sendToRegistrationId(
|
|
|
-// listString,
|
|
|
-// "报警通知!", cameraName != null ? cameraName : "",
|
|
|
-// // content,
|
|
|
-// formatDate + " " + (msgAlarmResp.getAlarmType() == 1 ? "泥石流" : msgAlarmResp.getAlarmType()) + " " + (baseCameraManagement.getLineDir() == 1 ? "上行" : "下行") + " " + mile + " " + endMile,
|
|
|
-// content);
|
|
|
}
|
|
|
-// // 存入数据
|
|
|
-// if (!StringUtils.isEmpty(msgAlarm.getAlarmId()) || !StringUtils.isEmpty(userIdList)) {
|
|
|
-// String userIdLogin = "admin编码";
|
|
|
-// SysUser user = userService.selectUserById(1L);
|
|
|
-// if (!ObjectUtils.isEmpty(user)) {
|
|
|
-// userIdLogin = user.getUserId();
|
|
|
-// }
|
|
|
-// String alarmId = msgAlarm.getAlarmId();
|
|
|
-// for (String userId : userIdList) {
|
|
|
-// MsgWebPush msgWebPush = new MsgWebPush();
|
|
|
-// // 状态:1未读;2已读
|
|
|
-// msgWebPush.setStatus(1);
|
|
|
-// msgWebPush.setAlarmId(alarmId);
|
|
|
-// msgWebPush.setReceiveBy(userId);
|
|
|
-// msgWebPush.setCreateBy(userIdLogin);
|
|
|
-// msgWebPush.setCreateTime(new Date());
|
|
|
-// msgWebPush.setUpdateBy(userIdLogin);
|
|
|
-// msgWebPush.setUpdateTime(new Date());
|
|
|
-// msgWebPushService.save(msgWebPush);
|
|
|
-// if (!StringUtils.isEmpty(alias) || alias.size() > 0) {
|
|
|
-// MsgAppPush msgAppPush = new MsgAppPush();
|
|
|
-// BeanUtils.copyProperties(msgWebPush, msgAppPush);
|
|
|
-// msgAppPushService.save(msgAppPush);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
|
map.put("code", 200);
|
|
|
return map;
|