<?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.syzy.mapper.BWwwNewsVideoMapper">

    <resultMap type="BWwwNewsVideo" id="BWwwNewsVideoResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="subType"    column="subType"    />
        <result property="title"    column="title"    />
        <result property="source"    column="source"    />
        <result property="sendDate"    column="sendDate"    />
        <result property="aliId"    column="aliId"    />
        <result property="createTime"    column="createTime"    />
        <result property="clicked"    column="clicked"    />
        <result property="status"    column="status"    />
        <result property="coverUrl"    column="coverUrl"    />
    </resultMap>

    <sql id="selectBWwwNewsVideoVo">
        select id, type, subType, title, source, sendDate, aliId, createTime, clicked, status, coverUrl from b_www_news_video
    </sql>

    <select id="selectBWwwNewsVideoList" parameterType="BWwwNewsVideo" resultMap="BWwwNewsVideoResult">
        <include refid="selectBWwwNewsVideoVo"/>
        <where>
            1=1 and status>0
            <if test="type != null  and type != ''"> and type like concat ('%', #{type},'%')</if>
            <if test="subType != null  and subType != ''"> and subType like concat ('%', #{subType},'%')</if>
            <if test="title != null  and title != ''"> and title like concat ('%', #{title},'%')</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="sendDate != null "> and sendDate = #{sendDate}</if>
            <if test="aliId != null  and aliId != ''"> and aliId like concat ('%', #{aliId},'%')</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="clicked != null "> and clicked = #{clicked}</if>
            <if test="coverUrl != null "> and coverUrl = #{coverUrl}</if>
        </where>
        <if test="tag=='hot'"> order by id desc, clicked desc </if>
        <if test="tag==null"> order by id desc  </if>
    </select>

    <select id="selectBWwwNewsVideoById" parameterType="Long" resultMap="BWwwNewsVideoResult">
        <include refid="selectBWwwNewsVideoVo"/>
        where id = #{id}
    </select>

    <select id="selectBWwwNewsVideoByAliId" parameterType="String" resultMap="BWwwNewsVideoResult">
        <include refid="selectBWwwNewsVideoVo"/>
        where aliId = #{aliId}
    </select>

    <select id="selectBWwwNewsVideoTypes" resultType="String">
        SELECT DISTINCT TYPE FROM b_www_news_video and type is not null
    </select>

    <select id="selectBWwwNewsVideoSubTypes" resultType="String">
        SELECT DISTINCT subType FROM b_www_news_video where type=#{type} and subType is not null
    </select>

    <insert id="insertBWwwNewsVideo" parameterType="BWwwNewsVideo" useGeneratedKeys="true" keyProperty="id">
        insert into b_www_news_video
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="subType != null">subType,</if>
            <if test="title != null">title,</if>
            <if test="source != null">source,</if>
            <if test="sendDate != null">sendDate,</if>
            <if test="aliId != null">aliId,</if>
            <if test="createTime != null">createTime,</if>
            <if test="clicked != null">clicked,</if>
            <if test="status != null">status,</if>
            <if test="coverUrl != null">coverUrl,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="subType != null">#{subType},</if>
            <if test="title != null">#{title},</if>
            <if test="source != null">#{source},</if>
            <if test="sendDate != null">#{sendDate},</if>
            <if test="aliId != null">#{aliId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="clicked != null">#{clicked},</if>
            <if test="status != null">#{status},</if>
            <if test="coverUrl != null">#{coverUrl},</if>
         </trim>
    </insert>

    <update id="updateBWwwNewsVideo" parameterType="BWwwNewsVideo">
        update b_www_news_video
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="subType != null">subType = #{subType},</if>
            <if test="title != null">title = #{title},</if>
            <if test="source != null">source = #{source},</if>
            <if test="sendDate != null">sendDate = #{sendDate},</if>
            <if test="aliId != null">aliId = #{aliId},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="clicked != null">clicked = #{clicked},</if>
            <if test="status != null">status = #{status},</if>
            <if test="coverUrl != null">coverUrl = #{coverUrl},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBWwwNewsVideoById" parameterType="Long">
        delete from b_www_news_video where id = #{id}
    </delete>

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