- 后端:重构 system 模块

This commit is contained in:
YunaiV 2019-05-15 20:18:09 +08:00
parent 0010701e68
commit 39f36837ea
102 changed files with 943 additions and 1056 deletions

View File

@ -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,
},
});
},

View File

@ -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 (<span>{text}</span>);
}
},
{
title: '状态',
dataIndex: 'status',
@ -174,7 +190,7 @@ const SearchForm = Form.create()(props => {
<Form onSubmit={handleSubmit} layout="inline">
<Row gutter={{ md: 8, lg: 24, xl: 48 }}>
<Col md={8} sm={24}>
<FormItem label="昵称">
<FormItem label="员工姓名">
{getFieldDecorator('nickname')(<Input placeholder="请输入" />)}
</FormItem>
</Col>
@ -251,18 +267,18 @@ const AddOrUpdateForm = Form.create()(props => {
okText='保存'
onCancel={() => handleModalVisible()}
>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="用户名">
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="账号">
{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,
})(<Input placeholder="请输入" />)}
</FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="昵称">
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="员工姓名">
{form.getFieldDecorator('nickname', {
rules: [{ required: true, message: '请输入昵称'},
rules: [{ required: true, message: '请输入员工姓名'},
{max: 10, message: '姓名最大长度为 10'}],
initialValue: formVals.nickname,
})(<Input placeholder="请输入" />)}

View File

@ -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 => <strong>{text}</strong>,
},
// {
// title: 'id',
// dataIndex: 'id',
// render: text => <strong>{text}</strong>,
// },
{
title: '名称',
dataIndex: 'name',
@ -289,7 +289,7 @@ class RoleList extends PureComponent {
{
title: '创建时间',
dataIndex: 'createTime',
sorter: true,
// sorter: true,
render: val => <span>{moment(val).format('YYYY-MM-DD')}</span>,
},
{
@ -325,7 +325,7 @@ class RoleList extends PureComponent {
type="primary"
onClick={() => this.handleModalVisible(true, 'add', {})}
>
新建
新建角色
</Button>
</div>
</div>

View File

@ -26,6 +26,11 @@
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<!-- DB 相关 -->
<dependency>
<groupId>org.mybatis</groupId>
@ -36,6 +41,10 @@
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-annotation</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-core</artifactId>
</dependency>
<!-- RPC 相关 -->
<dependency>

View File

@ -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 <T> 数据类型
*/
public class QueryWrapperX<T> extends QueryWrapper<T> {
public QueryWrapperX<T> likeIfPresent(String column, String val) {
if (StringUtils.hasText(val)) {
return (QueryWrapperX<T>) super.like(column, val);
}
return this;
}
}

View File

@ -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 <T> Set<T> asSet(T... objs) {
return new HashSet<>(Arrays.asList(objs));
}
public static <T, U> List<U> convertList(List<T> from, Function<T, U> func) {
return from.stream().map(func).collect(Collectors.toList());
}
public static <T, U> Set<U> convertSet(List<T> from, Function<T, U> func) {
return from.stream().map(func).collect(Collectors.toSet());
}
public static <T, K, V> Map<K, V> convertMap(List<T> from, Function<T, K> keyFunc, Function<T, V> valueFunc) {
return from.stream().collect(Collectors.toMap(keyFunc, valueFunc));
}
public static <T, K> Map<K, T> convertMap(List<T> from, Function<T, K> keyFunc) {
return from.stream().collect(Collectors.toMap(keyFunc, item -> item));
}
}

View File

@ -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;
}
}

View File

@ -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<T> implements Serializable {
@ApiModelProperty(value = "数据", required = true)
private List<T> list;
@ApiModelProperty(value = "总量", required = true)
private Integer total;
public List<T> getList() {
return list;
}
public PageResult<T> setList(List<T> list) {
this.list = list;
return this;
}
public Integer getTotal() {
return total;
}
public PageResult<T> setTotal(Integer total) {
this.total = total;
return this;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -18,7 +18,7 @@
- [ ] 订单管理
- [ ] 销售单 开发中
- [ ] 售后单 开发中
- [ ] 订单评价【待认领
- [ ] 订单评价【开发中
- [ ] 会员管理
- [ ] 会员资料 20%【待认领】
- TODO 需要补充
@ -31,8 +31,8 @@
- [ ] 限制折扣 20% 【待认领】
- [ ] 多人拼团【待认领】
- [ ] 系统管理
- [ ] 员工管理
- [ ] 角色管理
- [x] 员工管理
- [x] 角色管理 <!--【前端页面需要细化下】-->
- [ ] 权限管理
- [ ] 短信管理
- [ ] 短信模板

View File

@ -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.*;

View File

@ -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;

View File

@ -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;

View File

@ -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;

11
pom.xml
View File

@ -38,6 +38,7 @@
<curator.version>2.13.0</curator.version>
<!-- <curator.version>4.0.1</curator.version>-->
<!-- <zookeeper.version>3.4.14</zookeeper.version>-->
<swagger.version>1.5.21</swagger.version>
<springfox-swagger.version>2.9.2</springfox-swagger.version>
<swagger-bootstrap-ui.version>1.9.3</swagger-bootstrap-ui.version>
<mybatis-spring-boot-starter.version>2.0.0</mybatis-spring-boot-starter.version>
@ -88,6 +89,11 @@
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
@ -144,6 +150,11 @@
<artifactId>mybatis-plus-annotation</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-core</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>

View File

@ -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<List<AdminMenuTreeNodeVO>> menuResourceTree() {
List<ResourceBO> resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_MENU, AdminSecurityContextHolder.getContext().getRoleIds());
List<ResourceBO> resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_MENU,
AdminSecurityContextHolder.getContext().getRoleIds());
// 创建 AdminMenuTreeNodeVO Map
Map<Integer, AdminMenuTreeNodeVO> 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<Set<String>> urlResourceList() {
List<ResourceBO> resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_URL, AdminSecurityContextHolder.getContext().getRoleIds());
List<ResourceBO> 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<AdminPageVO> page(AdminPageDTO adminPageDTO) {
// CommonResult<AdminPageBO> result = adminService.getAdminPage(new AdminPageDTO().setNickname(nickname).setPageNo(pageNo).setPageSize(pageSize));
CommonResult<AdminPageBO> result = adminService.getAdminPage(adminPageDTO);
return AdminConvert.INSTANCE.convert(result);
public CommonResult<PageResult<AdminVO>> page(AdminPageDTO adminPageDTO) {
PageResult<AdminBO> page = adminService.getAdminPage(adminPageDTO);
PageResult<AdminVO> resultPage = AdminConvert.INSTANCE.convertAdminVOPage(page);
// 拼接结果
if (!resultPage.getList().isEmpty()) {
// 查询角色数组
Map<Integer, Collection<RoleBO>> 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<Boolean> 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<Boolean> 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<Boolean> updateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return adminService.updateAdminStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status);
public CommonResult<Boolean> 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<Boolean> 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<List<AdminRoleVO>> roleList(@RequestParam("id") Integer id) {
// 获得管理员拥有的角色集合
Set<Integer> adminRoleIdSet = roleService.getRoleList(id).getData();
// 获得所有角色数组
List<RoleBO> allRoleList = roleService.getRoleList().getData();
List<RoleBO> allRoleList = adminService.getRoleList(id);
Set<Integer> adminRoleIdSet = CollectionUtil.convertSet(allRoleList, RoleBO::getId);
// 转换出返回结果
List<AdminRoleVO> 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<Boolean> assignRole(@RequestParam("id") Integer id,
@RequestParam("roleIds")Set<Integer> roleIds) {
return adminService.assignRole(AdminSecurityContextHolder.getContext().getAdminId(), id, roleIds);
public CommonResult<Boolean> assignRole(AdminAssignRoleDTO adminAssignRoleDTO) {
return success(adminService.assignAdminRole(AdminSecurityContextHolder.getContext().getAdminId(), adminAssignRoleDTO));
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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<ResourceVO> 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<ResourceBO> 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<Boolean> 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<Boolean> 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<Boolean> delete(@RequestParam("id") Integer id) {
return resourceService.deleteResource(AdminSecurityContextHolder.getContext().getAdminId(), id);
return success(resourceService.deleteResource(AdminSecurityContextHolder.getContext().getAdminId(), id));
}
}

View File

@ -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<RolePageVO> page(@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
CommonResult<RolePageBO> result = roleService.getRolePage(new RolePageDTO().setName(name).setPageNo(pageNo).setPageSize(pageSize));
return RoleConvert.INSTANCE.convert2(result);
public CommonResult<PageResult<RoleBO>> page(RolePageDTO rolePageDTO) {
return success(roleService.getRolePage(rolePageDTO));
}
@PostMapping("/add")
@ApiOperation(value = "创建角色")
@ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "角色", required = true, example = "系统管理员"),
})
public CommonResult<RoleVO> add(@RequestParam("name") String name) {
RoleAddDTO roleAddDTO = new RoleAddDTO().setName(name);
return RoleConvert.INSTANCE.convert(roleService.addRole(AdminSecurityContextHolder.getContext().getAdminId(), roleAddDTO));
public CommonResult<RoleBO> 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<Boolean> 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<Boolean> 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<Boolean> 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<Boolean> assignResource(@RequestParam("id") Integer id,
@RequestParam(value = "resourceIds", required = false) Set<Integer> resourceIds) {
return roleService.assignResource(AdminSecurityContextHolder.getContext().getAdminId(), id, resourceIds);
public CommonResult<Boolean> assignResource(RoleAssignResourceDTO roleAssignResourceDTO) {
return success(roleService.assignRoleResource(AdminSecurityContextHolder.getContext().getAdminId(), roleAssignResourceDTO));
}
}

View File

@ -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<AdminVO> convert2(CommonResult<AdminBO> result);
@Mappings({})
CommonResult<AdminPageVO> convert(CommonResult<AdminPageBO> result);
@Mappings({})
List<AdminRoleVO> convert(List<RoleBO> roleList);
@Mappings({})
PageResult<AdminVO> convertAdminVOPage(PageResult<AdminBO> page);
List<AdminVO.Role> convertAdminVORoleList(Collection<RoleBO> list);
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<RoleVO> convert(List<RoleBO> roleBO);
@Mappings({})
CommonResult<RoleVO> convert(CommonResult<RoleBO> resourceBO);
@Mappings({})
CommonResult<RolePageVO> convert2(CommonResult<RolePageBO> resourceBO);
}

View File

@ -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<AdminVO> list;
@ApiModelProperty(value = "管理员总数")
private Integer total;
}

View File

@ -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;
}

View File

@ -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<RoleVO> roles;
@ApiModelProperty(value = "角色总数")
private Integer count;
}

View File

@ -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;
}

View File

@ -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<Integer> roleIds;

View File

@ -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;

View File

@ -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;

View File

@ -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<Role> 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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -21,8 +21,8 @@
<!-- Web 相关 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<!-- 工具类相关 -->

View File

@ -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<AdminPageBO> getAdminPage(AdminPageDTO adminPageDTO);
PageResult<AdminBO> getAdminPage(AdminPageDTO adminPageDTO);
AdminBO addAdmin(Integer adminId, AdminAddDTO adminAddDTO);
CommonResult<Boolean> updateAdmin(Integer adminId, AdminUpdateDTO adminUpdateDTO);
Boolean updateAdmin(Integer adminId, AdminUpdateDTO adminUpdateDTO);
CommonResult<Boolean> updateAdminStatus(Integer adminId, Integer updateAdminId,
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
Boolean updateAdminStatus(Integer adminId, AdminUpdateStatusDTO adminUpdateStatusDTO);
CommonResult<Boolean> deleteAdmin(Integer adminId, Integer updateAdminId);
Boolean deleteAdmin(Integer adminId, Integer updateAdminId);
CommonResult<Boolean> assignRole(Integer adminId, Integer updateAdminId, Set<Integer> roleIds);
/**
* 批量查询每个管理员拥有的角色
*
* @param adminIds 管理员编号数组
* @return 每个管理员拥有的角色
*/
Map<Integer, Collection<RoleBO>> getAdminRolesMap(Collection<Integer> adminIds);
/**
* 获得指定管理员拥有的角色数组
*
* @param adminId 指定管理员
* @return 角色编号数组
*/
List<RoleBO> getRoleList(Integer adminId);
/**
* 分配管理员角色
*
* @param adminId 操作管理员编号
* @param adminAssignRoleDTO 分配信息
* @return 是否成功目前默认返回 true
*/
Boolean assignAdminRole(Integer adminId, AdminAssignRoleDTO adminAssignRoleDTO);
}

View File

@ -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;

View File

@ -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;

View File

@ -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<ResourceBO> getResourcesByType(@Nullable Integer type);
CommonResult<ResourceBO> addResource(Integer adminId, ResourceAddDTO resourceAddDTO);
ResourceBO addResource(Integer adminId, ResourceAddDTO resourceAddDTO);
CommonResult<Boolean> updateResource(Integer adminId, ResourceUpdateDTO resourceUpdateDTO);
Boolean updateResource(Integer adminId, ResourceUpdateDTO resourceUpdateDTO);
CommonResult<Boolean> deleteResource(Integer adminId, Integer resourceId);
Boolean deleteResource(Integer adminId, Integer resourceId);
}

View File

@ -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<RolePageBO> getRolePage(RolePageDTO rolePageDTO);
/**
* 获得指定管理员拥有的角色编号数组
*
* @param adminId 指定管理员
* @return 角色编号数组
*/
CommonResult<Set<Integer>> getRoleList(Integer adminId);
PageResult<RoleBO> getRolePage(RolePageDTO rolePageDTO);
/**
* @return 返回角色列表
*/
CommonResult<List<RoleBO>> getRoleList();
List<RoleBO> getRoleList();
CommonResult<RoleBO> addRole(Integer adminId, RoleAddDTO roleAddDTO);
List<RoleBO> getRoleList(Collection<Integer> ids);
CommonResult<Boolean> updateRole(Integer adminId, RoleUpdateDTO roleUpdateDTO);
RoleBO addRole(Integer adminId, RoleAddDTO roleAddDTO);
CommonResult<Boolean> deleteRole(Integer adminId, Integer roleId);
Boolean updateRole(Integer adminId, RoleUpdateDTO roleUpdateDTO);
CommonResult<Boolean> assignResource(Integer adminId, Integer roleId, Set<Integer> resourceIds);
Boolean deleteRole(Integer adminId, Integer roleId);
Boolean assignRoleResource(Integer adminId, RoleAssignResourceDTO roleAssignResourceDTO);
}

View File

@ -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 接口

View File

@ -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;
}

View File

@ -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<RoleBO> roles;
/**
* 总量
*/
private Integer count;
}

View File

@ -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 = "时间戳格式")

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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, "角色不存在"),

View File

@ -10,9 +10,9 @@ public interface ResourceConstants {
*/
Integer TYPE_MENU = 1;
/**
* 类型 - URL
* 类型 - 按钮
*/
Integer TYPE_URL = 2;
Integer TYPE_BUTTON = 2;
/**
* 父资源编号 - 根节点

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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<Integer> roleIds;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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<String> permissions;
}

View File

@ -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<String> permissions;
}

View File

@ -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;

View File

@ -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<Integer> resourceIds;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.admin.api.dto;
package cn.iocoder.mall.admin.api.dto.systemlog;
import lombok.Data;

View File

@ -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;

View File

@ -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 分页插件
}
}

View File

@ -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;

View File

@ -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<AdminBO> convert(List<AdminDO> adminBOs);
@Mappings({
@Mapping(source = "records", target = "list"),
})
PageResult<AdminBO> convert(IPage<AdminDO> page);
}

View File

@ -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;

View File

@ -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;

View File

@ -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);
@Named("translateListFromString")
default List<String> translateListFromString(String picUrls) {
return StringUtil.split(picUrls, ",");
}
}

View File

@ -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<RoleBO> convert(List<RoleDO> roleDOs);
@Mappings({
@Mapping(source = "records", target = "list"),
})
PageResult<RoleBO> convert(IPage<RoleDO> page);
}

View File

@ -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<AdminDO> {
@ -15,12 +17,9 @@ public interface AdminMapper extends BaseMapper<AdminDO> {
return selectOne(new QueryWrapper<AdminDO>().eq("username", username));
}
List<AdminDO> 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<AdminDO> selectPage(AdminPageDTO adminPageDTO) {
return selectPage(new Page<>(adminPageDTO.getPageNo(), adminPageDTO.getPageSize()),
new QueryWrapperX<AdminDO>().likeIfPresent("nickname", adminPageDTO.getNickname()));
}
}

View File

@ -1,16 +1,23 @@
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<AdminRoleDO> {
List<AdminRoleDO> selectByAdminId(@Param("adminId") Integer adminId);
default List<AdminRoleDO> selectListByAdminIds(Collection<Integer> adminIds) {
return selectList(new QueryWrapper<AdminRoleDO>().in("admin_id", adminIds));
}
int updateToDeletedByAdminId(@Param("adminId") Integer adminId);
int updateToDeletedByRoleId(@Param("roleId") Integer roleId);

View File

@ -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<RoleDO> {
void insert(RoleDO roleDO);
default List<RoleDO> selectListByIds(Collection<Integer> ids) {
return selectList(new QueryWrapper<RoleDO>().in("id", ids));
}
int update(RoleDO roleDO);
default List<RoleDO> selectList() {
return selectList(new QueryWrapper<>());
}
RoleDO selectById(@Param("id") Integer id);
List<RoleDO> selectListByNameLike(@Param("name") String name,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByNameLike(@Param("name") String name);
List<RoleDO> selectListByIds(@Param("ids") Set<Integer> ids);
List<RoleDO> selectList();
default IPage<RoleDO> selectPage(RolePageDTO rolePageDTO) {
return selectPage(new Page<>(rolePageDTO.getPageNo(), rolePageDTO.getPageSize()),
new QueryWrapperX<RoleDO>().likeIfPresent("name", rolePageDTO.getName()));
}
}

View File

@ -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;
/**

View File

@ -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 {

View File

@ -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;
/**

View File

@ -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 或者前端组件名
* 当资源类型为URLhandler 配置为后端 URL 举个例子如果有一个创建管理员的表单那么前端界面上的按钮可以根据这个 url 判断是否展示后端接收到该 url 的请求时会判断是否有权限
* 目前当且仅当资源类型为菜单才会生效 handler 配置为界面 URL 或者前端组件名或者前端的路由
*/
private String handler;
/**
* 图表
*
* 目前当且仅当资源类型为菜单才会生效
*/
private String icon;
/**
* 权限标识数组使用逗号分隔
*
* 例如system.admin.add
* 推荐格式为 ${系统}.${模块}.${操作}
*/
private String permissions;
}

View File

@ -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 {

View File

@ -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<AdminPageBO> 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<AdminBO> getAdminPage(AdminPageDTO adminPageDTO) {
IPage<AdminDO> page = adminMapper.selectPage(adminPageDTO);
return AdminConvert.INSTANCE.convert(page);
}
@Override
@ -97,94 +92,121 @@ public class AdminServiceImpl implements AdminService {
}
@Override
public CommonResult<Boolean> 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<Boolean> 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<Boolean> 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<Integer, Collection<RoleBO>> getAdminRolesMap(Collection<Integer> adminIds) {
// 查询管理员拥有的角色关联数据
List<AdminRoleDO> adminRoleList = adminRoleMapper.selectListByAdminIds(adminIds);
if (adminRoleList.isEmpty()) {
return Collections.emptyMap();
}
// 查询角色数据
List<RoleBO> roleList = roleService.getRoleList(CollectionUtil.convertSet(adminRoleList, AdminRoleDO::getRoleId));
Map<Integer, RoleBO> roleMap = CollectionUtil.convertMap(roleList, RoleBO::getId);
// 拼接数据
Multimap<Integer, RoleBO> result = ArrayListMultimap.create();
adminRoleList.forEach(adminRole -> result.put(adminRole.getAdminId(), roleMap.get(adminRole.getRoleId())));
return result.asMap();
}
@Override
public List<RoleBO> getRoleList(Integer adminId) {
// 查询管理员拥有的角色关联数据
List<AdminRoleDO> adminRoleList = adminRoleMapper.selectByAdminId(adminId);
if (adminRoleList.isEmpty()) {
return Collections.emptyList();
}
// 查询角色数据
return roleService.getRoleList(CollectionUtil.convertSet(adminRoleList, AdminRoleDO::getRoleId));
}
@Override
@Transactional
public CommonResult<Boolean> assignRole(Integer adminId, Integer updateAdminId, Set<Integer> 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<RoleDO> 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<RoleDO> 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<AdminRoleDO> adminRoleDOs = roleIds.stream().map(roleId -> {
AdminRoleDO roleResource = new AdminRoleDO().setAdminId(updateAdminId).setRoleId(roleId);
if (!CollectionUtil.isEmpty(adminAssignRoleDTO.getRoleIds())) {
List<AdminRoleDO> 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) {

View File

@ -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;

View File

@ -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;

View File

@ -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<ResourceBO> 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<Boolean> 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<Boolean> 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<ResourceDO> getResources(Set<Integer> 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);
}
}
}

View File

@ -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<RolePageBO> 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<RoleBO> getRolePage(RolePageDTO rolePageDTO) {
IPage<RoleDO> page = roleMapper.selectPage(rolePageDTO);
return RoleConvert.INSTANCE.convert(page);
}
@Override
public CommonResult<Set<Integer>> getRoleList(Integer adminId) {
List<AdminRoleDO> adminRoleDOs = adminRoleMapper.selectByAdminId(adminId);
return CommonResult.success(adminRoleDOs.stream().map(AdminRoleDO::getRoleId).collect(Collectors.toSet()));
}
@Override
public CommonResult<List<RoleBO>> getRoleList() {
public List<RoleBO> getRoleList() {
List<RoleDO> roleList = roleMapper.selectList();
return CommonResult.success(RoleConvert.INSTANCE.convert(roleList));
return RoleConvert.INSTANCE.convert(roleList);
}
@Override
public CommonResult<RoleBO> addRole(Integer adminId, RoleAddDTO roleAddDTO) {
public List<RoleBO> getRoleList(Collection<Integer> ids) {
List<RoleDO> 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<Boolean> 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<Boolean> 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<Boolean> assignResource(Integer adminId, Integer roleId, Set<Integer> resourceIds) {
public Boolean assignRoleResource(Integer adminId, RoleAssignResourceDTO roleAssignResourceDTO) {
Integer roleId = roleAssignResourceDTO.getId();
Set<Integer> 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());
}
// 校验是否有不存在的资源
if (!CollectionUtil.isEmpty(resourceIds)) {
List<ResourceDO> resources = resourceService.getResources(resourceIds);
if (resources.size() != resourceIds.size()) {
return ServiceExceptionUtil.error(AdminErrorCodeEnum.ROLE_ASSIGN_RESOURCE_NOT_EXISTS.getCode());
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ROLE_ASSIGN_RESOURCE_NOT_EXISTS.getCode());
}
}
// TODO 芋艿这里先简单实现即方式是删除老的分配的资源关系然后添加新的分配的资源关系
// 标记角色原资源关系都为删除
roleResourceMapper.updateToDeletedByRoleId(roleId);
// 创建 RoleResourceDO 数组并插入到数据库
if (!resourceIds.isEmpty()) {
if (!CollectionUtil.isEmpty(resourceIds)) {
List<RoleResourceDO> 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<RoleDO> getRoles(Set<Integer> roleIds) {

View File

@ -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;

View File

@ -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

View File

@ -1,65 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.admin.dao.AdminMapper">
<sql id="FIELDS">
id, username, nickname, password, status,
create_time
</sql>
<select id="selectListByNicknameLike" resultType="AdminDO">
SELECT
<include refid="FIELDS" />
FROM admin
<where>
<if test="nickname != null">
nickname LIKE "%"#{nickname}"%"
</if>
AND deleted = 0
</where>
LIMIT #{offset}, #{limit}
</select>
<select id="selectCountByNicknameLike" resultType="Integer">
SELECT
COUNT(1)
FROM admin
<where>
<if test="nickname != null">
nickname LIKE "%"#{nickname}"%"
</if>
AND deleted = 0
</where>
</select>
<select id="selectById" parameterType="Integer" resultType="AdminDO">
SELECT
<include refid="FIELDS" />
FROM admin
WHERE id = #{id}
AND deleted = 0
</select>
<update id="update" parameterType="RoleDO">
UPDATE admin
<set>
<if test="username != null">
, username = #{username}
</if>
<if test="nickname != null">
, nickname = #{nickname}
</if>
<if test="password != null">
, password = #{password}
</if>
<if test="status != null">
, status = #{status}
</if>
<if test="deleted != null">
, deleted = #{deleted}
</if>
</set>
WHERE id = #{id}
</update>
</mapper>

View File

@ -2,14 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.admin.dao.ResourceMapper">
<!--<insert id="insert" parameterType="UserDO" useGeneratedKeys="true" keyProperty="id">-->
<!--INSERT INTO users (-->
<!--id, mobile, create_time-->
<!--) VALUES (-->
<!--#{id}, #{mobile}, #{createTime}-->
<!--)-->
<!--</insert>-->
<sql id="FIELDS">
id, name, type, sort, display_name,
create_time, pid, handler
@ -90,16 +82,6 @@
AND deleted = 0
</select>
<insert id="insert" parameterType="ResourceDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO resource (
name, type, sort, display_name, handler,
pid, create_time, deleted
) VALUES (
#{name}, #{type}, #{sort}, #{displayName}, #{handler},
#{pid}, #{createTime}, #{deleted}
)
</insert>
<update id="update" parameterType="ResourceDO">
UPDATE resource
<set>

Some files were not shown because too many files have changed in this diff Show More