fix:1.处理单元测试问题 2.处理配置散乱问题
This commit is contained in:
parent
21b9501be6
commit
bd531c5de1
|
|
@ -72,7 +72,7 @@ func (g *GroupConfigBiz) GetReportLists(ctx context.Context, groupConfig *model.
|
||||||
product = strings.Split(groupConfig.ProductName, ",")
|
product = strings.Split(groupConfig.ProductName, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
reportList, err := bbxt.NewBbxtTools()
|
reportList, err := bbxt.NewBbxtTools(g.conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -145,8 +145,8 @@ func (g *GroupConfigBiz) handleReport(ctx context.Context, rec *entitys.Recogniz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rep, err := bbxt.NewBbxtTools()
|
rep, err := bbxt.NewBbxtTools(g.conf)
|
||||||
uploader := bbxt.NewUploader(g.ossClient)
|
uploader := bbxt.NewUploader(g.ossClient, g.conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -296,3 +296,25 @@ func LoadConfigWithTest() (*Config, error) {
|
||||||
return &bc, nil
|
return &bc, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LoadConfigWithEnv() (*Config, error) {
|
||||||
|
var bc Config
|
||||||
|
modularDir, err := pkg.GetModuleDir()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
viper.SetConfigFile(modularDir + "/config/config_env.yaml")
|
||||||
|
viper.SetConfigType("yaml")
|
||||||
|
// 读取配置文件
|
||||||
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to read config file: %w", err)
|
||||||
|
}
|
||||||
|
// 解析配置
|
||||||
|
|
||||||
|
if err := viper.Unmarshal(&bc); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &bc, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"ai_scheduler/internal/domain/workflow/runtime"
|
"ai_scheduler/internal/domain/workflow/runtime"
|
||||||
"ai_scheduler/internal/pkg/lsxd"
|
"ai_scheduler/internal/pkg/lsxd"
|
||||||
"ai_scheduler/internal/pkg/utils_oss"
|
"ai_scheduler/internal/pkg/utils_oss"
|
||||||
|
"ai_scheduler/pkg"
|
||||||
"ai_scheduler/utils"
|
"ai_scheduler/utils"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -158,8 +159,7 @@ func (w *statisticsOursProduct) callStatisticsTool(ctx context.Context, state *S
|
||||||
|
|
||||||
func (w *statisticsOursProduct) generateExcelAndUpload(ctx context.Context, state *StatisticsOursProductContext) (*StatisticsOursProductContext, error) {
|
func (w *statisticsOursProduct) generateExcelAndUpload(ctx context.Context, state *StatisticsOursProductContext) (*StatisticsOursProductContext, error) {
|
||||||
// 1. 获取模板路径
|
// 1. 获取模板路径
|
||||||
// cwd, _ := filepath.Abs("../../") // 单元测试用
|
cwd, _ := pkg.GetModuleDir()
|
||||||
cwd, _ := filepath.Abs(".")
|
|
||||||
templatePath := filepath.Join(cwd, "tmpl", "excel_temp", "recharge_statistics_ours_product.xlsx")
|
templatePath := filepath.Join(cwd, "tmpl", "excel_temp", "recharge_statistics_ours_product.xlsx")
|
||||||
fileName := fmt.Sprintf("statistics_ours_product_%d%d", time.Now().Unix(), rand.Intn(1000))
|
fileName := fmt.Sprintf("statistics_ours_product_%d%d", time.Now().Unix(), rand.Intn(1000))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ var (
|
||||||
// run 函数是程序的入口函数,负责初始化和配置各个组件
|
// run 函数是程序的入口函数,负责初始化和配置各个组件
|
||||||
func run() {
|
func run() {
|
||||||
// 加载测试配置
|
// 加载测试配置
|
||||||
configConfig, err = config.LoadConfigWithTest()
|
// configConfig, err = config.LoadConfigWithTest()
|
||||||
|
configConfig, err = config.LoadConfigWithEnv()
|
||||||
// 初始化数据库连接
|
// 初始化数据库连接
|
||||||
db, _ := utils.NewGormDb(configConfig)
|
db, _ := utils.NewGormDb(configConfig)
|
||||||
// 初始化各种实现层组件
|
// 初始化各种实现层组件
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package bbxt
|
package bbxt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"ai_scheduler/internal/config"
|
||||||
pkginner "ai_scheduler/internal/pkg"
|
pkginner "ai_scheduler/internal/pkg"
|
||||||
"ai_scheduler/internal/pkg/utils_oss"
|
"ai_scheduler/internal/pkg/utils_oss"
|
||||||
"ai_scheduler/pkg"
|
"ai_scheduler/pkg"
|
||||||
|
|
@ -41,9 +42,10 @@ type BbxtTools struct {
|
||||||
cacheDir string
|
cacheDir string
|
||||||
excelTempDir string
|
excelTempDir string
|
||||||
ossClient *utils_oss.Client
|
ossClient *utils_oss.Client
|
||||||
|
config *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBbxtTools() (*BbxtTools, error) {
|
func NewBbxtTools(config *config.Config) (*BbxtTools, error) {
|
||||||
cache, err := pkg.GetCacheDir()
|
cache, err := pkg.GetCacheDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -56,6 +58,7 @@ func NewBbxtTools() (*BbxtTools, error) {
|
||||||
return &BbxtTools{
|
return &BbxtTools{
|
||||||
cacheDir: cache,
|
cacheDir: cache,
|
||||||
excelTempDir: fmt.Sprintf("%s/excel_temp", tempDir),
|
excelTempDir: fmt.Sprintf("%s/excel_temp", tempDir),
|
||||||
|
config: config,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +84,7 @@ func (b *BbxtTools) DailyReport(now time.Time, downWardValue int32, productName
|
||||||
reports = append(reports, profitRankingSum, statisOfficialProductSum, statisOfficialProductSumDecline)
|
reports = append(reports, profitRankingSum, statisOfficialProductSum, statisOfficialProductSumDecline)
|
||||||
|
|
||||||
if ossClient != nil {
|
if ossClient != nil {
|
||||||
uploader := NewUploader(ossClient)
|
uploader := NewUploader(ossClient, b.config)
|
||||||
for _, report := range reports {
|
for _, report := range reports {
|
||||||
_ = uploader.Run(report)
|
_ = uploader.Run(report)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package bbxt
|
package bbxt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"ai_scheduler/internal/config"
|
||||||
"ai_scheduler/internal/pkg/utils_oss"
|
"ai_scheduler/internal/pkg/utils_oss"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -19,13 +20,13 @@ import (
|
||||||
|
|
||||||
type Uploader struct {
|
type Uploader struct {
|
||||||
ossClient *utils_oss.Client
|
ossClient *utils_oss.Client
|
||||||
|
config *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
const RequestUrl = "http://excel2pic:8000/api/v1/convert"
|
func NewUploader(oss *utils_oss.Client, config *config.Config) *Uploader {
|
||||||
|
|
||||||
func NewUploader(oss *utils_oss.Client) *Uploader {
|
|
||||||
return &Uploader{
|
return &Uploader{
|
||||||
ossClient: oss,
|
ossClient: oss,
|
||||||
|
config: config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,7 +119,7 @@ func (u *Uploader) excel2picPy(templatePath string, excelBytes []byte, scale int
|
||||||
|
|
||||||
// 3. 发送 HTTP POST 请求
|
// 3. 发送 HTTP POST 请求
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", RequestUrl, body)
|
req, err := http.NewRequest("POST", u.config.EinoTools.Excel2Pic.BaseURL, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("create request failed: %v", err)
|
return nil, fmt.Errorf("create request failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue