From 5100f2a6d2c80de8ae3abf8b8e1095153f193900 Mon Sep 17 00:00:00 2001 From: nixj Date: Tue, 18 Jun 2024 08:47:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90add=E3=80=91=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dtos/system/RolePageDto.java | 12 ++++ .../dtos/system/RolePageQuery.java | 10 +++ .../application/system/UserController.java | 11 +++ .../domain/service/UserDomainService.java | 67 +++++++++++++++++++ .../repository/jdbc/JdbcRoleRepository.java | 4 ++ .../jdbc/JdbcRoleUserRepository.java | 2 + .../repository/jdbc/JdbcUserRepository.java | 4 ++ 7 files changed, 110 insertions(+) create mode 100644 src/main/java/com/chint/application/dtos/system/RolePageDto.java create mode 100644 src/main/java/com/chint/application/dtos/system/RolePageQuery.java create mode 100644 src/main/java/com/chint/domain/service/UserDomainService.java diff --git a/src/main/java/com/chint/application/dtos/system/RolePageDto.java b/src/main/java/com/chint/application/dtos/system/RolePageDto.java new file mode 100644 index 00000000..518c9850 --- /dev/null +++ b/src/main/java/com/chint/application/dtos/system/RolePageDto.java @@ -0,0 +1,12 @@ +package com.chint.application.dtos.system; + +import lombok.Data; + +@Data +public class RolePageDto { + private String name; + private String employeeNo; + private String roleName; + private Long roleId; + private Long roleUserId; +} diff --git a/src/main/java/com/chint/application/dtos/system/RolePageQuery.java b/src/main/java/com/chint/application/dtos/system/RolePageQuery.java new file mode 100644 index 00000000..8016a0d4 --- /dev/null +++ b/src/main/java/com/chint/application/dtos/system/RolePageQuery.java @@ -0,0 +1,10 @@ +package com.chint.application.dtos.system; + +import com.chint.domain.value_object.BaseQuery; +import lombok.Data; + +@Data +public class RolePageQuery extends BaseQuery { + private String name=""; + private String employeeNo=""; +} diff --git a/src/main/java/com/chint/application/system/UserController.java b/src/main/java/com/chint/application/system/UserController.java index 0599f825..97698a4c 100644 --- a/src/main/java/com/chint/application/system/UserController.java +++ b/src/main/java/com/chint/application/system/UserController.java @@ -3,6 +3,7 @@ package com.chint.application.system; import cn.hutool.core.bean.BeanUtil; import com.chint.application.dtos.response.UserRes; import com.chint.application.dtos.system.RoleOrgParam; +import com.chint.application.dtos.system.RolePageQuery; import com.chint.application.dtos.system.SupplierRedirectDTO; import com.chint.application.dtos.system.UserLoginSupplierParam; import com.chint.application.services.SupplierLoginService; @@ -15,6 +16,7 @@ import com.chint.domain.repository.RoleRepository; import com.chint.domain.repository.RoleUserRepository; import com.chint.domain.repository.UserRepository; import com.chint.domain.service.SystemDomainService; +import com.chint.domain.service.UserDomainService; import com.chint.domain.value_object.system.RoleOrganizationVO; import com.chint.domain.value_object.system.RoleVO; import com.chint.infrastructure.util.BaseContext; @@ -56,6 +58,8 @@ public class UserController { @Autowired private SupplierLoginService supplierLoginService; + @Autowired + private UserDomainService userDomainService; @ApiOperation("根据Id查询用户信息") @PostMapping("/query") @@ -157,4 +161,11 @@ public class UserController { User currentUser = BaseContext.getCurrentUser().loadRoleOrg(); return Result.Success(SUCCESS, BeanUtil.copyProperties(currentUser, UserRes.class)); } + + + @ApiOperation("用户角色分页查询") + @PostMapping("/role/pageQuery") + public Result> rolePageQuery(@RequestBody RolePageQuery rolePageQuery) { + return Result.Success(SUCCESS,userDomainService.userPageQuery(rolePageQuery)); + } } diff --git a/src/main/java/com/chint/domain/service/UserDomainService.java b/src/main/java/com/chint/domain/service/UserDomainService.java new file mode 100644 index 00000000..3b84f63a --- /dev/null +++ b/src/main/java/com/chint/domain/service/UserDomainService.java @@ -0,0 +1,67 @@ +package com.chint.domain.service; + +import com.chint.application.dtos.system.RolePageDto; +import com.chint.application.dtos.system.RolePageQuery; +import com.chint.domain.aggregates.user.Role; +import com.chint.domain.aggregates.user.RoleUser; +import com.chint.domain.aggregates.user.User; +import com.chint.infrastructure.repository.jdbc.JdbcRoleRepository; +import com.chint.infrastructure.repository.jdbc.JdbcRoleUserRepository; +import com.chint.infrastructure.repository.jdbc.JdbcUserRepository; +import com.chint.infrastructure.util.PageResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class UserDomainService { + @Autowired + private JdbcUserRepository jdbcUserRepository; + @Autowired + private JdbcRoleRepository jdbcRoleRepository; + @Autowired + private JdbcRoleUserRepository jdbcRoleUserRepository; + + public PageResult userPageQuery(RolePageQuery rolePageQuery) { + Page page=jdbcUserRepository.findAllByNameContainsAndEmployeeNoContains(rolePageQuery.getName(),rolePageQuery.getEmployeeNo(),rolePageQuery.getPageResult()); + List users=page.getContent(); + if(users.isEmpty()){ + return PageResult.totalPageNum(page.getTotalElements(), new ArrayList<>()); + } + List userIds=users.stream().map(User::getUserId).toList(); + List roleUsers=jdbcRoleUserRepository.findAllByUserIdIn(userIds); + if(roleUsers.isEmpty()){ + List result = users.stream().map(temp -> { + RolePageDto obj = new RolePageDto(); + obj.setName(temp.getName()); + obj.setEmployeeNo(temp.getEmployeeNo()); + return obj; + + }).toList(); + return PageResult.totalPageNum(page.getTotalElements(), result); + } + List roleIds=roleUsers.stream().map(RoleUser::getRoleId).toList(); + List roles=jdbcRoleRepository.findAllByIdIn(roleIds); + List result = users.stream().map(temp -> { + RolePageDto obj = new RolePageDto(); + obj.setName(temp.getName()); + obj.setEmployeeNo(temp.getEmployeeNo()); + List roleUser = roleUsers.stream() + .filter(s -> s.getUserId().equals(temp.getUserId())) + .toList(); + if(!roleUser.isEmpty()){ + obj.setRoleId(roleUser.get(0).getRoleId()); + obj.setRoleUserId(roleUser.get(0).getId()); + List roleList=roles.stream().filter(s->s.getId().equals(obj.getRoleId())).toList(); + if(!roleList.isEmpty()){ + obj.setRoleName(roleList.get(0).getRoleName()); + } + } + return obj; + }).toList(); + return PageResult.totalPageNum(page.getTotalElements(), result); + } +} diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRoleRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRoleRepository.java index a3e391bc..75b65cc6 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRoleRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRoleRepository.java @@ -6,7 +6,11 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface JdbcRoleRepository extends CrudRepository { Page findAll(Pageable pageable); + + List findAllByIdIn(List ids); } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRoleUserRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRoleUserRepository.java index 9fcf8dbf..595c4b23 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRoleUserRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRoleUserRepository.java @@ -13,5 +13,7 @@ public interface JdbcRoleUserRepository extends CrudRepository { List findByRoleId(Long roleId); + List findAllByUserIdIn(List userIds); + } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcUserRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcUserRepository.java index 87721ccc..19b0e397 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcUserRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcUserRepository.java @@ -1,6 +1,8 @@ package com.chint.infrastructure.repository.jdbc; import com.chint.domain.aggregates.user.User; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @@ -15,4 +17,6 @@ public interface JdbcUserRepository extends CrudRepository { List findByStatusIsNull(); List findAllByNameContains(String name); + + Page findAllByNameContainsAndEmployeeNoContains(String name, String employeeNo, Pageable pageable); }