<?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.system.VerInfoMapper">

    <select id="selectVerAppGridList" resultType="com.oqpo.api.entity.system.VerInfoEntity">
        select /* selectVerAppGridList */
                app_no, devi_tp_cd, fn_code_nm('DEVI_TP_CD', devi_tp_cd) as devi_tp_nm, app_ver, des_ver, date_format(app_ver_dt,'%Y.%m.%d %H:%i:%s') AS app_ver_dt
                , del_yn, date_format(add_dt,'%Y.%m.%d %H:%i:%s') AS  add_dt, add_id
        from np_ver_info
        where del_yn = 'N'
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'job_no'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by app_no asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by app_no desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by app_no desc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectVerAppGridCnt" resultType="int">
        select count(*)
        from np_ver_info
        where del_yn = 'N'
    </select>


    <insert id="insertVerInfo" >
        insert into np_ver_info
        (app_no, devi_tp_cd, app_ver, des_ver, app_ver_dt, del_yn, add_dt, add_id, chg_dt, chg_id)
        values
        (fn_get_key_no(35), 'SA', #{entity.appVer}, #{entity.desVer}, now(), 'N', now(), #{userId}, now(), #{userId})
    </insert>

    <update id="updateDelVerInfo" >
        UPDATE np_ver_info SET
                del_yn = 'Y',
                chg_dt = now(),
                chg_id = #{userId}
         WHERE app_no = #{appNo}
    </update>

    <select id="selectLastVerInfo" resultType="String">
        SELECT /* selectLastVerInfo */
                nvl(max(app_no),'0.0.0') as app_no
        FROM np_ver_info
        WHERE del_yn = 'N'
    </select>

    <select id="selectVerAppInfo" resultType="com.oqpo.api.entity.system.VerInfoEntity">
        SELECT /* selectVerAppInfo */
                app_no, app_ver, des_ver, date_format(app_ver_dt,'%Y.%m.%d %H:%i:%s') AS app_ver_dt
        FROM np_ver_info
        WHERE app_no = #{appNo}
    </select>
</mapper>
