手动结算电单车订单逻辑update

This commit is contained in:
Guoqs
2025-02-19 09:05:32 +08:00
parent beff27951b
commit 9c9d4632e0
4 changed files with 42 additions and 21 deletions

View File

@@ -14,6 +14,7 @@ import com.google.common.collect.Sets;
import com.huifu.adapay.core.AdapayCore;
import com.huifu.adapay.core.util.AdapaySign;
import com.jsowell.adapay.vo.PaymentInfo;
import com.jsowell.common.YouDianUtils;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
@@ -27,6 +28,7 @@ import com.jsowell.common.enums.InvoiceRecordEnum;
import com.jsowell.common.enums.MemberWalletEnum;
import com.jsowell.common.enums.adapay.AdapayEventEnum;
import com.jsowell.common.enums.adapay.AdapayPayChannelEnum;
import com.jsowell.common.enums.ebike.EBikeStopReasonEnum;
import com.jsowell.common.enums.uniapp.OccupyOrderPayStatusEnum;
import com.jsowell.common.enums.uniapp.OccupyOrderStatusEnum;
import com.jsowell.common.enums.ykc.*;
@@ -37,6 +39,7 @@ import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.bean.BeanUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd03;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.service.*;
import com.jsowell.pile.service.programlogic.AbstractProgramLogic;
@@ -774,19 +777,27 @@ public class OrderService {
}
}
// 结算订单 新逻辑
String mode = pileMerchantInfoService.getDelayModeByMerchantId(orderBasicInfo.getMerchantId());
AbstractProgramLogic orderLogic = ProgramLogicFactory.getProgramLogic(mode);
// 判断汽车还是电单车
String pileSn = orderBasicInfo.getPileSn();
if (YouDianUtils.isEBikePileSn(pileSn)) {
// 电单车桩
EBikeMessageCmd03 message = new EBikeMessageCmd03(new BigDecimal(chargingDegree), EBikeStopReasonEnum.EXTERNAL_OPERATION_STOPPED.getCode());
orderLogic.settleOrderForEBike(message, orderBasicInfo);
} else {
// 汽车桩
// 组装交易记录数据
TransactionRecordsData data = new TransactionRecordsData();
data.setConsumptionAmount(chargingAmount); // 总消费金额
data.setTotalElectricity(chargingDegree); // 总用电量
data.setStopReasonMsg("人工结算订单,操作人:" + SecurityUtils.getUsername()); // 停止原因
// 结算订单 新逻辑
String mode = pileMerchantInfoService.getDelayModeByMerchantId(orderBasicInfo.getMerchantId());
AbstractProgramLogic orderLogic = ProgramLogicFactory.getProgramLogic(mode);
orderLogic.settleOrder(data, orderBasicInfo);
}
// 发送停止充电指令
pileRemoteService.remoteStopCharging(orderBasicInfo.getPileSn(), orderBasicInfo.getConnectorCode(), orderBasicInfo.getTransactionCode());
pileRemoteService.remoteStopCharging(pileSn, orderBasicInfo.getConnectorCode(), orderBasicInfo.getTransactionCode());
log.info("人工结算订单-end orderCode:{}", dto.getOrderCode());

View File

@@ -158,7 +158,7 @@ public class OrderBasicInfoController extends BaseController {
/**
* 人工结算订单/手动结算逻辑/手动结算按钮
* 人工结算订单/手动结算逻辑/手动结算按钮/手动结算订单
* http://localhost:8080/order/manualSettlementOrder
*/
@PostMapping("/manualSettlementOrder")

View File

@@ -28,6 +28,12 @@ public class EBikeMessageCmd03 extends AbsEBikeMessage2 {
// private String timestamp; // 时间戳 上发指令当时的时间,有时候不准确,该字段属于调试使用,服务器无需关心此字段
// private String placeholderDuration; // 占位时长 充电柜专用,其他设备忽略此字段 表示充满后占用设备的时长,单位为分钟
// 构造方法, 使用consumedEnergy stopReason字段构造对象
public EBikeMessageCmd03(BigDecimal consumedEnergy, int stopReason) {
this.consumedEnergy = consumedEnergy;
this.stopReason= stopReason;
}
public EBikeMessageCmd03(byte[] messageBytes) {
super(messageBytes);

View File

@@ -535,18 +535,22 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderBasicInfo.getOrderCode());
// 订单消费金额, 除了充满自停是需要计算实际消费, 其他金额都是按次收费
BigDecimal orderAmount;
if (fullOfSelfStopping.compareTo(orderBasicInfo.getPayAmount()) == 0) {
// 耗电量
BigDecimal consumedEnergy = message.getConsumedEnergy();
// 计费模板
BigDecimal flatElectricityPrice = orderDetail.getFlatElectricityPrice(); // x元/每度
BigDecimal flatServicePrice = orderDetail.getFlatServicePrice(); // x元/每度
if (consumedEnergy == null || flatElectricityPrice == null) {
logger.info("计算电单车退款逻辑,耗电量或计费模板为空,不执行退款逻辑, orderCode:{}, 耗电量:{}, 每度电费:{}", orderBasicInfo.getOrderCode(), consumedEnergy, flatElectricityPrice);
return;
}
if (fullOfSelfStopping.compareTo(orderBasicInfo.getPayAmount()) == 0) {
// 计费模板, 只取平时段的价格
BigDecimal flatElectricityPrice = orderDetail.getFlatElectricityPrice() != null ? orderDetail.getFlatElectricityPrice() : BigDecimal.ZERO; // x元/每度
// BigDecimal flatServicePrice = orderDetail.getFlatServicePrice() != null ? orderDetail.getFlatServicePrice() : BigDecimal.ZERO; // x元/每度
BigDecimal flatServicePrice = BigDecimal.ZERO; // x元/每度 服务费默认0
// 单价 = 电费单价 + 服务费单价
BigDecimal price = flatElectricityPrice.add(flatServicePrice);
// 如果耗电量或单价为空或者为0则订单消费为0
// if (consumedEnergy == null || consumedEnergy.compareTo(BigDecimal.ZERO) == 0 || price.compareTo(BigDecimal.ZERO) == 0) {
// logger.info("计算电单车退款逻辑,耗电量或计费模板为空,不执行退款逻辑, orderCode:{}, 耗电量:{}, 每度电费:{}", orderBasicInfo.getOrderCode(), consumedEnergy, price);
// return;
// }
// 计算实际消费
orderAmount = consumedEnergy.multiply(flatElectricityPrice);
orderAmount = consumedEnergy.multiply(price);
} else {
// 其他金额都是按次收费, 不退款
orderAmount = orderBasicInfo.getPayAmount();
@@ -579,8 +583,8 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
// 更新订单详情
if (orderDetail != null) {
orderDetail.setTotalUsedElectricity(message.getConsumedEnergy());
orderDetail.setFlatUsedElectricity(message.getConsumedEnergy());
orderDetail.setTotalUsedElectricity(consumedEnergy);
orderDetail.setFlatUsedElectricity(consumedEnergy);
orderDetail.setTotalElectricityAmount(orderAmount); // 电费总金额
orderDetail.setTotalServiceAmount(BigDecimal.ZERO); // 服务费总金额
orderDetail.setTotalOrderAmount(orderDetail.getTotalElectricityAmount().add(orderDetail.getTotalServiceAmount())); // 总消费金额