<?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.TpActivityMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.TpActivity" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="community_id" property="communityId" jdbcType="INTEGER" />
    <result column="activity_title" property="activityTitle" jdbcType="VARCHAR" />
    <result column="activity_carousel_img" property="activityCarouselImg" jdbcType="VARCHAR" />
    <result column="activity_content" property="activityContent" jdbcType="LONGVARCHAR" />
    <result column="user_name" property="userName" jdbcType="VARCHAR" />
    <result column="sort" property="sort" jdbcType="INTEGER" />
    <result column="sign_up_count" property="signUpCount" jdbcType="INTEGER" />
    <result column="sign_up_max" property="signUpMax" jdbcType="INTEGER" />
    <result column="view_count" property="viewCount" jdbcType="INTEGER" />
    <result column="registration_start_time" property="registrationStartTime" jdbcType="TIMESTAMP" />
    <result column="registration_end_time" property="registrationEndTime" jdbcType="TIMESTAMP" />
    <result column="activity_start_time" property="activityStartTime" jdbcType="TIMESTAMP" />
    <result column="activity_end_time" property="activityEndTime" jdbcType="TIMESTAMP" />
    <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" />
    <result column="sign_in_code" property="signInCode" jdbcType="VARCHAR" />
    <result column="userRole" property="userRole"/>
    <result column="userName" property="userName"/>
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_id, activity_title, activity_carousel_img, activity_content, sort, 
    sign_up_count, sign_up_max, view_count, registration_start_time, registration_end_time, 
    activity_start_time, activity_end_time, status, create_user, create_date, update_user, 
    update_date,sign_in_code
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tp_activity
    where id = #{id,jdbcType=INTEGER} and community_id = #{communityId,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tp_activity
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.community.huiju.model.TpActivity" >
    insert into tp_activity (id, community_id, activity_title, 
      activity_carousel_img, activity_content, sort, 
      sign_up_count, sign_up_max, view_count, 
      registration_start_time, registration_end_time, 
      activity_start_time, activity_end_time, 
      status, create_user, create_date, 
      update_user, update_date,sign_in_code,sign_in_code,sign_in_code)
    values (#{id,jdbcType=INTEGER}, #{communityId,jdbcType=INTEGER}, #{activityTitle,jdbcType=VARCHAR}, 
      #{activityCarouselImg,jdbcType=VARCHAR}, #{activityContent,jdbcType=LONGVARCHAR}, #{sort,jdbcType=INTEGER},
      #{signUpCount,jdbcType=INTEGER}, #{signUpMax,jdbcType=INTEGER}, #{viewCount,jdbcType=INTEGER}, 
      #{registrationStartTime,jdbcType=TIMESTAMP}, #{registrationEndTime,jdbcType=TIMESTAMP}, 
      #{activityStartTime,jdbcType=TIMESTAMP}, #{activityEndTime,jdbcType=TIMESTAMP}, 
      #{status,jdbcType=CHAR}, #{createUser,jdbcType=INTEGER}, #{createDate,jdbcType=TIMESTAMP}, 
      #{updateUser,jdbcType=INTEGER}, #{updateDate,jdbcType=TIMESTAMP},#{signInCode,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.TpActivity" >
    insert into tp_activity
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="communityId != null" >
        community_id,
      </if>
      <if test="activityTitle != null" >
        activity_title,
      </if>
      <if test="activityCarouselImg != null" >
        activity_carousel_img,
      </if>
      <if test="activityContent != null" >
        activity_content,
      </if>
      <if test="sort != null" >
        sort,
      </if>
      <if test="signUpCount != null" >
        sign_up_count,
      </if>
      <if test="signUpMax != null" >
        sign_up_max,
      </if>
      <if test="viewCount != null" >
        view_count,
      </if>
      <if test="registrationStartTime != null" >
        registration_start_time,
      </if>
      <if test="registrationEndTime != null" >
        registration_end_time,
      </if>
      <if test="activityStartTime != null" >
        activity_start_time,
      </if>
      <if test="activityEndTime != null" >
        activity_end_time,
      </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>
      <if test="signInCode != null" >
        sign_in_code
      </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="activityTitle != null" >
        #{activityTitle,jdbcType=VARCHAR},
      </if>
      <if test="activityCarouselImg != null" >
        #{activityCarouselImg,jdbcType=VARCHAR},
      </if>
      <if test="activityContent != null" >
        #{activityContent,jdbcType=LONGVARCHAR},
      </if>
      <if test="sort != null" >
        #{sort,jdbcType=INTEGER},
      </if>
      <if test="signUpCount != null" >
        #{signUpCount,jdbcType=INTEGER},
      </if>
      <if test="signUpMax != null" >
        #{signUpMax,jdbcType=INTEGER},
      </if>
      <if test="viewCount != null" >
        #{viewCount,jdbcType=INTEGER},
      </if>
      <if test="registrationStartTime != null" >
        #{registrationStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="registrationEndTime != null" >
        #{registrationEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="activityStartTime != null" >
        #{activityStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="activityEndTime != null" >
        #{activityEndTime,jdbcType=TIMESTAMP},
      </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>
      <if test="signInCode != null" >
        #{signInCode,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.TpActivity" >
    update tp_activity
    <set >
      <if test="communityId != null" >
        community_id = #{communityId,jdbcType=INTEGER},
      </if>
      <if test="activityTitle != null" >
        activity_title = #{activityTitle,jdbcType=VARCHAR},
      </if>
      <if test="activityCarouselImg != null" >
        activity_carousel_img = #{activityCarouselImg,jdbcType=VARCHAR},
      </if>
      <if test="activityContent != null" >
        activity_content = #{activityContent,jdbcType=LONGVARCHAR},
      </if>
      <if test="sort != null" >
        sort = #{sort,jdbcType=INTEGER},
      </if>
      <if test="signUpCount != null" >
        sign_up_count = #{signUpCount,jdbcType=INTEGER},
      </if>
      <if test="signUpMax != null" >
        sign_up_max = #{signUpMax,jdbcType=INTEGER},
      </if>
      <if test="viewCount != null" >
        view_count = #{viewCount,jdbcType=INTEGER},
      </if>
      <if test="registrationStartTime != null" >
        registration_start_time = #{registrationStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="registrationEndTime != null" >
        registration_end_time = #{registrationEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="activityStartTime != null" >
        activity_start_time = #{activityStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="activityEndTime != null" >
        activity_end_time = #{activityEndTime,jdbcType=TIMESTAMP},
      </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>
      <if test="signInCode != null" >
        sign_in_code = #{signInCode,jdbcType=VARCHAR}
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.TpActivity" >
    update tp_activity
    set community_id = #{communityId,jdbcType=INTEGER},
      activity_title = #{activityTitle,jdbcType=VARCHAR},
      activity_carousel_img = #{activityCarouselImg,jdbcType=VARCHAR},
      activity_content = #{activityContent,jdbcType=LONGVARCHAR},
      sort = #{sort,jdbcType=INTEGER},
      sign_up_count = #{signUpCount,jdbcType=INTEGER},
      sign_up_max = #{signUpMax,jdbcType=INTEGER},
      view_count = #{viewCount,jdbcType=INTEGER},
      registration_start_time = #{registrationStartTime,jdbcType=TIMESTAMP},
      registration_end_time = #{registrationEndTime,jdbcType=TIMESTAMP},
      activity_start_time = #{activityStartTime,jdbcType=TIMESTAMP},
      activity_end_time = #{activityEndTime,jdbcType=TIMESTAMP},
      status = #{status,jdbcType=CHAR},
      create_user = #{createUser,jdbcType=INTEGER},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER},
      update_date = #{updateDate,jdbcType=TIMESTAMP},
      sign_in_code = #{signInCode,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="getActivitys" resultMap="BaseResultMap">
    SELECT
      a.id,
      a.activity_title,
      a.activity_content,
      a.create_date,
      u.user_name AS user_name,
      a.sort,
      a.view_count,
      a.sign_up_count
  FROM
      tp_activity 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.activity_title LIKE concat('%',#{title,jdbcType=VARCHAR},'%')
    </if>
  ORDER BY
      a.sort DESC,
      a.activity_end_time DESC,
      a.update_date DESC,
	  a.create_date DESC
  </select>

  <select id="getActivity" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tp_activity
    where community_id = #{communityId,jdbcType=INTEGER}  and status=1  order by create_date DESC limit  #{num,jdbcType=INTEGER}
  </select>

  <select id="selecttpActivity" resultMap="BaseResultMap">
    SELECT
    a.*,
    tu.user_name as userName
    FROM
    tp_activity a
    LEFT JOIN tp_activity_sign_up tr ON tr.activity_id = a.id
    LEFT JOIN tp_user tu ON a.create_user = tu.id
    WHERE tr.ta_user_id = #{id}
    AND tr.community_id =#{communityId}
    order by a.create_date desc
  </select>
  <select id="selectActivity" resultMap="BaseResultMap">
    select * from tp_activity where id = #{activityId}
  </select>
</mapper>