Selaa lähdekoodia

refactor(property): 重构房屋信息查询接口并优化排序逻辑

- 在 ASimplifiedHouseInfoMapper 接口中添加 sortClause 参数
- 修改 ASimplifiedHouseInfoMapper.xml 中的 SQL 查询,使用动态排序
- 更新 ASimplifiedHouseInfoServiceImpl 中的 getListPage 方法,处理排序逻辑- 将 EDepartmentEmployeeStats 中的 ageDistribution 字段类型改为 String
- 更新 EDepartmentEmployeeStatsMapper.xml 中的 ageDistribution 映射类型
林仔 10 kuukautta sitten
vanhempi
commit
309012895a

+ 1 - 1
src/main/java/com/zksy/info/domain/EDepartmentEmployeeStats.java

@@ -75,7 +75,7 @@ public class EDepartmentEmployeeStats implements Serializable {
      */
     @ApiModelProperty("年龄分布")
     @ExcelProperty(value = "年龄分布", index = 6)
-    private Object ageDistribution;
+    private String ageDistribution;
 
     /**
      * 员工总数

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

@@ -15,7 +15,7 @@ import java.util.List;
 * @Entity com.zksy.property.domain.ASimplifiedHouseInfo
 */
 public interface ASimplifiedHouseInfoMapper extends BaseMapper<ASimplifiedHouseInfo> {
-    public List<ASimplifiedHouseInfoVo> getListPage(@Param("entity") ASimplifiedHouseInfoDto entity,Integer offset,Integer limit);
+    public List<ASimplifiedHouseInfoVo> getListPage(@Param("entity") ASimplifiedHouseInfoDto entity,Integer offset,Integer limit,String sortClause);
 }
 
 

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

@@ -55,6 +55,7 @@ public class ASimplifiedHouseInfoServiceImpl extends ServiceImpl<ASimplifiedHous
     @Override
     public Page<ASimplifiedHouseInfoVo> getListPage(ASimplifiedHouseInfoDto entity) {
         int offset = 0;
+        String sortClause = null;
         // 计算偏移量
         if (entity.getPageNum() != null && entity.getPageSize() != null) {
             offset = (entity.getPageNum() - 1) * entity.getPageSize();
@@ -65,13 +66,21 @@ public class ASimplifiedHouseInfoServiceImpl extends ServiceImpl<ASimplifiedHous
                 entity.getPageNum() != null ? entity.getPageNum() : 1,
                 entity.getPageSize() != null ? entity.getPageSize() : 10
         );
-
+        if (entity.getSortSearch() != null) {
+            switch (entity.getSortSearch()) {
+                case "1": sortClause = "a.rent_range DESC"; break;
+                case "2": sortClause = "a.rent_range ASC"; break;
+                case "3": sortClause = "b.area DESC"; break;
+                case "4": sortClause = "b.area ASC"; break;
+                default: sortClause = null;
+            }
+        }
         // 执行查询
-        List<ASimplifiedHouseInfoVo> list = houseInfoMapper.getListPage(entity,offset,entity.getPageSize());
+        List<ASimplifiedHouseInfoVo> list = houseInfoMapper.getListPage(entity,offset,entity.getPageSize(),sortClause);
 
         // 设置分页数据
         page.setRecords(list);
-        page.setTotal(houseInfoMapper.getListPage(entity,offset,entity.getPageSize()).size());
+        page.setTotal(houseInfoMapper.getListPage(entity,offset,entity.getPageSize(),sortClause).size());
 
         return page;
     }

+ 1 - 1
src/main/resources/mapper/info/EDepartmentEmployeeStatsMapper.xml

@@ -12,7 +12,7 @@
             <result property="maleRatio" column="male_ratio" jdbcType="VARCHAR"/>
             <result property="femaleRatio" column="female_ratio" jdbcType="VARCHAR"/>
             <result property="educationDistribution" column="education_distribution" jdbcType="VARCHAR"/>
-            <result property="ageDistribution" column="age_distribution" jdbcType="OTHER"/>
+            <result property="ageDistribution" column="age_distribution" jdbcType="VARCHAR"/>
             <result property="totalEmployees" column="total_employees" jdbcType="INTEGER"/>
             <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
             <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>

+ 7 - 17
src/main/resources/mapper/property/ASimplifiedHouseInfoMapper.xml

@@ -50,23 +50,13 @@
                 AND b.area &lt;= COALESCE(#{entity.areaMax}, b.area)
             </if>
         </where>
-        <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="sortClause != null and sortClause != ''">
+            ORDER BY ${sortClause}
+        </if>
+        <!-- 默认排序 -->
+        <if test="sortClause == null or sortClause == ''">
+            ORDER BY a.create_time DESC
+        </if>
         <if test="offset != null and limit != null">
             LIMIT #{offset}, #{limit}
         </if>