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{
return gConf
}
func Init(path string) error {
file, e := os.Open(path)
if nil != e {

View File

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

View File

@ -7,6 +7,7 @@ import (
"background/model"
"fmt"
"strconv"
"strings"
"sync"
"github.com/gin-gonic/gin"
@ -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
}
@ -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,9 +424,10 @@ 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) {
@ -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() {
@ -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,7 +790,6 @@ func BookCount(c *gin.Context) {
resp.Status = 0
}
func Delbook(c *gin.Context) {
type Req struct {
ID int32 `json:"id"`
@ -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() {
@ -1124,7 +1118,6 @@ func CreateDocTemplate(c *gin.Context) {
resp.Status = 0
}
func UpdateDocTemplate(c *gin.Context) {
resp := RespBase{}
defer func() {

View File

@ -60,7 +60,6 @@ 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,
limit int, offset int) ([]string, error) {
@ -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{}

View File

@ -128,6 +128,7 @@ func main() {
if nil != e {
}
}()
go func() {
// programatically set swagger info
@ -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") // 比较两个文档差异

View File

@ -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,6 +48,7 @@ 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"
@ -125,8 +125,6 @@ func CreateDoc(doc Doc) error {
return nil
}
/*
CreateDoc
*/
@ -155,6 +153,20 @@ 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
*/
@ -177,7 +189,6 @@ func UpdateDoc(doc Doc) error {
return nil
}
// 添加文件版本。
func InsertDocHistory(doc DocTree) error {
sql := fmt.Sprintf(`insert into doc_history(title,doc_id,content,edit_time) values('%s',%d,'%s','%s');`,
@ -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")

View File

@ -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)
@ -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())

View File

@ -15,7 +15,6 @@ import (
"time"
)
func TestWaitGroup(t *testing.T) {
var wg sync.WaitGroup
wg.Add(2)
@ -34,7 +33,6 @@ func TestWaitGroup(t *testing.T) {
t.Log("all finish")
}
func TestChanel(t *testing.T) {
@ -65,14 +63,13 @@ func TestChanel(t *testing.T){
exit <- true
t.Logf("finish")
}
type TestInherit struct {
context.Context
x int32
}
func TestTimeoutContext(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), time.Second*1)
aa := TestInherit{ctx, 1}
@ -133,6 +130,5 @@ func TestContext(t *testing.T){
time.Sleep(5 * time.Second)
cancel()
t.Logf("finish")
}

View File

@ -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()
@ -187,9 +198,99 @@ 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){
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())
}
}
}
}
}
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 {