diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/AbstractOrderLogic.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/AbstractOrderLogic.java index 0c429a985..0e7f1fbfe 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/AbstractOrderLogic.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/AbstractOrderLogic.java @@ -14,14 +14,12 @@ import com.jsowell.common.enums.ykc.*; import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.StringUtils; -import com.jsowell.common.util.id.IdUtils; import com.jsowell.pile.domain.*; import com.jsowell.pile.dto.BasicPileDTO; import com.jsowell.pile.dto.GenerateOrderDTO; import com.jsowell.pile.dto.PayOrderDTO; import com.jsowell.pile.dto.PayOrderSuccessCallbackDTO; import com.jsowell.pile.service.*; -import com.jsowell.pile.transaction.dto.OrderTransactionDTO; import com.jsowell.pile.transaction.service.TransactionService; import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO; import com.jsowell.pile.vo.web.BalanceDeductionAmountVO; @@ -51,13 +49,13 @@ public abstract class AbstractOrderLogic implements InitializingBean { protected IOrderBasicInfoService orderBasicInfoService; @Autowired - private IPileBasicInfoService pileBasicInfoService; + protected IPileBasicInfoService pileBasicInfoService; @Autowired - private IPileStationInfoService pileStationInfoService; + protected IPileStationInfoService pileStationInfoService; @Autowired - private IPileBillingTemplateService pileBillingTemplateService; + protected IPileBillingTemplateService pileBillingTemplateService; @Autowired protected IMemberBasicInfoService memberBasicInfoService; @@ -118,15 +116,7 @@ public abstract class AbstractOrderLogic implements InitializingBean { */ public abstract void settleOrder(TransactionRecordsData data, OrderBasicInfo orderBasicInfo); - /** - * 余额支付订单退款 - */ - // public abstract void balancePaymentOrderRefund(OrderBasicInfo orderBasicInfo); - /** - * 在线支付订单退款 - */ - // public abstract void onlinePaymentOrderRefund(OrderBasicInfo orderBasicInfo); /** * 订单支付成功 支付回调 @@ -211,110 +201,7 @@ public abstract class AbstractOrderLogic implements InitializingBean { dto.setBillingTemplate(billingTemplateVO); } - /** - * 生成订单编号 - * - * @return - */ - private String generateNewOrderCode() { - while (true) { - String orderCode = "C" + IdUtils.getOrderCode(); - // 通过orderCode查询是否已经存在 - OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - if (orderBasicInfo == null) { - return orderCode; - } - } - } - /** - * 保存订单信息到数据库 - * - * @param dto - * @return - */ - protected OrderBasicInfo saveOrder2Database(GenerateOrderDTO dto) throws ParseException { - String orderCode = generateNewOrderCode(); - 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()) : ""; - String plateNumber = dto.getPlateNumber() != null ? dto.getPlateNumber() : ""; - // 订单基本信息 - 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()) - .plateNumber(plateNumber) - .orderAmount(BigDecimal.ZERO) - .virtualAmount(BigDecimal.ZERO) - .settleAmount(BigDecimal.ZERO) - .startType(dto.getStartType()) - .build(); - if (StringUtils.equals(dto.getStartMode(), StartModeEnum.AUTH_CARD.getValue())) { - // 鉴权卡启动 - orderBasicInfo.setLogicCard(dto.getPileAuthCardInfo().getLogicCard()); - } - if (StringUtils.equals(dto.getStartMode(), StartModeEnum.VIN_CODE.getValue())) { - // vin启动 - orderBasicInfo.setVinCode(dto.getMemberPlateNumberRelation().getVinCode()); - } - - 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(); - logger.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(); - transactionService.doCreateOrder(createOrderTransactionDTO); - return orderBasicInfo; - } /** * 返回更新后的OrderBasicInfo对象 diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/DelayMerchantOrderLogic.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/DelayMerchantOrderLogic.java index 154a20e44..769f3532b 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/DelayMerchantOrderLogic.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/DelayMerchantOrderLogic.java @@ -16,7 +16,9 @@ import com.jsowell.common.enums.MemberWalletEnum; import com.jsowell.common.enums.adapay.MerchantDelayModeEnum; import com.jsowell.common.enums.ykc.*; import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.IdUtils; import com.jsowell.pile.domain.*; import com.jsowell.pile.dto.ApplyRefundDTO; import com.jsowell.pile.dto.GenerateOrderDTO; @@ -25,6 +27,7 @@ import com.jsowell.pile.dto.PayOrderSuccessCallbackDTO; import com.jsowell.pile.transaction.dto.OrderTransactionDTO; import com.jsowell.pile.vo.uniapp.MemberVO; import com.jsowell.pile.vo.web.BalanceDeductionAmountVO; +import com.jsowell.pile.vo.web.BillingTemplateVO; import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; import com.jsowell.wxpay.dto.WechatSendMsgDTO; import org.apache.commons.collections4.CollectionUtils; @@ -68,6 +71,111 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic { return saveOrder2Database(dto); } + /** + * 生成订单编号 + * + * @return + */ + private String generateNewOrderCode() { + while (true) { + String orderCode = "C" + IdUtils.getOrderCode(); + // 通过orderCode查询是否已经存在 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderBasicInfo == null) { + return orderCode; + } + } + } + + /** + * 保存订单信息到数据库 + * + * @param dto + * @return + */ + protected OrderBasicInfo saveOrder2Database(GenerateOrderDTO dto) throws ParseException { + String orderCode = generateNewOrderCode(); + 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()) : ""; + String plateNumber = dto.getPlateNumber() != null ? dto.getPlateNumber() : ""; + // 订单基本信息 + 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()) + .plateNumber(plateNumber) + .orderAmount(BigDecimal.ZERO) + .virtualAmount(BigDecimal.ZERO) + .settleAmount(BigDecimal.ZERO) + .startType(dto.getStartType()) + .build(); + if (StringUtils.equals(dto.getStartMode(), StartModeEnum.AUTH_CARD.getValue())) { + // 鉴权卡启动 + orderBasicInfo.setLogicCard(dto.getPileAuthCardInfo().getLogicCard()); + } + if (StringUtils.equals(dto.getStartMode(), StartModeEnum.VIN_CODE.getValue())) { + // vin启动 + orderBasicInfo.setVinCode(dto.getMemberPlateNumberRelation().getVinCode()); + } + + 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(); + logger.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(); + transactionService.doCreateOrder(createOrderTransactionDTO); + return orderBasicInfo; + } + @Override public Map payOrder(PayOrderDTO dto) { logger.info("{}-支付订单start, param:{}", this.getClass().getSimpleName(), JSON.toJSONString(dto)); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/NotDelayMerchantOrderLogic.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/NotDelayMerchantOrderLogic.java index f7f40feaf..961ed212e 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/NotDelayMerchantOrderLogic.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/NotDelayMerchantOrderLogic.java @@ -14,7 +14,9 @@ import com.jsowell.common.enums.MemberWalletEnum; import com.jsowell.common.enums.adapay.MerchantDelayModeEnum; import com.jsowell.common.enums.ykc.*; import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.IdUtils; import com.jsowell.pile.domain.*; import com.jsowell.pile.dto.ApplyRefundDTO; import com.jsowell.pile.dto.GenerateOrderDTO; @@ -23,6 +25,7 @@ import com.jsowell.pile.dto.PayOrderSuccessCallbackDTO; import com.jsowell.pile.transaction.dto.OrderTransactionDTO; import com.jsowell.pile.vo.uniapp.MemberVO; import com.jsowell.pile.vo.web.BalanceDeductionAmountVO; +import com.jsowell.pile.vo.web.BillingTemplateVO; import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; import com.jsowell.wxpay.dto.WechatSendMsgDTO; import org.apache.commons.collections4.CollectionUtils; @@ -66,6 +69,111 @@ public class NotDelayMerchantOrderLogic extends AbstractOrderLogic{ return saveOrder2Database(dto); } + /** + * 生成订单编号 + * + * @return + */ + private String generateNewOrderCode() { + while (true) { + String orderCode = "C" + IdUtils.getOrderCode(); + // 通过orderCode查询是否已经存在 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderBasicInfo == null) { + return orderCode; + } + } + } + + /** + * 保存订单信息到数据库 + * + * @param dto + * @return + */ + protected OrderBasicInfo saveOrder2Database(GenerateOrderDTO dto) throws ParseException { + String orderCode = generateNewOrderCode(); + 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()) : ""; + String plateNumber = dto.getPlateNumber() != null ? dto.getPlateNumber() : ""; + // 订单基本信息 + 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()) + .plateNumber(plateNumber) + .orderAmount(BigDecimal.ZERO) + .virtualAmount(BigDecimal.ZERO) + .settleAmount(BigDecimal.ZERO) + .startType(dto.getStartType()) + .build(); + if (StringUtils.equals(dto.getStartMode(), StartModeEnum.AUTH_CARD.getValue())) { + // 鉴权卡启动 + orderBasicInfo.setLogicCard(dto.getPileAuthCardInfo().getLogicCard()); + } + if (StringUtils.equals(dto.getStartMode(), StartModeEnum.VIN_CODE.getValue())) { + // vin启动 + orderBasicInfo.setVinCode(dto.getMemberPlateNumberRelation().getVinCode()); + } + + 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(); + logger.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(); + transactionService.doCreateOrder(createOrderTransactionDTO); + return orderBasicInfo; + } + @Override public Map payOrder(PayOrderDTO dto) { logger.info("{}-支付订单start, param:{}", this.getClass().getSimpleName(), JSON.toJSONString(dto));