Przeglądaj źródła

feat(price-policy): 补充字典映射实现站点及接口类型转换

- 新增字典服务依赖用于获取字典项数据
- 实现建设场所类型字典加载及转换方法
- 实现站点类型字典加载及转换方法
- 实现充电设备接口类型字典加载及转换方法
- 实现站点状态字典加载及转换方法
- 在价格策略分页视图对象中添加站点类型字段
- 价格策略服务中调用字典方法替换硬编码文本转换
- 添加日志和异常捕获,保证字典转换的稳定性
- 新增定时任务手动触发控制器,实现价格策略及充电站信息同步接口
- 通过接口日志收集及统一结果返回规范调用结果
SheepHy 3 dni temu
rodzic
commit
0f9ad0679b

+ 67 - 0
src/main/java/com/zsElectric/boot/business/controller/JobManualTriggerController.java

@@ -0,0 +1,67 @@
+package com.zsElectric.boot.business.controller;
+
+import com.zsElectric.boot.charging.quartz.ChargingJob;
+import com.zsElectric.boot.common.annotation.Log;
+import com.zsElectric.boot.common.enums.LogModuleEnum;
+import com.zsElectric.boot.core.web.Result;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 定时任务手动触发控制器
+ *
+ * @author system
+ * @since 2025-12-12
+ */
+@Slf4j
+@RestController
+@RequiredArgsConstructor
+@Tag(name = "定时任务管理")
+@RequestMapping("/dev/v1/job")
+public class JobManualTriggerController {
+
+    private final ChargingJob chargingJob;
+
+    /**
+     * 手动触发价格策略同步任务
+     */
+    @Operation(summary = "手动触发价格策略同步任务")
+    @PostMapping("/sync-price-policy")
+    @Log(value = "手动触发价格策略同步任务", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
+    public Result<String> syncPricePolicy() {
+        log.info("收到手动触发价格策略同步请求");
+        
+        try {
+            // 调用定时任务方法
+            chargingJob.syncEquipmentPricePolicy();
+            return Result.success("价格策略同步任务已完成,请查看日志了解详细信息");
+        } catch (Exception e) {
+            log.error("手动触发价格策略同步任务失败", e);
+            return Result.failed("价格策略同步任务执行失败: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 手动触发充电站信息同步任务
+     */
+    @Operation(summary = "手动触发充电站信息同步任务")
+    @PostMapping("/sync-stations-info")
+    @Log(value = "手动触发充电站信息同步任务", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
+    public Result<String> syncStationsInfo() {
+        log.info("收到手动触发充电站信息同步请求");
+        
+        try {
+            // 调用定时任务方法
+            chargingJob.syncStationsInfo();
+            return Result.success("充电站信息同步任务已完成,请查看日志了解详细信息");
+        } catch (Exception e) {
+            log.error("手动触发充电站信息同步任务失败", e);
+            return Result.failed("充电站信息同步任务执行失败: " + e.getMessage());
+        }
+    }
+}

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

@@ -35,6 +35,9 @@ public class PricePolicyPageVO {
     @Schema(description = "场所类型", example = "其他")
     private String locationType;
 
+    @Schema(description = "站点类型", example = "公共")
+    private String stationType;
+
     @Schema(description = "充电终端数量", example = "24")
     private Integer terminalCount;
 

+ 108 - 4
src/main/java/com/zsElectric/boot/business/service/impl/PricePolicyManagementServiceImpl.java

@@ -15,6 +15,8 @@ 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.mapper.ThirdPartyStationInfoMapper;
+import com.zsElectric.boot.system.model.vo.DictItemOptionVO;
+import com.zsElectric.boot.system.service.DictItemService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -26,7 +28,9 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -44,8 +48,15 @@ public class PricePolicyManagementServiceImpl implements PricePolicyManagementSe
     private final ThirdPartyConnectorInfoMapper connectorInfoMapper;
     private final ThirdPartyEquipmentPricePolicyMapper pricePolicyMapper;
     private final ThirdPartyPolicyInfoMapper policyInfoMapper;
+    private final DictItemService dictItemService;
 
     private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm");
+    
+    // 字典缓存
+    private Map<String, String> constructionTypeMap;
+    private Map<String, String> stationStatusMap;
+    private Map<String, String> stationTypeMap;
+    private Map<String, String> connectorTypeMap;
 
     @Override
     public Page<PricePolicyPageVO> queryPricePolicyPage(PricePolicyPageQuery query) {
@@ -85,6 +96,7 @@ public class PricePolicyManagementServiceImpl implements PricePolicyManagementSe
         vo.setEquipmentOwner(station.getEquipmentOwnerId());
         vo.setAddress(station.getAddress());
         vo.setLocationType(getLocationType(station.getConstruction()));
+        vo.setStationType(getStationType(station.getStationType()));
         vo.setTerminalCount(getTerminalCount(station.getStationId()));
         vo.setStationStatus(getStationStatusText(station.getStationStatus()));
         vo.setServiceTel(station.getServiceTel());
@@ -288,8 +300,81 @@ public class PricePolicyManagementServiceImpl implements PricePolicyManagementSe
      * 获取场所类型文本
      */
     private String getLocationType(Integer construction) {
-        // TODO: 根据建设场所代码返回文本
-        return "其他";
+        if (construction == null) {
+            return "其他";
+        }
+        
+        // 懒加载字典数据
+        if (constructionTypeMap == null) {
+            loadConstructionTypeDict();
+        }
+        
+        return constructionTypeMap.getOrDefault(String.valueOf(construction), "其他");
+    }
+    
+    /**
+     * 加载建设场所类型字典
+     */
+    private void loadConstructionTypeDict() {
+        constructionTypeMap = new HashMap<>();
+        List<DictItemOptionVO> dictItems = dictItemService.getDictItems("charging_construction_type");
+        for (DictItemOptionVO item : dictItems) {
+            constructionTypeMap.put(item.getValue(), item.getLabel());
+        }
+    }
+
+    /**
+     * 获取站点类型文本
+     */
+    private String getStationType(Integer stationType) {
+        if (stationType == null) {
+            return "其他";
+        }
+        
+        // 懒加载字典数据
+        if (stationTypeMap == null) {
+            loadStationTypeDict();
+        }
+        
+        return stationTypeMap.getOrDefault(String.valueOf(stationType), "其他");
+    }
+    
+    /**
+     * 加载站点类型字典
+     */
+    private void loadStationTypeDict() {
+        stationTypeMap = new HashMap<>();
+        List<DictItemOptionVO> dictItems = dictItemService.getDictItems("charging_station_type");
+        for (DictItemOptionVO item : dictItems) {
+            stationTypeMap.put(item.getValue(), item.getLabel());
+        }
+    }
+
+    /**
+     * 获取充电设备接口类型文本
+     */
+    public String getConnectorType(Integer connectorType) {
+        if (connectorType == null) {
+            return "其他";
+        }
+        
+        // 懒加载字典数据
+        if (connectorTypeMap == null) {
+            loadConnectorTypeDict();
+        }
+        
+        return connectorTypeMap.getOrDefault(String.valueOf(connectorType), "其他");
+    }
+    
+    /**
+     * 加载充电设备接口类型字典
+     */
+    private void loadConnectorTypeDict() {
+        connectorTypeMap = new HashMap<>();
+        List<DictItemOptionVO> dictItems = dictItemService.getDictItems("charging_connector_type");
+        for (DictItemOptionVO item : dictItems) {
+            connectorTypeMap.put(item.getValue(), item.getLabel());
+        }
     }
 
     /**
@@ -307,7 +392,26 @@ public class PricePolicyManagementServiceImpl implements PricePolicyManagementSe
      * 获取站点状态文本
      */
     private String getStationStatusText(Integer status) {
-        // TODO: 根据状态代码返回文本
-        return "未知";
+        if (status == null) {
+            return "未知";
+        }
+        
+        // 懒加载字典数据
+        if (stationStatusMap == null) {
+            loadStationStatusDict();
+        }
+        
+        return stationStatusMap.getOrDefault(String.valueOf(status), "未知");
+    }
+    
+    /**
+     * 加载站点状态字典
+     */
+    private void loadStationStatusDict() {
+        stationStatusMap = new HashMap<>();
+        List<DictItemOptionVO> dictItems = dictItemService.getDictItems("charging_station_status");
+        for (DictItemOptionVO item : dictItems) {
+            stationStatusMap.put(item.getValue(), item.getLabel());
+        }
     }
 }