118 lines
3.0 KiB
Go
118 lines
3.0 KiB
Go
package advice
|
|
|
|
import (
|
|
"ai_scheduler/internal/biz"
|
|
"ai_scheduler/internal/config"
|
|
errorcode "ai_scheduler/internal/data/error"
|
|
"ai_scheduler/internal/pkg"
|
|
|
|
"ai_scheduler/internal/data/mongo_model"
|
|
"ai_scheduler/internal/entitys"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2/log"
|
|
)
|
|
|
|
// FileService 文件处理
|
|
type ChatService struct {
|
|
adviceChatBiz *biz.AdviceChatBiz
|
|
adviceClientBiz *biz.AdviceClientBiz
|
|
adviceAdvicerBiz *biz.AdviceAdvicerBiz
|
|
adviceProjectBiz *biz.AdviceProjectBiz
|
|
adviceSkillBiz *biz.AdviceSkillBiz
|
|
cfg *config.Config
|
|
}
|
|
|
|
// NewFileService
|
|
func NewChatService(
|
|
adviceChatBiz *biz.AdviceChatBiz,
|
|
adviceClientBiz *biz.AdviceClientBiz,
|
|
adviceAdvicerBiz *biz.AdviceAdvicerBiz,
|
|
adviceProjectBiz *biz.AdviceProjectBiz,
|
|
adviceSkillBiz *biz.AdviceSkillBiz,
|
|
cfg *config.Config,
|
|
) *ChatService {
|
|
return &ChatService{
|
|
adviceChatBiz: adviceChatBiz,
|
|
cfg: cfg,
|
|
adviceClientBiz: adviceClientBiz,
|
|
adviceAdvicerBiz: adviceAdvicerBiz,
|
|
adviceProjectBiz: adviceProjectBiz,
|
|
adviceSkillBiz: adviceSkillBiz,
|
|
}
|
|
}
|
|
|
|
func (a *ChatService) Regis(c *fiber.Ctx) error {
|
|
req := &entitys.AdvicerChatRegistReq{}
|
|
if err := c.BodyParser(req); err != nil {
|
|
return err
|
|
}
|
|
if len(req.AdvicerVersionId) == 0 {
|
|
return errorcode.ParamErr("AdvicerVersionId is empty")
|
|
}
|
|
if len(req.TalkSkillId) == 0 {
|
|
return errorcode.ParamErr("talkSkillId is empty")
|
|
}
|
|
//顾问版本信息
|
|
versionInfo, err := a.adviceAdvicerBiz.VersionInfo(c.UserContext(), &entitys.AdvicerVersionInfoReq{
|
|
Id: req.AdvicerVersionId,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
//顾问信息
|
|
advicerInfo, err := a.adviceAdvicerBiz.AdvicerInfo(c.UserContext(), &entitys.AdvicerInfoReq{
|
|
AdvicerID: versionInfo.AdvicerId,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
//项目信息
|
|
projectInfo, err := a.adviceProjectBiz.Info(c.UserContext(), &entitys.AdvicerProjectInfoReq{
|
|
ProjectId: advicerInfo.ProjectID,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
//销售技巧
|
|
talkSkill, err := a.adviceSkillBiz.Info(c.UserContext(), &entitys.AdvicerTalkSkillInfoReq{
|
|
Id: req.TalkSkillId,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
//客户信息
|
|
var clientInfo mongo_model.AdvicerClientMongo
|
|
if len(req.ClientId) != 0 {
|
|
|
|
clientInfo, err = a.adviceClientBiz.Info(c.UserContext(), &entitys.AdvicerClientInfoReq{
|
|
Id: req.ClientId,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
chat := entitys.ChatData{
|
|
ClientInfo: clientInfo.Entity(),
|
|
TalkSkill: talkSkill.Entity(),
|
|
ProjectInfo: projectInfo.Entity(),
|
|
AdvicerInfo: advicerInfo.Entity(),
|
|
AdvicerVersion: versionInfo.Entity(),
|
|
}
|
|
sessionId, err := a.adviceChatBiz.Regis(c.UserContext(), &chat)
|
|
log.Info(sessionId)
|
|
return pkg.HandleResponse(c, sessionId, err)
|
|
}
|
|
|
|
func (a *ChatService) Chat(c *fiber.Ctx) error {
|
|
req := &entitys.AdvicerChatReq{}
|
|
if err := c.BodyParser(req); err != nil {
|
|
return err
|
|
}
|
|
|
|
res, err := a.adviceChatBiz.Chat(c.UserContext(), req)
|
|
log.Info(res)
|
|
return pkg.HandleResponse(c, res, err)
|
|
}
|