<?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="MobileUserPhysical">
    <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}
        <if test="physicalSearchDate != null and physicalSearchDate != ''">
            AND DATE_FORMAT(MP.WRITE_DATE, '%Y-%m') = #{physicalSearchDate}
        </if>
    </select>

    <select id="selectUserPhysicalList" parameterType="hashMap" resultType="hashMap">
        SELECT MP.HEIGHT                                AS "height"
             , MP.WEIGHT                                AS "weight"
             , MP.BMI                                   AS "bmi"
             , 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
         WHERE MP.USE_YN = 'Y'
           AND MP.MU_USER_ID = #{muUserId}
           AND DATE_FORMAT(MP.WRITE_DATE, '%Y-%m') = #{physicalSearchDate}
         ORDER BY MP.REG_DATE DESC
    </select>

    <select id="selectRecentUserPhysicalList" parameterType="hashMap" resultType="hashMap">
        SELECT MP.HEIGHT                                        AS "height"
             , MP.WEIGHT                                        AS "weight"
             , MP.BMI                                           AS "bmi"
             , CONCAT(DATE_FORMAT(MP.WRITE_DATE, '%m'),'/',DATE_FORMAT(MP.WRITE_DATE, '%d'))    AS "writeDate"
          FROM MU_USER_PHYSICAL AS MP
         WHERE MP.USE_YN = 'Y'
           AND MP.MU_USER_ID = #{muUserId}
         ORDER BY MP.REG_DATE
         LIMIT 6
    </select>
</mapper>