This commit is contained in:
2026-06-08 16:34:31 +08:00
parent 3e9264ebc6
commit aea34dc5e4
7 changed files with 122 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
@Mapper
public interface SyncUserInfoLogMapper extends MyBatisBaseMapper<SyncUserInfoLog, Long> {
@@ -22,4 +23,6 @@ public interface SyncUserInfoLogMapper extends MyBatisBaseMapper<SyncUserInfoLog
void updateLastSyncTime(Date date);
SyncUserInfoLog findUserInfoByStuUserId(@Param("stuUserId") String stuUserId);
List<SyncUserInfoLog> batchFindUserInfoByStuUserIds(@Param("stuUserIds") List<String> stuUserIds);
}

View File

@@ -150,4 +150,11 @@
<select id="findUserInfoByStuUserId" resultMap="UserResultMap">
SELECT user_id, username FROM sync_user_info_log WHERE user_id = #{stuUserId}
</select>
<select id="batchFindUserInfoByStuUserIds" resultMap="UserResultMap">
SELECT user_id, username FROM sync_user_info_log WHERE user_id IN
<foreach collection="stuUserIds" item="stuUserId" open="(" separator="," close=")">
#{stuUserId}
</foreach>
</select>
</mapper>

View File

@@ -22,4 +22,11 @@ public interface TUserMapper extends MyBatisBaseMapper<TUser, Long> {
*/
Long findUserIdByUsername(@Param("username") String username);
/**
* 批量查询用户ID替代 N+1 循环查询)
* @param usernames 用户名列表
* @return username -> userId 映射列表
*/
List<TUser> batchFindUserIdByUsernames(@Param("usernames") List<String> usernames);
}

View File

@@ -189,5 +189,12 @@
<select id="findUserIdByUsername" resultType="java.lang.Long">
SELECT id FROM t_user WHERE user_no = #{username}
</select>
</select>
<select id="batchFindUserIdByUsernames" resultType="cn.wepact.dfm.training.dto.entity.TUser">
SELECT id, user_no AS userNo FROM t_user WHERE user_no IN
<foreach collection="usernames" item="username" open="(" separator="," close=")">
#{username}
</foreach>
</select>
</mapper>