<?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.ehsFloodDroughtWorker.mapper.EhsFloodDroughtWorkerMapper">

    <resultMap type="EhsFloodDroughtWorker" id="EhsFloodDroughtWorkerResult">
        <result property="id" column="id"/>
        <result property="teamId" column="team_id"/>
        <result property="teamName" column="team_name"/>
        <result property="workerName" column="worker_name"/>
        <result property="gender" column="gender"/>
        <result property="idCard" column="id_card"/>
        <result property="phone" column="phone"/>
        <result property="workYear" column="work_year"/>
        <result property="speciality" column="speciality"/>
        <result property="workerAge"    column="worker_age"    />
        <result property="teamPost"    column="team_post"    />
        <result property="trainNum"    column="train_num"    />
        <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="selectEhsFloodDroughtWorkerVo">
        select id, team_id, team_name, worker_name, worker_age, team_post, train_num,  gender, 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_flood_drought_worker
    </sql>
    <select id="selectEhsFloodDroughtWorkerList" parameterType="EhsFloodDroughtWorker"
            resultMap="EhsFloodDroughtWorkerResult">
        <include refid="selectEhsFloodDroughtWorkerVo"/>
        <where>
            <if test="teamId != null ">and team_id = #{teamId}</if>
            <if test="teamName != null  and teamName != ''">and team_name like concat('%', #{teamName}, '%')</if>
            <if test="workerName != null  and workerName != ''">and worker_name like concat('%', #{workerName}, '%')</if>
            <if test="gender != null ">and gender = #{gender}</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>
            <if test="deptId != null ">and dept_id = #{deptId}</if>
            <if test="workerAge != null"> and worker_age = #{workerAge}</if>
            <if test="teamPost != null  and teamPost != ''"> and team_post = #{teamPost}</if>
            <if test="trainNum != null"> and train_num = #{trainNum}</if>
        </where>
    </select>

    <select id="selectEhsFloodDroughtWorkerById" parameterType="Long" resultMap="EhsFloodDroughtWorkerResult">
        <include refid="selectEhsFloodDroughtWorkerVo"/>
        where id = #{id}
    </select>

    <update id="updateWorkerByTeamId">
        update ehs_flood_drought_worker
        <set>
            <if test="teamName != null and teamName != ''">
                team_name = #{teamName},
            </if>
        </set>
        where team_id = #{teamId}
    </update>

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

</mapper>