<?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.cab.dao.CabMymessageMapper" >
  <resultMap id="BaseResultMap" type="com.cab.model.CabMymessage" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="sys_user_id" property="sysUserId" jdbcType="INTEGER" />
    <result column="title" property="title" jdbcType="VARCHAR" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="status" property="status" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, type, title, content, create_time,sys_user_id,status
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from cab_pub_mymessage
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from cab_pub_mymessage
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.cab.model.CabMymessage" >
    insert into cab_pub_mymessage (id, type, sys_user_id,
      title, content,
      create_time,status)
    values (#{id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},  #{sysUserId,jdbcType=INTEGER},
      #{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR},
      #{createTime,jdbcType=TIMESTAMP},#{status,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.cab.model.CabMymessage" >
    insert into cab_pub_mymessage
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="type != null" >
        type,
      </if>
      <if test="sysUserId != null" >
        sys_user_id,
      </if>
      <if test="title != null" >
        title,
      </if>
      <if test="content != null" >
        content,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="status != null" >
        status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="type != null" >
        #{type,jdbcType=INTEGER},
      </if>
      <if test="sysUserId != null" >
        #{sysUserId,jdbcType=INTEGER},
      </if>
      <if test="title != null" >
        #{title,jdbcType=VARCHAR},
      </if>
      <if test="content != null" >
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null" >
        #{status,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.cab.model.CabMymessage" >
    update cab_pub_mymessage
    <set >
      <if test="type != null" >
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="sysUserId != null" >
        sys_user_id = #{sysUserId,jdbcType=INTEGER},
      </if>
      <if test="title != null" >
        title = #{title,jdbcType=VARCHAR},
      </if>
      <if test="content != null" >
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.cab.model.CabMymessage" >
    update cab_pub_mymessage
    set type = #{type,jdbcType=INTEGER},
      sys_user_id = #{sysUserId,jdbcType=INTEGER},
      title = #{title,jdbcType=VARCHAR},
      content = #{content,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      status = #{status,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <!-- 自定义 -->
  <resultMap id="getListResultMap" type="com.cab.model.CabMymessage" extends="BaseResultMap" >
    <association property="sysUser" column="sys_user_id" javaType="com.sys.model.SysUser">
      <result  column="user_name" property="userName"/>
    </association>
  </resultMap>
  <select id="getList" resultMap="getListResultMap" parameterType="java.lang.Integer" >
    select id, type, title, content, create_time,sys_user_id ,status,u.user_name from cab_pub_mymessage c left join sys_user u on c.sys_user_id = u.user_id
    where 1=1
    <if test="type!= null">
      and type = #{type,jdbcType=INTEGER}
    </if>
    <if test="title !=null " >
      and title like '%${title}%'
    </if>
    order by create_time desc
    limit #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
  </select>
  <select id="getCount" resultType="java.lang.Long" parameterType="java.lang.Integer" >
    select count(*) from cab_pub_mymessage
    where 1=1
    <if test="type!= null">
      and type = #{type,jdbcType=INTEGER}
    </if>
    <if test="title !=null " >
      and title like '%${title}%'
    </if>
  </select>

  <insert id="insertUserMessage" parameterType="com.cab.model.CabMymessage" >
    insert into cab_mymessage (type, user_id,
    title, content,
    create_time,isread,pub_id)
    values
    <foreach collection="list" item="item" index="index" separator="," >
      ( #{item.type,jdbcType=INTEGER},  #{item.userId,jdbcType=INTEGER},
      #{item.title,jdbcType=VARCHAR}, #{item.content,jdbcType=VARCHAR},
      #{item.createTime,jdbcType=TIMESTAMP},0, #{item.id,jdbcType=INTEGER})
    </foreach>
  </insert>

<!--  ( #{type,jdbcType=INTEGER},  #{userId,jdbcType=INTEGER},
  #{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR},
  #{createTime,jdbcType=TIMESTAMP},0, #{id,jdbcType=INTEGER})-->
</mapper>