<?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.judong.chuanyiserver.dao.PermissionDao">

    <insert id="addPermission">
        INSERT INTO sys_permission (permission_url, permission_name)
            VALUE (#{permissionUrl}, #{permissionName})
    </insert>
    <update id="updatePermission">
        update sys_permission
        set permission_url=#{permissionUrl},
            permission_name=#{permissionName}
        where id = #{id}
    </update>
    <delete id="deletePermissionById">
        delete
        from sys_permission
        where id = #{id}
    </delete>

    <delete id="deleteMenuPermissionById">
        delete
        from sys_menu_permission
        where permission_id = #{permissionId}
    </delete>

    <select id="getPermissionByUrl" resultType="com.judong.chuanyiserver.entity.Permission">
        select id, permission_url, permission_name
        from sys_permission
        where permission_url = #{permissionUrl}
    </select>

    <select id="getPermissionByNoIdUrl" resultType="com.judong.chuanyiserver.entity.Permission">
        select id, permission_url, permission_name
        from sys_permission
        where id != #{id}
          and permission_url = #{permissionUrl}
    </select>

    <select id="getPermissionById" resultType="com.judong.chuanyiserver.entity.Permission">
        select id, permission_url, permission_name
        from sys_permission
        where id = #{id}
    </select>

    <select id="getPermissionCount" resultType="java.lang.Long">
        select count(*)
        from sys_permission
        where 1=1
        <if test="permissionUrl != null">
            AND permission_url LIKE CONCAT('%', #{permissionUrl}, '%')
        </if>
        <if test="permissionName != null">
            AND permission_name LIKE CONCAT('%', #{permissionName}, '%')
        </if>
    </select>

    <select id="getPermissionListByPage" resultType="com.judong.chuanyiserver.entity.Permission">
        select id, permission_url, permission_name
        from sys_permission
        where 1=1
        <if test="permissionUrl != null">
            AND permission_url LIKE CONCAT('%', #{permissionUrl}, '%')
        </if>
        <if test="permissionName != null">
            AND permission_name LIKE CONCAT('%', #{permissionName}, '%')
        </if>
        limit #{startNum},#{limitNum}
    </select>
</mapper>