【add】用户信息分页查询接口新增公司部门信息

This commit is contained in:
nixj 2024-07-12 13:14:42 +08:00
parent ac5a8ed996
commit b47a7bf250
4 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package com.chint.application.dtos.system; package com.chint.application.dtos.system;
import com.chint.domain.aggregates.standards.StaffRank; import com.chint.domain.aggregates.standards.StaffRank;
import com.chint.route.entity.UserDepartmentInfoBasic;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@ -12,4 +13,5 @@ public class RolePageDto {
private Long userId; private Long userId;
List<RoleUserDto> roleUserDtos; List<RoleUserDto> roleUserDtos;
List<StaffRank> staffRanks; List<StaffRank> staffRanks;
List<UserDepartmentInfoBasic> departments;
} }

View File

@ -171,7 +171,7 @@ public class UserController {
} }
@ApiOperation("用户角色分页查询") @ApiOperation("用户信息分页查询")
@PostMapping("/role/pageQuery") @PostMapping("/role/pageQuery")
public Result<PageResult<?>> rolePageQuery(@RequestBody RolePageQuery rolePageQuery) { public Result<PageResult<?>> rolePageQuery(@RequestBody RolePageQuery rolePageQuery) {
return Result.Success(SUCCESS, userDomainService.userPageQuery(rolePageQuery)); return Result.Success(SUCCESS, userDomainService.userPageQuery(rolePageQuery));

View File

@ -7,12 +7,13 @@ import com.chint.domain.aggregates.standards.StaffRank;
import com.chint.domain.aggregates.user.Role; import com.chint.domain.aggregates.user.Role;
import com.chint.domain.aggregates.user.RoleUser; import com.chint.domain.aggregates.user.RoleUser;
import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.RoleRepository;
import com.chint.infrastructure.repository.jdbc.JdbcRoleRepository; import com.chint.infrastructure.repository.jdbc.JdbcRoleRepository;
import com.chint.infrastructure.repository.jdbc.JdbcRoleUserRepository; import com.chint.infrastructure.repository.jdbc.JdbcRoleUserRepository;
import com.chint.infrastructure.repository.jdbc.JdbcStaffRankRepository; import com.chint.infrastructure.repository.jdbc.JdbcStaffRankRepository;
import com.chint.infrastructure.repository.jdbc.JdbcUserRepository; import com.chint.infrastructure.repository.jdbc.JdbcUserRepository;
import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.PageResult;
import com.chint.route.entity.UserDepartmentInfoBasic;
import com.chint.route.mapper.JdbcUserDepartmentInfoBasicRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -32,6 +33,8 @@ public class UserDomainService {
private JdbcRoleUserRepository jdbcRoleUserRepository; private JdbcRoleUserRepository jdbcRoleUserRepository;
@Autowired @Autowired
private JdbcStaffRankRepository jdbcStaffRankRepository; private JdbcStaffRankRepository jdbcStaffRankRepository;
@Autowired
private JdbcUserDepartmentInfoBasicRepository jdbcUserDepartmentInfoBasicRepository;
public PageResult<RolePageDto> userPageQuery(RolePageQuery rolePageQuery) { public PageResult<RolePageDto> userPageQuery(RolePageQuery rolePageQuery) {
Page<User> page=jdbcUserRepository.findAllByNameContainsAndEmployeeNoContains(rolePageQuery.getName(),rolePageQuery.getEmployeeNo(),rolePageQuery.getPageResult()); Page<User> page=jdbcUserRepository.findAllByNameContainsAndEmployeeNoContains(rolePageQuery.getName(),rolePageQuery.getEmployeeNo(),rolePageQuery.getPageResult());
@ -54,8 +57,12 @@ public class UserDomainService {
} }
List<Long> roleIds=roleUsers.stream().map(RoleUser::getRoleId).toList(); List<Long> roleIds=roleUsers.stream().map(RoleUser::getRoleId).toList();
List<Role> roles=jdbcRoleRepository.findAllByIdIn(roleIds); List<Role> roles=jdbcRoleRepository.findAllByIdIn(roleIds);
//职级
List<StaffRank> staffRanks=jdbcStaffRankRepository.findByEmployeeNoIn(users.stream().map(User::getEmployeeNo).toList()); List<StaffRank> staffRanks=jdbcStaffRankRepository.findByEmployeeNoIn(users.stream().map(User::getEmployeeNo).toList());
Map<String, List<StaffRank>> collect= staffRanks.stream().collect(Collectors.groupingBy(StaffRank::getEmployeeNo)); Map<String, List<StaffRank>> collect= staffRanks.stream().collect(Collectors.groupingBy(StaffRank::getEmployeeNo));
//公司
List<UserDepartmentInfoBasic> departments=jdbcUserDepartmentInfoBasicRepository.findByUserIdIn(users.stream().map(User::getUserId).toList());
Map<Long, List<UserDepartmentInfoBasic>> departmentCollect= departments.stream().collect(Collectors.groupingBy(UserDepartmentInfoBasic::getUserId));
List<RolePageDto> result = users.stream().map(temp -> { List<RolePageDto> result = users.stream().map(temp -> {
RolePageDto obj = new RolePageDto(); RolePageDto obj = new RolePageDto();
@ -63,6 +70,7 @@ public class UserDomainService {
obj.setEmployeeNo(temp.getEmployeeNo()); obj.setEmployeeNo(temp.getEmployeeNo());
obj.setUserId(temp.getUserId()); obj.setUserId(temp.getUserId());
obj.setStaffRanks(collect.get(temp.getEmployeeNo())); obj.setStaffRanks(collect.get(temp.getEmployeeNo()));
obj.setDepartments(departmentCollect.get(temp.getUserId()));
List<RoleUser> roleUser = roleUsers.stream() List<RoleUser> roleUser = roleUsers.stream()
.filter(s -> s.getUserId().equals(temp.getUserId())) .filter(s -> s.getUserId().equals(temp.getUserId()))
.toList(); .toList();

View File

@ -15,4 +15,6 @@ import java.util.List;
public interface JdbcUserDepartmentInfoBasicRepository extends CrudRepository<UserDepartmentInfoBasic,Long> { public interface JdbcUserDepartmentInfoBasicRepository extends CrudRepository<UserDepartmentInfoBasic,Long> {
List<UserDepartmentInfoBasic> findByUserId(Long userId); List<UserDepartmentInfoBasic> findByUserId(Long userId);
List<UserDepartmentInfoBasic> findByUserIdIn(List<Long> userIds);
} }