<?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="user">

    <resultMap id="userResult" extends="common.markedObjectResult" type="user">
        <id property="userId" column="USER_ID"/>
        <result property="password" column="PASSWORD"/>
        <result property="description" column="DESCRIPTION"/>
        <result property="activeFlag" column="ACTIVE_FLAG"/>
        <result property="sysId" column="SYS_ID"/>
        <result property="empNo" column="EMP_NO"/>
        <result property="recentLoginIp" column="RECENT_LOGIN_IP"/>
        <result property="recentLoginDatetime" column="RECENT_LOGIN_DATETIME" jdbcType="TIMESTAMP"/>
        <result property="firstRegDatetime" column="FIRST_REG_DATETIME" jdbcType="TIMESTAMP"/>
        <result property="knoxId" column="KNOX_ID" />
        <result property="nickName" column="NICK_NAME" />
        <result property="firstName" column="FIRST_NAME" />
        <result property="lastName" column="LAST_NAME" />
        <result property="userNameEn" column="EN_USER_NAME" />
        <result property="firstNameEn" column="EN_FIRST_NAME" />
        <result property="lastNameEn" column="EN_LAST_NAME" />
        <result property="language" column="LANGUAGE_CODE" />
        <result property="displayName" column="DISPLAY_NAME" />
        <result property="userName" column="USER_NAME" />
        <result property="compName" column="COMP_NAME" />
        <result property="compNameEn" column="EN_COMP_NAME" />
        <result property="compCode" column="COMP_CODE" />
        <result property="deptName" column="DEPT_NAME" />
        <result property="deptNameEn" column="EN_DEPT_NAME" />
        <result property="deptCode" column="DEPT_CODE" />
        <result property="grdName" column="GRD_NAME" />
        <result property="grdNameEn" column="EN_GRD_NAME" />
        <result property="grdCode" column="GRD_CODE" />
        <result property="compTel" column="COMP_TEL_NO" />
        <result property="mobile" column="MOBILE_TEL_NO" />
        <result property="email" column="EMAIL_ADDRESS" />
        <result property="timeZoneCode" column="TIME_ZONE_CODE" />
        <result property="timeZoneId" column="TIME_ZONE_ID" />
        <result property="lastLoginDate" column="LAST_LOGIN_DATETIME" jdbcType="TIMESTAMP"/>
        <result property="lastLoginIp" column="LAST_LOGIN_IP" />
        <result property="lastLogoutDate" column="LAST_LOGOUT_DATETIME" jdbcType="TIMESTAMP"/>
        <result property="externalUser" column="EXTERNAL_USER_FLAG" />
        <result property="expireStatus" column="EXPIRE_STATUS_CODE" />
        <result property="userType" column="USER_TYPE" />
        <result property="privacyPolicy" column="PRIVACY_POLICY" />
        <result property="privacyPolicyDate" column="PRIVACY_POLICY_DATE" jdbcType="TIMESTAMP"/>
        <result property="euGdprPolicy" column="EU_GDPR_POLICY" />
        <result property="euGdprPolicyDate" column="EU_GDPR_POLICY_DATE" jdbcType="TIMESTAMP"/>
        <result property="deleted" column="DELETED"/>
        <result property="loginErrorCount" column="LOGIN_ERROR_COUNT"/>
        <result property="lastPwChangeDate" column="LAST_PW_CHANGE_DATETIME" jdbcType="TIMESTAMP"/>
        <result property="serverLocation" column="SERVER_LOCATION"/>
        <result property="lastActivityTime" column="LAST_ACTIVITY_TIME"/>
        <result property="jwt" column="JWT"/>
        <result property="userStatus" column="USER_STATUS" />
    </resultMap>

    <resultMap id="simpleUserResult" type="user">
        <id property="userId" column="USER_ID"/>
        <result property="password" column="PASSWORD"/>
        <result property="description" column="DESCRIPTION"/>
        <result property="activeFlag" column="ACTIVE_FLAG"/>
        <result property="sysId" column="SYS_ID"/>
        <result property="empNo" column="EMP_NO"/>
        <result property="recentLoginIp" column="RECENT_LOGIN_IP"/>
        <result property="recentLoginDatetime" column="RECENT_LOGIN_DATETIME" jdbcType="TIMESTAMP"/>
        <result property="firstRegDatetime" column="FIRST_REG_DATETIME" jdbcType="TIMESTAMP"/>
        <result property="knoxId" column="KNOX_ID" />
        <result property="nickName" column="NICK_NAME" />
        <result property="firstName" column="FIRST_NAME" />
        <result property="lastName" column="LAST_NAME" />
        <result property="userNameEn" column="EN_USER_NAME" />
        <result property="firstNameEn" column="EN_FIRST_NAME" />
        <result property="lastNameEn" column="EN_LAST_NAME" />
        <result property="language" column="LANGUAGE_CODE" />
        <result property="displayName" column="DISPLAY_NAME" />
        <result property="userName" column="USER_NAME" />
        <result property="compName" column="COMP_NAME" />
        <result property="compNameEn" column="EN_COMP_NAME" />
        <result property="compCode" column="COMP_CODE" />
        <result property="deptName" column="DEPT_NAME" />
        <result property="deptNameEn" column="EN_DEPT_NAME" />
        <result property="deptCode" column="DEPT_CODE" />
        <result property="grdName" column="GRD_NAME" />
        <result property="grdNameEn" column="EN_GRD_NAME" />
        <result property="grdCode" column="GRD_CODE" />
        <result property="compTel" column="COMP_TEL_NO" />
        <result property="mobile" column="MOBILE_TEL_NO" />
        <result property="email" column="EMAIL_ADDRESS" />
        <result property="timeZoneCode" column="TIME_ZONE_CODE" />
        <result property="timeZoneId" column="TIME_ZONE_ID" />
        <result property="lastLoginDate" column="LAST_LOGIN_DATETIME" jdbcType="TIMESTAMP"/>
        <result property="lastLoginAddr" column="LAST_LOGIN_IP" />
        <result property="lastLogoutDate" column="LAST_LOGOUT_DATETIME" jdbcType="TIMESTAMP"/>
        <result property="externalUser" column="EXTERNAL_USER_FLAG" />
        <result property="expireStatus" column="EXPIRE_STATUS_CODE" />
        <result property="userType" column="USER_TYPE" />
        <result property="privacyPolicy" column="PRIVACY_POLICY" />
        <result property="privacyPolicyDate" column="PRIVACY_POLICY_DATE" jdbcType="TIMESTAMP"/>
        <result property="euGdprPolicy" column="EU_GDPR_POLICY" />
        <result property="euGdprPolicyDate" column="EU_GDPR_POLICY_DATE" jdbcType="TIMESTAMP"/>
        <result property="deleted" column="DELETED"/>
        <result property="loginErrorCount" column="LOGIN_ERROR_COUNT"/>
        <result property="serverLocation" column="SERVER_LOCATION"/>
        <result property="lastActivityTime" column="LAST_ACTIVITY_TIME"/>
        <result property="jwt" column="JWT"/>
    </resultMap>

    <resultMap id="userMenuResult" type="userMenu">
        <result property="userId" column="USER_ID" />
        <result property="sysResourceId" column="SYS_RESOURCE_ID" />
        <result property="authorizationId" column="AUTHORIZATION_ID" />
        <result property="label" column="LABEL" />
        <result property="labelJson" column="LABEL_JSON" />
        <result property="fromDate" column="FROM_DATE" />
        <result property="thruDate" column="THRU_DATE" />
    </resultMap>

    <sql id="tableUser">TN_CF_USER</sql>
    <sql id="tableUserAuthorization">TN_CF_USER_AUTHORIZATION</sql>

    <sql id="columnsUser">
    USER_ID, PASSWORD, DESCRIPTION, ACTIVE_FLAG, SYS_ID, EMP_NO, RECENT_LOGIN_IP, RECENT_LOGIN_DATETIME, FIRST_REG_DATETIME,
    FIRST_REGR_ID, LAST_MOD_DATETIME, LAST_MODR_ID, KNOX_ID, FIRST_NAME, LAST_NAME, EN_USER_NAME, EN_FIRST_NAME, EN_LAST_NAME,
    LANGUAGE_CODE, DISPLAY_NAME, USER_NAME, COMP_NAME, EN_COMP_NAME, COMP_CODE, DEPT_NAME, EN_DEPT_NAME, DEPT_CODE, GRD_NAME,
    EN_GRD_NAME, GRD_CODE, COMP_TEL_NO, MOBILE_TEL_NO, EMAIL_ADDRESS, NICK_NAME, EXTERNAL_USER_FLAG, TIME_ZONE_CODE, LAST_LOGIN_DATETIME, LAST_LOGIN_IP,
    LAST_LOGOUT_DATETIME,EXPIRE_STATUS_CODE,USER_TYPE, PRIVACY_POLICY, PRIVACY_POLICY_DATE, EU_GDPR_POLICY, EU_GDPR_POLICY_DATE, DELETED,
    TIME_ZONE_ID, LOGIN_ERROR_COUNT, LAST_PW_CHANGE_DATETIME, SERVER_LOCATION, LAST_ACTIVITY_TIME, JWT
	</sql>

    <sql id="columnsUserExcel">
    USER_ID, PASSWORD, DESCRIPTION, ACTIVE_FLAG, SYS_ID, EMP_NO, RECENT_LOGIN_IP, RECENT_LOGIN_DATETIME, FIRST_REG_DATETIME,
    FIRST_REGR_ID, LAST_MOD_DATETIME, LAST_MODR_ID, KNOX_ID, FIRST_NAME, LAST_NAME, EN_USER_NAME, EN_FIRST_NAME, EN_LAST_NAME,
    LANGUAGE_CODE, DISPLAY_NAME, USER_NAME, COMP_NAME, EN_COMP_NAME, COMP_CODE, DEPT_NAME, EN_DEPT_NAME, DEPT_CODE, GRD_NAME,
    EN_GRD_NAME, GRD_CODE, COMP_TEL_NO, MOBILE_TEL_NO, EMAIL_ADDRESS, NICK_NAME, EXTERNAL_USER_FLAG, TIME_ZONE_CODE,
    LAST_LOGIN_DATETIME, LAST_LOGIN_IP, LAST_LOGOUT_DATETIME,
    CASE
       WHEN EXPIRE_STATUS_CODE IN ('RETIRE','MOVE','LONG_TERM') THEN EXPIRE_STATUS_CODE
       ELSE 'WORK'
    END EXPIRE_STATUS_CODE,
    USER_TYPE, PRIVACY_POLICY, PRIVACY_POLICY_DATE, EU_GDPR_POLICY, EU_GDPR_POLICY_DATE, DELETED,
    TIME_ZONE_ID, LOGIN_ERROR_COUNT, LAST_PW_CHANGE_DATETIME, SERVER_LOCATION, LAST_ACTIVITY_TIME, JWT,
    CASE
       WHEN ACTIVE_FLAG = '1' AND DELETED = '0' THEN 'ACTIVE'
       WHEN ACTIVE_FLAG = '0' AND DELETED = '0' AND EXPIRE_STATUS_CODE IS NOT NULL THEN 'INACTIVE'
       WHEN ACTIVE_FLAG = '0' AND DELETED = '0' AND EXPIRE_STATUS_CODE IS NULL THEN 'WAITING'
       WHEN DELETED = '1' THEN 'DELETED'
    END USER_STATUS
	</sql>

    <sql id="conditionUser">
        <trim prefix="WHERE" prefixOverrides="AND|OR">
            <if test="_parameter.containsKey('userId')">
                <choose>
                    <when test="@com.samsung.SdlComparator@isNotEmpty(userId)">
                        USER_ID = #{userId}
                    </when>
                    <otherwise>
                        USER_ID = NULL
                    </otherwise>
                </choose>
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(knoxId)">
                AND LOWER(KNOX_ID) LIKE CONCAT('%', LOWER(REPLACE(REPLACE(#{knoxId}, '%', '[%]'), '_', '[_]')), '%')
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(knoxIdNotLike)">
                AND KNOX_ID = #{knoxIdNotLike}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(userName)">
                AND LOWER(USER_NAME) LIKE CONCAT('%', LOWER(REPLACE(REPLACE(#{userName}, '%', '[%]'), '_', '[_]')), '%')
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(deptName)">
                AND LOWER(DEPT_NAME) LIKE CONCAT('%', LOWER(REPLACE(REPLACE(#{deptName}, '%', '[%]'), '_', '[_]')), '%')
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(activeFlag)">
                AND ACTIVE_FLAG = #{activeFlag}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(externalUser)">
                AND EXTERNAL_USER_FLAG = #{externalUser}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(userType)">
                AND USER_TYPE = #{userType}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(passWord)">
                AND PASSWORD = #{passWord}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(empNo)">
                AND EMP_NO = #{empNo}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(deptCode)">
                AND DEPT_CODE = #{deptCode}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(deleted)">
                AND DELETED = #{deleted}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(compName)">
                AND COMP_NAME = #{compName}
            </if>
            <if test="@com.samsung.SdlComparator@isNotEmpty(email)">
                AND EMAIL_ADDRESS = #{email}
            </if>
            <if test="_parameter.containsKey('expireStatus')">
                <choose>
                    <when test="@com.samsung.SdlComparator@isNotEmpty(expireStatus)">
                        AND EXPIRE_STATUS_CODE = #{expireStatus}
                    </when>
                    <otherwise>
                        AND EXPIRE_STATUS_CODE IS NULL
                    </otherwise>
                </choose>
            </if>
            <if test="_parameter.containsKey('expireStatusNotNull')">
                AND EXPIRE_STATUS_CODE IS NOT NULL
            </if>
        </trim>
    </sql>

    <select id="selectUser" parameterType="java.util.HashMap" resultMap="userResult">
        SELECT <choose>
                  <when test="@com.samsung.SdlComparator@isNotEmpty(isExcel)">
                     <include refid="columnsUserExcel" />
                  </when>
                  <otherwise>
                     <include refid="columnsUser" />
                  </otherwise>
               </choose>
        FROM   <include refid="tableUser" />
        <include refid="conditionUser" />
        <if test="@com.samsung.SdlComparator@isNotEmptyForDynamicSql(orderBy)">
        ORDER BY ${orderBy}
        </if>
    </select>

    <select id="selectUserByIds" parameterType="java.util.HashMap" resultMap="userResult">
        SELECT <include refid="columnsUser" />
        FROM   <include refid="tableUser" />
        <if test="@com.samsung.SdlComparator@isNotEmpty(userIds)">
        WHERE  USER_ID IN <foreach item="userId" index="index" collection="userIds" open="(" separator="," close=")">#{userId}</foreach>
        </if>
        <if test="@com.samsung.SdlComparator@isNotEmptyForDynamicSql(orderBy)">
        ORDER BY ${orderBy}
        </if>
    </select>

    <select id="countUser" parameterType="java.util.HashMap" resultType="int">
        SELECT COUNT(*) AS TOTAL
        FROM   <include refid="tableUser" />
        <include refid="conditionUser" />
    </select>

    <insert id="insertUser" parameterType="user">
        INSERT INTO <include refid="tableUser" />
        (USER_ID, PASSWORD, DESCRIPTION, ACTIVE_FLAG, SYS_ID, EMP_NO, RECENT_LOGIN_IP, RECENT_LOGIN_DATETIME,
         FIRST_REG_DATETIME, FIRST_REGR_ID, LAST_MOD_DATETIME, LAST_MODR_ID,
         KNOX_ID, FIRST_NAME, LAST_NAME, EN_USER_NAME, EN_FIRST_NAME, EN_LAST_NAME,
         LANGUAGE_CODE, DISPLAY_NAME, USER_NAME, COMP_NAME, EN_COMP_NAME, COMP_CODE, DEPT_NAME, EN_DEPT_NAME, DEPT_CODE, GRD_NAME,
         EN_GRD_NAME, GRD_CODE, COMP_TEL_NO, MOBILE_TEL_NO, EMAIL_ADDRESS, NICK_NAME, EXTERNAL_USER_FLAG, TIME_ZONE_CODE, USER_TYPE, DELETED,
         TIME_ZONE_ID, LOGIN_ERROR_COUNT, LAST_PW_CHANGE_DATETIME, SERVER_LOCATION, LAST_ACTIVITY_TIME, JWT)
        VALUES
        (#{userId}, #{password}, #{description}, #{activeFlag}, #{sysId}, #{empNo}, #{recentLoginIp}, #{recentLoginDatetime,jdbcType=TIMESTAMP},
         #{firstRegDatetime,jdbcType=TIMESTAMP}, #{userId}, #{lastModDatetime,jdbcType=TIMESTAMP}, #{userId},
         #{knoxId}, #{firstName}, #{lastName}, #{userNameEn}, #{firstNameEn}, #{lastNameEn},
         #{language}, #{displayName}, #{userName}, #{compName}, #{compNameEn}, #{compCode}, #{deptName}, #{deptNameEn}, #{deptCode}, #{grdName},
         #{grdNameEn}, #{grdCode}, #{compTel}, #{mobile}, #{email}, #{nickName}, #{externalUser}, #{timeZoneCode}, #{userType}, #{deleted},
         #{timeZoneId}, #{loginErrorCount}, #{lastPwChangeDate}, #{serverLocation}, #{lastActivityTime}, #{jwt})
    </insert>

    <update id="updateUser" parameterType="user">
        UPDATE <include refid="tableUser" />
        SET    DESCRIPTION = #{description},
               ACTIVE_FLAG = #{activeFlag},
               PASSWORD = #{password},
               EMP_NO = #{empNo},
               RECENT_LOGIN_IP = #{recentLoginIp},
               RECENT_LOGIN_DATETIME = #{recentLoginDatetime,jdbcType=TIMESTAMP},
               LAST_MOD_DATETIME = #{lastModDatetime,jdbcType=TIMESTAMP},
               LAST_MODR_ID = #{lastModrId},
               KNOX_ID = #{knoxId},
               NICK_NAME = #{nickName},
               FIRST_NAME = #{firstName},
               LAST_NAME = #{lastName},
               EN_USER_NAME = #{userNameEn},
               EN_FIRST_NAME = #{firstNameEn},
               EN_LAST_NAME = #{lastNameEn},
               LANGUAGE_CODE = #{language},
               DISPLAY_NAME = #{displayName},
               USER_NAME = #{userName},
               COMP_NAME = #{compName},
               EN_COMP_NAME = #{compNameEn},
               COMP_CODE = #{compCode},
               DEPT_NAME = #{deptName},
               EN_DEPT_NAME = #{deptNameEn},
               DEPT_CODE = #{deptCode},
               GRD_NAME = #{grdName},
               EN_GRD_NAME = #{grdNameEn},
               GRD_CODE = #{grdCode},
               COMP_TEL_NO = #{compTel},
               MOBILE_TEL_NO = #{mobile},
               EMAIL_ADDRESS = #{email},
               LAST_LOGOUT_DATETIME = #{lastLogoutDate,jdbcType=TIMESTAMP},
               LAST_LOGIN_DATETIME = #{lastLoginDate,jdbcType=TIMESTAMP},
               LAST_LOGIN_IP = #{lastLoginIp},
               TIME_ZONE_CODE = #{timeZoneCode},
               USER_TYPE = #{userType},
               PRIVACY_POLICY = #{privacyPolicy},
               PRIVACY_POLICY_DATE = #{privacyPolicyDate,jdbcType=TIMESTAMP},
               EU_GDPR_POLICY = #{euGdprPolicy},
               EU_GDPR_POLICY_DATE = #{euGdprPolicyDate,jdbcType=TIMESTAMP},
               EXPIRE_STATUS_CODE = #{expireStatus},
               EXTERNAL_USER_FLAG = #{externalUser},
               DELETED = #{deleted},
               TIME_ZONE_ID = #{timeZoneId},
               LOGIN_ERROR_COUNT = #{loginErrorCount},
               LAST_PW_CHANGE_DATETIME = #{lastPwChangeDate,jdbcType=TIMESTAMP},
               SERVER_LOCATION = #{serverLocation},
               LAST_ACTIVITY_TIME = #{lastActivityTime},
               JWT = #{jwt}
        WHERE  USER_ID = #{userId}
    </update>

    <update id="updateUserJwt" parameterType="java.util.HashMap">
        UPDATE <include refid="tableUser" />
        SET    JWT = #{jwt},
               LAST_LOGOUT_DATETIME = #{lastLogoutDate,jdbcType=TIMESTAMP}
        WHERE  USER_ID = #{userId}
    </update>

    <select id="selectListUser" parameterType="java.util.HashMap" resultMap="userResult">
        SELECT *
        FROM   (SELECT ROW_NUMBER() OVER (<if test="@com.samsung.SdlComparator@isNotEmptyForDynamicSql(orderBy)">ORDER BY ${orderBy}</if>
		                                  <if test="@com.samsung.SdlComparator@isEmpty(orderBy)">ORDER BY USER_NAME</if>) RNUM,
		               <include refid="columnsUser" />
	            FROM   <include refid="tableUser" />
	            <include refid="conditionUser" />) T
        WHERE  T.RNUM BETWEEN (#{pageIndex} - 1) * #{pageSize} + 1 AND #{pageIndex} * #{pageSize}
    </select>

    <select id="selectUserMenuList" parameterType="java.util.HashMap" resultMap="userMenuResult">
        WITH RECURSIVE TREE_TABLE(UPPER_SYS_RESOURCE_ID, MENU_ID, LABEL, MENU_ORDER) AS
        (SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
                M.LABEL "LABEL",
                CONCAT(REPEAT('0', 4 - LENGTH(M.MENU_SEQUENCE)), M.MENU_SEQUENCE) MENU_ORDER
         FROM   <include refid="menu.tableMenu" /> M,
                <include refid="sysResource.tableSysResource" /> SR
         WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
         AND    M.DELETE_YN = '0'
         AND    M.MENU_LEVEL = 1
         UNION ALL
         SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
                CONCAT(TT.LABEL, ' > ', M.LABEL) "LABEL",
                CONCAT(TT.MENU_ORDER, ' > ', REPEAT('0', 4 - LENGTH(M.MENU_SEQUENCE)), M.MENU_SEQUENCE) MENU_ORDER
         FROM   <include refid="menu.tableMenu" /> M,
                <include refid="sysResource.tableSysResource" /> SR,
                TREE_TABLE TT
         WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
         AND    SR.UPPER_SYS_RESOURCE_ID = TT.MENU_ID
         AND    M.DELETE_YN = '0')
        SELECT UA.USER_ID, UA.SYS_RESOURCE_ID, UA.AUTHORIZATION_ID,
               TT.LABEL,
               UA.FROM_DATE, UA.THRU_DATE
        FROM   <include refid="tableUserAuthorization" /> UA,
               TREE_TABLE TT
        WHERE  UA.SYS_RESOURCE_ID = TT.MENU_ID
        AND    UA.THRU_DATE <![CDATA[ >= ]]> DATE_FORMAT(NOW(), '%Y%m%d')
        AND    UA.USER_ID = #{userId}
        ORDER BY TT.MENU_ORDER ASC
    </select>

    <insert id="insertUserMenu" parameterType="java.util.HashMap">
        INSERT INTO <include refid="tableUserAuthorization" />
        (WORKGROUP_ID, SYS_RESOURCE_ID, AUTHORIZATION_ID, USER_ID,
         FROM_DATE, THRU_DATE,
         FIRST_REG_DATETIME, FIRST_REGR_ID, LAST_MOD_DATETIME, LAST_MODR_ID)
        VALUES
        (#{workgroupId}, #{sysResourceId}, #{authorizationId}, #{userId},
         #{fromDate}, #{thruDate},
         #{firstRegDatetime,jdbcType=TIMESTAMP}, #{firstRegrId}, #{lastModDatetime, jdbcType=TIMESTAMP}, #{lastModrId})
    </insert>

    <select id="selectUserMenuCntByAuthId" parameterType="java.util.HashMap" resultType="int">
        SELECT COUNT(SYS_RESOURCE_ID) CNT
        FROM   <include refid="tableUserAuthorization" />
        WHERE  WORKGROUP_ID = #{workgroupId}
        AND    SYS_RESOURCE_ID = #{sysResourceId}
        AND    AUTHORIZATION_ID = #{authorizationId}
        AND    USER_ID = #{userId}
    </select>

    <update id="updateUserMenu" parameterType="java.util.HashMap">
        UPDATE <include refid="tableUserAuthorization" />
        SET    FROM_DATE = #{fromDate},
               THRU_DATE = #{thruDate},
               LAST_MOD_DATETIME = #{lastModDatetime, jdbcType=TIMESTAMP},
               LAST_MODR_ID = #{lastModrId}
        WHERE  WORKGROUP_ID = #{workgroupId}
        AND    SYS_RESOURCE_ID = #{sysResourceId}
        AND    USER_ID = #{userId}
    </update>

    <delete id="deleteUserMenu" parameterType="java.util.HashMap">
        DELETE FROM <include refid="tableUserAuthorization" />
        WHERE  WORKGROUP_ID = #{workgroupId}
        AND    SYS_RESOURCE_ID = #{sysResourceId}
        <if test="@com.samsung.SdlComparator@isNotEmpty(userId)">
        AND    USER_ID = #{userId}
        </if>
        <if test="@com.samsung.SdlComparator@isNotEmpty(authorizationId)">
        AND    AUTHORIZATION_ID = #{authorizationId}
        </if>
    </delete>

    <delete id="deleteUserMenuByUserId" parameterType="java.util.HashMap">
        DELETE FROM <include refid="tableUserAuthorization" />
        WHERE  USER_ID = #{userId}
    </delete>

    <delete id="deleteUserMenuByThruDate" parameterType="workGroupMenu">
        DELETE FROM <include refid="tableUserAuthorization" />
        WHERE  THRU_DATE <![CDATA[ <= ]]> #{expiredDate}
    </delete>

    <select id="selectUserIdFromUserMenuByThruDate" parameterType="java.util.HashMap" resultType="String">
		SELECT USER_ID
		FROM   <include refid="tableUserAuthorization" />
	 	WHERE  THRU_DATE = #{alarmDate}
		GROUP BY USER_ID
	</select>

    <update id="updateUserPrivacyPolicy" parameterType="user">
        UPDATE <include refid="tableUser" />
        SET    PRIVACY_POLICY = #{privacyPolicy},
               PRIVACY_POLICY_DATE = #{privacyPolicyDate,jdbcType=TIMESTAMP},
               LAST_MOD_DATETIME = #{lastModDatetime,jdbcType=TIMESTAMP},
               LAST_MODR_ID = #{lastModrId}
        WHERE  USER_ID = #{userId}
    </update>

    <update id="updateUserLoginErrorCount" parameterType="user">
        UPDATE <include refid="tableUser" />
        SET    LOGIN_ERROR_COUNT = #{loginErrorCount}
        WHERE  USER_ID = #{userId}
    </update>

</mapper>