<?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.gyee.frame.mapper.auto.ChatDetailMapper">
  <resultMap id="BaseResultMap" type="com.gyee.frame.model.auto.ChatDetail">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="sendingid" jdbcType="VARCHAR" property="sendingid" />
    <result column="sendingname" jdbcType="VARCHAR" property="sendingname" />
    <result column="chattime" jdbcType="TIMESTAMP" property="chattime" />
    <result column="pointto" jdbcType="VARCHAR" property="pointto" />
    <result column="pointtoid" jdbcType="VARCHAR" property="pointtoid" />
    <result column="chattypes" jdbcType="VARCHAR" property="chattypes" />
    <result column="chatcontent" jdbcType="VARCHAR" property="chatcontent" />
    <result column="remark1" jdbcType="VARCHAR" property="remark1" />
    <result column="remark2" jdbcType="VARCHAR" property="remark2" />
    <result column="remark3" jdbcType="VARCHAR" property="remark3" />
    <result column="numericdate" jdbcType="BIGINT" property="numericdate" />
    <result column="sendingip" jdbcType="VARCHAR" property="sendingip" />
    <result column="receiveip" jdbcType="VARCHAR" property="receiveip" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    id, sendingid, sendingname, chattime, pointto, pointtoid, chattypes, chatcontent, 
    remark1, remark2, remark3, numericdate, sendingip, receiveip
  </sql>
  <select id="selectByExample" parameterType="com.gyee.frame.model.auto.ChatDetailExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from chatdetail
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from chatdetail
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from chatdetail
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.gyee.frame.model.auto.ChatDetailExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from chatdetail
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.gyee.frame.model.auto.ChatDetail">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into chatdetail (id, sendingid, sendingname, 
      chattime, pointto, pointtoid, 
      chattypes, chatcontent, remark1, 
      remark2, remark3, numericdate, 
      sendingip, receiveip)
    values (#{id,jdbcType=VARCHAR}, #{sendingid,jdbcType=VARCHAR}, #{sendingname,jdbcType=VARCHAR},
      #{chattime,jdbcType=TIMESTAMP}, #{pointto,jdbcType=VARCHAR}, #{pointtoid,jdbcType=VARCHAR}, 
      #{chattypes,jdbcType=VARCHAR}, #{chatcontent,jdbcType=VARCHAR}, #{remark1,jdbcType=VARCHAR}, 
      #{remark2,jdbcType=VARCHAR}, #{remark3,jdbcType=VARCHAR}, #{numericdate,jdbcType=BIGINT}, 
      #{sendingip,jdbcType=VARCHAR}, #{receiveip,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.gyee.frame.model.auto.ChatDetail">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into chatdetail
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="sendingid != null">
        sendingid,
      </if>
      <if test="sendingname != null">
        sendingname,
      </if>
      <if test="chattime != null">
        chattime,
      </if>
      <if test="pointto != null">
        pointto,
      </if>
      <if test="pointtoid != null">
        pointtoid,
      </if>
      <if test="chattypes != null">
        chattypes,
      </if>
      <if test="chatcontent != null">
        chatcontent,
      </if>
      <if test="remark1 != null">
        remark1,
      </if>
      <if test="remark2 != null">
        remark2,
      </if>
      <if test="remark3 != null">
        remark3,
      </if>
      <if test="numericdate != null">
        numericdate,
      </if>
      <if test="sendingip != null">
        sendingip,
      </if>
      <if test="receiveip != null">
        receiveip,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="sendingid != null">
        #{sendingid,jdbcType=VARCHAR},
      </if>
      <if test="sendingname != null">
        #{sendingname,jdbcType=VARCHAR},
      </if>
      <if test="chattime != null">
        #{chattime,jdbcType=TIMESTAMP},
      </if>
      <if test="pointto != null">
        #{pointto,jdbcType=VARCHAR},
      </if>
      <if test="pointtoid != null">
        #{pointtoid,jdbcType=VARCHAR},
      </if>
      <if test="chattypes != null">
        #{chattypes,jdbcType=VARCHAR},
      </if>
      <if test="chatcontent != null">
        #{chatcontent,jdbcType=VARCHAR},
      </if>
      <if test="remark1 != null">
        #{remark1,jdbcType=VARCHAR},
      </if>
      <if test="remark2 != null">
        #{remark2,jdbcType=VARCHAR},
      </if>
      <if test="remark3 != null">
        #{remark3,jdbcType=VARCHAR},
      </if>
      <if test="numericdate != null">
        #{numericdate,jdbcType=BIGINT},
      </if>
      <if test="sendingip != null">
        #{sendingip,jdbcType=VARCHAR},
      </if>
      <if test="receiveip != null">
        #{receiveip,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.gyee.frame.model.auto.ChatDetailExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from chatdetail
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update chatdetail
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.sendingid != null">
        sendingid = #{record.sendingid,jdbcType=VARCHAR},
      </if>
      <if test="record.sendingname != null">
        sendingname = #{record.sendingname,jdbcType=VARCHAR},
      </if>
      <if test="record.chattime != null">
        chattime = #{record.chattime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.pointto != null">
        pointto = #{record.pointto,jdbcType=VARCHAR},
      </if>
      <if test="record.pointtoid != null">
        pointtoid = #{record.pointtoid,jdbcType=VARCHAR},
      </if>
      <if test="record.chattypes != null">
        chattypes = #{record.chattypes,jdbcType=VARCHAR},
      </if>
      <if test="record.chatcontent != null">
        chatcontent = #{record.chatcontent,jdbcType=VARCHAR},
      </if>
      <if test="record.remark1 != null">
        remark1 = #{record.remark1,jdbcType=VARCHAR},
      </if>
      <if test="record.remark2 != null">
        remark2 = #{record.remark2,jdbcType=VARCHAR},
      </if>
      <if test="record.remark3 != null">
        remark3 = #{record.remark3,jdbcType=VARCHAR},
      </if>
      <if test="record.numericdate != null">
        numericdate = #{record.numericdate,jdbcType=BIGINT},
      </if>
      <if test="record.sendingip != null">
        sendingip = #{record.sendingip,jdbcType=VARCHAR},
      </if>
      <if test="record.receiveip != null">
        receiveip = #{record.receiveip,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update chatdetail
    set id = #{record.id,jdbcType=VARCHAR},
      sendingid = #{record.sendingid,jdbcType=VARCHAR},
      sendingname = #{record.sendingname,jdbcType=VARCHAR},
      chattime = #{record.chattime,jdbcType=TIMESTAMP},
      pointto = #{record.pointto,jdbcType=VARCHAR},
      pointtoid = #{record.pointtoid,jdbcType=VARCHAR},
      chattypes = #{record.chattypes,jdbcType=VARCHAR},
      chatcontent = #{record.chatcontent,jdbcType=VARCHAR},
      remark1 = #{record.remark1,jdbcType=VARCHAR},
      remark2 = #{record.remark2,jdbcType=VARCHAR},
      remark3 = #{record.remark3,jdbcType=VARCHAR},
      numericdate = #{record.numericdate,jdbcType=BIGINT},
      sendingip = #{record.sendingip,jdbcType=VARCHAR},
      receiveip = #{record.receiveip,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.gyee.frame.model.auto.ChatDetail">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update chatdetail
    <set>
      <if test="sendingid != null">
        sendingid = #{sendingid,jdbcType=VARCHAR},
      </if>
      <if test="sendingname != null">
        sendingname = #{sendingname,jdbcType=VARCHAR},
      </if>
      <if test="chattime != null">
        chattime = #{chattime,jdbcType=TIMESTAMP},
      </if>
      <if test="pointto != null">
        pointto = #{pointto,jdbcType=VARCHAR},
      </if>
      <if test="pointtoid != null">
        pointtoid = #{pointtoid,jdbcType=VARCHAR},
      </if>
      <if test="chattypes != null">
        chattypes = #{chattypes,jdbcType=VARCHAR},
      </if>
      <if test="chatcontent != null">
        chatcontent = #{chatcontent,jdbcType=VARCHAR},
      </if>
      <if test="remark1 != null">
        remark1 = #{remark1,jdbcType=VARCHAR},
      </if>
      <if test="remark2 != null">
        remark2 = #{remark2,jdbcType=VARCHAR},
      </if>
      <if test="remark3 != null">
        remark3 = #{remark3,jdbcType=VARCHAR},
      </if>
      <if test="numericdate != null">
        numericdate = #{numericdate,jdbcType=BIGINT},
      </if>
      <if test="sendingip != null">
        sendingip = #{sendingip,jdbcType=VARCHAR},
      </if>
      <if test="receiveip != null">
        receiveip = #{receiveip,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.gyee.frame.model.auto.ChatDetail">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update chatdetail
    set sendingid = #{sendingid,jdbcType=VARCHAR},
      sendingname = #{sendingname,jdbcType=VARCHAR},
      chattime = #{chattime,jdbcType=TIMESTAMP},
      pointto = #{pointto,jdbcType=VARCHAR},
      pointtoid = #{pointtoid,jdbcType=VARCHAR},
      chattypes = #{chattypes,jdbcType=VARCHAR},
      chatcontent = #{chatcontent,jdbcType=VARCHAR},
      remark1 = #{remark1,jdbcType=VARCHAR},
      remark2 = #{remark2,jdbcType=VARCHAR},
      remark3 = #{remark3,jdbcType=VARCHAR},
      numericdate = #{numericdate,jdbcType=BIGINT},
      sendingip = #{sendingip,jdbcType=VARCHAR},
      receiveip = #{receiveip,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="selectByUserId"   resultMap="BaseResultMap">
    select
    id, sendingid, sendingname, chattime, pointto, pointtoid, chattypes, chatcontent,
    remark1, remark2, remark3, numericdate, sendingip, receiveip
    from chatdetail
    where  ((sendingid = #{sendingid} and pointtoid = #{pointtoid}
    ) or (sendingid = #{pointtoid} and pointtoid = #{sendingid} ))
    AND  and rownum &lt;=10
    ORDER BY chattime
  </select>


  <select id="selectLimitByUserId"   resultMap="BaseResultMap">
    select * from (
      select
      ROW_NUMBER() Over(order by chattime desc) num, id, sendingid, sendingname, chattime, pointto, pointtoid, chattypes, chatcontent,
      remark1, remark2, remark3, numericdate, sendingip, receiveip
      from chatdetail
      where  ((sendingid = #{sendingid} and pointtoid = #{pointtoid}
      ) or (sendingid = #{pointtoid} and pointtoid = #{sendingid} ))
    ) where num &gt;=#{begin} and num &lt;=#{end}


  </select>


  <!-- <select id="selectLastInfoByUserId"  resultMap="BaseResultMap">
     select
     id, sendingid, sendingname, chattime, pointto, pointtoid, chattypes, chatcontent,
     remark1, remark2, remark3, numericdate, sendingip, receiveip
     from chatdetail
     where pointtoid = #{userid}
     AND   DATE_SUB(CURDATE(), INTERVAL 3 DAY) &lt;=chattime
     group by sendingid
     ORDER BY chattime desc
   </select>-->

  <select id="selectLastInfoByUserId"   resultMap="BaseResultMap">
    select * from (
      select
      ROW_NUMBER() Over(order by chattime desc) num, id, sendingid, sendingname, chattime, pointto, pointtoid, chattypes, chatcontent,
      remark1, remark2, remark3, numericdate, sendingip, receiveip
      from chatdetail
      where  ((sendingid = #{sendingid} and pointtoid = #{pointtoid}
      ) or (sendingid = #{pointtoid} and pointtoid = #{sendingid} ))
    ) where num = 1


  </select>
</mapper>