Browse Source

feat(property): 实现房屋信息分页查询功能

- 在 ASimplifiedHouseInfoController 中添加分页查询接口
- 在 ASimplifiedHouseInfoDto 中添加 pageNum 和 pageSize 字段
- 修改 ASimplifiedHouseInfoMapper 接口,添加分页查询方法
- 更新 ASimplifiedHouseInfoMapper.xml,实现分页查询的 SQL 逻辑
- 修改 ASimplifiedHouseInfoService 接口,添加分页查询方法
- 实现 ASimplifiedHouseInfoServiceImpl 中的分页查询逻辑
林仔 10 tháng trước cách đây
mục cha
commit
0fc4158ab6

+ 2 - 2
src/main/java/com/zksy/controller/property/ASimplifiedHouseInfoController.java

@@ -37,8 +37,8 @@ public class ASimplifiedHouseInfoController {
     }
     @GetMapping("/getList")
     @ApiOperation(value = "房屋查询")
-    public AjaxResult getList(ASimplifiedHouseInfoDto entity){
-        return AjaxResult.success(service.getList( entity));
+    public AjaxResult getList(@ModelAttribute ASimplifiedHouseInfoDto entity){
+        return AjaxResult.success(service.getListPage( entity));
     }
     @GetMapping("/getById/{id}")
     @ApiOperation(value = "根据Id查询房屋信息")

+ 2 - 0
src/main/java/com/zksy/controller/property/dto/ASimplifiedHouseInfoDto.java

@@ -18,4 +18,6 @@ public class ASimplifiedHouseInfoDto {
     private String rentRangeMax;
     private String areaMin;
     private String areaMax;
+    private Integer pageNum;
+    private Integer pageSize;
 }

+ 3 - 2
src/main/java/com/zksy/property/mapper/ASimplifiedHouseInfoMapper.java

@@ -1,9 +1,10 @@
 package com.zksy.property.mapper;
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.zksy.controller.property.dto.ASimplifiedHouseInfoDto;
 import com.zksy.controller.property.vo.ASimplifiedHouseInfoVo;
 import com.zksy.property.domain.ASimplifiedHouseInfo;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -14,7 +15,7 @@ import java.util.List;
 * @Entity com.zksy.property.domain.ASimplifiedHouseInfo
 */
 public interface ASimplifiedHouseInfoMapper extends BaseMapper<ASimplifiedHouseInfo> {
-    public List<ASimplifiedHouseInfoVo> getList(ASimplifiedHouseInfoDto entity);
+    public List<ASimplifiedHouseInfoVo> getListPage(@Param("entity") ASimplifiedHouseInfoDto entity,Integer offset,Integer limit);
 }
 
 

+ 1 - 1
src/main/java/com/zksy/property/service/ASimplifiedHouseInfoService.java

@@ -17,7 +17,7 @@ import java.util.List;
 public interface ASimplifiedHouseInfoService extends IService<ASimplifiedHouseInfo> {
     Page<ASimplifiedHouseInfo> findByPage(long pageNum, long pageSize, String assetType,String building,String houseName,String status);
     List<ASimplifiedHouseInfo> getASimplifiedHouseInfoList(String assetType,String building,String houseName,String status);
-    List<ASimplifiedHouseInfoVo> getList(ASimplifiedHouseInfoDto entity);
+    Page<ASimplifiedHouseInfoVo> getListPage(ASimplifiedHouseInfoDto entity);
 
     HouseInfoVo getHouseDetailInfo(String simplifiedHouseId);
 

+ 23 - 3
src/main/java/com/zksy/property/service/impl/ASimplifiedHouseInfoServiceImpl.java

@@ -27,6 +27,8 @@ import java.util.stream.Collectors;
 @Service
 public class ASimplifiedHouseInfoServiceImpl extends ServiceImpl<ASimplifiedHouseInfoMapper, ASimplifiedHouseInfo>
     implements ASimplifiedHouseInfoService{
+    @Autowired
+    private ASimplifiedHouseInfoMapper houseInfoMapper;
     @Override
     public Page<ASimplifiedHouseInfo> findByPage(long pageNum, long pageSize, String assetType, String building, String houseName, String status) {
         Page<ASimplifiedHouseInfo> page = new Page<>(pageNum,pageSize);
@@ -50,9 +52,27 @@ public class ASimplifiedHouseInfoServiceImpl extends ServiceImpl<ASimplifiedHous
     }
 
     @Override
-    public List<ASimplifiedHouseInfoVo> getList(ASimplifiedHouseInfoDto entity) {
-        List<ASimplifiedHouseInfoVo> list = this.baseMapper.getList(entity);
-        return list;
+    public Page<ASimplifiedHouseInfoVo> getListPage(ASimplifiedHouseInfoDto entity) {
+        int offset = 0;
+        // 计算偏移量
+        if (entity.getPageNum() != null && entity.getPageSize() != null) {
+            offset = (entity.getPageNum() - 1) * entity.getPageSize();
+        }
+
+        // 创建分页对象
+        Page<ASimplifiedHouseInfoVo> page = new Page<>(
+                entity.getPageNum() != null ? entity.getPageNum() : 1,
+                entity.getPageSize() != null ? entity.getPageSize() : 10
+        );
+
+        // 执行查询
+        List<ASimplifiedHouseInfoVo> list = houseInfoMapper.getListPage(entity,offset,entity.getPageSize());
+
+        // 设置分页数据
+        page.setRecords(list);
+        page.setTotal(houseInfoMapper.getListPage(entity,offset,entity.getPageSize()).size());
+
+        return page;
     }
 
     @Autowired

+ 34 - 24
src/main/resources/mapper/property/ASimplifiedHouseInfoMapper.xml

@@ -23,39 +23,49 @@
         status,rent_range,create_time,
         update_time
     </sql>
-    <select id="getList" resultType="com.zksy.controller.property.vo.ASimplifiedHouseInfoVo">
-        select a.*,b.area from a_simplified_house_info a LEFT JOIN a_house_info_detail b ON a.id = b.simplified_house_id
+    <select id="getListPage" resultType="com.zksy.controller.property.vo.ASimplifiedHouseInfoVo">
+        SELECT a.*, b.area
+        FROM a_simplified_house_info a
+        LEFT JOIN a_house_info_detail b ON a.id = b.simplified_house_id
         <where>
             <if test="entity.building != null and entity.building != ''">
-                and a.building = #{entity.building}
+                AND a.building = #{entity.building}
             </if>
-            <if test="entity.houseName != null and entity.houseName != ''">
-                and a.floor like concat('%',#{entity.floor},'%')
+            <if test="entity.floor != null and entity.floor != ''">
+                AND a.floor LIKE CONCAT(#{entity.floor}, '%')
             </if>
-            <if test="entity.rentRangeMin != null and entity.rentRangeMin != ''" >
-               and a.rent_range >= #{entity.rentRangeMin}
+            <if test="entity.rentRangeMin != null">
+                AND a.rent_range >= COALESCE(#{entity.rentRangeMin}, a.rent_range)
             </if>
-            <if test="entity.rentRangeMax != null and entity.rentRangeMax != ''">
-                and a.rent_range &lt;= #{entity.rentRangeMax}
+            <if test="entity.rentRangeMax != null">
+                AND a.rent_range &lt;= COALESCE(#{entity.rentRangeMax}, a.rent_range)
             </if>
-            <if test="entity.areaMin != null and entity.areaMin != ''">
-                and b.area >= #{entity.areaMin}
+            <if test="entity.areaMin != null">
+                AND b.area >= COALESCE(#{entity.areaMin}, b.area)
             </if>
-            <if test="entity.areaMax != null and entity.areaMax != ''">
-                and b.area &lt;= #{entity.areaMax}
+            <if test="entity.areaMax != null">
+                AND b.area &lt;= COALESCE(#{entity.areaMax}, b.area)
             </if>
         </where>
-        <if test="entity.sortSearch != null and entity.sortSearch != '' and entity.sortSearch = '1'">
-            order by a.rent_range  desc
-        </if>
-        <if test="entity.sortSearch != null and entity.sortSearch != '' and entity.sortSearch = '2'">
-            order by a.rent_range  asc
-        </if>
-        <if test="entity.sortSearch != null and entity.sortSearch != '' and entity.sortSearch = '3'">
-            order by b.area  desc
-        </if>
-        <if test="entity.sortSearch != null and entity.sortSearch != '' and entity.sortSearch = '4'">
-            order by b.area  asc
+        <choose>
+            <when test="entity.sortSearch == '1'">
+                ORDER BY a.rent_range DESC
+            </when>
+            <when test="entity.sortSearch == '2'">
+                ORDER BY a.rent_range ASC
+            </when>
+            <when test="entity.sortSearch == '3'">
+                ORDER BY b.area DESC
+            </when>
+            <when test="entity.sortSearch == '4'">
+                ORDER BY b.area ASC
+            </when>
+            <otherwise>
+                ORDER BY a.create_time DESC
+            </otherwise>
+        </choose>
+        <if test="offset != null and limit != null">
+            LIMIT #{offset}, #{limit}
         </if>
 
     </select>