Commit 944d960f LN

新增客户端自定义配置功能

1 个父辈 eb3f2377
......@@ -109,4 +109,7 @@ public class Constants {
*/
public static final String CACHE_msdSetting="msdSetting";
public static final String CACHE_clientSetting="clientSetting";
}
package com.neotel.smfcore.core.system.rest;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.SecurityUtils;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.system.rest.bean.dto.ClientSettingDto;
import com.neotel.smfcore.core.system.rest.bean.dto.SysSettingsDto;
import com.neotel.smfcore.core.system.service.po.Settings;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@Slf4j
@Api(tags = "界面:设置")
@RestController
@RequestMapping("/api/clientSettings")
@RequiredArgsConstructor
public class ClientSettingsController {
@Autowired
DataCache dataCache;
@ApiOperation("获取界面设置")
@GetMapping()
@PreAuthorize("@el.check('sysSetting')")
public ClientSettingDto getSettings(ClientSettingDto settingDto) {
if (settingDto == null || ObjectUtil.isEmpty(settingDto.getKey()) ) {
throw new ValidateException("smfcode.valueCanotNull", "{0}不能为空", new String[]{"key"});
}
//先查找自己的用户名,没找到时再找admin
String userName = SecurityUtils.getCurrentUsername();
String key = Constants.CACHE_clientSetting + "_" + userName + "_" + settingDto.getKey();
String value = dataCache.getCache(key);
if (ObjectUtil.isEmpty(value)) {
if (!userName.equals(Constants.SUPER_USERNAME)) {
key = Constants.CACHE_clientSetting + "_" + Constants.SUPER_USERNAME + "_" + settingDto.getKey();
value = dataCache.getCache(key);
}
}
settingDto.setValue(value);
return settingDto;
}
@ApiOperation("修改界面设置")
@PutMapping()
@PreAuthorize("@el.check('sysSetting')")
public ResultBean updateSettings(@RequestBody ClientSettingDto settingDto) {
if (settingDto == null || ObjectUtil.isEmpty(settingDto.getKey()) || ObjectUtil.isEmpty(settingDto.getValue())) {
throw new ValidateException("smfcode.valueCanotNull", "{0}不能为空", new String[]{"key"});
}
String userName = SecurityUtils.getCurrentUsername();
String key = Constants.CACHE_clientSetting + "_" + userName + "_" + settingDto.getKey();
dataCache.updateCache(key, settingDto.getValue());
// log.info("修改界面配置:[" + key + "]=[" + settingDto.getValue() + "]");
return ResultBean.newOkResult("");
}
}
package com.neotel.smfcore.core.system.rest.bean.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
@Getter
@Setter
public class ClientSettingDto implements Serializable {
@ApiModelProperty("设置的key")
private String key;
@ApiModelProperty("设置的值")
private String value;
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!