<?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.xunwang.education.mapper.StudentRequirementsMapper">

    <update id="batchupdate" parameterType="list">
        update stu_needs set
        viewed_count =
        <foreach collection="list" item="stu" index="index"
                 separator=" " open="case require_id" close="end">
            when #{stu.id} then
            #{stu.count}
        </foreach>
        where require_id in
        <foreach collection="list" item="stu" index="index"
                 separator="," open="(" close=")">
            #{stu.id}
        </foreach>
    </update>

    <select id="selectBatch" resultType="com.xunwang.education.entity.dto.MyStuNeedsDto">
        select require_id, name, subject_big, subject_small, salary, location_al, sex, goal
        from stu_needs
        where require_id in
            <foreach collection="list" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
    </select>

    <select id="getPersonCourse" resultType="com.xunwang.education.entity.dto.MyPublishStuNeedsDto">
        select require_id, subject_big, subject_small, salary, verify_status, display, locked, deal
        from stu_needs
        where uid = #{uid} and deleted = '0'
        order by datetime desc
    </select>

    <select id="selectAllStuNeed" resultType="com.xunwang.education.entity.dto.MyStuNeedsDto">
        select require_id, name, subject_big, subject_small, salary, location_al, sex, goal, profile_photo
        from stu_needs
        <where>
            <if test="item.sex != null and item.sex != '' ">
                and sex = #{item.sex}
            </if>
            <if test="item.time != null and item.time != '' ">
                and course_timetype like concat("%", #{item.time}, "%")
            </if>
            <if test="item.subject != null and item.subject != '1-1' ">
                and subject_small = #{item.subject}
            </if>
            <if test="item.subjectBig != null and item.subjectBig != '' ">
                and subject_big = #{item.subjectBig}
            </if>
            <if test="item.moneyLeft != null and item.moneyLeft != '' ">
                and #{item.moneyLeft} <![CDATA[ <= ]]> salary and salary <![CDATA[ <= ]]> #{item.moneyRight}
            </if>
            and display = '上架' and locked = '未锁'
        </where>
        limit #{item.pageNum}, #{item.pageSize}
    </select>

</mapper>
