Browse Source

改变目录

master
刘力 3 years ago
parent
commit
7827730ae5
  1. 6
      APIService/pom.xml
  2. 19
      APIService/src/main/java/com/storeroom/config/WebSocketConfig.java
  3. 5
      APIService/src/main/java/com/storeroom/controller/TestApiServiceController.java
  4. 93
      APIService/src/main/java/com/storeroom/controller/WebSoketService.java
  5. 11
      APIService/src/main/java/com/storeroom/service/impl/ApiServiceImpl.java
  6. 5
      storeroom/pom.xml
  7. 2
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/config/websoket/NettyConfig.java
  8. 2
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/config/websoket/NettyServer.java
  9. 3
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/config/websoket/WebSocketHandler.java
  10. 4
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/controller/PushController.java
  11. 2
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/PushService.java
  12. 7
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/PushServiceImpl.java
  13. 2
      system/src/main/resources/application.yml

6
APIService/pom.xml

@ -29,11 +29,7 @@
<version>3.5.2</version> <version>3.5.2</version>
</dependency> </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.33.Final</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

19
APIService/src/main/java/com/storeroom/config/WebSocketConfig.java

@ -1,19 +0,0 @@
package com.storeroom.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Service
@Configuration
@EnableWebSocket
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter(){
return new ServerEndpointExporter();
}
}

5
APIService/src/main/java/com/storeroom/controller/TestApiServiceController.java

@ -22,6 +22,7 @@ import java.util.Set;
public class TestApiServiceController { public class TestApiServiceController {
private final ApiService apiService; private final ApiService apiService;
//private final PushService pushService;
@ApiOperation("获取库房token") @ApiOperation("获取库房token")
@AnonymousGetMapping("token") @AnonymousGetMapping("token")
@ -45,13 +46,15 @@ public class TestApiServiceController {
@ApiOperation("获取报警信息") @ApiOperation("获取报警信息")
@AnonymousGetMapping("getcuralarm") @AnonymousGetMapping("getcuralarm")
public ApiResponse<Object> getInfo() { public ApiResponse<Object> getInfo() {
Object objMsg = apiService.getAllDeviceAlarm();
//pushService.pushMsgToAll(objMsg.toString());
return ApiResponse.success(apiService.getAllDeviceAlarm()); return ApiResponse.success(apiService.getAllDeviceAlarm());
} }
@ApiOperation("获取设备监控参数实时值") @ApiOperation("获取设备监控参数实时值")
@AnonymousPostMapping("getrealtimedata") @AnonymousPostMapping("getrealtimedata")
public ApiResponse<Object> getrealtimedata(@RequestBody Set<String> deviceIds) { public ApiResponse<Object> getrealtimedata(@RequestBody Set<String> deviceIds) {
;
;
return ApiResponse.success(apiService.getRealTimeData(deviceIds)); return ApiResponse.success(apiService.getRealTimeData(deviceIds));
} }
} }

93
APIService/src/main/java/com/storeroom/controller/WebSoketService.java

@ -1,93 +0,0 @@
package com.storeroom.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
@Component
@ServerEndpoint(value = "/webSocket/{name}")
public class WebSoketService {
/**
* 与某个客户端的连接对话需要通过它来给客户端发送消息
*/
private Session session;
/**
* 标识当前连接客户端的用户名
*/
private String name;
/**
* 用于存所有的连接服务的客户端这个对象存储是安全的
*/
private static ConcurrentHashMap<String, WebSoketService> webSocketSet = new ConcurrentHashMap<>();
@OnOpen
public void OnOpen(Session session, @PathParam(value = "name") String name) {
this.session = session;
this.name = name;
// name是用来表示唯一客户端如果需要指定发送需要指定发送通过name来区分
webSocketSet.put(name, this);
log.info("[WebSocket] 连接成功,当前连接人数为:={}", webSocketSet.size());
}
@OnClose
public void OnClose() {
webSocketSet.remove(this.name);
log.info("[WebSocket] 退出成功,当前连接人数为:={}", webSocketSet.size());
}
@OnMessage
public void OnMessage(String message) {
log.info("[WebSocket] 收到消息:{}", message);
//判断是否需要指定发送具体规则自定义
if (message.indexOf("TOUSER") == 0) {
String name = message.substring(message.indexOf("TOUSER") + 6, message.indexOf(";"));
AppointSending(name, message.substring(message.indexOf(";") + 1, message.length()));
} else {
GroupSending(message);
}
}
/**
* 群发
*
* @param message
*/
public void GroupSending(String message) {
for (String name : webSocketSet.keySet()) {
try {
webSocketSet.get(name).session.getBasicRemote().sendText(message);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 指定发送
*
* @param name
* @param message
*/
public void AppointSending(String name, String message) {
try {
webSocketSet.get(name).session.getBasicRemote().sendText(message);
} catch (Exception e) {
e.printStackTrace();
}
}
}

11
APIService/src/main/java/com/storeroom/service/impl/ApiServiceImpl.java

@ -1,7 +1,6 @@
package com.storeroom.service.impl; package com.storeroom.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.storeroom.exception.BaseException; import com.storeroom.exception.BaseException;
@ -12,14 +11,12 @@ import com.storeroom.service.dto.RealTimeDataDto;
import com.storeroom.utils.FastjsonUtils; import com.storeroom.utils.FastjsonUtils;
import com.storeroom.utils.HttpUtils; import com.storeroom.utils.HttpUtils;
import com.storeroom.utils.RedisUtils; import com.storeroom.utils.RedisUtils;
import com.storeroom.utils.StringUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import okhttp3.*; import okhttp3.*;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
@ -116,8 +113,8 @@ public class ApiServiceImpl implements ApiService {
map.put("Authorization", "Bearer" + token + ""); map.put("Authorization", "Bearer" + token + "");
HttpResponse response = HttpUtils.doGet("http://jiton.8800.org:800", "/Api/Third/GetCurAlarm", "Get", map, null); HttpResponse response = HttpUtils.doGet("http://jiton.8800.org:800", "/Api/Third/GetCurAlarm", "Get", map, null);
if (response.getStatusLine().getStatusCode() == 200) { if (response.getStatusLine().getStatusCode() == 200) {
String s = EntityUtils.toString(response.getEntity());
Map<String, Object> dataMap = FastjsonUtils.toJavaMap(s);
String result = EntityUtils.toString(response.getEntity());
Map<String, Object> dataMap = FastjsonUtils.toJavaMap(result);
List<GetCurAlarmDto> list = new ArrayList<>(); List<GetCurAlarmDto> list = new ArrayList<>();
dataMap.forEach((k, v) -> { dataMap.forEach((k, v) -> {
if (k.equals("Data")) { if (k.equals("Data")) {
@ -141,7 +138,9 @@ public class ApiServiceImpl implements ApiService {
} }
} }
}); });
return list;
//PushServiceImpl pushService=new PushServiceImpl();
// pushService.pushMsgToAll(result);
return result;
} else { } else {
throw new BaseException("访问失败" + response.getStatusLine().getStatusCode() + ""); throw new BaseException("访问失败" + response.getStatusLine().getStatusCode() + "");
} }

5
storeroom/pom.xml

@ -28,6 +28,11 @@
<artifactId>APIService</artifactId> <artifactId>APIService</artifactId>
<version>1.0</version> <version>1.0</version>
</dependency> </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.33.Final</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

2
APIService/src/main/java/com/storeroom/config/NettyConfig.java → storeroom/src/main/java/com/storeroom/modules/storeroom3d/config/websoket/NettyConfig.java

@ -1,4 +1,4 @@
package com.storeroom.config;
package com.storeroom.modules.storeroom3d.config.websoket;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.ChannelGroup;

2
APIService/src/main/java/com/storeroom/common/NettyServer.java → storeroom/src/main/java/com/storeroom/modules/storeroom3d/config/websoket/NettyServer.java

@ -1,4 +1,4 @@
package com.storeroom.common;
package com.storeroom.modules.storeroom3d.config.websoket;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;

3
APIService/src/main/java/com/storeroom/common/WebSocketHandler.java → storeroom/src/main/java/com/storeroom/modules/storeroom3d/config/websoket/WebSocketHandler.java

@ -1,8 +1,7 @@
package com.storeroom.common;
package com.storeroom.modules.storeroom3d.config.websoket;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.storeroom.config.NettyConfig;
import io.netty.channel.*; import io.netty.channel.*;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleState;

4
APIService/src/main/java/com/storeroom/controller/PushController.java → storeroom/src/main/java/com/storeroom/modules/storeroom3d/controller/PushController.java

@ -1,8 +1,8 @@
package com.storeroom.controller;
package com.storeroom.modules.storeroom3d.controller;
import com.storeroom.annotaion.rest.AnonymousGetMapping; import com.storeroom.annotaion.rest.AnonymousGetMapping;
import com.storeroom.annotaion.rest.AnonymousPostMapping; import com.storeroom.annotaion.rest.AnonymousPostMapping;
import com.storeroom.service.PushService;
import com.storeroom.modules.storeroom3d.service.PushService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

2
APIService/src/main/java/com/storeroom/service/PushService.java → storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/PushService.java

@ -1,4 +1,4 @@
package com.storeroom.service;
package com.storeroom.modules.storeroom3d.service;
public interface PushService { public interface PushService {

7
APIService/src/main/java/com/storeroom/service/impl/PushServiceImpl.java → storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/PushServiceImpl.java

@ -1,7 +1,8 @@
package com.storeroom.service.impl;
package com.storeroom.modules.storeroom3d.service.impl;
import com.storeroom.config.NettyConfig;
import com.storeroom.service.PushService;
import com.storeroom.modules.storeroom3d.config.websoket.NettyConfig;
import com.storeroom.modules.storeroom3d.service.PushService;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;

2
system/src/main/resources/application.yml

@ -83,7 +83,7 @@ hand-held:
webSocket: webSocket:
netty: netty:
port: 7071 port: 7071
path: /wsServer
path: /webSocket
readerIdleTime: 30 #读空闲超时时间设置(Netty心跳检测配置) readerIdleTime: 30 #读空闲超时时间设置(Netty心跳检测配置)
writerIdleTime: 30 #写空闲超时时间设置(Netty心跳检测配置) writerIdleTime: 30 #写空闲超时时间设置(Netty心跳检测配置)
allIdleTime: 30 #读写空闲超时时间设置(Netty心跳检测配置) allIdleTime: 30 #读写空闲超时时间设置(Netty心跳检测配置)

Loading…
Cancel
Save