95 lines
2.3 KiB
Go
95 lines
2.3 KiB
Go
package l_ai_category
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"gitea.cdlsxd.cn/self-tools/l_ai_category/utils_gorm"
|
||
"testing"
|
||
)
|
||
|
||
const (
|
||
dns = "root:lansexiongdi6,@tcp(47.97.27.195:3306)/report?parseTime=True&loc=Local"
|
||
driver = "mysql"
|
||
table = "goods_category"
|
||
modelType = "deepseek-v3-250324"
|
||
)
|
||
|
||
func TestCategory(t *testing.T) {
|
||
path := getPath()
|
||
res, err := GetCategory(context.Background(), "倍轻松头部按摩器\niDream 3(尊享版", "914ccf1d-c002-4fad-a431-f291f5e0d2ad", modelType, path)
|
||
t.Log(res, err)
|
||
}
|
||
|
||
func TestRem(t *testing.T) {
|
||
|
||
res, err := Test(context.Background(), "914ccf1d-c002-4fad-a431-f291f5e0d2ad", modelType)
|
||
t.Log(res, err)
|
||
}
|
||
|
||
//func TestFlush(t *testing.T) {
|
||
// catString := string(CategoryToJsonByte())
|
||
// res, err := FlushCate(context.Background(), "914ccf1d-c002-4fad-a431-f291f5e0d2ad", modelType, catString)
|
||
// t.Log(res, err)
|
||
//}
|
||
//
|
||
//func TestGetCateGoryJson(t *testing.T) {
|
||
// cateJsonByte := CategoryToJsonByte()
|
||
//
|
||
// t.Log(string(cateJsonByte))
|
||
//}
|
||
|
||
//func CategoryToJsonByte() (cateJsonByte []byte) {
|
||
//
|
||
// cateLevelPath := getPath()
|
||
// cate := cateIteration(cateLevelPath[0], cateIteration(cateLevelPath[1], cateLevelPath[2]))[0]
|
||
// cateJsonByte, _ = json.Marshal(cate)
|
||
// return
|
||
//}
|
||
|
||
func getPath() []map[int][]*CategoryDic {
|
||
cates := cateAll()
|
||
var (
|
||
cateLevelPath = make([]map[int][]*CategoryDic, 3)
|
||
)
|
||
for _, v := range cates {
|
||
if cateLevelPath[v.Level-1] == nil {
|
||
cateLevelPath[v.Level-1] = make(map[int][]*CategoryDic)
|
||
}
|
||
if _, ex := cateLevelPath[v.Level-1][v.Pid]; !ex {
|
||
cateLevelPath[v.Level-1][v.Pid] = make([]*CategoryDic, 0)
|
||
}
|
||
cateLevelPath[v.Level-1][v.Pid] = append(cateLevelPath[v.Level-1][v.Pid], &CategoryDic{Category: v})
|
||
}
|
||
return cateLevelPath
|
||
}
|
||
|
||
//func cateIteration(parent map[int][]*CategoryDic, child map[int][]*CategoryDic) map[int][]*CategoryDic {
|
||
// for _, v := range parent {
|
||
// for _, vv := range v {
|
||
// vv.Children = child[vv.Id]
|
||
// }
|
||
// }
|
||
// return parent
|
||
//}
|
||
|
||
func cateAll() (data []Category) {
|
||
var (
|
||
row Category
|
||
)
|
||
db, err, clean := utils_gorm.DB(driver, dns)
|
||
defer clean()
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
rows, _ := db.Raw(fmt.Sprintf("SELECT id,name,level,pid FROM `%s` where `type`=2", table)).Rows()
|
||
defer rows.Close()
|
||
for rows.Next() {
|
||
err = db.ScanRows(rows, &row)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
data = append(data, row)
|
||
}
|
||
return
|
||
}
|