ResourceMapper.xml 9.49 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.ResourceDaoImpl">
    <resultMap id="ResourceRM" type="com.diligrp.manage.domain.Resource">
        <id property="id" column="id"/>
        <result property="resourceName" column="resource_name"/>
        <result property="description" column="description"/>
        <result property="navbarId" column="navbar_id"/>
        <result property="url" column="url"/>
        <result property="status" column="status"/>
        <result property="created" column="created"/>
        <result property="modified" column="modified"/>
        <result property="method" column="method"/>
        <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>


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

		SELECT
		    id
		    ,resource_name
		    ,description
		    ,navbar_id
		    ,url
		    ,status
		    ,created
		    ,modified
		    ,method
		    ,type
		FROM security_resource

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

        ]]>
	</select>

    <insert id="save" parameterType="com.diligrp.manage.domain.Resource">
        <selectKey keyProperty="id" resultType="long" order="AFTER">
            SELECT LAST_INSERT_ID();
        </selectKey>
        <![CDATA[
		INSERT INTO security_resource(
                    resource_name
                    ,description
                    ,navbar_id
                    ,url
                    ,status
                    ,method
                    ,type
		) VALUES(
                    #{resourceName}
                    ,#{description}
                    ,#{navbarId}
                    ,#{url}
                    ,#{status}
                    ,#{method}
                    ,#{type}
		)
		]]>
    </insert>

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

            UPDATE security_resource set
                        resource_name=#{resourceName}
                        ,description=#{description}
                        ,navbar_id=#{navbarId}
                        ,url=#{url}
                        ,status=#{status}
                        ,method=#{method}
                        ,type=#{type}

            where 1=1
            and id = #{id}

        ]]>
    </update>

    <select id="countByCondition" parameterType="Query" resultType="Integer">
        <![CDATA[
		SELECT count(1) FROM security_resource where 1=1
		]]>
        <if test="param != null">
            <if test="param.id != null and param.id != ''">
                and id = #{param.id}
            </if>
            <if test="param.resourceName != null and param.resourceName != ''">
                and resource_name like CONCAT(#{param.resourceName}, '%')
            </if>
            <if test="param.description != null and param.description != ''">
                and description = #{param.description}
            </if>
            <if test="param.navbarId != null and param.navbarId != ''">
                and navbar_id = #{param.navbarId}
            </if>
            <if test="param.parentId != null and param.parentId != ''">
                and navbar_id = #{param.parentId}
            </if>
            <if test="param.url != null and param.url != ''">
                and url like concat(#{param.url}, '%')
            </if>
            <if test="param.status != null and param.status != ''">
                and status = #{param.status}
            </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 test="param.method != null and param.method != ''">
                and method = #{param.method}
            </if>
            <if test="param.type != null and param.type != ''">
                and type = #{param.type}
            </if>
            and yn = 1
        </if>
    </select>

    <select id="listByCondition" parameterType="Query" resultMap="ResourceRM">
        <![CDATA[
		SELECT
		    id
		    ,resource_name
		    ,description
		    ,navbar_id
		    ,url
		    ,status
		    ,created
		    ,modified
		    ,method
		    ,type
		FROM security_resource where 1=1
		]]>
        <if test="param != null">
            <if test="param.id != null and param.id != ''">
                and id = #{param.id}
            </if>
            <if test="param.resourceName != null and param.resourceName != ''">
                and resource_name like CONCAT(#{param.resourceName}, '%')
            </if>
            <if test="param.description != null and param.description != ''">
                and description = #{param.description}
            </if>
            <if test="param.navbarId != null and param.navbarId != ''">
                and navbar_id = #{param.navbarId}
            </if>
            <if test="param.parentId != null and param.parentId != ''">
                and navbar_id = #{param.parentId}
            </if>
            <if test="param.url != null and param.url != ''">
                and url like concat(#{param.url}, '%')
            </if>
            <if test="param.status != null and param.status != ''">
                and status = #{param.status}
            </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 test="param.method != null and param.method != ''">
                and method = #{param.method}
            </if>
            <if test="param.type != null and param.type != ''">
                and type = #{param.type}
            </if>
            and yn = 1
        </if>
        order by id desc
        <if test="param.pageQuery == null">
            <![CDATA[
				limit #{startRow},#{pageSize}
			]]>
        </if>

    </select>

    <select id="listAllUrls" resultType="java.lang.String">
		<![CDATA[
        SELECT
          concat(sn.code,'|',sr.status, '|', sr.method, '/', sr.url)
		FROM security_resource sr
        JOIN security_navbar sn on sn.id = sr.navbar_id
		WHERE
		1=1
        AND sr.yn = 1
        and sr.type != 3

        ]]>
	</select>

    <select id="getAllResourceJson" resultMap="ResourceRM" parameterType="com.diligrp.manage.domain.Resource">
        <![CDATA[
		SELECT
		    id
		    ,resource_name
		    ,description
		    ,navbar_id
		    ,url
		    ,status
		    ,created
		    ,modified
		    ,method
		FROM security_resource
		where
		 1=1
		 and yn = 1
		 and type = 1
	  ]]>

        <if test="url != null and url != ''">
            and url like CONCAT('%','${url}', '%')
        </if>

        <if test="resourceName != null and resourceName != ''">
            and resource_name like CONCAT('%','${resourceName}', '%')
        </if>


        <![CDATA[
		order by id desc
		 ]]>

    </select>


    <!--<update id="deleteById" parameterType="Long">-->
    <!--<![CDATA[-->
    <!--update security_resource set-->
    <!--yn = 2-->
    <!--where 1 = 1-->
    <!--and id = #{id}-->
    <!--]]>-->
    <!--</update>-->

    <delete id="deleteById" parameterType="Long">
        delete from security_resource where 1 = 1 and id = #{id}
    </delete>

    <select id="findAll" resultMap="ResourceRM" parameterType="map">
        SELECT
        id
        ,resource_name
        ,description
        ,navbar_id
        ,url
        ,status
        ,created
        ,modified
        ,method
        ,type
        FROM security_resource
        WHERE yn = 1
        <if test="status != null and status != ''">
            and status = #{status}
        </if>
    </select>

    <select id="findByRole" parameterType="Long" resultMap="ResourceRM">
    <![CDATA[

    	select sr.id
		    ,resource_name
		    ,description
		    ,navbar_id
		    ,url
		    ,status
		    ,created
		    ,modified
		    ,method
		    ,type
		from 
			security_resource sr left join security_role_permission srp on sr.id = srp.resource_id 
		where srp.role_id = #{id} and sr.yn = 1 and sr.status = 1

        ]]>
    </select>
    <select id="findByParent" parameterType="Long" resultMap="ResourceRM">
    <![CDATA[

    	select sr.id
		    ,resource_name
		    ,description
		    ,navbar_id
		    ,url
		    ,status
		    ,created
		    ,modified
		    ,method
		    ,type
		from
			security_resource sr
		where
		 1 = 1
		 and navbar_id = #{id}
		and sr.yn = 1 and sr.status = 1

        ]]>
    </select>


    <select id="checkResourceUrlUnique" parameterType="map" resultType="Boolean">
        select
        count(*) = 0
        from security_resource
        where yn = 1
        and url = #{url}

        <if test="id != null">
            and id &lt;&gt; #{id}
        </if>
    </select>

    <select id="checkResourceNameUnique" parameterType="map" resultType="Boolean">
        select
        count(*) = 0
        from security_resource
        where yn = 1
        and resource_name = #{resourceName}
        and type = 3

        <if test="id != null">
            and id &lt;&gt; #{id}
        </if>
    </select>
</mapper>