342 lines
9.6 KiB
TypeScript
342 lines
9.6 KiB
TypeScript
import { Controller, Example, Get, Path, Response, Route, SuccessResponse, Tags } from "tsoa";
|
|
|
|
import { DateTime } from "@elastic/elasticsearch/lib/api/types";
|
|
import { Double } from "typeorm";
|
|
import { AppDataSource } from "../database/data-source";
|
|
import { OrgRevision } from "../entities/OrgRevision";
|
|
import { Profile } from "../entities/Profile";
|
|
import HttpError from "../interfaces/http-error";
|
|
import HttpStatus from "../interfaces/http-status";
|
|
|
|
interface DPISResponse {
|
|
/**
|
|
* สถานะ
|
|
*/
|
|
status: number;
|
|
|
|
/**
|
|
* ข้อความตอบกลับ
|
|
*/
|
|
message: string;
|
|
|
|
/**
|
|
* ผลลัพธ์การค้นหา
|
|
*/
|
|
result?: DPISResult;
|
|
}
|
|
|
|
interface DPISResult {
|
|
/**
|
|
* เลขประจำตัวประชาชน
|
|
*/
|
|
citizenId: string;
|
|
/**
|
|
* คำนำหน้า
|
|
*/
|
|
prefix: string;
|
|
/**
|
|
* ชื่อ
|
|
*/
|
|
firstName: string;
|
|
/**
|
|
* นามสกุล
|
|
*/
|
|
lastName: string;
|
|
/**
|
|
* เพศ
|
|
*/
|
|
gender: string;
|
|
/**
|
|
* สถานะ
|
|
*/
|
|
physicalStatus: string;
|
|
/**
|
|
* หน่วยงานคุณภาพ
|
|
*/
|
|
QualityWorkforce: boolean;
|
|
/**
|
|
* วันเกิด
|
|
*/
|
|
birthDate: DateTime;
|
|
/**
|
|
* วันบรรจุ
|
|
*/
|
|
dateAppoint: DateTime;
|
|
/**
|
|
* วันเริ่มปฏิบัติราชการ
|
|
*/
|
|
dateStart: DateTime;
|
|
/**
|
|
* วันที่เกษียณอายุราชการ
|
|
*/
|
|
dateRetire: DateTime;
|
|
/**
|
|
* พ้นจากราชการหรือไม่?
|
|
*/
|
|
isLeave: boolean;
|
|
/**
|
|
* พ้นจากการทดลองปฏิบัติราชการหรือไม่?
|
|
*/
|
|
isProbation: boolean;
|
|
/**
|
|
* สาเหตุการพ้นจากราชการ
|
|
*/
|
|
leaveReason: string;
|
|
/**
|
|
* ระดับ
|
|
*/
|
|
positionLevel: string;
|
|
/**
|
|
* ประเภท
|
|
*/
|
|
positionType: string;
|
|
/**
|
|
* ข้อมูลประวัติการศึกษา
|
|
*/
|
|
educations: ProfileEducationResult[];
|
|
/**
|
|
* ข้อมูลการลา
|
|
*/
|
|
leaves: ProfileLeaveResult[];
|
|
/**
|
|
* ข้อมูลเงินเดือน
|
|
*/
|
|
salaries: ProfileSalaryResult[];
|
|
/**
|
|
* ข้อมูลหน่วยงาน
|
|
*/
|
|
organization: ProfileOrgResult;
|
|
}
|
|
|
|
interface ProfileLeaveResult {
|
|
dateLeaveStart: DateTime;
|
|
dateLeaveEnd: DateTime;
|
|
leaveType: string;
|
|
totalLeave: number;
|
|
}
|
|
|
|
interface ProfileOrgResult {
|
|
/**
|
|
* ผลลัพธ์การค้นหา
|
|
*/
|
|
orgRootName: string;
|
|
|
|
/**
|
|
* กองระดับ 1
|
|
*/
|
|
orgChild1Name: string;
|
|
|
|
/**
|
|
* กองระดับ 2
|
|
*/
|
|
orgChild2Name: string;
|
|
|
|
/**
|
|
* กองระดับ 3
|
|
*/
|
|
orgChild3Name: string;
|
|
|
|
/**
|
|
* กองระดับ 4
|
|
*/
|
|
orgChild4Name: string;
|
|
}
|
|
|
|
interface ProfileEducationResult {
|
|
country: string;
|
|
degree: string;
|
|
field: string;
|
|
institute: string;
|
|
educationLevel: string;
|
|
}
|
|
|
|
interface ProfileSalaryResult {
|
|
posNo: string;
|
|
position: string;
|
|
positionType: string;
|
|
positionLevel: string;
|
|
amount: Double;
|
|
positionSalaryAmount: Double;
|
|
monthSalaryAmount: Double;
|
|
}
|
|
|
|
@Route("api/v1/dpis")
|
|
@Tags("DPIS")
|
|
// @Security("bearerAuth")
|
|
@Response(
|
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
|
)
|
|
@SuccessResponse(HttpStatus.OK, "สำเร็จ")
|
|
export class DPISController extends Controller {
|
|
private profileRepo = AppDataSource.getRepository(Profile);
|
|
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
|
|
|
|
/**
|
|
* แสดงข้อมูลข้าราชการจากเลขประจำตัวประชาชน
|
|
*
|
|
* @summary แสดงข้อมูลข้าราชการจากเลขประจำตัวประชาชน
|
|
*
|
|
* @param {string} citizenId เลขประจำตัวประชาชน
|
|
*
|
|
* @returns ข้อมูลของข้าราชการที่ค้นหาพบในระบบ
|
|
*/
|
|
@Get("{citizenId}")
|
|
@Example({
|
|
status: 200,
|
|
message: "Success",
|
|
result: {
|
|
citizenId: "1103700765894",
|
|
prefix: "นาย",
|
|
firstName: "สุรศักดิ์",
|
|
lastName: "จันทร์ศรี",
|
|
gender: "หญิง",
|
|
physicalStatus: "ปกติ",
|
|
QualityWorkforce: true,
|
|
birthDate: "1995-05-06T17:00:00.000Z",
|
|
dateAppoint: "2022-11-24T17:00:00.000Z",
|
|
dateStart: "2022-11-24T17:00:00.000Z",
|
|
dateRetire: "2055-05-06T17:00:00.000Z",
|
|
isLeave: false,
|
|
isProbation: false,
|
|
leaveReason: null,
|
|
positionLevel: "ปฏิบัติงาน",
|
|
positionType: "ทั่วไป",
|
|
organization: {
|
|
orgRootName: "",
|
|
orgChild1Name: "",
|
|
orgChild2Name: "",
|
|
orgChild3Name: "",
|
|
orgChild4Name: "",
|
|
},
|
|
educations: [],
|
|
salaries: [
|
|
{
|
|
posNo: "ขพน.65",
|
|
position: "เจ้าพนักงานสาธารณสุข",
|
|
positionType: "ทั่วไป",
|
|
positionLevel: "ปฏิบัติงาน",
|
|
amount: 11860,
|
|
positionSalaryAmount: 0,
|
|
monthSalaryAmount: 0,
|
|
},
|
|
{
|
|
posNo: "ขพน.65",
|
|
position:
|
|
"เจ้าพนักงานสาธารณสุขปฏิบัติงาน ฝ่ายสิ่งแวดล้อมและสุขาภิบาล สำนักงานเขตพระนคร\n(ทดลองปฏิบัติหน้าที่ราชการ)",
|
|
positionType: "ทั่วไป",
|
|
positionLevel: "ปฏิบัติงาน",
|
|
amount: 11860,
|
|
positionSalaryAmount: 0,
|
|
monthSalaryAmount: 0,
|
|
},
|
|
{
|
|
posNo: "ขพน.65",
|
|
position:
|
|
"เจ้าพนักงานสาธารณสุขปฏิบัติงาน ฝ่ายสิ่งแวดล้อมและสุขาภิบาล สำนักงานเขตพระนคร\n(ทดลองปฏิบัติหน้าที่ราชการ)",
|
|
positionType: "ทั่วไป",
|
|
positionLevel: "ปฏิบัติงาน",
|
|
amount: 11500,
|
|
positionSalaryAmount: 0,
|
|
monthSalaryAmount: 0,
|
|
},
|
|
],
|
|
leaves: [],
|
|
},
|
|
})
|
|
async GetProfileCitizenIdAsync(@Path() citizenId: string): Promise<DPISResponse> {
|
|
const profile = await this.profileRepo.findOne({
|
|
relations: {
|
|
posLevel: true,
|
|
posType: true,
|
|
profileSalary: true,
|
|
profileEducations: true,
|
|
profileLeaves: true,
|
|
current_holders: true,
|
|
},
|
|
where: { citizenId: citizenId },
|
|
//relations: ["current_holders", "current_holders.orgRoot"],
|
|
order: {
|
|
profileSalary: {
|
|
date: "DESC",
|
|
},
|
|
profileLeaves: {
|
|
dateLeaveStart: "ASC",
|
|
},
|
|
profileEducations: {
|
|
level: "ASC",
|
|
},
|
|
},
|
|
});
|
|
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
|
const findRevision = await this.orgRevisionRepo.findOne({
|
|
where: { orgRevisionIsCurrent: true },
|
|
});
|
|
var current_holder = profile.current_holders?.find((x) => x.orgRevisionId == findRevision?.id);
|
|
|
|
const mapProfile: DPISResult = {
|
|
citizenId: profile.citizenId,
|
|
prefix: profile.prefix,
|
|
firstName: profile.firstName,
|
|
lastName: profile.lastName,
|
|
gender: profile.gender,
|
|
physicalStatus: "ปกติ",
|
|
QualityWorkforce: true,
|
|
birthDate: profile.birthDate,
|
|
dateAppoint: profile.dateAppoint,
|
|
dateStart: profile.dateStart,
|
|
dateRetire: profile.dateRetire,
|
|
isLeave: profile.isLeave,
|
|
isProbation: profile.isProbation,
|
|
leaveReason: profile.leaveReason,
|
|
positionLevel: profile.posLevel ? profile.posLevel.posLevelName : "",
|
|
positionType: profile.posType ? profile.posType.posTypeName : "",
|
|
|
|
organization: {
|
|
orgRootName: current_holder?.orgRoot?.orgRootName || "",
|
|
orgChild1Name: current_holder?.orgChild1?.orgChild1Name || "",
|
|
orgChild2Name: current_holder?.orgChild2?.orgChild2Name || "",
|
|
orgChild3Name: current_holder?.orgChild3?.orgChild3Name || "",
|
|
orgChild4Name: current_holder?.orgChild4?.orgChild4Name || "",
|
|
},
|
|
|
|
// educations
|
|
educations: profile.profileEducations.map((item) => {
|
|
return {
|
|
country: item.country,
|
|
degree: item.degree,
|
|
field: item.field,
|
|
institute: item.institute,
|
|
educationLevel: item.educationLevel,
|
|
};
|
|
}),
|
|
|
|
salaries: profile.profileSalary.map((item) => {
|
|
return {
|
|
posNo: item.posNo,
|
|
position: item.position,
|
|
positionType: item.positionType,
|
|
positionLevel: item.positionLevel,
|
|
amount: item.amount,
|
|
positionSalaryAmount: item.positionSalaryAmount,
|
|
monthSalaryAmount: item.mouthSalaryAmount,
|
|
};
|
|
}),
|
|
|
|
leaves: profile.profileLeaves.map((item) => {
|
|
return {
|
|
dateLeaveStart: item.dateLeaveStart,
|
|
dateLeaveEnd: item.dateLeaveEnd,
|
|
leaveType: item.leaveType ? item.leaveType.name : "",
|
|
totalLeave: item.totalLeave,
|
|
};
|
|
}),
|
|
};
|
|
|
|
return {
|
|
status: 200,
|
|
message: "Success",
|
|
result: mapProfile,
|
|
};
|
|
}
|
|
}
|