This commit is contained in:
Rzy 2026-04-23 14:32:54 +08:00
parent 5fb8e3d2ee
commit d068de7b82
10 changed files with 192 additions and 31 deletions

View File

@ -28,23 +28,24 @@ func InitializeApp(configConfig *config.Config, allLogger log.AllLogger) (*serve
platImpl := impl.NewPlatImpl(db) platImpl := impl.NewPlatImpl(db)
publishImpl := impl.NewPublishImpl(db) publishImpl := impl.NewPublishImpl(db)
loginRelationImpl := impl.NewLoginRelationImpl(db) loginRelationImpl := impl.NewLoginRelationImpl(db)
articleTypeImpl := impl.NewArticleTypeImpl(db)
productImpl := impl.NewProductImpl(db)
productSourceImpl := impl.NewProductSourceImpl(db)
oss, err := utils_oss.NewClient(configConfig)
if err != nil {
panic(err)
}
productBiz := biz.NewProductBiz(productImpl, productSourceImpl, configConfig, oss)
publishBiz := biz.NewPublishBiz(configConfig, publishImpl, userImpl, platImpl, tokenImpl, loginRelationImpl) publishBiz := biz.NewPublishBiz(configConfig, publishImpl, userImpl, platImpl, tokenImpl, loginRelationImpl)
authBiz := biz.NewAuthBiz(configConfig, tokenImpl, userImpl) authBiz := biz.NewAuthBiz(configConfig, tokenImpl, userImpl)
productImpl := impl.NewProductImpl(db)
productSourceImpl := impl.NewProductSourceImpl(db)
client, err := utils_oss.NewClient(configConfig)
if err != nil {
cleanup()
return nil, nil, err
}
productBiz := biz.NewProductBiz(productImpl, productSourceImpl, configConfig, client)
appService := service.NewAppService(configConfig, tokenImpl, userImpl, platImpl, publishBiz, authBiz, loginRelationImpl, productBiz) appService := service.NewAppService(configConfig, tokenImpl, userImpl, platImpl, publishBiz, authBiz, loginRelationImpl, productBiz)
loginService := service.NewLoginService(configConfig, publishBiz, authBiz) loginService := service.NewLoginService(configConfig, publishBiz, authBiz)
articleTypeImpl := impl.NewArticleTypeImpl(db)
aiBiz := biz.NewAiBiz(platImpl, articleTypeImpl) aiBiz := biz.NewAiBiz(platImpl, articleTypeImpl)
publishService := service.NewPublishService(configConfig, publishBiz, authBiz, db, aiBiz) publishService := service.NewPublishService(configConfig, publishBiz, authBiz, db, aiBiz)
collectImpl := impl.NewCollectImpl(db)
productService := service.NewProductService(configConfig, productImpl, authBiz, productBiz, aiBiz) collectTaskImpl := impl.NewCollectTaskImpl(db)
productService := service.NewProductService(configConfig, productImpl, authBiz, productBiz, aiBiz, collectImpl, collectTaskImpl)
productSourceService := service.NewProductSourceService(configConfig, productImpl, authBiz, aiBiz, productBiz, productSourceImpl, publishBiz, articleTypeImpl) productSourceService := service.NewProductSourceService(configConfig, productImpl, authBiz, aiBiz, productBiz, productSourceImpl, publishBiz, articleTypeImpl)
appModule := router.NewAppModule(configConfig, appService, loginService, publishService, productService, productSourceService) appModule := router.NewAppModule(configConfig, appService, loginService, publishService, productService, productSourceService)
routerServer := router.NewRouterServer(appModule) routerServer := router.NewRouterServer(appModule)

View File

@ -1,6 +1,9 @@
package ai_tool package ai_tool
import "geo/pkg" import (
"context"
"geo/pkg"
)
type Collect struct { type Collect struct {
apikey string apikey string
@ -56,8 +59,8 @@ var PlatFormList = []PlatForm{
} }
type CreateReq struct { type CreateReq struct {
// apikey // 品牌词,多个用英文逗号隔开
APIKey string `json:"api_key"` ApiKey string `json:"api_key"`
// 品牌词,多个用英文逗号隔开 // 品牌词,多个用英文逗号隔开
Keywords string `json:"keywords"` Keywords string `json:"keywords"`
// 平台1-deepseek2-豆包3-元宝4-千问5-文心一言6-纳米7-kimi8-智普 // 平台1-deepseek2-豆包3-元宝4-千问5-文心一言6-纳米7-kimi8-智普
@ -65,7 +68,7 @@ type CreateReq struct {
// 问题 // 问题
Question string `json:"question"` Question string `json:"question"`
// 建议填第三方的用户id。方便查单 // 建议填第三方的用户id。方便查单
ThirdID *string `json:"third_id,omitempty"` ThirdID string `json:"third_id,omitempty"`
} }
type CreateRes struct { type CreateRes struct {
@ -77,9 +80,9 @@ type CreateRes struct {
} `json:"data"` } `json:"data"`
} }
func (s *Collect) Create(data *CreateReq) (*CreateRes, error) { func (s *Collect) Create(ctx context.Context, data *CreateReq) (*CreateRes, error) {
url := "http://8.138.187.158:8082/api/geo/add_shoulu" url := "http://8.138.187.158:8082/api/geo/add_shoulu"
data.APIKey = s.apikey data.ApiKey = s.apikey
mapInfo, err := pkg.StructToMap(data) mapInfo, err := pkg.StructToMap(data)
if err != nil { if err != nil {
return nil, err return nil, err
@ -94,16 +97,16 @@ type CheckTaskRes struct {
Msg string `json:"msg"` Msg string `json:"msg"`
Time string `json:"time"` Time string `json:"time"`
Data struct { Data struct {
ShouluDate string `json:"shoulu_date"` ShouluDate string `json:"shoulu_date"` //收录日期格式2025-12-12
Platform int `json:"platform"` Platform int `json:"platform"` //AI平台1ds 2豆包 3元宝4千问5文心6纳米7kimi8智普
ScriptTime int `json:"script_time"` ScriptTime int `json:"script_time"` //最后查询时间戳
Question string `json:"question"` Question string `json:"question"` //问题
HitWord string `json:"hit_word"` HitWord string `json:"hit_word"` //品牌词
Status int `json:"status"` Status int `json:"status"` //查询状态0-查询中1已收录2未收录3查询失败已退款
ShareUrl string `json:"share_url"` ShareUrl string `json:"share_url"` //查询分享链接
KeywordRes string `json:"keyword_res"` KeywordRes string `json:"keyword_res"` //命中词
ImgUrl string `json:"img_url"` ImgUrl string `json:"img_url"` //查询结果截图
RequestId string `json:"request_id"` RequestId string `json:"request_id"` //任务id
} `json:"data"` } `json:"data"`
} }

View File

@ -13,7 +13,7 @@ type Config struct {
Hsyq Hsyq `mapstructure:"hsyq"` Hsyq Hsyq `mapstructure:"hsyq"`
Oss Oss `mapstructure:"oss"` Oss Oss `mapstructure:"oss"`
AiBot AiBot `mapstructure:"ai_bot"` AiBot AiBot `mapstructure:"ai_bot"`
collect Collect `mapstructure:"collect"` Collect Collect `mapstructure:"collect"`
} }
type Collect struct { type Collect struct {

View File

@ -0,0 +1,27 @@
package impl
import (
"geo/internal/data/model"
"geo/tmpl/dataTemp"
"geo/utils"
)
type CollectImpl struct {
dataTemp.DataTemp
db *utils.Db
}
func NewCollectImpl(db *utils.Db) *CollectImpl {
return &CollectImpl{
DataTemp: *dataTemp.NewDataTemp(db, new(model.Collect)),
db: db,
}
}
func (m *CollectImpl) PrimaryKey() string {
return "id"
}
func (m *CollectImpl) GetTemp() *dataTemp.DataTemp {
return &m.DataTemp
}

View File

@ -0,0 +1,27 @@
package impl
import (
"geo/internal/data/model"
"geo/tmpl/dataTemp"
"geo/utils"
)
type CollectTaskImpl struct {
dataTemp.DataTemp
db *utils.Db
}
func NewCollectTaskImpl(db *utils.Db) *CollectTaskImpl {
return &CollectTaskImpl{
DataTemp: *dataTemp.NewDataTemp(db, new(model.CollectTask)),
db: db,
}
}
func (m *CollectTaskImpl) PrimaryKey() string {
return "id"
}
func (m *CollectTaskImpl) GetTemp() *dataTemp.DataTemp {
return &m.DataTemp
}

View File

@ -13,4 +13,6 @@ var ProviderImpl = wire.NewSet(
NewProductImpl, NewProductImpl,
NewProductSourceImpl, NewProductSourceImpl,
NewArticleTypeImpl, NewArticleTypeImpl,
NewCollectTaskImpl,
NewCollectImpl,
) )

View File

@ -0,0 +1,30 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameCollect = "collect"
// Collect mapped from table <collect>
type Collect struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
ProductID int32 `gorm:"column:product_id;not null" json:"product_id"`
Keywords string `gorm:"column:keywords;not null" json:"keywords"`
Platform string `gorm:"column:platform;not null" json:"platform"`
Question string `gorm:"column:question;not null" json:"question"`
Progress int32 `gorm:"column:progress;not null" json:"progress"`
EndFile string `gorm:"column:end_file;not null" json:"end_file"`
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
Status int32 `gorm:"column:status;not null;comment:1:生成中2生成完毕" json:"status"` // 1:生成中2生成完毕
}
// TableName Collect's table name
func (*Collect) TableName() string {
return TableNameCollect
}

View File

@ -0,0 +1,33 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameCollectTask = "collect_task"
// CollectTask mapped from table <collect_task>
type CollectTask struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
RequestID string `gorm:"column:request_id;not null" json:"request_id"`
CollectID int32 `gorm:"column:collect_id;not null" json:"collect_id"`
ScriptTime string `gorm:"column:script_time;not null" json:"script_time"`
Platform int32 `gorm:"column:platform;not null" json:"platform"`
CollectData int32 `gorm:"column:collect_data;not null" json:"collect_data"`
ShareURL string `gorm:"column:share_url;not null;default:0" json:"share_url"`
ImgURL string `gorm:"column:img_url;not null" json:"img_url"`
PointKeyword string `gorm:"column:point_keyword;not null" json:"point_keyword"`
Res string `gorm:"column:res" json:"res"`
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
Status int32 `gorm:"column:status;not null" json:"status"`
}
// TableName CollectTask's table name
func (*CollectTask) TableName() string {
return TableNameCollectTask
}

View File

@ -200,5 +200,6 @@ type (
Keywords []string `json:"keywords" validate:"required" zh:"关键词"` Keywords []string `json:"keywords" validate:"required" zh:"关键词"`
Platform []int64 `json:"platform" validate:"required" zh:"平台"` Platform []int64 `json:"platform" validate:"required" zh:"平台"`
Question string `json:"question" validate:"required" zh:"问题"` Question string `json:"question" validate:"required" zh:"问题"`
ProductId int32 `json:"product_id" validate:"required" zh:"项目Id"`
} }
) )

View File

@ -1,6 +1,7 @@
package service package service
import ( import (
"context"
"geo/internal/ai_tool" "geo/internal/ai_tool"
"geo/internal/biz" "geo/internal/biz"
"geo/internal/config" "geo/internal/config"
@ -10,11 +11,14 @@ import (
"geo/pkg" "geo/pkg"
"geo/tmpl/dataTemp" "geo/tmpl/dataTemp"
"geo/tmpl/errcode" "geo/tmpl/errcode"
"github.com/go-viper/mapstructure/v2"
"github.com/gofiber/fiber/v2"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"time"
"github.com/go-viper/mapstructure/v2"
"github.com/gofiber/fiber/v2"
"xorm.io/builder" "xorm.io/builder"
) )
@ -26,7 +30,15 @@ type ProductService struct {
aiBiz *biz.AiBiz aiBiz *biz.AiBiz
} }
func NewProductService(cfg *config.Config, ProductImpl *impl.ProductImpl, authBiz *biz.AuthBiz, productBiz *biz.ProductBiz, aiBiz *biz.AiBiz) *ProductService { func NewProductService(
cfg *config.Config,
ProductImpl *impl.ProductImpl,
authBiz *biz.AuthBiz,
productBiz *biz.ProductBiz,
aiBiz *biz.AiBiz,
collect *impl.CollectImpl,
collectTask *impl.CollectTaskImpl,
) *ProductService {
return &ProductService{ return &ProductService{
cfg: cfg, cfg: cfg,
productImpl: ProductImpl, productImpl: ProductImpl,
@ -228,6 +240,31 @@ func (p *ProductService) Collect(c *fiber.Ctx, req *entitys.ProductCollectReques
if err != nil { if err != nil {
return err return err
} }
productInfo, err := p.productBiz.GetProduct(c.UserContext(), req.ProductId)
if err != nil {
return err
}
collect := ai_tool.NewCollect(p.cfg.Collect.ApiKey)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*120)
defer cancel()
for _, v := range req.Platform {
go func() {
defer func() {
if r := recover(); r != nil {
}
}()
request := ai_tool.CreateReq{
Keywords: strings.Join(req.Keywords, ","),
Question: req.Question,
Platform: v,
ThirdID: "11",
}
_, _err := collect.Create(ctx, &request)
if _err != nil {
return
}
}()
}
return pkg.HandleResponse(c, productInfo) return pkg.HandleResponse(c, productInfo)
} }