<?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.PdmWorkOrganMapper">
    
    <resultMap type="PdmWorkOrgan" id="PdmWorkOrganResult">
        <result property="id"    column="id"    />
        <result property="organName"    column="organ_name"    />
        <result property="organAbbr"    column="organ_abbr"    />
        <result property="status"    column="status"    />
        <result property="contactAddr"    column="contact_addr"    />
        <result property="contactTel"    column="contact_tel"    />
        <result property="liaisonMan"    column="liaison_man"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="organNo"    column="organ_no"    />
    </resultMap>

    <sql id="selectPdmWorkOrganVo">
        select id, organ_name, organ_abbr,organ_no, status, contact_addr, contact_tel, liaison_man, create_by, create_time, update_by, update_time, remark from pdm_work_organ
    </sql>

    <select id="selectPdmWorkOrganList" parameterType="PdmWorkOrgan" resultMap="PdmWorkOrganResult">
        <include refid="selectPdmWorkOrganVo"/>
        <where>  
            <if test="organName != null  and organName != ''"> and organ_name like concat('%', #{organName}, '%')</if>
            <if test="organNo != null  and organNo != ''"> and organ_no like concat('%', #{organNo}, '%')</if>
            <if test="organAbbr != null  and organAbbr != ''"> and organ_abbr = #{organAbbr}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="contactAddr != null  and contactAddr != ''"> and contact_addr = #{contactAddr}</if>
            <if test="contactTel != null  and contactTel != ''"> and contact_tel = #{contactTel}</if>
            <if test="liaisonMan != null  and liaisonMan != ''"> and liaison_man = #{liaisonMan}</if>
        </where>
        order by organ_abbr
    </select>
    
    <select id="selectPdmWorkOrganById" parameterType="Long" resultMap="PdmWorkOrganResult">
        <include refid="selectPdmWorkOrganVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPdmWorkOrgan" parameterType="PdmWorkOrgan" useGeneratedKeys="true" keyProperty="id">
        insert into pdm_work_organ
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="organName != null">organ_name,</if>
            <if test="organAbbr != null">organ_abbr,</if>
            <if test="organNo != null">organ_no,</if>
            <if test="status != null">status,</if>
            <if test="contactAddr != null">contact_addr,</if>
            <if test="contactTel != null">contact_tel,</if>
            <if test="liaisonMan != null">liaison_man,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="organName != null">#{organName},</if>
            <if test="organAbbr != null">#{organAbbr},</if>
            <if test="organNo != null">#{organNo},</if>
            <if test="status != null">#{status},</if>
            <if test="contactAddr != null">#{contactAddr},</if>
            <if test="contactTel != null">#{contactTel},</if>
            <if test="liaisonMan != null">#{liaisonMan},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updatePdmWorkOrgan" parameterType="PdmWorkOrgan">
        update pdm_work_organ
        <trim prefix="SET" suffixOverrides=",">
            <if test="organName != null">organ_name = #{organName},</if>
            <if test="organAbbr != null">organ_abbr = #{organAbbr},</if>
            <if test="organNo != null">organ_no=#{organNo},</if>
            <if test="status != null">status = #{status},</if>
            <if test="contactAddr != null">contact_addr = #{contactAddr},</if>
            <if test="contactTel != null">contact_tel = #{contactTel},</if>
            <if test="liaisonMan != null">liaison_man = #{liaisonMan},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePdmWorkOrganById" parameterType="Long">
        delete from pdm_work_organ where id = #{id}
    </delete>

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