Explorar el Código

fix(his): 修复用户列表查询重复数据问题

- 修改SQL查询语句,添加DISTINCT关键字去重
- 优化period_name字段的查询逻辑,使用子查询替代联表查询
- 移除不必要的联表操作,提升查询性能
- 确保用户最新学习记录的准确性
xw hace 2 meses
padre
commit
1db7a74d79
Se han modificado 1 ficheros con 5 adiciones y 4 borrados
  1. 5 4
      fs-service/src/main/resources/mapper/his/FsUserMapper.xml

+ 5 - 4
fs-service/src/main/resources/mapper/his/FsUserMapper.xml

@@ -332,7 +332,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="selectFsUserPageListNew" resultType="com.fs.store.vo.h5.FsUserPageListVO">
-        SELECT
+        SELECT DISTINCT
         fs_user.user_id,
         fs_user.nick_name as nickname,
         fs_user.avatar,
@@ -345,13 +345,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ucu.company_id,
         ucu.project_id,
         fs_user.integral,
-        fucp.period_name,
+        (SELECT fucp2.period_name FROM fs_course_watch_log fcwl2 
+         LEFT JOIN fs_user_course_period fucp2 ON fcwl2.period_id = fucp2.period_id 
+         WHERE fcwl2.user_id = fs_user.user_id 
+         ORDER BY fcwl2.last_heartbeat_time DESC LIMIT 1) as period_name,
         if(fs_user.pay_count>0,1,0) as isBuy
         FROM
         fs_user
         left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
-        left join fs_course_watch_log fcwl on fs_user.user_id = fcwl.user_id
-        left join fs_user_course_period fucp on fcwl.period_id = fucp.period_id
         <where>
             fs_user.is_del = 0
             <if test="userId != null">