From 99eddbebf80c5549a7487caed95b041abdc9bb5f Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期一, 14 七月 2025 14:06:40 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java |  340 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 315 insertions(+), 25 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
index 654db7e..5d21287 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -4,6 +4,7 @@
 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.*;
@@ -17,6 +18,7 @@
 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;
@@ -30,6 +32,7 @@
 import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData;
 import com.ruoyi.integration.api.feignClient.*;
 import com.ruoyi.integration.api.model.*;
+import com.ruoyi.integration.api.vo.ChargingOrderVo;
 import com.ruoyi.integration.api.vo.GetPlatformStopChargingReply;
 import com.ruoyi.integration.api.vo.StartChargeResult;
 import com.ruoyi.order.api.dto.SettlementConfirmAdd;
@@ -49,15 +52,19 @@
 import com.ruoyi.order.service.TChargingOrderService;
 import com.ruoyi.order.service.TOrderEvaluateService;
 import com.ruoyi.order.service.*;
+import com.ruoyi.order.util.RedisLock;
 import com.ruoyi.order.util.mongodb.service.PlatformStartChargingReplyService;
 import com.ruoyi.order.util.mongodb.service.TransactionRecordService;
 import com.ruoyi.order.util.mongodb.service.UploadRealTimeMonitoringDataService;
 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;
@@ -66,10 +73,14 @@
 import com.ruoyi.system.api.domain.SysUser;
 import com.ruoyi.system.api.feignClient.SysUserClient;
 import io.seata.spring.annotation.GlobalTransactional;
+import org.redisson.Redisson;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
@@ -131,6 +142,8 @@
 	
 	@Resource
 	private AliPaymentClient aliPaymentClient;
+	@Resource
+	private H5AliPaymentClient h5AliPaymentClient;
 
 	@Resource
 	private AppCouponClient appCouponClient;
@@ -212,6 +225,14 @@
 	
 	@Resource
 	private ITChargingOrderSummaryDataService chargingOrderSummaryDataService;
+	@Resource
+	private TOrderAppealService orderAppealService;
+	
+	@Autowired
+	private RedissonClient redissonClient;
+	
+	@Resource
+	private ChargingMessageClient chargingMessageClient;
 
 
 
@@ -266,6 +287,7 @@
 		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());
@@ -345,6 +367,9 @@
 			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;
 	}
 	
@@ -416,11 +441,21 @@
 					}
 				}
 			}
+			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());
+					}
+				}
+			}
 		}
 		
 		//检查当前枪是否是正在使用中
 		TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getChargingGunId, addChargingOrder.getId())
-				.in(TChargingOrder::getStatus, Arrays.asList(1, 2, 3)).eq(TChargingOrder::getDelFlag, 0));
+				.in(TChargingOrder::getStatus, Arrays.asList(3)).eq(TChargingOrder::getDelFlag, 0));
 		if(null != one){
 			return AjaxResult.error("充电枪正在充电中,启动失败");
 		}
@@ -454,6 +489,21 @@
 					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());
 					}
 				}
@@ -559,6 +609,20 @@
 			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("无效的支付方式");
@@ -747,24 +811,30 @@
 			
 			//清除计时器中的无效数据
 			counter_map.remove(code);
-			TChargingOrder order = new TChargingOrder();
-			order.setId(id);
-			order.setAppUserId(chargingOrder.getAppUserId());
 			if(0 == startup_result){
 				//启动失败
 				preChargeCheck1.setStartupSuccess(3);
 				preChargeCheck1.setFailureCause(failure_cause);
 				//启动失败后取消订单,退款操作
 				refund(code);
-				order.setStatus(-1);
-				order.setEndMode(0);
+				chargingOrder.setStatus(-1);
+				chargingOrder.setEndMode(0);
 			}else{
 				//启动成功
 				preChargeCheck1.setStartupSuccess(2);
-				order.setStatus(3);
-				order.setStartTime(LocalDateTime.now());
+				chargingOrder.setStatus(3);
+				chargingOrder.setStartTime(LocalDateTime.now());
 			}
-			this.updateById(order);
+			this.updateById(chargingOrder);
+			if(chargingOrder.getStatus() == 3){
+				//推送监管平台订单状态
+				new Thread(()->{
+					ChargingOrderVo chargingOrderVo = new ChargingOrderVo();
+					BeanUtils.copyProperties(chargingOrder, chargingOrderVo);
+					chargingMessageClient.pushOrderStatus(chargingOrderVo);
+				}).start();
+			}
+			
 			redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS);
 			//推送三方平台订单状态
 			if(2 == chargingOrder.getOrderSource()){
@@ -868,6 +938,15 @@
 		}
 		redisService.setCacheObject("AQJC_" + order.getChargingGunId(), preChargeCheck1, 24L, TimeUnit.HOURS);
 		this.updateById(order);
+		
+		if(3 == order.getStatus()){
+			//推送监管平台订单状态
+			new Thread(()->{
+				ChargingOrderVo chargingOrderVo = new ChargingOrderVo();
+				BeanUtils.copyProperties(order, chargingOrderVo);
+				chargingMessageClient.pushOrderStatus(chargingOrderVo);
+			}).start();
+		}
 		//推送三方平台启动充电结果
 		if(2 == order.getOrderSource()){
 			StartChargeResult result = new StartChargeResult();
@@ -973,6 +1052,36 @@
 					chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
 				}
 			}
+			if(3 == rechargePaymentType){
+				RefundReq dto = new RefundReq();
+				dto.setOutTradeNo(chargingOrder.getRechargeSerialNumber());
+				dto.setOutRequestNo(chargingOrderRefund.getCode());
+				dto.setRefundAmount(rechargeAmount.toString());
+				dto.setRefundReason("充电失败,取消充电订单");
+				RefundResp resp = h5AliPaymentClient.refund(dto).getData();
+				if(null != resp && "10000".equals(resp.getCode())){
+					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);
+				}
+			}
 
 		}
 	}
@@ -1040,7 +1149,24 @@
 					chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
 				}
 			}
-			
+			if(3 == rechargePaymentType){
+				RefundReq dto = new RefundReq();
+				dto.setOutTradeNo(chargingOrder.getRechargeSerialNumber());
+				dto.setOutRequestNo(chargingOrderRefund.getCode());
+				dto.setRefundAmount(money.toString());
+				dto.setRefundReason("充电完成退款");
+				RefundResp resp = h5AliPaymentClient.refund(dto).getData();
+				if(null != resp && "10000".equals(resp.getCode())){
+					chargingOrderRefundService.save(chargingOrderRefund);
+					try {
+						Thread.sleep(1000);
+					} catch (InterruptedException e) {
+						throw new RuntimeException(e);
+					}
+					chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
+				}
+			}
+
 		}
 	}
 
@@ -1138,13 +1264,11 @@
 		if(!order.getAppUserId().equals(userId)){
 			return AjaxResult.error("权限不足");
 		}
-		TChargingOrder chargingOrder = new TChargingOrder();
-		chargingOrder.setId(Long.valueOf(id));
-		chargingOrder.setAppUserId(order.getAppUserId());
-		chargingOrder.setEndTime(LocalDateTime.now());
-		chargingOrder.setStatus(4);
-		chargingOrder.setEndMode(1);
-		this.updateById(chargingOrder);
+		order.setEndTime(LocalDateTime.now());
+		order.setStatus(4);
+		order.setEndMode(1);
+		this.updateById(order);
+		
 		String code1 = order.getCode();
 		TChargingGun chargingGun = chargingGunClient.getChargingGunById(order.getChargingGunId()).getData();
 		//异步线程处理停机
@@ -1158,6 +1282,12 @@
 			sendMessageClient.platformStopCharging(platformStopCharging);
 			log.info(code1 + ":-------------------远程停止充电请求-------------------");
 			log.info(platformStopCharging.toString());
+			
+			//推送监管平台订单状态和订单详情
+			ChargingOrderVo chargingOrderVo = new ChargingOrderVo();
+			BeanUtils.copyProperties(order, chargingOrderVo);
+			chargingMessageClient.pushOrderInfo(chargingOrderVo);
+			chargingMessageClient.pushOrderStatus(chargingOrderVo);
 		});
 		//推送三方平台
 		if(2 == order.getOrderSource()){
@@ -2143,7 +2273,7 @@
 			}
 			chargingOrder.setChargingCapacity(query.getCharging_degree());
 			chargingOrder.setElectricity(query.getCharging_degree());
-			chargingOrder.setTotalElectricity(new BigDecimal(100 - query.getSoc()));
+			chargingOrder.setTotalElectricity(new BigDecimal(query.getSoc()));
 			this.updateById(chargingOrder);
 		}
 	}
@@ -2179,12 +2309,18 @@
 	 */
 	@Override
 	public R endChargeBillingCharge(TransactionRecordMessageVO vo) {
-		Boolean hasKey = redisService.hasKey("endOrder:" + vo.getTransaction_serial_number());
-		if(hasKey){
+		RLock lock = redissonClient.getLock("endOrder:" + vo.getTransaction_serial_number());
+		boolean tryLock = false;
+		try {
+			tryLock = lock.tryLock(100, TimeUnit.SECONDS);
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+			lock.unlock();
 			return R.ok();
 		}
-		//添加1分钟的缓存
-		redisService.setCacheObject("endOrder:" + vo.getTransaction_serial_number(), vo.getTransaction_serial_number(), 1L, TimeUnit.MINUTES);
+		if(!tryLock){
+			return R.ok();
+		}
 		try {
 			TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, vo.getTransaction_serial_number()));
 			if(null == chargingOrder){
@@ -2205,6 +2341,9 @@
 			
 			//获取订单的计费策略
 			List<AccountingStrategyDetailOrder> accountingStrategyDetailOrderList = accountingStrategyDetailOrderClient.getAllAccountingStrategyDetailOrder(chargingOrder.getId()).getData();
+			if(accountingStrategyDetailOrderList.isEmpty()){
+				return R.fail("计费策略为空,无法计算费用");
+			}
 			accountingStrategyDetailOrderList.get(accountingStrategyDetailOrderList.size() - 1).setEndTime("23:59");
 			//开始处理计费明细数据和优惠数据
 			chargingOrderAccountingStrategyService.remove(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()));
@@ -2617,7 +2756,18 @@
 							this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
 						}
 					}
-					
+					if(3 == rechargePaymentType){
+						RefundReq dto = new RefundReq();
+						dto.setOutTradeNo(chargingOrder.getRechargeSerialNumber());
+						dto.setOutRequestNo(chargingOrderRefund.getRefundCode());
+						dto.setRefundAmount(refundAmount.toString());
+						dto.setRefundReason("充电完成退款");
+						RefundResp resp = h5AliPaymentClient.refund(dto).getData();
+						if(null != resp && "10000".equals(resp.getCode())){
+							chargingOrderRefundService.save(chargingOrderRefund);
+							this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
+						}
+					}
 				}
 			}
 			
@@ -2653,7 +2803,7 @@
 		}catch (Exception e) {
 			e.printStackTrace();
 		}finally {
-			redisService.deleteObject("endOrder:" + vo.getTransaction_serial_number());
+			lock.unlock();
 		}
 		return R.ok();
 	}
@@ -2823,6 +2973,21 @@
 
 					}
 				}
+				if(3 == tChargingOrder.getRechargePaymentType()){
+					RefundReq dto = new RefundReq();
+					dto.setOutTradeNo(tChargingOrder.getRechargeSerialNumber());
+					dto.setOutRequestNo(tChargingOrder.getCode());
+					dto.setRefundAmount(payOrderQueryDto.getRefundAmount().toString());
+					dto.setRefundReason("取消订单");
+					RefundResp resp = h5AliPaymentClient.refund(dto).getData();
+					if(null != resp && "10000".equals(resp.getCode())){
+						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());
@@ -2890,6 +3055,20 @@
 						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);
+//					}
+//				}
 
 			}
 
@@ -2955,6 +3134,20 @@
 					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()));
+//					vipOrderService.updateById(tChargingOrder);
+//					vipOrderRefundService.save(chargingOrderRefund);
+//				}
+//			}
 		}
 		return R.ok();
 	}
@@ -3964,7 +4157,6 @@
 		chargingOrder.setStatus(4);
 		chargingOrder.setEndMode(1);
 		this.updateById(chargingOrder);
-		
 		tcecClient.notificationEquipChargeStatus(order.getStartChargeSeq(), order.getOperatorId());
 		
 		String code1 = order.getCode();
@@ -3980,6 +4172,12 @@
 			sendMessageClient.platformStopCharging(platformStopCharging);
 			log.info(code1 + ":-------------------远程停止充电请求-------------------");
 			log.info(platformStopCharging.toString());
+			
+			//推送监管平台订单状态和订单详情
+			ChargingOrderVo chargingOrderVo = new ChargingOrderVo();
+			BeanUtils.copyProperties(chargingOrder, chargingOrderVo);
+			chargingMessageClient.pushOrderInfo(chargingOrderVo);
+			chargingMessageClient.pushOrderStatus(chargingOrderVo);
 		});
 		return R.ok();
 	}
@@ -4064,4 +4262,96 @@
 		}
 		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);
+
+	}
+	
+	
+	/**
+	 * 获取启动失败且时间超过1小时的订单
+	 * @return
+	 */
+	@Override
+	public List<TChargingOrder> findFailedStartupOrder() {
+		return this.baseMapper.findFailedStartupOrder();
+	}
+	
+	
+	/**
+	 * 获取停止中的数据
+	 * @return
+	 */
+	@Override
+	public List<TChargingOrder> findStoppedOrder() {
+		return this.baseMapper.findStoppedOrder();
+	}
+	
+	
+	/**
+	 * 获取充电中的数据
+	 * @return
+	 */
+	@Override
+	public List<TChargingOrder> findChargingOrder() {
+		return this.baseMapper.findChargingOrder();
+	}
 }

--
Gitblit v1.7.1