no message

master
DESKTOP-4RNDQIC\29019 2021-03-26 13:13:23 +08:00
parent 3521716370
commit 540229aa5e
3 changed files with 90 additions and 12 deletions

View File

@ -680,9 +680,6 @@ func GetMemos(c *gin.Context) {
} }
func GetDocTemplate(c *gin.Context) {
}
func GetMemo(c *gin.Context) { func GetMemo(c *gin.Context) {
rsp := RespBase{"ERR", -1, nil} rsp := RespBase{"ERR", -1, nil}
@ -723,3 +720,82 @@ func DeleteMemos(c *gin.Context) {
resp.Msg = "OK" resp.Msg = "OK"
resp.Status = 0 resp.Status = 0
} }
func CreateDocTemplate(c *gin.Context) {
resp := RespBase{}
defer func() {
c.JSON(200, resp)
}()
var req model.DocTemplate
e := c.BindJSON(&req)
if nil != e {
logs.Error(e.Error())
resp.Msg = "wrong input"
return
}
e = model.CreateDocTemplate(req)
if nil != e{
log.Print(e.Error())
return
}
resp.Data = nil
resp.Msg = "OK"
resp.Status = 0
}
func UpdateDocTemplate(c *gin.Context) {
resp := RespBase{}
defer func() {
c.JSON(200, resp)
}()
var req model.DocTemplate
e := c.BindJSON(&req)
if nil != e {
resp.Msg = "wrong input"
return
}
e = model.UpdateDocTemplate(req)
if nil != e {
logs.Error(e.Error())
return
}
resp.Data = nil
resp.Msg = "OK"
resp.Status = 0
}
func GetDocTemplate(c *gin.Context) {
type ReqGet struct{
Title string `json:"title"`
}
req := ReqGet{}
resp := RespBase{}
defer func() {
c.JSON(200, resp)
}()
e := c.BindJSON(&req)
if nil != e{
log.Print(e.Error())
return
}
ret,e := model.GetDocTemplate(req.Title,5,0)
if nil != e{
log.Print(e.Error())
return
}
resp.Data = ret
resp.Msg = "OK"
resp.Status = 0
}
func DeleteDocTemplate(c *gin.Context) {
resp := RespBase{}
defer func() {
c.JSON(200, resp)
}()
type ReqDeleteDocTemplate struct {
}
}

View File

@ -165,7 +165,6 @@ func main() {
api.POST("type_group", controller.GetDocTypeGroup) // 获取类所在的组 api.POST("type_group", controller.GetDocTypeGroup) // 获取类所在的组
api.POST("group_type", controller.GetDoGroupcType) // 获取类所在的组 api.POST("group_type", controller.GetDoGroupcType) // 获取类所在的组
api.GET("templates", controller.GetDocTemplate) // 获取所有文章的模板
api.GET("doc_versions", nil) // 获取文章的某个版本 api.GET("doc_versions", nil) // 获取文章的某个版本
@ -187,6 +186,11 @@ func main() {
api.GET("/undo", planController.GetUndo) api.GET("/undo", planController.GetUndo)
api.DELETE("/undo/:id", planController.DeleteUndo) api.DELETE("/undo/:id", planController.DeleteUndo)
api.PUT("/doc_template",controller.CreateDocTemplate)
api.POST("/doc_template",controller.UpdateDocTemplate)
api.POST("/get_doc_template",controller.GetDocTemplate)
api.DELETE("/doc_template/:id",controller.DeleteDocTemplate)
} }
openapi := r.Group("openapi") openapi := r.Group("openapi")

View File

@ -10,14 +10,12 @@ import (
type DocTemplate struct { type DocTemplate struct {
Id int32 `sql:"id" json:"id"` Id int32 `sql:"id" json:"id"`
Content string `sql:"content" json:"content"` Content string `sql:"content" json:"content"`
Name string `sql:"content" json:"name"` Name string `sql:"name" json:"name"`
} }
func CreateDocTemplate(templ DocTemplate) error{ func CreateDocTemplate(templ DocTemplate) error{
sql := fmt.Sprintf(`insert into doc_template(content,name) select '%s','%s sql := fmt.Sprintf(`insert into doc_template(content,name) values('%s','%s')`,templ.Content,templ.Name)
from dual where not exists (select * from doc_template where doc_template.name='%s') `,
templ.Content,templ.Name,templ.Name)
log.Print(sql) log.Print(sql)
_, e := db.GetMysqlClient().Query(sql) _, e := db.GetMysqlClient().Query(sql)
if nil != e { if nil != e {
@ -28,8 +26,8 @@ func CreateDocTemplate(templ DocTemplate) error{
} }
func UpdateDocTemplate(templ DocTemplate) error{ func UpdateDocTemplate(templ DocTemplate) error{
sql := fmt.Sprintf(`update doc_template set content = %s, sql := fmt.Sprintf(`update doc_template set content = '%s',name = '%s' where doc_template.id = %d`,templ.Content,templ.Name,templ.Id)
name = %s, where memo.id = '%d'`,templ.Content,templ.Name,templ.Id) log.Print(sql)
_, e := db.GetMysqlClient().Query(sql) _, e := db.GetMysqlClient().Query(sql)
if nil != e { if nil != e {
log.Print(e.Error()) log.Print(e.Error())
@ -61,8 +59,8 @@ func ReadDocTemplate(id int32) ([]DocTemplate,error){
func GetDocTemplate(title string,limit int,offset int) ([]DocTemplate,error) { func GetDocTemplate(title string,limit int,offset int) ([]DocTemplate,error) {
memo := []DocTemplate{} memo := []DocTemplate{}
sql := fmt.Sprintf(`select * from doc_template where doc_template.name like '%s%%' limit %d offset %d`, sql := fmt.Sprintf(`select * from doc_template limit %d offset %d`,
title,limit,offset) limit,offset)
log.Print(sql) log.Print(sql)
e := db.GetMysqlClient().Query2(sql,&memo) e := db.GetMysqlClient().Query2(sql,&memo)
if nil != e { if nil != e {