<?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.BBusiWishUniversitiesDepartmentMapper">
    
    <resultMap type="BBusiWishUniversitiesDepartment" id="BBusiWishUniversitiesDepartmentResult">
        <result property="departmentId"    column="departmentId"    />
        <result property="collegeCode"    column="collegeCode"    />
        <result property="majorCount"    column="majorCount"    />
        <result property="name"    column="name"    />
        <result property="website"    column="website"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateTime"    column="updateTime"    />

        <collection property="departmentMajor" column="departmentId" javaType="java.util.List" resultMap="departmentMajorResult" />
    </resultMap>

    <resultMap type="BBusiWishUniversitiesDepartmentMajor" id="departmentMajorResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="name"    column="nameMajor"    />
        <result property="departmentId"    column="departmentId"    />
        <result property="level"    column="level"    />
        <result property="levelText"    column="levelText"    />
        <result property="collegeCode"    column="collegeCode"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectBBusiWishUniversitiesDepartmentVo">
        select t1.departmentId, t1.collegeCode, t1.majorCount, t1.name, t1.website, t1.createTime, t1.updateTime,
        t2.id, t2.code, t2.name nameMajor, t2.departmentId, t2.level, t2.levelText, t2.collegeCode, t2.createTime, t2.updateTime
        from b_busi_wish_universities_department t1
        left join b_busi_wish_universities_department_major t2 on t1.departmentId=t2.departmentId
    </sql>

    <select id="selectBBusiWishUniversitiesDepartmentList" parameterType="BBusiWishUniversitiesDepartment" resultMap="BBusiWishUniversitiesDepartmentResult">
        <include refid="selectBBusiWishUniversitiesDepartmentVo"/>
        <where>  
            <if test="departmentId != null  and departmentId != ''"> and t1.departmentId = #{departmentId}</if>
            <if test="collegeCode != null  and collegeCode != ''"> and t1.collegeCode = #{collegeCode}</if>
            <if test="majorCount != null "> and t1.majorCount = #{majorCount}</if>
            <if test="name != null  and name != ''"> and t1.name like concat('%', #{name}, '%')</if>
            <if test="website != null  and website != ''"> and t1.website = #{website}</if>
            <if test="createTime != null "> and t1.createTime = #{createTime}</if>
            <if test="updateTime != null "> and t1.updateTime = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectBBusiWishUniversitiesDepartmentById" parameterType="String" resultMap="BBusiWishUniversitiesDepartmentResult">
        <include refid="selectBBusiWishUniversitiesDepartmentVo"/>
        where t1.departmentId = #{departmentId}
    </select>
        
    <insert id="insertBBusiWishUniversitiesDepartment" parameterType="BBusiWishUniversitiesDepartment">
        insert into b_busi_wish_universities_department
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="departmentId != null">departmentId,</if>
            <if test="collegeCode != null and collegeCode != ''">collegeCode,</if>
            <if test="majorCount != null">majorCount,</if>
            <if test="name != null">name,</if>
            <if test="website != null">website,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateTime != null">updateTime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="departmentId != null">#{departmentId},</if>
            <if test="collegeCode != null and collegeCode != ''">#{collegeCode},</if>
            <if test="majorCount != null">#{majorCount},</if>
            <if test="name != null">#{name},</if>
            <if test="website != null">#{website},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateBBusiWishUniversitiesDepartment" parameterType="BBusiWishUniversitiesDepartment">
        update b_busi_wish_universities_department
        <trim prefix="SET" suffixOverrides=",">
            <if test="collegeCode != null and collegeCode != ''">collegeCode = #{collegeCode},</if>
            <if test="majorCount != null">majorCount = #{majorCount},</if>
            <if test="name != null">name = #{name},</if>
            <if test="website != null">website = #{website},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where departmentId = #{departmentId}
    </update>

    <delete id="deleteBBusiWishUniversitiesDepartmentById" parameterType="String">
        delete from b_busi_wish_universities_department where departmentId = #{departmentId}
    </delete>

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