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/config/MallSecurityConfig.java
View file @
fa0af318
...
...
@@ -13,8 +13,6 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
mall-admin/src/main/java/com/macro/mall/dao/CmsPrefrenceAreaProductRelationDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/4/26.
*/
public
interface
CmsPrefrenceAreaProductRelationDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
CmsPrefrenceAreaProductRelation
>
prefrenceAreaProductRelationList
);
}
mall-admin/src/main/java/com/macro/mall/dao/CmsSubjectProductRelationDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/4/26.
*/
public
interface
CmsSubjectProductRelationDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
CmsSubjectProductRelation
>
subjectProductRelationList
);
}
mall-admin/src/main/java/com/macro/mall/dao/OmsOrderOperateHistoryDao.java
View file @
fa0af318
...
...
@@ -6,12 +6,9 @@ import org.apache.ibatis.annotations.Param;
import
java.util.List
;
/**
*
自定义
订单操作记录Dao
* 订单操作记录
自定义
Dao
* Created by macro on 2018/10/12.
*/
public
interface
OmsOrderOperateHistoryDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
OmsOrderOperateHistory
>
orderOperateHistoryList
);
}
mall-admin/src/main/java/com/macro/mall/dao/PmsMemberPriceDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/4/26.
*/
public
interface
PmsMemberPriceDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
PmsMemberPrice
>
memberPriceList
);
}
mall-admin/src/main/java/com/macro/mall/dao/PmsProductAttributeCategoryDao.java
View file @
fa0af318
...
...
@@ -9,8 +9,5 @@ import java.util.List;
* Created by macro on 2018/5/24.
*/
public
interface
PmsProductAttributeCategoryDao
{
/**
* 获取包含商品属性的商品属性分类列表
*/
List
<
PmsProductAttributeCategoryItem
>
getListWithAttr
();
}
mall-admin/src/main/java/com/macro/mall/dao/PmsProductAttributeDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/5/23.
*/
public
interface
PmsProductAttributeDao
{
/**
* 获取商品分类对应属性列表
*/
List
<
ProductAttrInfo
>
getProductAttrInfo
(
@Param
(
"id"
)
Long
productCategoryId
);
}
mall-admin/src/main/java/com/macro/mall/dao/PmsProductAttributeValueDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/4/26.
*/
public
interface
PmsProductAttributeValueDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
PmsProductAttributeValue
>
productAttributeValueList
);
}
mall-admin/src/main/java/com/macro/mall/dao/PmsProductCategoryAttributeRelationDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/5/23.
*/
public
interface
PmsProductCategoryAttributeRelationDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
PmsProductCategoryAttributeRelation
>
productCategoryAttributeRelationList
);
}
mall-admin/src/main/java/com/macro/mall/dao/PmsProductCategoryDao.java
View file @
fa0af318
...
...
@@ -9,8 +9,5 @@ import java.util.List;
* Created by macro on 2018/5/25.
*/
public
interface
PmsProductCategoryDao
{
/**
* 获取包括子分类的商品分类列表
*/
List
<
PmsProductCategoryWithChildrenItem
>
listWithChildren
();
}
mall-admin/src/main/java/com/macro/mall/dao/PmsProductFullReductionDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/4/26.
*/
public
interface
PmsProductFullReductionDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
PmsProductFullReduction
>
productFullReductionList
);
}
mall-admin/src/main/java/com/macro/mall/dao/PmsProductLadderDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/4/26.
*/
public
interface
PmsProductLadderDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
PmsProductLadder
>
productLadderList
);
}
mall-admin/src/main/java/com/macro/mall/dao/PmsProductVertifyRecordDao.java
View file @
fa0af318
...
...
@@ -6,12 +6,9 @@ import org.apache.ibatis.annotations.Param;
import
java.util.List
;
/**
* 商品审核日志自定义
D
ao
* 商品审核日志自定义
d
ao
* Created by macro on 2018/4/27.
*/
public
interface
PmsProductVertifyRecordDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
PmsProductVertifyRecord
>
list
);
}
mall-admin/src/main/java/com/macro/mall/dao/SmsCouponDao.java
View file @
fa0af318
...
...
@@ -8,8 +8,5 @@ import org.apache.ibatis.annotations.Param;
* Created by macro on 2018/8/29.
*/
public
interface
SmsCouponDao
{
/**
* 获取优惠券详情,包括关联信息
*/
SmsCouponParam
getItem
(
@Param
(
"id"
)
Long
id
);
}
mall-admin/src/main/java/com/macro/mall/dao/SmsCouponProductCategoryRelationDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/8/28.
*/
public
interface
SmsCouponProductCategoryRelationDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
SmsCouponProductCategoryRelation
>
productCategoryRelationList
);
}
mall-admin/src/main/java/com/macro/mall/dao/SmsCouponProductRelationDao.java
View file @
fa0af318
...
...
@@ -10,8 +10,5 @@ import java.util.List;
* Created by macro on 2018/8/28.
*/
public
interface
SmsCouponProductRelationDao
{
/**
* 批量创建
*/
int
insertList
(
@Param
(
"list"
)
List
<
SmsCouponProductRelation
>
productRelationList
);
}
mall-admin/src/main/java/com/macro/mall/dao/UmsAdminRoleRelationDao.java
View file @
fa0af318
...
...
@@ -37,4 +37,9 @@ public interface UmsAdminRoleRelationDao {
* 获取用户所有可访问资源
*/
List
<
UmsResource
>
getResourceList
(
@Param
(
"adminId"
)
Long
adminId
);
/**
* 获取资源相关用户ID列表
*/
List
<
Long
>
getAdminIdList
(
@Param
(
"resourceId"
)
Long
resourceId
);
}
mall-admin/src/main/java/com/macro/mall/service/PmsProductAttributeService.java
View file @
fa0af318
...
...
@@ -14,8 +14,7 @@ import java.util.List;
public
interface
PmsProductAttributeService
{
/**
* 根据分类分页获取商品属性
*
* @param cid 分类id
* @param cid 分类id
* @param type 0->属性;2->参数
*/
List
<
PmsProductAttribute
>
getList
(
Long
cid
,
Integer
type
,
Integer
pageSize
,
Integer
pageNum
);
...
...
@@ -36,14 +35,8 @@ public interface PmsProductAttributeService {
*/
PmsProductAttribute
getItem
(
Long
id
);
/**
* 批量删除商品属性
*/
@Transactional
int
delete
(
List
<
Long
>
ids
);
/**
* 获取和分类相关的商品属性
*/
List
<
ProductAttrInfo
>
getProductAttrInfo
(
Long
productCategoryId
);
}
mall-admin/src/main/java/com/macro/mall/service/UmsAdminCacheService.java
0 → 100644
View file @
fa0af318
package
com.macro.mall.service
;
import
com.macro.mall.model.UmsAdmin
;
import
com.macro.mall.model.UmsResource
;
import
java.util.List
;
/**
* 后台用户缓存操作类
* Created by macro on 2020/3/13.
*/
public
interface
UmsAdminCacheService
{
/**
* 删除后台用户缓存
*/
void
delAdmin
(
Long
adminId
);
/**
* 删除后台用户资源列表缓存
*/
void
delResourceList
(
Long
adminId
);
/**
* 当角色相关资源信息改变时删除相关后台用户缓存
*/
void
delResourceListByRole
(
Long
roleId
);
/**
* 当角色相关资源信息改变时删除相关后台用户缓存
*/
void
delResourceListByRoleIds
(
List
<
Long
>
roleIds
);
/**
* 当资源信息改变时,删除资源项目后台用户缓存
*/
void
delResourceListByResource
(
Long
resourceId
);
/**
* 获取缓存后台用户信息
*/
UmsAdmin
getAdmin
(
String
username
);
/**
* 设置缓存后台用户信息
*/
void
setAdmin
(
UmsAdmin
admin
);
/**
* 获取缓存后台用户资源列表
*/
List
<
UmsResource
>
getResourceList
(
Long
adminId
);
/**
* 设置后台后台用户资源列表
*/
void
setResourceList
(
Long
adminId
,
List
<
UmsResource
>
resourceList
);
}
mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminCacheServiceImpl.java
0 → 100644
View file @
fa0af318
package
com.macro.mall.service.impl
;
import
cn.hutool.core.collection.CollUtil
;
import
com.macro.mall.dao.UmsAdminRoleRelationDao
;
import
com.macro.mall.mapper.UmsAdminRoleRelationMapper
;
import
com.macro.mall.model.UmsAdmin
;
import
com.macro.mall.model.UmsAdminRoleRelation
;
import
com.macro.mall.model.UmsAdminRoleRelationExample
;
import
com.macro.mall.model.UmsResource
;
import
com.macro.mall.security.service.RedisService
;
import
com.macro.mall.service.UmsAdminCacheService
;
import
com.macro.mall.service.UmsAdminService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* UmsAdminCacheService实现类
* Created by macro on 2020/3/13.
*/
@Service
public
class
UmsAdminCacheServiceImpl
implements
UmsAdminCacheService
{
@Autowired
private
UmsAdminService
adminService
;
@Autowired
private
RedisService
redisService
;
@Autowired
private
UmsAdminRoleRelationMapper
adminRoleRelationMapper
;
@Autowired
private
UmsAdminRoleRelationDao
adminRoleRelationDao
;
@Value
(
"${redis.database}"
)
private
String
REDIS_DATABASE
;
@Value
(
"${redis.expire.common}"
)
private
Long
REDIS_EXPIRE
;
@Value
(
"${redis.key.admin}"
)
private
String
REDIS_KEY_ADMIN
;
@Value
(
"${redis.key.resourceList}"
)
private
String
REDIS_KEY_RESOURCE_LIST
;
@Override
public
void
delAdmin
(
Long
adminId
)
{
UmsAdmin
admin
=
adminService
.
getItem
(
adminId
);
if
(
admin
!=
null
)
{
String
key
=
REDIS_DATABASE
+
":"
+
REDIS_KEY_ADMIN
+
":"
+
admin
.
getUsername
();
redisService
.
del
(
key
);
}
}
@Override
public
void
delResourceList
(
Long
adminId
)
{
String
key
=
REDIS_DATABASE
+
":"
+
REDIS_KEY_RESOURCE_LIST
+
":"
+
adminId
;
redisService
.
del
(
key
);
}
@Override
public
void
delResourceListByRole
(
Long
roleId
)
{
UmsAdminRoleRelationExample
example
=
new
UmsAdminRoleRelationExample
();
example
.
createCriteria
().
andRoleIdEqualTo
(
roleId
);
List
<
UmsAdminRoleRelation
>
relationList
=
adminRoleRelationMapper
.
selectByExample
(
example
);
if
(
CollUtil
.
isNotEmpty
(
relationList
))
{
String
keyPrefix
=
REDIS_DATABASE
+
":"
+
REDIS_KEY_RESOURCE_LIST
+
":"
;
List
<
String
>
keys
=
relationList
.
stream
().
map
(
relation
->
keyPrefix
+
relation
.
getAdminId
()).
collect
(
Collectors
.
toList
());
redisService
.
del
(
keys
);
}
}
@Override
public
void
delResourceListByRoleIds
(
List
<
Long
>
roleIds
)
{
UmsAdminRoleRelationExample
example
=
new
UmsAdminRoleRelationExample
();
example
.
createCriteria
().
andRoleIdIn
(
roleIds
);
List
<
UmsAdminRoleRelation
>
relationList
=
adminRoleRelationMapper
.
selectByExample
(
example
);
if
(
CollUtil
.
isNotEmpty
(
relationList
))
{
String
keyPrefix
=
REDIS_DATABASE
+
":"
+
REDIS_KEY_RESOURCE_LIST
+
":"
;
List
<
String
>
keys
=
relationList
.
stream
().
map
(
relation
->
keyPrefix
+
relation
.
getAdminId
()).
collect
(
Collectors
.
toList
());
redisService
.
del
(
keys
);
}
}
@Override
public
void
delResourceListByResource
(
Long
resourceId
)
{
List
<
Long
>
adminIdList
=
adminRoleRelationDao
.
getAdminIdList
(
resourceId
);
if
(
CollUtil
.
isNotEmpty
(
adminIdList
))
{
String
keyPrefix
=
REDIS_DATABASE
+
":"
+
REDIS_KEY_RESOURCE_LIST
+
":"
;
List
<
String
>
keys
=
adminIdList
.
stream
().
map
(
adminId
->
keyPrefix
+
adminId
).
collect
(
Collectors
.
toList
());
redisService
.
del
(
keys
);
}
}
@Override
public
UmsAdmin
getAdmin
(
String
username
)
{
String
key
=
REDIS_DATABASE
+
":"
+
REDIS_KEY_ADMIN
+
":"
+
username
;
return
(
UmsAdmin
)
redisService
.
get
(
key
);
}
@Override
public
void
setAdmin
(
UmsAdmin
admin
)
{
String
key
=
REDIS_DATABASE
+
":"
+
REDIS_KEY_ADMIN
+
":"
+
admin
.
getUsername
();
redisService
.
set
(
key
,
admin
,
REDIS_EXPIRE
);
}
@Override
public
List
<
UmsResource
>
getResourceList
(
Long
adminId
)
{
String
key
=
REDIS_DATABASE
+
":"
+
REDIS_KEY_RESOURCE_LIST
+
":"
+
adminId
;
return
(
List
<
UmsResource
>)
redisService
.
get
(
key
);
}
@Override
public
void
setResourceList
(
Long
adminId
,
List
<
UmsResource
>
resourceList
)
{
String
key
=
REDIS_DATABASE
+
":"
+
REDIS_KEY_RESOURCE_LIST
+
":"
+
adminId
;
redisService
.
set
(
key
,
resourceList
,
REDIS_EXPIRE
);
}
}
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