Commit d2fa839d3cd9a9b492f757d947f6e5b758471315

Authored by YunaiV
1 parent 35a01cbf

完成参数配置

Showing 23 changed files with 701 additions and 601 deletions
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserOnlineService.java renamed to ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ISysUserOnlineService.java
1 -package com.ruoyi.system.service;  
2 -  
3 -import com.ruoyi.common.core.domain.model.LoginUser;  
4 -import com.ruoyi.system.domain.SysUserOnline;  
5 -  
6 -/**  
7 - * 在线用户 服务层  
8 - *  
9 - * @author ruoyi  
10 - */  
11 -public interface ISysUserOnlineService  
12 -{  
13 - /**  
14 - * 通过登录地址查询信息  
15 - *  
16 - * @param ipaddr 登录地址  
17 - * @param user 用户信息  
18 - * @return 在线用户信息  
19 - */  
20 - public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user);  
21 -  
22 - /**  
23 - * 通过用户名称查询信息  
24 - *  
25 - * @param userName 用户名称  
26 - * @param user 用户信息  
27 - * @return 在线用户信息  
28 - */  
29 - public SysUserOnline selectOnlineByUserName(String userName, LoginUser user);  
30 -  
31 - /**  
32 - * 通过登录地址/用户名称查询信息  
33 - *  
34 - * @param ipaddr 登录地址  
35 - * @param userName 用户名称  
36 - * @param user 用户信息  
37 - * @return 在线用户信息  
38 - */  
39 - public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user);  
40 -  
41 - /**  
42 - * 设置在线用户信息  
43 - *  
44 - * @param user 用户信息  
45 - * @return 在线用户  
46 - */  
47 - public SysUserOnline loginUserToUserOnline(LoginUser user);  
48 -} 1 +package com.ruoyi.system.service;
  2 +
  3 +import com.ruoyi.common.core.domain.model.LoginUser;
  4 +import com.ruoyi.system.domain.SysUserOnline;
  5 +
  6 +/**
  7 + * 在线用户 服务层
  8 + *
  9 + * @author ruoyi
  10 + */
  11 +public interface ISysUserOnlineService
  12 +{
  13 + /**
  14 + * 通过登录地址查询信息
  15 + *
  16 + * @param ipaddr 登录地址
  17 + * @param user 用户信息
  18 + * @return 在线用户信息
  19 + */
  20 + public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user);
  21 +
  22 + /**
  23 + * 通过用户名称查询信息
  24 + *
  25 + * @param userName 用户名称
  26 + * @param user 用户信息
  27 + * @return 在线用户信息
  28 + */
  29 + public SysUserOnline selectOnlineByUserName(String userName, LoginUser user);
  30 +
  31 + /**
  32 + * 通过登录地址/用户名称查询信息
  33 + *
  34 + * @param ipaddr 登录地址
  35 + * @param userName 用户名称
  36 + * @param user 用户信息
  37 + * @return 在线用户信息
  38 + */
  39 + public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user);
  40 +
  41 + /**
  42 + * 设置在线用户信息
  43 + *
  44 + * @param user 用户信息
  45 + * @return 在线用户
  46 + */
  47 + public SysUserOnline loginUserToUserOnline(LoginUser user);
  48 +}
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUserOnline.java renamed to ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnline.java
1 -package com.ruoyi.system.domain;  
2 -  
3 -/**  
4 - * 当前在线会话  
5 - *  
6 - * @author ruoyi  
7 - */  
8 -public class SysUserOnline  
9 -{  
10 - /** 会话编号 */  
11 - private String tokenId;  
12 -  
13 - /** 部门名称 */  
14 - private String deptName;  
15 -  
16 - /** 用户名称 */  
17 - private String userName;  
18 -  
19 - /** 登录IP地址 */  
20 - private String ipaddr;  
21 -  
22 - /** 登录地址 */  
23 - private String loginLocation;  
24 -  
25 - /** 浏览器类型 */  
26 - private String browser;  
27 -  
28 - /** 操作系统 */  
29 - private String os;  
30 -  
31 - /** 登录时间 */  
32 - private Long loginTime;  
33 -  
34 -  
35 -} 1 +package com.ruoyi.system.domain;
  2 +
  3 +/**
  4 + * 当前在线会话
  5 + *
  6 + * @author ruoyi
  7 + */
  8 +public class SysUserOnline
  9 +{
  10 + /** 会话编号 */
  11 + private String tokenId;
  12 +
  13 + /** 部门名称 */
  14 + private String deptName;
  15 +
  16 + /** 用户名称 */
  17 + private String userName;
  18 +
  19 + /** 登录IP地址 */
  20 + private String ipaddr;
  21 +
  22 + /** 登录地址 */
  23 + private String loginLocation;
  24 +
  25 + /** 浏览器类型 */
  26 + private String browser;
  27 +
  28 + /** 操作系统 */
  29 + private String os;
  30 +
  31 + /** 登录时间 */
  32 + private Long loginTime;
  33 +
  34 +
  35 +}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserOnlineServiceImpl.java renamed to ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineServiceImpl.java
1 -package com.ruoyi.system.service.impl;  
2 -  
3 -import org.springframework.stereotype.Service;  
4 -import com.ruoyi.common.core.domain.model.LoginUser;  
5 -import com.ruoyi.common.utils.StringUtils;  
6 -import com.ruoyi.system.domain.SysUserOnline;  
7 -import com.ruoyi.system.service.ISysUserOnlineService;  
8 -  
9 -/**  
10 - * 在线用户 服务层处理  
11 - *  
12 - * @author ruoyi  
13 - */  
14 -@Service  
15 -public class SysUserOnlineServiceImpl implements ISysUserOnlineService {  
16 - /**  
17 - * 通过登录地址查询信息  
18 - *  
19 - * @param ipaddr 登录地址  
20 - * @param user 用户信息  
21 - * @return 在线用户信息  
22 - */  
23 - @Override  
24 - public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) {  
25 - if (StringUtils.equals(ipaddr, user.getIpaddr())) {  
26 - return loginUserToUserOnline(user);  
27 - }  
28 - return null;  
29 - }  
30 -  
31 - /**  
32 - * 通过用户名称查询信息  
33 - *  
34 - * @param userName 用户名称  
35 - * @param user 用户信息  
36 - * @return 在线用户信息  
37 - */  
38 - @Override  
39 - public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) {  
40 - if (StringUtils.equals(userName, user.getUsername())) {  
41 - return loginUserToUserOnline(user);  
42 - }  
43 - return null;  
44 - }  
45 -  
46 - /**  
47 - * 通过登录地址/用户名称查询信息  
48 - *  
49 - * @param ipaddr 登录地址  
50 - * @param userName 用户名称  
51 - * @param user 用户信息  
52 - * @return 在线用户信息  
53 - */  
54 - @Override  
55 - public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) {  
56 - if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) {  
57 - return loginUserToUserOnline(user);  
58 - }  
59 - return null;  
60 - }  
61 -  
62 - /**  
63 - * 设置在线用户信息  
64 - *  
65 - * @param user 用户信息  
66 - * @return 在线用户  
67 - */  
68 - @Override  
69 - public SysUserOnline loginUserToUserOnline(LoginUser user) {  
70 - if (StringUtils.isNull(user) || StringUtils.isNull(user.getUser())) {  
71 - return null;  
72 - }  
73 - SysUserOnline sysUserOnline = new SysUserOnline();  
74 - sysUserOnline.setTokenId(user.getToken());  
75 - sysUserOnline.setUserName(user.getUsername());  
76 - sysUserOnline.setIpaddr(user.getIpaddr());  
77 - sysUserOnline.setLoginLocation(user.getLoginLocation());  
78 - sysUserOnline.setBrowser(user.getBrowser());  
79 - sysUserOnline.setOs(user.getOs());  
80 - sysUserOnline.setLoginTime(user.getLoginTime());  
81 - if (StringUtils.isNotNull(user.getUser().getDept())) {  
82 - sysUserOnline.setDeptName(user.getUser().getDept().getDeptName());  
83 - }  
84 - return sysUserOnline;  
85 - }  
86 -} 1 +package com.ruoyi.system.service.impl;
  2 +
  3 +import org.springframework.stereotype.Service;
  4 +import com.ruoyi.common.core.domain.model.LoginUser;
  5 +import com.ruoyi.common.utils.StringUtils;
  6 +import com.ruoyi.system.domain.SysUserOnline;
  7 +import com.ruoyi.system.service.ISysUserOnlineService;
  8 +
  9 +/**
  10 + * 在线用户 服务层处理
  11 + *
  12 + * @author ruoyi
  13 + */
  14 +@Service
  15 +public class SysUserOnlineServiceImpl implements ISysUserOnlineService {
  16 + /**
  17 + * 通过登录地址查询信息
  18 + *
  19 + * @param ipaddr 登录地址
  20 + * @param user 用户信息
  21 + * @return 在线用户信息
  22 + */
  23 + @Override
  24 + public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) {
  25 + if (StringUtils.equals(ipaddr, user.getIpaddr())) {
  26 + return loginUserToUserOnline(user);
  27 + }
  28 + return null;
  29 + }
  30 +
  31 + /**
  32 + * 通过用户名称查询信息
  33 + *
  34 + * @param userName 用户名称
  35 + * @param user 用户信息
  36 + * @return 在线用户信息
  37 + */
  38 + @Override
  39 + public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) {
  40 + if (StringUtils.equals(userName, user.getUsername())) {
  41 + return loginUserToUserOnline(user);
  42 + }
  43 + return null;
  44 + }
  45 +
  46 + /**
  47 + * 通过登录地址/用户名称查询信息
  48 + *
  49 + * @param ipaddr 登录地址
  50 + * @param userName 用户名称
  51 + * @param user 用户信息
  52 + * @return 在线用户信息
  53 + */
  54 + @Override
  55 + public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) {
  56 + if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) {
  57 + return loginUserToUserOnline(user);
  58 + }
  59 + return null;
  60 + }
  61 +
  62 + /**
  63 + * 设置在线用户信息
  64 + *
  65 + * @param user 用户信息
  66 + * @return 在线用户
  67 + */
  68 + @Override
  69 + public SysUserOnline loginUserToUserOnline(LoginUser user) {
  70 + if (StringUtils.isNull(user) || StringUtils.isNull(user.getUser())) {
  71 + return null;
  72 + }
  73 + SysUserOnline sysUserOnline = new SysUserOnline();
  74 + sysUserOnline.setTokenId(user.getToken());
  75 + sysUserOnline.setUserName(user.getUsername());
  76 + sysUserOnline.setIpaddr(user.getIpaddr());
  77 + sysUserOnline.setLoginLocation(user.getLoginLocation());
  78 + sysUserOnline.setBrowser(user.getBrowser());
  79 + sysUserOnline.setOs(user.getOs());
  80 + sysUserOnline.setLoginTime(user.getLoginTime());
  81 + if (StringUtils.isNotNull(user.getUser().getDept())) {
  82 + sysUserOnline.setDeptName(user.getUser().getDept().getDeptName());
  83 + }
  84 + return sysUserOnline;
  85 + }
  86 +}
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java deleted
1 -package com.ruoyi.web.controller.system;  
2 -  
3 -import java.util.List;  
4 -  
5 -import org.springframework.beans.factory.annotation.Autowired;  
6 -import org.springframework.security.access.prepost.PreAuthorize;  
7 -import org.springframework.validation.annotation.Validated;  
8 -import org.springframework.web.bind.annotation.DeleteMapping;  
9 -import org.springframework.web.bind.annotation.GetMapping;  
10 -import org.springframework.web.bind.annotation.PathVariable;  
11 -import org.springframework.web.bind.annotation.PostMapping;  
12 -import org.springframework.web.bind.annotation.PutMapping;  
13 -import org.springframework.web.bind.annotation.RequestBody;  
14 -import org.springframework.web.bind.annotation.RequestMapping;  
15 -import org.springframework.web.bind.annotation.RestController;  
16 -import com.ruoyi.common.annotation.Log;  
17 -import com.ruoyi.common.annotation.RepeatSubmit;  
18 -import com.ruoyi.common.constant.UserConstants;  
19 -import com.ruoyi.common.core.controller.BaseController;  
20 -import com.ruoyi.common.core.domain.AjaxResult;  
21 -import com.ruoyi.common.core.page.TableDataInfo;  
22 -import com.ruoyi.common.enums.BusinessType;  
23 -import com.ruoyi.common.utils.SecurityUtils;  
24 -import com.ruoyi.common.utils.poi.ExcelUtil;  
25 -import com.ruoyi.system.domain.SysConfig;  
26 -import com.ruoyi.system.service.ISysConfigService;  
27 -  
28 -/**  
29 - * 参数配置 信息操作处理  
30 - *  
31 - * @author ruoyi  
32 - */  
33 -@RestController  
34 -@RequestMapping("/system/config")  
35 -public class SysConfigController extends BaseController {  
36 -  
37 - @Autowired  
38 - private ISysConfigService configService;  
39 -  
40 - /**  
41 - * 获取参数配置列表  
42 - */  
43 - @PreAuthorize("@ss.hasPermi('system:config:list')")  
44 - @GetMapping("/list")  
45 - public TableDataInfo list(SysConfig config) {  
46 - startPage();  
47 - List<SysConfig> list = configService.selectConfigList(config);  
48 - return getDataTable(list);  
49 - }  
50 -  
51 - @Log(title = "参数管理", businessType = BusinessType.EXPORT)  
52 - @PreAuthorize("@ss.hasPermi('system:config:export')")  
53 - @GetMapping("/export")  
54 - public AjaxResult export(SysConfig config) {  
55 - List<SysConfig> list = configService.selectConfigList(config);  
56 - ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class);  
57 - return util.exportExcel(list, "参数数据");  
58 - }  
59 -  
60 - /**  
61 - * 根据参数编号获取详细信息  
62 - */  
63 - @PreAuthorize("@ss.hasPermi('system:config:query')")  
64 - @GetMapping(value = "/{configId}")  
65 - public AjaxResult getInfo(@PathVariable Long configId) {  
66 - return AjaxResult.success(configService.selectConfigById(configId));  
67 - }  
68 -  
69 - /**  
70 - * 根据参数键名查询参数值  
71 - */  
72 - @GetMapping(value = "/configKey/{configKey}")  
73 - public AjaxResult getConfigKey(@PathVariable String configKey) {  
74 - return AjaxResult.success(configService.selectConfigByKey(configKey));  
75 - }  
76 -  
77 - /**  
78 - * 新增参数配置  
79 - */  
80 - @PreAuthorize("@ss.hasPermi('system:config:add')")  
81 - @Log(title = "参数管理", businessType = BusinessType.INSERT)  
82 - @PostMapping  
83 - @RepeatSubmit  
84 - public AjaxResult add(@Validated @RequestBody SysConfig config) {  
85 - if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {  
86 - return AjaxResult.error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");  
87 - }  
88 - config.setCreateBy(SecurityUtils.getUsername());  
89 - return toAjax(configService.insertConfig(config));  
90 - }  
91 -  
92 - /**  
93 - * 修改参数配置  
94 - */  
95 - @PreAuthorize("@ss.hasPermi('system:config:edit')")  
96 - @Log(title = "参数管理", businessType = BusinessType.UPDATE)  
97 - @PutMapping  
98 - public AjaxResult edit(@Validated @RequestBody SysConfig config) {  
99 - if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {  
100 - return AjaxResult.error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");  
101 - }  
102 - config.setUpdateBy(SecurityUtils.getUsername());  
103 - return toAjax(configService.updateConfig(config));  
104 - }  
105 -  
106 - /**  
107 - * 删除参数配置  
108 - */  
109 - @PreAuthorize("@ss.hasPermi('system:config:remove')")  
110 - @Log(title = "参数管理", businessType = BusinessType.DELETE)  
111 - @DeleteMapping("/{configIds}")  
112 - public AjaxResult remove(@PathVariable Long[] configIds) {  
113 - return toAjax(configService.deleteConfigByIds(configIds));  
114 - }  
115 -  
116 -}  
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java deleted
1 -package com.ruoyi.system.service.impl;  
2 -  
3 -import java.util.Collection;  
4 -import java.util.List;  
5 -import javax.annotation.PostConstruct;  
6 -  
7 -import org.springframework.beans.factory.annotation.Autowired;  
8 -import org.springframework.stereotype.Service;  
9 -import com.ruoyi.common.annotation.DataSource;  
10 -import com.ruoyi.common.constant.Constants;  
11 -import com.ruoyi.common.constant.UserConstants;  
12 -import com.ruoyi.common.core.redis.RedisCache;  
13 -import com.ruoyi.common.core.text.Convert;  
14 -import com.ruoyi.common.enums.DataSourceType;  
15 -import com.ruoyi.common.exception.CustomException;  
16 -import com.ruoyi.common.utils.StringUtils;  
17 -import com.ruoyi.system.domain.SysConfig;  
18 -import com.ruoyi.system.mapper.SysConfigMapper;  
19 -import com.ruoyi.system.service.ISysConfigService;  
20 -  
21 -/**  
22 - * 参数配置 服务层实现  
23 - *  
24 - * @author ruoyi  
25 - */  
26 -@Service  
27 -public class SysConfigServiceImpl implements ISysConfigService {  
28 - @Autowired  
29 - private SysConfigMapper configMapper;  
30 -  
31 - @Autowired  
32 - private RedisCache redisCache;  
33 -  
34 - /**  
35 - * 项目启动时,初始化参数到缓存  
36 - */  
37 - @PostConstruct  
38 - public void init() {  
39 - List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());  
40 - for (SysConfig config : configsList) {  
41 - redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());  
42 - }  
43 - }  
44 -  
45 - /**  
46 - * 查询参数配置信息  
47 - *  
48 - * @param configId 参数配置ID  
49 - * @return 参数配置信息  
50 - */  
51 - @Override  
52 - @DataSource(DataSourceType.MASTER)  
53 - public SysConfig selectConfigById(Long configId) {  
54 - SysConfig config = new SysConfig();  
55 - config.setConfigId(configId);  
56 - return configMapper.selectConfig(config);  
57 - }  
58 -  
59 - /**  
60 - * 根据键名查询参数配置信息  
61 - *  
62 - * @param configKey 参数key  
63 - * @return 参数键值  
64 - */  
65 - @Override  
66 - public String selectConfigByKey(String configKey) {  
67 - String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));  
68 - if (StringUtils.isNotEmpty(configValue)) {  
69 - return configValue;  
70 - }  
71 - SysConfig config = new SysConfig();  
72 - config.setConfigKey(configKey);  
73 - SysConfig retConfig = configMapper.selectConfig(config);  
74 - if (StringUtils.isNotNull(retConfig)) {  
75 - redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());  
76 - return retConfig.getConfigValue();  
77 - }  
78 - return StringUtils.EMPTY;  
79 - }  
80 -  
81 - /**  
82 - * 查询参数配置列表  
83 - *  
84 - * @param config 参数配置信息  
85 - * @return 参数配置集合  
86 - */  
87 - @Override  
88 - public List<SysConfig> selectConfigList(SysConfig config) {  
89 - return configMapper.selectConfigList(config);  
90 - }  
91 -  
92 - /**  
93 - * 新增参数配置  
94 - *  
95 - * @param config 参数配置信息  
96 - * @return 结果  
97 - */  
98 - @Override  
99 - public int insertConfig(SysConfig config) {  
100 - int row = configMapper.insertConfig(config);  
101 - if (row > 0) {  
102 - redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());  
103 - }  
104 - return row;  
105 - }  
106 -  
107 - /**  
108 - * 修改参数配置  
109 - *  
110 - * @param config 参数配置信息  
111 - * @return 结果  
112 - */  
113 - @Override  
114 - public int updateConfig(SysConfig config) {  
115 - int row = configMapper.updateConfig(config);  
116 - if (row > 0) {  
117 - redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());  
118 - }  
119 - return row;  
120 - }  
121 -  
122 - /**  
123 - * 批量删除参数信息  
124 - *  
125 - * @param configIds 需要删除的参数ID  
126 - * @return 结果  
127 - */  
128 - @Override  
129 - public int deleteConfigByIds(Long[] configIds) {  
130 - for (Long configId : configIds) {  
131 - SysConfig config = selectConfigById(configId);  
132 - if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {  
133 - throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));  
134 - }  
135 - }  
136 - int count = configMapper.deleteConfigByIds(configIds);  
137 - if (count > 0) {  
138 - Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");  
139 - redisCache.deleteObject(keys);  
140 - }  
141 - return count;  
142 - }  
143 -  
144 - /**  
145 - * 清空缓存数据  
146 - */  
147 - @Override  
148 - public void clearCache() {  
149 - Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");  
150 - redisCache.deleteObject(keys);  
151 - }  
152 -  
153 - /**  
154 - * 校验参数键名是否唯一  
155 - *  
156 - * @param config 参数配置信息  
157 - * @return 结果  
158 - */  
159 - @Override  
160 - public String checkConfigKeyUnique(SysConfig config) {  
161 - Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();  
162 - SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());  
163 - if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {  
164 - return UserConstants.NOT_UNIQUE;  
165 - }  
166 - return UserConstants.UNIQUE;  
167 - }  
168 -  
169 - /**  
170 - * 设置cache key  
171 - *  
172 - * @param configKey 参数键  
173 - * @return 缓存键key  
174 - */  
175 - private String getCacheKey(String configKey) {  
176 - return Constants.SYS_CONFIG_KEY + configKey;  
177 - }  
178 -}  
ruoyi-ui/src/api/system/config.js
@@ -3,7 +3,7 @@ import request from &#39;@/utils/request&#39; @@ -3,7 +3,7 @@ import request from &#39;@/utils/request&#39;
3 // 查询参数列表 3 // 查询参数列表
4 export function listConfig(query) { 4 export function listConfig(query) {
5 return request({ 5 return request({
6 - url: '/system/config/list', 6 + url: '/system/config/page',
7 method: 'get', 7 method: 'get',
8 params: query 8 params: query
9 }) 9 })
@@ -12,7 +12,7 @@ export function listConfig(query) { @@ -12,7 +12,7 @@ export function listConfig(query) {
12 // 查询参数详细 12 // 查询参数详细
13 export function getConfig(configId) { 13 export function getConfig(configId) {
14 return request({ 14 return request({
15 - url: '/system/config/' + configId, 15 + url: '/system/config/get?id=' + configId,
16 method: 'get' 16 method: 'get'
17 }) 17 })
18 } 18 }
@@ -20,7 +20,7 @@ export function getConfig(configId) { @@ -20,7 +20,7 @@ export function getConfig(configId) {
20 // 根据参数键名查询参数值 20 // 根据参数键名查询参数值
21 export function getConfigKey(configKey) { 21 export function getConfigKey(configKey) {
22 return request({ 22 return request({
23 - url: '/system/config/configKey/' + configKey, 23 + url: '/system/config/get-value-by-key?key=' + configKey,
24 method: 'get' 24 method: 'get'
25 }) 25 })
26 } 26 }
@@ -28,7 +28,7 @@ export function getConfigKey(configKey) { @@ -28,7 +28,7 @@ export function getConfigKey(configKey) {
28 // 新增参数配置 28 // 新增参数配置
29 export function addConfig(data) { 29 export function addConfig(data) {
30 return request({ 30 return request({
31 - url: '/system/config', 31 + url: '/system/config/create',
32 method: 'post', 32 method: 'post',
33 data: data 33 data: data
34 }) 34 })
@@ -37,7 +37,7 @@ export function addConfig(data) { @@ -37,7 +37,7 @@ export function addConfig(data) {
37 // 修改参数配置 37 // 修改参数配置
38 export function updateConfig(data) { 38 export function updateConfig(data) {
39 return request({ 39 return request({
40 - url: '/system/config', 40 + url: '/system/config/update',
41 method: 'put', 41 method: 'put',
42 data: data 42 data: data
43 }) 43 })
@@ -46,15 +46,7 @@ export function updateConfig(data) { @@ -46,15 +46,7 @@ export function updateConfig(data) {
46 // 删除参数配置 46 // 删除参数配置
47 export function delConfig(configId) { 47 export function delConfig(configId) {
48 return request({ 48 return request({
49 - url: '/system/config/' + configId,  
50 - method: 'delete'  
51 - })  
52 -}  
53 -  
54 -// 清理参数缓存  
55 -export function clearCache() {  
56 - return request({  
57 - url: '/system/config/clearCache', 49 + url: '/system/config/delete?id=' + configId,
58 method: 'delete' 50 method: 'delete'
59 }) 51 })
60 } 52 }
@@ -64,6 +56,7 @@ export function exportConfig(query) { @@ -64,6 +56,7 @@ export function exportConfig(query) {
64 return request({ 56 return request({
65 url: '/system/config/export', 57 url: '/system/config/export',
66 method: 'get', 58 method: 'get',
67 - params: query 59 + params: query,
  60 + responseType: 'blob'
68 }) 61 })
69 -}  
70 \ No newline at end of file 62 \ No newline at end of file
  63 +}
ruoyi-ui/src/utils/dict.js
@@ -13,7 +13,8 @@ export const DICT_TYPE = { @@ -13,7 +13,8 @@ export const DICT_TYPE = {
13 SYS_USER_SEX: 'sys_user_sex', 13 SYS_USER_SEX: 'sys_user_sex',
14 SYS_NOTICE_TYPE: 'sys_notice_type', 14 SYS_NOTICE_TYPE: 'sys_notice_type',
15 SYS_OPERATE_TYPE: 'sys_operate_type', 15 SYS_OPERATE_TYPE: 'sys_operate_type',
16 - SYS_LOGIN_RESULT: 'sys_login_result' 16 + SYS_LOGIN_RESULT: 'sys_login_result',
  17 + SYS_CONFIG_TYPE: 'sys_config_type',
17 } 18 }
18 19
19 /** 20 /**
ruoyi-ui/src/views/system/config/index.vue
1 <template> 1 <template>
2 <div class="app-container"> 2 <div class="app-container">
3 <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> 3 <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
4 - <el-form-item label="参数名称" prop="configName"> 4 + <el-form-item label="参数名称" prop="name">
5 <el-input 5 <el-input
6 - v-model="queryParams.configName" 6 + v-model="queryParams.name"
7 placeholder="请输入参数名称" 7 placeholder="请输入参数名称"
8 clearable 8 clearable
9 size="small" 9 size="small"
@@ -11,9 +11,9 @@ @@ -11,9 +11,9 @@
11 @keyup.enter.native="handleQuery" 11 @keyup.enter.native="handleQuery"
12 /> 12 />
13 </el-form-item> 13 </el-form-item>
14 - <el-form-item label="参数键名" prop="configKey"> 14 + <el-form-item label="参数键名" prop="key">
15 <el-input 15 <el-input
16 - v-model="queryParams.configKey" 16 + v-model="queryParams.key"
17 placeholder="请输入参数键名" 17 placeholder="请输入参数键名"
18 clearable 18 clearable
19 size="small" 19 size="small"
@@ -21,13 +21,13 @@ @@ -21,13 +21,13 @@
21 @keyup.enter.native="handleQuery" 21 @keyup.enter.native="handleQuery"
22 /> 22 />
23 </el-form-item> 23 </el-form-item>
24 - <el-form-item label="系统内置" prop="configType">  
25 - <el-select v-model="queryParams.configType" placeholder="系统内置" clearable size="small"> 24 + <el-form-item label="系统内置" prop="type">
  25 + <el-select v-model="queryParams.type" placeholder="系统内置" clearable size="small">
26 <el-option 26 <el-option
27 - v-for="dict in typeOptions"  
28 - :key="dict.dictValue"  
29 - :label="dict.dictLabel"  
30 - :value="dict.dictValue" 27 + v-for="dict in this.getDictDatas(DICT_TYPE.SYS_CONFIG_TYPE)"
  28 + :key="parseInt(dict.value)"
  29 + :label="dict.label"
  30 + :value="parseInt(dict.value)"
31 /> 31 />
32 </el-select> 32 </el-select>
33 </el-form-item> 33 </el-form-item>
@@ -61,26 +61,6 @@ @@ -61,26 +61,6 @@
61 </el-col> 61 </el-col>
62 <el-col :span="1.5"> 62 <el-col :span="1.5">
63 <el-button 63 <el-button
64 - type="success"  
65 - icon="el-icon-edit"  
66 - size="mini"  
67 - :disabled="single"  
68 - @click="handleUpdate"  
69 - v-hasPermi="['system:config:edit']"  
70 - >修改</el-button>  
71 - </el-col>  
72 - <el-col :span="1.5">  
73 - <el-button  
74 - type="danger"  
75 - icon="el-icon-delete"  
76 - size="mini"  
77 - :disabled="multiple"  
78 - @click="handleDelete"  
79 - v-hasPermi="['system:config:remove']"  
80 - >删除</el-button>  
81 - </el-col>  
82 - <el-col :span="1.5">  
83 - <el-button  
84 type="warning" 64 type="warning"
85 icon="el-icon-download" 65 icon="el-icon-download"
86 size="mini" 66 size="mini"
@@ -88,25 +68,25 @@ @@ -88,25 +68,25 @@
88 v-hasPermi="['system:config:export']" 68 v-hasPermi="['system:config:export']"
89 >导出</el-button> 69 >导出</el-button>
90 </el-col> 70 </el-col>
91 - <el-col :span="1.5">  
92 - <el-button  
93 - type="danger"  
94 - icon="el-icon-refresh"  
95 - size="mini"  
96 - @click="handleClearCache"  
97 - v-hasPermi="['system:config:remove']"  
98 - >清理缓存</el-button>  
99 - </el-col>  
100 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> 71 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
101 </el-row> 72 </el-row>
102 73
103 - <el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">  
104 - <el-table-column type="selection" width="55" align="center" />  
105 - <el-table-column label="参数主键" align="center" prop="configId" />  
106 - <el-table-column label="参数名称" align="center" prop="configName" :show-overflow-tooltip="true" />  
107 - <el-table-column label="参数键名" align="center" prop="configKey" :show-overflow-tooltip="true" />  
108 - <el-table-column label="参数键值" align="center" prop="configValue" />  
109 - <el-table-column label="系统内置" align="center" prop="configType" :formatter="typeFormat" /> 74 + <el-table v-loading="loading" :data="configList">
  75 + <el-table-column label="参数主键" align="center" prop="id" />
  76 + <el-table-column label="参数分组" align="center" prop="group" />
  77 + <el-table-column label="参数名称" align="center" prop="name" :show-overflow-tooltip="true" />
  78 + <el-table-column label="参数键名" align="center" prop="key" :show-overflow-tooltip="true" />
  79 + <el-table-column label="参数键值" align="center" prop="value" />
  80 + <el-table-column label="系统内置" align="center" prop="type">
  81 + <template slot-scope="scope">
  82 + <span>{{ getDictDataLabel(DICT_TYPE.SYS_CONFIG_TYPE, scope.row.type) }}</span>
  83 + </template>
  84 + </el-table-column>
  85 + <el-table-column label="是否敏感" align="center" prop="sensitive">
  86 + <template slot-scope="scope">
  87 + <span>{{ scope.row.sensitive ? '是' : '否' }}</span>
  88 + </template>
  89 + </el-table-column>
110 <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" /> 90 <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
111 <el-table-column label="创建时间" align="center" prop="createTime" width="180"> 91 <el-table-column label="创建时间" align="center" prop="createTime" width="180">
112 <template slot-scope="scope"> 92 <template slot-scope="scope">
@@ -136,7 +116,7 @@ @@ -136,7 +116,7 @@
136 <pagination 116 <pagination
137 v-show="total>0" 117 v-show="total>0"
138 :total="total" 118 :total="total"
139 - :page.sync="queryParams.pageNum" 119 + :page.sync="queryParams.pageNo"
140 :limit.sync="queryParams.pageSize" 120 :limit.sync="queryParams.pageSize"
141 @pagination="getList" 121 @pagination="getList"
142 /> 122 />
@@ -144,22 +124,22 @@ @@ -144,22 +124,22 @@
144 <!-- 添加或修改参数配置对话框 --> 124 <!-- 添加或修改参数配置对话框 -->
145 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> 125 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
146 <el-form ref="form" :model="form" :rules="rules" label-width="80px"> 126 <el-form ref="form" :model="form" :rules="rules" label-width="80px">
147 - <el-form-item label="参数名称" prop="configName">  
148 - <el-input v-model="form.configName" placeholder="请输入参数名称" /> 127 + <el-form-item label="参数分组" prop="group">
  128 + <el-input v-model="form.group" placeholder="请输入参数分组" />
  129 + </el-form-item>
  130 + <el-form-item label="参数名称" prop="name">
  131 + <el-input v-model="form.name" placeholder="请输入参数名称" />
149 </el-form-item> 132 </el-form-item>
150 - <el-form-item label="参数键名" prop="configKey">  
151 - <el-input v-model="form.configKey" placeholder="请输入参数键名" /> 133 + <el-form-item label="参数键名" prop="key">
  134 + <el-input v-model="form.key" placeholder="请输入参数键名" />
152 </el-form-item> 135 </el-form-item>
153 - <el-form-item label="参数键值" prop="configValue">  
154 - <el-input v-model="form.configValue" placeholder="请输入参数键值" /> 136 + <el-form-item label="参数键值" prop="value">
  137 + <el-input v-model="form.value" placeholder="请输入参数键值" />
155 </el-form-item> 138 </el-form-item>
156 - <el-form-item label="系统内置" prop="configType">  
157 - <el-radio-group v-model="form.configType">  
158 - <el-radio  
159 - v-for="dict in typeOptions"  
160 - :key="dict.dictValue"  
161 - :label="dict.dictValue"  
162 - >{{dict.dictLabel}}</el-radio> 139 + <el-form-item label="是否敏感" prop="type">
  140 + <el-radio-group v-model="form.sensitive">
  141 + <el-radio :key="true" :label="true">是</el-radio>
  142 + <el-radio :key="false" :label="false">否</el-radio>
163 </el-radio-group> 143 </el-radio-group>
164 </el-form-item> 144 </el-form-item>
165 <el-form-item label="备注" prop="remark"> 145 <el-form-item label="备注" prop="remark">
@@ -175,7 +155,7 @@ @@ -175,7 +155,7 @@
175 </template> 155 </template>
176 156
177 <script> 157 <script>
178 -import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig, clearCache } from "@/api/system/config"; 158 +import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig } from "@/api/system/config";
179 159
180 export default { 160 export default {
181 name: "Config", 161 name: "Config",
@@ -183,12 +163,6 @@ export default { @@ -183,12 +163,6 @@ export default {
183 return { 163 return {
184 // 遮罩层 164 // 遮罩层
185 loading: true, 165 loading: true,
186 - // 选中数组  
187 - ids: [],  
188 - // 非单个禁用  
189 - single: true,  
190 - // 非多个禁用  
191 - multiple: true,  
192 // 显示搜索条件 166 // 显示搜索条件
193 showSearch: true, 167 showSearch: true,
194 // 总条数 168 // 总条数
@@ -205,23 +179,26 @@ export default { @@ -205,23 +179,26 @@ export default {
205 dateRange: [], 179 dateRange: [],
206 // 查询参数 180 // 查询参数
207 queryParams: { 181 queryParams: {
208 - pageNum: 1, 182 + pageNo: 1,
209 pageSize: 10, 183 pageSize: 10,
210 - configName: undefined,  
211 - configKey: undefined,  
212 - configType: undefined 184 + name: undefined,
  185 + key: undefined,
  186 + type: undefined
213 }, 187 },
214 // 表单参数 188 // 表单参数
215 form: {}, 189 form: {},
216 // 表单校验 190 // 表单校验
217 rules: { 191 rules: {
218 - configName: [ 192 + group: [
  193 + { required: true, message: "参数分组不能为空", trigger: "blur" }
  194 + ],
  195 + name: [
219 { required: true, message: "参数名称不能为空", trigger: "blur" } 196 { required: true, message: "参数名称不能为空", trigger: "blur" }
220 ], 197 ],
221 - configKey: [ 198 + key: [
222 { required: true, message: "参数键名不能为空", trigger: "blur" } 199 { required: true, message: "参数键名不能为空", trigger: "blur" }
223 ], 200 ],
224 - configValue: [ 201 + value: [
225 { required: true, message: "参数键值不能为空", trigger: "blur" } 202 { required: true, message: "参数键值不能为空", trigger: "blur" }
226 ] 203 ]
227 } 204 }
@@ -229,24 +206,24 @@ export default { @@ -229,24 +206,24 @@ export default {
229 }, 206 },
230 created() { 207 created() {
231 this.getList(); 208 this.getList();
232 - this.getDicts("sys_yes_no").then(response => {  
233 - this.typeOptions = response.data;  
234 - });  
235 }, 209 },
236 methods: { 210 methods: {
237 /** 查询参数列表 */ 211 /** 查询参数列表 */
238 getList() { 212 getList() {
239 this.loading = true; 213 this.loading = true;
240 - listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(response => {  
241 - this.configList = response.rows;  
242 - this.total = response.total; 214 + listConfig(this.addDateRange(this.queryParams, [
  215 + this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
  216 + this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
  217 + ])).then(response => {
  218 + this.configList = response.data.list;
  219 + this.total = response.data.total;
243 this.loading = false; 220 this.loading = false;
244 } 221 }
245 ); 222 );
246 }, 223 },
247 // 参数系统内置字典翻译 224 // 参数系统内置字典翻译
248 typeFormat(row, column) { 225 typeFormat(row, column) {
249 - return this.selectDictLabel(this.typeOptions, row.configType); 226 + return this.selectDictLabel(this.typeOptions, row.type);
250 }, 227 },
251 // 取消按钮 228 // 取消按钮
252 cancel() { 229 cancel() {
@@ -256,18 +233,17 @@ export default { @@ -256,18 +233,17 @@ export default {
256 // 表单重置 233 // 表单重置
257 reset() { 234 reset() {
258 this.form = { 235 this.form = {
259 - configId: undefined,  
260 - configName: undefined,  
261 - configKey: undefined,  
262 - configValue: undefined,  
263 - configType: "Y", 236 + id: undefined,
  237 + name: undefined,
  238 + key: undefined,
  239 + value: undefined,
264 remark: undefined 240 remark: undefined
265 }; 241 };
266 this.resetForm("form"); 242 this.resetForm("form");
267 }, 243 },
268 /** 搜索按钮操作 */ 244 /** 搜索按钮操作 */
269 handleQuery() { 245 handleQuery() {
270 - this.queryParams.pageNum = 1; 246 + this.queryParams.pageNo = 1;
271 this.getList(); 247 this.getList();
272 }, 248 },
273 /** 重置按钮操作 */ 249 /** 重置按钮操作 */
@@ -282,17 +258,11 @@ export default { @@ -282,17 +258,11 @@ export default {
282 this.open = true; 258 this.open = true;
283 this.title = "添加参数"; 259 this.title = "添加参数";
284 }, 260 },
285 - // 多选框选中数据  
286 - handleSelectionChange(selection) {  
287 - this.ids = selection.map(item => item.configId)  
288 - this.single = selection.length!=1  
289 - this.multiple = !selection.length  
290 - },  
291 /** 修改按钮操作 */ 261 /** 修改按钮操作 */
292 handleUpdate(row) { 262 handleUpdate(row) {
293 this.reset(); 263 this.reset();
294 - const configId = row.configId || this.ids  
295 - getConfig(configId).then(response => { 264 + const id = row.id || this.ids
  265 + getConfig(id).then(response => {
296 this.form = response.data; 266 this.form = response.data;
297 this.open = true; 267 this.open = true;
298 this.title = "修改参数"; 268 this.title = "修改参数";
@@ -302,7 +272,7 @@ export default { @@ -302,7 +272,7 @@ export default {
302 submitForm: function() { 272 submitForm: function() {
303 this.$refs["form"].validate(valid => { 273 this.$refs["form"].validate(valid => {
304 if (valid) { 274 if (valid) {
305 - if (this.form.configId != undefined) { 275 + if (this.form.id !== undefined) {
306 updateConfig(this.form).then(response => { 276 updateConfig(this.form).then(response => {
307 this.msgSuccess("修改成功"); 277 this.msgSuccess("修改成功");
308 this.open = false; 278 this.open = false;
@@ -320,13 +290,13 @@ export default { @@ -320,13 +290,13 @@ export default {
320 }, 290 },
321 /** 删除按钮操作 */ 291 /** 删除按钮操作 */
322 handleDelete(row) { 292 handleDelete(row) {
323 - const configIds = row.configId || this.ids;  
324 - this.$confirm('是否确认删除参数编号为"' + configIds + '"的数据项?', "警告", { 293 + const ids = row.id || this.ids;
  294 + this.$confirm('是否确认删除参数编号为"' + ids + '"的数据项?', "警告", {
325 confirmButtonText: "确定", 295 confirmButtonText: "确定",
326 cancelButtonText: "取消", 296 cancelButtonText: "取消",
327 type: "warning" 297 type: "warning"
328 }).then(function() { 298 }).then(function() {
329 - return delConfig(configIds); 299 + return delConfig(ids);
330 }).then(() => { 300 }).then(() => {
331 this.getList(); 301 this.getList();
332 this.msgSuccess("删除成功"); 302 this.msgSuccess("删除成功");
@@ -342,15 +312,9 @@ export default { @@ -342,15 +312,9 @@ export default {
342 }).then(function() { 312 }).then(function() {
343 return exportConfig(queryParams); 313 return exportConfig(queryParams);
344 }).then(response => { 314 }).then(response => {
345 - this.download(response.msg); 315 + this.downloadExcel(response, '参数配置.xls');
346 }) 316 })
347 }, 317 },
348 - /** 清理缓存按钮操作 */  
349 - handleClearCache() {  
350 - clearCache().then(response => {  
351 - this.msgSuccess("清理成功");  
352 - });  
353 - }  
354 } 318 }
355 }; 319 };
356 -</script>  
357 \ No newline at end of file 320 \ No newline at end of file
  321 +</script>
src/main/java/cn/iocoder/dashboard/modules/system/controller/config/SysConfigController.java
1 package cn.iocoder.dashboard.modules.system.controller.config; 1 package cn.iocoder.dashboard.modules.system.controller.config;
2 2
  3 +import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
  4 +import cn.iocoder.dashboard.common.pojo.CommonResult;
  5 +import cn.iocoder.dashboard.common.pojo.PageResult;
  6 +import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
  7 +import cn.iocoder.dashboard.modules.system.controller.config.vo.*;
  8 +import cn.iocoder.dashboard.modules.system.convert.config.SysConfigConvert;
  9 +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
  10 +import cn.iocoder.dashboard.modules.system.service.config.SysConfigService;
3 import io.swagger.annotations.Api; 11 import io.swagger.annotations.Api;
4 -import org.springframework.web.bind.annotation.RequestMapping;  
5 -import org.springframework.web.bind.annotation.RestController; 12 +import io.swagger.annotations.ApiImplicitParam;
  13 +import io.swagger.annotations.ApiOperation;
  14 +import org.springframework.validation.annotation.Validated;
  15 +import org.springframework.web.bind.annotation.*;
  16 +
  17 +import javax.annotation.Resource;
  18 +import javax.servlet.http.HttpServletResponse;
  19 +import java.io.IOException;
  20 +import java.util.List;
  21 +
  22 +import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
  23 +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE;
6 24
7 @Api(tags = "参数配置") 25 @Api(tags = "参数配置")
8 @RestController 26 @RestController
@@ -24,4 +42,78 @@ public class SysConfigController { @@ -24,4 +42,78 @@ public class SysConfigController {
24 // 42 //
25 // } 43 // }
26 44
  45 + @Resource
  46 + private SysConfigService configService;
  47 +
  48 + @ApiOperation("获取参数配置分页")
  49 + @GetMapping("/page")
  50 +// @PreAuthorize("@ss.hasPermi('system:config:list')")
  51 + public CommonResult<PageResult<SysConfigRespVO>> getConfigPage(@Validated SysConfigPageReqVO reqVO) {
  52 + PageResult<SysConfigDO> page = configService.getConfigPage(reqVO);
  53 + return success(SysConfigConvert.INSTANCE.convertPage(page));
  54 + }
  55 +
  56 + @ApiOperation("导出参数配置")
  57 + @GetMapping("/export")
  58 +// @Log(title = "参数管理", businessType = BusinessType.EXPORT)
  59 +// @PreAuthorize("@ss.hasPermi('system:config:export')")
  60 + public void exportSysConfig(HttpServletResponse response, @Validated SysConfigExportReqVO reqVO) throws IOException {
  61 + List<SysConfigDO> list = configService.getConfigList(reqVO);
  62 + // 拼接数据
  63 + List<SysConfigExcelVO> excelDataList = SysConfigConvert.INSTANCE.convertList(list);
  64 + // 输出
  65 + ExcelUtils.write(response, "参数配置.xls", "配置列表",
  66 + SysConfigExcelVO.class, excelDataList);
  67 + }
  68 +
  69 + @ApiOperation("获得参数配置")
  70 + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
  71 + @GetMapping(value = "/get")
  72 +// @PreAuthorize("@ss.hasPermi('system:config:query')")
  73 + public CommonResult<SysConfigRespVO> getConfig(@RequestParam("id") Long id) {
  74 + return success(SysConfigConvert.INSTANCE.convert(configService.getConfig(id)));
  75 + }
  76 +
  77 + @ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端")
  78 + @ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class)
  79 + @GetMapping(value = "/get-value-by-key")
  80 + public CommonResult<String> getConfigKey(@RequestParam("key") String key) {
  81 + SysConfigDO config = configService.getConfigByKey(key);
  82 + if (config == null) {
  83 + return null;
  84 + }
  85 + if (config.getSensitive()) {
  86 + throw ServiceExceptionUtil.exception(CONFIG_GET_VALUE_ERROR_IF_SENSITIVE);
  87 + }
  88 + return success(config.getValue());
  89 + }
  90 +
  91 + @ApiOperation("新增参数配置")
  92 + @PostMapping("/create")
  93 +// @PreAuthorize("@ss.hasPermi('system:config:add')")
  94 +// @Log(title = "参数管理", businessType = BusinessType.INSERT)
  95 +// @RepeatSubmit
  96 + public CommonResult<Long> createConfig(@Validated @RequestBody SysConfigCreateReqVO reqVO) {
  97 + return success(configService.createConfig(reqVO));
  98 + }
  99 +
  100 + @ApiOperation("修改参数配置")
  101 + @PutMapping("/update")
  102 +// @PreAuthorize("@ss.hasPermi('system:config:edit')")
  103 +// @Log(title = "参数管理", businessType = BusinessType.UPDATE)
  104 + public CommonResult<Boolean> edit(@Validated @RequestBody SysConfigUpdateReqVO reqVO) {
  105 + configService.updateConfig(reqVO);
  106 + return success(true);
  107 + }
  108 +
  109 + @ApiOperation("删除参数配置")
  110 + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
  111 + @DeleteMapping("/delete")
  112 +// @PreAuthorize("@ss.hasPermi('system:config:remove')")
  113 +// @Log(title = "参数管理", businessType = BusinessType.DELETE)
  114 + public CommonResult<Boolean> deleteConfig(@RequestParam("id") Long id) {
  115 + configService.deleteConfig(id);
  116 + return success(true);
  117 + }
  118 +
27 } 119 }
src/main/java/cn/iocoder/dashboard/modules/system/controller/config/vo/SysConfigBaseVO.java
@@ -5,6 +5,7 @@ import lombok.Data; @@ -5,6 +5,7 @@ import lombok.Data;
5 5
6 import javax.validation.constraints.NotBlank; 6 import javax.validation.constraints.NotBlank;
7 import javax.validation.constraints.NotEmpty; 7 import javax.validation.constraints.NotEmpty;
  8 +import javax.validation.constraints.NotNull;
8 import javax.validation.constraints.Size; 9 import javax.validation.constraints.Size;
9 10
10 /** 11 /**
@@ -29,11 +30,8 @@ public class SysConfigBaseVO { @@ -29,11 +30,8 @@ public class SysConfigBaseVO {
29 @Size(max = 500, message = "参数键值长度不能超过500个字符") 30 @Size(max = 500, message = "参数键值长度不能超过500个字符")
30 private String value; 31 private String value;
31 32
32 - @ApiModelProperty(value = "参数类型", required = true, example = "1", notes = "参见 SysConfigTypeEnum 枚举")  
33 - private String type;  
34 -  
35 @ApiModelProperty(value = "是否敏感", required = true, example = "true") 33 @ApiModelProperty(value = "是否敏感", required = true, example = "true")
36 - @NotBlank(message = "是否敏感不能为空") 34 + @NotNull(message = "是否敏感不能为空")
37 private Boolean sensitive; 35 private Boolean sensitive;
38 36
39 @ApiModelProperty(value = "备注", example = "备注一下很帅气!") 37 @ApiModelProperty(value = "备注", example = "备注一下很帅气!")
src/main/java/cn/iocoder/dashboard/modules/system/controller/config/vo/SysConfigCreateReqVO.java
1 package cn.iocoder.dashboard.modules.system.controller.config.vo; 1 package cn.iocoder.dashboard.modules.system.controller.config.vo;
2 2
3 -import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptBaseVO;  
4 import io.swagger.annotations.ApiModel; 3 import io.swagger.annotations.ApiModel;
5 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
6 import lombok.Data; 5 import lombok.Data;
@@ -12,7 +11,7 @@ import javax.validation.constraints.Size; @@ -12,7 +11,7 @@ import javax.validation.constraints.Size;
12 @ApiModel("参数配置创建 Request VO") 11 @ApiModel("参数配置创建 Request VO")
13 @Data 12 @Data
14 @EqualsAndHashCode(callSuper = true) 13 @EqualsAndHashCode(callSuper = true)
15 -public class SysConfigCreateReqVO extends SysDeptBaseVO { 14 +public class SysConfigCreateReqVO extends SysConfigBaseVO {
16 15
17 @ApiModelProperty(value = "参数键名", required = true, example = "yunai.db.username") 16 @ApiModelProperty(value = "参数键名", required = true, example = "yunai.db.username")
18 @NotBlank(message = "参数键名长度不能为空") 17 @NotBlank(message = "参数键名长度不能为空")
src/main/java/cn/iocoder/dashboard/modules/system/controller/config/vo/SysConfigExcelVO.java
1 package cn.iocoder.dashboard.modules.system.controller.config.vo; 1 package cn.iocoder.dashboard.modules.system.controller.config.vo;
2 2
  3 +import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert;
  5 +import cn.iocoder.dashboard.modules.system.enums.dict.SysDictTypeEnum;
3 import com.alibaba.excel.annotation.ExcelProperty; 6 import com.alibaba.excel.annotation.ExcelProperty;
4 import lombok.Data; 7 import lombok.Data;
5 8
@@ -26,10 +29,12 @@ public class SysConfigExcelVO { @@ -26,10 +29,12 @@ public class SysConfigExcelVO {
26 @ExcelProperty("参数键值") 29 @ExcelProperty("参数键值")
27 private String value; 30 private String value;
28 31
29 - @ExcelProperty("参数类型")  
30 - private String type; 32 + @ExcelProperty(value = "参数类型", converter = DictConvert.class)
  33 + @DictFormat(SysDictTypeEnum.SYS_CONFIG_TYPE)
  34 + private Integer type;
31 35
32 - @ExcelProperty("是否敏感") 36 + @ExcelProperty(value = "是否敏感", converter = DictConvert.class)
  37 + @DictFormat(SysDictTypeEnum.SYS_BOOLEAN_STRING)
33 private Boolean sensitive; 38 private Boolean sensitive;
34 39
35 @ExcelProperty("备注") 40 @ExcelProperty("备注")
src/main/java/cn/iocoder/dashboard/modules/system/controller/config/vo/SysConfigExportReqVO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.config.vo;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +import org.springframework.format.annotation.DateTimeFormat;
  7 +
  8 +import java.util.Date;
  9 +
  10 +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +
  12 +@ApiModel("参数配置导出 Request VO")
  13 +@Data
  14 +public class SysConfigExportReqVO {
  15 +
  16 + @ApiModelProperty(value = "参数名称", example = "模糊匹配")
  17 + private String name;
  18 +
  19 + @ApiModelProperty(value = "参数键名", example = "yunai.db.username", notes = "模糊匹配")
  20 + private String key;
  21 +
  22 + @ApiModelProperty(value = "参数类型", example = "1", notes = "参见 SysConfigTypeEnum 枚举")
  23 + private Integer type;
  24 +
  25 + @ApiModelProperty(value = "开始时间", example = "2020-10-24")
  26 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  27 + private Date beginTime;
  28 +
  29 + @ApiModelProperty(value = "结束时间", example = "2020-10-24")
  30 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  31 + private Date endTime;
  32 +
  33 +}
src/main/java/cn/iocoder/dashboard/modules/system/controller/config/vo/SysConfigPageReqVO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.config.vo;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.PageParam;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +import lombok.EqualsAndHashCode;
  8 +import org.springframework.format.annotation.DateTimeFormat;
  9 +
  10 +import java.util.Date;
  11 +
  12 +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  13 +
  14 +@ApiModel("参数配置分页 Request VO")
  15 +@Data
  16 +@EqualsAndHashCode(callSuper = true)
  17 +public class SysConfigPageReqVO extends PageParam {
  18 +
  19 + @ApiModelProperty(value = "参数名称", example = "模糊匹配")
  20 + private String name;
  21 +
  22 + @ApiModelProperty(value = "参数键名", example = "yunai.db.username", notes = "模糊匹配")
  23 + private String key;
  24 +
  25 + @ApiModelProperty(value = "参数类型", example = "1", notes = "参见 SysConfigTypeEnum 枚举")
  26 + private Integer type;
  27 +
  28 + @ApiModelProperty(value = "开始时间", example = "2020-10-24")
  29 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  30 + private Date beginTime;
  31 +
  32 + @ApiModelProperty(value = "结束时间", example = "2020-10-24")
  33 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  34 + private Date endTime;
  35 +
  36 +}
src/main/java/cn/iocoder/dashboard/modules/system/controller/config/vo/SysConfigRespVO.java
@@ -22,6 +22,9 @@ public class SysConfigRespVO extends SysConfigBaseVO { @@ -22,6 +22,9 @@ public class SysConfigRespVO extends SysConfigBaseVO {
22 @Size(max = 100, message = "参数键名长度不能超过100个字符") 22 @Size(max = 100, message = "参数键名长度不能超过100个字符")
23 private String key; 23 private String key;
24 24
  25 + @ApiModelProperty(value = "参数类型", required = true, example = "1", notes = "参见 SysConfigTypeEnum 枚举")
  26 + private Integer type;
  27 +
25 @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") 28 @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
26 private Date createTime; 29 private Date createTime;
27 30
src/main/java/cn/iocoder/dashboard/modules/system/controller/config/vo/SysConfigUpdateReqVO.java
1 package cn.iocoder.dashboard.modules.system.controller.config.vo; 1 package cn.iocoder.dashboard.modules.system.controller.config.vo;
2 2
3 -import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptBaseVO;  
4 import io.swagger.annotations.ApiModel; 3 import io.swagger.annotations.ApiModel;
5 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
6 import lombok.Data; 5 import lombok.Data;
@@ -11,7 +10,7 @@ import javax.validation.constraints.NotNull; @@ -11,7 +10,7 @@ import javax.validation.constraints.NotNull;
11 @ApiModel("参数配置创建 Request VO") 10 @ApiModel("参数配置创建 Request VO")
12 @Data 11 @Data
13 @EqualsAndHashCode(callSuper = true) 12 @EqualsAndHashCode(callSuper = true)
14 -public class SysConfigUpdateReqVO extends SysDeptBaseVO { 13 +public class SysConfigUpdateReqVO extends SysConfigBaseVO {
15 14
16 @ApiModelProperty(value = "参数配置序号", required = true, example = "1024") 15 @ApiModelProperty(value = "参数配置序号", required = true, example = "1024")
17 @NotNull(message = "参数配置编号不能为空") 16 @NotNull(message = "参数配置编号不能为空")
src/main/java/cn/iocoder/dashboard/modules/system/convert/config/SysConfigConvert.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.convert.config;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.PageResult;
  4 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
  5 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExcelVO;
  6 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigRespVO;
  7 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
  8 +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
  9 +import org.mapstruct.Mapper;
  10 +import org.mapstruct.factory.Mappers;
  11 +
  12 +import java.util.List;
  13 +
  14 +@Mapper
  15 +public interface SysConfigConvert {
  16 +
  17 + SysConfigConvert INSTANCE = Mappers.getMapper(SysConfigConvert.class);
  18 +
  19 + PageResult<SysConfigRespVO> convertPage(PageResult<SysConfigDO> page);
  20 +
  21 + SysConfigRespVO convert(SysConfigDO bean);
  22 +
  23 + SysConfigDO convert(SysConfigCreateReqVO bean);
  24 +
  25 + SysConfigDO convert(SysConfigUpdateReqVO bean);
  26 +
  27 + List<SysConfigExcelVO> convertList(List<SysConfigDO> list);
  28 +
  29 +}
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/config/SysConfigMapper.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.dal.mysql.dao.config;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.PageResult;
  4 +import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
  6 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
  7 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
  8 +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
  9 +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  10 +import org.apache.ibatis.annotations.Mapper;
  11 +
  12 +import java.util.List;
  13 +
  14 +@Mapper
  15 +public interface SysConfigMapper extends BaseMapperX<SysConfigDO> {
  16 +
  17 + default PageResult<SysConfigDO> selectPage(SysConfigPageReqVO reqVO) {
  18 + return selectPage(reqVO,
  19 + new QueryWrapperX<SysConfigDO>().likeIfPresent("name", reqVO.getName())
  20 + .likeIfPresent("`key`", reqVO.getKey())
  21 + .eqIfPresent("`type`", reqVO.getType())
  22 + .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
  23 + }
  24 +
  25 + default SysConfigDO selectByKey(String key) {
  26 + return selectOne(new QueryWrapper<SysConfigDO>().eq("`key`", key));
  27 + }
  28 +
  29 + default List<SysConfigDO> selectList(SysConfigExportReqVO reqVO) {
  30 + return selectList(new QueryWrapperX<SysConfigDO>().likeIfPresent("name", reqVO.getName())
  31 + .likeIfPresent("`key`", reqVO.getKey())
  32 + .eqIfPresent("`type`", reqVO.getType())
  33 + .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
  34 + }
  35 +
  36 +}
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/config/SysConfigDO.java
@@ -2,7 +2,11 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config; @@ -2,7 +2,11 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config;
2 2
3 import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; 3 import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
4 import cn.iocoder.dashboard.modules.system.enums.config.SysConfigTypeEnum; 4 import cn.iocoder.dashboard.modules.system.enums.config.SysConfigTypeEnum;
  5 +import com.baomidou.mybatisplus.annotation.TableField;
5 import com.baomidou.mybatisplus.annotation.TableName; 6 import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.Data;
  8 +import lombok.EqualsAndHashCode;
  9 +import lombok.ToString;
6 10
7 /** 11 /**
8 * 参数配置表 12 * 参数配置表
@@ -10,6 +14,9 @@ import com.baomidou.mybatisplus.annotation.TableName; @@ -10,6 +14,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
10 * @author ruoyi 14 * @author ruoyi
11 */ 15 */
12 @TableName("sys_config") 16 @TableName("sys_config")
  17 +@Data
  18 +@EqualsAndHashCode(callSuper = true)
  19 +@ToString(callSuper = true)
13 public class SysConfigDO extends BaseDO { 20 public class SysConfigDO extends BaseDO {
14 21
15 /** 22 /**
@@ -19,6 +26,7 @@ public class SysConfigDO extends BaseDO { @@ -19,6 +26,7 @@ public class SysConfigDO extends BaseDO {
19 /** 26 /**
20 * 参数分组 27 * 参数分组
21 */ 28 */
  29 + @TableField("`group`")
22 private String group; 30 private String group;
23 /** 31 /**
24 * 参数名称 32 * 参数名称
@@ -27,6 +35,7 @@ public class SysConfigDO extends BaseDO { @@ -27,6 +35,7 @@ public class SysConfigDO extends BaseDO {
27 /** 35 /**
28 * 参数键名 36 * 参数键名
29 */ 37 */
  38 + @TableField("`key`")
30 private String key; 39 private String key;
31 /** 40 /**
32 * 参数键值 41 * 参数键值
@@ -37,12 +46,14 @@ public class SysConfigDO extends BaseDO { @@ -37,12 +46,14 @@ public class SysConfigDO extends BaseDO {
37 * 46 *
38 * 枚举 {@link SysConfigTypeEnum} 47 * 枚举 {@link SysConfigTypeEnum}
39 */ 48 */
40 - private String type; 49 + @TableField("`type`")
  50 + private Integer type;
41 /** 51 /**
42 * 是否敏感 52 * 是否敏感
43 * 53 *
44 * 对于敏感配置,需要管理权限才能查看 54 * 对于敏感配置,需要管理权限才能查看
45 */ 55 */
  56 + @TableField("`sensitive`")
46 private Boolean sensitive; 57 private Boolean sensitive;
47 /** 58 /**
48 * 备注 59 * 备注
src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java
@@ -74,4 +74,10 @@ public interface SysErrorCodeConstants { @@ -74,4 +74,10 @@ public interface SysErrorCodeConstants {
74 74
75 // ========== 文件 1002009000 ========== 75 // ========== 文件 1002009000 ==========
76 ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在"); 76 ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在");
  77 +
  78 + // ========== 参数配置 1002010000 ==========
  79 + ErrorCode CONFIG_NOT_FOUND = new ErrorCode(1002010001, "参数配置不存在");
  80 + ErrorCode CONFIG_NAME_DUPLICATE = new ErrorCode(1002010002, "参数配置 key 重复");
  81 + ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1002010003, "不能删除类型为系统内置的参数配置");
  82 + ErrorCode CONFIG_GET_VALUE_ERROR_IF_SENSITIVE = new ErrorCode(1002010004, "不允许获取敏感配置到前端");
77 } 83 }
src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/SysDictTypeEnum.java
@@ -14,6 +14,8 @@ public enum SysDictTypeEnum { @@ -14,6 +14,8 @@ public enum SysDictTypeEnum {
14 SYS_COMMON_STATUS("sys_common_status"), // 系统状态 14 SYS_COMMON_STATUS("sys_common_status"), // 系统状态
15 SYS_OPERATE_TYPE("sys_operate_type"), // 操作类型 15 SYS_OPERATE_TYPE("sys_operate_type"), // 操作类型
16 SYS_LOGIN_RESULT("sys_login_result"), // 登陆结果 16 SYS_LOGIN_RESULT("sys_login_result"), // 登陆结果
  17 + SYS_CONFIG_TYPE("sys_config_type"), // 参数配置类型
  18 + SYS_BOOLEAN_STRING("sys_boolean_string"), // Boolean 是否类型
17 ; 19 ;
18 20
19 21
src/main/java/cn/iocoder/dashboard/modules/system/service/config/SysConfigService.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.service.config;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.PageResult;
  4 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
  5 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
  6 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
  7 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
  8 +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
  9 +
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * 参数配置 Service 接口
  14 + */
  15 +public interface SysConfigService {
  16 +
  17 + /**
  18 + * 获得参数配置分页列表
  19 + *
  20 + * @param reqVO 分页条件
  21 + * @return 分页列表
  22 + */
  23 + PageResult<SysConfigDO> getConfigPage(SysConfigPageReqVO reqVO);
  24 +
  25 + /**
  26 + * 获得参数配置列表
  27 + *
  28 + * @param reqVO 列表
  29 + * @return 列表
  30 + */
  31 + List<SysConfigDO> getConfigList(SysConfigExportReqVO reqVO);
  32 +
  33 + /**
  34 + * 获得参数配置
  35 + *
  36 + * @param id 配置编号
  37 + * @return 参数配置
  38 + */
  39 + SysConfigDO getConfig(Long id);
  40 +
  41 + /**
  42 + * 根据参数键,获得参数配置
  43 + *
  44 + * @param key 配置键
  45 + * @return 参数配置
  46 + */
  47 + SysConfigDO getConfigByKey(String key);
  48 +
  49 + /**
  50 + * 创建参数配置
  51 + *
  52 + * @param reqVO 创建信息
  53 + * @return 配置编号
  54 + */
  55 + Long createConfig(SysConfigCreateReqVO reqVO);
  56 +
  57 + /**
  58 + * 更新参数配置
  59 + *
  60 + * @param reqVO 更新信息
  61 + */
  62 + void updateConfig(SysConfigUpdateReqVO reqVO);
  63 +
  64 + /**
  65 + * 删除参数配置
  66 + *
  67 + * @param id 配置编号
  68 + */
  69 + void deleteConfig(Long id);
  70 +
  71 +}
src/main/java/cn/iocoder/dashboard/modules/system/service/config/impl/SysConfigServiceImpl.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.service.config.impl;
  2 +
  3 +import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
  4 +import cn.iocoder.dashboard.common.pojo.PageResult;
  5 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
  6 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
  7 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
  8 +import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
  9 +import cn.iocoder.dashboard.modules.system.convert.config.SysConfigConvert;
  10 +import cn.iocoder.dashboard.modules.system.dal.mysql.dao.config.SysConfigMapper;
  11 +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
  12 +import cn.iocoder.dashboard.modules.system.enums.config.SysConfigTypeEnum;
  13 +import cn.iocoder.dashboard.modules.system.service.config.SysConfigService;
  14 +import lombok.extern.slf4j.Slf4j;
  15 +import org.springframework.stereotype.Service;
  16 +
  17 +import javax.annotation.Resource;
  18 +
  19 +import java.util.List;
  20 +
  21 +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
  22 +
  23 +/**
  24 + * 参数配置 Service 实现类
  25 + */
  26 +@Service
  27 +@Slf4j
  28 +public class SysConfigServiceImpl implements SysConfigService {
  29 +
  30 + @Resource
  31 + private SysConfigMapper configMapper;
  32 +
  33 + @Override
  34 + public PageResult<SysConfigDO> getConfigPage(SysConfigPageReqVO reqVO) {
  35 + return configMapper.selectPage(reqVO);
  36 + }
  37 +
  38 + @Override
  39 + public List<SysConfigDO> getConfigList(SysConfigExportReqVO reqVO) {
  40 + return configMapper.selectList(reqVO);
  41 + }
  42 +
  43 + @Override
  44 + public SysConfigDO getConfig(Long id) {
  45 + return configMapper.selectById(id);
  46 + }
  47 +
  48 + @Override
  49 + public SysConfigDO getConfigByKey(String key) {
  50 + return configMapper.selectByKey(key);
  51 + }
  52 +
  53 + @Override
  54 + public Long createConfig(SysConfigCreateReqVO reqVO) {
  55 + // 校验正确性
  56 + checkCreateOrUpdate(null, reqVO.getKey());
  57 + // 插入参数配置
  58 + SysConfigDO config = SysConfigConvert.INSTANCE.convert(reqVO);
  59 + config.setType(SysConfigTypeEnum.CUSTOM.getType());
  60 + configMapper.insert(config);
  61 + return config.getId();
  62 + }
  63 +
  64 + @Override
  65 + public void updateConfig(SysConfigUpdateReqVO reqVO) {
  66 + // 校验正确性
  67 + checkCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key
  68 + // 更新参数配置
  69 + SysConfigDO updateObj = SysConfigConvert.INSTANCE.convert(reqVO);
  70 + configMapper.updateById(updateObj);
  71 + }
  72 +
  73 + @Override
  74 + public void deleteConfig(Long id) {
  75 + // 校验配置存在
  76 + SysConfigDO config = checkConfigExists(id);
  77 + // 内置配置,不允许删除
  78 + if (SysConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
  79 + throw ServiceExceptionUtil.exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
  80 + }
  81 + // 删除
  82 + configMapper.deleteById(id);
  83 + }
  84 +
  85 + private void checkCreateOrUpdate(Long id, String key) {
  86 + // 校验自己存在
  87 + checkConfigExists(id);
  88 + // 校验参数配置 key 的唯一性
  89 + checkConfigKeyUnique(id, key);
  90 + }
  91 +
  92 + private SysConfigDO checkConfigExists(Long id) {
  93 + if (id == null) {
  94 + return null;
  95 + }
  96 + SysConfigDO config = configMapper.selectById(id);
  97 + if (config == null) {
  98 + throw ServiceExceptionUtil.exception(CONFIG_NOT_FOUND);
  99 + }
  100 + return config;
  101 + }
  102 +
  103 + private void checkConfigKeyUnique(Long id, String key) {
  104 + SysConfigDO config = configMapper.selectByKey(key);
  105 + if (config == null) {
  106 + return;
  107 + }
  108 + // 如果 id 为空,说明不用比较是否为相同 id 的参数配置
  109 + if (id == null) {
  110 + throw ServiceExceptionUtil.exception(CONFIG_NAME_DUPLICATE);
  111 + }
  112 + if (!config.getId().equals(id)) {
  113 + throw ServiceExceptionUtil.exception(CONFIG_NAME_DUPLICATE);
  114 + }
  115 + }
  116 +}