ai_scheduler/tmp_fix_projdata.go

111 lines
4.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//go:build ignore
package main
import (
"os"
"strings"
)
func main() {
// === 1. ChatData 加 ProjectData 字段 ===
f1 := "internal/entitys/advicer.go"
b1, _ := os.ReadFile(f1)
s1 := string(b1)
old1 := `type ChatData struct {
ClientInfo *mongo_model.AdvicerClientMongoEntity ` + "`json:\"clientInfo\"`" + `
TalkSkill *mongo_model.AdvicerTalkSkillMongoEntity ` + "`json:\"talkSkill\"`" + `
ProjectInfo *mongo_model.AdvicerProjectMongoEntity ` + "`json:\"projectInfo\"`" + `
AdvicerInfo *model.AiAdviceAdvicerEntity ` + "`json:\"advicerInfo\"`" + `
AdvicerVersion map[string]interface{} ` + "`json:\"advicerVersion\"`" + ` // 扁平维度数据
// RuleDimension 项目风控红线(来自项目模板 rule_dimension,可为空)
RuleDimension string ` + "`json:\"ruleDimension\"`" + `
}`
new1 := `type ChatData struct {
ClientInfo *mongo_model.AdvicerClientMongoEntity ` + "`json:\"clientInfo\"`" + `
TalkSkill *mongo_model.AdvicerTalkSkillMongoEntity ` + "`json:\"talkSkill\"`" + `
ProjectInfo *mongo_model.AdvicerProjectMongoEntity ` + "`json:\"projectInfo\"`" + `
ProjectData map[string]interface{} ` + "`json:\"projectData\"`" + ` // advicer_project_data 扁平栏目数据
AdvicerInfo *model.AiAdviceAdvicerEntity ` + "`json:\"advicerInfo\"`" + `
AdvicerVersion map[string]interface{} ` + "`json:\"advicerVersion\"`" + ` // 扁平维度数据
// RuleDimension 项目风控红线(来自项目模板 rule_dimension,可为空)
RuleDimension string ` + "`json:\"ruleDimension\"`" + `
}`
if strings.Contains(s1, old1) {
s1 = strings.Replace(s1, old1, new1, 1)
os.WriteFile(f1, []byte(s1), 0644)
println("1. ChatData: ProjectData field added")
} else {
println("1. ERROR: ChatData struct not found")
return
}
// === 2. autoRegisSession: 加载 ProjectData 并填入 ChatData ===
f2 := "internal/biz/advice_wx.go"
b2, _ := os.ReadFile(f2)
s2 := string(b2)
old2 := ` // 构建 ChatData(全量数据注入)
chatData := &entitys.ChatData{
AdvicerInfo: advicer.Entity(),
AdvicerVersion: versionInfo.Data,
ProjectInfo: projEntity,
RuleDimension: projectInfo.Base.RuleDimension,
TalkSkill: talkSkillEntity,
ClientInfo: clientEntity,
}`
new2 := ` // 加载项目资料(advicer_project_data 集合,扁平栏目数据)
var projectData map[string]interface{}
if projData, e := a.adviceProjectBiz.ProjectDataLoad(ctx, projectInfo.Base.ProjectID); e == nil && len(projData.Data) > 0 {
projectData = projData.Data
}
// 构建 ChatData(全量数据注入)
chatData := &entitys.ChatData{
AdvicerInfo: advicer.Entity(),
AdvicerVersion: versionInfo.Data,
ProjectInfo: projEntity,
ProjectData: projectData,
RuleDimension: projectInfo.Base.RuleDimension,
TalkSkill: talkSkillEntity,
ClientInfo: clientEntity,
}`
if strings.Contains(s2, old2) {
s2 = strings.Replace(s2, old2, new2, 1)
os.WriteFile(f2, []byte(s2), 0644)
println("2. autoRegisSession: ProjectData load added")
} else {
println("2. ERROR: ChatData construction block not found")
return
}
// === 3. buildChatPromptResponse: 注入 ProjectData ===
f3 := "internal/biz/advice_chat.go"
b3, _ := os.ReadFile(f3)
s3 := string(b3)
old3 := ` if chatData.ProjectInfo != nil {
sys.WriteString("\n[项目信息]\n")
sys.WriteString(pkg.JsonStringIgonErr(chatData.ProjectInfo))
}`
new3 := ` if chatData.ProjectInfo != nil {
sys.WriteString("\n[项目信息]\n")
sys.WriteString(pkg.JsonStringIgonErr(chatData.ProjectInfo))
}
if chatData.ProjectData != nil && len(chatData.ProjectData) > 0 {
sys.WriteString("\n[项目资料]\n")
sys.WriteString(pkg.JsonStringIgonErr(chatData.ProjectData))
}`
if strings.Contains(s3, old3) {
s3 = strings.Replace(s3, old3, new3, 1)
os.WriteFile(f3, []byte(s3), 0644)
println("3. buildChatPromptResponse: ProjectData injection added")
} else {
println("3. ERROR: ProjectInfo block in buildChatPromptResponse not found")
return
}
println("\nALL DONE")
}