添加redis缓存支持
This commit is contained in:
parent
944a305bf1
commit
fa0af3188c
@ -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.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/4/26.
|
* Created by macro on 2018/4/26.
|
||||||
*/
|
*/
|
||||||
public interface CmsPrefrenceAreaProductRelationDao {
|
public interface CmsPrefrenceAreaProductRelationDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list") List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList);
|
int insertList(@Param("list") List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/4/26.
|
* Created by macro on 2018/4/26.
|
||||||
*/
|
*/
|
||||||
public interface CmsSubjectProductRelationDao {
|
public interface CmsSubjectProductRelationDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list") List<CmsSubjectProductRelation> subjectProductRelationList);
|
int insertList(@Param("list") List<CmsSubjectProductRelation> subjectProductRelationList);
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,9 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义订单操作记录Dao
|
* 订单操作记录自定义Dao
|
||||||
* Created by macro on 2018/10/12.
|
* Created by macro on 2018/10/12.
|
||||||
*/
|
*/
|
||||||
public interface OmsOrderOperateHistoryDao {
|
public interface OmsOrderOperateHistoryDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list") List<OmsOrderOperateHistory> orderOperateHistoryList);
|
int insertList(@Param("list") List<OmsOrderOperateHistory> orderOperateHistoryList);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/4/26.
|
* Created by macro on 2018/4/26.
|
||||||
*/
|
*/
|
||||||
public interface PmsMemberPriceDao {
|
public interface PmsMemberPriceDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list") List<PmsMemberPrice> memberPriceList);
|
int insertList(@Param("list") List<PmsMemberPrice> memberPriceList);
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/5/24.
|
* Created by macro on 2018/5/24.
|
||||||
*/
|
*/
|
||||||
public interface PmsProductAttributeCategoryDao {
|
public interface PmsProductAttributeCategoryDao {
|
||||||
/**
|
|
||||||
* 获取包含商品属性的商品属性分类列表
|
|
||||||
*/
|
|
||||||
List<PmsProductAttributeCategoryItem> getListWithAttr();
|
List<PmsProductAttributeCategoryItem> getListWithAttr();
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/5/23.
|
* Created by macro on 2018/5/23.
|
||||||
*/
|
*/
|
||||||
public interface PmsProductAttributeDao {
|
public interface PmsProductAttributeDao {
|
||||||
/**
|
|
||||||
* 获取商品分类对应属性列表
|
|
||||||
*/
|
|
||||||
List<ProductAttrInfo> getProductAttrInfo(@Param("id") Long productCategoryId);
|
List<ProductAttrInfo> getProductAttrInfo(@Param("id") Long productCategoryId);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/4/26.
|
* Created by macro on 2018/4/26.
|
||||||
*/
|
*/
|
||||||
public interface PmsProductAttributeValueDao {
|
public interface PmsProductAttributeValueDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list")List<PmsProductAttributeValue> productAttributeValueList);
|
int insertList(@Param("list")List<PmsProductAttributeValue> productAttributeValueList);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/5/23.
|
* Created by macro on 2018/5/23.
|
||||||
*/
|
*/
|
||||||
public interface PmsProductCategoryAttributeRelationDao {
|
public interface PmsProductCategoryAttributeRelationDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list") List<PmsProductCategoryAttributeRelation> productCategoryAttributeRelationList);
|
int insertList(@Param("list") List<PmsProductCategoryAttributeRelation> productCategoryAttributeRelationList);
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/5/25.
|
* Created by macro on 2018/5/25.
|
||||||
*/
|
*/
|
||||||
public interface PmsProductCategoryDao {
|
public interface PmsProductCategoryDao {
|
||||||
/**
|
|
||||||
* 获取包括子分类的商品分类列表
|
|
||||||
*/
|
|
||||||
List<PmsProductCategoryWithChildrenItem> listWithChildren();
|
List<PmsProductCategoryWithChildrenItem> listWithChildren();
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/4/26.
|
* Created by macro on 2018/4/26.
|
||||||
*/
|
*/
|
||||||
public interface PmsProductFullReductionDao {
|
public interface PmsProductFullReductionDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list") List<PmsProductFullReduction> productFullReductionList);
|
int insertList(@Param("list") List<PmsProductFullReduction> productFullReductionList);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/4/26.
|
* Created by macro on 2018/4/26.
|
||||||
*/
|
*/
|
||||||
public interface PmsProductLadderDao {
|
public interface PmsProductLadderDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list") List<PmsProductLadder> productLadderList);
|
int insertList(@Param("list") List<PmsProductLadder> productLadderList);
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,9 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品审核日志自定义Dao
|
* 商品审核日志自定义dao
|
||||||
* Created by macro on 2018/4/27.
|
* Created by macro on 2018/4/27.
|
||||||
*/
|
*/
|
||||||
public interface PmsProductVertifyRecordDao {
|
public interface PmsProductVertifyRecordDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list") List<PmsProductVertifyRecord> list);
|
int insertList(@Param("list") List<PmsProductVertifyRecord> list);
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,5 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
* Created by macro on 2018/8/29.
|
* Created by macro on 2018/8/29.
|
||||||
*/
|
*/
|
||||||
public interface SmsCouponDao {
|
public interface SmsCouponDao {
|
||||||
/**
|
|
||||||
* 获取优惠券详情,包括关联信息
|
|
||||||
*/
|
|
||||||
SmsCouponParam getItem(@Param("id") Long id);
|
SmsCouponParam getItem(@Param("id") Long id);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/8/28.
|
* Created by macro on 2018/8/28.
|
||||||
*/
|
*/
|
||||||
public interface SmsCouponProductCategoryRelationDao {
|
public interface SmsCouponProductCategoryRelationDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list")List<SmsCouponProductCategoryRelation> productCategoryRelationList);
|
int insertList(@Param("list")List<SmsCouponProductCategoryRelation> productCategoryRelationList);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,5 @@ import java.util.List;
|
|||||||
* Created by macro on 2018/8/28.
|
* Created by macro on 2018/8/28.
|
||||||
*/
|
*/
|
||||||
public interface SmsCouponProductRelationDao {
|
public interface SmsCouponProductRelationDao {
|
||||||
/**
|
|
||||||
* 批量创建
|
|
||||||
*/
|
|
||||||
int insertList(@Param("list")List<SmsCouponProductRelation> productRelationList);
|
int insertList(@Param("list")List<SmsCouponProductRelation> productRelationList);
|
||||||
}
|
}
|
||||||
|
@ -37,4 +37,9 @@ public interface UmsAdminRoleRelationDao {
|
|||||||
* 获取用户所有可访问资源
|
* 获取用户所有可访问资源
|
||||||
*/
|
*/
|
||||||
List<UmsResource> getResourceList(@Param("adminId") Long adminId);
|
List<UmsResource> getResourceList(@Param("adminId") Long adminId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取资源相关用户ID列表
|
||||||
|
*/
|
||||||
|
List<Long> getAdminIdList(@Param("resourceId") Long resourceId);
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,7 @@ import java.util.List;
|
|||||||
public interface PmsProductAttributeService {
|
public interface PmsProductAttributeService {
|
||||||
/**
|
/**
|
||||||
* 根据分类分页获取商品属性
|
* 根据分类分页获取商品属性
|
||||||
*
|
* @param cid 分类id
|
||||||
* @param cid 分类id
|
|
||||||
* @param type 0->属性;2->参数
|
* @param type 0->属性;2->参数
|
||||||
*/
|
*/
|
||||||
List<PmsProductAttribute> getList(Long cid, Integer type, Integer pageSize, Integer pageNum);
|
List<PmsProductAttribute> getList(Long cid, Integer type, Integer pageSize, Integer pageNum);
|
||||||
@ -36,14 +35,8 @@ public interface PmsProductAttributeService {
|
|||||||
*/
|
*/
|
||||||
PmsProductAttribute getItem(Long id);
|
PmsProductAttribute getItem(Long id);
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除商品属性
|
|
||||||
*/
|
|
||||||
@Transactional
|
@Transactional
|
||||||
int delete(List<Long> ids);
|
int delete(List<Long> ids);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取和分类相关的商品属性
|
|
||||||
*/
|
|
||||||
List<ProductAttrInfo> getProductAttrInfo(Long productCategoryId);
|
List<ProductAttrInfo> getProductAttrInfo(Long productCategoryId);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ import com.macro.mall.mapper.UmsAdminPermissionRelationMapper;
|
|||||||
import com.macro.mall.mapper.UmsAdminRoleRelationMapper;
|
import com.macro.mall.mapper.UmsAdminRoleRelationMapper;
|
||||||
import com.macro.mall.model.*;
|
import com.macro.mall.model.*;
|
||||||
import com.macro.mall.security.util.JwtTokenUtil;
|
import com.macro.mall.security.util.JwtTokenUtil;
|
||||||
|
import com.macro.mall.service.UmsAdminCacheService;
|
||||||
import com.macro.mall.service.UmsAdminService;
|
import com.macro.mall.service.UmsAdminService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -61,14 +62,20 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
|||||||
private UmsAdminPermissionRelationDao adminPermissionRelationDao;
|
private UmsAdminPermissionRelationDao adminPermissionRelationDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UmsAdminLoginLogMapper loginLogMapper;
|
private UmsAdminLoginLogMapper loginLogMapper;
|
||||||
|
@Autowired
|
||||||
|
private UmsAdminCacheService adminCacheService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UmsAdmin getAdminByUsername(String username) {
|
public UmsAdmin getAdminByUsername(String username) {
|
||||||
|
UmsAdmin admin = adminCacheService.getAdmin(username);
|
||||||
|
if(admin!=null) return admin;
|
||||||
UmsAdminExample example = new UmsAdminExample();
|
UmsAdminExample example = new UmsAdminExample();
|
||||||
example.createCriteria().andUsernameEqualTo(username);
|
example.createCriteria().andUsernameEqualTo(username);
|
||||||
List<UmsAdmin> adminList = adminMapper.selectByExample(example);
|
List<UmsAdmin> adminList = adminMapper.selectByExample(example);
|
||||||
if (adminList != null && adminList.size() > 0) {
|
if (adminList != null && adminList.size() > 0) {
|
||||||
return adminList.get(0);
|
admin = adminList.get(0);
|
||||||
|
adminCacheService.setAdmin(admin);
|
||||||
|
return admin;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -119,6 +126,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
|||||||
*/
|
*/
|
||||||
private void insertLoginLog(String username) {
|
private void insertLoginLog(String username) {
|
||||||
UmsAdmin admin = getAdminByUsername(username);
|
UmsAdmin admin = getAdminByUsername(username);
|
||||||
|
if(admin==null) return;
|
||||||
UmsAdminLoginLog loginLog = new UmsAdminLoginLog();
|
UmsAdminLoginLog loginLog = new UmsAdminLoginLog();
|
||||||
loginLog.setAdminId(admin.getId());
|
loginLog.setAdminId(admin.getId());
|
||||||
loginLog.setCreateTime(new Date());
|
loginLog.setCreateTime(new Date());
|
||||||
@ -176,12 +184,17 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
|||||||
admin.setPassword(passwordEncoder.encode(admin.getPassword()));
|
admin.setPassword(passwordEncoder.encode(admin.getPassword()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return adminMapper.updateByPrimaryKeySelective(admin);
|
int count = adminMapper.updateByPrimaryKeySelective(admin);
|
||||||
|
adminCacheService.delAdmin(id);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Long id) {
|
public int delete(Long id) {
|
||||||
return adminMapper.deleteByPrimaryKey(id);
|
adminCacheService.delAdmin(id);
|
||||||
|
int count = adminMapper.deleteByPrimaryKey(id);
|
||||||
|
adminCacheService.delResourceList(id);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -202,6 +215,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
|||||||
}
|
}
|
||||||
adminRoleRelationDao.insertList(list);
|
adminRoleRelationDao.insertList(list);
|
||||||
}
|
}
|
||||||
|
adminCacheService.delResourceList(adminId);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +226,15 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UmsResource> getResourceList(Long adminId) {
|
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
|
@Override
|
||||||
@ -276,6 +298,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
|||||||
}
|
}
|
||||||
umsAdmin.setPassword(passwordEncoder.encode(param.getNewPassword()));
|
umsAdmin.setPassword(passwordEncoder.encode(param.getNewPassword()));
|
||||||
adminMapper.updateByPrimaryKey(umsAdmin);
|
adminMapper.updateByPrimaryKey(umsAdmin);
|
||||||
|
adminCacheService.delAdmin(umsAdmin.getId());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
|
|||||||
import com.macro.mall.mapper.UmsResourceMapper;
|
import com.macro.mall.mapper.UmsResourceMapper;
|
||||||
import com.macro.mall.model.UmsResource;
|
import com.macro.mall.model.UmsResource;
|
||||||
import com.macro.mall.model.UmsResourceExample;
|
import com.macro.mall.model.UmsResourceExample;
|
||||||
|
import com.macro.mall.service.UmsAdminCacheService;
|
||||||
import com.macro.mall.service.UmsResourceService;
|
import com.macro.mall.service.UmsResourceService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -20,6 +21,8 @@ import java.util.List;
|
|||||||
public class UmsResourceServiceImpl implements UmsResourceService {
|
public class UmsResourceServiceImpl implements UmsResourceService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UmsResourceMapper resourceMapper;
|
private UmsResourceMapper resourceMapper;
|
||||||
|
@Autowired
|
||||||
|
private UmsAdminCacheService adminCacheService;
|
||||||
@Override
|
@Override
|
||||||
public int create(UmsResource umsResource) {
|
public int create(UmsResource umsResource) {
|
||||||
umsResource.setCreateTime(new Date());
|
umsResource.setCreateTime(new Date());
|
||||||
@ -29,7 +32,9 @@ public class UmsResourceServiceImpl implements UmsResourceService {
|
|||||||
@Override
|
@Override
|
||||||
public int update(Long id, UmsResource umsResource) {
|
public int update(Long id, UmsResource umsResource) {
|
||||||
umsResource.setId(id);
|
umsResource.setId(id);
|
||||||
return resourceMapper.updateByPrimaryKeySelective(umsResource);
|
int count = resourceMapper.updateByPrimaryKeySelective(umsResource);
|
||||||
|
adminCacheService.delResourceListByResource(id);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -39,7 +44,9 @@ public class UmsResourceServiceImpl implements UmsResourceService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Long id) {
|
public int delete(Long id) {
|
||||||
return resourceMapper.deleteByPrimaryKey(id);
|
int count = resourceMapper.deleteByPrimaryKey(id);
|
||||||
|
adminCacheService.delResourceListByResource(id);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,6 +8,7 @@ import com.macro.mall.mapper.UmsRoleMenuRelationMapper;
|
|||||||
import com.macro.mall.mapper.UmsRolePermissionRelationMapper;
|
import com.macro.mall.mapper.UmsRolePermissionRelationMapper;
|
||||||
import com.macro.mall.mapper.UmsRoleResourceRelationMapper;
|
import com.macro.mall.mapper.UmsRoleResourceRelationMapper;
|
||||||
import com.macro.mall.model.*;
|
import com.macro.mall.model.*;
|
||||||
|
import com.macro.mall.service.UmsAdminCacheService;
|
||||||
import com.macro.mall.service.UmsRoleService;
|
import com.macro.mall.service.UmsRoleService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -35,6 +36,8 @@ public class UmsRoleServiceImpl implements UmsRoleService {
|
|||||||
private UmsRolePermissionRelationDao rolePermissionRelationDao;
|
private UmsRolePermissionRelationDao rolePermissionRelationDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UmsRoleDao roleDao;
|
private UmsRoleDao roleDao;
|
||||||
|
@Autowired
|
||||||
|
private UmsAdminCacheService adminCacheService;
|
||||||
@Override
|
@Override
|
||||||
public int create(UmsRole role) {
|
public int create(UmsRole role) {
|
||||||
role.setCreateTime(new Date());
|
role.setCreateTime(new Date());
|
||||||
@ -53,7 +56,9 @@ public class UmsRoleServiceImpl implements UmsRoleService {
|
|||||||
public int delete(List<Long> ids) {
|
public int delete(List<Long> ids) {
|
||||||
UmsRoleExample example = new UmsRoleExample();
|
UmsRoleExample example = new UmsRoleExample();
|
||||||
example.createCriteria().andIdIn(ids);
|
example.createCriteria().andIdIn(ids);
|
||||||
return roleMapper.deleteByExample(example);
|
int count = roleMapper.deleteByExample(example);
|
||||||
|
adminCacheService.delResourceListByRoleIds(ids);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -137,6 +142,7 @@ public class UmsRoleServiceImpl implements UmsRoleService {
|
|||||||
relation.setResourceId(resourceId);
|
relation.setResourceId(resourceId);
|
||||||
roleResourceRelationMapper.insert(relation);
|
roleResourceRelationMapper.insert(relation);
|
||||||
}
|
}
|
||||||
|
adminCacheService.delResourceListByRole(roleId);
|
||||||
return resourceIds.size();
|
return resourceIds.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,10 @@ spring:
|
|||||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据
|
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据
|
||||||
stat-view-servlet: #访问监控网页的登录用户名和密码
|
stat-view-servlet: #访问监控网页的登录用户名和密码
|
||||||
login-username: druid
|
login-username: druid
|
||||||
login-password: druid
|
login-password: druid
|
||||||
|
redis:
|
||||||
|
host: localhost # Redis服务器地址
|
||||||
|
database: 0 # Redis数据库索引(默认为0)
|
||||||
|
port: 6379 # Redis服务器连接端口
|
||||||
|
password: # Redis服务器连接密码(默认为空)
|
||||||
|
timeout: 300ms # 连接超时时间(毫秒)
|
@ -12,6 +12,12 @@ spring:
|
|||||||
stat-view-servlet: #访问监控网页的登录用户名和密码
|
stat-view-servlet: #访问监控网页的登录用户名和密码
|
||||||
login-username: druid
|
login-username: druid
|
||||||
login-password: druid
|
login-password: druid
|
||||||
|
redis:
|
||||||
|
host: redis # Redis服务器地址
|
||||||
|
database: 0 # Redis数据库索引(默认为0)
|
||||||
|
port: 6379 # Redis服务器连接端口
|
||||||
|
password: # Redis服务器连接密码(默认为空)
|
||||||
|
timeout: 300ms # 连接超时时间(毫秒)
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
path: /var/logs #配置日志生成路径
|
path: /var/logs #配置日志生成路径
|
@ -14,9 +14,17 @@ mybatis:
|
|||||||
jwt:
|
jwt:
|
||||||
tokenHeader: Authorization #JWT存储的请求头
|
tokenHeader: Authorization #JWT存储的请求头
|
||||||
secret: mall-admin-secret #JWT加解密使用的密钥
|
secret: mall-admin-secret #JWT加解密使用的密钥
|
||||||
expiration: 604800 #JWT的超期限时间(60*60*24)
|
expiration: 604800 #JWT的超期限时间(60*60*24*7)
|
||||||
tokenHead: Bearer #JWT负载中拿到开头
|
tokenHead: Bearer #JWT负载中拿到开头
|
||||||
|
|
||||||
|
redis:
|
||||||
|
database: mall
|
||||||
|
key:
|
||||||
|
admin: 'ums:admin'
|
||||||
|
resourceList: 'ums:resourceList'
|
||||||
|
expire:
|
||||||
|
common: 86400 # 24小时
|
||||||
|
|
||||||
secure:
|
secure:
|
||||||
ignored:
|
ignored:
|
||||||
urls: #安全路径白名单
|
urls: #安全路径白名单
|
||||||
|
@ -71,4 +71,12 @@
|
|||||||
GROUP BY
|
GROUP BY
|
||||||
ur.id
|
ur.id
|
||||||
</select>
|
</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>
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user