<?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.push.dao.impl.MorningEveningNewsDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.push.entity.MorningEveningNews">
        <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="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"/>
    </resultMap>

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

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

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

    <update id="update" parameterType="com.pcloud.book.push.entity.MorningEveningNews">
        update morning_evening_news
        <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="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>
            update_time = NOW(),
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

    <select id="getByPartyId" parameterType="Long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/> from morning_evening_news where create_user=#{partyId}
        order by create_time desc limit 1
    </select>

</mapper>