Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-04-02 16:30:19 +03:00
parent 7a98652a8e
commit 028c11e042
10 changed files with 783 additions and 175 deletions

View File

@@ -29,13 +29,26 @@ function logApiError (action, err, payload = null) {
})
}
function nowMs () {
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
return performance.now()
}
return Date.now()
}
export const useOrderProductionItemStore = defineStore('orderproductionitems', {
state: () => ({
items: [],
header: null,
products: [],
colorOptionsByCode: {},
newColorOptionsByCode: {},
secondColorOptionsByKey: {},
newSecondColorOptionsByKey: {},
colorRequestsByCode: {},
newColorRequestsByCode: {},
secondColorRequestsByKey: {},
newSecondColorRequestsByKey: {},
productAttributesByItemType: {},
cdItemLookups: null,
cdItemDraftsByCode: {},
@@ -127,16 +140,57 @@ export const useOrderProductionItemStore = defineStore('orderproductionitems', {
if (this.colorOptionsByCode[code]) {
return this.colorOptionsByCode[code]
}
if (this.colorRequestsByCode[code]) {
return this.colorRequestsByCode[code]
}
try {
const res = await api.get('/product-colors', { params: { code } })
const data = res?.data
const list = Array.isArray(data) ? data : []
this.colorOptionsByCode[code] = list
return list
this.colorRequestsByCode[code] = (async () => {
const t0 = nowMs()
console.info('[OrderProductionItemStore] fetchColors start', { code })
const res = await api.get('/product-colors', { params: { code } })
const data = res?.data
const list = Array.isArray(data) ? data : []
this.colorOptionsByCode[code] = list
console.info('[OrderProductionItemStore] fetchColors done', { code, count: list.length, durationMs: Math.round(nowMs() - t0) })
return list
})()
return await this.colorRequestsByCode[code]
} catch (err) {
this.error = err?.response?.data || err?.message || 'Renk listesi alinamadi'
return []
} finally {
delete this.colorRequestsByCode[code]
}
},
async fetchNewColors (productCode) {
const code = String(productCode || '').trim()
if (!code) return []
if (this.newColorOptionsByCode[code]) {
return this.newColorOptionsByCode[code]
}
if (this.newColorRequestsByCode[code]) {
return this.newColorRequestsByCode[code]
}
try {
this.newColorRequestsByCode[code] = (async () => {
const t0 = nowMs()
console.info('[OrderProductionItemStore] fetchNewColors start', { code })
const res = await api.get('/product-newcolors', { params: { code } })
const data = res?.data
const list = Array.isArray(data) ? data : []
this.newColorOptionsByCode[code] = list
console.info('[OrderProductionItemStore] fetchNewColors done', { code, count: list.length, durationMs: Math.round(nowMs() - t0) })
return list
})()
return await this.newColorRequestsByCode[code]
} catch (err) {
this.error = err?.response?.data || err?.message || 'Yeni urun renk listesi alinamadi'
return []
} finally {
delete this.newColorRequestsByCode[code]
}
},
async fetchSecondColors (productCode, colorCode) {
@@ -148,16 +202,59 @@ export const useOrderProductionItemStore = defineStore('orderproductionitems', {
if (this.secondColorOptionsByKey[key]) {
return this.secondColorOptionsByKey[key]
}
if (this.secondColorRequestsByKey[key]) {
return this.secondColorRequestsByKey[key]
}
try {
const res = await api.get('/product-secondcolor', { params: { code, color } })
const data = res?.data
const list = Array.isArray(data) ? data : []
this.secondColorOptionsByKey[key] = list
return list
this.secondColorRequestsByKey[key] = (async () => {
const t0 = nowMs()
console.info('[OrderProductionItemStore] fetchSecondColors start', { code, color })
const res = await api.get('/product-secondcolor', { params: { code, color } })
const data = res?.data
const list = Array.isArray(data) ? data : []
this.secondColorOptionsByKey[key] = list
console.info('[OrderProductionItemStore] fetchSecondColors done', { code, color, count: list.length, durationMs: Math.round(nowMs() - t0) })
return list
})()
return await this.secondColorRequestsByKey[key]
} catch (err) {
this.error = err?.response?.data || err?.message || '2. renk listesi alinamadi'
return []
} finally {
delete this.secondColorRequestsByKey[key]
}
},
async fetchNewSecondColors (productCode, colorCode) {
const code = String(productCode || '').trim()
const color = String(colorCode || '').trim()
if (!code || !color) return []
const key = `${code}::${color}`
if (this.newSecondColorOptionsByKey[key]) {
return this.newSecondColorOptionsByKey[key]
}
if (this.newSecondColorRequestsByKey[key]) {
return this.newSecondColorRequestsByKey[key]
}
try {
this.newSecondColorRequestsByKey[key] = (async () => {
const t0 = nowMs()
console.info('[OrderProductionItemStore] fetchNewSecondColors start', { code, color })
const res = await api.get('/product-newsecondcolor', { params: { code, color } })
const data = res?.data
const list = Array.isArray(data) ? data : []
this.newSecondColorOptionsByKey[key] = list
console.info('[OrderProductionItemStore] fetchNewSecondColors done', { code, color, count: list.length, durationMs: Math.round(nowMs() - t0) })
return list
})()
return await this.newSecondColorRequestsByKey[key]
} catch (err) {
this.error = err?.response?.data || err?.message || 'Yeni urun 2. renk listesi alinamadi'
return []
} finally {
delete this.newSecondColorRequestsByKey[key]
}
},
async fetchProductAttributes (itemTypeCode = 1) {
@@ -231,11 +328,22 @@ export const useOrderProductionItemStore = defineStore('orderproductionitems', {
this.error = null
try {
const t0 = nowMs()
console.info('[OrderProductionItemStore] validateUpdates start', { orderHeaderID, lineCount: lines?.length || 0 })
const res = await api.post(
`/orders/production-items/${encodeURIComponent(orderHeaderID)}/validate`,
{ lines }
)
return res?.data || { missingCount: 0, missing: [] }
const data = res?.data || { missingCount: 0, missing: [] }
const rid = res?.headers?.['x-debug-request-id'] || ''
console.info('[OrderProductionItemStore] validateUpdates done', {
orderHeaderID,
lineCount: lines?.length || 0,
missingCount: Number(data?.missingCount || 0),
requestId: rid,
durationMs: Math.round(nowMs() - t0)
})
return data
} catch (err) {
logApiError('validateUpdates', err, { orderHeaderID, lineCount: lines?.length || 0 })
this.error = extractApiErrorMessage(err, 'Kontrol basarisiz')
@@ -251,11 +359,29 @@ export const useOrderProductionItemStore = defineStore('orderproductionitems', {
this.error = null
try {
const t0 = nowMs()
console.info('[OrderProductionItemStore] applyUpdates start', {
orderHeaderID,
lineCount: lines?.length || 0,
insertMissing: !!insertMissing,
cdItemCount: cdItems?.length || 0,
attributeCount: productAttributes?.length || 0
})
const res = await api.post(
`/orders/production-items/${encodeURIComponent(orderHeaderID)}/apply`,
{ lines, insertMissing, cdItems, productAttributes }
)
return res?.data || { updated: 0, inserted: 0 }
const data = res?.data || { updated: 0, inserted: 0 }
const rid = res?.headers?.['x-debug-request-id'] || ''
console.info('[OrderProductionItemStore] applyUpdates done', {
orderHeaderID,
updated: Number(data?.updated || 0),
inserted: Number(data?.inserted || 0),
attributeUpserted: Number(data?.attributeUpserted || 0),
requestId: rid,
durationMs: Math.round(nowMs() - t0)
})
return data
} catch (err) {
logApiError('applyUpdates', err, { orderHeaderID, lineCount: lines?.length || 0, insertMissing })
this.error = extractApiErrorMessage(err, 'Guncelleme basarisiz')