2020-06-26 10:20:36 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"background/db"
|
|
|
|
"background/logs"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DocTemplate struct {
|
|
|
|
Id int32 `sql:"id" json:"id"`
|
|
|
|
Content string `sql:"content" json:"content"`
|
2021-03-26 05:13:23 +00:00
|
|
|
Name string `sql:"name" json:"name"`
|
2020-06-26 10:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func CreateDocTemplate(templ DocTemplate) error{
|
2021-03-26 05:13:23 +00:00
|
|
|
sql := fmt.Sprintf(`insert into doc_template(content,name) values('%s','%s')`,templ.Content,templ.Name)
|
2020-06-26 10:20:36 +00:00
|
|
|
log.Print(sql)
|
|
|
|
_, e := db.GetMysqlClient().Query(sql)
|
|
|
|
if nil != e {
|
|
|
|
log.Print(sql)
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateDocTemplate(templ DocTemplate) error{
|
2021-03-26 05:13:23 +00:00
|
|
|
sql := fmt.Sprintf(`update doc_template set content = '%s',name = '%s' where doc_template.id = %d`,templ.Content,templ.Name,templ.Id)
|
|
|
|
log.Print(sql)
|
2020-06-26 10:20:36 +00:00
|
|
|
_, e := db.GetMysqlClient().Query(sql)
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteDocTemplate(id int32) error{
|
|
|
|
sql := fmt.Sprintf(`delete from doc_template doc_template memo.id = '%d'`,id)
|
|
|
|
_, e := db.GetMysqlClient().Query(sql)
|
|
|
|
if nil != e {
|
|
|
|
logs.Error(e.Error())
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ReadDocTemplate(id int32) ([]DocTemplate,error){
|
|
|
|
memo := []DocTemplate{}
|
|
|
|
sql := fmt.Sprintf(`select * from doc_template where doc_template.id = '%d'`,id)
|
|
|
|
e := db.GetMysqlClient().Query2(sql,&memo)
|
|
|
|
if nil != e {
|
|
|
|
logs.Error(e.Error())
|
|
|
|
return nil,e
|
|
|
|
}
|
|
|
|
return memo,nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetDocTemplate(title string,limit int,offset int) ([]DocTemplate,error) {
|
|
|
|
memo := []DocTemplate{}
|
2021-03-26 05:13:23 +00:00
|
|
|
sql := fmt.Sprintf(`select * from doc_template limit %d offset %d`,
|
|
|
|
limit,offset)
|
2020-06-26 10:20:36 +00:00
|
|
|
log.Print(sql)
|
|
|
|
e := db.GetMysqlClient().Query2(sql,&memo)
|
|
|
|
if nil != e {
|
|
|
|
logs.Error(e.Error())
|
|
|
|
return nil,e
|
|
|
|
}
|
|
|
|
return memo,nil
|
|
|
|
}
|