From caa1d7baa3aa9cbf45f7ba41fbcdccd1c4c17727 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期三, 16 十月 2024 10:05:22 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java                    |   10 +
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java              |  154 +++++++++++++++++++-----------
 ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/dto/InfoCouponDto.java                           |    1 
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/wx/tools/WxAppletTools.java                          |   11 +
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java              |   48 +++++----
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java                   |    1 
 ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/model/TChargingOrder.java                            |   16 +++
 ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml                               |    2 
 ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java                      |    5 
 ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/TAppUserVipDetail.java                     |    2 
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java                 |    2 
 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java |    2 
 12 files changed, 158 insertions(+), 96 deletions(-)

diff --git a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/dto/InfoCouponDto.java b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/dto/InfoCouponDto.java
index 083e79f..bfc5838 100644
--- a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/dto/InfoCouponDto.java
+++ b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/dto/InfoCouponDto.java
@@ -20,6 +20,7 @@
     @TableField("name")
     private String name;
     private Integer type;
+    private Integer couponId;
     @ApiModelProperty(value = "优惠方式(1=满减,2=抵扣)")
     @TableField("preferential_mode")
     private Integer preferentialMode;
diff --git a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/TAppUserVipDetail.java b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/TAppUserVipDetail.java
index f46fc43..1ab909b 100644
--- a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/TAppUserVipDetail.java
+++ b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/TAppUserVipDetail.java
@@ -58,7 +58,7 @@
     @TableField("vip_id")
     private Integer vipId;
 
-    @ApiModelProperty(value = "1月卡2季卡3年卡")
+    @ApiModelProperty(value = "1月卡2季卡3年卡4集团")
     @TableField("vip_type")
     private Integer vipType;
 
diff --git a/ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/model/TChargingOrder.java b/ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/model/TChargingOrder.java
index 382ce1d..0202131 100644
--- a/ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/model/TChargingOrder.java
+++ b/ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/model/TChargingOrder.java
@@ -158,6 +158,10 @@
     @ApiModelProperty(value = "退款流水号")
     @TableField("refund_code")
     private String refundCode;
+
+    @ApiModelProperty(value = "标题")
+    @TableField("title")
+    private String title;
     @ApiModelProperty(value = "退款原因")
     @TableField(exist = false)
     private String refundReason;
@@ -173,6 +177,18 @@
     @ApiModelProperty(value = "累计电费")
     @TableField("electrovalence")
     private BigDecimal electrovalence;
+    @ApiModelProperty(value = "电流")
+    @TableField("current")
+    private BigDecimal current;
+    @ApiModelProperty(value = "电压")
+    @TableField("voltage")
+    private BigDecimal voltage;
+    @ApiModelProperty(value = "电量")
+    @TableField("electricity")
+    private BigDecimal electricity;
+    @ApiModelProperty(value = "功率")
+    @TableField("power")
+    private BigDecimal power;
 
     @ApiModelProperty(value = "退款状态(1=退款中,2=退款成功)")
     @TableField("refund_status")
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
index 839c11a..0225dae 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
@@ -639,6 +639,7 @@
                 InfoCouponDto infoCouponDto = new InfoCouponDto();
                 BeanUtils.copyProperties(coupon, infoCouponDto);
                 infoCouponDto.setId(tAppCoupon.getId().toString());
+                infoCouponDto.setCouponId(coupon.getId());
                 infoCouponDto.setEndTime(tAppCoupon.getEndTime());
                 couponDtos1.add(infoCouponDto);
 
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
index 43741a2..4a70696 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
@@ -38,6 +38,7 @@
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -64,6 +65,9 @@
     private WeixinProperties wxConfig;
     @Autowired
     private RestTemplate wxRestTemplate;
+    @Resource
+    private RedisService redisService;
+
     /**
      * 上传文件存储在本地的根路径
      */
@@ -77,7 +81,7 @@
     @PostMapping("/openIdByJsCode")
     public AjaxResult<Map<String, Object>> openIdByJsCode(@RequestBody AppletUserEncrypteData data) {
         log.info("<<<<<<<<换取openid开始<<<<<<<<:{}", data.getCode());
-        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig);
+        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisService);
         Code2SessionRespBody body = appletTools.getOpenIdByJscode2session(new Code2SessionResqBody().build(data.getCode()));
         String openid = body.getOpenid();
         String sessionKey = body.getSessionKey();
@@ -114,7 +118,7 @@
     public AjaxResult getQRCode() {
         InputStream inputStream = null;
         OutputStream outputStream = null;
-        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig);
+        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisService);
         String accessToken = appletTools.getAccessToken("");
         try {
             String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
@@ -171,7 +175,7 @@
      */
     @PostMapping("/getWXToken")
     public R<String> getWXToken(){
-        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig);
+        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisService);
         String accessToken = appletTools.getAccessToken("");
         return R.ok(accessToken);
     }
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/wx/tools/WxAppletTools.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/wx/tools/WxAppletTools.java
index 6f19eea..73f4a40 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/wx/tools/WxAppletTools.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/wx/tools/WxAppletTools.java
@@ -4,12 +4,14 @@
 import com.ruoyi.account.wx.body.resp.Code2SessionRespBody;
 import com.ruoyi.account.wx.body.resq.Code2SessionResqBody;
 import com.ruoyi.account.wx.model.WeixinProperties;
+import com.ruoyi.common.redis.service.RedisService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 import org.springframework.util.StringUtils;
 import org.springframework.web.client.RestTemplate;
 
 import java.text.MessageFormat;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author xiaochen
@@ -57,11 +59,12 @@
     public static String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";
     private WeixinProperties wxConfig;
     private RestTemplate wxRestTemplate;
-    private WxCacheTemplate<String> wxCacheTemplate;
+    private RedisService redisService;
 
-    public WxAppletTools(RestTemplate wxRestTemplate, WeixinProperties wxConfig) {
+    public WxAppletTools(RestTemplate wxRestTemplate, WeixinProperties wxConfig, RedisService redisService) {
         this.wxRestTemplate = wxRestTemplate;
         this.wxConfig = wxConfig;
+        this.redisService = redisService;
     }
 
     /**
@@ -101,7 +104,7 @@
      * @return
      */
     public String getAccessToken(String version) {
-        String accessToken = wxCacheTemplate.getKey(ACCESSTOKEN_CACHE_KEY + version);
+        String accessToken = redisService.getCacheObject(ACCESSTOKEN_CACHE_KEY + version);
         if (StringUtils.hasLength(accessToken)) {
             return accessToken;
         }
@@ -113,7 +116,7 @@
             // 抛出错误
             throw new WxException(accessTokenRespBody.getErrorCode() + ":" + accessTokenRespBody.getErrorMsg());
         }
-        wxCacheTemplate.setKey(ACCESSTOKEN_CACHE_KEY + version, accessTokenRespBody.getAccessToken());
+        redisService.setCacheObject(ACCESSTOKEN_CACHE_KEY + version, accessTokenRespBody.getAccessToken(), 7200L, TimeUnit.SECONDS);
         return accessTokenRespBody.getAccessToken();
     }
 
diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
index e63b804..3477646 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
@@ -262,7 +262,7 @@
 			//调用华为Iot删除设备
 			if(StringUtils.isNotEmpty(chargingPile.getIotdDeviceId())){
 				DeleteDeviceResp deviceResp = iotInterfaceClient.deleteDevice(chargingPile.getIotdDeviceId()).getData();
-				if(null != deviceResp && deviceResp.getHttpStatusCode() == 201){
+				if(null != deviceResp && deviceResp.getHttpStatusCode() == 0){
 					this.removeById(chargingPile);
 				}
 			}
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
index 3636697..15d8184 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
@@ -585,7 +585,7 @@
      */
     @PostMapping("/endChargeBillingCharge")
     public void endChargeBillingCharge(@RequestBody TransactionRecordMessageVO vo){
-        log.error("-------------------停止充电返回账单后计算费用-------------------:" + vo);
+        log.error("-------------------停止充电返回账单后计算费用及修改业务状态-------------------:" + vo);
         chargingOrderService.endChargeBillingCharge(vo);
     }
     
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 be2102b..604b1e2 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
@@ -434,6 +434,7 @@
 		chargingOrder.setAppUserId(userId);
 		chargingOrder.setAppUserCarId(addChargingOrder.getAppUserCarId());
 		TChargingGun tChargingGun = chargingGunClient.getChargingGunById(addChargingOrder.getId()).getData();
+		TChargingPile chargingPile = chargingPileClient.getChargingPileById(tChargingGun.getChargingPileId()).getData();
 		chargingOrder.setSiteId(tChargingGun.getSiteId());
 		chargingOrder.setChargingPileId(tChargingGun.getChargingPileId());
 		chargingOrder.setChargingGunId(addChargingOrder.getId());
@@ -443,6 +444,8 @@
 		chargingOrder.setAppCouponId(addChargingOrder.getAppUserCouponId());
 		chargingOrder.setVipDiscount(new BigDecimal(10));
 		chargingOrder.setVipDiscountAmount(BigDecimal.ZERO);
+		chargingOrder.setOrderSource(0);
+		chargingOrder.setTitle("【充电桩充电】" + chargingPile.getNumber() + "号桩/" + tChargingGun.getCode() + "号枪");
 		
 		Site site = siteClient.getSiteByIds(Arrays.asList(tChargingGun.getSiteId())).getData().get(0);
 		Integer accountingStrategyId = tChargingGun.getAccountingStrategyId();
@@ -965,7 +968,6 @@
 			return AjaxResult.error("不能重复操作");
 		}
 		chargingOrder.setEndTime(LocalDateTime.now());
-		chargingOrder.setStatus(4);
 		chargingOrder.setEndMode(1);
 		this.updateById(chargingOrder);
 		
@@ -987,6 +989,7 @@
 			for (int i = 0; i < 60; i++) {
 				TChargingOrder chargingOrder1 = this.getById(id);
 				if(chargingOrder1.getStatus() != 3){
+					stop_status = true;
 					break;
 				}
 				GetPlatformStopChargingReply query = new GetPlatformStopChargingReply();
@@ -1028,24 +1031,15 @@
 					} catch (InterruptedException e) {
 						throw new RuntimeException(e);
 					}
-					continue;
 				}else{
 					log.error(code1 + ":-------------------远程停止充电请求成功-------------------");
 					stop_status = true;
+					break;
 				}
-				break;
 			}
 			if(stop_status){
-				chargingOrder.setStatus(5);
+				chargingOrder.setEndMode(1);
 				this.updateById(chargingOrder);
-				
-				//计算用户标签
-				editUserTag(chargingOrder);
-				//用户推荐奖励
-				referralReward(chargingOrder);
-				// 将枪状态重置为空闲
-				chargingGun.setStatus(2);
-				chargingGunClient.updateChargingGunById(chargingGun);
 			}else{
 				log.error(code1 + ":-------------------远程停止充电应答最终失败-------------------");
 			}
@@ -1211,17 +1205,11 @@
 			}
 			log.error(code1 + ":停机失败:订单号:{},失败原因:{}", order.getCode(), failure_cause);
 		}else{
-			order.setEndTime(LocalDateTime.now());
-			order.setStatus(5);
-			order.setEndMode(1);
-			this.updateById(order);
-			//计算用户标签
-			editUserTag(order);
-			//用户推荐奖励
-			referralReward(order);
-			// 将枪状态重置为空闲
-			chargingGun.setStatus(2);
-			chargingGunClient.updateChargingGunById(chargingGun);
+			TChargingOrder chargingOrder = new TChargingOrder();
+			chargingOrder.setId(order.getId());
+			chargingOrder.setAppUserId(order.getAppUserId());
+			chargingOrder.setEndMode(1);
+			this.updateById(chargingOrder);
 		}
 	}
 	
@@ -1744,13 +1732,21 @@
 				if(chargingOrderAccountingStrategy.getAccountingStrategyDetailId().equals(strategyDetail.getId())){
 					//已充电总度数
 					BigDecimal charging_degree = query.getCharging_degree();
-					BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(charging_degree);
-					BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(charging_degree);
+					BigDecimal chargingCapacity = chargingOrderAccountingStrategy.getChargingCapacity();
+					//计算本阶段充电度数
+					BigDecimal subtract = charging_degree.subtract(chargingCapacity);
+					//计算本阶段费用
+					BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(subtract);
+					BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(subtract);
 					BigDecimal serviceCharge = originalServicePrice;
 					//计算优惠金额
 					if(null != chargingOrder.getVipDiscount()){
 						serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount().divide(new BigDecimal(10)));
 					}
+					//将本阶段的费用增加到总费用中
+					electrovalenc = electrovalenc.add(chargingOrderAccountingStrategy.getPeriodElectricPrice());
+					originalServicePrice = originalServicePrice.add(chargingOrderAccountingStrategy.getPeriodOriginalServicePrice());
+					serviceCharge = serviceCharge.add(chargingOrderAccountingStrategy.getPeriodServicePrice());
 					chargingOrderAccountingStrategy.setChargingCapacity(charging_degree);
 					chargingOrderAccountingStrategy.setPeriodElectricPrice(electrovalenc);
 					chargingOrderAccountingStrategy.setPeriodServicePrice(serviceCharge);
@@ -1794,8 +1790,16 @@
 			}
 			BigDecimal residualAmount = chargingOrder.getRechargeAmount().subtract(t).setScale(4, RoundingMode.HALF_EVEN);
 			chargingOrder.setResidualAmount(residualAmount);
-			BigDecimal divide = query.getOutput_current().multiply(query.getOutput_voltage()).divide(new BigDecimal(1000));
-			chargingOrder.setChargingPower(divide);
+			if(query.getOutput_current().compareTo(BigDecimal.ZERO) != 0){
+				BigDecimal divide = query.getOutput_current().multiply(query.getOutput_voltage()).divide(new BigDecimal(1000));
+				chargingOrder.setChargingPower(divide);
+				chargingOrder.setCurrent(query.getOutput_current());
+				chargingOrder.setVoltage(query.getOutput_voltage());
+				chargingOrder.setPower(query.getOutput_current().multiply(query.getOutput_voltage()));
+				chargingOrder.setNeedElec(query.getOutput_current());
+			}
+			chargingOrder.setElectricity(query.getCharging_degree());
+			chargingOrder.setTotalElectricity(new BigDecimal(100 - query.getSoc()));
 			this.updateById(chargingOrder);
 		}
 	}
@@ -1808,24 +1812,12 @@
 	@Override
 	@GlobalTransactional(rollbackFor = Exception.class)
 	public void endCharge(String orderCode, Integer endMode) {
-		TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, orderCode));
-		Integer status = chargingOrder.getStatus();
-		if(status == 4 || status == 5){
-			return;
-		}
-		chargingOrder.setStatus(5);
+		TChargingOrder order = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, orderCode));
+		TChargingOrder chargingOrder = new TChargingOrder();
+		chargingOrder.setId(order.getId());
+		chargingOrder.setAppUserId(order.getAppUserId());
 		chargingOrder.setEndMode(endMode);
-		chargingOrder.setEndTime(LocalDateTime.now());
 		this.updateById(chargingOrder);
-		// 将枪状态重置为空闲
-		TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData();
-		chargingGun.setStatus(2);
-		chargingGunClient.updateChargingGunById(chargingGun);
-		
-		//计算用户标签
-		editUserTag(chargingOrder);
-		//用户推荐奖励
-		referralReward(chargingOrder);
 	}
 
 	/**
@@ -1845,10 +1837,39 @@
 	@Override
 	@GlobalTransactional(rollbackFor = Exception.class)
 	public void endChargeBillingCharge(TransactionRecordMessageVO vo) {
+		TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, vo.getTransaction_serial_number()));
+		Integer status = chargingOrder.getStatus();
+		if(status == 4 || status == 5){
+			return;
+		}
+		
+		//先判断总的充电度数是否和总报文消息中的数据相同,不相同等待30s
+		UploadRealTimeMonitoringData uploadRealTimeMonitoringData = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrder.getCode()).getData();
+		if(null != uploadRealTimeMonitoringData){
+			for (int i = 0; i < 30; i++) {
+				List<TChargingOrderAccountingStrategy> list1 = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()));
+				BigDecimal reduce = list1.stream().map(TChargingOrderAccountingStrategy::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add);
+				BigDecimal charging_degree = uploadRealTimeMonitoringData.getCharging_degree();
+				if(charging_degree.compareTo(reduce) != 0){
+					try {
+						Thread.sleep(1000);
+					} catch (InterruptedException e) {
+						throw new RuntimeException(e);
+					}
+				}else{
+					break;
+				}
+			}
+		}
+		
+		//计算用户标签
+		editUserTag(chargingOrder);
+		//用户推荐奖励
+		referralReward(chargingOrder);
+		
 		//如果使用优惠券需要判断优惠券是否满足使用条件
 		//根据实际的充电金额计算退款金额   退回费用=(原金额/总金额)*(总金额-实际充电金额)
 		//退款金额=优惠券金额+剩余充电金额
-		TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, vo.getTransaction_serial_number()));
 		List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()));
 		BigDecimal periodElectricPrice_total = BigDecimal.ZERO;
 		BigDecimal periodServicePrice_total = BigDecimal.ZERO;
@@ -1897,12 +1918,21 @@
 			payAmount = payAmount.subtract(discountAmount);
 		}
 		
-		if(chargingOrder.getEndMode() == 2){
-			chargingOrder.setEndMode(refundAmount.compareTo(BigDecimal.ZERO) > 0 ? 2 : 3);
+		TChargingOrder order = new TChargingOrder();
+		order.setId(chargingOrder.getId());
+		order.setAppUserId(chargingOrder.getAppUserId());
+		if(null != chargingOrder.getEndMode() && chargingOrder.getEndMode() == 2){
+			order.setEndMode(refundAmount.compareTo(BigDecimal.ZERO) > 0 ? 2 : 3);
 		}
-		chargingOrder.setStatus(5);
-		chargingOrder.setOrderAmount(orderAmount);
-		chargingOrder.setVipDiscountAmount(discountAmount);
+		if(null == chargingOrder.getEndMode()){
+			order.setEndMode(1);
+		}
+		order.setEndTime(LocalDateTime.now());
+		order.setStatus(5);
+		order.setOrderAmount(orderAmount);
+		order.setVipDiscountAmount(discountAmount);
+		order.setServiceCharge(periodServicePrice_total);
+		order.setElectrovalence(periodElectricPrice_total);
 		
 		//计算优惠券
 		if(null != chargingOrder.getAppCouponId()){
@@ -1915,11 +1945,11 @@
 				//满减
 				if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){
 					refundAmount = refundAmount.add(tCoupon.getDiscountAmount());
-					chargingOrder.setCouponDiscountAmount(tCoupon.getDiscountAmount());
+					order.setCouponDiscountAmount(tCoupon.getDiscountAmount());
 					payAmount = payAmount.subtract(tCoupon.getDiscountAmount());
 				}else{
-					chargingOrder.setAppCouponId(null);
-					chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO);
+					order.setAppCouponId(null);
+					order.setCouponDiscountAmount(BigDecimal.ZERO);
 					appCouponClient.refund(chargingOrder.getAppCouponId().toString());
 				}
 			}
@@ -1930,17 +1960,25 @@
 					BigDecimal divide = payAmount.multiply(new BigDecimal(10).subtract(tCoupon.getDiscount())).divide(new BigDecimal(10));
 					divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide;
 					refundAmount = refundAmount.add(divide);
-					chargingOrder.setCouponDiscountAmount(divide);
+					order.setCouponDiscountAmount(divide);
 					payAmount = payAmount.subtract(divide);
 				}else{
-					chargingOrder.setAppCouponId(null);
-					chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO);
+					order.setAppCouponId(null);
+					order.setCouponDiscountAmount(BigDecimal.ZERO);
 					appCouponClient.refund(chargingOrder.getAppCouponId().toString());
 				}
 			}
 		}
-		chargingOrder.setPaymentAmount(payAmount);
-		this.updateById(chargingOrder);
+		order.setPaymentAmount(payAmount);
+		order.setRefundAmount(refundAmount);
+		order.setRefundStatus(1);
+		this.updateById(order);
+		chargingOrder = this.getById(order.getId());
+		
+		// 将枪状态重置为空闲
+		TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData();
+		chargingGun.setStatus(2);
+		chargingGunClient.updateChargingGunById(chargingGun);
 		
 		//添加积分
 		TIntegralRule integralRule = integralRuleClient.getSet().getData();
@@ -2009,7 +2047,7 @@
 				RefundReq dto = new RefundReq();
 				dto.setOutTradeNo(chargingOrder.getCode());
 				dto.setOutRequestNo(chargingOrderRefund.getCode());
-				dto.setRefundAmount(rechargeAmount.toString());
+				dto.setRefundAmount(refundAmount.toString());
 				dto.setRefundReason("充电完成退款");
 				RefundResp resp = aliPaymentClient.refund(dto).getData();
 				if(null != resp){
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
index 0e9038a..73a49b6 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
@@ -274,29 +274,31 @@
     
         //检测敏感词
         String content = orderEvaluate.getContent();
-        String token = appUserClient.getWXToken().getData();
-        JSONObject jsonObject = new JSONObject();
-        jsonObject.put("content", content);
-        jsonObject.put("version", 2);
-        jsonObject.put("scene", 2);
-        jsonObject.put("openid", appUser.getWxOpenid());
-        String post = HttpUtils.post("https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + token, jsonObject.toString());
-        JSONObject object = JSONObject.parseObject(post);
-        Integer errcode = object.getInteger("errcode");
-        if(0 != errcode){
-            throw new RuntimeException(object.getString("errmsg"));
-        }
-        JSONArray detail = object.getJSONArray("detail");
-        for (int i = 0; i < detail.size(); i++) {
-            JSONObject jsonObject1 = detail.getJSONObject(i);
-            Integer errcode1 = jsonObject1.getInteger("errcode");
-            if(0 == errcode1){
-                String suggest = jsonObject1.getString("suggest");
-                Integer label = jsonObject1.getInteger("label");
-                String keyword = jsonObject1.getString("keyword");
-                Integer prob = jsonObject1.getInteger("prob");
-                if(("risky".equals(suggest) || "review".equals(suggest)) && 100 != label && StringUtils.isNotEmpty(keyword) && 80 <= prob){
-                    content = content.replaceAll(keyword, "***");
+        if(StringUtils.isNotEmpty(content)){
+            String token = appUserClient.getWXToken().getData();
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("content", content);
+            jsonObject.put("version", 2);
+            jsonObject.put("scene", 2);
+            jsonObject.put("openid", appUser.getWxOpenid());
+            String post = HttpUtils.post("https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + token, jsonObject.toString());
+            JSONObject object = JSONObject.parseObject(post);
+            Integer errcode = object.getInteger("errcode");
+            if(0 != errcode){
+                throw new RuntimeException(object.getString("errmsg"));
+            }
+            JSONArray detail = object.getJSONArray("detail");
+            for (int i = 0; i < detail.size(); i++) {
+                JSONObject jsonObject1 = detail.getJSONObject(i);
+                Integer errcode1 = jsonObject1.getInteger("errcode");
+                if(0 == errcode1){
+                    String suggest = jsonObject1.getString("suggest");
+                    Integer label = jsonObject1.getInteger("label");
+                    String keyword = jsonObject1.getString("keyword");
+                    Integer prob = jsonObject1.getInteger("prob");
+                    if(("risky".equals(suggest) || "review".equals(suggest)) && 100 != label && StringUtils.isNotEmpty(keyword) && 80 <= prob){
+                        content = content.replaceAll(keyword, "***");
+                    }
                 }
             }
         }
diff --git a/ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml b/ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
index 74ee227..2e982a7 100644
--- a/ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
+++ b/ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
@@ -62,7 +62,7 @@
         </if>
     </select>
     <select id="getNoInvoicedOrder" resultMap="BaseResultMap">
-        select * from t_charging_order where del_flag = 0 and status = 5 and recharge_payment_status = 2 and payment_amount is null and app_user_id = #{appUserId}
+        select * from t_charging_order where del_flag = 0 and status = 5 and recharge_payment_status = 2 and payment_amount is not null and app_user_id = #{appUserId}
         <if test="null != month and '' != month">
             and DATE_FORMAT(end_time, '%Y-%m') = #{month}
         </if>
diff --git a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java
index 04048b4..52f2e96 100644
--- a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java
+++ b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java
@@ -123,7 +123,7 @@
      */
     @PostMapping("pay/notify")
     @ApiOperation("订单回调")
-    public R<Map<String, Object>> payNotify(HttpServletRequest request) throws Exception {
+    public void payNotify(HttpServletRequest request) throws Exception {
         try {
             Map<String, Object> params = wxV3Pay.verifyNotify(request, new TypeReference<Map<String, Object>>() {});
             log.info("支付回调:{}", params);
@@ -147,13 +147,10 @@
                     break;
             }
             wxV3Pay.ack();
-            return R.ok(params);
         } catch (Exception e) {
             log.error("支付回调异常:{}", e, e);
             wxV3Pay.ack(false, e.getMessage());
-            return R.fail("回调异常");
         }
-
     }
     
     /**

--
Gitblit v1.7.1