<?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.ygtx.worklog.mapper.SystemConfigMapper">

    <resultMap type="SystemConfig" id="SystemConfigResult">
        <result property="id"    column="id"    />
        <result property="configKey"    column="config_key"    />
        <result property="configValue"    column="config_value"    />
        <result property="configType"    column="config_type"    />
        <result property="configDesc"    column="config_desc"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSystemConfigVo">
        select id, config_key, config_value, config_type, config_desc,
               create_by, create_time, update_by, update_time
        from wl_system_config
    </sql>

    <select id="selectSystemConfigList" parameterType="SystemConfig" resultMap="SystemConfigResult">
        <include refid="selectSystemConfigVo"/>
        <where>
            <if test="configKey != null  and configKey != ''"> and config_key like concat('%', #{configKey}, '%')</if>
            <if test="configType != null  and configType != ''"> and config_type = #{configType}</if>
        </where>
        order by id asc
    </select>

    <select id="selectSystemConfigById" parameterType="Long" resultMap="SystemConfigResult">
        <include refid="selectSystemConfigVo"/>
        where id = #{id}
    </select>

    <select id="selectSystemConfigByKey" parameterType="String" resultMap="SystemConfigResult">
        <include refid="selectSystemConfigVo"/>
        where config_key = #{configKey}
        limit 1
    </select>

    <insert id="insertSystemConfig" parameterType="SystemConfig" useGeneratedKeys="true" keyProperty="id">
        insert into wl_system_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="configKey != null and configKey != ''">config_key,</if>
            <if test="configValue != null">config_value,</if>
            <if test="configType != null">config_type,</if>
            <if test="configDesc != null">config_desc,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="configKey != null and configKey != ''">#{configKey},</if>
            <if test="configValue != null">#{configValue},</if>
            <if test="configType != null">#{configType},</if>
            <if test="configDesc != null">#{configDesc},</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>
         </trim>
    </insert>

    <update id="updateSystemConfig" parameterType="SystemConfig">
        update wl_system_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="configKey != null and configKey != ''">config_key = #{configKey},</if>
            <if test="configValue != null">config_value = #{configValue},</if>
            <if test="configType != null">config_type = #{configType},</if>
            <if test="configDesc != null">config_desc = #{configDesc},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSystemConfigById" parameterType="Long">
        delete from wl_system_config where id = #{id}
    </delete>

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