<?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.srs.stureg.mapper.AtStationMapper">

    <resultMap type="AtStation" id="AtStationResult">
        <result property="id"    column="id"    />
        <result property="studentId"    column="student_id"    />
        <result property="toolsType"    column="tools_type"    />
        <result property="atStation"    column="at_station"    />
        <result property="classId" column="class_id"/>
        <result property="className" column="class_name"/>
        <result property="atDatetime"    column="at_datetime"    />
        <result property="isNeedPick"    column="is_need_pick"    />
        <result property="pickState"    column="pick_state"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <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="userName"    column="user_name"    />
        <result property="name"    column="nick_name"    />
        <result property="phone"    column="phonenumber"    />
        <result property="ksh"    column="ksh"    />
        <result property="name"    column="name"    />

    </resultMap>

    <sql id="selectAtStationVo">
        select sas.id, sas.student_id, sas.tools_type, sas.at_station, sas.at_datetime, sas.is_need_pick,
               sas.pick_state, sas.status, sas.del_flag, sas.create_by, sas.create_time, sas.update_by, sas.update_time,
               sas.ksh,b.SJH as phone,b.XSXM as `name`,sc.class_id,sc.class_name
        from srs_at_station sas
        left join srs_stu_reg as b on sas.ksh = b.KSH
        left join srs_class sc on b.BJDM = sc.class_code
    </sql>



    <select id="selectAtStationList" parameterType="AtStation" resultMap="AtStationResult">
        <include refid="selectAtStationVo"/>
        <where>
            <if test="studentId != null "> and student_id = #{studentId}</if>
            <if test="toolsType != null "> and tools_type = #{toolsType}</if>
            <if test="className != null  and className != ''">and sc.class_name = #{className}</if>
            <if test="classId != null  and classId != ''">and sc.class_id = #{classId}</if>
            <if test="atStation != null  and atStation != ''"> and at_station = #{atStation}</if>
            <if test="atDatetime != null "> and at_datetime = #{atDatetime}</if>
            <if test="isNeedPick != null "> and is_need_pick = #{isNeedPick}</if>
            <if test="pickState != null "> and pick_state = #{pickState}</if>
            <if test="status != null  and status != ''"> and sas.status = #{status}</if>
            <if test="ksh != null  and ksh != ''"> and sas.ksh = #{ksh}</if>
        </where>
    </select>

    <select id="selectAtStationById" parameterType="Long" resultMap="AtStationResult">
        <include refid="selectAtStationVo"/>
        where sas.id = #{id}
    </select>

    <select id="selectAtStationByUserId" parameterType="Long" resultMap="AtStationResult">
        <include refid="selectAtStationVo"/>
        where student_id = #{userId}
    </select>

    <insert id="insertAtStation" parameterType="AtStation" useGeneratedKeys="true" keyProperty="id">
        insert into srs_at_station
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="studentId != null">student_id,</if>
            <if test="toolsType != null">tools_type,</if>
            <if test="atStation != null">at_station,</if>
            <if test="atDatetime != null">at_datetime,</if>
            <if test="isNeedPick != null">is_need_pick,</if>
            <if test="pickState != null">pick_state,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</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="ksh != null">ksh,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="studentId != null">#{studentId},</if>
            <if test="toolsType != null">#{toolsType},</if>
            <if test="atStation != null">#{atStation},</if>
            <if test="atDatetime != null">#{atDatetime},</if>
            <if test="isNeedPick != null">#{isNeedPick},</if>
            <if test="pickState != null">#{pickState},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</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="ksh != null">#{ksh},</if>
         </trim>
    </insert>

    <update id="updateAtStation" parameterType="AtStation">
        update srs_at_station
        <trim prefix="SET" suffixOverrides=",">
            <if test="studentId != null">student_id = #{studentId},</if>
            <if test="toolsType != null">tools_type = #{toolsType},</if>
            <if test="atStation != null">at_station = #{atStation},</if>
            <if test="atDatetime != null">at_datetime = #{atDatetime},</if>
            <if test="isNeedPick != null">is_need_pick = #{isNeedPick},</if>
            <if test="pickState != null">pick_state = #{pickState},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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="ksh != null">ksh = #{ksh},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAtStationById" parameterType="Long">
        delete from srs_at_station where id = #{id}
    </delete>

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