update 电单车

This commit is contained in:
Guoqs
2024-09-20 14:45:47 +08:00
parent dbc037727e
commit 00b442572a
12 changed files with 74 additions and 34 deletions

View File

@@ -6,6 +6,8 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.math.BigDecimal;
/**
* 启动充电指令
*/
@@ -16,7 +18,7 @@ import lombok.experimental.SuperBuilder;
@SuperBuilder
public class EBikeStartChargingCommand extends StartChargingCommand{
/**
* 费率模式
* 费率模式 =0计时=1包月=2计量=3计次。包月、计次默认充满自停计时、计量可手动设置时长和电量
*/
private int rateMode;
@@ -25,4 +27,9 @@ public class EBikeStartChargingCommand extends StartChargingCommand{
*/
private int balanceOrValidity;
/**
* 根据金额计算出电量
*/
private BigDecimal electricity;
}

View File

@@ -106,7 +106,9 @@ public interface PileBillingTemplateService {
* @param stationId 站点id
* @return
*/
BillingTemplateVO queryUsedBillingTemplate(String stationId);
BillingTemplateVO queryUsedBillingTemplateForEV(String stationId);
BillingTemplateVO queryUsedBillingTemplateForEBike(String stationId);
List<BillingPriceVO> conversionParameters(List<BillingDetailVO> billingDetailList);

View File

@@ -21,6 +21,7 @@ import com.jsowell.pile.dto.RemoteAccountBalanceUpdateDTO;
import com.jsowell.pile.dto.UpdateFirmwareDTO;
import com.jsowell.pile.vo.web.BillingTemplateVO;
import com.jsowell.pile.vo.web.PileDetailVO;
import com.jsowell.wxpay.service.WxAppletRemoteService;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,6 +55,9 @@ public class PileRemoteService {
@Autowired
private RedisCache redisCache;
@Autowired
private WxAppletRemoteService wxAppletRemoteService;
@Autowired
private EBikeSendCommandService eBikeSendCommandService;
@@ -108,6 +112,12 @@ public class PileRemoteService {
log.warn("远程启动充电, 充电桩编号和枪口号不能为空");
return;
}
// 发送启动充电指令前,再次下发计费模板
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn);
this.publishPileBillingTemplate(pileSn, billingTemplateVO);
log.info("发送启动充电指令前,再次下发计费模板, transactionCode:{}, 计费模板:{}", transactionCode, JSON.toJSONString(billingTemplateVO));
log.info("【=====平台下发指令=====】: 远程启动充电, 桩号:{}, 枪口号:{}", pileSn, connectorCode);
StartChargingCommand startChargingCommand = StartChargingCommand.builder()
.pileSn(pileSn)
@@ -131,7 +141,12 @@ public class PileRemoteService {
startChargingCommand.setPileSn(pileSn);
startChargingCommand.setConnectorCode(connectorCode);
startChargingCommand.setTransactionCode(transactionCode);
startChargingCommand.setChargeAmount(chargeAmount);
startChargingCommand.setChargeAmount(chargeAmount); // 电单车这个字段表示具体度数
startChargingCommand.setRateMode(2);
// 根据启动金额计算电量
BigDecimal electricity = BigDecimal.ZERO;
startChargingCommand.setElectricity(electricity);
try {
ChargingOperationResponse startChargingResponse = eBikeSendCommandService.sendStartChargingCommand(startChargingCommand);

View File

@@ -57,6 +57,9 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
message.setChargeCommand(1);
// 充电时长/功率
int chargeDurationOrPower = 0;
if (command.getElectricity() != null) {
chargeDurationOrPower = command.getElectricity().multiply(new BigDecimal("100")).intValue();
}
message.setChargeTimeOrPower(chargeDurationOrPower);
// 订单编号

View File

@@ -502,7 +502,8 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
/**
* 充电桩启动成功
*
* 汽车桩收到0x33 成功后调用
* 电单车桩,收到回复成功后调用
* @param transactionCode
*/
@Override
@@ -518,6 +519,9 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
orderInfo.setChargeStartTime(new Date());
}
updateOrderBasicInfo(orderInfo);
// 发送小程序通知
wxAppletRemoteService.startChargingSendMsg(orderInfo);
}
/**
@@ -1910,7 +1914,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
}
// 查到站点计费模板
BillingTemplateVO billingTemplate = pileBillingTemplateService.queryUsedBillingTemplate(stationId);
BillingTemplateVO billingTemplate = pileBillingTemplateService.queryUsedBillingTemplateForEV(stationId);
if (billingTemplate != null) {
// 尖时段服务费单价
orderDetail.setSharpServicePrice(billingTemplate.getSharpServicePrice());
@@ -3150,14 +3154,10 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
logger.error("订单:{}支付成功, 启动充电失败, 桩信息为空, pileSn:{}", dto.getOrderCode(), pileSn);
return;
}
// 发送启动充电指令前,再次下发计费模板
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn);
if (billingTemplateVO != null && !StringUtils.equals(pileConnectorDetailVO.getChargePortType(), Constants.THREE)) {
logger.info("发送启动充电指令前,再次下发计费模板, orderCode:{}, 计费模板:{}", orderInfo.getOrderCode(), JSON.toJSONString(billingTemplateVO));
pileRemoteService.publishPileBillingTemplate(pileSn, billingTemplateVO);
}
// 获取启动金额
BigDecimal chargeAmount = computeChargeAmount(orderInfo.getMerchantId(), orderInfo.getStationId(), orderInfo.getMemberId(), orderInfo.getPayAmount());
// 发送启动指令
if (StringUtils.equals(pileConnectorDetailVO.getChargePortType(), Constants.THREE)) {
// 电单车桩
@@ -3178,17 +3178,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
orderInfo.setRemedialAmount(remedialAmount.subtract(payAmount));
}
/*
推送小程序启动充电消息
通过memberId查询openId
*/
if (StringUtils.isNotBlank(orderInfo.getMemberId())) {
try {
wxAppletRemoteService.startChargingSendMsg(orderInfo.getMemberId(), orderInfo.getOrderCode());
} catch (Exception e) {
logger.error("推送小程序启动充电消息error", e);
}
}
this.updateOrderBasicInfo(orderInfo);
}

View File

@@ -316,7 +316,7 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
/*
查新站点计费模板
*/
BillingTemplateVO billingTemplate = pileBillingTemplateService.queryUsedBillingTemplate(orderPileOccupy.getStationId());
BillingTemplateVO billingTemplate = pileBillingTemplateService.queryUsedBillingTemplateForEV(orderPileOccupy.getStationId());
if (billingTemplate == null) {
log.info("计算占桩订单金额-查询站点:{}计费模板为空, 不收取占桩费用", orderPileOccupy.getStationId());
return resultAmount;

View File

@@ -375,7 +375,7 @@ public class PileBillingTemplateServiceImpl implements PileBillingTemplateServic
LocalTime localTime = LocalTime.now();
String now = LocalTime.of(localTime.getHour(), localTime.getMinute(), localTime.getSecond()).toString();
// 通过站点id查询计费模板
BillingTemplateVO billingTemplateVO = queryUsedBillingTemplate(stationId);
BillingTemplateVO billingTemplateVO = queryUsedBillingTemplateForEV(stationId);
if (Objects.nonNull(billingTemplateVO)) {
result = new CurrentTimePriceDetails();
result.setTemplateCode(billingTemplateVO.getTemplateCode());
@@ -629,9 +629,20 @@ public class PileBillingTemplateServiceImpl implements PileBillingTemplateServic
* @return
*/
@Override
public BillingTemplateVO queryUsedBillingTemplate(String stationId) {
public BillingTemplateVO queryUsedBillingTemplateForEV(String stationId) {
List<BillingTemplateVO> list = queryStationBillingTemplateListForUniApp(stationId);
Optional<BillingTemplateVO> max = list.stream()
.filter(x -> StringUtils.equals(x.getDeviceType(), Constants.ONE)) // 过滤出汽车桩的计费模板
.filter(x -> StringUtils.isNotBlank(x.getPublishTime()))
.max(Comparator.comparing(BillingTemplateVO::getPublishTime));
return max.orElse(null);
}
@Override
public BillingTemplateVO queryUsedBillingTemplateForEBike(String stationId) {
List<BillingTemplateVO> list = queryStationBillingTemplateListForUniApp(stationId);
Optional<BillingTemplateVO> max = list.stream()
.filter(x -> StringUtils.equals(x.getDeviceType(), Constants.TWO)) // 过滤出电单车桩的计费模板
.filter(x -> StringUtils.isNotBlank(x.getPublishTime()))
.max(Comparator.comparing(BillingTemplateVO::getPublishTime));
return max.orElse(null);
@@ -684,7 +695,7 @@ public class PileBillingTemplateServiceImpl implements PileBillingTemplateServic
@Override
public List<BillingPriceVO> queryBillingPriceOld(String stationId) {
// 查询站点当前计费模板 有缓存
BillingTemplateVO billingTemplateVO = queryUsedBillingTemplate(stationId);
BillingTemplateVO billingTemplateVO = queryUsedBillingTemplateForEV(stationId);
if (billingTemplateVO == null) {
return Lists.newArrayList();
}
@@ -737,7 +748,7 @@ public class PileBillingTemplateServiceImpl implements PileBillingTemplateServic
@Override
public List<BillingPriceVO> queryBillingPrice(String stationId) {
// 查询站点当前计费模板 有缓存
BillingTemplateVO billingTemplateVO = queryUsedBillingTemplate(stationId);
BillingTemplateVO billingTemplateVO = queryUsedBillingTemplateForEV(stationId);
if (billingTemplateVO == null) {
return Lists.newArrayList();
}

View File

@@ -927,7 +927,7 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
generateOrderDTO.setConnectorCode(connectorCode);
// 通过站点id查询计费模板
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.queryUsedBillingTemplate(dto.getStationId());
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.queryUsedBillingTemplateForEV(dto.getStationId());
generateOrderDTO.setBillingTemplate(billingTemplateVO);
OrderBasicInfo orderBasicInfo;

View File

@@ -15,6 +15,7 @@ import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.http.HttpUtils;
import com.jsowell.pile.domain.MemberBasicInfo;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.service.MemberBasicInfoService;
import com.jsowell.pile.service.OrderBasicInfoService;
import com.jsowell.pile.service.PileBillingTemplateService;
@@ -199,6 +200,17 @@ public class WxAppletRemoteService {
return this.startChargingSendMsg(sendMsgDTO);
}
public Map<String, String> startChargingSendMsg(OrderBasicInfo orderBasicInfo) {
MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMemberId(orderBasicInfo.getMemberId());
if (memberBasicInfo == null) {
throw new BusinessException("99999", "开始充电发送消息 error, 查询openid为空");
}
WechatSendMsgDTO sendMsgDTO = new WechatSendMsgDTO();
sendMsgDTO.setOpenId(memberBasicInfo.getOpenId());
sendMsgDTO.setOrderCode(orderBasicInfo.getOrderCode());
return this.startChargingSendMsg(sendMsgDTO);
}
/**
* 开始充电发送消息
* @param dto