Pārlūkot izejas kodu

refactor(charging): 优化熔断检查逻辑并完善接口日志记录

- 将熔断检查方法参数由订单号改为充电状态对象,简化参数传递
- 新增第三方设备信息Mapper注入,支持设备相关策略查询
- 在熔断检查中新增第三方设备和策略费用的查询逻辑
- 统一日志中熔断检查锁相关的startChargeSeq获取方式
- 在充电状态推送接口添加日志记录注解,增强调用日志跟踪能力
- 优化导入包为通配符,简化代码结构
SheepHy 1 dienu atpakaļ
vecāks
revīzija
8bce84cb2b

+ 1 - 0
src/main/java/com/zsElectric/boot/charging/controller/LinkDataController.java

@@ -130,6 +130,7 @@ public class LinkDataController {
      * */
     @Operation(summary = "推送充电状态")
     @PostMapping("/notification_equip_charge_status")
+    @Log(value = "推送充电状态", module = LogModuleEnum.PARKING, params = true, result = true)
     public ResponseParmsEntity chargeStatusResponse(@RequestBody RequestParmsEntity requestDTO){
         return chargingReceptionService.chargeStatusResponse(requestDTO);
     }

+ 16 - 15
src/main/java/com/zsElectric/boot/charging/service/impl/ChargingReceptionServiceImpl.java

@@ -4,17 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.zsElectric.boot.business.mapper.ChargeOrderInfoMapper;
-import com.zsElectric.boot.business.mapper.PolicyFeeMapper;
-import com.zsElectric.boot.business.mapper.UserAccountMapper;
-import com.zsElectric.boot.business.mapper.UserFirmMapper;
+import com.zsElectric.boot.business.mapper.*;
 import com.zsElectric.boot.business.model.entity.ChargeOrderInfo;
+import com.zsElectric.boot.business.model.entity.PolicyFee;
 import com.zsElectric.boot.business.model.entity.UserAccount;
 import com.zsElectric.boot.business.model.entity.UserFirm;
-import com.zsElectric.boot.charging.entity.ConnectorStatusInfo;
-import com.zsElectric.boot.charging.entity.StationStatusInfo;
-import com.zsElectric.boot.charging.entity.ThirdPartyChargeStatus;
-import com.zsElectric.boot.charging.entity.ThirdPartyConnectorInfo;
+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.service.ChargingReceptionService;
@@ -69,6 +64,7 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
     private final UserFirmMapper userFirmMapper;
     private final PolicyFeeMapper policyFeeMapper;
     private final DictItemMapper dictItemMapper;
+    private final ThirdPartyEquipmentInfoMapper thirdPartyEquipmentInfoMapper;
 
     /** 熔断检查锁前缀 */
     private static final String BREAK_CHECK_LOCK_KEY = "charging:break:check:";
@@ -293,7 +289,7 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
                 log.info("新增充电状态成功 - startChargeSeq: {}", startChargeSeq);
             }
             //熔断保护
-            isNeedBreak(startChargeSeq);
+            isNeedBreak(chargeStatus);
         } catch (Exception e) {
             log.error("保存充电状态数据失败", e);
         }
@@ -332,8 +328,8 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
      * 根据充电订单号StartChargeSeq 获取订单信息判断是否需要熔断,提前跳枪
      * 使用分布式锁防止并发重复检查
      */
-    private void isNeedBreak(String startChargeSeq) {
-        String lockKey = BREAK_CHECK_LOCK_KEY + startChargeSeq;
+    private void isNeedBreak(ThirdPartyChargeStatus chargeStatus) {
+        String lockKey = BREAK_CHECK_LOCK_KEY + chargeStatus.getStartChargeSeq();
         RLock lock = redissonClient.getLock(lockKey);
         try {
             // 尝试获取锁,最多等待3秒,持有锁最多10秒
@@ -341,7 +337,7 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
                 try {
                     ChargeOrderInfo chargeOrderInfo = chargeOrderInfoMapper.selectOne(
                             Wrappers.<ChargeOrderInfo>lambdaQuery()
-                                    .eq(ChargeOrderInfo::getChargeOrderNo, startChargeSeq)
+                                    .eq(ChargeOrderInfo::getChargeOrderNo, chargeStatus.getStartChargeSeq())
                                     .eq(ChargeOrderInfo::getStatus, 1)
                                     .eq(ChargeOrderInfo::getIsDeleted, 0)
                     );
@@ -365,7 +361,12 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
                                 .eq(UserFirm::getUserId, chargeOrderInfo.getUserId())
                                 .eq(UserFirm::getIsDeleted, 0));
                         if(null != userFirm){
-
+                            ThirdPartyEquipmentInfo thirdPartyEquipmentInfo = thirdPartyEquipmentInfoMapper.selectOne(Wrappers.<ThirdPartyEquipmentInfo>lambdaQuery()
+                                    .eq(ThirdPartyEquipmentInfo::getEquipmentId, chargeOrderInfo.getEquipmentId())
+                                    .eq(ThirdPartyEquipmentInfo::getIsDeleted, 0));
+                            List<PolicyFee> policyFees = policyFeeMapper.selectList(Wrappers.<PolicyFee>lambdaQuery()
+                                    .eq(PolicyFee::getStationInfoId, thirdPartyEquipmentInfo.getStationId())
+                                    .eq(PolicyFee::getFirmId, userFirm.getFirmId()));
                         }
 
                     }
@@ -373,11 +374,11 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
                     lock.unlock();
                 }
             } else {
-                log.warn("获取熔断检查锁超时 - startChargeSeq: {}", startChargeSeq);
+                log.warn("获取熔断检查锁超时 - startChargeSeq: {}", chargeStatus.getStartChargeSeq());
             }
         } catch (InterruptedException e) {
             Thread.currentThread().interrupt();
-            log.error("获取熔断检查锁被中断 - startChargeSeq: {}", startChargeSeq, e);
+            log.error("获取熔断检查锁被中断 - startChargeSeq: {}", chargeStatus.getStartChargeSeq(), e);
         }
     }
 }