<?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.kexue.skills.mapper.SysDictMapper">

    <resultMap type="com.kexue.skills.entity.SysDict" id="SysDictMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="dictCode" column="dict_code" jdbcType="VARCHAR"/>
        <result property="dictName" column="dict_name" jdbcType="VARCHAR"/>
        <result property="dictCn" column="dict_cn" jdbcType="VARCHAR"/>
        <result property="dictEn" column="dict_en" jdbcType="VARCHAR"/>
        <result property="dictValue" column="dict_value" jdbcType="OTHER"/>
        <result property="sorts" column="sorts" jdbcType="OTHER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="SysDictMap">
        select
          id, dict_code, dict_name, dict_cn, dict_en, dict_value, sorts, create_time
        from sys_dict
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="getPageList" resultMap="SysDictMap">
        select
          id, dict_code, dict_name, dict_cn, dict_en, dict_value, sorts, create_time
        from sys_dict
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="dictCode != null and dictCode != ''">
                and dict_code = #{dictCode}
            </if>
            <if test="dictName != null and dictName != ''">
                and dict_name = #{dictName}
            </if>
            <if test="dictCn != null and dictCn != ''">
                and dict_cn = #{dictCn}
            </if>
            <if test="dictEn != null and dictEn != ''">
                and dict_en = #{dictEn}
            </if>
            <if test="dictValue != null">
                and dict_value = #{dictValue}
            </if>
            <if test="sorts != null">
                and sorts = #{sorts}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
        </where>
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="SysDictMap">
        select
          id, dict_code, dict_name, dict_cn, dict_en, dict_value, sorts, create_time
        from sys_dict
        limit #{offset}, #{limit}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="SysDictMap">
        select
          id, dict_code, dict_name, dict_cn, dict_en, dict_value, sorts, create_time
        from sys_dict
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="dictCode != null and dictCode != ''">
                and dict_code = #{dictCode}
            </if>
            <if test="dictName != null and dictName != ''">
                and dict_name = #{dictName}
            </if>
            <if test="dictCn != null and dictCn != ''">
                and dict_cn = #{dictCn}
            </if>
            <if test="dictEn != null and dictEn != ''">
                and dict_en = #{dictEn}
            </if>
            <if test="dictValue != null">
                and dict_value = #{dictValue}
            </if>
            <if test="sorts != null">
                and sorts = #{sorts}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
        </where>
    </select>

    <select id="getDictListByCode" resultMap="SysDictMap">
        select
            id, dict_code, dict_name, dict_cn, dict_en, dict_value, sorts, create_time
        from sys_dict where dict_code = #{dictCode}  order by sorts asc
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into sys_dict(dict_code, dict_name, dict_cn, dict_en, dict_value, sorts, create_time)
        values (#{dictCode}, #{dictName}, #{dictCn}, #{dictEn}, #{dictValue}, #{sorts}, #{createTime})
    </insert>
    
    
    <insert id="insertBatch" parameterType="java.util.List">
    INSERT INTO sys_dict (
        <!-- 动态生成列名 -->
        <foreach collection="list" item="item" index="index" open="" close="" separator="" >
            <if test="index == 0">
                <foreach collection="tableInfo.fullColumn" item="column" open="" close="" separator=",">
                    ${column.name}
                </foreach>
            </if>
        </foreach>
    ) VALUES
    <!-- 动态生成值 -->
    <foreach collection="list" item="item" index="index" open="" close="" separator=",">
        (
        <foreach collection="tableInfo.fullColumn" item="column" open="" close="" separator=",">
            #{item.${column.property}}
        </foreach>
        )
    </foreach>
</insert>

    <!--通过主键修改数据-->
    <update id="update">
        update sys_dict
        <set>
            <if test="dictCode != null and dictCode != ''">
                dict_code = #{dictCode},
            </if>
            <if test="dictName != null and dictName != ''">
                dict_name = #{dictName},
            </if>
            <if test="dictCn != null and dictCn != ''">
                dict_cn = #{dictCn},
            </if>
            <if test="dictEn != null and dictEn != ''">
                dict_en = #{dictEn},
            </if>
            <if test="dictValue != null">
                dict_value = #{dictValue},
            </if>
            <if test="sorts != null">
                sorts = #{sorts},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from sys_dict where id = #{id}
    </delete>

</mapper>
