<?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.SyTestSelectMajorMapper">
    
    <resultMap type="SyTestSelectMajor" id="SyTestSelectMajorResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="customerCode"    column="customer_code"    />
        <result property="majorCode"    column="major_code"    />
        <result property="majorName"    column="major_name"    />
        <result property="majorCategoryCode"    column="major_category_code"    />
        <result property="majorCategoryName"    column="major_category_name"    />
        <result property="state"    column="state"    />
        <result property="ranking"    column="ranking"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectSyTestSelectMajorVo">
        select id, user_id, customer_code, major_code, state, ranking, create_time from sy_test_select_major
    </sql>

    <select id="selectSyTestSelectMajorForRecommend" parameterType="map" resultMap="SyTestSelectMajorResult">
    SELECT DISTINCT sm.`customer_code`, mm.code `major_code`, mm.name `major_name`, mc.code `major_category_code`, mc.name `major_category_name`
      FROM `sy_test_select_major` sm
      JOIN `sy_major` mm ON sm.`major_code` = mm.`code`
      JOIN `sy_major` mc ON mm.`parent_code` = mc.`code`
      JOIN `sy_major` ms ON mc.`parent_code` = ms.`code`
     WHERE sm.`customer_code` IN <foreach item="o" collection="codes" open="(" separator="," close=")">#{o}</foreach> AND sm.`state` = 1
    </select>

    <select id="selectSyTestSelectMajorList" parameterType="SyTestSelectMajor" resultMap="SyTestSelectMajorResult">
        <include refid="selectSyTestSelectMajorVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="customerCode != null  and customerCode != ''"> and customer_code = #{customerCode}</if>
            <if test="majorCode != null  and majorCode != ''"> and major_code = #{majorCode}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="ranking != null "> and ranking = #{ranking}</if>
        </where>
    </select>
    
    <select id="selectSyTestSelectMajorById" parameterType="Long" resultMap="SyTestSelectMajorResult">
        <include refid="selectSyTestSelectMajorVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSyTestSelectMajor" parameterType="SyTestSelectMajor" useGeneratedKeys="true" keyProperty="id">
        insert into sy_test_select_major
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="customerCode != null">customer_code,</if>
            <if test="majorCode != null">major_code,</if>
            <if test="state != null">state,</if>
            <if test="ranking != null">ranking,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="customerCode != null">#{customerCode},</if>
            <if test="majorCode != null">#{majorCode},</if>
            <if test="state != null">#{state},</if>
            <if test="ranking != null">#{ranking},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateSyTestSelectMajor" parameterType="SyTestSelectMajor">
        update sy_test_select_major
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="customerCode != null">customer_code = #{customerCode},</if>
            <if test="majorCode != null">major_code = #{majorCode},</if>
            <if test="state != null">state = #{state},</if>
            <if test="ranking != null">ranking = #{ranking},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSyTestSelectMajorById" parameterType="Long">
        delete from sy_test_select_major where id = #{id}
    </delete>

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