From b9e17e056888f69cc6ce7bdbd3d786d693b78e81 Mon Sep 17 00:00:00 2001 From: xiao-fajia <1665375861@qq.com> Date: Wed, 14 Aug 2024 20:01:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=98=E5=B7=A5=E5=8A=A0=E8=A7=92=E8=89=B2(?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E3=80=81=E4=BA=A4=E6=8E=A5=E5=BE=85=E5=AE=8C?= =?UTF-8?q?=E5=96=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/CommonErrorCodeConstants.java | 1 + .../admin/CompanyStaffController.java | 13 +++ .../module/staff/entity/CompanyStaff.java | 12 ++ .../staff/service/CompanyStaffService.java | 8 ++ .../service/impl/CompanyStaffServiceImpl.java | 45 +++++++- .../module/staff/vo/CompanyStaffReqVO.java | 2 + .../mapper/staff/CompanyStaffMapper.xml | 107 ++++++++++-------- .../system/api/permission/PermissionApi.java | 18 +++ .../module/system/api/permission/RoleApi.java | 10 ++ .../api/permission/PermissionApiImpl.java | 27 +++++ .../system/api/permission/RoleApiImpl.java | 21 ++++ 11 files changed, 212 insertions(+), 52 deletions(-) diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java index 3be789cf..f35bdb37 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java @@ -9,4 +9,5 @@ public interface CommonErrorCodeConstants extends ErrorCodeConstants { ErrorCode UNIQUE_CODE_CREATE_REPEAT = new ErrorCode(2_002_000_000, "唯一推广码生成失败"); ErrorCode STAFF_CHANGE_CREATE_REPEAT = new ErrorCode(2_002_000_001, "该员工工作已交接"); ErrorCode STAFF_NOT_CHANGE = new ErrorCode(2_002_000_003, "该员工还有工作未交接,不可删除"); + ErrorCode LOGIN_ACCOUNT_EXIST = new ErrorCode(2_002_000_004, "登录账号已存在"); } diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/admin/CompanyStaffController.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/admin/CompanyStaffController.java index 3c181ceb..934379f1 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/admin/CompanyStaffController.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/admin/CompanyStaffController.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.staff.entity.CompanyStaff; import cn.iocoder.yudao.module.staff.service.CompanyStaffService; import cn.iocoder.yudao.module.staff.vo.CompanyStaffReqVO; import cn.iocoder.yudao.module.staff.vo.CompanyStaffRespVO; +import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.v3.oas.annotations.Operation; @@ -200,4 +201,16 @@ public class CompanyStaffController { staffService.resetPassword(staffRespVO); return CommonResult.ok(); } + + /** + * 获取角色列表 + * @author 小李 + * @date 15:08 2024/8/14 + **/ + @GetMapping("/roleList") + @Operation(summary = "获取角色列表") + @PreAuthorize("@ss.hasPermission('company:staff:query')") + public CommonResult> getRoleList(){ + return success(staffService.getRoleList()); + } } diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/entity/CompanyStaff.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/entity/CompanyStaff.java index add42b79..919a8a3f 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/entity/CompanyStaff.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/entity/CompanyStaff.java @@ -1,12 +1,14 @@ package cn.iocoder.yudao.module.staff.entity; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; @@ -15,7 +17,9 @@ import lombok.EqualsAndHashCode; import org.springframework.format.annotation.DateTimeFormat; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import static cn.iocoder.yudao.common.DictBaseConstants.*; @@ -98,4 +102,12 @@ public class CompanyStaff extends TenantBaseDO { /** 附件urls(infra_file表中的url,多个英文逗号拼接) */ private String fileUrls; + + /** 员工角色ID集合 */ + @TableField(exist = false) + private List roleIds; + + /** 员工角色名称们(,分隔) */ + @TableField(exist = false) + private String roleNames; } diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/CompanyStaffService.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/CompanyStaffService.java index 3c188bb6..aa30d64d 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/CompanyStaffService.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/CompanyStaffService.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.staff.entity.CompanyStaff; import cn.iocoder.yudao.module.label.entity.Label; import cn.iocoder.yudao.module.staff.vo.CompanyStaffReqVO; import cn.iocoder.yudao.module.staff.vo.CompanyStaffRespVO; +import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; @@ -94,4 +95,11 @@ public interface CompanyStaffService extends IService { * @date 11:41 2024/8/13 **/ void updateStaffWorkAndJoinedYears(); + + /** + * 获取当前租户有些什么角色可以分配 + * @author 小李 + * @date 14:53 2024/8/14 + **/ + List getRoleList(); } diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffServiceImpl.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffServiceImpl.java index 6eb601cf..a7cabf39 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffServiceImpl.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffServiceImpl.java @@ -4,9 +4,7 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.common.BaseConstants; import cn.iocoder.yudao.common.CommonErrorCodeConstants; -import cn.iocoder.yudao.framework.datapermission.core.rule.DataPermissionRule; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; -import cn.iocoder.yudao.module.company.service.CompanyService; import cn.iocoder.yudao.module.label.entity.BusiLabel; import cn.iocoder.yudao.module.label.entity.Label; import cn.iocoder.yudao.module.label.service.BusiLabelService; @@ -20,6 +18,9 @@ import cn.iocoder.yudao.module.staff.vo.CompanyStaffReqVO; import cn.iocoder.yudao.module.staff.vo.CompanyStaffRespVO; import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; +import cn.iocoder.yudao.module.system.api.permission.PermissionApi; +import cn.iocoder.yudao.module.system.api.permission.RoleApi; +import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import cn.iocoder.yudao.module.system.api.user.dto.UserDTO; @@ -37,6 +38,7 @@ import java.time.LocalDate; import java.time.Period; import java.time.ZoneId; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.config.CommonStr.USER_TYPE_STAFF; @@ -72,6 +74,12 @@ public class CompanyStaffServiceImpl extends ServiceImpl roleIds = staffRespVO.getRoleIds().stream().collect(Collectors.toSet()); + permissionApi.assignUserRoleByRoleIds(userId, roleIds); + /* 插入标签到业务标签表 */ if (ObjectUtil.isNotEmpty(staffRespVO.getLabelsArray())) { // 1 获取所有标签信息 @@ -198,6 +216,12 @@ public class CompanyStaffServiceImpl extends ServiceImpl roleIdes = staffRespVO.getRoleIds().stream().collect(Collectors.toSet()); + permissionApi.assignUserRoleByRoleIds(staffRespVO.getUserId(), roleIdes); + } + /* 修改员工表 */ baseMapper.updateById(staffRespVO); } @@ -227,6 +251,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl().eq(BusiLabel::getMainId, staff.getId())); + /* 删除员工表记录 */ baseMapper.deleteById(id); } @@ -251,6 +276,9 @@ public class CompanyStaffServiceImpl extends ServiceImpl labelsArray = busiLabels.stream().map(item -> item.getLabelName()).collect(Collectors.toList()); staffRespVO.setLabelsArray(labelsArray); } + // 查角色ID给响应对象 + List roleIds = permissionApi.getRoleIdsByUserId(staff.getUserId()); + staffRespVO.setRoleIds(roleIds); return staffRespVO; } @@ -427,7 +455,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl getRoleList() { + return roleApi.getRoleList(); + } } diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/vo/CompanyStaffReqVO.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/vo/CompanyStaffReqVO.java index a4c5b994..ae180284 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/vo/CompanyStaffReqVO.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/vo/CompanyStaffReqVO.java @@ -24,4 +24,6 @@ public class CompanyStaffReqVO extends CompanyStaff { @Schema(description = "入职日期查询范围") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private Date[] joinedDateArray; + + } diff --git a/dl-module-company/src/main/resources/mapper/staff/CompanyStaffMapper.xml b/dl-module-company/src/main/resources/mapper/staff/CompanyStaffMapper.xml index 59bd73dd..3f201670 100644 --- a/dl-module-company/src/main/resources/mapper/staff/CompanyStaffMapper.xml +++ b/dl-module-company/src/main/resources/mapper/staff/CompanyStaffMapper.xml @@ -5,57 +5,60 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - select id, - corp_id, - user_id, - dept_id, - work_no, - name, - tel, - sex, - address, - work_date, - work_year, - joined_date, - joined_year, - education, - content, - unique_code, - file_urls, - tenant_id, - deleted, - creator, - create_time, - updater, - update_time - from company_staff cs - where deleted = '0' + SELECT cs.id AS cs_id, + cs.corp_id AS cs_corp_id, + cs.user_id AS cs_user_id, + cs.dept_id AS cs_dept_id, + cs.work_no AS cs_work_no, + cs.name AS cs_name, + cs.tel AS cs_tel, + cs.sex AS cs_sex, + cs.address AS cs_address, + cs.work_date AS cs_work_date, + cs.work_year AS cs_work_year, + cs.joined_date AS cs_joined_date, + cs.joined_year AS cs_joined_year, + cs.education AS cs_education, + cs.content AS cs_content, + cs.unique_code AS cs_unique_code, + cs.file_urls AS cs_file_urls, + rn.role_names AS role_names + FROM company_staff cs + LEFT JOIN + ( + SELECT cs.user_id, + sr.id, + GROUP_CONCAT(DISTINCT sr.name ORDER BY sr.name SEPARATOR ',') AS role_names + FROM company_staff cs + LEFT JOIN + system_user_role sur ON cs.user_id = sur.user_id + LEFT JOIN + system_role sr ON sur.role_id = sr.id + WHERE cs.deleted = '0' AND sur.deleted = '0' + GROUP BY cs.user_id + ) rn ON cs.user_id = rn.user_id + WHERE cs.deleted = '0' \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApi.java index a59e758a..4487a93e 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApi.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.api.permission; import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO; import java.util.Collection; +import java.util.List; import java.util.Set; /** @@ -54,4 +55,21 @@ public interface PermissionApi { */ void assignUserRole(Long userId, Set roleCodes); + /** + * 设置用户角色 + * + * @author 小李 + * @date 18:58 2024/8/14 + * @param userId 用户D + * @param roleIds 角色IDs + **/ + void assignUserRoleByRoleIds(Long userId, Set roleIds); + + /** + * 获取某个用户的角色IDs + * @author 小李 + * @date 19:24 2024/8/14 + * @param userId 用户ID + **/ + List getRoleIdsByUserId(Long userId); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApi.java index 309c9ef6..55ce477c 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApi.java @@ -1,6 +1,9 @@ package cn.iocoder.yudao.module.system.api.permission; +import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO; + import java.util.Collection; +import java.util.List; /** * 角色 API 接口 @@ -18,4 +21,11 @@ public interface RoleApi { */ void validRoleList(Collection ids); + /** + * 查询角色列表 + * @author 小李 + * @date 15:03 2024/8/14 + **/ + List getRoleList(); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApiImpl.java index 654338a0..741a84c9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApiImpl.java @@ -6,7 +6,9 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * 权限 API 实现类 @@ -50,4 +52,29 @@ public class PermissionApiImpl implements PermissionApi { permissionService.assignUserRoleByCodes(userId, roleCodes); } + /** + * 设置用户角色 + * + * @author 小李 + * @date 18:58 2024/8/14 + * @param userId 用户D + * @param roleIds 角色IDs + **/ + @Override + public void assignUserRoleByRoleIds(Long userId, Set roleIds){ + permissionService.assignUserRole(userId, roleIds); + } + + /** + * 获取某个用户的角色IDs + * @author 小李 + * @date 19:24 2024/8/14 + * @param userId 用户ID + **/ + @Override + public List getRoleIdsByUserId(Long userId){ + Set roleIds = permissionService.getUserRoleIdListByUserId(userId); + return roleIds.stream().collect(Collectors.toList()); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApiImpl.java index d8622a29..4eb768b3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApiImpl.java @@ -1,10 +1,15 @@ package cn.iocoder.yudao.module.system.api.permission; +import cn.hutool.core.bean.BeanUtil; +import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO; +import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.service.permission.RoleService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; /** * 角色 API 实现类 @@ -21,4 +26,20 @@ public class RoleApiImpl implements RoleApi { public void validRoleList(Collection ids) { roleService.validateRoleList(ids); } + + /** + * 查询角色列表 + * @author 小李 + * @date 15:03 2024/8/14 + **/ + @Override + public List getRoleList(){ + List roleList = roleService.getRoleList(); + List result = roleList.stream().map(item -> { + RoleReqDTO roleReqDTO = new RoleReqDTO(); + BeanUtil.copyProperties(item, roleReqDTO); + return roleReqDTO; + }).collect(Collectors.toList()); + return result; + } }