This commit is contained in:
2023-07-08 09:44:05 +08:00
parent 07608b19c4
commit c8ef00867c
9 changed files with 644 additions and 158 deletions

View File

@@ -30,11 +30,9 @@ import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.common.util.bean.BeanUtils;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.service.*;
import com.jsowell.pile.transaction.dto.OrderTransactionDTO;
import com.jsowell.pile.transaction.service.TransactionService;
import com.jsowell.pile.vo.base.OrderAmountDetailVO;
import com.jsowell.pile.vo.base.OrderPeriodAmountVO;
@@ -136,24 +134,37 @@ public class OrderService {
* @return
*/
public String generateOrder(GenerateOrderDTO dto) throws ParseException {
log.info("generateOrder param:{}", JSONObject.toJSONString(dto));
// 处理前端传的参数
analysisPileParameter(dto);
// log.info("generateOrder param:{}", JSONObject.toJSONString(dto));
// // 处理前端传的参数
// analysisPileParameter(dto);
//
// // 校验充电桩相关的信息
// checkPileInfo(dto);
//
// // 保存订单到数据库 saveOrder2Database
// String orderCode = saveOrder2Database(dto);
// 校验充电桩相关的信息
checkPileInfo(dto);
// 保存订单到数据库 saveOrder2Database
String orderCode = saveOrder2Database(dto);
String orderCode = orderBasicInfoService.generateOrder(dto);
return orderCode;
}
/**
* 获取到vin 查询对应的用户,得到余额
*
* 生成订单
*
* 支付订单
*
*/
/**
* 订单支付
*
* @param dto
*/
public Map<String, Object> payOrder(PayOrderDTO dto) throws Exception {
orderBasicInfoService.payOrder(dto);
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode());
if (orderInfo == null) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_NULL_ERROR);
@@ -496,112 +507,112 @@ public class OrderService {
* @param dto
* @return
*/
private String saveOrder2Database(GenerateOrderDTO dto) throws ParseException {
String orderCode = IdUtils.getOrderCode();
String transactionCode = IdUtils.generateTransactionCode(dto.getPileSn(), dto.getConnectorCode());
if (StringUtils.isBlank(dto.getStartType())) {
dto.setStartType(StartTypeEnum.NOW.getValue());
}
String stationId = dto.getPileConnector().getStationId();
// 查询站点信息
PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(Long.valueOf(stationId));
String merchantId = pileStationInfo != null ? String.valueOf(pileStationInfo.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.getPileSn() + dto.getConnectorCode())
.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();
if (StringUtils.equals(dto.getStartType(), StartTypeEnum.APPOINTMENT.getValue())) {
orderBasicInfo.setAppointmentTime(DateUtils.parseDate(dto.getAppointmentTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
}
// 订单详情
BillingTemplateVO billingTemplate = dto.getBillingTemplate();
log.info("订单使用的计费模板-orderCode:{}, billingTemplate:{}", orderCode, JSONObject.toJSONString(billingTemplate));
BigDecimal sharpElectricityPrice = billingTemplate.getSharpElectricityPrice() != null ? billingTemplate.getSharpElectricityPrice() : BigDecimal.ZERO;
BigDecimal sharpServicePrice = billingTemplate.getSharpServicePrice() != null ? billingTemplate.getSharpServicePrice() : BigDecimal.ZERO;
BigDecimal peakElectricityPrice = billingTemplate.getPeakElectricityPrice() != null ? billingTemplate.getPeakElectricityPrice() : BigDecimal.ZERO;
BigDecimal peakServicePrice = billingTemplate.getPeakServicePrice() != null ? billingTemplate.getPeakServicePrice() : BigDecimal.ZERO;
BigDecimal flatElectricityPrice = billingTemplate.getFlatElectricityPrice() != null ? billingTemplate.getFlatElectricityPrice() : BigDecimal.ZERO;
BigDecimal flatServicePrice = billingTemplate.getFlatServicePrice() != null ? billingTemplate.getFlatServicePrice() : BigDecimal.ZERO;
BigDecimal valleyElectricityPrice = billingTemplate.getValleyElectricityPrice() != null ? billingTemplate.getValleyElectricityPrice() : BigDecimal.ZERO;
BigDecimal 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 orderCode;
}
// private String saveOrder2Database(GenerateOrderDTO dto) throws ParseException {
// String orderCode = IdUtils.getOrderCode();
// String transactionCode = IdUtils.generateTransactionCode(dto.getPileSn(), dto.getConnectorCode());
//
// if (StringUtils.isBlank(dto.getStartType())) {
// dto.setStartType(StartTypeEnum.NOW.getValue());
// }
//
// String stationId = dto.getPileConnector().getStationId();
// // 查询站点信息
// PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(Long.valueOf(stationId));
// String merchantId = pileStationInfo != null ? String.valueOf(pileStationInfo.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.getPileSn() + dto.getConnectorCode())
// .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();
// if (StringUtils.equals(dto.getStartType(), StartTypeEnum.APPOINTMENT.getValue())) {
// orderBasicInfo.setAppointmentTime(DateUtils.parseDate(dto.getAppointmentTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
// }
//
// // 订单详情
// BillingTemplateVO billingTemplate = dto.getBillingTemplate();
// log.info("订单使用的计费模板-orderCode:{}, billingTemplate:{}", orderCode, JSONObject.toJSONString(billingTemplate));
// BigDecimal sharpElectricityPrice = billingTemplate.getSharpElectricityPrice() != null ? billingTemplate.getSharpElectricityPrice() : BigDecimal.ZERO;
// BigDecimal sharpServicePrice = billingTemplate.getSharpServicePrice() != null ? billingTemplate.getSharpServicePrice() : BigDecimal.ZERO;
// BigDecimal peakElectricityPrice = billingTemplate.getPeakElectricityPrice() != null ? billingTemplate.getPeakElectricityPrice() : BigDecimal.ZERO;
// BigDecimal peakServicePrice = billingTemplate.getPeakServicePrice() != null ? billingTemplate.getPeakServicePrice() : BigDecimal.ZERO;
// BigDecimal flatElectricityPrice = billingTemplate.getFlatElectricityPrice() != null ? billingTemplate.getFlatElectricityPrice() : BigDecimal.ZERO;
// BigDecimal flatServicePrice = billingTemplate.getFlatServicePrice() != null ? billingTemplate.getFlatServicePrice() : BigDecimal.ZERO;
// BigDecimal valleyElectricityPrice = billingTemplate.getValleyElectricityPrice() != null ? billingTemplate.getValleyElectricityPrice() : BigDecimal.ZERO;
// BigDecimal 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 orderCode;
// }
/**
* 校验充电桩相关的信息
*
* @param dto
*/
private void checkPileInfo(GenerateOrderDTO dto) {
// 查询充电桩状态 是否空闲 枪口是否占用
PileConnectorDetailVO pileConnector = pileService.queryPileConnectorDetail(dto.getPileSn() + dto.getConnectorCode());
if (pileConnector == null) {
log.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.equals(pileConnector.getConnectorStatus(), PileConnectorDataBaseStatusEnum.FREE.getValue())
|| StringUtils.equals(pileConnector.getConnectorStatus(), PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue()))) {
log.error("checkPileInfo充电枪口状态不正确当前状态为:{}", pileConnector.getConnectorStatus());
throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_ERROR);
}
// 查询充电桩的计费模板
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(dto.getPileSn());
if (billingTemplateVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_BILLING_TEMPLATE_NULL_ERROR);
}
dto.setPileConnector(pileConnector);
dto.setBillingTemplate(billingTemplateVO);
}
// private void checkPileInfo(GenerateOrderDTO dto) {
// // 查询充电桩状态 是否空闲 枪口是否占用
// PileConnectorDetailVO pileConnector = pileService.queryPileConnectorDetail(dto.getPileSn() + dto.getConnectorCode());
// if (pileConnector == null) {
// log.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.equals(pileConnector.getConnectorStatus(), PileConnectorDataBaseStatusEnum.FREE.getValue())
// || StringUtils.equals(pileConnector.getConnectorStatus(), PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue()))) {
// log.error("checkPileInfo充电枪口状态不正确当前状态为:{}", pileConnector.getConnectorStatus());
// throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_ERROR);
// }
// // 查询充电桩的计费模板
// BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(dto.getPileSn());
// if (billingTemplateVO == null) {
// throw new BusinessException(ReturnCodeEnum.CODE_BILLING_TEMPLATE_NULL_ERROR);
// }
// dto.setPileConnector(pileConnector);
// dto.setBillingTemplate(billingTemplateVO);
// }
/**
@@ -610,23 +621,23 @@ public class OrderService {
*
* @param dto
*/
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()));
} 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);
}
}
}
// 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()));
// } 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);
// }
// }
// }
/**
* 结算订单
@@ -635,7 +646,7 @@ public class OrderService {
* @param dto 结算订单参数
*/
public void settleOrderForWeb(SettleOrderDTO dto) {
analysisPileParameter(dto);
orderBasicInfoService.analysisPileParameter(dto);
// 查询订单详情,验证订单中的桩编号是否正确
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode());
if (orderBasicInfo == null) {