<?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="cn.com.oa.mapper.UserMapper">

    <resultMap id="BaseResultMap" type="cn.com.oa.model.User">
            <result property="universalid" column="UNIVERSALID" jdbcType="BIGINT"/>
            <result property="userName" column="USER_NAME" jdbcType="VARCHAR"/>
            <result property="password" column="PASSWORD" jdbcType="VARCHAR"/>
            <result property="userState" column="USER_STATE" jdbcType="TINYINT"/>
            <result property="deleteSymbol" column="DELETE_SYMBOL" jdbcType="VARCHAR"/>
            <result property="groupid" column="groupid" jdbcType="VARCHAR"/>
            <result property="contactTel1" column="contact_tel1" jdbcType="VARCHAR"/>
            <result property="fixedPhone" column="fixed_phone" jdbcType="VARCHAR"/>
            <result property="desktopPhone" column="desktop_phone" jdbcType="VARCHAR"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="sex" column="sex" jdbcType="VARCHAR"/>
            <result property="position" column="position" jdbcType="VARCHAR"/>
            <result property="birthday" column="birthday" jdbcType="VARCHAR"/>
            <result property="fax" column="fax" jdbcType="VARCHAR"/>
            <result property="email" column="email" jdbcType="VARCHAR"/>
            <result property="qqnum" column="qqnum" jdbcType="VARCHAR"/>
            <result property="msnnum" column="msnnum" jdbcType="VARCHAR"/>
            <result property="address" column="address" jdbcType="VARCHAR"/>
            <result property="postcode" column="postcode" jdbcType="VARCHAR"/>
            <result property="homeno" column="homeno" jdbcType="VARCHAR"/>
            <result property="companyid" column="companyId" jdbcType="BIGINT"/>
            <result property="pos" column="pos" jdbcType="BIGINT"/>
            <result property="logintype" column="loginType" jdbcType="BIGINT"/>
            <result property="loginstyle" column="loginStyle" jdbcType="VARCHAR"/>
            <result property="createtime" column="createTime" jdbcType="TIMESTAMP"/>
            <result property="unitid" column="unitId" jdbcType="BIGINT"/>
            <result property="phoneCode" column="phone_code" jdbcType="VARCHAR"/>
            <result property="intro" column="intro" jdbcType="VARCHAR"/>
            <result property="clientid" column="clientid" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        UNIVERSALID,USER_NAME,PASSWORD,
        USER_STATE,DELETE_SYMBOL,groupid,
        contact_tel1,fixed_phone,desktop_phone,
        name,sex,position,
        birthday,fax,email,
        qqnum,msnnum,address,
        postcode,homeno,companyId,
        pos,loginType,loginStyle,
        createTime,unitId,phone_code,
        intro,clientid
    </sql>
    <select id="getDeptCount" resultType="cn.com.oa.model.dto.UserDTO">
        SELECT
            COUNT(*) AS deptCount,
            tg.GROUPNAME AS deptName
        FROM
            t_user u
                LEFT JOIN t_group tg ON tg.UNIVERSALID =(
                SELECT
                    gu.GROUPID
                FROM
                    t_groupxuser gu
                WHERE
                    gu.USERNAME = u.UNIVERSALID
                    AND gu.state != 0
                    AND gu.postype = 1
            )
        WHERE
            u.unitId = #{user.unitid}
            AND u.USER_STATE = #{user.userState}
            AND u.UNIVERSALID NOT IN
            (select special_user_id from hr_attendance_special where special_type = 1)
        GROUP BY
            tg.GROUPNAME
    </select>

</mapper>
