ค้นหาทะเบียน

This commit is contained in:
Kittapath 2024-03-26 09:47:17 +07:00
parent e368c4cae8
commit 6e8b8d58b9
5 changed files with 1412 additions and 32 deletions

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,7 @@ import { OrgRevision } from "../entities/OrgRevision";
import { PosMaster } from "../entities/PosMaster";
import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType";
import { calculateRetireDate } from "../interfaces/utils";
import { calculateRetireDate, calculateRetireYear } from "../interfaces/utils";
import { RequestWithUser } from "../middlewares/user";
@Route("api/v1/org/profile")
@ -259,39 +259,91 @@ export class ProfileController extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query() searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position",
@Query() searchKeyword: string = "",
@Query() posType?: string,
@Query() posLevel?: string,
@Query() yearLeave?: number,
@Query() isProbation?: boolean,
@Query() isRetire?: boolean,
) {
if (searchField === "fullName") {
const [record, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.gender", "gender")
.leftJoinAndSelect("profile.relationship", "relationship")
.leftJoinAndSelect("profile.bloodGroup", "bloodGroup")
.where("CONCAT(profile.firstName, ' ', profile.lastName) LIKE :fullName", {
fullName: `%${searchKeyword}%`,
})
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
return new HttpSuccess({ data: record, total });
let queryLike =
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
if (searchField == "citizenId") {
queryLike = "profile.citizenId LIKE :keyword";
} else if (searchField == "position") {
queryLike = "profile.position LIKE :keyword";
}
const [record, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.gender", "gender")
.leftJoinAndSelect("profile.relationship", "relationship")
.leftJoinAndSelect("profile.bloodGroup", "bloodGroup")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.select([
"profile.id",
"profile.prefix",
"profile.firstName",
"profile.lastName",
"profile.citizenId",
"profile.birthDate",
"profile.isProbation",
"profile.dateRetire",
"profile.position",
"posType.posTypeName",
"posLevel.posLevelName",
"current_holders.posMasterNo",
// "orgRoot?.orgRootShortName",
// "orgChild1?.orgRootShortName",
// "orgChild2?.orgRootShortName",
// "orgChild3?.orgRootShortName",
// "orgChild4?.orgRootShortName",
])
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.andWhere(
posType != undefined && posType != null && posType != ""
? "posType.posTypeName LIKE :keyword1"
: "1=1",
{
keyword1: `${posType}`,
},
)
.andWhere(
posLevel != undefined && posLevel != null && posLevel != ""
? "posLevel.posLevelName LIKE :keyword2"
: "1=1",
{
keyword2: `${posLevel}`,
},
)
.andWhere(
isProbation != undefined && isProbation != null
? `profile.isProbation = ${isProbation}`
: "1=1",
)
.andWhere(
isRetire != undefined && isRetire != null
? isRetire == true
? `profile.dateRetire IS null`
: `profile.dateRetire IS NOT NULL`
: "1=1",
)
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const [record, total] = await this.profileRepo.findAndCount({
relations: {
posLevel: true,
posType: true,
gender: true,
relationship: true,
bloodGroup: true,
},
where:
searchField && searchKeyword ? [{ [searchField]: Like(`%${searchKeyword}%`) }] : undefined,
order: { createdAt: "ASC" },
skip: (page - 1) * pageSize,
take: pageSize,
});
return new HttpSuccess({ data: record, total });
}