<?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.StationNoticeMapper">
    
    <resultMap type="StationNotice" id="StationNoticeResult">
        <result property="noticeId"    column="notice_id"    />
        <result property="fullName"    column="full_name"    />
        <result property="phone"    column="phone"    />
        <result property="bindDate"    column="bind_date"    />
        <result property="bindStatus"    column="bind_status"    />
        <result property="wxFullName"    column="wx_full_name"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
    </resultMap>

    <sql id="selectStationNoticeVo">
        select notice_id, full_name, phone, bind_date, bind_status, wx_full_name, station_id, station_name from station_notice
    </sql>

    <select id="selectStationNoticeList" parameterType="StationNotice" resultMap="StationNoticeResult">
        <include refid="selectStationNoticeVo"/>
        <where>  
            <if test="fullName != null  and fullName != ''"> and full_name like concat('%', #{fullName}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="bindDate != null "> and bind_date = #{bindDate}</if>
            <if test="bindStatus != null  and bindStatus != ''"> and bind_status = #{bindStatus}</if>
            <if test="wxFullName != null  and wxFullName != ''"> and wx_full_name like concat('%', #{wxFullName}, '%')</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
        </where>
    </select>
    
    <select id="selectStationNoticeById" parameterType="Long" resultMap="StationNoticeResult">
        <include refid="selectStationNoticeVo"/>
        where notice_id = #{noticeId}
    </select>
        
    <insert id="insertStationNotice" parameterType="StationNotice" useGeneratedKeys="true" keyProperty="noticeId">
        insert into station_notice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fullName != null">full_name,</if>
            <if test="phone != null">phone,</if>
            <if test="bindDate != null">bind_date,</if>
            <if test="bindStatus != null">bind_status,</if>
            <if test="wxFullName != null">wx_full_name,</if>
            <if test="stationId != null">station_id,</if>
            <if test="stationName != null">station_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fullName != null">#{fullName},</if>
            <if test="phone != null">#{phone},</if>
            <if test="bindDate != null">#{bindDate},</if>
            <if test="bindStatus != null">#{bindStatus},</if>
            <if test="wxFullName != null">#{wxFullName},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="stationName != null">#{stationName},</if>
         </trim>
    </insert>

    <update id="updateStationNotice" parameterType="StationNotice">
        update station_notice
        <trim prefix="SET" suffixOverrides=",">
            <if test="fullName != null">full_name = #{fullName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="bindDate != null">bind_date = #{bindDate},</if>
            <if test="bindStatus != null">bind_status = #{bindStatus},</if>
            <if test="wxFullName != null">wx_full_name = #{wxFullName},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="stationName != null">station_name = #{stationName},</if>
        </trim>
        where notice_id = #{noticeId}
    </update>

    <delete id="deleteStationNoticeById" parameterType="Long">
        delete from station_notice where notice_id = #{noticeId}
    </delete>

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