mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-07-05 06:27:59 +08:00
优化支付订单逻辑
This commit is contained in:
@@ -196,9 +196,7 @@ public class MemberService {
|
|||||||
*/
|
*/
|
||||||
public MemberVO getMemberInfoByMemberId(String memberId) {
|
public MemberVO getMemberInfoByMemberId(String memberId) {
|
||||||
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(memberId);
|
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(memberId);
|
||||||
if (Objects.nonNull(memberVO)) {
|
|
||||||
memberVO.setTotalAccountAmount(memberVO.getPrincipalBalance().add(memberVO.getGiftBalance()));
|
|
||||||
}
|
|
||||||
return memberVO;
|
return memberVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,6 @@ public class OrderService {
|
|||||||
* @param dto
|
* @param dto
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> payOrder(PayOrderDTO dto) throws Exception {
|
public Map<String, Object> payOrder(PayOrderDTO dto) throws Exception {
|
||||||
Map<String, Object> resultMap = Maps.newHashMap();
|
|
||||||
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode());
|
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode());
|
||||||
if (orderInfo == null) {
|
if (orderInfo == null) {
|
||||||
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_NULL_ERROR);
|
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_NULL_ERROR);
|
||||||
@@ -159,118 +158,150 @@ public class OrderService {
|
|||||||
// 订单已支付
|
// 订单已支付
|
||||||
throw new BusinessException(ReturnCodeEnum.CODE_ORDER_IS_NOT_TO_BE_PAID_ERROR);
|
throw new BusinessException(ReturnCodeEnum.CODE_ORDER_IS_NOT_TO_BE_PAID_ERROR);
|
||||||
}
|
}
|
||||||
String orderCode = orderInfo.getOrderCode();
|
Map<String, Object> resultMap = Maps.newHashMap();
|
||||||
// 该订单充电金额
|
if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
|
||||||
BigDecimal chargeAmount = dto.getPayAmount();
|
// 余额支付
|
||||||
// 记录支付流水
|
balancePayOrder(dto);
|
||||||
List<OrderPayRecord> payRecordList = Lists.newArrayList();
|
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
|
||||||
if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) { // 余额支付
|
// 微信支付
|
||||||
// 查询该会员的余额
|
Map<String, Object> weixinMap = wechatPayOrder(dto, orderInfo);
|
||||||
MemberVO memberVO = memberService.getMemberInfoByMemberId(dto.getMemberId());
|
|
||||||
BigDecimal totalAccountAmount = memberVO.getTotalAccountAmount();
|
|
||||||
|
|
||||||
if (totalAccountAmount.compareTo(chargeAmount) < 0) {
|
|
||||||
// 总余额小于充电金额
|
|
||||||
throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_IS_INSUFFICIENT);
|
|
||||||
}
|
|
||||||
BigDecimal principalAmount = memberVO.getPrincipalBalance(); // 会员剩余本金金额
|
|
||||||
BigDecimal giftAmount = memberVO.getGiftBalance(); // 会员剩余赠送余额
|
|
||||||
|
|
||||||
BigDecimal principalPay = null; // 30
|
|
||||||
BigDecimal giftPay = null; // 10
|
|
||||||
// 先扣除本金金额,再扣除赠送金额
|
|
||||||
BigDecimal subtract = principalAmount.subtract(chargeAmount);
|
|
||||||
if (subtract.compareTo(BigDecimal.ZERO) >= 0) {
|
|
||||||
principalPay = chargeAmount;
|
|
||||||
} else {
|
|
||||||
if (principalAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
||||||
principalPay = principalAmount;
|
|
||||||
}
|
|
||||||
giftPay = subtract.negate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新会员钱包
|
|
||||||
UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder()
|
|
||||||
.memberId(dto.getMemberId())
|
|
||||||
.type(MemberWalletEnum.TYPE_OUT.getValue())
|
|
||||||
.subType(MemberWalletEnum.SUBTYPE_PAYMENT_FOR_ORDER.getValue())
|
|
||||||
.updatePrincipalBalance(principalPay)
|
|
||||||
.updateGiftBalance(giftPay)
|
|
||||||
.relatedOrderCode(orderCode)
|
|
||||||
.build();
|
|
||||||
memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);
|
|
||||||
|
|
||||||
// 记录流水
|
|
||||||
if (principalPay != null) {
|
|
||||||
payRecordList.add(OrderPayRecord.builder()
|
|
||||||
.orderCode(dto.getOrderCode())
|
|
||||||
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
|
|
||||||
.payAmount(principalPay)
|
|
||||||
.createBy(dto.getMemberId())
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
if (giftPay != null) {
|
|
||||||
payRecordList.add(OrderPayRecord.builder()
|
|
||||||
.orderCode(dto.getOrderCode())
|
|
||||||
.payMode(OrderPayRecordEnum.GIFT_BALANCE_PAYMENT.getValue())
|
|
||||||
.payAmount(giftPay)
|
|
||||||
.createBy(dto.getMemberId())
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
// 余额支付可以直接调支付回调方法
|
|
||||||
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
|
|
||||||
.orderCode(orderCode)
|
|
||||||
.payAmount(chargeAmount)
|
|
||||||
.payMode(dto.getPayMode())
|
|
||||||
.build();
|
|
||||||
payOrderSuccessCallback(callbackDTO);
|
|
||||||
|
|
||||||
// 余额支付订单 记录会员交易流水
|
|
||||||
MemberTransactionRecord record = MemberTransactionRecord.builder()
|
|
||||||
.orderCode(orderCode)
|
|
||||||
.scenarioType(ScenarioEnum.ORDER.getValue())
|
|
||||||
.memberId(memberVO.getMemberId())
|
|
||||||
.actionType(ActionTypeEnum.FORWARD.getValue())
|
|
||||||
.payMode(PayModeEnum.PAYMENT_OF_BALANCE.getValue())
|
|
||||||
.amount(dto.getPayAmount()) // 单位元
|
|
||||||
.build();
|
|
||||||
memberTransactionRecordService.insertSelective(record);
|
|
||||||
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { // 微信支付
|
|
||||||
String openId = memberService.getOpenIdByCode(dto.getCode());
|
|
||||||
if (StringUtils.isBlank(openId)) {
|
|
||||||
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
|
||||||
}
|
|
||||||
WeixinPayDTO weixinPayDTO = new WeixinPayDTO();
|
|
||||||
weixinPayDTO.setOpenId(openId);
|
|
||||||
weixinPayDTO.setAmount(dto.getPayAmount().toString());
|
|
||||||
// 支付订单 附加参数
|
|
||||||
PaymentScenarioDTO paymentScenarioDTO = PaymentScenarioDTO.builder()
|
|
||||||
.type(ScenarioEnum.ORDER.getValue())
|
|
||||||
.orderCode(dto.getOrderCode())
|
|
||||||
.memberId(orderInfo.getMemberId())
|
|
||||||
.build();
|
|
||||||
weixinPayDTO.setAttach(JSONObject.toJSONString(paymentScenarioDTO));
|
|
||||||
weixinPayDTO.setDescription("充电费用");
|
|
||||||
Map<String, Object> weixinMap = this.weixinPayV3(weixinPayDTO);
|
|
||||||
// 返回微信支付参数
|
// 返回微信支付参数
|
||||||
resultMap.put("weixinMap", weixinMap);
|
resultMap.put("weixinMap", weixinMap);
|
||||||
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // 支付宝支付
|
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // 支付宝支付
|
||||||
// TODO 返回支付宝支付参数
|
// TODO 返回支付宝支付参数
|
||||||
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WHITELIST.getValue())) { // 白名单支付
|
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WHITELIST.getValue())) { // 白名单支付
|
||||||
// 白名单支付可以直接调支付回调方法
|
// 白名单支付可以直接调支付回调方法
|
||||||
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
|
whiteListPayOrder(dto);
|
||||||
.orderCode(orderCode)
|
|
||||||
.payAmount(dto.getPayAmount())
|
|
||||||
.payMode(dto.getPayMode())
|
|
||||||
.build();
|
|
||||||
payOrderSuccessCallback(callbackDTO);
|
|
||||||
}
|
}
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 白名单支付订单逻辑
|
||||||
|
* @param dto
|
||||||
|
*/
|
||||||
|
private void whiteListPayOrder(PayOrderDTO dto) {
|
||||||
|
String orderCode = dto.getOrderCode();
|
||||||
|
BigDecimal payAmount = dto.getPayAmount();
|
||||||
|
String payMode = dto.getPayMode();
|
||||||
|
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.payAmount(payAmount)
|
||||||
|
.payMode(payMode)
|
||||||
|
.build();
|
||||||
|
payOrderSuccessCallback(callbackDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信支付订单逻辑 获取支付参数
|
||||||
|
* @param dto
|
||||||
|
* @param orderInfo
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private Map<String, Object> wechatPayOrder(PayOrderDTO dto, OrderBasicInfo orderInfo) throws Exception {
|
||||||
|
String openId = memberService.getOpenIdByCode(dto.getCode());
|
||||||
|
if (StringUtils.isBlank(openId)) {
|
||||||
|
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
||||||
|
}
|
||||||
|
WeixinPayDTO weixinPayDTO = new WeixinPayDTO();
|
||||||
|
weixinPayDTO.setOpenId(openId);
|
||||||
|
weixinPayDTO.setAmount(dto.getPayAmount().toString());
|
||||||
|
// 支付订单 附加参数
|
||||||
|
PaymentScenarioDTO paymentScenarioDTO = PaymentScenarioDTO.builder()
|
||||||
|
.type(ScenarioEnum.ORDER.getValue())
|
||||||
|
.orderCode(dto.getOrderCode())
|
||||||
|
.memberId(orderInfo.getMemberId())
|
||||||
|
.build();
|
||||||
|
weixinPayDTO.setAttach(JSONObject.toJSONString(paymentScenarioDTO));
|
||||||
|
weixinPayDTO.setDescription("充电费用");
|
||||||
|
return this.weixinPayV3(weixinPayDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 余额支付订单逻辑
|
||||||
|
* @param dto
|
||||||
|
*/
|
||||||
|
private void balancePayOrder(PayOrderDTO dto) {
|
||||||
|
// 记录支付流水
|
||||||
|
List<OrderPayRecord> payRecordList = Lists.newArrayList();
|
||||||
|
String orderCode = dto.getOrderCode();
|
||||||
|
BigDecimal chargeAmount = dto.getPayAmount();
|
||||||
|
// 查询该会员的余额
|
||||||
|
MemberVO memberVO = memberService.getMemberInfoByMemberId(dto.getMemberId());
|
||||||
|
BigDecimal totalAccountAmount = memberVO.getTotalAccountAmount();
|
||||||
|
|
||||||
|
if (totalAccountAmount.compareTo(chargeAmount) < 0) {
|
||||||
|
// 总余额小于充电金额
|
||||||
|
throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_IS_INSUFFICIENT);
|
||||||
|
}
|
||||||
|
BigDecimal principalAmount = memberVO.getPrincipalBalance(); // 会员剩余本金金额
|
||||||
|
BigDecimal giftAmount = memberVO.getGiftBalance(); // 会员剩余赠送余额
|
||||||
|
|
||||||
|
BigDecimal principalPay = null; // 30
|
||||||
|
BigDecimal giftPay = null; // 10
|
||||||
|
// 先扣除本金金额,再扣除赠送金额
|
||||||
|
BigDecimal subtract = principalAmount.subtract(chargeAmount);
|
||||||
|
if (subtract.compareTo(BigDecimal.ZERO) >= 0) {
|
||||||
|
principalPay = chargeAmount;
|
||||||
|
} else {
|
||||||
|
if (principalAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
principalPay = principalAmount;
|
||||||
|
}
|
||||||
|
giftPay = subtract.negate();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新会员钱包
|
||||||
|
UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder()
|
||||||
|
.memberId(dto.getMemberId())
|
||||||
|
.type(MemberWalletEnum.TYPE_OUT.getValue())
|
||||||
|
.subType(MemberWalletEnum.SUBTYPE_PAYMENT_FOR_ORDER.getValue())
|
||||||
|
.updatePrincipalBalance(principalPay)
|
||||||
|
.updateGiftBalance(giftPay)
|
||||||
|
.relatedOrderCode(orderCode)
|
||||||
|
.build();
|
||||||
|
memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);
|
||||||
|
|
||||||
|
// 记录流水
|
||||||
|
if (principalPay != null) {
|
||||||
|
payRecordList.add(OrderPayRecord.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
|
||||||
|
.payAmount(principalPay)
|
||||||
|
.createBy(dto.getMemberId())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
if (giftPay != null) {
|
||||||
|
payRecordList.add(OrderPayRecord.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.payMode(OrderPayRecordEnum.GIFT_BALANCE_PAYMENT.getValue())
|
||||||
|
.payAmount(giftPay)
|
||||||
|
.createBy(dto.getMemberId())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
// 余额支付可以直接调支付回调方法
|
||||||
|
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.payAmount(chargeAmount)
|
||||||
|
.payMode(dto.getPayMode())
|
||||||
|
.build();
|
||||||
|
payOrderSuccessCallback(callbackDTO);
|
||||||
|
|
||||||
|
// 余额支付订单 记录会员交易流水
|
||||||
|
MemberTransactionRecord record = MemberTransactionRecord.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.scenarioType(ScenarioEnum.ORDER.getValue())
|
||||||
|
.memberId(memberVO.getMemberId())
|
||||||
|
.actionType(ActionTypeEnum.FORWARD.getValue())
|
||||||
|
.payMode(PayModeEnum.PAYMENT_OF_BALANCE.getValue())
|
||||||
|
.amount(dto.getPayAmount()) // 单位元
|
||||||
|
.build();
|
||||||
|
memberTransactionRecordService.insertSelective(record);
|
||||||
|
|
||||||
// 订单支付流水入库
|
// 订单支付流水入库
|
||||||
if (CollectionUtils.isNotEmpty(payRecordList)) {
|
if (CollectionUtils.isNotEmpty(payRecordList)) {
|
||||||
orderPayRecordService.batchInsert(payRecordList);
|
orderPayRecordService.batchInsert(payRecordList);
|
||||||
}
|
}
|
||||||
return resultMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,36 +5,26 @@ import com.google.common.primitives.Bytes;
|
|||||||
import com.jsowell.common.constant.Constants;
|
import com.jsowell.common.constant.Constants;
|
||||||
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
|
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
|
||||||
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
||||||
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
|
||||||
import com.jsowell.common.enums.ykc.PayModeEnum;
|
|
||||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||||
import com.jsowell.common.enums.ykc.StartModeEnum;
|
|
||||||
import com.jsowell.common.exception.BusinessException;
|
import com.jsowell.common.exception.BusinessException;
|
||||||
import com.jsowell.common.util.BytesUtil;
|
import com.jsowell.common.util.BytesUtil;
|
||||||
import com.jsowell.common.util.StringUtils;
|
import com.jsowell.common.util.StringUtils;
|
||||||
import com.jsowell.common.util.YKCUtils;
|
import com.jsowell.common.util.YKCUtils;
|
||||||
import com.jsowell.common.util.id.IdUtils;
|
|
||||||
import com.jsowell.netty.factory.YKCOperateFactory;
|
import com.jsowell.netty.factory.YKCOperateFactory;
|
||||||
import com.jsowell.pile.domain.OrderBasicInfo;
|
|
||||||
import com.jsowell.pile.domain.OrderDetail;
|
|
||||||
import com.jsowell.pile.domain.PileAuthCard;
|
import com.jsowell.pile.domain.PileAuthCard;
|
||||||
import com.jsowell.pile.domain.PileBasicInfo;
|
import com.jsowell.pile.dto.GenerateOrderDTO;
|
||||||
|
import com.jsowell.pile.service.IOrderBasicInfoService;
|
||||||
import com.jsowell.pile.service.IPileAuthCardService;
|
import com.jsowell.pile.service.IPileAuthCardService;
|
||||||
import com.jsowell.pile.service.IPileBasicInfoService;
|
import com.jsowell.pile.service.IPileBasicInfoService;
|
||||||
import com.jsowell.pile.service.IPileBillingTemplateService;
|
import com.jsowell.pile.service.IPileBillingTemplateService;
|
||||||
import com.jsowell.pile.service.impl.MemberBasicInfoServiceImpl;
|
import com.jsowell.pile.service.impl.MemberBasicInfoServiceImpl;
|
||||||
import com.jsowell.pile.transaction.dto.OrderTransactionDTO;
|
|
||||||
import com.jsowell.pile.transaction.service.TransactionService;
|
import com.jsowell.pile.transaction.service.TransactionService;
|
||||||
import com.jsowell.pile.vo.uniapp.CurrentTimePriceDetails;
|
|
||||||
import com.jsowell.pile.vo.uniapp.MemberVO;
|
|
||||||
import com.jsowell.pile.vo.web.BillingTemplateVO;
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.util.Map;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 充电桩主动申请启动充电 0x31
|
* 充电桩主动申请启动充电 0x31
|
||||||
@@ -63,6 +53,9 @@ public class ConfirmStartChargingRequestHandler extends AbstractHandler{
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IPileBillingTemplateService pileBillingTemplateService;
|
private IPileBillingTemplateService pileBillingTemplateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IOrderBasicInfoService orderBasicInfoService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
YKCOperateFactory.register(type, this);
|
YKCOperateFactory.register(type, this);
|
||||||
@@ -126,8 +119,7 @@ public class ConfirmStartChargingRequestHandler extends AbstractHandler{
|
|||||||
String transactionCode = "";
|
String transactionCode = "";
|
||||||
try {
|
try {
|
||||||
if (StringUtils.equals("01", startMode)) {
|
if (StringUtils.equals("01", startMode)) {
|
||||||
// 刷卡启动充电
|
// 查询卡信息 根据传过来的物理卡号查询数据库中此卡信息
|
||||||
// 根据传过来的物理卡号查询数据库中此卡信息
|
|
||||||
PileAuthCard pileAuthCardInfo = pileAuthCardService.selectCardInfoByLogicCard(physicsCard);
|
PileAuthCard pileAuthCardInfo = pileAuthCardService.selectCardInfoByLogicCard(physicsCard);
|
||||||
if (pileAuthCardInfo == null) {
|
if (pileAuthCardInfo == null) {
|
||||||
// 未查到此卡信息
|
// 未查到此卡信息
|
||||||
@@ -137,74 +129,23 @@ public class ConfirmStartChargingRequestHandler extends AbstractHandler{
|
|||||||
// 卡未绑定用户
|
// 卡未绑定用户
|
||||||
throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARD_NOT_BIND_USER);
|
throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARD_NOT_BIND_USER);
|
||||||
}
|
}
|
||||||
// 卡状态
|
// 判断卡状态
|
||||||
String cardStatus = pileAuthCardInfo.getStatus();
|
if (!StringUtils.equals("1", pileAuthCardInfo.getStatus())) {
|
||||||
// 逻辑卡号
|
|
||||||
logicCard = pileAuthCardInfo.getLogicCard();
|
|
||||||
// 通过memberId获取账户余额
|
|
||||||
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(pileAuthCardInfo.getMemberId());
|
|
||||||
BigDecimal principalBalance = memberVO.getPrincipalBalance(); // 本金金额
|
|
||||||
double accountBalance = principalBalance.add(memberVO.getGiftBalance()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
||||||
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(accountBalance), 2);
|
|
||||||
if (!StringUtils.equals("1", cardStatus)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 鉴权成功标识 0x00 失败 0x01 成功
|
|
||||||
authenticationFlagByteArr = Constants.oneByteArray;
|
|
||||||
transactionCode = IdUtils.generateTransactionCode(pileSn, connectorCode);
|
|
||||||
// 通过桩号查询所属站点
|
|
||||||
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
|
|
||||||
Long stationId = pileBasicInfo.getStationId();
|
|
||||||
// TODO 个人桩站点不计费
|
|
||||||
|
|
||||||
// 将此订单信息存入订单表
|
// 刷卡生成订单 刷卡启动充电
|
||||||
String orderCode = IdUtils.getOrderCode();
|
GenerateOrderDTO dto = new GenerateOrderDTO();
|
||||||
// 订单基本信息
|
dto.setPileAuthCardInfo(pileAuthCardInfo);
|
||||||
OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder()
|
dto.setPileSn(pileSn);
|
||||||
.orderCode(orderCode)
|
dto.setConnectorCode(connectorCode);
|
||||||
.transactionCode(transactionCode)
|
Map<String, Object> map = orderBasicInfoService.generateOrderByCard(dto);
|
||||||
.orderStatus(OrderStatusEnum.NOT_START.getValue())
|
if (map != null) {
|
||||||
.memberId(memberVO.getMemberId())
|
transactionCode = (String) map.get("transactionCode");
|
||||||
.stationId(String.valueOf(stationId))
|
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
|
||||||
.pileSn(pileSn)
|
// 鉴权成功标识 0x00 失败 0x01 成功
|
||||||
.connectorCode(connectorCode)
|
authenticationFlagByteArr = Constants.oneByteArray;
|
||||||
.pileConnectorCode(pileSn + connectorCode)
|
}
|
||||||
.logicCard(logicCard)
|
|
||||||
.startMode(StartModeEnum.CARD.getValue())
|
|
||||||
.payStatus(Constants.ZERO)
|
|
||||||
.payAmount(new BigDecimal(String.valueOf(accountBalance)))
|
|
||||||
.payTime(new Date())
|
|
||||||
.payMode(PayModeEnum.PAYMENT_OF_BALANCE.getValue())
|
|
||||||
.orderAmount(BigDecimal.ZERO)
|
|
||||||
.build();
|
|
||||||
// 根据桩编码查询当前计费模板
|
|
||||||
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn);
|
|
||||||
// 订单详情
|
|
||||||
OrderDetail orderDetail = OrderDetail.builder()
|
|
||||||
.orderCode(orderCode)
|
|
||||||
.sharpElectricityPrice(billingTemplateVO.getSharpElectricityPrice())
|
|
||||||
.sharpServicePrice(billingTemplateVO.getSharpServicePrice())
|
|
||||||
.peakElectricityPrice(billingTemplateVO.getPeakElectricityPrice())
|
|
||||||
.peakServicePrice(billingTemplateVO.getPeakServicePrice())
|
|
||||||
.flatElectricityPrice(billingTemplateVO.getFlatElectricityPrice())
|
|
||||||
.flatServicePrice(billingTemplateVO.getFlatServicePrice())
|
|
||||||
.valleyElectricityPrice(billingTemplateVO.getValleyElectricityPrice())
|
|
||||||
.valleyServicePrice(billingTemplateVO.getValleyServicePrice())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
OrderTransactionDTO createOrderTransactionDTO = OrderTransactionDTO.builder()
|
|
||||||
.orderBasicInfo(orderBasicInfo)
|
|
||||||
.orderDetail(orderDetail)
|
|
||||||
.build();
|
|
||||||
pileTransactionService.doCreateOrder(createOrderTransactionDTO);
|
|
||||||
|
|
||||||
// 将卡状态改为启动锁定
|
|
||||||
PileAuthCard pileAuthCard = PileAuthCard.builder()
|
|
||||||
.id(pileAuthCardInfo.getId())
|
|
||||||
.logicCard(physicsCard)
|
|
||||||
.status("2")
|
|
||||||
.build();
|
|
||||||
pileAuthCardService.updatePileAuthCard(pileAuthCard);
|
|
||||||
}
|
}
|
||||||
} catch (BusinessException e){
|
} catch (BusinessException e){
|
||||||
log.error("刷卡启动充电鉴权 error:{}, {}", e.getCode(), e.getMessage());
|
log.error("刷卡启动充电鉴权 error:{}, {}", e.getCode(), e.getMessage());
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.jsowell.pile.dto;
|
package com.jsowell.pile.dto;
|
||||||
|
|
||||||
|
import com.jsowell.pile.domain.PileAuthCard;
|
||||||
import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO;
|
import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO;
|
||||||
import com.jsowell.pile.vo.web.BillingTemplateVO;
|
import com.jsowell.pile.vo.web.BillingTemplateVO;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -59,4 +60,9 @@ public class GenerateOrderDTO extends BasicPileDTO{
|
|||||||
* 预约时间
|
* 预约时间
|
||||||
*/
|
*/
|
||||||
private String appointmentTime;
|
private String appointmentTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用刷卡创建订单时有值
|
||||||
|
*/
|
||||||
|
private PileAuthCard pileAuthCardInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
|
|||||||
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
|
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
|
||||||
import com.jsowell.pile.domain.OrderBasicInfo;
|
import com.jsowell.pile.domain.OrderBasicInfo;
|
||||||
import com.jsowell.pile.domain.OrderDetail;
|
import com.jsowell.pile.domain.OrderDetail;
|
||||||
|
import com.jsowell.pile.dto.GenerateOrderDTO;
|
||||||
import com.jsowell.pile.dto.IndexQueryDTO;
|
import com.jsowell.pile.dto.IndexQueryDTO;
|
||||||
import com.jsowell.pile.dto.QueryOrderDTO;
|
import com.jsowell.pile.dto.QueryOrderDTO;
|
||||||
import com.jsowell.pile.dto.QueryPersonPileDTO;
|
import com.jsowell.pile.dto.QueryPersonPileDTO;
|
||||||
@@ -17,6 +18,7 @@ import com.jsowell.wxpay.dto.WeChatRefundDTO;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单Service接口
|
* 订单Service接口
|
||||||
@@ -211,4 +213,6 @@ public interface IOrderBasicInfoService {
|
|||||||
void updateOrderStatusAsAbnormal(String pileSn);
|
void updateOrderStatusAsAbnormal(String pileSn);
|
||||||
|
|
||||||
List<OrderBasicInfo> getAppointmentOrder(LocalDateTime dateTime);
|
List<OrderBasicInfo> getAppointmentOrder(LocalDateTime dateTime);
|
||||||
|
|
||||||
|
Map<String, Object> generateOrderByCard(GenerateOrderDTO dto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,6 +241,12 @@ public class MemberBasicInfoServiceImpl implements IMemberBasicInfoService {
|
|||||||
}
|
}
|
||||||
// 加缓存
|
// 加缓存
|
||||||
MemberVO vo = memberBasicInfoMapper.queryMemberInfoByMemberId(memberId);
|
MemberVO vo = memberBasicInfoMapper.queryMemberInfoByMemberId(memberId);
|
||||||
|
if (vo == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
vo.setTotalAccountAmount(vo.getPrincipalBalance().add(vo.getGiftBalance()));
|
||||||
|
|
||||||
|
// 查询用户车牌号
|
||||||
MemberPlateNumberRelation memberPlateNumberRelation = new MemberPlateNumberRelation();
|
MemberPlateNumberRelation memberPlateNumberRelation = new MemberPlateNumberRelation();
|
||||||
memberPlateNumberRelation.setMemberId(memberId);
|
memberPlateNumberRelation.setMemberId(memberId);
|
||||||
List<MemberPlateNumberRelation> list = memberPlateNumberRelationMapper.selectMemberPlateNumberRelationList(memberPlateNumberRelation);
|
List<MemberPlateNumberRelation> list = memberPlateNumberRelationMapper.selectMemberPlateNumberRelationList(memberPlateNumberRelation);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.jsowell.common.enums.MemberWalletEnum;
|
|||||||
import com.jsowell.common.enums.ykc.OrderPayModeEnum;
|
import com.jsowell.common.enums.ykc.OrderPayModeEnum;
|
||||||
import com.jsowell.common.enums.ykc.OrderPayStatusEnum;
|
import com.jsowell.common.enums.ykc.OrderPayStatusEnum;
|
||||||
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
||||||
|
import com.jsowell.common.enums.ykc.PayModeEnum;
|
||||||
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
|
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
|
||||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||||
import com.jsowell.common.enums.ykc.StartModeEnum;
|
import com.jsowell.common.enums.ykc.StartModeEnum;
|
||||||
@@ -30,8 +31,11 @@ import com.jsowell.pile.domain.OrderAbnormalRecord;
|
|||||||
import com.jsowell.pile.domain.OrderBasicInfo;
|
import com.jsowell.pile.domain.OrderBasicInfo;
|
||||||
import com.jsowell.pile.domain.OrderDetail;
|
import com.jsowell.pile.domain.OrderDetail;
|
||||||
import com.jsowell.pile.domain.OrderPayRecord;
|
import com.jsowell.pile.domain.OrderPayRecord;
|
||||||
|
import com.jsowell.pile.domain.PileAuthCard;
|
||||||
|
import com.jsowell.pile.domain.PileBasicInfo;
|
||||||
import com.jsowell.pile.domain.WxpayCallbackRecord;
|
import com.jsowell.pile.domain.WxpayCallbackRecord;
|
||||||
import com.jsowell.pile.domain.WxpayRefundCallback;
|
import com.jsowell.pile.domain.WxpayRefundCallback;
|
||||||
|
import com.jsowell.pile.dto.GenerateOrderDTO;
|
||||||
import com.jsowell.pile.dto.IndexQueryDTO;
|
import com.jsowell.pile.dto.IndexQueryDTO;
|
||||||
import com.jsowell.pile.dto.QueryOrderDTO;
|
import com.jsowell.pile.dto.QueryOrderDTO;
|
||||||
import com.jsowell.pile.dto.QueryPersonPileDTO;
|
import com.jsowell.pile.dto.QueryPersonPileDTO;
|
||||||
@@ -41,6 +45,7 @@ import com.jsowell.pile.service.IMemberBasicInfoService;
|
|||||||
import com.jsowell.pile.service.IOrderAbnormalRecordService;
|
import com.jsowell.pile.service.IOrderAbnormalRecordService;
|
||||||
import com.jsowell.pile.service.IOrderBasicInfoService;
|
import com.jsowell.pile.service.IOrderBasicInfoService;
|
||||||
import com.jsowell.pile.service.IOrderPayRecordService;
|
import com.jsowell.pile.service.IOrderPayRecordService;
|
||||||
|
import com.jsowell.pile.service.IPileAuthCardService;
|
||||||
import com.jsowell.pile.service.IPileBasicInfoService;
|
import com.jsowell.pile.service.IPileBasicInfoService;
|
||||||
import com.jsowell.pile.service.IPileBillingTemplateService;
|
import com.jsowell.pile.service.IPileBillingTemplateService;
|
||||||
import com.jsowell.pile.service.IPileConnectorInfoService;
|
import com.jsowell.pile.service.IPileConnectorInfoService;
|
||||||
@@ -54,6 +59,7 @@ import com.jsowell.pile.vo.uniapp.MemberVO;
|
|||||||
import com.jsowell.pile.vo.uniapp.OrderVO;
|
import com.jsowell.pile.vo.uniapp.OrderVO;
|
||||||
import com.jsowell.pile.vo.uniapp.PersonPileConnectorSumInfoVO;
|
import com.jsowell.pile.vo.uniapp.PersonPileConnectorSumInfoVO;
|
||||||
import com.jsowell.pile.vo.uniapp.SendMessageVO;
|
import com.jsowell.pile.vo.uniapp.SendMessageVO;
|
||||||
|
import com.jsowell.pile.vo.web.BillingTemplateVO;
|
||||||
import com.jsowell.pile.vo.web.IndexOrderInfoVO;
|
import com.jsowell.pile.vo.web.IndexOrderInfoVO;
|
||||||
import com.jsowell.pile.vo.web.OrderListVO;
|
import com.jsowell.pile.vo.web.OrderListVO;
|
||||||
import com.jsowell.pile.vo.web.OrderTotalDataVO;
|
import com.jsowell.pile.vo.web.OrderTotalDataVO;
|
||||||
@@ -136,6 +142,9 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IPileBillingTemplateService pileBillingTemplateService;
|
private IPileBillingTemplateService pileBillingTemplateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IPileAuthCardService pileAuthCardService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询订单
|
* 查询订单
|
||||||
*
|
*
|
||||||
@@ -1189,4 +1198,88 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
|||||||
public List<OrderBasicInfo> getAppointmentOrder(LocalDateTime dateTime) {
|
public List<OrderBasicInfo> getAppointmentOrder(LocalDateTime dateTime) {
|
||||||
return orderBasicInfoMapper.getAppointmentOrder(dateTime);
|
return orderBasicInfoMapper.getAppointmentOrder(dateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成订单 返回交易流水号
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> generateOrderByCard(GenerateOrderDTO dto) {
|
||||||
|
String pileSn = dto.getPileSn();
|
||||||
|
String connectorCode = dto.getConnectorCode();
|
||||||
|
PileAuthCard pileAuthCardInfo = dto.getPileAuthCardInfo();
|
||||||
|
// 通过memberId获取账户余额
|
||||||
|
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(pileAuthCardInfo.getMemberId());
|
||||||
|
if (memberVO == null) {
|
||||||
|
throw new BusinessException(ReturnCodeEnum.CODE_GET_MEMBER_ACCOUNT_AMOUNT_ERROR);
|
||||||
|
}
|
||||||
|
BigDecimal totalAccountAmount = memberVO.getTotalAccountAmount();
|
||||||
|
if (totalAccountAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_IS_INSUFFICIENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
String transactionCode = IdUtils.generateTransactionCode(pileSn, connectorCode);
|
||||||
|
// 通过桩号查询所属站点
|
||||||
|
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
|
||||||
|
Long stationId = pileBasicInfo.getStationId();
|
||||||
|
// 自动余额全部支付订单 个人桩站点不计费
|
||||||
|
|
||||||
|
|
||||||
|
// 将此订单信息存入订单表
|
||||||
|
String orderCode = IdUtils.getOrderCode();
|
||||||
|
// 订单基本信息
|
||||||
|
OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.transactionCode(transactionCode)
|
||||||
|
.orderStatus(OrderStatusEnum.NOT_START.getValue())
|
||||||
|
.memberId(memberVO.getMemberId())
|
||||||
|
.stationId(String.valueOf(stationId))
|
||||||
|
.pileSn(pileSn)
|
||||||
|
.connectorCode(connectorCode)
|
||||||
|
.pileConnectorCode(pileSn + connectorCode)
|
||||||
|
.logicCard(pileAuthCardInfo.getLogicCard())
|
||||||
|
.startMode(StartModeEnum.CARD.getValue())
|
||||||
|
.payStatus(Constants.ONE)
|
||||||
|
.payAmount(totalAccountAmount)
|
||||||
|
.payTime(new Date())
|
||||||
|
.payMode(PayModeEnum.PAYMENT_OF_BALANCE.getValue())
|
||||||
|
.orderAmount(BigDecimal.ZERO)
|
||||||
|
.build();
|
||||||
|
// 根据桩编码查询当前计费模板
|
||||||
|
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn);
|
||||||
|
// 订单详情
|
||||||
|
OrderDetail orderDetail = OrderDetail.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.sharpElectricityPrice(billingTemplateVO.getSharpElectricityPrice())
|
||||||
|
.sharpServicePrice(billingTemplateVO.getSharpServicePrice())
|
||||||
|
.peakElectricityPrice(billingTemplateVO.getPeakElectricityPrice())
|
||||||
|
.peakServicePrice(billingTemplateVO.getPeakServicePrice())
|
||||||
|
.flatElectricityPrice(billingTemplateVO.getFlatElectricityPrice())
|
||||||
|
.flatServicePrice(billingTemplateVO.getFlatServicePrice())
|
||||||
|
.valleyElectricityPrice(billingTemplateVO.getValleyElectricityPrice())
|
||||||
|
.valleyServicePrice(billingTemplateVO.getValleyServicePrice())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
OrderTransactionDTO createOrderTransactionDTO = OrderTransactionDTO.builder()
|
||||||
|
.orderBasicInfo(orderBasicInfo)
|
||||||
|
.orderDetail(orderDetail)
|
||||||
|
.build();
|
||||||
|
pileTransactionService.doCreateOrder(createOrderTransactionDTO);
|
||||||
|
|
||||||
|
// 将卡状态改为启动锁定
|
||||||
|
PileAuthCard pileAuthCard = PileAuthCard.builder()
|
||||||
|
.id(pileAuthCardInfo.getId())
|
||||||
|
.logicCard(pileAuthCardInfo.getLogicCard())
|
||||||
|
.status("2")
|
||||||
|
.build();
|
||||||
|
pileAuthCardService.updatePileAuthCard(pileAuthCard);
|
||||||
|
|
||||||
|
// 组装结果集
|
||||||
|
Map<String, Object> resultMap = Maps.newHashMap();
|
||||||
|
resultMap.put("orderCode", orderBasicInfo.getOrderCode());
|
||||||
|
resultMap.put("transactionCode", orderBasicInfo.getTransactionCode());
|
||||||
|
resultMap.put("accountBalance", totalAccountAmount);
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user