<?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.system.mapper.SysLoginPolicyMapper">

    <resultMap id="SysLoginPolicyResult" type="SysLoginPolicy">
        <id property="policyId" column="policy_id"/>
        <result property="roleKey" column="role_key"/>
        <result property="networkZone" column="network_zone"/>
        <result property="policyType" column="policy_type"/>
        <result property="enabled" column="enabled"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="selectEnabledByNetworkZone" resultMap="SysLoginPolicyResult">
        select policy_id, role_key, network_zone, policy_type, enabled, remark,
               create_by, create_time, update_by, update_time
        from sys_login_policy
        where enabled = '1' and network_zone = #{networkZone}
        order by policy_id
    </select>

    <select id="selectDefaultByNetworkZone" resultMap="SysLoginPolicyResult">
        select policy_id, role_key, network_zone, policy_type, enabled, remark,
               create_by, create_time, update_by, update_time
        from sys_login_policy
        where enabled = '1' and network_zone = #{networkZone}
          and (role_key is null or role_key = '')
        order by policy_id
        limit 1
    </select>
</mapper>
