first
This commit is contained in:
commit
925c5d1ab2
60 changed files with 18843 additions and 0 deletions
370
src/controllers/ReportController.ts
Normal file
370
src/controllers/ReportController.ts
Normal file
|
|
@ -0,0 +1,370 @@
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
Body,
|
||||
Example,
|
||||
Get,
|
||||
Path,
|
||||
Post,
|
||||
Put,
|
||||
Request,
|
||||
Response,
|
||||
Route,
|
||||
Security,
|
||||
SuccessResponse,
|
||||
Tags,
|
||||
Delete,
|
||||
} from "tsoa";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { Evaluation } from "../entities/Evaluation";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import { EvaluationLogs } from "../entities/EvaluationLogs";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Education } from "../entities/Education";
|
||||
import { Certificate } from "../entities/Certificate";
|
||||
import { Salary } from "../entities/Salary";
|
||||
import { Training } from "../entities/Training";
|
||||
import { Assessment } from "../entities/Assessment";
|
||||
import { Director } from "../entities/Director";
|
||||
import { Meeting } from "../entities/Meeting";
|
||||
import { Brackets } from "typeorm";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import Extension from "../interfaces/extension";
|
||||
import { Not } from "typeorm"
|
||||
@Route("api/v1/evaluation/report")
|
||||
@Tags("report")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถทำรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class ReoportController {
|
||||
private evaluationRepository = AppDataSource.getRepository(Evaluation);
|
||||
private evaluationLogsRepository = AppDataSource.getRepository(EvaluationLogs);
|
||||
private educationRepository = AppDataSource.getRepository(Education);
|
||||
private certificateRepository = AppDataSource.getRepository(Certificate);
|
||||
private salaryRepository = AppDataSource.getRepository(Salary);
|
||||
private trainingRepository = AppDataSource.getRepository(Training);
|
||||
private assessmentRepository = AppDataSource.getRepository(Assessment);
|
||||
private directorRepository = AppDataSource.getRepository(Director);
|
||||
private meetingRepository = AppDataSource.getRepository(Meeting);
|
||||
|
||||
/**
|
||||
* Report ระบบประเมินบุคคล
|
||||
*
|
||||
* @summary Report ระบบประเมินบุคคล (ADMIN & USER)
|
||||
*
|
||||
* @param {string} id id ข้อมูลการประเมิน
|
||||
*/
|
||||
@Get("check-spec-report/{id}")
|
||||
async checkSpecGetReport(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
const evaluation = await AppDataSource.getRepository(Evaluation)
|
||||
.createQueryBuilder("evaluation")
|
||||
.leftJoin("evaluation.education", "education")
|
||||
.leftJoin("evaluation.certificate", "certificate")
|
||||
.leftJoin("evaluation.salaries", "salaries")
|
||||
.leftJoin("evaluation.training", "training")
|
||||
.leftJoin("evaluation.assessment", "assessment")
|
||||
.where("evaluation.id = :id", { id })
|
||||
.select([
|
||||
"evaluation.id",
|
||||
"evaluation.userId",
|
||||
"evaluation.subject",
|
||||
"evaluation.isEducationalQft",
|
||||
"evaluation.isGovermantServiceHtr",
|
||||
"evaluation.isOperatingExp",
|
||||
"evaluation.isMinPeriodOfTenure",
|
||||
"evaluation.isHaveSpecificQft",
|
||||
"evaluation.isHaveProLicense",
|
||||
"evaluation.isHaveMinPeriodOrHoldPos",
|
||||
"evaluation.type",
|
||||
"evaluation.prefix",
|
||||
"evaluation.fullName",
|
||||
"evaluation.position",
|
||||
"evaluation.posNo",
|
||||
"evaluation.oc",
|
||||
"evaluation.salary",
|
||||
"evaluation.positionLevel",
|
||||
"evaluation.birthDate",
|
||||
"evaluation.govAge",
|
||||
"evaluation.experience",
|
||||
|
||||
"education.educationLevel",
|
||||
"education.institute",
|
||||
"education.isDate",
|
||||
"education.startDate",
|
||||
"education.endDate",
|
||||
"education.finishDate",
|
||||
"education.isEducation",
|
||||
"education.degree",
|
||||
"education.field",
|
||||
"education.fundName",
|
||||
"education.gpa",
|
||||
"education.country",
|
||||
"education.other",
|
||||
"education.duration",
|
||||
"education.durationYear",
|
||||
|
||||
"certificate.certificateType",
|
||||
"certificate.issuer",
|
||||
"certificate.certificateNo",
|
||||
"certificate.issueDate",
|
||||
"certificate.expireDate",
|
||||
|
||||
"salaries.date",
|
||||
"salaries.amount",
|
||||
"salaries.positionSalaryAmount",
|
||||
"salaries.mouthSalaryAmount",
|
||||
"salaries.position",
|
||||
"salaries.posNo",
|
||||
"salaries.salaryClass",
|
||||
"salaries.salaryRef",
|
||||
"salaries.refCommandNo",
|
||||
"salaries.refCommandDate",
|
||||
"salaries.salaryStatus",
|
||||
|
||||
"training.name",
|
||||
"training.topic",
|
||||
"training.startDate",
|
||||
"training.endDate",
|
||||
"training.yearly",
|
||||
"training.place",
|
||||
"training.duration",
|
||||
"training.department",
|
||||
"training.numberOrder",
|
||||
"training.dateOrder",
|
||||
|
||||
"assessment.date",
|
||||
"assessment.point1Total",
|
||||
"assessment.point1",
|
||||
"assessment.point2Total",
|
||||
"assessment.point2",
|
||||
"assessment.pointSumTotal",
|
||||
"assessment.pointSum",
|
||||
])
|
||||
.getOne();
|
||||
|
||||
if (!evaluation) {
|
||||
return "ไม่พบข้อมูล";
|
||||
}
|
||||
let root: any
|
||||
let dateStart: any
|
||||
let dateRetireLaw: any
|
||||
let org: any
|
||||
let commanderFullname: any
|
||||
let commanderPosition: any
|
||||
let commanderRootName: any
|
||||
let commanderOrg: any
|
||||
let commanderAboveFullname: any
|
||||
let commanderAbovePosition: any
|
||||
let commanderAboveRootName: any
|
||||
let commanderAboveOrg: any
|
||||
if (!evaluation.userId) {
|
||||
return "ไม่พบข้อมูลผู้ขอประเมิน";
|
||||
}
|
||||
await new CallAPI()
|
||||
.GetData(request, `/org/profile/keycloak/commander/${evaluation.userId}`)
|
||||
.then(async (x) => {
|
||||
root = x.root,
|
||||
dateStart = x.dateStart,
|
||||
dateRetireLaw = x.dateRetireLaw,
|
||||
org = x.org,
|
||||
commanderFullname = x.commanderFullname,
|
||||
commanderPosition = x.commanderPosition,
|
||||
commanderRootName = x.commanderRootName,
|
||||
commanderOrg = x.commanderOrg,
|
||||
commanderAboveFullname = x.commanderAboveFullname,
|
||||
commanderAbovePosition = x.commanderAbovePosition,
|
||||
commanderAboveRootName = x.commanderAboveRootName,
|
||||
commanderAboveOrg = x.commanderAboveOrg
|
||||
})
|
||||
.catch();
|
||||
const evaluationOld = await this.evaluationRepository.find({
|
||||
where: {
|
||||
id: Not(id),
|
||||
userId: evaluation.userId,
|
||||
step: "DONE"
|
||||
}
|
||||
});
|
||||
let subjectOld = evaluationOld.length > 0
|
||||
? evaluationOld.map(x => x.subject).join(", ")
|
||||
: "ไม่มี"
|
||||
let thaiYear:number = new Date().getFullYear()+543
|
||||
let years = {
|
||||
lastTwoYear: Extension.ToThaiNumber((thaiYear-2).toString()),
|
||||
lastOneYear: Extension.ToThaiNumber((thaiYear-1).toString()),
|
||||
currentYear: Extension.ToThaiNumber(thaiYear.toString()),
|
||||
}
|
||||
const dataEvaluation = {
|
||||
isEducationalQft: evaluation.isEducationalQft,
|
||||
isGovermantServiceHtr: evaluation.isGovermantServiceHtr,
|
||||
isOperatingExp: evaluation.isOperatingExp,
|
||||
isMinPeriodOfTenure: evaluation.isMinPeriodOfTenure,
|
||||
isHaveSpecificQft: evaluation.isHaveSpecificQft,
|
||||
isHaveProLicense: evaluation.isHaveProLicense,
|
||||
isHaveMinPeriodOrHoldPos: evaluation.isHaveMinPeriodOrHoldPos,
|
||||
type: evaluation.type,
|
||||
prefix: evaluation.prefix,
|
||||
fullName: evaluation.prefix && evaluation.fullName ? `${evaluation.prefix}${evaluation.fullName}` : "-",
|
||||
position: evaluation.position ? evaluation.position : "-",
|
||||
posNo: evaluation.posNo ? Extension.ToThaiNumber(evaluation.posNo) : "-",
|
||||
oc: evaluation.oc ? evaluation.oc : "-",
|
||||
org: org ? org : "-", //สังกัด
|
||||
root: root ? root : "-", //หน่วยงาน
|
||||
salary: evaluation.salary ? Extension.ToThaiNumber(evaluation.salary) : "-",
|
||||
positionLevel: evaluation.positionLevel ? evaluation.positionLevel : "-",
|
||||
birthDate: evaluation.birthDate != null && evaluation.birthDate != ""
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(new Date(evaluation.birthDate)))
|
||||
: "-",
|
||||
govAge: evaluation.govAge != null
|
||||
? Extension.ToThaiNumber(evaluation.govAge)
|
||||
: "-",
|
||||
experience: evaluation.experience ? evaluation.experience : "-",
|
||||
dateStart: dateStart
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date(dateStart)))
|
||||
: "-",
|
||||
dateRetireLaw: dateRetireLaw
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date(dateRetireLaw)))
|
||||
: "-",
|
||||
subject: evaluation.subject != null ? evaluation.subject : "-",
|
||||
subjectOld: subjectOld,
|
||||
educations: evaluation.education.length > 0
|
||||
? evaluation.education.map((education) => ({
|
||||
educationLevel: education.educationLevel
|
||||
? Extension.ToThaiNumber(education.educationLevel)
|
||||
: "-",
|
||||
institute: education.institute
|
||||
? Extension.ToThaiNumber(education.institute)
|
||||
: "-",
|
||||
finishYear: education.finishDate
|
||||
? Extension.ToThaiNumber((Extension.ToThaiYear(education.finishDate.getFullYear())).toString())
|
||||
: "-",
|
||||
isDate: education.isDate,
|
||||
startDate: education.startDate,
|
||||
endDate: education.endDate,
|
||||
finishDate: education.finishDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate(education.finishDate).toString())
|
||||
: "-",
|
||||
isEducation: education.isEducation,
|
||||
degree: education.degree
|
||||
? Extension.ToThaiNumber(education.degree)
|
||||
: "-",
|
||||
field: education.field
|
||||
? Extension.ToThaiNumber(education.field)
|
||||
: "-",
|
||||
fundName: education.fundName,
|
||||
gpa: education.gpa,
|
||||
country: education.country,
|
||||
other: education.other,
|
||||
duration: education.duration,
|
||||
durationYear: education.durationYear,
|
||||
}))
|
||||
: [{
|
||||
educationLevel: "-",
|
||||
institute: "-",
|
||||
finishYear: "-",
|
||||
finishDate: "-",
|
||||
degree: "-",
|
||||
field: "-"
|
||||
}],
|
||||
certificates: evaluation.certificate.length > 0
|
||||
? evaluation.certificate.map((certificate) => ({
|
||||
certificateType: certificate.certificateType
|
||||
? Extension.ToThaiNumber(certificate.certificateType)
|
||||
: "-",
|
||||
issuer: certificate.issuer
|
||||
? Extension.ToThaiNumber(certificate.issuer)
|
||||
: "-",
|
||||
certificateNo: certificate.certificateNo
|
||||
? Extension.ToThaiNumber(certificate.certificateNo)
|
||||
: "-",
|
||||
issueDate: certificate.issueDate,
|
||||
expireDate: certificate.expireDate,
|
||||
}))
|
||||
: [{
|
||||
certificateType: "-",
|
||||
issuer: "-",
|
||||
certificateNo: "-",
|
||||
issueDate: "-",
|
||||
expireDate: "-",
|
||||
}],
|
||||
salaries: evaluation.salaries.length > 0
|
||||
? evaluation.salaries.map((salaries) => ({
|
||||
date: salaries.date
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(salaries.date))
|
||||
: "-",
|
||||
amount: salaries.amount
|
||||
? Extension.ToThaiNumber(salaries.amount.toLocaleString())
|
||||
: "-",
|
||||
position: salaries.position
|
||||
? Extension.ToThaiNumber(salaries.position)
|
||||
: "-",
|
||||
positionSalaryAmount: salaries.positionSalaryAmount,
|
||||
mouthSalaryAmount: salaries.mouthSalaryAmount,
|
||||
posNo: salaries.posNo,
|
||||
salaryClass: salaries.salaryClass,
|
||||
salaryRef: salaries.salaryRef,
|
||||
refCommandNo: salaries.refCommandNo,
|
||||
refCommandDate: salaries.refCommandDate,
|
||||
salaryStatus: salaries.salaryStatus,
|
||||
}))
|
||||
: [{
|
||||
date: "-",
|
||||
amount: "-",
|
||||
position: "-",
|
||||
}],
|
||||
trainings: evaluation.training.length > 0
|
||||
? evaluation.training.map((training) => ({
|
||||
name: training.name
|
||||
? Extension.ToThaiNumber(training.name)
|
||||
: "-",
|
||||
topic: training.topic
|
||||
? Extension.ToThaiNumber(training.topic)
|
||||
: "-",
|
||||
startDate: training.startDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(training.startDate))
|
||||
: "-",
|
||||
endDate: training.endDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(training.endDate))
|
||||
: "-",
|
||||
yearly: training.yearly
|
||||
? Extension.ToThaiNumber(training.yearly.toString())
|
||||
: "-",
|
||||
place: training.place,
|
||||
duration: training.duration,
|
||||
department: training.department,
|
||||
numberOrder: training.numberOrder,
|
||||
dateOrder: training.dateOrder,
|
||||
}))
|
||||
: [{
|
||||
name: "-",
|
||||
topic: "-",
|
||||
yearly: "-",
|
||||
}],
|
||||
assessments: evaluation.assessment.map((assessment) => ({
|
||||
date: assessment.date,
|
||||
point1Total: assessment.point1Total,
|
||||
point1: assessment.point1,
|
||||
point2Total: assessment.point2Total,
|
||||
point2: assessment.point2,
|
||||
pointSumTotal: assessment.pointSumTotal,
|
||||
pointSum: assessment.pointSum,
|
||||
})),
|
||||
commanderFullname: commanderFullname ? commanderFullname : "-",
|
||||
commanderPosition: commanderPosition ? commanderPosition : "-",
|
||||
commanderRootName: commanderRootName ? commanderRootName : "-",
|
||||
commanderOrg: commanderOrg ? commanderOrg : "-",
|
||||
commanderAboveFullname: commanderAboveFullname ? commanderAboveFullname : "-",
|
||||
commanderAbovePosition: commanderAbovePosition ? commanderAbovePosition : "-",
|
||||
commanderAboveRootName: commanderAboveRootName ? commanderAboveRootName : "-",
|
||||
commanderAboveOrg: commanderAboveOrg ? commanderAboveOrg : "-",
|
||||
years: years
|
||||
};
|
||||
|
||||
if (!dataEvaluation) {
|
||||
return "ไม่พบข้อมูล";
|
||||
}
|
||||
return new HttpSuccess(dataEvaluation);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue