242 lines
8.7 KiB
TypeScript
242 lines
8.7 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Route,
|
|
Security,
|
|
Tags,
|
|
Body,
|
|
Path,
|
|
Request,
|
|
Query,
|
|
} from "tsoa";
|
|
import { AppDataSource } from "../database/data-source";
|
|
import { Brackets, Not } from "typeorm";
|
|
import HttpSuccess from "../interfaces/http-success";
|
|
import HttpError from "../interfaces/http-error";
|
|
import HttpStatusCode from "../interfaces/http-status";
|
|
import { KpiPeriod } from "../entities/kpiPeriod";
|
|
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
|
import { off } from "process";
|
|
import Extension from "../interfaces/extension";
|
|
import { KpiRole } from "../entities/kpiRole";
|
|
import { KpiPlan } from "../entities/kpiPlan";
|
|
|
|
@Route("api/v1/kpi/report")
|
|
@Tags("Report")
|
|
@Security("bearerAuth")
|
|
export class ReportController extends Controller {
|
|
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
|
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
|
|
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
|
|
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
|
|
|
|
@Post("announcement")
|
|
async GetReportAnnouncement(
|
|
@Body()
|
|
requestBody: {
|
|
type: string;
|
|
root?: string | null;
|
|
periodId?: string | null;
|
|
profileId?: string | null;
|
|
// filters?: string | null;
|
|
// keyword?: string | null;
|
|
},
|
|
) {
|
|
let templateName: any;
|
|
let reportName: any;
|
|
let formattedData: any;
|
|
if (requestBody.type == "KPI1") {
|
|
templateName = "KPI1";
|
|
reportName = "KPI1";
|
|
}
|
|
if (requestBody.type == "KPI2") {
|
|
templateName = "KPI2";
|
|
reportName = "KPI2";
|
|
}
|
|
if (requestBody.type == "KPI3") {
|
|
templateName = "KPI3";
|
|
reportName = "KPI3";
|
|
}
|
|
if (requestBody.type == "KPI4") {
|
|
templateName = "KPI4";
|
|
reportName = "KPI4";
|
|
//use_filter
|
|
}
|
|
if (requestBody.type == "KPI5") {
|
|
templateName = "KPI5";
|
|
reportName = "KPI5";
|
|
//use_filter
|
|
}
|
|
if (requestBody.type == "KPI6") {
|
|
templateName = "KPI6";
|
|
reportName = "KPI6";
|
|
//use_filter
|
|
}
|
|
if (requestBody.type == "KPI7") {
|
|
templateName = "KPI7";
|
|
reportName = "KPI7";
|
|
}
|
|
if (requestBody.type == "KPI8") {
|
|
templateName = "KPI8";
|
|
reportName = "KPI8";
|
|
//use_filter
|
|
}
|
|
if (requestBody.type == "KPI9") {
|
|
templateName = "KPI8";
|
|
reportName = "KPI8";
|
|
}
|
|
if (requestBody.root && requestBody.periodId) {
|
|
const getEvaluations = await this.kpiUserEvaluationRepository.find({
|
|
where: { kpiPeriodId: requestBody.periodId },
|
|
});
|
|
|
|
// if (requestBody.type == "KPI-3") {
|
|
// formattedData = getEvaluations.map((x) => ({
|
|
// fullName: x.prefix+" "+x.firstName+" "+x.lastName,
|
|
// fullName: x.prefix+" "+x.firstName+" "+x.lastName,
|
|
// }));
|
|
// }
|
|
// const getRoot = await this.kpiRoleRepository.findOne({
|
|
// where: { rootId: requestBody.root },
|
|
// });
|
|
// const officer = getEvaluations.map((evaluation) => ({
|
|
// fullName: getEvaluations
|
|
// ? `${evaluation.prefix} ${evaluation.firstName} ${evaluation.lastName}`
|
|
// : "",
|
|
// position: getEvaluations ? evaluation.position : "",
|
|
// posLevel: getEvaluations ? evaluation.posLevelName : "",
|
|
// result: "ดีเด่น",
|
|
// }));
|
|
|
|
// const formattedData = {
|
|
// periodId: requestBody.periodId,
|
|
// authorizedFullName: "นาย สมหมาย นครชัยศรี",
|
|
// authorizedPosition: "ผู้อำนวยการต้น",
|
|
// announceYear: Extension.ToThaiNumber(getPeriod.year.toString()),
|
|
// oc: getRoot ? getRoot.root : "",
|
|
// organizationName: "กรุงเทพมหานคร",
|
|
// announceDate: "๑๒ สิงหาคม ๒๕๖๔",
|
|
// roundNo: "๑ (๒๕๖๔) ",
|
|
// officer: officer,
|
|
// };
|
|
}
|
|
// if (requestBody.filters && requestBody.keyword) {
|
|
// }
|
|
return new HttpSuccess({
|
|
template: templateName,
|
|
reportName: reportName,
|
|
data: formattedData,
|
|
});
|
|
}
|
|
|
|
@Post("kpi9/{profileId}")
|
|
async GetReportKpi9(@Path() profileId?: string | null) {
|
|
let formattedData: any;
|
|
if (profileId) {
|
|
const kpiUserEvaluation = await this.kpiUserEvaluationRepository.findOne({
|
|
relations: ["kpiUserRoles", "kpiUserPlanneds", "kpiUserSpecials", "kpiUserCapacitys"],
|
|
where: { profileId: profileId },
|
|
});
|
|
if (!kpiUserEvaluation)
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ประเมิน");
|
|
|
|
//period
|
|
const period = await this.kpiPeriodRepository.findOneBy({
|
|
id: kpiUserEvaluation?.kpiPeriodId,
|
|
});
|
|
if (!period) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงวดการประเมิน");
|
|
|
|
const kpiRole = await this.kpiRoleRepository.find({
|
|
where: { kpiPeriodId: period?.id },
|
|
});
|
|
|
|
const kpiPlan = await this.kpiPlanRepository.find({
|
|
where: { kpiPeriodId: period?.id },
|
|
});
|
|
|
|
formattedData = {
|
|
fullname:
|
|
kpiUserEvaluation.prefix + kpiUserEvaluation.firstName + " " + kpiUserEvaluation.lastName,
|
|
position: kpiUserEvaluation.position,
|
|
posTypeName: kpiUserEvaluation.posTypeName,
|
|
posLevelName: kpiUserEvaluation.posLevelName,
|
|
org: kpiUserEvaluation.org,
|
|
|
|
fullnameEvaluator:
|
|
kpiUserEvaluation.prefixEvaluator +
|
|
kpiUserEvaluation.firstNameEvaluator +
|
|
" " +
|
|
kpiUserEvaluation.lastNameEvaluator,
|
|
positionEvaluator: kpiUserEvaluation.positionEvaluator,
|
|
posTypeNameEvaluator: kpiUserEvaluation.posTypeNameEvaluator,
|
|
posLevelNameEvaluator: kpiUserEvaluation.posLevelNameEvaluator,
|
|
rootEvaluator: kpiUserEvaluation.orgEvaluator,
|
|
|
|
year: Extension.ToThaiNumber(
|
|
String(Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year)),
|
|
),
|
|
|
|
startDateApr:
|
|
kpiUserEvaluation.kpiPeriod == null ||
|
|
kpiUserEvaluation.kpiPeriod.startDate == null ||
|
|
kpiUserEvaluation.kpiPeriod.durationKPI != "APR"
|
|
? "-"
|
|
: Extension.ToThaiNumber(
|
|
Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate),
|
|
),
|
|
endDateApr:
|
|
kpiUserEvaluation.kpiPeriod == null ||
|
|
kpiUserEvaluation.kpiPeriod.endDate == null ||
|
|
kpiUserEvaluation.kpiPeriod.durationKPI != "APR"
|
|
? "-"
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.endDate)),
|
|
startDateOct:
|
|
kpiUserEvaluation.kpiPeriod == null ||
|
|
kpiUserEvaluation.kpiPeriod.startDate == null ||
|
|
kpiUserEvaluation.kpiPeriod.durationKPI != "OCT"
|
|
? "-"
|
|
: Extension.ToThaiNumber(
|
|
Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate),
|
|
),
|
|
endDateOct:
|
|
kpiUserEvaluation.kpiPeriod == null ||
|
|
kpiUserEvaluation.kpiPeriod.endDate == null ||
|
|
kpiUserEvaluation.kpiPeriod.durationKPI != "OCT"
|
|
? "-"
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.endDate)),
|
|
|
|
evaluationResults: kpiUserEvaluation.evaluationResults,
|
|
totalPoint1: Extension.ToThaiNumber(kpiUserEvaluation.totalPoint1.toLocaleString()),
|
|
totalPoint2: Extension.ToThaiNumber(
|
|
kpiUserEvaluation.totalPoint2_2 + kpiUserEvaluation.totalPoint2_1.toLocaleString(),
|
|
),
|
|
summaryPoint: Extension.ToThaiNumber(kpiUserEvaluation.summaryPoint.toLocaleString()),
|
|
weightPoint1: Extension.ToThaiNumber(kpiUserEvaluation.weightPoint1.toLocaleString()),
|
|
weightPoint2: Extension.ToThaiNumber(kpiUserEvaluation.weightPoint2.toLocaleString()),
|
|
summaryWeight: Extension.ToThaiNumber(kpiUserEvaluation.summaryWeight.toLocaleString()),
|
|
|
|
topicEvaluator: kpiUserEvaluation.topicEvaluator,
|
|
developEvaluator: kpiUserEvaluation.developEvaluator,
|
|
timeEvaluator: kpiUserEvaluation.timeEvaluator,
|
|
reasonEvaluator: kpiUserEvaluation.reasonEvaluator,
|
|
isReasonCommander: kpiUserEvaluation.isReasonCommander,
|
|
reasonCommander: kpiUserEvaluation.reasonCommander,
|
|
isReasonCommanderHigh: kpiUserEvaluation.isReasonCommanderHigh,
|
|
reasonCommanderHigh: kpiUserEvaluation.reasonCommanderHigh,
|
|
openDate:
|
|
kpiUserEvaluation.openDate == null
|
|
? null
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.openDate)),
|
|
};
|
|
}
|
|
|
|
return new HttpSuccess({
|
|
template: "KPI9",
|
|
reportName: "KPI9",
|
|
data: formattedData,
|
|
});
|
|
}
|
|
}
|