From ae76f22f897cfd438b30829326b6ad36a80eaac0 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 21 二月 2025 18:23:13 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java |  561 +++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 416 insertions(+), 145 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 098dd01..6a24a15 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
@@ -32,6 +32,7 @@
 import com.ruoyi.integration.api.feignClient.*;
 import com.ruoyi.integration.api.model.*;
 import com.ruoyi.integration.api.vo.GetPlatformStopChargingReply;
+import com.ruoyi.integration.api.vo.StartChargeResult;
 import com.ruoyi.order.api.dto.SettlementConfirmAdd;
 import com.ruoyi.order.api.feignClient.AccountingStrategyDetailOrderClient;
 import com.ruoyi.order.api.feignClient.AccountingStrategyOrderClient;
@@ -66,6 +67,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
@@ -141,7 +143,7 @@
 	private UploadRealTimeMonitoringDataClient uploadRealTimeMonitoringDataClient;
 	
 	@Resource
-	private ChargingHandshakeClient chargingHandshakeClient;
+	private TCECClient tcecClient;
 
 	@Resource
 	private SendMessageClient sendMessageClient;
@@ -202,6 +204,12 @@
 	
 	//计数器
 	private Map<String, Integer> boot_failed_map = new HashMap<>();
+	
+	@Resource
+	private OperatorClient operatorClient;
+	
+	@Resource
+	private TransactionRecordClient transactionRecordClient;
 
 
 
@@ -272,6 +280,8 @@
 			}else{
 				myChargingOrderInfo.setLicensePlate("无");
 			}
+		}else{
+			myChargingOrderInfo.setLicensePlate(chargingOrder.getPlateNum());
 		}
 		myChargingOrderInfo.setStartTime(chargingOrder.getStartTime().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond() * 1000);
 		myChargingOrderInfo.setEndTime(chargingOrder.getEndTime().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond() * 1000);
@@ -455,6 +465,12 @@
 		chargingOrder.setOrderClassification(1);
 		chargingOrder.setAppUserId(userId);
 		chargingOrder.setAppUserCarId(addChargingOrder.getAppUserCarId());
+		if(null != addChargingOrder.getAppUserCarId()){
+			TAppUserCar userCar = appUserCarClient.getCarById(addChargingOrder.getAppUserCarId().toString()).getData();
+			if(null != userCar){
+				chargingOrder.setPlateNum(userCar.getLicensePlate());
+			}
+		}
 		TChargingGun tChargingGun = chargingGunClient.getChargingGunById(addChargingOrder.getId()).getData();
 		TChargingPile chargingPile = chargingPileClient.getChargingPileById(tChargingGun.getChargingPileId()).getData();
 		chargingOrder.setSiteId(tChargingGun.getSiteId());
@@ -465,7 +481,7 @@
 		chargingOrder.setRechargeAmount(addChargingOrder.getPaymentAmount());
 		chargingOrder.setAppCouponId(addChargingOrder.getAppUserCouponId());
 		chargingOrder.setVipDiscountAmount(BigDecimal.ZERO);
-		chargingOrder.setOrderSource(0);
+		chargingOrder.setOrderSource(1);
 		chargingOrder.setTitle("【充电桩充电】" + chargingPile.getNumber() + "号桩/" + tChargingGun.getCode() + "号枪");
 		
 		Site site = siteClient.getSiteByIds(Arrays.asList(tChargingGun.getSiteId())).getData().get(0);
@@ -599,6 +615,7 @@
 			if(null != data && data.getChargeNum() > 0){
 				//计算折扣
 				List<AccountingStrategyDetailOrder> list = accountingStrategyDetailOrderClient.getAllAccountingStrategyDetailOrder(chargingOrder.getId()).getData();
+				list.get(list.size() - 1).setEndTime("23:59");
 				//将数据叠加两份,处理跨天的情况
 				list.addAll(list);
 				boolean sta = false;
@@ -744,6 +761,10 @@
 			}
 			this.updateById(order);
 			redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS);
+			//推送三方平台订单状态
+			if(2 == chargingOrder.getOrderSource()){
+				tcecClient.notificationEquipChargeStatus(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId());
+			}
 			return true;
 		}else{
 			Integer counter = boot_failed_map.get(code);
@@ -774,6 +795,10 @@
 			order.setEndMode(0);
 			this.updateById(order);
 			redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS);
+			//推送三方平台订单状态
+			if(2 == chargingOrder.getOrderSource()){
+				tcecClient.notificationEquipChargeStatus(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId());
+			}
 			return true;
 		}
 	}
@@ -833,9 +858,24 @@
 			TChargingGun chargingGun = chargingGunClient.getChargingGunById(order.getChargingGunId()).getData();
 			chargingGun.setStatus(4);
 			chargingGunClient.updateChargingGunById(chargingGun);
+			//推送状态给三方平台
+			tcecClient.pushChargingGunStatus(chargingGun.getFullNumber(), chargingGun.getStatus());
 		}
 		redisService.setCacheObject("AQJC_" + order.getChargingGunId(), preChargeCheck1, 24L, TimeUnit.HOURS);
 		this.updateById(order);
+		//推送三方平台启动充电结果
+		if(2 == order.getOrderSource()){
+			StartChargeResult result = new StartChargeResult();
+			result.setStartChargeSeq(order.getStartChargeSeq());
+			result.setStartChargeSeqStat(3 == order.getStatus() ? 2 : 4);
+			result.setConnectorID(order.getChargingGunId().toString());
+			result.setStartTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+			Operator operator = operatorClient.getOperatorById(order.getOperatorId()).getData();
+			result.setOperatorID(operator.getOperatorId());
+			tcecClient.notificationStartChargeResult(result);
+			
+			tcecClient.notificationEquipChargeStatus(order.getStartChargeSeq(), order.getOperatorId());
+		}
 	}
 	
 	/**
@@ -845,7 +885,7 @@
 	public void refund(String code){
 		log.info(code + ":-------------------充电启动失败,执行退款-------------------");
 		TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code));
-		if(chargingOrder.getStatus() == 2){
+		if(chargingOrder.getOrderSource() == 1 && chargingOrder.getStatus() == 2){
 			Integer rechargePaymentType = chargingOrder.getRechargePaymentType();
 			BigDecimal rechargeAmount = chargingOrder.getRechargeAmount();
 			//构建退款明细
@@ -875,9 +915,15 @@
 				amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue());
 				amount.setCurrency("CNY");
 				model.setAmount(amount);
-				R<String> orderR = wxPaymentClient.refundOrderR(model);
+				R<Map<String, Object>> orderR = wxPaymentClient.refundOrderR(model);
 				if(200 == orderR.getCode()){
 					chargingOrderRefundService.save(chargingOrderRefund);
+					//手续费
+					Map<String, Object> amount1 = (Map<String, Object>) orderR.getData().get("amount");
+					Object refund_fee1 = amount1.get("refund_fee");
+					BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100));
+					chargingOrderRefund.setRefundFee(refund_fee);
+					chargingOrderRefundService.updateById(chargingOrderRefund);
 				}
 			}
 			if(2 == rechargePaymentType){
@@ -1003,7 +1049,6 @@
 		chargingOrder.setStatus(4);
 		chargingOrder.setEndMode(1);
 		this.updateById(chargingOrder);
-		
 		String code1 = order.getCode();
 		TChargingGun chargingGun = chargingGunClient.getChargingGunById(order.getChargingGunId()).getData();
 		//异步线程处理停机
@@ -1018,6 +1063,11 @@
 			log.info(code1 + ":-------------------远程停止充电请求-------------------");
 			log.info(platformStopCharging.toString());
 		});
+		//推送三方平台
+		if(2 == order.getOrderSource()){
+			tcecClient.notificationEquipChargeStatus(order.getStartChargeSeq(), order.getOperatorId());
+		}
+		
 		return AjaxResult.success();
 	}
 	
@@ -1279,8 +1329,8 @@
 				}
 
 			}
-			chargingOrderVO.setCommissionAmount(chargingOrderVO.getOrderAmount()!=null?chargingOrderVO.getOrderAmount().multiply(new BigDecimal("0.006")):new BigDecimal("0"));
-			chargingOrderVO.setPlatFormMoney(chargingOrderVO.getOrderAmount()!=null?chargingOrderVO.getOrderAmount().multiply(new BigDecimal("0.006")).setScale(2,BigDecimal.ROUND_DOWN):new BigDecimal("0"));
+			chargingOrderVO.setCommissionAmount(chargingOrderVO.getRechargeAmount()!=null?chargingOrderVO.getRechargeAmount().multiply(new BigDecimal("0.006")):new BigDecimal("0"));
+			chargingOrderVO.setPlatFormMoney(chargingOrderVO.getRechargeAmount()!=null?chargingOrderVO.getRechargeAmount().multiply(new BigDecimal("0.006")).setScale(2,BigDecimal.ROUND_DOWN):new BigDecimal("0"));
 			chargingOrderVO.setUid(chargingOrderVO.getId()+"");
 			TChargingGun data3 = allGun.stream().filter(e->e.getId().equals(chargingOrderVO.getChargingGunId())).findFirst().orElse(null);
 			TChargingPile data2 = allPile.stream().filter(e->e.getId().equals(chargingOrderVO.getChargingPileId())).findFirst().orElse(null);
@@ -1318,6 +1368,8 @@
 					if (tAppUserCar!=null){
 						chargingOrderVO.setLicensePlate(tAppUserCar.getLicensePlate());
 					}
+				}else{
+					chargingOrderVO.setLicensePlate(chargingOrderVO.getPlateNum());
 				}
 
 			}
@@ -1332,7 +1384,9 @@
 
 		for (ChargingOrderVO chargingOrderVO : list1) {
 			paymentMoney= paymentMoney.add(chargingOrderVO.getPaymentAmount()!=null?chargingOrderVO.getPaymentAmount():new BigDecimal("0"));
-			commissionMoney = commissionMoney.add(chargingOrderVO.getOrderAmount()!=null?chargingOrderVO.getOrderAmount().multiply(new BigDecimal("0.006")):new BigDecimal("0"));
+			if (chargingOrderVO.getRechargeAmount()!=null){
+				commissionMoney = commissionMoney.add(chargingOrderVO.getRechargeAmount().multiply(new BigDecimal("0.006")).setScale(2,BigDecimal.ROUND_DOWN));
+			}
 			if (chargingOrderVO.getChargingCapacity()!=null){
 				total = total.add(chargingOrderVO.getElectricity()!=null?chargingOrderVO.getElectricity():new BigDecimal("0"));
 			}
@@ -1353,7 +1407,8 @@
 		}
 		tCharingOrderVO.setTotal(total);
 		tCharingOrderVO.setTime(time);
-		tCharingOrderVO.setIncome(paymentMoney.subtract(commissionMoney));
+//		tCharingOrderVO.setIncome(paymentMoney.subtract(commissionMoney));
+		tCharingOrderVO.setIncome(paymentMoney);
 		tCharingOrderVO.setElectronicMoney(electronicMoney);
 		tCharingOrderVO.setServiceMoney(serviceMoney);
 		pageInfo.setRecords(list);
@@ -1531,7 +1586,7 @@
 			chargingOrderListVO.setChargingCapacity(chargingOrderListVO.getElectricity());
 			BigDecimal bigDecimal = new BigDecimal("0.006");
 			if (chargingOrderListVO.getOrderAmount()!=null){
-				chargingOrderListVO.setCommissionAmount(chargingOrderListVO.getPaymentAmount().multiply(bigDecimal));
+				chargingOrderListVO.setCommissionAmount(chargingOrderListVO.getRechargeAmount().multiply(bigDecimal));
 			}
 			chargingOrderListVO.setPaymentAmount(chargingOrderListVO.getPaymentAmount());
 			chargingOrderListVO.setUid(chargingOrderListVO.getId()+"");
@@ -1587,6 +1642,8 @@
 								chargingOrderListVO.setLicensePlate(data4.get(0).getLicensePlate());
 							}
 						}
+					}else{
+						chargingOrderListVO.setLicensePlate(chargingOrderListVO.getPlateNum());
 					}
 					chargingOrderListVO.setPhone(data3.getPhone());
 				}
@@ -1864,7 +1921,11 @@
 
 		if (chargingOrder.getAppUserCarId()!=null){
 			List<TAppUserCar> data3 = appUserCarClient.getCarByIds(Collections.singletonList(chargingOrder.getAppUserCarId())).getData();
-			if (data3!=null && !data3.isEmpty())chargingOrderListInfoVO.setLicensePlate(data3.get(0).getLicensePlate());
+			if (data3!=null && !data3.isEmpty()) {
+				chargingOrderListInfoVO.setLicensePlate(data3.get(0).getLicensePlate());
+			}
+		}else{
+			chargingOrderListInfoVO.setLicensePlate(chargingOrder.getPlateNum());
 		}
 		chargingOrderListInfoVO.setStartTime(chargingOrder.getStartTime());
 		chargingOrderListInfoVO.setEndTime(chargingOrder.getEndTime());
@@ -1913,7 +1974,7 @@
 			chargingOrder.setChargingCapacity(query.getCharging_degree());
 			chargingOrder.setElectricity(query.getCharging_degree());
 			chargingOrder.setTotalElectricity(new BigDecimal(100 - query.getSoc()));
-			BmsDemandAndChargerExportation data = bmsDemandAndChargerExportationClient.getBmsDemandAndChargerExportation(chargingOrder.getCode()).getData();
+			BmsDemandAndChargerExportation data = bmsDemandAndChargerExportationClient.getBmsDemandAndChargerExportation(chargingOrder1.getCode()).getData();
 			if(null != data){
 				chargingOrder.setNeedElec(data.getBms_current_requirements());
 			}
@@ -1955,6 +2016,9 @@
 	@GlobalTransactional(rollbackFor = Exception.class)
 	public R endChargeBillingCharge(TransactionRecordMessageVO vo) {
 		TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, vo.getTransaction_serial_number()));
+		if(null == chargingOrder){
+			return R.ok();
+		}
 		Integer status = chargingOrder.getStatus();
 		if(status == 5){
 			return R.ok();
@@ -2192,7 +2256,7 @@
 		UploadRealTimeMonitoringData uploadRealTimeMonitoringData = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrder.getCode()).getData();
 		if(null != uploadRealTimeMonitoringData && null == chargingOrder.getEndMode()){
 			Integer soc = uploadRealTimeMonitoringData.getSoc();
-			if(soc > 98){
+			if(soc >= 98){
 				order.setEndMode(2);
 			}else if(chargingOrder.getResidualAmount().compareTo(new BigDecimal(1)) <= 0){
 				order.setEndMode(3);
@@ -2275,6 +2339,14 @@
 		this.updateById(order);
 		chargingOrder = this.getById(order.getId());
 		
+		//推送三方平台
+		if(2 == chargingOrder.getOrderSource()){
+			tcecClient.notificationEquipChargeStatus(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId());
+			tcecClient.notificationStopChargeResult(chargingOrder.getStartChargeSeq(), chargingOrder.getChargingGunId().toString(),
+					chargingOrder.getOperatorId());
+			tcecClient.notificationChargeOrderInfo(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId());
+		}
+		
 		//开始将优惠券优惠的金额添加到明细中
 		BigDecimal couponDiscountAmount = order.getCouponDiscountAmount();
 		if(null != couponDiscountAmount && couponDiscountAmount.compareTo(BigDecimal.ZERO) > 0){
@@ -2296,91 +2368,103 @@
 		chargingGun.setStatus(2);
 		chargingGun.setChargingPower(BigDecimal.ZERO);
 		chargingGunClient.updateChargingGunById(chargingGun);
+		//推送状态给三方平台
+		if(2 == chargingOrder.getOrderSource()){
+			tcecClient.pushChargingGunStatus(chargingGun.getFullNumber(), chargingGun.getStatus());
+		}
 		
 		//添加积分
-		TIntegralRule integralRule = integralRuleClient.getSet().getData();
-		if(null != integralRule){
-			TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
-			Integer num1 = JSON.parseObject(integralRule.getChargeCredit()).getInteger("num1");
-			Integer integral = chargingOrder.getServiceCharge().intValue() * num1;
-			if(null != appUser.getVipId()){
-				TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
-				Integer doubleIntegration = vip.getDoubleIntegration();
-				//双倍积分
-				if(1 == doubleIntegration){
-					integral *= 2;
+		if(1 == chargingOrder.getOrderSource()){
+			TIntegralRule integralRule = integralRuleClient.getSet().getData();
+			if(null != integralRule){
+				TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
+				Integer num1 = JSON.parseObject(integralRule.getChargeCredit()).getInteger("num1");
+				Integer integral = chargingOrder.getServiceCharge().intValue() * num1;
+				if(null != appUser.getVipId()){
+					TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
+					Integer doubleIntegration = vip.getDoubleIntegration();
+					//双倍积分
+					if(1 == doubleIntegration){
+						integral *= 2;
+					}
+				}
+				
+				if(integral > 0){
+					TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange();
+					appUserIntegralChange.setAppUserId(appUser.getId());
+					appUserIntegralChange.setChangeType(2);
+					appUserIntegralChange.setHistoricalIntegral(appUser.getPoints());
+					appUser.setPoints(appUser.getPoints() + integral);
+					appUserIntegralChange.setCurrentIntegral(appUser.getPoints());
+					appUserIntegralChange.setCreateTime(LocalDateTime.now());
+					appUserIntegralChange.setOrderCode(chargingOrder.getCode());
+					appUserIntegralChange.setExtension(chargingOrder.getId().toString());
+					appUserClient.updateAppUser(appUser);
+					appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
 				}
 			}
 			
-			if(integral > 0){
-				TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange();
-				appUserIntegralChange.setAppUserId(appUser.getId());
-				appUserIntegralChange.setChangeType(2);
-				appUserIntegralChange.setHistoricalIntegral(appUser.getPoints());
-				appUser.setPoints(appUser.getPoints() + integral);
-				appUserIntegralChange.setCurrentIntegral(appUser.getPoints());
-				appUserIntegralChange.setCreateTime(LocalDateTime.now());
-				appUserIntegralChange.setOrderCode(chargingOrder.getCode());
-				appUserIntegralChange.setExtension(chargingOrder.getId().toString());
-				appUserClient.updateAppUser(appUser);
-				appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
-			}
-		}
-
-		//计算用户标签
-		editUserTag(chargingOrder);
-		//用户推荐奖励
-		referralReward(chargingOrder);
-		
-		//开始构建退款费用
-		refundAmount = refundAmount.setScale(2, RoundingMode.HALF_EVEN);
-		if(refundAmount.compareTo(BigDecimal.ZERO) > 0){
-			Integer rechargePaymentType = chargingOrder.getRechargePaymentType();
-			//构建退款明细
-			TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund();
-			chargingOrderRefund.setChargingOrderId(chargingOrder.getId());
-			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
-			chargingOrderRefund.setRefundCode("CDF" + sdf.format(new Date()) + (Double.valueOf(Math.random() * 1000).intValue()));
-			chargingOrderRefund.setRefundAmount(refundAmount);
-			chargingOrderRefund.setRefundStatus(1);
-			chargingOrderRefund.setPayType(rechargePaymentType);
-			chargingOrderRefund.setRefundStatus(1);
-			chargingOrderRefund.setCode(chargingOrder.getCode());
-			chargingOrderRefund.setRefundTitle("充电完成退款");
-			chargingOrderRefund.setRefundContent("充电完成退款");
-			chargingOrderRefund.setRefundReason("充电完成退款");
-			chargingOrderRefund.setRefundRemark("实际充电消费金额:" + chargingOrder.getPaymentAmount());
-			chargingOrderRefund.setRefundTotalAmount(refundAmount);
-			chargingOrderRefund.setPayAmount(rechargeAmount);
-			if(1 == rechargePaymentType){
-				WxPaymentRefundModel model = new WxPaymentRefundModel();
-				model.setOut_trade_no(chargingOrder.getCode());
-				model.setOut_refund_no(chargingOrderRefund.getRefundCode());
-				model.setReason("充电完成退款");
-				model.setNotify_url("/payment/wx/refund/notify");
-				WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount();
-				amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue());
-				amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue());
-				amount.setCurrency("CNY");
-				model.setAmount(amount);
-				R<String> orderR = wxPaymentClient.refundOrderR(model);
-				if(200 == orderR.getCode()){
-					chargingOrderRefundService.save(chargingOrderRefund);
-				}
-			}
-			if(2 == rechargePaymentType){
-				RefundReq dto = new RefundReq();
-				dto.setOutTradeNo(chargingOrder.getCode());
-				dto.setOutRequestNo(chargingOrderRefund.getRefundCode());
-				dto.setRefundAmount(refundAmount.toString());
-				dto.setRefundReason("充电完成退款");
-				RefundResp resp = aliPaymentClient.refund(dto).getData();
-				if(null != resp){
-					chargingOrderRefundService.save(chargingOrderRefund);
-					this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
-				}
-			}
+			//计算用户标签
+			editUserTag(chargingOrder);
+			//用户推荐奖励
+			referralReward(chargingOrder);
 			
+			//开始构建退款费用
+			refundAmount = refundAmount.setScale(2, RoundingMode.HALF_EVEN);
+			if(refundAmount.compareTo(BigDecimal.ZERO) > 0){
+				Integer rechargePaymentType = chargingOrder.getRechargePaymentType();
+				//构建退款明细
+				TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund();
+				chargingOrderRefund.setChargingOrderId(chargingOrder.getId());
+				SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+				chargingOrderRefund.setRefundCode("CDF" + sdf.format(new Date()) + (Double.valueOf(Math.random() * 1000).intValue()));
+				chargingOrderRefund.setRefundAmount(refundAmount);
+				chargingOrderRefund.setRefundStatus(1);
+				chargingOrderRefund.setPayType(rechargePaymentType);
+				chargingOrderRefund.setRefundStatus(1);
+				chargingOrderRefund.setCode(chargingOrder.getCode());
+				chargingOrderRefund.setRefundTitle("充电完成退款");
+				chargingOrderRefund.setRefundContent("充电完成退款");
+				chargingOrderRefund.setRefundReason("充电完成退款");
+				chargingOrderRefund.setRefundRemark("实际充电消费金额:" + chargingOrder.getPaymentAmount());
+				chargingOrderRefund.setRefundTotalAmount(refundAmount);
+				chargingOrderRefund.setPayAmount(rechargeAmount);
+				if(1 == rechargePaymentType){
+					WxPaymentRefundModel model = new WxPaymentRefundModel();
+					model.setOut_trade_no(chargingOrder.getCode());
+					model.setOut_refund_no(chargingOrderRefund.getRefundCode());
+					model.setReason("充电完成退款");
+					model.setNotify_url("/payment/wx/refund/notify");
+					WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount();
+					amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue());
+					amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue());
+					amount.setCurrency("CNY");
+					model.setAmount(amount);
+					R<Map<String, Object>> result = wxPaymentClient.refundOrderR(model);
+					if(200 == result.getCode()){
+						chargingOrderRefundService.save(chargingOrderRefund);
+						//手续费
+						Map<String, Object> amount1 = (Map<String, Object>) result.getData().get("amount");
+						Object refund_fee1 = amount1.get("refund_fee");
+						BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100));
+						chargingOrderRefund.setRefundFee(refund_fee);
+						chargingOrderRefundService.updateById(chargingOrderRefund);
+					}
+				}
+				if(2 == rechargePaymentType){
+					RefundReq dto = new RefundReq();
+					dto.setOutTradeNo(chargingOrder.getCode());
+					dto.setOutRequestNo(chargingOrderRefund.getRefundCode());
+					dto.setRefundAmount(refundAmount.toString());
+					dto.setRefundReason("充电完成退款");
+					RefundResp resp = aliPaymentClient.refund(dto).getData();
+					if(null != resp){
+						chargingOrderRefundService.save(chargingOrderRefund);
+						this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
+					}
+				}
+				
+			}
 		}
 		return R.ok();
 	}
@@ -2520,12 +2604,18 @@
 					amount.setTotal(tChargingOrder.getRechargeAmount().multiply(new BigDecimal(100)).intValue());
 					amount.setCurrency("CNY");
 					model.setAmount(amount);
-					R<String> orderR = wxPaymentClient.refundOrderR(model);
+					R<Map<String, Object>> orderR = wxPaymentClient.refundOrderR(model);
 					if(200 == orderR.getCode()){
 						tChargingOrder.setRefundStatus(2);
 						tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount()));
 						this.baseMapper.updateById(tChargingOrder);
 						chargingOrderRefundService.save(chargingOrderRefund);
+						//手续费
+						Map<String, Object> amount1 = (Map<String, Object>) orderR.getData().get("amount");
+						Object refund_fee1 = amount1.get("refund_fee");
+						BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100));
+						chargingOrderRefund.setRefundFee(refund_fee);
+						chargingOrderRefundService.updateById(chargingOrderRefund);
 					}
 				}
 
@@ -2582,12 +2672,18 @@
 					amount.setTotal(tChargingOrder.getPaymentAmount().multiply(new BigDecimal(100)).intValue());
 					amount.setCurrency("CNY");
 					model.setAmount(amount);
-					R<String> orderR = wxPaymentClient.refundOrderR(model);
+					R<Map<String, Object>> orderR = wxPaymentClient.refundOrderR(model);
 					if(200 == orderR.getCode()){
 						tChargingOrder.setRefundStatus(2);
 						tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount()));
 						shoppingOrderService.updateById(tChargingOrder);
 						shoppingOrderRefundService.save(chargingOrderRefund);
+						//手续费
+						Map<String, Object> amount1 = (Map<String, Object>) orderR.getData().get("amount");
+						Object refund_fee1 = amount1.get("refund_fee");
+						BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100));
+						chargingOrderRefund.setRefundFee(refund_fee);
+						shoppingOrderRefundService.updateById(chargingOrderRefund);
 					}
 				}
 
@@ -2641,12 +2737,18 @@
 				amount.setTotal(tChargingOrder.getPaymentAmount().multiply(new BigDecimal(100)).intValue());
 				amount.setCurrency("CNY");
 				model.setAmount(amount);
-				R<String> orderR = wxPaymentClient.refundOrderR(model);
+				R<Map<String, Object>> orderR = wxPaymentClient.refundOrderR(model);
 				if(200 == orderR.getCode()){
 					tChargingOrder.setRefundStatus(2);
 					tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount()));
 					vipOrderService.updateById(tChargingOrder);
 					vipOrderRefundService.save(chargingOrderRefund);
+					//手续费
+					Map<String, Object> amount1 = (Map<String, Object>) orderR.getData().get("amount");
+					Object refund_fee1 = amount1.get("refund_fee");
+					BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100));
+					chargingOrderRefund.setRefundFee(refund_fee);
+					vipOrderRefundService.updateById(chargingOrderRefund);
 				}
 			}
 
@@ -2676,11 +2778,7 @@
 	 */
 	@Override
 	public TChargingOrder getChargingOrderByLicensePlate(GetChargingOrderByLicensePlate query) {
-		TAppUserCar appUserCar = appUserCarClient.getAppUserCarByLicensePlate(query.getLicensePlate()).getData();
-		if(null == appUserCar){
-			return null;
-		}
-		TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserCarId, appUserCar.getId())
+		TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getPlateNum, query.getLicensePlate())
 				.eq(TChargingOrder::getDelFlag, 0).between(TChargingOrder::getStartTime, query.getStartTime(), LocalDateTime.now())
 				.eq(TChargingOrder::getRechargePaymentStatus, 2).in(TChargingOrder::getStatus, Arrays.asList(4, 5)));
 		return one;
@@ -2774,7 +2872,7 @@
 			}
 			if (tChargingOrder.getPaymentAmount()!=null){
 				paymentAmount = paymentAmount.add(tChargingOrder.getPaymentAmount());
-				orderCommission = orderCommission.add(tChargingOrder.getPaymentAmount().multiply(new BigDecimal("0.006"))
+				orderCommission = orderCommission.add(tChargingOrder.getRechargeAmount().multiply(new BigDecimal("0.006"))
 						.setScale(2,BigDecimal.ROUND_DOWN));
 			}
 
@@ -2919,6 +3017,8 @@
 		return pageInfo;
 	}
 
+	@Autowired
+	private TChargingOrderService chargingOrderService;
 	@Override
 	public SettlementTotalVO settlementTotal(String time) {
 		Long userId = tokenService.getLoginUser().getUserid();
@@ -2933,6 +3033,14 @@
 		if (siteIds.isEmpty()){
 			siteIds.add(-1);
 		}
+		List<Site> siteList = siteClient.getSiteAll().getData();
+		List<TChargingGun> gunList = chargingGunClient.getAllGun().getData();
+		List<TChargingPile> pileList = chargingGunClient.getAllPile().getData();
+		List<TAppUser> userList = appUserClient.getAllUser().getData();
+		List<TAppUserCar> carList = appUserCarClient.getAllCar().getData();
+		List<TChargingOrder> totalOrder = chargingOrderService.list(new LambdaQueryWrapper<>(TChargingOrder.class)
+				.eq(TChargingOrder::getRechargePaymentStatus, 2));
+		List<TChargingOrderRefund> totalRefund = chargingOrderRefundService.lambdaQuery().eq(TChargingOrderRefund::getRefundStatus, 2).list();
 		SettlementTotalVO res = new SettlementTotalVO();
 		List<TSettlementConfirm> list1 = tSettlementConfirmMapper.settlementTotal(time,siteIds);
 		LocalDateTime parse = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
@@ -2980,9 +3088,9 @@
 		for (TSettlementConfirm tSettlementConfirm : list1) {
 			tSettlementConfirm.setXuhao(i);
 			tSettlementConfirm.setMetering(tSettlementConfirm.getSupplyElectronic());
-			List<Site> data1 = siteClient.getSiteByIds(Arrays.asList(tSettlementConfirm.getSiteId())).getData();
-			if (!data1.isEmpty()){
-				tSettlementConfirm.setSiteName(data1.get(0).getName());
+			Site site = siteList.stream().filter(e -> e.getId().equals(tSettlementConfirm.getSiteId())).findFirst().orElse(null);
+			if (site!=null){
+				tSettlementConfirm.setSiteName(site.getName());
 			}
 			if (tSettlementConfirm.getMeteringElectronic()!=null){
 				meteringElectronic = meteringElectronic.add(tSettlementConfirm.getMeteringElectronic());
@@ -3027,26 +3135,17 @@
 					eq.between("end_time", tSettlementConfirm.getStartTime(), tSettlementConfirm.getEndTime());
 					break;
 			}
-			List<TChargingOrder> tChargingOrders = this.baseMapper.selectList(eq);
-			Map<String,TChargingOrder> map = new HashMap<>();
-			StringBuilder stringBuilder = new StringBuilder();
-			for (TChargingOrder tChargingOrder : tChargingOrders) {
-				stringBuilder.append(tChargingOrder.getCode()).append(",");
-
-			}
+			List<TChargingOrder> tChargingOrders = totalOrder.stream().filter(e-> e.getPayTime()
+					.isBefore(tSettlementConfirm.getEndTime())
+					&& e.getPayTime().isAfter(tSettlementConfirm.getStartTime())&&e.getSiteId().equals(tSettlementConfirm.getSiteId())).collect(Collectors.toList());
 			// 充电总时长
-
-			Long temp = 1L;
-			if (StringUtils.hasLength(stringBuilder.toString())){
-				String substring = stringBuilder.substring(0, stringBuilder.length() - 1);
-				for (String s : substring.split(",")) {
-					UploadRealTimeMonitoringData data6 = uploadRealTimeMonitoringDataClient.chargingOrderInfo(s).getData();
-					if (data6!=null){
-						temp+=(data6.getCumulative_charging_time()*60);
-
-					}
-
-				}
+			Long temp = 0L;
+			for (TChargingOrder tChargingOrder : tChargingOrders) {
+				LocalDateTime startTime = tChargingOrder.getStartTime();
+				LocalDateTime endTime = tChargingOrder.getEndTime();
+				// 计算时间差 单位秒
+				long between = ChronoUnit.SECONDS.between(startTime, endTime);
+				temp+=between;
 			}
 			List<TChargingPile> data = siteClient.getPileListBySiteId(tSettlementConfirm.getSiteId()).getData();
 			// 计算充电桩的功率平均值
@@ -3058,7 +3157,7 @@
 
 			tSettlementConfirm.setIncome(tSettlementConfirm.getElectrovalence().add(tSettlementConfirm.getServiceCharge()));
 			//利用率=充电量/(桩数量*功率*时间)
-			List<TChargingPile> data2 = chargingPileClient.getChargingPileBySiteId(tSettlementConfirm.getSiteId()).getData();
+			List<TChargingPile> data2 = pileList.stream().filter(e -> e.getSiteId().equals(tSettlementConfirm.getSiteId())).collect(Collectors.toList());
 			BigDecimal bigDecimal2 = new BigDecimal("0");
 
 			if (data2!=null && (!data2.isEmpty())){
@@ -3174,11 +3273,16 @@
 		if (siteIds.isEmpty()){
 			siteIds.add(-1);
 		}
+		List<Site> siteList = siteClient.getSiteAll().getData();
+		List<TChargingGun> gunList = chargingGunClient.getAllGun().getData();
+		List<TChargingPile> pileList = chargingGunClient.getAllPile().getData();
+		List<TAppUser> userList = appUserClient.getAllUser().getData();
+		List<TAppUserCar> carList = appUserCarClient.getAllCar().getData();
+		List<TChargingOrder> totalOrder = chargingOrderService.list(new LambdaQueryWrapper<>(TChargingOrder.class)
+				.eq(TChargingOrder::getRechargePaymentStatus, 2));
 		SettlementTotalVO res = new SettlementTotalVO();
 		List<TSettlementConfirm> list1 = tSettlementConfirmMapper.settlementTotal(time,siteIds);
 		LocalDateTime parse = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-		// 减少一个月
-		LocalDateTime minus = parse.minusMonths(1);
 		List<TSettlementConfirm> list2 = tSettlementConfirmMapper.settlementTotal(time,siteIds);
 		// 合计
 		List<TSettlementConfirm> total = new ArrayList<>();
@@ -3221,7 +3325,7 @@
 		for (TSettlementConfirm tSettlementConfirm : list1) {
 			tSettlementConfirm.setXuhao(i);
 			tSettlementConfirm.setMetering(tSettlementConfirm.getSupplyElectronic());
-			List<Site> data1 = siteClient.getSiteByIds(Arrays.asList(tSettlementConfirm.getSiteId())).getData();
+			List<Site> data1 = siteList.stream().filter(e -> e.getId().equals(tSettlementConfirm.getSiteId())).collect(Collectors.toList());
 			if (!data1.isEmpty()){
 				tSettlementConfirm.setSiteName(data1.get(0).getName());
 			}
@@ -3268,26 +3372,18 @@
 					eq.between("end_time", tSettlementConfirm.getStartTime(), tSettlementConfirm.getEndTime());
 					break;
 			}
-			List<TChargingOrder> tChargingOrders = this.baseMapper.selectList(eq);
-			Map<String,TChargingOrder> map = new HashMap<>();
-			StringBuilder stringBuilder = new StringBuilder();
-			for (TChargingOrder tChargingOrder : tChargingOrders) {
-				stringBuilder.append(tChargingOrder.getCode()).append(",");
 
-			}
+			List<TChargingOrder> tChargingOrders = totalOrder.stream().filter(e-> e.getPayTime()
+					.isBefore(tSettlementConfirm.getEndTime())
+					&& e.getPayTime().isAfter(tSettlementConfirm.getStartTime())&&e.getSiteId().equals(tSettlementConfirm.getSiteId())).collect(Collectors.toList());
 			// 充电总时长
-
-			Long temp = 1L;
-			if (StringUtils.hasLength(stringBuilder.toString())){
-				String substring = stringBuilder.substring(0, stringBuilder.length() - 1);
-				for (String s : substring.split(",")) {
-					UploadRealTimeMonitoringData data6 = uploadRealTimeMonitoringDataClient.chargingOrderInfo(s).getData();
-					if (data6!=null){
-						temp+=(data6.getCumulative_charging_time()*60);
-
-					}
-
-				}
+			Long temp = 0L;
+			for (TChargingOrder tChargingOrder : tChargingOrders) {
+				LocalDateTime startTime = tChargingOrder.getStartTime();
+				LocalDateTime endTime = tChargingOrder.getEndTime();
+				// 计算时间差 单位秒
+				long between = ChronoUnit.SECONDS.between(startTime, endTime);
+				temp+=between;
 			}
 			List<TChargingPile> data = siteClient.getPileListBySiteId(tSettlementConfirm.getSiteId()).getData();
 			// 计算充电桩的功率平均值
@@ -3541,4 +3637,179 @@
 	public Long countCar(List<String> brands) {
 		return this.baseMapper.countCar(brands);
 	}
+	
+	
+	/**
+	 * 添加三方平台充电订单数据
+	 * @param query
+	 */
+	@Override
+	public R addTripartitePlatformOrder(AddTripartitePlatformOrder query) {
+		//检查当前枪是否是正在使用中
+		TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getChargingGunId, query.getChargingGunId())
+				.in(TChargingOrder::getStatus, Arrays.asList(1, 2, 3)).eq(TChargingOrder::getDelFlag, 0));
+		if(null != one){
+			return R.fail("充电枪正在充电中,启动失败");
+		}
+		
+		//构建订单数据
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+		TChargingOrder chargingOrder = new TChargingOrder();
+		String code = "CD" + Double.valueOf(Math.random() * 1000).intValue() + sdf.format(new Date());
+		chargingOrder.setCode(code);
+		chargingOrder.setOrderType(1);
+		chargingOrder.setOrderClassification(1);
+		TChargingGun tChargingGun = chargingGunClient.getChargingGunById(query.getChargingGunId()).getData();
+		TChargingPile chargingPile = chargingPileClient.getChargingPileById(tChargingGun.getChargingPileId()).getData();
+		chargingOrder.setSiteId(tChargingGun.getSiteId());
+		chargingOrder.setChargingPileId(tChargingGun.getChargingPileId());
+		chargingOrder.setChargingGunId(query.getChargingGunId());
+		chargingOrder.setRechargePaymentType(query.getRechargePaymentType());
+		chargingOrder.setRechargePaymentStatus(2);
+		chargingOrder.setRechargeAmount(query.getPaymentAmount());
+		chargingOrder.setVipDiscountAmount(BigDecimal.ZERO);
+		chargingOrder.setOrderSource(2);
+		Operator operator = operatorClient.getOperator(query.getOperatorId()).getData();
+		chargingOrder.setOperatorId(operator.getId());
+		chargingOrder.setAppUserId(operator.getId().longValue());
+		chargingOrder.setTripartitePlatformName(operator.getName());
+		chargingOrder.setStartChargeSeq(query.getStartChargeSeq());
+		//车辆信息
+		if(StringUtils.hasLength(query.getPlateNum())){
+			TAppUserCar appUserCar = appUserCarClient.getAppUserCarByLicensePlate(query.getPlateNum()).getData();
+			if(null != appUserCar){
+				chargingOrder.setAppUserCarId(appUserCar.getId());
+			}
+			chargingOrder.setPlateNum(query.getPlateNum());
+		}
+		
+		
+		chargingOrder.setTitle("【充电桩充电】" + chargingPile.getNumber() + "号桩/" + tChargingGun.getCode() + "号枪");
+		chargingOrder.setStatus(2);
+		chargingOrder.setPayTime(LocalDateTime.now());
+		chargingOrder.setChargeAmount(chargingOrder.getRechargeAmount());
+		chargingOrder.setVipDiscountAmount(BigDecimal.ZERO);
+		this.save(chargingOrder);
+		
+		Integer accountingStrategyId = tChargingGun.getAccountingStrategyId();
+		if(null == accountingStrategyId){
+			Site site = siteClient.getSiteByIds(Arrays.asList(tChargingGun.getSiteId())).getData().get(0);
+			//查询站点上面的计费策略
+			accountingStrategyId = site.getAccountingStrategyId();
+		}
+		TAccountingStrategy accountingStrategy = accountingStrategyClient.getAccountingStrategyById(accountingStrategyId).getData();
+		
+		//添加订单的计费策略
+		List<TAccountingStrategyDetail> strategyDetailList = accountingStrategyDetailClient.getListByAccountingStrategyId(accountingStrategyId).getData();
+		AccountingStrategyOrder accountingStrategyOrder = new AccountingStrategyOrder();
+		BeanUtils.copyProperties(accountingStrategy, accountingStrategyOrder);
+		accountingStrategyOrder.setChargingOrderId(chargingOrder.getId());
+		accountingStrategyOrderService.save(accountingStrategyOrder);
+		List<AccountingStrategyDetailOrder> list1 = new ArrayList<>();
+		for (TAccountingStrategyDetail tAccountingStrategyDetail : strategyDetailList) {
+			AccountingStrategyDetailOrder accountingStrategyDetailOrder = new AccountingStrategyDetailOrder();
+			BeanUtils.copyProperties(tAccountingStrategyDetail, accountingStrategyDetailOrder);
+			accountingStrategyDetailOrder.setChargingOrderId(chargingOrder.getId());
+			list1.add(accountingStrategyDetailOrder);
+		}
+		accountingStrategyDetailOrderService.saveBatch(list1);
+		
+		
+		//添加安全检测数据到缓存中,每步安全检测完成后需要更新缓存数据
+		PreChargeCheck preChargeCheck = new PreChargeCheck();
+		preChargeCheck.setElectronicLockLock(false);
+		preChargeCheck.setInsulationTesting(false);
+		preChargeCheck.setSecureConnectionDetection(false);
+		preChargeCheck.setStartupSuccess(1);
+		String key = "AQJC_" + chargingOrder.getChargingGunId();
+		redisService.setCacheObject(key, preChargeCheck, 24L, TimeUnit.HOURS);
+		
+		BigDecimal rechargeAmount = chargingOrder.getRechargeAmount();
+		//调用远程启动充电消息
+		PlatformStartCharging platformStartCharging = new PlatformStartCharging();
+		platformStartCharging.setTransaction_serial_number(chargingOrder.getCode());
+		platformStartCharging.setCharging_pile_code(chargingPile.getCode());
+		platformStartCharging.setCharging_gun_code(tChargingGun.getCode());
+		//使用订单id作为逻辑卡号
+		platformStartCharging.setCard_number(chargingOrder.getId().toString());
+		platformStartCharging.setAccount_balance(rechargeAmount);
+		log.info(chargingOrder.getCode() + ":-------------------远程调起开始充电请求-------------------" + platformStartCharging.toString());
+		sendMessageClient.platformStartCharging(platformStartCharging);
+		//异步线程检测远程启动的应答结果。如果失败,则需要全额退款
+		Long id = chargingOrder.getId();
+		//执行5分钟的定时任务检测
+		ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
+		scheduler.scheduleAtFixedRate(()->{
+			if(timingDetection(id)){
+				scheduler.shutdown();
+			}
+		}, 5, 1, TimeUnit.SECONDS);
+		
+		//推送三方平台订单状态
+		tcecClient.notificationEquipChargeStatus(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId());
+		return R.ok();
+	}
+	
+	
+	/**
+	 * 三方平台停止充电操作
+	 * @param startChargeSeq
+	 * @return
+	 */
+	@Override
+	public R tripartitePlatformStopCharge(String startChargeSeq) {
+		TChargingOrder order = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getStartChargeSeq, startChargeSeq));
+		Integer status = order.getStatus();
+		if(status != 3){
+			return R.fail("还未开始充电");
+		}
+		if(status == 4 || status == 5){
+			return R.fail("不能重复操作");
+		}
+		TChargingOrder chargingOrder = new TChargingOrder();
+		chargingOrder.setId(order.getId());
+		chargingOrder.setAppUserId(order.getOperatorId().longValue());
+		chargingOrder.setEndTime(LocalDateTime.now());
+		chargingOrder.setStatus(4);
+		chargingOrder.setEndMode(1);
+		this.updateById(chargingOrder);
+		
+		tcecClient.notificationEquipChargeStatus(order.getStartChargeSeq(), order.getOperatorId());
+		
+		String code1 = order.getCode();
+		TChargingGun chargingGun = chargingGunClient.getChargingGunById(order.getChargingGunId()).getData();
+		//异步线程处理停机
+		ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1);
+		cachedThreadPool.execute(()->{
+			//调用硬件停止充电,停止成功后开始计算费用退款
+			TChargingPile chargingPile = chargingPileClient.getChargingPileById(order.getChargingPileId()).getData();
+			PlatformStopCharging platformStopCharging = new PlatformStopCharging();
+			platformStopCharging.setCharging_pile_code(chargingPile.getCode());
+			platformStopCharging.setCharging_gun_code(chargingGun.getCode());
+			sendMessageClient.platformStopCharging(platformStopCharging);
+			log.info(code1 + ":-------------------远程停止充电请求-------------------");
+			log.info(platformStopCharging.toString());
+		});
+		return R.ok();
+	}
+	
+	
+	/**
+	 * 获取充电后没有扣除费用的数据
+	 * @return
+	 */
+	@Override
+	public R getNotPaymentChargingOrder() {
+		List<TChargingOrder> list = this.list(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getPaymentAmount, 0)
+				.ne(TChargingOrder::getElectricity, 0).in(TChargingOrder::getStatus, Arrays.asList(4, 5)));
+		List<Map<String, Object>> mapList = new ArrayList<>();
+		for (TChargingOrder order : list) {
+			TransactionRecord transactionRecord = transactionRecordClient.findTransactionRecord(order.getCode()).getData();
+			Map<String, Object> map = new HashMap<>();
+			map.put("order", order);
+			map.put("transactionRecord", transactionRecord);
+			mapList.add(map);
+		}
+		return R.ok(mapList);
+	}
 }

--
Gitblit v1.7.1