桩回调接口

This commit is contained in:
yuyang 2021-08-18 14:01:42 +08:00
parent 1091b95236
commit 682c4a8c35
9 changed files with 342 additions and 254 deletions

View File

@ -3,8 +3,12 @@ package com.xhpc.common.api;
import com.xhpc.common.api.factory.PileOrderFallbackFactory;
import com.xhpc.common.core.constant.ServiceNameConstants;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.dto.PileEndOrder;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/**
@ -36,4 +40,21 @@ public interface PileOrderService {
@GetMapping("/chargeOrder/pileStop")
R pileStop(@RequestParam(value = "orderNo") String orderNo, @RequestParam(value = "status") Integer status, @RequestParam(value = "remark") String remark);
/**
* 桩订单结束回调接口
* @param pileEndOrder 订单结束回调实体类
* @return
*/
@PostMapping("/chargeOrder/pileEndOrder")
R pileEndOrder(@Validated @RequestBody PileEndOrder pileEndOrder);
/**
* 桩订单实时订单回调接口
* @param orderNo 订单号
* @return
*/
@GetMapping("/chargeOrder/pileRimeOrder")
R pileRimeOrder(@RequestParam(value = "orderNo") String orderNo);
}

View File

@ -2,6 +2,7 @@ package com.xhpc.common.api.factory;
import com.xhpc.common.api.PileOrderService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.dto.PileEndOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
@ -32,6 +33,18 @@ public class PileOrderFallbackFactory implements FallbackFactory<PileOrderServic
return R.fail("桩停止回调接口失败:" + cause.getMessage());
}
@Override
public R pileEndOrder(PileEndOrder pileEndOrder) {
return R.fail("桩订单结束回调接口失败:" + cause.getMessage());
}
@Override
public R pileRimeOrder(String orderNo) {
return R.fail("桩实时订单回调接口失败:" + cause.getMessage());
}
};
}

View File

@ -1,5 +1,7 @@
package com.xhpc.common.dto;
import java.util.Date;
/**
* 订单结束回调实体类
*/
@ -15,7 +17,7 @@ public class PileEndOrder {
private Integer powerPrice;//电费
private Integer servicePrice;//服务费
private String erroRemark; //备注
private Date createTime;//时间
public String getOrderNo() {
@ -117,4 +119,14 @@ public class PileEndOrder {
this.servicePrice = servicePrice;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

View File

@ -1,5 +1,7 @@
package com.xhpc.order.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
@ -7,19 +9,19 @@ import com.xhpc.common.api.PileOrderService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.data.redis.CacheRealtimeData;
import com.xhpc.common.dto.PileEndOrder;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.common.util.ConnectionRabbitMQUtil;
import com.xhpc.order.domain.HxpcChargeOrder;
import com.xhpc.order.domain.XhpcHistoryOrder;
import com.xhpc.order.domain.XhpcRealTimeOrder;
import com.xhpc.order.service.IHxpcChargeOrderService;
import com.xhpc.order.service.IXhpcHistoryOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.Date;
@ -118,17 +120,58 @@ public class HxpcPileOrderController extends BaseController {
/**
* 桩实时数据回调接口
*
* @param orderNo 订单号
* @param status 离线故障充电空闲计费错误重新计算费用电量默认为正确
* @param remark 备注
* @param rateModel 费率模型id
* @return
*/
@GetMapping("/pileRealtime")
public AjaxResult pileRealtime(String orderNo, Integer status, String remark, String rateModel) {
@GetMapping("/chargeOrder/pileRimeOrder")
public R pileRealtime(String orderNo) {
return AjaxResult.success();
Date date = new Date();
//获取实时订单
Map<String, Object> cacheMap = redisService.getCacheMap("order:"+orderNo);
JSONArray st = (JSONArray)cacheMap.get("realtimeDataList");
System.out.println(st.toString());
HxpcChargeOrder hxpcChargeOrder = hxpcChargeOrderService.getSerialNumberMessage(orderNo);
if(st!=null && st.size()>0){
for (int i = 0; i <st.size() ; i++) {
CacheRealtimeData cacheRealtimeData = JSON.toJavaObject(st.getJSONObject(0), CacheRealtimeData.class);
XhpcRealTimeOrder xhpcRealTimeOrder =new XhpcRealTimeOrder();
xhpcRealTimeOrder.setChargingOrderId(hxpcChargeOrder.getChargeOrderId());
xhpcRealTimeOrder.setTransactionNumber(orderNo);
xhpcRealTimeOrder.setPileNumber(cacheRealtimeData.getPileNo());
xhpcRealTimeOrder.setGunNumber(cacheRealtimeData.getGunId());
if("00".equals(cacheRealtimeData.getPileGunStatus())){
xhpcRealTimeOrder.setPileGunStatus(0);
}else if("01".equals(cacheRealtimeData.getPileGunStatus())){
xhpcRealTimeOrder.setPileGunStatus(1);
}else{
xhpcRealTimeOrder.setPileGunStatus(2);
}
if("00".equals(cacheRealtimeData.getVehicleGunStatus())){
xhpcRealTimeOrder.setVehicleGunStatus(0);
}else{
xhpcRealTimeOrder.setVehicleGunStatus(1);
}
BigDecimal v = new BigDecimal(cacheRealtimeData.getWorkingVoltage()).divide(new BigDecimal(10));
BigDecimal c = new BigDecimal(cacheRealtimeData.getWorkingCurrent()).divide(new BigDecimal(10));
xhpcRealTimeOrder.setVoltage(v);
xhpcRealTimeOrder.setElectricCurrent(c);
xhpcRealTimeOrder.setGunLineTemperature(cacheRealtimeData.getGunLineTemperature());
xhpcRealTimeOrder.setGunLineNumber(cacheRealtimeData.getGunLineNumber());
xhpcRealTimeOrder.setSoc(cacheRealtimeData.getSoc().toString());
xhpcRealTimeOrder.setMaxTemperature(cacheRealtimeData.getMaxTemperature());
cacheRealtimeData.getChargingTime();
xhpcRealTimeOrder.setChargingTime(cacheRealtimeData.getChargingTime().toString());
//实时数据存入MYsqlsoc电流电压
}
}else{
return R.fail(500,"无实时数据");
}
return R.ok();
}
@ -137,9 +180,10 @@ public class HxpcPileOrderController extends BaseController {
*
*/
@Transactional
@GetMapping("/pileEndOrder")
public R pileEndOrder(@RequestBody PileEndOrder pileEndOrder) {
@PostMapping("/chargeOrder/pileEndOrder")
public R pileEndOrder(@Validated @RequestBody PileEndOrder pileEndOrder) {
try{
//解析订单编号
String s = pileEndOrder.getOrderNo().split("\\.")[0];
String s1 = s.split(":")[1];
@ -160,7 +204,7 @@ public class HxpcPileOrderController extends BaseController {
hxpcChargeOrder.setStartSoc(pileEndOrder.getStartSoc());
hxpcChargeOrder.setEndSoc(pileEndOrder.getEndSoc());
hxpcChargeOrder.setStatus(pileEndOrder.getStatus());
hxpcChargeOrder.setEndTime(date);
hxpcChargeOrder.setEndTime(pileEndOrder.getCreateTime());
hxpcChargeOrder.setChargingTime(pileEndOrder.getChargingTime().toString());
hxpcChargeOrder.setChargingDegree(pileEndOrder.getChargingDegree().toString());
hxpcChargeOrder.setAmountCharged(money.toString());
@ -298,7 +342,6 @@ public class HxpcPileOrderController extends BaseController {
xhpcHistoryOrder.setType(1);
xhpcHistoryOrder.setStatus(0);
xhpcHistoryOrder.setDelFlag(0);
xhpcHistoryOrder.setCreateTime(date);
//订单总价---运维服务费抽成
xhpcHistoryOrder.setTotalPrice(money);
xhpcHistoryOrder.setPromotionDiscount(promotionDiscount);
@ -319,58 +362,15 @@ public class HxpcPileOrderController extends BaseController {
xhpcHistoryOrderService.insert(xhpcHistoryOrder);
hxpcChargeOrderService.updateXhpcChargeOrder(hxpcChargeOrder);
//删除实时数据获取最新的实时数据
//hxpcChargeOrderService.deleteRealTimeOrder(hxpcChargeOrder.getChargeOrderId());
//添加新的实时数据
}catch (Exception e){
return R.fail(500,"添加订单回调失败");
}
return R.ok();
}
private void gun(){
// Date date = new Date();
// //获取实时订单
// Map<String, Object> cacheMap = redisService.getCacheMap("order:"+serialNumber);
// JSONArray st = (JSONArray)cacheMap.get("realtimeDataList");
// System.out.println(st.toString());
// CacheRealtimeData cacheRealtimeData = JSON.toJavaObject(st.getJSONObject(0), CacheRealtimeData.class);
//
// //用户第几次充电
// int count = iHxpcChargeOrderService.getCount(userId);
// String state ="";
// String discount ="";
// if(count==0){
// //活动折扣
// Map<String, Object> promotion = iHxpcChargeOrderService.getPromotion();
// if(promotion !=null){
// //state 1.总金额 2.金额 3.服务费 discount 折扣率
// state = promotion.get("state").toString();
// discount = promotion.get("discount").toString();
// }
// }
//
// //生成一条历史订单
// XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder();
// xhpcHistoryOrder.setChargeOrderId(hxpcChargeOrder.getChargeOrderId());
// xhpcHistoryOrder.setChargingStationId(hxpcChargeOrder.getChargingStationId());
// xhpcHistoryOrder.setUserId(userId);
// xhpcHistoryOrder.setTerminalId(hxpcChargeOrder.getTerminalId());
// xhpcHistoryOrder.setSerialNumber(hxpcChargeOrder.getSerialNumber());
// xhpcHistoryOrder.setStartSoc(hxpcChargeOrder.getStartSoc());
// xhpcHistoryOrder.setReconciliationStatus(0);
// xhpcHistoryOrder.setSortingStatus(0);
// xhpcHistoryOrder.setType(1);
// xhpcHistoryOrder.setStatus(0);
// xhpcHistoryOrder.setDelFlag(0);
// xhpcHistoryOrder.setCreateTime(date);
// //订单总价---运维服务费抽成
// //结束时soc
// xhpcHistoryOrderService.insert(xhpcHistoryOrder);
//
// //充电订单 --结束soc充电时长充电度数
// hxpcChargeOrder.setEndTime(date);
//
// //实时数据存入MYsqlsoc电流电压
}
/**
* @param status 状态
* @param delFlag 是否删除

View File

@ -2,6 +2,8 @@ package com.xhpc.order.domain;
import com.xhpc.common.core.web.domain.BaseEntity;
import java.math.BigDecimal;
/**
* @author yuyang
* @date 2021/8/7 15:06
@ -35,23 +37,23 @@ public class XhpcRealTimeOrder extends BaseEntity {
/**
* 是否插枪0否 1是
*/
private Long vehicleGunStatus;
private Integer vehicleGunStatus;
/**
* 电压
*/
private Double voltage;
private BigDecimal voltage;
/**
* 电流
*/
private Double electricCurrent;
private BigDecimal electricCurrent;
/**
* 枪线温度
*/
private Double gunLineTemperature;
private Integer gunLineTemperature;
/**
* 枪线编码
*/
private Double gunLineNumber;
private String gunLineNumber;
/**
* SOC
*/
@ -59,7 +61,7 @@ public class XhpcRealTimeOrder extends BaseEntity {
/**
* 电池组最高温度
*/
private Double maxTemperature;
private Integer maxTemperature;
/**
* 累计充电时间
*/
@ -142,52 +144,52 @@ public class XhpcRealTimeOrder extends BaseEntity {
this.pileGunStatus = pileGunStatus;
}
public Long getVehicleGunStatus() {
public Integer getVehicleGunStatus() {
return vehicleGunStatus;
}
public void setVehicleGunStatus(Long vehicleGunStatus) {
public void setVehicleGunStatus(Integer vehicleGunStatus) {
this.vehicleGunStatus = vehicleGunStatus;
}
public Double getVoltage() {
public BigDecimal getVoltage() {
return voltage;
}
public void setVoltage(Double voltage) {
public void setVoltage(BigDecimal voltage) {
this.voltage = voltage;
}
public Double getElectricCurrent() {
public BigDecimal getElectricCurrent() {
return electricCurrent;
}
public void setElectricCurrent(Double electricCurrent) {
public void setElectricCurrent(BigDecimal electricCurrent) {
this.electricCurrent = electricCurrent;
}
public Double getGunLineTemperature() {
public Integer getGunLineTemperature() {
return gunLineTemperature;
}
public void setGunLineTemperature(Double gunLineTemperature) {
public void setGunLineTemperature(Integer gunLineTemperature) {
this.gunLineTemperature = gunLineTemperature;
}
public Double getGunLineNumber() {
public String getGunLineNumber() {
return gunLineNumber;
}
public void setGunLineNumber(Double gunLineNumber) {
public void setGunLineNumber(String gunLineNumber) {
this.gunLineNumber = gunLineNumber;
}
@ -202,12 +204,12 @@ public class XhpcRealTimeOrder extends BaseEntity {
this.soc = soc;
}
public Double getMaxTemperature() {
public Integer getMaxTemperature() {
return maxTemperature;
}
public void setMaxTemperature(Double maxTemperature) {
public void setMaxTemperature(Integer maxTemperature) {
this.maxTemperature = maxTemperature;
}

View File

@ -96,9 +96,20 @@ public interface HxpcChargeOrderMapper {
/**
* 获取运营商信息
* @param operatorId
* @param chargingStationId
* @return
*/
Map<String,Object> getOperatorMessage(@Param("chargingStationId") Long chargingStationId);
/**
* 删除之前的实时订单数据
*/
void deleteRealTimeOrder(@Param("chargingStationId")Long chargingOrderId);
void deleteChargeVoltage(@Param("chargingStationId")Long chargingOrderId);
void deleteChargeOrderSoc(@Param("chargingStationId")Long chargingOrderId);
void deleteChargeOrderCurrent(@Param("chargingStationId")Long chargingOrderId);
}

View File

@ -82,8 +82,13 @@ public interface IHxpcChargeOrderService {
/**
* 获取运营商信息
* @param operatorId
* @param chargingStationId
* @return
*/
Map<String,Object> getOperatorMessage( Long chargingStationId);
/**
* 删除之前的实时订单数据
*/
void deleteRealTimeOrder(Long chargingOrderId);
}

View File

@ -212,4 +212,12 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
return hxpcChargeOrderMapper.getOperatorMessage(chargingStationId);
}
@Override
public void deleteRealTimeOrder(Long chargingOrderId) {
hxpcChargeOrderMapper.deleteRealTimeOrder(chargingOrderId);
hxpcChargeOrderMapper.deleteChargeOrderCurrent(chargingOrderId);
hxpcChargeOrderMapper.deleteChargeOrderSoc(chargingOrderId);
hxpcChargeOrderMapper.deleteChargeVoltage(chargingOrderId);
}
}

View File

@ -285,4 +285,20 @@
maintenance_commission_rate as maintenanceCommissionRate
from xhpc_operator where operator_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</select>
<delete id="deleteRealTimeOrder">
delete from xhpc_real_time_order where charging_order_id=#{chargingOrderId}
</delete>
<delete id="deleteChargeVoltage">
delete from xhpc_charge_order_current where charging_order_id=#{chargingOrderId}
</delete>
<delete id="deleteChargeOrderSoc">
delete from xhpc_charge_order_soc where charging_order_id=#{chargingOrderId}
</delete>
<delete id="deleteChargeOrderCurrent">
delete from xhpc_charge_order_voltage where charging_order_id=#{chargingOrderId}
</delete>
</mapper>