【7.4.0】【org】增加获取用户组织机构列表的接口

dev-7.4.0-sync
fengshuonan 2023-04-17 17:40:51 +08:00
parent f95f34972b
commit 2a3cfc07c7
5 changed files with 135 additions and 5 deletions

View File

@ -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);
}

View File

@ -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
*

View File

@ -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.
*
* GunsAPACHE 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);
}
}

View File

@ -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();
}

View File

@ -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) {