From c120287aa298855af532b790a09eae566e709657 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Fri, 1 Apr 2022 03:27:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=8E=86=E5=8F=B2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/blog.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/model/blog.go b/model/blog.go index 1f9f1b9..654b660 100644 --- a/model/blog.go +++ b/model/blog.go @@ -26,6 +26,14 @@ type Doc struct { OriginUrl string `json:"origin_url" gorm:"column:origin_url" sql:"origin_url"` } +type DocHistory struct{ + ID int32 `json:"id" gorm:"column:id" sql:"id"` + Title string `json:"title" gorm:"column:title" sql:"title"` + DocId int32 `json:"doc_id" gorm:"column:doc_id" sql:"doc_id"` + Content []byte `json:"content" gorm:"column:content" sql:"content"` + EditTime time.Time `json:"edit_time" gorm:"column:edit_time" sql:"edit_time"` +} + type DocGroup struct { Int int32 `sql:"int"` Name string `sql:"name"` @@ -85,7 +93,7 @@ func CreateDoc(doc Doc) error { } /* -UpdateDoc 更新文档 + UpdateDoc 更新文档 */ func UpdateDoc(doc Doc) error { sql := fmt.Sprintf(`update doc set doc.author = '%s' ,doc.title = '%s',doc.type = '%d',doc.content = '%s' ,doc.update_time = '%s' ,doc.version = '%d' where doc.id = '%d'; `, @@ -96,6 +104,13 @@ func UpdateDoc(doc Doc) error { logs.Error(e.Error()) return e } + sql = fmt.Sprintf(`insert into doc(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`, + doc.Title,doc.ID,strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05")) + _, er := db.GetMysqlClient().Query(sql) + if nil != er { + logs.Error(e.Error()) + return e + } return nil } @@ -162,8 +177,9 @@ func GetAllDocs() ([]Doc, error) { return nil, e } return ret, nil - } + + func GetAllGroup() ([]DocGroup, error) { ret := []DocGroup{} sql := fmt.Sprintf("select * from doc_group")