From e9120f63ba45bfcf16cea8ab682e3250d063f6ce Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 10 Feb 2025 09:26:12 +0700 Subject: [PATCH 1/3] update viewProfileEva --- ...9153948936-update_viewProfileEvaluation.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/migration/1739153948936-update_viewProfileEvaluation.ts diff --git a/src/migration/1739153948936-update_viewProfileEvaluation.ts b/src/migration/1739153948936-update_viewProfileEvaluation.ts new file mode 100644 index 00000000..8a3fc3cb --- /dev/null +++ b/src/migration/1739153948936-update_viewProfileEvaluation.ts @@ -0,0 +1,35 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateViewProfileEvaluation1739153948936 implements MigrationInterface { + name = 'UpdateViewProfileEvaluation1739153948936' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_profile_evaluation","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_profile_evaluation\``); + await queryRunner.query(`CREATE VIEW \`view_profile_evaluation\` AS SELECT + \`profileId\`,\`period\`,\`year\`,\`posMaster\`.\`orgRootId\`,\`posMaster\`.\`orgChild1Id\`,\`posMaster\`.\`orgChild2Id\`,\`posMaster\`.\`orgChild3Id\`,\`posMaster\`.\`orgChild4Id\`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result + FROM\`profileAssessment\` + LEFT JOIN \`profile\` ON \`profileAssessment\`.\`profileId\` = \`profile\`.\`id\` + LEFT JOIN \`posMaster\` ON \`profile\`.\`id\` = \`posMaster\`.\`current_holderId\` + LEFT JOIN \`orgRevision\` ON \`posMaster\`.\`orgRevisionId\` = \`orgRevision\`.\`id\` + WHERE \`period\` Is not null + AND \`orgRevision\`.\`orgRevisionIsCurrent\` = true + GROUP BY\`profileId\`,\`period\`,\`year\`,\`orgRootId\`,\`orgChild1Id\`,\`orgChild2Id\`,\`orgChild3Id\`,\`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_evaluation","SELECT \n `profileId`,`period`,`year`,`posMaster`.`orgRootId`,`posMaster`.`orgChild1Id`,`posMaster`.`orgChild2Id`,`posMaster`.`orgChild3Id`,`posMaster`.`orgChild4Id`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result\n FROM`profileAssessment` \n LEFT JOIN `profile` ON `profileAssessment`.`profileId` = `profile`.`id`\n LEFT JOIN `posMaster` ON `profile`.`id` = `posMaster`.`current_holderId`\n LEFT JOIN `orgRevision` ON `posMaster`.`orgRevisionId` = `orgRevision`.`id`\n WHERE `period` Is not null\n AND `orgRevision`.`orgRevisionIsCurrent` = true\n GROUP BY`profileId`,`period`,`year`,`orgRootId`,`orgChild1Id`,`orgChild2Id`,`orgChild3Id`,`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_evaluation","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_profile_evaluation\``); + await queryRunner.query(`CREATE VIEW \`view_profile_evaluation\` AS 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`); + 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_evaluation","SELECT \n `profileId`, `period`, `year`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result\n FROM `profileAssessment` \n WHERE `period` Is not null\n GROUP BY `profileId`, `period`, `year`\n ORDER BY `year` desc , `period` asc"]); + } + +} From cf6409161285604e71bb9521be6313aa7883314a Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 10 Feb 2025 10:48:15 +0700 Subject: [PATCH 2/3] add api calculateEvaluation --- .../OrganizationUnauthorizeController.ts | 71 ++++++++++++++++--- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 0e5f4cac..e0f32b9d 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -1174,25 +1174,46 @@ export class OrganizationUnauthorizeController extends Controller { * @summary ผลการประเมิน 5 ปีย้อนหลังนับจากปีปัจจุบัน * */ - @Get("calculate-Eva/{node}/{nodeId}") - async calculateEva( - @Path() node: string, - @Path() nodeId: string, + @Get("calculateEvaluation") + async calculateEvaluation( + // @Path() node: number, + // @Path() nodeId: string, ) { + + // let condition :any = {}; + // switch (node) { + // case 0: + // condition = {orgRootId: nodeId} + // break; + // case 1: + // condition = {orgChild1Id: nodeId} + // break; + // case 2: + // condition = {orgChild2Id: nodeId} + // break; + // case 3: + // condition = {orgChild3Id: nodeId} + // break; + // case 4: + // condition = {orgChild4Id: nodeId} + // break; + // default: + // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // } const lists = await this.viewProfileEvaluationRepo.find({ // where:{ - // profileId: profileId + // ...condition // } }) - const formattedResults: any = {}; + const groupData: any = {}; const year = new Date().getFullYear(); const years = [year, year - 1, year - 2, year - 3, year - 4]; lists.forEach((item: any) => { - if (!formattedResults[item.profileId]) { - formattedResults[item.profileId] = { + if (!groupData[item.profileId]) { + groupData[item.profileId] = { profileId: item.profileId, yearAPR1: "-", periodAPR1: "-", resultAPR1: "-", yearOCT1: "-", periodOCT1: "-", resultOCT1: "-", @@ -1214,12 +1235,40 @@ export class OrganizationUnauthorizeController extends Controller { const periodKey = `period${item.period}${yearSuffix}`; const resultKey = `result${item.period}${yearSuffix}`; - formattedResults[item.profileId][yearKey] = item.year; - formattedResults[item.profileId][periodKey] = item.period; - formattedResults[item.profileId][resultKey] = item.result; + groupData[item.profileId][yearKey] = item.year; + groupData[item.profileId][periodKey] = item.period; + groupData[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, + })); + return new HttpSuccess(formattedResults); } From 8c72f7df8793055a8f2281ce9acff16bce7dfee5 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 10 Feb 2025 11:53:39 +0700 Subject: [PATCH 3/3] fix command --- src/controllers/CommandController.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index b1b76e79..8fad6247 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -4848,7 +4848,6 @@ export class CommandController extends Controller { } profile.keycloak = checkUser[0].id; } - positionNew.positionIsSelected = true; profile.posLevelId = positionNew.posLevelId; profile.posTypeId = positionNew.posTypeId; @@ -4872,11 +4871,11 @@ export class CommandController extends Controller { root: posMaster.orgRoot.orgRootName, rootId: posMaster.orgRootId, rootShortName: posMaster.orgRoot.orgRootShortName, - rootDnaId: posMaster.orgRoot.ancestorDNA, - child1DnaId: posMaster.orgChild1.ancestorDNA, - child2DnaId: posMaster.orgChild2.ancestorDNA, - child3DnaId: posMaster.orgChild3.ancestorDNA, - child4DnaId: posMaster.orgChild4.ancestorDNA, + rootDnaId: posMaster.orgRoot.ancestorDNA??_null, + child1DnaId: posMaster.orgChild1.ancestorDNA??_null, + child2DnaId: posMaster.orgChild2.ancestorDNA??_null, + child3DnaId: posMaster.orgChild3.ancestorDNA??_null, + child4DnaId: posMaster.orgChild4.ancestorDNA??_null, }); await this.profileEmployeeRepository.save(profile); await this.employeePositionRepository.save(positionNew);