<?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.goafanti.common.dao.AchievementInterestMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.AchievementInterest" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="achievement_id" property="achievementId" jdbcType="VARCHAR" />
    <result column="uid" property="uid" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, achievement_id, uid, create_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from achievement_interest
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from achievement_interest
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.AchievementInterest" >
    insert into achievement_interest (id, achievement_id, uid, 
      create_time)
    values (#{id,jdbcType=VARCHAR}, #{achievementId,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.AchievementInterest" >
    insert into achievement_interest
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="achievementId != null" >
        achievement_id,
      </if>
      <if test="uid != null" >
        uid,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="achievementId != null" >
        #{achievementId,jdbcType=VARCHAR},
      </if>
      <if test="uid != null" >
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.AchievementInterest" >
    update achievement_interest
    <set >
      <if test="achievementId != null" >
        achievement_id = #{achievementId,jdbcType=VARCHAR},
      </if>
      <if test="uid != null" >
        uid = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.AchievementInterest" >
    update achievement_interest
    set achievement_id = #{achievementId,jdbcType=VARCHAR},
      uid = #{uid,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="findAchievementInterestListByPage" parameterType="String" resultType="com.goafanti.portal.bo.AchievementInterestListBo">
  	select 
  		ai.id, ai.achievement_id as achievementId, ai.create_time as createTime,
  		a.name, a.serial_number as serialNumber, a.deleted_sign as deletedSign,
  		a.audit_status as auditStatus, a.keyword
  	from achievement_interest ai
  	left join achievement a on a.id = ai.achievement_id
  	where 1=1
  	<if test="uid != null">
  		and ai.uid = #{uid,jdbcType=VARCHAR}
  	</if> 
  	order by ai.create_time desc
  	<if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  
  <select id="findAchievementInterestCount" parameterType="String" resultType="java.lang.Integer">
  	select 
  		count(1)
  	from achievement_interest ai
  	where 1=1
  	<if test="uid != null">
  		and	ai.uid = #{uid,jdbcType=VARCHAR}
  	</if> 
  </select>
  
  <select id="selectAchievementInterestByUidAndAchievementId" resultMap="BaseResultMap">
  	select  
  	<include refid="Base_Column_List" />
    from achievement_interest
    where uid = #{0} and achievement_id = #{1}
  </select>
   <select id="checkUidAndDid" resultType="Integer">
  		select count(0) from achievement_interest where 1=1
  		<if test="uid != null">
  	       and uid = #{uid,jdbcType=VARCHAR}
  	    </if>
  	    <if test="id != null">
  	       and achievement_id = #{id,jdbcType=VARCHAR}
  	    </if>
  </select>
  <delete id="deleteInterest" parameterType="java.lang.String" >
    delete from achievement_interest
    where uid = #{uid,jdbcType=VARCHAR}
    and achievement_id=#{objectId,jdbcType=VARCHAR}
  </delete>
</mapper>