<?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.ghy.system.mapper.SysGlobalConfigMapper">

    <resultMap type="com.ghy.system.domain.SysGlobalConfig" id="BaseResultMap">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="content" property="content"/>
        <result column="sort" property="sort"/>
        <result column="type" property="type"/>
        <result column="sys_default" property="sysDefault"/>
        <result column="describe" property="describe"/>
        <result column="data_type" property="dataType"/>
        <result column="config_unit" property="configUnit"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>
    <sql id="tableName">sys_global_config</sql>

    <sql id="allColumns">
        `id`
        , `name`, `content`, `sort`, `type`,`sys_default`, `describe`, `data_type`, `config_unit`,
            `create_time`, `update_time`
    </sql>

    <insert id="creates" keyProperty="id" keyColumn="id" useGeneratedKeys="true">
        INSERT INTO
        <include refid="tableName"/>
        (`name`, `content`, `sort`, `type`,`sys_default`, `describe`, `data_type`, `config_unit`,
        `create_time`, `update_time`)
        VALUES
        <foreach item="item" index="sysConfigs" collection="sysConfigs" separator=",">
            (
            #{item.name},
            #{item.content},
            #{item.sort},
            #{item.type},
            #{item.sysDefault},
            #{item.describe},
            #{item.dataType},
            #{item.configUnit},
            #{item.createTime},
            #{item.updateTime}
            )
        </foreach>
    </insert>

    <update id="updateById">
        update
        <include refid="tableName"/>
        <set>
            `name` = #{sysGlobalConfig.name},
            `content` = #{sysGlobalConfig.content},
            `sort` = #{sysGlobalConfig.sort},
            `type` = #{sysGlobalConfig.type},
            `sys_default` = #{sysGlobalConfig.sysDefault},
            `describe` = #{sysGlobalConfig.describe},
            `data_type` = #{sysGlobalConfig.dataType},
            `config_unit` = #{sysGlobalConfig.configUnit},
            `update_time` = #{sysGlobalConfig.updateTime}
        </set>
        <where>
            `id` = #{sysGlobalConfig.id}
        </where>
    </update>

    <select id="selectById" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from
        <include refid="tableName"/>
        <where>
            `id` = #{id}
        </where>
    </select>

    <select id="loadByConfigType" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from
        <include refid="tableName"/>
        <where>
            `type` = #{configType}
        </where>
    </select>

    <delete id="deleteById">
        delete from
        <include refid="tableName"/>
        <where>
            `id` = #{id}
        </where>
    </delete>

    <select id="vailName" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from
        <include refid="tableName"/>
        <where>
            `name` = #{name} and sys_default = 0
        </where>
    </select>


</mapper>