<?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.dgtis.dorm.manager.db.dao.AlumniFriUserMapper" >
  <resultMap id="BaseResultMap" type="com.dgtis.dorm.manager.db.domain.AlumniFriUser" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="fri_user_id" property="friUserId" jdbcType="INTEGER" />
    <result column="fk_user_id" property="fkUserId" jdbcType="INTEGER" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, fri_user_id, fk_user_id, create_date
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from zhll_fri_user
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from zhll_fri_user
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.dgtis.dorm.manager.db.domain.AlumniFriUser" >
    insert into zhll_fri_user (id, fri_user_id, fk_user_id,
      create_date)
    values (#{id,jdbcType=INTEGER}, #{friUserId,jdbcType=INTEGER}, #{fkUserId,jdbcType=INTEGER}, 
      #{createDate,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.dgtis.dorm.manager.db.domain.AlumniFriUser" >
    insert into zhll_fri_user
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="friUserId != null" >
        fri_user_id,
      </if>
      <if test="fkUserId != null" >
        fk_user_id,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="friUserId != null" >
        #{friUserId,jdbcType=INTEGER},
      </if>
      <if test="fkUserId != null" >
        #{fkUserId,jdbcType=INTEGER},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.dgtis.dorm.manager.db.domain.AlumniFriUser" >
    update zhll_fri_user
    <set >
      <if test="friUserId != null" >
        fri_user_id = #{friUserId,jdbcType=INTEGER},
      </if>
      <if test="fkUserId != null" >
        fk_user_id = #{fkUserId,jdbcType=INTEGER},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dgtis.dorm.manager.db.domain.AlumniFriUser" >
    update zhll_fri_user
    set fri_user_id = #{friUserId,jdbcType=INTEGER},
      fk_user_id = #{fkUserId,jdbcType=INTEGER},
      create_date = #{createDate,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
  <select id="selectUserByFKUserId" parameterType="java.lang.Integer" resultType="java.util.Map">
  	select au.id, au.en_user_name, au.user_name, au.begin_date, au.gender, au.role_type, au.degree, au.photo, au.sign, au.place, au.guider 
  	 from zhll_fri_user fu LEFT JOIN zhll_user au ON fu.fri_user_id = au.id
		where fu.fk_user_id = #{userId,jdbcType=INTEGER}
		and au.user_name is not null 
		ORDER BY au.en_user_name asc, au.id asc 
  </select>
  
  <select id="selectFriUser" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  	select 
	<include refid="Base_Column_List" />
    from zhll_fri_user
    where 
    fk_user_id = #{userId,jdbcType=INTEGER} 
    and fri_user_id = #{friUserId,jdbcType=INTEGER} 
  </select>
  
  <select id="selectUserConcerned" resultType="java.util.Map" >
  	select au.id, au.en_user_name, au.user_name, au.begin_date, au.gender, au.role_type, au.degree, au.photo, au.sign, au.place, au.guider  
  	 from zhll_fri_user fu LEFT JOIN zhll_user au ON fu.fri_user_id = au.id
		where fu.fk_user_id = #{userId,jdbcType=INTEGER}
		<if test="valString != null and valString != ''">
          and (
          au.user_name like concat('%', #{valString}, '%')
          or au.role_type = #{valString}
          or au.working = #{valString}
          or au.place like concat('%', #{valString}, '%')
          or au.phone = #{valString}
          )
    	</if>
    	ORDER BY au.en_user_name asc, au.id asc 
    	LIMIT 0,100
  </select>
</mapper>