<?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" >
  <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="getAnnouncements" resultType="com.community.huiju.model.TpAnnouncement">
    SELECT
    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
   FROM
      tp_announcement
      <where>
        <if test="record.id != null" >
          AND id like concat('%',#{record.id,jdbcType=VARCHAR},'%')
        </if>
        <if test="record.announcementTitle != null and record.announcementTitle != ''" >
          AND announcement_title like concat('%',#{record.announcementTitle,jdbcType=VARCHAR},'%')
        </if>
          AND community_id = #{record.communityId,jdbcType=INTEGER}
          ORDER BY sort DESC,create_date desc
      </where>
  </select>
  <select id="getById" resultType="com.community.huiju.model.TpAnnouncement">
    SELECT
    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
    FROM
    tp_announcement
    WHERE community_id = #{record.communityId,jdbcType=INTEGER}
  </select>
  <update id="updateTpAnnouncement" parameterType="com.community.huiju.model.TpAnnouncement" >
    update tp_announcement
    <set >
      <if test="communityId != null" >
        community_id = #{communityId,jdbcType=INTEGER},
      </if>
      <if test="announcementTitle != null" >
        announcement_title = #{announcementTitle,jdbcType=VARCHAR},
      </if>
      <if test="announcementCarouselImg != null and announcementCarouselImg !=''">
        announcement_carousel_img = #{announcementCarouselImg,jdbcType=VARCHAR},
      </if>
      <if test="announcementContent != null" >
        announcement_content = #{announcementContent,jdbcType=VARCHAR},
      </if>
      <if test="sort != null" >
        sort = #{sort,jdbcType=INTEGER},
      </if>
      <if test="viewCount != null" >
        view_count = #{viewCount,jdbcType=INTEGER},
      </if>
      <if test="setUpCarousel != null" >
        set_up_carousel = #{setUpCarousel,jdbcType=CHAR},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=CHAR},
      </if>
      <if test="createUser != null" >
        create_user = #{createUser,jdbcType=INTEGER},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null" >
        update_user = #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null" >
        update_date = #{updateDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>