From da4c358e0f3659c5fa56a24386b6079f9d31356c Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Tue, 4 May 2021 17:32:14 +0900 Subject: [PATCH 01/12] =?UTF-8?q?feat:=20=EB=A7=88=EA=B0=90=ED=95=9C=20?= =?UTF-8?q?=EB=AC=B8=EC=84=9C=EB=A5=BC=20=EC=9E=84=EC=8B=9C=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EB=A9=B4=20=EB=A7=88=EA=B0=90=20=EC=9C=A0?= =?UTF-8?q?=EB=AC=B4=EB=A5=BC=200=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/B3.ctrl.js | 46 +++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/api/inspectionDocs/B3.ctrl.js b/api/inspectionDocs/B3.ctrl.js index fa80639..e019980 100644 --- a/api/inspectionDocs/B3.ctrl.js +++ b/api/inspectionDocs/B3.ctrl.js @@ -68,8 +68,6 @@ exports.inspection = async (req, res) => { const pool = await sql.connect(config); const { recordset: CERTNO } = await pool.request().query`SELECT dbo.GD_F_NO('CT','002001', ${CERTDT}, ${ID})`; - const { recordset: RcvNos } = await pool.request().query`SELECT RcvNo FROM GRCV_CT WHERE (RcvNo = ${RCVNO})`; - const RcvNo = RcvNos.map(({ RcvNo }) => RcvNo)[0]; const { type } = req.params; @@ -77,15 +75,25 @@ exports.inspection = async (req, res) => { jwt.verify(token, process.env.JWT_SECRET); if (type === 'save') { // 임시저장 시 GRCV_CT 테이블에 데이터 삽입 - await pool.request().query` - UPDATE GRCV_CT SET CERT_NO = ${CERTNO[0]['']}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RcvNo} AND Doc_No = 'B3') + const { recordset: magamYn } = await pool.request().query` + UPDATE GRCV_CT SET CERT_NO = ${H.CERTNO || CERTNO[0]['']}, UP_ID = ${ID}, UP_DT = getDate() + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B3') + + SELECT MagamYn FROM GRCV_CT + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B3') `; + + if (magamYn[0].MagamYn) { + await pool.request().query` + UPDATE GRCV_CT SET MagamYn = 0, MagamDt = '' + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B3') + `; + } } else { // complete -> 검사완료 시 GRCV_CT 테이블에 데이터 삽입 await pool.request().query` - UPDATE GRCV_CT SET MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RcvNo} AND Doc_No = 'B3') + UPDATE GRCV_CT SET Cert_No = ${H.CERTNO || CERTNO[0]['']}, MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B3') `; } @@ -98,7 +106,7 @@ exports.inspection = async (req, res) => { when matched then update set UP_ID = ${ID}, UP_DT = GetDate() when not matched then - insert (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) values(${CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); + insert (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) values(${H.CERTNO || CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); `; Object.values(D1).forEach(async (v, i) => { @@ -106,11 +114,11 @@ exports.inspection = async (req, res) => { merge into GSVC_B3_D1 using(values (1)) as Source (Number) - on (CERTNO = ${CERTNO[0]['']} and CERTSEQ = ${i + 1}) + on (CERTNO = ${H.CERTNO || CERTNO[0]['']} and CERTSEQ = ${i + 1}) when matched and (Unit != ${v.Unit} or Remark != ${v.Remark} or Value != ${v.Value}) then update set UP_ID = ${ID}, UP_DT = GetDate(), Value = ${v.Value}, Unit = ${v.Unit}, Remark = ${v.Remark} when not matched then - insert (CERTNO, CERTSEQ, Value, Unit, Remark, IN_ID, UP_ID) values(${CERTNO[0]['']}, ${i + 1}, ${v.Value}, ${v.Unit}, ${ + insert (CERTNO, CERTSEQ, Value, Unit, Remark, IN_ID, UP_ID) values(${H.CERTNO || CERTNO[0]['']}, ${i + 1}, ${v.Value}, ${v.Unit}, ${ v.Remark }, ${ID}, ${ID}); `; @@ -120,7 +128,7 @@ exports.inspection = async (req, res) => { await pool.request().query`merge into GSVC_B3_D2 using(values (1)) as Source (Number) - on (CERTNO = ${CERTNO[0]['']} and CERTSEQ = ${i + 1}) + on (CERTNO = ${H.CERTNO || CERTNO[0]['']} and CERTSEQ = ${i + 1}) when matched and (CarriedOut != ${v.CarriedOut.toString()} or NotCarried != ${v.NotCarried.toString()} or NotApp != ${v.NotApp.toString()} or Comm != ${ v.Comm }) then @@ -128,9 +136,9 @@ exports.inspection = async (req, res) => { v.Comm }, UP_ID = ${ID}, UP_DT = GetDate() when not matched then - insert (CERTNO, CERTSEQ, CarriedOut, NotCarried, NotApp, Comm, IN_ID, UP_ID) values(${CERTNO[0]['']}, ${i + 1}, ${v.CarriedOut}, ${ - v.NotCarried - }, ${v.NotApp}, ${v.Comm}, ${ID}, ${ID}); + insert (CERTNO, CERTSEQ, CarriedOut, NotCarried, NotApp, Comm, IN_ID, UP_ID) values(${H.CERTNO || CERTNO[0]['']}, ${i + 1}, ${ + v.CarriedOut + }, ${v.NotCarried}, ${v.NotApp}, ${v.Comm}, ${ID}, ${ID}); `; }); @@ -138,11 +146,13 @@ exports.inspection = async (req, res) => { merge into GSVC_B3_D3 using (values(1)) as Source (Number) - on (CERTNO = ${CERTNO[0]['']}) - when matched and (Value1 != ${D3[0]} or Value2 != ${D3[1]} or Value3 != ${D3[2]}) then - update set Value1 = ${D3[0]}, Value2 = ${D3[1]}, Value3 = ${D3[2]}, UP_ID = ${ID}, UP_DT = GetDate() + on (CERTNO = ${H.CERTNO || CERTNO[0]['']}) + when matched and (Value1 != ${D3[0]} or Value2 != ${D3[1]} or Value3 != ${D3[2]} or Value4 != ${D3[3]}) then + update set Value1 = ${D3[0]}, Value2 = ${D3[1]}, Value3 = ${D3[2]}, Value4 = ${D3[3]}, UP_ID = ${ID}, UP_DT = GetDate() when not matched then - insert (CERTNO, CERTSEQ, Value1, Value2, Value3, IN_ID, UP_ID) values(${CERTNO[0]['']}, 1, ${D3[0]}, ${D3[1]}, ${D3[2]}, ${ID}, ${ID}); + insert (CERTNO, CERTSEQ, Value1, Value2, Value3, Value4, IN_ID, UP_ID) values(${CERTNO[0]['']}, 1, ${D3[0]}, ${D3[1]}, ${D3[2]}, ${ + D3[3] + }, ${ID}, ${ID}); `; res.status(200).send(); From 0ff64baedce0fb45f5061e3527880500844237ca Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Thu, 6 May 2021 17:58:04 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20=EB=AC=B8=EC=84=9C=20C=20GET=20AP?= =?UTF-8?q?I=20=EB=9D=BC=EC=9A=B0=ED=84=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/inspectionDocs/index.js b/api/inspectionDocs/index.js index aaea30f..217095a 100644 --- a/api/inspectionDocs/index.js +++ b/api/inspectionDocs/index.js @@ -49,7 +49,9 @@ router.get('/B3', B3.details); router.post('/B1/inspection/:type', B1.inspection); router.post('/B3/inspection/:type', B3.inspection); +// C router.post('/C/inspection/:type', C.inspection); +router.get('/C', C.details); router.post('/F/inspection/:type', F.inspection); router.post('/F2/inspection/:type', F2.inspection); From 4a8cfa7db6b372c52eaf3efc9421020ad9864728 Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Thu, 6 May 2021 17:58:19 +0900 Subject: [PATCH 03/12] =?UTF-8?q?fix:=20=EB=AC=B8=EC=84=9C=20C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/C.ctrl.js | 51 +++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/api/inspectionDocs/C.ctrl.js b/api/inspectionDocs/C.ctrl.js index 5b14814..9762c99 100644 --- a/api/inspectionDocs/C.ctrl.js +++ b/api/inspectionDocs/C.ctrl.js @@ -12,18 +12,25 @@ exports.details = async (req, res) => { const pool = await sql.connect(config); const { recordset: D1 } = await pool.request().query` - SELECT GSVC_C_D1.Value FROM GSVC_C_D1 - WHERE GSVC_C_D1.CERTNO = ${ct} + SELECT Value FROM GSVC_C_D1 + WHERE CERTNO = ${ct} `; const { recordset: D2 } = await pool.request().query` - SELECT GSVC_C_D2.Value FROM GSVC_C_D2 - WHERE GSVC_C_D2.CERTNO = ${ct} + SELECT CarriedOut, NotCarried, NotApp, Comm FROM GSVC_C_D2 + WHERE CERTNO = ${ct} `; const D1arr = D1.map((item, i) => ({ [i]: item.Value })); const D1obj = D1arr.reduce((a, c) => ({ ...a, ...c }), {}); - const D2arr = D2.map((item, i) => ({ [i]: +item.Value })); + const D2arr = D2.map((item, i) => ({ + [i]: { + CarriedOut: +item.CarriedOut, + NotCarried: +item.NotCarried, + NotApp: +item.NotApp, + Comm: item.Comm, + }, + })); const D2obj = D2arr.reduce((a, c) => ({ ...a, ...c }), {}); res.json({ @@ -46,8 +53,6 @@ exports.inspection = async (req, res) => { const pool = await sql.connect(config); const { recordset: CERTNO } = await pool.request().query`SELECT dbo.GD_F_NO('CT','002001', ${CERTDT}, ${ID})`; - const { recordset: RcvNos } = await pool.request().query`SELECT RcvNo FROM GRCV_CT WHERE (RcvNo = ${RCVNO})`; - const RcvNo = RcvNos.map(({ RcvNo }) => RcvNo)[0]; const { type } = req.params; @@ -55,15 +60,25 @@ exports.inspection = async (req, res) => { jwt.verify(token, process.env.JWT_SECRET); if (type === 'save') { // 임시저장 시 GRCV_CT 테이블에 데이터 삽입 - await pool.request().query` - UPDATE GRCV_CT SET CERT_NO = ${CERTNO[0]['']}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RcvNo} AND Doc_No = 'C') + const { recordset: magamYn } = await pool.request().query` + UPDATE GRCV_CT SET CERT_NO = ${H.CERTNO || CERTNO[0]['']}, UP_ID = ${ID}, UP_DT = getDate() + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C') + + SELECT MagamYn FROM GRCV_CT + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C') + `; + + if (magamYn[0].MagamYn) { + await pool.request().query` + UPDATE GRCV_CT SET MagamYn = 0, MagamDt = '' + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C') `; + } } else { // complete -> 검사완료 시 GRCV_CT 테이블에 데이터 삽입 await pool.request().query` UPDATE GRCV_CT SET MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RcvNo} AND Doc_No = 'C') + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C') `; } @@ -76,7 +91,7 @@ exports.inspection = async (req, res) => { when matched then update set UP_ID = ${ID}, UP_DT = GetDate() when not matched then - insert (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) values(${CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); + insert (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) values(${H.CERTNO || CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); `; Object.values(D1).forEach(async (v, i) => { @@ -84,11 +99,11 @@ exports.inspection = async (req, res) => { merge into GSVC_C_D1 using(values (1)) as Source (Number) - on (CERTNO = ${CERTNO[0]['']} and CERTSEQ = ${i + 1}) + on (CERTNO = ${H.CERTNO || CERTNO[0]['']} and CERTSEQ = ${i + 1}) when matched and (Value != ${v}) then update set Value = ${v}, UP_ID = ${ID}, UP_DT = GetDate() when not matched then - insert (CERTNO, CERTSEQ, Value, IN_ID, UP_ID) values(${CERTNO[0]['']}, ${i + 1}, ${v}, ${ID}, ${ID}); + insert (CERTNO, CERTSEQ, Value, IN_ID, UP_ID) values(${H.CERTNO || CERTNO[0]['']}, ${i + 1}, ${v}, ${ID}, ${ID}); `; }); @@ -96,7 +111,7 @@ exports.inspection = async (req, res) => { await pool.request().query`merge into GSVC_C_D2 using(values (1)) as Source (Number) - on (CERTNO = ${CERTNO[0]['']} and CERTSEQ = ${i + 1}) + on (CERTNO = ${H.CERTNO || CERTNO[0]['']} and CERTSEQ = ${i + 1}) when matched and (CarriedOut != ${v.CarriedOut.toString()} or NotCarried != ${v.NotCarried.toString()} or NotApp != ${v.NotApp.toString()} or Comm != ${ v.Comm }) then @@ -104,9 +119,9 @@ exports.inspection = async (req, res) => { v.Comm }, UP_ID = ${ID}, UP_DT = GetDate() when not matched then - insert (CERTNO, CERTSEQ, CarriedOut, NotCarried, NotApp, Comm, IN_ID, UP_ID) values(${CERTNO[0]['']}, ${i + 1}, ${v.CarriedOut}, ${ - v.NotCarried - }, ${v.NotApp}, ${v.Comm}, ${ID}, ${ID}); + insert (CERTNO, CERTSEQ, CarriedOut, NotCarried, NotApp, Comm, IN_ID, UP_ID) values(${H.CERTNO || CERTNO[0]['']}, ${i + 1}, ${ + v.CarriedOut + }, ${v.NotCarried}, ${v.NotApp}, ${v.Comm}, ${ID}, ${ID}); `; }); From f5b89275ab7bdc2801dd3a40e54b511724f4367c Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Fri, 7 May 2021 18:37:02 +0900 Subject: [PATCH 04/12] =?UTF-8?q?fix:=20=EB=8F=99=EC=A0=81=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=B6=94=EA=B0=80=EB=90=98=EB=8A=94=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/B1.ctrl.js | 72 +++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/api/inspectionDocs/B1.ctrl.js b/api/inspectionDocs/B1.ctrl.js index dafb209..9e82a9d 100644 --- a/api/inspectionDocs/B1.ctrl.js +++ b/api/inspectionDocs/B1.ctrl.js @@ -57,6 +57,7 @@ exports.inspection = async (req, res) => { try { jwt.verify(token, process.env.JWT_SECRET); if (type === 'save') { + // 마감 한 문서 => 임시 저장 => 임시 저장 문서로 변경 const { recordset: magamYn } = await pool.request().query` UPDATE GRCV_CT SET CERT_NO = ${H.CERTNO || CERTNO[0]['']}, UP_ID = ${ID}, UP_DT = getDate() WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') @@ -64,20 +65,26 @@ exports.inspection = async (req, res) => { SELECT MagamYn FROM GRCV_CT WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') `; - - if (magamYn[0].MagamYn) { + const { recordset: magam } = await pool.request().query` + SELECT MagamYn FROM GRCV_CT + WHERE (RcvNo = 'SN2012050002' AND Doc_No = 'B1') + `; + // 완료한 문서를 임시 저장하면 magam을 다시 0으로 + if (magamYn[0].MagamYn === '1') { await pool.request().query` UPDATE GRCV_CT SET MagamYn = 0, MagamDt = '' WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') `; } } else { + // 검사 완료 await pool.request().query` UPDATE GRCV_CT SET Cert_No = ${H.CERTNO || CERTNO[0]['']}, MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') `; } + // B1_H await pool.request().query` MERGE INTO GSVC_B1_H USING (values(1)) @@ -86,29 +93,52 @@ exports.inspection = async (req, res) => { WHEN MATCHED THEN UPDATE SET UP_ID = ${ID}, UP_DT = getDate() WHEN NOT MATCHED THEN - INSERT (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) VALUES(${CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); + INSERT (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) VALUES(${H.CERTNO || CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); + `; + + // request로 받지 않은 내용은 행 삭제를 해야 한다. + let insertDt = ''; + if (H.CERTNO) { + const { recordset: insertInfo } = await pool.request().query` + SELECT IN_DT FROM GSVC_B1_D1 + WHERE (CERTNO = ${H.CERTNO} AND CERTSEQ = 1) `; + insertDt = insertInfo[0].IN_DT; + + await pool.request().query` + SELECT * FROM GSVC_B1_D1 WHERE CERTNO = ${H.CERTNO} + + BEGIN TRAN + DELETE FROM GSVC_B1_D1 WHERE CERTNO = ${H.CERTNO} + SELECT * FROM GSVC_B1_D1 WHERE CERTNO = ${H.CERTNO} + COMMIT TRAN + `; + } Object.values(D1).forEach(async (v, i) => { - const TestDt = new Date(v.TestDt.substring(0, 10)).toFormat('MMM.YY'); + const { GasType, SerialNo, TestDt, TareWT, GrossWT, Capacity, Press, Temp, Perform } = v; + await pool.request().query` - MERGE INTO GSVC_B1_D1 - USING (values(1)) - AS Source (Number) - ON (CERTNO = ${CERTNO[0]['']} AND CERTSEQ = ${i + 1}) - WHEN MATCHED AND (GasType != ${v.GasType} OR SerialNo != ${v.SerialNo} OR TestDt != ${TestDt} OR TareWT != ${ - v.TareWT - } OR GrossWT != ${v.GrossWT} OR Capacity != ${v.Capacity} OR Press != ${v.Press} OR Temp != ${v.Temp} OR Perform != ${v.Perform}) THEN - UPDATE SET GasType = ${v.GasType}, SerialNo = ${v.SerialNo}, TestDt = ${TestDt}, TareWT = ${v.TareWT}, GrossWT = ${ - v.GrossWT - }, Capacity = ${v.Capacity}, Press = ${v.Press}, Temp = ${v.Temp}, Perform = ${v.Perform}, UP_ID = ${ID}, UP_DT = GetDate() - WHEN NOT MATCHED THEN - INSERT (CERTNO, CERTSEQ, GasType, SerialNo, TestDt, TareWT, GrossWT, Capacity, Press, Temp, Perform, IN_ID, UP_ID) VALUES(${ - CERTNO[0][''] - }, ${i + 1}, ${v.GasType}, ${v.SerialNo}, ${TestDt}, ${v.TareWT}, ${v.GrossWT}, ${v.Capacity}, ${v.Press}, ${v.Temp}, ${ - v.Perform - }, ${ID}, ${ID}); - `; + INSERT GSVC_B1_D1 (CERTNO, CERTSEQ, GasType, SerialNo, TestDt, TareWT, GrossWT, Capacity, Press, Temp, Perform, IN_ID, IN_DT, UP_ID) + VALUES(${H.CERTNO || CERTNO[0]['']}, ${ + i + 1 + }, ${GasType}, ${SerialNo}, ${TestDt}, ${TareWT}, ${GrossWT}, ${Capacity}, ${Press}, ${Temp}, ${Perform}, ${ID}, ${ + insertDt || new Date() + }, ${ID}); + `; + + // await pool.request().query` + // MERGE INTO GSVC_B1_D1 + // USING (values(1)) + // AS Source (Number) + // ON (CERTNO = ${H.CERTNO || CERTNO[0]['']} AND CERTSEQ = ${i + 1}) + // WHEN MATCHED AND (GasType != ${GasType} OR SerialNo != ${SerialNo} OR TestDt != ${TestDt} OR TareWT != ${TareWT} OR GrossWT != ${GrossWT} OR Capacity != ${Capacity} OR Press != ${Press} OR Temp != ${Temp} OR Perform != ${Perform}) THEN + // UPDATE SET GasType = ${GasType}, SerialNo = ${SerialNo}, TestDt = ${TestDt}, TareWT = ${TareWT}, GrossWT = ${GrossWT}, Capacity = ${Capacity}, Press = ${Press}, Temp = ${Temp}, Perform = ${Perform}, UP_ID = ${ID}, UP_DT = GetDate() + // WHEN NOT MATCHED THEN + // INSERT (CERTNO, CERTSEQ, GasType, SerialNo, TestDt, TareWT, GrossWT, Capacity, Press, Temp, Perform, IN_ID, UP_ID) VALUES(${ + // H.CERTNO || CERTNO[0][''] + // }, ${i + 1}, ${GasType}, ${SerialNo}, ${TestDt}, ${TareWT}, ${GrossWT}, ${Capacity}, ${Press}, ${Temp}, ${Perform}, ${ID}, ${ID}); + // `; }); res.status(200).send(); From 51e3d3463d7df0931e0895041eb55841e44ac9ee Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Mon, 10 May 2021 15:51:38 +0900 Subject: [PATCH 05/12] install moment --- package-lock.json | 17 +++++++++++------ package.json | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 984b005..3699324 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1635,9 +1635,9 @@ "integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==" }, "hosted-git-info": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", - "integrity": "sha1-dTm9S8Hg4KiVgVouAmJCCxKFhIg=", + "version": "2.8.9", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "dev": true }, "htmlparser2": { @@ -2197,6 +2197,11 @@ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "integrity": "sha1-Z9ZgFLZqaoqqDAg8X9WN9OTpdgI=" }, + "moment": { + "version": "2.29.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz", + "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==" + }, "morgan": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz", @@ -3312,9 +3317,9 @@ } }, "underscore": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.0.tgz", - "integrity": "sha1-SBSUBVH8gFh873hA0euw8WRTvpc=" + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz", + "integrity": "sha512-hzSoAVtJF+3ZtiFX0VgfFPHEDRm7Y/QPjGyNo4TVdnDTdft3tr8hEkD25a1jC+TjTuE7tkHGKkhwCgs9dgBB2g==" }, "unique-string": { "version": "2.0.0", diff --git a/package.json b/package.json index 4ccb994..2d6aece 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "express-session": "^1.17.1", "jsonwebtoken": "^8.5.1", "jwt-decode": "^3.1.2", + "moment": "^2.29.1", "morgan": "^1.10.0", "mssql": "^6.3.1", "nodemon": "^2.0.7", From b23debb872abfddf9707e8311e72fcc4d648c0b4 Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Mon, 10 May 2021 15:52:35 +0900 Subject: [PATCH 06/12] =?UTF-8?q?fix:=20B1=5FH=EC=97=90=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=20=EC=82=BD=EC=9E=85=EC=9D=B4=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95,=20=EC=84=9C=ED=8A=B8=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=EB=B2=88=ED=98=B8=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EC=84=A0=EC=96=B8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80,?= =?UTF-8?q?=20TestDt=20=EB=82=A0=EC=A7=9C=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/B1.ctrl.js | 51 ++++++++++++++++------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/api/inspectionDocs/B1.ctrl.js b/api/inspectionDocs/B1.ctrl.js index 9e82a9d..93eb309 100644 --- a/api/inspectionDocs/B1.ctrl.js +++ b/api/inspectionDocs/B1.ctrl.js @@ -1,5 +1,6 @@ const sql = require('mssql'); const jwt = require('jsonwebtoken'); +const moment = require('moment'); const config = require('../../lib/configDB'); require('dotenv').config(); @@ -13,7 +14,7 @@ exports.details = async (req, res) => { const { recordset: D1 } = await pool.request().query` SELECT GasType, SerialNo, TestDt, TareWT, GrossWT, Capacity, Press, Temp, Perform FROM GSVC_B1_D1 - WHERE GSVC_B1_D1.CERTNO = ${ct} + WHERE CERTNO = ${ct} `; const D1arr = D1.map((item, i) => { @@ -54,21 +55,28 @@ exports.inspection = async (req, res) => { const pool = await sql.connect(config); const { recordset: CERTNO } = await pool.request().query`SELECT dbo.GD_F_NO('CT','002001',${CERTDT}, ${ID})`; + // UPDATE GRCV_CT SET CERT_NO = ${H.CERTNO}, UP_ID = ${ID}, UP_DT = getDate() + // WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') + try { jwt.verify(token, process.env.JWT_SECRET); if (type === 'save') { // 마감 한 문서 => 임시 저장 => 임시 저장 문서로 변경 const { recordset: magamYn } = await pool.request().query` - UPDATE GRCV_CT SET CERT_NO = ${H.CERTNO || CERTNO[0]['']}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') - SELECT MagamYn FROM GRCV_CT WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') `; - const { recordset: magam } = await pool.request().query` - SELECT MagamYn FROM GRCV_CT - WHERE (RcvNo = 'SN2012050002' AND Doc_No = 'B1') - `; + + if (!magamYn[0].MagamYn) { + await pool.request().query` + INSERT GDOC_3 (Cert_NO, Doc_No, Doc_Seq, Seq, IN_ID, UP_ID) + VALUES (${CERTNO[0]['']}, 'B1', 1, 1, ${ID}, ${ID}) + + UPDATE GRCV_CT SET Cert_No = ${CERTNO[0]['']}, MagamYn = 0, IN_ID = ${ID} + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') + `; + } + // 완료한 문서를 임시 저장하면 magam을 다시 0으로 if (magamYn[0].MagamYn === '1') { await pool.request().query` @@ -79,7 +87,7 @@ exports.inspection = async (req, res) => { } else { // 검사 완료 await pool.request().query` - UPDATE GRCV_CT SET Cert_No = ${H.CERTNO || CERTNO[0]['']}, MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() + UPDATE GRCV_CT SET MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') `; } @@ -89,15 +97,16 @@ exports.inspection = async (req, res) => { MERGE INTO GSVC_B1_H USING (values(1)) AS Source (Number) - ON (CERTNO IS NOT NULL) + ON (CERTNO = ${H.CERTNO}) WHEN MATCHED THEN UPDATE SET UP_ID = ${ID}, UP_DT = getDate() WHEN NOT MATCHED THEN - INSERT (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) VALUES(${H.CERTNO || CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); + INSERT (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) VALUES(${CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); `; // request로 받지 않은 내용은 행 삭제를 해야 한다. - let insertDt = ''; + let insertDt = moment().format('YYYY-MM-DD HH:mm:ss'); + if (H.CERTNO) { const { recordset: insertInfo } = await pool.request().query` SELECT IN_DT FROM GSVC_B1_D1 @@ -117,28 +126,14 @@ exports.inspection = async (req, res) => { Object.values(D1).forEach(async (v, i) => { const { GasType, SerialNo, TestDt, TareWT, GrossWT, Capacity, Press, Temp, Perform } = v; + const testDt = new Date(TestDt).toFormat('YYYY-MM'); await pool.request().query` INSERT GSVC_B1_D1 (CERTNO, CERTSEQ, GasType, SerialNo, TestDt, TareWT, GrossWT, Capacity, Press, Temp, Perform, IN_ID, IN_DT, UP_ID) VALUES(${H.CERTNO || CERTNO[0]['']}, ${ i + 1 - }, ${GasType}, ${SerialNo}, ${TestDt}, ${TareWT}, ${GrossWT}, ${Capacity}, ${Press}, ${Temp}, ${Perform}, ${ID}, ${ - insertDt || new Date() - }, ${ID}); + }, ${GasType}, ${SerialNo}, ${testDt}, ${TareWT}, ${GrossWT}, ${Capacity}, ${Press}, ${Temp}, ${Perform}, ${ID}, ${insertDt}, ${ID}); `; - - // await pool.request().query` - // MERGE INTO GSVC_B1_D1 - // USING (values(1)) - // AS Source (Number) - // ON (CERTNO = ${H.CERTNO || CERTNO[0]['']} AND CERTSEQ = ${i + 1}) - // WHEN MATCHED AND (GasType != ${GasType} OR SerialNo != ${SerialNo} OR TestDt != ${TestDt} OR TareWT != ${TareWT} OR GrossWT != ${GrossWT} OR Capacity != ${Capacity} OR Press != ${Press} OR Temp != ${Temp} OR Perform != ${Perform}) THEN - // UPDATE SET GasType = ${GasType}, SerialNo = ${SerialNo}, TestDt = ${TestDt}, TareWT = ${TareWT}, GrossWT = ${GrossWT}, Capacity = ${Capacity}, Press = ${Press}, Temp = ${Temp}, Perform = ${Perform}, UP_ID = ${ID}, UP_DT = GetDate() - // WHEN NOT MATCHED THEN - // INSERT (CERTNO, CERTSEQ, GasType, SerialNo, TestDt, TareWT, GrossWT, Capacity, Press, Temp, Perform, IN_ID, UP_ID) VALUES(${ - // H.CERTNO || CERTNO[0][''] - // }, ${i + 1}, ${GasType}, ${SerialNo}, ${TestDt}, ${TareWT}, ${GrossWT}, ${Capacity}, ${Press}, ${Temp}, ${Perform}, ${ID}, ${ID}); - // `; }); res.status(200).send(); From f13a85bb8ce4f7a957573a30a06a4034340c3de5 Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Tue, 11 May 2021 13:47:03 +0900 Subject: [PATCH 07/12] =?UTF-8?q?fix:=20=ED=97=A4=EB=8D=94=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD,=20?= =?UTF-8?q?=EB=A7=88=EA=B0=90=20=ED=96=88=EC=96=B4=EB=8F=84=20=EC=9E=84?= =?UTF-8?q?=EC=8B=9C=EC=A0=80=EC=9E=A5=20=EA=B0=80=EB=8A=A5=ED=95=98?= =?UTF-8?q?=EA=B2=8C=20=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/C.ctrl.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/api/inspectionDocs/C.ctrl.js b/api/inspectionDocs/C.ctrl.js index 9762c99..6bcdd5d 100644 --- a/api/inspectionDocs/C.ctrl.js +++ b/api/inspectionDocs/C.ctrl.js @@ -19,7 +19,7 @@ exports.details = async (req, res) => { SELECT CarriedOut, NotCarried, NotApp, Comm FROM GSVC_C_D2 WHERE CERTNO = ${ct} `; - + console.log(D1); const D1arr = D1.map((item, i) => ({ [i]: item.Value })); const D1obj = D1arr.reduce((a, c) => ({ ...a, ...c }), {}); @@ -61,14 +61,21 @@ exports.inspection = async (req, res) => { if (type === 'save') { // 임시저장 시 GRCV_CT 테이블에 데이터 삽입 const { recordset: magamYn } = await pool.request().query` - UPDATE GRCV_CT SET CERT_NO = ${H.CERTNO || CERTNO[0]['']}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C') - SELECT MagamYn FROM GRCV_CT WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C') `; - if (magamYn[0].MagamYn) { + if (!magamYn[0].MagamYn) { + await pool.request().query` + INSERT GDOC_3 (Cert_NO, Doc_No, Doc_Seq, Seq, IN_ID, UP_ID) + VALUES (${CERTNO[0]['']}, 'C', 1, 1, ${ID}, ${ID}) + + UPDATE GRCV_CT SET Cert_No = ${CERTNO[0]['']}, MagamYn = 0, MagamDt = '' + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C') + `; + } + + if (magamYn[0].MagamYn === '1') { await pool.request().query` UPDATE GRCV_CT SET MagamYn = 0, MagamDt = '' WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C') @@ -77,7 +84,7 @@ exports.inspection = async (req, res) => { } else { // complete -> 검사완료 시 GRCV_CT 테이블에 데이터 삽입 await pool.request().query` - UPDATE GRCV_CT SET MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() + UPDATE GRCV_CT SET Cert_No = ${H.CERTNO || CERTNO[0]['']}, MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C') `; } @@ -87,11 +94,11 @@ exports.inspection = async (req, res) => { merge into GSVC_C_H using(values (1)) as Source (Number) - on (CERTNO IS NOT NULL) + on (CERTNO = ${H.CERTNO}) when matched then update set UP_ID = ${ID}, UP_DT = GetDate() when not matched then - insert (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) values(${H.CERTNO || CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); + insert (CERTNO, CERTDT, VESSELNM, IN_ID, UP_ID) values(${CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID}); `; Object.values(D1).forEach(async (v, i) => { From 38be90cb7f4d845185532806ddcbdccae30660b1 Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Tue, 11 May 2021 17:48:39 +0900 Subject: [PATCH 08/12] =?UTF-8?q?feat:=20F,=20F2=20=EB=9D=BC=EC=9A=B0?= =?UTF-8?q?=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/inspectionDocs/index.js b/api/inspectionDocs/index.js index 217095a..4a38a60 100644 --- a/api/inspectionDocs/index.js +++ b/api/inspectionDocs/index.js @@ -50,9 +50,14 @@ router.post('/B1/inspection/:type', B1.inspection); router.post('/B3/inspection/:type', B3.inspection); // C -router.post('/C/inspection/:type', C.inspection); router.get('/C', C.details); +router.post('/C/inspection/:type', C.inspection); + +// F, F2 +router.get('/F', F.details); +router.get('/F2', F2.details); + router.post('/F/inspection/:type', F.inspection); router.post('/F2/inspection/:type', F2.inspection); From b24ac9cb968b217399598a7b1cd345f98b9387b8 Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Tue, 11 May 2021 17:49:23 +0900 Subject: [PATCH 09/12] =?UTF-8?q?fix:=20=EB=8F=99=EC=A0=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80/=EC=82=AD=EC=A0=9C=20=EB=AC=B8=EC=84=9C=EC=97=90=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/F.ctrl.js | 91 +++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 28 deletions(-) diff --git a/api/inspectionDocs/F.ctrl.js b/api/inspectionDocs/F.ctrl.js index 6139593..0d8bb28 100644 --- a/api/inspectionDocs/F.ctrl.js +++ b/api/inspectionDocs/F.ctrl.js @@ -1,5 +1,7 @@ +/* eslint-disable camelcase */ const sql = require('mssql'); const jwt = require('jsonwebtoken'); +const moment = require('moment'); const config = require('../../lib/configDB'); exports.details = async (req, res) => { @@ -9,23 +11,28 @@ exports.details = async (req, res) => { const pool = await sql.connect(config); const { recordset: D1 } = await pool.request().query` - SELECT GSVC_F_D1.Value FROM GSVC_F_D1 - WHERE GSVC_F_D1.CERTNO = ${ct} + SELECT s_no, position, condition, remark FROM GSVC_F_D1 + WHERE CERTNO = ${ct} `; const { recordset: D2 } = await pool.request().query` - SELECT GSVC_F_D2.Value FROM GSVC_F_D2 - WHERE GSVC_F_D2.CERTNO = ${ct} + SELECT Value FROM GSVC_F_D2 + WHERE CERTNO = ${ct} `; + console.log(D1); - const D1arr = D1.map((item, i) => ({ [i]: item.Value })); + const D1arr = D1.map(({ s_no, position, condition, remark }, i) => ({ + [i]: { + s_no, + position, + condition, + remark, + }, + })); const D1obj = D1arr.reduce((a, c) => ({ ...a, ...c }), {}); - const D2arr = D2.map((item, i) => ({ [i]: +item.Value })); - const D2obj = D2arr.reduce((a, c) => ({ ...a, ...c }), {}); - res.json({ D1: D1obj, - D2: D2obj, + D2: D2[0].Value, }); } catch (e) { console.log(e); @@ -44,27 +51,42 @@ exports.inspection = async (req, res) => { const pool = await sql.connect(config); const { recordset: CERTNO } = await pool.request().query`SELECT dbo.GD_F_NO('CT','002001', ${CERTDT}, ${ID})`; - const { recordset: RcvNos } = await pool.request().query`SELECT RcvNo FROM GRCV_CT WHERE (RcvNo = ${RCVNO})`; - const RcvNo = RcvNos.map(({ RcvNo }) => RcvNo)[0]; try { jwt.verify(token, process.env.JWT_SECRET); if (type === 'save') { - await pool.request().query` - UPDATE GRCV_CT SET CERT_NO = ${CERTNO[0]['']}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RcvNo} AND Doc_No = 'F') + const { recordset: magamYn } = await pool.request().query` + SELECT MagamYn FROM GRCV_CT + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'F') `; + + if (!magamYn[0].MagamYn) { + await pool.request().query` + INSERT GDOC_3 (Cert_NO, Doc_No, Doc_Seq, Seq, IN_ID, UP_ID) + VALUES (${H.CERTNO || CERTNO[0]['']}, 'F', 1, 1, ${ID}, ${ID}) + + UPDATE GRCV_CT SET Cert_No = ${H.CERTNO || CERTNO[0]['']}, MagamYn = 0, IN_ID = ${ID} + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'F') + `; + } + + if (magamYn[0].MagamYn === '1') { + await pool.request().query` + UPDATE GRCV_CT SET MagamYn = 0, MagamDt = '' + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'F') + `; + } } else { await pool.request().query` - UPDATE GRCV_CT SET MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RcvNo} AND Doc_No = 'F') + UPDATE GRCV_CT SET Cert_No = ${H.CERTNO || CERTNO[0]['']}, MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'F') `; } await pool.request().query` MERGE INTO GSVC_F_H USING (values (1)) AS Source (Number) - ON (CERTNO IS NOT NULL) + ON (CERTNO = ${H.CERTNO}) WHEN MATCHED THEN UPDATE SET UP_ID = ${ID}, UP_DT = getDate() WHEN NOT MATCHED THEN @@ -72,24 +94,37 @@ exports.inspection = async (req, res) => { MERGE INTO GSVC_F_D2 USING (values (1)) AS Source (Number) - ON (CERTNO = ${CERTNO[0]['']}) + ON (CERTNO = ${H.CERTNO || CERTNO[0]['']}) WHEN MATCHED AND (Value != ${D2}) THEN UPDATE SET Value = ${D2}, UP_ID = ${ID}, UP_DT = getDate() WHEN NOT MATCHED THEN - INSERT (CERTNO, CERTSEQ, Value, IN_ID, UP_ID) VALUES (${CERTNO[0]['']}, 1, ${D2}, ${ID}, ${ID}); + INSERT (CERTNO, CERTSEQ, Value, IN_ID, UP_ID) VALUES (${H.CERTNO || CERTNO[0]['']}, 1, ${D2}, ${ID}, ${ID}); `; + let insertDt = moment().format('YYYY-MM-DD HH:mm:ss'); + + if (H.CERTNO) { + const { recordset: insertInfo } = await pool.request().query` + SELECT IN_DT FROM GSVC_F_D1 + WHERE (CERTNO = ${H.CERTNO} AND CERTSEQ = 1) + `; + insertDt = insertInfo[0].IN_DT; + + await pool.request().query` + SELECT * FROM GSVC_F_D1 WHERE CERTNO = ${H.CERTNO} + + BEGIN TRAN + DELETE FROM GSVC_F_D1 WHERE CERTNO = ${H.CERTNO} + SELECT * FROM GSVC_F_D1 WHERE CERTNO = ${H.CERTNO} + COMMIT TRAN + `; + } + Object.values(D1).forEach(async (v, i) => { + const { s_no, position, condition, remark } = v; await pool.request().query` - MERGE INTO GSVC_F_D1 - USING (values (1)) AS Source (Number) - ON (CERTNO = ${CERTNO[0]['']} AND CERTSEQ = ${i + 1}) - WHEN MATCHED AND (s_no != ${v.s_no} OR position != ${v.position} OR condition != ${v.condition} OR remark != ${v.remark}) THEN - UPDATE SET s_no = ${v.s_no}, position = ${v.position}, condition = ${v.condition}, remark = ${v.remark}, UP_ID = ${ID}, UP_DT = getDate() - WHEN NOT MATCHED THEN - INSERT (CERTNO, CERTSEQ, s_no, position, condition, remark, IN_ID, UP_ID) VALUES (${CERTNO[0]['']}, ${i + 1}, ${v.s_no}, ${v.position}, ${ - v.condition - }, ${v.remark}, ${ID}, ${ID}); + INSERT GSVC_F_D1 (CERTNO, CERTSEQ, s_no, position, condition, remark, IN_ID, IN_DT, UP_ID) + VALUES (${H.CERTNO || CERTNO[0]['']}, ${i + 1}, ${s_no}, ${position}, ${condition}, ${remark}, ${ID}, ${insertDt}, ${ID}); `; }); From 8ba122b2e374bce888387a5d8c0a6c9ac9b2e41a Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Tue, 11 May 2021 17:49:52 +0900 Subject: [PATCH 10/12] =?UTF-8?q?fix:=20=EB=A7=88=EA=B0=90=EC=99=84?= =?UTF-8?q?=EB=A3=8C=EC=8B=9C,=20=EC=84=9C=ED=8A=B8=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=82=BD=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/B1.ctrl.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/inspectionDocs/B1.ctrl.js b/api/inspectionDocs/B1.ctrl.js index 93eb309..feeb334 100644 --- a/api/inspectionDocs/B1.ctrl.js +++ b/api/inspectionDocs/B1.ctrl.js @@ -73,7 +73,7 @@ exports.inspection = async (req, res) => { VALUES (${CERTNO[0]['']}, 'B1', 1, 1, ${ID}, ${ID}) UPDATE GRCV_CT SET Cert_No = ${CERTNO[0]['']}, MagamYn = 0, IN_ID = ${ID} - WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') `; } @@ -87,7 +87,7 @@ exports.inspection = async (req, res) => { } else { // 검사 완료 await pool.request().query` - UPDATE GRCV_CT SET MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() + UPDATE GRCV_CT SET Cert_No = ${H.CERTNO || CERTNO[0]['']}, MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() WHERE (RcvNo = ${RCVNO} AND Doc_No = 'B1') `; } From 1ac440b42a12accf62e813738a409f18221cb9e2 Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Wed, 12 May 2021 14:43:19 +0900 Subject: [PATCH 11/12] camelcase off --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 13d8284..3487bc8 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -15,6 +15,7 @@ // "off" or 0 - turn the rule off // "warn" or 1 - turn the rule on as a warning (doesn’t affect exit code) // "error" or 2 - turn the rule on as an error (exit code is 1 when triggered) + "camelcase": "off", "no-unused-vars": 0, "no-console": "warn", "no-plusplus": "off", From 05cc57fb3f2ef507c447bf7a120365351aa6eeeb Mon Sep 17 00:00:00 2001 From: Kim-Jaemin420 Date: Wed, 12 May 2021 14:44:33 +0900 Subject: [PATCH 12/12] =?UTF-8?q?fix:=20=EB=AC=B8=EC=84=9C=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=20get=20=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20=EB=8F=99=EC=A0=81=20=EC=B6=94=EA=B0=80/?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=AC=B8=EC=84=9C=EC=97=90=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/inspectionDocs/F2.ctrl.js | 107 +++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 28 deletions(-) diff --git a/api/inspectionDocs/F2.ctrl.js b/api/inspectionDocs/F2.ctrl.js index b573f44..a88ce00 100644 --- a/api/inspectionDocs/F2.ctrl.js +++ b/api/inspectionDocs/F2.ctrl.js @@ -1,5 +1,6 @@ const sql = require('mssql'); const jwt = require('jsonwebtoken'); +const moment = require('moment'); const config = require('../../lib/configDB'); exports.details = async (req, res) => { @@ -9,18 +10,38 @@ exports.details = async (req, res) => { const pool = await sql.connect(config); const { recordset: D1 } = await pool.request().query` - SELECT GSVC_F1_D1.Value FROM GSVC_F1_D1 - WHERE GSVC_F1_D1.CERTNO = ${ct} + SELECT manuf, type, s_no, remark FROM GSVC_F2_D1 + WHERE CERTNO = ${ct} `; const { recordset: D2 } = await pool.request().query` - SELECT GSVC_F1_D2.Value FROM GSVC_F1_D2 - WHERE GSVC_F1_D2.CERTNO = ${ct} + SELECT confirm, f_pressure, f_depth, expiry_date, value1, value2, recommend FROM GSVC_F2_D2 + WHERE CERTNO = ${ct} `; - const D1arr = D1.map((item, i) => ({ [i]: item.Value })); + const D1arr = D1.map(({ manuf, type, s_no, remark }, i) => ({ + [i]: { + manuf, + type, + s_no, + remark, + }, + })); const D1obj = D1arr.reduce((a, c) => ({ ...a, ...c }), {}); - const D2arr = D2.map((item, i) => ({ [i]: +item.Value })); + const D2arr = D2.map((item, i) => { + const { confirm, f_pressure, f_depth, expiry_date, value1, value2, recommend } = item; + return { + [i]: { + confirm, + f_pressure, + f_depth, + expiry_date, + value1, + value2, + recommend, + }, + }; + }); const D2obj = D2arr.reduce((a, c) => ({ ...a, ...c }), {}); res.json({ @@ -44,29 +65,46 @@ exports.inspection = async (req, res) => { const pool = await sql.connect(config); const { recordset: CERTNO } = await pool.request().query`SELECT dbo.GD_F_NO('CT','002001', ${CERTDT}, ${ID})`; - const { recordset: RcvNos } = await pool.request().query`SELECT RcvNo FROM GRCV_CT WHERE (RcvNo = ${RCVNO})`; - const RcvNo = RcvNos.map(({ RcvNo }) => RcvNo)[0]; - const expiry_date = new Date(D2.expiry_date.substring(0, 10)).toFormat('MMM.YY'); + const { confirm, f_pressure, f_depth, value1, value2, recommend } = D2; + const expiry_date = new Date(D2.expiry_date).toFormat('YYYY-MM'); try { jwt.verify(token, process.env.JWT_SECRET); if (type === 'save') { - await pool.request().query` - UPDATE GRCV_CT SET CERT_NO = ${CERTNO[0]['']}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RcvNo} AND Doc_No = 'F2') + const { recordset: magamYn } = await pool.request().query` + SELECT MagamYn FROM GRCV_CT + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'F2') `; + + if (!magamYn[0].MagamYn) { + await pool.request().query` + INSERT GDOC_3 (Cert_NO, Doc_No, Doc_Seq, Seq, IN_ID, UP_ID) + VALUES (${CERTNO[0]['']}, 'B1', 1, 1, ${ID}, ${ID}) + + UPDATE GRCV_CT SET Cert_No = ${CERTNO[0]['']}, MagamYn = 0, IN_ID = ${ID} + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'F2') + `; + } + + // 완료한 문서를 임시 저장하면 magam을 다시 0으로 + if (magamYn[0].MagamYn === '1') { + await pool.request().query` + UPDATE GRCV_CT SET MagamYn = 0, MagamDt = '' + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'F2') + `; + } } else { await pool.request().query` - UPDATE GRCV_CT SET MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() - WHERE (RcvNo = ${RcvNo} AND Doc_No = 'F2') + UPDATE GRCV_CT SET Cert_No = ${H.CERTNO || CERTNO[0]['']}, MagamYn = 1, MagamDt = ${CERTDT}, UP_ID = ${ID}, UP_DT = getDate() + WHERE (RcvNo = ${RCVNO} AND Doc_No = 'F2') `; } await pool.request().query` MERGE INTO GSVC_F2_H USING (values (1)) AS Source (Number) - ON (CERTNO IS NOT NULL) + ON (CERTNO = ${H.CERTNO}) WHEN MATCHED THEN UPDATE SET UP_ID = ${ID}, UP_DT = getDate() WHEN NOT MATCHED THEN @@ -74,24 +112,37 @@ exports.inspection = async (req, res) => { MERGE INTO GSVC_F2_D2 USING (values (1)) AS Source (Number) - ON (CERTNO IS NOT NULL) - WHEN MATCHED AND (confirm != ${D2.confirm} OR f_pressure != ${D2.f_pressure} OR f_depth != ${D2.f_depth} OR expiry_date != ${expiry_date} OR value1 != ${D2.value1} OR value2 != ${D2.value2} OR recommend != ${D2.recommend}) THEN - UPDATE SET UP_ID = ${ID}, UP_DT = getDate() + ON (CERTNO = ${H.CERTNO}) + WHEN MATCHED AND (confirm != ${confirm} OR f_pressure != ${f_pressure} OR f_depth != ${f_depth} OR expiry_date != ${expiry_date} OR value1 != ${value1} OR value2 != ${value2} OR recommend != ${recommend}) THEN + UPDATE SET confirm = ${confirm}, f_pressure = ${f_pressure}, f_depth = ${f_depth}, expiry_date = ${expiry_date}, value1 = ${value1}, value2 = ${value2}, recommend = ${recommend}, UP_ID = ${ID}, UP_DT = getDate() WHEN NOT MATCHED THEN - INSERT (CERTNO, CERTSEQ, confirm, f_pressure, f_depth, expiry_date, value1, value2, recommend, IN_ID, UP_ID) VALUES (${CERTNO[0]['']}, 1, ${D2.confirm}, ${D2.f_pressure}, ${D2.f_depth}, ${expiry_date}, ${D2.value1}, ${D2.value2}, ${D2.recommend}, ${ID}, ${ID}); + INSERT (CERTNO, CERTSEQ, confirm, f_pressure, f_depth, expiry_date, value1, value2, recommend, IN_ID, UP_ID) VALUES (${CERTNO[0]['']}, 1, ${confirm}, ${f_pressure}, ${f_depth}, ${expiry_date}, ${value1}, ${value2}, ${recommend}, ${ID}, ${ID}); `; + let insertDt = moment().format('YYYY-MM-DD HH:mm:ss'); + + if (H.CERTNO) { + const { recordset: insertInfo } = await pool.request().query` + SELECT IN_DT FROM GSVC_F2_D1 + WHERE (CERTNO = ${H.CERTNO} AND CERTSEQ = 1) + `; + insertDt = insertInfo[0].IN_DT; + + await pool.request().query` + SELECT * FROM GSVC_F2_D1 WHERE CERTNO = ${H.CERTNO} + + BEGIN TRAN + DELETE FROM GSVC_F2_D1 WHERE CERTNO = ${H.CERTNO} + SELECT * FROM GSVC_F2_D1 WHERE CERTNO = ${H.CERTNO} + COMMIT TRAN + `; + } + Object.values(D1).forEach(async (v, i) => { await pool.request().query` - MERGE INTO GSVC_F2_D1 - USING (values (1)) AS Source (Number) - ON (CERTNO = ${CERTNO[0]['']} AND CERTSEQ = ${i + 1}) - WHEN MATCHED AND (manuf != ${v.manuf} OR type != ${v.type} OR s_no != ${v.s_no} OR remark != ${v.remark}) THEN - UPDATE SET manuf = ${v.manuf}, type = ${v.type}, s_no = ${v.s_no}, remark = ${v.remark}, UP_ID = ${ID}, UP_DT = getDate() - WHEN NOT MATCHED THEN - INSERT (CERTNO, CERTSEQ, manuf, type, s_no, remark, IN_ID, UP_ID) VALUES (${CERTNO[0]['']}, ${i + 1}, ${v.manuf}, ${v.type}, ${v.s_no}, ${ - v.remark - }, ${ID}, ${ID}); + INSERT GSVC_F2_D1 (CERTNO, CERTSEQ, manuf, type, s_no, remark, IN_ID, IN_DT, UP_ID) VALUES (${H.CERTNO || CERTNO[0]['']}, ${i + 1}, ${ + v.manuf + }, ${v.type}, ${v.s_no}, ${v.remark}, ${ID}, ${insertDt},${ID}); `; });