From 45154e01dbdf50c164d86291aa253130fda4f6eb Mon Sep 17 00:00:00 2001 From: odboy Date: Mon, 11 Nov 2024 21:15:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/resolve_record.go | 30 +++++++++++++++--------------- dao/resolve_version.go | 29 +++++++++++++++++++++++++++++ dns.sqlite3 | Bin 86016 -> 86016 bytes 3 files changed, 44 insertions(+), 15 deletions(-) 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 a11f71a089576d49fc8ca365637c59e3a0a2cb7c..2bd66da57f84ea5e447aa0c77e44372d5a9aaade 100644 GIT binary patch delta 86 zcmZozz}m2Yb%Hdb^h6nFM(M_ctqF_^<$3w{GcfZnX5|0QznK5_X2F1|{L^piGs?&? qFfhn48Z$~685o)98X5wTf{}rhiK&%=snqlX`i#=szv(k_DF6TuoECBb delta 80 zcmZozz}m2Yb%Hdb=tLQ3M$yKEtqF_^<#`zx7?}AFFz|opzs-MOvtYm`{^_^%8KtGA jm{=JYjTt4442(>44Gn=v!N|bM#Kg+jZ2LETMlJ;aZT}QE