From 187155d0e0ae19d4846372e196afb9f4a4e2652e Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 09 十月 2025 11:23:45 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java |   89 ++++++++++++++++-------------
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java     |   43 ++++++++------
 2 files changed, 74 insertions(+), 58 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java
index a3279fb..daec325 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java
@@ -15,9 +15,11 @@
 import com.ruoyi.chargingPile.api.feignClient.ChargingGunClient;
 import com.ruoyi.chargingPile.api.model.TChargingGun;
 import com.ruoyi.chargingPile.api.model.TChargingPile;
+import com.ruoyi.common.core.utils.ServletUtils;
 import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
 import com.ruoyi.common.log.enums.OperatorType;
+import com.ruoyi.common.security.utils.SecurityUtils;
 import com.ruoyi.other.api.vo.CouponListVOVO;
 import com.ruoyi.account.api.vo.ExchangeRecordVO;
 import com.ruoyi.account.service.TAppCouponService;
@@ -115,28 +117,33 @@
         data.setChargingGunId(id);
         data.setSiteId(chargingGun.getSiteId());
         data.setChargeMode(chargingGun.getChargeMode());
-        List<TAppUserCar> cars = appUserCarService.list(new QueryWrapper<TAppUserCar>()
-                .eq("app_user_id",tokenService.getLoginUserApplet().getUserId())
-                .orderByDesc("create_time"));
-        Long data1 = chargingOrderClient.getCar(tokenService.getLoginUserApplet().getUserId().toString()).getData();
-        Integer data2 = otherClient.getAddCarIntegral().getData();
-        data.setIntegral(data2);
-        if (!cars.isEmpty()){
-            if (null == data1 || data1 == -1){
-                // 没有充电订单 展示最新添加的车辆
-                data.setLicensePlate(cars.get(0).getLicensePlate());
-                data.setVehicleBrand(cars.get(0).getVehicleBrand());
-                data.setId(cars.get(0).getId().toString());
-            }else{
-                for (TAppUserCar car : cars) {
-                    if (car.getId().equals(data1)){
-                        data.setLicensePlate(car.getLicensePlate());
-                        data.setVehicleBrand(car.getVehicleBrand());
-                        data.setId(car.getId().toString());
+
+        String token = SecurityUtils.getToken(ServletUtils.getRequest());
+        if(com.ruoyi.common.core.utils.StringUtils.isNotEmpty(token)){
+            List<TAppUserCar> cars = appUserCarService.list(new QueryWrapper<TAppUserCar>()
+                    .eq("app_user_id",tokenService.getLoginUserApplet().getUserId())
+                    .orderByDesc("create_time"));
+            Long data1 = chargingOrderClient.getCar(tokenService.getLoginUserApplet().getUserId().toString()).getData();
+            if (!cars.isEmpty()){
+                if (null == data1 || data1 == -1){
+                    // 没有充电订单 展示最新添加的车辆
+                    data.setLicensePlate(cars.get(0).getLicensePlate());
+                    data.setVehicleBrand(cars.get(0).getVehicleBrand());
+                    data.setId(cars.get(0).getId().toString());
+                }else{
+                    for (TAppUserCar car : cars) {
+                        if (car.getId().equals(data1)){
+                            data.setLicensePlate(car.getLicensePlate());
+                            data.setVehicleBrand(car.getVehicleBrand());
+                            data.setId(car.getId().toString());
+                        }
                     }
                 }
             }
         }
+        Integer data2 = otherClient.getAddCarIntegral().getData();
+        data.setIntegral(data2);
+
         BigDecimal electrovalence = data.getElectrovalence();
         BigDecimal vipElectrovalence = data.getVipElectrovalence();
         // 计算预付金额能充多少度普通电
diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java
index c26fdc1..d574202 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java
@@ -26,6 +26,7 @@
 import com.ruoyi.chargingPile.service.*;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.utils.DateUtils;
+import com.ruoyi.common.core.utils.ServletUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.ruoyi.common.core.web.page.PageInfo;
@@ -149,30 +150,33 @@
 					&& DateUtils.string2LocalTime(tAccountingStrategyDetail.getEndTime() + ("23:59:59".equals(tAccountingStrategyDetail.getEndTime())?"":":00")).compareTo(LocalTime.now()) > 0){
 				siteInfoVO.setElectrovalence(tAccountingStrategyDetail.getElectrovalence().add(tAccountingStrategyDetail.getServiceCharge()).setScale(4, BigDecimal.ROUND_HALF_UP));
 				// 获取当前登录用户id
-				Long userId = tokenService.getLoginUserApplet().getUserId();
-				// 根据id查询用户信息
-				TAppUser appUser = appUserClient.getUserById(userId).getData();
-				if(Objects.nonNull(byId1.getDiscount())){
-					siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().multiply(byId1.getDiscount()).add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
-				}else {
-					siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
-				}
-				TVip vip = null;
-				if(Objects.nonNull(appUser)){
-//					TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
-					GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail();
-					getAppUserVipDetail.setAppUserId(userId);
-					getAppUserVipDetail.setVipId(appUser.getVipId());
-					R<TAppUserVipDetail> appUserVipDetail = vipDetailClient.getAppUserVipDetail(getAppUserVipDetail);
-					TAppUserVipDetail data1 = appUserVipDetail.getData();
-					if(Objects.nonNull(data1)){
-						String vipJson = data1.getVipJson();
-						vip = JSON.parseObject(vipJson, TVip.class);
+				String token = SecurityUtils.getToken(ServletUtils.getRequest());
+				if(StringUtils.isNotEmpty(token)){
+					Long userId = tokenService.getLoginUserApplet().getUserId();
+					// 根据id查询用户信息
+					TAppUser appUser = appUserClient.getUserById(userId).getData();
+					if(Objects.nonNull(byId1.getDiscount())){
+						siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().multiply(byId1.getDiscount()).add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
+					}else {
+						siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
 					}
-				}
+					TVip vip = null;
+					if(Objects.nonNull(appUser)){
+//					TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
+						GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail();
+						getAppUserVipDetail.setAppUserId(userId);
+						getAppUserVipDetail.setVipId(appUser.getVipId());
+						R<TAppUserVipDetail> appUserVipDetail = vipDetailClient.getAppUserVipDetail(getAppUserVipDetail);
+						TAppUserVipDetail data1 = appUserVipDetail.getData();
+						if(Objects.nonNull(data1)){
+							String vipJson = data1.getVipJson();
+							vip = JSON.parseObject(vipJson, TVip.class);
+						}
+					}
 
-				if(Objects.nonNull(vip) && vip.getType() == 2){
-					siteInfoVO.setVipElectrovalence(vip.getDiscount().divide(new BigDecimal(10)).multiply(tAccountingStrategyDetail.getServiceCharge()).add(tAccountingStrategyDetail.getElectrovalence()));
+					if(Objects.nonNull(vip) && vip.getType() == 2){
+						siteInfoVO.setVipElectrovalence(vip.getDiscount().divide(new BigDecimal(10)).multiply(tAccountingStrategyDetail.getServiceCharge()).add(tAccountingStrategyDetail.getElectrovalence()));
+					}
 				}
 			}
 		}
@@ -207,29 +211,34 @@
 					&& DateUtils.string2LocalTime(tAccountingStrategyDetail.getEndTime() + ("23:59:59".equals(tAccountingStrategyDetail.getEndTime())?"":":00")).compareTo(LocalTime.now()) > 0){
 				siteInfoVO.setElectrovalence(tAccountingStrategyDetail.getElectrovalence().add(tAccountingStrategyDetail.getServiceCharge()).setScale(4, BigDecimal.ROUND_HALF_UP));
 				// 获取当前登录用户id
-				Long userId = tokenService.getLoginUserApplet().getUserId();
-				// 根据id查询用户信息
-				TAppUser appUser = appUserClient.getUserById(userId).getData();
+				String token = SecurityUtils.getToken(ServletUtils.getRequest());
+				if(StringUtils.isNotEmpty(token)){
+					Long userId = tokenService.getLoginUserApplet().getUserId();
+					// 根据id查询用户信息
+					TAppUser appUser = appUserClient.getUserById(userId).getData();
+					if(Objects.nonNull(appUser)){
+//					TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
+						GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail();
+						getAppUserVipDetail.setAppUserId(userId);
+						getAppUserVipDetail.setVipId(appUser.getVipId());
+						R<TAppUserVipDetail> appUserVipDetail = vipDetailClient.getAppUserVipDetail(getAppUserVipDetail);
+						TAppUserVipDetail data1 = appUserVipDetail.getData();
+						if(Objects.nonNull(data1)){
+							String vipJson = data1.getVipJson();
+							TVip vip = JSON.parseObject(vipJson, TVip.class);
+							if(Objects.nonNull(vip) && vip.getType() == 2){
+								siteInfoVO.setVipElectrovalence(vip.getDiscount().divide(new BigDecimal(10)).multiply(tAccountingStrategyDetail.getServiceCharge()).add(tAccountingStrategyDetail.getElectrovalence()));
+							}
+						}
+					}
+				}
+
 				if(Objects.nonNull(byId1.getDiscount())){
 					siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().multiply(byId1.getDiscount()).add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
 				}else {
 					siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
 				}
-				if(Objects.nonNull(appUser)){
-//					TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
-					GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail();
-					getAppUserVipDetail.setAppUserId(userId);
-					getAppUserVipDetail.setVipId(appUser.getVipId());
-					R<TAppUserVipDetail> appUserVipDetail = vipDetailClient.getAppUserVipDetail(getAppUserVipDetail);
-					TAppUserVipDetail data1 = appUserVipDetail.getData();
-					if(Objects.nonNull(data1)){
-						String vipJson = data1.getVipJson();
-						TVip vip = JSON.parseObject(vipJson, TVip.class);
-						if(Objects.nonNull(vip) && vip.getType() == 2){
-							siteInfoVO.setVipElectrovalence(vip.getDiscount().divide(new BigDecimal(10)).multiply(tAccountingStrategyDetail.getServiceCharge()).add(tAccountingStrategyDetail.getElectrovalence()));
-						}
-					}
-				}
+
 			}
 		}
 		List<TVip> vips = vipClient.getVipList().getData();

--
Gitblit v1.7.1