From 7de1396e315896dbc72a9d54e44f77434ea90f18 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期日, 14 十二月 2025 23:47:34 +0800
Subject: [PATCH] feat:增加企业微信自动登录

---
 ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml |  114 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 74 insertions(+), 40 deletions(-)

diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
index b2b0c02..bdd74b3 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
@@ -19,11 +19,18 @@
         <result property="loginIp"      column="login_ip"     />
         <result property="loginDate"    column="login_date"   />
         <result property="oaUserId"     column="oa_user_id"   />
+        <result property="oaOrderClass" column="oa_order_class" />
         <result property="createBy"     column="create_by"    />
         <result property="createTime"   column="create_time"  />
         <result property="updateBy"     column="update_by"    />
         <result property="updateTime"   column="update_time"  />
         <result property="remark"       column="remark"       />
+        <result property="openId"       column="open_id"       />
+        <result property="unionId"     column="union_id"     />
+        <result property="wechatNickname" column="wechat_nickname" />
+        <result property="qyWechatUserId" column="qy_wechat_user_id" />
+        <result property="qyWechatUpdateTime" column="qy_wechat_update_time" />
+        <result property="canViewAllConsult" column="can_view_all_consult" />
         <association property="dept"    javaType="SysDept"         resultMap="deptResult" />
         <collection  property="roles"   javaType="java.util.List"  resultMap="RoleResult" />
     </resultMap>
@@ -48,7 +55,7 @@
     </resultMap>
 	
 	<sql id="selectUserVo">
-        select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.oa_user_id, u.create_by, u.create_time, u.remark, 
+        select u.user_id, u.dept_id, u.user_name,u.oa_user_id, u.oa_order_class, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.oa_user_id, u.create_by, u.create_time, u.remark,u.open_id,u.union_id,u.wechat_nickname,u.qy_wechat_user_id,u.qy_wechat_update_time,u.can_view_all_consult,
         d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
         r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
         from sys_user u
@@ -80,44 +87,11 @@
 			AND date_format(u.create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
 		</if>
 		<if test="deptId != null and deptId != 0">
-			<![CDATA[
-			AND u.dept_id IN (
-				-- 鏌ヨ鐢ㄦ埛鎵�灞炲垎鍏徃鍙婂叾鎵�鏈夊瓙閮ㄩ棬
-				SELECT t.dept_id FROM sys_dept t 
-				WHERE t.del_flag = '0' AND (
-					-- 鎯呭喌1锛氫紶鍏ョ殑閮ㄩ棬灏辨槸鍒嗗叕鍙�(parent_id=100)
-					(t.dept_id = ]]>#{deptId}<![CDATA[ AND EXISTS (
-						SELECT 1 FROM sys_dept d WHERE d.dept_id = ]]>#{deptId}<![CDATA[ AND d.parent_id = 100
-					))
-					OR
-					-- 鏌ヨ璇ュ垎鍏徃鐨勬墍鏈夊瓙閮ㄩ棬
-					(find_in_set(
-						(SELECT d.dept_id FROM sys_dept d WHERE d.dept_id = ]]>#{deptId}<![CDATA[ AND d.parent_id = 100),
-						t.ancestors
-					) > 0)
-					OR
-					-- 鎯呭喌2锛氫紶鍏ョ殑鏄瓙閮ㄩ棬锛屾壘鍒板叾鎵�灞炲垎鍏徃
-					(t.dept_id IN (
-						SELECT branch.dept_id FROM sys_dept branch
-						WHERE branch.parent_id = 100
-						  AND find_in_set(branch.dept_id, (
-							SELECT sub.ancestors FROM sys_dept sub WHERE sub.dept_id = ]]>#{deptId}<![CDATA[
-						  )) > 0
-					))
-					OR
-					-- 鏌ヨ璇ュ垎鍏徃鐨勬墍鏈夊瓙閮ㄩ棬
-					(find_in_set(
-						(SELECT branch.dept_id FROM sys_dept branch
-						 WHERE branch.parent_id = 100
-						   AND find_in_set(branch.dept_id, (
-							 SELECT sub.ancestors FROM sys_dept sub WHERE sub.dept_id = ]]>#{deptId}<![CDATA[
-						   )) > 0
-						),
-						t.ancestors
-					) > 0)
-				)
-			)
-			]]>
+			-- 鏌ヨ鎸囧畾閮ㄩ棬鍙婂叾鎵�鏈夊瓙閮ㄩ棬鐨勭敤鎴�
+			AND (u.dept_id = #{deptId} OR u.dept_id IN (
+				SELECT dept_id FROM sys_dept
+				WHERE del_flag = '0' AND find_in_set(#{deptId}, ancestors) > 0
+			))
 		</if>
 		<!-- 鏁版嵁鑼冨洿杩囨护 -->
 		${params.dataScope}
@@ -162,7 +136,11 @@
 	    <include refid="selectUserVo"/>
 		where u.user_name = #{userName} and u.del_flag = '0'
 	</select>
-	
+    <select id="selectUserByPhonenumber" parameterType="String" resultMap="SysUserResult">
+        <include refid="selectUserVo"/>
+        where u.phonenumber = #{phonenumber} and u.del_flag = '0'
+    </select>
+
 	<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
 		<include refid="selectUserVo"/>
 		where u.user_id = #{userId}
@@ -193,6 +171,9 @@
  			<if test="password != null and password != ''">password,</if>
  			<if test="status != null and status != ''">status,</if>
  			<if test="oaUserId != null">oa_user_id,</if>
+ 			<if test="oaOrderClass != null and oaOrderClass != ''">oa_order_class,</if>
+ 			<if test="qyWechatUserId != null and qyWechatUserId != ''">qy_wechat_user_id,</if>
+ 			<if test="qyWechatUpdateTime != null">qy_wechat_update_time,</if>
  			<if test="createBy != null and createBy != ''">create_by,</if>
  			<if test="remark != null and remark != ''">remark,</if>
  			create_time
@@ -208,6 +189,10 @@
  			<if test="password != null and password != ''">#{password},</if>
  			<if test="status != null and status != ''">#{status},</if>
  			<if test="oaUserId != null">#{oaUserId},</if>
+ 			<if test="oaOrderClass != null and oaOrderClass != ''">#{oaOrderClass},</if>
+ 			<if test="canViewAllConsult != null and canViewAllConsult != ''">#{canViewAllConsult},</if>
+ 			<if test="qyWechatUserId != null and qyWechatUserId != ''">#{qyWechatUserId},</if>
+ 			<if test="qyWechatUpdateTime != null">#{qyWechatUpdateTime},</if>
  			<if test="createBy != null and createBy != ''">#{createBy},</if>
  			<if test="remark != null and remark != ''">#{remark},</if>
  			sysdate()
@@ -226,6 +211,12 @@
  			<if test="password != null and password != ''">password = #{password},</if>
  			<if test="status != null and status != ''">status = #{status},</if>
  			<if test="oaUserId != null">oa_user_id = #{oaUserId},</if>
+ 			<if test="oaOrderClass != null">oa_order_class = #{oaOrderClass},</if>
+ 			<if test="canViewAllConsult != null and canViewAllConsult != ''">can_view_all_consult = #{canViewAllConsult},</if>
+ 			<if test="qyWechatUserId != null and qyWechatUserId != ''">qy_wechat_user_id = #{qyWechatUserId},</if>
+ 			<if test="qyWechatUpdateTime != null">qy_wechat_update_time = #{qyWechatUpdateTime},</if>
+ 			<if test="openId != null and openId != ''">open_id = #{openId},</if>
+ 			<if test="unionId != null and unionId != ''">union_id = #{unionId},</if>
  			<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  			<if test="loginDate != null">login_date = #{loginDate},</if>
  			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
@@ -266,4 +257,47 @@
 		limit 1
 	</select>
 	
+	<!-- 閫氳繃寰俊OpenID鏌ヨ鐢ㄦ埛 -->
+	<select id="selectUserByOpenId" parameterType="String" resultMap="SysUserResult">
+		<include refid="selectUserVo"/>
+		where u.open_id = #{openId} and u.del_flag = '0'
+	</select>
+	
+	<!-- 閫氳繃浼佷笟寰俊鐢ㄦ埛ID鏌ヨ鐢ㄦ埛 -->
+	<select id="selectUserByQyWechatUserId" parameterType="String" resultMap="SysUserResult">
+		<include refid="selectUserVo"/>
+		where u.qy_wechat_user_id = #{qyWechatUserId} and u.del_flag = '0'
+	</select>
+	
+	<!-- 鏍规嵁鍒嗗叕鍙窱D鍒楄〃鏌ヨ鐢ㄦ埛锛堝寘鍚垎鍏徃鍙婂叾鎵�鏈夊瓙閮ㄩ棬鐨勭敤鎴凤級 -->
+	<select id="selectUsersByBranchDeptIds" resultMap="SysUserResult">
+		SELECT DISTINCT
+			u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, 
+			u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.create_time,
+			d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
+			r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
+		FROM sys_user u
+		LEFT JOIN sys_dept d ON u.dept_id = d.dept_id
+		LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
+		LEFT JOIN sys_role r ON r.role_id = ur.role_id
+		WHERE u.del_flag = '0'
+			AND u.status = '0'
+			AND u.dept_id IN (				
+				SELECT t.dept_id 
+				FROM sys_dept t
+				WHERE t.del_flag = '0' 
+					AND (						
+						t.dept_id IN
+						<foreach collection="branchDeptIds" item="deptId" open="(" separator="," close=")">
+							#{deptId}
+						</foreach>
+						OR						
+						<foreach collection="branchDeptIds" item="deptId" open="(" separator=" OR " close=")">
+							find_in_set(#{deptId}, t.ancestors) > 0
+						</foreach>
+					)
+			)
+		ORDER BY u.create_time DESC
+	</select>
+	
 </mapper> 
\ No newline at end of file

--
Gitblit v1.9.1