| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.feignClient.*; |
| | | import com.ruoyi.account.api.model.*; |
| | |
| | | import com.ruoyi.common.core.dto.ChargingOrderGroup; |
| | | import com.ruoyi.common.core.dto.ChargingPercentProvinceDto; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.domain.BasePojo; |
| | | 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.order.service.TOrderEvaluateService; |
| | | import com.ruoyi.order.service.*; |
| | | import com.ruoyi.order.vo.EndOfChargePageInfo; |
| | | import com.ruoyi.order.vo.OrderCountByDate; |
| | | import com.ruoyi.order.vo.StatisticsOfBatteryVO; |
| | | import com.ruoyi.other.api.domain.*; |
| | | import com.ruoyi.order.vo.ChargingOrderListInfoVO; |
| | | import com.ruoyi.other.api.domain.TVip; |
| | | import com.ruoyi.other.api.feignClient.*; |
| | | import com.ruoyi.payment.api.feignClient.AliPaymentClient; |
| | | import com.ruoyi.payment.api.feignClient.H5AliPaymentClient; |
| | | import com.ruoyi.payment.api.feignClient.WxPaymentClient; |
| | | import com.ruoyi.payment.api.model.RefundReq; |
| | | import com.ruoyi.payment.api.model.RefundResp; |
| | |
| | | |
| | | @Resource |
| | | private AliPaymentClient aliPaymentClient; |
| | | @Resource |
| | | private H5AliPaymentClient h5AliPaymentClient; |
| | | |
| | | @Resource |
| | | private AppCouponClient appCouponClient; |
| | |
| | | |
| | | @Resource |
| | | private ITChargingOrderSummaryDataService chargingOrderSummaryDataService; |
| | | @Resource |
| | | private TOrderAppealService orderAppealService; |
| | | |
| | | |
| | | |
| | |
| | | TChargingOrder chargingOrder = this.getById(id); |
| | | MyChargingOrderInfo myChargingOrderInfo = new MyChargingOrderInfo(); |
| | | myChargingOrderInfo.setId(id); |
| | | myChargingOrderInfo.setChargingGunId(chargingOrder.getChargingGunId()); |
| | | myChargingOrderInfo.setCode(chargingOrder.getCode()); |
| | | myChargingOrderInfo.setCreateTime(chargingOrder.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | myChargingOrderInfo.setStatus(chargingOrder.getStatus()); |
| | |
| | | myChargingOrderInfo.setPower(power); |
| | | } |
| | | myChargingOrderInfo.setActionable(myChargingOrderInfo.getEndTime() + 604800000L < System.currentTimeMillis() ? 0 : 1); |
| | | long count = orderAppealService.count(Wrappers.lambdaQuery(TOrderAppeal.class) |
| | | .eq(TOrderAppeal::getOrderId, id)); |
| | | myChargingOrderInfo.setIsAppeal(count>0?0:1); |
| | | return myChargingOrderInfo; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | if(3 == rechargePaymentType){ |
| | | AliQueryOrder data = h5AliPaymentClient.query(tChargingOrder.getCode()).getData(); |
| | | if(null != data){ |
| | | //支付失败,删除无效的订单 |
| | | String tradeStatus = data.getTradeStatus(); |
| | | if(null != tradeStatus && tradeStatus.equals("TRADE_CLOSED")){ |
| | | this.removeById(tChargingOrder.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //检查当前枪是否是正在使用中 |
| | |
| | | if(trade_state.equals("WAIT_BUYER_PAY")){ |
| | | //结束第三方支付,删除订单 |
| | | aliPaymentClient.close(one.getCode()); |
| | | this.removeById(one.getId()); |
| | | } |
| | | } |
| | | } |
| | | if(3 == one.getRechargePaymentType()){ |
| | | AliQueryOrder data = h5AliPaymentClient.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")){ |
| | | //结束第三方支付,删除订单 |
| | | h5AliPaymentClient.close(one.getCode()); |
| | | this.removeById(one.getId()); |
| | | } |
| | | } |
| | |
| | | AliPaymentResp data = aliPaymentClient.payment(req).getData(); |
| | | if(null != data){ |
| | | return AjaxResult.success(data); |
| | | } |
| | | } |
| | | if(3 == addChargingOrder.getPaymentType()){ |
| | | AliPaymentReq req = new AliPaymentReq(); |
| | | req.setOutTradeNo(chargingOrder.getCode()); |
| | | req.setTotalAmount(addChargingOrder.getPaymentAmount().toString()); |
| | | req.setSubject("充电充值"); |
| | | req.setBuyerOpenId(appUser.getAliOpenid()); |
| | | req.setBody("充电充值"); |
| | | req.setNotifyUrl("/payment/aliH5/callBack"); |
| | | req.setReturnUrl(addChargingOrder.getReturnUrl()); |
| | | String data = h5AliPaymentClient.payment(req).getData(); |
| | | if(StringUtils.hasLength(data)){ |
| | | return AjaxResult.success("操作成功",data); |
| | | } |
| | | } |
| | | throw new RuntimeException("无效的支付方式"); |
| | |
| | | chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null); |
| | | } |
| | | } |
| | | if(3 == rechargePaymentType){ |
| | | RefundReq dto = new RefundReq(); |
| | | dto.setOutTradeNo(chargingOrder.getCode()); |
| | | dto.setOutRequestNo(chargingOrderRefund.getCode()); |
| | | dto.setRefundAmount(rechargeAmount.toString()); |
| | | dto.setRefundReason("充电失败,取消充电订单"); |
| | | RefundResp resp = h5AliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | //回退会员折扣次数 |
| | | if(chargingOrder.getVipDiscountAmount().compareTo(BigDecimal.ZERO) > 0){ |
| | | TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); |
| | | GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail(); |
| | | getAppUserVipDetail.setAppUserId(chargingOrder.getAppUserId()); |
| | | getAppUserVipDetail.setVipId(appUser.getVipId()); |
| | | TAppUserVipDetail data = appUserVipDetailClient.getAppUserVipDetail(getAppUserVipDetail).getData(); |
| | | if(null != data){ |
| | | data.setChargeNum(data.getChargeNum() + 1); |
| | | appUserVipDetailClient.updateAppUserVipDetail(data); |
| | | } |
| | | } |
| | | |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null); |
| | | } |
| | | } |
| | | |
| | | if(3 == rechargePaymentType){ |
| | | RefundReq dto = new RefundReq(); |
| | | dto.setOutTradeNo(chargingOrder.getCode()); |
| | | dto.setOutRequestNo(chargingOrderRefund.getCode()); |
| | | dto.setRefundAmount(money.toString()); |
| | | dto.setRefundReason("充电完成退款"); |
| | | RefundResp resp = h5AliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null); |
| | | } |
| | | } |
| | | |
| | | if(3 == rechargePaymentType){ |
| | | RefundReq dto = new RefundReq(); |
| | | dto.setOutTradeNo(chargingOrder.getCode()); |
| | | dto.setOutRequestNo(chargingOrderRefund.getRefundCode()); |
| | | dto.setRefundAmount(refundAmount.toString()); |
| | | dto.setRefundReason("充电完成退款"); |
| | | RefundResp resp = h5AliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | } |
| | | if(3 == tChargingOrder.getRechargePaymentType()){ |
| | | RefundReq dto = new RefundReq(); |
| | | dto.setOutTradeNo(tChargingOrder.getCode()); |
| | | dto.setOutRequestNo(tChargingOrder.getCode()); |
| | | dto.setRefundAmount(payOrderQueryDto.getRefundAmount().toString()); |
| | | dto.setRefundReason("取消订单"); |
| | | RefundResp resp = h5AliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | chargingOrderRefund.setRefundStatus(2); |
| | | chargingOrderRefund.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount())); |
| | | this.baseMapper.updateById(tChargingOrder); |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | |
| | | } |
| | | } |
| | | } |
| | | if (payOrderQueryDto.getType()==2){ |
| | | TShoppingOrder tChargingOrder = shoppingOrderService.getById(payOrderQueryDto.getOrderId()); |
| | |
| | | shoppingOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | | if(3 == tChargingOrder.getPaymentType()){ |
| | | RefundReq dto = new RefundReq(); |
| | | dto.setOutTradeNo(tChargingOrder.getCode()); |
| | | dto.setOutRequestNo(tChargingOrder.getCode()); |
| | | dto.setRefundAmount(payOrderQueryDto.getRefundAmount().toString()); |
| | | dto.setRefundReason("取消订单"); |
| | | RefundResp resp = h5AliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | tChargingOrder.setRefundStatus(2); |
| | | tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount())); |
| | | shoppingOrderService.updateById(tChargingOrder); |
| | | shoppingOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | dto.setRefundAmount(payOrderQueryDto.getRefundAmount().toString()); |
| | | dto.setRefundReason("取消订单"); |
| | | RefundResp resp = aliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | tChargingOrder.setRefundStatus(2); |
| | | tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount())); |
| | | vipOrderService.updateById(tChargingOrder); |
| | | vipOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | | if(3 == tChargingOrder.getPaymentType()){ |
| | | RefundReq dto = new RefundReq(); |
| | | dto.setOutTradeNo(tChargingOrder.getCode()); |
| | | dto.setOutRequestNo(tChargingOrder.getCode()); |
| | | dto.setRefundAmount(payOrderQueryDto.getRefundAmount().toString()); |
| | | dto.setRefundReason("取消订单"); |
| | | RefundResp resp = h5AliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | tChargingOrder.setRefundStatus(2); |
| | | tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount())); |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 大屏-新能源汽车电池安全检测次数统计 |
| | | */ |
| | | @Override |
| | | public R<StatisticsOfBatteryVO> getStatisticsOfBattery() { |
| | | StatisticsOfBatteryVO vo = new StatisticsOfBatteryVO(); |
| | | //1.计算累计次数 |
| | | //查询该俩站点的快充和超充的充电枪id集合 site_id 25 26 charge_model 1 2 |
| | | R<List<Integer>> r = chargingGunClient.getGunIdsBySiteIdsAndChargeModels(Arrays.asList(25,26),Arrays.asList(1,2)); |
| | | if (r.getCode()!=200){ |
| | | return R.ok(vo); |
| | | } |
| | | List<Integer> gunIds=r.getData(); |
| | | //统计 |
| | | Long total= 0L; |
| | | if(gunIds!=null && !gunIds.isEmpty()) { |
| | | total = this.baseMapper.selectCount(new LambdaQueryWrapper<TChargingOrder>() |
| | | .eq(TChargingOrder::getDelFlag, 0)//未删除 |
| | | .in(TChargingOrder::getStatus, Arrays.asList(3, 5))//充电中、已结束 |
| | | .in(TChargingOrder::getChargingGunId, gunIds));//符合条件的充电枪 |
| | | } |
| | | vo.setTotal(total.intValue()); |
| | | //2.折线图 |
| | | /* // 计算日期范围:前七天(不含今日)直接查找数据量太大,内存报错 |
| | | LocalDate today = LocalDate.now(); |
| | | LocalDateTime startDate = today.minusDays(7).atStartOfDay(); |
| | | LocalDateTime endDate = today.minusDays(1).atTime(LocalTime.MAX); |
| | | // 查询数据库 |
| | | List<OrderCountByDate> orderCounts = this.baseMapper.countOrdersByDate(startDate, endDate, gunIds);*/ |
| | | |
| | | |
| | | List<LocalDate> dates = new ArrayList<>(); |
| | | List<Integer> counts = new ArrayList<>(); |
| | | LocalDate today = LocalDate.now(); |
| | | // 直接查找数据量太大,内存报错,分每天查找 |
| | | for (int i = 7; i >= 1; i--) {//升序 |
| | | LocalDate day = today.minusDays(i); |
| | | LocalDateTime startOfDay = day.atStartOfDay(); |
| | | LocalDateTime endOfDay = day.atTime(LocalTime.MAX); |
| | | //统计 |
| | | Long count=0L; |
| | | if(gunIds!=null && !gunIds.isEmpty()){ |
| | | count = this.baseMapper.selectCount(new LambdaQueryWrapper<TChargingOrder>() |
| | | .eq(TChargingOrder::getDelFlag,0)//未删除 |
| | | .in(TChargingOrder::getStatus,Arrays.asList(3,5))//充电中、已结束 |
| | | .in(TChargingOrder::getChargingGunId,gunIds)//符合条件的充电枪 站点 超充快充 |
| | | .between(TChargingOrder::getCreateTime,startOfDay,endOfDay));//每天 |
| | | } |
| | | dates.add(day); |
| | | counts.add(count.intValue()); |
| | | } |
| | | vo.setDates(dates); |
| | | vo.setCounts(counts); |
| | | return R.ok(vo); |
| | | } |
| | | @Override |
| | | public BigDecimal getSumDegreeBySiteIds(List<Integer> siteIds) { |
| | | |
| | | return this.baseMapper.getSumDegreeBySiteIds(siteIds); |
| | | |
| | | } |
| | | } |