<?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.gitee.gen.mapper.SystemConfigMapper">
    <resultMap id="BaseResultMap" type="com.gitee.gen.entity.SystemConfig">
        <result column="id" property="id"/>
        <result column="config_key" property="configKey"/>
        <result column="config_value" property="configValue"/>
        <result column="remark" property="remark"/>
    </resultMap>
    <!-- 表字段 -->
    <sql id="baseColumns">t.id, t.config_key, t.config_value, t.remark</sql>
    <!-- 查询全部 -->
    <select id="listAll" resultMap="BaseResultMap">SELECT
        <include refid="baseColumns"/> FROM system_config t
    </select>
    <!-- 根据主键获取单条记录 -->
    <select id="getByKey" resultMap="BaseResultMap" parameterType="String">SELECT
        <include refid="baseColumns"/> FROM system_config t WHERE config_key = #{key}
    </select>
    <!-- 根据主键获取单条记录 -->
    <select id="getById" resultMap="BaseResultMap" parameterType="Integer">SELECT
        <include refid="baseColumns"/> FROM system_config t WHERE id = #{id}
    </select>
    <!-- 插入全部字段 -->
    <insert id="insert" parameterType="com.gitee.gen.entity.SystemConfig" keyProperty="id" keyColumn="id" useGeneratedKeys="true">INSERT INTO system_config
        <trim prefix="(" suffix=")" suffixOverrides=",">config_key, config_value, remark,</trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">#{configKey}, #{configValue}, #{remark},</trim>
    </insert>
    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.gitee.gen.entity.SystemConfig" keyProperty="id" keyColumn="id" useGeneratedKeys="true">INSERT INTO system_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="configKey != null">config_key,</if>
            <if test="configValue != null">config_value,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="configKey != null">#{configKey},</if>
            <if test="configValue != null">#{configValue},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>
    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.gitee.gen.entity.SystemConfig">UPDATE system_config
        <set>config_key=#{configKey}, config_value=#{configValue}, remark=#{remark},</set> WHERE id = #{id}
    </update>
    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.gitee.gen.entity.SystemConfig">UPDATE system_config
        <set>
            <if test="configKey != null">config_key=#{configKey},</if>
            <if test="configValue != null">config_value=#{configValue},</if>
            <if test="remark != null">remark=#{remark},</if>
        </set> WHERE id = #{id}
    </update>
    <!-- 根据主键删除记录 -->
    <delete id="delete" parameterType="com.gitee.gen.entity.SystemConfig">UPDATE system_config SET is_deleted=1 WHERE id = #{id}</delete>
</mapper>
