120 lines
4.2 KiB
Go
120 lines
4.2 KiB
Go
//go:build ignore
|
||
|
||
package main
|
||
|
||
import (
|
||
"os"
|
||
"strings"
|
||
)
|
||
|
||
func main() {
|
||
f := "internal/biz/advice_wx.go"
|
||
b, _ := os.ReadFile(f)
|
||
s := string(b)
|
||
ok := true
|
||
|
||
// === 1. autoRegisSession 签名加 peerWxid ===
|
||
old1 := `func (a *AdviceWxBiz) autoRegisSession(ctx context.Context,
|
||
advicer dbmodel.AiAdviceAdvicer,
|
||
projectInfo *entitys.AdvicerProjectInfoRes,
|
||
customerId int32, customerNickName string,
|
||
) (string, *dbmodel.AiAdviceSession, *dbmodel.AiAdviceModelSup, error) {`
|
||
new1 := `func (a *AdviceWxBiz) autoRegisSession(ctx context.Context,
|
||
advicer dbmodel.AiAdviceAdvicer,
|
||
projectInfo *entitys.AdvicerProjectInfoRes,
|
||
customerId int32, customerNickName string,
|
||
peerWxid string,
|
||
) (string, *dbmodel.AiAdviceSession, *dbmodel.AiAdviceModelSup, error) {`
|
||
if strings.Contains(s, old1) {
|
||
s = strings.Replace(s, old1, new1, 1)
|
||
println("1. autoRegisSession signature: peerWxid added")
|
||
} else {
|
||
println("1. ERROR: signature not found")
|
||
ok = false
|
||
}
|
||
|
||
// === 2. 调用点1(普通托管路径)加 peerWxid ===
|
||
old2 := `sessionId, cachedSession, cachedModelInfo, err = a.autoRegisSession(ctx, advicer, projectInfo, customer.CustomerID, customerNickName)
|
||
if err != nil {
|
||
// autoRegisSession error`
|
||
new2 := `sessionId, cachedSession, cachedModelInfo, err = a.autoRegisSession(ctx, advicer, projectInfo, customer.CustomerID, customerNickName, peerWxid)
|
||
if err != nil {
|
||
// autoRegisSession error`
|
||
if strings.Contains(s, old2) {
|
||
s = strings.Replace(s, old2, new2, 1)
|
||
println("2. call site 1: peerWxid added")
|
||
} else {
|
||
println("2. ERROR: call site 1 not found")
|
||
ok = false
|
||
}
|
||
|
||
// === 3. 调用点2(filehelper路径)加 peerWxid ===
|
||
old3 := `sessionId, cachedSession, cachedModelInfo, err = a.autoRegisSession(ctx, advicer, projectInfo, customer.CustomerID, customerNickName)
|
||
if err != nil {
|
||
// filehelper autoRegis error`
|
||
new3 := `sessionId, cachedSession, cachedModelInfo, err = a.autoRegisSession(ctx, advicer, projectInfo, customer.CustomerID, customerNickName, peerWxid)
|
||
if err != nil {
|
||
// filehelper autoRegis error`
|
||
if strings.Contains(s, old3) {
|
||
s = strings.Replace(s, old3, new3, 1)
|
||
println("3. call site 2 (filehelper): peerWxid added")
|
||
} else {
|
||
println("3. ERROR: call site 2 not found")
|
||
ok = false
|
||
}
|
||
|
||
// === 4. ChatData 构造:加载 TalkSkill + ClientInfo + 补全 ProjectInfo.Name ===
|
||
old4 := ` // 构建 ChatData(直接使用传入的 advicer,不再重复查询)
|
||
chatData := &entitys.ChatData{
|
||
AdvicerInfo: advicer.Entity(),
|
||
AdvicerVersion: versionInfo.Data,
|
||
ProjectInfo: projectInfo.ConfigInfo.Entity(),
|
||
RuleDimension: projectInfo.Base.RuleDimension,
|
||
}`
|
||
new4 := ` // 加载销售技巧
|
||
var talkSkillEntity *mongo_model.AdvicerTalkSkillMongoEntity
|
||
if advicer.HostingSkillId != "" {
|
||
if skillInfo, e := a.adviceSkillBiz.Info(ctx, &entitys.AdvicerTalkSkillInfoReq{Id: advicer.HostingSkillId}); e == nil && skillInfo.ProjectId > 0 {
|
||
talkSkillEntity = skillInfo.Entity()
|
||
}
|
||
}
|
||
// 加载客户信息(MongoDB advicer_client)
|
||
var clientEntity *mongo_model.AdvicerClientMongoEntity
|
||
if peerWxid != "" {
|
||
var clientDoc mongo_model.AdvicerClientMongo
|
||
filter := bson.M{"projectId": projectInfo.Base.ProjectID, "advicerId": advicer.AdvicerID, "wxid": peerWxid}
|
||
if e := a.mongo.Co(mongo_model.NewAdvicerClientMongo()).FindOne(ctx, filter).Decode(&clientDoc); e == nil {
|
||
clientEntity = clientDoc.Entity()
|
||
}
|
||
}
|
||
// 构建完整 ProjectInfo(确保 MySQL 项目名不丢)
|
||
projEntity := projectInfo.ConfigInfo.Entity()
|
||
if projEntity.ProjectInfo.Name == "" && projectInfo.Base.Name != "" {
|
||
projEntity.ProjectInfo.Name = projectInfo.Base.Name
|
||
}
|
||
|
||
// 构建 ChatData(全量数据注入)
|
||
chatData := &entitys.ChatData{
|
||
AdvicerInfo: advicer.Entity(),
|
||
AdvicerVersion: versionInfo.Data,
|
||
ProjectInfo: projEntity,
|
||
RuleDimension: projectInfo.Base.RuleDimension,
|
||
TalkSkill: talkSkillEntity,
|
||
ClientInfo: clientEntity,
|
||
}`
|
||
if strings.Contains(s, old4) {
|
||
s = strings.Replace(s, old4, new4, 1)
|
||
println("4. ChatData: TalkSkill + ClientInfo + ProjectInfo.Name fixed")
|
||
} else {
|
||
println("4. ERROR: ChatData block not found")
|
||
ok = false
|
||
}
|
||
|
||
if ok {
|
||
os.WriteFile(f, []byte(s), 0644)
|
||
println("\nALL DONE - advice_wx.go updated")
|
||
} else {
|
||
println("\nFAILED - some blocks not found")
|
||
}
|
||
}
|