u
This commit is contained in:
@@ -13,6 +13,14 @@ OUTER APPLY (
|
||||
ORDER BY ap.sort ASC, ap.id ASC
|
||||
) first_pic
|
||||
LEFT JOIN pic ON pic.id = first_pic.pic_id
|
||||
LEFT JOIN brand b ON b.id = a.brand_id
|
||||
OUTER APPLY (
|
||||
SELECT TOP 1 bp.pic_id
|
||||
FROM brandpic bp
|
||||
WHERE bp.brand_id = b.id
|
||||
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
|
||||
`;
|
||||
|
||||
@@ -49,7 +57,13 @@ export const ARTICLE_LIST_COLUMNS = `
|
||||
pic.hash AS fullHash,
|
||||
pic.thumbw AS thumbW,
|
||||
pic.thumbh AS thumbH,
|
||||
pic.thumbhash AS thumbHash
|
||||
pic.thumbhash AS thumbHash,
|
||||
b.id AS brandId,
|
||||
b.name AS brandName,
|
||||
brand_pic.hash AS brandFullHash,
|
||||
brand_pic.thumbw AS brandThumbW,
|
||||
brand_pic.thumbh AS brandThumbH,
|
||||
brand_pic.thumbhash AS brandThumbHash
|
||||
`;
|
||||
|
||||
export const GET_CATEGORY_ID_BY_SKU = `
|
||||
@@ -362,7 +376,9 @@ SELECT
|
||||
u.basesifactor AS unitBasesifactor,
|
||||
ut.symbol AS unitSymbol,
|
||||
ut.name AS unitName,
|
||||
b.id AS brandId,
|
||||
b.name AS brandName,
|
||||
bp.hash AS brandFullHash,
|
||||
bp.thumbw AS brandThumbW,
|
||||
bp.thumbh AS brandThumbH,
|
||||
bp.thumbhash AS brandThumbHash,
|
||||
|
||||
@@ -10,7 +10,9 @@ export const ARTICLE_DETAIL_COLUMNS = `
|
||||
u.basesifactor AS unitBasesifactor,
|
||||
ut.symbol AS unitSymbol,
|
||||
ut.name AS unitName,
|
||||
b.id AS brandId,
|
||||
b.name AS brandName,
|
||||
brand_pic.hash AS brandFullHash,
|
||||
brand_pic.thumbw AS brandThumbW,
|
||||
brand_pic.thumbh AS brandThumbH,
|
||||
brand_pic.thumbhash AS brandThumbHash,
|
||||
|
||||
@@ -1,21 +1,49 @@
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
gsprpinfo
|
||||
FROM brand
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY name
|
||||
b.id,
|
||||
b.name,
|
||||
b.gsprpinfo,
|
||||
(
|
||||
SELECT
|
||||
bp.id,
|
||||
bp.sort,
|
||||
p.hash AS fullHash,
|
||||
p.thumbw AS thumbW,
|
||||
p.thumbh AS thumbH,
|
||||
p.thumbhash AS thumbHash
|
||||
FROM brandpic bp
|
||||
INNER JOIN pic p ON p.id = bp.pic_id
|
||||
WHERE bp.brand_id = b.id
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
FOR JSON PATH
|
||||
) AS picsJson
|
||||
FROM brand b
|
||||
WHERE b.company_id = @companyId
|
||||
ORDER BY b.name
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_NAME = `
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
gsprpinfo
|
||||
FROM brand
|
||||
WHERE company_id = @companyId
|
||||
AND name = @name
|
||||
b.id,
|
||||
b.name,
|
||||
b.gsprpinfo,
|
||||
(
|
||||
SELECT
|
||||
bp.id,
|
||||
bp.sort,
|
||||
p.hash AS fullHash,
|
||||
p.thumbw AS thumbW,
|
||||
p.thumbh AS thumbH,
|
||||
p.thumbhash AS thumbHash
|
||||
FROM brandpic bp
|
||||
INNER JOIN pic p ON p.id = bp.pic_id
|
||||
WHERE bp.brand_id = b.id
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
FOR JSON PATH
|
||||
) AS picsJson
|
||||
FROM brand b
|
||||
WHERE b.company_id = @companyId
|
||||
AND b.name = @name
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
@@ -34,3 +62,13 @@ export const DELETE_BY_COMPANY_AND_ID = `
|
||||
DELETE FROM brand
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const GET_BY_ID_AND_COMPANY = `
|
||||
SELECT
|
||||
b.id,
|
||||
b.company_id,
|
||||
b.name,
|
||||
b.gsprpinfo
|
||||
FROM brand b
|
||||
WHERE b.id = @id AND b.company_id = @companyId
|
||||
`;
|
||||
|
||||
23
src/providers/mssql/queries/brandpic.js
Normal file
23
src/providers/mssql/queries/brandpic.js
Normal file
@@ -0,0 +1,23 @@
|
||||
export const GET_NEXT_SORT = `
|
||||
SELECT ISNULL(MAX(sort), -1) + 1 AS sort
|
||||
FROM brandpic
|
||||
WHERE brand_id = @brandId
|
||||
`;
|
||||
|
||||
export const ADD = `
|
||||
INSERT INTO brandpic (brand_id, pic_id, sort)
|
||||
VALUES (@brandId, @picId, @sort)
|
||||
`;
|
||||
|
||||
export const DELETE_BY_BRAND = `
|
||||
DELETE FROM brandpic
|
||||
WHERE brand_id = @brandId
|
||||
`;
|
||||
|
||||
export const GET_FIRST_PIC_BY_BRAND = `
|
||||
SELECT TOP 1 p.id AS picId, p.thumbw AS thumbW, p.thumbh AS thumbH, p.thumbhash AS thumbHash
|
||||
FROM brandpic bp
|
||||
INNER JOIN pic p ON p.id = bp.pic_id
|
||||
WHERE bp.brand_id = @brandId
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
`;
|
||||
@@ -23,6 +23,15 @@ FROM (
|
||||
FROM pic p
|
||||
INNER JOIN categorypic cp ON cp.pic_id = p.id
|
||||
WHERE p.hash = @hash
|
||||
|
||||
UNION
|
||||
|
||||
SELECT c.category_id AS categoryId
|
||||
FROM pic p
|
||||
INNER JOIN brandpic bp ON bp.pic_id = p.id
|
||||
INNER JOIN brand b ON b.id = bp.brand_id
|
||||
INNER JOIN company c ON c.id = b.company_id
|
||||
WHERE p.hash = @hash
|
||||
) AS combined
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user