|
|
@@ -13,6 +13,7 @@ import com.zsElectric.boot.business.service.ChargeOrderInfoService;
|
|
|
import com.zsElectric.boot.charging.entity.*;
|
|
|
import com.zsElectric.boot.charging.mapper.ThirdPartyChargeStatusMapper;
|
|
|
import com.zsElectric.boot.charging.mapper.ThirdPartyConnectorInfoMapper;
|
|
|
+import com.zsElectric.boot.charging.mapper.ThirdPartyEquipmentPricePolicyMapper;
|
|
|
import com.zsElectric.boot.charging.mapper.ThirdPartyPolicyInfoMapper;
|
|
|
import com.zsElectric.boot.charging.service.ChargingBusinessService;
|
|
|
import com.zsElectric.boot.charging.service.ChargingReceptionService;
|
|
|
@@ -42,10 +43,7 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Consumer;
|
|
|
@@ -84,6 +82,7 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
|
|
|
private final DiscountsActivityMapper discountsActivityMapper;
|
|
|
private final FirmAccountLogMapper firmAccountLogMapper;
|
|
|
private final OkHttpUtil okHttpUtil;
|
|
|
+ private final ThirdPartyEquipmentPricePolicyMapper thirdPartyEquipmentPricePolicyMapper;
|
|
|
|
|
|
/**
|
|
|
* 熔断检查锁前缀
|
|
|
@@ -236,6 +235,96 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
|
|
|
discountFee = discountFee.add(discountPrice.multiply(detailPower));
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ log.error("充电订单明细为空===============================================");
|
|
|
+ if (chargeOrderInfo.getThirdPartyTotalCost().compareTo(BigDecimal.ZERO) > 0 && chargeOrderInfo.getTotalCharge().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //判断当前订单创建时间在哪个时段
|
|
|
+ ThirdPartyChargeStatus thirdPartyChargeStatus = chargeStatusMapper.selectOne(Wrappers.<ThirdPartyChargeStatus>lambdaQuery()
|
|
|
+ .eq(ThirdPartyChargeStatus::getStartChargeSeq, chargeOrderInfo.getStartChargeSeq()));
|
|
|
+
|
|
|
+ ThirdPartyEquipmentPricePolicy thirdPartyEquipmentPricePolicy = thirdPartyEquipmentPricePolicyMapper.selectOne(Wrappers.<ThirdPartyEquipmentPricePolicy>lambdaQuery()
|
|
|
+ .eq(ThirdPartyEquipmentPricePolicy::getConnectorId, thirdPartyChargeStatus.getConnectorId())
|
|
|
+ .last("LIMIT 1"));
|
|
|
+
|
|
|
+ // 查询该价格策略下的所有时段信息,按startTime升序排列
|
|
|
+ List<ThirdPartyPolicyInfo> allPolicyInfos = thirdPartyPolicyInfoMapper.selectList(Wrappers.<ThirdPartyPolicyInfo>lambdaQuery()
|
|
|
+ .eq(ThirdPartyPolicyInfo::getPricePolicyId, thirdPartyEquipmentPricePolicy.getId())
|
|
|
+ .orderByAsc(ThirdPartyPolicyInfo::getStartTime));
|
|
|
+
|
|
|
+ // 将充电开始时间和结束时间转换为HHmmss格式字符串进行匹配
|
|
|
+ LocalDateTime chargeStartTime = thirdPartyChargeStatus.getStartTime();
|
|
|
+ LocalDateTime chargeEndTime = thirdPartyChargeStatus.getEndTime();
|
|
|
+ String chargeStartTimeStr = chargeStartTime.format(DateTimeFormatter.ofPattern("HHmmss"));
|
|
|
+ String chargeEndTimeStr = chargeEndTime.format(DateTimeFormatter.ofPattern("HHmmss"));
|
|
|
+
|
|
|
+ // 找到充电开始时间所在的时段索引
|
|
|
+ int startIndex = -1;
|
|
|
+ for (int i = allPolicyInfos.size() - 1; i >= 0; i--) {
|
|
|
+ if (chargeStartTimeStr.compareTo(allPolicyInfos.get(i).getStartTime()) >= 0) {
|
|
|
+ startIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (startIndex == -1 && !allPolicyInfos.isEmpty()) {
|
|
|
+ startIndex = allPolicyInfos.size() - 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找到充电结束时间所在的时段索引
|
|
|
+ int endIndex = -1;
|
|
|
+ for (int i = allPolicyInfos.size() - 1; i >= 0; i--) {
|
|
|
+ if (chargeEndTimeStr.compareTo(allPolicyInfos.get(i).getStartTime()) >= 0) {
|
|
|
+ endIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (endIndex == -1 && !allPolicyInfos.isEmpty()) {
|
|
|
+ endIndex = allPolicyInfos.size() - 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取充电时间跨越的所有时段集合
|
|
|
+ List<ThirdPartyPolicyInfo> matchedPolicyInfos = new ArrayList<>();
|
|
|
+ if (startIndex != -1 && endIndex != -1) {
|
|
|
+ if (startIndex <= endIndex) {
|
|
|
+ // 同一天内:从开始时段到结束时段
|
|
|
+ for (int i = startIndex; i <= endIndex; i++) {
|
|
|
+ matchedPolicyInfos.add(allPolicyInfos.get(i));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 跨天情况:从开始时段到最后 + 从第一个到结束时段
|
|
|
+ for (int i = startIndex; i < allPolicyInfos.size(); i++) {
|
|
|
+ matchedPolicyInfos.add(allPolicyInfos.get(i));
|
|
|
+ }
|
|
|
+ for (int i = 0; i <= endIndex; i++) {
|
|
|
+ matchedPolicyInfos.add(allPolicyInfos.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("充电时间段:{} - {},匹配到{}个时段", chargeStartTimeStr, chargeEndTimeStr, matchedPolicyInfos.size());
|
|
|
+
|
|
|
+ // 遍历所有匹配的时段,找到费用最高的时段计算服务费
|
|
|
+ if (!matchedPolicyInfos.isEmpty()) {
|
|
|
+ PolicyFee maxPolicyFee = null;
|
|
|
+ ThirdPartyPolicyInfo maxPolicyInfo = null;
|
|
|
+ for (ThirdPartyPolicyInfo policyInfo : matchedPolicyInfos) {
|
|
|
+ PolicyFee policyFee = policyFeeMapper.selectOne(Wrappers.<PolicyFee>lambdaQuery()
|
|
|
+ .eq(PolicyFee::getStationInfoId, thirdPartyStationInfo.getId())
|
|
|
+ .eq(PolicyFee::getPeriodFlag, policyInfo.getPeriodFlag())
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (ObjectUtil.isNotEmpty(policyFee)) {
|
|
|
+ if (maxPolicyFee == null || policyFee.getOpFee().compareTo(maxPolicyFee.getOpFee()) > 0) {
|
|
|
+ maxPolicyFee = policyFee;
|
|
|
+ maxPolicyInfo = policyInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (maxPolicyFee != null) {
|
|
|
+ log.info("使用最高费用时段:startTime={}, periodFlag={}, opFee={}",
|
|
|
+ maxPolicyInfo.getStartTime(), maxPolicyInfo.getPeriodFlag(), maxPolicyFee.getOpFee());
|
|
|
+ serviceFee = serviceFee.add(maxPolicyFee.getOpFee().multiply(chargeOrderInfo.getTotalCharge()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
log.info("计算后的平台服务费:{}", serviceFee);
|