Skip to content

Commit 7edd834

Browse files
committed
sys config
1 parent 0c79eaf commit 7edd834

File tree

26 files changed

+993
-159
lines changed

26 files changed

+993
-159
lines changed

api/db/sqltemp.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
create table sys_config
2+
(
3+
id varchar(32) not null
4+
primary key,
5+
config_key varchar(60) not null comment '配置属性',
6+
config_value longtext not null comment '配置值',
7+
config_enabled tinyint default 1 not null comment '是否生效',
8+
comment varchar(500) null comment '备注'
9+
);
10+
11+
INSERT INTO `sys_permission`(`id`, `parent_id`, `name`, `url`, `component`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_route`, `is_leaf`, `keep_alive`, `hidden`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`) VALUES ('1479321067621249026', 'd7d6e2e4e2934f2c9385a623fd98c6f3', '网站配置', '/sys/sysConfig', 'system/SysConfig', NULL, NULL, 1, NULL, '1', 1.00, 0, 'tool', 1, 1, 0, 0, NULL, 'admin', '2022-01-07 13:16:41', 'admin', '2022-01-07 13:38:53', 0, 0, '1', 0);
12+
13+

api/jeecg-boot-base-common/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.jeecg.common.exception;
22

3+
import com.sun.org.apache.xpath.internal.operations.Bool;
34
import io.lettuce.core.RedisConnectionException;
5+
import net.dongliu.requests.Requests;
46
import org.apache.shiro.authz.AuthorizationException;
57
import org.apache.shiro.authz.UnauthorizedException;
68
import org.jeecg.common.api.vo.Result;
9+
import org.jeecg.common.util.IPUtils;
10+
import org.springframework.beans.factory.annotation.Value;
711
import org.springframework.dao.DataIntegrityViolationException;
812
import org.springframework.dao.DuplicateKeyException;
913
import org.springframework.data.redis.connection.PoolException;
@@ -15,6 +19,14 @@
1519

1620
import lombok.extern.slf4j.Slf4j;
1721

22+
import javax.servlet.http.HttpServletRequest;
23+
import java.io.PrintWriter;
24+
import java.io.StringWriter;
25+
import java.net.InetAddress;
26+
import java.net.UnknownHostException;
27+
import java.util.HashMap;
28+
import java.util.Map;
29+
1830
/**
1931
* 异常处理器
2032
*
@@ -52,9 +64,34 @@ public Result<?> handleAuthorizationException(AuthorizationException e){
5264
return Result.noauth("没有权限,请联系管理员授权");
5365
}
5466

67+
@Value("${version:-}")
68+
private String version;
69+
@Value("${ueip:true}")
70+
private Boolean ueip;
71+
@Value("${jeecg.domain:true}")
72+
private String domain;
73+
5574
@ExceptionHandler(Exception.class)
56-
public Result<?> handleException(Exception e){
75+
public Result<?> handleException(HttpServletRequest req, Exception e){
5776
log.error(e.getMessage(), e);
77+
if (ueip == true){
78+
Map<String, Object> logData = new HashMap<String, Object>(){{
79+
put("v", "TO" + version);
80+
put("u", req.getRequestURL());
81+
put("e", e.toString());
82+
put("d", domain);
83+
}};
84+
StringWriter sw = new StringWriter();
85+
PrintWriter pw = new PrintWriter(sw);
86+
e.printStackTrace(pw);
87+
logData.put("ed", sw.toString());
88+
try {logData.put("i",InetAddress.getLocalHost().getHostAddress());
89+
} catch (UnknownHostException ignored) {}
90+
logData.put("ip", IPUtils.getIpAddr(req));
91+
new Thread(()->{
92+
try{ Requests.post("http://center.teaching.vip/api/log/error").body(logData).send(); }catch (Exception ignored){}
93+
}).start();
94+
}
5895
return Result.error("操作失败,"+e.getMessage());
5996
}
6097

api/jeecg-boot-module-system/src/main/java/org/jeecg/JeecgApplication.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.extern.slf4j.Slf4j;
44
import org.apache.catalina.Context;
55
import org.apache.tomcat.util.scan.StandardJarScanner;
6+
import org.springframework.beans.factory.annotation.Value;
67
import org.springframework.boot.SpringApplication;
78
import org.springframework.boot.autoconfigure.SpringBootApplication;
89
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
@@ -18,33 +19,31 @@
1819
@EnableSwagger2
1920
@SpringBootApplication
2021
public class JeecgApplication {
22+
public static void main(String[] args) throws UnknownHostException {
2123

22-
public static void main(String[] args) throws UnknownHostException {
23-
24-
ConfigurableApplicationContext application = SpringApplication.run(JeecgApplication.class, args);
25-
Environment env = application.getEnvironment();
26-
String ip = InetAddress.getLocalHost().getHostAddress();
27-
String port = env.getProperty("server.port");
28-
String path = env.getProperty("server.servlet.context-path");
29-
log.info("\n----------------------------------------------------------\n\t" +
30-
"Application Jeecg-Boot is running! Access URLs:\n\t" +
31-
"Local: \t\thttp://localhost:" + port + path + "/\n\t" +
32-
"External: \thttp://" + ip + ":" + port + path + "/\n\t" +
33-
"Swagger-UI: \t\thttp://" + ip + ":" + port + path + "/doc.html\n" +
34-
"----------------------------------------------------------");
35-
36-
}
24+
ConfigurableApplicationContext application = SpringApplication.run(JeecgApplication.class, args);
25+
Environment env = application.getEnvironment();
26+
String ip = InetAddress.getLocalHost().getHostAddress();
27+
String port = env.getProperty("server.port");
28+
String path = env.getProperty("server.servlet.context-path");
29+
log.info("\n----------------------------------------------------------\n\t" +
30+
"Application Teaching Open is running! Access URLs:\n\t" +
31+
"Local: \t\thttp://localhost:" + port + path + "/\n\t" +
32+
"External: \thttp://" + ip + ":" + port + path + "/\n\t" +
33+
"Swagger-UI: \t\thttp://" + ip + ":" + port + path + "/doc.html\n" +
34+
"----------------------------------------------------------");
35+
}
3736

38-
/**
39-
* tomcat-embed-jasper引用后提示jar找不到的问题
40-
*/
41-
@Bean
42-
public TomcatServletWebServerFactory tomcatFactory() {
43-
return new TomcatServletWebServerFactory() {
44-
@Override
45-
protected void postProcessContext(Context context) {
46-
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
37+
/**
38+
* tomcat-embed-jasper引用后提示jar找不到的问题
39+
*/
40+
@Bean
41+
public TomcatServletWebServerFactory tomcatFactory() {
42+
return new TomcatServletWebServerFactory() {
43+
@Override
44+
protected void postProcessContext(Context context) {
45+
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
46+
}
47+
};
4748
}
48-
};
49-
}
5049
}

api/jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
139139

140140
//支付
141141
filterChainDefinitionMap.put("/teaching/teachingOrder/createOrder", "anon");
142+
//配置
143+
filterChainDefinitionMap.put("/sys/config/getCurrentConfig", "anon");
142144

143145
// 作业
144146
filterChainDefinitionMap.put("/teaching/teachingWork/studentWorkInfo", "anon");
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.jeecg.modules.system.controller;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import org.apache.shiro.authz.annotation.RequiresRoles;
5+
import org.jeecg.common.api.vo.Result;
6+
import org.jeecg.config.QiniuConfig;
7+
import org.jeecg.modules.system.entity.SysConfig;
8+
import org.jeecg.modules.system.service.ISysConfigService;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.beans.factory.annotation.Value;
11+
import org.springframework.web.bind.annotation.*;
12+
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
@RestController
17+
@RequestMapping("/sys/config")
18+
public class SysConfigController {
19+
@Value("${version:-}")
20+
String version;
21+
@Autowired
22+
private ISysConfigService sysConfigService;
23+
24+
//保存配置
25+
@PostMapping("saveTenantConfig")
26+
@RequiresRoles("admin")
27+
public Result<?> saveTenantConfig(@RequestBody JSONObject param){
28+
for (Map.Entry entry : param.entrySet()) {
29+
String key = (String)entry.getKey();
30+
sysConfigService.saveConfig( key , (String)entry.getValue());
31+
}
32+
return Result.ok("修改成功");
33+
}
34+
35+
//获取所有的配置
36+
@GetMapping("getAllConfigList")
37+
public Result<List<SysConfig>> getAllConfigList(){
38+
Result<List<SysConfig>> result = new Result();
39+
List<SysConfig> list = sysConfigService.getConfigList();
40+
result.setResult(list);
41+
return result;
42+
}
43+
44+
//获取所有的配置Map
45+
@GetMapping("getAllConfigMap")
46+
public Result<Map<String, Object>> getAllConfigMap(){
47+
Result<Map<String, Object>> result = new Result();
48+
Map<String, Object> list = sysConfigService.getConfigMap();
49+
result.setResult(list);
50+
return result;
51+
}
52+
53+
//获取对外公开配置
54+
@GetMapping("getCurrentConfig")
55+
public Result<Map<String, Object>> getCurrentConfig(){
56+
Result<Map<String, Object>> result = new Result();
57+
Map<String, Object> tenantConfig = sysConfigService.getConfigMap();
58+
tenantConfig.put("qiniuDomain", QiniuConfig.domain);
59+
tenantConfig.put("version", version);
60+
result.setResult(tenantConfig);
61+
return result;
62+
}
63+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.jeecg.modules.system.entity;
2+
3+
import com.baomidou.mybatisplus.annotation.IdType;
4+
import com.baomidou.mybatisplus.annotation.TableId;
5+
import com.baomidou.mybatisplus.annotation.TableName;
6+
import io.swagger.annotations.ApiModel;
7+
import io.swagger.annotations.ApiModelProperty;
8+
import lombok.Data;
9+
import org.jeecgframework.poi.excel.annotation.Excel;
10+
11+
import java.io.Serializable;
12+
13+
/**
14+
* @Description: 租户配置
15+
* @Author: jeecg-boot
16+
* @Date: 2020-12-25
17+
* @Version: V1.0
18+
*/
19+
@ApiModel(value="sys_config对象", description="")
20+
@Data
21+
@TableName("sys_config")
22+
public class SysConfig implements Serializable {
23+
private static final long serialVersionUID = 1L;
24+
25+
/**ID*/
26+
@TableId(type = IdType.ID_WORKER_STR)
27+
@ApiModelProperty(value = "ID")
28+
private String id;
29+
/**配置属性*/
30+
@Excel(name = "配置属性", width = 15)
31+
@ApiModelProperty(value = "配置属性")
32+
private String configKey;
33+
/**配置值*/
34+
@Excel(name = "配置值", width = 15)
35+
@ApiModelProperty(value = "配置值")
36+
private String configValue;
37+
/**是否生效*/
38+
@Excel(name = "是否生效", width = 15)
39+
@ApiModelProperty(value = "是否生效")
40+
private Integer configEnabled;
41+
/**备注*/
42+
@Excel(name = "备注", width = 15)
43+
@ApiModelProperty(value = "备注")
44+
private String comment;
45+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.jeecg.modules.system.mapper;
2+
3+
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4+
import org.jeecg.modules.system.entity.SysConfig;
5+
6+
7+
public interface SysConfigMapper extends BaseMapper<SysConfig> {
8+
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3+
<mapper namespace="org.jeecg.modules.system.mapper.SysConfigMapper">
4+
</mapper>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.jeecg.modules.system.service;
2+
3+
import com.baomidou.mybatisplus.extension.service.IService;
4+
import org.jeecg.modules.system.entity.SysConfig;
5+
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
public interface ISysConfigService extends IService<SysConfig> {
10+
SysConfig getConfigEntity(String key);
11+
String getConfigItem(String key);
12+
Map<String, Object> getConfigMap();
13+
List<SysConfig> getConfigList();
14+
void saveConfig(String key, String value);
15+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.jeecg.modules.system.service.impl;
2+
3+
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4+
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5+
import org.jeecg.modules.system.entity.SysConfig;
6+
import org.jeecg.modules.system.mapper.SysConfigMapper;
7+
import org.jeecg.modules.system.service.ISysConfigService;
8+
import org.springframework.stereotype.Service;
9+
10+
import java.util.HashMap;
11+
import java.util.List;
12+
import java.util.Map;
13+
14+
@Service
15+
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService {
16+
@Override
17+
public SysConfig getConfigEntity(String key) {
18+
return this.getOne(new QueryWrapper<SysConfig>()
19+
.eq("config_key", key)
20+
.eq("config_enabled",1)
21+
.last("limit 1"));
22+
}
23+
24+
@Override
25+
public List<SysConfig> getConfigList() {
26+
return this.list(new QueryWrapper<SysConfig>()
27+
.eq("config_enabled", 1));
28+
}
29+
30+
@Override
31+
public void saveConfig(String key, String value) {
32+
SysConfig config = this.getConfigEntity(key);
33+
if (config == null){
34+
config = new SysConfig();
35+
config.setConfigKey(key);
36+
config.setConfigValue(value);
37+
config.setConfigEnabled(1);
38+
this.save(config);
39+
}else{
40+
config.setConfigEnabled(1);
41+
config.setConfigValue(value);
42+
this.updateById(config);
43+
}
44+
}
45+
46+
47+
@Override
48+
public Map<String, Object> getConfigMap() {
49+
List<SysConfig> configs = this.getConfigList();
50+
Map<String, Object> configMap = new HashMap<String, Object>();
51+
for (SysConfig config : configs){
52+
configMap.put(config.getConfigKey(), config.getConfigValue());
53+
}
54+
return configMap;
55+
}
56+
57+
@Override
58+
public String getConfigItem(String key) {
59+
SysConfig config = this.getConfigEntity(key);
60+
if (config == null){
61+
return null;
62+
}
63+
return config.getConfigValue();
64+
}
65+
}

0 commit comments

Comments
 (0)