<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.ElQuMapper">

    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.qu.ElQu">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="quType" column="qu_type" jdbcType="INTEGER"/>
            <result property="levels" column="levels" jdbcType="INTEGER"/>
            <result property="image" column="image" jdbcType="VARCHAR"/>
            <result property="content" column="content" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="remark" column="remark" jdbcType="VARCHAR"/>
            <result property="analysis" column="analysis" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,qu_type,levels,
        image,content,create_time,
        update_time,remark,analysis
    </sql>
    <select id="selectQuList" parameterType="com.ruoyi.system.domain.qu.dto.request.QuQueryReqDTO" resultType="com.ruoyi.system.domain.qu.ElQu">
        SELECT q.*
        FROM el_qu q
        LEFT JOIN el_qu_repo po ON q.id=po.qu_id
        <trim prefix="where" prefixOverrides="and|or">
            <if test="quType!=null">
                AND q.qu_type = #{quType}
            </if>
            <if test="repoIds!=null and repoIds.size()>0">
                AND po.repo_id IN
                <foreach collection="repoIds" open="(" close=")" separator="," item="repoId">#{repoId}</foreach>
            </if>
            <if test="content!=null and content!=''">
                AND q.content LIKE concat('%',#{content},'%')
            </if>
        </trim>
        GROUP BY q.id ORDER BY q.update_time DESC

    </select>


    <select id="listByRandom" resultMap="BaseResultMap">
        SELECT a.*
        FROM el_qu a
        LEFT JOIN el_qu_repo b ON a.id=b.qu_id
        WHERE b.repo_id=#{repoId} AND a.qu_type=#{quType}
        <if test="excludes!=null">
            AND a.id NOT IN
            <foreach item="item" collection="excludes" separator="," open="(" close=")" index="">'${item}'</foreach>
        </if>
        ORDER BY RANDOM()
        LIMIT ${size}
    </select>

</mapper>
