添加火点时,加入了websocket功能模块

This commit is contained in:
DESKTOP-G8BCEP0\HP 2021-07-20 16:38:14 +08:00
parent 31394ee9a2
commit 084bb672da
4 changed files with 21 additions and 3 deletions

View File

@ -76,7 +76,6 @@ public class TokenAuthenticationService {
LocalDateTime overTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime()); LocalDateTime overTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime());
// 计算距离结束时间的天数作为token // 计算距离结束时间的天数作为token
Duration duration = Duration.between(LocalDateTime.now(), overTime); Duration duration = Duration.between(LocalDateTime.now(), overTime);
System.out.println("-------"+duration.toDays());
/** /**
* 动态设置过期时间 * 动态设置过期时间
*/ */
@ -95,7 +94,6 @@ public class TokenAuthenticationService {
.signWith(key) .signWith(key)
.compact(); .compact();
map.put("token",jwt); map.put("token",jwt);
map.put("role",authsList);
map.put("user",sysUserEntity); map.put("user",sysUserEntity);
}else { }else {
/** /**
@ -116,7 +114,6 @@ public class TokenAuthenticationService {
.signWith(key) .signWith(key)
.compact(); .compact();
map.put("token",jwt); map.put("token",jwt);
map.put("role",authsList);
map.put("user",sysUserEntity); map.put("user",sysUserEntity);
} }
// JWT 写入 body // JWT 写入 body

View File

@ -47,6 +47,8 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers(HttpMethod.GET,"/selectAppTask").permitAll() .antMatchers(HttpMethod.GET,"/selectAppTask").permitAll()
.antMatchers(HttpMethod.GET,"/selectFirePointBetweenSeven").permitAll() .antMatchers(HttpMethod.GET,"/selectFirePointBetweenSeven").permitAll()
.antMatchers(HttpMethod.GET,"/selectFirePointNum").permitAll() .antMatchers(HttpMethod.GET,"/selectFirePointNum").permitAll()
.antMatchers(HttpMethod.GET,"/api/user/booleanUserName").permitAll()
.antMatchers(HttpMethod.GET,"/websocketTest").permitAll()
// 所有其它请求需要身份认证 // 所有其它请求需要身份认证
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()

View File

@ -8,6 +8,7 @@ import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.model.qo.FirePointQo; import com.xkrs.model.qo.FirePointQo;
import com.xkrs.model.vo.AppTaskBodyVo; import com.xkrs.model.vo.AppTaskBodyVo;
import com.xkrs.service.FirePointService; import com.xkrs.service.FirePointService;
import com.xkrs.websocket.service.WebSocketServer;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;

View File

@ -1,5 +1,6 @@
package com.xkrs.service.impl; package com.xkrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.common.tool.TokenUtil; import com.xkrs.common.tool.TokenUtil;
import com.xkrs.dao.*; import com.xkrs.dao.*;
@ -9,6 +10,7 @@ import com.xkrs.model.vo.AppPhotoVo;
import com.xkrs.model.vo.AppTaskBodyVo; import com.xkrs.model.vo.AppTaskBodyVo;
import com.xkrs.service.FirePointService; import com.xkrs.service.FirePointService;
import com.xkrs.utils.*; import com.xkrs.utils.*;
import com.xkrs.websocket.service.WebSocketServer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanCopier; import org.springframework.cglib.beans.BeanCopier;
@ -81,6 +83,22 @@ public class FirePointServiceImpl implements FirePointService {
firePointEntity.setAddTime(DateTimeUtil.dateTimeToString(LocalDateTime.now())); firePointEntity.setAddTime(DateTimeUtil.dateTimeToString(LocalDateTime.now()));
firePointEntity.setFireType("0"); firePointEntity.setFireType("0");
log.info("-------发现新火点"); 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); return firePointDao.save(firePointEntity);
} }