From 3cad8d369ebc6e98587cc05948de0be2d0ddaa03 Mon Sep 17 00:00:00 2001 From: odboy Date: Sat, 9 Nov 2024 21:27:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E5=8F=82=E6=95=B0=E9=A9=BC=E5=B3=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/resolve_config.go | 4 ++-- dao/resolve_record.go | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/dao/resolve_config.go b/dao/resolve_config.go index 392df4d..3725ec8 100644 --- a/dao/resolve_config.go +++ b/dao/resolve_config.go @@ -10,8 +10,8 @@ import ( ) type ResolveVersion struct { - Id int `xorm:"pk not null integer 'id' autoincr"` - CurrentVersion int `xorm:"not null integer 'curr_version'"` + 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 { diff --git a/dao/resolve_record.go b/dao/resolve_record.go index f0f876f..0df68b5 100644 --- a/dao/resolve_record.go +++ b/dao/resolve_record.go @@ -13,25 +13,41 @@ import ( ) type ResolveRecord struct { - Id int `xorm:"pk not null integer 'id' autoincr"` - Name string `xorm:"not null text 'name'"` - RecordType string `xorm:"not null text 'record_type'"` - Ttl int `xorm:"not null integer 'ttl'"` - Value string `xorm:"not null text 'value'"` - Version int `xorm:"not null integer 'version'"` + Id int `xorm:"pk not null integer 'id' autoincr" json:"id"` + Name string `xorm:"not null text 'name'" json:"name"` + RecordType string `xorm:"not null text 'record_type'" json:"recordType"` + Ttl int `xorm:"not null integer 'ttl'" json:"ttl"` + Value string `xorm:"not null text 'value'" json:"value"` + Version int `xorm:"not null integer 'version'" json:"version"` } func (ResolveRecord) TableName() string { return "resolve_record" } -func FindResolveRecordById(id int) ResolveRecord { +func FindResolveRecordById(id int) *ResolveRecord { var record ResolveRecord _, err := Engine.Table("resolve_record").Where("`id` = ?", id).Get(&record) if err != nil { fmt.Println(err) + return nil } - return record + return &record +} + +func FindOneResolveRecord(wrapper *ResolveRecord, version int) *ResolveRecord { + var record ResolveRecord + _, err := Engine.Table("resolve_record").Where("`name` = ? and `record_type` = ? and `value` = ? and `version` = ?", + wrapper.Name, + wrapper.RecordType, + wrapper.Value, + version, + ).Get(&record) + if err != nil { + fmt.Println(err) + return nil + } + return &record } func FindResolveRecordByVersion(version int) []ResolveRecord { @@ -154,12 +170,8 @@ func IsResolveRecordExistById(id int) bool { } func IsUpdResolveRecordExist(id int, wrapper *ResolveRecord) bool { - r := new(ResolveRecord) - r.Name = wrapper.Name - r.RecordType = wrapper.RecordType - r.Value = wrapper.Value - r.Version = GetResolveVersion() - count, err := Engine.Table("resolve_record").Where("id != ?", id).Count(r) + wrapper.Version = GetResolveVersion() + count, err := Engine.Table("resolve_record").Where("id != ?", id).Count(wrapper) if err != nil { fmt.Println(err) return false