<?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.landtool.lanbase.modules.sys.dao.SysRoleGroupDao">
|
|
<!-- 可根据自己的需求,是否要使用 -->
|
<resultMap type="com.landtool.lanbase.modules.sys.entity.SysRoleGroup" id="rolegroupMap">
|
<result property="roleId" column="roleid"/>
|
<result property="groupId" column="groupid"/>
|
<result property="createUnitId" column="createunitid"/>
|
<result property="rCreateDate" column="rcreatedate"/>
|
<result property="rCreateUser" column="rcreateuser"/>
|
</resultMap>
|
|
<select id="queryObject" resultType="com.landtool.lanbase.modules.sys.entity.SysRoleGroup">
|
select * from SYS_ROLEGROUP where roleid = #{value}
|
</select>
|
|
<select id="queryList" resultType="com.landtool.lanbase.modules.sys.entity.SysRoleGroup">
|
|
SELECT *
|
FROM(
|
SELECT ROW_NUMBER() OVER(ORDER BY B.roleid) AS rownumber,B.*
|
FROM (
|
|
select * from SYS_ROLEGROUP
|
|
) B
|
) A
|
WHERE rownumber > #{lowerOffset} AND <![CDATA[ rownumber <= ${upperOffset} ]]>
|
</select>
|
|
<select id="queryTotal" resultType="int">
|
select count(*) from SYS_ROLEGROUP
|
</select>
|
|
<insert id="save" parameterType="com.landtool.lanbase.modules.sys.entity.SysRoleGroup">
|
insert into SYS_ROLEGROUP
|
(
|
roleid,
|
groupid,
|
createunitid,
|
rcreatedate,
|
rcreateuser
|
)
|
values
|
(
|
#{roleId},
|
#{groupId},
|
#{createUnitId},
|
#{rCreateDate},
|
#{rCreateUser}
|
)
|
</insert>
|
|
<update id="update" parameterType="com.landtool.lanbase.modules.sys.entity.SysRoleGroup">
|
update SYS_ROLEGROUP
|
<set>
|
<if test="groupId != null">groupid = #{groupId}, </if>
|
<if test="createUnitId != null">createunitid = #{createUnitId}, </if>
|
<if test="rCreateDate != null">rcreatedate = #{rCreateDate}, </if>
|
<if test="rCreateUser != null">rcreateuser = #{rCreateUser}</if>
|
</set>
|
where roleid = #{roleId}
|
</update>
|
|
<delete id="delete">
|
delete from SYS_ROLEGROUP where roleid = #{value}
|
</delete>
|
|
<delete id="deleteBatch">
|
delete from SYS_ROLEGROUP where roleid in
|
<foreach item="roleId" collection="array" open="(" separator="," close=")">
|
#{roleId}
|
</foreach>
|
</delete>
|
|
<select id="findList" resultType="map">
|
SELECT
|
groupid "groupId", groupname "groupName", description "description", ROLES AS "roles"
|
FROM(
|
SELECT ROW_NUMBER() OVER(ORDER BY B.groupid) AS rownumber,B.*
|
FROM (
|
|
SELECT
|
og.groupid AS groupId,
|
og.groupname AS groupName,
|
og.description,
|
b.ROLES AS roles
|
FROM ORG_GROUP og
|
LEFT JOIN (
|
SELECT DISTINCT
|
A.groupid,
|
(SELECT STRING_AGG(cast(B.rolename as varchar),',')
|
FROM (SELECT srg.groupid, sr.rolename FROM SYS_ROLEGROUP srg
|
INNER JOIN SYS_ROLE sr ON srg.roleid = sr.roleid ) B
|
WHERE B.groupid = A.groupid group by A.groupid order by A.groupid) AS ROLES
|
FROM (
|
SELECT
|
srg.groupid,
|
sr.rolename
|
FROM SYS_ROLEGROUP srg
|
INNER JOIN SYS_ROLE sr ON srg.roleid = sr.roleid
|
) A
|
) b ON b.groupid = og.groupid
|
WHERE og.appid IN (SELECT 0 AS appid from SYS_ROLE
|
UNION
|
SELECT appid FROM SYS_ROLE WHERE roleid = #{roleId})
|
<if test="excludeGroupIds != null and excludeGroupIds.size() > 0">
|
AND og.groupid NOT IN
|
<foreach item="groupId" collection="excludeGroupIds" open="(" separator="," close=")">
|
#{groupId}
|
</foreach>
|
</if>
|
<if test="includeGroupIds != null">
|
<choose>
|
<when test="includeGroupIds.size() > 0">
|
AND og.groupid IN
|
<foreach item="groupId" collection="includeGroupIds" open="(" separator="," close=")">
|
#{groupId}
|
</foreach>
|
</when>
|
<otherwise>
|
AND og.groupid IN ('')
|
</otherwise>
|
</choose>
|
</if>
|
<if test="groupName != null and groupName != ''">
|
AND og.groupname LIKE ('%' || #{groupName} || '%')
|
</if>
|
<if test="groupNameWithSelected != null and groupNameWithSelected != ''">
|
AND og.groupname LIKE ('%' || #{groupNameWithSelected} || '%')
|
</if>
|
|
|
) B
|
) A
|
WHERE rownumber > #{lowerOffset} AND <![CDATA[ rownumber <= ${upperOffset} ]]>
|
|
</select>
|
|
<select id="findTotal" resultType="int">
|
SELECT
|
count(*)
|
FROM ORG_GROUP og
|
LEFT JOIN (
|
SELECT DISTINCT
|
A.groupid,
|
(SELECT STRING_AGG(cast(B.rolename as varchar),',')
|
FROM (SELECT srg.groupid, sr.rolename FROM SYS_ROLEGROUP srg
|
INNER JOIN SYS_ROLE sr ON srg.roleid = sr.roleid ) B
|
WHERE B.groupid = A.groupid group by A.groupid order by A.groupid) AS ROLES
|
FROM (
|
SELECT
|
srg.groupid,
|
sr.rolename
|
FROM SYS_ROLEGROUP srg
|
INNER JOIN SYS_ROLE sr ON srg.roleid = sr.roleid
|
) A
|
) b ON b.groupid = og.groupid
|
WHERE og.appid IN (SELECT 0 AS appid from SYS_ROLE
|
UNION
|
SELECT appid FROM SYS_ROLE WHERE roleid = #{roleId})
|
<if test="excludeGroupIds != null and excludeGroupIds.size() > 0">
|
AND og.groupid NOT IN
|
<foreach item="groupId" collection="excludeGroupIds" open="(" separator="," close=")">
|
#{groupId}
|
</foreach>
|
</if>
|
<if test="includeGroupIds != null">
|
<choose>
|
<when test="includeGroupIds.size() > 0">
|
AND og.groupid IN
|
<foreach item="groupId" collection="includeGroupIds" open="(" separator="," close=")">
|
#{groupId}
|
</foreach>
|
</when>
|
<otherwise>
|
AND og.groupid IN ('')
|
</otherwise>
|
</choose>
|
</if>
|
<if test="groupName != null and groupName != ''">
|
AND og.groupname LIKE ('%' || #{groupName} || '%')
|
</if>
|
<if test="groupNameWithSelected != null and groupNameWithSelected != ''">
|
AND og.groupname LIKE ('%' || #{groupNameWithSelected} || '%')
|
</if>
|
|
</select>
|
|
<select id="getGroupIdsByRoleId" resultType="java.lang.Long">
|
SELECT
|
srg.groupid
|
FROM SYS_ROLEGROUP srg
|
LEFT JOIN SYS_ROLE sr ON srg.roleid = sr.roleid
|
WHERE sr.roleid = #{roleId}
|
</select>
|
|
<select id="findRoleList" resultType="map">
|
SELECT roleid AS "roleId",
|
rolename AS "roleName"
|
FROM(
|
SELECT ROW_NUMBER() OVER(ORDER BY B.roleid) AS rownumber,B.*
|
FROM (
|
|
SELECT
|
og.roleid AS roleId,
|
og.rolename AS roleName
|
FROM SYS_ROLE og where 1=1
|
|
<if test="excludeRoleIds != null and excludeRoleIds.size() > 0">
|
AND og.roleid NOT IN
|
<foreach item="roleId" collection="excludeRoleIds" open="(" separator="," close=")">
|
#{roleId}
|
</foreach>
|
</if>
|
<if test="includeRoleIds != null">
|
<choose>
|
<when test="includeRoleIds.size() > 0">
|
AND og.roleid IN
|
<foreach item="roleId" collection="includeRoleIds" open="(" separator="," close=")">
|
#{roleId}
|
</foreach>
|
</when>
|
<otherwise>
|
AND og.roleid IN ('')
|
</otherwise>
|
</choose>
|
</if>
|
<if test="roleName != null and roleName != ''">
|
AND og.rolename LIKE ('%' || #{roleName} || '%')
|
</if>
|
<if test="roleNameWithSelected != null and roleNameWithSelected != ''">
|
AND og.rolename LIKE ('%' || #{roleNameWithSelected} || '%')
|
</if>
|
|
|
) B
|
) A
|
WHERE rownumber > #{lowerOffset} AND <![CDATA[ rownumber <= ${upperOffset} ]]>
|
</select>
|
|
<select id="findRoleTotal" resultType="int">
|
SELECT count(*) FROM SYS_ROLE og where 1=1
|
|
<if test="excludeRoleIds != null and excludeRoleIds.size() > 0">
|
AND og.roleid NOT IN
|
<foreach item="roleId" collection="excludeRoleIds" open="(" separator="," close=")">
|
#{roleId}
|
</foreach>
|
</if>
|
<if test="includeRoleIds != null">
|
<choose>
|
<when test="includeRoleIds.size() > 0">
|
AND og.roleid IN
|
<foreach item="roleId" collection="includeRoleIds" open="(" separator="," close=")">
|
#{roleId}
|
</foreach>
|
</when>
|
<otherwise>
|
AND og.roleid IN ('')
|
</otherwise>
|
</choose>
|
</if>
|
<if test="roleName != null and roleName != ''">
|
AND og.rolename LIKE ('%' || #{roleName} || '%')
|
</if>
|
<if test="roleNameWithSelected != null and roleNameWithSelected != ''">
|
AND og.rolename LIKE ('%' || #{roleNameWithSelected} || '%')
|
</if>
|
</select>
|
|
<select id="getRoleIdsByGroupId" resultType="java.lang.Long">
|
SELECT srg.roleid
|
FROM SYS_ROLEGROUP srg
|
WHERE srg.groupid = #{groupId}
|
</select>
|
|
<delete id="deleteBatchByRoleIdAndGroupIds">
|
DELETE FROM SYS_ROLEGROUP
|
WHERE
|
ROLEID = #{roleId}
|
AND groupid IN
|
<foreach item="groupId" collection="groupIds" open="(" separator="," close=")">
|
#{groupId}
|
</foreach>
|
</delete>
|
|
<delete id="deleteBatchByGroupId">
|
DELETE FROM SYS_ROLEGROUP WHERE groupid IN
|
<foreach item="groupId" collection="array" open="(" separator="," close=")">
|
#{groupId}
|
</foreach>
|
</delete>
|
</mapper>
|