<?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.community.huiju.dao.TpAnnouncementMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.TpAnnouncement" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="community_id" property="communityId" jdbcType="INTEGER" />
    <result column="announcement_title" property="announcementTitle" jdbcType="VARCHAR" />
    <result column="announcement_carousel_img" property="announcementCarouselImg" jdbcType="VARCHAR" />
    <result column="announcement_content" property="announcementContent" jdbcType="LONGVARCHAR" />
    <result column="user_name" property="userName" jdbcType="VARCHAR" />
    <result column="sort" property="sort" jdbcType="INTEGER" />
    <result column="view_count" property="viewCount" jdbcType="INTEGER" />
    <result column="set_up_carousel" property="setUpCarousel" jdbcType="CHAR" />
    <result column="status" property="status" jdbcType="CHAR" />
    <result column="create_user" property="createUser" jdbcType="INTEGER" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
    <result column="update_user" property="updateUser" jdbcType="INTEGER" />
    <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_id, announcement_title, announcement_carousel_img, announcement_content, 
    sort, view_count, set_up_carousel, status, create_user, create_date, update_user, 
    update_date
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tp_announcement
    where id = #{id,jdbcType=INTEGER} and community_id = #{communityId,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tp_announcement
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.community.huiju.model.TpAnnouncement" >
    insert into tp_announcement (id, community_id, announcement_title, 
      announcement_carousel_img, announcement_content, 
      sort, view_count, set_up_carousel, 
      status, create_user, create_date, 
      update_user, update_date)
    values (#{id,jdbcType=INTEGER}, #{communityId,jdbcType=INTEGER}, #{announcementTitle,jdbcType=VARCHAR}, 
      #{announcementCarouselImg,jdbcType=VARCHAR}, #{announcementContent,jdbcType=VARCHAR}, 
      #{sort,jdbcType=INTEGER}, #{viewCount,jdbcType=INTEGER}, #{setUpCarousel,jdbcType=CHAR}, 
      #{status,jdbcType=CHAR}, #{createUser,jdbcType=INTEGER}, #{createDate,jdbcType=TIMESTAMP}, 
      #{updateUser,jdbcType=INTEGER}, #{updateDate,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.TpAnnouncement" >
    insert into tp_announcement
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="communityId != null" >
        community_id,
      </if>
      <if test="announcementTitle != null" >
        announcement_title,
      </if>
      <if test="announcementCarouselImg != null" >
        announcement_carousel_img,
      </if>
      <if test="announcementContent != null" >
        announcement_content,
      </if>
      <if test="sort != null" >
        sort,
      </if>
      <if test="viewCount != null" >
        view_count,
      </if>
      <if test="setUpCarousel != null" >
        set_up_carousel,
      </if>
      <if test="status != null" >
        status,
      </if>
      <if test="createUser != null" >
        create_user,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
      <if test="updateUser != null" >
        update_user,
      </if>
      <if test="updateDate != null" >
        update_date,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="communityId != null" >
        #{communityId,jdbcType=INTEGER},
      </if>
      <if test="announcementTitle != null" >
        #{announcementTitle,jdbcType=VARCHAR},
      </if>
      <if test="announcementCarouselImg != null" >
        #{announcementCarouselImg,jdbcType=VARCHAR},
      </if>
      <if test="announcementContent != null" >
        #{announcementContent,jdbcType=VARCHAR},
      </if>
      <if test="sort != null" >
        #{sort,jdbcType=INTEGER},
      </if>
      <if test="viewCount != null" >
        #{viewCount,jdbcType=INTEGER},
      </if>
      <if test="setUpCarousel != null" >
        #{setUpCarousel,jdbcType=CHAR},
      </if>
      <if test="status != null" >
        #{status,jdbcType=CHAR},
      </if>
      <if test="createUser != null" >
        #{createUser,jdbcType=INTEGER},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null" >
        #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null" >
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" >
    update tp_announcement
    <set >
      <if test="viewCount != null" >
        view_count = #{viewCount,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.TpAnnouncement" >
    update tp_announcement
    set community_id = #{communityId,jdbcType=INTEGER},
      announcement_title = #{announcementTitle,jdbcType=VARCHAR},
      announcement_carousel_img = #{announcementCarouselImg,jdbcType=VARCHAR},
      announcement_content = #{announcementContent,jdbcType=LONGVARCHAR},
      sort = #{sort,jdbcType=INTEGER},
      view_count = #{viewCount,jdbcType=INTEGER},
      set_up_carousel = #{setUpCarousel,jdbcType=CHAR},
      status = #{status,jdbcType=CHAR},
      create_user = #{createUser,jdbcType=INTEGER},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER},
      update_date = #{updateDate,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="getAnnouncements" resultMap="BaseResultMap">
    SELECT
      a.id,
      a.announcement_title,
      a.announcement_content,
      a.create_date,
      u.user_name as user_name,
      a.sort,
      a.view_count
  FROM
      tp_announcement a
      LEFT JOIN tp_user u ON a.create_user = u.id
      AND u.community_id = #{communityId,jdbcType=INTEGER}
  WHERE
      a.community_id = #{communityId,jdbcType=INTEGER}
      AND ( a.STATUS = 1 OR a.STATUS = 3 )
      <if test="title != null and title != ''">
        and a.announcement_title like concat('%',#{title,jdbcType=VARCHAR},'%')
      </if>
  ORDER BY
      a.sort DESC,
      a.update_date DESC,
      a.create_date DESC
  </select>

  <select id="getAnnouncement" resultMap="BaseResultMap" parameterType="com.community.huiju.model.TpAnnouncement">
    select
    <include refid="Base_Column_List" />
    from tp_announcement
    where community_id = #{communityId,jdbcType=INTEGER}  and status=1  order by create_date DESC limit  #{sum,jdbcType=INTEGER}
  </select>
</mapper>