Explorar o código

通讯录列表数据缺少问题修复

ZL hai 3 meses
pai
achega
1f6da233c6

+ 6 - 6
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysUserController.java

@@ -803,12 +803,12 @@ public class SysUserController {
         for (SysUserSysDepartModel item : list) {
             String userId = item.getId();
             // userId
-            JSONObject getModel = hasUser.get(userId);
+//            JSONObject getModel = hasUser.get(userId);
             // 之前已存在过该用户,直接合并数据
-            if (getModel != null) {
-                String departName = getModel.get("departName").toString();
-                getModel.put("departName", (departName + " | " + item.getDepartName()));
-            } else {
+//            if (getModel != null) {
+//                String departName = getModel.get("departName").toString();
+//                getModel.put("departName", (departName + " | " + item.getDepartName()));
+//            } else {
                 // 将用户对象转换为json格式,并将部门信息合并到 json 中
                 JSONObject json = JSON.parseObject(JSON.toJSONString(item));
                 json.remove("id");
@@ -818,7 +818,7 @@ public class SysUserController {
 //                json.put("avatar", item.getSysUser().getAvatar());
                 resultJson.add(json);
                 hasUser.put(userId, json);
-            }
+//            }
         }
 
         IPage<JSONObject> result = new Page<>(pageNo, pageSize, pageList.getTotal());

+ 38 - 16
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml

@@ -75,9 +75,9 @@
 	<!-- 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
+		sys_user
+		INNER JOIN sys_user_depart ON sys_user.id = sys_user_depart.user_id
+		INNER JOIN sys_depart ON sys_user_depart.dep_id = sys_depart.id
 		WHERE
 		<if test="orgCode == null">
 			<bind name="bindOrgCode" value="'%'"/>
@@ -100,21 +100,43 @@
 	<!-- 根据 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
+		id,
+		realname,
+		avatar,
+		sex,
+		birthday,
+		workNo,
+		post,
+		telephone,
+		email,
+		phone,
+		GROUP_CONCAT( DISTINCT departName ORDER BY orgCode ASC SEPARATOR ' | ' ) AS departName,
+		GROUP_CONCAT( DISTINCT departId ORDER BY orgCode ASC SEPARATOR ' | ' ) AS departId
+		FROM
+		(
+		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_user.create_time AS createTime,
+		sys_depart.id AS departId,
+		sys_depart.depart_name AS departName,
+		sys_depart.org_code orgCode
 		<include refid="getUserByOrgCodeFromSql"/>
+		) u
+		GROUP BY
+		u.id,
+		u.realname,
+		u.createTime
 		ORDER BY
-			sys_depart.org_code ASC
+		u.createTime DESC
 	</select>
 
 	<!-- 查询 getUserByOrgCode 的总数-->

+ 2 - 2
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java

@@ -424,9 +424,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
     @Override
     public IPage<SysUserSysDepartModel> queryUserByOrgCode(String orgCode, SysUser userParams, IPage page) {
         List<SysUserSysDepartModel> list = baseMapper.getUserByOrgCode(page, orgCode, userParams);
-        Integer total = baseMapper.getUserByOrgCodeTotal(orgCode, userParams);
+//        Integer total = baseMapper.getUserByOrgCodeTotal(orgCode, userParams);
 
-        IPage<SysUserSysDepartModel> result = new Page<>(page.getCurrent(), page.getSize(), total);
+        IPage<SysUserSysDepartModel> result = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
         result.setRecords(list);
 
         return result;