mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-07-03 21:48:13 +08:00
新增 接收华为推送的订单信息接口
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
package com.jsowell.pile.dto.huawei;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.jsowell.pile.vo.huawei.QueryChargeStatusVO;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收华为推送的订单信息
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2024/1/31 9:47:40
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ReceiveOrderInfoDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 充电订单号
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "StartChargeSeq")
|
||||||
|
private String startChargeSeq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 充电设备接口编码
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "ConnectorID")
|
||||||
|
private String connectorID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始充电时间
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "StartTime")
|
||||||
|
private String startTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束充电时间
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "EndTime")
|
||||||
|
private String endTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 累计充电量
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "TotalPower")
|
||||||
|
private BigDecimal totalPower;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总电费
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "TotalElecMoney")
|
||||||
|
private BigDecimal totalElecMoney;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总服务费
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "TotalSeviceMoney")
|
||||||
|
private BigDecimal totalSeviceMoney;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 累计总金额
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "TotalMoney")
|
||||||
|
private BigDecimal totalMoney;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 充电结束原因
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "StopReason")
|
||||||
|
private Integer stopReason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时段数N
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "SumPeriod")
|
||||||
|
private Integer sumPeriod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 充电明细信息
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "ChargeDetails")
|
||||||
|
private List<QueryChargeStatusVO.ChargeDetail> chargeDetails;
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import com.jsowell.common.enums.thirdparty.huawei.StartFailedReasonEnum;
|
|||||||
import com.jsowell.common.enums.thirdparty.huawei.StopFailedReasonEnum;
|
import com.jsowell.common.enums.thirdparty.huawei.StopFailedReasonEnum;
|
||||||
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
||||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||||
|
import com.jsowell.common.enums.ykc.StartModeEnum;
|
||||||
import com.jsowell.common.enums.ykc.StopChargingFailedReasonEnum;
|
import com.jsowell.common.enums.ykc.StopChargingFailedReasonEnum;
|
||||||
import com.jsowell.common.exception.BusinessException;
|
import com.jsowell.common.exception.BusinessException;
|
||||||
import com.jsowell.common.util.DateUtils;
|
import com.jsowell.common.util.DateUtils;
|
||||||
@@ -21,10 +22,13 @@ import com.jsowell.common.util.StringUtils;
|
|||||||
import com.jsowell.common.util.id.IdUtils;
|
import com.jsowell.common.util.id.IdUtils;
|
||||||
import com.jsowell.pile.domain.*;
|
import com.jsowell.pile.domain.*;
|
||||||
import com.jsowell.pile.domain.huawei.HWStationInfo;
|
import com.jsowell.pile.domain.huawei.HWStationInfo;
|
||||||
|
import com.jsowell.pile.dto.GenerateOrderDTO;
|
||||||
import com.jsowell.pile.dto.PushStationInfoDTO;
|
import com.jsowell.pile.dto.PushStationInfoDTO;
|
||||||
import com.jsowell.pile.dto.QueryStartChargeDTO;
|
import com.jsowell.pile.dto.QueryStartChargeDTO;
|
||||||
import com.jsowell.pile.dto.huawei.*;
|
import com.jsowell.pile.dto.huawei.*;
|
||||||
import com.jsowell.pile.service.*;
|
import com.jsowell.pile.service.*;
|
||||||
|
import com.jsowell.pile.transaction.dto.OrderTransactionDTO;
|
||||||
|
import com.jsowell.pile.transaction.service.TransactionService;
|
||||||
import com.jsowell.pile.vo.huawei.DeliverEquipBusinessPolicyVO;
|
import com.jsowell.pile.vo.huawei.DeliverEquipBusinessPolicyVO;
|
||||||
import com.jsowell.pile.vo.huawei.QueryChargeStatusVO;
|
import com.jsowell.pile.vo.huawei.QueryChargeStatusVO;
|
||||||
import com.jsowell.pile.vo.huawei.QueryEquipAuthVO;
|
import com.jsowell.pile.vo.huawei.QueryEquipAuthVO;
|
||||||
@@ -43,6 +47,7 @@ import org.apache.commons.collections4.CollectionUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -84,6 +89,12 @@ public class HuaweiServiceV2 {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ThirdPartyStationRelationService thirdPartyStationRelationService;
|
private ThirdPartyStationRelationService thirdPartyStationRelationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MemberPlateNumberRelationService memberPlateNumberRelationService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TransactionService transactionService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisCache redisCache;
|
private RedisCache redisCache;
|
||||||
|
|
||||||
@@ -583,7 +594,7 @@ public class HuaweiServiceV2 {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 将源数据存储至缓存
|
// 将源数据存储至缓存
|
||||||
String redisKey = "HUA_WEI_ORDER_INFO_BY_ORDER_CODE:" + startChargeSeq;
|
String redisKey = "HUA_WEI_REAL_TIME_INFO_BY_ORDER_CODE:" + startChargeSeq;
|
||||||
String jsonMsg = JSONObject.toJSONString(dto);
|
String jsonMsg = JSONObject.toJSONString(dto);
|
||||||
// 在同一分钟内,只保留最后一条实时数据
|
// 在同一分钟内,只保留最后一条实时数据
|
||||||
redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", new Date()), jsonMsg);
|
redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", new Date()), jsonMsg);
|
||||||
@@ -651,7 +662,7 @@ public class HuaweiServiceV2 {
|
|||||||
* @param vo
|
* @param vo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String receiveStopChargeResult(ReceiveStopChargeResultVO vo) {
|
public Map<String, String> receiveStopChargeResult(ReceiveStopChargeResultVO vo) {
|
||||||
String startChargeSeq = vo.getStartChargeSeq();
|
String startChargeSeq = vo.getStartChargeSeq();
|
||||||
Integer startChargeSeqStat = vo.getStartChargeSeqStat();
|
Integer startChargeSeqStat = vo.getStartChargeSeqStat();
|
||||||
Integer succStat = vo.getSuccStat();
|
Integer succStat = vo.getSuccStat();
|
||||||
@@ -663,7 +674,6 @@ public class HuaweiServiceV2 {
|
|||||||
if (succStat == Constants.zero) {
|
if (succStat == Constants.zero) {
|
||||||
// 成功标识为 0-成功,修改订单状态为 2-待结算,具体的订单金额等详情金额,从所推送的订单信息中取
|
// 成功标识为 0-成功,修改订单状态为 2-待结算,具体的订单金额等详情金额,从所推送的订单信息中取
|
||||||
orderBasicInfo.setOrderStatus(OrderStatusEnum.STAY_SETTLEMENT.getValue());
|
orderBasicInfo.setOrderStatus(OrderStatusEnum.STAY_SETTLEMENT.getValue());
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
// 若成功标识为失败,则将失败原因记录存库
|
// 若成功标识为失败,则将失败原因记录存库
|
||||||
String reason = StopFailedReasonEnum.getReasonByCode(failReasonCode);
|
String reason = StopFailedReasonEnum.getReasonByCode(failReasonCode);
|
||||||
@@ -671,10 +681,131 @@ public class HuaweiServiceV2 {
|
|||||||
}
|
}
|
||||||
// 统一修改订单
|
// 统一修改订单
|
||||||
orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo);
|
orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo);
|
||||||
|
// 回复华为消息
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("StartChargeSeq", "startChargeSeq");
|
||||||
|
jsonObject.put("SuccStat", 0);
|
||||||
|
jsonObject.put("FailReason", 0);
|
||||||
|
|
||||||
|
Map<String, String> resultMap = getResultMap(jsonObject);
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收订单信息
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Map<String, String> receiveOrderInfo(ReceiveOrderInfoDTO dto) {
|
||||||
|
String startChargeSeq = dto.getStartChargeSeq();
|
||||||
|
List<QueryChargeStatusVO.ChargeDetail> chargeDetails = dto.getChargeDetails();
|
||||||
|
String pileConnectorCode = dto.getConnectorID();
|
||||||
|
|
||||||
|
// 将源数据存缓存
|
||||||
|
String redisKey = "HUA_WEI_ORDER_INFO_BY_ORDER_CODE:" + startChargeSeq;
|
||||||
|
redisCache.setCacheObject(redisKey, dto);
|
||||||
|
|
||||||
|
// // 截取桩号
|
||||||
|
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
|
||||||
|
// // 查询该桩的站点id
|
||||||
|
// PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
|
||||||
|
// String stationId = String.valueOf(pileBasicInfo.getStationId());
|
||||||
|
// // 根据站点id查询正在使用的计费模板
|
||||||
|
// List<BillingPriceVO> billingPriceVOList = pileBillingTemplateService.queryBillingPrice(stationId);
|
||||||
|
// if (CollectionUtils.isEmpty(billingPriceVOList)) {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// 查出订单基本信息和详情
|
||||||
|
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(startChargeSeq);
|
||||||
|
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(startChargeSeq);
|
||||||
|
|
||||||
|
orderBasicInfo.setChargeStartTime(DateUtils.parseDate(dto.getStartTime()));
|
||||||
|
orderBasicInfo.setChargeEndTime(DateUtils.parseDate(dto.getEndTime()));
|
||||||
|
orderBasicInfo.setReason(String.valueOf(dto.getStopReason())); // TODO 新建停止原因枚举
|
||||||
|
|
||||||
|
orderDetail.setTotalUsedElectricity(dto.getTotalPower());
|
||||||
|
orderDetail.setTotalElectricityAmount(dto.getTotalElecMoney());
|
||||||
|
orderDetail.setTotalServiceAmount(dto.getTotalSeviceMoney());
|
||||||
|
orderDetail.setTotalOrderAmount(dto.getTotalMoney());
|
||||||
|
|
||||||
|
// if (CollectionUtils.isNotEmpty(chargeDetails)) {
|
||||||
|
// for (BillingPriceVO billingPriceVO : billingPriceVOList) {
|
||||||
|
// for (QueryChargeStatusVO.ChargeDetail chargeDetail : chargeDetails) {
|
||||||
|
// if (StringUtils.equals(chargeDetail.getDetailStartTime(), billingPriceVO.getStartTime())) {
|
||||||
|
// // 开始时间相等,则为同一时间段,将该时段的消费金额、用电量存入数据库
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// 通过事务修改订单信息
|
||||||
|
OrderTransactionDTO transactionDTO = OrderTransactionDTO.builder()
|
||||||
|
.orderBasicInfo(orderBasicInfo)
|
||||||
|
.orderDetail(orderDetail)
|
||||||
|
.build();
|
||||||
|
transactionService.doUpdateOrder(transactionDTO);
|
||||||
|
|
||||||
|
// 构建返回参数
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("StartChargeSeq", startChargeSeq);
|
||||||
|
jsonObject.put("ConnectorID", pileConnectorCode);
|
||||||
|
jsonObject.put("ConfirmResult", 0);
|
||||||
|
|
||||||
|
Map<String, String> resultMap = getResultMap(jsonObject);
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VIN启动充电
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public Map<String, String> vinStartCharge(VinStartChargeDTO dto) throws Exception {
|
||||||
|
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||||
|
if (configInfo == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String vinCode = dto.getVin();
|
||||||
|
String pileConnectorCode = dto.getConnectorID();
|
||||||
|
// 截取桩号、枪口号
|
||||||
|
String pileSn = StringUtils.substring(pileConnectorCode, 0, pileConnectorCode.length() - 2);
|
||||||
|
String connectorCode = StringUtils.substring(pileConnectorCode, pileConnectorCode.length() - 2, pileConnectorCode.length());
|
||||||
|
// 根据vin查询小程序平台用户信息
|
||||||
|
MemberPlateNumberRelation basicInfo = memberPlateNumberRelationService.getMemberPlateInfoByVinCode(vinCode);
|
||||||
|
if (basicInfo == null) {
|
||||||
|
// 该用户未注册
|
||||||
|
throw new BusinessException(ReturnCodeEnum.CODE_GENERATE_ORDER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成订单,并启动充电
|
||||||
|
GenerateOrderDTO generateOrderDTO = new GenerateOrderDTO();
|
||||||
|
generateOrderDTO.setMemberPlateNumberRelation(basicInfo);
|
||||||
|
generateOrderDTO.setPileSn(pileSn);
|
||||||
|
generateOrderDTO.setConnectorCode(connectorCode);
|
||||||
|
generateOrderDTO.setStartMode(StartModeEnum.VIN_CODE.getValue());
|
||||||
|
generateOrderDTO.setMemberId(basicInfo.getMemberId());
|
||||||
|
generateOrderDTO.setStartSoc(String.valueOf(dto.getSoc()));
|
||||||
|
|
||||||
|
int succStat = Constants.one; // 操作结果
|
||||||
|
int failReason = Constants.one; // 失败原因
|
||||||
|
Map<String, Object> map = orderBasicInfoService.generateOrderByCard(generateOrderDTO);
|
||||||
|
if (map != null) {
|
||||||
|
// 鉴权成功
|
||||||
|
succStat = Constants.zero;
|
||||||
|
failReason = Constants.zero;
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("SuccStat", succStat);
|
||||||
|
jsonObject.put("FailReason", failReason);
|
||||||
|
|
||||||
|
Map<String, String> resultMap = getResultMap(jsonObject);
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user