no message
parent
1c687bbc21
commit
12899f01ea
|
@ -75,7 +75,7 @@ func GetArticles(c *gin.Context) {
|
|||
} else {
|
||||
is_public = 0
|
||||
}
|
||||
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title from doc where is_public = %d "+
|
||||
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc where is_public = %d "+
|
||||
"order by id desc limit %d offset %d", is_public, limit, offset)
|
||||
} else {
|
||||
is_public := 0
|
||||
|
@ -86,6 +86,7 @@ func GetArticles(c *gin.Context) {
|
|||
}
|
||||
sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc where doc.type = %d and is_public = %d "+
|
||||
" order by id desc limit %d offset %d", req.Type, is_public, limit, offset)
|
||||
|
||||
}
|
||||
}
|
||||
log.Print(sql)
|
||||
|
|
|
@ -24,8 +24,16 @@ type Doc struct {
|
|||
IsPublic int32 `json:"is_public" gorm:"column:is_public" sql:"is_public"`
|
||||
Deleted int32 `json:"deleted" gorm:"column:deleted" sql:"deleted"`
|
||||
OriginUrl string `json:"origin_url" gorm:"column:origin_url" sql:"origin_url"`
|
||||
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"`
|
||||
Father int32 `json:"father" gorm:"column:father" sql:"father"`
|
||||
Level int32 `json:"level" gorm:"column:level" sql:"level"`
|
||||
}
|
||||
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{
|
||||
ID int32 `json:"id" gorm:"column:id" sql:"id"`
|
||||
Title string `json:"title" gorm:"column:title" sql:"title"`
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"log"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/olivere/elastic"
|
||||
)
|
||||
|
@ -137,26 +136,85 @@ func TestPortDocVersion(t *testing.T) {
|
|||
InitRedisConfig()
|
||||
InitMysql()
|
||||
|
||||
doc_groups := []model.DocGroup{}
|
||||
e := db.GetMysqlClient().Query2("select * from doc_group",&doc_groups)
|
||||
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())
|
||||
// }
|
||||
// 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_copy2 (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_copy2 where doc_copy2.title = '%s' and doc_copy2.father=0",doc_group[0].Name),&doc)
|
||||
// if nil != e{
|
||||
// log.Print(e.Error())
|
||||
// }
|
||||
// log.Print(doc)
|
||||
// // str := fmt.Sprintf("insert into doc_copy2 (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_copy2 where doc_copy2.father is NULL ",&docs)
|
||||
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)
|
||||
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_copy2 where doc_copy2.title = '%s' and doc_copy2.father is not NULL ",
|
||||
doc_types[0].TypeName),&docsfortype)
|
||||
if nil != e{
|
||||
log.Print(e.Error())
|
||||
}
|
||||
log.Print(docsfortype)
|
||||
if len(docsfortype) > 0{
|
||||
str := fmt.Sprintf("update doc_copy2 set father = %d ,level = %d where doc_copy2.id = %d",
|
||||
docsfortype[0].ID,docsfortype[0].Level,(v.ID+1))
|
||||
log.Print(str)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue