ui: update ProductPerformanceProfitability page to enhance table views and tabs management
This commit is contained in:
@@ -676,7 +676,7 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
log.Printf("[ProductPerformanceRefresh] stock mssql query returned, postgres chunk insert start")
|
log.Printf("[ProductPerformanceRefresh] stock mssql query returned, postgres chunk upsert start")
|
||||||
|
|
||||||
const chunkSize = 5000
|
const chunkSize = 5000
|
||||||
count := 0
|
count := 0
|
||||||
@@ -687,11 +687,6 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
copyStmt, err := prepareProductPerformanceStockCopy(ctx, tx)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
defer copyStmt.Close()
|
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var r productPerformanceStockDaily
|
var r productPerformanceStockDaily
|
||||||
@@ -709,35 +704,21 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, err := copyStmt.ExecContext(ctx,
|
if err := insertProductPerformanceStock(ctx, tx, r); err != nil {
|
||||||
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
|
return count, err
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
chunkRows++
|
chunkRows++
|
||||||
if chunkRows >= chunkSize {
|
if chunkRows >= chunkSize {
|
||||||
log.Printf("[ProductPerformanceRefresh] stock chunk commit start inserted_rows=%d scanned_rows=%d", count, seen)
|
log.Printf("[ProductPerformanceRefresh] stock chunk commit start upserted_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 {
|
if err := tx.Commit(); err != nil {
|
||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
log.Printf("[ProductPerformanceRefresh] stock chunk commit done inserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
log.Printf("[ProductPerformanceRefresh] stock chunk commit done upserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||||
tx, err = pg.BeginTx(ctx, nil)
|
tx, err = pg.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
copyStmt, err = prepareProductPerformanceStockCopy(ctx, tx)
|
|
||||||
if err != nil {
|
|
||||||
return count, err
|
|
||||||
}
|
|
||||||
chunkRows = 0
|
chunkRows = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -745,22 +726,15 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
|||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
if chunkRows > 0 {
|
if chunkRows > 0 {
|
||||||
log.Printf("[ProductPerformanceRefresh] stock final chunk commit start inserted_rows=%d scanned_rows=%d", count, seen)
|
log.Printf("[ProductPerformanceRefresh] stock final chunk commit start upserted_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 {
|
if err := tx.Commit(); err != nil {
|
||||||
return count, err
|
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))
|
log.Printf("[ProductPerformanceRefresh] stock final chunk commit done upserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||||
} else {
|
} else {
|
||||||
_ = copyStmt.Close()
|
|
||||||
_ = tx.Rollback()
|
_ = tx.Rollback()
|
||||||
}
|
}
|
||||||
log.Printf("[ProductPerformanceRefresh] stock refresh done inserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
log.Printf("[ProductPerformanceRefresh] stock refresh done upserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user