完成参数配置
This commit is contained in:
parent
35a01cbf29
commit
d2fa839d3c
|
@ -1,48 +1,48 @@
|
|||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.system.domain.SysUserOnline;
|
||||
|
||||
/**
|
||||
* 在线用户 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ISysUserOnlineService
|
||||
{
|
||||
/**
|
||||
* 通过登录地址查询信息
|
||||
*
|
||||
* @param ipaddr 登录地址
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user);
|
||||
|
||||
/**
|
||||
* 通过用户名称查询信息
|
||||
*
|
||||
* @param userName 用户名称
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public SysUserOnline selectOnlineByUserName(String userName, LoginUser user);
|
||||
|
||||
/**
|
||||
* 通过登录地址/用户名称查询信息
|
||||
*
|
||||
* @param ipaddr 登录地址
|
||||
* @param userName 用户名称
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user);
|
||||
|
||||
/**
|
||||
* 设置在线用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 在线用户
|
||||
*/
|
||||
public SysUserOnline loginUserToUserOnline(LoginUser user);
|
||||
}
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.system.domain.SysUserOnline;
|
||||
|
||||
/**
|
||||
* 在线用户 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ISysUserOnlineService
|
||||
{
|
||||
/**
|
||||
* 通过登录地址查询信息
|
||||
*
|
||||
* @param ipaddr 登录地址
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user);
|
||||
|
||||
/**
|
||||
* 通过用户名称查询信息
|
||||
*
|
||||
* @param userName 用户名称
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public SysUserOnline selectOnlineByUserName(String userName, LoginUser user);
|
||||
|
||||
/**
|
||||
* 通过登录地址/用户名称查询信息
|
||||
*
|
||||
* @param ipaddr 登录地址
|
||||
* @param userName 用户名称
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user);
|
||||
|
||||
/**
|
||||
* 设置在线用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 在线用户
|
||||
*/
|
||||
public SysUserOnline loginUserToUserOnline(LoginUser user);
|
||||
}
|
|
@ -1,35 +1,35 @@
|
|||
package com.ruoyi.system.domain;
|
||||
|
||||
/**
|
||||
* 当前在线会话
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class SysUserOnline
|
||||
{
|
||||
/** 会话编号 */
|
||||
private String tokenId;
|
||||
|
||||
/** 部门名称 */
|
||||
private String deptName;
|
||||
|
||||
/** 用户名称 */
|
||||
private String userName;
|
||||
|
||||
/** 登录IP地址 */
|
||||
private String ipaddr;
|
||||
|
||||
/** 登录地址 */
|
||||
private String loginLocation;
|
||||
|
||||
/** 浏览器类型 */
|
||||
private String browser;
|
||||
|
||||
/** 操作系统 */
|
||||
private String os;
|
||||
|
||||
/** 登录时间 */
|
||||
private Long loginTime;
|
||||
|
||||
|
||||
}
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
/**
|
||||
* 当前在线会话
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class SysUserOnline
|
||||
{
|
||||
/** 会话编号 */
|
||||
private String tokenId;
|
||||
|
||||
/** 部门名称 */
|
||||
private String deptName;
|
||||
|
||||
/** 用户名称 */
|
||||
private String userName;
|
||||
|
||||
/** 登录IP地址 */
|
||||
private String ipaddr;
|
||||
|
||||
/** 登录地址 */
|
||||
private String loginLocation;
|
||||
|
||||
/** 浏览器类型 */
|
||||
private String browser;
|
||||
|
||||
/** 操作系统 */
|
||||
private String os;
|
||||
|
||||
/** 登录时间 */
|
||||
private Long loginTime;
|
||||
|
||||
|
||||
}
|
|
@ -1,86 +1,86 @@
|
|||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.SysUserOnline;
|
||||
import com.ruoyi.system.service.ISysUserOnlineService;
|
||||
|
||||
/**
|
||||
* 在线用户 服务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysUserOnlineServiceImpl implements ISysUserOnlineService {
|
||||
/**
|
||||
* 通过登录地址查询信息
|
||||
*
|
||||
* @param ipaddr 登录地址
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
@Override
|
||||
public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) {
|
||||
if (StringUtils.equals(ipaddr, user.getIpaddr())) {
|
||||
return loginUserToUserOnline(user);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名称查询信息
|
||||
*
|
||||
* @param userName 用户名称
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
@Override
|
||||
public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) {
|
||||
if (StringUtils.equals(userName, user.getUsername())) {
|
||||
return loginUserToUserOnline(user);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过登录地址/用户名称查询信息
|
||||
*
|
||||
* @param ipaddr 登录地址
|
||||
* @param userName 用户名称
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
@Override
|
||||
public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) {
|
||||
if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) {
|
||||
return loginUserToUserOnline(user);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置在线用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 在线用户
|
||||
*/
|
||||
@Override
|
||||
public SysUserOnline loginUserToUserOnline(LoginUser user) {
|
||||
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUser())) {
|
||||
return null;
|
||||
}
|
||||
SysUserOnline sysUserOnline = new SysUserOnline();
|
||||
sysUserOnline.setTokenId(user.getToken());
|
||||
sysUserOnline.setUserName(user.getUsername());
|
||||
sysUserOnline.setIpaddr(user.getIpaddr());
|
||||
sysUserOnline.setLoginLocation(user.getLoginLocation());
|
||||
sysUserOnline.setBrowser(user.getBrowser());
|
||||
sysUserOnline.setOs(user.getOs());
|
||||
sysUserOnline.setLoginTime(user.getLoginTime());
|
||||
if (StringUtils.isNotNull(user.getUser().getDept())) {
|
||||
sysUserOnline.setDeptName(user.getUser().getDept().getDeptName());
|
||||
}
|
||||
return sysUserOnline;
|
||||
}
|
||||
}
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.SysUserOnline;
|
||||
import com.ruoyi.system.service.ISysUserOnlineService;
|
||||
|
||||
/**
|
||||
* 在线用户 服务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysUserOnlineServiceImpl implements ISysUserOnlineService {
|
||||
/**
|
||||
* 通过登录地址查询信息
|
||||
*
|
||||
* @param ipaddr 登录地址
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
@Override
|
||||
public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) {
|
||||
if (StringUtils.equals(ipaddr, user.getIpaddr())) {
|
||||
return loginUserToUserOnline(user);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名称查询信息
|
||||
*
|
||||
* @param userName 用户名称
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
@Override
|
||||
public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) {
|
||||
if (StringUtils.equals(userName, user.getUsername())) {
|
||||
return loginUserToUserOnline(user);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过登录地址/用户名称查询信息
|
||||
*
|
||||
* @param ipaddr 登录地址
|
||||
* @param userName 用户名称
|
||||
* @param user 用户信息
|
||||
* @return 在线用户信息
|
||||
*/
|
||||
@Override
|
||||
public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) {
|
||||
if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) {
|
||||
return loginUserToUserOnline(user);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置在线用户信息
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 在线用户
|
||||
*/
|
||||
@Override
|
||||
public SysUserOnline loginUserToUserOnline(LoginUser user) {
|
||||
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUser())) {
|
||||
return null;
|
||||
}
|
||||
SysUserOnline sysUserOnline = new SysUserOnline();
|
||||
sysUserOnline.setTokenId(user.getToken());
|
||||
sysUserOnline.setUserName(user.getUsername());
|
||||
sysUserOnline.setIpaddr(user.getIpaddr());
|
||||
sysUserOnline.setLoginLocation(user.getLoginLocation());
|
||||
sysUserOnline.setBrowser(user.getBrowser());
|
||||
sysUserOnline.setOs(user.getOs());
|
||||
sysUserOnline.setLoginTime(user.getLoginTime());
|
||||
if (StringUtils.isNotNull(user.getUser().getDept())) {
|
||||
sysUserOnline.setDeptName(user.getUser().getDept().getDeptName());
|
||||
}
|
||||
return sysUserOnline;
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
package com.ruoyi.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.annotation.RepeatSubmit;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.system.domain.SysConfig;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
|
||||
/**
|
||||
* 参数配置 信息操作处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/config")
|
||||
public class SysConfigController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ISysConfigService configService;
|
||||
|
||||
/**
|
||||
* 获取参数配置列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:config:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SysConfig config) {
|
||||
startPage();
|
||||
List<SysConfig> list = configService.selectConfigList(config);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@Log(title = "参数管理", businessType = BusinessType.EXPORT)
|
||||
@PreAuthorize("@ss.hasPermi('system:config:export')")
|
||||
@GetMapping("/export")
|
||||
public AjaxResult export(SysConfig config) {
|
||||
List<SysConfig> list = configService.selectConfigList(config);
|
||||
ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class);
|
||||
return util.exportExcel(list, "参数数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数编号获取详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:config:query')")
|
||||
@GetMapping(value = "/{configId}")
|
||||
public AjaxResult getInfo(@PathVariable Long configId) {
|
||||
return AjaxResult.success(configService.selectConfigById(configId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数键名查询参数值
|
||||
*/
|
||||
@GetMapping(value = "/configKey/{configKey}")
|
||||
public AjaxResult getConfigKey(@PathVariable String configKey) {
|
||||
return AjaxResult.success(configService.selectConfigByKey(configKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增参数配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:config:add')")
|
||||
@Log(title = "参数管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@RepeatSubmit
|
||||
public AjaxResult add(@Validated @RequestBody SysConfig config) {
|
||||
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
|
||||
return AjaxResult.error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||
}
|
||||
config.setCreateBy(SecurityUtils.getUsername());
|
||||
return toAjax(configService.insertConfig(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改参数配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:config:edit')")
|
||||
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody SysConfig config) {
|
||||
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
|
||||
return AjaxResult.error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||
}
|
||||
config.setUpdateBy(SecurityUtils.getUsername());
|
||||
return toAjax(configService.updateConfig(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除参数配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:config:remove')")
|
||||
@Log(title = "参数管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{configIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] configIds) {
|
||||
return toAjax(configService.deleteConfigByIds(configIds));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.annotation.DataSource;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.enums.DataSourceType;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.SysConfig;
|
||||
import com.ruoyi.system.mapper.SysConfigMapper;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
|
||||
/**
|
||||
* 参数配置 服务层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysConfigServiceImpl implements ISysConfigService {
|
||||
@Autowired
|
||||
private SysConfigMapper configMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
/**
|
||||
* 项目启动时,初始化参数到缓存
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
|
||||
for (SysConfig config : configsList) {
|
||||
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询参数配置信息
|
||||
*
|
||||
* @param configId 参数配置ID
|
||||
* @return 参数配置信息
|
||||
*/
|
||||
@Override
|
||||
@DataSource(DataSourceType.MASTER)
|
||||
public SysConfig selectConfigById(Long configId) {
|
||||
SysConfig config = new SysConfig();
|
||||
config.setConfigId(configId);
|
||||
return configMapper.selectConfig(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据键名查询参数配置信息
|
||||
*
|
||||
* @param configKey 参数key
|
||||
* @return 参数键值
|
||||
*/
|
||||
@Override
|
||||
public String selectConfigByKey(String configKey) {
|
||||
String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
|
||||
if (StringUtils.isNotEmpty(configValue)) {
|
||||
return configValue;
|
||||
}
|
||||
SysConfig config = new SysConfig();
|
||||
config.setConfigKey(configKey);
|
||||
SysConfig retConfig = configMapper.selectConfig(config);
|
||||
if (StringUtils.isNotNull(retConfig)) {
|
||||
redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
|
||||
return retConfig.getConfigValue();
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询参数配置列表
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 参数配置集合
|
||||
*/
|
||||
@Override
|
||||
public List<SysConfig> selectConfigList(SysConfig config) {
|
||||
return configMapper.selectConfigList(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增参数配置
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertConfig(SysConfig config) {
|
||||
int row = configMapper.insertConfig(config);
|
||||
if (row > 0) {
|
||||
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改参数配置
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateConfig(SysConfig config) {
|
||||
int row = configMapper.updateConfig(config);
|
||||
if (row > 0) {
|
||||
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除参数信息
|
||||
*
|
||||
* @param configIds 需要删除的参数ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteConfigByIds(Long[] configIds) {
|
||||
for (Long configId : configIds) {
|
||||
SysConfig config = selectConfigById(configId);
|
||||
if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
|
||||
throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
|
||||
}
|
||||
}
|
||||
int count = configMapper.deleteConfigByIds(configIds);
|
||||
if (count > 0) {
|
||||
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
|
||||
redisCache.deleteObject(keys);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空缓存数据
|
||||
*/
|
||||
@Override
|
||||
public void clearCache() {
|
||||
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
|
||||
redisCache.deleteObject(keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验参数键名是否唯一
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String checkConfigKeyUnique(SysConfig config) {
|
||||
Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
|
||||
SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());
|
||||
if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置cache key
|
||||
*
|
||||
* @param configKey 参数键
|
||||
* @return 缓存键key
|
||||
*/
|
||||
private String getCacheKey(String configKey) {
|
||||
return Constants.SYS_CONFIG_KEY + configKey;
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ import request from '@/utils/request'
|
|||
// 查询参数列表
|
||||
export function listConfig(query) {
|
||||
return request({
|
||||
url: '/system/config/list',
|
||||
url: '/system/config/page',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
|
@ -12,7 +12,7 @@ export function listConfig(query) {
|
|||
// 查询参数详细
|
||||
export function getConfig(configId) {
|
||||
return request({
|
||||
url: '/system/config/' + configId,
|
||||
url: '/system/config/get?id=' + configId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ export function getConfig(configId) {
|
|||
// 根据参数键名查询参数值
|
||||
export function getConfigKey(configKey) {
|
||||
return request({
|
||||
url: '/system/config/configKey/' + configKey,
|
||||
url: '/system/config/get-value-by-key?key=' + configKey,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ export function getConfigKey(configKey) {
|
|||
// 新增参数配置
|
||||
export function addConfig(data) {
|
||||
return request({
|
||||
url: '/system/config',
|
||||
url: '/system/config/create',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
|
@ -37,7 +37,7 @@ export function addConfig(data) {
|
|||
// 修改参数配置
|
||||
export function updateConfig(data) {
|
||||
return request({
|
||||
url: '/system/config',
|
||||
url: '/system/config/update',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
|
@ -46,15 +46,7 @@ export function updateConfig(data) {
|
|||
// 删除参数配置
|
||||
export function delConfig(configId) {
|
||||
return request({
|
||||
url: '/system/config/' + configId,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
// 清理参数缓存
|
||||
export function clearCache() {
|
||||
return request({
|
||||
url: '/system/config/clearCache',
|
||||
url: '/system/config/delete?id=' + configId,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
@ -64,6 +56,7 @@ export function exportConfig(query) {
|
|||
return request({
|
||||
url: '/system/config/export',
|
||||
method: 'get',
|
||||
params: query
|
||||
params: query,
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ export const DICT_TYPE = {
|
|||
SYS_USER_SEX: 'sys_user_sex',
|
||||
SYS_NOTICE_TYPE: 'sys_notice_type',
|
||||
SYS_OPERATE_TYPE: 'sys_operate_type',
|
||||
SYS_LOGIN_RESULT: 'sys_login_result'
|
||||
SYS_LOGIN_RESULT: 'sys_login_result',
|
||||
SYS_CONFIG_TYPE: 'sys_config_type',
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
|
||||
<el-form-item label="参数名称" prop="configName">
|
||||
<el-form-item label="参数名称" prop="name">
|
||||
<el-input
|
||||
v-model="queryParams.configName"
|
||||
v-model="queryParams.name"
|
||||
placeholder="请输入参数名称"
|
||||
clearable
|
||||
size="small"
|
||||
|
@ -11,9 +11,9 @@
|
|||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="参数键名" prop="configKey">
|
||||
<el-form-item label="参数键名" prop="key">
|
||||
<el-input
|
||||
v-model="queryParams.configKey"
|
||||
v-model="queryParams.key"
|
||||
placeholder="请输入参数键名"
|
||||
clearable
|
||||
size="small"
|
||||
|
@ -21,13 +21,13 @@
|
|||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="系统内置" prop="configType">
|
||||
<el-select v-model="queryParams.configType" placeholder="系统内置" clearable size="small">
|
||||
<el-form-item label="系统内置" prop="type">
|
||||
<el-select v-model="queryParams.type" placeholder="系统内置" clearable size="small">
|
||||
<el-option
|
||||
v-for="dict in typeOptions"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictLabel"
|
||||
:value="dict.dictValue"
|
||||
v-for="dict in this.getDictDatas(DICT_TYPE.SYS_CONFIG_TYPE)"
|
||||
:key="parseInt(dict.value)"
|
||||
:label="dict.label"
|
||||
:value="parseInt(dict.value)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
@ -59,26 +59,6 @@
|
|||
v-hasPermi="['system:config:add']"
|
||||
>新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="success"
|
||||
icon="el-icon-edit"
|
||||
size="mini"
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
v-hasPermi="['system:config:edit']"
|
||||
>修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
v-hasPermi="['system:config:remove']"
|
||||
>删除</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="warning"
|
||||
|
@ -88,25 +68,25 @@
|
|||
v-hasPermi="['system:config:export']"
|
||||
>导出</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-refresh"
|
||||
size="mini"
|
||||
@click="handleClearCache"
|
||||
v-hasPermi="['system:config:remove']"
|
||||
>清理缓存</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="参数主键" align="center" prop="configId" />
|
||||
<el-table-column label="参数名称" align="center" prop="configName" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="参数键名" align="center" prop="configKey" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="参数键值" align="center" prop="configValue" />
|
||||
<el-table-column label="系统内置" align="center" prop="configType" :formatter="typeFormat" />
|
||||
<el-table v-loading="loading" :data="configList">
|
||||
<el-table-column label="参数主键" align="center" prop="id" />
|
||||
<el-table-column label="参数分组" align="center" prop="group" />
|
||||
<el-table-column label="参数名称" align="center" prop="name" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="参数键名" align="center" prop="key" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="参数键值" align="center" prop="value" />
|
||||
<el-table-column label="系统内置" align="center" prop="type">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ getDictDataLabel(DICT_TYPE.SYS_CONFIG_TYPE, scope.row.type) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="是否敏感" align="center" prop="sensitive">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.sensitive ? '是' : '否' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
||||
<template slot-scope="scope">
|
||||
|
@ -136,7 +116,7 @@
|
|||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:page.sync="queryParams.pageNo"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
@ -144,22 +124,22 @@
|
|||
<!-- 添加或修改参数配置对话框 -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="参数名称" prop="configName">
|
||||
<el-input v-model="form.configName" placeholder="请输入参数名称" />
|
||||
<el-form-item label="参数分组" prop="group">
|
||||
<el-input v-model="form.group" placeholder="请输入参数分组" />
|
||||
</el-form-item>
|
||||
<el-form-item label="参数键名" prop="configKey">
|
||||
<el-input v-model="form.configKey" placeholder="请输入参数键名" />
|
||||
<el-form-item label="参数名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入参数名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="参数键值" prop="configValue">
|
||||
<el-input v-model="form.configValue" placeholder="请输入参数键值" />
|
||||
<el-form-item label="参数键名" prop="key">
|
||||
<el-input v-model="form.key" placeholder="请输入参数键名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="系统内置" prop="configType">
|
||||
<el-radio-group v-model="form.configType">
|
||||
<el-radio
|
||||
v-for="dict in typeOptions"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictValue"
|
||||
>{{dict.dictLabel}}</el-radio>
|
||||
<el-form-item label="参数键值" prop="value">
|
||||
<el-input v-model="form.value" placeholder="请输入参数键值" />
|
||||
</el-form-item>
|
||||
<el-form-item label="是否敏感" prop="type">
|
||||
<el-radio-group v-model="form.sensitive">
|
||||
<el-radio :key="true" :label="true">是</el-radio>
|
||||
<el-radio :key="false" :label="false">否</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
|
@ -175,7 +155,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig, clearCache } from "@/api/system/config";
|
||||
import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig } from "@/api/system/config";
|
||||
|
||||
export default {
|
||||
name: "Config",
|
||||
|
@ -183,12 +163,6 @@ export default {
|
|||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 总条数
|
||||
|
@ -205,23 +179,26 @@ export default {
|
|||
dateRange: [],
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
configName: undefined,
|
||||
configKey: undefined,
|
||||
configType: undefined
|
||||
name: undefined,
|
||||
key: undefined,
|
||||
type: undefined
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 表单校验
|
||||
rules: {
|
||||
configName: [
|
||||
group: [
|
||||
{ required: true, message: "参数分组不能为空", trigger: "blur" }
|
||||
],
|
||||
name: [
|
||||
{ required: true, message: "参数名称不能为空", trigger: "blur" }
|
||||
],
|
||||
configKey: [
|
||||
key: [
|
||||
{ required: true, message: "参数键名不能为空", trigger: "blur" }
|
||||
],
|
||||
configValue: [
|
||||
value: [
|
||||
{ required: true, message: "参数键值不能为空", trigger: "blur" }
|
||||
]
|
||||
}
|
||||
|
@ -229,24 +206,24 @@ export default {
|
|||
},
|
||||
created() {
|
||||
this.getList();
|
||||
this.getDicts("sys_yes_no").then(response => {
|
||||
this.typeOptions = response.data;
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
/** 查询参数列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
|
||||
this.configList = response.rows;
|
||||
this.total = response.total;
|
||||
listConfig(this.addDateRange(this.queryParams, [
|
||||
this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
|
||||
this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
|
||||
])).then(response => {
|
||||
this.configList = response.data.list;
|
||||
this.total = response.data.total;
|
||||
this.loading = false;
|
||||
}
|
||||
);
|
||||
},
|
||||
// 参数系统内置字典翻译
|
||||
typeFormat(row, column) {
|
||||
return this.selectDictLabel(this.typeOptions, row.configType);
|
||||
return this.selectDictLabel(this.typeOptions, row.type);
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
|
@ -256,18 +233,17 @@ export default {
|
|||
// 表单重置
|
||||
reset() {
|
||||
this.form = {
|
||||
configId: undefined,
|
||||
configName: undefined,
|
||||
configKey: undefined,
|
||||
configValue: undefined,
|
||||
configType: "Y",
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
key: undefined,
|
||||
value: undefined,
|
||||
remark: undefined
|
||||
};
|
||||
this.resetForm("form");
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1;
|
||||
this.queryParams.pageNo = 1;
|
||||
this.getList();
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
|
@ -282,17 +258,11 @@ export default {
|
|||
this.open = true;
|
||||
this.title = "添加参数";
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map(item => item.configId)
|
||||
this.single = selection.length!=1
|
||||
this.multiple = !selection.length
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const configId = row.configId || this.ids
|
||||
getConfig(configId).then(response => {
|
||||
const id = row.id || this.ids
|
||||
getConfig(id).then(response => {
|
||||
this.form = response.data;
|
||||
this.open = true;
|
||||
this.title = "修改参数";
|
||||
|
@ -302,7 +272,7 @@ export default {
|
|||
submitForm: function() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.configId != undefined) {
|
||||
if (this.form.id !== undefined) {
|
||||
updateConfig(this.form).then(response => {
|
||||
this.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
|
@ -320,13 +290,13 @@ export default {
|
|||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const configIds = row.configId || this.ids;
|
||||
this.$confirm('是否确认删除参数编号为"' + configIds + '"的数据项?', "警告", {
|
||||
const ids = row.id || this.ids;
|
||||
this.$confirm('是否确认删除参数编号为"' + ids + '"的数据项?', "警告", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(function() {
|
||||
return delConfig(configIds);
|
||||
return delConfig(ids);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.msgSuccess("删除成功");
|
||||
|
@ -342,15 +312,9 @@ export default {
|
|||
}).then(function() {
|
||||
return exportConfig(queryParams);
|
||||
}).then(response => {
|
||||
this.download(response.msg);
|
||||
this.downloadExcel(response, '参数配置.xls');
|
||||
})
|
||||
},
|
||||
/** 清理缓存按钮操作 */
|
||||
handleClearCache() {
|
||||
clearCache().then(response => {
|
||||
this.msgSuccess("清理成功");
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
@ -1,8 +1,26 @@
|
|||
package cn.iocoder.dashboard.modules.system.controller.config;
|
||||
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.config.SysConfigConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.config.SysConfigService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE;
|
||||
|
||||
@Api(tags = "参数配置")
|
||||
@RestController
|
||||
|
@ -24,4 +42,78 @@ public class SysConfigController {
|
|||
//
|
||||
// }
|
||||
|
||||
@Resource
|
||||
private SysConfigService configService;
|
||||
|
||||
@ApiOperation("获取参数配置分页")
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:list')")
|
||||
public CommonResult<PageResult<SysConfigRespVO>> getConfigPage(@Validated SysConfigPageReqVO reqVO) {
|
||||
PageResult<SysConfigDO> page = configService.getConfigPage(reqVO);
|
||||
return success(SysConfigConvert.INSTANCE.convertPage(page));
|
||||
}
|
||||
|
||||
@ApiOperation("导出参数配置")
|
||||
@GetMapping("/export")
|
||||
// @Log(title = "参数管理", businessType = BusinessType.EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:export')")
|
||||
public void exportSysConfig(HttpServletResponse response, @Validated SysConfigExportReqVO reqVO) throws IOException {
|
||||
List<SysConfigDO> list = configService.getConfigList(reqVO);
|
||||
// 拼接数据
|
||||
List<SysConfigExcelVO> excelDataList = SysConfigConvert.INSTANCE.convertList(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "参数配置.xls", "配置列表",
|
||||
SysConfigExcelVO.class, excelDataList);
|
||||
}
|
||||
|
||||
@ApiOperation("获得参数配置")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@GetMapping(value = "/get")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:query')")
|
||||
public CommonResult<SysConfigRespVO> getConfig(@RequestParam("id") Long id) {
|
||||
return success(SysConfigConvert.INSTANCE.convert(configService.getConfig(id)));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端")
|
||||
@ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class)
|
||||
@GetMapping(value = "/get-value-by-key")
|
||||
public CommonResult<String> getConfigKey(@RequestParam("key") String key) {
|
||||
SysConfigDO config = configService.getConfigByKey(key);
|
||||
if (config == null) {
|
||||
return null;
|
||||
}
|
||||
if (config.getSensitive()) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_GET_VALUE_ERROR_IF_SENSITIVE);
|
||||
}
|
||||
return success(config.getValue());
|
||||
}
|
||||
|
||||
@ApiOperation("新增参数配置")
|
||||
@PostMapping("/create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:add')")
|
||||
// @Log(title = "参数管理", businessType = BusinessType.INSERT)
|
||||
// @RepeatSubmit
|
||||
public CommonResult<Long> createConfig(@Validated @RequestBody SysConfigCreateReqVO reqVO) {
|
||||
return success(configService.createConfig(reqVO));
|
||||
}
|
||||
|
||||
@ApiOperation("修改参数配置")
|
||||
@PutMapping("/update")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:edit')")
|
||||
// @Log(title = "参数管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> edit(@Validated @RequestBody SysConfigUpdateReqVO reqVO) {
|
||||
configService.updateConfig(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("删除参数配置")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@DeleteMapping("/delete")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:remove')")
|
||||
// @Log(title = "参数管理", businessType = BusinessType.DELETE)
|
||||
public CommonResult<Boolean> deleteConfig(@RequestParam("id") Long id) {
|
||||
configService.deleteConfig(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import lombok.Data;
|
|||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
|
@ -29,11 +30,8 @@ public class SysConfigBaseVO {
|
|||
@Size(max = 500, message = "参数键值长度不能超过500个字符")
|
||||
private String value;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", required = true, example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "是否敏感", required = true, example = "true")
|
||||
@NotBlank(message = "是否敏感不能为空")
|
||||
@NotNull(message = "是否敏感不能为空")
|
||||
private Boolean sensitive;
|
||||
|
||||
@ApiModelProperty(value = "备注", example = "备注一下很帅气!")
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptBaseVO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
@ -12,7 +11,7 @@ import javax.validation.constraints.Size;
|
|||
@ApiModel("参数配置创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysConfigCreateReqVO extends SysDeptBaseVO {
|
||||
public class SysConfigCreateReqVO extends SysConfigBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "参数键名", required = true, example = "yunai.db.username")
|
||||
@NotBlank(message = "参数键名长度不能为空")
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.dashboard.modules.system.enums.dict.SysDictTypeEnum;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -26,10 +29,12 @@ public class SysConfigExcelVO {
|
|||
@ExcelProperty("参数键值")
|
||||
private String value;
|
||||
|
||||
@ExcelProperty("参数类型")
|
||||
private String type;
|
||||
@ExcelProperty(value = "参数类型", converter = DictConvert.class)
|
||||
@DictFormat(SysDictTypeEnum.SYS_CONFIG_TYPE)
|
||||
private Integer type;
|
||||
|
||||
@ExcelProperty("是否敏感")
|
||||
@ExcelProperty(value = "是否敏感", converter = DictConvert.class)
|
||||
@DictFormat(SysDictTypeEnum.SYS_BOOLEAN_STRING)
|
||||
private Boolean sensitive;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("参数配置导出 Request VO")
|
||||
@Data
|
||||
public class SysConfigExportReqVO {
|
||||
|
||||
@ApiModelProperty(value = "参数名称", example = "模糊匹配")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "参数键名", example = "yunai.db.username", notes = "模糊匹配")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "开始时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("参数配置分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysConfigPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "参数名称", example = "模糊匹配")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "参数键名", example = "yunai.db.username", notes = "模糊匹配")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "开始时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
}
|
|
@ -22,6 +22,9 @@ public class SysConfigRespVO extends SysConfigBaseVO {
|
|||
@Size(max = 100, message = "参数键名长度不能超过100个字符")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", required = true, example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
|
||||
private Date createTime;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptBaseVO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
@ -11,7 +10,7 @@ import javax.validation.constraints.NotNull;
|
|||
@ApiModel("参数配置创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysConfigUpdateReqVO extends SysDeptBaseVO {
|
||||
public class SysConfigUpdateReqVO extends SysConfigBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "参数配置序号", required = true, example = "1024")
|
||||
@NotNull(message = "参数配置编号不能为空")
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package cn.iocoder.dashboard.modules.system.convert.config;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExcelVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysConfigConvert {
|
||||
|
||||
SysConfigConvert INSTANCE = Mappers.getMapper(SysConfigConvert.class);
|
||||
|
||||
PageResult<SysConfigRespVO> convertPage(PageResult<SysConfigDO> page);
|
||||
|
||||
SysConfigRespVO convert(SysConfigDO bean);
|
||||
|
||||
SysConfigDO convert(SysConfigCreateReqVO bean);
|
||||
|
||||
SysConfigDO convert(SysConfigUpdateReqVO bean);
|
||||
|
||||
List<SysConfigExcelVO> convertList(List<SysConfigDO> list);
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.config;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysConfigMapper extends BaseMapperX<SysConfigDO> {
|
||||
|
||||
default PageResult<SysConfigDO> selectPage(SysConfigPageReqVO reqVO) {
|
||||
return selectPage(reqVO,
|
||||
new QueryWrapperX<SysConfigDO>().likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("`key`", reqVO.getKey())
|
||||
.eqIfPresent("`type`", reqVO.getType())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
}
|
||||
|
||||
default SysConfigDO selectByKey(String key) {
|
||||
return selectOne(new QueryWrapper<SysConfigDO>().eq("`key`", key));
|
||||
}
|
||||
|
||||
default List<SysConfigDO> selectList(SysConfigExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<SysConfigDO>().likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("`key`", reqVO.getKey())
|
||||
.eqIfPresent("`type`", reqVO.getType())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
}
|
||||
|
||||
}
|
|
@ -2,7 +2,11 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config;
|
|||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.dashboard.modules.system.enums.config.SysConfigTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 参数配置表
|
||||
|
@ -10,6 +14,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||
* @author ruoyi
|
||||
*/
|
||||
@TableName("sys_config")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SysConfigDO extends BaseDO {
|
||||
|
||||
/**
|
||||
|
@ -19,6 +26,7 @@ public class SysConfigDO extends BaseDO {
|
|||
/**
|
||||
* 参数分组
|
||||
*/
|
||||
@TableField("`group`")
|
||||
private String group;
|
||||
/**
|
||||
* 参数名称
|
||||
|
@ -27,6 +35,7 @@ public class SysConfigDO extends BaseDO {
|
|||
/**
|
||||
* 参数键名
|
||||
*/
|
||||
@TableField("`key`")
|
||||
private String key;
|
||||
/**
|
||||
* 参数键值
|
||||
|
@ -37,12 +46,14 @@ public class SysConfigDO extends BaseDO {
|
|||
*
|
||||
* 枚举 {@link SysConfigTypeEnum}
|
||||
*/
|
||||
private String type;
|
||||
@TableField("`type`")
|
||||
private Integer type;
|
||||
/**
|
||||
* 是否敏感
|
||||
*
|
||||
* 对于敏感配置,需要管理权限才能查看
|
||||
*/
|
||||
@TableField("`sensitive`")
|
||||
private Boolean sensitive;
|
||||
/**
|
||||
* 备注
|
||||
|
|
|
@ -74,4 +74,10 @@ public interface SysErrorCodeConstants {
|
|||
|
||||
// ========== 文件 1002009000 ==========
|
||||
ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在");
|
||||
|
||||
// ========== 参数配置 1002010000 ==========
|
||||
ErrorCode CONFIG_NOT_FOUND = new ErrorCode(1002010001, "参数配置不存在");
|
||||
ErrorCode CONFIG_NAME_DUPLICATE = new ErrorCode(1002010002, "参数配置 key 重复");
|
||||
ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1002010003, "不能删除类型为系统内置的参数配置");
|
||||
ErrorCode CONFIG_GET_VALUE_ERROR_IF_SENSITIVE = new ErrorCode(1002010004, "不允许获取敏感配置到前端");
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ public enum SysDictTypeEnum {
|
|||
SYS_COMMON_STATUS("sys_common_status"), // 系统状态
|
||||
SYS_OPERATE_TYPE("sys_operate_type"), // 操作类型
|
||||
SYS_LOGIN_RESULT("sys_login_result"), // 登陆结果
|
||||
SYS_CONFIG_TYPE("sys_config_type"), // 参数配置类型
|
||||
SYS_BOOLEAN_STRING("sys_boolean_string"), // Boolean 是否类型
|
||||
;
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package cn.iocoder.dashboard.modules.system.service.config;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参数配置 Service 接口
|
||||
*/
|
||||
public interface SysConfigService {
|
||||
|
||||
/**
|
||||
* 获得参数配置分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 分页列表
|
||||
*/
|
||||
PageResult<SysConfigDO> getConfigPage(SysConfigPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得参数配置列表
|
||||
*
|
||||
* @param reqVO 列表
|
||||
* @return 列表
|
||||
*/
|
||||
List<SysConfigDO> getConfigList(SysConfigExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得参数配置
|
||||
*
|
||||
* @param id 配置编号
|
||||
* @return 参数配置
|
||||
*/
|
||||
SysConfigDO getConfig(Long id);
|
||||
|
||||
/**
|
||||
* 根据参数键,获得参数配置
|
||||
*
|
||||
* @param key 配置键
|
||||
* @return 参数配置
|
||||
*/
|
||||
SysConfigDO getConfigByKey(String key);
|
||||
|
||||
/**
|
||||
* 创建参数配置
|
||||
*
|
||||
* @param reqVO 创建信息
|
||||
* @return 配置编号
|
||||
*/
|
||||
Long createConfig(SysConfigCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新参数配置
|
||||
*
|
||||
* @param reqVO 更新信息
|
||||
*/
|
||||
void updateConfig(SysConfigUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除参数配置
|
||||
*
|
||||
* @param id 配置编号
|
||||
*/
|
||||
void deleteConfig(Long id);
|
||||
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package cn.iocoder.dashboard.modules.system.service.config.impl;
|
||||
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.config.SysConfigConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.config.SysConfigMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
import cn.iocoder.dashboard.modules.system.enums.config.SysConfigTypeEnum;
|
||||
import cn.iocoder.dashboard.modules.system.service.config.SysConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 参数配置 Service 实现类
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysConfigServiceImpl implements SysConfigService {
|
||||
|
||||
@Resource
|
||||
private SysConfigMapper configMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<SysConfigDO> getConfigPage(SysConfigPageReqVO reqVO) {
|
||||
return configMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysConfigDO> getConfigList(SysConfigExportReqVO reqVO) {
|
||||
return configMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysConfigDO getConfig(Long id) {
|
||||
return configMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysConfigDO getConfigByKey(String key) {
|
||||
return configMapper.selectByKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createConfig(SysConfigCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(null, reqVO.getKey());
|
||||
// 插入参数配置
|
||||
SysConfigDO config = SysConfigConvert.INSTANCE.convert(reqVO);
|
||||
config.setType(SysConfigTypeEnum.CUSTOM.getType());
|
||||
configMapper.insert(config);
|
||||
return config.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConfig(SysConfigUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key
|
||||
// 更新参数配置
|
||||
SysConfigDO updateObj = SysConfigConvert.INSTANCE.convert(reqVO);
|
||||
configMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteConfig(Long id) {
|
||||
// 校验配置存在
|
||||
SysConfigDO config = checkConfigExists(id);
|
||||
// 内置配置,不允许删除
|
||||
if (SysConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
|
||||
}
|
||||
// 删除
|
||||
configMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String key) {
|
||||
// 校验自己存在
|
||||
checkConfigExists(id);
|
||||
// 校验参数配置 key 的唯一性
|
||||
checkConfigKeyUnique(id, key);
|
||||
}
|
||||
|
||||
private SysConfigDO checkConfigExists(Long id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
SysConfigDO config = configMapper.selectById(id);
|
||||
if (config == null) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_NOT_FOUND);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
private void checkConfigKeyUnique(Long id, String key) {
|
||||
SysConfigDO config = configMapper.selectByKey(key);
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的参数配置
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_NAME_DUPLICATE);
|
||||
}
|
||||
if (!config.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue