From 8678a4b62b65621040a43a2edefec4fe7b2bc97d Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 11 Feb 2025 19:34:50 +0700 Subject: [PATCH] =?UTF-8?q?fix=20issue=20#1099=20=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B8=99=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=9A=E0=B8=9A=20KPI=20>>=20(=E0=B8=82=E0=B9=89=E0=B8=AD?= =?UTF-8?q?=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B8=88=E0=B8=B3=E0=B8=99=E0=B8=A7?= =?UTF-8?q?=E0=B8=99=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=9B=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B9=80=E0=B8=A1=E0=B8=B4=E0=B8=99=E0=B9=84=E0=B8=A1=E0=B9=88?= =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B6=E0=B8=81=E0=B8=A5?= =?UTF-8?q?=E0=B8=87=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 281 +++++++++++++--------------- 1 file changed, 131 insertions(+), 150 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index e79388f..d58213a 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -408,161 +408,142 @@ export class ReportController extends Controller { if (requestBody.type == "KPI3") { templateName = "KPI3"; reportName = "KPI3"; - const userEvaluations_ = - data?.kpiUserEvaluations?.length > 0 - ? data.kpiUserEvaluations.map((x: any, idx: number) => ({ - no: idx != null ? Extension.ToThaiNumber((idx + 1).toString()) : "-", - fullName: - x.prefix != null && x.firstName != null && x.lastName != null - ? `${x.prefix}${x.firstName} ${x.lastName}` - : "-", - position: x.position ? x.position : "-", - point1: - x.summaryPoint >= 90.0 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "-", - point2: - x.summaryPoint >= 80.0 && x.summaryPoint <= 89.99 - ? Extension.ToThaiNumber(x.summaryPoint.toString()) - : "-", - point3: - x.summaryPoint >= 70.0 && x.summaryPoint <= 79.99 - ? Extension.ToThaiNumber(x.summaryPoint.toString()) - : "-", - point4: - x.summaryPoint >= 60.0 && x.summaryPoint <= 69.99 - ? Extension.ToThaiNumber(x.summaryPoint.toString()) - : "-", - point5: - x.summaryPoint < 60.0 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "-", - remark: x.reasonEvaluator, - })) - : [ - { - no: "-", - fullName: "-", - position: "-", - point1: "-", - point2: "-", - point3: "-", - point4: "-", - point5: "-", - remark: "-", - }, - ]; - const prefixEvaluator_ = - data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].prefixEvaluator : ""; - const firstNameEvaluator_ = - data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].firstNameEvaluator : ""; - const lastNameEvaluator_ = - data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].lastNameEvaluator : ""; - const fullNameEvaluator = - prefixEvaluator_ != "" && firstNameEvaluator_ != "" && lastNameEvaluator_ != "" - ? `${prefixEvaluator_}${firstNameEvaluator_} ${lastNameEvaluator_}` - : "-"; - const commanderId = - data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].commanderId : ""; - let prefixCommander = ""; - let firstNameCommander = ""; - let lastNameCommander = ""; - let positionCommander = ""; - let posTypeNameCommander = ""; - let posLevelNameCommander = ""; - let orgCommander = ""; - if (commanderId != "" && commanderId != null) { - await new CallAPI() - .GetData(request, "org/profile/profileid/position/" + commanderId) - .then((x) => { - prefixCommander = x.prefix; - firstNameCommander = x.firstName; - lastNameCommander = x.lastName; - positionCommander = x.position; - orgCommander = x.root; - posTypeNameCommander = x.posTypeName; - posLevelNameCommander = x.posLevelName; - }) - .catch(() => { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ"); - }); + const groupedEvaluations: any[] = []; + let fullNameCommander: string = "-"; + let positionCommander: string = "-"; + let posTypeNameCommander: string = "-"; + let posLevelNameCommander: string = "-"; + let orgCommander: string = "-"; + let fullNameCommanderHigh: string = "-"; + let positionCommanderHigh: string = "-"; + let posTypeNameCommanderHigh: string = "-"; + let posLevelNameCommanderHigh: string = "-"; + let orgCommanderHigh: string = "-"; + let idx:number=0 + for (const x of data?.kpiUserEvaluations || []) { + let group = groupedEvaluations.find( + (g) => + g.evaluatorId === x.evaluatorId && + g.commanderId === x.commanderId && + g.commanderHighId === x.commanderHighId + ); + if (x.commanderId != "" && x.commanderId != null) { + await new CallAPI() + .GetData(request, "/org/profile/profileid/position/" + x.commanderId) + .then((res) => { + fullNameCommander = `${res.prefix}${res.firstName} ${res.lastName}`; + positionCommander = res.position; + posTypeNameCommander = res.posTypeName; + posLevelNameCommander = res.posLevelName; + orgCommander = res.root; + }) + .catch(() => {}); + } + if (x.commanderHighId != "" && x.commanderHighId != null) { + await new CallAPI() + .GetData(request, "/org/profile/profileid/position/" + x.commanderHighId) + .then((res) => { + fullNameCommanderHigh = `${res.prefix}${res.firstName} ${res.lastName}`; + positionCommanderHigh = res.position; + posTypeNameCommanderHigh = res.posTypeName; + posLevelNameCommanderHigh = res.posLevelName; + orgCommanderHigh = res.root; + }) + .catch(() => {}); + } + if (!group) { + group = { + evaluatorId: x.evaluatorId, + commanderId: x.commanderId, + commanderHighId: x.commanderHighId, + fullNameEvaluator: `${x.prefixEvaluator}${x.firstNameEvaluator} ${x.lastNameEvaluator}`, + positionEvaluator: x.positionEvaluator, + posTypeNameEvaluator: x.posTypeNameEvaluator, + posLevelNameEvaluator: x.posLevelNameEvaluator, + orgEvaluator: x.orgEvaluator, + fullNameCommander: fullNameCommander, + positionCommander: positionCommander, + posTypeNameCommander: posTypeNameCommander, + posLevelNameCommander: posLevelNameCommander, + orgCommander: orgCommander, + fullNameCommanderHigh: fullNameCommanderHigh, + positionCommanderHigh: positionCommanderHigh, + posTypeNameCommanderHigh: posTypeNameCommanderHigh, + posLevelNameCommanderHigh: posLevelNameCommanderHigh, + orgCommanderHigh: orgCommanderHigh, + evaluationResults: [], + }; + groupedEvaluations.push(group); + } + group.evaluationResults.push({ + no: idx != null ? Extension.ToThaiNumber((idx + 1).toString()) : "-", + fullName: + x.prefix != null && x.firstName != null && x.lastName != null + ? `${x.prefix}${x.firstName} ${x.lastName}` + : "-", + position: x.position ? x.position : "-", + point1: + x.summaryPoint >= 90.0 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "-", + point2: + x.summaryPoint >= 80.0 && x.summaryPoint <= 89.99 + ? Extension.ToThaiNumber(x.summaryPoint.toString()) + : "-", + point3: + x.summaryPoint >= 70.0 && x.summaryPoint <= 79.99 + ? Extension.ToThaiNumber(x.summaryPoint.toString()) + : "-", + point4: + x.summaryPoint >= 60.0 && x.summaryPoint <= 69.99 + ? Extension.ToThaiNumber(x.summaryPoint.toString()) + : "-", + point5: + x.summaryPoint < 60.0 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "-", + remark: x.reasonEvaluator, + }); + idx ++; } - const fullNameCommander = - prefixCommander != "" && firstNameCommander != "" && firstNameCommander != "" - ? `${prefixCommander}${firstNameCommander} ${lastNameCommander}` - : "-"; - - const commanderHighId = - data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].commanderHighId : ""; - let prefixCommanderHigh = ""; - let firstNameCommanderHigh = ""; - let lastNameCommanderHigh = ""; - let positionCommanderHigh = ""; - let posTypeNameCommanderHigh = ""; - let posLevelNameCommanderHigh = ""; - let orgCommanderHigh; - if (commanderHighId != "" && commanderHighId != null) { - await new CallAPI() - .GetData(request, "org/profile/profileid/position/" + commanderHighId) - .then((x) => { - prefixCommanderHigh = x.prefix; - firstNameCommanderHigh = x.firstName; - lastNameCommanderHigh = x.lastName; - positionCommanderHigh = x.position; - orgCommanderHigh = x.root; - posTypeNameCommanderHigh = x.posTypeName; - posLevelNameCommanderHigh = x.posLevelName; - }) - .catch(() => { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ"); - }); - } - const fullNameCommanderHigh = - prefixCommanderHigh != "" && firstNameCommanderHigh != "" && lastNameCommanderHigh != "" - ? `${prefixCommanderHigh}${firstNameCommanderHigh} ${lastNameCommanderHigh}` - : "-"; - + const _userEvaluations = groupedEvaluations.length > 0 + ? groupedEvaluations + : [ + { + evaluatorId: "-", + commanderId: "-", + commanderHighId: "-", + fullNameEvaluator: "-", + positionEvaluator: "-", + posTypeNameEvaluator: "-", + posLevelNameEvaluator: "-", + orgEvaluator: "-", + fullNameCommander: "-", + positionCommander: "-", + posTypeNameCommander: "-", + posLevelNameCommander: "-", + orgCommander: "-", + fullNameCommanderHigh: "-", + positionCommanderHigh: "-", + posTypeNameCommanderHigh: "-", + posLevelNameCommanderHigh: "-", + orgCommanderHigh: "-", + evaluationResults: [ + { + no: "-", + fullName: "-", + position: "-", + point1: "-", + point2: "-", + point3: "-", + point4: "-", + point5: "-", + remark: "-", + }, + ], + }, + ]; formattedData = { year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-", period1: Extension.ToThaiNumber(period1), period2: Extension.ToThaiNumber(period2), - durationKPI: data?.durationKPI, - root: data && data.rootName != null ? data.rootName : "-", - fullNameEvaluator: fullNameEvaluator, - positionEvaluator: - data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].positionEvaluator : "-", - posTypeNameEvaluator: - data.kpiUserEvaluations.length > 0 - ? data.kpiUserEvaluations[0].posTypeNameEvaluator - : "-", - posLevelNameEvaluator: - data.kpiUserEvaluations.length > 0 - ? data.kpiUserEvaluations[0].posLevelNameEvaluator - : "-", - orgEvaluator: - data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].orgEvaluator : "-", - fullNameCommander: fullNameCommander, - positionCommander: - positionCommander != "" && positionCommander != null ? positionCommander : "-", - posTypeNameCommander: - posTypeNameCommander != "" && posTypeNameCommander != null ? posTypeNameCommander : "-", - posLevelNameCommander: - posLevelNameCommander != "" && posLevelNameCommander != null - ? posLevelNameCommander - : "-", - orgCommander: orgCommander != "" && orgCommander != null ? orgCommander : "-", - fullNameCommanderHigh: fullNameCommanderHigh, - positionCommanderHigh: - positionCommanderHigh != "" && positionCommanderHigh != null - ? positionCommanderHigh - : "-", - posTypeNameCommanderHigh: - posTypeNameCommanderHigh != "" && posTypeNameCommanderHigh != null - ? posTypeNameCommanderHigh - : "-", - posLevelNameCommanderHigh: - posLevelNameCommanderHigh != "" && posLevelNameCommanderHigh != null - ? posLevelNameCommanderHigh - : "-", - orgCommanderHigh: - orgCommanderHigh != "" && orgCommanderHigh != null ? orgCommanderHigh : "-", - userEvaluations: userEvaluations_, + evaluations: _userEvaluations, }; } if (requestBody.type == "KPI4") {