Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
fa0af318
Commit
fa0af318
authored
Mar 22, 2020
by
macro
Browse files
添加redis缓存支持
parent
944a305b
Changes
27
Hide whitespace changes
Inline
Side-by-side
mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminServiceImpl.java
View file @
fa0af318
...
...
@@ -14,6 +14,7 @@ import com.macro.mall.mapper.UmsAdminPermissionRelationMapper;
import
com.macro.mall.mapper.UmsAdminRoleRelationMapper
;
import
com.macro.mall.model.*
;
import
com.macro.mall.security.util.JwtTokenUtil
;
import
com.macro.mall.service.UmsAdminCacheService
;
import
com.macro.mall.service.UmsAdminService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -61,14 +62,20 @@ public class UmsAdminServiceImpl implements UmsAdminService {
private
UmsAdminPermissionRelationDao
adminPermissionRelationDao
;
@Autowired
private
UmsAdminLoginLogMapper
loginLogMapper
;
@Autowired
private
UmsAdminCacheService
adminCacheService
;
@Override
public
UmsAdmin
getAdminByUsername
(
String
username
)
{
UmsAdmin
admin
=
adminCacheService
.
getAdmin
(
username
);
if
(
admin
!=
null
)
return
admin
;
UmsAdminExample
example
=
new
UmsAdminExample
();
example
.
createCriteria
().
andUsernameEqualTo
(
username
);
List
<
UmsAdmin
>
adminList
=
adminMapper
.
selectByExample
(
example
);
if
(
adminList
!=
null
&&
adminList
.
size
()
>
0
)
{
return
adminList
.
get
(
0
);
admin
=
adminList
.
get
(
0
);
adminCacheService
.
setAdmin
(
admin
);
return
admin
;
}
return
null
;
}
...
...
@@ -119,6 +126,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
*/
private
void
insertLoginLog
(
String
username
)
{
UmsAdmin
admin
=
getAdminByUsername
(
username
);
if
(
admin
==
null
)
return
;
UmsAdminLoginLog
loginLog
=
new
UmsAdminLoginLog
();
loginLog
.
setAdminId
(
admin
.
getId
());
loginLog
.
setCreateTime
(
new
Date
());
...
...
@@ -176,12 +184,17 @@ public class UmsAdminServiceImpl implements UmsAdminService {
admin
.
setPassword
(
passwordEncoder
.
encode
(
admin
.
getPassword
()));
}
}
return
adminMapper
.
updateByPrimaryKeySelective
(
admin
);
int
count
=
adminMapper
.
updateByPrimaryKeySelective
(
admin
);
adminCacheService
.
delAdmin
(
id
);
return
count
;
}
@Override
public
int
delete
(
Long
id
)
{
return
adminMapper
.
deleteByPrimaryKey
(
id
);
adminCacheService
.
delAdmin
(
id
);
int
count
=
adminMapper
.
deleteByPrimaryKey
(
id
);
adminCacheService
.
delResourceList
(
id
);
return
count
;
}
@Override
...
...
@@ -202,6 +215,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
}
adminRoleRelationDao
.
insertList
(
list
);
}
adminCacheService
.
delResourceList
(
adminId
);
return
count
;
}
...
...
@@ -212,7 +226,15 @@ public class UmsAdminServiceImpl implements UmsAdminService {
@Override
public
List
<
UmsResource
>
getResourceList
(
Long
adminId
)
{
return
adminRoleRelationDao
.
getResourceList
(
adminId
);
List
<
UmsResource
>
resourceList
=
adminCacheService
.
getResourceList
(
adminId
);
if
(
CollUtil
.
isNotEmpty
(
resourceList
)){
return
resourceList
;
}
resourceList
=
adminRoleRelationDao
.
getResourceList
(
adminId
);
if
(
CollUtil
.
isNotEmpty
(
resourceList
)){
adminCacheService
.
setResourceList
(
adminId
,
resourceList
);
}
return
resourceList
;
}
@Override
...
...
@@ -276,6 +298,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
}
umsAdmin
.
setPassword
(
passwordEncoder
.
encode
(
param
.
getNewPassword
()));
adminMapper
.
updateByPrimaryKey
(
umsAdmin
);
adminCacheService
.
delAdmin
(
umsAdmin
.
getId
());
return
1
;
}
...
...
mall-admin/src/main/java/com/macro/mall/service/impl/UmsResourceServiceImpl.java
View file @
fa0af318
...
...
@@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
import
com.macro.mall.mapper.UmsResourceMapper
;
import
com.macro.mall.model.UmsResource
;
import
com.macro.mall.model.UmsResourceExample
;
import
com.macro.mall.service.UmsAdminCacheService
;
import
com.macro.mall.service.UmsResourceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -20,6 +21,8 @@ import java.util.List;
public
class
UmsResourceServiceImpl
implements
UmsResourceService
{
@Autowired
private
UmsResourceMapper
resourceMapper
;
@Autowired
private
UmsAdminCacheService
adminCacheService
;
@Override
public
int
create
(
UmsResource
umsResource
)
{
umsResource
.
setCreateTime
(
new
Date
());
...
...
@@ -29,7 +32,9 @@ public class UmsResourceServiceImpl implements UmsResourceService {
@Override
public
int
update
(
Long
id
,
UmsResource
umsResource
)
{
umsResource
.
setId
(
id
);
return
resourceMapper
.
updateByPrimaryKeySelective
(
umsResource
);
int
count
=
resourceMapper
.
updateByPrimaryKeySelective
(
umsResource
);
adminCacheService
.
delResourceListByResource
(
id
);
return
count
;
}
@Override
...
...
@@ -39,7 +44,9 @@ public class UmsResourceServiceImpl implements UmsResourceService {
@Override
public
int
delete
(
Long
id
)
{
return
resourceMapper
.
deleteByPrimaryKey
(
id
);
int
count
=
resourceMapper
.
deleteByPrimaryKey
(
id
);
adminCacheService
.
delResourceListByResource
(
id
);
return
count
;
}
@Override
...
...
mall-admin/src/main/java/com/macro/mall/service/impl/UmsRoleServiceImpl.java
View file @
fa0af318
...
...
@@ -8,6 +8,7 @@ import com.macro.mall.mapper.UmsRoleMenuRelationMapper;
import
com.macro.mall.mapper.UmsRolePermissionRelationMapper
;
import
com.macro.mall.mapper.UmsRoleResourceRelationMapper
;
import
com.macro.mall.model.*
;
import
com.macro.mall.service.UmsAdminCacheService
;
import
com.macro.mall.service.UmsRoleService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -35,6 +36,8 @@ public class UmsRoleServiceImpl implements UmsRoleService {
private
UmsRolePermissionRelationDao
rolePermissionRelationDao
;
@Autowired
private
UmsRoleDao
roleDao
;
@Autowired
private
UmsAdminCacheService
adminCacheService
;
@Override
public
int
create
(
UmsRole
role
)
{
role
.
setCreateTime
(
new
Date
());
...
...
@@ -53,7 +56,9 @@ public class UmsRoleServiceImpl implements UmsRoleService {
public
int
delete
(
List
<
Long
>
ids
)
{
UmsRoleExample
example
=
new
UmsRoleExample
();
example
.
createCriteria
().
andIdIn
(
ids
);
return
roleMapper
.
deleteByExample
(
example
);
int
count
=
roleMapper
.
deleteByExample
(
example
);
adminCacheService
.
delResourceListByRoleIds
(
ids
);
return
count
;
}
@Override
...
...
@@ -137,6 +142,7 @@ public class UmsRoleServiceImpl implements UmsRoleService {
relation
.
setResourceId
(
resourceId
);
roleResourceRelationMapper
.
insert
(
relation
);
}
adminCacheService
.
delResourceListByRole
(
roleId
);
return
resourceIds
.
size
();
}
}
mall-admin/src/main/resources/application-dev.yml
View file @
fa0af318
...
...
@@ -11,4 +11,10 @@ spring:
exclusions
:
"
*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
#不统计这些请求数据
stat-view-servlet
:
#访问监控网页的登录用户名和密码
login-username
:
druid
login-password
:
druid
\ No newline at end of file
login-password
:
druid
redis
:
host
:
localhost
# Redis服务器地址
database
:
0
# Redis数据库索引(默认为0)
port
:
6379
# Redis服务器连接端口
password
:
# Redis服务器连接密码(默认为空)
timeout
:
300ms
# 连接超时时间(毫秒)
\ No newline at end of file
mall-admin/src/main/resources/application-prod.yml
View file @
fa0af318
...
...
@@ -12,6 +12,12 @@ spring:
stat-view-servlet
:
#访问监控网页的登录用户名和密码
login-username
:
druid
login-password
:
druid
redis
:
host
:
redis
# Redis服务器地址
database
:
0
# Redis数据库索引(默认为0)
port
:
6379
# Redis服务器连接端口
password
:
# Redis服务器连接密码(默认为空)
timeout
:
300ms
# 连接超时时间(毫秒)
logging
:
path
:
/var/logs
#配置日志生成路径
\ No newline at end of file
mall-admin/src/main/resources/application.yml
View file @
fa0af318
...
...
@@ -14,9 +14,17 @@ mybatis:
jwt
:
tokenHeader
:
Authorization
#JWT存储的请求头
secret
:
mall-admin-secret
#JWT加解密使用的密钥
expiration
:
604800
#JWT的超期限时间(60*60*24)
expiration
:
604800
#JWT的超期限时间(60*60*24
*7
)
tokenHead
:
Bearer
#JWT负载中拿到开头
redis
:
database
:
mall
key
:
admin
:
'
ums:admin'
resourceList
:
'
ums:resourceList'
expire
:
common
:
86400
# 24小时
secure
:
ignored
:
urls
:
#安全路径白名单
...
...
mall-admin/src/main/resources/dao/UmsAdminRoleRelationDao.xml
View file @
fa0af318
...
...
@@ -71,4 +71,12 @@
GROUP BY
ur.id
</select>
<select
id=
"getAdminIdList"
resultType=
"java.lang.Long"
>
SELECT
DISTINCT ar.admin_id
FROM
ums_role_resource_relation rr
LEFT JOIN ums_admin_role_relation ar ON rr.role_id = ar.role_id
WHERE rr.resource_id=#{resourceId}
</select>
</mapper>
\ No newline at end of file
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment