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

    <select id="selectConsultingChartNumber" parameterType="hashmap" resultType="hashmap">
        SELECT CONCAT('C', DATE_FORMAT(NOW(), '%Y%m%d'), '-', LPAD(IFNULL(MAX(SUBSTRING(CHART_NUMBER, 11)) + 1, 1), 4, '0')) AS "chartNumber"
          FROM MU_USER_CONSULTING_CHART AS MUCC
         WHERE CHART_NUMBER LIKE CONCAT('C', DATE_FORMAT(NOW(), '%Y%m%d'), '%')
    </select>

    <insert id="insertConsultingChart" parameterType="hashmap">
        <selectKey resultType="string" keyProperty="id" order="BEFORE">
            SELECT CONCAT(#{muUserConsultingChartId},LPAD((SELECT NEXTVAL(MU_USER_CONSULTING_CHART_SEQ)), 9, 0))
        </selectKey>
        INSERT INTO MU_USER_CONSULTING_CHART(
        MU_USER_CONSULTING_CHART_ID
        ,MU_RESERVE_ID
        ,MU_USER_ID
        ,CHART_NUMBER
        ,CONTENT
        ,WRITE_MEMBER_ID
        ,WRITE_DATE
        ,WRITE_TIME
        ,CUD_FLAG
        ,USE_YN
        ,REG_ID
        ,REG_DATE
        ,MOD_ID
        ,MOD_DATE
        ,T_ID
        ,T_DATE
        )VALUES(
        #{id}
        ,#{muReserveId}
        ,#{muUserId}
        ,#{chartNumber,jdbcType=VARCHAR}
        ,#{content,jdbcType=VARCHAR}
        ,#{regId}
        ,CURDATE()
        ,CURTIME()
        ,'C'
        ,'Y'
        ,#{regId}
        ,NOW()
        ,#{modId}
        ,NOW()
        ,#{tId}
        ,#{tDate}
        )
    </insert>

    <update id="deleteConsultingChart" parameterType="hashmap">
        UPDATE MU_USER_CONSULTING_CHART
           SET MOD_ID            = #{modId}
             ,MOD_DATE	         = NOW()
             ,CUD_FLAG          = 'D'
             ,USE_YN            = 'N'
         WHERE USE_YN                       = 'Y'
           AND MU_RESERVE_ID  = #{muReserveId}
    </update>
</mapper>