Compare commits
11 Commits
master
...
branch_fir
Author | SHA1 | Date | |
---|---|---|---|
3d9286ed3b | |||
e47c724a30 | |||
560105d2ca | |||
aba3b12135 | |||
aac7a6d750 | |||
7ff3b089d6 | |||
a0d1c6422a | |||
125aec00a9 | |||
8aa7fd11eb | |||
97a8e9c6c2 | |||
bfd418e174 |
@ -83,6 +83,10 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
|
||||
throw new DisabledException("用户状态不正常,请联系管理员");
|
||||
}
|
||||
|
||||
if (DateTimeUtil.dateTimeToString(LocalDateTime.now()).compareTo(userEntity.getOverTime()) > 0) {
|
||||
throw new DisabledException("该账号已过期,请联系管理员");
|
||||
}
|
||||
|
||||
// 认证逻辑
|
||||
String encryptPassword = encry256(password + userEntity.getSalt());
|
||||
if (encryptPassword.equals(userEntity.getPassword())) {
|
||||
|
@ -1,25 +0,0 @@
|
||||
package com.xkrs.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.messaging.MessageSecurityMetadataSourceRegistry;
|
||||
import org.springframework.security.config.annotation.web.socket.AbstractSecurityWebSocketMessageBrokerConfigurer;
|
||||
|
||||
import static org.springframework.messaging.simp.SimpMessageType.MESSAGE;
|
||||
import static org.springframework.messaging.simp.SimpMessageType.SUBSCRIBE;
|
||||
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
@Configuration
|
||||
public class WebSocketSecurityConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer {
|
||||
@Override
|
||||
protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
|
||||
messages
|
||||
.nullDestMatcher().authenticated()
|
||||
.simpSubscribeDestMatchers("/user/queue/errors").permitAll()
|
||||
.simpTypeMatchers(MESSAGE, SUBSCRIBE).denyAll()
|
||||
.anyMessage().denyAll();
|
||||
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.xkrs.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.dao.*;
|
||||
import com.xkrs.model.entity.CountyCodeWeiXinEntity;
|
||||
@ -95,10 +94,11 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
return false;
|
||||
}
|
||||
if ("Himawari 8".equals(firePointQo.getSatelliteType())) {
|
||||
if ("N".equals(firePointQo.getConfidence()) || "L".equals(firePointQo.getConfidence())) {
|
||||
if ("L".equals(firePointQo.getConfidence()) || "N".equals(firePointQo.getConfidence())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
FirePointEntity firePointEntity = new FirePointEntity();
|
||||
firePointEntity.setFireCode(firePointQo.getFireCode());
|
||||
firePointEntity.setCountyCode(firePointQo.getCountyCode().toString());
|
||||
@ -121,33 +121,9 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
}
|
||||
log.info("-------发现新火点");
|
||||
firePointDao.save(firePointEntity);
|
||||
forwardPoint(firePointEntity);
|
||||
//发送消息通知
|
||||
sendBroadcast(firePointEntity);
|
||||
return true;
|
||||
// if (firePointEntity.getCountyCode().startsWith("37")) {
|
||||
// //如果开关已打开,就只将未审核的火点添加到山东临时表
|
||||
// log.info("-------发现新山东火点");
|
||||
// ShanDongFirePointEntity shanDongFirePointByFirePoint = getShanDongFirePointByFirePoint(firePointEntity);
|
||||
// ShanDongFirePointEntity savedShanDongFirePoint = shanDongFirePointDao.save(shanDongFirePointByFirePoint);
|
||||
// //微信消息通知火点审核工作组
|
||||
// try {
|
||||
// String messageContent = getMessageContent(savedShanDongFirePoint);
|
||||
// WDWxSendMsgUtil.sendMsg("18447024917@chatroom", messageContent, 0);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
|
||||
private void forwardPoint(FirePointEntity firePointEntity) {
|
||||
try {
|
||||
String url = "http://121.36.229.60:6811/insertfirepointchannelThree";
|
||||
HttpClientUtils.sendHttpPostTextPlain(url, new ObjectMapper().writeValueAsString(firePointEntity));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -318,18 +294,7 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
String countyName = firePointEntity.getCountyName();
|
||||
String streetName = firePointEntity.getStreetName();
|
||||
String landType = firePointEntity.getLandType();
|
||||
return firePointEntity.getSatelliteType() + "发现1个火点。\n卫星时间:" + satelliteTime + ";\nlongitude:" + formatLongitude + ";\nlatitude:" + formatLatitude + ";\ncountyName:" + countyName + ";\nstreetName:" + streetName + ";\nlandType:" + landType;
|
||||
}
|
||||
|
||||
private String getMessageContent(ShanDongFirePointEntity firePointEntity) {
|
||||
java.text.DecimalFormat decimalFormat = new DecimalFormat("#.000000");
|
||||
String satelliteTime = firePointEntity.getSatelliteTime();
|
||||
String formatLongitude = decimalFormat.format(firePointEntity.getLongitude());
|
||||
String formatLatitude = decimalFormat.format(firePointEntity.getLatitude());
|
||||
String countyName = firePointEntity.getCountyName();
|
||||
String streetName = firePointEntity.getStreetName();
|
||||
String landType = firePointEntity.getLandType();
|
||||
return firePointEntity.getSatelliteType() + "发现1个待审核火点。\n卫星时间:" + satelliteTime + ";\nlongitude:" + formatLongitude + ";\nlatitude:" + formatLatitude + ";\ncountyName:" + countyName + ";\nstreetName:" + streetName + ";\nlandType:" + landType;
|
||||
return "星巡-全国火情播报系统\n" + firePointEntity.getSatelliteType() + "发现1个火点。\n卫星时间:" + satelliteTime + ";\nlongitude:" + formatLongitude + ";\nlatitude:" + formatLatitude + ";\ncountyName:" + countyName + ";\nstreetName:" + streetName + ";\nlandType:" + landType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,15 +111,15 @@ public class StreetServiceImpl implements StreetService {
|
||||
// RegionBean countyBean = new RegionBean();
|
||||
// countyBean.setCode(county.get("code"));
|
||||
// countyBean.setName(county.get("name"));
|
||||
//// List<Map<String, String>> streetList = selectStreetList(county.get("name"));
|
||||
//// List<RegionBean> streetBeanList = new ArrayList<>();
|
||||
//// for (Map<String, String> street : streetList) {
|
||||
//// RegionBean streetBean = new RegionBean();
|
||||
//// streetBean.setCode(street.get("code"));
|
||||
//// streetBean.setName(street.get("name"));
|
||||
//// streetBeanList.add(streetBean);
|
||||
//// }
|
||||
//// countyBean.setChildren(streetBeanList);
|
||||
// List<Map<String, String>> streetList = selectStreetList(county.get("code"));
|
||||
// List<RegionBean> streetBeanList = new ArrayList<>();
|
||||
// for (Map<String, String> street : streetList) {
|
||||
// RegionBean streetBean = new RegionBean();
|
||||
// streetBean.setCode(street.get("code"));
|
||||
// streetBean.setName(street.get("name"));
|
||||
// streetBeanList.add(streetBean);
|
||||
// }
|
||||
// countyBean.setChildren(streetBeanList);
|
||||
// countyBeanList.add(countyBean);
|
||||
// }
|
||||
// cityBean.setChildren(countyBeanList);
|
||||
|
@ -126,6 +126,7 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
|
||||
String countyCode = sysUserQo.getCountyCode();
|
||||
String countyName = sysUserQo.getCountyName();
|
||||
countyName = adapterCountyNameByCountyCode(countyCode);
|
||||
if (TextUtils.isEmpty(countyCode)) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "省市区街道编码不能为空!", locale);
|
||||
}
|
||||
@ -141,8 +142,10 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (streetNameList == null || streetNameList.isEmpty()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
|
||||
}
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setAccountType("街道级");
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(7L)));
|
||||
adapterStreetUser(sysUserEntity);
|
||||
} else if ("0000".equals(countyCode.substring(2))) {
|
||||
List<StreetEntity> proCodeList = streetDao.findByProCode(countyCode);
|
||||
if (proCodeList == null || proCodeList.size() == 0) {
|
||||
@ -152,8 +155,10 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (proNameList == null || proNameList.size() == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
|
||||
}
|
||||
sysUserEntity.setActiveFlag(1);
|
||||
sysUserEntity.setAccountType("省级");
|
||||
sysUserEntity.setActiveFlag(1);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(5L)));
|
||||
// adapterProUser(sysUserEntity);
|
||||
} else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) {
|
||||
List<StreetEntity> cityCodeList = streetDao.findByCityCode(countyCode);
|
||||
if (cityCodeList == null || cityCodeList.size() == 0) {
|
||||
@ -163,8 +168,10 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (cityNameList == null || cityNameList.size() == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
|
||||
}
|
||||
sysUserEntity.setActiveFlag(1);
|
||||
sysUserEntity.setAccountType("市级");
|
||||
sysUserEntity.setActiveFlag(1);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(5L)));
|
||||
adapterCityUser(sysUserEntity);
|
||||
} else {
|
||||
List<StreetEntity> countyCodeList = streetDao.findByCountyCode(countyCode);
|
||||
if (countyCodeList == null || countyCodeList.isEmpty()) {
|
||||
@ -174,13 +181,10 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (countyNameList == null || countyNameList.isEmpty()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
|
||||
}
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setAccountType("县级");
|
||||
}
|
||||
if (9 == countyCode.length()) {//街道账号7天后过期
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(7L)));
|
||||
} else {//省市区县账号5天后过期
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(5L)));
|
||||
adapterCountyUser(sysUserEntity);
|
||||
}
|
||||
sysUserEntity.setStatusCode(0);
|
||||
sysUserEntity.setAddTime(dateTimeToString(LocalDateTime.now()));
|
||||
@ -209,6 +213,81 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "注册成功!", locale);
|
||||
}
|
||||
|
||||
private String adapterCountyNameByCountyCode(String countyCode) {
|
||||
if (9 == countyCode.length()) {
|
||||
List<StreetEntity> streetCodeList = streetDao.findByStreetCode(countyCode);
|
||||
if (streetCodeList == null || streetCodeList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return streetCodeList.get(0).getStreetName();
|
||||
} else if ("0000".equals(countyCode.substring(2))) {
|
||||
List<StreetEntity> proCodeList = streetDao.findByProCode(countyCode);
|
||||
if (proCodeList == null || proCodeList.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return proCodeList.get(0).getProName();
|
||||
} else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) {
|
||||
List<StreetEntity> cityCodeList = streetDao.findByCityCode(countyCode);
|
||||
if (cityCodeList == null || cityCodeList.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return cityCodeList.get(0).getCityName();
|
||||
} else {
|
||||
List<StreetEntity> countyCodeList = streetDao.findByCountyCode(countyCode);
|
||||
if (countyCodeList == null || countyCodeList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return countyCodeList.get(0).getCountyName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 适配2023-11-09到2023-11-12之间注册的街道用户
|
||||
*/
|
||||
private void adapterStreetUser(SysUserEntity sysUserEntity) {
|
||||
if (in1109To1112()) {
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(180L)));
|
||||
}
|
||||
}
|
||||
|
||||
// private void adapterProUser(SysUserEntity sysUserEntity) {
|
||||
// if (in1109To1112()) {
|
||||
// sysUserEntity.setActiveFlag(1);
|
||||
// sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(5L)));
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 适配2023-11-09到2023-11-12之间注册的市级用户
|
||||
*/
|
||||
private void adapterCityUser(SysUserEntity sysUserEntity) {
|
||||
if (in1109To1112()) {
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(30L)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 适配2023-11-09到2023-11-12之间注册的区县用户
|
||||
*/
|
||||
private void adapterCountyUser(SysUserEntity sysUserEntity) {
|
||||
if (in1109To1112()) {
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(30L)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前是否处于2023-11-09到2023-11-12之间注册的
|
||||
*/
|
||||
private boolean in1109To1112() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime start1109 = LocalDateTime.of(2023, 11, 9, 0, 0, 0, 0);
|
||||
LocalDateTime end1112 = LocalDateTime.of(2023, 11, 13, 0, 0, 0, 0);
|
||||
return start1109.isBefore(now) && end1112.isAfter(now);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
*
|
||||
@ -247,8 +326,9 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (streetNameList == null || streetNameList.isEmpty()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
|
||||
}
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setAccountType("街道级");
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(7L)));
|
||||
} else if ("0000".equals(countyCode.substring(2))) {
|
||||
List<StreetEntity> proCodeList = streetDao.findByProCode(countyCode);
|
||||
if (proCodeList == null || proCodeList.size() == 0) {
|
||||
@ -258,8 +338,9 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (proNameList == null || proNameList.size() == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
|
||||
}
|
||||
sysUserEntity.setActiveFlag(1);
|
||||
sysUserEntity.setAccountType("省级");
|
||||
sysUserEntity.setActiveFlag(1);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(5L)));
|
||||
} else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) {
|
||||
List<StreetEntity> cityCodeList = streetDao.findByCityCode(countyCode);
|
||||
if (cityCodeList == null || cityCodeList.size() == 0) {
|
||||
@ -269,8 +350,9 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (cityNameList == null || cityNameList.size() == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
|
||||
}
|
||||
sysUserEntity.setActiveFlag(1);
|
||||
sysUserEntity.setAccountType("市级");
|
||||
sysUserEntity.setActiveFlag(1);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(5L)));
|
||||
} else {
|
||||
List<StreetEntity> countyCodeList = streetDao.findByCountyCode(countyCode);
|
||||
if (countyCodeList == null || countyCodeList.isEmpty()) {
|
||||
@ -280,12 +362,8 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (countyNameList == null || countyNameList.isEmpty()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale);
|
||||
}
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setAccountType("县级");
|
||||
}
|
||||
if (9 == countyCode.length()) {//街道账号7天后过期
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(7L)));
|
||||
} else {//省市区县账号5天后过期
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(5L)));
|
||||
}
|
||||
sysUserEntity.setStatusCode(0);
|
||||
|
@ -19,9 +19,9 @@ public class AliYunSmsUtils {
|
||||
//产品域名,开发者无需替换
|
||||
String domain = "dysmsapi.aliyuncs.com";
|
||||
//此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
|
||||
String accessKeyId = "LTAI5tMSjLfu8Xu2w6WeguFF";
|
||||
String accessKeyId = "LTAI5tMa5Va4CSwFwXxKpKfc";
|
||||
//修改成自己的
|
||||
String accessKeySecret = "hvqM5zpi72hvX4VXM71wq6AE0XYtDI";
|
||||
String accessKeySecret = "PIUhRNVcApBF3H8TzU8pM1ZI6fjvWQ";
|
||||
//可自助调整超时时间
|
||||
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
|
||||
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
|
||||
|
@ -1,25 +0,0 @@
|
||||
package com.xkrs.websocket.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||
|
||||
/**
|
||||
* websocket广播配置
|
||||
* @author xkrs
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebSocketMessageBroker
|
||||
public class WebSocketBrokerConfig implements WebSocketMessageBrokerConfigurer {
|
||||
@Override
|
||||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||
registry.addEndpoint("/endPointClientServer").withSockJS();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageBroker(MessageBrokerRegistry registry) {
|
||||
registry.enableSimpleBroker("/ws");
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.xkrs.websocket.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
@Configuration
|
||||
public class WebSocketConfig {
|
||||
@Bean
|
||||
public ServerEndpointExporter serverEndpointExporter(){
|
||||
return new ServerEndpointExporter();
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.xkrs.websocket.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class TestController {
|
||||
|
||||
@GetMapping("/hello")
|
||||
public String sayHello(){
|
||||
return "asdasd";
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.xkrs.websocket.controller.websocket;
|
||||
|
||||
import com.xkrs.websocket.service.WebSocketServer;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/socket")
|
||||
public class WebSocketController {
|
||||
|
||||
@GetMapping("/sendAll")
|
||||
public String sendAll(@RequestParam String msg) {
|
||||
WebSocketServer.broadInfo(msg);
|
||||
return "success";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sendOne", method = RequestMethod.GET)
|
||||
public String sendOne(@RequestParam String msg, @RequestParam String session) {
|
||||
WebSocketServer.sendMsg(msg, session);
|
||||
return "success";
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.xkrs.websocket.controller.websocketbroker;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
@Configuration
|
||||
public class ViewController extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/ws").setViewName("/ws");
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.xkrs.websocket.controller.websocketbroker;
|
||||
|
||||
import com.xkrs.websocket.websocket.ClientServerMessage;
|
||||
import com.xkrs.websocket.websocket.ServerClientMessage;
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
import org.springframework.messaging.handler.annotation.SendTo;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
@Controller
|
||||
public class WebSocketBrokerController {
|
||||
|
||||
@MessageMapping("/hello")
|
||||
@SendTo("/ws/getResponse")
|
||||
public ServerClientMessage say(ClientServerMessage message) throws InterruptedException {
|
||||
Thread.sleep(3000);
|
||||
return new ServerClientMessage("hello," + message.getName() + "!");
|
||||
}
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
package com.xkrs.websocket.service;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.websocket.*;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
@Component
|
||||
@ServerEndpoint(value = "/ws/asset")
|
||||
public class WebSocketServer {
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
System.out.println("websocketBroker loading......");
|
||||
}
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(WebSocketServer.class);
|
||||
private static final AtomicInteger ONLINE_COUNT = new AtomicInteger(0);
|
||||
private static CopyOnWriteArraySet<Session> sessionSet = new CopyOnWriteArraySet<>();
|
||||
|
||||
/**
|
||||
* 连接建立
|
||||
*/
|
||||
@OnOpen
|
||||
public void onOpen(Session session) {
|
||||
sessionSet.add(session);
|
||||
//在线加1
|
||||
int cnt = ONLINE_COUNT.incrementAndGet();
|
||||
//log.info("have a new connect:{}", cnt);
|
||||
//sendMsg(session, "connect success");
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接关闭
|
||||
*
|
||||
* @param session
|
||||
*/
|
||||
@OnClose
|
||||
public void onClose(Session session) {
|
||||
sessionSet.remove(session);
|
||||
//在线减1
|
||||
int cnt = ONLINE_COUNT.decrementAndGet();
|
||||
log.info("have a connect close:{}", cnt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收到客户端消息后调用的方法
|
||||
*
|
||||
* @param session
|
||||
* @param msg
|
||||
*/
|
||||
@OnMessage
|
||||
public void onMessage(String msg, Session session) {
|
||||
log.info("receive the msg:{}", msg);
|
||||
}
|
||||
|
||||
private static void sendMsg(Session session, String msg) {
|
||||
try {
|
||||
session.getBasicRemote().sendText(String.format(msg));
|
||||
} catch (IOException e) {
|
||||
log.error("发送信息出错:{}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendDate(Session session, Map map) {
|
||||
try {
|
||||
session.getBasicRemote().sendObject(map);
|
||||
} catch (IOException | EncodeException e) {
|
||||
log.error("发送信息出错:{}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定session发送
|
||||
*/
|
||||
public static void sendMsg(String msg, String sessionId) {
|
||||
Session session = null;
|
||||
for (Session s : sessionSet) {
|
||||
if (s.getId().equals(sessionId)) {
|
||||
session = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (session != null) {
|
||||
sendMsg(session, msg);
|
||||
} else {
|
||||
log.warn("not find your session");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 群发消息
|
||||
*/
|
||||
public static void broadInfo(String msg) {
|
||||
for (Session s : sessionSet) {
|
||||
synchronized (sessionSet){
|
||||
if (s.isOpen()) {
|
||||
sendMsg(s, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 群发map消息
|
||||
* @param map
|
||||
*/
|
||||
public static void broadInfoMap(Map map) {
|
||||
for (Session s : sessionSet) {
|
||||
if (s.isOpen()) {
|
||||
sendDate(s, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.xkrs.websocket.websocket;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
public class ClientServerMessage {
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.xkrs.websocket.websocket;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
public class ServerClientMessage {
|
||||
|
||||
public String getResponseMsg() {
|
||||
return responseMsg;
|
||||
}
|
||||
|
||||
public void setResponseMsg(String responseMsg) {
|
||||
this.responseMsg = responseMsg;
|
||||
}
|
||||
|
||||
private String responseMsg;
|
||||
|
||||
public ServerClientMessage(String responseMsg) {
|
||||
this.responseMsg = responseMsg;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
server.port = 6801
|
||||
|
||||
## 数据源配置
|
||||
spring.datasource.url = jdbc:postgresql://8.142.26.238:5432/fire_point
|
||||
spring.datasource.url = jdbc:postgresql://8.142.26.238:5432/fire_point_new
|
||||
spring.datasource.userName = fire_manage
|
||||
spring.datasource.password = fire456
|
||||
spring.datasource.driverClassName = org.postgresql.Driver
|
||||
|
Loading…
Reference in New Issue
Block a user