header-img
Info :
728x90

BEFORE

๋Œ€๊ฐ• ์œ„์™€ ๊ฐ™์€ raw data ๊ฐ€ ์žˆ๋‹ค.

๋‚˜๋Š” front-back ์–‘๋‹จ ๊ฐ€๊ณต์„ ํ†ตํ•ด์„œ ํŠธ๋ฆฌ ํ˜•ํƒœ์˜ ๋ฐ์ดํ„ฐ์— ๋„๋‹ฌํ•˜์—ฌ์•ผ ํ•œ๋‹ค.

์ด๋Ÿฐ ๋ชจ์–‘์ด ๋˜์–ด์•ผ ํ•œ๋‹ค.

 

AFTER

 

ํ”„๋ก ํŠธ ๋‹จ์—์„œ mui treeview ๋ฅผ ์“ธ๊ฑฐ๊ธด ํ•˜์ง€๋งŒ.. ์šฐ์„  ์–ด๋–ป๊ฒŒ ๋ ์ง€ ๋ชฐ๋ผ

level ๊ณผ display_number, PID(Parents ID)๋ฅผ ์ฑ„๋ฒˆํ•˜๋Š” ํ˜•์‹์œผ๋กœ ๋ฐ”๊ฟ”๋‘์—ˆ๋‹ค.

 

json ์œผ๋กœ parent-child ํ˜•์‹์œผ๋กœ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ์ด ๋ฒ ์ŠคํŠธ์ด๊ฒ ์ง€๋งŒ,

mssql ์„ ์–ด๋–ค ์‹์œผ๋กœ ์ฃผ๋ฌผ๋Ÿฌ์•ผ ๊ทธ๋ ‡๊ฒŒ ์™„์„ฑ๋˜๋Š” ์ง€ ์‚ฌ์‹ค ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค..

์ฐพ์•„๋ด๋„ ์˜จํ†ต ํ•˜๋“œ์ฝ”๋”ฉ ํ•˜๋Š” ๊ฒƒ ๋ฟ์ด๊ณ , (์•ฝ 3000๊ฑด์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์–ด๋–ป๊ฒŒ ํ•˜๋“œ์ฝ”๋”ฉ?)

์žฌ๊ท€๋ฅผ ์“ฐ๋”๋ผ๋„ ID ๊ฐ€ ์ฑ„๋ฒˆ๋˜์–ด ์žˆ๋Š” ์ƒํƒœ์—์„œ parentID ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค.

 

๊ณ ๋กœ ๊ฐ€๊ณต์„ ํ•œ๋ฒˆ ํ•ด๋†”์•ผ, ํ”„๋ก ํŠธ์—์„œ ์ฃผ๋ฌด๋ฅด๋˜, ๋ฐฑ์—์„œ ์ฃผ๋ฌด๋ฅด๋˜ ํ•œ๋‹ค๋Š” ๋œป์ด๋‹ค.

๊ทธ๋ž˜์„œ 1์ฐจ ๊ฐ€๊ณต์„ ํ–ˆ๋‹ค.

 

HOW TO ?

-- ์ž„์‹œ ํ…Œ์ด๋ธ” ์ƒ์„ฑ
CREATE TABLE #TEMP_1 ( Company NVARCHAR(10), Plant NVARCHAR(10), Vsm NVARCHAR(10) )
CREATE TABLE #TEMP ( VALUE NVARCHAR(10), LEVEL INT, DISPLAY_NO INT, PID INT )

-- ๊ธฐ๋ณธ์ด ๋˜์–ด์ค„ ์ž„์‹œ ํ…Œ์ด๋ธ”์— ๋ฐ์ดํ„ฐ ๋ชจ์–‘ ๋ฐ”๊ฟ”์„œ ๋ฐ€์–ด๋„ฃ๊ธฐ
INSERT INTO #TEMP_1 SELECT Company, '-', '-' FROM ์›๋ณธํ…Œ์ด๋ธ”๋ช… GROUP BY Company
INSERT INTO #TEMP_1 SELECT Company, Plant, '-' FROM ์›๋ณธํ…Œ์ด๋ธ”๋ช… GROUP BY Company, Plant
INSERT INTO #TEMP_1 SELECT Company, Plant, Vsm FROM ์›๋ณธํ…Œ์ด๋ธ”๋ช… GROUP BY Company, Plant, Vsm

-- ํ•œ๋ฒˆ ์ •๋ฆฌ๋œ #TEMP_1 ์„ ๊ธฐ๋ฐ˜์œผ๋กœ level, display_no, pid ๊ฐ’ ์Œ“์•„์ฃผ๊ธฐ
INSERT INTO #TEMP ( VALUE, LEVEL, DISPLAY_NO, PID )
SELECT Company, 1, (RANK() OVER (ORDER BY Company)) * 1000000, NULL
FROM #TEMP_1 
WHERE Plant = '-'

INSERT INTO #TEMP ( VALUE, LEVEL, DISPLAY_NO, PID )
SELECT A1.Plant, 2, A2.DISPLAY_NO + (RANK() OVER (PARTITION BY A1.Company ORDER BY A1.Plant)) * 1000 , A2.DISPLAY_NO
FROM #TEMP_1 A1 
	LEFT JOIN #TEMP A2 ON A1.Company = A2.VALUE 
WHERE A1.Plant <> '-' AND A1.Vsm = '-' AND A2.LEVEL = 1

INSERT INTO #TEMP ( VALUE, LEVEL, DISPLAY_NO, PID )
SELECT A1.Vsm, 3, A2.DISPLAY_NO + (RANK() OVER (PARTITION BY A1.Company, A1.Plant ORDER BY A1.Vsm)) , A2.DISPLAY_NO
FROM #TEMP_1 A1 
	LEFT JOIN #TEMP A2 ON A1.Plant = A2.VALUE
WHERE A1.Vsm <> '-' AND A2.LEVEL = 2

 

 

 

๋ฐฑ์€ ์ด์ •๋„๋กœ ๊ฐ€๊ณตํ•ด๋‘๊ณ , ํ”„๋ก ํŠธ ๋‹จ์—์„œ

1. level ๊ฐ’ ์‚ฌ์šฉํ•˜์—ฌ์„œ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก treeview์˜ ์ œ๊ณต api ๋ฅผ ์ฐพ๋˜์ง€

2. array ์—๋‹ค๊ฐ€ PID + DISPLAY_NO ์‚ฌ์šฉํ•ด์„œ parent-child ๋ชจ์–‘ ๋งŒ๋“ค์–ด์ฃผ๊ณ , map ๋Œ๋ ค์„œ treeview ์— ๋ฐœ๋ผ์ฃผ๋˜์ง€

 

ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™๋‹ค.

 

์šฐ์„  ์ด ๋ฐฉ๋ฒ• ์ด์•ผ๊ธฐ ํ•œ๋ฒˆ ํ•ด๋ณด๊ณ ... ๊ณ„์† ์ง„ํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด ํ”„๋ก ํŠธ ๋‹จ ๊ฐ€๊ณต๋„ ํฌ์ŠคํŒ… ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ๋‹ค.

 

 

728x90
๋”๋ณด๊ธฐ
BACKEND/MSSQL