<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.adnews.dao.impl.AdNewsSetDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.adnews.entity.AdNewsSet">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="morning_time" property="morningTime" jdbcType="VARCHAR"/>
        <result column="evening_time" property="eveningTime" jdbcType="VARCHAR"/>
        <result column="has_morning_open" property="hasMorningOpen" jdbcType="BOOLEAN"/>
        <result column="has_evening_open" property="hasEveningOpen" jdbcType="BOOLEAN"/>
        <result column="send_count" property="sendCount" jdbcType="INTEGER"/>
        <result column="send_rule" property="sendRule" jdbcType="INTEGER"/>
        <result column="start_content" property="startContent" jdbcType="VARCHAR"/>
        <result column="end_content" property="endContent" jdbcType="VARCHAR"/>
        <result column="has_start_content" property="hasStartContent" jdbcType="BOOLEAN"/>
        <result column="has_end_content" property="hasEndContent" jdbcType="BOOLEAN"/>
        <result column="create_user" property="createUser" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_user" property="updateUser" jdbcType="BIGINT"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="content_from" property="contentFrom" jdbcType="INTEGER"/>
        <result column="morning_content" property="morningContent" jdbcType="VARCHAR"/>
        <result column="evening_content" property="eveningContent" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, morning_time, evening_time, has_morning_open, has_evening_open, send_count,send_rule, start_content,
        end_content, has_start_content, has_end_content, create_user, create_time, update_user, update_time
        ,content_from,morning_content,evening_content
    </sql>

    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from ad_news_set
        where id = #{id,jdbcType=BIGINT}
    </select>

    <insert id="insert" parameterType="com.pcloud.book.adnews.entity.AdNewsSet" useGeneratedKeys="true" keyProperty="id">
        insert into ad_news_set
        <trim prefix="(" suffix=")" suffixOverrides=",">
            morning_time,
            evening_time,
            has_morning_open,
            has_evening_open,
            send_count,
            send_rule,
            start_content,
            end_content,
            has_start_content,
            has_end_content,
            create_user,
            create_time,
            update_user,
            update_time,
            content_from,
            morning_content,
            evening_content
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{morningTime,jdbcType=VARCHAR},
            #{eveningTime,jdbcType=VARCHAR},
            #{hasMorningOpen,jdbcType=BOOLEAN},
            #{hasEveningOpen,jdbcType=BOOLEAN},
            #{sendCount,jdbcType=INTEGER},
            #{sendRule,jdbcType=INTEGER},
            #{startContent,jdbcType=VARCHAR},
            #{endContent,jdbcType=VARCHAR},
            #{hasStartContent,jdbcType=BOOLEAN},
            #{hasEndContent,jdbcType=BOOLEAN},
            #{createUser,jdbcType=BIGINT},
            NOW(),
            #{updateUser,jdbcType=BIGINT},
            NOW(),
            #{contentFrom,jdbcType=BIGINT},
            #{morningContent,jdbcType=VARCHAR},
            #{eveningContent,jdbcType=VARCHAR},
        </trim>
    </insert>

    <update id="update" parameterType="com.pcloud.book.adnews.entity.AdNewsSet">
        update ad_news_set
        <set>
            <if test="morningTime != null">
                morning_time = #{morningTime,jdbcType=VARCHAR},
            </if>
            <if test="eveningTime != null">
                evening_time = #{eveningTime,jdbcType=VARCHAR},
            </if>
            <if test="hasMorningOpen != null">
                has_morning_open = #{hasMorningOpen,jdbcType=BOOLEAN},
            </if>
            <if test="hasEveningOpen != null">
                has_evening_open = #{hasEveningOpen,jdbcType=BOOLEAN},
            </if>
            <if test="sendCount != null">
                send_count = #{sendCount,jdbcType=INTEGER},
            </if>
            <if test="sendRule != null">
                send_rule = #{sendRule,jdbcType=INTEGER},
            </if>
            <if test="startContent != null">
                start_content = #{startContent,jdbcType=VARCHAR},
            </if>
            <if test="endContent != null">
                end_content = #{endContent,jdbcType=VARCHAR},
            </if>
            <if test="hasStartContent != null">
                has_start_content = #{hasStartContent,jdbcType=BOOLEAN},
            </if>
            <if test="hasEndContent != null">
                has_end_content = #{hasEndContent,jdbcType=BOOLEAN},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser,jdbcType=BIGINT},
            </if>
            <if test="contentFrom != null">
                content_from = #{contentFrom,jdbcType=BIGINT},
            </if>
            <if test="morningContent != null">
                morning_content = #{morningContent,jdbcType=VARCHAR},
            </if>
            <if test="eveningContent != null">
                evening_content = #{eveningContent,jdbcType=VARCHAR},
            </if>
            update_time = NOW()
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

    <!--根据创建人查询-->
    <select id="getByPartyId" parameterType="Long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/> from ad_news_set
        where create_user=#{createUser}
    </select>
</mapper>