<?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.heketai.website.mapper.GuestbookMapper">
    <resultMap id="BaseResultMap" type="com.heketai.website.entity.Guestbook">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="language_type" jdbcType="INTEGER" property="languageType"/>
        <result column="username" jdbcType="VARCHAR" property="username"/>
        <result column="company_name" jdbcType="VARCHAR" property="companyName"/>
        <result column="job_title" jdbcType="VARCHAR" property="jobTitle"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
        <result column="mailbox" jdbcType="VARCHAR" property="mailbox"/>
        <result column="country" jdbcType="VARCHAR" property="country"/>
        <result column="company_type" jdbcType="VARCHAR" property="companyType"/>
        <result column="query_type" jdbcType="VARCHAR" property="queryType"/>
        <result column="trade" jdbcType="VARCHAR" property="trade"/>
        <result column="message_contents" jdbcType="VARCHAR" property="messageContents"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="create_name" jdbcType="VARCHAR" property="createName"/>
        <result column="state" jdbcType="INTEGER" property="state"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="notes" jdbcType="VARCHAR" property="notes"/>

    </resultMap>
    <sql id="Base_Column_List">
        id
        , language_type, username, company_name, job_title, phone, mailbox, country, company_type,
    query_type, trade, message_contents, create_time, create_name, `state`,update_time,notes
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from guestbook
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete
        from guestbook
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insertGuestbook" parameterType="com.heketai.website.entity.Guestbook">
        insert into guestbook (language_type, username,
                               company_name, job_title, phone,
                               mailbox, country, company_type,
                               query_type, trade, message_contents,
                               create_name, `state`)
        values (#{languageType,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR},
                #{companyName,jdbcType=VARCHAR}, #{jobTitle,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
                #{mailbox,jdbcType=VARCHAR}, #{country,jdbcType=VARCHAR}, #{companyType,jdbcType=VARCHAR},
                #{queryType,jdbcType=VARCHAR}, #{trade,jdbcType=VARCHAR}, #{messageContents,jdbcType=VARCHAR},
                #{createName,jdbcType=VARCHAR}, #{state,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" parameterType="com.heketai.website.entity.Guestbook">
        insert into guestbook
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="languageType != null">
                language_type,
            </if>
            <if test="username != null">
                username,
            </if>
            <if test="companyName != null">
                company_name,
            </if>
            <if test="jobTitle != null">
                job_title,
            </if>
            <if test="phone != null">
                phone,
            </if>
            <if test="mailbox != null">
                mailbox,
            </if>
            <if test="country != null">
                country,
            </if>
            <if test="companyType != null">
                company_type,
            </if>
            <if test="queryType != null">
                query_type,
            </if>
            <if test="trade != null">
                trade,
            </if>
            <if test="messageContents != null">
                message_contents,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="createName != null">
                create_name,
            </if>
            <if test="state != null">
                `state`,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="languageType != null">
                #{languageType,jdbcType=INTEGER},
            </if>
            <if test="username != null">
                #{username,jdbcType=VARCHAR},
            </if>
            <if test="companyName != null">
                #{companyName,jdbcType=VARCHAR},
            </if>
            <if test="jobTitle != null">
                #{jobTitle,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                #{phone,jdbcType=VARCHAR},
            </if>
            <if test="mailbox != null">
                #{mailbox,jdbcType=VARCHAR},
            </if>
            <if test="country != null">
                #{country,jdbcType=VARCHAR},
            </if>
            <if test="companyType != null">
                #{companyType,jdbcType=VARCHAR},
            </if>
            <if test="queryType != null">
                #{queryType,jdbcType=VARCHAR},
            </if>
            <if test="trade != null">
                #{trade,jdbcType=VARCHAR},
            </if>
            <if test="messageContents != null">
                #{messageContents,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createName != null">
                #{createName,jdbcType=VARCHAR},
            </if>
            <if test="state != null">
                #{state,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.heketai.website.entity.Guestbook">
        update guestbook
        <set>
            <if test="languageType != null">
                language_type = #{languageType,jdbcType=INTEGER},
            </if>
            <if test="username != null">
                username = #{username,jdbcType=VARCHAR},
            </if>
            <if test="companyName != null">
                company_name = #{companyName,jdbcType=VARCHAR},
            </if>
            <if test="jobTitle != null">
                job_title = #{jobTitle,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                phone = #{phone,jdbcType=VARCHAR},
            </if>
            <if test="mailbox != null">
                mailbox = #{mailbox,jdbcType=VARCHAR},
            </if>
            <if test="country != null">
                country = #{country,jdbcType=VARCHAR},
            </if>
            <if test="companyType != null">
                company_type = #{companyType,jdbcType=VARCHAR},
            </if>
            <if test="queryType != null">
                query_type = #{queryType,jdbcType=VARCHAR},
            </if>
            <if test="trade != null">
                trade = #{trade,jdbcType=VARCHAR},
            </if>
            <if test="messageContents != null">
                message_contents = #{messageContents,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createName != null">
                create_name = #{createName,jdbcType=VARCHAR},
            </if>
            <if test="state != null">
                `state` = #{state,jdbcType=INTEGER},
            </if>
            <if test="notes != null">
                notes = #{notes}
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.heketai.website.entity.Guestbook">
        update guestbook
        set language_type    = #{languageType,jdbcType=INTEGER},
            username         = #{username,jdbcType=VARCHAR},
            company_name     = #{companyName,jdbcType=VARCHAR},
            job_title        = #{jobTitle,jdbcType=VARCHAR},
            phone            = #{phone,jdbcType=VARCHAR},
            mailbox          = #{mailbox,jdbcType=VARCHAR},
            country          = #{country,jdbcType=VARCHAR},
            company_type     = #{companyType,jdbcType=VARCHAR},
            query_type       = #{queryType,jdbcType=VARCHAR},
            trade            = #{trade,jdbcType=VARCHAR},
            message_contents = #{messageContents,jdbcType=VARCHAR},
            create_time      = #{createTime,jdbcType=TIMESTAMP},
            create_name      = #{createName,jdbcType=VARCHAR},
            `state`          = #{state,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <select id="selectGuestbookList" resultType="com.heketai.website.entity.Guestbook">
        select id,
        language_type,
        username,
        company_name,
        job_title,
        phone,
        mailbox,
        country,
        company_type,
        query_type,
        trade,
        message_contents,
        create_time,
        create_name,
        `state`,
        update_time,
        notes
        from guestbook
        where language_type = #{languageType}
        <if test="state != null">
            and `state` = #{state}
        </if>
        order by `state` asc,
        <if test="state == 1 or state==2">
            update_time desc,
        </if>
        create_time desc
        limit #{start}, #{size}
    </select>
    <select id="selectGuestbookListByState" resultType="java.lang.Integer">
        select id
        from guestbook
        where `state` = #{state}
    </select>

    <delete id="deleteByState" parameterType="java.lang.Integer">
        delete
        from guestbook
        where id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </delete>

    <update id="updateByIdList">
        update guestbook
        <set>
            <if test="state!= null ">
                `state` = #{state,jdbcType=INTEGER},
            </if>
            <if test="notes != null and notes !=''">
                notes = #{notes}
            </if>
        </set>

        where id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </update>
    <select id="selectGuestbookCount" resultType="java.lang.Integer">
        select count(*)
        from guestbook
        where language_type = #{languageType}
        <if test="state != null">
            and `state` = #{state}
        </if>
    </select>
</mapper>