<?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.PdmConstructTeamMapper">
    
    <resultMap type="PdmConstructTeam" id="PdmConstructTeamResult">
        <result property="id"    column="id"    />
        <result property="teamNo"    column="team_no"    />
        <result property="countyOrgNm"    column="county_org_nm"    />
        <result property="teamNm"    column="team_nm"    />
        <result property="legalPerson"    column="legal_person"    />
        <result property="legalContactPhone"    column="legal_contact_phone"    />
        <result property="teamSerialNo"    column="team_serial_no"    />
        <result property="teamLeader"    column="team_leader"    />
        <result property="teamLeaderPhone"    column="team_leader_phone"    />
        <result property="construcCarNumber"    column="construc_car_number"    typeHandler="com.ruoyi.common.handler.ConvertCommaSeparatedStrToListTypeHandler" javaType="java.util.List" />
        <result property="arrestPoint"    column="arrest_point"    />
        <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>
    <resultMap type="com.ruoyi.powerdistribution.domain.vo.PdmConstructTeamVo" id="PdmConstructTeamResult2">
        <result property="id"    column="id"    />
        <result property="countyOrgNm"    column="county_org_nm"    />
        <result property="teamNo"    column="team_no"    />
        <result property="teamNm"    column="team_nm"    />
        <result property="legalPerson"    column="legal_person"    />
        <result property="legalContactPhone"    column="legal_contact_phone"    />
        <result property="teamSerialNo"    column="team_serial_no"    />
        <result property="teamLeader"    column="team_leader"    />
        <result property="teamLeaderPhone"    column="team_leader_phone"    />
        <result property="construcCarNumber"    column="construc_car_number"  typeHandler="com.ruoyi.common.handler.ConvertCommaSeparatedStrToListTypeHandler" javaType="java.util.List"/>
        <result property="arrestPoint"    column="arrest_point"    />
        <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"    />
        <collection property="constructorList" column="{teamNo=team_no}" select="com.ruoyi.powerdistribution.mapper.PdmConstructorMapper.selectPdmConstructorByTeamNo"></collection>
    </resultMap>

    <sql id="selectPdmConstructTeamVo">
        select id, county_org_nm,team_no, team_nm, legal_person, legal_contact_phone, team_serial_no, team_leader, team_leader_phone, construc_car_number, arrest_point, create_by, create_time, update_by, update_time, remark from pdm_construct_team
    </sql>

    <select id="selectPdmConstructTeamList" parameterType="PdmConstructTeam" resultMap="PdmConstructTeamResult2">
        <include refid="selectPdmConstructTeamVo"/>
        <where>
            <if test="countyOrgNm != null  and countyOrgNm != ''"> and county_org_nm = #{countyOrgNm}</if>
            <if test="teamNo != null  and teamNo != ''"> and team_no = #{teamNo}</if>
            <if test="teamNm != null  and teamNm != ''"> and team_nm = #{teamNm}</if>
            <if test="legalPerson != null  and legalPerson != ''"> and legal_person = #{legalPerson}</if>
            <if test="legalContactPhone != null  and legalContactPhone != ''"> and legal_contact_phone = #{legalContactPhone}</if>
            <if test="teamSerialNo != null "> and team_serial_no = #{teamSerialNo}</if>
            <if test="teamLeader != null  and teamLeader != ''"> and team_leader = #{teamLeader}</if>
            <if test="teamLeaderPhone != null  and teamLeaderPhone != ''"> and team_leader_phone = #{teamLeaderPhone}</if>
            <if test="construcCarNumber != null  and construcCarNumber != ''"> and construc_car_number = #{construcCarNumber}</if>
            <if test="arrestPoint != null  and arrestPoint != ''"> and arrest_point = #{arrestPoint}</if>
        </where>
    </select>
    
    <select id="selectPdmConstructTeamById" parameterType="Long" resultMap="PdmConstructTeamResult">
        <include refid="selectPdmConstructTeamVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPdmConstructTeam" parameterType="PdmConstructTeam">
        insert into pdm_construct_team
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="countyOrgNm != null">county_org_nm,</if>
            <if test="teamNo != null and teamNo != ''">team_no,</if>
            <if test="teamNm != null">team_nm,</if>
            <if test="legalPerson != null">legal_person,</if>
            <if test="legalContactPhone != null">legal_contact_phone,</if>
            <if test="teamSerialNo != null">team_serial_no,</if>
            <if test="teamLeader != null">team_leader,</if>
            <if test="teamLeaderPhone != null">team_leader_phone,</if>
            <if test="construcCarNumber != null">construc_car_number,</if>
            <if test="arrestPoint != null">arrest_point,</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="countyOrgNm != null and countyOrgNm!=''">#{countyOrgNm},</if>
            <if test="teamNo != null and teamNo != ''">#{teamNo},</if>
            <if test="teamNm != null">#{teamNm},</if>
            <if test="legalPerson != null">#{legalPerson},</if>
            <if test="legalContactPhone != null">#{legalContactPhone},</if>
            <if test="teamSerialNo != null">#{teamSerialNo},</if>
            <if test="teamLeader != null">#{teamLeader},</if>
            <if test="teamLeaderPhone != null">#{teamLeaderPhone},</if>
            <if test="construcCarNumber != null">#{construcCarNumber},</if>
            <if test="arrestPoint != null">#{arrestPoint},</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="updatePdmConstructTeam" parameterType="PdmConstructTeam">
        update pdm_construct_team
        <trim prefix="SET" suffixOverrides=",">
            <if test="countyOrgNm != null and countyOrgNm!=''">county_org_nm=#{countyOrgNm},</if>
            <if test="teamNo != null and teamNo != ''">team_no = #{teamNo},</if>
            <if test="teamNm != null">team_nm = #{teamNm},</if>
            <if test="legalPerson != null">legal_person = #{legalPerson},</if>
            <if test="legalContactPhone != null">legal_contact_phone = #{legalContactPhone},</if>
            <if test="teamSerialNo != null">team_serial_no = #{teamSerialNo},</if>
            <if test="teamLeader != null">team_leader = #{teamLeader},</if>
            <if test="teamLeaderPhone != null">team_leader_phone = #{teamLeaderPhone},</if>
            <if test="construcCarNumber != null">construc_car_number = #{construcCarNumber},</if>
            <if test="arrestPoint != null">arrest_point = #{arrestPoint},</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="deletePdmConstructTeamById" parameterType="Long">
        delete from pdm_construct_team where id = #{id}
    </delete>

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