netty
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
package com.chaozhanggui.system.cashierservice.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
//处理前端改变购物车的行为,并记录
|
||||
public class ChangeHandler extends Handler {
|
||||
|
||||
@Override
|
||||
public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
List<JSONObject>> recordMap,
|
||||
AppWebSocketServer webSocke) throws IOException {
|
||||
|
||||
if (jsonObject.containsKey("change")) {
|
||||
ArrayList<JSONObject> jsonObjects = new ArrayList<>();
|
||||
jsonObjects.add(jsonObject);
|
||||
// producerMq.syncShopCar(jsonObjects);
|
||||
//记录每一次购物车变化的记录
|
||||
List<JSONObject> objects = recordMap.get(webSocke.getTableId());
|
||||
objects.add(jsonObject);
|
||||
} else {
|
||||
// 无法处理,传递给下一个处理器
|
||||
if (nextHandler != null) {
|
||||
nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//package com.chaozhanggui.system.cashierservice.config;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
////处理前端改变购物车的行为,并记录
|
||||
//public class ChangeHandler extends Handler {
|
||||
//
|
||||
// @Override
|
||||
// public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
// JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
// List<JSONObject>> recordMap,
|
||||
// AppWebSocketServer webSocke) throws IOException {
|
||||
//
|
||||
// if (jsonObject.containsKey("change")) {
|
||||
// ArrayList<JSONObject> jsonObjects = new ArrayList<>();
|
||||
// jsonObjects.add(jsonObject);
|
||||
//// producerMq.syncShopCar(jsonObjects);
|
||||
// //记录每一次购物车变化的记录
|
||||
// List<JSONObject> objects = recordMap.get(webSocke.getTableId());
|
||||
// objects.add(jsonObject);
|
||||
// } else {
|
||||
// // 无法处理,传递给下一个处理器
|
||||
// if (nextHandler != null) {
|
||||
// nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
package com.chaozhanggui.system.cashierservice.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
//处理前端订单已完成,把订单标志位置为false
|
||||
public class ClearHandler extends Handler{
|
||||
|
||||
@Override
|
||||
public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
List<JSONObject>> recordMap,
|
||||
AppWebSocketServer webSocke) throws IOException {
|
||||
if (jsonObject.containsKey("clear")) {
|
||||
if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
|
||||
List<AppWebSocketServer> serverList = webSocketMap.get(webSocke.getTableId());
|
||||
//遍历所有对象,把订单都改为未提交,为了下一次点餐
|
||||
serverList.forEach(m -> m.getCreateOrder().set(false));
|
||||
|
||||
}
|
||||
} else {
|
||||
// 无法处理,传递给下一个处理器
|
||||
if (nextHandler != null) {
|
||||
nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//package com.chaozhanggui.system.cashierservice.config;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
////处理前端订单已完成,把订单标志位置为false
|
||||
//public class ClearHandler extends Handler{
|
||||
//
|
||||
// @Override
|
||||
// public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
// JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
// List<JSONObject>> recordMap,
|
||||
// AppWebSocketServer webSocke) throws IOException {
|
||||
// if (jsonObject.containsKey("clear")) {
|
||||
// if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
|
||||
// List<AppWebSocketServer> serverList = webSocketMap.get(webSocke.getTableId());
|
||||
// //遍历所有对象,把订单都改为未提交,为了下一次点餐
|
||||
// serverList.forEach(m -> m.getCreateOrder().set(false));
|
||||
//
|
||||
// }
|
||||
// } else {
|
||||
// // 无法处理,传递给下一个处理器
|
||||
// if (nextHandler != null) {
|
||||
// nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,79 +1,79 @@
|
||||
package com.chaozhanggui.system.cashierservice.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
//处理前端创建订单
|
||||
public class CreateOrderHandler extends Handler{
|
||||
|
||||
@Override
|
||||
public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
List<JSONObject>> recordMap,
|
||||
AppWebSocketServer webSocke) throws IOException {
|
||||
|
||||
|
||||
if (jsonObject.containsKey("createOrdwebSockeer")) {
|
||||
if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
|
||||
List<AppWebSocketServer> serverList = webSocketMap.get(webSocke.getTableId());
|
||||
//有一个为true就说明已经有订单了
|
||||
if (serverList.stream().anyMatch(m -> m.getCreateOrder().get())) {
|
||||
webSocke.sendMessage("已有人提交订单,请稍后");
|
||||
return;
|
||||
}
|
||||
}
|
||||
synchronized (webSocke) {
|
||||
if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
|
||||
List<AppWebSocketServer> serverList = webSocketMap.get(webSocke.getTableId());
|
||||
//有一个为true就说明已经有订单了
|
||||
if (serverList.stream().anyMatch(m -> m.getCreateOrder().get())) {
|
||||
webSocke.sendMessage("已有人提交订单,请稍后");
|
||||
return;
|
||||
}
|
||||
|
||||
BigDecimal amount = new BigDecimal((Integer) jsonObject.get("amount"));
|
||||
JSONArray shopCarList = jsonObject.getJSONArray("shopCarList");
|
||||
String remark = jsonObject.get("remark").toString();
|
||||
|
||||
|
||||
// List<ShopListDto> list=shopCarList.toJavaList(ShopListDto.class);
|
||||
// //TODO 加个拦截加个shopid,抛出异常,前端展示
|
||||
// setShopId(list.get(0).getShopId());
|
||||
// try {
|
||||
// Result order = orderFeign.createOrder(new CreateOrderDto(Long.parseLong(webSocke.getTableId()), amount, list, remark));
|
||||
// if (order.getCode() == 200){
|
||||
// //通知清空购物车
|
||||
// AppSendInfo("订单提交成功", webSocke.getTableId());
|
||||
// //清空本地的购物记录
|
||||
// recordMap.get(webSocke.getTableId()).clear();
|
||||
// webSocke.getCreateOrder().set(true);
|
||||
// }else {
|
||||
// AppSendInfo("订单提交失败",webSocke.getTableId());
|
||||
// }
|
||||
//package com.chaozhanggui.system.cashierservice.config;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONArray;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.math.BigDecimal;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
////处理前端创建订单
|
||||
//public class CreateOrderHandler extends Handler{
|
||||
//
|
||||
// @Override
|
||||
// public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
// JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
// List<JSONObject>> recordMap,
|
||||
// AppWebSocketServer webSocke) throws IOException {
|
||||
//
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// AppSendInfo("订单提交失败",webSocke.getTableId());
|
||||
// if (jsonObject.containsKey("createOrdwebSockeer")) {
|
||||
// if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
|
||||
// List<AppWebSocketServer> serverList = webSocketMap.get(webSocke.getTableId());
|
||||
// //有一个为true就说明已经有订单了
|
||||
// if (serverList.stream().anyMatch(m -> m.getCreateOrder().get())) {
|
||||
// webSocke.sendMessage("已有人提交订单,请稍后");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// synchronized (webSocke) {
|
||||
// if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
|
||||
// List<AppWebSocketServer> serverList = webSocketMap.get(webSocke.getTableId());
|
||||
// //有一个为true就说明已经有订单了
|
||||
// if (serverList.stream().anyMatch(m -> m.getCreateOrder().get())) {
|
||||
// webSocke.sendMessage("已有人提交订单,请稍后");
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 无法处理,传递给下一个处理器
|
||||
if (nextHandler != null) {
|
||||
nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// BigDecimal amount = new BigDecimal((Integer) jsonObject.get("amount"));
|
||||
// JSONArray shopCarList = jsonObject.getJSONArray("shopCarList");
|
||||
// String remark = jsonObject.get("remark").toString();
|
||||
//
|
||||
//
|
||||
//// List<ShopListDto> list=shopCarList.toJavaList(ShopListDto.class);
|
||||
//// //TODO 加个拦截加个shopid,抛出异常,前端展示
|
||||
//// setShopId(list.get(0).getShopId());
|
||||
//// try {
|
||||
//// Result order = orderFeign.createOrder(new CreateOrderDto(Long.parseLong(webSocke.getTableId()), amount, list, remark));
|
||||
//// if (order.getCode() == 200){
|
||||
//// //通知清空购物车
|
||||
//// AppSendInfo("订单提交成功", webSocke.getTableId());
|
||||
//// //清空本地的购物记录
|
||||
//// recordMap.get(webSocke.getTableId()).clear();
|
||||
//// webSocke.getCreateOrder().set(true);
|
||||
//// }else {
|
||||
//// AppSendInfo("订单提交失败",webSocke.getTableId());
|
||||
//// }
|
||||
////
|
||||
////
|
||||
//// }catch (Exception e){
|
||||
//// e.printStackTrace();
|
||||
//// AppSendInfo("订单提交失败",webSocke.getTableId());
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// // 无法处理,传递给下一个处理器
|
||||
// if (nextHandler != null) {
|
||||
// nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package com.chaozhanggui.system.cashierservice.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class Handler {
|
||||
protected Handler nextHandler;
|
||||
|
||||
|
||||
public Handler addNextHandler(Handler handler) {
|
||||
this.nextHandler = handler;
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public abstract void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
List<JSONObject>> recordMap,
|
||||
AppWebSocketServer webSocke) throws IOException;
|
||||
}
|
||||
//package com.chaozhanggui.system.cashierservice.config;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
//public abstract class Handler {
|
||||
// protected Handler nextHandler;
|
||||
//
|
||||
//
|
||||
// public Handler addNextHandler(Handler handler) {
|
||||
// this.nextHandler = handler;
|
||||
// return handler;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// public abstract void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
// JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
// List<JSONObject>> recordMap,
|
||||
// AppWebSocketServer webSocke) throws IOException;
|
||||
//}
|
||||
@@ -1,30 +1,30 @@
|
||||
package com.chaozhanggui.system.cashierservice.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer.AppSendInfo;
|
||||
|
||||
|
||||
//兜底处理器
|
||||
public class OtherHandler extends Handler{
|
||||
@Override
|
||||
public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
JSONObject jsonObject,
|
||||
ConcurrentHashMap<String, List<JSONObject>> recordMap,
|
||||
AppWebSocketServer webSocke) throws IOException {
|
||||
|
||||
//传送给对应tableId用户的websocket
|
||||
if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
|
||||
AppSendInfo("1", webSocke.getTableId(),"",false);
|
||||
|
||||
} else {
|
||||
System.out.println("请求的tableId:" + webSocke.getTableId() + "不在该服务器上");
|
||||
}
|
||||
}
|
||||
}
|
||||
//package com.chaozhanggui.system.cashierservice.config;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
//import static com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer.AppSendInfo;
|
||||
//
|
||||
//
|
||||
////兜底处理器
|
||||
//public class OtherHandler extends Handler{
|
||||
// @Override
|
||||
// public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
// JSONObject jsonObject,
|
||||
// ConcurrentHashMap<String, List<JSONObject>> recordMap,
|
||||
// AppWebSocketServer webSocke) throws IOException {
|
||||
//
|
||||
// //传送给对应tableId用户的websocket
|
||||
// if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
|
||||
// AppSendInfo("1", webSocke.getTableId(),"",false);
|
||||
//
|
||||
// } else {
|
||||
// System.out.println("请求的tableId:" + webSocke.getTableId() + "不在该服务器上");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
package com.chaozhanggui.system.cashierservice.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
//处理前端初次扫码同步购物车
|
||||
public class SyncHandler extends Handler {
|
||||
|
||||
@Override
|
||||
public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
List<JSONObject>> recordMap,
|
||||
AppWebSocketServer webSocke) throws IOException {
|
||||
if (jsonObject.containsKey("sync")) {
|
||||
//这个是判断是否有这个桌号,也就是 是否有人点过餐
|
||||
|
||||
List<JSONObject> recordList = recordMap.get(webSocke.getTableId());
|
||||
//指定发送对象
|
||||
if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId()) && recordList != null) {
|
||||
List<AppWebSocketServer> serverList = webSocketMap.get(webSocke.getTableId());
|
||||
for (AppWebSocketServer server : serverList) {
|
||||
if (server.getSync().get()) {
|
||||
server.sendMessage(recordList);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
ArrayList<JSONObject> objects = new ArrayList<>();
|
||||
recordMap.put(webSocke.getTableId(), objects);
|
||||
}
|
||||
webSocke.getSync().set(!webSocke.getSync().get());
|
||||
|
||||
} else {
|
||||
// 无法处理,传递给下一个处理器
|
||||
if (nextHandler != null) {
|
||||
nextHandler.handleRequest(webSocketMap, jsonObject, recordMap, webSocke);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//package com.chaozhanggui.system.cashierservice.config;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
////处理前端初次扫码同步购物车
|
||||
//public class SyncHandler extends Handler {
|
||||
//
|
||||
// @Override
|
||||
// public void handleRequest(ConcurrentHashMap<String, List<AppWebSocketServer>> webSocketMap,
|
||||
// JSONObject jsonObject, ConcurrentHashMap<String,
|
||||
// List<JSONObject>> recordMap,
|
||||
// AppWebSocketServer webSocke) throws IOException {
|
||||
// if (jsonObject.containsKey("sync")) {
|
||||
// //这个是判断是否有这个桌号,也就是 是否有人点过餐
|
||||
//
|
||||
// List<JSONObject> recordList = recordMap.get(webSocke.getTableId());
|
||||
// //指定发送对象
|
||||
// if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId()) && recordList != null) {
|
||||
// List<AppWebSocketServer> serverList = webSocketMap.get(webSocke.getTableId());
|
||||
// for (AppWebSocketServer server : serverList) {
|
||||
// if (server.getSync().get()) {
|
||||
// server.sendMessage(recordList);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// } else {
|
||||
// ArrayList<JSONObject> objects = new ArrayList<>();
|
||||
// recordMap.put(webSocke.getTableId(), objects);
|
||||
// }
|
||||
// webSocke.getSync().set(!webSocke.getSync().get());
|
||||
//
|
||||
// } else {
|
||||
// // 无法处理,传递给下一个处理器
|
||||
// if (nextHandler != null) {
|
||||
// nextHandler.handleRequest(webSocketMap, jsonObject, recordMap, webSocke);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user