From ee71e985abd49f0816ac8ff453fda66320beb6c2 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 17 Feb 2025 10:57:03 +0700 Subject: [PATCH 1/4] add viewProfileEmp --- .../OrganizationUnauthorizeController.ts | 11 ++-- src/controllers/ReportController.ts | 7 +-- .../view/viewProfileEmployeeEvaluation.ts | 55 +++++++++++++++++++ 3 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 src/entities/view/viewProfileEmployeeEvaluation.ts diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index e0f32b9d..0f9506b7 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -1174,12 +1174,12 @@ export class OrganizationUnauthorizeController extends Controller { * @summary ผลการประเมิน 5 ปีย้อนหลังนับจากปีปัจจุบัน * */ - @Get("calculateEvaluation") + @Get("calculateEvaluation/{type}") async calculateEvaluation( - // @Path() node: number, + @Path() type: string, // @Path() nodeId: string, ) { - + const conType = type.toUpperCase(); // let condition :any = {}; // switch (node) { // case 0: @@ -1206,7 +1206,10 @@ export class OrganizationUnauthorizeController extends Controller { // ...condition // } }) - + // if(conType == "EMPLOYEE"){ + // const lists = await this.viewProfileEmployeeEvaluationRepo.find({ + // }) + // } const groupData: any = {}; const year = new Date().getFullYear(); const years = [year, year - 1, year - 2, year - 3, year - 4]; diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 1139f2d3..b35aa04b 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -83,7 +83,7 @@ export class ReportController extends Controller { .andWhere(rootId?'posMaster.orgRootId = :rootId': "1=1", { rootId: rootId }) .andWhere('posMaster.current_holderId Is Not Null') .andWhere('positions.positionIsSelected = :positionIsSelected', { positionIsSelected: true }) - .andWhere( yearInAD && yearInAD != null? 'YEAR(current_holder.dateAppoint) = :year': "1=1", { year: yearInAD }) + .andWhere( yearInAD && yearInAD != null? 'YEAR(current_holder.dateAppoint) = :year': "1=1", { year: yearInAD }) //ตอนนี้ where ที่วันที่บรรจุ (รอ prove) ว่าจะ where ที่ไหน .andWhere(` TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) >= :minAge AND TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) <= :maxAge @@ -137,12 +137,11 @@ export class ReportController extends Controller { ...item , count: Extension.ToThaiNumber(item.count.toString()), })); - return new HttpSuccess({ template: "registry-officer", reportName: "xlsx-report", data: { - year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()), + year: year?Extension.ToThaiNumber((year + 543).toString()):Extension.ToThaiNumber(((new Date()).getFullYear()+543).toString()), date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), list: result }, @@ -248,7 +247,7 @@ export class ReportController extends Controller { template: "registry-emp", reportName: "xlsx-report", data: { - year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()), + year: year?Extension.ToThaiNumber((year + 543).toString()):Extension.ToThaiNumber(((new Date()).getFullYear()+543).toString()), date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), list: result }, diff --git a/src/entities/view/viewProfileEmployeeEvaluation.ts b/src/entities/view/viewProfileEmployeeEvaluation.ts new file mode 100644 index 00000000..b738697d --- /dev/null +++ b/src/entities/view/viewProfileEmployeeEvaluation.ts @@ -0,0 +1,55 @@ +import { ViewColumn, ViewEntity } from "typeorm"; + +@ViewEntity({ + expression: `SELECT + \`profileEmployeeId\`, + \`period\`, + \`year\`, + \`employeePosMaster\`.\`orgRootId\`, + \`employeePosMaster\`.\`orgChild1Id\`, + \`employeePosMaster\`.\`orgChild2Id\`, + \`employeePosMaster\`.\`orgChild3Id\`, + \`employeePosMaster\`.\`orgChild4Id\`, + COUNT(*) AS recordCount, + SUM(pointSum) AS totalPointSum, + SUM(pointSum) / COUNT(*) AS result + FROM \`profileAssessment\` + LEFT JOIN \`profileEmployee\` ON \`profileAssessment\`.\`profileEmployeeId\` = \`profileEmployee\`.\`id\` + LEFT JOIN \`employeePosMaster\` ON \`profileEmployee\`.\`id\` = \`employeePosMaster\`.\`current_holderId\` + LEFT JOIN \`orgRevision\` ON \`employeePosMaster\`.\`orgRevisionId\` = \`orgRevision\`.\`id\` + WHERE \`period\` IS NOT NULL + AND \`orgRevision\`.\`orgRevisionIsCurrent\` = TRUE + GROUP BY \`profileEmployeeId\`, \`period\`, \`year\`, + \`employeePosMaster\`.\`orgRootId\`, + \`employeePosMaster\`.\`orgChild1Id\`, + \`employeePosMaster\`.\`orgChild2Id\`, + \`employeePosMaster\`.\`orgChild3Id\`, + \`employeePosMaster\`.\`orgChild4Id\` + ORDER BY \`year\` DESC, \`period\` ASC; + `, +}) + +export class viewProfileEmployeeEvaluation { + @ViewColumn() + profileEmployeeId: string; + @ViewColumn() + period: string; + @ViewColumn() + year: number; + @ViewColumn() + orgRootId: string; + @ViewColumn() + orgChild1Id: string; + @ViewColumn() + orgChild2Id: string; + @ViewColumn() + orgChild3Id: string; + @ViewColumn() + orgChild4Id: string; + @ViewColumn() + recordCount: number; + @ViewColumn() + totalPointSum: number; + @ViewColumn() + result: number; +} From 188a028becf04822532f4bb6d3a95ae73b04aff1 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 17 Feb 2025 12:07:22 +0700 Subject: [PATCH 2/4] migrate --- src/entities/OFFICER.ts | 12 +++--- ...503699-addViewProfileEmployeeEvaluation.ts | 41 +++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 src/migration/1739768503699-addViewProfileEmployeeEvaluation.ts diff --git a/src/entities/OFFICER.ts b/src/entities/OFFICER.ts index 17632f72..58edfd64 100644 --- a/src/entities/OFFICER.ts +++ b/src/entities/OFFICER.ts @@ -12,12 +12,12 @@ export class OFFICER { // }) // RET_YEAR: string; - @Column({ - nullable: true, - type: "text", - default: null, - }) - ID: string; + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // ID: string; @Column({ nullable: true, diff --git a/src/migration/1739768503699-addViewProfileEmployeeEvaluation.ts b/src/migration/1739768503699-addViewProfileEmployeeEvaluation.ts new file mode 100644 index 00000000..e42452f8 --- /dev/null +++ b/src/migration/1739768503699-addViewProfileEmployeeEvaluation.ts @@ -0,0 +1,41 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddViewProfileEmployeeEvaluation1739768503699 implements MigrationInterface { + name = 'AddViewProfileEmployeeEvaluation1739768503699' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE VIEW \`view_profile_employee_evaluation\` AS SELECT + \`profileEmployeeId\`, + \`period\`, + \`year\`, + \`employeePosMaster\`.\`orgRootId\`, + \`employeePosMaster\`.\`orgChild1Id\`, + \`employeePosMaster\`.\`orgChild2Id\`, + \`employeePosMaster\`.\`orgChild3Id\`, + \`employeePosMaster\`.\`orgChild4Id\`, + COUNT(*) AS recordCount, + SUM(pointSum) AS totalPointSum, + SUM(pointSum) / COUNT(*) AS result + FROM \`profileAssessment\` + LEFT JOIN \`profileEmployee\` ON \`profileAssessment\`.\`profileEmployeeId\` = \`profileEmployee\`.\`id\` + LEFT JOIN \`employeePosMaster\` ON \`profileEmployee\`.\`id\` = \`employeePosMaster\`.\`current_holderId\` + LEFT JOIN \`orgRevision\` ON \`employeePosMaster\`.\`orgRevisionId\` = \`orgRevision\`.\`id\` + WHERE \`period\` IS NOT NULL + AND \`orgRevision\`.\`orgRevisionIsCurrent\` = TRUE + GROUP BY \`profileEmployeeId\`, \`period\`, \`year\`, + \`employeePosMaster\`.\`orgRootId\`, + \`employeePosMaster\`.\`orgChild1Id\`, + \`employeePosMaster\`.\`orgChild2Id\`, + \`employeePosMaster\`.\`orgChild3Id\`, + \`employeePosMaster\`.\`orgChild4Id\` + ORDER BY \`year\` DESC, \`period\` ASC; + `); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_profile_employee_evaluation","SELECT \n `profileEmployeeId`,\n `period`,\n `year`,\n `employeePosMaster`.`orgRootId`,\n `employeePosMaster`.`orgChild1Id`,\n `employeePosMaster`.`orgChild2Id`,\n `employeePosMaster`.`orgChild3Id`,\n `employeePosMaster`.`orgChild4Id`, \n COUNT(*) AS recordCount, \n SUM(pointSum) AS totalPointSum, \n SUM(pointSum) / COUNT(*) AS result\n FROM `profileAssessment` \n LEFT JOIN `profileEmployee` ON `profileAssessment`.`profileEmployeeId` = `profileEmployee`.`id`\n LEFT JOIN `employeePosMaster` ON `profileEmployee`.`id` = `employeePosMaster`.`current_holderId`\n LEFT JOIN `orgRevision` ON `employeePosMaster`.`orgRevisionId` = `orgRevision`.`id`\n WHERE `period` IS NOT NULL\n AND `orgRevision`.`orgRevisionIsCurrent` = TRUE\n GROUP BY `profileEmployeeId`, `period`, `year`, \n `employeePosMaster`.`orgRootId`, \n `employeePosMaster`.`orgChild1Id`, \n `employeePosMaster`.`orgChild2Id`, \n `employeePosMaster`.`orgChild3Id`, \n `employeePosMaster`.`orgChild4Id`\n ORDER BY `year` DESC, `period` ASC;"]); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_profile_employee_evaluation","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_profile_employee_evaluation\``); + } + +} From a05e6178fa9840c6d74f47b5ee9462080f5c86a8 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 17 Feb 2025 14:46:25 +0700 Subject: [PATCH 3/4] update --- src/controllers/ImportDataController.ts | 6 +- .../OrganizationUnauthorizeController.ts | 81 +++++++++---------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 0e4ada5c..de280f18 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -122,7 +122,7 @@ export class ImportDataController extends Controller { // } const existingProfile = await this.profileRepo.findOne({ - where: { citizenId: item.ID }, + where: { citizenId: item.id.toString() }, }); if (existingProfile) { profile.id = existingProfile.id; @@ -152,7 +152,7 @@ export class ImportDataController extends Controller { } let dateRetire = new Date(item.BORN); - profile.citizenId = item.ID == "" ? "" : item.ID; + profile.citizenId = item.id.toString() == "" ? "" : item.id.toString(); profile.rank = item.RANK_NAME == "" || item.RANK_NAME == "นาย" || @@ -1817,7 +1817,7 @@ export class ImportDataController extends Controller { rowCount++; const existingProfile = await this.profileRepo.findOne({ - where: { citizenId: item.ID }, + where: { citizenId: item.id.toString() }, }); if (existingProfile == null) { continue; diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 0f9506b7..5ae837c2 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -16,6 +16,7 @@ import { ProfileAssessment } from "../entities/ProfileAssessment"; import { log } from "console"; import { format } from "path"; import { viewProfileEvaluation } from "../entities/view/viewProfileEvaluation"; +import { viewProfileEmployeeEvaluation } from "../entities/view/viewProfileEmployeeEvaluation"; @Route("api/v1/org/unauthorize") @Tags("OrganizationUnauthorize") @@ -30,6 +31,7 @@ export class OrganizationUnauthorizeController extends Controller { private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private profileAssessmentRepo = AppDataSource.getRepository(ProfileAssessment); private viewProfileEvaluationRepo = AppDataSource.getRepository(viewProfileEvaluation); + private viewProfileEmployeeEvaluationRepo = AppDataSource.getRepository(viewProfileEmployeeEvaluation); /** * API รายชื่อราชการที่เลื่อนเงินเดือน (unauthorize) @@ -1200,24 +1202,23 @@ export class OrganizationUnauthorizeController extends Controller { // default: // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); // } - - const lists = await this.viewProfileEvaluationRepo.find({ + let lists = null; + lists = await this.viewProfileEvaluationRepo.find({ // where:{ // ...condition // } }) - // if(conType == "EMPLOYEE"){ - // const lists = await this.viewProfileEmployeeEvaluationRepo.find({ - // }) - // } + if(conType == "EMPLOYEE"){ + lists = await this.viewProfileEmployeeEvaluationRepo.find({}) + } const groupData: any = {}; const year = new Date().getFullYear(); const years = [year, year - 1, year - 2, year - 3, year - 4]; lists.forEach((item: any) => { - if (!groupData[item.profileId]) { - groupData[item.profileId] = { - profileId: item.profileId, + if (!groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId]) { + groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId] = { + profileId: conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId, yearAPR1: "-", periodAPR1: "-", resultAPR1: "-", yearOCT1: "-", periodOCT1: "-", resultOCT1: "-", yearAPR2: "-", periodAPR2: "-", resultAPR2: "-", @@ -1230,7 +1231,6 @@ export class OrganizationUnauthorizeController extends Controller { yearOCT5: "-", periodOCT5: "-", resultOCT5: "-" }; } - const yearIndex = years.indexOf(parseInt(item.year)); if (yearIndex !== -1) { const yearSuffix = yearIndex + 1; @@ -1238,40 +1238,39 @@ export class OrganizationUnauthorizeController extends Controller { const periodKey = `period${item.period}${yearSuffix}`; const resultKey = `result${item.period}${yearSuffix}`; - groupData[item.profileId][yearKey] = item.year; - groupData[item.profileId][periodKey] = item.period; - groupData[item.profileId][resultKey] = item.result; + groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId][yearKey] = item.year; + groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId][periodKey] = item.period; + groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId][resultKey] = item.result; } }); - - const formattedResults = Object.values(groupData).map((item: any) => ({ - profileId: item.profileId, - yearAPR1: item.yearAPR1, - periodAPR1: item.periodAPR1, - resultAPR1: item.resultAPR1, - yearOCT1: item.yearOCT1, - periodOCT1: item.periodOCT1, - resultOCT1: item.resultOCT1, - yearAPR2: item.yearAPR2, - periodAPR2: item.periodAPR2, - resultAPR2: item.resultAPR2, - yearOCT2: item.yearOCT2, - periodOCT2: item.periodOCT2, - resultOCT2: item.resultOCT2, - yearAPR3: item.yearAPR3, - periodAPR3: item.periodAPR3, - resultAPR3: item.resultAPR3, - yearOCT3: item.yearOCT3, - periodOCT3: item.periodOCT3, - resultOCT3: item.resultOCT3, - yearAPR4: item.yearAPR4, - periodAPR4: item.periodAPR4, - resultAPR4: item.resultAPR4, - yearOCT4: item.yearOCT4, - periodOCT4: item.periodOCT4, - resultOCT4: item.resultOCT4, + const formattedResults = Object.values(groupData).map((x: any) => ({ + profileId: x.profileId, + yearAPR1: x.yearAPR1, + periodAPR1: x.periodAPR1, + resultAPR1: x.resultAPR1, + yearOCT1: x.yearOCT1, + periodOCT1: x.periodOCT1, + resultOCT1: x.resultOCT1, + yearAPR2: x.yearAPR2, + periodAPR2: x.periodAPR2, + resultAPR2: x.resultAPR2, + yearOCT2: x.yearOCT2, + periodOCT2: x.periodOCT2, + resultOCT2: x.resultOCT2, + yearAPR3: x.yearAPR3, + periodAPR3: x.periodAPR3, + resultAPR3: x.resultAPR3, + yearOCT3: x.yearOCT3, + periodOCT3: x.periodOCT3, + resultOCT3: x.resultOCT3, + yearAPR4: x.yearAPR4, + periodAPR4: x.periodAPR4, + resultAPR4: x.resultAPR4, + yearOCT4: x.yearOCT4, + periodOCT4: x.periodOCT4, + resultOCT4: x.resultOCT4, })); - + return new HttpSuccess(formattedResults); } From 108d2356b988f80569995063d5bea0ee295d054b Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 17 Feb 2025 17:12:50 +0700 Subject: [PATCH 4/4] fix --- src/controllers/OrganizationUnauthorizeController.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 5ae837c2..c73d2f23 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -1269,6 +1269,12 @@ export class OrganizationUnauthorizeController extends Controller { yearOCT4: x.yearOCT4, periodOCT4: x.periodOCT4, resultOCT4: x.resultOCT4, + yearAPR5: x.yearAPR5, + periodAPR5: x.periodAPR5, + resultAPR5: x.resultAPR5, + yearOCT5: x.yearOCT5, + periodOCT5: x.periodOCT5, + resultOCT5: x.resultOCT5, })); return new HttpSuccess(formattedResults);