<?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.keyPersonVisitPower" name="重点人员按钮权限">
    <!-- 列出所有page_button字典，并左连接权限表，汇总可见部门类型（label以逗号拼接） -->
    <select id="selectPageButtonPowerList" parameterType="map" resultType="map">
        SELECT
            d.value AS rating_dict_value,
            d.label AS rating_dict_label,
            p.rating_visit_office AS office_labels,
            p.rating_visit_office_value AS office_values
        FROM sys_dict d
        LEFT JOIN jl_key_person_visit_power p
            ON p.rating_dict_value = d.value
        WHERE d.type = 'page_button'
        ORDER BY d.sort ASC
    </select>

    <!-- 根据按钮value获取配置 -->
    <select id="getPowerByRatingValue" parameterType="map" resultType="map">
        SELECT id, rating_dict_value, rating_dict_label, rating_visit_office, rating_visit_office_value
        FROM jl_key_person_visit_power
        WHERE rating_dict_value = #{rating_dict_value}
        LIMIT 1
    </select>

    <!-- 新增配置 -->
    <insert id="insertPower" parameterType="map">
        INSERT INTO jl_key_person_visit_power(
            id,
            rating_dict_value,
            rating_dict_label,
            rating_visit_office,
            rating_visit_office_value,
            create_by,
            create_time
        ) VALUES (
            UUID(),
            #{rating_dict_value},
            #{rating_dict_label},
            #{rating_visit_office},
            #{rating_visit_office_value},
            #{_user.id},
            NOW()
        )
    </insert>

    <!-- 更新配置（按value） -->
    <update id="updatePower" parameterType="map">
        UPDATE jl_key_person_visit_power
        SET
            rating_dict_label = #{rating_dict_label},
            rating_visit_office = #{rating_visit_office},
            rating_visit_office_value = #{rating_visit_office_value},
            update_by = #{_user.id},
            update_time = NOW()
        WHERE rating_dict_value = #{rating_dict_value}
    </update>
</mapper>


