|
@@ -2,187 +2,248 @@
|
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
<mapper namespace="org.jeecg.modules.system.mapper.SysUserMapper">
|
|
|
|
|
|
- <!-- 根据用户名查询 -->
|
|
|
- <select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
+ <!-- 根据用户名查询 -->
|
|
|
+ <select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
select * from sys_user where username = #{username} and del_flag = 0
|
|
|
</select>
|
|
|
|
|
|
- <!-- 根据部门Id查询 -->
|
|
|
- <select id="getUserByDepId" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
- select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_depart where dep_id=#{departId})
|
|
|
- <if test="username!=null and username!=''">
|
|
|
- and username = #{username}
|
|
|
- </if>
|
|
|
- </select>
|
|
|
-
|
|
|
- <!-- 查询用户的所属部门名称信息 -->
|
|
|
- <select id="getDepNamesByUserIds" resultType="org.jeecg.modules.system.vo.SysUserDepVo">
|
|
|
- select d.depart_name,ud.user_id from sys_user_depart ud,sys_depart d where d.id = ud.dep_id and ud.user_id in
|
|
|
- <foreach collection="userIds" index="index" item="id" open="(" separator="," close=")">
|
|
|
- #{id}
|
|
|
- </foreach>
|
|
|
- </select>
|
|
|
+ <!-- 根据部门Id查询 -->
|
|
|
+ <select id="getUserByDepId" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
+ select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_depart where
|
|
|
+ dep_id=#{departId})
|
|
|
+ <if test="username!=null and username!=''">
|
|
|
+ and username = #{username}
|
|
|
+ </if>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 查询用户的所属部门名称信息 -->
|
|
|
+ <select id="getDepNamesByUserIds" resultType="org.jeecg.modules.system.vo.SysUserDepVo">
|
|
|
+ select d.depart_name,ud.user_id from sys_user_depart ud,sys_depart d where d.id = ud.dep_id and ud.user_id in
|
|
|
+ <foreach collection="userIds" index="index" item="id" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </select>
|
|
|
|
|
|
- <!-- 通过多个部门IDS,查询部门下的用户信息 -->
|
|
|
- <select id="getUserByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
- select * from sys_user where del_flag = 0
|
|
|
- <if test="departIds!=null and departIds.size()>0">
|
|
|
- and id in (select user_id from sys_user_depart where dep_id in
|
|
|
- <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
|
|
|
- #{id}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
- </if>
|
|
|
- <if test="username!=null and username!=''">
|
|
|
- and username = #{username}
|
|
|
- </if>
|
|
|
- </select>
|
|
|
-
|
|
|
- <!-- 根据角色Id查询 -->
|
|
|
- <select id="getUserByRoleId" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
- select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_role where role_id=#{roleId})
|
|
|
- <if test="username!=null and username!=''">
|
|
|
- and username = #{username}
|
|
|
- </if>
|
|
|
- </select>
|
|
|
-
|
|
|
- <!-- 修改用户部门code -->
|
|
|
- <update id="updateUserDepart">
|
|
|
+ <!-- 通过多个部门IDS,查询部门下的用户信息 -->
|
|
|
+ <select id="getUserByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
+ select * from sys_user where del_flag = 0
|
|
|
+ <if test="departIds!=null and departIds.size()>0">
|
|
|
+ and id in (select user_id from sys_user_depart where dep_id in
|
|
|
+ <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <if test="username!=null and username!=''">
|
|
|
+ and username = #{username}
|
|
|
+ </if>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 根据角色Id查询 -->
|
|
|
+ <select id="getUserByRoleId" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
+ select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_role where role_id=#{roleId})
|
|
|
+ <if test="username!=null and username!=''">
|
|
|
+ and username = #{username}
|
|
|
+ </if>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 修改用户部门code -->
|
|
|
+ <update id="updateUserDepart">
|
|
|
UPDATE sys_user SET org_code = #{orgCode} where username = #{username}
|
|
|
</update>
|
|
|
|
|
|
- <!-- 根据手机号查询 -->
|
|
|
- <select id="getUserByPhone" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
+ <!-- 根据手机号查询 -->
|
|
|
+ <select id="getUserByPhone" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
select * from sys_user where phone = #{phone} and del_flag = 0
|
|
|
</select>
|
|
|
|
|
|
- <!-- 根据邮箱查询用户信息 -->
|
|
|
- <select id="getUserByEmail" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
+ <!-- 根据邮箱查询用户信息 -->
|
|
|
+ <select id="getUserByEmail" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
select * from sys_user where email = #{email} and del_flag = 0
|
|
|
</select>
|
|
|
|
|
|
- <!-- SQL片段:getUserByOrgCode 的 FROM 和 WHERE 部分 -->
|
|
|
- <sql id="getUserByOrgCodeFromSql">
|
|
|
- FROM
|
|
|
- sys_depart
|
|
|
- INNER JOIN sys_user_depart ON sys_user_depart.dep_id = sys_depart.id
|
|
|
- INNER JOIN sys_user ON sys_user.id = sys_user_depart.user_id
|
|
|
- WHERE
|
|
|
- <if test="orgCode == null">
|
|
|
- <bind name="bindOrgCode" value="'%'"/>
|
|
|
- </if>
|
|
|
- <if test="orgCode != null">
|
|
|
- <bind name="bindOrgCode" value="orgCode+'%'"/>
|
|
|
- </if>
|
|
|
- sys_user.del_flag = 0 AND sys_depart.org_code LIKE #{bindOrgCode}
|
|
|
-
|
|
|
- <if test="userParams != null">
|
|
|
- <if test="userParams.realname != null and userParams.realname != ''">
|
|
|
- AND sys_user.realname LIKE concat(concat('%',#{userParams.realname}),'%')
|
|
|
- </if>
|
|
|
- <if test="userParams.workNo != null and userParams.workNo != ''">
|
|
|
- AND sys_user.work_no LIKE concat(concat('%',#{userParams.workNo}),'%')
|
|
|
- </if>
|
|
|
- </if>
|
|
|
- </sql>
|
|
|
-
|
|
|
- <!-- 根据 orgCode 查询用户,包括子部门下的用户 -->
|
|
|
- <select id="getUserByOrgCode" resultType="org.jeecg.modules.system.model.SysUserSysDepartModel">
|
|
|
- SELECT
|
|
|
- sys_user.id AS id,
|
|
|
- sys_user.realname AS realname,
|
|
|
- sys_user.avatar AS avatar,
|
|
|
- sys_user.sex AS sex,
|
|
|
- sys_user.birthday AS birthday,
|
|
|
- sys_user.work_no AS workNo,
|
|
|
- sys_user.post AS post,
|
|
|
- sys_user.telephone AS telephone,
|
|
|
- sys_user.email AS email,
|
|
|
- sys_user.phone AS phone,
|
|
|
- sys_depart.id AS departId,
|
|
|
- sys_depart.depart_name AS departName
|
|
|
- <include refid="getUserByOrgCodeFromSql"/>
|
|
|
- ORDER BY
|
|
|
- sys_depart.org_code ASC
|
|
|
- </select>
|
|
|
-
|
|
|
- <!-- 查询 getUserByOrgCode 的总数-->
|
|
|
- <select id="getUserByOrgCodeTotal" resultType="java.lang.Integer">
|
|
|
- SELECT COUNT(1) <include refid="getUserByOrgCodeFromSql"/>
|
|
|
- </select>
|
|
|
-
|
|
|
- <!-- 批量删除角色的与用户关系-->
|
|
|
- <update id="deleteBathRoleUserRelation">
|
|
|
- delete from sys_user_role
|
|
|
- where role_id in
|
|
|
- <foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
|
|
|
- #{id}
|
|
|
- </foreach>
|
|
|
- </update>
|
|
|
- <!-- 批量删除角色的与权限关系-->
|
|
|
- <update id="deleteBathRolePermissionRelation">
|
|
|
- delete from sys_role_permission
|
|
|
- where role_id in
|
|
|
- <foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
|
|
|
- #{id}
|
|
|
- </foreach>
|
|
|
- </update>
|
|
|
-
|
|
|
- <!-- 查询被逻辑删除的用户 -->
|
|
|
- <select id="selectLogicDeleted" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
+ <!-- SQL片段:getUserByOrgCode 的 FROM 和 WHERE 部分 -->
|
|
|
+ <sql id="getUserByOrgCodeFromSql">
|
|
|
+ FROM
|
|
|
+ sys_depart
|
|
|
+ INNER JOIN sys_user_depart ON sys_user_depart.dep_id = sys_depart.id
|
|
|
+ INNER JOIN sys_user ON sys_user.id = sys_user_depart.user_id
|
|
|
+ WHERE
|
|
|
+ <if test="orgCode == null">
|
|
|
+ <bind name="bindOrgCode" value="'%'"/>
|
|
|
+ </if>
|
|
|
+ <if test="orgCode != null">
|
|
|
+ <bind name="bindOrgCode" value="orgCode+'%'"/>
|
|
|
+ </if>
|
|
|
+ sys_user.del_flag = 0 AND sys_depart.org_code LIKE #{bindOrgCode}
|
|
|
+
|
|
|
+ <if test="userParams != null">
|
|
|
+ <if test="userParams.realname != null and userParams.realname != ''">
|
|
|
+ AND sys_user.realname LIKE concat(concat('%',#{userParams.realname}),'%')
|
|
|
+ </if>
|
|
|
+ <if test="userParams.workNo != null and userParams.workNo != ''">
|
|
|
+ AND sys_user.work_no LIKE concat(concat('%',#{userParams.workNo}),'%')
|
|
|
+ </if>
|
|
|
+ </if>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!-- 根据 orgCode 查询用户,包括子部门下的用户 -->
|
|
|
+ <select id="getUserByOrgCode" resultType="org.jeecg.modules.system.model.SysUserSysDepartModel">
|
|
|
+ SELECT
|
|
|
+ sys_user.id AS id,
|
|
|
+ sys_user.realname AS realname,
|
|
|
+ sys_user.avatar AS avatar,
|
|
|
+ sys_user.sex AS sex,
|
|
|
+ sys_user.birthday AS birthday,
|
|
|
+ sys_user.work_no AS workNo,
|
|
|
+ sys_user.post AS post,
|
|
|
+ sys_user.telephone AS telephone,
|
|
|
+ sys_user.email AS email,
|
|
|
+ sys_user.phone AS phone,
|
|
|
+ sys_depart.id AS departId,
|
|
|
+ sys_depart.depart_name AS departName
|
|
|
+ <include refid="getUserByOrgCodeFromSql"/>
|
|
|
+ ORDER BY
|
|
|
+ sys_depart.org_code ASC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 查询 getUserByOrgCode 的总数-->
|
|
|
+ <select id="getUserByOrgCodeTotal" resultType="java.lang.Integer">
|
|
|
+ SELECT COUNT(1)
|
|
|
+ <include refid="getUserByOrgCodeFromSql"/>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 批量删除角色的与用户关系-->
|
|
|
+ <update id="deleteBathRoleUserRelation">
|
|
|
+ delete from sys_user_role
|
|
|
+ where role_id in
|
|
|
+ <foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </update>
|
|
|
+ <!-- 批量删除角色的与权限关系-->
|
|
|
+ <update id="deleteBathRolePermissionRelation">
|
|
|
+ delete from sys_role_permission
|
|
|
+ where role_id in
|
|
|
+ <foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <!-- 查询被逻辑删除的用户 -->
|
|
|
+ <select id="selectLogicDeleted" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
SELECT * FROM sys_user ${ew.customSqlSegment}
|
|
|
</select>
|
|
|
|
|
|
- <!-- 更新被逻辑删除的用户 -->
|
|
|
- <update id="revertLogicDeleted">
|
|
|
- UPDATE
|
|
|
- sys_user
|
|
|
- SET
|
|
|
- del_flag = 0,
|
|
|
- update_by = #{entity.updateBy},
|
|
|
- update_time = #{entity.updateTime}
|
|
|
- WHERE
|
|
|
- del_flag = 1
|
|
|
- AND id IN
|
|
|
- <foreach collection="userIds" item="userId" open="(" close=")" separator="," >
|
|
|
- #{userId}
|
|
|
- </foreach>
|
|
|
- </update>
|
|
|
-
|
|
|
- <!-- 彻底删除被逻辑删除的用户 -->
|
|
|
- <delete id="deleteLogicDeleted">
|
|
|
- DELETE FROM sys_user WHERE del_flag = 1 AND id IN
|
|
|
- <foreach collection="userIds" item="userId" open="(" close=")" separator="," >
|
|
|
- #{userId}
|
|
|
- </foreach>
|
|
|
- </delete>
|
|
|
-
|
|
|
- <!-- 更新空字符串为null -->
|
|
|
- <update id="updateNullByEmptyString">
|
|
|
- UPDATE sys_user
|
|
|
- <if test="fieldName == 'email'">
|
|
|
- SET email = NULL WHERE email = ''
|
|
|
- </if>
|
|
|
- <if test="fieldName == 'phone'">
|
|
|
- SET phone = NULL WHERE phone = ''
|
|
|
- </if>
|
|
|
- </update>
|
|
|
- <update id="updateStatus">
|
|
|
- update sys_depart set status = 0 where update_time < #{startDate} > #{endDate}
|
|
|
- </update>
|
|
|
+ <!-- 更新被逻辑删除的用户 -->
|
|
|
+ <update id="revertLogicDeleted">
|
|
|
+ UPDATE
|
|
|
+ sys_user
|
|
|
+ SET
|
|
|
+ del_flag = 0,
|
|
|
+ update_by = #{entity.updateBy},
|
|
|
+ update_time = #{entity.updateTime}
|
|
|
+ WHERE
|
|
|
+ del_flag = 1
|
|
|
+ AND id IN
|
|
|
+ <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
+ #{userId}
|
|
|
+ </foreach>
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <!-- 彻底删除被逻辑删除的用户 -->
|
|
|
+ <delete id="deleteLogicDeleted">
|
|
|
+ DELETE FROM sys_user WHERE del_flag = 1 AND id IN
|
|
|
+ <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
+ #{userId}
|
|
|
+ </foreach>
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <!-- 更新空字符串为null -->
|
|
|
+ <update id="updateNullByEmptyString">
|
|
|
+ UPDATE sys_user
|
|
|
+ <if test="fieldName == 'email'">
|
|
|
+ SET email = NULL WHERE email = ''
|
|
|
+ </if>
|
|
|
+ <if test="fieldName == 'phone'">
|
|
|
+ SET phone = NULL WHERE phone = ''
|
|
|
+ </if>
|
|
|
+ </update>
|
|
|
|
|
|
<!-- 通过多个部门IDS,查询部门下的用户信息 -->
|
|
|
- <select id="queryByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
- select * from sys_user where del_flag = 0
|
|
|
- <if test="departIds!=null and departIds.size()>0">
|
|
|
- and id in (select user_id from sys_user_depart where dep_id in
|
|
|
- <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
|
|
|
- #{id}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
- </if>
|
|
|
- <if test="username!=null and username!=''">
|
|
|
- and username != #{username}
|
|
|
- </if>
|
|
|
- </select>
|
|
|
+ <select id="queryByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
|
|
|
+ select * from sys_user where del_flag = 0
|
|
|
+ <if test="departIds!=null and departIds.size()>0">
|
|
|
+ and id in (select user_id from sys_user_depart where dep_id in
|
|
|
+ <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <if test="username!=null and username!=''">
|
|
|
+ and username != #{username}
|
|
|
+ </if>
|
|
|
+ </select>
|
|
|
+
|
|
|
+
|
|
|
+<!-- <insert id="insertOrUpdate" parameterType="org.jeecg.modules.system.entity.SysUser">-->
|
|
|
+<!-- insert into sys_user-->
|
|
|
+<!-- (id,username,realname,password,salt,avatar,birthday,sex,email,phone,org_code,status,del_flag,third_id,third_type,activiti_sync,work_no,post,telephone,create_by-->
|
|
|
+<!-- ,create_time,update_by,update_time,user_identity,depart_ids,rel_tenant_ids,client_id)-->
|
|
|
+<!-- <trim prefix="values (" suffix=")" suffixOverrides=",">-->
|
|
|
+<!-- <if test="sysUser.id != null">#{sysUser.id},</if>-->
|
|
|
+<!-- <if test="sysUser.username != null">#{sysUser.username},</if>-->
|
|
|
+<!-- <if test="sysUser.realname != null">#{sysUser.realname},</if>-->
|
|
|
+<!-- <if test="sysUser.password != null">#{sysUser.password},</if>-->
|
|
|
+<!-- <if test="sysUser.salt != null">#{sysUser.salt},</if>-->
|
|
|
+<!-- <if test="sysUser.avatar != null">#{sysUser.avatar},</if>-->
|
|
|
+<!-- <if test="sysUser.birthday != null">#{sysUser.birthday},</if>-->
|
|
|
+<!-- <if test="sysUser.sex != null">#{sysUser.sex},</if>-->
|
|
|
+<!-- <if test="sysUser.email != null">#{sysUser.email},</if>-->
|
|
|
+<!-- <if test="sysUser.phone != null">#{sysUser.phone},</if>-->
|
|
|
+<!-- <if test="sysUser.orgCode != null">#{sysUser.orgCode},</if>-->
|
|
|
+<!-- <if test="sysUser.status != null">#{sysUser.status},</if>-->
|
|
|
+<!-- <if test="sysUser.delFlag != null">#{sysUser.delFlag},</if>-->
|
|
|
+<!-- null,-->
|
|
|
+<!-- null,-->
|
|
|
+<!-- <if test="sysUser.activitiSync != null">#{sysUser.activitiSync},</if>-->
|
|
|
+<!-- <if test="sysUser.workNo != null">#{sysUser.workNo},</if>-->
|
|
|
+<!-- <if test="sysUser.post != null">#{sysUser.post},</if>-->
|
|
|
+<!-- <if test="sysUser.telephone != null">#{sysUser.telephone},</if>-->
|
|
|
+<!-- <if test="sysUser.createBy != null">#{sysUser.createBy},</if>-->
|
|
|
+<!-- <if test="sysUser.createTime != null">#{sysUser.createTime},</if>-->
|
|
|
+<!-- <if test="sysUser.updateBy != null">#{sysUser.updateBy},</if>-->
|
|
|
+<!-- <if test="sysUser.updateTime != null">#{sysUser.updateTime},</if>-->
|
|
|
+<!-- <if test="sysUser.userIdentity != null">#{sysUser.userIdentity},</if>-->
|
|
|
+<!-- <if test="sysUser.departIds != null">#{sysUser.departIds},</if>-->
|
|
|
+<!-- <if test="sysUser.relTenantIds != null">#{sysUser.relTenantIds},</if>-->
|
|
|
+<!-- <if test="sysUser.clientId != null">#{sysUser.clientId},</if>-->
|
|
|
+<!-- </trim>-->
|
|
|
+<!-- ON DUPLICATE KEY UPDATE-->
|
|
|
+<!-- username = VALUES(username),-->
|
|
|
+<!-- realname = VALUES(realname),-->
|
|
|
+<!-- password = VALUES(password),-->
|
|
|
+<!-- salt = VALUES(salt),-->
|
|
|
+<!-- avatar = VALUES(avatar),-->
|
|
|
+<!-- birthday = VALUES(birthday),-->
|
|
|
+<!-- sex = VALUES(sex),-->
|
|
|
+<!-- email = VALUES(email),-->
|
|
|
+<!-- phone = VALUES(phone),-->
|
|
|
+<!-- org_code = VALUES(org_code),-->
|
|
|
+<!-- status = VALUES(status),-->
|
|
|
+<!-- del_flag = VALUES(del_flag),-->
|
|
|
+<!-- activiti_sync = VALUES(activiti_sync),-->
|
|
|
+<!-- work_no = VALUES(work_no),-->
|
|
|
+<!-- post = VALUES(post),-->
|
|
|
+<!-- telephone = VALUES(telephone),-->
|
|
|
+<!-- create_by = VALUES(create_by),-->
|
|
|
+<!-- create_time = VALUES(create_time),-->
|
|
|
+<!-- update_by = VALUES(update_by),-->
|
|
|
+<!-- update_time = VALUES(update_time),-->
|
|
|
+<!-- user_identity = VALUES(user_identity),-->
|
|
|
+<!-- depart_ids = VALUES(depart_ids),-->
|
|
|
+<!-- rel_tenant_ids = VALUES(rel_tenant_ids),-->
|
|
|
+<!-- client_id = VALUES(client_id),-->
|
|
|
+<!-- </insert>-->
|
|
|
+
|
|
|
</mapper>
|