feat: 机器新增备注字段,其他优化

This commit is contained in:
meilin.huang
2022-05-12 10:34:16 +08:00
parent 9db3db31be
commit ffb91e9169
20 changed files with 147 additions and 135 deletions

View File

@@ -9,9 +9,10 @@ type MachineForm struct {
Ip string `json:"ip" binding:"required"`
// 用户名
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
Password string `json:"password"`
// 端口号
Port int `json:"port" binding:"required"`
Port int `json:"port" binding:"required"`
Remark string `json:"remark"`
}
type MachineRunForm struct {

View File

@@ -30,6 +30,7 @@ type MachineVO struct {
Modifier *string `json:"modifier"`
ModifierId *int64 `json:"modifierId"`
HasCli bool `json:"hasCli" gorm:"-"`
Remark *string `json:"remark"`
}
type MachineScriptVO struct {

View File

@@ -162,7 +162,7 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
}
// 最大连接周期超过时间的连接就close
DB.SetConnMaxLifetime(100 * time.Second)
// DB.SetConnMaxLifetime(100 * time.Second)
// 设置最大连接数
DB.SetMaxOpenConns(2)
// 设置闲置连接数
@@ -182,7 +182,7 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
var dbCache = cache.NewTimedCache(30*time.Minute, 5*time.Second).
WithUpdateAccessTime(true).
OnEvicted(func(key interface{}, value interface{}) {
global.Log.Info(fmt.Sprintf("删除db连接缓存 id: %s", key))
global.Log.Info(fmt.Sprintf("删除db连接缓存 id = %s", key))
value.(*DbInstance).Close()
})
@@ -307,13 +307,9 @@ func getDsn(d *entity.Db) string {
return ""
}
// 关闭该数据库所有连接
// 删除db缓存并关闭该数据库所有连接
func CloseDb(dbId uint64, db string) {
id := GetDbCacheKey(dbId, db)
if di := GetDbInstanceByCache(id); di != nil {
di.Close()
dbCache.Delete(id)
}
dbCache.Delete(GetDbCacheKey(dbId, db))
}
//-----------------------------------元数据-------------------------------------------

View File

@@ -51,7 +51,10 @@ func (m *machineAppImpl) Count(condition *entity.Machine) int64 {
// 根据条件获取机器信息
func (m *machineAppImpl) Save(me *entity.Machine) {
biz.ErrIsNilAppendErr(machine.TestConn(me), "该机器无法连接: %s")
// ’修改机器信息且密码不为空‘ or ‘新增’需要测试是否可连接
if (me.Id != 0 && me.Password != "") || me.Id == 0 {
biz.ErrIsNilAppendErr(machine.TestConn(me), "该机器无法连接: %s")
}
oldMachine := &entity.Machine{Ip: me.Ip, Port: me.Port, Username: me.Username}
err := m.GetMachine(oldMachine)

View File

@@ -126,7 +126,7 @@ func (r *redisAppImpl) GetRedisInstance(id uint64) *RedisInstance {
var redisCache = cache.NewTimedCache(30*time.Minute, 5*time.Second).
WithUpdateAccessTime(true).
OnEvicted(func(key interface{}, value interface{}) {
global.Log.Info(fmt.Sprintf("删除redis连接缓存 id: %d", key))
global.Log.Info(fmt.Sprintf("删除redis连接缓存 id = %d", key))
value.(*RedisInstance).Cli.Close()
})
@@ -137,12 +137,9 @@ type RedisInstance struct {
Cli *redis.Client
}
// 关闭redis连接
// 移除redis连接缓存并关闭redis连接
func CloseRedis(id uint64) {
if load, ok := redisCache.Get(id); ok {
load.(*RedisInstance).Cli.Close()
redisCache.Delete(id)
}
redisCache.Delete(id)
}
func TestRedisConnection(re *entity.Redis) {

View File

@@ -14,6 +14,7 @@ type Machine struct {
Password string `json:"-"`
Port int `json:"port"` // 端口号
Status int8 `json:"status"` // 状态 1:启用2:停用
Remark string `json:"remark"` // 备注
}
const (

View File

@@ -88,6 +88,7 @@ CREATE TABLE `t_machine` (
`username` varchar(12) COLLATE utf8mb4_bin NOT NULL,
`password` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
`status` tinyint(2) NOT NULL COMMENT '状态: 1:启用; -1:禁用',
`remark` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
`need_monitor` tinyint(2) DEFAULT NULL,
`create_time` datetime NOT NULL,
`creator` varchar(16) COLLATE utf8mb4_bin DEFAULT NULL,