fix: 1.降低图片生成倍率 2.调整模板
This commit is contained in:
parent
e77da7875e
commit
36d9d3f363
|
|
@ -21,7 +21,7 @@ func New(cfg config.ToolConfig) *Client {
|
|||
}
|
||||
|
||||
// Call 将 Excel 文件转换为图片
|
||||
func (c *Client) Call(filename string, fileBytes []byte) ([]byte, error) {
|
||||
func (c *Client) Call(filename string, fileBytes []byte, scale int) ([]byte, error) {
|
||||
body := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(body)
|
||||
|
||||
|
|
@ -33,6 +33,14 @@ func (c *Client) Call(filename string, fileBytes []byte) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// 添加 scale 参数
|
||||
if scale <= 0 {
|
||||
scale = 2
|
||||
}
|
||||
if err = writer.WriteField("scale", fmt.Sprintf("%d", scale)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = writer.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,13 +110,13 @@ func (w *statisticsOursProduct) generateExcelAndUpload(ctx context.Context, data
|
|||
excelData := w.convertDataToExcelFormat(data)
|
||||
|
||||
// 4. 生成 Excel
|
||||
excelBytes, err := w.toolManager.Common.ExcelGenerator.Call(templatePath, excelData, 2, 2)
|
||||
excelBytes, err := w.toolManager.Common.ExcelGenerator.Call(templatePath, excelData, 4, 3)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("生成 Excel 失败: %v", err)
|
||||
}
|
||||
|
||||
// 5. Excel 转图片
|
||||
picBytes, err := w.toolManager.Common.ImageConverter.Call(fileName+".xlsx", excelBytes)
|
||||
picBytes, err := w.toolManager.Common.ImageConverter.Call(fileName+".xlsx", excelBytes, 2)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Excel 转图片失败: %v", err)
|
||||
}
|
||||
|
|
@ -143,15 +143,16 @@ func (w *statisticsOursProduct) convertDataToExcelFormat(data []statistics_ours_
|
|||
for _, item := range data {
|
||||
row := []string{
|
||||
item.OursProductName,
|
||||
fmt.Sprintf("%d", item.OursProductId),
|
||||
// fmt.Sprintf("%d", item.OursProductId),
|
||||
item.Count,
|
||||
item.TotalPrice,
|
||||
item.SuccessCount,
|
||||
// item.TotalPrice,
|
||||
// item.SuccessCount,
|
||||
item.SuccessPrice,
|
||||
item.FailCount,
|
||||
item.FailPrice,
|
||||
// item.FailCount,
|
||||
// item.FailPrice,
|
||||
item.Profit,
|
||||
}
|
||||
|
||||
result = append(result, row)
|
||||
}
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ type HTTPServer struct {
|
|||
callback *services.CallbackService
|
||||
chatHis *services.HistoryService
|
||||
capabilityService *services.CapabilityService
|
||||
cronService *services.CronService
|
||||
}
|
||||
|
||||
func NewHTTPServer(
|
||||
|
|
@ -29,11 +28,10 @@ func NewHTTPServer(
|
|||
callback *services.CallbackService,
|
||||
chatHis *services.HistoryService,
|
||||
capabilityService *services.CapabilityService,
|
||||
cronService *services.CronService,
|
||||
) *fiber.App {
|
||||
//构建 server
|
||||
app := initRoute()
|
||||
router.SetupRoutes(app, service, session, task, gateway, callback, chatHis, capabilityService, cronService)
|
||||
router.SetupRoutes(app, service, session, task, gateway, callback, chatHis, capabilityService)
|
||||
return app
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,13 +21,12 @@ type RouterServer struct {
|
|||
gateway *gateway.Gateway
|
||||
chatHist *services.HistoryService
|
||||
capabilityService *services.CapabilityService
|
||||
cronService *services.CronService
|
||||
}
|
||||
|
||||
// SetupRoutes 设置路由
|
||||
func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionService *services.SessionService, task *services.TaskService,
|
||||
gateway *gateway.Gateway, callbackService *services.CallbackService, chatHist *services.HistoryService,
|
||||
capabilityService *services.CapabilityService, cronService *services.CronService,
|
||||
capabilityService *services.CapabilityService,
|
||||
) {
|
||||
app.Use(func(c *fiber.Ctx) error {
|
||||
// 设置 CORS 头
|
||||
|
|
@ -95,11 +94,6 @@ func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionServi
|
|||
// 能力
|
||||
r.Post("/capability/product/ingest", capabilityService.ProductIngest) // 商品数据提取
|
||||
r.Post("/capability/product/ingest/:thread_id/confirm", capabilityService.ProductIngestConfirm) // 商品数据提取确认
|
||||
|
||||
// 测试任务
|
||||
r.Post("/test/cron", func(c *fiber.Ctx) error {
|
||||
return cronService.CronReportSend(c.Context())
|
||||
})
|
||||
}
|
||||
|
||||
func routerSocket(app *fiber.App, chatService *services.ChatService) {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func (u *Uploader) Run(report *ReportRes) (err error) {
|
|||
return fmt.Errorf("write to bytes failed: %v", err)
|
||||
}
|
||||
|
||||
picBytes, err := u.excel2picPy(report.Path, excelBytes.Bytes())
|
||||
picBytes, err := u.excel2picPy(report.Path, excelBytes.Bytes(), 2)
|
||||
if err != nil {
|
||||
return fmt.Errorf("excel2picPy failed: %v", err)
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ func (u *Uploader) Run(report *ReportRes) (err error) {
|
|||
// --header 'Content-Type: multipart/form-data; boundary=--------------------------952147881043913664015069' \
|
||||
// --form 'file=@"C:\\Users\\Administrator\\Downloads\\销售同比分析2025-12-29 0-12点.xlsx"' \
|
||||
// --form 'sheet_name="销售同比分析"'
|
||||
func (u *Uploader) excel2picPy(templatePath string, excelBytes []byte) ([]byte, error) {
|
||||
func (u *Uploader) excel2picPy(templatePath string, excelBytes []byte, scale int) ([]byte, error) {
|
||||
// 1. 获取 Sheet Name
|
||||
// 尝试从 excelBytes 解析,如果失败则使用默认值 "Sheet1"
|
||||
sheetName := "Sheet1"
|
||||
|
|
@ -99,6 +99,14 @@ func (u *Uploader) excel2picPy(templatePath string, excelBytes []byte) ([]byte,
|
|||
return nil, fmt.Errorf("write field sheet_name failed: %v", err)
|
||||
}
|
||||
|
||||
// 添加 scale 字段
|
||||
if scale <= 0 {
|
||||
scale = 2
|
||||
}
|
||||
if err = writer.WriteField("scale", fmt.Sprintf("%d", scale)); err != nil {
|
||||
return nil, fmt.Errorf("write field scale failed: %v", err)
|
||||
}
|
||||
|
||||
if err = writer.Close(); err != nil {
|
||||
return nil, fmt.Errorf("close writer failed: %v", err)
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue