Просмотр исходного кода

fix: sort place list by calculated rating

Sheep 2 недель назад
Родитель
Сommit
6210a3fb71

+ 17 - 2
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/AppSiteMapper.xml

@@ -5,7 +5,7 @@
         SELECT
         b.id,
         b.name AS name,
-        b.good_rate AS goodRate,
+        COALESCE(ROUND(r.score_sum / NULLIF(r.score_num, 0), 1), 0) AS goodRate,
         b.address,
         b.category_id,
         b.latitude,
@@ -15,6 +15,15 @@
         FROM
         nm_site b
         LEFT JOIN sys_depart c ON b.org_code = c.org_code
+        LEFT JOIN (
+            SELECT
+                site_id,
+                SUM(score) AS score_sum,
+                COUNT(1) AS score_num
+            FROM nm_evaluate
+            WHERE check_status = 1
+            GROUP BY site_id
+        ) r ON r.site_id = b.id
         WHERE 1 = 1 AND b.del_flag = 0
         AND (
         b.type != 0
@@ -35,6 +44,12 @@
         <if test="venueType != null and venueType == '2-2'">
             AND c.org_category = 21
         </if>
+        <if test="venueType == null or (venueType != '0-2' and venueType != '1-1' and venueType != '2-1')">
+            ORDER BY
+                COALESCE(r.score_sum / NULLIF(r.score_num, 0), 0) DESC,
+                COALESCE(r.score_num, 0) DESC,
+                b.id ASC
+        </if>
     </select>
 
     <select id="convertSearchPlaceVOPage" resultType="org.jeecg.modules.app.vo.SearchVO$SearchPlaceVO" parameterType="org.jeecg.modules.app.dto.SearchDTO">
@@ -93,4 +108,4 @@
                 LEFT JOIN sys_depart b ON a.tenant_id = b.id
         WHERE a.del_flag = 0 AND a.status = 0 AND a.id = #{id}
     </select>
-</mapper>
+</mapper>