ResourceUrlMapper.xml 5.15 KB
<?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.diligrp.manage.dao.impl.ResourceUrlDaoImpl">
    <resultMap id="ResourceUrlRM" type="com.diligrp.manage.domain.ResourceUrl">
        <id property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="url" column="url"/>
        <result property="method" column="method"/>
        <result property="created" column="created"/>
        <result property="modified" column="modified"/>
        <!--&lt;!&ndash; TODO: ??&ndash;&gt;-->
        <!--<association property="navbar" column="navbar_id" javaType="com.diligrp.manage.domain.Navbar"-->
                     <!--select="com.diligrp.manage.dao.impl.NavbarDaoImpl.getById"/>-->
    </resultMap>


    <select id="getById" parameterType="Long" resultMap="ResourceUrlRM">
		<![CDATA[

		SELECT
		    id
		    ,parent_id
		    ,url
		    ,method
		    ,created
		    ,modified
		FROM security_resource_url

		WHERE id=#{pk}

        ]]>
	</select>

    <insert id="save" parameterType="com.diligrp.manage.domain.ResourceUrl">
        <selectKey keyProperty="id" resultType="long" order="AFTER">
            SELECT LAST_INSERT_ID();
        </selectKey>
        <![CDATA[
		INSERT INTO security_resource_url(
                    parent_id
                    ,url
                    ,method
		) VALUES(
                    #{parentId}
                    ,#{url}
                    ,#{method}
		)
		]]>
    </insert>

    <update id="update" parameterType="com.diligrp.manage.domain.ResourceUrl">
    <![CDATA[

            UPDATE security_resource_url set
                        parent_id=#{parentId}
                        ,url=#{url}
                        ,method=#{method}

            where 1=1
            and id = #{id}

        ]]>
    </update>

    <select id="countByCondition" parameterType="Query" resultType="Integer">
        <![CDATA[
		SELECT count(1) FROM security_resource_url where 1=1
		]]>
        <if test="param != null">
            <if test="param.id != null and param.id != ''">
                and id = #{param.id}
            </if>
            <if test="param.parentId != null and param.parentId != ''">
                and parent_id = #{param.parentId}
            </if>
            <if test="param.url != null and param.url != ''">
                and url like concat(#{param.url}, '%')
            </if>
            <if test="param.method != null and param.method != ''">
                and method = #{param.method}
            </if>
            <if test="param.created != null and param.created != ''">
                and DATE_FORMAT(created, '%Y-%m-%d') = #{param.created}
            </if>
            <if test="param.modified != null and param.modified != ''">
                and DATE_FORMAT(modified, '%Y-%m-%d') = #{param.modified}
            </if>
        </if>
    </select>

    <select id="listByCondition" parameterType="Query" resultMap="ResourceUrlRM">
        <![CDATA[
		SELECT
		    id
		    ,parent_id
		    ,url
		    ,method
		    ,created
		    ,modified
		FROM security_resource_url where 1=1
		]]>
        <if test="param != null">
            <if test="param.id != null and param.id != ''">
                and id = #{param.id}
            </if>
            <if test="param.parentId != null and param.parentId != ''">
                and parent_id = #{param.parentId}
            </if>
            <if test="param.url != null and param.url != ''">
                and url like concat(#{param.url}, '%')
            </if>
            <if test="param.method != null and param.method != ''">
                and method = #{param.method}
            </if>
            <if test="param.created != null and param.created != ''">
                and DATE_FORMAT(created, '%Y-%m-%d') = #{param.created}
            </if>
            <if test="param.modified != null and param.modified != ''">
                and DATE_FORMAT(modified, '%Y-%m-%d') = #{param.modified}
            </if>
        </if>
        order by id desc
        <if test="param.pageQuery == null">
            <![CDATA[
				limit #{startRow},#{pageSize}
			]]>
        </if>

    </select>
    <select id="listAll" resultMap="ResourceUrlRM">
        <![CDATA[
		SELECT
		    id
		    ,parent_id
		    ,url
		    ,method
		    ,created
		    ,modified
		FROM security_resource_url where 1=1
		]]>

    </select>
    <select id="listByResourceID" resultMap="ResourceUrlRM">
        <![CDATA[
		SELECT
		    id
		    ,parent_id
		    ,url
		    ,method
		    ,created
		    ,modified
		FROM security_resource_url where parent_id=#{id}
		]]>

    </select>

    <delete id="deleteByParentId" parameterType="Long">
        delete from security_resource_url where 1 = 1 and parent_id = #{parentId}
    </delete>


    <select id="getResUrlsByRoleId" parameterType="Long" resultMap="ResourceUrlRM">
        <![CDATA[

    	select
    	    sru.id
		    ,parent_id
		    ,url
		    ,method
		    ,created
		    ,modified
		from
			security_resource_url sru left join security_role_permission srp on sru.parent_id = srp.resource_id
		where srp.role_id = #{id}

        ]]>
    </select>
</mapper>