<?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.BBusiWishUniversitySubmitsMapper">

  <resultMap type="BBusiWishUniversitySubmits" id="BBusiWishUniversitySubmitsResult">
    <result property="id" column="id" />
    <result property="universityId" column="universityId" />
    <result property="universityName" column="universityName" />
    <result property="universityNameText" column="universityNameText" />
    <result property="year" column="year" />
    <result property="location" column="location" />
    <result property="batch" column="batch" />
    <result property="type" column="type" />
    <result property="level" column="level" />
    <result property="score" column="score" />
    <result property="seat" column="seat" />
    <result property="num" column="num" />
    <result property="numReal" column="numReal" />
    <result property="createTime" column="createTime" />
    <result property="status" column="status" />

    <result property="universityName" column="universityName" />
    <result property="universityCode" column="universityCode" />
    <result property="collegeCode" column="collegeCode" />
    <result property="batchName" column="batchName" />
    <result property="liberalScience" column="liberalScience" />
    <result property="course" column="course" />
    <result property="collegeRemark" column="collegeRemark" />
  </resultMap>

  <sql id="selectBBusiWishUniversitySubmitsVo">
    select id, universityId, year, location, batch, type, level, score, seat, num, numReal, createTime, status,
        universityName,universityCode,collegeCode,batchName,liberalScience,course,collegeRemark
    from b_busi_wish_university_submits
  </sql>

  <select id="query" parameterType="String" resultType="com.alibaba.fastjson.JSONObject">
    ${sql}
  </select>

  <select id="levels" resultType="String">
    select distinct level from b_busi_wish_university_submits where 1=1
    <if test="location!=null and location!=''">
      and location = #{location}
    </if>
    <if test="year!=null">
      and year = #{year}
    </if>
  </select>

  <select id="types" resultType="String">
    select distinct type from b_busi_wish_university_submits where 1=1
    <if test="location!=null and location!=''">
      and location = #{location}
    </if>
    <if test="year!=null">
      and year = #{year}
    </if>
  </select>

 <select id="years" resultType="String">
    select distinct year from b_busi_wish_university_submits where 1=1
    <if test="location!=null and location!=''">
      and location = #{location}
    </if>
    <if test="type!=null and type!=''">
      and type = #{type}
    </if>
    <if test="level!=null and level!=''">
      and level = #{level}
    </if>
    order by year desc
  </select>

  <select id="yearsStatus" resultType="String">
    select distinct year from b_busi_wish_university_submits where status &gt; 0
    <if test="location!=null and location!=''">
      and location = #{location}
    </if>
    <if test="type!=null and type!=''">
      and type = #{type}
    </if>
    <choose><when test="level!=null and level=='本科批'">and SUBSTRING(level, 1, 2) = SUBSTRING(#{level}, 1, 2)</when><when test="level!=null">and level = #{level}</when></choose>
    order by year desc
  </select>

  <select id="search" parameterType="Map" resultMap="BBusiWishUniversitySubmitsResult">
    select a.id, a.universityId, a.year, b.location as location, a.batch, a.type, a.level as level,
    a.score, a.seat, a.num, a.numReal, a.createTime, a.status,
    a.universityCode,a.collegeCode,a.batchName,a.liberalScience,a.course,a.collegeRemark,
    a.universityName as universityName, a.universityNameText as universityNameText
    from b_busi_wish_university_submits a
    LEFT JOIN b_busi_wish_universities b ON a.universityId = b.id
    where a.status &gt;= 0 and b.status &gt; 0
    <if test="univerName != null and univerName != ''"> and (a.universityName like concat('%', #{univerName}, '%') or a.universityNameText like concat('%', #{univerName}, '%'))</if>
    <if test="universityId != null"> and b.id = #{universityId}</if>
    <if test="code != null and code != ''"> and b.code = #{code}</if>
    <if test="location != null and location != ''"> and b.location = #{location}</if>
    <if test="level != null and level != ''"> and a.level like concat('%', #{level}, '%')</if>
    <if test="type != null and type != ''"> and a.type = #{type} </if>
    <if test="year != null and year != ''"> and a.year = #{year} </if>
    <if test="spro != null and spro != ''"> and a.location = #{spro} </if>
    order by b.code asc,a.score desc
  </select>


  <select id="selectBBusiWishUniversitySubmitsList" parameterType="BBusiWishUniversitySubmits" resultMap="BBusiWishUniversitySubmitsResult">
    <include refid="selectBBusiWishUniversitySubmitsVo" />
    <where>
      <if test="universityId != null  and universityId != ''"> and universityId = #{universityId}</if>
      <if test="year != null  and year != ''"> and year = #{year}</if>
      <if test="location != null  and location != ''"> and location = #{location}</if>
      <if test="batch != null "> and batch = #{batch}</if>
      <if test="type != null  and type != ''"> and type = #{type}</if>
      <if test="level != null  and level != ''"> and level = #{level}</if>
      <if test="score != null "> and score = #{score}</if>
      <if test="seat != null "> and seat = #{seat}</if>
      <if test="num != null "> and num = #{num}</if>
      <if test="numReal != null "> and numReal = #{numReal}</if>
      <if test="createTime != null "> and createTime = #{createTime}</if>
      <if test="status != null "> and status = #{status}</if>
    </where>
  </select>

  <select id="selectBBusiWishUniversitySubmitsById" parameterType="Long" resultMap="BBusiWishUniversitySubmitsResult">
    <include refid="selectBBusiWishUniversitySubmitsVo" />
    where id = #{id}
  </select>

  <select id="selectBBusiWishUniversitySubmitsByCond" parameterType="map" resultMap="BBusiWishUniversitySubmitsResult">
    <include refid="selectBBusiWishUniversitySubmitsVo" />
    where`location` = #{location} AND `year` = #{year} AND `level` = #{level} AND liberalScience = #{liberalScience}
     and universityId in <foreach item="id" collection="universityIds" open="(" separator="," close=")">#{id}</foreach>
  </select>

  <insert id="insertBBusiWishUniversitySubmits" parameterType="BBusiWishUniversitySubmits" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_wish_university_submits
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="universityId != null">universityId,</if>
      <if test="year != null and year != ''">year,</if>
      <if test="location != null">location,</if>
      <if test="batch != null">batch,</if>
      <if test="type != null">type,</if>
      <if test="level != null">level,</if>
      <if test="score != null">score,</if>
      <if test="seat != null">seat,</if>
      <if test="num != null">num,</if>
      <if test="numReal != null">numReal,</if>
      <if test="createTime != null">createTime,</if>
      <if test="status != null">status,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="universityId != null">#{universityId},</if>
      <if test="year != null and year != ''">#{year},</if>
      <if test="location != null">#{location},</if>
      <if test="batch != null">#{batch},</if>
      <if test="type != null">#{type},</if>
      <if test="level != null">#{level},</if>
      <if test="score != null">#{score},</if>
      <if test="seat != null">#{seat},</if>
      <if test="num != null">#{num},</if>
      <if test="numReal != null">#{numReal},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="status != null">#{status},</if>
    </trim>
  </insert>

  <update id="updateBBusiWishUniversitySubmits" parameterType="BBusiWishUniversitySubmits">
    update b_busi_wish_university_submits
    <trim prefix="SET" suffixOverrides=",">
      <if test="universityId != null">universityId = #{universityId},</if>
      <if test="year != null and year != ''">year = #{year},</if>
      <if test="location != null">location = #{location},</if>
      <if test="batch != null">batch = #{batch},</if>
      <if test="type != null">type = #{type},</if>
      <if test="level != null">level = #{level},</if>
      <if test="score != null">score = #{score},</if>
      <if test="seat != null">seat = #{seat},</if>
      <if test="num != null">num = #{num},</if>
      <if test="numReal != null">numReal = #{numReal},</if>
      <if test="createTime != null">createTime = #{createTime},</if>
      <if test="status != null">status = #{status},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBBusiWishUniversitySubmitsById" parameterType="Long">
    delete from b_busi_wish_university_submits where id = #{id}
  </delete>

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