<?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.ie.mapper.AEnrollScoreMapper">
    
    <resultMap type="AEnrollScore" id="AEnrollScoreResult">
        <result property="id"    column="id"    />
        <result property="year"    column="year"    />
        <result property="universityId"    column="universityId"    />
        <result property="universityName"    column="universityName"    />
        <result property="enrollFormula"    column="enrollFormula"    />
        <result property="majorGroups"    column="majorGroups"    />
        <result property="majorNames"    column="majorNames"    />
        <result property="majorDirections"    column="majorDirections"    />
        <result property="examineeTypes"    column="examineeTypes"    />
        <result property="itemCategory"    column="itemCategory"    />
        <result property="itemName"    column="itemName"    />
        <result property="itemGroup"    column="itemGroup"    />
        <result property="itemType"    column="itemType"    />
        <result property="itemField"    column="itemField"    />
        <result property="valueType"    column="valueType"    />
        <result property="valueRule"    column="valueRule"    />
        <result property="correctType"    column="correctType"    />
        <result property="correctValue"    column="correctValue"    />
        <result property="valuePassRule"    column="valuePassRule"    />
        <result property="valueOptional"    column="valueOptional"    />
        <result property="scoreTotal"    column="scoreTotal"    />
        <result property="description"    column="description"    />
        <result property="comment"    column="comment"    />
        <result property="regex"    column="regex"    />
        <result property="placeholder"    column="placeholder"    />
        <result property="defaultValue"    column="defaultValue"    />
        <result property="tips"    column="tips"    />
        <result property="keyboardMode"    column="keyboardMode"    />
        <result property="dotDisable"    column="dotDisable"    />
    </resultMap>

    <sql id="selectAEnrollScoreVo">
        select id, year, universityId, universityName, enrollFormula, majorGroups, majorNames, majorDirections, examineeTypes, itemCategory, itemName, itemGroup, itemType, itemField, valueType, valueRule, correctType, correctValue, valuePassRule, valueOptional, scoreTotal, description, comment, regex, placeholder, defaultValue, tips, keyboardMode, dotDisable from a_enroll_score
    </sql>
    <select id="selectListByRuleCond" parameterType="Map" resultMap="AEnrollScoreResult">
        SELECT distinct es.id, es.year, es.universityId, es.universityName, enrollFormula, majorGroups, majorNames, majorDirections, examineeTypes, itemCategory, itemName, itemGroup, itemType, itemField, valueType, valueRule, correctType, correctValue, valuePassRule, valueOptional, scoreTotal, description, comment, regex, placeholder, defaultValue, tips, keyboardMode, dotDisable
        FROM `a_enroll_score` es
        JOIN `b_busi_wish_universities` u ON es.`universityId` = u.`id`
        LEFT JOIN `sy_major` m1 ON FIND_IN_SET(m1.`name`, es.`majorNames`) OR es.`majorNames` LIKE CONCAT('%', m1.`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="examineeType != null "> and es.examineeTypes = #{examineeType}</if>
            <if test="year != null "> and es.year = #{year}</if>
            <if test="universityCode != null and universityCode != ''"> and u.`code` = #{universityCode}</if>
            <if test="majorGroup != null"> and es.`majorGroups` = #{majorGroup}</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 es.`universityId` 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>
        ORDER BY itemType, es.`majorNames` DESC
    </select>

    <select id="selectAEnrollScoreList" parameterType="AEnrollScore" resultMap="AEnrollScoreResult">
        <include refid="selectAEnrollScoreVo"/>
        <where>  
            <if test="year != null "> and year = #{year}</if>
            <if test="universityId != null "> and universityId = #{universityId}</if>
            <if test="universityName != null  and universityName != ''"> and universityName like concat('%', #{universityName}, '%')</if>
            <if test="enrollFormula != null  and enrollFormula != ''"> and enrollFormula = #{enrollFormula}</if>
            <if test="majorGroups != null  and majorGroups != ''"> and majorGroups = #{majorGroups}</if>
            <if test="majorNames != null  and majorNames != ''"> and majorNames = #{majorNames}</if>
            <if test="majorDirections != null  and majorDirections != ''"> and majorDirections = #{majorDirections}</if>
            <if test="examineeTypes != null  and examineeTypes != ''"> and examineeTypes = #{examineeTypes}</if>
            <if test="itemCategory != null  and itemCategory != ''"> and itemCategory = #{itemCategory}</if>
            <if test="itemName != null  and itemName != ''"> and itemName like concat('%', #{itemName}, '%')</if>
            <if test="itemGroup != null  and itemGroup != ''"> and itemGroup = #{itemGroup}</if>
            <if test="itemType != null  and itemType != ''"> and itemType = #{itemType}</if>
            <if test="itemField != null  and itemField != ''"> and itemField = #{itemField}</if>
            <if test="valueType != null  and valueType != ''"> and valueType = #{valueType}</if>
            <if test="valueRule != null  and valueRule != ''"> and valueRule = #{valueRule}</if>
            <if test="correctType != null "> and correctType = #{correctType}</if>
            <if test="correctValue != null  and correctValue != ''"> and correctValue = #{correctValue}</if>
            <if test="valuePassRule != null  and valuePassRule != ''"> and valuePassRule = #{valuePassRule}</if>
            <if test="valueOptional != null  and valueOptional != ''"> and valueOptional = #{valueOptional}</if>
            <if test="scoreTotal != null "> and scoreTotal = #{scoreTotal}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="comment != null  and comment != ''"> and comment = #{comment}</if>
            <if test="regex != null  and regex != ''"> and regex = #{regex}</if>
            <if test="placeholder != null  and placeholder != ''"> and placeholder = #{placeholder}</if>
            <if test="defaultValue != null  and defaultValue != ''"> and defaultValue = #{defaultValue}</if>
            <if test="tips != null  and tips != ''"> and tips = #{tips}</if>
            <if test="keyboardMode != null  and keyboardMode != ''"> and keyboardMode = #{keyboardMode}</if>
            <if test="dotDisable != null "> and dotDisable = #{dotDisable}</if>
        </where>
    </select>
    
    <select id="selectAEnrollScoreById" parameterType="String" resultMap="AEnrollScoreResult">
        <include refid="selectAEnrollScoreVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAEnrollScore" parameterType="AEnrollScore" useGeneratedKeys="true" keyProperty="id">
        insert into a_enroll_score
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="year != null">year,</if>
            <if test="universityId != null">universityId,</if>
            <if test="universityName != null">universityName,</if>
            <if test="enrollFormula != null">enrollFormula,</if>
            <if test="majorGroups != null">majorGroups,</if>
            <if test="majorNames != null">majorNames,</if>
            <if test="majorDirections != null">majorDirections,</if>
            <if test="examineeTypes != null">examineeTypes,</if>
            <if test="itemCategory != null">itemCategory,</if>
            <if test="itemName != null">itemName,</if>
            <if test="itemGroup != null">itemGroup,</if>
            <if test="itemType != null">itemType,</if>
            <if test="itemField != null">itemField,</if>
            <if test="valueType != null">valueType,</if>
            <if test="valueRule != null">valueRule,</if>
            <if test="correctType != null">correctType,</if>
            <if test="correctValue != null">correctValue,</if>
            <if test="valuePassRule != null">valuePassRule,</if>
            <if test="valueOptional != null">valueOptional,</if>
            <if test="scoreTotal != null">scoreTotal,</if>
            <if test="description != null">description,</if>
            <if test="comment != null">comment,</if>
            <if test="regex != null">regex,</if>
            <if test="placeholder != null">placeholder,</if>
            <if test="defaultValue != null">defaultValue,</if>
            <if test="tips != null">tips,</if>
            <if test="keyboardMode != null">keyboardMode,</if>
            <if test="dotDisable != null">dotDisable,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="year != null">#{year},</if>
            <if test="universityId != null">#{universityId},</if>
            <if test="universityName != null">#{universityName},</if>
            <if test="enrollFormula != null">#{enrollFormula},</if>
            <if test="majorGroups != null">#{majorGroups},</if>
            <if test="majorNames != null">#{majorNames},</if>
            <if test="majorDirections != null">#{majorDirections},</if>
            <if test="examineeTypes != null">#{examineeTypes},</if>
            <if test="itemCategory != null">#{itemCategory},</if>
            <if test="itemName != null">#{itemName},</if>
            <if test="itemGroup != null">#{itemGroup},</if>
            <if test="itemType != null">#{itemType},</if>
            <if test="itemField != null">#{itemField},</if>
            <if test="valueType != null">#{valueType},</if>
            <if test="valueRule != null">#{valueRule},</if>
            <if test="correctType != null">#{correctType},</if>
            <if test="correctValue != null">#{correctValue},</if>
            <if test="valuePassRule != null">#{valuePassRule},</if>
            <if test="valueOptional != null">#{valueOptional},</if>
            <if test="scoreTotal != null">#{scoreTotal},</if>
            <if test="description != null">#{description},</if>
            <if test="comment != null">#{comment},</if>
            <if test="regex != null">#{regex},</if>
            <if test="placeholder != null">#{placeholder},</if>
            <if test="defaultValue != null">#{defaultValue},</if>
            <if test="tips != null">#{tips},</if>
            <if test="keyboardMode != null">#{keyboardMode},</if>
            <if test="dotDisable != null">#{dotDisable},</if>
         </trim>
    </insert>

    <update id="updateAEnrollScore" parameterType="AEnrollScore">
        update a_enroll_score
        <trim prefix="SET" suffixOverrides=",">
            <if test="year != null">year = #{year},</if>
            <if test="universityId != null">universityId = #{universityId},</if>
            <if test="universityName != null">universityName = #{universityName},</if>
            <if test="enrollFormula != null">enrollFormula = #{enrollFormula},</if>
            <if test="majorGroups != null">majorGroups = #{majorGroups},</if>
            <if test="majorNames != null">majorNames = #{majorNames},</if>
            <if test="majorDirections != null">majorDirections = #{majorDirections},</if>
            <if test="examineeTypes != null">examineeTypes = #{examineeTypes},</if>
            <if test="itemCategory != null">itemCategory = #{itemCategory},</if>
            <if test="itemName != null">itemName = #{itemName},</if>
            <if test="itemGroup != null">itemGroup = #{itemGroup},</if>
            <if test="itemType != null">itemType = #{itemType},</if>
            <if test="itemField != null">itemField = #{itemField},</if>
            <if test="valueType != null">valueType = #{valueType},</if>
            <if test="valueRule != null">valueRule = #{valueRule},</if>
            <if test="correctType != null">correctType = #{correctType},</if>
            <if test="correctValue != null">correctValue = #{correctValue},</if>
            <if test="valuePassRule != null">valuePassRule = #{valuePassRule},</if>
            <if test="valueOptional != null">valueOptional = #{valueOptional},</if>
            <if test="scoreTotal != null">scoreTotal = #{scoreTotal},</if>
            <if test="description != null">description = #{description},</if>
            <if test="comment != null">comment = #{comment},</if>
            <if test="regex != null">regex = #{regex},</if>
            <if test="placeholder != null">placeholder = #{placeholder},</if>
            <if test="defaultValue != null">defaultValue = #{defaultValue},</if>
            <if test="tips != null">tips = #{tips},</if>
            <if test="keyboardMode != null">keyboardMode = #{keyboardMode},</if>
            <if test="dotDisable != null">dotDisable = #{dotDisable},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAEnrollScoreById" parameterType="Long">
        delete from a_enroll_score where id = #{id}
    </delete>

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