<?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.diagbot.mapper.UserMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.User">
        <id column="id" property="id" />
        <result column="is_deleted" property="isDeleted" />
        <result column="gmt_create" property="gmtCreate" />
        <result column="gmt_modified" property="gmtModified" />
        <result column="creator" property="creator" />
        <result column="modifier" property="modifier" />
        <result column="username" property="username" />
        <result column="password" property="password" />
        <result column="linkman" property="linkman" />
        <result column="phone" property="phone" />
        <result column="position" property="position" />
        <result column="dept" property="dept" />
        <result column="email" property="email" />
        <result column="auth_status" property="authStatus" />
        <result column="passauth_time" property="passauthTime" />
        <result column="type" property="type" />
        <result column="remark" property="remark" />
    </resultMap>

    <resultMap id="UserOrgDTO" type="com.diagbot.dto.UserOrgDTO">
        <id column="user_id" property="userId"/>
        <result column="username" property="username"/>
        <result column="linkman" property="linkman"/>
        <result column="email" property="email"/>
        <result column="org_id" property="orgId"/>
        <result column="org_name" property="orgName"/>
        <result column="is_reject" property="isReject"/>
        <result column="au_status" property="auStatus"/>
        <result column="sub_num" property="subNum"/>
    </resultMap>


    <select id="findByName" resultMap="BaseResultMap" parameterType="java.lang.String">
        select * from sys_user
        where username = #{username} and is_deleted = 'N'
    </select>

    <select id="selectUserListPage" resultMap="BaseResultMap">
        select u.*
        from sys_user u
        LEFT JOIN sys_user_role ur on u.id= ur.user_id
        LEFT JOIN sys_role r on ur.role_id=r.id
        where u.is_deleted = 'N'
        <if test="user.id != null">
            and u.id = #{user.id}
        </if>
    </select>


    <select id="indexPage" resultMap="BaseResultMap">
        select u.* from sys_user u where u.is_deleted = 'N'
        <if test="user.id != null">
            and u.id = #{user.id}
        </if>
        <if test="user.username != null and user.username != '' ">
            and u.username like concat('%',#{user.username},'%')
        </if>
    </select>

    <select id="getByIds" resultMap="BaseResultMap">
        select u.* from sys_user u where u.is_deleted = 'N'
        and u.id in
        <foreach collection="list" item="ids" open="(" close=")" separator=",">
            #{ids}
        </foreach>
    </select>


    <select id="getUserOrgDTOByIds" resultMap="UserOrgDTO">
        select u.id user_id ,u.username username, u.email email, u.linkman linkman , org.id org_id,
        org.name org_name, u.auth_status is_reject, u.auth_status au_status,org.sub_num
        from sys_user u, sys_user_organization uo, sys_organization org
        where u.is_deleted = 'N' and uo.is_deleted = 'N' and org.is_deleted = 'N'
        and u.id = uo.user_id and uo.organization_id = org.id
        and u.id in
        <foreach collection="list" item="ids" open="(" close=")" separator=",">
            #{ids}
        </foreach>
    </select>


    <select id="getUserByOrgName" resultMap="BaseResultMap">
		select a.* from sys_user a, sys_organization org, sys_user_organization uo
		where a.is_deleted = 'N' and org.is_deleted = 'N' and uo.is_deleted = 'N'
		and a.id = uo.user_id and uo.organization_id = org.id and org.`name` like concat('%' ,#{orgName}, '%')
	</select>


    <!-- 	<select id="selectUserInfoListPage" resultMap="BaseResultMap">
            select u.*
            LEFT JOIN sys_user_role ur on u.id= ur.user_id
            LEFT JOIN
            sys_role r on ur.role_id=r.id
            where u.is_deleted = 'N' and type = "0"
            ORDER BY gmt_create DESC
        </select> -->

    <!--  <select id="selectUserInfoPage"  parameterType="com.diagbot.dto.UserInfoDTO" resultType="com.diagbot.dto.UserInfoDTO">
         SELECT
         u.id AS userId,
         u.gmt_create as userGmtCreate,
         u.username as userName,
         u.linkman as linKman,
         u.email as email,
         org.id AS orgId,
         org.gmt_create as orgGmtCreate,
         org.name as orgName
         FROM sys_user u
         LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
         LEFT JOIN sys_organization org ON uorg.organization_id = org.id
         WHERE u.is_deleted = 'N' AND u.TYPE = 0 ORDER BY u.gmt_create DESC
     </select> -->
    <select id="selectUserInfoListPage" resultType="com.diagbot.dto.UserInfoDTO">
        SELECT
        u.id AS userId,
        u.gmt_create AS userGmtCreate,
        u.username AS userName,
        u.linkman AS linkman,
        u.email AS email,
        org.id AS orgId,
        org.gmt_create AS orgGmtCreate,
        org.name AS orgName,
        org.type as orgType,
        org.principal AS orgPrincipal,
        org.address as orgAddress,
        org.parent_id as orgParentId,
        org.sub_num as orgSub_num,
        u.position as position,
        aut.is_reject as autIsReject,
        u.auth_status as authStatus
        FROM sys_user u
        LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
        LEFT JOIN sys_organization org ON uorg.organization_id = org.id
        LEFT JOIN sys_user_authentication aut ON u.id = aut.user_id
        WHERE u.is_deleted = 'N' AND u.TYPE = 0
        <if test="userInfo.orgName != null">
            AND org.name LIKE CONCAT('%', #{userInfo.orgName}, '%')
        </if>
        <if test="userInfo.authStatus != null">
            AND u.auth_status = #{userInfo.authStatus}
        </if>
        ORDER BY u.gmt_create DESC
    </select>

    <update id="updateUserInfoAll" parameterType="java.util.Map">
        UPDATE sys_user u ,sys_user_organization a ,
        sys_organization b ,sys_user_authentication c
        SET u.remark = "0"
        <if test="userMap.email != null">
            <if test="userMap.gmtModified !=null">
                ,u.gmt_modified=#{userMap.gmtModified}
            </if>
            <if test="userMap.modifier != null">
                ,u.modifier=#{userMap.modifier}
            </if>
            ,u.email=#{userMap.email}
        </if>
        <if test="userMap.principal != null || userMap.address != null || userMap.type != null">
            <if test="userMap.gmtModified !=null">
                ,b.gmt_modified=#{userMap.gmtModified}
            </if>
            <if test="userMap.modifier != null">
                ,b.modifier=#{userMap.modifier}
            </if>
            <if test="userMap.principal != null">
                ,b.principal=#{userMap.principal}
            </if>
            <if test="userMap.address != null">
                ,b.address=#{userMap.address}
            </if>
            <if test="userMap.type != null">
                ,b.type=#{userMap.type}
            </if>
        </if>

        <!-- <if test="position != null || isReject != null || rejectType !=null || rejectComment !=null || status != null"> -->
        <if test="userMap.position != null">
            <if test="userMap.gmtModified !=null">
                ,c.gmt_modified=#{userMap.gmtModified}
            </if>
            <if test="userMap.modifier != null">
                ,c.modifier=#{userMap.modifier}
            </if>
            ,c.position=#{userMap.position}
        </if>
        <!-- <if test="isReject != null">
         ,c.is_reject=#{isReject}
        </if>
        <if test="rejectType !=null">
          ,c.reject_type=#{rejectType}
        </if>
        <if test="rejectComment !=null">
          ,c.reject_comment=#{rejectComment}
        </if>
        <if test="status != null">
          ,c.status = #{status}
        </if> -->
        <!-- </if> -->
        WHERE
        u.is_deleted = "N"
        AND u.id = #{userMap.userId}
        AND c.user_id= #{userMap.userId}
        AND a.user_id = #{userMap.userId}
        AND a.organization_id =b.id

    </update>


    <update id="updateDeleted" parameterType="java.util.Map">
        UPDATE sys_user u ,sys_user_organization a ,
        sys_organization b,sys_user_authentication c, sys_user_role r
        SET u.is_deleted = "Y",a.is_deleted= "Y",b.is_deleted= "Y",c.is_deleted="Y", r.is_deleted="Y"
        <if test="map.gmtModified !=null">
            ,u.gmt_modified=#{map.gmtModified}
            ,a.gmt_modified=#{map.gmtModified}
            ,b.gmt_modified=#{map.gmtModified}
            ,c.gmt_modified=#{map.gmtModified}
            ,r.gmt_modified=#{map.gmtModified}
        </if>
        <if test="map.modifier != null">
            ,u.modifier=#{map.modifier}
            ,a.modifier=#{map.modifier}
            ,b.modifier=#{map.modifier}
            ,c.modifier=#{map.modifier}
            ,r.modifier=#{map.modifier}
        </if>
        WHERE u.id = #{map.userId}
        AND c.user_id= #{map.userId}
        AND a.user_id = #{map.userId}
        AND a.organization_id =b.id
        AND r.user_id= #{map.userId}
    </update>
    <update id="auditUserInfoAll" parameterType="java.util.Map">
        UPDATE sys_user_authentication a, sys_user u 
        <trim prefix="set" suffixOverrides=",">
            <if test="auditMap.gmtModified !=null">a.gmt_modified=#{auditMap.gmtModified},</if>
            <if test="auditMap.modifier != null">a.modifier=#{auditMap.modifier},</if>
            <if test="auditMap.isReject != null">a.is_reject = #{auditMap.isReject} ,</if>
            <if test="auditMap.certificationDate != null">a.certification_date = #{auditMap.certificationDate},</if>
            <if test="auditMap.rejectType != null">a.reject_type =#{auditMap.rejectType},</if>
            <if test="auditMap.rejectComment != null">a.reject_comment= #{auditMap.rejectComment},</if>
            <if test="auditMap.status != null">a.STATUS= #{auditMap.status},</if>
            <if test="auditMap.authStatus != null">u.auth_status = #{auditMap.authStatus},</if>
            <if test="auditMap.certificationDate != null">u.passauth_time = #{auditMap.certificationDate},</if>
            <if test="auditMap.gmtModified !=null">u.gmt_modified=#{auditMap.gmtModified},</if>
            <if test="auditMap.modifier != null">u.modifier=#{auditMap.modifier}</if>
        </trim>
        WHERE
        a.is_deleted = "N"
        AND a.user_id = #{auditMap.userId}
        AND a.order_num = #{auditMap.orderNum}
        AND u.id = #{auditMap.userId}
    </update>

    <select id="dependentuserInfoByTime" parameterType="java.util.Map"
            resultType="com.diagbot.dto.UserInfoDTO">

        SELECT
        u.id AS userId,
        u.gmt_create AS userGmtCreate,
        u.passauth_time AS passauthTime,
        u.username AS userName,
        u.linkman AS linkman,
        u.email AS email,
        org.id AS orgId,
        org.gmt_create AS orgGmtCreate,
        org.name AS orgName,
        org.type as orgType,
        org.principal AS orgPrincipal,
        org.address as orgAddress,
        org.parent_id as orgParentId,
        org.sub_num as orgSub_num,
        u.position as position,
        u.auth_status as authStatus
        FROM sys_user u
        LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
        LEFT JOIN sys_organization org ON uorg.organization_id = org.id
        WHERE
        u.is_deleted = 'N'
        AND u.TYPE = "0"
        <if test="userExport.orgName != null">
            AND org.name LIKE CONCAT('%', #{userExport.orgName}, '%')
        </if>
        <if test="userExport.userName != null">
            AND u.username LIKE CONCAT('%', #{userExport.userName}, '%')
        </if>
        <if test="userExport.authStatus != null">
            AND u.auth_status = #{userExport.authStatus}
        </if>
        <if test="userExport.startTime != null and userExport.endTime != null">
            AND u.gmt_create BETWEEN #{userExport.startTime} and #{userExport.endTime}
        </if>
        ORDER BY u.gmt_create DESC
    </select>
    <select id="queryUserInformation"  resultType="com.diagbot.dto.UserAllDTO">
     SELECT
        u.id AS userId,
        u.gmt_create AS userGmtCreate,
        u.username AS userName,
        u.linkman AS linkman,
        u.email AS email,
        org.id AS orgId,
        org.name AS orgName,
        u.auth_status AS authStatus
        FROM sys_user u
        LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
        LEFT JOIN sys_organization org ON uorg.organization_id = org.id
        WHERE u.is_deleted = 'N' AND u.TYPE = 0
        <if test="userInformation.userName != null">
            AND u.username LIKE CONCAT('%', #{userInformation.userName}, '%')
        </if>
        <if test="userInformation.authStatus != null">
            AND u.auth_status = #{userInformation.authStatus}
        </if>
         <if test="userInformation.startTime != null and userInformation.endTime != null">
            AND u.gmt_create BETWEEN #{userInformation.startTime} and #{userInformation.endTime}
        </if>
        ORDER BY u.gmt_create DESC  
    </select>
    
   <!-- <select id="queryMechanismInformation(jiude)" resultType="com.diagbot.dto.OrganizationDTO">
    SELECT
        u.id AS userId,
        u.linkman AS linkman,
        org.id AS orgId,
        org.gmt_create AS orgGmtCreate,
        org.name AS orgName,
        org.type AS orgType,
        org.principal AS orgPrincipal,
        org.address AS orgAddress,
        org.parent_id AS orgParentId,
        org.sub_num AS orgSub_num
        FROM sys_user u
        LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
        LEFT JOIN sys_organization org ON uorg.organization_id = org.id
        LEFT JOIN sys_user_authentication aut ON u.id = aut.user_id
        WHERE u.is_deleted = 'N' AND u.TYPE = 0
        <if test="mechanism.orgName != null">
            AND org.name LIKE CONCAT('%', #{mechanism.orgName}, '%')
        </if>
        <if test="mechanism.authStatus != null">
            AND u.auth_status = #{mechanism.authStatus}
        </if>
         <if test="mechanism.startTime != null and mechanism.endTime != null">
            AND u.gmt_create BETWEEN #{mechanism.startTime} and #{mechanism.endTime}
        </if>
        ORDER BY u.gmt_create DESC 
   </select> -->
   <select id="queryMechanismInformation" resultType="com.diagbot.dto.OrganizationDTO">
      SELECT  
        u.id AS userId,
        org.id AS orgId,
        org.gmt_create AS orgGmtCreate,
        org.name AS orgName,
        org.principal AS orgPrincipal,
        org.type AS orgType,
        org.address AS orgAddress,
        u.linkman AS linkman,
        u.auth_status AS authStatus,
        org.parent_id AS orgParentId,
        org.sub_num AS orgSubNum
        FROM 
        sys_organization org 
        LEFT JOIN  sys_user_organization uorg  ON org.id = uorg.organization_id
        LEFT JOIN sys_user u ON uorg.user_id = u.id
        WHERE org.is_deleted = 'N' 
        <if test="mechanism.orgName != null">
            AND org.name LIKE CONCAT('%', #{mechanism.orgName}, '%')
        </if>
        <if test="mechanism.authStatus != null">
            AND u.auth_status = #{mechanism.authStatus}
        </if>
         <if test="mechanism.startTime != null and mechanism.endTime != null">
            AND org.gmt_create BETWEEN #{mechanism.startTime} and #{mechanism.endTime}
        </if>
        ORDER BY org.gmt_create DESC 
   </select> 
    
    <select id="queryVerifiedUserOrganizationProduct" resultType="com.diagbot.dto.UserOrgizationProductDTO">
     SELECT
        u.id AS userId,
        u.gmt_create AS userGmtCreate,
        u.username AS userName,
        u.linkman AS linkman,
        u.email AS email,
        org.id AS orgId,
        org.gmt_create AS orgGmtCreate,
        org.name AS orgName,
        org.type AS orgType,
        org.principal AS orgPrincipal,
        org.address AS orgAddress,
        org.parent_id AS orgParentId,
        org.sub_num AS orgSubNum,
        u.passauth_time AS passauthTime,
        u.position AS position,
        u.auth_status AS authStatus
        FROM sys_user u
        LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
        LEFT JOIN sys_organization org ON uorg.organization_id = org.id
        WHERE u.is_deleted = 'N' AND u.TYPE = 0
        <if test="userOrg.orgName != null">
            AND org.name LIKE CONCAT('%', #{userOrg.orgName}, '%')
        </if>
        <if test="userOrg.userName != null">
            AND u.username LIKE CONCAT('%', #{userOrg.userName}, '%')
        </if>
         <if test="userOrg.startTime != null and userOrg.endTime != null">
            AND u.passauth_time BETWEEN #{userOrg.startTime} and #{userOrg.endTime}
        </if>
        AND u.auth_status = 1
        ORDER BY u.passauth_time DESC
    </select>
    <select id="queryAuthentication" resultType="com.diagbot.dto.AuthenticationDTO">
	SELECT
	u.id AS userId,
	aut.gmt_create AS autGmtCreate,
	u.username AS userName,
	u.linkman AS linkman,
	u.email AS email,
	org.id AS orgId,
	org.gmt_create AS orgGmtCreate,
	org.name AS orgName,
	org.type AS orgType,
	org.principal AS orgPrincipal,
	org.address AS orgAddress,
	org.parent_id AS orgParentId,
	org.sub_num AS orgSubNum,
	u.position AS position,
	u.auth_status AS authStatus,
	aut.order_num AS orderNum,
	aut.status AS status
	FROM sys_user_authentication aut
	JOIN sys_user u ON u.id = aut.user_id
	JOIN sys_user_organization uorg ON u.id = uorg.user_id
	JOIN sys_organization org ON uorg.organization_id = org.id
	WHERE u.is_deleted = 'N' AND aut.is_deleted = 'N' AND u.TYPE = 0 
	<if test="authen.status != null">
	    AND aut.status = #{authen.status}
	</if>     
	<if test="authen.authStatus != null">
	    AND u.auth_status= #{authen.authStatus}
	</if>
	<if test="authen.orgName != null">
		AND org.name LIKE CONCAT('%', #{authen.orgName}, '%')
	</if>
	<if test="authen.userName != null">
		AND u.username LIKE CONCAT('%', #{authen.userName}, '%')
	</if>
	<if test="authen.startTime != null and authen.endTime != null">
		AND aut.gmt_create BETWEEN #{authen.startTime} and #{authen.endTime}
	</if>

	ORDER BY aut.gmt_create DESC
	<!-- SELECT u.id AS userId, u.gmt_create AS userGmtCreate, u.username AS 
		userName, u.linkman AS linKman, u.email AS email, org.id AS orgId, org.gmt_create 
		AS orgGmtCreate, org.name AS orgName, org.type AS orgType, org.principal 
		AS orgPrincipal, org.address AS orgAddress, org.parent_id AS orgParentId, 
		org.sub_num AS orgSub_num, u.position AS autPosition, u.auth_status AS authStatus 
		FROM sys_user u LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id 
		LEFT JOIN sys_organization org ON uorg.organization_id = org.id WHERE u.is_deleted 
		= 'N' AND u.TYPE = 0 <if test="authen.orgName != null"> AND org.name LIKE 
		CONCAT('%', #{authen.orgName}, '%') </if> <if test="authen.userName != null"> 
		AND u.username LIKE CONCAT('%', #{authen.userName}, '%') </if> <if test="authen.startTime 
		!= null and authen.endTime != null"> AND u.gmt_create BETWEEN #{authen.startTime} 
		and #{authen.endTime} </if> AND u.auth_status = 2 ORDER BY u.gmt_create DESC -->
    </select>
	<update id="updateUserInfo" parameterType="java.util.Map">
	UPDATE
	sys_user a
	<trim prefix="set" suffixOverrides=",">
		<if test="amendUserInfo.linkman != null">
			a.linkman = #{amendUserInfo.linkman},
		</if>
		<if test="amendUserInfo.email != null">
			a.email = #{amendUserInfo.email},
		</if>
		<if test="amendUserInfo.position != null">
			a.position = #{amendUserInfo.position},
		</if>
		<if test="amendUserInfo.gmtModified != null">
			a.gmt_modified =#{amendUserInfo.gmtModified},
		</if>
		<if test="amendUserInfo.modifier != null">
			a.modifier = #{amendUserInfo.modifier},
		</if>
	</trim>
	WHERE
	a.is_deleted = "N"
	AND a.id = #{amendUserInfo.userId}
    </update>
	<update id="updateOrganizations" parameterType="java.util.Map">
		UPDATE sys_organization a
		<trim prefix="set" suffixOverrides=",">
			<if test="amendOrg.address != null">
				a.address = #{amendOrg.address},
			</if>
			<if test="amendOrg.type != null">
				a.type = #{amendOrg.type},
			</if>
			<if test="amendOrg.orgSubNum != null">
				a.sub_num = #{amendOrg.orgSubNum},
			</if>
			<if test="amendOrg.gmtModified != null">
				a.gmt_modified =#{amendOrg.gmtModified},
			</if>
			<if test="amendOrg.modifier != null">
				a.modifier =#{amendOrg.modifier}
			</if>
		</trim>
		WHERE
		a.is_deleted = "N"
		AND a.id = #{amendOrg.orgId}
	</update>
	<select id="exportOrganizations" parameterType="java.util.Map"
            resultType="com.diagbot.dto.UserInfoDTO">
	SELECT  
        u.id AS userId,
        org.id AS orgId,
        org.gmt_create AS orgGmtCreate,
        org.name AS orgName,
        org.principal AS orgPrincipal,
        org.type AS orgType,
        org.address AS orgAddress,
        u.linkman AS linkman,
        u.auth_status AS authStatus,
        org.parent_id AS orgParentId,
        org.sub_num AS orgSubNum
        FROM 
        sys_organization org 
        LEFT JOIN  sys_user_organization uorg  ON org.id = uorg.organization_id
        LEFT JOIN sys_user u ON uorg.user_id = u.id
        WHERE org.is_deleted = 'N' 
        <if test="exportOrg.orgName != null">
            AND org.name LIKE CONCAT('%', #{exportOrg.orgName}, '%')
        </if>
        <if test="exportOrg.startTime != null and exportOrg.endTime != null">
            AND org.gmt_create BETWEEN #{exportOrg.startTime} and #{exportOrg.endTime}
        </if>
        ORDER BY org.gmt_create DESC 
	</select>
	<select id="exportKema"  resultType="com.diagbot.dto.AuthenticationDTO">
	SELECT
	u.id AS userId,
	aut.gmt_create AS autGmtCreate,
	u.username AS userName,
	u.linkman AS linkman,
	u.email AS email,
	org.id AS orgId,
	org.gmt_create AS orgGmtCreate,
	org.name AS orgName,
	org.type AS orgType,
	org.principal AS orgPrincipal,
	org.address AS orgAddress,
	org.parent_id AS orgParentId,
	org.sub_num AS orgSubNum,
	u.position AS position,
	u.auth_status AS authStatus,
	aut.order_num AS orderNum,
	aut.status AS status
	FROM sys_user_authentication aut
	JOIN sys_user u ON u.id = aut.user_id
	JOIN sys_user_organization uorg ON u.id = uorg.user_id
	JOIN sys_organization org ON uorg.organization_id = org.id
	WHERE u.is_deleted = 'N' AND aut.is_deleted = 'N' AND u.TYPE = 0 
	<if test="exportKema.status != null">
	    AND aut.status = #{exportKema.status}
	</if>     
	<if test="exportKema.authStatus != null">
	    AND u.auth_status= #{exportKema.authStatus}
	</if>
	<if test="exportKema.orgName != null">
		AND org.name LIKE CONCAT('%', #{exportKema.orgName}, '%')
	</if>
	<if test="exportKema.userName != null">
		AND u.username LIKE CONCAT('%', #{exportKema.userName}, '%')
	</if>
	<if test="exportKema.startTime != null and exportKema.endTime != null">
		AND aut.gmt_create BETWEEN #{exportKema.startTime} and #{exportKema.endTime}
	</if>

	ORDER BY aut.gmt_create DESC
	</select>
	 <select id="exportVerified" resultType="com.diagbot.dto.UserInfoDTO">
     SELECT
        u.id AS userId,
        u.gmt_create AS userGmtCreate,
        u.username AS userName,
        u.linkman AS linkman,
        u.email AS email,
        org.id AS orgId,
        org.gmt_create AS orgGmtCreate,
        org.name AS orgName,
        org.type AS orgType,
        org.principal AS orgPrincipal,
        org.address AS orgAddress,
        org.parent_id AS orgParentId,
        org.sub_num AS orgSubNum,
        u.passauth_time AS passauthTime,
        u.position AS position,
        u.auth_status AS authStatus
        FROM sys_user u
        LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
        LEFT JOIN sys_organization org ON uorg.organization_id = org.id
        WHERE 
		u.is_deleted = 'N' 
		AND u.TYPE = 0
        <if test="Verified.orgName != null">
            AND org.name LIKE CONCAT('%', #{Verified.orgName}, '%')
        </if>
        <if test="Verified.userName != null">
            AND u.username LIKE CONCAT('%', #{Verified.userName}, '%')
        </if>
         <if test="Verified.startTime != null and Verified.endTime != null">
            AND u.passauth_time BETWEEN #{Verified.startTime} and #{Verified.endTime}
        </if>
        AND u.auth_status = 1
        ORDER BY u.passauth_time DESC
    </select>

    <select id="getAllUserInfos" resultMap="BaseResultMap">
        SELECT * FROM `sys_user` where is_deleted ='N'
    </select>
</mapper>