v3.5.4版本提交,修改api
CI / verify (pull_request) Waiting to run

This commit is contained in:
2026-08-21 16:22:53 +08:00
parent a01217539c
commit 62e61a9e63
21 changed files with 594 additions and 142 deletions
@@ -5,6 +5,30 @@
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const PREFIX = 'DK';
const PAD = 6;
const RE = /^DK(\d+)$/;
async function nextDkCode() {
const [items, skus] = await Promise.all([
prisma.commonProductItem.findMany({
where: { skuCode: { startsWith: PREFIX } },
select: { skuCode: true },
}),
prisma.commonProductSku.findMany({
where: { skuCode: { startsWith: PREFIX } },
select: { skuCode: true },
}),
]);
let maxSeq = 0;
for (const row of [...items, ...skus]) {
const m = RE.exec(row.skuCode);
if (!m) continue;
const n = Number(m[1]);
if (Number.isFinite(n) && n > maxSeq) maxSeq = n;
}
return `${PREFIX}${String(maxSeq + 1).padStart(PAD, '0')}`;
}
async function main() {
const products = await prisma.commonProductItem.findMany({
@@ -13,10 +37,11 @@ async function main() {
let created = 0;
for (const p of products) {
if (p.skus.length > 0) continue;
const skuCode = RE.test(p.skuCode) ? p.skuCode : await nextDkCode();
await prisma.commonProductSku.create({
data: {
productId: p.id,
skuCode: p.skuCode,
skuCode,
barcode69: p.barcode69,
specKey: '',
specText: p.spec,
@@ -32,8 +57,14 @@ async function main() {
sortOrder: 0,
},
});
if (p.skuCode !== skuCode) {
await prisma.commonProductItem.update({
where: { id: p.id },
data: { skuCode },
});
}
created += 1;
console.log(`created default sku for product ${p.id} ${p.skuCode}`);
console.log(`created default sku for product ${p.id} ${skuCode}`);
}
console.log(`done, created=${created}, scanned=${products.length}`);
}