ค้นหาเฉพาะกิ่ง

This commit is contained in:
kittapath 2024-09-04 12:09:23 +07:00
parent 1d0b35983b
commit af5cd2d17e
3 changed files with 53 additions and 22 deletions

View file

@ -2634,7 +2634,9 @@ export class ProfileController extends Controller {
@Query() isRetire?: boolean,
@Query() node?: number,
@Query() nodeId?: string,
@Query() isAll?: boolean,
) {
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
let queryLike =
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
if (searchField == "citizenId") {
@ -2652,18 +2654,23 @@ export class ProfileController extends Controller {
) LIKE :keyword`;
}
let nodeCondition = "1=1";
let nodeAll = "";
if (node === 0 && nodeId) {
nodeCondition = "current_holders.orgRootId = :nodeId";
if (isAll == true) nodeAll = " AND current_holders.orgChild1Id IS NULL";
} else if (node === 1 && nodeId) {
nodeCondition = "current_holders.orgChild1Id = :nodeId";
if (isAll == true) nodeAll = " AND current_holders.orgChild2Id IS NULL";
} else if (node === 2 && nodeId) {
nodeCondition = "current_holders.orgChild2Id = :nodeId";
if (isAll == true) nodeAll = " AND current_holders.orgChild3Id IS NULL";
} else if (node === 3 && nodeId) {
nodeCondition = "current_holders.orgChild3Id = :nodeId";
if (isAll == true) nodeAll = " AND current_holders.orgChild4Id IS NULL";
} else if (node === 4 && nodeId) {
nodeCondition = "current_holders.orgChild4Id = :nodeId";
}
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
nodeCondition = nodeCondition + nodeAll;
const [record, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")

View file

@ -1107,7 +1107,8 @@ export class ProfileEmployeeController extends Controller {
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query() searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position",
@Query()
searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position" | "posNo",
@Query() searchKeyword: string = "",
@Query() posType?: string,
@Query() posLevel?: string,
@ -1115,15 +1116,45 @@ export class ProfileEmployeeController extends Controller {
@Query() isProbation?: boolean,
@Query() isRetire?: boolean,
@Query() type?: string,
@Query() node?: number,
@Query() nodeId?: string,
@Query() isAll?: boolean,
) {
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_EMP");
let queryLike =
"CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword";
if (searchField == "citizenId") {
queryLike = "profileEmployee.citizenId LIKE :keyword";
} else if (searchField == "position") {
queryLike = "profileEmployee.position LIKE :keyword";
} else if (searchField == "posNo") {
queryLike = `CONCAT(
IFNULL(orgChild4.orgChild4ShortName, ''),
IFNULL(orgChild3.orgChild3ShortName, ''),
IFNULL(orgChild2.orgChild2ShortName, ''),
IFNULL(orgChild1.orgChild1ShortName, ''),
IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`;
}
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_EMP");
let nodeCondition = "1=1";
let nodeAll = "";
if (node === 0 && nodeId) {
nodeCondition = "current_holders.orgRootId = :nodeId";
if (isAll == true) nodeAll = " AND current_holders.orgChild1Id IS NULL";
} else if (node === 1 && nodeId) {
nodeCondition = "current_holders.orgChild1Id = :nodeId";
if (isAll == true) nodeAll = " AND current_holders.orgChild2Id IS NULL";
} else if (node === 2 && nodeId) {
nodeCondition = "current_holders.orgChild2Id = :nodeId";
if (isAll == true) nodeAll = " AND current_holders.orgChild3Id IS NULL";
} else if (node === 3 && nodeId) {
nodeCondition = "current_holders.orgChild3Id = :nodeId";
if (isAll == true) nodeAll = " AND current_holders.orgChild4Id IS NULL";
} else if (node === 4 && nodeId) {
nodeCondition = "current_holders.orgChild4Id = :nodeId";
}
nodeCondition = nodeCondition + nodeAll;
const [record, total] = await this.profileRepo
.createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
@ -1186,14 +1217,6 @@ export class ProfileEmployeeController extends Controller {
child4: _data.child4,
},
)
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.andWhere(
posType != undefined && posType != null && posType != ""
? "posType.posTypeName LIKE :keyword1"
@ -1222,14 +1245,20 @@ export class ProfileEmployeeController extends Controller {
: `profile.dateRetire IS NOT NULL`
: "1=1",
)
.andWhere("profileEmployee.employeeClass LIKE :type", {
type: "PREM",
})
.andWhere(
type !== undefined && type !== null && type !== ""
? "profileEmployee.employeeClass LIKE :type"
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
type: type == null || type == undefined ? null : `${type.trim().toUpperCase()}`,
keyword: `%${searchKeyword}%`,
},
)
.andWhere(nodeCondition, {
nodeId: nodeId,
})
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();

View file

@ -1206,14 +1206,9 @@ export class ProfileEmployeeTempController extends Controller {
: `profile.dateRetire IS NOT NULL`
: "1=1",
)
.andWhere(
type !== undefined && type !== null && type !== ""
? "profileEmployee.employeeClass LIKE :type"
: "1=1",
{
type: type == null || type == undefined ? null : `${type.trim().toUpperCase()}`,
},
)
.andWhere("profileEmployee.employeeClass LIKE :type", {
type: "TEMP",
})
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();