111 lines
3.1 KiB
Go
111 lines
3.1 KiB
Go
package advice
|
|
|
|
import (
|
|
"ai_scheduler/internal/biz"
|
|
"ai_scheduler/internal/biz/llm_service/third_party"
|
|
"ai_scheduler/internal/config"
|
|
"ai_scheduler/internal/data/impl"
|
|
"ai_scheduler/internal/entitys"
|
|
"ai_scheduler/utils"
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
func Test_WordAna(t *testing.T) {
|
|
Run(nil)
|
|
ana, err := file.WordAnat("https://attachment-public.oss-cn-hangzhou.aliyuncs.com/ai-scheduler/data-analytics/word/content3.docx")
|
|
t.Log(ana, err)
|
|
}
|
|
|
|
func Test_AdvicerInit(t *testing.T) {
|
|
reqBody := `{"advicer_id": 124, "name": "张三111", "birth": "1990-01-01", "gender": 1, "working_years": 10}`
|
|
Run([]byte(reqBody))
|
|
|
|
err := advicer.AdvicerUpdate(fiberCtx)
|
|
t.Log(err)
|
|
}
|
|
|
|
func Test_Json(t *testing.T) {
|
|
responseByte, err := os.ReadFile("./res.json")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var (
|
|
result map[string]interface{}
|
|
res = make(map[string]entitys.AdviceData)
|
|
)
|
|
|
|
if err = json.Unmarshal(responseByte, &result); err != nil {
|
|
panic(err)
|
|
}
|
|
for k, v := range result {
|
|
if _, ok := dataMap[k]; !ok {
|
|
continue
|
|
}
|
|
var vbyte []byte
|
|
if vbyte, err = json.Marshal(v); err != nil {
|
|
panic(err)
|
|
}
|
|
newData := dataMap[k].Copy()
|
|
|
|
if err = json.Unmarshal(vbyte, newData); err != nil {
|
|
panic(err)
|
|
}
|
|
res[k] = newData
|
|
}
|
|
t.Log(result)
|
|
}
|
|
|
|
var (
|
|
file *FileService
|
|
advicer *DataService
|
|
configConfig *config.Config
|
|
fiberCtx *fiber.Ctx
|
|
)
|
|
|
|
// run 函数是程序的入口函数,负责初始化和配置各个组件
|
|
func Run(reqBody []byte) {
|
|
if reqBody != nil {
|
|
app := fiber.New()
|
|
fctx := &fasthttp.RequestCtx{}
|
|
fctx.Request.Header.SetMethod("POST")
|
|
fctx.Request.SetBody(reqBody)
|
|
fctx.Request.Header.SetContentType("application/json")
|
|
fiberCtx = app.AcquireCtx(fctx)
|
|
}
|
|
configConfig, _ = config.LoadConfigWithEnv()
|
|
// 初始化数据库连接
|
|
db, _ := utils.NewGormDb(configConfig)
|
|
advicerImpl := impl.NewAdviceAdvicerImpl(db)
|
|
advicerVersionImpl := impl.NewAdviceAdvicerVersionImpl(db)
|
|
hsyq := third_party.NewHsyq()
|
|
advicerfilebiz := biz.NewAdviceFileBiz(hsyq)
|
|
advicerbiz := biz.NewAdviceAdvicerBiz(advicerImpl, advicerVersionImpl)
|
|
file = NewFileService(advicerfilebiz, configConfig)
|
|
advicer = NewDataService(advicerbiz, configConfig)
|
|
}
|
|
|
|
var dataMap = map[string]entitys.AdviceData{
|
|
"DialectFeatures": &entitys.DialectFeatures{},
|
|
"SentencePatterns": &entitys.SentencePatterns{},
|
|
"PersonalityTags": &entitys.PersonalityTags{},
|
|
"ToneTags": &entitys.ToneTags{},
|
|
"SignatureDialogues": &entitys.SignatureDialogues{},
|
|
"RegionValue": &entitys.RegionValue{},
|
|
"CompetitionComparison": &entitys.CompetitionComparison{},
|
|
"CoreSellingPoints": &entitys.CoreSellingPoints{},
|
|
"SupportingFacilities": &entitys.SupportingFacilities{},
|
|
"DeveloperBacking": &entitys.DeveloperBacking{},
|
|
"NeedsMining": &entitys.NeedsMining{},
|
|
"PainPointResponse": &entitys.PainPointResponse{},
|
|
"ValueBuilding": &entitys.ValueBuilding{},
|
|
"ClosingTechniques": &entitys.ClosingTechniques{},
|
|
"CommunicationRhythm": &entitys.CommunicationRhythm{},
|
|
}
|