<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.keyPersonRatingDay" name="评分周期设置">
    <!-- 列表（可按类别过滤），附带类别中文名 -->
    <select id="selectRatingDayList" parameterType="map" resultType="map">
        SELECT
            t.id,
            t.rating_dict_type,
            d.label AS rating_dict_label,
            t.rating_start_day,
            t.rating_end_day,
            t.rating_over_day
        FROM jl_key_person_rating_dict_day t
        LEFT JOIN sys_dict d ON d.type = 'rating_dict_type' AND d.value = t.rating_dict_type
        <where>
            <if test="rating_dict_type != null and rating_dict_type != ''">
                AND t.rating_dict_type = #{rating_dict_type}
            </if>
        </where>
        ORDER BY t.rating_dict_type ASC
    </select>

    <!-- 单条（按类别） -->
    <select id="getByType" parameterType="map" resultType="map">
        SELECT id, rating_dict_type, rating_start_day, rating_end_day, rating_over_day
        FROM jl_key_person_rating_dict_day
        WHERE rating_dict_type = #{rating_dict_type}
        LIMIT 1
    </select>

    <!-- 新增 -->
    <insert id="insertRatingDay" parameterType="map">
        INSERT INTO jl_key_person_rating_dict_day (
            id,
            rating_dict_type,
            rating_start_day,
            rating_end_day,
            rating_over_day,
            create_by,
            create_time
        ) VALUES (
            UUID(),
            #{rating_dict_type},
            #{rating_start_day},
            #{rating_end_day},
            #{rating_over_day},
            #{_user.id},
            NOW()
        )
    </insert>

    <!-- 更新（按类别） -->
    <update id="updateRatingDay" parameterType="map">
        UPDATE jl_key_person_rating_dict_day
        SET
            rating_start_day = #{rating_start_day},
            rating_end_day = #{rating_end_day},
            rating_over_day = #{rating_over_day},
            update_by = #{_user.id},
            update_time = NOW()
        WHERE rating_dict_type = #{rating_dict_type}
    </update>
</mapper>
