Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部门人员选择组件出现人员重复以及数量不对的情况 #6342

Closed
xgzit opened this issue Jun 21, 2024 · 2 comments
Closed

部门人员选择组件出现人员重复以及数量不对的情况 #6342

xgzit opened this issue Jun 21, 2024 · 2 comments

Comments

@xgzit
Copy link

xgzit commented Jun 21, 2024

版本号:3.7.0
分支: master?还是springboot3?

master

前端版本: vue3版?还是 vue2版?

vue3

问题描述:

部门人员选择组件出现人员重复以及数量不对的情况。
1、第一页本身或者与后续页会出现人员重复
2、某一页比如第二页出现数量不足10条,但是总页数超过2.
见最后一张图片。

问题分析:
SysUserController.java文件的queryUserComponentData方法,最终调用queryDepartUserPageList方法。

当 传递了departId时,会走自定义SQL。

image

而自定义SQL

	<select id="queryDepartUserPageList" resultType="org.jeecg.modules.system.entity.SysUser">
		select a.*, c.depart_name as org_code_txt from sys_user a
		join sys_user_depart b on b.user_id = a.id
		join sys_depart c on b.dep_id = c.id
		<bind name="bindOrgCode" value="orgCode+'%'"/>
		where a.del_flag = 0 and a.status = 1 and c.org_code like #{bindOrgCode} and a.username!='_reserve_user_external'
		<if test="username!=null and username!=''">
			<bind name="bindUsername" value="'%'+username+'%'"/>
			and a.username like #{bindUsername}
		</if>
		<if test="realname!=null and realname!=''">
		    <bind name="bindRealname" value="'%'+realname+'%'"/>
			and a.realname like #{bindRealname}
		</if>
	</select>

这是一个执行的SQL

SELECT
  a.*,                           -- 选择sys_user表中的所有列
  c.depart_name AS org_code_txt  -- 将部门名称列为org_code_txt,便于前端展示或后续处理
FROM
  sys_user a                     -- 用户表
  JOIN sys_user_depart b ON b.user_id = a.id -- 用户与部门关联表,按用户ID连接用户表
  JOIN sys_depart c ON b.dep_id = c.id AND c.org_code LIKE 'A0101%'     -- 部门表,按部门ID连接用户与部门关联表
WHERE
  a.del_flag = 0                  -- 筛选未被删除的用户记录
  AND a.STATUS = 1                -- 筛选用户状态为有效的记录
  AND a.username != '_reserve_user_external' -- 排除特定用户名'_reserve_user_external'的记录 

使用的是 内连接join,会出现人员重复的情况,由于会出现人员重复情况,后续去重代码
image

会导致 前端明明一页有10个人,但是显示会少于10个。

解决方案:查询的时候就要进行人员去重,而不是查完之后用代码去重。通过人员id分组进行去重。并以id进行排序。 直接使用 GROUP_CONCAT(c.depart_name SEPARATOR ',') AS org_codes_txt 就不需要后续进行部门的拼接。

   select a.*,
    GROUP_CONCAT(c.depart_name SEPARATOR ',') AS org_codes_txt
    FROM
    sys_user a
    LEFT JOIN sys_user_depart b ON b.user_id = a.id
    LEFT JOIN sys_depart c ON b.dep_id = c.id
    <bind name="bindOrgCode" value="orgCode+'%'"/>
    where a.del_flag = 0
      and a.status = 1
      and c.org_code like #{bindOrgCode}
      and a.username!='_reserve_user_external'
    <if test="username!=null and username!=''">
      <bind name="bindUsername" value="'%'+username+'%'"/>
      and a.username like #{bindUsername}
    </if>
    <if test="realname!=null and realname!=''">
      <bind name="bindRealname" value="'%'+realname+'%'"/>
      and a.realname like #{bindRealname}
    </if>
    GROUP BY a.id
    HAVING COUNT(a.id) > 0
    ORDER BY a.id DESC;

示例SQL

SELECT
  a.*,
  GROUP_CONCAT( c.depart_name SEPARATOR ',' ) AS org_codes_txt 
FROM
  sys_user a
  LEFT JOIN sys_user_depart b ON b.user_id = a.id
  LEFT JOIN sys_depart c ON b.dep_id = c.id 
WHERE
  a.del_flag = 0 
  AND a.STATUS = 1 
  AND c.org_code LIKE 'A0101%' 
  AND a.username != '_reserve_user_external' 
GROUP BY
  a.id 
HAVING
  COUNT( a.id ) > 0 
ORDER BY
  a.id DESC 
截图&代码:

fc9522f2bbea03a024140ce407d6567
主要还是一个人多部门造成的。

友情提示(为了提高issue处理效率):

  • 未按格式要求发帖、描述过于简抽象的,会被直接删掉;
  • 请自己初判问题描述是否清楚,是否方便我们调查处理;
  • 针对问题请说明是Online在线功能(需说明用的主题模板),还是生成的代码功能;
@zhangdaiscott
Copy link
Member

zhangdaiscott commented Jun 27, 2024

ws

@1298191366
Copy link

已修复,待新版本发布

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants