<?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.jkcredit.invoice.hub.mapper.PermissionMapper">
    <resultMap id="baseResultMap" type="com.jkcredit.invoice.hub.model.po.permission.PermissionPo">
        <id column="id" property="id"/>
        <result column="permission" property="permission"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="activated" property="activated"/>
        <result column="permission_name" property="permissionName"/>
    </resultMap>

    <select id="getPermissionByUserId" resultMap="baseResultMap">
        select * from h_permission permission
        left join h_user_role_permission association on permission.id = association.permission_id
        where association.user_id = #{userId}
    </select>

    <select id="getPermissions" resultMap="baseResultMap">
        select * from
        h_permission
        <where>
            <if test="query.permission != null and query.permission != ''">
                and permission = #{query.permission}
            </if>
            <if test="query.permissionName != null and query.permissionName != ''">
                and permission_name = #{query.permissionName}
            </if>
        </where>
    </select>
</mapper>
