修改用户是否在充电sql
This commit is contained in:
parent
d1639320f6
commit
c597826849
@ -18,12 +18,13 @@ import javax.websocket.OnOpen;
|
|||||||
import javax.websocket.Session;
|
import javax.websocket.Session;
|
||||||
import javax.websocket.server.PathParam;
|
import javax.websocket.server.PathParam;
|
||||||
import javax.websocket.server.ServerEndpoint;
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yuyang
|
* @author yuyang
|
||||||
* @date 2021/8/9 14:33
|
* @date 2021/8/9 14:33
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@ServerEndpoint(value="/websocket/{userId}")
|
@ServerEndpoint(value = "/websocket/{userId}")
|
||||||
public class WebSocketController {
|
public class WebSocketController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,14 +45,16 @@ public class WebSocketController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 连接建立成功调用的方法
|
* 连接建立成功调用的方法
|
||||||
* @param session 可选的参数。session为与某个客户端的连接会话,需要通过它来给客户端发送数据
|
*
|
||||||
|
* @param session 可选的参数。session为与某个客户端的连接会话,需要通过它来给客户端发送数据
|
||||||
*/
|
*/
|
||||||
@OnOpen
|
@OnOpen
|
||||||
public void onOpen(@PathParam("userId") Long userId,Session session){
|
public void onOpen(@PathParam("userId") Long userId, Session session) {
|
||||||
this.userId =userId;
|
|
||||||
|
this.userId = userId;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
System.out.println("userId:"+userId);
|
System.out.println("userId:" + userId);
|
||||||
System.out.println("session:"+session);
|
System.out.println("session:" + session);
|
||||||
webSocketSet.add(this); //加入set中
|
webSocketSet.add(this); //加入set中
|
||||||
addOnlineCount(); //在线数加1
|
addOnlineCount(); //在线数加1
|
||||||
System.out.println("有新连接加入!当前在线人数为" + getOnlineCount());
|
System.out.println("有新连接加入!当前在线人数为" + getOnlineCount());
|
||||||
@ -61,41 +64,15 @@ public class WebSocketController {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 给指定的人发送消息
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
@OnMessage
|
|
||||||
public void sendToUser(String message) {
|
|
||||||
String sendUserno = message.split("[|]")[1];
|
|
||||||
String sendMessage = message.split("[|]")[0];
|
|
||||||
try {
|
|
||||||
if (webSocketSet.get(sendUserno) != null) {
|
|
||||||
webSocketSet.get(sendUserno).sendMessage("用户" + userno + "发来消息:" + " <br/> " + sendMessage);
|
|
||||||
} else {
|
|
||||||
System.out.println("当前用户不在线");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 获取当前时间
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String getNowTime() {
|
|
||||||
Date date = new Date();
|
|
||||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
String time = format.format(date);
|
|
||||||
return time;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 连接关闭调用的方法
|
* 连接关闭调用的方法
|
||||||
*/
|
*/
|
||||||
@OnClose
|
@OnClose
|
||||||
public void onClose(){
|
public void onClose() {
|
||||||
|
|
||||||
webSocketSet.remove(this); //从set中删除
|
webSocketSet.remove(this); //从set中删除
|
||||||
subOnlineCount(); //在线数减1
|
subOnlineCount(); //在线数减1
|
||||||
System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount());
|
System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount());
|
||||||
@ -103,15 +80,17 @@ public class WebSocketController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 收到客户端消息后调用的方法
|
* 收到客户端消息后调用的方法
|
||||||
|
*
|
||||||
* @param message 客户端发送过来的消息
|
* @param message 客户端发送过来的消息
|
||||||
* @param session 可选的参数
|
* @param session 可选的参数
|
||||||
*/
|
*/
|
||||||
@OnMessage
|
@OnMessage
|
||||||
public void onMessage(String message, Session session) {
|
public void onMessage(String message, Session session) {
|
||||||
System.out.println("收到:" + this.userId+"的消息");
|
|
||||||
|
System.out.println("收到:" + this.userId + "的消息");
|
||||||
System.out.println("来自客户端的消息:" + message);
|
System.out.println("来自客户端的消息:" + message);
|
||||||
try {
|
try {
|
||||||
message ="{\n" +
|
message = "{\n" +
|
||||||
" \"msg\": \"操作成功\",\n" +
|
" \"msg\": \"操作成功\",\n" +
|
||||||
" \"code\": 200,\n" +
|
" \"code\": 200,\n" +
|
||||||
" \"data\": {\n" +
|
" \"data\": {\n" +
|
||||||
@ -133,7 +112,7 @@ public class WebSocketController {
|
|||||||
ApplicationContext act = ApplicationContextRegister.getApplicationContext();
|
ApplicationContext act = ApplicationContextRegister.getApplicationContext();
|
||||||
RedisService redisService = act.getBean(RedisService.class);
|
RedisService redisService = act.getBean(RedisService.class);
|
||||||
Object cacheObject = redisService.getCacheObject("gun:1472583698524602.seqdec");
|
Object cacheObject = redisService.getCacheObject("gun:1472583698524602.seqdec");
|
||||||
System.out.println("cacheObject:"+cacheObject);
|
System.out.println("cacheObject:" + cacheObject);
|
||||||
|
|
||||||
this.session.getBasicRemote().sendText(message);
|
this.session.getBasicRemote().sendText(message);
|
||||||
|
|
||||||
@ -144,24 +123,30 @@ public class WebSocketController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发生错误时调用
|
* 发生错误时调用
|
||||||
|
*
|
||||||
* @param session
|
* @param session
|
||||||
* @param error
|
* @param error
|
||||||
*/
|
*/
|
||||||
@OnError
|
@OnError
|
||||||
public void onError(Session session, Throwable error){
|
public void onError(Session session, Throwable error) {
|
||||||
|
|
||||||
System.out.println("发生错误");
|
System.out.println("发生错误");
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized int getOnlineCount() {
|
public static synchronized int getOnlineCount() {
|
||||||
|
|
||||||
return onlineCount;
|
return onlineCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void addOnlineCount() {
|
public static synchronized void addOnlineCount() {
|
||||||
|
|
||||||
WebSocketController.onlineCount++;
|
WebSocketController.onlineCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void subOnlineCount() {
|
public static synchronized void subOnlineCount() {
|
||||||
|
|
||||||
WebSocketController.onlineCount--;
|
WebSocketController.onlineCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,7 +87,10 @@
|
|||||||
where del_flag=0
|
where del_flag=0
|
||||||
</select>
|
</select>
|
||||||
<select id="countXhpcRealTimeOrder" resultType="int">
|
<select id="countXhpcRealTimeOrder" resultType="int">
|
||||||
select count(real_time_order_id) from xhpc_real_time_order where user_id =#{userId} and type =2 order by create_time desc LIMIT 1
|
select
|
||||||
|
count(charge_order_id)
|
||||||
|
from xhpc_charge_order
|
||||||
|
where user_id =#{userId} and status=0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="countXhpcChargeOrder" resultType="int">
|
<select id="countXhpcChargeOrder" resultType="int">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user