3 changed files with 53 additions and 40 deletions
@ -1,40 +0,0 @@ |
|||
package com.xtong.zhbs.service; |
|||
|
|||
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.ServerEndpoint; |
|||
import java.io.IOException; |
|||
|
|||
/** |
|||
* 客流接口 |
|||
* websocket |
|||
*/ |
|||
@Component |
|||
@ServerEndpoint("/pl") |
|||
public class WsPassFlowService { |
|||
/** |
|||
* 发送消息 |
|||
* @param json |
|||
* @param session |
|||
* @throws IOException |
|||
*/ |
|||
@OnMessage |
|||
public void onMessage(String json, Session session) throws IOException { |
|||
session.getBasicRemote().sendText(json); |
|||
} |
|||
|
|||
@OnOpen |
|||
public void onOpen(){ |
|||
// do nothing
|
|||
System.out.println("web socket open"); |
|||
} |
|||
|
|||
@OnClose |
|||
public void onclose(){ |
|||
System.out.println("webscoket close"); |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
package com.xtong.zhbs.utils; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
public class AjaxResult { |
|||
/** |
|||
* 接口返回数据 |
|||
* @param msg |
|||
* @param usetime 耗费时间 |
|||
* @param dataList |
|||
* @return |
|||
*/ |
|||
public static JSONObject success(String msg, long usetime, List dataList){ |
|||
JSONObject result = new JSONObject(); |
|||
result.put("code",200); |
|||
result.put("msg",msg); |
|||
result.put("userTime",usetime); |
|||
result.put("data",dataList); |
|||
return result; |
|||
} |
|||
|
|||
public static JSONObject success(String msg, long usetime, Map map){ |
|||
JSONObject result = new JSONObject(); |
|||
result.put("code",200); |
|||
result.put("msg",msg); |
|||
result.put("userTime",usetime); |
|||
result.put("data",map); |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 异常信息 |
|||
* @param msg |
|||
* @return |
|||
*/ |
|||
public static JSONObject error(String msg){ |
|||
JSONObject result = new JSONObject(); |
|||
result.put("code",400); |
|||
result.put("msg",msg); |
|||
return result; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue