【add】用户角色分页查询接口新增职级数据

This commit is contained in:
nixj 2024-07-11 13:53:52 +08:00
parent dfb90dfa31
commit 773f2a9786
3 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package com.chint.application.dtos.system;
import com.chint.domain.aggregates.standards.StaffRank;
import lombok.Data;
import java.util.List;
@ -10,4 +11,5 @@ public class RolePageDto {
private String employeeNo;
private Long userId;
List<RoleUserDto> roleUserDtos;
List<StaffRank> staffRanks;
}

View File

@ -3,12 +3,14 @@ package com.chint.domain.service;
import com.chint.application.dtos.system.RolePageDto;
import com.chint.application.dtos.system.RolePageQuery;
import com.chint.application.dtos.system.RoleUserDto;
import com.chint.domain.aggregates.standards.StaffRank;
import com.chint.domain.aggregates.user.Role;
import com.chint.domain.aggregates.user.RoleUser;
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.JdbcRoleUserRepository;
import com.chint.infrastructure.repository.jdbc.JdbcStaffRankRepository;
import com.chint.infrastructure.repository.jdbc.JdbcUserRepository;
import com.chint.infrastructure.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,6 +19,8 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class UserDomainService {
@ -24,9 +28,10 @@ public class UserDomainService {
private JdbcUserRepository jdbcUserRepository;
@Autowired
private JdbcRoleRepository jdbcRoleRepository;
@Autowired
private JdbcRoleUserRepository jdbcRoleUserRepository;
@Autowired
private JdbcStaffRankRepository jdbcStaffRankRepository;
public PageResult<RolePageDto> userPageQuery(RolePageQuery rolePageQuery) {
Page<User> page=jdbcUserRepository.findAllByNameContainsAndEmployeeNoContains(rolePageQuery.getName(),rolePageQuery.getEmployeeNo(),rolePageQuery.getPageResult());
@ -49,11 +54,15 @@ public class UserDomainService {
}
List<Long> roleIds=roleUsers.stream().map(RoleUser::getRoleId).toList();
List<Role> roles=jdbcRoleRepository.findAllByIdIn(roleIds);
List<StaffRank> staffRanks=jdbcStaffRankRepository.findByEmployeeNoIn(users.stream().map(User::getEmployeeNo).toList());
Map<String, List<StaffRank>> collect= staffRanks.stream().collect(Collectors.groupingBy(StaffRank::getEmployeeNo));
List<RolePageDto> result = users.stream().map(temp -> {
RolePageDto obj = new RolePageDto();
obj.setName(temp.getName());
obj.setEmployeeNo(temp.getEmployeeNo());
obj.setUserId(temp.getUserId());
obj.setStaffRanks(collect.get(temp.getEmployeeNo()));
List<RoleUser> roleUser = roleUsers.stream()
.filter(s -> s.getUserId().equals(temp.getUserId()))
.toList();

View File

@ -12,6 +12,7 @@ import java.util.List;
public interface JdbcStaffRankRepository extends CrudRepository<StaffRank, Integer> {
List<StaffRank> findByEmployeeNoAndTag(String employeeNo,String tag);
List<StaffRank> findByEmployeeNo(String employeeNo);
List<StaffRank> findByEmployeeNoIn(List<String> employeeNos);
Page<StaffRank> findAllByEmployeeNoContainsAndEmployeeNameContains(String employeeNo, String employeeName, Pageable pageable);
}