<?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.ruixuan.live.mapper.KuaishouLiveProjectMapper">

    <resultMap type="com.ruixuan.live.entity.KuaishouLiveProject" id="KuaishouLiveProjectResult">
        <result property="id" column="id"/>
        <result property="projectName" column="project_name"/>
        <result property="state" column="state"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouLiveProjectVo">
        select id, project_name, state, create_time, update_time
        from kuaishou_live_project
    </sql>

    <select id="selectKuaishouLiveProjectList" parameterType="com.ruixuan.live.entity.KuaishouLiveProject"
            resultMap="KuaishouLiveProjectResult">
        <include refid="selectKuaishouLiveProjectVo"/>
        <where>
            <if test="projectName != null  and projectName != ''">and project_name like concat('%', #{projectName},
                '%')
            </if>
            <if test="state != null  and state != ''">and state = #{state}</if>
        </where>
    </select>

    <select id="selectKuaishouLiveProjectById" parameterType="Long" resultMap="KuaishouLiveProjectResult">
        <include refid="selectKuaishouLiveProjectVo"/>
        where id = #{id}
    </select>

    <select id="getOne" resultMap="KuaishouLiveProjectResult">
        <include refid="selectKuaishouLiveProjectVo"/>
        where id = #{id}
        <if test="projectName != null">
            and project_name = #{projectName}
        </if>
        and state = 1
    </select>

    <insert id="insertKuaishouLiveProject" parameterType="com.ruixuan.live.entity.KuaishouLiveProject">
        insert into kuaishou_live_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="projectName != null">project_name,</if>
            <if test="state != null">state,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="state != null">#{state},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLiveProject" parameterType="com.ruixuan.live.entity.KuaishouLiveProject">
        update kuaishou_live_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="state != null">state = #{state},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKuaishouLiveProjectById" parameterType="Long">
        delete
        from kuaishou_live_project
        where id = #{id}
    </delete>

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