Merge branch 'lyf' of https://e.coding.net/g-cphe0354/shouyinjixitong/wx-cashier-service into lyf
# Conflicts: # src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java
This commit is contained in:
commit
117fd0dbd2
|
|
@ -1,35 +0,0 @@
|
|||
//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 +0,0 @@
|
|||
//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 +0,0 @@
|
|||
//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());
|
||||
//// }
|
||||
////
|
||||
////
|
||||
//// }catch (Exception e){
|
||||
//// e.printStackTrace();
|
||||
//// AppSendInfo("订单提交失败",webSocke.getTableId());
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// // 无法处理,传递给下一个处理器
|
||||
// if (nextHandler != null) {
|
||||
// nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
//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 +0,0 @@
|
|||
//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 +0,0 @@
|
|||
//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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package com.chaozhanggui.system.cashierservice.config;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import javax.websocket.Encoder;
|
||||
import javax.websocket.EndpointConfig;
|
||||
|
||||
/**
|
||||
* 为了websocket发送对象
|
||||
*/
|
||||
|
||||
public class WebSocketCustomEncoding implements Encoder.Text<Object> {
|
||||
// public String encode(Object vo) 这个就是指定发送的类型
|
||||
@Override
|
||||
public String encode(Object vo) {
|
||||
assert vo!=null;
|
||||
return JSON.toJSONString(vo);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init(EndpointConfig endpointConfig) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,20 +1,12 @@
|
|||
package com.chaozhanggui.system.cashierservice.netty.config;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.QueryStringDecoder;
|
||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
import io.netty.handler.codec.mqtt.*;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.Charsets;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -87,66 +79,6 @@ public abstract class NettyChannelHandlerAdapter extends ChannelInboundHandlerAd
|
|||
*/
|
||||
@Override
|
||||
public final void channelRead(ChannelHandlerContext ctx, Object msg) throws InterruptedException {
|
||||
if (msg instanceof MqttMessage) {
|
||||
MqttMessage mqttMessage = (MqttMessage) msg;
|
||||
|
||||
MqttMessageType messageType = mqttMessage.fixedHeader().messageType();
|
||||
switch (messageType) {
|
||||
case PINGREQ:
|
||||
sendPingResponse(ctx);
|
||||
break;
|
||||
case CONNECT:
|
||||
MqttConnectMessage connectMessage = (MqttConnectMessage) mqttMessage;
|
||||
MqttConnectVariableHeader variableHeader = connectMessage.variableHeader();
|
||||
String id = connectMessage.payload().clientIdentifier();
|
||||
channelRead(ctx, "CONNECT#"+id);
|
||||
// 发送连接回执
|
||||
sendConnectAck(ctx, connectMessage.variableHeader().isCleanSession());
|
||||
break;
|
||||
case SUBSCRIBE:
|
||||
// 处理接收到的 SUBSCRIBE 消息
|
||||
MqttSubscribeMessage subscribeMessage = (MqttSubscribeMessage) mqttMessage;
|
||||
List<MqttTopicSubscription> mqttTopicSubscriptions = subscribeMessage.payload().topicSubscriptions();
|
||||
if (mqttTopicSubscriptions != null && !mqttTopicSubscriptions.isEmpty()) {
|
||||
for (MqttTopicSubscription topicSubscription : mqttTopicSubscriptions) {
|
||||
String topicFilter = topicSubscription.topicName();
|
||||
MqttQoS qos = topicSubscription.qualityOfService();
|
||||
// log.info("订阅主题:" + topicFilter + ",服务质量等级:" + qos.name());
|
||||
}
|
||||
} else {
|
||||
// log.info("没有订阅主题。");
|
||||
}
|
||||
// 发送订阅回执
|
||||
sendSubscribeAck(ctx, subscribeMessage.variableHeader().messageId(), subscribeMessage.payload().topicSubscriptions());
|
||||
break;
|
||||
case PUBLISH:
|
||||
// 处理接收到的消息
|
||||
MqttPublishMessage publishMessage = (MqttPublishMessage) mqttMessage;
|
||||
int i = publishMessage.variableHeader().packetId();
|
||||
String topic = publishMessage.variableHeader().topicName();
|
||||
// 提取发布消息的数据和主题等信息
|
||||
ByteBuf publishPayload = publishMessage.payload();
|
||||
String payloadContent = publishPayload.toString(CharsetUtil.UTF_8); // 将数据转换为字符串
|
||||
log.info("主题:"+topic+"数据:"+payloadContent);
|
||||
if (i >= 1 && i <= 65535) {
|
||||
sendPublishAck(ctx, publishMessage);
|
||||
} else {
|
||||
// log.info("无效消息id");
|
||||
}
|
||||
channelRead(ctx, topic+"#"+payloadContent);
|
||||
break;
|
||||
case DISCONNECT:
|
||||
ctx.close();
|
||||
break;
|
||||
case PUBACK:
|
||||
MqttPubAckMessage pubAckMessage = (MqttPubAckMessage) mqttMessage;
|
||||
int messageId = pubAckMessage.variableHeader().messageId();
|
||||
break;
|
||||
default:
|
||||
log.info("收到其他类型的消息:" + messageType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (msg instanceof TextWebSocketFrame) {
|
||||
String text =((TextWebSocketFrame) msg).text(); // 获取消息内容
|
||||
channelRead(ctx, text);
|
||||
|
|
@ -166,52 +98,6 @@ public abstract class NettyChannelHandlerAdapter extends ChannelInboundHandlerAd
|
|||
}
|
||||
}
|
||||
|
||||
private void sendConnectAck(ChannelHandlerContext ctx, boolean cleanSession) {
|
||||
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
|
||||
MqttConnAckVariableHeader variableHeader = new MqttConnAckVariableHeader(MqttConnectReturnCode.CONNECTION_ACCEPTED, cleanSession);
|
||||
MqttConnAckMessage connAckMessage = new MqttConnAckMessage(fixedHeader, variableHeader);
|
||||
|
||||
ctx.writeAndFlush(connAckMessage);
|
||||
}
|
||||
|
||||
private void sendPingResponse(ChannelHandlerContext ctx) {
|
||||
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0);
|
||||
MqttMessage pingRespMessage = new MqttMessage(fixedHeader);
|
||||
ctx.writeAndFlush(pingRespMessage);
|
||||
}
|
||||
|
||||
private void sendPublishAck(ChannelHandlerContext ctx, MqttPublishMessage publishMessage) {
|
||||
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBACK, false, MqttQoS.AT_LEAST_ONCE, false, 0);
|
||||
MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(publishMessage.variableHeader().packetId());
|
||||
MqttPubAckMessage pubAckMessage = new MqttPubAckMessage(fixedHeader, variableHeader);
|
||||
ctx.writeAndFlush(pubAckMessage);
|
||||
}
|
||||
|
||||
private void sendSubscribeAck(ChannelHandlerContext ctx, int messageId, List<MqttTopicSubscription> subscriptions) {
|
||||
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_LEAST_ONCE, false, 0);
|
||||
MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);
|
||||
MqttSubAckPayload payload = createSubAckPayload(subscriptions); // 自定义方法,创建订阅回执的有效载荷
|
||||
|
||||
MqttSubAckMessage subAckMessage = new MqttSubAckMessage(fixedHeader, variableHeader, payload);
|
||||
|
||||
ctx.writeAndFlush(subAckMessage);
|
||||
}
|
||||
|
||||
private MqttSubAckPayload createSubAckPayload(List<MqttTopicSubscription> subscriptions) {
|
||||
List<Integer> grantedQosLevels = new ArrayList<>();
|
||||
for (MqttTopicSubscription subscription : subscriptions) {
|
||||
int qosLevel = getGrantedQosLevel(subscription); // 自定义方法,根据订阅主题获取授予的 QoS 等级
|
||||
grantedQosLevels.add(qosLevel);
|
||||
}
|
||||
return new MqttSubAckPayload(grantedQosLevels);
|
||||
}
|
||||
private int getGrantedQosLevel(MqttTopicSubscription subscription) {
|
||||
// 根据实际情况对订阅主题进行处理,并返回授予的 QoS 等级
|
||||
|
||||
// 这里我们简单地返回 1,即“至少一次”QoS 等级
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务器接受客户端的数据信息时触发
|
||||
*
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
import com.chaozhanggui.system.cashierservice.service.CartService1;
|
||||
import com.chaozhanggui.system.cashierservice.service.CartService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
|
|
@ -25,7 +25,7 @@ public class CartConsumer {
|
|||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private CartService1 cartService;
|
||||
private CartService cartService;
|
||||
@RabbitHandler
|
||||
@RabbitListener(queues = {"${queue}"})
|
||||
public void listener(String message) {
|
||||
|
|
@ -54,16 +54,6 @@ public class CartConsumer {
|
|||
cartService.createOrder(jsonObject);
|
||||
}
|
||||
}
|
||||
// else if(jsonObject.getString("type").equals("pendingOrder")){
|
||||
// String cartDetail = redisUtil.getMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId));
|
||||
// if (StringUtils.isEmpty(cartDetail)){
|
||||
// throw new MsgException("购物车为空无法下单");
|
||||
// }
|
||||
// JSONArray array = JSON.parseArray(cartDetail);
|
||||
// if (array.size() > 0){
|
||||
// cartService.pendingOrder(jsonObject);
|
||||
// }
|
||||
// }
|
||||
else if(jsonObject.getString("type").equals("clearCart")){
|
||||
cartService.clearCart(jsonObject);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,359 +0,0 @@
|
|||
//package com.chaozhanggui.system.cashierservice.socket;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.alibaba.fastjson.JSONArray;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.chaozhanggui.system.cashierservice.config.WebSocketCustomEncoding;
|
||||
//import com.chaozhanggui.system.cashierservice.dao.TbShopTableMapper;
|
||||
//import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
|
||||
//import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
|
||||
//import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
//import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
||||
//import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
//import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
//import com.chaozhanggui.system.cashierservice.util.JSONUtil;
|
||||
//import com.chaozhanggui.system.cashierservice.util.SpringUtils;
|
||||
//import lombok.Data;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.PostConstruct;
|
||||
//import javax.annotation.Resource;
|
||||
//import javax.websocket.*;
|
||||
//import javax.websocket.server.PathParam;
|
||||
//import javax.websocket.server.ServerEndpoint;
|
||||
//import java.io.*;
|
||||
//import java.math.BigDecimal;
|
||||
//import java.util.*;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//import java.util.concurrent.atomic.AtomicBoolean;
|
||||
//
|
||||
//@ServerEndpoint(value = "/websocket/table", encoders = WebSocketCustomEncoding.class)
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//@Data
|
||||
//public class AppWebSocketServer {
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private RabbitProducer a;
|
||||
//
|
||||
// //注入为空
|
||||
// public static RabbitProducer rabbitProducer;
|
||||
//
|
||||
// @PostConstruct
|
||||
// public void b() {
|
||||
// rabbitProducer = this.a;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private RedisUtil redisUtils = SpringUtils.getBean(RedisUtil.class);
|
||||
// private TbShopTableMapper shopTableMapper = SpringUtils.getBean(TbShopTableMapper.class);
|
||||
// /**
|
||||
// * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
|
||||
// */
|
||||
// //一个 AppWebSocketServer 就是一个用户,一个tableId下有一个 List<AppWebSocketServer> 也就是多个用户
|
||||
// private static HashMap<String, ConcurrentHashMap<String, AppWebSocketServer>> webSocketMap = new HashMap<>();
|
||||
// public static ConcurrentHashMap<String, Set<String>> userMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// /**
|
||||
// * 与某个客户端的连接会话,需要通过它来给客户端发送数据
|
||||
// */
|
||||
// private Session session;
|
||||
//
|
||||
// /**
|
||||
// * 接收tableId
|
||||
// */
|
||||
// private String tableId = "";
|
||||
// private String shopId = "";
|
||||
// private String userId = "";
|
||||
//
|
||||
// /**
|
||||
// * 用来标识这个用户需要接收同步的购物车信息
|
||||
// */
|
||||
// private volatile AtomicBoolean sync = new AtomicBoolean(true);
|
||||
//
|
||||
// private volatile AtomicBoolean createOrder = new AtomicBoolean(false);
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 连接建立成功调用的方法
|
||||
// */
|
||||
// @OnOpen
|
||||
// public void onOpen(Session session) {
|
||||
// this.session = session;
|
||||
// log.info("建立连接开始");
|
||||
//// public void onOpen(Session session, @PathParam("tableId") String tableId, @PathParam("shopId") String shopId, @PathParam("userId") String userId) {
|
||||
// Map<String, String> queryParams = getParamMap();
|
||||
// String tableId = queryParams.get("tableId");
|
||||
// String shopId = queryParams.get("shopId");
|
||||
// String userId = queryParams.get("userId");
|
||||
//
|
||||
// log.info("建立连接参数 tableId:{} shopId:{} userId:{} sessionId:{}",tableId,shopId,userId,session.getId());
|
||||
// this.tableId = tableId;
|
||||
// this.shopId = shopId;
|
||||
// this.userId = userId;
|
||||
// try {
|
||||
// String key=tableId + "-" + shopId;
|
||||
// TbShopTable shopTable = shopTableMapper.selectQRcode(tableId);
|
||||
// if (Objects.isNull(shopTable)) {
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "fail");
|
||||
// jsonObject1.put("msg", "桌码不存在");
|
||||
// jsonObject1.put("type", "addCart");
|
||||
// jsonObject1.put("data", new ArrayList<>());
|
||||
// jsonObject1.put("amount", BigDecimal.ZERO);
|
||||
// sendMessage(jsonObject1);
|
||||
// onClose();
|
||||
// }
|
||||
//
|
||||
// if (webSocketMap.containsKey(key)) {
|
||||
// ConcurrentHashMap<String, AppWebSocketServer> userSocketMap = webSocketMap.get(key);
|
||||
// // 在放置新条目之前检查并清除同名userId的数据
|
||||
// userSocketMap.put(userId,this);
|
||||
// } else {
|
||||
// ConcurrentHashMap<String, AppWebSocketServer> userSocketMap=new ConcurrentHashMap<>();
|
||||
// userSocketMap.put(userId,this);
|
||||
// webSocketMap.put(key,userSocketMap);
|
||||
// }
|
||||
//
|
||||
// if (userMap.containsKey(tableId)) {
|
||||
// Set<String> userSet = userMap.get(tableId);
|
||||
// userSet.add(userId);
|
||||
// } else {
|
||||
// Set<String> userSet = new HashSet<>();
|
||||
// userSet.add(userId);
|
||||
// userMap.put(tableId,userSet);
|
||||
// }
|
||||
// String mes = redisUtils.getMessage(RedisCst.TABLE_CART.concat(key));
|
||||
// if (StringUtils.isEmpty(mes)) {
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "success");
|
||||
// jsonObject1.put("msg", "成功");
|
||||
// jsonObject1.put("type", "addCart");
|
||||
// jsonObject1.put("data", new ArrayList<>());
|
||||
// jsonObject1.put("amount", BigDecimal.ZERO);
|
||||
// sendMessage(jsonObject1);
|
||||
// } else {
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "success");
|
||||
// jsonObject1.put("msg", "成功");
|
||||
// jsonObject1.put("type", "addCart");
|
||||
// BigDecimal amount = BigDecimal.ZERO;
|
||||
// JSONArray jsonArray = JSON.parseArray(redisUtils.getMessage(RedisCst.TABLE_CART.concat(key)));
|
||||
// for (int i = 0; i < jsonArray.size(); i++) {
|
||||
// JSONObject object = jsonArray.getJSONObject(i);
|
||||
// amount = amount.add(object.getBigDecimal("totalAmount"));
|
||||
// }
|
||||
// jsonObject1.put("amount", amount);
|
||||
// jsonObject1.put("data", jsonArray);
|
||||
// sendMessage(jsonObject1);
|
||||
// }
|
||||
//// sendMessage(recordMap.get(tableId));
|
||||
// } catch (IOException e) {
|
||||
// log.error("用户:" + tableId + ",网络异常!!!!!!");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 连接关闭调用的方法
|
||||
// */
|
||||
// @OnClose
|
||||
// public void onClose() throws IOException {
|
||||
// String key=tableId + "-" + shopId;
|
||||
// log.info("触发关闭操作 key为:{} userId为:{} sessionId:{}",key,userId,session.getId());
|
||||
// if (webSocketMap.containsKey(key)) {
|
||||
// ConcurrentHashMap<String, AppWebSocketServer> userSocketMap = webSocketMap.get(key);
|
||||
// // 在放置新条目之前检查并清除同名userId的数据
|
||||
// userSocketMap.remove(userId);
|
||||
// log.info("存在的 {}用户数3为:{}",key,userSocketMap.size());
|
||||
// }
|
||||
// if (userMap.containsKey(tableId)){
|
||||
// Set<String> userSet = userMap.get(tableId);
|
||||
// userSet.remove(userId);
|
||||
//// if (userSet.isEmpty()){
|
||||
//// userMap.remove(tableId + "-" + shopId);
|
||||
//// }
|
||||
// }
|
||||
// session.close();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 收到客户端消息后调用的方法
|
||||
// *
|
||||
// * @param message 客户端发送过来的消息
|
||||
// */
|
||||
// @OnMessage
|
||||
// public void onMessage(String message, Session session) {
|
||||
// log.info("接收消息 tableId:{} shopId:{} userId:{} message:{} sessionId:{}",this.tableId,this.shopId,this.userId,message,session.getId());
|
||||
// //可以群发消息
|
||||
// //消息保存到数据库、redis
|
||||
// if (StringUtils.isNotBlank(message) && !message.equals("undefined")) {
|
||||
// try {
|
||||
// //解析发送的报文
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// if (StringUtils.isNotEmpty(message)) {
|
||||
// jsonObject = JSONObject.parseObject(message);
|
||||
// }
|
||||
// //追加发送人(防止串改)
|
||||
// jsonObject.put("tableId", this.tableId);
|
||||
// jsonObject.put("shopId", this.shopId);
|
||||
// if ("sku".equals(jsonObject.getString("type"))){
|
||||
// boolean exist = redisUtils.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)));
|
||||
// Integer num = 0;
|
||||
// if (exist){
|
||||
// JSONArray array = JSON.parseArray(redisUtils.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
|
||||
// for (int i = 0; i < array.size(); i++) {
|
||||
// JSONObject object = array.getJSONObject(i);
|
||||
// if (object.getString("skuId").equals(jsonObject.getString("skuId"))) {
|
||||
// num = object.getIntValue("totalNumber");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "success");
|
||||
// jsonObject1.put("msg", "成功");
|
||||
// jsonObject1.put("type", "sku");
|
||||
// jsonObject1.put("data", new ArrayList<>());
|
||||
// jsonObject1.put("amount", num);
|
||||
// sendMessage(jsonObject1);
|
||||
// }else {
|
||||
// rabbitProducer.putCart(jsonObject.toJSONString());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("接收消息 处理失败",e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 发生错误时候
|
||||
// *
|
||||
// * @param session
|
||||
// * @param error
|
||||
// */
|
||||
// @OnError
|
||||
// public void onError(Session session, Throwable error) throws IOException {
|
||||
// log.error("用户错误:" + this.tableId + ",原因:" + error.getMessage());
|
||||
//// error.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 实现服务器主动推送
|
||||
// */
|
||||
// public void sendMessage(Object message) throws IOException {
|
||||
// //加入线程锁
|
||||
// synchronized (session) {
|
||||
// try {
|
||||
// log.info("发送消息 session:{}",session.getId());
|
||||
// //同步发送信息
|
||||
// this.session.getBasicRemote().sendObject(message);
|
||||
// } catch (Exception e) {
|
||||
// log.error("服务器推送失败:" + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 发送自定义消息
|
||||
// * */
|
||||
// /**
|
||||
// * 发送自定义消息
|
||||
// *
|
||||
// * @param message 发送的信息
|
||||
// * @param tableId 如果为null默认发送所有 tableId-shopId(桌码-店铺ID)
|
||||
// * @param userId userFlag为 true时 必填
|
||||
// * @param userFlag true 发送给指定用户 false 群发
|
||||
// * @throws IOException
|
||||
// */
|
||||
// public static void AppSendInfo(Object message, String tableId,String userId, boolean userFlag) throws IOException {
|
||||
// log.info("发送消息 tableId:{} userId:{} userFlag:{} message:{}",tableId,userId,userFlag,JSONUtil.toJSONString(message));
|
||||
// if (userFlag) {
|
||||
// if (webSocketMap.containsKey(tableId)) {
|
||||
// ConcurrentHashMap<String, AppWebSocketServer> userSocketMap = webSocketMap.get(tableId);
|
||||
// if(!userSocketMap.isEmpty()){
|
||||
// if(StringUtils.isNotBlank(userId)){
|
||||
// userSocketMap.get(userId).sendMessage(message);
|
||||
// }
|
||||
// }else {
|
||||
// log.error("请求的tableId:"+tableId+"用户连接为空");
|
||||
// }
|
||||
// }else {
|
||||
// log.error("请求的tableId:"+tableId+" userId:" + userId + "不在该服务器上");
|
||||
// }
|
||||
// } else {
|
||||
// if (StringUtils.isEmpty(tableId)) {
|
||||
// // 向所有用户发送信息
|
||||
// for (ConcurrentHashMap<String, AppWebSocketServer> value : webSocketMap.values()) {
|
||||
// for (AppWebSocketServer server : value.values()) {
|
||||
// server.sendMessage(message);
|
||||
// }
|
||||
// }
|
||||
// } else if (webSocketMap.containsKey(tableId)) {
|
||||
// log.info("发送消息的webSocketMap:存在");
|
||||
// // 对应桌码发送消息
|
||||
// for (AppWebSocketServer server : webSocketMap.get(tableId).values()) {
|
||||
// log.info("发送消息的webSocketMap 次数:");
|
||||
// server.sendMessage(message);
|
||||
// }
|
||||
// } else {
|
||||
// log.error("请求的tableId:" + tableId + "不在该服务器上");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public Map<String,String> getParamMap(){
|
||||
// // 获取连接建立时传递的参数
|
||||
// Map<String, List<String>> queryParams = session.getRequestParameterMap();
|
||||
// // 创建新的Map来存储转换后的参数
|
||||
// Map<String, String> parameterMap = new HashMap<>();
|
||||
//
|
||||
// // 遍历原始参数Map的键值对
|
||||
// for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
|
||||
// String key = entry.getKey();
|
||||
// List<String> values = entry.getValue();
|
||||
//
|
||||
// // 如果值列表不为空,则将第一个值作为键的值存储在新的Map中
|
||||
// if (!values.isEmpty()) {
|
||||
// String value = values.get(0);
|
||||
// parameterMap.put(key, value);
|
||||
// }
|
||||
// }
|
||||
// return parameterMap;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//// public static synchronized ConcurrentHashMap<String, Set<AppWebSocketServer>> getWebSocketMap() {
|
||||
//// return AppWebSocketServer.webSocketMap;
|
||||
//// }
|
||||
////
|
||||
//// public static synchronized ConcurrentHashMap<String, List<JSONObject>> getRecordMap() {
|
||||
//// return AppWebSocketServer.recordMap;
|
||||
//// }
|
||||
//// private byte[] serialize(Object obj) {
|
||||
//// try {
|
||||
//// ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
//// ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||
//// oos.writeObject(obj);
|
||||
//// return bos.toByteArray();
|
||||
//// } catch (IOException e) {
|
||||
//// e.printStackTrace();
|
||||
//// return null;
|
||||
//// }
|
||||
//// }
|
||||
////
|
||||
//// private Object deserialize(byte[] bytes) {
|
||||
//// try {
|
||||
//// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
|
||||
//// ObjectInputStream ois = new ObjectInputStream(bis);
|
||||
//// return ois.readObject();
|
||||
//// } catch (IOException | ClassNotFoundException e) {
|
||||
//// e.printStackTrace();
|
||||
//// return null;
|
||||
//// }
|
||||
//// }
|
||||
//}
|
||||
|
|
@ -1,311 +0,0 @@
|
|||
//package com.chaozhanggui.system.cashierservice.socket;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.alibaba.fastjson.JSONArray;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.chaozhanggui.system.cashierservice.config.WebSocketCustomEncoding;
|
||||
//import com.chaozhanggui.system.cashierservice.dao.TbShopTableMapper;
|
||||
//import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
|
||||
//import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
||||
//import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
//import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
//import com.chaozhanggui.system.cashierservice.util.SpringUtils;
|
||||
//import lombok.Data;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.PostConstruct;
|
||||
//import javax.annotation.Resource;
|
||||
//import javax.websocket.*;
|
||||
//import javax.websocket.server.PathParam;
|
||||
//import javax.websocket.server.ServerEndpoint;
|
||||
//import java.io.IOException;
|
||||
//import java.math.BigDecimal;
|
||||
//import java.util.*;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//import java.util.concurrent.atomic.AtomicBoolean;
|
||||
//
|
||||
//@ServerEndpoint(value = "/websocket/table/{tableId}/{shopId}/{userId}", encoders = WebSocketCustomEncoding.class)
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//@Data
|
||||
//public class AppWebSocketServerCopy {
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private RabbitProducer a;
|
||||
//
|
||||
// //注入为空
|
||||
// public static RabbitProducer rabbitProducer;
|
||||
//
|
||||
// @PostConstruct
|
||||
// public void b() {
|
||||
// rabbitProducer = this.a;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private RedisUtil redisUtils = SpringUtils.getBean(RedisUtil.class);
|
||||
// private TbShopTableMapper shopTableMapper = SpringUtils.getBean(TbShopTableMapper.class);
|
||||
// /**
|
||||
// * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
|
||||
// */
|
||||
// //一个 AppWebSocketServer 就是一个用户,一个tableId下有一个 List<AppWebSocketServer> 也就是多个用户
|
||||
// private static ConcurrentHashMap<String, List<AppWebSocketServerCopy>> webSocketMap = new ConcurrentHashMap<>();
|
||||
// public static ConcurrentHashMap<String, Set<String>> userMap = new ConcurrentHashMap<>();
|
||||
// private static ConcurrentHashMap<String, AppWebSocketServerCopy> userSocketMap = new ConcurrentHashMap<>();
|
||||
// //购物车的记录,用于第一次扫码的人同步购物车
|
||||
// private static ConcurrentHashMap<String, List<JSONObject>> recordMap = new ConcurrentHashMap<>();
|
||||
// private static ConcurrentHashMap<String, Session> sessionMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// /**
|
||||
// * 与某个客户端的连接会话,需要通过它来给客户端发送数据
|
||||
// */
|
||||
// private Session session;
|
||||
//
|
||||
// /**
|
||||
// * 接收tableId
|
||||
// */
|
||||
// private String tableId = "";
|
||||
// private String shopId = "";
|
||||
// private String userId = "";
|
||||
//
|
||||
// /**
|
||||
// * 用来标识这个用户需要接收同步的购物车信息
|
||||
// */
|
||||
// private volatile AtomicBoolean sync = new AtomicBoolean(true);
|
||||
//
|
||||
// private volatile AtomicBoolean createOrder = new AtomicBoolean(false);
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 连接建立成功调用的方法
|
||||
// */
|
||||
// @OnOpen
|
||||
// public void onOpen(Session session, @PathParam("tableId") String tableId, @PathParam("shopId") String shopId, @PathParam("userId") String userId) {
|
||||
// this.session = session;
|
||||
// this.tableId = tableId;
|
||||
// this.shopId = shopId;
|
||||
// this.userId = userId;
|
||||
// try {
|
||||
// TbShopTable shopTable = shopTableMapper.selectQRcode(tableId);
|
||||
// if (Objects.isNull(shopTable)) {
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "fail");
|
||||
// jsonObject1.put("msg", "桌码不存在");
|
||||
// jsonObject1.put("type", "addCart");
|
||||
// jsonObject1.put("data", new ArrayList<>());
|
||||
// jsonObject1.put("amount", BigDecimal.ZERO);
|
||||
// sendMessage(jsonObject1);
|
||||
// onClose();
|
||||
// }
|
||||
// if (webSocketMap.containsKey(tableId + "-" + shopId)) {
|
||||
// List<AppWebSocketServerCopy> serverList = webSocketMap.get(tableId + "-" + shopId);
|
||||
// serverList.add(this);
|
||||
// } else {
|
||||
// List<AppWebSocketServerCopy> serverList = new ArrayList<>();
|
||||
// serverList.add(this);
|
||||
// webSocketMap.put(tableId + "-" + shopId, serverList);
|
||||
// }
|
||||
// if (userMap.containsKey(tableId + "-" + shopId)) {
|
||||
// Set<String> userSet = userMap.get(tableId + "-" + shopId);
|
||||
// userSet.add(userId);
|
||||
// } else {
|
||||
// Set<String> userSet = new HashSet<>();
|
||||
// userSet.add(userId);
|
||||
// userMap.put(tableId + "-" + shopId,userSet);
|
||||
// }
|
||||
//
|
||||
// userSocketMap.put(userId, this);
|
||||
//// sessionMap.put(userId,session);
|
||||
// String mes = redisUtils.getMessage(RedisCst.TABLE_CART.concat(tableId + "-" + shopId));
|
||||
// if (StringUtils.isEmpty(mes)) {
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "success");
|
||||
// jsonObject1.put("msg", "成功");
|
||||
// jsonObject1.put("type", "addCart");
|
||||
// jsonObject1.put("data", new ArrayList<>());
|
||||
// jsonObject1.put("amount", BigDecimal.ZERO);
|
||||
// sendMessage(jsonObject1);
|
||||
// } else {
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "success");
|
||||
// jsonObject1.put("msg", "成功");
|
||||
// jsonObject1.put("type", "addCart");
|
||||
// BigDecimal amount = BigDecimal.ZERO;
|
||||
// JSONArray jsonArray = JSON.parseArray(redisUtils.getMessage(RedisCst.TABLE_CART.concat(tableId + "-" + shopId)));
|
||||
// for (int i = 0; i < jsonArray.size(); i++) {
|
||||
// JSONObject object = jsonArray.getJSONObject(i);
|
||||
// amount = amount.add(object.getBigDecimal("totalAmount"));
|
||||
// }
|
||||
// jsonObject1.put("amount", amount);
|
||||
// jsonObject1.put("data", jsonArray);
|
||||
// sendMessage(jsonObject1);
|
||||
// }
|
||||
//// sendMessage(recordMap.get(tableId));
|
||||
// } catch (IOException e) {
|
||||
// log.error("用户:" + tableId + ",网络异常!!!!!!");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 连接关闭调用的方法
|
||||
// */
|
||||
// @OnClose
|
||||
// public void onClose() {
|
||||
// if (webSocketMap.containsKey(tableId + "-" + shopId)) {
|
||||
// List<AppWebSocketServerCopy> serverList = webSocketMap.get(tableId + "-" + shopId);
|
||||
// if (serverList.isEmpty()) {
|
||||
// webSocketMap.remove(tableId + "-" + shopId);
|
||||
// }
|
||||
// serverList.remove(this);
|
||||
//
|
||||
// }
|
||||
// if (userMap.containsKey(tableId + "-" + shopId)){
|
||||
// Set<String> userSet = userMap.get(tableId + "-" + shopId);
|
||||
// if (userSet.isEmpty()){
|
||||
// userMap.remove(tableId + "-" + shopId);
|
||||
// }
|
||||
// userSet.remove(userId);
|
||||
// }
|
||||
// }
|
||||
// public static void onClosed(String user) throws IOException {
|
||||
// Session session1 = sessionMap.get(user);
|
||||
// session1.close();
|
||||
// }
|
||||
// /**
|
||||
// * 收到客户端消息后调用的方法
|
||||
// *
|
||||
// * @param message 客户端发送过来的消息
|
||||
// */
|
||||
// @OnMessage
|
||||
// public void onMessage(String message, Session session) {
|
||||
//
|
||||
// System.out.println(message);
|
||||
// //可以群发消息
|
||||
// //消息保存到数据库、redis
|
||||
// if (StringUtils.isNotBlank(message) && !message.equals("undefined")) {
|
||||
// try {
|
||||
// //解析发送的报文
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// if (StringUtils.isNotEmpty(message)) {
|
||||
// jsonObject = JSONObject.parseObject(message);
|
||||
// }
|
||||
// //追加发送人(防止串改)
|
||||
// jsonObject.put("tableId", this.tableId);
|
||||
// jsonObject.put("shopId", this.shopId);
|
||||
//
|
||||
// //这里采用责任链模式,每一个处理器对应一个前段发过来的请,这里还可以用工厂模式来生成对象
|
||||
//// ChangeHandler changeHandler = new ChangeHandler();
|
||||
//// CreateOrderHandler createOrderHandler = new CreateOrderHandler();
|
||||
//// SyncHandler syncHandler = new SyncHandler();
|
||||
//// ClearHandler clearHandler = new ClearHandler();
|
||||
//// OtherHandler otherHandler = new OtherHandler();
|
||||
////
|
||||
//// changeHandler.addNextHandler(syncHandler).addNextHandler(createOrderHandler).addNextHandler(clearHandler).addNextHandler(otherHandler);
|
||||
//// changeHandler.handleRequest(webSocketMap,jsonObject,recordMap,this);
|
||||
// if ("sku".equals(jsonObject.getString("type"))){
|
||||
// boolean exist = redisUtils.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)));
|
||||
// Integer num = 0;
|
||||
// if (exist){
|
||||
// JSONArray array = JSON.parseArray(redisUtils.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
|
||||
// for (int i = 0; i < array.size(); i++) {
|
||||
// JSONObject object = array.getJSONObject(i);
|
||||
// if (object.getString("skuId").equals(jsonObject.getString("skuId"))) {
|
||||
// num = object.getIntValue("totalNumber");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "success");
|
||||
// jsonObject1.put("msg", "成功");
|
||||
// jsonObject1.put("type", "sku");
|
||||
// jsonObject1.put("data", new ArrayList<>());
|
||||
// jsonObject1.put("amount", num);
|
||||
// sendMessage(jsonObject1);
|
||||
// }else {
|
||||
// rabbitProducer.putCart(jsonObject.toJSONString());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 发生错误时候
|
||||
// *
|
||||
// * @param session
|
||||
// * @param error
|
||||
// */
|
||||
// @OnError
|
||||
// public void onError(Session session, Throwable error) {
|
||||
// log.error("用户错误:" + this.tableId + ",原因:" + error.getMessage());
|
||||
// error.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 实现服务器主动推送
|
||||
// */
|
||||
// public void sendMessage(Object message) throws IOException {
|
||||
// //加入线程锁
|
||||
// synchronized (session) {
|
||||
// try {
|
||||
// //同步发送信息
|
||||
// this.session.getBasicRemote().sendObject(message);
|
||||
// } catch (Exception e) {
|
||||
// log.error("服务器推送失败:" + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 发送自定义消息
|
||||
// * */
|
||||
// /**
|
||||
// * 发送自定义消息
|
||||
// *
|
||||
// * @param message 发送的信息
|
||||
// * @param tableId 如果为null默认发送所有
|
||||
// * @throws IOException
|
||||
// */
|
||||
// public static void AppSendInfo(Object message, String tableId, boolean userFlag) throws IOException {
|
||||
// if (userFlag) {
|
||||
// if (userSocketMap.containsKey(tableId)) {
|
||||
// AppWebSocketServerCopy server = userSocketMap.get(tableId);
|
||||
// server.sendMessage(message);
|
||||
// } else {
|
||||
// log.error("请求的userId:" + tableId + "不在该服务器上");
|
||||
// }
|
||||
// } else {
|
||||
// if (StringUtils.isEmpty(tableId)) {
|
||||
// // 向所有用户发送信息
|
||||
// for (List<AppWebSocketServerCopy> serverList : webSocketMap.values()) {
|
||||
// for (AppWebSocketServerCopy server : serverList) {
|
||||
// server.sendMessage(message);
|
||||
// }
|
||||
// }
|
||||
// } else if (webSocketMap.containsKey(tableId)) {
|
||||
// // 发送给指定用户信息
|
||||
// List<AppWebSocketServerCopy> serverList = webSocketMap.get(tableId);
|
||||
// for (AppWebSocketServerCopy server : serverList) {
|
||||
// server.sendMessage(message);
|
||||
// }
|
||||
// } else {
|
||||
// log.error("请求的tableId:" + tableId + "不在该服务器上");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static synchronized ConcurrentHashMap<String, List<AppWebSocketServerCopy>> getWebSocketMap() {
|
||||
// return AppWebSocketServerCopy.webSocketMap;
|
||||
// }
|
||||
//
|
||||
// public static synchronized ConcurrentHashMap<String, List<JSONObject>> getRecordMap() {
|
||||
// return AppWebSocketServerCopy.recordMap;
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
//package com.chaozhanggui.system.cashierservice.socket;
|
||||
//
|
||||
//import lombok.Data;
|
||||
//
|
||||
//import javax.websocket.Session;
|
||||
//import java.io.Serializable;
|
||||
//
|
||||
//@Data
|
||||
//public class SocketSession implements Serializable {
|
||||
// private Session session;
|
||||
// private String tableId ;
|
||||
// private String shopId ;
|
||||
// private String userId ;
|
||||
//}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
//package com.chaozhanggui.system.cashierservice.socket;
|
||||
//
|
||||
//import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
//import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
//
|
||||
//import javax.servlet.ServletContext;
|
||||
//import javax.servlet.ServletException;
|
||||
//
|
||||
///**
|
||||
// * WebSocket配置
|
||||
// */
|
||||
//@Configuration
|
||||
//public class WebSocketConfig implements ServletContextInitializer {
|
||||
//
|
||||
// @Bean
|
||||
// public ServerEndpointExporter serverEndpointExporter () {
|
||||
// return new ServerEndpointExporter();
|
||||
// }
|
||||
// @Override
|
||||
// public void onStartup(ServletContext servletContext) throws ServletException {
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
//package com.chaozhanggui.system.cashierservice.socket;
|
||||
//
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.websocket.*;
|
||||
//import javax.websocket.server.ServerEndpoint;
|
||||
//import java.io.IOException;
|
||||
//import java.util.concurrent.CopyOnWriteArraySet;
|
||||
//import java.util.concurrent.atomic.AtomicInteger;
|
||||
//
|
||||
//
|
||||
//@Component
|
||||
//@ServerEndpoint(value = "/ws")
|
||||
//public class WebSocketServer {
|
||||
//
|
||||
// //与某个客户端的连接会话,需要通过它来给客户端发送数据
|
||||
// private Session session;
|
||||
//
|
||||
// private static final AtomicInteger OnlineCount = new AtomicInteger(0);
|
||||
//
|
||||
// private static CopyOnWriteArraySet<Session> SessionSet = new CopyOnWriteArraySet<>();
|
||||
//
|
||||
// /**
|
||||
// * 连接建立成功调用的方法
|
||||
// */
|
||||
// @OnOpen
|
||||
// public void onOpen(Session session) {
|
||||
// SessionSet.add(session);
|
||||
// this.session = session;
|
||||
// int cnt = OnlineCount.incrementAndGet(); // 在线数加1
|
||||
// System.out.println("有连接加入,当前连接数为:" + cnt);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 连接关闭调用的方法
|
||||
// */
|
||||
// @OnClose
|
||||
// public void onClose() {
|
||||
// SessionSet.remove(this.session);
|
||||
// int cnt = OnlineCount.decrementAndGet();
|
||||
// System.out.println("有连接关闭,当前连接数为:" + cnt);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 收到客户端消息后调用的方法
|
||||
// * @param message 客户端发送过来的消息
|
||||
// */
|
||||
// @OnMessage
|
||||
// public void onMessage(String message, Session session) {
|
||||
// System.out.println(message);
|
||||
// BroadCastInfo(message);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 出现错误
|
||||
// * @param error
|
||||
// */
|
||||
// @OnError
|
||||
// public void onError(Throwable error) {
|
||||
// error.printStackTrace();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 发送消息
|
||||
// *
|
||||
// * @param session
|
||||
// * @param message
|
||||
// */
|
||||
// public static void SendMessage(Session session, String message) {
|
||||
// try {
|
||||
// if (session.isOpen()) {
|
||||
// session.getBasicRemote().sendText(message);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 群发消息
|
||||
// *
|
||||
// * @param message
|
||||
// * @throws IOException
|
||||
// */
|
||||
// public static void BroadCastInfo(String message) {
|
||||
// for (Session session : SessionSet) {
|
||||
// SendMessage(session, message);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 指定Session发送消息
|
||||
// *
|
||||
// * @param sessionId
|
||||
// * @param message
|
||||
// * @throws IOException
|
||||
// */
|
||||
// public static void SendMessage(String message, String sessionId) {
|
||||
// Session session = null;
|
||||
// for (Session s : SessionSet) {
|
||||
// if (s.getId().equals(sessionId)) {
|
||||
// session = s;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (session != null) {
|
||||
// SendMessage(session, message);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
<result column="is_gift" jdbcType="VARCHAR" property="isGift"/>
|
||||
<result column="pending_at" jdbcType="BIGINT" property="pendingAt"/>
|
||||
<result column="uuid" jdbcType="VARCHAR" property="uuid"/>
|
||||
<result column="sku_id" jdbcType="VARCHAR" property="skuName"/>
|
||||
<result column="sku_name" jdbcType="VARCHAR" property="skuName"/>
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, master_id, order_id, ref_order_id, total_amount, product_id, cover_img, is_sku,pack_fee,is_pack,is_gift,pending_at,
|
||||
|
|
@ -103,7 +103,7 @@
|
|||
name, sale_price, number,
|
||||
total_number, refund_number, category_id,
|
||||
status, type, merchant_id,
|
||||
shop_id, created_at, updated_at, pack_fee,trade_day,is_pack,is_gift,table_id,user_id
|
||||
shop_id, created_at, updated_at, pack_fee,trade_day,is_pack,is_gift,table_id,user_id,sku_name
|
||||
)
|
||||
values (#{id,jdbcType=INTEGER}, #{masterId,jdbcType=VARCHAR}, #{orderId,jdbcType=VARCHAR},
|
||||
#{refOrderId,jdbcType=VARCHAR}, #{totalAmount,jdbcType=DECIMAL}, #{productId,jdbcType=VARCHAR},
|
||||
|
|
@ -112,7 +112,7 @@
|
|||
#{totalNumber,jdbcType=REAL}, #{refundNumber,jdbcType=REAL}, #{categoryId,jdbcType=VARCHAR},
|
||||
#{status,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{merchantId,jdbcType=VARCHAR},
|
||||
#{shopId,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{packFee,jdbcType=DECIMAL}
|
||||
, #{tradeDay,jdbcType=VARCHAR}, #{isPack,jdbcType=VARCHAR}, #{isGift,jdbcType=VARCHAR}, #{tableId,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER}
|
||||
, #{tradeDay,jdbcType=VARCHAR}, #{isPack,jdbcType=VARCHAR}, #{isGift,jdbcType=VARCHAR}, #{tableId,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER},#{skuName,jdbcType=VARCHAR}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart">
|
||||
|
|
|
|||
Loading…
Reference in New Issue