Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
36f62b24
提交
36f62b24
authored
3月 02, 2019
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加管理员模块的增删改查~
上级
ffeb866b
隐藏空白字符变更
内嵌
并排
正在显示
25 个修改的文件
包含
436 行增加
和
34 行删除
+436
-34
AdminController.java
...er/mall/admin/application/controller/AdminController.java
+54
-5
PassportController.java
...mall/admin/application/controller/PassportController.java
+1
-1
ResourceController.java
...mall/admin/application/controller/ResourceController.java
+1
-1
RoleController.java
...der/mall/admin/application/controller/RoleController.java
+1
-1
AdminConvert.java
.../iocoder/mall/admin/application/convert/AdminConvert.java
+3
-0
application.yaml
admin/admin-application/src/main/resources/application.yaml
+4
-2
AdminService.java
...src/main/java/cn/iocoder/mall/admin/api/AdminService.java
+12
-0
OAuth2Service.java
...rc/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java
+0
-3
AdminErrorCodeEnum.java
...n/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java
+3
-0
AdminAddDTO.java
.../main/java/cn/iocoder/mall/admin/api/dto/AdminAddDTO.java
+53
-0
AdminUpdateDTO.java
...in/java/cn/iocoder/mall/admin/api/dto/AdminUpdateDTO.java
+68
-0
AdminConvert.java
...main/java/cn/iocoder/mall/admin/convert/AdminConvert.java
+8
-0
AdminMapper.java
.../src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java
+7
-0
AdminRoleMapper.java
.../main/java/cn/iocoder/mall/admin/dao/AdminRoleMapper.java
+5
-0
OAuth2AccessTokenMapper.java
...va/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java
+5
-1
OAuth2RefreshTokenMapper.java
...a/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java
+4
-0
AdminRoleDO.java
...in/java/cn/iocoder/mall/admin/dataobject/AdminRoleDO.java
+2
-18
AdminServiceImpl.java
.../java/cn/iocoder/mall/admin/service/AdminServiceImpl.java
+106
-2
OAuth2ServiceImpl.java
...java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java
+15
-0
ResourceServiceImpl.java
...va/cn/iocoder/mall/admin/service/ResourceServiceImpl.java
+2
-0
RoleServiceImpl.java
...n/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java
+10
-0
AdminMapper.xml
...in-service-impl/src/main/resources/mapper/AdminMapper.xml
+41
-0
AdminRoleMapper.xml
...ervice-impl/src/main/resources/mapper/AdminRoleMapper.xml
+15
-0
OAuth2AccessTokenMapper.xml
...mpl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml
+8
-0
OAuth2RefreshTokenMapper.xml
...pl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml
+8
-0
没有找到文件。
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/AdminController.java
浏览文件 @
36f62b24
...
...
@@ -6,27 +6,27 @@ import cn.iocoder.mall.admin.api.ResourceService;
import
cn.iocoder.mall.admin.api.bo.AdminPageBO
;
import
cn.iocoder.mall.admin.api.bo.ResourceBO
;
import
cn.iocoder.mall.admin.api.constant.ResourceConstants
;
import
cn.iocoder.mall.admin.api.dto.AdminAddDTO
;
import
cn.iocoder.mall.admin.api.dto.AdminPageDTO
;
import
cn.iocoder.mall.admin.api.dto.AdminUpdateDTO
;
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.AdminVO
;
import
cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder
;
import
com.alibaba.dubbo.config.annotation.Reference
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
"admin/admin"
)
@RequestMapping
(
"admin
s
/admin"
)
@Api
(
"管理员模块"
)
public
class
AdminController
{
...
...
@@ -88,4 +88,52 @@ public class AdminController {
return
AdminConvert
.
INSTANCE
.
convert
(
result
);
}
@PostMapping
(
"/add"
)
@ApiOperation
(
value
=
"创建管理员"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"username"
,
value
=
"账号"
,
required
=
true
,
example
=
"15601691300"
),
@ApiImplicitParam
(
name
=
"nickname"
,
value
=
"昵称"
,
required
=
true
,
example
=
"小王"
),
@ApiImplicitParam
(
name
=
"password"
,
value
=
"密码"
,
required
=
true
,
example
=
"buzhidao"
),
})
public
CommonResult
<
AdminVO
>
add
(
@RequestParam
(
"username"
)
String
username
,
@RequestParam
(
"nickname"
)
String
nickname
,
@RequestParam
(
"password"
)
String
password
)
{
AdminAddDTO
adminAddDTO
=
new
AdminAddDTO
().
setUsername
(
username
).
setNickname
(
nickname
).
setPassword
(
password
);
return
AdminConvert
.
INSTANCE
.
convert2
(
adminService
.
addAdmin
(
AdminSecurityContextHolder
.
getContext
().
getAdminId
(),
adminAddDTO
));
}
@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
=
"密码"
,
required
=
true
,
example
=
"buzhidao"
),
})
public
CommonResult
<
Boolean
>
update
(
@RequestParam
(
"id"
)
Integer
id
,
@RequestParam
(
"username"
)
String
username
,
@RequestParam
(
"nickname"
)
String
nickname
,
@RequestParam
(
"password"
)
String
password
)
{
AdminUpdateDTO
adminUpdateDTO
=
new
AdminUpdateDTO
().
setId
(
id
).
setUsername
(
username
).
setNickname
(
nickname
).
setPassword
(
password
);
return
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
);
}
@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
);
}
}
\ No newline at end of file
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/PassportController.java
浏览文件 @
36f62b24
...
...
@@ -16,7 +16,7 @@ import io.swagger.annotations.ApiOperation;
import
org.springframework.web.bind.annotation.*
;
@RestController
@RequestMapping
(
"admin/passport"
)
@RequestMapping
(
"admin
s
/passport"
)
@Api
(
"Admin Passport 模块"
)
public
class
PassportController
{
...
...
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/ResourceController.java
浏览文件 @
36f62b24
...
...
@@ -24,7 +24,7 @@ import java.util.Map;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
"admin/resource"
)
@RequestMapping
(
"admin
s
/resource"
)
@Api
(
"资源模块"
)
public
class
ResourceController
{
...
...
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/RoleController.java
浏览文件 @
36f62b24
...
...
@@ -25,7 +25,7 @@ import java.util.*;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
"admin/role"
)
@RequestMapping
(
"admin
s
/role"
)
public
class
RoleController
{
@Reference
(
validation
=
"true"
)
...
...
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java
浏览文件 @
36f62b24
...
...
@@ -22,6 +22,9 @@ public interface AdminConvert {
@Mappings
({})
AdminVO
convert
(
AdminBO
adminBO
);
@Mappings
({})
CommonResult
<
AdminVO
>
convert2
(
CommonResult
<
AdminBO
>
result
);
@Mappings
({})
CommonResult
<
AdminPageVO
>
convert
(
CommonResult
<
AdminPageBO
>
result
);
...
...
admin/admin-application/src/main/resources/application.yaml
浏览文件 @
36f62b24
...
...
@@ -4,4 +4,6 @@ spring:
# server
server
:
port
:
18083
\ No newline at end of file
port
:
18083
servlet
:
context-path
:
/admin-api/
\ No newline at end of file
admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java
浏览文件 @
36f62b24
package
cn
.
iocoder
.
mall
.
admin
.
api
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.admin.api.bo.AdminBO
;
import
cn.iocoder.mall.admin.api.bo.AdminPageBO
;
import
cn.iocoder.mall.admin.api.dto.AdminAddDTO
;
import
cn.iocoder.mall.admin.api.dto.AdminPageDTO
;
import
cn.iocoder.mall.admin.api.dto.AdminUpdateDTO
;
public
interface
AdminService
{
CommonResult
<
AdminPageBO
>
getAdminPage
(
AdminPageDTO
adminPageDTO
);
CommonResult
<
AdminBO
>
addAdmin
(
Integer
adminId
,
AdminAddDTO
adminAddDTO
);
CommonResult
<
Boolean
>
updateAdmin
(
Integer
adminId
,
AdminUpdateDTO
adminUpdateDTO
);
CommonResult
<
Boolean
>
updateAdminStatus
(
Integer
adminId
,
Integer
updateAdminId
,
Integer
status
);
CommonResult
<
Boolean
>
deleteAdmin
(
Integer
adminId
,
Integer
updateAdminId
);
}
\ No newline at end of file
admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java
浏览文件 @
36f62b24
...
...
@@ -30,6 +30,4 @@ public interface OAuth2Service {
// TODO @see 刷新 token
// TODO @see 移除 token
}
\ No newline at end of file
admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java
浏览文件 @
36f62b24
...
...
@@ -24,6 +24,9 @@ public enum AdminErrorCodeEnum {
ADMIN_USERNAME_NOT_REGISTERED
(
1002002000
,
"账号不存在"
),
ADMIN_PASSWORD_ERROR
(
1002002001
,
"密码不正确"
),
ADMIN_IS_DISABLE
(
1002002002
,
"账号被禁用"
),
ADMIN_USERNAME_EXISTS
(
1002002002
,
"账号已经存在"
),
ADMIN_STATUS_EQUALS
(
1002002003
,
"账号已经是该状态"
),
ADMIN_DELETE_ONLY_DISABLE
(
1002002004
,
"只有关闭的账号才可以删除"
),
// ========== 资源模块 1002003000 ==========
RESOURCE_NAME_DUPLICATE
(
1002003000
,
"已经存在该名字的资源"
),
...
...
admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminAddDTO.java
0 → 100644
浏览文件 @
36f62b24
package
cn
.
iocoder
.
mall
.
admin
.
api
.
dto
;
import
javax.validation.constraints.NotEmpty
;
/**
* 管理员添加 DTO
*/
public
class
AdminAddDTO
{
/**
* 登陆账号
*/
@NotEmpty
(
message
=
"登陆账号不能为空"
)
private
String
username
;
/**
* 昵称
*/
@NotEmpty
(
message
=
"昵称不能为空"
)
private
String
nickname
;
/**
* 密码
*/
@NotEmpty
(
message
=
"密码不能为空"
)
private
String
password
;
public
String
getUsername
()
{
return
username
;
}
public
AdminAddDTO
setUsername
(
String
username
)
{
this
.
username
=
username
;
return
this
;
}
public
String
getNickname
()
{
return
nickname
;
}
public
AdminAddDTO
setNickname
(
String
nickname
)
{
this
.
nickname
=
nickname
;
return
this
;
}
public
String
getPassword
()
{
return
password
;
}
public
AdminAddDTO
setPassword
(
String
password
)
{
this
.
password
=
password
;
return
this
;
}
}
\ No newline at end of file
admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminUpdateDTO.java
0 → 100644
浏览文件 @
36f62b24
package
cn
.
iocoder
.
mall
.
admin
.
api
.
dto
;
import
javax.validation.constraints.NotEmpty
;
import
javax.validation.constraints.NotNull
;
/**
* 管理员更新 DTO
*/
public
class
AdminUpdateDTO
{
/**
* 管理员编号
*/
@NotNull
(
message
=
"管理员编号不能为空"
)
private
Integer
id
;
/**
* 登陆账号
*/
@NotEmpty
(
message
=
"登陆账号不能为空"
)
private
String
username
;
/**
* 昵称
*/
@NotEmpty
(
message
=
"昵称不能为空"
)
private
String
nickname
;
/**
* 密码
*/
@NotEmpty
(
message
=
"密码不能为空"
)
private
String
password
;
public
String
getUsername
()
{
return
username
;
}
public
AdminUpdateDTO
setUsername
(
String
username
)
{
this
.
username
=
username
;
return
this
;
}
public
String
getNickname
()
{
return
nickname
;
}
public
AdminUpdateDTO
setNickname
(
String
nickname
)
{
this
.
nickname
=
nickname
;
return
this
;
}
public
String
getPassword
()
{
return
password
;
}
public
AdminUpdateDTO
setPassword
(
String
password
)
{
this
.
password
=
password
;
return
this
;
}
public
Integer
getId
()
{
return
id
;
}
public
AdminUpdateDTO
setId
(
Integer
id
)
{
this
.
id
=
id
;
return
this
;
}
}
\ No newline at end of file
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java
浏览文件 @
36f62b24
package
cn
.
iocoder
.
mall
.
admin
.
convert
;
import
cn.iocoder.mall.admin.api.bo.AdminBO
;
import
cn.iocoder.mall.admin.api.dto.AdminAddDTO
;
import
cn.iocoder.mall.admin.api.dto.AdminUpdateDTO
;
import
cn.iocoder.mall.admin.dataobject.AdminDO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mappings
;
...
...
@@ -16,6 +18,12 @@ public interface AdminConvert {
@Mappings
({})
AdminBO
convert
(
AdminDO
adminDO
);
@Mappings
({})
AdminDO
convert
(
AdminAddDTO
adminAddDTO
);
@Mappings
({})
AdminDO
convert
(
AdminUpdateDTO
adminUpdateDTO
);
@Mappings
({})
List
<
AdminBO
>
convert
(
List
<
AdminDO
>
adminBOs
);
...
...
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java
浏览文件 @
36f62b24
...
...
@@ -9,6 +9,8 @@ import java.util.List;
@Repository
public
interface
AdminMapper
{
AdminDO
selectById
(
@Param
(
"id"
)
Integer
id
);
AdminDO
selectByUsername
(
@Param
(
"username"
)
String
username
);
List
<
AdminDO
>
selectListByNicknameLike
(
@Param
(
"nickname"
)
String
nickname
,
...
...
@@ -17,4 +19,8 @@ public interface AdminMapper {
Integer
selectCountByNicknameLike
(
@Param
(
"nickname"
)
String
nickname
);
void
insert
(
AdminDO
admin
);
int
update
(
AdminDO
admin
);
}
\ No newline at end of file
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminRoleMapper.java
浏览文件 @
36f62b24
...
...
@@ -11,4 +11,8 @@ public interface AdminRoleMapper {
List
<
AdminRoleDO
>
selectByAdminId
(
@Param
(
"adminId"
)
Integer
adminId
);
int
updateToDeletedByAdminId
(
@Param
(
"adminId"
)
Integer
adminId
);
int
updateToDeletedByRoleId
(
@Param
(
"roleId"
)
Integer
roleId
);
}
\ No newline at end of file
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java
浏览文件 @
36f62b24
package
cn
.
iocoder
.
mall
.
admin
.
dao
;
import
cn.iocoder.mall.admin.dataobject.OAuth2AccessTokenDO
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.stereotype.Repository
;
@Repository
...
...
@@ -8,6 +9,8 @@ public interface OAuth2AccessTokenMapper {
void
insert
(
OAuth2AccessTokenDO
entity
);
OAuth2AccessTokenDO
selectByTokenId
(
String
tokenId
);
OAuth2AccessTokenDO
selectByTokenId
(
@Param
(
"id"
)
String
id
);
int
updateToInvalidByAdminId
(
@Param
(
"adminId"
)
Integer
adminId
);
}
\ No newline at end of file
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java
浏览文件 @
36f62b24
package
cn
.
iocoder
.
mall
.
admin
.
dao
;
import
cn.iocoder.mall.admin.dataobject.OAuth2RefreshTokenDO
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.stereotype.Repository
;
@Repository
...
...
@@ -8,4 +9,6 @@ public interface OAuth2RefreshTokenMapper {
void
insert
(
OAuth2RefreshTokenDO
entity
);
int
updateToInvalidByAdminId
(
@Param
(
"adminId"
)
Integer
adminId
);
}
\ No newline at end of file
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminRoleDO.java
浏览文件 @
36f62b24
package
cn
.
iocoder
.
mall
.
admin
.
dataobject
;
import
java.util.Date
;
import
cn.iocoder.common.framework.dataobject.BaseDO
;
/**
* {@link AdminDO} 和 {@link RoleDO} 的关联表
*/
public
class
AdminRoleDO
{
public
class
AdminRoleDO
extends
BaseDO
{
/**
* 编号
...
...
@@ -19,12 +19,6 @@ public class AdminRoleDO {
* 角色编号(外键:{@link RoleDO}
*/
private
Integer
roleId
;
/**
* 创建时间
*/
private
Date
createTime
;
// TODO 芋艿 删除状态
public
Integer
getId
()
{
return
id
;
...
...
@@ -53,13 +47,4 @@ public class AdminRoleDO {
return
this
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
AdminRoleDO
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
return
this
;
}
}
\ No newline at end of file
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java
浏览文件 @
36f62b24
package
cn
.
iocoder
.
mall
.
admin
.
service
;
import
cn.iocoder.common.framework.constant.SysErrorCodeEnum
;
import
cn.iocoder.common.framework.dataobject.BaseDO
;
import
cn.iocoder.common.framework.util.ServiceExceptionUtil
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.admin.api.AdminService
;
import
cn.iocoder.mall.admin.api.bo.AdminBO
;
import
cn.iocoder.mall.admin.api.bo.AdminPageBO
;
import
cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum
;
import
cn.iocoder.mall.admin.api.dto.AdminAddDTO
;
import
cn.iocoder.mall.admin.api.dto.AdminPageDTO
;
import
cn.iocoder.mall.admin.api.dto.AdminUpdateDTO
;
import
cn.iocoder.mall.admin.convert.AdminConvert
;
import
cn.iocoder.mall.admin.dataobject.AdminDO
;
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
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
;
@Service
...
...
@@ -25,6 +32,8 @@ public class AdminServiceImpl implements AdminService {
private
AdminMapper
adminMapper
;
@Autowired
private
AdminRoleMapper
adminRoleMapper
;
@Autowired
private
OAuth2ServiceImpl
oAuth2Service
;
public
CommonResult
<
AdminDO
>
validAdmin
(
String
username
,
String
password
)
{
AdminDO
admin
=
adminMapper
.
selectByUsername
(
username
);
...
...
@@ -33,7 +42,7 @@ public class AdminServiceImpl implements AdminService {
return
ServiceExceptionUtil
.
error
(
AdminErrorCodeEnum
.
ADMIN_USERNAME_NOT_REGISTERED
.
getCode
());
}
// 密码不正确
if
(
DigestUtils
.
md5DigestAsHex
(
password
.
getBytes
()
).
equals
(
admin
.
getPassword
()))
{
if
(
encodePassword
(
password
).
equals
(
admin
.
getPassword
()))
{
return
ServiceExceptionUtil
.
error
(
AdminErrorCodeEnum
.
ADMIN_PASSWORD_ERROR
.
getCode
());
}
// 账号被禁用
...
...
@@ -62,4 +71,98 @@ public class AdminServiceImpl implements AdminService {
return
CommonResult
.
success
(
adminPage
);
}
@Override
public
CommonResult
<
AdminBO
>
addAdmin
(
Integer
adminId
,
AdminAddDTO
adminAddDTO
)
{
// 校验账号唯一
if
(
adminMapper
.
selectByUsername
(
adminAddDTO
.
getUsername
())
!=
null
)
{
return
ServiceExceptionUtil
.
error
(
AdminErrorCodeEnum
.
ADMIN_USERNAME_EXISTS
.
getCode
());
}
// 保存到数据库
AdminDO
admin
=
AdminConvert
.
INSTANCE
.
convert
(
adminAddDTO
)
.
setPassword
(
encodePassword
(
adminAddDTO
.
getPassword
()))
// 加密密码
.
setStatus
(
AdminDO
.
STATUS_ENABLE
);
admin
.
setCreateTime
(
new
Date
()).
setDeleted
(
BaseDO
.
DELETED_NO
);
adminMapper
.
insert
(
admin
);
// TODO 插入操作日志
// 返回成功
return
CommonResult
.
success
(
AdminConvert
.
INSTANCE
.
convert
(
admin
));
}
@Override
public
CommonResult
<
Boolean
>
updateAdmin
(
Integer
adminId
,
AdminUpdateDTO
adminUpdateDTO
)
{
// 校验账号存在
if
(
adminMapper
.
selectById
(
adminUpdateDTO
.
getId
())
==
null
)
{
return
ServiceExceptionUtil
.
error
(
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
());
}
// 更新到数据库
AdminDO
updateAdmin
=
AdminConvert
.
INSTANCE
.
convert
(
adminUpdateDTO
);
adminMapper
.
update
(
updateAdmin
);
// TODO 插入操作日志
// 返回成功
return
CommonResult
.
success
(
true
);
}
@Override
@Transactional
public
CommonResult
<
Boolean
>
updateAdminStatus
(
Integer
adminId
,
Integer
updateAdminId
,
Integer
status
)
{
// 校验参数
if
(!
isValidStatus
(
status
))
{
return
CommonResult
.
error
(
SysErrorCodeEnum
.
VALIDATION_REQUEST_PARAM_ERROR
.
getCode
(),
"变更状态必须是开启(1)或关闭(2)"
);
// TODO 有点搓
}
// 校验账号存在
AdminDO
admin
=
adminMapper
.
selectById
(
updateAdminId
);
if
(
admin
==
null
)
{
return
ServiceExceptionUtil
.
error
(
AdminErrorCodeEnum
.
ADMIN_USERNAME_NOT_REGISTERED
.
getCode
());
}
// 如果状态相同,则返回错误
if
(
status
.
equals
(
admin
.
getStatus
()))
{
return
ServiceExceptionUtil
.
error
(
AdminErrorCodeEnum
.
ADMIN_STATUS_EQUALS
.
getCode
());
}
// 更新管理员状态
AdminDO
updateAdmin
=
new
AdminDO
().
setId
(
updateAdminId
).
setStatus
(
status
);
adminMapper
.
update
(
updateAdmin
);
// 如果是关闭管理员,则标记 token 失效。否则,管理员还可以继续蹦跶
if
(
AdminDO
.
STATUS_DISABLE
.
equals
(
status
))
{
oAuth2Service
.
removeToken
(
updateAdminId
);
}
// TODO 插入操作日志
// 返回成功
return
CommonResult
.
success
(
true
);
}
@Override
@Transactional
public
CommonResult
<
Boolean
>
deleteAdmin
(
Integer
adminId
,
Integer
updateAdminId
)
{
// 校验账号存在
AdminDO
admin
=
adminMapper
.
selectById
(
updateAdminId
);
if
(
admin
==
null
)
{
return
ServiceExceptionUtil
.
error
(
AdminErrorCodeEnum
.
ADMIN_USERNAME_NOT_REGISTERED
.
getCode
());
}
if
(
AdminDO
.
STATUS_ENABLE
.
equals
(
admin
.
getStatus
()))
{
return
ServiceExceptionUtil
.
error
(
AdminErrorCodeEnum
.
ADMIN_DELETE_ONLY_DISABLE
.
getCode
());
}
// 只有禁用的账号才可以删除
AdminDO
updateAdmin
=
new
AdminDO
().
setId
(
updateAdminId
);
updateAdmin
.
setDeleted
(
BaseDO
.
DELETED_YES
);
adminMapper
.
update
(
updateAdmin
);
// 标记删除 AdminRole
adminRoleMapper
.
updateToDeletedByAdminId
(
updateAdminId
);
// TODO 插入操作日志
// 返回成功
return
CommonResult
.
success
(
true
);
}
private
String
encodePassword
(
String
password
)
{
return
DigestUtils
.
md5DigestAsHex
(
password
.
getBytes
());
}
private
boolean
isValidStatus
(
Integer
status
)
{
return
AdminDO
.
STATUS_ENABLE
.
equals
(
status
)
||
AdminDO
.
STATUS_DISABLE
.
equals
(
status
);
}
}
\ No newline at end of file
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java
浏览文件 @
36f62b24
...
...
@@ -13,6 +13,7 @@ import cn.iocoder.mall.admin.dataobject.*;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -46,6 +47,7 @@ public class OAuth2ServiceImpl implements OAuth2Service {
private
ResourceServiceImpl
resourceService
;
@Override
@Transactional
public
CommonResult
<
OAuth2AccessTokenBO
>
getAccessToken
(
String
username
,
String
password
)
{
CommonResult
<
AdminDO
>
adminResult
=
adminService
.
validAdmin
(
username
,
password
);
// 校验失败,返回错误结果
...
...
@@ -79,6 +81,19 @@ public class OAuth2ServiceImpl implements OAuth2Service {
return
CommonResult
.
success
(
OAuth2Convert
.
INSTANCE
.
convertToAuthentication
(
accessTokenDO
,
adminRoleDOs
));
}
/**
* 移除管理员对应的 Token
*
* @param adminId 管理员编号
*/
@Transactional
public
void
removeToken
(
Integer
adminId
)
{
// 设置 access token 失效
oauth2AccessTokenMapper
.
updateToInvalidByAdminId
(
adminId
);
// 设置 refresh token 失效
oauth2RefreshTokenMapper
.
updateToInvalidByAdminId
(
adminId
);
}
@Override
public
CommonResult
<
Boolean
>
checkPermission
(
Integer
adminId
,
Set
<
Integer
>
roleIds
,
String
url
)
{
// 如果未配置该资源,说明无需权限控制。
...
...
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/ResourceServiceImpl.java
浏览文件 @
36f62b24
...
...
@@ -16,6 +16,7 @@ import cn.iocoder.mall.admin.dao.RoleResourceMapper;
import
cn.iocoder.mall.admin.dataobject.ResourceDO
;
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
;
...
...
@@ -116,6 +117,7 @@ public class ResourceServiceImpl implements ResourceService {
}
@Override
@Transactional
public
CommonResult
<
Boolean
>
deleteResource
(
Integer
adminId
,
Integer
resourceId
)
{
// 校验更新的资源是否存在
if
(
resourceMapper
.
selectById
(
resourceId
)
==
null
)
{
...
...
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java
浏览文件 @
36f62b24
...
...
@@ -11,6 +11,7 @@ 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.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.ResourceDO
;
...
...
@@ -18,6 +19,7 @@ import cn.iocoder.mall.admin.dataobject.RoleDO;
import
cn.iocoder.mall.admin.dataobject.RoleResourceDO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -31,6 +33,8 @@ public class RoleServiceImpl implements RoleService {
@Autowired
private
RoleResourceMapper
roleResourceMapper
;
@Autowired
private
AdminRoleMapper
adminRoleMapper
;
@Autowired
private
RoleMapper
roleMapper
;
@Autowired
...
...
@@ -84,6 +88,7 @@ public class RoleServiceImpl implements RoleService {
}
@Override
@Transactional
public
CommonResult
<
Boolean
>
deleteRole
(
Integer
adminId
,
Integer
roleId
)
{
// 校验角色是否存在
if
(
roleMapper
.
selectById
(
roleId
)
==
null
)
{
...
...
@@ -93,12 +98,17 @@ public class RoleServiceImpl implements RoleService {
RoleDO
roleDO
=
new
RoleDO
().
setId
(
roleId
);
roleDO
.
setDeleted
(
RoleDO
.
DELETED_YES
);
roleMapper
.
update
(
roleDO
);
// 标记删除 RoleResource
roleResourceMapper
.
updateToDeletedByRoleId
(
roleId
);
// 标记删除 AdminRole
adminRoleMapper
.
updateToDeletedByRoleId
(
roleId
);
// TODO 插入操作日志
// 返回成功
return
CommonResult
.
success
(
true
);
}
@Override
@Transactional
public
CommonResult
<
Boolean
>
assignResource
(
Integer
adminId
,
Integer
roleId
,
Set
<
Integer
>
resourceIds
)
{
// 校验角色是否存在
if
(
roleMapper
.
selectById
(
roleId
)
==
null
)
{
...
...
admin/admin-service-impl/src/main/resources/mapper/AdminMapper.xml
浏览文件 @
36f62b24
...
...
@@ -40,4 +40,44 @@
</where>
</select>
<insert
id=
"insert"
parameterType=
"AdminDO"
useGeneratedKeys=
"true"
keyColumn=
"id"
keyProperty=
"id"
>
INSERT INTO admin (
username, nickname, password, status,
create_time, deleted
) VALUES (
#{username}, #{nickname}, #{password}, #{status},
#{createTime}, #{deleted}
)
</insert>
<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>
\ No newline at end of file
admin/admin-service-impl/src/main/resources/mapper/AdminRoleMapper.xml
浏览文件 @
36f62b24
...
...
@@ -18,4 +18,18 @@
AND a.id = ar.admin_id
</select>
<update
id=
"updateToDeletedByAdminId"
parameterType=
"Integer"
>
UPDATE admin_role
SET deleted = 1
WHERE admin_id = #{adminId}
AND deleted = 0
</update>
<update
id=
"updateToDeletedByRoleId"
parameterType=
"Integer"
>
UPDATE admin_role
SET deleted = 1
WHERE role_id = #{roleId}
AND deleted = 0
</update>
</mapper>
\ No newline at end of file
admin/admin-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml
浏览文件 @
36f62b24
...
...
@@ -19,4 +19,11 @@
WHERE id = #{id}
</select>
<update
id=
"updateToInvalidByAdminId"
parameterType=
"Integer"
>
UPDATE oauth2_access_token
SET valid = 0
WHERE admin_id = #{adminId}
AND valid = 1
</update>
</mapper>
\ No newline at end of file
admin/admin-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml
浏览文件 @
36f62b24
...
...
@@ -10,4 +10,11 @@
)
</insert>
<update
id=
"updateToInvalidByAdminId"
parameterType=
"Integer"
>
UPDATE oauth2_refresh_token
SET valid = 0
WHERE admin_id = #{adminId}
AND valid = 1
</update>
</mapper>
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论