根据输入的userId,返回排序后的所有二级部门
This commit is contained in:
+13
@@ -845,6 +845,17 @@ public class SysUserController {
|
||||
return Result.ok(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据输入的userId查询排序号后的所有的一级部门
|
||||
*/
|
||||
@GetMapping("/getOrderedDepartListByUserId")
|
||||
@Operation(summary = "获取用户所在的排序后的一级部门")
|
||||
public Result<?> getOrderedDepartListByUserId(
|
||||
@RequestParam(name = "userId") String userId
|
||||
) {
|
||||
return Result.ok(sysUserDepartService.getOrderedDepartListById(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 orgCode 查询用户,包括子部门下的用户
|
||||
* 针对通讯录模块做的接口,将多个部门的用户合并成一条记录,并转成对前端友好的格式
|
||||
@@ -1990,4 +2001,6 @@ public class SysUserController {
|
||||
sysUserService.updatePasswordNotBindPhone(oldPassword, password, username);
|
||||
return Result.OK("修改密码成功!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+7
@@ -4,6 +4,7 @@ package org.jeecg.modules.system.service;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.jeecg.modules.system.entity.SysDepart;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.entity.SysUserDepart;
|
||||
import org.jeecg.modules.system.model.DepartIdModel;
|
||||
@@ -101,4 +102,10 @@ public interface ISysUserDepartService extends IService<SysUserDepart> {
|
||||
* @return
|
||||
*/
|
||||
List<SysUser> getUsersByDepartTenantId(String departId,Integer tenantId);
|
||||
|
||||
/**
|
||||
* 根据用户Id按序返回一级部门列表
|
||||
* @param userId
|
||||
*/
|
||||
List<SysDepart> getOrderedDepartListById(String userId);
|
||||
}
|
||||
|
||||
+26
-4
@@ -1,5 +1,6 @@
|
||||
package org.jeecg.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
@@ -13,10 +14,7 @@ import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.config.mybatis.MybatisPlusSaasConfig;
|
||||
import org.jeecg.modules.system.entity.SysDepart;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.entity.SysUserDepart;
|
||||
import org.jeecg.modules.system.entity.SysUserRole;
|
||||
import org.jeecg.modules.system.entity.*;
|
||||
import org.jeecg.modules.system.mapper.SysUserDepartMapper;
|
||||
import org.jeecg.modules.system.mapper.SysUserMapper;
|
||||
import org.jeecg.modules.system.mapper.SysUserTenantMapper;
|
||||
@@ -491,4 +489,28 @@ public class SysUserDepartServiceImpl extends ServiceImpl<SysUserDepartMapper, S
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDepart> getOrderedDepartListById(String userId) {
|
||||
if(StringUtils.isBlank(userId)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> deptIdList = this.lambdaQuery()
|
||||
.eq(SysUserDepart::getUserId, userId) // 建议变量名改为小写 userId
|
||||
.list()
|
||||
.stream()
|
||||
.map(SysUserDepart::getDepId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isNotEmpty(deptIdList)) {
|
||||
|
||||
List<SysDepart> sortedDeparts = sysDepartService.lambdaQuery()
|
||||
.in(SysDepart::getId, deptIdList) // 范围限定在这些 ID 内
|
||||
.eq(SysDepart::getOrgType, 2) // 这里的 "SomeField" 替换成你那个要求值为 1 的字段名
|
||||
.orderByAsc(SysDepart::getDepartOrder) // 直接在 SQL 层面完成排序
|
||||
.list();
|
||||
|
||||
return sortedDeparts;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user