From 157b166435fbaf3fd278d2d16214352f47afc3bf Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Fri, 1 May 2020 11:04:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=20system=20=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=EF=BC=8Cadmin=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-web/src/models/admin/adminList.js | 10 +- admin-web/src/pages/Admin/AdminList.js | 61 ++++-------- admin-web/src/pages/Admin/RoleList.js | 24 ++++- admin-web/src/services/system.js | 8 ++ .../common/framework/util/CollectionUtil.java | 6 ++ system/pom.xml | 4 +- .../system/biz/enums/SystemErrorCodeEnum.java | 5 + .../biz/enums/admin/AdminStatusEnum.java | 41 ++++++++ .../enums/authorization/ResourceIdEnum.java | 6 ++ .../enums/authorization/ResourceTypeEnum.java | 2 +- .../mall/system/biz/bo/admin/AdminBO.java | 18 ++++ .../system/biz/bo/authorization/RoleBO.java | 4 + .../biz/convert/admin/AdminConvert.java | 6 ++ .../biz/convert/oauth2/OAuth2Convert.java | 2 + .../system/biz/dao/admin/AdminMapper.java | 10 ++ .../biz/dao/authorization/RoleMapper.java | 10 +- .../system/biz/dataobject/admin/AdminDO.java | 9 +- .../system/biz/dto/admin/AdminPageDTO.java | 26 +++++ ...uthorizationGetRoleMapByAccountIdsDTO.java | 19 ++++ .../dto/authorization/ResourceGetListDTO.java | 2 + .../biz/dto/authorization/RoleGetListDTO.java | 22 +++++ .../OAuth2AccessTokenAuthenticateDTO.java | 10 +- .../OAuth2RefreshTokenAuthenticateDTO.java | 20 ++++ .../oatuh2/OAuth2UsernameAuthenticateDTO.java | 9 +- .../biz/service/admin/AdminService.java | 18 +++- .../biz/service/admin/AdminServiceImpl.java | 14 ++- .../authorization/AuthorizationService.java | 15 ++- .../AuthorizationServiceImpl.java | 20 ++++ .../service/authorization/RoleService.java | 3 +- .../authorization/RoleServiceImpl.java | 62 ++++++------ .../biz/service/oauth2/OAuth2Service.java | 3 + .../biz/service/oauth2/OAuth2ServiceImpl.java | 35 +++++-- .../admin/AdminsAdminController.java | 94 +++++++++++++++++++ .../AdminsAuthorizationController.java | 28 ++++++ .../convert/admin/AdminsAdminConvert.java | 9 ++ .../convert/oauth2/AdminsOAuth2Convert.java | 2 +- .../convert/oauth2/UsersOAuth2Convert.java | 2 - .../request/admin/AdminsAdminPageRequest.java | 22 +++++ .../admin/AdminsAdminPageResponse.java | 79 ++++++++++++++++ .../authorization/AdminsRolePageResponse.java | 2 + .../iocoder/mall/system/api/AdminService.java | 22 ----- .../mall/system/api/OAuth2Service.java | 29 ------ .../iocoder/mall/system/api/RoleService.java | 10 -- .../api/dto/admin/AdminAuthenticationDTO.java | 28 ------ .../iocoder/mall/admin/dao/AdminMapper.java | 32 ------- .../mall/admin/dataobject/AdminDO.java | 50 ---------- .../mall/admin/service/OAuth2ServiceImpl.java | 93 ------------------ .../controller/admins/AdminController.java | 21 ----- 48 files changed, 627 insertions(+), 400 deletions(-) create mode 100644 system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/admin/AdminStatusEnum.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/admin/AdminPageDTO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleMapByAccountIdsDTO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleGetListDTO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2RefreshTokenAuthenticateDTO.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsAdminPageRequest.java create mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/admin/AdminsAdminPageResponse.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/system/api/dto/admin/AdminAuthenticationDTO.java delete mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java delete mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java diff --git a/admin-web/src/models/admin/adminList.js b/admin-web/src/models/admin/adminList.js index 95025b69..cade2626 100644 --- a/admin-web/src/models/admin/adminList.js +++ b/admin-web/src/models/admin/adminList.js @@ -4,17 +4,19 @@ import { addAdmin, adminRoleAssign, deleteAdmin, - queryAdmin, queryAdminRoleList, updateAdmin, updateAdminStatus, deptTreeAll, } from '../../services/admin'; +import { + adminPage +} from '../../services/system'; import { arrayToStringParams } from '../../utils/request.qs'; import PaginationHelper from '../../../helpers/PaginationHelper'; const SEARCH_PARAMS_DEFAULT = { - nickname: '', + name: '', }; const buildSelectTree = list => { @@ -76,7 +78,7 @@ export default { }); // 请求 - const response = yield call(queryAdmin, payload); + const response = yield call(adminPage, payload); // 响应 yield put({ type: 'setAll', @@ -84,7 +86,7 @@ export default { list: response.data.list, pagination: PaginationHelper.formatPagination(response.data, payload), searchParams: { - nickname: payload.nickname || '', + name: payload.name || '', }, }, }); diff --git a/admin-web/src/pages/Admin/AdminList.js b/admin-web/src/pages/Admin/AdminList.js index 1866cfad..a78de6e7 100644 --- a/admin-web/src/pages/Admin/AdminList.js +++ b/admin-web/src/pages/Admin/AdminList.js @@ -28,7 +28,7 @@ import PaginationHelper from '../../../helpers/PaginationHelper'; const FormItem = Form.Item; const { TreeNode } = Tree; -const status = ['未知', '正常', '禁用']; +const status = ['未知', '在职', '离职']; // 列表 function List({ @@ -52,23 +52,6 @@ function List({ }); } - function handleStatus(record) { - Modal.confirm({ - title: record.status === 1 ? '确认禁用' : '取消禁用', - content: `${record.username}`, - onOk() { - dispatch({ - type: 'adminList/updateStatus', - payload: { - id: record.id, - status: record.status === 1 ? 2 : 1, - }, - }); - }, - onCancel() {}, - }); - } - function handleDelete(record) { Modal.confirm({ title: `确认删除?`, @@ -92,7 +75,7 @@ function List({ }, { title: '员工姓名', - dataIndex: 'nickname', + dataIndex: 'name', }, { title: '部门', @@ -115,7 +98,7 @@ function List({ }, }, { - title: '状态', + title: '在职状态', dataIndex: 'status', render(val) { return {status[val]}; // TODO 芋艿,此处要改 @@ -130,16 +113,12 @@ function List({ title: '操作', width: 360, render: (text, record) => { - const statusText = record.status === 1 ? '禁用' : '开启'; // TODO 芋艿,此处要改 return ( handleModalVisible(true, 'update', record)}>编辑 handleRoleAssign(record)}>角色分配 - handleStatus(record)}> - {statusText} - {record.status === 2 ? ( @@ -223,7 +202,7 @@ const SearchForm = Form.create()(props => { - {getFieldDecorator('nickname')()} + {getFieldDecorator('name')()} @@ -233,7 +212,7 @@ const SearchForm = Form.create()(props => { })( { okText="保存" onCancel={() => handleModalVisible()} > - - {form.getFieldDecorator('username', { - rules: [ - { required: true, message: '请输入账号!' }, - { max: 16, min: 6, message: '长度为 6-16 位' }, - { - validator: (rule, value, callback) => - checkTypeWithEnglishAndNumbers(rule, value, callback, '数字以及字母'), - }, - ], - initialValue: formVals.username, - })()} - - {form.getFieldDecorator('nickname', { + {form.getFieldDecorator('name', { rules: [ { required: true, message: '请输入员工姓名!' }, { max: 10, message: '姓名最大长度为 10' }, ], - initialValue: formVals.nickname, + initialValue: formVals.name, })()} @@ -364,6 +330,19 @@ const AddOrUpdateForm = Form.create()(props => { /> )} + + {form.getFieldDecorator('username', { + rules: [ + { required: true, message: '请输入账号!' }, + { max: 16, min: 6, message: '长度为 6-16 位' }, + { + validator: (rule, value, callback) => + checkTypeWithEnglishAndNumbers(rule, value, callback, '数字以及字母'), + }, + ], + initialValue: formVals.username, + })()} + {form.getFieldDecorator('password', { rules: [ diff --git a/admin-web/src/pages/Admin/RoleList.js b/admin-web/src/pages/Admin/RoleList.js index 8cd9df09..0befe716 100644 --- a/admin-web/src/pages/Admin/RoleList.js +++ b/admin-web/src/pages/Admin/RoleList.js @@ -10,6 +10,7 @@ import styles from './RoleList.less'; const FormItem = Form.Item; const { TreeNode } = Tree; +const types = ['未知', '系统角色', '自定义角色']; // 添加 form 表单 const CreateForm = Form.create()(props => { @@ -296,6 +297,13 @@ class RoleList extends PureComponent { title: '编码', dataIndex: 'code', }, + { + title: '类型', + dataIndex: 'type', + render(val) { + return {types[val]}; + }, + }, { title: '创建时间', dataIndex: 'createTime', @@ -307,13 +315,21 @@ class RoleList extends PureComponent { width: 200, render: (text, record) => ( - this.handleModalVisible(true, 'update', record)}>更新 + {record.type === 2 ? ( + + this.handleModalVisible(true, 'update', record)}>更新 + + ) : null} this.handleAssignModalVisible(true, record)}>分配权限 - this.handleDelete(record)}> - 删除 - + {record.type === 2 ? ( + + this.handleDelete(record)}> + 删除 + + + ) : null} ), }, diff --git a/admin-web/src/services/system.js b/admin-web/src/services/system.js index 3b445363..06a52433 100644 --- a/admin-web/src/services/system.js +++ b/admin-web/src/services/system.js @@ -89,3 +89,11 @@ export async function roleUpdate(params) { body: {}, }); } + +// ========== Admin 模块 ========== + +export async function adminPage(params) { + return request(`/system-api/admins/admin/page?${stringify(params)}`, { + method: 'GET', + }); +} diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtil.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtil.java index 21ca16ef..2a737e87 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtil.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtil.java @@ -41,6 +41,12 @@ public class CollectionUtil { Collectors.mapping(valueFunc, Collectors.toList()))); } + // 暂时没想好名字,先以 2 结尾噶 + public static Map> convertMultiMap2(List from, Function keyFunc, Function valueFunc) { + return from.stream().collect(Collectors.groupingBy(keyFunc, + Collectors.mapping(valueFunc, Collectors.toSet()))); + } + public static boolean containsAny(Collection source, Collection candidates) { return CollectionUtils.containsAny(source, candidates); } diff --git a/system/pom.xml b/system/pom.xml index ce815a2d..f6cd2d90 100644 --- a/system/pom.xml +++ b/system/pom.xml @@ -16,8 +16,8 @@ system-application - system-service-api - system-service-impl + + system-rpc-api system-rpc system-rest diff --git a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/SystemErrorCodeEnum.java b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/SystemErrorCodeEnum.java index e150c32f..9fac37ac 100644 --- a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/SystemErrorCodeEnum.java +++ b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/SystemErrorCodeEnum.java @@ -16,6 +16,9 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable { OAUTH2_ACCESS_TOKEN_TOKEN_EXPIRED(1001001002, "访问令牌已过期"), OAUTH2_ACCESS_TOKEN_INVALID(1001001003, "访问令牌已失效"), OAUTH2_NOT_AUTHENTICATE(1001001004, "账号未登陆"), + OAUTH2_REFRESH_TOKEN_NOT_FOUND(1001001005, "刷新令牌不存在"), + OAUTH_REFRESH_TOKEN_EXPIRED(1001001006, "访问令牌已过期"), + OAUTH_REFRESH_TOKEN_INVALID(1001001007, "刷新令牌已失效"), // 其它 1001001100 开始 OAUTH2_ACCOUNT_NOT_FOUND(1001001100, "账号不存在"), OAUTH2_ACCOUNT_PASSWORD_ERROR(1001001101, "密码不正确"), @@ -52,6 +55,8 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable { ROLE_NOT_EXISTS(1002004000, "角色不存在"), ROLE_NAME_DUPLICATE(1002004001, "已经存在名为【{}}】的角色"), ROLE_CODE_DUPLICATE(1002004002, "已经存在编码为【{}}】的角色"), + ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE(1002004004, "不能修改类型为系统内置的角色"), + ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE(1002004005, "不能删除类型为系统内置的角色"), // ========== 数据字典模块 1002005000 ========== // DATA_DICT_EXISTS(1002005000, "该数据字典已经存在"), diff --git a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/admin/AdminStatusEnum.java b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/admin/AdminStatusEnum.java new file mode 100644 index 00000000..1f6281a7 --- /dev/null +++ b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/admin/AdminStatusEnum.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.system.biz.enums.admin; + +import cn.iocoder.common.framework.core.IntArrayValuable; + +import java.util.Arrays; + +public enum AdminStatusEnum implements IntArrayValuable { + + ACTIVE(1, "在职"), + INACTIVE(2, "离职"); + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(AdminStatusEnum::getStatus).toArray(); + + /** + * 在职状态 + */ + private final Integer status; + /** + * 描述 + */ + private final String name; + + AdminStatusEnum(Integer status, String name) { + this.status = status; + this.name = name; + } + + public Integer getStatus() { + return status; + } + + public String getName() { + return name; + } + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/authorization/ResourceIdEnum.java b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/authorization/ResourceIdEnum.java index b1475603..c6199e34 100644 --- a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/authorization/ResourceIdEnum.java +++ b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/authorization/ResourceIdEnum.java @@ -1,7 +1,13 @@ package cn.iocoder.mall.system.biz.enums.authorization; +/** + * Resource 编号枚举 + */ public enum ResourceIdEnum { + /** + * 根节点 + */ ROOT(0); private final Integer id; diff --git a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/authorization/ResourceTypeEnum.java b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/authorization/ResourceTypeEnum.java index 851452f4..64511c87 100644 --- a/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/authorization/ResourceTypeEnum.java +++ b/system/system-biz-api/src/main/java/cn/iocoder/mall/system/biz/enums/authorization/ResourceTypeEnum.java @@ -5,7 +5,7 @@ import cn.iocoder.common.framework.core.IntArrayValuable; import java.util.Arrays; /** - * 资源类型枚举 + * Resource 类型枚举 */ public enum ResourceTypeEnum implements IntArrayValuable { diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/admin/AdminBO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/admin/AdminBO.java index 27900eef..6a8c03da 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/admin/AdminBO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/admin/AdminBO.java @@ -3,6 +3,8 @@ package cn.iocoder.mall.system.biz.bo.admin; import lombok.Data; import lombok.experimental.Accessors; +import java.util.Date; + /** * 管理员模块 - 账号信息 BO */ @@ -14,9 +16,25 @@ public class AdminBO { * 管理员编号 */ private Integer id; + /** + * 账号编号 + */ + private Integer accountId; /** * 真实名字 */ private String name; + /** + * 部门编号 + */ + private Integer departmentId; + /** + * 在职状态 + */ + private Integer status; + /** + * 创建时间 + */ + private Date createTime; } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/RoleBO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/RoleBO.java index 9d4b3cb6..50e8d197 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/RoleBO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/RoleBO.java @@ -24,6 +24,10 @@ public class RoleBO { * 角色编码 */ private String code; + /** + * 角色类型 + */ + private Integer type; /** * 添加时间 */ diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/admin/AdminConvert.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/admin/AdminConvert.java index 0bddb49e..f7cfb0d4 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/admin/AdminConvert.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/admin/AdminConvert.java @@ -1,8 +1,11 @@ package cn.iocoder.mall.system.biz.convert.admin; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.system.biz.bo.admin.AdminBO; import cn.iocoder.mall.system.biz.dataobject.admin.AdminDO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @Mapper @@ -12,4 +15,7 @@ public interface AdminConvert { AdminBO convert(AdminDO bean); + @Mapping(source = "records", target = "list") + PageResult convertPage(IPage bean); + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/oauth2/OAuth2Convert.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/oauth2/OAuth2Convert.java index c5c8dc22..08845a6d 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/oauth2/OAuth2Convert.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/oauth2/OAuth2Convert.java @@ -3,6 +3,7 @@ package cn.iocoder.mall.system.biz.convert.oauth2; import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO; import cn.iocoder.mall.system.biz.dataobject.oauth2.OAuth2AccessTokenDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @Mapper @@ -10,6 +11,7 @@ public interface OAuth2Convert { OAuth2Convert INSTANCE = Mappers.getMapper(OAuth2Convert.class); + @Mapping(source = "id", target = "accessToken") OAuth2AuthenticateBO convert(OAuth2AccessTokenDO bean); } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/admin/AdminMapper.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/admin/AdminMapper.java index b8bce40b..f9b1a8e3 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/admin/AdminMapper.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/admin/AdminMapper.java @@ -1,8 +1,12 @@ package cn.iocoder.mall.system.biz.dao.admin; +import cn.iocoder.mall.mybatis.query.QueryWrapperX; import cn.iocoder.mall.system.biz.dataobject.admin.AdminDO; +import cn.iocoder.mall.system.biz.dto.admin.AdminPageDTO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Repository; @Repository @@ -14,4 +18,10 @@ public interface AdminMapper extends BaseMapper { ); } + default IPage selectPage(AdminPageDTO adminPageDTO) { + return selectPage(new Page<>(adminPageDTO.getPageNo(), adminPageDTO.getPageSize()), + new QueryWrapperX().likeIfPresent("name", adminPageDTO.getName()) + .eqIfPresent("department_id", adminPageDTO.getDepartmentId())); + } + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/authorization/RoleMapper.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/authorization/RoleMapper.java index b3ac325f..12073f07 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/authorization/RoleMapper.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/authorization/RoleMapper.java @@ -3,26 +3,26 @@ package cn.iocoder.mall.system.biz.dao.authorization; import cn.iocoder.mall.mybatis.query.QueryWrapperX; import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO; import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Repository; +import java.util.Collection; import java.util.List; @Repository public interface RoleMapper extends BaseMapper { - default List selectList() { - return selectList(new QueryWrapper<>()); - } - default IPage selectPage(RolePageDTO rolePageDTO) { return selectPage(new Page<>(rolePageDTO.getPageNo(), rolePageDTO.getPageSize()), new QueryWrapperX().likeIfPresent("name", rolePageDTO.getName())); } + default List selectListByIds(Collection ids) { + return selectList(new QueryWrapperX().inIfPresent("id", ids)); + } + default RoleDO selectByName(String name) { return selectOne(new QueryWrapperX().eqIfPresent("name", name)); } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/admin/AdminDO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/admin/AdminDO.java index e43d329e..6b347843 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/admin/AdminDO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/admin/AdminDO.java @@ -2,6 +2,7 @@ package cn.iocoder.mall.system.biz.dataobject.admin; import cn.iocoder.mall.mybatis.dataobject.DeletableDO; import cn.iocoder.mall.system.biz.dataobject.account.AccountDO; +import cn.iocoder.mall.system.biz.enums.admin.AdminStatusEnum; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; @@ -31,10 +32,16 @@ public class AdminDO extends DeletableDO { */ private String name; /** - * 科室编号 + * 部门编号 * * 关联 {@link DepartmentDO#getId()} */ private Integer departmentId; + /** + * 在职状态 + * + * 枚举 {@link AdminStatusEnum} + */ + private Integer status; } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/admin/AdminPageDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/admin/AdminPageDTO.java new file mode 100644 index 00000000..24d6fdb2 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/admin/AdminPageDTO.java @@ -0,0 +1,26 @@ +package cn.iocoder.mall.system.biz.dto.admin; + +import cn.iocoder.common.framework.vo.PageParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * 管理员模块 - 管理员分页 DTO + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +public class AdminPageDTO extends PageParam { + + /** + * 真实名字,模糊匹配 + */ + private String name; + + /** + * 部门编号 + */ + private Integer departmentId; + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleMapByAccountIdsDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleMapByAccountIdsDTO.java new file mode 100644 index 00000000..d846de70 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleMapByAccountIdsDTO.java @@ -0,0 +1,19 @@ +package cn.iocoder.mall.system.biz.dto.authorization; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.util.Collection; + +/** + * 授权模块 - 获得每个账号所拥有的角色 DTO + */ +@Data +@Accessors(chain = true) +public class AuthorizationGetRoleMapByAccountIdsDTO { + + @NotNull(message = "账号编号数组不能为空") + private Collection accountIds; + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetListDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetListDTO.java index 53a7ac80..1538c862 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetListDTO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetListDTO.java @@ -14,6 +14,8 @@ public class ResourceGetListDTO { /** * 资源编号数组 + * + * 如果传入空,则不进行资源编号的过滤 */ private Collection ids; diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleGetListDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleGetListDTO.java new file mode 100644 index 00000000..7c665512 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleGetListDTO.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.system.biz.dto.authorization; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Collection; + +/** + * 角色模块 - 获得角色列表 DTO + */ +@Data +@Accessors(chain = true) +public class RoleGetListDTO { + + /** + * 角色编号数组 + * + * 如果传入空,则不进行角色编号的过滤 + */ + private Collection ids; + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2AccessTokenAuthenticateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2AccessTokenAuthenticateDTO.java index cb0b98bc..e146d12f 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2AccessTokenAuthenticateDTO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2AccessTokenAuthenticateDTO.java @@ -3,16 +3,18 @@ package cn.iocoder.mall.system.biz.dto.oatuh2; import lombok.Data; import lombok.experimental.Accessors; -import javax.validation.constraints.NotNull; +import javax.validation.constraints.NotEmpty; -// TODO 注释 +/** + * 认证模块 - 访问令牌认证 DTO + */ @Data @Accessors(chain = true) public class OAuth2AccessTokenAuthenticateDTO { - @NotNull(message = "访问令牌不能为空") + @NotEmpty(message = "访问令牌不能为空") private String accessToken; - @NotNull(message = "IP 不能为空") + @NotEmpty(message = "IP 不能为空") private String ip; } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2RefreshTokenAuthenticateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2RefreshTokenAuthenticateDTO.java new file mode 100644 index 00000000..095149c7 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2RefreshTokenAuthenticateDTO.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.system.biz.dto.oatuh2; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; + +/** + * 认证模块 - 访问令牌认证 DTO + */ +@Data +@Accessors(chain = true) +public class OAuth2RefreshTokenAuthenticateDTO { + + @NotEmpty(message = "访问令牌不能为空") + private String refreshToken; + @NotEmpty(message = "IP 不能为空") + private String ip; + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2UsernameAuthenticateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2UsernameAuthenticateDTO.java index c132c411..aebd947f 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2UsernameAuthenticateDTO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2UsernameAuthenticateDTO.java @@ -3,12 +3,19 @@ package cn.iocoder.mall.system.biz.dto.oatuh2; import lombok.Data; import lombok.experimental.Accessors; -// TODO 注释 +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * 认证模块 - 账号 + 密码认证 DTO + */ @Data @Accessors(chain = true) public class OAuth2UsernameAuthenticateDTO { + @NotEmpty(message = "账号不能为空") private String username; + @NotNull(message = "密码不能为空") private String password; } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/admin/AdminService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/admin/AdminService.java index 60e35e53..04023af3 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/admin/AdminService.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/admin/AdminService.java @@ -1,14 +1,30 @@ package cn.iocoder.mall.system.biz.service.admin; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.system.biz.bo.admin.AdminBO; +import cn.iocoder.mall.system.biz.dto.admin.AdminPageDTO; /** - * 管理员 Service 接口 + * 管理员模块 - Service 接口 */ public interface AdminService { + /** + * 根据编号获得管理员信息 + * + * @param id 编号 + * @return 管理员 + */ AdminBO getAdmin(Integer id); + /** + * 获得账号编号获得管理员信息 + * + * @param accountId 账号编号 + * @return 管理员 + */ AdminBO getAdminByAccountId(Integer accountId); + PageResult getAdminPage(AdminPageDTO pageDTO); + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/admin/AdminServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/admin/AdminServiceImpl.java index 616c2ceb..a6c02e80 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/admin/AdminServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/admin/AdminServiceImpl.java @@ -1,9 +1,10 @@ package cn.iocoder.mall.system.biz.service.admin; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.system.biz.bo.admin.AdminBO; import cn.iocoder.mall.system.biz.convert.admin.AdminConvert; import cn.iocoder.mall.system.biz.dao.admin.AdminMapper; -import cn.iocoder.mall.system.biz.dataobject.admin.AdminDO; +import cn.iocoder.mall.system.biz.dto.admin.AdminPageDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -15,14 +16,17 @@ public class AdminServiceImpl implements AdminService { @Override public AdminBO getAdmin(Integer id) { - AdminDO adminDO = adminMapper.selectById(id); - return AdminConvert.INSTANCE.convert(adminDO); + return AdminConvert.INSTANCE.convert(adminMapper.selectById(id)); } @Override public AdminBO getAdminByAccountId(Integer accountId) { - AdminDO adminDO = adminMapper.selectByAccountId(accountId); - return AdminConvert.INSTANCE.convert(adminDO); + return AdminConvert.INSTANCE.convert(adminMapper.selectByAccountId(accountId)); + } + + @Override + public PageResult getAdminPage(AdminPageDTO pageDTO) { + return AdminConvert.INSTANCE.convertPage(adminMapper.selectPage(pageDTO)); } } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationService.java index 35845eff..080d8c96 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationService.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationService.java @@ -3,12 +3,11 @@ package cn.iocoder.mall.system.biz.service.authorization; import cn.iocoder.common.framework.exception.ServiceException; import cn.iocoder.mall.system.biz.bo.authorization.ResourceBO; import cn.iocoder.mall.system.biz.bo.authorization.ResourceTreeNodeBO; -import cn.iocoder.mall.system.biz.dto.authorization.AuthorizationAssignRoleResourceDTO; -import cn.iocoder.mall.system.biz.dto.authorization.AuthorizationCheckPermissionsDTO; -import cn.iocoder.mall.system.biz.dto.authorization.AuthorizationGetResourcesByAccountIdDTO; -import cn.iocoder.mall.system.biz.dto.authorization.AuthorizationGetRoleResourcesDTO; +import cn.iocoder.mall.system.biz.bo.authorization.RoleBO; +import cn.iocoder.mall.system.biz.dto.authorization.*; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -33,6 +32,14 @@ public interface AuthorizationService { */ List getResourcesByAccountId(AuthorizationGetResourcesByAccountIdDTO getResourcesByAccountIdDTO); + /** + * 获得每个账号拥有的角色集合 + * + * @param getRoleMapByAccountIdsDTO 查询条件 DTO + * @return <账号编号, > + */ + Map> getRoleMapByAccountIds(AuthorizationGetRoleMapByAccountIdsDTO getRoleMapByAccountIdsDTO); + /** * 获得指定账号的资源树 * diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java index 44f11aea..d45b244a 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java @@ -5,6 +5,7 @@ import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum; import cn.iocoder.mall.system.biz.bo.authorization.ResourceBO; import cn.iocoder.mall.system.biz.bo.authorization.ResourceTreeNodeBO; +import cn.iocoder.mall.system.biz.bo.authorization.RoleBO; import cn.iocoder.mall.system.biz.dao.authorization.AccountRoleMapper; import cn.iocoder.mall.system.biz.dao.authorization.RoleResourceMapper; import cn.iocoder.mall.system.biz.dataobject.authorization.AccountRoleDO; @@ -94,6 +95,25 @@ public class AuthorizationServiceImpl implements AuthorizationService { return resourceService.getResources(new ResourceGetListDTO().setIds(resourceIds).setType(getResourcesByAccountIdDTO.getType())); } + @Override + public Map> getRoleMapByAccountIds(AuthorizationGetRoleMapByAccountIdsDTO getRoleMapByAccountIdsDTO) { + return null; + } + +// @Override +// public Map> getRoleIdMapByAccountIds(AuthorizationGetRoleMapByAccountIdsDTO getRoleMapByAccountIdsDTO) { +// // 查询管理员拥有的角色关联数据 +// List accountRoleDOs = accountRoleMapper.selectListByAccountIds(getRoleMapByAccountIdsDTO.getAccountIds()); +// if (CollectionUtil.isEmpty(accountRoleDOs)) { +// return Collections.emptyMap(); +// } +// // 构建结果 +// Map> accountRoleMap = CollectionUtil.convertMultiMap2(accountRoleDOs, +// AccountRoleDO::getAccountId, AccountRoleDO::getRoleId); +// getRoleMapByAccountIdsDTO.getAccountIds().forEach(accountId -> accountRoleMap.putIfAbsent(accountId, Collections.emptySet())); +// return accountRoleMap; +// } + @Override public List getResourceTreeByAccountId(AuthorizationGetResourcesByAccountIdDTO getResourcesByAccountIdDTO) { // 查询管理员拥有的角色关联数据 diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleService.java index 95588f6f..cb7cfcf4 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleService.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleService.java @@ -6,6 +6,7 @@ import cn.iocoder.mall.system.biz.dto.authorization.RoleAddDTO; import cn.iocoder.mall.system.biz.dto.authorization.RoleDeleteDTO; import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO; import cn.iocoder.mall.system.biz.dto.authorization.RoleUpdateDTO; +import cn.iocoder.mall.system.biz.dto.authorization.RoleGetListDTO; import java.util.Collection; import java.util.List; @@ -17,7 +18,7 @@ public interface RoleService { RoleBO getRole(Integer id); - List getRoleList(Collection ids); + List getRoleList(RoleGetListDTO getListDTO); PageResult getRolePage(RolePageDTO pageDTO); diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java index 534d2870..f3f1da4c 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java @@ -8,12 +8,10 @@ import cn.iocoder.mall.system.biz.bo.authorization.RoleBO; import cn.iocoder.mall.system.biz.convert.authorization.RoleConvert; import cn.iocoder.mall.system.biz.dao.authorization.RoleMapper; import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleAddDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleDeleteDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleUpdateDTO; +import cn.iocoder.mall.system.biz.dto.authorization.*; import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum; import cn.iocoder.mall.system.biz.enums.authorization.RoleCodeEnum; +import cn.iocoder.mall.system.biz.enums.authorization.RoleTypeEnum; import cn.iocoder.mall.system.biz.event.authorization.ResourceDeleteEvent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; @@ -39,8 +37,8 @@ public class RoleServiceImpl implements RoleService { } @Override - public List getRoleList(Collection ids) { - return RoleConvert.INSTANCE.convertList(roleMapper.selectBatchIds(ids)); + public List getRoleList(RoleGetListDTO getListDTO) { + return RoleConvert.INSTANCE.convertList(roleMapper.selectListByIds(getListDTO.getIds())); } @Override @@ -62,9 +60,10 @@ public class RoleServiceImpl implements RoleService { @Override public Integer addRole(RoleAddDTO roleAddDTO) { // 校验角色 - checkRole(roleAddDTO.getName(), roleAddDTO.getCode(), null); + checkDuplicateRole(roleAddDTO.getName(), roleAddDTO.getCode(), null); // 保存到数据库 RoleDO role = RoleConvert.INSTANCE.convert(roleAddDTO); + role.setType(RoleTypeEnum.CUSTOM.getType()); role.setCreateTime(new Date()); role.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); roleMapper.insert(role); @@ -76,14 +75,19 @@ public class RoleServiceImpl implements RoleService { @Override public void updateRole(RoleUpdateDTO roleUpdateDTO) { // 校验角色是否存在 - if (roleMapper.selectById(roleUpdateDTO.getId()) == null) { + RoleDO roleDO = roleMapper.selectById(roleUpdateDTO.getId()); + if (roleDO == null) { throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_NOT_EXISTS); } - // 校验角色 - checkRole(roleUpdateDTO.getName(), roleUpdateDTO.getCode(), roleUpdateDTO.getId()); + // 内置角色,不允许修改 + if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { + throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE); + } + // 校验角色的唯一字段是否重复 + checkDuplicateRole(roleUpdateDTO.getName(), roleUpdateDTO.getCode(), roleUpdateDTO.getId()); // 更新到数据库 - RoleDO roleDO = RoleConvert.INSTANCE.convert(roleUpdateDTO); - roleMapper.updateById(roleDO); + RoleDO updateRole = RoleConvert.INSTANCE.convert(roleUpdateDTO); + roleMapper.updateById(updateRole); // TODO 插入操作日志 } @@ -91,9 +95,14 @@ public class RoleServiceImpl implements RoleService { @Transactional public void deleteRole(RoleDeleteDTO roleDeleteDTO) { // 校验角色是否存在 - if (roleMapper.selectById(roleDeleteDTO.getId()) == null) { + RoleDO roleDO = roleMapper.selectById(roleDeleteDTO.getId()); + if (roleDO == null) { throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_NOT_EXISTS); } + // 内置角色,不允许删除 + if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { + throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE); + } // 更新到数据库,标记删除 roleMapper.deleteById(roleDeleteDTO.getId()); // 发布角色删除事件,方便清理关联表 @@ -102,7 +111,7 @@ public class RoleServiceImpl implements RoleService { } /** - * 校验角色是否合法 + * 校验角色的唯一字段是否重复 * * 1. 是否存在相同名字的角色 * 2. 是否存在相同编码的角色 @@ -111,31 +120,20 @@ public class RoleServiceImpl implements RoleService { * @param code 角色额编码 * @param id 角色编号 */ - private void checkRole(String name, String code, Integer id) { - // 1. 是否存在相同名字的角色 + private void checkDuplicateRole(String name, String code, Integer id) { + // 1. 该 name 名字被其它角色所使用 RoleDO role = roleMapper.selectByName(name); - if (role != null) { - // 如果 id 为空,说明不用比较是否为相同 id 的资源 - if (id == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_NAME_DUPLICATE, name); - } - if (!role.getId().equals(id)) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_NAME_DUPLICATE, name); - } + if (role != null && !role.getId().equals(id)) { + throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_NAME_DUPLICATE, name); } // 2. 是否存在相同编码的角色 if (!StringUtil.hasText(code)) { return; } + // 该 code 编码被其它角色所使用 role = roleMapper.selectByCode(code); - if (role != null) { - // 如果 id 为空,说明不用比较是否为相同 id 的资源 - if (id == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_CODE_DUPLICATE, name); - } - if (!role.getId().equals(id)) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_CODE_DUPLICATE, name); - } + if (role != null && !role.getId().equals(id)) { + throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_CODE_DUPLICATE, name); } } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/oauth2/OAuth2Service.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/oauth2/OAuth2Service.java index 8387089e..ec081b78 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/oauth2/OAuth2Service.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/oauth2/OAuth2Service.java @@ -3,6 +3,7 @@ package cn.iocoder.mall.system.biz.service.oauth2; import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO; import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2AccessTokenAuthenticateDTO; import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2MobileCodeAuthenticateDTO; +import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2RefreshTokenAuthenticateDTO; import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2UsernameAuthenticateDTO; /** @@ -16,4 +17,6 @@ public interface OAuth2Service { OAuth2AuthenticateBO authenticate(OAuth2AccessTokenAuthenticateDTO authenticateDTO); + OAuth2AuthenticateBO authenticate(OAuth2RefreshTokenAuthenticateDTO authenticateDTO); + } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/oauth2/OAuth2ServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/oauth2/OAuth2ServiceImpl.java index 0e0d4f6d..d19e7d5b 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/oauth2/OAuth2ServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/oauth2/OAuth2ServiceImpl.java @@ -13,8 +13,8 @@ import cn.iocoder.mall.system.biz.dataobject.oauth2.OAuth2RefreshTokenDO; import cn.iocoder.mall.system.biz.dto.account.AccountCreateDTO; import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2AccessTokenAuthenticateDTO; import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2MobileCodeAuthenticateDTO; +import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2RefreshTokenAuthenticateDTO; import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2UsernameAuthenticateDTO; -import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum; import cn.iocoder.mall.system.biz.service.account.AccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -24,8 +24,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.UUID; -import static cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum.OAUTH2_ACCOUNT_NOT_FOUND; -import static cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum.OAUTH2_ACCOUNT_PASSWORD_ERROR; +import static cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum.*; @Service public class OAuth2ServiceImpl implements OAuth2Service { @@ -101,18 +100,42 @@ public class OAuth2ServiceImpl implements OAuth2Service { public OAuth2AuthenticateBO authenticate(OAuth2AccessTokenAuthenticateDTO authenticateDTO) { OAuth2AccessTokenDO oauth2AccessTokenDO = oauth2AccessTokenMapper.selectById(authenticateDTO.getAccessToken()); if (oauth2AccessTokenDO == null) { // 不存在 - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.OAUTH2_ACCESS_TOKEN_NOT_FOUND.getCode()); + throw ServiceExceptionUtil.exception(OAUTH2_ACCESS_TOKEN_NOT_FOUND); } if (oauth2AccessTokenDO.getExpiresTime().getTime() < System.currentTimeMillis()) { // 已过期 - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.OAUTH2_ACCESS_TOKEN_TOKEN_EXPIRED.getCode()); + throw ServiceExceptionUtil.exception(OAUTH2_ACCESS_TOKEN_TOKEN_EXPIRED); } if (!oauth2AccessTokenDO.getValid()) { // 无效 - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.OAUTH2_ACCESS_TOKEN_INVALID.getCode()); + throw ServiceExceptionUtil.exception(OAUTH2_ACCESS_TOKEN_INVALID); } // 转换返回 return OAuth2Convert.INSTANCE.convert(oauth2AccessTokenDO); } + @Override + @Transactional + public OAuth2AuthenticateBO authenticate(OAuth2RefreshTokenAuthenticateDTO authenticateDTO) { + OAuth2RefreshTokenDO refreshTokenDO = oauth2RefreshTokenMapper.selectById(authenticateDTO.getRefreshToken()); + // 校验刷新令牌是否合法 + if (refreshTokenDO == null) { // 不存在 + throw ServiceExceptionUtil.exception(OAUTH2_REFRESH_TOKEN_NOT_FOUND); + } + if (refreshTokenDO.getExpiresTime().getTime() < System.currentTimeMillis()) { // 已过期 + throw ServiceExceptionUtil.exception(OAUTH_REFRESH_TOKEN_EXPIRED); + } + if (!refreshTokenDO.getValid()) { // 无效 + throw ServiceExceptionUtil.exception(OAUTH_REFRESH_TOKEN_INVALID); + } + // 标记 refreshToken 对应的 accessToken 都不合法 + // 这块的实现,参考了 Spring Security OAuth2 的代码 + oauth2AccessTokenMapper.updateToInvalidByRefreshToken(authenticateDTO.getRefreshToken()); + // 创建访问令牌 + OAuth2AccessTokenDO oauth2AccessTokenDO = createOAuth2AccessToken(refreshTokenDO.getAccountId(), + refreshTokenDO.getId()); + // 转换返回 + return OAuth2Convert.INSTANCE.convert(oauth2AccessTokenDO); + } + private OAuth2AccessTokenDO createOAuth2AccessToken(Integer accountId, String refreshToken) { OAuth2AccessTokenDO accessToken = new OAuth2AccessTokenDO() .setId(generateAccessToken()) diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsAdminController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsAdminController.java index 7e61566b..b3fb5df3 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsAdminController.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsAdminController.java @@ -1,7 +1,19 @@ package cn.iocoder.mall.system.rest.controller.admin; import cn.iocoder.common.framework.constant.MallConstants; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.security.core.annotation.RequiresPermissions; +import cn.iocoder.mall.system.biz.bo.admin.AdminBO; +import cn.iocoder.mall.system.biz.dto.admin.AdminPageDTO; +import cn.iocoder.mall.system.biz.service.admin.AdminService; +import cn.iocoder.mall.system.rest.convert.admin.AdminsAdminConvert; +import cn.iocoder.mall.system.rest.request.admin.AdminsAdminPageRequest; +import cn.iocoder.mall.system.rest.response.admin.AdminsAdminPageResponse; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -10,6 +22,88 @@ import org.springframework.web.bind.annotation.RestController; @Api(tags = "管理员 - 管理员 API") public class AdminsAdminController { + @Autowired + private AdminService adminService; + @GetMapping("/page") + @RequiresPermissions("system:admin:page") + @ApiOperation(value = "管理员分页") + public CommonResult> page(AdminsAdminPageRequest request) { + // 查询管理员分页 + AdminPageDTO pageDTO = AdminsAdminConvert.INSTANCE.convert(request); + PageResult adminPageBO = adminService.getAdminPage(pageDTO); + PageResult adminPageResponse = AdminsAdminConvert.INSTANCE.convertPage(adminPageBO); + if (adminPageResponse.getList().isEmpty()) { + return CommonResult.success(adminPageResponse); + } + // 拼接角色数据 + + + // TODO 拼接部门数据 + + // 拼接结果 +// if (!resultPage.getList().isEmpty()) { +// // 查询角色数组 +// Map> roleMap = adminService.getAdminRolesMap(CollectionUtil.convertList(resultPage.getList(), AdminBO::getId)); +// resultPage.getList().forEach(admin -> admin.setRoles(AdminConvert.INSTANCE.convertAdminVORoleList(roleMap.get(admin.getId())))); +// +// // 查询对应部门 +// List deptmentBOS = deptmentService.getAllDeptments(); +// Map deptNameMap = deptmentBOS.stream().collect(Collectors.toMap(d->d.getId(), d->d.getName())); +// //管理员所在部门被删后,变成未分配状态 +// deptNameMap.put(0, "未分配"); +// resultPage.getList().forEach(admin->{ +// admin.setDeptment(new AdminVO.Deptment(admin.getDeptmentId(), deptNameMap.get(admin.getDeptmentId()))); +// }); +// } + + return CommonResult.success(adminPageResponse); + } + +// @PostMapping("/add") +// @ApiOperation(value = "创建管理员") +// public CommonResult add(AdminAddDTO adminAddDTO) { +// return success(adminService.addAdmin(AdminSecurityContextHolder.getContext().getAdminId(), adminAddDTO)); +// } +// +// @PostMapping("/update") +// @ApiOperation(value = "更新管理员") +// public CommonResult update(AdminUpdateDTO adminUpdateDTO) { +// return success(adminService.updateAdmin(AdminSecurityContextHolder.getContext().getAdminId(), adminUpdateDTO)); +// } +// +// @PostMapping("/update_status") +// @ApiOperation(value = "更新管理员状态") +// public CommonResult updateStatus(AdminUpdateStatusDTO adminUpdateStatusDTO) { +// return success(adminService.updateAdminStatus(AdminSecurityContextHolder.getContext().getAdminId(), adminUpdateStatusDTO)); +// } +// +// @PostMapping("/delete") +// @ApiOperation(value = "删除管理员") +// @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1") +// public CommonResult delete(@RequestParam("id") Integer id) { +// return success(adminService.deleteAdmin(AdminSecurityContextHolder.getContext().getAdminId(), id)); +// } +// +// @GetMapping("/role_list") +// @ApiOperation(value = "指定管理员拥有的角色列表") +// @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1") +// public CommonResult> roleList(@RequestParam("id") Integer id) { +// // 获得所有角色列表 +// List allRoleList = roleService.getRoleList(); +// // 获得管理员的角色数组 +// Set adminRoleIdSet = CollectionUtil.convertSet(adminService.getRoleList(id), RoleBO::getId); +// // 转换出返回结果 +// List result = AdminConvert.INSTANCE.convert(allRoleList); +// // 设置每个角色是否赋予给改管理员 +// result.forEach(adminRoleVO -> adminRoleVO.setAssigned(adminRoleIdSet.contains(adminRoleVO.getId()))); +// return success(result); +// } +// +// @PostMapping("/assign_role") +// @ApiOperation(value = "分配给管理员角色") +// public CommonResult assignRole(AdminAssignRoleDTO adminAssignRoleDTO) { +// return success(adminService.assignAdminRole(AdminSecurityContextHolder.getContext().getAdminId(), adminAssignRoleDTO)); +// } } diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsAuthorizationController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsAuthorizationController.java index 4864c952..35f94ec0 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsAuthorizationController.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsAuthorizationController.java @@ -2,6 +2,7 @@ package cn.iocoder.mall.system.rest.controller.authorization; import cn.iocoder.common.framework.constant.MallConstants; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.security.core.annotation.RequiresPermissions; import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder; import cn.iocoder.mall.system.biz.bo.authorization.ResourceBO; import cn.iocoder.mall.system.biz.bo.authorization.ResourceTreeNodeBO; @@ -12,6 +13,7 @@ import cn.iocoder.mall.system.biz.dto.authorization.ResourceGetTreeDTO; import cn.iocoder.mall.system.biz.enums.authorization.ResourceTypeEnum; import cn.iocoder.mall.system.biz.service.authorization.AuthorizationService; import cn.iocoder.mall.system.biz.service.authorization.ResourceService; +import cn.iocoder.mall.system.biz.service.authorization.RoleService; import cn.iocoder.mall.system.rest.convert.authorization.AdminsAuthorizationConvert; import cn.iocoder.mall.system.rest.request.authorization.AdminsAuthorizationAssignRoleResourceRequest; import cn.iocoder.mall.system.rest.response.authorization.AdminsAuthorizationMenuTreeResponse; @@ -37,6 +39,8 @@ public class AdminsAuthorizationController { private AuthorizationService authorizationService; @Autowired private ResourceService resourceService; + @Autowired + private RoleService roleService; @GetMapping("/menu-resource-tree") @ApiOperation(value = "获得当前账号的菜单资源树", notes = "以树结构返回") @@ -57,6 +61,7 @@ public class AdminsAuthorizationController { @GetMapping("/role_resource_tree") @ApiOperation(value = "获得角色拥有的菜单权限", notes = "以树结构返回。注意,返回的资源树是完整的结构,会标记每个资源节点是否被角色所拥有") @ApiImplicitParam(name = "roleId", value = "角色编号", required = true, example = "1") + @RequiresPermissions("system:authorization:assign_role_resource") public CommonResult> roleResourceTree(@RequestParam("roleId") Integer roleId) { // 1. 获得完整的资源树 List resourceTreeNodeBOs = resourceService.getResourceTree(new ResourceGetTreeDTO()); @@ -68,6 +73,7 @@ public class AdminsAuthorizationController { @PostMapping("/assign_role_resource") @ApiOperation(value = "分配角色资源") + @RequiresPermissions("system:authorization:assign_role_resource") public CommonResult assignRoleResource(AdminsAuthorizationAssignRoleResourceRequest request) { AuthorizationAssignRoleResourceDTO authorizationAssignRoleResourceDTO = AdminsAuthorizationConvert.INSTANCE.convert(request) .setAdminId(AdminSecurityContextHolder.getAdminId()); @@ -75,4 +81,26 @@ public class AdminsAuthorizationController { return CommonResult.success(true); } +// @GetMapping("/role_list") +// @ApiOperation(value = "指定账号拥有的角色列表") +// @ApiImplicitParam(name = "accountId", value = "账号编号", required = true, example = "1") +// public CommonResult> roleList(@RequestParam("accountId") Integer accountId) { +// // 获得所有角色列表 +// List allRoleList = roleService.getRoleList(); +// // 获得管理员的角色数组 +// Set adminRoleIdSet = CollectionUtil.convertSet(adminService.getRoleList(id), RoleBO::getId); +// // 转换出返回结果 +// List result = AdminConvert.INSTANCE.convert(allRoleList); +// // 设置每个角色是否赋予给改管理员 +// result.forEach(adminRoleVO -> adminRoleVO.setAssigned(adminRoleIdSet.contains(adminRoleVO.getId()))); +// return success(result); +// } +// +// @PostMapping("/assign_role") +// @ApiOperation(value = "分配给管理员角色") +// public CommonResult assignRole(AdminAssignRoleDTO adminAssignRoleDTO) { +// return success(adminService.assignAdminRole(AdminSecurityContextHolder.getContext().getAdminId(), adminAssignRoleDTO)); +// } + + } diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/admin/AdminsAdminConvert.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/admin/AdminsAdminConvert.java index cddb939d..7e3fae0f 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/admin/AdminsAdminConvert.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/admin/AdminsAdminConvert.java @@ -1,7 +1,12 @@ package cn.iocoder.mall.system.rest.convert.admin; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.system.biz.bo.account.AccountUsernameAuthorizeBO; +import cn.iocoder.mall.system.biz.bo.admin.AdminBO; +import cn.iocoder.mall.system.biz.dto.admin.AdminPageDTO; +import cn.iocoder.mall.system.rest.request.admin.AdminsAdminPageRequest; import cn.iocoder.mall.system.rest.request.oauth2.AdminsOAuth2UsernameAuthenticateRequest; +import cn.iocoder.mall.system.rest.response.admin.AdminsAdminPageResponse; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -12,4 +17,8 @@ public interface AdminsAdminConvert { AccountUsernameAuthorizeBO convert(AdminsOAuth2UsernameAuthenticateRequest bean); + AdminPageDTO convert(AdminsAdminPageRequest bean); + + PageResult convertPage(PageResult bean); + } diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/oauth2/AdminsOAuth2Convert.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/oauth2/AdminsOAuth2Convert.java index f65427e1..2279151e 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/oauth2/AdminsOAuth2Convert.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/oauth2/AdminsOAuth2Convert.java @@ -17,7 +17,7 @@ public interface AdminsOAuth2Convert { OAuth2UsernameAuthenticateDTO convert(AdminsOAuth2UsernameAuthenticateRequest bean); @Mapping(source = "adminBO", target = "admin") - @Mapping(source = "accessTokenBO.id", target = "token.accessToken") + @Mapping(source = "accessTokenBO.accessToken", target = "token.accessToken") @Mapping(source = "accessTokenBO.refreshToken", target = "token.refreshToken") @Mapping(source = "accessTokenBO.expiresTime", target = "token.expiresTime") AdminsOAuth2AuthenticateResponse convert(AdminBO adminBO, OAuth2AuthenticateBO accessTokenBO); diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/oauth2/UsersOAuth2Convert.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/oauth2/UsersOAuth2Convert.java index 3ca01f3d..4afec028 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/oauth2/UsersOAuth2Convert.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/oauth2/UsersOAuth2Convert.java @@ -5,7 +5,6 @@ import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2MobileCodeAuthenticateDTO; import cn.iocoder.mall.system.rest.request.oauth2.UsersOAuth2MobileCodeAuthenticateRequest; import cn.iocoder.mall.system.rest.response.user.UsersOAuth2AuthenticateResponse; import org.mapstruct.Mapper; -import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @Mapper @@ -15,7 +14,6 @@ public interface UsersOAuth2Convert { OAuth2MobileCodeAuthenticateDTO convert(UsersOAuth2MobileCodeAuthenticateRequest bean); - @Mapping(source = "token.id", target = "token.accessToken") UsersOAuth2AuthenticateResponse convert(UserAuthenticateBO bean); } diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsAdminPageRequest.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsAdminPageRequest.java new file mode 100644 index 00000000..d8977305 --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/admin/AdminsAdminPageRequest.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.system.rest.request.admin; + +import cn.iocoder.common.framework.vo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +@ApiModel("管理员 - 管理员模块 - 管理员分页信息 Request") +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +public class AdminsAdminPageRequest extends PageParam { + + @ApiModelProperty(value = "真实名字,模糊匹配", example = "小王") + private String name; + + @ApiModelProperty(value = "部门编号") + private Integer departmentId; + +} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/admin/AdminsAdminPageResponse.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/admin/AdminsAdminPageResponse.java new file mode 100644 index 00000000..97828794 --- /dev/null +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/admin/AdminsAdminPageResponse.java @@ -0,0 +1,79 @@ +package cn.iocoder.mall.system.rest.response.admin; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; +import java.util.List; + +@ApiModel("管理员 - 管理员模块 - 管理员分页信息 Response") +@Data +@Accessors(chain = true) +public class AdminsAdminPageResponse { + + @ApiModel("角色") + @Data + @Accessors(chain = true) + public static class Role { + + @ApiModelProperty(value = "角色编号", required = true, example = "1") + private Integer id; + + @ApiModelProperty(value = "角色名", required = true, example = "码神") + private String name; + + } + + @ApiModel("部门") + @Data + @Accessors(chain = true) + public static class Department { + + @ApiModelProperty(value = "部门编号", required = true, example = "1") + private Integer id; + + @ApiModelProperty(value = "部门名称", required = true, example = "研发部") + private String name; + + } + + @ApiModel("账号") + @Data + @Accessors(chain = true) + public static class Account { + + @ApiModelProperty(value = "账号编号", required = true, example = "1") + private Integer id; + + @ApiModelProperty(value = "登陆账号", required = true, example = "15601691300") + private String username; + + } + + @ApiModelProperty(value = "管理员编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "真实名字", required = true, example = "小王") + private String name; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") + private Date createTime; + @ApiModelProperty(value = "在职状态", required = true, example = "1", notes = "见 AdminStatusEnum 枚举") + private Integer status; + + /** + * 账号 + */ + private Account account; + + /** + * 角色列表 + */ + private List roles; + + /** + * 所在部门 + */ + private Department department; + +} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/authorization/AdminsRolePageResponse.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/authorization/AdminsRolePageResponse.java index e5bc4a62..90b3d6d6 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/authorization/AdminsRolePageResponse.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/authorization/AdminsRolePageResponse.java @@ -18,6 +18,8 @@ public class AdminsRolePageResponse { private String name; @ApiModelProperty(value = "角色编码", example = "SUPER_ADMIN") private String code; + @ApiModelProperty(value = "角色类型", required = true, example = "1-系统角色; 2-内置角色") + private Integer type; @ApiModelProperty(value = "创建时间", required = true) private Date createTime; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/AdminService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/AdminService.java index 90dcdbc4..14ddfcc6 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/AdminService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/AdminService.java @@ -1,11 +1,8 @@ package cn.iocoder.mall.system.api; import cn.iocoder.common.framework.vo.PageResult; -import cn.iocoder.mall.system.api.bo.admin.AdminAuthenticationBO; -import cn.iocoder.mall.system.api.bo.admin.AdminAuthorizationBO; import cn.iocoder.mall.system.api.bo.admin.AdminBO; import cn.iocoder.mall.system.api.bo.role.RoleBO; -import cn.iocoder.mall.admin.api.dto.admin.*; import cn.iocoder.mall.system.api.dto.admin.*; import java.util.Collection; @@ -17,16 +14,6 @@ import java.util.Map; */ public interface AdminService { - /** - * 管理员认证。认证成功后,返回认证信息 - * - * 实际上,就是用户名 + 密码登陆 - * - * @param adminAuthenticationDTO 用户认证信息 - * @return 认证信息 - */ - AdminAuthenticationBO authentication(AdminAuthenticationDTO adminAuthenticationDTO); - PageResult getAdminPage(AdminPageDTO adminPageDTO); AdminBO addAdmin(Integer adminId, AdminAddDTO adminAddDTO); @@ -62,13 +49,4 @@ public interface AdminService { */ Boolean assignAdminRole(Integer adminId, AdminAssignRoleDTO adminAssignRoleDTO); - /** - * 判断管理员是否有指定权限 - * - * @param adminId 管理员 - * @param permissions 权限数组 - * @return 管理员授权信息 - */ - AdminAuthorizationBO checkPermissions(Integer adminId, List permissions); - } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/OAuth2Service.java b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/OAuth2Service.java index 1065ce71..693943a1 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/OAuth2Service.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/OAuth2Service.java @@ -1,10 +1,5 @@ package cn.iocoder.mall.system.api; -import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AccessTokenBO; -import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AuthenticationBO; -import cn.iocoder.mall.system.api.dto.oauth2.OAuth2CreateTokenDTO; -import cn.iocoder.mall.system.api.dto.oauth2.OAuth2GetTokenDTO; -import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RefreshTokenDTO; import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RemoveTokenByUserDTO; /** @@ -12,14 +7,6 @@ import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RemoveTokenByUserDTO; */ public interface OAuth2Service { - /** - * 根据身份信息,创建 accessToken 信息 - * - * @param oauth2CreateTokenDTO 身份信息 DTO - * @return accessToken 信息 - */ - OAuth2AccessTokenBO createToken(OAuth2CreateTokenDTO oauth2CreateTokenDTO); - /** * 基于用户移除 accessToken * @@ -27,20 +14,4 @@ public interface OAuth2Service { */ void removeToken(OAuth2RemoveTokenByUserDTO oauth2RemoveTokenDTO); - /** - * 刷新令牌,获得新的 accessToken 信息 - * - * @param oauth2RefreshTokenDTO refreshToken 信息 - * @return accessToken 信息 - */ - OAuth2AccessTokenBO refreshToken(OAuth2RefreshTokenDTO oauth2RefreshTokenDTO); - - /** - * 通过 accessToken 获得身份信息 - * - * @param oauth2GetTokenDTO accessToken 信息 - * @return 身份信息 - */ - OAuth2AuthenticationBO getAuthentication(OAuth2GetTokenDTO oauth2GetTokenDTO); - } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/RoleService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/RoleService.java index 787441ae..503d1d37 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/RoleService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/RoleService.java @@ -1,24 +1,14 @@ package cn.iocoder.mall.system.api; -import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.system.api.bo.role.RoleBO; -import cn.iocoder.mall.system.api.dto.role.RoleAddDTO; -import cn.iocoder.mall.system.api.dto.role.RoleAssignResourceDTO; -import cn.iocoder.mall.system.api.dto.role.RolePageDTO; -import cn.iocoder.mall.system.api.dto.role.RoleUpdateDTO; -import java.util.Collection; import java.util.List; public interface RoleService { - PageResult getRolePage(RolePageDTO rolePageDTO); - /** * @return 返回角色列表 */ List getRoleList(); - Boolean assignRoleResource(Integer adminId, RoleAssignResourceDTO roleAssignResourceDTO); - } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/dto/admin/AdminAuthenticationDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/dto/admin/AdminAuthenticationDTO.java deleted file mode 100644 index 8f273dfd..00000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/dto/admin/AdminAuthenticationDTO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.mall.system.api.dto.admin; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; - -@ApiModel("管理员认证 DTO") -@Data -@Accessors(chain = true) -public class AdminAuthenticationDTO { - - @ApiModelProperty(value = "登陆账号", required = true, example = "15601691300") - @NotEmpty(message = "登陆账号不能为空") - @Length(min = 5, max = 16, message = "账号长度为 5-16 位") - @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母") - private String username; - - @ApiModelProperty(value = "密码", required = true, example = "buzhidao") - @NotEmpty(message = "密码不能为空") - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") - private String password; - -} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java deleted file mode 100644 index ec539580..00000000 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.mall.admin.dao; - -import cn.iocoder.common.framework.mybatis.QueryWrapperX; -import cn.iocoder.mall.system.api.dto.admin.AdminPageDTO; -import cn.iocoder.mall.admin.dataobject.AdminDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -@Repository -public interface AdminMapper extends BaseMapper { - - default AdminDO selectByUsername(@Param("username") String username) { - return selectOne(new QueryWrapper().eq("username", username)); - } - - default IPage selectPage(AdminPageDTO adminPageDTO) { - return selectPage(new Page<>(adminPageDTO.getPageNo(), adminPageDTO.getPageSize()), - new QueryWrapperX().likeIfPresent("nickname", adminPageDTO.getNickname()) - .eqIfPresent("deptment_id", adminPageDTO.getDeptmentId())); - } - - default int updateDeptByDeptId(@Param("fromDeptId")Integer fromDeptId, @Param("toDeptId")Integer toDeptId){ - QueryWrapper query = new QueryWrapper() - .eq("deptment_id", fromDeptId); - return update(new AdminDO().setDeptmentId(toDeptId), query); - } - -} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java deleted file mode 100644 index fd644c72..00000000 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.mall.admin.dataobject; - -import cn.iocoder.common.framework.dataobject.DeletableDO; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -/** - * 管理员实体 - */ -@TableName(value = "admin") -@Data -@EqualsAndHashCode(callSuper = true) -@Accessors(chain = true) -public class AdminDO extends DeletableDO { - - /** - * 管理员编号 - */ - private Integer id; - /** - * 登陆账号 - */ - private String username; - /** - * 昵称 - */ - private String nickname; - /** - * 密码 - * - * TODO 芋艿 暂时最简单的 MD5 - */ - private String password; - /** - * 账号状态 - */ - private Integer status; - - /** - * 管理员部门id - */ - private Integer deptmentId; - - - // TODO 芋艿,最后登陆时间、最后登陆 IP - // TODO 芋艿,登陆日志 - -} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java index e6c83d14..4cccbbbc 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java @@ -39,27 +39,6 @@ public class OAuth2ServiceImpl implements OAuth2Service { @Autowired private AdminServiceImpl adminService; - @Autowired - private OAuth2AccessTokenMapper oauth2AccessTokenMapper; - @Autowired - private OAuth2RefreshTokenMapper oauth2RefreshTokenMapper; - @Autowired - private RoleServiceImpl roleService; - @Autowired - private ResourceServiceImpl resourceService; - - @Override - @Transactional - public OAuth2AccessTokenBO createToken(OAuth2CreateTokenDTO oauth2CreateTokenDTO) { - Integer userId = oauth2CreateTokenDTO.getUserId(); - Integer userType = oauth2CreateTokenDTO.getUserType(); - // 创建刷新令牌 - OAuth2RefreshTokenDO oauth2RefreshTokenDO = createOAuth2RefreshToken(userId, userType); - // 创建访问令牌 - OAuth2AccessTokenDO oauth2AccessTokenDO = createOAuth2AccessToken(userId, userType, oauth2RefreshTokenDO.getId()); - // 转换返回 - return OAuth2Convert.INSTANCE.convertToAccessTokenWithExpiresIn(oauth2AccessTokenDO); - } @Override @Transactional @@ -72,76 +51,4 @@ public class OAuth2ServiceImpl implements OAuth2Service { oauth2RefreshTokenMapper.updateToInvalid(userId, userType); } - @Override - public OAuth2AccessTokenBO refreshToken(OAuth2RefreshTokenDTO oauth2RefreshTokenDTO) { - OAuth2RefreshTokenDO refreshTokenDO = oauth2RefreshTokenMapper.selectById(oauth2RefreshTokenDTO.getRefreshToken()); - // 校验刷新令牌是否合法 - if (refreshTokenDO == null) { // 不存在 - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.OAUTH_INVALID_REFRESH_TOKEN_NOT_FOUND.getCode()); - } - if (refreshTokenDO.getExpiresTime().getTime() < System.currentTimeMillis()) { // 已过期 - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.OAUTH_INVALID_REFRESH_TOKEN_EXPIRED.getCode()); - } - if (!refreshTokenDO.getValid()) { // 无效 - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.OAUTH_INVALID_REFRESH_TOKEN_INVALID.getCode()); - } - // 标记 refreshToken 对应的 accessToken 都不合法 - oauth2AccessTokenMapper.updateToInvalidByRefreshToken(oauth2RefreshTokenDTO.getRefreshToken()); - // 创建访问令牌 - OAuth2AccessTokenDO oauth2AccessTokenDO = createOAuth2AccessToken(refreshTokenDO.getUserId(), refreshTokenDO.getUserType(), - refreshTokenDO.getId()); - // 转换返回 - return OAuth2Convert.INSTANCE.convertToAccessTokenWithExpiresIn(oauth2AccessTokenDO); - } - - @Override - public OAuth2AuthenticationBO getAuthentication(OAuth2GetTokenDTO oauth2GetTokenDTO) { - OAuth2AccessTokenDO accessTokenDO = oauth2AccessTokenMapper.selectById(oauth2GetTokenDTO.getAccessToken()); - if (accessTokenDO == null) { // 不存在 - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.OAUTH2_INVALID_TOKEN_NOT_FOUND.getCode()); - } - if (accessTokenDO.getExpiresTime().getTime() < System.currentTimeMillis()) { // 已过期 - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.OAUTH2_INVALID_TOKEN_EXPIRED.getCode()); - } - if (!accessTokenDO.getValid()) { // 无效 - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.OAUTH2_INVALID_TOKEN_INVALID.getCode()); - } - if (!oauth2GetTokenDTO.getUserType().equals(accessTokenDO.getUserType())) { - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.OAUTH2_INVALID_TOKEN_INVALID.getCode()); - } - // 转换返回 - return OAuth2Convert.INSTANCE.convertToAuthentication(accessTokenDO); - } - - private OAuth2AccessTokenDO createOAuth2AccessToken(Integer userId, Integer userType, String refreshToken) { - OAuth2AccessTokenDO accessToken - = new OAuth2AccessTokenDO() - .setId(generateAccessToken()) - .setRefreshToken(refreshToken) - .setUserId(userId).setUserType(userType) - .setExpiresTime(new Date(System.currentTimeMillis() + accessTokenExpireTimeMillis)) - .setValid(true); - oauth2AccessTokenMapper.insert(accessToken); - return accessToken; - } - - private OAuth2RefreshTokenDO createOAuth2RefreshToken(Integer userId, Integer userType) { - OAuth2RefreshTokenDO refreshToken - = new OAuth2RefreshTokenDO() - .setId(generateRefreshToken()) - .setUserId(userId).setUserType(userType) - .setExpiresTime(new Date(System.currentTimeMillis() + refreshTokenExpireTimeMillis)) - .setValid(true); - oauth2RefreshTokenMapper.insert(refreshToken); - return refreshToken; - } - - private String generateAccessToken() { - return UUID.randomUUID().toString().replaceAll("-", ""); - } - - private String generateRefreshToken() { - return UUID.randomUUID().toString().replaceAll("-", ""); - } - } diff --git a/system/system-start/src/main/java/cn/iocoder/mall/system/application/controller/admins/AdminController.java b/system/system-start/src/main/java/cn/iocoder/mall/system/application/controller/admins/AdminController.java index 0e634598..86151f6d 100644 --- a/system/system-start/src/main/java/cn/iocoder/mall/system/application/controller/admins/AdminController.java +++ b/system/system-start/src/main/java/cn/iocoder/mall/system/application/controller/admins/AdminController.java @@ -102,25 +102,4 @@ public class AdminController { return success(adminService.deleteAdmin(AdminSecurityContextHolder.getContext().getAdminId(), id)); } - @GetMapping("/role_list") - @ApiOperation(value = "指定管理员拥有的角色列表") - @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1") - public CommonResult> roleList(@RequestParam("id") Integer id) { - // 获得所有角色列表 - List allRoleList = roleService.getRoleList(); - // 获得管理员的角色数组 - Set adminRoleIdSet = CollectionUtil.convertSet(adminService.getRoleList(id), RoleBO::getId); - // 转换出返回结果 - List result = AdminConvert.INSTANCE.convert(allRoleList); - // 设置每个角色是否赋予给改管理员 - result.forEach(adminRoleVO -> adminRoleVO.setAssigned(adminRoleIdSet.contains(adminRoleVO.getId()))); - return success(result); - } - - @PostMapping("/assign_role") - @ApiOperation(value = "分配给管理员角色") - public CommonResult assignRole(AdminAssignRoleDTO adminAssignRoleDTO) { - return success(adminService.assignAdminRole(AdminSecurityContextHolder.getContext().getAdminId(), adminAssignRoleDTO)); - } - }