mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 12:39:05 +08:00
🐛 Fixing a bug. #613 缓存支持不区分租户
This commit is contained in:
1 parent
93021656e2
commit
5d1cd5de75
6 files changed
+26
-17
No files matched your search
+8
-2
@@ -15,6 +15,12 @@ public interface CacheConstants {
|
||||
*/
|
||||
String GLOBALLY = "gl:";
|
||||
|
||||
/**
|
||||
* 验证码前缀
|
||||
*/
|
||||
String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY:";
|
||||
|
||||
|
||||
/**
|
||||
* 菜单信息缓存
|
||||
*/
|
||||
@@ -63,7 +69,7 @@ public interface CacheConstants {
|
||||
String PARAMS_DETAILS = "params_details";
|
||||
|
||||
/**
|
||||
* 租户缓存
|
||||
* 租户缓存 (不区分租户)
|
||||
*/
|
||||
String TENANT_DETAILS = "tenant_details";
|
||||
String TENANT_DETAILS = GLOBALLY + "tenant_details";
|
||||
}
|
||||
-5
@@ -78,11 +78,6 @@ public interface CommonConstants {
|
||||
*/
|
||||
String BACK_END_PROJECT = "pigx";
|
||||
|
||||
/**
|
||||
* 验证码前缀
|
||||
*/
|
||||
String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY_";
|
||||
|
||||
/**
|
||||
* 公共参数
|
||||
*/
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ package com.pig4cloud.pigx.gateway.filter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.LoginTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.exception.ValidateCodeException;
|
||||
@@ -129,7 +129,7 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
|
||||
randomStr = mobile;
|
||||
}
|
||||
|
||||
String key = CommonConstants.DEFAULT_CODE_KEY + randomStr;
|
||||
String key = CacheConstants.DEFAULT_CODE_KEY + randomStr;
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
|
||||
if (!redisTemplate.hasKey(key)) {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package com.pig4cloud.pigx.gateway.handler;
|
||||
|
||||
import com.google.code.kaptcha.Producer;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -62,8 +63,8 @@ public class ImageCodeHandler implements HandlerFunction<ServerResponse> {
|
||||
//保存验证码信息
|
||||
String randomStr = serverRequest.queryParam("randomStr").get();
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.opsForValue().set(CommonConstants.DEFAULT_CODE_KEY + randomStr, text
|
||||
, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
||||
redisTemplate.opsForValue().set(CacheConstants.DEFAULT_CODE_KEY + randomStr, text
|
||||
, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
||||
|
||||
// 转换流信息写出
|
||||
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
|
||||
@@ -75,8 +76,8 @@ public class ImageCodeHandler implements HandlerFunction<ServerResponse> {
|
||||
}
|
||||
|
||||
return ServerResponse
|
||||
.status(HttpStatus.OK)
|
||||
.contentType(MediaType.IMAGE_JPEG)
|
||||
.body(BodyInserters.fromResource(new ByteArrayResource(os.toByteArray())));
|
||||
.status(HttpStatus.OK)
|
||||
.contentType(MediaType.IMAGE_JPEG)
|
||||
.body(BodyInserters.fromResource(new ByteArrayResource(os.toByteArray())));
|
||||
}
|
||||
}
|
||||
+7
@@ -21,11 +21,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysTenant;
|
||||
import com.pig4cloud.pigx.admin.service.SysTenantService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -77,6 +80,7 @@ public class SysTenantController {
|
||||
@SysLog("新增租户")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('admin_systenant_add')")
|
||||
@CacheEvict(value = CacheConstants.TENANT_DETAILS, allEntries = true)
|
||||
public R save(@RequestBody SysTenant sysTenant) {
|
||||
return R.ok(sysTenantService.saveTenant(sysTenant));
|
||||
}
|
||||
@@ -90,6 +94,7 @@ public class SysTenantController {
|
||||
@SysLog("修改租户")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('admin_systenant_edit')")
|
||||
@CacheEvict(value = CacheConstants.TENANT_DETAILS, allEntries = true)
|
||||
public R updateById(@RequestBody SysTenant sysTenant) {
|
||||
return R.ok(sysTenantService.updateById(sysTenant));
|
||||
}
|
||||
@@ -103,6 +108,7 @@ public class SysTenantController {
|
||||
@SysLog("删除租户")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('admin_systenant_del')")
|
||||
@CacheEvict(value = CacheConstants.TENANT_DETAILS, allEntries = true)
|
||||
public R removeById(@PathVariable Integer id) {
|
||||
return R.ok(sysTenantService.removeById(id));
|
||||
}
|
||||
@@ -114,6 +120,7 @@ public class SysTenantController {
|
||||
*/
|
||||
@Inner(value = false)
|
||||
@GetMapping("/list")
|
||||
@Cacheable(value = CacheConstants.TENANT_DETAILS)
|
||||
public R list() {
|
||||
return R.ok(sysTenantService.getNormal());
|
||||
}
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUser;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysUserMapper;
|
||||
import com.pig4cloud.pigx.admin.service.MobileService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.LoginTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
@@ -68,7 +68,7 @@ public class MobileServiceImpl implements MobileService {
|
||||
return R.ok(Boolean.FALSE, "手机号未注册");
|
||||
}
|
||||
|
||||
Object codeObj = redisTemplate.opsForValue().get(CommonConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile);
|
||||
Object codeObj = redisTemplate.opsForValue().get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile);
|
||||
|
||||
if (codeObj != null) {
|
||||
log.info("手机号验证码未过期:{},{}", mobile, codeObj);
|
||||
@@ -78,7 +78,7 @@ public class MobileServiceImpl implements MobileService {
|
||||
String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
|
||||
log.debug("手机号生成验证码成功:{},{}", mobile, code);
|
||||
redisTemplate.opsForValue().set(
|
||||
CommonConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile
|
||||
CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile
|
||||
, code, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
||||
return R.ok(Boolean.TRUE, code);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user