<?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.StarMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.Star" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="uid" property="uid" jdbcType="VARCHAR" />
    <result column="hot" property="hot" jdbcType="INTEGER" />
    <result column="star" property="star" jdbcType="INTEGER" />
    <result column="portal_url" property="portalUrl" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, uid, hot, star, portal_url
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from star
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from star
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.Star" >
    insert into star (id, uid, hot, 
      star, portal_url)
    values (#{id,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, #{hot,jdbcType=INTEGER}, 
      #{star,jdbcType=INTEGER}, #{portalUrl,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.Star" >
    insert into star
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="uid != null" >
        uid,
      </if>
      <if test="hot != null" >
        hot,
      </if>
      <if test="star != null" >
        star,
      </if>
      <if test="portalUrl != null" >
        portal_url,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="uid != null" >
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="hot != null" >
        #{hot,jdbcType=INTEGER},
      </if>
      <if test="star != null" >
        #{star,jdbcType=INTEGER},
      </if>
      <if test="portalUrl != null" >
        #{portalUrl,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.Star" >
    update star
    <set >
      <if test="uid != null" >
        uid = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="hot != null" >
        hot = #{hot,jdbcType=INTEGER},
      </if>
      <if test="star != null" >
        star = #{star,jdbcType=INTEGER},
      </if>
      <if test="portalUrl != null" >
        portal_url = #{portalUrl,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.Star" >
    update star
    set uid = #{uid,jdbcType=VARCHAR},
      hot = #{hot,jdbcType=INTEGER},
      star = #{star,jdbcType=INTEGER},
      portal_url = #{portalUrl,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="listHostStar"  resultType="com.goafanti.star.bo.HotStarListBo">
  	select
  		u.id as uid,
  		u.number,
  		ui.username,
  		uc.engaged_field as engagedField,
  		uc.professional_title as professionalTitle,
  		uc.work_unit as workUnit,
  		adc.achievement_count as achievementNum
  	from star s
  	left join user u on u.id = s.uid
  	left join user_identity ui on ui.uid = s.uid
  	left join user_career uc on uc.uid = s.uid
  	left join achievement_demand_count adc on adc.uid = s.uid 
  	where s.hot = 1 and ui.celebrity = 1
  	order by adc.achievement_count desc
  </select>
  
  <select id="listStarList"  parameterType="java.lang.String" resultType="com.goafanti.star.bo.HotStarListBo">
  	select
  		u.id as uid,
  		u.number,
  		ui.username,
  		uc.engaged_field as engagedField,
  		uc.professional_title as professionalTitle,
  		uc.work_unit as workUnit,
  		adc.achievement_count as achievementNum,
  		u.head_portrait_url as personPortraitUrl
  	from star s
  	left join user u on u.id = s.uid
  	left join user_identity ui on ui.uid = s.uid
  	left join user_career uc on uc.uid = s.uid
  	left join achievement_demand_count adc on adc.uid = s.uid 
  	<!-- left join user_info info on info.uid = s.uid -->
  	left join user_interest interest on interest.to_uid = s.uid and interest.from_uid = #{uid,jdbcType=VARCHAR}
  	where s.star = 1 and ui.celebrity = 1
  	order by adc.achievement_count desc
  </select>
  
  <delete id="deleteAll">
  	delete from star
  </delete>
  
   <insert id="insertBatch" parameterType="com.goafanti.common.model.Star">
    insert into star (id, uid, hot, star, portal_url)
    values 
    <foreach item="item" index="index" collection="list" separator=",">
      (
      	#{item.id,jdbcType=VARCHAR}, #{item.uid,jdbcType=VARCHAR}, #{item.hot,jdbcType=INTEGER},
      	#{item.star,jdbcType=INTEGER}, #{item.portalUrl,jdbcType=VARCHAR}
      )
    </foreach>
  </insert>
  
  <select id="listBigShotStar" parameterType="java.lang.String" resultType="com.goafanti.star.bo.BigShotStarListBo">
  	select
  		u.id as uid,
  		u.number,
  		ui.username,
  		uc.engaged_field as engagedField,
  		uc.professional_title as professionalTitle,
  		uc.work_unit as workUnit,
  		adc.achievement_count as achievementNum,
  		u.head_portrait_url as personPortraitUrl,
  		interest.id as interestId
  	from star s
  	left join user u on u.id = s.uid
  	left join user_info info on info.uid = s.uid
  	left join user_identity ui on ui.uid = s.uid
  	left join user_career uc on uc.uid = s.uid
  	left join achievement_demand_count adc on adc.uid = s.uid 
  	left join user_interest interest on interest.to_uid = s.uid and interest.from_uid = #{uid,jdbcType=VARCHAR}
  	where s.hot = 1 
  	order by adc.achievement_count desc
  </select>
  
  <select id="findBigShotInterestStatus" parameterType="java.lang.String" resultType="com.goafanti.star.bo.BigShotStarInterest">
  	select
  		ui.id as interestId,
  		s.uid as fromUid,
  		ui.to_uid as toUid
  	from star s
  	left join user_interest ui on s.uid = ui.to_uid and ui.from_uid = #{uid,jdbcType=VARCHAR} 
  	where  s.hot = 1 
  </select>
  
  <select id="findStarInterestStatus" parameterType="java.lang.String" resultType="com.goafanti.star.bo.BigShotStarInterest">
  	select
  		ui.id as interestId,
  		s.uid as fromUid,
  		ui.to_uid as toUid
  	from star s
  	left join user_interest ui on s.uid = ui.to_uid and ui.from_uid = #{uid,jdbcType=VARCHAR} 
  	where  s.star = 1 
  </select>
</mapper>