From 084bb672da610dfc3a91f2c2db977eb4255d13f4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com> Date: Tue, 20 Jul 2021 16:38:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=81=AB=E7=82=B9=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=85=A5=E4=BA=86websocket=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/TokenAuthenticationService.java | 3 --- .../xkrs/common/config/WebSecurityConfig.java | 2 ++ .../xkrs/controller/FirePointController.java | 1 + .../service/impl/FirePointServiceImpl.java | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java index 3bc2aab..777adb2 100644 --- a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java +++ b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java @@ -76,7 +76,6 @@ public class TokenAuthenticationService { LocalDateTime overTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime()); // 计算距离结束时间的天数作为token Duration duration = Duration.between(LocalDateTime.now(), overTime); - System.out.println("-------"+duration.toDays()); /** * 动态设置过期时间 */ @@ -95,7 +94,6 @@ public class TokenAuthenticationService { .signWith(key) .compact(); map.put("token",jwt); - map.put("role",authsList); map.put("user",sysUserEntity); }else { /** @@ -116,7 +114,6 @@ public class TokenAuthenticationService { .signWith(key) .compact(); map.put("token",jwt); - map.put("role",authsList); map.put("user",sysUserEntity); } // 将 JWT 写入 body diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index ef01d27..57f535b 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -47,6 +47,8 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET,"/selectAppTask").permitAll() .antMatchers(HttpMethod.GET,"/selectFirePointBetweenSeven").permitAll() .antMatchers(HttpMethod.GET,"/selectFirePointNum").permitAll() + .antMatchers(HttpMethod.GET,"/api/user/booleanUserName").permitAll() + .antMatchers(HttpMethod.GET,"/websocketTest").permitAll() // 所有其它请求需要身份认证 .anyRequest().authenticated() .and() diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index be79bc3..0890889 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -8,6 +8,7 @@ import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.qo.FirePointQo; import com.xkrs.model.vo.AppTaskBodyVo; import com.xkrs.service.FirePointService; +import com.xkrs.websocket.service.WebSocketServer; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index f3bd168..892c35c 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -1,5 +1,6 @@ package com.xkrs.service.impl; +import com.alibaba.fastjson.JSON; import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.common.tool.TokenUtil; import com.xkrs.dao.*; @@ -9,6 +10,7 @@ import com.xkrs.model.vo.AppPhotoVo; import com.xkrs.model.vo.AppTaskBodyVo; import com.xkrs.service.FirePointService; import com.xkrs.utils.*; +import com.xkrs.websocket.service.WebSocketServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cglib.beans.BeanCopier; @@ -81,6 +83,22 @@ public class FirePointServiceImpl implements FirePointService { firePointEntity.setAddTime(DateTimeUtil.dateTimeToString(LocalDateTime.now())); firePointEntity.setFireType("0"); log.info("-------发现新火点"); + log.info("---------------开始进行实时通讯,将检测到的火点传给前端"); + Map map = new HashMap(3); + map.put("countyCode",firePointQo.getCountyCode()); + map.put("countyName",firePointQo.getCountyName()); + map.put("fireCode",firePointQo.getFireCode()); + map.put("latitude",firePointQo.getLatitude()); + map.put("longitude",firePointQo.getLongitude()); + map.put("satelliteTime",DateTimeUtil.timeMillisToString(firePointQo.getSatelliteTimeTs().longValue())); + map.put("satelliteType",firePointQo.getSatelliteType()); + map.put("addTime",DateTimeUtil.dateTimeToString(LocalDateTime.now())); + map.put("detailedAddress",AddressUtils.getLatAndLng(firePointQo.getLatitude().toString(),firePointQo.getLongitude().toString())); + Map map1 = new HashMap(3); + map1.put("fire",map); + String websocket = JSON.toJSONString(map1); + // 将监测到的火点信息返给前端 + WebSocketServer.broadInfo(websocket); return firePointDao.save(firePointEntity); }