From ef88894ea43d9dbe905a9f161d3f1ccdf9a05555 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 6 Feb 2025 17:16:09 +0700 Subject: [PATCH] add view --- .../OrganizationUnauthorizeController.ts | 55 ++++++++++++++++++- src/entities/view/viewProfileEvaluation.ts | 25 +++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/entities/view/viewProfileEvaluation.ts diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 8e58f395..aa698960 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -1,10 +1,10 @@ -import { Controller, Get, Post, Route, Tags, Body, Path, Response, Patch } from "tsoa"; +import { Controller, Get, Post, Route, Tags, Body, Path, Response, Patch, Query } from "tsoa"; import { OrgRevision } from "../entities/OrgRevision"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; -import { Brackets, IsNull, Not } from "typeorm"; +import { Brackets, In, IsNull, Not } from "typeorm"; import { OrgRoot } from "../entities/OrgRoot"; import { PosMaster } from "../entities/PosMaster"; import { calculateRetireDate } from "../interfaces/utils"; @@ -12,6 +12,9 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { Profile } from "../entities/Profile"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import HttpStatus from "../interfaces/http-status"; +import { ProfileAssessment } from "../entities/ProfileAssessment"; +import { log } from "console"; +import { format } from "path"; @Route("api/v1/org/unauthorize") @Tags("OrganizationUnauthorize") @@ -24,6 +27,7 @@ export class OrganizationUnauthorizeController extends Controller { private orgRootRepository = AppDataSource.getRepository(OrgRoot); private profileRepo = AppDataSource.getRepository(Profile); private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); + private profileAssessmentRepo = AppDataSource.getRepository(ProfileAssessment); /** * API รายชื่อราชการที่เลื่อนเงินเดือน (unauthorize) @@ -1161,6 +1165,53 @@ export class OrganizationUnauthorizeController extends Controller { return new HttpSuccess("Email verified successfully."); } + + /** + * API ผลการประเมิน 5 ปีย้อนหลังนับจากปีปัจจุบัน + * + * @summary ผลการประเมิน 5 ปีย้อนหลังนับจากปีปัจจุบัน + * + */ + @Get("calculate-Eva/{profileId}") + async calculateEva( + @Path() profileId: string, + ) { + + // const list = await this.viewProfileEvaluation.findOne({ + // where: { + // profileId: profileId, + // }, + // }); + + // const formattedData = list.map((item: any) => { + // const year = new Date().getFullYear(); + // const result: any = {}; + + // for (let i = 1; i <= 5; i++) { + // const currentYear = year - (i - 1); + // const periodKey = `periodAPR${i}`; + // const resultKey = `resultAPR${i}`; + + // result[`yearAPR${i}`] = item.year === currentYear ? item.year : "-"; + // result[periodKey] = item.period ? item.period : "-"; + // result[resultKey] = item.result ? item.result : "-"; + + // const octYear = year - (i - 1); + // const octPeriodKey = `periodOCT${i}`; + // const octResultKey = `resultOCT${i}`; + + // result[`yearOCT${i}`] = item.year === octYear ? item.year : "-"; + // result[octPeriodKey] = item.period ? item.period : "-"; + // result[octResultKey] = item.result ? item.result : "-"; + // } + + // return result; + // }); + + return new HttpSuccess(); + } + + // @Patch("retirement") // public async updateStatusRetirement( // @Body() diff --git a/src/entities/view/viewProfileEvaluation.ts b/src/entities/view/viewProfileEvaluation.ts new file mode 100644 index 00000000..115b1e1b --- /dev/null +++ b/src/entities/view/viewProfileEvaluation.ts @@ -0,0 +1,25 @@ +import { ViewColumn, ViewEntity } from "typeorm"; + +@ViewEntity({ + expression: `SELECT + \`profileId\`, \`period\`, \`year\`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result + FROM \`profileAssessment\` + WHERE \`period\` Is not null + GROUP BY \`profileId\`, \`period\`, \`year\` + ORDER BY \`year\` desc , \`period\` asc +`, +}) +export class viewDirectorActing { + @ViewColumn() + profileId: string; + @ViewColumn() + period: string; + @ViewColumn() + year: number; + @ViewColumn() + recordCount: number; + @ViewColumn() + totalPointSum: number; + @ViewColumn() + result: number; +}