feat: 回滚
This commit is contained in:
parent
287ce3636c
commit
cb9c8d8ef3
|
@ -234,13 +234,21 @@ func InitRestFunc(r *gin.Engine) {
|
|||
})
|
||||
return
|
||||
})
|
||||
// 查询变更历史记录
|
||||
r.POST("/queryVersionList", func(c *gin.Context) {
|
||||
records := dao.FindResolveVersion()
|
||||
// 分页查询变更历史记录
|
||||
r.POST("/queryVersionPage", func(c *gin.Context) {
|
||||
var jsonObj domain.QueryPageArgs
|
||||
err := c.ShouldBindJSON(&jsonObj)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("校验失败, %v", err)})
|
||||
return
|
||||
}
|
||||
records := dao.FindResolveVersionPage(jsonObj.Page, jsonObj.PageSize)
|
||||
count := dao.CountResolveVersionPage(jsonObj.Page, jsonObj.PageSize)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "查询变更历史记录列表成功",
|
||||
"message": "分页查询变更历史记录成功",
|
||||
"data": records,
|
||||
"count": count,
|
||||
})
|
||||
return
|
||||
})
|
||||
|
@ -257,19 +265,19 @@ func InitRestFunc(r *gin.Engine) {
|
|||
c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("版本号 %d 不存在, 回滚失败", jsonObj.Version)})
|
||||
return
|
||||
}
|
||||
executeResult, err := dao.ModifyResolveVersion(jsonObj.Version)
|
||||
if !executeResult {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("回滚失败, %v", err)})
|
||||
return
|
||||
}
|
||||
cache.ReloadCache()
|
||||
body := make(map[string]interface{})
|
||||
body["currentVersion"] = jsonObj.Version
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "回滚成功",
|
||||
"data": body,
|
||||
})
|
||||
//executeResult, err := dao.ModifyResolveVersion(jsonObj.Version)
|
||||
//if !executeResult {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("回滚失败, %v", err)})
|
||||
// return
|
||||
//}
|
||||
//cache.ReloadCache()
|
||||
//body := make(map[string]interface{})
|
||||
//body["currentVersion"] = jsonObj.Version
|
||||
//c.JSON(http.StatusOK, gin.H{
|
||||
// "code": 0,
|
||||
// "message": "回滚成功",
|
||||
// "data": body,
|
||||
//})
|
||||
return
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
package dao
|
||||
|
||||
/*
|
||||
* @Description 解析配置定义与操作
|
||||
* @Author www.odboy.cn
|
||||
* @Date 20241107
|
||||
*/
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ResolveVersion struct {
|
||||
Id int `xorm:"pk not null integer 'id' autoincr" json:"id"`
|
||||
CurrentVersion int `xorm:"not null integer 'curr_version'" json:"currentVersion"`
|
||||
}
|
||||
|
||||
func (ResolveVersion) TableName() string {
|
||||
return "resolve_version"
|
||||
}
|
||||
|
||||
func GetResolveVersion() int {
|
||||
var records []ResolveVersion
|
||||
err := Engine.Table("resolve_config").Where("`id` = ?", 1).Find(&records)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return 0
|
||||
}
|
||||
if len(records) == 0 {
|
||||
return 0
|
||||
}
|
||||
return records[0].CurrentVersion
|
||||
}
|
||||
|
||||
func ModifyResolveVersion(currentVersion int) (bool, error) {
|
||||
wrapper := new(ResolveVersion)
|
||||
wrapper.Id = 1
|
||||
|
||||
updateRecord := new(ResolveVersion)
|
||||
updateRecord.CurrentVersion = currentVersion
|
||||
_, err := Engine.Table("resolve_config").Update(updateRecord, wrapper)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
|
@ -182,13 +182,12 @@ func BackupResolveRecord(record *ResolveRecord) (bool, error, int, int) {
|
|||
return false, err, 0, 0
|
||||
}
|
||||
}
|
||||
updRecord := new(ResolveVersion)
|
||||
updRecord.CurrentVersion = newVersion
|
||||
condition := new(ResolveVersion)
|
||||
condition.Id = 1
|
||||
_, err := Engine.Table("resolve_config").Update(updRecord, condition)
|
||||
if err != nil {
|
||||
return false, err, 0, 0
|
||||
// 新增版本记录
|
||||
var resolveVersion ResolveVersion
|
||||
resolveVersion.Version = newVersion
|
||||
_, err2 := SaveResolveVersion(&resolveVersion)
|
||||
if err2 != nil {
|
||||
return false, err2, 0, 0
|
||||
}
|
||||
return true, nil, oldVersion, newVersion
|
||||
}
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
package dao
|
||||
|
||||
/*
|
||||
* @Description 解析配置定义与操作
|
||||
* @Author www.odboy.cn
|
||||
* @Date 20241107
|
||||
*/
|
||||
import (
|
||||
"fmt"
|
||||
"kenaito-dns/config"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ResolveVersion struct {
|
||||
Id int `xorm:"pk not null integer 'id' autoincr" json:"id"`
|
||||
Version int `xorm:"not null integer 'version'" json:"version"`
|
||||
CreateTime string `xorm:"not null text 'create_time'" json:"createTime"`
|
||||
IsRelease int `xorm:"not null integer 'is_release'" json:"isRelease"`
|
||||
}
|
||||
|
||||
func (ResolveVersion) TableName() string {
|
||||
return "resolve_version"
|
||||
}
|
||||
|
||||
func GetResolveVersion() int {
|
||||
var records []ResolveVersion
|
||||
session := Engine.Table("resolve_version")
|
||||
session.Desc("id")
|
||||
session.And("is_release = ?", 1)
|
||||
err := session.Find(&records)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return 0
|
||||
}
|
||||
if len(records) == 0 {
|
||||
return 0
|
||||
}
|
||||
return records[0].Version
|
||||
}
|
||||
|
||||
func SaveResolveVersion(wrapper *ResolveVersion) (bool, error) {
|
||||
// 全表更新为未发布
|
||||
_, _ = Engine.Table("resolve_version").Update(ResolveVersion{IsRelease: 2}, ResolveVersion{})
|
||||
// 新增发布记录
|
||||
wrapper.CreateTime = time.Now().Format(config.DataTimeFormat)
|
||||
wrapper.IsRelease = 1
|
||||
_, err := Engine.Table("resolve_version").Insert(wrapper)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func FindResolveVersionPage(pageNo int, pageSize int) []*ResolveVersion {
|
||||
// 每页显示5条记录
|
||||
if pageSize <= 5 {
|
||||
pageSize = 5
|
||||
}
|
||||
// 要查询的页码
|
||||
if pageNo <= 0 {
|
||||
pageNo = 1
|
||||
}
|
||||
// 计算跳过的记录数
|
||||
offset := (pageNo - 1) * pageSize
|
||||
records := make([]*ResolveVersion, 0)
|
||||
session := Engine.Table("resolve_version")
|
||||
session.Desc("id")
|
||||
err := session.Limit(pageSize, offset).Find(&records)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return records
|
||||
}
|
||||
func CountResolveVersionPage(pageNo int, pageSize int) int {
|
||||
// 每页显示5条记录
|
||||
if pageSize <= 5 {
|
||||
pageSize = 5
|
||||
}
|
||||
// 要查询的页码
|
||||
if pageNo <= 0 {
|
||||
pageNo = 1
|
||||
}
|
||||
// 计算跳过的记录数
|
||||
offset := (pageNo - 1) * pageSize
|
||||
session := Engine.Table("resolve_version")
|
||||
count, err := session.Limit(pageSize, offset).Count()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return int(count)
|
||||
}
|
BIN
dns.sqlite3
BIN
dns.sqlite3
Binary file not shown.
Loading…
Reference in New Issue