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

  <resultMap type="BBusiWishXkcx" id="BBusiWishXkcxResult">
    <result property="id" column="id" />
    <result property="year" column="year" />
    <result property="customerCode" column="customer_code" />
    <result property="location" column="location" />
    <result property="level" column="level" />
    <result property="marjorId" column="marjorId" />
    <result property="universityId" column="universityId" />
    <result property="universityName" column="universityName" />
    <result property="marjorName" column="marjorName" />
    <result property="marjorBelongs" column="marjorBelongs" />
    <result property="marjorDirection" column="marjorDirection" />
    <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="seat" column="seat" />
    <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="roundId" column="roundId" />
    <result property="roundName" column="roundName" />
  </resultMap>

  <sql id="selectBBusiWishXkcxVo">
    select id, year, location, level, marjorId, universityId, universityName, marjorName, marjorBelongs, marjorDirection, courseRemark0, courseRemark1, course0, course1, course2,
    score, seat, num, numReal, scoreRealTop, seatRealTop, scoreRealAverage, seatRealAverage, createTime, status from b_busi_wish_xkcx
  </sql>

  <select id="selectBusiWishXkcxForRecommend" parameterType="list" resultMap="BBusiWishXkcxResult">
    SELECT distinct wx.course0, wx.course1, wx.course2, wx.`marjorName`
    FROM b_busi_wish_xkcx wx
    <where> wx.`course0` != '' AND
      <foreach item="c" collection="list" open="(" separator="OR" close=")">
        wx.`marjorName` = #{c.marjorName} AND <foreach item="o" collection="c.belongs" open="(" separator="OR" close=")"> wx.`marjorBelongs` LIKE #{o} </foreach>
      </foreach>
    </where>
  </select>

  <select id="selectBusiWishXkcxByCustomer2" parameterType="map" resultMap="BBusiWishXkcxResult">
    SELECT cx.`customerCode` customer_code,cx.`round_id` roundId, bx.`universityId`, bx.`universityName`, bx.`level`, bx.`marjorName`, bx.`marjorBelongs`, bx.`course0`, bx.`course1`, bx.`course2`
    FROM `b_customer_xkcx` cx
    JOIN `b_busi_wish_xkcx` bx ON cx.`submitId` = bx.`id`
    WHERE cx.`customerCode` in <foreach item="id" collection="customerCodes" open="(" separator="," close=")">#{id}</foreach> and cx.`is_select_course` = 1
  </select>

  <select id="selectBusiWishXkcxByCustomer" parameterType="map" resultMap="BBusiWishXkcxResult">
    SELECT cx.`customerCode` customer_code,cx.`round_id` roundId, bx.`universityId`, bx.`universityName`, mc.code `marjorId`, bx.`marjorName`, bx.`marjorBelongs`, bx.`course0`, bx.`course1`, bx.`course2`
    FROM `b_customer_xkcx` cx
    JOIN `b_busi_wish_xkcx` bx ON cx.`submitId` = bx.`id`
    JOIN `sy_major` mc ON mc.`name` = bx.`marjorName` AND mc.`type` = bx.`level` AND mc.`level` = 2
    WHERE cx.`customerCode` in <foreach item="id" collection="customerCodes" open="(" separator="," close=")">#{id}</foreach> and cx.`is_select_course` = 1
  </select>

  <select id="selectBBusiWishXkcxList" parameterType="BBusiWishXkcx" resultMap="BBusiWishXkcxResult">
    <include refid="selectBBusiWishXkcxVo" />
    <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="marjorId != null  and marjorId != ''"> and marjorId = #{marjorId}</if>
      <if test="universityId != null  and universityId != ''"> and universityId = #{universityId}</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="marjorBelongs != null  and marjorBelongs != ''"> and marjorBelongs = #{marjorBelongs}</if>
      <if test="marjorDirection != null  and marjorDirection != ''"> and marjorDirection = #{marjorDirection}</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>
    </where>
  </select>
  
  <select id="listByCourses" parameterType="String" resultMap="BBusiWishXkcxResult">
    <include refid="selectBBusiWishXkcxVo" />
    ${qw}
    <!--order by (SELECT code from b_busi_wish_universities t2 where t2.id=universityId) asc-->
  </select>

  <!--<select id="listByCourses_COUNT" parameterType="String" resultMap="BBusiWishXkcxResult">
    SELECT count(0) FROM b_busi_wish_xkcx
    ${qw}
  </select>-->

  <select id="listByCourses2" parameterType="BCustomerXkcx" resultMap="BBusiWishXkcxResult">
    select bbwx.*,concat(msr.year,' ',msr.name) roundName from b_customer_xkcx bcx
        LEFT JOIN b_busi_wish_xkcx bbwx on bcx.submitId = bbwx.id
        LEFT JOIN mxjb_selected_round msr on msr.round_id = bcx.round_id
        <where>
          <if test="customerCode != null  and customerCode != ''"> and bcx.customerCode = #{customerCode}</if>
          <if test="submitId != null "> and bcx.submitId = #{submitId}</if>
          <if test="createTime != null "> and bcx.createTime = #{createTime}</if>
          <if test="status != null "> and bcx.status = #{status}</if>
          <if test="isSelectCourse != null "> and bcx.is_select_course = #{isSelectCourse}</if>
          <if test="roundId != null "> and bcx.round_id = #{roundId}</if>
        </where>
  </select>

  <select id="selectBBusiWishXkcxRandom" parameterType="Integer" resultMap="BBusiWishXkcxResult">
    select * from b_busi_wish_xkcx WHERE
      `location` = '湖南'
        AND `level` = '本科' AND `year` =2024
        and (
          course0='历史'
          or
          course0='物理'
        )
        and universityId in ( SELECT t2.id FROM `b_busi_wish_universities` t2 WHERE t2.`yjsy` =2 and t2.`level` LIKE '%本科%')
        order by rand() LIMIT #{count}
  </select>

  <select id="selectBBusiWishXkcxById" parameterType="Long" resultMap="BBusiWishXkcxResult">
    <include refid="selectBBusiWishXkcxVo" />
    where id = #{id}
  </select>

  <select id="selectBBusiWishXkcxYears" parameterType="String"  resultType="Integer">
    SELECT DISTINCT year from b_busi_wish_xkcx where location =#{location} ORDER by year desc
  </select>

  <insert id="insertBBusiWishXkcx" parameterType="BBusiWishXkcx" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_wish_xkcx
    <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="marjorId != null">marjorId,</if>
      <if test="universityId != null">universityId,</if>
      <if test="universityName != null">universityName,</if>
      <if test="marjorName != null">marjorName,</if>
      <if test="marjorBelongs != null">marjorBelongs,</if>
      <if test="marjorDirection != null">marjorDirection,</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="marjorId != null">#{marjorId},</if>
      <if test="universityId != null">#{universityId},</if>
      <if test="universityName != null">#{universityName},</if>
      <if test="marjorName != null">#{marjorName},</if>
      <if test="marjorBelongs != null">#{marjorBelongs},</if>
      <if test="marjorDirection != null">#{marjorDirection},</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="updateBBusiWishXkcx" parameterType="BBusiWishXkcx">
    update b_busi_wish_xkcx
    <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="marjorId != null">marjorId = #{marjorId},</if>
      <if test="universityId != null">universityId = #{universityId},</if>
      <if test="universityName != null">universityName = #{universityName},</if>
      <if test="marjorName != null">marjorName = #{marjorName},</if>
      <if test="marjorBelongs != null">marjorBelongs = #{marjorBelongs},</if>
      <if test="marjorDirection != null">marjorDirection = #{marjorDirection},</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="deleteBBusiWishXkcxById" parameterType="Long">
    delete from b_busi_wish_xkcx where id = #{id}
  </delete>

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