<?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.sy.mapper.SyMajorUniversityMapper">
    
    <resultMap type="SyMajorUniversity" id="SyMajorUniversityResult">
        <result property="id"    column="id"    />
        <result property="universityCode"    column="universityCode"    />
        <result property="universityName"    column="universityName"    />
        <result property="diffScore"    column="diffScore"    />
        <result property="grade"    column="grade"    />
        <result property="mseLevel"    column="mseLevel"    />
        <result property="rank"    column="rank"    />
        <result property="majorCode"    column="majorCode"    />
        <result property="year"    column="year"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateTime"    column="updateTime"    />

        <association property="university"    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" />
        <result property="bannerUrl" column="bannerUrlU" />
        <result property="webSite" column="webSiteU" />
    </resultMap>


    <sql id="selectSyMajorUniversityVo">
        select t1.id, t1.universityCode, t1.universityName, t1.diffScore, t1.grade, t1.mseLevel, t1.`rank`, t1.majorCode, t1.year, 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,t2.bannerUrl bannerUrlU,t2.webSite webSiteU
        from sy_major_university t1
        LEFT  JOIN b_busi_wish_universities t2 ON  t1.universityCode= t2.code
    </sql>

    <select id="selectSyMajorUniversityList" parameterType="SyMajorUniversity" resultMap="SyMajorUniversityResult">
        <include refid="selectSyMajorUniversityVo"/>
        <where>  
            <if test="universityCode != null  and universityCode != ''"> and t1.universityCode = #{universityCode}</if>
            <if test="universityName != null  and universityName != ''"> and t1.universityName like concat('%', #{universityName}, '%')</if>
            <if test="diffScore != null  and diffScore != ''"> and t1.diffScore = #{diffScore}</if>
            <if test="grade != null  and grade != ''"> and t1.grade = #{grade}</if>
            <if test="mseLevel != null  and mseLevel != ''"> and t1.mseLevel = #{mseLevel}</if>
            <if test="rank != null "> and t1.`rank` = #{rank}</if>
            <if test="majorCode != null  and majorCode != ''"> and t1.majorCode = #{majorCode}</if>
            <if test="year != null "> and t1.year = #{year}</if>
            <if test="createTime != null "> and t1.createTime = #{createTime}</if>
            <if test="updateTime != null "> and t1.updateTime = #{updateTime}</if>

            <if test="managerType != null  and managerType != ''"> and t2.managerType = #{managerType}</if>
            <if test="type != null  and type != ''"> and t2.type like concat('%', #{type}, '%')</if>
            <if test="level != null  and level != ''"> and t2.level = #{level}</if>
            <if test="natureTypeCN != null  and natureTypeCN != ''"> and t2.natureTypeCN like concat('%', #{natureTypeCN}, '%')</if>
            <if test="features != null  and features != ''"> and t2.features like concat('%', #{features}, '%')</if>
            <if test="location != null  and location != ''"> and t2.location like concat('%', #{location}, '%')</if>
        </where>
          order by t1.`rank` asc
    </select>
    
    <select id="selectSyMajorUniversityById" parameterType="Long" resultMap="SyMajorUniversityResult">
        <include refid="selectSyMajorUniversityVo"/>
        where t1.id = #{id}
    </select>
        
    <insert id="insertSyMajorUniversity" parameterType="SyMajorUniversity" useGeneratedKeys="true" keyProperty="id">
        insert into sy_major_university
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="universityCode != null">universityCode,</if>
            <if test="universityName != null">universityName,</if>
            <if test="diffScore != null">diffScore,</if>
            <if test="grade != null">grade,</if>
            <if test="mseLevel != null">mseLevel,</if>
            <if test="rank != null">`rank`,</if>
            <if test="majorCode != null">majorCode,</if>
            <if test="year != null">year,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateTime != null">updateTime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="universityCode != null">#{universityCode},</if>
            <if test="universityName != null">#{universityName},</if>
            <if test="diffScore != null">#{diffScore},</if>
            <if test="grade != null">#{grade},</if>
            <if test="mseLevel != null">#{mseLevel},</if>
            <if test="rank != null">#{rank},</if>
            <if test="majorCode != null">#{majorCode},</if>
            <if test="year != null">#{year},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateSyMajorUniversity" parameterType="SyMajorUniversity">
        update sy_major_university
        <trim prefix="SET" suffixOverrides=",">
            <if test="universityCode != null">universityCode = #{universityCode},</if>
            <if test="universityName != null">universityName = #{universityName},</if>
            <if test="diffScore != null">diffScore = #{diffScore},</if>
            <if test="grade != null">grade = #{grade},</if>
            <if test="mseLevel != null">mseLevel = #{mseLevel},</if>
            <if test="rank != null">`rank` = #{rank},</if>
            <if test="majorCode != null">majorCode = #{majorCode},</if>
            <if test="year != null">year = #{year},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSyMajorUniversityById" parameterType="Long">
        delete from sy_major_university where id = #{id}
    </delete>

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