MenuMapper.xml 10.3 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.MenuDaoImpl">
    <resultMap id="MenuRM" type="com.diligrp.manage.domain.Menu">
        <id property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="sort" column="sort"/>
        <result property="isRoot" column="is_root"/>
        <result property="menuUrl" column="menu_url"/>
        <result property="label" column="label"/>
        <result property="description" column="description"/>
        <result property="target" column="target"/>
        <result property="navbarId" column="navbar_id"/>
        <result property="created" column="created"/>
        <result property="modified" column="modified"/>
        <result property="yn" column="yn"/>
        <result property="type" column="type"/>
        <!--<association property="navbar" column="navbar_id" javaType="com.diligrp.manage.domain.Navbar"-->
                     <!--select="com.diligrp.manage.dao.impl.NavbarDaoImpl.getById"/>-->
    </resultMap>
    
    <resultMap id="MenuJsonRM" type="com.diligrp.manage.domain.MenuJson">
        <id property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="sort" column="sort"/>
        <result property="menuUrl" column="menu_url"/>
        <result property="label" column="label"/>
        <result property="description" column="description"/>
        <result property="created" column="created"/>
        <result property="modified" column="modified"/>
		<result property="yn" column="yn"/>
    </resultMap>


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

		SELECT
		    id
		    ,parent_id
		    ,sort
		    ,is_root
		    ,menu_url
		    ,label
		    ,description
		    ,target
		    ,navbar_id
		    ,created
		    ,modified
		    ,yn
		    ,type
		FROM security_menu

		WHERE id=#{pk}
		and (yn is null or yn = 1)

        ]]>
	</select>


    <select id="getAll" resultMap="MenuRM">
        <![CDATA[
		SELECT
		    id
		    ,parent_id
		    ,sort
		    ,is_root
		    ,menu_url
		    ,label
		    ,description
		    ,target
		    ,navbar_id
		    ,created
		    ,modified
		    ,type
		FROM security_menu

		WHERE 1 = 1
		and (yn is null or yn = 1)
        order by navbar_id, sort asc
        ]]>
    </select>
    
    <select id="getAllMenuJson" resultMap="MenuJsonRM">
        <![CDATA[
		SELECT
		    id
		    ,parent_id
		    ,sort
		    ,menu_url
		    ,label
		    ,description
		    ,created
		    ,modified
		FROM security_menu

		WHERE (yn is null or yn = 1) order  by sort asc
        ]]>
    </select>

    <select id="getByParent" parameterType="Long" resultMap="MenuRM">
        <![CDATA[

		SELECT
		    id
		    ,parent_id
		    ,sort
		    ,is_root
		    ,menu_url
		    ,label
		    ,description
		    ,target
		    ,navbar_id
		    ,created
		    ,modified
		    ,type
		FROM security_menu

		WHERE parent_id=#{pk}
		and (yn is null or yn = 1)
        order by navbar_id, sort asc
        ]]>
    </select>

    <select id="findByUser" parameterType="Long" resultMap="MenuRM">
        select
            sm.id
		    ,sm.parent_id
		    ,sm.sort
		    ,sm.is_root
		    ,sm.menu_url
		    ,sm.label
		    ,sm.description
		    ,sm.target
		    ,sm.navbar_id
		    ,sm.created
		    ,sm.modified
		    ,type
		FROM security_menu sm
		left join security_role_menu srm on srm.menu_id = sm.id
		left join security_role sr on srm.role_id = sr.id
		left join security_user_role sur on sur.role_id = sr.id
		WHERE sur.user_id = #{pk}
		AND (sm.yn is null or sm.yn = 1)
    </select>

    <select id="getByRole" parameterType="Long" resultMap="MenuRM">
        select
            sm.id
		    ,sm.parent_id
		    ,sm.sort
		    ,sm.is_root
		    ,sm.menu_url
		    ,sm.label
		    ,sm.description
		    ,sm.target
		    ,sm.navbar_id
		    ,sm.created
		    ,sm.modified
		    ,type
		FROM security_menu sm
		left join security_role_menu srm on srm.menu_id = sm.id
		left join security_role sr on srm.role_id = sr.id
		where sr.id = #{pk}
		and (sm.yn is null or sm.yn = 1)
    </select>



    <insert id="save" parameterType="com.diligrp.manage.domain.Menu">
        <selectKey keyProperty="id" resultType="long" order="AFTER">
            SELECT LAST_INSERT_ID();
        </selectKey>
        <![CDATA[
		INSERT INTO security_menu(
                    parent_id
                    ,sort
                    ,is_root
                    ,menu_url
                    ,label
                    ,description
                    ,target
                    ,navbar_id
                    ,type
                    ,resource_id
		) VALUES(
                    #{parentId}
                    ,#{sort}
                    ,#{isRoot}
                    ,#{menuUrl}
                    ,#{label}
                    ,#{description}
                    ,#{target}
                    ,#{navbarId}
                    ,#{type}
                    ,#{resourceId}
		)
		]]>
    </insert>

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

            UPDATE security_menu set
                        parent_id=#{parentId}
                        ,sort=#{sort}
                        ,is_root=#{isRoot}
                        ,menu_url=#{menuUrl}
                        ,label=#{label}
                        ,description=#{description}
                        ,target=#{target}
                        ,navbar_id=#{navbarId}
                        ,type=#{type}
                        ,resource_id=#{resourceId}

            where 1=1
            and id = #{id}

        ]]>
    </update>

    <select id="countByCondition" parameterType="Query" resultType="Integer">
        <![CDATA[
		SELECT count(1) FROM security_menu 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.sort != null and param.sort != ''">
                and sort = #{param.sort}
            </if>
            <if test="param.isRoot != null and param.isRoot != ''">
                and is_root = #{param.isRoot}
            </if>
            <if test="param.menuUrl != null and param.menuUrl != ''">
                and menu_url = #{param.menuUrl}
            </if>
            <if test="param.label != null and param.label != ''">
                and label = #{param.label}
            </if>
            <if test="param.description != null and param.description != ''">
                and description = #{param.description}
            </if>
            <if test="param.target != null and param.target != ''">
                and target = #{param.target}
            </if>
            <if test="param.navbarId != null and param.navbarId != ''">
                and navbar_id = #{param.navbarId}
            </if>
            <if test="param.created != null and param.created != ''">
                and created = #{param.created}
            </if>
            <if test="param.modified != null and param.modified != ''">
                and modified = #{param.modified}
            </if>
            <![CDATA[
                    and (yn is null or yn = 1)
                    ]]>
            <if test="param.type != null and param.type != ''">
            and type = #{param.type}
            </if>
        </if>
    </select>
    
    
    <select id="countAllChild" parameterType="Long" resultType="Integer">
        <![CDATA[
		SELECT count(1) FROM security_menu where parent_id = #{parentId}  and (yn is null or yn = 1)
		]]>
    </select>

    <select id="listByCondition" parameterType="Query" resultMap="MenuRM">
        <![CDATA[
		SELECT
		    id
		    ,parent_id
		    ,sort
		    ,is_root
		    ,menu_url
		    ,label
		    ,description
		    ,target
		    ,navbar_id
		    ,created
		    ,modified
		    ,yn
		    ,type
		FROM security_menu 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.sort != null and param.sort != ''">
                and sort = #{param.sort}
            </if>
            <if test="param.isRoot != null and param.isRoot != ''">
                and is_root = #{param.isRoot}
            </if>
            <if test="param.menuUrl != null and param.menuUrl != ''">
                and menu_url = #{param.menuUrl}
            </if>
            <if test="param.label != null and param.label != ''">
                and label = #{param.label}
            </if>
            <if test="param.description != null and param.description != ''">
                and description = #{param.description}
            </if>
            <if test="param.target != null and param.target != ''">
                and target = #{param.target}
            </if>
            <if test="param.navbarId != null and param.navbarId != ''">
                and navbar_id = #{param.navbarId}
            </if>
            <if test="param.created != null and param.created != ''">
                and created = #{param.created}
            </if>
            <if test="param.modified != null and param.modified != ''">
                and modified = #{param.modified}
            </if>
	    <![CDATA[
	        and (yn is null or yn = 1)
	        ]]>
	        <if test="param.type != null and param.type != ''">
	            and type = #{param.type}
	        </if>

        </if>
        order by sort asc
        <![CDATA[
		limit #{startRow},#{pageSize}
		]]>
    </select>

    <delete id="deleteById" parameterType="long">
        delete from security_menu where id =#{id}
    </delete>

    <!--<update id="deleteById" parameterType="Long">-->
    <!--<![CDATA[-->

        <!--update security_menu set-->
        <!--yn = 2-->
        <!--where 1 = 1-->
        <!--and id = #{id}-->

        <!--]]>-->
    <!--</update>-->


    <update id="delByNavbar" parameterType="Long">
    <![CDATA[
        update security_menu set
        yn = 2
        where 1 = 1
        and navbar_id = #{id}
        ]]>
    </update>

</mapper>