<?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.org.dao.OrgUserGroupDao">
|
|
<!-- 可根据自己的需求,是否要使用 -->
|
<resultMap type="com.landtool.lanbase.modules.org.entity.OrgUserGroup" id="usergroupMap">
|
<result property="userId" column="userid"/>
|
<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.org.entity.OrgUserGroup">
|
select * from ORG_USERGROUP where userid = #{value}
|
</select>
|
|
<select id="queryList" resultType="com.landtool.lanbase.modules.org.entity.OrgUserGroup">
|
|
SELECT *
|
FROM(
|
SELECT ROW_NUMBER() OVER(ORDER BY B.userid) AS rownumber,B.*
|
FROM (
|
|
select * from ORG_USERGROUP
|
|
) B
|
) A
|
WHERE rownumber > #{lowerOffset} AND <![CDATA[ rownumber <= ${upperOffset} ]]>
|
</select>
|
|
<select id="queryTotal" resultType="int">
|
select count(*) from ORG_USERGROUP
|
</select>
|
|
<select id="queryListForUserJoinUnitWithRoles" resultType="map">
|
|
SELECT USERID "userId",
|
LOGINNAME "loginName",
|
CHINESENAME "chineseName",
|
USERSTATUS "userStatus",
|
GROUPS "groups",
|
UNITNAMES "unitNames",
|
UNITTYPE "unitType"
|
FROM(
|
SELECT ROW_NUMBER() OVER(ORDER BY B.USERID) AS rownumber,B.*
|
FROM (
|
|
SELECT
|
ou.USERID AS userId,
|
ou.LOGINNAME AS loginName,
|
ou.CHINESENAME AS chineseName,
|
ou.USERSTATUS AS userStatus,
|
b.GROUPS AS groups,
|
b2.UNITNAMES AS unitNames,
|
b2.UNITTYPES AS unitType
|
FROM ORG_USER ou
|
LEFT JOIN (
|
SELECT DISTINCT
|
A.userid,
|
(SELECT STRING_AGG(cast(B.groupname as varchar),',') FROM (
|
SELECT
|
oug.userid,og.groupname
|
FROM ORG_USERGROUP oug
|
LEFT JOIN ORG_GROUP og ON oug.groupid = og.groupid
|
) B
|
WHERE B.userid = A.userid group by A.userid order by A.userid) AS GROUPS
|
FROM (
|
SELECT
|
oug.userid,og.groupname
|
FROM ORG_USERGROUP oug
|
LEFT JOIN ORG_GROUP og ON oug.groupid = og.groupid
|
) A
|
) b ON b.userid = ou.userid
|
LEFT JOIN (
|
SELECT distinct A.userid,C.unitname AS UNITNAMES,
|
(SELECT STRING_AGG(cast(B.unittype as varchar),',') FROM (
|
SELECT
|
ouu.userid,ou.unittype
|
FROM ORG_USERUNIT ouu
|
LEFT JOIN ORG_UNIT ou ON ouu.unitid = ou.unitid
|
) B WHERE B.userid = A.userid group by A.userid order by A.userid) as UNITTYPES
|
FROM (
|
SELECT
|
ouu.userid,ou.unittype
|
FROM ORG_USERUNIT ouu
|
LEFT JOIN ORG_UNIT ou ON ouu.unitid = ou.unitid
|
)A
|
LEFT JOIN (
|
SELECT
|
ouu.userid,max(ou.unitname) AS unitname ,max(ou.rcreatedate) AS currentdate
|
FROM ORG_USERUNIT ouu
|
LEFT JOIN ORG_UNIT ou ON ouu.unitid = ou.unitid
|
GROUP BY ouu.userid
|
)C ON A.userid = C.userid
|
) b2 ON b2.userid = ou.userid
|
<where>
|
<if test="excludeUserIds != null ">
|
ou.userstatus = 0
|
<choose>
|
<when test="excludeUserIds.size() > 0" >
|
AND ou.userid NOT IN
|
<foreach item="userId" collection="excludeUserIds" open="(" separator="," close=")">
|
#{userId}
|
</foreach>
|
</when>
|
</choose>
|
</if>
|
<if test="includeUserIds != null">
|
<choose>
|
<when test="includeUserIds.size() > 0">
|
AND ou.userid IN
|
<foreach item="userId" collection="includeUserIds" open="(" separator="," close=")">
|
#{userId}
|
</foreach>
|
</when>
|
<otherwise>
|
AND ou.userid IN ('')
|
</otherwise>
|
</choose>
|
</if>
|
<if test="userName != null and userName != ''">
|
AND (ou.LOGINNAME LIKE ('%'|| #{userName} ||'%') or ou.CHINESENAME LIKE ('%'|| #{userName} ||'%') or LOWER(ou.spellfirst) LIKE ('%'|| LOWER(#{userName}) ||'%'))
|
</if>
|
<if test="userNameWithSelected != null and userNameWithSelected != ''">
|
AND (ou.LOGINNAME LIKE ('%'|| #{userNameWithSelected} ||'%') or ou.CHINESENAME LIKE ('%'|| #{userNameWithSelected} ||'%') or LOWER(ou.spellfirst) LIKE ('%'|| LOWER(#{userNameWithSelected}) ||'%'))
|
</if>
|
<if test="unitType != null and unitType != ''">
|
AND b2.UNITTYPES LIKE ('%'|| #{unitType} ||'%')
|
</if>
|
</where>
|
|
) B
|
) A
|
WHERE rownumber > #{lowerOffset} AND <![CDATA[ rownumber <= ${upperOffset} ]]>
|
</select>
|
|
<select id="queryTotalOfListForUserJoinUnitWithRoles" resultType="int">
|
SELECT
|
count(*)
|
FROM ORG_USER ou
|
LEFT JOIN (
|
SELECT DISTINCT
|
A.userid,
|
(SELECT STRING_AGG(cast(B.groupname as varchar),',') FROM (
|
SELECT
|
oug.userid,og.groupname
|
FROM ORG_USERGROUP oug
|
LEFT JOIN ORG_GROUP og ON oug.groupid = og.groupid
|
) B
|
WHERE B.userid = A.userid group by A.userid order by A.userid) AS GROUPS
|
FROM (
|
SELECT
|
oug.userid,og.groupname
|
FROM ORG_USERGROUP oug
|
LEFT JOIN ORG_GROUP og ON oug.groupid = og.groupid
|
) A
|
) b ON b.userid = ou.userid
|
LEFT JOIN (
|
SELECT distinct A.userid,C.unitname AS UNITNAMES,
|
(SELECT STRING_AGG(cast(B.unittype as varchar),',') FROM (
|
SELECT
|
ouu.userid,ou.unittype
|
FROM ORG_USERUNIT ouu
|
LEFT JOIN ORG_UNIT ou ON ouu.unitid = ou.unitid
|
) B WHERE B.userid = A.userid group by A.userid order by A.userid) as UNITTYPES
|
FROM (
|
SELECT
|
ouu.userid,ou.unittype
|
FROM ORG_USERUNIT ouu
|
LEFT JOIN ORG_UNIT ou ON ouu.unitid = ou.unitid
|
)A
|
LEFT JOIN (
|
SELECT
|
ouu.userid,max(ou.unitname) AS unitname,max(ou.rcreatedate) AS currentdate
|
FROM ORG_USERUNIT ouu
|
LEFT JOIN ORG_UNIT ou ON ouu.unitid = ou.unitid
|
GROUP BY ouu.userid
|
)C ON A.userid = C.userid
|
) b2 ON b2.userid = ou.userid
|
<where>
|
<if test="excludeUserIds != null ">
|
ou.userstatus = 0
|
<choose>
|
<when test="excludeUserIds.size() > 0" >
|
AND ou.userid NOT IN
|
<foreach item="userId" collection="excludeUserIds" open="(" separator="," close=")">
|
#{userId}
|
</foreach>
|
</when>
|
</choose>
|
</if>
|
<if test="includeUserIds != null">
|
<choose>
|
<when test="includeUserIds.size() > 0">
|
AND ou.userid IN
|
<foreach item="userId" collection="includeUserIds" open="(" separator="," close=")">
|
#{userId}
|
</foreach>
|
</when>
|
<otherwise>
|
AND ou.userid IN ('')
|
</otherwise>
|
</choose>
|
</if>
|
<if test="userName != null and userName != ''">
|
AND (ou.LOGINNAME LIKE ('%'|| #{userName} ||'%') or ou.chinesename LIKE ('%'|| #{userName} ||'%') or LOWER(ou.spellfirst) LIKE ('%'|| LOWER(#{userName}) ||'%'))
|
</if>
|
<if test="userNameWithSelected != null and userNameWithSelected != ''">
|
AND (ou.LOGINNAME LIKE ('%'|| #{userNameWithSelected} ||'%') or ou.chinesename LIKE ('%'|| #{userNameWithSelected} ||'%') or LOWER(ou.spellfirst) LIKE ('%'|| LOWER(#{userNameWithSelected}) ||'%'))
|
</if>
|
<if test="unitType != null and unitType != ''">
|
AND b2.UNITTYPES LIKE ('%'|| #{unitType} ||'%')
|
</if>
|
</where>
|
</select>
|
|
<insert id="save" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserGroup">
|
insert into ORG_USERGROUP
|
(
|
userid,
|
groupid,
|
createunitid,
|
rcreatedate,
|
rcreateuser
|
)
|
values
|
(
|
#{userId},
|
#{groupId},
|
#{createUnitId},
|
#{rCreateDate},
|
#{rCreateUser}
|
)
|
</insert>
|
|
<update id="update" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserGroup">
|
update ORG_USERGROUP
|
<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 userid = #{userId}
|
</update>
|
|
<delete id="delete">
|
delete from ORG_USERGROUP where userid = #{value}
|
</delete>
|
|
<delete id="deleteBatchByGroupIdAndUserIds">
|
DELETE FROM ORG_USERGROUP
|
WHERE
|
groupid = #{groupId}
|
AND userid IN
|
<foreach item="userId" collection="userIds" open="(" separator="," close=")">
|
#{userId}
|
</foreach>
|
</delete>
|
|
<delete id="deleteBatch">
|
delete from ORG_USERGROUP where userid in
|
<foreach item="userId" collection="array" open="(" separator="," close=")">
|
#{userId}
|
</foreach>
|
</delete>
|
|
<select id="getUserIdsByGroupId" resultType="java.lang.Long">
|
SELECT
|
ou.userid
|
FROM ORG_USERGROUP oug
|
LEFT JOIN ORG_USER ou ON ou.userid = oug.userid
|
WHERE oug.groupid = #{groupId}
|
</select>
|
|
<delete id="deleteBatchByGroupId">
|
DELETE FROM ORG_USERGROUP WHERE groupid IN
|
<foreach item="groupId" collection="array" open="(" separator="," close=")">
|
#{groupId}
|
</foreach>
|
</delete>
|
</mapper>
|