<?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.zlpt.company.mapper.BmCompanyTypeMapper">


    <select id="selectCompanyTypeList" resultType="com.bonus.zlpt.company.api.domain.SysDic">
    select
        id,p_id,code,`name`,description,`value`,sort,`level`,status,create_time,creator 
    from sys_dic
    <where>
        <if test="id != null"> and id = #{id}</if>
        <if test="pId != null"> and p_id = #{pId}</if>
        <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 LIKE CONCAT('%', #{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>
    </where>
    </select>

    <insert id="addCompanyType">
            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="updateCompanyType">
        update sys_dic
        <set>
            <if test="pId != null">  p_id = #{pId},</if>
            <if test="code != null and code != ''">  code = #{code},</if>
            <if test="name != null and name != ''">  `name`=#{name} , </if>
            <if test="description != null and description != ''">  description = #{description}, </if>
            <if test="value != null and value != ''">  `value` = #{value},</if>
            <if test="sort != null and sort != ''">  sort = #{sort},</if>
            <if test="level != null and level != ''">  `level` = #{level},</if>
            <if test="status != null and status != ''">  status = #{status},</if>
        </set>
        where id = #{id}
    </update>


    <select id="getById" resultType="com.bonus.zlpt.company.api.domain.SysDic">
        select
            id,p_id,code,`name`,description,`value`,sort,`level`,status,create_time,creator
        from sys_dic
        <where>
            <if test="id != null"> and id=#{id}</if>
        </where>
    </select>


    <delete id="deleteById">
        delete from sys_dic where id = #{id}
    </delete>


</mapper>