mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-05 05:18:12 +08:00
新增系统参数表,ip白名单配置转存到系统参数中
This commit is contained in:
parent
a4280df700
commit
16b132ae00
@ -158,6 +158,9 @@ public class StringUtil {
|
||||
*/
|
||||
public static <T> T jsonConvert(String jsonStr, Class<T> cls) {
|
||||
try {
|
||||
if (StrUtil.isEmpty(jsonStr)) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parseObject(jsonStr, cls);
|
||||
} catch (Exception e) {
|
||||
return JSON.parseObject(JSON.parse(jsonStr).toString(), cls);
|
||||
|
@ -31,7 +31,7 @@ import cn.jiangzeyin.common.interceptor.InterceptorPattens;
|
||||
import cn.jiangzeyin.common.spring.SpringUtil;
|
||||
import io.jpom.common.ServerOpenApi;
|
||||
import io.jpom.model.data.SystemIpConfigModel;
|
||||
import io.jpom.service.system.SystemIpConfigService;
|
||||
import io.jpom.service.system.SystemParametersServer;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
|
||||
@ -55,8 +55,8 @@ public class IpInterceptor extends BaseJpomInterceptor {
|
||||
if (StrUtil.equals(NetUtil.LOCAL_IP, clientIp)) {
|
||||
return true;
|
||||
}
|
||||
SystemIpConfigService bean = SpringUtil.getBean(SystemIpConfigService.class);
|
||||
SystemIpConfigModel config = bean.getConfig();
|
||||
SystemParametersServer bean = SpringUtil.getBean(SystemParametersServer.class);
|
||||
SystemIpConfigModel config = bean.getConfig(SystemIpConfigModel.ID, SystemIpConfigModel.class);
|
||||
if (config == null) {
|
||||
return true;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ import io.jpom.common.interceptor.OptLog;
|
||||
import io.jpom.model.data.SystemIpConfigModel;
|
||||
import io.jpom.model.log.UserOperateLogV1;
|
||||
import io.jpom.permission.SystemPermission;
|
||||
import io.jpom.service.system.SystemIpConfigService;
|
||||
import io.jpom.service.system.SystemParametersServer;
|
||||
import io.jpom.system.ExtConfigBean;
|
||||
import org.springframework.boot.env.YamlPropertySourceLoader;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
@ -64,10 +64,10 @@ import java.nio.charset.StandardCharsets;
|
||||
@RequestMapping(value = "system")
|
||||
public class SystemConfigController extends BaseServerController {
|
||||
|
||||
private final SystemIpConfigService systemIpConfigService;
|
||||
private final SystemParametersServer systemParametersServer;
|
||||
|
||||
public SystemConfigController(SystemIpConfigService systemIpConfigService) {
|
||||
this.systemIpConfigService = systemIpConfigService;
|
||||
public SystemConfigController(SystemParametersServer systemParametersServer) {
|
||||
this.systemParametersServer = systemParametersServer;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,13 +141,13 @@ public class SystemConfigController extends BaseServerController {
|
||||
@SystemPermission
|
||||
@ResponseBody
|
||||
public String ipConfigData() {
|
||||
SystemIpConfigModel config = systemIpConfigService.getConfig();
|
||||
SystemIpConfigModel config = systemParametersServer.getConfig(SystemIpConfigModel.ID, SystemIpConfigModel.class);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
if (config != null) {
|
||||
jsonObject.put("allowed", config.getAllowed());
|
||||
jsonObject.put("prohibited", config.getProhibited());
|
||||
}
|
||||
jsonObject.put("path", FileUtil.getAbsolutePath(systemIpConfigService.filePath()));
|
||||
//jsonObject.put("path", FileUtil.getAbsolutePath(systemIpConfigService.filePath()));
|
||||
jsonObject.put("ip", getIp());
|
||||
return JsonMessage.getString(200, "加载成功", jsonObject);
|
||||
}
|
||||
@ -160,7 +160,7 @@ public class SystemConfigController extends BaseServerController {
|
||||
SystemIpConfigModel systemIpConfigModel = new SystemIpConfigModel();
|
||||
systemIpConfigModel.setAllowed(StrUtil.emptyToDefault(allowed, StrUtil.EMPTY));
|
||||
systemIpConfigModel.setProhibited(StrUtil.emptyToDefault(prohibited, StrUtil.EMPTY));
|
||||
systemIpConfigService.save(systemIpConfigModel);
|
||||
systemParametersServer.upsert(SystemIpConfigModel.ID, systemIpConfigModel, SystemIpConfigModel.ID);
|
||||
//
|
||||
return JsonMessage.getString(200, "修改成功");
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package io.jpom.model;
|
||||
|
||||
/**
|
||||
* 带逻辑删除 数据表实体
|
||||
*
|
||||
* @author bwcx_jzy
|
||||
* @since 2021/12/2
|
||||
*/
|
||||
public abstract class BaseStrikeDbModel extends BaseUserModifyDbModel {
|
||||
|
||||
/**
|
||||
* 逻辑删除 1 删除 0 未删除
|
||||
*/
|
||||
private Integer strike;
|
||||
|
||||
public Integer getStrike() {
|
||||
return strike;
|
||||
}
|
||||
|
||||
public void setStrike(Integer strike) {
|
||||
this.strike = strike;
|
||||
}
|
||||
}
|
@ -23,6 +23,8 @@
|
||||
package io.jpom.model;
|
||||
|
||||
/**
|
||||
* 带最后修改人字段 数据表实体
|
||||
*
|
||||
* @author bwcx_jzy
|
||||
* @since 2021/8/24
|
||||
*/
|
||||
|
@ -37,78 +37,78 @@ import java.util.stream.Collectors;
|
||||
* @date 2019/9/16
|
||||
*/
|
||||
public enum Cycle implements BaseEnum {
|
||||
/**
|
||||
* 监控周期,code 代表周期时间,单位:分钟、秒
|
||||
*/
|
||||
seconds30(-30, "30秒"),
|
||||
none(0, "不开启"),
|
||||
one(1, "1分钟"),
|
||||
five(5, "5分钟"),
|
||||
ten(10, "10分钟"),
|
||||
thirty(30, "30分钟");
|
||||
/**
|
||||
* 监控周期,code 代表周期时间,单位:分钟、秒
|
||||
*/
|
||||
seconds30(-30, "30秒"),
|
||||
none(0, "不开启"),
|
||||
one(1, "1分钟"),
|
||||
five(5, "5分钟"),
|
||||
ten(10, "10分钟"),
|
||||
thirty(30, "30分钟");
|
||||
|
||||
private int code;
|
||||
private String desc;
|
||||
private CronPattern cronPattern;
|
||||
private long millis;
|
||||
final int code;
|
||||
final String desc;
|
||||
CronPattern cronPattern;
|
||||
long millis;
|
||||
|
||||
Cycle(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
if (code > 0) {
|
||||
this.cronPattern = new CronPattern(String.format("0 0/%s * * * ?", code));
|
||||
this.millis = TimeUnit.MINUTES.toMillis(code);
|
||||
} else if (code == 0) {
|
||||
//
|
||||
Cycle(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
if (code > 0) {
|
||||
this.cronPattern = new CronPattern(String.format("0 0/%s * * * ?", code));
|
||||
this.millis = TimeUnit.MINUTES.toMillis(code);
|
||||
} else if (code == 0) {
|
||||
//
|
||||
|
||||
} else {
|
||||
code = -code;
|
||||
this.cronPattern = new CronPattern(String.format("0/%s * * * * ?", code));
|
||||
this.millis = TimeUnit.SECONDS.toMillis(code);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
code = -code;
|
||||
this.cronPattern = new CronPattern(String.format("0/%s * * * * ?", code));
|
||||
this.millis = TimeUnit.SECONDS.toMillis(code);
|
||||
}
|
||||
}
|
||||
|
||||
public long getMillis() {
|
||||
return millis;
|
||||
}
|
||||
public long getMillis() {
|
||||
return millis;
|
||||
}
|
||||
|
||||
public CronPattern getCronPattern() {
|
||||
return cronPattern;
|
||||
}
|
||||
public CronPattern getCronPattern() {
|
||||
return cronPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static JSONArray getAllJSONArray() {
|
||||
//监控周期
|
||||
JSONArray jsonArray = BaseEnum.toJSONArray(Cycle.class);
|
||||
jsonArray = jsonArray.stream().filter(o -> {
|
||||
JSONObject jsonObject = (JSONObject) o;
|
||||
int code = jsonObject.getIntValue("code");
|
||||
return code != none.getCode();
|
||||
}).collect(Collectors.toCollection(JSONArray::new));
|
||||
try {
|
||||
JSONObject jsonObject = BaseEnum.toJSONObject(Cycle.none);
|
||||
jsonArray.add(0, jsonObject);
|
||||
} catch (InvocationTargetException | IllegalAccessException ignored) {
|
||||
}
|
||||
return jsonArray;
|
||||
}
|
||||
public static JSONArray getAllJSONArray() {
|
||||
//监控周期
|
||||
JSONArray jsonArray = BaseEnum.toJSONArray(Cycle.class);
|
||||
jsonArray = jsonArray.stream().filter(o -> {
|
||||
JSONObject jsonObject = (JSONObject) o;
|
||||
int code = jsonObject.getIntValue("code");
|
||||
return code != none.getCode();
|
||||
}).collect(Collectors.toCollection(JSONArray::new));
|
||||
try {
|
||||
JSONObject jsonObject = BaseEnum.toJSONObject(Cycle.none);
|
||||
jsonArray.add(0, jsonObject);
|
||||
} catch (InvocationTargetException | IllegalAccessException ignored) {
|
||||
}
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
public static JSONArray getJSONArray() {
|
||||
//监控周期
|
||||
JSONArray cycleArray = getAllJSONArray();
|
||||
return cycleArray.stream().filter(o -> {
|
||||
JSONObject jsonObject = (JSONObject) o;
|
||||
int code = jsonObject.getIntValue("code");
|
||||
return code > none.getCode();
|
||||
}).collect(Collectors.toCollection(JSONArray::new));
|
||||
}
|
||||
public static JSONArray getJSONArray() {
|
||||
//监控周期
|
||||
JSONArray cycleArray = getAllJSONArray();
|
||||
return cycleArray.stream().filter(o -> {
|
||||
JSONObject jsonObject = (JSONObject) o;
|
||||
int code = jsonObject.getIntValue("code");
|
||||
return code > none.getCode();
|
||||
}).collect(Collectors.toCollection(JSONArray::new));
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ package io.jpom.model.data;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import io.jpom.model.BaseDbModel;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.BaseStrikeDbModel;
|
||||
import io.jpom.model.enums.GitProtocolEnum;
|
||||
import io.jpom.service.h2db.TableName;
|
||||
|
||||
@ -34,7 +34,7 @@ import io.jpom.service.h2db.TableName;
|
||||
* 仓库地址实体类
|
||||
*/
|
||||
@TableName("REPOSITORY")
|
||||
public class RepositoryModel extends BaseDbModel {
|
||||
public class RepositoryModel extends BaseStrikeDbModel {
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@ -70,11 +70,6 @@ public class RepositoryModel extends BaseDbModel {
|
||||
*/
|
||||
private String rsaPrv;
|
||||
|
||||
/**
|
||||
* 逻辑删除
|
||||
*/
|
||||
private Integer strike;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@ -155,14 +150,6 @@ public class RepositoryModel extends BaseDbModel {
|
||||
this.rsaPrv = rsaPrv;
|
||||
}
|
||||
|
||||
public Integer getStrike() {
|
||||
return strike;
|
||||
}
|
||||
|
||||
public void setStrike(Integer strike) {
|
||||
this.strike = strike;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仓库类型
|
||||
*/
|
||||
|
@ -30,29 +30,31 @@ import io.jpom.model.BaseJsonModel;
|
||||
*/
|
||||
public class SystemIpConfigModel extends BaseJsonModel {
|
||||
|
||||
/**
|
||||
* ip 白名单 允许访问
|
||||
*/
|
||||
private String allowed;
|
||||
public static final String ID = "IP_CONFIG";
|
||||
|
||||
/**
|
||||
* 禁止
|
||||
*/
|
||||
private String prohibited;
|
||||
/**
|
||||
* ip 白名单 允许访问
|
||||
*/
|
||||
private String allowed;
|
||||
|
||||
public String getAllowed() {
|
||||
return allowed;
|
||||
}
|
||||
/**
|
||||
* 禁止
|
||||
*/
|
||||
private String prohibited;
|
||||
|
||||
public void setAllowed(String allowed) {
|
||||
this.allowed = allowed;
|
||||
}
|
||||
public String getAllowed() {
|
||||
return allowed;
|
||||
}
|
||||
|
||||
public String getProhibited() {
|
||||
return prohibited;
|
||||
}
|
||||
public void setAllowed(String allowed) {
|
||||
this.allowed = allowed;
|
||||
}
|
||||
|
||||
public void setProhibited(String prohibited) {
|
||||
this.prohibited = prohibited;
|
||||
}
|
||||
public String getProhibited() {
|
||||
return prohibited;
|
||||
}
|
||||
|
||||
public void setProhibited(String prohibited) {
|
||||
this.prohibited = prohibited;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package io.jpom.model.data;
|
||||
|
||||
import io.jpom.model.BaseStrikeDbModel;
|
||||
import io.jpom.service.h2db.TableName;
|
||||
import io.jpom.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 系统参数
|
||||
*
|
||||
* @author bwcx_jzy
|
||||
* @since 2021/12/2
|
||||
*/
|
||||
@TableName("SYSTEM_PARAMETERS")
|
||||
public class SystemParametersModel extends BaseStrikeDbModel {
|
||||
|
||||
/**
|
||||
* 参数值
|
||||
*/
|
||||
private String value;
|
||||
/**
|
||||
* 参数描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public <T> T jsonToBean(Class<T> cls) {
|
||||
return StringUtil.jsonConvert(this.getValue(), cls);
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ import cn.hutool.db.Db;
|
||||
import cn.hutool.db.Entity;
|
||||
import cn.hutool.db.Page;
|
||||
import cn.hutool.db.PageResult;
|
||||
import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
import io.jpom.system.JpomRuntimeException;
|
||||
import io.jpom.system.db.DbConfig;
|
||||
|
||||
@ -43,7 +44,7 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* db 日志记录表
|
||||
* 数据库基础操作 通用 service
|
||||
*
|
||||
* @author bwcx_jzy
|
||||
* @date 2019/7/20
|
||||
@ -105,6 +106,7 @@ public abstract class BaseDbCommonService<T> {
|
||||
public void insert(T t) {
|
||||
if (!DbConfig.getInstance().isInit()) {
|
||||
// ignore
|
||||
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
|
||||
return;
|
||||
}
|
||||
Db db = Db.use();
|
||||
@ -125,6 +127,7 @@ public abstract class BaseDbCommonService<T> {
|
||||
public void insert(Collection<T> t) {
|
||||
if (!DbConfig.getInstance().isInit() || CollUtil.isEmpty(t)) {
|
||||
// ignore
|
||||
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
|
||||
return;
|
||||
}
|
||||
Db db = Db.use();
|
||||
@ -160,6 +163,7 @@ public abstract class BaseDbCommonService<T> {
|
||||
public int insert(Entity entity) {
|
||||
if (!DbConfig.getInstance().isInit()) {
|
||||
// ignore
|
||||
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
|
||||
return 0;
|
||||
}
|
||||
Db db = Db.use();
|
||||
@ -192,6 +196,7 @@ public abstract class BaseDbCommonService<T> {
|
||||
public int update(Entity entity, Entity where) {
|
||||
if (!DbConfig.getInstance().isInit()) {
|
||||
// ignore
|
||||
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
|
||||
return 0;
|
||||
}
|
||||
Db db = Db.use();
|
||||
@ -220,6 +225,7 @@ public abstract class BaseDbCommonService<T> {
|
||||
}
|
||||
if (!DbConfig.getInstance().isInit()) {
|
||||
// ignore
|
||||
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
|
||||
return null;
|
||||
}
|
||||
Entity where = new Entity(tableName);
|
||||
@ -265,6 +271,7 @@ public abstract class BaseDbCommonService<T> {
|
||||
}
|
||||
if (!DbConfig.getInstance().isInit()) {
|
||||
// ignore
|
||||
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
|
||||
return 0;
|
||||
}
|
||||
Entity where = new Entity(tableName);
|
||||
@ -281,6 +288,7 @@ public abstract class BaseDbCommonService<T> {
|
||||
public int del(Entity where) {
|
||||
if (!DbConfig.getInstance().isInit()) {
|
||||
// ignore
|
||||
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
|
||||
return 0;
|
||||
}
|
||||
where.setTableName(tableName);
|
||||
@ -316,6 +324,7 @@ public abstract class BaseDbCommonService<T> {
|
||||
public boolean exists(Entity where) {
|
||||
if (!DbConfig.getInstance().isInit()) {
|
||||
// ignore
|
||||
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
|
||||
return false;
|
||||
}
|
||||
where.setTableName(getTableName());
|
||||
@ -340,6 +349,7 @@ public abstract class BaseDbCommonService<T> {
|
||||
public PageResult<T> listPage(Entity where, Page page) {
|
||||
if (!DbConfig.getInstance().isInit()) {
|
||||
// ignore
|
||||
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
|
||||
return new PageResult<>(page.getPageNumber(), page.getPageSize(), 0);
|
||||
}
|
||||
where.setTableName(getTableName());
|
||||
|
@ -27,8 +27,11 @@ import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.db.Entity;
|
||||
import io.jpom.common.BaseServerController;
|
||||
import io.jpom.common.Const;
|
||||
import io.jpom.model.BaseDbModel;
|
||||
import io.jpom.model.BaseUserModifyDbModel;
|
||||
import io.jpom.model.data.UserModel;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -54,9 +57,7 @@ public abstract class BaseDbService<T extends BaseDbModel> extends BaseDbCommonS
|
||||
|
||||
@Override
|
||||
public void insert(T t) {
|
||||
// def create time
|
||||
t.setCreateTimeMillis(ObjectUtil.defaultIfNull(t.getCreateTimeMillis(), SystemClock.now()));
|
||||
t.setId(ObjectUtil.defaultIfNull(t.getId(), IdUtil.fastSimpleUUID()));
|
||||
this.fillInsert(t);
|
||||
super.insert(t);
|
||||
}
|
||||
|
||||
@ -64,13 +65,23 @@ public abstract class BaseDbService<T extends BaseDbModel> extends BaseDbCommonS
|
||||
@Override
|
||||
public void insert(Collection<T> t) {
|
||||
// def create time
|
||||
t.forEach(t1 -> {
|
||||
t1.setCreateTimeMillis(ObjectUtil.defaultIfNull(t1.getCreateTimeMillis(), SystemClock.now()));
|
||||
t1.setId(ObjectUtil.defaultIfNull(t1.getId(), IdUtil.fastSimpleUUID()));
|
||||
});
|
||||
t.forEach(this::fillInsert);
|
||||
super.insert(t);
|
||||
}
|
||||
|
||||
private void fillInsert(T t) {
|
||||
// def create time
|
||||
t.setCreateTimeMillis(ObjectUtil.defaultIfNull(t.getCreateTimeMillis(), SystemClock.now()));
|
||||
t.setId(ObjectUtil.defaultIfNull(t.getId(), IdUtil.fastSimpleUUID()));
|
||||
if (t instanceof BaseUserModifyDbModel) {
|
||||
BaseUserModifyDbModel modifyDbModel = (BaseUserModifyDbModel) t;
|
||||
UserModel userModel = BaseServerController.getUserModel();
|
||||
if (userModel != null) {
|
||||
modifyDbModel.setModifyUser(ObjectUtil.defaultIfNull(modifyDbModel.getModifyUser(), userModel.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* update by id with data
|
||||
*
|
||||
@ -85,6 +96,14 @@ public abstract class BaseDbService<T extends BaseDbModel> extends BaseDbCommonS
|
||||
info.setModifyTimeMillis(ObjectUtil.defaultIfNull(info.getModifyTimeMillis(), SystemClock.now()));
|
||||
// remove create time
|
||||
info.setCreateTimeMillis(null);
|
||||
// fill modify user
|
||||
if (info instanceof BaseUserModifyDbModel) {
|
||||
BaseUserModifyDbModel modifyDbModel = (BaseUserModifyDbModel) info;
|
||||
UserModel userModel = BaseServerController.getUserModel();
|
||||
if (userModel != null) {
|
||||
modifyDbModel.setModifyUser(ObjectUtil.defaultIfNull(modifyDbModel.getModifyUser(), userModel.getId()));
|
||||
}
|
||||
}
|
||||
//
|
||||
Entity entity = this.dataBeanToEntity(info);
|
||||
//
|
||||
|
@ -1,66 +1,67 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 码之科技工作室
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package io.jpom.service.system;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.jpom.common.BaseDataService;
|
||||
import io.jpom.model.data.SystemIpConfigModel;
|
||||
import io.jpom.system.ServerConfigBean;
|
||||
import io.jpom.util.JsonFileUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 系统ip 白名单
|
||||
*
|
||||
* @author bwcx_jzy
|
||||
*/
|
||||
@Service
|
||||
public class SystemIpConfigService extends BaseDataService {
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
*
|
||||
* @return config
|
||||
*/
|
||||
public SystemIpConfigModel getConfig() {
|
||||
JSONObject config = getJSONObject(ServerConfigBean.IP_CONFIG);
|
||||
if (config == null) {
|
||||
return null;
|
||||
}
|
||||
return config.toJavaObject(SystemIpConfigModel.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置
|
||||
*
|
||||
* @param configModel config
|
||||
*/
|
||||
public void save(SystemIpConfigModel configModel) {
|
||||
String path = getDataFilePath(ServerConfigBean.IP_CONFIG);
|
||||
JsonFileUtil.saveJson(path, configModel.toJson());
|
||||
}
|
||||
|
||||
public String filePath() {
|
||||
return getDataFilePath(ServerConfigBean.IP_CONFIG);
|
||||
}
|
||||
}
|
||||
///*
|
||||
// * The MIT License (MIT)
|
||||
// *
|
||||
// * Copyright (c) 2019 码之科技工作室
|
||||
// *
|
||||
// * Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// * this software and associated documentation files (the "Software"), to deal in
|
||||
// * the Software without restriction, including without limitation the rights to
|
||||
// * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// * the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
// * subject to the following conditions:
|
||||
// *
|
||||
// * The above copyright notice and this permission notice shall be included in all
|
||||
// * copies or substantial portions of the Software.
|
||||
// *
|
||||
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
// * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
// * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
// * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// */
|
||||
//package io.jpom.service.system;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import io.jpom.common.BaseDataService;
|
||||
//import io.jpom.model.data.SystemIpConfigModel;
|
||||
//import io.jpom.system.ServerConfigBean;
|
||||
//import io.jpom.util.JsonFileUtil;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
///**
|
||||
// * 系统ip 白名单
|
||||
// *
|
||||
// * @author bwcx_jzy
|
||||
// */
|
||||
//@Service
|
||||
//@Deprecated
|
||||
//public class SystemIpConfigService extends BaseDataService {
|
||||
//
|
||||
// /**
|
||||
// * 获取配置
|
||||
// *
|
||||
// * @return config
|
||||
// */
|
||||
// public SystemIpConfigModel getConfig() {
|
||||
// JSONObject config = getJSONObject(ServerConfigBean.IP_CONFIG);
|
||||
// if (config == null) {
|
||||
// return null;
|
||||
// }
|
||||
// return config.toJavaObject(SystemIpConfigModel.class);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 保存配置
|
||||
// *
|
||||
// * @param configModel config
|
||||
// */
|
||||
// public void save(SystemIpConfigModel configModel) {
|
||||
// String path = getDataFilePath(ServerConfigBean.IP_CONFIG);
|
||||
// JsonFileUtil.saveJson(path, configModel.toJson());
|
||||
// }
|
||||
//
|
||||
// public String filePath() {
|
||||
// return getDataFilePath(ServerConfigBean.IP_CONFIG);
|
||||
// }
|
||||
//}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package io.jpom.service.system;
|
||||
|
||||
import io.jpom.model.BaseJsonModel;
|
||||
import io.jpom.model.data.SystemParametersModel;
|
||||
import io.jpom.service.h2db.BaseDbService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author bwcx_jzy
|
||||
* @since 2021/12/2
|
||||
*/
|
||||
@Service
|
||||
public class SystemParametersServer extends BaseDbService<SystemParametersModel> {
|
||||
|
||||
|
||||
/**
|
||||
* 先尝试更新,更新失败尝试插入
|
||||
*
|
||||
* @param name 参数名称
|
||||
* @param jsonModel 参数值
|
||||
* @param desc 描述
|
||||
*/
|
||||
public void upsert(String name, BaseJsonModel jsonModel, String desc) {
|
||||
SystemParametersModel systemParametersModel = new SystemParametersModel();
|
||||
systemParametersModel.setId(name);
|
||||
systemParametersModel.setValue(jsonModel.toString());
|
||||
systemParametersModel.setDescription(desc);
|
||||
int update = super.update(systemParametersModel);
|
||||
if (update <= 0) {
|
||||
super.insert(systemParametersModel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 系统参数 值
|
||||
*
|
||||
* @param name 参数名称
|
||||
* @param cls 类
|
||||
* @param <T> 泛型
|
||||
* @return data
|
||||
*/
|
||||
public <T> T getConfig(String name, Class<T> cls) {
|
||||
SystemParametersModel parametersModel = super.getByKey(name);
|
||||
if (parametersModel == null) {
|
||||
return null;
|
||||
}
|
||||
return parametersModel.jsonToBean(cls);
|
||||
}
|
||||
}
|
@ -107,6 +107,7 @@ public class ServerConfigBean {
|
||||
/**
|
||||
* ip配置
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String IP_CONFIG = "ip_config.json";
|
||||
|
||||
/**
|
||||
|
@ -96,7 +96,8 @@ public class InitDb implements DisposableBean, InitializingBean {
|
||||
*/
|
||||
String[] files = new String[]{
|
||||
"classpath:/bin/h2-db-v1.sql",
|
||||
"classpath:/bin/h2-db-v2.sql"
|
||||
"classpath:/bin/h2-db-v2.sql",
|
||||
"classpath:/bin/h2-db-v3.sql",
|
||||
};
|
||||
// 加载 sql 变更记录,避免重复执行
|
||||
Set<String> executeSqlLog = DbConfig.loadExecuteSqlLog();
|
||||
@ -114,18 +115,15 @@ public class InitDb implements DisposableBean, InitializingBean {
|
||||
}
|
||||
DbConfig.saveExecuteSqlLog(executeSqlLog);
|
||||
DSFactory.setCurrentDSFactory(dsFactory);
|
||||
/**
|
||||
* @author Hotstrip
|
||||
* @date 2021-08-03
|
||||
* load build.js data to DB
|
||||
*/
|
||||
LoadBuildJsonToDB.getInstance().doJsonToSql();
|
||||
//
|
||||
} catch (Exception e) {
|
||||
DefaultSystemLog.getLog().error("初始化数据库失败", e);
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
instance.initOk();
|
||||
// json load to db
|
||||
InitDb.loadJsonToDb();
|
||||
Console.log("h2 db Successfully loaded, url is 【{}】", dbUrl);
|
||||
if (JpomManifest.getInstance().isDebug()) {
|
||||
//
|
||||
@ -139,6 +137,17 @@ public class InitDb implements DisposableBean, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadJsonToDb() {
|
||||
/**
|
||||
* @author Hotstrip
|
||||
* @date 2021-08-03
|
||||
* load build.js data to DB
|
||||
*/
|
||||
LoadBuildJsonToDB.getInstance().doJsonToSql();
|
||||
// @author bwcx_jzy @date 2021-12-02
|
||||
LoadIpConfigToDb.getInstance().load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
|
@ -0,0 +1,59 @@
|
||||
package io.jpom.system.init;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
import cn.jiangzeyin.common.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.jpom.model.data.SystemIpConfigModel;
|
||||
import io.jpom.service.system.SystemParametersServer;
|
||||
import io.jpom.system.ConfigBean;
|
||||
import io.jpom.system.ServerConfigBean;
|
||||
import io.jpom.util.JsonFileUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 加载 ip
|
||||
*
|
||||
* @author bwcx_jzy
|
||||
* @since 2021/12/2
|
||||
*/
|
||||
public class LoadIpConfigToDb {
|
||||
|
||||
private LoadIpConfigToDb() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 静态内部类实现单例模式
|
||||
*/
|
||||
private static class LoadIpConfigToDbHolder {
|
||||
private static final LoadIpConfigToDb INSTANCE = new LoadIpConfigToDb();
|
||||
}
|
||||
|
||||
public static LoadIpConfigToDb getInstance() {
|
||||
return LoadIpConfigToDb.LoadIpConfigToDbHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
File backupOldData = FileUtil.file(ConfigBean.getInstance().getDataPath(), "backup_old_data");
|
||||
// 读取 build.json 文件内容
|
||||
File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.IP_CONFIG);
|
||||
if (!FileUtil.exist(file)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
JSON json = JsonFileUtil.readJson(file.getAbsolutePath());
|
||||
SystemIpConfigModel systemIpConfigModel = json.toJavaObject(SystemIpConfigModel.class);
|
||||
if (systemIpConfigModel == null) {
|
||||
return;
|
||||
}
|
||||
SystemParametersServer parametersServer = SpringUtil.getBean(SystemParametersServer.class);
|
||||
parametersServer.upsert(SystemIpConfigModel.ID, systemIpConfigModel, SystemIpConfigModel.ID);
|
||||
// 将 json 文件转移到备份目录
|
||||
FileUtil.move(file, FileUtil.mkdir(backupOldData), true);
|
||||
DefaultSystemLog.getLog().info("{} mv to {}", FileUtil.getAbsolutePath(file), FileUtil.getAbsolutePath(backupOldData));
|
||||
} catch (Exception e) {
|
||||
DefaultSystemLog.getLog().error("load ip config error ", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -97,6 +97,11 @@ ALTER TABLE BUILD_INFO
|
||||
ALTER TABLE REPOSITORY
|
||||
ADD IF NOT EXISTS STRIKE int DEFAULT 0 comment '逻辑删除';
|
||||
|
||||
|
||||
-- @author bwcx_jzy 增加 MODIFYUSER
|
||||
ALTER TABLE REPOSITORY
|
||||
ADD IF NOT EXISTS MODIFYUSER VARCHAR(50) comment '修改人';
|
||||
|
||||
-- @author jzy
|
||||
ALTER TABLE BUILD_INFO
|
||||
ADD IF NOT EXISTS BRANCHTAGNAME VARCHAR(50) comment '标签';
|
||||
|
18
modules/server/src/main/resources/bin/h2-db-v3.sql
Normal file
18
modules/server/src/main/resources/bin/h2-db-v3.sql
Normal file
@ -0,0 +1,18 @@
|
||||
-- @author bwcx_jzy
|
||||
-- @Date 2021-12-02
|
||||
-- add new tables for storage other info...
|
||||
|
||||
-- 系统参数名称
|
||||
CREATE TABLE IF NOT EXISTS PUBLIC.SYSTEM_PARAMETERS
|
||||
(
|
||||
ID VARCHAR(50) not null comment 'id',
|
||||
CREATETIMEMILLIS BIGINT COMMENT '数据创建时间',
|
||||
MODIFYTIMEMILLIS BIGINT COMMENT '数据修改时间',
|
||||
MODIFYUSER VARCHAR(50) comment '修改人',
|
||||
STRIKE int DEFAULT 0 comment '逻辑删除{1,删除,0 未删除(默认)}',
|
||||
`VALUE` CLOB comment '参数值,JSON 字符串格式',
|
||||
DESCRIPTION varchar(255) comment '参数描述',
|
||||
CONSTRAINT SYSTEM_PARAMETERS_PK PRIMARY KEY (ID)
|
||||
);
|
||||
comment on table SYSTEM_PARAMETERS is '系统参数表';
|
||||
|
Loading…
Reference in New Issue
Block a user