<?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="io.dataease.base.mapper.ext.ExtSysAuthDetailMapper">

    <select id="searchAuthTypeModel" resultMap="io.dataease.base.mapper.SysAuthDetailMapper.BaseResultMap">
        select
        sys_auth_detail.privilege_name ,
        sys_auth_detail.privilege_type ,
        sys_auth_detail.privilege_value
        from sys_auth_detail where sys_auth_detail.auth_id =#{authTypeModel} order by sys_auth_detail.privilege_type desc
    </select>

    <insert id="copyAuthModel">
        INSERT INTO  sys_auth_detail (
            id,
            auth_id,
            privilege_name,
            privilege_type,
            privilege_value,
            privilege_extend,
            remark,
            create_user,
            create_time
        ) SELECT
        uuid() AS id,
        #{authId} AS auth_id,
        sys_auth_detail.privilege_name,
        sys_auth_detail.privilege_type,
        sys_auth_detail.privilege_value,
        sys_auth_detail.privilege_extend,
        sys_auth_detail.remark,
        #{createUser} AS create_user,
        unix_timestamp(now())* 1000 AS create_time
        FROM
            sys_auth_detail where auth_id =#{authTypeModel}
    </insert>


    <update id="authDetailsChange">
        UPDATE sys_auth_detail
        SET privilege_value = #{privilegeValue}
        <where>
            auth_id in
            <foreach collection='authIds' item='authId' open='(' separator=',' close=')'>#{authId}</foreach>
            <if test="privilegeValue == 1">
                and privilege_type &lt;=  #{privilegeType}
            </if>
            <if test="privilegeValue == 0">
                and privilege_type &gt;=  #{privilegeType}
            </if>
        </where>
    </update>

</mapper>
