<?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.yijia.station.mapper.StationPersonnelMapper">
    
    <resultMap type="StationPersonnel" id="StationPersonnelResult">
        <result property="personnelId"    column="personnel_id"    />
        <result property="personnelName"    column="personnel_name"    />
        <result property="gunNo"    column="gun_no"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="qrCode"    column="qr_code"    />
        <result property="personnelPhone"    column="personnel_phone"    />
    </resultMap>

    <sql id="selectStationPersonnelVo">
        select personnel_id, personnel_name, gun_no, station_id, station_name, qr_code, personnel_phone from station_personnel
    </sql>

    <select id="selectStationPersonnelList" parameterType="StationPersonnel" resultMap="StationPersonnelResult">
        <include refid="selectStationPersonnelVo"/>
        <where>  
            <if test="personnelName != null  and personnelName != ''"> and personnel_name like concat('%', #{personnelName}, '%')</if>
            <if test="gunNo != null  and gunNo != ''"> and gun_no = #{gunNo}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
            <if test="qrCode != null  and qrCode != ''"> and qr_code = #{qrCode}</if>
            <if test="personnelPhone != null  and personnelPhone != ''"> and personnel_phone = #{personnelPhone}</if>
        </where>
    </select>
    
    <select id="selectStationPersonnelById" parameterType="Long" resultMap="StationPersonnelResult">
        <include refid="selectStationPersonnelVo"/>
        where personnel_id = #{personnelId}
    </select>
        
    <insert id="insertStationPersonnel" parameterType="StationPersonnel">
        insert into station_personnel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="personnelId != null">personnel_id,</if>
            <if test="personnelName != null">personnel_name,</if>
            <if test="gunNo != null">gun_no,</if>
            <if test="stationId != null">station_id,</if>
            <if test="stationName != null">station_name,</if>
            <if test="qrCode != null">qr_code,</if>
            <if test="personnelPhone != null">personnel_phone,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="personnelId != null">#{personnelId},</if>
            <if test="personnelName != null">#{personnelName},</if>
            <if test="gunNo != null">#{gunNo},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="stationName != null">#{stationName},</if>
            <if test="qrCode != null">#{qrCode},</if>
            <if test="personnelPhone != null">#{personnelPhone},</if>
         </trim>
    </insert>

    <update id="updateStationPersonnel" parameterType="StationPersonnel">
        update station_personnel
        <trim prefix="SET" suffixOverrides=",">
            <if test="personnelName != null">personnel_name = #{personnelName},</if>
            <if test="gunNo != null">gun_no = #{gunNo},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="stationName != null">station_name = #{stationName},</if>
            <if test="qrCode != null">qr_code = #{qrCode},</if>
            <if test="personnelPhone != null">personnel_phone = #{personnelPhone},</if>
        </trim>
        where personnel_id = #{personnelId}
    </update>

    <delete id="deleteStationPersonnelById" parameterType="Long">
        delete from station_personnel where personnel_id = #{personnelId}
    </delete>

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