<?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.syzy.mapper.BBusiWishLocationSubmitsMapper">

  <resultMap type="BBusiWishLocationSubmits" id="BBusiWishLocationSubmitsResult">
    <result property="id" column="id" />
    <result property="location" column="location" />
    <result property="year" column="year" />
    <result property="type" column="type" />
    <result property="score" column="score" />
    <result property="createTime" column="createTime" />
    <result property="status" column="status" />
    <result property="typeName" column="typeName" />
    <result property="course" column="course" />
    <result property="courseName" column="courseName" />
    <result property="pressureScore" column="pressure_score" />
    <result property="pressureRange" column="pressure_range" />
  </resultMap>

  <sql id="selectBBusiWishLocationSubmitsVo">
    select id, location, year, type, typeName, score, course, courseName, pressure_score, pressure_range, createTime, status from b_busi_wish_location_submits
  </sql>

  <select id="selectBBusiWishLocationSubmitsList" parameterType="BBusiWishLocationSubmits" resultMap="BBusiWishLocationSubmitsResult">
    <include refid="selectBBusiWishLocationSubmitsVo" />
    <where>
      <if test="location != null  and location != ''"> and location = #{location}</if>
      <if test="year != null  and year != ''"> and year = #{year}</if>
      <if test="score != null "> and score = #{score}</if>
      <if test="type != null "> and type = #{type}</if>
      <if test="typeName != null and typeName != '' "> and typeName = #{typeName}</if>
      <if test="course != null and course != '' "> and course = #{course}</if>
      <if test="pressureScore != null and pressureScore != '' "> and pressure_score = #{pressureScore}</if>
      <if test="pressureRange != null and pressureRange != '' "> and pressure_range = #{pressureRange}</if>
      <if test="createTime != null "> and createTime = #{createTime}</if>
      <if test="status != null "> and status = #{status}</if>
    </where>
    order by year desc,type asc
  </select>

  <select id="selectBBusiWishLocationSubmitsById" parameterType="Long" resultMap="BBusiWishLocationSubmitsResult">
    <include refid="selectBBusiWishLocationSubmitsVo" />
    where id = #{id}
  </select>

  <select id="locations" resultType="String">
     select distinct location from b_busi_wish_location_submits where status &gt; 0
  </select>

  <select id="years" parameterType="String" resultType="String">
    select distinct year from b_busi_wish_location_submits where status &gt; 0
    <if test="location!=null and location!=''">
        and location = #{location}
    </if>
    order by year desc
  </select>

  <select id="yearsNoStatus" parameterType="String" resultType="String">
    select distinct year from b_busi_wish_location_submits where 1=1
    <if test="location!=null and location!=''">
      and location = #{location}
    </if>
    order by year desc
  </select>

  <insert id="insertBBusiWishLocationSubmits" parameterType="BBusiWishLocationSubmits" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_wish_location_submits
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="location != null">location,</if>
      <if test="year != null">year,</if>
      <if test="type != null">type,</if>
      <if test="score != null">score,</if>
      <if test="createTime != null">createTime,</if>
      <if test="status != null">status,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="location != null">#{location},</if>
      <if test="year != null">#{year},</if>
      <if test="type != null">#{type},</if>
      <if test="score != null">#{score},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="status != null">#{status},</if>
    </trim>
  </insert>

  <update id="updateBBusiWishLocationSubmits" parameterType="BBusiWishLocationSubmits">
    update b_busi_wish_location_submits
    <trim prefix="SET" suffixOverrides=",">
      <if test="location != null">location = #{location},</if>
      <if test="year != null">year = #{year},</if>
      <if test="type != null">type = #{type},</if>
      <if test="score != null">score = #{score},</if>
      <if test="createTime != null">createTime = #{createTime},</if>
      <if test="status != null">status = #{status},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBBusiWishLocationSubmitsById" parameterType="Long">
    delete from b_busi_wish_location_submits where id = #{id}
  </delete>

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

  <select id="batches" resultMap="BBusiWishLocationSubmitsResult">
    select year,type,score,typeName,course
    from b_busi_wish_location_submits
    where status>0 and location= #{location}
    and year=(select max(year) from b_busi_wish_location_submits where status>0 and location= #{location}) and course = #{mode}
    order by type
  </select>

  <select id="batchesNoStatus" parameterType="String" resultMap="BBusiWishLocationSubmitsResult">
    select year,type,score,typeName,course
    from b_busi_wish_location_submits
    where 1=1 and location= #{location}
      and year=(select max(year) from b_busi_wish_location_submits where 1=1 and location= #{location}) and course = #{mode}
    order by type
  </select>

  <select id="examMajors" parameterType="String" resultMap="BBusiWishLocationSubmitsResult">
    select distinct course, courseName
    from b_busi_wish_location_submits
    where 1=1
    <if test="location != null  and location != ''"> and location = #{location}</if>
    and year=(select max(year) from b_busi_wish_location_submits where 1=1
    <if test="location != null  and location != ''"> and location = #{location}</if>
    )
    order by course
  </select>


</mapper>
