From 39f36837eab251da281f9a369706ba6ff35f124b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 15 May 2019 20:18:09 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E9=87=8D?= =?UTF-8?q?=E6=9E=84=20system=20=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-web/src/models/admin/roleList.js | 6 +- admin-web/src/pages/Admin/AdminList.js | 30 ++++- admin-web/src/pages/Admin/RoleList.js | 16 +-- common/common-framework/pom.xml | 9 ++ .../framework/mybatis/QueryWrapperX.java | 22 ++++ .../common/framework/util/CollectionUtil.java | 26 +++- .../common/framework/vo/PageParam.java | 45 +++++++ .../common/framework/vo/PageResult.java | 36 ++++++ .../web/handler/GlobalExceptionHandler.java | 4 +- .../web/interceptor/AccessLogInterceptor.java | 2 +- docs/guides/功能列表/功能列表-管理后台.md | 6 +- .../controller/users/OrderController.java | 2 +- .../users/OrderLogisticsController.java | 2 +- .../users/OrderReturnController.java | 2 +- .../biz/service/OrderReturnServiceImpl.java | 2 +- pom.xml | 11 ++ .../controller/admins/AdminController.java | 84 +++++------- .../controller/admins/DataDictController.java | 10 +- .../controller/admins/PassportController.java | 2 +- .../controller/admins/ResourceController.java | 53 ++------ .../controller/admins/RoleController.java | 61 ++++----- .../application/convert/AdminConvert.java | 20 +-- .../application/convert/DataDictConvert.java | 8 +- .../application/convert/PassportConvert.java | 4 +- .../application/convert/ResourceConvert.java | 12 +- .../application/convert/RoleConvert.java | 22 +--- .../admin/application/vo/AdminPageVO.java | 20 --- .../mall/admin/application/vo/AdminVO.java | 30 ----- .../mall/admin/application/vo/RolePageVO.java | 20 --- .../mall/admin/application/vo/RoleVO.java | 22 ---- .../vo/{ => admin}/AdminInfoVO.java | 4 +- .../vo/{ => admin}/AdminMenuTreeNodeVO.java | 2 +- .../vo/{ => admin}/AdminRoleVO.java | 2 +- .../admin/application/vo/admin/AdminVO.java | 31 +++++ .../vo/{ => datadict}/DataDictEnumVO.java | 2 +- .../vo/{ => datadict}/DataDictVO.java | 2 +- .../vo/{ => datadict}/DataDictValueVO.java | 2 +- .../{ => vo/oauth2}/SystemApplication.java | 2 +- .../vo/{ => resource}/ResourceTreeNodeVO.java | 2 +- .../vo/{ => resource}/ResourceVO.java | 2 +- .../vo/{ => role}/RoleResourceTreeNodeVO.java | 2 +- .../interceptor/AdminSecurityInterceptor.java | 2 +- system/system-service-api/pom.xml | 4 +- .../iocoder/mall/admin/api/AdminService.java | 48 +++++-- .../mall/admin/api/DataDictService.java | 6 +- .../iocoder/mall/admin/api/OAuth2Service.java | 6 +- .../mall/admin/api/ResourceService.java | 15 +-- .../iocoder/mall/admin/api/RoleService.java | 38 +++--- .../mall/admin/api/SystemLogService.java | 4 +- .../iocoder/mall/admin/api/bo/ResourceBO.java | 49 ------- .../iocoder/mall/admin/api/bo/RolePageBO.java | 25 ---- .../mall/admin/api/bo/admin/AdminBO.java | 2 +- .../api/bo/{ => datadict}/DataDictBO.java | 2 +- .../bo/{ => oauth2}/OAuth2AccessTokenBO.java | 2 +- .../{ => oauth2}/OAuth2AuthenticationBO.java | 2 +- .../admin/api/bo/resource/ResourceBO.java | 40 ++++++ .../mall/admin/api/bo/{ => role}/RoleBO.java | 2 +- .../api/constant/AdminErrorCodeEnum.java | 4 +- .../admin/api/constant/ResourceConstants.java | 6 +- .../mall/admin/api/dto/ResourceAddDTO.java | 46 ------- .../mall/admin/api/dto/ResourceUpdateDTO.java | 46 ------- .../mall/admin/api/dto/RolePageDTO.java | 45 ------- .../api/dto/admin/AdminAssignRoleDTO.java | 23 ++++ .../admin/api/dto/admin/AdminPageDTO.java | 18 +-- .../admin/api/dto/admin/AdminUpdateDTO.java | 33 ++--- .../api/dto/admin/AdminUpdateStatusDTO.java | 26 ++++ .../dto/{ => datadict}/DataDictAddDTO.java | 2 +- .../dto/{ => datadict}/DataDictUpdateDTO.java | 2 +- .../api/dto/resource/ResourceAddDTO.java | 43 ++++++ .../api/dto/resource/ResourceUpdateDTO.java | 47 +++++++ .../admin/api/dto/{ => role}/RoleAddDTO.java | 12 +- .../api/dto/role/RoleAssignResourceDTO.java | 23 ++++ .../mall/admin/api/dto/role/RolePageDTO.java | 17 +++ .../api/dto/{ => role}/RoleUpdateDTO.java | 17 +-- .../dto/{ => systemlog}/AccessLogAddDTO.java | 2 +- .../{ => systemlog}/ExceptionLogAddDTO.java | 2 +- .../admin/config/DatabaseConfiguration.java | 6 + .../mall/admin/convert/AccessLogConvert.java | 4 +- .../mall/admin/convert/AdminConvert.java | 8 ++ .../mall/admin/convert/DataDictConvert.java | 8 +- .../mall/admin/convert/OAuth2Convert.java | 6 +- .../mall/admin/convert/ResourceConvert.java | 20 ++- .../mall/admin/convert/RoleConvert.java | 16 ++- .../iocoder/mall/admin/dao/AdminMapper.java | 17 ++- .../mall/admin/dao/AdminRoleMapper.java | 11 +- .../cn/iocoder/mall/admin/dao/RoleMapper.java | 36 +++--- .../mall/admin/dataobject/AccessLogDO.java | 3 +- .../mall/admin/dataobject/AdminRoleDO.java | 2 + .../mall/admin/dataobject/ExceptionLogDO.java | 3 +- .../mall/admin/dataobject/ResourceDO.java | 39 ++---- .../iocoder/mall/admin/dataobject/RoleDO.java | 2 + .../mall/admin/service/AdminServiceImpl.java | 122 +++++++++++------- .../admin/service/DataDictServiceImpl.java | 6 +- .../mall/admin/service/OAuth2ServiceImpl.java | 4 +- .../admin/service/ResourceServiceImpl.java | 99 +++++++------- .../mall/admin/service/RoleServiceImpl.java | 89 ++++++------- .../admin/service/SystemLogServiceImpl.java | 4 +- .../main/resources/config/application.yaml | 6 + .../src/main/resources/mapper/AdminMapper.xml | 65 ---------- .../main/resources/mapper/ResourceMapper.xml | 20 +-- .../src/main/resources/mapper/RoleMapper.xml | 81 ------------ .../src/main/resources/mybatis-config.xml | 19 --- 102 files changed, 943 insertions(+), 1056 deletions(-) create mode 100644 common/common-framework/src/main/java/cn/iocoder/common/framework/mybatis/QueryWrapperX.java create mode 100644 common/common-framework/src/main/java/cn/iocoder/common/framework/vo/PageParam.java create mode 100644 common/common-framework/src/main/java/cn/iocoder/common/framework/vo/PageResult.java delete mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminPageVO.java delete mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java delete mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RolePageVO.java delete mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RoleVO.java rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/{ => admin}/AdminInfoVO.java (75%) rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/{ => admin}/AdminMenuTreeNodeVO.java (95%) rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/{ => admin}/AdminRoleVO.java (91%) create mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminVO.java rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/{ => datadict}/DataDictEnumVO.java (90%) rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/{ => datadict}/DataDictVO.java (93%) rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/{ => datadict}/DataDictValueVO.java (89%) rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/{ => vo/oauth2}/SystemApplication.java (93%) rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/{ => resource}/ResourceTreeNodeVO.java (96%) rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/{ => resource}/ResourceVO.java (95%) rename system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/{ => role}/RoleResourceTreeNodeVO.java (95%) delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/ResourceBO.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/RolePageBO.java rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/{ => datadict}/DataDictBO.java (93%) rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/{ => oauth2}/OAuth2AccessTokenBO.java (90%) rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/{ => oauth2}/OAuth2AuthenticationBO.java (89%) create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/resource/ResourceBO.java rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/{ => role}/RoleBO.java (90%) delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ResourceAddDTO.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ResourceUpdateDTO.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RolePageDTO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAssignRoleDTO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateStatusDTO.java rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/{ => datadict}/DataDictAddDTO.java (94%) rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/{ => datadict}/DataDictUpdateDTO.java (94%) create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/resource/ResourceAddDTO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/resource/ResourceUpdateDTO.java rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/{ => role}/RoleAddDTO.java (51%) create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleAssignResourceDTO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RolePageDTO.java rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/{ => role}/RoleUpdateDTO.java (56%) rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/{ => systemlog}/AccessLogAddDTO.java (96%) rename system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/{ => systemlog}/ExceptionLogAddDTO.java (97%) delete mode 100644 system/system-service-impl/src/main/resources/mapper/AdminMapper.xml delete mode 100644 system/system-service-impl/src/main/resources/mapper/RoleMapper.xml delete mode 100644 system/system-service-impl/src/main/resources/mybatis-config.xml diff --git a/admin-web/src/models/admin/roleList.js b/admin-web/src/models/admin/roleList.js index 1b8b97e8f..0933e493e 100644 --- a/admin-web/src/models/admin/roleList.js +++ b/admin-web/src/models/admin/roleList.js @@ -65,12 +65,12 @@ export default { *query({ payload }, { call, put }) { const response = yield call(queryRole, payload); message.info('查询成功!'); - const { count, roles } = response.data; + const { total, list } = response.data; yield put({ type: 'querySuccess', payload: { - list: roles, - count, + list: list, + count: total, }, }); }, diff --git a/admin-web/src/pages/Admin/AdminList.js b/admin-web/src/pages/Admin/AdminList.js index 91206b454..8e4e77ca5 100644 --- a/admin-web/src/pages/Admin/AdminList.js +++ b/admin-web/src/pages/Admin/AdminList.js @@ -65,13 +65,29 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch, const columns = [ { - title: '用户名', + title: '账号', dataIndex: 'username' }, { - title: '昵称', + title: '员工姓名', dataIndex: 'nickname', }, + { + title: '角色', + dataIndex: 'roles', + render(roles) { + let text = ''; + if (roles) { + for (let i in roles) { + if (i > 0) { + text += ' '; + } + text += roles[i].name; + } + } + return ({text}); + } + }, { title: '状态', dataIndex: 'status', @@ -174,7 +190,7 @@ const SearchForm = Form.create()(props => {
- + {getFieldDecorator('nickname')()} @@ -251,18 +267,18 @@ const AddOrUpdateForm = Form.create()(props => { okText='保存' onCancel={() => handleModalVisible()} > - + {form.getFieldDecorator('username', { - rules: [{ required: true, message: '请输入用户名!'}, + 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', { - rules: [{ required: true, message: '请输入昵称!'}, + rules: [{ required: true, message: '请输入员工姓名!'}, {max: 10, message: '姓名最大长度为 10'}], initialValue: formVals.nickname, })()} diff --git a/admin-web/src/pages/Admin/RoleList.js b/admin-web/src/pages/Admin/RoleList.js index c17797ba8..aca549cc5 100644 --- a/admin-web/src/pages/Admin/RoleList.js +++ b/admin-web/src/pages/Admin/RoleList.js @@ -143,7 +143,7 @@ class RoleList extends PureComponent { type: 'roleList/query', payload: { name: '', - pageNo: 0, + pageNo: 1, pageSize: 10, }, }); @@ -277,11 +277,11 @@ class RoleList extends PureComponent { }; const columns = [ - { - title: 'id', - dataIndex: 'id', - render: text => {text}, - }, + // { + // title: 'id', + // dataIndex: 'id', + // render: text => {text}, + // }, { title: '名称', dataIndex: 'name', @@ -289,7 +289,7 @@ class RoleList extends PureComponent { { title: '创建时间', dataIndex: 'createTime', - sorter: true, + // sorter: true, render: val => {moment(val).format('YYYY-MM-DD')}, }, { @@ -325,7 +325,7 @@ class RoleList extends PureComponent { type="primary" onClick={() => this.handleModalVisible(true, 'add', {})} > - 新建 + 新建角色 diff --git a/common/common-framework/pom.xml b/common/common-framework/pom.xml index 76937f96f..674893bf9 100644 --- a/common/common-framework/pom.xml +++ b/common/common-framework/pom.xml @@ -26,6 +26,11 @@ spring-webmvc + + io.swagger + swagger-annotations + + org.mybatis @@ -36,6 +41,10 @@ com.baomidou mybatis-plus-annotation + + com.baomidou + mybatis-plus-core + diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/mybatis/QueryWrapperX.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/mybatis/QueryWrapperX.java new file mode 100644 index 000000000..a1de9eeee --- /dev/null +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/mybatis/QueryWrapperX.java @@ -0,0 +1,22 @@ +package cn.iocoder.common.framework.mybatis; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.springframework.util.StringUtils; + +/** + * 拓展 MyBatis Plus QueryWrapper 类,主要增加如下功能: + * + * 1. 拼接条件的方法,增加 xxxIfPresent 方法,用于判断值不存在的时候,不要拼接到条件中。 + * + * @param 数据类型 + */ +public class QueryWrapperX extends QueryWrapper { + + public QueryWrapperX likeIfPresent(String column, String val) { + if (StringUtils.hasText(val)) { + return (QueryWrapperX) super.like(column, val); + } + return this; + } + +} 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 f1af58317..81cdbcb3d 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 @@ -1,9 +1,8 @@ package cn.iocoder.common.framework.util; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; public class CollectionUtil { @@ -14,4 +13,21 @@ public class CollectionUtil { public static Set asSet(T... objs) { return new HashSet<>(Arrays.asList(objs)); } -} \ No newline at end of file + + public static List convertList(List from, Function func) { + return from.stream().map(func).collect(Collectors.toList()); + } + + public static Set convertSet(List from, Function func) { + return from.stream().map(func).collect(Collectors.toSet()); + } + + public static Map convertMap(List from, Function keyFunc, Function valueFunc) { + return from.stream().collect(Collectors.toMap(keyFunc, valueFunc)); + } + + public static Map convertMap(List from, Function keyFunc) { + return from.stream().collect(Collectors.toMap(keyFunc, item -> item)); + } + +} diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/vo/PageParam.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/vo/PageParam.java new file mode 100644 index 000000000..5b4d4f6e8 --- /dev/null +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/vo/PageParam.java @@ -0,0 +1,45 @@ +package cn.iocoder.common.framework.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +@ApiModel("分页参数") +public class PageParam { + + @ApiModelProperty(value = "页码,从 1 开始", required = true,example = "1") + @NotNull(message = "页码不能为空") + @Min(value = 1, message = "页码最小值为 1") + private Integer pageNo; + + @ApiModelProperty(value = "每页条数,最大值为 100", required = true, example = "10") + @NotNull(message = "每页条数不能为空") + @Range(min = 1, max = 100, message = "条数范围为 [1, 100]") + private Integer pageSize; + + public Integer getPageNo() { + return pageNo; + } + + public PageParam setPageNo(Integer pageNo) { + this.pageNo = pageNo; + return this; + } + + public Integer getPageSize() { + return pageSize; + } + + public PageParam setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public final int getOffset() { + return (pageNo - 1) * pageSize; + } + +} diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/vo/PageResult.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/vo/PageResult.java new file mode 100644 index 000000000..b454c54bb --- /dev/null +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/vo/PageResult.java @@ -0,0 +1,36 @@ +package cn.iocoder.common.framework.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +import java.util.List; + +@ApiModel("分页结果") +public final class PageResult implements Serializable { + + @ApiModelProperty(value = "数据", required = true) + private List list; + + @ApiModelProperty(value = "总量", required = true) + private Integer total; + + public List getList() { + return list; + } + + public PageResult setList(List list) { + this.list = list; + return this; + } + + public Integer getTotal() { + return total; + } + + public PageResult setTotal(Integer total) { + this.total = total; + return this; + } + +} diff --git a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/handler/GlobalExceptionHandler.java b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/handler/GlobalExceptionHandler.java index 7c11be672..b4d4b77bb 100644 --- a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/handler/GlobalExceptionHandler.java +++ b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/handler/GlobalExceptionHandler.java @@ -7,8 +7,8 @@ import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.MallUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.SystemLogService; -import cn.iocoder.mall.admin.api.dto.AccessLogAddDTO; -import cn.iocoder.mall.admin.api.dto.ExceptionLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.ExceptionLogAddDTO; import com.alibaba.fastjson.JSON; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.dubbo.config.annotation.Reference; diff --git a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/interceptor/AccessLogInterceptor.java b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/interceptor/AccessLogInterceptor.java index 335054e23..46c90c6e1 100644 --- a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/interceptor/AccessLogInterceptor.java +++ b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/interceptor/AccessLogInterceptor.java @@ -4,7 +4,7 @@ import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.MallUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.SystemLogService; -import cn.iocoder.mall.admin.api.dto.AccessLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; import com.alibaba.fastjson.JSON; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.dubbo.config.annotation.Reference; diff --git a/docs/guides/功能列表/功能列表-管理后台.md b/docs/guides/功能列表/功能列表-管理后台.md index 9b79f4d35..bb534edfc 100644 --- a/docs/guides/功能列表/功能列表-管理后台.md +++ b/docs/guides/功能列表/功能列表-管理后台.md @@ -18,7 +18,7 @@ - [ ] 订单管理 - [ ] 销售单 开发中 - [ ] 售后单 开发中 - - [ ] 订单评价【待认领】 + - [ ] 订单评价【开发中】 - [ ] 会员管理 - [ ] 会员资料 20%【待认领】 - TODO 需要补充 @@ -31,8 +31,8 @@ - [ ] 限制折扣 20% 【待认领】 - [ ] 多人拼团【待认领】 - [ ] 系统管理 - - [ ] 员工管理 - - [ ] 角色管理 + - [x] 员工管理 + - [x] 角色管理 - [ ] 权限管理 - [ ] 短信管理 - [ ] 短信模板 diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderController.java index 8b718e357..587559b1e 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderController.java @@ -4,7 +4,7 @@ import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.DataDictService; -import cn.iocoder.mall.admin.api.bo.DataDictBO; +import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; import cn.iocoder.mall.order.api.CartService; import cn.iocoder.mall.order.api.OrderService; import cn.iocoder.mall.order.api.bo.*; diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java index 75bbf0c0b..34cbcf972 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java @@ -3,7 +3,7 @@ package cn.iocoder.mall.order.application.controller.users; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.DataDictService; -import cn.iocoder.mall.admin.api.bo.DataDictBO; +import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; import cn.iocoder.mall.order.api.OrderLogisticsService; import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO; import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoWithOrderBO; diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderReturnController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderReturnController.java index 663816cb9..b17359796 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderReturnController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderReturnController.java @@ -2,7 +2,7 @@ package cn.iocoder.mall.order.application.controller.users; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.DataDictService; -import cn.iocoder.mall.admin.api.bo.DataDictBO; +import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; import cn.iocoder.mall.order.api.OrderReturnService; import cn.iocoder.mall.order.api.bo.OrderReturnInfoBO; import cn.iocoder.mall.order.api.constant.DictKeyConstants; diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java index c96a7a19e..3c77c12d1 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java @@ -4,7 +4,7 @@ import cn.iocoder.common.framework.constant.DeletedStatusEnum; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.DataDictService; -import cn.iocoder.mall.admin.api.bo.DataDictBO; +import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; import cn.iocoder.mall.order.api.OrderLogisticsService; import cn.iocoder.mall.order.api.OrderReturnService; import cn.iocoder.mall.order.api.bo.OrderLastLogisticsInfoBO; diff --git a/pom.xml b/pom.xml index d646411cf..45f2f5994 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ 2.13.0 + 1.5.21 2.9.2 1.9.3 2.0.0 @@ -88,6 +89,11 @@ ${springboot.version} + + io.swagger + swagger-annotations + ${swagger.version} + io.springfox springfox-swagger2 @@ -144,6 +150,11 @@ mybatis-plus-annotation ${mybatis-plus.version} + + com.baomidou + mybatis-plus-core + ${mybatis-plus.version} + com.baomidou mybatis-plus-boot-starter diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java index b7bcb0b23..ff043b462 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java @@ -1,27 +1,25 @@ package cn.iocoder.mall.admin.application.controller.admins; import cn.iocoder.common.framework.constant.MallConstants; +import cn.iocoder.common.framework.util.CollectionUtil; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.admin.api.AdminService; import cn.iocoder.mall.admin.api.ResourceService; import cn.iocoder.mall.admin.api.RoleService; -import cn.iocoder.mall.admin.api.bo.ResourceBO; -import cn.iocoder.mall.admin.api.bo.RoleBO; +import cn.iocoder.mall.admin.api.bo.resource.ResourceBO; +import cn.iocoder.mall.admin.api.bo.role.RoleBO; import cn.iocoder.mall.admin.api.bo.admin.AdminBO; -import cn.iocoder.mall.admin.api.bo.admin.AdminPageBO; import cn.iocoder.mall.admin.api.constant.ResourceConstants; -import cn.iocoder.mall.admin.api.dto.admin.AdminAddDTO; -import cn.iocoder.mall.admin.api.dto.admin.AdminPageDTO; -import cn.iocoder.mall.admin.api.dto.admin.AdminUpdateDTO; +import cn.iocoder.mall.admin.api.dto.admin.*; import cn.iocoder.mall.admin.application.convert.AdminConvert; import cn.iocoder.mall.admin.application.convert.ResourceConvert; -import cn.iocoder.mall.admin.application.vo.AdminMenuTreeNodeVO; -import cn.iocoder.mall.admin.application.vo.AdminPageVO; -import cn.iocoder.mall.admin.application.vo.AdminRoleVO; +import cn.iocoder.mall.admin.application.vo.admin.AdminMenuTreeNodeVO; +import cn.iocoder.mall.admin.application.vo.admin.AdminRoleVO; +import cn.iocoder.mall.admin.application.vo.admin.AdminVO; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.dubbo.config.annotation.Reference; import org.springframework.web.bind.annotation.*; @@ -38,8 +36,10 @@ public class AdminController { @Reference(validation = "true", version = "${dubbo.provider.ResourceService.version}") private ResourceService resourceService; + @Reference(validation = "true", version = "${dubbo.provider.AdminService.version}") private AdminService adminService; + @Reference(validation = "true", version = "${dubbo.provider.RoleService.version}") private RoleService roleService; @@ -51,7 +51,8 @@ public class AdminController { @GetMapping("/menu_resource_tree") @ApiOperation(value = "获得当前登陆的管理员拥有的菜单权限", notes = "以树结构返回") public CommonResult> menuResourceTree() { - List resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_MENU, AdminSecurityContextHolder.getContext().getRoleIds()); + List resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_MENU, + AdminSecurityContextHolder.getContext().getRoleIds()); // 创建 AdminMenuTreeNodeVO Map Map treeNodeMap = new LinkedHashMap<>(); // 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。 resources.stream().sorted(Comparator.comparing(ResourceBO::getSort)).forEach(resourceBO -> treeNodeMap.put(resourceBO.getId(), ResourceConvert.INSTANCE.convert(resourceBO))); @@ -77,9 +78,8 @@ public class AdminController { @GetMapping("/url_resource_list") @ApiOperation(value = "获得当前登陆的管理员拥有的 URL 权限列表") -// @ApiModelProperty(value = "data", example = "['/admin/role/add', '/admin/role/update']") 没效果 public CommonResult> urlResourceList() { - List resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_URL, AdminSecurityContextHolder.getContext().getRoleIds()); + List resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_BUTTON, AdminSecurityContextHolder.getContext().getRoleIds()); return success(resources.stream().map(ResourceBO::getHandler).collect(Collectors.toSet())); } @@ -87,15 +87,16 @@ public class AdminController { @GetMapping("/page") @ApiOperation(value = "管理员分页") - @ApiImplicitParams({ - @ApiImplicitParam(name = "nickname", value = "昵称,模糊匹配", example = "小王"), - @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), - }) - public CommonResult page(AdminPageDTO adminPageDTO) { -// CommonResult result = adminService.getAdminPage(new AdminPageDTO().setNickname(nickname).setPageNo(pageNo).setPageSize(pageSize)); - CommonResult result = adminService.getAdminPage(adminPageDTO); - return AdminConvert.INSTANCE.convert(result); + public CommonResult> page(AdminPageDTO adminPageDTO) { + PageResult page = adminService.getAdminPage(adminPageDTO); + PageResult resultPage = AdminConvert.INSTANCE.convertAdminVOPage(page); + // 拼接结果 + 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())))); + } + return success(resultPage); } @PostMapping("/add") @@ -106,46 +107,30 @@ public class AdminController { @PostMapping("/update") @ApiOperation(value = "更新管理员") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1"), - @ApiImplicitParam(name = "username", value = "账号", required = true, example = "15601691300"), - @ApiImplicitParam(name = "nickname", value = "昵称", required = true, example = "小王"), - @ApiImplicitParam(name = "password", value = "密码", example = "buzhidao"), - }) - public CommonResult update(@RequestParam("id") Integer id, - @RequestParam("username") String username, - @RequestParam("nickname") String nickname, - @RequestParam(value = "password", required = false) String password) { - AdminUpdateDTO adminUpdateDTO = new AdminUpdateDTO().setId(id).setUsername(username).setNickname(nickname).setPassword(password); - return adminService.updateAdmin(AdminSecurityContextHolder.getContext().getAdminId(), adminUpdateDTO); + public CommonResult update(AdminUpdateDTO adminUpdateDTO) { + return success(adminService.updateAdmin(AdminSecurityContextHolder.getContext().getAdminId(), adminUpdateDTO)); } @PostMapping("/update_status") @ApiOperation(value = "更新管理员状态") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1"), - @ApiImplicitParam(name = "status", value = "状态。1 - 开启;2 - 禁用", required = true, example = "1"), - }) - public CommonResult updateStatus(@RequestParam("id") Integer id, - @RequestParam("status") Integer status) { - return adminService.updateAdminStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status); + 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 adminService.deleteAdmin(AdminSecurityContextHolder.getContext().getAdminId(), 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) { - // 获得管理员拥有的角色集合 - Set adminRoleIdSet = roleService.getRoleList(id).getData(); // 获得所有角色数组 - List allRoleList = roleService.getRoleList().getData(); + List allRoleList = adminService.getRoleList(id); + Set adminRoleIdSet = CollectionUtil.convertSet(allRoleList, RoleBO::getId); // 转换出返回结果 List result = AdminConvert.INSTANCE.convert(allRoleList); // 设置每个角色是否赋予给改管理员 @@ -155,13 +140,8 @@ public class AdminController { @PostMapping("/assign_role") @ApiOperation(value = "分配给管理员角色") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1"), - @ApiImplicitParam(name = "roleIds", value = "角色编号集合", required = true, example = "1,2,3"), - }) - public CommonResult assignRole(@RequestParam("id") Integer id, - @RequestParam("roleIds")Set roleIds) { - return adminService.assignRole(AdminSecurityContextHolder.getContext().getAdminId(), id, roleIds); + public CommonResult assignRole(AdminAssignRoleDTO adminAssignRoleDTO) { + return success(adminService.assignAdminRole(AdminSecurityContextHolder.getContext().getAdminId(), adminAssignRoleDTO)); } } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java index 5bf48c041..95103301f 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java @@ -2,12 +2,12 @@ package cn.iocoder.mall.admin.application.controller.admins; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.DataDictService; -import cn.iocoder.mall.admin.api.bo.DataDictBO; -import cn.iocoder.mall.admin.api.dto.DataDictAddDTO; -import cn.iocoder.mall.admin.api.dto.DataDictUpdateDTO; +import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; +import cn.iocoder.mall.admin.api.dto.datadict.DataDictAddDTO; +import cn.iocoder.mall.admin.api.dto.datadict.DataDictUpdateDTO; import cn.iocoder.mall.admin.application.convert.DataDictConvert; -import cn.iocoder.mall.admin.application.vo.DataDictEnumVO; -import cn.iocoder.mall.admin.application.vo.DataDictVO; +import cn.iocoder.mall.admin.application.vo.datadict.DataDictEnumVO; +import cn.iocoder.mall.admin.application.vo.datadict.DataDictVO; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.Multimaps; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java index 5c20907fa..ed3b3ce33 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java @@ -2,7 +2,7 @@ package cn.iocoder.mall.admin.application.controller.admins; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.OAuth2Service; -import cn.iocoder.mall.admin.api.bo.OAuth2AccessTokenBO; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AccessTokenBO; import cn.iocoder.mall.admin.application.convert.PassportConvert; import cn.iocoder.mall.admin.application.vo.PassportLoginVO; import io.swagger.annotations.Api; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/ResourceController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/ResourceController.java index 5ccc3b010..71a31013a 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/ResourceController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/ResourceController.java @@ -2,17 +2,15 @@ package cn.iocoder.mall.admin.application.controller.admins; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.ResourceService; -import cn.iocoder.mall.admin.api.bo.ResourceBO; +import cn.iocoder.mall.admin.api.bo.resource.ResourceBO; import cn.iocoder.mall.admin.api.constant.ResourceConstants; -import cn.iocoder.mall.admin.api.dto.ResourceAddDTO; -import cn.iocoder.mall.admin.api.dto.ResourceUpdateDTO; +import cn.iocoder.mall.admin.api.dto.resource.ResourceAddDTO; +import cn.iocoder.mall.admin.api.dto.resource.ResourceUpdateDTO; import cn.iocoder.mall.admin.application.convert.ResourceConvert; -import cn.iocoder.mall.admin.application.vo.ResourceTreeNodeVO; -import cn.iocoder.mall.admin.application.vo.ResourceVO; +import cn.iocoder.mall.admin.application.vo.resource.ResourceTreeNodeVO; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.dubbo.config.annotation.Reference; import org.springframework.web.bind.annotation.*; @@ -23,6 +21,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static cn.iocoder.common.framework.vo.CommonResult.success; + @RestController @RequestMapping("admins/resource") @Api("资源模块") @@ -55,55 +55,26 @@ public class ResourceController { .filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT)) .sorted(Comparator.comparing(ResourceTreeNodeVO::getSort)) .collect(Collectors.toList()); - return CommonResult.success(rootNodes); + return success(rootNodes); } @PostMapping("/add") @ApiOperation(value = "创建资源", notes = "例如说,菜单资源,Url 资源") - @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "资源名字(标识)", required = true, example = "admin/info"), - @ApiImplicitParam(name = "type", value = "资源类型。1 代表【菜单】;2 代表【Url】", required = true, example = "1"), - @ApiImplicitParam(name = "sort", value = "排序", required = true, example = "1"), - @ApiImplicitParam(name = "displayName", value = "菜单展示名", required = true, example = "商品管理"), - @ApiImplicitParam(name = "pid", value = "父级资源编号", required = true, example = "1"), - @ApiImplicitParam(name = "handler", value = "操作", example = "/order/list"), - }) - public CommonResult add(@RequestParam("name") String name, - @RequestParam("type") Integer type, - @RequestParam("sort") Integer sort, - @RequestParam("displayName") String displayName, - @RequestParam("pid") Integer pid, - @RequestParam(value = "handler", required = false) String handler) { - ResourceAddDTO resourceAddDTO = new ResourceAddDTO().setName(name).setType(type).setSort(sort) - .setDisplayName(displayName).setPid(pid).setHandler(handler); - return ResourceConvert.INSTANCE.convert3(resourceService.addResource(AdminSecurityContextHolder.getContext().getAdminId(), resourceAddDTO)); + public CommonResult add(ResourceAddDTO resourceAddDTO) { + return success(resourceService.addResource(AdminSecurityContextHolder.getContext().getAdminId(), resourceAddDTO)); } @PostMapping("/update") @ApiOperation(value = "更新资源") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "资源编号", required = true, example = "1"), - @ApiImplicitParam(name = "name", value = "资源名字(标识)", required = true, example = "admin/info"), - @ApiImplicitParam(name = "sort", value = "排序", required = true, example = "1"), - @ApiImplicitParam(name = "displayName", value = "菜单展示名", required = true, example = "商品管理"), - @ApiImplicitParam(name = "pid", value = "父级资源编号", required = true, example = "1"), - @ApiImplicitParam(name = "handler", value = "操作", example = "/order/list"), - }) - public CommonResult update(@RequestParam("id") Integer id, - @RequestParam("name") String name, - @RequestParam("sort") Integer sort, - @RequestParam("displayName") String displayName, - @RequestParam("pid") Integer pid, - @RequestParam(value = "handler", required = false) String handler) { - ResourceUpdateDTO resourceUpdateDTO = new ResourceUpdateDTO().setId(id).setName(name).setSort(sort).setDisplayName(displayName).setPid(pid).setHandler(handler); - return resourceService.updateResource(AdminSecurityContextHolder.getContext().getAdminId(), resourceUpdateDTO); + public CommonResult update(ResourceUpdateDTO resourceUpdateDTO) { + return success(resourceService.updateResource(AdminSecurityContextHolder.getContext().getAdminId(), resourceUpdateDTO)); } @PostMapping("/delete") @ApiOperation(value = "删除资源") @ApiImplicitParam(name = "id", value = "资源编号", required = true, example = "1") public CommonResult delete(@RequestParam("id") Integer id) { - return resourceService.deleteResource(AdminSecurityContextHolder.getContext().getAdminId(), id); + return success(resourceService.deleteResource(AdminSecurityContextHolder.getContext().getAdminId(), id)); } } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java index 34e9e22b2..3846fe8d1 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java @@ -2,20 +2,20 @@ package cn.iocoder.mall.admin.application.controller.admins; import cn.iocoder.common.framework.util.CollectionUtil; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.admin.api.ResourceService; import cn.iocoder.mall.admin.api.RoleService; -import cn.iocoder.mall.admin.api.bo.ResourceBO; -import cn.iocoder.mall.admin.api.bo.RolePageBO; +import cn.iocoder.mall.admin.api.bo.resource.ResourceBO; +import cn.iocoder.mall.admin.api.bo.role.RoleBO; import cn.iocoder.mall.admin.api.constant.ResourceConstants; -import cn.iocoder.mall.admin.api.dto.RoleAddDTO; -import cn.iocoder.mall.admin.api.dto.RolePageDTO; -import cn.iocoder.mall.admin.api.dto.RoleUpdateDTO; +import cn.iocoder.mall.admin.api.dto.role.RoleAddDTO; +import cn.iocoder.mall.admin.api.dto.role.RoleAssignResourceDTO; +import cn.iocoder.mall.admin.api.dto.role.RolePageDTO; +import cn.iocoder.mall.admin.api.dto.role.RoleUpdateDTO; import cn.iocoder.mall.admin.application.convert.ResourceConvert; -import cn.iocoder.mall.admin.application.convert.RoleConvert; -import cn.iocoder.mall.admin.application.vo.RolePageVO; -import cn.iocoder.mall.admin.application.vo.RoleResourceTreeNodeVO; -import cn.iocoder.mall.admin.application.vo.RoleVO; +import cn.iocoder.mall.admin.application.vo.role.RoleResourceTreeNodeVO; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; @@ -25,56 +25,42 @@ import org.springframework.web.bind.annotation.*; import java.util.*; import java.util.stream.Collectors; +import static cn.iocoder.common.framework.vo.CommonResult.success; + @RestController @RequestMapping("admins/role") +@Api("角色模块") public class RoleController { @Reference(validation = "true", version = "${dubbo.provider.RoleService.version}") private RoleService roleService; + @Reference(validation = "true", version = "${dubbo.provider.ResourceService.version}") private ResourceService resourceService; @GetMapping("/page") @ApiOperation(value = "角色分页") - @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "角色名,模糊匹配", required = true, example = "系统管理员"), - @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), - }) - public CommonResult page(@RequestParam(value = "name", required = false) String name, - @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, - @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { - CommonResult result = roleService.getRolePage(new RolePageDTO().setName(name).setPageNo(pageNo).setPageSize(pageSize)); - return RoleConvert.INSTANCE.convert2(result); + public CommonResult> page(RolePageDTO rolePageDTO) { + return success(roleService.getRolePage(rolePageDTO)); } @PostMapping("/add") @ApiOperation(value = "创建角色") - @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "角色", required = true, example = "系统管理员"), - }) - public CommonResult add(@RequestParam("name") String name) { - RoleAddDTO roleAddDTO = new RoleAddDTO().setName(name); - return RoleConvert.INSTANCE.convert(roleService.addRole(AdminSecurityContextHolder.getContext().getAdminId(), roleAddDTO)); + public CommonResult add(RoleAddDTO roleAddDTO) { + return success(roleService.addRole(AdminSecurityContextHolder.getContext().getAdminId(), roleAddDTO)); } @PostMapping("/update") @ApiOperation(value = "更新角色") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1"), - @ApiImplicitParam(name = "name", value = "角色名", required = true, example = "系统管理员"), - }) - public CommonResult update(@RequestParam("id") Integer id, - @RequestParam("name") String name) { - RoleUpdateDTO roleUpdateDTO = new RoleUpdateDTO().setId(id).setName(name); - return roleService.updateRole(AdminSecurityContextHolder.getContext().getAdminId(), roleUpdateDTO); + public CommonResult update(RoleUpdateDTO roleUpdateDTO) { + return success(roleService.updateRole(AdminSecurityContextHolder.getContext().getAdminId(), roleUpdateDTO)); } @PostMapping("/delete") @ApiOperation(value = "删除角色") @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1") public CommonResult delete(@RequestParam("id") Integer id) { - return roleService.deleteRole(AdminSecurityContextHolder.getContext().getAdminId(), id); + return success(roleService.deleteRole(AdminSecurityContextHolder.getContext().getAdminId(), id)); } @SuppressWarnings("Duplicates") @@ -110,7 +96,7 @@ public class RoleController { // 第三步,设置角色是否有该角色 treeNodeMap.values().forEach(nodeVO -> nodeVO.setAssigned(roleResources.contains(nodeVO.getId()))); // 返回结果 - return CommonResult.success(rootNodes); + return success(rootNodes); } @PostMapping("/assign_resource") @@ -119,9 +105,8 @@ public class RoleController { @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1"), @ApiImplicitParam(name = "resourceIds", value = "资源数组", required = true, example = "1,2,3"), }) - public CommonResult assignResource(@RequestParam("id") Integer id, - @RequestParam(value = "resourceIds", required = false) Set resourceIds) { - return roleService.assignResource(AdminSecurityContextHolder.getContext().getAdminId(), id, resourceIds); + public CommonResult assignResource(RoleAssignResourceDTO roleAssignResourceDTO) { + return success(roleService.assignRoleResource(AdminSecurityContextHolder.getContext().getAdminId(), roleAssignResourceDTO)); } } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java index 42b4e57a6..0c3a459fd 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java @@ -1,18 +1,18 @@ package cn.iocoder.mall.admin.application.convert; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.admin.api.bo.role.RoleBO; import cn.iocoder.mall.admin.api.bo.admin.AdminBO; -import cn.iocoder.mall.admin.api.bo.admin.AdminPageBO; -import cn.iocoder.mall.admin.api.bo.RoleBO; -import cn.iocoder.mall.admin.application.vo.AdminInfoVO; -import cn.iocoder.mall.admin.application.vo.AdminPageVO; -import cn.iocoder.mall.admin.application.vo.AdminRoleVO; -import cn.iocoder.mall.admin.application.vo.AdminVO; +import cn.iocoder.mall.admin.application.vo.admin.AdminInfoVO; +import cn.iocoder.mall.admin.application.vo.admin.AdminRoleVO; +import cn.iocoder.mall.admin.application.vo.admin.AdminVO; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContext; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; +import java.util.Collection; import java.util.List; @Mapper @@ -29,10 +29,12 @@ public interface AdminConvert { @Mappings({}) CommonResult convert2(CommonResult result); - @Mappings({}) - CommonResult convert(CommonResult result); - @Mappings({}) List convert(List roleList); + @Mappings({}) + PageResult convertAdminVOPage(PageResult page); + + List convertAdminVORoleList(Collection list); + } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java index 1b18244e6..8d875c4d9 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java @@ -1,9 +1,9 @@ package cn.iocoder.mall.admin.application.convert; import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.DataDictBO; -import cn.iocoder.mall.admin.application.vo.DataDictVO; -import cn.iocoder.mall.admin.application.vo.DataDictValueVO; +import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; +import cn.iocoder.mall.admin.application.vo.datadict.DataDictVO; +import cn.iocoder.mall.admin.application.vo.datadict.DataDictValueVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -30,4 +30,4 @@ public interface DataDictConvert { @Mappings({}) List convert2(List dataDictBOs); -} \ No newline at end of file +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/PassportConvert.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/PassportConvert.java index 35389ac90..ee82785d1 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/PassportConvert.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/PassportConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.admin.application.convert; import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.OAuth2AccessTokenBO; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AccessTokenBO; import cn.iocoder.mall.admin.application.vo.PassportLoginVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; @@ -18,4 +18,4 @@ public interface PassportConvert { @Mappings({}) CommonResult convert(CommonResult oauth2AccessTokenBO); -} \ No newline at end of file +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/ResourceConvert.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/ResourceConvert.java index a3fda7381..223ac6689 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/ResourceConvert.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/ResourceConvert.java @@ -1,11 +1,11 @@ package cn.iocoder.mall.admin.application.convert; import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.ResourceBO; -import cn.iocoder.mall.admin.application.vo.AdminMenuTreeNodeVO; -import cn.iocoder.mall.admin.application.vo.ResourceTreeNodeVO; -import cn.iocoder.mall.admin.application.vo.ResourceVO; -import cn.iocoder.mall.admin.application.vo.RoleResourceTreeNodeVO; +import cn.iocoder.mall.admin.api.bo.resource.ResourceBO; +import cn.iocoder.mall.admin.application.vo.admin.AdminMenuTreeNodeVO; +import cn.iocoder.mall.admin.application.vo.resource.ResourceTreeNodeVO; +import cn.iocoder.mall.admin.application.vo.resource.ResourceVO; +import cn.iocoder.mall.admin.application.vo.role.RoleResourceTreeNodeVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -30,4 +30,4 @@ public interface ResourceConvert { @Mappings({}) CommonResult convert3(CommonResult resourceBO); -} \ No newline at end of file +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/RoleConvert.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/RoleConvert.java index 1d8b47007..eb365885e 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/RoleConvert.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/RoleConvert.java @@ -1,31 +1,11 @@ package cn.iocoder.mall.admin.application.convert; -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.RoleBO; -import cn.iocoder.mall.admin.api.bo.RolePageBO; -import cn.iocoder.mall.admin.application.vo.RolePageVO; -import cn.iocoder.mall.admin.application.vo.RoleVO; import org.mapstruct.Mapper; -import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; -import java.util.List; - @Mapper public interface RoleConvert { RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class); - @Mappings({}) - RoleVO convert(RoleBO roleBO); - - @Mappings({}) - List convert(List roleBO); - - @Mappings({}) - CommonResult convert(CommonResult resourceBO); - - @Mappings({}) - CommonResult convert2(CommonResult resourceBO); - -} \ No newline at end of file +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminPageVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminPageVO.java deleted file mode 100644 index f446bc6fb..000000000 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminPageVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.mall.admin.application.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.List; - -@ApiModel("管理员分页 VO") -@Data -@Accessors(chain = true) -public class AdminPageVO { - - @ApiModelProperty(value = "管理员数组") - private List list; - @ApiModelProperty(value = "管理员总数") - private Integer total; - -} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java deleted file mode 100644 index 4090bbfe9..000000000 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.admin.application.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -@ApiModel("管理员 VO") -@Data -@Accessors(chain = true) -public class AdminVO { - - @ApiModelProperty(value = "管理员编号", required = true, example = "1") - private Integer id; - - @ApiModelProperty(value = "登陆账号", required = true, example = "15601691300") - private String username; - - @ApiModelProperty(value = "昵称", required = true, example = "小王") - private String nickname; - - @ApiModelProperty(value = "账号状态", required = true, example = "1") - private Integer status; - - @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") - private Date createTime; - -} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RolePageVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RolePageVO.java deleted file mode 100644 index c1f574496..000000000 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RolePageVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.mall.admin.application.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.List; - -@ApiModel("角色分页 VO") -@Data -@Accessors(chain = true) -public class RolePageVO { - - @ApiModelProperty(value = "角色数组") - private List roles; - @ApiModelProperty(value = "角色总数") - private Integer count; - -} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RoleVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RoleVO.java deleted file mode 100644 index 517dd80d4..000000000 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RoleVO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.mall.admin.application.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -@ApiModel("角色 VO") -@Data -@Accessors(chain = true) -public class RoleVO { - - @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; - -} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminInfoVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminInfoVO.java similarity index 75% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminInfoVO.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminInfoVO.java index 676ea0c55..931d34c68 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminInfoVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminInfoVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.vo; +package cn.iocoder.mall.admin.application.vo.admin; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -12,7 +12,7 @@ import java.util.Set; @Accessors(chain = true) public class AdminInfoVO { - @ApiModelProperty(value = "管理员比那好", required = true, example = "1") + @ApiModelProperty(value = "管理员编号", required = true, example = "1") private Integer adminId; @ApiModelProperty(value = "角色编号的数组", required = true, example = "[1, 2]") private Set roleIds; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminMenuTreeNodeVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminMenuTreeNodeVO.java similarity index 95% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminMenuTreeNodeVO.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminMenuTreeNodeVO.java index 277777fa0..e88174be2 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminMenuTreeNodeVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminMenuTreeNodeVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.vo; +package cn.iocoder.mall.admin.application.vo.admin; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminRoleVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminRoleVO.java similarity index 91% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminRoleVO.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminRoleVO.java index 4e4b1ae3a..417d86b91 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminRoleVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminRoleVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.vo; +package cn.iocoder.mall.admin.application.vo.admin; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminVO.java new file mode 100644 index 000000000..086e4266e --- /dev/null +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.mall.admin.application.vo.admin; + +import cn.iocoder.mall.admin.api.bo.admin.AdminBO; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.List; + +@ApiModel("管理员 VO") +@Data +@Accessors(chain = true) +public class AdminVO extends AdminBO { + + private List roles; + + @ApiModel("管理员 VO - 角色") + @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; + + } + +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictEnumVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java similarity index 90% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictEnumVO.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java index 1ac524c91..d9814747b 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictEnumVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.vo; +package cn.iocoder.mall.admin.application.vo.datadict; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java similarity index 93% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictVO.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java index 9ebdbb854..1524ce4c6 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.vo; +package cn.iocoder.mall.admin.application.vo.datadict; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictValueVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java similarity index 89% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictValueVO.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java index 917ad493f..7ed6eeff4 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictValueVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.vo; +package cn.iocoder.mall.admin.application.vo.datadict; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/oauth2/SystemApplication.java similarity index 93% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/oauth2/SystemApplication.java index d4b1b995f..01adad7c4 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/oauth2/SystemApplication.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application; +package cn.iocoder.mall.admin.application.vo.oauth2; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/ResourceTreeNodeVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/resource/ResourceTreeNodeVO.java similarity index 96% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/ResourceTreeNodeVO.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/resource/ResourceTreeNodeVO.java index bba3696ae..3feda78ed 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/ResourceTreeNodeVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/resource/ResourceTreeNodeVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.vo; +package cn.iocoder.mall.admin.application.vo.resource; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/ResourceVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/resource/ResourceVO.java similarity index 95% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/ResourceVO.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/resource/ResourceVO.java index e16cb4208..d7078d7e1 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/ResourceVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/resource/ResourceVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.vo; +package cn.iocoder.mall.admin.application.vo.resource; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RoleResourceTreeNodeVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/role/RoleResourceTreeNodeVO.java similarity index 95% rename from system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RoleResourceTreeNodeVO.java rename to system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/role/RoleResourceTreeNodeVO.java index fed45cac6..1994c7826 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/RoleResourceTreeNodeVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/role/RoleResourceTreeNodeVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.vo; +package cn.iocoder.mall.admin.application.vo.role; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/system/system-sdk/src/main/java/cn/iocoder/mall/admin/sdk/interceptor/AdminSecurityInterceptor.java b/system/system-sdk/src/main/java/cn/iocoder/mall/admin/sdk/interceptor/AdminSecurityInterceptor.java index 3578f878b..d04cd7419 100644 --- a/system/system-sdk/src/main/java/cn/iocoder/mall/admin/sdk/interceptor/AdminSecurityInterceptor.java +++ b/system/system-sdk/src/main/java/cn/iocoder/mall/admin/sdk/interceptor/AdminSecurityInterceptor.java @@ -6,7 +6,7 @@ import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.MallUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.OAuth2Service; -import cn.iocoder.mall.admin.api.bo.OAuth2AuthenticationBO; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AuthenticationBO; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContext; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; diff --git a/system/system-service-api/pom.xml b/system/system-service-api/pom.xml index 644cc079e..3b77e0d06 100644 --- a/system/system-service-api/pom.xml +++ b/system/system-service-api/pom.xml @@ -21,8 +21,8 @@ - io.springfox - springfox-swagger2 + io.swagger + swagger-annotations diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java index cce2eebc7..9337ecd11 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java @@ -1,32 +1,52 @@ package cn.iocoder.mall.admin.api; -import cn.iocoder.common.framework.constant.CommonStatusEnum; -import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.admin.api.bo.role.RoleBO; import cn.iocoder.mall.admin.api.bo.admin.AdminBO; -import cn.iocoder.mall.admin.api.bo.admin.AdminPageBO; -import cn.iocoder.mall.admin.api.dto.admin.AdminAddDTO; -import cn.iocoder.mall.admin.api.dto.admin.AdminPageDTO; -import cn.iocoder.mall.admin.api.dto.admin.AdminUpdateDTO; +import cn.iocoder.mall.admin.api.dto.admin.*; -import java.util.Set; +import java.util.Collection; +import java.util.List; +import java.util.Map; /** * 管理员 Service 接口 */ public interface AdminService { - CommonResult getAdminPage(AdminPageDTO adminPageDTO); + PageResult getAdminPage(AdminPageDTO adminPageDTO); AdminBO addAdmin(Integer adminId, AdminAddDTO adminAddDTO); - CommonResult updateAdmin(Integer adminId, AdminUpdateDTO adminUpdateDTO); + Boolean updateAdmin(Integer adminId, AdminUpdateDTO adminUpdateDTO); - CommonResult updateAdminStatus(Integer adminId, Integer updateAdminId, - @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status); + Boolean updateAdminStatus(Integer adminId, AdminUpdateStatusDTO adminUpdateStatusDTO); - CommonResult deleteAdmin(Integer adminId, Integer updateAdminId); + Boolean deleteAdmin(Integer adminId, Integer updateAdminId); - CommonResult assignRole(Integer adminId, Integer updateAdminId, Set roleIds); + /** + * 批量查询每个管理员拥有的角色 + * + * @param adminIds 管理员编号数组 + * @return 每个管理员拥有的角色 + */ + Map> getAdminRolesMap(Collection adminIds); + + /** + * 获得指定管理员拥有的角色数组 + * + * @param adminId 指定管理员 + * @return 角色编号数组 + */ + List getRoleList(Integer adminId); + + /** + * 分配管理员角色 + * + * @param adminId 操作管理员编号 + * @param adminAssignRoleDTO 分配信息 + * @return 是否成功。目前,默认返回 true + */ + Boolean assignAdminRole(Integer adminId, AdminAssignRoleDTO adminAssignRoleDTO); } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java index 601c3cb18..7d92b8bee 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java @@ -1,9 +1,9 @@ package cn.iocoder.mall.admin.api; import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.DataDictBO; -import cn.iocoder.mall.admin.api.dto.DataDictAddDTO; -import cn.iocoder.mall.admin.api.dto.DataDictUpdateDTO; +import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; +import cn.iocoder.mall.admin.api.dto.datadict.DataDictAddDTO; +import cn.iocoder.mall.admin.api.dto.datadict.DataDictUpdateDTO; import java.util.Collection; import java.util.List; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java index cdf9a7531..1041a3ba9 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java @@ -1,8 +1,8 @@ package cn.iocoder.mall.admin.api; import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.OAuth2AccessTokenBO; -import cn.iocoder.mall.admin.api.bo.OAuth2AuthenticationBO; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AccessTokenBO; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AuthenticationBO; import java.util.Set; @@ -30,4 +30,4 @@ public interface OAuth2Service { // TODO @see 刷新 token -} \ No newline at end of file +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/ResourceService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/ResourceService.java index 7edacb804..0af97d266 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/ResourceService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/ResourceService.java @@ -1,9 +1,8 @@ package cn.iocoder.mall.admin.api; -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.ResourceBO; -import cn.iocoder.mall.admin.api.dto.ResourceAddDTO; -import cn.iocoder.mall.admin.api.dto.ResourceUpdateDTO; +import cn.iocoder.mall.admin.api.bo.resource.ResourceBO; +import cn.iocoder.mall.admin.api.dto.resource.ResourceAddDTO; +import cn.iocoder.mall.admin.api.dto.resource.ResourceUpdateDTO; import org.springframework.lang.Nullable; import java.util.List; @@ -28,10 +27,10 @@ public interface ResourceService { */ List getResourcesByType(@Nullable Integer type); - CommonResult addResource(Integer adminId, ResourceAddDTO resourceAddDTO); + ResourceBO addResource(Integer adminId, ResourceAddDTO resourceAddDTO); - CommonResult updateResource(Integer adminId, ResourceUpdateDTO resourceUpdateDTO); + Boolean updateResource(Integer adminId, ResourceUpdateDTO resourceUpdateDTO); - CommonResult deleteResource(Integer adminId, Integer resourceId); + Boolean deleteResource(Integer adminId, Integer resourceId); -} \ No newline at end of file +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/RoleService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/RoleService.java index bb8c92f06..22358ad53 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/RoleService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/RoleService.java @@ -1,38 +1,32 @@ package cn.iocoder.mall.admin.api; -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.RoleBO; -import cn.iocoder.mall.admin.api.bo.RolePageBO; -import cn.iocoder.mall.admin.api.dto.RoleAddDTO; -import cn.iocoder.mall.admin.api.dto.RolePageDTO; -import cn.iocoder.mall.admin.api.dto.RoleUpdateDTO; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.admin.api.bo.role.RoleBO; +import cn.iocoder.mall.admin.api.dto.role.RoleAddDTO; +import cn.iocoder.mall.admin.api.dto.role.RoleAssignResourceDTO; +import cn.iocoder.mall.admin.api.dto.role.RolePageDTO; +import cn.iocoder.mall.admin.api.dto.role.RoleUpdateDTO; +import java.util.Collection; import java.util.List; -import java.util.Set; public interface RoleService { - CommonResult getRolePage(RolePageDTO rolePageDTO); - - /** - * 获得指定管理员拥有的角色编号数组 - * - * @param adminId 指定管理员 - * @return 角色编号数组 - */ - CommonResult> getRoleList(Integer adminId); + PageResult getRolePage(RolePageDTO rolePageDTO); /** * @return 返回角色列表 */ - CommonResult> getRoleList(); + List getRoleList(); - CommonResult addRole(Integer adminId, RoleAddDTO roleAddDTO); + List getRoleList(Collection ids); - CommonResult updateRole(Integer adminId, RoleUpdateDTO roleUpdateDTO); + RoleBO addRole(Integer adminId, RoleAddDTO roleAddDTO); - CommonResult deleteRole(Integer adminId, Integer roleId); + Boolean updateRole(Integer adminId, RoleUpdateDTO roleUpdateDTO); - CommonResult assignResource(Integer adminId, Integer roleId, Set resourceIds); + Boolean deleteRole(Integer adminId, Integer roleId); -} \ No newline at end of file + Boolean assignRoleResource(Integer adminId, RoleAssignResourceDTO roleAssignResourceDTO); + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SystemLogService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SystemLogService.java index 044a5edcb..f39fbfc4f 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SystemLogService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SystemLogService.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.admin.api; -import cn.iocoder.mall.admin.api.dto.AccessLogAddDTO; -import cn.iocoder.mall.admin.api.dto.ExceptionLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.ExceptionLogAddDTO; /** * 系统日志 Service 接口 diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/ResourceBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/ResourceBO.java deleted file mode 100644 index 8cbebc291..000000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/ResourceBO.java +++ /dev/null @@ -1,49 +0,0 @@ -package cn.iocoder.mall.admin.api.bo; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; - -/** - * 资源 BO - */ -@Data -@Accessors(chain = true) -public class ResourceBO implements Serializable { - - /** - * 资源编号 - */ - private Integer id; - /** - * 资源名字(标识) - */ - private String name; - /** - * 资源类型 - */ - private Integer type; - /** - * 排序 - */ - private Integer sort; - /** - * 展示名 - */ - private String displayName; - /** - * 添加时间 - */ - private Date createTime; - /** - * 父级资源编号 - */ - private Integer pid; - /** - * 操作 - */ - private String handler; - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/RolePageBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/RolePageBO.java deleted file mode 100644 index d6eecf4c4..000000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/RolePageBO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.mall.admin.api.bo; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.List; - -/** - * 角色分页 BO - */ -@Data -@Accessors(chain = true) -public class RolePageBO implements Serializable { - - /** - * 角色数组 - */ - private List roles; - /** - * 总量 - */ - private Integer count; - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java index 65673e18f..88dbb3428 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java @@ -22,7 +22,7 @@ public class AdminBO implements Serializable { @ApiModelProperty(value = "昵称", required = true, example = "小王") private String nickname; - @ApiModelProperty(value = "账号状态", required = true, example = "1", dataType= "CommonStatusEnum") + @ApiModelProperty(value = "账号状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举") private Integer status; @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/DataDictBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/datadict/DataDictBO.java similarity index 93% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/DataDictBO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/datadict/DataDictBO.java index 479388802..03eafa2c8 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/DataDictBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/datadict/DataDictBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.bo; +package cn.iocoder.mall.admin.api.bo.datadict; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/OAuth2AccessTokenBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AccessTokenBO.java similarity index 90% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/OAuth2AccessTokenBO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AccessTokenBO.java index 59c70e5f0..25a5f466b 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/OAuth2AccessTokenBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AccessTokenBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.bo; +package cn.iocoder.mall.admin.api.bo.oauth2; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/OAuth2AuthenticationBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AuthenticationBO.java similarity index 89% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/OAuth2AuthenticationBO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AuthenticationBO.java index fc3769474..68e5ff9ea 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/OAuth2AuthenticationBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AuthenticationBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.bo; +package cn.iocoder.mall.admin.api.bo.oauth2; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/resource/ResourceBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/resource/ResourceBO.java new file mode 100644 index 000000000..d8be6097a --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/resource/ResourceBO.java @@ -0,0 +1,40 @@ +package cn.iocoder.mall.admin.api.bo.resource; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +@ApiModel("资源 BO") +@Data +@Accessors(chain = true) +public class ResourceBO implements Serializable { + + @ApiModelProperty(value = "资源编号", required = true, example = "1") + private Integer id; + + @ApiModelProperty(value = "资源类型", required = true, example = "1") + private Integer type; + + @ApiModelProperty(value = "排序", required = true, example = "1") + private Integer sort; + + @ApiModelProperty(value = "菜单展示名", required = true, example = "商品管理") + private String displayName; + + @ApiModelProperty(value = "父级资源编号", required = true, example = "1", notes = "如果无父资源,则值为 0") + private Integer pid; + + @ApiModelProperty(value = "操作", required = true, example = "/order/list") + private String handler; + + @ApiModelProperty(value = "图标", example = "add") + private String icon; + + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") + private Date createTime; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/RoleBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/role/RoleBO.java similarity index 90% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/RoleBO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/role/RoleBO.java index c80d62475..6ade9ca96 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/RoleBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/role/RoleBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.bo; +package cn.iocoder.mall.admin.api.bo.role; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java index eb1a05736..61f4dfd1d 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java @@ -28,6 +28,7 @@ public enum AdminErrorCodeEnum { ADMIN_STATUS_EQUALS(1002002003, "账号已经是该状态"), ADMIN_DELETE_ONLY_DISABLE(1002002004, "只有关闭的账号才可以删除"), ADMIN_ADMIN_STATUS_CAN_NOT_UPDATE(1002002005, "管理员的账号状态不允许变更"), + ADMIN_ASSIGN_ROLE_NOT_EXISTS(1002002006, "分配员工角色时,有角色不存在"), // ========== 资源模块 1002003000 ========== RESOURCE_NAME_DUPLICATE(1002003000, "已经存在该名字的资源"), @@ -35,6 +36,7 @@ public enum AdminErrorCodeEnum { RESOURCE_PARENT_ERROR(1002003002, "不能设置自己为父资源"), RESOURCE_NOT_EXISTS(1002003003, "资源不存在"), RESOURCE_EXISTS_CHILDREN(1002003004, "存在子资源,无法删除"), + RESOURCE_PARENT_NOT_MENU(1002003005, "父资源的类型必须是菜单"), // ========== 角色模块 1002004000 ========== ROLE_NOT_EXISTS(1002004000, "角色不存在"), @@ -62,4 +64,4 @@ public enum AdminErrorCodeEnum { return message; } -} \ No newline at end of file +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/ResourceConstants.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/ResourceConstants.java index 863192b59..ee31f1898 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/ResourceConstants.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/ResourceConstants.java @@ -10,13 +10,13 @@ public interface ResourceConstants { */ Integer TYPE_MENU = 1; /** - * 类型 - URL + * 类型 - 按钮 */ - Integer TYPE_URL = 2; + Integer TYPE_BUTTON = 2; /** * 父资源编号 - 根节点 */ Integer PID_ROOT = 0; -} \ No newline at end of file +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ResourceAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ResourceAddDTO.java deleted file mode 100644 index 4892adad9..000000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ResourceAddDTO.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.mall.admin.api.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * 资源添加 DTO - */ -@Data -@Accessors(chain = true) -public class ResourceAddDTO implements Serializable { - - /** - * 资源名字(标识) - */ - @NotEmpty(message = "资源名字不能为空") - private String name; - /** - * 类型 - */ - @NotNull(message = "类型不能为空") - private Integer type; - /** - * 排序值 - */ - @NotNull(message = "类型不能为空") - private Integer sort; - /** - * 展示名 - */ - @NotEmpty(message = "资源名字不能为空") - private String displayName; - /** - * 父资源编号 - */ - private Integer pid; - /** - * 操作 - */ - private String handler; - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ResourceUpdateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ResourceUpdateDTO.java deleted file mode 100644 index ee915e59f..000000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ResourceUpdateDTO.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.mall.admin.api.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * 资源更新 DTO - */ -@Data -@Accessors(chain = true) -public class ResourceUpdateDTO implements Serializable { - - /** - * 资源编号 - */ - @NotNull(message = "资源编号不能为空") - private Integer id; - /** - * 资源名字(标识) - */ - @NotEmpty(message = "资源名字不能为空") - private String name; - /** - * 排序值 - */ - @NotNull(message = "类型不能为空") - private Integer sort; - /** - * 展示名 - */ - @NotEmpty(message = "资源名字不能为空") - private String displayName; - /** - * 父资源编号 - */ - private Integer pid; - /** - * 操作 - */ - private String handler; - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RolePageDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RolePageDTO.java deleted file mode 100644 index 3f7ee4c80..000000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RolePageDTO.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.iocoder.mall.admin.api.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** - * 角色分页 DTO - */ -@Data -@Accessors(chain = true) -public class RolePageDTO implements Serializable { - - private Integer pageNo; - private Integer pageSize; - private String name; - - public Integer getPageNo() { - return pageNo; - } - - public RolePageDTO setPageNo(Integer pageNo) { - this.pageNo = pageNo; - return this; - } - - public Integer getPageSize() { - return pageSize; - } - - public RolePageDTO setPageSize(Integer pageSize) { - this.pageSize = pageSize; - return this; - } - - public String getName() { - return name; - } - - public RolePageDTO setName(String name) { - this.name = name; - return this; - } -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAssignRoleDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAssignRoleDTO.java new file mode 100644 index 000000000..ad42d01b1 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAssignRoleDTO.java @@ -0,0 +1,23 @@ +package cn.iocoder.mall.admin.api.dto.admin; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.util.Set; + +@ApiModel("管理员分配角色 DTO") +@Data +@Accessors(chain = true) +public class AdminAssignRoleDTO { + + @ApiModelProperty(value = "管理员编号", required = true, example = "1") + @NotNull(message = "管理员编号不能为空") + private Integer id; + + @ApiModelProperty(value = "角色编号数组", example = "1") + private Set roleIds; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java index 953ec6edb..923890f56 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java @@ -1,26 +1,20 @@ package cn.iocoder.mall.admin.api.dto.admin; +import cn.iocoder.common.framework.vo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * 管理员分页 DTO - */ +@ApiModel(value = "管理员分页 DTO") @Data @Accessors(chain = true) -public class AdminPageDTO implements Serializable { +public class AdminPageDTO extends PageParam { /** * 昵称,模糊匹配 */ + @ApiModelProperty(value = "昵称,模糊匹配", example = "小王") private String nickname; - @NotNull(message = "页码不能为空") - private Integer pageNo; - @NotNull(message = "每页条数不能为空") - private Integer pageSize; - } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java index 13c6ccecc..fd8d1f25d 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.admin.api.dto.admin; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; @@ -11,40 +11,27 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import java.io.Serializable; -/** - * 管理员更新 DTO - */ +@ApiModel("管理员更新 DTO") @Data @Accessors(chain = true) -@ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1"), - @ApiImplicitParam(name = "username", value = "账号", required = true, example = "15601691300"), - @ApiImplicitParam(name = "nickname", value = "昵称", required = true, example = "小王"), - @ApiImplicitParam(name = "password", value = "密码", example = "buzhidao"), -}) public class AdminUpdateDTO implements Serializable { - /** - * 管理员编号 - */ + @ApiModelProperty(value = "管理员编号", required = true, example = "1") @NotNull(message = "管理员编号不能为空") private Integer id; - /** - * 登陆账号 - */ + + @ApiModelProperty(value = "登陆账号", required = true, example = "15601691300") @NotEmpty(message = "登陆账号不能为空") @Length(min = 6, max = 16, message = "账号长度为 6-16 位") @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母") private String username; - /** - * 昵称 - */ + + @ApiModelProperty(value = "昵称", required = true, example = "小王") @NotEmpty(message = "昵称不能为空") @Length(max = 10, message = "昵称长度最大为 10 位") private String nickname; - /** - * 密码 - */ + + @ApiModelProperty(value = "密码", example = "buzhidao") @Length(min = 6, max = 16, message = "密码长度为 6-16 位") private String password; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateStatusDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateStatusDTO.java new file mode 100644 index 000000000..4155ae8dd --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateStatusDTO.java @@ -0,0 +1,26 @@ +package cn.iocoder.mall.admin.api.dto.admin; + +import cn.iocoder.common.framework.constant.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; + +@ApiModel("管理员更新状态 DTO") +@Data +@Accessors(chain = true) +public class AdminUpdateStatusDTO { + + @ApiModelProperty(value = "管理员编号", required = true, example = "1") + @NotNull(message = "管理员编号不能为空") + private Integer id; + + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举") + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java similarity index 94% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictAddDTO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java index ca451df94..574a66ae5 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictAddDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.dto; +package cn.iocoder.mall.admin.api.dto.datadict; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictUpdateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java similarity index 94% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictUpdateDTO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java index 582f958ce..9653beb2b 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictUpdateDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.dto; +package cn.iocoder.mall.admin.api.dto.datadict; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/resource/ResourceAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/resource/ResourceAddDTO.java new file mode 100644 index 000000000..f52b08514 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/resource/ResourceAddDTO.java @@ -0,0 +1,43 @@ +package cn.iocoder.mall.admin.api.dto.resource; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +@ApiModel("资源添加 DTO") +@Data +@Accessors(chain = true) +public class ResourceAddDTO implements Serializable { + + @ApiModelProperty(value = "资源类型。1 代表【菜单】;2 代表【按钮】", required = true, example = "1") + @NotNull(message = "类型不能为空") + private Integer type; + + @ApiModelProperty(value = "排序", required = true, example = "1") + @NotNull(message = "类型不能为空") + private Integer sort; + + @ApiModelProperty(value = "菜单展示名", required = true, example = "商品管理") + @NotEmpty(message = "资源名字不能为空") + private String displayName; + + @ApiModelProperty(value = "父级资源编号", required = true, example = "1") + @NotNull(message = "父级资源编号不能为空") + private Integer pid; + + @ApiModelProperty(value = "操作", example = "/order/list") + private String handler; + + @ApiModelProperty(value = "图标", example = "add") + private String icon; + + @ApiModelProperty(value = "权限标识数组", example = "system.order.add,system.order.update") + private List permissions; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/resource/ResourceUpdateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/resource/ResourceUpdateDTO.java new file mode 100644 index 000000000..2b72f3020 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/resource/ResourceUpdateDTO.java @@ -0,0 +1,47 @@ +package cn.iocoder.mall.admin.api.dto.resource; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +@ApiModel("资源更新 DTO") +@Data +@Accessors(chain = true) +public class ResourceUpdateDTO implements Serializable { + + @ApiModelProperty(value = "资源编号", required = true, example = "1") + @NotNull(message = "资源编号不能为空") + private Integer id; + + @ApiModelProperty(value = "资源类型。1 代表【菜单】;2 代表【按钮】", required = true, example = "1") + @NotNull(message = "类型不能为空") + private Integer type; + + @ApiModelProperty(value = "排序", required = true, example = "1") + @NotNull(message = "类型不能为空") + private Integer sort; + + @ApiModelProperty(value = "菜单展示名", required = true, example = "商品管理") + @NotEmpty(message = "资源名字不能为空") + private String displayName; + + @ApiModelProperty(value = "父级资源编号", required = true, example = "1") + @NotNull(message = "父级资源编号不能为空") + private Integer pid; + + @ApiModelProperty(value = "操作", example = "/order/list") + private String handler; + + @ApiModelProperty(value = "图标", example = "add") + private String icon; + + @ApiModelProperty(value = "权限标识数组", example = "system.order.add,system.order.update") + private List permissions; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RoleAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleAddDTO.java similarity index 51% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RoleAddDTO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleAddDTO.java index 02268f4a2..53591c497 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RoleAddDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleAddDTO.java @@ -1,21 +1,19 @@ -package cn.iocoder.mall.admin.api.dto; +package cn.iocoder.mall.admin.api.dto.role; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; import javax.validation.constraints.NotEmpty; import java.io.Serializable; -/** - * 角色添加 DTO - */ +@ApiModel("角色添加 DTO") @Data @Accessors(chain = true) public class RoleAddDTO implements Serializable { - /** - * 角色名字(标识) - */ + @ApiModelProperty(name = "name", value = "角色名字(标识)", required = true, example = "系统管理员") @NotEmpty(message = "角色名字不能为空") private String name; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleAssignResourceDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleAssignResourceDTO.java new file mode 100644 index 000000000..64b1027fb --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleAssignResourceDTO.java @@ -0,0 +1,23 @@ +package cn.iocoder.mall.admin.api.dto.role; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.util.Set; + +@ApiModel("角色分配资源 DTO") +@Data +@Accessors(chain = true) +public class RoleAssignResourceDTO { + + @ApiModelProperty(value = "角色编号", required = true, example = "1") + @NotNull(message = "角色编号不能为空") + private Integer id; + + @ApiModelProperty(value = "资源编号数组", example = "1,2") + private Set resourceIds; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RolePageDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RolePageDTO.java new file mode 100644 index 000000000..7fe363d70 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RolePageDTO.java @@ -0,0 +1,17 @@ +package cn.iocoder.mall.admin.api.dto.role; + +import cn.iocoder.common.framework.vo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +@ApiModel("角色分页 DTO") +@Data +@Accessors(chain = true) +public class RolePageDTO extends PageParam { + + @ApiModelProperty( value = "角色名,模糊匹配", example = "系统管理员") + private String name; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RoleUpdateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleUpdateDTO.java similarity index 56% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RoleUpdateDTO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleUpdateDTO.java index 66e2d7bb4..fc50fe3e3 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/RoleUpdateDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/role/RoleUpdateDTO.java @@ -1,5 +1,7 @@ -package cn.iocoder.mall.admin.api.dto; +package cn.iocoder.mall.admin.api.dto.role; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; @@ -7,21 +9,16 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.io.Serializable; -/** - * 角色添加 DTO - */ +@ApiModel("角色添加 DTO") @Data @Accessors(chain = true) public class RoleUpdateDTO implements Serializable { - /** - * 角色编号 - */ + @ApiModelProperty(value = "角色编号", required = true, example = "1") @NotNull(message = "角色编号不能为空") private Integer id; - /** - * 角色名字(标识) - */ + + @ApiModelProperty(value = "角色名", required = true, example = "系统管理员") @NotEmpty(message = "角色名字不能为空") private String name; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AccessLogAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/AccessLogAddDTO.java similarity index 96% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AccessLogAddDTO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/AccessLogAddDTO.java index 04c29a80b..289f2056c 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AccessLogAddDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/AccessLogAddDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.dto; +package cn.iocoder.mall.admin.api.dto.systemlog; import lombok.Data; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ExceptionLogAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/ExceptionLogAddDTO.java similarity index 97% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ExceptionLogAddDTO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/ExceptionLogAddDTO.java index 5767238f9..7cdc61b0e 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/ExceptionLogAddDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/systemlog/ExceptionLogAddDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.dto; +package cn.iocoder.mall.admin.api.dto.systemlog; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/config/DatabaseConfiguration.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/config/DatabaseConfiguration.java index fef005762..6a944d0ec 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/config/DatabaseConfiguration.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/config/DatabaseConfiguration.java @@ -2,6 +2,7 @@ package cn.iocoder.mall.admin.config; import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; import com.baomidou.mybatisplus.core.injector.ISqlInjector; +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -19,4 +20,9 @@ public class DatabaseConfiguration { return new DefaultSqlInjector(); // MyBatis Plus 逻辑删除 } + @Bean + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); // MyBatis Plus 分页插件 + } + } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AccessLogConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AccessLogConvert.java index 1ba100c0a..7dcdd4c90 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AccessLogConvert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AccessLogConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.admin.convert; -import cn.iocoder.mall.admin.api.dto.AccessLogAddDTO; -import cn.iocoder.mall.admin.api.dto.ExceptionLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.ExceptionLogAddDTO; import cn.iocoder.mall.admin.dataobject.AccessLogDO; import cn.iocoder.mall.admin.dataobject.ExceptionLogDO; import org.mapstruct.Mapper; diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java index ce27ed781..4a02b8caa 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java @@ -1,10 +1,13 @@ package cn.iocoder.mall.admin.convert; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.admin.api.bo.admin.AdminBO; import cn.iocoder.mall.admin.api.dto.admin.AdminAddDTO; import cn.iocoder.mall.admin.api.dto.admin.AdminUpdateDTO; import cn.iocoder.mall.admin.dataobject.AdminDO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -27,4 +30,9 @@ public interface AdminConvert { @Mappings({}) List convert(List adminBOs); + @Mappings({ + @Mapping(source = "records", target = "list"), + }) + PageResult convert(IPage page); + } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DataDictConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DataDictConvert.java index 2ccde04d7..d5dcb15ce 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DataDictConvert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DataDictConvert.java @@ -1,8 +1,8 @@ package cn.iocoder.mall.admin.convert; -import cn.iocoder.mall.admin.api.bo.DataDictBO; -import cn.iocoder.mall.admin.api.dto.DataDictAddDTO; -import cn.iocoder.mall.admin.api.dto.DataDictUpdateDTO; +import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; +import cn.iocoder.mall.admin.api.dto.datadict.DataDictAddDTO; +import cn.iocoder.mall.admin.api.dto.datadict.DataDictUpdateDTO; import cn.iocoder.mall.admin.dataobject.DataDictDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -22,4 +22,4 @@ public interface DataDictConvert { List convert(List dataDictDOs); -} \ No newline at end of file +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/OAuth2Convert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/OAuth2Convert.java index a58c8d271..4629e552f 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/OAuth2Convert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/OAuth2Convert.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.admin.convert; -import cn.iocoder.mall.admin.api.bo.OAuth2AccessTokenBO; -import cn.iocoder.mall.admin.api.bo.OAuth2AuthenticationBO; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AccessTokenBO; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AuthenticationBO; import cn.iocoder.mall.admin.dataobject.AdminRoleDO; import cn.iocoder.mall.admin.dataobject.OAuth2AccessTokenDO; import org.mapstruct.Mapper; @@ -35,4 +35,4 @@ public interface OAuth2Convert { .setRoleIds(adminRoleDOs.stream().map(AdminRoleDO::getRoleId).collect(Collectors.toSet())); } -} \ No newline at end of file +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/ResourceConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/ResourceConvert.java index 49b168941..844d35ea1 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/ResourceConvert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/ResourceConvert.java @@ -1,11 +1,14 @@ package cn.iocoder.mall.admin.convert; -import cn.iocoder.mall.admin.api.bo.ResourceBO; -import cn.iocoder.mall.admin.api.dto.ResourceAddDTO; -import cn.iocoder.mall.admin.api.dto.ResourceUpdateDTO; +import cn.iocoder.common.framework.util.StringUtil; +import cn.iocoder.mall.admin.api.bo.resource.ResourceBO; +import cn.iocoder.mall.admin.api.dto.resource.ResourceAddDTO; +import cn.iocoder.mall.admin.api.dto.resource.ResourceUpdateDTO; import cn.iocoder.mall.admin.dataobject.ResourceDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.Named; import org.mapstruct.factory.Mappers; import java.util.List; @@ -15,7 +18,9 @@ public interface ResourceConvert { ResourceConvert INSTANCE = Mappers.getMapper(ResourceConvert.class); - @Mappings({}) + @Mappings({ + @Mapping(source = "permissions", target = "permissions", qualifiedByName = "translateListFromString") + }) ResourceBO convert(ResourceDO resourceDO); @Mappings({}) @@ -27,4 +32,9 @@ public interface ResourceConvert { @Mappings({}) ResourceDO convert(ResourceUpdateDTO resourceUpdateDTO); -} \ No newline at end of file + @Named("translateListFromString") + default List translateListFromString(String picUrls) { + return StringUtil.split(picUrls, ","); + } + +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/RoleConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/RoleConvert.java index 73ad2c417..e1657fc4b 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/RoleConvert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/RoleConvert.java @@ -1,10 +1,13 @@ package cn.iocoder.mall.admin.convert; -import cn.iocoder.mall.admin.api.bo.RoleBO; -import cn.iocoder.mall.admin.api.dto.RoleAddDTO; -import cn.iocoder.mall.admin.api.dto.RoleUpdateDTO; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.admin.api.bo.role.RoleBO; +import cn.iocoder.mall.admin.api.dto.role.RoleAddDTO; +import cn.iocoder.mall.admin.api.dto.role.RoleUpdateDTO; import cn.iocoder.mall.admin.dataobject.RoleDO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -27,4 +30,9 @@ public interface RoleConvert { @Mappings({}) List convert(List roleDOs); -} \ No newline at end of file + @Mappings({ + @Mapping(source = "records", target = "list"), + }) + PageResult convert(IPage page); + +} 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 index b8d04138c..49e049537 100644 --- 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 @@ -1,13 +1,15 @@ package cn.iocoder.mall.admin.dao; +import cn.iocoder.common.framework.mybatis.QueryWrapperX; +import cn.iocoder.mall.admin.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; -import java.util.List; - @Repository public interface AdminMapper extends BaseMapper { @@ -15,12 +17,9 @@ public interface AdminMapper extends BaseMapper { return selectOne(new QueryWrapper().eq("username", username)); } - List selectListByNicknameLike(@Param("nickname") String nickname, - @Param("offset") Integer offset, - @Param("limit") Integer limit); - - Integer selectCountByNicknameLike(@Param("nickname") String nickname); - - int update(AdminDO admin); + default IPage selectPage(AdminPageDTO adminPageDTO) { + return selectPage(new Page<>(adminPageDTO.getPageNo(), adminPageDTO.getPageSize()), + new QueryWrapperX().likeIfPresent("nickname", adminPageDTO.getNickname())); + } } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminRoleMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminRoleMapper.java index 3c69199c2..9112a484e 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminRoleMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminRoleMapper.java @@ -1,20 +1,27 @@ package cn.iocoder.mall.admin.dao; import cn.iocoder.mall.admin.dataobject.AdminRoleDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.Collection; import java.util.List; @Repository -public interface AdminRoleMapper { +public interface AdminRoleMapper extends BaseMapper { List selectByAdminId(@Param("adminId") Integer adminId); + default List selectListByAdminIds(Collection adminIds) { + return selectList(new QueryWrapper().in("admin_id", adminIds)); + } + int updateToDeletedByAdminId(@Param("adminId") Integer adminId); int updateToDeletedByRoleId(@Param("roleId") Integer roleId); void insertList(@Param("adminRoleDOs") List adminRoleDOs); -} \ No newline at end of file +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/RoleMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/RoleMapper.java index fce5428d8..3a4ed4a05 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/RoleMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/RoleMapper.java @@ -1,29 +1,31 @@ package cn.iocoder.mall.admin.dao; +import cn.iocoder.common.framework.mybatis.QueryWrapperX; +import cn.iocoder.mall.admin.api.dto.role.RolePageDTO; import cn.iocoder.mall.admin.dataobject.RoleDO; -import org.apache.ibatis.annotations.Param; +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; -import java.util.Set; @Repository -public interface RoleMapper { +public interface RoleMapper extends BaseMapper { - void insert(RoleDO roleDO); + default List selectListByIds(Collection ids) { + return selectList(new QueryWrapper().in("id", ids)); + } - int update(RoleDO roleDO); + default List selectList() { + return selectList(new QueryWrapper<>()); + } - RoleDO selectById(@Param("id") Integer id); + default IPage selectPage(RolePageDTO rolePageDTO) { + return selectPage(new Page<>(rolePageDTO.getPageNo(), rolePageDTO.getPageSize()), + new QueryWrapperX().likeIfPresent("name", rolePageDTO.getName())); + } - List selectListByNameLike(@Param("name") String name, - @Param("offset") Integer offset, - @Param("limit") Integer limit); - - Integer selectCountByNameLike(@Param("name") String name); - - List selectListByIds(@Param("ids") Set ids); - - List selectList(); - -} \ No newline at end of file +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AccessLogDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AccessLogDO.java index 5ed0edd40..34ce8a1e2 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AccessLogDO.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AccessLogDO.java @@ -2,6 +2,7 @@ package cn.iocoder.mall.admin.dataobject; import cn.iocoder.common.framework.dataobject.BaseDO; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; @@ -29,7 +30,7 @@ public class AccessLogDO extends BaseDO { /** * 用户编号. * - * 当管理员为空时,该值为 {@link cn.iocoder.mall.admin.api.dto.AccessLogAddDTO#USER_ID_NULL} + * 当管理员为空时,该值为 {@link AccessLogAddDTO#USER_ID_NULL} */ private Integer userId; /** diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminRoleDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminRoleDO.java index 5b0a32e8f..b3e365b72 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminRoleDO.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminRoleDO.java @@ -1,12 +1,14 @@ package cn.iocoder.mall.admin.dataobject; import cn.iocoder.common.framework.dataobject.DeletableDO; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; /** * {@link AdminDO} 和 {@link RoleDO} 的关联表 */ +@TableName("admin_role") @Data @Accessors(chain = true) public class AdminRoleDO extends DeletableDO { diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/ExceptionLogDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/ExceptionLogDO.java index 48af626e0..236ad95a3 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/ExceptionLogDO.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/ExceptionLogDO.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.admin.dataobject; import cn.iocoder.common.framework.dataobject.BaseDO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; @@ -28,7 +29,7 @@ public class ExceptionLogDO extends BaseDO { /** * 用户编号. * - * 当管理员为空时,该值为 {@link cn.iocoder.mall.admin.api.dto.AccessLogAddDTO#USER_ID_NULL} + * 当管理员为空时,该值为 {@link AccessLogAddDTO#USER_ID_NULL} */ private Integer userId; /** diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/ResourceDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/ResourceDO.java index 795338ccb..e2b8ad26c 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/ResourceDO.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/ResourceDO.java @@ -4,8 +4,6 @@ import cn.iocoder.common.framework.dataobject.DeletableDO; import lombok.Data; import lombok.experimental.Accessors; -import java.util.Date; - /** * 资源实体 */ @@ -13,27 +11,10 @@ import java.util.Date; @Accessors(chain = true) public class ResourceDO extends DeletableDO { - /** - * 资源类型 - 菜单 - */ - @Deprecated - public static final Integer TYPE_MENU = 1; - /** - * 资源类型 - 操作 - * - * 例如,按钮。 - */ - @Deprecated - public static final Integer TYPE_OPERATION = 2; - /** * 资源编号 */ private Integer id; - /** - * 资源名字(标识) - */ - private String name; /** * 资源类型 */ @@ -46,10 +27,6 @@ public class ResourceDO extends DeletableDO { * 展示名 */ private String displayName; - /** - * 添加时间 - */ - private Date createTime; /** * 父级资源编号(外键:{@link ResourceDO#id}) */ @@ -57,9 +34,21 @@ public class ResourceDO extends DeletableDO { /** * 操作 * - * 当资源类型为【菜单】时,handler 配置为界面 URL ,或者前端组件名 - * 当资源类型为【URL】时,handler 配置为后端 URL 。举个例子,如果有一个「创建管理员」的表单,那么前端界面上的按钮可以根据这个 url 判断是否展示,后端接收到该 url 的请求时会判断是否有权限。 + * 目前当且仅当资源类型为【菜单】时,才会生效,即 handler 配置为界面 URL ,或者前端组件名,或者前端的路由。 */ private String handler; + /** + * 图表 + * + * 目前当且仅当资源类型为【菜单】时,才会生效 + */ + private String icon; + /** + * 权限标识数组,使用逗号分隔。 + * + * 例如:system.admin.add 。 + * 推荐格式为 ${系统}.${模块}.${操作} 。 + */ + private String permissions; } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/RoleDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/RoleDO.java index d84fdf303..9fc58be16 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/RoleDO.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/RoleDO.java @@ -1,12 +1,14 @@ package cn.iocoder.mall.admin.dataobject; import cn.iocoder.common.framework.dataobject.DeletableDO; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; /** * 角色实体 */ +@TableName("role") @Data @Accessors(chain = true) public class RoleDO extends DeletableDO { diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java index 5ba6c61f7..5b926d3ad 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java @@ -2,30 +2,31 @@ package cn.iocoder.mall.admin.service; import cn.iocoder.common.framework.constant.CommonStatusEnum; import cn.iocoder.common.framework.constant.DeletedStatusEnum; +import cn.iocoder.common.framework.util.CollectionUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.admin.api.AdminService; +import cn.iocoder.mall.admin.api.bo.role.RoleBO; import cn.iocoder.mall.admin.api.bo.admin.AdminBO; -import cn.iocoder.mall.admin.api.bo.admin.AdminPageBO; import cn.iocoder.mall.admin.api.constant.AdminConstants; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; -import cn.iocoder.mall.admin.api.dto.admin.AdminAddDTO; -import cn.iocoder.mall.admin.api.dto.admin.AdminPageDTO; -import cn.iocoder.mall.admin.api.dto.admin.AdminUpdateDTO; +import cn.iocoder.mall.admin.api.dto.admin.*; import cn.iocoder.mall.admin.convert.AdminConvert; import cn.iocoder.mall.admin.dao.AdminMapper; import cn.iocoder.mall.admin.dao.AdminRoleMapper; import cn.iocoder.mall.admin.dataobject.AdminDO; import cn.iocoder.mall.admin.dataobject.AdminRoleDO; import cn.iocoder.mall.admin.dataobject.RoleDO; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.DigestUtils; -import java.util.Date; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; @Service @@ -67,15 +68,9 @@ public class AdminServiceImpl implements AdminService { } @Override - public CommonResult getAdminPage(AdminPageDTO adminPageDTO) { - AdminPageBO adminPage = new AdminPageBO(); - // 查询分页数据 - int offset = (adminPageDTO.getPageNo() - 1) * adminPageDTO.getPageSize(); - adminPage.setList(AdminConvert.INSTANCE.convert(adminMapper.selectListByNicknameLike(adminPageDTO.getNickname(), - offset, adminPageDTO.getPageSize()))); - // 查询分页总数 - adminPage.setTotal(adminMapper.selectCountByNicknameLike(adminPageDTO.getNickname())); - return CommonResult.success(adminPage); + public PageResult getAdminPage(AdminPageDTO adminPageDTO) { + IPage page = adminMapper.selectPage(adminPageDTO); + return AdminConvert.INSTANCE.convert(page); } @Override @@ -97,94 +92,121 @@ public class AdminServiceImpl implements AdminService { } @Override - public CommonResult updateAdmin(Integer adminId, AdminUpdateDTO adminUpdateDTO) { + public Boolean updateAdmin(Integer adminId, AdminUpdateDTO adminUpdateDTO) { // 校验账号存在 if (adminMapper.selectById(adminUpdateDTO.getId()) == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode()); } // 校验账号唯一 AdminDO usernameAdmin = adminMapper.selectByUsername(adminUpdateDTO.getUsername()); if (usernameAdmin != null && !usernameAdmin.getId().equals(adminUpdateDTO.getId())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ADMIN_USERNAME_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_USERNAME_EXISTS.getCode()); } // 更新到数据库 AdminDO updateAdmin = AdminConvert.INSTANCE.convert(adminUpdateDTO); - adminMapper.update(updateAdmin); + adminMapper.updateById(updateAdmin); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } @Override @Transactional - public CommonResult updateAdminStatus(Integer adminId, Integer updateAdminId, Integer status) { + public Boolean updateAdminStatus(Integer adminId, AdminUpdateStatusDTO adminUpdateStatusDTO) { // 校验账号存在 - AdminDO admin = adminMapper.selectById(updateAdminId); + AdminDO admin = adminMapper.selectById(adminUpdateStatusDTO.getId()); if (admin == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode()); } if (AdminConstants.USERNAME_ADMIN.equals(admin.getUsername())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ADMIN_ADMIN_STATUS_CAN_NOT_UPDATE.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_ADMIN_STATUS_CAN_NOT_UPDATE.getCode()); } // 如果状态相同,则返回错误 - if (status.equals(admin.getStatus())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ADMIN_STATUS_EQUALS.getCode()); + if (adminUpdateStatusDTO.getStatus().equals(admin.getStatus())) { + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_STATUS_EQUALS.getCode()); } // 更新管理员状态 - AdminDO updateAdmin = new AdminDO().setId(updateAdminId).setStatus(status); - adminMapper.update(updateAdmin); + AdminDO updateAdmin = new AdminDO().setId(adminUpdateStatusDTO.getId()).setStatus(adminUpdateStatusDTO.getStatus()); + adminMapper.updateById(updateAdmin); // 如果是关闭管理员,则标记 token 失效。否则,管理员还可以继续蹦跶 - if (CommonStatusEnum.DISABLE.getValue().equals(status)) { - oAuth2Service.removeToken(updateAdminId); + if (CommonStatusEnum.DISABLE.getValue().equals(adminUpdateStatusDTO.getStatus())) { + oAuth2Service.removeToken(adminUpdateStatusDTO.getId()); } // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } @Override @Transactional - public CommonResult deleteAdmin(Integer adminId, Integer updateAdminId) { + public Boolean deleteAdmin(Integer adminId, Integer updateAdminId) { // 校验账号存在 AdminDO admin = adminMapper.selectById(updateAdminId); if (admin == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode()); } // 只有禁用的账号才可以删除 if (CommonStatusEnum.ENABLE.getValue().equals(admin.getStatus())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ADMIN_DELETE_ONLY_DISABLE.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_DELETE_ONLY_DISABLE.getCode()); } // 标记删除 AdminDO - AdminDO updateAdmin = new AdminDO().setId(updateAdminId); - updateAdmin.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); - adminMapper.update(updateAdmin); + adminMapper.deleteById(updateAdminId); // 标记删除 // 标记删除 AdminRole adminRoleMapper.updateToDeletedByAdminId(updateAdminId); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; + } + + @Override + public Map> getAdminRolesMap(Collection adminIds) { + // 查询管理员拥有的角色关联数据 + List adminRoleList = adminRoleMapper.selectListByAdminIds(adminIds); + if (adminRoleList.isEmpty()) { + return Collections.emptyMap(); + } + // 查询角色数据 + List roleList = roleService.getRoleList(CollectionUtil.convertSet(adminRoleList, AdminRoleDO::getRoleId)); + Map roleMap = CollectionUtil.convertMap(roleList, RoleBO::getId); + // 拼接数据 + Multimap result = ArrayListMultimap.create(); + adminRoleList.forEach(adminRole -> result.put(adminRole.getAdminId(), roleMap.get(adminRole.getRoleId()))); + return result.asMap(); + } + + @Override + public List getRoleList(Integer adminId) { + // 查询管理员拥有的角色关联数据 + List adminRoleList = adminRoleMapper.selectByAdminId(adminId); + if (adminRoleList.isEmpty()) { + return Collections.emptyList(); + } + // 查询角色数据 + return roleService.getRoleList(CollectionUtil.convertSet(adminRoleList, AdminRoleDO::getRoleId)); } @Override @Transactional - public CommonResult assignRole(Integer adminId, Integer updateAdminId, Set roleIds) { + public Boolean assignAdminRole(Integer adminId, AdminAssignRoleDTO adminAssignRoleDTO) { // 校验账号存在 - AdminDO admin = adminMapper.selectById(updateAdminId); + AdminDO admin = adminMapper.selectById(adminAssignRoleDTO.getId()); if (admin == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode()); } // 校验是否有不存在的角色 - List roles = roleService.getRoles(roleIds); - if (roles.size() != roleIds.size()) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ROLE_ASSIGN_RESOURCE_NOT_EXISTS.getCode()); + if (!CollectionUtil.isEmpty(adminAssignRoleDTO.getRoleIds())) { + List roles = roleService.getRoles(adminAssignRoleDTO.getRoleIds()); + if (roles.size() != adminAssignRoleDTO.getRoleIds().size()) { + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_ASSIGN_ROLE_NOT_EXISTS.getCode()); + } } // TODO 芋艿,这里先简单实现。即方式是,删除老的分配的角色关系,然后添加新的分配的角色关系 // 标记管理员角色源关系都为删除 - adminRoleMapper.updateToDeletedByAdminId(updateAdminId); + adminRoleMapper.updateToDeletedByAdminId(adminAssignRoleDTO.getId()); // 创建 RoleResourceDO 数组,并插入到数据库 - if (!roleIds.isEmpty()) { - List adminRoleDOs = roleIds.stream().map(roleId -> { - AdminRoleDO roleResource = new AdminRoleDO().setAdminId(updateAdminId).setRoleId(roleId); + if (!CollectionUtil.isEmpty(adminAssignRoleDTO.getRoleIds())) { + List adminRoleDOs = adminAssignRoleDTO.getRoleIds().stream().map(roleId -> { + AdminRoleDO roleResource = new AdminRoleDO().setAdminId(adminAssignRoleDTO.getId()).setRoleId(roleId); roleResource.setCreateTime(new Date()); roleResource.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); return roleResource; @@ -193,7 +215,7 @@ public class AdminServiceImpl implements AdminService { } // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } private String encodePassword(String password) { diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java index 6651fe4fb..348d7bbf7 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java @@ -4,10 +4,10 @@ import cn.iocoder.common.framework.constant.DeletedStatusEnum; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.DataDictService; -import cn.iocoder.mall.admin.api.bo.DataDictBO; +import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; -import cn.iocoder.mall.admin.api.dto.DataDictAddDTO; -import cn.iocoder.mall.admin.api.dto.DataDictUpdateDTO; +import cn.iocoder.mall.admin.api.dto.datadict.DataDictAddDTO; +import cn.iocoder.mall.admin.api.dto.datadict.DataDictUpdateDTO; import cn.iocoder.mall.admin.convert.DataDictConvert; import cn.iocoder.mall.admin.dao.DataDictMapper; import cn.iocoder.mall.admin.dataobject.DataDictDO; 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 2a63cb642..b40d34d40 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 @@ -3,8 +3,8 @@ package cn.iocoder.mall.admin.service; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.OAuth2Service; -import cn.iocoder.mall.admin.api.bo.OAuth2AccessTokenBO; -import cn.iocoder.mall.admin.api.bo.OAuth2AuthenticationBO; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AccessTokenBO; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AuthenticationBO; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; import cn.iocoder.mall.admin.convert.OAuth2Convert; import cn.iocoder.mall.admin.dao.OAuth2AccessTokenMapper; diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/ResourceServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/ResourceServiceImpl.java index 03070f4e9..b65e3a3cf 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/ResourceServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/ResourceServiceImpl.java @@ -3,13 +3,12 @@ package cn.iocoder.mall.admin.service; import cn.iocoder.common.framework.constant.DeletedStatusEnum; import cn.iocoder.common.framework.constant.SysErrorCodeEnum; import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.ResourceService; -import cn.iocoder.mall.admin.api.bo.ResourceBO; +import cn.iocoder.mall.admin.api.bo.resource.ResourceBO; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; import cn.iocoder.mall.admin.api.constant.ResourceConstants; -import cn.iocoder.mall.admin.api.dto.ResourceAddDTO; -import cn.iocoder.mall.admin.api.dto.ResourceUpdateDTO; +import cn.iocoder.mall.admin.api.dto.resource.ResourceAddDTO; +import cn.iocoder.mall.admin.api.dto.resource.ResourceUpdateDTO; import cn.iocoder.mall.admin.convert.ResourceConvert; import cn.iocoder.mall.admin.dao.ResourceMapper; import cn.iocoder.mall.admin.dao.RoleResourceMapper; @@ -51,81 +50,52 @@ public class ResourceServiceImpl implements ResourceService { @Override @SuppressWarnings("Duplicates") - public CommonResult addResource(Integer adminId, ResourceAddDTO resourceAddDTO) { + public ResourceBO addResource(Integer adminId, ResourceAddDTO resourceAddDTO) { // 补充未在 Validation 中校验的参数校验 if (!isValidResourceType(resourceAddDTO.getType())) { - return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "资源类型必须是菜单或 Url"); // TODO 有点搓 - } - // 校验资源唯一性 - if (resourceMapper.selectByName(resourceAddDTO.getName()) != null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_NAME_DUPLICATE.getCode()); + throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "资源类型必须是菜单或 Url"); // TODO 有点搓 } // 校验父资源存在 - if (resourceAddDTO.getPid() == null) { - resourceAddDTO.setPid(ResourceConstants.PID_ROOT); - } - if (checkParentExists(resourceAddDTO.getPid())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_PARENT_NOT_EXISTS.getCode()); - } + checkParentResource(resourceAddDTO.getPid(), null); // 存储到数据库 ResourceDO resource = ResourceConvert.INSTANCE.convert(resourceAddDTO); - if (ResourceConstants.PID_ROOT.equals(resourceAddDTO.getPid())) { // 根节点,必须没有操作 - resource.setHandler(null); - } else if (!resource.getHandler().startsWith("/")) { - resource.setHandler("/" + resource.getHandler()); - } + initResourceProperty(resource); resource.setCreateTime(new Date()); resource.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); resourceMapper.insert(resource); // TODO 操作日志 // 返回成功 - return CommonResult.success(ResourceConvert.INSTANCE.convert(resource)); + return ResourceConvert.INSTANCE.convert(resource); } @Override @SuppressWarnings("Duplicates") - public CommonResult updateResource(Integer adminId, ResourceUpdateDTO resourceUpdateDTO) { + public Boolean updateResource(Integer adminId, ResourceUpdateDTO resourceUpdateDTO) { // 校验更新的资源是否存在 if (resourceMapper.selectById(resourceUpdateDTO.getId()) == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); - } - // 校验资源唯一性 - ResourceDO existNameResource = resourceMapper.selectByName(resourceUpdateDTO.getName()); - if (existNameResource != null && !existNameResource.getId().equals(resourceUpdateDTO.getId())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_NAME_DUPLICATE.getCode()); - } - // 不能设置自己为父资源 - if (resourceUpdateDTO.getId().equals(resourceUpdateDTO.getPid())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_PARENT_ERROR.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); } // 校验父资源存在 - if (resourceUpdateDTO.getPid() == null) { - resourceUpdateDTO.setPid(ResourceConstants.PID_ROOT); - } - if (checkParentExists(resourceUpdateDTO.getPid())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_PARENT_NOT_EXISTS.getCode()); - } + checkParentResource(resourceUpdateDTO.getPid(), resourceUpdateDTO.getId()); // 更新到数据库 ResourceDO resource = ResourceConvert.INSTANCE.convert(resourceUpdateDTO); - if (ResourceConstants.PID_ROOT.equals(resourceUpdateDTO.getPid())) { // 根节点,必须没有操作 - resource.setHandler(null); - } + initResourceProperty(resource); resourceMapper.update(resource); // TODO 操作日志 // 返回成功 - return CommonResult.success(true); + return true; } @Override @Transactional - public CommonResult deleteResource(Integer adminId, Integer resourceId) { + public Boolean deleteResource(Integer adminId, Integer resourceId) { // 校验更新的资源是否存在 if (resourceMapper.selectById(resourceId) == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); } // 校验是否还有子资源 if (resourceMapper.selectCountByPid(resourceId) > 0) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_EXISTS_CHILDREN.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_EXISTS_CHILDREN.getCode()); } // 更新到数据库 ResourceDO resource = new ResourceDO().setId(resourceId); @@ -134,7 +104,7 @@ public class ResourceServiceImpl implements ResourceService { // 删除资源关联表 roleResourceMapper.updateToDeletedByResourceId(resourceId); // 返回成功 - return CommonResult.success(true); + return true; } public List getResources(Set resourceIds) { @@ -146,7 +116,7 @@ public class ResourceServiceImpl implements ResourceService { private boolean isValidResourceType(Integer type) { return ResourceConstants.TYPE_MENU.equals(type) - || ResourceConstants.TYPE_URL.equals(type); + || ResourceConstants.TYPE_BUTTON.equals(type); } private boolean checkParentExists(Integer pid) { @@ -156,4 +126,37 @@ public class ResourceServiceImpl implements ResourceService { return false; } + private void checkParentResource(Integer pid, Integer childId) { + if (pid == null || ResourceConstants.PID_ROOT.equals(pid)) { + return; + } + if (pid.equals(childId)) { // 不能设置自己为父资源 + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_PARENT_ERROR.getCode()); + } + ResourceDO resource = resourceMapper.selectById(pid); + if (resource == null) { // 父资源不存在 + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_PARENT_NOT_EXISTS.getCode()); + } + if (!ResourceConstants.TYPE_MENU.equals(resource.getType())) { // 父资源必须是菜单类型 + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_PARENT_NOT_MENU.getCode()); + } + } + + /** + * 初始化资源的通用属性。 + * + * 例如说,只有菜单类型的资源,才设置 icon + * + * @param resource 资源 + */ + private void initResourceProperty(ResourceDO resource) { + if (resource.getPid() == null) { + resource.setPid(ResourceConstants.PID_ROOT); + } + if (ResourceConstants.TYPE_BUTTON.equals(resource.getType())) { + resource.setHandler(null); + resource.setIcon(null); + } + } + } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java index 07fb700fd..bb8048cfa 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java @@ -3,30 +3,27 @@ package cn.iocoder.mall.admin.service; import cn.iocoder.common.framework.constant.DeletedStatusEnum; import cn.iocoder.common.framework.util.CollectionUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.admin.api.RoleService; -import cn.iocoder.mall.admin.api.bo.RoleBO; -import cn.iocoder.mall.admin.api.bo.RolePageBO; +import cn.iocoder.mall.admin.api.bo.role.RoleBO; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; -import cn.iocoder.mall.admin.api.dto.RoleAddDTO; -import cn.iocoder.mall.admin.api.dto.RolePageDTO; -import cn.iocoder.mall.admin.api.dto.RoleUpdateDTO; +import cn.iocoder.mall.admin.api.dto.role.RoleAddDTO; +import cn.iocoder.mall.admin.api.dto.role.RoleAssignResourceDTO; +import cn.iocoder.mall.admin.api.dto.role.RolePageDTO; +import cn.iocoder.mall.admin.api.dto.role.RoleUpdateDTO; import cn.iocoder.mall.admin.convert.RoleConvert; import cn.iocoder.mall.admin.dao.AdminRoleMapper; import cn.iocoder.mall.admin.dao.RoleMapper; import cn.iocoder.mall.admin.dao.RoleResourceMapper; -import cn.iocoder.mall.admin.dataobject.AdminRoleDO; import cn.iocoder.mall.admin.dataobject.ResourceDO; import cn.iocoder.mall.admin.dataobject.RoleDO; import cn.iocoder.mall.admin.dataobject.RoleResourceDO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; @Service @@ -52,31 +49,25 @@ public class RoleServiceImpl implements RoleService { } @Override - public CommonResult getRolePage(RolePageDTO rolePageDTO) { - RolePageBO rolePage = new RolePageBO(); - // 查询分页数据 - int offset = rolePageDTO.getPageNo() * rolePageDTO.getPageSize(); - rolePage.setRoles(RoleConvert.INSTANCE.convert(roleMapper.selectListByNameLike(rolePageDTO.getName(), - offset, rolePageDTO.getPageSize()))); - // 查询分页总数 - rolePage.setCount(roleMapper.selectCountByNameLike(rolePageDTO.getName())); - return CommonResult.success(rolePage); + public PageResult getRolePage(RolePageDTO rolePageDTO) { + IPage page = roleMapper.selectPage(rolePageDTO); + return RoleConvert.INSTANCE.convert(page); } @Override - public CommonResult> getRoleList(Integer adminId) { - List adminRoleDOs = adminRoleMapper.selectByAdminId(adminId); - return CommonResult.success(adminRoleDOs.stream().map(AdminRoleDO::getRoleId).collect(Collectors.toSet())); - } - - @Override - public CommonResult> getRoleList() { + public List getRoleList() { List roleList = roleMapper.selectList(); - return CommonResult.success(RoleConvert.INSTANCE.convert(roleList)); + return RoleConvert.INSTANCE.convert(roleList); } @Override - public CommonResult addRole(Integer adminId, RoleAddDTO roleAddDTO) { + public List getRoleList(Collection ids) { + List roles = roleMapper.selectListByIds(ids); + return RoleConvert.INSTANCE.convert(roles); + } + + @Override + public RoleBO addRole(Integer adminId, RoleAddDTO roleAddDTO) { // TODO 芋艿,角色名是否要唯一呢?貌似一般系统都是允许的。 // 保存到数据库 RoleDO role = RoleConvert.INSTANCE.convert(roleAddDTO); @@ -85,61 +76,63 @@ public class RoleServiceImpl implements RoleService { roleMapper.insert(role); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(RoleConvert.INSTANCE.convert(role)); + return RoleConvert.INSTANCE.convert(role); } @Override - public CommonResult updateRole(Integer adminId, RoleUpdateDTO roleUpdateDTO) { + public Boolean updateRole(Integer adminId, RoleUpdateDTO roleUpdateDTO) { // TODO 芋艿,角色名是否要唯一呢?貌似一般系统都是允许的。 // 校验角色是否存在 if (roleMapper.selectById(roleUpdateDTO.getId()) == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); } // 更新到数据库 RoleDO roleDO = RoleConvert.INSTANCE.convert(roleUpdateDTO); - roleMapper.update(roleDO); + roleMapper.updateById(roleDO); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } @Override @Transactional - public CommonResult deleteRole(Integer adminId, Integer roleId) { + public Boolean deleteRole(Integer adminId, Integer roleId) { // 校验角色是否存在 if (roleMapper.selectById(roleId) == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); } // 更新到数据库,标记删除 - RoleDO roleDO = new RoleDO().setId(roleId); - roleDO.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); - roleMapper.update(roleDO); + roleMapper.deleteById(roleId); // 标记删除 RoleResource roleResourceMapper.updateToDeletedByRoleId(roleId); // 标记删除 AdminRole adminRoleMapper.updateToDeletedByRoleId(roleId); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } @Override @Transactional - public CommonResult assignResource(Integer adminId, Integer roleId, Set resourceIds) { + public Boolean assignRoleResource(Integer adminId, RoleAssignResourceDTO roleAssignResourceDTO) { + Integer roleId = roleAssignResourceDTO.getId(); + Set resourceIds = roleAssignResourceDTO.getResourceIds(); // 校验角色是否存在 - if (roleMapper.selectById(roleId) == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); + if (roleMapper.selectById(roleAssignResourceDTO.getId()) == null) { + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode()); } // 校验是否有不存在的资源 - List resources = resourceService.getResources(resourceIds); - if (resources.size() != resourceIds.size()) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ROLE_ASSIGN_RESOURCE_NOT_EXISTS.getCode()); + if (!CollectionUtil.isEmpty(resourceIds)) { + List resources = resourceService.getResources(resourceIds); + if (resources.size() != resourceIds.size()) { + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ROLE_ASSIGN_RESOURCE_NOT_EXISTS.getCode()); + } } // TODO 芋艿,这里先简单实现。即方式是,删除老的分配的资源关系,然后添加新的分配的资源关系 // 标记角色原资源关系都为删除 roleResourceMapper.updateToDeletedByRoleId(roleId); // 创建 RoleResourceDO 数组,并插入到数据库 - if (!resourceIds.isEmpty()) { + if (!CollectionUtil.isEmpty(resourceIds)) { List roleResources = resourceIds.stream().map(resourceId -> { RoleResourceDO roleResource = new RoleResourceDO().setRoleId(roleId).setResourceId(resourceId); roleResource.setCreateTime(new Date()); @@ -150,7 +143,7 @@ public class RoleServiceImpl implements RoleService { } // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } public List getRoles(Set roleIds) { diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SystemLogServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SystemLogServiceImpl.java index a44759691..e21525a54 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SystemLogServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SystemLogServiceImpl.java @@ -2,8 +2,8 @@ package cn.iocoder.mall.admin.service; import cn.iocoder.common.framework.util.StringUtil; import cn.iocoder.mall.admin.api.SystemLogService; -import cn.iocoder.mall.admin.api.dto.AccessLogAddDTO; -import cn.iocoder.mall.admin.api.dto.ExceptionLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO; +import cn.iocoder.mall.admin.api.dto.systemlog.ExceptionLogAddDTO; import cn.iocoder.mall.admin.convert.AccessLogConvert; import cn.iocoder.mall.admin.dao.AccessLogMapper; import cn.iocoder.mall.admin.dao.ExceptionLogMapper; diff --git a/system/system-service-impl/src/main/resources/config/application.yaml b/system/system-service-impl/src/main/resources/config/application.yaml index 0bb439c57..2030b1573 100644 --- a/system/system-service-impl/src/main/resources/config/application.yaml +++ b/system/system-service-impl/src/main/resources/config/application.yaml @@ -49,3 +49,9 @@ dubbo: version: 1.0.0 RoleService: version: 1.0.0 + +# logging +logging: + level: + # dao 开启 debug 模式 mybatis 输入 sql + cn.iocoder.mall.admin.dao: debug diff --git a/system/system-service-impl/src/main/resources/mapper/AdminMapper.xml b/system/system-service-impl/src/main/resources/mapper/AdminMapper.xml deleted file mode 100644 index 13272d4be..000000000 --- a/system/system-service-impl/src/main/resources/mapper/AdminMapper.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - id, username, nickname, password, status, - create_time - - - - - - - - - - UPDATE admin - - - , username = #{username} - - - , nickname = #{nickname} - - - , password = #{password} - - - , status = #{status} - - - , deleted = #{deleted} - - - WHERE id = #{id} - - - diff --git a/system/system-service-impl/src/main/resources/mapper/ResourceMapper.xml b/system/system-service-impl/src/main/resources/mapper/ResourceMapper.xml index ee1ba621b..a3d8f281f 100644 --- a/system/system-service-impl/src/main/resources/mapper/ResourceMapper.xml +++ b/system/system-service-impl/src/main/resources/mapper/ResourceMapper.xml @@ -2,14 +2,6 @@ - - - - - - - - id, name, type, sort, display_name, create_time, pid, handler @@ -90,16 +82,6 @@ AND deleted = 0 - - INSERT INTO resource ( - name, type, sort, display_name, handler, - pid, create_time, deleted - ) VALUES ( - #{name}, #{type}, #{sort}, #{displayName}, #{handler}, - #{pid}, #{createTime}, #{deleted} - ) - - UPDATE resource @@ -125,4 +107,4 @@ WHERE id = #{id} - \ No newline at end of file + diff --git a/system/system-service-impl/src/main/resources/mapper/RoleMapper.xml b/system/system-service-impl/src/main/resources/mapper/RoleMapper.xml deleted file mode 100644 index 8b1b84b7f..000000000 --- a/system/system-service-impl/src/main/resources/mapper/RoleMapper.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - id, name, create_time - - - - INSERT INTO role ( - name, create_time, deleted - ) VALUES ( - #{name}, #{createTime}, #{deleted} - ) - - - - UPDATE role - - - , name = #{name} - - - , deleted = #{deleted} - - - WHERE id = #{id} - - - - - - - - - - - - - \ No newline at end of file diff --git a/system/system-service-impl/src/main/resources/mybatis-config.xml b/system/system-service-impl/src/main/resources/mybatis-config.xml deleted file mode 100644 index 7f604cc7e..000000000 --- a/system/system-service-impl/src/main/resources/mybatis-config.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file