From 9ee70eb05a8b6fe7dda3a0d70e6597d55bc1174f Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Tue, 14 Apr 2026 17:52:38 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- svc/queries/orderproduction_items.go | 57 ++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/svc/queries/orderproduction_items.go b/svc/queries/orderproduction_items.go index 63ff05c..d6bcf34 100644 --- a/svc/queries/orderproduction_items.go +++ b/svc/queries/orderproduction_items.go @@ -665,8 +665,19 @@ WHERE Barcode = @p1 return true, nil } -func existingVariantBarcode(q sqlQueryRower, barcodeTypeCode string, itemTypeCode int16, itemCode string, colorCode string, dim1 string, dim2 string, dim3 string) (string, bool, error) { +func existingVariantBarcode( + q sqlQueryRower, + barcodeTypeCode string, + itemTypeCode int16, + itemCode string, + colorCode string, + dim1 string, + dim2 string, + dim3 string, +) (string, bool, error) { + var barcode string + err := q.QueryRow(` SELECT TOP 1 LTRIM(RTRIM(ISNULL(Barcode, ''))) FROM dbo.prItemBarcode WITH (UPDLOCK, HOLDLOCK) @@ -678,23 +689,48 @@ WHERE BarcodeTypeCode = @p1 AND ISNULL(LTRIM(RTRIM(ItemDim2Code)), '') = @p6 AND ISNULL(LTRIM(RTRIM(ItemDim3Code)), '') = @p7 AND ISNULL(LTRIM(RTRIM(UnitOfMeasureCode)), '') = 'AD' -ORDER BY TRY_CONVERT(BIGINT, NULLIF(LTRIM(RTRIM(Barcode)), '')) DESC, Barcode DESC -`, strings.TrimSpace(barcodeTypeCode), itemTypeCode, strings.TrimSpace(itemCode), strings.TrimSpace(colorCode), strings.TrimSpace(dim1), strings.TrimSpace(dim2), strings.TrimSpace(dim3)).Scan(&barcode) +ORDER BY + CASE + WHEN ISNUMERIC(Barcode) = 1 + THEN CAST(Barcode AS BIGINT) + ELSE 0 + END DESC, + Barcode DESC +`, + strings.TrimSpace(barcodeTypeCode), + itemTypeCode, + strings.TrimSpace(itemCode), + strings.TrimSpace(colorCode), + strings.TrimSpace(dim1), + strings.TrimSpace(dim2), + strings.TrimSpace(dim3), + ).Scan(&barcode) + if err == sql.ErrNoRows { return "", false, nil } + if err != nil { return "", false, err } + return strings.TrimSpace(barcode), true, nil } - func maxNumericBarcode(q sqlQueryRower) (int64, error) { + var maxBarcode int64 + err := q.QueryRow(` -SELECT ISNULL(MAX(TRY_CONVERT(BIGINT, NULLIF(LTRIM(RTRIM(Barcode)), ''))), 0) +SELECT ISNULL(MAX( + CASE + WHEN ISNUMERIC(Barcode) = 1 + THEN CAST(Barcode AS BIGINT) + ELSE NULL + END +), 0) FROM dbo.prItemBarcode WITH (UPDLOCK, HOLDLOCK) `).Scan(&maxBarcode) + return maxBarcode, err } @@ -930,9 +966,14 @@ SELECT FROM missing m CROSS JOIN ( - SELECT ISNULL(MAX(TRY_CONVERT(BIGINT, Barcode)),0) MaxBarcode - FROM dbo.prItemBarcode -) seed + SELECT ISNULL(MAX( + CASE + WHEN ISNUMERIC(Barcode)=1 + THEN CAST(Barcode AS BIGINT) + ELSE NULL + END +),0) MaxBarcode +FROM dbo.prItemBarcode `, strings.Join(values, ","), orderHeaderParam, usernameParam, usernameParam) chunkStart := time.Now()