新增:getByKey、updateByKey方法

This commit is contained in:
2025-07-10 18:39:31 +08:00
parent 68187623e4
commit ae0d8a5ef5
4 changed files with 32 additions and 3 deletions

View File

@@ -77,6 +77,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
"/api/system/tenant/saveByPhone",
"/api/system/user-referee/getRefereeNum",
"/api/system/user-referee/getRefereeNumByUidList",
"/api/system/setting/getByKey/**",
"/api/system/setting/updateByKey/**",
"/lvQ4EoivKJ.txt"
)
.permitAll()

View File

@@ -165,11 +165,28 @@ public class SettingController extends BaseController {
return success(settingService.getData("setting"));
}
@PreAuthorize("hasAuthority('sys:setting:list')")
@ApiOperation("根据key查询系统设置")
@GetMapping("/{key}")
@GetMapping("/getByKey/{key}")
public ApiResult<JSONObject> getByKey(@PathVariable("key") String key) {
return success(settingService.getBySettingKey(key));
final User loginUser = getLoginUser();
if(loginUser != null){
return success(settingService.getBySettingKey(key));
}
return fail("请先登录", null);
}
@ApiOperation("根据key更新系统设置")
@OperationLog
@PutMapping("/updateByKey")
public ApiResult<?> updateByKey(@RequestBody Setting setting) {
final User loginUser = getLoginUser();
if(loginUser == null){
return fail("请先登录");
}
if(!loginUser.getIsSuperAdmin()){
return fail("权限不足");
}
return success(settingService.updateByKey(setting));
}
@PreAuthorize("hasAuthority('sys:setting:save')")

View File

@@ -57,4 +57,6 @@ public interface SettingService extends IService<Setting> {
Config getConfig(Integer tenantId);
JSONObject getUploadConfig(Integer tenantId);
boolean updateByKey(Setting key);
}

View File

@@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.config.ConfigProperties;
import com.gxwebsoft.common.core.exception.BusinessException;
import com.gxwebsoft.common.core.utils.JSONUtil;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
@@ -93,6 +95,7 @@ public class SettingServiceImpl extends ServiceImpl<SettingMapper, Setting> impl
if ("printer".equals(key)) {
throw new BusinessException("打印机未配置");
}
return new JSONObject();
}
return JSON.parseObject(setting.getContent());
}
@@ -176,4 +179,9 @@ public class SettingServiceImpl extends ServiceImpl<SettingMapper, Setting> impl
return settingInfo;
}
@Override
public boolean updateByKey(Setting setting) {
return update(setting, new QueryWrapper<Setting>().eq("setting_key", setting.getSettingKey()));
}
}