Pārlūkot izejas kodu

refactor(charging): 优化第三方充电设备信息查询逻辑

- 删除了对设备状态的查询字段和VO属性,简化查询条件
- 迁移分页查询逻辑至Mapper层,使用联表查询提高查询效率
- 移除原Service层复杂的实体转换及关联查询,简化代码结构
- 更新application-dev.yml配置,调整业务控制器包路径
- 修改部分条件谓词,避免无效或默认值的查询过滤
SheepHy 4 dienas atpakaļ
vecāks
revīzija
16cb0242c2

+ 14 - 0
src/main/java/com/zsElectric/boot/charging/mapper/ThirdPartyEquipmentInfoMapper.java

@@ -1,8 +1,13 @@
 package com.zsElectric.boot.charging.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zsElectric.boot.charging.entity.ThirdPartyEquipmentInfo;
+import com.zsElectric.boot.charging.model.query.ThirdPartyEquipmentInfoQuery;
+import com.zsElectric.boot.charging.model.vo.ThirdPartyEquipmentInfoVO;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 第三方充电设备信息Mapper接口
@@ -12,4 +17,13 @@ import org.apache.ibatis.annotations.Mapper;
  */
 @Mapper
 public interface ThirdPartyEquipmentInfoMapper extends BaseMapper<ThirdPartyEquipmentInfo> {
+
+    /**
+     * 分页查询充电桩信息(联表查询)
+     *
+     * @param page 分页对象
+     * @param query 查询条件
+     * @return 充电桩信息分页列表
+     */
+    IPage<ThirdPartyEquipmentInfoVO> selectEquipmentInfoPage(Page<ThirdPartyEquipmentInfoVO> page, @Param("query") ThirdPartyEquipmentInfoQuery query);
 }

+ 0 - 3
src/main/java/com/zsElectric/boot/charging/model/query/ThirdPartyEquipmentInfoQuery.java

@@ -31,9 +31,6 @@ public class ThirdPartyEquipmentInfoQuery extends BasePageQuery {
     @Schema(description = "设备类型")
     private Integer equipmentType;
 
-    @Schema(description = "设备状态")
-    private String deviceStatus;
-
     @Schema(description = "接口类型")
     private Integer connectorType;
 

+ 0 - 3
src/main/java/com/zsElectric/boot/charging/model/vo/ThirdPartyEquipmentInfoVO.java

@@ -32,9 +32,6 @@ public class ThirdPartyEquipmentInfoVO {
     @Schema(description = "接口类型")
     private Integer connectorType;
 
-    @Schema(description = "设备状态")
-    private String deviceStatus;
-
     @Schema(description = "充电总功率")
     private BigDecimal power;
 

+ 3 - 52
src/main/java/com/zsElectric/boot/charging/service/impl/ThirdPartyEquipmentInfoServiceImpl.java

@@ -1,18 +1,12 @@
 package com.zsElectric.boot.charging.service.impl;
 
-import cn.hutool.core.util.StrUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.zsElectric.boot.charging.entity.ThirdPartyConnectorInfo;
-import com.zsElectric.boot.charging.entity.ThirdPartyEquipmentInfo;
-import com.zsElectric.boot.charging.mapper.ThirdPartyConnectorInfoMapper;
 import com.zsElectric.boot.charging.mapper.ThirdPartyEquipmentInfoMapper;
 import com.zsElectric.boot.charging.model.query.ThirdPartyEquipmentInfoQuery;
 import com.zsElectric.boot.charging.model.vo.ThirdPartyEquipmentInfoVO;
 import com.zsElectric.boot.charging.service.ThirdPartyEquipmentInfoService;
 import lombok.RequiredArgsConstructor;
-import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 /**
@@ -26,56 +20,13 @@ import org.springframework.stereotype.Service;
 public class ThirdPartyEquipmentInfoServiceImpl implements ThirdPartyEquipmentInfoService {
 
     private final ThirdPartyEquipmentInfoMapper equipmentInfoMapper;
-    private final ThirdPartyConnectorInfoMapper connectorInfoMapper;
 
     @Override
     public IPage<ThirdPartyEquipmentInfoVO> getEquipmentInfoPage(ThirdPartyEquipmentInfoQuery queryParams) {
         // 构建分页
-        Page<ThirdPartyEquipmentInfo> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
+        Page<ThirdPartyEquipmentInfoVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
 
-        // 构建查询条件
-        LambdaQueryWrapper<ThirdPartyEquipmentInfo> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(StrUtil.isNotBlank(queryParams.getEquipmentId()), ThirdPartyEquipmentInfo::getEquipmentId, queryParams.getEquipmentId())
-                .like(StrUtil.isNotBlank(queryParams.getEquipmentName()), ThirdPartyEquipmentInfo::getEquipmentName, queryParams.getEquipmentName())
-                .eq(StrUtil.isNotBlank(queryParams.getStationId()), ThirdPartyEquipmentInfo::getStationId, queryParams.getStationId())
-                .like(StrUtil.isNotBlank(queryParams.getStationName()), ThirdPartyEquipmentInfo::getStationName, queryParams.getStationName())
-                .eq(queryParams.getEquipmentType() != null, ThirdPartyEquipmentInfo::getEquipmentType, queryParams.getEquipmentType())
-                .eq(StrUtil.isNotBlank(queryParams.getDeviceStatus()), ThirdPartyEquipmentInfo::getDeviceStatus, queryParams.getDeviceStatus())
-                .eq(StrUtil.isNotBlank(queryParams.getParkNo()), ThirdPartyEquipmentInfo::getParkNo, queryParams.getParkNo())
-                .eq(queryParams.getNationalStandard() != null, ThirdPartyEquipmentInfo::getNationalStandard, queryParams.getNationalStandard())
-                .orderByDesc(ThirdPartyEquipmentInfo::getUpdateTime);
-
-        // 查询设备信息
-        Page<ThirdPartyEquipmentInfo> equipmentPage = equipmentInfoMapper.selectPage(page, queryWrapper);
-
-        // 实体转换并填充接口信息
-        Page<ThirdPartyEquipmentInfoVO> voPage = new Page<>(equipmentPage.getCurrent(), equipmentPage.getSize(), equipmentPage.getTotal());
-        voPage.setRecords(equipmentPage.getRecords().stream().map(entity -> {
-            ThirdPartyEquipmentInfoVO vo = new ThirdPartyEquipmentInfoVO();
-            BeanUtils.copyProperties(entity, vo);
-
-            // 根据接口类型查询参数,查询接口信息
-            LambdaQueryWrapper<ThirdPartyConnectorInfo> connectorWrapper = new LambdaQueryWrapper<>();
-            connectorWrapper.eq(ThirdPartyConnectorInfo::getEquipmentId, entity.getEquipmentId())
-                    .eq(ThirdPartyConnectorInfo::getStationId, entity.getStationId());
-            if (queryParams.getConnectorType() != null) {
-                connectorWrapper.eq(ThirdPartyConnectorInfo::getConnectorType, queryParams.getConnectorType());
-            }
-            connectorWrapper.last("LIMIT 1");
-
-            ThirdPartyConnectorInfo connectorInfo = connectorInfoMapper.selectOne(connectorWrapper);
-            if (connectorInfo != null) {
-                vo.setConnectorId(connectorInfo.getConnectorId());
-                vo.setConnectorName(connectorInfo.getConnectorName());
-                vo.setConnectorType(connectorInfo.getConnectorType());
-                vo.setVoltageUpperLimits(connectorInfo.getVoltageUpperLimits());
-                vo.setVoltageLowerLimits(connectorInfo.getVoltageLowerLimits());
-                vo.setCurrent(connectorInfo.getCurrent());
-            }
-
-            return vo;
-        }).toList());
-
-        return voPage;
+        // 调用Mapper联表查询
+        return equipmentInfoMapper.selectEquipmentInfoPage(page, queryParams);
     }
 }

+ 2 - 2
src/main/java/com/zsElectric/boot/charging/service/impl/ThirdPartyStationInfoServiceImpl.java

@@ -36,8 +36,8 @@ public class ThirdPartyStationInfoServiceImpl implements ThirdPartyStationInfoSe
                 .like(StrUtil.isNotBlank(queryParams.getStationName()), ThirdPartyStationInfo::getStationName, queryParams.getStationName())
                 .eq(StrUtil.isNotBlank(queryParams.getAreaCode()), ThirdPartyStationInfo::getAreaCode, queryParams.getAreaCode())
                 .eq(StrUtil.isNotBlank(queryParams.getEquipmentOwnerId()), ThirdPartyStationInfo::getEquipmentOwnerId, queryParams.getEquipmentOwnerId())
-                .eq(queryParams.getStationStatus() != null, ThirdPartyStationInfo::getStationStatus, queryParams.getStationStatus())
-                .eq(queryParams.getStationType() != null, ThirdPartyStationInfo::getStationType, queryParams.getStationType())
+                .eq(queryParams.getStationStatus() != null && queryParams.getStationStatus() != 0, ThirdPartyStationInfo::getStationStatus, queryParams.getStationStatus())
+                .eq(queryParams.getStationType() != null && queryParams.getStationType() != 0, ThirdPartyStationInfo::getStationType, queryParams.getStationType())
                 .eq(StrUtil.isNotBlank(queryParams.getServiceTel()), ThirdPartyStationInfo::getServiceTel, queryParams.getServiceTel())
                 .orderByDesc(ThirdPartyStationInfo::getUpdateTime);
 

+ 1 - 0
src/main/resources/application-dev.yml

@@ -214,6 +214,7 @@ springdoc:
         - com.zsElectric.boot.platform.file.controller
         - com.zsElectric.boot.platform.codegen.controller
         - com.zsElectric.boot.charging.controller
+        - com.zsElectric.boot.business.controller
   default-flat-param-object: true
 
 # knife4j 接口文档配置