update 电单车协议

This commit is contained in:
Guoqs
2024-09-05 11:19:15 +08:00
parent b341862071
commit 4c8362b80c
5 changed files with 153 additions and 17 deletions

View File

@@ -627,7 +627,7 @@ public class SpringBootTestController {
// 查询充电桩的计费模板
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(dto.getPileSn());
dto.setBillingTemplate(billingTemplateVO);
OrderBasicInfo orderBasicInfo = orderBasicInfoService.saveOrder2Database(dto);
OrderBasicInfo orderBasicInfo = orderBasicInfoService.saveOrderForEV(dto);
return orderBasicInfo;
}

View File

@@ -91,7 +91,9 @@ public interface OrderBasicInfoService{
* 【公共方法】
* @param dto
*/
void checkPileInfo(GenerateOrderDTO dto);
void checkPileInfoForEV(GenerateOrderDTO dto);
void checkPileInfoForEBike(GenerateOrderDTO dto);
/**
* 保存订单到数据库 saveOrder2Database
@@ -100,7 +102,9 @@ public interface OrderBasicInfoService{
* @return
* @throws ParseException
*/
OrderBasicInfo saveOrder2Database(GenerateOrderDTO dto) throws ParseException;
OrderBasicInfo saveOrderForEV(GenerateOrderDTO dto) throws ParseException;
OrderBasicInfo saveOrderForEBike(GenerateOrderDTO dto) throws ParseException;
/**
* 修改订单

View File

@@ -2541,7 +2541,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
generateOrderDTO.setConnectorCode(connectorCode);
generateOrderDTO.setStartMode(StartModeEnum.THIRD_PARTY_PLATFORM.getValue());
checkPileInfo(generateOrderDTO);
checkPileInfoForEV(generateOrderDTO);
// 通过桩号查询所属站点
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
Long stationId = pileBasicInfo.getStationId();
@@ -2955,10 +2955,10 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
analysisPileParameter(dto);
// 校验充电桩相关的信息
checkPileInfo(dto);
checkPileInfoForEV(dto);
// 保存订单到数据库 saveOrder2Database
return saveOrder2Database(dto);
return saveOrderForEV(dto);
}
/**
@@ -3509,7 +3509,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
* @param dto
*/
@Override
public void checkPileInfo(GenerateOrderDTO dto) {
public void checkPileInfoForEV(GenerateOrderDTO dto) {
// 查询充电桩状态 是否空闲 枪口是否占用
PileConnectorDetailVO pileConnector = pileBasicInfoService.queryPileConnectorDetail(dto.getPileSn() + dto.getConnectorCode());
if (pileConnector == null) {
@@ -3559,6 +3559,46 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
dto.setBillingTemplate(billingTemplateVO);
}
@Override
public void checkPileInfoForEBike(GenerateOrderDTO dto) {
// 查询充电桩状态 是否空闲 枪口是否占用
PileConnectorDetailVO pileConnector = pileBasicInfoService.queryPileConnectorDetail(dto.getPileConnectorCode());
if (pileConnector == null) {
logger.error("checkPileInfo充电枪口为空 pileSn:{}, connectorCode:{}", dto.getPileSn(), dto.getConnectorCode());
throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR);
}
// 查询站点状态
PileStationVO stationInfo = pileStationInfoService.getStationInfo(pileConnector.getStationId());
if (stationInfo == null || StringUtils.equals(stationInfo.getOpenFlag(), Constants.ZERO)) {
throw new BusinessException(ReturnCodeEnum.CODE_STATION_IS_NOT_OPEN);
}
// 校验启动桩使用的小程序,和充电桩所属一级运营商是否一致
if (StringUtils.isNotBlank(dto.getAppId())) {
String merchantIdByAppId = "";
if (StringUtils.equals(dto.getRequestSource(), AdapayPayChannelEnum.ALIPAY_LITE.getValue())) {
// 支付宝小程序
merchantIdByAppId = pileMerchantInfoService.getDelayModeByAlipayAppId(dto.getAppId());
}else {
// 微信小程序
merchantIdByAppId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(dto.getAppId());
}
String merchantIdByMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByMerchantId(stationInfo.getMerchantId());
if (!StringUtils.equals(merchantIdByAppId, merchantIdByMerchantId)) {
throw new BusinessException("", "当前桩运营商与小程序所属运营商不一致");
}
}
// 查询充电桩的计费模板
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(dto.getPileSn());
if (billingTemplateVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_BILLING_TEMPLATE_NULL_ERROR);
}
dto.setPileConnector(pileConnector);
dto.setBillingTemplate(billingTemplateVO);
}
/**
* 保存订单信息到数据库
*
@@ -3566,7 +3606,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
* @return
*/
@Override
public OrderBasicInfo saveOrder2Database(GenerateOrderDTO dto) throws ParseException {
public OrderBasicInfo saveOrderForEV(GenerateOrderDTO dto) throws ParseException {
String orderCode = generateNewOrderCode();
String transactionCode = dto.getTransactionCode();
if (StringUtils.isBlank(transactionCode)) {
@@ -3651,7 +3691,95 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
flatServicePrice = billingTemplate.getFlatServicePrice() != null ? billingTemplate.getFlatServicePrice() : BigDecimal.ZERO;
valleyElectricityPrice = billingTemplate.getValleyElectricityPrice() != null ? billingTemplate.getValleyElectricityPrice() : BigDecimal.ZERO;
valleyServicePrice = billingTemplate.getValleyServicePrice() != null ? billingTemplate.getValleyServicePrice() : BigDecimal.ZERO;
}
OrderDetail orderDetail = OrderDetail.builder()
.orderCode(orderCode)
.sharpPrice(sharpElectricityPrice.add(sharpServicePrice))
.sharpElectricityPrice(sharpElectricityPrice)
.sharpServicePrice(sharpServicePrice)
.peakPrice(peakElectricityPrice.add(peakServicePrice))
.peakElectricityPrice(peakElectricityPrice)
.peakServicePrice(peakServicePrice)
.flatPrice(flatElectricityPrice.add(flatServicePrice))
.flatElectricityPrice(flatElectricityPrice)
.flatServicePrice(flatServicePrice)
.valleyPrice(valleyElectricityPrice.add(valleyServicePrice))
.valleyElectricityPrice(valleyElectricityPrice)
.valleyServicePrice(valleyServicePrice)
.build();
// 保存到数据库
OrderTransactionDTO createOrderTransactionDTO = OrderTransactionDTO.builder()
.orderBasicInfo(orderBasicInfo)
.orderDetail(orderDetail)
.build();
pileTransactionService.doCreateOrder(createOrderTransactionDTO);
return orderBasicInfo;
}
/**
* 保存电单车订单信息
* @param dto
* @return
* @throws ParseException
*/
@Override
public OrderBasicInfo saveOrderForEBike(GenerateOrderDTO dto) throws ParseException {
String orderCode = generateNewOrderCode();
String transactionCode = dto.getTransactionCode();
if (StringUtils.isBlank(transactionCode)) {
transactionCode = IdUtils.generateTransactionCode(dto.getPileSn(), dto.getConnectorCode());
}
// 启动类型, 默认立即启动
if (StringUtils.isBlank(dto.getStartType())) {
dto.setStartType(StartTypeEnum.NOW.getValue());
}
String stationId = dto.getPileConnector().getStationId();
String merchantId = dto.getPileConnector().getMerchantId();
// 订单基本信息
OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder()
.orderCode(orderCode)
.transactionCode(transactionCode)
.orderStatus(OrderStatusEnum.NOT_START.getValue())
.memberId(dto.getMemberId())
.stationId(stationId)
.merchantId(merchantId)
.pileSn(dto.getPileSn())
.connectorCode(dto.getConnectorCode())
.pileConnectorCode(dto.getPileConnectorCode())
.startMode(dto.getStartMode())
.payStatus(Constants.ZERO)
// .payAmount(dto.getChargeAmount()) // 支付完成后填入支付金额
.payMode(dto.getPayMode())
.orderAmount(BigDecimal.ZERO)
.virtualAmount(BigDecimal.ZERO)
.settleAmount(BigDecimal.ZERO)
.startType(dto.getStartType())
.build();
// 订单详情
BillingTemplateVO billingTemplate = dto.getBillingTemplate();
logger.info("订单使用的计费模板-orderCode:{}, billingTemplate:{}", orderCode, JSON.toJSONString(billingTemplate));
BigDecimal sharpElectricityPrice = BigDecimal.ZERO; // 尖时段电费单价
BigDecimal sharpServicePrice = BigDecimal.ZERO; // 尖时段服务费单价
BigDecimal peakElectricityPrice = BigDecimal.ZERO; // 峰时段电费单价
BigDecimal peakServicePrice = BigDecimal.ZERO; // 峰时段服务费单价
BigDecimal flatElectricityPrice = BigDecimal.ZERO; // 平时段电费单价
BigDecimal flatServicePrice = BigDecimal.ZERO; // 平时段服务费单价
BigDecimal valleyElectricityPrice = BigDecimal.ZERO; // 谷时段电费单价
BigDecimal valleyServicePrice = BigDecimal.ZERO; // 谷时段服务费单价
if (billingTemplate != null) {
sharpElectricityPrice = billingTemplate.getSharpElectricityPrice() != null ? billingTemplate.getSharpElectricityPrice() : BigDecimal.ZERO;
sharpServicePrice = billingTemplate.getSharpServicePrice() != null ? billingTemplate.getSharpServicePrice() : BigDecimal.ZERO;
peakElectricityPrice = billingTemplate.getPeakElectricityPrice() != null ? billingTemplate.getPeakElectricityPrice() : BigDecimal.ZERO;
peakServicePrice = billingTemplate.getPeakServicePrice() != null ? billingTemplate.getPeakServicePrice() : BigDecimal.ZERO;
flatElectricityPrice = billingTemplate.getFlatElectricityPrice() != null ? billingTemplate.getFlatElectricityPrice() : BigDecimal.ZERO;
flatServicePrice = billingTemplate.getFlatServicePrice() != null ? billingTemplate.getFlatServicePrice() : BigDecimal.ZERO;
valleyElectricityPrice = billingTemplate.getValleyElectricityPrice() != null ? billingTemplate.getValleyElectricityPrice() : BigDecimal.ZERO;
valleyServicePrice = billingTemplate.getValleyServicePrice() != null ? billingTemplate.getValleyServicePrice() : BigDecimal.ZERO;
}
OrderDetail orderDetail = OrderDetail.builder()
.orderCode(orderCode)

View File

@@ -68,7 +68,6 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
*/
@Override
public OrderBasicInfo generateOrder(GenerateOrderDTO dto) throws ParseException {
logger.info("【{}】-生成订单start, param:{}", this.getClass().getSimpleName(), JSON.toJSONString(dto));
// 处理前端传的参数
orderBasicInfoService.analysisPileParameter(dto);
@@ -90,23 +89,28 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
* @throws ParseException
*/
private OrderBasicInfo generateOrderForEV(GenerateOrderDTO dto) throws ParseException {
logger.info("【{}】-生成电动汽车订单start, param:{}", this.getClass().getSimpleName(), JSON.toJSONString(dto));
// 校验充电桩相关的信息
if (StringUtils.isBlank(dto.getTransactionCode())) {
// 无transactionCode, 表示由平台端启动充电, 需要验证充电桩状态
orderBasicInfoService.checkPileInfo(dto);
orderBasicInfoService.checkPileInfoForEV(dto);
}
// 保存订单到数据库 saveOrder2Database
return orderBasicInfoService.saveOrder2Database(dto);
return orderBasicInfoService.saveOrderForEV(dto);
}
/**
* 生成电单车订单
* 生成电单车订单/电单车生成订单
*/
private OrderBasicInfo generateOrderForEBike(GenerateOrderDTO dto) {
private OrderBasicInfo generateOrderForEBike(GenerateOrderDTO dto) throws ParseException {
logger.info("【{}】-生成电单车订单start, param:{}", this.getClass().getSimpleName(), JSON.toJSONString(dto));
return null;
// 校验充电桩相关的信息
if (StringUtils.isBlank(dto.getTransactionCode())) {
// 无transactionCode, 表示由平台端启动充电, 需要验证充电桩状态
orderBasicInfoService.checkPileInfoForEBike(dto);
}
return orderBasicInfoService.saveOrderForEBike(dto);
}
/**

View File

@@ -72,11 +72,11 @@ public class NotDelayMerchantProgramLogic extends AbstractProgramLogic {
// 校验充电桩相关的信息
if (StringUtils.isBlank(dto.getTransactionCode())) {
// 无transactionCode, 表示由平台端启动充电, 需要验证充电桩状态
orderBasicInfoService.checkPileInfo(dto);
orderBasicInfoService.checkPileInfoForEV(dto);
}
// 保存订单到数据库 saveOrder2Database
return orderBasicInfoService.saveOrder2Database(dto);
return orderBasicInfoService.saveOrderForEV(dto);
}
@Override