From 3161ccce3ddbbf889d6e2ae89b3751617cab96d4 Mon Sep 17 00:00:00 2001 From: Bright Date: Sat, 15 Feb 2025 15:10:19 +0700 Subject: [PATCH] =?UTF-8?q?KPI=20=E0=B9=81=E0=B8=9A=E0=B8=9A=E0=B8=9F?= =?UTF-8?q?=E0=B8=AD=E0=B8=A3=E0=B9=8C=E0=B8=A1=201=20#1243?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 220 ++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index d58213a..3cf7c44 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -8,6 +8,9 @@ import { KpiPeriod } from "../entities/kpiPeriod"; import { KpiUserEvaluation } from "../entities/kpiUserEvaluation"; import Extension from "../interfaces/extension"; import { KpiUserDevelopment } from "../entities/kpiUserDevelopment"; +import { KpiCapacity } from "../entities/kpiCapacity"; +import { KpiPlan } from "../entities/kpiPlan"; +import { KpiRole } from "../entities/kpiRole"; import CallAPI from "../interfaces/call-api"; @Route("api/v1/kpi/report") @Tags("Report") @@ -16,6 +19,9 @@ export class ReportController extends Controller { private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod); private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation); private kpiUserDevelopmentRepository = AppDataSource.getRepository(KpiUserDevelopment); + private kpiCapacityRepository = AppDataSource.getRepository(KpiCapacity); + private kpiPlanRepository = AppDataSource.getRepository(KpiPlan); + private kpiRoleRepository = AppDataSource.getRepository(KpiRole); @Post("announcement") async GetReportAnnouncement( @@ -1765,4 +1771,218 @@ export class ReportController extends Controller { data: formattedData, }); } + + /** + * API Report แบบกำหนดข้อตกลงการประเมินผลสัมฤทธิ์ของงานและพฤติกรรมการปฏิบัติราชการ + * + * @summary Report แบบกำหนดข้อตกลงการประเมินผลสัมฤทธิ์ของงานและพฤติกรรมการปฏิบัติราชการ + * + * @param {string} id Guid, *Id รายการประเมินผลการปฏิบัติราชการระดับบุคคล + */ + @Get("list/{id}") + async GetReportKpiListGroup1(@Path() id?: string) { + const kpiUserEvaluation = await this.kpiUserEvaluationRepository.findOne({ + relations: [ + "kpiPeriod", + "kpiUserPlanneds", + "kpiUserRoles", + "kpiUserSpecials", + "kpiUserCapacitys", + "kpiUserDevelopments" + ], + where: { + id: id + }, + order: { + createdAt: "DESC", + kpiUserPlanneds: { + createdAt: "DESC" + }, + kpiUserSpecials: { + createdAt: "DESC" + }, + kpiUserCapacitys: { + createdAt: "DESC" + } + } + }); + if (!kpiUserEvaluation) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ประเมิน"); + const isGroup2: boolean = ["ทั่วไป", "วิชาการ"].includes(kpiUserEvaluation.posTypeName); + const Plan = await this.kpiPlanRepository.find(); + const Role = await this.kpiRoleRepository.find(); + const Capacitys = await this.kpiCapacityRepository.find({ + where: { + type: In(["HEAD", "EXECUTIVE", "GROUP"]) + } + }); + let durationKpi_APR = kpiUserEvaluation.kpiPeriod && kpiUserEvaluation.kpiPeriod.durationKPI == "APR" ? `🗹` : `☐` + let durationKpi_OCT = kpiUserEvaluation.kpiPeriod && kpiUserEvaluation.kpiPeriod.durationKPI == "OCT" ? `🗹` : `☐` + let period1:string=""; + let period2:string=""; + if(kpiUserEvaluation.kpiPeriod) { + if (kpiUserEvaluation.kpiPeriod.durationKPI === "APR") { + period1 = `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${Extension.ToThaiFullDate2(kpiUserEvaluation.kpiPeriod.startDate)} ถึง ${Extension.ToThaiFullDate2(kpiUserEvaluation.kpiPeriod.endDate)}`; + let _period2 = await this.kpiPeriodRepository.findOne({ + where: { + year: kpiUserEvaluation.kpiPeriod.year, + durationKPI: "OCT", + }, + }); + period2 = _period2 + ? `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}` + : `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ๑ เมษายน ${Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year)} ถึง ๓๑ กันยายน ${Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year)}`; + } + else if (kpiUserEvaluation.kpiPeriod.durationKPI === "OCT") { + period2 = `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${Extension.ToThaiFullDate2(kpiUserEvaluation.kpiPeriod.startDate)} ถึง ${Extension.ToThaiFullDate2(kpiUserEvaluation.kpiPeriod.endDate)}`; + let _period1 = await this.kpiPeriodRepository.findOne({ + where: { + year: kpiUserEvaluation.kpiPeriod.year, + durationKPI: "APR", + }, + }); + period1 = _period1 + ? `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}` + : `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ๑ ตุลาคม ${Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year-1)} ถึง ๓๑ มีนาคม ${Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year)}`; + } + } + let mapData = { + year: kpiUserEvaluation.kpiPeriod + ? Extension.ToThaiNumber((kpiUserEvaluation.kpiPeriod.year+543).toString()) + : "-", + period: period1 != "" && period2 != "" + ? Extension.ToThaiNumber(`${period1} ${period2}`) + : "-", + fullName: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName}`, + position: kpiUserEvaluation.position ? kpiUserEvaluation.position : "-", + posTypeName: kpiUserEvaluation.posTypeName ? kpiUserEvaluation.posTypeName : "-", + posLevelName: kpiUserEvaluation.posLevelName ? kpiUserEvaluation.posLevelName : "-", + org: kpiUserEvaluation.org ? kpiUserEvaluation.org : "-", + fullnameEvaluator: + `${kpiUserEvaluation.prefixEvaluator}${kpiUserEvaluation.firstNameEvaluator} ${kpiUserEvaluation.lastNameEvaluator}`, + positionEvaluator: kpiUserEvaluation.positionEvaluator, + posTypeNameEvaluator: kpiUserEvaluation.posTypeNameEvaluator, + posLevelNameEvaluator: kpiUserEvaluation.posLevelNameEvaluator, + orgEvaluator: kpiUserEvaluation.orgEvaluator, + fullnameCommander: + `${kpiUserEvaluation.prefixCommander}${kpiUserEvaluation.firstNameCommander} ${kpiUserEvaluation.lastNameCommander}`, + positionCommander: kpiUserEvaluation.positionCommander ? kpiUserEvaluation.positionCommander : "-", + fullnameCommanderHigh: + `${kpiUserEvaluation.prefixCommanderHigh}${kpiUserEvaluation.firstNameCommanderHigh} ${kpiUserEvaluation.lastNameCommanderHigh}`, + positionCommanderHigh: kpiUserEvaluation.positionCommanderHigh ? kpiUserEvaluation.positionCommanderHigh : "-", + planneds: kpiUserEvaluation.kpiUserPlanneds + .map( + x => ({ + name: Plan.find(y => y.id === x.kpiPlanId)?.includingName || "-", + target: x.target ? Extension.ToThaiNumber(x.target.toLocaleString()) : "-", + point1: x.point == 1 ? "✔" : "-", + point2: x.point == 2 ? "✔" : "-", + point3: x.point == 3 ? "✔" : "-", + point4: x.point == 4 ? "✔" : "-", + point5: x.point == 5 ? "✔" : "-", + weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-", + achievement: Extension.ToThaiNumber(`ระดับ ${x.point}`), + summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-", + }) + ), + roles: kpiUserEvaluation.kpiUserRoles + .map( + x => ({ + name: Role.find(y => y.id === x.kpiRoleId)?.includingName || "-", + target: x.target ? Extension.ToThaiNumber(x.target.toLocaleString()) : "-", + point1: x.point == 1 ? "✔" : "-", + point2: x.point == 2 ? "✔" : "-", + point3: x.point == 3 ? "✔" : "-", + point4: x.point == 4 ? "✔" : "-", + point5: x.point == 5 ? "✔" : "-", + weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-", + achievement: Extension.ToThaiNumber(`ระดับ ${x.point}`), + summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-", + }) + ), + specials: kpiUserEvaluation.kpiUserSpecials + .map( + x => ({ + name: x.includingName ?? "-", + target: x.target ? Extension.ToThaiNumber(x.target.toLocaleString()) : "-", + point1: x.point == 1 ? "✔" : "-", + point2: x.point == 2 ? "✔" : "-", + point3: x.point == 3 ? "✔" : "-", + point4: x.point == 4 ? "✔" : "-", + point5: x.point == 5 ? "✔" : "-", + weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-", + achievement: Extension.ToThaiNumber(`ระดับ ${x.point}`), + summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-", + }) + ), + develops: kpiUserEvaluation.kpiUserDevelopments + .map( + x => ({ + name: x.name ?? "-", + target: x.target ? Extension.ToThaiNumber(x.target.toLocaleString()) : "-", + achievement10: x.point == 10 ? `🗹 ${x.achievement10}` : `☐ ${x.achievement10}`, + achievement5: x.point == 5 ? `🗹 ${x.achievement5}` : `☐ ${x.achievement5}`, + achievement0: x.point == 0 ? `🗹 ${x.achievement0}` : `☐ ${x.achievement0}`, + isDevelopment70: x.isDevelopment70 == true ? `🗹 ๗๐ การลงมือปฏิบัติ(โดยผู้บังคับบัญชามอบหมาย)` : `☐ ๗๐ การลงมือปฏิบัติ(โดยผู้บังคับบัญชามอบหมาย)`, + isDevelopment20: x.isDevelopment20 == true ? `🗹 ๒๐ การเรียนรู้จากผู้อื่น Coach/Mentor/Consulting` : `☐ ๒๐ การเรียนรู้จากผู้อื่น Coach/Mentor/Consulting`, + isDevelopment10: x.isDevelopment10 == true ? `🗹 ๑๐ การฝึกอบรมอื่น ๆ` : `☐ ๑๐ การฝึกอบรมอื่น ๆ`, + point: x.point ? Extension.ToThaiNumber(x.point.toLocaleString()) : "-", + summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-", + }) + ), + headCaps: kpiUserEvaluation.kpiUserCapacitys + .filter( + x => Capacitys.some(y => y.id === x.kpiCapacityId && y.type === "HEAD") + ).map( + x => ({ + name: `- ${Capacitys.find(y => y.id === x.kpiCapacityId)?.name}`, + level: x.level ? Extension.ToThaiNumber(x.level.toLocaleString()) : "-", + weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-", + point1: x.point == 1 ? "✔" : "-", + point2: x.point == 2 ? "✔" : "-", + point3: x.point == 3 ? "✔" : "-", + point4: x.point == 4 ? "✔" : "-", + point5: x.point == 5 ? "✔" : "-", + summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-", + }) + ), + executiveCaps: kpiUserEvaluation.kpiUserCapacitys + .filter( + x => Capacitys.some(y => y.id === x.kpiCapacityId && y.type === "EXECUTIVE") + ).map( + x => ({ + name: `- ${Capacitys.find(y => y.id === x.kpiCapacityId)?.name}`, + level: x.level ? Extension.ToThaiNumber(x.level.toLocaleString()) : "-", + weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-", + point1: x.point == 1 ? "✔" : "-", + point2: x.point == 2 ? "✔" : "-", + point3: x.point == 3 ? "✔" : "-", + point4: x.point == 4 ? "✔" : "-", + point5: x.point == 5 ? "✔" : "-", + summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-", + }) + ), + groupCaps: kpiUserEvaluation.kpiUserCapacitys + .filter( + x => Capacitys.some(y => y.id === x.kpiCapacityId && y.type === "GROUP") + ).map( + x => ({ + name: `- ${Capacitys.find(y => y.id === x.kpiCapacityId)?.name}`, + level: x.level ? Extension.ToThaiNumber(x.level.toLocaleString()) : "-", + weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-", + point1: x.point == 1 ? "✔" : "-", + point2: x.point == 2 ? "✔" : "-", + point3: x.point == 3 ? "✔" : "-", + point4: x.point == 4 ? "✔" : "-", + point5: x.point == 5 ? "✔" : "-", + summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-", + }) + ), + }; + + return new HttpSuccess({ + template: !isGroup2 ? "KPI_ListGroup1" : "KPI_ListGroup2&3", + reportName: !isGroup2 ? "KPI_ListGroup1" : "KPI_ListGroup2&3", + data: mapData, + }); + } }