<?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.goldenwater.slgc.mapper.ObjResMapper">

    <resultMap type="ObjRes" id="ObjResResult">
        <result property="resCode" column="RES_CODE"/>
        <result property="resName" column="RES_NAME"/>
        <result property="fromDate" column="FROM_DATE"/>
        <result property="toDate" column="TO_DATE"/>
    </resultMap>

    <sql id="selectObjResVo">
        select RES_CODE, RES_NAME, FROM_DATE, TO_DATE from OBJ_RES
    </sql>

    <select id="selectObjResList" parameterType="ObjRes" resultMap="ObjResResult">
        <include refid="selectObjResVo"/>
        <where>
            <if test="resName != null and resName != ''">
                and RES_NAME like concat('%', #{resName}, '%')
            </if>
        </where>
        order by RES_CODE
    </select>

    <select id="selectObjResById" parameterType="String" resultMap="ObjResResult">
        <include refid="selectObjResVo"/>
        where RES_CODE = #{resCode}
    </select>

    <delete id="deleteObjResById" parameterType="String">
        delete from OBJ_RES where RES_CODE = #{resCode}
    </delete>

    <insert id="insertObjRes" parameterType="ObjRes">
        insert into OBJ_RES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="resCode != null">RES_CODE,</if>
            <if test="resName != null">RES_NAME,</if>
            <if test="fromDate != null">FROM_DATE,</if>
            <if test="toDate != null">TO_DATE,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="resCode != null">#{resCode},</if>
            <if test="resName != null">#{resName},</if>
            <if test="fromDate != null">#{fromDate},</if>
            <if test="toDate != null">#{toDate},</if>
        </trim>
    </insert>

    <update id="updateObjRes" parameterType="ObjRes">
        update OBJ_RES
        <trim prefix="SET" suffixOverrides=",">
            <if test="resName != null">RES_NAME = #{resName},</if>
            <if test="fromDate != null">FROM_DATE = #{fromDate},</if>
            <if test="toDate != null">TO_DATE = #{toDate},</if>
        </trim>
        where RES_CODE = #{resCode}
    </update>

</mapper>
