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

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

View file

@ -1107,7 +1107,8 @@ export class ProfileEmployeeController extends Controller {
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query() searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position", @Query()
searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position" | "posNo",
@Query() searchKeyword: string = "", @Query() searchKeyword: string = "",
@Query() posType?: string, @Query() posType?: string,
@Query() posLevel?: string, @Query() posLevel?: string,
@ -1115,15 +1116,45 @@ export class ProfileEmployeeController extends Controller {
@Query() isProbation?: boolean, @Query() isProbation?: boolean,
@Query() isRetire?: boolean, @Query() isRetire?: boolean,
@Query() type?: string, @Query() type?: string,
@Query() node?: number,
@Query() nodeId?: string,
@Query() isAll?: boolean,
) { ) {
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_EMP");
let queryLike = let queryLike =
"CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword"; "CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword";
if (searchField == "citizenId") { if (searchField == "citizenId") {
queryLike = "profileEmployee.citizenId LIKE :keyword"; queryLike = "profileEmployee.citizenId LIKE :keyword";
} else if (searchField == "position") { } else if (searchField == "position") {
queryLike = "profileEmployee.position LIKE :keyword"; 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 const [record, total] = await this.profileRepo
.createQueryBuilder("profileEmployee") .createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
@ -1186,14 +1217,6 @@ export class ProfileEmployeeController extends Controller {
child4: _data.child4, child4: _data.child4,
}, },
) )
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.andWhere( .andWhere(
posType != undefined && posType != null && posType != "" posType != undefined && posType != null && posType != ""
? "posType.posTypeName LIKE :keyword1" ? "posType.posTypeName LIKE :keyword1"
@ -1222,14 +1245,20 @@ export class ProfileEmployeeController extends Controller {
: `profile.dateRetire IS NOT NULL` : `profile.dateRetire IS NOT NULL`
: "1=1", : "1=1",
) )
.andWhere("profileEmployee.employeeClass LIKE :type", {
type: "PREM",
})
.andWhere( .andWhere(
type !== undefined && type !== null && type !== "" searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? "profileEmployee.employeeClass LIKE :type" ? queryLike
: "1=1", : "1=1",
{ {
type: type == null || type == undefined ? null : `${type.trim().toUpperCase()}`, keyword: `%${searchKeyword}%`,
}, },
) )
.andWhere(nodeCondition, {
nodeId: nodeId,
})
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();

View file

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