|
|
@@ -1,15 +1,17 @@
|
|
|
package com.usky.system.controller.web;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.core.bean.ApiResult;
|
|
|
-import com.usky.system.domain.SysDept;
|
|
|
import com.usky.system.controller.web.page.TableDataInfo;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.system.domain.SysPerson;
|
|
|
+import com.usky.system.domain.SysUser;
|
|
|
import com.usky.system.domain.SysUserPerson;
|
|
|
-import com.usky.system.service.ISysDeptService;
|
|
|
+import com.usky.system.service.ISysUserService;
|
|
|
import com.usky.system.service.SysPersonService;
|
|
|
import com.usky.system.service.SysUserPersonService;
|
|
|
import com.usky.common.core.util.StringUtils;
|
|
|
@@ -19,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
@@ -41,7 +44,7 @@ public class SysPersonController extends BaseController {
|
|
|
@Autowired
|
|
|
private SysUserPersonService sysUserPersonService;
|
|
|
@Autowired
|
|
|
- private ISysDeptService sysDeptService;
|
|
|
+ private ISysUserService sysUserService;
|
|
|
|
|
|
/**
|
|
|
* 人员列表(分页)
|
|
|
@@ -50,45 +53,60 @@ public class SysPersonController extends BaseController {
|
|
|
public ApiResult<TableDataInfo> list(SysPerson person) {
|
|
|
startPage();
|
|
|
// 支持 fullName 模糊查询;其他字段保持按传入条件精确匹配
|
|
|
+ Long filterDeptId = person != null ? person.getDeptId() : null;
|
|
|
+
|
|
|
SysPerson queryEntity = new SysPerson();
|
|
|
if (person != null) {
|
|
|
BeanUtils.copyProperties(person, queryEntity);
|
|
|
// fullName 用 like 查询,避免 Wrappers.query(entity) 产生 fullName=xxx 的精确条件
|
|
|
queryEntity.setFullName(null);
|
|
|
+ // 部门、岗位以关联用户为准,不作为人员表列条件;部门筛选见下方按用户 dept_id 关联
|
|
|
+ queryEntity.setDeptId(null);
|
|
|
+ queryEntity.setPostId(null);
|
|
|
}
|
|
|
QueryWrapper<SysPerson> queryWrapper = Wrappers.query(queryEntity);
|
|
|
queryWrapper.lambda()
|
|
|
.like(person != null && StringUtils.isNotBlank(person.getFullName()),
|
|
|
SysPerson::getFullName, person.getFullName());
|
|
|
- List<SysPerson> list = sysPersonService.list(queryWrapper);
|
|
|
|
|
|
- // 回显部门名称
|
|
|
- if (list != null && !list.isEmpty()) {
|
|
|
- List<Long> deptIds = list.stream()
|
|
|
- .map(SysPerson::getDeptId)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (!deptIds.isEmpty()) {
|
|
|
- List<SysDept> depts = sysDeptService.selectDeptByIds(deptIds);
|
|
|
- if (depts != null && !depts.isEmpty()) {
|
|
|
- Map<Long, String> deptNameMap = depts.stream()
|
|
|
- .collect(Collectors.toMap(
|
|
|
- SysDept::getDeptId,
|
|
|
- SysDept::getDeptName,
|
|
|
- (n1, n2) -> n1
|
|
|
- ));
|
|
|
- list.forEach(p -> {
|
|
|
- String deptName = deptNameMap.get(p.getDeptId());
|
|
|
- if (deptName != null) {
|
|
|
- p.setDeptName(deptName);
|
|
|
- }
|
|
|
- });
|
|
|
+ // 按部门筛选:关联用户的 dept_id = filterDeptId
|
|
|
+ if (filterDeptId != null) {
|
|
|
+ LambdaQueryWrapper<SysUser> userQuery = Wrappers.<SysUser>lambdaQuery()
|
|
|
+ .eq(SysUser::getDeptId, filterDeptId)
|
|
|
+ .eq(SysUser::getDelFlag, "0");
|
|
|
+ Integer tenantId = SecurityUtils.getTenantId();
|
|
|
+ if (tenantId != null) {
|
|
|
+ userQuery.eq(SysUser::getTenantId, tenantId);
|
|
|
+ }
|
|
|
+ List<SysUser> deptUsers = sysUserService.list(userQuery);
|
|
|
+ if (deptUsers == null || deptUsers.isEmpty()) {
|
|
|
+ queryWrapper.apply("1 = 0");
|
|
|
+ } else {
|
|
|
+ List<Long> userIds = deptUsers.stream()
|
|
|
+ .map(SysUser::getUserId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<SysUserPerson> deptRelations = sysUserPersonService.list(
|
|
|
+ Wrappers.<SysUserPerson>lambdaQuery()
|
|
|
+ .in(SysUserPerson::getUserId, userIds)
|
|
|
+ );
|
|
|
+ if (deptRelations == null || deptRelations.isEmpty()) {
|
|
|
+ queryWrapper.apply("1 = 0");
|
|
|
+ } else {
|
|
|
+ List<Integer> deptPersonIds = deptRelations.stream()
|
|
|
+ .map(SysUserPerson::getPersonId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ queryWrapper.lambda().in(SysPerson::getId, deptPersonIds);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 回显每个人员对应的 userId
|
|
|
+ List<SysPerson> list = sysPersonService.list(queryWrapper);
|
|
|
+
|
|
|
+ // 回显 userId,以及通过 userId 回显部门、岗位
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
List<Integer> personIds = list.stream()
|
|
|
.map(SysPerson::getId)
|
|
|
@@ -99,8 +117,9 @@ public class SysPersonController extends BaseController {
|
|
|
Wrappers.<SysUserPerson>lambdaQuery()
|
|
|
.in(SysUserPerson::getPersonId, personIds)
|
|
|
);
|
|
|
+ final Map<Integer, Long> personUserMap;
|
|
|
if (relations != null && !relations.isEmpty()) {
|
|
|
- Map<Integer, Long> personUserMap = relations.stream()
|
|
|
+ personUserMap = relations.stream()
|
|
|
.collect(Collectors.toMap(
|
|
|
SysUserPerson::getPersonId,
|
|
|
SysUserPerson::getUserId,
|
|
|
@@ -112,7 +131,10 @@ public class SysPersonController extends BaseController {
|
|
|
p.setUserId(userId);
|
|
|
}
|
|
|
});
|
|
|
+ } else {
|
|
|
+ personUserMap = new HashMap<>();
|
|
|
}
|
|
|
+ sysPersonService.fillDeptAndPostForList(list, personUserMap);
|
|
|
}
|
|
|
}
|
|
|
return ApiResult.success(getDataTable(list));
|
|
|
@@ -125,21 +147,17 @@ public class SysPersonController extends BaseController {
|
|
|
public ApiResult<SysPerson> getInfo(@PathVariable("id") Integer id) {
|
|
|
SysPerson person = sysPersonService.getById(id);
|
|
|
if (person != null) {
|
|
|
+ Long userId = null;
|
|
|
SysUserPerson userPerson = sysUserPersonService.getOne(
|
|
|
Wrappers.<SysUserPerson>lambdaQuery()
|
|
|
.eq(SysUserPerson::getPersonId, id)
|
|
|
.last("limit 1")
|
|
|
);
|
|
|
if (userPerson != null) {
|
|
|
- person.setUserId(userPerson.getUserId());
|
|
|
- }
|
|
|
-
|
|
|
- if (person.getDeptId() != null) {
|
|
|
- SysDept dept = sysDeptService.selectDeptById(person.getDeptId());
|
|
|
- if (dept != null) {
|
|
|
- person.setDeptName(dept.getDeptName());
|
|
|
- }
|
|
|
+ userId = userPerson.getUserId();
|
|
|
+ person.setUserId(userId);
|
|
|
}
|
|
|
+ sysPersonService.fillDeptAndPostFromUser(person, userId);
|
|
|
}
|
|
|
return ApiResult.success(person);
|
|
|
}
|