<?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.mingxue.mapper.MxjbOperationManualMapper">
    
    <resultMap type="MxjbOperationManual" id="MxjbOperationManualResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="name"    column="name"    />
        <result property="nameType"    column="name_type"    />
        <result property="aliId"    column="aliId"    />
        <result property="source"    column="source"    />
        <result property="fileSize"    column="file_size"    />
        <result property="duration"    column="duration"    />
        <result property="coverUrl"    column="cover_url"    />
        <result property="roleIds"    column="role_ids"    />
        <result property="sort"    column="sort"    />
        <result property="createTime"    column="create_time"    />
        <result property="status"    column="status"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMxjbOperationManualVo">
        select id, parent_id, ancestors, name, name_type, aliId, source, file_size, duration, cover_url, role_ids, sort, create_time, status, update_time from mxjb_operation_manual
    </sql>

    <select id="selectMxjbOperationManualList" parameterType="MxjbOperationManual" resultMap="MxjbOperationManualResult">
        <include refid="selectMxjbOperationManualVo"/>
        <where>  
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="nameType != null  and nameType != ''"> and name_type = #{nameType}</if>
            <if test="aliId != null  and aliId != ''"> and aliId = #{aliId}</if>
            <if test="source != null  and source != ''"> and find_in_set(#{source}, source)</if>
            <if test="fileSize != null "> and file_size = #{fileSize}</if>
            <if test="duration != null "> and duration = #{duration}</if>
            <if test="coverUrl != null  and coverUrl != ''"> and cover_url = #{coverUrl}</if>
            <if test="roleIds != null  and roleIds != ''"> and find_in_set(#{roleIds}, role_ids)</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="status == null "> and status >0</if>
        </where>
    </select>

    <select id="selectMxjbOperationManualByNameType" parameterType="String" resultMap="MxjbOperationManualResult">
        <include refid="selectMxjbOperationManualVo"/>
        where status >0 and name_type = #{nameType}
    </select>

    <select id="selectMxjbOperationManualAndChildren" parameterType="MxjbOperationManual" resultMap="MxjbOperationManualResult">
        <include refid="selectMxjbOperationManualVo"/>
        where status >0
        and (id = #{id} OR id IN (
          SELECT t.id FROM mxjb_operation_manual t WHERE find_in_set(#{id}, ancestors)
            <if test="source != null  and source != ''"> and source like concat('%', #{source}, '%')</if>
            <if test="roleIds != null  and roleIds != ''"> and role_ids like concat('%', #{roleIds}, '%')</if>
          )
        )
    </select>
    
    <select id="selectMxjbOperationManualById" parameterType="Long" resultMap="MxjbOperationManualResult">
        <include refid="selectMxjbOperationManualVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertMxjbOperationManual" parameterType="MxjbOperationManual" useGeneratedKeys="true" keyProperty="id">
        insert into mxjb_operation_manual
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="name != null">name,</if>
            <if test="nameType != null">name_type,</if>
            <if test="aliId != null">aliId,</if>
            <if test="source != null">source,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="duration != null">duration,</if>
            <if test="coverUrl != null">cover_url,</if>
            <if test="roleIds != null and roleIds != ''">role_ids,</if>
            <if test="sort != null">sort,</if>
            <if test="createTime != null">create_time,</if>
            <if test="status != null">status,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="name != null">#{name},</if>
            <if test="nameType != null">#{nameType},</if>
            <if test="aliId != null">#{aliId},</if>
            <if test="source != null">#{source},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="duration != null">#{duration},</if>
            <if test="coverUrl != null">#{coverUrl},</if>
            <if test="roleIds != null and roleIds != ''">#{roleIds},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateMxjbOperationManual" parameterType="MxjbOperationManual">
        update mxjb_operation_manual
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
            <if test="name != null">name = #{name},</if>
            <if test="nameType != null">name_type = #{nameType},</if>
            <if test="aliId != null">aliId = #{aliId},</if>
            <if test="source != null">source = #{source},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="coverUrl != null">cover_url = #{coverUrl},</if>
            <if test="roleIds != null and roleIds != ''">role_ids = #{roleIds},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMxjbOperationManualById" parameterType="Long">
        delete from mxjb_operation_manual where id = #{id}
    </delete>

    <delete id="deleteMxjbOperationManualByIds" parameterType="String">
        delete from mxjb_operation_manual where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>