diff --git a/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/enums/OrgTypeEnum.java b/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/enums/OrgTypeEnum.java new file mode 100644 index 000000000..f171f0c76 --- /dev/null +++ b/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/enums/OrgTypeEnum.java @@ -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. + * + * 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.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; + } + +} diff --git a/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/CompanyDeptDTO.java b/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/CompanyDeptDTO.java new file mode 100644 index 000000000..3d77201ba --- /dev/null +++ b/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/CompanyDeptDTO.java @@ -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. + * + * 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.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; + } + +} diff --git a/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/UserOrgDTO.java b/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/UserOrgDTO.java index d30d04066..877b727c7 100644 --- a/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/UserOrgDTO.java +++ b/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/UserOrgDTO.java @@ -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 { diff --git a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/HrOrganizationService.java b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/HrOrganizationService.java index 520dfb61c..673744794 100644 --- a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/HrOrganizationService.java +++ b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/HrOrganizationService.java @@ -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 { */ List 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); + } \ No newline at end of file diff --git a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/impl/HrOrganizationServiceImpl.java b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/impl/HrOrganizationServiceImpl.java index f200c1366..402ed480b 100644 --- a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/impl/HrOrganizationServiceImpl.java +++ b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/impl/HrOrganizationServiceImpl.java @@ -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 totalOrgIdSet = DbOperatorContext.me().findSubListByParentId( - "hr_organization", "org_pids", "org_id", hrOrganizationRequest.getOrgId()); + Set 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 tempSubOrgIdList = DbOperatorContext.me().findSubListByParentId( - "hr_organization", "org_pids", "org_id", orgId); + Set tempSubOrgIdList = DbOperatorContext.me().findSubListByParentId("hr_organization", "org_pids", "org_id", orgId); orgIdList.addAll(tempSubOrgIdList); } @@ -107,8 +108,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl 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 sysRolePage = this.page(PageFactory.defaultPage(), wrapper); return PageResultFactory.createPageResult(sysRolePage); @@ -143,6 +143,56 @@ public class HrOrganizationServiceImpl extends ServiceImpl().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); + } + /** * 获取信息 * diff --git a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/position/service/HrPositionService.java b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/position/service/HrPositionService.java index 946f61694..15e2b5015 100644 --- a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/position/service/HrPositionService.java +++ b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/position/service/HrPositionService.java @@ -79,4 +79,12 @@ public interface HrPositionService extends IService { */ PageResult findPage(HrPositionRequest hrPositionRequest); + /** + * 获取职务的名称 + * + * @author fengshuonan + * @since 2023/6/12 16:38 + */ + String getPositionName(Long positionId); + } \ No newline at end of file diff --git a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/position/service/impl/HrPositionServiceImpl.java b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/position/service/impl/HrPositionServiceImpl.java index 3efe9b4a6..fb62b79d9 100644 --- a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/position/service/impl/HrPositionServiceImpl.java +++ b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/position/service/impl/HrPositionServiceImpl.java @@ -93,6 +93,23 @@ public class HrPositionServiceImpl extends ServiceImpl 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 findList(HrPositionRequest hrPositionRequest) { LambdaQueryWrapper wrapper = this.createWrapper(hrPositionRequest); diff --git a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/biz/UserIntegrationService.java b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/biz/UserIntegrationService.java index 4a6062af0..d3178b9a1 100644 --- a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/biz/UserIntegrationService.java +++ b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/biz/UserIntegrationService.java @@ -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 queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysUserOrg::getUserId, userId); + queryWrapper.eq(SysUserOrg::getMainFlag, YesOrNotEnum.Y.getCode()); + List 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 diff --git a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/enums/SysUserOrgExceptionEnum.java b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/enums/SysUserOrgExceptionEnum.java index e8cbf0c36..3b780e4d6 100644 --- a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/enums/SysUserOrgExceptionEnum.java +++ b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/enums/SysUserOrgExceptionEnum.java @@ -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为:{}"); /** * 错误编码 diff --git a/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/factory/UserOrgFactory.java b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/factory/UserOrgFactory.java new file mode 100644 index 000000000..246345f9a --- /dev/null +++ b/kernel-s-sys/sys-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/factory/UserOrgFactory.java @@ -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; + } + +}