<?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.ehsRescueTeamWorker.mapper.EhsRescueTeamWorkerMapper">

    <resultMap type="EhsRescueTeamWorker" id="EhsRescueTeamWorkerResult">
            <result property="id"    column="id"    />
            <result property="rescueTeamId"    column="rescue_team_id"    />
            <result property="rescueTeamName"    column="rescue_team_name"    />
            <result property="workerName"    column="worker_name"    />
            <result property="gender"    column="gender"    />
            <result property="birthday"    column="birthday"    />
            <result property="idCard"    column="id_card"    />
            <result property="phone"    column="phone"    />
            <result property="workYear"    column="work_year"    />
            <result property="speciality"    column="speciality"    />
            <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="deptId"    column="dept_id"    />
            <result property="createUserId"    column="create_user_id"    />
            <result property="updateUserId"    column="update_user_id"    />
    </resultMap>

    <sql id="selectEhsRescueTeamWorkerVo">
        select id, rescue_team_id, rescue_team_name, worker_name, gender, birthday, id_card, phone, work_year, speciality, create_by, create_time, update_by, update_time, remark, dept_id, create_user_id, update_user_id from ehs_rescue_team_worker
    </sql>
    <update id="updateWorkerByTeamId">
        update ehs_rescue_team_worker
        <set>
            <if test="rescueTeamName != null and rescueTeamName != ''">
                rescue_team_name = #{rescueTeamName},
            </if>
        </set>
        where rescue_team_id = #{rescueTeamId}
    </update>

    <select id="selectEhsRescueTeamWorkerList" parameterType="EhsRescueTeamWorker" resultMap="EhsRescueTeamWorkerResult">
        <include refid="selectEhsRescueTeamWorkerVo"/>
        <where>
                        <if test="rescueTeamId != null "> and rescue_team_id = #{rescueTeamId}</if>
                        <if test="rescueTeamName != null  and rescueTeamName != ''"> and rescue_team_name like concat('%', #{rescueTeamName}, '%')</if>
                        <if test="workerName != null  and workerName != ''"> and worker_name like concat('%', #{workerName}, '%')</if>
                        <if test="gender != null "> and gender = #{gender}</if>
                        <if test="birthday != null "> and birthday = #{birthday}</if>
                        <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
                        <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
                        <if test="workYear != null  and workYear != ''"> and work_year = #{workYear}</if>
                        <if test="speciality != null  and speciality != ''"> and speciality = #{speciality}</if>
        </where>
    </select>

    <select id="selectEhsRescueTeamWorkerById" parameterType="Long" resultMap="EhsRescueTeamWorkerResult">
            <include refid="selectEhsRescueTeamWorkerVo"/>
            where id = #{id}
    </select>

    <delete id="removeWorkerByTeamIds">
        delete from ehs_rescue_team_worker
        where rescue_team_id in
        <foreach collection="list" separator="," open="(" close=")" item="items">
            #{items}
        </foreach>
    </delete>



</mapper>