report kpi1,2,3,7,9
This commit is contained in:
parent
f0af5a5c83
commit
20ec8579e0
2 changed files with 292 additions and 45 deletions
|
|
@ -13,7 +13,7 @@ import {
|
|||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Brackets, Not } from "typeorm";
|
||||
import { Brackets, IsNull, Not } from "typeorm";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -23,6 +23,7 @@ import { off } from "process";
|
|||
import Extension from "../interfaces/extension";
|
||||
import { KpiRole } from "../entities/kpiRole";
|
||||
import { KpiPlan } from "../entities/kpiPlan";
|
||||
import { KpiUserDevelopment } from "../entities/kpiUserDevelopment";
|
||||
|
||||
@Route("api/v1/kpi/report")
|
||||
@Tags("Report")
|
||||
|
|
@ -32,6 +33,7 @@ export class ReportController extends Controller {
|
|||
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
|
||||
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
|
||||
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
|
||||
private kpiUserDevelopmentRepository = AppDataSource.getRepository(KpiUserDevelopment);
|
||||
|
||||
@Post("announcement")
|
||||
async GetReportAnnouncement(
|
||||
|
|
@ -48,17 +50,224 @@ export class ReportController extends Controller {
|
|||
let templateName: any;
|
||||
let reportName: any;
|
||||
let formattedData: any;
|
||||
|
||||
//KPI1, KPI2, KPI3, KPI7, KPI9
|
||||
let data: any;
|
||||
let period1: any;
|
||||
let period2: any;
|
||||
|
||||
if (requestBody.root && requestBody.periodId) {
|
||||
data = await this.kpiPeriodRepository.createQueryBuilder("period")
|
||||
.leftJoinAndSelect("period.kpiUserEvaluations", "kpiUserEvaluations")
|
||||
.where("period.id = :periodId", { periodId: requestBody.periodId })
|
||||
.andWhere("kpiUserEvaluations.orgId = :orgId", { orgId: requestBody.root })
|
||||
.getOne();
|
||||
|
||||
if(data.durationKPI == "APR") {
|
||||
period1 = `${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}`
|
||||
let _period2 = await this.kpiPeriodRepository.findOne({
|
||||
where: {
|
||||
year: data.year, durationKPI: "OCR", isActive: true
|
||||
}
|
||||
});
|
||||
period2 = _period2 ? `${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}` : ""
|
||||
|
||||
}
|
||||
else if(data.durationKPI == "OCT"){
|
||||
period2 = `${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}`
|
||||
let _period1 = await this.kpiPeriodRepository.findOne({
|
||||
where: {
|
||||
year: data.year, durationKPI: "APR", isActive: true
|
||||
}
|
||||
});
|
||||
period1 = _period1 ? `${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}` : ""
|
||||
}
|
||||
}
|
||||
|
||||
if (requestBody.type == "KPI1") {
|
||||
templateName = "KPI1";
|
||||
reportName = "KPI1";
|
||||
/*ROOT*/
|
||||
const userEvaluationOrg = await this.kpiUserEvaluationRepository.find({
|
||||
where: {
|
||||
orgId: String(requestBody.root),
|
||||
// child1Id: "" || IsNull(),
|
||||
// child2Id: "" || IsNull(),
|
||||
// child3Id: "" || IsNull(),
|
||||
// child4Id: "" || IsNull(),
|
||||
}
|
||||
});
|
||||
const resultAll = userEvaluationOrg.length > 0
|
||||
? Extension.ToThaiNumber(userEvaluationOrg.length.toString())
|
||||
: "๐"
|
||||
const result = userEvaluationOrg.length > 0
|
||||
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults != "PENDING").length.toString())
|
||||
: "๐"
|
||||
const excellent = userEvaluationOrg.length > 0
|
||||
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "EXCELLENT").length.toString())
|
||||
: "๐"
|
||||
const verygood = userEvaluationOrg.length > 0
|
||||
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "VERY_GOOD").length.toString())
|
||||
: "๐"
|
||||
const good = userEvaluationOrg.length > 0
|
||||
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "GOOD").length.toString())
|
||||
: "๐"
|
||||
const fair = userEvaluationOrg.length > 0
|
||||
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "FAIR").length.toString())
|
||||
: "๐"
|
||||
const improvment = userEvaluationOrg.length > 0
|
||||
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "IMPROVEMENT").length.toString())
|
||||
: "๐"
|
||||
/*END ROOT*/
|
||||
formattedData = {
|
||||
year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "",
|
||||
period1: Extension.ToThaiNumber(period1),
|
||||
period2: Extension.ToThaiNumber(period2),
|
||||
durationKPI: data?.durationKPI,
|
||||
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
||||
? data?.kpiUserEvaluations[0].orgEvaluator
|
||||
: "",
|
||||
userEvaluations: [
|
||||
{
|
||||
no: "๑",
|
||||
root: userEvaluationOrg.length > 0
|
||||
? userEvaluationOrg[0].orgEvaluator ?? ""
|
||||
: "",
|
||||
resultAll: resultAll,
|
||||
result: result,
|
||||
excellent: excellent,
|
||||
verygood: verygood,
|
||||
good: good,
|
||||
fair: fair,
|
||||
improvment: improvment,
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
if (requestBody.type == "KPI2") {
|
||||
templateName = "KPI2";
|
||||
reportName = "KPI2";
|
||||
const excellent = data.length > 0
|
||||
? data.fla((x:any, idx:number) => ({
|
||||
no: Extension.ToThaiNumber((idx+1).toString()),
|
||||
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
|
||||
position: x.position ? x.position : "",
|
||||
posLevelName: x.posLevelName ? x.posLevelName : "",
|
||||
org: x.org ? x.org : "",
|
||||
})).filter((x:any) => x.evaluationResults == "EXCELLENT")
|
||||
: []
|
||||
const verygood = data.length > 0
|
||||
? data.map((x:any, idx:number) => ({
|
||||
no: Extension.ToThaiNumber((idx+1).toString()),
|
||||
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
|
||||
position: x.position ? x.position : "",
|
||||
posLevelName: x.posLevelName ? x.posLevelName : "",
|
||||
org: x.org ? x.org : "",
|
||||
})).filter((x:any) => x.evaluationResults == "VERY_GOOD")
|
||||
: []
|
||||
const good = data.length > 0
|
||||
? data.map((x:any, idx:number) => ({
|
||||
no: Extension.ToThaiNumber((idx+1).toString()),
|
||||
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
|
||||
position: x.position ? x.position : "",
|
||||
posLevelName: x.posLevelName ? x.posLevelName : "",
|
||||
org: x.org ? x.org : "",
|
||||
})).filter((x:any) => x.evaluationResults == "GOOD")
|
||||
: []
|
||||
const fair = data.length > 0
|
||||
? data.map((x:any, idx:number) => ({
|
||||
no: Extension.ToThaiNumber((idx+1).toString()),
|
||||
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
|
||||
position: x.position ? x.position : "",
|
||||
posLevelName: x.posLevelName ? x.posLevelName : "",
|
||||
org: x.org ? x.org : "",
|
||||
})).filter((x:any) => x.evaluationResults == "FAIR")
|
||||
: []
|
||||
const improvment = data.length > 0
|
||||
? data.map((x:any, idx:number) => ({
|
||||
no: Extension.ToThaiNumber((idx+1).toString()),
|
||||
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
|
||||
position: x.position ? x.position : "",
|
||||
posLevelName: x.posLevelName ? x.posLevelName : "",
|
||||
org: x.org ? x.org : "",
|
||||
})).filter((x:any) => x.evaluationResults == "IMPROVEMENT")
|
||||
: []
|
||||
formattedData = {
|
||||
year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "",
|
||||
period1: Extension.ToThaiNumber(period1),
|
||||
period2: Extension.ToThaiNumber(period2),
|
||||
durationKPI: data?.durationKPI,
|
||||
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
||||
? data?.kpiUserEvaluations[0].orgEvaluator
|
||||
: "",
|
||||
excellents: {
|
||||
count: Extension.ToThaiNumber(excellent.length.toString()),
|
||||
data: excellent
|
||||
},
|
||||
verygoods: {
|
||||
count: Extension.ToThaiNumber(verygood.length.toString()),
|
||||
data: verygood
|
||||
},
|
||||
goods: {
|
||||
count: Extension.ToThaiNumber(good.length.toString()),
|
||||
data: good
|
||||
},
|
||||
fairs: {
|
||||
count: Extension.ToThaiNumber(fair.length.toString()),
|
||||
data: fair
|
||||
},
|
||||
improvments: {
|
||||
count: Extension.ToThaiNumber(improvment.length.toString()),
|
||||
data: improvment
|
||||
},
|
||||
}
|
||||
}
|
||||
if (requestBody.type == "KPI3") {
|
||||
templateName = "KPI3";
|
||||
reportName = "KPI3";
|
||||
const userEvaluations_ = data?.kpiUserEvaluations?.length > 0
|
||||
? data.kpiUserEvaluations.map((x:any, idx:number) => ({
|
||||
no: Extension.ToThaiNumber((idx+1).toString()),
|
||||
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
|
||||
position: x.position ? x.position : "",
|
||||
point1: x.summaryPoint >= 90.00 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
||||
point2: x.summaryPoint >= 80.00 && x.summaryPoint <= 89.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
||||
point3: x.summaryPoint >= 70.00 && x.summaryPoint <= 79.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
||||
point4: x.summaryPoint >= 60.00 && x.summaryPoint <= 69.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
||||
point5: x.summaryPoint < 60.00 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
||||
remark: ""
|
||||
}))
|
||||
: []
|
||||
// const prefixEvaluator_ = data.kpiUserEvaluations.find((x:any) => x.prefixEvaluator);
|
||||
// const firstNameEvaluator_ = data.kpiUserEvaluations.firstNameEvaluator ? data.kpiUserEvaluations.firstNameEvaluator : "";
|
||||
// const lastNameEvaluator_ = data.kpiUserEvaluations.lastNameEvaluator ? data.kpiUserEvaluations.lastNameEvaluator : "";
|
||||
formattedData = {
|
||||
year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "",
|
||||
period1: Extension.ToThaiNumber(period1),
|
||||
period2: Extension.ToThaiNumber(period2),
|
||||
durationKPI: data?.durationKPI,
|
||||
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
||||
? data?.kpiUserEvaluations[0].orgEvaluator
|
||||
: "",
|
||||
fullNameEvaluator: "-",
|
||||
positionEvaluator: "-",
|
||||
posTypeNameEvaluator: "-",
|
||||
posLevelNameEvaluator: "-",
|
||||
orgEvaluator: "-",
|
||||
|
||||
fullNameCommander: "-",
|
||||
positionCommander: "-",
|
||||
posTypeNameCommander: "-",
|
||||
posLevelNameCommander: "-",
|
||||
orgCommander: "-",
|
||||
|
||||
fullNameCommanderHigh: "-",
|
||||
positionCommanderHigh: "-",
|
||||
posTypeNameCommanderHigh: "-",
|
||||
posLevelNameCommanderHigh: "-",
|
||||
orgCommanderHigh: "-",
|
||||
userEvaluations : userEvaluations_
|
||||
}
|
||||
}
|
||||
if (requestBody.type == "KPI4") {
|
||||
templateName = "KPI4";
|
||||
|
|
@ -78,6 +287,29 @@ export class ReportController extends Controller {
|
|||
if (requestBody.type == "KPI7") {
|
||||
templateName = "KPI7";
|
||||
reportName = "KPI7";
|
||||
formattedData = {
|
||||
year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "",
|
||||
period1: Extension.ToThaiNumber(period1),
|
||||
period2: Extension.ToThaiNumber(period2),
|
||||
durationKPI: data?.durationKPI,
|
||||
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
||||
? data?.kpiUserEvaluations[0].orgEvaluator
|
||||
: "",
|
||||
userEvaluations: data.kpiUserEvaluations.map((x: any, idx: number) => ({
|
||||
no: Extension.ToThaiNumber((idx + 1).toString()),
|
||||
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
|
||||
position: x.position ? x.position : "",
|
||||
posLevelName: x.posLevelName ? x.posLevelName : "",
|
||||
developName: x.topicEvaluator ? x.topicEvaluator : "",
|
||||
developEvaluator: x.developEvaluator ? x.developEvaluator : "",
|
||||
target: "", //เป้าหมาย
|
||||
timeEvaluator: x.timeEvaluator ? x.timeEvaluator : "",
|
||||
developResults: "", //วิธีการวัดผลการพัฒนา
|
||||
evaluationResults: x.evaluationResults
|
||||
? Extension.EvaluationResult(x.evaluationResults)
|
||||
: "",
|
||||
})),
|
||||
}
|
||||
}
|
||||
if (requestBody.type == "KPI8") {
|
||||
templateName = "KPI8";
|
||||
|
|
@ -87,44 +319,24 @@ export class ReportController extends Controller {
|
|||
if (requestBody.type == "KPI9") {
|
||||
templateName = "KPI9";
|
||||
reportName = "KPI9";
|
||||
formattedData = {
|
||||
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
||||
? data?.kpiUserEvaluations[0].orgEvaluator
|
||||
: "",
|
||||
period: data?.durationKPI == "APR" ? "๑": data?.durationKPI == "OCT" ? "๒" : "-",
|
||||
year: Extension.ToThaiNumber((data.year+543).toString()),
|
||||
userEvaluations: data.kpiUserEvaluations.map((x: any, idx: number) => ({
|
||||
no: Extension.ToThaiNumber((idx + 1).toString()),
|
||||
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
|
||||
position: x.position ? x.position : "",
|
||||
posLevelName: x.posLevelName ? x.posLevelName : "",
|
||||
evaluationResults: x.evaluationResults
|
||||
? Extension.EvaluationResult(x.evaluationResults)
|
||||
: "",
|
||||
})),
|
||||
}
|
||||
}
|
||||
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,
|
||||
|
|
@ -168,26 +380,26 @@ export class ReportController extends Controller {
|
|||
|
||||
startDateApr:
|
||||
kpiUserEvaluation.kpiPeriod == null ||
|
||||
kpiUserEvaluation.kpiPeriod.startDate == null ||
|
||||
kpiUserEvaluation.kpiPeriod.durationKPI != "APR"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
kpiUserEvaluation.kpiPeriod.endDate == null ||
|
||||
kpiUserEvaluation.kpiPeriod.durationKPI != "OCT"
|
||||
? "-"
|
||||
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.endDate)),
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,30 @@
|
|||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
class Extension {
|
||||
|
||||
public static EvaluationResult(value: string) {
|
||||
switch (value) {
|
||||
case "PENDING":
|
||||
return "รอดำเนินการ";
|
||||
case "PASSED":
|
||||
return "ผ่านการประเมิน";
|
||||
case "NOTPASSED":
|
||||
return "ไม่ผ่านการประเมิน";
|
||||
case "EXCELLENT":
|
||||
return "ดีเด่น";
|
||||
case "VERY_GOOD":
|
||||
return "ดีมาก";
|
||||
case "GOOD":
|
||||
return "ดี";
|
||||
case "FAIR":
|
||||
return "พอใช้";
|
||||
case "IMPROVEMENT":
|
||||
return "ต้องปรับปรุง";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static ToThaiMonth(value: number) {
|
||||
switch (value) {
|
||||
case 1:
|
||||
|
|
@ -100,6 +124,17 @@ class Extension {
|
|||
);
|
||||
}
|
||||
|
||||
public static ToThaiFullDate2(value: Date) {
|
||||
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
|
||||
return (
|
||||
value.getDate() +
|
||||
" " +
|
||||
Extension.ToThaiMonth(value.getMonth() + 1) +
|
||||
" " +
|
||||
yy
|
||||
);
|
||||
}
|
||||
|
||||
public static ToThaiShortDate(value: Date) {
|
||||
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue