<?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.PdmConstructorMapper">
    
    <resultMap type="PdmConstructor" id="PdmConstructorResult">
        <result property="id"    column="id"    />
        <result property="teamNo"    column="team_no"    />
        <result property="constructPersonType"    column="construct_person_type"    />
        <result property="constructPersonnelName"    column="construct_personnel_name"    />
        <result property="constructPersonnelPhone"    column="construct_personnel_phone"    />
        <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"    />
    </resultMap>

    <sql id="selectPdmConstructorVo">
        select id, team_no, construct_person_type, construct_personnel_name, construct_personnel_phone, create_by, create_time, update_by, update_time, remark from pdm_constructor
    </sql>

    <select id="selectPdmConstructorList" parameterType="PdmConstructor" resultMap="PdmConstructorResult">
        <include refid="selectPdmConstructorVo"/>
        <where>  
            <if test="teamNo != null  and teamNo != ''"> and team_no = #{teamNo}</if>
            <if test="constructPersonType != null  and constructPersonType != ''"> and construct_person_type = #{constructPersonType}</if>
            <if test="constructPersonnelName != null  and constructPersonnelName != ''"> and construct_personnel_name like concat('%', #{constructPersonnelName}, '%')</if>
            <if test="constructPersonnelPhone != null  and constructPersonnelPhone != ''"> and construct_personnel_phone = #{constructPersonnelPhone}</if>
        </where>
    </select>
    
    <select id="selectPdmConstructorById" parameterType="Long" resultMap="PdmConstructorResult">
        <include refid="selectPdmConstructorVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPdmConstructor" parameterType="PdmConstructor">
        insert into pdm_constructor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="teamNo != null and teamNo != ''">team_no,</if>
            <if test="constructPersonType != null">construct_person_type,</if>
            <if test="constructPersonnelName != null">construct_personnel_name,</if>
            <if test="constructPersonnelPhone != null">construct_personnel_phone,</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="id != null">#{id},</if>
            <if test="teamNo != null and teamNo != ''">#{teamNo},</if>
            <if test="constructPersonType != null">#{constructPersonType},</if>
            <if test="constructPersonnelName != null">#{constructPersonnelName},</if>
            <if test="constructPersonnelPhone != null">#{constructPersonnelPhone},</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="updatePdmConstructor" parameterType="PdmConstructor">
        update pdm_constructor
        <trim prefix="SET" suffixOverrides=",">
            <if test="teamNo != null and teamNo != ''">team_no = #{teamNo},</if>
            <if test="constructPersonType != null">construct_person_type = #{constructPersonType},</if>
            <if test="constructPersonnelName != null">construct_personnel_name = #{constructPersonnelName},</if>
            <if test="constructPersonnelPhone != null">construct_personnel_phone = #{constructPersonnelPhone},</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="deletePdmConstructorById" parameterType="Long">
        delete from pdm_constructor where id = #{id}
    </delete>

    <delete id="deletePdmConstructorByIds" parameterType="String">
        delete from pdm_constructor where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deletePdmConstructorByTeamId" parameterType="Long">
        delete from pdm_constructor where team_no =(select team_no from pdm_construct_team t where t.id=#{teamId} )
    </delete>

    <delete id="deletePdmConstructorByTeamIds" parameterType="String">
        delete from pdm_constructor where team_no in( select team_no from pdm_construct_team t  where t.id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
        )
    </delete>
    <select id="selectPdmConstructorByTeamNo" resultMap="PdmConstructorResult">
        select * from pdm_constructor where team_no=#{teamNo}
    </select>
</mapper>