Browse Source

泵站相关接口优化

王苗苗 3 months ago
parent
commit
074b3427c7

+ 1 - 8
slibra-admin/src/main/java/com/slibra/web/controller/business/FrontController.java

@@ -54,8 +54,7 @@ public class FrontController extends BaseController {
     @Autowired
     private TPumpingStationNeighbourhoodNumberMapper tPumpingStationNeighbourhoodNumberMapper;
 
-    @Autowired
-    private ITNeighborhoodService tNeighborhoodService;
+
 
 
 
@@ -86,12 +85,6 @@ public class FrontController extends BaseController {
     }
 
 
-    //2024年11月12日11:17:56 新增接口 通过小区ID,查询楼号和泵站的关联关系
-    @GetMapping("/getPumpingStationAndNeighbourhoodBuildingsById")
-    private R<List<PumpAndNumber>> getPumpingStationAndNeighbourhoodBuildingsById(Long id){
-        log.info("进入了 通过小区ID,查询楼号和泵站的关联关系的接口 ");
-        return R.ok(tNeighborhoodService.getPumpingStationAndNeighbourhoodBuildingsById(id));
-    }
 
 //    /**
 //     * 获取大屏的实时数据 + 统计数据

+ 8 - 0
slibra-admin/src/main/java/com/slibra/web/controller/business/TNeighborhoodController.java

@@ -110,5 +110,13 @@ public class TNeighborhoodController extends BaseController
     }
 
 
+    //2024年11月12日11:17:56 新增接口 通过小区ID,查询楼号和泵站的关联关系
+    @GetMapping("/getPumpingStationAndNeighbourhoodBuildingsById")
+    private R<List<PumpAndNumber>> getPumpingStationAndNeighbourhoodBuildingsById(Long id){
+        log.info("进入了 通过小区ID,查询楼号和泵站的关联关系的接口 ");
+        return R.ok(tNeighborhoodService.getPumpingStationAndNeighbourhoodBuildingsById(id));
+    }
+
+
 
 }

+ 7 - 0
slibra-system/src/main/java/com/slibra/business/domain/TPumpingStation.java

@@ -1,5 +1,6 @@
 package com.slibra.business.domain;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -51,10 +52,16 @@ public class TPumpingStation extends BaseEntity
     private String sort;
 
     /** 删除标志(0代表存在 2代表删除) */
+    @JsonIgnore
     private Long delFlag;
 
     /** 乐观锁 */
     @Excel(name = "乐观锁")
+    @JsonIgnore
     private Long revision;
 
+    //额外查询的信息
+    //关联的小区  复兴小区(A#、B#、C#),康华时代(1#、2#、3#)
+    private String neighbourhoodAndBuildings;
+
 }

+ 3 - 0
slibra-system/src/main/java/com/slibra/business/mapper/TPumpingStationMapper.java

@@ -2,6 +2,7 @@ package com.slibra.business.mapper;
 
 import java.util.List;
 import com.slibra.business.domain.TPumpingStation;
+import com.slibra.business.res.NeighbourhoodAndBuilding;
 
 /**
  * 泵站Mapper接口
@@ -58,4 +59,6 @@ public interface TPumpingStationMapper
      * @return 结果
      */
     public int deleteTPumpingStationByIds(Long[] ids);
+
+    List<NeighbourhoodAndBuilding> getNeighbourhoodAndBuildingByPumpingId(Long id);
 }

+ 29 - 0
slibra-system/src/main/java/com/slibra/business/res/NeighbourhoodAndBuilding.java

@@ -0,0 +1,29 @@
+package com.slibra.business.res;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Builder
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class NeighbourhoodAndBuilding {
+
+    //关联的中间表的ID,唯一的一条记录
+    @JsonIgnore
+    private Long id;
+
+    //小区名字
+    private String neighborhoodName;
+
+    //楼号名称
+    private String neighborhoodBuildingName;
+
+
+
+
+}

+ 25 - 0
slibra-system/src/main/java/com/slibra/business/res/NeighbourhoodAndNumber.java

@@ -0,0 +1,25 @@
+package com.slibra.business.res;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Builder
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class NeighbourhoodAndNumber {
+
+
+    //小区名称
+    private String neighbourhoodName;
+
+    //关联的楼号名称
+    private String buildingsNames;
+
+
+
+
+}

+ 44 - 1
slibra-system/src/main/java/com/slibra/business/service/impl/TPumpingStationServiceImpl.java

@@ -1,12 +1,21 @@
 package com.slibra.business.service.impl;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import com.slibra.business.res.NeighbourhoodAndBuilding;
+import com.slibra.business.res.NeighbourhoodAndNumber;
+import com.slibra.business.res.PumpAndBuildingNumberNames;
+import com.slibra.business.res.PumpAndNumber;
 import com.slibra.common.utils.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.slibra.business.mapper.TPumpingStationMapper;
 import com.slibra.business.domain.TPumpingStation;
 import com.slibra.business.service.ITPumpingStationService;
+import org.springframework.util.CollectionUtils;
 
 /**
  * 泵站Service业务层处理
@@ -41,7 +50,41 @@ public class TPumpingStationServiceImpl implements ITPumpingStationService
     @Override
     public List<TPumpingStation> selectTPumpingStationList(TPumpingStation tPumpingStation)
     {
-        return tPumpingStationMapper.selectTPumpingStationList(tPumpingStation);
+        List<TPumpingStation> pumpingStations = tPumpingStationMapper.selectTPumpingStationList(tPumpingStation);
+        //2024年11月12日15:51:43 返回泵站关联的小区信息
+        if(!CollectionUtils.isEmpty(pumpingStations)){
+            for (TPumpingStation pumpingStation : pumpingStations) {
+                this.addNeighbourhoodAndBuildings(pumpingStation);
+            }
+        }
+        return pumpingStations;
+    }
+
+    /**
+     *  查询泵站关联的小区信息
+     * @param pumpingStation
+     */
+    private void addNeighbourhoodAndBuildings(TPumpingStation pumpingStation) {
+        List<NeighbourhoodAndBuilding> list = this.tPumpingStationMapper.getNeighbourhoodAndBuildingByPumpingId(pumpingStation.getId());
+        if(!CollectionUtils.isEmpty(list)){
+            Map<String, List<NeighbourhoodAndBuilding>> collect = list.stream().collect(Collectors.groupingBy(NeighbourhoodAndBuilding::getNeighborhoodName));
+            List<NeighbourhoodAndNumber> result = new ArrayList<>(collect.size());
+            collect.forEach((key, value) -> {
+                NeighbourhoodAndNumber neighbourhoodAndNumber = new NeighbourhoodAndNumber();
+                neighbourhoodAndNumber.setNeighbourhoodName(key);
+                neighbourhoodAndNumber.setBuildingsNames(value.stream().map(NeighbourhoodAndBuilding::getNeighborhoodBuildingName).collect(Collectors.joining("、")));
+                result.add(neighbourhoodAndNumber);
+            });
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < result.size(); i++) {
+                NeighbourhoodAndNumber neighbourhoodAndNumber = result.get(i);
+                sb.append(neighbourhoodAndNumber.getNeighbourhoodName()).append("(").append(neighbourhoodAndNumber.getBuildingsNames()).append(")");
+                if (i != result.size() - 1) {
+                    sb.append(",");
+                }
+            }
+            pumpingStation.setNeighbourhoodAndBuildings(sb.toString());
+        }
     }
 
     /**

+ 17 - 0
slibra-system/src/main/resources/mapper/business/TPumpingStationMapper.xml

@@ -112,4 +112,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <!-- 2024年11月12日16:05:46 下面是新增的SQL,不允许覆盖 -->
+    <select id="getNeighbourhoodAndBuildingByPumpingId" resultType="com.slibra.business.res.NeighbourhoodAndBuilding">
+        SELECT
+            tpsnn.id id,
+            tnb.`name` neighborhoodBuildingName,
+            tn.`name` neighborhoodName
+        FROM
+            t_neighborhood_building tnb
+                INNER JOIN t_pumping_station_neighbourhood_number tpsnn ON tpsnn.neighborhood_building_id = tnb.id
+                INNER JOIN t_neighborhood tn ON tn.id = tnb.neighborhood_id
+        WHERE
+            tnb.del_flag = 0
+          AND tpsnn.del_flag = 0
+          AND tn.del_flag = 0
+          AND tpsnn.pumping_station_id = #{id}
+    </select>
 </mapper>