修改实时数据接口

This commit is contained in:
yuyang 2021-09-03 09:59:45 +08:00
parent 3c919734bd
commit 65c496d183

View File

@ -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<String, Object> orderMessage = iXhpcChargeOrderService.getOrderMessage(userId);
Map<String, Object> map =new HashMap<>();
map.put("msg","实时数据");
map.put("code","200");
map.put("userId",userId);
map.put("data",orderMessage);
Map<String,Object> map =new HashMap<>();
map.put("code", 200);
map.put("message", "实时数据");
map.put("userId", userId);
if(orderMessage ==null){
Map<String, Object> 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) {
}
}
}