From d125ba1d4cd4b77e103e7b5b26d1d83a9c8c8bd4 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期四, 05 九月 2024 16:14:43 +0800
Subject: [PATCH] 代码提交

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java |  122 +++++++++++++++++++++-------------------
 1 files changed, 65 insertions(+), 57 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 ea7bafb..b672bec 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,7 +4,6 @@
 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.*;
@@ -16,11 +15,9 @@
 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.page.BasePage;
 import com.ruoyi.common.core.web.page.PageInfo;
 import com.ruoyi.common.redis.service.RedisService;
 import com.ruoyi.common.security.service.TokenService;
-import com.ruoyi.common.security.utils.SecurityUtils;
 import com.ruoyi.integration.api.feignClient.ChargingHandshakeClient;
 import com.ruoyi.integration.api.feignClient.PlatformStartChargingReplyClient;
 import com.ruoyi.integration.api.feignClient.SendMessageClient;
@@ -43,6 +40,10 @@
 import com.ruoyi.order.api.vo.TCharingOrderVO;
 import com.ruoyi.order.dto.*;
 import com.ruoyi.order.mapper.TChargingOrderMapper;
+import com.ruoyi.order.service.TChargingOrderAccountingStrategyService;
+import com.ruoyi.order.service.TChargingOrderRefundService;
+import com.ruoyi.order.service.TChargingOrderService;
+import com.ruoyi.order.service.TOrderEvaluateService;
 import com.ruoyi.order.service.*;
 import com.ruoyi.other.api.domain.TCoupon;
 import com.ruoyi.other.api.domain.TGoods;
@@ -57,7 +58,6 @@
 import com.ruoyi.payment.api.model.RefundResp;
 import com.ruoyi.payment.api.model.WxPaymentRefundModel;
 import com.ruoyi.payment.api.vo.*;
-import com.ruoyi.system.api.domain.SysUser;
 import com.ruoyi.system.api.feignClient.SysUserClient;
 import io.seata.spring.annotation.GlobalTransactional;
 import io.swagger.annotations.ApiModelProperty;
@@ -77,7 +77,6 @@
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
-import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.stream.Collectors;
@@ -94,7 +93,7 @@
 public class TChargingOrderServiceImpl extends ServiceImpl<TChargingOrderMapper, TChargingOrder> implements TChargingOrderService {
 	
 	private Logger log = LoggerFactory.getLogger(TChargingOrderServiceImpl.class);
-	
+
 	@Resource
 	private ChargingGunClient chargingGunClient;
 	
@@ -144,45 +143,45 @@
 	@Resource
 	private TOrderEvaluateService orderEvaluateService;
 
-	
+
 	@Resource
 	private AccountingStrategyDetailClient accountingStrategyDetailClient;
-	
+
 	@Resource
 	private AccountingStrategyDetailOrderClient accountingStrategyDetailOrderClient;
-	
+
 	@Resource
 	private AccountingStrategyClient accountingStrategyClient;
-	
+
 	@Resource
 	private PlatformStartChargingReplyClient platformStartChargingReplyClient;
-	
+
 	@Resource
 	private TChargingOrderRefundService chargingOrderRefundService;
-	
+
 	@Resource
 	private PlatformStopChargingReplyClient platformStopChargingReplyClient;
-	
+
 	@Resource
 	private AccountingStrategyOrderService accountingStrategyOrderService;
-	
+
 	@Resource
 	private AccountingStrategyDetailOrderService accountingStrategyDetailOrderService;
-	
+
 	@Resource
 	private InviteUserClient inviteUserClient;
-	
+
 	@Resource
 	private AppUserIntegralChangeClient appUserIntegralChangeClient;
-	
+
 	@Resource
 	private IntegralRuleClient integralRuleClient;
-	
+
 	//计数器
 	private Map<String, Integer> counter_map = new HashMap<>();
-	
-	
-	
+
+
+
 
 	/**
 	 * 获取小程序充电记录列表数据
@@ -443,7 +442,7 @@
 			}
 		}
 		this.save(chargingOrder);
-		
+
 		//添加订单的计费策略
 		TAccountingStrategy accountingStrategy = accountingStrategyClient.getAccountingStrategyById(tChargingGun.getAccountingStrategyId()).getData();
 		List<TAccountingStrategyDetail> strategyDetailList = accountingStrategyDetailClient.getListByAccountingStrategyId(tChargingGun.getAccountingStrategyId()).getData();
@@ -459,7 +458,7 @@
 			list1.add(accountingStrategyDetailOrder);
 		}
 		accountingStrategyDetailOrderService.saveBatch(list1);
-		
+
 		//会员优惠折扣将其计入增加充电时长(增加总充电金额)
 		//如果充电总金额未使用完,则需要退回费用=(原金额/总金额)*(总金额-实际充电金额)
 		if(1 == addChargingOrder.getPaymentType()){
@@ -507,7 +506,7 @@
 		chargingOrder.setRechargePaymentStatus(2);
 		chargingOrder.setRechargeSerialNumber(transaction_id);
 		chargingOrder.setStatus(2);
-		
+
 		//添加安全检测数据到缓存中,每步安全检测完成后需要更新缓存数据
 		PreChargeCheck preChargeCheck = new PreChargeCheck();
 		preChargeCheck.setElectronicLockLock(false);
@@ -529,7 +528,7 @@
 		//计算电费金额和服务费
 		BigDecimal serviceCharge = strategyDetail.getServiceCharge().multiply(degrees);
 		BigDecimal electrovalence = strategyDetail.getElectrovalence().multiply(degrees);
-		
+
 		//再处理会员折扣
 		BigDecimal discount = BigDecimal.ZERO;
 		TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
@@ -547,8 +546,8 @@
 		electrovalence = electrovalence.add(discount);
 		chargingOrder.setChargeAmount(electrovalence);
 		this.updateById(chargingOrder);
-		
-		
+
+
 		TChargingPile chargingPile = chargingPileClient.getChargingPileById(chargingGun.getChargingPileId()).getData();
 		//调用远程启动充电消息
 		PlatformStartCharging platformStartCharging = new PlatformStartCharging();
@@ -665,11 +664,11 @@
 					}
 				}
 			}
-			
+
 		}
 	}
-	
-	
+
+
 	/**
 	 * 启动失败后微信退款的回调处理
 	 * @param out_refund_no
@@ -688,10 +687,10 @@
 		}
 		return AjaxResult.success();
 	}
-	
-	
-	
-	
+
+
+
+
 	/**
 	 * 获取充电中的详情
 	 * @param id
@@ -754,7 +753,7 @@
 		chargingOrder.setStatus(4);
 		chargingOrder.setEndMode(1);
 		this.updateById(chargingOrder);
-		
+
 		//异步线程处理停机
 		ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1);
 		cachedThreadPool.execute(()->{
@@ -779,7 +778,7 @@
 					}
 					continue;
 				}
-				
+
 				if(0 == reply.getStop_result()){
 					String failure_cause = "";
 					switch (reply.getFailure_cause()){
@@ -799,14 +798,14 @@
 					log.error("停机失败:订单号:{},失败原因:{}", chargingOrder.getCode(), failure_cause);
 					throw new RuntimeException(failure_cause);
 				}
-				
+
 				//计算费用,处理退款
 				endCharge(chargingOrder);
 				break;
 			}
 		});
-		
-		
+
+
 		//处理推荐奖励(被推荐首单奖励)
 		TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
 		long count = this.count(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserId, chargingOrder.getAppUserId())
@@ -841,15 +840,15 @@
 			appUserIntegralChange.setCurrentIntegral(appUser1.getPoints() + num1);
 			appUserIntegralChange.setCreateTime(LocalDateTime.now());
 			appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
-			
+
 			appUser1.setPoints(appUser1.getPoints() + num1);
 			appUserClient.updateAppUser(appUser1);
 		}
-		
+
 		return AjaxResult.success();
 	}
-	
-	
+
+
 	/**
 	 * 手动结束后的费用计算和退款逻辑
 	 */
@@ -876,14 +875,14 @@
 			orderAmount = orderAmount.divide(chargingOrder.getVipDiscount().divide(new BigDecimal(10)));
 			chargingOrder.setOrderAmount(total);
 		}
-		
-		if(chargingOrder.getEndMode() != 1){
+
+		if(chargingOrder.getEndMode() == 2){
 			chargingOrder.setEndMode(refundAmount.compareTo(BigDecimal.ZERO) > 0 ? 2 : 3);
 		}
 		chargingOrder.setStatus(5);
 		chargingOrder.setPaymentAmount(payAmount);
 		this.updateById(chargingOrder);
-		
+
 		//计算优惠券
 		if(null != chargingOrder.getAppCouponId()){
 			//判断实际充电金额是否满足优惠券使用条件,如果不满足则不适用优惠券。
@@ -919,7 +918,7 @@
 				}
 			}
 		}
-		
+
 		if(null != chargingOrder.getVipDiscount()){
 			BigDecimal subtract = orderAmount.subtract(total);
 			chargingOrder.setVipDiscountAmount(subtract);
@@ -975,9 +974,9 @@
 					}
 				}
 			}
-			
+
 		}
-		
+
 	}
 
 
@@ -1466,7 +1465,7 @@
 					chargingOrderAccountingStrategyService.save(chargingOrderAccountingStrategy1);
 				}
 			}
-			
+
 			List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>()
 					.eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()));
 			BigDecimal t = BigDecimal.ZERO;
@@ -1480,27 +1479,27 @@
 			this.updateById(chargingOrder);
 		}
 	}
-	
-	
+
+
 	/**
 	 * 自动结束充电后的处理逻辑
 	 * @param orderCode
 	 */
 	@Override
 	@GlobalTransactional(rollbackFor = Exception.class)
-	public void endCharge(String orderCode) {
+	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);
-		chargingOrder.setEndMode(2);
+		chargingOrder.setEndMode(endMode);
 		this.updateById(chargingOrder);
-		
+
 		//计算费用,处理退款
 		endCharge(chargingOrder);
-	
+
 		//处理推荐奖励(被推荐首单奖励)
 		TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
 		long count = this.count(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserId, chargingOrder.getAppUserId())
@@ -1535,9 +1534,18 @@
 			appUserIntegralChange.setCurrentIntegral(appUser1.getPoints() + num1);
 			appUserIntegralChange.setCreateTime(LocalDateTime.now());
 			appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
-			
+
 			appUser1.setPoints(appUser1.getPoints() + num1);
 			appUserClient.updateAppUser(appUser1);
 		}
 	}
+
+	/**
+	 * 异常结束充电处理逻辑
+	 * @param orderCode
+	 */
+	@Override
+	public void excelEndCharge(String orderCode) {
+		endCharge(orderCode, 0);
+	}
 }

--
Gitblit v1.7.1