คอมเม้นผู้บังคับบัญชา

This commit is contained in:
Kittapath 2024-04-26 17:39:24 +07:00
parent 9576d26753
commit 7f7b676750
9 changed files with 318 additions and 10 deletions

View file

@ -22,6 +22,7 @@ import HttpStatusCode from "../interfaces/http-status";
import { KpiPlan, createKpiPlan, updateKpiPlan } from "../entities/kpiPlan";
import CallAPI from "../interfaces/call-api";
import { KpiPeriod } from "../entities/kpiPeriod";
import { Brackets } from "typeorm";
@Route("api/v1/kpi/plan")
@Tags("kpiPlan")
@ -320,6 +321,14 @@ export class kpiPlanController extends Controller {
kpiPeriodId: kpiPeriodId,
},
)
.andWhere(
new Brackets((qb) => {
qb.orWhere("kpiPlan.including LIKE :keyword", { keyword: `%${keyword}%` }).orWhere(
"kpiPlan.includingName LIKE :keyword",
{ keyword: `%${keyword}%` },
);
}),
)
.select([
"kpiPlan.id",
"kpiPeriod.year",

View file

@ -22,6 +22,7 @@ import HttpStatusCode from "../interfaces/http-status";
import { KpiRole, createKpiRole, updateKpiRole } from "../entities/kpiRole";
import CallAPI from "../interfaces/call-api";
import { KpiPeriod } from "../entities/kpiPeriod";
import { Brackets } from "typeorm";
@Route("api/v1/kpi/role")
@Tags("kpiRole")
@ -257,6 +258,14 @@ export class kpiRoleController extends Controller {
.andWhere(position != undefined ? "kpiRole.position LIKE :position" : "1=1", {
position: `%${position}%`,
})
.andWhere(
new Brackets((qb) => {
qb.orWhere("kpiRole.including LIKE :keyword", { keyword: `%${keyword}%` }).orWhere(
"kpiRole.includingName LIKE :keyword",
{ keyword: `%${keyword}%` },
);
}),
)
.select([
"kpiRole.id",
"kpiPeriod.year",

View file

@ -26,9 +26,14 @@ import {
createKpiUserEvaluation,
updateKpiUserCheckEvaluation,
updateKpiUserEvaluation,
updateKpiUserPointEvaluation,
} from "../entities/kpiUserEvaluation";
import { Like, In } from "typeorm";
import { Like, In, Brackets } from "typeorm";
import CallAPI from "../interfaces/call-api";
import {
KpiUserEvaluationReason,
updateKpiUserReasonEvaluation,
} from "../entities/kpiUserEvaluationReason";
@Route("api/v1/kpi/user/evaluation")
@Tags("kpiUserEvaluation")
@ -41,6 +46,7 @@ import CallAPI from "../interfaces/call-api";
export class KpiUserEvaluationController extends Controller {
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
private kpiUserEvalutionRepository = AppDataSource.getRepository(KpiUserEvaluation);
private kpiUserEvaluationReasonRepository = AppDataSource.getRepository(KpiUserEvaluationReason);
/**
* API
@ -53,13 +59,20 @@ export class KpiUserEvaluationController extends Controller {
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("kpiPeriodId") kpiPeriodId?: string,
// @Query("keyword") keyword?: string,
@Query("keyword") keyword?: string,
) {
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
.createQueryBuilder("kpiUserEvaluation")
.andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", {
kpiPeriodId: kpiPeriodId,
})
.andWhere(
new Brackets((qb) => {
qb.orWhere("kpiUserEvaluation.prefix LIKE :keyword", { keyword: `%${keyword}%` })
.orWhere("kpiUserEvaluation.firstName LIKE :keyword", { keyword: `%${keyword}%` })
.orWhere("kpiUserEvaluation.lastName LIKE :keyword", { keyword: `%${keyword}%` });
}),
)
.orderBy("kpiUserEvaluation.createdAt", "ASC")
.skip((page - 1) * pageSize)
.take(pageSize)
@ -153,6 +166,85 @@ export class KpiUserEvaluationController extends Controller {
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API (USER)
*
* @summary (USER)
*
* @param {string} id Guid, *Id (USER)
*/
@Put("point/{id}")
async updateKpiUserPointEvaluation(
@Path() id: string,
@Body() requestBody: updateKpiUserPointEvaluation,
@Request() request: { user: Record<string, any> },
) {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
Object.assign(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API (USER)
*
* @summary (USER)
*
* @param {string} id Guid, *Id (USER)
*/
@Put("{type}/{id}")
async updateKpiUserEvaluatorEvaluation(
@Path() id: string,
@Path() type: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: { user: Record<string, any> },
) {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
const kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReason(), requestBody);
kpiUserEvaluationReason.type = type.trim().toUpperCase();
kpiUserEvaluationReason.kpiUserEvaluationId = id;
kpiUserEvaluationReason.createdUserId = request.user.sub;
kpiUserEvaluationReason.createdFullName = request.user.name;
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonRepository.save(kpiUserEvaluationReason);
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API list (USER)
*
* @summary list (USER)
*
* @param {string} id Guid, *Id (USER)
*/
@Get("{type}/{id}")
async listKpiUserCommanderEvaluation(@Path() id: string, @Path() type: string) {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRepository.find({
where: { kpiUserEvaluationId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
}
/**
* API (USER)
*
@ -217,6 +309,10 @@ export class KpiUserEvaluationController extends Controller {
"evaluatorId",
"commanderId",
"commanderHighId",
"plannedPoint",
"rolePoint",
"specialPoint",
"capacityPoint",
],
});
if (!kpiUserEvaluation) {
@ -264,6 +360,10 @@ export class KpiUserEvaluationController extends Controller {
commanderId: item.commanderId,
commanderHighId: item.commanderHighId,
createdAt: item.createdAt,
plannedPoint: item.plannedPoint,
rolePoint: item.rolePoint,
specialPoint: item.specialPoint,
capacityPoint: item.capacityPoint,
}));
return new HttpSuccess({ data: mapData, total });
}

View file

@ -5,6 +5,7 @@ import { KpiUserSpecial } from "./kpiUserSpecial";
import { KpiUserRole } from "./kpiUserRole";
import { KpiUserPlanned } from "./kpiUserPlanned";
import { KpiUserCapacity } from "./kpiUserCapacity";
import { KpiUserEvaluationReason } from "./kpiUserEvaluationReason";
@Entity("kpiUserEvaluation")
export class KpiUserEvaluation extends EntityBase {
@Column({
@ -31,14 +32,6 @@ export class KpiUserEvaluation extends EntityBase {
})
lastName: string;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง kpiPeriodId",
default: null,
})
kpiPeriodId: string;
@Column({
nullable: true,
length: 40,
@ -91,6 +84,46 @@ export class KpiUserEvaluation extends EntityBase {
})
evaluationResults: string;
@Column({
type: "double",
nullable: true,
default: null,
comment: "งานตามแผนปฏิบัติราชการประจำปี ร้อยละ",
})
plannedPoint: number;
@Column({
type: "double",
nullable: true,
default: null,
comment: "งานตามหน้าที่ความรับผิดชอบหลัก ร้อยละ",
})
rolePoint: number;
@Column({
type: "double",
nullable: true,
default: null,
comment: "งานที่ได้รับมอบหมายพิเศษ ร้อยละ",
})
specialPoint: number;
@Column({
type: "double",
nullable: true,
default: null,
comment: "สมรรถนะ ร้อยละ",
})
capacityPoint: number;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง kpiPeriodId",
default: null,
})
kpiPeriodId: string;
@ManyToOne(() => KpiPeriod, (kpiPeriod) => kpiPeriod.kpiUserEvaluations)
@JoinColumn({ name: "kpiPeriodId" })
kpiPeriod: KpiPeriod;
@ -106,6 +139,12 @@ export class KpiUserEvaluation extends EntityBase {
@OneToMany(() => KpiUserSpecial, (kpiUserSpecial) => kpiUserSpecial.kpiUserEvaluation)
kpiUserSpecials: KpiUserSpecial[];
@OneToMany(
() => KpiUserEvaluationReason,
(kpiUserEvaluationReason) => kpiUserEvaluationReason.kpiUserEvaluation,
)
kpiUserEvaluationReasons: KpiUserEvaluationReason[];
}
export class createKpiUserEvaluation {
@ -148,3 +187,14 @@ export class updateKpiUserCheckEvaluation {
@Column()
commanderHighId: string | null;
}
export class updateKpiUserPointEvaluation {
@Column()
plannedPoint: number | null;
@Column()
rolePoint: number | null;
@Column()
specialPoint: number | null;
@Column()
capacityPoint: number | null;
}

View file

@ -0,0 +1,56 @@
import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { KpiPeriod } from "./kpiPeriod";
import { KpiUserSpecial } from "./kpiUserSpecial";
import { KpiUserRole } from "./kpiUserRole";
import { KpiUserPlanned } from "./kpiUserPlanned";
import { KpiUserCapacity } from "./kpiUserCapacity";
import { KpiUserEvaluation } from "./kpiUserEvaluation";
@Entity("kpiUserEvaluationReason")
export class KpiUserEvaluationReason extends EntityBase {
@Column({
nullable: true,
comment: "หมายเหตุ",
length: 255,
default: null,
})
reason: string;
@Column({
nullable: true,
comment: "หัวข้อ",
length: 255,
default: null,
})
topic: string;
@Column({
nullable: true,
comment: "ประเภท",
length: 255,
default: null,
})
type: string;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง kpiPeriodId",
default: null,
})
kpiUserEvaluationId: string;
@ManyToOne(
() => KpiUserEvaluation,
(kpiUserEvaluation) => kpiUserEvaluation.kpiUserEvaluationReasons,
)
@JoinColumn({ name: "kpiUserEvaluationId" })
kpiUserEvaluation: KpiUserEvaluation;
}
export class updateKpiUserReasonEvaluation {
@Column()
reason: string | null;
@Column()
topic: string | null;
}

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableKpiUserEvalutionAddPoint1714125247489 implements MigrationInterface {
name = 'UpdateTableKpiUserEvalutionAddPoint1714125247489'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`plannedPoint\` double NULL COMMENT 'งานตามแผนปฏิบัติราชการประจำปี ร้อยละ'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`rolePoint\` double NULL COMMENT 'งานตามหน้าที่ความรับผิดชอบหลัก ร้อยละ'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`specialPoint\` double NULL COMMENT 'งานที่ได้รับมอบหมายพิเศษ ร้อยละ'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`capacityPoint\` double NULL COMMENT 'สมรรถนะ ร้อยละ'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`capacityPoint\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`specialPoint\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`rolePoint\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`plannedPoint\``);
}
}

View file

@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableKpiUserEvalutionAddPoint11714125714200 implements MigrationInterface {
name = 'UpdateTableKpiUserEvalutionAddPoint11714125714200'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`evaluatorReason\` varchar(255) NULL COMMENT 'หมายเหตุ ของผู้ประเมิน'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderReason\` varchar(255) NULL COMMENT 'หมายเหตุ ของผู้บังคับบัญชาเหนือขึ้นไป'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderHighReason\` varchar(255) NULL COMMENT 'หมายเหตุ ของผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderHighReason\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderReason\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`evaluatorReason\``);
}
}

View file

@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableKpiUserEvalutionAddPoint21714126663201 implements MigrationInterface {
name = 'UpdateTableKpiUserEvalutionAddPoint21714126663201'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`evaluatorTopic\` varchar(255) NULL COMMENT 'หัวข้อ ของผู้ประเมิน'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderTopic\` varchar(255) NULL COMMENT 'หัวข้อ ของผู้บังคับบัญชาเหนือขึ้นไป'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderHighTopic\` varchar(255) NULL COMMENT 'หัวข้อ ของผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderHighTopic\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderTopic\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`evaluatorTopic\``);
}
}

View file

@ -0,0 +1,28 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableKpiUserEvalutionAddPoint31714127671110 implements MigrationInterface {
name = 'UpdateTableKpiUserEvalutionAddPoint31714127671110'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`kpiUserEvaluationReason\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`reason\` varchar(255) NULL COMMENT 'หมายเหตุ', \`topic\` varchar(255) NULL COMMENT 'หัวข้อ', \`type\` varchar(255) NULL COMMENT 'ประเภท', \`kpiUserEvaluationId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง kpiPeriodId', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`evaluatorReason\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderReason\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderHighReason\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`evaluatorTopic\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderTopic\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderHighTopic\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReason\` ADD CONSTRAINT \`FK_99a78bf1acfce1ba7f763296f91\` FOREIGN KEY (\`kpiUserEvaluationId\`) REFERENCES \`kpiUserEvaluation\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReason\` DROP FOREIGN KEY \`FK_99a78bf1acfce1ba7f763296f91\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderHighTopic\` varchar(255) NULL COMMENT 'หัวข้อ ของผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderTopic\` varchar(255) NULL COMMENT 'หัวข้อ ของผู้บังคับบัญชาเหนือขึ้นไป'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`evaluatorTopic\` varchar(255) NULL COMMENT 'หัวข้อ ของผู้ประเมิน'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderHighReason\` varchar(255) NULL COMMENT 'หมายเหตุ ของผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderReason\` varchar(255) NULL COMMENT 'หมายเหตุ ของผู้บังคับบัญชาเหนือขึ้นไป'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`evaluatorReason\` varchar(255) NULL COMMENT 'หมายเหตุ ของผู้ประเมิน'`);
await queryRunner.query(`DROP TABLE \`kpiUserEvaluationReason\``);
}
}