Skip to content

Commit

Permalink
Merge pull request #102 from Kim-Jaemin420/develop
Browse files Browse the repository at this point in the history
문서 F2 수정
  • Loading branch information
Kim-Jaemin420 authored May 12, 2021
2 parents 8abaacb + 12ec19e commit ec917a5
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 118 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
73 changes: 49 additions & 24 deletions api/inspectionDocs/B1.ctrl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const sql = require('mssql');
const jwt = require('jsonwebtoken');
const moment = require('moment');
const config = require('../../lib/configDB');

require('dotenv').config();
Expand All @@ -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) => {
Expand Down Expand Up @@ -54,61 +55,85 @@ 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')
`;

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]['']}, '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`
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))
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(${CERTNO[0]['']}, ${CERTDT}, ${VESSELNM}, ${ID}, ${ID});
`;

// request로 받지 않은 내용은 행 삭제를 해야 한다.
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
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;
const testDt = new Date(TestDt).toFormat('YYYY-MM');

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}, ${ID});
`;
});

res.status(200).send();
Expand Down
46 changes: 28 additions & 18 deletions api/inspectionDocs/B3.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,32 @@ 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;

try {
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')
`;
}

Expand All @@ -98,19 +106,19 @@ 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) => {
await pool.request().query`
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});
`;
Expand All @@ -120,29 +128,31 @@ 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
update set CarriedOut = ${v.CarriedOut}, NotCarried = ${v.NotCarried}, NotApp = ${v.NotApp}, Comm = ${
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});
`;
});

await pool.request().query`
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();
Expand Down
62 changes: 42 additions & 20 deletions api/inspectionDocs/C.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
`;

console.log(D1);
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({
Expand All @@ -46,24 +53,39 @@ 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;

try {
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`
SELECT MagamYn FROM GRCV_CT
WHERE (RcvNo = ${RCVNO} AND Doc_No = 'C')
`;

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')
`;
}
} 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')
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')
`;
}

Expand All @@ -72,7 +94,7 @@ 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
Expand All @@ -84,29 +106,29 @@ 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});
`;
});

Object.values(D2).forEach(async (v, i) => {
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
update set CarriedOut = ${v.CarriedOut}, NotCarried = ${v.NotCarried}, NotApp = ${v.NotApp}, Comm = ${
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});
`;
});

Expand Down
Loading

0 comments on commit ec917a5

Please sign in to comment.