ai_scheduler/tmp_fix_project.go

52 lines
1.4 KiB
Go
Raw 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() {
f := "internal/biz/advice_wx.go"
b, _ := os.ReadFile(f)
s := string(b)
// Fix: Use Base.Name (MySQL) instead of ConfigInfo.ProjectInfo.Name (MongoDB)
// The MySQL ai_advice_project table has the project name, MongoDB might not have projectInfo sub-doc
old := ` if pi := projectInfo.ConfigInfo.ProjectInfo; pi.Name != "" || pi.Address != "" {
projectDesc := "\n[项目信息]"
if pi.Name != "" {
projectDesc += "\n项目名称:" + pi.Name
}
if pi.Address != "" {
projectDesc += "\n项目地址:" + pi.Address
}
mission = mission + projectDesc
log.Infof("[托管] 项目信息已注入 mission advicerId=%d projectName=%s", advicer.AdvicerID, pi.Name)
}`
new := ` // 项目信息:优先用 MySQL 的 Base.Name(一定有),MongoDB 的 ProjectInfo 作为补充
projectDesc := "\n[项目信息]"
hasProjectInfo := false
if projectInfo.Base.Name != "" {
projectDesc += "\n项目名称:" + projectInfo.Base.Name
hasProjectInfo = true
}
if pi := projectInfo.ConfigInfo.ProjectInfo; pi.Address != "" {
projectDesc += "\n项目地址:" + pi.Address
hasProjectInfo = true
}
if hasProjectInfo {
mission = mission + projectDesc
}`
if strings.Contains(s, old) {
s = strings.Replace(s, old, new, 1)
os.WriteFile(f, []byte(s), 0644)
println("done - fixed project info to use Base.Name")
} else {
println("ERROR: project info block not found")
}
}