| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient; |
| | | import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.api.model.TChargingOrderAccountingStrategy; |
| | | import com.ruoyi.order.api.query.ChargingOrderQuery; |
| | |
| | | import com.ruoyi.order.mapper.TChargingOrderMapper; |
| | | import com.ruoyi.order.service.TChargingOrderAccountingStrategyService; |
| | | import com.ruoyi.order.service.TChargingOrderService; |
| | | import com.ruoyi.other.api.domain.TCoupon; |
| | | import com.ruoyi.other.api.domain.TVip; |
| | | import com.ruoyi.payment.api.feignClient.AliPaymentClient; |
| | | import com.ruoyi.payment.api.feignClient.WxPaymentClient; |
| | | import com.ruoyi.payment.api.vo.NotifyV3PayDecodeRespBody; |
| | | import com.ruoyi.payment.api.vo.PaymentOrder; |
| | | import com.ruoyi.payment.api.vo.*; |
| | | import io.seata.spring.annotation.GlobalTransactional; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private WxPaymentClient wxPaymentClient; |
| | | |
| | | @Resource |
| | | private AliPaymentClient aliPaymentClient; |
| | | |
| | | @Resource |
| | | private ChargingPileClient chargingPileClient; |
| | | |
| | | |
| | |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private UploadRealTimeMonitoringDataClient uploadRealTimeMonitoringDataClient; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取小程序充电记录列表数据 |
| | |
| | | .orderByAsc(TChargingOrderAccountingStrategy::getStartTime) |
| | | ); |
| | | myChargingOrderInfo.setStageCost(stageCost); |
| | | // todo 待完善 |
| | | //再MongoDB中获取数据 |
| | | myChargingOrderInfo.setCurrentAndVoltage(null); |
| | | //再MongoDB中获取数据 |
| | | myChargingOrderInfo.setPower(null); |
| | | List<UploadRealTimeMonitoringData> dataList = uploadRealTimeMonitoringDataClient.getDataByOrderCode(chargingOrder.getCode()).getData(); |
| | | if(null != dataList){ |
| | | //在MongoDB中获取数据 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); |
| | | List<String> time = dataList.stream().map(s -> sdf.format(s.getCreate_time())).collect(Collectors.toList()); |
| | | List<BigDecimal> outputVoltage = dataList.stream().map(UploadRealTimeMonitoringData::getOutput_voltage).collect(Collectors.toList()); |
| | | List<BigDecimal> outputCurrent = dataList.stream().map(UploadRealTimeMonitoringData::getOutput_current).collect(Collectors.toList()); |
| | | List<Map<String, Object>> currentAndVoltage = new ArrayList<>(); |
| | | for (int i = 0; i < time.size(); i++) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("time", time.get(i)); |
| | | //电流 |
| | | map.put("electricity", outputCurrent.get(i)); |
| | | //电压 |
| | | map.put("voltage", outputVoltage.get(i)); |
| | | currentAndVoltage.add(map); |
| | | } |
| | | myChargingOrderInfo.setCurrentAndVoltage(currentAndVoltage); |
| | | //在MongoDB中获取数据 |
| | | List<Integer> soc = dataList.stream().map(UploadRealTimeMonitoringData::getSoc).collect(Collectors.toList()); |
| | | List<BigDecimal> po = dataList.stream().map(s -> s.getOutput_current().multiply(s.getOutput_voltage()).divide(new BigDecimal(1000))).collect(Collectors.toList()); |
| | | List<Map<String, Object>> power = new ArrayList<>(); |
| | | for (int i = 0; i < time.size(); i++) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("time", time.get(i)); |
| | | //soc |
| | | map.put("soc", soc.get(i)); |
| | | //电压 |
| | | map.put("power", po.get(i)); |
| | | power.add(map); |
| | | } |
| | | myChargingOrderInfo.setPower(power); |
| | | } |
| | | myChargingOrderInfo.setActionable(myChargingOrderInfo.getEndTime() + 604800000L > System.currentTimeMillis() ? 0 : 1); |
| | | return myChargingOrderInfo; |
| | | } |
| | |
| | | } |
| | | } |
| | | if(2 == rechargePaymentType){ |
| | | |
| | | AliQueryOrder data = aliPaymentClient.query(tChargingOrder.getCode()).getData(); |
| | | if(null != data){ |
| | | //支付失败,删除无效的订单 |
| | | String tradeStatus = data.getTradeStatus(); |
| | | if(tradeStatus.equals("TRADE_CLOSED")){ |
| | | this.removeById(tChargingOrder.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | if(2 == one.getRechargePaymentType()){ |
| | | |
| | | AliQueryOrder data = aliPaymentClient.query(one.getCode()).getData(); |
| | | if(null != data){ |
| | | String trade_state = data.getTradeStatus(); |
| | | //支付失败,删除无效的订单 |
| | | if(trade_state.equals("TRADE_CLOSED")){ |
| | | this.removeById(one.getId()); |
| | | } |
| | | if(trade_state.equals("WAIT_BUYER_PAY")){ |
| | | //结束第三方支付,删除订单 |
| | | aliPaymentClient.close(one.getCode()); |
| | | this.removeById(one.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | return AjaxResult.success(data); |
| | | } |
| | | if(2 == addChargingOrder.getPaymentType()){ |
| | | |
| | | AliPaymentReq req = new AliPaymentReq(); |
| | | req.setOutTradeNo(chargingOrder.getCode()); |
| | | req.setTotalAmount(chargingOrder.getPaymentAmount().toString()); |
| | | req.setSubject("充电充值"); |
| | | req.setBuyerOpenId(appUser.getAliOpenid()); |
| | | req.setBody("充电充值"); |
| | | AliPaymentResp data = aliPaymentClient.payment(req).getData(); |
| | | if(null != data){ |
| | | data.setNotifyUrl(data.getNotifyUrl() + "/t-charging-order/chargingOrderALICallback"); |
| | | return AjaxResult.success(data); |
| | | } |
| | | } |
| | | throw new RuntimeException("无效的支付方式"); |
| | | } |
| | |
| | | BigDecimal electronicMoney = new BigDecimal("0"); |
| | | BigDecimal serviceMoney = new BigDecimal("0"); |
| | | for (ChargingOrderVO chargingOrderVO : list) { |
| | | total = total.add(chargingOrderVO.getChargingCapacity()); |
| | | if (chargingOrderVO.getChargingCapacity()!=null){ |
| | | total = total.add(chargingOrderVO.getChargingCapacity()); |
| | | } |
| | | // 充电订单 明细记录 |
| | | List<TChargingOrderAccountingStrategy> chargingOrderId = chargingOrderAccountingStrategyService.list(new QueryWrapper<TChargingOrderAccountingStrategy>() |
| | | .eq("charging_order_id", chargingOrderVO.getId())); |
| | |
| | | LocalDateTime startTime = chargingOrderVO.getStartTime(); |
| | | LocalDateTime endTime = chargingOrderVO.getEndTime(); |
| | | // 计算时间差 秒 充电时长 |
| | | long between = ChronoUnit.SECONDS.between(startTime, endTime); |
| | | chargingOrderVO.setChargingSecond(between); |
| | | time += between; |
| | | if (startTime!=null && endTime!=null){ |
| | | long between = ChronoUnit.SECONDS.between(startTime, endTime); |
| | | chargingOrderVO.setChargingSecond(between); |
| | | time += between; |
| | | } |
| | | // 总收入 |
| | | if (chargingOrderVO.getRefundStatus() == 2){ |
| | | income = income.add(chargingOrderVO.getPaymentAmount().subtract(chargingOrderVO.getRefundAmount())); |