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

  <resultMap type="BBusiWishUniversitySubmitMarjors" id="BBusiWishUniversitySubmitMarjorsResult">
    <result property="id" column="id" />
    <result property="year" column="year" />
    <result property="location" column="location" />
    <result property="level" column="level" />
    <result property="type" column="type" />
    <result property="marjorId" column="marjorId" />
    <result property="universityId" column="universityId" />
    <result property="universityCode" column="universityCode" />
    <result property="universityName" column="universityName" />
    <result property="universityNameText" column="universityNameText" />
    <result property="marjorCode" column="marjorCode" />
    <result property="marjorName" column="marjorName" />
    <result property="marjorNameText" column="marjorNameText" />
    <result property="marjorBelongs" column="marjorBelongs" />
    <result property="marjorDirection" column="marjorDirection" />
    <result property="specialProject" column="specialProject" />
    <result property="courseRemark0" column="courseRemark0" />
    <result property="courseRemark1" column="courseRemark1" />
    <result property="course0" column="course0" />
    <result property="course1" column="course1" />
    <result property="course2" column="course2" />
    <result property="score" column="score" />
    <result property="corrScore" column="corrScore" />
    <result property="seat" column="seat" />
    <result property="corrSeat" column="corrSeat" />
    <result property="num" column="num" />
    <result property="numReal" column="numReal" />
    <result property="scoreRealTop" column="scoreRealTop" />
    <result property="seatRealTop" column="seatRealTop" />
    <result property="scoreRealAverage" column="scoreRealAverage" />
    <result property="seatRealAverage" column="seatRealAverage" />
    <result property="createTime" column="createTime" />
    <result property="status" column="status" />
    <result property="collegeCode" column="collegeCode" />
    <result property="course" column="course" />
    <result property="liberalScience" column="liberalScience" />
    <result property="batch" column="batch" />
    <result property="groups" column="groups" />
    <result property="groupsName" column="groupsName" />
    <result property="xuezhi" column="xuezhi" />
  </resultMap>

  <sql id="selectBBusiWishUniversitySubmitMarjorsVo">
    select id, year, location, batch, level, type, marjorId, universityId, universityName, marjorCode, marjorName, marjorNameText, marjorBelongs, marjorDirection, specialProject, courseRemark0, courseRemark1, course0, course1,
    course2, score, corrScore, seat, corrSeat, num, numReal, scoreRealTop, seatRealTop, scoreRealAverage, seatRealAverage, createTime, status,
    universityCode,collegeCode,course,liberalScience,`groups`,`groupsName`, xuezhi
    from b_busi_wish_university_submit_marjors
  </sql>


  <select id="selectYearTypes" parameterType="map" resultMap="BBusiWishUniversitySubmitMarjorsResult">
    SELECT DISTINCT `year`, `type` FROM `b_busi_wish_university_submit_marjors`
    <where> location = #{location} AND `year` &gt;= #{year} AND `year` &lt;= #{currYear} AND liberalScience = #{liberalScience}
    </where>
  </select>

  <select id="selectWishUniversitySubmitMarjorsGroups" parameterType="map" resultMap="BBusiWishUniversitySubmitMarjorsResult">
  SELECT m.`id`, m.`universityId`, m.`collegeCode`, m.`year`, m.`location`, m.`batch`, m.`liberalScience`, m.`level`, m.`type`, m.`marjorName`, m.`marjorBelongs`, m.`marjorDirection`, m.`specialProject`, m.`numReal`, m.`score`, m.`seat`
    FROM `b_busi_wish_university_submit_marjors` m
    <where>
      <if test="ids != null"> and m.id in <foreach item="id" collection="ids" open="(" separator="," close=")">#{id}</foreach></if>
      <if test="location != null  and location != ''"> and m.`location` = #{location}</if>
      <if test="year != null"> AND m.`year` &gt;= #{year}</if>
      <if test="currYear != null != ''"> AND m.`year` &lt;= #{currYear}</if>
      <if test="liberalScience != null "> and  m.`liberalScience` = #{liberalScience} </if>
      <if test="level != null  and level != ''"> and m.`level` = #{level}</if>
      <if test="universityIds != null"> AND m.`universityId` in <foreach item="o" collection="universityIds" open="(" separator="," close=")">#{o}</foreach></if>
      <if test="collegeCodes != null"> AND m.`collegeCode` in <foreach item="o" collection="collegeCodes" open="(" separator="," close=")">#{o}</foreach></if>
    </where>
  </select>

  <select id="selectWishUniversitySubmitMarjorsByRank" parameterType="map" resultMap="BBusiWishUniversitySubmitMarjorsResult">
    SELECT m.`year`, m.`marjorName`, m.`marjorDirection`, m.`specialProject`, m.`universityId`, m.`type`
    FROM `b_busi_wish_university_submit_marjors` m
    JOIN `b_busi_wish_universities` u ON m.`universityId` = u.`id`
    <where> m.`location` = #{location} AND m.`year` = #{year} AND m.level = #{level} AND m.liberalScience = #{liberalScience}  and m.`seat` &gt;= #{lowestRank}
      <if test="highestRank != null"> and m.`seat` &lt; #{highestRank} </if>
      <if test="majors != null"> and m.`marjorName` in <foreach item="o" collection="majors" open="(" separator="," close=")">#{o}</foreach></if>
      <if test="uIds != null"> and u.`id` in <foreach item="o" collection="uIds" open="(" separator="," close=")">#{o}</foreach></if>
      <if test="uName != null and uName != ''"> and u.`name` like concat('%', #{uName}, '%')</if>
      <if test="uCode != null and uCode != ''"> and u.`code` = #{uCode}</if>
      <if test="uManagerType != null and uManagerType != ''"> and u.`managerType` = #{uManagerType}</if>

      <if test="uLocations != null"> and u.location in <foreach item="o" collection="uLocations" open="(" separator="," close=")">#{o}</foreach></if>
      <if test="uTypes != null"> and <foreach item="o" collection="uTypes" open="(" separator=" OR " close=")">u.`type` like concat('%', #{o}, '%')</foreach></if>
      <if test="uLevels != null"> and u.`level` in <foreach item="o" collection="uLevels" open="(" separator="," close=")">#{o}</foreach></if>
      <if test="uNatureTypeCNs != null"> and <foreach item="o" collection="uNatureTypeCNs" open="(" separator=" OR " close=")">u.`natureTypeCN` like concat('%', #{o}, '%')</foreach></if>
      <if test="uFeatureses"> and <foreach item="o" collection="uFeatureses" open="(" separator=" OR " close=")">u.`features` like concat('%', #{o}, '%')</foreach></if>
    </where>
  </select>

  <select id="selectBBusiWishUniversitySubmitMarjorsList" parameterType="BBusiWishUniversitySubmitMarjors" resultMap="BBusiWishUniversitySubmitMarjorsResult">
    <include refid="selectBBusiWishUniversitySubmitMarjorsVo" />
    <where>
      <if test="year != null  and year != ''"> and year = #{year}</if>
      <if test="location != null  and location != ''"> and location = #{location}</if>
      <if test="level != null  and level != ''"> and level = #{level}</if>
      <if test="type != null  and type != ''"> and type = #{type}</if>
      <if test="marjorId != null  and marjorId != ''"> and marjorId = #{marjorId}</if>
      <if test="universityId != null  and universityId != ''"> and universityId = #{universityId}</if>
      <if test="universityCode != null  and universityCode != ''"> and universityCode = #{universityCode}</if>
      <if test="universityName != null  and universityName != ''"> and universityName like concat('%', #{universityName}, '%')</if>
      <if test="marjorName != null  and marjorName != ''"> and marjorName like concat('%', #{marjorName}, '%')</if>
      <if test="marjorNameText != null  and marjorNameText != ''"> and marjorNameText like concat('%', #{marjorNameText}, '%')</if>
      <if test="marjorBelongs != null  and marjorBelongs != ''"> and marjorBelongs = #{marjorBelongs}</if>
      <if test="marjorDirection != null  and marjorDirection != ''"> and marjorDirection like concat('%', #{marjorDirection}, '%')</if>
      <if test="specialProject != null  and specialProject != ''"> and specialProject  like concat('%', #{specialProject}, '%')</if>
      <if test="courseRemark0 != null  and courseRemark0 != ''"> and courseRemark0 = #{courseRemark0}</if>
      <if test="courseRemark1 != null  and courseRemark1 != ''"> and courseRemark1 = #{courseRemark1}</if>
      <if test="course0 != null  and course0 != ''"> and course0 = #{course0}</if>
      <if test="course1 != null  and course1 != ''"> and course1 = #{course1}</if>
      <if test="course2 != null  and course2 != ''"> and course2 = #{course2}</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="scoreRealTop != null "> and scoreRealTop = #{scoreRealTop}</if>
      <if test="seatRealTop != null "> and seatRealTop = #{seatRealTop}</if>
      <if test="scoreRealAverage != null "> and scoreRealAverage = #{scoreRealAverage}</if>
      <if test="seatRealAverage != null "> and seatRealAverage = #{seatRealAverage}</if>
      <if test="createTime != null "> and createTime = #{createTime}</if>
      <if test="status != null "> and status = #{status}</if>

      <if test="collegeCode != null  and collegeCode != ''"> and collegeCode = #{collegeCode}</if>
      <if test="course != null  and course != ''"> and course = #{course}</if>
      <if test="liberalScience != null "> and liberalScience = #{liberalScience}</if>

    </where>
    order by collegeCode, batch, marjorCode, year desc
  </select>

  <select id="selectBBusiWishUniversitySubmitMarjorsById" parameterType="Long" resultMap="BBusiWishUniversitySubmitMarjorsResult">
    <include refid="selectBBusiWishUniversitySubmitMarjorsVo" />
    where id = #{id}
  </select>

  <select id="selectBBusiWishUniversitySubmitMarjorsByIds" parameterType="Long" resultMap="BBusiWishUniversitySubmitMarjorsResult">
    <include refid="selectBBusiWishUniversitySubmitMarjorsVo" />
    where id in
    <foreach item="id" collection="list" open="(" separator="," close=")">
      #{id}
    </foreach>
  </select>

  <select id="search" parameterType="Map" resultMap="BBusiWishUniversitySubmitMarjorsResult">
    select a.id, a.year, b.location as location, a.level as level, a.type, a.marjorId, a.universityId,
    a.universityName as universityName, a.universityNameText as universityNameText, a.marjorCode, a.marjorName,a.marjorNameText,
    a.marjorBelongs, a.marjorDirection, a.specialProject, a.courseRemark0, a.courseRemark1, a.course0, a.course1,
    a.course2, a.score, a.seat, a.num, a.numReal, a.scoreRealTop, a.seatRealTop, a.scoreRealAverage,
    a.seatRealAverage, a.createTime, a.status ,a.universityCode,a.collegeCode,a.course,a.liberalScience
    from b_busi_wish_university_submit_marjors 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}, '%')</if>
    <if test="universityNameText != null and universityNameText != ''"> and a.universityNameText like concat('%', #{universityNameText}, '%')</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="collegeCode != null and collegeCode != ''"> and a.collegeCode like concat('%', #{collegeCode}, '%')</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="batch != null">
      and a.batch = #{batch}
      <!-- and a.universityId in(select universityId from b_busi_wish_university_submits where batch= #{batch} )-->
    </if>
    <if test="spro != null and spro != ''"> and a.location = #{spro}</if>
    order by a.universityNameText, a.score desc
  </select>

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

  <select id="levels" resultType="String"> <!--  where status &gt; 0 -->
    select distinct level from b_busi_wish_university_submit_marjors
    <where>
    <if test="location!=null and location!=''">and location = #{location}</if>
    <if test="year!=null">and year = #{year}</if>
    </where>
    order by batch asc
  </select>

  <select id="types" resultType="String">
    select distinct type from b_busi_wish_university_submit_marjors where status &gt; 0
    <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_submit_marjors where status &gt; 0
    <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="getUniversityNameText" resultType="String">
    SELECT distinct universityNameText from b_busi_wish_university_submit_marjors where status &gt; 0 and (universityNameText is not null or universityNameText != '')
    and universityCode = #{universityCode} and location = #{location} and year = #{year} and type = #{type}
    <if test="level!=null and level!=''">
      and level = #{level}
    </if>
  </select>

  <select id="query" parameterType="String" resultMap="BBusiWishUniversitySubmitMarjorsResult">
    ${sql}
  </select>


  <insert id="insertBBusiWishUniversitySubmitMarjors" parameterType="BBusiWishUniversitySubmitMarjors" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_wish_university_submit_marjors
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="year != null and year != ''">year,</if>
      <if test="location != null">location,</if>
      <if test="level != null">level,</if>
      <if test="type != null">type,</if>
      <if test="marjorId != null">marjorId,</if>
      <if test="universityId != null">universityId,</if>
      <if test="universityName != null">universityName,</if>
      <if test="marjorCode != null">marjorCode,</if>
      <if test="marjorName != null">marjorName,</if>
      <if test="marjorNameText != null">marjorNameText,</if>
      <if test="marjorBelongs != null">marjorBelongs,</if>
      <if test="marjorDirection != null">marjorDirection,</if>
      <if test="specialProject != null">specialProject,</if>
      <if test="courseRemark0 != null">courseRemark0,</if>
      <if test="courseRemark1 != null">courseRemark1,</if>
      <if test="course0 != null">course0,</if>
      <if test="course1 != null">course1,</if>
      <if test="course2 != null">course2,</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="scoreRealTop != null">scoreRealTop,</if>
      <if test="seatRealTop != null">seatRealTop,</if>
      <if test="scoreRealAverage != null">scoreRealAverage,</if>
      <if test="seatRealAverage != null">seatRealAverage,</if>
      <if test="createTime != null">createTime,</if>
      <if test="status != null">status,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="year != null and year != ''">#{year},</if>
      <if test="location != null">#{location},</if>
      <if test="level != null">#{level},</if>
      <if test="type != null">#{type},</if>
      <if test="marjorId != null">#{marjorId},</if>
      <if test="universityId != null">#{universityId},</if>
      <if test="universityName != null">#{universityName},</if>
      <if test="marjorCode != null">#{marjorCode},</if>
      <if test="marjorName != null">#{marjorName},</if>
      <if test="marjorNameText != null">#{marjorNameText},</if>
      <if test="marjorBelongs != null">#{marjorBelongs},</if>
      <if test="marjorDirection != null">#{marjorDirection},</if>
      <if test="specialProject != null">#{specialProject},</if>
      <if test="courseRemark0 != null">#{courseRemark0},</if>
      <if test="courseRemark1 != null">#{courseRemark1},</if>
      <if test="course0 != null">#{course0},</if>
      <if test="course1 != null">#{course1},</if>
      <if test="course2 != null">#{course2},</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="scoreRealTop != null">#{scoreRealTop},</if>
      <if test="seatRealTop != null">#{seatRealTop},</if>
      <if test="scoreRealAverage != null">#{scoreRealAverage},</if>
      <if test="seatRealAverage != null">#{seatRealAverage},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="status != null">#{status},</if>
    </trim>
  </insert>

  <update id="updateBBusiWishUniversitySubmitMarjors" parameterType="BBusiWishUniversitySubmitMarjors">
    update b_busi_wish_university_submit_marjors
    <trim prefix="SET" suffixOverrides=",">
      <if test="year != null and year != ''">year = #{year},</if>
      <if test="location != null">location = #{location},</if>
      <if test="level != null">level = #{level},</if>
      <if test="type != null">type = #{type},</if>
      <if test="marjorId != null">marjorId = #{marjorId},</if>
      <if test="universityId != null">universityId = #{universityId},</if>
      <if test="universityName != null">universityName = #{universityName},</if>
      <if test="marjorCode != null">marjorCode = #{marjorCode},</if>
      <if test="marjorName != null">marjorName = #{marjorName},</if>
      <if test="marjorNameText != null">marjorNameText = #{marjorNameText},</if>
      <if test="marjorBelongs != null">marjorBelongs = #{marjorBelongs},</if>
      <if test="marjorDirection != null">marjorDirection = #{marjorDirection},</if>
      <if test="specialProject != null">specialProject = #{specialProject},</if>
      <if test="courseRemark0 != null">courseRemark0 = #{courseRemark0},</if>
      <if test="courseRemark1 != null">courseRemark1 = #{courseRemark1},</if>
      <if test="course0 != null">course0 = #{course0},</if>
      <if test="course1 != null">course1 = #{course1},</if>
      <if test="course2 != null">course2 = #{course2},</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="scoreRealTop != null">scoreRealTop = #{scoreRealTop},</if>
      <if test="seatRealTop != null">seatRealTop = #{seatRealTop},</if>
      <if test="scoreRealAverage != null">scoreRealAverage = #{scoreRealAverage},</if>
      <if test="seatRealAverage != null">seatRealAverage = #{seatRealAverage},</if>
      <if test="createTime != null">createTime = #{createTime},</if>
      <if test="status != null">status = #{status},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBBusiWishUniversitySubmitMarjorsById" parameterType="Long">
    delete from b_busi_wish_university_submit_marjors where id = #{id}
  </delete>

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