<?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.KuaishouLiveBroadcastMapper">

    <resultMap type="com.ruixuan.live.entity.KuaishouLiveBroadcast" id="KuaishouLiveBroadcastResult">
        <result property="id" column="id"/>
        <result property="ksId" column="ks_id"/>
        <result property="ksName" column="ks_name"/>
        <result property="accountId" column="account_id"/>
        <result property="accountName" column="account_name"/>
        <result property="goalGmv" column="goal_gmv"/>
        <result property="actualGmv" column="actual_gmv"/>
        <result property="gmvRoi" column="gmvRoi"/>
        <result property="liveTime" column="live_time"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="liveLevel" column="live_level"/>
        <result property="anchorId" column="anchor_id"/>
        <result property="anchor" column="anchor"/>
        <result property="traderId" column="trader_id"/>
        <result property="trader" column="trader"/>
        <result property="centralControlId" column="central_control_id"/>
        <result property="centralController" column="central_controller"/>
        <result property="fieldControlId" column="field_control_id"/>
        <result property="fieldController" column="field_controller"/>
        <result property="contentControlId" column="content_control_id"/>
        <result property="contentController" column="content_controller"/>
        <result property="inputControlId" column="input_control_id"/>
        <result property="inputController" column="input_controller"/>
        <result property="createrId" column="creater_id"/>
        <result property="uploadFileCount" column="upload_file_count"/>
        <result property="uploadFileCount" column="upload_file_count"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouLiveBroadcastVo">
        select id,
               ks_id,
               ks_name,
               account_id,
               account_name,
               if(goal_gmv >= 10000, CONCAT(truncate(goal_gmv / 10000, 2), 'W'), goal_gmv) as 'goal_gmv',
               actual_gmv,
               if(actual_gmv is null, '-', CONCAT(ROUND(actual_gmv / goal_gmv * 100, 2), '%')) as 'gmvRoi',
               live_time,
               start_time,
               end_time,
               live_level,
               anchor_id,
               anchor,
               trader_id,
               trader,
               central_control_id,
               central_controller,
               field_control_id,
               field_controller,
               content_control_id,
               content_controller,
               input_control_id,
               input_controller,
               upload_file_count,
               upload_picture_count
        from kuaishou_live_broadcast
    </sql>

    <select id="selectKuaishouLiveBroadcastList" parameterType="com.ruixuan.live.entity.KuaishouLiveBroadcast"
            resultMap="KuaishouLiveBroadcastResult">
        <include refid="selectKuaishouLiveBroadcastVo"/>
        <where>
            <if test="ksId != null ">and ks_id = #{ksId}</if>
            <if test="ksName != null  and ksName != ''">and ks_name like concat('%', #{ksName}, '%')</if>
            <if test="accountId != null ">and account_id = #{accountId}</if>
            <if test="accountName != null  and accountName != ''">and account_name like concat('%', #{accountName},
                '%')
            </if>
            <if test="goalGmv != null  and goalGmv != ''">and goal_gmv = #{goalGmv}</if>
            <if test="startTime != null  and startTime != ''">and start_time >= #{startTime}</if>
            <if test="endTime != null  and endTime != ''">and end_time &lt;= #{endTime}</if>
            <if test="liveLevel != null  and liveLevel != ''">and live_level = #{liveLevel}</if>
            <if test="anchorId != null  and anchorId != ''">and anchor_id = #{anchorId}</if>
            <if test="anchor != null  and anchor != ''">and anchor = #{anchor}</if>
            <if test="traderId != null  and traderId != ''">and trader_id = #{traderId}</if>
            <if test="trader != null  and trader != ''">and trader = #{trader}</if>
            <if test="centralControlId != null  and centralControlId != ''">and central_control_id =
                #{centralControlId}
            </if>
            <if test="centralController != null  and centralController != ''">and central_controller
                like concat('%', #{centralController}, '%')
            </if>
            <if test="fieldControlId != null  and fieldControlId != ''">and field_control_id = #{fieldControlId}</if>
            <if test="fieldController != null  and fieldController != ''">and field_controller
                like concat('%', #{fieldController}, '%')
            </if>
            <if test="contentControlId != null  and contentControlId != ''">and content_control_id =
                #{contentControlId}
            </if>
            <if test="contentController != null  and contentController != ''">and content_controller
                like concat('%', #{contentController}, '%')
            </if>
            <if test="inputControlId != null  and inputControlId != ''">and input_control_id = #{inputControlId}</if>
            <if test="inputController != null  and inputController != ''">and input_controller
                like concat('%', #{inputController}, '%')
            </if>
        </where>
        ORDER BY create_time desc
    </select>

    <select id="selectKuaishouLiveBroadcastById" parameterType="String" resultMap="KuaishouLiveBroadcastResult">
        select id,
               ks_id,
               ks_name,
               account_id,
               account_name,
               goal_gmv,
               actual_gmv,
               live_time,
               start_time,
               end_time,
               live_level,
               anchor_id,
               anchor,
               trader_id,
               trader,
               central_control_id,
               central_controller,
               field_control_id,
               field_controller,
               content_control_id,
               content_controller,
               input_control_id,
               input_controller,
               upload_file_count,
               upload_picture_count
        from kuaishou_live_broadcast
        where id = #{id}
    </select>

    <select id="getOne" parameterType="com.ruixuan.live.entity.KuaishouLiveBroadcast"
            resultMap="KuaishouLiveBroadcastResult">
        <include refid="selectKuaishouLiveBroadcastVo"/>
        where ks_id = #{ksId}
        and account_name = #{accountName}
        and start_time = #{startTime}
        and end_time = #{endTime}
        <if test="id != null  and id != ''">and id = #{id}</if>
    </select>

    <insert id="insertKuaishouLiveBroadcast" parameterType="com.ruixuan.live.entity.KuaishouLiveBroadcast">
        insert into kuaishou_live_broadcast
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="ksId != null">ks_id,</if>
            <if test="ksName != null">ks_name,</if>
            <if test="accountId != null">account_id,</if>
            <if test="accountName != null">account_name,</if>
            <if test="actualGmv != null">actual_gmv,</if>
            <if test="goalGmv != null">goal_gmv,</if>
            <if test="liveTime != null">live_time,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="liveLevel != null">live_level,</if>
            <if test="anchorId != null">anchor_id,</if>
            <if test="anchor != null">anchor,</if>
            <if test="traderId != null">trader_id,</if>
            <if test="trader != null">trader,</if>
            <if test="centralControlId != null">central_control_id,</if>
            <if test="centralController != null">central_controller,</if>
            <if test="fieldControlId != null">field_control_id,</if>
            <if test="fieldController != null">field_controller,</if>
            <if test="contentControlId != null">content_control_id,</if>
            <if test="contentController != null">content_controller,</if>
            <if test="inputControlId != null">input_control_id,</if>
            <if test="inputController != null">input_controller,</if>
            <if test="createrId != null">creater_id,</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="ksId != null">#{ksId},</if>
            <if test="ksName != null">#{ksName},</if>
            <if test="accountId != null">#{accountId},</if>
            <if test="accountName != null">#{accountName},</if>
            <if test="actualGmv != null">#{actualGmv},</if>
            <if test="goalGmv != null">#{goalGmv},</if>
            <if test="liveTime != null">#{liveTime},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="liveLevel != null">#{liveLevel},</if>
            <if test="anchorId != null">#{anchorId},</if>
            <if test="anchor != null">#{anchor},</if>
            <if test="traderId != null">#{traderId},</if>
            <if test="trader != null">#{trader},</if>
            <if test="centralControlId != null">#{centralControlId},</if>
            <if test="centralController != null">#{centralController},</if>
            <if test="fieldControlId != null">#{fieldControlId},</if>
            <if test="fieldController != null">#{fieldController},</if>
            <if test="contentControlId != null">#{contentControlId},</if>
            <if test="contentController != null">#{contentController},</if>
            <if test="inputControlId != null">#{inputControlId},</if>
            <if test="inputController != null">#{inputController},</if>
            <if test="createrId != null">#{createrId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLiveBroadcast" parameterType="com.ruixuan.live.entity.KuaishouLiveBroadcast">
        update kuaishou_live_broadcast
        <trim prefix="SET" suffixOverrides=",">
            <if test="ksId != null">ks_id = #{ksId},</if>
            <if test="ksName != null">ks_name = #{ksName},</if>
            <if test="accountId != null">account_id = #{accountId},</if>
            <if test="accountName != null">account_name = #{accountName},</if>
            <if test="actualGmv != null">actual_gmv = #{actualGmv},</if>
            <if test="goalGmv != null">goal_gmv = #{goalGmv},</if>
            <if test="liveTime != null">live_time = #{liveTime},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="liveLevel != null">live_level = #{liveLevel},</if>
            <if test="anchorId != null">anchor_id = #{anchorId},</if>
            <if test="anchor != null">anchor = #{anchor},</if>
            <if test="traderId != null">trader_id = #{traderId},</if>
            <if test="trader != null">trader = #{trader},</if>
            <if test="centralControlId != null">central_control_id = #{centralControlId},</if>
            <if test="centralController != null">central_controller = #{centralController},</if>
            <if test="fieldControlId != null">field_control_id = #{fieldControlId},</if>
            <if test="fieldController != null">field_controller = #{fieldController},</if>
            <if test="contentControlId != null">content_control_id = #{contentControlId},</if>
            <if test="contentController != null">content_controller = #{contentController},</if>
            <if test="inputControlId != null">input_control_id = #{inputControlId},</if>
            <if test="inputController != null">input_controller = #{inputController},</if>
            <if test="createrId != null">creater_id = #{createrId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="uploadPictureCount != null">upload_picture_count = #{uploadPictureCount},</if>
            <if test="uploadFileCount != null">upload_file_count = #{uploadFileCount},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKuaishouLiveBroadcastById" parameterType="String">
        delete
        from kuaishou_live_broadcast
        where id = #{id}
    </delete>

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