From b1a3bbd3c583d2c54014dcaf9da35719da79286f Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Sat, 4 Apr 2026 19:04:59 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- svc/queries/orderproduction_items.go | 10 +++ svc/routes/orderproductionitems.go | 6 ++ svc/routes/productattributes.go | 29 +++++++- ...g.js.temporary.compiled.1775318047003.mjs} | 0 ui/src/pages/OrderProductionUpdate.vue | 74 +++++++++++++++++-- 5 files changed, 110 insertions(+), 9 deletions(-) rename ui/{quasar.config.js.temporary.compiled.1775136347383.mjs => quasar.config.js.temporary.compiled.1775318047003.mjs} (100%) diff --git a/svc/queries/orderproduction_items.go b/svc/queries/orderproduction_items.go index fb8b008..eb82113 100644 --- a/svc/queries/orderproduction_items.go +++ b/svc/queries/orderproduction_items.go @@ -210,7 +210,9 @@ func InsertMissingVariantsTx( username string, cdItemByCode map[string]models.OrderProductionCdItemDraft, ) (int64, error) { + start := time.Now() if len(missing) == 0 { + log.Printf("[InsertMissingVariantsTx] missing=0 inserted=0 duration_ms=0") return 0, nil } @@ -332,6 +334,8 @@ WHERE pv.ItemCode IS NULL; if rows, rowsErr := res.RowsAffected(); rowsErr == nil { inserted += rows } + log.Printf("[InsertMissingVariantsTx] missing=%d unique=%d ensuredItems=%d inserted=%d duration_ms=%d", + len(missing), len(uniqueVariants), len(ensuredItems), inserted, time.Since(start).Milliseconds()) return inserted, nil } @@ -571,7 +575,9 @@ WHERE l.OrderHeaderID = @p%d; } func UpsertItemAttributesTx(tx *sql.Tx, attrs []models.OrderProductionItemAttributeRow, username string) (int64, error) { + start := time.Now() if len(attrs) == 0 { + log.Printf("[UpsertItemAttributesTx] attrs=0 affected=0 duration_ms=0") return 0, nil } @@ -658,7 +664,11 @@ SELECT (@updated + @inserted) AS Affected; return affected, err } affected += chunkAffected + log.Printf("[UpsertItemAttributesTx] chunk=%d-%d chunkAffected=%d cumulative=%d", + i, end, chunkAffected, affected) } + log.Printf("[UpsertItemAttributesTx] attrs=%d affected=%d duration_ms=%d", + len(attrs), affected, time.Since(start).Milliseconds()) return affected, nil } diff --git a/svc/routes/orderproductionitems.go b/svc/routes/orderproductionitems.go index 47c91bd..6b1f5cd 100644 --- a/svc/routes/orderproductionitems.go +++ b/svc/routes/orderproductionitems.go @@ -169,6 +169,8 @@ func OrderProductionValidateRoute(mssql *sql.DB) http.Handler { http.Error(w, err.Error(), http.StatusBadRequest) return } + log.Printf("[OrderProductionValidateRoute] rid=%s orderHeaderID=%s payload lineCount=%d insertMissing=%t cdItemCount=%d attributeCount=%d", + rid, id, len(payload.Lines), payload.InsertMissing, len(payload.CdItems), len(payload.ProductAttributes)) stepStart := time.Now() missing, err := buildMissingVariants(mssql, id, payload.Lines) @@ -216,6 +218,8 @@ func OrderProductionApplyRoute(mssql *sql.DB) http.Handler { http.Error(w, err.Error(), http.StatusBadRequest) return } + log.Printf("[OrderProductionApplyRoute] rid=%s orderHeaderID=%s payload lineCount=%d insertMissing=%t cdItemCount=%d attributeCount=%d", + rid, id, len(payload.Lines), payload.InsertMissing, len(payload.CdItems), len(payload.ProductAttributes)) stepMissingStart := time.Now() missing, err := buildMissingVariants(mssql, id, payload.Lines) @@ -317,6 +321,8 @@ func OrderProductionApplyRoute(mssql *sql.DB) http.Handler { "inserted": inserted, "attributeUpserted": attributeAffected, } + log.Printf("[OrderProductionApplyRoute] rid=%s orderHeaderID=%s result updated=%d inserted=%d attributeUpserted=%d", + rid, id, updated, inserted, attributeAffected) if err := json.NewEncoder(w).Encode(resp); err != nil { log.Printf("❌ encode error: %v", err) } diff --git a/svc/routes/productattributes.go b/svc/routes/productattributes.go index 6205186..1dd8b60 100644 --- a/svc/routes/productattributes.go +++ b/svc/routes/productattributes.go @@ -6,11 +6,15 @@ import ( "bssapp-backend/models" "bssapp-backend/queries" "encoding/json" + "log" "net/http" "strconv" + "strings" + "time" ) func GetProductAttributesHandler(w http.ResponseWriter, r *http.Request) { + start := time.Now() claims, ok := auth.GetClaimsFromContext(r.Context()) if !ok || claims == nil { http.Error(w, "unauthorized", http.StatusUnauthorized) @@ -26,9 +30,12 @@ func GetProductAttributesHandler(w http.ResponseWriter, r *http.Request) { } itemTypeCode = int16(v) } + log.Printf("[GetProductAttributes] start user=%s itemTypeCode=%d", claims.Username, itemTypeCode) rows, err := db.MssqlDB.Query(queries.GetProductAttributes, itemTypeCode) if err != nil { + log.Printf("[GetProductAttributes] query_error user=%s itemTypeCode=%d err=%v duration_ms=%d", + claims.Username, itemTypeCode, err, time.Since(start).Milliseconds()) http.Error(w, "Product attributes alinamadi: "+err.Error(), http.StatusInternalServerError) return } @@ -48,12 +55,21 @@ func GetProductAttributesHandler(w http.ResponseWriter, r *http.Request) { } list = append(list, x) } + if err := rows.Err(); err != nil { + log.Printf("[GetProductAttributes] rows_error user=%s itemTypeCode=%d err=%v duration_ms=%d", + claims.Username, itemTypeCode, err, time.Since(start).Milliseconds()) + http.Error(w, "Product attributes okunamadi: "+err.Error(), http.StatusInternalServerError) + return + } w.Header().Set("Content-Type", "application/json; charset=utf-8") _ = json.NewEncoder(w).Encode(list) + log.Printf("[GetProductAttributes] done user=%s itemTypeCode=%d count=%d duration_ms=%d", + claims.Username, itemTypeCode, len(list), time.Since(start).Milliseconds()) } func GetProductItemAttributesHandler(w http.ResponseWriter, r *http.Request) { + start := time.Now() claims, ok := auth.GetClaimsFromContext(r.Context()) if !ok || claims == nil { http.Error(w, "unauthorized", http.StatusUnauthorized) @@ -70,14 +86,17 @@ func GetProductItemAttributesHandler(w http.ResponseWriter, r *http.Request) { itemTypeCode = int16(v) } - itemCode := r.URL.Query().Get("itemCode") + itemCode := strings.TrimSpace(r.URL.Query().Get("itemCode")) if itemCode == "" { http.Error(w, "itemCode zorunlu", http.StatusBadRequest) return } + log.Printf("[GetProductItemAttributes] start user=%s itemTypeCode=%d itemCode=%s", claims.Username, itemTypeCode, itemCode) rows, err := db.MssqlDB.Query(queries.GetProductItemAttributes, itemTypeCode, itemCode) if err != nil { + log.Printf("[GetProductItemAttributes] query_error user=%s itemTypeCode=%d itemCode=%s err=%v duration_ms=%d", + claims.Username, itemTypeCode, itemCode, err, time.Since(start).Milliseconds()) http.Error(w, "Product item attributes alinamadi: "+err.Error(), http.StatusInternalServerError) return } @@ -95,7 +114,15 @@ func GetProductItemAttributesHandler(w http.ResponseWriter, r *http.Request) { } list = append(list, x) } + if err := rows.Err(); err != nil { + log.Printf("[GetProductItemAttributes] rows_error user=%s itemTypeCode=%d itemCode=%s err=%v duration_ms=%d", + claims.Username, itemTypeCode, itemCode, err, time.Since(start).Milliseconds()) + http.Error(w, "Product item attributes okunamadi: "+err.Error(), http.StatusInternalServerError) + return + } w.Header().Set("Content-Type", "application/json; charset=utf-8") _ = json.NewEncoder(w).Encode(list) + log.Printf("[GetProductItemAttributes] done user=%s itemTypeCode=%d itemCode=%s count=%d duration_ms=%d", + claims.Username, itemTypeCode, itemCode, len(list), time.Since(start).Milliseconds()) } diff --git a/ui/quasar.config.js.temporary.compiled.1775136347383.mjs b/ui/quasar.config.js.temporary.compiled.1775318047003.mjs similarity index 100% rename from ui/quasar.config.js.temporary.compiled.1775136347383.mjs rename to ui/quasar.config.js.temporary.compiled.1775318047003.mjs diff --git a/ui/src/pages/OrderProductionUpdate.vue b/ui/src/pages/OrderProductionUpdate.vue index 6a3afd0..b1991fd 100644 --- a/ui/src/pages/OrderProductionUpdate.vue +++ b/ui/src/pages/OrderProductionUpdate.vue @@ -895,18 +895,19 @@ async function saveCdItemDraft () { function buildAttributeRowsFromLookup (list) { const grouped = new Map() for (const it of (list || [])) { - const typeCode = Number(it?.attribute_type_code || 0) + const typeCode = Number(it?.attribute_type_code || it?.AttributeTypeCode || 0) if (!typeCode) continue if (!grouped.has(typeCode)) { grouped.set(typeCode, { typeCode, - typeDesc: String(it?.attribute_type_description || '').trim() || String(typeCode), + typeDesc: String(it?.attribute_type_description || it?.AttributeTypeDescription || '').trim() || String(typeCode), options: [] }) } const g = grouped.get(typeCode) - const code = String(it?.attribute_code || '').trim() - const desc = String(it?.attribute_description || '').trim() + const code = String(it?.attribute_code || it?.AttributeCode || '').trim() + const desc = String(it?.attribute_description || it?.AttributeDescription || '').trim() + if (!code) continue g.options.push({ value: code, label: `${code} - ${desc || code}` @@ -963,7 +964,7 @@ function mergeAttributeDraftWithLookupOptions (draftRows, lookupRows) { const allOptions = baseAllOptions.length ? baseAllOptions : draftAllOptions if (selectedCode && !allOptions.some(opt => String(opt?.value || '').trim() === selectedCode)) { - allOptions.unshift({ value: selectedCode, label: `${selectedCode} - (Secili)` }) + allOptions.unshift({ value: selectedCode, label: selectedCode }) } return { @@ -982,14 +983,24 @@ async function openAttributeDialog (itemCode) { if (!code) return attributeTargetCode.value = code const existingDraft = store.getProductAttributeDraft(code) + const modeInfo = store.classifyItemCode(code) const fetched = await store.fetchProductAttributes(1) const fromLookup = buildAttributeRowsFromLookup(fetched) + console.info('[OrderProductionUpdate] openAttributeDialog lookup', { + code, + mode: modeInfo.mode, + fetchedCount: Array.isArray(fetched) ? fetched.length : 0, + rowCount: fromLookup.length + }) if (!fromLookup.length) { $q.notify({ type: 'negative', message: 'Urun ozellikleri listesi alinamadi. Lutfen daha sonra tekrar deneyin.' }) return } - const modeInfo = store.classifyItemCode(code) const dbCurrent = await store.fetchProductItemAttributes(code, 1, true) + console.info('[OrderProductionUpdate] openAttributeDialog dbCurrent', { + code, + dbCurrentCount: Array.isArray(dbCurrent) ? dbCurrent.length : 0 + }) const dbMap = new Map( (dbCurrent || []).map(x => [ @@ -1004,7 +1015,7 @@ async function openAttributeDialog (itemCode) { ? [...row.AllOptions] : (Array.isArray(row.Options) ? [...row.Options] : []) if (currentCode && !currentOptions.some(opt => String(opt?.value || '').trim() === currentCode)) { - currentOptions.unshift({ value: currentCode, label: `${currentCode} - (Mevcut)` }) + currentOptions.unshift({ value: currentCode, label: currentCode }) } return { ...row, @@ -1019,6 +1030,18 @@ async function openAttributeDialog (itemCode) { attributeRows.value = useDraft ? JSON.parse(JSON.stringify(mergeAttributeDraftWithLookupOptions(existingDraft, baseRows))) : JSON.parse(JSON.stringify(baseRows)) + console.info('[OrderProductionUpdate] openAttributeDialog rowsPrepared', { + code, + mode: modeInfo.mode, + useDraft, + rowCount: Array.isArray(attributeRows.value) ? attributeRows.value.length : 0, + optionCounts: (attributeRows.value || []).map(r => ({ + type: Number(r?.AttributeTypeCodeNumber || 0), + options: Array.isArray(r?.Options) ? r.Options.length : 0, + allOptions: Array.isArray(r?.AllOptions) ? r.AllOptions.length : 0, + selected: String(r?.AttributeCode || '').trim() + })) + }) for (const row of (attributeRows.value || [])) { if (!Array.isArray(row.AllOptions)) { row.AllOptions = Array.isArray(row.Options) ? [...row.Options] : [] @@ -1046,6 +1069,14 @@ function saveAttributeDraft () { } } store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(attributeRows.value || []))) + console.info('[OrderProductionUpdate] saveAttributeDraft', { + code, + rowCount: (attributeRows.value || []).length, + selected: (attributeRows.value || []).map(r => ({ + type: Number(r?.AttributeTypeCodeNumber || 0), + code: String(r?.AttributeCode || '').trim() + })) + }) attributeDialogOpen.value = false $q.notify({ type: 'positive', message: 'Urun ozellikleri taslagi kaydedildi.' }) } @@ -1062,6 +1093,11 @@ async function collectProductAttributesFromSelectedRows (selectedRows) { const modeInfo = store.classifyItemCode(code) let rows = store.getProductAttributeDraft(code) let dbMap = new Map() + console.info('[OrderProductionUpdate] collectProductAttributes start', { + code, + mode: modeInfo.mode, + draftRowCount: Array.isArray(rows) ? rows.length : 0 + }) if (modeInfo.mode === 'existing') { const dbCurrent = await store.fetchProductItemAttributes(code, 1, true) @@ -1077,13 +1113,18 @@ async function collectProductAttributesFromSelectedRows (selectedRows) { if (!Array.isArray(rows) || !rows.length) { const lookup = await store.fetchProductAttributes(1) const baseRows = buildAttributeRowsFromLookup(lookup) + console.info('[OrderProductionUpdate] collectProductAttributes existing refetch', { + code, + lookupCount: Array.isArray(lookup) ? lookup.length : 0, + baseRowCount: baseRows.length + }) rows = baseRows.map(row => { const currentCode = dbMap.get(Number(row.AttributeTypeCodeNumber || 0)) || '' const currentOptions = Array.isArray(row.AllOptions) ? [...row.AllOptions] : (Array.isArray(row.Options) ? [...row.Options] : []) if (currentCode && !currentOptions.some(opt => String(opt?.value || '').trim() === currentCode)) { - currentOptions.unshift({ value: currentCode, label: `${currentCode} - (Mevcut)` }) + currentOptions.unshift({ value: currentCode, label: currentCode }) } return { ...row, @@ -1109,6 +1150,12 @@ async function collectProductAttributesFromSelectedRows (selectedRows) { ...row, AttributeCode: dbMap.get(Number(row.AttributeTypeCodeNumber || 0)) || '' })) + console.info('[OrderProductionUpdate] collectProductAttributes new init', { + code, + lookupCount: Array.isArray(lookup) ? lookup.length : 0, + baseRowCount: baseRows.length, + dbCurrentCount: Array.isArray(dbCurrent) ? dbCurrent.length : 0 + }) store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(rows))) } @@ -1143,6 +1190,17 @@ async function collectProductAttributesFromSelectedRows (selectedRows) { AttributeCode: attributeCode }) } + console.info('[OrderProductionUpdate] collectProductAttributes done', { + code, + mode: modeInfo.mode, + outCount: out.filter(x => x.ItemCode === code).length, + rowCount: rows.length, + optionCounts: rows.map(r => ({ + type: Number(r?.AttributeTypeCodeNumber || 0), + options: Array.isArray(r?.Options) ? r.Options.length : 0, + allOptions: Array.isArray(r?.AllOptions) ? r.AllOptions.length : 0 + })) + }) } return { errMsg: '', productAttributes: out } }