【7.6.0】【sys】【user】更新用户获取主要部门信息

pull/55/MERGE
fengshuonan 2023-06-12 16:46:05 +08:00
parent c19ee6bea5
commit 7650e6f749
10 changed files with 313 additions and 10 deletions

View File

@ -0,0 +1,54 @@
/*
* 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.sys.api.enums;
import lombok.Getter;
/**
*
*
* @author fengshuonan
* @since 2022/5/21 11:26
*/
@Getter
public enum OrgTypeEnum {
/**
*
*/
COMPANY(1),
/**
*
*/
DEPT(2);
private final Integer code;
OrgTypeEnum(Integer code) {
this.code = code;
}
}

View File

@ -0,0 +1,71 @@
/*
* 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.sys.api.pojo;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import lombok.Data;
/**
*
*
* @author fengshuonan
* @since 2023/6/12 15:41
*/
@Data
public class CompanyDeptDTO {
/**
* id
*/
@ChineseDescription("用户所属公司id")
private Long companyId;
/**
*
*/
@ChineseDescription("用户所属公司名称")
private String companyName;
/**
* id
*/
@ChineseDescription("用户所属部门id")
private Long deptId;
/**
*
*/
@ChineseDescription("用户所属部门名称")
private String deptName;
public CompanyDeptDTO() {
}
public CompanyDeptDTO(Long companyId, String companyName) {
this.companyId = companyId;
this.companyName = companyName;
}
}

View File

@ -28,10 +28,10 @@ import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import lombok.Data;
/**
*
*
*
* @author fengshuonan
* @since 2023/6/11 17:05
* @since 2023/6/12 15:41
*/
@Data
public class UserOrgDTO {

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.sys.modular.org.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.sys.api.pojo.CompanyDeptDTO;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.HrOrganizationRequest;
import com.baomidou.mybatisplus.extension.service.IService;
@ -89,4 +90,24 @@ public interface HrOrganizationService extends IService<HrOrganization> {
*/
List<HrOrganization> commonOrgTree(HrOrganizationRequest hrOrganizationRequest);
/**
* id
*
* @param orgId id
* @return
* @author fengshuonan
* @since 2023/6/12 15:42
*/
CompanyDeptDTO getCompanyDeptInfo(Long orgId);
/**
*
*
* @param hrOrganization
* @return
* @author fengshuonan
* @since 2023/6/12 16:09
*/
CompanyDeptDTO getOrgCompanyInfo(HrOrganization hrOrganization);
}

View File

@ -9,10 +9,13 @@ 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.entity.BaseEntity;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.constants.TreeConstants;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.rule.tree.factory.DefaultTreeBuildFactory;
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveOrgCallbackApi;
import cn.stylefeng.roses.kernel.sys.api.enums.OrgTypeEnum;
import cn.stylefeng.roses.kernel.sys.api.exception.enums.OrgExceptionEnum;
import cn.stylefeng.roses.kernel.sys.api.pojo.CompanyDeptDTO;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
import cn.stylefeng.roses.kernel.sys.modular.org.factory.OrganizationFactory;
import cn.stylefeng.roses.kernel.sys.modular.org.mapper.HrOrganizationMapper;
@ -54,8 +57,7 @@ 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());
// 执行删除操作
@ -71,8 +73,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
// 批量查询组织机构下的下属机构
for (Long orgId : orgIdList) {
// 查询被删除组织机构的所有子级节点
Set<Long> tempSubOrgIdList = DbOperatorContext.me().findSubListByParentId(
"hr_organization", "org_pids", "org_id", orgId);
Set<Long> tempSubOrgIdList = DbOperatorContext.me().findSubListByParentId("hr_organization", "org_pids", "org_id", orgId);
orgIdList.addAll(tempSubOrgIdList);
}
@ -107,8 +108,7 @@ 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);
@ -143,6 +143,56 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
return new DefaultTreeBuildFactory<HrOrganization>().doTreeBuild(hrOrganizationList);
}
@Override
public CompanyDeptDTO getCompanyDeptInfo(Long orgId) {
if (orgId == null) {
return null;
}
HrOrganization hrOrganization = this.getById(orgId);
if (hrOrganization == null) {
return null;
}
// 获取当前组织机构id是公司还是部门如果是公司则直接返回结果
if (OrgTypeEnum.COMPANY.getCode().equals(hrOrganization.getOrgType())) {
return new CompanyDeptDTO(hrOrganization.getOrgId(), hrOrganization.getOrgName());
}
// 如果是部门则递归向上查询到部门所属的公司id
CompanyDeptDTO orgCompanyInfo = this.getOrgCompanyInfo(hrOrganization);
if (orgCompanyInfo != null) {
orgCompanyInfo.setDeptId(hrOrganization.getOrgId());
orgCompanyInfo.setDeptName(hrOrganization.getOrgName());
}
return orgCompanyInfo;
}
@Override
public CompanyDeptDTO getOrgCompanyInfo(HrOrganization hrOrganization) {
if (hrOrganization == null) {
return null;
}
// 如果是到了根节点,则直接返回当前根节点信息
if (TreeConstants.DEFAULT_PARENT_ID.equals(hrOrganization.getOrgParentId())) {
return new CompanyDeptDTO(hrOrganization.getOrgId(), hrOrganization.getOrgName());
}
// 如果当前已经是公司类型,则直接返回
if (OrgTypeEnum.COMPANY.getCode().equals(hrOrganization.getOrgType())) {
return new CompanyDeptDTO(hrOrganization.getOrgId(), hrOrganization.getOrgName());
}
// 查询父级是否是公司
Long orgParentId = hrOrganization.getOrgParentId();
HrOrganization parentOrgInfo = this.getById(orgParentId);
return this.getOrgCompanyInfo(parentOrgInfo);
}
/**
*
*

View File

@ -79,4 +79,12 @@ public interface HrPositionService extends IService<HrPosition> {
*/
PageResult<HrPosition> findPage(HrPositionRequest hrPositionRequest);
/**
*
*
* @author fengshuonan
* @since 2023/6/12 16:38
*/
String getPositionName(Long positionId);
}

View File

@ -93,6 +93,23 @@ public class HrPositionServiceImpl extends ServiceImpl<HrPositionMapper, HrPosit
return PageResultFactory.createPageResult(sysRolePage);
}
@Override
public String getPositionName(Long positionId) {
if (positionId == null) {
return null;
}
LambdaQueryWrapper<HrPosition> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(HrPosition::getPositionId, positionId);
queryWrapper.select(HrPosition::getPositionName);
HrPosition hrPosition = this.getOne(queryWrapper);
if (hrPosition == null) {
return null;
} else {
return hrPosition.getPositionName();
}
}
@Override
public List<HrPosition> findList(HrPositionRequest hrPositionRequest) {
LambdaQueryWrapper<HrPosition> wrapper = this.createWrapper(hrPositionRequest);

View File

@ -2,10 +2,15 @@ package cn.stylefeng.roses.kernel.sys.modular.user.biz;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.file.api.FileInfoApi;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.sys.api.SysUserServiceApi;
import cn.stylefeng.roses.kernel.sys.api.exception.SysException;
import cn.stylefeng.roses.kernel.sys.api.pojo.SimpleUserDTO;
import cn.stylefeng.roses.kernel.sys.api.pojo.UserOrgDTO;
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.factory.UserOrgFactory;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
@ -13,6 +18,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import static cn.stylefeng.roses.kernel.sys.modular.user.enums.SysUserOrgExceptionEnum.MAIN_FLAG_COUNT_ERROR;
/**
*
*
@ -28,6 +35,9 @@ public class UserIntegrationService implements SysUserServiceApi {
@Resource
private FileInfoApi fileInfoApi;
@Resource
private SysUserOrgService sysUserOrgService;
@Override
public SimpleUserDTO getUserInfoByUserId(Long userId) {
@ -62,7 +72,22 @@ public class UserIntegrationService implements SysUserServiceApi {
@Override
public UserOrgDTO getUserMainOrgInfo(Long userId) {
return null;
if (userId == null) {
return null;
}
LambdaQueryWrapper<SysUserOrg> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysUserOrg::getUserId, userId);
queryWrapper.eq(SysUserOrg::getMainFlag, YesOrNotEnum.Y.getCode());
List<SysUserOrg> sysUserOrgList = sysUserOrgService.list(queryWrapper);
if (sysUserOrgList.size() > 1) {
throw new SysException(MAIN_FLAG_COUNT_ERROR, userId);
}
// 获取到用户的主部门信息
SysUserOrg sysUserOrg = sysUserOrgList.get(0);
return UserOrgFactory.createUserOrgDetailInfo(sysUserOrg);
}
@Override

View File

@ -26,7 +26,12 @@ public enum SysUserOrgExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
MAIN_FLAG_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10003", "用户主部门数量错误,请确保用户有且只有一个主部门");
MAIN_FLAG_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10003", "用户主部门数量错误,请确保用户有且只有一个主部门"),
/**
*
*/
MAIN_FLAG_COUNT_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10004", "用户主部门数量错误用户存在多个主部门信息请纠正数据错误用户id为{}");
/**
*

View File

@ -0,0 +1,52 @@
package cn.stylefeng.roses.kernel.sys.modular.user.factory;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.stylefeng.roses.kernel.sys.api.pojo.CompanyDeptDTO;
import cn.stylefeng.roses.kernel.sys.api.pojo.UserOrgDTO;
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;
import cn.stylefeng.roses.kernel.sys.modular.position.service.HrPositionService;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserOrg;
/**
*
*
* @author fengshuonan
* @since 2023/6/12 15:31
*/
public class UserOrgFactory {
/**
*
*
* @author fengshuonan
* @since 2023/6/12 15:36
*/
public static UserOrgDTO createUserOrgDetailInfo(SysUserOrg sysUserOrg) {
UserOrgDTO result = new UserOrgDTO();
result.setUserId(sysUserOrg.getUserId());
result.setMainFlag(sysUserOrg.getMainFlag());
// 获取用户的组织机构id
Long orgId = sysUserOrg.getOrgId();
// 获取用户的职位id
Long positionId = sysUserOrg.getPositionId();
// 先获取组织机构对应的公司和部门的详情信息
HrOrganizationService hrOrganizationService = SpringUtil.getBean(HrOrganizationService.class);
CompanyDeptDTO companyDeptInfo = hrOrganizationService.getCompanyDeptInfo(orgId);
BeanUtil.copyProperties(companyDeptInfo, result);
// 再获取职位对应的名称
HrPositionService hrPositionService = SpringUtil.getBean(HrPositionService.class);
String positionName = hrPositionService.getPositionName(positionId);
result.setPositionId(positionId);
result.setPositionName(positionName);
return result;
}
}