From d068de7b82a6c906ce3f68406bd3b87222812bd0 Mon Sep 17 00:00:00 2001 From: Rzy <465386466@qq.com> Date: Thu, 23 Apr 2026 14:32:54 +0800 Subject: [PATCH] 22 --- cmd/server/wire_gen.go | 23 ++++++------- internal/ai_tool/collect.go | 35 +++++++++++--------- internal/config/config.go | 2 +- internal/data/impl/collect.go | 27 ++++++++++++++++ internal/data/impl/collect_task.go | 27 ++++++++++++++++ internal/data/impl/provider_set.go | 2 ++ internal/data/model/collect.gen.go | 30 +++++++++++++++++ internal/data/model/collect_task.gen.go | 33 +++++++++++++++++++ internal/entitys/request.go | 1 + internal/service/product.go | 43 +++++++++++++++++++++++-- 10 files changed, 192 insertions(+), 31 deletions(-) create mode 100644 internal/data/impl/collect.go create mode 100644 internal/data/impl/collect_task.go create mode 100644 internal/data/model/collect.gen.go create mode 100644 internal/data/model/collect_task.gen.go diff --git a/cmd/server/wire_gen.go b/cmd/server/wire_gen.go index a53134c..bdcbccb 100644 --- a/cmd/server/wire_gen.go +++ b/cmd/server/wire_gen.go @@ -28,23 +28,24 @@ func InitializeApp(configConfig *config.Config, allLogger log.AllLogger) (*serve platImpl := impl.NewPlatImpl(db) publishImpl := impl.NewPublishImpl(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) 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) loginService := service.NewLoginService(configConfig, publishBiz, authBiz) + articleTypeImpl := impl.NewArticleTypeImpl(db) aiBiz := biz.NewAiBiz(platImpl, articleTypeImpl) publishService := service.NewPublishService(configConfig, publishBiz, authBiz, db, aiBiz) - - productService := service.NewProductService(configConfig, productImpl, authBiz, productBiz, aiBiz) - + collectImpl := impl.NewCollectImpl(db) + 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) appModule := router.NewAppModule(configConfig, appService, loginService, publishService, productService, productSourceService) routerServer := router.NewRouterServer(appModule) diff --git a/internal/ai_tool/collect.go b/internal/ai_tool/collect.go index 4116cd8..e363cf7 100644 --- a/internal/ai_tool/collect.go +++ b/internal/ai_tool/collect.go @@ -1,6 +1,9 @@ package ai_tool -import "geo/pkg" +import ( + "context" + "geo/pkg" +) type Collect struct { apikey string @@ -56,8 +59,8 @@ var PlatFormList = []PlatForm{ } type CreateReq struct { - // apikey - APIKey string `json:"api_key"` + // 品牌词,多个用英文逗号隔开 + ApiKey string `json:"api_key"` // 品牌词,多个用英文逗号隔开 Keywords string `json:"keywords"` // 平台,1-deepseek,2-豆包,3-元宝,4-千问,5-文心一言,6-纳米,7-kimi,8-智普 @@ -65,7 +68,7 @@ type CreateReq struct { // 问题 Question string `json:"question"` // 建议填第三方的用户id。方便查单 - ThirdID *string `json:"third_id,omitempty"` + ThirdID string `json:"third_id,omitempty"` } type CreateRes struct { @@ -77,9 +80,9 @@ type CreateRes struct { } `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" - data.APIKey = s.apikey + data.ApiKey = s.apikey mapInfo, err := pkg.StructToMap(data) if err != nil { return nil, err @@ -94,16 +97,16 @@ type CheckTaskRes struct { Msg string `json:"msg"` Time string `json:"time"` Data struct { - ShouluDate string `json:"shoulu_date"` - Platform int `json:"platform"` - ScriptTime int `json:"script_time"` - Question string `json:"question"` - HitWord string `json:"hit_word"` - Status int `json:"status"` - ShareUrl string `json:"share_url"` - KeywordRes string `json:"keyword_res"` - ImgUrl string `json:"img_url"` - RequestId string `json:"request_id"` + ShouluDate string `json:"shoulu_date"` //收录日期,格式:2025-12-12 + Platform int `json:"platform"` //AI平台,1ds, 2豆包, 3元宝,4千问,5文心,6纳米,7kimi,8智普 + ScriptTime int `json:"script_time"` //最后查询时间戳 + Question string `json:"question"` //问题 + HitWord string `json:"hit_word"` //品牌词 + Status int `json:"status"` //查询状态,0-查询中,1已收录,2未收录,3查询失败已退款 + ShareUrl string `json:"share_url"` //查询分享链接 + KeywordRes string `json:"keyword_res"` //命中词 + ImgUrl string `json:"img_url"` //查询结果截图 + RequestId string `json:"request_id"` //任务id } `json:"data"` } diff --git a/internal/config/config.go b/internal/config/config.go index 4102335..89142ce 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -13,7 +13,7 @@ type Config struct { Hsyq Hsyq `mapstructure:"hsyq"` Oss Oss `mapstructure:"oss"` AiBot AiBot `mapstructure:"ai_bot"` - collect Collect `mapstructure:"collect"` + Collect Collect `mapstructure:"collect"` } type Collect struct { diff --git a/internal/data/impl/collect.go b/internal/data/impl/collect.go new file mode 100644 index 0000000..51a3e86 --- /dev/null +++ b/internal/data/impl/collect.go @@ -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 +} diff --git a/internal/data/impl/collect_task.go b/internal/data/impl/collect_task.go new file mode 100644 index 0000000..4eeaf3c --- /dev/null +++ b/internal/data/impl/collect_task.go @@ -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 +} diff --git a/internal/data/impl/provider_set.go b/internal/data/impl/provider_set.go index dfbe556..cde8817 100644 --- a/internal/data/impl/provider_set.go +++ b/internal/data/impl/provider_set.go @@ -13,4 +13,6 @@ var ProviderImpl = wire.NewSet( NewProductImpl, NewProductSourceImpl, NewArticleTypeImpl, + NewCollectTaskImpl, + NewCollectImpl, ) diff --git a/internal/data/model/collect.gen.go b/internal/data/model/collect.gen.go new file mode 100644 index 0000000..ec400e4 --- /dev/null +++ b/internal/data/model/collect.gen.go @@ -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 +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 +} diff --git a/internal/data/model/collect_task.gen.go b/internal/data/model/collect_task.gen.go new file mode 100644 index 0000000..6353355 --- /dev/null +++ b/internal/data/model/collect_task.gen.go @@ -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 +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 +} diff --git a/internal/entitys/request.go b/internal/entitys/request.go index fd38f87..00887d4 100644 --- a/internal/entitys/request.go +++ b/internal/entitys/request.go @@ -200,5 +200,6 @@ type ( Keywords []string `json:"keywords" validate:"required" zh:"关键词"` Platform []int64 `json:"platform" validate:"required" zh:"平台"` Question string `json:"question" validate:"required" zh:"问题"` + ProductId int32 `json:"product_id" validate:"required" zh:"项目Id"` } ) diff --git a/internal/service/product.go b/internal/service/product.go index c4c4a66..e852781 100644 --- a/internal/service/product.go +++ b/internal/service/product.go @@ -1,6 +1,7 @@ package service import ( + "context" "geo/internal/ai_tool" "geo/internal/biz" "geo/internal/config" @@ -10,11 +11,14 @@ import ( "geo/pkg" "geo/tmpl/dataTemp" "geo/tmpl/errcode" - "github.com/go-viper/mapstructure/v2" - "github.com/gofiber/fiber/v2" "io" "os" "path/filepath" + "strings" + "time" + + "github.com/go-viper/mapstructure/v2" + "github.com/gofiber/fiber/v2" "xorm.io/builder" ) @@ -26,7 +30,15 @@ type ProductService struct { 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{ cfg: cfg, productImpl: ProductImpl, @@ -228,6 +240,31 @@ func (p *ProductService) Collect(c *fiber.Ctx, req *entitys.ProductCollectReques if err != nil { 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) }