修复:系统设置的Redis缓存不同步的bug

This commit is contained in:
gxwebsoft
2024-05-13 12:46:45 +08:00
parent ba214b7290
commit 638fa61c61
2 changed files with 7 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.core.exception.BusinessException;
import com.gxwebsoft.common.core.utils.CommonUtil;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.*;
import com.gxwebsoft.common.system.entity.Company;
import com.gxwebsoft.common.system.entity.Tenant;
@@ -51,6 +52,8 @@ public class CompanyController extends BaseController {
private TenantMapper tenantMapper;
@Resource
private UserCollectionService userCollectionService;
@Resource
private RedisUtil redisUtil;
@ApiOperation("分页查询企业信息不限租户")
@@ -141,6 +144,8 @@ public class CompanyController extends BaseController {
@PutMapping()
public ApiResult<?> update(@RequestBody Company company) {
if (companyService.updateById(company)) {
// 清除缓存
redisUtil.delete("TenantInfo:".concat(company.getTenantId().toString()));
return success("修改成功");
}
return fail("修改失败");

View File

@@ -1,5 +1,6 @@
package com.gxwebsoft.common.system.controller;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -88,19 +89,14 @@ public class SettingController extends BaseController {
public ApiResult<?> update(@RequestBody Setting setting) {
if (settingService.updateById(setting)) {
// 更新系统设置信息到缓存
String key = "setting:" + setting.getSettingKey() + ":" + getTenantId();
System.out.println("key = " + key);
String key = StrUtil.upperFirst(setting.getSettingKey()).concat(":").concat(getTenantId().toString());
redisUtil.set(key, JSON.parseObject(setting.getContent()));
// 创建微信支付Bean
// settingService.initConfig(setting);
// 更新租户信息
if (setting.getSettingKey().equals("setting")) {
System.out.println("修改系统设置 = " + setting.getContent());
final String content = setting.getContent();
final JSONObject jsonObject = JSONObject.parseObject(content);
final String siteName = jsonObject.getString("siteName");
final String logo = jsonObject.getString("logo");
System.out.println("siteName = " + siteName);
final Tenant tenant = new Tenant();
tenant.setTenantName(siteName);
tenant.setTenantId(getTenantId());