| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import cn.hutool.core.lang.Snowflake; |
| | | 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.github.pagehelper.PageHelper; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.config.C3mRedisConfig; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.C3mRedisConstant; |
| | | 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.bo.C3mOrderBo; |
| | | 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; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author liuhaonan |
| | |
| | | private final C3mOrderMapper c3mOrderMapper; |
| | | private final WxFastPayService fastPayService; |
| | | private final OrderQueryListener orderQueryListener; |
| | | private final Snowflake snowflake; |
| | | |
| | | public boolean orderRefund(String outTradeNo, Double refundAmount/*, Long userId, String username*/) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | |
| | | if (orderByOutTradeNo.getTotalAmount() < refundAmount) { |
| | | throw new BusinessException("退款金额错误,不能大于付款金额"); |
| | | } |
| | | if (null == orderByOutTradeNo) { |
| | | return false; |
| | | if (orderByOutTradeNo == null) { |
| | | throw new BusinessException("未找到订单"); |
| | | } else { |
| | | orderByOutTradeNo.setRefundAmount(refundAmount); |
| | | return c3mOrderRefund(orderByOutTradeNo, "充电桩退款", userId, username); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 退款 |
| | | * |
| | | * @param C3mOrder |
| | | * @param msg |
| | | * @param userId |
| | | * @param username |
| | | * @return |
| | | */ |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | private boolean c3mOrderRefund(C3mOrder C3mOrder, String msg, Long userId, String username) { |
| | | // 进行退款,设置订单状态为已退款 |
| | | boolean b = false; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建订单 |
| | | * |
| | | * @param streetlightId |
| | | * @param c3m |
| | | * @param orderType |
| | | * @param totalAmount |
| | | * @param subscribeChargingCapacity |
| | | * @return |
| | | */ |
| | | public C3mOrder advancePayOrder(Long streetlightId, C3mCharging c3m, String orderType, Double totalAmount, |
| | | Integer subscribeChargingCapacity) { |
| | | |
| | |
| | | subscribeChargingCapacity |
| | | ); |
| | | // 加载到redis缓存中, 查询模块自动查询状态并处理 |
| | | boolean b = redisUtils.set( |
| | | C3mRedisConstant.C3_NO_PAY_ORDER.getCode() + c3m.getC3Mac() + c3mOrderEntity.getOutTradeNo(), |
| | | JSON.toJSONString(c3mOrderEntity), |
| | | C3mRedisConfig.ORDER_MAX_TIME |
| | | ); |
| | | // boolean b = redisUtils.set( |
| | | // C3mRedisConstant.C3_NO_PAY_ORDER.getCode() + c3m.getC3Mac() + c3mOrderEntity.getOutTradeNo(), |
| | | // JSON.toJSONString(c3mOrderEntity), |
| | | // C3mRedisConfig.ORDER_MAX_TIME // TODO 测试时关闭 |
| | | // ); |
| | | boolean b = true; |
| | | c3mOrderEntity.setOrderId(snowflake.nextId()); |
| | | c3mOrderEntity.setC3Mac(c3m.getC3Name()); |
| | | c3mOrderEntity.setPoleId(streetlightId); |
| | | c3mOrderEntity.setPoleMac(pole.getDeviceCode()); |
| | | c3mOrderEntity.setPoleName(pole.getPoleName()); |
| | | c3mOrderEntity.setC3Mac(c3m.getC3Mac()); |
| | | c3mOrderEntity.setOrderStatus(0); |
| | | |
| | | |
| | | // 推送到自动查询模块,进行扫描启动 |
| | | orderQueryListener.startScan(OrderScanType.C3M.getType()); |
| | | if(b){ |
| | | save(c3mOrderEntity); |
| | | // orderQueryListener.startScan(OrderScanType.C3M.getType()); // TODO 测试时关闭 |
| | | if (b) { |
| | | this.save(c3mOrderEntity); |
| | | } |
| | | return b ? c3mOrderEntity : null; |
| | | } |
| | |
| | | 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 (!updateById(userOrder)) { |
| | | return WxPayNotifyResponse.fail("更新数据已失效"); |
| | | } |
| | | /** |
| | | * 调起开始充电接口 // TODO |
| | | */ |
| | | |
| | | // UserPayRecord userPayRecord = new UserPayRecord(); |
| | | // userPayRecord.setOrderId(userOrder.getId()); |
| | | // userPayRecord.setPayAmount(userOrder.getTotalPrice()); |
| | | // userPayRecord.setPayType(PayTypeEnums.WECHAT.getCode()); |
| | | // userPayRecord.setPayDate(userOrder.getPayTime()); |
| | | // userPayRecord.setUserId(userOrder.getUserId()); |
| | | // userPayRecordService.save(userPayRecord); |
| | | |
| | | return WxPayNotifyResponse.success("更新数据成功"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 订单详情 by orderSn |
| | | * |
| | | * @param orderSn |
| | | * @return |
| | | */ |
| | | public C3mOrder getByOrderSn(String orderSn) { |
| | | LambdaQueryWrapper<C3mOrder> wrapper = Wrappers.lambdaQuery(C3mOrder.class).eq(C3mOrder::getOutTradeNo, orderSn).last("limit 1"); |
| | | return getOne(wrapper); |
| | | } |
| | | |
| | | /** |
| | | * 订单列表 |
| | | * |
| | | * @param baseConditionVO |
| | | * @return |
| | | */ |
| | | public List<C3mOrderBo> orderList(BaseConditionVO baseConditionVO) { |
| | | Long userId = SecurityUtils.getClientId(); |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | List<C3mOrderBo> list = baseMapper.orderList(userId); |
| | | return list; |
| | | } |
| | | } |