mirror of https://gitee.com/stylefeng/roses
【7.4.0】【org】增加获取用户组织机构列表的接口
parent
f95f34972b
commit
2a3cfc07c7
|
@ -95,4 +95,12 @@ public interface OrganizationServiceApi {
|
|||
*/
|
||||
Long getParentLevelOrgId(Long orgId, Integer parentLevelNum, DetectModeEnum detectModeEnum);
|
||||
|
||||
/**
|
||||
* 根据组织机构id,获取这个组织机构的公司信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/4/17 17:12
|
||||
*/
|
||||
HrOrganizationDTO getOrgCompanyInfo(Long orgId);
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ import cn.stylefeng.roses.kernel.system.api.RoleServiceApi;
|
|||
import cn.stylefeng.roses.kernel.system.api.UserOrgServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.UserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.enums.DetectModeEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.enums.OrgTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.enums.organization.OrganizationExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.organization.HrOrganizationDTO;
|
||||
|
@ -497,6 +498,31 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HrOrganizationDTO getOrgCompanyInfo(Long orgId) {
|
||||
|
||||
// 如果组织机构id是空,则直接返回
|
||||
if (ObjectUtil.isEmpty(orgId)) {
|
||||
return new HrOrganizationDTO();
|
||||
}
|
||||
|
||||
// 获取参数公司的信息
|
||||
HrOrganizationDTO orgDetail = this.getOrgDetail(orgId);
|
||||
|
||||
// 如果是到了根节点,则直接返回当前根节点信息
|
||||
if (TreeConstants.DEFAULT_PARENT_ID.equals(orgDetail.getOrgParentId())) {
|
||||
return orgDetail;
|
||||
}
|
||||
|
||||
// 如果是公司则直接返回公司信息
|
||||
if (OrgTypeEnum.COMPANY.getCode().equals(orgDetail.getOrgType())) {
|
||||
return orgDetail;
|
||||
}
|
||||
|
||||
// 如果当前节点是部门,则继续向上查询部门的公司信息
|
||||
return getOrgCompanyInfo(orgDetail.getOrgParentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建组织架构的通用条件查询wrapper
|
||||
*
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.system.modular.user.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.organization.HrOrganizationDTO;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserOrgService;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户组织机构信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/4/17 17:07
|
||||
*/
|
||||
@RestController
|
||||
@ApiResource(name = "用户组织机构信息", resBizType = ResBizTypeEnum.SYSTEM)
|
||||
public class SysUserOrgController {
|
||||
|
||||
@Resource
|
||||
private SysUserOrgService sysUserOrgService;
|
||||
|
||||
/**
|
||||
* 获取当前登录用户所在组织机构列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/4/17 17:08
|
||||
*/
|
||||
@GetResource(name = "获取用户所在组织机构列表", path = "/sysUserOrg/getUserOrgList", requiredPermission = false)
|
||||
public ResponseData<List<HrOrganizationDTO>> getUserOrgList() {
|
||||
List<HrOrganizationDTO> userCompanyList = sysUserOrgService.getUserCompanyList();
|
||||
return new SuccessResponseData<>(userCompanyList);
|
||||
}
|
||||
|
||||
}
|
|
@ -25,6 +25,7 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.api.UserOrgServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.organization.HrOrganizationDTO;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.user.request.UserOrgRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUserOrg;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
@ -51,8 +52,8 @@ public interface SysUserOrgService extends IService<SysUserOrg>, UserOrgServiceA
|
|||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param orgId 机构id
|
||||
* @param userId 用户id
|
||||
* @param orgId 机构id
|
||||
* @author chenjinlong
|
||||
* @since 2021/1/26 12:52
|
||||
*/
|
||||
|
@ -99,8 +100,8 @@ public interface SysUserOrgService extends IService<SysUserOrg>, UserOrgServiceA
|
|||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param orgId 机构id
|
||||
* @param userId 用户id
|
||||
* @param orgId 机构id
|
||||
* @author chenjinlong
|
||||
* @since 2021/1/26 12:52
|
||||
*/
|
||||
|
@ -135,5 +136,12 @@ public interface SysUserOrgService extends IService<SysUserOrg>, UserOrgServiceA
|
|||
*/
|
||||
List<SysUserOrg> findList(UserOrgRequest userOrgResponse);
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的公司列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/4/17 17:11
|
||||
*/
|
||||
List<HrOrganizationDTO> getUserCompanyList();
|
||||
|
||||
}
|
||||
|
|
|
@ -26,9 +26,12 @@ package cn.stylefeng.roses.kernel.system.modular.user.service.impl;
|
|||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.OrganizationServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.enums.user.SysUserOrgExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.organization.HrOrganizationDTO;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.user.SysUserOrgDTO;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.user.request.UserOrgRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUserOrg;
|
||||
|
@ -40,6 +43,7 @@ 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;
|
||||
|
@ -57,6 +61,9 @@ public class SysUserOrgServiceServiceImpl extends ServiceImpl<SysUserOrgMapper,
|
|||
@Resource(name = "userOrgCacheApi")
|
||||
private CacheOperatorApi<SysUserOrgDTO> userOrgCacheApi;
|
||||
|
||||
@Resource
|
||||
private OrganizationServiceApi organizationServiceApi;
|
||||
|
||||
@Override
|
||||
public SysUserOrgDTO getUserOrgByUserId(Long userId) {
|
||||
|
||||
|
@ -89,7 +96,6 @@ public class SysUserOrgServiceServiceImpl extends ServiceImpl<SysUserOrgMapper,
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void add(UserOrgRequest userOrgResponse) {
|
||||
SysUserOrg sysUserOrg = new SysUserOrg();
|
||||
|
@ -183,6 +189,24 @@ public class SysUserOrgServiceServiceImpl extends ServiceImpl<SysUserOrgMapper,
|
|||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HrOrganizationDTO> getUserCompanyList() {
|
||||
|
||||
// 获取当前用户绑定的组织机构列表
|
||||
UserOrgRequest userOrgResponse = new UserOrgRequest();
|
||||
userOrgResponse.setUserId(LoginContext.me().getLoginUser().getUserId());
|
||||
List<SysUserOrg> sysUserOrgList = this.findList(userOrgResponse);
|
||||
|
||||
ArrayList<HrOrganizationDTO> results = new ArrayList<>();
|
||||
for (SysUserOrg sysUserOrg : sysUserOrgList) {
|
||||
|
||||
// 获取用户的公司信息
|
||||
HrOrganizationDTO companyInfo = organizationServiceApi.getOrgCompanyInfo(sysUserOrg.getOrgId());
|
||||
results.add(companyInfo);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getUserOrgFlag(Long orgId, Long positionId) {
|
||||
|
|
Loading…
Reference in New Issue