<?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.bonus.sgzb.base.mapper.SysDicMapper">
    <resultMap type="com.bonus.sgzb.base.api.domain.SysDic" id="SysDicResult">
        <result property="id" column="id"/>
        <result property="pId" column="p_id"/>
        <result property="code" column="code"/>
        <result property="name" column="name"/>
        <result property="description" column="description"/>
        <result property="value" column="value"/>
        <result property="sort" column="sort"/>
        <result property="level" column="level"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="creator" column="creator"/>
    </resultMap>
    <sql id="selectSysDicVo"> select id, p_id, code, name, description, value, sort, level, status, create_time, creator from sys_dic </sql>
    <select id="selectSysDicList" parameterType="com.bonus.sgzb.base.api.domain.SysDic" resultMap="SysDicResult">
        <include refid="selectSysDicVo"/>
        <where>
            p_id = #{id}
            <if test="code != null and code != ''"> and code = #{code}</if>
            <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="description != null and description != ''"> and description = #{description}</if>
            <if test="value != null and value != ''"> and value = #{value}</if>
            <if test="sort != null and sort != ''"> and sort = #{sort}</if>
            <if test="level != null and level != ''"> and level = #{level}</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
            <if test="creator != null and creator != ''"> and creator = #{creator}</if>
        </where>
    </select>
    <select id="selectSysDic" parameterType="com.bonus.sgzb.base.api.domain.SysDic" resultMap="SysDicResult">
        <include refid="selectSysDicVo"/>
        <where>
            id = #{id}
            <if test="code != null and code != ''"> and code = #{code}</if>
            <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="description != null and description != ''"> and description = #{description}</if>
            <if test="value != null and value != ''"> and value = #{value}</if>
            <if test="sort != null and sort != ''"> and sort = #{sort}</if>
            <if test="level != null and level != ''"> and level = #{level}</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
            <if test="creator != null and creator != ''"> and creator = #{creator}</if>
        </where>
    </select>
    <select id="selectSysDicLists" parameterType="com.bonus.sgzb.base.api.domain.SysDic" resultMap="SysDicResult">
        <include refid="selectSysDicVo"/>
        <where>
            p_id = #{id}
            <if test="code != null and code != ''"> and code = #{code}</if>
            <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="description != null and description != ''"> and description = #{description}</if>
            <if test="value != null and value != ''"> and value = #{value}</if>
            <if test="sort != null and sort != ''"> and sort = #{sort}</if>
            <if test="level != null and level != ''"> and level = #{level}</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
            <if test="creator != null and creator != ''"> and creator = #{creator}</if>
        </where>
    </select>
    <select id="selectSysDicById" parameterType="Long" resultMap="SysDicResult">
        <include refid="selectSysDicVo"/>
        where id = '0'
    </select>
    <select id="selectByName" resultType="com.bonus.sgzb.base.api.domain.SysDic">
            select * from sys_dic
            where
            status != 2
            <if test="name != null and name != ''">and name = #{name}</if>
    </select>
    <select id="getBear" resultType="java.lang.String">
        SELECT name
        FROM
            sys_dic
        WHERE
            p_id = 124
    </select>


    <insert id="insertSysDic" parameterType="com.bonus.sgzb.base.api.domain.SysDic">
        insert into sys_dic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="pId != null">p_id,</if>
            <if test="code != null">code,</if>
            <if test="name != null">name,</if>
            <if test="description != null">description,</if>
            <if test="value != null">value,</if>
            <if test="sort != null">sort,</if>
            <if test="level != null">level,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creator != null">creator,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="pId != null">#{pId},</if>
            <if test="code != null">#{code},</if>
            <if test="name != null">#{name},</if>
            <if test="description != null">#{description},</if>
            <if test="value != null">#{value},</if>
            <if test="sort != null">#{sort},</if>
            <if test="level != null">#{level},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creator != null">#{creator},</if>
        </trim>
    </insert>
    <update id="updateSysDic" parameterType="com.bonus.sgzb.base.api.domain.SysDic">
        update sys_dic
        <trim prefix="SET" suffixOverrides=",">
            <if test="pId != null">p_id = #{pId},</if>
            <if test="code != null">code = #{code},</if>
            <if test="name != null">name = #{name},</if>
            <if test="description != null">description = #{description},</if>
            <if test="value != null">value = #{value},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="level != null">level = #{level},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creator != null">creator = #{creator},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updates" parameterType="com.bonus.sgzb.base.api.domain.SysDic">
        update sys_dic
        <trim prefix="SET" suffixOverrides=",">
            <if test="pId != null">p_id = #{pId},</if>
            <if test="code != null">code = #{code},</if>
            <if test="name != null">name = #{name},</if>
            <if test="description != null">description = #{description},</if>
            <if test="value != null">value = #{value},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="level != null">level = #{level},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creator != null">creator = #{creator},</if>
        </trim>
        where id = #{id}
    </update>
    <delete id="deleteSysDicById" parameterType="Long"> delete from sys_dic where id = #{id} </delete>
    <delete id="deleteSysDicByIds" parameterType="String">
        delete from sys_dic where id in
        <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach>
    </delete>
</mapper>