瀏覽代碼

refactor(charging): 优化实时充电费用查询接口

- 在AppChargingCostVO中新增充电状态status字段描述充电进度
- 修改AppletHomeService及实现,新增根据订单号查询实时费用的方法
- 调整AppletStationController接口,支持传入订单号查询费用
- 更新数据库查询语句,使用订单号过滤当前充电订单数据
- 注释优化ChargingJob调度说明,明确执行周期改为每5分钟一次
SheepHy 3 周之前
父節點
當前提交
d1f79ccea9

+ 2 - 2
src/main/java/com/zsElectric/boot/business/controller/applet/AppletStationController.java

@@ -78,8 +78,8 @@ public class AppletStationController {
     @Operation(summary = "获取当前充电订单实时费用")
     @GetMapping("/charging-cost")
     @ApiRateLimit(prefix = "applet:charging_cost", limitType = ApiRateLimit.LimitType.IP, count = 2000, time = 60, message = "获取充电费用请求过于频繁,请稍后再试")
-    public Result<AppChargingCostVO> getCurrentChargingCost() {
-        return Result.success(appletHomeService.getCurrentChargingCost());
+    public Result<AppChargingCostVO> getCurrentChargingCost(String orderNo) {
+        return Result.success(appletHomeService.getCurrentChargingCost(orderNo));
     }
 
     /**

+ 1 - 1
src/main/java/com/zsElectric/boot/business/mapper/ThirdPartyStationInfoMapper.java

@@ -98,7 +98,7 @@ public interface ThirdPartyStationInfoMapper extends BaseMapper<ThirdPartyStatio
      * @param userId 用户ID
      * @return 实时充电费用信息
      */
-    AppChargingCostVO selectCurrentChargingCost(@Param("userId") Long userId);
+    AppChargingCostVO selectCurrentChargingCost(@Param("userId") Long userId, @Param("orderNo") String orderNo);
 
     /**
      * 搜索充电站(根据站点名称和地址模糊查询)

+ 3 - 0
src/main/java/com/zsElectric/boot/business/model/vo/applet/AppChargingCostVO.java

@@ -78,4 +78,7 @@ public class AppChargingCostVO implements Serializable {
 
     @Schema(description = "时段明细JSON(跨时段充电时有值)")
     private String chargeDetails;
+
+    @Schema(description = "充电状态 状态0待启动 1 充电中 2 结算中 3 已完成, 5未成功充电")
+    private String status;
 }

+ 1 - 1
src/main/java/com/zsElectric/boot/business/service/AppletHomeService.java

@@ -61,7 +61,7 @@ public interface AppletHomeService {
      * 根据当前登录用户ID查询正在充电中的订单
      * @return 实时充电费用信息,如果没有正在充电的订单则返回null
      * */
-    AppChargingCostVO getCurrentChargingCost();
+    AppChargingCostVO getCurrentChargingCost(String orderNo);
 
     /**
      * 搜索充电站

+ 2 - 2
src/main/java/com/zsElectric/boot/business/service/impl/AppletHomeServiceImpl.java

@@ -686,14 +686,14 @@ public class AppletHomeServiceImpl implements AppletHomeService {
     }
 
     @Override
-    public AppChargingCostVO getCurrentChargingCost() {
+    public AppChargingCostVO getCurrentChargingCost(String orderNo) {
         // 获取当前登录用户ID
         Long userId = SecurityUtils.getUserId();
         if (userId == null) {
             return null;
         }
 
-        AppChargingCostVO result = thirdPartyStationInfoMapper.selectCurrentChargingCost(userId);
+        AppChargingCostVO result = thirdPartyStationInfoMapper.selectCurrentChargingCost(userId,orderNo);
         if (result == null) {
             return null;
         }

+ 2 - 3
src/main/java/com/zsElectric/boot/charging/quartz/ChargingJob.java

@@ -43,10 +43,9 @@ public class ChargingJob {
 
     /**
      * 同步充电站信息
-     * 手动触发或启动时执行一次,从第三方接口获取充电站信息并存储到数据库
-     * 注意:已移除定时任务,改为手动触发
+     * 每5分钟执行一次,从第三方接口获取充电站信息并存储到数据库
      */
-//     @Scheduled(cron = "0 0/30 * * * ?") // 已禁用定时执行
+//    @Scheduled(cron = "0 0/15 * * * ?")
     public void syncStationsInfo() {
         log.info("开始执行充电站信息同步定时任务");
         

+ 2 - 1
src/main/resources/mapper/business/ThirdPartyStationInfoMapper.xml

@@ -571,6 +571,7 @@
         SELECT
             coi.charge_order_no,
             tpsi.station_name,
+            coi.status,
             tpci.connector_name,
             tcs.start_charge_seq_stat AS order_status,
             CASE tcs.start_charge_seq_stat
@@ -613,7 +614,7 @@
             ON tpci.station_id = tpsi.station_id
             AND tpsi.is_deleted = 0
         WHERE coi.user_id = #{userId}
-            AND coi.status = 1
+            AND coi.charge_order_no = #{orderNo}
             AND coi.is_deleted = 0
         ORDER BY tcs.update_time DESC
         LIMIT 1