diff --git a/controller/resolve_record.go b/controller/resolve_record.go index 26b9e80..a093e8b 100644 --- a/controller/resolve_record.go +++ b/controller/resolve_record.go @@ -260,24 +260,24 @@ func InitRestFunc(r *gin.Engine) { c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("校验失败, %v", err)}) return } - versions := dao.FindResolveRecordByVersion(jsonObj.Version, true) - if len(versions) == 0 { + resolveVersion := dao.FindResolveVersionByVersion(jsonObj.Version) + if resolveVersion == nil { 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, - //}) + err = dao.ModifyResolveVersion(jsonObj.Version) + if err != nil { + 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 }) } diff --git a/dao/resolve_version.go b/dao/resolve_version.go index 13b4c12..78bf5be 100644 --- a/dao/resolve_version.go +++ b/dao/resolve_version.go @@ -38,6 +38,21 @@ func GetResolveVersion() int { return records[0].Version } +func FindResolveVersionByVersion(version int) *ResolveVersion { + var record ResolveVersion + session := Engine.Table("resolve_version") + session.And("version = ?", version) + result, err := session.Get(&record) + if err != nil { + fmt.Println(err) + return nil + } + if result { + return &record + } + return nil +} + func SaveResolveVersion(wrapper *ResolveVersion) (bool, error) { // 全表更新为未发布 _, _ = Engine.Table("resolve_version").Update(ResolveVersion{IsRelease: 2}, ResolveVersion{}) @@ -52,6 +67,20 @@ func SaveResolveVersion(wrapper *ResolveVersion) (bool, error) { return true, nil } +func ModifyResolveVersion(version int) error { + // 全表更新为未发布 + _, err := Engine.Table("resolve_version").Update(ResolveVersion{IsRelease: 2}, ResolveVersion{}) + if err != nil { + return err + } + // 更新具体的版本为已发布 + _, err = Engine.Table("resolve_version").Update(ResolveVersion{IsRelease: 1}, ResolveVersion{Version: version}) + if err != nil { + return err + } + return nil +} + func FindResolveVersionPage(pageNo int, pageSize int) []*ResolveVersion { // 每页显示5条记录 if pageSize <= 5 { diff --git a/dns.sqlite3 b/dns.sqlite3 index a11f71a..2bd66da 100644 Binary files a/dns.sqlite3 and b/dns.sqlite3 differ