<?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.ssm.manage.mapper.RoutingMapper">

    <resultMap id="RoutingMap" type="com.ssm.manage.entity.Routing">
        <result column="id" jdbcType="BIGINT" property="id" />
        <result column="member_name" jdbcType="VARCHAR" property="memberName" />
        <result column="type" jdbcType="BIGINT" property="type" />
        <result column="superior_id" jdbcType="BIGINT" property="superiorId" />
        <result column="superior_name" jdbcType="VARCHAR" property="superiorName" />
        <result column="path" jdbcType="VARCHAR" property="path" />
        <result column="founder_staff" jdbcType="VARCHAR" property="founderStaff" />
        <result column="founder_datetime" jdbcType="DATE" property="founderDatetime" />
        <result column="modify_by" jdbcType="VARCHAR" property="modifyBy" />
        <result column="modify_datetime" jdbcType="DATE" property="modifyDatetime" />
        <result column="component" jdbcType="VARCHAR" property="component" />
        <result column="path_index" jdbcType="VARCHAR" property="pathIndex" />
    </resultMap>

    <resultMap id="SysRolePower" type="com.ssm.manage.entity.SysRolePower">
        <result column="power_id" jdbcType="BIGINT" property="powerId" />
    </resultMap>

    <resultMap id="SysMenuPower" type="com.ssm.manage.entity.SysMenuPower">
        <result column="id" jdbcType="BIGINT" property="id" />
    </resultMap>


    <!--路由查询-->
    <select id="selectPage" resultMap="RoutingMap">
        select * from routing
        <where>
            <if test="memberName != null">
                and  member_name like  concat('%',concat( #{memberName, jdbcType = VARCHAR}, '%'))
            </if>
        </where>
    </select>

    <!--路径重复查询-->
    <select id="selectPath" resultMap="RoutingMap">
        select path from routing where path= #{path, jdbcType = VARCHAR}
    </select>



    <!--查询添加ID是否重复-->
    <select id="selectDvalue" resultMap="RoutingMap">
        select id from routing where id= #{id, jdbcType = VARCHAR}
    </select>
    <!--查询添加ID是否重复-->
    <select id="selectDvalue1" resultMap="SysRolePower">
        select power_id from sys_role_power where power_id= #{powerId, jdbcType = VARCHAR}
    </select>
    <!--查询添加ID是否重复-->
    <select id="selectDvalue2" resultMap="SysMenuPower">
        select id from sys_menu_power where id= #{id, jdbcType = VARCHAR}
    </select>





    <!--路由删除-->
    <delete id="deleteID" >
        delete from routing where id in
        <foreach collection="list"  item="item" open="(" separator="," close=")">
            #{item.id, jdbcType = BIGINT}
        </foreach>
    </delete>

    <!--路由权限删除1-->
    <delete id="deleteID1" >
        delete from sys_menu_power where id = #{id, jdbcType = BIGINT}
    </delete>

    <!--路由权限删除2-->
    <delete id="deleteID2" >
        delete from sys_role_power where power_id = #{powerId, jdbcType = BIGINT}
    </delete>



    <!--路由修改-->
    <update id="updateId">
        update  routing set superior_name = #{memberName , jdbcType = VARCHAR}
        where id in
        <foreach collection="list"  item="item" open="(" separator="," close=")">
            #{item.id, jdbcType = BIGINT}
        </foreach>
    </update>

    <!--路由权限修改1-->
    <update id="updateId1">
        update  sys_menu_power set power_name = #{memberName , jdbcType = VARCHAR}
        where id = #{id, jdbcType = BIGINT}
    </update>

    <!--路由查询-->
    <select id="selectSuperid"  resultMap="RoutingMap">
        select id from routing where superior_id = #{id, jdbcType = BIGINT};
    </select>

    <insert id="add1" >
        insert into sys_menu_power(type,power_name,id,state) values
            (
                #{type, jdbcType = VARCHAR},
                #{memberName, jdbcType = VARCHAR},
                #{id, jdbcType = BIGINT},
                '0'
            )
    </insert>

    <insert id="add2" >
        insert into sys_role_power(role_id,power_id) values
            (
                '45680126901686272',
                #{id, jdbcType = BIGINT}
            )


    </insert>



</mapper>