苍穹外卖--WebSocket-来单提示管理端功能实现

This commit is contained in:
2025-12-01 14:33:29 +08:00
parent 8e742cd563
commit cdc50bebf7

View File

@@ -1,5 +1,6 @@
package com.sky.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
@@ -17,6 +18,7 @@ import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.websocket.WebSocketServer;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
@@ -27,7 +29,9 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@@ -50,6 +54,9 @@ public class OrderServiceImpl implements OrderService {
private Orders orders;//用来记录对应要支付的订单
@Autowired
private WebSocketServer webSocketServer;
/**
* 用户下单
* @param ordersSubmitDTO
@@ -130,6 +137,16 @@ public class OrderServiceImpl implements OrderService {
Integer OrderStatus = Orders.TO_BE_CONFIRMED; //订单状态,待接单
LocalDateTime check_out_time = LocalDateTime.now(); //更新支付时间
orderMapper.updateStatus(OrderStatus, OrderPaidStatus, check_out_time, this.orders.getId());
//这里支付成功了,那就要让服务器向客户端发送来单提示
Map map = new HashMap();
map.put("type", 1);
map.put("orderId", this.orders.getId());
map.put("content","订单号:"+this.orders.getNumber());
//将java对象转为json字符串
String json = JSON.toJSONString(map);
webSocketServer.sendToAllClient(json);
return vo;
}