feat(cms): 添加网站密钥和字段加密功能

- 在 CmsWebsite 实体中新增 websiteSecret 字段
- 在 CmsWebsiteField 和 CmsWebsiteFieldParam 中新增 encrypted 字段
- 在 CmsWebsiteParam 中新增 websiteSecret 字段- 优化 MybatisPlusConfig 中租户ID获取逻辑,增强空值判断- 移除 ShopUserRefereeController 中多余的权限注解
- 添加清除缓存时的控制台输出日志- 修复潜在的空指针异常并统一异常日志输出格式
This commit is contained in:
2025-09-30 17:15:42 +08:00
parent 221874425f
commit 292413acdb
7 changed files with 31 additions and 8 deletions

View File

@@ -307,7 +307,7 @@ public class CmsWebsiteController extends BaseController {
website.setStatusText("状态未知"); website.setStatusText("状态未知");
return; return;
} }
if (!running.equals(1)) { if (!running.equals(1)) {
// 未开通 // 未开通
if (running.equals(0)) { if (running.equals(0)) {
@@ -525,6 +525,7 @@ public class CmsWebsiteController extends BaseController {
@DeleteMapping("/clearSiteInfo/{key}") @DeleteMapping("/clearSiteInfo/{key}")
public ApiResult<?> clearSiteInfo(@PathVariable("key") String key) { public ApiResult<?> clearSiteInfo(@PathVariable("key") String key) {
log.info("清除缓存开始key: {}", key); log.info("清除缓存开始key: {}", key);
System.out.println("清除缓存开始key = " + key);
// 清除指定key // 清除指定key
redisUtil.delete(key); redisUtil.delete(key);
// 清除缓存 // 清除缓存

View File

@@ -41,6 +41,9 @@ public class CmsWebsite implements Serializable {
@Schema(description = "网站标识") @Schema(description = "网站标识")
private String websiteCode; private String websiteCode;
@Schema(description = "网站密钥")
private String websiteSecret;
@Schema(description = "网站LOGO") @Schema(description = "网站LOGO")
private String websiteIcon; private String websiteIcon;

View File

@@ -52,6 +52,9 @@ public class CmsWebsiteField implements Serializable {
@Schema(description = "国际化语言") @Schema(description = "国际化语言")
private String lang; private String lang;
@Schema(description = "是否加密")
private Boolean encrypted;
@Schema(description = "商户ID") @Schema(description = "商户ID")
private Long merchantId; private Long merchantId;

View File

@@ -48,6 +48,9 @@ public class CmsWebsiteFieldParam extends BaseParam {
@Schema(description = "名称") @Schema(description = "名称")
private String value; private String value;
@Schema(description = "是否加密")
private Boolean encrypted;
@Schema(description = "排序(数字越小越靠前)") @Schema(description = "排序(数字越小越靠前)")
@QueryField(type = QueryType.EQ) @QueryField(type = QueryType.EQ)
private Integer sortNumber; private Integer sortNumber;

View File

@@ -41,6 +41,9 @@ public class CmsWebsiteParam extends BaseParam {
@Schema(description = "网站标识") @Schema(description = "网站标识")
private String websiteCode; private String websiteCode;
@Schema(description = "网站密钥")
private String websiteSecret;
@Schema(description = "网站LOGO") @Schema(description = "网站LOGO")
private String websiteIcon; private String websiteIcon;

View File

@@ -49,7 +49,7 @@ public class MybatisPlusConfig {
if (request != null) { if (request != null) {
// 从请求头拿ID // 从请求头拿ID
tenantId = request.getHeader("tenantId"); tenantId = request.getHeader("tenantId");
if(tenantId != null){ if(tenantId != null && !tenantId.trim().isEmpty()){
return new LongValue(tenantId); return new LongValue(tenantId);
} }
// 从域名拿ID // 从域名拿ID
@@ -57,7 +57,7 @@ public class MybatisPlusConfig {
if (StrUtil.isNotBlank(Domain)) { if (StrUtil.isNotBlank(Domain)) {
String key = "Domain:" + Domain; String key = "Domain:" + Domain;
tenantId = redisUtil.get(key); tenantId = redisUtil.get(key);
if(tenantId != null){ if(tenantId != null && !tenantId.trim().isEmpty()){
System.out.println("从域名拿TID = " + tenantId); System.out.println("从域名拿TID = " + tenantId);
return new LongValue(tenantId); return new LongValue(tenantId);
} }
@@ -65,8 +65,17 @@ public class MybatisPlusConfig {
} }
} catch (Exception e) { } catch (Exception e) {
// 忽略异常,使用默认逻辑 // 忽略异常,使用默认逻辑
System.err.println("获取租户ID异常: " + e.getMessage());
} }
return getLoginUserTenantId();
// 最后尝试从登录用户获取
Expression loginUserTenantId = getLoginUserTenantId();
if (loginUserTenantId instanceof LongValue) {
return loginUserTenantId;
}
// 如果都获取不到返回null而不是undefined
return new NullValue();
} }
@Override @Override
@@ -119,11 +128,14 @@ public class MybatisPlusConfig {
if (authentication != null) { if (authentication != null) {
Object object = authentication.getPrincipal(); Object object = authentication.getPrincipal();
if (object instanceof User) { if (object instanceof User) {
return new LongValue(((User) object).getTenantId()); Integer tenantId = ((User) object).getTenantId();
if (tenantId != null) {
return new LongValue(tenantId);
}
} }
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println(e.getMessage()); System.err.println("获取登录用户租户ID异常: " + e.getMessage());
} }
return new NullValue(); return new NullValue();
} }

View File

@@ -31,7 +31,6 @@ public class ShopUserRefereeController extends BaseController {
@Resource @Resource
private ShopUserRefereeService shopUserRefereeService; private ShopUserRefereeService shopUserRefereeService;
@PreAuthorize("hasAuthority('shop:shopUserReferee:list')")
@Operation(summary = "分页查询用户推荐关系表") @Operation(summary = "分页查询用户推荐关系表")
@GetMapping("/page") @GetMapping("/page")
public ApiResult<PageResult<ShopUserReferee>> page(ShopUserRefereeParam param) { public ApiResult<PageResult<ShopUserReferee>> page(ShopUserRefereeParam param) {
@@ -39,7 +38,6 @@ public class ShopUserRefereeController extends BaseController {
return success(shopUserRefereeService.pageRel(param)); return success(shopUserRefereeService.pageRel(param));
} }
@PreAuthorize("hasAuthority('shop:shopUserReferee:list')")
@Operation(summary = "查询全部用户推荐关系表") @Operation(summary = "查询全部用户推荐关系表")
@GetMapping() @GetMapping()
public ApiResult<List<ShopUserReferee>> list(ShopUserRefereeParam param) { public ApiResult<List<ShopUserReferee>> list(ShopUserRefereeParam param) {