<?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.BBusiWishUniversitiesRankingMapper">
    
    <resultMap type="BBusiWishUniversitiesRanking" id="BBusiWishUniversitiesRankingResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="collegeCode"    column="collegeCode"    />
        <result property="collegeName"    column="collegeName"    />
        <result property="ranking"    column="ranking"    />
        <result property="year"    column="year"    />
        <result property="collegeNumId"    column="collegeNumId"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateTime"    column="updateTime"    />
        <association property="universities"    column="code" javaType="BBusiWishUniversities" resultMap="universitiesResult" />
    </resultMap>

    <resultMap type="BBusiWishUniversities" id="universitiesResult">
        <result property="id" column="idU" />
        <result property="code" column="codeU" />
        <result property="name" column="nameU" />
        <result property="logo" column="logoU" />
        <result property="location" column="locationU" />
        <result property="managerType" column="managerTypeU" />
        <result property="type" column="typeU" />
        <result property="level" column="levelU" />
        <result property="comScore" column="comScoreU" />
        <result property="rankingOfEdu" column="rankingOfEduU" />
        <result property="ranking" column="rankingU" />
        <result property="cityName" column="cityNameU" />
        <result property="bxLevel" column="bxLevelU" />
        <result property="features" column="featuresU" />
        <result property="hits" column="hitsU" />
        <result property="natureTypeCN" column="natureTypeCNU" />
    </resultMap>

    <sql id="selectBBusiWishUniversitiesRankingVo">
        select t1.id, t1.type, t1.collegeCode, t1.collegeName, t1.ranking, t1.year, t1.collegeNumId, t1.createTime, t1.updateTime,
        t2.id idU, t2.code codeU, t2.name nameU, t2.logo logoU, t2.location locationU, t2.managerType managerTypeU, t2.type typeU, t2.level levelU,
    t2.comScore comScoreU,t2.rankingOfEdu rankingOfEduU,t2.ranking rankingU,t2.cityName cityNameU,
    t2.bxLevel bxLevelU,t2.features featuresU,t2.hits hitsU,t2.natureTypeCN natureTypeCNU
        from b_busi_wish_universities_ranking t1
        LEFT JOIN b_busi_wish_universities t2 on t1.collegeCode=t2.code
    </sql>

    <select id="selectBBusiWishUniversitiesRankingList" parameterType="BBusiWishUniversitiesRanking" resultMap="BBusiWishUniversitiesRankingResult">
        <include refid="selectBBusiWishUniversitiesRankingVo"/>
        <where>  
            <if test="type != null  and type != ''"> and t1.type = #{type}</if>
            <if test="collegeCodes != null"> and collegeCode in <foreach item="o" collection="collegeCodes" open="(" separator="," close=")">#{o}</foreach></if>
            <if test="collegeCode != null  and collegeCode != ''"> and t1.collegeCode = #{collegeCode}</if>
            <if test="collegeName != null  and collegeName != ''"> and t1.collegeName like concat('%', #{collegeName}, '%')</if>
            <if test="ranking != null "> and t1.ranking = #{ranking}</if>
            <if test="year != null "> and t1.year = #{year}</if>
            <if test="collegeNumId != null "> and t1.collegeNumId = #{collegeNumId}</if>
            <if test="createTime != null "> and t1.createTime = #{createTime}</if>
            <if test="updateTime != null "> and t1.updateTime = #{updateTime}</if>

            <if test="params != null and params.minYear != null "> and t1.year &gt;= #{params.minYear} </if>
            <if test="params != null and params.maxYear != null "> and t1.year &lt;= #{params.maxYear} </if>
        </where>
        order by ranking
        <if test="params.orderBy!=null and params.orderBy != ''"> order by #{params.orderBy} </if>
    </select>

    <select id="selectUniversitiesRankingMaxYearByType" parameterType="String" resultType="java.lang.Integer">
        select max(year) from b_busi_wish_universities_ranking
        where type = #{type}
    </select>

    <select id="selectBBusiWishUniversitiesRankingById" parameterType="String" resultMap="BBusiWishUniversitiesRankingResult">
        <include refid="selectBBusiWishUniversitiesRankingVo"/>
        where t1.id = #{id}
    </select>

    <select id="selectBBusiWishUniversitiesRankingTypes" resultType="String">
        SELECT DISTINCT `type` from b_busi_wish_universities_ranking order by type asc
    </select>

    <select id="selectBBusiWishUniversitiesRankingYears" parameterType="String" resultType="Integer">
        SELECT DISTINCT `year` from b_busi_wish_universities_ranking
        where 1=1
        <if test="type != null and type != ''">type = #{type},</if>
        order by year desc
    </select>
        
    <insert id="insertBBusiWishUniversitiesRanking" parameterType="BBusiWishUniversitiesRanking">
        insert into b_busi_wish_universities_ranking
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="collegeCode != null and collegeCode != ''">collegeCode,</if>
            <if test="collegeName != null and collegeName != ''">collegeName,</if>
            <if test="ranking != null">ranking,</if>
            <if test="year != null">year,</if>
            <if test="collegeNumId != null">collegeNumId,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateTime != null">updateTime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="collegeCode != null and collegeCode != ''">#{collegeCode},</if>
            <if test="collegeName != null and collegeName != ''">#{collegeName},</if>
            <if test="ranking != null">#{ranking},</if>
            <if test="year != null">#{year},</if>
            <if test="collegeNumId != null">#{collegeNumId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateBBusiWishUniversitiesRanking" parameterType="BBusiWishUniversitiesRanking">
        update b_busi_wish_universities_ranking
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="collegeCode != null and collegeCode != ''">collegeCode = #{collegeCode},</if>
            <if test="collegeName != null and collegeName != ''">collegeName = #{collegeName},</if>
            <if test="ranking != null">ranking = #{ranking},</if>
            <if test="year != null">year = #{year},</if>
            <if test="collegeNumId != null">collegeNumId = #{collegeNumId},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBBusiWishUniversitiesRankingById" parameterType="String">
        delete from b_busi_wish_universities_ranking where id = #{id}
    </delete>

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