From 047ebd5bb12ade0eda991d4da7bdfc2a4a9c68dd Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 26 Jun 2024 23:27:33 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=AB=E0=B8=95=E0=B8=B8=E0=B8=9C?= =?UTF-8?q?=E0=B8=A5=20kpi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/KpiReasonController.ts | 10 +- .../KpiUserEvaluationController.ts | 128 ++++++++++++++++-- src/entities/kpiUserEvaluation.ts | 40 ++++-- ...19393220115-update_table_summaryPoint_0.ts | 28 ++++ ...719398567558-update_table_summaryWeight.ts | 18 +++ 5 files changed, 196 insertions(+), 28 deletions(-) create mode 100644 src/migration/1719393220115-update_table_summaryPoint_0.ts create mode 100644 src/migration/1719398567558-update_table_summaryWeight.ts diff --git a/src/controllers/KpiReasonController.ts b/src/controllers/KpiReasonController.ts index 5472a24..26332f7 100644 --- a/src/controllers/KpiReasonController.ts +++ b/src/controllers/KpiReasonController.ts @@ -80,7 +80,7 @@ export class kpiReasonController extends Controller { let kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonPlan(), requestBody); kpiUserEvaluationReason.type = type.trim().toUpperCase(); - if (type.trim().toUpperCase() == "PROBLEM") { + if (type.trim().toUpperCase() == "PROGRESS") { const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.findOne({ where: { id: id }, relations: ["kpiUserPlanned", "kpiUserPlanned.kpiUserEvaluation"], @@ -267,7 +267,7 @@ export class kpiReasonController extends Controller { }); let kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonRole(), requestBody); kpiUserEvaluationReason.type = type.trim().toUpperCase(); - if (type.trim().toUpperCase() == "PROBLEM") { + if (type.trim().toUpperCase() == "PROGRESS") { const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.findOne({ where: { id: id }, relations: ["kpiUserRole", "kpiUserRole.kpiUserEvaluation"], @@ -458,7 +458,7 @@ export class kpiReasonController extends Controller { requestBody, ); kpiUserEvaluationReason.type = type.trim().toUpperCase(); - if (type.trim().toUpperCase() == "PROBLEM") { + if (type.trim().toUpperCase() == "PROGRESS") { const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.findOne({ where: { id: id }, relations: ["kpiUserSpecial", "kpiUserSpecial.kpiUserEvaluation"], @@ -648,7 +648,7 @@ export class kpiReasonController extends Controller { requestBody, ); kpiUserEvaluationReason.type = type.trim().toUpperCase(); - if (type.trim().toUpperCase() == "PROBLEM") { + if (type.trim().toUpperCase() == "PROGRESS") { const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.findOne({ where: { id: id }, relations: ["kpiUserDevelopment", "kpiUserDevelopment.kpiUserEvaluation"], @@ -842,7 +842,7 @@ export class kpiReasonController extends Controller { requestBody, ); kpiUserEvaluationReason.type = type.trim().toUpperCase(); - if (type.trim().toUpperCase() == "PROBLEM") { + if (type.trim().toUpperCase() == "PROGRESS") { const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.findOne({ where: { id: id }, relations: ["kpiUserCapacity", "kpiUserCapacity.kpiUserEvaluation"], diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index fd076dd..5a76f4b 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -100,19 +100,24 @@ export class KpiUserEvaluationController extends Controller { requestBody.status != null && requestBody.status != undefined ? requestBody.status.trim().toUpperCase() == "NEW" ? `evaluationStatus LIKE CASE WHEN evaluatorId = "${profileId}" THEN "NEW_EVALUATOR" WHEN commanderId = "${profileId}" THEN "NEW_COMMANDER" WHEN commanderHighId = "${profileId}" THEN "NEW_COMMANDER_HIGH" ELSE "${requestBody.status.trim().toUpperCase()}" END` - : requestBody.status.trim().toUpperCase() == "EVALUATING_EVALUATOR" - ? requestBody.evaluating == null || requestBody.evaluating == undefined - ? `evaluationStatus LIKE CASE WHEN evaluatorId = "${profileId}" THEN "EVALUATING_EVALUATOR" WHEN commanderId = "${profileId}" THEN "EVALUATING_COMMANDER" WHEN commanderHighId = "${profileId}" THEN "EVALUATING_COMMANDER_HIGH" ELSE "${requestBody.status.trim().toUpperCase()}" END` - : requestBody.evaluating == true - ? `evaluationStatus LIKE CASE WHEN evaluatorId = "${profileId}" THEN "EVALUATING_EVALUATOR" ELSE "${requestBody.status.trim().toUpperCase()}" END` - : `evaluationStatus LIKE CASE WHEN commanderId = "${profileId}" THEN "EVALUATING_COMMANDER" WHEN commanderHighId = "${profileId}" THEN "EVALUATING_COMMANDER_HIGH" ELSE "${requestBody.status.trim().toUpperCase()}" END` - : "evaluationStatus LIKE :status" + : requestBody.status.trim().toUpperCase() == "EVALUATING_EVALUATOR" || + requestBody.status.trim().toUpperCase() == "EVALUATING" + ? "evaluationStatus LIKE :status" + : requestBody.status.trim().toUpperCase() == "SUMMARY" + ? "evaluationStatus LIKE :status" + : "evaluationStatus LIKE :status" : "1=1", { status: requestBody.status == null || requestBody.status == undefined ? null - : requestBody.status.trim().toUpperCase(), + : requestBody.status.trim().toUpperCase() == "EVALUATING" || + requestBody.status.trim().toUpperCase() == "EVALUATING_EVALUATOR" || + requestBody.status.trim().toUpperCase() == "SUMMARY" + ? requestBody.status.trim().toUpperCase() == "SUMMARY" + ? `%${requestBody.status.trim().toUpperCase()}%` + : `%EVALUATING%` + : requestBody.status.trim().toUpperCase(), }, ) .andWhere( @@ -415,7 +420,13 @@ export class KpiUserEvaluationController extends Controller { levelForGourp = "2"; if (kpiUserEvaluation.posTypeName == "ทั่วไป" && kpiUserEvaluation.posLevelName == "ปฏิบัติงาน") levelForGourp = "1"; + kpiUserEvaluation.weightPoint1 = 80; + kpiUserEvaluation.weightPoint2 = 20; + kpiUserEvaluation.summaryWeight = 100; if (findPosition && findPosition.kpiLinkId && levelForGourp != null) { + kpiUserEvaluation.weightPoint1 = 70; + kpiUserEvaluation.weightPoint2 = 30; + kpiUserEvaluation.summaryWeight = 100; const findKpiLink = await this.kpiLinkRepository.findOne({ relations: ["kpiCapacitys"], where: { @@ -493,6 +504,22 @@ export class KpiUserEvaluationController extends Controller { "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", ); } + + if (requestBody.summaryPoint != null) { + if (requestBody.summaryPoint >= 90) { + kpiUserEvaluation.evaluationResults = "EXCELLENT"; + } else if (requestBody.summaryPoint >= 80) { + kpiUserEvaluation.evaluationResults = "VERY_GOOD"; + } else if (requestBody.summaryPoint >= 70) { + kpiUserEvaluation.evaluationResults = "GOOD"; + } else if (requestBody.summaryPoint >= 60) { + kpiUserEvaluation.evaluationResults = "FAIR"; + } else { + kpiUserEvaluation.evaluationResults = "IMPROVEMENT"; + } + } else { + kpiUserEvaluation.evaluationResults = "IMPROVEMENT"; + } kpiUserEvaluation.lastUpdateUserId = request.user.sub; kpiUserEvaluation.lastUpdateFullName = request.user.name; Object.assign(kpiUserEvaluation, requestBody); @@ -663,11 +690,15 @@ export class KpiUserEvaluationController extends Controller { evaluatorId: kpiUserEvaluation.evaluatorId, commanderId: kpiUserEvaluation.commanderId, commanderHighId: kpiUserEvaluation.commanderHighId, - plannedPoint: kpiUserEvaluation.plannedPoint, - rolePoint: kpiUserEvaluation.rolePoint, - specialPoint: kpiUserEvaluation.specialPoint, - capacityPoint: kpiUserEvaluation.capacityPoint, + // plannedPoint: kpiUserEvaluation.plannedPoint, + // rolePoint: kpiUserEvaluation.rolePoint, + // specialPoint: kpiUserEvaluation.specialPoint, + // capacityPoint: kpiUserEvaluation.capacityPoint, kpiPeriodId: kpiUserEvaluation.kpiPeriodId, + totalPoint1: kpiUserEvaluation.totalPoint1, + totalPoint2_1: kpiUserEvaluation.totalPoint2_1, + totalPoint2_2: kpiUserEvaluation.totalPoint2_2, + summaryPoint: kpiUserEvaluation.summaryPoint, year: kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.year, durationKPI: kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.durationKPI, @@ -960,7 +991,7 @@ export class KpiUserEvaluationController extends Controller { if (role == "EVALUATOR") { if (item.evaluationStatus == "EVALUATING_EVALUATOR") { if (item.commanderId == null || item.commanderId == "") { - item.evaluationStatus = "COMPLETE"; + item.evaluationStatus = "SUMMARY"; } else { item.evaluationStatus = "EVALUATING_COMMANDER"; } @@ -969,13 +1000,13 @@ export class KpiUserEvaluationController extends Controller { } else if (role == "COMMANDER") { if (item.evaluationStatus == "EVALUATING_COMMANDER") { if (item.commanderHighId == null || item.commanderHighId == "") { - item.evaluationStatus = "COMPLETE"; + item.evaluationStatus = "SUMMARY"; } else { item.evaluationStatus = "EVALUATING_COMMANDER_HIGH"; } } } else { - item.evaluationStatus = "COMPLETE"; + item.evaluationStatus = "SUMMARY"; } // } else { // // item.evaluationStatus = requestBody.status.trim().toUpperCase(); @@ -1043,6 +1074,24 @@ export class KpiUserEvaluationController extends Controller { ); } const _null: any = null; + if (kpiUserEvaluation.commanderId == null) { + kpiUserEvaluation.evaluationStatus = "COMPLETE"; + await new CallAPI() + .PostData(request, "org/profile/assessments", { + date: new Date(), + name: null, + point1: null, + point1Total: kpiUserEvaluation.totalPoint1, + point2: null, + point2Total: kpiUserEvaluation.totalPoint2_1 + kpiUserEvaluation.totalPoint2_2, + pointSum: null, + pointSumTotal: kpiUserEvaluation.summaryPoint, + profileId: kpiUserEvaluation.profileId, + }) + .then(async (x) => {}); + } else { + kpiUserEvaluation.evaluationStatus = "SUMMARY_COMMANDER"; + } kpiUserEvaluation.topicEvaluator = requestBody.topicEvaluator == null ? _null : requestBody.topicEvaluator; kpiUserEvaluation.developEvaluator = @@ -1084,6 +1133,24 @@ export class KpiUserEvaluationController extends Controller { ); } const _null: any = null; + if (kpiUserEvaluation.commanderHighId == null) { + kpiUserEvaluation.evaluationStatus = "COMPLETE"; + await new CallAPI() + .PostData(request, "org/profile/assessments", { + date: new Date(), + name: null, + point1: null, + point1Total: kpiUserEvaluation.totalPoint1, + point2: null, + point2Total: kpiUserEvaluation.totalPoint2_1 + kpiUserEvaluation.totalPoint2_2, + pointSum: null, + pointSumTotal: kpiUserEvaluation.summaryPoint, + profileId: kpiUserEvaluation.profileId, + }) + .then(async (x) => {}); + } else { + kpiUserEvaluation.evaluationStatus = "SUMMARY_COMMANDER_HIGH"; + } kpiUserEvaluation.isReasonCommander = requestBody.isReason; kpiUserEvaluation.reasonCommander = requestBody.reason == null ? _null : requestBody.reason; kpiUserEvaluation.lastUpdateUserId = request.user.sub; @@ -1119,6 +1186,20 @@ export class KpiUserEvaluationController extends Controller { ); } const _null: any = null; + kpiUserEvaluation.evaluationStatus = "COMPLETE"; + await new CallAPI() + .PostData(request, "org/profile/assessments", { + date: new Date(), + name: null, + point1: null, + point1Total: kpiUserEvaluation.totalPoint1, + point2: null, + point2Total: kpiUserEvaluation.totalPoint2_1 + kpiUserEvaluation.totalPoint2_2, + pointSum: null, + pointSumTotal: kpiUserEvaluation.summaryPoint, + profileId: kpiUserEvaluation.profileId, + }) + .then(async (x) => {}); kpiUserEvaluation.isReasonCommanderHigh = requestBody.isReason; kpiUserEvaluation.reasonCommanderHigh = requestBody.reason == null ? _null : requestBody.reason; kpiUserEvaluation.lastUpdateUserId = request.user.sub; @@ -1150,6 +1231,23 @@ export class KpiUserEvaluationController extends Controller { "reasonCommander", "isReasonCommanderHigh", "reasonCommanderHigh", + + "plannedPoint", + "rolePoint", + "specialPoint", + "capacityPoint", + + "totalPoint1", + "totalPoint2_1", + "totalPoint2_2", + "summaryPoint", + + "weightPoint1", + "weightPoint2", + "summaryWeight", + + "evaluationResults", + "isOpen", ], }); diff --git a/src/entities/kpiUserEvaluation.ts b/src/entities/kpiUserEvaluation.ts index 53bd0bd..61a5c6f 100644 --- a/src/entities/kpiUserEvaluation.ts +++ b/src/entities/kpiUserEvaluation.ts @@ -127,7 +127,7 @@ export class KpiUserEvaluation extends EntityBase { @Column({ type: "double", nullable: true, - default: null, + default: 0, comment: "งานตามแผนปฏิบัติราชการประจำปี ร้อยละ", }) plannedPoint: number; @@ -135,7 +135,7 @@ export class KpiUserEvaluation extends EntityBase { @Column({ type: "double", nullable: true, - default: null, + default: 0, comment: "งานตามหน้าที่ความรับผิดชอบหลัก ร้อยละ", }) rolePoint: number; @@ -143,7 +143,7 @@ export class KpiUserEvaluation extends EntityBase { @Column({ type: "double", nullable: true, - default: null, + default: 0, comment: "งานที่ได้รับมอบหมายพิเศษ ร้อยละ", }) specialPoint: number; @@ -151,7 +151,7 @@ export class KpiUserEvaluation extends EntityBase { @Column({ type: "double", nullable: true, - default: null, + default: 0, comment: "สมรรถนะ ร้อยละ", }) capacityPoint: number; @@ -159,7 +159,7 @@ export class KpiUserEvaluation extends EntityBase { @Column({ type: "double", nullable: true, - default: null, + default: 0, comment: "คะแนนประเมินองค์ประกอบที่ 1", }) totalPoint1: number; @@ -167,7 +167,7 @@ export class KpiUserEvaluation extends EntityBase { @Column({ type: "double", nullable: true, - default: null, + default: 0, comment: "คะแนนประเมินองค์ประกอบที่ 2.1", }) totalPoint2_1: number; @@ -175,7 +175,7 @@ export class KpiUserEvaluation extends EntityBase { @Column({ type: "double", nullable: true, - default: null, + default: 0, comment: "คะแนนประเมินองค์ประกอบที่ 2.2", }) totalPoint2_2: number; @@ -183,11 +183,35 @@ export class KpiUserEvaluation extends EntityBase { @Column({ type: "double", nullable: true, - default: null, + default: 0, comment: "คะแนนประเมิน", }) summaryPoint: number; + @Column({ + type: "double", + nullable: true, + default: 0, + comment: "คะแนนประเมินองค์ประกอบที่ 1", + }) + weightPoint1: number; + + @Column({ + type: "double", + nullable: true, + default: 0, + comment: "คะแนนประเมินองค์ประกอบที่ 2", + }) + weightPoint2: number; + + @Column({ + type: "double", + nullable: true, + default: 0, + comment: "คะแนนประเมิน", + }) + summaryWeight: number; + @Column({ nullable: true, comment: "ชื่อเรื่อง/เนื้อหา/หัวข้อการพัฒนา", diff --git a/src/migration/1719393220115-update_table_summaryPoint_0.ts b/src/migration/1719393220115-update_table_summaryPoint_0.ts new file mode 100644 index 0000000..086b8df --- /dev/null +++ b/src/migration/1719393220115-update_table_summaryPoint_0.ts @@ -0,0 +1,28 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableSummaryPoint01719393220115 implements MigrationInterface { + name = 'UpdateTableSummaryPoint01719393220115' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`plannedPoint\` \`plannedPoint\` double NULL COMMENT 'งานตามแผนปฏิบัติราชการประจำปี ร้อยละ' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`rolePoint\` \`rolePoint\` double NULL COMMENT 'งานตามหน้าที่ความรับผิดชอบหลัก ร้อยละ' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`specialPoint\` \`specialPoint\` double NULL COMMENT 'งานที่ได้รับมอบหมายพิเศษ ร้อยละ' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`capacityPoint\` \`capacityPoint\` double NULL COMMENT 'สมรรถนะ ร้อยละ' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`totalPoint1\` \`totalPoint1\` double NULL COMMENT 'คะแนนประเมินองค์ประกอบที่ 1' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`totalPoint2_1\` \`totalPoint2_1\` double NULL COMMENT 'คะแนนประเมินองค์ประกอบที่ 2.1' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`totalPoint2_2\` \`totalPoint2_2\` double NULL COMMENT 'คะแนนประเมินองค์ประกอบที่ 2.2' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`summaryPoint\` \`summaryPoint\` double NULL COMMENT 'คะแนนประเมิน' DEFAULT '0'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`summaryPoint\` \`summaryPoint\` double NULL COMMENT 'คะแนนประเมิน'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`totalPoint2_2\` \`totalPoint2_2\` double NULL COMMENT 'คะแนนประเมินองค์ประกอบที่ 2.2'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`totalPoint2_1\` \`totalPoint2_1\` double NULL COMMENT 'คะแนนประเมินองค์ประกอบที่ 2.1'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`totalPoint1\` \`totalPoint1\` double NULL COMMENT 'คะแนนประเมินองค์ประกอบที่ 1'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`capacityPoint\` \`capacityPoint\` double NULL COMMENT 'สมรรถนะ ร้อยละ'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`specialPoint\` \`specialPoint\` double NULL COMMENT 'งานที่ได้รับมอบหมายพิเศษ ร้อยละ'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`rolePoint\` \`rolePoint\` double NULL COMMENT 'งานตามหน้าที่ความรับผิดชอบหลัก ร้อยละ'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`plannedPoint\` \`plannedPoint\` double NULL COMMENT 'งานตามแผนปฏิบัติราชการประจำปี ร้อยละ'`); + } + +} diff --git a/src/migration/1719398567558-update_table_summaryWeight.ts b/src/migration/1719398567558-update_table_summaryWeight.ts new file mode 100644 index 0000000..3c5551d --- /dev/null +++ b/src/migration/1719398567558-update_table_summaryWeight.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableSummaryWeight1719398567558 implements MigrationInterface { + name = 'UpdateTableSummaryWeight1719398567558' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`weightPoint1\` double NULL COMMENT 'คะแนนประเมินองค์ประกอบที่ 1' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`weightPoint2\` double NULL COMMENT 'คะแนนประเมินองค์ประกอบที่ 2' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`summaryWeight\` double NULL COMMENT 'คะแนนประเมิน' DEFAULT '0'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`summaryWeight\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`weightPoint2\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`weightPoint1\``); + } + +}