<?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.DemandInterestMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.DemandInterest" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <id column="uid" property="uid" jdbcType="VARCHAR" />
    <result column="demand_id" property="demandId" jdbcType="VARCHAR" />
    <result column="uid" property="uid" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, demand_id, uid, create_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from demand_interest
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from demand_interest
    where 1=1
      <if test="id != null" >
        and demand_id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="uid != null" >
        and uid = #{uid,jdbcType=VARCHAR}
      </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.DemandInterest" >
    insert into demand_interest (id, demand_id, uid, 
      create_time)
    values (#{id,jdbcType=VARCHAR}, #{demandId,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.DemandInterest" >
    insert into demand_interest
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="demandId != null" >
        demand_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="demandId != null" >
        #{demandId,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.DemandInterest" >
    update demand_interest
    <set >
      <if test="demandId != null" >
        demand_id = #{demandId,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.DemandInterest" >
    update demand_interest
    set demand_id = #{demandId,jdbcType=VARCHAR},
      uid = #{uid,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
   <select id="findDemandInterestListByPage" parameterType="String" resultType="com.goafanti.portal.bo.DemandInterestListBo">
  	select 
  		di.id, di.demand_id as demandId, di.create_time as createTime,
  		d.name, d.serial_number as serialNumber, d.deleted_sign as deletedSign,
  		d.audit_status as auditStatus, d.keyword, d.status
  	from demand_interest di
  	left join demand d on d.id = di.demand_id
  	where 1=1
  	<if test="uid != null">
  		and di.uid = #{uid,jdbcType=VARCHAR}
  	</if> 
  	order by di.create_time desc
  	<if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  
  <select id="findDemandInterestCount" parameterType="String" resultType="java.lang.Integer">
  	select 
  		count(1)
  	from demand_interest di
  	where 1=1
  	<if test="uid != null">
  		and	di.uid = #{uid,jdbcType=VARCHAR}
  	</if> 
  </select>
  
   <select id="selectDemandInterestByUidAndDemandId" resultMap="BaseResultMap"  >
    select 
    <include refid="Base_Column_List" />
    from demand_interest
    where uid = #{0} and demand_id = #{1}
  </select>
  
    <select id="countInterestById" resultType="Integer">
  	    select count(0) from demand_interest where 1=1  
  	    <if test="id != null">
  	       and demand_id = #{id,jdbcType=VARCHAR}
  	    </if> 
  </select>
  
  <select id="checkUidAndDid" resultType="Integer">
  		select count(0) from demand_interest where 1=1
  		<if test="uid != null">
  	       and uid = #{uid,jdbcType=VARCHAR}
  	    </if>
  	    <if test="id != null">
  	       and demand_id = #{id,jdbcType=VARCHAR}
  	    </if>
  </select>
  
   <delete id="deleteInterest" parameterType="java.lang.String" >
    delete from demand_interest
    where demand_id=#{objectId,jdbcType=VARCHAR}
    and uid=#{uid,jdbcType=VARCHAR}
  </delete>
  
  <select id="checkCount" resultType="Integer">
  		select count(0) from demand_interest where 1=1
  		<if test="uid != null">
  	      and demand_id = #{uid,jdbcType=VARCHAR}
  	    </if>
  	    
  </select>
</mapper>