【7.6.0】【sys】【首页用户详情接口】补全用户机构信息

pull/57/head
fengshuonan 2023-06-18 23:59:35 +08:00
parent 4fce080788
commit abff52c1a3
5 changed files with 100 additions and 10 deletions

View File

@ -57,7 +57,8 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
public void del(HrOrganizationRequest hrOrganizationRequest) { 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()); totalOrgIdSet.add(hrOrganizationRequest.getOrgId());
// 执行删除操作 // 执行删除操作
@ -108,7 +109,8 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
LambdaQueryWrapper<HrOrganization> wrapper = createWrapper(hrOrganizationRequest); 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); Page<HrOrganization> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(sysRolePage); return PageResultFactory.createPageResult(sysRolePage);
@ -119,7 +121,8 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
// 根据条件查询组织机构列表 // 根据条件查询组织机构列表
LambdaQueryWrapper<HrOrganization> wrapper = this.createWrapper(hrOrganizationRequest); 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); List<HrOrganization> hrOrganizationList = this.list(wrapper);
if (ObjectUtil.isEmpty(hrOrganizationList)) { if (ObjectUtil.isEmpty(hrOrganizationList)) {
@ -162,6 +165,8 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
// 如果是部门则递归向上查询到部门所属的公司id // 如果是部门则递归向上查询到部门所属的公司id
CompanyDeptDTO orgCompanyInfo = this.getOrgCompanyInfo(hrOrganization); CompanyDeptDTO orgCompanyInfo = this.getOrgCompanyInfo(hrOrganization);
// 查到公司id之后设置部门id则为参数orgId
if (orgCompanyInfo != null) { if (orgCompanyInfo != null) {
orgCompanyInfo.setDeptId(hrOrganization.getOrgId()); orgCompanyInfo.setDeptId(hrOrganization.getOrgId());
orgCompanyInfo.setDeptName(hrOrganization.getOrgName()); orgCompanyInfo.setDeptName(hrOrganization.getOrgName());

View File

@ -13,7 +13,7 @@ import java.util.List;
* @since 2023/6/18 22:26 * @since 2023/6/18 22:26
*/ */
@Data @Data
public class UserMenuInfo { public class IndexUserMenuInfo {
/** /**
* id * id
@ -73,6 +73,6 @@ public class UserMenuInfo {
* *
*/ */
@ChineseDescription("子级菜单") @ChineseDescription("子级菜单")
private List<UserMenuInfo> children; private List<IndexUserMenuInfo> children;
} }

View File

@ -5,13 +5,13 @@ import lombok.Data;
/** /**
* *
* *
* @author fengshuonan * @author fengshuonan
* @since 2023/6/18 22:12 * @since 2023/6/18 22:12
*/ */
@Data @Data
public class UserOrgInfo { public class IndexUserOrgInfo {
/** /**
* id * id

View File

@ -38,7 +38,7 @@ public class UserIndexInfo {
* *
*/ */
@ChineseDescription("当前用户的部门和任职信息") @ChineseDescription("当前用户的部门和任职信息")
private List<UserOrgInfo> userOrgInfo; private List<IndexUserOrgInfo> userOrgInfo;
/** /**
* *
@ -56,7 +56,7 @@ public class UserIndexInfo {
* *
*/ */
@ChineseDescription("用户菜单集合") @ChineseDescription("用户菜单集合")
private List<UserMenuInfo> menuList; private List<IndexUserMenuInfo> menuList;
/** /**
* appId * appId

View File

@ -1,13 +1,20 @@
package cn.stylefeng.roses.kernel.sys.modular.login.service; 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.context.LoginContext;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser; 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.SysUserServiceApi;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.SimpleUserDTO; 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 cn.stylefeng.roses.kernel.sys.modular.login.pojo.UserIndexInfo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/** /**
* *
@ -21,6 +28,9 @@ public class UserIndexInfoService {
@Resource @Resource
private SysUserServiceApi sysUserServiceApi; private SysUserServiceApi sysUserServiceApi;
@Resource
private SysUserOrgServiceApi sysUserOrgServiceApi;
/** /**
* *
* *
@ -38,7 +48,8 @@ public class UserIndexInfoService {
// 1. 获取用户的姓名和头像 // 1. 获取用户的姓名和头像
this.fillUserBaseInfo(loginUser.getUserId(), userIndexInfo); this.fillUserBaseInfo(loginUser.getUserId(), userIndexInfo);
// 2. 获取用户的部门和任职信息 // 2. 获取用户所有的部门和任职信息,并默认激活(选中)主部门的任职信息
this.fillUserOrgInfo(loginUser, userIndexInfo);
// 3. 获取用户的权限编码集合 // 3. 获取用户的权限编码集合
@ -64,4 +75,78 @@ public class UserIndexInfoService {
userIndexInfo.setAvatarUrl(simpleUserDTO.getAvatarUrl()); 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);
}
} }