u
This commit is contained in:
@@ -21,7 +21,7 @@ OUTER APPLY (
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
) first_brand_pic
|
||||
LEFT JOIN pic brand_pic ON brand_pic.id = first_brand_pic.pic_id
|
||||
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
||||
LEFT JOIN article parent ON parent.id = a.parentarticle_id
|
||||
`;
|
||||
|
||||
export const ARTICLE_LIST_COLUMNS = `
|
||||
@@ -32,7 +32,7 @@ export const ARTICLE_LIST_COLUMNS = `
|
||||
pr.net,
|
||||
t.rate AS taxRate,
|
||||
a.track_stock,
|
||||
a.is_father AS isFather,
|
||||
a.is_parent AS isParent,
|
||||
CASE
|
||||
WHEN a.optionslist_id IS NOT NULL THEN (
|
||||
SELECT COUNT(*)
|
||||
@@ -52,10 +52,10 @@ export const ARTICLE_LIST_COLUMNS = `
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM article child
|
||||
WHERE child.fatherarticle_id = a.id
|
||||
WHERE child.parentarticle_id = a.id
|
||||
) AS childCount,
|
||||
a.fatherarticle_id AS fatherArticleId,
|
||||
father.sku AS fatherSku,
|
||||
a.parentarticle_id AS parentArticleId,
|
||||
parent.sku AS parentSku,
|
||||
pic.hash AS fullHash,
|
||||
pic.thumbw AS thumbW,
|
||||
pic.thumbh AS thumbH,
|
||||
@@ -75,7 +75,7 @@ INNER JOIN categoryarticle ca ON ca.article_id = a.id
|
||||
WHERE a.sku = @sku AND (@companyId IS NULL OR a.company_id = @companyId)
|
||||
`;
|
||||
|
||||
/** Resolve an article id by sku (used to wire father/child compound links). */
|
||||
/** Resolve an article id by sku (used to wire parent/child compound links). */
|
||||
export const GET_ID_BY_SKU = `
|
||||
SELECT TOP 1 id AS articleId
|
||||
FROM article
|
||||
@@ -89,49 +89,49 @@ FROM articleean
|
||||
WHERE ean = @ean
|
||||
`;
|
||||
|
||||
/** Link an article to its father article and mark the father. */
|
||||
export const UPDATE_FATHER_BY_SKU = `
|
||||
/** Link an article to its parent article and mark the parent. */
|
||||
export const UPDATE_PARENT_BY_SKU = `
|
||||
UPDATE article
|
||||
SET fatherarticle_id = @fatherArticleId,
|
||||
fathersort = COALESCE(@fathersort, 0)
|
||||
SET parentarticle_id = @parentArticleId,
|
||||
parentsort = COALESCE(@parentsort, 0)
|
||||
WHERE sku = @sku AND (@companyId IS NULL OR company_id = @companyId)
|
||||
`;
|
||||
|
||||
export const SET_IS_FATHER = `
|
||||
export const SET_IS_PARENT = `
|
||||
UPDATE article
|
||||
SET is_father = 1
|
||||
SET is_parent = 1
|
||||
WHERE id = @articleId
|
||||
`;
|
||||
|
||||
export const TOGGLE_FATHER = `
|
||||
export const TOGGLE_PARENT = `
|
||||
UPDATE article
|
||||
SET is_father = @isFather,
|
||||
fatherattributename_id = @fatherAttributeNameId
|
||||
SET is_parent = @isParent,
|
||||
parentattributename_id = @parentAttributeNameId
|
||||
WHERE id = @articleId
|
||||
`;
|
||||
|
||||
export const CREATE_CHILD = `
|
||||
INSERT INTO article (
|
||||
company_id, sku, unit_id, unitamount, weight, track_stock, brand_id, is_father, fatherarticle_id, fathersort
|
||||
company_id, sku, unit_id, unitamount, weight, track_stock, brand_id, is_parent, parentarticle_id, parentsort
|
||||
)
|
||||
OUTPUT INSERTED.id
|
||||
VALUES (
|
||||
@companyId, @sku, @unitId, @unitamount, @weight, @trackStock, @brandId, 0, @fatherArticleId, @fathersort
|
||||
@companyId, @sku, @unitId, @unitamount, @weight, @trackStock, @brandId, 0, @parentArticleId, @parentsort
|
||||
)
|
||||
`;
|
||||
|
||||
export const UNLINK_CHILD = `
|
||||
UPDATE article
|
||||
SET fatherarticle_id = NULL,
|
||||
fathersort = 0
|
||||
WHERE id = @articleId AND fatherarticle_id = @fatherArticleId
|
||||
SET parentarticle_id = NULL,
|
||||
parentsort = 0
|
||||
WHERE id = @articleId AND parentarticle_id = @parentArticleId
|
||||
`;
|
||||
|
||||
export const LIST_CHILDREN_BY_FATHER_ID = `
|
||||
export const LIST_CHILDREN_BY_PARENT_ID = `
|
||||
SELECT
|
||||
child.id,
|
||||
child.sku,
|
||||
child.fathersort,
|
||||
child.parentsort,
|
||||
child.track_stock AS trackStock,
|
||||
child.unitamount,
|
||||
child.weight,
|
||||
@@ -145,14 +145,14 @@ LEFT JOIN (
|
||||
articleattributevalue aav
|
||||
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = @attributeId
|
||||
) ON aav.article_id = child.id
|
||||
WHERE child.fatherarticle_id = @fatherArticleId
|
||||
ORDER BY child.fathersort ASC, child.id ASC
|
||||
WHERE child.parentarticle_id = @parentArticleId
|
||||
ORDER BY child.parentsort ASC, child.id ASC
|
||||
`;
|
||||
|
||||
export const SET_FATHER_SORT = `
|
||||
export const SET_PARENT_SORT = `
|
||||
UPDATE article
|
||||
SET fathersort = @fathersort
|
||||
WHERE id = @articleId AND fatherarticle_id = @fatherArticleId
|
||||
SET parentsort = @parentsort
|
||||
WHERE id = @articleId AND parentarticle_id = @parentArticleId
|
||||
`;
|
||||
|
||||
/** SKU → article/category + company auth in one round-trip. */
|
||||
@@ -484,19 +484,19 @@ SELECT
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM article child
|
||||
WHERE child.fatherarticle_id = a.id
|
||||
WHERE child.parentarticle_id = a.id
|
||||
) AS childCount,
|
||||
a.is_father AS isFather,
|
||||
a.fatherattributename_id AS fatherAttributeNameId,
|
||||
fan.name AS fatherAttributeName,
|
||||
fan.exclusive AS fatherAttributeExclusive,
|
||||
a.fatherarticle_id AS fatherArticleId,
|
||||
fa.sku AS fatherSku,
|
||||
a.is_parent AS isParent,
|
||||
a.parentattributename_id AS parentAttributeNameId,
|
||||
fan.name AS parentAttributeName,
|
||||
fan.exclusive AS parentAttributeExclusive,
|
||||
a.parentarticle_id AS parentArticleId,
|
||||
fa.sku AS parentSku,
|
||||
(
|
||||
SELECT
|
||||
child.id,
|
||||
child.sku,
|
||||
child.fathersort,
|
||||
child.parentsort,
|
||||
at_child.name,
|
||||
av.id AS attributeValueId,
|
||||
av.value AS attributeValue
|
||||
@@ -504,10 +504,10 @@ SELECT
|
||||
LEFT JOIN articletext at_child ON at_child.article_id = child.id AND at_child.language_id = auth.languageId
|
||||
LEFT JOIN (
|
||||
articleattributevalue aav
|
||||
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = a.fatherattributename_id
|
||||
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = a.parentattributename_id
|
||||
) ON aav.article_id = child.id
|
||||
WHERE child.fatherarticle_id = a.id
|
||||
ORDER BY child.fathersort ASC, child.id ASC
|
||||
WHERE child.parentarticle_id = a.id
|
||||
ORDER BY child.parentsort ASC, child.id ASC
|
||||
FOR JSON PATH
|
||||
) AS childrenJson,
|
||||
(
|
||||
@@ -637,8 +637,8 @@ SELECT
|
||||
ORDER BY bp2.sort ASC, bp2.id ASC
|
||||
) first_brand_pic
|
||||
LEFT JOIN pic bp ON bp.id = first_brand_pic.pic_id
|
||||
LEFT JOIN article fa ON fa.id = a.fatherarticle_id
|
||||
LEFT JOIN attributename fan ON fan.id = a.fatherattributename_id
|
||||
LEFT JOIN article fa ON fa.id = a.parentarticle_id
|
||||
LEFT JOIN attributename fan ON fan.id = a.parentattributename_id
|
||||
WHERE a.id = auth.articleId
|
||||
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
|
||||
) AS articleJson
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
export const GET_CHILD_COUNT = `
|
||||
SELECT COUNT(*) AS count
|
||||
FROM article
|
||||
WHERE fatherarticle_id = @articleId
|
||||
WHERE parentarticle_id = @articleId
|
||||
`;
|
||||
|
||||
export const GET_CHILDREN_IDS = `
|
||||
SELECT id
|
||||
FROM article
|
||||
WHERE fatherarticle_id = @id
|
||||
WHERE parentarticle_id = @id
|
||||
`;
|
||||
|
||||
export const GET_LIST_IDS = `
|
||||
|
||||
@@ -36,10 +36,10 @@ export const ARTICLE_DETAIL_COLUMNS = `
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM article child
|
||||
WHERE child.fatherarticle_id = a.id
|
||||
WHERE child.parentarticle_id = a.id
|
||||
) AS childCount,
|
||||
a.fatherarticle_id AS fatherArticleId,
|
||||
father.sku AS fatherSku
|
||||
a.parentarticle_id AS parentArticleId,
|
||||
parent.sku AS parentSku
|
||||
`;
|
||||
|
||||
export const GET_DETAIL_BY_SKU = `
|
||||
@@ -59,7 +59,7 @@ OUTER APPLY (
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
) first_brand_pic
|
||||
LEFT JOIN pic brand_pic ON brand_pic.id = first_brand_pic.pic_id
|
||||
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
||||
LEFT JOIN article parent ON parent.id = a.parentarticle_id
|
||||
WHERE a.sku = @sku AND (@companyId IS NULL OR a.company_id = @companyId)
|
||||
`;
|
||||
|
||||
@@ -80,7 +80,7 @@ OUTER APPLY (
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
) first_brand_pic
|
||||
LEFT JOIN pic brand_pic ON brand_pic.id = first_brand_pic.pic_id
|
||||
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
||||
LEFT JOIN article parent ON parent.id = a.parentarticle_id
|
||||
WHERE a.id = @articleId
|
||||
`;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ FROM categoryarticle ca
|
||||
INNER JOIN article a ON a.id = ca.article_id
|
||||
${ARTICLE_LIST_JOINS}
|
||||
WHERE ca.category_id = @categoryId
|
||||
AND a.fatherarticle_id IS NULL
|
||||
AND a.parentarticle_id IS NULL
|
||||
ORDER BY a.id
|
||||
`;
|
||||
|
||||
|
||||
@@ -109,10 +109,10 @@ VALUES (
|
||||
)
|
||||
`;
|
||||
|
||||
export const CHECK_ARTICLE_IS_FATHER = `
|
||||
export const CHECK_ARTICLE_IS_PARENT = `
|
||||
SELECT
|
||||
a.id,
|
||||
a.is_father AS isFather,
|
||||
a.is_parent AS isParent,
|
||||
COALESCE(
|
||||
(SELECT at.name FROM articletext at WHERE at.article_id = a.id AND at.language_id = co.default_language_id),
|
||||
(SELECT MIN(at2.name) FROM articletext at2 WHERE at2.article_id = a.id),
|
||||
|
||||
@@ -253,7 +253,7 @@ SELECT TOP (@limit)
|
||||
SELECT TOP 1 p2.hash
|
||||
FROM articlepic ap2
|
||||
INNER JOIN pic p2 ON p2.id = ap2.pic_id
|
||||
WHERE a.fatherarticle_id IS NOT NULL AND ap2.article_id = a.fatherarticle_id
|
||||
WHERE a.parentarticle_id IS NOT NULL AND ap2.article_id = a.parentarticle_id
|
||||
ORDER BY ap2.sort ASC, ap2.id ASC
|
||||
)
|
||||
) AS imgHash,
|
||||
@@ -263,15 +263,15 @@ SELECT TOP (@limit)
|
||||
WHERE ae.article_id = a.id
|
||||
ORDER BY ae.id ASC
|
||||
) AS barcode,
|
||||
a.is_father AS isParent,
|
||||
a.fatherarticle_id AS parentArticleId,
|
||||
a.is_parent AS isParent,
|
||||
a.parentarticle_id AS parentArticleId,
|
||||
(
|
||||
SELECT TOP 1 CONCAT(fan.name, '|', av.value, '|', fan.sort, '|', a.fathersort)
|
||||
SELECT TOP 1 CONCAT(fan.name, '|', av.value, '|', fan.sort, '|', a.parentsort)
|
||||
FROM article fa
|
||||
INNER JOIN attributename fan ON fan.id = fa.fatherattributename_id
|
||||
INNER JOIN attributename fan ON fan.id = fa.parentattributename_id
|
||||
INNER JOIN articleattributevalue aav ON aav.article_id = a.id
|
||||
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = fan.id
|
||||
WHERE a.fatherarticle_id IS NOT NULL AND fa.id = a.fatherarticle_id
|
||||
WHERE a.parentarticle_id IS NOT NULL AND fa.id = a.parentarticle_id
|
||||
) AS variantName,
|
||||
CASE
|
||||
WHEN a.articlelist_id IS NOT NULL AND EXISTS (
|
||||
|
||||
@@ -323,10 +323,10 @@ BEGIN
|
||||
brand_id INT NULL,
|
||||
articlelist_id INT NULL,
|
||||
optionslist_id INT NULL,
|
||||
is_father BIT NOT NULL CONSTRAINT DF_article_is_father DEFAULT 0,
|
||||
fatherarticle_id INT NULL,
|
||||
fatherattributename_id INT NULL,
|
||||
fathersort INT NOT NULL CONSTRAINT DF_article_fathersort DEFAULT 0,
|
||||
is_parent BIT NOT NULL CONSTRAINT DF_article_is_parent DEFAULT 0,
|
||||
parentarticle_id INT NULL,
|
||||
parentattributename_id INT NULL,
|
||||
parentsort INT NOT NULL CONSTRAINT DF_article_parentsort DEFAULT 0,
|
||||
created_at DATETIME2 NOT NULL CONSTRAINT DF_article_created_at DEFAULT SYSUTCDATETIME(),
|
||||
updated_at DATETIME2 NOT NULL CONSTRAINT DF_article_updated_at DEFAULT SYSUTCDATETIME(),
|
||||
CONSTRAINT FK_article_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE NO ACTION,
|
||||
@@ -334,23 +334,23 @@ BEGIN
|
||||
CONSTRAINT FK_article_brand FOREIGN KEY (brand_id) REFERENCES brand(id) ON DELETE SET NULL,
|
||||
CONSTRAINT FK_article_articlelist FOREIGN KEY (articlelist_id) REFERENCES articlelist(id) ON DELETE SET NULL,
|
||||
CONSTRAINT FK_article_optionslist FOREIGN KEY (optionslist_id) REFERENCES optionslist(id) ON DELETE SET NULL,
|
||||
CONSTRAINT FK_article_fatherarticle FOREIGN KEY (fatherarticle_id) REFERENCES article(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT FK_article_fatherattributename FOREIGN KEY (fatherattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT FK_article_parentarticle FOREIGN KEY (parentarticle_id) REFERENCES article(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT FK_article_parentattributename FOREIGN KEY (parentattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT UQ_article_company_sku UNIQUE (company_id, sku)
|
||||
);
|
||||
|
||||
-- Only enforce sibling sort uniqueness among children of the same father.
|
||||
-- Only enforce sibling sort uniqueness among children of the same parent.
|
||||
-- (SQL Server UNIQUE treats NULLs as equal, which would block multiple root articles.)
|
||||
CREATE UNIQUE INDEX UQ_article_fatherarticle_fathersort
|
||||
ON article (fatherarticle_id, fathersort)
|
||||
WHERE fatherarticle_id IS NOT NULL;
|
||||
CREATE UNIQUE INDEX UQ_article_parentarticle_parentsort
|
||||
ON article (parentarticle_id, parentsort)
|
||||
WHERE parentarticle_id IS NOT NULL;
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('article') AND name = 'fatherattributename_id')
|
||||
IF NOT EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('article') AND name = 'parentattributename_id')
|
||||
BEGIN
|
||||
ALTER TABLE article ADD fatherattributename_id INT NULL;
|
||||
ALTER TABLE article ADD CONSTRAINT FK_article_fatherattributename FOREIGN KEY (fatherattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION;
|
||||
ALTER TABLE article ADD parentattributename_id INT NULL;
|
||||
ALTER TABLE article ADD CONSTRAINT FK_article_parentattributename FOREIGN KEY (parentattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION;
|
||||
END
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('article') AND name = 'track_stock')
|
||||
|
||||
@@ -434,9 +434,9 @@ export class BetterSqlite3Provider extends BetterSqlite3Executor {
|
||||
`ALTER TABLE article ADD COLUMN track_stock INTEGER NOT NULL DEFAULT 1`,
|
||||
);
|
||||
}
|
||||
if (articleCols.length > 0 && !articleCols.includes('fatherattributename_id')) {
|
||||
if (articleCols.length > 0 && !articleCols.includes('parentattributename_id')) {
|
||||
this.db.exec(
|
||||
`ALTER TABLE article ADD COLUMN fatherattributename_id INTEGER REFERENCES attributename(id) ON DELETE NO ACTION`,
|
||||
`ALTER TABLE article ADD COLUMN parentattributename_id INTEGER REFERENCES attributename(id) ON DELETE NO ACTION`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ export const {
|
||||
DELETE_CATEGORIES_BY_ARTICLE, DELETE_EANS_BY_ARTICLE, EAN_EXISTS,
|
||||
GET_BRAND_BY_COMPANY_AND_ID,
|
||||
GET_CATEGORY_ID_BY_SKU, GET_CATEGORY_TREE_FLAT, GET_ID_BY_SKU,
|
||||
LIST_CHILDREN_BY_FATHER_ID,
|
||||
SET_FATHER_SORT,
|
||||
SET_IS_FATHER, TOGGLE_FATHER, UNLINK_CHILD, UPDATE_BRAND, UPDATE_FATHER_BY_SKU, UPDATE_TRACK_STOCK, UPDATE_UNIT,
|
||||
LIST_CHILDREN_BY_PARENT_ID,
|
||||
SET_PARENT_SORT,
|
||||
SET_IS_PARENT, TOGGLE_PARENT, UNLINK_CHILD, UPDATE_BRAND, UPDATE_PARENT_BY_SKU, UPDATE_TRACK_STOCK, UPDATE_UNIT,
|
||||
UPDATE_UNITAMOUNT, UPDATE_UNIT_AND_AMOUNT, UPDATE_WEIGHT,
|
||||
} = queries;
|
||||
|
||||
@@ -30,7 +30,7 @@ LEFT JOIN pic brand_pic ON brand_pic.id = (
|
||||
SELECT bp.pic_id FROM brandpic bp
|
||||
WHERE bp.brand_id = b.id ORDER BY bp.sort, bp.id LIMIT 1
|
||||
)
|
||||
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
||||
LEFT JOIN article parent ON parent.id = a.parentarticle_id
|
||||
`;
|
||||
|
||||
export const RESOLVE_ARTICLE_ACCESS_BY_SKU = `
|
||||
@@ -160,16 +160,16 @@ SELECT auth.*,
|
||||
LEFT JOIN articletext at_item ON at_item.article_id = a_item.id AND at_item.language_id = auth.languageId
|
||||
WHERE ala.articlelist_id = a.articlelist_id
|
||||
ORDER BY ala.sort ASC, ala.id ASC)),
|
||||
'childCount', (SELECT COUNT(*) FROM article WHERE fatherarticle_id = a.id),
|
||||
'isFather', a.is_father,
|
||||
'fatherAttributeNameId', a.fatherattributename_id,
|
||||
'fatherAttributeName', fan.name,
|
||||
'fatherAttributeExclusive', fan.exclusive,
|
||||
'fatherArticleId', a.fatherarticle_id, 'fatherSku', father.sku,
|
||||
'childCount', (SELECT COUNT(*) FROM article WHERE parentarticle_id = a.id),
|
||||
'isParent', a.is_parent,
|
||||
'parentAttributeNameId', a.parentattributename_id,
|
||||
'parentAttributeName', fan.name,
|
||||
'parentAttributeExclusive', fan.exclusive,
|
||||
'parentArticleId', a.parentarticle_id, 'parentSku', parent.sku,
|
||||
'childrenJson', json((SELECT COALESCE(json_group_array(json_object(
|
||||
'id', child.id,
|
||||
'sku', child.sku,
|
||||
'fathersort', child.fathersort,
|
||||
'parentsort', child.parentsort,
|
||||
'name', at_child.name,
|
||||
'attributeValueId', av.id,
|
||||
'attributeValue', av.value
|
||||
@@ -177,10 +177,10 @@ SELECT auth.*,
|
||||
LEFT JOIN articletext at_child ON at_child.article_id = child.id AND at_child.language_id = auth.languageId
|
||||
LEFT JOIN (
|
||||
articleattributevalue aav
|
||||
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = a.fatherattributename_id
|
||||
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = a.parentattributename_id
|
||||
) ON aav.article_id = child.id
|
||||
WHERE child.fatherarticle_id = a.id
|
||||
ORDER BY child.fathersort ASC, child.id ASC)),
|
||||
WHERE child.parentarticle_id = a.id
|
||||
ORDER BY child.parentsort ASC, child.id ASC)),
|
||||
'categoryIdsJson', json(${JSON_CATEGORIES}),
|
||||
'photosJson', json((SELECT COALESCE(json_group_array(json_object(
|
||||
'sort', sort, 'fullHash', hash, 'fullW', w, 'fullH', h,
|
||||
@@ -270,6 +270,6 @@ LEFT JOIN brand b ON b.id = a.brand_id
|
||||
LEFT JOIN pic bp ON bp.id = (
|
||||
SELECT pic_id FROM brandpic WHERE brand_id = b.id ORDER BY sort, id LIMIT 1
|
||||
)
|
||||
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
||||
LEFT JOIN attributename fan ON fan.id = a.fatherattributename_id
|
||||
LEFT JOIN article parent ON parent.id = a.parentarticle_id
|
||||
LEFT JOIN attributename fan ON fan.id = a.parentattributename_id
|
||||
`;
|
||||
@@ -19,7 +19,7 @@ LEFT JOIN pic brand_pic ON brand_pic.id = (
|
||||
WHERE bp.brand_id = b.id
|
||||
ORDER BY bp.sort, bp.id LIMIT 1
|
||||
)
|
||||
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
||||
LEFT JOIN article parent ON parent.id = a.parentarticle_id
|
||||
`;
|
||||
|
||||
export const GET_DETAIL_BY_SKU = `
|
||||
|
||||
@@ -65,7 +65,7 @@ FROM categoryarticle ca
|
||||
INNER JOIN article a ON a.id = ca.article_id
|
||||
${ARTICLE_LIST_JOINS}
|
||||
WHERE ca.category_id = @categoryId
|
||||
AND a.fatherarticle_id IS NULL
|
||||
AND a.parentarticle_id IS NULL
|
||||
ORDER BY a.id
|
||||
`;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { translateQueries } from './translate.js';
|
||||
|
||||
const queries = translateQueries(source, 'manifestDoc');
|
||||
export const {
|
||||
CHECK_ARTICLE_IS_FATHER, CREATE_LINE, CREATE_MANIFEST, DELETE_LINES_BY_MANIFEST,
|
||||
CHECK_ARTICLE_IS_PARENT, CREATE_LINE, CREATE_MANIFEST, DELETE_LINES_BY_MANIFEST,
|
||||
DELETE_MANIFEST, GET_MANIFEST_HEADER, GET_MANIFEST_LINES, LIST_MANIFESTS,
|
||||
ORDER_TYPE, QUOTE_TYPE, UPDATE_MANIFEST,
|
||||
} = queries;
|
||||
@@ -78,7 +78,7 @@ SELECT
|
||||
SELECT p2.hash
|
||||
FROM articlepic ap2
|
||||
INNER JOIN pic p2 ON p2.id = ap2.pic_id
|
||||
WHERE a.fatherarticle_id IS NOT NULL AND ap2.article_id = a.fatherarticle_id
|
||||
WHERE a.parentarticle_id IS NOT NULL AND ap2.article_id = a.parentarticle_id
|
||||
ORDER BY ap2.sort ASC, ap2.id ASC
|
||||
LIMIT 1
|
||||
)
|
||||
@@ -90,15 +90,15 @@ SELECT
|
||||
ORDER BY ae.id ASC
|
||||
LIMIT 1
|
||||
) AS barcode,
|
||||
a.is_father AS isParent,
|
||||
a.fatherarticle_id AS parentArticleId,
|
||||
a.is_parent AS isParent,
|
||||
a.parentarticle_id AS parentArticleId,
|
||||
(
|
||||
SELECT fan.name || '|' || av.value || '|' || fan.sort || '|' || a.fathersort
|
||||
SELECT fan.name || '|' || av.value || '|' || fan.sort || '|' || a.parentsort
|
||||
FROM article fa
|
||||
INNER JOIN attributename fan ON fan.id = fa.fatherattributename_id
|
||||
INNER JOIN attributename fan ON fan.id = fa.parentattributename_id
|
||||
INNER JOIN articleattributevalue aav ON aav.article_id = a.id
|
||||
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = fan.id
|
||||
WHERE a.fatherarticle_id IS NOT NULL AND fa.id = a.fatherarticle_id
|
||||
WHERE a.parentarticle_id IS NOT NULL AND fa.id = a.parentarticle_id
|
||||
LIMIT 1
|
||||
) AS variantName,
|
||||
CASE
|
||||
|
||||
@@ -222,10 +222,10 @@ CREATE TABLE IF NOT EXISTS article (
|
||||
brand_id INTEGER,
|
||||
articlelist_id INTEGER,
|
||||
optionslist_id INTEGER,
|
||||
is_father INTEGER NOT NULL DEFAULT 0,
|
||||
fatherarticle_id INTEGER,
|
||||
fathersort INTEGER NOT NULL DEFAULT 0,
|
||||
fatherattributename_id INTEGER,
|
||||
is_parent INTEGER NOT NULL DEFAULT 0,
|
||||
parentarticle_id INTEGER,
|
||||
parentsort INTEGER NOT NULL DEFAULT 0,
|
||||
parentattributename_id INTEGER,
|
||||
created_at TEXT NOT NULL DEFAULT (${UTC_NOW}),
|
||||
updated_at TEXT NOT NULL DEFAULT (${UTC_NOW}),
|
||||
UNIQUE (company_id, sku),
|
||||
@@ -234,12 +234,12 @@ CREATE TABLE IF NOT EXISTS article (
|
||||
FOREIGN KEY (brand_id) REFERENCES brand(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (articlelist_id) REFERENCES articlelist(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (optionslist_id) REFERENCES optionslist(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (fatherarticle_id) REFERENCES article(id) ON DELETE NO ACTION,
|
||||
FOREIGN KEY (fatherattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION
|
||||
FOREIGN KEY (parentarticle_id) REFERENCES article(id) ON DELETE NO ACTION,
|
||||
FOREIGN KEY (parentattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS UQ_article_fatherarticle_fathersort
|
||||
ON article(fatherarticle_id, fathersort)
|
||||
WHERE fatherarticle_id IS NOT NULL;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS UQ_article_parentarticle_parentsort
|
||||
ON article(parentarticle_id, parentsort)
|
||||
WHERE parentarticle_id IS NOT NULL;
|
||||
`;
|
||||
|
||||
export const INIT_ARTICLEEAN = `
|
||||
|
||||
Reference in New Issue
Block a user