新增 接收华为推送的订单信息接口

This commit is contained in:
Lemon
2024-01-31 16:03:07 +08:00
parent ad2ecbe20b
commit 91aca42700
2 changed files with 219 additions and 4 deletions

View File

@@ -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.ykc.OrderStatusEnum;
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.exception.BusinessException;
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.pile.domain.*;
import com.jsowell.pile.domain.huawei.HWStationInfo;
import com.jsowell.pile.dto.GenerateOrderDTO;
import com.jsowell.pile.dto.PushStationInfoDTO;
import com.jsowell.pile.dto.QueryStartChargeDTO;
import com.jsowell.pile.dto.huawei.*;
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.QueryChargeStatusVO;
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.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
@@ -84,6 +89,12 @@ public class HuaweiServiceV2 {
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Autowired
private MemberPlateNumberRelationService memberPlateNumberRelationService;
@Resource
private TransactionService transactionService;
@Autowired
private RedisCache redisCache;
@@ -583,7 +594,7 @@ public class HuaweiServiceV2 {
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);
// 在同一分钟内,只保留最后一条实时数据
redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", new Date()), jsonMsg);
@@ -651,7 +662,7 @@ public class HuaweiServiceV2 {
* @param vo
* @return
*/
public String receiveStopChargeResult(ReceiveStopChargeResultVO vo) {
public Map<String, String> receiveStopChargeResult(ReceiveStopChargeResultVO vo) {
String startChargeSeq = vo.getStartChargeSeq();
Integer startChargeSeqStat = vo.getStartChargeSeqStat();
Integer succStat = vo.getSuccStat();
@@ -663,7 +674,6 @@ public class HuaweiServiceV2 {
if (succStat == Constants.zero) {
// 成功标识为 0-成功,修改订单状态为 2-待结算,具体的订单金额等详情金额,从所推送的订单信息中取
orderBasicInfo.setOrderStatus(OrderStatusEnum.STAY_SETTLEMENT.getValue());
}else {
// 若成功标识为失败,则将失败原因记录存库
String reason = StopFailedReasonEnum.getReasonByCode(failReasonCode);
@@ -671,10 +681,131 @@ public class HuaweiServiceV2 {
}
// 统一修改订单
orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo);
// 回复华为消息
JSONObject jsonObject = new JSONObject();
jsonObject.put("StartChargeSeq", "startChargeSeq");
jsonObject.put("SuccStat", 0);
jsonObject.put("FailReason", 0);
return null;
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;
}
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;
}
/**