Sfoglia il codice sorgente

feat(applet): 添加充电设备接口详情查询功能

- 新增AppletConnectorDetailVO封装充电设备接口详细信息
- 在AppletHomeService接口及实现类中添加getConnectorDetail方法
- 查询接口详细信息包括设备、充电站、价格及充电状态数据
- 支持根据当前登录用户查询企业定价
- 新增AppletStationController中接口以提供充电接口详情查询
- 提供接口类型和国家标准名称的辅助方法映射描述信息
- 充电中状态下返回实时电流、电压、功率及电池SOC数据
- 接口返回包含价格、状态、设备和充电站相关丰富信息
SheepHy 11 ore fa
parent
commit
8f3ade871c

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

@@ -4,6 +4,7 @@ import com.zsElectric.boot.business.model.vo.AppletConnectorListVO;
 import com.zsElectric.boot.business.model.vo.AppletStationDetailVO;
 import com.zsElectric.boot.business.model.vo.AppletStationPriceListVO;
 import com.zsElectric.boot.business.model.vo.applet.AppletChargingCostVO;
+import com.zsElectric.boot.business.model.vo.applet.AppletConnectorDetailVO;
 import com.zsElectric.boot.business.model.vo.applet.AppletStationSearchVO;
 import com.zsElectric.boot.business.service.AppletHomeService;
 import com.zsElectric.boot.common.annotation.ApiRateLimit;
@@ -97,4 +98,16 @@ public class AppletStationController {
             @RequestParam(required = false) BigDecimal latitude) {
         return Result.success(appletHomeService.searchStations(keyword, longitude, latitude));
     }
+
+    /**
+     * 获取充电设备接口详情
+     *
+     * @param connectorId 充电设备接口ID
+     * @return 设备接口详情
+     */
+    @Operation(summary = "获取充电设备接口详情")
+    @GetMapping("/connector/detail")
+    public Result<AppletConnectorDetailVO> getConnectorDetail(@RequestParam Long connectorId) {
+        return Result.success(appletHomeService.getConnectorDetail(connectorId));
+    }
 }

+ 117 - 0
src/main/java/com/zsElectric/boot/business/model/vo/applet/AppletConnectorDetailVO.java

@@ -0,0 +1,117 @@
+package com.zsElectric.boot.business.model.vo.applet;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 小程序充电设备接口详情VO
+ *
+ * @author system
+ * @since 2025-12-22
+ */
+@Getter
+@Setter
+@Schema(description = "小程序充电设备接口详情VO")
+public class AppletConnectorDetailVO implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    @Schema(description = "充电设备接口ID")
+    private Long connectorId;
+
+    @Schema(description = "充电设备接口编码")
+    private String connectorCode;
+
+    @Schema(description = "充电设备接口名称")
+    private String connectorName;
+
+    @Schema(description = "充电站ID")
+    private Long stationId;
+
+    @Schema(description = "充电站名称")
+    private String stationName;
+
+    @Schema(description = "充电站地址")
+    private String stationAddress;
+
+    @Schema(description = "设备ID")
+    private Long equipmentId;
+
+    @Schema(description = "设备编码")
+    private String equipmentCode;
+
+    @Schema(description = "设备名称")
+    private String equipmentName;
+
+    @Schema(description = "设备类型:1-直流设备 2-交流设备 3-交直流一体设备 4-无线设备 5-其他")
+    private Integer equipmentType;
+
+    @Schema(description = "设备类型名称")
+    private String equipmentTypeName;
+
+    @Schema(description = "车位号")
+    private String parkNo;
+
+    @Schema(description = "终端状态:0-离网 1-空闲 2-占用(未充电) 3-占用(充电中) 4-占用(预约锁定) 255-故障")
+    private Integer status;
+
+    @Schema(description = "终端状态名称")
+    private String statusName;
+
+    @Schema(description = "接口类型:1-家用插座 2-交流接口插座 3-交流接口插头 4-直流接口枪头 5-无线充电座 6-其他")
+    private Integer connectorType;
+
+    @Schema(description = "接口类型名称")
+    private String connectorTypeName;
+
+    @Schema(description = "额定电压上限(V)")
+    private Integer voltageUpperLimits;
+
+    @Schema(description = "额定电压下限(V)")
+    private Integer voltageLowerLimits;
+
+    @Schema(description = "额定电流(A)")
+    private Integer current;
+
+    @Schema(description = "额定功率(kW)")
+    private BigDecimal power;
+
+    @Schema(description = "国家标准:1-2011 2-2015")
+    private Integer nationalStandard;
+
+    @Schema(description = "国家标准名称")
+    private String nationalStandardName;
+
+    @Schema(description = "当前电流(A),仅充电中时有值")
+    private BigDecimal currentCurrent;
+
+    @Schema(description = "当前电压(V),仅充电中时有值")
+    private BigDecimal currentVoltage;
+
+    @Schema(description = "当前功率(kW),仅充电中时有值")
+    private BigDecimal currentPower;
+
+    @Schema(description = "电池剩余电量SOC(%),仅充电中时有值")
+    private Integer soc;
+
+    @Schema(description = "当前价格(元/度)")
+    private BigDecimal currentPrice;
+
+    @Schema(description = "企业价格(元/度),仅企业用户且有企业价时返回")
+    private BigDecimal enterprisePrice;
+
+    @Schema(description = "当前时段描述")
+    private String currentPeriodDesc;
+
+    @Schema(description = "提示语/停车费说明")
+    private String parkingTips;
+
+    @Schema(description = "最后更新时间")
+    private String lastUpdateTime;
+}

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

@@ -9,6 +9,7 @@ import com.zsElectric.boot.business.model.vo.BannerInfoVO;
 import com.zsElectric.boot.business.model.vo.StationInfoMapVO;
 import com.zsElectric.boot.business.model.vo.StationInfoVO;
 import com.zsElectric.boot.business.model.vo.applet.AppletChargingCostVO;
+import com.zsElectric.boot.business.model.vo.applet.AppletConnectorDetailVO;
 import com.zsElectric.boot.business.model.vo.applet.AppletStationSearchVO;
 
 import java.math.BigDecimal;
@@ -73,4 +74,11 @@ public interface AppletHomeService {
      */
     List<AppletStationSearchVO> searchStations(String keyword, BigDecimal longitude, BigDecimal latitude);
 
+    /**
+     * 获取充电设备接口详情
+     * @param connectorId 充电设备接口ID
+     * @return 设备接口详情
+     */
+    AppletConnectorDetailVO getConnectorDetail(Long connectorId);
+
 }

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

@@ -29,6 +29,7 @@ import com.zsElectric.boot.business.model.vo.BannerInfoVO;
 import com.zsElectric.boot.business.model.vo.StationInfoMapVO;
 import com.zsElectric.boot.business.model.vo.StationInfoVO;
 import com.zsElectric.boot.business.model.vo.applet.AppletChargingCostVO;
+import com.zsElectric.boot.business.model.vo.applet.AppletConnectorDetailVO;
 import com.zsElectric.boot.business.model.vo.applet.AppletStationSearchVO;
 import com.zsElectric.boot.business.service.AppletHomeService;
 import com.zsElectric.boot.business.converter.BannerInfoConverter;
@@ -674,4 +675,198 @@ public class AppletHomeServiceImpl implements AppletHomeService {
         // 调用Mapper查询
         return thirdPartyStationInfoMapper.searchStations(keyword.trim(), longitude, latitude);
     }
+
+    @Override
+    public AppletConnectorDetailVO getConnectorDetail(Long connectorId) {
+        // 查询充电接口信息
+        ThirdPartyConnectorInfo connectorInfo = thirdPartyConnectorInfoMapper.selectById(connectorId);
+        if (connectorInfo == null) {
+            log.warn("充电接口不存在,connectorId: {}", connectorId);
+            return null;
+        }
+
+        // 构建返回VO
+        AppletConnectorDetailVO result = new AppletConnectorDetailVO();
+        result.setConnectorId(connectorId);
+        result.setConnectorCode(connectorInfo.getConnectorId());
+        result.setConnectorName(connectorInfo.getConnectorName());
+        result.setConnectorType(connectorInfo.getConnectorType());
+        result.setConnectorTypeName(getConnectorTypeName(connectorInfo.getConnectorType()));
+        result.setVoltageUpperLimits(connectorInfo.getVoltageUpperLimits());
+        result.setVoltageLowerLimits(connectorInfo.getVoltageLowerLimits());
+        result.setCurrent(connectorInfo.getCurrent());
+        result.setPower(connectorInfo.getPower());
+        result.setParkNo(connectorInfo.getParkNo());
+        result.setNationalStandard(connectorInfo.getNationalStandard());
+        result.setNationalStandardName(getNationalStandardName(connectorInfo.getNationalStandard()));
+        result.setStatus(connectorInfo.getStatus());
+        result.setStatusName(getStatusName(connectorInfo.getStatus()));
+
+        // 查询设备信息
+        ThirdPartyEquipmentInfo equipmentInfo = thirdPartyEquipmentInfoMapper.selectOne(
+                new LambdaQueryWrapper<ThirdPartyEquipmentInfo>()
+                        .eq(ThirdPartyEquipmentInfo::getEquipmentId, connectorInfo.getEquipmentId())
+                        .last("LIMIT 1")
+        );
+
+        if (equipmentInfo != null) {
+            result.setEquipmentId(equipmentInfo.getId());
+            result.setEquipmentCode(equipmentInfo.getEquipmentId());
+            result.setEquipmentName(equipmentInfo.getEquipmentName());
+            result.setEquipmentType(equipmentInfo.getEquipmentType());
+            result.setEquipmentTypeName(getEquipmentTypeName(equipmentInfo.getEquipmentType()));
+
+            // 查询充电站信息
+            ThirdPartyStationInfo stationInfo = thirdPartyStationInfoMapper.selectOne(
+                    new LambdaQueryWrapper<ThirdPartyStationInfo>()
+                            .eq(ThirdPartyStationInfo::getStationId, equipmentInfo.getStationId())
+                            .last("LIMIT 1")
+            );
+
+            if (stationInfo != null) {
+                result.setStationId(stationInfo.getId());
+                result.setStationName(stationInfo.getStationName());
+                result.setStationAddress(stationInfo.getAddress());
+                result.setParkingTips(stationInfo.getStationTips());
+
+                // 获取当前价格信息
+                String currentTime = LocalTime.now().format(TIME_FORMATTER);
+                
+                // 查询价格策略
+                ThirdPartyEquipmentPricePolicy pricePolicy = thirdPartyEquipmentPricePolicyMapper.selectOne(
+                        new LambdaQueryWrapper<ThirdPartyEquipmentPricePolicy>()
+                                .eq(ThirdPartyEquipmentPricePolicy::getConnectorId, connectorInfo.getConnectorId())
+                                .eq(ThirdPartyEquipmentPricePolicy::getIsDeleted, 0)
+                                .last("LIMIT 1")
+                );
+
+                if (pricePolicy != null) {
+                    // 查询当前时段的价格
+                    List<ThirdPartyPolicyInfo> policyInfoList = thirdPartyPolicyInfoMapper.selectList(
+                            new LambdaQueryWrapper<ThirdPartyPolicyInfo>()
+                                    .eq(ThirdPartyPolicyInfo::getPricePolicyId, pricePolicy.getId())
+                                    .eq(ThirdPartyPolicyInfo::getIsDeleted, 0)
+                                    .le(ThirdPartyPolicyInfo::getStartTime, currentTime)
+                                    .orderByDesc(ThirdPartyPolicyInfo::getStartTime)
+                                    .last("LIMIT 1")
+                    );
+
+                    if (!policyInfoList.isEmpty()) {
+                        ThirdPartyPolicyInfo currentPolicyInfo = policyInfoList.get(0);
+                        BigDecimal elecPrice = currentPolicyInfo.getElecPrice() != null ? currentPolicyInfo.getElecPrice() : BigDecimal.ZERO;
+                        BigDecimal servicePrice = currentPolicyInfo.getServicePrice() != null ? currentPolicyInfo.getServicePrice() : BigDecimal.ZERO;
+                        result.setCurrentPrice(elecPrice.add(servicePrice));
+                        result.setCurrentPeriodDesc(getPeriodFlagName(currentPolicyInfo.getPeriodFlag()));
+
+                        // 获取当前登录用户ID,查询是否为企业用户
+                        Long userId = SecurityUtils.getUserId();
+                        if (userId != null) {
+                            UserFirm userFirm = userFirmMapper.selectOne(
+                                    new LambdaQueryWrapper<UserFirm>()
+                                            .eq(UserFirm::getUserId, userId)
+                                            .last("LIMIT 1")
+                            );
+                            
+                            if (userFirm != null) {
+                                // 查询企业价格
+                                PolicyFee policyFee = policyFeeMapper.selectOne(
+                                        new LambdaQueryWrapper<PolicyFee>()
+                                                .eq(PolicyFee::getStationInfoId, stationInfo.getId())
+                                                .eq(PolicyFee::getSalesType, 1) // 1-企业
+                                                .eq(PolicyFee::getFirmId, userFirm.getFirmId())
+                                                .eq(PolicyFee::getStartTime, currentPolicyInfo.getStartTime())
+                                                .eq(PolicyFee::getIsDeleted, 0)
+                                                .last("LIMIT 1")
+                                );
+                                
+                                if (policyFee != null) {
+                                    // 企业价格 = 电费 + 服务费 + 运营费 + 综合销售费
+                                    BigDecimal opFee = policyFee.getOpFee() != null ? policyFee.getOpFee() : BigDecimal.ZERO;
+                                    BigDecimal compSalesFee = policyFee.getCompSalesFee() != null ? policyFee.getCompSalesFee() : BigDecimal.ZERO;
+                                    BigDecimal enterprisePrice = elecPrice.add(servicePrice).add(opFee).add(compSalesFee);
+                                    result.setEnterprisePrice(enterprisePrice);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        // 如果是充电中状态,查询实时充电数据
+        if (connectorInfo.getStatus() != null && connectorInfo.getStatus() == 3) {
+            // 查询正在充电的订单
+            ThirdPartyChargeStatus chargeStatus = thirdPartyChargeStatusMapper.selectOne(
+                    new LambdaQueryWrapper<ThirdPartyChargeStatus>()
+                            .eq(ThirdPartyChargeStatus::getConnectorId, connectorInfo.getConnectorId())
+                            .eq(ThirdPartyChargeStatus::getStartChargeSeqStat, 2) // 充电中
+                            .orderByDesc(ThirdPartyChargeStatus::getUpdateTime)
+                            .last("LIMIT 1")
+            );
+
+            if (chargeStatus != null) {
+                // 电流取A相电流
+                result.setCurrentCurrent(chargeStatus.getCurrentA());
+                // 电压取A相电压
+                result.setCurrentVoltage(chargeStatus.getVoltageA());
+                // 功率 = 电压 * 电流 / 1000 (转换为kW)
+                if (chargeStatus.getVoltageA() != null && chargeStatus.getCurrentA() != null) {
+                    BigDecimal power = chargeStatus.getVoltageA()
+                            .multiply(chargeStatus.getCurrentA())
+                            .divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP);
+                    result.setCurrentPower(power);
+                }
+                result.setSoc(chargeStatus.getSoc());
+            }
+        }
+
+        // 设置最后更新时间
+        if (connectorInfo.getUpdateTime() != null) {
+            result.setLastUpdateTime(connectorInfo.getUpdateTime().toString());
+        }
+
+        return result;
+    }
+
+    /**
+     * 获取接口类型名称
+     */
+    private String getConnectorTypeName(Integer connectorType) {
+        if (connectorType == null) {
+            return "未知";
+        }
+        switch (connectorType) {
+            case 1:
+                return "家用插座";
+            case 2:
+                return "交流接口插座";
+            case 3:
+                return "交流接口插头";
+            case 4:
+                return "直流接口枪头";
+            case 5:
+                return "无线充电座";
+            case 6:
+                return "其他";
+            default:
+                return "未知";
+        }
+    }
+
+    /**
+     * 获取国家标准名称
+     */
+    private String getNationalStandardName(Integer nationalStandard) {
+        if (nationalStandard == null) {
+            return "未知";
+        }
+        switch (nationalStandard) {
+            case 1:
+                return "2011版";
+            case 2:
+                return "2015版";
+            default:
+                return "未知";
+        }
+    }
 }