<?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.PdmParMapper">
    
    <resultMap type="PdmPar" id="PdmParResult">
        <result property="id"    column="id"    />
        <result property="parCode"    column="par_code"    />
        <result property="parName"    column="par_name"    />
        <result property="parValue"    column="par_value"    />
        <result property="parUnit"    column="par_unit"    />
        <result property="parUnitCn"    column="par_unit_cn"    />
        <result property="parType"    column="par_Type"    />
        <result property="parField"    column="par_field"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <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="selectPdmParVo">
        select id, par_code, par_name, par_value, par_unit,par_Type,par_field,p.status, p.remark, p.create_by, p.create_time, p.update_by, p.update_time from pdm_par p
    </sql>
    <sql id="selectPdmParVo2">
        select id, par_code, par_name, par_value, par_unit, dict_label par_unit_cn,par_Type,par_field,p.status, p.remark, p.create_by, p.create_time, p.update_by, p.update_time from pdm_par p
    </sql>
    <select id="selectPdmParList" parameterType="PdmPar" resultMap="PdmParResult">
        <include refid="selectPdmParVo2"/>  LEFT JOIN sys_dict_data on dict_value=par_unit and dict_type in('pdm_maintenance_time','repeat_power_failure')
        <where>  
            <if test="parCode != null  and parCode != ''"> and par_code = #{parCode}</if>
            <if test="parName != null  and parName != ''"> and par_name like concat('%', #{parName}, '%')</if>
            <if test="parValue != null  and parValue != ''"> and par_value = #{parValue}</if>
            <if test="parUnit != null  and parUnit != ''"> and par_unit = #{parUnit}</if>
            <if test="parType != null  and parType != ''"> and par_type = #{parType}</if>
        </where>
    </select>
    
    <select id="selectPdmParById" parameterType="Long" resultMap="PdmParResult">
        <include refid="selectPdmParVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPdmPar" parameterType="PdmPar" useGeneratedKeys="true" keyProperty="id">
        insert into pdm_par
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parCode != null">par_code,</if>
            <if test="parName != null">par_name,</if>
            <if test="parValue != null">par_value,</if>
            <if test="parUnit != null">par_unit,</if>
            <if test="parType != null">par_type,</if>
            <if test="parField != null">par_field,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</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="parCode != null">#{parCode},</if>
            <if test="parName != null">#{parName},</if>
            <if test="parValue != null">#{parValue},</if>
            <if test="parUnit != null">#{parUnit},</if>
            <if test="parType != null">#{parType},</if>
            <if test="parField != null">#{parField},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</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="updatePdmPar" parameterType="PdmPar">
        update pdm_par
        <trim prefix="SET" suffixOverrides=",">
            <if test="parCode != null">par_code = #{parCode},</if>
            <if test="parName != null">par_name = #{parName},</if>
            <if test="parValue != null">par_value = #{parValue},</if>
            <if test="parUnit != null">par_unit = #{parUnit},</if>
            <if test="parType != null">par_type = #{parType},</if>
            <if test="parField != null">par_field=#{parField},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</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="deletePdmParById" parameterType="Long">
        delete from pdm_par where id = #{id}
    </delete>

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