DataAuthMapper.xml 4.64 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.DataAuthDaoImpl">
	<resultMap id="dataAuthRM" type="com.diligrp.manage.domain.DataAuth">
		<id property="id" column="id" />
		<result property="type" column="type" />
		<result property="userId" column="user_id" />
		<result property="dataId" column="data_id" />
		<result property="parentDataId" column="parent_data_id" />
	</resultMap>

	<select id="findByParentDataId" parameterType="java.util.Map"
		resultMap="dataAuthRM">
		SELECT
		id
		,type
		,user_id
		,data_id
		,label
		,parent_data_id
		FROM
		security_data_auth
		WHERE type = #{type} AND user_id = #{userId} AND
		parent_data_id =
		#{parentDataId}
	</select>

	<select id="getById" parameterType="Long" resultMap="dataAuthRM">
		<![CDATA[
		SELECT
		    id
		    ,type
		    ,user_id
		    ,data_id
		    ,label
		    ,parent_data_id
		FROM security_data_auth

		WHERE id=#{pk}
		]]>
	</select>

	<select id="findByType" parameterType="map" resultMap="dataAuthRM">
		<![CDATA[
		SELECT
		    id
		    ,type
		    ,user_id
		    ,data_id
		    ,label
		    ,parent_data_id
		FROM security_data_auth

		WHERE user_id=#{userId}
		and type=#{type}
		]]>
	</select>

	<select id="findByData" parameterType="map" resultMap="dataAuthRM">
		<![CDATA[
		SELECT
		    id
		    ,type
		    ,user_id
		    ,data_id
		    ,label
		    ,parent_data_id
		FROM security_data_auth

		WHERE user_id=#{userId}
		and type=#{type}
		and data_id=#{dataId}
		]]>
	</select>

	<select id="findByUser" parameterType="long" resultMap="dataAuthRM">
		<![CDATA[
		SELECT
		    id
		    ,type
		    ,user_id
		    ,data_id
		    ,label
		    ,parent_data_id
		FROM security_data_auth
		WHERE user_id=#{pk}
		]]>
	</select>

	<insert id="save" parameterType="com.diligrp.manage.domain.DataAuth">
		<selectKey keyProperty="id" resultType="long" order="AFTER">
			SELECT
			LAST_INSERT_ID();
		</selectKey>
		<![CDATA[
		INSERT INTO security_data_auth(
                    type
                    ,user_id
                    ,data_id
                    ,label
                    ,parent_data_id
		) VALUES(
                    #{type}
                    ,#{userId}
                    ,#{dataId}
                    ,#{label}
                    ,#{parentDataId}
		)
		]]>
	</insert>

	<update id="update" parameterType="com.diligrp.manage.domain.DataAuth">
    <![CDATA[
            UPDATE security_data_auth set
                        type=#{type}
                        ,user_id=#{userId}
                        ,data_id=#{dataId}
                        ,label=#{label}
                        ,parent_data_id=#{parentDataId}

            where 1=1
            and id = #{id}
            ]]>
	</update>

	<select id="countByCondition" parameterType="Query" resultType="Integer">
		<![CDATA[
		SELECT count(1) FROM security_data_auth where 1=1
		]]>
		<if test="param != null">
			<if test="param.id != null and param.id != ''">
				and id = #{param.id}
			</if>
			<if test="param.type != null and param.type != ''">
				and type = #{param.type}
			</if>
			<if test="param.userId != null and param.userId != ''">
				and user_id = #{param.userId}
			</if>
			<if test="param.dataId != null and param.dataId != ''">
				and data_id = #{param.dataId}
			</if>
			<if test="param.label != null and param.label != ''">
				and label = #{param.label}
			</if>
			<if test="param.parentDataId != null and param.parentDataId != ''">
				and parent_data_id = #{param.parentDataId}
			</if>
		</if>
	</select>

	<select id="listByCondition" parameterType="Query" resultMap="dataAuthRM">
		<![CDATA[
		SELECT
		    id
		    ,type
		    ,user_id
		    ,data_id
		    ,parent_data_id
		FROM security_data_auth where 1=1
		]]>
		<if test="param != null">
			<if test="param.id != null and param.id != ''">
				and id = #{param.id}
			</if>
			<if test="param.type != null and param.type != ''">
				and type = #{param.type}
			</if>
			<if test="param.userId != null and param.userId != ''">
				and user_id = #{param.userId}
			</if>
			<if test="param.dataId != null and param.dataId != ''">
				and data_id = #{param.dataId}
			</if>
			<if test="param.label != null and param.label != ''">
				and label = #{param.label}
			</if>
			<if test="param.parentDataId != null and param.parentDataId != ''">
				and parent_data_id = #{param.parentDataId}
			</if>
		</if>
		order by id desc
		<![CDATA[
		limit #{startRow},#{pageSize}
		]]>
	</select>


	<update id="deleteById" parameterType="Long">
    <![CDATA[
        DELETE FROM security_data_auth
        where 1 = 1
        and id = #{id}
    ]]>
	</update>

</mapper>