ui: update ProductPerformanceProfitability page to enhance table views and tabs management
This commit is contained in:
@@ -528,6 +528,11 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
||||
return 0, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
copyStmt, err := prepareProductPerformanceStockCopy(ctx, tx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer copyStmt.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var r productPerformanceStockDaily
|
||||
@@ -545,13 +550,23 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := insertProductPerformanceStock(ctx, tx, r); err != nil {
|
||||
if _, err := copyStmt.ExecContext(ctx,
|
||||
r.StockDate, r.ProductCode, r.ColorCode, r.YakaKodu, r.StockQty,
|
||||
r.InQty, r.OutQty, r.KpiInQty, r.KpiOutQty, r.SalesMovementQty,
|
||||
r.ProductionInQty, r.PurchaseInQty, r.ConsumptionOutQty, r.CountDiffQty,
|
||||
); err != nil {
|
||||
return count, err
|
||||
}
|
||||
count++
|
||||
chunkRows++
|
||||
if chunkRows >= chunkSize {
|
||||
log.Printf("[ProductPerformanceRefresh] stock chunk commit start inserted_rows=%d scanned_rows=%d", count, seen)
|
||||
if _, err := copyStmt.ExecContext(ctx); err != nil {
|
||||
return count, err
|
||||
}
|
||||
if err := copyStmt.Close(); err != nil {
|
||||
return count, err
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
return count, err
|
||||
}
|
||||
@@ -560,6 +575,10 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
copyStmt, err = prepareProductPerformanceStockCopy(ctx, tx)
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
chunkRows = 0
|
||||
}
|
||||
}
|
||||
@@ -568,11 +587,18 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
||||
}
|
||||
if chunkRows > 0 {
|
||||
log.Printf("[ProductPerformanceRefresh] stock final chunk commit start inserted_rows=%d scanned_rows=%d", count, seen)
|
||||
if _, err := copyStmt.ExecContext(ctx); err != nil {
|
||||
return count, err
|
||||
}
|
||||
if err := copyStmt.Close(); err != nil {
|
||||
return count, err
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
return count, err
|
||||
}
|
||||
log.Printf("[ProductPerformanceRefresh] stock final chunk commit done inserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||
} else {
|
||||
_ = copyStmt.Close()
|
||||
_ = tx.Rollback()
|
||||
}
|
||||
log.Printf("[ProductPerformanceRefresh] stock refresh done inserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||
@@ -583,6 +609,26 @@ type productPerformanceStockExec interface {
|
||||
ExecContext(context.Context, string, ...any) (sql.Result, error)
|
||||
}
|
||||
|
||||
func prepareProductPerformanceStockCopy(ctx context.Context, tx *sql.Tx) (*sql.Stmt, error) {
|
||||
return tx.PrepareContext(ctx, pq.CopyIn(
|
||||
"mk_product_performance_stock_daily",
|
||||
"stock_date",
|
||||
"product_code",
|
||||
"color_code",
|
||||
"yaka_kodu",
|
||||
"stock_qty",
|
||||
"in_qty",
|
||||
"out_qty",
|
||||
"kpi_in_qty",
|
||||
"kpi_out_qty",
|
||||
"sales_movement_qty",
|
||||
"production_in_qty",
|
||||
"purchase_in_qty",
|
||||
"consumption_out_qty",
|
||||
"count_diff_qty",
|
||||
))
|
||||
}
|
||||
|
||||
func insertProductPerformanceStock(ctx context.Context, exec productPerformanceStockExec, r productPerformanceStockDaily) error {
|
||||
_, err := exec.ExecContext(ctx, `
|
||||
INSERT INTO mk_product_performance_stock_daily (
|
||||
|
||||
Reference in New Issue
Block a user