diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcChargeOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcChargeOrderController.java index 1d8023f5..f958b31f 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcChargeOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcChargeOrderController.java @@ -1,9 +1,12 @@ package com.xhpc.order.api; import com.alibaba.fastjson.JSONObject; +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Connection; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.page.TableDataInfo; +import com.xhpc.common.util.ConnectionRabbitMQUtil; import com.xhpc.order.service.IXhpcChargeOrderService; import com.xhpc.order.service.IXhpcHistoryOrderService; import io.swagger.annotations.Api; @@ -13,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -116,18 +120,52 @@ public class XhpcChargeOrderController extends BaseController { * @return */ @GetMapping("/getOrderMessage") - public Object getOrderMessage(@RequestParam Long userId) + public void getOrderMessage(@RequestParam Long userId) { Map orderMessage = iXhpcChargeOrderService.getOrderMessage(userId); - Map map =new HashMap<>(); - map.put("msg","实时数据"); - map.put("code","200"); - map.put("userId",userId); - map.put("data",orderMessage); + Map map =new HashMap<>(); + map.put("code", 200); + map.put("message", "实时数据"); + map.put("userId", userId); + if(orderMessage ==null){ + Map data = new HashMap<>(); + BigDecimal decimal = new BigDecimal(0); + data.put("amountCharged",decimal); + data.put("gunNumber","0"); + data.put("chargingOrderId",0L); + data.put("soc",0); + data.put("chargingTime","0"); + data.put("electricCurrent",decimal); + data.put("voltage", decimal); + data.put("power", "0"); + data.put("chargingDegree", decimal); + data.put("remainingTime","0"); + data.put("serialNumber","0"); + data.put("parkingInstructions","在非充电情况下占用车位按照0.30元/分钟收费"); + map.put("data", data); + }else{ + map.put("data",orderMessage); + } JSONObject json = new JSONObject(map); - return json; + rabbimt(userId + "##" + json); } + private void rabbimt(String message) { + //发送消息队列 + try { + // 1、获取到连接 + Connection connection = ConnectionRabbitMQUtil.getConnection(); + // 2、从连接中创建通道,使用通道才能完成消息相关的操作 + Channel channel = connection.createChannel(); + // 3、声明(创建)队列 + channel.queueDeclare("webSocket", false, false, false, null); + // 4、消息内容 + channel.basicPublish("", "webSocket", null, message.getBytes()); + channel.close(); + connection.close(); + } catch (Exception e) { + } + } }