<?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.system.mapper.SiteConfigMapper">
    
    <resultMap type="SiteConfig" id="SiteConfigResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="value"    column="value"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectSiteConfigVo">
        select id, name, value, created_at, updated_at from site_config
    </sql>

    <select id="selectSiteConfigList" parameterType="SiteConfig" resultMap="SiteConfigResult">
        <include refid="selectSiteConfigVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="value != null  and value != ''"> and value = #{value}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectSiteConfigById" parameterType="Integer" resultMap="SiteConfigResult">
        <include refid="selectSiteConfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertSiteConfig" parameterType="SiteConfig" useGeneratedKeys="true" keyProperty="id">
        insert into site_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="value != null">value,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="value != null">#{value},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateSiteConfig" parameterType="SiteConfig">
        update site_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="value != null">value = #{value},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSiteConfigById" parameterType="Integer">
        delete from site_config where id = #{id}
    </delete>

    <delete id="deleteSiteConfigByIds" parameterType="String">
        delete from site_config where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>