mirror of https://gitee.com/stylefeng/roses
【7.6.0】【sys】【首页用户详情接口】补全用户机构信息
parent
4fce080788
commit
abff52c1a3
|
@ -57,7 +57,8 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
public void del(HrOrganizationRequest hrOrganizationRequest) {
|
||||
|
||||
// 查询被删除组织机构的所有子级节点
|
||||
Set<Long> totalOrgIdSet = DbOperatorContext.me().findSubListByParentId("hr_organization", "org_pids", "org_id", hrOrganizationRequest.getOrgId());
|
||||
Set<Long> totalOrgIdSet = DbOperatorContext.me()
|
||||
.findSubListByParentId("hr_organization", "org_pids", "org_id", hrOrganizationRequest.getOrgId());
|
||||
totalOrgIdSet.add(hrOrganizationRequest.getOrgId());
|
||||
|
||||
// 执行删除操作
|
||||
|
@ -108,7 +109,8 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
LambdaQueryWrapper<HrOrganization> wrapper = createWrapper(hrOrganizationRequest);
|
||||
|
||||
// 只查询需要的字段
|
||||
wrapper.select(HrOrganization::getOrgId, HrOrganization::getOrgName, HrOrganization::getOrgCode, HrOrganization::getStatusFlag, HrOrganization::getOrgType, HrOrganization::getOrgSort, BaseEntity::getCreateTime);
|
||||
wrapper.select(HrOrganization::getOrgId, HrOrganization::getOrgName, HrOrganization::getOrgCode, HrOrganization::getStatusFlag,
|
||||
HrOrganization::getOrgType, HrOrganization::getOrgSort, BaseEntity::getCreateTime);
|
||||
|
||||
Page<HrOrganization> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
|
||||
return PageResultFactory.createPageResult(sysRolePage);
|
||||
|
@ -119,7 +121,8 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
|
||||
// 根据条件查询组织机构列表
|
||||
LambdaQueryWrapper<HrOrganization> wrapper = this.createWrapper(hrOrganizationRequest);
|
||||
wrapper.select(HrOrganization::getOrgId, HrOrganization::getOrgParentId, HrOrganization::getOrgPids, HrOrganization::getOrgName, HrOrganization::getOrgSort, HrOrganization::getOrgType);
|
||||
wrapper.select(HrOrganization::getOrgId, HrOrganization::getOrgParentId, HrOrganization::getOrgPids, HrOrganization::getOrgName,
|
||||
HrOrganization::getOrgSort, HrOrganization::getOrgType);
|
||||
List<HrOrganization> hrOrganizationList = this.list(wrapper);
|
||||
|
||||
if (ObjectUtil.isEmpty(hrOrganizationList)) {
|
||||
|
@ -162,6 +165,8 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
|
||||
// 如果是部门,则递归向上查询到部门所属的公司id
|
||||
CompanyDeptDTO orgCompanyInfo = this.getOrgCompanyInfo(hrOrganization);
|
||||
|
||||
// 查到公司id之后,设置部门id则为参数orgId
|
||||
if (orgCompanyInfo != null) {
|
||||
orgCompanyInfo.setDeptId(hrOrganization.getOrgId());
|
||||
orgCompanyInfo.setDeptName(hrOrganization.getOrgName());
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
* @since 2023/6/18 22:26
|
||||
*/
|
||||
@Data
|
||||
public class UserMenuInfo {
|
||||
public class IndexUserMenuInfo {
|
||||
|
||||
/**
|
||||
* 菜单id
|
||||
|
@ -73,6 +73,6 @@ public class UserMenuInfo {
|
|||
* 子级菜单
|
||||
*/
|
||||
@ChineseDescription("子级菜单")
|
||||
private List<UserMenuInfo> children;
|
||||
private List<IndexUserMenuInfo> children;
|
||||
|
||||
}
|
|
@ -5,13 +5,13 @@ import lombok.Data;
|
|||
|
||||
|
||||
/**
|
||||
* 用户组织机构的绑定关系
|
||||
* 用户组织机构的绑定关系,用在首页获取用户信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/18 22:12
|
||||
*/
|
||||
@Data
|
||||
public class UserOrgInfo {
|
||||
public class IndexUserOrgInfo {
|
||||
|
||||
/**
|
||||
* 用户id
|
|
@ -38,7 +38,7 @@ public class UserIndexInfo {
|
|||
* 当前用户的部门和任职信息
|
||||
*/
|
||||
@ChineseDescription("当前用户的部门和任职信息")
|
||||
private List<UserOrgInfo> userOrgInfo;
|
||||
private List<IndexUserOrgInfo> userOrgInfo;
|
||||
|
||||
/**
|
||||
* 当前用户的权限编码集合,包括【菜单编码】和【菜单功能编码】
|
||||
|
@ -56,7 +56,7 @@ public class UserIndexInfo {
|
|||
* 用户菜单集合
|
||||
*/
|
||||
@ChineseDescription("用户菜单集合")
|
||||
private List<UserMenuInfo> menuList;
|
||||
private List<IndexUserMenuInfo> menuList;
|
||||
|
||||
/**
|
||||
* 菜单路由和appId的映射关系
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.login.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysUserOrgServiceApi;
|
||||
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.modular.login.pojo.IndexUserOrgInfo;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.login.pojo.UserIndexInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 获取用户首页信息的业务
|
||||
|
@ -21,6 +28,9 @@ public class UserIndexInfoService {
|
|||
@Resource
|
||||
private SysUserServiceApi sysUserServiceApi;
|
||||
|
||||
@Resource
|
||||
private SysUserOrgServiceApi sysUserOrgServiceApi;
|
||||
|
||||
/**
|
||||
* 获取用户首页信息
|
||||
*
|
||||
|
@ -38,7 +48,8 @@ public class UserIndexInfoService {
|
|||
// 1. 获取用户的姓名和头像
|
||||
this.fillUserBaseInfo(loginUser.getUserId(), userIndexInfo);
|
||||
|
||||
// 2. 获取用户的部门和任职信息
|
||||
// 2. 获取用户所有的部门和任职信息,并默认激活(选中)主部门的任职信息
|
||||
this.fillUserOrgInfo(loginUser, userIndexInfo);
|
||||
|
||||
// 3. 获取用户的权限编码集合
|
||||
|
||||
|
@ -64,4 +75,78 @@ public class UserIndexInfoService {
|
|||
userIndexInfo.setAvatarUrl(simpleUserDTO.getAvatarUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的任职信息,包含了机构的详细描述
|
||||
* <p>
|
||||
* 如果指定用户没有当前激活的组织机构id,则直接指定默认的组织机构
|
||||
* <p>
|
||||
* 用在首页获取用户详情接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/18 23:33
|
||||
*/
|
||||
private void fillUserOrgInfo(LoginUser loginUser, UserIndexInfo userIndexInfo) {
|
||||
|
||||
List<IndexUserOrgInfo> resultUserOrg = new ArrayList<>();
|
||||
|
||||
// 获取当前用户是否有已经激活的公司id
|
||||
Long currentOrgId = loginUser.getCurrentOrgId();
|
||||
|
||||
// 获取用户的所有组织机构集合
|
||||
List<UserOrgDTO> userOrgList = sysUserOrgServiceApi.getUserOrgList(loginUser.getUserId());
|
||||
|
||||
// 查询到机构为空,直接返回
|
||||
if (ObjectUtil.isEmpty(userOrgList)) {
|
||||
userIndexInfo.setUserOrgInfo(resultUserOrg);
|
||||
return;
|
||||
}
|
||||
|
||||
// 将查询结果转化为前端需要的信息
|
||||
for (UserOrgDTO userOrgItem : userOrgList) {
|
||||
IndexUserOrgInfo indexUserOrgInfo = new IndexUserOrgInfo();
|
||||
indexUserOrgInfo.setUserId(loginUser.getUserId());
|
||||
|
||||
// 设置当前orgId为部门id,如果部门id为空,则代表当前用户只绑定到公司id了
|
||||
if (ObjectUtil.isNotEmpty(userOrgItem.getDeptId())) {
|
||||
indexUserOrgInfo.setOrgId(userOrgItem.getDeptId());
|
||||
} else {
|
||||
indexUserOrgInfo.setOrgId(userOrgItem.getCompanyId());
|
||||
}
|
||||
|
||||
indexUserOrgInfo.setCompanyName(userOrgItem.getCompanyName());
|
||||
indexUserOrgInfo.setDeptName(userOrgItem.getDeptName());
|
||||
indexUserOrgInfo.setPositionName(userOrgItem.getPositionName());
|
||||
|
||||
// 设置是否是主要任职部门
|
||||
indexUserOrgInfo.setMainFlag(YesOrNotEnum.Y.getCode().equals(userOrgItem.getMainFlag()));
|
||||
|
||||
resultUserOrg.add(indexUserOrgInfo);
|
||||
}
|
||||
|
||||
// 设置用户的选中的组织机构
|
||||
// 如果当前没激活的组织机构,则直接将主部门激活
|
||||
if (currentOrgId == null) {
|
||||
for (IndexUserOrgInfo indexUserOrgInfo : resultUserOrg) {
|
||||
if (indexUserOrgInfo.getMainFlag()) {
|
||||
indexUserOrgInfo.setCurrentSelectFlag(true);
|
||||
} else {
|
||||
indexUserOrgInfo.setCurrentSelectFlag(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果有激活的组织机构
|
||||
else {
|
||||
for (IndexUserOrgInfo indexUserOrgInfo : resultUserOrg) {
|
||||
if (indexUserOrgInfo.getOrgId().equals(currentOrgId)) {
|
||||
indexUserOrgInfo.setCurrentSelectFlag(true);
|
||||
} else {
|
||||
indexUserOrgInfo.setCurrentSelectFlag(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 填充用户组织机构信息
|
||||
userIndexInfo.setUserOrgInfo(resultUserOrg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue