<?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="ink.wgink.login.base.dao.config.IConfigDao">

    <cache flushInterval="3600000"/>

    <resultMap id="configDTO" type="ink.wgink.login.base.pojo.dtos.config.ConfigDTO">
        <result property="configKey" column="config_key"/>
        <result property="configValue" column="config_value"/>
    </resultMap>

    <!-- 建表 -->
    <update id="createTable">
        CREATE TABLE IF NOT EXISTS `sys_config` (
            `config_key` varchar(255) NOT NULL,
            `config_value` longtext,
            PRIMARY KEY (`config_key`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    </update>

    <!-- 新增配置 -->
    <insert id="save" parameterType="map" flushCache="true">
        INSERT INTO sys_config(
            config_key,
            config_value
        ) VALUES(
            #{configKey},
            #{configValue}
        )
    </insert>

    <!-- 更新配置 -->
    <update id="update" parameterType="map" flushCache="true">
        UPDATE
            sys_config
        SET
            config_value = #{configValue}
        WHERE
            config_key = #{configKey}
    </update>

    <!-- 配置列表 -->
    <select id="list" resultMap="configDTO" useCache="true">
        SELECT
            *
        FROM
            sys_config
    </select>

    <!-- 获取配置 -->
    <select id="get" parameterType="String" resultMap="configDTO" useCache="true">
        SELECT
            *
        FROM
            sys_config
        WHERE
            config_key = #{_parameter}
    </select>
</mapper>