<?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="WebUser">
    <select id="checkUser" parameterType="hashMap" resultType="hashMap">
        SELECT  MU.USER_NAME        AS "userName"
               ,MU.PHONE_NUMBER     AS "phoneNumber"
        FROM MU_USER AS MU
        WHERE MU.MU_USER_ID  = #{muUserId}
    </select>

    <select id="selectTotalUserCount" parameterType="hashmap" resultType="Integer">
        SELECT COUNT(*)                         AS "totalCount"
          FROM MU_USER AS MU
     LEFT JOIN MU_CATEGORY_ITEM AS MCIN
            ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
     LEFT JOIN MU_CATEGORY_ITEM AS MCIT
            ON MCIT.MU_CATEGORY_ITEM_ID = MU.USER_TYPE
         WHERE MU.USE_YN = 'Y'
        <if test="userType != null and userType != ''">
           AND MCIT.CATEGORY_ITEM_CODE = #{userType}
           AND MCIT.CATEGORY_CODE = #{userTypeCode}
        </if>
        <if test="nationality != null and nationality != ''">
           AND MCIN.CATEGORY_ITEM_CODE = #{nationality}
           AND MCIN.CATEGORY_CODE = #{nationalityCode}
        </if>
        <if test="membershipYn != null and membershipYn != ''">
           AND MU.MEMBERSHIP_YN = #{membershipYn}
        </if>
        <if test="userSearchKeywordParam != null and userSearchKeywordParam != ''">
           AND (MU.USER_NAME LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
                OR MU.PHONE_NUMBER LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
                OR DATE_FORMAT(MU.BIRTHDAY,'%Y%m%d') LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%'))
        </if>
    </select>

    <select id="selectListUser" parameterType="hashmap" resultType="hashmap">
        SELECT ROW_NUMBER() OVER (ORDER BY MU.REG_DATE DESC)            AS "rowNum"
              ,MU.MU_USER_ID                                            AS "muUserId"
              ,MU.USER_NAME                                             AS "userName"
              ,MCIN.CATEGORY_ITEM_NAME                                  AS "nationality"
              ,DATE_FORMAT(MU.BIRTHDAY, '%Y-%m-%d')                     AS "birthday"
              ,TIMESTAMPDIFF(YEAR, MU.BIRTHDAY, CURDATE()) - (DATE_FORMAT(CURDATE(), '%m%d') <![CDATA[ < ]]> DATE_FORMAT(MU.BIRTHDAY, '%m%d'))
                                                                        AS "age"
              ,CASE MU.GENDER
                   WHEN 'M' THEN '남'
                   WHEN 'F' THEN '여'
                   ELSE ''
               END                                                      AS "gender"
              ,IFNULL(MCIT.FILE_PATH,MU.USER_TYPE2)                     AS "userType"
              ,MU.USER_TYPE2                                            AS "userType2"
              ,MU.PHONE_NUMBER                                          AS "phoneNumber"
              ,CASE MU.MEMBERSHIP_YN
                   WHEN 'Y' THEN '가입'
                   WHEN 'N' THEN '미가입'
               END                                                      AS "membershipYn"
              ,MU.ETC                                                   AS "etc"
              ,MU.MEMO                                                  AS "memo"
              ,IFNULL(DATE_FORMAT(MU.LAST_VISIT_DATE, '%Y-%m-%d'), '')  AS "lastVisitDate"
              ,CASE IFNULL(APP_USE_YN,'N')
                      WHEN 'Y' THEN
                                    CASE APP_STATUS
                                        WHEN 'C' THEN '가입'
                                        WHEN 'D' THEN '탈퇴'
                                        ELSE '미가입'
                                    END
                      WHEN 'N' THEN '미가입'
                END                                                      AS "appUseYn"
        FROM MU_USER AS MU
        LEFT JOIN MU_CATEGORY_ITEM AS MCIN
    ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
        LEFT JOIN MU_CATEGORY_ITEM AS MCIT
    ON MCIT.MU_CATEGORY_ITEM_ID = MU.USER_TYPE
        WHERE MU.USE_YN = 'Y'
        <if test="userType != null and userType != ''">
        AND MCIT.CATEGORY_ITEM_CODE = #{userType}
        AND MCIT.CATEGORY_CODE = #{userTypeCode}
        </if>
        <if test="nationality != null and nationality != ''">
        AND MCIN.CATEGORY_ITEM_CODE = #{nationality}
        AND MCIN.CATEGORY_CODE = #{nationalityCode}
        </if>
        <if test="membershipYn != null and membershipYn != ''">
        AND MU.MEMBERSHIP_YN = #{membershipYn}
        </if>
        <if test="appUseYn != null and appUseYn != ''">
            AND (
            (#{appUseYn} = 'Y' AND MU.APP_STATUS = 'C' AND MU.APP_USE_YN = 'Y') OR
            (#{appUseYn} = 'N' AND MU.APP_USE_YN = 'N') OR
            (#{appUseYn} = 'D' AND MU.APP_USE_YN = 'Y' AND MU.APP_STATUS = 'D')
            )
        </if>
        <if test="userSearchKeywordParam != null and userSearchKeywordParam != ''">
        AND (MU.USER_NAME LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
         OR MU.PHONE_NUMBER LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
         OR DATE_FORMAT(MU.BIRTHDAY,'%Y%m%d') LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%'))
        </if>
        <choose>
        <when test="userSort != null and userSort != ''">
    ORDER BY ${userSort}
       </when>
       <otherwise>
    ORDER BY MU.REG_DATE DESC
       </otherwise>
       </choose>
        <if test="userStart != null and userStart != ''">
            LIMIT ${userStart}
            <if test="userLimit != null and userLimit != ''">
            ,${userLimit}
            </if>
        </if>
    </select>

    <select id="selectTotalUserMarketingCount" parameterType="hashmap" resultType="Integer">
        SELECT COUNT(*)                         AS "totalCount"
          FROM MU_USER AS MU
     LEFT JOIN MU_CATEGORY_ITEM AS MCIN
            ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
     LEFT JOIN MU_CATEGORY_ITEM AS MCIT
            ON MCIT.MU_CATEGORY_ITEM_ID = MU.USER_TYPE
         WHERE MU.USE_YN = 'Y'
        <if test="userType != null and userType != ''">
           AND MCIT.CATEGORY_ITEM_CODE = #{userType}
           AND MCIT.CATEGORY_CODE = #{userTypeCode}
        </if>
        <if test="nationality != null and nationality != ''">
           AND MCIN.CATEGORY_ITEM_CODE = #{nationality}
           AND MCIN.CATEGORY_CODE = #{nationalityCode}
        </if>
        <if test="membershipYn != null and membershipYn != ''">
           AND MU.MEMBERSHIP_YN = #{membershipYn}
        </if>
        <if test="userSearchKeywordParam != null and userSearchKeywordParam != ''">
           AND (MU.USER_NAME LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
                OR MU.PHONE_NUMBER LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%'))
        </if>
    </select>

    <select id="selectListUserMarketing" parameterType="hashmap" resultType="hashmap">
        SELECT ROW_NUMBER() OVER (ORDER BY MU.REG_DATE DESC)            AS "rowNum"
              ,MU.MU_USER_ID                                            AS "muUserId"
              ,MU.USER_NAME                                             AS "userName"
              ,MCIN.CATEGORY_ITEM_NAME                                  AS "nationality"
              ,DATE_FORMAT(MU.BIRTHDAY, '%Y-%m-%d')                     AS "birthday"
              ,TIMESTAMPDIFF(YEAR, MU.BIRTHDAY, CURDATE()) - (DATE_FORMAT(CURDATE(), '%m%d') <![CDATA[ < ]]> DATE_FORMAT(MU.BIRTHDAY, '%m%d'))
                                                                        AS "age"
              ,CASE MU.GENDER
                   WHEN 'M' THEN '남'
                   WHEN 'F' THEN '여'
                   ELSE ''
               END                                                      AS "gender"
              ,IFNULL(MCIT.FILE_PATH,MU.USER_TYPE2)                     AS "userType"
              ,MU.USER_TYPE2                                            AS "userType2"
              ,MU.PHONE_NUMBER                                          AS "phoneNumber"
              ,CASE MU.MEMBERSHIP_YN
                   WHEN 'Y' THEN '가입'
                   WHEN 'N' THEN '미가입'
               END                                                      AS "membershipYn"
              ,MU.ETC                                                   AS "etc"
              ,MU.MEMO                                                  AS "memo"
              ,IFNULL(DATE_FORMAT(MU.LAST_VISIT_DATE, '%Y-%m-%d'), '')  AS "lastVisitDate"
              ,CASE IFNULL(MU.APP_USE_YN,'N')
               WHEN 'Y'
               THEN CASE MU.APP_STATUS
                    WHEN 'C'
                    THEN '가입'
                    WHEN 'D'
                    THEN '탈퇴'
                    ELSE '미가입'
                    END
               WHEN 'N'
               THEN '미가입'
                END                                                      AS "appUseYn"
          FROM MU_USER AS MU
     LEFT JOIN MU_CATEGORY_ITEM AS MCIN
            ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
     LEFT JOIN MU_CATEGORY_ITEM AS MCIT
            ON MCIT.MU_CATEGORY_ITEM_ID = MU.USER_TYPE
         WHERE MU.USE_YN = 'Y'
        <if test="userType != null and userType != ''">
           AND MCIT.CATEGORY_ITEM_CODE = #{userType}
           AND MCIT.CATEGORY_CODE = #{userTypeCode}
        </if>
        <if test="nationality != null and nationality != ''">
           AND MCIN.CATEGORY_ITEM_CODE = #{nationality}
           AND MCIN.CATEGORY_CODE = #{nationalityCode}
        </if>
        <if test="membershipYn != null and membershipYn != ''">
           AND MU.MEMBERSHIP_YN = #{membershipYn}
        </if>
        <if test="userSearchKeywordParam != null and userSearchKeywordParam != ''">
           AND (MU.USER_NAME LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
                OR MU.PHONE_NUMBER LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
                OR DATE_FORMAT(MU.BIRTHDAY,'%Y%m%d') LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%'))
        </if>
        <choose>
        <when test="userSort != null and userSort != ''">
      ORDER BY ${userSort}
       </when>
       <otherwise>
      ORDER BY MU.REG_DATE DESC
       </otherwise>
       </choose>
       <if test="userStart != null and userStart != ''">
         LIMIT ${userStart}
       <if test="userLimit != null and userLimit != ''">
              ,${userLimit}
       </if>
       </if>
    </select>

    <select id="selectTotalUserMarketingPushCount" parameterType="hashmap" resultType="Integer">
        SELECT COUNT(*)                         AS "totalCount"
          FROM MU_USER AS MU
     LEFT JOIN MU_CATEGORY_ITEM AS MCIN
            ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
     LEFT JOIN MU_CATEGORY_ITEM AS MCIT
            ON MCIT.MU_CATEGORY_ITEM_ID = MU.USER_TYPE
         WHERE MU.USE_YN = 'Y'
           AND MU.APP_USE_YN = 'Y'
        <if test="userType != null and userType != ''">
           AND MCIT.CATEGORY_ITEM_CODE = #{userType}
           AND MCIT.CATEGORY_CODE = #{userTypeCode}
        </if>
        <if test="nationality != null and nationality != ''">
           AND MCIN.CATEGORY_ITEM_CODE = #{nationality}
           AND MCIN.CATEGORY_CODE = #{nationalityCode}
        </if>
        <if test="membershipYn != null and membershipYn != ''">
           AND MU.MEMBERSHIP_YN = #{membershipYn}
        </if>
        <if test="userSearchKeywordParam != null and userSearchKeywordParam != ''">
           AND (MU.USER_NAME LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
                OR MU.PHONE_NUMBER LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%'))
        </if>
    </select>

    <select id="selectListUserMarketingPush" parameterType="hashmap" resultType="hashmap">
        SELECT ROW_NUMBER() OVER (ORDER BY MU.REG_DATE DESC)            AS "rowNum"
              ,MU.MU_USER_ID                                            AS "muUserId"
              ,MU.USER_NAME                                             AS "userName"
              ,MCIN.CATEGORY_ITEM_NAME                                  AS "nationality"
              ,DATE_FORMAT(MU.BIRTHDAY, '%Y-%m-%d')                     AS "birthday"
              ,TIMESTAMPDIFF(YEAR, MU.BIRTHDAY, CURDATE()) - (DATE_FORMAT(CURDATE(), '%m%d') <![CDATA[ < ]]> DATE_FORMAT(MU.BIRTHDAY, '%m%d'))
                                                                        AS "age"
              ,CASE MU.GENDER
                   WHEN 'M' THEN '남'
                   WHEN 'F' THEN '여'
                   ELSE ''
               END                                                      AS "gender"
              ,IFNULL(MCIT.FILE_PATH,MU.USER_TYPE2)                     AS "userType"
              ,MU.USER_TYPE2                                            AS "userType2"
              ,MU.PHONE_NUMBER                                          AS "phoneNumber"
              ,CASE MU.MEMBERSHIP_YN
                   WHEN 'Y' THEN '가입'
                   WHEN 'N' THEN '미가입'
               END                                                      AS "membershipYn"
              ,MU.ETC                                                   AS "etc"
              ,MU.MEMO                                                  AS "memo"
              ,IFNULL(DATE_FORMAT(MU.LAST_VISIT_DATE, '%Y-%m-%d'), '')  AS "lastVisitDate"
              ,CASE IFNULL(MU.APP_USE_YN,'N')
                   WHEN 'Y' THEN CASE MU.APP_STATUS
                                    WHEN 'C' THEN '가입'
                                    WHEN 'D' THEN '탈퇴'
                                    ELSE '미가입'
                                  END
                   WHEN 'N'THEN '미가입'
               END                                                      AS "appUseYn"
        FROM MU_USER AS MU
   LEFT JOIN MU_CATEGORY_ITEM AS MCIN
          ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
   LEFT JOIN MU_CATEGORY_ITEM AS MCIT
          ON MCIT.MU_CATEGORY_ITEM_ID = MU.USER_TYPE
       WHERE MU.USE_YN = 'Y'
         AND MU.APP_USE_YN = 'Y'
        <if test="userType != null and userType != ''">
         AND MCIT.CATEGORY_ITEM_CODE = #{userType}
         AND MCIT.CATEGORY_CODE = #{userTypeCode}
        </if>
        <if test="nationality != null and nationality != ''">
         AND MCIN.CATEGORY_ITEM_CODE = #{nationality}
         AND MCIN.CATEGORY_CODE = #{nationalityCode}
        </if>
        <if test="membershipYn != null and membershipYn != ''">
         AND MU.MEMBERSHIP_YN = #{membershipYn}
        </if>
        <if test="userSearchKeywordParam != null and userSearchKeywordParam != ''">
         AND (MU.USER_NAME LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
              OR MU.PHONE_NUMBER LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%'))
        </if>
        <choose>
        <when test="userSort != null and userSort != ''">
    ORDER BY ${userSort}
       </when>
       <otherwise>
    ORDER BY MU.REG_DATE DESC
       </otherwise>
       </choose>
       <if test="userStart != null and userStart != ''">
       LIMIT ${userStart}
       <if test="userLimit != null and userLimit != ''">
            ,${userLimit}
       </if>
       </if>
    </select>

    <select id="selectListUserExcel" parameterType="hashmap" resultType="hashmap">
        SELECT MU.MU_USER_ID                                AS "muUserId"
              ,MU.USER_NAME                                 AS "userName"
              ,MCIN.CATEGORY_ITEM_NAME                      AS "nationality"
              ,DATE_FORMAT(MU.BIRTHDAY, '%Y-%m-%d')                     AS "birthday"
              ,TIMESTAMPDIFF(YEAR, MU.BIRTHDAY, CURDATE()) - (DATE_FORMAT(CURDATE(), '%m%d') <![CDATA[ < ]]> DATE_FORMAT(MU.BIRTHDAY, '%m%d'))
                                                                        AS "age"
              ,CASE MU.GENDER
                   WHEN 'M' THEN '남'
                   WHEN 'F' THEN '여'
                   ELSE ''
               END                                          AS "gender"
              ,CASE MU.USER_TYPE2
                   WHEN 'Y' THEN MCIT.CATEGORY_ITEM_NAME
                   WHEN 'T' THEN '간편예약고객'
               END                                          AS "userType"
              ,MU.USER_TYPE2                                AS "userType2"
              ,MU.PHONE_NUMBER                              AS "phoneNumber"
              ,CASE MU.MEMBERSHIP_YN
                   WHEN 'Y' THEN '가입'
                   WHEN 'N' THEN '미가입'
               END                                          AS "membershipYn"
              ,MU.ETC                                       AS "etc"
              ,MU.MEMO                                      AS "memo"
              ,IFNULL(DATE_FORMAT(MU.LAST_VISIT_DATE, '%Y-%m-%d'), '')  AS "lastVisitDate"
              ,CASE IFNULL(APP_USE_YN,'N')
                      WHEN 'Y' THEN
                                    CASE APP_STATUS
                                        WHEN 'C' THEN '가입'
                                        WHEN 'D' THEN '탈퇴'
                                        ELSE '미가입'
                                    END
                      WHEN 'N' THEN '미가입'
                END                                                      AS "appUseYn"
        FROM MU_USER AS MU
        LEFT JOIN MU_CATEGORY_ITEM AS MCIN
    ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
        LEFT JOIN MU_CATEGORY_ITEM AS MCIT
    ON MCIT.MU_CATEGORY_ITEM_ID = MU.USER_TYPE
        WHERE MU.USE_YN = 'Y'
        <if test="userType != null and userType != ''">
        AND MCIT.CATEGORY_ITEM_CODE = #{userType}
        AND MCIT.CATEGORY_CODE = #{userTypeCode}
        </if>
        <if test="nationality != null and nationality != ''">
        AND MCIN.CATEGORY_ITEM_CODE = #{nationality}
        AND MCIN.CATEGORY_CODE = #{nationalityCode}
        </if>
        <if test="membershipYn != null and membershipYn != ''">
        AND MU.MEMBERSHIP_YN = #{membershipYn}
        </if>
        <if test="appUseYn != null and appUseYn != ''">
            AND (
            (#{appUseYn} = 'Y' AND MU.APP_STATUS = 'C' AND MU.APP_USE_YN = 'Y') OR
            (#{appUseYn} = 'N' AND MU.APP_USE_YN = 'N') OR
            (#{appUseYn} = 'D' AND MU.APP_USE_YN = 'Y' AND MU.APP_STATUS = 'D')
            )
        </if>
        <if test="userSearchKeywordParam != null and userSearchKeywordParam != ''">
        AND (MU.USER_NAME LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%')
        OR MU.PHONE_NUMBER LIKE CONCAT('%',TRIM(#{userSearchKeywordParam}),'%'))
        </if>
        <choose>
        <when test="userSort != null and userSort != ''">
    ORDER BY ${userSort}
        </when>
        <otherwise>
    ORDER BY MU.WRITE_DATE DESC
        </otherwise>
        </choose>
    </select>

    <select id="selectListUserPid" parameterType="hashmap" resultType="hashmap">
        SELECT MU.MU_USER_ID      AS "muUserId"
              ,MU.CRM_MEMBER_PID  AS "crmMemberPid"
              ,MU.MEMBERSHIP_YN   AS "membershipYn"
          FROM MU_USER AS MU
         WHERE MU.CRM_MEMBER_PID IS NOT NULL
    </select>

    <select id="selectUser" parameterType="hashMap" resultType="hashMap">
        SELECT MU.MU_USER_ID                               AS "muUserId"
              ,MU.USER_NUMBER                              AS "userNumber"
              ,MU.USER_NAME                                AS "userName"
              ,MCIN.CATEGORY_ITEM_CODE                     AS "nationality"
              ,MCIN.CATEGORY_ITEM_NAME                     AS "nationalityName"
              ,DATE_FORMAT(MU.BIRTHDAY, '%Y-%m-%d')        AS "birthday"
              ,MU.USER_RRN1                                AS "userRrn1"
              ,MU.USER_RRN2                                AS "userRrn2"
              ,MU.GENDER                                   AS "gender"
              ,CONCAT(
                    '만 '
                    ,TIMESTAMPDIFF(YEAR,  DATE_FORMAT(MU.BIRTHDAY, '%Y-%m-%d'), CURDATE())
                    ,'세'
               )                                           AS "identity"
              ,MU.USER_PNO                                  AS "userPno"
              ,MU.USER_ARC1                                 AS "userArc1"
              ,MU.USER_ARC2                                 AS "userArc2"
              ,MCIT.CATEGORY_ITEM_CODE                      AS "userType"
              ,MCIT.FILE_PATH                               AS "filePath"
              ,MU.USER_TYPE2                                AS "userType2"
              ,MU.PHONE_NUMBER                              AS "phoneNumber"
              ,MU.PHONE_NUMBER2                             AS "phoneNumber2"
              ,MU.EMAIL                                     AS "email"
              ,MU.ZIP_CODE                                  AS "zipCode"
              ,MU.ADDRESS                                   AS "address"
              ,MU.ADDRESS_DETAILS                           AS "addressDetails"
              ,CASE MU.MEMBERSHIP_YN
               WHEN 'Y' THEN '가입'
               WHEN 'N' THEN '미가입'
                END                                         AS "membershipYn"
              ,MU.MEMBERSHIP_ACCOUNT                        AS "membershipAccount"
              ,MU.MU_GROUP_ID                               AS "muGroupId"
              ,MCIC.CATEGORY_ITEM_CODE                      AS "channel"
              ,MCIC.CATEGORY_ITEM_NAME                      AS "channelName"
              ,MU.INTRO_USER_ID                             AS "introUserId"
              ,MU.INTRO_MEMBER_ID                           AS "introMemberId"
              ,MU.ETC                                       AS "etc"
              ,MU.MEMO                                      AS "memo"
              ,MU.EMAIL_YN                                  AS "emailYn"
              ,MU.SMS_YN                                    AS "smsYn"
              ,MU.REFUSE_PHOTO_YN                           AS "refusePhotoYn"
              ,CASE IFNULL(APP_USE_YN,'N')
               WHEN 'Y'
               THEN CASE APP_STATUS
                    WHEN 'C' THEN '가입'
                    WHEN 'D' THEN '탈퇴'
                    ELSE '미가입'
                     END
               WHEN 'N'
               THEN '미가입'
                END                                         AS "appUseYn"
              ,DATE_FORMAT(MU.APP_INTRO_DATE, '%Y-%m-%d')   AS "appIntroDate"
              ,DATE_FORMAT(MU.LEAVE_DATE, '%Y-%m-%d')       AS "leaveDate"
          FROM MU_USER AS MU
     LEFT JOIN MU_CATEGORY_ITEM AS MCIN
            ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
     LEFT JOIN MU_CATEGORY_ITEM AS MCIT
            ON MCIT.MU_CATEGORY_ITEM_ID = MU.USER_TYPE
     LEFT JOIN MU_CATEGORY_ITEM AS MCIC
            ON MCIC.MU_CATEGORY_ITEM_ID = MU.CHANNEL
         WHERE MU.USE_YN      = 'Y'
           AND MU.MU_USER_ID  = #{muUserId}
    </select>

    <select id="selectUserPhysical" parameterType="hashMap" resultType="hashMap">
        SELECT MU.USER_NAME                           AS "userName"
             ,MCIN.CATEGORY_ITEM_NAME                 AS "nationality"
             ,DATE_FORMAT(MU.BIRTHDAY, '%Y-%m-%d')    AS "birthday"
             ,MU.GENDER                               AS "gender"
             ,MU.PHONE_NUMBER                         AS "phoneNumber"
             ,MM.name                                 AS "memberName"
             ,MP.HEIGHT                               AS "height"
             ,MP.WEIGHT                               AS "weight"
             ,MP.SKELETAL_MUSCLE_MASS                 AS "muscle"
             ,MP.BODY_FAT_MASS                        AS "fatMass"
             ,MP.BODY_FAT_PERCENTAGE                  AS "fatPercent"
             ,MP.BMI                                  AS "bmi"
             ,DATE_FORMAT(MP.WRITE_DATE, '%Y-%m-%d')  AS "writeDate"
        FROM MU_USER AS MU
        LEFT JOIN MU_USER_PHYSICAL                 AS MP
               ON MU.MU_USER_ID = MP.MU_USER_ID
              AND MP.USE_YN = 'Y'
        LEFT JOIN MU_MEMBER                        AS MM
               ON MM.MU_MEMBER_ID = #{muMemberId}
              AND MM.USE_YN = 'Y'
              AND MM.STATUS= 'Y'
        LEFT JOIN
             MU_CATEGORY_ITEM AS MCIN
             ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
        WHERE MU.MU_USER_ID = #{muUserId}
        ORDER BY MP.REG_DATE DESC
        LIMIT 1;
    </select>

    <select id="selectTotalPhysicalCount" parameterType="hashmap" resultType="integer">
        SELECT
            COUNT(*)                         AS "totalCount"
        FROM MU_USER_PHYSICAL AS MP
        WHERE MP.USE_YN = 'Y'
        AND MU_USER_ID = #{muUserId}
    </select>

    <select id="selectUserPhysicalList" parameterType="hashMap" resultType="hashMap">
        SELECT ROW_NUMBER() OVER (ORDER BY MP.REG_DATE DESC)            AS "rowNum"
              ,MP.MU_USER_PHYSICAL_ID                   AS "muUserPhysicalId"
        	  ,MP.HEIGHT                                AS "height"
              ,MP.WEIGHT                                AS "weight"
              ,MP.SKELETAL_MUSCLE_MASS                  AS "muscle"
              ,MP.BODY_FAT_MASS                         AS "fatMass"
              ,MP.BODY_FAT_PERCENTAGE                   AS "fatPercent"
              ,MP.BMI                                   AS "bmi"
              ,CASE
               WHEN MP.INBODY_DATE_TIMES IS NOT NULL
               THEN DATE_FORMAT(MP.INBODY_DATE_TIMES, '%Y-%m-%d')
               ELSE DATE_FORMAT(MP.WRITE_DATE, '%Y-%m-%d')
               END                                      AS "writeDate"
              ,MP.MEMO                                  AS "memo"
              ,MM.NAME                                  AS "memberName"
              ,MU.USER_NAME                             AS "userName"
          FROM MU_USER_PHYSICAL AS MP
     LEFT JOIN MU_MEMBER AS MM
            ON MP.MU_MEMBER_ID = MM.MU_MEMBER_ID
     LEFT JOIN MU_USER AS MU
            ON MP.MU_USER_ID = MU.MU_USER_ID
         WHERE MP.USE_YN = 'Y'
           AND MP.MU_USER_ID = #{muUserId}
           AND (MM.MU_MEMBER_ID = #{muMemberId}
            OR MM.MU_MEMBER_ID IS NULL)
        <choose>
        <when test="userSort != null and userSort != ''">
      ORDER BY ${userSort}
        </when>
        <otherwise>
      ORDER BY MP.REG_DATE DESC
        </otherwise>
        </choose>
         LIMIT ${userStart}, ${userLimit}
    </select>

    <select id="selectUserPhysicalListExcel" parameterType="hashmap" resultType="hashmap">
        SELECT CAST(@RNUM:=@RNUM + 1 AS CHAR)           AS "rowNum"
              ,MP.HEIGHT                                AS "height"
              ,MP.WEIGHT                                AS "weight"
              ,MP.SKELETAL_MUSCLE_MASS                  AS "muscle"
              ,MP.BODY_FAT_MASS                         AS "fatMass"
              ,MP.BODY_FAT_PERCENTAGE                   AS "fatPercent"
              ,MP.BMI                                   AS "bmi"
              ,DATE_FORMAT(MP.WRITE_DATE, '%Y-%m-%d')   AS "writeDate"
              ,MP.MEMO                                  AS "memo"
              ,MM.NAME                                  AS "memberName"
              ,MU.USER_NAME                             AS "userName"
        FROM MU_USER_PHYSICAL AS MP
                 LEFT JOIN MU_MEMBER AS MM ON MP.MU_MEMBER_ID = MM.MU_MEMBER_ID
                 LEFT JOIN MU_USER AS MU ON MP.MU_USER_ID = MU.MU_USER_ID
        WHERE MP.USE_YN = 'Y'
          AND MP.MU_USER_ID = #{muUserId}
          AND (MM.MU_MEMBER_ID = #{muMemberId}
           OR MM.MU_MEMBER_ID IS NULL)
        <choose>
            <when test="userSort != null and userSort != ''">
                ORDER BY ${userSort}
            </when>
            <otherwise>
                ORDER BY MP.WRITE_DATE DESC
            </otherwise>
        </choose>
    </select>

	<select id="selectUserPhysical2" parameterType="hashMap" resultType="hashMap">
		SELECT MP.MU_USER_PHYSICAL_ID                   AS "muUserPhysicalId"
			  ,MP.HEIGHT                                AS "height"
			  ,MP.WEIGHT                                AS "weight"
			  ,MP.SKELETAL_MUSCLE_MASS                  AS "muscle"
			  ,MP.BODY_FAT_MASS                         AS "fatMass"
			  ,MP.BODY_FAT_PERCENTAGE                   AS "fatPercent"
			  ,MP.BMI                                   AS "bmi"
			  ,MP.MEMO                                  AS "memo"
			  ,MM.MU_MEMBER_ID                          AS "muMemberId"
			  ,MM.NAME                                  AS "memberName"
			  ,MU.USER_NAME                             AS "userName"
			  ,MCIN.CATEGORY_ITEM_NAME                  AS "nationality"
			  ,DATE_FORMAT(MU.BIRTHDAY, '%Y-%m-%d')     AS "birthday"
			  ,MU.GENDER                                AS "gender"
			  ,MU.PHONE_NUMBER                          AS "phoneNumber"
			  ,DATE_FORMAT(MP.WRITE_DATE, '%Y-%m-%d')   AS "writeDate"
		  FROM MU_USER_PHYSICAL AS MP
	 LEFT JOIN MU_MEMBER AS MM
			ON MP.MU_MEMBER_ID = MM.MU_MEMBER_ID
	 LEFT JOIN MU_USER AS MU
			ON MP.MU_USER_ID = MU.MU_USER_ID
	 LEFT JOIN MU_CATEGORY_ITEM AS MCIN
			ON MCIN.MU_CATEGORY_ITEM_ID = MU.NATIONALITY
		 WHERE MP.USE_YN              = 'Y'
		   AND MP.MU_USER_PHYSICAL_ID = #{muUserPhysicalId}
		 LIMIT 0, 1
	</select>

    <select id="selectUserAgreementListExcel" parameterType="hashmap" resultType="hashmap">
        SELECT MU.MU_USER_ID                                AS "muUserId"
              ,MU.USER_NAME                                 AS "userName"
        	  ,MA.MU_USER_AGREEMENT_ID                      AS "muUserAgreementId"
        	  ,CASE MA.TYPE
                    WHEN 'A' THEN '개인정보수집 및 이용안내'
                    WHEN 'B' THEN '메이드유 시술 동의서'
                    WHEN 'C' THEN '이용 약관 동의서'
                    WHEN 'D' THEN 'MADEU Membership 신청서'
                    WHEN 'E' THEN '메이드유 문진 동의서'
                    WHEN 'F' THEN '미성년자 시술 동의서'
                    WHEN 'G' THEN '사진 촬영 거부 동의서'
                    WHEN 'H' THEN '진료비 환불 확인서(동의서)'
                    WHEN 'I' THEN '개인정보 수집 및 이용안내(일본)'
                    WHEN 'J' THEN '시술 동의서(일본)'
                    WHEN 'K' THEN '이용 약관 동의서(일본)'
                    WHEN 'L' THEN '문진 동의서(일본)'
                    WHEN 'M' THEN '인플루언서 동의서(일본)'
                    WHEN 'N' THEN '일반체험단 동의서(일본)'
                    WHEN 'O' THEN '개인정보 수집 및 이용안내(중국)'
                    WHEN 'P' THEN '시술 동의서(중국)'
                    WHEN 'Q' THEN '이용 약관 동의서(중국)'
                    WHEN 'R' THEN '문진 동의서(중국)'
                    ELSE MA.TYPE
               END                                          AS "type"
              ,DATE_FORMAT(MA.WRITE_DATE, '%Y-%m-%d')       AS "writeDate"
              ,MA.RENEWAL_CYCLE                             AS "renewalCycle"
              ,DATE_FORMAT(MA.EXPIRATION_DATE, '%Y-%m-%d')  AS "expirationDate"
              ,MA.AGREE_YN                                  AS "agreeYn"
              ,CASE MA.AGREE_YN
					WHEN 'Y' THEN '동의'
					WHEN 'N' THEN '미동의'
					ELSE ''
			   END                                          AS "agreeYnName"
              ,(SELECT MAX(MA2.REG_DATE)
				  FROM MU_USER_AGREEMENT MA2
				 WHERE MA2.USE_YN = 'Y'
				   AND MA2.MU_USER_ID = MA.MU_USER_ID
			   )         AS "latestWriteDate"
              ,(SELECT COUNT(*)
				  FROM MU_USER_AGREEMENT MA2
				 WHERE MA2.USE_YN = 'Y'
				   AND MA2.MU_USER_ID = MA.MU_USER_ID
			   )         AS "totalCount"
		  FROM MU_USER AS MU
	LEFT OUTER JOIN MU_USER_AGREEMENT AS MA
            ON MA.MU_USER_ID = MU.MU_USER_ID
           AND MA.USE_YN = 'Y'
		 WHERE MU.MU_USER_ID = #{muUserId}
        <choose>
            <when test="userSort != null and userSort != ''">
                ORDER BY ${userSort}
            </when>
            <otherwise>
                ORDER BY MA.REG_DATE DESC
            </otherwise>
        </choose>
    </select>

    <select id="selectUserAgreementList" parameterType="hashMap" resultType="hashMap">
        SELECT ROW_NUMBER() OVER (ORDER BY MA.REG_DATE DESC)   AS "rowNum"
              ,MU.MU_USER_ID                                        AS "muUserId"
              ,MU.USER_NAME                                         AS "userName"
        	  ,MA.MU_USER_AGREEMENT_ID                              AS "muUserAgreementId"
        	  ,CASE MA.TYPE
                    WHEN 'A' THEN '개인정보수집 및 이용안내'
                    WHEN 'B' THEN '메이드유 시술 동의서'
                    WHEN 'C' THEN '이용 약관 동의서'
                    WHEN 'D' THEN 'MADEU Membership 신청서'
                    WHEN 'E' THEN '메이드유 문진 동의서'
                    WHEN 'F' THEN '미성년자 시술 동의서'
                    WHEN 'G' THEN '사진 촬영 거부 동의서'
                    WHEN 'H' THEN '진료비 환불 확인서(동의서)'
                    WHEN 'I' THEN '개인정보 수집 및 이용안내(일본)'
                    WHEN 'J' THEN '시술 동의서(일본)'
                    WHEN 'K' THEN '이용 약관 동의서(일본)'
                    WHEN 'L' THEN '문진 동의서(일본)'
                    WHEN 'M' THEN '인플루언서 동의서(일본)'
                    WHEN 'N' THEN '일반체험단 동의서(일본)'
                    WHEN 'O' THEN '개인정보 수집 및 이용안내(중국)'
                    WHEN 'P' THEN '시술 동의서(중국)'
                    WHEN 'Q' THEN '이용 약관 동의서(중국)'
                    WHEN 'R' THEN '문진 동의서(중국)'
                    ELSE MA.TYPE
               END                                          AS "type"
              ,DATE_FORMAT(MA.WRITE_DATE, '%Y-%m-%d')       AS "writeDate"
              ,MA.RENEWAL_CYCLE                             AS "renewalCycle"
              ,DATE_FORMAT(MA.EXPIRATION_DATE, '%Y-%m-%d')  AS "expirationDate"
              ,MA.AGREE_YN                                  AS "agreeYn"
              ,CASE MA.AGREE_YN
					WHEN 'Y' THEN '동의'
					WHEN 'N' THEN '미동의'
					ELSE ''
			   END                                          AS "agreeYnName"
              ,(SELECT MAX(MA2.REG_DATE)
				  FROM MU_USER_AGREEMENT MA2
				 WHERE MA2.USE_YN = 'Y'
				   AND MA2.MU_USER_ID = MA.MU_USER_ID
			   )         AS "latestWriteDate"
              ,(SELECT COUNT(*)
				  FROM MU_USER_AGREEMENT MA2
				 WHERE MA2.USE_YN = 'Y'
				   AND MA2.MU_USER_ID = MA.MU_USER_ID
			   )         AS "totalCount"
		  FROM MU_USER AS MU
	LEFT OUTER JOIN MU_USER_AGREEMENT AS MA
            ON MA.MU_USER_ID = MU.MU_USER_ID
           AND MA.USE_YN = 'Y'
		 WHERE MU.MU_USER_ID = #{muUserId}
        <choose>
            <when test="userSort != null and userSort != ''">
                ORDER BY ${userSort}
            </when>
            <otherwise>
                ORDER BY MA.REG_DATE DESC
            </otherwise>
        </choose>
        LIMIT ${userStart}, ${userLimit}
    </select>

    <select id="selectUserAgreement" parameterType="hashMap" resultType="hashMap">
        SELECT MA.MU_USER_AGREEMENT_ID                                   AS "muUserAgreementId"
        	  ,MA.MU_USER_ID                                             AS "muUserId"
        	  ,MA.USER_NAME                                              AS "userName"
        	  ,MA.TYPE                                                   AS "type"
              ,MA.RENEWAL_CYCLE                                          AS "renewalCycle"
              ,MA.AGREE_YN                                               AS "agreeYn"
              ,DATE_FORMAT(MA.EXPIRATION_DATE, '%Y-%m-%d')               AS "expirationDate"
			  ,IFNULL(CONCAT(MA.CDN_URL, MA.FILE_PATH, MA.FILE_NAME),'') AS "fileUrl"
              ,MA.AGREE3_YN                                              AS "agree3Yn"
              ,MA.PT_USER_NAME                                           AS "ptUserName"
              ,MA.PT_BIRTHDAY                                            AS "ptBirthday"
              ,MA.PT_PHONE_NUMBER                                        AS "ptPhoneNumber"
              ,MA.PT_PNO                                                 AS "ptPno"
              ,MA.PT_ADDRESS                                             AS "ptAddress"
              ,MA.PT_EMAIL                                               AS "ptEmail"
              ,MA.NOK_USER_NAME                                          AS "nokUserName"
              ,MA.NOK_BIRTHDAY                                           AS "nokBirthday"
              ,MA.NOK_RELATIONSHIP                                       AS "nokRelationship"
              ,MA.NOK_PHONE_NUMBER                                       AS "nokPhoneNumber"
              ,MA.NOK_ADDRESS                                            AS "nokAddress"
              ,MA.SNS_ITEM1                                              AS "snsItem1"
              ,MA.SNS_ITEM2                                              AS "snsItem2"
              ,MA.PT_USER_RRN                                            AS "ptUserRrn"
              ,MA.INTRO_USER_NAME                                        AS "introUserName"
              ,MA.QUESTIONNAIRE_ITEM1                                    AS "questionnaireItem1"
              ,MA.QUESTIONNAIRE_ITEM1_ETC                                AS "questionnaireItem1Etc"
              ,MA.QUESTIONNAIRE_ITEM1_DETAIL                             AS "questionnaireItem1Detail"
              ,MA.QUESTIONNAIRE_ITEM2                                    AS "questionnaireItem2"
              ,MA.QUESTIONNAIRE_ITEM2_ETC                                AS "questionnaireItem2Etc"
              ,MA.QUESTIONNAIRE_ITEM3                                    AS "questionnaireItem3"
              ,MA.QUESTIONNAIRE_ITEM3_ETC                                AS "questionnaireItem3Etc"
              ,MA.QUESTIONNAIRE_ITEM4                                    AS "questionnaireItem4"
              ,MA.QUESTIONNAIRE_ITEM4_ETC                                AS "questionnaireItem4Etc"
			  ,MA.MU_RESERVE_ID                                          AS "muReserveId"
			  ,IFNULL((SELECT MR.TREATMENT_PROCEDURE_NAME
						 FROM MU_RESERVE MR
				   		WHERE MR.USE_YN     = 'Y'
					   	  AND MR.MU_RESERVE_ID = MA.MU_RESERVE_ID
					    LIMIT 0, 1
			   ),'')                                                     AS "treatmentProcedureName"
			  ,IFNULL((SELECT MM.NAME
						 FROM MU_RESERVE MR
				   INNER JOIN MU_MEMBER MM
				   		   ON MM.MU_MEMBER_ID = MR.RESERVE_MEMBER_ID
				   		  AND MR.USE_YN     = 'Y'
					    WHERE MR.MU_RESERVE_ID = MA.MU_RESERVE_ID
					    LIMIT 0, 1
			   ),'')                                                     AS "reserveMemberName"
			  ,IFNULL((SELECT MR.TREATMENT_NAME
						 FROM MU_RESERVE MR
				   		WHERE MR.USE_YN     = 'Y'
					   	  AND MR.MU_RESERVE_ID = MA.MU_RESERVE_ID
					    LIMIT 0, 1
			   ),'')                                                     AS "treatmentName"
			  ,IFNULL((SELECT DATE_FORMAT(MR.RESERVE_DATE,'%Y-%m-%d')
						 FROM MU_RESERVE MR
				   		WHERE MR.USE_YN     = 'Y'
					   	  AND MR.MU_RESERVE_ID = MA.MU_RESERVE_ID
					    LIMIT 0, 1
			   ),'')                                                     AS "reserveDate"
			  ,IFNULL((SELECT DATE_FORMAT(MR.RESERVE_TIME, '%H:%i')
						 FROM MU_RESERVE MR
				   		WHERE MR.USE_YN     = 'Y'
					   	  AND MR.MU_RESERVE_ID = MA.MU_RESERVE_ID
					    LIMIT 0, 1
			   ),'')                                                     AS "reserveTime"
			  ,IFNULL((SELECT MP.PAYMENT_AMOUNT
						 FROM MU_RESERVE MR
                    INNER JOIN MU_PAYMENT_DETAIL MPD
                          ON MR.MU_RESERVE_ID = MPD.MU_RESERVE_ID
					   	  AND MR.USE_YN     = 'Y'
                    INNER JOIN MU_PAYMENT MP
                          ON MPD.MU_PAYMENT_ID = MP.MU_PAYMENT_ID
					   	  AND MP.USE_YN     = 'Y'
						WHERE MR.MU_RESERVE_ID = MA.MU_RESERVE_ID
					    LIMIT 0, 1
			   ),'')                                                     AS "totalAmount"
			  ,IFNULL((SELECT MP.PAYMENT_CATEGORY_ITEM_NAME
						 FROM MU_RESERVE MR
				   INNER JOIN MU_PAYMENT MP
						   ON MR.MU_RESERVE_ID = MP.MU_RESERVE_ID
					   	  AND MR.USE_YN     = 'Y'
					   	  AND MP.USE_YN     = 'Y'
						WHERE MR.MU_RESERVE_ID = MA.MU_RESERVE_ID
					    LIMIT 0, 1
			   ),'')                                                     AS "paymentCategoryItemName"
			  ,MA.RETURN_AMOUNT                                          AS "returnAmount"
			  ,MA.RETURN_METHOD_PAYMENT                                  AS "returnMethodPayment"
			  ,MA.RETURN_REASON                                          AS "returnReason"
			  ,MA.RETURN_BANK                                            AS "returnBank"
			  ,MA.RETURN_ACCOUNT                                         AS "returnAccount"
			  ,MA.RETURN_ADDRESS2                                        AS "returnAddress2"
			  ,MA.RETURN_USER_RRN2                                       AS "returnUserRrn2"
			  ,MA.RETURN_USER_NAME2                                      AS "returnUserName2"
			  ,MA.RETURN_RELATIONSHIP                                    AS "returnRelationship"
			  ,MA.RETURN_PHONE_NUMBER                                    AS "returnPhoneNumber"
              ,DATE_FORMAT(MA.WRITE_DATE, '%Y-%m-%d')                    AS "writeDate"
		  FROM MU_USER_AGREEMENT AS MA
		 WHERE MA.USE_YN               = 'Y'
		   AND MA.MU_USER_AGREEMENT_ID = #{muUserAgreementId}
        LIMIT 0, 1
    </select>

    <select id="selectUserId" parameterType="hashMap" resultType="hashMap">
        SELECT MU.MU_USER_ID       AS "muUserId"
          FROM MU_USER AS MU
         WHERE MU.USE_YN        = 'Y'
           AND MU.USER_NAME     = #{userName}
           AND MU.PHONE_NUMBER  = #{phoneNumber}
      ORDER BY MU.WRITE_DATE DESC
              ,MU.WRITE_TIME DESC
         LIMIT 0, 1
    </select>

    <select id="selectListUserVisitLastMonthAll" parameterType="hashMap" resultType="hashMap">
		SELECT MU.MU_USER_ID       AS "muUserId"
        	  ,MU.USER_NAME        AS "userName"
        	  ,MU.PHONE_NUMBER     AS "phoneNumber"
          FROM MU_USER AS MU
         WHERE MU.USE_YN        = 'Y'
           AND MU.LAST_VISIT_DATE >= DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 MONTH), '%Y-%m-%d')
      ORDER BY MU.WRITE_DATE DESC
    </select>

    <select id="selectUserSearch" parameterType="hashMap" resultType="hashMap">
        SELECT MU.MU_USER_ID                                            AS "muUserId"
              ,MU.USER_NAME                                             AS "userName"
              ,IFNULL(DATE_FORMAT(MU.BIRTHDAY, '%Y-%m-%d'),'')          AS "birthday"
              ,CASE MU.GENDER
                   WHEN 'M' THEN '남'
                   WHEN 'F' THEN '여'
                   ELSE ''
               END                                                      AS "gender"
              ,MU.PHONE_NUMBER                                          AS "phoneNumber"
              ,MU.USER_TYPE2                                            AS "userType2"
              ,IFNULL(DATE_FORMAT(MU.LAST_VISIT_DATE, '%Y-%m-%d'), '')  AS "lastVisitDate"
          FROM MU_USER AS MU
         WHERE MU.USE_YN        = 'Y'
           AND (MU.USER_NAME LIKE CONCAT('%',TRIM(#{searchKeyword}),'%')
            OR MU.PHONE_NUMBER LIKE CONCAT('%',TRIM(#{searchKeyword}),'%')
            OR DATE_FORMAT(MU.BIRTHDAY, '%Y%m%d') LIKE CONCAT('%',TRIM(#{searchKeyword}),'%'))
      ORDER BY MU.LAST_VISIT_DATE DESC
    </select>

    <select id="selectUserAgreementFile" parameterType="hashMap" resultType="hashMap">
        SELECT MUA.MU_USER_AGREEMENT_ID AS "muUserAgreementId"
			  ,MUA.FILE_PATH            AS "filePath"
			  ,MUA.FILE_NAME            AS "chgFileName"
			  ,MUA.ORG_FILE_NAME        AS "orgFileName"
          FROM MU_USER_AGREEMENT AS MUA
         WHERE MU.USE_YN        = 'Y'
           AND MU_USER_AGREEMENT  = #{muUserAgreementId}
      ORDER BY MU.WRITE_DATE DESC
              ,MU.WRITE_TIME DESC
         LIMIT 0, 1
    </select>

    <select id="selectUserPhysicalInbodyDateTimes" parameterType="hashMap" resultType="hashMap">
        SELECT COUNT(*)    AS "totalCount"
          FROM MU_USER_PHYSICAL AS MUP
         WHERE MUP.USE_YN            = 'Y'
           AND MUP.MU_USER_ID        = #{muUserId}
           AND MUP.INBODY_DATE_TIMES = #{inbodyDateTimes}
    </select>

    <select id="selectUserCheck" parameterType="hashMap" resultType="hashMap">
        SELECT MU.MU_USER_ID AS "muUserId"
          FROM MU_USER AS MU
         WHERE MU.CRM_MEMBER_PID = #{pId}
         LIMIT 0, 1
    </select>

    <insert id="insertUserAgreement" parameterType="hashmap">
        <selectKey resultType="string" keyProperty="id" order="BEFORE">
            SELECT CONCAT(#{muUserAgreementId},LPAD((SELECT NEXTVAL(MU_USER_AGREEMENT_SEQ)), 10, 0))
        </selectKey>
        INSERT INTO MU_USER_AGREEMENT(
			         MU_USER_AGREEMENT_ID
			        ,MU_USER_ID
			        ,USER_NAME
			        ,TYPE
			        ,RENEWAL_CYCLE
			        ,AGREE_YN
			        ,EXPIRATION_DATE
			        ,CDN_URL
			        ,FILE_PATH
			        ,FILE_NAME
			        ,ORIGINAL_FILE_NAME
			<choose>
			   <when test="type eq 'C'.toString()">
			        ,AGREE3_YN
			   </when>
			   <when test="type eq 'K'.toString()">
			        ,AGREE3_YN
			   </when>
			   <when test="type eq 'Q'.toString()">
			        ,AGREE3_YN
			   </when>
			   <when test="type eq 'F'.toString()">
			        ,PT_USER_NAME
			        ,PT_BIRTHDAY
			        ,PT_PHONE_NUMBER
			        ,NOK_USER_NAME
			        ,NOK_BIRTHDAY
			        ,NOK_RELATIONSHIP
			        ,NOK_PHONE_NUMBER
			        ,NOK_ADDRESS
			   </when>
			   <when test="type eq 'M'.toString() or type eq 'N'.toString()">
			        ,SNS_ITEM1
			        ,SNS_ITEM2
			        ,PT_PNO
			        ,PT_ADDRESS
			        ,PT_PHONE_NUMBER
			        ,PT_EMAIL
			   </when>
			   <when test="type eq 'E'.toString() or type eq 'L'.toString() or type eq 'R'.toString()">
			        ,PT_USER_NAME
			        ,PT_USER_RRN
			        ,INTRO_USER_NAME
			        ,QUESTIONNAIRE_ITEM1
			        ,QUESTIONNAIRE_ITEM1_ETC
			        ,QUESTIONNAIRE_ITEM1_DETAIL
			        ,QUESTIONNAIRE_ITEM2
			        ,QUESTIONNAIRE_ITEM2_ETC
			        ,QUESTIONNAIRE_ITEM3
			        ,QUESTIONNAIRE_ITEM3_ETC
			        ,QUESTIONNAIRE_ITEM4
			        ,QUESTIONNAIRE_ITEM4_ETC
			   </when>
			   <when test="type eq 'H'.toString()">
			        ,PT_USER_NAME
			        ,MU_RESERVE_ID
			        ,RETURN_AMOUNT
			        ,RETURN_METHOD_PAYMENT
			        ,RETURN_REASON
			        ,RETURN_BANK
			        ,RETURN_ACCOUNT
			        ,RETURN_ADDRESS2
			        ,RETURN_USER_RRN2
			        ,RETURN_USER_NAME2
			        ,RETURN_RELATIONSHIP
			        ,RETURN_PHONE_NUMBER
			   </when>
			</choose>
			        ,WRITE_DATE
			        ,WRITE_TIME
			        ,CUD_FLAG
			        ,USE_YN
			        ,REG_ID
			        ,REG_DATE
			        ,MOD_ID
			        ,MOD_DATE
        )VALUES(
			         #{id}
			        ,#{muUserId}
			        ,#{userName}
			        ,#{type}
			        ,#{renewalCycle}
			        ,'Y'
			        ,#{expirationDate}
			        ,#{cdnUrl}
			        ,#{filePath}
			        ,#{fileName}
			        ,#{originalFileName}
			<choose>
			   <when test="type eq 'C'.toString()">
			        ,#{agree3Yn}
			   </when>
			   <when test="type eq 'K'.toString()">
			        ,#{agree3Yn}
			   </when>
			   <when test="type eq 'Q'.toString()">
			        ,#{agree3Yn}
			   </when>
			   <when test="type eq 'F'.toString()">
			        ,#{ptUserName}
			        ,#{ptBirthday}
			        ,#{ptPhoneNumber}
			        ,#{nokUserName}
			        ,#{nokBirthday}
			        ,#{nokRelationship}
			        ,#{nokPhoneNumber}
			        ,#{nokAddress}
			   </when>
			   <when test="type eq 'M'.toString() or type eq 'N'.toString()">
			        ,#{snsItem1}
			        ,#{snsItem2}
			        ,#{ptPno}
			        ,#{ptAddress}
			        ,#{ptPhoneNumber}
			        ,#{ptEmail}
			   </when>
			   <when test="type eq 'E'.toString() or type eq 'L'.toString() or type eq 'R'.toString()">
			        ,#{ptUserName}
			        ,#{ptUserRrn}
			        ,#{introUserName}
			        ,#{questionnaireItem1}
			        ,#{questionnaireItem1Etc}
			        ,#{questionnaireItem1Detail}
			        ,#{questionnaireItem2}
			        ,#{questionnaireItem2Etc}
			        ,#{questionnaireItem3}
			        ,#{questionnaireItem3Etc}
			        ,#{questionnaireItem4}
			        ,#{questionnaireItem4Etc}
			   </when>
			   <when test="type eq 'H'.toString()">
			        ,#{ptUserName}
			        ,#{muReserveId}
			        ,#{returnAmount}
			        ,#{returnMethodPayment}
			        ,#{returnReason}
			        ,#{returnBank}
			        ,#{returnAccount}
			        ,#{address2}
			        ,#{userRrn2}
			        ,#{userName2}
			        ,#{relationship}
			        ,#{phoneNumber2}
			   </when>
			</choose>
			        ,NOW()
			        ,NOW()
			        ,'C'
			        ,'Y'
			        ,#{loginMemberId}
			        ,NOW()
			        ,#{loginMemberId}
			        ,NOW()
        )
    </insert>

    <insert id="insertUser" parameterType="hashmap">
        <selectKey resultType="HashMap" keyProperty="userNumber" order="BEFORE">
            SELECT USER.id AS id
                  ,USER.NUMBER AS number
                  ,MCIN.MU_CATEGORY_ITEM_ID AS nationality
                  ,MCIT.MU_CATEGORY_ITEM_ID AS userType
                  ,MCIC.MU_CATEGORY_ITEM_ID AS channel
              FROM (SELECT CONCAT('U', DATE_FORMAT(NOW(), '%Y%m%d'), '-', LPAD(IFNULL(MAX(SUBSTRING(USER_NUMBER, 11)) + 1, 1), 3, '0')) AS NUMBER
                          ,CONCAT(#{muUserId},LPAD((SELECT NEXTVAL(MU_USER_SEQ)), 11, 0)) AS id
                      FROM MU_USER AS MU
                     WHERE USER_NUMBER LIKE CONCAT('U', DATE_FORMAT(NOW(), '%Y%m%d'), '%')
              ) AS USER
         LEFT JOIN MU_CATEGORY_ITEM AS MCIN
                ON MCIN.CATEGORY_CODE = #{nationalityCode}
               AND MCIN.CATEGORY_ITEM_CODE = #{nationality}
         LEFT JOIN MU_CATEGORY_ITEM AS MCIT
                ON MCIT.CATEGORY_CODE = #{userTypeCode}
               AND MCIT.CATEGORY_ITEM_CODE = #{userType}
         LEFT JOIN MU_CATEGORY_ITEM AS MCIC
                ON MCIC.CATEGORY_CODE = #{channelCode}
               AND MCIC.CATEGORY_ITEM_CODE = #{channel}
        </selectKey>
        INSERT INTO MU_USER (
            MU_USER_ID
            ,USER_NUMBER
            ,USER_NAME
            ,NATIONALITY
            ,BIRTHDAY
            ,GENDER
            ,USER_RRN1
            ,USER_RRN2
            ,USER_PNO
            ,USER_ARC1
            ,USER_ARC2
            ,USER_TYPE
            ,PHONE_NUMBER
            ,PHONE_NUMBER2
            <!-- ,EMAIL
            ,EMAIL_YN
            ,ZIP_CODE
            ,ADDRESS
            ,ADDRESS_DETAILS -->
            ,MU_GROUP_ID
            ,CHANNEL
            ,INTRO_USER_ID
            ,INTRO_MEMBER_ID
            ,ETC
            ,MEMO
            ,SMS_YN
            ,REFUSE_PHOTO_YN
            ,WRITE_DATE
            ,WRITE_TIME
            ,REMARK
            ,CUD_FLAG
            ,USE_YN
            ,REG_ID
            ,REG_DATE
            ,MOD_ID
            ,MOD_DATE
        ) VALUES (
             #{userNumber.id}
            ,#{userNumber.number}
            ,#{userName}
            ,#{userNumber.nationality}
            ,#{birthday}
            ,#{gender}
            ,#{userRrn1}
            ,#{userRrn2}
            ,#{userPno}
            ,#{userArc1}
            ,#{userArc2}
            ,#{userNumber.userType}
            ,#{phoneNumber}
            ,#{phoneNumber2}
            <!-- ,#{email}
            ,#{emailYn}
            ,#{zipCode}
            ,#{address}
            ,#{addressDetails} -->
            ,#{muGroupId}
            ,#{userNumber.channel}
            ,#{introUserId}
            ,#{introMemberId}
            ,#{etc}
            ,#{memo}
            ,#{smsYn}
            ,#{refusePhotoYn}
            ,NOW()
            ,NOW()
            ,#{remark}
            ,'C'
            ,'Y'
            ,#{modId}
            ,NOW()
            ,#{regId}
            ,NOW()
        )
    </insert>

    <insert id="insertUserBatch" parameterType="hashmap">
        <selectKey resultType="string" keyProperty="id" order="BEFORE">
            SELECT CONCAT(#{muUserId},LPAD((SELECT NEXTVAL(MU_USER_SEQ)), 11, 0))
        </selectKey>
        INSERT INTO MU_USER (
                    MU_USER_ID
                   ,USER_NUMBER
                   ,USER_NAME
                   ,NATIONALITY
                   ,BIRTHDAY
                   ,GENDER
                   ,USER_RRN1
                   ,USER_RRN2
                   ,USER_PNO
                   ,USER_ARC1
                   ,USER_ARC2
                   ,USER_TYPE
                   ,USER_TYPE2
                   ,PHONE_NUMBER
                   ,PHONE_NUMBER2
                   ,EMAIL
                   ,ZIP_CODE
                   ,ADDRESS
                   ,ADDRESS_DETAILS
                   ,MEMBERSHIP_YN
                   ,MEMBERSHIP_ACCOUNT
                   ,MEMBERSHIP_PASSWORD
                   ,MU_GROUP_ID
                   ,CHANNEL
                   ,INTRO_USER_ID
                   ,INTRO_MEMBER_ID
                   ,ETC
                   ,MEMO
                   ,EMAIL_YN
                   ,SMS_YN
                   ,LAST_VISIT_DATE
                   ,WRITE_DATE
                   ,WRITE_TIME
                   ,REMARK
                   ,CUD_FLAG
                   ,USE_YN
                   ,REG_ID
                   ,REG_DATE
                   ,MOD_ID
                   ,MOD_DATE
                   ,T_ID
                   ,T_DATE
                   ,CRM_MEMBER_PID
                   ,CRM_MEMBER_MB_COUNTRY
                   ,CRM_MEMBER_MB_INTRO_NO
                   ,CRM_MEMBER_STAFF_PID
                   ,CRM_MEMBER_MB_HP
                   ,CRM_MEMBER_MB_TEL
        )    SELECT #{id}                          AS MU_USER_ID <!-- 식별자 -->
                   ,CM.MB_NO                       AS USER_NUMBER  <!-- 고객번호 -->
                   ,CM.MB_NAME                     AS USER_NAME <!-- 이름 -->
                   ,(SELECT MCI.MU_CATEGORY_ITEM_ID
                       FROM MU_CATEGORY_ITEM AS MCI
                      WHERE MCI.USE_YN = 'Y'
                        AND MCI.MU_CATEGORY_ID = 'C17128016604480000000001'
                        AND SUBSTR(MCI.CATEGORY_ITEM_NAME, 1, 2) = (CASE
                                                                    WHEN CM.MB_COUNTRY = ''
                                                                    THEN '한국'
                                                                    WHEN CM.MB_COUNTRY = '대한민국'
                                                                    THEN '한국'
                                                                    ELSE CM.MB_COUNTRY
                                                                    END)
                      LIMIT 0, 1)                  AS NATIONALITY <!-- 국적 -->
                   ,CM.MB_BIRTH                    AS BIRTHDAY <!-- 생년월일 -->
                   ,CM.MB_SEX                      AS GENDER <!-- 성별 -->
                   ,CM.MB_JUMIN1                   AS USER_RRN1 <!-- 주민번호1 -->
                   ,CM.MB_JUMIN2                   AS USER_RRN2 <!-- 주민번호2 -->
                   ,''                             AS USER_PNO <!-- 여권번호 -->
                   ,CM.MB_JUMIN1                   AS USER_ARC1  <!-- 외국인등록번호 -->
                   ,CM.MB_JUMIN2                   AS USER_ARC2  <!-- 외국인등록번호2 -->
                   ,'CI1718360267449000000065'     AS USER_TYPE  <!-- 고객구분 (모두 일반으로 등록) -->
                   ,'Y'                            AS USER_TYPE2 <!-- 진료완료/수납내역으로 분류 (수납내역 등록 후 업데이트 쿼리) -->
                   ,IF(LENGTH(REPLACE(CM.MB_HP, '-', '')) = 11, REPLACE(CM.MB_HP, '-', ''), '')
                                                   AS PHONE_NUMBER <!-- 연락처 -->
                   ,IF(LENGTH(REPLACE(CM.MB_TEL, '-', '')) = 11, REPLACE(CM.MB_HP, '-', ''), '')
                                                   AS PHONE_NUMBER2 <!-- 보조연락처 -->
                   ,CM.MB_EMAIL                    AS EMAIL <!-- 이메일 -->
                   ,CM.MB_ZIP                      AS ZIP_CODE <!-- 우편변호 -->
                   ,CM.MB_ADD1                     AS ADDRESS <!-- 주소 -->
                   ,CM.MB_ADD2                     AS ADDRESS_DETAILS <!-- 상세주소 -->
                   ,'N'                            AS MEMBERSHIP_YN <!-- 멤버십 여부 (수납내역에서 조회 후 업데이트 쿼리) -->
                   ,''                             AS MEMBERSHIP_ACCOUNT <!-- 멤버십 계정 -->
                   ,''                             AS MEMBERSHIP_PASSWORD <!-- 비밀번호 (암호화) -->
                   ,''                             AS MU_GROUP_ID <!-- 진료 식별자 -->
                   ,CM.MB_CHANNEL                  AS CHANNEL <!-- 방문경로 -->
                   ,''                             AS INTRO_USER_ID <!-- 소개자(고객) 식별자 (고객 차트 번호) (고객 등록 후 업데이트 쿼리) -->
                   ,''                             AS INTRO_MEMBER_ID <!-- 소개자(직원) 식별자 () (고객 등록 후 업데이트 쿼리) -->
                   ,''                             AS ETC <!-- 특이사항 -->
                   ,CM.MB_TEXT                     AS MEMO <!-- 고객 메모 (기존 특이사항 -> 고객 메모로 저장) -->
                   ,'N'                            AS EMAIL_YN <!-- 이메일수신여부 -->
                   ,UPPER(CM.MB_SMS)               AS SMS_YN <!-- SMS수신여부 -->
                   ,NULL                           AS LAST_VISIT_DATE <!-- 최근내원일자(접수시 업데이트) -->
                   ,CM.REG_DATE                    AS WRITE_DATE <!-- 작성일자 -->
                   ,CM.REG_DATE                    AS WRITE_TIME <!-- 작성시간 -->
                   ,''                             AS REMARK <!-- 비고 -->
                   ,'C'                            AS CUD_FLAG <!-- 작업타입 (C: 등록, U: 수정, D : 삭제) -->
                   ,CASE
                    WHEN CM.MB_DEL = 'N'
                    THEN 'Y'
                    WHEN CM.MB_DEL = 'Y'
                    THEN 'N'
                    ELSE ''
                    END                            AS USE_YN <!-- 사용여부 -->
                   ,'BatchSystem'                  AS REG_ID <!-- 등록자 -->
                   ,CM.REG_DATE                    AS REG_DATE <!-- 등록일자 -->
                   ,'BatchSystem'                  AS MOD_ID <!-- 수정자 -->
                   ,CM.UP_DATE                     AS MOD_DATE <!-- 수정일자 -->
                   ,#{tId}                         AS T_ID <!-- 트랜잭션 ID -->
                   ,#{tDate}                       AS T_DATE <!-- 트랜잭션 DATE -->
                   ,CM.PID                         AS CRM_MEMBER_PID <!-- 기존 DB 식별자 -->
                   ,CM.MB_COUNTRY                  AS CRM_MEMBER_MB_COUNTRY <!-- 기존 DB 국적 -->
                   ,CM.MB_INTRO_NO                 AS CRM_MEMBER_MB_INTRO_NO <!-- 기존 DB 고객 차트 번호 -->
                   ,CM.STAFF_PID                   AS CRM_MEMBER_STAFF_PID <!-- 기존 DB 직원 식별자 -->
                   ,CM.MB_HP                       AS CRM_MEMBER_MB_HP <!-- 기존 DB 직원 식별자 -->
                   ,CM.MB_TEL                      AS CRM_MEMBER_MB_TEL <!-- 기존 DB 직원 식별자 -->
               FROM CRM_MEMBER AS CM
              WHERE CM.PID = #{pId}
    </insert>


	<insert id="insertUserTemp" parameterType="hashmap">
		<selectKey resultType="string" keyProperty="id" order="BEFORE">
			SELECT CONCAT(#{muUserId},LPAD((SELECT NEXTVAL(MU_USER_SEQ)), 11, 0))
		</selectKey>
			INSERT INTO MU_USER (
						 MU_USER_ID
						,USER_NUMBER
						,USER_NAME
						,USER_TYPE2
						,PHONE_NUMBER
						,BIRTHDAY
						,CHANNEL
						,EMAIL_YN
						,SMS_YN
						,WRITE_DATE
						,WRITE_TIME
						,CUD_FLAG
						,USE_YN
						,REG_ID
						,REG_DATE
						,MOD_ID
						,MOD_DATE
						,T_ID
						,T_DATE
			) VALUES (
						 #{id}
						,(SELECT CONCAT('U', DATE_FORMAT(NOW(), '%Y%m%d'), '-', LPAD(IFNULL(MAX(SUBSTRING(USER_NUMBER, 11)) + 1, 1), 3, '0'))
							FROM MU_USER AS MU
						   WHERE USER_NUMBER LIKE CONCAT('U', DATE_FORMAT(NOW(), '%Y%m%d'), '%')
						 )
						,#{userName}
						,'T'
						,#{phoneNumber}
						,#{birthday}
						,(SELECT MU_CATEGORY_ITEM_ID
							FROM MU_CATEGORY_ITEM
						   WHERE MU_CATEGORY_ITEM_ID = #{reserveCategoryItemId}
						   LIMIT 0, 1
						 )
						,'N'
						,'N'
						,CURDATE()
						,CURTIME()
						,'C'
						,'Y'
						,#{regId}
						,NOW()
						,#{modId}
						,NOW()
						,#{tId}
						,#{tDate}
			)
	</insert>

    <insert id="insertPhysical" parameterType="hashmap">
        <selectKey resultType="string" keyProperty="id" order="BEFORE">
            SELECT CONCAT(#{muUserPhysicalId},LPAD((SELECT NEXTVAL(MU_USER_PHYSICAL_SEQ)), 10, 0))
        </selectKey>
       		INSERT INTO MU_USER_PHYSICAL (
			             MU_USER_PHYSICAL_ID
			            ,MU_USER_ID
			            ,HEIGHT
			            ,WEIGHT
			            ,SKELETAL_MUSCLE_MASS
			            ,BODY_FAT_MASS
			            ,BODY_FAT_PERCENTAGE
			            ,BMI
			            ,MU_MEMBER_ID
			            ,MEMO
			            ,INBODY_DATE_TIMES
			            ,WRITE_DATE
			            ,WRITE_TIME
			            ,USE_YN
			            ,REG_ID
			            ,REG_DATE
			            ,MOD_ID
			            ,MOD_DATE
			            ,T_ID
			            ,T_DATE
	        ) VALUES (
			             #{id}
			            ,#{muUserId}
			            ,#{height}
			            ,#{weight}
			            ,#{muscleMass}
			            ,#{fatMass}
			            ,#{fatPercent}
			            ,#{bmi}
			            ,#{muMemberId,jdbcType=VARCHAR}
			            ,#{memo,jdbcType=VARCHAR}
			            ,#{inbodyDateTimes,jdbcType=VARCHAR}
			            ,now()
			            ,now()
			            ,'Y'
			            ,#{regId}
			            ,now()
			            ,#{modId}
			            ,now()
			            ,#{tId}
			            ,#{tDate}
	         );

    </insert>
    <update id="updateUser" parameterType="hashmap">
        <!--<selectKey resultType="HashMap" keyProperty="userNumber" order="BEFORE">
            SELECT MCIN.MU_CATEGORY_ITEM_ID       AS nationality
                  ,MCIT.MU_CATEGORY_ITEM_ID       AS userType
                  ,MCIC.MU_CATEGORY_ITEM_ID       AS channel
              FROM MU_CATEGORY_ITEM AS MCIN
         LEFT JOIN MU_CATEGORY_ITEM AS MCIT
                ON MCIT.CATEGORY_CODE = #{userTypeCode}
               AND MCIT.CATEGORY_ITEM_CODE = #{userType}
         LEFT JOIN MU_CATEGORY_ITEM AS MCIC
                ON MCIC.CATEGORY_CODE = #{channelCode}
               AND MCIC.CATEGORY_ITEM_CODE = #{channel}
             WHERE MCIN.CATEGORY_CODE = #{nationalityCode}
               AND MCIN.CATEGORY_ITEM_CODE = #{nationality}
        </selectKey>-->
        UPDATE MU_USER
           SET MOD_ID               = #{modId}
              ,MOD_DATE             = NOW()
              ,CUD_FLAG             = 'U'
              ,USER_NAME            = #{userName}
              ,NATIONALITY          = (SELECT MCI.MU_CATEGORY_ITEM_ID
                                         FROM MU_CATEGORY_ITEM AS MCI
                                        WHERE MCI.USE_YN = 'Y'
                                          AND MCI.CATEGORY_CODE = #{nationalityCode}
                                          AND MCI.CATEGORY_ITEM_CODE = #{nationality})
              ,BIRTHDAY             = #{birthday}
              ,GENDER               = #{gender}
              ,USER_RRN1            = #{userRrn1}
              ,USER_RRN2            = #{userRrn2}
              ,USER_PNO             = #{userPno}
              ,USER_ARC1            = #{userArc1}
              ,USER_ARC2            = #{userArc2}
              ,USER_TYPE            = (SELECT MCI.MU_CATEGORY_ITEM_ID
                                         FROM MU_CATEGORY_ITEM AS MCI
                                        WHERE MCI.USE_YN = 'Y'
                                          AND MCI.CATEGORY_CODE = #{userTypeCode}
                                          AND MCI.CATEGORY_ITEM_CODE = #{userType})
              ,PHONE_NUMBER         = #{phoneNumber}
              ,PHONE_NUMBER2        = #{phoneNumber2}
              <!-- ,EMAIL                = #{email}
              ,EMAIL_YN             = #{emailYn}
              ,ZIP_CODE             = #{zipCode}
              ,ADDRESS              = #{address}
              ,ADDRESS_DETAILS      = #{addressDetails} -->
              ,MU_GROUP_ID          = #{muGroupId}
              ,CHANNEL              = (SELECT MCI.MU_CATEGORY_ITEM_ID
                                         FROM MU_CATEGORY_ITEM AS MCI
                                        WHERE MCI.USE_YN = 'Y'
                                          AND MCI.CATEGORY_CODE = #{channelCode}
                                          AND MCI.CATEGORY_ITEM_CODE = #{channel})
              ,INTRO_USER_ID        = #{introUserId}
              ,INTRO_MEMBER_ID      = #{introMemberId}
              ,ETC                  = #{etc}
              ,MEMO                 = #{memo}
              ,SMS_YN               = #{smsYn}
              ,REFUSE_PHOTO_YN      = #{refusePhotoYn}
              ,MU_MEMBER_ID2        = #{muMemberId2}
              ,INTRO_NAME           = #{introName}
              ,INTRO_SMS            = #{introSms}
              ,INTRO_NO             = #{introNo}
              ,USER_TYPE2           = 'Y'
         WHERE USE_YN               = 'Y'
           AND MU_USER_ID         = #{muUserId}
    </update>
    
    <update id="updateMembershipYn" parameterType="hashmap">
        UPDATE MU_USER
        SET MOD_ID              = #{modId}
          ,MOD_DATE            = NOW()
          ,CUD_FLAG            = 'U'
          ,MEMBERSHIP_YN       = 'Y'
        WHERE USE_YN        = 'Y'
          AND MU_USER_ID  = #{muUserId}
    </update>

    <update id="updateMembershipYnBatch" parameterType="hashmap">
        UPDATE MU_USER
           SET MOD_ID          = 'BatchSystem'
              ,MOD_DATE        = NOW()
              ,CUD_FLAG        = 'U'
              ,MEMBERSHIP_YN   = 'Y'
         WHERE USE_YN      = 'Y'
           AND MU_USER_ID  = #{muUserId}
    </update>

    <update id="updateUserLastVisitDate" parameterType="hashmap">
        UPDATE MU_USER
           SET MOD_ID              = #{modId}
              ,MOD_DATE            = NOW()
              ,CUD_FLAG            = 'U'
              ,LAST_VISIT_DATE     = IFNULL(LAST_VISIT_DATE, NOW())
              ,LAST_VISIT_DATE     = IFNULL(LAST_VISIT_DATE, NOW())
         WHERE USE_YN        = 'Y'
           AND MU_USER_ID  = #{muUserId}
    </update>
	
	<update id="updateUserPhysical" parameterType="hashmap">
		UPDATE MU_USER_PHYSICAL
		   SET MOD_ID         = #{modId}
			  ,MOD_DATE       = NOW()
			  ,CUD_FLAG       = 'U'
			  ,MU_MEMBER_ID   = #{muMemberId,jdbcType=VARCHAR}
		 WHERE USE_YN               = 'Y'
		   AND MU_USER_PHYSICAL_ID  = #{muUserPhysicalId}
	</update>
</mapper>