<?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="com.oqpo.api.mapper.oper.MailFormMapper">
    <select id="selectMailFormGridList" resultType="com.oqpo.api.entity.oper.MailFormEntity">
        select /* MailForm.selectMailFormGridList*/
               mail_form_no, mail_form_nm, mail_status_cd, fn_code_nm('MAIL_STATUS_CD',mail_status_cd) AS mail_status_nm, date_format(add_dt ,'%Y.%m.%d') as add_dt
        from   np_mail_form
        where  1=1
        <if test="sMailFormNm != null and sMailFormNm != ''">
        and    mail_form_nm like concat('%',#{sMailFormNm},'%')
        </if>
        <if test="sMailStatusCd != null and sMailStatusCd != ''">
        and    mail_status_cd = #{sMailStatusCd}
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by mail_form_nm asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by mail_form_nm desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by mail_form_nm asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectMailFormGridCnt" resultType="int">
        select /* MailForm.selectMailFormGridCnt*/
        count(*) as cnt
        from   np_mail_form
        where  1=1
        <if test="sMailFormNm != null and sMailFormNm != ''">
            and    mail_form_nm like concat('%',#{sMailFormNm},'%')
        </if>
        <if test="sMailStatusCd != null and sMailStatusCd != ''">
        and    mail_status_cd = #{sMailStatusCd}
        </if>
    </select>

    <select id="selectMailFormInfo" resultType="com.oqpo.api.entity.oper.MailFormEntity">
        select  /* MailForm.selectMailFormInfo */
                mail_form_no, mail_form_nm, mail_subject, mail_status_cd, fn_code_nm('MAIL_STATUS_CD',mail_status_cd) AS mail_status_nm, file_no, mail_desc
        from  np_mail_form
        where mail_form_no = #{mailFormNo}
    </select>

    <insert id="insertMailFormInfo" >
        insert into np_mail_form   /* MailForm.insertMailFormInfo*/
        (mail_form_no, mail_form_nm, mail_subject, mail_status_cd, file_no, mail_desc, add_dt, add_id, chg_dt, chg_id)
        values
        (#{entity.mailFormNo}, #{entity.mailFormNm}, #{entity.mailSubject}, #{entity.mailStatusCd}, #{entity.fileNo}, #{entity.mailDesc}, now(), #{userId}, now(), #{userId})
    </insert>

    <update id="updateMailFormInfo">
        update np_mail_form  /* MailForm.updateMailFormInfo*/
        set    chg_dt = now()
              , chg_id = #{userId}
              , mail_form_nm = #{entity.mailFormNm}
              , mail_subject = #{entity.mailSubject}
              , mail_status_cd = #{entity.mailStatusCd}
              , file_no = #{entity.fileNo}
              , mail_desc = #{entity.mailDesc}
        where  mail_form_no = #{entity.mailFormNo}
    </update>


</mapper>
