实时数据通知webSocket

This commit is contained in:
yuyang 2021-08-19 10:53:11 +08:00
parent f9d731ebda
commit c16bec32fe
5 changed files with 70 additions and 10 deletions

View File

@ -42,13 +42,11 @@ public class HxpcPileOrderController extends BaseController {
@Autowired
private IXhpcRealTimeOrderService xhpcRealTimeOrderService;
@Autowired
private PileOrderService pileOrderService;
/**
* 测试
*/
@ -130,16 +128,19 @@ public class HxpcPileOrderController extends BaseController {
public R pileRealtime(@RequestParam(value = "orderNo")String orderNo) {
Date date = new Date();
Map<String, Object> map = new HashMap<>();
//获取实时订单
CacheRealtimeData cacheRealtimeData = redisService.getCacheObject("order:"+orderNo+".lord");
HxpcChargeOrder hxpcChargeOrder = hxpcChargeOrderService.getSerialNumberMessage(orderNo);
Long userId = hxpcChargeOrder.getUserId();
try{
XhpcRealTimeOrder xhpcRealTimeOrder =new XhpcRealTimeOrder();
xhpcRealTimeOrder.setChargingOrderId(hxpcChargeOrder.getChargeOrderId());
xhpcRealTimeOrder.setTransactionNumber(orderNo);
xhpcRealTimeOrder.setPileNumber(cacheRealtimeData.getPileNo());
xhpcRealTimeOrder.setGunNumber(cacheRealtimeData.getGunId());
String gunId = cacheRealtimeData.getGunId();
xhpcRealTimeOrder.setGunNumber(gunId);
if("00".equals(cacheRealtimeData.getPileGunStatus())){
xhpcRealTimeOrder.setPileGunStatus(0);
}else if("01".equals(cacheRealtimeData.getPileGunStatus())){
@ -177,9 +178,11 @@ public class HxpcPileOrderController extends BaseController {
xhpcRealTimeOrder.setRemainingTime(cacheRealtimeData.getChargingTime()+"");
}
BigDecimal decimal = new BigDecimal(100);
xhpcRealTimeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal));
xhpcRealTimeOrder.setLossChargingDegree(new BigDecimal(cacheRealtimeData.getLossChargingDegree()).divide(decimal));
xhpcRealTimeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getLossChargingDegree()).divide(decimal));
BigDecimal divide = new BigDecimal(cacheRealtimeData.getLossChargingDegree()).divide(decimal);
BigDecimal chargingDegree = new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal);
xhpcRealTimeOrder.setChargingDegree(chargingDegree);
xhpcRealTimeOrder.setLossChargingDegree(divide);
xhpcRealTimeOrder.setAmountCharged(divide);
xhpcRealTimeOrder.setHardwareFault(cacheRealtimeData.getHardwareFault());
if("00".equals(cacheRealtimeData.getStatus())){
xhpcRealTimeOrder.setStatus(0);
@ -216,7 +219,33 @@ public class HxpcPileOrderController extends BaseController {
xhpcChargeOrderVoltage.setVoltage(v.toString());
xhpcChargeOrderVoltage.setCreateTime(date);
xhpcRealTimeOrderService.addVoltage(xhpcChargeOrderVoltage);
map.put("code", 200);
map.put("message", "实时数据");
map.put("userId", userId);
Map<String, Object> data = new HashMap<>();
data.put("amountCharged",divide);
data.put("gunNumber",gunId);
data.put("chargingOrderId ",chargeOrderId);
data.put("soc",soc);
data.put("chargingTime",xhpcRealTimeOrder.getChargingTime());
data.put("electricCurrent",c);
data.put("voltage",v);
data.put("power",hxpcChargeOrder.getPower());
data.put("chargingDegree",chargingDegree);
data.put("remainingTime",xhpcRealTimeOrder.getRemainingTime());
map.put("data", data);
JSONObject json = new JSONObject(map);
//消息对了内容
rabbimt(userId + "##" + json);
}catch (Exception e){
map.put("code", 500);
map.put("userId", hxpcChargeOrder.getUserId());
JSONObject json = new JSONObject(map);
//消息对了内容
rabbimt(userId + "##" + json);
return R.fail(500,"无实时数据");
}
return R.ok();

View File

@ -94,6 +94,8 @@ public class HxpcChargeOrder extends BaseEntity {
/** 总金额 */
private String amountCharged;
/** 功率 */
private Double power;
public Long getChargeOrderId() {
@ -295,4 +297,14 @@ public class HxpcChargeOrder extends BaseEntity {
this.amountCharged = amountCharged;
}
public Double getPower() {
return power;
}
public void setPower(Double power) {
this.power = power;
}
}

View File

@ -1,5 +1,6 @@
package com.xhpc.order.mapper;
import com.xhpc.common.domain.XhpcChargingPile;
import com.xhpc.common.domain.XhpcTerminal;
import com.xhpc.order.domain.HxpcChargeOrder;
import org.apache.ibatis.annotations.Param;
@ -101,4 +102,7 @@ public interface HxpcChargeOrderMapper {
*/
Map<String,Object> getOperatorMessage(@Param("chargingStationId") Long chargingStationId);
//获取桩信息
XhpcChargingPile getXhpcChargingPileById(@Param("chargingPileid") Long chargingPileid);
}

View File

@ -6,6 +6,7 @@ import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.data.down.StartChargingData;
import com.xhpc.common.data.redis.SeqUtil;
import com.xhpc.common.domain.XhpcChargingPile;
import com.xhpc.common.domain.XhpcTerminal;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.order.domain.HxpcChargeOrder;
@ -138,6 +139,9 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
if(r1.getCode() !=200){
return AjaxResult.error(r1.getMsg());
}
//获取桩信息
XhpcChargingPile xhpcChargingPile = hxpcChargeOrderMapper.getXhpcChargingPileById(xhpcTerminal.getChargingPileId());
//创建充电订单(充电启动soc初始值结束是获取,并修改状态)
HxpcChargeOrder hxpcChargeOrder = new HxpcChargeOrder();
hxpcChargeOrder.setChargingStationId(xhpcTerminal.getChargingStationId());
@ -146,6 +150,7 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
hxpcChargeOrder.setSerialNumber(orderNo);
hxpcChargeOrder.setSource(0);
hxpcChargeOrder.setStatus(-1);
hxpcChargeOrder.setPower(xhpcChargingPile.getPower());
hxpcChargeOrder.setRateModelId(xhpcTerminal.getRateModelId());
if(type ==1){
hxpcChargeOrder.setChargingMode("小华充电微信");

View File

@ -30,6 +30,7 @@
<result column="type" property="type"/>
<result column="erro_remark" property="erroRemark"/>
<result column="amount_charged" property="amountCharged"/>
<result column="power" property="power"/>
</resultMap>
<resultMap id="BaseResultMap" type="com.xhpc.common.domain.XhpcTerminal">
@ -160,7 +161,10 @@
erro_remark,
</if>
<if test="null != amountCharged ">
amount_charged
amount_charged,
</if>
<if test="null != power ">
power
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
@ -219,7 +223,10 @@
#{erroRemark},
</if>
<if test="null != amountCharged ">
#{amountCharged}
#{amountCharged},
</if>
<if test="null != power ">
#{power}
</if>
</trim>
</insert>
@ -235,6 +242,7 @@
<if test="chargingTime != null">charging_time = #{chargingTime},</if>
<if test="chargingDegree != null">charging_degree = #{chargingDegree},</if>
<if test="type != null">type = #{type},</if>
<if test="power != null">power = #{power},</if>
<if test="erroRemark != null">erro_remark = #{erroRemark},</if>
<if test="amountCharged != null">amount_charged = #{amountCharged},</if>
</trim>
@ -286,5 +294,7 @@
from xhpc_operator where operator_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</select>
<select id="getXhpcChargingPileById" resultMap="com.xhpc.common.domain.XhpcChargingPile">
select * from xhpc_charging_pile where charging_pile_id=#{chargingPileid}
</select>
</mapper>