feat: optimize background tasks and fix warehouse pricelist workflow
Optimize task retention from 5 minutes to 30 seconds to reduce polling overhead since toast notifications are shown only once. Add conditional warehouse pricelist creation via checkbox. Fix category storage in warehouse pricelists to properly load from lot table. Replace SSE with task polling for all long operations. Add comprehensive logging for debugging while minimizing noise from polling endpoints. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -143,7 +143,7 @@ func (h *PricelistHandler) CreateWithProgress(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Send final completion message
|
||||
progressCb(100, fmt.Sprintf("Прайслист создан: v%d из источника %s", pl.Version, pl.Source))
|
||||
progressCb(100, fmt.Sprintf("Прайслист создан: %s из источника %s", pl.Version, pl.Source))
|
||||
|
||||
return map[string]interface{}{
|
||||
"pricelist_id": pl.ID,
|
||||
@@ -295,9 +295,9 @@ func (h *PricelistHandler) ExportCSV(c *gin.Context) {
|
||||
row = append(row, item.LotName)
|
||||
|
||||
// Категория
|
||||
category := item.Category
|
||||
if category == "" {
|
||||
category = "-"
|
||||
category := "-"
|
||||
if item.LotCategory != nil && *item.LotCategory != "" {
|
||||
category = *item.LotCategory
|
||||
}
|
||||
row = append(row, category)
|
||||
|
||||
|
||||
@@ -1009,6 +1009,10 @@ func (h *PricingHandler) ImportStockLog(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Read create_pricelist parameter
|
||||
createPricelistStr := c.PostForm("create_pricelist")
|
||||
createPricelist := createPricelistStr == "true"
|
||||
|
||||
file, err := fileHeader.Open()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "failed to open uploaded file"})
|
||||
@@ -1035,7 +1039,7 @@ func (h *PricingHandler) ImportStockLog(c *gin.Context) {
|
||||
filename := fileHeader.Filename
|
||||
|
||||
taskID := h.taskManager.Submit(tasks.TaskTypeStockImport, func(ctx context.Context, progressCb func(int, string)) (map[string]interface{}, error) {
|
||||
result, impErr := h.stockImportService.Import(filename, content, modTime, h.dbUsername, func(p services.StockImportProgress) {
|
||||
result, impErr := h.stockImportService.Import(filename, content, modTime, h.dbUsername, createPricelist, func(p services.StockImportProgress) {
|
||||
// Convert service progress to task progress
|
||||
var progress int
|
||||
if p.Total > 0 {
|
||||
@@ -1048,7 +1052,13 @@ func (h *PricingHandler) ImportStockLog(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Send final completion message
|
||||
progressCb(100, fmt.Sprintf("Импорт завершён: добавлено %d позиций", result.Inserted))
|
||||
var message string
|
||||
if result.WarehousePLID > 0 {
|
||||
message = fmt.Sprintf("Импорт завершён: добавлено %d позиций, создан прайслист %s", result.Inserted, result.WarehousePLVer)
|
||||
} else {
|
||||
message = fmt.Sprintf("Импорт завершён: добавлено %d позиций", result.Inserted)
|
||||
}
|
||||
progressCb(100, message)
|
||||
|
||||
return map[string]interface{}{
|
||||
"rows_total": result.RowsTotal,
|
||||
@@ -1067,6 +1077,7 @@ func (h *PricingHandler) ImportStockLog(c *gin.Context) {
|
||||
}, nil
|
||||
})
|
||||
|
||||
fmt.Printf("[StockImport] Task submitted: task_id=%s, filename=%s, size=%d bytes, create_pricelist=%v\n", taskID, filename, len(content), createPricelist)
|
||||
c.JSON(http.StatusOK, gin.H{"task_id": taskID})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user