<?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.ruoyi.frequency.agreement.mapper.AgreementMapper">
    
    <resultMap type="com.ruoyi.frequency.agreement.entity.Agreement" id="AgreementResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="code"    column="code"    />
    </resultMap>

    <sql id="selectAgreementVo">
        select id, del_flag, create_by, create_time, update_by, update_time, title, content, code from t_agreement
    </sql>

    <select id="selectAgreementList" parameterType="com.ruoyi.frequency.agreement.entity.Agreement" resultMap="AgreementResult">
        <include refid="selectAgreementVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
        </where>
       order by create_time desc
    </select>
    
    <select id="selectAgreementById" parameterType="Long" resultMap="AgreementResult">
        <include refid="selectAgreementVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAgreement" parameterType="com.ruoyi.frequency.agreement.entity.Agreement">
        insert into t_agreement
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="code != null">code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="code != null">#{code},</if>
         </trim>
    </insert>

    <update id="updateAgreement" parameterType="com.ruoyi.frequency.agreement.entity.Agreement">
        update t_agreement
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="code != null">code = #{code},</if>
        </trim>
        where id = #{id}
    </update>

</mapper>