<?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.AlumniOrganizeUserCustomMapper">

  <resultMap id="BaseResultMap" type="com.dgtis.dorm.manager.db.domain.AlumniOrganizeUserCustom">
      <id column="id" jdbcType="INTEGER" property="id" />
      <result column="fk_organize_id" jdbcType="INTEGER" property="fkOrganizeId" />
      <result column="fk_user_id" jdbcType="INTEGER" property="fkUserId" />
      <result column="is_normal" jdbcType="VARCHAR" property="isNormal" />
      <result column="pri_type" jdbcType="VARCHAR" property="priType" />
      <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
      <result column="auth_user_id" jdbcType="INTEGER" property="authUserId" />
      <result column="auth_date" jdbcType="TIMESTAMP" property="authDate" />
      <result column="auth_memo" jdbcType="VARCHAR" property="authMemo" />
      <result column="is_delete" jdbcType="BIT" property="isDelete" />
      <result column="delete_memo" jdbcType="VARCHAR" property="deleteMemo" />
      <result column="delete_date" jdbcType="TIMESTAMP" property="deleteDate" />
      <result column="is_forbidden" jdbcType="BIT" property="isForbidden" />
      <result column="modify_date" jdbcType="TIMESTAMP" property="modifyDate" />
      <result column="modify_user_id" jdbcType="INTEGER" property="modifyUserId" />
      <result column="user_memo" jdbcType="VARCHAR" property="userMemo" />
  </resultMap>

    <resultMap id="CustomResultMap" type="com.dgtis.dorm.manager.db.domain.AlumniOrganizeUserCustom" extends="BaseResultMap">
        <result column="user_name" jdbcType="VARCHAR" property="userName" />
        <result column="tem_role_type" property="temRoleType" jdbcType="VARCHAR" />
        <result column="role_type" property="roleType" jdbcType="VARCHAR" />
        <result column="gender" property="gender" jdbcType="VARCHAR" />
        <result column="degree" property="degree" jdbcType="VARCHAR" />
        <result column="begin_date" property="beginDate" jdbcType="TIMESTAMP" />
        <result column="graduation_date" property="graduationDate" jdbcType="TIMESTAMP" />
        <result column="working" property="working" jdbcType="VARCHAR" />
        <result column="position" property="position" jdbcType="VARCHAR" />
        <result column="place" property="place" jdbcType="VARCHAR" />
        <result column="guider" property="guider" jdbcType="VARCHAR" />
        <result column="photo" property="photo" jdbcType="VARCHAR" />
        <result column="sign" property="sign" jdbcType="VARCHAR" />
        <result column="email" property="email" jdbcType="VARCHAR" />
        <result column="phone" property="phone" jdbcType="VARCHAR" />
        <result column="organize_name" property="organizeName" jdbcType="VARCHAR" />
    </resultMap>


    <sql id="Base_Column_List">
    id, fk_organize_id, fk_user_id, is_normal, pri_type, create_date, auth_user_id, auth_date, 
    auth_memo, is_delete, delete_memo, delete_date, is_forbidden, modify_date, modify_user_id,
    user_memo
  </sql>



    <select id="selectOrganizeUserBySelective" parameterType="com.dgtis.dorm.manager.db.domain.AlumniOrganizeUserCustom" resultMap="CustomResultMap">
        SELECT
            ou.id,
            ou.fk_organize_id,
            ou.fk_user_id,
            ou.is_normal,
            ou.pri_type,
            ou.create_date,
            ou.auth_user_id,
            ou.auth_date,
            ou.auth_memo,
            ou.user_memo,
            ou.is_delete,
            ou.delete_memo,
            ou.delete_date,
            ou.is_forbidden,
            ou.modify_date,
            ou.modify_user_id,
            u.user_name,
            u.`tem_role_type`,
            u.`role_type`,
            u.`gender`,
            u.`degree`,
            u.`begin_date`,
            u.`graduation_date`,
            u.`working`,
            u.`position`,
            u.`place`,
            u.`guider`,
            u.`photo`,
            u.`sign`,
            u.`email`,
            u.`phone`,
            o.`organize_name`
        FROM zhll_organize_user ou
            LEFT JOIN zhll_user u ON ou.fk_user_id = u.id
            LEFT JOIN zhll_organize o ON o.id = ou.`fk_organize_id`
        WHERE 1 = 1
            <if test="id != null">
                AND ou.id = #{id,jdbcType=INTEGER}
            </if>
            <if test="fkOrganizeId != null">
                AND ou.fk_organize_id = #{fkOrganizeId,jdbcType=INTEGER}
            </if>
            <if test="fkUserId != null and fkUserId != ''">
                AND ou.fk_user_id = #{fkUserId,jdbcType=INTEGER}
            </if>
            <if test="isNormal != null">
                AND ou.is_normal = #{isNormal,jdbcType=VARCHAR}
            </if>
            <if test="priType != null">
                AND ou.pri_type = #{priType,jdbcType=VARCHAR}
            </if>
            <if test="authUserId != null">
                AND ou.auth_user_id = #{authUserId,jdbcType=INTEGER}
            </if>
            <if test="isDelete != null">
                AND ou.is_delete = #{isDelete,jdbcType=BIT}
            </if>
            <if test="isForbidden != null">
                AND ou.is_forbidden = #{isForbidden,jdbcType=BIT}
            </if>
            <if test="modifyUserId != null">
                AND ou.modify_user_id= #{modifyUserId,jdbcType=INTEGER}
            </if>
            <if test="userName != null and userName != ''">
                AND u.user_name= #{userName,jdbcType=VARCHAR}
            </if>
            <if test="exclusiveOrgUserId != null and exclusiveOrgUserId.size() > 0">
                AND ou.id NOT IN
                <foreach collection="exclusiveOrgUserId" index="index" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>

    </select>
    
    <select id="selectOrganizeNoNormalByUserIdAndOrgId" parameterType="java.lang.Integer" resultMap="CustomResultMap" >
        SELECT
            ou.id,
            ou.fk_organize_id,
            ou.fk_user_id,
            ou.is_normal,
            ou.pri_type,
            ou.create_date,
            ou.auth_user_id,
            ou.auth_date,
            ou.auth_memo,
            ou.is_delete,
            ou.delete_memo,
            ou.delete_date,
            ou.is_forbidden,
            ou.modify_date,
            ou.modify_user_id,
            ou.user_memo,
            u.user_name,
            u.`tem_role_type`,
            u.`role_type`,
            u.`gender`,
            u.`degree`,
            u.`begin_date`,
            u.`graduation_date`,
            u.`working`,
            u.`position`,
            u.`place`,
            u.`guider`,
            u.`photo`,
            u.`sign`,
            u.`email`,
            u.`phone`,
            o.organize_name
        FROM zhll_organize_user a
            LEFT JOIN zhll_organize_user ou ON a.`fk_organize_id` = ou.`fk_organize_id`
            LEFT JOIN zhll_user u ON u.id = ou.fk_user_id
            LEFT JOIN zhll_organize o on o.id = ou.fk_organize_id
        WHERE 1 = 1
            AND ou.`is_normal` = 0
            AND a.pri_type IN ("1", "2")
            AND a.fk_user_id = #{adminUserId,jdbcType=INTEGER}
            <if test="OrgId != null">
                AND a.fk_organize_id = #{OrgId,jdbcType=INTEGER}
            </if>

    </select>


</mapper>