来单提醒 + 客户催单 业务代码开发
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.sky.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
|
||||
/**
|
||||
* WebSocket配置类,用于注册WebSocket的Bean
|
||||
*/
|
||||
@Configuration
|
||||
public class WebSocketConfiguration {
|
||||
|
||||
@Bean
|
||||
public ServerEndpointExporter serverEndpointExporter() {
|
||||
return new ServerEndpointExporter();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -97,4 +97,17 @@ public class OrderController {
|
||||
orderService.repetition(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 客户催单
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/reminder/{id}")
|
||||
@ApiOperation("客户催单")
|
||||
public Result reminder(@PathVariable Long id){
|
||||
orderService.reminder(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,4 +111,11 @@ public interface OrderService {
|
||||
* @param id
|
||||
*/
|
||||
void complete(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 客户催单
|
||||
* @param id
|
||||
*/
|
||||
void reminder(Long id);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.Page;
|
||||
@@ -22,6 +23,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 io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.xmlbeans.impl.xb.xmlconfig.Extensionconfig;
|
||||
@@ -67,6 +69,9 @@ public class OrderServiceImpl implements OrderService {
|
||||
@Value("${sky.baidu.ak}")
|
||||
private String ak;
|
||||
|
||||
@Autowired
|
||||
private WebSocketServer webSocketServer;
|
||||
|
||||
/**
|
||||
* 用户下单
|
||||
* @param ordersSubmitDTO
|
||||
@@ -191,6 +196,16 @@ public class OrderServiceImpl implements OrderService {
|
||||
.build();
|
||||
|
||||
orderMapper.update(orders);
|
||||
|
||||
//通过websocket向客户端浏览器推送消息 type orderId content
|
||||
Map map = new HashMap();
|
||||
map.put("type", 1); //1表示来单提醒 2表示客户催单
|
||||
map.put("orderId", ordersDB.getId());
|
||||
map.put("content", "订单号:" + outTradeNo);
|
||||
String json = JSON.toJSONString(map);
|
||||
|
||||
webSocketServer.sendToAllClient(json);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -531,6 +546,30 @@ public class OrderServiceImpl implements OrderService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 客户催单
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void reminder(Long id) {
|
||||
|
||||
//根据id查询订单
|
||||
Orders ordersDB = orderMapper.getById(id);
|
||||
//校验订单是否存在
|
||||
if(ordersDB == null){
|
||||
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
|
||||
}
|
||||
|
||||
Map map = new HashMap();
|
||||
map.put("type", 2); //1表示来单提醒 2表示客户催单
|
||||
map.put("orderId", id);
|
||||
map.put("content", ordersDB.getNumber());
|
||||
|
||||
//通过websocket向客户端浏览器推送消息
|
||||
webSocketServer.sendToAllClient(JSON.toJSONString(map));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查客户的收货地址是否超出配送范围
|
||||
* @param address
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.sky.websocket;
|
||||
|
||||
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.PathParam;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* WebSocket服务
|
||||
*/
|
||||
@Component
|
||||
@ServerEndpoint("/ws/{sid}")
|
||||
public class WebSocketServer {
|
||||
|
||||
//存放会话对象
|
||||
private static Map<String, Session> sessionMap = new HashMap();
|
||||
|
||||
/**
|
||||
* 连接建立成功调用的方法
|
||||
*/
|
||||
@OnOpen
|
||||
public void onOpen(Session session, @PathParam("sid") String sid) {
|
||||
System.out.println("客户端:" + sid + "建立连接");
|
||||
sessionMap.put(sid, session);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收到客户端消息后调用的方法
|
||||
*
|
||||
* @param message 客户端发送过来的消息
|
||||
*/
|
||||
@OnMessage
|
||||
public void onMessage(String message, @PathParam("sid") String sid) {
|
||||
System.out.println("收到来自客户端:" + sid + "的信息:" + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接关闭调用的方法
|
||||
*
|
||||
* @param sid
|
||||
*/
|
||||
@OnClose
|
||||
public void onClose(@PathParam("sid") String sid) {
|
||||
System.out.println("连接断开:" + sid);
|
||||
sessionMap.remove(sid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 群发
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public void sendToAllClient(String message) {
|
||||
Collection<Session> sessions = sessionMap.values();
|
||||
for (Session session : sessions) {
|
||||
try {
|
||||
//服务器向客户端发送消息
|
||||
session.getBasicRemote().sendText(message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user