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

    <resultMap type="BBusiWishUniversitiesProfession" id="BBusiWishUniversitiesProfessionResult">
        <result property="id"    column="id"    />
        <result property="collegeCode"    column="collegeCode"    />
        <result property="type"    column="type"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="professionType"    column="professionType"    />
        <result property="examType"    column="examType"    />
        <result property="hot"    column="hot"    />
        <result property="ranking"    column="ranking"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectBBusiWishUniversitiesProfessionVo">
        select id, collegeCode, type, code, name, professionType, examType, hot, ranking, createTime, updateTime from b_busi_wish_universities_profession
    </sql>


    <select id="selectListByRuleCond" parameterType="Map" resultMap="BBusiWishUniversitiesProfessionResult">
      SELECT distinct es.id, collegeCode, es.type, es.code, es.name, professionType, es.examType, es.hot, es.ranking, es.createTime, es.updateTime
        FROM `b_busi_wish_universities_profession` es
        JOIN `b_busi_wish_universities` u ON es.`collegeCode` = u.`code`
        LEFT JOIN `sy_major` m1 ON m1.`name` =  es.`name`
        LEFT JOIN `sy_major` m2 ON m1.`parent_code` = m2.`code`
        LEFT JOIN `sy_major` m3 ON m2.`parent_code` = m3.`code`
        <where>
            <if test="examType != null and examType != ''"> and es.examType = #{examType}</if>
            <if test="universityCode != null and universityCode != ''"> and u.`code` = #{universityCode}</if>
            <choose>
                <when test="majorCodes != null"> AND (m1.`id` IS NULL OR m1.`code` in <foreach item="o" collection="majorCodes" open="(" separator="," close=")">#{o}</foreach>)</when>
                <when test="majorTypes != null"> AND (m1.`id` IS NULL OR m2.`code` in <foreach item="o" collection="majorTypes" open="(" separator="," close=")">#{o}</foreach>)</when>
                <when test="majorCategory != null and majorCategory != ''"> AND (m1.`id` IS NULL OR m3.`code` = #{majorCategory}) </when>
            </choose>
            <if test="universityIds != null"> AND u.`id` in <foreach item="o" collection="universityIds" open="(" separator="," close=")">#{o}</foreach></if>
            <if test="universityName != null and universityName != ''"> AND u.`name` LIKE CONCAT('%', #{universityName}, '%')</if>
            <if test="universityLevel != null"> AND u.`level` in <foreach item="o" collection="universityLevel" open="(" separator="," close=")">#{o}</foreach></if>
            <if test="universityType != null"> AND u.`type` in <foreach item="o" collection="universityType" open="(" separator="," close=")">#{o}</foreach></if>
            <if test="universityNatureType != null"> AND u.`natureTypeCN` in <foreach item="o" collection="universityNatureType" open="(" separator="," close=")">#{o}</foreach></if>
            <if test="universityLocation != null"> AND u.`location` in <foreach item="o" collection="universityLocation" open="(" separator="," close=")">#{o}</foreach></if>
        </where>
    </select>

    <select id="selectBBusiWishUniversitiesProfessionList" parameterType="BBusiWishUniversitiesProfession" resultMap="BBusiWishUniversitiesProfessionResult">
        <include refid="selectBBusiWishUniversitiesProfessionVo"/>
        <where>
            <if test="collegeCode != null  and collegeCode != ''"> and collegeCode = #{collegeCode}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="examType != null  and examType != ''"> and examType = #{examType}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="professionType != null  and professionType != ''"> and professionType = #{professionType}</if>
            <if test="hot != null"> and hot = #{hot}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
        order by id,ranking asc
    </select>

    <select id="selectEnrollPlanProfessionByCode" parameterType="map" resultMap="BBusiWishUniversitiesProfessionResult">
        SELECT distinct up.id, up.collegeCode, up.type, up.code, up.name, up.professionType, up.hot, up.ranking, up.createTime, up.updateTime, mp.`id` enrollCode, mp.`majorDirection` majorDirection  FROM `a_marjor_plan` mp
        JOIN `b_busi_wish_universities_profession` up ON mp.`universityId` = up.`collegeCode` AND up.`name` = mp.`majorName`
        <where>
            <if test="collegeCode != null  and collegeCode != ''"> and  mp.`universityId` = #{collegeCode}</if>
            <if test="year != null"> and mp.`year` = #{year}</if>
            <if test="code != null  and code != ''"> and up.code = #{code}</if>
            <if test="name != null  and name != ''"> and up.name like concat('%', #{name}, '%')</if>
            <if test="professionType != null  and professionType != ''"> and up.professionType = #{professionType}</if>
            <if test="examineeType != null  and examineeType != ''"> and mp.`examineeType` = #{examineeType}</if>
            <if test="examType != null  and examType != ''"> and up.`examType` = #{examType}</if>
            <if test="examMajor != null  and examMajor != ''"> and examMajor = #{examMajor}</if>
            <if test="hot != null"> and up.hot = #{hot}</if>
        </where>
        order by up.`ranking` asc, up.id
    </select>

    <select id="selectBBusiWishUniversitiesProfessionById" parameterType="String" resultMap="BBusiWishUniversitiesProfessionResult">
        <include refid="selectBBusiWishUniversitiesProfessionVo"/>
        where id = #{id}
    </select>

    <select id="selectBBusiWishUniversitiesProfessionByCode" parameterType="String" resultMap="BBusiWishUniversitiesProfessionResult">
        <include refid="selectBBusiWishUniversitiesProfessionVo"/>
        where code = #{code}
    </select>

    <insert id="insertBBusiWishUniversitiesProfession" parameterType="BBusiWishUniversitiesProfession">
        insert into b_busi_wish_universities_profession
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="collegeCode != null and collegeCode != ''">collegeCode,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="code != null and code != ''">code,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="professionType != null and professionType != ''">professionType,</if>
            <if test="hot != null">hot,</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="collegeCode != null and collegeCode != ''">#{collegeCode},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="code != null and code != ''">#{code},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="professionType != null and professionType != ''">#{professionType},</if>
            <if test="hot != null">#{hot},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateBBusiWishUniversitiesProfession" parameterType="BBusiWishUniversitiesProfession">
        update b_busi_wish_universities_profession
        <trim prefix="SET" suffixOverrides=",">
            <if test="collegeCode != null and collegeCode != ''">collegeCode = #{collegeCode},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="professionType != null and professionType != ''">professionType = #{professionType},</if>
            <if test="hot != null">hot = #{hot},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBBusiWishUniversitiesProfessionById" parameterType="String">
        delete from b_busi_wish_universities_profession where id = #{id}
    </delete>

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