no message
This commit is contained in:
parent
3afd2af811
commit
702f023cb5
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -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"
|
||||
}
|
@ -78,6 +78,7 @@ var gConf ConfAPI
|
||||
func ApiConfig() ConfAPI{
|
||||
return gConf
|
||||
}
|
||||
|
||||
func Init(path string) error {
|
||||
file, e := os.Open(path)
|
||||
if nil != e {
|
||||
|
@ -52,6 +52,8 @@ func InitRedis() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func RedisOne() *redis.Client {
|
||||
return gRedis1
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"background/model"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -14,7 +15,7 @@ import (
|
||||
"qiniupkg.com/x/log.v7"
|
||||
)
|
||||
|
||||
type DocTree struct{
|
||||
type DocTree struct {
|
||||
ID int64 `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Level int `json:"level"`
|
||||
@ -24,13 +25,13 @@ type DocTree struct{
|
||||
var gDocMapCache map[int]*DocTree = nil
|
||||
var gLock sync.Mutex
|
||||
|
||||
func init(){
|
||||
if nil == gDocMapCache{
|
||||
func init() {
|
||||
if nil == gDocMapCache {
|
||||
gDocMapCache = make(map[int]*DocTree)
|
||||
}
|
||||
}
|
||||
|
||||
func InitDocCache(){
|
||||
func InitDocCache() {
|
||||
gLock.Lock()
|
||||
for k := range gDocMapCache {
|
||||
delete(gDocMapCache, k)
|
||||
@ -42,24 +43,24 @@ func InitDocCache(){
|
||||
logs.Error(e.Error())
|
||||
return
|
||||
}
|
||||
for _,v := range articles{
|
||||
tmp := new (DocTree)
|
||||
for _, v := range articles {
|
||||
tmp := new(DocTree)
|
||||
tmp.ID = v.ID
|
||||
tmp.Level = int(v.Level)
|
||||
tmp.Label = v.Title
|
||||
tmp.Children = make([]*DocTree,0)
|
||||
tmp.Children = make([]*DocTree, 0)
|
||||
gDocMapCache[int(v.ID)] = tmp
|
||||
}
|
||||
for _,v := range articles{
|
||||
tmp := new (DocTree)
|
||||
for _, v := range articles {
|
||||
tmp := new(DocTree)
|
||||
tmp.ID = v.ID
|
||||
tmp.Label = v.Title
|
||||
tmp.Level = int(v.Level)
|
||||
tmp.Children = make([]*DocTree,0)
|
||||
tmp.Children = make([]*DocTree, 0)
|
||||
gDocMapCache[int(v.ID)] = tmp
|
||||
}
|
||||
for _,v := range articles{
|
||||
if v.Father != 0{
|
||||
for _, v := range articles {
|
||||
if v.Father != 0 {
|
||||
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()
|
||||
ret := []*DocTree{}
|
||||
for _, v := range articles {
|
||||
if v.Level == 0{
|
||||
if v.Level == 0 {
|
||||
ret = append(ret, gDocMapCache[int(v.ID)])
|
||||
}
|
||||
}
|
||||
@ -245,8 +246,8 @@ func AddArticleHistory(c *gin.Context) {
|
||||
Author: req.Author,
|
||||
Father: int32(req.Father),
|
||||
Level: int32(req.Level),
|
||||
},)
|
||||
if(nil != e){
|
||||
})
|
||||
if nil != e {
|
||||
logs.Error(er.Error())
|
||||
return
|
||||
}
|
||||
@ -298,7 +299,7 @@ func GetArticle(c *gin.Context) {
|
||||
query := fmt.Sprintf("select * from doc_copy1 where doc_copy1.id = '%d'", id)
|
||||
docs := []model.Doc{}
|
||||
e := db.GetMysqlClient().Query2(query, &docs)
|
||||
fmt.Print(query,docs)
|
||||
fmt.Print(query, docs)
|
||||
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
@ -327,8 +328,6 @@ func UpdateArtilce(c *gin.Context) {
|
||||
c.JSON(200, rsp)
|
||||
}()
|
||||
|
||||
|
||||
|
||||
er := c.BindJSON(&req)
|
||||
if nil != er {
|
||||
logs.Error(er.Error())
|
||||
@ -369,8 +368,6 @@ func UpdateArtilce(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
func UpdateArtilceTree(c *gin.Context) {
|
||||
rsp := RespBase{Msg: "FAIL", Status: 210}
|
||||
type ReqUpdateArticle struct {
|
||||
@ -408,6 +405,8 @@ func UpdateArtilceTree(c *gin.Context) {
|
||||
rsp.Msg = "不存在该"
|
||||
return
|
||||
}
|
||||
log.Print(req.Content)
|
||||
req.Content = strings.ReplaceAll(req.Content, "\\", "\\\\")
|
||||
e = model.UpdateDocTree(
|
||||
model.DocTree{
|
||||
Type: int32(req.Type),
|
||||
@ -425,13 +424,14 @@ func UpdateArtilceTree(c *gin.Context) {
|
||||
logs.Error(e.Error())
|
||||
return
|
||||
}
|
||||
config.RedisOne().Del("artilcetree")
|
||||
rsp.Msg = "OK"
|
||||
rsp.Status = 0
|
||||
config.RedisOne().Del("artilcetree")
|
||||
|
||||
}
|
||||
|
||||
func SearchArticleESHightLight(c *gin.Context) {
|
||||
type RetHighlight struct{
|
||||
type RetHighlight struct {
|
||||
ID int64 `json:"id" gorm:"column:id" sql:"id"`
|
||||
Title string `json:"title" gorm:"column:title" sql:"title"`
|
||||
Type int32 `json:"type" gorm:"column:type" sql:"type"`
|
||||
@ -441,12 +441,12 @@ func SearchArticleESHightLight(c *gin.Context) {
|
||||
defer func() {
|
||||
c.JSON(200, rsp)
|
||||
}()
|
||||
type Req struct{
|
||||
type Req struct {
|
||||
Term string `json:"term"`
|
||||
}
|
||||
var req Req
|
||||
e := c.BindJSON(&req)
|
||||
if nil != e{
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
@ -457,7 +457,7 @@ func SearchArticleESHightLight(c *gin.Context) {
|
||||
highlight = highlight.PreTags("<span>").PostTags("</span>")
|
||||
x := []RetHighlight{}
|
||||
_, e = db.GetElastic().
|
||||
QueryHighlight("doc", query, &x,highlight, 10, 0)
|
||||
QueryHighlight("doc", query, &x, highlight, 10, 0)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
@ -473,12 +473,12 @@ func SearchArticleES(c *gin.Context) {
|
||||
defer func() {
|
||||
c.JSON(200, rsp)
|
||||
}()
|
||||
type Req struct{
|
||||
type Req struct {
|
||||
Term string `json:"term"`
|
||||
}
|
||||
var req Req
|
||||
e := c.BindJSON(&req)
|
||||
if nil != e{
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
@ -535,7 +535,6 @@ func AddArticle(c *gin.Context) {
|
||||
rsp.Status = 0
|
||||
}
|
||||
|
||||
|
||||
func AddArticleTree(c *gin.Context) {
|
||||
rsp := RespBase{Msg: "FAIL", Status: 210}
|
||||
type ReqAddArticle struct {
|
||||
@ -577,9 +576,11 @@ func AddArticleTree(c *gin.Context) {
|
||||
logs.Error(e.Error())
|
||||
return
|
||||
}
|
||||
config.RedisOne().Del("artilcetree")
|
||||
rsp.Msg = "OK"
|
||||
rsp.Status = 0
|
||||
rsp.Data = model.GetIdFromTitle(req.Title)
|
||||
config.RedisOne().Del("artilcetree")
|
||||
|
||||
}
|
||||
|
||||
func ArticlesType(c *gin.Context) {
|
||||
@ -672,7 +673,6 @@ func DeleteArticle(c *gin.Context) {
|
||||
rsp.Msg = "OK"
|
||||
}
|
||||
|
||||
|
||||
func DeleteArticleTree(c *gin.Context) {
|
||||
rsp := RespBase{Msg: "FAIL", Status: 210}
|
||||
defer func() {
|
||||
@ -713,7 +713,7 @@ func ArticlesTypes(c *gin.Context) {
|
||||
}
|
||||
|
||||
func SearchArticles(c *gin.Context) {
|
||||
type ReqSearch struct{
|
||||
type ReqSearch struct {
|
||||
Term string `json:"term"`
|
||||
}
|
||||
resp := RespBase{"unkown error", -231, nil}
|
||||
@ -778,7 +778,6 @@ func CreateBook(c *gin.Context) {
|
||||
resp.Status = 0
|
||||
}
|
||||
|
||||
|
||||
func BookCount(c *gin.Context) {
|
||||
resp := RespBase{"unkown error", -231, nil}
|
||||
defer func() {
|
||||
@ -791,9 +790,8 @@ func BookCount(c *gin.Context) {
|
||||
resp.Status = 0
|
||||
}
|
||||
|
||||
|
||||
func Delbook(c *gin.Context) {
|
||||
type Req struct{
|
||||
type Req struct {
|
||||
ID int32 `json:"id"`
|
||||
}
|
||||
var req Req
|
||||
@ -810,7 +808,7 @@ func Delbook(c *gin.Context) {
|
||||
}
|
||||
count := 0
|
||||
e = db.GetOrm().Model(&model.Book{}).Delete(model.Book{ID: int64(req.ID)}).Error
|
||||
if nil != e{
|
||||
if nil != e {
|
||||
log.Printf(e.Error())
|
||||
return
|
||||
}
|
||||
@ -897,15 +895,15 @@ func GetPageBook(c *gin.Context) {
|
||||
}
|
||||
books := []model.Book{}
|
||||
|
||||
if req.BookName != ""{
|
||||
if req.BookName != "" {
|
||||
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
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
e = db.GetOrm().Model(&model.Book{}).
|
||||
Limit(iLmit).Offset(iOffset).Find(&books).Error
|
||||
if nil != e {
|
||||
@ -1046,7 +1044,6 @@ func GetMemos(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
func GetMemoCnt(c *gin.Context) {
|
||||
rsp := RespBase{"ERR", -1, nil}
|
||||
defer func() {
|
||||
@ -1060,7 +1057,6 @@ func GetMemoCnt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
func GetMemo(c *gin.Context) {
|
||||
rsp := RespBase{"ERR", -1, nil}
|
||||
defer func() {
|
||||
@ -1076,7 +1072,6 @@ func GetMemo(c *gin.Context) {
|
||||
rsp.Data = dat
|
||||
}
|
||||
|
||||
|
||||
func DeleteMemos(c *gin.Context) {
|
||||
resp := RespBase{"unkown error", -231, nil}
|
||||
defer func() {
|
||||
@ -1101,7 +1096,6 @@ func DeleteMemos(c *gin.Context) {
|
||||
resp.Status = 0
|
||||
}
|
||||
|
||||
|
||||
func CreateDocTemplate(c *gin.Context) {
|
||||
resp := RespBase{}
|
||||
defer func() {
|
||||
@ -1115,7 +1109,7 @@ func CreateDocTemplate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
e = model.CreateDocTemplate(req)
|
||||
if nil != e{
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
@ -1124,7 +1118,6 @@ func CreateDocTemplate(c *gin.Context) {
|
||||
resp.Status = 0
|
||||
}
|
||||
|
||||
|
||||
func UpdateDocTemplate(c *gin.Context) {
|
||||
resp := RespBase{}
|
||||
defer func() {
|
||||
@ -1147,7 +1140,7 @@ func UpdateDocTemplate(c *gin.Context) {
|
||||
}
|
||||
|
||||
func GetDocTemplate(c *gin.Context) {
|
||||
type ReqGet struct{
|
||||
type ReqGet struct {
|
||||
Title string `json:"title"`
|
||||
}
|
||||
req := ReqGet{}
|
||||
@ -1156,12 +1149,12 @@ func GetDocTemplate(c *gin.Context) {
|
||||
c.JSON(200, resp)
|
||||
}()
|
||||
e := c.BindJSON(&req)
|
||||
if nil != e{
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
ret,e := model.GetDocTemplate(req.Title,5,0)
|
||||
if nil != e{
|
||||
ret, e := model.GetDocTemplate(req.Title, 5, 0)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
@ -1176,13 +1169,13 @@ func DeleteDocTemplate(c *gin.Context) {
|
||||
c.JSON(200, resp)
|
||||
}()
|
||||
sid := c.Param("id")
|
||||
id,e := strconv.Atoi(sid)
|
||||
if nil != e{
|
||||
id, e := strconv.Atoi(sid)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
e = model.DeleteDocTemplate(int32(id))
|
||||
if nil != e{
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
@ -1197,19 +1190,19 @@ func GetDocTemplateId(c *gin.Context) {
|
||||
c.JSON(200, resp)
|
||||
}()
|
||||
sid := c.Param("id")
|
||||
id,e := strconv.Atoi(sid)
|
||||
if nil != e{
|
||||
id, e := strconv.Atoi(sid)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
ret,e := model.ReadDocTemplate(int32(id))
|
||||
if nil != e{
|
||||
ret, e := model.ReadDocTemplate(int32(id))
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
if len(ret) > 0{
|
||||
if len(ret) > 0 {
|
||||
resp.Data = ret[0]
|
||||
}else{
|
||||
} else {
|
||||
resp.Data = nil
|
||||
}
|
||||
resp.Msg = "OK"
|
||||
|
@ -60,8 +60,7 @@ func (p *ElkEngine) Delete(query elastic.Query, index string) error {
|
||||
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) {
|
||||
|
||||
if reflect.ValueOf(v).Kind() != reflect.Ptr {
|
||||
@ -186,7 +185,7 @@ func (p *ElkEngine) Query(index string, query elastic.Query, v interface{},
|
||||
} else {
|
||||
res, err := p.cli.Search(index).Query(query).Size(limit).From(limit * offset).Do(context.Background())
|
||||
if err != nil {
|
||||
print(err)
|
||||
log.Print(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
id := []string{}
|
||||
|
6
main.go
6
main.go
@ -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-Allow-Credentials", "true")
|
||||
|
||||
log.Print("remote addr is ",c.Request.RemoteAddr)
|
||||
log.Print("remote addr is ", c.Request.RemoteAddr)
|
||||
|
||||
if c.Request.Method == "OPTIONS" {
|
||||
log.Println("OPTIONS")
|
||||
@ -128,6 +128,7 @@ func main() {
|
||||
if nil != e {
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
|
||||
// programatically set swagger info
|
||||
@ -178,7 +179,7 @@ func main() {
|
||||
api.GET("/articleCount", controller.GetArticleCount) //获取所有文章个数
|
||||
api.DELETE("/article/:id", controller.DeleteArticle) ////删除文章
|
||||
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_origin", fileController.OnUploadOrigin) // 上传图片
|
||||
@ -235,6 +236,7 @@ func main() {
|
||||
api.DELETE("/doc_template/:id", controller.DeleteDocTemplate) // 删除文章模板
|
||||
api.GET("/doc_template/:id", controller.GetDocTemplateId) //获得单个文章模板信息
|
||||
}
|
||||
|
||||
openapi := r.Group("openapi")
|
||||
{
|
||||
openapi.POST("/diff") // 比较两个文档差异
|
||||
|
@ -30,7 +30,6 @@ type Doc struct {
|
||||
Level int32 `json:"level" gorm:"column:level" sql:"level"`
|
||||
}
|
||||
|
||||
|
||||
type DocTree struct {
|
||||
ID int64 `json:"id" gorm:"column:id" sql:"id"`
|
||||
Title string `json:"title" gorm:"column:title" sql:"title"`
|
||||
@ -49,17 +48,18 @@ type DocTree struct {
|
||||
Father int32 `json:"father" gorm:"column:father" sql:"father"`
|
||||
Level int32 `json:"level" gorm:"column:level" sql:"level"`
|
||||
}
|
||||
|
||||
// 设置User的表名为`profiles`
|
||||
func (DocTree) TableName() string {
|
||||
return "doc_copy1"
|
||||
}
|
||||
|
||||
type DocType struct{
|
||||
type DocType struct {
|
||||
Id int32 `json:"id" gorm:"column:id" sql:"id"`
|
||||
TypeName string `json:"type_name" gorm:"column:type_name" sql:"type_name"`
|
||||
Group int32 `json:"group" gorm:"column:group" sql:"group"`
|
||||
}
|
||||
type DocHistory struct{
|
||||
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"`
|
||||
@ -125,8 +125,6 @@ func CreateDoc(doc Doc) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
CreateDoc 新建文档
|
||||
*/
|
||||
@ -145,7 +143,7 @@ func CreateDocTree(doc DocTree) error {
|
||||
DUAL
|
||||
WHERE
|
||||
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)
|
||||
if nil != e {
|
||||
log.Print(sql)
|
||||
@ -155,13 +153,27 @@ func CreateDocTree(doc DocTree) error {
|
||||
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 更新文档
|
||||
*/
|
||||
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'; `,
|
||||
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)
|
||||
if nil != e {
|
||||
logs.Error(e.Error())
|
||||
@ -177,11 +189,10 @@ func UpdateDoc(doc Doc) error {
|
||||
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');`,
|
||||
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)
|
||||
if nil != er {
|
||||
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.version = '%d' where doc_copy1.id = '%d'; `,
|
||||
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)
|
||||
if nil != e {
|
||||
logs.Error(e.Error())
|
||||
@ -220,8 +231,6 @@ func DeleteDoc(id int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
DeleteDoc 删除文档
|
||||
*/
|
||||
@ -276,9 +285,9 @@ func DeleteArticleType(id int32) error {
|
||||
return nil
|
||||
|
||||
}
|
||||
func GetAllDocs() ([]Doc, error) {
|
||||
ret := []Doc{}
|
||||
sql := fmt.Sprintf("select * from doc")
|
||||
func GetAllDocs() ([]DocTree, error) {
|
||||
ret := []DocTree{}
|
||||
sql := fmt.Sprintf("select * from doc_copy1")
|
||||
e := db.GetMysqlClient().Query2(sql, &ret)
|
||||
if nil != e {
|
||||
logs.Error(e.Error())
|
||||
@ -287,7 +296,6 @@ func GetAllDocs() ([]Doc, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
func GetAllGroup() ([]DocGroup, error) {
|
||||
ret := []DocGroup{}
|
||||
sql := fmt.Sprintf("select * from doc_group")
|
||||
|
@ -35,6 +35,7 @@ func MysqlToElasticSearchMapping(types string, Key string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
/*
|
||||
"settings":{
|
||||
"number_of_shards":1,
|
||||
@ -76,7 +77,7 @@ func QueryDocument(query elastic.Query, limit int, offset int) ([]Hardware, erro
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
func InsertDocToElaticSearch(doc Doc) error {
|
||||
func InsertDocToElaticSearch(doc DocTree) error {
|
||||
matchPhraseQuery := elastic.NewMatchQuery("title", doc.Title)
|
||||
existedHardware, e := QueryHardwares(matchPhraseQuery, 10, 0)
|
||||
log.Print(e, existedHardware)
|
||||
@ -97,7 +98,7 @@ func InsertDocToElaticSearch(doc Doc) error {
|
||||
|
||||
func CreateIndexFromMysqlTable(tblname string) error {
|
||||
columns := []Field{}
|
||||
e := db.GetMysqlClient().Query2("describe " + tblname, &columns)
|
||||
e := db.GetMysqlClient().Query2("describe "+tblname, &columns)
|
||||
if nil != e {
|
||||
logger.Debug(e.Error())
|
||||
return e
|
||||
@ -155,7 +156,8 @@ func PortDocumentToElasticsearch(tblname string) error {
|
||||
"analysis": map[string]interface{}{
|
||||
"analyzer": 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 {
|
||||
log.Print(e.Error())
|
||||
}
|
||||
log.Print(string(dat))
|
||||
e = db.GetElastic().CreateIndex(tblname, string(dat))
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
|
@ -15,17 +15,16 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
func TestWaitGroup(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
|
||||
go func () {
|
||||
time.Sleep(3*time.Second)
|
||||
go func() {
|
||||
time.Sleep(3 * time.Second)
|
||||
t.Logf("job 1 done")
|
||||
wg.Done()
|
||||
}()
|
||||
go func () {
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
t.Logf("job 2 done")
|
||||
wg.Done()
|
||||
@ -34,29 +33,28 @@ func TestWaitGroup(t *testing.T) {
|
||||
|
||||
t.Log("all finish")
|
||||
|
||||
|
||||
}
|
||||
|
||||
func TestChanel(t *testing.T){
|
||||
func TestChanel(t *testing.T) {
|
||||
exit := make(chan bool)
|
||||
go func () {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-exit:
|
||||
t.Logf("exit 1")
|
||||
return
|
||||
case <- time.After(1 * time.Second) :
|
||||
case <-time.After(1 * time.Second):
|
||||
t.Logf("time out ")
|
||||
}
|
||||
}
|
||||
}()
|
||||
go func () {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-exit:
|
||||
t.Logf("exit 2")
|
||||
return
|
||||
case <- time.After(1 * time.Second) :
|
||||
case <-time.After(1 * time.Second):
|
||||
t.Logf("time out ")
|
||||
}
|
||||
}
|
||||
@ -65,25 +63,24 @@ func TestChanel(t *testing.T){
|
||||
exit <- true
|
||||
t.Logf("finish")
|
||||
|
||||
|
||||
}
|
||||
|
||||
type TestInherit struct{
|
||||
type TestInherit struct {
|
||||
context.Context
|
||||
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 {
|
||||
select {
|
||||
case <-aa.Done():
|
||||
t.Logf("exit")
|
||||
return
|
||||
case <- time.After(5 * time.Second) :
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Logf("time out ")
|
||||
}
|
||||
}
|
||||
@ -92,40 +89,40 @@ func TestTimeoutContext(t * testing.T){
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
|
||||
func TestContext(t *testing.T){
|
||||
ctx,cancel := context.WithCancel(context.Background())
|
||||
func TestContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
go func () {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Logf("exit")
|
||||
return
|
||||
case <- time.After(1 * time.Second) :
|
||||
case <-time.After(1 * time.Second):
|
||||
t.Logf("time out ")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
go func () {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Logf("exit")
|
||||
return
|
||||
case <- time.After(1 * time.Second) :
|
||||
case <-time.After(1 * time.Second):
|
||||
t.Logf("time out ")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
go func () {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Logf("exit")
|
||||
return
|
||||
case <- time.After(1 * time.Second) :
|
||||
case <-time.After(1 * time.Second):
|
||||
t.Logf("time out ")
|
||||
}
|
||||
}
|
||||
@ -133,6 +130,5 @@ func TestContext(t *testing.T){
|
||||
time.Sleep(5 * time.Second)
|
||||
cancel()
|
||||
|
||||
|
||||
t.Logf("finish")
|
||||
}
|
@ -59,7 +59,19 @@ func TestPortDocToElastic(t *testing.T) {
|
||||
InitRedisConfig()
|
||||
InitMysql()
|
||||
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 {
|
||||
log.Print(e.Error())
|
||||
}
|
||||
@ -129,7 +141,6 @@ func TestChangeStructFieldThroughStruct(t *testing.T) {
|
||||
fmt.Println(cap(arr1))
|
||||
}
|
||||
|
||||
|
||||
func TestPortDocVersion(t *testing.T) {
|
||||
InitConfig()
|
||||
InitLogs()
|
||||
@ -139,9 +150,9 @@ func TestPortDocVersion(t *testing.T) {
|
||||
docs := []model.Doc{}
|
||||
doc_groups := []model.DocGroup{}
|
||||
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())
|
||||
}
|
||||
// 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)
|
||||
if(nil != e){
|
||||
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)
|
||||
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{
|
||||
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{
|
||||
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{
|
||||
doc_types[0].TypeName), &docsfortype)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
}
|
||||
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",
|
||||
docsfortype[0].ID,docsfortype[0].Level + 1,(v.ID))
|
||||
docsfortype[0].ID, docsfortype[0].Level+1, (v.ID))
|
||||
log.Print(str)
|
||||
_,e = db.GetMysqlClient().Query(str)
|
||||
if nil != e{
|
||||
_, e = db.GetMysqlClient().Query(str)
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user