数据库添加文件修改历史记录。

master
zcy 2022-04-01 03:27:07 +08:00
parent 398a9c2772
commit c120287aa2
1 changed files with 18 additions and 2 deletions

View File

@ -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")