Merge branch 'develop'
This commit is contained in:
commit
75e1d761b5
12 changed files with 918 additions and 249 deletions
|
|
@ -439,6 +439,7 @@ export class CommandController extends Controller {
|
||||||
remarkVertical: x.remarkVertical,
|
remarkVertical: x.remarkVertical,
|
||||||
remarkHorizontal: x.remarkHorizontal,
|
remarkHorizontal: x.remarkHorizontal,
|
||||||
amount: x.amount,
|
amount: x.amount,
|
||||||
|
amountSpecial: x.amountSpecial,
|
||||||
positionSalaryAmount: x.positionSalaryAmount,
|
positionSalaryAmount: x.positionSalaryAmount,
|
||||||
mouthSalaryAmount: x.mouthSalaryAmount,
|
mouthSalaryAmount: x.mouthSalaryAmount,
|
||||||
})),
|
})),
|
||||||
|
|
@ -542,6 +543,7 @@ export class CommandController extends Controller {
|
||||||
remarkVertical: string | null;
|
remarkVertical: string | null;
|
||||||
remarkHorizontal: string | null;
|
remarkHorizontal: string | null;
|
||||||
amount: Double | null;
|
amount: Double | null;
|
||||||
|
amountSpecial: Double | null;
|
||||||
positionSalaryAmount: Double | null;
|
positionSalaryAmount: Double | null;
|
||||||
mouthSalaryAmount: Double | null;
|
mouthSalaryAmount: Double | null;
|
||||||
},
|
},
|
||||||
|
|
@ -698,10 +700,10 @@ export class CommandController extends Controller {
|
||||||
commandSend.lastUpdateFullName = request.user.name;
|
commandSend.lastUpdateFullName = request.user.name;
|
||||||
commandSend.lastUpdatedAt = new Date();
|
commandSend.lastUpdatedAt = new Date();
|
||||||
await this.commandSendRepository.save(commandSend);
|
await this.commandSendRepository.save(commandSend);
|
||||||
if(commandSend && commandSend.id) {
|
if (commandSend && commandSend.id) {
|
||||||
let _ccName = new Array("EMAIL", "INBOX");
|
let _ccName = new Array("EMAIL", "INBOX");
|
||||||
let _dataSendCC = new Array();
|
let _dataSendCC = new Array();
|
||||||
for(let i=0; i<_ccName.length; i++) {
|
for (let i = 0; i < _ccName.length; i++) {
|
||||||
_dataSendCC.push({
|
_dataSendCC.push({
|
||||||
commandSendId: commandSend.id,
|
commandSendId: commandSend.id,
|
||||||
name: _ccName[i],
|
name: _ccName[i],
|
||||||
|
|
@ -941,6 +943,7 @@ export class CommandController extends Controller {
|
||||||
await new permission().PermissionGet(request, "COMMAND");
|
await new permission().PermissionGet(request, "COMMAND");
|
||||||
const command = await this.commandRepository.findOne({
|
const command = await this.commandRepository.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
|
relations: ["commandType"],
|
||||||
});
|
});
|
||||||
if (!command) {
|
if (!command) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||||
|
|
@ -953,6 +956,7 @@ export class CommandController extends Controller {
|
||||||
isDraft: command.isDraft,
|
isDraft: command.isDraft,
|
||||||
isSign: command.isSign,
|
isSign: command.isSign,
|
||||||
isAttachment: command.isAttachment,
|
isAttachment: command.isAttachment,
|
||||||
|
isSalary: command.commandType ? command.commandType.isSalary : null,
|
||||||
};
|
};
|
||||||
return new HttpSuccess(_command);
|
return new HttpSuccess(_command);
|
||||||
}
|
}
|
||||||
|
|
@ -1144,88 +1148,88 @@ export class CommandController extends Controller {
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API ออกคำสั่ง
|
* API ออกคำสั่ง
|
||||||
*
|
*
|
||||||
* @summary API ออกคำสั่ง
|
* @summary API ออกคำสั่ง
|
||||||
*
|
*
|
||||||
* @param {string} id Id คำสั่ง
|
* @param {string} id Id คำสั่ง
|
||||||
*/
|
*/
|
||||||
@Put("testRabbit/{id}")
|
@Put("testRabbit/{id}")
|
||||||
async testRabbit(
|
async testRabbit(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: { sign?: boolean },
|
requestBody: { sign?: boolean },
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "COMMAND");
|
await new permission().PermissionUpdate(request, "COMMAND");
|
||||||
const command = await this.commandRepository.findOne({
|
const command = await this.commandRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
relations: ["commandType", "commandRecives",],
|
relations: ["commandType", "commandRecives"],
|
||||||
});
|
});
|
||||||
if (!command) {
|
if (!command) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||||
}
|
}
|
||||||
command.isSign = true;
|
command.isSign = true;
|
||||||
if (command.commandExcecuteDate == null)
|
if (command.commandExcecuteDate == null)
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล");
|
||||||
|
|
||||||
let profiles =
|
let profiles =
|
||||||
command && command.commandRecives.length > 0
|
command && command.commandRecives.length > 0
|
||||||
? command.commandRecives
|
? command.commandRecives
|
||||||
.filter((x) => x.profileId != null)
|
.filter((x) => x.profileId != null)
|
||||||
.map((x) => ({
|
.map((x) => ({
|
||||||
receiverUserId: x.profileId,
|
receiverUserId: x.profileId,
|
||||||
notiLink: "",
|
notiLink: "",
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostData(request, "/placement/noti/profiles", {
|
.PostData(request, "/placement/noti/profiles", {
|
||||||
subject: `${command.issue}`,
|
subject: `${command.issue}`,
|
||||||
body: `${command.issue}`,
|
body: `${command.issue}`,
|
||||||
receiverUserIds: profiles,
|
receiverUserIds: profiles,
|
||||||
payload: "", //แนบไฟล์
|
payload: "", //แนบไฟล์
|
||||||
isSendMail: true,
|
isSendMail: true,
|
||||||
isSendInbox: true,
|
isSendInbox: true,
|
||||||
isSendNotification: true,
|
isSendNotification: true,
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error calling API:", error);
|
console.error("Error calling API:", error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) <
|
||||||
|
new Date(
|
||||||
|
command.commandExcecuteDate.getFullYear(),
|
||||||
|
command.commandExcecuteDate.getMonth(),
|
||||||
|
command.commandExcecuteDate.getDate(),
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
command.status = "WAITING";
|
||||||
|
command.lastUpdateUserId = request.user.sub;
|
||||||
|
command.lastUpdateFullName = request.user.name;
|
||||||
|
command.lastUpdatedAt = new Date();
|
||||||
|
await this.commandRepository.save(command);
|
||||||
|
} else {
|
||||||
|
const path = commandTypePath(command.commandType.code);
|
||||||
|
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||||
|
const msg = {
|
||||||
|
data: {
|
||||||
|
id: command.id,
|
||||||
|
status: "REPORTED",
|
||||||
|
lastUpdateUserId: request.user.sub,
|
||||||
|
lastUpdateFullName: request.user.name,
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
},
|
||||||
|
user: request.user,
|
||||||
|
token: request.headers["authorization"],
|
||||||
|
};
|
||||||
|
sendToQueue(msg);
|
||||||
|
}
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) <
|
|
||||||
new Date(
|
|
||||||
command.commandExcecuteDate.getFullYear(),
|
|
||||||
command.commandExcecuteDate.getMonth(),
|
|
||||||
command.commandExcecuteDate.getDate(),
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
command.status = "WAITING";
|
|
||||||
command.lastUpdateUserId = request.user.sub;
|
|
||||||
command.lastUpdateFullName = request.user.name;
|
|
||||||
command.lastUpdatedAt = new Date();
|
|
||||||
await this.commandRepository.save(command);
|
|
||||||
} else {
|
|
||||||
const path = commandTypePath(command.commandType.code);
|
|
||||||
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
|
||||||
const msg = {
|
|
||||||
data: {
|
|
||||||
id: command.id,
|
|
||||||
status: "REPORTED",
|
|
||||||
lastUpdateUserId: request.user.sub,
|
|
||||||
lastUpdateFullName: request.user.name,
|
|
||||||
lastUpdatedAt: new Date(),
|
|
||||||
},
|
|
||||||
user: request.user,
|
|
||||||
token: request.headers["authorization"],
|
|
||||||
};
|
|
||||||
sendToQueue(msg);
|
|
||||||
}
|
|
||||||
return new HttpSuccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
async cronjobCommand(@Request() request?: RequestWithUser) {
|
async cronjobCommand(@Request() request?: RequestWithUser) {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
today.setUTCHours(0, 0, 0, 0);
|
today.setUTCHours(0, 0, 0, 0);
|
||||||
|
|
@ -1251,7 +1255,7 @@ export class CommandController extends Controller {
|
||||||
let _data: any = null;
|
let _data: any = null;
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostDataKeycloak("/realms/bma-ehr/protocol/openid-connect/token", data)
|
.PostDataKeycloak(`/realms/${process.env.KC_REALM}/protocol/openid-connect/token`, data)
|
||||||
.then(async (x) => {
|
.then(async (x) => {
|
||||||
_data = x;
|
_data = x;
|
||||||
})
|
})
|
||||||
|
|
@ -1631,7 +1635,7 @@ export class CommandController extends Controller {
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
let command = new Command();
|
let command = new Command();
|
||||||
let commandCode:string = "";
|
let commandCode: string = "";
|
||||||
let null_: any = null;
|
let null_: any = null;
|
||||||
if (
|
if (
|
||||||
requestBody.commandId != undefined &&
|
requestBody.commandId != undefined &&
|
||||||
|
|
@ -1822,10 +1826,10 @@ export class CommandController extends Controller {
|
||||||
commandSend.lastUpdateFullName = request.user.name;
|
commandSend.lastUpdateFullName = request.user.name;
|
||||||
commandSend.lastUpdatedAt = new Date();
|
commandSend.lastUpdatedAt = new Date();
|
||||||
await this.commandSendRepository.save(commandSend);
|
await this.commandSendRepository.save(commandSend);
|
||||||
if(commandSend && commandSend.id) {
|
if (commandSend && commandSend.id) {
|
||||||
let _ccName = new Array("EMAIL", "INBOX");
|
let _ccName = new Array("EMAIL", "INBOX");
|
||||||
let _dataSendCC = new Array();
|
let _dataSendCC = new Array();
|
||||||
for(let i=0; i<_ccName.length; i++) {
|
for (let i = 0; i < _ccName.length; i++) {
|
||||||
_dataSendCC.push({
|
_dataSendCC.push({
|
||||||
commandSendId: commandSend.id,
|
commandSendId: commandSend.id,
|
||||||
name: _ccName[i],
|
name: _ccName[i],
|
||||||
|
|
@ -1838,7 +1842,7 @@ export class CommandController extends Controller {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await this.commandSendCCRepository.save(_dataSendCC);
|
await this.commandSendCCRepository.save(_dataSendCC);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -1880,10 +1884,10 @@ export class CommandController extends Controller {
|
||||||
commandSend.lastUpdateFullName = request.user.name;
|
commandSend.lastUpdateFullName = request.user.name;
|
||||||
commandSend.lastUpdatedAt = new Date();
|
commandSend.lastUpdatedAt = new Date();
|
||||||
await this.commandSendRepository.save(commandSend);
|
await this.commandSendRepository.save(commandSend);
|
||||||
if(commandSend && commandSend.id) {
|
if (commandSend && commandSend.id) {
|
||||||
let _ccName = new Array("EMAIL", "INBOX");
|
let _ccName = new Array("EMAIL", "INBOX");
|
||||||
let _dataSendCC = new Array();
|
let _dataSendCC = new Array();
|
||||||
for(let i=0; i<_ccName.length; i++) {
|
for (let i = 0; i < _ccName.length; i++) {
|
||||||
_dataSendCC.push({
|
_dataSendCC.push({
|
||||||
commandSendId: commandSend.id,
|
commandSendId: commandSend.id,
|
||||||
name: _ccName[i],
|
name: _ccName[i],
|
||||||
|
|
@ -1932,7 +1936,7 @@ export class CommandController extends Controller {
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.data.map(async (item) => {
|
body.data.map(async (item) => {
|
||||||
const profile:any = await this.profileRepository.findOneBy({ id: item.profileId });
|
const profile: any = await this.profileRepository.findOneBy({ id: item.profileId });
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
|
||||||
}
|
}
|
||||||
|
|
@ -2054,7 +2058,7 @@ export class CommandController extends Controller {
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.data.map(async (item) => {
|
body.data.map(async (item) => {
|
||||||
const profile:any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
|
const profile: any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
}
|
}
|
||||||
|
|
@ -2261,16 +2265,22 @@ export class CommandController extends Controller {
|
||||||
lastName: profile.lastName,
|
lastName: profile.lastName,
|
||||||
});
|
});
|
||||||
// กรณี Keycloak ไม่ถูกลบ ให้ลบซ้ำอีกรอบแล้วสร้างใหม่ และหากยังไม่สามารถลบได้ให้แสดง Error
|
// กรณี Keycloak ไม่ถูกลบ ให้ลบซ้ำอีกรอบแล้วสร้างใหม่ และหากยังไม่สามารถลบได้ให้แสดง Error
|
||||||
if (profile.keycloak != null && userKeycloakId && userKeycloakId.errorMessage === "User exists with same username") {
|
if (
|
||||||
|
profile.keycloak != null &&
|
||||||
|
userKeycloakId &&
|
||||||
|
userKeycloakId.errorMessage === "User exists with same username"
|
||||||
|
) {
|
||||||
const delUserKeycloak = await deleteUser(profile.keycloak);
|
const delUserKeycloak = await deleteUser(profile.keycloak);
|
||||||
if(delUserKeycloak) {
|
if (delUserKeycloak) {
|
||||||
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
|
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
|
||||||
firstName: profile.firstName,
|
firstName: profile.firstName,
|
||||||
lastName: profile.lastName,
|
lastName: profile.lastName,
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
throw new HttpError(
|
||||||
throw new HttpError(HttpStatus.BAD_REQUEST, "พบข้อผิดพลาด ไม่สามารถจัดการผู้ใช้งานได้");
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"พบข้อผิดพลาด ไม่สามารถจัดการผู้ใช้งานได้",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const list = await getRoles();
|
const list = await getRoles();
|
||||||
|
|
@ -2426,7 +2436,7 @@ export class CommandController extends Controller {
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.data.map(async (item) => {
|
body.data.map(async (item) => {
|
||||||
const profile:any = await this.profileRepository.findOne({
|
const profile: any = await this.profileRepository.findOne({
|
||||||
where: { id: item.profileId },
|
where: { id: item.profileId },
|
||||||
relations: ["roleKeycloaks"],
|
relations: ["roleKeycloaks"],
|
||||||
});
|
});
|
||||||
|
|
@ -2705,7 +2715,7 @@ export class CommandController extends Controller {
|
||||||
const exceptClear = await checkExceptCommandType(String(item.commandId));
|
const exceptClear = await checkExceptCommandType(String(item.commandId));
|
||||||
if (item.isLeave == true && !exceptClear) {
|
if (item.isLeave == true && !exceptClear) {
|
||||||
await removeProfileInOrganize(_profile.id, "OFFICER");
|
await removeProfileInOrganize(_profile.id, "OFFICER");
|
||||||
}
|
}
|
||||||
//คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
|
//คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
|
||||||
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
|
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
|
||||||
// const enableActive = await enableStatus(_profile.keycloak, false);
|
// const enableActive = await enableStatus(_profile.keycloak, false);
|
||||||
|
|
@ -3157,7 +3167,7 @@ export class CommandController extends Controller {
|
||||||
where: { profileId: profile.id },
|
where: { profileId: profile.id },
|
||||||
order: { order: "DESC" },
|
order: { order: "DESC" },
|
||||||
});
|
});
|
||||||
const profileSal: any = new ProfileSalary();
|
const profileSal: any = new ProfileSalary();
|
||||||
Object.assign(profileSal, { ...item.bodySalarys, ...meta });
|
Object.assign(profileSal, { ...item.bodySalarys, ...meta });
|
||||||
const salaryHistory = new ProfileSalaryHistory();
|
const salaryHistory = new ProfileSalaryHistory();
|
||||||
Object.assign(salaryHistory, { ...profileSal, id: undefined });
|
Object.assign(salaryHistory, { ...profileSal, id: undefined });
|
||||||
|
|
@ -3788,7 +3798,9 @@ export class CommandController extends Controller {
|
||||||
if (
|
if (
|
||||||
orgRevision != null &&
|
orgRevision != null &&
|
||||||
!["REPORT", "DONE"].includes(
|
!["REPORT", "DONE"].includes(
|
||||||
orgRevision.posMasters.find((x) => x.statusReport === "REPORT" || x.statusReport === "DONE")?.statusReport || "",
|
orgRevision.posMasters.find(
|
||||||
|
(x) => x.statusReport === "REPORT" || x.statusReport === "DONE",
|
||||||
|
)?.statusReport || "",
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
await this.orgRevisionRepo.update(orgRevision.id, {
|
await this.orgRevisionRepo.update(orgRevision.id, {
|
||||||
|
|
|
||||||
|
|
@ -26,25 +26,85 @@ interface DPISResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DPISResult {
|
interface DPISResult {
|
||||||
|
/**
|
||||||
|
* เลขประจำตัวประชาชน
|
||||||
|
*/
|
||||||
citizenId: string;
|
citizenId: string;
|
||||||
|
/**
|
||||||
|
* คำนำหน้า
|
||||||
|
*/
|
||||||
prefix: string;
|
prefix: string;
|
||||||
|
/**
|
||||||
|
* ชื่อ
|
||||||
|
*/
|
||||||
firstName: string;
|
firstName: string;
|
||||||
|
/**
|
||||||
|
* นามสกุล
|
||||||
|
*/
|
||||||
lastName: string;
|
lastName: string;
|
||||||
|
/**
|
||||||
|
* เพศ
|
||||||
|
*/
|
||||||
gender: string;
|
gender: string;
|
||||||
|
/**
|
||||||
|
* สถานะ
|
||||||
|
*/
|
||||||
physicalStatus: string;
|
physicalStatus: string;
|
||||||
|
/**
|
||||||
|
* หน่วยงานคุณภาพ
|
||||||
|
*/
|
||||||
QualityWorkforce: boolean;
|
QualityWorkforce: boolean;
|
||||||
|
/**
|
||||||
|
* วันเกิด
|
||||||
|
*/
|
||||||
birthDate: DateTime;
|
birthDate: DateTime;
|
||||||
|
/**
|
||||||
|
* วันบรรจุ
|
||||||
|
*/
|
||||||
dateAppoint: DateTime;
|
dateAppoint: DateTime;
|
||||||
|
/**
|
||||||
|
* วันเริ่มปฏิบัติราชการ
|
||||||
|
*/
|
||||||
dateStart: DateTime;
|
dateStart: DateTime;
|
||||||
|
/**
|
||||||
|
* วันที่เกษียณอายุราชการ
|
||||||
|
*/
|
||||||
dateRetire: DateTime;
|
dateRetire: DateTime;
|
||||||
|
/**
|
||||||
|
* พ้นจากราชการหรือไม่?
|
||||||
|
*/
|
||||||
isLeave: boolean;
|
isLeave: boolean;
|
||||||
|
/**
|
||||||
|
* พ้นจากการทดลองปฏิบัติราชการหรือไม่?
|
||||||
|
*/
|
||||||
isProbation: boolean;
|
isProbation: boolean;
|
||||||
|
/**
|
||||||
|
* สาเหตุการพ้นจากราชการ
|
||||||
|
*/
|
||||||
leaveReason: string;
|
leaveReason: string;
|
||||||
|
/**
|
||||||
|
* ระดับ
|
||||||
|
*/
|
||||||
positionLevel: string;
|
positionLevel: string;
|
||||||
|
/**
|
||||||
|
* ประเภท
|
||||||
|
*/
|
||||||
positionType: string;
|
positionType: string;
|
||||||
|
/**
|
||||||
|
* ข้อมูลประวัติการศึกษา
|
||||||
|
*/
|
||||||
educations: ProfileEducationResult[];
|
educations: ProfileEducationResult[];
|
||||||
|
/**
|
||||||
|
* ข้อมูลการลา
|
||||||
|
*/
|
||||||
leaves: ProfileLeaveResult[];
|
leaves: ProfileLeaveResult[];
|
||||||
|
/**
|
||||||
|
* ข้อมูลเงินเดือน
|
||||||
|
*/
|
||||||
salaries: ProfileSalaryResult[];
|
salaries: ProfileSalaryResult[];
|
||||||
|
/**
|
||||||
|
* ข้อมูลหน่วยงาน
|
||||||
|
*/
|
||||||
organization: ProfileOrgResult;
|
organization: ProfileOrgResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ export class LoginController extends Controller {
|
||||||
let _data: any = null;
|
let _data: any = null;
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostDataKeycloak("/realms/bma-ehr/protocol/openid-connect/token", data)
|
.PostDataKeycloak(`/realms/${process.env.KC_REALM}/protocol/openid-connect/token`, data)
|
||||||
.then(async (x) => {
|
.then(async (x) => {
|
||||||
_data = x;
|
_data = x;
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6372,7 +6372,9 @@ export class OrganizationController extends Controller {
|
||||||
orgRoot.orgRootCode +
|
orgRoot.orgRootCode +
|
||||||
orgChild1.orgChild1Code +
|
orgChild1.orgChild1Code +
|
||||||
" " +
|
" " +
|
||||||
orgChild1.orgChild1ShortName,
|
orgChild1.orgChild1ShortName +
|
||||||
|
"/" +
|
||||||
|
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||||
totalPosition: await this.posMasterRepository.count({
|
totalPosition: await this.posMasterRepository.count({
|
||||||
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
|
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
|
||||||
}),
|
}),
|
||||||
|
|
@ -6487,7 +6489,16 @@ export class OrganizationController extends Controller {
|
||||||
orgRoot.orgRootCode +
|
orgRoot.orgRootCode +
|
||||||
orgChild2.orgChild2Code +
|
orgChild2.orgChild2Code +
|
||||||
" " +
|
" " +
|
||||||
orgChild2.orgChild2ShortName,
|
orgChild2.orgChild2ShortName +
|
||||||
|
"/" +
|
||||||
|
orgChild1.orgChild1Name +
|
||||||
|
" " +
|
||||||
|
orgRoot.orgRootCode +
|
||||||
|
orgChild1.orgChild1Code +
|
||||||
|
" " +
|
||||||
|
orgChild1.orgChild1ShortName +
|
||||||
|
"/" +
|
||||||
|
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||||
totalPosition: await this.posMasterRepository.count({
|
totalPosition: await this.posMasterRepository.count({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: orgRoot.orgRevisionId,
|
orgRevisionId: orgRoot.orgRevisionId,
|
||||||
|
|
@ -6599,13 +6610,29 @@ export class OrganizationController extends Controller {
|
||||||
orgRevisionId: orgRoot.orgRevisionId,
|
orgRevisionId: orgRoot.orgRevisionId,
|
||||||
orgRootName: orgRoot.orgRootName,
|
orgRootName: orgRoot.orgRootName,
|
||||||
responsibility: orgChild3.responsibility,
|
responsibility: orgChild3.responsibility,
|
||||||
labelName:
|
labelName:
|
||||||
orgChild3.orgChild3Name +
|
orgChild3.orgChild3Name +
|
||||||
" " +
|
" " +
|
||||||
orgRoot.orgRootCode +
|
orgRoot.orgRootCode +
|
||||||
orgChild3.orgChild3Code +
|
orgChild3.orgChild3Code +
|
||||||
" " +
|
" " +
|
||||||
orgChild3.orgChild3ShortName,
|
orgChild3.orgChild3ShortName +
|
||||||
|
"/" +
|
||||||
|
orgChild2.orgChild2Name +
|
||||||
|
" " +
|
||||||
|
orgRoot.orgRootCode +
|
||||||
|
orgChild2.orgChild2Code +
|
||||||
|
" " +
|
||||||
|
orgChild2.orgChild2ShortName +
|
||||||
|
"/" +
|
||||||
|
orgChild1.orgChild1Name +
|
||||||
|
" " +
|
||||||
|
orgRoot.orgRootCode +
|
||||||
|
orgChild1.orgChild1Code +
|
||||||
|
" " +
|
||||||
|
orgChild1.orgChild1ShortName +
|
||||||
|
"/" +
|
||||||
|
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||||
totalPosition: await this.posMasterRepository.count({
|
totalPosition: await this.posMasterRepository.count({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: orgRoot.orgRevisionId,
|
orgRevisionId: orgRoot.orgRevisionId,
|
||||||
|
|
@ -6723,7 +6750,30 @@ export class OrganizationController extends Controller {
|
||||||
orgRoot.orgRootCode +
|
orgRoot.orgRootCode +
|
||||||
orgChild4.orgChild4Code +
|
orgChild4.orgChild4Code +
|
||||||
" " +
|
" " +
|
||||||
orgChild4.orgChild4ShortName,
|
orgChild4.orgChild4ShortName +
|
||||||
|
"/" +
|
||||||
|
orgChild3.orgChild3Name +
|
||||||
|
" " +
|
||||||
|
orgRoot.orgRootCode +
|
||||||
|
orgChild3.orgChild3Code +
|
||||||
|
" " +
|
||||||
|
orgChild3.orgChild3ShortName +
|
||||||
|
"/" +
|
||||||
|
orgChild2.orgChild2Name +
|
||||||
|
" " +
|
||||||
|
orgRoot.orgRootCode +
|
||||||
|
orgChild2.orgChild2Code +
|
||||||
|
" " +
|
||||||
|
orgChild2.orgChild2ShortName +
|
||||||
|
"/" +
|
||||||
|
orgChild1.orgChild1Name +
|
||||||
|
" " +
|
||||||
|
orgRoot.orgRootCode +
|
||||||
|
orgChild1.orgChild1Code +
|
||||||
|
" " +
|
||||||
|
orgChild1.orgChild1ShortName +
|
||||||
|
"/" +
|
||||||
|
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||||
totalPosition: await this.posMasterRepository.count({
|
totalPosition: await this.posMasterRepository.count({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: orgRoot.orgRevisionId,
|
orgRevisionId: orgRoot.orgRevisionId,
|
||||||
|
|
|
||||||
|
|
@ -2619,6 +2619,266 @@ export class OrganizationDotnetController extends Controller {
|
||||||
return new HttpSuccess(profile_);
|
return new HttpSuccess(profile_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5. เอารายชื่อคนที่มีการ ,map keycloak id แล้ว
|
||||||
|
*
|
||||||
|
* @summary 5. เอารายชื่อคนที่มีการ ,map keycloak id แล้ว
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("keycloak-employee")
|
||||||
|
async GetProfileWithKeycloakEmployee() {
|
||||||
|
const profile = await this.profileEmpRepo.find({
|
||||||
|
where: { keycloak: Not(IsNull()) || Not("") },
|
||||||
|
relations: [
|
||||||
|
"posType",
|
||||||
|
"posLevel",
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
"profileSalary",
|
||||||
|
],
|
||||||
|
order: {
|
||||||
|
profileSalary: {
|
||||||
|
order: "DESC",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const findRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: { orgRevisionIsCurrent: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const profile_ = await Promise.all(
|
||||||
|
profile.map((item: ProfileEmployee) => {
|
||||||
|
const rootName =
|
||||||
|
item.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot
|
||||||
|
?.orgRootName;
|
||||||
|
const shortName =
|
||||||
|
item.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
|
||||||
|
null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild3 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild2 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild1 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgRoot != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
oc: rootName,
|
||||||
|
id: item.id,
|
||||||
|
createdAt: item.createdAt,
|
||||||
|
createdUserId: item.createdUserId,
|
||||||
|
lastUpdatedAt: item.lastUpdatedAt,
|
||||||
|
lastUpdateUserId: item.lastUpdateUserId,
|
||||||
|
createdFullName: item.createdFullName,
|
||||||
|
lastUpdateFullName: item.lastUpdateFullName,
|
||||||
|
avatar: item.avatar,
|
||||||
|
avatarName: item.avatarName,
|
||||||
|
rank: item.rank,
|
||||||
|
prefix: item.prefix,
|
||||||
|
firstName: item.firstName,
|
||||||
|
lastName: item.lastName,
|
||||||
|
citizenId: item.citizenId,
|
||||||
|
position: item.position,
|
||||||
|
posLevelId: item.posLevelId,
|
||||||
|
posTypeId: item.posTypeId,
|
||||||
|
email: item.email,
|
||||||
|
phone: item.phone,
|
||||||
|
keycloak: item.keycloak,
|
||||||
|
isProbation: item.isProbation,
|
||||||
|
isLeave: item.isLeave,
|
||||||
|
leaveReason: item.leaveReason,
|
||||||
|
dateLeave: item.dateLeave,
|
||||||
|
dateRetire: item.dateRetire,
|
||||||
|
dateAppoint: item.dateAppoint,
|
||||||
|
dateRetireLaw: item.dateRetireLaw,
|
||||||
|
dateStart: item.dateStart,
|
||||||
|
govAgeAbsent: item.govAgeAbsent,
|
||||||
|
govAgePlus: item.govAgePlus,
|
||||||
|
birthDate: item.birthDate ?? new Date(),
|
||||||
|
reasonSameDate: item.reasonSameDate,
|
||||||
|
ethnicity: item.ethnicity,
|
||||||
|
telephoneNumber: item.telephoneNumber,
|
||||||
|
nationality: item.nationality,
|
||||||
|
gender: item.gender,
|
||||||
|
relationship: item.relationship,
|
||||||
|
religion: item.religion,
|
||||||
|
bloodGroup: item.bloodGroup,
|
||||||
|
registrationAddress: item.registrationAddress,
|
||||||
|
registrationProvinceId: item.registrationProvinceId,
|
||||||
|
registrationDistrictId: item.registrationDistrictId,
|
||||||
|
registrationSubDistrictId: item.registrationSubDistrictId,
|
||||||
|
registrationZipCode: item.registrationZipCode,
|
||||||
|
currentAddress: item.currentAddress,
|
||||||
|
currentProvinceId: item.currentProvinceId,
|
||||||
|
currentDistrictId: item.currentDistrictId,
|
||||||
|
currentSubDistrictId: item.currentSubDistrictId,
|
||||||
|
currentZipCode: item.currentZipCode,
|
||||||
|
dutyTimeId: item.dutyTimeId,
|
||||||
|
dutyTimeEffectiveDate: item.dutyTimeEffectiveDate,
|
||||||
|
positionLevel: item.profileSalary.length > 0 ? item.profileSalary[0].positionLevel : null,
|
||||||
|
posNo: shortName,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return new HttpSuccess(profile_);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5. เอารายชื่อคนที่มีการ ,map keycloak id แล้ว
|
||||||
|
*
|
||||||
|
* @summary 5. เอารายชื่อคนที่มีการ ,map keycloak id แล้ว
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("keycloak-all-officer")
|
||||||
|
async GetProfileWithKeycloakAllOfficer() {
|
||||||
|
const profile = await this.profileRepo.find({
|
||||||
|
where: { keycloak: Not(IsNull()) || Not(""), isLeave: false },
|
||||||
|
relations: [
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const findRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: { orgRevisionIsCurrent: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const profile_ = await Promise.all(
|
||||||
|
profile.map((item: Profile) => {
|
||||||
|
const shortName =
|
||||||
|
item.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
|
||||||
|
null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild3 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild2 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild1 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgRoot != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: item.id,
|
||||||
|
prefix: item.prefix,
|
||||||
|
firstName: item.firstName,
|
||||||
|
lastName: item.lastName,
|
||||||
|
keycloak: item.keycloak,
|
||||||
|
posNo: shortName,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return new HttpSuccess(profile_);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5. เอารายชื่อคนที่มีการ ,map keycloak id แล้ว
|
||||||
|
*
|
||||||
|
* @summary 5. เอารายชื่อคนที่มีการ ,map keycloak id แล้ว
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("keycloak-all-employee")
|
||||||
|
async GetProfileWithKeycloakAllEmployee() {
|
||||||
|
const profile = await this.profileEmpRepo.find({
|
||||||
|
where: { keycloak: Not(IsNull()) || Not(""), isLeave: false },
|
||||||
|
relations: [
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const findRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: { orgRevisionIsCurrent: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const profile_ = await Promise.all(
|
||||||
|
profile.map((item: ProfileEmployee) => {
|
||||||
|
const shortName =
|
||||||
|
item.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
|
||||||
|
null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild3 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild2 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild1 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgRoot != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: item.id,
|
||||||
|
prefix: item.prefix,
|
||||||
|
firstName: item.firstName,
|
||||||
|
lastName: item.lastName,
|
||||||
|
citizenId: item.citizenId,
|
||||||
|
keycloak: item.keycloak,
|
||||||
|
posNo: shortName,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return new HttpSuccess(profile_);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 4. API Update รอบการลงเวลา ในตาราง profile
|
* 4. API Update รอบการลงเวลา ในตาราง profile
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -4953,6 +4953,7 @@ export class PositionController extends Controller {
|
||||||
(masterId.length > 0
|
(masterId.length > 0
|
||||||
? { id: In(masterId) }
|
? { id: In(masterId) }
|
||||||
: { posMasterNo: Like(`%${body.keyword}%`) })),
|
: { posMasterNo: Like(`%${body.keyword}%`) })),
|
||||||
|
current_holderId: IsNull(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
let [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
let [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||||
|
|
@ -4962,66 +4963,136 @@ export class PositionController extends Controller {
|
||||||
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
|
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
|
||||||
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
|
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
|
||||||
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
||||||
|
.leftJoinAndSelect("posMaster.orgRevision", "orgRevision")
|
||||||
|
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||||
|
.leftJoinAndSelect("current_holder.posType", "posType")
|
||||||
|
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
|
||||||
.where(conditions)
|
.where(conditions)
|
||||||
.andWhere({
|
.orWhere(
|
||||||
current_holderId: IsNull(),
|
new Brackets((qb) => {
|
||||||
})
|
qb.andWhere(
|
||||||
.andWhere(
|
_data.root != undefined && _data.root != null
|
||||||
_data.root != undefined && _data.root != null
|
? _data.root[0] != null
|
||||||
? _data.root[0] != null
|
? `posMaster.orgRootId IN (:...root)`
|
||||||
? `posMaster.orgRootId IN (:...root)`
|
: `posMaster.orgRootId is null`
|
||||||
: `posMaster.orgRootId is null`
|
: "1=1",
|
||||||
: "1=1",
|
{
|
||||||
{
|
root: _data.root,
|
||||||
root: _data.root,
|
},
|
||||||
},
|
)
|
||||||
|
.andWhere(conditions)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.andWhere(
|
.orWhere(
|
||||||
_data.child1 != undefined && _data.child1 != null
|
new Brackets((qb) => {
|
||||||
? _data.child1[0] != null
|
qb.andWhere(
|
||||||
? `posMaster.orgChild1Id IN (:...child1)`
|
_data.child1 != undefined && _data.child1 != null
|
||||||
: `posMaster.orgChild1Id is null`
|
? _data.child1[0] != null
|
||||||
: "1=1",
|
? `posMaster.orgChild1Id IN (:...child1)`
|
||||||
{
|
: `posMaster.orgChild1Id is null`
|
||||||
child1: _data.child1,
|
: "1=1",
|
||||||
},
|
{
|
||||||
|
child1: _data.child1,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(conditions)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.andWhere(
|
.orWhere(
|
||||||
_data.child2 != undefined && _data.child2 != null
|
new Brackets((qb) => {
|
||||||
? _data.child2[0] != null
|
qb.andWhere(
|
||||||
? `posMaster.orgChild2Id IN (:...child2)`
|
_data.child2 != undefined && _data.child2 != null
|
||||||
: `posMaster.orgChild2Id is null`
|
? _data.child2[0] != null
|
||||||
: "1=1",
|
? `posMaster.orgChild2Id IN (:...child2)`
|
||||||
{
|
: `posMaster.orgChild2Id is null`
|
||||||
child2: _data.child2,
|
: "1=1",
|
||||||
},
|
{
|
||||||
|
child2: _data.child2,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(conditions)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.andWhere(
|
.orWhere(
|
||||||
_data.child3 != undefined && _data.child3 != null
|
new Brackets((qb) => {
|
||||||
? _data.child3[0] != null
|
qb.andWhere(
|
||||||
? `posMaster.orgChild3Id IN (:...child3)`
|
_data.child3 != undefined && _data.child3 != null
|
||||||
: `posMaster.orgChild3Id is null`
|
? _data.child3[0] != null
|
||||||
: "1=1",
|
? `posMaster.orgChild3Id IN (:...child3)`
|
||||||
{
|
: `posMaster.orgChild3Id is null`
|
||||||
child3: _data.child3,
|
: "1=1",
|
||||||
},
|
{
|
||||||
|
child3: _data.child3,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(conditions)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.andWhere(
|
.orWhere(
|
||||||
_data.child4 != undefined && _data.child4 != null
|
new Brackets((qb) => {
|
||||||
? _data.child4[0] != null
|
qb.andWhere(
|
||||||
? `posMaster.orgChild4Id IN (:...child4)`
|
_data.child4 != undefined && _data.child4 != null
|
||||||
: `posMaster.orgChild4Id is null`
|
? _data.child4[0] != null
|
||||||
: "1=1",
|
? `posMaster.orgChild4Id IN (:...child4)`
|
||||||
{
|
: `posMaster.orgChild4Id is null`
|
||||||
child4: _data.child4,
|
: "1=1",
|
||||||
},
|
{
|
||||||
|
child4: _data.child4,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(conditions)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.andWhere(
|
.orWhere(
|
||||||
body.keyword != null && body.keyword != ""
|
new Brackets((qb) => {
|
||||||
? body.isAll == false
|
qb.andWhere(
|
||||||
? searchShortName
|
body.keyword != null && body.keyword != ""
|
||||||
: `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'`
|
? `current_holder.posType LIKE :keyword`
|
||||||
: "1=1",
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${body.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(conditions)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.andWhere(
|
||||||
|
body.keyword != null && body.keyword != ""
|
||||||
|
? `current_holder.posLevel LIKE :keyword`
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${body.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(conditions)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.andWhere(
|
||||||
|
body.keyword != null && body.keyword != ""
|
||||||
|
? `current_holder.position LIKE :keyword`
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${body.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(conditions)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.andWhere(
|
||||||
|
body.keyword != null && body.keyword != ""
|
||||||
|
? body.isAll == false
|
||||||
|
? searchShortName
|
||||||
|
: `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'`
|
||||||
|
: "1=1",
|
||||||
|
)
|
||||||
|
.andWhere(conditions)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.orderBy("posMaster.posMasterOrder", "ASC")
|
.orderBy("posMaster.posMasterOrder", "ASC")
|
||||||
.skip((body.page - 1) * body.pageSize)
|
.skip((body.page - 1) * body.pageSize)
|
||||||
|
|
|
||||||
|
|
@ -278,7 +278,7 @@ export class ProfileController extends Controller {
|
||||||
: "-",
|
: "-",
|
||||||
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
|
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
|
||||||
educations: Education,
|
educations: Education,
|
||||||
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
|
url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
|
||||||
};
|
};
|
||||||
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
|
|
@ -715,7 +715,7 @@ export class ProfileController extends Controller {
|
||||||
: "",
|
: "",
|
||||||
telephone:
|
telephone:
|
||||||
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
|
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
|
||||||
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
|
url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
|
||||||
url1: _ImgUrl[0] ? _ImgUrl[0] : null,
|
url1: _ImgUrl[0] ? _ImgUrl[0] : null,
|
||||||
yearUpload1: profiles.profileAvatars[0]
|
yearUpload1: profiles.profileAvatars[0]
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))
|
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))
|
||||||
|
|
@ -1426,11 +1426,11 @@ export class ProfileController extends Controller {
|
||||||
)
|
)
|
||||||
.orWhere(
|
.orWhere(
|
||||||
body.keyword != null && body.keyword != ""
|
body.keyword != null && body.keyword != ""
|
||||||
? "CONCAT(viewDirectorActing.posType, ' (', viewDirectorActing.posLevel, ')') LIKE :keyword"
|
? "CONCAT(viewDirectorActing.posType, ' (', viewDirectorActing.posLevel, ')') LIKE :keyword"
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
keyword: `%${body.keyword}%`,
|
keyword: `%${body.keyword}%`,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.orWhere(
|
.orWhere(
|
||||||
body.keyword != null && body.keyword != ""
|
body.keyword != null && body.keyword != ""
|
||||||
|
|
@ -1511,11 +1511,11 @@ export class ProfileController extends Controller {
|
||||||
// )
|
// )
|
||||||
.orWhere(
|
.orWhere(
|
||||||
body.keyword != null && body.keyword != ""
|
body.keyword != null && body.keyword != ""
|
||||||
? "CONCAT(viewDirector.posType, ' (', viewDirector.posLevel, ')') LIKE :keyword"
|
? "CONCAT(viewDirector.posType, ' (', viewDirector.posLevel, ')') LIKE :keyword"
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
keyword: `%${body.keyword}%`,
|
keyword: `%${body.keyword}%`,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.orWhere(
|
.orWhere(
|
||||||
body.keyword != null && body.keyword != ""
|
body.keyword != null && body.keyword != ""
|
||||||
|
|
@ -1839,7 +1839,7 @@ export class ProfileController extends Controller {
|
||||||
|
|
||||||
const profile = Object.assign(new Profile(), body);
|
const profile = Object.assign(new Profile(), body);
|
||||||
profile.prefixMain = profile.prefix;
|
profile.prefixMain = profile.prefix;
|
||||||
profile.prefix = profile.rank && profile.rank.length > 0?profile.rank:profile.prefixMain;
|
profile.prefix = profile.rank && profile.rank.length > 0 ? profile.rank : profile.prefixMain;
|
||||||
profile.isProbation = false;
|
profile.isProbation = false;
|
||||||
profile.isLeave = false;
|
profile.isLeave = false;
|
||||||
profile.createdUserId = request.user.sub;
|
profile.createdUserId = request.user.sub;
|
||||||
|
|
@ -1912,7 +1912,7 @@ export class ProfileController extends Controller {
|
||||||
const profile: Profile = Object.assign(new Profile(), body);
|
const profile: Profile = Object.assign(new Profile(), body);
|
||||||
const _null: any = null;
|
const _null: any = null;
|
||||||
profile.prefixMain = profile.prefix;
|
profile.prefixMain = profile.prefix;
|
||||||
profile.prefix = profile.rank && profile.rank.length > 0?profile.rank:profile.prefixMain;
|
profile.prefix = profile.rank && profile.rank.length > 0 ? profile.rank : profile.prefixMain;
|
||||||
profile.dateRetire = body.birthDate == null ? _null : calculateRetireDate(body.birthDate);
|
profile.dateRetire = body.birthDate == null ? _null : calculateRetireDate(body.birthDate);
|
||||||
profile.dateRetireLaw = body.birthDate == null ? _null : calculateRetireLaw(body.birthDate);
|
profile.dateRetireLaw = body.birthDate == null ? _null : calculateRetireLaw(body.birthDate);
|
||||||
profile.createdUserId = request.user.sub;
|
profile.createdUserId = request.user.sub;
|
||||||
|
|
@ -1981,7 +1981,7 @@ export class ProfileController extends Controller {
|
||||||
}
|
}
|
||||||
const profile: Profile = Object.assign(new Profile(), body);
|
const profile: Profile = Object.assign(new Profile(), body);
|
||||||
profile.prefixMain = profile.prefix;
|
profile.prefixMain = profile.prefix;
|
||||||
profile.prefix = profile.rank && profile.rank.length > 0?profile.rank:profile.prefixMain;
|
profile.prefix = profile.rank && profile.rank.length > 0 ? profile.rank : profile.prefixMain;
|
||||||
profile.createdUserId = request.user.sub;
|
profile.createdUserId = request.user.sub;
|
||||||
profile.createdFullName = request.user.name;
|
profile.createdFullName = request.user.name;
|
||||||
profile.lastUpdateUserId = request.user.sub;
|
profile.lastUpdateUserId = request.user.sub;
|
||||||
|
|
@ -3553,7 +3553,7 @@ export class ProfileController extends Controller {
|
||||||
|
|
||||||
Object.assign(record, body);
|
Object.assign(record, body);
|
||||||
record.prefixMain = record.prefix;
|
record.prefixMain = record.prefix;
|
||||||
record.prefix = record.rank && record.rank.length > 0?record.rank:record.prefixMain;
|
record.prefix = record.rank && record.rank.length > 0 ? record.rank : record.prefixMain;
|
||||||
record.createdUserId = request.user.sub;
|
record.createdUserId = request.user.sub;
|
||||||
record.createdFullName = request.user.name;
|
record.createdFullName = request.user.name;
|
||||||
record.createdAt = new Date();
|
record.createdAt = new Date();
|
||||||
|
|
@ -3804,7 +3804,7 @@ export class ProfileController extends Controller {
|
||||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||||
.where("current_holders.orgRevisionId = :orgRevisionId", {orgRevisionId: findRevision.id})
|
.where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: findRevision.id })
|
||||||
.andWhere(
|
.andWhere(
|
||||||
posType != undefined && posType != null && posType != ""
|
posType != undefined && posType != null && posType != ""
|
||||||
? "posType.posTypeName LIKE :keyword1"
|
? "posType.posTypeName LIKE :keyword1"
|
||||||
|
|
@ -4156,7 +4156,7 @@ export class ProfileController extends Controller {
|
||||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||||
.where("current_holders.orgRevisionId = :orgRevisionId", {orgRevisionId: findRevision.id})
|
.where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: findRevision.id })
|
||||||
.andWhere(
|
.andWhere(
|
||||||
_data.root != undefined && _data.root != null
|
_data.root != undefined && _data.root != null
|
||||||
? _data.root[0] != null
|
? _data.root[0] != null
|
||||||
|
|
@ -4236,20 +4236,20 @@ export class ProfileController extends Controller {
|
||||||
: "1=1",
|
: "1=1",
|
||||||
)
|
)
|
||||||
.andWhere(nodeCondition, {
|
.andWhere(nodeCondition, {
|
||||||
nodeId: nodeId,
|
nodeId: nodeId,
|
||||||
})
|
})
|
||||||
|
|
||||||
.andWhere(
|
.andWhere(
|
||||||
new Brackets((qb) => {
|
new Brackets((qb) => {
|
||||||
qb.orWhere(
|
qb.orWhere(
|
||||||
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
|
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
|
||||||
? queryLike
|
? queryLike
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
keyword: `%${searchKeyword}%`,
|
keyword: `%${searchKeyword}%`,
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
})
|
}),
|
||||||
)
|
)
|
||||||
.orderBy("current_holders.posMasterNo", "ASC")
|
.orderBy("current_holders.posMasterNo", "ASC")
|
||||||
.skip((page - 1) * pageSize)
|
.skip((page - 1) * pageSize)
|
||||||
|
|
@ -6004,7 +6004,7 @@ export class ProfileController extends Controller {
|
||||||
) {
|
) {
|
||||||
let findProfile: any;
|
let findProfile: any;
|
||||||
let total: any;
|
let total: any;
|
||||||
let revision = await this.orgRevisionRepo.findOne({where: { orgRevisionIsCurrent: true }});
|
let revision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } });
|
||||||
const skip = (page - 1) * pageSize;
|
const skip = (page - 1) * pageSize;
|
||||||
const take = pageSize;
|
const take = pageSize;
|
||||||
let queryLike = `CONCAT(
|
let queryLike = `CONCAT(
|
||||||
|
|
@ -6023,15 +6023,15 @@ export class ProfileController extends Controller {
|
||||||
IFNULL(orgRoot.orgRootShortName, ''),
|
IFNULL(orgRoot.orgRootShortName, ''),
|
||||||
IFNULL(current_holders.posMasterNo , '')
|
IFNULL(current_holders.posMasterNo , '')
|
||||||
) LIKE :keyword`;
|
) LIKE :keyword`;
|
||||||
|
|
||||||
switch (body.fieldName) {
|
switch (body.fieldName) {
|
||||||
case "citizenId":
|
case "citizenId":
|
||||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||||
where: {
|
where: {
|
||||||
citizenId: Like(`%${body.keyword}%`),
|
citizenId: Like(`%${body.keyword}%`),
|
||||||
current_holders:{
|
current_holders: {
|
||||||
orgRevisionId:revision?.id
|
orgRevisionId: revision?.id,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
relations: [
|
relations: [
|
||||||
"posType",
|
"posType",
|
||||||
|
|
@ -6050,29 +6050,33 @@ export class ProfileController extends Controller {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "fullName":
|
case "fullName":
|
||||||
[findProfile, total] = await this.profileRepo.createQueryBuilder("profile")
|
[findProfile, total] = await this.profileRepo
|
||||||
.leftJoinAndSelect("profile.posType", "posType")
|
.createQueryBuilder("profile")
|
||||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
.leftJoinAndSelect("profile.posType", "posType")
|
||||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||||
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||||
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
||||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||||
.where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id })
|
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||||
.andWhere("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` })
|
.where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id })
|
||||||
.skip(skip)
|
.andWhere(
|
||||||
.take(take)
|
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword",
|
||||||
.getManyAndCount();
|
{ keyword: `%${body.keyword}%` },
|
||||||
|
)
|
||||||
|
.skip(skip)
|
||||||
|
.take(take)
|
||||||
|
.getManyAndCount();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "position":
|
case "position":
|
||||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||||
where: {
|
where: {
|
||||||
position: Like(`%${body.keyword}%`),
|
position: Like(`%${body.keyword}%`),
|
||||||
current_holders:{
|
current_holders: {
|
||||||
orgRevisionId:revision?.id
|
orgRevisionId: revision?.id,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
relations: [
|
relations: [
|
||||||
"posType",
|
"posType",
|
||||||
|
|
@ -6091,7 +6095,8 @@ export class ProfileController extends Controller {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "posNo":
|
case "posNo":
|
||||||
[findProfile, total] = await this.profileRepo.createQueryBuilder("profile")
|
[findProfile, total] = await this.profileRepo
|
||||||
|
.createQueryBuilder("profile")
|
||||||
.leftJoinAndSelect("profile.posType", "posType")
|
.leftJoinAndSelect("profile.posType", "posType")
|
||||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||||
|
|
@ -6103,13 +6108,15 @@ export class ProfileController extends Controller {
|
||||||
.where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id })
|
.where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id })
|
||||||
.andWhere(
|
.andWhere(
|
||||||
new Brackets((qb) => {
|
new Brackets((qb) => {
|
||||||
qb.orWhere(body.keyword != undefined && body.keyword != null && body.keyword != ""
|
qb.orWhere(
|
||||||
? queryLike
|
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||||
: "1=1",
|
? queryLike
|
||||||
{
|
: "1=1",
|
||||||
keyword: `%${body.keyword}%`,
|
{
|
||||||
})
|
keyword: `%${body.keyword}%`,
|
||||||
})
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.skip(skip)
|
.skip(skip)
|
||||||
.take(take)
|
.take(take)
|
||||||
|
|
@ -6118,13 +6125,13 @@ export class ProfileController extends Controller {
|
||||||
|
|
||||||
case "posType":
|
case "posType":
|
||||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||||
where: {
|
where: {
|
||||||
posType: {
|
posType: {
|
||||||
posTypeName:Like(`%${body.keyword}%`)
|
posTypeName: Like(`%${body.keyword}%`),
|
||||||
|
},
|
||||||
|
current_holders: {
|
||||||
|
orgRevisionId: revision?.id,
|
||||||
},
|
},
|
||||||
current_holders:{
|
|
||||||
orgRevisionId:revision?.id
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
relations: [
|
relations: [
|
||||||
"posType",
|
"posType",
|
||||||
|
|
@ -6144,13 +6151,13 @@ export class ProfileController extends Controller {
|
||||||
|
|
||||||
case "posLevel":
|
case "posLevel":
|
||||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||||
where: {
|
where: {
|
||||||
posLevel: {
|
posLevel: {
|
||||||
posLevelName:Like(`%${body.keyword}%`)
|
posLevelName: Like(`%${body.keyword}%`),
|
||||||
|
},
|
||||||
|
current_holders: {
|
||||||
|
orgRevisionId: revision?.id,
|
||||||
},
|
},
|
||||||
current_holders:{
|
|
||||||
orgRevisionId:revision?.id
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
relations: [
|
relations: [
|
||||||
"posType",
|
"posType",
|
||||||
|
|
@ -6170,13 +6177,14 @@ export class ProfileController extends Controller {
|
||||||
|
|
||||||
case "organization":
|
case "organization":
|
||||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||||
where: {
|
where: {
|
||||||
current_holders:{
|
current_holders: {
|
||||||
orgRevisionId:revision?.id,
|
orgRevisionId: revision?.id,
|
||||||
orgRoot:{
|
orgRoot: {
|
||||||
orgRootName:Like(`%${body.keyword}%`)
|
orgRootName: Like(`%${body.keyword}%`),
|
||||||
}
|
},
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
relations: [
|
relations: [
|
||||||
"posType",
|
"posType",
|
||||||
"posLevel",
|
"posLevel",
|
||||||
|
|
@ -6192,13 +6200,13 @@ export class ProfileController extends Controller {
|
||||||
take,
|
take,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||||
where:{
|
where: {
|
||||||
current_holders:{
|
current_holders: {
|
||||||
orgRevisionId:revision?.id
|
orgRevisionId: revision?.id,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
relations: [
|
relations: [
|
||||||
"posType",
|
"posType",
|
||||||
|
|
@ -7251,7 +7259,7 @@ export class ProfileController extends Controller {
|
||||||
// item.current_holder == null || item.current_holder.profileSalary.length == 0
|
// item.current_holder == null || item.current_holder.profileSalary.length == 0
|
||||||
// ? null
|
// ? null
|
||||||
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
|
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
|
||||||
const amount = item.current_holder?item.current_holder.amount:null;
|
const amount = item.current_holder ? item.current_holder.amount : null;
|
||||||
let datePeriodStart = new Date(
|
let datePeriodStart = new Date(
|
||||||
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
|
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
|
||||||
);
|
);
|
||||||
|
|
@ -8061,7 +8069,7 @@ export class ProfileController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
profile.prefixMain = profile.prefix;
|
profile.prefixMain = profile.prefix;
|
||||||
profile.prefix = profile.rank && profile.rank.length > 0?profile.rank:profile.prefixMain;
|
profile.prefix = profile.rank && profile.rank.length > 0 ? profile.rank : profile.prefixMain;
|
||||||
profile.createdUserId = request.user.sub;
|
profile.createdUserId = request.user.sub;
|
||||||
profile.createdFullName = request.user.name;
|
profile.createdFullName = request.user.name;
|
||||||
profile.lastUpdateUserId = request.user.sub;
|
profile.lastUpdateUserId = request.user.sub;
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
: "-",
|
: "-",
|
||||||
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
|
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
|
||||||
educations: Education,
|
educations: Education,
|
||||||
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
|
url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
|
||||||
};
|
};
|
||||||
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
|
|
@ -722,7 +722,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
: "",
|
: "",
|
||||||
telephone:
|
telephone:
|
||||||
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
|
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
|
||||||
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
|
url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
|
||||||
url1: _ImgUrl[0] ? _ImgUrl[0] : null,
|
url1: _ImgUrl[0] ? _ImgUrl[0] : null,
|
||||||
yearUpload1: profiles.profileAvatars[0]
|
yearUpload1: profiles.profileAvatars[0]
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))
|
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))
|
||||||
|
|
@ -830,7 +830,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
|
|
||||||
const profile = Object.assign(new ProfileEmployee(), body);
|
const profile = Object.assign(new ProfileEmployee(), body);
|
||||||
profile.prefixMain = profile.prefix;
|
profile.prefixMain = profile.prefix;
|
||||||
profile.prefix = profile.rank && profile.rank.length > 0?profile.rank:profile.prefixMain;
|
profile.prefix = profile.rank && profile.rank.length > 0 ? profile.rank : profile.prefixMain;
|
||||||
profile.createdUserId = request.user.sub;
|
profile.createdUserId = request.user.sub;
|
||||||
profile.createdFullName = request.user.name;
|
profile.createdFullName = request.user.name;
|
||||||
profile.lastUpdateUserId = request.user.sub;
|
profile.lastUpdateUserId = request.user.sub;
|
||||||
|
|
@ -927,7 +927,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
|
|
||||||
Object.assign(record, body);
|
Object.assign(record, body);
|
||||||
record.prefixMain = record.prefix;
|
record.prefixMain = record.prefix;
|
||||||
record.prefix = record.rank && record.rank.length > 0?record.rank:record.prefixMain;
|
record.prefix = record.rank && record.rank.length > 0 ? record.rank : record.prefixMain;
|
||||||
record.createdUserId = request.user.sub;
|
record.createdUserId = request.user.sub;
|
||||||
record.createdFullName = request.user.name;
|
record.createdFullName = request.user.name;
|
||||||
record.createdAt = new Date();
|
record.createdAt = new Date();
|
||||||
|
|
@ -2954,7 +2954,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
// item.current_holder == null || item.current_holder.profileSalary.length == 0
|
// item.current_holder == null || item.current_holder.profileSalary.length == 0
|
||||||
// ? null
|
// ? null
|
||||||
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
|
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
|
||||||
const amount = item.current_holder?item.current_holder.amount:null;
|
const amount = item.current_holder ? item.current_holder.amount : null;
|
||||||
let datePeriodStart = new Date(
|
let datePeriodStart = new Date(
|
||||||
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
|
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ export class ProfileEmployeeTempController extends Controller {
|
||||||
: "-",
|
: "-",
|
||||||
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
|
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
|
||||||
educations: Education,
|
educations: Education,
|
||||||
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
|
url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
|
||||||
};
|
};
|
||||||
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
|
|
@ -719,7 +719,7 @@ export class ProfileEmployeeTempController extends Controller {
|
||||||
: "",
|
: "",
|
||||||
telephone:
|
telephone:
|
||||||
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
|
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
|
||||||
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
|
url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
|
||||||
url1: _ImgUrl[0] ? _ImgUrl[0] : null,
|
url1: _ImgUrl[0] ? _ImgUrl[0] : null,
|
||||||
yearUpload1: profiles.profileAvatars[0]
|
yearUpload1: profiles.profileAvatars[0]
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))
|
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))
|
||||||
|
|
@ -2703,7 +2703,7 @@ export class ProfileEmployeeTempController extends Controller {
|
||||||
// item.current_holder == null || item.current_holder.profileSalary.length == 0
|
// item.current_holder == null || item.current_holder.profileSalary.length == 0
|
||||||
// ? null
|
// ? null
|
||||||
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
|
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
|
||||||
const amount = item.current_holder?item.current_holder.amount:null;
|
const amount = item.current_holder ? item.current_holder.amount : null;
|
||||||
let datePeriodStart = new Date(
|
let datePeriodStart = new Date(
|
||||||
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
|
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Controller, Get, Route, Security, Tags, SuccessResponse, Response, Path } from "tsoa";
|
import { Controller, Get, Route, Security, Tags, SuccessResponse, Response, Path, Query } from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
|
@ -17,6 +17,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||||
import Extension from "../interfaces/extension";
|
import Extension from "../interfaces/extension";
|
||||||
import { LeaveType } from "../entities/LeaveType";
|
import { LeaveType } from "../entities/LeaveType";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import { Profile } from "../entities/Profile";
|
||||||
@Route("api/v1/org/report")
|
@Route("api/v1/org/report")
|
||||||
@Tags("Report")
|
@Tags("Report")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -34,7 +35,207 @@ export class ReportController extends Controller {
|
||||||
private posTypepository = AppDataSource.getRepository(PosType);
|
private posTypepository = AppDataSource.getRepository(PosType);
|
||||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||||
|
private profileRepository = AppDataSource.getRepository(Profile);
|
||||||
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
|
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
|
||||||
|
/**
|
||||||
|
* API รายงานสถิติข้อมูลข้าราชการ กทม. สามัญ
|
||||||
|
*
|
||||||
|
* @summary รายงานสถิติข้อมูลข้าราชการ กทม. สามัญ
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("registry-officer")
|
||||||
|
async registryOfficer(
|
||||||
|
@Query() rootId: string,
|
||||||
|
@Query() year?: number,
|
||||||
|
@Query() ageMin?: number,
|
||||||
|
@Query() ageMax?: number,
|
||||||
|
) {
|
||||||
|
if (ageMin && (ageMin < 20 || ageMin > 80)) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ageMin must be between 20 and 80");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ageMax && (ageMax < 20 || ageMax > 80)) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ageMax must be between 20 and 80");
|
||||||
|
}
|
||||||
|
|
||||||
|
const minAge = ageMin ?? 20;
|
||||||
|
const maxAge = ageMax ?? 80;
|
||||||
|
|
||||||
|
if (minAge > maxAge) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax");
|
||||||
|
}
|
||||||
|
const yearInAD = year?year - 543:null;
|
||||||
|
const currentRevision = await this.orgRevisionRepository.findOne({
|
||||||
|
where:{
|
||||||
|
orgRevisionIsCurrent: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const rawdataProfile = await this.posMasterRepository
|
||||||
|
.createQueryBuilder('posMaster')
|
||||||
|
.leftJoinAndSelect('posMaster.current_holder', 'current_holder')
|
||||||
|
.leftJoinAndSelect('posMaster.positions', 'positions')
|
||||||
|
.leftJoinAndSelect('posMaster.orgRoot', 'orgRoot')
|
||||||
|
.leftJoinAndSelect('positions.posExecutive', 'posExecutive')
|
||||||
|
.leftJoinAndSelect('current_holder.posType', 'posType')
|
||||||
|
.leftJoinAndSelect('current_holder.posLevel', 'posLevel')
|
||||||
|
.leftJoinAndSelect('current_holder.profileEducations', 'profileEducations')
|
||||||
|
.where('posMaster.orgRevisionId = :currentRevisionId', { currentRevisionId: currentRevision?.id })
|
||||||
|
.andWhere('posMaster.orgRootId = :rootId', { rootId })
|
||||||
|
.andWhere('posMaster.current_holderId Is Not Null')
|
||||||
|
.andWhere('positions.positionIsSelected = :positionIsSelected', { positionIsSelected: true })
|
||||||
|
.andWhere( yearInAD && yearInAD != null? 'YEAR(current_holder.dateAppoint) = :year': "1=1", { year: yearInAD })
|
||||||
|
.andWhere(`
|
||||||
|
TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) >= :minAge
|
||||||
|
AND TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) <= :maxAge
|
||||||
|
`, { minAge, maxAge })
|
||||||
|
.orderBy("posType.posTypeaName","ASC")
|
||||||
|
.getMany();
|
||||||
|
if(!rawdataProfile){
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||||
|
}
|
||||||
|
const mapData = rawdataProfile
|
||||||
|
.map((x) => {
|
||||||
|
const latestEducation = x.current_holder.profileEducations.sort((a:any, b:any) => b.endDate - a.startDate)[0];
|
||||||
|
return {
|
||||||
|
name: x.current_holder.firstName + " " + x.current_holder.lastName,
|
||||||
|
affiliation: x.orgRoot.orgRootName,
|
||||||
|
gender: x.current_holder.gender,
|
||||||
|
positionName: x.positions[0]?x.positions[0].positionName:"-",
|
||||||
|
status: x.current_holder.relationship,
|
||||||
|
posType: x.current_holder.posType.posTypeName,
|
||||||
|
posLevel: x.current_holder.posLevel.posLevelName,
|
||||||
|
degree: latestEducation ? latestEducation.educationLevel : "-",
|
||||||
|
posExecutive: x.positions[0].posExecutive?x.positions[0].posExecutive.posExecutiveName:"-",
|
||||||
|
currentPreiodPos: "-",
|
||||||
|
levelPeriodPos: "-",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const groupedData = mapData.reduce((acc:any, item) => {
|
||||||
|
const key = `${item.posType} - ${item.affiliation} - ${item.gender} - ${item.degree || 'ไม่พบข้อมูล'} - ${item.status || 'ไม่พบข้อมูล'} - ${item.positionName} - ${item.posLevel} - ${item.posExecutive || 'ไม่พบข้อมูล'} `;
|
||||||
|
if (!acc[key]) {
|
||||||
|
acc[key] = {
|
||||||
|
posType: item.posType,
|
||||||
|
affiliation: item.affiliation,
|
||||||
|
gender: item.gender,
|
||||||
|
degree: item.degree,
|
||||||
|
status: item.status,
|
||||||
|
positionName: item.positionName,
|
||||||
|
posLevel: item.posLevel,
|
||||||
|
posExecutive: item.posExecutive,
|
||||||
|
currentPreiodPos: "-",
|
||||||
|
levelPeriodPos: "-",
|
||||||
|
count: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
acc[key].count++;
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return new HttpSuccess({
|
||||||
|
template: "registry-officer",
|
||||||
|
reportName: "xlsx-report",
|
||||||
|
data: groupedData,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* API รายงานสถิติข้อมูลลูกจ้างประจำ กทม.
|
||||||
|
*
|
||||||
|
* @summary รายงานสถิติข้อมูลลูกจ้างประจำ กทม.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("registry-emp")
|
||||||
|
async registryEmp(
|
||||||
|
@Query() rootId: string,
|
||||||
|
@Query() year?: number,
|
||||||
|
@Query() ageMin?: number,
|
||||||
|
@Query() ageMax?: number,
|
||||||
|
) {
|
||||||
|
if (ageMin && (ageMin < 20 || ageMin > 80)) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ageMin must be between 20 and 80");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ageMax && (ageMax < 20 || ageMax > 80)) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ageMax must be between 20 and 80");
|
||||||
|
}
|
||||||
|
|
||||||
|
const minAge = ageMin ?? 20;
|
||||||
|
const maxAge = ageMax ?? 80;
|
||||||
|
|
||||||
|
if (minAge > maxAge) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax");
|
||||||
|
}
|
||||||
|
const yearInAD = year?year - 543:null;
|
||||||
|
const currentRevision = await this.orgRevisionRepository.findOne({
|
||||||
|
where:{
|
||||||
|
orgRevisionIsCurrent: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const rawdataProfile = await this.empPosMasterRepository
|
||||||
|
.createQueryBuilder('posMaster')
|
||||||
|
.leftJoinAndSelect('posMaster.current_holder', 'current_holder')
|
||||||
|
.leftJoinAndSelect('posMaster.positions', 'positions')
|
||||||
|
.leftJoinAndSelect('posMaster.orgRoot', 'orgRoot')
|
||||||
|
.leftJoinAndSelect('current_holder.posType', 'posType')
|
||||||
|
.leftJoinAndSelect('current_holder.posLevel', 'posLevel')
|
||||||
|
.leftJoinAndSelect('current_holder.profileEducations', 'profileEducations')
|
||||||
|
.where('posMaster.orgRevisionId = :currentRevisionId', { currentRevisionId: currentRevision?.id })
|
||||||
|
.andWhere('posMaster.orgRootId = :rootId', { rootId })
|
||||||
|
.andWhere('posMaster.current_holderId Is Not Null')
|
||||||
|
.andWhere('positions.positionIsSelected = :positionIsSelected', { positionIsSelected: true })
|
||||||
|
.andWhere( yearInAD && yearInAD != null? 'YEAR(current_holder.dateAppoint) = :year': "1=1", { year: yearInAD })
|
||||||
|
.andWhere(`
|
||||||
|
TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) >= :minAge
|
||||||
|
AND TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) <= :maxAge
|
||||||
|
`, { minAge, maxAge })
|
||||||
|
.getMany();
|
||||||
|
if(!rawdataProfile){
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||||
|
}
|
||||||
|
const mapData = rawdataProfile.map((x) => {
|
||||||
|
const latestEducation = x.current_holder.profileEducations.sort((a:any, b:any) => b.endDate - a.startDate)[0];
|
||||||
|
return {
|
||||||
|
name: x.current_holder.firstName + " " + x.current_holder.lastName,
|
||||||
|
affiliation: x.orgRoot.orgRootName,
|
||||||
|
gender: x.current_holder.gender,
|
||||||
|
positionName: x.positions[0]?x.positions[0].positionName: "-",
|
||||||
|
status: x.current_holder.relationship,
|
||||||
|
posType: x.current_holder.posType.posTypeName,
|
||||||
|
posLevel: x.current_holder.posLevel.posLevelName,
|
||||||
|
degree: latestEducation ? latestEducation.educationLevel : "-",
|
||||||
|
period: "-",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const groupedData = mapData.reduce((acc:any, item) => {
|
||||||
|
const key = `${item.affiliation} - ${item.gender} - ${item.degree || 'ไม่พบข้อมูล'} - ${item.status || 'ไม่พบข้อมูล'} - ${item.posType} - ${item.positionName} - ${item.posLevel}
|
||||||
|
`;
|
||||||
|
if (!acc[key]) {
|
||||||
|
acc[key] = {
|
||||||
|
affiliation: item.affiliation,
|
||||||
|
gender: item.gender,
|
||||||
|
degree: item.degree,
|
||||||
|
status: item.status,
|
||||||
|
posType: item.posType,
|
||||||
|
positionName: item.positionName,
|
||||||
|
posLevel: item.posLevel,
|
||||||
|
period: "-",
|
||||||
|
count: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
acc[key].count++;
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return new HttpSuccess({
|
||||||
|
template: "registry-emp",
|
||||||
|
reportName: "xlsx-report",
|
||||||
|
data: groupedData,
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API Report1
|
* API Report1
|
||||||
|
|
@ -6471,4 +6672,5 @@ export class ReportController extends Controller {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -628,7 +628,7 @@ export class WorkflowController extends Controller {
|
||||||
if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ");
|
if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ");
|
||||||
|
|
||||||
if (state.stateUserComments.filter((x) => x.profileId == body.profileId).length > 0)
|
if (state.stateUserComments.filter((x) => x.profileId == body.profileId).length > 0)
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "มีผู้ใช้งานนี้อยู่แล้ว");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถเลือกซ้ำได้");
|
||||||
|
|
||||||
const stateUserComment = new StateUserComment();
|
const stateUserComment = new StateUserComment();
|
||||||
stateUserComment.order = state.stateUserComments.length + 1;
|
stateUserComment.order = state.stateUserComments.length + 1;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { In, IsNull, MoreThan, Not } from "typeorm";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import { Command } from "../entities/Command";
|
import { Command } from "../entities/Command";
|
||||||
import { ProfileSalary } from "../entities/ProfileSalary";
|
import { ProfileSalary } from "../entities/ProfileSalary";
|
||||||
|
import { Profile } from "../entities/Profile";
|
||||||
export function calculateAge(start: Date, end = new Date()) {
|
export function calculateAge(start: Date, end = new Date()) {
|
||||||
if (start.getTime() > end.getTime()) return null;
|
if (start.getTime() > end.getTime()) return null;
|
||||||
|
|
||||||
|
|
@ -85,10 +86,15 @@ export async function calculateGovAge(profileId: string, type: string) {
|
||||||
|
|
||||||
return { years, months, days };
|
return { years, months, days };
|
||||||
};
|
};
|
||||||
|
const profile = await AppDataSource.getRepository(Profile).findOne({
|
||||||
const firstStartDate = new Date(records[0].date);
|
where:{
|
||||||
|
id:profileId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// const firstStartDate = new Date(records[0].date);
|
||||||
|
const firstStartDate = profile?.dateAppoint;
|
||||||
const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date();
|
const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
years: totalYears1,
|
years: totalYears1,
|
||||||
months: totalMonths1,
|
months: totalMonths1,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue