<?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.unis.crk.basic.mapper.UserInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.unis.crk.basic.entity.UserInfo">
        <id column="user_id" property="userId" />
        <result column="username" property="username" />
        <result column="password" property="password" />
        <result column="org_id" property="orgId" />
        <result column="real_name" property="realName" />
        <result column="sex" property="sex" />
        <result column="telphone" property="telphone" />
        <result column="mobile" property="mobile" />
        <result column="address" property="address" />
        <result column="email" property="email" />
        <result column="qq_number" property="qqNumber" />
        <result column="img_url" property="imgUrl" />
        <result column="signature" property="signature" />
        <result column="create_time" property="createTime" />
        <result column="create_user_id" property="createUserId" />
        <result column="update_time" property="updateTime" />
        <result column="update_user_id" property="updateUserId" />
        <result column="status" property="status" />
        <result column="del_flag" property="delFlag" />
        <result column="user_alias" property="userAlias" />
        <result column="updatetime" property="updatetime" />
    </resultMap>
    <resultMap id="UserRoleOrgMap" type="com.unis.crk.basic.entity.UserInfo">
        <id column="user_id" jdbcType="INTEGER" property="userId" />
        <result column="username" jdbcType="VARCHAR" property="username" />
        <result column="org_name" jdbcType="VARCHAR" property="orgName" />
        <result column="real_name" jdbcType="VARCHAR" property="realName" />
        <result column="telphone" jdbcType="VARCHAR" property="telphone" />
        <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
    </resultMap>
    <resultMap id="UserInfoVo" type="com.unis.crk.basic.entity.vo.UserInfoVo">
        <id column="user_id" property="userId" />
        <result column="username" property="username" />
        <result column="password" property="password" />
        <result column="org_id" property="orgId" />
        <result column="real_name" property="realName" />
        <result column="sex" property="sex" />
        <result column="telphone" property="telphone" />
        <result column="mobile" property="mobile" />
        <result column="address" property="address" />
        <result column="email" property="email" />
        <result column="qq_number" property="qqNumber" />
        <result column="img_url" property="imgUrl" />
        <result column="signature" property="signature" />
        <result column="create_time" property="createTime" />
        <result column="create_user_id" property="createUserId" />
        <result column="update_time" property="updateTime" />
        <result column="update_user_id" property="updateUserId" />
        <result column="status" property="status" />
        <result column="del_flag" property="delFlag" />
        <result column="user_alias" property="userAlias" />
        <result column="updatetime" property="updatetime" />
    </resultMap>
    <select id="queryAll"   resultType="java.util.Map">
        SELECT
        distinct ui.user_id,
        ui.real_name,
        ui.username,
        ui.mobile,
        ui.status,
        ui.telphone,
        ui.del_flag,
        ui.create_time,
        oi.org_name
        FROM
        user_info ui
        LEFT JOIN user_role ur ON ui.user_id = ur.user_id
        LEFT JOIN role_info ri ON ur.role_id = ri.role_id
        LEFT JOIN org_info oi ON oi.org_id = ui.org_id
        where 1=1
        <if test="ew.sqlSegment != null and  ew.sqlSegment != ''">
          and  ${ew.sqlSegment}
        </if>
        ORDER BY create_time DESC
    </select>

    <select id="queryAuditUser" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
        ui.user_id userId,
        ui.real_name realName,
        ui.username username
        FROM
        user_role ur
        LEFT JOIN role_info ri ON ur.role_id = ri.role_id
        LEFT JOIN user_info ui ON ur.user_id = ui.user_id
        <where>
            1=1
            <if test="roleName != null">
               and   ri.role_name = #{roleName}
            </if>
            <if test="orgId != null">
                AND ri.org_id = #{orgId}
                AND ui.org_id = #{orgId}
            </if>
        </where>
    </select>

    <select id="queryAllByOrgClass" resultType="java.util.Map">
        SELECT
        ui.user_id,
        ui.username,
        ui.real_name,
        oi.org_name
        FROM
        user_info ui
        LEFT JOIN org_info oi ON oi.org_id = ui.org_id
        where 1=1
        <if test="ew.sqlSegment != null and  ew.sqlSegment != ''">
            and  ${ew.sqlSegment}
        </if>
        GROUP BY
        ui.user_id
    </select>

    <select id="selectUserInfoVo" resultMap="UserInfoVo" parameterType="com.unis.crk.basic.entity.vo.UserInfoVo">
        select * from user_info
            <where>
                1=1

                    and   username = '${username}'

                    and   password = '${password}'

            </where>
    </select>

    <select id="selectUserInfoVoById" resultMap="UserInfoVo" parameterType="com.unis.crk.basic.entity.vo.UserInfoVo">
        select * from user_info
        <where>
            1=1
            <if test="userid!=null and userid!=''">
                and   user_id = '${userid}'
            </if>

        </where>
    </select>
</mapper>
