| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; |
| | | import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.config.C3mRedisConfig; |
| | | import com.sandu.ximon.admin.pay.OrderStatusEnums; |
| | | import com.sandu.ximon.admin.pay.wx.WxFastPayService; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.security.order.OrderQueryListener; |
| | | import com.sandu.ximon.admin.security.order.OrderScanType; |
| | | import com.sandu.ximon.admin.utils.AliPayUtils; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.admin.vo.C3mOrderVO; |
| | | import com.sandu.ximon.dao.domain.C3mCharging; |
| | | import com.sandu.ximon.dao.domain.C3mOrder; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.C3mRedisConstant; |
| | | import com.sandu.ximon.dao.enums.OrderStatus; |
| | | import com.sandu.ximon.dao.enums.OrderType; |
| | | import com.sandu.ximon.dao.mapper.C3mOrderMapper; |
| | |
| | | @AllArgsConstructor |
| | | public class C3mOrderService extends BaseServiceImpl<C3mOrderMapper, C3mOrder> { |
| | | |
| | | private final RedisUtils redisUtils; |
| | | private final PoleService poleService; |
| | | private final C3mOrderMapper c3mOrderMapper; |
| | | private final WxFastPayService fastPayService; |
| | | private final OrderQueryListener orderQueryListener; |
| | | |
| | | public boolean orderRefund(String outTradeNo, Double refundAmount/*, Long userId, String username*/) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | |
| | | return false; |
| | | } else { |
| | | orderByOutTradeNo.setRefundAmount(refundAmount); |
| | | return c3mOrderRefund(orderByOutTradeNo, "页面API退款", userId, username); |
| | | return c3mOrderRefund(orderByOutTradeNo, "充电桩退款", userId, username); |
| | | } |
| | | |
| | | |
| | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | public C3mOrder advancePayOrder(Long streetlightId, C3mCharging c3m, String orderType, Double totalAmount, |
| | | Integer subscribeChargingCapacity) { |
| | | |
| | | // 判断该充电桩是否存在正在进行中的订单 |
| | | String chargingJson = redisUtils.get(C3mRedisConstant.C3_CHARGING_ORDER.getCode() + c3m.getC3Mac()); |
| | | if (null != chargingJson) { |
| | | return null; |
| | | } |
| | | Pole pole = poleService.getById(streetlightId); |
| | | if (null == pole) { |
| | | return null; |
| | | } |
| | | // 生成订单,并加载到redis缓存,设置超时时间为5分钟 |
| | | C3mOrder c3mOrderEntity = new C3mOrderVO().generateOrder( |
| | | streetlightId, |
| | | pole.getDeviceCode(), |
| | | c3m.getC3Mac(), |
| | | OrderType.getOrderType(orderType), |
| | | totalAmount, |
| | | subscribeChargingCapacity |
| | | ); |
| | | // 加载到redis缓存中, 查询模块自动查询状态并处理 |
| | | boolean b = redisUtils.set( |
| | | C3mRedisConstant.C3_NO_PAY_ORDER.getCode() + c3m.getC3Mac() + c3mOrderEntity.getOutTradeNo(), |
| | | JSON.toJSONString(c3mOrderEntity), |
| | | C3mRedisConfig.ORDER_MAX_TIME |
| | | ); |
| | | // 推送到自动查询模块,进行扫描启动 |
| | | orderQueryListener.startScan(OrderScanType.C3M.getType()); |
| | | // if(b){ |
| | | // save(c3mOrderEntity); |
| | | // } |
| | | return b ? c3mOrderEntity : null; |
| | | } |
| | | |
| | | /** |
| | | * 微信支付回调 |
| | | */ |
| | | public Object payWechatNotify(String xmlData) { |
| | | WxPayOrderNotifyResult wxPayOrderNotifyResult = fastPayService.parseOrderNotifyResult(xmlData); |
| | | String orderSn = wxPayOrderNotifyResult.getOutTradeNo(); |
| | | String transactionId = wxPayOrderNotifyResult.getOutTradeNo(); |
| | | Integer totalFee = wxPayOrderNotifyResult.getTotalFee(); |
| | | C3mOrder userOrder = getByOrderSn(orderSn); |
| | | if (userOrder == null) { |
| | | return WxPayNotifyResponse.fail("订单不存在 sn=" + orderSn); |
| | | } |
| | | |
| | | // 检查这个订单是否已经处理过 |
| | | if (!OrderStatusEnums.UNPAID.getCode().equals(userOrder.getOrderStatus())) { |
| | | return WxPayNotifyResponse.success("订单已经处理成功!"); |
| | | } |
| | | userOrder.setOutTradeNo(transactionId); |
| | | userOrder.setPayTimestamp(new Date().getTime()); |
| | | userOrder.setOrderStatus(OrderStatusEnums.PAID.getCode()); |
| | | if (!updateById(userOrder)) { |
| | | return WxPayNotifyResponse.fail("更新数据已失效"); |
| | | } |
| | | |
| | | return WxPayNotifyResponse.success("更新数据成功"); |
| | | } |
| | | |
| | | |
| | | public C3mOrder getByOrderSn(String orderSn) { |
| | | LambdaQueryWrapper<C3mOrder> wrapper = Wrappers.lambdaQuery(C3mOrder.class).eq(C3mOrder::getOutTradeNo, orderSn).last("limit 1"); |
| | | return getOne(wrapper); |
| | | } |
| | | |
| | | } |