【7.6.0】【sys】整理,迁移所有userOrg关联查询的api

pull/57/head
fengshuonan 2023-06-18 23:21:38 +08:00
parent f469529717
commit 6c0202ec1f
5 changed files with 79 additions and 73 deletions

View File

@ -2,6 +2,8 @@ package cn.stylefeng.roses.kernel.sys.api;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.UserOrgDTO;
import java.util.List;
/**
* Api
*
@ -20,4 +22,22 @@ public interface SysUserOrgServiceApi {
*/
UserOrgDTO getUserMainOrgInfo(Long userId);
/**
*
*
* @author fengshuonan
* @since 2023/6/11 21:08
*/
List<UserOrgDTO> getUserOrgList(Long userId);
/**
* id
*
* @param orgId id
* @param containSubOrgFlag true-false-
* @author fengshuonan
* @since 2023/6/11 21:46
*/
List<Long> getOrgUserIdList(Long orgId, Boolean containSubOrgFlag);
}

View File

@ -25,7 +25,6 @@
package cn.stylefeng.roses.kernel.sys.api;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.SimpleUserDTO;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.UserOrgDTO;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.UserValidateDTO;
import java.util.List;
@ -46,24 +45,6 @@ public interface SysUserServiceApi {
*/
SimpleUserDTO getUserInfoByUserId(Long userId);
/**
*
*
* @author fengshuonan
* @since 2023/6/11 21:08
*/
List<UserOrgDTO> getUserOrgList(Long userId);
/**
* id
*
* @param orgId id
* @param containSubOrgFlag true-false-
* @author fengshuonan
* @since 2023/6/11 21:46
*/
List<Long> getOrgUserIdList(Long orgId, Boolean containSubOrgFlag);
/**
* id
*

View File

@ -7,13 +7,10 @@ import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.sys.api.SysUserServiceApi;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.SimpleUserDTO;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.UserOrgDTO;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.UserValidateDTO;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUser;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserOrg;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserRole;
import cn.stylefeng.roses.kernel.sys.modular.user.enums.SysUserExceptionEnum;
import cn.stylefeng.roses.kernel.sys.modular.user.factory.UserOrgFactory;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserRoleService;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserService;
@ -25,7 +22,6 @@ import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
@ -84,52 +80,6 @@ public class UserIntegrationService implements SysUserServiceApi {
return simpleUserDTO;
}
@Override
public List<UserOrgDTO> getUserOrgList(Long userId) {
if (userId == null) {
return null;
}
// 获取用户所有的部门信息
LambdaQueryWrapper<SysUserOrg> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysUserOrg::getUserId, userId);
queryWrapper.orderByDesc(SysUserOrg::getMainFlag);
List<SysUserOrg> sysUserOrgList = sysUserOrgService.list(queryWrapper);
// 补充完整用户的部门和职位信息
ArrayList<UserOrgDTO> userOrgDTOS = new ArrayList<>();
for (SysUserOrg sysUserOrg : sysUserOrgList) {
UserOrgDTO userOrgDetailInfo = UserOrgFactory.createUserOrgDetailInfo(sysUserOrg);
userOrgDTOS.add(userOrgDetailInfo);
}
return userOrgDTOS;
}
@Override
public List<Long> getOrgUserIdList(Long orgId, Boolean containSubOrgFlag) {
// 如果不包含查询子公司,则直接查询参数指定公司下的人员
if (!containSubOrgFlag) {
LambdaQueryWrapper<SysUserOrg> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysUserOrg::getOrgId, orgId);
queryWrapper.select(SysUserOrg::getUserId);
List<SysUserOrg> list = this.sysUserOrgService.list(queryWrapper);
return list.stream().map(SysUserOrg::getUserId).collect(Collectors.toList());
}
// 如果包含查询子公司,以及子公司的子公司
Set<Long> subOrgIdList = dbOperatorApi.findSubListByParentId("hr_organization", "org_pids", "org_id", orgId);
subOrgIdList.add(orgId);
LambdaQueryWrapper<SysUserOrg> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SysUserOrg::getOrgId, subOrgIdList);
queryWrapper.select(SysUserOrg::getUserId);
List<SysUserOrg> list = this.sysUserOrgService.list(queryWrapper);
return list.stream().map(SysUserOrg::getUserId).collect(Collectors.toList());
}
@Override
public List<Long> getUserRoleIdList(Long userId) {
if (userId == null) {

View File

@ -2,6 +2,7 @@ package cn.stylefeng.roses.kernel.sys.modular.user.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
@ -24,8 +25,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static cn.stylefeng.roses.kernel.sys.modular.user.enums.SysUserOrgExceptionEnum.MAIN_FLAG_COUNT_ERROR;
@ -36,7 +40,11 @@ import static cn.stylefeng.roses.kernel.sys.modular.user.enums.SysUserOrgExcepti
* @date 2023/06/10 21:26
*/
@Service
public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUserOrg> implements SysUserOrgService, RemoveOrgCallbackApi, RemoveUserCallbackApi {
public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUserOrg> implements SysUserOrgService, RemoveOrgCallbackApi,
RemoveUserCallbackApi {
@Resource
private DbOperatorApi dbOperatorApi;
@Override
public void add(SysUserOrgRequest sysUserOrgRequest) {
@ -141,6 +149,52 @@ public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUser
return UserOrgFactory.createUserOrgDetailInfo(sysUserOrg);
}
@Override
public List<UserOrgDTO> getUserOrgList(Long userId) {
if (userId == null) {
return null;
}
// 获取用户所有的部门信息
LambdaQueryWrapper<SysUserOrg> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysUserOrg::getUserId, userId);
queryWrapper.orderByDesc(SysUserOrg::getMainFlag);
List<SysUserOrg> sysUserOrgList = this.list(queryWrapper);
// 补充完整用户的部门和职位信息
ArrayList<UserOrgDTO> userOrgDTOS = new ArrayList<>();
for (SysUserOrg sysUserOrg : sysUserOrgList) {
UserOrgDTO userOrgDetailInfo = UserOrgFactory.createUserOrgDetailInfo(sysUserOrg);
userOrgDTOS.add(userOrgDetailInfo);
}
return userOrgDTOS;
}
@Override
public List<Long> getOrgUserIdList(Long orgId, Boolean containSubOrgFlag) {
// 如果不包含查询子公司,则直接查询参数指定公司下的人员
if (!containSubOrgFlag) {
LambdaQueryWrapper<SysUserOrg> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysUserOrg::getOrgId, orgId);
queryWrapper.select(SysUserOrg::getUserId);
List<SysUserOrg> list = this.list(queryWrapper);
return list.stream().map(SysUserOrg::getUserId).collect(Collectors.toList());
}
// 如果包含查询子公司,以及子公司的子公司
Set<Long> subOrgIdList = dbOperatorApi.findSubListByParentId("hr_organization", "org_pids", "org_id", orgId);
subOrgIdList.add(orgId);
LambdaQueryWrapper<SysUserOrg> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SysUserOrg::getOrgId, subOrgIdList);
queryWrapper.select(SysUserOrg::getUserId);
List<SysUserOrg> list = this.list(queryWrapper);
return list.stream().map(SysUserOrg::getUserId).collect(Collectors.toList());
}
/**
*
*
@ -187,7 +241,8 @@ public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUser
for (SysUserOrg sysUserOrg : userOrgList) {
// 校验参数是否缺失
if (ObjectUtil.isEmpty(sysUserOrg.getOrgId()) || ObjectUtil.isEmpty(sysUserOrg.getPositionId()) || ObjectUtil.isEmpty(sysUserOrg.getMainFlag())) {
if (ObjectUtil.isEmpty(sysUserOrg.getOrgId()) || ObjectUtil.isEmpty(sysUserOrg.getPositionId()) || ObjectUtil.isEmpty(
sysUserOrg.getMainFlag())) {
throw new ServiceException(SysUserOrgExceptionEnum.EMPTY_PARAM);
}

View File

@ -126,7 +126,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
SysUser sysUser = this.querySysUser(sysUserRequest);
// 获取用户的组织机构信息
List<UserOrgDTO> userOrgList = sysUserServiceApi.getUserOrgList(sysUser.getUserId());
List<UserOrgDTO> userOrgList = sysUserOrgService.getUserOrgList(sysUser.getUserId());
sysUser.setUserOrgDTOList(userOrgList);
// 获取用户的角色信息
@ -231,7 +231,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 如果传递了组织机构id查询条件则查询对应机构id下有哪些用户再拼接用户查询条件
if (ObjectUtil.isNotEmpty(sysUserRequest.getOrgIdCondition())) {
List<Long> orgUserIdList = this.sysUserServiceApi.getOrgUserIdList(sysUserRequest.getOrgIdCondition(),
List<Long> orgUserIdList = this.sysUserOrgService.getOrgUserIdList(sysUserRequest.getOrgIdCondition(),
true);
queryWrapper.in(SysUser::getUserId, orgUserIdList);
}