This commit is contained in:
AdisakKanthawilang 2024-12-24 18:04:19 +07:00
parent 27137aad68
commit 9b2cd6d3e3
2 changed files with 277 additions and 112 deletions

View file

@ -4136,14 +4136,9 @@ 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( .where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
node && nodeId orgRevisionId: node && nodeId ? findRevision.id : undefined,
? "current_holders.orgRevisionId = :orgRevisionId" })
: "1=1",
{
orgRevisionId: node && nodeId ? findRevision.id : undefined,
}
)
.andWhere( .andWhere(
_data.root != undefined && _data.root != null _data.root != undefined && _data.root != null
? _data.root[0] != null ? _data.root[0] != null
@ -4483,6 +4478,74 @@ export class ProfileController extends Controller {
return new HttpSuccess({ data: data, total }); return new HttpSuccess({ data: data, total });
} }
// /**
// * API ค้นหาประวัติการครองตำแหน่ง ข้าราชการ
// *
// * @summary ค้นหาประวัติการครองตำแหน่ง ข้าราชการ
// *
// */
// @Post("search/history/oc")
// async searchHistoryOC(
// @Body()
// requestBody: {
// posNo?: string;
// position?: string;
// },
// ) {
// const profiles = await this.profileRepo
// .createQueryBuilder("profile")
// .leftJoinAndSelect("profile.profileSalary", "profileSalary")
// .select([
// "profile.id",
// "profile.prefix",
// "profile.firstName",
// "profile.lastName",
// "profile.citizenId",
// "profileSalary.position",
// "profileSalary.posNo",
// "profileSalary.date",
// ])
// .andWhere(
// requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined
// ? "profileSalary.position LIKE :position"
// : "1=2",
// {
// position: `%${requestBody.position}%`,
// },
// )
// .orWhere(
// requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined
// ? "profileSalary.posNo LIKE :posNo"
// : "1=2",
// {
// posNo: `%${requestBody.posNo}%`,
// },
// )
// .getMany();
// const mapData = profiles.map((profile) => {
// let profileSalary;
// if (profile.profileSalary && profile.profileSalary.length > 0) {
// profileSalary = profile.profileSalary.reduce((latest, current) => {
// return new Date(current.date) > new Date(latest.date) ? current : latest;
// });
// }
// return {
// id: profile.id,
// // prefix: profile.prefix,
// // firstName: profile.firstName,
// // lastName: profile.lastName,
// fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
// citizenId: profile.citizenId,
// position: profileSalary ? profileSalary.position : null,
// posNo: profileSalary ? profileSalary.posNo : null,
// date: profileSalary ? profileSalary.date : null,
// };
// });
// return new HttpSuccess(mapData);
// }
/** /**
* API * API
* *
@ -4490,63 +4553,80 @@ export class ProfileController extends Controller {
* *
*/ */
@Post("search/history/oc") @Post("search/history/oc")
async searchHistoryOC( async searchOC(
@Body() @Body()
requestBody: { requestBody: {
posNo?: string; posNo?: string;
position?: string; position?: string;
}, },
) { ) {
let queryLike = `
CASE
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
END LIKE :keyword
`;
const profiles = await this.profileRepo const profiles = await this.profileRepo
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.profileSalary", "profileSalary") .leftJoinAndSelect("profile.current_holders", "current_holders")
.select([ .leftJoinAndSelect("current_holders.positions", "positions")
"profile.id", .leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
"profile.prefix", .leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
"profile.firstName", .leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
"profile.lastName", .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
"profile.citizenId", .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
"profileSalary.position", .where("positions.positionIsSelected = :posIsSelected", { posIsSelected: true })
"profileSalary.posNo",
"profileSalary.date",
])
.andWhere( .andWhere(
requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined new Brackets((qb) => {
? "profileSalary.position LIKE :position" qb.orWhere(
: "1=2", requestBody.posNo != undefined && requestBody.posNo != null && requestBody.posNo != ""
{ ? queryLike
position: `%${requestBody.position}%`, : "1=1",
}, {
keyword: `%${requestBody.posNo}%`,
},
);
}),
) )
.orWhere( .andWhere(
requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined requestBody.position != null && requestBody.position !== ""
? "profileSalary.posNo LIKE :posNo" ? "positions.positionName LIKE :positionName"
: "1=2", : "1=1",
{ { positionName: `${requestBody.position}` },
posNo: `%${requestBody.posNo}%`,
},
) )
.getMany(); .getMany();
const mapData = profiles.map((profile) => { const mapData = profiles
let profileSalary; .map((profile) => {
if (profile.profileSalary && profile.profileSalary.length > 0) { const shortNames = profile.current_holders.map((holder) => {
profileSalary = profile.profileSalary.reduce((latest, current) => { const shortName =
return new Date(current.date) > new Date(latest.date) ? current : latest; holder.orgChild4?.orgChild4ShortName ||
holder.orgChild3?.orgChild3ShortName ||
holder.orgChild2?.orgChild2ShortName ||
holder.orgChild1?.orgChild1ShortName ||
holder.orgRoot?.orgRootShortName;
return `${shortName || ""}${holder.posMasterNo || ""}`;
}); });
} return profile.current_holders.map((holder, index) => {
return { const position = holder.positions.find((position) => position.posMasterId === holder.id);
id: profile.id, const positionName = position ? position.positionName : null;
// prefix: profile.prefix,
// firstName: profile.firstName, return {
// lastName: profile.lastName, id: profile.id,
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, posMasterId: holder.id,
citizenId: profile.citizenId, fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
position: profileSalary ? profileSalary.position : null, citizenId: profile.citizenId,
posNo: profileSalary ? profileSalary.posNo : null, posNo: shortNames[index],
date: profileSalary ? profileSalary.date : null, positionName: positionName,
}; date: holder.createdAt
}); };
});
})
.flat();
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
} }

View file

@ -1855,70 +1855,155 @@ export class ProfileEmployeeController extends Controller {
return new HttpSuccess({ data: data, total }); return new HttpSuccess({ data: data, total });
} }
/** // /**
* API // * API ค้นหาประวัติการครองตำแหน่ง ลูกจ้าง
// *
// * @summary ค้นหาประวัติการครองตำแหน่ง ลูกจ้าง
// *
// */
// @Post("search/history/oc")
// async searchHistoryOC(
// @Body()
// requestBody: {
// posNo?: string;
// position?: string;
// },
// ) {
// const profiles = await this.profileRepo
// .createQueryBuilder("profileEmployee")
// .leftJoinAndSelect("profileEmployee.profileSalary", "profileSalary")
// .select([
// "profileEmployee.id",
// "profileEmployee.prefix",
// "profileEmployee.firstName",
// "profileEmployee.lastName",
// "profileEmployee.citizenId",
// "profileSalary.position",
// "profileSalary.posNo",
// "profileSalary.date",
// ])
// .andWhere(
// requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined
// ? "profileSalary.position LIKE :position"
// : "1=2",
// {
// position: `%${requestBody.position}%`,
// },
// )
// .orWhere(
// requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined
// ? "profileSalars.posNo LIKE :posNo"
// : "1=2",
// {
// posNo: `%${requestBody.posNo}%`,
// },
// )
// .getMany();
// const mapData = profiles.map((profile) => {
// let profileSalary;
// if (profile.profileSalary && profile.profileSalary.length > 0) {
// profileSalary = profile.profileSalary.reduce((latest, current) => {
// return new Date(current.date) > new Date(latest.date) ? current : latest;
// });
// }
// return {
// id: profile.id,
// fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
// citizenId: profile.citizenId,
// position: profileSalary ? profileSalary.position : null,
// posNo: profileSalary ? profileSalary.posNo : null,
// date: profileSalary ? profileSalary.date : null,
// };
// });
// return new HttpSuccess(mapData);
// }
/**
* API
* *
* @summary * @summary
* *
*/ */
@Post("search/history/oc") @Post("search/history/oc")
async searchHistoryOC( async searchOC(
@Body() @Body()
requestBody: { requestBody: {
posNo?: string; posNo?: string;
position?: string; position?: string;
}, },
) { ) {
const profiles = await this.profileRepo let queryLike = `
.createQueryBuilder("profileEmployee") CASE
.leftJoinAndSelect("profileEmployee.profileSalary", "profileSalary") WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
.select([ WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
"profileEmployee.id", WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
"profileEmployee.prefix", WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
"profileEmployee.firstName", ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
"profileEmployee.lastName", END LIKE :keyword
"profileEmployee.citizenId", `;
"profileSalary.position",
"profileSalary.posNo", const profiles = await this.profileRepo
"profileSalary.date", .createQueryBuilder("profileEmployee")
]) .leftJoinAndSelect("profileEmployee.current_holders", "current_holders")
.andWhere( .leftJoinAndSelect("current_holders.positions", "positions")
requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined .leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
? "profileSalary.position LIKE :position" .leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
: "1=2", .leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
{ .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
position: `%${requestBody.position}%`, .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
}, .where("positions.positionIsSelected = :posIsSelected", { posIsSelected: true })
) .andWhere(
.orWhere( new Brackets((qb) => {
requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined qb.orWhere(
? "profileSalars.posNo LIKE :posNo" requestBody.posNo != undefined && requestBody.posNo != null && requestBody.posNo != ""
: "1=2", ? queryLike
{ : "1=1",
posNo: `%${requestBody.posNo}%`, {
}, keyword: `%${requestBody.posNo}%`,
) },
.getMany(); );
}),
const mapData = profiles.map((profile) => { )
let profileSalary; .andWhere(
if (profile.profileSalary && profile.profileSalary.length > 0) { requestBody.position != null && requestBody.position !== ""
profileSalary = profile.profileSalary.reduce((latest, current) => { ? "positions.positionName LIKE :positionName"
return new Date(current.date) > new Date(latest.date) ? current : latest; : "1=1",
}); { positionName: `${requestBody.position}` },
} )
return { .getMany();
id: profile.id,
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, const mapData = profiles
citizenId: profile.citizenId, .map((profile) => {
position: profileSalary ? profileSalary.position : null, const shortNames = profile.current_holders.map((holder) => {
posNo: profileSalary ? profileSalary.posNo : null, const shortName =
date: profileSalary ? profileSalary.date : null, holder.orgChild4?.orgChild4ShortName ||
}; holder.orgChild3?.orgChild3ShortName ||
}); holder.orgChild2?.orgChild2ShortName ||
holder.orgChild1?.orgChild1ShortName ||
return new HttpSuccess(mapData); holder.orgRoot?.orgRootShortName;
} return `${shortName || ""}${holder.posMasterNo || ""}`;
});
return profile.current_holders.map((holder, index) => {
const position = holder.positions.find((position) => position.posMasterId === holder.id);
const positionName = position ? position.positionName : null;
return {
id: profile.id,
posMasterId: holder.id,
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
citizenId: profile.citizenId,
posNo: shortNames[index],
positionName: positionName,
date: holder.createdAt
};
});
})
.flat();
return new HttpSuccess(mapData);
}
/** /**
* API keycloak * API keycloak