From 7a83b0ab98b99940d4e99fcb2eafd6ce68647eef Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 26 Aug 2024 13:46:45 +0700 Subject: [PATCH] fix report --- src/controllers/ReportController.ts | 414 +++++++++++++++++++++------- 1 file changed, 313 insertions(+), 101 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index f44168e..60b6f49 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -40,20 +40,12 @@ export class ReportController extends Controller { //KPI1, KPI2, KPI3, KPI7, KPI9 let data: any; + let dataKpiUserEvaluations: any; let period1: any; let period2: any; - + let rootName: any if (requestBody.root && requestBody.periodId) { - // data = await this.kpiPeriodRepository.createQueryBuilder("period") - // .leftJoinAndSelect("period.kpiUserEvaluations", "kpiUserEvaluations") - // .where("period.id = :periodId", { periodId: requestBody.periodId }) - // .andWhere("kpiUserEvaluations.orgId = :orgId", { orgId: requestBody.root }) - // .getOne(); - - // if(data == null || data == undefined){ - // throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการ ของหน่วยงานที่เลือก`); - // } data = await this.kpiPeriodRepository.findOne({ where: { id: requestBody.periodId }, }); @@ -64,6 +56,11 @@ export class ReportController extends Controller { evaluationStatus: "KP7", }, }); + await new CallAPI() + .GetData(request, `org/root/${requestBody.root}`) + .then((x) => { + rootName = x.orgRootName; + }); data = { id: data.id, year: data.year, @@ -71,6 +68,7 @@ export class ReportController extends Controller { startDate: data.startDate, endDate: data.endDate, kpiUserEvaluations: dataKpiUserEvaluations, + rootName: rootName }; if (data.durationKPI == "APR") { @@ -108,10 +106,6 @@ export class ReportController extends Controller { where: { orgId: String(requestBody?.root), kpiPeriodId: String(requestBody?.periodId), - // child1Id: "" || IsNull(), - // child2Id: "" || IsNull(), - // child3Id: "" || IsNull(), - // child4Id: "" || IsNull(), }, }); const resultAll = @@ -177,22 +171,29 @@ export class ReportController extends Controller { period2: Extension.ToThaiNumber(period2), durationKPI: data?.durationKPI, root: - data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator + data && data.rootName != null + ? data.rootName : "-", userEvaluations: [ { - no: userEvaluationOrg.length > 0 ? "๑" : "", - root: userEvaluationOrg.length > 0 ? userEvaluationOrg[0].orgEvaluator ?? "" : "-", - resultAll: userEvaluationOrg.length > 0 ? resultAll : "", - result: userEvaluationOrg.length > 0 ? result : "", - excellent: userEvaluationOrg.length > 0 ? excellent : "", - verygood: userEvaluationOrg.length > 0 ? verygood : "", - good: userEvaluationOrg.length > 0 ? good : "", - fair: userEvaluationOrg.length > 0 ? fair : "", - improvment: userEvaluationOrg.length > 0 ? improvment : "", + no: userEvaluationOrg.length > 0 ? "๑" : "-", + root: data && data.rootName != null ? data.rootName : "-", + resultAll: userEvaluationOrg.length > 0 ? resultAll : "-", + result: userEvaluationOrg.length > 0 ? result : "-", + excellent: userEvaluationOrg.length > 0 ? excellent : "-", + verygood: userEvaluationOrg.length > 0 ? verygood : "-", + good: userEvaluationOrg.length > 0 ? good : "-", + fair: userEvaluationOrg.length > 0 ? fair : "-", + improvment: userEvaluationOrg.length > 0 ? improvment : "-", }, ], + resultAll_: userEvaluationOrg.length > 0 ? resultAll : "-", + result_: userEvaluationOrg.length > 0 ? result : "-", + excellent_: userEvaluationOrg.length > 0 ? excellent : "-", + verygood_: userEvaluationOrg.length > 0 ? verygood : "-", + good_: userEvaluationOrg.length > 0 ? good : "-", + fair_: userEvaluationOrg.length > 0 ? fair : "-", + improvment_: userEvaluationOrg.length > 0 ? improvment : "-", }; } if (requestBody.type == "KPI2") { @@ -204,103 +205,172 @@ export class ReportController extends Controller { .filter((x: any) => x.evaluationResults == "EXCELLENT") .map((x: any, idx: number) => ({ no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", + fullName: x.prefix!=null&&x.firstName!=null&&x.lastName!=null + ? `${x.prefix}${x.firstName} ${x.lastName}` + : "-", + position: x.position ? x.position : "-", + posLevelName: x.posLevelName ? x.posLevelName : "-", + org: x.org ? x.org : "-", })) - : [{}]; + : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }]; const verygood = data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations .filter((x: any) => x.evaluationResults == "VERY_GOOD") .map((x: any, idx: number) => ({ no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", + fullName: x.prefix!=null&&x.firstName!=null&&x.lastName!=null + ? `${x.prefix}${x.firstName} ${x.lastName}` + : "-", + position: x.position ? x.position : "-", + posLevelName: x.posLevelName ? x.posLevelName : "-", + org: x.org ? x.org : "-", })) - : [{}]; + : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }]; const good = data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations .filter((x: any) => x.evaluationResults == "GOOD") .map((x: any, idx: number) => ({ no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", + fullName: x.prefix!=null&&x.firstName!=null&&x.lastName!=null + ? `${x.prefix}${x.firstName} ${x.lastName}` + : "-", + position: x.position ? x.position : "-", + posLevelName: x.posLevelName ? x.posLevelName : "-", + org: x.org ? x.org : "-", })) - : [{}]; + : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }]; const fair = data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations .filter((x: any) => x.evaluationResults == "FAIR") .map((x: any, idx: number) => ({ no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", + fullName: x.prefix!=null&&x.firstName!=null&&x.lastName!=null + ? `${x.prefix}${x.firstName} ${x.lastName}` + : "-", + position: x.position ? x.position : "-", + posLevelName: x.posLevelName ? x.posLevelName : "-", + org: x.org ? x.org : "-", })) - : [{}]; + : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }]; const improvment = data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations .filter((x: any) => x.evaluationResults == "IMPROVEMENT") .map((x: any, idx: number) => ({ no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", + fullName: x.prefix!=null&&x.firstName!=null&&x.lastName!=null + ? `${x.prefix}${x.firstName} ${x.lastName}` + : "-", + position: x.position ? x.position : "-", + posLevelName: x.posLevelName ? x.posLevelName : "-", + org: x.org ? x.org : "-", })) - : [{}]; + : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }]; formattedData = { year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-", period1: Extension.ToThaiNumber(period1), period2: Extension.ToThaiNumber(period2), durationKPI: data?.durationKPI, - root: - data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator + root: data && data.rootName != null + ? data.rootName : "-", excellents: { count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(excellent.length.toString()) - : "", - data: excellent, + : "๐", + data: excellent.length > 0 ? excellent : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }], }, verygoods: { count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(verygood.length.toString()) - : "", - data: verygood, + : "๐", + data: verygood.length > 0 ? verygood : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }], }, goods: { count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(good.length.toString()) - : "", - data: good, + : "๐", + data: good.length > 0 ? good : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }], }, fairs: { count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(fair.length.toString()) - : "", - data: fair, + : "๐", + data: fair.length > 0 ? fair : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }], }, improvments: { count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(improvment.length.toString()) - : "", - data: improvment, + : "๐", + data: improvment.length > 0 ? improvment : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + org: "-", + }], }, }; } @@ -310,28 +380,44 @@ export class ReportController extends Controller { const userEvaluations_ = data?.kpiUserEvaluations?.length > 0 ? data.kpiUserEvaluations.map((x: any, idx: number) => ({ - no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", + 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()) : "", + 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()) : "", + 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_ = @@ -408,8 +494,8 @@ export class ReportController extends Controller { period2: Extension.ToThaiNumber(period2), durationKPI: data?.durationKPI, root: - data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator + data && data.rootName != null + ? data.rootName : "-", fullNameEvaluator: fullNameEvaluator, positionEvaluator: @@ -827,7 +913,60 @@ export class ReportController extends Controller { year5: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow).toString()), }, ); - formattedData = combinedData; + formattedData = profileEvaluation.length > 0 + ? combinedData + : { + fullName: "-", + position: "-", + posType: "-", + posLevel: "-", + affiliation: "-", + summaryPointAPR1: "-", + textPointAPR1: "-", + periodAPR1: "-", + yearAPR1: "-", + summaryPointOCT1: "-", + textPointOCT1: "-", + periodOCT1: "-", + yearOCT1: "-", + summaryPointAPR2: "-", + textPointAPR2: "-", + periodAPR2: "-", + yearAPR2: "-", + summaryPointOCT2: "-", + textPointOCT2: "-", + periodOCT2: "-", + yearOCT2: "-", + summaryPointAPR3: "-", + textPointAPR3: "-", + periodAPR3: "-", + yearAPR3: "-", + summaryPointOCT3: "-", + textPointOCT3: "-", + periodOCT3: "-", + yearOCT3: "-", + summaryPointAPR4: "-", + textPointAPR4: "-", + periodAPR4: "-", + yearAPR4: "-", + summaryPointOCT4: "-", + textPointOCT4: "-", + periodOCT4: "-", + yearOCT4: "-", + summaryPointAPR5: "-", + textPointAPR5: "-", + periodAPR5: "-", + yearAPR5: "-", + summaryPointOCT5: "-", + textPointOCT5: "-", + periodOCT5: "-", + yearOCT5: "-", + year1: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 4).toString()), + year2: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 3).toString()), + year3: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 2).toString()), + year4: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 1).toString()), + year5: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow).toString()), + }; // } } } @@ -1010,7 +1149,42 @@ export class ReportController extends Controller { year3: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow).toString()), }, ); - formattedData = combinedData; + formattedData = profileEvaluation.length > 0 + ? combinedData + : { + fullName: "-", + position: "-", + posType: "-", + posLevel: "-", + affiliation: "-", + summaryPointAPR1: "-", + textPointAPR1: "-", + periodAPR1: "-", + yearAPR1: "-", + summaryPointOCT1: "-", + textPointOCT1: "-", + periodOCT1: "-", + yearOCT1: "-", + summaryPointAPR2: "-", + textPointAPR2: "-", + periodAPR2: "-", + yearAPR2: "-", + summaryPointOCT2: "-", + textPointOCT2: "-", + periodOCT2: "-", + yearOCT2: "-", + summaryPointAPR3: "-", + textPointAPR3: "-", + periodAPR3: "-", + yearAPR3: "-", + summaryPointOCT3: "-", + textPointOCT3: "-", + periodOCT3: "-", + yearOCT3: "-", + year1: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 2).toString()), + year2: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 1).toString()), + year3: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow).toString()), + }; // } } } @@ -1036,24 +1210,33 @@ export class ReportController extends Controller { // : "" return { no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - developName: x.topicEvaluator ? x.topicEvaluator : "", - developEvaluator: x.developEvaluator ? x.developEvaluator : "", - // target: target_ ? target_.target : "", + fullName: x.prefix != null && x.firstName != null && x.lastName != null + ? `${x.prefix}${x.firstName} ${x.lastName}` + : "-", + position: x.position ? x.position : "-", + posLevelName: x.posLevelName ? x.posLevelName : "-", + developName: x.topicEvaluator ? x.topicEvaluator : "-", + developEvaluator: x.developEvaluator ? x.developEvaluator : "-", target: "-", - timeEvaluator: x.timeEvaluator ? Extension.ToThaiNumber(x.timeEvaluator) : "", - developResults: "-", //วิธีการวัดผลการพัฒนา - // isDev70, - // isDev20, - // isDev10, + timeEvaluator: x.timeEvaluator ? Extension.ToThaiNumber(x.timeEvaluator) : "-", + developResults: "-", evaluationResults: x.evaluationResults ? Extension.EvaluationResult(x.evaluationResults) - : "", + : "-", }; }) - : [{}], + : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + developName: "-", + developEvaluator: "-", + target: "-", + timeEvaluator: "-", + developResults: "-", + evaluationResults: "-" + }], ); formattedData = { year: data.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-", @@ -1061,10 +1244,23 @@ export class ReportController extends Controller { period2: Extension.ToThaiNumber(period2), durationKPI: data.durationKPI, root: - data.kpiUserEvaluations != null && data.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator - : "-", - userEvaluations: userEvaluations_, + data && data.rootName != null + ? data.rootName + : "-", + userEvaluations: userEvaluations_.length > 0 + ? userEvaluations_ + : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + developName: "-", + developEvaluator: "-", + target: "-", + timeEvaluator: "-", + developResults: "-", + evaluationResults: "-" + }], }; } if (requestBody.type == "KPI8") { @@ -1214,22 +1410,38 @@ export class ReportController extends Controller { ) .map((x: any, idx: number) => ({ no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", + fullName: x.prefix != null && x.firstName != null && x.lastName != null + ? `${x.prefix}${x.firstName} ${x.lastName}` + : "-", + position: x.position ? x.position : "-", + posLevelName: x.posLevelName ? x.posLevelName : "-", evaluationResults: x.evaluationResults ? Extension.EvaluationResult(x.evaluationResults) - : "", + : "-", })) - : [{}]; + : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + evaluationResults: "-", + }]; formattedData = { root: - data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator + data && data.rootName != null + ? data.rootName : "-", period: data?.durationKPI == "APR" ? "๑" : data?.durationKPI == "OCT" ? "๒" : "-", year: data.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-", - userEvaluations: userEvaluations_.length > 0 ? userEvaluations_ : [{}], + userEvaluations: userEvaluations_.length > 0 + ? userEvaluations_ + : [{ + no: "-", + fullName: "-", + position: "-", + posLevelName: "-", + evaluationResults: "-", + }], }; }