mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-01 16:40:04 +08:00
Merge branch 'dev' of http://192.168.2.46:8099/jsowell/jsowell-charger-web into dev
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
package com.jsowell.pile.service.impl;
|
||||
|
||||
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 电单车发送指令service
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EBikeSendCommandService {
|
||||
|
||||
/**
|
||||
* 公共方法发送指令
|
||||
* @param pileSn 装编号
|
||||
* @param msg 消息
|
||||
* @param timeout 超时时间
|
||||
* @param unit 时间单位
|
||||
*/
|
||||
private void sendCommand(String pileSn, Class<? extends AbsEBikeMessage> msg, long timeout, TimeUnit unit) {
|
||||
// 通过桩编号获取channel
|
||||
ChannelHandlerContext ctx = PileChannelEntity.getChannelByPileSn(pileSn);
|
||||
if (Objects.isNull(ctx)) {
|
||||
log.error("push命令[{}]失败, 桩号:{}无法获取到长连接, 请检查充电桩连接状态!", "value", pileSn);
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,159 @@
|
||||
package com.jsowell.pile.service.impl;
|
||||
|
||||
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.RandomUtil;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.common.util.id.IdUtils;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import com.jsowell.pile.domain.ebike.serversend.EBikeMessageCmd82;
|
||||
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
|
||||
import com.jsowell.pile.domain.ykcCommond.StopChargingCommand;
|
||||
import com.jsowell.pile.service.EBikeSendCommandService;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
|
||||
@Override
|
||||
public void send(String pileSn, AbsEBikeMessage msg) {
|
||||
|
||||
// 过载功率, 单位0.1W, 2450 * 0.1 = 2450W
|
||||
private final int OVER_LOAD_POWER = 2450;
|
||||
|
||||
/**
|
||||
* 电单车发送启动充电指令
|
||||
*/
|
||||
@Override
|
||||
public void sendStartChargingCommand(StartChargingCommand command) {
|
||||
String pileSn = command.getPileSn();
|
||||
String connectorCode = command.getConnectorCode();
|
||||
String transactionCode = command.getTransactionCode();
|
||||
if (StringUtils.isBlank(transactionCode)) {
|
||||
transactionCode = IdUtils.generateTransactionCode(pileSn, connectorCode);
|
||||
}
|
||||
|
||||
// 组装参数
|
||||
EBikeMessageCmd82 message = new EBikeMessageCmd82();
|
||||
message.setPhysicalId(Integer.parseInt(pileSn));
|
||||
message.setMessageId(RandomUtil.getRandomNumber(4));
|
||||
message.setCommand("82");
|
||||
|
||||
EBikeMessageCmd82.SpecificData data = new EBikeMessageCmd82.SpecificData();
|
||||
// 充电模式
|
||||
data.setRateMode(3);
|
||||
// 余额或有效期
|
||||
data.setBalanceOrValidity(1234);
|
||||
// 端口号
|
||||
data.setPortNumber(Integer.parseInt(connectorCode));
|
||||
// 充电命令
|
||||
data.setChargeCommand(1);
|
||||
// 充电时长/功率
|
||||
int chargeDurationOrPower = 0;
|
||||
data.setChargeTimeOrPower(chargeDurationOrPower);
|
||||
|
||||
// 订单编号
|
||||
data.setTransactionCode(transactionCode);
|
||||
|
||||
// 最大充电时长
|
||||
data.setMaxChargeTime(0);
|
||||
// 过载功率
|
||||
data.setOverloadPower(OVER_LOAD_POWER);
|
||||
data.setQrCodeLight(0);
|
||||
data.setLongChargeMode(0);
|
||||
data.setExtraFloatChargeTime(0);
|
||||
data.setSkipShortCircuitDetection(0);
|
||||
data.setNoUserPullOutCheck(0);
|
||||
data.setForceAutoStopWhenFull(0);
|
||||
data.setFullChargePower(0);
|
||||
data.setMaxFullChargePowerCheckTime(0);
|
||||
message.setData(data);
|
||||
this.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送停止充电指令
|
||||
* @param command
|
||||
*/
|
||||
@Override
|
||||
public void sendStopChargingCommand(StopChargingCommand command) {
|
||||
String pileSn = command.getPileSn();
|
||||
String connectorCode = command.getConnectorCode();
|
||||
String transactionCode = command.getTransactionCode();
|
||||
|
||||
// 组装参数
|
||||
EBikeMessageCmd82 message = new EBikeMessageCmd82();
|
||||
message.setPhysicalId(Integer.parseInt(pileSn));
|
||||
message.setMessageId(RandomUtil.getRandomNumber(4));
|
||||
message.setCommand("82");
|
||||
|
||||
EBikeMessageCmd82.SpecificData data = new EBikeMessageCmd82.SpecificData();
|
||||
// 充电模式
|
||||
data.setRateMode(3);
|
||||
// 余额或有效期
|
||||
data.setBalanceOrValidity(1234);
|
||||
// 端口号
|
||||
data.setPortNumber(Integer.parseInt(connectorCode));
|
||||
// 充电命令
|
||||
data.setChargeCommand(0);
|
||||
// 充电时长/功率
|
||||
int chargeDurationOrPower = 0;
|
||||
data.setChargeTimeOrPower(chargeDurationOrPower);
|
||||
|
||||
// 订单编号
|
||||
data.setTransactionCode(transactionCode);
|
||||
|
||||
// 最大充电时长
|
||||
data.setMaxChargeTime(0);
|
||||
// 过载功率
|
||||
data.setOverloadPower(OVER_LOAD_POWER);
|
||||
data.setQrCodeLight(0);
|
||||
data.setLongChargeMode(0);
|
||||
data.setExtraFloatChargeTime(0);
|
||||
data.setSkipShortCircuitDetection(0);
|
||||
data.setNoUserPullOutCheck(0);
|
||||
data.setForceAutoStopWhenFull(0);
|
||||
data.setFullChargePower(0);
|
||||
data.setMaxFullChargePowerCheckTime(0);
|
||||
message.setData(data);
|
||||
this.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公共方法, 发送指令
|
||||
* @param msg
|
||||
*/
|
||||
private void send(AbsEBikeMessage msg) {
|
||||
String pileSn = msg.getPhysicalId() + "";
|
||||
byte[] messageBytes = msg.getMessageBytes();
|
||||
// PileChannelEntity.output();
|
||||
log.info("发送电单车send命令, pileSn:{}, messageBytes:{}", pileSn, BytesUtil.binary(messageBytes, 16));
|
||||
// 获取桩的channel
|
||||
ChannelHandlerContext ctx = PileChannelEntity.getChannelByPileSn(pileSn);
|
||||
if (Objects.isNull(ctx)) {
|
||||
log.error("电单车send命令失败, 桩号:{}无法获取到长连接, 请检查充电桩连接状态!", pileSn);
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
ByteBuf byteBuf = ctx.channel().alloc().buffer().writeBytes(messageBytes);
|
||||
ChannelFuture channelFuture = ctx.channel().writeAndFlush(byteBuf);
|
||||
channelFuture.addListener((ChannelFutureListener) channelFutureListener -> {
|
||||
// 检查操作的状态
|
||||
if (channelFutureListener.isSuccess()) {
|
||||
log.info("【电单车send结果===>成功】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
|
||||
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), msg.getCommand(), BytesUtil.binary(messageBytes, 16));
|
||||
} else {
|
||||
// 如果发生错误,则访问描述原因的Throwable
|
||||
Throwable cause = channelFutureListener.cause();
|
||||
log.info("【电单车send结果===>失败】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
|
||||
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), msg.getCommand(), BytesUtil.binary(messageBytes, 16));
|
||||
log.error("电单车send发送命令失败, pileSn:{}", pileSn, cause);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.PageUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.common.util.bean.BeanUtils;
|
||||
import com.jsowell.common.util.id.IdUtils;
|
||||
import com.jsowell.common.util.id.SnowflakeIdWorker;
|
||||
@@ -73,7 +74,6 @@ import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -573,21 +573,6 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
String str1 = "2024-08-12 09:41:02";
|
||||
// Date time = Date.parse();
|
||||
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date parse = null;
|
||||
try {
|
||||
parse = sdf1.parse(str1);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
System.out.println(currentTimeMillis - parse.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询充电中的订单,没有数据权限校验,后管不要用
|
||||
*
|
||||
@@ -2543,8 +2528,10 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
// 生成订单
|
||||
String orderCode = dto.getStartChargeSeq();
|
||||
String pileConnectorCode = dto.getConnectorID();
|
||||
String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
|
||||
String connectorCode = StringUtils.substring(pileConnectorCode, 14, 16);
|
||||
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
|
||||
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
|
||||
// String connectorCode = StringUtils.substring(pileConnectorCode, 14, 16);
|
||||
String connectorCode = YKCUtils.getConnectorCode(pileConnectorCode);
|
||||
|
||||
String transactionCode = IdUtils.generateTransactionCode(pileSn, connectorCode);
|
||||
|
||||
@@ -2554,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();
|
||||
@@ -2968,10 +2955,10 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
analysisPileParameter(dto);
|
||||
|
||||
// 校验充电桩相关的信息
|
||||
checkPileInfo(dto);
|
||||
checkPileInfoForEV(dto);
|
||||
|
||||
// 保存订单到数据库 saveOrder2Database
|
||||
return saveOrder2Database(dto);
|
||||
return saveOrderForEV(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2980,23 +2967,46 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
// @Override
|
||||
// public void analysisPileParameter(BasicPileDTO dto) {
|
||||
// if (StringUtils.isBlank(dto.getPileSn()) || StringUtils.isBlank(dto.getConnectorCode())) {
|
||||
// // 从pileConnectorCode解析
|
||||
// String pileConnectorCode = dto.getPileConnectorCode();
|
||||
// // dto.setPileSn(StringUtils.substring(pileConnectorCode, 0, pileConnectorCode.length() - 2));
|
||||
// // dto.setConnectorCode(StringUtils.substring(pileConnectorCode, pileConnectorCode.length() - 2, pileConnectorCode.length()));
|
||||
// dto.setPileSn(YKCUtils.getPileSn(pileConnectorCode));
|
||||
// dto.setConnectorCode(YKCUtils.getConnectorCode(pileConnectorCode));
|
||||
// } else {
|
||||
// // 说明pileSn 和 connectorCode前端传了,那就校验一下长度
|
||||
// if (dto.getPileSn().length() != Constants.PILE_SN_LENGTH_FOR_EV || dto.getConnectorCode().length() != Constants.CONNECTOR_CODE_LENGTH_FOR_EV
|
||||
// || dto.getPileSn().length() != Constants.PILE_SN_LENGTH_FOR_EBIKE || dto.getConnectorCode().length() != Constants.CONNECTOR_CODE_LENGTH_FOR_EBIKE) {
|
||||
// throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void analysisPileParameter(BasicPileDTO dto) {
|
||||
if (StringUtils.isBlank(dto.getPileSn()) || StringUtils.isBlank(dto.getConnectorCode())) {
|
||||
// 从pileConnectorCode解析
|
||||
String pileConnectorCode = dto.getPileConnectorCode();
|
||||
if (StringUtils.isNotEmpty(pileConnectorCode) && pileConnectorCode.length() == Constants.PILE_CONNECTOR_CODE_LENGTH) {
|
||||
dto.setPileSn(StringUtils.substring(pileConnectorCode, 0, pileConnectorCode.length() - 2));
|
||||
dto.setConnectorCode(StringUtils.substring(pileConnectorCode, pileConnectorCode.length() - 2, pileConnectorCode.length()));
|
||||
String pileSn = dto.getPileSn();
|
||||
String connectorCode = dto.getConnectorCode();
|
||||
String pileConnectorCode = dto.getPileConnectorCode();
|
||||
if (StringUtils.isBlank(pileSn) || StringUtils.isBlank(connectorCode)) {
|
||||
if (StringUtils.isBlank(pileConnectorCode)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
||||
} else {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR);
|
||||
}
|
||||
} else {
|
||||
// 说明pileSn 和 connectorCode前端传了,那就校验一下长度
|
||||
if (dto.getPileSn().length() != Constants.PILE_SN_LENGTH || dto.getConnectorCode().length() != Constants.CONNECTOR_CODE_LENGTH) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR);
|
||||
// 从pileConnectorCode解析
|
||||
pileSn = YKCUtils.getPileSn(pileConnectorCode);
|
||||
connectorCode = YKCUtils.getConnectorCode(pileConnectorCode);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isBlank(pileConnectorCode)) {
|
||||
if (StringUtils.isNotBlank(pileSn) && StringUtils.isNotBlank(connectorCode)) {
|
||||
pileConnectorCode = pileSn + connectorCode;
|
||||
}
|
||||
}
|
||||
dto.setPileConnectorCode(pileConnectorCode);
|
||||
dto.setPileSn(pileSn);
|
||||
dto.setConnectorCode(connectorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3499,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) {
|
||||
@@ -3549,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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存订单信息到数据库
|
||||
*
|
||||
@@ -3556,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)) {
|
||||
@@ -3641,7 +3691,111 @@ 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)
|
||||
|
||||
@@ -450,9 +450,9 @@ public class PileBillingTemplateServiceImpl implements PileBillingTemplateServic
|
||||
*/
|
||||
@Override
|
||||
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
|
||||
public int changeStationTemplate(String stationId, String templateId) {
|
||||
// 根据stationId把站点下所有的计费模板设置为 未启用
|
||||
pileBillingTemplateMapper.updateStatusByStationId(stationId, Constants.ZERO);
|
||||
public int changeStationTemplate(String stationId, String templateId, String deviceType) {
|
||||
// 根据stationId把站点下所有的计费模板设置为 未启用, 区分deviceType
|
||||
pileBillingTemplateMapper.updateStatusByStationId(stationId, Constants.ZERO, deviceType);
|
||||
// 根据templateId 修改状态为启用
|
||||
pileBillingTemplateMapper.updateStatusByTemplateId(templateId, Constants.ONE);
|
||||
// 清缓存
|
||||
|
||||
@@ -600,8 +600,7 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService {
|
||||
}
|
||||
String redisKey = CacheConstants.PILE_CONNECTOR_STATUS_KEY + pileConnectorCode; // 获取缓存
|
||||
String redisStatus = redisCache.getCacheObject(redisKey);
|
||||
// log.info("更新枪口状态-枪口编号:{}, redisKey:{}, 缓存状态:{}, 传来的状态:{}, 状态描述:{}", pileConnectorCode, redisKey,
|
||||
// redisStatus, status, PileConnectorDataBaseStatusEnum.getStatusDescription(status));
|
||||
|
||||
if (!StringUtils.equals(redisStatus, status)) {
|
||||
log.info("更新枪口状态ing-枪口编号:{}, redisKey:{}, 缓存状态:{}, 传来的状态:{}, 状态描述:{}", pileConnectorCode, redisKey,
|
||||
redisStatus, status, PileConnectorDataBaseStatusEnum.getStatusDescription(status));
|
||||
@@ -609,7 +608,7 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService {
|
||||
// 只修改一个枪口的状态
|
||||
num = pileConnectorInfoMapper.updateConnectorStatus(pileConnectorCode, status);
|
||||
deleteRedisByPileSnOrPileConnectorCode(pileSn, pileConnectorCode);
|
||||
redisCache.setCacheObject(redisKey, status, CacheConstants.cache_expire_time_3m);
|
||||
redisCache.setCacheObject(redisKey, status, CacheConstants.cache_expire_time_5m);
|
||||
|
||||
// 异步放缓存
|
||||
CompletableFuture.runAsync(() -> statusChange(pileConnectorCode));
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.pile.domain.PileMemberRelation;
|
||||
import com.jsowell.pile.domain.PileReservationInfo;
|
||||
import com.jsowell.pile.domain.ykcCommond.ReservationChargingCommand;
|
||||
@@ -504,8 +505,10 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic
|
||||
@Override
|
||||
public void personPileStopCharging(PersonPileStopChargingDTO dto) {
|
||||
String pileConnectorCode = dto.getPileConnectorCode();
|
||||
String pileSn = StringUtils.substring(pileConnectorCode, 0, pileConnectorCode.length() - 2);
|
||||
String connectorCode = StringUtils.substring(pileConnectorCode, pileConnectorCode.length() - 2, pileConnectorCode.length());
|
||||
// String pileSn = StringUtils.substring(pileConnectorCode, 0, pileConnectorCode.length() - 2);
|
||||
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
|
||||
// String connectorCode = StringUtils.substring(pileConnectorCode, pileConnectorCode.length() - 2, pileConnectorCode.length());
|
||||
String connectorCode = YKCUtils.getConnectorCode(pileConnectorCode);
|
||||
// 查询个人桩信息
|
||||
List<PileMemberRelation> pileMemberRelations = pileMemberRelationService.selectPileMemberRelationByPileSn(pileSn);
|
||||
Map<String, List<String>> listMap = pileMemberRelations.stream()
|
||||
|
||||
@@ -193,7 +193,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
|
||||
CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToWgs84(Double.parseDouble(pileStationInfo.getStationLng()), Double.parseDouble(pileStationInfo.getStationLat()));
|
||||
vo.setStationLat(String.format("%.6f", coordinate.getLat()));
|
||||
vo.setStationLng(String.format("%.6f", coordinate.getLng()));
|
||||
log.info("高德坐标:{}, 转天地图坐标:{}", pileStationInfo.getStationLng() + ", " + pileStationInfo.getStationLat(), vo.getStationLng() + ", " + vo.getStationLat());
|
||||
log.debug("高德坐标:{}, 转天地图坐标:{}", pileStationInfo.getStationLng() + ", " + pileStationInfo.getStationLat(), vo.getStationLng() + ", " + vo.getStationLat());
|
||||
}
|
||||
|
||||
vo.setCountryCode(pileStationInfo.getCountryCode());
|
||||
@@ -223,7 +223,8 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
|
||||
if (StringUtils.isBlank(pileConnectorCode)) {
|
||||
return null;
|
||||
}
|
||||
String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
|
||||
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
|
||||
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
|
||||
return getStationInfoByPileSn(pileSn);
|
||||
}
|
||||
|
||||
|
||||
@@ -281,6 +281,7 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
log.info("【=====平台下发充电指令=====】:订单id:{}, 桩号:{}, 枪口号:{}, 逻辑卡号:{}, 物理卡号:{}, 账户余额:{}",
|
||||
transactionCode, pileSn, BytesUtil.bcd2Str(connectorCodeByteArr), logicCardNum, physicsCardNum, chargeAmount);
|
||||
}
|
||||
@@ -314,7 +315,7 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
log.info("【=====平台下发指令=====】:获取充电桩:{} 的 {} 枪口实时数据信息", pileSn, connectorCode);
|
||||
log.info("【=====平台下发指令=====】:获取枪口实时数据信息, pileSn:{}, 枪口:{} ", pileSn, connectorCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -327,7 +328,6 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 下发二维码
|
||||
|
||||
Reference in New Issue
Block a user