90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"geo/internal/ai_tool"
|
|
"geo/internal/biz"
|
|
"geo/internal/config"
|
|
"geo/internal/data/impl"
|
|
"geo/internal/data/model"
|
|
"geo/internal/entitys"
|
|
"github.com/go-viper/mapstructure/v2"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type ProductSourceService struct {
|
|
cfg *config.Config
|
|
productImpl *impl.ProductImpl
|
|
authBiz *biz.AuthBiz
|
|
aiBiz *biz.AiBiz
|
|
productBiz *biz.ProductBiz
|
|
}
|
|
|
|
func NewProductSourceService(cfg *config.Config, ProductImpl *impl.ProductImpl, authBiz *biz.AuthBiz, aiBiz *biz.AiBiz, productBiz *biz.ProductBiz) *ProductSourceService {
|
|
return &ProductSourceService{
|
|
cfg: cfg,
|
|
productImpl: ProductImpl,
|
|
authBiz: authBiz,
|
|
aiBiz: aiBiz,
|
|
productBiz: productBiz,
|
|
}
|
|
}
|
|
|
|
func (p *ProductSourceService) Create(c *fiber.Ctx, req *entitys.ProductSourceCreateRequest) error {
|
|
// 验证token
|
|
_, err := p.authBiz.ValidateAccessToken(c.UserContext(), req.AccessToken)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
brandInfo, err := p.productBiz.GetBrandInfo(c.UserContext(), req.Id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
BotChatMes := &entitys.BotChat{
|
|
Question: req.Ques,
|
|
ArticleType: req.ArticleType,
|
|
BrandInfo: brandInfo,
|
|
}
|
|
mes := p.aiBiz.CreateArticlePrompt(c.UserContext(), BotChatMes)
|
|
content, err := ai_tool.NewHsyq().RequestHsyqBot(c.UserContext(), p.cfg.Hsyq.ApiKey, "bot-20260413000114-8bw62", mes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var resp entitys.BotChatResponse
|
|
if err := json.Unmarshal(content, &resp); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p *ProductSourceService) List(c *fiber.Ctx, req *entitys.ProductSourceListRequest) error {
|
|
// 验证token
|
|
_, _, err := p.authBiz.UserAndTokenValid(c.UserContext(), req.UserIndex, req.AccessToken)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p *ProductSourceService) Upload(c *fiber.Ctx, req *entitys.ProductSourceUploadRequest) error {
|
|
// 验证token
|
|
_, _, err := p.authBiz.UserAndTokenValid(c.UserContext(), req.UserIndex, req.AccessToken)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p *ProductSourceService) Del(c *fiber.Ctx, req *entitys.ProductSourceDelRequest) error {
|
|
// 验证token
|
|
_, _, err := p.authBiz.UserAndTokenValid(c.UserContext(), req.UserIndex, req.AccessToken)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|