no message

master
zcy 2023-09-27 00:32:29 +08:00
parent 3afd2af811
commit 702f023cb5
10 changed files with 344 additions and 238 deletions

View File

@ -1,3 +1,4 @@
{ {
"vue3snippets.enable-compile-vue-file-on-did-save-code": false "vue3snippets.enable-compile-vue-file-on-did-save-code": false,
"C_Cpp.intelliSenseEngineFallback": "enabled"
} }

View File

@ -78,6 +78,7 @@ var gConf ConfAPI
func ApiConfig() ConfAPI{ func ApiConfig() ConfAPI{
return gConf return gConf
} }
func Init(path string) error { func Init(path string) error {
file, e := os.Open(path) file, e := os.Open(path)
if nil != e { if nil != e {

View File

@ -52,6 +52,8 @@ func InitRedis() error {
} }
return nil return nil
} }
func RedisOne() *redis.Client { func RedisOne() *redis.Client {
return gRedis1 return gRedis1
} }

View File

@ -7,6 +7,7 @@ import (
"background/model" "background/model"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"sync" "sync"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -14,23 +15,23 @@ import (
"qiniupkg.com/x/log.v7" "qiniupkg.com/x/log.v7"
) )
type DocTree struct{ type DocTree struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Label string `json:"label"` Label string `json:"label"`
Level int `json:"level"` Level int `json:"level"`
Children []*DocTree `json:"children"` Children []*DocTree `json:"children"`
} }
var gDocMapCache map[int]*DocTree = nil var gDocMapCache map[int]*DocTree = nil
var gLock sync.Mutex var gLock sync.Mutex
func init(){ func init() {
if nil == gDocMapCache{ if nil == gDocMapCache {
gDocMapCache = make(map[int]*DocTree) gDocMapCache = make(map[int]*DocTree)
} }
} }
func InitDocCache(){ func InitDocCache() {
gLock.Lock() gLock.Lock()
for k := range gDocMapCache { for k := range gDocMapCache {
delete(gDocMapCache, k) delete(gDocMapCache, k)
@ -42,24 +43,24 @@ func InitDocCache(){
logs.Error(e.Error()) logs.Error(e.Error())
return return
} }
for _,v := range articles{ for _, v := range articles {
tmp := new (DocTree) tmp := new(DocTree)
tmp.ID = v.ID tmp.ID = v.ID
tmp.Level = int(v.Level) tmp.Level = int(v.Level)
tmp.Label = v.Title tmp.Label = v.Title
tmp.Children = make([]*DocTree,0) tmp.Children = make([]*DocTree, 0)
gDocMapCache[int(v.ID)] = tmp gDocMapCache[int(v.ID)] = tmp
} }
for _,v := range articles{ for _, v := range articles {
tmp := new (DocTree) tmp := new(DocTree)
tmp.ID = v.ID tmp.ID = v.ID
tmp.Label = v.Title tmp.Label = v.Title
tmp.Level = int(v.Level) tmp.Level = int(v.Level)
tmp.Children = make([]*DocTree,0) tmp.Children = make([]*DocTree, 0)
gDocMapCache[int(v.ID)] = tmp gDocMapCache[int(v.ID)] = tmp
} }
for _,v := range articles{ for _, v := range articles {
if v.Father != 0{ if v.Father != 0 {
gDocMapCache[int(v.Father)].Children = append(gDocMapCache[int(v.Father)].Children, gDocMapCache[int(v.ID)]) gDocMapCache[int(v.Father)].Children = append(gDocMapCache[int(v.Father)].Children, gDocMapCache[int(v.ID)])
} }
} }
@ -99,7 +100,7 @@ func GetArticlesTree(c *gin.Context) {
InitDocCache() InitDocCache()
ret := []*DocTree{} ret := []*DocTree{}
for _, v := range articles { for _, v := range articles {
if v.Level == 0{ if v.Level == 0 {
ret = append(ret, gDocMapCache[int(v.ID)]) ret = append(ret, gDocMapCache[int(v.ID)])
} }
} }
@ -213,7 +214,7 @@ func GetArticleCount(c *gin.Context) {
func AddArticleHistory(c *gin.Context) { func AddArticleHistory(c *gin.Context) {
rsp := RespBase{Msg: "FAIL", Status: 211} rsp := RespBase{Msg: "FAIL", Status: 211}
type ReqUpdateArticle struct { type ReqUpdateArticle struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`
Author string `json:"author"` Author string `json:"author"`
@ -238,15 +239,15 @@ func AddArticleHistory(c *gin.Context) {
} }
e := model.InsertDocHistory(model.DocTree{ e := model.InsertDocHistory(model.DocTree{
ID: (req.ID), ID: (req.ID),
Type: int32(req.Type), Type: int32(req.Type),
Title: req.Title, Title: req.Title,
Content: req.Content, Content: req.Content,
Author: req.Author, Author: req.Author,
Father: int32(req.Father), Father: int32(req.Father),
Level: int32(req.Level), Level: int32(req.Level),
},) })
if(nil != e){ if nil != e {
logs.Error(er.Error()) logs.Error(er.Error())
return return
} }
@ -298,7 +299,7 @@ func GetArticle(c *gin.Context) {
query := fmt.Sprintf("select * from doc_copy1 where doc_copy1.id = '%d'", id) query := fmt.Sprintf("select * from doc_copy1 where doc_copy1.id = '%d'", id)
docs := []model.Doc{} docs := []model.Doc{}
e := db.GetMysqlClient().Query2(query, &docs) e := db.GetMysqlClient().Query2(query, &docs)
fmt.Print(query,docs) fmt.Print(query, docs)
if nil != e { if nil != e {
log.Print(e.Error()) log.Print(e.Error())
@ -315,7 +316,7 @@ func GetArticle(c *gin.Context) {
func UpdateArtilce(c *gin.Context) { func UpdateArtilce(c *gin.Context) {
rsp := RespBase{Msg: "FAIL", Status: 210} rsp := RespBase{Msg: "FAIL", Status: 210}
type ReqUpdateArticle struct { type ReqUpdateArticle struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`
Author string `json:"author"` Author string `json:"author"`
@ -327,8 +328,6 @@ func UpdateArtilce(c *gin.Context) {
c.JSON(200, rsp) c.JSON(200, rsp)
}() }()
er := c.BindJSON(&req) er := c.BindJSON(&req)
if nil != er { if nil != er {
logs.Error(er.Error()) logs.Error(er.Error())
@ -357,7 +356,7 @@ func UpdateArtilce(c *gin.Context) {
Author: req.Author, Author: req.Author,
ID: req.ID, ID: req.ID,
IsPublic: int32(req.IsPublic), IsPublic: int32(req.IsPublic),
Version: (docs[0].Version + 1), Version: (docs[0].Version + 1),
}, },
) )
if nil != e { if nil != e {
@ -369,12 +368,10 @@ func UpdateArtilce(c *gin.Context) {
} }
func UpdateArtilceTree(c *gin.Context) { func UpdateArtilceTree(c *gin.Context) {
rsp := RespBase{Msg: "FAIL", Status: 210} rsp := RespBase{Msg: "FAIL", Status: 210}
type ReqUpdateArticle struct { type ReqUpdateArticle struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`
Author string `json:"author"` Author string `json:"author"`
@ -408,6 +405,8 @@ func UpdateArtilceTree(c *gin.Context) {
rsp.Msg = "不存在该" rsp.Msg = "不存在该"
return return
} }
log.Print(req.Content)
req.Content = strings.ReplaceAll(req.Content, "\\", "\\\\")
e = model.UpdateDocTree( e = model.UpdateDocTree(
model.DocTree{ model.DocTree{
Type: int32(req.Type), Type: int32(req.Type),
@ -416,37 +415,38 @@ func UpdateArtilceTree(c *gin.Context) {
Author: req.Author, Author: req.Author,
ID: req.ID, ID: req.ID,
IsPublic: int32(req.IsPublic), IsPublic: int32(req.IsPublic),
Version: (docs[0].Version + 1), Version: (docs[0].Version + 1),
Father: int32(req.Father), Father: int32(req.Father),
Level: int32(req.Level), Level: int32(req.Level),
}, },
) )
if nil != e { if nil != e {
logs.Error(e.Error()) logs.Error(e.Error())
return return
} }
config.RedisOne().Del("artilcetree")
rsp.Msg = "OK" rsp.Msg = "OK"
rsp.Status = 0 rsp.Status = 0
config.RedisOne().Del("artilcetree")
} }
func SearchArticleESHightLight(c *gin.Context) { func SearchArticleESHightLight(c *gin.Context) {
type RetHighlight struct{ type RetHighlight struct {
ID int64 `json:"id" gorm:"column:id" sql:"id"` ID int64 `json:"id" gorm:"column:id" sql:"id"`
Title string `json:"title" gorm:"column:title" sql:"title"` Title string `json:"title" gorm:"column:title" sql:"title"`
Type int32 `json:"type" gorm:"column:type" sql:"type"` Type int32 `json:"type" gorm:"column:type" sql:"type"`
Highlight []string `json:"highlight" gorm:"column:highlight" sql:"highlight"` Highlight []string `json:"highlight" gorm:"column:highlight" sql:"highlight"`
} }
rsp := RespBase{Msg: "FAIL", Status: 210} rsp := RespBase{Msg: "FAIL", Status: 210}
defer func() { defer func() {
c.JSON(200, rsp) c.JSON(200, rsp)
}() }()
type Req struct{ type Req struct {
Term string `json:"term"` Term string `json:"term"`
} }
var req Req var req Req
e := c.BindJSON(&req) e := c.BindJSON(&req)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
@ -457,7 +457,7 @@ func SearchArticleESHightLight(c *gin.Context) {
highlight = highlight.PreTags("<span>").PostTags("</span>") highlight = highlight.PreTags("<span>").PostTags("</span>")
x := []RetHighlight{} x := []RetHighlight{}
_, e = db.GetElastic(). _, e = db.GetElastic().
QueryHighlight("doc", query, &x,highlight, 10, 0) QueryHighlight("doc", query, &x, highlight, 10, 0)
if nil != e { if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
@ -473,12 +473,12 @@ func SearchArticleES(c *gin.Context) {
defer func() { defer func() {
c.JSON(200, rsp) c.JSON(200, rsp)
}() }()
type Req struct{ type Req struct {
Term string `json:"term"` Term string `json:"term"`
} }
var req Req var req Req
e := c.BindJSON(&req) e := c.BindJSON(&req)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
@ -535,7 +535,6 @@ func AddArticle(c *gin.Context) {
rsp.Status = 0 rsp.Status = 0
} }
func AddArticleTree(c *gin.Context) { func AddArticleTree(c *gin.Context) {
rsp := RespBase{Msg: "FAIL", Status: 210} rsp := RespBase{Msg: "FAIL", Status: 210}
type ReqAddArticle struct { type ReqAddArticle struct {
@ -544,7 +543,7 @@ func AddArticleTree(c *gin.Context) {
Author string `json:"author"` Author string `json:"author"`
Type int64 `json:"type"` Type int64 `json:"type"`
Ispublic int `json:"is_public"` Ispublic int `json:"is_public"`
Father int `json:"father"` Father int `json:"father"`
Level int `json:"level"` Level int `json:"level"`
} }
var req ReqAddArticle var req ReqAddArticle
@ -569,17 +568,19 @@ func AddArticleTree(c *gin.Context) {
Content: req.Content, Content: req.Content,
Author: req.Author, Author: req.Author,
IsPublic: int32(req.Ispublic), IsPublic: int32(req.Ispublic),
Father: int32(req.Father), Father: int32(req.Father),
Level: int32(req.Level), Level: int32(req.Level),
}, },
) )
if nil != e { if nil != e {
logs.Error(e.Error()) logs.Error(e.Error())
return return
} }
config.RedisOne().Del("artilcetree")
rsp.Msg = "OK" rsp.Msg = "OK"
rsp.Status = 0 rsp.Status = 0
rsp.Data = model.GetIdFromTitle(req.Title)
config.RedisOne().Del("artilcetree")
} }
func ArticlesType(c *gin.Context) { func ArticlesType(c *gin.Context) {
@ -672,7 +673,6 @@ func DeleteArticle(c *gin.Context) {
rsp.Msg = "OK" rsp.Msg = "OK"
} }
func DeleteArticleTree(c *gin.Context) { func DeleteArticleTree(c *gin.Context) {
rsp := RespBase{Msg: "FAIL", Status: 210} rsp := RespBase{Msg: "FAIL", Status: 210}
defer func() { defer func() {
@ -713,8 +713,8 @@ func ArticlesTypes(c *gin.Context) {
} }
func SearchArticles(c *gin.Context) { func SearchArticles(c *gin.Context) {
type ReqSearch struct{ type ReqSearch struct {
Term string `json:"term"` Term string `json:"term"`
} }
resp := RespBase{"unkown error", -231, nil} resp := RespBase{"unkown error", -231, nil}
defer func() { defer func() {
@ -778,7 +778,6 @@ func CreateBook(c *gin.Context) {
resp.Status = 0 resp.Status = 0
} }
func BookCount(c *gin.Context) { func BookCount(c *gin.Context) {
resp := RespBase{"unkown error", -231, nil} resp := RespBase{"unkown error", -231, nil}
defer func() { defer func() {
@ -791,10 +790,9 @@ func BookCount(c *gin.Context) {
resp.Status = 0 resp.Status = 0
} }
func Delbook(c *gin.Context) { func Delbook(c *gin.Context) {
type Req struct{ type Req struct {
ID int32 `json:"id"` ID int32 `json:"id"`
} }
var req Req var req Req
resp := RespBase{"unkown error", -231, nil} resp := RespBase{"unkown error", -231, nil}
@ -810,7 +808,7 @@ func Delbook(c *gin.Context) {
} }
count := 0 count := 0
e = db.GetOrm().Model(&model.Book{}).Delete(model.Book{ID: int64(req.ID)}).Error e = db.GetOrm().Model(&model.Book{}).Delete(model.Book{ID: int64(req.ID)}).Error
if nil != e{ if nil != e {
log.Printf(e.Error()) log.Printf(e.Error())
return return
} }
@ -897,17 +895,17 @@ func GetPageBook(c *gin.Context) {
} }
books := []model.Book{} books := []model.Book{}
if req.BookName != ""{ if req.BookName != "" {
e = db.GetOrm().Model(&model.Book{}). e = db.GetOrm().Model(&model.Book{}).
Where(fmt.Sprintf("book_name like '%%%s%%' ",req.BookName)). Where(fmt.Sprintf("book_name like '%%%s%%' ", req.BookName)).
Limit(iLmit).Offset(iOffset).Find(&books).Error Limit(iLmit).Offset(iOffset).Find(&books).Error
if nil != e { if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
}else{ } else {
e = db.GetOrm().Model(&model.Book{}). e = db.GetOrm().Model(&model.Book{}).
Limit(iLmit).Offset(iOffset).Find(&books).Error Limit(iLmit).Offset(iOffset).Find(&books).Error
if nil != e { if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
@ -1046,7 +1044,6 @@ func GetMemos(c *gin.Context) {
} }
func GetMemoCnt(c *gin.Context) { func GetMemoCnt(c *gin.Context) {
rsp := RespBase{"ERR", -1, nil} rsp := RespBase{"ERR", -1, nil}
defer func() { defer func() {
@ -1060,7 +1057,6 @@ func GetMemoCnt(c *gin.Context) {
} }
func GetMemo(c *gin.Context) { func GetMemo(c *gin.Context) {
rsp := RespBase{"ERR", -1, nil} rsp := RespBase{"ERR", -1, nil}
defer func() { defer func() {
@ -1076,7 +1072,6 @@ func GetMemo(c *gin.Context) {
rsp.Data = dat rsp.Data = dat
} }
func DeleteMemos(c *gin.Context) { func DeleteMemos(c *gin.Context) {
resp := RespBase{"unkown error", -231, nil} resp := RespBase{"unkown error", -231, nil}
defer func() { defer func() {
@ -1101,7 +1096,6 @@ func DeleteMemos(c *gin.Context) {
resp.Status = 0 resp.Status = 0
} }
func CreateDocTemplate(c *gin.Context) { func CreateDocTemplate(c *gin.Context) {
resp := RespBase{} resp := RespBase{}
defer func() { defer func() {
@ -1115,7 +1109,7 @@ func CreateDocTemplate(c *gin.Context) {
return return
} }
e = model.CreateDocTemplate(req) e = model.CreateDocTemplate(req)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
@ -1124,7 +1118,6 @@ func CreateDocTemplate(c *gin.Context) {
resp.Status = 0 resp.Status = 0
} }
func UpdateDocTemplate(c *gin.Context) { func UpdateDocTemplate(c *gin.Context) {
resp := RespBase{} resp := RespBase{}
defer func() { defer func() {
@ -1147,21 +1140,21 @@ func UpdateDocTemplate(c *gin.Context) {
} }
func GetDocTemplate(c *gin.Context) { func GetDocTemplate(c *gin.Context) {
type ReqGet struct{ type ReqGet struct {
Title string `json:"title"` Title string `json:"title"`
} }
req := ReqGet{} req := ReqGet{}
resp := RespBase{} resp := RespBase{}
defer func() { defer func() {
c.JSON(200, resp) c.JSON(200, resp)
}() }()
e := c.BindJSON(&req) e := c.BindJSON(&req)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
ret,e := model.GetDocTemplate(req.Title,5,0) ret, e := model.GetDocTemplate(req.Title, 5, 0)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
@ -1176,13 +1169,13 @@ func DeleteDocTemplate(c *gin.Context) {
c.JSON(200, resp) c.JSON(200, resp)
}() }()
sid := c.Param("id") sid := c.Param("id")
id,e := strconv.Atoi(sid) id, e := strconv.Atoi(sid)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
e = model.DeleteDocTemplate(int32(id)) e = model.DeleteDocTemplate(int32(id))
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
@ -1197,19 +1190,19 @@ func GetDocTemplateId(c *gin.Context) {
c.JSON(200, resp) c.JSON(200, resp)
}() }()
sid := c.Param("id") sid := c.Param("id")
id,e := strconv.Atoi(sid) id, e := strconv.Atoi(sid)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
ret,e := model.ReadDocTemplate(int32(id)) ret, e := model.ReadDocTemplate(int32(id))
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
return return
} }
if len(ret) > 0{ if len(ret) > 0 {
resp.Data = ret[0] resp.Data = ret[0]
}else{ } else {
resp.Data = nil resp.Data = nil
} }
resp.Msg = "OK" resp.Msg = "OK"

View File

@ -60,8 +60,7 @@ func (p *ElkEngine) Delete(query elastic.Query, index string) error {
return nil return nil
} }
func (p *ElkEngine) QueryHighlight(index string, query elastic.Query, v interface{}, hightlight *elastic.Highlight,
func (p *ElkEngine) QueryHighlight(index string, query elastic.Query, v interface{},hightlight *elastic.Highlight,
limit int, offset int) ([]string, error) { limit int, offset int) ([]string, error) {
if reflect.ValueOf(v).Kind() != reflect.Ptr { if reflect.ValueOf(v).Kind() != reflect.Ptr {
@ -186,7 +185,7 @@ func (p *ElkEngine) Query(index string, query elastic.Query, v interface{},
} else { } else {
res, err := p.cli.Search(index).Query(query).Size(limit).From(limit * offset).Do(context.Background()) res, err := p.cli.Search(index).Query(query).Size(limit).From(limit * offset).Do(context.Background())
if err != nil { if err != nil {
print(err) log.Print(err.Error())
return nil, err return nil, err
} }
id := []string{} id := []string{}

28
main.go
View File

@ -50,7 +50,7 @@ func CORSMiddleware(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length") c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true") c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
log.Print("remote addr is ",c.Request.RemoteAddr) log.Print("remote addr is ", c.Request.RemoteAddr)
if c.Request.Method == "OPTIONS" { if c.Request.Method == "OPTIONS" {
log.Println("OPTIONS") log.Println("OPTIONS")
@ -128,6 +128,7 @@ func main() {
if nil != e { if nil != e {
} }
}() }()
go func() { go func() {
// programatically set swagger info // programatically set swagger info
@ -157,13 +158,13 @@ func main() {
/** 修改密码**/ /** 修改密码**/
api.POST("modify_pass", middle.AuthMiddle, userController.ModifyPasswd) api.POST("modify_pass", middle.AuthMiddle, userController.ModifyPasswd)
api.GET("/article/:id", controller.GetArticle) //获取文章 api.GET("/article/:id", controller.GetArticle) //获取文章
api.POST("/articles", controller.GetArticles) // 获取所有文章 api.POST("/articles", controller.GetArticles) // 获取所有文章
api.GET("/articles_tree", controller.GetArticlesTree) // 获取所有文章 api.GET("/articles_tree", controller.GetArticlesTree) // 获取所有文章
api.PUT("/article", controller.AddArticle) // 添加文章 api.PUT("/article", controller.AddArticle) // 添加文章
api.PUT("/article_tree", controller.AddArticleTree) // 添加文章 api.PUT("/article_tree", controller.AddArticleTree) // 添加文章
api.PUT("/article_tree_history", controller.AddArticleHistory) // 添加文章 api.PUT("/article_tree_history", controller.AddArticleHistory) // 添加文章
api.PUT("/article_search", controller.SearchArticles) // 添加文章 api.PUT("/article_search", controller.SearchArticles) // 添加文章
api.GET("/article_type", controller.ArticlesType) //获取所有文章分类 api.GET("/article_type", controller.ArticlesType) //获取所有文章分类
@ -172,13 +173,13 @@ func main() {
api.POST("/doc_search_term", controller.SearchArticleES) // 文章内容搜索,基于es的倒排 api.POST("/doc_search_term", controller.SearchArticleES) // 文章内容搜索,基于es的倒排
api.POST("/doc_match_search_hightlight", controller.SearchArticleESHightLight) // 文章内容搜索,基于es的倒排 api.POST("/doc_match_search_hightlight", controller.SearchArticleESHightLight) // 文章内容搜索,基于es的倒排
api.POST("/article_update", controller.UpdateArtilce) //更新文章 api.POST("/article_update", controller.UpdateArtilce) //更新文章
api.POST("/article_update_tree", controller.UpdateArtilceTree) //更新文章 api.POST("/article_update_tree", controller.UpdateArtilceTree) //更新文章
api.GET("/articleCount", controller.GetArticleCount) //获取所有文章个数 api.GET("/articleCount", controller.GetArticleCount) //获取所有文章个数
api.DELETE("/article/:id", controller.DeleteArticle) ////删除文章 api.DELETE("/article/:id", controller.DeleteArticle) ////删除文章
api.DELETE("/article_tree/:id", controller.DeleteArticleTree) ////删除文章 api.DELETE("/article_tree/:id", controller.DeleteArticleTree) ////删除文章
api.GET("/article_history",controller.GetArticleHistory) // 历史 api.GET("/article_history", controller.GetArticleHistory) // 历史
api.POST("/image_upload", fileController.OnUpload) // 上传图片,如果图片太大自动裁减为原来的一半 api.POST("/image_upload", fileController.OnUpload) // 上传图片,如果图片太大自动裁减为原来的一半
api.POST("/image_upload_origin", fileController.OnUploadOrigin) // 上传图片 api.POST("/image_upload_origin", fileController.OnUploadOrigin) // 上传图片
@ -235,6 +236,7 @@ func main() {
api.DELETE("/doc_template/:id", controller.DeleteDocTemplate) // 删除文章模板 api.DELETE("/doc_template/:id", controller.DeleteDocTemplate) // 删除文章模板
api.GET("/doc_template/:id", controller.GetDocTemplateId) //获得单个文章模板信息 api.GET("/doc_template/:id", controller.GetDocTemplateId) //获得单个文章模板信息
} }
openapi := r.Group("openapi") openapi := r.Group("openapi")
{ {
openapi.POST("/diff") // 比较两个文档差异 openapi.POST("/diff") // 比较两个文档差异

View File

@ -12,58 +12,58 @@ import (
) )
type Doc struct { type Doc struct {
ID int64 `json:"id" gorm:"column:id" sql:"id"` ID int64 `json:"id" gorm:"column:id" sql:"id"`
Title string `json:"title" gorm:"column:title" sql:"title"` Title string `json:"title" gorm:"column:title" sql:"title"`
Type int32 `json:"type" gorm:"column:type" sql:"type"` Type int32 `json:"type" gorm:"column:type" sql:"type"`
Content string `json:"content" gorm:"column:content" sql:"content"` Content string `json:"content" gorm:"column:content" sql:"content"`
Author string `json:"author" gorm:"column:author" sql:"author"` Author string `json:"author" gorm:"column:author" sql:"author"`
CreateTime time.Time `json:"create_time" gorm:"column:create_time" sql:"create_time"` CreateTime time.Time `json:"create_time" gorm:"column:create_time" sql:"create_time"`
UpdateTime time.Time `json:"update_time" gorm:"column:update_time" sql:"update_time"` UpdateTime time.Time `json:"update_time" gorm:"column:update_time" sql:"update_time"`
DeleteTime time.Time `json:"delete_time" gorm:"column:delete_time" sql:"delete_time"` DeleteTime time.Time `json:"delete_time" gorm:"column:delete_time" sql:"delete_time"`
Version int32 `json:"version" gorm:"column:version" sql:"version"` Version int32 `json:"version" gorm:"column:version" sql:"version"`
IsPublic int32 `json:"is_public" gorm:"column:is_public" sql:"is_public"` IsPublic int32 `json:"is_public" gorm:"column:is_public" sql:"is_public"`
Deleted int32 `json:"deleted" gorm:"column:deleted" sql:"deleted"` Deleted int32 `json:"deleted" gorm:"column:deleted" sql:"deleted"`
OriginUrl string `json:"origin_url" gorm:"column:origin_url" sql:"origin_url"` OriginUrl string `json:"origin_url" gorm:"column:origin_url" sql:"origin_url"`
EsId string `json:"es_id" gorm:"column:es_id" sql:"es_id"` EsId string `json:"es_id" gorm:"column:es_id" sql:"es_id"`
DeletedAt time.Time `json:"deleted_at" gorm:"column:deleted_at" sql:"deleted_at"` DeletedAt time.Time `json:"deleted_at" gorm:"column:deleted_at" sql:"deleted_at"`
Father int32 `json:"father" gorm:"column:father" sql:"father"` Father int32 `json:"father" gorm:"column:father" sql:"father"`
Level int32 `json:"level" gorm:"column:level" sql:"level"` Level int32 `json:"level" gorm:"column:level" sql:"level"`
} }
type DocTree struct { type DocTree struct {
ID int64 `json:"id" gorm:"column:id" sql:"id"` ID int64 `json:"id" gorm:"column:id" sql:"id"`
Title string `json:"title" gorm:"column:title" sql:"title"` Title string `json:"title" gorm:"column:title" sql:"title"`
Type int32 `json:"type" gorm:"column:type" sql:"type"` Type int32 `json:"type" gorm:"column:type" sql:"type"`
Content string `json:"content" gorm:"column:content" sql:"content"` Content string `json:"content" gorm:"column:content" sql:"content"`
Author string `json:"author" gorm:"column:author" sql:"author"` Author string `json:"author" gorm:"column:author" sql:"author"`
CreateTime time.Time `json:"create_time" gorm:"column:create_time" sql:"create_time"` CreateTime time.Time `json:"create_time" gorm:"column:create_time" sql:"create_time"`
UpdateTime time.Time `json:"update_time" gorm:"column:update_time" sql:"update_time"` UpdateTime time.Time `json:"update_time" gorm:"column:update_time" sql:"update_time"`
DeleteTime time.Time `json:"delete_time" gorm:"column:delete_time" sql:"delete_time"` DeleteTime time.Time `json:"delete_time" gorm:"column:delete_time" sql:"delete_time"`
Version int32 `json:"version" gorm:"column:version" sql:"version"` Version int32 `json:"version" gorm:"column:version" sql:"version"`
IsPublic int32 `json:"is_public" gorm:"column:is_public" sql:"is_public"` IsPublic int32 `json:"is_public" gorm:"column:is_public" sql:"is_public"`
Deleted int32 `json:"deleted" gorm:"column:deleted" sql:"deleted"` Deleted int32 `json:"deleted" gorm:"column:deleted" sql:"deleted"`
OriginUrl string `json:"origin_url" gorm:"column:origin_url" sql:"origin_url"` OriginUrl string `json:"origin_url" gorm:"column:origin_url" sql:"origin_url"`
EsId string `json:"es_id" gorm:"column:es_id" sql:"es_id"` EsId string `json:"es_id" gorm:"column:es_id" sql:"es_id"`
DeletedAt time.Time `json:"deleted_at" gorm:"column:deleted_at" sql:"deleted_at"` DeletedAt time.Time `json:"deleted_at" gorm:"column:deleted_at" sql:"deleted_at"`
Father int32 `json:"father" gorm:"column:father" sql:"father"` Father int32 `json:"father" gorm:"column:father" sql:"father"`
Level int32 `json:"level" gorm:"column:level" sql:"level"` Level int32 `json:"level" gorm:"column:level" sql:"level"`
} }
// 设置User的表名为`profiles` // 设置User的表名为`profiles`
func (DocTree) TableName() string { func (DocTree) TableName() string {
return "doc_copy1" return "doc_copy1"
} }
type DocType struct{ type DocType struct {
Id int32 `json:"id" gorm:"column:id" sql:"id"` Id int32 `json:"id" gorm:"column:id" sql:"id"`
TypeName string `json:"type_name" gorm:"column:type_name" sql:"type_name"` TypeName string `json:"type_name" gorm:"column:type_name" sql:"type_name"`
Group int32 `json:"group" gorm:"column:group" sql:"group"` Group int32 `json:"group" gorm:"column:group" sql:"group"`
} }
type DocHistory struct{ type DocHistory struct {
ID int32 `json:"id" gorm:"column:id" sql:"id"` ID int32 `json:"id" gorm:"column:id" sql:"id"`
Title string `json:"title" gorm:"column:title" sql:"title"` Title string `json:"title" gorm:"column:title" sql:"title"`
DocId int32 `json:"doc_id" gorm:"column:doc_id" sql:"doc_id"` DocId int32 `json:"doc_id" gorm:"column:doc_id" sql:"doc_id"`
Content string `json:"content" gorm:"column:content" sql:"content"` Content string `json:"content" gorm:"column:content" sql:"content"`
EditTime string `json:"edit_time" gorm:"column:edit_time" sql:"edit_time"` EditTime string `json:"edit_time" gorm:"column:edit_time" sql:"edit_time"`
} }
@ -125,8 +125,6 @@ func CreateDoc(doc Doc) error {
return nil return nil
} }
/* /*
CreateDoc CreateDoc
*/ */
@ -145,7 +143,7 @@ func CreateDocTree(doc DocTree) error {
DUAL DUAL
WHERE WHERE
NOT EXISTS ( SELECT * FROM doc_copy1 WHERE doc_copy1.title = '%s' );`, doc.Title, strings.Replace(doc.Content, "'", "\\'", -1), NOT EXISTS ( SELECT * FROM doc_copy1 WHERE doc_copy1.title = '%s' );`, doc.Title, strings.Replace(doc.Content, "'", "\\'", -1),
doc.Author, doc.Type, doc.IsPublic, time.Now().Format("2006-01-02 15:04:05"), doc.Father,doc.Level,doc.Title) doc.Author, doc.Type, doc.IsPublic, time.Now().Format("2006-01-02 15:04:05"), doc.Father, doc.Level, doc.Title)
_, e := db.GetMysqlClient().Query(sql) _, e := db.GetMysqlClient().Query(sql)
if nil != e { if nil != e {
log.Print(sql) log.Print(sql)
@ -155,13 +153,27 @@ func CreateDocTree(doc DocTree) error {
return nil return nil
} }
func GetIdFromTitle(title string) int {
motors := []DocTree{}
db.GetOrm().LogMode(true)
db.GetOrm().Model(&DocTree{}).Find(&motors, fmt.Sprintf("title = '%s'", title))
if len(motors) == 0 {
return -1
}
db.GetOrm().LogMode(false)
return int(motors[0].ID)
}
/* /*
UpdateDoc UpdateDoc
*/ */
func UpdateDoc(doc Doc) error { 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'; `, 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'; `,
doc.Author, doc.Title, doc.Type, doc.Author, doc.Title, doc.Type,
strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"),doc.Version, doc.ID) strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"), doc.Version, doc.ID)
_, e := db.GetMysqlClient().Query(sql) _, e := db.GetMysqlClient().Query(sql)
if nil != e { if nil != e {
logs.Error(e.Error()) logs.Error(e.Error())
@ -177,11 +189,10 @@ func UpdateDoc(doc Doc) error {
return nil return nil
} }
// 添加文件版本。 // 添加文件版本。
func InsertDocHistory(doc DocTree) error{ func InsertDocHistory(doc DocTree) error {
sql := fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`, sql := fmt.Sprintf(`insert into doc_history(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")) doc.Title, doc.ID, strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"))
_, er := db.GetMysqlClient().Query(sql) _, er := db.GetMysqlClient().Query(sql)
if nil != er { if nil != er {
logs.Error(er.Error()) logs.Error(er.Error())
@ -198,7 +209,7 @@ func UpdateDocTree(doc DocTree) error {
doc_copy1.type = '%d',doc_copy1.content = '%s' ,doc_copy1.update_time = '%s' , doc_copy1.type = '%d',doc_copy1.content = '%s' ,doc_copy1.update_time = '%s' ,
doc_copy1.version = '%d' where doc_copy1.id = '%d'; `, doc_copy1.version = '%d' where doc_copy1.id = '%d'; `,
doc.Author, doc.Title, doc.Type, doc.Author, doc.Title, doc.Type,
strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"),doc.Version, doc.ID) strings.Replace(doc.Content, "'", "\\'", -1), time.Now().Format("2006-01-02 15:04:05"), doc.Version, doc.ID)
_, e := db.GetMysqlClient().Query(sql) _, e := db.GetMysqlClient().Query(sql)
if nil != e { if nil != e {
logs.Error(e.Error()) logs.Error(e.Error())
@ -220,8 +231,6 @@ func DeleteDoc(id int64) error {
return nil return nil
} }
/* /*
DeleteDoc DeleteDoc
*/ */
@ -276,9 +285,9 @@ func DeleteArticleType(id int32) error {
return nil return nil
} }
func GetAllDocs() ([]Doc, error) { func GetAllDocs() ([]DocTree, error) {
ret := []Doc{} ret := []DocTree{}
sql := fmt.Sprintf("select * from doc") sql := fmt.Sprintf("select * from doc_copy1")
e := db.GetMysqlClient().Query2(sql, &ret) e := db.GetMysqlClient().Query2(sql, &ret)
if nil != e { if nil != e {
logs.Error(e.Error()) logs.Error(e.Error())
@ -287,7 +296,6 @@ func GetAllDocs() ([]Doc, error) {
return ret, nil return ret, nil
} }
func GetAllGroup() ([]DocGroup, error) { func GetAllGroup() ([]DocGroup, error) {
ret := []DocGroup{} ret := []DocGroup{}
sql := fmt.Sprintf("select * from doc_group") sql := fmt.Sprintf("select * from doc_group")

View File

@ -35,6 +35,7 @@ func MysqlToElasticSearchMapping(types string, Key string) string {
} }
return "" return ""
} }
/* /*
"settings":{ "settings":{
"number_of_shards":1, "number_of_shards":1,
@ -76,7 +77,7 @@ func QueryDocument(query elastic.Query, limit int, offset int) ([]Hardware, erro
} }
return ret, nil return ret, nil
} }
func InsertDocToElaticSearch(doc Doc) error { func InsertDocToElaticSearch(doc DocTree) error {
matchPhraseQuery := elastic.NewMatchQuery("title", doc.Title) matchPhraseQuery := elastic.NewMatchQuery("title", doc.Title)
existedHardware, e := QueryHardwares(matchPhraseQuery, 10, 0) existedHardware, e := QueryHardwares(matchPhraseQuery, 10, 0)
log.Print(e, existedHardware) log.Print(e, existedHardware)
@ -97,7 +98,7 @@ func InsertDocToElaticSearch(doc Doc) error {
func CreateIndexFromMysqlTable(tblname string) error { func CreateIndexFromMysqlTable(tblname string) error {
columns := []Field{} columns := []Field{}
e := db.GetMysqlClient().Query2("describe " + tblname, &columns) e := db.GetMysqlClient().Query2("describe "+tblname, &columns)
if nil != e { if nil != e {
logger.Debug(e.Error()) logger.Debug(e.Error())
return e return e
@ -155,7 +156,8 @@ func PortDocumentToElasticsearch(tblname string) error {
"analysis": map[string]interface{}{ "analysis": map[string]interface{}{
"analyzer": map[string]interface{}{ "analyzer": map[string]interface{}{
"default": map[string]interface{}{ "default": map[string]interface{}{
"type": "smartcn", "type": "ik_smart",
// "type": "smartcn",
}, },
}, },
}, },
@ -172,6 +174,7 @@ func PortDocumentToElasticsearch(tblname string) error {
if nil != e { if nil != e {
log.Print(e.Error()) log.Print(e.Error())
} }
log.Print(string(dat))
e = db.GetElastic().CreateIndex(tblname, string(dat)) e = db.GetElastic().CreateIndex(tblname, string(dat))
if nil != e { if nil != e {
log.Print(e.Error()) log.Print(e.Error())

View File

@ -15,17 +15,16 @@ import (
"time" "time"
) )
func TestWaitGroup(t *testing.T) { func TestWaitGroup(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
go func () { go func() {
time.Sleep(3*time.Second) time.Sleep(3 * time.Second)
t.Logf("job 1 done") t.Logf("job 1 done")
wg.Done() wg.Done()
}() }()
go func () { go func() {
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
t.Logf("job 2 done") t.Logf("job 2 done")
wg.Done() wg.Done()
@ -34,29 +33,28 @@ func TestWaitGroup(t *testing.T) {
t.Log("all finish") t.Log("all finish")
} }
func TestChanel(t *testing.T){ func TestChanel(t *testing.T) {
exit := make(chan bool) exit := make(chan bool)
go func () { go func() {
for { for {
select { select {
case <-exit: case <-exit:
t.Logf("exit 1") t.Logf("exit 1")
return return
case <- time.After(1 * time.Second) : case <-time.After(1 * time.Second):
t.Logf("time out ") t.Logf("time out ")
} }
} }
}() }()
go func () { go func() {
for { for {
select { select {
case <-exit: case <-exit:
t.Logf("exit 2") t.Logf("exit 2")
return return
case <- time.After(1 * time.Second) : case <-time.After(1 * time.Second):
t.Logf("time out ") t.Logf("time out ")
} }
} }
@ -65,25 +63,24 @@ func TestChanel(t *testing.T){
exit <- true exit <- true
t.Logf("finish") t.Logf("finish")
} }
type TestInherit struct{ type TestInherit struct {
context.Context context.Context
x int32 x int32
} }
func TestTimeoutContext(t * testing.T){
ctx,_ := context.WithTimeout(context.Background(), time.Second * 1)
aa := TestInherit{ctx,1}
go func (aa *TestInherit) { func TestTimeoutContext(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), time.Second*1)
aa := TestInherit{ctx, 1}
go func(aa *TestInherit) {
for { for {
select { select {
case <-aa.Done(): case <-aa.Done():
t.Logf("exit") t.Logf("exit")
return return
case <- time.After(5 * time.Second) : case <-time.After(5 * time.Second):
t.Logf("time out ") t.Logf("time out ")
} }
} }
@ -92,40 +89,40 @@ func TestTimeoutContext(t * testing.T){
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
} }
func TestContext(t *testing.T){ func TestContext(t *testing.T) {
ctx,cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
go func () { go func() {
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
t.Logf("exit") t.Logf("exit")
return return
case <- time.After(1 * time.Second) : case <-time.After(1 * time.Second):
t.Logf("time out ") t.Logf("time out ")
} }
} }
}() }()
go func () { go func() {
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
t.Logf("exit") t.Logf("exit")
return return
case <- time.After(1 * time.Second) : case <-time.After(1 * time.Second):
t.Logf("time out ") t.Logf("time out ")
} }
} }
}() }()
go func () { go func() {
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
t.Logf("exit") t.Logf("exit")
return return
case <- time.After(1 * time.Second) : case <-time.After(1 * time.Second):
t.Logf("time out ") t.Logf("time out ")
} }
} }
@ -133,6 +130,5 @@ func TestContext(t *testing.T){
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
cancel() cancel()
t.Logf("finish") t.Logf("finish")
} }

View File

@ -59,7 +59,19 @@ func TestPortDocToElastic(t *testing.T) {
InitRedisConfig() InitRedisConfig()
InitMysql() InitMysql()
db.InitELK() db.InitELK()
e := model.PortDocumentToElasticsearch("doc") e := model.PortDocumentToElasticsearch("doc_copy1")
if nil != e {
log.Print(e.Error())
}
}
func TestPortDocTreeToElastic(t *testing.T) {
InitConfig()
InitLogs()
InitRedisConfig()
InitMysql()
db.InitELK()
e := model.PortDocumentToElasticsearch("doc_copy1")
if nil != e { if nil != e {
log.Print(e.Error()) log.Print(e.Error())
} }
@ -129,7 +141,6 @@ func TestChangeStructFieldThroughStruct(t *testing.T) {
fmt.Println(cap(arr1)) fmt.Println(cap(arr1))
} }
func TestPortDocVersion(t *testing.T) { func TestPortDocVersion(t *testing.T) {
InitConfig() InitConfig()
InitLogs() InitLogs()
@ -139,9 +150,9 @@ func TestPortDocVersion(t *testing.T) {
docs := []model.Doc{} docs := []model.Doc{}
doc_groups := []model.DocGroup{} doc_groups := []model.DocGroup{}
doc_types := []model.DocType{} doc_types := []model.DocType{}
e := db.GetMysqlClient().Query2("select * from doc_group",&doc_groups) e := db.GetMysqlClient().Query2("select * from doc_group", &doc_groups)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
} }
// for k,v := range doc_groups{ // for k,v := range doc_groups{
@ -187,33 +198,123 @@ func TestPortDocVersion(t *testing.T) {
// } // }
e = db.GetMysqlClient().Query2("select id,title,type from doc_copy1 where doc_copy1.father is NULL ", &docs)
e = db.GetMysqlClient().Query2("select id,title,type from doc_copy1 where doc_copy1.father is NULL ",&docs) if nil != e {
if(nil != e){
log.Print(e.Error()) log.Print(e.Error())
} }
for k,v := range docs{ for k, v := range docs {
log.Print(k,v) log.Print(k, v)
e = db.GetMysqlClient().Query2(fmt.Sprintf("select * from doc_type where doc_type.id = %d ",v.Type),&doc_types) e = db.GetMysqlClient().Query2(fmt.Sprintf("select * from doc_type where doc_type.id = %d ", v.Type), &doc_types)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
} }
log.Print(doc_types) log.Print(doc_types)
if len(doc_types) > 0{ if len(doc_types) > 0 {
docsfortype := []model.Doc{} docsfortype := []model.Doc{}
e = db.GetMysqlClient().Query2(fmt.Sprintf("select * from doc_copy1 where doc_copy1.title = '%s' and doc_copy1.level = 1", e = db.GetMysqlClient().Query2(fmt.Sprintf("select * from doc_copy1 where doc_copy1.title = '%s' and doc_copy1.level = 1",
doc_types[0].TypeName),&docsfortype) doc_types[0].TypeName), &docsfortype)
if nil != e{ if nil != e {
log.Print(e.Error()) log.Print(e.Error())
} }
log.Print(docsfortype) log.Print(docsfortype)
if len(docsfortype) > 0{ if len(docsfortype) > 0 {
str := fmt.Sprintf("update doc_copy1 set father = %d ,level = %d where doc_copy1.id = %d", str := fmt.Sprintf("update doc_copy1 set father = %d ,level = %d where doc_copy1.id = %d",
docsfortype[0].ID,docsfortype[0].Level + 1,(v.ID)) docsfortype[0].ID, docsfortype[0].Level+1, (v.ID))
log.Print(str) log.Print(str)
_,e = db.GetMysqlClient().Query(str) _, e = db.GetMysqlClient().Query(str)
if nil != e{ if nil != e {
log.Printf(e.Error())
}
}
}
}
}
func TestPortDocTree(t *testing.T) {
InitConfig()
InitLogs()
InitRedisConfig()
InitMysql()
docs := []model.Doc{}
doc_groups := []model.DocGroup{}
doc_types := []model.DocType{}
e := db.GetMysqlClient().Query2("select * from doc_group", &doc_groups)
if nil != e {
log.Print(e.Error())
}
// for k,v := range doc_groups{
// log.Print(k,v)
// e := db.GetMysqlClient().Query2("select * from doc_group",&doc_groups)
// if(nil != e){
// log.Print(e.Error())
// }
// str := fmt.Sprintf("insert into doc_copy1 (title,type,content,author,create_time,version,is_public, deleted,origin_url,es_id,father,level) values ('%s',0,'','admin','%s', 1,1,0,'','',0,0)",
// v.Name,time.Now().Format("2006-01-02 15:04:05"))
// log.Print(str)
// _,e = db.GetMysqlClient().Query(str)
// if nil != e{
// log.Print(e.Error())
// }
// }
// e = db.GetMysqlClient().Query2("select * from doc_type",&doc_types)
// if(nil != e){
// log.Print(e.Error())
// }
// for k,v := range doc_types{
// log.Print(k,v)
// doc_group := []model.DocGroup{}
// e = db.GetMysqlClient().Query2(fmt.Sprintf("select * from doc_group where doc_group.int = '%d'",v.Group),&doc_group)
// if nil != e{
// log.Print(e.Error())
// }
// log.Print(doc_group[0])
// doc := []model.Doc{}
// e = db.GetMysqlClient().Query2(fmt.Sprintf("select * from doc_copy1 where doc_copy1.title = '%s' and doc_copy1.father=0",doc_group[0].Name),&doc)
// if nil != e{
// log.Print(e.Error())
// }
// log.Print(doc)
// str := fmt.Sprintf("insert into doc_copy1 (title,type,content,author,create_time,version,is_public, deleted,origin_url,es_id,father,level) values ('%s',0,'','admin','%s', 1,1,0,'','',%d,1)",
// v.TypeName,time.Now().Format("2006-01-02 15:04:05"),doc[0].ID)
// log.Print(str)
// _,e = db.GetMysqlClient().Query(str)
// if nil != e{
// log.Print(e.Error())
// }
// }
e = db.GetMysqlClient().Query2("select id,title,type from doc_copy1 where doc_copy1.father is NULL ", &docs)
if nil != e {
log.Print(e.Error())
}
for k, v := range docs {
log.Print(k, v)
e = db.GetMysqlClient().Query2(fmt.Sprintf("select * from doc_type where doc_type.id = %d ", v.Type), &doc_types)
if nil != e {
log.Print(e.Error())
}
log.Print(doc_types)
if len(doc_types) > 0 {
docsfortype := []model.Doc{}
e = db.GetMysqlClient().Query2(fmt.Sprintf("select * from doc_copy1 where doc_copy1.title = '%s' and doc_copy1.level = 1",
doc_types[0].TypeName), &docsfortype)
if nil != e {
log.Print(e.Error())
}
log.Print(docsfortype)
if len(docsfortype) > 0 {
str := fmt.Sprintf("update doc_copy1 set father = %d ,level = %d where doc_copy1.id = %d",
docsfortype[0].ID, docsfortype[0].Level+1, (v.ID))
log.Print(str)
_, e = db.GetMysqlClient().Query(str)
if nil != e {
log.Printf(e.Error()) log.Printf(e.Error())
} }
} }