桩回调启动充电、回调停止充电
This commit is contained in:
parent
a294568e6f
commit
96d3fb752f
@ -1,8 +1,12 @@
|
|||||||
package com.xhpc.order.controller;
|
package com.xhpc.order.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.xhpc.common.core.web.controller.BaseController;
|
import com.xhpc.common.core.web.controller.BaseController;
|
||||||
import com.xhpc.common.core.web.domain.AjaxResult;
|
import com.xhpc.common.core.web.domain.AjaxResult;
|
||||||
import com.xhpc.common.core.web.page.TableDataInfo;
|
import com.xhpc.common.core.web.page.TableDataInfo;
|
||||||
|
import com.xhpc.common.data.redis.CacheRealtimeData;
|
||||||
|
import com.xhpc.common.redis.service.RedisService;
|
||||||
import com.xhpc.order.service.IHxpcChargeOrderService;
|
import com.xhpc.order.service.IHxpcChargeOrderService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -25,7 +29,8 @@ public class HxpcChargeOrderController extends BaseController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IHxpcChargeOrderService iHxpcChargeOrderService;
|
private IHxpcChargeOrderService iHxpcChargeOrderService;
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
/**
|
/**
|
||||||
* 实时订单
|
* 实时订单
|
||||||
*/
|
*/
|
||||||
@ -56,7 +61,7 @@ public class HxpcChargeOrderController extends BaseController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/startUp")
|
@GetMapping("/startUp")
|
||||||
public AjaxResult startUp(@RequestParam Long userId,@RequestParam String serialNumber,Integer type){
|
public AjaxResult startUp(@RequestParam Long userId,@RequestParam String serialNumber,@RequestParam Integer type){
|
||||||
return iHxpcChargeOrderService.startUp(userId, serialNumber,type);
|
return iHxpcChargeOrderService.startUp(userId, serialNumber,type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,13 +78,42 @@ public class HxpcChargeOrderController extends BaseController {
|
|||||||
return iHxpcChargeOrderService.stopUp(userId, serialNumber,chargingOrderId);
|
return iHxpcChargeOrderService.stopUp(userId, serialNumber,chargingOrderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桩回调接口
|
* 桩启动回调接口
|
||||||
|
* @param orderNo 订单号
|
||||||
|
* @param status 1 成功 2失败
|
||||||
|
* @param remark 备注
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/pileStatus")
|
@GetMapping("/pileStartUp")
|
||||||
public AjaxResult pileStatus(String orderNo,Integer status,String remark){
|
public void pileStartUp(String orderNo,Integer status,String remark){
|
||||||
iHxpcChargeOrderService.pileStatus(orderNo, status,remark);
|
iHxpcChargeOrderService.pileStartUp(orderNo,status,remark);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 桩停止回调接口
|
||||||
|
* @param orderNo 订单号
|
||||||
|
* @param status 1 成功 2失败
|
||||||
|
* @param remark 备注
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/pileStopUp")
|
||||||
|
public void pileStopUp(String orderNo,Integer status,String remark){
|
||||||
|
iHxpcChargeOrderService.pileStopUp(orderNo,status,remark);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 桩实时数据回调接口
|
||||||
|
* @param orderNo 订单号
|
||||||
|
* @param status 离线、故障、充电、空闲、计费错误(重新计算费用,电量默认为正确)
|
||||||
|
* @param remark 备注
|
||||||
|
* @param rateModel 费率模型id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/pileRealtime")
|
||||||
|
public AjaxResult pileRealtime(String orderNo,Integer status,String remark,String rateModel){
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,12 +43,21 @@ public interface IHxpcChargeOrderService {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桩回调接口
|
* 桩启动回调接口
|
||||||
* @param orderNo 订单编号
|
* @param orderNo 订单号
|
||||||
* @param status 订单状态 (启动状态 1成功 2失败 | 实时订单状态 3充电中 4 桩充电完成 6桩异常停止充电 )
|
* @param status 1 成功 2失败
|
||||||
* @param remark 失败的备注
|
* @param remark 备注
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
void pileStatus(String orderNo,Integer status,String remark);
|
void pileStartUp(String orderNo,Integer status,String remark);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 桩停止回调接口
|
||||||
|
* @param orderNo 订单号
|
||||||
|
* @param status 1 成功 2失败
|
||||||
|
* @param remark 备注
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void pileStopUp(String orderNo,Integer status,String remark);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,16 @@
|
|||||||
package com.xhpc.order.service.impl;
|
package com.xhpc.order.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.rabbitmq.client.Channel;
|
import com.rabbitmq.client.Channel;
|
||||||
import com.rabbitmq.client.Connection;
|
import com.rabbitmq.client.Connection;
|
||||||
import com.xhpc.common.api.PowerPileService;
|
import com.xhpc.common.api.PowerPileService;
|
||||||
import com.xhpc.common.core.domain.R;
|
import com.xhpc.common.core.domain.R;
|
||||||
import com.xhpc.common.core.web.domain.AjaxResult;
|
import com.xhpc.common.core.web.domain.AjaxResult;
|
||||||
import com.xhpc.common.data.down.StartChargingData;
|
import com.xhpc.common.data.down.StartChargingData;
|
||||||
|
import com.xhpc.common.data.redis.CacheRealtimeData;
|
||||||
import com.xhpc.common.data.redis.SeqUtil;
|
import com.xhpc.common.data.redis.SeqUtil;
|
||||||
import com.xhpc.common.domain.XhpcTerminal;
|
import com.xhpc.common.domain.XhpcTerminal;
|
||||||
import com.xhpc.common.redis.service.RedisService;
|
import com.xhpc.common.redis.service.RedisService;
|
||||||
@ -23,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -172,6 +177,9 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
|
|||||||
if (xhpcTerminal == null || xhpcTerminal.getTerminalId() == null || xhpcTerminal.getChargingPileId() == null || xhpcTerminal.getPileSerialNumber() == null) {
|
if (xhpcTerminal == null || xhpcTerminal.getTerminalId() == null || xhpcTerminal.getChargingPileId() == null || xhpcTerminal.getPileSerialNumber() == null) {
|
||||||
return AjaxResult.error(1104, "无效的终端编号");
|
return AjaxResult.error(1104, "无效的终端编号");
|
||||||
}
|
}
|
||||||
|
HxpcChargeOrder serialNumberMessage = hxpcChargeOrderMapper.getSerialNumberMessage(serialNumber);
|
||||||
|
serialNumberMessage.setType(1);
|
||||||
|
hxpcChargeOrderMapper.updateXhpcChargeOrder(serialNumberMessage);
|
||||||
R oa = powerPileService.stopCharging(xhpcTerminal.getPileSerialNumber(), xhpcTerminal.getSerialNumber(), "OA");
|
R oa = powerPileService.stopCharging(xhpcTerminal.getPileSerialNumber(), xhpcTerminal.getSerialNumber(), "OA");
|
||||||
if(oa.getCode() !=200){
|
if(oa.getCode() !=200){
|
||||||
return AjaxResult.error(oa.getMsg());
|
return AjaxResult.error(oa.getMsg());
|
||||||
@ -180,51 +188,83 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桩回调接口
|
* 桩启动回调接口
|
||||||
* @param orderNo 订单编号
|
* @param orderNo 订单号
|
||||||
* @param status 订单状态 (启动状态 1成功 2失败 实时订单状态 3充电中 4 桩充电完成 5 用户停止充电 6桩异常停止充电 )
|
* @param status 1 成功 2失败
|
||||||
* @param remark 失败的备注
|
* @param remark 备注
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void pileStatus(String orderNo, Integer status,String remark) {
|
public void pileStartUp(String orderNo, Integer status, String remark) {
|
||||||
//解析订单编号
|
//解析订单编号
|
||||||
String s = orderNo.split("\\.")[0];
|
String s = orderNo.split("\\.")[0];
|
||||||
String s1 = s.split(":")[1];
|
String s1 = s.split(":")[1];
|
||||||
|
Long userId;
|
||||||
|
Integer code ;
|
||||||
if(status ==1){
|
if(status ==1){
|
||||||
update(orderNo,0, 0,null, s1,0);
|
code=200;
|
||||||
}else if(status ==2){
|
userId=update(0, 0,remark, s1,0);
|
||||||
update(orderNo,-1, 1,remark, s1,0);
|
|
||||||
}else{
|
}else{
|
||||||
if(status == 3){
|
code=500;
|
||||||
//发送实时数据
|
userId=update(-1, 1,remark, s1,0);
|
||||||
}
|
|
||||||
if(status == 4 || status==5){
|
|
||||||
//发送实时订单结束状态,并修改订单状态,生成一条历史订单
|
|
||||||
update(orderNo,1, 0,null, s1,status);
|
|
||||||
}
|
|
||||||
if(status ==6){
|
|
||||||
//订单异常,修改订单状态
|
|
||||||
update(orderNo,2, 0,remark, s1,status);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Map<String,Object> map =new HashMap<>();
|
||||||
|
map.put("code",code);
|
||||||
|
map.put("userId",userId);
|
||||||
|
map.put("message",remark);
|
||||||
|
JSONObject json = new JSONObject(map);
|
||||||
//消息对了内容
|
//消息对了内容
|
||||||
String message="";
|
rabbimt(userId+"##"+json);
|
||||||
|
}
|
||||||
rabbimt(message);
|
/**
|
||||||
|
* 桩停止回调接口
|
||||||
|
* @param orderNo 订单号
|
||||||
|
* @param status 1 成功 2失败
|
||||||
|
* @param remark 备注
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void pileStopUp(String orderNo, Integer status, String remark) {
|
||||||
|
//解析订单编号
|
||||||
|
String s = orderNo.split("\\.")[0];
|
||||||
|
String s1 = s.split(":")[1];
|
||||||
|
Integer code=300 ;
|
||||||
|
Long userId=update(status, 0,remark, s1,1);
|
||||||
|
Map<String,Object> map =new HashMap<>();
|
||||||
|
map.put("code",code);
|
||||||
|
map.put("userId",userId);
|
||||||
|
if(status==1){
|
||||||
|
map.put("message","停止充电成功");
|
||||||
|
}else{
|
||||||
|
map.put("message",remark);
|
||||||
|
}
|
||||||
|
JSONObject json = new JSONObject(map);
|
||||||
|
//消息对了内容
|
||||||
|
rabbimt(userId+"##"+json);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(String orderNo,Integer status,Integer delFlag, String remark, String serialNumber,Integer type) {
|
/**
|
||||||
|
* @param status 状态
|
||||||
|
* @param delFlag 是否删除
|
||||||
|
* @param remark 备注
|
||||||
|
* @param serialNumber 订单号
|
||||||
|
* @param type 结束订单状态
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Long update(Integer status,Integer delFlag, String remark, String serialNumber,Integer type) {
|
||||||
HxpcChargeOrder hxpcChargeOrder = hxpcChargeOrderMapper.getSerialNumberMessage(serialNumber);
|
HxpcChargeOrder hxpcChargeOrder = hxpcChargeOrderMapper.getSerialNumberMessage(serialNumber);
|
||||||
hxpcChargeOrder.setStatus(status);
|
hxpcChargeOrder.setStatus(status);
|
||||||
hxpcChargeOrder.setDelFlag(delFlag);
|
hxpcChargeOrder.setDelFlag(delFlag);
|
||||||
hxpcChargeOrder.setRemark(remark);
|
hxpcChargeOrder.setRemark(remark);
|
||||||
|
|
||||||
Long userId = hxpcChargeOrder.getUserId();
|
Long userId = hxpcChargeOrder.getUserId();
|
||||||
if(type==4 ||type ==5){
|
if(type==1){
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
//获取实时订单
|
//获取实时订单
|
||||||
Map<String, Object> cacheMap = REDIS.getCacheMap("order:"+orderNo);
|
Map<String, Object> cacheMap = redisService.getCacheMap("order:"+serialNumber);
|
||||||
cacheMap.get("realtimeDataList");
|
JSONArray st = (JSONArray)cacheMap.get("realtimeDataList");
|
||||||
|
System.out.println(st.toString());
|
||||||
|
CacheRealtimeData cacheRealtimeData = JSON.toJavaObject(st.getJSONObject(0), CacheRealtimeData.class);
|
||||||
|
|
||||||
//用户第几次充电
|
//用户第几次充电
|
||||||
int count = hxpcChargeOrderMapper.getCount(userId);
|
int count = hxpcChargeOrderMapper.getCount(userId);
|
||||||
@ -260,18 +300,12 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
|
|||||||
|
|
||||||
//充电订单 --结束soc、充电时长、充电度数
|
//充电订单 --结束soc、充电时长、充电度数
|
||||||
hxpcChargeOrder.setEndTime(date);
|
hxpcChargeOrder.setEndTime(date);
|
||||||
if(type ==4){
|
|
||||||
hxpcChargeOrder.setType(0);
|
|
||||||
}else{
|
|
||||||
hxpcChargeOrder.setType(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
//实时数据存入MYsql、soc、电流、电压
|
//实时数据存入MYsql、soc、电流、电压
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
hxpcChargeOrderMapper.updateXhpcChargeOrder(hxpcChargeOrder);
|
hxpcChargeOrderMapper.updateXhpcChargeOrder(hxpcChargeOrder);
|
||||||
|
|
||||||
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rabbimt(String message) {
|
private void rabbimt(String message) {
|
||||||
|
|||||||
@ -38,7 +38,7 @@ KEY: "sichuanxianghuakejiyouxiangongsi"
|
|||||||
#微信小程序支付地址
|
#微信小程序支付地址
|
||||||
WXPAYUNIFIEDORDER: "https://api.mch.weixin.qq.com/pay/unifiedorder"
|
WXPAYUNIFIEDORDER: "https://api.mch.weixin.qq.com/pay/unifiedorder"
|
||||||
#微信支付回调地址
|
#微信支付回调地址
|
||||||
SERVERDOMAIN: "http://cdz.project2.tingsun.net/prod-api/xhpc-payment/wx/paymentCallback"
|
SERVERDOMAIN: "http://xhpc.scxhua.com/prod-api/xhpc-payment/wx/paymentCallback"
|
||||||
#微信小程序支付地址
|
#微信小程序支付地址
|
||||||
WXTRANSFERS: "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"
|
WXTRANSFERS: "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"
|
||||||
|
|
||||||
|
|||||||
@ -37,9 +37,6 @@ public class RabbitmConsumer implements ApplicationRunner {
|
|||||||
// body 即消息体
|
// body 即消息体
|
||||||
String msg = new String(body,"utf-8");
|
String msg = new String(body,"utf-8");
|
||||||
String[] split = msg.split("##");
|
String[] split = msg.split("##");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OrderNotificationWebSocket.sendMessage(split[0],split[1]);
|
OrderNotificationWebSocket.sendMessage(split[0],split[1]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user