From cb9c8d8ef3d198f23db7bfa63b77c3f2edaf867e Mon Sep 17 00:00:00 2001 From: odboy Date: Mon, 11 Nov 2024 21:01:32 +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 | 42 +++++++++------- dao/resolve_config.go | 46 ------------------ dao/resolve_record.go | 13 +++-- dao/resolve_version.go | 92 +++++++++++++++++++++++++++++++++++ dns.sqlite3 | Bin 45056 -> 86016 bytes 5 files changed, 123 insertions(+), 70 deletions(-) delete mode 100644 dao/resolve_config.go create mode 100644 dao/resolve_version.go diff --git a/controller/resolve_record.go b/controller/resolve_record.go index e2d75a7..26b9e80 100644 --- a/controller/resolve_record.go +++ b/controller/resolve_record.go @@ -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 }) } diff --git a/dao/resolve_config.go b/dao/resolve_config.go deleted file mode 100644 index 3725ec8..0000000 --- a/dao/resolve_config.go +++ /dev/null @@ -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 -} diff --git a/dao/resolve_record.go b/dao/resolve_record.go index 3e78a1e..f20285e 100644 --- a/dao/resolve_record.go +++ b/dao/resolve_record.go @@ -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 } diff --git a/dao/resolve_version.go b/dao/resolve_version.go new file mode 100644 index 0000000..13b4c12 --- /dev/null +++ b/dao/resolve_version.go @@ -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) +} diff --git a/dns.sqlite3 b/dns.sqlite3 index 88e4cde8c701ae77a4b477b8ce91ef9a2af6edfd..a11f71a089576d49fc8ca365637c59e3a0a2cb7c 100644 GIT binary patch delta 1578 zcmbW1OKclO7{_OJv(I>U{D@ykr5r%0hf2Lr6?y{1i9<=HipR`2YZ-@v#A+>lJOA(d zecyjQvzLD0F0Bb4_4$GT0Qz&UiPeL4AP5e>c1|Em5Iv+q5IuB!Gw&g;N8j>7?_=l$ zK-ztP*3n&b0KJ1sNI+lf_w+CHPxV*yS^bc%YWJPE_ontlAiyW!a`}9&9c2iQG7AnYtTiEK_siv}JnS zIAxit8{3vC@db#_$+4hFO!ZJ_?H4YMybew0?#SShB;EsYVIE?6?eU0|mAB zy)Vowe~MScX<aCMQzqiDWu& z;t#JGWbyNB!!VAu#vqBU#xOK+qtTDI*AXii;_?Hn#38Tp8+gWQgJWxBpb3spaB9NN z6vHamlM-$9rYZS-3>js;`&jQN>)qSxO$$ixXj@{Wl}LmT74YHpZ)9bJ&T}l*vM|J_ z^L{Eji&rlTmyIqFq6YvyaC}QYqtzL~FG2x803sTB*AVRhw6iO91tcg^>3?dXE|vJgiTy zlulL3dr!q`Eyszoo3#_7TIX~rTqwZ$oA?dYgeiJHxReKfsV2z7FX{_8D~IuvC*=Gt zmZ4gk^EA^3Sh~&9ZIz|lB>h=uN&N{rr{oHBKGrOVEp!v#(C0$bge2bq`j6Tz&-LyP zRIGd^-ysM3EBUF~Oi&6Z60knc=IuDd9gl(Ox!hziXA~!=j^_-sLnR{|!EY-WI`P1N zya)U=3I%t+AAkE&_=%mcw5#AxP=OGWnx-D8T?{nczs%f^Gxy^@=6>95-M3O*DOF74 z%;HM<#qu&KtMB)-vbUyL*%&Ju^Rlurw~S02z|VIpcv$xS1ESB@L|6=wWr!?dh-^C| zVLX{TI(hPV(Xb9`s$rOWr}254sD6gZFjPios7yO5{wP2QH37p6kY<3i#sFyoaJNh# H{0P8bRKK0| delta 310 zcmZozz}oPDX@ayMBLf2iHxR>s=0qK1Sw;rEszP3#2nG(ezYKgw`3-rea3pbOaTRl( zWBa?Yv5{@NvIS!*<8~(-#vDeSMkOA0aZOFe#`==Pq@2{E)Z+Y{vefwG{JgZxbW|SK zbbkv*F*b