<?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.ruoyi.powerdistribution.mapper.PdmDicMapper">
    
    <resultMap type="PdmDic" id="PdmDicResult">
        <result property="id"    column="id"    />
        <result property="dicId"    column="dic_id"    />
        <result property="sortNo"    column="sort_no"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="keyValue"    column="key_value"    />
        <result property="status"    column="status"    />
        <result property="parentId"    column="parent_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPdmDicVo">
        select id, dic_id, sort_no, code, name, key_value, status, parent_id, create_by, create_time, update_by, update_time from pdm_dic
    </sql>

    <select id="selectPdmDicList" parameterType="PdmDic" resultMap="PdmDicResult">
        <include refid="selectPdmDicVo"/>
        <where>  
            <if test="dicId != null  and dicId != ''"> and dic_id = #{dicId}</if>
            <if test="sortNo != null "> and sort_no = #{sortNo}</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="keyValue != null  and keyValue != ''"> and key_value = #{keyValue}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="parentId != null  and parentId != ''"> and parent_id = #{parentId}</if>
        </where>
        order by code
    </select>
    
    <select id="selectPdmDicById" parameterType="Long" resultMap="PdmDicResult">
        <include refid="selectPdmDicVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPdmDic" parameterType="PdmDic" useGeneratedKeys="true" keyProperty="id">
        insert into pdm_dic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dicId != null">dic_id,</if>
            <if test="sortNo != null">sort_no,</if>
            <if test="code != null">code,</if>
            <if test="name != null">name,</if>
            <if test="keyValue != null">key_value,</if>
            <if test="status != null">status,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dicId != null">#{dicId},</if>
            <if test="sortNo != null">#{sortNo},</if>
            <if test="code != null">#{code},</if>
            <if test="name != null">#{name},</if>
            <if test="keyValue != null">#{keyValue},</if>
            <if test="status != null">#{status},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePdmDic" parameterType="PdmDic">
        update pdm_dic
        <trim prefix="SET" suffixOverrides=",">
            <if test="dicId != null">dic_id = #{dicId},</if>
            <if test="sortNo != null">sort_no = #{sortNo},</if>
            <if test="code != null">code = #{code},</if>
            <if test="name != null">name = #{name},</if>
            <if test="keyValue != null">key_value = #{keyValue},</if>
            <if test="status != null">status = #{status},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePdmDicById" parameterType="Long">
        delete from pdm_dic where id = #{id}
    </delete>

    <delete id="deletePdmDicByIds" parameterType="String">
        delete from pdm_dic where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>